mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make flags-only DecoderInputBuffer hold all flags
Currently a flags-only DecoderInputBuffer may hold only the end-of-stream flag. This change makes flags-only buffer read any kind of flag set in the next sample. If no sample is available RESULT_NOTHING_READ is returned. PiperOrigin-RevId: 237027581
This commit is contained in:
parent
a4754bb741
commit
155a129d2c
5 changed files with 58 additions and 40 deletions
|
|
@ -723,8 +723,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
if (result == C.RESULT_FORMAT_READ) {
|
if (result == C.RESULT_FORMAT_READ) {
|
||||||
onInputFormatChanged(formatHolder.format);
|
onInputFormatChanged(formatHolder.format);
|
||||||
return true;
|
return true;
|
||||||
} else if (result == C.RESULT_BUFFER_READ) {
|
} else if (result == C.RESULT_BUFFER_READ && flagsOnlyBuffer.isEndOfStream()) {
|
||||||
Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
|
|
||||||
inputStreamEnded = true;
|
inputStreamEnded = true;
|
||||||
processEndOfStream();
|
processEndOfStream();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -219,25 +219,31 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
*
|
*
|
||||||
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
||||||
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
||||||
* end of the stream. If a sample is read then the buffer is populated with information
|
* end of the stream. If a sample is read then the buffer is populated with information about
|
||||||
* about the sample, but not its data. The size and absolute position of the data in the
|
* the sample, but not its data. The size and absolute position of the data in the rolling
|
||||||
* rolling buffer is stored in {@code extrasHolder}, along with an encryption id if present
|
* buffer is stored in {@code extrasHolder}, along with an encryption id if present and the
|
||||||
* and the absolute position of the first byte that may still be required after the current
|
* absolute position of the first byte that may still be required after the current sample has
|
||||||
* sample has been read. May be null if the caller requires that the format of the stream be
|
* been read. If a {@link DecoderInputBuffer#isFlagsOnly() flags-only} buffer is passed, only
|
||||||
* read even if it's not changing.
|
* the buffer flags may be populated by this method and the read position of the queue will
|
||||||
* @param formatRequired Whether the caller requires that the format of the stream be read even
|
* not change. May be null if the caller requires that the format of the stream be read even
|
||||||
* if it's not changing. A sample will never be read if set to true, however it is still
|
* if it's not changing.
|
||||||
* possible for the end of stream or nothing to be read.
|
* @param formatRequired Whether the caller requires that the format of the stream be read even if
|
||||||
|
* it's not changing. A sample will never be read if set to true, however it is still possible
|
||||||
|
* for the end of stream or nothing to be read.
|
||||||
* @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 downstreamFormat The current downstream {@link Format}. If the format of the next
|
* @param downstreamFormat The current downstream {@link Format}. If the format of the next sample
|
||||||
* sample is different to the current downstream format then a format will be read.
|
* is different to the current downstream format then a format will be read.
|
||||||
* @param extrasHolder The holder into which extra sample information should be written.
|
* @param extrasHolder The holder into which extra sample information should be written.
|
||||||
* @return The result, which can be {@link C#RESULT_NOTHING_READ}, {@link C#RESULT_FORMAT_READ}
|
* @return The result, which can be {@link C#RESULT_NOTHING_READ}, {@link C#RESULT_FORMAT_READ} or
|
||||||
* or {@link C#RESULT_BUFFER_READ}.
|
* {@link C#RESULT_BUFFER_READ}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ReferenceEquality")
|
@SuppressWarnings("ReferenceEquality")
|
||||||
public synchronized int read(FormatHolder formatHolder, DecoderInputBuffer buffer,
|
public synchronized int read(
|
||||||
boolean formatRequired, boolean loadingFinished, Format downstreamFormat,
|
FormatHolder formatHolder,
|
||||||
|
DecoderInputBuffer buffer,
|
||||||
|
boolean formatRequired,
|
||||||
|
boolean loadingFinished,
|
||||||
|
Format downstreamFormat,
|
||||||
SampleExtrasHolder extrasHolder) {
|
SampleExtrasHolder extrasHolder) {
|
||||||
if (!hasNextSample()) {
|
if (!hasNextSample()) {
|
||||||
if (loadingFinished || isLastSampleQueued) {
|
if (loadingFinished || isLastSampleQueued) {
|
||||||
|
|
@ -258,12 +264,12 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
return C.RESULT_FORMAT_READ;
|
return C.RESULT_FORMAT_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer.setFlags(flags[relativeReadIndex]);
|
||||||
|
buffer.timeUs = timesUs[relativeReadIndex];
|
||||||
if (buffer.isFlagsOnly()) {
|
if (buffer.isFlagsOnly()) {
|
||||||
return C.RESULT_NOTHING_READ;
|
return C.RESULT_BUFFER_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.timeUs = timesUs[relativeReadIndex];
|
|
||||||
buffer.setFlags(flags[relativeReadIndex]);
|
|
||||||
extrasHolder.size = sizes[relativeReadIndex];
|
extrasHolder.size = sizes[relativeReadIndex];
|
||||||
extrasHolder.offset = offsets[relativeReadIndex];
|
extrasHolder.offset = offsets[relativeReadIndex];
|
||||||
extrasHolder.cryptoData = cryptoDatas[relativeReadIndex];
|
extrasHolder.cryptoData = cryptoDatas[relativeReadIndex];
|
||||||
|
|
|
||||||
|
|
@ -317,8 +317,10 @@ public class SampleQueue implements TrackOutput {
|
||||||
*
|
*
|
||||||
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
||||||
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
||||||
* end of the stream. If the end of the stream has been reached, the
|
* end of the stream. If the end of the stream has been reached, the {@link
|
||||||
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer.
|
* C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer. If a {@link
|
||||||
|
* DecoderInputBuffer#isFlagsOnly() flags-only} buffer is passed, only the buffer flags may be
|
||||||
|
* populated by this method and the read position of the queue will not change.
|
||||||
* @param formatRequired Whether the caller requires that the format of the stream be read even if
|
* @param formatRequired Whether the caller requires that the format of the stream be read even if
|
||||||
* it's not changing. A sample will never be read if set to true, however it is still possible
|
* it's not changing. A sample will never be read if set to true, however it is still possible
|
||||||
* for the end of stream or nothing to be read.
|
* for the end of stream or nothing to be read.
|
||||||
|
|
@ -328,8 +330,12 @@ public class SampleQueue implements TrackOutput {
|
||||||
* @return The result, which can be {@link C#RESULT_NOTHING_READ}, {@link C#RESULT_FORMAT_READ} or
|
* @return The result, which can be {@link C#RESULT_NOTHING_READ}, {@link C#RESULT_FORMAT_READ} or
|
||||||
* {@link C#RESULT_BUFFER_READ}.
|
* {@link C#RESULT_BUFFER_READ}.
|
||||||
*/
|
*/
|
||||||
public int read(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired,
|
public int read(
|
||||||
boolean loadingFinished, long decodeOnlyUntilUs) {
|
FormatHolder formatHolder,
|
||||||
|
DecoderInputBuffer buffer,
|
||||||
|
boolean formatRequired,
|
||||||
|
boolean loadingFinished,
|
||||||
|
long decodeOnlyUntilUs) {
|
||||||
int result = metadataQueue.read(formatHolder, buffer, formatRequired, loadingFinished,
|
int result = metadataQueue.read(formatHolder, buffer, formatRequired, loadingFinished,
|
||||||
downstreamFormat, extrasHolder);
|
downstreamFormat, extrasHolder);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
|
|
@ -341,6 +347,7 @@ public class SampleQueue implements TrackOutput {
|
||||||
if (buffer.timeUs < decodeOnlyUntilUs) {
|
if (buffer.timeUs < decodeOnlyUntilUs) {
|
||||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
||||||
}
|
}
|
||||||
|
if (!buffer.isFlagsOnly()) {
|
||||||
// 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);
|
||||||
|
|
@ -349,6 +356,7 @@ public class SampleQueue implements TrackOutput {
|
||||||
buffer.ensureSpaceForWrite(extrasHolder.size);
|
buffer.ensureSpaceForWrite(extrasHolder.size);
|
||||||
readData(extrasHolder.offset, buffer.data, extrasHolder.size);
|
readData(extrasHolder.offset, buffer.data, extrasHolder.size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return C.RESULT_BUFFER_READ;
|
return C.RESULT_BUFFER_READ;
|
||||||
case C.RESULT_NOTHING_READ:
|
case C.RESULT_NOTHING_READ:
|
||||||
return C.RESULT_NOTHING_READ;
|
return C.RESULT_NOTHING_READ;
|
||||||
|
|
|
||||||
|
|
@ -45,18 +45,20 @@ public interface SampleStream {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to read from the stream.
|
* Attempts to read from the stream.
|
||||||
* <p>
|
*
|
||||||
* If the stream has ended then {@link C#BUFFER_FLAG_END_OF_STREAM} flag is set on {@code buffer}
|
* <p>If the stream has ended then {@link C#BUFFER_FLAG_END_OF_STREAM} flag is set on {@code
|
||||||
* and {@link C#RESULT_BUFFER_READ} is returned. Else if no data is available then
|
* buffer} and {@link C#RESULT_BUFFER_READ} is returned. Else if no data is available then {@link
|
||||||
* {@link C#RESULT_NOTHING_READ} is returned. Else if the format of the media is changing or if
|
* C#RESULT_NOTHING_READ} is returned. Else if the format of the media is changing or if {@code
|
||||||
* {@code formatRequired} is set then {@code formatHolder} is populated and
|
* formatRequired} is set then {@code formatHolder} is populated and {@link C#RESULT_FORMAT_READ}
|
||||||
* {@link C#RESULT_FORMAT_READ} is returned. Else {@code buffer} is populated and
|
* is returned. Else {@code buffer} is populated and {@link C#RESULT_BUFFER_READ} is returned.
|
||||||
* {@link C#RESULT_BUFFER_READ} is returned.
|
|
||||||
*
|
*
|
||||||
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
||||||
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
||||||
* end of the stream. If the end of the stream has been reached, the
|
* end of the stream. If the end of the stream has been reached, the {@link
|
||||||
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer.
|
* C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer. If a {@link
|
||||||
|
* DecoderInputBuffer#isFlagsOnly() flags-only} buffer is passed, then no {@link
|
||||||
|
* DecoderInputBuffer#data} will be read and the read position of the stream will not change,
|
||||||
|
* but the flags of the buffer will be populated.
|
||||||
* @param formatRequired Whether the caller requires that the format of the stream be read even if
|
* @param formatRequired Whether the caller requires that the format of the stream be read even if
|
||||||
* it's not changing. A sample will never be read if set to true, however it is still possible
|
* it's not changing. A sample will never be read if set to true, however it is still possible
|
||||||
* for the end of stream or nothing to be read.
|
* for the end of stream or nothing to be read.
|
||||||
|
|
|
||||||
|
|
@ -326,8 +326,11 @@ import java.util.Arrays;
|
||||||
return C.RESULT_FORMAT_READ;
|
return C.RESULT_FORMAT_READ;
|
||||||
} else if (loadingFinished) {
|
} else if (loadingFinished) {
|
||||||
if (loadingSucceeded) {
|
if (loadingSucceeded) {
|
||||||
buffer.timeUs = 0;
|
|
||||||
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
|
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
|
||||||
|
buffer.timeUs = 0;
|
||||||
|
if (buffer.isFlagsOnly()) {
|
||||||
|
return C.RESULT_BUFFER_READ;
|
||||||
|
}
|
||||||
buffer.ensureSpaceForWrite(sampleSize);
|
buffer.ensureSpaceForWrite(sampleSize);
|
||||||
buffer.data.put(sampleData, 0, sampleSize);
|
buffer.data.put(sampleData, 0, sampleSize);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue