Commit e63d3b4b by ibaker Committed by Oliver Woodman

Add HlsSampleStreamWrapper#assertPreparationComplete

This gives a clear way to ensure all the preparation-related @MonotonicNonNull
fields have been set to something.

PiperOrigin-RevId: 274988280
parent 03e3ceae
...@@ -66,6 +66,7 @@ import java.util.List; ...@@ -66,6 +66,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.checkerframework.checker.nullness.compatqual.NullableType; import org.checkerframework.checker.nullness.compatqual.NullableType;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
...@@ -233,7 +234,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -233,7 +234,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
*/ */
public void prepareWithMasterPlaylistInfo( public void prepareWithMasterPlaylistInfo(
TrackGroup[] trackGroups, int primaryTrackGroupIndex, int... optionalTrackGroupsIndices) { TrackGroup[] trackGroups, int primaryTrackGroupIndex, int... optionalTrackGroupsIndices) {
prepared = true;
this.trackGroups = createTrackGroupArrayWithDrmInfo(trackGroups); this.trackGroups = createTrackGroupArrayWithDrmInfo(trackGroups);
optionalTrackGroups = new HashSet<>(); optionalTrackGroups = new HashSet<>();
for (int optionalTrackGroupIndex : optionalTrackGroupsIndices) { for (int optionalTrackGroupIndex : optionalTrackGroupsIndices) {
...@@ -241,6 +241,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -241,6 +241,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
this.primaryTrackGroupIndex = primaryTrackGroupIndex; this.primaryTrackGroupIndex = primaryTrackGroupIndex;
handler.post(callback::onPrepared); handler.post(callback::onPrepared);
setIsPrepared();
} }
public void maybeThrowPrepareError() throws IOException { public void maybeThrowPrepareError() throws IOException {
...@@ -251,6 +252,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -251,6 +252,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
public TrackGroupArray getTrackGroups() { public TrackGroupArray getTrackGroups() {
assertIsPrepared();
return trackGroups; return trackGroups;
} }
...@@ -259,6 +261,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -259,6 +261,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
public int bindSampleQueueToSampleStream(int trackGroupIndex) { public int bindSampleQueueToSampleStream(int trackGroupIndex) {
assertIsPrepared();
int sampleQueueIndex = trackGroupToSampleQueueIndex[trackGroupIndex]; int sampleQueueIndex = trackGroupToSampleQueueIndex[trackGroupIndex];
if (sampleQueueIndex == C.INDEX_UNSET) { if (sampleQueueIndex == C.INDEX_UNSET) {
return optionalTrackGroups.contains(trackGroups.get(trackGroupIndex)) return optionalTrackGroups.contains(trackGroups.get(trackGroupIndex))
...@@ -274,6 +278,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -274,6 +278,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
public void unbindSampleQueue(int trackGroupIndex) { public void unbindSampleQueue(int trackGroupIndex) {
assertIsPrepared();
int sampleQueueIndex = trackGroupToSampleQueueIndex[trackGroupIndex]; int sampleQueueIndex = trackGroupToSampleQueueIndex[trackGroupIndex];
Assertions.checkState(sampleQueuesEnabledStates[sampleQueueIndex]); Assertions.checkState(sampleQueuesEnabledStates[sampleQueueIndex]);
sampleQueuesEnabledStates[sampleQueueIndex] = false; sampleQueuesEnabledStates[sampleQueueIndex] = false;
...@@ -303,7 +308,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -303,7 +308,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
boolean[] streamResetFlags, boolean[] streamResetFlags,
long positionUs, long positionUs,
boolean forceReset) { boolean forceReset) {
Assertions.checkState(prepared); assertIsPrepared();
int oldEnabledTrackGroupCount = enabledTrackGroupCount; int oldEnabledTrackGroupCount = enabledTrackGroupCount;
// Deselect old tracks. // Deselect old tracks.
for (int i = 0; i < selections.length; i++) { for (int i = 0; i < selections.length; i++) {
...@@ -1001,7 +1006,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -1001,7 +1006,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} else { } else {
// Tracks are created using media segment information. // Tracks are created using media segment information.
buildTracksFromSampleStreams(); buildTracksFromSampleStreams();
prepared = true; setIsPrepared();
callback.onPrepared(); callback.onPrepared();
} }
} }
...@@ -1173,6 +1178,18 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -1173,6 +1178,18 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return true; return true;
} }
@RequiresNonNull({"trackGroups", "optionalTrackGroups"})
private void setIsPrepared() {
prepared = true;
}
@EnsuresNonNull({"trackGroups", "optionalTrackGroups"})
private void assertIsPrepared() {
Assertions.checkState(prepared);
Assertions.checkNotNull(trackGroups);
Assertions.checkNotNull(optionalTrackGroups);
}
/** /**
* Scores a track type. Where multiple tracks are muxed into a container, the track with the * Scores a track type. Where multiple tracks are muxed into a container, the track with the
* highest score is the primary track. * highest score is the primary track.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment