mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-16 20:43:42 +00:00
refactoring
This commit is contained in:
@@ -131,7 +131,7 @@ void encoder_prepare_for_device(struct encoder_t *encoder, struct device_t *dev)
|
|||||||
int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, const unsigned index) {
|
int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, const unsigned index) {
|
||||||
assert(encoder->type != ENCODER_TYPE_UNKNOWN);
|
assert(encoder->type != ENCODER_TYPE_UNKNOWN);
|
||||||
|
|
||||||
dev->run->pictures[index].encode_begin_time = now_monotonic_ms();
|
dev->run->pictures[index].encode_begin_time = get_now_monotonic();
|
||||||
|
|
||||||
if (encoder->type == ENCODER_TYPE_CPU) {
|
if (encoder->type == ENCODER_TYPE_CPU) {
|
||||||
jpeg_encoder_compress_buffer(dev, index, encoder->quality);
|
jpeg_encoder_compress_buffer(dev, index, encoder->quality);
|
||||||
@@ -144,7 +144,7 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, con
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
dev->run->pictures[index].encode_end_time = now_monotonic_ms();
|
dev->run->pictures[index].encode_end_time = get_now_monotonic();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
24
src/http.c
24
src/http.c
@@ -208,7 +208,7 @@ static void _http_callback_snapshot(struct evhttp_request *request, void *v_serv
|
|||||||
# define ADD_TIME_HEADER(_key, _value) \
|
# define ADD_TIME_HEADER(_key, _value) \
|
||||||
{ sprintf(time_buf, "%.06Lf", _value); ADD_HEADER(_key, time_buf); }
|
{ sprintf(time_buf, "%.06Lf", _value); ADD_HEADER(_key, time_buf); }
|
||||||
|
|
||||||
ADD_TIME_HEADER("X-Timestamp", now_real_ms());
|
ADD_TIME_HEADER("X-Timestamp", get_now_real());
|
||||||
|
|
||||||
ADD_HEADER("X-UStreamer-Picture-Type", (EXPOSED(type) == PICTURE_TYPE_REAL ? "real" : "blank"));
|
ADD_HEADER("X-UStreamer-Picture-Type", (EXPOSED(type) == PICTURE_TYPE_REAL ? "real" : "blank"));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Grab-Time", EXPOSED(picture.grab_time));
|
ADD_TIME_HEADER("X-UStreamer-Grab-Time", EXPOSED(picture.grab_time));
|
||||||
@@ -217,7 +217,7 @@ static void _http_callback_snapshot(struct evhttp_request *request, void *v_serv
|
|||||||
ADD_TIME_HEADER("X-UStreamer-Expose-Begin-Time", EXPOSED(expose_begin_time));
|
ADD_TIME_HEADER("X-UStreamer-Expose-Begin-Time", EXPOSED(expose_begin_time));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Expose-Cmp-Time", EXPOSED(expose_cmp_time));
|
ADD_TIME_HEADER("X-UStreamer-Expose-Cmp-Time", EXPOSED(expose_cmp_time));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Expose-End-Time", EXPOSED(expose_end_time));
|
ADD_TIME_HEADER("X-UStreamer-Expose-End-Time", EXPOSED(expose_end_time));
|
||||||
ADD_TIME_HEADER("X-UStreamer-Send-Time", now_monotonic_ms());
|
ADD_TIME_HEADER("X-UStreamer-Send-Time", get_now_monotonic());
|
||||||
|
|
||||||
# undef ADD_TIME_HEADER
|
# undef ADD_TIME_HEADER
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
|||||||
"X-Timestamp: %.06Lf" RN
|
"X-Timestamp: %.06Lf" RN
|
||||||
"%s",
|
"%s",
|
||||||
EXPOSED(picture.size) * sizeof(*EXPOSED(picture.data)),
|
EXPOSED(picture.size) * sizeof(*EXPOSED(picture.data)),
|
||||||
now_real_ms(), (client->server->extra_stream_headers ? "" : RN)
|
get_now_real(), (client->server->extra_stream_headers ? "" : RN)
|
||||||
));
|
));
|
||||||
if (client->server->extra_stream_headers) {
|
if (client->server->extra_stream_headers) {
|
||||||
assert(evbuffer_add_printf(buf,
|
assert(evbuffer_add_printf(buf,
|
||||||
@@ -334,7 +334,7 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
|||||||
EXPOSED(expose_begin_time),
|
EXPOSED(expose_begin_time),
|
||||||
EXPOSED(expose_cmp_time),
|
EXPOSED(expose_cmp_time),
|
||||||
EXPOSED(expose_end_time),
|
EXPOSED(expose_end_time),
|
||||||
now_monotonic_ms()
|
get_now_monotonic()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +434,7 @@ static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (queue_send) {
|
if (queue_send) {
|
||||||
if ((now = ms_to_s(now_monotonic_ms())) != eps_second) {
|
if ((now = floor_ms(get_now_monotonic())) != eps_second) {
|
||||||
server->run->exposed->eps = eps;
|
server->run->exposed->eps = eps;
|
||||||
eps = 0;
|
eps = 0;
|
||||||
eps_second = now;
|
eps_second = now;
|
||||||
@@ -454,7 +454,7 @@ static bool _expose_new_picture(struct http_server_t *server) {
|
|||||||
|
|
||||||
assert(STREAM(picture.size) > 0);
|
assert(STREAM(picture.size) > 0);
|
||||||
EXPOSED(fps) = STREAM(fps);
|
EXPOSED(fps) = STREAM(fps);
|
||||||
EXPOSED(expose_begin_time) = now_monotonic_ms();
|
EXPOSED(expose_begin_time) = get_now_monotonic();
|
||||||
|
|
||||||
# define MEM_STREAM_TO_EXPOSED \
|
# define MEM_STREAM_TO_EXPOSED \
|
||||||
EXPOSED(picture.data), STREAM(picture.data), \
|
EXPOSED(picture.data), STREAM(picture.data), \
|
||||||
@@ -467,7 +467,7 @@ static bool _expose_new_picture(struct http_server_t *server) {
|
|||||||
&& EXPOSED(picture.size) == STREAM(picture.size)
|
&& EXPOSED(picture.size) == STREAM(picture.size)
|
||||||
&& !memcmp(MEM_STREAM_TO_EXPOSED)
|
&& !memcmp(MEM_STREAM_TO_EXPOSED)
|
||||||
) {
|
) {
|
||||||
EXPOSED(expose_cmp_time) = now_monotonic_ms();
|
EXPOSED(expose_cmp_time) = get_now_monotonic();
|
||||||
EXPOSED(expose_end_time) = EXPOSED(expose_cmp_time);
|
EXPOSED(expose_end_time) = EXPOSED(expose_cmp_time);
|
||||||
LOG_PERF(
|
LOG_PERF(
|
||||||
"HTTP: dropped same frame number %u; comparsion time = %.06Lf",
|
"HTTP: dropped same frame number %u; comparsion time = %.06Lf",
|
||||||
@@ -476,7 +476,7 @@ static bool _expose_new_picture(struct http_server_t *server) {
|
|||||||
EXPOSED(dropped) += 1;
|
EXPOSED(dropped) += 1;
|
||||||
return false; // Not updated
|
return false; // Not updated
|
||||||
} else {
|
} else {
|
||||||
EXPOSED(expose_cmp_time) = now_monotonic_ms();
|
EXPOSED(expose_cmp_time) = get_now_monotonic();
|
||||||
LOG_PERF(
|
LOG_PERF(
|
||||||
"HTTP: passed same frame check (frames are differ); comparsion time = %.06Lf",
|
"HTTP: passed same frame check (frames are differ); comparsion time = %.06Lf",
|
||||||
EXPOSED(expose_cmp_time) - EXPOSED(expose_begin_time)
|
EXPOSED(expose_cmp_time) - EXPOSED(expose_begin_time)
|
||||||
@@ -505,7 +505,7 @@ static bool _expose_new_picture(struct http_server_t *server) {
|
|||||||
EXPOSED(online) = true;
|
EXPOSED(online) = true;
|
||||||
EXPOSED(dropped) = 0;
|
EXPOSED(dropped) = 0;
|
||||||
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
||||||
EXPOSED(expose_end_time) = now_monotonic_ms();
|
EXPOSED(expose_end_time) = get_now_monotonic();
|
||||||
|
|
||||||
# undef STREAM
|
# undef STREAM
|
||||||
# undef EXPOSED
|
# undef EXPOSED
|
||||||
@@ -515,7 +515,7 @@ static bool _expose_new_picture(struct http_server_t *server) {
|
|||||||
static bool _expose_blank_picture(struct http_server_t *server) {
|
static bool _expose_blank_picture(struct http_server_t *server) {
|
||||||
# define EXPOSED(_next) server->run->exposed->_next
|
# define EXPOSED(_next) server->run->exposed->_next
|
||||||
|
|
||||||
EXPOSED(expose_begin_time) = now_monotonic_ms();
|
EXPOSED(expose_begin_time) = get_now_monotonic();
|
||||||
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
EXPOSED(expose_cmp_time) = EXPOSED(expose_begin_time);
|
||||||
|
|
||||||
if (EXPOSED(online) || EXPOSED(picture.size) == 0) {
|
if (EXPOSED(online) || EXPOSED(picture.size) == 0) {
|
||||||
@@ -546,13 +546,13 @@ static bool _expose_blank_picture(struct http_server_t *server) {
|
|||||||
if (EXPOSED(dropped) < server->run->drop_same_frames_blank) {
|
if (EXPOSED(dropped) < server->run->drop_same_frames_blank) {
|
||||||
LOG_PERF("HTTP: dropped same frame (BLANK) number %u", EXPOSED(dropped));
|
LOG_PERF("HTTP: dropped same frame (BLANK) number %u", EXPOSED(dropped));
|
||||||
EXPOSED(dropped) += 1;
|
EXPOSED(dropped) += 1;
|
||||||
EXPOSED(expose_end_time) = now_monotonic_ms();
|
EXPOSED(expose_end_time) = get_now_monotonic();
|
||||||
return false; // Not updated
|
return false; // Not updated
|
||||||
}
|
}
|
||||||
|
|
||||||
updated:
|
updated:
|
||||||
EXPOSED(dropped) = 0;
|
EXPOSED(dropped) = 0;
|
||||||
EXPOSED(expose_end_time) = now_monotonic_ms();
|
EXPOSED(expose_end_time) = get_now_monotonic();
|
||||||
return true; // Updated
|
return true; // Updated
|
||||||
|
|
||||||
# undef EXPOSED
|
# undef EXPOSED
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ pthread_mutex_t log_mutex;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_PRINTF_NOLOCK(_label, _msg, ...) { \
|
#define LOG_PRINTF_NOLOCK(_label, _msg, ...) { \
|
||||||
printf("-- " _label " [%.03Lf tid=%ld] -- " _msg "\n", now_monotonic_ms(), syscall(SYS_gettid), ##__VA_ARGS__); \
|
printf("-- " _label " [%.03Lf tid=%ld] -- " _msg "\n", get_now_monotonic(), syscall(SYS_gettid), ##__VA_ARGS__); \
|
||||||
fflush(stdout); \
|
fflush(stdout); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ pthread_mutex_t log_mutex;
|
|||||||
char _buf[1024] = ""; \
|
char _buf[1024] = ""; \
|
||||||
strerror_r(errno, _buf, 1024); \
|
strerror_r(errno, _buf, 1024); \
|
||||||
LOGGING_LOCK; \
|
LOGGING_LOCK; \
|
||||||
printf("-- ERROR [%.03Lf tid=%ld] -- " _msg ": %s\n", now_monotonic_ms(), syscall(SYS_gettid), ##__VA_ARGS__, _buf); \
|
printf("-- ERROR [%.03Lf tid=%ld] -- " _msg ": %s\n", get_now_monotonic(), syscall(SYS_gettid), ##__VA_ARGS__, _buf); \
|
||||||
fflush(stdout); \
|
fflush(stdout); \
|
||||||
LOGGING_UNLOCK; \
|
LOGGING_UNLOCK; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#define LOG_OMX_ERROR(_error, _msg, ...) { \
|
#define LOG_OMX_ERROR(_error, _msg, ...) { \
|
||||||
LOGGING_LOCK; \
|
LOGGING_LOCK; \
|
||||||
printf("-- ERROR [%.03Lf tid=%ld] -- " _msg ": %s\n", now_monotonic_ms(), \
|
printf("-- ERROR [%.03Lf tid=%ld] -- " _msg ": %s\n", get_now_monotonic(), \
|
||||||
syscall(SYS_gettid), ##__VA_ARGS__, omx_error_to_string(_error)); \
|
syscall(SYS_gettid), ##__VA_ARGS__, omx_error_to_string(_error)); \
|
||||||
LOGGING_UNLOCK; \
|
LOGGING_UNLOCK; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ void stream_loop(struct stream_t *stream) {
|
|||||||
LOG_DEBUG("Frame is ready");
|
LOG_DEBUG("Frame is ready");
|
||||||
|
|
||||||
struct v4l2_buffer buf_info;
|
struct v4l2_buffer buf_info;
|
||||||
long double now = now_monotonic_ms();
|
long double now = get_now_monotonic();
|
||||||
long long now_second = ms_to_s(now);
|
long long now_second = floor_ms(now);
|
||||||
|
|
||||||
if (_stream_grab_buffer(stream->dev, &buf_info) < 0) {
|
if (_stream_grab_buffer(stream->dev, &buf_info) < 0) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
12
src/tools.h
12
src/tools.h
@@ -61,11 +61,11 @@ INLINE unsigned max_u(unsigned a, unsigned b) {
|
|||||||
return (a > b ? a : b);
|
return (a > b ? a : b);
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE long long ms_to_s(long double now) {
|
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 now_ms(clockid_t clk_id, time_t *sec, long *msec) {
|
INLINE void get_now(clockid_t clk_id, time_t *sec, long *msec) {
|
||||||
struct timespec spec;
|
struct timespec spec;
|
||||||
|
|
||||||
assert(!clock_gettime(clk_id, &spec));
|
assert(!clock_gettime(clk_id, &spec));
|
||||||
@@ -78,18 +78,18 @@ INLINE void now_ms(clockid_t clk_id, time_t *sec, long *msec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE long double now_monotonic_ms(void) {
|
INLINE long double get_now_monotonic(void) {
|
||||||
time_t sec;
|
time_t sec;
|
||||||
long msec;
|
long msec;
|
||||||
|
|
||||||
now_ms(CLOCK_MONOTONIC_RAW, &sec, &msec);
|
get_now(CLOCK_MONOTONIC_RAW, &sec, &msec);
|
||||||
return (long double)sec + ((long double)msec) / 1000;
|
return (long double)sec + ((long double)msec) / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE long double now_real_ms(void) {
|
INLINE long double get_now_real(void) {
|
||||||
time_t sec;
|
time_t sec;
|
||||||
long msec;
|
long msec;
|
||||||
|
|
||||||
now_ms(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