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_pssh.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "media/base/bit_reader.h" |
| 9 #include "media/formats/mp2t/mp2t_common.h" |
| 10 |
| 11 namespace media { |
| 12 namespace mp2t { |
| 13 |
| 14 TsSectionCetsPssh::TsSectionCetsPssh( |
| 15 const RegisterPsshBoxesCb& register_pssh_boxes_cb) |
| 16 : register_pssh_boxes_cb_(register_pssh_boxes_cb) {} |
| 17 |
| 18 TsSectionCetsPssh::~TsSectionCetsPssh() {} |
| 19 |
| 20 bool TsSectionCetsPssh::Parse(bool payload_unit_start_indicator, |
| 21 const uint8_t* buf, |
| 22 int size) { |
| 23 DCHECK(buf); |
| 24 // Ignore if doesn't contain PUSI. |
| 25 if (!payload_unit_start_indicator) |
| 26 return false; |
| 27 // TODO(dougsteed). This initial implementation requires the entire CETS-PSSH |
| 28 // to fit in one TS packet, so we know that the box length will fit in one |
| 29 // byte. |
| 30 BitReader bit_reader(buf, size); |
| 31 bool md5_flag; |
| 32 RCHECK(bit_reader.ReadFlag(&md5_flag) && !md5_flag); |
| 33 RCHECK(bit_reader.SkipBits(31)); |
| 34 int box_length_bits = bit_reader.bits_available(); |
| 35 std::string pssh; |
| 36 RCHECK(bit_reader.ReadString(box_length_bits, &pssh)); |
| 37 // Now check that the first 4 bytes are of the form {0x00, 0x00, 0x00, X}, |
| 38 // where X is the box length in bytes. |
| 39 RCHECK(pssh[0] == 0x00 && pssh[1] == 0x00 && pssh[2] == 0x00); |
| 40 uint8_t declared_box_bytes = static_cast<uint8_t>(pssh[3]); |
| 41 RCHECK(declared_box_bytes <= box_length_bits * 8); |
| 42 pssh.resize(declared_box_bytes); |
| 43 register_pssh_boxes_cb_.Run(std::vector<uint8_t>(pssh.begin(), pssh.end())); |
| 44 return true; |
| 45 } |
| 46 |
| 47 void TsSectionCetsPssh::Flush() { |
| 48 // No pending state. |
| 49 } |
| 50 |
| 51 void TsSectionCetsPssh::Reset() { |
| 52 // No state to clean up. |
| 53 } |
| 54 |
| 55 } // namespace mp2t |
| 56 } // namespace media |
OLD | NEW |