Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Select first of identical audio streams #3869

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/abr/simple_abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ goog.provide('shaka.abr.SimpleAbrManager');
goog.require('goog.asserts');
goog.require('shaka.abr.EwmaBandwidthEstimator');
goog.require('shaka.log');
goog.require('shaka.util.Iterables');
goog.require('shaka.util.StreamUtils');


Expand Down Expand Up @@ -145,23 +144,30 @@ shaka.abr.SimpleAbrManager = class {
// Start by assuming that we will use the first Stream.
let chosen = sortedVariants[0] || null;

const enumerate = (it) => shaka.util.Iterables.enumerate(it);
for (const {item, next} of enumerate(sortedVariants)) {
for (let i = 0; i < sortedVariants.length; i++) {
const item = sortedVariants[i];
const playbackRate =
!isNaN(this.playbackRate_) ? Math.abs(this.playbackRate_) : 1;
const itemBandwidth = playbackRate * item.bandwidth;
const minBandwidth =
itemBandwidth / this.config_.bandwidthDowngradeTarget;
const nextBandwidth =
playbackRate * (next || {bandwidth: Infinity}).bandwidth;
let next = {bandwidth: Infinity};
for (let j = i + 1; j < sortedVariants.length; j++) {
if (item.bandwidth != sortedVariants[j].bandwidth) {
next = sortedVariants[j];
break;
}
}
const nextBandwidth = playbackRate * next.bandwidth;
const maxBandwidth = nextBandwidth / this.config_.bandwidthUpgradeTarget;
shaka.log.v2('Bandwidth ranges:',
(itemBandwidth / 1e6).toFixed(3),
(minBandwidth / 1e6).toFixed(3),
(maxBandwidth / 1e6).toFixed(3));

if (currentBandwidth >= minBandwidth &&
currentBandwidth <= maxBandwidth) {
currentBandwidth <= maxBandwidth &&
chosen.bandwidth != item.bandwidth) {
chosen = item;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/abr/simple_abr_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('SimpleAbrManager', () => {
config.defaultBandwidthEstimate = 3e6;
abrManager.configure(config);
const chosen = abrManager.chooseVariant();
expect(chosen.id).toBe(104);
expect(chosen.id).toBe(103);
});

it('can handle empty variants', () => {
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('SimpleAbrManager', () => {
abrManager.segmentDownloaded(1000, bytesPerSecond);

// Expect variants 4 to be chosen
const expectedVariant = variants[4];
const expectedVariant = variants[3];

expect(switchCallback).toHaveBeenCalledWith(expectedVariant);
});
Expand Down