mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08:00
Add a Util.nullSafeArrayAppend and use it in HlsSampleStreamWrapper
I could do this with nullSafeArrayConcat but this saves allocating a throw-away single-element array. PiperOrigin-RevId: 274545815
This commit is contained in:
parent
498a23e328
commit
eb677eb4b9
@ -336,7 +336,20 @@ public final class Util {
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates two non-null type arrays.
|
||||
* Creates a new array containing {@code original} with {@code newElement} appended.
|
||||
*
|
||||
* @param original The input array.
|
||||
* @param newElement The element to append.
|
||||
* @return The new array.
|
||||
*/
|
||||
public static <T> T[] nullSafeArrayAppend(T[] original, T newElement) {
|
||||
@NullableType T[] result = Arrays.copyOf(original, original.length + 1);
|
||||
result[original.length] = newElement;
|
||||
return castNonNullTypeArray(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new array containing the concatenation of two non-null type arrays.
|
||||
*
|
||||
* @param first The first array.
|
||||
* @param second The second array.
|
||||
|
@ -905,11 +905,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
trackOutput.setUpstreamFormatChangeListener(this);
|
||||
sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
|
||||
sampleQueueTrackIds[trackCount] = id;
|
||||
sampleQueues = Arrays.copyOf(sampleQueues, trackCount + 1);
|
||||
sampleQueues[trackCount] = trackOutput;
|
||||
sampleQueueReaders = Arrays.copyOf(sampleQueueReaders, trackCount + 1);
|
||||
sampleQueueReaders[trackCount] =
|
||||
new DecryptableSampleQueueReader(sampleQueues[trackCount], drmSessionManager);
|
||||
sampleQueues = Util.nullSafeArrayAppend(sampleQueues, trackOutput);
|
||||
sampleQueueReaders =
|
||||
Util.nullSafeArrayAppend(
|
||||
sampleQueueReaders,
|
||||
new DecryptableSampleQueueReader(sampleQueues[trackCount], drmSessionManager));
|
||||
sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
|
||||
sampleQueueIsAudioVideoFlags[trackCount] =
|
||||
type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO;
|
||||
|
Loading…
x
Reference in New Issue
Block a user