From 9873d71f316cabbe42190d826b8df87791ea1034 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:13:08 -0500 Subject: [PATCH 1/4] wavpack: decode directly to the user-provided AVFrame --- libavcodec/wavpack.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index e8f34fa632..ca639ee54b 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -127,7 +127,6 @@ typedef struct WavpackFrameContext { typedef struct WavpackContext { AVCodecContext *avctx; - AVFrame frame; WavpackFrameContext *fdec[WV_MAX_FRAME_DECODERS]; int fdec_num; @@ -739,9 +738,6 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx) s->fdec_num = 0; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -1172,6 +1168,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, WavpackContext *s = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; + AVFrame *frame = data; int frame_size, ret, frame_flags; int samplecount = 0; @@ -1207,8 +1204,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = s->samples; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->samples; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -1232,7 +1229,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, return -1; } if ((samplecount = wavpack_decode_block(avctx, s->block, - s->frame.data[0], got_frame_ptr, + frame->data[0], got_frame_ptr, buf, frame_size)) < 0) { wavpack_decode_flush(avctx); return -1; @@ -1241,9 +1238,6 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, buf += frame_size; buf_size -= frame_size; } - if (*got_frame_ptr) - *(AVFrame *)data = s->frame; - return avpkt->size; } From f4a283eec49b116fa07498bb71249e0620ec0fff Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:16:21 -0500 Subject: [PATCH 2/4] wmapro: decode directly to the user-provided AVFrame --- libavcodec/wmaprodec.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index b54484ea9d..e8b9df4e7d 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -169,7 +169,6 @@ typedef struct { typedef struct WMAProDecodeCtx { /* generic decoder variables */ AVCodecContext* avctx; ///< codec context for av_log - AVFrame frame; ///< AVFrame for decoded output AVFloatDSPContext fdsp; uint8_t frame_data[MAX_FRAMESIZE + FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data @@ -461,9 +460,6 @@ static av_cold int decode_init(AVCodecContext *avctx) avctx->channel_layout = channel_mask; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -1293,7 +1289,7 @@ static int decode_subframe(WMAProDecodeCtx *s) *@return 0 if the trailer bit indicates that this is the last frame, * 1 if there are additional frames */ -static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr) +static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr) { AVCodecContext *avctx = s->avctx; GetBitContext* gb = &s->gb; @@ -1366,8 +1362,8 @@ static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr) } /* get output buffer */ - s->frame.nb_samples = s->samples_per_frame; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = s->samples_per_frame; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); s->packet_loss = 1; return 0; @@ -1375,7 +1371,7 @@ static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr) /** copy samples to the output buffer */ for (i = 0; i < avctx->channels; i++) - memcpy(s->frame.extended_data[i], s->channel[i].out, + memcpy(frame->extended_data[i], s->channel[i].out, s->samples_per_frame * sizeof(*s->channel[i].out)); for (i = 0; i < avctx->channels; i++) { @@ -1543,7 +1539,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, /** decode the cross packet frame if it is valid */ if (!s->packet_loss) - decode_frame(s, got_frame_ptr); + decode_frame(s, data, got_frame_ptr); } else if (s->num_saved_bits - s->frame_offset) { av_dlog(avctx, "ignoring %x previously saved bits\n", s->num_saved_bits - s->frame_offset); @@ -1566,7 +1562,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, (frame_size = show_bits(gb, s->log2_frame_size)) && frame_size <= remaining_bits(s, gb)) { save_bits(s, gb, frame_size, 0); - s->packet_done = !decode_frame(s, got_frame_ptr); + s->packet_done = !decode_frame(s, data, got_frame_ptr); } else if (!s->len_prefix && s->num_saved_bits > get_bits_count(&s->gb)) { /** when the frames do not have a length prefix, we don't know @@ -1576,7 +1572,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, therefore we save the incoming packet first, then we append the "previous frame" data from the next packet so that we get a buffer that only contains full frames */ - s->packet_done = !decode_frame(s, got_frame_ptr); + s->packet_done = !decode_frame(s, data, got_frame_ptr); } else s->packet_done = 1; } @@ -1592,9 +1588,6 @@ static int decode_packet(AVCodecContext *avctx, void *data, if (s->packet_loss) return AVERROR_INVALIDDATA; - if (*got_frame_ptr) - *(AVFrame *)data = s->frame; - return get_bits_count(gb) >> 3; } From c815ca36412e54e641dd0a91bc54f43f4d9d5621 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:25:52 -0500 Subject: [PATCH 3/4] wma: decode directly to the user-provided AVFrame --- libavcodec/wmadec.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c index 4edf92f5c1..6fbef08920 100644 --- a/libavcodec/wmadec.c +++ b/libavcodec/wmadec.c @@ -110,9 +110,6 @@ static int wma_decode_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; - avcodec_get_frame_defaults(&s->frame); - avctx->coded_frame = &s->frame; - return 0; } @@ -788,6 +785,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples, static int wma_decode_superframe(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; WMACodecContext *s = avctx->priv_data; @@ -821,12 +819,12 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, } /* get output buffer */ - s->frame.nb_samples = nb_frames * s->frame_len; - if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { + frame->nb_samples = nb_frames * s->frame_len; + if ((ret = ff_get_buffer(avctx, frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (float **)s->frame.extended_data; + samples = (float **)frame->extended_data; samples_offset = 0; if (s->use_bit_reservoir) { @@ -905,8 +903,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len, (int8_t *)samples - (int8_t *)data, avctx->block_align); - *got_frame_ptr = 1; - *(AVFrame *)data = s->frame; + *got_frame_ptr = 1; return avctx->block_align; fail: From 205a95f7b5178362874bc1e65eae9866723491c1 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 23 Dec 2012 20:26:15 -0500 Subject: [PATCH 4/4] wmaenc: alloc/free coded_frame instead of keeping it in the WMACodecContext --- libavcodec/wma.c | 5 +++++ libavcodec/wma.h | 1 - libavcodec/wmaenc.c | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/wma.c b/libavcodec/wma.c index 03e310bc94..ab7bcf53a8 100644 --- a/libavcodec/wma.c +++ b/libavcodec/wma.c @@ -386,6 +386,11 @@ int ff_wma_end(AVCodecContext *avctx) av_free(s->int_table[i]); } +#if FF_API_OLD_ENCODE_AUDIO + if (av_codec_is_encoder(avctx->codec)) + av_freep(&avctx->coded_frame); +#endif + return 0; } diff --git a/libavcodec/wma.h b/libavcodec/wma.h index 9312ec5dd7..ced3a8f87f 100644 --- a/libavcodec/wma.h +++ b/libavcodec/wma.h @@ -66,7 +66,6 @@ typedef struct CoefVLCTable { typedef struct WMACodecContext { AVCodecContext* avctx; - AVFrame frame; GetBitContext gb; PutBitContext pb; int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index bf8c2674b9..f110f89465 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -52,6 +52,11 @@ static int encode_init(AVCodecContext * avctx){ return AVERROR(EINVAL); } +#if FF_API_OLD_ENCODE_AUDIO + if (!(avctx->coded_frame = avcodec_alloc_frame())) + return AVERROR(ENOMEM); +#endif + /* extract flag infos */ flags1 = 0; flags2 = 1; @@ -88,11 +93,6 @@ static int encode_init(AVCodecContext * avctx){ s->frame_len; avctx->frame_size = avctx->delay = s->frame_len; -#if FF_API_OLD_ENCODE_AUDIO - avctx->coded_frame = &s->frame; - avcodec_get_frame_defaults(avctx->coded_frame); -#endif - return 0; }