[FFmpeg-devel] [PATCH 25/27] avformat/avienc: Simplify writing padding

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Thu Sep 23 18:29:00 EEST 2021


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
write_odml_master() was responsible for 134406 of the 135347
calls to avio_wl64() during a fate-run.

 libavformat/avienc.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 9eb072ce12..3b11841cd3 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -237,7 +237,6 @@ static void write_odml_master(AVFormatContext *s, int stream_index)
     AVCodecParameters *par = st->codecpar;
     AVIStream *avist = st->priv_data;
     unsigned char tag[5];
-    int j;
 
     /* Starting to lay out AVI OpenDML master index.
         * We want to make it JUNK entry for now, since we'd
@@ -250,10 +249,8 @@ static void write_odml_master(AVFormatContext *s, int stream_index)
     avio_wl32(pb, 0);   /* nEntriesInUse (will fill out later on) */
     ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, par->codec_type));
                         /* dwChunkId */
-    avio_wl64(pb, 0);   /* dwReserved[3] */
-    avio_wl32(pb, 0);   /* Must be 0.    */
-    for (j = 0; j < avi->master_index_max_size * 2; j++)
-        avio_wl64(pb, 0);
+    ffio_fill(pb, 0, 3 * 4 /* dwReserved[3] */
+                     + 16LL * avi->master_index_max_size);
     ff_end_tag(pb, avist->indexes.indx_start);
 }
 
@@ -351,10 +348,7 @@ static int avi_write_header(AVFormatContext *s)
         avio_wl32(pb, 0);
         avio_wl32(pb, 0);
     }
-    avio_wl32(pb, 0); /* reserved */
-    avio_wl32(pb, 0); /* reserved */
-    avio_wl32(pb, 0); /* reserved */
-    avio_wl32(pb, 0); /* reserved */
+    ffio_fill(pb, 0, 4 * 4); /* reserved */
 
     /* stream list */
     for (i = 0; i < n; i++) {
@@ -569,8 +563,7 @@ static int avi_write_header(AVFormatContext *s)
         ffio_wfourcc(pb, "odml");
         ffio_wfourcc(pb, "dmlh");
         avio_wl32(pb, 248);
-        for (i = 0; i < 248; i += 4)
-            avio_wl32(pb, 0);
+        ffio_fill(pb, 0, 248);
         ff_end_tag(pb, avi->odml_list);
     }
 
@@ -586,8 +579,7 @@ static int avi_write_header(AVFormatContext *s)
     /* some padding for easier tag editing */
     if (padding) {
         list2 = ff_start_tag(pb, "JUNK");
-        for (i = padding; i > 0; i -= 4)
-            avio_wl32(pb, 0);
+        ffio_fill(pb, 0, FFALIGN((uint32_t)padding, 4));
         ff_end_tag(pb, list2);
     }
 
-- 
2.30.2



More information about the ffmpeg-devel mailing list