Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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/mp2t/ts_section_pmt.h" | |
| 6 | |
| 7 #include <map> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "media/base/bit_reader.h" | |
| 11 #include "media/mp2t/mp2t_common.h" | |
| 12 | |
| 13 namespace media { | |
| 14 namespace mp2t { | |
| 15 | |
| 16 TsSectionPmt::TsSectionPmt(RegisterPesCb register_pes_cb) | |
| 17 : register_pes_cb_(register_pes_cb) { | |
| 18 } | |
| 19 | |
| 20 TsSectionPmt::~TsSectionPmt() { | |
| 21 } | |
| 22 | |
| 23 bool TsSectionPmt::ParsePsiSection(BitReader* bit_reader) { | |
| 24 // Read up to |last_section_number|. | |
| 25 int table_id; | |
| 26 bool section_syntax_indicator; | |
| 27 bool dummy_zero; | |
| 28 int reserved; | |
| 29 int section_length; | |
| 30 int program_number; | |
| 31 int version_number; | |
| 32 bool current_next_indicator; | |
| 33 int section_number; | |
| 34 int last_section_number; | |
| 35 RCHECK(bit_reader->ReadBits(8, &table_id)); | |
| 36 RCHECK(bit_reader->ReadBits(1, §ion_syntax_indicator)); | |
| 37 RCHECK(bit_reader->ReadBits(1, &dummy_zero)); | |
| 38 RCHECK(bit_reader->ReadBits(2, &reserved)); | |
| 39 RCHECK(bit_reader->ReadBits(12, §ion_length)); | |
|
damienv1
2013/09/13 01:23:01
RCHECK(section_length >= 5);
damienv1
2013/09/13 16:07:09
Done.
| |
| 40 RCHECK(bit_reader->ReadBits(16, &program_number)); | |
| 41 RCHECK(bit_reader->ReadBits(2, &reserved)); | |
| 42 RCHECK(bit_reader->ReadBits(5, &version_number)); | |
| 43 RCHECK(bit_reader->ReadBits(1, ¤t_next_indicator)); | |
| 44 RCHECK(bit_reader->ReadBits(8, §ion_number)); | |
| 45 RCHECK(bit_reader->ReadBits(8, &last_section_number)); | |
| 46 section_length -= 5; | |
| 47 | |
| 48 // Perform a few verifications: | |
| 49 // - table ID should be 2 for a PMT. | |
| 50 // - section_syntax_indicator should be one. | |
| 51 // - section length should not exceed 1021. | |
| 52 RCHECK(table_id == 0x2); | |
| 53 RCHECK(section_syntax_indicator); | |
| 54 RCHECK(!dummy_zero); | |
| 55 RCHECK(section_length <= 1021); | |
| 56 RCHECK(section_number == 0); | |
| 57 RCHECK(last_section_number == 0); | |
| 58 | |
| 59 // TODO(damienv): | |
| 60 // Verify that there is no mismatch between the program number | |
| 61 // and the program number that was provided in a PAT for the current PMT. | |
| 62 | |
| 63 // Make sure there are enough bits for the rest of the section. | |
| 64 if (bit_reader->bits_available() < section_length * 8) { | |
| 65 LOG(WARNING) << "bits_available=" << bit_reader->bits_available(); | |
| 66 return false; | |
| 67 } | |
|
damienv1
2013/09/13 01:23:01
Not really needed anymore since a RCHECK is done e
damienv1
2013/09/13 16:07:09
Done.
| |
| 68 | |
| 69 // Read the end of the fixed length section. | |
| 70 RCHECK(section_length >= 4); | |
| 71 int pcr_pid; | |
| 72 int program_info_length; | |
| 73 RCHECK(bit_reader->ReadBits(3, &reserved)); | |
| 74 RCHECK(bit_reader->ReadBits(13, &pcr_pid)); | |
| 75 RCHECK(bit_reader->ReadBits(4, &reserved)); | |
| 76 RCHECK(bit_reader->ReadBits(12, &program_info_length)); | |
| 77 RCHECK(program_info_length < 1024); | |
| 78 section_length -= 4; | |
| 79 | |
| 80 // Read the program info descriptor. | |
| 81 // TODO(damienv): check wether any of the descriptors could be useful. | |
| 82 // Defined in section 2.6 of ISO-13818. | |
| 83 RCHECK(section_length >= program_info_length); | |
| 84 for (int k = 0; k < program_info_length; k++) { | |
| 85 int dummy; | |
| 86 RCHECK(bit_reader->ReadBits(8, &dummy)); | |
| 87 } | |
| 88 section_length -= program_info_length; | |
| 89 | |
| 90 // Read the ES description table. | |
| 91 // 5 bytes: minimum size of an ES descriptor. | |
| 92 std::map<int, int> pid_map; | |
| 93 while (section_length >= 5) { | |
| 94 int stream_type; | |
| 95 int reserved; | |
| 96 int pid_es; | |
| 97 int es_info_length; | |
| 98 RCHECK(bit_reader->ReadBits(8, &stream_type)); | |
| 99 RCHECK(bit_reader->ReadBits(3, &reserved)); | |
| 100 RCHECK(bit_reader->ReadBits(13, &pid_es)); | |
| 101 RCHECK(bit_reader->ReadBits(4, &reserved)); | |
| 102 RCHECK(bit_reader->ReadBits(12, &es_info_length)); | |
| 103 section_length -= 5; | |
| 104 | |
| 105 // Do not register the PID right away. | |
| 106 // Wait for the end of the section to be fully parsed | |
| 107 // to make sure there is no error. | |
| 108 pid_map.insert(std::pair<int, int>(pid_es, stream_type)); | |
| 109 | |
| 110 // Read the ES info descriptors. | |
| 111 // TODO(damienv): check wether any of the descriptors could be useful. | |
| 112 // Defined in section 2.6 of ISO-13818. | |
| 113 RCHECK(section_length >= es_info_length); | |
| 114 for (int k = 0; k < es_info_length; k++) { | |
| 115 int dummy; | |
| 116 RCHECK(bit_reader->ReadBits(8, &dummy)); | |
| 117 } | |
| 118 section_length -= es_info_length; | |
| 119 } | |
| 120 | |
| 121 // Read the CRC. | |
| 122 RCHECK(section_length >= 4); | |
| 123 int crc32; | |
| 124 RCHECK(bit_reader->ReadBits(32, &crc32)); | |
| 125 section_length -= 4; | |
| 126 | |
| 127 // Should not happen if the PMT size was correctly encoded into the stream. | |
| 128 DVLOG_IF(1, section_length != 0) | |
| 129 << "section_length=" << section_length; | |
| 130 | |
| 131 // Once the PMT has been proved to be correct, register the PIDs. | |
| 132 for (std::map<int, int>::iterator it = pid_map.begin(); | |
| 133 it != pid_map.end(); ++it) | |
| 134 register_pes_cb_.Run(it->first, it->second); | |
| 135 | |
| 136 return true; | |
| 137 } | |
| 138 | |
| 139 void TsSectionPmt::ResetPsiSection() { | |
| 140 } | |
| 141 | |
| 142 } // namespace mp2t | |
| 143 } // namespace media | |
| 144 | |
| OLD | NEW |