Skip to content

Commit f57b62c

Browse files
committed
Give a name to decoder instances
This will be useful in logs. PR #3757 <Genymobile/scrcpy#3757>
1 parent b994288 commit f57b62c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

app/src/decoder.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sc_decoder_open(struct sc_decoder *decoder, const AVCodec *codec) {
4848
decoder->codec_ctx->flags |= AV_CODEC_FLAG_LOW_DELAY;
4949

5050
if (avcodec_open2(decoder->codec_ctx, codec, NULL) < 0) {
51-
LOGE("Could not open codec");
51+
LOGE("Decoder '%s': could not open codec", decoder->name);
5252
avcodec_free_context(&decoder->codec_ctx);
5353
return false;
5454
}
@@ -101,7 +101,8 @@ sc_decoder_push(struct sc_decoder *decoder, const AVPacket *packet) {
101101

102102
int ret = avcodec_send_packet(decoder->codec_ctx, packet);
103103
if (ret < 0 && ret != AVERROR(EAGAIN)) {
104-
LOGE("Could not send video packet: %d", ret);
104+
LOGE("Decoder '%s': could not send video packet: %d",
105+
decoder->name, ret);
105106
return false;
106107
}
107108
ret = avcodec_receive_frame(decoder->codec_ctx, decoder->frame);
@@ -114,7 +115,8 @@ sc_decoder_push(struct sc_decoder *decoder, const AVPacket *packet) {
114115

115116
av_frame_unref(decoder->frame);
116117
} else if (ret != AVERROR(EAGAIN)) {
117-
LOGE("Could not receive video frame: %d", ret);
118+
LOGE("Decoder '%s', could not receive video frame: %d",
119+
decoder->name, ret);
118120
return false;
119121
}
120122
return true;
@@ -140,7 +142,8 @@ sc_decoder_packet_sink_push(struct sc_packet_sink *sink,
140142
}
141143

142144
void
143-
sc_decoder_init(struct sc_decoder *decoder) {
145+
sc_decoder_init(struct sc_decoder *decoder, const char *name) {
146+
decoder->name = name; // statically allocated
144147
decoder->sink_count = 0;
145148

146149
static const struct sc_packet_sink_ops ops = {

app/src/decoder.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
struct sc_decoder {
1515
struct sc_packet_sink packet_sink; // packet sink trait
1616

17+
const char *name; // must be statically allocated (e.g. a string literal)
18+
1719
struct sc_frame_sink *sinks[SC_DECODER_MAX_SINKS];
1820
unsigned sink_count;
1921

2022
AVCodecContext *codec_ctx;
2123
AVFrame *frame;
2224
};
2325

26+
// The name must be statically allocated (e.g. a string literal)
2427
void
25-
sc_decoder_init(struct sc_decoder *decoder);
28+
sc_decoder_init(struct sc_decoder *decoder, const char *name);
2629

2730
void
2831
sc_decoder_add_sink(struct sc_decoder *decoder, struct sc_frame_sink *sink);

app/src/scrcpy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ scrcpy(struct scrcpy_options *options) {
441441
needs_video_decoder |= !!options->v4l2_device;
442442
#endif
443443
if (needs_video_decoder) {
444-
sc_decoder_init(&s->video_decoder);
444+
sc_decoder_init(&s->video_decoder, "video");
445445
sc_demuxer_add_sink(&s->video_demuxer, &s->video_decoder.packet_sink);
446446
}
447447

0 commit comments

Comments
 (0)