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

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: Improve buffer emission + Cleanup 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(const 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, &section_syntax_indicator));
37 RCHECK(bit_reader->ReadBits(1, &dummy_zero));
38 RCHECK(bit_reader->ReadBits(2, &reserved));
39 RCHECK(bit_reader->ReadBits(12, &section_length));
40 int section_start_marker = bit_reader->bits_available() / 8;
41
42 RCHECK(bit_reader->ReadBits(16, &program_number));
43 RCHECK(bit_reader->ReadBits(2, &reserved));
44 RCHECK(bit_reader->ReadBits(5, &version_number));
45 RCHECK(bit_reader->ReadBits(1, &current_next_indicator));
46 RCHECK(bit_reader->ReadBits(8, &section_number));
47 RCHECK(bit_reader->ReadBits(8, &last_section_number));
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);
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 int pcr_pid;
66 int program_info_length;
67 RCHECK(bit_reader->ReadBits(3, &reserved));
68 RCHECK(bit_reader->ReadBits(13, &pcr_pid));
69 RCHECK(bit_reader->ReadBits(4, &reserved));
70 RCHECK(bit_reader->ReadBits(12, &program_info_length));
71 RCHECK(program_info_length < 1024);
72
73 // Read the program info descriptor.
74 // TODO(damienv): check wether any of the descriptors could be useful.
75 // Defined in section 2.6 of ISO-13818.
76 RCHECK(bit_reader->SkipBits(8 * program_info_length));
77
78 // Read the ES description table.
79 // 5 bytes: minimum size of an ES descriptor.
80 int section_remaining_size = section_length -
81 (section_start_marker - bit_reader->bits_available() / 8);
82 std::map<int, int> pid_map;
83 while (section_remaining_size >= 5) {
acolwell GONE FROM CHROMIUM 2013/09/18 01:46:05 nit: Can't you reorganize the math so this conditi
damienv1 2013/09/18 21:40:17 Done.
84 int stream_type;
85 int reserved;
86 int pid_es;
87 int es_info_length;
88 RCHECK(bit_reader->ReadBits(8, &stream_type));
89 RCHECK(bit_reader->ReadBits(3, &reserved));
90 RCHECK(bit_reader->ReadBits(13, &pid_es));
91 RCHECK(bit_reader->ReadBits(4, &reserved));
92 RCHECK(bit_reader->ReadBits(12, &es_info_length));
93 section_remaining_size -= 5;
94
95 // Do not register the PID right away.
96 // Wait for the end of the section to be fully parsed
97 // to make sure there is no error.
98 pid_map.insert(std::pair<int, int>(pid_es, stream_type));
99
100 // Read the ES info descriptors.
101 // TODO(damienv): check wether any of the descriptors could be useful.
102 // Defined in section 2.6 of ISO-13818.
103 RCHECK(section_length >= es_info_length);
104 RCHECK(bit_reader->SkipBits(8 * es_info_length));
105 section_remaining_size -= es_info_length;
106 }
107
108 // Read the CRC.
109 int crc32;
110 RCHECK(section_remaining_size == 4);
111 RCHECK(bit_reader->ReadBits(32, &crc32));
112
113 // Once the PMT has been proved to be correct, register the PIDs.
114 for (std::map<int, int>::iterator it = pid_map.begin();
115 it != pid_map.end(); ++it)
116 register_pes_cb_.Run(it->first, it->second);
117
118 return true;
119 }
120
121 void TsSectionPmt::ResetPsiSection() {
122 }
123
124 } // namespace mp2t
125 } // namespace media
126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698