Skip to content

Commit

Permalink
Immediately switch audio tracks if different role selected
Browse files Browse the repository at this point in the history
Previously, selecting a new audio track with selectAudioLanguage(), with
the same language but different role, would only set the variants to
switch to for ABR, but wouldn't actually switch to any of those variants
at the moment of selection due to a bug in chooseStreams_(), which was
still looking at only audio language as a differentiating mechanism.
This change honors the role as well, so that a switch to the correct
variants immediately happens.

Closes shaka-project#948
  • Loading branch information
Bryan Huh committed Jul 26, 2017
1 parent 4496f53 commit 6958e95
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ goog.require('shaka.media.SegmentReference');
goog.require('shaka.media.StreamingEngine');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.text.SimpleTextDisplayer');
goog.require('shaka.util.ArrayUtils');
goog.require('shaka.util.CancelableChain');
goog.require('shaka.util.ConfigUtils');
goog.require('shaka.util.Error');
Expand Down Expand Up @@ -2327,7 +2328,7 @@ shaka.Player.prototype.chooseStreams_ =
}

// Check if any of the active streams is no longer available
// or is using the wrong language.
// or is using the wrong language/role.
var activeStreams = this.streamingEngine_.getActiveStreams();
// activePeriod may reasonably be null before StreamingEngine is streaming.
var activePeriod = this.streamingEngine_.getActivePeriod();
Expand All @@ -2346,7 +2347,9 @@ shaka.Player.prototype.chooseStreams_ =
for (var type in activeStreams) {
var stream = activeStreams[type];
if (stream.type == ContentType.AUDIO &&
stream.language != variants[0].language) {
(stream.language != variants[0].language ||
!shaka.util.ArrayUtils.equal(stream.roles,
variants[0].audio.roles))) {
needsUpdate.push(type);
} else if (stream.type == ContentType.TEXT && textStreams.length > 0 &&
stream.language != textStreams[0].language) {
Expand Down
25 changes: 22 additions & 3 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ describe('Player', function() {
.addVariant(3)
.bandwidth(200)
.language('en')
.addAudio(2).bandwidth(100)
.addAudio(2).bandwidth(100).roles(['secondary'])
.addVideo(4).bandwidth(100).size(100, 200)
.frameRate(1000000 / 42000)
.addVariant(4)
Expand Down Expand Up @@ -1122,7 +1122,7 @@ describe('Player', function() {
audioCodec: 'mp4a.40.2',
videoCodec: 'avc1.4d401f',
primary: false,
roles: [],
roles: ['secondary'],
videoId: 4,
audioId: 2,
channelsCount: null,
Expand All @@ -1145,7 +1145,7 @@ describe('Player', function() {
audioCodec: 'mp4a.40.2',
videoCodec: 'avc1.4d401f',
primary: false,
roles: [],
roles: ['secondary'],
videoId: 5,
audioId: 2,
channelsCount: null,
Expand Down Expand Up @@ -1285,6 +1285,25 @@ describe('Player', function() {
ContentType.AUDIO, variant2.audio, false);
});

it('switches audio if tracks have different roles ', function() {
chooseStreams();
canSwitch();

var period = manifest.periods[0];
var variant1 = period.variants[0];
var variant2 = period.variants[2];
expect(shaka.util.ArrayUtils.equal(
variant1.audio.roles, variant2.audio.roles)).toBe(false);

player.selectVariantTrack(variantTracks[0]);
streamingEngine.switch.calls.reset();

player.selectVariantTrack(variantTracks[2]);

expect(streamingEngine.switch).toHaveBeenCalledWith(
ContentType.AUDIO, variant2.audio, false);
});

it('doesn\'t switch video if old and new variants ' +
'have the same video track', function() {
chooseStreams();
Expand Down

0 comments on commit 6958e95

Please sign in to comment.