Commit 1637575d by aquilescanta Committed by Oliver Woodman

For HLS mode, pick the lowest PID track for each track type

This prevents strange behaviors for streams that changes the track declaration
order in the PMT.

NOTE: This should not change ANY behavior other than the one described above.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158140890
parent a3ee684e
...@@ -382,10 +382,14 @@ public final class TsExtractor implements Extractor { ...@@ -382,10 +382,14 @@ public final class TsExtractor implements Extractor {
private static final int TS_PMT_DESC_DVBSUBS = 0x59; private static final int TS_PMT_DESC_DVBSUBS = 0x59;
private final ParsableBitArray pmtScratch; private final ParsableBitArray pmtScratch;
private final SparseArray<TsPayloadReader> trackIdToReaderScratch;
private final SparseIntArray trackIdToPidScratch;
private final int pid; private final int pid;
public PmtReader(int pid) { public PmtReader(int pid) {
pmtScratch = new ParsableBitArray(new byte[5]); pmtScratch = new ParsableBitArray(new byte[5]);
trackIdToReaderScratch = new SparseArray<>();
trackIdToPidScratch = new SparseIntArray();
this.pid = pid; this.pid = pid;
} }
...@@ -436,6 +440,8 @@ public final class TsExtractor implements Extractor { ...@@ -436,6 +440,8 @@ public final class TsExtractor implements Extractor {
new TrackIdGenerator(programNumber, TS_STREAM_TYPE_ID3, MAX_PID_PLUS_ONE)); new TrackIdGenerator(programNumber, TS_STREAM_TYPE_ID3, MAX_PID_PLUS_ONE));
} }
trackIdToReaderScratch.clear();
trackIdToPidScratch.clear();
int remainingEntriesLength = sectionData.bytesLeft(); int remainingEntriesLength = sectionData.bytesLeft();
while (remainingEntriesLength > 0) { while (remainingEntriesLength > 0) {
sectionData.readBytes(pmtScratch, 5); sectionData.readBytes(pmtScratch, 5);
...@@ -454,23 +460,30 @@ public final class TsExtractor implements Extractor { ...@@ -454,23 +460,30 @@ public final class TsExtractor implements Extractor {
if (trackIds.get(trackId)) { if (trackIds.get(trackId)) {
continue; continue;
} }
trackIds.put(trackId, true);
TsPayloadReader reader; TsPayloadReader reader = mode == MODE_HLS && streamType == TS_STREAM_TYPE_ID3 ? id3Reader
if (mode == MODE_HLS && streamType == TS_STREAM_TYPE_ID3) { : payloadReaderFactory.createPayloadReader(streamType, esInfo);
reader = id3Reader; if (mode != MODE_HLS
} else { || elementaryPid < trackIdToPidScratch.get(trackId, MAX_PID_PLUS_ONE)) {
reader = payloadReaderFactory.createPayloadReader(streamType, esInfo); trackIdToPidScratch.put(trackId, elementaryPid);
if (reader != null) { trackIdToReaderScratch.put(trackId, reader);
reader.init(timestampAdjuster, output,
new TrackIdGenerator(programNumber, trackId, MAX_PID_PLUS_ONE));
}
} }
}
int trackIdCount = trackIdToPidScratch.size();
for (int i = 0; i < trackIdCount; i++) {
int trackId = trackIdToPidScratch.keyAt(i);
trackIds.put(trackId, true);
TsPayloadReader reader = trackIdToReaderScratch.valueAt(i);
if (reader != null) { if (reader != null) {
tsPayloadReaders.put(elementaryPid, reader); if (reader != id3Reader) {
reader.init(timestampAdjuster, output,
new TrackIdGenerator(programNumber, trackId, MAX_PID_PLUS_ONE));
}
tsPayloadReaders.put(trackIdToPidScratch.valueAt(i), reader);
} }
} }
if (mode == MODE_HLS) { if (mode == MODE_HLS) {
if (!tracksEnded) { if (!tracksEnded) {
output.endTracks(); output.endTracks();
......
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