Commit 0dff771f authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '205a95f7'

* commit '205a95f7':
  wmaenc: alloc/free coded_frame instead of keeping it in the WMACodecContext
  wma: decode directly to the user-provided AVFrame
  wmapro: decode directly to the user-provided AVFrame
  wavpack: decode directly to the user-provided AVFrame

Conflicts:
	libavcodec/wavpack.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents dca6fb08 205a95f7
......@@ -129,7 +129,6 @@ typedef struct WavpackFrameContext {
typedef struct WavpackContext {
AVCodecContext *avctx;
AVFrame frame;
WavpackFrameContext *fdec[WV_MAX_FRAME_DECODERS];
int fdec_num;
......@@ -741,9 +740,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;
}
......@@ -1183,6 +1179,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;
......@@ -1218,12 +1215,12 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
}
/* get output buffer */
s->frame.nb_samples = s->samples + 1;
if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
frame->nb_samples = s->samples + 1;
if ((ret = ff_get_buffer(avctx, frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
s->frame.nb_samples = s->samples;
frame->nb_samples = s->samples;
while (buf_size > 0) {
if (!s->multichannel) {
......@@ -1244,7 +1241,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA;
}
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 AVERROR_INVALIDDATA;
......@@ -1253,9 +1250,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;
}
......
......@@ -390,6 +390,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;
}
......
......@@ -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)
......
......@@ -117,9 +117,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;
}
......@@ -800,6 +797,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;
......@@ -834,12 +832,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) {
......@@ -918,8 +916,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 buf_size;
fail:
......
......@@ -50,6 +50,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;
......@@ -85,11 +90,6 @@ static int encode_init(AVCodecContext * avctx){
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;
}
......
......@@ -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
......@@ -471,9 +470,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;
}
......@@ -1304,7 +1300,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;
......@@ -1377,8 +1373,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;
......@@ -1386,7 +1382,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++) {
......@@ -1554,7 +1550,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);
......@@ -1577,7 +1573,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
......@@ -1587,7 +1583,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;
}
......@@ -1603,9 +1599,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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment