mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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 final LoadControl loadControl;
|
||||||
|
|
||||||
private boolean prepared;
|
private boolean prepared;
|
||||||
|
private boolean notifyReset;
|
||||||
private long lastPreferredQueueSizeEvaluationTimeMs;
|
private long lastPreferredQueueSizeEvaluationTimeMs;
|
||||||
private Format downstreamFormat;
|
private Format downstreamFormat;
|
||||||
|
|
||||||
private TrackGroupArray trackGroups;
|
private TrackGroupArray trackGroups;
|
||||||
private boolean trackEnabled;
|
private boolean trackEnabled;
|
||||||
private boolean pendingReset;
|
|
||||||
|
|
||||||
private long downstreamPositionUs;
|
private long downstreamPositionUs;
|
||||||
private long lastSeekPositionUs;
|
private long lastSeekPositionUs;
|
||||||
|
|
@ -198,7 +198,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
||||||
sampleQueue.needDownstreamFormat();
|
sampleQueue.needDownstreamFormat();
|
||||||
downstreamPositionUs = positionUs;
|
downstreamPositionUs = positionUs;
|
||||||
lastSeekPositionUs = positionUs;
|
lastSeekPositionUs = positionUs;
|
||||||
pendingReset = false;
|
notifyReset = false;
|
||||||
restartFrom(positionUs);
|
restartFrom(positionUs);
|
||||||
}
|
}
|
||||||
return newStreams;
|
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
|
@Override
|
||||||
public long getBufferedPositionUs() {
|
public long getBufferedPositionUs() {
|
||||||
if (loadingFinished) {
|
if (loadingFinished) {
|
||||||
|
|
@ -248,7 +257,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
||||||
restartFrom(positionUs);
|
restartFrom(positionUs);
|
||||||
}
|
}
|
||||||
// Either way, we need to send a discontinuity to the downstream components.
|
// Either way, we need to send a discontinuity to the downstream components.
|
||||||
pendingReset = true;
|
notifyReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -273,18 +282,9 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
||||||
chunkSource.maybeThrowError();
|
chunkSource.maybeThrowError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long readReset() {
|
|
||||||
if (pendingReset) {
|
|
||||||
pendingReset = false;
|
|
||||||
return lastSeekPositionUs;
|
|
||||||
}
|
|
||||||
return C.UNSET_TIME_US;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
|
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
|
||||||
if (pendingReset || isPendingReset()) {
|
if (notifyReset || isPendingReset()) {
|
||||||
return NOTHING_READ;
|
return NOTHING_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -300,19 +300,9 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
||||||
downstreamFormat = currentFormat;
|
downstreamFormat = currentFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = sampleQueue.readData(formatHolder, buffer, loadingFinished);
|
int result = sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
|
||||||
switch (result) {
|
if (result == FORMAT_READ) {
|
||||||
case FORMAT_READ:
|
formatHolder.drmInitData = currentChunk.getDrmInitData();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -375,17 +365,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
|
||||||
|
|
||||||
// Internal methods.
|
// 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) {
|
private void restartFrom(long positionUs) {
|
||||||
pendingResetPositionUs = positionUs;
|
pendingResetPositionUs = positionUs;
|
||||||
loadingFinished = false;
|
loadingFinished = false;
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that {@link #readData(FormatHolder, DecoderInputBuffer, boolean)} should provide
|
* Indicates that {@link #readData(FormatHolder, DecoderInputBuffer, boolean, long)} should
|
||||||
* the sample format before any samples, even if it has already been provided.
|
* provide the sample format before any samples, even if it has already been provided.
|
||||||
*/
|
*/
|
||||||
public void needDownstreamFormat() {
|
public void needDownstreamFormat() {
|
||||||
downstreamFormat = null;
|
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
|
* {@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.
|
* 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 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},
|
* @return The result, which can be {@link TrackStream#NOTHING_READ},
|
||||||
* {@link TrackStream#FORMAT_READ} or {@link TrackStream#BUFFER_READ}.
|
* {@link TrackStream#FORMAT_READ} or {@link TrackStream#BUFFER_READ}.
|
||||||
*/
|
*/
|
||||||
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,
|
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,
|
||||||
boolean loadingFinished) {
|
boolean loadingFinished, long decodeOnlyUntilUs) {
|
||||||
// Write the sample information into the buffer and extrasHolder.
|
switch (infoQueue.readData(formatHolder, buffer, downstreamFormat, extrasHolder)) {
|
||||||
int result = infoQueue.readData(formatHolder, buffer, downstreamFormat, extrasHolder);
|
|
||||||
switch (result) {
|
|
||||||
case TrackStream.NOTHING_READ:
|
case TrackStream.NOTHING_READ:
|
||||||
if (loadingFinished) {
|
if (loadingFinished) {
|
||||||
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
||||||
|
|
@ -236,8 +236,11 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||||
return TrackStream.NOTHING_READ;
|
return TrackStream.NOTHING_READ;
|
||||||
case TrackStream.FORMAT_READ:
|
case TrackStream.FORMAT_READ:
|
||||||
downstreamFormat = formatHolder.format;
|
downstreamFormat = formatHolder.format;
|
||||||
break;
|
return TrackStream.FORMAT_READ;
|
||||||
case TrackStream.BUFFER_READ:
|
case TrackStream.BUFFER_READ:
|
||||||
|
if (buffer.timeUs < decodeOnlyUntilUs) {
|
||||||
|
buffer.setFlags(C.BUFFER_FLAG_DECODE_ONLY);
|
||||||
|
}
|
||||||
// Read encryption data if the sample is encrypted.
|
// Read encryption data if the sample is encrypted.
|
||||||
if (buffer.isEncrypted()) {
|
if (buffer.isEncrypted()) {
|
||||||
readEncryptionData(buffer, extrasHolder);
|
readEncryptionData(buffer, extrasHolder);
|
||||||
|
|
@ -247,9 +250,10 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||||
readData(extrasHolder.offset, buffer.data, buffer.size);
|
readData(extrasHolder.offset, buffer.data, buffer.size);
|
||||||
// Advance the read head.
|
// Advance the read head.
|
||||||
dropDownstreamTo(extrasHolder.nextOffset);
|
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;
|
return TrackStream.NOTHING_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = sampleQueues[track].readData(formatHolder, buffer, loadingFinished);
|
int result = sampleQueues[track].readData(formatHolder, buffer, loadingFinished,
|
||||||
switch (result) {
|
lastSeekPositionUs);
|
||||||
case TrackStream.FORMAT_READ:
|
if (result == TrackStream.FORMAT_READ) {
|
||||||
formatHolder.drmInitData = drmInitData;
|
formatHolder.drmInitData = drmInitData;
|
||||||
break;
|
|
||||||
case TrackStream.BUFFER_READ:
|
|
||||||
if (!buffer.isEndOfStream() && buffer.timeUs < lastSeekPositionUs) {
|
|
||||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -314,12 +314,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
||||||
downstreamFormat = currentFormat;
|
downstreamFormat = currentFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = sampleQueues[group].readData(formatHolder, buffer, loadingFinished);
|
return sampleQueues[group].readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
|
||||||
if (result == TrackStream.BUFFER_READ && !buffer.isEndOfStream()
|
|
||||||
&& buffer.timeUs < lastSeekPositionUs) {
|
|
||||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loader.Callback implementation.
|
// Loader.Callback implementation.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue