[FFmpeg-cvslog] avformat/matroskaenc: Reuse dynamic buffer

Andreas Rheinhardt git at videolan.org
Fri Jun 24 19:52:38 EEST 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed Jun 15 13:15:42 2022 +0200| [cf30b538e522703924ce3ef68ddfbd557a29d93f] | committer: Andreas Rheinhardt

avformat/matroskaenc: Reuse dynamic buffer

Avoids some allocations.

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

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

 libavformat/matroskaenc.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a63e491b63..4f5afc1be4 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -222,7 +222,8 @@ typedef struct MatroskaMuxContext {
      * to write the length field of EBML Masters.
      * Every user has to reset the buffer after using it and
      * different uses may not overlap. It is currently used in
-     * mkv_write_tag(). */
+     * mkv_write_tag(), in mkv_assemble_cues() as well as in
+     * mkv_update_codecprivate() and mkv_write_track(). */
     AVIOContext        *tmp_bc;
 
     AVPacket           *cur_audio_pkt;
@@ -941,17 +942,10 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts,
     return 0;
 }
 
-static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
+static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint,
                              const mkv_cues *cues, mkv_track *tracks, int num_tracks,
                              uint64_t offset)
 {
-    AVIOContext *cuepoint;
-    int ret;
-
-    ret = avio_open_dyn_buf(&cuepoint);
-    if (ret < 0)
-        return ret;
-
     for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
          entry < end;) {
         uint64_t pts = entry->pts;
@@ -981,14 +975,13 @@ static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
             end_ebml_master(cuepoint, track_positions);
         } while (++entry < end && entry->pts == pts);
         size = avio_get_dyn_buf(cuepoint, &buf);
-        if ((ret = cuepoint->error) < 0)
-            break;
+        if (cuepoint->error < 0)
+            return cuepoint->error;
         put_ebml_binary(dyn_cp, MATROSKA_ID_POINTENTRY, buf, size);
         ffio_reset_dyn_buf(cuepoint);
     }
-    ffio_free_dyn_buf(&cuepoint);
 
-    return ret;
+    return 0;
 }
 
 static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb,
@@ -2964,7 +2957,7 @@ redo_cues:
         if (ret < 0)
             return ret;
 
-        ret = mkv_assemble_cues(s->streams, cues, &mkv->cues,
+        ret = mkv_assemble_cues(s->streams, cues, mkv->tmp_bc, &mkv->cues,
                                 mkv->tracks, s->nb_streams, offset);
         if (ret < 0) {
             ffio_free_dyn_buf(&cues);



More information about the ffmpeg-cvslog mailing list