Skip tables with unexpected table_id for PAT and PMT readers

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140606435
This commit is contained in:
aquilescanta 2016-11-30 08:17:10 -08:00 committed by Oliver Woodman
parent 289ae3ff38
commit f702568776
2 changed files with 24 additions and 11 deletions

View file

@ -15,6 +15,7 @@
*/
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.TimestampAdjuster;
import com.google.android.exoplayer2.util.ParsableBitArray;
@ -44,16 +45,16 @@ public final class SectionReader implements TsPayloadReader {
public void init(TimestampAdjuster timestampAdjuster, ExtractorOutput extractorOutput,
TrackIdGenerator idGenerator) {
reader.init(timestampAdjuster, extractorOutput, idGenerator);
sectionLength = C.LENGTH_UNSET;
}
@Override
public void seek() {
// Do nothing.
sectionLength = C.LENGTH_UNSET;
}
@Override
public void consume(ParsableByteArray data, boolean payloadUnitStartIndicator) {
// Skip pointer.
if (payloadUnitStartIndicator) {
int pointerField = data.readUnsignedByte();
data.skipBytes(pointerField);
@ -67,6 +68,9 @@ public final class SectionReader implements TsPayloadReader {
sectionBytesRead = 0;
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);
@ -76,8 +80,8 @@ public final class SectionReader implements TsPayloadReader {
// Not yet fully read.
return;
}
if (Util.crc(sectionData.data, 0, sectionLength, 0xFFFFFFFF) != 0) {
sectionLength = C.LENGTH_UNSET;
if (Util.crc(sectionData.data, 0, sectionBytesRead, 0xFFFFFFFF) != 0) {
// CRC Invalid. The section gets discarded.
return;
}

View file

@ -283,10 +283,15 @@ public final class TsExtractor implements Extractor {
@Override
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),
// section_number (8), last_section_number (8)
sectionData.skipBytes(8);
sectionData.skipBytes(7);
int programCount = sectionData.bytesLeft() / 4;
for (int i = 0; i < programCount; i++) {
@ -331,11 +336,15 @@ public final class TsExtractor implements Extractor {
@Override
public void consume(ParsableByteArray sectionData) {
// table_id(8), 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)
// Skip the rest of the PMT header.
sectionData.skipBytes(10);
int tableId = sectionData.readUnsignedByte();
if (tableId != 0x02 /* TS_program_map_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), 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.
sectionData.readBytes(pmtScratch, 2);