From a3de4010c2d018ce37a1bfa50b35a17b958d670e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 16:28:03 -0500 Subject: [PATCH 1/4] 8svx: decode directly to the user-provided AVFrame --- libavcodec/8svx.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c index dda181b86a..4f2a8971e7 100644 --- a/libavcodec/8svx.c +++ b/libavcodec/8svx.c @@ -34,7 +34,6 @@ /** decoder context */ typedef struct EightSvxContext { - AVFrame frame; uint8_t fib_acc[2]; const int8_t *table; @@ -85,6 +84,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { EightSvxContext *esc = avctx->priv_data; + AVFrame *frame = data; int buf_size; int ch, ret; int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR); @@ -136,26 +136,25 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - esc->frame.nb_samples = buf_size * (is_compr + 1); - if ((ret = ff_get_buffer(avctx, &esc->frame)) < 0) { + frame->nb_samples = buf_size * (is_compr + 1); + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } for (ch = 0; ch < avctx->channels; ch++) { if (is_compr) { - delta_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx], + delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx], buf_size, &esc->fib_acc[ch], esc->table); } else { - raw_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx], + raw_decode(frame->data[ch], &esc->data[ch][esc->data_idx], buf_size); } } esc->data_idx += buf_size; - *got_frame_ptr = 1; - *(AVFrame *)data = esc->frame; + *got_frame_ptr = 1; return avpkt->size; } @@ -184,9 +183,6 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx) } avctx->sample_fmt = AV_SAMPLE_FMT_U8P; - avcodec_get_frame_defaults(&esc->frame); - avctx->coded_frame = &esc->frame; - return 0; } From ffd2123095bd1ab5109c78f78c72759bb838805b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 16:37:23 -0500 Subject: [PATCH 2/4] aac: decode directly to the user-provided AVFrame --- libavcodec/aac.h | 2 +- libavcodec/aacdec.c | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index dd337a0a75..97f46e26a2 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -262,7 +262,7 @@ typedef struct ChannelElement { */ typedef struct AACContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; int is_saved; ///< Set if elements have stored overlap from previous frame. DynamicRangeControl che_drc; diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 5afc9b820e..133a557fba 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -180,8 +180,8 @@ static int frame_configure_elements(AVCodecContext *avctx) } /* get output buffer */ - ac->frame.nb_samples = 2048; - if ((ret = ff_get_buffer(avctx, &ac->frame)) < 0) { + ac->frame->nb_samples = 2048; + if ((ret = ff_get_buffer(avctx, ac->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -189,7 +189,7 @@ static int frame_configure_elements(AVCodecContext *avctx) /* map output channel pointers to AVFrame data */ for (ch = 0; ch < avctx->channels; ch++) { if (ac->output_element[ch]) - ac->output_element[ch]->ret = (float *)ac->frame.extended_data[ch]; + ac->output_element[ch]->ret = (float *)ac->frame->extended_data[ch]; } return 0; @@ -918,9 +918,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) cbrt_tableinit(); - avcodec_get_frame_defaults(&ac->frame); - avctx->coded_frame = &ac->frame; - return 0; } @@ -2389,6 +2386,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, int err, elem_id; int samples = 0, multiplier, audio_found = 0, pce_found = 0; + ac->frame = data; + if (show_bits(gb, 12) == 0xfff) { if (parse_adts_frame_header(ac, gb) < 0) { av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); @@ -2503,10 +2502,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, multiplier = (ac->oc[1].m4ac.sbr == 1) ? ac->oc[1].m4ac.ext_sample_rate > ac->oc[1].m4ac.sample_rate : 0; samples <<= multiplier; - if (samples) { - ac->frame.nb_samples = samples; - *(AVFrame *)data = ac->frame; - } + if (samples) + ac->frame->nb_samples = samples; *got_frame_ptr = !!samples; if (ac->oc[1].status && audio_found) { From 55d2e12aefa25100ff437bf1530d2aa3713d0ec5 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 16:40:37 -0500 Subject: [PATCH 3/4] ac3: decode directly to the user-provided AVFrame --- libavcodec/ac3dec.c | 13 +++++-------- libavcodec/ac3dec.h | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 82ae61857d..8d9fe5a73c 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -185,9 +185,6 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) } s->downmixed = 1; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - for (i = 0; i < AC3_MAX_CHANNELS; i++) { s->xcfptr[i] = s->transform_coeffs[i]; s->dlyptr[i] = s->delay[i]; @@ -1267,6 +1264,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) static int ac3_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; AC3DecodeContext *s = avctx->priv_data; @@ -1370,8 +1368,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, /* get output buffer */ avctx->channels = s->out_channels; - s->frame.nb_samples = s->num_blocks * 256; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->num_blocks * 256; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -1380,7 +1378,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, channel_map = ff_ac3_dec_channel_map[s->output_mode & ~AC3_OUTPUT_LFEON][s->lfe_on]; for (ch = 0; ch < s->channels; ch++) { if (ch < s->out_channels) - s->outptr[channel_map[ch]] = (float *)s->frame.data[ch]; + s->outptr[channel_map[ch]] = (float *)frame->data[ch]; else s->outptr[ch] = s->output[ch]; output[ch] = s->output[ch]; @@ -1403,8 +1401,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, for (ch = 0; ch < s->out_channels; ch++) memcpy(s->output[ch], output[ch], 1024); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return FFMIN(buf_size, s->frame_size); } diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index 8d3a311bfc..6707fd2643 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -69,7 +69,6 @@ typedef struct AC3DecodeContext { AVClass *class; ///< class for AVOptions AVCodecContext *avctx; ///< parent context - AVFrame frame; ///< AVFrame for decoded output GetBitContext gbc; ///< bitstream reader ///@name Bit stream information From e57daa876bf0cf50782550e366e589441cd8c2bd Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 16:43:07 -0500 Subject: [PATCH 4/4] adpcm: decode directly to the user-provided AVFrame --- libavcodec/adpcm.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 3b0eb8b9d0..becb480c40 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -85,7 +85,6 @@ static const int swf_index_tables[4][16] = { /* end of tables */ typedef struct ADPCMDecodeContext { - AVFrame frame; ADPCMChannelStatus status[6]; int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */ } ADPCMDecodeContext; @@ -156,9 +155,6 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; } - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -591,6 +587,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, static int adpcm_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; ADPCMDecodeContext *c = avctx->priv_data; @@ -611,20 +608,20 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = nb_samples; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = nb_samples; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (short *)c->frame.data[0]; - samples_p = (int16_t **)c->frame.extended_data; + samples = (short *)frame->data[0]; + samples_p = (int16_t **)frame->extended_data; /* use coded_samples when applicable */ /* it is always <= nb_samples, so the output buffer will be large enough */ if (coded_samples) { if (coded_samples != nb_samples) av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n"); - c->frame.nb_samples = nb_samples = coded_samples; + frame->nb_samples = nb_samples = coded_samples; } st = avctx->channels == 2 ? 1 : 0; @@ -710,7 +707,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } for (i = 0; i < avctx->channels; i++) { - samples = (int16_t *)c->frame.data[i]; + samples = (int16_t *)frame->data[i]; cs = &c->status[i]; for (n = nb_samples >> 1; n > 0; n--) { int v = bytestream2_get_byteu(&gb); @@ -1097,7 +1094,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } - c->frame.nb_samples = count * 28; + frame->nb_samples = count * 28; bytestream2_seek(&gb, 0, SEEK_END); break; } @@ -1278,8 +1275,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, return -1; } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return bytestream2_tell(&gb); }