5 #include "packager/media/formats/mp4/box_definitions.h"
9 #include "packager/base/logging.h"
10 #include "packager/media/base/bit_reader.h"
11 #include "packager/media/formats/mp4/box_buffer.h"
12 #include "packager/media/formats/mp4/rcheck.h"
15 const uint32_t kFourCCSize = 4;
18 const uint32_t kCencKeyIdSize = 16;
21 const uint8_t kUnityMatrix[] = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
23 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0, 0};
26 const char kVideoHandlerName[] =
"VideoHandler";
27 const char kAudioHandlerName[] =
"SoundHandler";
28 const char kTextHandlerName[] =
"TextHandler";
31 const uint32_t kVideoResolution = 0x00480000;
32 const uint16_t kVideoFrameCount = 1;
33 const uint16_t kVideoDepth = 0x0018;
35 const uint32_t kCompressorNameSize = 32u;
36 const char kAvcCompressorName[] =
"\012AVC Coding";
37 const char kHevcCompressorName[] =
"\013HEVC Coding";
38 const char kVpcCompressorName[] =
"\012VPC Coding";
42 const int kCueSourceIdNotSet = -1;
45 bool IsFitIn32Bits(uint64_t a) {
46 return a <= std::numeric_limits<uint32_t>::max();
49 bool IsFitIn32Bits(int64_t a) {
50 return a <= std::numeric_limits<int32_t>::max() &&
51 a >= std::numeric_limits<int32_t>::min();
54 template <
typename T1,
typename T2>
55 bool IsFitIn32Bits(T1 a1, T2 a2) {
56 return IsFitIn32Bits(a1) && IsFitIn32Bits(a2);
59 template <
typename T1,
typename T2,
typename T3>
60 bool IsFitIn32Bits(T1 a1, T2 a2, T3 a3) {
61 return IsFitIn32Bits(a1) && IsFitIn32Bits(a2) && IsFitIn32Bits(a3);
66 namespace edash_packager {
70 FileType::FileType() : major_brand(FOURCC_NULL), minor_version(0) {}
71 FileType::~FileType() {}
74 bool FileType::ReadWriteInternal(
BoxBuffer* buffer) {
76 buffer->ReadWriteFourCC(&major_brand) &&
77 buffer->ReadWriteUInt32(&minor_version));
80 num_brands = (buffer->
Size() - buffer->
Pos()) /
sizeof(FourCC);
81 compatible_brands.resize(num_brands);
83 num_brands = compatible_brands.size();
85 for (
size_t i = 0; i < num_brands; ++i)
86 RCHECK(buffer->ReadWriteFourCC(&compatible_brands[i]));
90 uint32_t FileType::ComputeSizeInternal() {
91 return HeaderSize() + kFourCCSize +
sizeof(minor_version) +
92 kFourCCSize * compatible_brands.size();
97 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {}
98 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {}
101 bool ProtectionSystemSpecificHeader::ReadWriteInternal(
BoxBuffer* buffer) {
102 if (!buffer->
Reading() && !raw_box.empty()) {
104 buffer->
writer()->AppendVector(raw_box);
108 uint32_t size = data.size();
110 buffer->ReadWriteVector(&system_id, 16) &&
111 buffer->ReadWriteUInt32(&size) &&
112 buffer->ReadWriteVector(&data, size));
117 DCHECK(raw_box.empty());
118 BoxReader* reader = buffer->
reader();
120 raw_box.assign(reader->data(), reader->data() + reader->size());
125 uint32_t ProtectionSystemSpecificHeader::ComputeSizeInternal() {
126 if (!raw_box.empty()) {
127 return raw_box.size();
129 return HeaderSize() + system_id.size() +
sizeof(uint32_t) + data.size();
133 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {}
134 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {}
137 bool SampleAuxiliaryInformationOffset::ReadWriteInternal(
BoxBuffer* buffer) {
142 uint32_t count = offsets.size();
143 RCHECK(buffer->ReadWriteUInt32(&count));
144 offsets.resize(count);
146 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
147 for (uint32_t i = 0; i < count; ++i)
152 uint32_t SampleAuxiliaryInformationOffset::ComputeSizeInternal() {
154 if (offsets.size() == 0)
156 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
157 return HeaderSize() +
sizeof(uint32_t) + num_bytes * offsets.size();
160 SampleAuxiliaryInformationSize::SampleAuxiliaryInformationSize()
161 : default_sample_info_size(0), sample_count(0) {}
162 SampleAuxiliaryInformationSize::~SampleAuxiliaryInformationSize() {}
165 bool SampleAuxiliaryInformationSize::ReadWriteInternal(
BoxBuffer* buffer) {
170 RCHECK(buffer->ReadWriteUInt8(&default_sample_info_size) &&
171 buffer->ReadWriteUInt32(&sample_count));
172 if (default_sample_info_size == 0)
173 RCHECK(buffer->ReadWriteVector(&sample_info_sizes, sample_count));
177 uint32_t SampleAuxiliaryInformationSize::ComputeSizeInternal() {
179 if (sample_count == 0)
181 return HeaderSize() +
sizeof(default_sample_info_size) +
182 sizeof(sample_count) +
183 (default_sample_info_size == 0 ? sample_info_sizes.size() : 0);
186 OriginalFormat::OriginalFormat() : format(FOURCC_NULL) {}
187 OriginalFormat::~OriginalFormat() {}
190 bool OriginalFormat::ReadWriteInternal(
BoxBuffer* buffer) {
194 uint32_t OriginalFormat::ComputeSizeInternal() {
198 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {}
199 SchemeType::~SchemeType() {}
202 bool SchemeType::ReadWriteInternal(
BoxBuffer* buffer) {
204 buffer->ReadWriteFourCC(&type) &&
205 buffer->ReadWriteUInt32(&version));
209 uint32_t SchemeType::ComputeSizeInternal() {
210 return HeaderSize() + kFourCCSize +
sizeof(version);
213 TrackEncryption::TrackEncryption()
214 : is_encrypted(false), default_iv_size(0), default_kid(16, 0) {}
215 TrackEncryption::~TrackEncryption() {}
218 bool TrackEncryption::ReadWriteInternal(
BoxBuffer* buffer) {
220 if (default_kid.size() != kCencKeyIdSize) {
221 LOG(WARNING) <<
"CENC defines key id length of " << kCencKeyIdSize
222 <<
" bytes; got " << default_kid.size()
223 <<
". Resized accordingly.";
224 default_kid.resize(kCencKeyIdSize);
228 uint8_t flag = is_encrypted ? 1 : 0;
231 buffer->ReadWriteUInt8(&flag) &&
232 buffer->ReadWriteUInt8(&default_iv_size) &&
233 buffer->ReadWriteVector(&default_kid, kCencKeyIdSize));
235 is_encrypted = (flag != 0);
237 RCHECK(default_iv_size == 8 || default_iv_size == 16);
239 RCHECK(default_iv_size == 0);
245 uint32_t TrackEncryption::ComputeSizeInternal() {
246 return HeaderSize() +
sizeof(uint32_t) + kCencKeyIdSize;
249 SchemeInfo::SchemeInfo() {}
250 SchemeInfo::~SchemeInfo() {}
253 bool SchemeInfo::ReadWriteInternal(
BoxBuffer* buffer) {
259 uint32_t SchemeInfo::ComputeSizeInternal() {
263 ProtectionSchemeInfo::ProtectionSchemeInfo() {}
264 ProtectionSchemeInfo::~ProtectionSchemeInfo() {}
267 bool ProtectionSchemeInfo::ReadWriteInternal(
BoxBuffer* buffer) {
272 if (type.type == FOURCC_CENC)
281 uint32_t ProtectionSchemeInfo::ComputeSizeInternal() {
283 if (format.format == FOURCC_NULL)
289 MovieHeader::MovieHeader()
291 modification_time(0),
297 MovieHeader::~MovieHeader() {}
300 bool MovieHeader::ReadWriteInternal(
BoxBuffer* buffer) {
303 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
306 buffer->ReadWriteUInt32(×cale) &&
309 std::vector<uint8_t> matrix(kUnityMatrix,
310 kUnityMatrix + arraysize(kUnityMatrix));
311 RCHECK(buffer->ReadWriteInt32(&rate) &&
312 buffer->ReadWriteInt16(&volume) &&
314 buffer->ReadWriteVector(&matrix, matrix.size()) &&
316 buffer->ReadWriteUInt32(&next_track_id));
320 uint32_t MovieHeader::ComputeSizeInternal() {
321 version = IsFitIn32Bits(creation_time, modification_time, duration) ? 0 : 1;
322 return HeaderSize() +
sizeof(uint32_t) * (1 + version) * 3 +
323 sizeof(timescale) +
sizeof(rate) +
sizeof(volume) +
324 sizeof(next_track_id) +
sizeof(kUnityMatrix) + 10 +
328 TrackHeader::TrackHeader()
330 modification_time(0),
338 flags = kTrackEnabled | kTrackInMovie;
340 TrackHeader::~TrackHeader() {}
343 bool TrackHeader::ReadWriteInternal(
BoxBuffer* buffer) {
346 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
349 buffer->ReadWriteUInt32(&track_id) &&
356 volume = (width != 0 && height != 0) ? 0 : 0x100;
358 std::vector<uint8_t> matrix(kUnityMatrix,
359 kUnityMatrix + arraysize(kUnityMatrix));
361 buffer->ReadWriteInt16(&layer) &&
362 buffer->ReadWriteInt16(&alternate_group) &&
363 buffer->ReadWriteInt16(&volume) &&
365 buffer->ReadWriteVector(&matrix, matrix.size()) &&
366 buffer->ReadWriteUInt32(&width) &&
367 buffer->ReadWriteUInt32(&height));
371 uint32_t TrackHeader::ComputeSizeInternal() {
372 version = IsFitIn32Bits(creation_time, modification_time, duration) ? 0 : 1;
374 sizeof(uint32_t) * (1 + version) * 3 +
sizeof(layer) +
375 sizeof(alternate_group) +
sizeof(volume) +
sizeof(width) +
376 sizeof(height) +
sizeof(kUnityMatrix) + 14;
379 SampleDescription::SampleDescription() : type(kInvalid) {}
380 SampleDescription::~SampleDescription() {}
383 bool SampleDescription::ReadWriteInternal(
BoxBuffer* buffer) {
387 count = video_entries.size();
390 count = audio_entries.size();
393 count = wvtt_entries.size();
396 NOTIMPLEMENTED() <<
"SampleDecryption type " << type
397 <<
" is not handled. Skipping.";
400 buffer->ReadWriteUInt32(&count));
403 BoxReader* reader = buffer->
reader();
405 video_entries.clear();
406 audio_entries.clear();
409 if (type == kVideo) {
410 RCHECK(reader->ReadAllChildren(&video_entries));
411 RCHECK(video_entries.size() == count);
412 }
else if (type == kAudio) {
413 RCHECK(reader->ReadAllChildren(&audio_entries));
414 RCHECK(audio_entries.size() == count);
415 }
else if (type == kText) {
416 RCHECK(reader->ReadAllChildren(&wvtt_entries));
417 RCHECK(wvtt_entries.size() == count);
420 DCHECK_LT(0u, count);
421 if (type == kVideo) {
422 for (uint32_t i = 0; i < count; ++i)
424 }
else if (type == kAudio) {
425 for (uint32_t i = 0; i < count; ++i)
427 }
else if (type == kText) {
428 for (uint32_t i = 0; i < count; ++i)
437 uint32_t SampleDescription::ComputeSizeInternal() {
438 uint32_t box_size =
HeaderSize() +
sizeof(uint32_t);
439 if (type == kVideo) {
440 for (uint32_t i = 0; i < video_entries.size(); ++i)
442 }
else if (type == kAudio) {
443 for (uint32_t i = 0; i < audio_entries.size(); ++i)
449 DecodingTimeToSample::DecodingTimeToSample() {}
450 DecodingTimeToSample::~DecodingTimeToSample() {}
453 bool DecodingTimeToSample::ReadWriteInternal(
BoxBuffer* buffer) {
454 uint32_t count = decoding_time.size();
456 buffer->ReadWriteUInt32(&count));
458 decoding_time.resize(count);
459 for (uint32_t i = 0; i < count; ++i) {
460 RCHECK(buffer->ReadWriteUInt32(&decoding_time[i].sample_count) &&
461 buffer->ReadWriteUInt32(&decoding_time[i].sample_delta));
466 uint32_t DecodingTimeToSample::ComputeSizeInternal() {
468 sizeof(DecodingTime) * decoding_time.size();
471 CompositionTimeToSample::CompositionTimeToSample() {}
472 CompositionTimeToSample::~CompositionTimeToSample() {}
475 bool CompositionTimeToSample::ReadWriteInternal(
BoxBuffer* buffer) {
476 uint32_t count = composition_offset.size();
482 for (uint32_t i = 0; i < count; ++i) {
483 if (composition_offset[i].sample_offset < 0) {
491 buffer->ReadWriteUInt32(&count));
493 composition_offset.resize(count);
494 for (uint32_t i = 0; i < count; ++i) {
495 RCHECK(buffer->ReadWriteUInt32(&composition_offset[i].sample_count));
498 uint32_t sample_offset = composition_offset[i].sample_offset;
499 RCHECK(buffer->ReadWriteUInt32(&sample_offset));
500 composition_offset[i].sample_offset = sample_offset;
502 int32_t sample_offset = composition_offset[i].sample_offset;
503 RCHECK(buffer->ReadWriteInt32(&sample_offset));
504 composition_offset[i].sample_offset = sample_offset;
510 uint32_t CompositionTimeToSample::ComputeSizeInternal() {
512 if (composition_offset.empty())
517 const uint32_t kCompositionOffsetSize =
sizeof(uint32_t) * 2;
519 kCompositionOffsetSize * composition_offset.size();
522 SampleToChunk::SampleToChunk() {}
523 SampleToChunk::~SampleToChunk() {}
526 bool SampleToChunk::ReadWriteInternal(
BoxBuffer* buffer) {
527 uint32_t count = chunk_info.size();
529 buffer->ReadWriteUInt32(&count));
531 chunk_info.resize(count);
532 for (uint32_t i = 0; i < count; ++i) {
533 RCHECK(buffer->ReadWriteUInt32(&chunk_info[i].first_chunk) &&
534 buffer->ReadWriteUInt32(&chunk_info[i].samples_per_chunk) &&
535 buffer->ReadWriteUInt32(&chunk_info[i].sample_description_index));
537 RCHECK(i == 0 ? chunk_info[i].first_chunk == 1
538 : chunk_info[i].first_chunk > chunk_info[i - 1].first_chunk);
543 uint32_t SampleToChunk::ComputeSizeInternal() {
545 sizeof(ChunkInfo) * chunk_info.size();
548 SampleSize::SampleSize() : sample_size(0), sample_count(0) {}
549 SampleSize::~SampleSize() {}
552 bool SampleSize::ReadWriteInternal(
BoxBuffer* buffer) {
554 buffer->ReadWriteUInt32(&sample_size) &&
555 buffer->ReadWriteUInt32(&sample_count));
557 if (sample_size == 0) {
559 sizes.resize(sample_count);
561 DCHECK(sample_count == sizes.size());
562 for (uint32_t i = 0; i < sample_count; ++i)
563 RCHECK(buffer->ReadWriteUInt32(&sizes[i]));
568 uint32_t SampleSize::ComputeSizeInternal() {
569 return HeaderSize() +
sizeof(sample_size) +
sizeof(sample_count) +
570 (sample_size == 0 ?
sizeof(uint32_t) * sizes.size() : 0);
573 CompactSampleSize::CompactSampleSize() : field_size(0) {}
574 CompactSampleSize::~CompactSampleSize() {}
577 bool CompactSampleSize::ReadWriteInternal(
BoxBuffer* buffer) {
578 uint32_t sample_count = sizes.size();
581 buffer->ReadWriteUInt8(&field_size) &&
582 buffer->ReadWriteUInt32(&sample_count));
585 sizes.resize(sample_count + (field_size == 4 ? 1 : 0), 0);
586 switch (field_size) {
588 for (uint32_t i = 0; i < sample_count; i += 2) {
591 RCHECK(buffer->ReadWriteUInt8(&size));
592 sizes[i] = size >> 4;
593 sizes[i + 1] = size & 0x0F;
595 DCHECK_LT(sizes[i], 16u);
596 DCHECK_LT(sizes[i + 1], 16u);
597 uint8_t size = (sizes[i] << 4) | sizes[i + 1];
598 RCHECK(buffer->ReadWriteUInt8(&size));
603 for (uint32_t i = 0; i < sample_count; ++i) {
604 uint8_t size = sizes[i];
605 RCHECK(buffer->ReadWriteUInt8(&size));
610 for (uint32_t i = 0; i < sample_count; ++i) {
611 uint16_t size = sizes[i];
612 RCHECK(buffer->ReadWriteUInt16(&size));
619 sizes.resize(sample_count);
623 uint32_t CompactSampleSize::ComputeSizeInternal() {
624 return HeaderSize() +
sizeof(uint32_t) +
sizeof(uint32_t) +
625 (field_size * sizes.size() + 7) / 8;
628 ChunkOffset::ChunkOffset() {}
629 ChunkOffset::~ChunkOffset() {}
632 bool ChunkOffset::ReadWriteInternal(
BoxBuffer* buffer) {
633 uint32_t count = offsets.size();
635 buffer->ReadWriteUInt32(&count));
637 offsets.resize(count);
638 for (uint32_t i = 0; i < count; ++i)
643 uint32_t ChunkOffset::ComputeSizeInternal() {
644 return HeaderSize() +
sizeof(uint32_t) +
sizeof(uint32_t) * offsets.size();
647 ChunkLargeOffset::ChunkLargeOffset() {}
648 ChunkLargeOffset::~ChunkLargeOffset() {}
651 bool ChunkLargeOffset::ReadWriteInternal(
BoxBuffer* buffer) {
652 uint32_t count = offsets.size();
656 if (count == 0 || IsFitIn32Bits(offsets[count - 1])) {
658 stco.offsets.swap(offsets);
661 stco.offsets.swap(offsets);
667 buffer->ReadWriteUInt32(&count));
669 offsets.resize(count);
670 for (uint32_t i = 0; i < count; ++i)
671 RCHECK(buffer->ReadWriteUInt64(&offsets[i]));
675 uint32_t ChunkLargeOffset::ComputeSizeInternal() {
676 uint32_t count = offsets.size();
677 int use_large_offset =
678 (count > 0 && !IsFitIn32Bits(offsets[count - 1])) ? 1 : 0;
680 sizeof(uint32_t) * (1 + use_large_offset) * offsets.size();
683 SyncSample::SyncSample() {}
684 SyncSample::~SyncSample() {}
687 bool SyncSample::ReadWriteInternal(
BoxBuffer* buffer) {
688 uint32_t count = sample_number.size();
690 buffer->ReadWriteUInt32(&count));
692 sample_number.resize(count);
693 for (uint32_t i = 0; i < count; ++i)
694 RCHECK(buffer->ReadWriteUInt32(&sample_number[i]));
698 uint32_t SyncSample::ComputeSizeInternal() {
700 if (sample_number.empty())
703 sizeof(uint32_t) * sample_number.size();
706 SampleTable::SampleTable() {}
707 SampleTable::~SampleTable() {}
710 bool SampleTable::ReadWriteInternal(
BoxBuffer* buffer) {
726 CompactSampleSize compact_sample_size;
727 RCHECK(reader->
ReadChild(&compact_sample_size));
728 sample_size.sample_size = 0;
729 sample_size.sample_count = compact_sample_size.sizes.size();
730 sample_size.sizes.swap(compact_sample_size.sizes);
734 if (reader->
ChildExist(&chunk_large_offset)) {
735 RCHECK(reader->
ReadChild(&chunk_large_offset));
737 ChunkOffset chunk_offset;
738 RCHECK(reader->
ReadChild(&chunk_offset));
739 chunk_large_offset.offsets.swap(chunk_offset.offsets);
749 uint32_t SampleTable::ComputeSizeInternal() {
757 EditList::EditList() {}
758 EditList::~EditList() {}
761 bool EditList::ReadWriteInternal(
BoxBuffer* buffer) {
762 uint32_t count = edits.size();
766 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
767 for (uint32_t i = 0; i < count; ++i) {
770 buffer->ReadWriteInt64NBytes(&edits[i].media_time, num_bytes) &&
771 buffer->ReadWriteInt16(&edits[i].media_rate_integer) &&
772 buffer->ReadWriteInt16(&edits[i].media_rate_fraction));
777 uint32_t EditList::ComputeSizeInternal() {
783 for (uint32_t i = 0; i < edits.size(); ++i) {
784 if (!IsFitIn32Bits(edits[i].segment_duration, edits[i].media_time)) {
790 (
sizeof(uint32_t) * (1 + version) * 2 +
sizeof(int16_t) * 2) *
798 bool Edit::ReadWriteInternal(
BoxBuffer* buffer) {
804 uint32_t Edit::ComputeSizeInternal() {
806 if (list.edits.empty())
811 HandlerReference::HandlerReference() : type(kInvalid) {}
812 HandlerReference::~HandlerReference() {}
815 bool HandlerReference::ReadWriteInternal(
BoxBuffer* buffer) {
816 FourCC hdlr_type = FOURCC_NULL;
817 std::vector<uint8_t> handler_name;
819 if (type == kVideo) {
820 hdlr_type = FOURCC_VIDE;
821 handler_name.assign(kVideoHandlerName,
822 kVideoHandlerName + arraysize(kVideoHandlerName));
823 }
else if (type == kAudio) {
824 hdlr_type = FOURCC_SOUN;
825 handler_name.assign(kAudioHandlerName,
826 kAudioHandlerName + arraysize(kAudioHandlerName));
827 }
else if (type == kText) {
828 hdlr_type = FOURCC_TEXT;
829 handler_name.assign(kTextHandlerName,
830 kTextHandlerName + arraysize(kTextHandlerName));
838 buffer->ReadWriteFourCC(&hdlr_type));
841 if (hdlr_type == FOURCC_VIDE) {
843 }
else if (hdlr_type == FOURCC_SOUN) {
850 buffer->ReadWriteVector(&handler_name, handler_name.size()));
855 uint32_t HandlerReference::ComputeSizeInternal() {
856 uint32_t box_size =
HeaderSize() + kFourCCSize + 16;
857 if (type == kVideo) {
858 box_size +=
sizeof(kVideoHandlerName);
859 }
else if (type == kAudio) {
860 box_size +=
sizeof(kAudioHandlerName);
862 box_size +=
sizeof(kTextHandlerName);
867 CodecConfigurationRecord::CodecConfigurationRecord() : box_type(FOURCC_NULL) {}
868 CodecConfigurationRecord::~CodecConfigurationRecord() {}
875 bool CodecConfigurationRecord::ReadWriteInternal(
BoxBuffer* buffer) {
878 RCHECK(buffer->ReadWriteVector(&data, buffer->
BytesLeft()));
880 RCHECK(buffer->ReadWriteVector(&data, data.size()));
885 uint32_t CodecConfigurationRecord::ComputeSizeInternal() {
891 PixelAspectRatio::PixelAspectRatio() : h_spacing(0), v_spacing(0) {}
892 PixelAspectRatio::~PixelAspectRatio() {}
895 bool PixelAspectRatio::ReadWriteInternal(
BoxBuffer* buffer) {
897 buffer->ReadWriteUInt32(&h_spacing) &&
898 buffer->ReadWriteUInt32(&v_spacing));
902 uint32_t PixelAspectRatio::ComputeSizeInternal() {
904 if (h_spacing == 0 && v_spacing == 0)
907 DCHECK(h_spacing != 0 && v_spacing != 0);
908 return HeaderSize() +
sizeof(h_spacing) +
sizeof(v_spacing);
911 VideoSampleEntry::VideoSampleEntry()
912 : format(FOURCC_NULL), data_reference_index(1), width(0), height(0) {}
914 VideoSampleEntry::~VideoSampleEntry() {}
916 if (format == FOURCC_NULL) {
917 LOG(ERROR) <<
"VideoSampleEntry should be parsed according to the "
918 <<
"handler type recovered in its Media ancestor.";
923 bool VideoSampleEntry::ReadWriteInternal(
BoxBuffer* buffer) {
924 std::vector<uint8_t> compressor_name;
927 format = buffer->
reader()->type();
931 const FourCC actual_format = GetActualFormat();
932 switch (actual_format) {
934 compressor_name.assign(
936 kAvcCompressorName + arraysize(kAvcCompressorName));
940 compressor_name.assign(
942 kHevcCompressorName + arraysize(kHevcCompressorName));
947 compressor_name.assign(
949 kVpcCompressorName + arraysize(kVpcCompressorName));
952 LOG(ERROR) << FourCCToString(actual_format) <<
" is not supported.";
955 compressor_name.resize(kCompressorNameSize);
958 uint32_t video_resolution = kVideoResolution;
959 uint16_t video_frame_count = kVideoFrameCount;
960 uint16_t video_depth = kVideoDepth;
961 int16_t predefined = -1;
963 buffer->ReadWriteUInt16(&data_reference_index) &&
965 buffer->ReadWriteUInt16(&width) &&
966 buffer->ReadWriteUInt16(&height) &&
967 buffer->ReadWriteUInt32(&video_resolution) &&
968 buffer->ReadWriteUInt32(&video_resolution) &&
970 buffer->ReadWriteUInt16(&video_frame_count) &&
971 buffer->ReadWriteVector(&compressor_name, kCompressorNameSize) &&
972 buffer->ReadWriteUInt16(&video_depth) &&
973 buffer->ReadWriteInt16(&predefined));
977 if (format == FOURCC_ENCV) {
981 while (sinf.type.type != FOURCC_CENC) {
990 const FourCC actual_format = GetActualFormat();
991 switch (actual_format) {
993 codec_config_record.box_type = FOURCC_AVCC;
997 codec_config_record.box_type = FOURCC_HVCC;
1002 codec_config_record.box_type = FOURCC_VPCC;
1005 LOG(ERROR) << FourCCToString(actual_format) <<
" is not supported.";
1013 uint32_t VideoSampleEntry::ComputeSizeInternal() {
1014 return HeaderSize() +
sizeof(data_reference_index) +
sizeof(width) +
1015 sizeof(height) +
sizeof(kVideoResolution) * 2 +
1016 sizeof(kVideoFrameCount) +
sizeof(kVideoDepth) +
1018 codec_config_record.
ComputeSize() + kCompressorNameSize + 6 + 4 + 16 +
1022 ElementaryStreamDescriptor::ElementaryStreamDescriptor() {}
1023 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {}
1026 bool ElementaryStreamDescriptor::ReadWriteInternal(
BoxBuffer* buffer) {
1029 std::vector<uint8_t> data;
1030 RCHECK(buffer->ReadWriteVector(&data, buffer->
BytesLeft()));
1031 RCHECK(es_descriptor.Parse(data));
1032 if (es_descriptor.
IsAAC()) {
1033 RCHECK(aac_audio_specific_config.
Parse(
1034 es_descriptor.decoder_specific_info()));
1037 DCHECK(buffer->
writer());
1038 es_descriptor.Write(buffer->
writer());
1043 uint32_t ElementaryStreamDescriptor::ComputeSizeInternal() {
1045 if (es_descriptor.object_type() == kForbidden)
1047 return HeaderSize() + es_descriptor.ComputeSize();
1050 DTSSpecific::DTSSpecific() {}
1051 DTSSpecific::~DTSSpecific() {}
1054 bool DTSSpecific::ReadWriteInternal(
BoxBuffer* buffer) {
1059 buffer->ReadWriteVector(&data, buffer->
Size() - buffer->
Pos()));
1061 RCHECK(buffer->ReadWriteVector(&data, data.size()));
1066 uint32_t DTSSpecific::ComputeSizeInternal() {
1068 if (data.size() == 0)
1073 AudioSampleEntry::AudioSampleEntry()
1074 : format(FOURCC_NULL),
1075 data_reference_index(1),
1080 AudioSampleEntry::~AudioSampleEntry() {}
1083 if (format == FOURCC_NULL) {
1084 LOG(ERROR) <<
"AudioSampleEntry should be parsed according to the "
1085 <<
"handler type recovered in its Media ancestor.";
1090 bool AudioSampleEntry::ReadWriteInternal(
BoxBuffer* buffer) {
1092 DCHECK(buffer->
reader());
1093 format = buffer->
reader()->type();
1101 buffer->ReadWriteUInt16(&data_reference_index) &&
1103 buffer->ReadWriteUInt16(&channelcount) &&
1104 buffer->ReadWriteUInt16(&samplesize) &&
1106 buffer->ReadWriteUInt32(&samplerate));
1111 if (format == FOURCC_ENCA) {
1115 while (sinf.type.type != FOURCC_CENC) {
1130 uint32_t AudioSampleEntry::ComputeSizeInternal() {
1131 return HeaderSize() +
sizeof(data_reference_index) +
sizeof(channelcount) +
1132 sizeof(samplesize) +
sizeof(samplerate) + sinf.
ComputeSize() +
1138 WebVTTConfigurationBox::WebVTTConfigurationBox() {}
1139 WebVTTConfigurationBox::~WebVTTConfigurationBox() {}
1145 bool WebVTTConfigurationBox::ReadWriteInternal(
BoxBuffer* buffer) {
1152 uint32_t WebVTTConfigurationBox::ComputeSizeInternal() {
1156 WebVTTSourceLabelBox::WebVTTSourceLabelBox() {}
1157 WebVTTSourceLabelBox::~WebVTTSourceLabelBox() {}
1163 bool WebVTTSourceLabelBox::ReadWriteInternal(
BoxBuffer* buffer) {
1167 : source_label.size());
1170 uint32_t WebVTTSourceLabelBox::ComputeSizeInternal() {
1171 if (source_label.empty())
1176 WVTTSampleEntry::WVTTSampleEntry() {}
1177 WVTTSampleEntry::~WVTTSampleEntry() {}
1183 bool WVTTSampleEntry::ReadWriteInternal(
BoxBuffer* buffer) {
1187 buffer->ReadWriteUInt16(&data_reference_index) &&
1194 uint32_t WVTTSampleEntry::ComputeSizeInternal() {
1196 return HeaderSize() + 6 +
sizeof(data_reference_index) +
1200 MediaHeader::MediaHeader()
1201 : creation_time(0), modification_time(0), timescale(0), duration(0) {
1204 MediaHeader::~MediaHeader() {}
1207 bool MediaHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1210 uint8_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
1213 buffer->ReadWriteUInt32(×cale) &&
1219 std::vector<uint8_t> temp;
1220 RCHECK(buffer->ReadWriteVector(&temp, 2));
1223 bit_reader.SkipBits(1);
1224 for (
int i = 0; i < 3; ++i) {
1225 CHECK(bit_reader.ReadBits(5, &language[i]));
1226 language[i] += 0x60;
1231 const char kUndefinedLanguage[] =
"und";
1232 if (language[0] == 0)
1233 strcpy(language, kUndefinedLanguage);
1237 for (
int i = 0; i < 3; ++i)
1238 lang |= (language[i] - 0x60) << ((2 - i) * 5);
1239 RCHECK(buffer->ReadWriteUInt16(&lang));
1246 uint32_t MediaHeader::ComputeSizeInternal() {
1247 version = IsFitIn32Bits(creation_time, modification_time, duration) ? 0 : 1;
1249 sizeof(uint32_t) * (1 + version) * 3 + 2 +
1253 VideoMediaHeader::VideoMediaHeader()
1254 : graphicsmode(0), opcolor_red(0), opcolor_green(0), opcolor_blue(0) {
1255 const uint32_t kVideoMediaHeaderFlags = 1;
1256 flags = kVideoMediaHeaderFlags;
1258 VideoMediaHeader::~VideoMediaHeader() {}
1260 bool VideoMediaHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1262 buffer->ReadWriteUInt16(&graphicsmode) &&
1263 buffer->ReadWriteUInt16(&opcolor_red) &&
1264 buffer->ReadWriteUInt16(&opcolor_green) &&
1265 buffer->ReadWriteUInt16(&opcolor_blue));
1269 uint32_t VideoMediaHeader::ComputeSizeInternal() {
1270 return HeaderSize() +
sizeof(graphicsmode) +
sizeof(opcolor_red) +
1271 sizeof(opcolor_green) +
sizeof(opcolor_blue);
1274 SoundMediaHeader::SoundMediaHeader() : balance(0) {}
1275 SoundMediaHeader::~SoundMediaHeader() {}
1277 bool SoundMediaHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1279 buffer->ReadWriteUInt16(&balance) &&
1284 uint32_t SoundMediaHeader::ComputeSizeInternal() {
1285 return HeaderSize() +
sizeof(balance) +
sizeof(uint16_t);
1288 SubtitleMediaHeader::SubtitleMediaHeader() {}
1289 SubtitleMediaHeader::~SubtitleMediaHeader() {}
1293 bool SubtitleMediaHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1297 uint32_t SubtitleMediaHeader::ComputeSizeInternal() {
1301 DataEntryUrl::DataEntryUrl() {
1302 const uint32_t kDataEntryUrlFlags = 1;
1303 flags = kDataEntryUrlFlags;
1305 DataEntryUrl::~DataEntryUrl() {}
1307 bool DataEntryUrl::ReadWriteInternal(
BoxBuffer* buffer) {
1310 RCHECK(buffer->ReadWriteVector(&location, buffer->
Size() - buffer->
Pos()));
1312 RCHECK(buffer->ReadWriteVector(&location, location.size()));
1317 uint32_t DataEntryUrl::ComputeSizeInternal() {
1321 DataReference::DataReference() {
1323 data_entry.resize(1);
1325 DataReference::~DataReference() {}
1327 bool DataReference::ReadWriteInternal(
BoxBuffer* buffer) {
1328 uint32_t entry_count = data_entry.size();
1330 buffer->ReadWriteUInt32(&entry_count));
1331 data_entry.resize(entry_count);
1333 for (uint32_t i = 0; i < entry_count; ++i)
1338 uint32_t DataReference::ComputeSizeInternal() {
1339 uint32_t count = data_entry.size();
1340 uint32_t box_size =
HeaderSize() +
sizeof(count);
1341 for (uint32_t i = 0; i < count; ++i)
1346 DataInformation::DataInformation() {}
1347 DataInformation::~DataInformation() {}
1350 bool DataInformation::ReadWriteInternal(
BoxBuffer* buffer) {
1356 uint32_t DataInformation::ComputeSizeInternal() {
1360 MediaInformation::MediaInformation() {}
1361 MediaInformation::~MediaInformation() {}
1364 bool MediaInformation::ReadWriteInternal(
BoxBuffer* buffer) {
1369 switch (sample_table.description.type) {
1386 uint32_t MediaInformation::ComputeSizeInternal() {
1389 switch (sample_table.description.type) {
1409 bool Media::ReadWriteInternal(
BoxBuffer* buffer) {
1421 information.sample_table.description.type = handler.type;
1423 DCHECK_EQ(information.sample_table.description.type, handler.type);
1429 uint32_t Media::ComputeSizeInternal() {
1438 bool Track::ReadWriteInternal(
BoxBuffer* buffer) {
1447 uint32_t Track::ComputeSizeInternal() {
1452 MovieExtendsHeader::MovieExtendsHeader() : fragment_duration(0) {}
1453 MovieExtendsHeader::~MovieExtendsHeader() {}
1456 bool MovieExtendsHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1458 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
1463 uint32_t MovieExtendsHeader::ComputeSizeInternal() {
1465 if (fragment_duration == 0)
1467 version = IsFitIn32Bits(fragment_duration) ? 0 : 1;
1468 return HeaderSize() +
sizeof(uint32_t) * (1 + version);
1471 TrackExtends::TrackExtends()
1473 default_sample_description_index(0),
1474 default_sample_duration(0),
1475 default_sample_size(0),
1476 default_sample_flags(0) {}
1477 TrackExtends::~TrackExtends() {}
1480 bool TrackExtends::ReadWriteInternal(
BoxBuffer* buffer) {
1482 buffer->ReadWriteUInt32(&track_id) &&
1483 buffer->ReadWriteUInt32(&default_sample_description_index) &&
1484 buffer->ReadWriteUInt32(&default_sample_duration) &&
1485 buffer->ReadWriteUInt32(&default_sample_size) &&
1486 buffer->ReadWriteUInt32(&default_sample_flags));
1490 uint32_t TrackExtends::ComputeSizeInternal() {
1492 sizeof(default_sample_description_index) +
1493 sizeof(default_sample_duration) +
sizeof(default_sample_size) +
1494 sizeof(default_sample_flags);
1497 MovieExtends::MovieExtends() {}
1498 MovieExtends::~MovieExtends() {}
1501 bool MovieExtends::ReadWriteInternal(
BoxBuffer* buffer) {
1506 DCHECK(buffer->
reader());
1509 for (uint32_t i = 0; i < tracks.size(); ++i)
1515 uint32_t MovieExtends::ComputeSizeInternal() {
1517 if (tracks.size() == 0)
1520 for (uint32_t i = 0; i < tracks.size(); ++i)
1529 bool Movie::ReadWriteInternal(
BoxBuffer* buffer) {
1540 for (uint32_t i = 0; i < tracks.size(); ++i)
1542 for (uint32_t i = 0; i < pssh.size(); ++i)
1548 uint32_t Movie::ComputeSizeInternal() {
1551 for (uint32_t i = 0; i < tracks.size(); ++i)
1553 for (uint32_t i = 0; i < pssh.size(); ++i)
1558 TrackFragmentDecodeTime::TrackFragmentDecodeTime() : decode_time(0) {}
1559 TrackFragmentDecodeTime::~TrackFragmentDecodeTime() {}
1562 bool TrackFragmentDecodeTime::ReadWriteInternal(
BoxBuffer* buffer) {
1564 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
1569 uint32_t TrackFragmentDecodeTime::ComputeSizeInternal() {
1570 version = IsFitIn32Bits(decode_time) ? 0 : 1;
1571 return HeaderSize() +
sizeof(uint32_t) * (1 + version);
1574 MovieFragmentHeader::MovieFragmentHeader() : sequence_number(0) {}
1575 MovieFragmentHeader::~MovieFragmentHeader() {}
1578 bool MovieFragmentHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1580 buffer->ReadWriteUInt32(&sequence_number);
1583 uint32_t MovieFragmentHeader::ComputeSizeInternal() {
1584 return HeaderSize() +
sizeof(sequence_number);
1587 TrackFragmentHeader::TrackFragmentHeader()
1589 sample_description_index(0),
1590 default_sample_duration(0),
1591 default_sample_size(0),
1592 default_sample_flags(0) {}
1594 TrackFragmentHeader::~TrackFragmentHeader() {}
1597 bool TrackFragmentHeader::ReadWriteInternal(
BoxBuffer* buffer) {
1599 buffer->ReadWriteUInt32(&track_id));
1601 if (flags & kBaseDataOffsetPresentMask) {
1606 uint64_t base_data_offset;
1607 RCHECK(buffer->ReadWriteUInt64(&base_data_offset));
1608 DLOG(WARNING) <<
"base-data-offset-present is not expected. Assumes "
1609 "default-base-is-moof.";
1612 if (flags & kSampleDescriptionIndexPresentMask) {
1613 RCHECK(buffer->ReadWriteUInt32(&sample_description_index));
1614 }
else if (buffer->
Reading()) {
1615 sample_description_index = 0;
1618 if (flags & kDefaultSampleDurationPresentMask) {
1619 RCHECK(buffer->ReadWriteUInt32(&default_sample_duration));
1620 }
else if (buffer->
Reading()) {
1621 default_sample_duration = 0;
1624 if (flags & kDefaultSampleSizePresentMask) {
1625 RCHECK(buffer->ReadWriteUInt32(&default_sample_size));
1626 }
else if (buffer->
Reading()) {
1627 default_sample_size = 0;
1630 if (flags & kDefaultSampleFlagsPresentMask)
1631 RCHECK(buffer->ReadWriteUInt32(&default_sample_flags));
1635 uint32_t TrackFragmentHeader::ComputeSizeInternal() {
1636 uint32_t box_size =
HeaderSize() +
sizeof(track_id);
1637 if (flags & kSampleDescriptionIndexPresentMask)
1638 box_size +=
sizeof(sample_description_index);
1639 if (flags & kDefaultSampleDurationPresentMask)
1640 box_size +=
sizeof(default_sample_duration);
1641 if (flags & kDefaultSampleSizePresentMask)
1642 box_size +=
sizeof(default_sample_size);
1643 if (flags & kDefaultSampleFlagsPresentMask)
1644 box_size +=
sizeof(default_sample_flags);
1648 TrackFragmentRun::TrackFragmentRun() : sample_count(0), data_offset(0) {}
1649 TrackFragmentRun::~TrackFragmentRun() {}
1652 bool TrackFragmentRun::ReadWriteInternal(
BoxBuffer* buffer) {
1658 if (flags & kSampleCompTimeOffsetsPresentMask) {
1659 for (uint32_t i = 0; i < sample_count; ++i) {
1660 if (sample_composition_time_offsets[i] < 0) {
1669 buffer->ReadWriteUInt32(&sample_count));
1671 bool data_offset_present = (flags & kDataOffsetPresentMask) != 0;
1672 bool first_sample_flags_present = (flags & kFirstSampleFlagsPresentMask) != 0;
1673 bool sample_duration_present = (flags & kSampleDurationPresentMask) != 0;
1674 bool sample_size_present = (flags & kSampleSizePresentMask) != 0;
1675 bool sample_flags_present = (flags & kSampleFlagsPresentMask) != 0;
1676 bool sample_composition_time_offsets_present =
1677 (flags & kSampleCompTimeOffsetsPresentMask) != 0;
1679 if (data_offset_present) {
1680 RCHECK(buffer->ReadWriteUInt32(&data_offset));
1691 uint32_t first_sample_flags;
1694 if (first_sample_flags_present)
1695 RCHECK(buffer->ReadWriteUInt32(&first_sample_flags));
1697 if (sample_duration_present)
1698 sample_durations.resize(sample_count);
1699 if (sample_size_present)
1700 sample_sizes.resize(sample_count);
1701 if (sample_flags_present)
1702 sample_flags.resize(sample_count);
1703 if (sample_composition_time_offsets_present)
1704 sample_composition_time_offsets.resize(sample_count);
1706 if (first_sample_flags_present) {
1707 first_sample_flags = sample_flags[0];
1708 DCHECK(sample_flags.size() == 1);
1709 RCHECK(buffer->ReadWriteUInt32(&first_sample_flags));
1712 if (sample_duration_present)
1713 DCHECK(sample_durations.size() == sample_count);
1714 if (sample_size_present)
1715 DCHECK(sample_sizes.size() == sample_count);
1716 if (sample_flags_present)
1717 DCHECK(sample_flags.size() == sample_count);
1718 if (sample_composition_time_offsets_present)
1719 DCHECK(sample_composition_time_offsets.size() == sample_count);
1722 for (uint32_t i = 0; i < sample_count; ++i) {
1723 if (sample_duration_present)
1724 RCHECK(buffer->ReadWriteUInt32(&sample_durations[i]));
1725 if (sample_size_present)
1726 RCHECK(buffer->ReadWriteUInt32(&sample_sizes[i]));
1727 if (sample_flags_present)
1728 RCHECK(buffer->ReadWriteUInt32(&sample_flags[i]));
1730 if (sample_composition_time_offsets_present) {
1732 uint32_t sample_offset = sample_composition_time_offsets[i];
1733 RCHECK(buffer->ReadWriteUInt32(&sample_offset));
1734 sample_composition_time_offsets[i] = sample_offset;
1736 int32_t sample_offset = sample_composition_time_offsets[i];
1737 RCHECK(buffer->ReadWriteInt32(&sample_offset));
1738 sample_composition_time_offsets[i] = sample_offset;
1744 if (first_sample_flags_present) {
1745 if (sample_flags.size() == 0) {
1746 sample_flags.push_back(first_sample_flags);
1748 sample_flags[0] = first_sample_flags;
1755 uint32_t TrackFragmentRun::ComputeSizeInternal() {
1756 uint32_t box_size =
HeaderSize() +
sizeof(sample_count);
1757 if (flags & kDataOffsetPresentMask)
1758 box_size +=
sizeof(data_offset);
1759 if (flags & kFirstSampleFlagsPresentMask)
1760 box_size +=
sizeof(uint32_t);
1761 uint32_t fields = (flags & kSampleDurationPresentMask ? 1 : 0) +
1762 (flags & kSampleSizePresentMask ? 1 : 0) +
1763 (flags & kSampleFlagsPresentMask ? 1 : 0) +
1764 (flags & kSampleCompTimeOffsetsPresentMask ? 1 : 0);
1765 box_size += fields *
sizeof(uint32_t) * sample_count;
1769 SampleToGroup::SampleToGroup() : grouping_type(0), grouping_type_parameter(0) {}
1770 SampleToGroup::~SampleToGroup() {}
1773 bool SampleToGroup::ReadWriteInternal(
BoxBuffer* buffer) {
1775 buffer->ReadWriteUInt32(&grouping_type));
1777 RCHECK(buffer->ReadWriteUInt32(&grouping_type_parameter));
1779 if (grouping_type != FOURCC_SEIG) {
1781 DLOG(WARNING) <<
"Sample group "
1782 << FourCCToString(static_cast<FourCC>(grouping_type))
1783 <<
" is not supported.";
1787 uint32_t count = entries.size();
1788 RCHECK(buffer->ReadWriteUInt32(&count));
1789 entries.resize(count);
1790 for (uint32_t i = 0; i < count; ++i) {
1791 RCHECK(buffer->ReadWriteUInt32(&entries[i].sample_count) &&
1792 buffer->ReadWriteUInt32(&entries[i].group_description_index));
1797 uint32_t SampleToGroup::ComputeSizeInternal() {
1799 if (entries.empty())
1801 return HeaderSize() +
sizeof(grouping_type) +
1802 (version == 1 ?
sizeof(grouping_type_parameter) : 0) +
1803 sizeof(uint32_t) + entries.size() *
sizeof(entries[0]);
1806 CencSampleEncryptionInfoEntry::CencSampleEncryptionInfoEntry()
1807 : is_encrypted(false), iv_size(0) {
1809 CencSampleEncryptionInfoEntry::~CencSampleEncryptionInfoEntry() {};
1811 SampleGroupDescription::SampleGroupDescription() : grouping_type(0) {}
1812 SampleGroupDescription::~SampleGroupDescription() {}
1815 bool SampleGroupDescription::ReadWriteInternal(
BoxBuffer* buffer) {
1817 buffer->ReadWriteUInt32(&grouping_type));
1819 if (grouping_type != FOURCC_SEIG) {
1821 DLOG(WARNING) <<
"Sample group '" << grouping_type <<
"' is not supported.";
1825 const size_t kEntrySize =
sizeof(uint32_t) + kCencKeyIdSize;
1826 uint32_t default_length = 0;
1829 RCHECK(buffer->ReadWriteUInt32(&default_length));
1830 RCHECK(default_length == 0 || default_length >= kEntrySize);
1832 default_length = kEntrySize;
1833 RCHECK(buffer->ReadWriteUInt32(&default_length));
1837 uint32_t count = entries.size();
1838 RCHECK(buffer->ReadWriteUInt32(&count));
1839 entries.resize(count);
1840 for (uint32_t i = 0; i < count; ++i) {
1842 if (buffer->
Reading() && default_length == 0) {
1843 uint32_t description_length = 0;
1844 RCHECK(buffer->ReadWriteUInt32(&description_length));
1845 RCHECK(description_length >= kEntrySize);
1850 if (entries[i].key_id.size() != kCencKeyIdSize) {
1851 LOG(WARNING) <<
"CENC defines key id length of " << kCencKeyIdSize
1852 <<
" bytes; got " << entries[i].key_id.size()
1853 <<
". Resized accordingly.";
1854 entries[i].key_id.resize(kCencKeyIdSize);
1858 uint8_t flag = entries[i].is_encrypted ? 1 : 0;
1860 buffer->ReadWriteUInt8(&flag) &&
1861 buffer->ReadWriteUInt8(&entries[i].iv_size) &&
1862 buffer->ReadWriteVector(&entries[i].key_id, kCencKeyIdSize));
1865 entries[i].is_encrypted = (flag != 0);
1866 if (entries[i].is_encrypted) {
1867 RCHECK(entries[i].iv_size == 8 || entries[i].iv_size == 16);
1869 RCHECK(entries[i].iv_size == 0);
1876 uint32_t SampleGroupDescription::ComputeSizeInternal() {
1880 if (entries.empty())
1882 const size_t kEntrySize =
sizeof(uint32_t) + kCencKeyIdSize;
1883 return HeaderSize() +
sizeof(grouping_type) +
1884 (version == 1 ?
sizeof(uint32_t) : 0) +
sizeof(uint32_t) +
1885 entries.size() * kEntrySize;
1888 TrackFragment::TrackFragment() : decode_time_absent(false) {}
1889 TrackFragment::~TrackFragment() {}
1892 bool TrackFragment::ReadWriteInternal(
BoxBuffer* buffer) {
1897 DCHECK(buffer->
reader());
1899 if (!decode_time_absent)
1907 while (sample_to_group.grouping_type != FOURCC_SEIG &&
1911 while (sample_group_description.grouping_type != FOURCC_SEIG &&
1916 if (!decode_time_absent)
1918 for (uint32_t i = 0; i < runs.size(); ++i)
1927 uint32_t TrackFragment::ComputeSizeInternal() {
1932 for (uint32_t i = 0; i < runs.size(); ++i)
1937 MovieFragment::MovieFragment() {}
1938 MovieFragment::~MovieFragment() {}
1941 bool MovieFragment::ReadWriteInternal(
BoxBuffer* buffer) {
1951 for (uint32_t i = 0; i < tracks.size(); ++i)
1953 for (uint32_t i = 0; i < pssh.size(); ++i)
1959 uint32_t MovieFragment::ComputeSizeInternal() {
1961 for (uint32_t i = 0; i < tracks.size(); ++i)
1963 for (uint32_t i = 0; i < pssh.size(); ++i)
1968 SegmentIndex::SegmentIndex()
1971 earliest_presentation_time(0),
1973 SegmentIndex::~SegmentIndex() {}
1976 bool SegmentIndex::ReadWriteInternal(
BoxBuffer* buffer) {
1978 buffer->ReadWriteUInt32(&reference_id) &&
1979 buffer->ReadWriteUInt32(×cale));
1981 size_t num_bytes = (version == 1) ?
sizeof(uint64_t) :
sizeof(uint32_t);
1986 uint16_t reference_count = references.size();
1988 buffer->ReadWriteUInt16(&reference_count));
1989 references.resize(reference_count);
1991 uint32_t reference_type_size;
1993 for (uint32_t i = 0; i < reference_count; ++i) {
1995 reference_type_size = references[i].referenced_size;
1996 if (references[i].reference_type)
1997 reference_type_size |= (1 << 31);
1998 sap = (references[i].sap_type << 28) | references[i].sap_delta_time;
1999 if (references[i].starts_with_sap)
2002 RCHECK(buffer->ReadWriteUInt32(&reference_type_size) &&
2003 buffer->ReadWriteUInt32(&references[i].subsegment_duration) &&
2004 buffer->ReadWriteUInt32(&sap));
2006 references[i].reference_type = (reference_type_size >> 31) ?
true :
false;
2007 references[i].referenced_size = reference_type_size & ~(1 << 31);
2008 references[i].starts_with_sap = (sap >> 31) ?
true :
false;
2009 references[i].sap_type =
2010 static_cast<SegmentReference::SAPType
>((sap >> 28) & 0x07);
2011 references[i].sap_delta_time = sap & ~(0xF << 28);
2017 uint32_t SegmentIndex::ComputeSizeInternal() {
2018 version = IsFitIn32Bits(earliest_presentation_time, first_offset) ? 0 : 1;
2019 return HeaderSize() +
sizeof(reference_id) +
sizeof(timescale) +
2020 sizeof(uint32_t) * (1 + version) * 2 + 2 *
sizeof(uint16_t) +
2021 3 *
sizeof(uint32_t) * references.size();
2024 MediaData::MediaData() : data_size(0) {}
2025 MediaData::~MediaData() {}
2028 bool MediaData::ReadWriteInternal(
BoxBuffer* buffer) {
2029 NOTIMPLEMENTED() <<
"Actual data is parsed and written separately.";
2033 uint32_t MediaData::ComputeSizeInternal() {
2037 CueSourceIDBox::CueSourceIDBox() : source_id(kCueSourceIdNotSet) {}
2038 CueSourceIDBox::~CueSourceIDBox() {}
2042 bool CueSourceIDBox::ReadWriteInternal(
BoxBuffer* buffer) {
2047 uint32_t CueSourceIDBox::ComputeSizeInternal() {
2048 if (source_id == kCueSourceIdNotSet)
2053 CueTimeBox::CueTimeBox() {}
2054 CueTimeBox::~CueTimeBox() {}
2060 bool CueTimeBox::ReadWriteInternal(
BoxBuffer* buffer) {
2067 uint32_t CueTimeBox::ComputeSizeInternal() {
2068 if (cue_current_time.empty())
2070 return HeaderSize() + cue_current_time.size();
2073 CueIDBox::CueIDBox() {}
2074 CueIDBox::~CueIDBox() {}
2080 bool CueIDBox::ReadWriteInternal(
BoxBuffer* buffer) {
2086 uint32_t CueIDBox::ComputeSizeInternal() {
2092 CueSettingsBox::CueSettingsBox() {}
2093 CueSettingsBox::~CueSettingsBox() {}
2099 bool CueSettingsBox::ReadWriteInternal(
BoxBuffer* buffer) {
2105 uint32_t CueSettingsBox::ComputeSizeInternal() {
2106 if (settings.empty())
2111 CuePayloadBox::CuePayloadBox() {}
2112 CuePayloadBox::~CuePayloadBox() {}
2118 bool CuePayloadBox::ReadWriteInternal(
BoxBuffer* buffer) {
2124 uint32_t CuePayloadBox::ComputeSizeInternal() {
2128 VTTEmptyCueBox::VTTEmptyCueBox() {}
2129 VTTEmptyCueBox::~VTTEmptyCueBox() {}
2135 bool VTTEmptyCueBox::ReadWriteInternal(
BoxBuffer* buffer) {
2139 uint32_t VTTEmptyCueBox::ComputeSizeInternal() {
2143 VTTAdditionalTextBox::VTTAdditionalTextBox() {}
2144 VTTAdditionalTextBox::~VTTAdditionalTextBox() {}
2150 bool VTTAdditionalTextBox::ReadWriteInternal(
BoxBuffer* buffer) {
2153 &cue_additional_text,
2157 uint32_t VTTAdditionalTextBox::ComputeSizeInternal() {
2158 return HeaderSize() + cue_additional_text.size();
2161 VTTCueBox::VTTCueBox() {}
2162 VTTCueBox::~VTTCueBox() {}
2168 bool VTTCueBox::ReadWriteInternal(
BoxBuffer* buffer) {
2179 uint32_t VTTCueBox::ComputeSizeInternal() {
FourCC BoxType() const override
FourCC BoxType() const override
FourCC BoxType() const override
FourCC BoxType() const override
FourCC BoxType() const override