Skip to content

Commit

Permalink
Always re-send format if sample buffer is null
Browse files Browse the repository at this point in the history
Also clear the playingPeriodHolder in the case the renderers
are being disabled. This is required to ensure that
setPlayingPeriodHolder isn't turned into a no-op, which will
break the seek.

Issue: #2330

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144635220
  • Loading branch information
ojw28 committed Jan 17, 2017
1 parent 60a3eda commit 79a0899
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,14 @@ public boolean isReady() {

@Override
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
if (readFormat) {
if (buffer == null || !readFormat) {
formatHolder.format = format;
readFormat = true;
return C.RESULT_FORMAT_READ;
} else {
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
}
formatHolder.format = format;
readFormat = true;
return C.RESULT_FORMAT_READ;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ protected final int getIndex() {
* {@link C#RESULT_BUFFER_READ} is only returned if {@link #setCurrentStreamFinal()} has been
* called. {@link C#RESULT_NOTHING_READ} is returned otherwise.
*
* @see SampleStream#readData(FormatHolder, DecoderInputBuffer)
* @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
* end of the stream. If the end of the stream has been reached, the
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer.
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer. May be null if the
* caller requires that the format of the stream be read even if it's not changing.
* @return The result, which can be {@link C#RESULT_NOTHING_READ}, {@link C#RESULT_FORMAT_READ} or
* {@link C#RESULT_BUFFER_READ}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ private long seekToPeriodPosition(int periodIndex, long periodPositionUs)
enabledRenderers = new Renderer[0];
rendererMediaClock = null;
rendererMediaClockSource = null;
playingPeriodHolder = null;
}

// Update the holders.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ public boolean skipToKeyframeBefore(long timeUs, boolean allowTimeBeyondBuffer)
* @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
* end of the stream. If the end of the stream has been reached, the
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer.
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer. May be null if the
* caller requires that the format of the stream be read even if it's not changing.
* @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.
Expand Down Expand Up @@ -751,7 +752,8 @@ public synchronized long getLargestQueuedTimestampUs() {
* about the sample, but not its data. The size and absolute position of the data in the
* rolling buffer is stored in {@code extrasHolder}, along with an encryption id if present
* and the absolute position of the first byte that may still be required after the current
* sample has been read.
* sample has been read. May be null if the caller requires that the format of the stream be
* read even if it's not changing.
* @param downstreamFormat The current downstream {@link Format}. If the format of the next
* sample 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.
Expand All @@ -761,14 +763,14 @@ public synchronized long getLargestQueuedTimestampUs() {
public synchronized int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,
Format downstreamFormat, BufferExtrasHolder extrasHolder) {
if (queueSize == 0) {
if (upstreamFormat != null && upstreamFormat != downstreamFormat) {
if (upstreamFormat != null && (buffer == null || upstreamFormat != downstreamFormat)) {
formatHolder.format = upstreamFormat;
return C.RESULT_FORMAT_READ;
}
return C.RESULT_NOTHING_READ;
}

if (formats[relativeReadIndex] != downstreamFormat) {
if (buffer == null || formats[relativeReadIndex] != downstreamFormat) {
formatHolder.format = formats[relativeReadIndex];
return C.RESULT_FORMAT_READ;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
if (pendingDiscontinuity) {
return C.RESULT_NOTHING_READ;
}
if (buffer == null) {
return stream.readData(formatHolder, null);
}
if (sentEos) {
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ public interface SampleStream {

/**
* Attempts to read from the stream.
* <p>
* If no data is available then {@link C#RESULT_NOTHING_READ} is returned. If the format of the
* media is changing or if {@code buffer == null} then {@code formatHolder} is populated and
* {@link C#RESULT_FORMAT_READ} is returned. Else {@code buffer} is populated and
* {@link C#RESULT_BUFFER_READ} is returned.
*
* @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
* end of the stream. If the end of the stream has been reached, the
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer.
* {@link C#BUFFER_FLAG_END_OF_STREAM} flag will be set on the buffer. May be null if the
* caller requires that the format of the stream be read even if it's not changing.
* @return The result, which can be {@link C#RESULT_NOTHING_READ}, {@link C#RESULT_FORMAT_READ} or
* {@link C#RESULT_BUFFER_READ}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ public void maybeThrowError() throws IOException {

@Override
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
if (streamState == STREAM_STATE_END_OF_STREAM) {
buffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
} else if (streamState == STREAM_STATE_SEND_FORMAT) {
if (buffer == null || streamState == STREAM_STATE_SEND_FORMAT) {
formatHolder.format = format;
streamState = STREAM_STATE_SEND_SAMPLE;
return C.RESULT_FORMAT_READ;
} else if (streamState == STREAM_STATE_END_OF_STREAM) {
buffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
}

Assertions.checkState(streamState == STREAM_STATE_SEND_SAMPLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* package */ final class HlsSampleStream implements SampleStream {

public final int group;

private final HlsSampleStreamWrapper sampleStreamWrapper;

public HlsSampleStream(HlsSampleStreamWrapper sampleStreamWrapper, int group) {
Expand Down

0 comments on commit 79a0899

Please sign in to comment.