From fed74c0ae497723f4756fab5cfe3ac9b04176edf Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:56:32 -0500 Subject: [PATCH 1/4] shorten: decode directly to the user-provided AVFrame --- libavcodec/shorten.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 0d022f67cc..e678ee8e6a 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -80,7 +80,6 @@ static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 }; typedef struct ShortenContext { AVCodecContext *avctx; - AVFrame frame; GetBitContext gb; int min_framesize, max_framesize; @@ -115,9 +114,6 @@ static av_cold int shorten_decode_init(AVCodecContext * avctx) s->avctx = avctx; avctx->sample_fmt = AV_SAMPLE_FMT_S16P; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -408,6 +404,7 @@ static int read_header(ShortenContext *s) static int shorten_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; ShortenContext *s = avctx->priv_data; @@ -582,17 +579,16 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, s->cur_chan++; if (s->cur_chan == s->channels) { /* get output buffer */ - s->frame.nb_samples = s->blocksize; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->blocksize; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } /* interleave output */ - output_buffer((int16_t **)s->frame.extended_data, s->channels, + output_buffer((int16_t **)frame->extended_data, s->channels, s->blocksize, s->decoded); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; } } } From 09d6831f490179a3d87f680955f29b9d7cdda4d4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 19:58:35 -0500 Subject: [PATCH 2/4] sipr: decode directly to the user-provided AVFrame --- libavcodec/sipr.c | 15 ++++++--------- libavcodec/sipr.h | 1 - 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index 3f3c13c6e1..a36cdeff95 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -516,9 +516,6 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx) avctx->channel_layout = AV_CH_LAYOUT_MONO; avctx->sample_fmt = AV_SAMPLE_FMT_FLT; - avcodec_get_frame_defaults(&ctx->frame); - avctx->coded_frame = &ctx->frame; - return 0; } @@ -526,6 +523,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { SiprContext *ctx = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf=avpkt->data; SiprParameters parm; const SiprModeParam *mode_par = &modes[ctx->mode]; @@ -543,13 +541,13 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - ctx->frame.nb_samples = mode_par->frames_per_packet * subframe_size * - mode_par->subframe_count; - if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) { + frame->nb_samples = mode_par->frames_per_packet * subframe_size * + mode_par->subframe_count; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (float *)ctx->frame.data[0]; + samples = (float *)frame->data[0]; init_get_bits(&gb, buf, mode_par->bits_per_frame); @@ -561,8 +559,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, samples += subframe_size * mode_par->subframe_count; } - *got_frame_ptr = 1; - *(AVFrame *)data = ctx->frame; + *got_frame_ptr = 1; return mode_par->bits_per_frame >> 3; } diff --git a/libavcodec/sipr.h b/libavcodec/sipr.h index 5007c75c8a..1a35cdbfc1 100644 --- a/libavcodec/sipr.h +++ b/libavcodec/sipr.h @@ -65,7 +65,6 @@ typedef struct SiprParameters { typedef struct SiprContext { AVCodecContext *avctx; - AVFrame frame; SiprMode mode; From 903b62cc0b883094b3e0330c7fe87ca4a5ace91e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:00:41 -0500 Subject: [PATCH 3/4] smackaud: decode directly to the user-provided AVFrame --- libavcodec/smacker.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index b20a7b6d10..bc75a17e63 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -555,14 +555,8 @@ static av_cold int decode_end(AVCodecContext *avctx) } -typedef struct SmackerAudioContext { - AVFrame frame; -} SmackerAudioContext; - static av_cold int smka_decode_init(AVCodecContext *avctx) { - SmackerAudioContext *s = avctx->priv_data; - if (avctx->channels < 1 || avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n"); return AVERROR(EINVAL); @@ -570,9 +564,6 @@ static av_cold int smka_decode_init(AVCodecContext *avctx) avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -582,7 +573,7 @@ static av_cold int smka_decode_init(AVCodecContext *avctx) static int smka_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { - SmackerAudioContext *s = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; GetBitContext gb; @@ -622,13 +613,13 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = unp_size / (avctx->channels * (bits + 1)); - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = unp_size / (avctx->channels * (bits + 1)); + 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]; - samples8 = s->frame.data[0]; + samples = (int16_t *)frame->data[0]; + samples8 = frame->data[0]; // Initialize for(i = 0; i < (1 << (bits + stereo)); i++) { @@ -717,8 +708,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, av_free(h[i].values); } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return buf_size; } @@ -739,7 +729,6 @@ AVCodec ff_smackaud_decoder = { .name = "smackaud", .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_SMACKAUDIO, - .priv_data_size = sizeof(SmackerAudioContext), .init = smka_decode_init, .decode = smka_decode_frame, .capabilities = CODEC_CAP_DR1, From 4a2b26fc1b1ad123eba473a20e270f2b0ba92bca Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:02:46 -0500 Subject: [PATCH 4/4] tak: decode directly to the user-provided AVFrame --- libavcodec/takdec.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c index 1a2cc3bed7..48a424ebb7 100644 --- a/libavcodec/takdec.c +++ b/libavcodec/takdec.c @@ -45,7 +45,6 @@ typedef struct MCDParam { typedef struct TAKDecContext { AVCodecContext *avctx; // parent AVCodecContext - AVFrame frame; // AVFrame for decoded output DSPContext dsp; TAKStreamInfo ti; GetBitContext gb; // bitstream reader initialized to start at the current frame @@ -176,8 +175,6 @@ static av_cold int tak_decode_init(AVCodecContext *avctx) ff_dsputil_init(&s->dsp, avctx); s->avctx = avctx; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; set_sample_rate_params(avctx); @@ -675,6 +672,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt) { TAKDecContext *s = avctx->priv_data; + AVFrame *frame = data; GetBitContext *gb = &s->gb; int chan, i, ret, hsize; @@ -741,8 +739,8 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, s->nb_samples = s->ti.last_frame_samples ? s->ti.last_frame_samples : s->ti.frame_samples; - s->frame.nb_samples = s->nb_samples; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) + frame->nb_samples = s->nb_samples; + if ((ret = ff_get_buffer(avctx, frame)) < 0) return ret; if (avctx->bits_per_coded_sample <= 16) { @@ -759,7 +757,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, return ret; } else { for (chan = 0; chan < avctx->channels; chan++) - s->decoded[chan] = (int32_t *)s->frame.extended_data[chan]; + s->decoded[chan] = (int32_t *)frame->extended_data[chan]; } if (s->nb_samples < 16) { @@ -877,7 +875,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, switch (avctx->sample_fmt) { case AV_SAMPLE_FMT_U8P: for (chan = 0; chan < avctx->channels; chan++) { - uint8_t *samples = (uint8_t *)s->frame.extended_data[chan]; + uint8_t *samples = (uint8_t *)frame->extended_data[chan]; int32_t *decoded = s->decoded[chan]; for (i = 0; i < s->nb_samples; i++) samples[i] = decoded[i] + 0x80; @@ -885,7 +883,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, break; case AV_SAMPLE_FMT_S16P: for (chan = 0; chan < avctx->channels; chan++) { - int16_t *samples = (int16_t *)s->frame.extended_data[chan]; + int16_t *samples = (int16_t *)frame->extended_data[chan]; int32_t *decoded = s->decoded[chan]; for (i = 0; i < s->nb_samples; i++) samples[i] = decoded[i]; @@ -893,15 +891,14 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, break; case AV_SAMPLE_FMT_S32P: for (chan = 0; chan < avctx->channels; chan++) { - int32_t *samples = (int32_t *)s->frame.extended_data[chan]; + int32_t *samples = (int32_t *)frame->extended_data[chan]; for (i = 0; i < s->nb_samples; i++) samples[i] <<= 8; } break; } - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return pkt->size; }