mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Generalize selectedVariantIndices in preparation for non-main adaptation
After this change, multiple HlsSampleStreamWrappers may contain an apdaptive track group. PiperOrigin-RevId: 232507292
This commit is contained in:
parent
6b81d9e7a4
commit
fc2a99a688
1 changed files with 23 additions and 17 deletions
|
|
@ -69,7 +69,8 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
private TrackGroupArray trackGroups;
|
private TrackGroupArray trackGroups;
|
||||||
private HlsSampleStreamWrapper[] sampleStreamWrappers;
|
private HlsSampleStreamWrapper[] sampleStreamWrappers;
|
||||||
private HlsSampleStreamWrapper[] enabledSampleStreamWrappers;
|
private HlsSampleStreamWrapper[] enabledSampleStreamWrappers;
|
||||||
private int[] selectedVariantIndices;
|
// Maps sample stream wrappers to variant/rendition index by matching array positions.
|
||||||
|
private int[][] manifestUrlsIndicesPerWrapper;
|
||||||
private SequenceableLoader compositeSequenceableLoader;
|
private SequenceableLoader compositeSequenceableLoader;
|
||||||
private boolean notifiedReadingStarted;
|
private boolean notifiedReadingStarted;
|
||||||
|
|
||||||
|
|
@ -114,7 +115,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
timestampAdjusterProvider = new TimestampAdjusterProvider();
|
timestampAdjusterProvider = new TimestampAdjusterProvider();
|
||||||
sampleStreamWrappers = new HlsSampleStreamWrapper[0];
|
sampleStreamWrappers = new HlsSampleStreamWrapper[0];
|
||||||
enabledSampleStreamWrappers = new HlsSampleStreamWrapper[0];
|
enabledSampleStreamWrappers = new HlsSampleStreamWrapper[0];
|
||||||
selectedVariantIndices = new int[0];
|
manifestUrlsIndicesPerWrapper = new int[0][];
|
||||||
eventDispatcher.mediaPeriodCreated();
|
eventDispatcher.mediaPeriodCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,11 +157,14 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
|
|
||||||
TrackGroupArray mainWrapperTrackGroups;
|
TrackGroupArray mainWrapperTrackGroups;
|
||||||
int mainWrapperPrimaryGroupIndex;
|
int mainWrapperPrimaryGroupIndex;
|
||||||
|
int[] mainWrapperVariantIndices;
|
||||||
if (hasVariants) {
|
if (hasVariants) {
|
||||||
HlsSampleStreamWrapper mainWrapper = sampleStreamWrappers[0];
|
HlsSampleStreamWrapper mainWrapper = sampleStreamWrappers[0];
|
||||||
|
mainWrapperVariantIndices = manifestUrlsIndicesPerWrapper[0];
|
||||||
mainWrapperTrackGroups = mainWrapper.getTrackGroups();
|
mainWrapperTrackGroups = mainWrapper.getTrackGroups();
|
||||||
mainWrapperPrimaryGroupIndex = mainWrapper.getPrimaryTrackGroupIndex();
|
mainWrapperPrimaryGroupIndex = mainWrapper.getPrimaryTrackGroupIndex();
|
||||||
} else {
|
} else {
|
||||||
|
mainWrapperVariantIndices = new int[0];
|
||||||
mainWrapperTrackGroups = TrackGroupArray.EMPTY;
|
mainWrapperTrackGroups = TrackGroupArray.EMPTY;
|
||||||
mainWrapperPrimaryGroupIndex = 0;
|
mainWrapperPrimaryGroupIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +180,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
// Primary group in main wrapper.
|
// Primary group in main wrapper.
|
||||||
hasPrimaryTrackGroupSelection = true;
|
hasPrimaryTrackGroupSelection = true;
|
||||||
for (int i = 0; i < trackSelection.length(); i++) {
|
for (int i = 0; i < trackSelection.length(); i++) {
|
||||||
int variantIndex = selectedVariantIndices[trackSelection.getIndexInTrackGroup(i)];
|
int variantIndex = mainWrapperVariantIndices[trackSelection.getIndexInTrackGroup(i)];
|
||||||
streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, variantIndex));
|
streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, variantIndex));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -188,13 +192,11 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
for (int i = audioWrapperOffset; i < sampleStreamWrappers.length; i++) {
|
for (int i = audioWrapperOffset; i < sampleStreamWrappers.length; i++) {
|
||||||
TrackGroupArray wrapperTrackGroups = sampleStreamWrappers[i].getTrackGroups();
|
TrackGroupArray wrapperTrackGroups = sampleStreamWrappers[i].getTrackGroups();
|
||||||
if (wrapperTrackGroups.indexOf(trackSelectionGroup) != C.INDEX_UNSET) {
|
if (wrapperTrackGroups.indexOf(trackSelectionGroup) != C.INDEX_UNSET) {
|
||||||
if (i < subtitleWrapperOffset) {
|
int groupIndexType =
|
||||||
streamKeys.add(
|
i < subtitleWrapperOffset
|
||||||
new StreamKey(HlsMasterPlaylist.GROUP_INDEX_AUDIO, i - audioWrapperOffset));
|
? HlsMasterPlaylist.GROUP_INDEX_AUDIO
|
||||||
} else {
|
: HlsMasterPlaylist.GROUP_INDEX_SUBTITLE;
|
||||||
streamKeys.add(
|
streamKeys.add(new StreamKey(groupIndexType, manifestUrlsIndicesPerWrapper[i][0]));
|
||||||
new StreamKey(HlsMasterPlaylist.GROUP_INDEX_SUBTITLE, i - subtitleWrapperOffset));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -203,13 +205,14 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
if (needsPrimaryTrackGroupSelection && !hasPrimaryTrackGroupSelection) {
|
if (needsPrimaryTrackGroupSelection && !hasPrimaryTrackGroupSelection) {
|
||||||
// A track selection includes a variant-embedded track, but no variant is added yet. We use
|
// A track selection includes a variant-embedded track, but no variant is added yet. We use
|
||||||
// the valid variant with the lowest bitrate to reduce overhead.
|
// the valid variant with the lowest bitrate to reduce overhead.
|
||||||
int lowestBitrateIndex = selectedVariantIndices[0];
|
int lowestBitrateIndex = mainWrapperVariantIndices[0];
|
||||||
int lowestBitrate = masterPlaylist.variants.get(selectedVariantIndices[0]).format.bitrate;
|
int lowestBitrate = masterPlaylist.variants.get(mainWrapperVariantIndices[0]).format.bitrate;
|
||||||
for (int i = 1; i < selectedVariantIndices.length; i++) {
|
for (int i = 1; i < mainWrapperVariantIndices.length; i++) {
|
||||||
int variantBitrate = masterPlaylist.variants.get(selectedVariantIndices[i]).format.bitrate;
|
int variantBitrate =
|
||||||
|
masterPlaylist.variants.get(mainWrapperVariantIndices[i]).format.bitrate;
|
||||||
if (variantBitrate < lowestBitrate) {
|
if (variantBitrate < lowestBitrate) {
|
||||||
lowestBitrate = variantBitrate;
|
lowestBitrate = variantBitrate;
|
||||||
lowestBitrateIndex = selectedVariantIndices[i];
|
lowestBitrateIndex = mainWrapperVariantIndices[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, lowestBitrateIndex));
|
streamKeys.add(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, lowestBitrateIndex));
|
||||||
|
|
@ -423,6 +426,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
|
|
||||||
int wrapperCount = (hasVariants ? 1 : 0) + audioRenditions.size() + subtitleRenditions.size();
|
int wrapperCount = (hasVariants ? 1 : 0) + audioRenditions.size() + subtitleRenditions.size();
|
||||||
sampleStreamWrappers = new HlsSampleStreamWrapper[wrapperCount];
|
sampleStreamWrappers = new HlsSampleStreamWrapper[wrapperCount];
|
||||||
|
manifestUrlsIndicesPerWrapper = new int[wrapperCount][];
|
||||||
pendingPrepareCount = wrapperCount;
|
pendingPrepareCount = wrapperCount;
|
||||||
|
|
||||||
int currentWrapperIndex = 0;
|
int currentWrapperIndex = 0;
|
||||||
|
|
@ -443,6 +447,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
null,
|
null,
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
positionUs);
|
positionUs);
|
||||||
|
manifestUrlsIndicesPerWrapper[currentWrapperIndex] = new int[] {i};
|
||||||
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
||||||
Format renditionFormat = audioRendition.format;
|
Format renditionFormat = audioRendition.format;
|
||||||
if (allowChunklessPreparation && renditionFormat.codecs != null) {
|
if (allowChunklessPreparation && renditionFormat.codecs != null) {
|
||||||
|
|
@ -457,6 +462,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
HlsSampleStreamWrapper sampleStreamWrapper =
|
HlsSampleStreamWrapper sampleStreamWrapper =
|
||||||
buildSampleStreamWrapper(
|
buildSampleStreamWrapper(
|
||||||
C.TRACK_TYPE_TEXT, new HlsUrl[] {url}, null, Collections.emptyList(), positionUs);
|
C.TRACK_TYPE_TEXT, new HlsUrl[] {url}, null, Collections.emptyList(), positionUs);
|
||||||
|
manifestUrlsIndicesPerWrapper[currentWrapperIndex] = new int[] {i};
|
||||||
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
||||||
sampleStreamWrapper.prepareWithMasterPlaylistInfo(
|
sampleStreamWrapper.prepareWithMasterPlaylistInfo(
|
||||||
new TrackGroupArray(new TrackGroup(url.format)), 0, TrackGroupArray.EMPTY);
|
new TrackGroupArray(new TrackGroup(url.format)), 0, TrackGroupArray.EMPTY);
|
||||||
|
|
@ -530,13 +536,13 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||||
selectedVariantsCount = variantTypes.length - audioVariantCount;
|
selectedVariantsCount = variantTypes.length - audioVariantCount;
|
||||||
}
|
}
|
||||||
HlsUrl[] selectedVariants = new HlsUrl[selectedVariantsCount];
|
HlsUrl[] selectedVariants = new HlsUrl[selectedVariantsCount];
|
||||||
selectedVariantIndices = new int[selectedVariantsCount];
|
manifestUrlsIndicesPerWrapper[0] = new int[selectedVariantsCount];
|
||||||
int outIndex = 0;
|
int outIndex = 0;
|
||||||
for (int i = 0; i < masterPlaylist.variants.size(); i++) {
|
for (int i = 0; i < masterPlaylist.variants.size(); i++) {
|
||||||
if ((!useVideoVariantsOnly || variantTypes[i] == C.TRACK_TYPE_VIDEO)
|
if ((!useVideoVariantsOnly || variantTypes[i] == C.TRACK_TYPE_VIDEO)
|
||||||
&& (!useNonAudioVariantsOnly || variantTypes[i] != C.TRACK_TYPE_AUDIO)) {
|
&& (!useNonAudioVariantsOnly || variantTypes[i] != C.TRACK_TYPE_AUDIO)) {
|
||||||
selectedVariants[outIndex] = masterPlaylist.variants.get(i);
|
selectedVariants[outIndex] = masterPlaylist.variants.get(i);
|
||||||
selectedVariantIndices[outIndex++] = i;
|
manifestUrlsIndicesPerWrapper[0][outIndex++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String codecs = selectedVariants[0].format.codecs;
|
String codecs = selectedVariants[0].format.codecs;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue