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>
This commit is contained in:
parent
b5b825c381
commit
83ce51cc7d
@ -203,7 +203,6 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
|
|||||||
int buf_size;
|
int buf_size;
|
||||||
MPCContext *c = avctx->priv_data;
|
MPCContext *c = avctx->priv_data;
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
uint8_t *bits;
|
|
||||||
int i, ch;
|
int i, ch;
|
||||||
int mb = -1;
|
int mb = -1;
|
||||||
Band *bands = c->bands;
|
Band *bands = c->bands;
|
||||||
@ -235,11 +234,11 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bits = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
av_fast_padded_malloc(&c->bits, &c->buf_size, buf_size);
|
||||||
if (!bits)
|
if (!c->bits)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
c->dsp.bswap_buf((uint32_t *)bits, (const uint32_t *)buf, buf_size >> 2);
|
c->dsp.bswap_buf((uint32_t *)c->bits, (const uint32_t *)buf, buf_size >> 2);
|
||||||
init_get_bits(&gb, bits, buf_size * 8);
|
init_get_bits(&gb, c->bits, buf_size * 8);
|
||||||
skip_bits_long(&gb, skip);
|
skip_bits_long(&gb, skip);
|
||||||
|
|
||||||
/* read subband indexes */
|
/* 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);
|
ff_mpc_dequantize_and_synth(c, mb, c->frame.data[0], 2);
|
||||||
|
|
||||||
av_free(bits);
|
|
||||||
|
|
||||||
bits_used = get_bits_count(&gb);
|
bits_used = get_bits_count(&gb);
|
||||||
bits_avail = buf_size * 8;
|
bits_avail = buf_size * 8;
|
||||||
if (!last_frame && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))) {
|
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;
|
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 = {
|
AVCodec ff_mpc7_decoder = {
|
||||||
.name = "mpc7",
|
.name = "mpc7",
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
.id = CODEC_ID_MUSEPACK7,
|
.id = CODEC_ID_MUSEPACK7,
|
||||||
.priv_data_size = sizeof(MPCContext),
|
.priv_data_size = sizeof(MPCContext),
|
||||||
.init = mpc7_decode_init,
|
.init = mpc7_decode_init,
|
||||||
|
.close = mpc7_decode_close,
|
||||||
.decode = mpc7_decode_frame,
|
.decode = mpc7_decode_frame,
|
||||||
.flush = mpc7_decode_flush,
|
.flush = mpc7_decode_flush,
|
||||||
.capabilities = CODEC_CAP_DR1,
|
.capabilities = CODEC_CAP_DR1,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user