From b29b4f7e1a66d78faedb468d3edba527e96ff0d3 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 4 Oct 2016 04:16:05 -0700 Subject: [PATCH] MergingMediaPeriod + subtitle fixes - Correctly null out streams[j] in the case that a renderer is being disabled. - Read discontinuities from all children, not just enabled ones. This fixes a failure when reading a discontinuity with all renderers disabled. - Add in some assertions to make incorrect stream selection failures obvious and immediate. - Relocate subtitles so they're above the shutter (needed so they continue to be visible when video is disabled but text is still enabled). Issue: #1854 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=135089944 --- .../exoplayer2/ExoPlayerImplInternal.java | 5 ++- .../exoplayer2/source/MergingMediaPeriod.java | 37 ++++++++++++------- .../res/layout/exo_simple_player_view.xml | 10 ++--- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 039d6dd810..85f365e51e 100644 --- a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -1264,11 +1264,14 @@ import java.io.IOException; sampleStreams, streamResetFlags, positionUs); periodTrackSelections = trackSelections; + // Update whether we have enabled tracks and sanity check the expected streams are non-null. hasEnabledTracks = false; for (int i = 0; i < sampleStreams.length; i++) { if (sampleStreams[i] != null) { + Assertions.checkState(trackSelections.get(i) != null); hasEnabledTracks = true; - break; + } else { + Assertions.checkState(trackSelections.get(i) == null); } } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java b/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java index 227dc29366..81721d587c 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.trackselection.TrackSelection; +import com.google.android.exoplayer2.util.Assertions; import java.io.IOException; import java.util.ArrayList; import java.util.IdentityHashMap; @@ -103,10 +104,17 @@ import java.util.IdentityHashMap; boolean periodEnabled = false; for (int j = 0; j < selections.length; j++) { if (selectionChildIndices[j] == i) { + // Assert that the child provided a stream for the selection. + Assertions.checkState(childStreams[j] != null); streams[j] = childStreams[j]; - if (childStreams[j] != null) { - periodEnabled = true; - streamPeriodIndices.put(childStreams[j], i); + periodEnabled = true; + streamPeriodIndices.put(childStreams[j], i); + } else if (streamChildIndices[j] == i) { + // Assert that the child cleared any previous stream. + Assertions.checkState(childStreams[j] == null); + if (selectionChildIndices[j] == C.INDEX_UNSET) { + // No other child will be setting the stream at index j, so clear it. + streams[j] = null; } } } @@ -133,19 +141,20 @@ import java.util.IdentityHashMap; @Override public long readDiscontinuity() { - long positionUs = enabledPeriods[0].readDiscontinuity(); - if (positionUs != C.TIME_UNSET) { - // It must be possible to seek additional periods to the new position. - for (int i = 1; i < enabledPeriods.length; i++) { - if (enabledPeriods[i].seekToUs(positionUs) != positionUs) { - throw new IllegalStateException("Children seeked to different positions"); - } + long positionUs = periods[0].readDiscontinuity(); + // Periods other than the first one are not allowed to report discontinuities. + for (int i = 1; i < periods.length; i++) { + if (periods[i].readDiscontinuity() != C.TIME_UNSET) { + throw new IllegalStateException("Child reported discontinuity"); } } - // Additional periods are not allowed to report discontinuities. - for (int i = 1; i < enabledPeriods.length; i++) { - if (enabledPeriods[i].readDiscontinuity() != C.TIME_UNSET) { - throw new IllegalStateException("Child reported discontinuity"); + // It must be possible to seek enabled periods to the new position, if there is one. + if (positionUs != C.TIME_UNSET) { + for (int i = 0; i < enabledPeriods.length; i++) { + if (enabledPeriods[i] != periods[0] + && enabledPeriods[i].seekToUs(positionUs) != positionUs) { + throw new IllegalStateException("Children seeked to different positions"); + } } } return positionUs; diff --git a/library/src/main/res/layout/exo_simple_player_view.xml b/library/src/main/res/layout/exo_simple_player_view.xml index e1745abcff..99945b8d25 100644 --- a/library/src/main/res/layout/exo_simple_player_view.xml +++ b/library/src/main/res/layout/exo_simple_player_view.xml @@ -22,17 +22,17 @@ android:layout_height="match_parent" android:layout_gravity="center"> + + - -