Skip to content

Commit

Permalink
Make HlsParser.getRequiredAttributeValue_ static
Browse files Browse the repository at this point in the history
This will allow me to use it outside of prototype methods in an
upcoming change.

Issue #279

Change-Id: Iaa7c9a92787d0f33b86dc1ba823f750aa268b9b1
  • Loading branch information
joeyparrish committed Mar 30, 2017
1 parent fb84124 commit 3dfc61a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ shaka.hls.HlsParser.prototype.createPeriod_ = function(playlist) {

var mediaTags = Utils.filterTagsByName(playlist.tags, 'EXT-X-MEDIA');
var textStreamTags = mediaTags.filter(function(tag) {
var type = this.getRequiredAttributeValue_(tag, 'TYPE');
var type = shaka.hls.HlsParser.getRequiredAttributeValue_(tag, 'TYPE');
return type == 'SUBTITLES';
}.bind(this));

Expand Down Expand Up @@ -213,10 +213,12 @@ shaka.hls.HlsParser.prototype.createVariantsForTag_ = function(tag, playlist) {
goog.asserts.assert(tag.name == 'EXT-X-STREAM-INF',
'Should only be called on variant tags!');
var ContentType = shaka.util.ManifestParserUtils.ContentType;
var HlsParser = shaka.hls.HlsParser;
var Utils = shaka.hls.Utils;
var bandwidth = Number(this.getRequiredAttributeValue_(tag, 'BANDWIDTH'));
var bandwidth =
Number(HlsParser.getRequiredAttributeValue_(tag, 'BANDWIDTH'));

var codecs = this.getRequiredAttributeValue_(tag, 'CODECS').split(',');
var codecs = HlsParser.getRequiredAttributeValue_(tag, 'CODECS').split(',');
var resolutionAttr = tag.getAttribute('RESOLUTION');
var width;
var height;
Expand Down Expand Up @@ -396,7 +398,7 @@ shaka.hls.HlsParser.prototype.createTextStream_ = function(tag, playlist) {
goog.asserts.assert(tag.name == 'EXT-X-MEDIA',
'Should only be called on media tags!');

var type = this.getRequiredAttributeValue_(tag, 'TYPE');
var type = shaka.hls.HlsParser.getRequiredAttributeValue_(tag, 'TYPE');
goog.asserts.assert(type == 'SUBTITLES',
'Should only be called on tags with TYPE="SUBTITLES"!');

Expand Down Expand Up @@ -430,7 +432,8 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ =
}.bind(this));
}

var type = this.getRequiredAttributeValue_(tag, 'TYPE').toLowerCase();
var HlsParser = shaka.hls.HlsParser;
var type = HlsParser.getRequiredAttributeValue_(tag, 'TYPE').toLowerCase();
// Shaka recognizes content types 'audio', 'video' and 'text'.
// HLS 'subtitles' type needs to be mapped to 'text'.
var ContentType = shaka.util.ManifestParserUtils.ContentType;
Expand All @@ -447,7 +450,7 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ =
// Attribute descriptions:
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-4.3.4.1

var uri = this.getRequiredAttributeValue_(tag, 'URI');
var uri = HlsParser.getRequiredAttributeValue_(tag, 'URI');
var primary = !!defaultAttr || !!autoselectAttr;
return this.createStreamInfo_(uri, allCodecs, type, timeOffset, language,
primary).then(function(streamInfo) {
Expand All @@ -472,7 +475,7 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromVariantTag_ =
goog.asserts.assert(tag.name == 'EXT-X-STREAM-INF',
'Should only be called on media tags!');

var uri = this.getRequiredAttributeValue_(tag, 'URI');
var uri = shaka.hls.HlsParser.getRequiredAttributeValue_(tag, 'URI');
return this.createStreamInfo_(uri, allCodecs, type, timeOffset,
/* language */ 'und', /* primary */ false);
};
Expand All @@ -493,6 +496,7 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ =
function(uri, allCodecs, type, timeOffset, language, primary) {
var Utils = shaka.hls.Utils;
var ContentType = shaka.util.ManifestParserUtils.ContentType;
var HlsParser = shaka.hls.HlsParser;
uri = Utils.constructAbsoluteUri(this.manifestUri_, uri);

return this.requestManifest_(uri).then(function(response) {
Expand Down Expand Up @@ -549,15 +553,17 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ =
var drmInfo = null;
var drmTag = Utils.getFirstTagWithName(playlist.tags, 'EXT-X-KEY');
if (drmTag) {
var method = this.getRequiredAttributeValue_(drmTag, 'METHOD');
var method = HlsParser.getRequiredAttributeValue_(drmTag, 'METHOD');
if (method != 'NONE') {
// TODO: throw an error if a method we can't support is encountered
var keyFormat = this.getRequiredAttributeValue_(drmTag, 'KEYFORMAT');
var keyFormat =
HlsParser.getRequiredAttributeValue_(drmTag, 'KEYFORMAT');
var keySystem =
shaka.hls.HlsParser.KEYFORMATS_TO_EME_KEYSYSTEM_IDS_[keyFormat] ||
'';
drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(keySystem, []);
var licenseServerUri = this.getRequiredAttributeValue_(drmTag, 'URI');
var licenseServerUri =
HlsParser.getRequiredAttributeValue_(drmTag, 'URI');
drmInfo.licenseServerUri = licenseServerUri;
}
}
Expand Down Expand Up @@ -619,7 +625,7 @@ shaka.hls.HlsParser.prototype.createInitSegmentReference_ = function(playlist) {

// Map tag example: #EXT-X-MAP:URI="main.mp4",BYTERANGE="720@0"
var mapTag = mapTags[0];
var initUri = this.getRequiredAttributeValue_(mapTag, 'URI');
var initUri = shaka.hls.HlsParser.getRequiredAttributeValue_(mapTag, 'URI');
var uri = Utils.constructAbsoluteUri(playlist.uri, initUri);
var startByte = 0;
var endByte = null;
Expand Down Expand Up @@ -818,7 +824,8 @@ shaka.hls.HlsParser.prototype.getTimeOffset_ = function(playlist) {
// TODO: Should we respect the PRECISE flag?
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-4.3.5.2
if (startTag)
return Number(this.getRequiredAttributeValue_(startTag, 'TIME-OFFSET'));
return Number(shaka.hls.HlsParser.getRequiredAttributeValue_(
startTag, 'TIME-OFFSET'));

return this.config_.hls.defaultTimeOffset;
};
Expand All @@ -834,7 +841,7 @@ shaka.hls.HlsParser.prototype.getTimeOffset_ = function(playlist) {
* @private
* @throws {shaka.util.Error}
*/
shaka.hls.HlsParser.prototype.getRequiredAttributeValue_ =
shaka.hls.HlsParser.getRequiredAttributeValue_ =
function(tag, attributeName) {
var attribute = tag.getAttribute(attributeName);
if (!attribute) {
Expand Down

0 comments on commit 3dfc61a

Please sign in to comment.