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

Unified 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: Address comment about DCHECK vs RCHECK 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 side-by-side diff with in-line comments
Download patch
Index: media/mp2t/ts_section_pmt.cc
diff --git a/media/mp2t/ts_section_pmt.cc b/media/mp2t/ts_section_pmt.cc
new file mode 100644
index 0000000000000000000000000000000000000000..111652afee9560bd76e0b503f5d360692608a6a7
--- /dev/null
+++ b/media/mp2t/ts_section_pmt.cc
@@ -0,0 +1,144 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/mp2t/ts_section_pmt.h"
+
+#include <map>
+
+#include "base/logging.h"
+#include "media/base/bit_reader.h"
+#include "media/mp2t/mp2t_common.h"
+
+namespace media {
+namespace mp2t {
+
+TsSectionPmt::TsSectionPmt(RegisterPesCb register_pes_cb)
+ : register_pes_cb_(register_pes_cb) {
+}
+
+TsSectionPmt::~TsSectionPmt() {
+}
+
+bool TsSectionPmt::ParsePsiSection(BitReader* bit_reader) {
+ // Read up to |last_section_number|.
+ int table_id;
+ bool section_syntax_indicator;
+ bool dummy_zero;
+ int reserved;
+ int section_length;
+ int program_number;
+ int version_number;
+ bool current_next_indicator;
+ int section_number;
+ int last_section_number;
+ RCHECK(bit_reader->ReadBits(8, &table_id));
+ RCHECK(bit_reader->ReadBits(1, &section_syntax_indicator));
+ RCHECK(bit_reader->ReadBits(1, &dummy_zero));
+ RCHECK(bit_reader->ReadBits(2, &reserved));
+ RCHECK(bit_reader->ReadBits(12, &section_length));
damienv1 2013/09/13 01:23:01 RCHECK(section_length >= 5);
damienv1 2013/09/13 16:07:09 Done.
+ RCHECK(bit_reader->ReadBits(16, &program_number));
+ RCHECK(bit_reader->ReadBits(2, &reserved));
+ RCHECK(bit_reader->ReadBits(5, &version_number));
+ RCHECK(bit_reader->ReadBits(1, &current_next_indicator));
+ RCHECK(bit_reader->ReadBits(8, &section_number));
+ RCHECK(bit_reader->ReadBits(8, &last_section_number));
+ section_length -= 5;
+
+ // Perform a few verifications:
+ // - table ID should be 2 for a PMT.
+ // - section_syntax_indicator should be one.
+ // - section length should not exceed 1021.
+ RCHECK(table_id == 0x2);
+ RCHECK(section_syntax_indicator);
+ RCHECK(!dummy_zero);
+ RCHECK(section_length <= 1021);
+ RCHECK(section_number == 0);
+ RCHECK(last_section_number == 0);
+
+ // TODO(damienv):
+ // Verify that there is no mismatch between the program number
+ // and the program number that was provided in a PAT for the current PMT.
+
+ // Make sure there are enough bits for the rest of the section.
+ if (bit_reader->bits_available() < section_length * 8) {
+ LOG(WARNING) << "bits_available=" << bit_reader->bits_available();
+ return false;
+ }
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.
+
+ // Read the end of the fixed length section.
+ RCHECK(section_length >= 4);
+ int pcr_pid;
+ int program_info_length;
+ RCHECK(bit_reader->ReadBits(3, &reserved));
+ RCHECK(bit_reader->ReadBits(13, &pcr_pid));
+ RCHECK(bit_reader->ReadBits(4, &reserved));
+ RCHECK(bit_reader->ReadBits(12, &program_info_length));
+ RCHECK(program_info_length < 1024);
+ section_length -= 4;
+
+ // Read the program info descriptor.
+ // TODO(damienv): check wether any of the descriptors could be useful.
+ // Defined in section 2.6 of ISO-13818.
+ RCHECK(section_length >= program_info_length);
+ for (int k = 0; k < program_info_length; k++) {
+ int dummy;
+ RCHECK(bit_reader->ReadBits(8, &dummy));
+ }
+ section_length -= program_info_length;
+
+ // Read the ES description table.
+ // 5 bytes: minimum size of an ES descriptor.
+ std::map<int, int> pid_map;
+ while (section_length >= 5) {
+ int stream_type;
+ int reserved;
+ int pid_es;
+ int es_info_length;
+ RCHECK(bit_reader->ReadBits(8, &stream_type));
+ RCHECK(bit_reader->ReadBits(3, &reserved));
+ RCHECK(bit_reader->ReadBits(13, &pid_es));
+ RCHECK(bit_reader->ReadBits(4, &reserved));
+ RCHECK(bit_reader->ReadBits(12, &es_info_length));
+ section_length -= 5;
+
+ // Do not register the PID right away.
+ // Wait for the end of the section to be fully parsed
+ // to make sure there is no error.
+ pid_map.insert(std::pair<int, int>(pid_es, stream_type));
+
+ // Read the ES info descriptors.
+ // TODO(damienv): check wether any of the descriptors could be useful.
+ // Defined in section 2.6 of ISO-13818.
+ RCHECK(section_length >= es_info_length);
+ for (int k = 0; k < es_info_length; k++) {
+ int dummy;
+ RCHECK(bit_reader->ReadBits(8, &dummy));
+ }
+ section_length -= es_info_length;
+ }
+
+ // Read the CRC.
+ RCHECK(section_length >= 4);
+ int crc32;
+ RCHECK(bit_reader->ReadBits(32, &crc32));
+ section_length -= 4;
+
+ // Should not happen if the PMT size was correctly encoded into the stream.
+ DVLOG_IF(1, section_length != 0)
+ << "section_length=" << section_length;
+
+ // Once the PMT has been proved to be correct, register the PIDs.
+ for (std::map<int, int>::iterator it = pid_map.begin();
+ it != pid_map.end(); ++it)
+ register_pes_cb_.Run(it->first, it->second);
+
+ return true;
+}
+
+void TsSectionPmt::ResetPsiSection() {
+}
+
+} // namespace mp2t
+} // namespace media
+

Powered by Google App Engine
This is Rietveld 408576698