From b3004ab1c302bf9a0e195fc4234b982f2ffee255 Mon Sep 17 00:00:00 2001 From: hoangtc Date: Thu, 14 Sep 2017 04:28:56 -0700 Subject: [PATCH] Do not apply SampleStream skip-ahead for NoSampleRenderer. Currently, to make transition to next media period seamless, after the renderer has read until the end of the current SampleStream, we may send it the next SampleStream so the renderer may read from the next SampleStream ahead of the transition. For NoSampleRenderer, we should avoid doing this: skipping ahead for such renderer doesn't have any benefit (the renderer does not consume data from SampleStream), and it will change the provided rendererOffsetUs while the renderer is still rendering from the playing media period. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=168669800 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index c0fc36964c..61c5b01cf7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -1355,18 +1355,25 @@ import java.io.IOException; } else if (!renderer.isCurrentStreamFinal()) { TrackSelection newSelection = newTrackSelectorResult.selections.get(i); boolean newRendererEnabled = newTrackSelectorResult.renderersEnabled[i]; + boolean isNoSampleRenderer = rendererCapabilities[i].getTrackType() == C.TRACK_TYPE_NONE; RendererConfiguration oldConfig = oldTrackSelectorResult.rendererConfigurations[i]; RendererConfiguration newConfig = newTrackSelectorResult.rendererConfigurations[i]; - if (newRendererEnabled && newConfig.equals(oldConfig)) { + if (newRendererEnabled && newConfig.equals(oldConfig) && !isNoSampleRenderer) { // Replace the renderer's SampleStream so the transition to playing the next period can // be seamless. + // This should be avoided for no-sample renderer, because skipping ahead for such + // renderer doesn't have any benefit (the renderer does not consume the sample stream), + // and it will change the provided rendererOffsetUs while the renderer is still + // rendering from the playing media period. Format[] formats = getFormats(newSelection); renderer.replaceStream(formats, readingPeriodHolder.sampleStreams[i], readingPeriodHolder.getRendererOffset()); } else { - // The renderer will be disabled when transitioning to playing the next period, either - // because there's no new selection or because a configuration change is required. Mark - // the SampleStream as final to play out any remaining data. + // The renderer will be disabled when transitioning to playing the next period, because + // there's no new selection, or because a configuration change is required, or because + // it's a no-sample renderer for which rendererOffsetUs should be updated only when + // starting to play the next period. Mark the SampleStream as final to play out any + // remaining data. renderer.setCurrentStreamFinal(); } }