Commit 152d1c7d by kimvde Committed by Christos Tsilopoulos

TsExtractor: handle packets without PTS

Issue: #9294
PiperOrigin-RevId: 392844983
parent 66d1e2cc
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
* Core Library: * Core Library:
* Fix track selection in `StyledPlayerControlView` when using * Fix track selection in `StyledPlayerControlView` when using
`ForwardingPlayer`. `ForwardingPlayer`.
* Extractors:
* Support TS packets without PTS flag
([#9294](https://github.com/google/ExoPlayer/issues/9294)).
* Video * Video
* Request smaller decoder input buffers for Dolby Vision. This fixes an * Request smaller decoder input buffers for Dolby Vision. This fixes an
issue that could cause UHD Dolby Vision playbacks to fail on some issue that could cause UHD Dolby Vision playbacks to fail on some
......
...@@ -102,12 +102,14 @@ public final class CeaUtil { ...@@ -102,12 +102,14 @@ public final class CeaUtil {
for (TrackOutput output : outputs) { for (TrackOutput output : outputs) {
ccDataBuffer.setPosition(sampleStartPosition); ccDataBuffer.setPosition(sampleStartPosition);
output.sampleData(ccDataBuffer, sampleLength); output.sampleData(ccDataBuffer, sampleLength);
output.sampleMetadata( if (presentationTimeUs != C.TIME_UNSET) {
presentationTimeUs, output.sampleMetadata(
C.BUFFER_FLAG_KEY_FRAME, presentationTimeUs,
sampleLength, C.BUFFER_FLAG_KEY_FRAME,
/* offset= */ 0, sampleLength,
/* encryptionData= */ null); /* offset= */ 0,
/* cryptoData= */ null);
}
} }
} }
......
...@@ -85,6 +85,7 @@ public final class Ac3Reader implements ElementaryStreamReader { ...@@ -85,6 +85,7 @@ public final class Ac3Reader implements ElementaryStreamReader {
headerScratchBits = new ParsableBitArray(new byte[HEADER_SIZE]); headerScratchBits = new ParsableBitArray(new byte[HEADER_SIZE]);
headerScratchBytes = new ParsableByteArray(headerScratchBits.data); headerScratchBytes = new ParsableByteArray(headerScratchBits.data);
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
timeUs = C.TIME_UNSET;
this.language = language; this.language = language;
} }
...@@ -93,6 +94,7 @@ public final class Ac3Reader implements ElementaryStreamReader { ...@@ -93,6 +94,7 @@ public final class Ac3Reader implements ElementaryStreamReader {
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
bytesRead = 0; bytesRead = 0;
lastByteWas0B = false; lastByteWas0B = false;
timeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -104,7 +106,9 @@ public final class Ac3Reader implements ElementaryStreamReader { ...@@ -104,7 +106,9 @@ public final class Ac3Reader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
timeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -133,8 +137,10 @@ public final class Ac3Reader implements ElementaryStreamReader { ...@@ -133,8 +137,10 @@ public final class Ac3Reader implements ElementaryStreamReader {
output.sampleData(data, bytesToRead); output.sampleData(data, bytesToRead);
bytesRead += bytesToRead; bytesRead += bytesToRead;
if (bytesRead == sampleSize) { if (bytesRead == sampleSize) {
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null); if (timeUs != C.TIME_UNSET) {
timeUs += sampleDurationUs; output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
timeUs += sampleDurationUs;
}
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
} }
break; break;
......
...@@ -87,6 +87,7 @@ public final class Ac4Reader implements ElementaryStreamReader { ...@@ -87,6 +87,7 @@ public final class Ac4Reader implements ElementaryStreamReader {
bytesRead = 0; bytesRead = 0;
lastByteWasAC = false; lastByteWasAC = false;
hasCRC = false; hasCRC = false;
timeUs = C.TIME_UNSET;
this.language = language; this.language = language;
} }
...@@ -96,6 +97,7 @@ public final class Ac4Reader implements ElementaryStreamReader { ...@@ -96,6 +97,7 @@ public final class Ac4Reader implements ElementaryStreamReader {
bytesRead = 0; bytesRead = 0;
lastByteWasAC = false; lastByteWasAC = false;
hasCRC = false; hasCRC = false;
timeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -107,7 +109,9 @@ public final class Ac4Reader implements ElementaryStreamReader { ...@@ -107,7 +109,9 @@ public final class Ac4Reader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
timeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -136,8 +140,10 @@ public final class Ac4Reader implements ElementaryStreamReader { ...@@ -136,8 +140,10 @@ public final class Ac4Reader implements ElementaryStreamReader {
output.sampleData(data, bytesToRead); output.sampleData(data, bytesToRead);
bytesRead += bytesToRead; bytesRead += bytesToRead;
if (bytesRead == sampleSize) { if (bytesRead == sampleSize) {
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null); if (timeUs != C.TIME_UNSET) {
timeUs += sampleDurationUs; output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
timeUs += sampleDurationUs;
}
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
} }
break; break;
......
...@@ -114,6 +114,7 @@ public final class AdtsReader implements ElementaryStreamReader { ...@@ -114,6 +114,7 @@ public final class AdtsReader implements ElementaryStreamReader {
firstFrameVersion = VERSION_UNSET; firstFrameVersion = VERSION_UNSET;
firstFrameSampleRateIndex = C.INDEX_UNSET; firstFrameSampleRateIndex = C.INDEX_UNSET;
sampleDurationUs = C.TIME_UNSET; sampleDurationUs = C.TIME_UNSET;
timeUs = C.TIME_UNSET;
this.exposeId3 = exposeId3; this.exposeId3 = exposeId3;
this.language = language; this.language = language;
} }
...@@ -125,6 +126,7 @@ public final class AdtsReader implements ElementaryStreamReader { ...@@ -125,6 +126,7 @@ public final class AdtsReader implements ElementaryStreamReader {
@Override @Override
public void seek() { public void seek() {
timeUs = C.TIME_UNSET;
resetSync(); resetSync();
} }
...@@ -149,7 +151,9 @@ public final class AdtsReader implements ElementaryStreamReader { ...@@ -149,7 +151,9 @@ public final class AdtsReader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
timeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -529,8 +533,10 @@ public final class AdtsReader implements ElementaryStreamReader { ...@@ -529,8 +533,10 @@ public final class AdtsReader implements ElementaryStreamReader {
currentOutput.sampleData(data, bytesToRead); currentOutput.sampleData(data, bytesToRead);
bytesRead += bytesToRead; bytesRead += bytesToRead;
if (bytesRead == sampleSize) { if (bytesRead == sampleSize) {
currentOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null); if (timeUs != C.TIME_UNSET) {
timeUs += currentSampleDuration; currentOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
timeUs += currentSampleDuration;
}
setFindingSampleState(); setFindingSampleState();
} }
} }
......
...@@ -66,6 +66,7 @@ public final class DtsReader implements ElementaryStreamReader { ...@@ -66,6 +66,7 @@ public final class DtsReader implements ElementaryStreamReader {
public DtsReader(@Nullable String language) { public DtsReader(@Nullable String language) {
headerScratchBytes = new ParsableByteArray(new byte[HEADER_SIZE]); headerScratchBytes = new ParsableByteArray(new byte[HEADER_SIZE]);
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
timeUs = C.TIME_UNSET;
this.language = language; this.language = language;
} }
...@@ -74,6 +75,7 @@ public final class DtsReader implements ElementaryStreamReader { ...@@ -74,6 +75,7 @@ public final class DtsReader implements ElementaryStreamReader {
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
bytesRead = 0; bytesRead = 0;
syncBytes = 0; syncBytes = 0;
timeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -85,7 +87,9 @@ public final class DtsReader implements ElementaryStreamReader { ...@@ -85,7 +87,9 @@ public final class DtsReader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
timeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -111,8 +115,10 @@ public final class DtsReader implements ElementaryStreamReader { ...@@ -111,8 +115,10 @@ public final class DtsReader implements ElementaryStreamReader {
output.sampleData(data, bytesToRead); output.sampleData(data, bytesToRead);
bytesRead += bytesToRead; bytesRead += bytesToRead;
if (bytesRead == sampleSize) { if (bytesRead == sampleSize) {
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null); if (timeUs != C.TIME_UNSET) {
timeUs += sampleDurationUs; output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
timeUs += sampleDurationUs;
}
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
} }
break; break;
......
...@@ -43,11 +43,13 @@ public final class DvbSubtitleReader implements ElementaryStreamReader { ...@@ -43,11 +43,13 @@ public final class DvbSubtitleReader implements ElementaryStreamReader {
public DvbSubtitleReader(List<DvbSubtitleInfo> subtitleInfos) { public DvbSubtitleReader(List<DvbSubtitleInfo> subtitleInfos) {
this.subtitleInfos = subtitleInfos; this.subtitleInfos = subtitleInfos;
outputs = new TrackOutput[subtitleInfos.size()]; outputs = new TrackOutput[subtitleInfos.size()];
sampleTimeUs = C.TIME_UNSET;
} }
@Override @Override
public void seek() { public void seek() {
writingSample = false; writingSample = false;
sampleTimeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -73,7 +75,9 @@ public final class DvbSubtitleReader implements ElementaryStreamReader { ...@@ -73,7 +75,9 @@ public final class DvbSubtitleReader implements ElementaryStreamReader {
return; return;
} }
writingSample = true; writingSample = true;
sampleTimeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
sampleTimeUs = pesTimeUs;
}
sampleBytesWritten = 0; sampleBytesWritten = 0;
bytesToCheck = 2; bytesToCheck = 2;
} }
...@@ -81,8 +85,10 @@ public final class DvbSubtitleReader implements ElementaryStreamReader { ...@@ -81,8 +85,10 @@ public final class DvbSubtitleReader implements ElementaryStreamReader {
@Override @Override
public void packetFinished() { public void packetFinished() {
if (writingSample) { if (writingSample) {
for (TrackOutput output : outputs) { if (sampleTimeUs != C.TIME_UNSET) {
output.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleBytesWritten, 0, null); for (TrackOutput output : outputs) {
output.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleBytesWritten, 0, null);
}
} }
writingSample = false; writingSample = false;
} }
......
...@@ -87,6 +87,8 @@ public final class H262Reader implements ElementaryStreamReader { ...@@ -87,6 +87,8 @@ public final class H262Reader implements ElementaryStreamReader {
userData = null; userData = null;
userDataParsable = null; userDataParsable = null;
} }
pesTimeUs = C.TIME_UNSET;
sampleTimeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -98,6 +100,8 @@ public final class H262Reader implements ElementaryStreamReader { ...@@ -98,6 +100,8 @@ public final class H262Reader implements ElementaryStreamReader {
} }
totalBytesWritten = 0; totalBytesWritten = 0;
startedFirstSample = false; startedFirstSample = false;
pesTimeUs = C.TIME_UNSET;
sampleTimeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -182,7 +186,7 @@ public final class H262Reader implements ElementaryStreamReader { ...@@ -182,7 +186,7 @@ public final class H262Reader implements ElementaryStreamReader {
} }
if (startCodeValue == START_PICTURE || startCodeValue == START_SEQUENCE_HEADER) { if (startCodeValue == START_PICTURE || startCodeValue == START_SEQUENCE_HEADER) {
int bytesWrittenPastStartCode = limit - startCodeOffset; int bytesWrittenPastStartCode = limit - startCodeOffset;
if (startedFirstSample && sampleHasPicture && hasOutputFormat) { if (sampleHasPicture && hasOutputFormat && sampleTimeUs != C.TIME_UNSET) {
// Output the sample. // Output the sample.
@C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0; @C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
int size = (int) (totalBytesWritten - samplePosition) - bytesWrittenPastStartCode; int size = (int) (totalBytesWritten - samplePosition) - bytesWrittenPastStartCode;
...@@ -194,7 +198,9 @@ public final class H262Reader implements ElementaryStreamReader { ...@@ -194,7 +198,9 @@ public final class H262Reader implements ElementaryStreamReader {
sampleTimeUs = sampleTimeUs =
pesTimeUs != C.TIME_UNSET pesTimeUs != C.TIME_UNSET
? pesTimeUs ? pesTimeUs
: (startedFirstSample ? (sampleTimeUs + frameDurationUs) : 0); : (sampleTimeUs != C.TIME_UNSET
? (sampleTimeUs + frameDurationUs)
: C.TIME_UNSET);
sampleIsKeyframe = false; sampleIsKeyframe = false;
pesTimeUs = C.TIME_UNSET; pesTimeUs = C.TIME_UNSET;
startedFirstSample = true; startedFirstSample = true;
......
...@@ -87,6 +87,7 @@ public final class H263Reader implements ElementaryStreamReader { ...@@ -87,6 +87,7 @@ public final class H263Reader implements ElementaryStreamReader {
this.userDataReader = userDataReader; this.userDataReader = userDataReader;
prefixFlags = new boolean[4]; prefixFlags = new boolean[4];
csdBuffer = new CsdBuffer(128); csdBuffer = new CsdBuffer(128);
pesTimeUs = C.TIME_UNSET;
if (userDataReader != null) { if (userDataReader != null) {
userData = new NalUnitTargetBuffer(START_CODE_VALUE_USER_DATA, 128); userData = new NalUnitTargetBuffer(START_CODE_VALUE_USER_DATA, 128);
userDataParsable = new ParsableByteArray(); userDataParsable = new ParsableByteArray();
...@@ -107,6 +108,7 @@ public final class H263Reader implements ElementaryStreamReader { ...@@ -107,6 +108,7 @@ public final class H263Reader implements ElementaryStreamReader {
userData.reset(); userData.reset();
} }
totalBytesWritten = 0; totalBytesWritten = 0;
pesTimeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -123,7 +125,9 @@ public final class H263Reader implements ElementaryStreamReader { ...@@ -123,7 +125,9 @@ public final class H263Reader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
// TODO (Internal b/32267012): Consider using random access indicator. // TODO (Internal b/32267012): Consider using random access indicator.
this.pesTimeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
this.pesTimeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -462,7 +466,10 @@ public final class H263Reader implements ElementaryStreamReader { ...@@ -462,7 +466,10 @@ public final class H263Reader implements ElementaryStreamReader {
} }
public void onDataEnd(long position, int bytesWrittenPastPosition, boolean hasOutputFormat) { public void onDataEnd(long position, int bytesWrittenPastPosition, boolean hasOutputFormat) {
if (startCodeValue == START_CODE_VALUE_VOP && hasOutputFormat && readingSample) { if (startCodeValue == START_CODE_VALUE_VOP
&& hasOutputFormat
&& readingSample
&& sampleTimeUs != C.TIME_UNSET) {
int size = (int) (position - samplePosition); int size = (int) (position - samplePosition);
@C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0; @C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
output.sampleMetadata( output.sampleMetadata(
......
...@@ -86,6 +86,7 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -86,6 +86,7 @@ public final class H264Reader implements ElementaryStreamReader {
sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128); sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128);
pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128); pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128);
sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128); sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128);
pesTimeUs = C.TIME_UNSET;
seiWrapper = new ParsableByteArray(); seiWrapper = new ParsableByteArray();
} }
...@@ -93,6 +94,7 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -93,6 +94,7 @@ public final class H264Reader implements ElementaryStreamReader {
public void seek() { public void seek() {
totalBytesWritten = 0; totalBytesWritten = 0;
randomAccessIndicator = false; randomAccessIndicator = false;
pesTimeUs = C.TIME_UNSET;
NalUnitUtil.clearPrefixFlags(prefixFlags); NalUnitUtil.clearPrefixFlags(prefixFlags);
sps.reset(); sps.reset();
pps.reset(); pps.reset();
...@@ -113,7 +115,9 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -113,7 +115,9 @@ public final class H264Reader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
this.pesTimeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
this.pesTimeUs = pesTimeUs;
}
randomAccessIndicator |= (flags & FLAG_RANDOM_ACCESS_INDICATOR) != 0; randomAccessIndicator |= (flags & FLAG_RANDOM_ACCESS_INDICATOR) != 0;
} }
...@@ -495,6 +499,9 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -495,6 +499,9 @@ public final class H264Reader implements ElementaryStreamReader {
} }
private void outputSample(int offset) { private void outputSample(int offset) {
if (sampleTimeUs == C.TIME_UNSET) {
return;
}
@C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0; @C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
int size = (int) (nalUnitStartPosition - samplePosition); int size = (int) (nalUnitStartPosition - samplePosition);
output.sampleMetadata(sampleTimeUs, flags, size, offset, null); output.sampleMetadata(sampleTimeUs, flags, size, offset, null);
......
...@@ -85,12 +85,14 @@ public final class H265Reader implements ElementaryStreamReader { ...@@ -85,12 +85,14 @@ public final class H265Reader implements ElementaryStreamReader {
pps = new NalUnitTargetBuffer(PPS_NUT, 128); pps = new NalUnitTargetBuffer(PPS_NUT, 128);
prefixSei = new NalUnitTargetBuffer(PREFIX_SEI_NUT, 128); prefixSei = new NalUnitTargetBuffer(PREFIX_SEI_NUT, 128);
suffixSei = new NalUnitTargetBuffer(SUFFIX_SEI_NUT, 128); suffixSei = new NalUnitTargetBuffer(SUFFIX_SEI_NUT, 128);
pesTimeUs = C.TIME_UNSET;
seiWrapper = new ParsableByteArray(); seiWrapper = new ParsableByteArray();
} }
@Override @Override
public void seek() { public void seek() {
totalBytesWritten = 0; totalBytesWritten = 0;
pesTimeUs = C.TIME_UNSET;
NalUnitUtil.clearPrefixFlags(prefixFlags); NalUnitUtil.clearPrefixFlags(prefixFlags);
vps.reset(); vps.reset();
sps.reset(); sps.reset();
...@@ -114,7 +116,9 @@ public final class H265Reader implements ElementaryStreamReader { ...@@ -114,7 +116,9 @@ public final class H265Reader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
// TODO (Internal b/32267012): Consider using random access indicator. // TODO (Internal b/32267012): Consider using random access indicator.
this.pesTimeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
this.pesTimeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -536,6 +540,9 @@ public final class H265Reader implements ElementaryStreamReader { ...@@ -536,6 +540,9 @@ public final class H265Reader implements ElementaryStreamReader {
} }
private void outputSample(int offset) { private void outputSample(int offset) {
if (sampleTimeUs == C.TIME_UNSET) {
return;
}
@C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0; @C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
int size = (int) (nalUnitPosition - samplePosition); int size = (int) (nalUnitPosition - samplePosition);
output.sampleMetadata(sampleTimeUs, flags, size, offset, null); output.sampleMetadata(sampleTimeUs, flags, size, offset, null);
......
...@@ -49,11 +49,13 @@ public final class Id3Reader implements ElementaryStreamReader { ...@@ -49,11 +49,13 @@ public final class Id3Reader implements ElementaryStreamReader {
public Id3Reader() { public Id3Reader() {
id3Header = new ParsableByteArray(ID3_HEADER_LENGTH); id3Header = new ParsableByteArray(ID3_HEADER_LENGTH);
sampleTimeUs = C.TIME_UNSET;
} }
@Override @Override
public void seek() { public void seek() {
writingSample = false; writingSample = false;
sampleTimeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -73,7 +75,9 @@ public final class Id3Reader implements ElementaryStreamReader { ...@@ -73,7 +75,9 @@ public final class Id3Reader implements ElementaryStreamReader {
return; return;
} }
writingSample = true; writingSample = true;
sampleTimeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
sampleTimeUs = pesTimeUs;
}
sampleSize = 0; sampleSize = 0;
sampleBytesRead = 0; sampleBytesRead = 0;
} }
...@@ -120,7 +124,9 @@ public final class Id3Reader implements ElementaryStreamReader { ...@@ -120,7 +124,9 @@ public final class Id3Reader implements ElementaryStreamReader {
if (!writingSample || sampleSize == 0 || sampleBytesRead != sampleSize) { if (!writingSample || sampleSize == 0 || sampleBytesRead != sampleSize) {
return; return;
} }
output.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null); if (sampleTimeUs != C.TIME_UNSET) {
output.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
}
writingSample = false; writingSample = false;
} }
} }
...@@ -78,11 +78,13 @@ public final class LatmReader implements ElementaryStreamReader { ...@@ -78,11 +78,13 @@ public final class LatmReader implements ElementaryStreamReader {
this.language = language; this.language = language;
sampleDataBuffer = new ParsableByteArray(INITIAL_BUFFER_SIZE); sampleDataBuffer = new ParsableByteArray(INITIAL_BUFFER_SIZE);
sampleBitArray = new ParsableBitArray(sampleDataBuffer.getData()); sampleBitArray = new ParsableBitArray(sampleDataBuffer.getData());
timeUs = C.TIME_UNSET;
} }
@Override @Override
public void seek() { public void seek() {
state = STATE_FINDING_SYNC_1; state = STATE_FINDING_SYNC_1;
timeUs = C.TIME_UNSET;
streamMuxRead = false; streamMuxRead = false;
} }
...@@ -95,7 +97,9 @@ public final class LatmReader implements ElementaryStreamReader { ...@@ -95,7 +97,9 @@ public final class LatmReader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
timeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -306,8 +310,10 @@ public final class LatmReader implements ElementaryStreamReader { ...@@ -306,8 +310,10 @@ public final class LatmReader implements ElementaryStreamReader {
sampleDataBuffer.setPosition(0); sampleDataBuffer.setPosition(0);
} }
output.sampleData(sampleDataBuffer, muxLengthBytes); output.sampleData(sampleDataBuffer, muxLengthBytes);
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, muxLengthBytes, 0, null); if (timeUs != C.TIME_UNSET) {
timeUs += sampleDurationUs; output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, muxLengthBytes, 0, null);
timeUs += sampleDurationUs;
}
} }
private void resetBufferForSize(int newSize) { private void resetBufferForSize(int newSize) {
......
...@@ -69,6 +69,7 @@ public final class MpegAudioReader implements ElementaryStreamReader { ...@@ -69,6 +69,7 @@ public final class MpegAudioReader implements ElementaryStreamReader {
headerScratch = new ParsableByteArray(4); headerScratch = new ParsableByteArray(4);
headerScratch.getData()[0] = (byte) 0xFF; headerScratch.getData()[0] = (byte) 0xFF;
header = new MpegAudioUtil.Header(); header = new MpegAudioUtil.Header();
timeUs = C.TIME_UNSET;
this.language = language; this.language = language;
} }
...@@ -77,6 +78,7 @@ public final class MpegAudioReader implements ElementaryStreamReader { ...@@ -77,6 +78,7 @@ public final class MpegAudioReader implements ElementaryStreamReader {
state = STATE_FINDING_HEADER; state = STATE_FINDING_HEADER;
frameBytesRead = 0; frameBytesRead = 0;
lastByteWasFF = false; lastByteWasFF = false;
timeUs = C.TIME_UNSET;
} }
@Override @Override
...@@ -88,7 +90,9 @@ public final class MpegAudioReader implements ElementaryStreamReader { ...@@ -88,7 +90,9 @@ public final class MpegAudioReader implements ElementaryStreamReader {
@Override @Override
public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) { public void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags) {
timeUs = pesTimeUs; if (pesTimeUs != C.TIME_UNSET) {
timeUs = pesTimeUs;
}
} }
@Override @Override
...@@ -227,8 +231,10 @@ public final class MpegAudioReader implements ElementaryStreamReader { ...@@ -227,8 +231,10 @@ public final class MpegAudioReader implements ElementaryStreamReader {
return; return;
} }
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, frameSize, 0, null); if (timeUs != C.TIME_UNSET) {
timeUs += frameDurationUs; output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, frameSize, 0, null);
timeUs += frameDurationUs;
}
frameBytesRead = 0; frameBytesRead = 0;
state = STATE_FINDING_HEADER; state = STATE_FINDING_HEADER;
} }
......
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