mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
HLS: Better stream selection at start of playback.
- Correctly handle bandwidth NO_ESTIMATE case. - Don't consider switching without a previous chunk.
This commit is contained in:
parent
489e99158f
commit
be103106cb
1 changed files with 11 additions and 3 deletions
|
|
@ -387,16 +387,24 @@ public class HlsChunkSource {
|
||||||
|
|
||||||
private int getNextVariantIndex(TsChunk previousTsChunk, long playbackPositionUs) {
|
private int getNextVariantIndex(TsChunk previousTsChunk, long playbackPositionUs) {
|
||||||
clearStaleBlacklistedPlaylists();
|
clearStaleBlacklistedPlaylists();
|
||||||
|
if (previousTsChunk == null) {
|
||||||
|
// Don't consider switching if we don't have a previous chunk.
|
||||||
|
return variantIndex;
|
||||||
|
}
|
||||||
|
long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
|
||||||
|
if (bitrateEstimate == BandwidthMeter.NO_ESTIMATE) {
|
||||||
|
// Don't consider switching if we don't have a bandwidth estimate.
|
||||||
|
return variantIndex;
|
||||||
|
}
|
||||||
int idealVariantIndex = getVariantIndexForBandwdith(
|
int idealVariantIndex = getVariantIndexForBandwdith(
|
||||||
(int) (bandwidthMeter.getBitrateEstimate() * BANDWIDTH_FRACTION));
|
(int) (bitrateEstimate * BANDWIDTH_FRACTION));
|
||||||
if (idealVariantIndex == variantIndex) {
|
if (idealVariantIndex == variantIndex) {
|
||||||
// We're already using the ideal variant.
|
// We're already using the ideal variant.
|
||||||
return variantIndex;
|
return variantIndex;
|
||||||
}
|
}
|
||||||
// We're not using the ideal variant for the available bandwidth, but only switch if the
|
// We're not using the ideal variant for the available bandwidth, but only switch if the
|
||||||
// conditions are appropriate.
|
// conditions are appropriate.
|
||||||
long bufferedPositionUs = previousTsChunk == null ? playbackPositionUs
|
long bufferedPositionUs = adaptiveMode == ADAPTIVE_MODE_SPLICE ? previousTsChunk.startTimeUs
|
||||||
: adaptiveMode == ADAPTIVE_MODE_SPLICE ? previousTsChunk.startTimeUs
|
|
||||||
: previousTsChunk.endTimeUs;
|
: previousTsChunk.endTimeUs;
|
||||||
long bufferedUs = bufferedPositionUs - playbackPositionUs;
|
long bufferedUs = bufferedPositionUs - playbackPositionUs;
|
||||||
if (mediaPlaylistBlacklistTimesMs[variantIndex] != 0
|
if (mediaPlaylistBlacklistTimesMs[variantIndex] != 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue