Files
shaka-player/lib/util/manifest_parser_utils.js
T
Sandra Lokshina 01d6458422 Prepeare HLS parser for supporting encrypted content.
This change enables HLS parser to get DRM information
from the manifest and create DrmInfo objects.
Note that until we actually add support for any of the
drm systems, we will still reject encrypted content.

Issue #279.

Change-Id: I4d0652411a567bc75d919c5bf732f20e870a5aeb
2017-03-29 17:33:12 +00:00

105 lines
2.8 KiB
JavaScript

/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
goog.provide('shaka.util.ManifestParserUtils');
goog.require('goog.Uri');
goog.require('shaka.util.Functional');
/**
* @namespace shaka.util.ManifestParserUtils
* @summary Utility functions for manifest parsing.
*/
/**
* Resolves an array of relative URIs to the given base URIs. This will result
* in M*N number of URIs.
*
* @param {!Array.<string>} baseUris
* @param {!Array.<string>} relativeUris
* @return {!Array.<string>}
*/
shaka.util.ManifestParserUtils.resolveUris = function(baseUris, relativeUris) {
var Functional = shaka.util.Functional;
if (relativeUris.length == 0)
return baseUris;
var relativeAsGoog =
relativeUris.map(function(uri) { return new goog.Uri(uri); });
// Resolve each URI relative to each base URI, creating an Array of Arrays.
// Then flatten the Arrays into a single Array.
return baseUris.map(function(uri) { return new goog.Uri(uri); })
.map(function(base) { return relativeAsGoog.map(base.resolve.bind(base)); })
.reduce(Functional.collapseArrays, [])
.map(function(uri) { return uri.toString(); });
};
/**
* Creates a DrmInfo object from the given info.
*
* @param {string} keySystem
* @param {Array.<shakaExtern.InitDataOverride>} initData
* @return {shakaExtern.DrmInfo}
*/
shaka.util.ManifestParserUtils.createDrmInfo = function(keySystem, initData) {
return {
keySystem: keySystem,
licenseServerUri: '',
distinctiveIdentifierRequired: false,
persistentStateRequired: false,
audioRobustness: '',
videoRobustness: '',
serverCertificate: null,
initData: initData || [],
keyIds: []
};
};
/**
* @enum {string}
*/
shaka.util.ManifestParserUtils.ContentType = {
VIDEO: 'video',
AUDIO: 'audio',
TEXT: 'text',
APPLICATION: 'application'
};
/**
* @enum {string}
*/
shaka.util.ManifestParserUtils.TextStreamKind = {
SUBTITLE: 'subtitle',
CLOSED_CAPTION: 'caption'
};
/**
* Specifies how tolerant the player is to inaccurate segment start times and
* end times within a manifest. For example, gaps or overlaps between segments
* in a SegmentTimeline which are greater than or equal to this value will
* result in a warning message.
*
* @const {number}
*/
shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS = 1 / 15;