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 committed Jul 7, 2017
1 parent 54d2914 commit b3586c1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
8 changes: 7 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ shakaExtern.Stats;
* roles: !Array.<string>,
* videoId: ?number,
* audioId: ?number,
* channelsCount: ?number
* channelsCount: ?number,
* audioBandwidth: ?number,
* videoBandwidth: ?number
* }}
*
* @description
Expand Down Expand Up @@ -199,6 +201,10 @@ shakaExtern.Stats;
* (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
10 changes: 8 additions & 2 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ shaka.util.StreamUtils.getVariantTracks =
roles: roles,
videoId: variant.video ? variant.video.id : null,
audioId: variant.audio ? variant.audio.id : null,
channelsCount: variant.audio ? variant.audio.channelsCount : 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 @@ -302,7 +306,9 @@ shaka.util.StreamUtils.getTextTracks = function(period, activeStreamId) {
videoCodec: null,
primary: stream.primary,
roles: stream.roles,
channelsCount: null
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
};
});
};
Expand Down
10 changes: 8 additions & 2 deletions test/offline/storage_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ describe('Storage', function() {
roles: [],
videoId: 0,
audioId: 1,
channelsCount: null
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
}
];
Promise
Expand Down Expand Up @@ -210,7 +212,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().then(function() {
Expand Down
56 changes: 37 additions & 19 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,31 +862,31 @@ describe('Player', function() {
.addVariant(1)
.bandwidth(200)
.language('fr')
.addAudio(2).bandwidth(100)
.addAudio(2).bandwidth(200)
.addVariant(2)
.bandwidth(400)
.language('en')
.addAudio(1).bandwidth(100)
.addVideo(4).bandwidth(100).size(100, 200)
.addAudio(1).bandwidth(200)
.addVideo(4).bandwidth(200).size(100, 200)
.frameRate(1000000 / 42000)
.addVariant(3)
.bandwidth(200)
.addVideo(5).bandwidth(100).size(300, 400)
.addVideo(5).bandwidth(200).size(300, 400)
.frameRate(1000000 / 42000)
.addPeriod(1)
.addVariant(1)
.bandwidth(200)
.language('fr')
.addAudio(2).bandwidth(100)
.addAudio(2).bandwidth(200)
.addVariant(2)
.bandwidth(200)
.addVideo(5).bandwidth(100).size(300, 400)
.addVideo(5).bandwidth(200).size(300, 400)
.frameRate(1000000 / 42000)
.addVariant(3)
.bandwidth(450)
.bandwidth(400)
.language('en')
.addAudio(1).bandwidth(100)
.addVideo(4).bandwidth(100).size(100, 200)
.addAudio(1).bandwidth(200)
.addVideo(4).bandwidth(200).size(100, 200)
.frameRate(1000000 / 42000)
.build();

Expand All @@ -910,15 +910,17 @@ describe('Player', function() {
roles: [],
videoId: 4,
audioId: 1,
channelsCount: null
channelsCount: null,
audioBandwidth: 200,
videoBandwidth: 200
}
];
var variantTracks2 = [
{
id: 3,
active: false,
type: 'variant',
bandwidth: 450,
bandwidth: 400,
language: 'en',
label: null,
kind: null,
Expand All @@ -933,7 +935,9 @@ describe('Player', function() {
roles: [],
videoId: 4,
audioId: 1,
channelsCount: null
channelsCount: null,
audioBandwidth: 200,
videoBandwidth: 200
}
];

Expand Down Expand Up @@ -1024,7 +1028,9 @@ describe('Player', function() {
roles: [],
videoId: 4,
audioId: 1,
channelsCount: null
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 100
},
{
id: 2,
Expand All @@ -1045,7 +1051,9 @@ describe('Player', function() {
roles: [],
videoId: 5,
audioId: 1,
channelsCount: null
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 200
},
{
id: 3,
Expand All @@ -1066,7 +1074,9 @@ describe('Player', function() {
roles: [],
videoId: 4,
audioId: 2,
channelsCount: null
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 100
},
{
id: 4,
Expand All @@ -1087,7 +1097,9 @@ describe('Player', function() {
roles: [],
videoId: 5,
audioId: 2,
channelsCount: null
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 200
},
{
id: 5,
Expand All @@ -1108,7 +1120,9 @@ describe('Player', function() {
roles: [],
videoId: 5,
audioId: 8,
channelsCount: null
channelsCount: null,
audioBandwidth: 100,
videoBandwidth: 200
}
];

Expand All @@ -1126,7 +1140,9 @@ describe('Player', function() {
videoCodec: null,
primary: false,
roles: [],
channelsCount: null
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
},
{
id: 7,
Expand All @@ -1141,7 +1157,9 @@ describe('Player', function() {
videoCodec: null,
primary: false,
roles: [],
channelsCount: null
channelsCount: null,
audioBandwidth: null,
videoBandwidth: null
}
];
});
Expand Down

0 comments on commit b3586c1

Please sign in to comment.