From 40e1cc87d16301e2549e9372b495887fb3e7e19a Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Mon, 4 Apr 2016 11:28:08 -0700 Subject: [PATCH] Fix bug in WebM SeekHead. The positions in the SeekHead element should be relative to the Segment payload, not the start of the file. Also added entries for Tracks and SegmentInfo. Change-Id: Id692da25fffc27d78e9f1a06d061431aeb6f1e7c --- .../testdata/bear-320x240-vorbis-golden.webm | Bin 23999 -> 23999 bytes .../testdata/bear-320x240-vp9-golden.webm | Bin 69533 -> 69533 bytes .../bear-640x360-vp8-cenc-golden.webm | Bin 115275 -> 115275 bytes .../testdata/bear-640x360-vp8-golden.webm | Bin 114725 -> 114725 bytes .../webm/encrypted_segmenter_unittest.cc | 32 ++++++++++------ packager/media/formats/webm/seek_head.cc | 11 +++--- packager/media/formats/webm/segmenter.cc | 2 + .../formats/webm/single_segment_segmenter.cc | 4 +- .../webm/single_segment_segmenter_unittest.cc | 36 +++++++++++------- .../webm/two_pass_single_segment_segmenter.cc | 2 +- 10 files changed, 55 insertions(+), 32 deletions(-) diff --git a/packager/app/test/testdata/bear-320x240-vorbis-golden.webm b/packager/app/test/testdata/bear-320x240-vorbis-golden.webm index 66a902379a3037818ff416df99f5c19f0ac7917e..8d7a28c92e0ff4f53856b2d34642d01652937a02 100644 GIT binary patch delta 77 zcmdnLn{oec#tA02yL@+d2d{1s^<0@2yrwY{!V?Qwmks0{_1)bAl#_SfRvNsfNq`^1 Wl?mPrlx&KPdoyEVqQu5dvseIe!6R<~ delta 50 zcmdnLn{oec#t9~h^L%&r1g~z9civVSyrxOO9>SFg-klBP#`eA0GTD&LWMijUEC51y B7HGxFQMnK3a@qOo&pC!+{I0MYFu`Tzg` delta 59 zcmbO`pJncRmI)?G^L=;s1g~z9civVSyrzj!-gkE|kSi0sJ3DwyGb4ZQo6QpoB_=j- N0#Reb)&@pdegN@87)1a8 diff --git a/packager/app/test/testdata/bear-640x360-vp8-cenc-golden.webm b/packager/app/test/testdata/bear-640x360-vp8-cenc-golden.webm index 76ce0e1c931c3489729bf1e686d9bf4daa5e0d7b..ea363b8a3bbd354d2ab64426d192ae9e35d3a72b 100644 GIT binary patch delta 81 zcmX@z!hX7ieS(SIZr|PA!K+(DJy)g$uW5{g@WevaWdnIfeRuZ&<>Z~Wl?JbAVpQ?n e-3#Q(1n&k)HZvZ4`DXgWMDfPXt(}aA4gvu6!X_L5 delta 78 zcmX@z!hX7ieS(SIeBa$Y!K+*3owt<+uW4co@!j1Exh&1MEXps{Fc I5#!B+09m{jB>(^b diff --git a/packager/app/test/testdata/bear-640x360-vp8-golden.webm b/packager/app/test/testdata/bear-640x360-vp8-golden.webm index 59fdcdac008f200dfdba3ca3dabde0cbf964a4b9..b176d09ab2fa3730dfba4128fbb754b56b894609 100644 GIT binary patch delta 80 zcmZ45z`nGBeS(SYF5lhV!K+(DJy)g$uW5{g@WevaWdnIfAv}5KZKXioN8jDOK$SAV YyMc1ejQfwgnK3a@qOo&pC*z#`0N79_LjV8( delta 59 zcmZ45z`nGBeS(S7eBa$Y!K+*3owt<+uW4db^xfSH* data) { - const int64_t positions[] = {cluster_pos_, cues_pos_, info_pos_, tracks_pos_}; + const int64_t positions[] = {info_pos_, tracks_pos_, cluster_pos_, cues_pos_}; uint64_t total_payload_size = 0; data->resize(kElementIdCount); for (int i = 0; i < kElementIdCount; ++i) { diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index 5db1d3f96b..72c219de3a 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -224,9 +224,11 @@ Status Segmenter::WriteSegmentHeader(uint64_t file_size, MkvWriter* writer) { return error_status; } + seek_head_.set_info_pos(writer->Position() - segment_payload_pos_); if (!segment_info_.Write(writer)) return error_status; + seek_head_.set_tracks_pos(writer->Position() - segment_payload_pos_); if (!tracks_.Write(writer)) return error_status; diff --git a/packager/media/formats/webm/single_segment_segmenter.cc b/packager/media/formats/webm/single_segment_segmenter.cc index 5a8d64603f..71eab2e3d0 100644 --- a/packager/media/formats/webm/single_segment_segmenter.cc +++ b/packager/media/formats/webm/single_segment_segmenter.cc @@ -22,7 +22,7 @@ Status SingleSegmentSegmenter::DoInitialize(scoped_ptr writer) { writer_ = writer.Pass(); Status ret = WriteSegmentHeader(0, writer_.get()); init_end_ = writer_->Position() - 1; - seek_head()->set_cluster_pos(init_end_ + 1); + seek_head()->set_cluster_pos(init_end_ + 1 - segment_payload_pos()); return ret; } @@ -32,7 +32,7 @@ Status SingleSegmentSegmenter::DoFinalize() { // Write the Cues to the end of the file. index_start_ = writer_->Position(); - seek_head()->set_cues_pos(index_start_); + seek_head()->set_cues_pos(index_start_ - segment_payload_pos()); if (!cues()->Write(writer_.get())) return Status(error::FILE_FAILURE, "Error writing Cues data."); diff --git a/packager/media/formats/webm/single_segment_segmenter_unittest.cc b/packager/media/formats/webm/single_segment_segmenter_unittest.cc index 3bcda22cde..1f216ea189 100644 --- a/packager/media/formats/webm/single_segment_segmenter_unittest.cc +++ b/packager/media/formats/webm/single_segment_segmenter_unittest.cc @@ -35,26 +35,36 @@ const uint8_t kBasicSupportData[] = { 0x42, 0x85, 0x81, 0x02, // ID: Segment, Payload Size: 343 0x18, 0x53, 0x80, 0x67, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x57, - // ID: SeekHead, Payload Size: 30 - 0x11, 0x4d, 0x9b, 0x74, 0x9e, - // ID: Seek, Payload Size: 12 - 0x4d, 0xbb, 0x8c, + // ID: SeekHead, Payload Size: 57 + 0x11, 0x4d, 0x9b, 0x74, 0xb9, + // ID: Seek, Payload Size: 11 + 0x4d, 0xbb, 0x8b, + // SeekID: binary(4) (Info) + 0x53, 0xab, 0x84, 0x15, 0x49, 0xa9, 0x66, + // SeekPosition: 89 + 0x53, 0xac, 0x81, 0x59, + // ID: Seek, Payload Size: 11 + 0x4d, 0xbb, 0x8b, + // SeekID: binary(4) (Tracks) + 0x53, 0xab, 0x84, 0x16, 0x54, 0xae, 0x6b, + // SeekPosition: 182 + 0x53, 0xac, 0x81, 0xb6, + // ID: Seek, Payload Size: 11 + 0x4d, 0xbb, 0x8b, // SeekID: binary(4) (Cluster) 0x53, 0xab, 0x84, 0x1f, 0x43, 0xb6, 0x75, - // SeekPosition: 276 - 0x53, 0xac, 0x82, 0x01, 0x14, + // SeekPosition: 228 + 0x53, 0xac, 0x81, 0xe4, // ID: Seek, Payload Size: 12 0x4d, 0xbb, 0x8c, // SeekID: binary(4) (Cues) 0x53, 0xab, 0x84, 0x1c, 0x53, 0xbb, 0x6b, - // SeekPosition: 367 - 0x53, 0xac, 0x82, 0x01, 0x75, - // ID: Void, Payload Size: 52 - 0xec, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // SeekPosition: 325 + 0x53, 0xac, 0x82, 0x01, 0x45, + // ID: Void, Payload Size: 25 + 0xec, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, // ID: Info, Payload Size: 88 0x15, 0x49, 0xa9, 0x66, 0xd8, // TimecodeScale: 1000000 diff --git a/packager/media/formats/webm/two_pass_single_segment_segmenter.cc b/packager/media/formats/webm/two_pass_single_segment_segmenter.cc index 5eb4311d15..4f2541d4c7 100644 --- a/packager/media/formats/webm/two_pass_single_segment_segmenter.cc +++ b/packager/media/formats/webm/two_pass_single_segment_segmenter.cc @@ -95,7 +95,7 @@ Status TwoPassSingleSegmentSegmenter::DoFinalize() { // Write the Cues to the end of the temp file. uint64_t cues_pos = writer()->Position(); set_index_start(cues_pos); - seek_head()->set_cues_pos(cues_pos); + seek_head()->set_cues_pos(cues_pos - segment_payload_pos()); if (!cues()->Write(writer())) return Status(error::FILE_FAILURE, "Error writing Cues data.");