OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/formats/mp2t/ts_section_cets_ecm.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "media/base/bit_reader.h" |
| 9 #include "media/base/decrypt_config.h" |
| 10 #include "media/formats/mp2t/mp2t_common.h" |
| 11 |
| 12 namespace media { |
| 13 namespace mp2t { |
| 14 |
| 15 TsSectionCetsEcm::TsSectionCetsEcm( |
| 16 const RegisterDecryptConfigCb& register_decrypt_config_cb) |
| 17 : register_decrypt_config_cb_(register_decrypt_config_cb) {} |
| 18 |
| 19 TsSectionCetsEcm::~TsSectionCetsEcm() {} |
| 20 |
| 21 bool TsSectionCetsEcm::Parse(bool payload_unit_start_indicator, |
| 22 const uint8_t* buf, |
| 23 int size) { |
| 24 DCHECK(buf); |
| 25 BitReader bit_reader(buf, size); |
| 26 int num_states; |
| 27 bool next_key_id_flag; |
| 28 bool no_byte_align; |
| 29 int iv_size; |
| 30 std::string key_id; |
| 31 int transport_scrambling_control; |
| 32 int num_au; |
| 33 bool key_id_flag; |
| 34 int au_byte_offset_size; |
| 35 std::string iv; |
| 36 std::vector<SubsampleEntry> subsamples_empty; |
| 37 // TODO(dougsteed). Currently we allow only a subset of the possible values. |
| 38 // When we flesh out this implementation to cover all of ISO/IEC 23001-9 we |
| 39 // will need to generalize this. |
| 40 RCHECK(bit_reader.ReadBits(2, &num_states)); |
| 41 RCHECK(num_states == 1); |
| 42 RCHECK(bit_reader.ReadFlag(&next_key_id_flag) && !next_key_id_flag); |
| 43 // TODO(dougsteed). The standard (ISO/IEC 23001-9:2014) reserves 3 bits, |
| 44 // whereas it likely was intended to be 5 bits to follow the usual practice of |
| 45 // syncing to a byte boundary for the byte oriented fields that follow. |
| 46 // For now, we plan to use it with byte alignment for convenience. Rather than |
| 47 // just having an unadvertized deviation from the standard, I have repurposed |
| 48 // the first reserved bit as a flag. This approach gives flexibility for the |
| 49 // future if the standard is fixed or comes into wide use in its present form. |
| 50 RCHECK(bit_reader.ReadFlag(&no_byte_align)); |
| 51 if (no_byte_align) |
| 52 RCHECK(bit_reader.SkipBits(2)); |
| 53 else |
| 54 RCHECK(bit_reader.SkipBits(4)); |
| 55 RCHECK(bit_reader.ReadBits(8, &iv_size)); |
| 56 RCHECK(iv_size == 16); |
| 57 RCHECK(bit_reader.ReadString(128, &key_id)); |
| 58 RCHECK(bit_reader.ReadBits(2, &transport_scrambling_control)); |
| 59 RCHECK(transport_scrambling_control == 0); |
| 60 RCHECK(bit_reader.ReadBits(6, &num_au)); |
| 61 RCHECK(num_au == 1); |
| 62 RCHECK(bit_reader.ReadFlag(&key_id_flag) && !key_id_flag); |
| 63 RCHECK(bit_reader.SkipBits(3)); |
| 64 RCHECK(bit_reader.ReadBits(4, &au_byte_offset_size)); |
| 65 RCHECK(au_byte_offset_size == 0); |
| 66 RCHECK(bit_reader.ReadString(128, &iv)); |
| 67 // The CETS-ECM is supposed to use adaptation field stuffing to fill the TS |
| 68 // packet, so there should be no data left to read. |
| 69 RCHECK(bit_reader.bits_available() == 0); |
| 70 DecryptConfig decrypt_config(key_id, iv, subsamples_empty); |
| 71 register_decrypt_config_cb_.Run(decrypt_config); |
| 72 return true; |
| 73 } |
| 74 |
| 75 void TsSectionCetsEcm::Flush() { |
| 76 // No pending state. |
| 77 } |
| 78 |
| 79 void TsSectionCetsEcm::Reset() { |
| 80 // No state to clean up. |
| 81 } |
| 82 |
| 83 } // namespace mp2t |
| 84 } // namespace media |
OLD | NEW |