mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Rollback of dd7223df10
*** Original commit *** Refactor HlsSampleStreamWrapper#track() to clarify the return paths I found the original implementation quite hard to follow, and I believe this is functionally identical. *** PiperOrigin-RevId: 270263186
This commit is contained in:
parent
e5f9a858d3
commit
0a854d6b84
1 changed files with 36 additions and 34 deletions
|
|
@ -127,7 +127,7 @@ import java.util.Set;
|
||||||
private Format downstreamTrackFormat;
|
private Format downstreamTrackFormat;
|
||||||
private boolean released;
|
private boolean released;
|
||||||
|
|
||||||
// Tracks are complicated in HLS. See documentation of buildTracksFromSampleStreams for details.
|
// Tracks are complicated in HLS. See documentation of buildTracks for details.
|
||||||
// Indexed by track (as exposed by this source).
|
// Indexed by track (as exposed by this source).
|
||||||
private TrackGroupArray trackGroups;
|
private TrackGroupArray trackGroups;
|
||||||
private Set<TrackGroup> optionalTrackGroups;
|
private Set<TrackGroup> optionalTrackGroups;
|
||||||
|
|
@ -815,15 +815,42 @@ import java.util.Set;
|
||||||
int trackCount = sampleQueues.length;
|
int trackCount = sampleQueues.length;
|
||||||
|
|
||||||
// Audio and video tracks are handled manually to ignore ids.
|
// Audio and video tracks are handled manually to ignore ids.
|
||||||
@Nullable TrackOutput mappedTrack = maybeMapAndGetSampleQueue(id, type);
|
if (type == C.TRACK_TYPE_AUDIO) {
|
||||||
if (mappedTrack != null) {
|
if (audioSampleQueueIndex != C.INDEX_UNSET) {
|
||||||
return mappedTrack;
|
if (audioSampleQueueMappingDone) {
|
||||||
|
return sampleQueueTrackIds[audioSampleQueueIndex] == id
|
||||||
|
? sampleQueues[audioSampleQueueIndex]
|
||||||
|
: createDummyTrackOutput(id, type);
|
||||||
|
}
|
||||||
|
audioSampleQueueMappingDone = true;
|
||||||
|
sampleQueueTrackIds[audioSampleQueueIndex] = id;
|
||||||
|
return sampleQueues[audioSampleQueueIndex];
|
||||||
|
} else if (tracksEnded) {
|
||||||
|
return createDummyTrackOutput(id, type);
|
||||||
|
}
|
||||||
|
} else if (type == C.TRACK_TYPE_VIDEO) {
|
||||||
|
if (videoSampleQueueIndex != C.INDEX_UNSET) {
|
||||||
|
if (videoSampleQueueMappingDone) {
|
||||||
|
return sampleQueueTrackIds[videoSampleQueueIndex] == id
|
||||||
|
? sampleQueues[videoSampleQueueIndex]
|
||||||
|
: createDummyTrackOutput(id, type);
|
||||||
|
}
|
||||||
|
videoSampleQueueMappingDone = true;
|
||||||
|
sampleQueueTrackIds[videoSampleQueueIndex] = id;
|
||||||
|
return sampleQueues[videoSampleQueueIndex];
|
||||||
|
} else if (tracksEnded) {
|
||||||
|
return createDummyTrackOutput(id, type);
|
||||||
|
}
|
||||||
|
} else /* sparse track */ {
|
||||||
|
for (int i = 0; i < trackCount; i++) {
|
||||||
|
if (sampleQueueTrackIds[i] == id) {
|
||||||
|
return sampleQueues[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tracksEnded) {
|
||||||
|
return createDummyTrackOutput(id, type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (tracksEnded) {
|
|
||||||
return createDummyTrackOutput(id, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The relevant SampleQueue hasn't been constructed yet - so construct it:
|
|
||||||
SampleQueue trackOutput = new FormatAdjustingSampleQueue(allocator, overridingDrmInitData);
|
SampleQueue trackOutput = new FormatAdjustingSampleQueue(allocator, overridingDrmInitData);
|
||||||
trackOutput.setSampleOffsetUs(sampleOffsetUs);
|
trackOutput.setSampleOffsetUs(sampleOffsetUs);
|
||||||
trackOutput.sourceId(chunkUid);
|
trackOutput.sourceId(chunkUid);
|
||||||
|
|
@ -854,31 +881,6 @@ import java.util.Set;
|
||||||
return trackOutput;
|
return trackOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private TrackOutput maybeMapAndGetSampleQueue(int id, int type) {
|
|
||||||
int sampleQueueIndex;
|
|
||||||
boolean sampleQueueMappingDone;
|
|
||||||
if (type == C.TRACK_TYPE_AUDIO && audioSampleQueueIndex != C.INDEX_UNSET) {
|
|
||||||
sampleQueueIndex = audioSampleQueueIndex;
|
|
||||||
sampleQueueMappingDone = audioSampleQueueMappingDone;
|
|
||||||
audioSampleQueueMappingDone = true;
|
|
||||||
} else if (type == C.TRACK_TYPE_VIDEO && videoSampleQueueIndex != C.INDEX_UNSET) {
|
|
||||||
sampleQueueIndex = videoSampleQueueIndex;
|
|
||||||
sampleQueueMappingDone = videoSampleQueueMappingDone;
|
|
||||||
videoSampleQueueMappingDone = true;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sampleQueueMappingDone) {
|
|
||||||
return sampleQueueTrackIds[sampleQueueIndex] == id
|
|
||||||
? sampleQueues[sampleQueueIndex]
|
|
||||||
: createDummyTrackOutput(id, type);
|
|
||||||
} else {
|
|
||||||
return sampleQueues[sampleQueueIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endTracks() {
|
public void endTracks() {
|
||||||
tracksEnded = true;
|
tracksEnded = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue