From a6bb39add273ad05b345c49ab3c7a7fa721b55cf Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 17:10:12 -0500 Subject: [PATCH 1/5] pcm: decode directly to the user-provided AVFrame --- libavcodec/pcm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c index d6899cf52d..64a230ae03 100644 --- a/libavcodec/pcm.c +++ b/libavcodec/pcm.c @@ -199,7 +199,6 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } typedef struct PCMDecode { - AVFrame frame; short table[256]; } PCMDecode; @@ -231,9 +230,6 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx) if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec->id); - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -260,6 +256,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *src = avpkt->data; int buf_size = avpkt->size; PCMDecode *s = avctx->priv_data; + AVFrame *frame = data; int sample_size, c, n, ret, samples_per_block; uint8_t *samples; int32_t *dst_int32_t; @@ -301,12 +298,12 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, n = buf_size / sample_size; /* get output buffer */ - s->frame.nb_samples = n * samples_per_block / avctx->channels; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = n * samples_per_block / avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = s->frame.data[0]; + samples = frame->data[0]; switch (avctx->codec->id) { case AV_CODEC_ID_PCM_U32LE: @@ -341,7 +338,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, int av_unused n2; n /= avctx->channels; for (c = 0; c < avctx->channels; c++) { - samples = s->frame.extended_data[c]; + samples = frame->extended_data[c]; #if HAVE_BIGENDIAN n2 = n; DECODE(16, le16, src, samples, n2, 0, 0) @@ -414,7 +411,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, case AV_CODEC_ID_PCM_DVD: { const uint8_t *src8; - dst_int32_t = (int32_t *)s->frame.data[0]; + dst_int32_t = (int32_t *)frame->data[0]; n /= avctx->channels; switch (avctx->bits_per_coded_sample) { case 20: @@ -447,7 +444,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, int i; n /= avctx->channels; for (c = 0; c < avctx->channels; c++) { - dst_int32_t = (int32_t *)s->frame.extended_data[c]; + dst_int32_t = (int32_t *)frame->extended_data[c]; for (i = 0; i < n; i++) { // extract low 20 bits and expand to 32 bits *dst_int32_t++ = (src[2] << 28) | @@ -470,8 +467,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, return -1; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return buf_size; } From e42e5a89d62386b4dae37cd7fb0fd61d449632e6 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 17:35:54 -0500 Subject: [PATCH 2/5] bmvaudio: decode directly to the user-provided AVFrame --- libavcodec/bmv.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/libavcodec/bmv.c b/libavcodec/bmv.c index a082d3ced7..75c550f3f5 100644 --- a/libavcodec/bmv.c +++ b/libavcodec/bmv.c @@ -295,32 +295,23 @@ static av_cold int decode_end(AVCodecContext *avctx) return 0; } -typedef struct BMVAudioDecContext { - AVFrame frame; -} BMVAudioDecContext; - static const int bmv_aud_mults[16] = { 16512, 8256, 4128, 2064, 1032, 516, 258, 192, 129, 88, 64, 56, 48, 40, 36, 32 }; static av_cold int bmv_aud_decode_init(AVCodecContext *avctx) { - BMVAudioDecContext *c = avctx->priv_data; - avctx->channels = 2; avctx->channel_layout = AV_CH_LAYOUT_STEREO; avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - BMVAudioDecContext *c = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int blocks = 0, total_blocks, i; @@ -336,12 +327,12 @@ static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = total_blocks * 32; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = total_blocks * 32; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output_samples = (int16_t *)c->frame.data[0]; + output_samples = (int16_t *)frame->data[0]; for (blocks = 0; blocks < total_blocks; blocks++) { uint8_t code = *buf++; @@ -354,8 +345,7 @@ static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return buf_size; } @@ -376,7 +366,6 @@ AVCodec ff_bmv_audio_decoder = { .name = "bmv_audio", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_BMV_AUDIO, - .priv_data_size = sizeof(BMVAudioDecContext), .init = bmv_aud_decode_init, .decode = bmv_aud_decode_frame, .capabilities = CODEC_CAP_DR1, From cddf8998f1afedc21e48d395fff915bb8e6824c8 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 17:37:34 -0500 Subject: [PATCH 3/5] comfortnoise: decode directly to the user-provided AVFrame --- libavcodec/cngdec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/cngdec.c b/libavcodec/cngdec.c index 6eb0e72058..b47cda8974 100644 --- a/libavcodec/cngdec.c +++ b/libavcodec/cngdec.c @@ -28,7 +28,6 @@ #include "libavutil/lfg.h" typedef struct CNGContext { - AVFrame avframe; float *refl_coef, *target_refl_coef; float *lpc_coef; int order; @@ -58,8 +57,6 @@ static av_cold int cng_decode_init(AVCodecContext *avctx) avctx->channels = 1; avctx->sample_rate = 8000; - avcodec_get_frame_defaults(&p->avframe); - avctx->coded_frame = &p->avframe; p->order = 12; avctx->frame_size = 640; p->refl_coef = av_mallocz(p->order * sizeof(*p->refl_coef)); @@ -105,7 +102,7 @@ static void cng_decode_flush(AVCodecContext *avctx) static int cng_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - + AVFrame *frame = data; CNGContext *p = avctx->priv_data; int buf_size = avpkt->size; int ret, i; @@ -144,19 +141,18 @@ static int cng_decode_frame(AVCodecContext *avctx, void *data, ff_celp_lp_synthesis_filterf(p->filter_out + p->order, p->lpc_coef, p->excitation, avctx->frame_size, p->order); - p->avframe.nb_samples = avctx->frame_size; - if ((ret = ff_get_buffer(avctx, &p->avframe)) < 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; } - buf_out = (int16_t *)p->avframe.data[0]; + buf_out = (int16_t *)frame->data[0]; for (i = 0; i < avctx->frame_size; i++) buf_out[i] = p->filter_out[i + p->order]; memcpy(p->filter_out, p->filter_out + avctx->frame_size, p->order * sizeof(*p->filter_out)); - *got_frame_ptr = 1; - *(AVFrame *)data = p->avframe; + *got_frame_ptr = 1; return buf_size; } From 7b78321597a9d8e55153fa1f509dff8aa95c1639 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 17:41:31 -0500 Subject: [PATCH 4/5] cook: decode directly to the user-provided AVFrame --- libavcodec/cook.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/cook.c b/libavcodec/cook.c index 85565bbd6d..ba542c2e1e 100644 --- a/libavcodec/cook.c +++ b/libavcodec/cook.c @@ -123,7 +123,6 @@ typedef struct cook { AVCodecContext* avctx; DSPContext dsp; - AVFrame frame; GetBitContext gb; /* stream data */ int num_vectors; @@ -944,6 +943,7 @@ static int decode_subpacket(COOKContext *q, COOKSubpacket *p, static int cook_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; COOKContext *q = avctx->priv_data; @@ -957,12 +957,12 @@ static int cook_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ if (q->discarded_packets >= 2) { - q->frame.nb_samples = q->samples_per_channel; - if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) { + frame->nb_samples = q->samples_per_channel; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (float **)q->frame.extended_data; + samples = (float **)frame->extended_data; } /* estimate subpacket sizes */ @@ -1003,8 +1003,7 @@ static int cook_decode_frame(AVCodecContext *avctx, void *data, return avctx->block_align; } - *got_frame_ptr = 1; - *(AVFrame *) data = q->frame; + *got_frame_ptr = 1; return avctx->block_align; } @@ -1248,9 +1247,6 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) else avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&q->frame); - avctx->coded_frame = &q->frame; - #ifdef DEBUG dump_cook_context(q); #endif From 182821cff43f5f977004d105b86c47ceb20d00d6 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 17:43:47 -0500 Subject: [PATCH 5/5] dca: decode directly to the user-provided AVFrame --- libavcodec/dcadec.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c index ab2757543a..96f1ee20b2 100644 --- a/libavcodec/dcadec.c +++ b/libavcodec/dcadec.c @@ -285,7 +285,6 @@ static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, typedef struct { AVCodecContext *avctx; - AVFrame frame; /* Frame header */ int frame_type; ///< type of the current frame int samples_deficit; ///< deficit sample count @@ -1653,6 +1652,7 @@ static void dca_exss_parse_header(DCAContext *s) static int dca_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; @@ -1835,17 +1835,17 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, avctx->channels = channels; /* get output buffer */ - s->frame.nb_samples = 256 * (s->sample_blocks / 8); - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = 256 * (s->sample_blocks / 8); + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples_flt = (float **) s->frame.extended_data; + samples_flt = (float **)frame->extended_data; /* allocate buffer for extra channels if downmixing */ if (avctx->channels < full_channels) { ret = av_samples_get_buffer_size(NULL, full_channels - channels, - s->frame.nb_samples, + frame->nb_samples, avctx->sample_fmt, 0); if (ret < 0) return ret; @@ -1858,7 +1858,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, ret = av_samples_fill_arrays((uint8_t **)s->extra_channels, NULL, s->extra_channels_buffer, full_channels - channels, - s->frame.nb_samples, avctx->sample_fmt, 0); + frame->nb_samples, avctx->sample_fmt, 0); if (ret < 0) return ret; } @@ -1890,8 +1890,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, for (i = 0; i < 2 * s->lfe * 4; i++) s->lfe_data[i] = s->lfe_data[i + lfe_samples]; - *got_frame_ptr = 1; - *(AVFrame *) data = s->frame; + *got_frame_ptr = 1; return buf_size; } @@ -1925,9 +1924,6 @@ static av_cold int dca_decode_init(AVCodecContext *avctx) avctx->channels = avctx->request_channels; } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; }