From fd7242ddbdd3bb3bedc3b520d8c80f4512742074 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Tue, 20 Jul 2010 21:54:46 +0000 Subject: [PATCH] remove an unneeded av_realloc() Originally committed as revision 24375 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/libvorbis.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c index d0463adeef..4b875338a4 100644 --- a/libavcodec/libvorbis.c +++ b/libavcodec/libvorbis.c @@ -85,11 +85,14 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco return vorbis_encode_setup_init(vi); } +/* How many bytes are needed for a buffer of length 'l' */ +static int xiph_len(int l) { return (1 + l / 255 + l); } + static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) { OggVorbisContext *context = avccontext->priv_data ; ogg_packet header, header_comm, header_code; uint8_t *p; - unsigned int offset, len; + unsigned int offset; vorbis_info_init(&context->vi) ; if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) { @@ -105,9 +108,11 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) { vorbis_analysis_headerout(&context->vd, &context->vc, &header, &header_comm, &header_code); - len = header.bytes + header_comm.bytes + header_code.bytes; - avccontext->extradata_size= 64 + len + len/255; - p = avccontext->extradata= av_mallocz(avccontext->extradata_size); + avccontext->extradata_size= + 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) + + header_code.bytes; + p = avccontext->extradata = + av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); p[0] = 2; offset = 1; offset += av_xiphlacing(&p[offset], header.bytes); @@ -118,8 +123,7 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) { offset += header_comm.bytes; memcpy(&p[offset], header_code.packet, header_code.bytes); offset += header_code.bytes; - avccontext->extradata_size = offset; - avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size); + assert(offset == avccontext->extradata_size); /* vorbis_block_clear(&context->vb); vorbis_dsp_clear(&context->vd);