From dc33fbbfd0f416fa7a3fcce1847a122e57d7a84a Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:24:24 -0500 Subject: [PATCH 1/6] mlp/truehd: decode directly to the user-provided AVFrame --- libavcodec/mlpdec.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index c0174b49b6..cf01b6e23c 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -118,7 +118,6 @@ typedef struct SubStream { typedef struct MLPDecodeContext { AVCodecContext *avctx; - AVFrame frame; /// Current access unit being read has a major sync. int is_major_sync_unit; @@ -268,9 +267,6 @@ static av_cold int mlp_decode_init(AVCodecContext *avctx) m->substream[substr].lossless_check_data = 0xffffffff; ff_mlpdsp_init(&m->dsp); - avcodec_get_frame_defaults(&m->frame); - avctx->coded_frame = &m->frame; - return 0; } @@ -973,7 +969,7 @@ static void rematrix_channels(MLPDecodeContext *m, unsigned int substr) /** Write the audio data into the output buffer. */ static int output_data(MLPDecodeContext *m, unsigned int substr, - void *data, int *got_frame_ptr) + AVFrame *frame, int *got_frame_ptr) { AVCodecContext *avctx = m->avctx; SubStream *s = &m->substream[substr]; @@ -989,13 +985,13 @@ static int output_data(MLPDecodeContext *m, unsigned int substr, } /* get output buffer */ - m->frame.nb_samples = s->blockpos; - if ((ret = ff_get_buffer(avctx, &m->frame)) < 0) { + frame->nb_samples = s->blockpos; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - data_32 = (int32_t *)m->frame.data[0]; - data_16 = (int16_t *)m->frame.data[0]; + data_32 = (int32_t *)frame->data[0]; + data_16 = (int16_t *)frame->data[0]; for (i = 0; i < s->blockpos; i++) { for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) { @@ -1008,8 +1004,7 @@ static int output_data(MLPDecodeContext *m, unsigned int substr, } } - *got_frame_ptr = 1; - *(AVFrame *)data = m->frame; + *got_frame_ptr = 1; return 0; } From 2c785e250a1f4a6ee2b35e1c86dda79553d2a6c1 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:34:54 -0500 Subject: [PATCH 2/6] mpegaudio: decode directly to the user-provided AVFrame --- libavcodec/mpegaudiodec.c | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 3524cff146..03cc6b080b 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -24,6 +24,7 @@ * MPEG Audio decoder */ +#include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/float_dsp.h" #include "avcodec.h" @@ -84,7 +85,7 @@ typedef struct MPADecodeContext { AVCodecContext* avctx; MPADSPContext mpadsp; AVFloatDSPContext fdsp; - AVFrame frame; + AVFrame *frame; } MPADecodeContext; #if CONFIG_FLOAT @@ -448,9 +449,6 @@ static av_cold int decode_init(AVCodecContext * avctx) if (avctx->codec_id == AV_CODEC_ID_MP3ADU) s->adu_mode = 1; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -1612,12 +1610,13 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples, /* get output buffer */ if (!samples) { - s->frame.nb_samples = s->avctx->frame_size; - if ((ret = ff_get_buffer(s->avctx, &s->frame)) < 0) { + av_assert0(s->frame != NULL); + s->frame->nb_samples = s->avctx->frame_size; + if ((ret = ff_get_buffer(s->avctx, s->frame)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (OUT_INT **)s->frame.extended_data; + samples = (OUT_INT **)s->frame->extended_data; } /* apply the synthesis filter */ @@ -1679,11 +1678,13 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, buf_size= s->frame_size; } + s->frame = data; + ret = mp_decode_frame(s, NULL, buf, buf_size); if (ret >= 0) { - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; - avctx->sample_rate = s->sample_rate; + s->frame->nb_samples = avctx->frame_size; + *got_frame_ptr = 1; + avctx->sample_rate = s->sample_rate; //FIXME maybe move the other codec info stuff from above here too } else { av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n"); @@ -1750,14 +1751,15 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data, s->frame_size = len; + s->frame = data; + ret = mp_decode_frame(s, NULL, buf, buf_size); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n"); return ret; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return buf_size; } @@ -1769,7 +1771,6 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data, * Context for MP3On4 decoder */ typedef struct MP3On4DecodeContext { - AVFrame *frame; int frames; ///< number of mp3 frames per block (number of mp3 decoder instances) int syncword; ///< syncword patch const uint8_t *coff; ///< channel offsets in output buffer @@ -1858,7 +1859,6 @@ static int decode_init_mp3on4(AVCodecContext * avctx) // Put decoder context in place to make init_decode() happy avctx->priv_data = s->mp3decctx[0]; decode_init(avctx); - s->frame = avctx->coded_frame; // Restore mp3on4 context pointer avctx->priv_data = s; s->mp3decctx[0]->adu_mode = 1; // Set adu mode @@ -1895,6 +1895,7 @@ static void flush_mp3on4(AVCodecContext *avctx) static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MP3On4DecodeContext *s = avctx->priv_data; @@ -1906,12 +1907,12 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, int fr, ch, ret; /* get output buffer */ - s->frame->nb_samples = MPA_FRAME_SIZE; - if ((ret = ff_get_buffer(avctx, s->frame)) < 0) { + frame->nb_samples = MPA_FRAME_SIZE; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out_samples = (OUT_INT **)s->frame->extended_data; + out_samples = (OUT_INT **)frame->extended_data; // Discard too short frames if (buf_size < HEADER_SIZE) @@ -1961,9 +1962,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, /* update codec info */ avctx->sample_rate = s->mp3decctx[0]->sample_rate; - s->frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT)); - *got_frame_ptr = 1; - *(AVFrame *)data = *s->frame; + frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT)); + *got_frame_ptr = 1; return buf_size; } From 3a23752c5a065ce34dc56491836e1db1fc3b88ae Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:38:34 -0500 Subject: [PATCH 3/6] mpc7/8: decode directly to the user-provided AVFrame --- libavcodec/mpc.h | 1 - libavcodec/mpc7.c | 13 +++++-------- libavcodec/mpc8.c | 13 +++++-------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/libavcodec/mpc.h b/libavcodec/mpc.h index 86d4b6d393..cbb121eddd 100644 --- a/libavcodec/mpc.h +++ b/libavcodec/mpc.h @@ -50,7 +50,6 @@ typedef struct Band { }Band; typedef struct MPCContext { - AVFrame frame; DSPContext dsp; MPADSPContext mpadsp; GetBitContext gb; diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c index 6a2b120230..f151f9c304 100644 --- a/libavcodec/mpc7.c +++ b/libavcodec/mpc7.c @@ -139,9 +139,6 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx) } vlc_initialized = 1; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -201,6 +198,7 @@ static int get_scale_idx(GetBitContext *gb, int ref) static int mpc7_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size; MPCContext *c = avctx->priv_data; @@ -230,8 +228,8 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, buf_size -= 4; /* get output buffer */ - c->frame.nb_samples = last_frame ? c->lastframelen : MPC_FRAME_SIZE; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = last_frame ? c->lastframelen : MPC_FRAME_SIZE; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -295,7 +293,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, for(ch = 0; ch < 2; ch++) idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off); - ff_mpc_dequantize_and_synth(c, mb, (int16_t **)c->frame.extended_data, 2); + ff_mpc_dequantize_and_synth(c, mb, (int16_t **)frame->extended_data, 2); bits_used = get_bits_count(&gb); bits_avail = buf_size * 8; @@ -309,8 +307,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, return avpkt->size; } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return avpkt->size; } diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c index a270be36fd..1b32c4b3fa 100644 --- a/libavcodec/mpc8.c +++ b/libavcodec/mpc8.c @@ -230,15 +230,13 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) } vlc_initialized = 1; - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } static int mpc8_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; MPCContext *c = avctx->priv_data; @@ -250,8 +248,8 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data, int last[2]; /* get output buffer */ - c->frame.nb_samples = MPC_FRAME_SIZE; - if ((res = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = MPC_FRAME_SIZE; + if ((res = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return res; } @@ -407,7 +405,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data, } ff_mpc_dequantize_and_synth(c, maxband - 1, - (int16_t **)c->frame.extended_data, + (int16_t **)frame->extended_data, avctx->channels); c->cur_frame++; @@ -418,8 +416,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data, if(c->cur_frame >= c->frames) c->cur_frame = 0; - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return c->cur_frame ? c->last_bits_used >> 3 : buf_size; } From 0fe4056f953ab2a6430d72e74246eb391dcf6db9 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:39:44 -0500 Subject: [PATCH 4/6] nellymoser: decode directly to the user-provided AVFrame --- libavcodec/nellymoserdec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c index 08cc4ab15b..e427b23a07 100644 --- a/libavcodec/nellymoserdec.c +++ b/libavcodec/nellymoserdec.c @@ -49,7 +49,6 @@ typedef struct NellyMoserDecodeContext { AVCodecContext* avctx; - AVFrame frame; AVLFG random_state; GetBitContext gb; float scale_bias; @@ -136,15 +135,13 @@ static av_cold int decode_init(AVCodecContext * avctx) { avctx->channels = 1; avctx->channel_layout = AV_CH_LAYOUT_MONO; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } static int decode_tag(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; NellyMoserDecodeContext *s = avctx->priv_data; @@ -169,12 +166,12 @@ static int decode_tag(AVCodecContext *avctx, void *data, */ /* get output buffer */ - s->frame.nb_samples = NELLY_SAMPLES * blocks; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = NELLY_SAMPLES * blocks; + 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.data[0]; + samples_flt = (float *)frame->data[0]; for (i=0 ; iframe; + *got_frame_ptr = 1; return buf_size; } From 0905c96390b048939a57ffd6bc919b0e44d41be0 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:41:46 -0500 Subject: [PATCH 5/6] pcm-bluray: decode directly to the user-provided AVFrame --- libavcodec/pcm-mpeg.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/libavcodec/pcm-mpeg.c b/libavcodec/pcm-mpeg.c index c8c683d11b..41bcb3e395 100644 --- a/libavcodec/pcm-mpeg.c +++ b/libavcodec/pcm-mpeg.c @@ -121,26 +121,12 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx, return 0; } -typedef struct PCMBRDecode { - AVFrame frame; -} PCMBRDecode; - -static av_cold int pcm_bluray_decode_init(AVCodecContext * avctx) -{ - PCMBRDecode *s = avctx->priv_data; - - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - - return 0; -} - static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *src = avpkt->data; int buf_size = avpkt->size; - PCMBRDecode *s = avctx->priv_data; GetByteContext gb; int num_source_channels, channel, retval; int sample_size, samples; @@ -165,13 +151,13 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, samples = buf_size / sample_size; /* get output buffer */ - s->frame.nb_samples = samples; - if ((retval = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = samples; + if ((retval = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return retval; } - dst16 = (int16_t *)s->frame.data[0]; - dst32 = (int32_t *)s->frame.data[0]; + dst16 = (int16_t *)frame->data[0]; + dst32 = (int32_t *)frame->data[0]; if (samples) { switch (avctx->channel_layout) { @@ -305,8 +291,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; retval = bytestream2_tell(&gb); if (avctx->debug & FF_DEBUG_BITSTREAM) @@ -319,8 +304,6 @@ AVCodec ff_pcm_bluray_decoder = { .name = "pcm_bluray", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_PCM_BLURAY, - .priv_data_size = sizeof(PCMBRDecode), - .init = pcm_bluray_decode_init, .decode = pcm_bluray_decode_frame, .capabilities = CODEC_CAP_DR1, .sample_fmts = (const enum AVSampleFormat[]){ From 1b9b6d6e5ea556b6d307f9d473f54f6406fdc3c8 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:43:11 -0500 Subject: [PATCH 6/6] qcelp: decode directly to the user-provided AVFrame --- libavcodec/qcelpdec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c index 59220d53e3..9c7855d78e 100644 --- a/libavcodec/qcelpdec.c +++ b/libavcodec/qcelpdec.c @@ -53,7 +53,6 @@ typedef enum { } qcelp_packet_rate; typedef struct { - AVFrame avframe; GetBitContext gb; qcelp_packet_rate bitrate; QCELPFrame frame; /**< unpacked data frame */ @@ -97,9 +96,6 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx) for (i = 0; i < 10; i++) q->prev_lspf[i] = (i + 1) / 11.; - avcodec_get_frame_defaults(&q->avframe); - avctx->coded_frame = &q->avframe; - return 0; } @@ -690,6 +686,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; QCELPContext *q = avctx->priv_data; + AVFrame *frame = data; float *outbuffer; int i, ret; float quantized_lspf[10], lpc[10]; @@ -697,12 +694,12 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, float *formant_mem; /* get output buffer */ - q->avframe.nb_samples = 160; - if ((ret = ff_get_buffer(avctx, &q->avframe)) < 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; } - outbuffer = (float *)q->avframe.data[0]; + outbuffer = (float *)frame->data[0]; if ((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) { warn_insufficient_frame_quality(avctx, "bitrate cannot be determined."); @@ -785,8 +782,7 @@ erasure: memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf)); q->prev_bitrate = q->bitrate; - *got_frame_ptr = 1; - *(AVFrame *)data = q->avframe; + *got_frame_ptr = 1; return buf_size; }