Skip to content

Commit

Permalink
MergingMediaPeriod + subtitle fixes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ojw28 committed Oct 4, 2016
1 parent 6306c26 commit b29b4f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,14 @@ public long updatePeriodTrackSelection(long positionUs, LoadControl loadControl,
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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;
Expand Down Expand Up @@ -103,10 +104,17 @@ public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamF
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;
}
}
}
Expand All @@ -133,21 +141,22 @@ public long getNextLoadPositionUs() {

@Override
public long readDiscontinuity() {
long positionUs = enabledPeriods[0].readDiscontinuity();
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");
}
}
// It must be possible to seek enabled periods to the new position, if there is one.
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) {
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");
}
}
}
// 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");
}
}
return positionUs;
}

Expand Down
10 changes: 5 additions & 5 deletions library/src/main/res/layout/exo_simple_player_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
android:layout_height="match_parent"
android:layout_gravity="center">

<View android:id="@+id/shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"/>

<com.google.android.exoplayer2.ui.SubtitleView android:id="@+id/subtitles"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

<View android:id="@+id/shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"/>

<com.google.android.exoplayer2.ui.PlaybackControlView android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Expand Down

0 comments on commit b29b4f7

Please sign in to comment.