mirror of
https://github.com/androidx/media.git
synced 2025-05-05 06:30:24 +08:00
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
This commit is contained in:
parent
79048ffae6
commit
a0c884849e
@ -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 {
|
|||||||
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 {
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 != id3Reader) {
|
||||||
reader.init(timestampAdjuster, output,
|
reader.init(timestampAdjuster, output,
|
||||||
new TrackIdGenerator(programNumber, trackId, MAX_PID_PLUS_ONE));
|
new TrackIdGenerator(programNumber, trackId, MAX_PID_PLUS_ONE));
|
||||||
}
|
}
|
||||||
}
|
tsPayloadReaders.put(trackIdToPidScratch.valueAt(i), reader);
|
||||||
|
|
||||||
if (reader != null) {
|
|
||||||
tsPayloadReaders.put(elementaryPid, reader);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == MODE_HLS) {
|
if (mode == MODE_HLS) {
|
||||||
if (!tracksEnded) {
|
if (!tracksEnded) {
|
||||||
output.endTracks();
|
output.endTracks();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user