Skip to content

Commit

Permalink
Refactor shaka internals to use variants instead of stream sets.
Browse files Browse the repository at this point in the history
Issue shaka-project#279

Change-Id: Idf4241b4e2490876bdc6275685361a5c9bf132b0
  • Loading branch information
ismena committed Dec 28, 2016
1 parent 371687a commit e95d7b9
Show file tree
Hide file tree
Showing 33 changed files with 2,312 additions and 1,787 deletions.
9 changes: 2 additions & 7 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,8 @@ <h1>Shaka Player <span id="version"></span></h1>
<details class="input">
<summary>Info</summary>
<div class="flex">
<label for="videoTracks">Video tracks:</label>
<select id="videoTracks" class="flex-grow"></select>
</div>

<div class="flex">
<label for="audioTracks">Audio tracks:</label>
<select id="audioTracks" class="flex-grow"></select>
<label for="variantTracks">Video+audio track combinations:</label>
<select id="variantTracks" class="flex-grow"></select>
</div>

<div class="flex">
Expand Down
24 changes: 10 additions & 14 deletions demo/info_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ shakaDemo.setupInfo_ = function() {
'trackschanged', shakaDemo.onTracksChanged_);
shakaDemo.player_.addEventListener(
'adaptation', shakaDemo.onAdaptation_);
document.getElementById('videoTracks').addEventListener(
'change', shakaDemo.onTrackSelected_);
document.getElementById('audioTracks').addEventListener(
document.getElementById('variantTracks').addEventListener(
'change', shakaDemo.onTrackSelected_);
document.getElementById('textTracks').addEventListener(
'change', shakaDemo.onTrackSelected_);
Expand All @@ -43,18 +41,17 @@ shakaDemo.setupInfo_ = function() {
shakaDemo.onTracksChanged_ = function(event) {
// Update the track lists.
var lists = {
video: document.getElementById('videoTracks'),
audio: document.getElementById('audioTracks'),
variant: document.getElementById('variantTracks'),
text: document.getElementById('textTracks')
};
var formatters = {
video: function(track) {
return track.width + 'x' + track.height + ', ' +
track.bandwidth + ' bits/s';
},
audio: function(track) {
return 'language: ' + track.language + ', ' +
track.bandwidth + ' bits/s';
variant: function(track) {
var trackInfo = '';
if (track.language) trackInfo += 'language: ' + track.language + ', ';
if (track.width && track.height)
trackInfo += track.width + 'x' + track.height + ', ';
trackInfo += track.bandwidth + ' bits/s';
return trackInfo;
},
text: function(track) {
return 'language: ' + track.language + ' ' +
Expand Down Expand Up @@ -99,8 +96,7 @@ shakaDemo.onTracksChanged_ = function(event) {
*/
shakaDemo.onAdaptation_ = function(event) {
var lists = {
video: document.getElementById('videoTracks'),
audio: document.getElementById('audioTracks'),
variant: document.getElementById('variantTracks'),
text: document.getElementById('textTracks')
};

Expand Down
29 changes: 24 additions & 5 deletions externs/shaka/abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,34 @@ shakaExtern.AbrManager.prototype.init = function(switchCallback) {};


/**
* Chooses one Stream from each StreamSet to switch to. All StreamSets must be
* from the same Period. Some StreamSets may be absent in the case of language
* changes.
* Updates manager's variants collection.
*
* @param {!Object.<string, !shakaExtern.StreamSet>} streamSetsByType
* @param {!Array.<!shakaExtern.Variant>} variants
* @exportDoc
*/
shakaExtern.AbrManager.prototype.setVariants = function(variants) {};


/**
* Updates manager's text streams collection.
*
* @param {!Array.<!shakaExtern.Stream>} streams
* @exportDoc
*/
shakaExtern.AbrManager.prototype.setTextStreams = function(streams) {};


/**
* Chooses one Stream from each media type in mediaTypesToUpdate to switch to.
* All Variants and Streams must be from the same Period.
*
* @param {!Array.<!string>} mediaTypesToUpdate
* @return {!Object.<string, shakaExtern.Stream>}
* @exportDoc
*/
shakaExtern.AbrManager.prototype.chooseStreams = function(streamSetsByType) {};
// TODO: Consider breaking down into chooseVariant() and chooseText()
shakaExtern.AbrManager.prototype.chooseStreams =
function(mediaTypesToUpdate) {};


/**
Expand Down
91 changes: 55 additions & 36 deletions externs/shaka/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
*
* <p>
* The presentation timeline is divided into one or more Periods, and each of
* these Periods contains its own collection of streams. Periods group their
* streams by type (e.g., 'audio', 'video', or 'text') and logical content, and
* each individual group defines a StreamSet.
* these Periods contains its own collection of Variants and text streams.
* Variant is a combination of an audio and a video streams that can be played
* together.
* </p>
*
* <p>
Expand Down Expand Up @@ -84,7 +84,8 @@ shakaExtern.Manifest;
/**
* @typedef {{
* startTime: number,
* streamSets: !Array.<shakaExtern.StreamSet>
* variants: !Array.<shakaExtern.Variant>,
* textStreams: !Array.<shakaExtern.Stream>
* }}
*
* @description
Expand All @@ -97,9 +98,12 @@ shakaExtern.Manifest;
* presentation. The Period ends immediately before the next Period's start
* time or exactly at the end of the presentation timeline. Periods which
* begin after the end of the presentation timeline are ignored.
* @property {!Array.<shakaExtern.StreamSet>} streamSets
* @property {!Array.<shakaExtern.Variant>} variants
* <i>Required.</i> <br>
* The Period's StreamSets. There must be at least one StreamSet.
* The Period's Variants. There must be at least one Variant.
* @property {!Array.<shakaExtern.Stream>} textStreams
* <i>Required.</i> <br>
* The Period's text streams.
*
* @exportDoc
*/
Expand Down Expand Up @@ -185,43 +189,57 @@ shakaExtern.DrmInfo;

/**
* @typedef {{
* id: number,
* language: string,
* type: string,
* primary: boolean,
* drmInfos: Array.<!shakaExtern.DrmInfo>,
* streams: !Array.<!shakaExtern.Stream>
* audio: ?shakaExtern.Stream,
* video: ?shakaExtern.Stream,
* bandwidth: number,
* drmInfos: !Array.<!shakaExtern.DrmInfo>,
* allowedByApplication: boolean,
* allowedByKeySystem: boolean
* }}
*
* @description
* A StreamSet object contains a set of Streams which have the same type,
* container/format, and logical content. A StreamSet's type and
* container/format define its MIME type.
* A Variant describes a combination of an audio and video streams which
* could be played together. It's possible to have a video/audio only
* variant.
*
* @property {number} id
* <i>Required.</i> <br>
* A unique ID among all Variant objects within the same Manifest.
* @property {string} language
* <i>Defaults to '' (i.e., unknown).</i> <br>
* The Streams' language, specified as a language code. <br>
* The Variant's language, specified as a language code. <br>
* See {@link https://tools.ietf.org/html/rfc5646} <br>
* See {@link http://www.iso.org/iso/home/standards/language_codes.htm}
* @property {string} type
* <i>Required.</i> <br>
* The Streams' type, e.g., 'audio', 'video', or 'text'.
* @property {boolean} primary
* <i>Defaults to false.</i> <br>
* True indicates that the player should use this StreamSet over others of
* the same type in the same Period. However, the player may use another
* StreamSet to meet application preferences, or to achieve better MIME type
* or DRM compatibility among other StreamSets.
* @property {Array.<!shakaExtern.DrmInfo>} drmInfos
* True indicates that the player should use this Variant over others of
* the in the same Period. However, the player may use another
* Variant to meet application preferences.
* @property {?shakaExtern.Stream} audio
* The audio stream of the variant.
* @property {?shakaExtern.Stream} video
* The video stream of the variant.
* @property {number} bandwidth
* The variant's required bandwidth in bits per second.
* @property {!Array.<!shakaExtern.DrmInfo>} drmInfos
* <i>Defaults to [] (i.e., no DRM).</i> <br>
* An array of DrmInfo objects which describe DRM schemes are compatible with
* the content.
* @property {!Array.<!shakaExtern.Stream>} streams
* <i>Required.</i> <br>
* The StreamSets's Streams. There must be at least one Stream.
* @property {boolean} allowedByApplication
* <i>Defaults to true.</i><br>
* Set by the Player to indicate whether the variant is allowed to be played
* by the application.
* @property {boolean} allowedByKeySystem
* <i>Defaults to true.</i><br>
* Set by the Player to indicate whether the variant is allowed to be played
* by the key system.
*
* @exportDoc
*/
shakaExtern.StreamSet;
shakaExtern.Variant;


/**
Expand Down Expand Up @@ -275,8 +293,8 @@ shakaExtern.GetSegmentReferenceFunction;
* encrypted: boolean,
* keyId: ?string,
* language: string,
* allowedByApplication: boolean,
* allowedByKeySystem: boolean
* type: string,
* primary: boolean
* }}
*
* @description
Expand Down Expand Up @@ -345,15 +363,16 @@ shakaExtern.GetSegmentReferenceFunction;
* stream.
* @property {string} language
* The Stream's language, specified as a language code. <br>
* Must be identical to the language of the containing StreamSet.
* @property {boolean} allowedByApplication
* <i>Defaults to true.</i><br>
* Set by the Player to indicate whether the stream is allowed to be played
* by the application.
* @property {boolean} allowedByKeySystem
* <i>Defaults to true.</i><br>
* Set by the Player to indicate whether the stream is allowed to be played
* by the key system.
* Audio stream's language must be identical to the language of the containing
* Variant.
* @property {string} type
* <i>Required.</i> <br>
* Content type (e.g. 'video', 'audio' or 'text')
* @property {boolean} primary
* <i>Defaults to false.</i> <br>
* True indicates that the player should prefer this Stream over others
* in the same Period. However, the player may use another
* Stream to meet application preferences.
*
* @exportDoc
*/
Expand Down
5 changes: 4 additions & 1 deletion externs/shaka/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ shakaExtern.PeriodDB;
* initSegmentUri: ?string,
* encrypted: boolean,
* keyId: ?string,
* segments: !Array.<shakaExtern.SegmentDB>
* segments: !Array.<shakaExtern.SegmentDB>,
* variantIds: ?Array.<number>
* }}
*
* @property {number} id
Expand Down Expand Up @@ -179,6 +180,8 @@ shakaExtern.PeriodDB;
* The key ID this stream is encrypted with.
* @property {!Array.<shakaExtern.SegmentDB>} segments
* An array of segments that make up the stream
* @property {?Array.<number>} variantIds
* An array of ids of variants the stream is a part of.
*/
shakaExtern.StreamDB;

Expand Down
18 changes: 6 additions & 12 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ shakaExtern.Track;
* minPixels: number,
* maxPixels: number,
*
* minAudioBandwidth: number,
* maxAudioBandwidth: number,
* minVideoBandwidth: number,
* maxVideoBandwidth: number
* minBandwidth: number,
* maxBandwidth: number
* }}
*
* @description
Expand All @@ -174,14 +172,10 @@ shakaExtern.Track;
* @property {number} maxPixels
* The maximum number of total pixels in a video track (i.e. width * height).
*
* @property {number} minAudioBandwidth
* The minimum bandwidth of an audio track, in bit/sec.
* @property {number} maxAudioBandwidth
* The maximum bandwidth of an audio track, in bit/sec.
* @property {number} minVideoBandwidth
* The minimum bandwidth of a video track, in bit/sec.
* @property {number} maxVideoBandwidth
* The maximum bandwidth of a video track, in bit/sec.
* @property {number} minBandwidth
* The minimum bandwidth of a variant track, in bit/sec.
* @property {number} maxBandwidth
* The maximum bandwidth of a variant track, in bit/sec.
* @exportDoc
*/
shakaExtern.Restrictions;
Expand Down
Loading

0 comments on commit e95d7b9

Please sign in to comment.