refactoring

This commit is contained in:
Maxim Devaev
2024-03-02 19:37:50 +02:00
parent c32ea286f2
commit 77a53347c3
5 changed files with 12 additions and 12 deletions

View File

@@ -418,18 +418,18 @@ static void _http_callback_state(struct evhttp_request *request, void *v_server)
); );
} }
if (stream->sink != NULL || stream->h264_sink != NULL) { if (stream->jpeg_sink != NULL || stream->h264_sink != NULL) {
_A_EVBUFFER_ADD_PRINTF(buf, " \"sinks\": {"); _A_EVBUFFER_ADD_PRINTF(buf, " \"sinks\": {");
if (stream->sink != NULL) { if (stream->jpeg_sink != NULL) {
_A_EVBUFFER_ADD_PRINTF(buf, _A_EVBUFFER_ADD_PRINTF(buf,
"\"jpeg\": {\"has_clients\": %s}", "\"jpeg\": {\"has_clients\": %s}",
us_bool_to_string(atomic_load(&stream->sink->has_clients)) us_bool_to_string(atomic_load(&stream->jpeg_sink->has_clients))
); );
} }
if (stream->h264_sink != NULL) { if (stream->h264_sink != NULL) {
_A_EVBUFFER_ADD_PRINTF(buf, _A_EVBUFFER_ADD_PRINTF(buf,
"%s\"h264\": {\"has_clients\": %s}", "%s\"h264\": {\"has_clients\": %s}",
(stream->sink ? ", " : ""), (stream->jpeg_sink ? ", " : ""),
us_bool_to_string(atomic_load(&stream->h264_sink->has_clients)) us_bool_to_string(atomic_load(&stream->h264_sink->has_clients))
); );
} }

View File

@@ -250,7 +250,7 @@ us_options_s *us_options_init(unsigned argc, char *argv[]) {
} }
void us_options_destroy(us_options_s *options) { void us_options_destroy(us_options_s *options) {
US_DELETE(options->sink, us_memsink_destroy); US_DELETE(options->jpeg_sink, us_memsink_destroy);
US_DELETE(options->raw_sink, us_memsink_destroy); US_DELETE(options->raw_sink, us_memsink_destroy);
US_DELETE(options->h264_sink, us_memsink_destroy); US_DELETE(options->h264_sink, us_memsink_destroy);
@@ -338,7 +338,7 @@ int options_parse(us_options_s *options, us_device_s *dev, us_encoder_s *enc, us
bool x_prefix##_rm = false; \ bool x_prefix##_rm = false; \
unsigned x_prefix##_client_ttl = 10; \ unsigned x_prefix##_client_ttl = 10; \
unsigned x_prefix##_timeout = 1; unsigned x_prefix##_timeout = 1;
ADD_SINK(sink); ADD_SINK(jpeg_sink);
ADD_SINK(raw_sink); ADD_SINK(raw_sink);
ADD_SINK(h264_sink); ADD_SINK(h264_sink);
# undef ADD_SINK # undef ADD_SINK
@@ -436,7 +436,7 @@ int options_parse(us_options_s *options, us_device_s *dev, us_encoder_s *enc, us
case _O_##x_up##_RM: OPT_SET(x_lp##_rm, true); \ case _O_##x_up##_RM: OPT_SET(x_lp##_rm, true); \
case _O_##x_up##_CLIENT_TTL: OPT_NUMBER("--" #x_opt "sink-client-ttl", x_lp##_client_ttl, 1, 60, 0); \ case _O_##x_up##_CLIENT_TTL: OPT_NUMBER("--" #x_opt "sink-client-ttl", x_lp##_client_ttl, 1, 60, 0); \
case _O_##x_up##_TIMEOUT: OPT_NUMBER("--" #x_opt "sink-timeout", x_lp##_timeout, 1, 60, 0); case _O_##x_up##_TIMEOUT: OPT_NUMBER("--" #x_opt "sink-timeout", x_lp##_timeout, 1, 60, 0);
ADD_SINK("", sink, SINK) ADD_SINK("", jpeg_sink, SINK)
ADD_SINK("raw-", raw_sink, RAW_SINK) ADD_SINK("raw-", raw_sink, RAW_SINK)
ADD_SINK("h264-", h264_sink, H264_SINK) ADD_SINK("h264-", h264_sink, H264_SINK)
case _O_H264_BITRATE: OPT_NUMBER("--h264-bitrate", stream->h264_bitrate, 25, 20000, 0); case _O_H264_BITRATE: OPT_NUMBER("--h264-bitrate", stream->h264_bitrate, 25, 20000, 0);
@@ -497,7 +497,7 @@ int options_parse(us_options_s *options, us_device_s *dev, us_encoder_s *enc, us
} \ } \
stream->x_prefix = options->x_prefix; \ stream->x_prefix = options->x_prefix; \
} }
ADD_SINK("JPEG", sink); ADD_SINK("JPEG", jpeg_sink);
ADD_SINK("RAW", raw_sink); ADD_SINK("RAW", raw_sink);
ADD_SINK("H264", h264_sink); ADD_SINK("H264", h264_sink);
# undef ADD_SINK # undef ADD_SINK

View File

@@ -53,7 +53,7 @@ typedef struct {
unsigned argc; unsigned argc;
char **argv; char **argv;
char **argv_copy; char **argv_copy;
us_memsink_s *sink; us_memsink_s *jpeg_sink;
us_memsink_s *raw_sink; us_memsink_s *raw_sink;
us_memsink_s *h264_sink; us_memsink_s *h264_sink;
} us_options_s; } us_options_s;

View File

@@ -237,7 +237,7 @@ static bool _stream_has_any_clients(us_stream_s *stream) {
return ( return (
atomic_load(&run->http_has_clients) atomic_load(&run->http_has_clients)
// has_clients синков НЕ обновляются в реальном времени // has_clients синков НЕ обновляются в реальном времени
|| (stream->sink != NULL && atomic_load(&stream->sink->has_clients)) || (stream->jpeg_sink != NULL && atomic_load(&stream->jpeg_sink->has_clients))
|| (run->h264 != NULL && /*run->h264->sink == NULL ||*/ atomic_load(&run->h264->sink->has_clients)) || (run->h264 != NULL && /*run->h264->sink == NULL ||*/ atomic_load(&run->h264->sink->has_clients))
); );
} }
@@ -362,5 +362,5 @@ static void _stream_expose_frame(us_stream_s *stream, us_frame_s *frame) {
run->last_online = (frame != NULL); run->last_online = (frame != NULL);
us_ring_producer_release(run->http_jpeg_ring, ri); us_ring_producer_release(run->http_jpeg_ring, ri);
_SINK_PUT(sink, (frame != NULL ? frame : run->blank->jpeg)); _SINK_PUT(jpeg_sink, (frame != NULL ? frame : run->blank->jpeg));
} }

View File

@@ -59,7 +59,7 @@ typedef struct {
unsigned error_delay; unsigned error_delay;
unsigned exit_on_no_clients; unsigned exit_on_no_clients;
us_memsink_s *sink; us_memsink_s *jpeg_sink;
us_memsink_s *raw_sink; us_memsink_s *raw_sink;
us_memsink_s *h264_sink; us_memsink_s *h264_sink;