From c1cb78d574c0429aa5e3ff3a2b3886e4bc153212 Mon Sep 17 00:00:00 2001 From: bbergeron Date: Wed, 3 Apr 2024 17:32:01 -0400 Subject: Reset Git repo and use a pseudonym to sign commits I used to sign my commits with my real name and my personal email address, which I wanted scrubbed off the "B." pseudosphere. Re-creating a new git repository was safer than simpler than re-writing the history (although the latter could've also worked but, oh well). --- audio/decoder.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 audio/decoder.c (limited to 'audio/decoder.c') diff --git a/audio/decoder.c b/audio/decoder.c new file mode 100644 index 0000000..70eacd5 --- /dev/null +++ b/audio/decoder.c @@ -0,0 +1,58 @@ +#include "decoder.h" +#include + +int decoder_init (struct Decoder *decoder, const AVCodecParameters *codecpar, AVDictionary **opts) +{ + int err; + AVCodecContext *avctx; + const AVCodec *codec; + + if ((codec = avcodec_find_decoder(codecpar->codec_id)) == NULL) + return AVERROR_DECODER_NOT_FOUND; + + /* NOTE: parameter 'codec' might be redundant here due to the next, more + * featuref-full call to avcodec_parameters_to_context. */ + if ((avctx = avcodec_alloc_context3(codec)) == NULL) + return AVERROR(ENOMEM); /* NOTE: After reading libavcodec's code, this + * error code *could* misrepresent the actual + * error, but ffmpeg won't tell us what it is + * anyway so oh well. */ + + if ((err = avcodec_parameters_to_context(avctx, codecpar)) < 0) + goto error; + + if ((err = avcodec_open2(avctx, codec, opts)) < 0) + goto error; + + /* Free previous context (no-op if avctx == NULL) and swap it with the new + * one. This allows the previous one to be left untouched in case of error, + * which is generally a nice thing to do in your code. */ + avcodec_free_context(&decoder->avctx); + decoder->avctx = avctx; + return 0; + +error: + avcodec_free_context(&avctx); + return err; +} + +int decoder_init_for_stream (struct Decoder *decoder, const AVStream *stream, AVDictionary **opts) +{ + return decoder_init(decoder, stream->codecpar, opts); +} + +int decoder_send (struct Decoder *decoder, const AVPacket *pkt) +{ + return avcodec_send_packet(decoder->avctx, pkt); +} + +int decoder_convert (struct Decoder *decoder, AVFrame *out) +{ + return avcodec_receive_frame(decoder->avctx, out); +} + +void decoder_free (struct Decoder *decoder) +{ + if (decoder == NULL) return; + avcodec_free_context(&decoder->avctx); +} -- cgit v1.2.3