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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 if (first_sample_flags_present) { | 764 if (first_sample_flags_present) { |
765 if (sample_flags.size() == 0) { | 765 if (sample_flags.size() == 0) { |
766 sample_flags.push_back(first_sample_flags); | 766 sample_flags.push_back(first_sample_flags); |
767 } else { | 767 } else { |
768 sample_flags[0] = first_sample_flags; | 768 sample_flags[0] = first_sample_flags; |
769 } | 769 } |
770 } | 770 } |
771 return true; | 771 return true; |
772 } | 772 } |
773 | 773 |
| 774 SampleToGroup::SampleToGroup() : grouping_type(0), grouping_type_parameter(0) {} |
| 775 SampleToGroup::~SampleToGroup() {} |
| 776 FourCC SampleToGroup::BoxType() const { return FOURCC_SBGP; } |
| 777 |
| 778 bool SampleToGroup::Parse(BoxReader* reader) { |
| 779 RCHECK(reader->ReadFullBoxHeader() && |
| 780 reader->Read4(&grouping_type)); |
| 781 |
| 782 if (reader->version() == 1) |
| 783 RCHECK(reader->Read4(&grouping_type_parameter)); |
| 784 |
| 785 if (grouping_type != FOURCC_SEIG) { |
| 786 DLOG(WARNING) << "SampleToGroup box with grouping_type '" << grouping_type |
| 787 << "' is not supported."; |
| 788 return true; |
| 789 } |
| 790 |
| 791 uint32 count; |
| 792 RCHECK(reader->Read4(&count)); |
| 793 entries.resize(count); |
| 794 for (uint32 i = 0; i < count; ++i) { |
| 795 RCHECK(reader->Read4(&entries[i].sample_count) && |
| 796 reader->Read4(&entries[i].group_description_index)); |
| 797 } |
| 798 return true; |
| 799 } |
| 800 |
| 801 CencSampleEncryptionInfoEntry::CencSampleEncryptionInfoEntry() |
| 802 : is_encrypted(false), iv_size(0) {} |
| 803 CencSampleEncryptionInfoEntry::~CencSampleEncryptionInfoEntry() {} |
| 804 |
| 805 SampleGroupDescription::SampleGroupDescription() : grouping_type(0) {} |
| 806 SampleGroupDescription::~SampleGroupDescription() {} |
| 807 FourCC SampleGroupDescription::BoxType() const { return FOURCC_SGPD; } |
| 808 |
| 809 bool SampleGroupDescription::Parse(BoxReader* reader) { |
| 810 RCHECK(reader->ReadFullBoxHeader() && |
| 811 reader->Read4(&grouping_type)); |
| 812 |
| 813 if (grouping_type != FOURCC_SEIG) { |
| 814 DLOG(WARNING) << "SampleGroupDescription box with grouping_type '" |
| 815 << grouping_type << "' is not supported."; |
| 816 return true; |
| 817 } |
| 818 |
| 819 const uint8 version = reader->version(); |
| 820 |
| 821 const size_t kKeyIdSize = 16; |
| 822 const size_t kEntrySize = sizeof(uint32) + kKeyIdSize; |
| 823 uint32 default_length = 0; |
| 824 if (version == 1) { |
| 825 RCHECK(reader->Read4(&default_length)); |
| 826 RCHECK(default_length == 0 || default_length >= kEntrySize); |
| 827 } |
| 828 |
| 829 uint32 count; |
| 830 RCHECK(reader->Read4(&count)); |
| 831 entries.resize(count); |
| 832 for (uint32 i = 0; i < count; ++i) { |
| 833 if (version == 1) { |
| 834 if (default_length == 0) { |
| 835 uint32 description_length = 0; |
| 836 RCHECK(reader->Read4(&description_length)); |
| 837 RCHECK(description_length >= kEntrySize); |
| 838 } |
| 839 } |
| 840 |
| 841 uint8 flag; |
| 842 RCHECK(reader->SkipBytes(2) && // reserved. |
| 843 reader->Read1(&flag) && |
| 844 reader->Read1(&entries[i].iv_size) && |
| 845 reader->ReadVec(&entries[i].key_id, kKeyIdSize)); |
| 846 |
| 847 entries[i].is_encrypted = (flag != 0); |
| 848 if (entries[i].is_encrypted) { |
| 849 RCHECK(entries[i].iv_size == 8 || entries[i].iv_size == 16); |
| 850 } else { |
| 851 RCHECK(entries[i].iv_size == 0); |
| 852 } |
| 853 } |
| 854 return true; |
| 855 } |
| 856 |
774 TrackFragment::TrackFragment() {} | 857 TrackFragment::TrackFragment() {} |
775 TrackFragment::~TrackFragment() {} | 858 TrackFragment::~TrackFragment() {} |
776 FourCC TrackFragment::BoxType() const { return FOURCC_TRAF; } | 859 FourCC TrackFragment::BoxType() const { return FOURCC_TRAF; } |
777 | 860 |
778 bool TrackFragment::Parse(BoxReader* reader) { | 861 bool TrackFragment::Parse(BoxReader* reader) { |
779 return reader->ScanChildren() && | 862 RCHECK(reader->ScanChildren() && |
780 reader->ReadChild(&header) && | 863 reader->ReadChild(&header) && |
781 // Media Source specific: 'tfdt' required | 864 // Media Source specific: 'tfdt' required |
782 reader->ReadChild(&decode_time) && | 865 reader->ReadChild(&decode_time) && |
783 reader->MaybeReadChildren(&runs) && | 866 reader->MaybeReadChildren(&runs) && |
784 reader->MaybeReadChild(&auxiliary_offset) && | 867 reader->MaybeReadChild(&auxiliary_offset) && |
785 reader->MaybeReadChild(&auxiliary_size) && | 868 reader->MaybeReadChild(&auxiliary_size) && |
786 reader->MaybeReadChild(&sdtp); | 869 reader->MaybeReadChild(&sdtp)); |
| 870 |
| 871 // There could be multiple SampleGroupDescription and SampleToGroup boxes with |
| 872 // different grouping types. For common encryption, the relevant grouping type |
| 873 // is 'seig'. Continue reading until 'seig' is found, or until running out of |
| 874 // child boxes. |
| 875 while (sample_group_description.grouping_type != FOURCC_SEIG && |
| 876 reader->HasChild(&sample_group_description)) { |
| 877 RCHECK(reader->ReadChild(&sample_group_description)); |
| 878 } |
| 879 while (sample_to_group.grouping_type != FOURCC_SEIG && |
| 880 reader->HasChild(&sample_to_group)) { |
| 881 RCHECK(reader->ReadChild(&sample_to_group)); |
| 882 } |
| 883 return true; |
787 } | 884 } |
788 | 885 |
789 MovieFragment::MovieFragment() {} | 886 MovieFragment::MovieFragment() {} |
790 MovieFragment::~MovieFragment() {} | 887 MovieFragment::~MovieFragment() {} |
791 FourCC MovieFragment::BoxType() const { return FOURCC_MOOF; } | 888 FourCC MovieFragment::BoxType() const { return FOURCC_MOOF; } |
792 | 889 |
793 bool MovieFragment::Parse(BoxReader* reader) { | 890 bool MovieFragment::Parse(BoxReader* reader) { |
794 RCHECK(reader->ScanChildren() && | 891 RCHECK(reader->ScanChildren() && |
795 reader->ReadChild(&header) && | 892 reader->ReadChild(&header) && |
796 reader->ReadChildren(&tracks) && | 893 reader->ReadChildren(&tracks) && |
(...skipping 28 matching lines...) Expand all Loading... |
825 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 922 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
826 size_t i) const { | 923 size_t i) const { |
827 if (i >= sample_depends_on_.size()) | 924 if (i >= sample_depends_on_.size()) |
828 return kSampleDependsOnUnknown; | 925 return kSampleDependsOnUnknown; |
829 | 926 |
830 return sample_depends_on_[i]; | 927 return sample_depends_on_[i]; |
831 } | 928 } |
832 | 929 |
833 } // namespace mp4 | 930 } // namespace mp4 |
834 } // namespace media | 931 } // namespace media |
OLD | NEW |