Skip to content

Commit 4c17803

Browse files
committed
Support DTS-HD with packets across PES boundary
In DTS-HD streams, it can happen that core packet is in one PES and the extension substream is in another PES. Ensure we can read ahead into next PES in this case. We need to use the old timestamp as extss and core always belong together.
1 parent b168816 commit 4c17803

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • libraries/extractor/src/main/java/androidx/media3/extractor/ts

libraries/extractor/src/main/java/androidx/media3/extractor/ts/DtsReader.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public final class DtsReader implements ElementaryStreamReader {
9595
// Used when reading the samples.
9696
private boolean coreFormatPendingEmit;
9797
private long timeUs;
98+
private long pendingTimeUs;
9899
private boolean hasCore;
99100
private boolean skipExtssUntilCore;
100101

@@ -114,6 +115,7 @@ public DtsReader(
114115
headerScratchBytes = new ParsableByteArray(new byte[maxHeaderSize]);
115116
state = STATE_FINDING_SYNC;
116117
timeUs = C.TIME_UNSET;
118+
pendingTimeUs = C.TIME_UNSET;
117119
uhdAudioChunkId = new AtomicInteger();
118120
extensionSubstreamHeaderSize = C.LENGTH_UNSET;
119121
uhdHeaderSize = C.LENGTH_UNSET;
@@ -144,7 +146,13 @@ public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGen
144146

145147
@Override
146148
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
147-
timeUs = pesTimeUs;
149+
if (pesTimeUs != C.TIME_UNSET) {
150+
if (state == STATE_CHECKING_FOR_EXTSS_AFTER_CORE) {
151+
pendingTimeUs = pesTimeUs;
152+
} else {
153+
timeUs = pesTimeUs;
154+
}
155+
}
148156
}
149157

150158
@Override
@@ -265,6 +273,10 @@ public void consume(ParsableByteArray data) throws ParserException {
265273
checkState(timeUs != C.TIME_UNSET);
266274
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, coreSampleSize, 0, null);
267275
timeUs += sampleDurationUs;
276+
if (pendingTimeUs != C.TIME_UNSET) {
277+
timeUs = pendingTimeUs;
278+
pendingTimeUs = C.TIME_UNSET;
279+
}
268280
coreSampleSize = 0;
269281

270282
syncBytes = extSyncBytes;
@@ -293,7 +305,7 @@ public void consume(ParsableByteArray data) throws ParserException {
293305
}
294306

295307
@Override
296-
public void packetFinished(boolean isEndOfInput) {
308+
public void endOfInputReached() {
297309
if (state == STATE_CHECKING_FOR_EXTSS_AFTER_CORE) {
298310
checkNotNull(output);
299311
if (coreFormatPendingEmit) {

0 commit comments

Comments
 (0)