Commit 6a52cd74 by tonihei Committed by Oliver Woodman

Ensure HlsMediaPeriod works with playlists without variants.

Currently, we remove all variants if none of the stream keys contains any
variants. This causes HlsMediaPeriod to throw exceptions as it expects at least
one variant.

Change it to support master playlists without variants.

PiperOrigin-RevId: 231385547
parent 9779f2c3
......@@ -343,15 +343,19 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
private void buildAndPrepareSampleStreamWrappers(long positionUs) {
HlsMasterPlaylist masterPlaylist = playlistTracker.getMasterPlaylist();
boolean hasVariants = !masterPlaylist.variants.isEmpty();
List<HlsUrl> audioRenditions = masterPlaylist.audios;
List<HlsUrl> subtitleRenditions = masterPlaylist.subtitles;
int wrapperCount = 1 /* variants */ + audioRenditions.size() + subtitleRenditions.size();
int wrapperCount = (hasVariants ? 1 : 0) + audioRenditions.size() + subtitleRenditions.size();
sampleStreamWrappers = new HlsSampleStreamWrapper[wrapperCount];
pendingPrepareCount = wrapperCount;
buildAndPrepareMainSampleStreamWrapper(masterPlaylist, positionUs);
int currentWrapperIndex = 1;
int currentWrapperIndex = 0;
if (hasVariants) {
buildAndPrepareMainSampleStreamWrapper(masterPlaylist, positionUs);
currentWrapperIndex++;
}
// TODO: Build video stream wrappers here.
......@@ -370,8 +374,6 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
if (allowChunklessPreparation && renditionFormat.codecs != null) {
sampleStreamWrapper.prepareWithMasterPlaylistInfo(
new TrackGroupArray(new TrackGroup(audioRendition.format)), 0, TrackGroupArray.EMPTY);
} else {
sampleStreamWrapper.continuePreparing();
}
}
......@@ -386,6 +388,12 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
new TrackGroupArray(new TrackGroup(url.format)), 0, TrackGroupArray.EMPTY);
}
// Set timestamp master and trigger preparation (if not already prepared)
sampleStreamWrappers[0].setIsTimestampMaster(true);
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
sampleStreamWrapper.continuePreparing();
}
// All wrappers are enabled during preparation.
enabledSampleStreamWrappers = sampleStreamWrappers;
}
......@@ -503,9 +511,6 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
new TrackGroupArray(muxedTrackGroups.toArray(new TrackGroup[0])),
0,
new TrackGroupArray(id3TrackGroup));
} else {
sampleStreamWrapper.setIsTimestampMaster(true);
sampleStreamWrapper.continuePreparing();
}
}
......@@ -566,7 +571,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
if (isPrimaryTrackInVariant) {
channelCount = variantFormat.channelCount;
selectionFlags = variantFormat.selectionFlags;
language = variantFormat.label;
language = variantFormat.language;
label = variantFormat.label;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment