mirror of
https://github.com/androidx/media.git
synced 2025-05-06 23:20:42 +08:00
Deprecate C.POSITION_UNSET
in favour of C.INDEX_UNSET
These have the same value (`-1`), and basically the same meaning (offset in an array/list/file/byte stream/etc), but 'position' is an overloaded term in a media playback library, and there's a risk people assume that methods like `Player.getCurrentPosition()` may return `C.POSITION_UNSET`, when in fact unset media times (whether duration or position) are always represented by `C.TIME_UNSET` which is a) a `long` (not `int`) and b) a different underlying value. (aside: `getCurrentPosition()` never returns an unset value, but it's a good example of the ambiguity of the word 'position' between 'byte offset' and 'media timestamp'.) PiperOrigin-RevId: 492493102
This commit is contained in:
parent
634c6161f1
commit
3efc62b512
@ -60,11 +60,13 @@ public final class C {
|
||||
*/
|
||||
public static final long TIME_UNSET = Long.MIN_VALUE + 1;
|
||||
|
||||
/** Represents an unset or unknown index. */
|
||||
/** Represents an unset or unknown index or byte position. */
|
||||
public static final int INDEX_UNSET = -1;
|
||||
|
||||
/** Represents an unset or unknown position. */
|
||||
@UnstableApi public static final int POSITION_UNSET = -1;
|
||||
/**
|
||||
* @deprecated Use {@link #INDEX_UNSET}.
|
||||
*/
|
||||
@Deprecated @UnstableApi public static final int POSITION_UNSET = INDEX_UNSET;
|
||||
|
||||
/** Represents an unset or unknown rate. */
|
||||
public static final float RATE_UNSET = -Float.MAX_VALUE;
|
||||
|
@ -116,16 +116,16 @@ public final class CacheWriter {
|
||||
endPosition = dataSpec.position + dataSpec.length;
|
||||
} else {
|
||||
long contentLength = ContentMetadata.getContentLength(cache.getContentMetadata(cacheKey));
|
||||
endPosition = contentLength == C.LENGTH_UNSET ? C.POSITION_UNSET : contentLength;
|
||||
endPosition = contentLength == C.LENGTH_UNSET ? C.INDEX_UNSET : contentLength;
|
||||
}
|
||||
if (progressListener != null) {
|
||||
progressListener.onProgress(getLength(), bytesCached, /* newBytesCached= */ 0);
|
||||
}
|
||||
|
||||
while (endPosition == C.POSITION_UNSET || nextPosition < endPosition) {
|
||||
while (endPosition == C.INDEX_UNSET || nextPosition < endPosition) {
|
||||
throwIfCanceled();
|
||||
long maxRemainingLength =
|
||||
endPosition == C.POSITION_UNSET ? Long.MAX_VALUE : endPosition - nextPosition;
|
||||
endPosition == C.INDEX_UNSET ? Long.MAX_VALUE : endPosition - nextPosition;
|
||||
long blockLength = cache.getCachedLength(cacheKey, nextPosition, maxRemainingLength);
|
||||
if (blockLength > 0) {
|
||||
nextPosition += blockLength;
|
||||
@ -225,7 +225,7 @@ public final class CacheWriter {
|
||||
}
|
||||
|
||||
private long getLength() {
|
||||
return endPosition == C.POSITION_UNSET ? C.LENGTH_UNSET : endPosition - dataSpec.position;
|
||||
return endPosition == C.INDEX_UNSET ? C.LENGTH_UNSET : endPosition - dataSpec.position;
|
||||
}
|
||||
|
||||
private void throwIfCanceled() throws InterruptedIOException {
|
||||
|
@ -237,7 +237,7 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@TargetApi(19) // audioTimestamp will be null if Util.SDK_INT < 19.
|
||||
public long getTimestampPositionFrames() {
|
||||
return audioTimestamp != null ? audioTimestamp.getTimestampPositionFrames() : C.POSITION_UNSET;
|
||||
return audioTimestamp != null ? audioTimestamp.getTimestampPositionFrames() : C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
private void updateState(@State int state) {
|
||||
@ -246,7 +246,7 @@ import java.lang.annotation.Target;
|
||||
case STATE_INITIALIZING:
|
||||
// Force polling a timestamp immediately, and poll quickly.
|
||||
lastTimestampSampleTimeUs = 0;
|
||||
initialTimestampPositionFrames = C.POSITION_UNSET;
|
||||
initialTimestampPositionFrames = C.INDEX_UNSET;
|
||||
initializeSystemTimeUs = System.nanoTime() / 1000;
|
||||
sampleIntervalUs = FAST_POLL_INTERVAL_US;
|
||||
break;
|
||||
|
@ -115,7 +115,7 @@ public final class BundledExtractorsAdapter implements ProgressiveMediaExtractor
|
||||
|
||||
@Override
|
||||
public long getCurrentInputPosition() {
|
||||
return extractorInput != null ? extractorInput.getPosition() : C.POSITION_UNSET;
|
||||
return extractorInput != null ? extractorInput.getPosition() : C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +128,7 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac
|
||||
positionHolder.position = inputReaderAdapter.getAndResetSeekPosition();
|
||||
return !shouldContinue
|
||||
? Extractor.RESULT_END_OF_INPUT
|
||||
: positionHolder.position != C.POSITION_UNSET
|
||||
: positionHolder.position != C.INDEX_UNSET
|
||||
? Extractor.RESULT_SEEK
|
||||
: Extractor.RESULT_CONTINUE;
|
||||
}
|
||||
|
@ -75,8 +75,8 @@ public interface ProgressiveMediaExtractor {
|
||||
void disableSeekingOnMp3Streams();
|
||||
|
||||
/**
|
||||
* Returns the current read position in the input stream, or {@link C#POSITION_UNSET} if no input
|
||||
* is available.
|
||||
* Returns the current read position in the input stream, or {@link C#INDEX_UNSET} if no input is
|
||||
* available.
|
||||
*/
|
||||
long getCurrentInputPosition();
|
||||
|
||||
|
@ -1048,7 +1048,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
} finally {
|
||||
if (result == Extractor.RESULT_SEEK) {
|
||||
result = Extractor.RESULT_CONTINUE;
|
||||
} else if (progressiveMediaExtractor.getCurrentInputPosition() != C.POSITION_UNSET) {
|
||||
} else if (progressiveMediaExtractor.getCurrentInputPosition() != C.INDEX_UNSET) {
|
||||
positionHolder.position = progressiveMediaExtractor.getCurrentInputPosition();
|
||||
}
|
||||
DataSourceUtil.closeQuietly(dataSource);
|
||||
|
@ -146,11 +146,11 @@ import java.util.Arrays;
|
||||
/**
|
||||
* Advances the read position to the specified absolute position.
|
||||
*
|
||||
* @param absolutePosition The new absolute read position. May be {@link C#POSITION_UNSET}, in
|
||||
* which case calling this method is a no-op.
|
||||
* @param absolutePosition The new absolute read position. May be {@link C#INDEX_UNSET}, in which
|
||||
* case calling this method is a no-op.
|
||||
*/
|
||||
public void discardDownstreamTo(long absolutePosition) {
|
||||
if (absolutePosition == C.POSITION_UNSET) {
|
||||
if (absolutePosition == C.INDEX_UNSET) {
|
||||
return;
|
||||
}
|
||||
while (absolutePosition >= firstAllocationNode.endPosition) {
|
||||
|
@ -754,26 +754,26 @@ public class SampleQueue implements TrackOutput {
|
||||
private synchronized long discardSampleMetadataTo(
|
||||
long timeUs, boolean toKeyframe, boolean stopAtReadPosition) {
|
||||
if (length == 0 || timeUs < timesUs[relativeFirstIndex]) {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
int searchLength = stopAtReadPosition && readPosition != length ? readPosition + 1 : length;
|
||||
int discardCount = findSampleBefore(relativeFirstIndex, searchLength, timeUs, toKeyframe);
|
||||
if (discardCount == -1) {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
return discardSamples(discardCount);
|
||||
}
|
||||
|
||||
public synchronized long discardSampleMetadataToRead() {
|
||||
if (readPosition == 0) {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
return discardSamples(readPosition);
|
||||
}
|
||||
|
||||
private synchronized long discardSampleMetadataToEnd() {
|
||||
if (length == 0) {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
return discardSamples(length);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public final class InputReaderAdapterV30 implements MediaParser.SeekableInputRea
|
||||
public void setDataReader(DataReader dataReader, long length) {
|
||||
this.dataReader = dataReader;
|
||||
resourceLength = length;
|
||||
lastSeekPosition = C.POSITION_UNSET;
|
||||
lastSeekPosition = C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
/** Sets the absolute position in the resource from which the wrapped {@link DataReader} reads. */
|
||||
@ -55,11 +55,11 @@ public final class InputReaderAdapterV30 implements MediaParser.SeekableInputRea
|
||||
|
||||
/**
|
||||
* Returns the last value passed to {@link #seekToPosition(long)} and sets the stored value to
|
||||
* {@link C#POSITION_UNSET}.
|
||||
* {@link C#INDEX_UNSET}.
|
||||
*/
|
||||
public long getAndResetSeekPosition() {
|
||||
long lastSeekPosition = this.lastSeekPosition;
|
||||
this.lastSeekPosition = C.POSITION_UNSET;
|
||||
this.lastSeekPosition = C.INDEX_UNSET;
|
||||
return lastSeekPosition;
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ public abstract class BinarySearchSeeker {
|
||||
@interface Type {}
|
||||
|
||||
public static final TimestampSearchResult NO_TIMESTAMP_IN_RANGE_RESULT =
|
||||
new TimestampSearchResult(TYPE_NO_TIMESTAMP, C.TIME_UNSET, C.POSITION_UNSET);
|
||||
new TimestampSearchResult(TYPE_NO_TIMESTAMP, C.TIME_UNSET, C.INDEX_UNSET);
|
||||
|
||||
/** The type of the result. */
|
||||
private final @Type int type;
|
||||
|
@ -144,8 +144,8 @@ public final class AviExtractor implements Extractor {
|
||||
chunkHeaderHolder = new ChunkHeaderHolder();
|
||||
extractorOutput = new DummyExtractorOutput();
|
||||
chunkReaders = new ChunkReader[0];
|
||||
moviStart = C.POSITION_UNSET;
|
||||
moviEnd = C.POSITION_UNSET;
|
||||
moviStart = C.INDEX_UNSET;
|
||||
moviEnd = C.INDEX_UNSET;
|
||||
hdrlSize = C.LENGTH_UNSET;
|
||||
durationUs = C.TIME_UNSET;
|
||||
}
|
||||
@ -156,7 +156,7 @@ public final class AviExtractor implements Extractor {
|
||||
public void init(ExtractorOutput output) {
|
||||
this.state = STATE_SKIPPING_TO_HDRL;
|
||||
this.extractorOutput = output;
|
||||
pendingReposition = C.POSITION_UNSET;
|
||||
pendingReposition = C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -208,7 +208,7 @@ public final class AviExtractor implements Extractor {
|
||||
state = STATE_FINDING_MOVI_HEADER;
|
||||
return RESULT_CONTINUE;
|
||||
case STATE_FINDING_MOVI_HEADER:
|
||||
if (moviStart != C.POSITION_UNSET && input.getPosition() != moviStart) {
|
||||
if (moviStart != C.INDEX_UNSET && input.getPosition() != moviStart) {
|
||||
pendingReposition = moviStart;
|
||||
return RESULT_CONTINUE;
|
||||
}
|
||||
@ -275,7 +275,7 @@ public final class AviExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public void seek(long position, long timeUs) {
|
||||
pendingReposition = C.POSITION_UNSET;
|
||||
pendingReposition = C.INDEX_UNSET;
|
||||
currentChunkReader = null;
|
||||
for (ChunkReader chunkReader : chunkReaders) {
|
||||
chunkReader.seekToPosition(position);
|
||||
@ -308,7 +308,7 @@ public final class AviExtractor implements Extractor {
|
||||
private boolean resolvePendingReposition(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException {
|
||||
boolean needSeek = false;
|
||||
if (pendingReposition != C.POSITION_UNSET) {
|
||||
if (pendingReposition != C.INDEX_UNSET) {
|
||||
long currentPosition = input.getPosition();
|
||||
if (pendingReposition < currentPosition
|
||||
|| pendingReposition > currentPosition + RELOAD_MINIMUM_SEEK_DISTANCE) {
|
||||
@ -320,7 +320,7 @@ public final class AviExtractor implements Extractor {
|
||||
input.skipFully((int) (pendingReposition - currentPosition));
|
||||
}
|
||||
}
|
||||
pendingReposition = C.POSITION_UNSET;
|
||||
pendingReposition = C.INDEX_UNSET;
|
||||
return needSeek;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public final class JpegExtractor implements Extractor {
|
||||
|
||||
public JpegExtractor() {
|
||||
scratch = new ParsableByteArray(EXIF_ID_CODE_LENGTH);
|
||||
mp4StartPosition = C.POSITION_UNSET;
|
||||
mp4StartPosition = C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,7 +202,7 @@ public final class JpegExtractor implements Extractor {
|
||||
input.readFully(scratch.getData(), /* offset= */ 0, /* length= */ 2);
|
||||
marker = scratch.readUnsignedShort();
|
||||
if (marker == MARKER_SOS) { // Start of scan.
|
||||
if (mp4StartPosition != C.POSITION_UNSET) {
|
||||
if (mp4StartPosition != C.INDEX_UNSET) {
|
||||
state = STATE_SNIFFING_MOTION_PHOTO_VIDEO;
|
||||
} else {
|
||||
endReadingWithImageTrack();
|
||||
|
@ -81,9 +81,9 @@ import java.util.List;
|
||||
// Iterate backwards through the items to find the earlier video in the list. If we find a video
|
||||
// item with length zero, we need to keep scanning backwards to find the preceding item with
|
||||
// non-zero length, which is the item that contains the video data.
|
||||
long photoStartPosition = C.POSITION_UNSET;
|
||||
long photoStartPosition = C.INDEX_UNSET;
|
||||
long photoLength = C.LENGTH_UNSET;
|
||||
long mp4StartPosition = C.POSITION_UNSET;
|
||||
long mp4StartPosition = C.INDEX_UNSET;
|
||||
long mp4Length = C.LENGTH_UNSET;
|
||||
boolean itemContainsMp4 = false;
|
||||
long itemStartPosition = motionPhotoLength;
|
||||
@ -110,9 +110,9 @@ import java.util.List;
|
||||
photoLength = itemEndPosition;
|
||||
}
|
||||
}
|
||||
if (mp4StartPosition == C.POSITION_UNSET
|
||||
if (mp4StartPosition == C.INDEX_UNSET
|
||||
|| mp4Length == C.LENGTH_UNSET
|
||||
|| photoStartPosition == C.POSITION_UNSET
|
||||
|| photoStartPosition == C.INDEX_UNSET
|
||||
|| photoLength == C.LENGTH_UNSET) {
|
||||
return null;
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public final class ChapterFrame extends Id3Frame {
|
||||
public final String chapterId;
|
||||
public final int startTimeMs;
|
||||
public final int endTimeMs;
|
||||
/** The byte offset of the start of the chapter, or {@link C#POSITION_UNSET} if not set. */
|
||||
/** The byte offset of the start of the chapter, or {@link C#INDEX_UNSET} if not set. */
|
||||
public final long startOffset;
|
||||
/** The byte offset of the end of the chapter, or {@link C#POSITION_UNSET} if not set. */
|
||||
/** The byte offset of the end of the chapter, or {@link C#INDEX_UNSET} if not set. */
|
||||
public final long endOffset;
|
||||
|
||||
private final Id3Frame[] subFrames;
|
||||
|
@ -659,11 +659,11 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
|
||||
int endTime = id3Data.readInt();
|
||||
long startOffset = id3Data.readUnsignedInt();
|
||||
if (startOffset == 0xFFFFFFFFL) {
|
||||
startOffset = C.POSITION_UNSET;
|
||||
startOffset = C.INDEX_UNSET;
|
||||
}
|
||||
long endOffset = id3Data.readUnsignedInt();
|
||||
if (endOffset == 0xFFFFFFFFL) {
|
||||
endOffset = C.POSITION_UNSET;
|
||||
endOffset = C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
ArrayList<Id3Frame> subFrames = new ArrayList<>();
|
||||
|
@ -396,7 +396,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
private @MonotonicNonNull ByteBuffer encryptionSubsampleDataBuffer;
|
||||
|
||||
private long segmentContentSize;
|
||||
private long segmentContentPosition = C.POSITION_UNSET;
|
||||
private long segmentContentPosition = C.INDEX_UNSET;
|
||||
private long timecodeScale = C.TIME_UNSET;
|
||||
private long durationTimecode = C.TIME_UNSET;
|
||||
private long durationUs = C.TIME_UNSET;
|
||||
@ -413,8 +413,8 @@ public class MatroskaExtractor implements Extractor {
|
||||
|
||||
// Cue related elements.
|
||||
private boolean seekForCues;
|
||||
private long cuesContentPosition = C.POSITION_UNSET;
|
||||
private long seekPositionAfterBuildingCues = C.POSITION_UNSET;
|
||||
private long cuesContentPosition = C.INDEX_UNSET;
|
||||
private long seekPositionAfterBuildingCues = C.INDEX_UNSET;
|
||||
private long clusterTimecodeUs = C.TIME_UNSET;
|
||||
@Nullable private LongArray cueTimesUs;
|
||||
@Nullable private LongArray cueClusterPositions;
|
||||
@ -658,8 +658,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
assertInitialized();
|
||||
switch (id) {
|
||||
case ID_SEGMENT:
|
||||
if (segmentContentPosition != C.POSITION_UNSET
|
||||
&& segmentContentPosition != contentPosition) {
|
||||
if (segmentContentPosition != C.INDEX_UNSET && segmentContentPosition != contentPosition) {
|
||||
throw ParserException.createForMalformedContainer(
|
||||
"Multiple Segment elements not supported", /* cause= */ null);
|
||||
}
|
||||
@ -668,7 +667,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
break;
|
||||
case ID_SEEK:
|
||||
seekEntryId = UNSET_ENTRY_ID;
|
||||
seekEntryPosition = C.POSITION_UNSET;
|
||||
seekEntryPosition = C.INDEX_UNSET;
|
||||
break;
|
||||
case ID_CUES:
|
||||
cueTimesUs = new LongArray();
|
||||
@ -680,7 +679,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
case ID_CLUSTER:
|
||||
if (!sentSeekMap) {
|
||||
// We need to build cues before parsing the cluster.
|
||||
if (seekForCuesEnabled && cuesContentPosition != C.POSITION_UNSET) {
|
||||
if (seekForCuesEnabled && cuesContentPosition != C.INDEX_UNSET) {
|
||||
// We know where the Cues element is located. Seek to request it.
|
||||
seekForCues = true;
|
||||
} else {
|
||||
@ -731,7 +730,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
}
|
||||
break;
|
||||
case ID_SEEK:
|
||||
if (seekEntryId == UNSET_ENTRY_ID || seekEntryPosition == C.POSITION_UNSET) {
|
||||
if (seekEntryId == UNSET_ENTRY_ID || seekEntryPosition == C.INDEX_UNSET) {
|
||||
throw ParserException.createForMalformedContainer(
|
||||
"Mandatory element SeekID or SeekPosition not found", /* cause= */ null);
|
||||
}
|
||||
@ -1792,7 +1791,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
*/
|
||||
private SeekMap buildSeekMap(
|
||||
@Nullable LongArray cueTimesUs, @Nullable LongArray cueClusterPositions) {
|
||||
if (segmentContentPosition == C.POSITION_UNSET
|
||||
if (segmentContentPosition == C.INDEX_UNSET
|
||||
|| durationUs == C.TIME_UNSET
|
||||
|| cueTimesUs == null
|
||||
|| cueTimesUs.size() == 0
|
||||
@ -1848,9 +1847,9 @@ public class MatroskaExtractor implements Extractor {
|
||||
}
|
||||
// After parsing Cues, seek back to original position if available. We will not do this unless
|
||||
// we seeked to get to the Cues in the first place.
|
||||
if (sentSeekMap && seekPositionAfterBuildingCues != C.POSITION_UNSET) {
|
||||
if (sentSeekMap && seekPositionAfterBuildingCues != C.INDEX_UNSET) {
|
||||
seekPosition.position = seekPositionAfterBuildingCues;
|
||||
seekPositionAfterBuildingCues = C.POSITION_UNSET;
|
||||
seekPositionAfterBuildingCues = C.INDEX_UNSET;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -54,6 +54,6 @@ import androidx.media3.extractor.MpegAudioUtil;
|
||||
|
||||
@Override
|
||||
public long getDataEndPosition() {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,6 @@ import androidx.media3.extractor.metadata.id3.MlltFrame;
|
||||
|
||||
@Override
|
||||
public long getDataEndPosition() {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
private boolean peekEndOfStreamOrHeader(ExtractorInput extractorInput) throws IOException {
|
||||
if (seeker != null) {
|
||||
long dataEndPosition = seeker.getDataEndPosition();
|
||||
if (dataEndPosition != C.POSITION_UNSET
|
||||
if (dataEndPosition != C.INDEX_UNSET
|
||||
&& extractorInput.getPeekPosition() > dataEndPosition - 4) {
|
||||
return true;
|
||||
}
|
||||
@ -454,7 +454,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
@Nullable Seeker resultSeeker = null;
|
||||
if ((flags & FLAG_ENABLE_INDEX_SEEKING) != 0) {
|
||||
long durationUs;
|
||||
long dataEndPosition = C.POSITION_UNSET;
|
||||
long dataEndPosition = C.INDEX_UNSET;
|
||||
if (metadataSeeker != null) {
|
||||
durationUs = metadataSeeker.getDurationUs();
|
||||
dataEndPosition = metadataSeeker.getDataEndPosition();
|
||||
|
@ -35,7 +35,7 @@ import androidx.media3.extractor.SeekMap;
|
||||
|
||||
/**
|
||||
* Returns the position (byte offset) in the stream that is immediately after audio data, or
|
||||
* {@link C#POSITION_UNSET} if not known.
|
||||
* {@link C#INDEX_UNSET} if not known.
|
||||
*/
|
||||
long getDataEndPosition();
|
||||
|
||||
@ -54,7 +54,7 @@ import androidx.media3.extractor.SeekMap;
|
||||
@Override
|
||||
public long getDataEndPosition() {
|
||||
// Position unset as we do not know the data end position. Note that returning 0 doesn't work.
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ import androidx.media3.extractor.SeekPoint;
|
||||
this.durationUs = durationUs;
|
||||
this.tableOfContents = tableOfContents;
|
||||
this.dataSize = dataSize;
|
||||
dataEndPosition = dataSize == C.LENGTH_UNSET ? C.POSITION_UNSET : dataStartPosition + dataSize;
|
||||
dataEndPosition = dataSize == C.LENGTH_UNSET ? C.INDEX_UNSET : dataStartPosition + dataSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1515,7 +1515,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
childAtomType == Atom.TYPE_esds
|
||||
? childPosition
|
||||
: findBoxPosition(parent, Atom.TYPE_esds, childPosition, childAtomSize);
|
||||
if (esdsAtomPosition != C.POSITION_UNSET) {
|
||||
if (esdsAtomPosition != C.INDEX_UNSET) {
|
||||
esdsData = parseEsdsFromParent(parent, esdsAtomPosition);
|
||||
mimeType = esdsData.mimeType;
|
||||
@Nullable byte[] initializationDataBytes = esdsData.initializationData;
|
||||
@ -1623,7 +1623,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
/**
|
||||
* Returns the position of the first box with the given {@code boxType} within {@code parent}, or
|
||||
* {@link C#POSITION_UNSET} if no such box is found.
|
||||
* {@link C#INDEX_UNSET} if no such box is found.
|
||||
*
|
||||
* @param parent The {@link ParsableByteArray} to search. The search will start from the {@link
|
||||
* ParsableByteArray#getPosition() current position}.
|
||||
@ -1631,7 +1631,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
* @param parentBoxPosition The position in {@code parent} of the box we are searching.
|
||||
* @param parentBoxSize The size of the parent box we are searching in bytes.
|
||||
* @return The position of the first box with the given {@code boxType} within {@code parent}, or
|
||||
* {@link C#POSITION_UNSET} if no such box is found.
|
||||
* {@link C#INDEX_UNSET} if no such box is found.
|
||||
*/
|
||||
private static int findBoxPosition(
|
||||
ParsableByteArray parent, int boxType, int parentBoxPosition, int parentBoxSize)
|
||||
@ -1648,7 +1648,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
}
|
||||
childAtomPosition += childAtomSize;
|
||||
}
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
/** Returns codec-specific initialization data contained in an esds box. */
|
||||
@ -1736,7 +1736,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
/* package */ static Pair<Integer, TrackEncryptionBox> parseCommonEncryptionSinfFromParent(
|
||||
ParsableByteArray parent, int position, int size) throws ParserException {
|
||||
int childPosition = position + Atom.HEADER_SIZE;
|
||||
int schemeInformationBoxPosition = C.POSITION_UNSET;
|
||||
int schemeInformationBoxPosition = C.INDEX_UNSET;
|
||||
int schemeInformationBoxSize = 0;
|
||||
@Nullable String schemeType = null;
|
||||
@Nullable Integer dataFormat = null;
|
||||
@ -1763,7 +1763,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|| C.CENC_TYPE_cbcs.equals(schemeType)) {
|
||||
ExtractorUtil.checkContainerInput(dataFormat != null, "frma atom is mandatory");
|
||||
ExtractorUtil.checkContainerInput(
|
||||
schemeInformationBoxPosition != C.POSITION_UNSET, "schi atom is mandatory");
|
||||
schemeInformationBoxPosition != C.INDEX_UNSET, "schi atom is mandatory");
|
||||
@Nullable
|
||||
TrackEncryptionBox encryptionBox =
|
||||
parseSchiFromParent(
|
||||
|
@ -304,7 +304,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
long firstTimeUs;
|
||||
long firstOffset;
|
||||
long secondTimeUs = C.TIME_UNSET;
|
||||
long secondOffset = C.POSITION_UNSET;
|
||||
long secondOffset = C.INDEX_UNSET;
|
||||
|
||||
// Note that the id matches the index in tracks.
|
||||
int mainTrackIndex = trackId != C.INDEX_UNSET ? trackId : firstVideoTrackIndex;
|
||||
|
@ -109,7 +109,7 @@ import java.io.IOException;
|
||||
return positionBeforeSeekToEnd;
|
||||
case STATE_SEEK:
|
||||
long position = getNextSeekPosition(input);
|
||||
if (position != C.POSITION_UNSET) {
|
||||
if (position != C.INDEX_UNSET) {
|
||||
return position;
|
||||
}
|
||||
state = STATE_SKIP;
|
||||
@ -142,18 +142,18 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Performs a single step of a seeking binary search, returning the byte position from which data
|
||||
* should be provided for the next step, or {@link C#POSITION_UNSET} if the search has converged.
|
||||
* If the search has converged then {@link #skipToPageOfTargetGranule(ExtractorInput)} should be
|
||||
* should be provided for the next step, or {@link C#INDEX_UNSET} if the search has converged. If
|
||||
* the search has converged then {@link #skipToPageOfTargetGranule(ExtractorInput)} should be
|
||||
* called to skip to the target page.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} to read from.
|
||||
* @return The byte position from which data should be provided for the next step, or {@link
|
||||
* C#POSITION_UNSET} if the search has converged.
|
||||
* C#INDEX_UNSET} if the search has converged.
|
||||
* @throws IOException If reading from the input fails.
|
||||
*/
|
||||
private long getNextSeekPosition(ExtractorInput input) throws IOException {
|
||||
if (start == end) {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
long currentPosition = input.getPosition();
|
||||
@ -170,7 +170,7 @@ import java.io.IOException;
|
||||
long granuleDistance = targetGranule - pageHeader.granulePosition;
|
||||
int pageSize = pageHeader.headerSize + pageHeader.bodySize;
|
||||
if (0 <= granuleDistance && granuleDistance < MATCH_RANGE) {
|
||||
return C.POSITION_UNSET;
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
if (granuleDistance < 0) {
|
||||
|
@ -79,7 +79,7 @@ import java.io.IOException;
|
||||
* *\/ C.POSITION_UNSET)}.
|
||||
*/
|
||||
public boolean skipToNextPage(ExtractorInput input) throws IOException {
|
||||
return skipToNextPage(input, /* limit= */ C.POSITION_UNSET);
|
||||
return skipToNextPage(input, /* limit= */ C.INDEX_UNSET);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ import java.io.IOException;
|
||||
*
|
||||
* @param input The {@link ExtractorInput} to read from (must have {@code readPosition ==
|
||||
* peekPosition}).
|
||||
* @param limit The max position in {@code input} to peek to, or {@link C#POSITION_UNSET} to allow
|
||||
* @param limit The max position in {@code input} to peek to, or {@link C#INDEX_UNSET} to allow
|
||||
* peeking to the end.
|
||||
* @return True if a capture_pattern was found.
|
||||
* @throws IOException If reading data fails.
|
||||
@ -102,7 +102,7 @@ import java.io.IOException;
|
||||
public boolean skipToNextPage(ExtractorInput input, long limit) throws IOException {
|
||||
Assertions.checkArgument(input.getPosition() == input.getPeekPosition());
|
||||
scratch.reset(/* limit= */ CAPTURE_PATTERN_SIZE);
|
||||
while ((limit == C.POSITION_UNSET || input.getPosition() + CAPTURE_PATTERN_SIZE < limit)
|
||||
while ((limit == C.INDEX_UNSET || input.getPosition() + CAPTURE_PATTERN_SIZE < limit)
|
||||
&& peekFullyQuietly(
|
||||
input, scratch.getData(), 0, CAPTURE_PATTERN_SIZE, /* allowEndOfInput= */ true)) {
|
||||
scratch.setPosition(0);
|
||||
@ -114,7 +114,7 @@ import java.io.IOException;
|
||||
input.skipFully(1);
|
||||
}
|
||||
// Move the read & peek positions to limit or end-of-input, whichever is closer.
|
||||
while ((limit == C.POSITION_UNSET || input.getPosition() < limit)
|
||||
while ((limit == C.INDEX_UNSET || input.getPosition() < limit)
|
||||
&& input.skip(1) != C.RESULT_END_OF_INPUT) {}
|
||||
return false;
|
||||
}
|
||||
|
@ -1007,10 +1007,10 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
public void clear() {
|
||||
rolledUpCaptions.clear();
|
||||
captionStringBuilder.clear();
|
||||
italicsStartPosition = C.POSITION_UNSET;
|
||||
underlineStartPosition = C.POSITION_UNSET;
|
||||
foregroundColorStartPosition = C.POSITION_UNSET;
|
||||
backgroundColorStartPosition = C.POSITION_UNSET;
|
||||
italicsStartPosition = C.INDEX_UNSET;
|
||||
underlineStartPosition = C.INDEX_UNSET;
|
||||
foregroundColorStartPosition = C.INDEX_UNSET;
|
||||
backgroundColorStartPosition = C.INDEX_UNSET;
|
||||
row = 0;
|
||||
}
|
||||
|
||||
@ -1122,27 +1122,27 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
// TODO: Add support for other offsets.
|
||||
// TODO: Add support for other pen sizes.
|
||||
|
||||
if (italicsStartPosition != C.POSITION_UNSET) {
|
||||
if (italicsStartPosition != C.INDEX_UNSET) {
|
||||
if (!italicsToggle) {
|
||||
captionStringBuilder.setSpan(
|
||||
new StyleSpan(Typeface.ITALIC),
|
||||
italicsStartPosition,
|
||||
captionStringBuilder.length(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
italicsStartPosition = C.POSITION_UNSET;
|
||||
italicsStartPosition = C.INDEX_UNSET;
|
||||
}
|
||||
} else if (italicsToggle) {
|
||||
italicsStartPosition = captionStringBuilder.length();
|
||||
}
|
||||
|
||||
if (underlineStartPosition != C.POSITION_UNSET) {
|
||||
if (underlineStartPosition != C.INDEX_UNSET) {
|
||||
if (!underlineToggle) {
|
||||
captionStringBuilder.setSpan(
|
||||
new UnderlineSpan(),
|
||||
underlineStartPosition,
|
||||
captionStringBuilder.length(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
underlineStartPosition = C.POSITION_UNSET;
|
||||
underlineStartPosition = C.INDEX_UNSET;
|
||||
}
|
||||
} else if (underlineToggle) {
|
||||
underlineStartPosition = captionStringBuilder.length();
|
||||
@ -1153,7 +1153,7 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
}
|
||||
|
||||
public void setPenColor(int foregroundColor, int backgroundColor, int edgeColor) {
|
||||
if (foregroundColorStartPosition != C.POSITION_UNSET) {
|
||||
if (foregroundColorStartPosition != C.INDEX_UNSET) {
|
||||
if (this.foregroundColor != foregroundColor) {
|
||||
captionStringBuilder.setSpan(
|
||||
new ForegroundColorSpan(this.foregroundColor),
|
||||
@ -1167,7 +1167,7 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
this.foregroundColor = foregroundColor;
|
||||
}
|
||||
|
||||
if (backgroundColorStartPosition != C.POSITION_UNSET) {
|
||||
if (backgroundColorStartPosition != C.INDEX_UNSET) {
|
||||
if (this.backgroundColor != backgroundColor) {
|
||||
captionStringBuilder.setSpan(
|
||||
new BackgroundColorSpan(this.backgroundColor),
|
||||
@ -1209,16 +1209,16 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
rolledUpCaptions.add(buildSpannableString());
|
||||
captionStringBuilder.clear();
|
||||
|
||||
if (italicsStartPosition != C.POSITION_UNSET) {
|
||||
if (italicsStartPosition != C.INDEX_UNSET) {
|
||||
italicsStartPosition = 0;
|
||||
}
|
||||
if (underlineStartPosition != C.POSITION_UNSET) {
|
||||
if (underlineStartPosition != C.INDEX_UNSET) {
|
||||
underlineStartPosition = 0;
|
||||
}
|
||||
if (foregroundColorStartPosition != C.POSITION_UNSET) {
|
||||
if (foregroundColorStartPosition != C.INDEX_UNSET) {
|
||||
foregroundColorStartPosition = 0;
|
||||
}
|
||||
if (backgroundColorStartPosition != C.POSITION_UNSET) {
|
||||
if (backgroundColorStartPosition != C.INDEX_UNSET) {
|
||||
backgroundColorStartPosition = 0;
|
||||
}
|
||||
|
||||
@ -1237,7 +1237,7 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
int length = spannableStringBuilder.length();
|
||||
|
||||
if (length > 0) {
|
||||
if (italicsStartPosition != C.POSITION_UNSET) {
|
||||
if (italicsStartPosition != C.INDEX_UNSET) {
|
||||
spannableStringBuilder.setSpan(
|
||||
new StyleSpan(Typeface.ITALIC),
|
||||
italicsStartPosition,
|
||||
@ -1245,7 +1245,7 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
if (underlineStartPosition != C.POSITION_UNSET) {
|
||||
if (underlineStartPosition != C.INDEX_UNSET) {
|
||||
spannableStringBuilder.setSpan(
|
||||
new UnderlineSpan(),
|
||||
underlineStartPosition,
|
||||
@ -1253,7 +1253,7 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
if (foregroundColorStartPosition != C.POSITION_UNSET) {
|
||||
if (foregroundColorStartPosition != C.INDEX_UNSET) {
|
||||
spannableStringBuilder.setSpan(
|
||||
new ForegroundColorSpan(foregroundColor),
|
||||
foregroundColorStartPosition,
|
||||
@ -1261,7 +1261,7 @@ public final class Cea708Decoder extends CeaDecoder {
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
if (backgroundColorStartPosition != C.POSITION_UNSET) {
|
||||
if (backgroundColorStartPosition != C.INDEX_UNSET) {
|
||||
spannableStringBuilder.setSpan(
|
||||
new BackgroundColorSpan(backgroundColor),
|
||||
backgroundColorStartPosition,
|
||||
|
@ -132,7 +132,7 @@ public final class AdtsExtractor implements Extractor {
|
||||
reader = new AdtsReader(true);
|
||||
packetBuffer = new ParsableByteArray(MAX_PACKET_SIZE);
|
||||
averageFrameSize = C.LENGTH_UNSET;
|
||||
firstFramePosition = C.POSITION_UNSET;
|
||||
firstFramePosition = C.INDEX_UNSET;
|
||||
// Allocate scratch space for an ID3 header. The same buffer is also used to read 4 byte values.
|
||||
scratch = new ParsableByteArray(ID3_HEADER_LENGTH);
|
||||
scratchBits = new ParsableBitArray(scratch.getData());
|
||||
@ -258,7 +258,7 @@ public final class AdtsExtractor implements Extractor {
|
||||
}
|
||||
input.resetPeekPosition();
|
||||
input.advancePeekPosition(firstFramePosition);
|
||||
if (this.firstFramePosition == C.POSITION_UNSET) {
|
||||
if (this.firstFramePosition == C.INDEX_UNSET) {
|
||||
this.firstFramePosition = firstFramePosition;
|
||||
}
|
||||
return firstFramePosition;
|
||||
|
@ -89,8 +89,8 @@ import java.io.IOException;
|
||||
|
||||
private TimestampSearchResult searchForScrValueInBuffer(
|
||||
ParsableByteArray packetBuffer, long targetScrTimeUs, long bufferStartOffset) {
|
||||
int startOfLastPacketPosition = C.POSITION_UNSET;
|
||||
int endOfLastPacketPosition = C.POSITION_UNSET;
|
||||
int startOfLastPacketPosition = C.INDEX_UNSET;
|
||||
int endOfLastPacketPosition = C.INDEX_UNSET;
|
||||
long lastScrTimeUsInRange = C.TIME_UNSET;
|
||||
|
||||
while (packetBuffer.bytesLeft() >= 4) {
|
||||
|
@ -66,7 +66,7 @@ public final class SectionReader implements TsPayloadReader {
|
||||
@Override
|
||||
public void consume(ParsableByteArray data, @Flags int flags) {
|
||||
boolean payloadUnitStartIndicator = (flags & FLAG_PAYLOAD_UNIT_START_INDICATOR) != 0;
|
||||
int payloadStartPosition = C.POSITION_UNSET;
|
||||
int payloadStartPosition = C.INDEX_UNSET;
|
||||
if (payloadUnitStartIndicator) {
|
||||
int payloadStartOffset = data.readUnsignedByte();
|
||||
payloadStartPosition = data.getPosition() + payloadStartOffset;
|
||||
|
@ -96,8 +96,8 @@ import java.io.IOException;
|
||||
ParsableByteArray packetBuffer, long targetPcrTimeUs, long bufferStartOffset) {
|
||||
int limit = packetBuffer.limit();
|
||||
|
||||
long startOfLastPacketPosition = C.POSITION_UNSET;
|
||||
long endOfLastPacketPosition = C.POSITION_UNSET;
|
||||
long startOfLastPacketPosition = C.INDEX_UNSET;
|
||||
long endOfLastPacketPosition = C.INDEX_UNSET;
|
||||
long lastPcrTimeUsInRange = C.TIME_UNSET;
|
||||
|
||||
while (packetBuffer.bytesLeft() >= TsExtractor.TS_PACKET_SIZE) {
|
||||
|
@ -92,8 +92,8 @@ public final class WavExtractor implements Extractor {
|
||||
public WavExtractor() {
|
||||
state = STATE_READING_FILE_TYPE;
|
||||
rf64SampleDataSize = C.LENGTH_UNSET;
|
||||
dataStartPosition = C.POSITION_UNSET;
|
||||
dataEndPosition = C.POSITION_UNSET;
|
||||
dataStartPosition = C.INDEX_UNSET;
|
||||
dataEndPosition = C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,7 +153,7 @@ public final class WavExtractor implements Extractor {
|
||||
|
||||
private void readFileType(ExtractorInput input) throws IOException {
|
||||
Assertions.checkState(input.getPosition() == 0);
|
||||
if (dataStartPosition != C.POSITION_UNSET) {
|
||||
if (dataStartPosition != C.INDEX_UNSET) {
|
||||
input.skipFully(dataStartPosition);
|
||||
state = STATE_READING_SAMPLE_DATA;
|
||||
return;
|
||||
@ -228,7 +228,7 @@ public final class WavExtractor implements Extractor {
|
||||
}
|
||||
|
||||
private @ReadResult int readSampleData(ExtractorInput input) throws IOException {
|
||||
Assertions.checkState(dataEndPosition != C.POSITION_UNSET);
|
||||
Assertions.checkState(dataEndPosition != C.INDEX_UNSET);
|
||||
long bytesLeft = dataEndPosition - input.getPosition();
|
||||
return Assertions.checkNotNull(outputWriter).sampleData(input, bytesLeft)
|
||||
? RESULT_END_OF_INPUT
|
||||
|
@ -218,7 +218,7 @@ public final class PsExtractorSeekTest {
|
||||
long initialSeekLoadPosition = seekPoints.first.position;
|
||||
psExtractor.seek(initialSeekLoadPosition, seekTimeUs);
|
||||
|
||||
positionHolder.position = C.POSITION_UNSET;
|
||||
positionHolder.position = C.INDEX_UNSET;
|
||||
ExtractorInput extractorInput = getExtractorInputFromPosition(initialSeekLoadPosition);
|
||||
int extractorReadResult = Extractor.RESULT_CONTINUE;
|
||||
while (true) {
|
||||
|
@ -428,7 +428,7 @@ public class TestUtil {
|
||||
extractor.seek(initialSeekLoadPosition, seekTimeUs);
|
||||
|
||||
PositionHolder positionHolder = new PositionHolder();
|
||||
positionHolder.position = C.POSITION_UNSET;
|
||||
positionHolder.position = C.INDEX_UNSET;
|
||||
ExtractorInput extractorInput =
|
||||
TestUtil.getExtractorInputFromPosition(dataSource, initialSeekLoadPosition, uri);
|
||||
int extractorReadResult = Extractor.RESULT_CONTINUE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user