Update SampleQueue.sourceId to be a long rather than an int.

This simplifies usage of 64-bit sequence numbers.

PiperOrigin-RevId: 508107588
This commit is contained in:
Googler 2023-02-08 17:52:39 +00:00 committed by christosts
parent fedb74907e
commit e0ad4ed828
3 changed files with 12 additions and 8 deletions

View File

@ -26,6 +26,9 @@
* Add `ConcatenatingMediaSource2` that allows combining multiple media * Add `ConcatenatingMediaSource2` that allows combining multiple media
items into a single window items into a single window
([#247](https://github.com/androidx/media/issues/247)). ([#247](https://github.com/androidx/media/issues/247)).
* Update `SampleQueue` to store `sourceId` as a `long` rather than an
`int`. This changes the signatures of public methods
`SampleQueue.sourceId` and `SampleQueue.peekSourceId`.
* Extractors: * Extractors:
* Throw a ParserException instead of a NullPointerException if the sample * Throw a ParserException instead of a NullPointerException if the sample
table (stbl) is missing a required sample description (stsd) when table (stbl) is missing a required sample description (stsd) when

View File

@ -81,7 +81,7 @@ public class SampleQueue implements TrackOutput {
@Nullable private DrmSession currentDrmSession; @Nullable private DrmSession currentDrmSession;
private int capacity; private int capacity;
private int[] sourceIds; private long[] sourceIds;
private long[] offsets; private long[] offsets;
private int[] sizes; private int[] sizes;
private int[] flags; private int[] flags;
@ -102,7 +102,7 @@ public class SampleQueue implements TrackOutput {
private boolean upstreamFormatAdjustmentRequired; private boolean upstreamFormatAdjustmentRequired;
@Nullable private Format unadjustedUpstreamFormat; @Nullable private Format unadjustedUpstreamFormat;
@Nullable private Format upstreamFormat; @Nullable private Format upstreamFormat;
private int upstreamSourceId; private long upstreamSourceId;
private boolean upstreamAllSamplesAreSyncSamples; private boolean upstreamAllSamplesAreSyncSamples;
private boolean loggedUnexpectedNonSyncSample; private boolean loggedUnexpectedNonSyncSample;
@ -168,7 +168,7 @@ public class SampleQueue implements TrackOutput {
sampleDataQueue = new SampleDataQueue(allocator); sampleDataQueue = new SampleDataQueue(allocator);
extrasHolder = new SampleExtrasHolder(); extrasHolder = new SampleExtrasHolder();
capacity = SAMPLE_CAPACITY_INCREMENT; capacity = SAMPLE_CAPACITY_INCREMENT;
sourceIds = new int[capacity]; sourceIds = new long[capacity];
offsets = new long[capacity]; offsets = new long[capacity];
timesUs = new long[capacity]; timesUs = new long[capacity];
flags = new int[capacity]; flags = new int[capacity];
@ -240,7 +240,7 @@ public class SampleQueue implements TrackOutput {
* *
* @param sourceId The source identifier. * @param sourceId The source identifier.
*/ */
public final void sourceId(int sourceId) { public final void sourceId(long sourceId) {
upstreamSourceId = sourceId; upstreamSourceId = sourceId;
} }
@ -318,7 +318,7 @@ public class SampleQueue implements TrackOutput {
* *
* @return The source id. * @return The source id.
*/ */
public final synchronized int peekSourceId() { public final synchronized long peekSourceId() {
int relativeReadIndex = getRelativeIndex(readPosition); int relativeReadIndex = getRelativeIndex(readPosition);
return hasNextSample() ? sourceIds[relativeReadIndex] : upstreamSourceId; return hasNextSample() ? sourceIds[relativeReadIndex] : upstreamSourceId;
} }
@ -828,7 +828,7 @@ public class SampleQueue implements TrackOutput {
if (length == capacity) { if (length == capacity) {
// Increase the capacity. // Increase the capacity.
int newCapacity = capacity + SAMPLE_CAPACITY_INCREMENT; int newCapacity = capacity + SAMPLE_CAPACITY_INCREMENT;
int[] newSourceIds = new int[newCapacity]; long[] newSourceIds = new long[newCapacity];
long[] newOffsets = new long[newCapacity]; long[] newOffsets = new long[newCapacity];
long[] newTimesUs = new long[newCapacity]; long[] newTimesUs = new long[newCapacity];
int[] newFlags = new int[newCapacity]; int[] newFlags = new int[newCapacity];

View File

@ -71,6 +71,7 @@ import androidx.media3.extractor.metadata.emsg.EventMessageDecoder;
import androidx.media3.extractor.metadata.id3.PrivFrame; import androidx.media3.extractor.metadata.id3.PrivFrame;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.primitives.Ints;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -664,7 +665,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
Format format = Assertions.checkNotNull(formatHolder.format); Format format = Assertions.checkNotNull(formatHolder.format);
if (sampleQueueIndex == primarySampleQueueIndex) { if (sampleQueueIndex == primarySampleQueueIndex) {
// Fill in primary sample format with information from the track format. // Fill in primary sample format with information from the track format.
int chunkUid = sampleQueues[sampleQueueIndex].peekSourceId(); int chunkUid = Ints.checkedCast(sampleQueues[sampleQueueIndex].peekSourceId());
int chunkIndex = 0; int chunkIndex = 0;
while (chunkIndex < mediaChunks.size() && mediaChunks.get(chunkIndex).uid != chunkUid) { while (chunkIndex < mediaChunks.size() && mediaChunks.get(chunkIndex).uid != chunkUid) {
chunkIndex++; chunkIndex++;