From 4f69612d3e6190bcad325d34d8efbeff3979c338 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 18:40:50 -0500 Subject: [PATCH 1/5] libgsm: decode directly to the user-provided AVFrame --- libavcodec/libgsm.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c index cc0f05ec73..baa65bea71 100644 --- a/libavcodec/libgsm.c +++ b/libavcodec/libgsm.c @@ -148,7 +148,6 @@ AVCodec ff_libgsm_ms_encoder = { }; typedef struct LibGSMDecodeContext { - AVFrame frame; struct gsm_state *state; } LibGSMDecodeContext; @@ -175,9 +174,6 @@ static av_cold int libgsm_decode_init(AVCodecContext *avctx) { } } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -194,6 +190,7 @@ static int libgsm_decode_frame(AVCodecContext *avctx, void *data, { int i, ret; LibGSMDecodeContext *s = avctx->priv_data; + AVFrame *frame = data; uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int16_t *samples; @@ -204,12 +201,12 @@ static int libgsm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = avctx->frame_size; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = avctx->frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t *)s->frame.data[0]; + samples = (int16_t *)frame->data[0]; for (i = 0; i < avctx->frame_size / GSM_FRAME_SIZE; i++) { if ((ret = gsm_decode(s->state, buf, samples)) < 0) @@ -218,8 +215,7 @@ static int libgsm_decode_frame(AVCodecContext *avctx, void *data, samples += GSM_FRAME_SIZE; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avctx->block_align; } From 0cd08367dd6a443b89b7d6d39590ea27269689ad Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 18:42:58 -0500 Subject: [PATCH 2/5] libopencore-amr: decode directly to the user-provided AVFrame --- libavcodec/libopencore-amr.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c index 2662d0bdc5..1d1acf2cf4 100644 --- a/libavcodec/libopencore-amr.c +++ b/libavcodec/libopencore-amr.c @@ -86,7 +86,6 @@ static int get_bitrate_mode(int bitrate, void *log_ctx) typedef struct AMRContext { AVClass *av_class; - AVFrame frame; void *dec_state; void *enc_state; int enc_bitrate; @@ -119,9 +118,6 @@ static av_cold int amr_nb_decode_init(AVCodecContext *avctx) return -1; } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -137,6 +133,7 @@ static av_cold int amr_nb_decode_close(AVCodecContext *avctx) static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AMRContext *s = avctx->priv_data; @@ -148,8 +145,8 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, buf, buf_size, avctx->frame_number); /* get output buffer */ - s->frame.nb_samples = 160; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 160; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -166,10 +163,9 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, av_dlog(avctx, "packet_size=%d buf= 0x%X %X %X %X\n", packet_size, buf[0], buf[1], buf[2], buf[3]); /* call decoder */ - Decoder_Interface_Decode(s->dec_state, buf, (short *)s->frame.data[0], 0); + Decoder_Interface_Decode(s->dec_state, buf, (short *)frame->data[0], 0); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return packet_size; } @@ -315,7 +311,6 @@ AVCodec ff_libopencore_amrnb_encoder = { #include typedef struct AMRWBContext { - AVFrame frame; void *state; } AMRWBContext; @@ -329,15 +324,13 @@ static av_cold int amr_wb_decode_init(AVCodecContext *avctx) s->state = D_IF_init(); - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AMRWBContext *s = avctx->priv_data; @@ -346,8 +339,8 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; /* get output buffer */ - s->frame.nb_samples = 320; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 320; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -361,10 +354,9 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - D_IF_decode(s->state, buf, (short *)s->frame.data[0], _good_frame); + D_IF_decode(s->state, buf, (short *)frame->data[0], _good_frame); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return packet_size; } From 19b2cb268f5eb8fad3c4f6db9e7874dd52c7ad0c Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 18:45:55 -0500 Subject: [PATCH 3/5] libopus: decode directly to the user-provided AVFrame --- libavcodec/libopusdec.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c index 15fa493498..0bf040b33b 100644 --- a/libavcodec/libopusdec.c +++ b/libavcodec/libopusdec.c @@ -32,7 +32,6 @@ struct libopus_context { OpusMSDecoder *dec; - AVFrame frame; }; #define OPUS_HEAD_SIZE 19 @@ -95,8 +94,7 @@ static av_cold int libopus_decode_init(AVCodecContext *avc) opus_strerror(ret)); avc->delay = 3840; /* Decoder delay (in samples) at 48kHz */ - avcodec_get_frame_defaults(&opus->frame); - avc->coded_frame = &opus->frame; + return 0; } @@ -110,14 +108,15 @@ static av_cold int libopus_decode_close(AVCodecContext *avc) #define MAX_FRAME_SIZE (960 * 6) -static int libopus_decode(AVCodecContext *avc, void *frame, +static int libopus_decode(AVCodecContext *avc, void *data, int *got_frame_ptr, AVPacket *pkt) { struct libopus_context *opus = avc->priv_data; + AVFrame *frame = data; int ret, nb_samples; - opus->frame.nb_samples = MAX_FRAME_SIZE; - ret = ff_get_buffer(avc, &opus->frame); + frame->nb_samples = MAX_FRAME_SIZE; + ret = ff_get_buffer(avc, frame); if (ret < 0) { av_log(avc, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; @@ -125,12 +124,12 @@ static int libopus_decode(AVCodecContext *avc, void *frame, if (avc->sample_fmt == AV_SAMPLE_FMT_S16) nb_samples = opus_multistream_decode(opus->dec, pkt->data, pkt->size, - (opus_int16 *)opus->frame.data[0], - opus->frame.nb_samples, 0); + (opus_int16 *)frame->data[0], + frame->nb_samples, 0); else nb_samples = opus_multistream_decode_float(opus->dec, pkt->data, pkt->size, - (float *)opus->frame.data[0], - opus->frame.nb_samples, 0); + (float *)frame->data[0], + frame->nb_samples, 0); if (nb_samples < 0) { av_log(avc, AV_LOG_ERROR, "Decoding error: %s\n", @@ -138,9 +137,9 @@ static int libopus_decode(AVCodecContext *avc, void *frame, return ff_opus_error_to_averror(nb_samples); } - opus->frame.nb_samples = nb_samples; - *(AVFrame *)frame = opus->frame; - *got_frame_ptr = 1; + frame->nb_samples = nb_samples; + *got_frame_ptr = 1; + return pkt->size; } From bed957bb1116b4f11890087059c597b00c57f0be Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:19:25 -0500 Subject: [PATCH 4/5] libspeex: decode directly to the user-provided AVFrame --- libavcodec/libspeexdec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index 8aa82ca7a8..549ff1dfee 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -29,7 +29,6 @@ #include "internal.h" typedef struct { - AVFrame frame; SpeexBits bits; SpeexStereoState stereo; void *dec_state; @@ -102,9 +101,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback); } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -114,16 +110,17 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data, uint8_t *buf = avpkt->data; int buf_size = avpkt->size; LibSpeexContext *s = avctx->priv_data; + AVFrame *frame = data; int16_t *output; int ret, consumed = 0; /* get output buffer */ - s->frame.nb_samples = s->frame_size; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->frame_size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output = (int16_t *)s->frame.data[0]; + output = (int16_t *)frame->data[0]; /* if there is not enough data left for the smallest possible frame or the next 5 bits are a terminator code, reset the libspeex buffer using the @@ -150,8 +147,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data, if (avctx->channels == 2) speex_decode_stereo_int(output, s->frame_size, &s->stereo); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return consumed; } From 86bfcfcf2364bc837b7bb582c66a8a15a332414f Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:22:07 -0500 Subject: [PATCH 5/5] mace: decode directly to the user-provided AVFrame --- libavcodec/mace.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libavcodec/mace.c b/libavcodec/mace.c index c78a207a09..368e5d7986 100644 --- a/libavcodec/mace.c +++ b/libavcodec/mace.c @@ -155,7 +155,6 @@ typedef struct ChannelData { } ChannelData; typedef struct MACEContext { - AVFrame frame; ChannelData chd[2]; } MACEContext; @@ -227,21 +226,17 @@ static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, int tab_idx) static av_cold int mace_decode_init(AVCodecContext * avctx) { - MACEContext *ctx = avctx->priv_data; - if (avctx->channels > 2) return -1; avctx->sample_fmt = AV_SAMPLE_FMT_S16P; - avcodec_get_frame_defaults(&ctx->frame); - avctx->coded_frame = &ctx->frame; - return 0; } static int mace_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int16_t **samples; @@ -250,12 +245,12 @@ static int mace_decode_frame(AVCodecContext *avctx, void *data, int is_mace3 = (avctx->codec_id == AV_CODEC_ID_MACE3); /* get output buffer */ - ctx->frame.nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels; - if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) { + frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t **)ctx->frame.extended_data; + samples = (int16_t **)frame->extended_data; for(i = 0; i < avctx->channels; i++) { int16_t *output = samples[i]; @@ -279,8 +274,7 @@ static int mace_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = ctx->frame; + *got_frame_ptr = 1; return buf_size; }