From 3997fef95262e1138bade4cc109176a05ecc0b6e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:04:31 -0500 Subject: [PATCH 1/5] truespeech: decode directly to the user-provided AVFrame --- libavcodec/truespeech.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c index 486e41f895..73f2de917f 100644 --- a/libavcodec/truespeech.c +++ b/libavcodec/truespeech.c @@ -36,7 +36,6 @@ * TrueSpeech decoder context */ typedef struct { - AVFrame frame; DSPContext dsp; /* input data */ DECLARE_ALIGNED(16, uint8_t, buffer)[32]; @@ -73,9 +72,6 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx) ff_dsputil_init(&c->dsp, avctx); - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -310,6 +306,7 @@ static void truespeech_save_prevvec(TSContext *c) static int truespeech_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; TSContext *c = avctx->priv_data; @@ -327,12 +324,12 @@ static int truespeech_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = iterations * 240; - if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = iterations * 240; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (int16_t *)c->frame.data[0]; + samples = (int16_t *)frame->data[0]; memset(samples, 0, iterations * 240 * sizeof(*samples)); @@ -354,8 +351,7 @@ static int truespeech_decode_frame(AVCodecContext *avctx, void *data, truespeech_save_prevvec(c); } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return buf_size; } From ad2104ba449a1a9c66271920b77ec6785e5762e4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:06:41 -0500 Subject: [PATCH 2/5] tta: decode directly to the user-provided AVFrame --- libavcodec/tta.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/libavcodec/tta.c b/libavcodec/tta.c index 5ed70e99c9..e230fafbf6 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -58,7 +58,6 @@ typedef struct TTAChannel { typedef struct TTAContext { AVCodecContext *avctx; - AVFrame frame; GetBitContext gb; const AVCRC *crc_table; @@ -303,15 +302,13 @@ static av_cold int tta_decode_init(AVCodecContext * avctx) return -1; } - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } static int tta_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; TTAContext *s = avctx->priv_data; @@ -327,15 +324,15 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, init_get_bits(&s->gb, buf, buf_size*8); /* get output buffer */ - s->frame.nb_samples = framelen; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = framelen; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } // decode directly to output buffer for 24-bit sample format if (s->bps == 3) - s->decode_buffer = (int32_t *)s->frame.data[0]; + s->decode_buffer = (int32_t *)frame->data[0]; // init per channel states for (i = 0; i < s->channels; i++) { @@ -424,7 +421,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, i++; // check for last frame if (i == s->last_frame_length && get_bits_left(&s->gb) / 8 == 4) { - s->frame.nb_samples = framelen = s->last_frame_length; + frame->nb_samples = framelen = s->last_frame_length; break; } } @@ -439,20 +436,19 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, // convert to output buffer if (s->bps == 2) { - int16_t *samples = (int16_t *)s->frame.data[0]; + int16_t *samples = (int16_t *)frame->data[0]; for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) *samples++ = *p; } else { // shift samples for 24-bit sample format - int32_t *samples = (int32_t *)s->frame.data[0]; + int32_t *samples = (int32_t *)frame->data[0]; for (i = 0; i < framelen * s->channels; i++) *samples++ <<= 8; // reset decode buffer s->decode_buffer = NULL; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return buf_size; error: From 3b7d43383f5e6caa4a43c2eda39d44133c99b973 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:08:05 -0500 Subject: [PATCH 3/5] twinvq: decode directly to the user-provided AVFrame --- libavcodec/twinvq.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c index 754d7bfa39..1ff85caa24 100644 --- a/libavcodec/twinvq.c +++ b/libavcodec/twinvq.c @@ -177,7 +177,6 @@ static const ModeTab mode_44_48 = { typedef struct TwinContext { AVCodecContext *avctx; - AVFrame frame; AVFloatDSPContext fdsp; FFTContext mdct_ctx[3]; @@ -811,6 +810,7 @@ static void read_and_decode_spectrum(TwinContext *tctx, GetBitContext *gb, static int twin_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; TwinContext *tctx = avctx->priv_data; @@ -832,12 +832,12 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data, /* get output buffer */ if (tctx->discarded_packets >= 2) { - tctx->frame.nb_samples = mtab->size; - if ((ret = ff_get_buffer(avctx, &tctx->frame)) < 0) { + frame->nb_samples = mtab->size; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - out = (float **)tctx->frame.extended_data; + out = (float **)frame->extended_data; } init_get_bits(&gb, buf, buf_size * 8); @@ -863,8 +863,7 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data, return buf_size; } - *got_frame_ptr = 1; - *(AVFrame *)data = tctx->frame;; + *got_frame_ptr = 1; return buf_size; } @@ -1166,9 +1165,6 @@ static av_cold int twin_decode_init(AVCodecContext *avctx) memset_float(tctx->bark_hist[0][0], 0.1, FF_ARRAY_ELEMS(tctx->bark_hist)); - avcodec_get_frame_defaults(&tctx->frame); - avctx->coded_frame = &tctx->frame; - return 0; } From f80f8dd4c25a1762a24c9f28dc3f07aad1ff3594 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:10:01 -0500 Subject: [PATCH 4/5] vmdaudio: decode directly to the user-provided AVFrame --- libavcodec/vmdav.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c index cffc00aa40..88cd167659 100644 --- a/libavcodec/vmdav.c +++ b/libavcodec/vmdav.c @@ -476,7 +476,6 @@ static av_cold int vmdvideo_decode_end(AVCodecContext *avctx) #define BLOCK_TYPE_SILENCE 3 typedef struct VmdAudioContext { - AVFrame frame; int out_bps; int chunk_size; } VmdAudioContext; @@ -521,9 +520,6 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx) s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2); - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, " "block align = %d, sample rate = %d\n", avctx->channels, avctx->bits_per_coded_sample, avctx->block_align, @@ -564,6 +560,7 @@ static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size, static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; const uint8_t *buf_end; int buf_size = avpkt->size; @@ -608,13 +605,14 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, audio_chunks = buf_size / s->chunk_size; /* get output buffer */ - s->frame.nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / avctx->channels; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / + avctx->channels; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - output_samples_u8 = s->frame.data[0]; - output_samples_s16 = (int16_t *)s->frame.data[0]; + output_samples_u8 = frame->data[0]; + output_samples_s16 = (int16_t *)frame->data[0]; /* decode silent chunks */ if (silent_chunks > 0) { @@ -644,8 +642,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, } } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avpkt->size; } From ee6ca11b657515ad736ec0d2b8635e098d0a2680 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:11:36 -0500 Subject: [PATCH 5/5] vorbis: decode directly to the user-provided AVFrame --- libavcodec/vorbisdec.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 791314e9fc..158bd6f57c 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -123,7 +123,6 @@ typedef struct { typedef struct vorbis_context_s { AVCodecContext *avccontext; - AVFrame frame; GetBitContext gb; VorbisDSPContext dsp; AVFloatDSPContext fdsp; @@ -1030,9 +1029,6 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) avccontext->channels = vc->audio_channels; avccontext->sample_rate = vc->audio_samplerate; - avcodec_get_frame_defaults(&vc->frame); - avccontext->coded_frame = &vc->frame; - return 0; } @@ -1643,6 +1639,7 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; vorbis_context *vc = avccontext->priv_data; + AVFrame *frame = data; GetBitContext *gb = &vc->gb; float *channel_ptrs[255]; int i, len, ret; @@ -1650,19 +1647,19 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data, av_dlog(NULL, "packet length %d \n", buf_size); /* get output buffer */ - vc->frame.nb_samples = vc->blocksize[1] / 2; - if ((ret = ff_get_buffer(avccontext, &vc->frame)) < 0) { + frame->nb_samples = vc->blocksize[1] / 2; + if ((ret = ff_get_buffer(avccontext, frame)) < 0) { av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } if (vc->audio_channels > 8) { for (i = 0; i < vc->audio_channels; i++) - channel_ptrs[i] = (float *)vc->frame.extended_data[i]; + channel_ptrs[i] = (float *)frame->extended_data[i]; } else { for (i = 0; i < vc->audio_channels; i++) { int ch = ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i]; - channel_ptrs[ch] = (float *)vc->frame.extended_data[i]; + channel_ptrs[ch] = (float *)frame->extended_data[i]; } } @@ -1680,9 +1677,8 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data, av_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb) / 8, get_bits_count(gb) % 8, len); - vc->frame.nb_samples = len; - *got_frame_ptr = 1; - *(AVFrame *)data = vc->frame; + frame->nb_samples = len; + *got_frame_ptr = 1; return buf_size; }