diff mbox series

[FFmpeg-devel,7/7] avformat/matroskaenc: Reuse dynamic buffer

Message ID DB6PR0101MB2214C7BCFB6101F8B0696B5D8FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit cf30b538e522703924ce3ef68ddfbd557a29d93f
Headers show
Series [FFmpeg-devel,1/6] avformat/matroskaenc: Split assembling CodecPrivate from writing it | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Andreas Rheinhardt June 21, 2022, 3:22 a.m. UTC
Avoids some allocations.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/matroskaenc.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index acb50017b6..bfc397dbe6 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);