Files
shaka-player/lib/offline/stored_content_utils.js
T
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00

120 lines
3.3 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.offline.StoredContentUtils');
goog.require('goog.asserts');
goog.require('shaka.offline.ManifestConverter');
goog.require('shaka.offline.OfflineUri');
goog.require('shaka.util.StreamUtils');
/**
* A utility class used to create |shaka.extern.StoredContent| from different
* types of input.
*/
shaka.offline.StoredContentUtils = class {
/**
* @param {string} originalUri
* @param {shaka.extern.Manifest} manifest
* @param {number} size
* @param {!Object} metadata
* @return {shaka.extern.StoredContent}
*/
static fromManifest(originalUri, manifest, size, metadata) {
goog.asserts.assert(
manifest.variants.length,
'Cannot create stored content from manifest with no variants.');
/** @type {number} */
const duration = manifest.presentationTimeline.getDuration();
/** @type {!Array.<shaka.extern.Track>} */
const tracks = shaka.offline.StoredContentUtils.getTracks_(manifest);
/** @type {shaka.extern.StoredContent} */
const content = {
offlineUri: null,
originalManifestUri: originalUri,
duration: duration,
size: size,
// This expiration value is temporary and will be used in progress reports
// during the storage process. The real value would have to come from
// DrmEngine.
expiration: Infinity,
tracks: tracks,
appMetadata: metadata,
};
return content;
}
/**
* @param {!shaka.offline.OfflineUri} offlineUri
* @param {shaka.extern.ManifestDB} manifestDB
* @return {shaka.extern.StoredContent}
*/
static fromManifestDB(offlineUri, manifestDB) {
goog.asserts.assert(
manifestDB.streams.length,
'Cannot create stored content from manifestDB with no streams.');
const converter = new shaka.offline.ManifestConverter(
offlineUri.mechanism(), offlineUri.cell());
/** @type {shaka.extern.Manifest} */
const manifest = converter.fromManifestDB(manifestDB);
/** @type {!Object} */
const metadata = manifestDB.appMetadata || {};
/** @type {!Array.<shaka.extern.Track>} */
const tracks = shaka.offline.StoredContentUtils.getTracks_(manifest);
goog.asserts.assert(
manifestDB.expiration != null,
'Manifest expiration must be set by now!');
/** @type {shaka.extern.StoredContent} */
const content = {
offlineUri: offlineUri.toString(),
originalManifestUri: manifestDB.originalManifestUri,
duration: manifestDB.duration,
size: manifestDB.size,
expiration: manifestDB.expiration,
tracks: tracks,
appMetadata: metadata,
};
return content;
}
/**
* Gets track representations of all playable variants and all text streams.
*
* @param {shaka.extern.Manifest} manifest
* @return {!Array.<shaka.extern.Track>}
* @private
*/
static getTracks_(manifest) {
const StreamUtils = shaka.util.StreamUtils;
const tracks = [];
const variants = StreamUtils.getPlayableVariants(manifest.variants);
for (const variant of variants) {
tracks.push(StreamUtils.variantToTrack(variant));
}
const textStreams = manifest.textStreams;
for (const stream of textStreams) {
tracks.push(StreamUtils.textStreamToTrack(stream));
}
return tracks;
}
};