Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: media/mp2t/ts_section_pmt.cc

Issue 23566013: Mpeg2 TS stream parser for media source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better naming: mp2t namespace & class names Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 if (bit_reader->bits_available() < 8 * 8) {
26 DVLOG(1) << "bits_available=" << bit_reader->bits_available();
27 return false;
28 }
29 int table_id;
30 bool section_syntax_indicator;
31 bool dummy_zero;
32 int reserved;
33 int section_length;
34 int program_number;
35 int version_number;
36 bool current_next_indicator;
37 int section_number;
38 int last_section_number;
39 DCHECK(bit_reader->ReadBits(8, &table_id));
40 DCHECK(bit_reader->ReadBits(1, &section_syntax_indicator));
41 DCHECK(bit_reader->ReadBits(1, &dummy_zero));
42 DCHECK(bit_reader->ReadBits(2, &reserved));
43 DCHECK(bit_reader->ReadBits(12, &section_length));
44 DCHECK(bit_reader->ReadBits(16, &program_number));
45 DCHECK(bit_reader->ReadBits(2, &reserved));
46 DCHECK(bit_reader->ReadBits(5, &version_number));
47 DCHECK(bit_reader->ReadBits(1, &current_next_indicator));
48 DCHECK(bit_reader->ReadBits(8, &section_number));
49 DCHECK(bit_reader->ReadBits(8, &last_section_number));
50 section_length -= 5;
51
52 // Perform a few verifications:
53 // - table ID should be 2 for a PMT.
54 // - section_syntax_indicator should be one.
55 // - section length should not exceed 1021.
56 RCHECK(table_id == 0x2);
57 RCHECK(section_syntax_indicator);
58 RCHECK(!dummy_zero);
59 RCHECK(section_length <= 1021);
60 RCHECK(section_number == 0);
61 RCHECK(last_section_number == 0);
62
63 // TODO(damienv):
64 // Verify that there is no mismatch between the program number
65 // and the program number that was provided in a PAT for the current PMT.
66
67 // Make sure there are enough bits for the rest of the section.
68 if (bit_reader->bits_available() < section_length * 8) {
69 LOG(WARNING) << "bits_available=" << bit_reader->bits_available();
70 return false;
71 }
72
73 // Read the end of the fixed length section.
74 if (section_length < 4) {
75 LOG(WARNING) << "Section length too small";
76 return false;
77 }
78 int pcr_pid;
79 int program_info_length;
80 DCHECK(bit_reader->ReadBits(3, &reserved));
81 DCHECK(bit_reader->ReadBits(13, &pcr_pid));
82 DCHECK(bit_reader->ReadBits(4, &reserved));
83 DCHECK(bit_reader->ReadBits(12, &program_info_length));
84 RCHECK(program_info_length < 1024);
85 section_length -= 4;
86
87 // Read the program info descriptor.
88 // TODO(damienv): check wether any of the descriptors could be useful.
89 // Defined in section 2.6 of ISO-13818.
90 if (section_length < program_info_length) {
91 DVLOG(1) << "Section length too small";
92 return false;
93 }
94 for (int k = 0; k < program_info_length; k++) {
95 int dummy;
96 DCHECK(bit_reader->ReadBits(8, &dummy));
97 }
98 section_length -= program_info_length;
99
100 // Read the ES description table.
101 // 5 bytes: minimum size of an ES descriptor.
102 std::map<int, int> pid_map;
103 while (section_length >= 5) {
104 int stream_type;
105 int reserved;
106 int pid_es;
107 int es_info_length;
108 DCHECK(bit_reader->ReadBits(8, &stream_type));
109 DCHECK(bit_reader->ReadBits(3, &reserved));
110 DCHECK(bit_reader->ReadBits(13, &pid_es));
111 DCHECK(bit_reader->ReadBits(4, &reserved));
112 DCHECK(bit_reader->ReadBits(12, &es_info_length));
113 section_length -= 5;
114
115 // Do not register the PID right away.
116 // Wait for the end of the section to be fully parsed
117 // to make sure there is no error.
118 pid_map.insert(std::pair<int, int>(pid_es, stream_type));
119
120 // Read the ES info descriptors.
121 // TODO(damienv): check wether any of the descriptors could be useful.
122 // Defined in section 2.6 of ISO-13818.
123 if (section_length < es_info_length) {
124 DVLOG(1) << "section_length=" << section_length
125 << " es_info_length=" << es_info_length;
126 return false;
127 }
128 for (int k = 0; k < es_info_length; k++) {
129 int dummy;
130 DCHECK(bit_reader->ReadBits(8, &dummy));
131 }
132 section_length -= es_info_length;
133 }
134
135 // Read the CRC.
136 if (section_length < 4) {
137 DVLOG(1) << "Section length too small: " << section_length;
138 return false;
139 }
140 int crc32;
141 DCHECK(bit_reader->ReadBits(32, &crc32));
142 section_length -= 4;
143
144 // Should not happen if the PMT size was correctly encoded into the stream.
145 DVLOG_IF(1, section_length != 0)
146 << "section_length=" << section_length;
147
148 // Once the PMT has been proved to be correct, register the PIDs.
149 for (std::map<int, int>::iterator it = pid_map.begin();
150 it != pid_map.end(); ++it)
151 register_pes_cb_.Run(it->first, it->second);
152
153 return true;
154 }
155
156 void TsSectionPmt::ResetPsiSection() {
157 }
158
159 } // namespace mp2t
160 } // namespace media
161
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698