Commit f7025687 by aquilescanta Committed by Oliver Woodman

Skip tables with unexpected table_id for PAT and PMT readers

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140606435
parent 289ae3ff
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.extractor.ts; package com.google.android.exoplayer2.extractor.ts;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.TimestampAdjuster; import com.google.android.exoplayer2.extractor.TimestampAdjuster;
import com.google.android.exoplayer2.util.ParsableBitArray; import com.google.android.exoplayer2.util.ParsableBitArray;
...@@ -44,16 +45,16 @@ public final class SectionReader implements TsPayloadReader { ...@@ -44,16 +45,16 @@ public final class SectionReader implements TsPayloadReader {
public void init(TimestampAdjuster timestampAdjuster, ExtractorOutput extractorOutput, public void init(TimestampAdjuster timestampAdjuster, ExtractorOutput extractorOutput,
TrackIdGenerator idGenerator) { TrackIdGenerator idGenerator) {
reader.init(timestampAdjuster, extractorOutput, idGenerator); reader.init(timestampAdjuster, extractorOutput, idGenerator);
sectionLength = C.LENGTH_UNSET;
} }
@Override @Override
public void seek() { public void seek() {
// Do nothing. sectionLength = C.LENGTH_UNSET;
} }
@Override @Override
public void consume(ParsableByteArray data, boolean payloadUnitStartIndicator) { public void consume(ParsableByteArray data, boolean payloadUnitStartIndicator) {
// Skip pointer.
if (payloadUnitStartIndicator) { if (payloadUnitStartIndicator) {
int pointerField = data.readUnsignedByte(); int pointerField = data.readUnsignedByte();
data.skipBytes(pointerField); data.skipBytes(pointerField);
...@@ -67,6 +68,9 @@ public final class SectionReader implements TsPayloadReader { ...@@ -67,6 +68,9 @@ public final class SectionReader implements TsPayloadReader {
sectionBytesRead = 0; sectionBytesRead = 0;
sectionData.reset(sectionLength); sectionData.reset(sectionLength);
} else if (sectionLength == C.LENGTH_UNSET) {
// We're not already reading a section and this is not the start of a new one.
return;
} }
int bytesToRead = Math.min(data.bytesLeft(), sectionLength - sectionBytesRead); int bytesToRead = Math.min(data.bytesLeft(), sectionLength - sectionBytesRead);
...@@ -76,8 +80,8 @@ public final class SectionReader implements TsPayloadReader { ...@@ -76,8 +80,8 @@ public final class SectionReader implements TsPayloadReader {
// Not yet fully read. // Not yet fully read.
return; return;
} }
sectionLength = C.LENGTH_UNSET;
if (Util.crc(sectionData.data, 0, sectionLength, 0xFFFFFFFF) != 0) { if (Util.crc(sectionData.data, 0, sectionBytesRead, 0xFFFFFFFF) != 0) {
// CRC Invalid. The section gets discarded. // CRC Invalid. The section gets discarded.
return; return;
} }
......
...@@ -283,10 +283,15 @@ public final class TsExtractor implements Extractor { ...@@ -283,10 +283,15 @@ public final class TsExtractor implements Extractor {
@Override @Override
public void consume(ParsableByteArray sectionData) { public void consume(ParsableByteArray sectionData) {
// table_id(8), section_syntax_indicator(1), '0'(1), reserved(2), section_length(12), int tableId = sectionData.readUnsignedByte();
if (tableId != 0x00 /* program_association_section */) {
// See ISO/IEC 13818-1, section 2.4.4.4 for more information on table id assignment.
return;
}
// section_syntax_indicator(1), '0'(1), reserved(2), section_length(12),
// transport_stream_id (16), reserved (2), version_number (5), current_next_indicator (1), // transport_stream_id (16), reserved (2), version_number (5), current_next_indicator (1),
// section_number (8), last_section_number (8) // section_number (8), last_section_number (8)
sectionData.skipBytes(8); sectionData.skipBytes(7);
int programCount = sectionData.bytesLeft() / 4; int programCount = sectionData.bytesLeft() / 4;
for (int i = 0; i < programCount; i++) { for (int i = 0; i < programCount; i++) {
...@@ -331,11 +336,15 @@ public final class TsExtractor implements Extractor { ...@@ -331,11 +336,15 @@ public final class TsExtractor implements Extractor {
@Override @Override
public void consume(ParsableByteArray sectionData) { public void consume(ParsableByteArray sectionData) {
// table_id(8), section_syntax_indicator(1), '0'(1), reserved(2), section_length(12), int tableId = sectionData.readUnsignedByte();
// program_number (16), reserved (2), version_number (5), current_next_indicator (1), if (tableId != 0x02 /* TS_program_map_section */) {
// section_number (8), last_section_number (8), reserved (3), PCR_PID (13) // See ISO/IEC 13818-1, section 2.4.4.4 for more information on table id assignment.
// Skip the rest of the PMT header. return;
sectionData.skipBytes(10); }
// section_syntax_indicator(1), '0'(1), reserved(2), section_length(12), program_number (16),
// reserved (2), version_number (5), current_next_indicator (1), // section_number (8),
// last_section_number (8), reserved (3), PCR_PID (13)
sectionData.skipBytes(9);
// Read program_info_length. // Read program_info_length.
sectionData.readBytes(pmtScratch, 2); sectionData.readBytes(pmtScratch, 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment