mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-05-27 07:46:15 +00:00
using hashes to enumerate frames in memsink
This commit is contained in:
@@ -102,7 +102,7 @@ int memsink_server_put(memsink_s *sink, const frame_s *frame) {
|
|||||||
LOG_VERBOSE("%s sink: >>>>> Exposing new frame ...", sink->name);
|
LOG_VERBOSE("%s sink: >>>>> Exposing new frame ...", sink->name);
|
||||||
|
|
||||||
# define COPY(_field) sink->mem->_field = frame->_field
|
# define COPY(_field) sink->mem->_field = frame->_field
|
||||||
sink->mem->seq += 1;
|
sink->mem->id = get_now_id();
|
||||||
COPY(used);
|
COPY(used);
|
||||||
COPY(width);
|
COPY(width);
|
||||||
COPY(height);
|
COPY(height);
|
||||||
@@ -145,11 +145,11 @@ int memsink_client_get(memsink_s *sink, frame_s *frame) { // cppcheck-suppress u
|
|||||||
|
|
||||||
bool same = false;
|
bool same = false;
|
||||||
|
|
||||||
if (sink->client_seq == sink->mem->seq) {
|
if (sink->mem->id == sink->consumed_id) {
|
||||||
same = true;
|
same = true;
|
||||||
} else {
|
} else {
|
||||||
# define COPY(_field) frame->_field = sink->mem->_field
|
# define COPY(_field) frame->_field = sink->mem->_field
|
||||||
sink->client_seq = sink->mem->seq;
|
sink->consumed_id = sink->mem->id;
|
||||||
COPY(width);
|
COPY(width);
|
||||||
COPY(height);
|
COPY(height);
|
||||||
COPY(format);
|
COPY(format);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t seq;
|
uint64_t id;
|
||||||
size_t used;
|
size_t used;
|
||||||
unsigned width;
|
unsigned width;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
@@ -68,7 +68,7 @@ typedef struct {
|
|||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
memsink_shared_s *mem;
|
memsink_shared_s *mem;
|
||||||
uint64_t client_seq;
|
uint64_t consumed_id; // Client only
|
||||||
} memsink_s;
|
} memsink_s;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -62,12 +63,23 @@ INLINE long long floor_ms(long double now) {
|
|||||||
return (long long)now - (now < (long long)now); // floor()
|
return (long long)now - (now < (long long)now); // floor()
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE void get_now(clockid_t clk_id, time_t *sec, long *msec) {
|
INLINE uint32_t triple_u32(uint32_t x) {
|
||||||
struct timespec spec;
|
// https://nullprogram.com/blog/2018/07/31/
|
||||||
|
x ^= x >> 17;
|
||||||
|
x *= UINT32_C(0xED5AD4BB);
|
||||||
|
x ^= x >> 11;
|
||||||
|
x *= UINT32_C(0xAC4C1B51);
|
||||||
|
x ^= x >> 15;
|
||||||
|
x *= UINT32_C(0x31848BAB);
|
||||||
|
x ^= x >> 14;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
assert(!clock_gettime(clk_id, &spec));
|
INLINE void get_now(clockid_t clk_id, time_t *sec, long *msec) {
|
||||||
*sec = spec.tv_sec;
|
struct timespec ts;
|
||||||
*msec = round(spec.tv_nsec / 1.0e6);
|
assert(!clock_gettime(clk_id, &ts));
|
||||||
|
*sec = ts.tv_sec;
|
||||||
|
*msec = round(ts.tv_nsec / 1.0e6);
|
||||||
|
|
||||||
if (*msec > 999) {
|
if (*msec > 999) {
|
||||||
*sec += 1;
|
*sec += 1;
|
||||||
@@ -75,24 +87,33 @@ INLINE void get_now(clockid_t clk_id, time_t *sec, long *msec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CLOCK_MONOTONIC_RAW)
|
||||||
|
# define X_CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW
|
||||||
|
#elif defined(CLOCK_MONOTONIC_FAST)
|
||||||
|
# define X_CLOCK_MONOTONIC CLOCK_MONOTONIC_FAST
|
||||||
|
#else
|
||||||
|
# define X_CLOCK_MONOTONIC CLOCK_MONOTONIC
|
||||||
|
#endif
|
||||||
|
|
||||||
INLINE long double get_now_monotonic(void) {
|
INLINE long double get_now_monotonic(void) {
|
||||||
time_t sec;
|
time_t sec;
|
||||||
long msec;
|
long msec;
|
||||||
|
get_now(X_CLOCK_MONOTONIC, &sec, &msec);
|
||||||
# if defined(CLOCK_MONOTONIC_RAW)
|
|
||||||
get_now(CLOCK_MONOTONIC_RAW, &sec, &msec);
|
|
||||||
# elif defined(CLOCK_MONOTONIC_FAST)
|
|
||||||
get_now(CLOCK_MONOTONIC_FAST, &sec, &msec);
|
|
||||||
# else
|
|
||||||
get_now(CLOCK_MONOTONIC, &sec, &msec);
|
|
||||||
# endif
|
|
||||||
return (long double)sec + ((long double)msec) / 1000;
|
return (long double)sec + ((long double)msec) / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE uint64_t get_now_id(void) {
|
||||||
|
struct timespec ts;
|
||||||
|
assert(!clock_gettime(X_CLOCK_MONOTONIC, &ts));
|
||||||
|
uint64_t now = (uint64_t)(ts.tv_nsec / 1000) + (uint64_t)ts.tv_sec * 1000000;
|
||||||
|
return (uint64_t)triple_u32(now) | ((uint64_t)triple_u32(now + 12345) << 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef X_CLOCK_MONOTONIC
|
||||||
|
|
||||||
INLINE long double get_now_real(void) {
|
INLINE long double get_now_real(void) {
|
||||||
time_t sec;
|
time_t sec;
|
||||||
long msec;
|
long msec;
|
||||||
|
|
||||||
get_now(CLOCK_REALTIME, &sec, &msec);
|
get_now(CLOCK_REALTIME, &sec, &msec);
|
||||||
return (long double)sec + ((long double)msec) / 1000;
|
return (long double)sec + ((long double)msec) / 1000;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user