mirror of
https://github.com/samsonjs/media.git
synced 2026-03-28 09:55:48 +00:00
Set decode only flag in DefaultTrackOutput.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=120553402
This commit is contained in:
parent
9a893e3003
commit
854acaa1ac
4 changed files with 34 additions and 62 deletions
|
|
@ -61,12 +61,12 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
private final LoadControl loadControl;
|
||||
|
||||
private boolean prepared;
|
||||
private boolean notifyReset;
|
||||
private long lastPreferredQueueSizeEvaluationTimeMs;
|
||||
private Format downstreamFormat;
|
||||
|
||||
private TrackGroupArray trackGroups;
|
||||
private boolean trackEnabled;
|
||||
private boolean pendingReset;
|
||||
|
||||
private long downstreamPositionUs;
|
||||
private long lastSeekPositionUs;
|
||||
|
|
@ -198,7 +198,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
sampleQueue.needDownstreamFormat();
|
||||
downstreamPositionUs = positionUs;
|
||||
lastSeekPositionUs = positionUs;
|
||||
pendingReset = false;
|
||||
notifyReset = false;
|
||||
restartFrom(positionUs);
|
||||
}
|
||||
return newStreams;
|
||||
|
|
@ -213,6 +213,15 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readReset() {
|
||||
if (notifyReset) {
|
||||
notifyReset = false;
|
||||
return lastSeekPositionUs;
|
||||
}
|
||||
return C.UNSET_TIME_US;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBufferedPositionUs() {
|
||||
if (loadingFinished) {
|
||||
|
|
@ -248,7 +257,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
restartFrom(positionUs);
|
||||
}
|
||||
// Either way, we need to send a discontinuity to the downstream components.
|
||||
pendingReset = true;
|
||||
notifyReset = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -273,18 +282,9 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
chunkSource.maybeThrowError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readReset() {
|
||||
if (pendingReset) {
|
||||
pendingReset = false;
|
||||
return lastSeekPositionUs;
|
||||
}
|
||||
return C.UNSET_TIME_US;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
|
||||
if (pendingReset || isPendingReset()) {
|
||||
if (notifyReset || isPendingReset()) {
|
||||
return NOTHING_READ;
|
||||
}
|
||||
|
||||
|
|
@ -300,19 +300,9 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
downstreamFormat = currentFormat;
|
||||
}
|
||||
|
||||
int result = sampleQueue.readData(formatHolder, buffer, loadingFinished);
|
||||
switch (result) {
|
||||
case FORMAT_READ:
|
||||
formatHolder.drmInitData = currentChunk.getDrmInitData();
|
||||
break;
|
||||
case BUFFER_READ:
|
||||
if (!buffer.isEndOfStream()) {
|
||||
if (buffer.timeUs < lastSeekPositionUs) {
|
||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
}
|
||||
onSampleRead(currentChunk, buffer);
|
||||
}
|
||||
break;
|
||||
int result = sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
|
||||
if (result == FORMAT_READ) {
|
||||
formatHolder.drmInitData = currentChunk.getDrmInitData();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -375,17 +365,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
|||
|
||||
// Internal methods.
|
||||
|
||||
/**
|
||||
* Called when a sample has been read. Can be used to perform any modifications necessary before
|
||||
* the sample is returned.
|
||||
*
|
||||
* @param mediaChunk The chunk from which the sample was obtained.
|
||||
* @param buffer Holds the read sample.
|
||||
*/
|
||||
protected void onSampleRead(MediaChunk mediaChunk, DecoderInputBuffer buffer) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
private void restartFrom(long positionUs) {
|
||||
pendingResetPositionUs = positionUs;
|
||||
loadingFinished = false;
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||
}
|
||||
|
||||
/**
|
||||
* Indicates that {@link #readData(FormatHolder, DecoderInputBuffer, boolean)} should provide
|
||||
* the sample format before any samples, even if it has already been provided.
|
||||
* Indicates that {@link #readData(FormatHolder, DecoderInputBuffer, boolean, long)} should
|
||||
* provide the sample format before any samples, even if it has already been provided.
|
||||
*/
|
||||
public void needDownstreamFormat() {
|
||||
downstreamFormat = null;
|
||||
|
|
@ -220,14 +220,14 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||
* {@link DecoderInputBuffer#data} references a valid buffer. If the end of the stream has
|
||||
* been reached, the {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer.
|
||||
* @param loadingFinished True if an empty queue should be considered the end of the stream.
|
||||
* @param decodeOnlyUntilUs If a buffer is read, the {@link C#BUFFER_FLAG_DECODE_ONLY} flag will
|
||||
* be set if the buffer's timestamp is less than this value.
|
||||
* @return The result, which can be {@link TrackStream#NOTHING_READ},
|
||||
* {@link TrackStream#FORMAT_READ} or {@link TrackStream#BUFFER_READ}.
|
||||
*/
|
||||
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,
|
||||
boolean loadingFinished) {
|
||||
// Write the sample information into the buffer and extrasHolder.
|
||||
int result = infoQueue.readData(formatHolder, buffer, downstreamFormat, extrasHolder);
|
||||
switch (result) {
|
||||
boolean loadingFinished, long decodeOnlyUntilUs) {
|
||||
switch (infoQueue.readData(formatHolder, buffer, downstreamFormat, extrasHolder)) {
|
||||
case TrackStream.NOTHING_READ:
|
||||
if (loadingFinished) {
|
||||
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
||||
|
|
@ -236,8 +236,11 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||
return TrackStream.NOTHING_READ;
|
||||
case TrackStream.FORMAT_READ:
|
||||
downstreamFormat = formatHolder.format;
|
||||
break;
|
||||
return TrackStream.FORMAT_READ;
|
||||
case TrackStream.BUFFER_READ:
|
||||
if (buffer.timeUs < decodeOnlyUntilUs) {
|
||||
buffer.setFlags(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
}
|
||||
// Read encryption data if the sample is encrypted.
|
||||
if (buffer.isEncrypted()) {
|
||||
readEncryptionData(buffer, extrasHolder);
|
||||
|
|
@ -247,9 +250,10 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||
readData(extrasHolder.offset, buffer.data, buffer.size);
|
||||
// Advance the read head.
|
||||
dropDownstreamTo(extrasHolder.nextOffset);
|
||||
break;
|
||||
return TrackStream.BUFFER_READ;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -463,16 +463,10 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
return TrackStream.NOTHING_READ;
|
||||
}
|
||||
|
||||
int result = sampleQueues[track].readData(formatHolder, buffer, loadingFinished);
|
||||
switch (result) {
|
||||
case TrackStream.FORMAT_READ:
|
||||
formatHolder.drmInitData = drmInitData;
|
||||
break;
|
||||
case TrackStream.BUFFER_READ:
|
||||
if (!buffer.isEndOfStream() && buffer.timeUs < lastSeekPositionUs) {
|
||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
}
|
||||
break;
|
||||
int result = sampleQueues[track].readData(formatHolder, buffer, loadingFinished,
|
||||
lastSeekPositionUs);
|
||||
if (result == TrackStream.FORMAT_READ) {
|
||||
formatHolder.drmInitData = drmInitData;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,12 +314,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
downstreamFormat = currentFormat;
|
||||
}
|
||||
|
||||
int result = sampleQueues[group].readData(formatHolder, buffer, loadingFinished);
|
||||
if (result == TrackStream.BUFFER_READ && !buffer.isEndOfStream()
|
||||
&& buffer.timeUs < lastSeekPositionUs) {
|
||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
}
|
||||
return result;
|
||||
return sampleQueues[group].readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
|
||||
}
|
||||
|
||||
// Loader.Callback implementation.
|
||||
|
|
|
|||
Loading…
Reference in a new issue