cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / mp4 / box_definitions.cc
blobe7f169323bb6b90a94854d9bfe9ce55bc07bcd3e
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/mp4/box_definitions.h"
7 #include "base/logging.h"
8 #include "media/mp4/es_descriptor.h"
9 #include "media/mp4/rcheck.h"
11 namespace media {
12 namespace mp4 {
14 FileType::FileType() {}
15 FileType::~FileType() {}
16 FourCC FileType::BoxType() const { return FOURCC_FTYP; }
18 bool FileType::Parse(BoxReader* reader) {
19 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version));
20 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC);
21 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands
24 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {}
25 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {}
26 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; }
28 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) {
29 // Validate the box's contents and hang on to the system ID.
30 uint32 size;
31 RCHECK(reader->ReadFullBoxHeader() &&
32 reader->ReadVec(&system_id, 16) &&
33 reader->Read4(&size) &&
34 reader->HasBytes(size));
36 // Copy the entire box, including the header, for passing to EME as initData.
37 DCHECK(raw_box.empty());
38 raw_box.assign(reader->data(), reader->data() + reader->size());
39 return true;
42 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {}
43 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {}
44 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; }
46 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) {
47 RCHECK(reader->ReadFullBoxHeader());
48 if (reader->flags() & 1)
49 RCHECK(reader->SkipBytes(8));
51 uint32 count;
52 RCHECK(reader->Read4(&count) &&
53 reader->HasBytes(count * (reader->version() == 1 ? 8 : 4)));
54 offsets.resize(count);
56 for (uint32 i = 0; i < count; i++) {
57 if (reader->version() == 1) {
58 RCHECK(reader->Read8(&offsets[i]));
59 } else {
60 RCHECK(reader->Read4Into8(&offsets[i]));
63 return true;
66 SampleAuxiliaryInformationSize::SampleAuxiliaryInformationSize()
67 : default_sample_info_size(0), sample_count(0) {
69 SampleAuxiliaryInformationSize::~SampleAuxiliaryInformationSize() {}
70 FourCC SampleAuxiliaryInformationSize::BoxType() const { return FOURCC_SAIZ; }
72 bool SampleAuxiliaryInformationSize::Parse(BoxReader* reader) {
73 RCHECK(reader->ReadFullBoxHeader());
74 if (reader->flags() & 1)
75 RCHECK(reader->SkipBytes(8));
77 RCHECK(reader->Read1(&default_sample_info_size) &&
78 reader->Read4(&sample_count));
79 if (default_sample_info_size == 0)
80 return reader->ReadVec(&sample_info_sizes, sample_count);
81 return true;
84 OriginalFormat::OriginalFormat() : format(FOURCC_NULL) {}
85 OriginalFormat::~OriginalFormat() {}
86 FourCC OriginalFormat::BoxType() const { return FOURCC_FRMA; }
88 bool OriginalFormat::Parse(BoxReader* reader) {
89 return reader->ReadFourCC(&format);
92 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {}
93 SchemeType::~SchemeType() {}
94 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; }
96 bool SchemeType::Parse(BoxReader* reader) {
97 RCHECK(reader->ReadFullBoxHeader() &&
98 reader->ReadFourCC(&type) &&
99 reader->Read4(&version));
100 return true;
103 TrackEncryption::TrackEncryption()
104 : is_encrypted(false), default_iv_size(0) {
106 TrackEncryption::~TrackEncryption() {}
107 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; }
109 bool TrackEncryption::Parse(BoxReader* reader) {
110 uint8 flag;
111 RCHECK(reader->ReadFullBoxHeader() &&
112 reader->SkipBytes(2) &&
113 reader->Read1(&flag) &&
114 reader->Read1(&default_iv_size) &&
115 reader->ReadVec(&default_kid, 16));
116 is_encrypted = (flag != 0);
117 if (is_encrypted) {
118 RCHECK(default_iv_size == 8 || default_iv_size == 16);
119 } else {
120 RCHECK(default_iv_size == 0);
122 return true;
125 SchemeInfo::SchemeInfo() {}
126 SchemeInfo::~SchemeInfo() {}
127 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; }
129 bool SchemeInfo::Parse(BoxReader* reader) {
130 return reader->ScanChildren() && reader->ReadChild(&track_encryption);
133 ProtectionSchemeInfo::ProtectionSchemeInfo() {}
134 ProtectionSchemeInfo::~ProtectionSchemeInfo() {}
135 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; }
137 bool ProtectionSchemeInfo::Parse(BoxReader* reader) {
138 RCHECK(reader->ScanChildren() &&
139 reader->ReadChild(&format) &&
140 reader->ReadChild(&type));
141 if (type.type == FOURCC_CENC)
142 RCHECK(reader->ReadChild(&info));
143 // Other protection schemes are silently ignored. Since the protection scheme
144 // type can't be determined until this box is opened, we return 'true' for
145 // non-CENC protection scheme types. It is the parent box's responsibility to
146 // ensure that this scheme type is a supported one.
147 return true;
150 MovieHeader::MovieHeader()
151 : creation_time(0),
152 modification_time(0),
153 timescale(0),
154 duration(0),
155 rate(-1),
156 volume(-1),
157 next_track_id(0) {}
158 MovieHeader::~MovieHeader() {}
159 FourCC MovieHeader::BoxType() const { return FOURCC_MVHD; }
161 bool MovieHeader::Parse(BoxReader* reader) {
162 RCHECK(reader->ReadFullBoxHeader());
164 if (reader->version() == 1) {
165 RCHECK(reader->Read8(&creation_time) &&
166 reader->Read8(&modification_time) &&
167 reader->Read4(&timescale) &&
168 reader->Read8(&duration));
169 } else {
170 RCHECK(reader->Read4Into8(&creation_time) &&
171 reader->Read4Into8(&modification_time) &&
172 reader->Read4(&timescale) &&
173 reader->Read4Into8(&duration));
176 RCHECK(reader->Read4s(&rate) &&
177 reader->Read2s(&volume) &&
178 reader->SkipBytes(10) && // reserved
179 reader->SkipBytes(36) && // matrix
180 reader->SkipBytes(24) && // predefined zero
181 reader->Read4(&next_track_id));
182 return true;
185 TrackHeader::TrackHeader()
186 : creation_time(0),
187 modification_time(0),
188 track_id(0),
189 duration(0),
190 layer(-1),
191 alternate_group(-1),
192 volume(-1),
193 width(0),
194 height(0) {}
195 TrackHeader::~TrackHeader() {}
196 FourCC TrackHeader::BoxType() const { return FOURCC_TKHD; }
198 bool TrackHeader::Parse(BoxReader* reader) {
199 RCHECK(reader->ReadFullBoxHeader());
200 if (reader->version() == 1) {
201 RCHECK(reader->Read8(&creation_time) &&
202 reader->Read8(&modification_time) &&
203 reader->Read4(&track_id) &&
204 reader->SkipBytes(4) && // reserved
205 reader->Read8(&duration));
206 } else {
207 RCHECK(reader->Read4Into8(&creation_time) &&
208 reader->Read4Into8(&modification_time) &&
209 reader->Read4(&track_id) &&
210 reader->SkipBytes(4) && // reserved
211 reader->Read4Into8(&duration));
214 RCHECK(reader->SkipBytes(8) && // reserved
215 reader->Read2s(&layer) &&
216 reader->Read2s(&alternate_group) &&
217 reader->Read2s(&volume) &&
218 reader->SkipBytes(2) && // reserved
219 reader->SkipBytes(36) && // matrix
220 reader->Read4(&width) &&
221 reader->Read4(&height));
222 width >>= 16;
223 height >>= 16;
224 return true;
227 SampleDescription::SampleDescription() : type(kInvalid) {}
228 SampleDescription::~SampleDescription() {}
229 FourCC SampleDescription::BoxType() const { return FOURCC_STSD; }
231 bool SampleDescription::Parse(BoxReader* reader) {
232 uint32 count;
233 RCHECK(reader->SkipBytes(4) &&
234 reader->Read4(&count));
235 video_entries.clear();
236 audio_entries.clear();
238 // Note: this value is preset before scanning begins. See comments in the
239 // Parse(Media*) function.
240 if (type == kVideo) {
241 RCHECK(reader->ReadAllChildren(&video_entries));
242 } else if (type == kAudio) {
243 RCHECK(reader->ReadAllChildren(&audio_entries));
245 return true;
248 SampleTable::SampleTable() {}
249 SampleTable::~SampleTable() {}
250 FourCC SampleTable::BoxType() const { return FOURCC_STBL; }
252 bool SampleTable::Parse(BoxReader* reader) {
253 return reader->ScanChildren() &&
254 reader->ReadChild(&description);
257 EditList::EditList() {}
258 EditList::~EditList() {}
259 FourCC EditList::BoxType() const { return FOURCC_ELST; }
261 bool EditList::Parse(BoxReader* reader) {
262 uint32 count;
263 RCHECK(reader->ReadFullBoxHeader() && reader->Read4(&count));
265 if (reader->version() == 1) {
266 RCHECK(reader->HasBytes(count * 20));
267 } else {
268 RCHECK(reader->HasBytes(count * 12));
270 edits.resize(count);
272 for (std::vector<EditListEntry>::iterator edit = edits.begin();
273 edit != edits.end(); ++edit) {
274 if (reader->version() == 1) {
275 RCHECK(reader->Read8(&edit->segment_duration) &&
276 reader->Read8s(&edit->media_time));
277 } else {
278 RCHECK(reader->Read4Into8(&edit->segment_duration) &&
279 reader->Read4sInto8s(&edit->media_time));
281 RCHECK(reader->Read2s(&edit->media_rate_integer) &&
282 reader->Read2s(&edit->media_rate_fraction));
284 return true;
287 Edit::Edit() {}
288 Edit::~Edit() {}
289 FourCC Edit::BoxType() const { return FOURCC_EDTS; }
291 bool Edit::Parse(BoxReader* reader) {
292 return reader->ScanChildren() && reader->ReadChild(&list);
295 HandlerReference::HandlerReference() : type(kInvalid) {}
296 HandlerReference::~HandlerReference() {}
297 FourCC HandlerReference::BoxType() const { return FOURCC_HDLR; }
299 bool HandlerReference::Parse(BoxReader* reader) {
300 FourCC hdlr_type;
301 RCHECK(reader->SkipBytes(8) && reader->ReadFourCC(&hdlr_type));
302 // Note: remaining fields in box ignored
303 if (hdlr_type == FOURCC_VIDE) {
304 type = kVideo;
305 } else if (hdlr_type == FOURCC_SOUN) {
306 type = kAudio;
307 } else {
308 type = kInvalid;
310 return true;
313 AVCDecoderConfigurationRecord::AVCDecoderConfigurationRecord()
314 : version(0),
315 profile_indication(0),
316 profile_compatibility(0),
317 avc_level(0),
318 length_size(0) {}
320 AVCDecoderConfigurationRecord::~AVCDecoderConfigurationRecord() {}
321 FourCC AVCDecoderConfigurationRecord::BoxType() const { return FOURCC_AVCC; }
323 bool AVCDecoderConfigurationRecord::Parse(BoxReader* reader) {
324 RCHECK(reader->Read1(&version) && version == 1 &&
325 reader->Read1(&profile_indication) &&
326 reader->Read1(&profile_compatibility) &&
327 reader->Read1(&avc_level));
329 uint8 length_size_minus_one;
330 RCHECK(reader->Read1(&length_size_minus_one) &&
331 (length_size_minus_one & 0xfc) == 0xfc);
332 length_size = (length_size_minus_one & 0x3) + 1;
334 uint8 num_sps;
335 RCHECK(reader->Read1(&num_sps) && (num_sps & 0xe0) == 0xe0);
336 num_sps &= 0x1f;
338 sps_list.resize(num_sps);
339 for (int i = 0; i < num_sps; i++) {
340 uint16 sps_length;
341 RCHECK(reader->Read2(&sps_length) &&
342 reader->ReadVec(&sps_list[i], sps_length));
345 uint8 num_pps;
346 RCHECK(reader->Read1(&num_pps));
348 pps_list.resize(num_pps);
349 for (int i = 0; i < num_pps; i++) {
350 uint16 pps_length;
351 RCHECK(reader->Read2(&pps_length) &&
352 reader->ReadVec(&pps_list[i], pps_length));
355 return true;
358 PixelAspectRatioBox::PixelAspectRatioBox() : h_spacing(1), v_spacing(1) {}
359 PixelAspectRatioBox::~PixelAspectRatioBox() {}
360 FourCC PixelAspectRatioBox::BoxType() const { return FOURCC_PASP; }
362 bool PixelAspectRatioBox::Parse(BoxReader* reader) {
363 RCHECK(reader->Read4(&h_spacing) &&
364 reader->Read4(&v_spacing));
365 return true;
368 VideoSampleEntry::VideoSampleEntry()
369 : format(FOURCC_NULL),
370 data_reference_index(0),
371 width(0),
372 height(0) {}
374 VideoSampleEntry::~VideoSampleEntry() {}
375 FourCC VideoSampleEntry::BoxType() const {
376 DCHECK(false) << "VideoSampleEntry should be parsed according to the "
377 << "handler type recovered in its Media ancestor.";
378 return FOURCC_NULL;
381 bool VideoSampleEntry::Parse(BoxReader* reader) {
382 format = reader->type();
383 RCHECK(reader->SkipBytes(6) &&
384 reader->Read2(&data_reference_index) &&
385 reader->SkipBytes(16) &&
386 reader->Read2(&width) &&
387 reader->Read2(&height) &&
388 reader->SkipBytes(50));
390 RCHECK(reader->ScanChildren() &&
391 reader->MaybeReadChild(&pixel_aspect));
393 if (format == FOURCC_ENCV) {
394 // Continue scanning until a recognized protection scheme is found, or until
395 // we run out of protection schemes.
396 while (sinf.type.type != FOURCC_CENC) {
397 if (!reader->ReadChild(&sinf))
398 return false;
402 if (format == FOURCC_AVC1 ||
403 (format == FOURCC_ENCV && sinf.format.format == FOURCC_AVC1)) {
404 RCHECK(reader->ReadChild(&avcc));
406 return true;
409 ElementaryStreamDescriptor::ElementaryStreamDescriptor()
410 : object_type(kForbidden) {}
412 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {}
414 FourCC ElementaryStreamDescriptor::BoxType() const {
415 return FOURCC_ESDS;
418 bool ElementaryStreamDescriptor::Parse(BoxReader* reader) {
419 std::vector<uint8> data;
420 ESDescriptor es_desc;
422 RCHECK(reader->ReadFullBoxHeader());
423 RCHECK(reader->ReadVec(&data, reader->size() - reader->pos()));
424 RCHECK(es_desc.Parse(data));
426 object_type = es_desc.object_type();
428 RCHECK(aac.Parse(es_desc.decoder_specific_info()));
430 return true;
433 AudioSampleEntry::AudioSampleEntry()
434 : format(FOURCC_NULL),
435 data_reference_index(0),
436 channelcount(0),
437 samplesize(0),
438 samplerate(0) {}
440 AudioSampleEntry::~AudioSampleEntry() {}
442 FourCC AudioSampleEntry::BoxType() const {
443 DCHECK(false) << "AudioSampleEntry should be parsed according to the "
444 << "handler type recovered in its Media ancestor.";
445 return FOURCC_NULL;
448 bool AudioSampleEntry::Parse(BoxReader* reader) {
449 format = reader->type();
450 RCHECK(reader->SkipBytes(6) &&
451 reader->Read2(&data_reference_index) &&
452 reader->SkipBytes(8) &&
453 reader->Read2(&channelcount) &&
454 reader->Read2(&samplesize) &&
455 reader->SkipBytes(4) &&
456 reader->Read4(&samplerate));
457 // Convert from 16.16 fixed point to integer
458 samplerate >>= 16;
460 RCHECK(reader->ScanChildren());
461 if (format == FOURCC_ENCA) {
462 // Continue scanning until a recognized protection scheme is found, or until
463 // we run out of protection schemes.
464 while (sinf.type.type != FOURCC_CENC) {
465 if (!reader->ReadChild(&sinf))
466 return false;
470 // ESDS is not valid in case of EAC3.
471 RCHECK(reader->MaybeReadChild(&esds));
472 return true;
475 MediaHeader::MediaHeader()
476 : creation_time(0),
477 modification_time(0),
478 timescale(0),
479 duration(0) {}
480 MediaHeader::~MediaHeader() {}
481 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; }
483 bool MediaHeader::Parse(BoxReader* reader) {
484 RCHECK(reader->ReadFullBoxHeader());
486 if (reader->version() == 1) {
487 RCHECK(reader->Read8(&creation_time) &&
488 reader->Read8(&modification_time) &&
489 reader->Read4(&timescale) &&
490 reader->Read8(&duration));
491 } else {
492 RCHECK(reader->Read4Into8(&creation_time) &&
493 reader->Read4Into8(&modification_time) &&
494 reader->Read4(&timescale) &&
495 reader->Read4Into8(&duration));
497 // Skip language information
498 return reader->SkipBytes(4);
501 MediaInformation::MediaInformation() {}
502 MediaInformation::~MediaInformation() {}
503 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; }
505 bool MediaInformation::Parse(BoxReader* reader) {
506 return reader->ScanChildren() &&
507 reader->ReadChild(&sample_table);
510 Media::Media() {}
511 Media::~Media() {}
512 FourCC Media::BoxType() const { return FOURCC_MDIA; }
514 bool Media::Parse(BoxReader* reader) {
515 RCHECK(reader->ScanChildren() &&
516 reader->ReadChild(&header) &&
517 reader->ReadChild(&handler));
519 // Maddeningly, the HandlerReference box specifies how to parse the
520 // SampleDescription box, making the latter the only box (of those that we
521 // support) which cannot be parsed correctly on its own (or even with
522 // information from its strict ancestor tree). We thus copy the handler type
523 // to the sample description box *before* parsing it to provide this
524 // information while parsing.
525 information.sample_table.description.type = handler.type;
526 RCHECK(reader->ReadChild(&information));
527 return true;
530 Track::Track() {}
531 Track::~Track() {}
532 FourCC Track::BoxType() const { return FOURCC_TRAK; }
534 bool Track::Parse(BoxReader* reader) {
535 RCHECK(reader->ScanChildren() &&
536 reader->ReadChild(&header) &&
537 reader->ReadChild(&media) &&
538 reader->MaybeReadChild(&edit));
539 return true;
542 MovieExtendsHeader::MovieExtendsHeader() : fragment_duration(0) {}
543 MovieExtendsHeader::~MovieExtendsHeader() {}
544 FourCC MovieExtendsHeader::BoxType() const { return FOURCC_MEHD; }
546 bool MovieExtendsHeader::Parse(BoxReader* reader) {
547 RCHECK(reader->ReadFullBoxHeader());
548 if (reader->version() == 1) {
549 RCHECK(reader->Read8(&fragment_duration));
550 } else {
551 RCHECK(reader->Read4Into8(&fragment_duration));
553 return true;
556 TrackExtends::TrackExtends()
557 : track_id(0),
558 default_sample_description_index(0),
559 default_sample_duration(0),
560 default_sample_size(0),
561 default_sample_flags(0) {}
562 TrackExtends::~TrackExtends() {}
563 FourCC TrackExtends::BoxType() const { return FOURCC_TREX; }
565 bool TrackExtends::Parse(BoxReader* reader) {
566 RCHECK(reader->ReadFullBoxHeader() &&
567 reader->Read4(&track_id) &&
568 reader->Read4(&default_sample_description_index) &&
569 reader->Read4(&default_sample_duration) &&
570 reader->Read4(&default_sample_size) &&
571 reader->Read4(&default_sample_flags));
572 return true;
575 MovieExtends::MovieExtends() {}
576 MovieExtends::~MovieExtends() {}
577 FourCC MovieExtends::BoxType() const { return FOURCC_MVEX; }
579 bool MovieExtends::Parse(BoxReader* reader) {
580 header.fragment_duration = 0;
581 return reader->ScanChildren() &&
582 reader->MaybeReadChild(&header) &&
583 reader->ReadChildren(&tracks);
586 Movie::Movie() : fragmented(false) {}
587 Movie::~Movie() {}
588 FourCC Movie::BoxType() const { return FOURCC_MOOV; }
590 bool Movie::Parse(BoxReader* reader) {
591 return reader->ScanChildren() &&
592 reader->ReadChild(&header) &&
593 reader->ReadChildren(&tracks) &&
594 // Media Source specific: 'mvex' required
595 reader->ReadChild(&extends) &&
596 reader->MaybeReadChildren(&pssh);
599 TrackFragmentDecodeTime::TrackFragmentDecodeTime() : decode_time(0) {}
600 TrackFragmentDecodeTime::~TrackFragmentDecodeTime() {}
601 FourCC TrackFragmentDecodeTime::BoxType() const { return FOURCC_TFDT; }
603 bool TrackFragmentDecodeTime::Parse(BoxReader* reader) {
604 RCHECK(reader->ReadFullBoxHeader());
605 if (reader->version() == 1)
606 return reader->Read8(&decode_time);
607 else
608 return reader->Read4Into8(&decode_time);
611 MovieFragmentHeader::MovieFragmentHeader() : sequence_number(0) {}
612 MovieFragmentHeader::~MovieFragmentHeader() {}
613 FourCC MovieFragmentHeader::BoxType() const { return FOURCC_MFHD; }
615 bool MovieFragmentHeader::Parse(BoxReader* reader) {
616 return reader->SkipBytes(4) && reader->Read4(&sequence_number);
619 TrackFragmentHeader::TrackFragmentHeader()
620 : track_id(0),
621 sample_description_index(0),
622 default_sample_duration(0),
623 default_sample_size(0),
624 default_sample_flags(0),
625 has_default_sample_flags(false) {}
627 TrackFragmentHeader::~TrackFragmentHeader() {}
628 FourCC TrackFragmentHeader::BoxType() const { return FOURCC_TFHD; }
630 bool TrackFragmentHeader::Parse(BoxReader* reader) {
631 RCHECK(reader->ReadFullBoxHeader() && reader->Read4(&track_id));
633 // Media Source specific: reject tracks that set 'base-data-offset-present'.
634 // Although the Media Source requires that 'default-base-is-moof' (14496-12
635 // Amendment 2) be set, we omit this check as many otherwise-valid files in
636 // the wild don't set it.
638 // RCHECK((flags & 0x020000) && !(flags & 0x1));
639 RCHECK(!(reader->flags() & 0x1));
641 if (reader->flags() & 0x2) {
642 RCHECK(reader->Read4(&sample_description_index));
643 } else {
644 sample_description_index = 0;
647 if (reader->flags() & 0x8) {
648 RCHECK(reader->Read4(&default_sample_duration));
649 } else {
650 default_sample_duration = 0;
653 if (reader->flags() & 0x10) {
654 RCHECK(reader->Read4(&default_sample_size));
655 } else {
656 default_sample_size = 0;
659 if (reader->flags() & 0x20) {
660 RCHECK(reader->Read4(&default_sample_flags));
661 has_default_sample_flags = true;
662 } else {
663 has_default_sample_flags = false;
666 return true;
669 TrackFragmentRun::TrackFragmentRun()
670 : sample_count(0), data_offset(0) {}
671 TrackFragmentRun::~TrackFragmentRun() {}
672 FourCC TrackFragmentRun::BoxType() const { return FOURCC_TRUN; }
674 bool TrackFragmentRun::Parse(BoxReader* reader) {
675 RCHECK(reader->ReadFullBoxHeader() &&
676 reader->Read4(&sample_count));
677 const uint32 flags = reader->flags();
679 bool data_offset_present = (flags & 0x1) != 0;
680 bool first_sample_flags_present = (flags & 0x4) != 0;
681 bool sample_duration_present = (flags & 0x100) != 0;
682 bool sample_size_present = (flags & 0x200) != 0;
683 bool sample_flags_present = (flags & 0x400) != 0;
684 bool sample_composition_time_offsets_present = (flags & 0x800) != 0;
686 if (data_offset_present) {
687 RCHECK(reader->Read4(&data_offset));
688 } else {
689 data_offset = 0;
692 uint32 first_sample_flags;
693 if (first_sample_flags_present)
694 RCHECK(reader->Read4(&first_sample_flags));
696 int fields = sample_duration_present + sample_size_present +
697 sample_flags_present + sample_composition_time_offsets_present;
698 RCHECK(reader->HasBytes(fields * sample_count));
700 if (sample_duration_present)
701 sample_durations.resize(sample_count);
702 if (sample_size_present)
703 sample_sizes.resize(sample_count);
704 if (sample_flags_present)
705 sample_flags.resize(sample_count);
706 if (sample_composition_time_offsets_present)
707 sample_composition_time_offsets.resize(sample_count);
709 for (uint32 i = 0; i < sample_count; ++i) {
710 if (sample_duration_present)
711 RCHECK(reader->Read4(&sample_durations[i]));
712 if (sample_size_present)
713 RCHECK(reader->Read4(&sample_sizes[i]));
714 if (sample_flags_present)
715 RCHECK(reader->Read4(&sample_flags[i]));
716 if (sample_composition_time_offsets_present)
717 RCHECK(reader->Read4s(&sample_composition_time_offsets[i]));
720 if (first_sample_flags_present) {
721 if (sample_flags.size() == 0) {
722 sample_flags.push_back(first_sample_flags);
723 } else {
724 sample_flags[0] = first_sample_flags;
727 return true;
730 TrackFragment::TrackFragment() {}
731 TrackFragment::~TrackFragment() {}
732 FourCC TrackFragment::BoxType() const { return FOURCC_TRAF; }
734 bool TrackFragment::Parse(BoxReader* reader) {
735 return reader->ScanChildren() &&
736 reader->ReadChild(&header) &&
737 // Media Source specific: 'tfdt' required
738 reader->ReadChild(&decode_time) &&
739 reader->MaybeReadChildren(&runs) &&
740 reader->MaybeReadChild(&auxiliary_offset) &&
741 reader->MaybeReadChild(&auxiliary_size);
744 MovieFragment::MovieFragment() {}
745 MovieFragment::~MovieFragment() {}
746 FourCC MovieFragment::BoxType() const { return FOURCC_MOOF; }
748 bool MovieFragment::Parse(BoxReader* reader) {
749 RCHECK(reader->ScanChildren() &&
750 reader->ReadChild(&header) &&
751 reader->ReadChildren(&tracks) &&
752 reader->MaybeReadChildren(&pssh));
753 return true;
756 } // namespace mp4
757 } // namespace media