Move HLS mapped track picking into a separate method
This helps reduce the amount of nesting in HlsSampleStreamWrapper.track() PiperOrigin-RevId: 271983779
This commit is contained in:
parent
9cc927bc64
commit
f0723a27b7
@ -814,24 +814,14 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public TrackOutput track(int id, int type) {
|
||||
int trackCount = sampleQueues.length;
|
||||
|
||||
if (MAPPABLE_TYPES.contains(type)) {
|
||||
// Track types in MAPPABLE_TYPES are handled manually to ignore IDs.
|
||||
int sampleQueueIndex = sampleQueueIndicesByType.get(type, C.INDEX_UNSET);
|
||||
if (sampleQueueIndex != C.INDEX_UNSET) {
|
||||
if (sampleQueueMappingDoneByType.contains(type)) {
|
||||
return sampleQueueTrackIds[sampleQueueIndex] == id
|
||||
? sampleQueues[sampleQueueIndex]
|
||||
: createDummyTrackOutput(id, type);
|
||||
} else {
|
||||
sampleQueueMappingDoneByType.add(type);
|
||||
sampleQueueTrackIds[sampleQueueIndex] = id;
|
||||
return sampleQueues[sampleQueueIndex];
|
||||
}
|
||||
@Nullable TrackOutput mappedTrackOutput = getMappedTrackOutput(id, type);
|
||||
if (mappedTrackOutput != null) {
|
||||
return mappedTrackOutput;
|
||||
}
|
||||
} else /* sparse track */ {
|
||||
for (int i = 0; i < trackCount; i++) {
|
||||
for (int i = 0; i < sampleQueues.length; i++) {
|
||||
if (sampleQueueTrackIds[i] == id) {
|
||||
return sampleQueues[i];
|
||||
}
|
||||
@ -840,6 +830,8 @@ import java.util.Set;
|
||||
if (tracksEnded) {
|
||||
return createDummyTrackOutput(id, type);
|
||||
}
|
||||
|
||||
int trackCount = sampleQueues.length;
|
||||
SampleQueue trackOutput = new FormatAdjustingSampleQueue(allocator, overridingDrmInitData);
|
||||
trackOutput.setSampleOffsetUs(sampleOffsetUs);
|
||||
trackOutput.sourceId(chunkUid);
|
||||
@ -865,6 +857,37 @@ import java.util.Set;
|
||||
return trackOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link TrackOutput} for the provided {@code type} and {@code id}, or null if none
|
||||
* has been created yet.
|
||||
*
|
||||
* <p>If a {@link SampleQueue} for {@code type} has been created and is mapped, but it has a
|
||||
* different ID, then return a {@link DummyTrackOutput} that does nothing.
|
||||
*
|
||||
* <p>If a {@link SampleQueue} for {@code type} has been created but is not mapped, then map it to
|
||||
* this {@code id} and return it. This situation can happen after a call to {@link #init} with
|
||||
* {@code reusingExtractor=false}.
|
||||
*
|
||||
* @param id The ID of the track.
|
||||
* @param type The type of the track, must be one of {@link #MAPPABLE_TYPES}.
|
||||
* @return The the mapped {@link TrackOutput}, or null if it's not been created yet.
|
||||
*/
|
||||
@Nullable
|
||||
private TrackOutput getMappedTrackOutput(int id, int type) {
|
||||
Assertions.checkArgument(MAPPABLE_TYPES.contains(type));
|
||||
int sampleQueueIndex = sampleQueueIndicesByType.get(type, C.INDEX_UNSET);
|
||||
if (sampleQueueIndex == C.INDEX_UNSET) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (sampleQueueMappingDoneByType.add(type)) {
|
||||
sampleQueueTrackIds[sampleQueueIndex] = id;
|
||||
}
|
||||
return sampleQueueTrackIds[sampleQueueIndex] == id
|
||||
? sampleQueues[sampleQueueIndex]
|
||||
: createDummyTrackOutput(id, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endTracks() {
|
||||
tracksEnded = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user