[FFmpeg-cvslog] avformat/flacenc: Don't allocate updated streaminfo separately

Andreas Rheinhardt git at videolan.org
Sat Apr 18 03:05:25 EEST 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Sun Apr 12 18:23:44 2020 +0200| [1d15e4208f78b2b92b01992686dd47fc4159278d] | committer: Andreas Rheinhardt

avformat/flacenc: Don't allocate updated streaminfo separately

It is a small buffer of a known, fixed size and so it should simply be
put into the muxer's context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1d15e4208f78b2b92b01992686dd47fc4159278d
---

 libavformat/flacenc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 42c1efec54..a043274df6 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -42,7 +42,8 @@ typedef struct FlacMuxerContext {
     AVPacketList *queue, *queue_end;
 
     /* updated streaminfo sent by the encoder at the end */
-    uint8_t *streaminfo;
+    uint8_t streaminfo[FLAC_STREAMINFO_SIZE];
+    int updated_streaminfo;
 
     unsigned attached_types;
 } FlacMuxerContext;
@@ -294,12 +295,8 @@ static int flac_write_audio_packet(struct AVFormatContext *s, AVPacket *pkt)
     streaminfo = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
                                          &streaminfo_size);
     if (streaminfo && streaminfo_size == FLAC_STREAMINFO_SIZE) {
-        av_freep(&c->streaminfo);
-
-        c->streaminfo = av_malloc(FLAC_STREAMINFO_SIZE);
-        if (!c->streaminfo)
-            return AVERROR(ENOMEM);
         memcpy(c->streaminfo, streaminfo, FLAC_STREAMINFO_SIZE);
+        c->updated_streaminfo = 1;
     }
 
     if (pkt->size)
@@ -338,7 +335,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
         flac_queue_flush(s);
     }
 
-    if (!c->write_header || !c->streaminfo)
+    if (!c->write_header || !c->updated_streaminfo)
         return 0;
 
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
@@ -359,7 +356,6 @@ static void flac_deinit(struct AVFormatContext *s)
     FlacMuxerContext *c = s->priv_data;
 
     ff_packet_list_free(&c->queue, &c->queue_end);
-    av_freep(&c->streaminfo);
 }
 
 static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)



More information about the ffmpeg-cvslog mailing list