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