OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/formats/mp4/box_definitions.h" | 5 #include "media/formats/mp4/box_definitions.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/formats/mp4/es_descriptor.h" | 8 #include "media/formats/mp4/es_descriptor.h" |
9 #include "media/formats/mp4/rcheck.h" | 9 #include "media/formats/mp4/rcheck.h" |
10 | 10 |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 if (first_sample_flags_present) { | 753 if (first_sample_flags_present) { |
754 if (sample_flags.size() == 0) { | 754 if (sample_flags.size() == 0) { |
755 sample_flags.push_back(first_sample_flags); | 755 sample_flags.push_back(first_sample_flags); |
756 } else { | 756 } else { |
757 sample_flags[0] = first_sample_flags; | 757 sample_flags[0] = first_sample_flags; |
758 } | 758 } |
759 } | 759 } |
760 return true; | 760 return true; |
761 } | 761 } |
762 | 762 |
763 SampleToGroup::SampleToGroup() : grouping_type(0), grouping_type_parameter(0) {} | |
764 SampleToGroup::~SampleToGroup() {} | |
765 FourCC SampleToGroup::BoxType() const { return FOURCC_SBGP; } | |
766 | |
767 bool SampleToGroup::Parse(BoxReader* reader) { | |
768 RCHECK(reader->ReadFullBoxHeader() && | |
769 reader->Read4(&grouping_type)); | |
770 | |
771 if (reader->version() == 1) | |
772 RCHECK(reader->Read4(&grouping_type_parameter)); | |
773 | |
774 if (grouping_type != FOURCC_SEIG) { | |
775 DLOG(WARNING) << "SampleToGroup box with grouping_type '" << grouping_type | |
776 << "' is not supported."; | |
777 return true; | |
778 } | |
779 | |
780 uint32 count; | |
781 RCHECK(reader->Read4(&count)); | |
782 entries.resize(count); | |
783 for (uint32 i = 0; i < count; ++i) { | |
784 RCHECK(reader->Read4(&entries[i].sample_count) && | |
785 reader->Read4(&entries[i].group_description_index)); | |
786 } | |
787 return true; | |
788 } | |
789 | |
790 CencSampleEncryptionInfoEntry::CencSampleEncryptionInfoEntry() | |
791 : is_encrypted(false), iv_size(0) {} | |
792 CencSampleEncryptionInfoEntry::~CencSampleEncryptionInfoEntry() {} | |
793 | |
794 SampleGroupDescription::SampleGroupDescription() : grouping_type(0) {} | |
795 SampleGroupDescription::~SampleGroupDescription() {} | |
796 FourCC SampleGroupDescription::BoxType() const { return FOURCC_SGPD; } | |
797 | |
798 bool SampleGroupDescription::Parse(BoxReader* reader) { | |
799 RCHECK(reader->ReadFullBoxHeader() && | |
800 reader->Read4(&grouping_type)); | |
801 | |
802 if (grouping_type != FOURCC_SEIG) { | |
803 DLOG(WARNING) << "SampleGroupDescription box with grouping_type '" | |
804 << grouping_type << "' is not supported."; | |
805 return true; | |
806 } | |
807 | |
808 const uint8 version = reader->version(); | |
809 | |
810 const size_t kKeyIdSize = 16; | |
811 const size_t kEntrySize = sizeof(uint32) + kKeyIdSize; | |
812 uint32 default_length = 0; | |
813 if (version == 1) { | |
814 RCHECK(reader->Read4(&default_length)); | |
815 RCHECK(default_length == 0 || default_length == kEntrySize); | |
816 } | |
817 | |
818 uint32 count; | |
819 RCHECK(reader->Read4(&count)); | |
820 entries.resize(count); | |
821 for (uint32 i = 0; i < count; ++i) { | |
822 if (version == 1) { | |
823 if (default_length == 0) { | |
824 uint32 description_length = 0; | |
825 RCHECK(reader->Read4(&description_length)); | |
826 RCHECK(description_length == kEntrySize); | |
827 } | |
828 } | |
829 | |
830 uint8 flag; | |
831 RCHECK(reader->SkipBytes(2) && // reserved. | |
832 reader->Read1(&flag) && | |
833 reader->Read1(&entries[i].iv_size) && | |
834 reader->ReadVec(&entries[i].key_id, kKeyIdSize)); | |
835 | |
836 entries[i].is_encrypted = (flag != 0); | |
837 if (entries[i].is_encrypted) { | |
838 RCHECK(entries[i].iv_size == 8 || entries[i].iv_size == 16); | |
839 } else { | |
840 RCHECK(entries[i].iv_size == 0); | |
841 } | |
842 } | |
843 return true; | |
844 } | |
845 | |
763 TrackFragment::TrackFragment() {} | 846 TrackFragment::TrackFragment() {} |
764 TrackFragment::~TrackFragment() {} | 847 TrackFragment::~TrackFragment() {} |
765 FourCC TrackFragment::BoxType() const { return FOURCC_TRAF; } | 848 FourCC TrackFragment::BoxType() const { return FOURCC_TRAF; } |
766 | 849 |
767 bool TrackFragment::Parse(BoxReader* reader) { | 850 bool TrackFragment::Parse(BoxReader* reader) { |
768 return reader->ScanChildren() && | 851 RCHECK(reader->ScanChildren() && |
769 reader->ReadChild(&header) && | 852 reader->ReadChild(&header) && |
770 // Media Source specific: 'tfdt' required | 853 // Media Source specific: 'tfdt' required |
771 reader->ReadChild(&decode_time) && | 854 reader->ReadChild(&decode_time) && |
772 reader->MaybeReadChildren(&runs) && | 855 reader->MaybeReadChildren(&runs) && |
773 reader->MaybeReadChild(&auxiliary_offset) && | 856 reader->MaybeReadChild(&auxiliary_offset) && |
774 reader->MaybeReadChild(&auxiliary_size) && | 857 reader->MaybeReadChild(&auxiliary_size) && |
775 reader->MaybeReadChild(&sdtp); | 858 reader->MaybeReadChild(&sdtp)); |
859 | |
860 // There could be multiple SampleGroupDescription and SampleToGroup boxes with | |
861 // different grouping types. For common encryption, the relevant grouping type | |
862 // is 'seig'. Continue reading until 'seig' is found, or until run out of | |
xhwang
2014/05/01 20:53:34
s/run/running
kqyang
2014/05/06 22:13:02
Done.
| |
863 // child boxes. | |
864 while (sample_group_description.grouping_type != FOURCC_SEIG && | |
865 reader->HasChild(&sample_group_description)) { | |
866 RCHECK(reader->ReadChild(&sample_group_description)); | |
867 } | |
868 while (sample_to_group.grouping_type != FOURCC_SEIG && | |
869 reader->HasChild(&sample_to_group)) { | |
870 RCHECK(reader->ReadChild(&sample_to_group)); | |
871 } | |
872 return true; | |
776 } | 873 } |
777 | 874 |
778 MovieFragment::MovieFragment() {} | 875 MovieFragment::MovieFragment() {} |
779 MovieFragment::~MovieFragment() {} | 876 MovieFragment::~MovieFragment() {} |
780 FourCC MovieFragment::BoxType() const { return FOURCC_MOOF; } | 877 FourCC MovieFragment::BoxType() const { return FOURCC_MOOF; } |
781 | 878 |
782 bool MovieFragment::Parse(BoxReader* reader) { | 879 bool MovieFragment::Parse(BoxReader* reader) { |
783 RCHECK(reader->ScanChildren() && | 880 RCHECK(reader->ScanChildren() && |
784 reader->ReadChild(&header) && | 881 reader->ReadChild(&header) && |
785 reader->ReadChildren(&tracks) && | 882 reader->ReadChildren(&tracks) && |
(...skipping 28 matching lines...) Expand all Loading... | |
814 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 911 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
815 size_t i) const { | 912 size_t i) const { |
816 if (i >= sample_depends_on_.size()) | 913 if (i >= sample_depends_on_.size()) |
817 return kSampleDependsOnUnknown; | 914 return kSampleDependsOnUnknown; |
818 | 915 |
819 return sample_depends_on_[i]; | 916 return sample_depends_on_[i]; |
820 } | 917 } |
821 | 918 |
822 } // namespace mp4 | 919 } // namespace mp4 |
823 } // namespace media | 920 } // namespace media |
OLD | NEW |