7 #include "packager/media/formats/webm/seek_head.h"
11 #include "packager/third_party/libwebm/src/mkvmuxerutil.hpp"
12 #include "packager/third_party/libwebm/src/webmids.hpp"
14 namespace edash_packager {
17 const mkvmuxer::uint64 kElementIds[] = {mkvmuxer::kMkvCluster,
18 mkvmuxer::kMkvCues, mkvmuxer::kMkvInfo,
19 mkvmuxer::kMkvTracks};
20 const int kElementIdCount = arraysize(kElementIds);
22 uint64_t MaxSeekEntrySize() {
23 const uint64_t max_entry_payload_size =
26 static_cast<mkvmuxer::uint64>(std::numeric_limits<uint32_t>::max())) +
27 EbmlElementSize(mkvmuxer::kMkvSeekPosition,
28 std::numeric_limits<mkvmuxer::uint64>::max());
29 const uint64_t max_entry_size =
30 EbmlMasterElementSize(mkvmuxer::kMkvSeek, max_entry_payload_size) +
31 max_entry_payload_size;
33 return max_entry_size;
44 SeekHead::~SeekHead() {}
47 std::vector<uint64_t> element_sizes;
48 const uint64_t payload_size = GetPayloadSize(&element_sizes);
50 if (payload_size == 0) {
54 const int64_t start_pos = writer->Position();
55 if (!WriteEbmlMasterElement(writer, mkvmuxer::kMkvSeekHead, payload_size))
58 const int64_t positions[] = {cluster_pos_, cues_pos_, info_pos_, tracks_pos_};
59 for (
int i = 0; i < kElementIdCount; ++i) {
60 if (element_sizes[i] == 0)
63 const mkvmuxer::uint64 position =
64 static_cast<mkvmuxer::uint64
>(positions[i]);
65 if (!WriteEbmlMasterElement(writer, mkvmuxer::kMkvSeek, element_sizes[i]) ||
66 !WriteEbmlElement(writer, mkvmuxer::kMkvSeekID, kElementIds[i]) ||
67 !WriteEbmlElement(writer, mkvmuxer::kMkvSeekPosition, position))
73 const uint64_t max_payload_size = kElementIdCount * MaxSeekEntrySize();
74 const uint64_t total_void_size =
75 EbmlMasterElementSize(mkvmuxer::kMkvSeekHead, max_payload_size) +
78 const uint64_t extra_void =
79 total_void_size - (writer->Position() - start_pos);
80 if (!WriteVoidElement(writer, extra_void))
88 const uint64_t payload_size = kElementIdCount * MaxSeekEntrySize();
89 const uint64_t total_size =
90 EbmlMasterElementSize(mkvmuxer::kMkvSeekHead, payload_size) +
94 const uint64_t written = WriteVoidElement(writer, total_size);
101 uint64_t SeekHead::GetPayloadSize(std::vector<uint64_t>* data) {
102 const int64_t positions[] = {cluster_pos_, cues_pos_, info_pos_, tracks_pos_};
103 uint64_t total_payload_size = 0;
104 data->resize(kElementIdCount);
105 for (
int i = 0; i < kElementIdCount; ++i) {
106 if (positions[i] < 0) {
111 const mkvmuxer::uint64 position =
112 static_cast<mkvmuxer::uint64
>(positions[i]);
113 (*data)[i] = EbmlElementSize(mkvmuxer::kMkvSeekID, kElementIds[i]) +
114 EbmlElementSize(mkvmuxer::kMkvSeekPosition, position);
115 total_payload_size +=
116 data->at(i) + EbmlMasterElementSize(mkvmuxer::kMkvSeek, data->at(i));
119 return total_payload_size;