Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public final class DtsReader implements ElementaryStreamReader {
// Used when reading the samples.
private boolean coreFormatPendingEmit;
private long timeUs;
private long pendingTimeUs;
private boolean hasCore;
private boolean skipExtssUntilCore;

Expand All @@ -114,6 +115,7 @@ public DtsReader(
headerScratchBytes = new ParsableByteArray(new byte[maxHeaderSize]);
state = STATE_FINDING_SYNC;
timeUs = C.TIME_UNSET;
pendingTimeUs = C.TIME_UNSET;
uhdAudioChunkId = new AtomicInteger();
extensionSubstreamHeaderSize = C.LENGTH_UNSET;
uhdHeaderSize = C.LENGTH_UNSET;
Expand All @@ -130,6 +132,7 @@ public void seek() {
extSyncBytes = 0;
coreSampleSize = 0;
timeUs = C.TIME_UNSET;
pendingTimeUs = C.TIME_UNSET;
uhdAudioChunkId.set(0);
coreFormatPendingEmit = false;
skipExtssUntilCore = hasCore;
Expand All @@ -144,7 +147,14 @@ public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGen

@Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs;
if (pesTimeUs != C.TIME_UNSET) {
if (state != STATE_FINDING_SYNC) {
pendingTimeUs = pesTimeUs;
} else {
timeUs = pesTimeUs;
pendingTimeUs = C.TIME_UNSET;
}
}
}

@Override
Expand Down Expand Up @@ -233,13 +243,20 @@ public void consume(ParsableByteArray data) throws ParserException {
int combinedSize =
sampleSize
+ (frameType == DtsUtil.FRAME_TYPE_EXTENSION_SUBSTREAM ? coreSampleSize : 0);
long emittedTimeUs = timeUs;
output.sampleMetadata(
timeUs,
frameType == DtsUtil.FRAME_TYPE_UHD_NON_SYNC ? 0 : C.BUFFER_FLAG_KEY_FRAME,
combinedSize,
0,
null);
timeUs += sampleDurationUs;
if (pendingTimeUs != C.TIME_UNSET) {
if (pendingTimeUs != emittedTimeUs) {
timeUs = pendingTimeUs;
}
pendingTimeUs = C.TIME_UNSET;
}
coreSampleSize = 0;
state = STATE_FINDING_SYNC;
}
Expand All @@ -263,8 +280,15 @@ public void consume(ParsableByteArray data) throws ParserException {
coreFormatPendingEmit = false;
}
checkState(timeUs != C.TIME_UNSET);
long emittedTimeUs = timeUs;
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, coreSampleSize, 0, null);
timeUs += sampleDurationUs;
if (pendingTimeUs != C.TIME_UNSET) {
if (pendingTimeUs != emittedTimeUs) {
timeUs = pendingTimeUs;
}
pendingTimeUs = C.TIME_UNSET;
}
coreSampleSize = 0;

syncBytes = extSyncBytes;
Expand Down Expand Up @@ -293,7 +317,7 @@ public void consume(ParsableByteArray data) throws ParserException {
}

@Override
public void packetFinished() {
public void endOfInputReached() {
if (state == STATE_CHECKING_FOR_EXTSS_AFTER_CORE) {
checkNotNull(output);
if (coreFormatPendingEmit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ public void sampleWithDtsHdMa() throws Exception {
simulationConfig);
}

@Test
public void sampleWithDtsHdAcrossPesBoundary() throws Exception {
ExtractorAsserts.assertBehavior(
getExtractorFactory(
subtitlesParsedDuringExtraction,
MODE_SINGLE_PMT,
new TimestampAdjuster(0),
new DefaultTsPayloadReaderFactory(FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS)),
"media/ts/sample_dts_hd_across_pes.ts",
simulationConfig);
}

@Test
public void sampleWithDtsUhd() throws Exception {
ExtractorAsserts.assertBehavior(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
seekMap:
isSeekable = false
duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1
track 256:
total output bytes = 2128
sample count = 1
format 0:
averageBitrate = 1536000
id = 1/256
containerMimeType = video/mp2t
sampleMimeType = audio/vnd.dts.hd;profile=lbr
channelCount = 8
sampleRate = 48000
language = en
sample 0:
time = 0
flags = 1
data = length 2128, hash E93B32EA
tracksEnded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
seekMap:
isSeekable = false
duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1
track 256:
total output bytes = 2128
sample count = 1
format 0:
averageBitrate = 1536000
id = 1/256
containerMimeType = video/mp2t
sampleMimeType = audio/vnd.dts.hd;profile=lbr
channelCount = 8
sampleRate = 48000
language = en
sample 0:
time = 0
flags = 1
data = length 2128, hash E93B32EA
tracksEnded = true
Binary file not shown.