Skip to content

Commit

Permalink
Isolate Util Method To Be Near Usage
Browse files Browse the repository at this point in the history
There was a stream utilty was that only be used in one class
(another utility class). The method was to get tracks, but it
sat along side other methods that look similar but were different
in very small ways.

This change moves that function to be in the same class as where
it is used so that it will be less distracting from the other
getTrack methods.

Change-Id: I21737b6b1341c06b41e6016e24b2b20ce5d40e77
  • Loading branch information
vaage committed Aug 31, 2018
1 parent 49c7c0c commit 0310c78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
30 changes: 28 additions & 2 deletions lib/offline/stored_content_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ shaka.offline.StoredContentUtils = class {
let firstPeriod = manifest.periods[0];

/** @type {!Array.<shaka.extern.Track>} */
let tracks = shaka.util.StreamUtils.getTracks(firstPeriod);
let tracks = shaka.offline.StoredContentUtils.getTracks_(firstPeriod);

/** @type {shaka.extern.StoredContent} */
let content = {
Expand Down Expand Up @@ -96,7 +96,7 @@ shaka.offline.StoredContentUtils = class {
let metadata = manifestDB.appMetadata || {};

/** @type {!Array.<shaka.extern.Track>} */
let tracks = shaka.util.StreamUtils.getTracks(firstPeriod);
let tracks = shaka.offline.StoredContentUtils.getTracks_(firstPeriod);

/** @type {shaka.extern.StoredContent} */
let content = {
Expand All @@ -111,4 +111,30 @@ shaka.offline.StoredContentUtils = class {

return content;
}


/**
* Gets track representations of all playable variants and all text streams.
*
* @param {shaka.extern.Period} period
* @return {!Array.<shaka.extern.Track>}
* @private
*/
static getTracks_(period) {
const StreamUtils = shaka.util.StreamUtils;

const tracks = [];

const variants = StreamUtils.getPlayableVariants(period.variants);
for (const variant of variants) {
tracks.push(StreamUtils.variantToTrack(variant));
}

const textStreams = period.textStreams;
for (const stream of textStreams) {
tracks.push(StreamUtils.textStreamToTrack(stream));
}

return tracks;
}
};
26 changes: 0 additions & 26 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,32 +350,6 @@ shaka.util.StreamUtils.textStreamToTrack = function(stream) {
};


/**
* Gets track representations of all playable variants and all text streams.
*
* @param {shaka.extern.Period} period
* @return {!Array.<shaka.extern.Track>}
*/
shaka.util.StreamUtils.getTracks = function(period) {
const StreamUtils = shaka.util.StreamUtils;

let tracks = [];

let variants = StreamUtils.getPlayableVariants(period.variants);
let textStreams = period.textStreams;

variants.forEach(function(variant) {
tracks.push(StreamUtils.variantToTrack(variant));
});

textStreams.forEach(function(stream) {
tracks.push(StreamUtils.textStreamToTrack(stream));
});

return tracks;
};


/**
* Gets an array of Track objects for the given Period.
*
Expand Down

0 comments on commit 0310c78

Please sign in to comment.