mirror of
https://github.com/samsonjs/media.git
synced 2026-04-09 11:55:46 +00:00
Add some nullness annotations to SampleQueue
PiperOrigin-RevId: 292921158
This commit is contained in:
parent
b23940dc61
commit
cfda4a5870
4 changed files with 31 additions and 25 deletions
|
|
@ -719,7 +719,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
TrackGroup[] trackArray = new TrackGroup[trackCount];
|
||||
boolean[] trackIsAudioVideoFlags = new boolean[trackCount];
|
||||
for (int i = 0; i < trackCount; i++) {
|
||||
Format trackFormat = sampleQueues[i].getUpstreamFormat();
|
||||
Format trackFormat = Assertions.checkNotNull(sampleQueues[i].getUpstreamFormat());
|
||||
String mimeType = trackFormat.sampleMimeType;
|
||||
boolean isAudio = MimeTypes.isAudio(mimeType);
|
||||
boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
|||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
/** A queue of media samples. */
|
||||
public class SampleQueue implements TrackOutput {
|
||||
|
|
@ -54,7 +55,7 @@ public class SampleQueue implements TrackOutput {
|
|||
private final SampleDataQueue sampleDataQueue;
|
||||
private final SampleExtrasHolder extrasHolder;
|
||||
private final DrmSessionManager<?> drmSessionManager;
|
||||
private UpstreamFormatChangedListener upstreamFormatChangeListener;
|
||||
@Nullable private UpstreamFormatChangedListener upstreamFormatChangeListener;
|
||||
|
||||
@Nullable private Format downstreamFormat;
|
||||
@Nullable private DrmSession<?> currentDrmSession;
|
||||
|
|
@ -65,7 +66,7 @@ public class SampleQueue implements TrackOutput {
|
|||
private int[] sizes;
|
||||
private int[] flags;
|
||||
private long[] timesUs;
|
||||
private CryptoData[] cryptoDatas;
|
||||
private @NullableType CryptoData[] cryptoDatas;
|
||||
private Format[] formats;
|
||||
|
||||
private int length;
|
||||
|
|
@ -78,12 +79,12 @@ public class SampleQueue implements TrackOutput {
|
|||
private boolean isLastSampleQueued;
|
||||
private boolean upstreamKeyframeRequired;
|
||||
private boolean upstreamFormatRequired;
|
||||
private Format upstreamFormat;
|
||||
private Format upstreamCommittedFormat;
|
||||
private boolean upstreamFormatAdjustmentRequired;
|
||||
@Nullable private Format unadjustedUpstreamFormat;
|
||||
@Nullable private Format upstreamFormat;
|
||||
@Nullable private Format upstreamCommittedFormat;
|
||||
private int upstreamSourceId;
|
||||
|
||||
private boolean pendingUpstreamFormatAdjustment;
|
||||
private Format unadjustedUpstreamFormat;
|
||||
private long sampleOffsetUs;
|
||||
private boolean pendingSplice;
|
||||
|
||||
|
|
@ -226,6 +227,7 @@ public class SampleQueue implements TrackOutput {
|
|||
}
|
||||
|
||||
/** Returns the upstream {@link Format} in which samples are being queued. */
|
||||
@Nullable
|
||||
public final synchronized Format getUpstreamFormat() {
|
||||
return upstreamFormatRequired ? null : upstreamFormat;
|
||||
}
|
||||
|
|
@ -448,7 +450,8 @@ public class SampleQueue implements TrackOutput {
|
|||
*
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public final void setUpstreamFormatChangeListener(UpstreamFormatChangedListener listener) {
|
||||
public final void setUpstreamFormatChangeListener(
|
||||
@Nullable UpstreamFormatChangedListener listener) {
|
||||
upstreamFormatChangeListener = listener;
|
||||
}
|
||||
|
||||
|
|
@ -457,7 +460,7 @@ public class SampleQueue implements TrackOutput {
|
|||
@Override
|
||||
public final void format(Format unadjustedUpstreamFormat) {
|
||||
Format adjustedUpstreamFormat = getAdjustedUpstreamFormat(unadjustedUpstreamFormat);
|
||||
pendingUpstreamFormatAdjustment = false;
|
||||
upstreamFormatAdjustmentRequired = false;
|
||||
this.unadjustedUpstreamFormat = unadjustedUpstreamFormat;
|
||||
boolean upstreamFormatChanged = setUpstreamFormat(adjustedUpstreamFormat);
|
||||
if (upstreamFormatChangeListener != null && upstreamFormatChanged) {
|
||||
|
|
@ -483,8 +486,8 @@ public class SampleQueue implements TrackOutput {
|
|||
int size,
|
||||
int offset,
|
||||
@Nullable CryptoData cryptoData) {
|
||||
if (pendingUpstreamFormatAdjustment) {
|
||||
format(unadjustedUpstreamFormat);
|
||||
if (upstreamFormatAdjustmentRequired) {
|
||||
format(Assertions.checkStateNotNull(unadjustedUpstreamFormat));
|
||||
}
|
||||
timeUs += sampleOffsetUs;
|
||||
if (pendingSplice) {
|
||||
|
|
@ -502,7 +505,7 @@ public class SampleQueue implements TrackOutput {
|
|||
* will be called to adjust the upstream {@link Format} again before the next sample is queued.
|
||||
*/
|
||||
protected final void invalidateUpstreamFormatAdjustment() {
|
||||
pendingUpstreamFormatAdjustment = true;
|
||||
upstreamFormatAdjustmentRequired = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -593,10 +596,6 @@ public class SampleQueue implements TrackOutput {
|
|||
}
|
||||
|
||||
private synchronized boolean setUpstreamFormat(Format format) {
|
||||
if (format == null) {
|
||||
upstreamFormatRequired = true;
|
||||
return false;
|
||||
}
|
||||
upstreamFormatRequired = false;
|
||||
if (Util.areEqual(format, upstreamFormat)) {
|
||||
// The format is unchanged. If format and upstreamFormat are different objects, we keep the
|
||||
|
|
@ -653,7 +652,11 @@ public class SampleQueue implements TrackOutput {
|
|||
}
|
||||
|
||||
private synchronized void commitSample(
|
||||
long timeUs, @C.BufferFlags int sampleFlags, long offset, int size, CryptoData cryptoData) {
|
||||
long timeUs,
|
||||
@C.BufferFlags int sampleFlags,
|
||||
long offset,
|
||||
int size,
|
||||
@Nullable CryptoData cryptoData) {
|
||||
if (upstreamKeyframeRequired) {
|
||||
if ((sampleFlags & C.BUFFER_FLAG_KEY_FRAME) == 0) {
|
||||
return;
|
||||
|
|
@ -770,7 +773,7 @@ public class SampleQueue implements TrackOutput {
|
|||
private void onFormatResult(Format newFormat, FormatHolder outputFormatHolder) {
|
||||
outputFormatHolder.format = newFormat;
|
||||
boolean isFirstFormat = downstreamFormat == null;
|
||||
DrmInitData oldDrmInitData = isFirstFormat ? null : downstreamFormat.drmInitData;
|
||||
@Nullable DrmInitData oldDrmInitData = isFirstFormat ? null : downstreamFormat.drmInitData;
|
||||
downstreamFormat = newFormat;
|
||||
if (drmSessionManager == DrmSessionManager.DUMMY) {
|
||||
// Avoid attempting to acquire a session using the dummy DRM session manager. It's likely that
|
||||
|
|
@ -779,7 +782,7 @@ public class SampleQueue implements TrackOutput {
|
|||
// TODO: Remove once renderers are migrated [Internal ref: b/122519809].
|
||||
return;
|
||||
}
|
||||
DrmInitData newDrmInitData = newFormat.drmInitData;
|
||||
@Nullable DrmInitData newDrmInitData = newFormat.drmInitData;
|
||||
outputFormatHolder.includesDrmSession = true;
|
||||
outputFormatHolder.drmSession = currentDrmSession;
|
||||
if (!isFirstFormat && Util.areEqual(oldDrmInitData, newDrmInitData)) {
|
||||
|
|
@ -788,7 +791,7 @@ public class SampleQueue implements TrackOutput {
|
|||
}
|
||||
// Ensure we acquire the new session before releasing the previous one in case the same session
|
||||
// is being used for both DrmInitData.
|
||||
DrmSession<?> previousSession = currentDrmSession;
|
||||
@Nullable DrmSession<?> previousSession = currentDrmSession;
|
||||
Looper playbackLooper = Assertions.checkNotNull(Looper.myLooper());
|
||||
currentDrmSession =
|
||||
newDrmInitData != null
|
||||
|
|
@ -920,6 +923,6 @@ public class SampleQueue implements TrackOutput {
|
|||
|
||||
public int size;
|
||||
public long offset;
|
||||
public CryptoData cryptoData;
|
||||
@Nullable public CryptoData cryptoData;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -665,7 +665,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||
sampleStreamWrapper.prepareWithMasterPlaylistInfo(
|
||||
muxedTrackGroups.toArray(new TrackGroup[0]),
|
||||
/* primaryTrackGroupIndex= */ 0,
|
||||
/* optionalTrackGroupsIndices= */ muxedTrackGroups.indexOf(id3TrackGroup));
|
||||
/* optionalTrackGroupsIndices...= */ muxedTrackGroups.indexOf(id3TrackGroup));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1069,7 +1069,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
for (int i = 0; i < trackGroupCount; i++) {
|
||||
for (int queueIndex = 0; queueIndex < sampleQueues.length; queueIndex++) {
|
||||
SampleQueue sampleQueue = sampleQueues[queueIndex];
|
||||
if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) {
|
||||
Format upstreamFormat = Assertions.checkStateNotNull(sampleQueue.getUpstreamFormat());
|
||||
if (formatsMatch(upstreamFormat, trackGroups.get(i).getFormat(0))) {
|
||||
trackGroupToSampleQueueIndex[i] = queueIndex;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1118,7 +1119,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
int primaryExtractorTrackIndex = C.INDEX_UNSET;
|
||||
int extractorTrackCount = sampleQueues.length;
|
||||
for (int i = 0; i < extractorTrackCount; i++) {
|
||||
@Nullable String sampleMimeType = sampleQueues[i].getUpstreamFormat().sampleMimeType;
|
||||
@Nullable
|
||||
String sampleMimeType =
|
||||
Assertions.checkStateNotNull(sampleQueues[i].getUpstreamFormat()).sampleMimeType;
|
||||
int trackType;
|
||||
if (MimeTypes.isVideo(sampleMimeType)) {
|
||||
trackType = C.TRACK_TYPE_VIDEO;
|
||||
|
|
@ -1153,7 +1156,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
// Construct the set of exposed track groups.
|
||||
TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
|
||||
for (int i = 0; i < extractorTrackCount; i++) {
|
||||
Format sampleFormat = sampleQueues[i].getUpstreamFormat();
|
||||
Format sampleFormat = Assertions.checkStateNotNull(sampleQueues[i].getUpstreamFormat());
|
||||
if (i == primaryExtractorTrackIndex) {
|
||||
Format[] formats = new Format[chunkSourceTrackCount];
|
||||
if (chunkSourceTrackCount == 1) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue