changeset 12203:a2c993c7ae90 libavcodec

remove an unneeded av_realloc()
author skal
date Tue, 20 Jul 2010 21:54:46 +0000
parents 3465e53116e5
children 563339ea87aa
files libvorbis.c
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libvorbis.c	Tue Jul 20 17:54:28 2010 +0000
+++ b/libvorbis.c	Tue Jul 20 21:54:46 2010 +0000
@@ -85,11 +85,14 @@
     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 @@
     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 @@
     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);