diff --git a/app/src/decoder.c b/app/src/decoder.c index 3b94afef..41e2fe85 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -6,6 +6,9 @@ #include "video_buffer.h" #include "util/log.h" +/** Downcast packet_sink to decoder */ +#define DOWNCAST(SINK) container_of(SINK, struct decoder, packet_sink) + bool decoder_open(struct decoder *decoder, const AVCodec *codec) { decoder->codec_ctx = avcodec_alloc_context3(codec); @@ -59,7 +62,33 @@ decoder_push(struct decoder *decoder, const AVPacket *packet) { return true; } +static bool +decoder_packet_sink_open(struct sc_packet_sink *sink, const AVCodec *codec) { + struct decoder *decoder = DOWNCAST(sink); + return decoder_open(decoder, codec); +} + +static void +decoder_packet_sink_close(struct sc_packet_sink *sink) { + struct decoder *decoder = DOWNCAST(sink); + decoder_close(decoder); +} + +static bool +decoder_packet_sink_push(struct sc_packet_sink *sink, const AVPacket *packet) { + struct decoder *decoder = DOWNCAST(sink); + return decoder_push(decoder, packet); +} + void decoder_init(struct decoder *decoder, struct video_buffer *vb) { decoder->video_buffer = vb; + + static const struct sc_packet_sink_ops ops = { + .open = decoder_packet_sink_open, + .close = decoder_packet_sink_close, + .push = decoder_packet_sink_push, + }; + + decoder->packet_sink.ops = &ops; } diff --git a/app/src/decoder.h b/app/src/decoder.h index 50dd7fe0..c3f7cb73 100644 --- a/app/src/decoder.h +++ b/app/src/decoder.h @@ -3,12 +3,16 @@ #include "common.h" +#include "trait/packet_sink.h" + #include #include struct video_buffer; struct decoder { + struct sc_packet_sink packet_sink; // packet sink trait + struct video_buffer *video_buffer; AVCodecContext *codec_ctx;