summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-01-31 11:17:04 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2012-02-01 19:35:59 -0500
commit83ce51cc7d10c1589f07fda1b9f10fbc5aa93e77 (patch)
treebdff87fd288cc87a1bf3d6bbc2b0219892c4e9a5
parentb5b825c3818c2792b06f0e97d190e3c0962f1a02 (diff)
downloadffmpeg-83ce51cc7d10c1589f07fda1b9f10fbc5aa93e77.tar.gz
mpc7: use av_fast_padded_malloc()
Avoids doing malloc/free for each frame. Also fixes valgrind errors due to use of uninitialized padding bytes. Based on a patch by Reimar Döffinger <Reimar.Doeffinger@gmx.de>
-rw-r--r--libavcodec/mpc7.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index ab2f543db4..8b3a1b9a20 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -203,7 +203,6 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
int buf_size;
MPCContext *c = avctx->priv_data;
GetBitContext gb;
- uint8_t *bits;
int i, ch;
int mb = -1;
Band *bands = c->bands;
@@ -235,11 +234,11 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
return ret;
}
- bits = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!bits)
+ av_fast_padded_malloc(&c->bits, &c->buf_size, buf_size);
+ if (!c->bits)
return AVERROR(ENOMEM);
- c->dsp.bswap_buf((uint32_t *)bits, (const uint32_t *)buf, buf_size >> 2);
- init_get_bits(&gb, bits, buf_size * 8);
+ c->dsp.bswap_buf((uint32_t *)c->bits, (const uint32_t *)buf, buf_size >> 2);
+ init_get_bits(&gb, c->bits, buf_size * 8);
skip_bits_long(&gb, skip);
/* read subband indexes */
@@ -296,8 +295,6 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
ff_mpc_dequantize_and_synth(c, mb, c->frame.data[0], 2);
- av_free(bits);
-
bits_used = get_bits_count(&gb);
bits_avail = buf_size * 8;
if (!last_frame && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))) {
@@ -324,12 +321,21 @@ static void mpc7_decode_flush(AVCodecContext *avctx)
c->frames_to_skip = 32;
}
+static av_cold int mpc7_decode_close(AVCodecContext *avctx)
+{
+ MPCContext *c = avctx->priv_data;
+ av_freep(&c->bits);
+ c->buf_size = 0;
+ return 0;
+}
+
AVCodec ff_mpc7_decoder = {
.name = "mpc7",
.type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_MUSEPACK7,
.priv_data_size = sizeof(MPCContext),
.init = mpc7_decode_init,
+ .close = mpc7_decode_close,
.decode = mpc7_decode_frame,
.flush = mpc7_decode_flush,
.capabilities = CODEC_CAP_DR1,