[FFmpeg-devel] [PATCH 11/15] avformat/matroskaenc: Write CRC-32 in non-seekable mode

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sat Apr 20 02:41:06 EEST 2019


Given that in both the seekable as well as the non-seekable mode dynamic
buffers are used to write level 1 elements and that now no seeks are
used in the seekable case any more, the two modes can be combined; as a
consequence, the non-seekable mode automatically inherits the ability to
write CRC-32 elements.

There are no differences in case the output is seekable; when it is not
and writing CRC-32 elements is disabled, there can still be minor
differences because before this commit, the EBML ID and length field
were counted towards the cluster size limit; now they no longer are.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/matroskaenc.c    | 14 ++------------
 tests/fate/matroska.mak      |  2 +-
 tests/fate/wavpack.mak       |  4 ++--
 tests/ref/fate/binsub-mksenc |  2 +-
 4 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 2875552469..d9a7ca9ad1 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -336,20 +336,15 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master)
 static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv,
                                    ebml_master *master, uint32_t elementid, uint64_t expectedsize)
 {
-    int ret;
+    int ret, bytes = expectedsize ? ebml_num_size(expectedsize) : 8;
 
     if ((ret = avio_open_dyn_buf(dyn_cp)) < 0)
         return ret;
 
-    if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
-        int bytes = expectedsize ? ebml_num_size(expectedsize) : 8;
-
         put_ebml_id(pb, elementid);
         *master = (ebml_master) { avio_tell(pb), bytes };
         if (mkv->write_crc)
             put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */
-    } else
-        *master = start_ebml_master(*dyn_cp, elementid, expectedsize);
 
     return 0;
 }
@@ -360,7 +355,6 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk
     uint8_t *buf, crc[4];
     int size, skip = 0;
 
-    if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
         size = avio_close_dyn_buf(*dyn_cp, &buf);
         put_ebml_num(pb, size, master.sizebytes);
         if (mkv->write_crc) {
@@ -369,11 +363,7 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk
             put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc));
         }
         avio_write(pb, buf + skip, size - skip);
-    } else {
-        end_ebml_master(*dyn_cp, master);
-        size = avio_close_dyn_buf(*dyn_cp, &buf);
-        avio_write(pb, buf, size);
-    }
+
     av_free(buf);
     *dyn_cp = NULL;
 }
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 6bcd2b08d6..d1500a1aae 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -4,7 +4,7 @@
 FATE_MATROSKA-$(call DEMMUX, MATROSKA, MATROSKA) += fate-matroska-remux
 fate-matroska-remux: CMD = md5pipe -i $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-2pass-akiyo.webm -color_trc 4 -c:v copy -fflags +bitexact -strict -2 -f matroska
 fate-matroska-remux: CMP = oneline
-fate-matroska-remux: REF = 768af2b49132a0de5e0502926ab9ca4f
+fate-matroska-remux: REF = 82a5beaf7a0fb5bb2970d9bba9028086
 
 FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += fate-matroska-spherical-mono
 fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_side_data_list -select_streams v -v 0 $(TARGET_SAMPLES)/mkv/spherical.mkv
diff --git a/tests/fate/wavpack.mak b/tests/fate/wavpack.mak
index a4095a9771..7358d50d82 100644
--- a/tests/fate/wavpack.mak
+++ b/tests/fate/wavpack.mak
@@ -91,12 +91,12 @@ fate-wavpack-matroskamode: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/special/matros
 FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-mono
 fate-wavpack-matroska_mux-mono: CMD = md5pipe -i $(TARGET_SAMPLES)/wavpack/num_channels/mono_16bit_int.wv -c copy -fflags +bitexact -f matroska
 fate-wavpack-matroska_mux-mono: CMP = oneline
-fate-wavpack-matroska_mux-mono: REF = 646c726a80857b74a55ba16a6d83aeed
+fate-wavpack-matroska_mux-mono: REF = 942af4e88c4045e822508400545c47fd
 
 FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-61
 fate-wavpack-matroska_mux-61: CMD = md5pipe -i $(TARGET_SAMPLES)/wavpack/num_channels/eva_2.22_6.1_16bit-partial.wv -c copy -fflags +bitexact -f matroska
 fate-wavpack-matroska_mux-61: CMP = oneline
-fate-wavpack-matroska_mux-61: REF = 35b033bc75a0e18bbaabbaef38914837
+fate-wavpack-matroska_mux-61: REF = c874587c6172feb74df52230197396de
 
 FATE_SAMPLES_AVCONV += $(FATE_WAVPACK-yes)
 fate-wavpack: $(FATE_WAVPACK-yes)
diff --git a/tests/ref/fate/binsub-mksenc b/tests/ref/fate/binsub-mksenc
index 2f7022442f..cd958a80bc 100644
--- a/tests/ref/fate/binsub-mksenc
+++ b/tests/ref/fate/binsub-mksenc
@@ -1 +1 @@
-5d6f6f595b38d33424c186484f1c39ee
+1d0977e91873b77b4c78b61f4f3cdec5
-- 
2.21.0



More information about the ffmpeg-devel mailing list