mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add HlsSampleStreamWrapper#assertPreparationComplete
This gives a clear way to ensure all the preparation-related @MonotonicNonNull fields have been set to something. PiperOrigin-RevId: 274988280
This commit is contained in:
parent
03e3ceaedb
commit
e63d3b4b61
1 changed files with 20 additions and 3 deletions
|
|
@ -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;
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackGroupArray getTrackGroups() {
|
public TrackGroupArray getTrackGroups() {
|
||||||
|
assertIsPrepared();
|
||||||
return trackGroups;
|
return trackGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
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;
|
||||||
} 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;
|
||||||
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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue