/**
* @license
* Copyright 2015 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.Error');
/**
* @param {shaka.util.Error.Category} category
* @param {shaka.util.Error.Code} code
* @param {...*} var_args
* @constructor
* @struct
* @export
*/
shaka.util.Error = function(category, code, var_args) {
/**
* @const {shaka.util.Error.Category}
* @expose
*/
this.category = category;
/**
* @const {shaka.util.Error.Code}
* @expose
*/
this.code = code;
/**
* @const {!Array.<*>}
* @expose
*/
this.data = Array.prototype.slice.call(arguments, 2);
// This improves formatting of Errors in failure messages in the tests.
if (!COMPILED) {
var categoryName = 'UNKNOWN';
var codeName = 'UNKNOWN';
for (var k in shaka.util.Error.Category) {
if (shaka.util.Error.Category[k] == this.category)
categoryName = k;
}
for (var k in shaka.util.Error.Code) {
if (shaka.util.Error.Code[k] == this.code)
codeName = k;
}
this.message = 'Shaka Error ' + categoryName + '.' + codeName +
' (' + this.data.toString() + ')';
try {
throw new Error(this.message);
} catch (e) {
this.stack = e.stack;
}
}
};
/** @return {string} */
shaka.util.Error.prototype.toString = function() {
return 'shaka.util.Error ' + JSON.stringify(this, null, ' ');
};
/**
* @enum {number}
* @export
*/
shaka.util.Error.Category = {
/** Errors from the network stack. */
'NETWORK': 1,
/** Errors parsing text streams. */
'TEXT': 2,
/** Errors parsing or processing audio or video streams. */
'MEDIA': 3,
/** Errors parsing the Manifest. */
'MANIFEST': 4,
/** Errors related to DRM. */
'DRM': 5
};
/**
* @enum {number}
* @export
*/
shaka.util.Error.Code = {
/**
* A network request was made using an unsupported URI scheme.
*
error.data[0] is the URI.
*/
'UNSUPPORTED_SCHEME': 1,
/**
* An HTTP network request returned an HTTP status that indicated a failure.
*
error.data[0] is the URI.
*
error.data[1] is the status code.
*/
'BAD_HTTP_STATUS': 2,
/**
* An HTTP network request failed with an error, but not from the server.
*
error.data[0] is the URI.
*/
'HTTP_ERROR': 3,
/**
* A network request timed out.
*
error.data[0] is the URI.
*/
'TIMEOUT': 4,
/**
* A network request was made with a malformed data URI.
*
error.data[0] is the URI.
*/
'MALFORMED_DATA_URI': 5,
/**
* A network request was made with a data URI using an unknown encoding.
*
error.data[0] is the URI.
*/
'UNKNOWN_DATA_URI_ENCODING': 6,
/** The text parser failed to parse a text stream due to an invalid header. */
'INVALID_TEXT_HEADER': 7,
/** The text parser failed to parse a text stream due to an invalid cue. */
'INVALID_TEXT_CUE': 8,
/**
* The text parser failed to parse a text stream due to invalid cue settings.
*/
'INVALID_TEXT_SETTINGS': 9,
/**
* Some component tried to read past the end of a buffer. The segment index,
* init segment, or PSSH may be malformed.
*/
'BUFFER_READ_OUT_OF_BOUNDS': 10,
/**
* Some component tried to parse an integer that was too large to fit in a
* JavaScript number without rounding error. JavaScript can only natively
* represent integers up to 53 bits.
*/
'JS_INTEGER_OVERFLOW': 11,
/**
* The EBML parser used to parse the WebM container encountered an integer,
* ID, or other field larger than the maximum supported by the parser.
*/
'EBML_OVERFLOW': 12,
/**
* The EBML parser used to parse the WebM container encountered a floating-
* point field of a size not supported by the parser.
*/
'EBML_BAD_FLOATING_POINT_SIZE': 13,
/**
* The MP4 SIDX parser found the wrong box type.
* Either the segment index range is incorrect or the data is corrupt.
*/
'MP4_SIDX_WRONG_BOX_TYPE': 14,
/**
* The MP4 SIDX parser encountered an invalid timescale.
* The segment index data may be corrupt.
*/
'MP4_SIDX_INVALID_TIMESCALE': 15,
/** The MP4 SIDX parser encountered a type of SIDX that is not supported. */
'MP4_SIDX_TYPE_NOT_SUPPORTED': 16,
/**
* The WebM Cues parser was unable to locate the Cues element.
* The segment index data may be corrupt.
*/
'WEBM_CUES_ELEMENT_MISSING': 17,
/**
* The WebM header parser was unable to locate the Ebml element.
* The init segment data may be corrupt.
*/
'WEBM_EBML_HEADER_ELEMENT_MISSING': 18,
/**
* The WebM header parser was unable to locate the Segment element.
* The init segment data may be corrupt.
*/
'WEBM_SEGMENT_ELEMENT_MISSING': 19,
/**
* The WebM header parser was unable to locate the Info element.
* The init segment data may be corrupt.
*/
'WEBM_INFO_ELEMENT_MISSING': 20,
/**
* The WebM header parser was unable to locate the Duration element.
* The init segment data may be corrupt or may have been incorrectly encoded.
* Shaka requires a duration in WebM DASH content.
*/
'WEBM_DURATION_ELEMENT_MISSING': 21,
/**
* The WebM Cues parser was unable to locate the Cue Track Positions element.
* The segment index data may be corrupt.
*/
'WEBM_CUE_TRACK_POSITIONS_ELEMENT_MISSING': 22,
/**
* The WebM Cues parser was unable to locate the Cue Time element.
* The segment index data may be corrupt.
*/
'WEBM_CUE_TIME_ELEMENT_MISSING': 23,
/** The DASH Manifest contained invalid XML markup. */
'DASH_INVALID_XML': 24,
/**
* The DASH Manifest contained a representation with no Segment info. This
* can occur if there are no Segment* in a Representation or if one of the
* Segment* elements do not contain enough Segment information.
*/
'DASH_NO_SEGMENT_INFO': 25,
/** The DASH Manifest contained an AdaptationSet with no Representations. */
'DASH_EMPTY_ADAPTATION_SET': 26,
/** The DASH Manifest contained an Period with no AdaptationSets. */
'DASH_EMPTY_PERIOD': 27,
/**
* The DASH Manifest does not specify an init segment with a WebM container.
*/
'DASH_WEBM_MISSING_INIT': 28,
/** The DASH Manifest contained an unsupported container format. */
'DASH_UNSUPPORTED_CONTAINER': 29,
/** The embedded PSSH data has invalid encoding. */
'DASH_PSSH_BAD_ENCODING': 30,
/**
* There is an AdaptationSet whose Representations do not have any common
* key-systems.
*/
'DASH_NO_COMMON_KEY_SYSTEM': 31,
/** Having multiple key IDs per Representation is not supported. */
'DASH_MULTIPLE_KEY_IDS_NOT_SUPPORTED': 32,
/** The DASH Manifest specifies conflicting key IDs. */
'DASH_CONFLICTING_KEY_IDS': 33,
/**
* The StreamingEngine appended a segment but the SourceBuffer is empty, or
* the StreamingEngine removed all segments and the SourceBuffer is
* non-empty.
*
* This is an unrecoverable error.
*
*
error.data[0] is the type of content which caused the error.
*/
'STREAMING_INCONSISTENT_BUFFER_STATE': 34,
/**
* The StreamingEngine cannot append the next segment because the segment's
* corresponding SegmentReference does not exist (i.e., findSegmentPosition()
* succeeded but getSegmentReference() failed) or the segment's corresponding
* SegmentReference has an invalid time range.
*
* This is a non-recoverable error.
*
*
error.data[0] is the type of content which caused the error.
*
error.data[1] is the index of the Period.
*
error.data[2] is the position of the segment.
*/
'STREAMING_INVALID_SEGMENT_INDEX': 35,
/**
* The StreamingEngine cannot append the next segment because the next
* segment does not exist (i.e., findSegmentPosition() failed). This can
* occur for three reasons:
* 1. there is positive drift (the segments' timestamps are ahead of
* the manifest's timestamps) and the playhead is outside the drifted
* segment availability window.
* 2. the manifest is not updating fast enough for live presentations; or
* 3. the manifest is not complete.
* The first case is a recoverable error; recovery may be attempted by
* repositioning the playhead and then invoking StreamingEngine.seeked().
*
*
error.data[0] is the type of content which caused the error.
*
error.data[1] is the index of the Period.
*
error.data[2] is the timestamp needed.
*/
'STREAMING_SEGMENT_DOES_NOT_EXIST': 36,
/**
* The StreamingEngine cannot append the next segment because doing so
* would exceed the byte limit.
*
* This is a recoverable error; recovery may be attempted by adjusting the
* byte limit and then invoking StreamingEngine.switch().
*
*
error.data[0] is the type of content which caused the error.
*/
'STREAMING_CANNOT_SATISFY_BYTE_LIMIT': 37,
/**
* The StreamingEngine inserted a media segment, but the segment did not
* contain any actual media content.
*
* This is likely a non-recoverable error; however, recovery may be attempted
* by invoking StreamingEngine.switch().
*
*
error.data[0] is the type of content which caused the error.
*/
'STREAMING_BAD_SEGMENT': 38,
/**
* The Player was unable to guess the manifest type based on file extension
* or MIME type. To fix, try one of the following:
*