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)); | |
40 RCHECK(section_length >= 5); | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: not needed since you are using RCHECK here.
damienv1
2013/09/17 02:58:23
Done.
| |
41 RCHECK(bit_reader->ReadBits(16, &program_number)); | |
42 RCHECK(bit_reader->ReadBits(2, &reserved)); | |
43 RCHECK(bit_reader->ReadBits(5, &version_number)); | |
44 RCHECK(bit_reader->ReadBits(1, ¤t_next_indicator)); | |
45 RCHECK(bit_reader->ReadBits(8, §ion_number)); | |
46 RCHECK(bit_reader->ReadBits(8, &last_section_number)); | |
47 section_length -= 5; | |
48 | |
49 // Perform a few verifications: | |
50 // - table ID should be 2 for a PMT. | |
51 // - section_syntax_indicator should be one. | |
52 // - section length should not exceed 1021. | |
53 RCHECK(table_id == 0x2); | |
54 RCHECK(section_syntax_indicator); | |
55 RCHECK(!dummy_zero); | |
56 RCHECK(section_length <= 1021); | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
Does this need to be adjusted because of the -=5 a
damienv1
2013/09/17 02:58:23
My mistake: I was not cautious when I moved some R
| |
57 RCHECK(section_number == 0); | |
58 RCHECK(last_section_number == 0); | |
59 | |
60 // TODO(damienv): | |
61 // Verify that there is no mismatch between the program number | |
62 // and the program number that was provided in a PAT for the current PMT. | |
63 | |
64 // Read the end of the fixed length section. | |
65 RCHECK(section_length >= 4); | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: not needed
damienv1
2013/09/17 02:58:23
Done.
| |
66 int pcr_pid; | |
67 int program_info_length; | |
68 RCHECK(bit_reader->ReadBits(3, &reserved)); | |
69 RCHECK(bit_reader->ReadBits(13, &pcr_pid)); | |
70 RCHECK(bit_reader->ReadBits(4, &reserved)); | |
71 RCHECK(bit_reader->ReadBits(12, &program_info_length)); | |
72 RCHECK(program_info_length < 1024); | |
73 section_length -= 4; | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: You shouldn't need these types of updates. Yo
damienv1
2013/09/17 02:58:23
Done.
| |
74 | |
75 // Read the program info descriptor. | |
76 // TODO(damienv): check wether any of the descriptors could be useful. | |
77 // Defined in section 2.6 of ISO-13818. | |
78 RCHECK(section_length >= program_info_length); | |
79 for (int k = 0; k < program_info_length; k++) { | |
80 int dummy; | |
81 RCHECK(bit_reader->ReadBits(8, &dummy)); | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: Use SkipBits
damienv1
2013/09/17 02:58:23
Done.
| |
82 } | |
83 section_length -= program_info_length; | |
84 | |
85 // Read the ES description table. | |
86 // 5 bytes: minimum size of an ES descriptor. | |
87 std::map<int, int> pid_map; | |
88 while (section_length >= 5) { | |
89 int stream_type; | |
90 int reserved; | |
91 int pid_es; | |
92 int es_info_length; | |
93 RCHECK(bit_reader->ReadBits(8, &stream_type)); | |
94 RCHECK(bit_reader->ReadBits(3, &reserved)); | |
95 RCHECK(bit_reader->ReadBits(13, &pid_es)); | |
96 RCHECK(bit_reader->ReadBits(4, &reserved)); | |
97 RCHECK(bit_reader->ReadBits(12, &es_info_length)); | |
98 section_length -= 5; | |
99 | |
100 // Do not register the PID right away. | |
101 // Wait for the end of the section to be fully parsed | |
102 // to make sure there is no error. | |
103 pid_map.insert(std::pair<int, int>(pid_es, stream_type)); | |
104 | |
105 // Read the ES info descriptors. | |
106 // TODO(damienv): check wether any of the descriptors could be useful. | |
107 // Defined in section 2.6 of ISO-13818. | |
108 RCHECK(section_length >= es_info_length); | |
109 for (int k = 0; k < es_info_length; k++) { | |
110 int dummy; | |
111 RCHECK(bit_reader->ReadBits(8, &dummy)); | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: SkipBits instead of loop
damienv1
2013/09/17 02:58:23
Done.
| |
112 } | |
113 section_length -= es_info_length; | |
114 } | |
115 | |
116 // Read the CRC. | |
117 RCHECK(section_length >= 4); | |
118 int crc32; | |
119 RCHECK(bit_reader->ReadBits(32, &crc32)); | |
120 section_length -= 4; | |
121 | |
122 // Should not happen if the PMT size was correctly encoded into the stream. | |
123 DVLOG_IF(1, section_length != 0) << "section_length=" << section_length; | |
124 | |
125 // Once the PMT has been proved to be correct, register the PIDs. | |
126 for (std::map<int, int>::iterator it = pid_map.begin(); | |
127 it != pid_map.end(); ++it) | |
128 register_pes_cb_.Run(it->first, it->second); | |
129 | |
130 return true; | |
131 } | |
132 | |
133 void TsSectionPmt::ResetPsiSection() { | |
134 } | |
135 | |
136 } // namespace mp2t | |
137 } // namespace media | |
138 | |
OLD | NEW |