| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mp2t/descriptors.h" | 5 #include "media/formats/mp2t/descriptors.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/bit_reader.h" | 10 #include "media/base/bit_reader.h" |
| 11 #include "media/base/encryption_scheme.h" |
| 11 #include "media/formats/mp2t/mp2t_common.h" | 12 #include "media/formats/mp2t/mp2t_common.h" |
| 12 | 13 |
| 13 namespace media { | 14 namespace media { |
| 14 namespace mp2t { | 15 namespace mp2t { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Tag values for various kinds of descriptors for which there is specific | 19 // Tag values for various kinds of descriptors for which there is specific |
| 19 // parsing support herein. | 20 // parsing support herein. |
| 20 enum DescriptorTag { | 21 enum DescriptorTag { |
| 21 DESCRIPTOR_TAG_REGISTRATION = 5, | 22 DESCRIPTOR_TAG_REGISTRATION = 5, |
| 22 DESCRIPTOR_TAG_CA = 9, | 23 DESCRIPTOR_TAG_CA = 9, |
| 23 DESCRIPTOR_TAG_PRIVATE_DATA_INDICATOR = 15, | 24 DESCRIPTOR_TAG_PRIVATE_DATA_INDICATOR = 15, |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 const int kCASystemIdCenc = 0x6365; // 'ce' | 27 const int kCASystemIdCenc = 0x6365; // 'ce' |
| 28 const uint32_t kFourccCbcs = 0x63626373; // 'cbcs' |
| 27 | 29 |
| 28 class StringBitReader : public BitReader { | 30 class StringBitReader : public BitReader { |
| 29 public: | 31 public: |
| 30 StringBitReader(const std::string& input); | 32 StringBitReader(const std::string& input); |
| 31 ~StringBitReader() override; | 33 ~StringBitReader() override; |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 StringBitReader::StringBitReader(const std::string& input) | 36 StringBitReader::StringBitReader(const std::string& input) |
| 35 : BitReader(reinterpret_cast<const uint8_t*>(input.data()), input.size()) {} | 37 : BitReader(reinterpret_cast<const uint8_t*>(input.data()), input.size()) {} |
| 36 | 38 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 StringBitReader reader(data); | 105 StringBitReader reader(data); |
| 104 RCHECK(reader.ReadBits(16, system_id)); | 106 RCHECK(reader.ReadBits(16, system_id)); |
| 105 RCHECK(reader.SkipBits(3)); | 107 RCHECK(reader.SkipBits(3)); |
| 106 RCHECK(reader.ReadBits(13, pid)); | 108 RCHECK(reader.ReadBits(13, pid)); |
| 107 size_t extra_bits = reader.bits_available(); | 109 size_t extra_bits = reader.bits_available(); |
| 108 RCHECK(extra_bits % 8 == 0); | 110 RCHECK(extra_bits % 8 == 0); |
| 109 RCHECK(reader.ReadString(extra_bits, private_data)); | 111 RCHECK(reader.ReadString(extra_bits, private_data)); |
| 110 return true; | 112 return true; |
| 111 } | 113 } |
| 112 | 114 |
| 113 bool Descriptors::HasCADescriptorCenc(int* ca_pid, int* pssh_pid) const { | 115 bool Descriptors::HasCADescriptorCenc(int* ca_pid, |
| 116 int* pssh_pid, |
| 117 EncryptionScheme* scheme) const { |
| 114 DCHECK(ca_pid); | 118 DCHECK(ca_pid); |
| 115 DCHECK(pssh_pid); | 119 DCHECK(pssh_pid); |
| 116 int system_id; | 120 int system_id; |
| 117 std::string private_data; | 121 std::string private_data; |
| 118 if (!HasCADescriptor(&system_id, ca_pid, &private_data)) | 122 if (!HasCADescriptor(&system_id, ca_pid, &private_data)) |
| 119 return false; | 123 return false; |
| 120 if (system_id != kCASystemIdCenc) | 124 if (system_id != kCASystemIdCenc) |
| 121 return false; | 125 return false; |
| 122 StringBitReader reader(private_data); | 126 StringBitReader reader(private_data); |
| 123 uint32_t scheme_type; | 127 uint32_t scheme_type; |
| 124 uint32_t scheme_version; | 128 uint32_t scheme_version; |
| 125 int num_systems; | 129 int num_systems; |
| 126 int encryption_algorithm; | 130 int encryption_algorithm; |
| 127 char pssh_system_id[16]; | 131 char pssh_system_id[16]; |
| 128 // TODO(dougsteed). Currently we don't check many of the following values. | 132 // TODO(dougsteed). Currently we don't check many of the following values, |
| 133 // and we only support the 'cbcs' scheme (which involves AES-CBC encryption). |
| 129 // When we flesh out this implementation to cover all of ISO/IEC 23001-9 we | 134 // When we flesh out this implementation to cover all of ISO/IEC 23001-9 we |
| 130 // will need to use and check these values. | 135 // will need to use and check these values more comprehensively. |
| 131 RCHECK(reader.ReadBits(32, &scheme_type)); | 136 RCHECK(reader.ReadBits(32, &scheme_type)); |
| 137 RCHECK(scheme_type == kFourccCbcs); |
| 132 RCHECK(reader.ReadBits(32, &scheme_version)); | 138 RCHECK(reader.ReadBits(32, &scheme_version)); |
| 133 RCHECK(reader.ReadBits(8, &num_systems)); | 139 RCHECK(reader.ReadBits(8, &num_systems)); |
| 134 RCHECK(num_systems == 1); | 140 RCHECK(num_systems == 1); |
| 135 RCHECK(reader.ReadBits(24, &encryption_algorithm)); | 141 RCHECK(reader.ReadBits(24, &encryption_algorithm)); |
| 136 for (size_t i = 0; i < 16; i++) { | 142 for (size_t i = 0; i < 16; i++) { |
| 137 RCHECK(reader.ReadBits(8, &pssh_system_id[i])); | 143 RCHECK(reader.ReadBits(8, &pssh_system_id[i])); |
| 138 } | 144 } |
| 139 RCHECK(reader.ReadBits(13, pssh_pid)); | 145 RCHECK(reader.ReadBits(13, pssh_pid)); |
| 146 // The pattern is actually set differently for audio and video, so OK not to |
| 147 // set it here. Important thing is to set the cipher mode. |
| 148 *scheme = EncryptionScheme(EncryptionScheme::CIPHER_MODE_AES_CBC, |
| 149 EncryptionScheme::Pattern()); |
| 140 return true; | 150 return true; |
| 141 } | 151 } |
| 142 | 152 |
| 143 bool Descriptors::HasPrivateDataIndicator(int64_t value) const { | 153 bool Descriptors::HasPrivateDataIndicator(int64_t value) const { |
| 144 int64_t private_data_indicator; | 154 int64_t private_data_indicator; |
| 145 auto search = descriptors_.find(DESCRIPTOR_TAG_PRIVATE_DATA_INDICATOR); | 155 auto search = descriptors_.find(DESCRIPTOR_TAG_PRIVATE_DATA_INDICATOR); |
| 146 if (search == descriptors_.end()) | 156 if (search == descriptors_.end()) |
| 147 return false; | 157 return false; |
| 148 const std::string& data = search->second; | 158 const std::string& data = search->second; |
| 149 StringBitReader reader(data); | 159 StringBitReader reader(data); |
| 150 RCHECK(reader.ReadBits(32, &private_data_indicator)); | 160 RCHECK(reader.ReadBits(32, &private_data_indicator)); |
| 151 RCHECK(reader.bits_available() == 0); | 161 RCHECK(reader.bits_available() == 0); |
| 152 return private_data_indicator == value; | 162 return private_data_indicator == value; |
| 153 } | 163 } |
| 154 | 164 |
| 155 } // namespace mp2t | 165 } // namespace mp2t |
| 156 } // namespace media | 166 } // namespace media |
| OLD | NEW |