]> git.sesse.net Git - ffmpeg/commitdiff
avformat/ttaenc: Defer freeing dynamic buffer
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 20 May 2020 19:52:09 +0000 (21:52 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 21 May 2020 03:30:26 +0000 (05:30 +0200)
The TTA muxer writes a seektable in a dynamic buffer as it receives
packets and when writing the trailer, closes the dynamic buffer using
avio_close_dyn_buf(), writes the seektable and frees the buffer. But
the TTA muxer already has a deinit function which unconditionally
calls ffio_free_dyn_buf() on the dynamic buffer, so switching to
avio_get_dyn_buf() means that one can remove the code to free the
buffer; furthermore, it also might save an allocation if the seektable
is so small that it fits into the dynamic buffer's write buffer or if
adding the padding that avio_close_dyn_buf() adds necessitated
reallocating of the underlying buffer.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/ttaenc.c

index 4860aab4c13468904797571e61fc5cc42ee0ddd2..becd3e7153652e33724786e03098a44c2ffea33f 100644 (file)
@@ -145,10 +145,8 @@ static int tta_write_trailer(AVFormatContext *s)
     /* Write Seek table */
     crc = ffio_get_checksum(tta->seek_table) ^ UINT32_MAX;
     avio_wl32(tta->seek_table, crc);
-    size = avio_close_dyn_buf(tta->seek_table, &ptr);
+    size = avio_get_dyn_buf(tta->seek_table, &ptr);
     avio_write(s->pb, ptr, size);
-    tta->seek_table = NULL;
-    av_free(ptr);
 
     /* Write audio data */
     tta_queue_flush(s);