From d499f890e7fe019ac3c60bec7ceb61d39aaca97b Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 19 Feb 2023 00:13:54 +0100 Subject: [PATCH] Give a name to demuxer instances This will be useful in logs. PR #3757 --- app/src/demuxer.c | 13 +++++++------ app/src/demuxer.h | 5 ++++- app/src/scrcpy.c | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/demuxer.c b/app/src/demuxer.c index c83d6bfa..e5f07628 100644 --- a/app/src/demuxer.c +++ b/app/src/demuxer.c @@ -122,7 +122,7 @@ static bool sc_demuxer_push_packet(struct sc_demuxer *demuxer, AVPacket *packet) { bool ok = push_packet_to_sinks(demuxer, packet); if (!ok) { - LOGE("Could not process packet"); + LOGE("Demuxer '%s': could not process packet", demuxer->name); return false; } @@ -177,7 +177,7 @@ run_demuxer(void *data) { const AVCodec *codec = avcodec_find_decoder(codec_id); if (!codec) { - LOGE("Decoder not found"); + LOGE("Demuxer '%s': decoder not found", demuxer->name); goto end; } @@ -217,7 +217,7 @@ run_demuxer(void *data) { } } - LOGD("End of frames"); + LOGD("Demuxer '%s': end of frames", demuxer->name); sc_packet_merger_destroy(&merger); @@ -231,8 +231,9 @@ end: } void -sc_demuxer_init(struct sc_demuxer *demuxer, sc_socket socket, +sc_demuxer_init(struct sc_demuxer *demuxer, const char *name, sc_socket socket, const struct sc_demuxer_callbacks *cbs, void *cbs_userdata) { + demuxer->name = name; // statically allocated demuxer->socket = socket; demuxer->sink_count = 0; @@ -252,12 +253,12 @@ sc_demuxer_add_sink(struct sc_demuxer *demuxer, struct sc_packet_sink *sink) { bool sc_demuxer_start(struct sc_demuxer *demuxer) { - LOGD("Starting demuxer thread"); + LOGD("Demuxer '%s': starting thread", demuxer->name); bool ok = sc_thread_create(&demuxer->thread, run_demuxer, "scrcpy-demuxer", demuxer); if (!ok) { - LOGE("Could not start demuxer thread"); + LOGE("Demuxer '%s': could not start thread", demuxer->name); return false; } return true; diff --git a/app/src/demuxer.h b/app/src/demuxer.h index e403fe35..73166b41 100644 --- a/app/src/demuxer.h +++ b/app/src/demuxer.h @@ -15,6 +15,8 @@ #define SC_DEMUXER_MAX_SINKS 2 struct sc_demuxer { + const char *name; // must be statically allocated (e.g. a string literal) + sc_socket socket; sc_thread thread; @@ -29,8 +31,9 @@ struct sc_demuxer_callbacks { void (*on_ended)(struct sc_demuxer *demuxer, bool eos, void *userdata); }; +// The name must be statically allocated (e.g. a string literal) void -sc_demuxer_init(struct sc_demuxer *demuxer, sc_socket socket, +sc_demuxer_init(struct sc_demuxer *demuxer, const char *name, sc_socket socket, const struct sc_demuxer_callbacks *cbs, void *cbs_userdata); void diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index e4e1355c..820f3328 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -387,7 +387,7 @@ scrcpy(struct scrcpy_options *options) { static const struct sc_demuxer_callbacks video_demuxer_cbs = { .on_ended = sc_video_demuxer_on_ended, }; - sc_demuxer_init(&s->video_demuxer, s->server.video_socket, + sc_demuxer_init(&s->video_demuxer, "video", s->server.video_socket, &video_demuxer_cbs, NULL); bool needs_decoder = options->display;