Skip to content

Commit

Permalink
Add stream bandwidth info to variant tracks.
Browse files Browse the repository at this point in the history
Closes shaka-project#834.

Change-Id: I3af66a227ad09f1686a7ca3f545c2bf9683d3c24
  • Loading branch information
ismena authored and jforbes committed Jul 10, 2017
1 parent 4a704b6 commit 293fcde
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 17 deletions.
11 changes: 10 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ shakaExtern.Stats;
* primary: boolean,
* roles: !Array.<string>,
* videoId: ?number,
* audioId: ?number
* audioId: ?number,
* channelsCount: ?number,
* audioBandwidth: ?number,
* videoBandwidth: ?number
* }}
*
* @description
Expand Down Expand Up @@ -196,6 +199,12 @@ shakaExtern.Stats;
* (only for variant tracks) The video stream id.
* @property {?number} audioId
* (only for variant tracks) The audio stream id.
* @property {?number} channelsCount
* The count of the audio track channels.
* @property {?number} audioBandwidth
* (only for variant tracks) The audio stream's bandwidth if known.
* @property {?number} videoBandwidth
* (only for variant tracks) The video stream's bandwidth if known.
* @exportDoc
*/
shakaExtern.Track;
Expand Down
12 changes: 10 additions & 2 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ shaka.util.StreamUtils.getVariantTracks =
primary: variant.primary,
roles: roles,
videoId: variant.video ? variant.video.id : null,
audioId: variant.audio ? variant.audio.id : null
audioId: variant.audio ? variant.audio.id : null,
channelsCount: variant.audio ? variant.audio.channelsCount : null,
audioBandwidth: (variant.audio && variant.audio.bandwidth) ?
variant.audio.bandwidth : null,
videoBandwidth: (variant.video && variant.video.bandwidth) ?
variant.video.bandwidth : null
};
});

Expand Down Expand Up @@ -300,7 +305,10 @@ shaka.util.StreamUtils.getTextTracks = function(period, activeStreamId) {
audioCodec: null,
videoCodec: null,
primary: stream.primary,
roles: stream.roles
roles: stream.roles,
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
};
});
};
Expand Down
11 changes: 9 additions & 2 deletions test/offline/storage_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ describe('Storage', function() {
videoCodec: 'avc1.4d401f',
roles: [],
videoId: 0,
audioId: 1
audioId: 1,
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
}
];
Promise
Expand Down Expand Up @@ -202,7 +205,11 @@ describe('Storage', function() {
tracks = getVariantTracks(manifest.periods[0], null, null);
// The expected tracks we get back from the stored version of the content
// will have 0 for bandwidth, so adjust the tracks list to match.
tracks.forEach(function(t) { t.bandwidth = 0; });
tracks.forEach(function(t) {
t.bandwidth = 0;
t.audioBandwidth = null;
t.videoBandwidth = null;
});

storage.loadInternal = function() {
return Promise.resolve({
Expand Down
142 changes: 130 additions & 12 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,108 @@ describe('Player', function() {
expect(abrManager.enable).not.toHaveBeenCalled();
});

it('sets the default bandwidth estimate', function() {
chooseStreams();
canSwitch();
player.configure({abr: {defaultBandwidthEstimate: 2000}});
expect(abrManager.setDefaultEstimate).toHaveBeenCalledWith(2000);
});

describe('filterTracks', function() {
it('retains only video+audio variants if they exist', function(done) {
var manifest = new shaka.test.ManifestGenerator()
.addPeriod(0)
.addVariant(1)
.bandwidth(200)
.language('fr')
.addAudio(2).bandwidth(200)
.addVariant(2)
.bandwidth(400)
.language('en')
.addAudio(1).bandwidth(200)
.addVideo(4).bandwidth(200).size(100, 200)
.frameRate(1000000 / 42000)
.addVariant(3)
.bandwidth(200)
.addVideo(5).bandwidth(200).size(300, 400)
.frameRate(1000000 / 42000)
.addPeriod(1)
.addVariant(1)
.bandwidth(200)
.language('fr')
.addAudio(2).bandwidth(200)
.addVariant(2)
.bandwidth(200)
.addVideo(5).bandwidth(200).size(300, 400)
.frameRate(1000000 / 42000)
.addVariant(3)
.bandwidth(400)
.language('en')
.addAudio(1).bandwidth(200)
.addVideo(4).bandwidth(200).size(100, 200)
.frameRate(1000000 / 42000)
.build();

var variantTracks1 = [
{
id: 2,
active: false,
type: 'variant',
bandwidth: 400,
language: 'en',
label: null,
kind: null,
width: 100,
height: 200,
frameRate: 1000000 / 42000,
mimeType: 'video/mp4',
codecs: 'avc1.4d401f, mp4a.40.2',
audioCodec: 'mp4a.40.2',
videoCodec: 'avc1.4d401f',
primary: false,
roles: [],
videoId: 4,
audioId: 1,
channelsCount: null,
audioBandwidth: 200,
videoBandwidth: 200
}
];
var variantTracks2 = [
{
id: 3,
active: false,
type: 'variant',
bandwidth: 400,
language: 'en',
label: null,
kind: null,
width: 100,
height: 200,
frameRate: 1000000 / 42000,
mimeType: 'video/mp4',
codecs: 'avc1.4d401f, mp4a.40.2',
audioCodec: 'mp4a.40.2',
videoCodec: 'avc1.4d401f',
primary: false,
roles: [],
videoId: 4,
audioId: 1,
channelsCount: null,
audioBandwidth: 200,
videoBandwidth: 200
}
];

var parser = new shaka.test.FakeManifestParser(manifest);
var parserFactory = function() { return parser; };
player.load('', 0, parserFactory).catch(fail).then(function() {
// Check the first period's variant tracks.
var actualVariantTracks1 = player.getVariantTracks();
expect(actualVariantTracks1).toEqual(variantTracks1);

// Check the second period's variant tracks.
playhead.getTime.and.callFake(function() {
return 100;
});
var actualVariantTracks2 = player.getVariantTracks();
expect(actualVariantTracks2).toEqual(variantTracks2);
}).then(done);
});
});

Expand Down Expand Up @@ -805,7 +902,10 @@ describe('Player', function() {
primary: false,
roles: [],
videoId: 4,
audioId: 1
audioId: 1,
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 100
},
{
id: 2,
Expand All @@ -825,7 +925,10 @@ describe('Player', function() {
primary: false,
roles: [],
videoId: 5,
audioId: 1
audioId: 1,
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 200
},
{
id: 3,
Expand All @@ -845,7 +948,10 @@ describe('Player', function() {
primary: false,
roles: [],
videoId: 4,
audioId: 2
audioId: 2,
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 100
},
{
id: 4,
Expand All @@ -865,7 +971,10 @@ describe('Player', function() {
primary: false,
roles: [],
videoId: 5,
audioId: 2
audioId: 2,
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 200
},
{
id: 5,
Expand All @@ -885,7 +994,10 @@ describe('Player', function() {
primary: false,
roles: [],
videoId: 5,
audioId: 8
audioId: 8,
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 200
}
];

Expand All @@ -902,7 +1014,10 @@ describe('Player', function() {
audioCodec: null,
videoCodec: null,
primary: false,
roles: []
roles: [],
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
},
{
id: 7,
Expand All @@ -916,7 +1031,10 @@ describe('Player', function() {
audioCodec: null,
videoCodec: null,
primary: false,
roles: []
roles: [],
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
}
];
});
Expand Down

0 comments on commit 293fcde

Please sign in to comment.