diff mbox

[FFmpeg-devel,06/11] avformat/matroskaenc: write a CRC32 element on Cues

Message ID 20161003233707.3624-7-jamrial@gmail.com
State Accepted
Headers show

Commit Message

James Almer Oct. 3, 2016, 11:37 p.m. UTC
Implements part of ticket #4347

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskaenc.c | 29 ++++++++++++++++-------------
 tests/ref/fate/rgb24-mkv  |  4 ++--
 tests/ref/lavf/mkv        |  8 ++++----
 3 files changed, 22 insertions(+), 19 deletions(-)
diff mbox

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index da45f7c..56ee1ec 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -514,13 +514,16 @@  static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts
 
 static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tracks, int num_tracks)
 {
-    AVIOContext *pb = s->pb;
+    MatroskaMuxContext *mkv = s->priv_data;
+    AVIOContext *dyn_cp, *pb = s->pb;
     ebml_master cues_element;
     int64_t currentpos;
-    int i, j;
+    int i, j, ret;
 
     currentpos = avio_tell(pb);
-    cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0);
+    ret = start_ebml_master_crc32(pb, &dyn_cp, &cues_element, MATROSKA_ID_CUES, 0);
+    if (ret < 0)
+        return ret;
 
     for (i = 0; i < cues->num_entries; i++) {
         ebml_master cuepoint, track_positions;
@@ -540,8 +543,8 @@  static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra
             ctp_nb ++;
         }
 
-        cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(ctp_nb));
-        put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts);
+        cuepoint = start_ebml_master(dyn_cp, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(ctp_nb));
+        put_ebml_uint(dyn_cp, MATROSKA_ID_CUETIME, pts);
 
         // put all the entries from different tracks that have the exact same
         // timestamp into the same CuePoint
@@ -553,18 +556,18 @@  static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra
             if (tracks[tracknum].has_cue && s->streams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
                 continue;
             tracks[tracknum].has_cue = 1;
-            track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);
-            put_ebml_uint(pb, MATROSKA_ID_CUETRACK           , entry[j].tracknum   );
-            put_ebml_uint(pb, MATROSKA_ID_CUECLUSTERPOSITION , entry[j].cluster_pos);
-            put_ebml_uint(pb, MATROSKA_ID_CUERELATIVEPOSITION, entry[j].relative_pos);
+            track_positions = start_ebml_master(dyn_cp, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);
+            put_ebml_uint(dyn_cp, MATROSKA_ID_CUETRACK           , entry[j].tracknum   );
+            put_ebml_uint(dyn_cp, MATROSKA_ID_CUECLUSTERPOSITION , entry[j].cluster_pos);
+            put_ebml_uint(dyn_cp, MATROSKA_ID_CUERELATIVEPOSITION, entry[j].relative_pos);
             if (entry[j].duration != -1)
-                put_ebml_uint(pb, MATROSKA_ID_CUEDURATION    , entry[j].duration);
-            end_ebml_master(pb, track_positions);
+                put_ebml_uint(dyn_cp, MATROSKA_ID_CUEDURATION    , entry[j].duration);
+            end_ebml_master(dyn_cp, track_positions);
         }
         i += j - 1;
-        end_ebml_master(pb, cuepoint);
+        end_ebml_master(dyn_cp, cuepoint);
     }
-    end_ebml_master(pb, cues_element);
+    end_ebml_master_crc32(pb, &dyn_cp, mkv, cues_element);
 
     return currentpos;
 }
diff --git a/tests/ref/fate/rgb24-mkv b/tests/ref/fate/rgb24-mkv
index 6bcffa1..d1a9b6d 100644
--- a/tests/ref/fate/rgb24-mkv
+++ b/tests/ref/fate/rgb24-mkv
@@ -1,5 +1,5 @@ 
-c368e77c46109ac20e279ff83f9649b3 *tests/data/fate/rgb24-mkv.matroska
-58340 tests/data/fate/rgb24-mkv.matroska
+7f800fb3147ca8441f6b4d8cdfeec6d5 *tests/data/fate/rgb24-mkv.matroska
+58346 tests/data/fate/rgb24-mkv.matroska
 #tb 0: 1/10
 #media_type 0: video
 #codec_id 0: rawvideo
diff --git a/tests/ref/lavf/mkv b/tests/ref/lavf/mkv
index 9c9394f..664a84d 100644
--- a/tests/ref/lavf/mkv
+++ b/tests/ref/lavf/mkv
@@ -1,6 +1,6 @@ 
-161e0ed817bd65194fd4001c0d5380f0 *./tests/data/lavf/lavf.mkv
-472920 ./tests/data/lavf/lavf.mkv
+d0376acc0f57613e193192a685d9a4d6 *./tests/data/lavf/lavf.mkv
+472926 ./tests/data/lavf/lavf.mkv
 ./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
-7afba147b92da5115095fa52e214cfee *./tests/data/lavf/lavf.mkv
-320596 ./tests/data/lavf/lavf.mkv
+a08252617efbd7de6c8262e13ca7f3e4 *./tests/data/lavf/lavf.mkv
+320602 ./tests/data/lavf/lavf.mkv
 ./tests/data/lavf/lavf.mkv CRC=0xec6c3c68