1 |
|
2 | (function (global, factory) {
|
3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('video.js'), require('@xmldom/xmldom')) :
|
4 | typeof define === 'function' && define.amd ? define(['exports', 'video.js', '@xmldom/xmldom'], factory) :
|
5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.httpStreaming = {}, global.videojs, global.window));
|
6 | })(this, (function (exports, videojs, xmldom) { 'use strict';
|
7 |
|
8 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
9 |
|
10 | var videojs__default = _interopDefaultLegacy(videojs);
|
11 |
|
12 | function createCommonjsModule(fn, basedir, module) {
|
13 | return module = {
|
14 | path: basedir,
|
15 | exports: {},
|
16 | require: function (path, base) {
|
17 | return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
18 | }
|
19 | }, fn(module, module.exports), module.exports;
|
20 | }
|
21 |
|
22 | function commonjsRequire () {
|
23 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
24 | }
|
25 |
|
26 | var assertThisInitialized = createCommonjsModule(function (module) {
|
27 | function _assertThisInitialized(self) {
|
28 | if (self === void 0) {
|
29 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
30 | }
|
31 |
|
32 | return self;
|
33 | }
|
34 |
|
35 | module.exports = _assertThisInitialized;
|
36 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
37 | });
|
38 |
|
39 | var setPrototypeOf = createCommonjsModule(function (module) {
|
40 | function _setPrototypeOf(o, p) {
|
41 | module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
42 | o.__proto__ = p;
|
43 | return o;
|
44 | };
|
45 |
|
46 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
47 | return _setPrototypeOf(o, p);
|
48 | }
|
49 |
|
50 | module.exports = _setPrototypeOf;
|
51 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
52 | });
|
53 |
|
54 | var inheritsLoose = createCommonjsModule(function (module) {
|
55 | function _inheritsLoose(subClass, superClass) {
|
56 | subClass.prototype = Object.create(superClass.prototype);
|
57 | subClass.prototype.constructor = subClass;
|
58 | setPrototypeOf(subClass, superClass);
|
59 | }
|
60 |
|
61 | module.exports = _inheritsLoose;
|
62 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
63 | });
|
64 |
|
65 | var urlToolkit = createCommonjsModule(function (module, exports) {
|
66 |
|
67 | (function (root) {
|
68 | var URL_REGEX = /^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#[^]*)?$/;
|
69 | var FIRST_SEGMENT_REGEX = /^([^\/?#]*)([^]*)$/;
|
70 | var SLASH_DOT_REGEX = /(?:\/|^)\.(?=\/)/g;
|
71 | var SLASH_DOT_DOT_REGEX = /(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g;
|
72 | var URLToolkit = {
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | buildAbsoluteURL: function buildAbsoluteURL(baseURL, relativeURL, opts) {
|
80 | opts = opts || {};
|
81 |
|
82 | baseURL = baseURL.trim();
|
83 | relativeURL = relativeURL.trim();
|
84 |
|
85 | if (!relativeURL) {
|
86 |
|
87 |
|
88 |
|
89 | if (!opts.alwaysNormalize) {
|
90 | return baseURL;
|
91 | }
|
92 |
|
93 | var basePartsForNormalise = URLToolkit.parseURL(baseURL);
|
94 |
|
95 | if (!basePartsForNormalise) {
|
96 | throw new Error('Error trying to parse base URL.');
|
97 | }
|
98 |
|
99 | basePartsForNormalise.path = URLToolkit.normalizePath(basePartsForNormalise.path);
|
100 | return URLToolkit.buildURLFromParts(basePartsForNormalise);
|
101 | }
|
102 |
|
103 | var relativeParts = URLToolkit.parseURL(relativeURL);
|
104 |
|
105 | if (!relativeParts) {
|
106 | throw new Error('Error trying to parse relative URL.');
|
107 | }
|
108 |
|
109 | if (relativeParts.scheme) {
|
110 |
|
111 |
|
112 | if (!opts.alwaysNormalize) {
|
113 | return relativeURL;
|
114 | }
|
115 |
|
116 | relativeParts.path = URLToolkit.normalizePath(relativeParts.path);
|
117 | return URLToolkit.buildURLFromParts(relativeParts);
|
118 | }
|
119 |
|
120 | var baseParts = URLToolkit.parseURL(baseURL);
|
121 |
|
122 | if (!baseParts) {
|
123 | throw new Error('Error trying to parse base URL.');
|
124 | }
|
125 |
|
126 | if (!baseParts.netLoc && baseParts.path && baseParts.path[0] !== '/') {
|
127 |
|
128 |
|
129 | var pathParts = FIRST_SEGMENT_REGEX.exec(baseParts.path);
|
130 | baseParts.netLoc = pathParts[1];
|
131 | baseParts.path = pathParts[2];
|
132 | }
|
133 |
|
134 | if (baseParts.netLoc && !baseParts.path) {
|
135 | baseParts.path = '/';
|
136 | }
|
137 |
|
138 | var builtParts = {
|
139 |
|
140 |
|
141 | scheme: baseParts.scheme,
|
142 | netLoc: relativeParts.netLoc,
|
143 | path: null,
|
144 | params: relativeParts.params,
|
145 | query: relativeParts.query,
|
146 | fragment: relativeParts.fragment
|
147 | };
|
148 |
|
149 | if (!relativeParts.netLoc) {
|
150 |
|
151 |
|
152 |
|
153 | builtParts.netLoc = baseParts.netLoc;
|
154 |
|
155 |
|
156 | if (relativeParts.path[0] !== '/') {
|
157 | if (!relativeParts.path) {
|
158 |
|
159 |
|
160 | builtParts.path = baseParts.path;
|
161 |
|
162 |
|
163 |
|
164 | if (!relativeParts.params) {
|
165 | builtParts.params = baseParts.params;
|
166 |
|
167 |
|
168 |
|
169 | if (!relativeParts.query) {
|
170 | builtParts.query = baseParts.query;
|
171 | }
|
172 | }
|
173 | } else {
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | var baseURLPath = baseParts.path;
|
179 | var newPath = baseURLPath.substring(0, baseURLPath.lastIndexOf('/') + 1) + relativeParts.path;
|
180 | builtParts.path = URLToolkit.normalizePath(newPath);
|
181 | }
|
182 | }
|
183 | }
|
184 |
|
185 | if (builtParts.path === null) {
|
186 | builtParts.path = opts.alwaysNormalize ? URLToolkit.normalizePath(relativeParts.path) : relativeParts.path;
|
187 | }
|
188 |
|
189 | return URLToolkit.buildURLFromParts(builtParts);
|
190 | },
|
191 | parseURL: function parseURL(url) {
|
192 | var parts = URL_REGEX.exec(url);
|
193 |
|
194 | if (!parts) {
|
195 | return null;
|
196 | }
|
197 |
|
198 | return {
|
199 | scheme: parts[1] || '',
|
200 | netLoc: parts[2] || '',
|
201 | path: parts[3] || '',
|
202 | params: parts[4] || '',
|
203 | query: parts[5] || '',
|
204 | fragment: parts[6] || ''
|
205 | };
|
206 | },
|
207 | normalizePath: function normalizePath(path) {
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | path = path.split('').reverse().join('').replace(SLASH_DOT_REGEX, '');
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 | while (path.length !== (path = path.replace(SLASH_DOT_DOT_REGEX, '')).length) {}
|
224 |
|
225 | return path.split('').reverse().join('');
|
226 | },
|
227 | buildURLFromParts: function buildURLFromParts(parts) {
|
228 | return parts.scheme + parts.netLoc + parts.path + parts.params + parts.query + parts.fragment;
|
229 | }
|
230 | };
|
231 | module.exports = URLToolkit;
|
232 | })();
|
233 | });
|
234 |
|
235 | var DEFAULT_LOCATION = 'http://example.com';
|
236 |
|
237 | var resolveUrl$1 = function resolveUrl(baseUrl, relativeUrl) {
|
238 |
|
239 | if (/^[a-z]+:/i.test(relativeUrl)) {
|
240 | return relativeUrl;
|
241 | }
|
242 |
|
243 |
|
244 | if (/^data:/.test(baseUrl)) {
|
245 | baseUrl = window.location && window.location.href || '';
|
246 | }
|
247 |
|
248 |
|
249 |
|
250 | var nativeURL = typeof window.URL === 'function';
|
251 | var protocolLess = /^\/\//.test(baseUrl);
|
252 |
|
253 |
|
254 | var removeLocation = !window.location && !/\/\//i.test(baseUrl);
|
255 |
|
256 | if (nativeURL) {
|
257 | baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION);
|
258 | } else if (!/\/\//i.test(baseUrl)) {
|
259 | baseUrl = urlToolkit.buildAbsoluteURL(window.location && window.location.href || '', baseUrl);
|
260 | }
|
261 |
|
262 | if (nativeURL) {
|
263 | var newUrl = new URL(relativeUrl, baseUrl);
|
264 |
|
265 |
|
266 |
|
267 | if (removeLocation) {
|
268 | return newUrl.href.slice(DEFAULT_LOCATION.length);
|
269 | } else if (protocolLess) {
|
270 | return newUrl.href.slice(newUrl.protocol.length);
|
271 | }
|
272 |
|
273 | return newUrl.href;
|
274 | }
|
275 |
|
276 | return urlToolkit.buildAbsoluteURL(baseUrl, relativeUrl);
|
277 | };
|
278 |
|
279 | |
280 |
|
281 |
|
282 | var resolveUrl = resolveUrl$1;
|
283 | |
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 | var resolveManifestRedirect = function resolveManifestRedirect(handleManifestRedirect, url, req) {
|
296 |
|
297 |
|
298 |
|
299 | if (handleManifestRedirect && req && req.responseURL && url !== req.responseURL) {
|
300 | return req.responseURL;
|
301 | }
|
302 |
|
303 | return url;
|
304 | };
|
305 |
|
306 | var logger = function logger(source) {
|
307 | if (videojs__default["default"].log.debug) {
|
308 | return videojs__default["default"].log.debug.bind(videojs__default["default"], 'VHS:', source + " >");
|
309 | }
|
310 |
|
311 | return function () {};
|
312 | };
|
313 |
|
314 | var _extends_1 = createCommonjsModule(function (module) {
|
315 | function _extends() {
|
316 | module.exports = _extends = Object.assign || function (target) {
|
317 | for (var i = 1; i < arguments.length; i++) {
|
318 | var source = arguments[i];
|
319 |
|
320 | for (var key in source) {
|
321 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
322 | target[key] = source[key];
|
323 | }
|
324 | }
|
325 | }
|
326 |
|
327 | return target;
|
328 | };
|
329 |
|
330 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
331 | return _extends.apply(this, arguments);
|
332 | }
|
333 |
|
334 | module.exports = _extends;
|
335 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
336 | });
|
337 |
|
338 | |
339 |
|
340 |
|
341 |
|
342 | |
343 |
|
344 |
|
345 |
|
346 |
|
347 | var Stream = function () {
|
348 | function Stream() {
|
349 | this.listeners = {};
|
350 | }
|
351 | |
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | var _proto = Stream.prototype;
|
361 |
|
362 | _proto.on = function on(type, listener) {
|
363 | if (!this.listeners[type]) {
|
364 | this.listeners[type] = [];
|
365 | }
|
366 |
|
367 | this.listeners[type].push(listener);
|
368 | }
|
369 | |
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | ;
|
378 |
|
379 | _proto.off = function off(type, listener) {
|
380 | if (!this.listeners[type]) {
|
381 | return false;
|
382 | }
|
383 |
|
384 | var index = this.listeners[type].indexOf(listener);
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 | this.listeners[type] = this.listeners[type].slice(0);
|
394 | this.listeners[type].splice(index, 1);
|
395 | return index > -1;
|
396 | }
|
397 | |
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 | ;
|
404 |
|
405 | _proto.trigger = function trigger(type) {
|
406 | var callbacks = this.listeners[type];
|
407 |
|
408 | if (!callbacks) {
|
409 | return;
|
410 | }
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | if (arguments.length === 2) {
|
417 | var length = callbacks.length;
|
418 |
|
419 | for (var i = 0; i < length; ++i) {
|
420 | callbacks[i].call(this, arguments[1]);
|
421 | }
|
422 | } else {
|
423 | var args = Array.prototype.slice.call(arguments, 1);
|
424 | var _length = callbacks.length;
|
425 |
|
426 | for (var _i = 0; _i < _length; ++_i) {
|
427 | callbacks[_i].apply(this, args);
|
428 | }
|
429 | }
|
430 | }
|
431 | |
432 |
|
433 |
|
434 | ;
|
435 |
|
436 | _proto.dispose = function dispose() {
|
437 | this.listeners = {};
|
438 | }
|
439 | |
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 | ;
|
448 |
|
449 | _proto.pipe = function pipe(destination) {
|
450 | this.on('data', function (data) {
|
451 | destination.push(data);
|
452 | });
|
453 | };
|
454 |
|
455 | return Stream;
|
456 | }();
|
457 |
|
458 | var atob = function atob(s) {
|
459 | return window.atob ? window.atob(s) : Buffer.from(s, 'base64').toString('binary');
|
460 | };
|
461 |
|
462 | function decodeB64ToUint8Array(b64Text) {
|
463 | var decodedString = atob(b64Text);
|
464 | var array = new Uint8Array(decodedString.length);
|
465 |
|
466 | for (var i = 0; i < decodedString.length; i++) {
|
467 | array[i] = decodedString.charCodeAt(i);
|
468 | }
|
469 |
|
470 | return array;
|
471 | }
|
472 |
|
473 |
|
474 | |
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | var LineStream = function (_Stream) {
|
483 | inheritsLoose(LineStream, _Stream);
|
484 |
|
485 | function LineStream() {
|
486 | var _this;
|
487 |
|
488 | _this = _Stream.call(this) || this;
|
489 | _this.buffer = '';
|
490 | return _this;
|
491 | }
|
492 | |
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 | var _proto = LineStream.prototype;
|
500 |
|
501 | _proto.push = function push(data) {
|
502 | var nextNewline;
|
503 | this.buffer += data;
|
504 | nextNewline = this.buffer.indexOf('\n');
|
505 |
|
506 | for (; nextNewline > -1; nextNewline = this.buffer.indexOf('\n')) {
|
507 | this.trigger('data', this.buffer.substring(0, nextNewline));
|
508 | this.buffer = this.buffer.substring(nextNewline + 1);
|
509 | }
|
510 | };
|
511 |
|
512 | return LineStream;
|
513 | }(Stream);
|
514 |
|
515 | var TAB = String.fromCharCode(0x09);
|
516 |
|
517 | var parseByterange = function parseByterange(byterangeString) {
|
518 |
|
519 |
|
520 | var match = /([0-9.]*)?@?([0-9.]*)?/.exec(byterangeString || '');
|
521 | var result = {};
|
522 |
|
523 | if (match[1]) {
|
524 | result.length = parseInt(match[1], 10);
|
525 | }
|
526 |
|
527 | if (match[2]) {
|
528 | result.offset = parseInt(match[2], 10);
|
529 | }
|
530 |
|
531 | return result;
|
532 | };
|
533 | |
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 | var attributeSeparator = function attributeSeparator() {
|
543 | var key = '[^=]*';
|
544 | var value = '"[^"]*"|[^,]*';
|
545 | var keyvalue = '(?:' + key + ')=(?:' + value + ')';
|
546 | return new RegExp('(?:^|,)(' + keyvalue + ')');
|
547 | };
|
548 | |
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 | var parseAttributes$1 = function parseAttributes(attributes) {
|
556 |
|
557 | var attrs = attributes.split(attributeSeparator());
|
558 | var result = {};
|
559 | var i = attrs.length;
|
560 | var attr;
|
561 |
|
562 | while (i--) {
|
563 |
|
564 | if (attrs[i] === '') {
|
565 | continue;
|
566 | }
|
567 |
|
568 |
|
569 | attr = /([^=]*)=(.*)/.exec(attrs[i]).slice(1);
|
570 |
|
571 | attr[0] = attr[0].replace(/^\s+|\s+$/g, '');
|
572 | attr[1] = attr[1].replace(/^\s+|\s+$/g, '');
|
573 | attr[1] = attr[1].replace(/^['"](.*)['"]$/g, '$1');
|
574 | result[attr[0]] = attr[1];
|
575 | }
|
576 |
|
577 | return result;
|
578 | };
|
579 | |
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 | var ParseStream = function (_Stream) {
|
606 | inheritsLoose(ParseStream, _Stream);
|
607 |
|
608 | function ParseStream() {
|
609 | var _this;
|
610 |
|
611 | _this = _Stream.call(this) || this;
|
612 | _this.customParsers = [];
|
613 | _this.tagMappers = [];
|
614 | return _this;
|
615 | }
|
616 | |
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 | var _proto = ParseStream.prototype;
|
624 |
|
625 | _proto.push = function push(line) {
|
626 | var _this2 = this;
|
627 |
|
628 | var match;
|
629 | var event;
|
630 |
|
631 | line = line.trim();
|
632 |
|
633 | if (line.length === 0) {
|
634 |
|
635 | return;
|
636 | }
|
637 |
|
638 |
|
639 | if (line[0] !== '#') {
|
640 | this.trigger('data', {
|
641 | type: 'uri',
|
642 | uri: line
|
643 | });
|
644 | return;
|
645 | }
|
646 |
|
647 |
|
648 | var newLines = this.tagMappers.reduce(function (acc, mapper) {
|
649 | var mappedLine = mapper(line);
|
650 |
|
651 | if (mappedLine === line) {
|
652 | return acc;
|
653 | }
|
654 |
|
655 | return acc.concat([mappedLine]);
|
656 | }, [line]);
|
657 | newLines.forEach(function (newLine) {
|
658 | for (var i = 0; i < _this2.customParsers.length; i++) {
|
659 | if (_this2.customParsers[i].call(_this2, newLine)) {
|
660 | return;
|
661 | }
|
662 | }
|
663 |
|
664 |
|
665 | if (newLine.indexOf('#EXT') !== 0) {
|
666 | _this2.trigger('data', {
|
667 | type: 'comment',
|
668 | text: newLine.slice(1)
|
669 | });
|
670 |
|
671 | return;
|
672 | }
|
673 |
|
674 |
|
675 |
|
676 | newLine = newLine.replace('\r', '');
|
677 |
|
678 | match = /^#EXTM3U/.exec(newLine);
|
679 |
|
680 | if (match) {
|
681 | _this2.trigger('data', {
|
682 | type: 'tag',
|
683 | tagType: 'm3u'
|
684 | });
|
685 |
|
686 | return;
|
687 | }
|
688 |
|
689 | match = /^#EXTINF:?([0-9\.]*)?,?(.*)?$/.exec(newLine);
|
690 |
|
691 | if (match) {
|
692 | event = {
|
693 | type: 'tag',
|
694 | tagType: 'inf'
|
695 | };
|
696 |
|
697 | if (match[1]) {
|
698 | event.duration = parseFloat(match[1]);
|
699 | }
|
700 |
|
701 | if (match[2]) {
|
702 | event.title = match[2];
|
703 | }
|
704 |
|
705 | _this2.trigger('data', event);
|
706 |
|
707 | return;
|
708 | }
|
709 |
|
710 | match = /^#EXT-X-TARGETDURATION:?([0-9.]*)?/.exec(newLine);
|
711 |
|
712 | if (match) {
|
713 | event = {
|
714 | type: 'tag',
|
715 | tagType: 'targetduration'
|
716 | };
|
717 |
|
718 | if (match[1]) {
|
719 | event.duration = parseInt(match[1], 10);
|
720 | }
|
721 |
|
722 | _this2.trigger('data', event);
|
723 |
|
724 | return;
|
725 | }
|
726 |
|
727 | match = /^#EXT-X-VERSION:?([0-9.]*)?/.exec(newLine);
|
728 |
|
729 | if (match) {
|
730 | event = {
|
731 | type: 'tag',
|
732 | tagType: 'version'
|
733 | };
|
734 |
|
735 | if (match[1]) {
|
736 | event.version = parseInt(match[1], 10);
|
737 | }
|
738 |
|
739 | _this2.trigger('data', event);
|
740 |
|
741 | return;
|
742 | }
|
743 |
|
744 | match = /^#EXT-X-MEDIA-SEQUENCE:?(\-?[0-9.]*)?/.exec(newLine);
|
745 |
|
746 | if (match) {
|
747 | event = {
|
748 | type: 'tag',
|
749 | tagType: 'media-sequence'
|
750 | };
|
751 |
|
752 | if (match[1]) {
|
753 | event.number = parseInt(match[1], 10);
|
754 | }
|
755 |
|
756 | _this2.trigger('data', event);
|
757 |
|
758 | return;
|
759 | }
|
760 |
|
761 | match = /^#EXT-X-DISCONTINUITY-SEQUENCE:?(\-?[0-9.]*)?/.exec(newLine);
|
762 |
|
763 | if (match) {
|
764 | event = {
|
765 | type: 'tag',
|
766 | tagType: 'discontinuity-sequence'
|
767 | };
|
768 |
|
769 | if (match[1]) {
|
770 | event.number = parseInt(match[1], 10);
|
771 | }
|
772 |
|
773 | _this2.trigger('data', event);
|
774 |
|
775 | return;
|
776 | }
|
777 |
|
778 | match = /^#EXT-X-PLAYLIST-TYPE:?(.*)?$/.exec(newLine);
|
779 |
|
780 | if (match) {
|
781 | event = {
|
782 | type: 'tag',
|
783 | tagType: 'playlist-type'
|
784 | };
|
785 |
|
786 | if (match[1]) {
|
787 | event.playlistType = match[1];
|
788 | }
|
789 |
|
790 | _this2.trigger('data', event);
|
791 |
|
792 | return;
|
793 | }
|
794 |
|
795 | match = /^#EXT-X-BYTERANGE:?(.*)?$/.exec(newLine);
|
796 |
|
797 | if (match) {
|
798 | event = _extends_1(parseByterange(match[1]), {
|
799 | type: 'tag',
|
800 | tagType: 'byterange'
|
801 | });
|
802 |
|
803 | _this2.trigger('data', event);
|
804 |
|
805 | return;
|
806 | }
|
807 |
|
808 | match = /^#EXT-X-ALLOW-CACHE:?(YES|NO)?/.exec(newLine);
|
809 |
|
810 | if (match) {
|
811 | event = {
|
812 | type: 'tag',
|
813 | tagType: 'allow-cache'
|
814 | };
|
815 |
|
816 | if (match[1]) {
|
817 | event.allowed = !/NO/.test(match[1]);
|
818 | }
|
819 |
|
820 | _this2.trigger('data', event);
|
821 |
|
822 | return;
|
823 | }
|
824 |
|
825 | match = /^#EXT-X-MAP:?(.*)$/.exec(newLine);
|
826 |
|
827 | if (match) {
|
828 | event = {
|
829 | type: 'tag',
|
830 | tagType: 'map'
|
831 | };
|
832 |
|
833 | if (match[1]) {
|
834 | var attributes = parseAttributes$1(match[1]);
|
835 |
|
836 | if (attributes.URI) {
|
837 | event.uri = attributes.URI;
|
838 | }
|
839 |
|
840 | if (attributes.BYTERANGE) {
|
841 | event.byterange = parseByterange(attributes.BYTERANGE);
|
842 | }
|
843 | }
|
844 |
|
845 | _this2.trigger('data', event);
|
846 |
|
847 | return;
|
848 | }
|
849 |
|
850 | match = /^#EXT-X-STREAM-INF:?(.*)$/.exec(newLine);
|
851 |
|
852 | if (match) {
|
853 | event = {
|
854 | type: 'tag',
|
855 | tagType: 'stream-inf'
|
856 | };
|
857 |
|
858 | if (match[1]) {
|
859 | event.attributes = parseAttributes$1(match[1]);
|
860 |
|
861 | if (event.attributes.RESOLUTION) {
|
862 | var split = event.attributes.RESOLUTION.split('x');
|
863 | var resolution = {};
|
864 |
|
865 | if (split[0]) {
|
866 | resolution.width = parseInt(split[0], 10);
|
867 | }
|
868 |
|
869 | if (split[1]) {
|
870 | resolution.height = parseInt(split[1], 10);
|
871 | }
|
872 |
|
873 | event.attributes.RESOLUTION = resolution;
|
874 | }
|
875 |
|
876 | if (event.attributes.BANDWIDTH) {
|
877 | event.attributes.BANDWIDTH = parseInt(event.attributes.BANDWIDTH, 10);
|
878 | }
|
879 |
|
880 | if (event.attributes['PROGRAM-ID']) {
|
881 | event.attributes['PROGRAM-ID'] = parseInt(event.attributes['PROGRAM-ID'], 10);
|
882 | }
|
883 | }
|
884 |
|
885 | _this2.trigger('data', event);
|
886 |
|
887 | return;
|
888 | }
|
889 |
|
890 | match = /^#EXT-X-MEDIA:?(.*)$/.exec(newLine);
|
891 |
|
892 | if (match) {
|
893 | event = {
|
894 | type: 'tag',
|
895 | tagType: 'media'
|
896 | };
|
897 |
|
898 | if (match[1]) {
|
899 | event.attributes = parseAttributes$1(match[1]);
|
900 | }
|
901 |
|
902 | _this2.trigger('data', event);
|
903 |
|
904 | return;
|
905 | }
|
906 |
|
907 | match = /^#EXT-X-ENDLIST/.exec(newLine);
|
908 |
|
909 | if (match) {
|
910 | _this2.trigger('data', {
|
911 | type: 'tag',
|
912 | tagType: 'endlist'
|
913 | });
|
914 |
|
915 | return;
|
916 | }
|
917 |
|
918 | match = /^#EXT-X-DISCONTINUITY/.exec(newLine);
|
919 |
|
920 | if (match) {
|
921 | _this2.trigger('data', {
|
922 | type: 'tag',
|
923 | tagType: 'discontinuity'
|
924 | });
|
925 |
|
926 | return;
|
927 | }
|
928 |
|
929 | match = /^#EXT-X-PROGRAM-DATE-TIME:?(.*)$/.exec(newLine);
|
930 |
|
931 | if (match) {
|
932 | event = {
|
933 | type: 'tag',
|
934 | tagType: 'program-date-time'
|
935 | };
|
936 |
|
937 | if (match[1]) {
|
938 | event.dateTimeString = match[1];
|
939 | event.dateTimeObject = new Date(match[1]);
|
940 | }
|
941 |
|
942 | _this2.trigger('data', event);
|
943 |
|
944 | return;
|
945 | }
|
946 |
|
947 | match = /^#EXT-X-KEY:?(.*)$/.exec(newLine);
|
948 |
|
949 | if (match) {
|
950 | event = {
|
951 | type: 'tag',
|
952 | tagType: 'key'
|
953 | };
|
954 |
|
955 | if (match[1]) {
|
956 | event.attributes = parseAttributes$1(match[1]);
|
957 |
|
958 | if (event.attributes.IV) {
|
959 | if (event.attributes.IV.substring(0, 2).toLowerCase() === '0x') {
|
960 | event.attributes.IV = event.attributes.IV.substring(2);
|
961 | }
|
962 |
|
963 | event.attributes.IV = event.attributes.IV.match(/.{8}/g);
|
964 | event.attributes.IV[0] = parseInt(event.attributes.IV[0], 16);
|
965 | event.attributes.IV[1] = parseInt(event.attributes.IV[1], 16);
|
966 | event.attributes.IV[2] = parseInt(event.attributes.IV[2], 16);
|
967 | event.attributes.IV[3] = parseInt(event.attributes.IV[3], 16);
|
968 | event.attributes.IV = new Uint32Array(event.attributes.IV);
|
969 | }
|
970 | }
|
971 |
|
972 | _this2.trigger('data', event);
|
973 |
|
974 | return;
|
975 | }
|
976 |
|
977 | match = /^#EXT-X-START:?(.*)$/.exec(newLine);
|
978 |
|
979 | if (match) {
|
980 | event = {
|
981 | type: 'tag',
|
982 | tagType: 'start'
|
983 | };
|
984 |
|
985 | if (match[1]) {
|
986 | event.attributes = parseAttributes$1(match[1]);
|
987 | event.attributes['TIME-OFFSET'] = parseFloat(event.attributes['TIME-OFFSET']);
|
988 | event.attributes.PRECISE = /YES/.test(event.attributes.PRECISE);
|
989 | }
|
990 |
|
991 | _this2.trigger('data', event);
|
992 |
|
993 | return;
|
994 | }
|
995 |
|
996 | match = /^#EXT-X-CUE-OUT-CONT:?(.*)?$/.exec(newLine);
|
997 |
|
998 | if (match) {
|
999 | event = {
|
1000 | type: 'tag',
|
1001 | tagType: 'cue-out-cont'
|
1002 | };
|
1003 |
|
1004 | if (match[1]) {
|
1005 | event.data = match[1];
|
1006 | } else {
|
1007 | event.data = '';
|
1008 | }
|
1009 |
|
1010 | _this2.trigger('data', event);
|
1011 |
|
1012 | return;
|
1013 | }
|
1014 |
|
1015 | match = /^#EXT-X-CUE-OUT:?(.*)?$/.exec(newLine);
|
1016 |
|
1017 | if (match) {
|
1018 | event = {
|
1019 | type: 'tag',
|
1020 | tagType: 'cue-out'
|
1021 | };
|
1022 |
|
1023 | if (match[1]) {
|
1024 | event.data = match[1];
|
1025 | } else {
|
1026 | event.data = '';
|
1027 | }
|
1028 |
|
1029 | _this2.trigger('data', event);
|
1030 |
|
1031 | return;
|
1032 | }
|
1033 |
|
1034 | match = /^#EXT-X-CUE-IN:?(.*)?$/.exec(newLine);
|
1035 |
|
1036 | if (match) {
|
1037 | event = {
|
1038 | type: 'tag',
|
1039 | tagType: 'cue-in'
|
1040 | };
|
1041 |
|
1042 | if (match[1]) {
|
1043 | event.data = match[1];
|
1044 | } else {
|
1045 | event.data = '';
|
1046 | }
|
1047 |
|
1048 | _this2.trigger('data', event);
|
1049 |
|
1050 | return;
|
1051 | }
|
1052 |
|
1053 | match = /^#EXT-X-SKIP:(.*)$/.exec(newLine);
|
1054 |
|
1055 | if (match && match[1]) {
|
1056 | event = {
|
1057 | type: 'tag',
|
1058 | tagType: 'skip'
|
1059 | };
|
1060 | event.attributes = parseAttributes$1(match[1]);
|
1061 |
|
1062 | if (event.attributes.hasOwnProperty('SKIPPED-SEGMENTS')) {
|
1063 | event.attributes['SKIPPED-SEGMENTS'] = parseInt(event.attributes['SKIPPED-SEGMENTS'], 10);
|
1064 | }
|
1065 |
|
1066 | if (event.attributes.hasOwnProperty('RECENTLY-REMOVED-DATERANGES')) {
|
1067 | event.attributes['RECENTLY-REMOVED-DATERANGES'] = event.attributes['RECENTLY-REMOVED-DATERANGES'].split(TAB);
|
1068 | }
|
1069 |
|
1070 | _this2.trigger('data', event);
|
1071 |
|
1072 | return;
|
1073 | }
|
1074 |
|
1075 | match = /^#EXT-X-PART:(.*)$/.exec(newLine);
|
1076 |
|
1077 | if (match && match[1]) {
|
1078 | event = {
|
1079 | type: 'tag',
|
1080 | tagType: 'part'
|
1081 | };
|
1082 | event.attributes = parseAttributes$1(match[1]);
|
1083 | ['DURATION'].forEach(function (key) {
|
1084 | if (event.attributes.hasOwnProperty(key)) {
|
1085 | event.attributes[key] = parseFloat(event.attributes[key]);
|
1086 | }
|
1087 | });
|
1088 | ['INDEPENDENT', 'GAP'].forEach(function (key) {
|
1089 | if (event.attributes.hasOwnProperty(key)) {
|
1090 | event.attributes[key] = /YES/.test(event.attributes[key]);
|
1091 | }
|
1092 | });
|
1093 |
|
1094 | if (event.attributes.hasOwnProperty('BYTERANGE')) {
|
1095 | event.attributes.byterange = parseByterange(event.attributes.BYTERANGE);
|
1096 | }
|
1097 |
|
1098 | _this2.trigger('data', event);
|
1099 |
|
1100 | return;
|
1101 | }
|
1102 |
|
1103 | match = /^#EXT-X-SERVER-CONTROL:(.*)$/.exec(newLine);
|
1104 |
|
1105 | if (match && match[1]) {
|
1106 | event = {
|
1107 | type: 'tag',
|
1108 | tagType: 'server-control'
|
1109 | };
|
1110 | event.attributes = parseAttributes$1(match[1]);
|
1111 | ['CAN-SKIP-UNTIL', 'PART-HOLD-BACK', 'HOLD-BACK'].forEach(function (key) {
|
1112 | if (event.attributes.hasOwnProperty(key)) {
|
1113 | event.attributes[key] = parseFloat(event.attributes[key]);
|
1114 | }
|
1115 | });
|
1116 | ['CAN-SKIP-DATERANGES', 'CAN-BLOCK-RELOAD'].forEach(function (key) {
|
1117 | if (event.attributes.hasOwnProperty(key)) {
|
1118 | event.attributes[key] = /YES/.test(event.attributes[key]);
|
1119 | }
|
1120 | });
|
1121 |
|
1122 | _this2.trigger('data', event);
|
1123 |
|
1124 | return;
|
1125 | }
|
1126 |
|
1127 | match = /^#EXT-X-PART-INF:(.*)$/.exec(newLine);
|
1128 |
|
1129 | if (match && match[1]) {
|
1130 | event = {
|
1131 | type: 'tag',
|
1132 | tagType: 'part-inf'
|
1133 | };
|
1134 | event.attributes = parseAttributes$1(match[1]);
|
1135 | ['PART-TARGET'].forEach(function (key) {
|
1136 | if (event.attributes.hasOwnProperty(key)) {
|
1137 | event.attributes[key] = parseFloat(event.attributes[key]);
|
1138 | }
|
1139 | });
|
1140 |
|
1141 | _this2.trigger('data', event);
|
1142 |
|
1143 | return;
|
1144 | }
|
1145 |
|
1146 | match = /^#EXT-X-PRELOAD-HINT:(.*)$/.exec(newLine);
|
1147 |
|
1148 | if (match && match[1]) {
|
1149 | event = {
|
1150 | type: 'tag',
|
1151 | tagType: 'preload-hint'
|
1152 | };
|
1153 | event.attributes = parseAttributes$1(match[1]);
|
1154 | ['BYTERANGE-START', 'BYTERANGE-LENGTH'].forEach(function (key) {
|
1155 | if (event.attributes.hasOwnProperty(key)) {
|
1156 | event.attributes[key] = parseInt(event.attributes[key], 10);
|
1157 | var subkey = key === 'BYTERANGE-LENGTH' ? 'length' : 'offset';
|
1158 | event.attributes.byterange = event.attributes.byterange || {};
|
1159 | event.attributes.byterange[subkey] = event.attributes[key];
|
1160 |
|
1161 | delete event.attributes[key];
|
1162 | }
|
1163 | });
|
1164 |
|
1165 | _this2.trigger('data', event);
|
1166 |
|
1167 | return;
|
1168 | }
|
1169 |
|
1170 | match = /^#EXT-X-RENDITION-REPORT:(.*)$/.exec(newLine);
|
1171 |
|
1172 | if (match && match[1]) {
|
1173 | event = {
|
1174 | type: 'tag',
|
1175 | tagType: 'rendition-report'
|
1176 | };
|
1177 | event.attributes = parseAttributes$1(match[1]);
|
1178 | ['LAST-MSN', 'LAST-PART'].forEach(function (key) {
|
1179 | if (event.attributes.hasOwnProperty(key)) {
|
1180 | event.attributes[key] = parseInt(event.attributes[key], 10);
|
1181 | }
|
1182 | });
|
1183 |
|
1184 | _this2.trigger('data', event);
|
1185 |
|
1186 | return;
|
1187 | }
|
1188 |
|
1189 |
|
1190 | _this2.trigger('data', {
|
1191 | type: 'tag',
|
1192 | data: newLine.slice(4)
|
1193 | });
|
1194 | });
|
1195 | }
|
1196 | |
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 | ;
|
1206 |
|
1207 | _proto.addParser = function addParser(_ref) {
|
1208 | var _this3 = this;
|
1209 |
|
1210 | var expression = _ref.expression,
|
1211 | customType = _ref.customType,
|
1212 | dataParser = _ref.dataParser,
|
1213 | segment = _ref.segment;
|
1214 |
|
1215 | if (typeof dataParser !== 'function') {
|
1216 | dataParser = function dataParser(line) {
|
1217 | return line;
|
1218 | };
|
1219 | }
|
1220 |
|
1221 | this.customParsers.push(function (line) {
|
1222 | var match = expression.exec(line);
|
1223 |
|
1224 | if (match) {
|
1225 | _this3.trigger('data', {
|
1226 | type: 'custom',
|
1227 | data: dataParser(line),
|
1228 | customType: customType,
|
1229 | segment: segment
|
1230 | });
|
1231 |
|
1232 | return true;
|
1233 | }
|
1234 | });
|
1235 | }
|
1236 | |
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 | ;
|
1244 |
|
1245 | _proto.addTagMapper = function addTagMapper(_ref2) {
|
1246 | var expression = _ref2.expression,
|
1247 | map = _ref2.map;
|
1248 |
|
1249 | var mapFn = function mapFn(line) {
|
1250 | if (expression.test(line)) {
|
1251 | return map(line);
|
1252 | }
|
1253 |
|
1254 | return line;
|
1255 | };
|
1256 |
|
1257 | this.tagMappers.push(mapFn);
|
1258 | };
|
1259 |
|
1260 | return ParseStream;
|
1261 | }(Stream);
|
1262 |
|
1263 | var camelCase = function camelCase(str) {
|
1264 | return str.toLowerCase().replace(/-(\w)/g, function (a) {
|
1265 | return a[1].toUpperCase();
|
1266 | });
|
1267 | };
|
1268 |
|
1269 | var camelCaseKeys = function camelCaseKeys(attributes) {
|
1270 | var result = {};
|
1271 | Object.keys(attributes).forEach(function (key) {
|
1272 | result[camelCase(key)] = attributes[key];
|
1273 | });
|
1274 | return result;
|
1275 | };
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 | var setHoldBack = function setHoldBack(manifest) {
|
1282 | var serverControl = manifest.serverControl,
|
1283 | targetDuration = manifest.targetDuration,
|
1284 | partTargetDuration = manifest.partTargetDuration;
|
1285 |
|
1286 | if (!serverControl) {
|
1287 | return;
|
1288 | }
|
1289 |
|
1290 | var tag = '#EXT-X-SERVER-CONTROL';
|
1291 | var hb = 'holdBack';
|
1292 | var phb = 'partHoldBack';
|
1293 | var minTargetDuration = targetDuration && targetDuration * 3;
|
1294 | var minPartDuration = partTargetDuration && partTargetDuration * 2;
|
1295 |
|
1296 | if (targetDuration && !serverControl.hasOwnProperty(hb)) {
|
1297 | serverControl[hb] = minTargetDuration;
|
1298 | this.trigger('info', {
|
1299 | message: tag + " defaulting HOLD-BACK to targetDuration * 3 (" + minTargetDuration + ")."
|
1300 | });
|
1301 | }
|
1302 |
|
1303 | if (minTargetDuration && serverControl[hb] < minTargetDuration) {
|
1304 | this.trigger('warn', {
|
1305 | message: tag + " clamping HOLD-BACK (" + serverControl[hb] + ") to targetDuration * 3 (" + minTargetDuration + ")"
|
1306 | });
|
1307 | serverControl[hb] = minTargetDuration;
|
1308 | }
|
1309 |
|
1310 |
|
1311 | if (partTargetDuration && !serverControl.hasOwnProperty(phb)) {
|
1312 | serverControl[phb] = partTargetDuration * 3;
|
1313 | this.trigger('info', {
|
1314 | message: tag + " defaulting PART-HOLD-BACK to partTargetDuration * 3 (" + serverControl[phb] + ")."
|
1315 | });
|
1316 | }
|
1317 |
|
1318 |
|
1319 | if (partTargetDuration && serverControl[phb] < minPartDuration) {
|
1320 | this.trigger('warn', {
|
1321 | message: tag + " clamping PART-HOLD-BACK (" + serverControl[phb] + ") to partTargetDuration * 2 (" + minPartDuration + ")."
|
1322 | });
|
1323 | serverControl[phb] = minPartDuration;
|
1324 | }
|
1325 | };
|
1326 | |
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 | var Parser = function (_Stream) {
|
1350 | inheritsLoose(Parser, _Stream);
|
1351 |
|
1352 | function Parser() {
|
1353 | var _this;
|
1354 |
|
1355 | _this = _Stream.call(this) || this;
|
1356 | _this.lineStream = new LineStream();
|
1357 | _this.parseStream = new ParseStream();
|
1358 |
|
1359 | _this.lineStream.pipe(_this.parseStream);
|
1360 |
|
1361 |
|
1362 |
|
1363 | var self = assertThisInitialized(_this);
|
1364 |
|
1365 |
|
1366 |
|
1367 | var uris = [];
|
1368 | var currentUri = {};
|
1369 |
|
1370 | var currentMap;
|
1371 |
|
1372 | var _key;
|
1373 |
|
1374 | var hasParts = false;
|
1375 |
|
1376 | var noop = function noop() {};
|
1377 |
|
1378 | var defaultMediaGroups = {
|
1379 | 'AUDIO': {},
|
1380 | 'VIDEO': {},
|
1381 | 'CLOSED-CAPTIONS': {},
|
1382 | 'SUBTITLES': {}
|
1383 | };
|
1384 |
|
1385 |
|
1386 | var widevineUuid = 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed';
|
1387 |
|
1388 | var currentTimeline = 0;
|
1389 |
|
1390 | _this.manifest = {
|
1391 | allowCache: true,
|
1392 | discontinuityStarts: [],
|
1393 | segments: []
|
1394 | };
|
1395 |
|
1396 |
|
1397 |
|
1398 | var lastByterangeEnd = 0;
|
1399 |
|
1400 | var lastPartByterangeEnd = 0;
|
1401 |
|
1402 | _this.on('end', function () {
|
1403 |
|
1404 |
|
1405 | if (currentUri.uri || !currentUri.parts && !currentUri.preloadHints) {
|
1406 | return;
|
1407 | }
|
1408 |
|
1409 | if (!currentUri.map && currentMap) {
|
1410 | currentUri.map = currentMap;
|
1411 | }
|
1412 |
|
1413 | if (!currentUri.key && _key) {
|
1414 | currentUri.key = _key;
|
1415 | }
|
1416 |
|
1417 | if (!currentUri.timeline && typeof currentTimeline === 'number') {
|
1418 | currentUri.timeline = currentTimeline;
|
1419 | }
|
1420 |
|
1421 | _this.manifest.preloadSegment = currentUri;
|
1422 | });
|
1423 |
|
1424 |
|
1425 | _this.parseStream.on('data', function (entry) {
|
1426 | var mediaGroup;
|
1427 | var rendition;
|
1428 | ({
|
1429 | tag: function tag() {
|
1430 |
|
1431 | (({
|
1432 | version: function version() {
|
1433 | if (entry.version) {
|
1434 | this.manifest.version = entry.version;
|
1435 | }
|
1436 | },
|
1437 | 'allow-cache': function allowCache() {
|
1438 | this.manifest.allowCache = entry.allowed;
|
1439 |
|
1440 | if (!('allowed' in entry)) {
|
1441 | this.trigger('info', {
|
1442 | message: 'defaulting allowCache to YES'
|
1443 | });
|
1444 | this.manifest.allowCache = true;
|
1445 | }
|
1446 | },
|
1447 | byterange: function byterange() {
|
1448 | var byterange = {};
|
1449 |
|
1450 | if ('length' in entry) {
|
1451 | currentUri.byterange = byterange;
|
1452 | byterange.length = entry.length;
|
1453 |
|
1454 | if (!('offset' in entry)) {
|
1455 | |
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 | entry.offset = lastByterangeEnd;
|
1466 | }
|
1467 | }
|
1468 |
|
1469 | if ('offset' in entry) {
|
1470 | currentUri.byterange = byterange;
|
1471 | byterange.offset = entry.offset;
|
1472 | }
|
1473 |
|
1474 | lastByterangeEnd = byterange.offset + byterange.length;
|
1475 | },
|
1476 | endlist: function endlist() {
|
1477 | this.manifest.endList = true;
|
1478 | },
|
1479 | inf: function inf() {
|
1480 | if (!('mediaSequence' in this.manifest)) {
|
1481 | this.manifest.mediaSequence = 0;
|
1482 | this.trigger('info', {
|
1483 | message: 'defaulting media sequence to zero'
|
1484 | });
|
1485 | }
|
1486 |
|
1487 | if (!('discontinuitySequence' in this.manifest)) {
|
1488 | this.manifest.discontinuitySequence = 0;
|
1489 | this.trigger('info', {
|
1490 | message: 'defaulting discontinuity sequence to zero'
|
1491 | });
|
1492 | }
|
1493 |
|
1494 | if (entry.duration > 0) {
|
1495 | currentUri.duration = entry.duration;
|
1496 | }
|
1497 |
|
1498 | if (entry.duration === 0) {
|
1499 | currentUri.duration = 0.01;
|
1500 | this.trigger('info', {
|
1501 | message: 'updating zero segment duration to a small value'
|
1502 | });
|
1503 | }
|
1504 |
|
1505 | this.manifest.segments = uris;
|
1506 | },
|
1507 | key: function key() {
|
1508 | if (!entry.attributes) {
|
1509 | this.trigger('warn', {
|
1510 | message: 'ignoring key declaration without attribute list'
|
1511 | });
|
1512 | return;
|
1513 | }
|
1514 |
|
1515 |
|
1516 | if (entry.attributes.METHOD === 'NONE') {
|
1517 | _key = null;
|
1518 | return;
|
1519 | }
|
1520 |
|
1521 | if (!entry.attributes.URI) {
|
1522 | this.trigger('warn', {
|
1523 | message: 'ignoring key declaration without URI'
|
1524 | });
|
1525 | return;
|
1526 | }
|
1527 |
|
1528 | if (entry.attributes.KEYFORMAT === 'com.apple.streamingkeydelivery') {
|
1529 | this.manifest.contentProtection = this.manifest.contentProtection || {};
|
1530 |
|
1531 | this.manifest.contentProtection['com.apple.fps.1_0'] = {
|
1532 | attributes: entry.attributes
|
1533 | };
|
1534 | return;
|
1535 | }
|
1536 |
|
1537 |
|
1538 |
|
1539 | if (entry.attributes.KEYFORMAT === widevineUuid) {
|
1540 | var VALID_METHODS = ['SAMPLE-AES', 'SAMPLE-AES-CTR', 'SAMPLE-AES-CENC'];
|
1541 |
|
1542 | if (VALID_METHODS.indexOf(entry.attributes.METHOD) === -1) {
|
1543 | this.trigger('warn', {
|
1544 | message: 'invalid key method provided for Widevine'
|
1545 | });
|
1546 | return;
|
1547 | }
|
1548 |
|
1549 | if (entry.attributes.METHOD === 'SAMPLE-AES-CENC') {
|
1550 | this.trigger('warn', {
|
1551 | message: 'SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead'
|
1552 | });
|
1553 | }
|
1554 |
|
1555 | if (entry.attributes.URI.substring(0, 23) !== 'data:text/plain;base64,') {
|
1556 | this.trigger('warn', {
|
1557 | message: 'invalid key URI provided for Widevine'
|
1558 | });
|
1559 | return;
|
1560 | }
|
1561 |
|
1562 | if (!(entry.attributes.KEYID && entry.attributes.KEYID.substring(0, 2) === '0x')) {
|
1563 | this.trigger('warn', {
|
1564 | message: 'invalid key ID provided for Widevine'
|
1565 | });
|
1566 | return;
|
1567 | }
|
1568 |
|
1569 |
|
1570 |
|
1571 | this.manifest.contentProtection = this.manifest.contentProtection || {};
|
1572 | this.manifest.contentProtection['com.widevine.alpha'] = {
|
1573 | attributes: {
|
1574 | schemeIdUri: entry.attributes.KEYFORMAT,
|
1575 |
|
1576 | keyId: entry.attributes.KEYID.substring(2)
|
1577 | },
|
1578 |
|
1579 | pssh: decodeB64ToUint8Array(entry.attributes.URI.split(',')[1])
|
1580 | };
|
1581 | return;
|
1582 | }
|
1583 |
|
1584 | if (!entry.attributes.METHOD) {
|
1585 | this.trigger('warn', {
|
1586 | message: 'defaulting key method to AES-128'
|
1587 | });
|
1588 | }
|
1589 |
|
1590 |
|
1591 | _key = {
|
1592 | method: entry.attributes.METHOD || 'AES-128',
|
1593 | uri: entry.attributes.URI
|
1594 | };
|
1595 |
|
1596 | if (typeof entry.attributes.IV !== 'undefined') {
|
1597 | _key.iv = entry.attributes.IV;
|
1598 | }
|
1599 | },
|
1600 | 'media-sequence': function mediaSequence() {
|
1601 | if (!isFinite(entry.number)) {
|
1602 | this.trigger('warn', {
|
1603 | message: 'ignoring invalid media sequence: ' + entry.number
|
1604 | });
|
1605 | return;
|
1606 | }
|
1607 |
|
1608 | this.manifest.mediaSequence = entry.number;
|
1609 | },
|
1610 | 'discontinuity-sequence': function discontinuitySequence() {
|
1611 | if (!isFinite(entry.number)) {
|
1612 | this.trigger('warn', {
|
1613 | message: 'ignoring invalid discontinuity sequence: ' + entry.number
|
1614 | });
|
1615 | return;
|
1616 | }
|
1617 |
|
1618 | this.manifest.discontinuitySequence = entry.number;
|
1619 | currentTimeline = entry.number;
|
1620 | },
|
1621 | 'playlist-type': function playlistType() {
|
1622 | if (!/VOD|EVENT/.test(entry.playlistType)) {
|
1623 | this.trigger('warn', {
|
1624 | message: 'ignoring unknown playlist type: ' + entry.playlist
|
1625 | });
|
1626 | return;
|
1627 | }
|
1628 |
|
1629 | this.manifest.playlistType = entry.playlistType;
|
1630 | },
|
1631 | map: function map() {
|
1632 | currentMap = {};
|
1633 |
|
1634 | if (entry.uri) {
|
1635 | currentMap.uri = entry.uri;
|
1636 | }
|
1637 |
|
1638 | if (entry.byterange) {
|
1639 | currentMap.byterange = entry.byterange;
|
1640 | }
|
1641 |
|
1642 | if (_key) {
|
1643 | currentMap.key = _key;
|
1644 | }
|
1645 | },
|
1646 | 'stream-inf': function streamInf() {
|
1647 | this.manifest.playlists = uris;
|
1648 | this.manifest.mediaGroups = this.manifest.mediaGroups || defaultMediaGroups;
|
1649 |
|
1650 | if (!entry.attributes) {
|
1651 | this.trigger('warn', {
|
1652 | message: 'ignoring empty stream-inf attributes'
|
1653 | });
|
1654 | return;
|
1655 | }
|
1656 |
|
1657 | if (!currentUri.attributes) {
|
1658 | currentUri.attributes = {};
|
1659 | }
|
1660 |
|
1661 | _extends_1(currentUri.attributes, entry.attributes);
|
1662 | },
|
1663 | media: function media() {
|
1664 | this.manifest.mediaGroups = this.manifest.mediaGroups || defaultMediaGroups;
|
1665 |
|
1666 | if (!(entry.attributes && entry.attributes.TYPE && entry.attributes['GROUP-ID'] && entry.attributes.NAME)) {
|
1667 | this.trigger('warn', {
|
1668 | message: 'ignoring incomplete or missing media group'
|
1669 | });
|
1670 | return;
|
1671 | }
|
1672 |
|
1673 |
|
1674 | var mediaGroupType = this.manifest.mediaGroups[entry.attributes.TYPE];
|
1675 | mediaGroupType[entry.attributes['GROUP-ID']] = mediaGroupType[entry.attributes['GROUP-ID']] || {};
|
1676 | mediaGroup = mediaGroupType[entry.attributes['GROUP-ID']];
|
1677 |
|
1678 | rendition = {
|
1679 | default: /yes/i.test(entry.attributes.DEFAULT)
|
1680 | };
|
1681 |
|
1682 | if (rendition.default) {
|
1683 | rendition.autoselect = true;
|
1684 | } else {
|
1685 | rendition.autoselect = /yes/i.test(entry.attributes.AUTOSELECT);
|
1686 | }
|
1687 |
|
1688 | if (entry.attributes.LANGUAGE) {
|
1689 | rendition.language = entry.attributes.LANGUAGE;
|
1690 | }
|
1691 |
|
1692 | if (entry.attributes.URI) {
|
1693 | rendition.uri = entry.attributes.URI;
|
1694 | }
|
1695 |
|
1696 | if (entry.attributes['INSTREAM-ID']) {
|
1697 | rendition.instreamId = entry.attributes['INSTREAM-ID'];
|
1698 | }
|
1699 |
|
1700 | if (entry.attributes.CHARACTERISTICS) {
|
1701 | rendition.characteristics = entry.attributes.CHARACTERISTICS;
|
1702 | }
|
1703 |
|
1704 | if (entry.attributes.FORCED) {
|
1705 | rendition.forced = /yes/i.test(entry.attributes.FORCED);
|
1706 | }
|
1707 |
|
1708 |
|
1709 | mediaGroup[entry.attributes.NAME] = rendition;
|
1710 | },
|
1711 | discontinuity: function discontinuity() {
|
1712 | currentTimeline += 1;
|
1713 | currentUri.discontinuity = true;
|
1714 | this.manifest.discontinuityStarts.push(uris.length);
|
1715 | },
|
1716 | 'program-date-time': function programDateTime() {
|
1717 | if (typeof this.manifest.dateTimeString === 'undefined') {
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 | this.manifest.dateTimeString = entry.dateTimeString;
|
1723 | this.manifest.dateTimeObject = entry.dateTimeObject;
|
1724 | }
|
1725 |
|
1726 | currentUri.dateTimeString = entry.dateTimeString;
|
1727 | currentUri.dateTimeObject = entry.dateTimeObject;
|
1728 | },
|
1729 | targetduration: function targetduration() {
|
1730 | if (!isFinite(entry.duration) || entry.duration < 0) {
|
1731 | this.trigger('warn', {
|
1732 | message: 'ignoring invalid target duration: ' + entry.duration
|
1733 | });
|
1734 | return;
|
1735 | }
|
1736 |
|
1737 | this.manifest.targetDuration = entry.duration;
|
1738 | setHoldBack.call(this, this.manifest);
|
1739 | },
|
1740 | start: function start() {
|
1741 | if (!entry.attributes || isNaN(entry.attributes['TIME-OFFSET'])) {
|
1742 | this.trigger('warn', {
|
1743 | message: 'ignoring start declaration without appropriate attribute list'
|
1744 | });
|
1745 | return;
|
1746 | }
|
1747 |
|
1748 | this.manifest.start = {
|
1749 | timeOffset: entry.attributes['TIME-OFFSET'],
|
1750 | precise: entry.attributes.PRECISE
|
1751 | };
|
1752 | },
|
1753 | 'cue-out': function cueOut() {
|
1754 | currentUri.cueOut = entry.data;
|
1755 | },
|
1756 | 'cue-out-cont': function cueOutCont() {
|
1757 | currentUri.cueOutCont = entry.data;
|
1758 | },
|
1759 | 'cue-in': function cueIn() {
|
1760 | currentUri.cueIn = entry.data;
|
1761 | },
|
1762 | 'skip': function skip() {
|
1763 | this.manifest.skip = camelCaseKeys(entry.attributes);
|
1764 | this.warnOnMissingAttributes_('#EXT-X-SKIP', entry.attributes, ['SKIPPED-SEGMENTS']);
|
1765 | },
|
1766 | 'part': function part() {
|
1767 | var _this2 = this;
|
1768 |
|
1769 | hasParts = true;
|
1770 |
|
1771 | var segmentIndex = this.manifest.segments.length;
|
1772 | var part = camelCaseKeys(entry.attributes);
|
1773 | currentUri.parts = currentUri.parts || [];
|
1774 | currentUri.parts.push(part);
|
1775 |
|
1776 | if (part.byterange) {
|
1777 | if (!part.byterange.hasOwnProperty('offset')) {
|
1778 | part.byterange.offset = lastPartByterangeEnd;
|
1779 | }
|
1780 |
|
1781 | lastPartByterangeEnd = part.byterange.offset + part.byterange.length;
|
1782 | }
|
1783 |
|
1784 | var partIndex = currentUri.parts.length - 1;
|
1785 | this.warnOnMissingAttributes_("#EXT-X-PART #" + partIndex + " for segment #" + segmentIndex, entry.attributes, ['URI', 'DURATION']);
|
1786 |
|
1787 | if (this.manifest.renditionReports) {
|
1788 | this.manifest.renditionReports.forEach(function (r, i) {
|
1789 | if (!r.hasOwnProperty('lastPart')) {
|
1790 | _this2.trigger('warn', {
|
1791 | message: "#EXT-X-RENDITION-REPORT #" + i + " lacks required attribute(s): LAST-PART"
|
1792 | });
|
1793 | }
|
1794 | });
|
1795 | }
|
1796 | },
|
1797 | 'server-control': function serverControl() {
|
1798 | var attrs = this.manifest.serverControl = camelCaseKeys(entry.attributes);
|
1799 |
|
1800 | if (!attrs.hasOwnProperty('canBlockReload')) {
|
1801 | attrs.canBlockReload = false;
|
1802 | this.trigger('info', {
|
1803 | message: '#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false'
|
1804 | });
|
1805 | }
|
1806 |
|
1807 | setHoldBack.call(this, this.manifest);
|
1808 |
|
1809 | if (attrs.canSkipDateranges && !attrs.hasOwnProperty('canSkipUntil')) {
|
1810 | this.trigger('warn', {
|
1811 | message: '#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set'
|
1812 | });
|
1813 | }
|
1814 | },
|
1815 | 'preload-hint': function preloadHint() {
|
1816 |
|
1817 | var segmentIndex = this.manifest.segments.length;
|
1818 | var hint = camelCaseKeys(entry.attributes);
|
1819 | var isPart = hint.type && hint.type === 'PART';
|
1820 | currentUri.preloadHints = currentUri.preloadHints || [];
|
1821 | currentUri.preloadHints.push(hint);
|
1822 |
|
1823 | if (hint.byterange) {
|
1824 | if (!hint.byterange.hasOwnProperty('offset')) {
|
1825 |
|
1826 | hint.byterange.offset = isPart ? lastPartByterangeEnd : 0;
|
1827 |
|
1828 | if (isPart) {
|
1829 | lastPartByterangeEnd = hint.byterange.offset + hint.byterange.length;
|
1830 | }
|
1831 | }
|
1832 | }
|
1833 |
|
1834 | var index = currentUri.preloadHints.length - 1;
|
1835 | this.warnOnMissingAttributes_("#EXT-X-PRELOAD-HINT #" + index + " for segment #" + segmentIndex, entry.attributes, ['TYPE', 'URI']);
|
1836 |
|
1837 | if (!hint.type) {
|
1838 | return;
|
1839 | }
|
1840 |
|
1841 |
|
1842 |
|
1843 | for (var i = 0; i < currentUri.preloadHints.length - 1; i++) {
|
1844 | var otherHint = currentUri.preloadHints[i];
|
1845 |
|
1846 | if (!otherHint.type) {
|
1847 | continue;
|
1848 | }
|
1849 |
|
1850 | if (otherHint.type === hint.type) {
|
1851 | this.trigger('warn', {
|
1852 | message: "#EXT-X-PRELOAD-HINT #" + index + " for segment #" + segmentIndex + " has the same TYPE " + hint.type + " as preload hint #" + i
|
1853 | });
|
1854 | }
|
1855 | }
|
1856 | },
|
1857 | 'rendition-report': function renditionReport() {
|
1858 | var report = camelCaseKeys(entry.attributes);
|
1859 | this.manifest.renditionReports = this.manifest.renditionReports || [];
|
1860 | this.manifest.renditionReports.push(report);
|
1861 | var index = this.manifest.renditionReports.length - 1;
|
1862 | var required = ['LAST-MSN', 'URI'];
|
1863 |
|
1864 | if (hasParts) {
|
1865 | required.push('LAST-PART');
|
1866 | }
|
1867 |
|
1868 | this.warnOnMissingAttributes_("#EXT-X-RENDITION-REPORT #" + index, entry.attributes, required);
|
1869 | },
|
1870 | 'part-inf': function partInf() {
|
1871 | this.manifest.partInf = camelCaseKeys(entry.attributes);
|
1872 | this.warnOnMissingAttributes_('#EXT-X-PART-INF', entry.attributes, ['PART-TARGET']);
|
1873 |
|
1874 | if (this.manifest.partInf.partTarget) {
|
1875 | this.manifest.partTargetDuration = this.manifest.partInf.partTarget;
|
1876 | }
|
1877 |
|
1878 | setHoldBack.call(this, this.manifest);
|
1879 | }
|
1880 | })[entry.tagType] || noop).call(self);
|
1881 | },
|
1882 | uri: function uri() {
|
1883 | currentUri.uri = entry.uri;
|
1884 | uris.push(currentUri);
|
1885 |
|
1886 | if (this.manifest.targetDuration && !('duration' in currentUri)) {
|
1887 | this.trigger('warn', {
|
1888 | message: 'defaulting segment duration to the target duration'
|
1889 | });
|
1890 | currentUri.duration = this.manifest.targetDuration;
|
1891 | }
|
1892 |
|
1893 |
|
1894 | if (_key) {
|
1895 | currentUri.key = _key;
|
1896 | }
|
1897 |
|
1898 | currentUri.timeline = currentTimeline;
|
1899 |
|
1900 | if (currentMap) {
|
1901 | currentUri.map = currentMap;
|
1902 | }
|
1903 |
|
1904 |
|
1905 | lastPartByterangeEnd = 0;
|
1906 |
|
1907 | currentUri = {};
|
1908 | },
|
1909 | comment: function comment() {
|
1910 | },
|
1911 | custom: function custom() {
|
1912 |
|
1913 | if (entry.segment) {
|
1914 | currentUri.custom = currentUri.custom || {};
|
1915 | currentUri.custom[entry.customType] = entry.data;
|
1916 | } else {
|
1917 | this.manifest.custom = this.manifest.custom || {};
|
1918 | this.manifest.custom[entry.customType] = entry.data;
|
1919 | }
|
1920 | }
|
1921 | })[entry.type].call(self);
|
1922 | });
|
1923 |
|
1924 | return _this;
|
1925 | }
|
1926 |
|
1927 | var _proto = Parser.prototype;
|
1928 |
|
1929 | _proto.warnOnMissingAttributes_ = function warnOnMissingAttributes_(identifier, attributes, required) {
|
1930 | var missing = [];
|
1931 | required.forEach(function (key) {
|
1932 | if (!attributes.hasOwnProperty(key)) {
|
1933 | missing.push(key);
|
1934 | }
|
1935 | });
|
1936 |
|
1937 | if (missing.length) {
|
1938 | this.trigger('warn', {
|
1939 | message: identifier + " lacks required attribute(s): " + missing.join(', ')
|
1940 | });
|
1941 | }
|
1942 | }
|
1943 | |
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 | ;
|
1949 |
|
1950 | _proto.push = function push(chunk) {
|
1951 | this.lineStream.push(chunk);
|
1952 | }
|
1953 | |
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 | ;
|
1959 |
|
1960 | _proto.end = function end() {
|
1961 |
|
1962 | this.lineStream.push('\n');
|
1963 | this.trigger('end');
|
1964 | }
|
1965 | |
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 | ;
|
1975 |
|
1976 | _proto.addParser = function addParser(options) {
|
1977 | this.parseStream.addParser(options);
|
1978 | }
|
1979 | |
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 | ;
|
1987 |
|
1988 | _proto.addTagMapper = function addTagMapper(options) {
|
1989 | this.parseStream.addTagMapper(options);
|
1990 | };
|
1991 |
|
1992 | return Parser;
|
1993 | }(Stream);
|
1994 |
|
1995 | var regexs = {
|
1996 |
|
1997 | mp4: /^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,
|
1998 | webm: /^(vp0?[89]|av0?1|opus|vorbis)/,
|
1999 | ogg: /^(vp0?[89]|theora|flac|opus|vorbis)/,
|
2000 |
|
2001 | video: /^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,
|
2002 | audio: /^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,
|
2003 | text: /^(stpp.ttml.im1t)/,
|
2004 |
|
2005 | muxerVideo: /^(avc0?1)/,
|
2006 | muxerAudio: /^(mp4a)/,
|
2007 |
|
2008 |
|
2009 |
|
2010 | muxerText: /a^/
|
2011 | };
|
2012 | var mediaTypes = ['video', 'audio', 'text'];
|
2013 | var upperMediaTypes = ['Video', 'Audio', 'Text'];
|
2014 | |
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 |
|
2024 | var translateLegacyCodec = function translateLegacyCodec(codec) {
|
2025 | if (!codec) {
|
2026 | return codec;
|
2027 | }
|
2028 |
|
2029 | return codec.replace(/avc1\.(\d+)\.(\d+)/i, function (orig, profile, avcLevel) {
|
2030 | var profileHex = ('00' + Number(profile).toString(16)).slice(-2);
|
2031 | var avcLevelHex = ('00' + Number(avcLevel).toString(16)).slice(-2);
|
2032 | return 'avc1.' + profileHex + '00' + avcLevelHex;
|
2033 | });
|
2034 | };
|
2035 | |
2036 |
|
2037 |
|
2038 |
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 | |
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 |
|
2057 | var parseCodecs = function parseCodecs(codecString) {
|
2058 | if (codecString === void 0) {
|
2059 | codecString = '';
|
2060 | }
|
2061 |
|
2062 | var codecs = codecString.split(',');
|
2063 | var result = [];
|
2064 | codecs.forEach(function (codec) {
|
2065 | codec = codec.trim();
|
2066 | var codecType;
|
2067 | mediaTypes.forEach(function (name) {
|
2068 | var match = regexs[name].exec(codec.toLowerCase());
|
2069 |
|
2070 | if (!match || match.length <= 1) {
|
2071 | return;
|
2072 | }
|
2073 |
|
2074 | codecType = name;
|
2075 |
|
2076 | var type = codec.substring(0, match[1].length);
|
2077 | var details = codec.replace(type, '');
|
2078 | result.push({
|
2079 | type: type,
|
2080 | details: details,
|
2081 | mediaType: name
|
2082 | });
|
2083 | });
|
2084 |
|
2085 | if (!codecType) {
|
2086 | result.push({
|
2087 | type: codec,
|
2088 | details: '',
|
2089 | mediaType: 'unknown'
|
2090 | });
|
2091 | }
|
2092 | });
|
2093 | return result;
|
2094 | };
|
2095 | |
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 | var codecsFromDefault = function codecsFromDefault(master, audioGroupId) {
|
2108 | if (!master.mediaGroups.AUDIO || !audioGroupId) {
|
2109 | return null;
|
2110 | }
|
2111 |
|
2112 | var audioGroup = master.mediaGroups.AUDIO[audioGroupId];
|
2113 |
|
2114 | if (!audioGroup) {
|
2115 | return null;
|
2116 | }
|
2117 |
|
2118 | for (var name in audioGroup) {
|
2119 | var audioType = audioGroup[name];
|
2120 |
|
2121 | if (audioType.default && audioType.playlists) {
|
2122 |
|
2123 | return parseCodecs(audioType.playlists[0].attributes.CODECS);
|
2124 | }
|
2125 | }
|
2126 |
|
2127 | return null;
|
2128 | };
|
2129 | var isAudioCodec = function isAudioCodec(codec) {
|
2130 | if (codec === void 0) {
|
2131 | codec = '';
|
2132 | }
|
2133 |
|
2134 | return regexs.audio.test(codec.trim().toLowerCase());
|
2135 | };
|
2136 | var isTextCodec = function isTextCodec(codec) {
|
2137 | if (codec === void 0) {
|
2138 | codec = '';
|
2139 | }
|
2140 |
|
2141 | return regexs.text.test(codec.trim().toLowerCase());
|
2142 | };
|
2143 | var getMimeForCodec = function getMimeForCodec(codecString) {
|
2144 | if (!codecString || typeof codecString !== 'string') {
|
2145 | return;
|
2146 | }
|
2147 |
|
2148 | var codecs = codecString.toLowerCase().split(',').map(function (c) {
|
2149 | return translateLegacyCodec(c.trim());
|
2150 | });
|
2151 |
|
2152 | var type = 'video';
|
2153 |
|
2154 |
|
2155 | if (codecs.length === 1 && isAudioCodec(codecs[0])) {
|
2156 | type = 'audio';
|
2157 | } else if (codecs.length === 1 && isTextCodec(codecs[0])) {
|
2158 |
|
2159 | type = 'application';
|
2160 | }
|
2161 |
|
2162 |
|
2163 | var container = 'mp4';
|
2164 |
|
2165 |
|
2166 | if (codecs.every(function (c) {
|
2167 | return regexs.mp4.test(c);
|
2168 | })) {
|
2169 | container = 'mp4';
|
2170 | } else if (codecs.every(function (c) {
|
2171 | return regexs.webm.test(c);
|
2172 | })) {
|
2173 | container = 'webm';
|
2174 | } else if (codecs.every(function (c) {
|
2175 | return regexs.ogg.test(c);
|
2176 | })) {
|
2177 | container = 'ogg';
|
2178 | }
|
2179 |
|
2180 | return type + "/" + container + ";codecs=\"" + codecString + "\"";
|
2181 | };
|
2182 | var browserSupportsCodec = function browserSupportsCodec(codecString) {
|
2183 | if (codecString === void 0) {
|
2184 | codecString = '';
|
2185 | }
|
2186 |
|
2187 | return window.MediaSource && window.MediaSource.isTypeSupported && window.MediaSource.isTypeSupported(getMimeForCodec(codecString)) || false;
|
2188 | };
|
2189 | var muxerSupportsCodec = function muxerSupportsCodec(codecString) {
|
2190 | if (codecString === void 0) {
|
2191 | codecString = '';
|
2192 | }
|
2193 |
|
2194 | return codecString.toLowerCase().split(',').every(function (codec) {
|
2195 | codec = codec.trim();
|
2196 |
|
2197 | for (var i = 0; i < upperMediaTypes.length; i++) {
|
2198 | var type = upperMediaTypes[i];
|
2199 |
|
2200 | if (regexs["muxer" + type].test(codec)) {
|
2201 | return true;
|
2202 | }
|
2203 | }
|
2204 |
|
2205 | return false;
|
2206 | });
|
2207 | };
|
2208 | var DEFAULT_AUDIO_CODEC = 'mp4a.40.2';
|
2209 | var DEFAULT_VIDEO_CODEC = 'avc1.4d400d';
|
2210 |
|
2211 | |
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 | var TIME_FUDGE_FACTOR = 1 / 30;
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 | var SAFE_TIME_DELTA = TIME_FUDGE_FACTOR * 3;
|
2225 |
|
2226 | var filterRanges = function filterRanges(timeRanges, predicate) {
|
2227 | var results = [];
|
2228 | var i;
|
2229 |
|
2230 | if (timeRanges && timeRanges.length) {
|
2231 |
|
2232 | for (i = 0; i < timeRanges.length; i++) {
|
2233 | if (predicate(timeRanges.start(i), timeRanges.end(i))) {
|
2234 | results.push([timeRanges.start(i), timeRanges.end(i)]);
|
2235 | }
|
2236 | }
|
2237 | }
|
2238 |
|
2239 | return videojs__default["default"].createTimeRanges(results);
|
2240 | };
|
2241 | |
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 | var findRange = function findRange(buffered, time) {
|
2252 | return filterRanges(buffered, function (start, end) {
|
2253 | return start - SAFE_TIME_DELTA <= time && end + SAFE_TIME_DELTA >= time;
|
2254 | });
|
2255 | };
|
2256 | |
2257 |
|
2258 |
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 | var findNextRange = function findNextRange(timeRanges, time) {
|
2265 | return filterRanges(timeRanges, function (start) {
|
2266 | return start - TIME_FUDGE_FACTOR >= time;
|
2267 | });
|
2268 | };
|
2269 | |
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 | var findGaps = function findGaps(buffered) {
|
2277 | if (buffered.length < 2) {
|
2278 | return videojs__default["default"].createTimeRanges();
|
2279 | }
|
2280 |
|
2281 | var ranges = [];
|
2282 |
|
2283 | for (var i = 1; i < buffered.length; i++) {
|
2284 | var start = buffered.end(i - 1);
|
2285 | var end = buffered.start(i);
|
2286 | ranges.push([start, end]);
|
2287 | }
|
2288 |
|
2289 | return videojs__default["default"].createTimeRanges(ranges);
|
2290 | };
|
2291 | |
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 | var bufferIntersection = function bufferIntersection(bufferA, bufferB) {
|
2300 | var start = null;
|
2301 | var end = null;
|
2302 | var arity = 0;
|
2303 | var extents = [];
|
2304 | var ranges = [];
|
2305 |
|
2306 | if (!bufferA || !bufferA.length || !bufferB || !bufferB.length) {
|
2307 | return videojs__default["default"].createTimeRange();
|
2308 | }
|
2309 |
|
2310 |
|
2311 |
|
2312 | var count = bufferA.length;
|
2313 |
|
2314 | while (count--) {
|
2315 | extents.push({
|
2316 | time: bufferA.start(count),
|
2317 | type: 'start'
|
2318 | });
|
2319 | extents.push({
|
2320 | time: bufferA.end(count),
|
2321 | type: 'end'
|
2322 | });
|
2323 | }
|
2324 |
|
2325 | count = bufferB.length;
|
2326 |
|
2327 | while (count--) {
|
2328 | extents.push({
|
2329 | time: bufferB.start(count),
|
2330 | type: 'start'
|
2331 | });
|
2332 | extents.push({
|
2333 | time: bufferB.end(count),
|
2334 | type: 'end'
|
2335 | });
|
2336 | }
|
2337 |
|
2338 |
|
2339 | extents.sort(function (a, b) {
|
2340 | return a.time - b.time;
|
2341 | });
|
2342 |
|
2343 |
|
2344 | for (count = 0; count < extents.length; count++) {
|
2345 | if (extents[count].type === 'start') {
|
2346 | arity++;
|
2347 |
|
2348 |
|
2349 | if (arity === 2) {
|
2350 | start = extents[count].time;
|
2351 | }
|
2352 | } else if (extents[count].type === 'end') {
|
2353 | arity--;
|
2354 |
|
2355 |
|
2356 | if (arity === 1) {
|
2357 | end = extents[count].time;
|
2358 | }
|
2359 | }
|
2360 |
|
2361 |
|
2362 | if (start !== null && end !== null) {
|
2363 | ranges.push([start, end]);
|
2364 | start = null;
|
2365 | end = null;
|
2366 | }
|
2367 | }
|
2368 |
|
2369 | return videojs__default["default"].createTimeRanges(ranges);
|
2370 | };
|
2371 | |
2372 |
|
2373 |
|
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 | var printableRange = function printableRange(range) {
|
2379 | var strArr = [];
|
2380 |
|
2381 | if (!range || !range.length) {
|
2382 | return '';
|
2383 | }
|
2384 |
|
2385 | for (var i = 0; i < range.length; i++) {
|
2386 | strArr.push(range.start(i) + ' => ' + range.end(i));
|
2387 | }
|
2388 |
|
2389 | return strArr.join(', ');
|
2390 | };
|
2391 | |
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 | var timeUntilRebuffer = function timeUntilRebuffer(buffered, currentTime, playbackRate) {
|
2407 | if (playbackRate === void 0) {
|
2408 | playbackRate = 1;
|
2409 | }
|
2410 |
|
2411 | var bufferedEnd = buffered.length ? buffered.end(buffered.length - 1) : 0;
|
2412 | return (bufferedEnd - currentTime) / playbackRate;
|
2413 | };
|
2414 | |
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 | var timeRangesToArray = function timeRangesToArray(timeRanges) {
|
2422 | var timeRangesList = [];
|
2423 |
|
2424 | for (var i = 0; i < timeRanges.length; i++) {
|
2425 | timeRangesList.push({
|
2426 | start: timeRanges.start(i),
|
2427 | end: timeRanges.end(i)
|
2428 | });
|
2429 | }
|
2430 |
|
2431 | return timeRangesList;
|
2432 | };
|
2433 | |
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 | var isRangeDifferent = function isRangeDifferent(a, b) {
|
2447 |
|
2448 | if (a === b) {
|
2449 | return false;
|
2450 | }
|
2451 |
|
2452 |
|
2453 | if (!a && b || !b && a) {
|
2454 | return true;
|
2455 | }
|
2456 |
|
2457 |
|
2458 | if (a.length !== b.length) {
|
2459 | return true;
|
2460 | }
|
2461 |
|
2462 |
|
2463 | for (var i = 0; i < a.length; i++) {
|
2464 | if (a.start(i) !== b.start(i) || a.end(i) !== b.end(i)) {
|
2465 | return true;
|
2466 | }
|
2467 | }
|
2468 |
|
2469 |
|
2470 |
|
2471 | return false;
|
2472 | };
|
2473 | var lastBufferedEnd = function lastBufferedEnd(a) {
|
2474 | if (!a || !a.length || !a.end) {
|
2475 | return;
|
2476 | }
|
2477 |
|
2478 | return a.end(a.length - 1);
|
2479 | };
|
2480 | |
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 | var timeAheadOf = function timeAheadOf(range, startTime) {
|
2496 | var time = 0;
|
2497 |
|
2498 | if (!range || !range.length) {
|
2499 | return time;
|
2500 | }
|
2501 |
|
2502 | for (var i = 0; i < range.length; i++) {
|
2503 | var start = range.start(i);
|
2504 | var end = range.end(i);
|
2505 |
|
2506 | if (startTime > end) {
|
2507 | continue;
|
2508 | }
|
2509 |
|
2510 |
|
2511 | if (startTime > start && startTime <= end) {
|
2512 | time += end - startTime;
|
2513 | continue;
|
2514 | }
|
2515 |
|
2516 |
|
2517 | time += end - start;
|
2518 | }
|
2519 |
|
2520 | return time;
|
2521 | };
|
2522 |
|
2523 | |
2524 |
|
2525 |
|
2526 |
|
2527 |
|
2528 | var createTimeRange = videojs__default["default"].createTimeRange;
|
2529 | |
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 | var getPartsAndSegments = function getPartsAndSegments(playlist) {
|
2539 | return (playlist.segments || []).reduce(function (acc, segment, si) {
|
2540 | if (segment.parts) {
|
2541 | segment.parts.forEach(function (part, pi) {
|
2542 | acc.push({
|
2543 | duration: part.duration,
|
2544 | segmentIndex: si,
|
2545 | partIndex: pi,
|
2546 | part: part,
|
2547 | segment: segment
|
2548 | });
|
2549 | });
|
2550 | } else {
|
2551 | acc.push({
|
2552 | duration: segment.duration,
|
2553 | segmentIndex: si,
|
2554 | partIndex: null,
|
2555 | segment: segment,
|
2556 | part: null
|
2557 | });
|
2558 | }
|
2559 |
|
2560 | return acc;
|
2561 | }, []);
|
2562 | };
|
2563 | var getLastParts = function getLastParts(media) {
|
2564 | var lastSegment = media.segments && media.segments.length && media.segments[media.segments.length - 1];
|
2565 | return lastSegment && lastSegment.parts || [];
|
2566 | };
|
2567 | var getKnownPartCount = function getKnownPartCount(_ref) {
|
2568 | var preloadSegment = _ref.preloadSegment;
|
2569 |
|
2570 | if (!preloadSegment) {
|
2571 | return;
|
2572 | }
|
2573 |
|
2574 | var parts = preloadSegment.parts,
|
2575 | preloadHints = preloadSegment.preloadHints;
|
2576 | var partCount = (preloadHints || []).reduce(function (count, hint) {
|
2577 | return count + (hint.type === 'PART' ? 1 : 0);
|
2578 | }, 0);
|
2579 | partCount += parts && parts.length ? parts.length : 0;
|
2580 | return partCount;
|
2581 | };
|
2582 | |
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 | var liveEdgeDelay = function liveEdgeDelay(master, media) {
|
2592 | if (media.endList) {
|
2593 | return 0;
|
2594 | }
|
2595 |
|
2596 |
|
2597 | if (master && master.suggestedPresentationDelay) {
|
2598 | return master.suggestedPresentationDelay;
|
2599 | }
|
2600 |
|
2601 | var hasParts = getLastParts(media).length > 0;
|
2602 |
|
2603 | if (hasParts && media.serverControl && media.serverControl.partHoldBack) {
|
2604 | return media.serverControl.partHoldBack;
|
2605 | } else if (hasParts && media.partTargetDuration) {
|
2606 | return media.partTargetDuration * 3;
|
2607 | } else if (media.serverControl && media.serverControl.holdBack) {
|
2608 | return media.serverControl.holdBack;
|
2609 | } else if (media.targetDuration) {
|
2610 | return media.targetDuration * 3;
|
2611 | }
|
2612 |
|
2613 | return 0;
|
2614 | };
|
2615 | |
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 | var backwardDuration = function backwardDuration(playlist, endSequence) {
|
2624 | var result = 0;
|
2625 | var i = endSequence - playlist.mediaSequence;
|
2626 |
|
2627 |
|
2628 | var segment = playlist.segments[i];
|
2629 |
|
2630 |
|
2631 | if (segment) {
|
2632 | if (typeof segment.start !== 'undefined') {
|
2633 | return {
|
2634 | result: segment.start,
|
2635 | precise: true
|
2636 | };
|
2637 | }
|
2638 |
|
2639 | if (typeof segment.end !== 'undefined') {
|
2640 | return {
|
2641 | result: segment.end - segment.duration,
|
2642 | precise: true
|
2643 | };
|
2644 | }
|
2645 | }
|
2646 |
|
2647 | while (i--) {
|
2648 | segment = playlist.segments[i];
|
2649 |
|
2650 | if (typeof segment.end !== 'undefined') {
|
2651 | return {
|
2652 | result: result + segment.end,
|
2653 | precise: true
|
2654 | };
|
2655 | }
|
2656 |
|
2657 | result += segment.duration;
|
2658 |
|
2659 | if (typeof segment.start !== 'undefined') {
|
2660 | return {
|
2661 | result: result + segment.start,
|
2662 | precise: true
|
2663 | };
|
2664 | }
|
2665 | }
|
2666 |
|
2667 | return {
|
2668 | result: result,
|
2669 | precise: false
|
2670 | };
|
2671 | };
|
2672 | |
2673 |
|
2674 |
|
2675 |
|
2676 |
|
2677 |
|
2678 |
|
2679 |
|
2680 |
|
2681 | var forwardDuration = function forwardDuration(playlist, endSequence) {
|
2682 | var result = 0;
|
2683 | var segment;
|
2684 | var i = endSequence - playlist.mediaSequence;
|
2685 |
|
2686 |
|
2687 | for (; i < playlist.segments.length; i++) {
|
2688 | segment = playlist.segments[i];
|
2689 |
|
2690 | if (typeof segment.start !== 'undefined') {
|
2691 | return {
|
2692 | result: segment.start - result,
|
2693 | precise: true
|
2694 | };
|
2695 | }
|
2696 |
|
2697 | result += segment.duration;
|
2698 |
|
2699 | if (typeof segment.end !== 'undefined') {
|
2700 | return {
|
2701 | result: segment.end - result,
|
2702 | precise: true
|
2703 | };
|
2704 | }
|
2705 | }
|
2706 |
|
2707 |
|
2708 | return {
|
2709 | result: -1,
|
2710 | precise: false
|
2711 | };
|
2712 | };
|
2713 | |
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 | var intervalDuration = function intervalDuration(playlist, endSequence, expired) {
|
2729 | if (typeof endSequence === 'undefined') {
|
2730 | endSequence = playlist.mediaSequence + playlist.segments.length;
|
2731 | }
|
2732 |
|
2733 | if (endSequence < playlist.mediaSequence) {
|
2734 | return 0;
|
2735 | }
|
2736 |
|
2737 |
|
2738 | var backward = backwardDuration(playlist, endSequence);
|
2739 |
|
2740 | if (backward.precise) {
|
2741 |
|
2742 |
|
2743 |
|
2744 | return backward.result;
|
2745 | }
|
2746 |
|
2747 |
|
2748 |
|
2749 | var forward = forwardDuration(playlist, endSequence);
|
2750 |
|
2751 | if (forward.precise) {
|
2752 |
|
2753 |
|
2754 | return forward.result;
|
2755 | }
|
2756 |
|
2757 |
|
2758 | return backward.result + expired;
|
2759 | };
|
2760 | |
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 | var duration = function duration(playlist, endSequence, expired) {
|
2778 | if (!playlist) {
|
2779 | return 0;
|
2780 | }
|
2781 |
|
2782 | if (typeof expired !== 'number') {
|
2783 | expired = 0;
|
2784 | }
|
2785 |
|
2786 |
|
2787 |
|
2788 | if (typeof endSequence === 'undefined') {
|
2789 |
|
2790 | if (playlist.totalDuration) {
|
2791 | return playlist.totalDuration;
|
2792 | }
|
2793 |
|
2794 |
|
2795 | if (!playlist.endList) {
|
2796 | return window.Infinity;
|
2797 | }
|
2798 | }
|
2799 |
|
2800 |
|
2801 | return intervalDuration(playlist, endSequence, expired);
|
2802 | };
|
2803 | |
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 | var sumDurations = function sumDurations(_ref2) {
|
2817 | var defaultDuration = _ref2.defaultDuration,
|
2818 | durationList = _ref2.durationList,
|
2819 | startIndex = _ref2.startIndex,
|
2820 | endIndex = _ref2.endIndex;
|
2821 | var durations = 0;
|
2822 |
|
2823 | if (startIndex > endIndex) {
|
2824 | var _ref3 = [endIndex, startIndex];
|
2825 | startIndex = _ref3[0];
|
2826 | endIndex = _ref3[1];
|
2827 | }
|
2828 |
|
2829 | if (startIndex < 0) {
|
2830 | for (var i = startIndex; i < Math.min(0, endIndex); i++) {
|
2831 | durations += defaultDuration;
|
2832 | }
|
2833 |
|
2834 | startIndex = 0;
|
2835 | }
|
2836 |
|
2837 | for (var _i = startIndex; _i < endIndex; _i++) {
|
2838 | durations += durationList[_i].duration;
|
2839 | }
|
2840 |
|
2841 | return durations;
|
2842 | };
|
2843 | |
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 | var playlistEnd = function playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding) {
|
2864 | if (!playlist || !playlist.segments) {
|
2865 | return null;
|
2866 | }
|
2867 |
|
2868 | if (playlist.endList) {
|
2869 | return duration(playlist);
|
2870 | }
|
2871 |
|
2872 | if (expired === null) {
|
2873 | return null;
|
2874 | }
|
2875 |
|
2876 | expired = expired || 0;
|
2877 | var lastSegmentTime = intervalDuration(playlist, playlist.mediaSequence + playlist.segments.length, expired);
|
2878 |
|
2879 | if (useSafeLiveEnd) {
|
2880 | liveEdgePadding = typeof liveEdgePadding === 'number' ? liveEdgePadding : liveEdgeDelay(null, playlist);
|
2881 | lastSegmentTime -= liveEdgePadding;
|
2882 | }
|
2883 |
|
2884 |
|
2885 | return Math.max(0, lastSegmentTime);
|
2886 | };
|
2887 | |
2888 |
|
2889 |
|
2890 |
|
2891 |
|
2892 |
|
2893 |
|
2894 |
|
2895 |
|
2896 |
|
2897 |
|
2898 |
|
2899 |
|
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 | var seekable = function seekable(playlist, expired, liveEdgePadding) {
|
2906 | var useSafeLiveEnd = true;
|
2907 | var seekableStart = expired || 0;
|
2908 | var seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding);
|
2909 |
|
2910 | if (seekableEnd === null) {
|
2911 | return createTimeRange();
|
2912 | }
|
2913 |
|
2914 | return createTimeRange(seekableStart, seekableEnd);
|
2915 | };
|
2916 | |
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 | var getMediaInfoForTime = function getMediaInfoForTime(_ref4) {
|
2931 | var playlist = _ref4.playlist,
|
2932 | currentTime = _ref4.currentTime,
|
2933 | startingSegmentIndex = _ref4.startingSegmentIndex,
|
2934 | startingPartIndex = _ref4.startingPartIndex,
|
2935 | startTime = _ref4.startTime,
|
2936 | experimentalExactManifestTimings = _ref4.experimentalExactManifestTimings;
|
2937 | var time = currentTime - startTime;
|
2938 | var partsAndSegments = getPartsAndSegments(playlist);
|
2939 | var startIndex = 0;
|
2940 |
|
2941 | for (var i = 0; i < partsAndSegments.length; i++) {
|
2942 | var partAndSegment = partsAndSegments[i];
|
2943 |
|
2944 | if (startingSegmentIndex !== partAndSegment.segmentIndex) {
|
2945 | continue;
|
2946 | }
|
2947 |
|
2948 |
|
2949 | if (typeof startingPartIndex === 'number' && typeof partAndSegment.partIndex === 'number' && startingPartIndex !== partAndSegment.partIndex) {
|
2950 | continue;
|
2951 | }
|
2952 |
|
2953 | startIndex = i;
|
2954 | break;
|
2955 | }
|
2956 |
|
2957 | if (time < 0) {
|
2958 |
|
2959 |
|
2960 | if (startIndex > 0) {
|
2961 | for (var _i2 = startIndex - 1; _i2 >= 0; _i2--) {
|
2962 | var _partAndSegment = partsAndSegments[_i2];
|
2963 | time += _partAndSegment.duration;
|
2964 |
|
2965 | if (experimentalExactManifestTimings) {
|
2966 | if (time < 0) {
|
2967 | continue;
|
2968 | }
|
2969 | } else if (time + TIME_FUDGE_FACTOR <= 0) {
|
2970 | continue;
|
2971 | }
|
2972 |
|
2973 | return {
|
2974 | partIndex: _partAndSegment.partIndex,
|
2975 | segmentIndex: _partAndSegment.segmentIndex,
|
2976 | startTime: startTime - sumDurations({
|
2977 | defaultDuration: playlist.targetDuration,
|
2978 | durationList: partsAndSegments,
|
2979 | startIndex: startIndex,
|
2980 | endIndex: _i2
|
2981 | })
|
2982 | };
|
2983 | }
|
2984 | }
|
2985 |
|
2986 |
|
2987 |
|
2988 | return {
|
2989 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
2990 | segmentIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
2991 | startTime: currentTime
|
2992 | };
|
2993 | }
|
2994 |
|
2995 |
|
2996 |
|
2997 |
|
2998 | if (startIndex < 0) {
|
2999 | for (var _i3 = startIndex; _i3 < 0; _i3++) {
|
3000 | time -= playlist.targetDuration;
|
3001 |
|
3002 | if (time < 0) {
|
3003 | return {
|
3004 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
3005 | segmentIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
3006 | startTime: currentTime
|
3007 | };
|
3008 | }
|
3009 | }
|
3010 |
|
3011 | startIndex = 0;
|
3012 | }
|
3013 |
|
3014 |
|
3015 |
|
3016 | for (var _i4 = startIndex; _i4 < partsAndSegments.length; _i4++) {
|
3017 | var _partAndSegment2 = partsAndSegments[_i4];
|
3018 | time -= _partAndSegment2.duration;
|
3019 |
|
3020 | if (experimentalExactManifestTimings) {
|
3021 | if (time > 0) {
|
3022 | continue;
|
3023 | }
|
3024 | } else if (time - TIME_FUDGE_FACTOR >= 0) {
|
3025 | continue;
|
3026 | }
|
3027 |
|
3028 | return {
|
3029 | partIndex: _partAndSegment2.partIndex,
|
3030 | segmentIndex: _partAndSegment2.segmentIndex,
|
3031 | startTime: startTime + sumDurations({
|
3032 | defaultDuration: playlist.targetDuration,
|
3033 | durationList: partsAndSegments,
|
3034 | startIndex: startIndex,
|
3035 | endIndex: _i4
|
3036 | })
|
3037 | };
|
3038 | }
|
3039 |
|
3040 |
|
3041 | return {
|
3042 | segmentIndex: partsAndSegments[partsAndSegments.length - 1].segmentIndex,
|
3043 | partIndex: partsAndSegments[partsAndSegments.length - 1].partIndex,
|
3044 | startTime: currentTime
|
3045 | };
|
3046 | };
|
3047 | |
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 |
|
3054 |
|
3055 | var isBlacklisted = function isBlacklisted(playlist) {
|
3056 | return playlist.excludeUntil && playlist.excludeUntil > Date.now();
|
3057 | };
|
3058 | |
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 | var isIncompatible = function isIncompatible(playlist) {
|
3068 | return playlist.excludeUntil && playlist.excludeUntil === Infinity;
|
3069 | };
|
3070 | |
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 | var isEnabled = function isEnabled(playlist) {
|
3079 | var blacklisted = isBlacklisted(playlist);
|
3080 | return !playlist.disabled && !blacklisted;
|
3081 | };
|
3082 | |
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 | var isDisabled = function isDisabled(playlist) {
|
3091 | return playlist.disabled;
|
3092 | };
|
3093 | |
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 | var isAes = function isAes(media) {
|
3100 | for (var i = 0; i < media.segments.length; i++) {
|
3101 | if (media.segments[i].key) {
|
3102 | return true;
|
3103 | }
|
3104 | }
|
3105 |
|
3106 | return false;
|
3107 | };
|
3108 | |
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 | var hasAttribute = function hasAttribute(attr, playlist) {
|
3121 | return playlist.attributes && playlist.attributes[attr];
|
3122 | };
|
3123 | |
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 | var estimateSegmentRequestTime = function estimateSegmentRequestTime(segmentDuration, bandwidth, playlist, bytesReceived) {
|
3141 | if (bytesReceived === void 0) {
|
3142 | bytesReceived = 0;
|
3143 | }
|
3144 |
|
3145 | if (!hasAttribute('BANDWIDTH', playlist)) {
|
3146 | return NaN;
|
3147 | }
|
3148 |
|
3149 | var size = segmentDuration * playlist.attributes.BANDWIDTH;
|
3150 | return (size - bytesReceived * 8) / bandwidth;
|
3151 | };
|
3152 | |
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 | var isLowestEnabledRendition = function isLowestEnabledRendition(master, media) {
|
3159 | if (master.playlists.length === 1) {
|
3160 | return true;
|
3161 | }
|
3162 |
|
3163 | var currentBandwidth = media.attributes.BANDWIDTH || Number.MAX_VALUE;
|
3164 | return master.playlists.filter(function (playlist) {
|
3165 | if (!isEnabled(playlist)) {
|
3166 | return false;
|
3167 | }
|
3168 |
|
3169 | return (playlist.attributes.BANDWIDTH || 0) < currentBandwidth;
|
3170 | }).length === 0;
|
3171 | };
|
3172 | var playlistMatch = function playlistMatch(a, b) {
|
3173 |
|
3174 |
|
3175 |
|
3176 | if (!a && !b || !a && b || a && !b) {
|
3177 | return false;
|
3178 | }
|
3179 |
|
3180 |
|
3181 | if (a === b) {
|
3182 | return true;
|
3183 | }
|
3184 |
|
3185 |
|
3186 |
|
3187 | if (a.id && b.id && a.id === b.id) {
|
3188 | return true;
|
3189 | }
|
3190 |
|
3191 |
|
3192 |
|
3193 | if (a.resolvedUri && b.resolvedUri && a.resolvedUri === b.resolvedUri) {
|
3194 | return true;
|
3195 | }
|
3196 |
|
3197 |
|
3198 |
|
3199 | if (a.uri && b.uri && a.uri === b.uri) {
|
3200 | return true;
|
3201 | }
|
3202 |
|
3203 | return false;
|
3204 | };
|
3205 |
|
3206 | var someAudioVariant = function someAudioVariant(master, callback) {
|
3207 | var AUDIO = master && master.mediaGroups && master.mediaGroups.AUDIO || {};
|
3208 | var found = false;
|
3209 |
|
3210 | for (var groupName in AUDIO) {
|
3211 | for (var label in AUDIO[groupName]) {
|
3212 | found = callback(AUDIO[groupName][label]);
|
3213 |
|
3214 | if (found) {
|
3215 | break;
|
3216 | }
|
3217 | }
|
3218 |
|
3219 | if (found) {
|
3220 | break;
|
3221 | }
|
3222 | }
|
3223 |
|
3224 | return !!found;
|
3225 | };
|
3226 |
|
3227 | var isAudioOnly = function isAudioOnly(master) {
|
3228 |
|
3229 |
|
3230 | if (!master || !master.playlists || !master.playlists.length) {
|
3231 |
|
3232 |
|
3233 | var found = someAudioVariant(master, function (variant) {
|
3234 | return variant.playlists && variant.playlists.length || variant.uri;
|
3235 | });
|
3236 | return found;
|
3237 | }
|
3238 |
|
3239 |
|
3240 | var _loop = function _loop(i) {
|
3241 | var playlist = master.playlists[i];
|
3242 | var CODECS = playlist.attributes && playlist.attributes.CODECS;
|
3243 |
|
3244 | if (CODECS && CODECS.split(',').every(function (c) {
|
3245 | return isAudioCodec(c);
|
3246 | })) {
|
3247 | return "continue";
|
3248 | }
|
3249 |
|
3250 |
|
3251 | var found = someAudioVariant(master, function (variant) {
|
3252 | return playlistMatch(playlist, variant);
|
3253 | });
|
3254 |
|
3255 | if (found) {
|
3256 | return "continue";
|
3257 | }
|
3258 |
|
3259 |
|
3260 |
|
3261 | return {
|
3262 | v: false
|
3263 | };
|
3264 | };
|
3265 |
|
3266 | for (var i = 0; i < master.playlists.length; i++) {
|
3267 | var _ret = _loop(i);
|
3268 |
|
3269 | if (_ret === "continue") continue;
|
3270 | if (typeof _ret === "object") return _ret.v;
|
3271 | }
|
3272 |
|
3273 |
|
3274 |
|
3275 | return true;
|
3276 | };
|
3277 |
|
3278 | var Playlist = {
|
3279 | liveEdgeDelay: liveEdgeDelay,
|
3280 | duration: duration,
|
3281 | seekable: seekable,
|
3282 | getMediaInfoForTime: getMediaInfoForTime,
|
3283 | isEnabled: isEnabled,
|
3284 | isDisabled: isDisabled,
|
3285 | isBlacklisted: isBlacklisted,
|
3286 | isIncompatible: isIncompatible,
|
3287 | playlistEnd: playlistEnd,
|
3288 | isAes: isAes,
|
3289 | hasAttribute: hasAttribute,
|
3290 | estimateSegmentRequestTime: estimateSegmentRequestTime,
|
3291 | isLowestEnabledRendition: isLowestEnabledRendition,
|
3292 | isAudioOnly: isAudioOnly,
|
3293 | playlistMatch: playlistMatch
|
3294 | };
|
3295 |
|
3296 | var log = videojs__default["default"].log;
|
3297 | var createPlaylistID = function createPlaylistID(index, uri) {
|
3298 | return index + "-" + uri;
|
3299 | };
|
3300 | |
3301 |
|
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 | var parseManifest = function parseManifest(_ref) {
|
3320 | var onwarn = _ref.onwarn,
|
3321 | oninfo = _ref.oninfo,
|
3322 | manifestString = _ref.manifestString,
|
3323 | _ref$customTagParsers = _ref.customTagParsers,
|
3324 | customTagParsers = _ref$customTagParsers === void 0 ? [] : _ref$customTagParsers,
|
3325 | _ref$customTagMappers = _ref.customTagMappers,
|
3326 | customTagMappers = _ref$customTagMappers === void 0 ? [] : _ref$customTagMappers,
|
3327 | experimentalLLHLS = _ref.experimentalLLHLS;
|
3328 | var parser = new Parser();
|
3329 |
|
3330 | if (onwarn) {
|
3331 | parser.on('warn', onwarn);
|
3332 | }
|
3333 |
|
3334 | if (oninfo) {
|
3335 | parser.on('info', oninfo);
|
3336 | }
|
3337 |
|
3338 | customTagParsers.forEach(function (customParser) {
|
3339 | return parser.addParser(customParser);
|
3340 | });
|
3341 | customTagMappers.forEach(function (mapper) {
|
3342 | return parser.addTagMapper(mapper);
|
3343 | });
|
3344 | parser.push(manifestString);
|
3345 | parser.end();
|
3346 | var manifest = parser.manifest;
|
3347 |
|
3348 |
|
3349 | if (!experimentalLLHLS) {
|
3350 | ['preloadSegment', 'skip', 'serverControl', 'renditionReports', 'partInf', 'partTargetDuration'].forEach(function (k) {
|
3351 | if (manifest.hasOwnProperty(k)) {
|
3352 | delete manifest[k];
|
3353 | }
|
3354 | });
|
3355 |
|
3356 | if (manifest.segments) {
|
3357 | manifest.segments.forEach(function (segment) {
|
3358 | ['parts', 'preloadHints'].forEach(function (k) {
|
3359 | if (segment.hasOwnProperty(k)) {
|
3360 | delete segment[k];
|
3361 | }
|
3362 | });
|
3363 | });
|
3364 | }
|
3365 | }
|
3366 |
|
3367 | if (!manifest.targetDuration) {
|
3368 | var targetDuration = 10;
|
3369 |
|
3370 | if (manifest.segments && manifest.segments.length) {
|
3371 | targetDuration = manifest.segments.reduce(function (acc, s) {
|
3372 | return Math.max(acc, s.duration);
|
3373 | }, 0);
|
3374 | }
|
3375 |
|
3376 | if (onwarn) {
|
3377 | onwarn("manifest has no targetDuration defaulting to " + targetDuration);
|
3378 | }
|
3379 |
|
3380 | manifest.targetDuration = targetDuration;
|
3381 | }
|
3382 |
|
3383 | var parts = getLastParts(manifest);
|
3384 |
|
3385 | if (parts.length && !manifest.partTargetDuration) {
|
3386 | var partTargetDuration = parts.reduce(function (acc, p) {
|
3387 | return Math.max(acc, p.duration);
|
3388 | }, 0);
|
3389 |
|
3390 | if (onwarn) {
|
3391 | onwarn("manifest has no partTargetDuration defaulting to " + partTargetDuration);
|
3392 | log.error('LL-HLS manifest has parts but lacks required #EXT-X-PART-INF:PART-TARGET value. See https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-09#section-4.4.3.7. Playback is not guaranteed.');
|
3393 | }
|
3394 |
|
3395 | manifest.partTargetDuration = partTargetDuration;
|
3396 | }
|
3397 |
|
3398 | return manifest;
|
3399 | };
|
3400 | |
3401 |
|
3402 |
|
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 | var forEachMediaGroup = function forEachMediaGroup(master, callback) {
|
3411 | if (!master.mediaGroups) {
|
3412 | return;
|
3413 | }
|
3414 |
|
3415 | ['AUDIO', 'SUBTITLES'].forEach(function (mediaType) {
|
3416 | if (!master.mediaGroups[mediaType]) {
|
3417 | return;
|
3418 | }
|
3419 |
|
3420 | for (var groupKey in master.mediaGroups[mediaType]) {
|
3421 | for (var labelKey in master.mediaGroups[mediaType][groupKey]) {
|
3422 | var mediaProperties = master.mediaGroups[mediaType][groupKey][labelKey];
|
3423 | callback(mediaProperties, mediaType, groupKey, labelKey);
|
3424 | }
|
3425 | }
|
3426 | });
|
3427 | };
|
3428 | |
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 | var setupMediaPlaylist = function setupMediaPlaylist(_ref2) {
|
3444 | var playlist = _ref2.playlist,
|
3445 | uri = _ref2.uri,
|
3446 | id = _ref2.id;
|
3447 | playlist.id = id;
|
3448 | playlist.playlistErrors_ = 0;
|
3449 |
|
3450 | if (uri) {
|
3451 |
|
3452 |
|
3453 |
|
3454 | playlist.uri = uri;
|
3455 | }
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 | playlist.attributes = playlist.attributes || {};
|
3465 | };
|
3466 | |
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 | var setupMediaPlaylists = function setupMediaPlaylists(master) {
|
3476 | var i = master.playlists.length;
|
3477 |
|
3478 | while (i--) {
|
3479 | var playlist = master.playlists[i];
|
3480 | setupMediaPlaylist({
|
3481 | playlist: playlist,
|
3482 | id: createPlaylistID(i, playlist.uri)
|
3483 | });
|
3484 | playlist.resolvedUri = resolveUrl(master.uri, playlist.uri);
|
3485 | master.playlists[playlist.id] = playlist;
|
3486 |
|
3487 | master.playlists[playlist.uri] = playlist;
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 | if (!playlist.attributes.BANDWIDTH) {
|
3493 | log.warn('Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute.');
|
3494 | }
|
3495 | }
|
3496 | };
|
3497 | |
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 | var resolveMediaGroupUris = function resolveMediaGroupUris(master) {
|
3505 | forEachMediaGroup(master, function (properties) {
|
3506 | if (properties.uri) {
|
3507 | properties.resolvedUri = resolveUrl(master.uri, properties.uri);
|
3508 | }
|
3509 | });
|
3510 | };
|
3511 | |
3512 |
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 | var masterForMedia = function masterForMedia(media, uri) {
|
3524 | var id = createPlaylistID(0, uri);
|
3525 | var master = {
|
3526 | mediaGroups: {
|
3527 | 'AUDIO': {},
|
3528 | 'VIDEO': {},
|
3529 | 'CLOSED-CAPTIONS': {},
|
3530 | 'SUBTITLES': {}
|
3531 | },
|
3532 | uri: window.location.href,
|
3533 | resolvedUri: window.location.href,
|
3534 | playlists: [{
|
3535 | uri: uri,
|
3536 | id: id,
|
3537 | resolvedUri: uri,
|
3538 |
|
3539 |
|
3540 | attributes: {}
|
3541 | }]
|
3542 | };
|
3543 |
|
3544 | master.playlists[id] = master.playlists[0];
|
3545 |
|
3546 | master.playlists[uri] = master.playlists[0];
|
3547 | return master;
|
3548 | };
|
3549 | |
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 | var addPropertiesToMaster = function addPropertiesToMaster(master, uri) {
|
3560 | master.uri = uri;
|
3561 |
|
3562 | for (var i = 0; i < master.playlists.length; i++) {
|
3563 | if (!master.playlists[i].uri) {
|
3564 |
|
3565 |
|
3566 |
|
3567 | var phonyUri = "placeholder-uri-" + i;
|
3568 | master.playlists[i].uri = phonyUri;
|
3569 | }
|
3570 | }
|
3571 |
|
3572 | var audioOnlyMaster = isAudioOnly(master);
|
3573 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
3574 | var groupId = "placeholder-uri-" + mediaType + "-" + groupKey + "-" + labelKey;
|
3575 |
|
3576 | if (!properties.playlists || !properties.playlists.length) {
|
3577 |
|
3578 |
|
3579 |
|
3580 | if (audioOnlyMaster && mediaType === 'AUDIO' && !properties.uri) {
|
3581 | for (var _i = 0; _i < master.playlists.length; _i++) {
|
3582 | var p = master.playlists[_i];
|
3583 |
|
3584 | if (p.attributes && p.attributes.AUDIO && p.attributes.AUDIO === groupKey) {
|
3585 | return;
|
3586 | }
|
3587 | }
|
3588 | }
|
3589 |
|
3590 | properties.playlists = [_extends_1({}, properties)];
|
3591 | }
|
3592 |
|
3593 | properties.playlists.forEach(function (p, i) {
|
3594 | var id = createPlaylistID(i, groupId);
|
3595 |
|
3596 | if (p.uri) {
|
3597 | p.resolvedUri = p.resolvedUri || resolveUrl(master.uri, p.uri);
|
3598 | } else {
|
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 | p.uri = i === 0 ? groupId : id;
|
3604 |
|
3605 |
|
3606 | p.resolvedUri = p.uri;
|
3607 | }
|
3608 |
|
3609 | p.id = p.id || id;
|
3610 |
|
3611 |
|
3612 | p.attributes = p.attributes || {};
|
3613 |
|
3614 | master.playlists[p.id] = p;
|
3615 | master.playlists[p.uri] = p;
|
3616 | });
|
3617 | });
|
3618 | setupMediaPlaylists(master);
|
3619 | resolveMediaGroupUris(master);
|
3620 | };
|
3621 |
|
3622 | var mergeOptions$2 = videojs__default["default"].mergeOptions,
|
3623 | EventTarget$1 = videojs__default["default"].EventTarget;
|
3624 |
|
3625 | var addLLHLSQueryDirectives = function addLLHLSQueryDirectives(uri, media) {
|
3626 | if (media.endList || !media.serverControl) {
|
3627 | return uri;
|
3628 | }
|
3629 |
|
3630 | var parameters = {};
|
3631 |
|
3632 | if (media.serverControl.canBlockReload) {
|
3633 | var preloadSegment = media.preloadSegment;
|
3634 |
|
3635 | var nextMSN = media.mediaSequence + media.segments.length;
|
3636 |
|
3637 |
|
3638 |
|
3639 | if (preloadSegment) {
|
3640 | var parts = preloadSegment.parts || [];
|
3641 |
|
3642 | var nextPart = getKnownPartCount(media) - 1;
|
3643 |
|
3644 |
|
3645 |
|
3646 | if (nextPart > -1 && nextPart !== parts.length - 1) {
|
3647 |
|
3648 |
|
3649 | parameters._HLS_part = nextPart;
|
3650 | }
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 | if (nextPart > -1 || parts.length) {
|
3662 | nextMSN--;
|
3663 | }
|
3664 | }
|
3665 |
|
3666 |
|
3667 |
|
3668 | parameters._HLS_msn = nextMSN;
|
3669 | }
|
3670 |
|
3671 | if (media.serverControl && media.serverControl.canSkipUntil) {
|
3672 |
|
3673 |
|
3674 | parameters._HLS_skip = media.serverControl.canSkipDateranges ? 'v2' : 'YES';
|
3675 | }
|
3676 |
|
3677 | if (Object.keys(parameters).length) {
|
3678 | var parsedUri = new window.URL(uri);
|
3679 | ['_HLS_skip', '_HLS_msn', '_HLS_part'].forEach(function (name) {
|
3680 | if (!parameters.hasOwnProperty(name)) {
|
3681 | return;
|
3682 | }
|
3683 |
|
3684 | parsedUri.searchParams.set(name, parameters[name]);
|
3685 | });
|
3686 | uri = parsedUri.toString();
|
3687 | }
|
3688 |
|
3689 | return uri;
|
3690 | };
|
3691 | |
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 |
|
3700 |
|
3701 |
|
3702 | var updateSegment = function updateSegment(a, b) {
|
3703 | if (!a) {
|
3704 | return b;
|
3705 | }
|
3706 |
|
3707 | var result = mergeOptions$2(a, b);
|
3708 |
|
3709 |
|
3710 | if (a.preloadHints && !b.preloadHints) {
|
3711 | delete result.preloadHints;
|
3712 | }
|
3713 |
|
3714 |
|
3715 |
|
3716 | if (a.parts && !b.parts) {
|
3717 | delete result.parts;
|
3718 |
|
3719 |
|
3720 | } else if (a.parts && b.parts) {
|
3721 | for (var i = 0; i < b.parts.length; i++) {
|
3722 | if (a.parts && a.parts[i]) {
|
3723 | result.parts[i] = mergeOptions$2(a.parts[i], b.parts[i]);
|
3724 | }
|
3725 | }
|
3726 | }
|
3727 |
|
3728 |
|
3729 |
|
3730 | if (!a.skipped && b.skipped) {
|
3731 | result.skipped = false;
|
3732 | }
|
3733 |
|
3734 |
|
3735 |
|
3736 | if (a.preload && !b.preload) {
|
3737 | result.preload = false;
|
3738 | }
|
3739 |
|
3740 | return result;
|
3741 | };
|
3742 | |
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 | var updateSegments = function updateSegments(original, update, offset) {
|
3759 | var oldSegments = original.slice();
|
3760 | var newSegments = update.slice();
|
3761 | offset = offset || 0;
|
3762 | var result = [];
|
3763 | var currentMap;
|
3764 |
|
3765 | for (var newIndex = 0; newIndex < newSegments.length; newIndex++) {
|
3766 | var oldSegment = oldSegments[newIndex + offset];
|
3767 | var newSegment = newSegments[newIndex];
|
3768 |
|
3769 | if (oldSegment) {
|
3770 | currentMap = oldSegment.map || currentMap;
|
3771 | result.push(updateSegment(oldSegment, newSegment));
|
3772 | } else {
|
3773 |
|
3774 | if (currentMap && !newSegment.map) {
|
3775 | newSegment.map = currentMap;
|
3776 | }
|
3777 |
|
3778 | result.push(newSegment);
|
3779 | }
|
3780 | }
|
3781 |
|
3782 | return result;
|
3783 | };
|
3784 | var resolveSegmentUris = function resolveSegmentUris(segment, baseUri) {
|
3785 |
|
3786 |
|
3787 | if (!segment.resolvedUri && segment.uri) {
|
3788 | segment.resolvedUri = resolveUrl(baseUri, segment.uri);
|
3789 | }
|
3790 |
|
3791 | if (segment.key && !segment.key.resolvedUri) {
|
3792 | segment.key.resolvedUri = resolveUrl(baseUri, segment.key.uri);
|
3793 | }
|
3794 |
|
3795 | if (segment.map && !segment.map.resolvedUri) {
|
3796 | segment.map.resolvedUri = resolveUrl(baseUri, segment.map.uri);
|
3797 | }
|
3798 |
|
3799 | if (segment.map && segment.map.key && !segment.map.key.resolvedUri) {
|
3800 | segment.map.key.resolvedUri = resolveUrl(baseUri, segment.map.key.uri);
|
3801 | }
|
3802 |
|
3803 | if (segment.parts && segment.parts.length) {
|
3804 | segment.parts.forEach(function (p) {
|
3805 | if (p.resolvedUri) {
|
3806 | return;
|
3807 | }
|
3808 |
|
3809 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
3810 | });
|
3811 | }
|
3812 |
|
3813 | if (segment.preloadHints && segment.preloadHints.length) {
|
3814 | segment.preloadHints.forEach(function (p) {
|
3815 | if (p.resolvedUri) {
|
3816 | return;
|
3817 | }
|
3818 |
|
3819 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
3820 | });
|
3821 | }
|
3822 | };
|
3823 |
|
3824 | var getAllSegments = function getAllSegments(media) {
|
3825 | var segments = media.segments || [];
|
3826 | var preloadSegment = media.preloadSegment;
|
3827 |
|
3828 |
|
3829 |
|
3830 | if (preloadSegment && preloadSegment.parts && preloadSegment.parts.length) {
|
3831 |
|
3832 |
|
3833 |
|
3834 | if (preloadSegment.preloadHints) {
|
3835 | for (var i = 0; i < preloadSegment.preloadHints.length; i++) {
|
3836 | if (preloadSegment.preloadHints[i].type === 'MAP') {
|
3837 | return segments;
|
3838 | }
|
3839 | }
|
3840 | }
|
3841 |
|
3842 |
|
3843 | preloadSegment.duration = media.targetDuration;
|
3844 | preloadSegment.preload = true;
|
3845 | segments.push(preloadSegment);
|
3846 | }
|
3847 |
|
3848 | return segments;
|
3849 | };
|
3850 |
|
3851 |
|
3852 |
|
3853 |
|
3854 | var isPlaylistUnchanged = function isPlaylistUnchanged(a, b) {
|
3855 | return a === b || a.segments && b.segments && a.segments.length === b.segments.length && a.endList === b.endList && a.mediaSequence === b.mediaSequence;
|
3856 | };
|
3857 | |
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 | var updateMaster$1 = function updateMaster(master, newMedia, unchangedCheck) {
|
3871 | if (unchangedCheck === void 0) {
|
3872 | unchangedCheck = isPlaylistUnchanged;
|
3873 | }
|
3874 |
|
3875 | var result = mergeOptions$2(master, {});
|
3876 | var oldMedia = result.playlists[newMedia.id];
|
3877 |
|
3878 | if (!oldMedia) {
|
3879 | return null;
|
3880 | }
|
3881 |
|
3882 | if (unchangedCheck(oldMedia, newMedia)) {
|
3883 | return null;
|
3884 | }
|
3885 |
|
3886 | newMedia.segments = getAllSegments(newMedia);
|
3887 | var mergedPlaylist = mergeOptions$2(oldMedia, newMedia);
|
3888 |
|
3889 | if (mergedPlaylist.preloadSegment && !newMedia.preloadSegment) {
|
3890 | delete mergedPlaylist.preloadSegment;
|
3891 | }
|
3892 |
|
3893 |
|
3894 | if (oldMedia.segments) {
|
3895 | if (newMedia.skip) {
|
3896 | newMedia.segments = newMedia.segments || [];
|
3897 |
|
3898 |
|
3899 | for (var i = 0; i < newMedia.skip.skippedSegments; i++) {
|
3900 | newMedia.segments.unshift({
|
3901 | skipped: true
|
3902 | });
|
3903 | }
|
3904 | }
|
3905 |
|
3906 | mergedPlaylist.segments = updateSegments(oldMedia.segments, newMedia.segments, newMedia.mediaSequence - oldMedia.mediaSequence);
|
3907 | }
|
3908 |
|
3909 |
|
3910 | mergedPlaylist.segments.forEach(function (segment) {
|
3911 | resolveSegmentUris(segment, mergedPlaylist.resolvedUri);
|
3912 | });
|
3913 |
|
3914 |
|
3915 |
|
3916 | for (var _i = 0; _i < result.playlists.length; _i++) {
|
3917 | if (result.playlists[_i].id === newMedia.id) {
|
3918 | result.playlists[_i] = mergedPlaylist;
|
3919 | }
|
3920 | }
|
3921 |
|
3922 | result.playlists[newMedia.id] = mergedPlaylist;
|
3923 |
|
3924 | result.playlists[newMedia.uri] = mergedPlaylist;
|
3925 |
|
3926 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
3927 | if (!properties.playlists) {
|
3928 | return;
|
3929 | }
|
3930 |
|
3931 | for (var _i2 = 0; _i2 < properties.playlists.length; _i2++) {
|
3932 | if (newMedia.id === properties.playlists[_i2].id) {
|
3933 | properties.playlists[_i2] = newMedia;
|
3934 | }
|
3935 | }
|
3936 | });
|
3937 | return result;
|
3938 | };
|
3939 | |
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 | var refreshDelay = function refreshDelay(media, update) {
|
3951 | var segments = media.segments || [];
|
3952 | var lastSegment = segments[segments.length - 1];
|
3953 | var lastPart = lastSegment && lastSegment.parts && lastSegment.parts[lastSegment.parts.length - 1];
|
3954 | var lastDuration = lastPart && lastPart.duration || lastSegment && lastSegment.duration;
|
3955 |
|
3956 | if (update && lastDuration) {
|
3957 | return lastDuration * 1000;
|
3958 | }
|
3959 |
|
3960 |
|
3961 |
|
3962 | return (media.partTargetDuration || media.targetDuration || 10) * 500;
|
3963 | };
|
3964 | |
3965 |
|
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 | var PlaylistLoader = function (_EventTarget) {
|
3975 | inheritsLoose(PlaylistLoader, _EventTarget);
|
3976 |
|
3977 | function PlaylistLoader(src, vhs, options) {
|
3978 | var _this;
|
3979 |
|
3980 | if (options === void 0) {
|
3981 | options = {};
|
3982 | }
|
3983 |
|
3984 | _this = _EventTarget.call(this) || this;
|
3985 |
|
3986 | if (!src) {
|
3987 | throw new Error('A non-empty playlist URL or object is required');
|
3988 | }
|
3989 |
|
3990 | _this.logger_ = logger('PlaylistLoader');
|
3991 | var _options = options,
|
3992 | _options$withCredenti = _options.withCredentials,
|
3993 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
3994 | _options$handleManife = _options.handleManifestRedirects,
|
3995 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
3996 | _this.src = src;
|
3997 | _this.vhs_ = vhs;
|
3998 | _this.withCredentials = withCredentials;
|
3999 | _this.handleManifestRedirects = handleManifestRedirects;
|
4000 | var vhsOptions = vhs.options_;
|
4001 | _this.customTagParsers = vhsOptions && vhsOptions.customTagParsers || [];
|
4002 | _this.customTagMappers = vhsOptions && vhsOptions.customTagMappers || [];
|
4003 | _this.experimentalLLHLS = vhsOptions && vhsOptions.experimentalLLHLS || false;
|
4004 |
|
4005 | if (videojs__default["default"].browser.IE_VERSION) {
|
4006 | _this.experimentalLLHLS = false;
|
4007 | }
|
4008 |
|
4009 |
|
4010 | _this.state = 'HAVE_NOTHING';
|
4011 |
|
4012 | _this.handleMediaupdatetimeout_ = _this.handleMediaupdatetimeout_.bind(assertThisInitialized(_this));
|
4013 |
|
4014 | _this.on('mediaupdatetimeout', _this.handleMediaupdatetimeout_);
|
4015 |
|
4016 | return _this;
|
4017 | }
|
4018 |
|
4019 | var _proto = PlaylistLoader.prototype;
|
4020 |
|
4021 | _proto.handleMediaupdatetimeout_ = function handleMediaupdatetimeout_() {
|
4022 | var _this2 = this;
|
4023 |
|
4024 | if (this.state !== 'HAVE_METADATA') {
|
4025 |
|
4026 | return;
|
4027 | }
|
4028 |
|
4029 | var media = this.media();
|
4030 | var uri = resolveUrl(this.master.uri, media.uri);
|
4031 |
|
4032 | if (this.experimentalLLHLS) {
|
4033 | uri = addLLHLSQueryDirectives(uri, media);
|
4034 | }
|
4035 |
|
4036 | this.state = 'HAVE_CURRENT_METADATA';
|
4037 | this.request = this.vhs_.xhr({
|
4038 | uri: uri,
|
4039 | withCredentials: this.withCredentials
|
4040 | }, function (error, req) {
|
4041 |
|
4042 | if (!_this2.request) {
|
4043 | return;
|
4044 | }
|
4045 |
|
4046 | if (error) {
|
4047 | return _this2.playlistRequestError(_this2.request, _this2.media(), 'HAVE_METADATA');
|
4048 | }
|
4049 |
|
4050 | _this2.haveMetadata({
|
4051 | playlistString: _this2.request.responseText,
|
4052 | url: _this2.media().uri,
|
4053 | id: _this2.media().id
|
4054 | });
|
4055 | });
|
4056 | };
|
4057 |
|
4058 | _proto.playlistRequestError = function playlistRequestError(xhr, playlist, startingState) {
|
4059 | var uri = playlist.uri,
|
4060 | id = playlist.id;
|
4061 |
|
4062 | this.request = null;
|
4063 |
|
4064 | if (startingState) {
|
4065 | this.state = startingState;
|
4066 | }
|
4067 |
|
4068 | this.error = {
|
4069 | playlist: this.master.playlists[id],
|
4070 | status: xhr.status,
|
4071 | message: "HLS playlist request error at URL: " + uri + ".",
|
4072 | responseText: xhr.responseText,
|
4073 | code: xhr.status >= 500 ? 4 : 2
|
4074 | };
|
4075 | this.trigger('error');
|
4076 | };
|
4077 |
|
4078 | _proto.parseManifest_ = function parseManifest_(_ref) {
|
4079 | var _this3 = this;
|
4080 |
|
4081 | var url = _ref.url,
|
4082 | manifestString = _ref.manifestString;
|
4083 | return parseManifest({
|
4084 | onwarn: function onwarn(_ref2) {
|
4085 | var message = _ref2.message;
|
4086 | return _this3.logger_("m3u8-parser warn for " + url + ": " + message);
|
4087 | },
|
4088 | oninfo: function oninfo(_ref3) {
|
4089 | var message = _ref3.message;
|
4090 | return _this3.logger_("m3u8-parser info for " + url + ": " + message);
|
4091 | },
|
4092 | manifestString: manifestString,
|
4093 | customTagParsers: this.customTagParsers,
|
4094 | customTagMappers: this.customTagMappers,
|
4095 | experimentalLLHLS: this.experimentalLLHLS
|
4096 | });
|
4097 | }
|
4098 | |
4099 |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 | ;
|
4111 |
|
4112 | _proto.haveMetadata = function haveMetadata(_ref4) {
|
4113 | var playlistString = _ref4.playlistString,
|
4114 | playlistObject = _ref4.playlistObject,
|
4115 | url = _ref4.url,
|
4116 | id = _ref4.id;
|
4117 |
|
4118 | this.request = null;
|
4119 | this.state = 'HAVE_METADATA';
|
4120 | var playlist = playlistObject || this.parseManifest_({
|
4121 | url: url,
|
4122 | manifestString: playlistString
|
4123 | });
|
4124 | playlist.lastRequest = Date.now();
|
4125 | setupMediaPlaylist({
|
4126 | playlist: playlist,
|
4127 | uri: url,
|
4128 | id: id
|
4129 | });
|
4130 |
|
4131 | var update = updateMaster$1(this.master, playlist);
|
4132 | this.targetDuration = playlist.partTargetDuration || playlist.targetDuration;
|
4133 |
|
4134 | if (update) {
|
4135 | this.master = update;
|
4136 | this.media_ = this.master.playlists[id];
|
4137 | } else {
|
4138 | this.trigger('playlistunchanged');
|
4139 | }
|
4140 |
|
4141 | this.updateMediaUpdateTimeout_(refreshDelay(this.media(), !!update));
|
4142 | this.trigger('loadedplaylist');
|
4143 | }
|
4144 | |
4145 |
|
4146 |
|
4147 | ;
|
4148 |
|
4149 | _proto.dispose = function dispose() {
|
4150 | this.trigger('dispose');
|
4151 | this.stopRequest();
|
4152 | window.clearTimeout(this.mediaUpdateTimeout);
|
4153 | window.clearTimeout(this.finalRenditionTimeout);
|
4154 | this.off();
|
4155 | };
|
4156 |
|
4157 | _proto.stopRequest = function stopRequest() {
|
4158 | if (this.request) {
|
4159 | var oldRequest = this.request;
|
4160 | this.request = null;
|
4161 | oldRequest.onreadystatechange = null;
|
4162 | oldRequest.abort();
|
4163 | }
|
4164 | }
|
4165 | |
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 |
|
4177 |
|
4178 |
|
4179 | ;
|
4180 |
|
4181 | _proto.media = function media(playlist, shouldDelay) {
|
4182 | var _this4 = this;
|
4183 |
|
4184 |
|
4185 | if (!playlist) {
|
4186 | return this.media_;
|
4187 | }
|
4188 |
|
4189 |
|
4190 | if (this.state === 'HAVE_NOTHING') {
|
4191 | throw new Error('Cannot switch media playlist from ' + this.state);
|
4192 | }
|
4193 |
|
4194 |
|
4195 |
|
4196 | if (typeof playlist === 'string') {
|
4197 | if (!this.master.playlists[playlist]) {
|
4198 | throw new Error('Unknown playlist URI: ' + playlist);
|
4199 | }
|
4200 |
|
4201 | playlist = this.master.playlists[playlist];
|
4202 | }
|
4203 |
|
4204 | window.clearTimeout(this.finalRenditionTimeout);
|
4205 |
|
4206 | if (shouldDelay) {
|
4207 | var delay = (playlist.partTargetDuration || playlist.targetDuration) / 2 * 1000 || 5 * 1000;
|
4208 | this.finalRenditionTimeout = window.setTimeout(this.media.bind(this, playlist, false), delay);
|
4209 | return;
|
4210 | }
|
4211 |
|
4212 | var startingState = this.state;
|
4213 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
4214 | var masterPlaylistRef = this.master.playlists[playlist.id];
|
4215 |
|
4216 | if (masterPlaylistRef && masterPlaylistRef.endList ||
|
4217 |
|
4218 | playlist.endList && playlist.segments.length) {
|
4219 |
|
4220 | if (this.request) {
|
4221 | this.request.onreadystatechange = null;
|
4222 | this.request.abort();
|
4223 | this.request = null;
|
4224 | }
|
4225 |
|
4226 | this.state = 'HAVE_METADATA';
|
4227 | this.media_ = playlist;
|
4228 |
|
4229 | if (mediaChange) {
|
4230 | this.trigger('mediachanging');
|
4231 |
|
4232 | if (startingState === 'HAVE_MASTER') {
|
4233 |
|
4234 |
|
4235 |
|
4236 |
|
4237 |
|
4238 | this.trigger('loadedmetadata');
|
4239 | } else {
|
4240 | this.trigger('mediachange');
|
4241 | }
|
4242 | }
|
4243 |
|
4244 | return;
|
4245 | }
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 | this.updateMediaUpdateTimeout_(refreshDelay(playlist, true));
|
4253 |
|
4254 | if (!mediaChange) {
|
4255 | return;
|
4256 | }
|
4257 |
|
4258 | this.state = 'SWITCHING_MEDIA';
|
4259 |
|
4260 | if (this.request) {
|
4261 | if (playlist.resolvedUri === this.request.url) {
|
4262 |
|
4263 |
|
4264 | return;
|
4265 | }
|
4266 |
|
4267 | this.request.onreadystatechange = null;
|
4268 | this.request.abort();
|
4269 | this.request = null;
|
4270 | }
|
4271 |
|
4272 |
|
4273 | if (this.media_) {
|
4274 | this.trigger('mediachanging');
|
4275 | }
|
4276 |
|
4277 | this.request = this.vhs_.xhr({
|
4278 | uri: playlist.resolvedUri,
|
4279 | withCredentials: this.withCredentials
|
4280 | }, function (error, req) {
|
4281 |
|
4282 | if (!_this4.request) {
|
4283 | return;
|
4284 | }
|
4285 |
|
4286 | playlist.lastRequest = Date.now();
|
4287 | playlist.resolvedUri = resolveManifestRedirect(_this4.handleManifestRedirects, playlist.resolvedUri, req);
|
4288 |
|
4289 | if (error) {
|
4290 | return _this4.playlistRequestError(_this4.request, playlist, startingState);
|
4291 | }
|
4292 |
|
4293 | _this4.haveMetadata({
|
4294 | playlistString: req.responseText,
|
4295 | url: playlist.uri,
|
4296 | id: playlist.id
|
4297 | });
|
4298 |
|
4299 |
|
4300 | if (startingState === 'HAVE_MASTER') {
|
4301 | _this4.trigger('loadedmetadata');
|
4302 | } else {
|
4303 | _this4.trigger('mediachange');
|
4304 | }
|
4305 | });
|
4306 | }
|
4307 | |
4308 |
|
4309 |
|
4310 | ;
|
4311 |
|
4312 | _proto.pause = function pause() {
|
4313 | if (this.mediaUpdateTimeout) {
|
4314 | window.clearTimeout(this.mediaUpdateTimeout);
|
4315 | this.mediaUpdateTimeout = null;
|
4316 | }
|
4317 |
|
4318 | this.stopRequest();
|
4319 |
|
4320 | if (this.state === 'HAVE_NOTHING') {
|
4321 |
|
4322 |
|
4323 | this.started = false;
|
4324 | }
|
4325 |
|
4326 |
|
4327 | if (this.state === 'SWITCHING_MEDIA') {
|
4328 |
|
4329 |
|
4330 |
|
4331 | if (this.media_) {
|
4332 | this.state = 'HAVE_METADATA';
|
4333 | } else {
|
4334 | this.state = 'HAVE_MASTER';
|
4335 | }
|
4336 | } else if (this.state === 'HAVE_CURRENT_METADATA') {
|
4337 | this.state = 'HAVE_METADATA';
|
4338 | }
|
4339 | }
|
4340 | |
4341 |
|
4342 |
|
4343 | ;
|
4344 |
|
4345 | _proto.load = function load(shouldDelay) {
|
4346 | var _this5 = this;
|
4347 |
|
4348 | if (this.mediaUpdateTimeout) {
|
4349 | window.clearTimeout(this.mediaUpdateTimeout);
|
4350 | this.mediaUpdateTimeout = null;
|
4351 | }
|
4352 |
|
4353 | var media = this.media();
|
4354 |
|
4355 | if (shouldDelay) {
|
4356 | var delay = media ? (media.partTargetDuration || media.targetDuration) / 2 * 1000 : 5 * 1000;
|
4357 | this.mediaUpdateTimeout = window.setTimeout(function () {
|
4358 | _this5.mediaUpdateTimeout = null;
|
4359 |
|
4360 | _this5.load();
|
4361 | }, delay);
|
4362 | return;
|
4363 | }
|
4364 |
|
4365 | if (!this.started) {
|
4366 | this.start();
|
4367 | return;
|
4368 | }
|
4369 |
|
4370 | if (media && !media.endList) {
|
4371 | this.trigger('mediaupdatetimeout');
|
4372 | } else {
|
4373 | this.trigger('loadedplaylist');
|
4374 | }
|
4375 | };
|
4376 |
|
4377 | _proto.updateMediaUpdateTimeout_ = function updateMediaUpdateTimeout_(delay) {
|
4378 | var _this6 = this;
|
4379 |
|
4380 | if (this.mediaUpdateTimeout) {
|
4381 | window.clearTimeout(this.mediaUpdateTimeout);
|
4382 | this.mediaUpdateTimeout = null;
|
4383 | }
|
4384 |
|
4385 |
|
4386 | if (!this.media() || this.media().endList) {
|
4387 | return;
|
4388 | }
|
4389 |
|
4390 | this.mediaUpdateTimeout = window.setTimeout(function () {
|
4391 | _this6.mediaUpdateTimeout = null;
|
4392 |
|
4393 | _this6.trigger('mediaupdatetimeout');
|
4394 |
|
4395 | _this6.updateMediaUpdateTimeout_(delay);
|
4396 | }, delay);
|
4397 | }
|
4398 | |
4399 |
|
4400 |
|
4401 | ;
|
4402 |
|
4403 | _proto.start = function start() {
|
4404 | var _this7 = this;
|
4405 |
|
4406 | this.started = true;
|
4407 |
|
4408 | if (typeof this.src === 'object') {
|
4409 |
|
4410 |
|
4411 | if (!this.src.uri) {
|
4412 | this.src.uri = window.location.href;
|
4413 | }
|
4414 |
|
4415 |
|
4416 |
|
4417 | this.src.resolvedUri = this.src.uri;
|
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 |
|
4424 |
|
4425 |
|
4426 |
|
4427 | setTimeout(function () {
|
4428 | _this7.setupInitialPlaylist(_this7.src);
|
4429 | }, 0);
|
4430 | return;
|
4431 | }
|
4432 |
|
4433 |
|
4434 | this.request = this.vhs_.xhr({
|
4435 | uri: this.src,
|
4436 | withCredentials: this.withCredentials
|
4437 | }, function (error, req) {
|
4438 |
|
4439 | if (!_this7.request) {
|
4440 | return;
|
4441 | }
|
4442 |
|
4443 |
|
4444 | _this7.request = null;
|
4445 |
|
4446 | if (error) {
|
4447 | _this7.error = {
|
4448 | status: req.status,
|
4449 | message: "HLS playlist request error at URL: " + _this7.src + ".",
|
4450 | responseText: req.responseText,
|
4451 |
|
4452 | code: 2
|
4453 | };
|
4454 |
|
4455 | if (_this7.state === 'HAVE_NOTHING') {
|
4456 | _this7.started = false;
|
4457 | }
|
4458 |
|
4459 | return _this7.trigger('error');
|
4460 | }
|
4461 |
|
4462 | _this7.src = resolveManifestRedirect(_this7.handleManifestRedirects, _this7.src, req);
|
4463 |
|
4464 | var manifest = _this7.parseManifest_({
|
4465 | manifestString: req.responseText,
|
4466 | url: _this7.src
|
4467 | });
|
4468 |
|
4469 | _this7.setupInitialPlaylist(manifest);
|
4470 | });
|
4471 | };
|
4472 |
|
4473 | _proto.srcUri = function srcUri() {
|
4474 | return typeof this.src === 'string' ? this.src : this.src.uri;
|
4475 | }
|
4476 | |
4477 |
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 |
|
4488 |
|
4489 |
|
4490 |
|
4491 |
|
4492 |
|
4493 |
|
4494 | ;
|
4495 |
|
4496 | _proto.setupInitialPlaylist = function setupInitialPlaylist(manifest) {
|
4497 | this.state = 'HAVE_MASTER';
|
4498 |
|
4499 | if (manifest.playlists) {
|
4500 | this.master = manifest;
|
4501 | addPropertiesToMaster(this.master, this.srcUri());
|
4502 |
|
4503 |
|
4504 |
|
4505 | manifest.playlists.forEach(function (playlist) {
|
4506 | playlist.segments = getAllSegments(playlist);
|
4507 | playlist.segments.forEach(function (segment) {
|
4508 | resolveSegmentUris(segment, playlist.resolvedUri);
|
4509 | });
|
4510 | });
|
4511 | this.trigger('loadedplaylist');
|
4512 |
|
4513 | if (!this.request) {
|
4514 |
|
4515 |
|
4516 | this.media(this.master.playlists[0]);
|
4517 | }
|
4518 |
|
4519 | return;
|
4520 | }
|
4521 |
|
4522 |
|
4523 |
|
4524 |
|
4525 | var uri = this.srcUri() || window.location.href;
|
4526 | this.master = masterForMedia(manifest, uri);
|
4527 | this.haveMetadata({
|
4528 | playlistObject: manifest,
|
4529 | url: uri,
|
4530 | id: this.master.playlists[0].id
|
4531 | });
|
4532 | this.trigger('loadedmetadata');
|
4533 | };
|
4534 |
|
4535 | return PlaylistLoader;
|
4536 | }(EventTarget$1);
|
4537 |
|
4538 | |
4539 |
|
4540 |
|
4541 | var videojsXHR = videojs__default["default"].xhr,
|
4542 | mergeOptions$1 = videojs__default["default"].mergeOptions;
|
4543 |
|
4544 | var callbackWrapper = function callbackWrapper(request, error, response, callback) {
|
4545 | var reqResponse = request.responseType === 'arraybuffer' ? request.response : request.responseText;
|
4546 |
|
4547 | if (!error && reqResponse) {
|
4548 | request.responseTime = Date.now();
|
4549 | request.roundTripTime = request.responseTime - request.requestTime;
|
4550 | request.bytesReceived = reqResponse.byteLength || reqResponse.length;
|
4551 |
|
4552 | if (!request.bandwidth) {
|
4553 | request.bandwidth = Math.floor(request.bytesReceived / request.roundTripTime * 8 * 1000);
|
4554 | }
|
4555 | }
|
4556 |
|
4557 | if (response.headers) {
|
4558 | request.responseHeaders = response.headers;
|
4559 | }
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 | if (error && error.code === 'ETIMEDOUT') {
|
4565 | request.timedout = true;
|
4566 | }
|
4567 |
|
4568 |
|
4569 |
|
4570 |
|
4571 | if (!error && !request.aborted && response.statusCode !== 200 && response.statusCode !== 206 && response.statusCode !== 0) {
|
4572 | error = new Error('XHR Failed with a response of: ' + (request && (reqResponse || request.responseText)));
|
4573 | }
|
4574 |
|
4575 | callback(error, request);
|
4576 | };
|
4577 |
|
4578 | var xhrFactory = function xhrFactory() {
|
4579 | var xhr = function XhrFunction(options, callback) {
|
4580 |
|
4581 | options = mergeOptions$1({
|
4582 | timeout: 45e3
|
4583 | }, options);
|
4584 |
|
4585 |
|
4586 | var beforeRequest = XhrFunction.beforeRequest || videojs__default["default"].Vhs.xhr.beforeRequest;
|
4587 |
|
4588 | if (beforeRequest && typeof beforeRequest === 'function') {
|
4589 | var newOptions = beforeRequest(options);
|
4590 |
|
4591 | if (newOptions) {
|
4592 | options = newOptions;
|
4593 | }
|
4594 | }
|
4595 |
|
4596 |
|
4597 |
|
4598 | var xhrMethod = videojs__default["default"].Vhs.xhr.original === true ? videojsXHR : videojs__default["default"].Vhs.xhr;
|
4599 | var request = xhrMethod(options, function (error, response) {
|
4600 | return callbackWrapper(request, error, response, callback);
|
4601 | });
|
4602 | var originalAbort = request.abort;
|
4603 |
|
4604 | request.abort = function () {
|
4605 | request.aborted = true;
|
4606 | return originalAbort.apply(request, arguments);
|
4607 | };
|
4608 |
|
4609 | request.uri = options.uri;
|
4610 | request.requestTime = Date.now();
|
4611 | return request;
|
4612 | };
|
4613 |
|
4614 | xhr.original = true;
|
4615 | return xhr;
|
4616 | };
|
4617 | |
4618 |
|
4619 |
|
4620 |
|
4621 |
|
4622 |
|
4623 |
|
4624 |
|
4625 |
|
4626 | var byterangeStr = function byterangeStr(byterange) {
|
4627 |
|
4628 |
|
4629 | var byterangeEnd = byterange.offset + byterange.length - 1;
|
4630 | var byterangeStart = byterange.offset;
|
4631 | return 'bytes=' + byterangeStart + '-' + byterangeEnd;
|
4632 | };
|
4633 | |
4634 |
|
4635 |
|
4636 |
|
4637 |
|
4638 |
|
4639 |
|
4640 |
|
4641 | var segmentXhrHeaders = function segmentXhrHeaders(segment) {
|
4642 | var headers = {};
|
4643 |
|
4644 | if (segment.byterange) {
|
4645 | headers.Range = byterangeStr(segment.byterange);
|
4646 | }
|
4647 |
|
4648 | return headers;
|
4649 | };
|
4650 |
|
4651 | var MPEGURL_REGEX = /^(audio|video|application)\/(x-|vnd\.apple\.)?mpegurl/i;
|
4652 | var DASH_REGEX = /^application\/dash\+xml/i;
|
4653 | |
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 |
|
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 | var simpleTypeFromSourceType = function simpleTypeFromSourceType(type) {
|
4666 | if (MPEGURL_REGEX.test(type)) {
|
4667 | return 'hls';
|
4668 | }
|
4669 |
|
4670 | if (DASH_REGEX.test(type)) {
|
4671 | return 'dash';
|
4672 | }
|
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 | if (type === 'application/vnd.videojs.vhs+json') {
|
4682 | return 'vhs-json';
|
4683 | }
|
4684 |
|
4685 | return null;
|
4686 | };
|
4687 |
|
4688 | |
4689 |
|
4690 |
|
4691 |
|
4692 | |
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 |
|
4698 |
|
4699 | var textRange = function textRange(range, i) {
|
4700 | return range.start(i) + '-' + range.end(i);
|
4701 | };
|
4702 | |
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 | var formatHexString = function formatHexString(e, i) {
|
4712 | var value = e.toString(16);
|
4713 | return '00'.substring(0, 2 - value.length) + value + (i % 2 ? ' ' : '');
|
4714 | };
|
4715 |
|
4716 | var formatAsciiString = function formatAsciiString(e) {
|
4717 | if (e >= 0x20 && e < 0x7e) {
|
4718 | return String.fromCharCode(e);
|
4719 | }
|
4720 |
|
4721 | return '.';
|
4722 | };
|
4723 | |
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 |
|
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 |
|
4735 | var createTransferableMessage = function createTransferableMessage(message) {
|
4736 | var transferable = {};
|
4737 | Object.keys(message).forEach(function (key) {
|
4738 | var value = message[key];
|
4739 |
|
4740 | if (ArrayBuffer.isView(value)) {
|
4741 | transferable[key] = {
|
4742 | bytes: value.buffer,
|
4743 | byteOffset: value.byteOffset,
|
4744 | byteLength: value.byteLength
|
4745 | };
|
4746 | } else {
|
4747 | transferable[key] = value;
|
4748 | }
|
4749 | });
|
4750 | return transferable;
|
4751 | };
|
4752 | |
4753 |
|
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 | var initSegmentId = function initSegmentId(initSegment) {
|
4763 | var byterange = initSegment.byterange || {
|
4764 | length: Infinity,
|
4765 | offset: 0
|
4766 | };
|
4767 | return [byterange.length, byterange.offset, initSegment.resolvedUri].join(',');
|
4768 | };
|
4769 | |
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 | var segmentKeyId = function segmentKeyId(key) {
|
4777 | return key.resolvedUri;
|
4778 | };
|
4779 | |
4780 |
|
4781 |
|
4782 |
|
4783 |
|
4784 |
|
4785 |
|
4786 |
|
4787 |
|
4788 | var hexDump = function hexDump(data) {
|
4789 | var bytes = Array.prototype.slice.call(data);
|
4790 | var step = 16;
|
4791 | var result = '';
|
4792 | var hex;
|
4793 | var ascii;
|
4794 |
|
4795 | for (var j = 0; j < bytes.length / step; j++) {
|
4796 | hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
|
4797 | ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
|
4798 | result += hex + ' ' + ascii + '\n';
|
4799 | }
|
4800 |
|
4801 | return result;
|
4802 | };
|
4803 | var tagDump = function tagDump(_ref) {
|
4804 | var bytes = _ref.bytes;
|
4805 | return hexDump(bytes);
|
4806 | };
|
4807 | var textRanges = function textRanges(ranges) {
|
4808 | var result = '';
|
4809 | var i;
|
4810 |
|
4811 | for (i = 0; i < ranges.length; i++) {
|
4812 | result += textRange(ranges, i) + ' ';
|
4813 | }
|
4814 |
|
4815 | return result;
|
4816 | };
|
4817 |
|
4818 | var utils = Object.freeze({
|
4819 | __proto__: null,
|
4820 | createTransferableMessage: createTransferableMessage,
|
4821 | initSegmentId: initSegmentId,
|
4822 | segmentKeyId: segmentKeyId,
|
4823 | hexDump: hexDump,
|
4824 | tagDump: tagDump,
|
4825 | textRanges: textRanges
|
4826 | });
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 | var SEGMENT_END_FUDGE_PERCENT = 0.25;
|
4832 | |
4833 |
|
4834 |
|
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 |
|
4840 |
|
4841 |
|
4842 |
|
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 | var playerTimeToProgramTime = function playerTimeToProgramTime(playerTime, segment) {
|
4849 | if (!segment.dateTimeObject) {
|
4850 |
|
4851 |
|
4852 | return null;
|
4853 | }
|
4854 |
|
4855 | var transmuxerPrependedSeconds = segment.videoTimingInfo.transmuxerPrependedSeconds;
|
4856 | var transmuxedStart = segment.videoTimingInfo.transmuxedPresentationStart;
|
4857 |
|
4858 | var startOfSegment = transmuxedStart + transmuxerPrependedSeconds;
|
4859 | var offsetFromSegmentStart = playerTime - startOfSegment;
|
4860 | return new Date(segment.dateTimeObject.getTime() + offsetFromSegmentStart * 1000);
|
4861 | };
|
4862 | var originalSegmentVideoDuration = function originalSegmentVideoDuration(videoTimingInfo) {
|
4863 | return videoTimingInfo.transmuxedPresentationEnd - videoTimingInfo.transmuxedPresentationStart - videoTimingInfo.transmuxerPrependedSeconds;
|
4864 | };
|
4865 | |
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 | var findSegmentForProgramTime = function findSegmentForProgramTime(programTime, playlist) {
|
4874 |
|
4875 |
|
4876 |
|
4877 | var dateTimeObject;
|
4878 |
|
4879 | try {
|
4880 | dateTimeObject = new Date(programTime);
|
4881 | } catch (e) {
|
4882 | return null;
|
4883 | }
|
4884 |
|
4885 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
4886 | return null;
|
4887 | }
|
4888 |
|
4889 | var segment = playlist.segments[0];
|
4890 |
|
4891 | if (dateTimeObject < segment.dateTimeObject) {
|
4892 |
|
4893 | return null;
|
4894 | }
|
4895 |
|
4896 | for (var i = 0; i < playlist.segments.length - 1; i++) {
|
4897 | segment = playlist.segments[i];
|
4898 | var nextSegmentStart = playlist.segments[i + 1].dateTimeObject;
|
4899 |
|
4900 | if (dateTimeObject < nextSegmentStart) {
|
4901 | break;
|
4902 | }
|
4903 | }
|
4904 |
|
4905 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
4906 | var lastSegmentStart = lastSegment.dateTimeObject;
|
4907 | var lastSegmentDuration = lastSegment.videoTimingInfo ? originalSegmentVideoDuration(lastSegment.videoTimingInfo) : lastSegment.duration + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT;
|
4908 | var lastSegmentEnd = new Date(lastSegmentStart.getTime() + lastSegmentDuration * 1000);
|
4909 |
|
4910 | if (dateTimeObject > lastSegmentEnd) {
|
4911 |
|
4912 | return null;
|
4913 | }
|
4914 |
|
4915 | if (dateTimeObject > lastSegmentStart) {
|
4916 | segment = lastSegment;
|
4917 | }
|
4918 |
|
4919 | return {
|
4920 | segment: segment,
|
4921 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : Playlist.duration(playlist, playlist.mediaSequence + playlist.segments.indexOf(segment)),
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
4927 | };
|
4928 | };
|
4929 | |
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 | var findSegmentForPlayerTime = function findSegmentForPlayerTime(time, playlist) {
|
4937 |
|
4938 |
|
4939 |
|
4940 |
|
4941 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
4942 | return null;
|
4943 | }
|
4944 |
|
4945 | var segmentEnd = 0;
|
4946 | var segment;
|
4947 |
|
4948 | for (var i = 0; i < playlist.segments.length; i++) {
|
4949 | segment = playlist.segments[i];
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 | segmentEnd = segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationEnd : segmentEnd + segment.duration;
|
4957 |
|
4958 | if (time <= segmentEnd) {
|
4959 | break;
|
4960 | }
|
4961 | }
|
4962 |
|
4963 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
4964 |
|
4965 | if (lastSegment.videoTimingInfo && lastSegment.videoTimingInfo.transmuxedPresentationEnd < time) {
|
4966 |
|
4967 | return null;
|
4968 | }
|
4969 |
|
4970 | if (time > segmentEnd) {
|
4971 |
|
4972 |
|
4973 |
|
4974 | if (time > segmentEnd + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT) {
|
4975 |
|
4976 |
|
4977 |
|
4978 | return null;
|
4979 | }
|
4980 |
|
4981 | segment = lastSegment;
|
4982 | }
|
4983 |
|
4984 | return {
|
4985 | segment: segment,
|
4986 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : segmentEnd - segment.duration,
|
4987 |
|
4988 |
|
4989 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
4990 | };
|
4991 | };
|
4992 | |
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 | var getOffsetFromTimestamp = function getOffsetFromTimestamp(comparisonTimeStamp, programTime) {
|
5004 | var segmentDateTime;
|
5005 | var programDateTime;
|
5006 |
|
5007 | try {
|
5008 | segmentDateTime = new Date(comparisonTimeStamp);
|
5009 | programDateTime = new Date(programTime);
|
5010 | } catch (e) {
|
5011 | }
|
5012 |
|
5013 | var segmentTimeEpoch = segmentDateTime.getTime();
|
5014 | var programTimeEpoch = programDateTime.getTime();
|
5015 | return (programTimeEpoch - segmentTimeEpoch) / 1000;
|
5016 | };
|
5017 | |
5018 |
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 | var verifyProgramDateTimeTags = function verifyProgramDateTimeTags(playlist) {
|
5024 | if (!playlist.segments || playlist.segments.length === 0) {
|
5025 | return false;
|
5026 | }
|
5027 |
|
5028 | for (var i = 0; i < playlist.segments.length; i++) {
|
5029 | var segment = playlist.segments[i];
|
5030 |
|
5031 | if (!segment.dateTimeObject) {
|
5032 | return false;
|
5033 | }
|
5034 | }
|
5035 |
|
5036 | return true;
|
5037 | };
|
5038 | |
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 | var getProgramTime = function getProgramTime(_ref) {
|
5055 | var playlist = _ref.playlist,
|
5056 | _ref$time = _ref.time,
|
5057 | time = _ref$time === void 0 ? undefined : _ref$time,
|
5058 | callback = _ref.callback;
|
5059 |
|
5060 | if (!callback) {
|
5061 | throw new Error('getProgramTime: callback must be provided');
|
5062 | }
|
5063 |
|
5064 | if (!playlist || time === undefined) {
|
5065 | return callback({
|
5066 | message: 'getProgramTime: playlist and time must be provided'
|
5067 | });
|
5068 | }
|
5069 |
|
5070 | var matchedSegment = findSegmentForPlayerTime(time, playlist);
|
5071 |
|
5072 | if (!matchedSegment) {
|
5073 | return callback({
|
5074 | message: 'valid programTime was not found'
|
5075 | });
|
5076 | }
|
5077 |
|
5078 | if (matchedSegment.type === 'estimate') {
|
5079 | return callback({
|
5080 | message: 'Accurate programTime could not be determined.' + ' Please seek to e.seekTime and try again',
|
5081 | seekTime: matchedSegment.estimatedStart
|
5082 | });
|
5083 | }
|
5084 |
|
5085 | var programTimeObject = {
|
5086 | mediaSeconds: time
|
5087 | };
|
5088 | var programTime = playerTimeToProgramTime(time, matchedSegment.segment);
|
5089 |
|
5090 | if (programTime) {
|
5091 | programTimeObject.programDateTime = programTime.toISOString();
|
5092 | }
|
5093 |
|
5094 | return callback(null, programTimeObject);
|
5095 | };
|
5096 | |
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 |
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 |
|
5111 | var seekToProgramTime = function seekToProgramTime(_ref2) {
|
5112 | var programTime = _ref2.programTime,
|
5113 | playlist = _ref2.playlist,
|
5114 | _ref2$retryCount = _ref2.retryCount,
|
5115 | retryCount = _ref2$retryCount === void 0 ? 2 : _ref2$retryCount,
|
5116 | seekTo = _ref2.seekTo,
|
5117 | _ref2$pauseAfterSeek = _ref2.pauseAfterSeek,
|
5118 | pauseAfterSeek = _ref2$pauseAfterSeek === void 0 ? true : _ref2$pauseAfterSeek,
|
5119 | tech = _ref2.tech,
|
5120 | callback = _ref2.callback;
|
5121 |
|
5122 | if (!callback) {
|
5123 | throw new Error('seekToProgramTime: callback must be provided');
|
5124 | }
|
5125 |
|
5126 | if (typeof programTime === 'undefined' || !playlist || !seekTo) {
|
5127 | return callback({
|
5128 | message: 'seekToProgramTime: programTime, seekTo and playlist must be provided'
|
5129 | });
|
5130 | }
|
5131 |
|
5132 | if (!playlist.endList && !tech.hasStarted_) {
|
5133 | return callback({
|
5134 | message: 'player must be playing a live stream to start buffering'
|
5135 | });
|
5136 | }
|
5137 |
|
5138 | if (!verifyProgramDateTimeTags(playlist)) {
|
5139 | return callback({
|
5140 | message: 'programDateTime tags must be provided in the manifest ' + playlist.resolvedUri
|
5141 | });
|
5142 | }
|
5143 |
|
5144 | var matchedSegment = findSegmentForProgramTime(programTime, playlist);
|
5145 |
|
5146 | if (!matchedSegment) {
|
5147 | return callback({
|
5148 | message: programTime + " was not found in the stream"
|
5149 | });
|
5150 | }
|
5151 |
|
5152 | var segment = matchedSegment.segment;
|
5153 | var mediaOffset = getOffsetFromTimestamp(segment.dateTimeObject, programTime);
|
5154 |
|
5155 | if (matchedSegment.type === 'estimate') {
|
5156 |
|
5157 | if (retryCount === 0) {
|
5158 | return callback({
|
5159 | message: programTime + " is not buffered yet. Try again"
|
5160 | });
|
5161 | }
|
5162 |
|
5163 | seekTo(matchedSegment.estimatedStart + mediaOffset);
|
5164 | tech.one('seeked', function () {
|
5165 | seekToProgramTime({
|
5166 | programTime: programTime,
|
5167 | playlist: playlist,
|
5168 | retryCount: retryCount - 1,
|
5169 | seekTo: seekTo,
|
5170 | pauseAfterSeek: pauseAfterSeek,
|
5171 | tech: tech,
|
5172 | callback: callback
|
5173 | });
|
5174 | });
|
5175 | return;
|
5176 | }
|
5177 |
|
5178 |
|
5179 |
|
5180 |
|
5181 | var seekToTime = segment.start + mediaOffset;
|
5182 |
|
5183 | var seekedCallback = function seekedCallback() {
|
5184 | return callback(null, tech.currentTime());
|
5185 | };
|
5186 |
|
5187 |
|
5188 | tech.one('seeked', seekedCallback);
|
5189 |
|
5190 | if (pauseAfterSeek) {
|
5191 | tech.pause();
|
5192 | }
|
5193 |
|
5194 | seekTo(seekToTime);
|
5195 | };
|
5196 |
|
5197 |
|
5198 |
|
5199 | var isObject = function isObject(obj) {
|
5200 | return !!obj && typeof obj === 'object';
|
5201 | };
|
5202 |
|
5203 | var merge = function merge() {
|
5204 | for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
5205 | objects[_key] = arguments[_key];
|
5206 | }
|
5207 |
|
5208 | return objects.reduce(function (result, source) {
|
5209 | if (typeof source !== 'object') {
|
5210 | return result;
|
5211 | }
|
5212 |
|
5213 | Object.keys(source).forEach(function (key) {
|
5214 | if (Array.isArray(result[key]) && Array.isArray(source[key])) {
|
5215 | result[key] = result[key].concat(source[key]);
|
5216 | } else if (isObject(result[key]) && isObject(source[key])) {
|
5217 | result[key] = merge(result[key], source[key]);
|
5218 | } else {
|
5219 | result[key] = source[key];
|
5220 | }
|
5221 | });
|
5222 | return result;
|
5223 | }, {});
|
5224 | };
|
5225 |
|
5226 | var values = function values(o) {
|
5227 | return Object.keys(o).map(function (k) {
|
5228 | return o[k];
|
5229 | });
|
5230 | };
|
5231 |
|
5232 | var range = function range(start, end) {
|
5233 | var result = [];
|
5234 |
|
5235 | for (var i = start; i < end; i++) {
|
5236 | result.push(i);
|
5237 | }
|
5238 |
|
5239 | return result;
|
5240 | };
|
5241 |
|
5242 | var flatten = function flatten(lists) {
|
5243 | return lists.reduce(function (x, y) {
|
5244 | return x.concat(y);
|
5245 | }, []);
|
5246 | };
|
5247 |
|
5248 | var from = function from(list) {
|
5249 | if (!list.length) {
|
5250 | return [];
|
5251 | }
|
5252 |
|
5253 | var result = [];
|
5254 |
|
5255 | for (var i = 0; i < list.length; i++) {
|
5256 | result.push(list[i]);
|
5257 | }
|
5258 |
|
5259 | return result;
|
5260 | };
|
5261 |
|
5262 | var findIndexes = function findIndexes(l, key) {
|
5263 | return l.reduce(function (a, e, i) {
|
5264 | if (e[key]) {
|
5265 | a.push(i);
|
5266 | }
|
5267 |
|
5268 | return a;
|
5269 | }, []);
|
5270 | };
|
5271 |
|
5272 | var errors = {
|
5273 | INVALID_NUMBER_OF_PERIOD: 'INVALID_NUMBER_OF_PERIOD',
|
5274 | DASH_EMPTY_MANIFEST: 'DASH_EMPTY_MANIFEST',
|
5275 | DASH_INVALID_XML: 'DASH_INVALID_XML',
|
5276 | NO_BASE_URL: 'NO_BASE_URL',
|
5277 | MISSING_SEGMENT_INFORMATION: 'MISSING_SEGMENT_INFORMATION',
|
5278 | SEGMENT_TIME_UNSPECIFIED: 'SEGMENT_TIME_UNSPECIFIED',
|
5279 | UNSUPPORTED_UTC_TIMING_SCHEME: 'UNSUPPORTED_UTC_TIMING_SCHEME'
|
5280 | };
|
5281 | |
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 | |
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 |
|
5299 |
|
5300 |
|
5301 |
|
5302 |
|
5303 |
|
5304 |
|
5305 |
|
5306 |
|
5307 | var urlTypeToSegment = function urlTypeToSegment(_ref) {
|
5308 | var _ref$baseUrl = _ref.baseUrl,
|
5309 | baseUrl = _ref$baseUrl === void 0 ? '' : _ref$baseUrl,
|
5310 | _ref$source = _ref.source,
|
5311 | source = _ref$source === void 0 ? '' : _ref$source,
|
5312 | _ref$range = _ref.range,
|
5313 | range = _ref$range === void 0 ? '' : _ref$range,
|
5314 | _ref$indexRange = _ref.indexRange,
|
5315 | indexRange = _ref$indexRange === void 0 ? '' : _ref$indexRange;
|
5316 | var segment = {
|
5317 | uri: source,
|
5318 | resolvedUri: resolveUrl$1(baseUrl || '', source)
|
5319 | };
|
5320 |
|
5321 | if (range || indexRange) {
|
5322 | var rangeStr = range ? range : indexRange;
|
5323 | var ranges = rangeStr.split('-');
|
5324 | var startRange = parseInt(ranges[0], 10);
|
5325 | var endRange = parseInt(ranges[1], 10);
|
5326 |
|
5327 |
|
5328 | segment.byterange = {
|
5329 | length: endRange - startRange + 1,
|
5330 | offset: startRange
|
5331 | };
|
5332 | }
|
5333 |
|
5334 | return segment;
|
5335 | };
|
5336 |
|
5337 | var byteRangeToString = function byteRangeToString(byterange) {
|
5338 |
|
5339 |
|
5340 | var endRange = byterange.offset + byterange.length - 1;
|
5341 | return byterange.offset + "-" + endRange;
|
5342 | };
|
5343 | |
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 | var parseEndNumber = function parseEndNumber(endNumber) {
|
5356 | if (endNumber && typeof endNumber !== 'number') {
|
5357 | endNumber = parseInt(endNumber, 10);
|
5358 | }
|
5359 |
|
5360 | if (isNaN(endNumber)) {
|
5361 | return null;
|
5362 | }
|
5363 |
|
5364 | return endNumber;
|
5365 | };
|
5366 | |
5367 |
|
5368 |
|
5369 |
|
5370 |
|
5371 |
|
5372 | var segmentRange = {
|
5373 | |
5374 |
|
5375 |
|
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 | static: function _static(attributes) {
|
5382 | var duration = attributes.duration,
|
5383 | _attributes$timescale = attributes.timescale,
|
5384 | timescale = _attributes$timescale === void 0 ? 1 : _attributes$timescale,
|
5385 | sourceDuration = attributes.sourceDuration,
|
5386 | periodDuration = attributes.periodDuration;
|
5387 | var endNumber = parseEndNumber(attributes.endNumber);
|
5388 | var segmentDuration = duration / timescale;
|
5389 |
|
5390 | if (typeof endNumber === 'number') {
|
5391 | return {
|
5392 | start: 0,
|
5393 | end: endNumber
|
5394 | };
|
5395 | }
|
5396 |
|
5397 | if (typeof periodDuration === 'number') {
|
5398 | return {
|
5399 | start: 0,
|
5400 | end: periodDuration / segmentDuration
|
5401 | };
|
5402 | }
|
5403 |
|
5404 | return {
|
5405 | start: 0,
|
5406 | end: sourceDuration / segmentDuration
|
5407 | };
|
5408 | },
|
5409 |
|
5410 | |
5411 |
|
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 |
|
5417 |
|
5418 | dynamic: function dynamic(attributes) {
|
5419 | var NOW = attributes.NOW,
|
5420 | clientOffset = attributes.clientOffset,
|
5421 | availabilityStartTime = attributes.availabilityStartTime,
|
5422 | _attributes$timescale2 = attributes.timescale,
|
5423 | timescale = _attributes$timescale2 === void 0 ? 1 : _attributes$timescale2,
|
5424 | duration = attributes.duration,
|
5425 | _attributes$start = attributes.start,
|
5426 | start = _attributes$start === void 0 ? 0 : _attributes$start,
|
5427 | _attributes$minimumUp = attributes.minimumUpdatePeriod,
|
5428 | minimumUpdatePeriod = _attributes$minimumUp === void 0 ? 0 : _attributes$minimumUp,
|
5429 | _attributes$timeShift = attributes.timeShiftBufferDepth,
|
5430 | timeShiftBufferDepth = _attributes$timeShift === void 0 ? Infinity : _attributes$timeShift;
|
5431 | var endNumber = parseEndNumber(attributes.endNumber);
|
5432 | var now = (NOW + clientOffset) / 1000;
|
5433 | var periodStartWC = availabilityStartTime + start;
|
5434 | var periodEndWC = now + minimumUpdatePeriod;
|
5435 | var periodDuration = periodEndWC - periodStartWC;
|
5436 | var segmentCount = Math.ceil(periodDuration * timescale / duration);
|
5437 | var availableStart = Math.floor((now - periodStartWC - timeShiftBufferDepth) * timescale / duration);
|
5438 | var availableEnd = Math.floor((now - periodStartWC) * timescale / duration);
|
5439 | return {
|
5440 | start: Math.max(0, availableStart),
|
5441 | end: typeof endNumber === 'number' ? endNumber : Math.min(segmentCount, availableEnd)
|
5442 | };
|
5443 | }
|
5444 | };
|
5445 | |
5446 |
|
5447 |
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 |
|
5453 |
|
5454 |
|
5455 |
|
5456 |
|
5457 |
|
5458 |
|
5459 | |
5460 |
|
5461 |
|
5462 |
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 | var toSegments = function toSegments(attributes) {
|
5470 | return function (number, index) {
|
5471 | var duration = attributes.duration,
|
5472 | _attributes$timescale3 = attributes.timescale,
|
5473 | timescale = _attributes$timescale3 === void 0 ? 1 : _attributes$timescale3,
|
5474 | periodIndex = attributes.periodIndex,
|
5475 | _attributes$startNumb = attributes.startNumber,
|
5476 | startNumber = _attributes$startNumb === void 0 ? 1 : _attributes$startNumb;
|
5477 | return {
|
5478 | number: startNumber + number,
|
5479 | duration: duration / timescale,
|
5480 | timeline: periodIndex,
|
5481 | time: index * duration
|
5482 | };
|
5483 | };
|
5484 | };
|
5485 | |
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 |
|
5494 |
|
5495 |
|
5496 |
|
5497 | var parseByDuration = function parseByDuration(attributes) {
|
5498 | var type = attributes.type,
|
5499 | duration = attributes.duration,
|
5500 | _attributes$timescale4 = attributes.timescale,
|
5501 | timescale = _attributes$timescale4 === void 0 ? 1 : _attributes$timescale4,
|
5502 | periodDuration = attributes.periodDuration,
|
5503 | sourceDuration = attributes.sourceDuration;
|
5504 |
|
5505 | var _segmentRange$type = segmentRange[type](attributes),
|
5506 | start = _segmentRange$type.start,
|
5507 | end = _segmentRange$type.end;
|
5508 |
|
5509 | var segments = range(start, end).map(toSegments(attributes));
|
5510 |
|
5511 | if (type === 'static') {
|
5512 | var index = segments.length - 1;
|
5513 |
|
5514 | var sectionDuration = typeof periodDuration === 'number' ? periodDuration : sourceDuration;
|
5515 |
|
5516 | segments[index].duration = sectionDuration - duration / timescale * index;
|
5517 | }
|
5518 |
|
5519 | return segments;
|
5520 | };
|
5521 | |
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 | var segmentsFromBase = function segmentsFromBase(attributes) {
|
5534 | var baseUrl = attributes.baseUrl,
|
5535 | _attributes$initializ = attributes.initialization,
|
5536 | initialization = _attributes$initializ === void 0 ? {} : _attributes$initializ,
|
5537 | sourceDuration = attributes.sourceDuration,
|
5538 | _attributes$indexRang = attributes.indexRange,
|
5539 | indexRange = _attributes$indexRang === void 0 ? '' : _attributes$indexRang,
|
5540 | duration = attributes.duration;
|
5541 |
|
5542 | if (!baseUrl) {
|
5543 | throw new Error(errors.NO_BASE_URL);
|
5544 | }
|
5545 |
|
5546 | var initSegment = urlTypeToSegment({
|
5547 | baseUrl: baseUrl,
|
5548 | source: initialization.sourceURL,
|
5549 | range: initialization.range
|
5550 | });
|
5551 | var segment = urlTypeToSegment({
|
5552 | baseUrl: baseUrl,
|
5553 | source: baseUrl,
|
5554 | indexRange: indexRange
|
5555 | });
|
5556 | segment.map = initSegment;
|
5557 |
|
5558 |
|
5559 | if (duration) {
|
5560 | var segmentTimeInfo = parseByDuration(attributes);
|
5561 |
|
5562 | if (segmentTimeInfo.length) {
|
5563 | segment.duration = segmentTimeInfo[0].duration;
|
5564 | segment.timeline = segmentTimeInfo[0].timeline;
|
5565 | }
|
5566 | } else if (sourceDuration) {
|
5567 | segment.duration = sourceDuration;
|
5568 | segment.timeline = 0;
|
5569 | }
|
5570 |
|
5571 |
|
5572 | segment.number = 0;
|
5573 | return [segment];
|
5574 | };
|
5575 | |
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 |
|
5588 | var addSidxSegmentsToPlaylist = function addSidxSegmentsToPlaylist(playlist, sidx, baseUrl) {
|
5589 |
|
5590 | var initSegment = playlist.sidx.map ? playlist.sidx.map : null;
|
5591 |
|
5592 | var sourceDuration = playlist.sidx.duration;
|
5593 |
|
5594 | var timeline = playlist.timeline || 0;
|
5595 | var sidxByteRange = playlist.sidx.byterange;
|
5596 | var sidxEnd = sidxByteRange.offset + sidxByteRange.length;
|
5597 |
|
5598 | var timescale = sidx.timescale;
|
5599 |
|
5600 | var mediaReferences = sidx.references.filter(function (r) {
|
5601 | return r.referenceType !== 1;
|
5602 | });
|
5603 | var segments = [];
|
5604 | var type = playlist.endList ? 'static' : 'dynamic';
|
5605 |
|
5606 | var startIndex = sidxEnd + sidx.firstOffset;
|
5607 |
|
5608 | for (var i = 0; i < mediaReferences.length; i++) {
|
5609 | var reference = sidx.references[i];
|
5610 |
|
5611 | var size = reference.referencedSize;
|
5612 |
|
5613 |
|
5614 | var duration = reference.subsegmentDuration;
|
5615 |
|
5616 | var endIndex = startIndex + size - 1;
|
5617 | var indexRange = startIndex + "-" + endIndex;
|
5618 | var attributes = {
|
5619 | baseUrl: baseUrl,
|
5620 | timescale: timescale,
|
5621 | timeline: timeline,
|
5622 |
|
5623 | periodIndex: timeline,
|
5624 | duration: duration,
|
5625 | sourceDuration: sourceDuration,
|
5626 | indexRange: indexRange,
|
5627 | type: type
|
5628 | };
|
5629 | var segment = segmentsFromBase(attributes)[0];
|
5630 |
|
5631 | if (initSegment) {
|
5632 | segment.map = initSegment;
|
5633 | }
|
5634 |
|
5635 | segments.push(segment);
|
5636 | startIndex += size;
|
5637 | }
|
5638 |
|
5639 | playlist.segments = segments;
|
5640 | return playlist;
|
5641 | };
|
5642 |
|
5643 | var generateSidxKey = function generateSidxKey(sidx) {
|
5644 | return sidx && sidx.uri + '-' + byteRangeToString(sidx.byterange);
|
5645 | };
|
5646 |
|
5647 | var mergeDiscontiguousPlaylists = function mergeDiscontiguousPlaylists(playlists) {
|
5648 | var mergedPlaylists = values(playlists.reduce(function (acc, playlist) {
|
5649 |
|
5650 |
|
5651 |
|
5652 | var name = playlist.attributes.id + (playlist.attributes.lang || '');
|
5653 |
|
5654 | if (acc[name]) {
|
5655 | var _acc$name$segments;
|
5656 |
|
5657 |
|
5658 | if (playlist.segments[0]) {
|
5659 | playlist.segments[0].discontinuity = true;
|
5660 | }
|
5661 |
|
5662 | (_acc$name$segments = acc[name].segments).push.apply(_acc$name$segments, playlist.segments);
|
5663 |
|
5664 |
|
5665 |
|
5666 | if (playlist.attributes.contentProtection) {
|
5667 | acc[name].attributes.contentProtection = playlist.attributes.contentProtection;
|
5668 | }
|
5669 | } else {
|
5670 |
|
5671 | acc[name] = playlist;
|
5672 | }
|
5673 |
|
5674 | return acc;
|
5675 | }, {}));
|
5676 | return mergedPlaylists.map(function (playlist) {
|
5677 | playlist.discontinuityStarts = findIndexes(playlist.segments, 'discontinuity');
|
5678 | return playlist;
|
5679 | });
|
5680 | };
|
5681 |
|
5682 | var addSidxSegmentsToPlaylist$1 = function addSidxSegmentsToPlaylist$1(playlist, sidxMapping) {
|
5683 | var sidxKey = generateSidxKey(playlist.sidx);
|
5684 | var sidxMatch = sidxKey && sidxMapping[sidxKey] && sidxMapping[sidxKey].sidx;
|
5685 |
|
5686 | if (sidxMatch) {
|
5687 | addSidxSegmentsToPlaylist(playlist, sidxMatch, playlist.sidx.resolvedUri);
|
5688 | }
|
5689 |
|
5690 | return playlist;
|
5691 | };
|
5692 |
|
5693 | var addSidxSegmentsToPlaylists = function addSidxSegmentsToPlaylists(playlists, sidxMapping) {
|
5694 | if (sidxMapping === void 0) {
|
5695 | sidxMapping = {};
|
5696 | }
|
5697 |
|
5698 | if (!Object.keys(sidxMapping).length) {
|
5699 | return playlists;
|
5700 | }
|
5701 |
|
5702 | for (var i in playlists) {
|
5703 | playlists[i] = addSidxSegmentsToPlaylist$1(playlists[i], sidxMapping);
|
5704 | }
|
5705 |
|
5706 | return playlists;
|
5707 | };
|
5708 |
|
5709 | var formatAudioPlaylist = function formatAudioPlaylist(_ref, isAudioOnly) {
|
5710 | var _attributes;
|
5711 |
|
5712 | var attributes = _ref.attributes,
|
5713 | segments = _ref.segments,
|
5714 | sidx = _ref.sidx;
|
5715 | var playlist = {
|
5716 | attributes: (_attributes = {
|
5717 | NAME: attributes.id,
|
5718 | BANDWIDTH: attributes.bandwidth,
|
5719 | CODECS: attributes.codecs
|
5720 | }, _attributes['PROGRAM-ID'] = 1, _attributes),
|
5721 | uri: '',
|
5722 | endList: attributes.type === 'static',
|
5723 | timeline: attributes.periodIndex,
|
5724 | resolvedUri: '',
|
5725 | targetDuration: attributes.duration,
|
5726 | segments: segments,
|
5727 | mediaSequence: segments.length ? segments[0].number : 1
|
5728 | };
|
5729 |
|
5730 | if (attributes.contentProtection) {
|
5731 | playlist.contentProtection = attributes.contentProtection;
|
5732 | }
|
5733 |
|
5734 | if (sidx) {
|
5735 | playlist.sidx = sidx;
|
5736 | }
|
5737 |
|
5738 | if (isAudioOnly) {
|
5739 | playlist.attributes.AUDIO = 'audio';
|
5740 | playlist.attributes.SUBTITLES = 'subs';
|
5741 | }
|
5742 |
|
5743 | return playlist;
|
5744 | };
|
5745 |
|
5746 | var formatVttPlaylist = function formatVttPlaylist(_ref2) {
|
5747 | var _m3u8Attributes;
|
5748 |
|
5749 | var attributes = _ref2.attributes,
|
5750 | segments = _ref2.segments;
|
5751 |
|
5752 | if (typeof segments === 'undefined') {
|
5753 |
|
5754 | segments = [{
|
5755 | uri: attributes.baseUrl,
|
5756 | timeline: attributes.periodIndex,
|
5757 | resolvedUri: attributes.baseUrl || '',
|
5758 | duration: attributes.sourceDuration,
|
5759 | number: 0
|
5760 | }];
|
5761 |
|
5762 | attributes.duration = attributes.sourceDuration;
|
5763 | }
|
5764 |
|
5765 | var m3u8Attributes = (_m3u8Attributes = {
|
5766 | NAME: attributes.id,
|
5767 | BANDWIDTH: attributes.bandwidth
|
5768 | }, _m3u8Attributes['PROGRAM-ID'] = 1, _m3u8Attributes);
|
5769 |
|
5770 | if (attributes.codecs) {
|
5771 | m3u8Attributes.CODECS = attributes.codecs;
|
5772 | }
|
5773 |
|
5774 | return {
|
5775 | attributes: m3u8Attributes,
|
5776 | uri: '',
|
5777 | endList: attributes.type === 'static',
|
5778 | timeline: attributes.periodIndex,
|
5779 | resolvedUri: attributes.baseUrl || '',
|
5780 | targetDuration: attributes.duration,
|
5781 | segments: segments,
|
5782 | mediaSequence: segments.length ? segments[0].number : 1
|
5783 | };
|
5784 | };
|
5785 |
|
5786 | var organizeAudioPlaylists = function organizeAudioPlaylists(playlists, sidxMapping, isAudioOnly) {
|
5787 | if (sidxMapping === void 0) {
|
5788 | sidxMapping = {};
|
5789 | }
|
5790 |
|
5791 | if (isAudioOnly === void 0) {
|
5792 | isAudioOnly = false;
|
5793 | }
|
5794 |
|
5795 | var mainPlaylist;
|
5796 | var formattedPlaylists = playlists.reduce(function (a, playlist) {
|
5797 | var role = playlist.attributes.role && playlist.attributes.role.value || '';
|
5798 | var language = playlist.attributes.lang || '';
|
5799 | var label = playlist.attributes.label || 'main';
|
5800 |
|
5801 | if (language && !playlist.attributes.label) {
|
5802 | var roleLabel = role ? " (" + role + ")" : '';
|
5803 | label = "" + playlist.attributes.lang + roleLabel;
|
5804 | }
|
5805 |
|
5806 | if (!a[label]) {
|
5807 | a[label] = {
|
5808 | language: language,
|
5809 | autoselect: true,
|
5810 | default: role === 'main',
|
5811 | playlists: [],
|
5812 | uri: ''
|
5813 | };
|
5814 | }
|
5815 |
|
5816 | var formatted = addSidxSegmentsToPlaylist$1(formatAudioPlaylist(playlist, isAudioOnly), sidxMapping);
|
5817 | a[label].playlists.push(formatted);
|
5818 |
|
5819 | if (typeof mainPlaylist === 'undefined' && role === 'main') {
|
5820 | mainPlaylist = playlist;
|
5821 | mainPlaylist.default = true;
|
5822 | }
|
5823 |
|
5824 | return a;
|
5825 | }, {});
|
5826 |
|
5827 | if (!mainPlaylist) {
|
5828 | var firstLabel = Object.keys(formattedPlaylists)[0];
|
5829 | formattedPlaylists[firstLabel].default = true;
|
5830 | }
|
5831 |
|
5832 | return formattedPlaylists;
|
5833 | };
|
5834 |
|
5835 | var organizeVttPlaylists = function organizeVttPlaylists(playlists, sidxMapping) {
|
5836 | if (sidxMapping === void 0) {
|
5837 | sidxMapping = {};
|
5838 | }
|
5839 |
|
5840 | return playlists.reduce(function (a, playlist) {
|
5841 | var label = playlist.attributes.lang || 'text';
|
5842 |
|
5843 | if (!a[label]) {
|
5844 | a[label] = {
|
5845 | language: label,
|
5846 | default: false,
|
5847 | autoselect: false,
|
5848 | playlists: [],
|
5849 | uri: ''
|
5850 | };
|
5851 | }
|
5852 |
|
5853 | a[label].playlists.push(addSidxSegmentsToPlaylist$1(formatVttPlaylist(playlist), sidxMapping));
|
5854 | return a;
|
5855 | }, {});
|
5856 | };
|
5857 |
|
5858 | var organizeCaptionServices = function organizeCaptionServices(captionServices) {
|
5859 | return captionServices.reduce(function (svcObj, svc) {
|
5860 | if (!svc) {
|
5861 | return svcObj;
|
5862 | }
|
5863 |
|
5864 | svc.forEach(function (service) {
|
5865 | var channel = service.channel,
|
5866 | language = service.language;
|
5867 | svcObj[language] = {
|
5868 | autoselect: false,
|
5869 | default: false,
|
5870 | instreamId: channel,
|
5871 | language: language
|
5872 | };
|
5873 |
|
5874 | if (service.hasOwnProperty('aspectRatio')) {
|
5875 | svcObj[language].aspectRatio = service.aspectRatio;
|
5876 | }
|
5877 |
|
5878 | if (service.hasOwnProperty('easyReader')) {
|
5879 | svcObj[language].easyReader = service.easyReader;
|
5880 | }
|
5881 |
|
5882 | if (service.hasOwnProperty('3D')) {
|
5883 | svcObj[language]['3D'] = service['3D'];
|
5884 | }
|
5885 | });
|
5886 | return svcObj;
|
5887 | }, {});
|
5888 | };
|
5889 |
|
5890 | var formatVideoPlaylist = function formatVideoPlaylist(_ref3) {
|
5891 | var _attributes2;
|
5892 |
|
5893 | var attributes = _ref3.attributes,
|
5894 | segments = _ref3.segments,
|
5895 | sidx = _ref3.sidx;
|
5896 | var playlist = {
|
5897 | attributes: (_attributes2 = {
|
5898 | NAME: attributes.id,
|
5899 | AUDIO: 'audio',
|
5900 | SUBTITLES: 'subs',
|
5901 | RESOLUTION: {
|
5902 | width: attributes.width,
|
5903 | height: attributes.height
|
5904 | },
|
5905 | CODECS: attributes.codecs,
|
5906 | BANDWIDTH: attributes.bandwidth
|
5907 | }, _attributes2['PROGRAM-ID'] = 1, _attributes2),
|
5908 | uri: '',
|
5909 | endList: attributes.type === 'static',
|
5910 | timeline: attributes.periodIndex,
|
5911 | resolvedUri: '',
|
5912 | targetDuration: attributes.duration,
|
5913 | segments: segments,
|
5914 | mediaSequence: segments.length ? segments[0].number : 1
|
5915 | };
|
5916 |
|
5917 | if (attributes.contentProtection) {
|
5918 | playlist.contentProtection = attributes.contentProtection;
|
5919 | }
|
5920 |
|
5921 | if (sidx) {
|
5922 | playlist.sidx = sidx;
|
5923 | }
|
5924 |
|
5925 | return playlist;
|
5926 | };
|
5927 |
|
5928 | var videoOnly = function videoOnly(_ref4) {
|
5929 | var attributes = _ref4.attributes;
|
5930 | return attributes.mimeType === 'video/mp4' || attributes.mimeType === 'video/webm' || attributes.contentType === 'video';
|
5931 | };
|
5932 |
|
5933 | var audioOnly = function audioOnly(_ref5) {
|
5934 | var attributes = _ref5.attributes;
|
5935 | return attributes.mimeType === 'audio/mp4' || attributes.mimeType === 'audio/webm' || attributes.contentType === 'audio';
|
5936 | };
|
5937 |
|
5938 | var vttOnly = function vttOnly(_ref6) {
|
5939 | var attributes = _ref6.attributes;
|
5940 | return attributes.mimeType === 'text/vtt' || attributes.contentType === 'text';
|
5941 | };
|
5942 |
|
5943 | var toM3u8 = function toM3u8(dashPlaylists, locations, sidxMapping) {
|
5944 | var _mediaGroups;
|
5945 |
|
5946 | if (sidxMapping === void 0) {
|
5947 | sidxMapping = {};
|
5948 | }
|
5949 |
|
5950 | if (!dashPlaylists.length) {
|
5951 | return {};
|
5952 | }
|
5953 |
|
5954 |
|
5955 | var _dashPlaylists$0$attr = dashPlaylists[0].attributes,
|
5956 | duration = _dashPlaylists$0$attr.sourceDuration,
|
5957 | type = _dashPlaylists$0$attr.type,
|
5958 | suggestedPresentationDelay = _dashPlaylists$0$attr.suggestedPresentationDelay,
|
5959 | minimumUpdatePeriod = _dashPlaylists$0$attr.minimumUpdatePeriod;
|
5960 | var videoPlaylists = mergeDiscontiguousPlaylists(dashPlaylists.filter(videoOnly)).map(formatVideoPlaylist);
|
5961 | var audioPlaylists = mergeDiscontiguousPlaylists(dashPlaylists.filter(audioOnly));
|
5962 | var vttPlaylists = dashPlaylists.filter(vttOnly);
|
5963 | var captions = dashPlaylists.map(function (playlist) {
|
5964 | return playlist.attributes.captionServices;
|
5965 | }).filter(Boolean);
|
5966 | var manifest = {
|
5967 | allowCache: true,
|
5968 | discontinuityStarts: [],
|
5969 | segments: [],
|
5970 | endList: true,
|
5971 | mediaGroups: (_mediaGroups = {
|
5972 | AUDIO: {},
|
5973 | VIDEO: {}
|
5974 | }, _mediaGroups['CLOSED-CAPTIONS'] = {}, _mediaGroups.SUBTITLES = {}, _mediaGroups),
|
5975 | uri: '',
|
5976 | duration: duration,
|
5977 | playlists: addSidxSegmentsToPlaylists(videoPlaylists, sidxMapping)
|
5978 | };
|
5979 |
|
5980 | if (minimumUpdatePeriod >= 0) {
|
5981 | manifest.minimumUpdatePeriod = minimumUpdatePeriod * 1000;
|
5982 | }
|
5983 |
|
5984 | if (locations) {
|
5985 | manifest.locations = locations;
|
5986 | }
|
5987 |
|
5988 | if (type === 'dynamic') {
|
5989 | manifest.suggestedPresentationDelay = suggestedPresentationDelay;
|
5990 | }
|
5991 |
|
5992 | var isAudioOnly = manifest.playlists.length === 0;
|
5993 |
|
5994 | if (audioPlaylists.length) {
|
5995 | manifest.mediaGroups.AUDIO.audio = organizeAudioPlaylists(audioPlaylists, sidxMapping, isAudioOnly);
|
5996 | }
|
5997 |
|
5998 | if (vttPlaylists.length) {
|
5999 | manifest.mediaGroups.SUBTITLES.subs = organizeVttPlaylists(vttPlaylists, sidxMapping);
|
6000 | }
|
6001 |
|
6002 | if (captions.length) {
|
6003 | manifest.mediaGroups['CLOSED-CAPTIONS'].cc = organizeCaptionServices(captions);
|
6004 | }
|
6005 |
|
6006 | return manifest;
|
6007 | };
|
6008 | |
6009 |
|
6010 |
|
6011 |
|
6012 |
|
6013 |
|
6014 |
|
6015 |
|
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 | var getLiveRValue = function getLiveRValue(attributes, time, duration) {
|
6026 | var NOW = attributes.NOW,
|
6027 | clientOffset = attributes.clientOffset,
|
6028 | availabilityStartTime = attributes.availabilityStartTime,
|
6029 | _attributes$timescale = attributes.timescale,
|
6030 | timescale = _attributes$timescale === void 0 ? 1 : _attributes$timescale,
|
6031 | _attributes$start = attributes.start,
|
6032 | start = _attributes$start === void 0 ? 0 : _attributes$start,
|
6033 | _attributes$minimumUp = attributes.minimumUpdatePeriod,
|
6034 | minimumUpdatePeriod = _attributes$minimumUp === void 0 ? 0 : _attributes$minimumUp;
|
6035 | var now = (NOW + clientOffset) / 1000;
|
6036 | var periodStartWC = availabilityStartTime + start;
|
6037 | var periodEndWC = now + minimumUpdatePeriod;
|
6038 | var periodDuration = periodEndWC - periodStartWC;
|
6039 | return Math.ceil((periodDuration * timescale - time) / duration);
|
6040 | };
|
6041 | |
6042 |
|
6043 |
|
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 |
|
6049 |
|
6050 |
|
6051 |
|
6052 |
|
6053 |
|
6054 |
|
6055 |
|
6056 | var parseByTimeline = function parseByTimeline(attributes, segmentTimeline) {
|
6057 | var type = attributes.type,
|
6058 | _attributes$minimumUp2 = attributes.minimumUpdatePeriod,
|
6059 | minimumUpdatePeriod = _attributes$minimumUp2 === void 0 ? 0 : _attributes$minimumUp2,
|
6060 | _attributes$media = attributes.media,
|
6061 | media = _attributes$media === void 0 ? '' : _attributes$media,
|
6062 | sourceDuration = attributes.sourceDuration,
|
6063 | _attributes$timescale2 = attributes.timescale,
|
6064 | timescale = _attributes$timescale2 === void 0 ? 1 : _attributes$timescale2,
|
6065 | _attributes$startNumb = attributes.startNumber,
|
6066 | startNumber = _attributes$startNumb === void 0 ? 1 : _attributes$startNumb,
|
6067 | timeline = attributes.periodIndex;
|
6068 | var segments = [];
|
6069 | var time = -1;
|
6070 |
|
6071 | for (var sIndex = 0; sIndex < segmentTimeline.length; sIndex++) {
|
6072 | var S = segmentTimeline[sIndex];
|
6073 | var duration = S.d;
|
6074 | var repeat = S.r || 0;
|
6075 | var segmentTime = S.t || 0;
|
6076 |
|
6077 | if (time < 0) {
|
6078 |
|
6079 | time = segmentTime;
|
6080 | }
|
6081 |
|
6082 | if (segmentTime && segmentTime > time) {
|
6083 |
|
6084 |
|
6085 |
|
6086 |
|
6087 |
|
6088 |
|
6089 |
|
6090 |
|
6091 |
|
6092 |
|
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 |
|
6103 | time = segmentTime;
|
6104 | }
|
6105 |
|
6106 | var count = void 0;
|
6107 |
|
6108 | if (repeat < 0) {
|
6109 | var nextS = sIndex + 1;
|
6110 |
|
6111 | if (nextS === segmentTimeline.length) {
|
6112 |
|
6113 | if (type === 'dynamic' && minimumUpdatePeriod > 0 && media.indexOf('$Number$') > 0) {
|
6114 | count = getLiveRValue(attributes, time, duration);
|
6115 | } else {
|
6116 |
|
6117 | count = (sourceDuration * timescale - time) / duration;
|
6118 | }
|
6119 | } else {
|
6120 | count = (segmentTimeline[nextS].t - time) / duration;
|
6121 | }
|
6122 | } else {
|
6123 | count = repeat + 1;
|
6124 | }
|
6125 |
|
6126 | var end = startNumber + segments.length + count;
|
6127 | var number = startNumber + segments.length;
|
6128 |
|
6129 | while (number < end) {
|
6130 | segments.push({
|
6131 | number: number,
|
6132 | duration: duration / timescale,
|
6133 | time: time,
|
6134 | timeline: timeline
|
6135 | });
|
6136 | time += duration;
|
6137 | number++;
|
6138 | }
|
6139 | }
|
6140 |
|
6141 | return segments;
|
6142 | };
|
6143 |
|
6144 | var identifierPattern = /\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g;
|
6145 | |
6146 |
|
6147 |
|
6148 |
|
6149 |
|
6150 |
|
6151 |
|
6152 |
|
6153 |
|
6154 |
|
6155 |
|
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 |
|
6161 |
|
6162 |
|
6163 |
|
6164 | |
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 |
|
6174 |
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 | var identifierReplacement = function identifierReplacement(values) {
|
6183 | return function (match, identifier, format, width) {
|
6184 | if (match === '$$') {
|
6185 |
|
6186 | return '$';
|
6187 | }
|
6188 |
|
6189 | if (typeof values[identifier] === 'undefined') {
|
6190 | return match;
|
6191 | }
|
6192 |
|
6193 | var value = '' + values[identifier];
|
6194 |
|
6195 | if (identifier === 'RepresentationID') {
|
6196 |
|
6197 | return value;
|
6198 | }
|
6199 |
|
6200 | if (!format) {
|
6201 | width = 1;
|
6202 | } else {
|
6203 | width = parseInt(width, 10);
|
6204 | }
|
6205 |
|
6206 | if (value.length >= width) {
|
6207 | return value;
|
6208 | }
|
6209 |
|
6210 | return "" + new Array(width - value.length + 1).join('0') + value;
|
6211 | };
|
6212 | };
|
6213 | |
6214 |
|
6215 |
|
6216 |
|
6217 |
|
6218 |
|
6219 |
|
6220 |
|
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 |
|
6227 |
|
6228 |
|
6229 |
|
6230 |
|
6231 |
|
6232 |
|
6233 | var constructTemplateUrl = function constructTemplateUrl(url, values) {
|
6234 | return url.replace(identifierPattern, identifierReplacement(values));
|
6235 | };
|
6236 | |
6237 |
|
6238 |
|
6239 |
|
6240 |
|
6241 |
|
6242 |
|
6243 |
|
6244 |
|
6245 |
|
6246 |
|
6247 |
|
6248 |
|
6249 |
|
6250 |
|
6251 | var parseTemplateInfo = function parseTemplateInfo(attributes, segmentTimeline) {
|
6252 | if (!attributes.duration && !segmentTimeline) {
|
6253 |
|
6254 |
|
6255 | return [{
|
6256 | number: attributes.startNumber || 1,
|
6257 | duration: attributes.sourceDuration,
|
6258 | time: 0,
|
6259 | timeline: attributes.periodIndex
|
6260 | }];
|
6261 | }
|
6262 |
|
6263 | if (attributes.duration) {
|
6264 | return parseByDuration(attributes);
|
6265 | }
|
6266 |
|
6267 | return parseByTimeline(attributes, segmentTimeline);
|
6268 | };
|
6269 | |
6270 |
|
6271 |
|
6272 |
|
6273 |
|
6274 |
|
6275 |
|
6276 |
|
6277 |
|
6278 |
|
6279 |
|
6280 |
|
6281 |
|
6282 |
|
6283 | var segmentsFromTemplate = function segmentsFromTemplate(attributes, segmentTimeline) {
|
6284 | var templateValues = {
|
6285 | RepresentationID: attributes.id,
|
6286 | Bandwidth: attributes.bandwidth || 0
|
6287 | };
|
6288 | var _attributes$initializ = attributes.initialization,
|
6289 | initialization = _attributes$initializ === void 0 ? {
|
6290 | sourceURL: '',
|
6291 | range: ''
|
6292 | } : _attributes$initializ;
|
6293 | var mapSegment = urlTypeToSegment({
|
6294 | baseUrl: attributes.baseUrl,
|
6295 | source: constructTemplateUrl(initialization.sourceURL, templateValues),
|
6296 | range: initialization.range
|
6297 | });
|
6298 | var segments = parseTemplateInfo(attributes, segmentTimeline);
|
6299 | return segments.map(function (segment) {
|
6300 | templateValues.Number = segment.number;
|
6301 | templateValues.Time = segment.time;
|
6302 | var uri = constructTemplateUrl(attributes.media || '', templateValues);
|
6303 |
|
6304 |
|
6305 | var timescale = attributes.timescale || 1;
|
6306 |
|
6307 | var presentationTimeOffset = attributes.presentationTimeOffset || 0;
|
6308 | var presentationTime =
|
6309 |
|
6310 | attributes.periodStart + (segment.time - presentationTimeOffset) / timescale;
|
6311 | var map = {
|
6312 | uri: uri,
|
6313 | timeline: segment.timeline,
|
6314 | duration: segment.duration,
|
6315 | resolvedUri: resolveUrl$1(attributes.baseUrl || '', uri),
|
6316 | map: mapSegment,
|
6317 | number: segment.number,
|
6318 | presentationTime: presentationTime
|
6319 | };
|
6320 | return map;
|
6321 | });
|
6322 | };
|
6323 | |
6324 |
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 |
|
6330 |
|
6331 |
|
6332 |
|
6333 |
|
6334 |
|
6335 |
|
6336 | var SegmentURLToSegmentObject = function SegmentURLToSegmentObject(attributes, segmentUrl) {
|
6337 | var baseUrl = attributes.baseUrl,
|
6338 | _attributes$initializ = attributes.initialization,
|
6339 | initialization = _attributes$initializ === void 0 ? {} : _attributes$initializ;
|
6340 | var initSegment = urlTypeToSegment({
|
6341 | baseUrl: baseUrl,
|
6342 | source: initialization.sourceURL,
|
6343 | range: initialization.range
|
6344 | });
|
6345 | var segment = urlTypeToSegment({
|
6346 | baseUrl: baseUrl,
|
6347 | source: segmentUrl.media,
|
6348 | range: segmentUrl.mediaRange
|
6349 | });
|
6350 | segment.map = initSegment;
|
6351 | return segment;
|
6352 | };
|
6353 | |
6354 |
|
6355 |
|
6356 |
|
6357 |
|
6358 |
|
6359 |
|
6360 |
|
6361 |
|
6362 |
|
6363 |
|
6364 |
|
6365 |
|
6366 |
|
6367 |
|
6368 | var segmentsFromList = function segmentsFromList(attributes, segmentTimeline) {
|
6369 | var duration = attributes.duration,
|
6370 | _attributes$segmentUr = attributes.segmentUrls,
|
6371 | segmentUrls = _attributes$segmentUr === void 0 ? [] : _attributes$segmentUr,
|
6372 | periodStart = attributes.periodStart;
|
6373 |
|
6374 |
|
6375 | if (!duration && !segmentTimeline || duration && segmentTimeline) {
|
6376 | throw new Error(errors.SEGMENT_TIME_UNSPECIFIED);
|
6377 | }
|
6378 |
|
6379 | var segmentUrlMap = segmentUrls.map(function (segmentUrlObject) {
|
6380 | return SegmentURLToSegmentObject(attributes, segmentUrlObject);
|
6381 | });
|
6382 | var segmentTimeInfo;
|
6383 |
|
6384 | if (duration) {
|
6385 | segmentTimeInfo = parseByDuration(attributes);
|
6386 | }
|
6387 |
|
6388 | if (segmentTimeline) {
|
6389 | segmentTimeInfo = parseByTimeline(attributes, segmentTimeline);
|
6390 | }
|
6391 |
|
6392 | var segments = segmentTimeInfo.map(function (segmentTime, index) {
|
6393 | if (segmentUrlMap[index]) {
|
6394 | var segment = segmentUrlMap[index];
|
6395 |
|
6396 |
|
6397 | var timescale = attributes.timescale || 1;
|
6398 |
|
6399 | var presentationTimeOffset = attributes.presentationTimeOffset || 0;
|
6400 | segment.timeline = segmentTime.timeline;
|
6401 | segment.duration = segmentTime.duration;
|
6402 | segment.number = segmentTime.number;
|
6403 | segment.presentationTime = periodStart + (segmentTime.time - presentationTimeOffset) / timescale;
|
6404 | return segment;
|
6405 | }
|
6406 |
|
6407 |
|
6408 |
|
6409 | }).filter(function (segment) {
|
6410 | return segment;
|
6411 | });
|
6412 | return segments;
|
6413 | };
|
6414 |
|
6415 | var generateSegments = function generateSegments(_ref) {
|
6416 | var attributes = _ref.attributes,
|
6417 | segmentInfo = _ref.segmentInfo;
|
6418 | var segmentAttributes;
|
6419 | var segmentsFn;
|
6420 |
|
6421 | if (segmentInfo.template) {
|
6422 | segmentsFn = segmentsFromTemplate;
|
6423 | segmentAttributes = merge(attributes, segmentInfo.template);
|
6424 | } else if (segmentInfo.base) {
|
6425 | segmentsFn = segmentsFromBase;
|
6426 | segmentAttributes = merge(attributes, segmentInfo.base);
|
6427 | } else if (segmentInfo.list) {
|
6428 | segmentsFn = segmentsFromList;
|
6429 | segmentAttributes = merge(attributes, segmentInfo.list);
|
6430 | }
|
6431 |
|
6432 | var segmentsInfo = {
|
6433 | attributes: attributes
|
6434 | };
|
6435 |
|
6436 | if (!segmentsFn) {
|
6437 | return segmentsInfo;
|
6438 | }
|
6439 |
|
6440 | var segments = segmentsFn(segmentAttributes, segmentInfo.segmentTimeline);
|
6441 |
|
6442 |
|
6443 |
|
6444 | if (segmentAttributes.duration) {
|
6445 | var _segmentAttributes = segmentAttributes,
|
6446 | duration = _segmentAttributes.duration,
|
6447 | _segmentAttributes$ti = _segmentAttributes.timescale,
|
6448 | timescale = _segmentAttributes$ti === void 0 ? 1 : _segmentAttributes$ti;
|
6449 | segmentAttributes.duration = duration / timescale;
|
6450 | } else if (segments.length) {
|
6451 |
|
6452 |
|
6453 | segmentAttributes.duration = segments.reduce(function (max, segment) {
|
6454 | return Math.max(max, Math.ceil(segment.duration));
|
6455 | }, 0);
|
6456 | } else {
|
6457 | segmentAttributes.duration = 0;
|
6458 | }
|
6459 |
|
6460 | segmentsInfo.attributes = segmentAttributes;
|
6461 | segmentsInfo.segments = segments;
|
6462 |
|
6463 | if (segmentInfo.base && segmentAttributes.indexRange) {
|
6464 | segmentsInfo.sidx = segments[0];
|
6465 | segmentsInfo.segments = [];
|
6466 | }
|
6467 |
|
6468 | return segmentsInfo;
|
6469 | };
|
6470 |
|
6471 | var toPlaylists = function toPlaylists(representations) {
|
6472 | return representations.map(generateSegments);
|
6473 | };
|
6474 |
|
6475 | var findChildren = function findChildren(element, name) {
|
6476 | return from(element.childNodes).filter(function (_ref) {
|
6477 | var tagName = _ref.tagName;
|
6478 | return tagName === name;
|
6479 | });
|
6480 | };
|
6481 |
|
6482 | var getContent = function getContent(element) {
|
6483 | return element.textContent.trim();
|
6484 | };
|
6485 |
|
6486 | var parseDuration = function parseDuration(str) {
|
6487 | var SECONDS_IN_YEAR = 365 * 24 * 60 * 60;
|
6488 | var SECONDS_IN_MONTH = 30 * 24 * 60 * 60;
|
6489 | var SECONDS_IN_DAY = 24 * 60 * 60;
|
6490 | var SECONDS_IN_HOUR = 60 * 60;
|
6491 | var SECONDS_IN_MIN = 60;
|
6492 |
|
6493 | var durationRegex = /P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/;
|
6494 | var match = durationRegex.exec(str);
|
6495 |
|
6496 | if (!match) {
|
6497 | return 0;
|
6498 | }
|
6499 |
|
6500 | var _match$slice = match.slice(1),
|
6501 | year = _match$slice[0],
|
6502 | month = _match$slice[1],
|
6503 | day = _match$slice[2],
|
6504 | hour = _match$slice[3],
|
6505 | minute = _match$slice[4],
|
6506 | second = _match$slice[5];
|
6507 |
|
6508 | return parseFloat(year || 0) * SECONDS_IN_YEAR + parseFloat(month || 0) * SECONDS_IN_MONTH + parseFloat(day || 0) * SECONDS_IN_DAY + parseFloat(hour || 0) * SECONDS_IN_HOUR + parseFloat(minute || 0) * SECONDS_IN_MIN + parseFloat(second || 0);
|
6509 | };
|
6510 |
|
6511 | var parseDate = function parseDate(str) {
|
6512 |
|
6513 |
|
6514 | var dateRegex = /^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/;
|
6515 |
|
6516 |
|
6517 | if (dateRegex.test(str)) {
|
6518 | str += 'Z';
|
6519 | }
|
6520 |
|
6521 | return Date.parse(str);
|
6522 | };
|
6523 |
|
6524 | var parsers = {
|
6525 | |
6526 |
|
6527 |
|
6528 |
|
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 |
|
6534 | mediaPresentationDuration: function mediaPresentationDuration(value) {
|
6535 | return parseDuration(value);
|
6536 | },
|
6537 |
|
6538 | |
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 |
|
6547 |
|
6548 | availabilityStartTime: function availabilityStartTime(value) {
|
6549 | return parseDate(value) / 1000;
|
6550 | },
|
6551 |
|
6552 | |
6553 |
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 |
|
6561 | minimumUpdatePeriod: function minimumUpdatePeriod(value) {
|
6562 | return parseDuration(value);
|
6563 | },
|
6564 |
|
6565 | |
6566 |
|
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 | suggestedPresentationDelay: function suggestedPresentationDelay(value) {
|
6575 | return parseDuration(value);
|
6576 | },
|
6577 |
|
6578 | |
6579 |
|
6580 |
|
6581 |
|
6582 |
|
6583 |
|
6584 |
|
6585 |
|
6586 |
|
6587 | type: function type(value) {
|
6588 | return value;
|
6589 | },
|
6590 |
|
6591 | |
6592 |
|
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 | timeShiftBufferDepth: function timeShiftBufferDepth(value) {
|
6601 | return parseDuration(value);
|
6602 | },
|
6603 |
|
6604 | |
6605 |
|
6606 |
|
6607 |
|
6608 |
|
6609 |
|
6610 |
|
6611 |
|
6612 |
|
6613 | start: function start(value) {
|
6614 | return parseDuration(value);
|
6615 | },
|
6616 |
|
6617 | |
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 | width: function width(value) {
|
6626 | return parseInt(value, 10);
|
6627 | },
|
6628 |
|
6629 | |
6630 |
|
6631 |
|
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 |
|
6637 | height: function height(value) {
|
6638 | return parseInt(value, 10);
|
6639 | },
|
6640 |
|
6641 | |
6642 |
|
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 | bandwidth: function bandwidth(value) {
|
6650 | return parseInt(value, 10);
|
6651 | },
|
6652 |
|
6653 | |
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 |
|
6659 |
|
6660 |
|
6661 | startNumber: function startNumber(value) {
|
6662 | return parseInt(value, 10);
|
6663 | },
|
6664 |
|
6665 | |
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 | timescale: function timescale(value) {
|
6674 | return parseInt(value, 10);
|
6675 | },
|
6676 |
|
6677 | |
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 |
|
6686 | presentationTimeOffset: function presentationTimeOffset(value) {
|
6687 | return parseInt(value, 10);
|
6688 | },
|
6689 |
|
6690 | |
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 |
|
6700 |
|
6701 |
|
6702 | duration: function duration(value) {
|
6703 | var parsedValue = parseInt(value, 10);
|
6704 |
|
6705 | if (isNaN(parsedValue)) {
|
6706 | return parseDuration(value);
|
6707 | }
|
6708 |
|
6709 | return parsedValue;
|
6710 | },
|
6711 |
|
6712 | |
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 |
|
6719 |
|
6720 | d: function d(value) {
|
6721 | return parseInt(value, 10);
|
6722 | },
|
6723 |
|
6724 | |
6725 |
|
6726 |
|
6727 |
|
6728 |
|
6729 |
|
6730 |
|
6731 |
|
6732 |
|
6733 | t: function t(value) {
|
6734 | return parseInt(value, 10);
|
6735 | },
|
6736 |
|
6737 | |
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 |
|
6746 | r: function r(value) {
|
6747 | return parseInt(value, 10);
|
6748 | },
|
6749 |
|
6750 | |
6751 |
|
6752 |
|
6753 |
|
6754 |
|
6755 |
|
6756 |
|
6757 |
|
6758 |
|
6759 | DEFAULT: function DEFAULT(value) {
|
6760 | return value;
|
6761 | }
|
6762 | };
|
6763 | |
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 | var parseAttributes = function parseAttributes(el) {
|
6774 | if (!(el && el.attributes)) {
|
6775 | return {};
|
6776 | }
|
6777 |
|
6778 | return from(el.attributes).reduce(function (a, e) {
|
6779 | var parseFn = parsers[e.name] || parsers.DEFAULT;
|
6780 | a[e.name] = parseFn(e.value);
|
6781 | return a;
|
6782 | }, {});
|
6783 | };
|
6784 |
|
6785 | var keySystemsMap = {
|
6786 | 'urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b': 'org.w3.clearkey',
|
6787 | 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed': 'com.widevine.alpha',
|
6788 | 'urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95': 'com.microsoft.playready',
|
6789 | 'urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb': 'com.adobe.primetime'
|
6790 | };
|
6791 | |
6792 |
|
6793 |
|
6794 |
|
6795 |
|
6796 |
|
6797 |
|
6798 |
|
6799 |
|
6800 |
|
6801 |
|
6802 | var buildBaseUrls = function buildBaseUrls(referenceUrls, baseUrlElements) {
|
6803 | if (!baseUrlElements.length) {
|
6804 | return referenceUrls;
|
6805 | }
|
6806 |
|
6807 | return flatten(referenceUrls.map(function (reference) {
|
6808 | return baseUrlElements.map(function (baseUrlElement) {
|
6809 | return resolveUrl$1(reference, getContent(baseUrlElement));
|
6810 | });
|
6811 | }));
|
6812 | };
|
6813 | |
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 |
|
6827 | |
6828 |
|
6829 |
|
6830 |
|
6831 |
|
6832 |
|
6833 |
|
6834 |
|
6835 |
|
6836 |
|
6837 | var getSegmentInformation = function getSegmentInformation(adaptationSet) {
|
6838 | var segmentTemplate = findChildren(adaptationSet, 'SegmentTemplate')[0];
|
6839 | var segmentList = findChildren(adaptationSet, 'SegmentList')[0];
|
6840 | var segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL').map(function (s) {
|
6841 | return merge({
|
6842 | tag: 'SegmentURL'
|
6843 | }, parseAttributes(s));
|
6844 | });
|
6845 | var segmentBase = findChildren(adaptationSet, 'SegmentBase')[0];
|
6846 | var segmentTimelineParentNode = segmentList || segmentTemplate;
|
6847 | var segmentTimeline = segmentTimelineParentNode && findChildren(segmentTimelineParentNode, 'SegmentTimeline')[0];
|
6848 | var segmentInitializationParentNode = segmentList || segmentBase || segmentTemplate;
|
6849 | var segmentInitialization = segmentInitializationParentNode && findChildren(segmentInitializationParentNode, 'Initialization')[0];
|
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 | var template = segmentTemplate && parseAttributes(segmentTemplate);
|
6856 |
|
6857 | if (template && segmentInitialization) {
|
6858 | template.initialization = segmentInitialization && parseAttributes(segmentInitialization);
|
6859 | } else if (template && template.initialization) {
|
6860 |
|
6861 |
|
6862 |
|
6863 | template.initialization = {
|
6864 | sourceURL: template.initialization
|
6865 | };
|
6866 | }
|
6867 |
|
6868 | var segmentInfo = {
|
6869 | template: template,
|
6870 | segmentTimeline: segmentTimeline && findChildren(segmentTimeline, 'S').map(function (s) {
|
6871 | return parseAttributes(s);
|
6872 | }),
|
6873 | list: segmentList && merge(parseAttributes(segmentList), {
|
6874 | segmentUrls: segmentUrls,
|
6875 | initialization: parseAttributes(segmentInitialization)
|
6876 | }),
|
6877 | base: segmentBase && merge(parseAttributes(segmentBase), {
|
6878 | initialization: parseAttributes(segmentInitialization)
|
6879 | })
|
6880 | };
|
6881 | Object.keys(segmentInfo).forEach(function (key) {
|
6882 | if (!segmentInfo[key]) {
|
6883 | delete segmentInfo[key];
|
6884 | }
|
6885 | });
|
6886 | return segmentInfo;
|
6887 | };
|
6888 | |
6889 |
|
6890 |
|
6891 |
|
6892 |
|
6893 |
|
6894 |
|
6895 |
|
6896 |
|
6897 |
|
6898 |
|
6899 | |
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 |
|
6906 |
|
6907 |
|
6908 |
|
6909 |
|
6910 | |
6911 |
|
6912 |
|
6913 |
|
6914 |
|
6915 |
|
6916 |
|
6917 |
|
6918 |
|
6919 |
|
6920 |
|
6921 |
|
6922 |
|
6923 |
|
6924 |
|
6925 | var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) {
|
6926 | return function (representation) {
|
6927 | var repBaseUrlElements = findChildren(representation, 'BaseURL');
|
6928 | var repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements);
|
6929 | var attributes = merge(adaptationSetAttributes, parseAttributes(representation));
|
6930 | var representationSegmentInfo = getSegmentInformation(representation);
|
6931 | return repBaseUrls.map(function (baseUrl) {
|
6932 | return {
|
6933 | segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo),
|
6934 | attributes: merge(attributes, {
|
6935 | baseUrl: baseUrl
|
6936 | })
|
6937 | };
|
6938 | });
|
6939 | };
|
6940 | };
|
6941 | |
6942 |
|
6943 |
|
6944 |
|
6945 |
|
6946 |
|
6947 |
|
6948 |
|
6949 |
|
6950 |
|
6951 |
|
6952 | var generateKeySystemInformation = function generateKeySystemInformation(contentProtectionNodes) {
|
6953 | return contentProtectionNodes.reduce(function (acc, node) {
|
6954 | var attributes = parseAttributes(node);
|
6955 | var keySystem = keySystemsMap[attributes.schemeIdUri];
|
6956 |
|
6957 | if (keySystem) {
|
6958 | acc[keySystem] = {
|
6959 | attributes: attributes
|
6960 | };
|
6961 | var psshNode = findChildren(node, 'cenc:pssh')[0];
|
6962 |
|
6963 | if (psshNode) {
|
6964 | var pssh = getContent(psshNode);
|
6965 | var psshBuffer = pssh && decodeB64ToUint8Array(pssh);
|
6966 | acc[keySystem].pssh = psshBuffer;
|
6967 | }
|
6968 | }
|
6969 |
|
6970 | return acc;
|
6971 | }, {});
|
6972 | };
|
6973 |
|
6974 |
|
6975 | var parseCaptionServiceMetadata = function parseCaptionServiceMetadata(service) {
|
6976 |
|
6977 | if (service.schemeIdUri === 'urn:scte:dash:cc:cea-608:2015') {
|
6978 | var values = typeof service.value !== 'string' ? [] : service.value.split(';');
|
6979 | return values.map(function (value) {
|
6980 | var channel;
|
6981 | var language;
|
6982 |
|
6983 | language = value;
|
6984 |
|
6985 | if (/^CC\d=/.test(value)) {
|
6986 | var _value$split = value.split('=');
|
6987 |
|
6988 | channel = _value$split[0];
|
6989 | language = _value$split[1];
|
6990 | } else if (/^CC\d$/.test(value)) {
|
6991 | channel = value;
|
6992 | }
|
6993 |
|
6994 | return {
|
6995 | channel: channel,
|
6996 | language: language
|
6997 | };
|
6998 | });
|
6999 | } else if (service.schemeIdUri === 'urn:scte:dash:cc:cea-708:2015') {
|
7000 | var _values = typeof service.value !== 'string' ? [] : service.value.split(';');
|
7001 |
|
7002 | return _values.map(function (value) {
|
7003 | var flags = {
|
7004 |
|
7005 | 'channel': undefined,
|
7006 |
|
7007 |
|
7008 | 'language': undefined,
|
7009 |
|
7010 |
|
7011 | 'aspectRatio': 1,
|
7012 |
|
7013 |
|
7014 |
|
7015 | 'easyReader': 0,
|
7016 |
|
7017 |
|
7018 |
|
7019 | '3D': 0
|
7020 | };
|
7021 |
|
7022 | if (/=/.test(value)) {
|
7023 | var _value$split2 = value.split('='),
|
7024 | channel = _value$split2[0],
|
7025 | _value$split2$ = _value$split2[1],
|
7026 | opts = _value$split2$ === void 0 ? '' : _value$split2$;
|
7027 |
|
7028 | flags.channel = channel;
|
7029 | flags.language = value;
|
7030 | opts.split(',').forEach(function (opt) {
|
7031 | var _opt$split = opt.split(':'),
|
7032 | name = _opt$split[0],
|
7033 | val = _opt$split[1];
|
7034 |
|
7035 | if (name === 'lang') {
|
7036 | flags.language = val;
|
7037 | } else if (name === 'er') {
|
7038 | flags.easyReader = Number(val);
|
7039 | } else if (name === 'war') {
|
7040 | flags.aspectRatio = Number(val);
|
7041 | } else if (name === '3D') {
|
7042 | flags['3D'] = Number(val);
|
7043 | }
|
7044 | });
|
7045 | } else {
|
7046 | flags.language = value;
|
7047 | }
|
7048 |
|
7049 | if (flags.channel) {
|
7050 | flags.channel = 'SERVICE' + flags.channel;
|
7051 | }
|
7052 |
|
7053 | return flags;
|
7054 | });
|
7055 | }
|
7056 | };
|
7057 | |
7058 |
|
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 |
|
7065 |
|
7066 |
|
7067 |
|
7068 | |
7069 |
|
7070 |
|
7071 |
|
7072 |
|
7073 |
|
7074 |
|
7075 |
|
7076 |
|
7077 |
|
7078 |
|
7079 |
|
7080 |
|
7081 |
|
7082 |
|
7083 | var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo) {
|
7084 | return function (adaptationSet) {
|
7085 | var adaptationSetAttributes = parseAttributes(adaptationSet);
|
7086 | var adaptationSetBaseUrls = buildBaseUrls(periodBaseUrls, findChildren(adaptationSet, 'BaseURL'));
|
7087 | var role = findChildren(adaptationSet, 'Role')[0];
|
7088 | var roleAttributes = {
|
7089 | role: parseAttributes(role)
|
7090 | };
|
7091 | var attrs = merge(periodAttributes, adaptationSetAttributes, roleAttributes);
|
7092 | var accessibility = findChildren(adaptationSet, 'Accessibility')[0];
|
7093 | var captionServices = parseCaptionServiceMetadata(parseAttributes(accessibility));
|
7094 |
|
7095 | if (captionServices) {
|
7096 | attrs = merge(attrs, {
|
7097 | captionServices: captionServices
|
7098 | });
|
7099 | }
|
7100 |
|
7101 | var label = findChildren(adaptationSet, 'Label')[0];
|
7102 |
|
7103 | if (label && label.childNodes.length) {
|
7104 | var labelVal = label.childNodes[0].nodeValue.trim();
|
7105 | attrs = merge(attrs, {
|
7106 | label: labelVal
|
7107 | });
|
7108 | }
|
7109 |
|
7110 | var contentProtection = generateKeySystemInformation(findChildren(adaptationSet, 'ContentProtection'));
|
7111 |
|
7112 | if (Object.keys(contentProtection).length) {
|
7113 | attrs = merge(attrs, {
|
7114 | contentProtection: contentProtection
|
7115 | });
|
7116 | }
|
7117 |
|
7118 | var segmentInfo = getSegmentInformation(adaptationSet);
|
7119 | var representations = findChildren(adaptationSet, 'Representation');
|
7120 | var adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo);
|
7121 | return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo)));
|
7122 | };
|
7123 | };
|
7124 | |
7125 |
|
7126 |
|
7127 |
|
7128 |
|
7129 |
|
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 | |
7135 |
|
7136 |
|
7137 |
|
7138 |
|
7139 |
|
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 |
|
7147 |
|
7148 | |
7149 |
|
7150 |
|
7151 |
|
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 |
|
7159 |
|
7160 |
|
7161 | var toAdaptationSets = function toAdaptationSets(mpdAttributes, mpdBaseUrls) {
|
7162 | return function (period, index) {
|
7163 | var periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period.node, 'BaseURL'));
|
7164 | var parsedPeriodId = parseInt(period.attributes.id, 10);
|
7165 |
|
7166 | var periodIndex = window.isNaN(parsedPeriodId) ? index : parsedPeriodId;
|
7167 | var periodAttributes = merge(mpdAttributes, {
|
7168 | periodIndex: periodIndex,
|
7169 | periodStart: period.attributes.start
|
7170 | });
|
7171 |
|
7172 | if (typeof period.attributes.duration === 'number') {
|
7173 | periodAttributes.periodDuration = period.attributes.duration;
|
7174 | }
|
7175 |
|
7176 | var adaptationSets = findChildren(period.node, 'AdaptationSet');
|
7177 | var periodSegmentInfo = getSegmentInformation(period.node);
|
7178 | return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo)));
|
7179 | };
|
7180 | };
|
7181 | |
7182 |
|
7183 |
|
7184 |
|
7185 |
|
7186 |
|
7187 |
|
7188 |
|
7189 |
|
7190 |
|
7191 |
|
7192 |
|
7193 |
|
7194 |
|
7195 |
|
7196 |
|
7197 | var getPeriodStart = function getPeriodStart(_ref) {
|
7198 | var attributes = _ref.attributes,
|
7199 | priorPeriodAttributes = _ref.priorPeriodAttributes,
|
7200 | mpdType = _ref.mpdType;
|
7201 |
|
7202 |
|
7203 |
|
7204 |
|
7205 |
|
7206 |
|
7207 |
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 |
|
7213 |
|
7214 |
|
7215 | if (typeof attributes.start === 'number') {
|
7216 | return attributes.start;
|
7217 | }
|
7218 |
|
7219 |
|
7220 | if (priorPeriodAttributes && typeof priorPeriodAttributes.start === 'number' && typeof priorPeriodAttributes.duration === 'number') {
|
7221 | return priorPeriodAttributes.start + priorPeriodAttributes.duration;
|
7222 | }
|
7223 |
|
7224 |
|
7225 | if (!priorPeriodAttributes && mpdType === 'static') {
|
7226 | return 0;
|
7227 | }
|
7228 |
|
7229 |
|
7230 |
|
7231 |
|
7232 |
|
7233 |
|
7234 |
|
7235 |
|
7236 | return null;
|
7237 | };
|
7238 | |
7239 |
|
7240 |
|
7241 |
|
7242 |
|
7243 |
|
7244 |
|
7245 |
|
7246 |
|
7247 |
|
7248 |
|
7249 |
|
7250 |
|
7251 |
|
7252 |
|
7253 |
|
7254 |
|
7255 |
|
7256 |
|
7257 | var inheritAttributes = function inheritAttributes(mpd, options) {
|
7258 | if (options === void 0) {
|
7259 | options = {};
|
7260 | }
|
7261 |
|
7262 | var _options = options,
|
7263 | _options$manifestUri = _options.manifestUri,
|
7264 | manifestUri = _options$manifestUri === void 0 ? '' : _options$manifestUri,
|
7265 | _options$NOW = _options.NOW,
|
7266 | NOW = _options$NOW === void 0 ? Date.now() : _options$NOW,
|
7267 | _options$clientOffset = _options.clientOffset,
|
7268 | clientOffset = _options$clientOffset === void 0 ? 0 : _options$clientOffset;
|
7269 | var periodNodes = findChildren(mpd, 'Period');
|
7270 |
|
7271 | if (!periodNodes.length) {
|
7272 | throw new Error(errors.INVALID_NUMBER_OF_PERIOD);
|
7273 | }
|
7274 |
|
7275 | var locations = findChildren(mpd, 'Location');
|
7276 | var mpdAttributes = parseAttributes(mpd);
|
7277 | var mpdBaseUrls = buildBaseUrls([manifestUri], findChildren(mpd, 'BaseURL'));
|
7278 |
|
7279 | mpdAttributes.type = mpdAttributes.type || 'static';
|
7280 | mpdAttributes.sourceDuration = mpdAttributes.mediaPresentationDuration || 0;
|
7281 | mpdAttributes.NOW = NOW;
|
7282 | mpdAttributes.clientOffset = clientOffset;
|
7283 |
|
7284 | if (locations.length) {
|
7285 | mpdAttributes.locations = locations.map(getContent);
|
7286 | }
|
7287 |
|
7288 | var periods = [];
|
7289 |
|
7290 |
|
7291 |
|
7292 |
|
7293 | periodNodes.forEach(function (node, index) {
|
7294 | var attributes = parseAttributes(node);
|
7295 |
|
7296 |
|
7297 | var priorPeriod = periods[index - 1];
|
7298 | attributes.start = getPeriodStart({
|
7299 | attributes: attributes,
|
7300 | priorPeriodAttributes: priorPeriod ? priorPeriod.attributes : null,
|
7301 | mpdType: mpdAttributes.type
|
7302 | });
|
7303 | periods.push({
|
7304 | node: node,
|
7305 | attributes: attributes
|
7306 | });
|
7307 | });
|
7308 | return {
|
7309 | locations: mpdAttributes.locations,
|
7310 | representationInfo: flatten(periods.map(toAdaptationSets(mpdAttributes, mpdBaseUrls)))
|
7311 | };
|
7312 | };
|
7313 |
|
7314 | var stringToMpdXml = function stringToMpdXml(manifestString) {
|
7315 | if (manifestString === '') {
|
7316 | throw new Error(errors.DASH_EMPTY_MANIFEST);
|
7317 | }
|
7318 |
|
7319 | var parser = new xmldom.DOMParser();
|
7320 | var xml;
|
7321 | var mpd;
|
7322 |
|
7323 | try {
|
7324 | xml = parser.parseFromString(manifestString, 'application/xml');
|
7325 | mpd = xml && xml.documentElement.tagName === 'MPD' ? xml.documentElement : null;
|
7326 | } catch (e) {
|
7327 | }
|
7328 |
|
7329 | if (!mpd || mpd && mpd.getElementsByTagName('parsererror').length > 0) {
|
7330 | throw new Error(errors.DASH_INVALID_XML);
|
7331 | }
|
7332 |
|
7333 | return mpd;
|
7334 | };
|
7335 | |
7336 |
|
7337 |
|
7338 |
|
7339 |
|
7340 |
|
7341 |
|
7342 |
|
7343 |
|
7344 |
|
7345 | var parseUTCTimingScheme = function parseUTCTimingScheme(mpd) {
|
7346 | var UTCTimingNode = findChildren(mpd, 'UTCTiming')[0];
|
7347 |
|
7348 | if (!UTCTimingNode) {
|
7349 | return null;
|
7350 | }
|
7351 |
|
7352 | var attributes = parseAttributes(UTCTimingNode);
|
7353 |
|
7354 | switch (attributes.schemeIdUri) {
|
7355 | case 'urn:mpeg:dash:utc:http-head:2014':
|
7356 | case 'urn:mpeg:dash:utc:http-head:2012':
|
7357 | attributes.method = 'HEAD';
|
7358 | break;
|
7359 |
|
7360 | case 'urn:mpeg:dash:utc:http-xsdate:2014':
|
7361 | case 'urn:mpeg:dash:utc:http-iso:2014':
|
7362 | case 'urn:mpeg:dash:utc:http-xsdate:2012':
|
7363 | case 'urn:mpeg:dash:utc:http-iso:2012':
|
7364 | attributes.method = 'GET';
|
7365 | break;
|
7366 |
|
7367 | case 'urn:mpeg:dash:utc:direct:2014':
|
7368 | case 'urn:mpeg:dash:utc:direct:2012':
|
7369 | attributes.method = 'DIRECT';
|
7370 | attributes.value = Date.parse(attributes.value);
|
7371 | break;
|
7372 |
|
7373 | case 'urn:mpeg:dash:utc:http-ntp:2014':
|
7374 | case 'urn:mpeg:dash:utc:ntp:2014':
|
7375 | case 'urn:mpeg:dash:utc:sntp:2014':
|
7376 | default:
|
7377 | throw new Error(errors.UNSUPPORTED_UTC_TIMING_SCHEME);
|
7378 | }
|
7379 |
|
7380 | return attributes;
|
7381 | };
|
7382 |
|
7383 | var parse = function parse(manifestString, options) {
|
7384 | if (options === void 0) {
|
7385 | options = {};
|
7386 | }
|
7387 |
|
7388 | var parsedManifestInfo = inheritAttributes(stringToMpdXml(manifestString), options);
|
7389 | var playlists = toPlaylists(parsedManifestInfo.representationInfo);
|
7390 | return toM3u8(playlists, parsedManifestInfo.locations, options.sidxMapping);
|
7391 | };
|
7392 | |
7393 |
|
7394 |
|
7395 |
|
7396 |
|
7397 |
|
7398 |
|
7399 |
|
7400 |
|
7401 |
|
7402 | var parseUTCTiming = function parseUTCTiming(manifestString) {
|
7403 | return parseUTCTimingScheme(stringToMpdXml(manifestString));
|
7404 | };
|
7405 |
|
7406 | var MAX_UINT32 = Math.pow(2, 32);
|
7407 |
|
7408 | var parseSidx = function parseSidx(data) {
|
7409 | var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
7410 | result = {
|
7411 | version: data[0],
|
7412 | flags: new Uint8Array(data.subarray(1, 4)),
|
7413 | references: [],
|
7414 | referenceId: view.getUint32(4),
|
7415 | timescale: view.getUint32(8)
|
7416 | },
|
7417 | i = 12;
|
7418 |
|
7419 | if (result.version === 0) {
|
7420 | result.earliestPresentationTime = view.getUint32(i);
|
7421 | result.firstOffset = view.getUint32(i + 4);
|
7422 | i += 8;
|
7423 | } else {
|
7424 |
|
7425 | result.earliestPresentationTime = view.getUint32(i) * MAX_UINT32 + view.getUint32(i + 4);
|
7426 | result.firstOffset = view.getUint32(i + 8) * MAX_UINT32 + view.getUint32(i + 12);
|
7427 | i += 16;
|
7428 | }
|
7429 |
|
7430 | i += 2;
|
7431 |
|
7432 | var referenceCount = view.getUint16(i);
|
7433 | i += 2;
|
7434 |
|
7435 | for (; referenceCount > 0; i += 12, referenceCount--) {
|
7436 | result.references.push({
|
7437 | referenceType: (data[i] & 0x80) >>> 7,
|
7438 | referencedSize: view.getUint32(i) & 0x7FFFFFFF,
|
7439 | subsegmentDuration: view.getUint32(i + 4),
|
7440 | startsWithSap: !!(data[i + 8] & 0x80),
|
7441 | sapType: (data[i + 8] & 0x70) >>> 4,
|
7442 | sapDeltaTime: view.getUint32(i + 8) & 0x0FFFFFFF
|
7443 | });
|
7444 | }
|
7445 |
|
7446 | return result;
|
7447 | };
|
7448 |
|
7449 | var parseSidx_1 = parseSidx;
|
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 | var countBits = function countBits(x) {
|
7457 | return x.toString(2).length;
|
7458 | };
|
7459 |
|
7460 | var countBytes = function countBytes(x) {
|
7461 | return Math.ceil(countBits(x) / 8);
|
7462 | };
|
7463 | var isTypedArray = function isTypedArray(obj) {
|
7464 | return ArrayBuffer.isView(obj);
|
7465 | };
|
7466 | var toUint8 = function toUint8(bytes) {
|
7467 | if (bytes instanceof Uint8Array) {
|
7468 | return bytes;
|
7469 | }
|
7470 |
|
7471 | if (!Array.isArray(bytes) && !isTypedArray(bytes) && !(bytes instanceof ArrayBuffer)) {
|
7472 |
|
7473 |
|
7474 | if (typeof bytes !== 'number' || typeof bytes === 'number' && bytes !== bytes) {
|
7475 | bytes = 0;
|
7476 | } else {
|
7477 | bytes = [bytes];
|
7478 | }
|
7479 | }
|
7480 |
|
7481 | return new Uint8Array(bytes && bytes.buffer || bytes, bytes && bytes.byteOffset || 0, bytes && bytes.byteLength || 0);
|
7482 | };
|
7483 | var BigInt = window.BigInt || Number;
|
7484 | var BYTE_TABLE = [BigInt('0x1'), BigInt('0x100'), BigInt('0x10000'), BigInt('0x1000000'), BigInt('0x100000000'), BigInt('0x10000000000'), BigInt('0x1000000000000'), BigInt('0x100000000000000'), BigInt('0x10000000000000000')];
|
7485 | (function () {
|
7486 | var a = new Uint16Array([0xFFCC]);
|
7487 | var b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
7488 |
|
7489 | if (b[0] === 0xFF) {
|
7490 | return 'big';
|
7491 | }
|
7492 |
|
7493 | if (b[0] === 0xCC) {
|
7494 | return 'little';
|
7495 | }
|
7496 |
|
7497 | return 'unknown';
|
7498 | })();
|
7499 | var bytesToNumber = function bytesToNumber(bytes, _temp) {
|
7500 | var _ref = _temp === void 0 ? {} : _temp,
|
7501 | _ref$signed = _ref.signed,
|
7502 | signed = _ref$signed === void 0 ? false : _ref$signed,
|
7503 | _ref$le = _ref.le,
|
7504 | le = _ref$le === void 0 ? false : _ref$le;
|
7505 |
|
7506 | bytes = toUint8(bytes);
|
7507 | var fn = le ? 'reduce' : 'reduceRight';
|
7508 | var obj = bytes[fn] ? bytes[fn] : Array.prototype[fn];
|
7509 | var number = obj.call(bytes, function (total, byte, i) {
|
7510 | var exponent = le ? i : Math.abs(i + 1 - bytes.length);
|
7511 | return total + BigInt(byte) * BYTE_TABLE[exponent];
|
7512 | }, BigInt(0));
|
7513 |
|
7514 | if (signed) {
|
7515 | var max = BYTE_TABLE[bytes.length] / BigInt(2) - BigInt(1);
|
7516 | number = BigInt(number);
|
7517 |
|
7518 | if (number > max) {
|
7519 | number -= max;
|
7520 | number -= max;
|
7521 | number -= BigInt(2);
|
7522 | }
|
7523 | }
|
7524 |
|
7525 | return Number(number);
|
7526 | };
|
7527 | var numberToBytes = function numberToBytes(number, _temp2) {
|
7528 | var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
7529 | _ref2$le = _ref2.le,
|
7530 | le = _ref2$le === void 0 ? false : _ref2$le;
|
7531 |
|
7532 |
|
7533 | if (typeof number !== 'bigint' && typeof number !== 'number' || typeof number === 'number' && number !== number) {
|
7534 | number = 0;
|
7535 | }
|
7536 |
|
7537 | number = BigInt(number);
|
7538 | var byteCount = countBytes(number);
|
7539 | var bytes = new Uint8Array(new ArrayBuffer(byteCount));
|
7540 |
|
7541 | for (var i = 0; i < byteCount; i++) {
|
7542 | var byteIndex = le ? i : Math.abs(i + 1 - bytes.length);
|
7543 | bytes[byteIndex] = Number(number / BYTE_TABLE[i] & BigInt(0xFF));
|
7544 |
|
7545 | if (number < 0) {
|
7546 | bytes[byteIndex] = Math.abs(~bytes[byteIndex]);
|
7547 | bytes[byteIndex] -= i === 0 ? 1 : 2;
|
7548 | }
|
7549 | }
|
7550 |
|
7551 | return bytes;
|
7552 | };
|
7553 | var stringToBytes = function stringToBytes(string, stringIsBytes) {
|
7554 | if (typeof string !== 'string' && string && typeof string.toString === 'function') {
|
7555 | string = string.toString();
|
7556 | }
|
7557 |
|
7558 | if (typeof string !== 'string') {
|
7559 | return new Uint8Array();
|
7560 | }
|
7561 |
|
7562 |
|
7563 |
|
7564 |
|
7565 | if (!stringIsBytes) {
|
7566 | string = unescape(encodeURIComponent(string));
|
7567 | }
|
7568 |
|
7569 | var view = new Uint8Array(string.length);
|
7570 |
|
7571 | for (var i = 0; i < string.length; i++) {
|
7572 | view[i] = string.charCodeAt(i);
|
7573 | }
|
7574 |
|
7575 | return view;
|
7576 | };
|
7577 | var concatTypedArrays = function concatTypedArrays() {
|
7578 | for (var _len = arguments.length, buffers = new Array(_len), _key = 0; _key < _len; _key++) {
|
7579 | buffers[_key] = arguments[_key];
|
7580 | }
|
7581 |
|
7582 | buffers = buffers.filter(function (b) {
|
7583 | return b && (b.byteLength || b.length) && typeof b !== 'string';
|
7584 | });
|
7585 |
|
7586 | if (buffers.length <= 1) {
|
7587 |
|
7588 |
|
7589 | return toUint8(buffers[0]);
|
7590 | }
|
7591 |
|
7592 | var totalLen = buffers.reduce(function (total, buf, i) {
|
7593 | return total + (buf.byteLength || buf.length);
|
7594 | }, 0);
|
7595 | var tempBuffer = new Uint8Array(totalLen);
|
7596 | var offset = 0;
|
7597 | buffers.forEach(function (buf) {
|
7598 | buf = toUint8(buf);
|
7599 | tempBuffer.set(buf, offset);
|
7600 | offset += buf.byteLength;
|
7601 | });
|
7602 | return tempBuffer;
|
7603 | };
|
7604 | |
7605 |
|
7606 |
|
7607 |
|
7608 |
|
7609 |
|
7610 |
|
7611 |
|
7612 |
|
7613 |
|
7614 |
|
7615 |
|
7616 |
|
7617 |
|
7618 |
|
7619 |
|
7620 |
|
7621 |
|
7622 |
|
7623 |
|
7624 |
|
7625 |
|
7626 |
|
7627 | var bytesMatch = function bytesMatch(a, b, _temp3) {
|
7628 | var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
7629 | _ref3$offset = _ref3.offset,
|
7630 | offset = _ref3$offset === void 0 ? 0 : _ref3$offset,
|
7631 | _ref3$mask = _ref3.mask,
|
7632 | mask = _ref3$mask === void 0 ? [] : _ref3$mask;
|
7633 |
|
7634 | a = toUint8(a);
|
7635 | b = toUint8(b);
|
7636 |
|
7637 | var fn = b.every ? b.every : Array.prototype.every;
|
7638 | return b.length && a.length - offset >= b.length &&
|
7639 | fn.call(b, function (bByte, i) {
|
7640 | var aByte = mask[i] ? mask[i] & a[offset + i] : a[offset + i];
|
7641 | return bByte === aByte;
|
7642 | });
|
7643 | };
|
7644 |
|
7645 | var ID3 = toUint8([0x49, 0x44, 0x33]);
|
7646 | var getId3Size = function getId3Size(bytes, offset) {
|
7647 | if (offset === void 0) {
|
7648 | offset = 0;
|
7649 | }
|
7650 |
|
7651 | bytes = toUint8(bytes);
|
7652 | var flags = bytes[offset + 5];
|
7653 | var returnSize = bytes[offset + 6] << 21 | bytes[offset + 7] << 14 | bytes[offset + 8] << 7 | bytes[offset + 9];
|
7654 | var footerPresent = (flags & 16) >> 4;
|
7655 |
|
7656 | if (footerPresent) {
|
7657 | return returnSize + 20;
|
7658 | }
|
7659 |
|
7660 | return returnSize + 10;
|
7661 | };
|
7662 | var getId3Offset = function getId3Offset(bytes, offset) {
|
7663 | if (offset === void 0) {
|
7664 | offset = 0;
|
7665 | }
|
7666 |
|
7667 | bytes = toUint8(bytes);
|
7668 |
|
7669 | if (bytes.length - offset < 10 || !bytesMatch(bytes, ID3, {
|
7670 | offset: offset
|
7671 | })) {
|
7672 | return offset;
|
7673 | }
|
7674 |
|
7675 | offset += getId3Size(bytes, offset);
|
7676 |
|
7677 |
|
7678 |
|
7679 | return getId3Offset(bytes, offset);
|
7680 | };
|
7681 |
|
7682 | var normalizePath$1 = function normalizePath(path) {
|
7683 | if (typeof path === 'string') {
|
7684 | return stringToBytes(path);
|
7685 | }
|
7686 |
|
7687 | if (typeof path === 'number') {
|
7688 | return path;
|
7689 | }
|
7690 |
|
7691 | return path;
|
7692 | };
|
7693 |
|
7694 | var normalizePaths$1 = function normalizePaths(paths) {
|
7695 | if (!Array.isArray(paths)) {
|
7696 | return [normalizePath$1(paths)];
|
7697 | }
|
7698 |
|
7699 | return paths.map(function (p) {
|
7700 | return normalizePath$1(p);
|
7701 | });
|
7702 | };
|
7703 | |
7704 |
|
7705 |
|
7706 |
|
7707 |
|
7708 |
|
7709 |
|
7710 |
|
7711 |
|
7712 |
|
7713 |
|
7714 |
|
7715 |
|
7716 |
|
7717 |
|
7718 |
|
7719 |
|
7720 |
|
7721 |
|
7722 |
|
7723 |
|
7724 | var findBox = function findBox(bytes, paths, complete) {
|
7725 | if (complete === void 0) {
|
7726 | complete = false;
|
7727 | }
|
7728 |
|
7729 | paths = normalizePaths$1(paths);
|
7730 | bytes = toUint8(bytes);
|
7731 | var results = [];
|
7732 |
|
7733 | if (!paths.length) {
|
7734 |
|
7735 | return results;
|
7736 | }
|
7737 |
|
7738 | var i = 0;
|
7739 |
|
7740 | while (i < bytes.length) {
|
7741 | var size = (bytes[i] << 24 | bytes[i + 1] << 16 | bytes[i + 2] << 8 | bytes[i + 3]) >>> 0;
|
7742 | var type = bytes.subarray(i + 4, i + 8);
|
7743 |
|
7744 | if (size === 0) {
|
7745 | break;
|
7746 | }
|
7747 |
|
7748 | var end = i + size;
|
7749 |
|
7750 | if (end > bytes.length) {
|
7751 |
|
7752 |
|
7753 | if (complete) {
|
7754 | break;
|
7755 | }
|
7756 |
|
7757 | end = bytes.length;
|
7758 | }
|
7759 |
|
7760 | var data = bytes.subarray(i + 8, end);
|
7761 |
|
7762 | if (bytesMatch(type, paths[0])) {
|
7763 | if (paths.length === 1) {
|
7764 |
|
7765 |
|
7766 | results.push(data);
|
7767 | } else {
|
7768 |
|
7769 | results.push.apply(results, findBox(data, paths.slice(1), complete));
|
7770 | }
|
7771 | }
|
7772 |
|
7773 | i = end;
|
7774 | }
|
7775 |
|
7776 |
|
7777 | return results;
|
7778 | };
|
7779 |
|
7780 |
|
7781 |
|
7782 |
|
7783 |
|
7784 | var EBML_TAGS = {
|
7785 | EBML: toUint8([0x1A, 0x45, 0xDF, 0xA3]),
|
7786 | DocType: toUint8([0x42, 0x82]),
|
7787 | Segment: toUint8([0x18, 0x53, 0x80, 0x67]),
|
7788 | SegmentInfo: toUint8([0x15, 0x49, 0xA9, 0x66]),
|
7789 | Tracks: toUint8([0x16, 0x54, 0xAE, 0x6B]),
|
7790 | Track: toUint8([0xAE]),
|
7791 | TrackNumber: toUint8([0xd7]),
|
7792 | DefaultDuration: toUint8([0x23, 0xe3, 0x83]),
|
7793 | TrackEntry: toUint8([0xAE]),
|
7794 | TrackType: toUint8([0x83]),
|
7795 | FlagDefault: toUint8([0x88]),
|
7796 | CodecID: toUint8([0x86]),
|
7797 | CodecPrivate: toUint8([0x63, 0xA2]),
|
7798 | VideoTrack: toUint8([0xe0]),
|
7799 | AudioTrack: toUint8([0xe1]),
|
7800 |
|
7801 |
|
7802 |
|
7803 | Cluster: toUint8([0x1F, 0x43, 0xB6, 0x75]),
|
7804 | Timestamp: toUint8([0xE7]),
|
7805 | TimestampScale: toUint8([0x2A, 0xD7, 0xB1]),
|
7806 | BlockGroup: toUint8([0xA0]),
|
7807 | BlockDuration: toUint8([0x9B]),
|
7808 | Block: toUint8([0xA1]),
|
7809 | SimpleBlock: toUint8([0xA3])
|
7810 | };
|
7811 | |
7812 |
|
7813 |
|
7814 |
|
7815 |
|
7816 |
|
7817 |
|
7818 |
|
7819 | var LENGTH_TABLE = [128, 64, 32, 16, 8, 4, 2, 1];
|
7820 |
|
7821 | var getLength = function getLength(byte) {
|
7822 | var len = 1;
|
7823 |
|
7824 | for (var i = 0; i < LENGTH_TABLE.length; i++) {
|
7825 | if (byte & LENGTH_TABLE[i]) {
|
7826 | break;
|
7827 | }
|
7828 |
|
7829 | len++;
|
7830 | }
|
7831 |
|
7832 | return len;
|
7833 | };
|
7834 |
|
7835 |
|
7836 |
|
7837 |
|
7838 |
|
7839 |
|
7840 | var getvint = function getvint(bytes, offset, removeLength, signed) {
|
7841 | if (removeLength === void 0) {
|
7842 | removeLength = true;
|
7843 | }
|
7844 |
|
7845 | if (signed === void 0) {
|
7846 | signed = false;
|
7847 | }
|
7848 |
|
7849 | var length = getLength(bytes[offset]);
|
7850 | var valueBytes = bytes.subarray(offset, offset + length);
|
7851 |
|
7852 |
|
7853 |
|
7854 |
|
7855 | if (removeLength) {
|
7856 | valueBytes = Array.prototype.slice.call(bytes, offset, offset + length);
|
7857 | valueBytes[0] ^= LENGTH_TABLE[length - 1];
|
7858 | }
|
7859 |
|
7860 | return {
|
7861 | length: length,
|
7862 | value: bytesToNumber(valueBytes, {
|
7863 | signed: signed
|
7864 | }),
|
7865 | bytes: valueBytes
|
7866 | };
|
7867 | };
|
7868 |
|
7869 | var normalizePath = function normalizePath(path) {
|
7870 | if (typeof path === 'string') {
|
7871 | return path.match(/.{1,2}/g).map(function (p) {
|
7872 | return normalizePath(p);
|
7873 | });
|
7874 | }
|
7875 |
|
7876 | if (typeof path === 'number') {
|
7877 | return numberToBytes(path);
|
7878 | }
|
7879 |
|
7880 | return path;
|
7881 | };
|
7882 |
|
7883 | var normalizePaths = function normalizePaths(paths) {
|
7884 | if (!Array.isArray(paths)) {
|
7885 | return [normalizePath(paths)];
|
7886 | }
|
7887 |
|
7888 | return paths.map(function (p) {
|
7889 | return normalizePath(p);
|
7890 | });
|
7891 | };
|
7892 |
|
7893 | var getInfinityDataSize = function getInfinityDataSize(id, bytes, offset) {
|
7894 | if (offset >= bytes.length) {
|
7895 | return bytes.length;
|
7896 | }
|
7897 |
|
7898 | var innerid = getvint(bytes, offset, false);
|
7899 |
|
7900 | if (bytesMatch(id.bytes, innerid.bytes)) {
|
7901 | return offset;
|
7902 | }
|
7903 |
|
7904 | var dataHeader = getvint(bytes, offset + innerid.length);
|
7905 | return getInfinityDataSize(id, bytes, offset + dataHeader.length + dataHeader.value + innerid.length);
|
7906 | };
|
7907 | |
7908 |
|
7909 |
|
7910 |
|
7911 |
|
7912 |
|
7913 |
|
7914 |
|
7915 |
|
7916 |
|
7917 |
|
7918 |
|
7919 |
|
7920 |
|
7921 |
|
7922 |
|
7923 |
|
7924 |
|
7925 |
|
7926 |
|
7927 |
|
7928 | var findEbml = function findEbml(bytes, paths) {
|
7929 | paths = normalizePaths(paths);
|
7930 | bytes = toUint8(bytes);
|
7931 | var results = [];
|
7932 |
|
7933 | if (!paths.length) {
|
7934 | return results;
|
7935 | }
|
7936 |
|
7937 | var i = 0;
|
7938 |
|
7939 | while (i < bytes.length) {
|
7940 | var id = getvint(bytes, i, false);
|
7941 | var dataHeader = getvint(bytes, i + id.length);
|
7942 | var dataStart = i + id.length + dataHeader.length;
|
7943 |
|
7944 | if (dataHeader.value === 0x7f) {
|
7945 | dataHeader.value = getInfinityDataSize(id, bytes, dataStart);
|
7946 |
|
7947 | if (dataHeader.value !== bytes.length) {
|
7948 | dataHeader.value -= dataStart;
|
7949 | }
|
7950 | }
|
7951 |
|
7952 | var dataEnd = dataStart + dataHeader.value > bytes.length ? bytes.length : dataStart + dataHeader.value;
|
7953 | var data = bytes.subarray(dataStart, dataEnd);
|
7954 |
|
7955 | if (bytesMatch(paths[0], id.bytes)) {
|
7956 | if (paths.length === 1) {
|
7957 |
|
7958 |
|
7959 | results.push(data);
|
7960 | } else {
|
7961 |
|
7962 |
|
7963 | results = results.concat(findEbml(data, paths.slice(1)));
|
7964 | }
|
7965 | }
|
7966 |
|
7967 | var totalLength = id.length + dataHeader.length + data.length;
|
7968 |
|
7969 | i += totalLength;
|
7970 | }
|
7971 |
|
7972 | return results;
|
7973 | };
|
7974 |
|
7975 | var NAL_TYPE_ONE = toUint8([0x00, 0x00, 0x00, 0x01]);
|
7976 | var NAL_TYPE_TWO = toUint8([0x00, 0x00, 0x01]);
|
7977 | var EMULATION_PREVENTION = toUint8([0x00, 0x00, 0x03]);
|
7978 | |
7979 |
|
7980 |
|
7981 |
|
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 |
|
7988 | var discardEmulationPreventionBytes = function discardEmulationPreventionBytes(bytes) {
|
7989 | var positions = [];
|
7990 | var i = 1;
|
7991 |
|
7992 | while (i < bytes.length - 2) {
|
7993 | if (bytesMatch(bytes.subarray(i, i + 3), EMULATION_PREVENTION)) {
|
7994 | positions.push(i + 2);
|
7995 | i++;
|
7996 | }
|
7997 |
|
7998 | i++;
|
7999 | }
|
8000 |
|
8001 |
|
8002 |
|
8003 | if (positions.length === 0) {
|
8004 | return bytes;
|
8005 | }
|
8006 |
|
8007 |
|
8008 | var newLength = bytes.length - positions.length;
|
8009 | var newData = new Uint8Array(newLength);
|
8010 | var sourceIndex = 0;
|
8011 |
|
8012 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
8013 | if (sourceIndex === positions[0]) {
|
8014 |
|
8015 | sourceIndex++;
|
8016 |
|
8017 | positions.shift();
|
8018 | }
|
8019 |
|
8020 | newData[i] = bytes[sourceIndex];
|
8021 | }
|
8022 |
|
8023 | return newData;
|
8024 | };
|
8025 | var findNal = function findNal(bytes, dataType, types, nalLimit) {
|
8026 | if (nalLimit === void 0) {
|
8027 | nalLimit = Infinity;
|
8028 | }
|
8029 |
|
8030 | bytes = toUint8(bytes);
|
8031 | types = [].concat(types);
|
8032 | var i = 0;
|
8033 | var nalStart;
|
8034 | var nalsFound = 0;
|
8035 |
|
8036 |
|
8037 |
|
8038 |
|
8039 |
|
8040 | while (i < bytes.length && (nalsFound < nalLimit || nalStart)) {
|
8041 | var nalOffset = void 0;
|
8042 |
|
8043 | if (bytesMatch(bytes.subarray(i), NAL_TYPE_ONE)) {
|
8044 | nalOffset = 4;
|
8045 | } else if (bytesMatch(bytes.subarray(i), NAL_TYPE_TWO)) {
|
8046 | nalOffset = 3;
|
8047 | }
|
8048 |
|
8049 |
|
8050 |
|
8051 | if (!nalOffset) {
|
8052 | i++;
|
8053 | continue;
|
8054 | }
|
8055 |
|
8056 | nalsFound++;
|
8057 |
|
8058 | if (nalStart) {
|
8059 | return discardEmulationPreventionBytes(bytes.subarray(nalStart, i));
|
8060 | }
|
8061 |
|
8062 | var nalType = void 0;
|
8063 |
|
8064 | if (dataType === 'h264') {
|
8065 | nalType = bytes[i + nalOffset] & 0x1f;
|
8066 | } else if (dataType === 'h265') {
|
8067 | nalType = bytes[i + nalOffset] >> 1 & 0x3f;
|
8068 | }
|
8069 |
|
8070 | if (types.indexOf(nalType) !== -1) {
|
8071 | nalStart = i + nalOffset;
|
8072 | }
|
8073 |
|
8074 |
|
8075 | i += nalOffset + (dataType === 'h264' ? 1 : 2);
|
8076 | }
|
8077 |
|
8078 | return bytes.subarray(0, 0);
|
8079 | };
|
8080 | var findH264Nal = function findH264Nal(bytes, type, nalLimit) {
|
8081 | return findNal(bytes, 'h264', type, nalLimit);
|
8082 | };
|
8083 | var findH265Nal = function findH265Nal(bytes, type, nalLimit) {
|
8084 | return findNal(bytes, 'h265', type, nalLimit);
|
8085 | };
|
8086 |
|
8087 | var CONSTANTS = {
|
8088 |
|
8089 | 'webm': toUint8([0x77, 0x65, 0x62, 0x6d]),
|
8090 |
|
8091 | 'matroska': toUint8([0x6d, 0x61, 0x74, 0x72, 0x6f, 0x73, 0x6b, 0x61]),
|
8092 |
|
8093 | 'flac': toUint8([0x66, 0x4c, 0x61, 0x43]),
|
8094 |
|
8095 | 'ogg': toUint8([0x4f, 0x67, 0x67, 0x53]),
|
8096 |
|
8097 |
|
8098 | 'ac3': toUint8([0x0b, 0x77]),
|
8099 |
|
8100 | 'riff': toUint8([0x52, 0x49, 0x46, 0x46]),
|
8101 |
|
8102 | 'avi': toUint8([0x41, 0x56, 0x49]),
|
8103 |
|
8104 | 'wav': toUint8([0x57, 0x41, 0x56, 0x45]),
|
8105 |
|
8106 | '3gp': toUint8([0x66, 0x74, 0x79, 0x70, 0x33, 0x67]),
|
8107 |
|
8108 | 'mp4': toUint8([0x66, 0x74, 0x79, 0x70]),
|
8109 |
|
8110 | 'fmp4': toUint8([0x73, 0x74, 0x79, 0x70]),
|
8111 |
|
8112 | 'mov': toUint8([0x66, 0x74, 0x79, 0x70, 0x71, 0x74]),
|
8113 |
|
8114 | 'moov': toUint8([0x6D, 0x6F, 0x6F, 0x76]),
|
8115 |
|
8116 | 'moof': toUint8([0x6D, 0x6F, 0x6F, 0x66])
|
8117 | };
|
8118 | var _isLikely = {
|
8119 | aac: function aac(bytes) {
|
8120 | var offset = getId3Offset(bytes);
|
8121 | return bytesMatch(bytes, [0xFF, 0x10], {
|
8122 | offset: offset,
|
8123 | mask: [0xFF, 0x16]
|
8124 | });
|
8125 | },
|
8126 | mp3: function mp3(bytes) {
|
8127 | var offset = getId3Offset(bytes);
|
8128 | return bytesMatch(bytes, [0xFF, 0x02], {
|
8129 | offset: offset,
|
8130 | mask: [0xFF, 0x06]
|
8131 | });
|
8132 | },
|
8133 | webm: function webm(bytes) {
|
8134 | var docType = findEbml(bytes, [EBML_TAGS.EBML, EBML_TAGS.DocType])[0];
|
8135 |
|
8136 | return bytesMatch(docType, CONSTANTS.webm);
|
8137 | },
|
8138 | mkv: function mkv(bytes) {
|
8139 | var docType = findEbml(bytes, [EBML_TAGS.EBML, EBML_TAGS.DocType])[0];
|
8140 |
|
8141 | return bytesMatch(docType, CONSTANTS.matroska);
|
8142 | },
|
8143 | mp4: function mp4(bytes) {
|
8144 |
|
8145 | if (_isLikely['3gp'](bytes) || _isLikely.mov(bytes)) {
|
8146 | return false;
|
8147 | }
|
8148 |
|
8149 |
|
8150 | if (bytesMatch(bytes, CONSTANTS.mp4, {
|
8151 | offset: 4
|
8152 | }) || bytesMatch(bytes, CONSTANTS.fmp4, {
|
8153 | offset: 4
|
8154 | })) {
|
8155 | return true;
|
8156 | }
|
8157 |
|
8158 |
|
8159 | if (bytesMatch(bytes, CONSTANTS.moof, {
|
8160 | offset: 4
|
8161 | }) || bytesMatch(bytes, CONSTANTS.moov, {
|
8162 | offset: 4
|
8163 | })) {
|
8164 | return true;
|
8165 | }
|
8166 | },
|
8167 | mov: function mov(bytes) {
|
8168 | return bytesMatch(bytes, CONSTANTS.mov, {
|
8169 | offset: 4
|
8170 | });
|
8171 | },
|
8172 | '3gp': function gp(bytes) {
|
8173 | return bytesMatch(bytes, CONSTANTS['3gp'], {
|
8174 | offset: 4
|
8175 | });
|
8176 | },
|
8177 | ac3: function ac3(bytes) {
|
8178 | var offset = getId3Offset(bytes);
|
8179 | return bytesMatch(bytes, CONSTANTS.ac3, {
|
8180 | offset: offset
|
8181 | });
|
8182 | },
|
8183 | ts: function ts(bytes) {
|
8184 | if (bytes.length < 189 && bytes.length >= 1) {
|
8185 | return bytes[0] === 0x47;
|
8186 | }
|
8187 |
|
8188 | var i = 0;
|
8189 |
|
8190 | while (i + 188 < bytes.length && i < 188) {
|
8191 | if (bytes[i] === 0x47 && bytes[i + 188] === 0x47) {
|
8192 | return true;
|
8193 | }
|
8194 |
|
8195 | i += 1;
|
8196 | }
|
8197 |
|
8198 | return false;
|
8199 | },
|
8200 | flac: function flac(bytes) {
|
8201 | var offset = getId3Offset(bytes);
|
8202 | return bytesMatch(bytes, CONSTANTS.flac, {
|
8203 | offset: offset
|
8204 | });
|
8205 | },
|
8206 | ogg: function ogg(bytes) {
|
8207 | return bytesMatch(bytes, CONSTANTS.ogg);
|
8208 | },
|
8209 | avi: function avi(bytes) {
|
8210 | return bytesMatch(bytes, CONSTANTS.riff) && bytesMatch(bytes, CONSTANTS.avi, {
|
8211 | offset: 8
|
8212 | });
|
8213 | },
|
8214 | wav: function wav(bytes) {
|
8215 | return bytesMatch(bytes, CONSTANTS.riff) && bytesMatch(bytes, CONSTANTS.wav, {
|
8216 | offset: 8
|
8217 | });
|
8218 | },
|
8219 | 'h264': function h264(bytes) {
|
8220 |
|
8221 | return findH264Nal(bytes, 7, 3).length;
|
8222 | },
|
8223 | 'h265': function h265(bytes) {
|
8224 |
|
8225 | return findH265Nal(bytes, [32, 33], 3).length;
|
8226 | }
|
8227 | };
|
8228 |
|
8229 |
|
8230 |
|
8231 | var isLikelyTypes = Object.keys(_isLikely)
|
8232 | .filter(function (t) {
|
8233 | return t !== 'ts' && t !== 'h264' && t !== 'h265';
|
8234 | })
|
8235 | .concat(['ts', 'h264', 'h265']);
|
8236 |
|
8237 | isLikelyTypes.forEach(function (type) {
|
8238 | var isLikelyFn = _isLikely[type];
|
8239 |
|
8240 | _isLikely[type] = function (bytes) {
|
8241 | return isLikelyFn(toUint8(bytes));
|
8242 | };
|
8243 | });
|
8244 |
|
8245 | var isLikely = _isLikely;
|
8246 |
|
8247 |
|
8248 | var detectContainerForBytes = function detectContainerForBytes(bytes) {
|
8249 | bytes = toUint8(bytes);
|
8250 |
|
8251 | for (var i = 0; i < isLikelyTypes.length; i++) {
|
8252 | var type = isLikelyTypes[i];
|
8253 |
|
8254 | if (isLikely[type](bytes)) {
|
8255 | return type;
|
8256 | }
|
8257 | }
|
8258 |
|
8259 | return '';
|
8260 | };
|
8261 |
|
8262 | var isLikelyFmp4MediaSegment = function isLikelyFmp4MediaSegment(bytes) {
|
8263 | return findBox(bytes, ['moof']).length > 0;
|
8264 | };
|
8265 |
|
8266 |
|
8267 |
|
8268 | var callbackOnCompleted = function callbackOnCompleted(request, cb) {
|
8269 | if (request.readyState === 4) {
|
8270 | return cb();
|
8271 | }
|
8272 |
|
8273 | return;
|
8274 | };
|
8275 |
|
8276 | var containerRequest = function containerRequest(uri, xhr, cb) {
|
8277 | var bytes = [];
|
8278 | var id3Offset;
|
8279 | var finished = false;
|
8280 |
|
8281 | var endRequestAndCallback = function endRequestAndCallback(err, req, type, _bytes) {
|
8282 | req.abort();
|
8283 | finished = true;
|
8284 | return cb(err, req, type, _bytes);
|
8285 | };
|
8286 |
|
8287 | var progressListener = function progressListener(error, request) {
|
8288 | if (finished) {
|
8289 | return;
|
8290 | }
|
8291 |
|
8292 | if (error) {
|
8293 | return endRequestAndCallback(error, request, '', bytes);
|
8294 | }
|
8295 |
|
8296 |
|
8297 | var newPart = request.responseText.substring(bytes && bytes.byteLength || 0, request.responseText.length);
|
8298 |
|
8299 | bytes = concatTypedArrays(bytes, stringToBytes(newPart, true));
|
8300 | id3Offset = id3Offset || getId3Offset(bytes);
|
8301 |
|
8302 |
|
8303 | if (bytes.length < 10 || id3Offset && bytes.length < id3Offset + 2) {
|
8304 | return callbackOnCompleted(request, function () {
|
8305 | return endRequestAndCallback(error, request, '', bytes);
|
8306 | });
|
8307 | }
|
8308 |
|
8309 | var type = detectContainerForBytes(bytes);
|
8310 |
|
8311 |
|
8312 |
|
8313 | if (type === 'ts' && bytes.length < 188) {
|
8314 | return callbackOnCompleted(request, function () {
|
8315 | return endRequestAndCallback(error, request, '', bytes);
|
8316 | });
|
8317 | }
|
8318 |
|
8319 |
|
8320 |
|
8321 | if (!type && bytes.length < 376) {
|
8322 | return callbackOnCompleted(request, function () {
|
8323 | return endRequestAndCallback(error, request, '', bytes);
|
8324 | });
|
8325 | }
|
8326 |
|
8327 | return endRequestAndCallback(null, request, type, bytes);
|
8328 | };
|
8329 |
|
8330 | var options = {
|
8331 | uri: uri,
|
8332 | beforeSend: function beforeSend(request) {
|
8333 |
|
8334 | request.overrideMimeType('text/plain; charset=x-user-defined');
|
8335 | request.addEventListener('progress', function (_ref) {
|
8336 | _ref.total;
|
8337 | _ref.loaded;
|
8338 | return callbackWrapper(request, null, {
|
8339 | statusCode: request.status
|
8340 | }, progressListener);
|
8341 | });
|
8342 | }
|
8343 | };
|
8344 | var request = xhr(options, function (error, response) {
|
8345 | return callbackWrapper(request, error, response, progressListener);
|
8346 | });
|
8347 | return request;
|
8348 | };
|
8349 |
|
8350 | var EventTarget = videojs__default["default"].EventTarget,
|
8351 | mergeOptions = videojs__default["default"].mergeOptions;
|
8352 |
|
8353 | var dashPlaylistUnchanged = function dashPlaylistUnchanged(a, b) {
|
8354 | if (!isPlaylistUnchanged(a, b)) {
|
8355 | return false;
|
8356 | }
|
8357 |
|
8358 |
|
8359 |
|
8360 |
|
8361 |
|
8362 |
|
8363 |
|
8364 | if (a.sidx && b.sidx && (a.sidx.offset !== b.sidx.offset || a.sidx.length !== b.sidx.length)) {
|
8365 | return false;
|
8366 | } else if (!a.sidx && b.sidx || a.sidx && !b.sidx) {
|
8367 | return false;
|
8368 | }
|
8369 |
|
8370 |
|
8371 |
|
8372 | if (a.segments && !b.segments || !a.segments && b.segments) {
|
8373 | return false;
|
8374 | }
|
8375 |
|
8376 |
|
8377 | if (!a.segments && !b.segments) {
|
8378 | return true;
|
8379 | }
|
8380 |
|
8381 |
|
8382 | for (var i = 0; i < a.segments.length; i++) {
|
8383 | var aSegment = a.segments[i];
|
8384 | var bSegment = b.segments[i];
|
8385 |
|
8386 | if (aSegment.uri !== bSegment.uri) {
|
8387 | return false;
|
8388 | }
|
8389 |
|
8390 |
|
8391 | if (!aSegment.byterange && !bSegment.byterange) {
|
8392 | continue;
|
8393 | }
|
8394 |
|
8395 | var aByterange = aSegment.byterange;
|
8396 | var bByterange = bSegment.byterange;
|
8397 |
|
8398 | if (aByterange && !bByterange || !aByterange && bByterange) {
|
8399 | return false;
|
8400 | }
|
8401 |
|
8402 |
|
8403 | if (aByterange.offset !== bByterange.offset || aByterange.length !== bByterange.length) {
|
8404 | return false;
|
8405 | }
|
8406 | }
|
8407 |
|
8408 |
|
8409 | return true;
|
8410 | };
|
8411 | |
8412 |
|
8413 |
|
8414 |
|
8415 |
|
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 |
|
8422 |
|
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 |
|
8429 | var parseMasterXml = function parseMasterXml(_ref) {
|
8430 | var masterXml = _ref.masterXml,
|
8431 | srcUrl = _ref.srcUrl,
|
8432 | clientOffset = _ref.clientOffset,
|
8433 | sidxMapping = _ref.sidxMapping;
|
8434 | var master = parse(masterXml, {
|
8435 | manifestUri: srcUrl,
|
8436 | clientOffset: clientOffset,
|
8437 | sidxMapping: sidxMapping
|
8438 | });
|
8439 | addPropertiesToMaster(master, srcUrl);
|
8440 | return master;
|
8441 | };
|
8442 | |
8443 |
|
8444 |
|
8445 |
|
8446 |
|
8447 |
|
8448 |
|
8449 |
|
8450 |
|
8451 |
|
8452 |
|
8453 |
|
8454 |
|
8455 | var updateMaster = function updateMaster(oldMaster, newMaster, sidxMapping) {
|
8456 | var noChanges = true;
|
8457 | var update = mergeOptions(oldMaster, {
|
8458 |
|
8459 | duration: newMaster.duration,
|
8460 | minimumUpdatePeriod: newMaster.minimumUpdatePeriod
|
8461 | });
|
8462 |
|
8463 | for (var i = 0; i < newMaster.playlists.length; i++) {
|
8464 | var playlist = newMaster.playlists[i];
|
8465 |
|
8466 | if (playlist.sidx) {
|
8467 | var sidxKey = generateSidxKey(playlist.sidx);
|
8468 |
|
8469 | if (sidxMapping && sidxMapping[sidxKey] && sidxMapping[sidxKey].sidx) {
|
8470 | addSidxSegmentsToPlaylist(playlist, sidxMapping[sidxKey].sidx, playlist.sidx.resolvedUri);
|
8471 | }
|
8472 | }
|
8473 |
|
8474 | var playlistUpdate = updateMaster$1(update, playlist, dashPlaylistUnchanged);
|
8475 |
|
8476 | if (playlistUpdate) {
|
8477 | update = playlistUpdate;
|
8478 | noChanges = false;
|
8479 | }
|
8480 | }
|
8481 |
|
8482 |
|
8483 | forEachMediaGroup(newMaster, function (properties, type, group, label) {
|
8484 | if (properties.playlists && properties.playlists.length) {
|
8485 | var id = properties.playlists[0].id;
|
8486 |
|
8487 | var _playlistUpdate = updateMaster$1(update, properties.playlists[0], dashPlaylistUnchanged);
|
8488 |
|
8489 | if (_playlistUpdate) {
|
8490 | update = _playlistUpdate;
|
8491 |
|
8492 | update.mediaGroups[type][group][label].playlists[0] = update.playlists[id];
|
8493 | noChanges = false;
|
8494 | }
|
8495 | }
|
8496 | });
|
8497 |
|
8498 | if (newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
8499 | noChanges = false;
|
8500 | }
|
8501 |
|
8502 | if (noChanges) {
|
8503 | return null;
|
8504 | }
|
8505 |
|
8506 | return update;
|
8507 | };
|
8508 |
|
8509 |
|
8510 |
|
8511 |
|
8512 | var equivalentSidx = function equivalentSidx(a, b) {
|
8513 | var neitherMap = Boolean(!a.map && !b.map);
|
8514 | var equivalentMap = neitherMap || Boolean(a.map && b.map && a.map.byterange.offset === b.map.byterange.offset && a.map.byterange.length === b.map.byterange.length);
|
8515 | return equivalentMap && a.uri === b.uri && a.byterange.offset === b.byterange.offset && a.byterange.length === b.byterange.length;
|
8516 | };
|
8517 |
|
8518 |
|
8519 | var compareSidxEntry = function compareSidxEntry(playlists, oldSidxMapping) {
|
8520 | var newSidxMapping = {};
|
8521 |
|
8522 | for (var id in playlists) {
|
8523 | var playlist = playlists[id];
|
8524 | var currentSidxInfo = playlist.sidx;
|
8525 |
|
8526 | if (currentSidxInfo) {
|
8527 | var key = generateSidxKey(currentSidxInfo);
|
8528 |
|
8529 | if (!oldSidxMapping[key]) {
|
8530 | break;
|
8531 | }
|
8532 |
|
8533 | var savedSidxInfo = oldSidxMapping[key].sidxInfo;
|
8534 |
|
8535 | if (equivalentSidx(savedSidxInfo, currentSidxInfo)) {
|
8536 | newSidxMapping[key] = oldSidxMapping[key];
|
8537 | }
|
8538 | }
|
8539 | }
|
8540 |
|
8541 | return newSidxMapping;
|
8542 | };
|
8543 | |
8544 |
|
8545 |
|
8546 |
|
8547 |
|
8548 |
|
8549 |
|
8550 |
|
8551 |
|
8552 | var filterChangedSidxMappings = function filterChangedSidxMappings(master, oldSidxMapping) {
|
8553 | var videoSidx = compareSidxEntry(master.playlists, oldSidxMapping);
|
8554 | var mediaGroupSidx = videoSidx;
|
8555 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
8556 | if (properties.playlists && properties.playlists.length) {
|
8557 | var playlists = properties.playlists;
|
8558 | mediaGroupSidx = mergeOptions(mediaGroupSidx, compareSidxEntry(playlists, oldSidxMapping));
|
8559 | }
|
8560 | });
|
8561 | return mediaGroupSidx;
|
8562 | };
|
8563 |
|
8564 | var DashPlaylistLoader = function (_EventTarget) {
|
8565 | inheritsLoose(DashPlaylistLoader, _EventTarget);
|
8566 |
|
8567 |
|
8568 |
|
8569 |
|
8570 | function DashPlaylistLoader(srcUrlOrPlaylist, vhs, options, masterPlaylistLoader) {
|
8571 | var _this;
|
8572 |
|
8573 | if (options === void 0) {
|
8574 | options = {};
|
8575 | }
|
8576 |
|
8577 | _this = _EventTarget.call(this) || this;
|
8578 | _this.masterPlaylistLoader_ = masterPlaylistLoader || assertThisInitialized(_this);
|
8579 |
|
8580 | if (!masterPlaylistLoader) {
|
8581 | _this.isMaster_ = true;
|
8582 | }
|
8583 |
|
8584 | var _options = options,
|
8585 | _options$withCredenti = _options.withCredentials,
|
8586 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
8587 | _options$handleManife = _options.handleManifestRedirects,
|
8588 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
8589 | _this.vhs_ = vhs;
|
8590 | _this.withCredentials = withCredentials;
|
8591 | _this.handleManifestRedirects = handleManifestRedirects;
|
8592 |
|
8593 | if (!srcUrlOrPlaylist) {
|
8594 | throw new Error('A non-empty playlist URL or object is required');
|
8595 | }
|
8596 |
|
8597 |
|
8598 | _this.on('minimumUpdatePeriod', function () {
|
8599 | _this.refreshXml_();
|
8600 | });
|
8601 |
|
8602 |
|
8603 | _this.on('mediaupdatetimeout', function () {
|
8604 | _this.refreshMedia_(_this.media().id);
|
8605 | });
|
8606 |
|
8607 | _this.state = 'HAVE_NOTHING';
|
8608 | _this.loadedPlaylists_ = {};
|
8609 | _this.logger_ = logger('DashPlaylistLoader');
|
8610 |
|
8611 |
|
8612 | if (_this.isMaster_) {
|
8613 | _this.masterPlaylistLoader_.srcUrl = srcUrlOrPlaylist;
|
8614 |
|
8615 |
|
8616 | _this.masterPlaylistLoader_.sidxMapping_ = {};
|
8617 | } else {
|
8618 | _this.childPlaylist_ = srcUrlOrPlaylist;
|
8619 | }
|
8620 |
|
8621 | return _this;
|
8622 | }
|
8623 |
|
8624 | var _proto = DashPlaylistLoader.prototype;
|
8625 |
|
8626 | _proto.requestErrored_ = function requestErrored_(err, request, startingState) {
|
8627 |
|
8628 | if (!this.request) {
|
8629 | return true;
|
8630 | }
|
8631 |
|
8632 |
|
8633 | this.request = null;
|
8634 |
|
8635 | if (err) {
|
8636 |
|
8637 |
|
8638 | this.error = typeof err === 'object' && !(err instanceof Error) ? err : {
|
8639 | status: request.status,
|
8640 | message: 'DASH request error at URL: ' + request.uri,
|
8641 | response: request.response,
|
8642 |
|
8643 | code: 2
|
8644 | };
|
8645 |
|
8646 | if (startingState) {
|
8647 | this.state = startingState;
|
8648 | }
|
8649 |
|
8650 | this.trigger('error');
|
8651 | return true;
|
8652 | }
|
8653 | }
|
8654 | |
8655 |
|
8656 |
|
8657 |
|
8658 | ;
|
8659 |
|
8660 | _proto.addSidxSegments_ = function addSidxSegments_(playlist, startingState, cb) {
|
8661 | var _this2 = this;
|
8662 |
|
8663 | var sidxKey = playlist.sidx && generateSidxKey(playlist.sidx);
|
8664 |
|
8665 | if (!playlist.sidx || !sidxKey || this.masterPlaylistLoader_.sidxMapping_[sidxKey]) {
|
8666 |
|
8667 | this.mediaRequest_ = window.setTimeout(function () {
|
8668 | return cb(false);
|
8669 | }, 0);
|
8670 | return;
|
8671 | }
|
8672 |
|
8673 |
|
8674 | var uri = resolveManifestRedirect(this.handleManifestRedirects, playlist.sidx.resolvedUri);
|
8675 |
|
8676 | var fin = function fin(err, request) {
|
8677 | if (_this2.requestErrored_(err, request, startingState)) {
|
8678 | return;
|
8679 | }
|
8680 |
|
8681 | var sidxMapping = _this2.masterPlaylistLoader_.sidxMapping_;
|
8682 | var sidx;
|
8683 |
|
8684 | try {
|
8685 | sidx = parseSidx_1(toUint8(request.response).subarray(8));
|
8686 | } catch (e) {
|
8687 |
|
8688 | _this2.requestErrored_(e, request, startingState);
|
8689 |
|
8690 | return;
|
8691 | }
|
8692 |
|
8693 | sidxMapping[sidxKey] = {
|
8694 | sidxInfo: playlist.sidx,
|
8695 | sidx: sidx
|
8696 | };
|
8697 | addSidxSegmentsToPlaylist(playlist, sidx, playlist.sidx.resolvedUri);
|
8698 | return cb(true);
|
8699 | };
|
8700 |
|
8701 | this.request = containerRequest(uri, this.vhs_.xhr, function (err, request, container, bytes) {
|
8702 | if (err) {
|
8703 | return fin(err, request);
|
8704 | }
|
8705 |
|
8706 | if (!container || container !== 'mp4') {
|
8707 | return fin({
|
8708 | status: request.status,
|
8709 | message: "Unsupported " + (container || 'unknown') + " container type for sidx segment at URL: " + uri,
|
8710 |
|
8711 |
|
8712 | response: '',
|
8713 | playlist: playlist,
|
8714 | internal: true,
|
8715 | blacklistDuration: Infinity,
|
8716 |
|
8717 | code: 2
|
8718 | }, request);
|
8719 | }
|
8720 |
|
8721 |
|
8722 | var _playlist$sidx$bytera = playlist.sidx.byterange,
|
8723 | offset = _playlist$sidx$bytera.offset,
|
8724 | length = _playlist$sidx$bytera.length;
|
8725 |
|
8726 | if (bytes.length >= length + offset) {
|
8727 | return fin(err, {
|
8728 | response: bytes.subarray(offset, offset + length),
|
8729 | status: request.status,
|
8730 | uri: request.uri
|
8731 | });
|
8732 | }
|
8733 |
|
8734 |
|
8735 | _this2.request = _this2.vhs_.xhr({
|
8736 | uri: uri,
|
8737 | responseType: 'arraybuffer',
|
8738 | headers: segmentXhrHeaders({
|
8739 | byterange: playlist.sidx.byterange
|
8740 | })
|
8741 | }, fin);
|
8742 | });
|
8743 | };
|
8744 |
|
8745 | _proto.dispose = function dispose() {
|
8746 | this.trigger('dispose');
|
8747 | this.stopRequest();
|
8748 | this.loadedPlaylists_ = {};
|
8749 | window.clearTimeout(this.minimumUpdatePeriodTimeout_);
|
8750 | window.clearTimeout(this.mediaRequest_);
|
8751 | window.clearTimeout(this.mediaUpdateTimeout);
|
8752 | this.mediaUpdateTimeout = null;
|
8753 | this.mediaRequest_ = null;
|
8754 | this.minimumUpdatePeriodTimeout_ = null;
|
8755 |
|
8756 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
8757 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
8758 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
8759 | }
|
8760 |
|
8761 | this.off();
|
8762 | };
|
8763 |
|
8764 | _proto.hasPendingRequest = function hasPendingRequest() {
|
8765 | return this.request || this.mediaRequest_;
|
8766 | };
|
8767 |
|
8768 | _proto.stopRequest = function stopRequest() {
|
8769 | if (this.request) {
|
8770 | var oldRequest = this.request;
|
8771 | this.request = null;
|
8772 | oldRequest.onreadystatechange = null;
|
8773 | oldRequest.abort();
|
8774 | }
|
8775 | };
|
8776 |
|
8777 | _proto.media = function media(playlist) {
|
8778 | var _this3 = this;
|
8779 |
|
8780 |
|
8781 | if (!playlist) {
|
8782 | return this.media_;
|
8783 | }
|
8784 |
|
8785 |
|
8786 | if (this.state === 'HAVE_NOTHING') {
|
8787 | throw new Error('Cannot switch media playlist from ' + this.state);
|
8788 | }
|
8789 |
|
8790 | var startingState = this.state;
|
8791 |
|
8792 | if (typeof playlist === 'string') {
|
8793 | if (!this.masterPlaylistLoader_.master.playlists[playlist]) {
|
8794 | throw new Error('Unknown playlist URI: ' + playlist);
|
8795 | }
|
8796 |
|
8797 | playlist = this.masterPlaylistLoader_.master.playlists[playlist];
|
8798 | }
|
8799 |
|
8800 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
8801 |
|
8802 | if (mediaChange && this.loadedPlaylists_[playlist.id] && this.loadedPlaylists_[playlist.id].endList) {
|
8803 | this.state = 'HAVE_METADATA';
|
8804 | this.media_ = playlist;
|
8805 |
|
8806 | if (mediaChange) {
|
8807 | this.trigger('mediachanging');
|
8808 | this.trigger('mediachange');
|
8809 | }
|
8810 |
|
8811 | return;
|
8812 | }
|
8813 |
|
8814 |
|
8815 | if (!mediaChange) {
|
8816 | return;
|
8817 | }
|
8818 |
|
8819 |
|
8820 | if (this.media_) {
|
8821 | this.trigger('mediachanging');
|
8822 | }
|
8823 |
|
8824 | this.addSidxSegments_(playlist, startingState, function (sidxChanged) {
|
8825 |
|
8826 | _this3.haveMetadata({
|
8827 | startingState: startingState,
|
8828 | playlist: playlist
|
8829 | });
|
8830 | });
|
8831 | };
|
8832 |
|
8833 | _proto.haveMetadata = function haveMetadata(_ref2) {
|
8834 | var startingState = _ref2.startingState,
|
8835 | playlist = _ref2.playlist;
|
8836 | this.state = 'HAVE_METADATA';
|
8837 | this.loadedPlaylists_[playlist.id] = playlist;
|
8838 | this.mediaRequest_ = null;
|
8839 |
|
8840 | this.refreshMedia_(playlist.id);
|
8841 |
|
8842 |
|
8843 | if (startingState === 'HAVE_MASTER') {
|
8844 | this.trigger('loadedmetadata');
|
8845 | } else {
|
8846 |
|
8847 | this.trigger('mediachange');
|
8848 | }
|
8849 | };
|
8850 |
|
8851 | _proto.pause = function pause() {
|
8852 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
8853 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
8854 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
8855 | }
|
8856 |
|
8857 | this.stopRequest();
|
8858 | window.clearTimeout(this.mediaUpdateTimeout);
|
8859 | this.mediaUpdateTimeout = null;
|
8860 |
|
8861 | if (this.isMaster_) {
|
8862 | window.clearTimeout(this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_);
|
8863 | this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_ = null;
|
8864 | }
|
8865 |
|
8866 | if (this.state === 'HAVE_NOTHING') {
|
8867 |
|
8868 |
|
8869 | this.started = false;
|
8870 | }
|
8871 | };
|
8872 |
|
8873 | _proto.load = function load(isFinalRendition) {
|
8874 | var _this4 = this;
|
8875 |
|
8876 | window.clearTimeout(this.mediaUpdateTimeout);
|
8877 | this.mediaUpdateTimeout = null;
|
8878 | var media = this.media();
|
8879 |
|
8880 | if (isFinalRendition) {
|
8881 | var delay = media ? media.targetDuration / 2 * 1000 : 5 * 1000;
|
8882 | this.mediaUpdateTimeout = window.setTimeout(function () {
|
8883 | return _this4.load();
|
8884 | }, delay);
|
8885 | return;
|
8886 | }
|
8887 |
|
8888 |
|
8889 |
|
8890 | if (!this.started) {
|
8891 | this.start();
|
8892 | return;
|
8893 | }
|
8894 |
|
8895 | if (media && !media.endList) {
|
8896 |
|
8897 |
|
8898 |
|
8899 | if (this.isMaster_ && !this.minimumUpdatePeriodTimeout_) {
|
8900 |
|
8901 | this.trigger('minimumUpdatePeriod');
|
8902 |
|
8903 | this.updateMinimumUpdatePeriodTimeout_();
|
8904 | }
|
8905 |
|
8906 | this.trigger('mediaupdatetimeout');
|
8907 | } else {
|
8908 | this.trigger('loadedplaylist');
|
8909 | }
|
8910 | };
|
8911 |
|
8912 | _proto.start = function start() {
|
8913 | var _this5 = this;
|
8914 |
|
8915 | this.started = true;
|
8916 |
|
8917 |
|
8918 | if (!this.isMaster_) {
|
8919 | this.mediaRequest_ = window.setTimeout(function () {
|
8920 | return _this5.haveMaster_();
|
8921 | }, 0);
|
8922 | return;
|
8923 | }
|
8924 |
|
8925 | this.requestMaster_(function (req, masterChanged) {
|
8926 | _this5.haveMaster_();
|
8927 |
|
8928 | if (!_this5.hasPendingRequest() && !_this5.media_) {
|
8929 | _this5.media(_this5.masterPlaylistLoader_.master.playlists[0]);
|
8930 | }
|
8931 | });
|
8932 | };
|
8933 |
|
8934 | _proto.requestMaster_ = function requestMaster_(cb) {
|
8935 | var _this6 = this;
|
8936 |
|
8937 | this.request = this.vhs_.xhr({
|
8938 | uri: this.masterPlaylistLoader_.srcUrl,
|
8939 | withCredentials: this.withCredentials
|
8940 | }, function (error, req) {
|
8941 | if (_this6.requestErrored_(error, req)) {
|
8942 | if (_this6.state === 'HAVE_NOTHING') {
|
8943 | _this6.started = false;
|
8944 | }
|
8945 |
|
8946 | return;
|
8947 | }
|
8948 |
|
8949 | var masterChanged = req.responseText !== _this6.masterPlaylistLoader_.masterXml_;
|
8950 | _this6.masterPlaylistLoader_.masterXml_ = req.responseText;
|
8951 |
|
8952 | if (req.responseHeaders && req.responseHeaders.date) {
|
8953 | _this6.masterLoaded_ = Date.parse(req.responseHeaders.date);
|
8954 | } else {
|
8955 | _this6.masterLoaded_ = Date.now();
|
8956 | }
|
8957 |
|
8958 | _this6.masterPlaylistLoader_.srcUrl = resolveManifestRedirect(_this6.handleManifestRedirects, _this6.masterPlaylistLoader_.srcUrl, req);
|
8959 |
|
8960 | if (masterChanged) {
|
8961 | _this6.handleMaster_();
|
8962 |
|
8963 | _this6.syncClientServerClock_(function () {
|
8964 | return cb(req, masterChanged);
|
8965 | });
|
8966 |
|
8967 | return;
|
8968 | }
|
8969 |
|
8970 | return cb(req, masterChanged);
|
8971 | });
|
8972 | }
|
8973 | |
8974 |
|
8975 |
|
8976 |
|
8977 |
|
8978 |
|
8979 |
|
8980 | ;
|
8981 |
|
8982 | _proto.syncClientServerClock_ = function syncClientServerClock_(done) {
|
8983 | var _this7 = this;
|
8984 |
|
8985 | var utcTiming = parseUTCTiming(this.masterPlaylistLoader_.masterXml_);
|
8986 |
|
8987 |
|
8988 | if (utcTiming === null) {
|
8989 | this.masterPlaylistLoader_.clientOffset_ = this.masterLoaded_ - Date.now();
|
8990 | return done();
|
8991 | }
|
8992 |
|
8993 | if (utcTiming.method === 'DIRECT') {
|
8994 | this.masterPlaylistLoader_.clientOffset_ = utcTiming.value - Date.now();
|
8995 | return done();
|
8996 | }
|
8997 |
|
8998 | this.request = this.vhs_.xhr({
|
8999 | uri: resolveUrl(this.masterPlaylistLoader_.srcUrl, utcTiming.value),
|
9000 | method: utcTiming.method,
|
9001 | withCredentials: this.withCredentials
|
9002 | }, function (error, req) {
|
9003 |
|
9004 | if (!_this7.request) {
|
9005 | return;
|
9006 | }
|
9007 |
|
9008 | if (error) {
|
9009 |
|
9010 |
|
9011 | _this7.masterPlaylistLoader_.clientOffset_ = _this7.masterLoaded_ - Date.now();
|
9012 | return done();
|
9013 | }
|
9014 |
|
9015 | var serverTime;
|
9016 |
|
9017 | if (utcTiming.method === 'HEAD') {
|
9018 | if (!req.responseHeaders || !req.responseHeaders.date) {
|
9019 |
|
9020 |
|
9021 | serverTime = _this7.masterLoaded_;
|
9022 | } else {
|
9023 | serverTime = Date.parse(req.responseHeaders.date);
|
9024 | }
|
9025 | } else {
|
9026 | serverTime = Date.parse(req.responseText);
|
9027 | }
|
9028 |
|
9029 | _this7.masterPlaylistLoader_.clientOffset_ = serverTime - Date.now();
|
9030 | done();
|
9031 | });
|
9032 | };
|
9033 |
|
9034 | _proto.haveMaster_ = function haveMaster_() {
|
9035 | this.state = 'HAVE_MASTER';
|
9036 |
|
9037 | if (this.isMaster_) {
|
9038 |
|
9039 |
|
9040 |
|
9041 | this.trigger('loadedplaylist');
|
9042 | } else if (!this.media_) {
|
9043 |
|
9044 |
|
9045 | this.media(this.childPlaylist_);
|
9046 | }
|
9047 | };
|
9048 |
|
9049 | _proto.handleMaster_ = function handleMaster_() {
|
9050 |
|
9051 | this.mediaRequest_ = null;
|
9052 | var newMaster = parseMasterXml({
|
9053 | masterXml: this.masterPlaylistLoader_.masterXml_,
|
9054 | srcUrl: this.masterPlaylistLoader_.srcUrl,
|
9055 | clientOffset: this.masterPlaylistLoader_.clientOffset_,
|
9056 | sidxMapping: this.masterPlaylistLoader_.sidxMapping_
|
9057 | });
|
9058 | var oldMaster = this.masterPlaylistLoader_.master;
|
9059 |
|
9060 | if (oldMaster) {
|
9061 | newMaster = updateMaster(oldMaster, newMaster, this.masterPlaylistLoader_.sidxMapping_);
|
9062 | }
|
9063 |
|
9064 |
|
9065 | this.masterPlaylistLoader_.master = newMaster ? newMaster : oldMaster;
|
9066 | var location = this.masterPlaylistLoader_.master.locations && this.masterPlaylistLoader_.master.locations[0];
|
9067 |
|
9068 | if (location && location !== this.masterPlaylistLoader_.srcUrl) {
|
9069 | this.masterPlaylistLoader_.srcUrl = location;
|
9070 | }
|
9071 |
|
9072 | if (!oldMaster || newMaster && newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
9073 | this.updateMinimumUpdatePeriodTimeout_();
|
9074 | }
|
9075 |
|
9076 | return Boolean(newMaster);
|
9077 | };
|
9078 |
|
9079 | _proto.updateMinimumUpdatePeriodTimeout_ = function updateMinimumUpdatePeriodTimeout_() {
|
9080 | var mpl = this.masterPlaylistLoader_;
|
9081 |
|
9082 |
|
9083 | if (mpl.createMupOnMedia_) {
|
9084 | mpl.off('loadedmetadata', mpl.createMupOnMedia_);
|
9085 | mpl.createMupOnMedia_ = null;
|
9086 | }
|
9087 |
|
9088 |
|
9089 | if (mpl.minimumUpdatePeriodTimeout_) {
|
9090 | window.clearTimeout(mpl.minimumUpdatePeriodTimeout_);
|
9091 | mpl.minimumUpdatePeriodTimeout_ = null;
|
9092 | }
|
9093 |
|
9094 | var mup = mpl.master && mpl.master.minimumUpdatePeriod;
|
9095 |
|
9096 |
|
9097 |
|
9098 |
|
9099 | if (mup === 0) {
|
9100 | if (mpl.media()) {
|
9101 | mup = mpl.media().targetDuration * 1000;
|
9102 | } else {
|
9103 | mpl.createMupOnMedia_ = mpl.updateMinimumUpdatePeriodTimeout_;
|
9104 | mpl.one('loadedmetadata', mpl.createMupOnMedia_);
|
9105 | }
|
9106 | }
|
9107 |
|
9108 |
|
9109 |
|
9110 |
|
9111 | if (typeof mup !== 'number' || mup <= 0) {
|
9112 | if (mup < 0) {
|
9113 | this.logger_("found invalid minimumUpdatePeriod of " + mup + ", not setting a timeout");
|
9114 | }
|
9115 |
|
9116 | return;
|
9117 | }
|
9118 |
|
9119 | this.createMUPTimeout_(mup);
|
9120 | };
|
9121 |
|
9122 | _proto.createMUPTimeout_ = function createMUPTimeout_(mup) {
|
9123 | var mpl = this.masterPlaylistLoader_;
|
9124 | mpl.minimumUpdatePeriodTimeout_ = window.setTimeout(function () {
|
9125 | mpl.minimumUpdatePeriodTimeout_ = null;
|
9126 | mpl.trigger('minimumUpdatePeriod');
|
9127 | mpl.createMUPTimeout_(mup);
|
9128 | }, mup);
|
9129 | }
|
9130 | |
9131 |
|
9132 |
|
9133 | ;
|
9134 |
|
9135 | _proto.refreshXml_ = function refreshXml_() {
|
9136 | var _this8 = this;
|
9137 |
|
9138 | this.requestMaster_(function (req, masterChanged) {
|
9139 | if (!masterChanged) {
|
9140 | return;
|
9141 | }
|
9142 |
|
9143 | if (_this8.media_) {
|
9144 | _this8.media_ = _this8.masterPlaylistLoader_.master.playlists[_this8.media_.id];
|
9145 | }
|
9146 |
|
9147 |
|
9148 | _this8.masterPlaylistLoader_.sidxMapping_ = filterChangedSidxMappings(_this8.masterPlaylistLoader_.master, _this8.masterPlaylistLoader_.sidxMapping_);
|
9149 |
|
9150 | _this8.addSidxSegments_(_this8.media(), _this8.state, function (sidxChanged) {
|
9151 |
|
9152 | _this8.refreshMedia_(_this8.media().id);
|
9153 | });
|
9154 | });
|
9155 | }
|
9156 | |
9157 |
|
9158 |
|
9159 |
|
9160 |
|
9161 | ;
|
9162 |
|
9163 | _proto.refreshMedia_ = function refreshMedia_(mediaID) {
|
9164 | var _this9 = this;
|
9165 |
|
9166 | if (!mediaID) {
|
9167 | throw new Error('refreshMedia_ must take a media id');
|
9168 | }
|
9169 |
|
9170 |
|
9171 |
|
9172 |
|
9173 |
|
9174 |
|
9175 | if (this.media_ && this.isMaster_) {
|
9176 | this.handleMaster_();
|
9177 | }
|
9178 |
|
9179 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
9180 | var mediaChanged = !this.media_ || this.media_ !== playlists[mediaID];
|
9181 |
|
9182 | if (mediaChanged) {
|
9183 | this.media_ = playlists[mediaID];
|
9184 | } else {
|
9185 | this.trigger('playlistunchanged');
|
9186 | }
|
9187 |
|
9188 | if (!this.mediaUpdateTimeout) {
|
9189 | var createMediaUpdateTimeout = function createMediaUpdateTimeout() {
|
9190 | if (_this9.media().endList) {
|
9191 | return;
|
9192 | }
|
9193 |
|
9194 | _this9.mediaUpdateTimeout = window.setTimeout(function () {
|
9195 | _this9.trigger('mediaupdatetimeout');
|
9196 |
|
9197 | createMediaUpdateTimeout();
|
9198 | }, refreshDelay(_this9.media(), Boolean(mediaChanged)));
|
9199 | };
|
9200 |
|
9201 | createMediaUpdateTimeout();
|
9202 | }
|
9203 |
|
9204 | this.trigger('loadedplaylist');
|
9205 | };
|
9206 |
|
9207 | return DashPlaylistLoader;
|
9208 | }(EventTarget);
|
9209 |
|
9210 | var Config = {
|
9211 | GOAL_BUFFER_LENGTH: 30,
|
9212 | MAX_GOAL_BUFFER_LENGTH: 60,
|
9213 | BACK_BUFFER_LENGTH: 30,
|
9214 | GOAL_BUFFER_LENGTH_RATE: 1,
|
9215 |
|
9216 | INITIAL_BANDWIDTH: 4194304,
|
9217 |
|
9218 |
|
9219 | BANDWIDTH_VARIANCE: 1.2,
|
9220 |
|
9221 | BUFFER_LOW_WATER_LINE: 0,
|
9222 | MAX_BUFFER_LOW_WATER_LINE: 30,
|
9223 |
|
9224 | EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE: 16,
|
9225 | BUFFER_LOW_WATER_LINE_RATE: 1,
|
9226 |
|
9227 | BUFFER_HIGH_WATER_LINE: 30
|
9228 | };
|
9229 |
|
9230 | var stringToArrayBuffer = function stringToArrayBuffer(string) {
|
9231 | var view = new Uint8Array(new ArrayBuffer(string.length));
|
9232 |
|
9233 | for (var i = 0; i < string.length; i++) {
|
9234 | view[i] = string.charCodeAt(i);
|
9235 | }
|
9236 |
|
9237 | return view.buffer;
|
9238 | };
|
9239 |
|
9240 |
|
9241 |
|
9242 | var browserWorkerPolyFill = function browserWorkerPolyFill(workerObj) {
|
9243 |
|
9244 | workerObj.on = workerObj.addEventListener;
|
9245 | workerObj.off = workerObj.removeEventListener;
|
9246 | return workerObj;
|
9247 | };
|
9248 |
|
9249 | var createObjectURL = function createObjectURL(str) {
|
9250 | try {
|
9251 | return URL.createObjectURL(new Blob([str], {
|
9252 | type: 'application/javascript'
|
9253 | }));
|
9254 | } catch (e) {
|
9255 | var blob = new BlobBuilder();
|
9256 | blob.append(str);
|
9257 | return URL.createObjectURL(blob.getBlob());
|
9258 | }
|
9259 | };
|
9260 |
|
9261 | var factory = function factory(code) {
|
9262 | return function () {
|
9263 | var objectUrl = createObjectURL(code);
|
9264 | var worker = browserWorkerPolyFill(new Worker(objectUrl));
|
9265 | worker.objURL = objectUrl;
|
9266 | var terminate = worker.terminate;
|
9267 | worker.on = worker.addEventListener;
|
9268 | worker.off = worker.removeEventListener;
|
9269 |
|
9270 | worker.terminate = function () {
|
9271 | URL.revokeObjectURL(objectUrl);
|
9272 | return terminate.call(this);
|
9273 | };
|
9274 |
|
9275 | return worker;
|
9276 | };
|
9277 | };
|
9278 | var transform = function transform(code) {
|
9279 | return "var browserWorkerPolyFill = " + browserWorkerPolyFill.toString() + ";\n" + 'browserWorkerPolyFill(self);\n' + code;
|
9280 | };
|
9281 |
|
9282 | var getWorkerString = function getWorkerString(fn) {
|
9283 | return fn.toString().replace(/^function.+?{/, '').slice(0, -1);
|
9284 | };
|
9285 |
|
9286 |
|
9287 | var workerCode$1 = transform(getWorkerString(function () {
|
9288 | |
9289 |
|
9290 |
|
9291 |
|
9292 |
|
9293 |
|
9294 |
|
9295 |
|
9296 |
|
9297 |
|
9298 | var Stream = function Stream() {
|
9299 | this.init = function () {
|
9300 | var listeners = {};
|
9301 | |
9302 |
|
9303 |
|
9304 |
|
9305 |
|
9306 |
|
9307 |
|
9308 | this.on = function (type, listener) {
|
9309 | if (!listeners[type]) {
|
9310 | listeners[type] = [];
|
9311 | }
|
9312 |
|
9313 | listeners[type] = listeners[type].concat(listener);
|
9314 | };
|
9315 | |
9316 |
|
9317 |
|
9318 |
|
9319 |
|
9320 |
|
9321 |
|
9322 |
|
9323 | this.off = function (type, listener) {
|
9324 | var index;
|
9325 |
|
9326 | if (!listeners[type]) {
|
9327 | return false;
|
9328 | }
|
9329 |
|
9330 | index = listeners[type].indexOf(listener);
|
9331 | listeners[type] = listeners[type].slice();
|
9332 | listeners[type].splice(index, 1);
|
9333 | return index > -1;
|
9334 | };
|
9335 | |
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 | this.trigger = function (type) {
|
9343 | var callbacks, i, length, args;
|
9344 | callbacks = listeners[type];
|
9345 |
|
9346 | if (!callbacks) {
|
9347 | return;
|
9348 | }
|
9349 |
|
9350 |
|
9351 |
|
9352 |
|
9353 |
|
9354 | if (arguments.length === 2) {
|
9355 | length = callbacks.length;
|
9356 |
|
9357 | for (i = 0; i < length; ++i) {
|
9358 | callbacks[i].call(this, arguments[1]);
|
9359 | }
|
9360 | } else {
|
9361 | args = [];
|
9362 | i = arguments.length;
|
9363 |
|
9364 | for (i = 1; i < arguments.length; ++i) {
|
9365 | args.push(arguments[i]);
|
9366 | }
|
9367 |
|
9368 | length = callbacks.length;
|
9369 |
|
9370 | for (i = 0; i < length; ++i) {
|
9371 | callbacks[i].apply(this, args);
|
9372 | }
|
9373 | }
|
9374 | };
|
9375 | |
9376 |
|
9377 |
|
9378 |
|
9379 |
|
9380 | this.dispose = function () {
|
9381 | listeners = {};
|
9382 | };
|
9383 | };
|
9384 | };
|
9385 | |
9386 |
|
9387 |
|
9388 |
|
9389 |
|
9390 |
|
9391 |
|
9392 |
|
9393 |
|
9394 |
|
9395 |
|
9396 | Stream.prototype.pipe = function (destination) {
|
9397 | this.on('data', function (data) {
|
9398 | destination.push(data);
|
9399 | });
|
9400 | this.on('done', function (flushSource) {
|
9401 | destination.flush(flushSource);
|
9402 | });
|
9403 | this.on('partialdone', function (flushSource) {
|
9404 | destination.partialFlush(flushSource);
|
9405 | });
|
9406 | this.on('endedtimeline', function (flushSource) {
|
9407 | destination.endTimeline(flushSource);
|
9408 | });
|
9409 | this.on('reset', function (flushSource) {
|
9410 | destination.reset(flushSource);
|
9411 | });
|
9412 | return destination;
|
9413 | };
|
9414 |
|
9415 |
|
9416 |
|
9417 |
|
9418 |
|
9419 | Stream.prototype.push = function (data) {
|
9420 | this.trigger('data', data);
|
9421 | };
|
9422 |
|
9423 | Stream.prototype.flush = function (flushSource) {
|
9424 | this.trigger('done', flushSource);
|
9425 | };
|
9426 |
|
9427 | Stream.prototype.partialFlush = function (flushSource) {
|
9428 | this.trigger('partialdone', flushSource);
|
9429 | };
|
9430 |
|
9431 | Stream.prototype.endTimeline = function (flushSource) {
|
9432 | this.trigger('endedtimeline', flushSource);
|
9433 | };
|
9434 |
|
9435 | Stream.prototype.reset = function (flushSource) {
|
9436 | this.trigger('reset', flushSource);
|
9437 | };
|
9438 |
|
9439 | var stream = Stream;
|
9440 | |
9441 |
|
9442 |
|
9443 |
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 | var UINT32_MAX = Math.pow(2, 32) - 1;
|
9451 | var box, dinf, esds, ftyp, mdat, mfhd, minf, moof, moov, mvex, mvhd, trak, tkhd, mdia, mdhd, hdlr, sdtp, stbl, stsd, traf, trex, trun$1, types, MAJOR_BRAND, MINOR_VERSION, AVC1_BRAND, VIDEO_HDLR, AUDIO_HDLR, HDLR_TYPES, VMHD, SMHD, DREF, STCO, STSC, STSZ, STTS;
|
9452 |
|
9453 | (function () {
|
9454 | var i;
|
9455 | types = {
|
9456 | avc1: [],
|
9457 |
|
9458 | avcC: [],
|
9459 | btrt: [],
|
9460 | dinf: [],
|
9461 | dref: [],
|
9462 | esds: [],
|
9463 | ftyp: [],
|
9464 | hdlr: [],
|
9465 | mdat: [],
|
9466 | mdhd: [],
|
9467 | mdia: [],
|
9468 | mfhd: [],
|
9469 | minf: [],
|
9470 | moof: [],
|
9471 | moov: [],
|
9472 | mp4a: [],
|
9473 |
|
9474 | mvex: [],
|
9475 | mvhd: [],
|
9476 | pasp: [],
|
9477 | sdtp: [],
|
9478 | smhd: [],
|
9479 | stbl: [],
|
9480 | stco: [],
|
9481 | stsc: [],
|
9482 | stsd: [],
|
9483 | stsz: [],
|
9484 | stts: [],
|
9485 | styp: [],
|
9486 | tfdt: [],
|
9487 | tfhd: [],
|
9488 | traf: [],
|
9489 | trak: [],
|
9490 | trun: [],
|
9491 | trex: [],
|
9492 | tkhd: [],
|
9493 | vmhd: []
|
9494 | };
|
9495 |
|
9496 |
|
9497 | if (typeof Uint8Array === 'undefined') {
|
9498 | return;
|
9499 | }
|
9500 |
|
9501 | for (i in types) {
|
9502 | if (types.hasOwnProperty(i)) {
|
9503 | types[i] = [i.charCodeAt(0), i.charCodeAt(1), i.charCodeAt(2), i.charCodeAt(3)];
|
9504 | }
|
9505 | }
|
9506 |
|
9507 | MAJOR_BRAND = new Uint8Array(['i'.charCodeAt(0), 's'.charCodeAt(0), 'o'.charCodeAt(0), 'm'.charCodeAt(0)]);
|
9508 | AVC1_BRAND = new Uint8Array(['a'.charCodeAt(0), 'v'.charCodeAt(0), 'c'.charCodeAt(0), '1'.charCodeAt(0)]);
|
9509 | MINOR_VERSION = new Uint8Array([0, 0, 0, 1]);
|
9510 | VIDEO_HDLR = new Uint8Array([0x00,
|
9511 | 0x00, 0x00, 0x00,
|
9512 | 0x00, 0x00, 0x00, 0x00,
|
9513 | 0x76, 0x69, 0x64, 0x65,
|
9514 | 0x00, 0x00, 0x00, 0x00,
|
9515 | 0x00, 0x00, 0x00, 0x00,
|
9516 | 0x00, 0x00, 0x00, 0x00,
|
9517 | 0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
9518 | ]);
|
9519 | AUDIO_HDLR = new Uint8Array([0x00,
|
9520 | 0x00, 0x00, 0x00,
|
9521 | 0x00, 0x00, 0x00, 0x00,
|
9522 | 0x73, 0x6f, 0x75, 0x6e,
|
9523 | 0x00, 0x00, 0x00, 0x00,
|
9524 | 0x00, 0x00, 0x00, 0x00,
|
9525 | 0x00, 0x00, 0x00, 0x00,
|
9526 | 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
9527 | ]);
|
9528 | HDLR_TYPES = {
|
9529 | video: VIDEO_HDLR,
|
9530 | audio: AUDIO_HDLR
|
9531 | };
|
9532 | DREF = new Uint8Array([0x00,
|
9533 | 0x00, 0x00, 0x00,
|
9534 | 0x00, 0x00, 0x00, 0x01,
|
9535 | 0x00, 0x00, 0x00, 0x0c,
|
9536 | 0x75, 0x72, 0x6c, 0x20,
|
9537 | 0x00,
|
9538 | 0x00, 0x00, 0x01
|
9539 | ]);
|
9540 | SMHD = new Uint8Array([0x00,
|
9541 | 0x00, 0x00, 0x00,
|
9542 | 0x00, 0x00,
|
9543 | 0x00, 0x00
|
9544 | ]);
|
9545 | STCO = new Uint8Array([0x00,
|
9546 | 0x00, 0x00, 0x00,
|
9547 | 0x00, 0x00, 0x00, 0x00
|
9548 | ]);
|
9549 | STSC = STCO;
|
9550 | STSZ = new Uint8Array([0x00,
|
9551 | 0x00, 0x00, 0x00,
|
9552 | 0x00, 0x00, 0x00, 0x00,
|
9553 | 0x00, 0x00, 0x00, 0x00
|
9554 | ]);
|
9555 | STTS = STCO;
|
9556 | VMHD = new Uint8Array([0x00,
|
9557 | 0x00, 0x00, 0x01,
|
9558 | 0x00, 0x00,
|
9559 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
9560 | ]);
|
9561 | })();
|
9562 |
|
9563 | box = function box(type) {
|
9564 | var payload = [],
|
9565 | size = 0,
|
9566 | i,
|
9567 | result,
|
9568 | view;
|
9569 |
|
9570 | for (i = 1; i < arguments.length; i++) {
|
9571 | payload.push(arguments[i]);
|
9572 | }
|
9573 |
|
9574 | i = payload.length;
|
9575 |
|
9576 | while (i--) {
|
9577 | size += payload[i].byteLength;
|
9578 | }
|
9579 |
|
9580 | result = new Uint8Array(size + 8);
|
9581 | view = new DataView(result.buffer, result.byteOffset, result.byteLength);
|
9582 | view.setUint32(0, result.byteLength);
|
9583 | result.set(type, 4);
|
9584 |
|
9585 | for (i = 0, size = 8; i < payload.length; i++) {
|
9586 | result.set(payload[i], size);
|
9587 | size += payload[i].byteLength;
|
9588 | }
|
9589 |
|
9590 | return result;
|
9591 | };
|
9592 |
|
9593 | dinf = function dinf() {
|
9594 | return box(types.dinf, box(types.dref, DREF));
|
9595 | };
|
9596 |
|
9597 | esds = function esds(track) {
|
9598 | return box(types.esds, new Uint8Array([0x00,
|
9599 | 0x00, 0x00, 0x00,
|
9600 |
|
9601 | 0x03,
|
9602 | 0x19,
|
9603 | 0x00, 0x00,
|
9604 | 0x00,
|
9605 |
|
9606 | 0x04,
|
9607 | 0x11,
|
9608 | 0x40,
|
9609 | 0x15,
|
9610 | 0x00, 0x06, 0x00,
|
9611 | 0x00, 0x00, 0xda, 0xc0,
|
9612 | 0x00, 0x00, 0xda, 0xc0,
|
9613 |
|
9614 | 0x05,
|
9615 | 0x02,
|
9616 |
|
9617 |
|
9618 | track.audioobjecttype << 3 | track.samplingfrequencyindex >>> 1, track.samplingfrequencyindex << 7 | track.channelcount << 3, 0x06, 0x01, 0x02
|
9619 | ]));
|
9620 | };
|
9621 |
|
9622 | ftyp = function ftyp() {
|
9623 | return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND, AVC1_BRAND);
|
9624 | };
|
9625 |
|
9626 | hdlr = function hdlr(type) {
|
9627 | return box(types.hdlr, HDLR_TYPES[type]);
|
9628 | };
|
9629 |
|
9630 | mdat = function mdat(data) {
|
9631 | return box(types.mdat, data);
|
9632 | };
|
9633 |
|
9634 | mdhd = function mdhd(track) {
|
9635 | var result = new Uint8Array([0x00,
|
9636 | 0x00, 0x00, 0x00,
|
9637 | 0x00, 0x00, 0x00, 0x02,
|
9638 | 0x00, 0x00, 0x00, 0x03,
|
9639 | 0x00, 0x01, 0x5f, 0x90,
|
9640 | track.duration >>> 24 & 0xFF, track.duration >>> 16 & 0xFF, track.duration >>> 8 & 0xFF, track.duration & 0xFF,
|
9641 | 0x55, 0xc4,
|
9642 | 0x00, 0x00]);
|
9643 |
|
9644 |
|
9645 |
|
9646 | if (track.samplerate) {
|
9647 | result[12] = track.samplerate >>> 24 & 0xFF;
|
9648 | result[13] = track.samplerate >>> 16 & 0xFF;
|
9649 | result[14] = track.samplerate >>> 8 & 0xFF;
|
9650 | result[15] = track.samplerate & 0xFF;
|
9651 | }
|
9652 |
|
9653 | return box(types.mdhd, result);
|
9654 | };
|
9655 |
|
9656 | mdia = function mdia(track) {
|
9657 | return box(types.mdia, mdhd(track), hdlr(track.type), minf(track));
|
9658 | };
|
9659 |
|
9660 | mfhd = function mfhd(sequenceNumber) {
|
9661 | return box(types.mfhd, new Uint8Array([0x00, 0x00, 0x00, 0x00,
|
9662 | (sequenceNumber & 0xFF000000) >> 24, (sequenceNumber & 0xFF0000) >> 16, (sequenceNumber & 0xFF00) >> 8, sequenceNumber & 0xFF
|
9663 | ]));
|
9664 | };
|
9665 |
|
9666 | minf = function minf(track) {
|
9667 | return box(types.minf, track.type === 'video' ? box(types.vmhd, VMHD) : box(types.smhd, SMHD), dinf(), stbl(track));
|
9668 | };
|
9669 |
|
9670 | moof = function moof(sequenceNumber, tracks) {
|
9671 | var trackFragments = [],
|
9672 | i = tracks.length;
|
9673 |
|
9674 | while (i--) {
|
9675 | trackFragments[i] = traf(tracks[i]);
|
9676 | }
|
9677 |
|
9678 | return box.apply(null, [types.moof, mfhd(sequenceNumber)].concat(trackFragments));
|
9679 | };
|
9680 | |
9681 |
|
9682 |
|
9683 |
|
9684 |
|
9685 |
|
9686 |
|
9687 | moov = function moov(tracks) {
|
9688 | var i = tracks.length,
|
9689 | boxes = [];
|
9690 |
|
9691 | while (i--) {
|
9692 | boxes[i] = trak(tracks[i]);
|
9693 | }
|
9694 |
|
9695 | return box.apply(null, [types.moov, mvhd(0xffffffff)].concat(boxes).concat(mvex(tracks)));
|
9696 | };
|
9697 |
|
9698 | mvex = function mvex(tracks) {
|
9699 | var i = tracks.length,
|
9700 | boxes = [];
|
9701 |
|
9702 | while (i--) {
|
9703 | boxes[i] = trex(tracks[i]);
|
9704 | }
|
9705 |
|
9706 | return box.apply(null, [types.mvex].concat(boxes));
|
9707 | };
|
9708 |
|
9709 | mvhd = function mvhd(duration) {
|
9710 | var bytes = new Uint8Array([0x00,
|
9711 | 0x00, 0x00, 0x00,
|
9712 | 0x00, 0x00, 0x00, 0x01,
|
9713 | 0x00, 0x00, 0x00, 0x02,
|
9714 | 0x00, 0x01, 0x5f, 0x90,
|
9715 | (duration & 0xFF000000) >> 24, (duration & 0xFF0000) >> 16, (duration & 0xFF00) >> 8, duration & 0xFF,
|
9716 | 0x00, 0x01, 0x00, 0x00,
|
9717 | 0x01, 0x00,
|
9718 | 0x00, 0x00,
|
9719 | 0x00, 0x00, 0x00, 0x00,
|
9720 | 0x00, 0x00, 0x00, 0x00,
|
9721 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
9722 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
9723 | 0xff, 0xff, 0xff, 0xff
|
9724 | ]);
|
9725 | return box(types.mvhd, bytes);
|
9726 | };
|
9727 |
|
9728 | sdtp = function sdtp(track) {
|
9729 | var samples = track.samples || [],
|
9730 | bytes = new Uint8Array(4 + samples.length),
|
9731 | flags,
|
9732 | i;
|
9733 |
|
9734 |
|
9735 | for (i = 0; i < samples.length; i++) {
|
9736 | flags = samples[i].flags;
|
9737 | bytes[i + 4] = flags.dependsOn << 4 | flags.isDependedOn << 2 | flags.hasRedundancy;
|
9738 | }
|
9739 |
|
9740 | return box(types.sdtp, bytes);
|
9741 | };
|
9742 |
|
9743 | stbl = function stbl(track) {
|
9744 | return box(types.stbl, stsd(track), box(types.stts, STTS), box(types.stsc, STSC), box(types.stsz, STSZ), box(types.stco, STCO));
|
9745 | };
|
9746 |
|
9747 | (function () {
|
9748 | var videoSample, audioSample;
|
9749 |
|
9750 | stsd = function stsd(track) {
|
9751 | return box(types.stsd, new Uint8Array([0x00,
|
9752 | 0x00, 0x00, 0x00,
|
9753 | 0x00, 0x00, 0x00, 0x01]), track.type === 'video' ? videoSample(track) : audioSample(track));
|
9754 | };
|
9755 |
|
9756 | videoSample = function videoSample(track) {
|
9757 | var sps = track.sps || [],
|
9758 | pps = track.pps || [],
|
9759 | sequenceParameterSets = [],
|
9760 | pictureParameterSets = [],
|
9761 | i,
|
9762 | avc1Box;
|
9763 |
|
9764 | for (i = 0; i < sps.length; i++) {
|
9765 | sequenceParameterSets.push((sps[i].byteLength & 0xFF00) >>> 8);
|
9766 | sequenceParameterSets.push(sps[i].byteLength & 0xFF);
|
9767 |
|
9768 | sequenceParameterSets = sequenceParameterSets.concat(Array.prototype.slice.call(sps[i]));
|
9769 | }
|
9770 |
|
9771 |
|
9772 | for (i = 0; i < pps.length; i++) {
|
9773 | pictureParameterSets.push((pps[i].byteLength & 0xFF00) >>> 8);
|
9774 | pictureParameterSets.push(pps[i].byteLength & 0xFF);
|
9775 | pictureParameterSets = pictureParameterSets.concat(Array.prototype.slice.call(pps[i]));
|
9776 | }
|
9777 |
|
9778 | avc1Box = [types.avc1, new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
9779 | 0x00, 0x01,
|
9780 | 0x00, 0x00,
|
9781 | 0x00, 0x00,
|
9782 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
9783 | (track.width & 0xff00) >> 8, track.width & 0xff,
|
9784 | (track.height & 0xff00) >> 8, track.height & 0xff,
|
9785 | 0x00, 0x48, 0x00, 0x00,
|
9786 | 0x00, 0x48, 0x00, 0x00,
|
9787 | 0x00, 0x00, 0x00, 0x00,
|
9788 | 0x00, 0x01,
|
9789 | 0x13, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x6a, 0x73, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x2d, 0x68, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
9790 | 0x00, 0x18,
|
9791 | 0x11, 0x11
|
9792 | ]), box(types.avcC, new Uint8Array([0x01,
|
9793 | track.profileIdc,
|
9794 | track.profileCompatibility,
|
9795 | track.levelIdc,
|
9796 | 0xff
|
9797 | ].concat([sps.length],
|
9798 | sequenceParameterSets,
|
9799 | [pps.length],
|
9800 | pictureParameterSets
|
9801 | ))), box(types.btrt, new Uint8Array([0x00, 0x1c, 0x9c, 0x80,
|
9802 | 0x00, 0x2d, 0xc6, 0xc0,
|
9803 | 0x00, 0x2d, 0xc6, 0xc0
|
9804 | ]))];
|
9805 |
|
9806 | if (track.sarRatio) {
|
9807 | var hSpacing = track.sarRatio[0],
|
9808 | vSpacing = track.sarRatio[1];
|
9809 | avc1Box.push(box(types.pasp, new Uint8Array([(hSpacing & 0xFF000000) >> 24, (hSpacing & 0xFF0000) >> 16, (hSpacing & 0xFF00) >> 8, hSpacing & 0xFF, (vSpacing & 0xFF000000) >> 24, (vSpacing & 0xFF0000) >> 16, (vSpacing & 0xFF00) >> 8, vSpacing & 0xFF])));
|
9810 | }
|
9811 |
|
9812 | return box.apply(null, avc1Box);
|
9813 | };
|
9814 |
|
9815 | audioSample = function audioSample(track) {
|
9816 | return box(types.mp4a, new Uint8Array([
|
9817 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
9818 | 0x00, 0x01,
|
9819 |
|
9820 | 0x00, 0x00, 0x00, 0x00,
|
9821 | 0x00, 0x00, 0x00, 0x00,
|
9822 | (track.channelcount & 0xff00) >> 8, track.channelcount & 0xff,
|
9823 | (track.samplesize & 0xff00) >> 8, track.samplesize & 0xff,
|
9824 | 0x00, 0x00,
|
9825 | 0x00, 0x00,
|
9826 | (track.samplerate & 0xff00) >> 8, track.samplerate & 0xff, 0x00, 0x00
|
9827 |
|
9828 | ]), esds(track));
|
9829 | };
|
9830 | })();
|
9831 |
|
9832 | tkhd = function tkhd(track) {
|
9833 | var result = new Uint8Array([0x00,
|
9834 | 0x00, 0x00, 0x07,
|
9835 | 0x00, 0x00, 0x00, 0x00,
|
9836 | 0x00, 0x00, 0x00, 0x00,
|
9837 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
9838 | 0x00, 0x00, 0x00, 0x00,
|
9839 | (track.duration & 0xFF000000) >> 24, (track.duration & 0xFF0000) >> 16, (track.duration & 0xFF00) >> 8, track.duration & 0xFF,
|
9840 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
9841 | 0x00, 0x00,
|
9842 | 0x00, 0x00,
|
9843 | 0x01, 0x00,
|
9844 | 0x00, 0x00,
|
9845 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
9846 | (track.width & 0xFF00) >> 8, track.width & 0xFF, 0x00, 0x00,
|
9847 | (track.height & 0xFF00) >> 8, track.height & 0xFF, 0x00, 0x00
|
9848 | ]);
|
9849 | return box(types.tkhd, result);
|
9850 | };
|
9851 | |
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 | traf = function traf(track) {
|
9858 | var trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable, dataOffset, upperWordBaseMediaDecodeTime, lowerWordBaseMediaDecodeTime;
|
9859 | trackFragmentHeader = box(types.tfhd, new Uint8Array([0x00,
|
9860 | 0x00, 0x00, 0x3a,
|
9861 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
9862 | 0x00, 0x00, 0x00, 0x01,
|
9863 | 0x00, 0x00, 0x00, 0x00,
|
9864 | 0x00, 0x00, 0x00, 0x00,
|
9865 | 0x00, 0x00, 0x00, 0x00
|
9866 | ]));
|
9867 | upperWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime / (UINT32_MAX + 1));
|
9868 | lowerWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime % (UINT32_MAX + 1));
|
9869 | trackFragmentDecodeTime = box(types.tfdt, new Uint8Array([0x01,
|
9870 | 0x00, 0x00, 0x00,
|
9871 |
|
9872 | upperWordBaseMediaDecodeTime >>> 24 & 0xFF, upperWordBaseMediaDecodeTime >>> 16 & 0xFF, upperWordBaseMediaDecodeTime >>> 8 & 0xFF, upperWordBaseMediaDecodeTime & 0xFF, lowerWordBaseMediaDecodeTime >>> 24 & 0xFF, lowerWordBaseMediaDecodeTime >>> 16 & 0xFF, lowerWordBaseMediaDecodeTime >>> 8 & 0xFF, lowerWordBaseMediaDecodeTime & 0xFF]));
|
9873 |
|
9874 |
|
9875 |
|
9876 | dataOffset = 32 +
|
9877 | 20 +
|
9878 | 8 +
|
9879 | 16 +
|
9880 | 8 +
|
9881 | 8;
|
9882 |
|
9883 |
|
9884 | if (track.type === 'audio') {
|
9885 | trackFragmentRun = trun$1(track, dataOffset);
|
9886 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun);
|
9887 | }
|
9888 |
|
9889 |
|
9890 |
|
9891 |
|
9892 | sampleDependencyTable = sdtp(track);
|
9893 | trackFragmentRun = trun$1(track, sampleDependencyTable.length + dataOffset);
|
9894 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable);
|
9895 | };
|
9896 | |
9897 |
|
9898 |
|
9899 |
|
9900 |
|
9901 |
|
9902 |
|
9903 | trak = function trak(track) {
|
9904 | track.duration = track.duration || 0xffffffff;
|
9905 | return box(types.trak, tkhd(track), mdia(track));
|
9906 | };
|
9907 |
|
9908 | trex = function trex(track) {
|
9909 | var result = new Uint8Array([0x00,
|
9910 | 0x00, 0x00, 0x00,
|
9911 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
9912 | 0x00, 0x00, 0x00, 0x01,
|
9913 | 0x00, 0x00, 0x00, 0x00,
|
9914 | 0x00, 0x00, 0x00, 0x00,
|
9915 | 0x00, 0x01, 0x00, 0x01
|
9916 | ]);
|
9917 |
|
9918 |
|
9919 |
|
9920 |
|
9921 | if (track.type !== 'video') {
|
9922 | result[result.length - 1] = 0x00;
|
9923 | }
|
9924 |
|
9925 | return box(types.trex, result);
|
9926 | };
|
9927 |
|
9928 | (function () {
|
9929 | var audioTrun, videoTrun, trunHeader;
|
9930 |
|
9931 |
|
9932 |
|
9933 |
|
9934 | trunHeader = function trunHeader(samples, offset) {
|
9935 | var durationPresent = 0,
|
9936 | sizePresent = 0,
|
9937 | flagsPresent = 0,
|
9938 | compositionTimeOffset = 0;
|
9939 |
|
9940 | if (samples.length) {
|
9941 | if (samples[0].duration !== undefined) {
|
9942 | durationPresent = 0x1;
|
9943 | }
|
9944 |
|
9945 | if (samples[0].size !== undefined) {
|
9946 | sizePresent = 0x2;
|
9947 | }
|
9948 |
|
9949 | if (samples[0].flags !== undefined) {
|
9950 | flagsPresent = 0x4;
|
9951 | }
|
9952 |
|
9953 | if (samples[0].compositionTimeOffset !== undefined) {
|
9954 | compositionTimeOffset = 0x8;
|
9955 | }
|
9956 | }
|
9957 |
|
9958 | return [0x00,
|
9959 | 0x00, durationPresent | sizePresent | flagsPresent | compositionTimeOffset, 0x01,
|
9960 | (samples.length & 0xFF000000) >>> 24, (samples.length & 0xFF0000) >>> 16, (samples.length & 0xFF00) >>> 8, samples.length & 0xFF,
|
9961 | (offset & 0xFF000000) >>> 24, (offset & 0xFF0000) >>> 16, (offset & 0xFF00) >>> 8, offset & 0xFF
|
9962 | ];
|
9963 | };
|
9964 |
|
9965 | videoTrun = function videoTrun(track, offset) {
|
9966 | var bytesOffest, bytes, header, samples, sample, i;
|
9967 | samples = track.samples || [];
|
9968 | offset += 8 + 12 + 16 * samples.length;
|
9969 | header = trunHeader(samples, offset);
|
9970 | bytes = new Uint8Array(header.length + samples.length * 16);
|
9971 | bytes.set(header);
|
9972 | bytesOffest = header.length;
|
9973 |
|
9974 | for (i = 0; i < samples.length; i++) {
|
9975 | sample = samples[i];
|
9976 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
9977 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
9978 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
9979 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
9980 |
|
9981 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
9982 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
9983 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
9984 | bytes[bytesOffest++] = sample.size & 0xFF;
|
9985 |
|
9986 | bytes[bytesOffest++] = sample.flags.isLeading << 2 | sample.flags.dependsOn;
|
9987 | bytes[bytesOffest++] = sample.flags.isDependedOn << 6 | sample.flags.hasRedundancy << 4 | sample.flags.paddingValue << 1 | sample.flags.isNonSyncSample;
|
9988 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0xF0 << 8;
|
9989 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0x0F;
|
9990 |
|
9991 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF000000) >>> 24;
|
9992 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF0000) >>> 16;
|
9993 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF00) >>> 8;
|
9994 | bytes[bytesOffest++] = sample.compositionTimeOffset & 0xFF;
|
9995 | }
|
9996 |
|
9997 | return box(types.trun, bytes);
|
9998 | };
|
9999 |
|
10000 | audioTrun = function audioTrun(track, offset) {
|
10001 | var bytes, bytesOffest, header, samples, sample, i;
|
10002 | samples = track.samples || [];
|
10003 | offset += 8 + 12 + 8 * samples.length;
|
10004 | header = trunHeader(samples, offset);
|
10005 | bytes = new Uint8Array(header.length + samples.length * 8);
|
10006 | bytes.set(header);
|
10007 | bytesOffest = header.length;
|
10008 |
|
10009 | for (i = 0; i < samples.length; i++) {
|
10010 | sample = samples[i];
|
10011 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
10012 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
10013 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
10014 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
10015 |
|
10016 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
10017 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
10018 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
10019 | bytes[bytesOffest++] = sample.size & 0xFF;
|
10020 | }
|
10021 |
|
10022 | return box(types.trun, bytes);
|
10023 | };
|
10024 |
|
10025 | trun$1 = function trun(track, offset) {
|
10026 | if (track.type === 'audio') {
|
10027 | return audioTrun(track, offset);
|
10028 | }
|
10029 |
|
10030 | return videoTrun(track, offset);
|
10031 | };
|
10032 | })();
|
10033 |
|
10034 | var mp4Generator = {
|
10035 | ftyp: ftyp,
|
10036 | mdat: mdat,
|
10037 | moof: moof,
|
10038 | moov: moov,
|
10039 | initSegment: function initSegment(tracks) {
|
10040 | var fileType = ftyp(),
|
10041 | movie = moov(tracks),
|
10042 | result;
|
10043 | result = new Uint8Array(fileType.byteLength + movie.byteLength);
|
10044 | result.set(fileType);
|
10045 | result.set(movie, fileType.byteLength);
|
10046 | return result;
|
10047 | }
|
10048 | };
|
10049 | |
10050 |
|
10051 |
|
10052 |
|
10053 |
|
10054 |
|
10055 |
|
10056 |
|
10057 |
|
10058 |
|
10059 |
|
10060 | var groupNalsIntoFrames = function groupNalsIntoFrames(nalUnits) {
|
10061 | var i,
|
10062 | currentNal,
|
10063 | currentFrame = [],
|
10064 | frames = [];
|
10065 |
|
10066 | frames.byteLength = 0;
|
10067 | frames.nalCount = 0;
|
10068 | frames.duration = 0;
|
10069 | currentFrame.byteLength = 0;
|
10070 |
|
10071 | for (i = 0; i < nalUnits.length; i++) {
|
10072 | currentNal = nalUnits[i];
|
10073 |
|
10074 | if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
|
10075 |
|
10076 |
|
10077 | if (currentFrame.length) {
|
10078 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
10079 |
|
10080 | frames.byteLength += currentFrame.byteLength;
|
10081 | frames.nalCount += currentFrame.length;
|
10082 | frames.duration += currentFrame.duration;
|
10083 | frames.push(currentFrame);
|
10084 | }
|
10085 |
|
10086 | currentFrame = [currentNal];
|
10087 | currentFrame.byteLength = currentNal.data.byteLength;
|
10088 | currentFrame.pts = currentNal.pts;
|
10089 | currentFrame.dts = currentNal.dts;
|
10090 | } else {
|
10091 |
|
10092 | if (currentNal.nalUnitType === 'slice_layer_without_partitioning_rbsp_idr') {
|
10093 | currentFrame.keyFrame = true;
|
10094 | }
|
10095 |
|
10096 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
10097 | currentFrame.byteLength += currentNal.data.byteLength;
|
10098 | currentFrame.push(currentNal);
|
10099 | }
|
10100 | }
|
10101 |
|
10102 |
|
10103 |
|
10104 | if (frames.length && (!currentFrame.duration || currentFrame.duration <= 0)) {
|
10105 | currentFrame.duration = frames[frames.length - 1].duration;
|
10106 | }
|
10107 |
|
10108 |
|
10109 |
|
10110 | frames.byteLength += currentFrame.byteLength;
|
10111 | frames.nalCount += currentFrame.length;
|
10112 | frames.duration += currentFrame.duration;
|
10113 | frames.push(currentFrame);
|
10114 | return frames;
|
10115 | };
|
10116 |
|
10117 |
|
10118 |
|
10119 |
|
10120 |
|
10121 | var groupFramesIntoGops = function groupFramesIntoGops(frames) {
|
10122 | var i,
|
10123 | currentFrame,
|
10124 | currentGop = [],
|
10125 | gops = [];
|
10126 |
|
10127 |
|
10128 | currentGop.byteLength = 0;
|
10129 | currentGop.nalCount = 0;
|
10130 | currentGop.duration = 0;
|
10131 | currentGop.pts = frames[0].pts;
|
10132 | currentGop.dts = frames[0].dts;
|
10133 |
|
10134 | gops.byteLength = 0;
|
10135 | gops.nalCount = 0;
|
10136 | gops.duration = 0;
|
10137 | gops.pts = frames[0].pts;
|
10138 | gops.dts = frames[0].dts;
|
10139 |
|
10140 | for (i = 0; i < frames.length; i++) {
|
10141 | currentFrame = frames[i];
|
10142 |
|
10143 | if (currentFrame.keyFrame) {
|
10144 |
|
10145 |
|
10146 | if (currentGop.length) {
|
10147 | gops.push(currentGop);
|
10148 | gops.byteLength += currentGop.byteLength;
|
10149 | gops.nalCount += currentGop.nalCount;
|
10150 | gops.duration += currentGop.duration;
|
10151 | }
|
10152 |
|
10153 | currentGop = [currentFrame];
|
10154 | currentGop.nalCount = currentFrame.length;
|
10155 | currentGop.byteLength = currentFrame.byteLength;
|
10156 | currentGop.pts = currentFrame.pts;
|
10157 | currentGop.dts = currentFrame.dts;
|
10158 | currentGop.duration = currentFrame.duration;
|
10159 | } else {
|
10160 | currentGop.duration += currentFrame.duration;
|
10161 | currentGop.nalCount += currentFrame.length;
|
10162 | currentGop.byteLength += currentFrame.byteLength;
|
10163 | currentGop.push(currentFrame);
|
10164 | }
|
10165 | }
|
10166 |
|
10167 | if (gops.length && currentGop.duration <= 0) {
|
10168 | currentGop.duration = gops[gops.length - 1].duration;
|
10169 | }
|
10170 |
|
10171 | gops.byteLength += currentGop.byteLength;
|
10172 | gops.nalCount += currentGop.nalCount;
|
10173 | gops.duration += currentGop.duration;
|
10174 |
|
10175 | gops.push(currentGop);
|
10176 | return gops;
|
10177 | };
|
10178 | |
10179 |
|
10180 |
|
10181 |
|
10182 |
|
10183 |
|
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 |
|
10189 | var extendFirstKeyFrame = function extendFirstKeyFrame(gops) {
|
10190 | var currentGop;
|
10191 |
|
10192 | if (!gops[0][0].keyFrame && gops.length > 1) {
|
10193 |
|
10194 | currentGop = gops.shift();
|
10195 | gops.byteLength -= currentGop.byteLength;
|
10196 | gops.nalCount -= currentGop.nalCount;
|
10197 |
|
10198 |
|
10199 |
|
10200 | gops[0][0].dts = currentGop.dts;
|
10201 | gops[0][0].pts = currentGop.pts;
|
10202 | gops[0][0].duration += currentGop.duration;
|
10203 | }
|
10204 |
|
10205 | return gops;
|
10206 | };
|
10207 | |
10208 |
|
10209 |
|
10210 |
|
10211 |
|
10212 |
|
10213 | var createDefaultSample = function createDefaultSample() {
|
10214 | return {
|
10215 | size: 0,
|
10216 | flags: {
|
10217 | isLeading: 0,
|
10218 | dependsOn: 1,
|
10219 | isDependedOn: 0,
|
10220 | hasRedundancy: 0,
|
10221 | degradationPriority: 0,
|
10222 | isNonSyncSample: 1
|
10223 | }
|
10224 | };
|
10225 | };
|
10226 | |
10227 |
|
10228 |
|
10229 |
|
10230 |
|
10231 |
|
10232 |
|
10233 |
|
10234 |
|
10235 |
|
10236 | var sampleForFrame = function sampleForFrame(frame, dataOffset) {
|
10237 | var sample = createDefaultSample();
|
10238 | sample.dataOffset = dataOffset;
|
10239 | sample.compositionTimeOffset = frame.pts - frame.dts;
|
10240 | sample.duration = frame.duration;
|
10241 | sample.size = 4 * frame.length;
|
10242 |
|
10243 | sample.size += frame.byteLength;
|
10244 |
|
10245 | if (frame.keyFrame) {
|
10246 | sample.flags.dependsOn = 2;
|
10247 | sample.flags.isNonSyncSample = 0;
|
10248 | }
|
10249 |
|
10250 | return sample;
|
10251 | };
|
10252 |
|
10253 |
|
10254 | var generateSampleTable$1 = function generateSampleTable(gops, baseDataOffset) {
|
10255 | var h,
|
10256 | i,
|
10257 | sample,
|
10258 | currentGop,
|
10259 | currentFrame,
|
10260 | dataOffset = baseDataOffset || 0,
|
10261 | samples = [];
|
10262 |
|
10263 | for (h = 0; h < gops.length; h++) {
|
10264 | currentGop = gops[h];
|
10265 |
|
10266 | for (i = 0; i < currentGop.length; i++) {
|
10267 | currentFrame = currentGop[i];
|
10268 | sample = sampleForFrame(currentFrame, dataOffset);
|
10269 | dataOffset += sample.size;
|
10270 | samples.push(sample);
|
10271 | }
|
10272 | }
|
10273 |
|
10274 | return samples;
|
10275 | };
|
10276 |
|
10277 |
|
10278 | var concatenateNalData = function concatenateNalData(gops) {
|
10279 | var h,
|
10280 | i,
|
10281 | j,
|
10282 | currentGop,
|
10283 | currentFrame,
|
10284 | currentNal,
|
10285 | dataOffset = 0,
|
10286 | nalsByteLength = gops.byteLength,
|
10287 | numberOfNals = gops.nalCount,
|
10288 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
10289 | data = new Uint8Array(totalByteLength),
|
10290 | view = new DataView(data.buffer);
|
10291 |
|
10292 | for (h = 0; h < gops.length; h++) {
|
10293 | currentGop = gops[h];
|
10294 |
|
10295 | for (i = 0; i < currentGop.length; i++) {
|
10296 | currentFrame = currentGop[i];
|
10297 |
|
10298 | for (j = 0; j < currentFrame.length; j++) {
|
10299 | currentNal = currentFrame[j];
|
10300 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
10301 | dataOffset += 4;
|
10302 | data.set(currentNal.data, dataOffset);
|
10303 | dataOffset += currentNal.data.byteLength;
|
10304 | }
|
10305 | }
|
10306 | }
|
10307 |
|
10308 | return data;
|
10309 | };
|
10310 |
|
10311 |
|
10312 | var generateSampleTableForFrame = function generateSampleTableForFrame(frame, baseDataOffset) {
|
10313 | var sample,
|
10314 | dataOffset = baseDataOffset || 0,
|
10315 | samples = [];
|
10316 | sample = sampleForFrame(frame, dataOffset);
|
10317 | samples.push(sample);
|
10318 | return samples;
|
10319 | };
|
10320 |
|
10321 |
|
10322 | var concatenateNalDataForFrame = function concatenateNalDataForFrame(frame) {
|
10323 | var i,
|
10324 | currentNal,
|
10325 | dataOffset = 0,
|
10326 | nalsByteLength = frame.byteLength,
|
10327 | numberOfNals = frame.length,
|
10328 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
10329 | data = new Uint8Array(totalByteLength),
|
10330 | view = new DataView(data.buffer);
|
10331 |
|
10332 | for (i = 0; i < frame.length; i++) {
|
10333 | currentNal = frame[i];
|
10334 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
10335 | dataOffset += 4;
|
10336 | data.set(currentNal.data, dataOffset);
|
10337 | dataOffset += currentNal.data.byteLength;
|
10338 | }
|
10339 |
|
10340 | return data;
|
10341 | };
|
10342 |
|
10343 | var frameUtils = {
|
10344 | groupNalsIntoFrames: groupNalsIntoFrames,
|
10345 | groupFramesIntoGops: groupFramesIntoGops,
|
10346 | extendFirstKeyFrame: extendFirstKeyFrame,
|
10347 | generateSampleTable: generateSampleTable$1,
|
10348 | concatenateNalData: concatenateNalData,
|
10349 | generateSampleTableForFrame: generateSampleTableForFrame,
|
10350 | concatenateNalDataForFrame: concatenateNalDataForFrame
|
10351 | };
|
10352 | |
10353 |
|
10354 |
|
10355 |
|
10356 |
|
10357 |
|
10358 |
|
10359 | var highPrefix = [33, 16, 5, 32, 164, 27];
|
10360 | var lowPrefix = [33, 65, 108, 84, 1, 2, 4, 8, 168, 2, 4, 8, 17, 191, 252];
|
10361 |
|
10362 | var zeroFill = function zeroFill(count) {
|
10363 | var a = [];
|
10364 |
|
10365 | while (count--) {
|
10366 | a.push(0);
|
10367 | }
|
10368 |
|
10369 | return a;
|
10370 | };
|
10371 |
|
10372 | var makeTable = function makeTable(metaTable) {
|
10373 | return Object.keys(metaTable).reduce(function (obj, key) {
|
10374 | obj[key] = new Uint8Array(metaTable[key].reduce(function (arr, part) {
|
10375 | return arr.concat(part);
|
10376 | }, []));
|
10377 | return obj;
|
10378 | }, {});
|
10379 | };
|
10380 |
|
10381 | var silence;
|
10382 |
|
10383 | var silence_1 = function silence_1() {
|
10384 | if (!silence) {
|
10385 |
|
10386 | var coneOfSilence = {
|
10387 | 96000: [highPrefix, [227, 64], zeroFill(154), [56]],
|
10388 | 88200: [highPrefix, [231], zeroFill(170), [56]],
|
10389 | 64000: [highPrefix, [248, 192], zeroFill(240), [56]],
|
10390 | 48000: [highPrefix, [255, 192], zeroFill(268), [55, 148, 128], zeroFill(54), [112]],
|
10391 | 44100: [highPrefix, [255, 192], zeroFill(268), [55, 163, 128], zeroFill(84), [112]],
|
10392 | 32000: [highPrefix, [255, 192], zeroFill(268), [55, 234], zeroFill(226), [112]],
|
10393 | 24000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 112], zeroFill(126), [224]],
|
10394 | 16000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 255], zeroFill(269), [223, 108], zeroFill(195), [1, 192]],
|
10395 | 12000: [lowPrefix, zeroFill(268), [3, 127, 248], zeroFill(268), [6, 255, 240], zeroFill(268), [13, 255, 224], zeroFill(268), [27, 253, 128], zeroFill(259), [56]],
|
10396 | 11025: [lowPrefix, zeroFill(268), [3, 127, 248], zeroFill(268), [6, 255, 240], zeroFill(268), [13, 255, 224], zeroFill(268), [27, 255, 192], zeroFill(268), [55, 175, 128], zeroFill(108), [112]],
|
10397 | 8000: [lowPrefix, zeroFill(268), [3, 121, 16], zeroFill(47), [7]]
|
10398 | };
|
10399 | silence = makeTable(coneOfSilence);
|
10400 | }
|
10401 |
|
10402 | return silence;
|
10403 | };
|
10404 | |
10405 |
|
10406 |
|
10407 |
|
10408 |
|
10409 |
|
10410 |
|
10411 |
|
10412 | var ONE_SECOND_IN_TS$4 = 90000,
|
10413 |
|
10414 | secondsToVideoTs,
|
10415 | secondsToAudioTs,
|
10416 | videoTsToSeconds,
|
10417 | audioTsToSeconds,
|
10418 | audioTsToVideoTs,
|
10419 | videoTsToAudioTs,
|
10420 | metadataTsToSeconds;
|
10421 |
|
10422 | secondsToVideoTs = function secondsToVideoTs(seconds) {
|
10423 | return seconds * ONE_SECOND_IN_TS$4;
|
10424 | };
|
10425 |
|
10426 | secondsToAudioTs = function secondsToAudioTs(seconds, sampleRate) {
|
10427 | return seconds * sampleRate;
|
10428 | };
|
10429 |
|
10430 | videoTsToSeconds = function videoTsToSeconds(timestamp) {
|
10431 | return timestamp / ONE_SECOND_IN_TS$4;
|
10432 | };
|
10433 |
|
10434 | audioTsToSeconds = function audioTsToSeconds(timestamp, sampleRate) {
|
10435 | return timestamp / sampleRate;
|
10436 | };
|
10437 |
|
10438 | audioTsToVideoTs = function audioTsToVideoTs(timestamp, sampleRate) {
|
10439 | return secondsToVideoTs(audioTsToSeconds(timestamp, sampleRate));
|
10440 | };
|
10441 |
|
10442 | videoTsToAudioTs = function videoTsToAudioTs(timestamp, sampleRate) {
|
10443 | return secondsToAudioTs(videoTsToSeconds(timestamp), sampleRate);
|
10444 | };
|
10445 | |
10446 |
|
10447 |
|
10448 |
|
10449 |
|
10450 |
|
10451 | metadataTsToSeconds = function metadataTsToSeconds(timestamp, timelineStartPts, keepOriginalTimestamps) {
|
10452 | return videoTsToSeconds(keepOriginalTimestamps ? timestamp : timestamp - timelineStartPts);
|
10453 | };
|
10454 |
|
10455 | var clock = {
|
10456 | ONE_SECOND_IN_TS: ONE_SECOND_IN_TS$4,
|
10457 | secondsToVideoTs: secondsToVideoTs,
|
10458 | secondsToAudioTs: secondsToAudioTs,
|
10459 | videoTsToSeconds: videoTsToSeconds,
|
10460 | audioTsToSeconds: audioTsToSeconds,
|
10461 | audioTsToVideoTs: audioTsToVideoTs,
|
10462 | videoTsToAudioTs: videoTsToAudioTs,
|
10463 | metadataTsToSeconds: metadataTsToSeconds
|
10464 | };
|
10465 | |
10466 |
|
10467 |
|
10468 |
|
10469 |
|
10470 |
|
10471 |
|
10472 | |
10473 |
|
10474 |
|
10475 |
|
10476 | var sumFrameByteLengths = function sumFrameByteLengths(array) {
|
10477 | var i,
|
10478 | currentObj,
|
10479 | sum = 0;
|
10480 |
|
10481 | for (i = 0; i < array.length; i++) {
|
10482 | currentObj = array[i];
|
10483 | sum += currentObj.data.byteLength;
|
10484 | }
|
10485 |
|
10486 | return sum;
|
10487 | };
|
10488 |
|
10489 |
|
10490 |
|
10491 | var prefixWithSilence = function prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime) {
|
10492 | var baseMediaDecodeTimeTs,
|
10493 | frameDuration = 0,
|
10494 | audioGapDuration = 0,
|
10495 | audioFillFrameCount = 0,
|
10496 | audioFillDuration = 0,
|
10497 | silentFrame,
|
10498 | i,
|
10499 | firstFrame;
|
10500 |
|
10501 | if (!frames.length) {
|
10502 | return;
|
10503 | }
|
10504 |
|
10505 | baseMediaDecodeTimeTs = clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate);
|
10506 |
|
10507 | frameDuration = Math.ceil(clock.ONE_SECOND_IN_TS / (track.samplerate / 1024));
|
10508 |
|
10509 | if (audioAppendStartTs && videoBaseMediaDecodeTime) {
|
10510 |
|
10511 | audioGapDuration = baseMediaDecodeTimeTs - Math.max(audioAppendStartTs, videoBaseMediaDecodeTime);
|
10512 |
|
10513 | audioFillFrameCount = Math.floor(audioGapDuration / frameDuration);
|
10514 | audioFillDuration = audioFillFrameCount * frameDuration;
|
10515 | }
|
10516 |
|
10517 |
|
10518 |
|
10519 | if (audioFillFrameCount < 1 || audioFillDuration > clock.ONE_SECOND_IN_TS / 2) {
|
10520 | return;
|
10521 | }
|
10522 |
|
10523 | silentFrame = silence_1()[track.samplerate];
|
10524 |
|
10525 | if (!silentFrame) {
|
10526 |
|
10527 |
|
10528 | silentFrame = frames[0].data;
|
10529 | }
|
10530 |
|
10531 | for (i = 0; i < audioFillFrameCount; i++) {
|
10532 | firstFrame = frames[0];
|
10533 | frames.splice(0, 0, {
|
10534 | data: silentFrame,
|
10535 | dts: firstFrame.dts - frameDuration,
|
10536 | pts: firstFrame.pts - frameDuration
|
10537 | });
|
10538 | }
|
10539 |
|
10540 | track.baseMediaDecodeTime -= Math.floor(clock.videoTsToAudioTs(audioFillDuration, track.samplerate));
|
10541 | return audioFillDuration;
|
10542 | };
|
10543 |
|
10544 |
|
10545 |
|
10546 |
|
10547 |
|
10548 | var trimAdtsFramesByEarliestDts = function trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts) {
|
10549 | if (track.minSegmentDts >= earliestAllowedDts) {
|
10550 | return adtsFrames;
|
10551 | }
|
10552 |
|
10553 |
|
10554 | track.minSegmentDts = Infinity;
|
10555 | return adtsFrames.filter(function (currentFrame) {
|
10556 |
|
10557 | if (currentFrame.dts >= earliestAllowedDts) {
|
10558 | track.minSegmentDts = Math.min(track.minSegmentDts, currentFrame.dts);
|
10559 | track.minSegmentPts = track.minSegmentDts;
|
10560 | return true;
|
10561 | }
|
10562 |
|
10563 |
|
10564 | return false;
|
10565 | });
|
10566 | };
|
10567 |
|
10568 |
|
10569 | var generateSampleTable = function generateSampleTable(frames) {
|
10570 | var i,
|
10571 | currentFrame,
|
10572 | samples = [];
|
10573 |
|
10574 | for (i = 0; i < frames.length; i++) {
|
10575 | currentFrame = frames[i];
|
10576 | samples.push({
|
10577 | size: currentFrame.data.byteLength,
|
10578 | duration: 1024
|
10579 |
|
10580 | });
|
10581 | }
|
10582 |
|
10583 | return samples;
|
10584 | };
|
10585 |
|
10586 |
|
10587 | var concatenateFrameData = function concatenateFrameData(frames) {
|
10588 | var i,
|
10589 | currentFrame,
|
10590 | dataOffset = 0,
|
10591 | data = new Uint8Array(sumFrameByteLengths(frames));
|
10592 |
|
10593 | for (i = 0; i < frames.length; i++) {
|
10594 | currentFrame = frames[i];
|
10595 | data.set(currentFrame.data, dataOffset);
|
10596 | dataOffset += currentFrame.data.byteLength;
|
10597 | }
|
10598 |
|
10599 | return data;
|
10600 | };
|
10601 |
|
10602 | var audioFrameUtils = {
|
10603 | prefixWithSilence: prefixWithSilence,
|
10604 | trimAdtsFramesByEarliestDts: trimAdtsFramesByEarliestDts,
|
10605 | generateSampleTable: generateSampleTable,
|
10606 | concatenateFrameData: concatenateFrameData
|
10607 | };
|
10608 | |
10609 |
|
10610 |
|
10611 |
|
10612 |
|
10613 |
|
10614 |
|
10615 | var ONE_SECOND_IN_TS$3 = clock.ONE_SECOND_IN_TS;
|
10616 | |
10617 |
|
10618 |
|
10619 |
|
10620 |
|
10621 |
|
10622 | var collectDtsInfo = function collectDtsInfo(track, data) {
|
10623 | if (typeof data.pts === 'number') {
|
10624 | if (track.timelineStartInfo.pts === undefined) {
|
10625 | track.timelineStartInfo.pts = data.pts;
|
10626 | }
|
10627 |
|
10628 | if (track.minSegmentPts === undefined) {
|
10629 | track.minSegmentPts = data.pts;
|
10630 | } else {
|
10631 | track.minSegmentPts = Math.min(track.minSegmentPts, data.pts);
|
10632 | }
|
10633 |
|
10634 | if (track.maxSegmentPts === undefined) {
|
10635 | track.maxSegmentPts = data.pts;
|
10636 | } else {
|
10637 | track.maxSegmentPts = Math.max(track.maxSegmentPts, data.pts);
|
10638 | }
|
10639 | }
|
10640 |
|
10641 | if (typeof data.dts === 'number') {
|
10642 | if (track.timelineStartInfo.dts === undefined) {
|
10643 | track.timelineStartInfo.dts = data.dts;
|
10644 | }
|
10645 |
|
10646 | if (track.minSegmentDts === undefined) {
|
10647 | track.minSegmentDts = data.dts;
|
10648 | } else {
|
10649 | track.minSegmentDts = Math.min(track.minSegmentDts, data.dts);
|
10650 | }
|
10651 |
|
10652 | if (track.maxSegmentDts === undefined) {
|
10653 | track.maxSegmentDts = data.dts;
|
10654 | } else {
|
10655 | track.maxSegmentDts = Math.max(track.maxSegmentDts, data.dts);
|
10656 | }
|
10657 | }
|
10658 | };
|
10659 | |
10660 |
|
10661 |
|
10662 |
|
10663 |
|
10664 |
|
10665 | var clearDtsInfo = function clearDtsInfo(track) {
|
10666 | delete track.minSegmentDts;
|
10667 | delete track.maxSegmentDts;
|
10668 | delete track.minSegmentPts;
|
10669 | delete track.maxSegmentPts;
|
10670 | };
|
10671 | |
10672 |
|
10673 |
|
10674 |
|
10675 |
|
10676 |
|
10677 |
|
10678 |
|
10679 |
|
10680 |
|
10681 | var calculateTrackBaseMediaDecodeTime = function calculateTrackBaseMediaDecodeTime(track, keepOriginalTimestamps) {
|
10682 | var baseMediaDecodeTime,
|
10683 | scale,
|
10684 | minSegmentDts = track.minSegmentDts;
|
10685 |
|
10686 | if (!keepOriginalTimestamps) {
|
10687 | minSegmentDts -= track.timelineStartInfo.dts;
|
10688 | }
|
10689 |
|
10690 |
|
10691 |
|
10692 | baseMediaDecodeTime = track.timelineStartInfo.baseMediaDecodeTime;
|
10693 |
|
10694 | baseMediaDecodeTime += minSegmentDts;
|
10695 |
|
10696 | baseMediaDecodeTime = Math.max(0, baseMediaDecodeTime);
|
10697 |
|
10698 | if (track.type === 'audio') {
|
10699 |
|
10700 |
|
10701 | scale = track.samplerate / ONE_SECOND_IN_TS$3;
|
10702 | baseMediaDecodeTime *= scale;
|
10703 | baseMediaDecodeTime = Math.floor(baseMediaDecodeTime);
|
10704 | }
|
10705 |
|
10706 | return baseMediaDecodeTime;
|
10707 | };
|
10708 |
|
10709 | var trackDecodeInfo = {
|
10710 | clearDtsInfo: clearDtsInfo,
|
10711 | calculateTrackBaseMediaDecodeTime: calculateTrackBaseMediaDecodeTime,
|
10712 | collectDtsInfo: collectDtsInfo
|
10713 | };
|
10714 | |
10715 |
|
10716 |
|
10717 |
|
10718 |
|
10719 |
|
10720 |
|
10721 |
|
10722 |
|
10723 |
|
10724 |
|
10725 |
|
10726 |
|
10727 |
|
10728 |
|
10729 |
|
10730 | var USER_DATA_REGISTERED_ITU_T_T35 = 4,
|
10731 | RBSP_TRAILING_BITS = 128;
|
10732 | |
10733 |
|
10734 |
|
10735 |
|
10736 |
|
10737 |
|
10738 |
|
10739 |
|
10740 |
|
10741 | var parseSei = function parseSei(bytes) {
|
10742 | var i = 0,
|
10743 | result = {
|
10744 | payloadType: -1,
|
10745 | payloadSize: 0
|
10746 | },
|
10747 | payloadType = 0,
|
10748 | payloadSize = 0;
|
10749 |
|
10750 | while (i < bytes.byteLength) {
|
10751 |
|
10752 | if (bytes[i] === RBSP_TRAILING_BITS) {
|
10753 | break;
|
10754 | }
|
10755 |
|
10756 |
|
10757 | while (bytes[i] === 0xFF) {
|
10758 | payloadType += 255;
|
10759 | i++;
|
10760 | }
|
10761 |
|
10762 | payloadType += bytes[i++];
|
10763 |
|
10764 | while (bytes[i] === 0xFF) {
|
10765 | payloadSize += 255;
|
10766 | i++;
|
10767 | }
|
10768 |
|
10769 | payloadSize += bytes[i++];
|
10770 |
|
10771 |
|
10772 | if (!result.payload && payloadType === USER_DATA_REGISTERED_ITU_T_T35) {
|
10773 | var userIdentifier = String.fromCharCode(bytes[i + 3], bytes[i + 4], bytes[i + 5], bytes[i + 6]);
|
10774 |
|
10775 | if (userIdentifier === 'GA94') {
|
10776 | result.payloadType = payloadType;
|
10777 | result.payloadSize = payloadSize;
|
10778 | result.payload = bytes.subarray(i, i + payloadSize);
|
10779 | break;
|
10780 | } else {
|
10781 | result.payload = void 0;
|
10782 | }
|
10783 | }
|
10784 |
|
10785 |
|
10786 | i += payloadSize;
|
10787 | payloadType = 0;
|
10788 | payloadSize = 0;
|
10789 | }
|
10790 |
|
10791 | return result;
|
10792 | };
|
10793 |
|
10794 |
|
10795 | var parseUserData = function parseUserData(sei) {
|
10796 |
|
10797 |
|
10798 | if (sei.payload[0] !== 181) {
|
10799 | return null;
|
10800 | }
|
10801 |
|
10802 |
|
10803 | if ((sei.payload[1] << 8 | sei.payload[2]) !== 49) {
|
10804 | return null;
|
10805 | }
|
10806 |
|
10807 |
|
10808 | if (String.fromCharCode(sei.payload[3], sei.payload[4], sei.payload[5], sei.payload[6]) !== 'GA94') {
|
10809 | return null;
|
10810 | }
|
10811 |
|
10812 |
|
10813 | if (sei.payload[7] !== 0x03) {
|
10814 | return null;
|
10815 | }
|
10816 |
|
10817 |
|
10818 |
|
10819 | return sei.payload.subarray(8, sei.payload.length - 1);
|
10820 | };
|
10821 |
|
10822 |
|
10823 | var parseCaptionPackets = function parseCaptionPackets(pts, userData) {
|
10824 | var results = [],
|
10825 | i,
|
10826 | count,
|
10827 | offset,
|
10828 | data;
|
10829 |
|
10830 | if (!(userData[0] & 0x40)) {
|
10831 | return results;
|
10832 | }
|
10833 |
|
10834 |
|
10835 | count = userData[0] & 0x1f;
|
10836 |
|
10837 | for (i = 0; i < count; i++) {
|
10838 | offset = i * 3;
|
10839 | data = {
|
10840 | type: userData[offset + 2] & 0x03,
|
10841 | pts: pts
|
10842 | };
|
10843 |
|
10844 | if (userData[offset + 2] & 0x04) {
|
10845 | data.ccData = userData[offset + 3] << 8 | userData[offset + 4];
|
10846 | results.push(data);
|
10847 | }
|
10848 | }
|
10849 |
|
10850 | return results;
|
10851 | };
|
10852 |
|
10853 | var discardEmulationPreventionBytes$1 = function discardEmulationPreventionBytes(data) {
|
10854 | var length = data.byteLength,
|
10855 | emulationPreventionBytesPositions = [],
|
10856 | i = 1,
|
10857 | newLength,
|
10858 | newData;
|
10859 |
|
10860 | while (i < length - 2) {
|
10861 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
10862 | emulationPreventionBytesPositions.push(i + 2);
|
10863 | i += 2;
|
10864 | } else {
|
10865 | i++;
|
10866 | }
|
10867 | }
|
10868 |
|
10869 |
|
10870 |
|
10871 | if (emulationPreventionBytesPositions.length === 0) {
|
10872 | return data;
|
10873 | }
|
10874 |
|
10875 |
|
10876 | newLength = length - emulationPreventionBytesPositions.length;
|
10877 | newData = new Uint8Array(newLength);
|
10878 | var sourceIndex = 0;
|
10879 |
|
10880 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
10881 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
10882 |
|
10883 | sourceIndex++;
|
10884 |
|
10885 | emulationPreventionBytesPositions.shift();
|
10886 | }
|
10887 |
|
10888 | newData[i] = data[sourceIndex];
|
10889 | }
|
10890 |
|
10891 | return newData;
|
10892 | };
|
10893 |
|
10894 |
|
10895 | var captionPacketParser = {
|
10896 | parseSei: parseSei,
|
10897 | parseUserData: parseUserData,
|
10898 | parseCaptionPackets: parseCaptionPackets,
|
10899 | discardEmulationPreventionBytes: discardEmulationPreventionBytes$1,
|
10900 | USER_DATA_REGISTERED_ITU_T_T35: USER_DATA_REGISTERED_ITU_T_T35
|
10901 | };
|
10902 |
|
10903 |
|
10904 | var CaptionStream$1 = function CaptionStream(options) {
|
10905 | options = options || {};
|
10906 | CaptionStream.prototype.init.call(this);
|
10907 |
|
10908 | this.parse708captions_ = typeof options.parse708captions === 'boolean' ? options.parse708captions : true;
|
10909 | this.captionPackets_ = [];
|
10910 | this.ccStreams_ = [new Cea608Stream(0, 0),
|
10911 | new Cea608Stream(0, 1),
|
10912 | new Cea608Stream(1, 0),
|
10913 | new Cea608Stream(1, 1)
|
10914 | ];
|
10915 |
|
10916 | if (this.parse708captions_) {
|
10917 | this.cc708Stream_ = new Cea708Stream({
|
10918 | captionServices: options.captionServices
|
10919 | });
|
10920 | }
|
10921 |
|
10922 | this.reset();
|
10923 |
|
10924 | this.ccStreams_.forEach(function (cc) {
|
10925 | cc.on('data', this.trigger.bind(this, 'data'));
|
10926 | cc.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
10927 | cc.on('done', this.trigger.bind(this, 'done'));
|
10928 | }, this);
|
10929 |
|
10930 | if (this.parse708captions_) {
|
10931 | this.cc708Stream_.on('data', this.trigger.bind(this, 'data'));
|
10932 | this.cc708Stream_.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
10933 | this.cc708Stream_.on('done', this.trigger.bind(this, 'done'));
|
10934 | }
|
10935 | };
|
10936 |
|
10937 | CaptionStream$1.prototype = new stream();
|
10938 |
|
10939 | CaptionStream$1.prototype.push = function (event) {
|
10940 | var sei, userData, newCaptionPackets;
|
10941 |
|
10942 | if (event.nalUnitType !== 'sei_rbsp') {
|
10943 | return;
|
10944 | }
|
10945 |
|
10946 |
|
10947 | sei = captionPacketParser.parseSei(event.escapedRBSP);
|
10948 |
|
10949 | if (!sei.payload) {
|
10950 | return;
|
10951 | }
|
10952 |
|
10953 |
|
10954 | if (sei.payloadType !== captionPacketParser.USER_DATA_REGISTERED_ITU_T_T35) {
|
10955 | return;
|
10956 | }
|
10957 |
|
10958 |
|
10959 | userData = captionPacketParser.parseUserData(sei);
|
10960 |
|
10961 | if (!userData) {
|
10962 | return;
|
10963 | }
|
10964 |
|
10965 |
|
10966 |
|
10967 |
|
10968 |
|
10969 |
|
10970 |
|
10971 |
|
10972 |
|
10973 | if (event.dts < this.latestDts_) {
|
10974 |
|
10975 | this.ignoreNextEqualDts_ = true;
|
10976 | return;
|
10977 | } else if (event.dts === this.latestDts_ && this.ignoreNextEqualDts_) {
|
10978 | this.numSameDts_--;
|
10979 |
|
10980 | if (!this.numSameDts_) {
|
10981 |
|
10982 | this.ignoreNextEqualDts_ = false;
|
10983 | }
|
10984 |
|
10985 | return;
|
10986 | }
|
10987 |
|
10988 |
|
10989 | newCaptionPackets = captionPacketParser.parseCaptionPackets(event.pts, userData);
|
10990 | this.captionPackets_ = this.captionPackets_.concat(newCaptionPackets);
|
10991 |
|
10992 | if (this.latestDts_ !== event.dts) {
|
10993 | this.numSameDts_ = 0;
|
10994 | }
|
10995 |
|
10996 | this.numSameDts_++;
|
10997 | this.latestDts_ = event.dts;
|
10998 | };
|
10999 |
|
11000 | CaptionStream$1.prototype.flushCCStreams = function (flushType) {
|
11001 | this.ccStreams_.forEach(function (cc) {
|
11002 | return flushType === 'flush' ? cc.flush() : cc.partialFlush();
|
11003 | }, this);
|
11004 | };
|
11005 |
|
11006 | CaptionStream$1.prototype.flushStream = function (flushType) {
|
11007 |
|
11008 | if (!this.captionPackets_.length) {
|
11009 | this.flushCCStreams(flushType);
|
11010 | return;
|
11011 | }
|
11012 |
|
11013 |
|
11014 |
|
11015 | this.captionPackets_.forEach(function (elem, idx) {
|
11016 | elem.presortIndex = idx;
|
11017 | });
|
11018 |
|
11019 | this.captionPackets_.sort(function (a, b) {
|
11020 | if (a.pts === b.pts) {
|
11021 | return a.presortIndex - b.presortIndex;
|
11022 | }
|
11023 |
|
11024 | return a.pts - b.pts;
|
11025 | });
|
11026 | this.captionPackets_.forEach(function (packet) {
|
11027 | if (packet.type < 2) {
|
11028 |
|
11029 | this.dispatchCea608Packet(packet);
|
11030 | } else {
|
11031 |
|
11032 | this.dispatchCea708Packet(packet);
|
11033 | }
|
11034 | }, this);
|
11035 | this.captionPackets_.length = 0;
|
11036 | this.flushCCStreams(flushType);
|
11037 | };
|
11038 |
|
11039 | CaptionStream$1.prototype.flush = function () {
|
11040 | return this.flushStream('flush');
|
11041 | };
|
11042 |
|
11043 |
|
11044 | CaptionStream$1.prototype.partialFlush = function () {
|
11045 | return this.flushStream('partialFlush');
|
11046 | };
|
11047 |
|
11048 | CaptionStream$1.prototype.reset = function () {
|
11049 | this.latestDts_ = null;
|
11050 | this.ignoreNextEqualDts_ = false;
|
11051 | this.numSameDts_ = 0;
|
11052 | this.activeCea608Channel_ = [null, null];
|
11053 | this.ccStreams_.forEach(function (ccStream) {
|
11054 | ccStream.reset();
|
11055 | });
|
11056 | };
|
11057 |
|
11058 | |
11059 |
|
11060 |
|
11061 |
|
11062 |
|
11063 |
|
11064 |
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 | CaptionStream$1.prototype.dispatchCea608Packet = function (packet) {
|
11071 |
|
11072 | if (this.setsTextOrXDSActive(packet)) {
|
11073 | this.activeCea608Channel_[packet.type] = null;
|
11074 | } else if (this.setsChannel1Active(packet)) {
|
11075 | this.activeCea608Channel_[packet.type] = 0;
|
11076 | } else if (this.setsChannel2Active(packet)) {
|
11077 | this.activeCea608Channel_[packet.type] = 1;
|
11078 | }
|
11079 |
|
11080 | if (this.activeCea608Channel_[packet.type] === null) {
|
11081 |
|
11082 |
|
11083 |
|
11084 | return;
|
11085 | }
|
11086 |
|
11087 | this.ccStreams_[(packet.type << 1) + this.activeCea608Channel_[packet.type]].push(packet);
|
11088 | };
|
11089 |
|
11090 | CaptionStream$1.prototype.setsChannel1Active = function (packet) {
|
11091 | return (packet.ccData & 0x7800) === 0x1000;
|
11092 | };
|
11093 |
|
11094 | CaptionStream$1.prototype.setsChannel2Active = function (packet) {
|
11095 | return (packet.ccData & 0x7800) === 0x1800;
|
11096 | };
|
11097 |
|
11098 | CaptionStream$1.prototype.setsTextOrXDSActive = function (packet) {
|
11099 | return (packet.ccData & 0x7100) === 0x0100 || (packet.ccData & 0x78fe) === 0x102a || (packet.ccData & 0x78fe) === 0x182a;
|
11100 | };
|
11101 |
|
11102 | CaptionStream$1.prototype.dispatchCea708Packet = function (packet) {
|
11103 | if (this.parse708captions_) {
|
11104 | this.cc708Stream_.push(packet);
|
11105 | }
|
11106 | };
|
11107 |
|
11108 |
|
11109 |
|
11110 |
|
11111 |
|
11112 |
|
11113 |
|
11114 |
|
11115 |
|
11116 |
|
11117 |
|
11118 |
|
11119 |
|
11120 |
|
11121 |
|
11122 |
|
11123 |
|
11124 |
|
11125 |
|
11126 | var CHARACTER_TRANSLATION_708 = {
|
11127 | 0x7f: 0x266a,
|
11128 |
|
11129 | 0x1020: 0x20,
|
11130 |
|
11131 | 0x1021: 0xa0,
|
11132 |
|
11133 | 0x1025: 0x2026,
|
11134 |
|
11135 | 0x102a: 0x0160,
|
11136 |
|
11137 | 0x102c: 0x0152,
|
11138 |
|
11139 | 0x1030: 0x2588,
|
11140 |
|
11141 | 0x1031: 0x2018,
|
11142 |
|
11143 | 0x1032: 0x2019,
|
11144 |
|
11145 | 0x1033: 0x201c,
|
11146 |
|
11147 | 0x1034: 0x201d,
|
11148 |
|
11149 | 0x1035: 0x2022,
|
11150 |
|
11151 | 0x1039: 0x2122,
|
11152 |
|
11153 | 0x103a: 0x0161,
|
11154 |
|
11155 | 0x103c: 0x0153,
|
11156 |
|
11157 | 0x103d: 0x2120,
|
11158 |
|
11159 | 0x103f: 0x0178,
|
11160 |
|
11161 | 0x1076: 0x215b,
|
11162 |
|
11163 | 0x1077: 0x215c,
|
11164 |
|
11165 | 0x1078: 0x215d,
|
11166 |
|
11167 | 0x1079: 0x215e,
|
11168 |
|
11169 | 0x107a: 0x23d0,
|
11170 |
|
11171 | 0x107b: 0x23a4,
|
11172 |
|
11173 | 0x107c: 0x23a3,
|
11174 |
|
11175 | 0x107d: 0x23af,
|
11176 |
|
11177 | 0x107e: 0x23a6,
|
11178 |
|
11179 | 0x107f: 0x23a1,
|
11180 |
|
11181 | 0x10a0: 0x3138
|
11182 |
|
11183 | };
|
11184 |
|
11185 | var get708CharFromCode = function get708CharFromCode(code) {
|
11186 | var newCode = CHARACTER_TRANSLATION_708[code] || code;
|
11187 |
|
11188 | if (code & 0x1000 && code === newCode) {
|
11189 |
|
11190 | return '';
|
11191 | }
|
11192 |
|
11193 | return String.fromCharCode(newCode);
|
11194 | };
|
11195 |
|
11196 | var within708TextBlock = function within708TextBlock(b) {
|
11197 | return 0x20 <= b && b <= 0x7f || 0xa0 <= b && b <= 0xff;
|
11198 | };
|
11199 |
|
11200 | var Cea708Window = function Cea708Window(windowNum) {
|
11201 | this.windowNum = windowNum;
|
11202 | this.reset();
|
11203 | };
|
11204 |
|
11205 | Cea708Window.prototype.reset = function () {
|
11206 | this.clearText();
|
11207 | this.pendingNewLine = false;
|
11208 | this.winAttr = {};
|
11209 | this.penAttr = {};
|
11210 | this.penLoc = {};
|
11211 | this.penColor = {};
|
11212 |
|
11213 |
|
11214 | this.visible = 0;
|
11215 | this.rowLock = 0;
|
11216 | this.columnLock = 0;
|
11217 | this.priority = 0;
|
11218 | this.relativePositioning = 0;
|
11219 | this.anchorVertical = 0;
|
11220 | this.anchorHorizontal = 0;
|
11221 | this.anchorPoint = 0;
|
11222 | this.rowCount = 1;
|
11223 | this.virtualRowCount = this.rowCount + 1;
|
11224 | this.columnCount = 41;
|
11225 | this.windowStyle = 0;
|
11226 | this.penStyle = 0;
|
11227 | };
|
11228 |
|
11229 | Cea708Window.prototype.getText = function () {
|
11230 | return this.rows.join('\n');
|
11231 | };
|
11232 |
|
11233 | Cea708Window.prototype.clearText = function () {
|
11234 | this.rows = [''];
|
11235 | this.rowIdx = 0;
|
11236 | };
|
11237 |
|
11238 | Cea708Window.prototype.newLine = function (pts) {
|
11239 | if (this.rows.length >= this.virtualRowCount && typeof this.beforeRowOverflow === 'function') {
|
11240 | this.beforeRowOverflow(pts);
|
11241 | }
|
11242 |
|
11243 | if (this.rows.length > 0) {
|
11244 | this.rows.push('');
|
11245 | this.rowIdx++;
|
11246 | }
|
11247 |
|
11248 |
|
11249 | while (this.rows.length > this.virtualRowCount) {
|
11250 | this.rows.shift();
|
11251 | this.rowIdx--;
|
11252 | }
|
11253 | };
|
11254 |
|
11255 | Cea708Window.prototype.isEmpty = function () {
|
11256 | if (this.rows.length === 0) {
|
11257 | return true;
|
11258 | } else if (this.rows.length === 1) {
|
11259 | return this.rows[0] === '';
|
11260 | }
|
11261 |
|
11262 | return false;
|
11263 | };
|
11264 |
|
11265 | Cea708Window.prototype.addText = function (text) {
|
11266 | this.rows[this.rowIdx] += text;
|
11267 | };
|
11268 |
|
11269 | Cea708Window.prototype.backspace = function () {
|
11270 | if (!this.isEmpty()) {
|
11271 | var row = this.rows[this.rowIdx];
|
11272 | this.rows[this.rowIdx] = row.substr(0, row.length - 1);
|
11273 | }
|
11274 | };
|
11275 |
|
11276 | var Cea708Service = function Cea708Service(serviceNum, encoding, stream) {
|
11277 | this.serviceNum = serviceNum;
|
11278 | this.text = '';
|
11279 | this.currentWindow = new Cea708Window(-1);
|
11280 | this.windows = [];
|
11281 | this.stream = stream;
|
11282 |
|
11283 | if (typeof encoding === 'string') {
|
11284 | this.createTextDecoder(encoding);
|
11285 | }
|
11286 | };
|
11287 | |
11288 |
|
11289 |
|
11290 |
|
11291 |
|
11292 |
|
11293 |
|
11294 |
|
11295 |
|
11296 | Cea708Service.prototype.init = function (pts, beforeRowOverflow) {
|
11297 | this.startPts = pts;
|
11298 |
|
11299 | for (var win = 0; win < 8; win++) {
|
11300 | this.windows[win] = new Cea708Window(win);
|
11301 |
|
11302 | if (typeof beforeRowOverflow === 'function') {
|
11303 | this.windows[win].beforeRowOverflow = beforeRowOverflow;
|
11304 | }
|
11305 | }
|
11306 | };
|
11307 | |
11308 |
|
11309 |
|
11310 |
|
11311 |
|
11312 |
|
11313 |
|
11314 | Cea708Service.prototype.setCurrentWindow = function (windowNum) {
|
11315 | this.currentWindow = this.windows[windowNum];
|
11316 | };
|
11317 | |
11318 |
|
11319 |
|
11320 |
|
11321 |
|
11322 | Cea708Service.prototype.createTextDecoder = function (encoding) {
|
11323 | if (typeof TextDecoder === 'undefined') {
|
11324 | this.stream.trigger('log', {
|
11325 | level: 'warn',
|
11326 | message: 'The `encoding` option is unsupported without TextDecoder support'
|
11327 | });
|
11328 | } else {
|
11329 | try {
|
11330 | this.textDecoder_ = new TextDecoder(encoding);
|
11331 | } catch (error) {
|
11332 | this.stream.trigger('log', {
|
11333 | level: 'warn',
|
11334 | message: 'TextDecoder could not be created with ' + encoding + ' encoding. ' + error
|
11335 | });
|
11336 | }
|
11337 | }
|
11338 | };
|
11339 |
|
11340 | var Cea708Stream = function Cea708Stream(options) {
|
11341 | options = options || {};
|
11342 | Cea708Stream.prototype.init.call(this);
|
11343 | var self = this;
|
11344 | var captionServices = options.captionServices || {};
|
11345 | var captionServiceEncodings = {};
|
11346 | var serviceProps;
|
11347 |
|
11348 | Object.keys(captionServices).forEach(function (serviceName) {
|
11349 | serviceProps = captionServices[serviceName];
|
11350 |
|
11351 | if (/^SERVICE/.test(serviceName)) {
|
11352 | captionServiceEncodings[serviceName] = serviceProps.encoding;
|
11353 | }
|
11354 | });
|
11355 | this.serviceEncodings = captionServiceEncodings;
|
11356 | this.current708Packet = null;
|
11357 | this.services = {};
|
11358 |
|
11359 | this.push = function (packet) {
|
11360 | if (packet.type === 3) {
|
11361 |
|
11362 | self.new708Packet();
|
11363 | self.add708Bytes(packet);
|
11364 | } else {
|
11365 | if (self.current708Packet === null) {
|
11366 |
|
11367 | self.new708Packet();
|
11368 | }
|
11369 |
|
11370 | self.add708Bytes(packet);
|
11371 | }
|
11372 | };
|
11373 | };
|
11374 |
|
11375 | Cea708Stream.prototype = new stream();
|
11376 | |
11377 |
|
11378 |
|
11379 |
|
11380 | Cea708Stream.prototype.new708Packet = function () {
|
11381 | if (this.current708Packet !== null) {
|
11382 | this.push708Packet();
|
11383 | }
|
11384 |
|
11385 | this.current708Packet = {
|
11386 | data: [],
|
11387 | ptsVals: []
|
11388 | };
|
11389 | };
|
11390 | |
11391 |
|
11392 |
|
11393 |
|
11394 |
|
11395 | Cea708Stream.prototype.add708Bytes = function (packet) {
|
11396 | var data = packet.ccData;
|
11397 | var byte0 = data >>> 8;
|
11398 | var byte1 = data & 0xff;
|
11399 |
|
11400 |
|
11401 | this.current708Packet.ptsVals.push(packet.pts);
|
11402 | this.current708Packet.data.push(byte0);
|
11403 | this.current708Packet.data.push(byte1);
|
11404 | };
|
11405 | |
11406 |
|
11407 |
|
11408 |
|
11409 |
|
11410 | Cea708Stream.prototype.push708Packet = function () {
|
11411 | var packet708 = this.current708Packet;
|
11412 | var packetData = packet708.data;
|
11413 | var serviceNum = null;
|
11414 | var blockSize = null;
|
11415 | var i = 0;
|
11416 | var b = packetData[i++];
|
11417 | packet708.seq = b >> 6;
|
11418 | packet708.sizeCode = b & 0x3f;
|
11419 |
|
11420 | for (; i < packetData.length; i++) {
|
11421 | b = packetData[i++];
|
11422 | serviceNum = b >> 5;
|
11423 | blockSize = b & 0x1f;
|
11424 |
|
11425 | if (serviceNum === 7 && blockSize > 0) {
|
11426 |
|
11427 | b = packetData[i++];
|
11428 | serviceNum = b;
|
11429 | }
|
11430 |
|
11431 | this.pushServiceBlock(serviceNum, i, blockSize);
|
11432 |
|
11433 | if (blockSize > 0) {
|
11434 | i += blockSize - 1;
|
11435 | }
|
11436 | }
|
11437 | };
|
11438 | |
11439 |
|
11440 |
|
11441 |
|
11442 |
|
11443 |
|
11444 |
|
11445 |
|
11446 |
|
11447 |
|
11448 |
|
11449 |
|
11450 |
|
11451 |
|
11452 | Cea708Stream.prototype.pushServiceBlock = function (serviceNum, start, size) {
|
11453 | var b;
|
11454 | var i = start;
|
11455 | var packetData = this.current708Packet.data;
|
11456 | var service = this.services[serviceNum];
|
11457 |
|
11458 | if (!service) {
|
11459 | service = this.initService(serviceNum, i);
|
11460 | }
|
11461 |
|
11462 | for (; i < start + size && i < packetData.length; i++) {
|
11463 | b = packetData[i];
|
11464 |
|
11465 | if (within708TextBlock(b)) {
|
11466 | i = this.handleText(i, service);
|
11467 | } else if (b === 0x18) {
|
11468 | i = this.multiByteCharacter(i, service);
|
11469 | } else if (b === 0x10) {
|
11470 | i = this.extendedCommands(i, service);
|
11471 | } else if (0x80 <= b && b <= 0x87) {
|
11472 | i = this.setCurrentWindow(i, service);
|
11473 | } else if (0x98 <= b && b <= 0x9f) {
|
11474 | i = this.defineWindow(i, service);
|
11475 | } else if (b === 0x88) {
|
11476 | i = this.clearWindows(i, service);
|
11477 | } else if (b === 0x8c) {
|
11478 | i = this.deleteWindows(i, service);
|
11479 | } else if (b === 0x89) {
|
11480 | i = this.displayWindows(i, service);
|
11481 | } else if (b === 0x8a) {
|
11482 | i = this.hideWindows(i, service);
|
11483 | } else if (b === 0x8b) {
|
11484 | i = this.toggleWindows(i, service);
|
11485 | } else if (b === 0x97) {
|
11486 | i = this.setWindowAttributes(i, service);
|
11487 | } else if (b === 0x90) {
|
11488 | i = this.setPenAttributes(i, service);
|
11489 | } else if (b === 0x91) {
|
11490 | i = this.setPenColor(i, service);
|
11491 | } else if (b === 0x92) {
|
11492 | i = this.setPenLocation(i, service);
|
11493 | } else if (b === 0x8f) {
|
11494 | service = this.reset(i, service);
|
11495 | } else if (b === 0x08) {
|
11496 |
|
11497 | service.currentWindow.backspace();
|
11498 | } else if (b === 0x0c) {
|
11499 |
|
11500 | service.currentWindow.clearText();
|
11501 | } else if (b === 0x0d) {
|
11502 |
|
11503 | service.currentWindow.pendingNewLine = true;
|
11504 | } else if (b === 0x0e) {
|
11505 |
|
11506 | service.currentWindow.clearText();
|
11507 | } else if (b === 0x8d) {
|
11508 |
|
11509 | i++;
|
11510 | } else ;
|
11511 | }
|
11512 | };
|
11513 | |
11514 |
|
11515 |
|
11516 |
|
11517 |
|
11518 |
|
11519 |
|
11520 |
|
11521 |
|
11522 | Cea708Stream.prototype.extendedCommands = function (i, service) {
|
11523 | var packetData = this.current708Packet.data;
|
11524 | var b = packetData[++i];
|
11525 |
|
11526 | if (within708TextBlock(b)) {
|
11527 | i = this.handleText(i, service, {
|
11528 | isExtended: true
|
11529 | });
|
11530 | }
|
11531 |
|
11532 | return i;
|
11533 | };
|
11534 | |
11535 |
|
11536 |
|
11537 |
|
11538 |
|
11539 |
|
11540 |
|
11541 |
|
11542 | Cea708Stream.prototype.getPts = function (byteIndex) {
|
11543 |
|
11544 | return this.current708Packet.ptsVals[Math.floor(byteIndex / 2)];
|
11545 | };
|
11546 | |
11547 |
|
11548 |
|
11549 |
|
11550 |
|
11551 |
|
11552 |
|
11553 |
|
11554 | Cea708Stream.prototype.initService = function (serviceNum, i) {
|
11555 | var serviceName = 'SERVICE' + serviceNum;
|
11556 | var self = this;
|
11557 | var serviceName;
|
11558 | var encoding;
|
11559 |
|
11560 | if (serviceName in this.serviceEncodings) {
|
11561 | encoding = this.serviceEncodings[serviceName];
|
11562 | }
|
11563 |
|
11564 | this.services[serviceNum] = new Cea708Service(serviceNum, encoding, self);
|
11565 | this.services[serviceNum].init(this.getPts(i), function (pts) {
|
11566 | self.flushDisplayed(pts, self.services[serviceNum]);
|
11567 | });
|
11568 | return this.services[serviceNum];
|
11569 | };
|
11570 | |
11571 |
|
11572 |
|
11573 |
|
11574 |
|
11575 |
|
11576 |
|
11577 |
|
11578 |
|
11579 | Cea708Stream.prototype.handleText = function (i, service, options) {
|
11580 | var isExtended = options && options.isExtended;
|
11581 | var isMultiByte = options && options.isMultiByte;
|
11582 | var packetData = this.current708Packet.data;
|
11583 | var extended = isExtended ? 0x1000 : 0x0000;
|
11584 | var currentByte = packetData[i];
|
11585 | var nextByte = packetData[i + 1];
|
11586 | var win = service.currentWindow;
|
11587 | var char;
|
11588 | var charCodeArray;
|
11589 |
|
11590 | if (service.textDecoder_ && !isExtended) {
|
11591 | if (isMultiByte) {
|
11592 | charCodeArray = [currentByte, nextByte];
|
11593 | i++;
|
11594 | } else {
|
11595 | charCodeArray = [currentByte];
|
11596 | }
|
11597 |
|
11598 | char = service.textDecoder_.decode(new Uint8Array(charCodeArray));
|
11599 | } else {
|
11600 | char = get708CharFromCode(extended | currentByte);
|
11601 | }
|
11602 |
|
11603 | if (win.pendingNewLine && !win.isEmpty()) {
|
11604 | win.newLine(this.getPts(i));
|
11605 | }
|
11606 |
|
11607 | win.pendingNewLine = false;
|
11608 | win.addText(char);
|
11609 | return i;
|
11610 | };
|
11611 | |
11612 |
|
11613 |
|
11614 |
|
11615 |
|
11616 |
|
11617 |
|
11618 |
|
11619 |
|
11620 | Cea708Stream.prototype.multiByteCharacter = function (i, service) {
|
11621 | var packetData = this.current708Packet.data;
|
11622 | var firstByte = packetData[i + 1];
|
11623 | var secondByte = packetData[i + 2];
|
11624 |
|
11625 | if (within708TextBlock(firstByte) && within708TextBlock(secondByte)) {
|
11626 | i = this.handleText(++i, service, {
|
11627 | isMultiByte: true
|
11628 | });
|
11629 | }
|
11630 |
|
11631 | return i;
|
11632 | };
|
11633 | |
11634 |
|
11635 |
|
11636 |
|
11637 |
|
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 |
|
11643 |
|
11644 | Cea708Stream.prototype.setCurrentWindow = function (i, service) {
|
11645 | var packetData = this.current708Packet.data;
|
11646 | var b = packetData[i];
|
11647 | var windowNum = b & 0x07;
|
11648 | service.setCurrentWindow(windowNum);
|
11649 | return i;
|
11650 | };
|
11651 | |
11652 |
|
11653 |
|
11654 |
|
11655 |
|
11656 |
|
11657 |
|
11658 |
|
11659 |
|
11660 |
|
11661 |
|
11662 | Cea708Stream.prototype.defineWindow = function (i, service) {
|
11663 | var packetData = this.current708Packet.data;
|
11664 | var b = packetData[i];
|
11665 | var windowNum = b & 0x07;
|
11666 | service.setCurrentWindow(windowNum);
|
11667 | var win = service.currentWindow;
|
11668 | b = packetData[++i];
|
11669 | win.visible = (b & 0x20) >> 5;
|
11670 |
|
11671 | win.rowLock = (b & 0x10) >> 4;
|
11672 |
|
11673 | win.columnLock = (b & 0x08) >> 3;
|
11674 |
|
11675 | win.priority = b & 0x07;
|
11676 |
|
11677 | b = packetData[++i];
|
11678 | win.relativePositioning = (b & 0x80) >> 7;
|
11679 |
|
11680 | win.anchorVertical = b & 0x7f;
|
11681 |
|
11682 | b = packetData[++i];
|
11683 | win.anchorHorizontal = b;
|
11684 |
|
11685 | b = packetData[++i];
|
11686 | win.anchorPoint = (b & 0xf0) >> 4;
|
11687 |
|
11688 | win.rowCount = b & 0x0f;
|
11689 |
|
11690 | b = packetData[++i];
|
11691 | win.columnCount = b & 0x3f;
|
11692 |
|
11693 | b = packetData[++i];
|
11694 | win.windowStyle = (b & 0x38) >> 3;
|
11695 |
|
11696 | win.penStyle = b & 0x07;
|
11697 |
|
11698 |
|
11699 | win.virtualRowCount = win.rowCount + 1;
|
11700 | return i;
|
11701 | };
|
11702 | |
11703 |
|
11704 |
|
11705 |
|
11706 |
|
11707 |
|
11708 |
|
11709 |
|
11710 |
|
11711 |
|
11712 |
|
11713 | Cea708Stream.prototype.setWindowAttributes = function (i, service) {
|
11714 | var packetData = this.current708Packet.data;
|
11715 | var b = packetData[i];
|
11716 | var winAttr = service.currentWindow.winAttr;
|
11717 | b = packetData[++i];
|
11718 | winAttr.fillOpacity = (b & 0xc0) >> 6;
|
11719 |
|
11720 | winAttr.fillRed = (b & 0x30) >> 4;
|
11721 |
|
11722 | winAttr.fillGreen = (b & 0x0c) >> 2;
|
11723 |
|
11724 | winAttr.fillBlue = b & 0x03;
|
11725 |
|
11726 | b = packetData[++i];
|
11727 | winAttr.borderType = (b & 0xc0) >> 6;
|
11728 |
|
11729 | winAttr.borderRed = (b & 0x30) >> 4;
|
11730 |
|
11731 | winAttr.borderGreen = (b & 0x0c) >> 2;
|
11732 |
|
11733 | winAttr.borderBlue = b & 0x03;
|
11734 |
|
11735 | b = packetData[++i];
|
11736 | winAttr.borderType += (b & 0x80) >> 5;
|
11737 |
|
11738 | winAttr.wordWrap = (b & 0x40) >> 6;
|
11739 |
|
11740 | winAttr.printDirection = (b & 0x30) >> 4;
|
11741 |
|
11742 | winAttr.scrollDirection = (b & 0x0c) >> 2;
|
11743 |
|
11744 | winAttr.justify = b & 0x03;
|
11745 |
|
11746 | b = packetData[++i];
|
11747 | winAttr.effectSpeed = (b & 0xf0) >> 4;
|
11748 |
|
11749 | winAttr.effectDirection = (b & 0x0c) >> 2;
|
11750 |
|
11751 | winAttr.displayEffect = b & 0x03;
|
11752 |
|
11753 | return i;
|
11754 | };
|
11755 | |
11756 |
|
11757 |
|
11758 |
|
11759 |
|
11760 |
|
11761 |
|
11762 |
|
11763 | Cea708Stream.prototype.flushDisplayed = function (pts, service) {
|
11764 | var displayedText = [];
|
11765 |
|
11766 |
|
11767 | for (var winId = 0; winId < 8; winId++) {
|
11768 | if (service.windows[winId].visible && !service.windows[winId].isEmpty()) {
|
11769 | displayedText.push(service.windows[winId].getText());
|
11770 | }
|
11771 | }
|
11772 |
|
11773 | service.endPts = pts;
|
11774 | service.text = displayedText.join('\n\n');
|
11775 | this.pushCaption(service);
|
11776 | service.startPts = pts;
|
11777 | };
|
11778 | |
11779 |
|
11780 |
|
11781 |
|
11782 |
|
11783 |
|
11784 |
|
11785 | Cea708Stream.prototype.pushCaption = function (service) {
|
11786 | if (service.text !== '') {
|
11787 | this.trigger('data', {
|
11788 | startPts: service.startPts,
|
11789 | endPts: service.endPts,
|
11790 | text: service.text,
|
11791 | stream: 'cc708_' + service.serviceNum
|
11792 | });
|
11793 | service.text = '';
|
11794 | service.startPts = service.endPts;
|
11795 | }
|
11796 | };
|
11797 | |
11798 |
|
11799 |
|
11800 |
|
11801 |
|
11802 |
|
11803 |
|
11804 |
|
11805 |
|
11806 |
|
11807 |
|
11808 | Cea708Stream.prototype.displayWindows = function (i, service) {
|
11809 | var packetData = this.current708Packet.data;
|
11810 | var b = packetData[++i];
|
11811 | var pts = this.getPts(i);
|
11812 | this.flushDisplayed(pts, service);
|
11813 |
|
11814 | for (var winId = 0; winId < 8; winId++) {
|
11815 | if (b & 0x01 << winId) {
|
11816 | service.windows[winId].visible = 1;
|
11817 | }
|
11818 | }
|
11819 |
|
11820 | return i;
|
11821 | };
|
11822 | |
11823 |
|
11824 |
|
11825 |
|
11826 |
|
11827 |
|
11828 |
|
11829 |
|
11830 |
|
11831 |
|
11832 |
|
11833 | Cea708Stream.prototype.hideWindows = function (i, service) {
|
11834 | var packetData = this.current708Packet.data;
|
11835 | var b = packetData[++i];
|
11836 | var pts = this.getPts(i);
|
11837 | this.flushDisplayed(pts, service);
|
11838 |
|
11839 | for (var winId = 0; winId < 8; winId++) {
|
11840 | if (b & 0x01 << winId) {
|
11841 | service.windows[winId].visible = 0;
|
11842 | }
|
11843 | }
|
11844 |
|
11845 | return i;
|
11846 | };
|
11847 | |
11848 |
|
11849 |
|
11850 |
|
11851 |
|
11852 |
|
11853 |
|
11854 |
|
11855 |
|
11856 |
|
11857 |
|
11858 | Cea708Stream.prototype.toggleWindows = function (i, service) {
|
11859 | var packetData = this.current708Packet.data;
|
11860 | var b = packetData[++i];
|
11861 | var pts = this.getPts(i);
|
11862 | this.flushDisplayed(pts, service);
|
11863 |
|
11864 | for (var winId = 0; winId < 8; winId++) {
|
11865 | if (b & 0x01 << winId) {
|
11866 | service.windows[winId].visible ^= 1;
|
11867 | }
|
11868 | }
|
11869 |
|
11870 | return i;
|
11871 | };
|
11872 | |
11873 |
|
11874 |
|
11875 |
|
11876 |
|
11877 |
|
11878 |
|
11879 |
|
11880 |
|
11881 |
|
11882 |
|
11883 | Cea708Stream.prototype.clearWindows = function (i, service) {
|
11884 | var packetData = this.current708Packet.data;
|
11885 | var b = packetData[++i];
|
11886 | var pts = this.getPts(i);
|
11887 | this.flushDisplayed(pts, service);
|
11888 |
|
11889 | for (var winId = 0; winId < 8; winId++) {
|
11890 | if (b & 0x01 << winId) {
|
11891 | service.windows[winId].clearText();
|
11892 | }
|
11893 | }
|
11894 |
|
11895 | return i;
|
11896 | };
|
11897 | |
11898 |
|
11899 |
|
11900 |
|
11901 |
|
11902 |
|
11903 |
|
11904 |
|
11905 |
|
11906 |
|
11907 |
|
11908 | Cea708Stream.prototype.deleteWindows = function (i, service) {
|
11909 | var packetData = this.current708Packet.data;
|
11910 | var b = packetData[++i];
|
11911 | var pts = this.getPts(i);
|
11912 | this.flushDisplayed(pts, service);
|
11913 |
|
11914 | for (var winId = 0; winId < 8; winId++) {
|
11915 | if (b & 0x01 << winId) {
|
11916 | service.windows[winId].reset();
|
11917 | }
|
11918 | }
|
11919 |
|
11920 | return i;
|
11921 | };
|
11922 | |
11923 |
|
11924 |
|
11925 |
|
11926 |
|
11927 |
|
11928 |
|
11929 |
|
11930 |
|
11931 |
|
11932 |
|
11933 | Cea708Stream.prototype.setPenAttributes = function (i, service) {
|
11934 | var packetData = this.current708Packet.data;
|
11935 | var b = packetData[i];
|
11936 | var penAttr = service.currentWindow.penAttr;
|
11937 | b = packetData[++i];
|
11938 | penAttr.textTag = (b & 0xf0) >> 4;
|
11939 |
|
11940 | penAttr.offset = (b & 0x0c) >> 2;
|
11941 |
|
11942 | penAttr.penSize = b & 0x03;
|
11943 |
|
11944 | b = packetData[++i];
|
11945 | penAttr.italics = (b & 0x80) >> 7;
|
11946 |
|
11947 | penAttr.underline = (b & 0x40) >> 6;
|
11948 |
|
11949 | penAttr.edgeType = (b & 0x38) >> 3;
|
11950 |
|
11951 | penAttr.fontStyle = b & 0x07;
|
11952 |
|
11953 | return i;
|
11954 | };
|
11955 | |
11956 |
|
11957 |
|
11958 |
|
11959 |
|
11960 |
|
11961 |
|
11962 |
|
11963 |
|
11964 |
|
11965 |
|
11966 | Cea708Stream.prototype.setPenColor = function (i, service) {
|
11967 | var packetData = this.current708Packet.data;
|
11968 | var b = packetData[i];
|
11969 | var penColor = service.currentWindow.penColor;
|
11970 | b = packetData[++i];
|
11971 | penColor.fgOpacity = (b & 0xc0) >> 6;
|
11972 |
|
11973 | penColor.fgRed = (b & 0x30) >> 4;
|
11974 |
|
11975 | penColor.fgGreen = (b & 0x0c) >> 2;
|
11976 |
|
11977 | penColor.fgBlue = b & 0x03;
|
11978 |
|
11979 | b = packetData[++i];
|
11980 | penColor.bgOpacity = (b & 0xc0) >> 6;
|
11981 |
|
11982 | penColor.bgRed = (b & 0x30) >> 4;
|
11983 |
|
11984 | penColor.bgGreen = (b & 0x0c) >> 2;
|
11985 |
|
11986 | penColor.bgBlue = b & 0x03;
|
11987 |
|
11988 | b = packetData[++i];
|
11989 | penColor.edgeRed = (b & 0x30) >> 4;
|
11990 |
|
11991 | penColor.edgeGreen = (b & 0x0c) >> 2;
|
11992 |
|
11993 | penColor.edgeBlue = b & 0x03;
|
11994 |
|
11995 | return i;
|
11996 | };
|
11997 | |
11998 |
|
11999 |
|
12000 |
|
12001 |
|
12002 |
|
12003 |
|
12004 |
|
12005 |
|
12006 |
|
12007 |
|
12008 | Cea708Stream.prototype.setPenLocation = function (i, service) {
|
12009 | var packetData = this.current708Packet.data;
|
12010 | var b = packetData[i];
|
12011 | var penLoc = service.currentWindow.penLoc;
|
12012 |
|
12013 | service.currentWindow.pendingNewLine = true;
|
12014 | b = packetData[++i];
|
12015 | penLoc.row = b & 0x0f;
|
12016 |
|
12017 | b = packetData[++i];
|
12018 | penLoc.column = b & 0x3f;
|
12019 |
|
12020 | return i;
|
12021 | };
|
12022 | |
12023 |
|
12024 |
|
12025 |
|
12026 |
|
12027 |
|
12028 |
|
12029 |
|
12030 |
|
12031 |
|
12032 |
|
12033 | Cea708Stream.prototype.reset = function (i, service) {
|
12034 | var pts = this.getPts(i);
|
12035 | this.flushDisplayed(pts, service);
|
12036 | return this.initService(service.serviceNum, i);
|
12037 | };
|
12038 |
|
12039 |
|
12040 |
|
12041 |
|
12042 |
|
12043 |
|
12044 |
|
12045 |
|
12046 | var CHARACTER_TRANSLATION = {
|
12047 | 0x2a: 0xe1,
|
12048 |
|
12049 | 0x5c: 0xe9,
|
12050 |
|
12051 | 0x5e: 0xed,
|
12052 |
|
12053 | 0x5f: 0xf3,
|
12054 |
|
12055 | 0x60: 0xfa,
|
12056 |
|
12057 | 0x7b: 0xe7,
|
12058 |
|
12059 | 0x7c: 0xf7,
|
12060 |
|
12061 | 0x7d: 0xd1,
|
12062 |
|
12063 | 0x7e: 0xf1,
|
12064 |
|
12065 | 0x7f: 0x2588,
|
12066 |
|
12067 | 0x0130: 0xae,
|
12068 |
|
12069 | 0x0131: 0xb0,
|
12070 |
|
12071 | 0x0132: 0xbd,
|
12072 |
|
12073 | 0x0133: 0xbf,
|
12074 |
|
12075 | 0x0134: 0x2122,
|
12076 |
|
12077 | 0x0135: 0xa2,
|
12078 |
|
12079 | 0x0136: 0xa3,
|
12080 |
|
12081 | 0x0137: 0x266a,
|
12082 |
|
12083 | 0x0138: 0xe0,
|
12084 |
|
12085 | 0x0139: 0xa0,
|
12086 |
|
12087 | 0x013a: 0xe8,
|
12088 |
|
12089 | 0x013b: 0xe2,
|
12090 |
|
12091 | 0x013c: 0xea,
|
12092 |
|
12093 | 0x013d: 0xee,
|
12094 |
|
12095 | 0x013e: 0xf4,
|
12096 |
|
12097 | 0x013f: 0xfb,
|
12098 |
|
12099 | 0x0220: 0xc1,
|
12100 |
|
12101 | 0x0221: 0xc9,
|
12102 |
|
12103 | 0x0222: 0xd3,
|
12104 |
|
12105 | 0x0223: 0xda,
|
12106 |
|
12107 | 0x0224: 0xdc,
|
12108 |
|
12109 | 0x0225: 0xfc,
|
12110 |
|
12111 | 0x0226: 0x2018,
|
12112 |
|
12113 | 0x0227: 0xa1,
|
12114 |
|
12115 | 0x0228: 0x2a,
|
12116 |
|
12117 | 0x0229: 0x27,
|
12118 |
|
12119 | 0x022a: 0x2014,
|
12120 |
|
12121 | 0x022b: 0xa9,
|
12122 |
|
12123 | 0x022c: 0x2120,
|
12124 |
|
12125 | 0x022d: 0x2022,
|
12126 |
|
12127 | 0x022e: 0x201c,
|
12128 |
|
12129 | 0x022f: 0x201d,
|
12130 |
|
12131 | 0x0230: 0xc0,
|
12132 |
|
12133 | 0x0231: 0xc2,
|
12134 |
|
12135 | 0x0232: 0xc7,
|
12136 |
|
12137 | 0x0233: 0xc8,
|
12138 |
|
12139 | 0x0234: 0xca,
|
12140 |
|
12141 | 0x0235: 0xcb,
|
12142 |
|
12143 | 0x0236: 0xeb,
|
12144 |
|
12145 | 0x0237: 0xce,
|
12146 |
|
12147 | 0x0238: 0xcf,
|
12148 |
|
12149 | 0x0239: 0xef,
|
12150 |
|
12151 | 0x023a: 0xd4,
|
12152 |
|
12153 | 0x023b: 0xd9,
|
12154 |
|
12155 | 0x023c: 0xf9,
|
12156 |
|
12157 | 0x023d: 0xdb,
|
12158 |
|
12159 | 0x023e: 0xab,
|
12160 |
|
12161 | 0x023f: 0xbb,
|
12162 |
|
12163 | 0x0320: 0xc3,
|
12164 |
|
12165 | 0x0321: 0xe3,
|
12166 |
|
12167 | 0x0322: 0xcd,
|
12168 |
|
12169 | 0x0323: 0xcc,
|
12170 |
|
12171 | 0x0324: 0xec,
|
12172 |
|
12173 | 0x0325: 0xd2,
|
12174 |
|
12175 | 0x0326: 0xf2,
|
12176 |
|
12177 | 0x0327: 0xd5,
|
12178 |
|
12179 | 0x0328: 0xf5,
|
12180 |
|
12181 | 0x0329: 0x7b,
|
12182 |
|
12183 | 0x032a: 0x7d,
|
12184 |
|
12185 | 0x032b: 0x5c,
|
12186 |
|
12187 | 0x032c: 0x5e,
|
12188 |
|
12189 | 0x032d: 0x5f,
|
12190 |
|
12191 | 0x032e: 0x7c,
|
12192 |
|
12193 | 0x032f: 0x7e,
|
12194 |
|
12195 | 0x0330: 0xc4,
|
12196 |
|
12197 | 0x0331: 0xe4,
|
12198 |
|
12199 | 0x0332: 0xd6,
|
12200 |
|
12201 | 0x0333: 0xf6,
|
12202 |
|
12203 | 0x0334: 0xdf,
|
12204 |
|
12205 | 0x0335: 0xa5,
|
12206 |
|
12207 | 0x0336: 0xa4,
|
12208 |
|
12209 | 0x0337: 0x2502,
|
12210 |
|
12211 | 0x0338: 0xc5,
|
12212 |
|
12213 | 0x0339: 0xe5,
|
12214 |
|
12215 | 0x033a: 0xd8,
|
12216 |
|
12217 | 0x033b: 0xf8,
|
12218 |
|
12219 | 0x033c: 0x250c,
|
12220 |
|
12221 | 0x033d: 0x2510,
|
12222 |
|
12223 | 0x033e: 0x2514,
|
12224 |
|
12225 | 0x033f: 0x2518
|
12226 |
|
12227 | };
|
12228 |
|
12229 | var getCharFromCode = function getCharFromCode(code) {
|
12230 | if (code === null) {
|
12231 | return '';
|
12232 | }
|
12233 |
|
12234 | code = CHARACTER_TRANSLATION[code] || code;
|
12235 | return String.fromCharCode(code);
|
12236 | };
|
12237 |
|
12238 |
|
12239 | var BOTTOM_ROW = 14;
|
12240 |
|
12241 |
|
12242 | var ROWS = [0x1100, 0x1120, 0x1200, 0x1220, 0x1500, 0x1520, 0x1600, 0x1620, 0x1700, 0x1720, 0x1000, 0x1300, 0x1320, 0x1400, 0x1420];
|
12243 |
|
12244 |
|
12245 | var createDisplayBuffer = function createDisplayBuffer() {
|
12246 | var result = [],
|
12247 | i = BOTTOM_ROW + 1;
|
12248 |
|
12249 | while (i--) {
|
12250 | result.push('');
|
12251 | }
|
12252 |
|
12253 | return result;
|
12254 | };
|
12255 |
|
12256 | var Cea608Stream = function Cea608Stream(field, dataChannel) {
|
12257 | Cea608Stream.prototype.init.call(this);
|
12258 | this.field_ = field || 0;
|
12259 | this.dataChannel_ = dataChannel || 0;
|
12260 | this.name_ = 'CC' + ((this.field_ << 1 | this.dataChannel_) + 1);
|
12261 | this.setConstants();
|
12262 | this.reset();
|
12263 |
|
12264 | this.push = function (packet) {
|
12265 | var data, swap, char0, char1, text;
|
12266 |
|
12267 | data = packet.ccData & 0x7f7f;
|
12268 |
|
12269 | if (data === this.lastControlCode_) {
|
12270 | this.lastControlCode_ = null;
|
12271 | return;
|
12272 | }
|
12273 |
|
12274 |
|
12275 | if ((data & 0xf000) === 0x1000) {
|
12276 | this.lastControlCode_ = data;
|
12277 | } else if (data !== this.PADDING_) {
|
12278 | this.lastControlCode_ = null;
|
12279 | }
|
12280 |
|
12281 | char0 = data >>> 8;
|
12282 | char1 = data & 0xff;
|
12283 |
|
12284 | if (data === this.PADDING_) {
|
12285 | return;
|
12286 | } else if (data === this.RESUME_CAPTION_LOADING_) {
|
12287 | this.mode_ = 'popOn';
|
12288 | } else if (data === this.END_OF_CAPTION_) {
|
12289 |
|
12290 |
|
12291 |
|
12292 |
|
12293 | this.mode_ = 'popOn';
|
12294 | this.clearFormatting(packet.pts);
|
12295 |
|
12296 | this.flushDisplayed(packet.pts);
|
12297 |
|
12298 | swap = this.displayed_;
|
12299 | this.displayed_ = this.nonDisplayed_;
|
12300 | this.nonDisplayed_ = swap;
|
12301 |
|
12302 | this.startPts_ = packet.pts;
|
12303 | } else if (data === this.ROLL_UP_2_ROWS_) {
|
12304 | this.rollUpRows_ = 2;
|
12305 | this.setRollUp(packet.pts);
|
12306 | } else if (data === this.ROLL_UP_3_ROWS_) {
|
12307 | this.rollUpRows_ = 3;
|
12308 | this.setRollUp(packet.pts);
|
12309 | } else if (data === this.ROLL_UP_4_ROWS_) {
|
12310 | this.rollUpRows_ = 4;
|
12311 | this.setRollUp(packet.pts);
|
12312 | } else if (data === this.CARRIAGE_RETURN_) {
|
12313 | this.clearFormatting(packet.pts);
|
12314 | this.flushDisplayed(packet.pts);
|
12315 | this.shiftRowsUp_();
|
12316 | this.startPts_ = packet.pts;
|
12317 | } else if (data === this.BACKSPACE_) {
|
12318 | if (this.mode_ === 'popOn') {
|
12319 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
12320 | } else {
|
12321 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
12322 | }
|
12323 | } else if (data === this.ERASE_DISPLAYED_MEMORY_) {
|
12324 | this.flushDisplayed(packet.pts);
|
12325 | this.displayed_ = createDisplayBuffer();
|
12326 | } else if (data === this.ERASE_NON_DISPLAYED_MEMORY_) {
|
12327 | this.nonDisplayed_ = createDisplayBuffer();
|
12328 | } else if (data === this.RESUME_DIRECT_CAPTIONING_) {
|
12329 | if (this.mode_ !== 'paintOn') {
|
12330 |
|
12331 |
|
12332 | this.flushDisplayed(packet.pts);
|
12333 | this.displayed_ = createDisplayBuffer();
|
12334 | }
|
12335 |
|
12336 | this.mode_ = 'paintOn';
|
12337 | this.startPts_ = packet.pts;
|
12338 | } else if (this.isSpecialCharacter(char0, char1)) {
|
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 | char0 = (char0 & 0x03) << 8;
|
12344 | text = getCharFromCode(char0 | char1);
|
12345 | this[this.mode_](packet.pts, text);
|
12346 | this.column_++;
|
12347 | } else if (this.isExtCharacter(char0, char1)) {
|
12348 |
|
12349 |
|
12350 |
|
12351 |
|
12352 |
|
12353 | if (this.mode_ === 'popOn') {
|
12354 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
12355 | } else {
|
12356 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
12357 | }
|
12358 |
|
12359 |
|
12360 |
|
12361 |
|
12362 |
|
12363 | char0 = (char0 & 0x03) << 8;
|
12364 | text = getCharFromCode(char0 | char1);
|
12365 | this[this.mode_](packet.pts, text);
|
12366 | this.column_++;
|
12367 | } else if (this.isMidRowCode(char0, char1)) {
|
12368 |
|
12369 | this.clearFormatting(packet.pts);
|
12370 |
|
12371 |
|
12372 | this[this.mode_](packet.pts, ' ');
|
12373 | this.column_++;
|
12374 |
|
12375 | if ((char1 & 0xe) === 0xe) {
|
12376 | this.addFormatting(packet.pts, ['i']);
|
12377 | }
|
12378 |
|
12379 | if ((char1 & 0x1) === 0x1) {
|
12380 | this.addFormatting(packet.pts, ['u']);
|
12381 | }
|
12382 |
|
12383 | } else if (this.isOffsetControlCode(char0, char1)) {
|
12384 |
|
12385 |
|
12386 |
|
12387 |
|
12388 | this.column_ += char1 & 0x03;
|
12389 | } else if (this.isPAC(char0, char1)) {
|
12390 |
|
12391 |
|
12392 | var row = ROWS.indexOf(data & 0x1f20);
|
12393 |
|
12394 | if (this.mode_ === 'rollUp') {
|
12395 |
|
12396 |
|
12397 |
|
12398 | if (row - this.rollUpRows_ + 1 < 0) {
|
12399 | row = this.rollUpRows_ - 1;
|
12400 | }
|
12401 |
|
12402 | this.setRollUp(packet.pts, row);
|
12403 | }
|
12404 |
|
12405 | if (row !== this.row_) {
|
12406 |
|
12407 | this.clearFormatting(packet.pts);
|
12408 | this.row_ = row;
|
12409 | }
|
12410 |
|
12411 |
|
12412 |
|
12413 | if (char1 & 0x1 && this.formatting_.indexOf('u') === -1) {
|
12414 | this.addFormatting(packet.pts, ['u']);
|
12415 | }
|
12416 |
|
12417 | if ((data & 0x10) === 0x10) {
|
12418 |
|
12419 |
|
12420 |
|
12421 |
|
12422 | this.column_ = ((data & 0xe) >> 1) * 4;
|
12423 | }
|
12424 |
|
12425 | if (this.isColorPAC(char1)) {
|
12426 |
|
12427 |
|
12428 |
|
12429 |
|
12430 | if ((char1 & 0xe) === 0xe) {
|
12431 | this.addFormatting(packet.pts, ['i']);
|
12432 | }
|
12433 | }
|
12434 |
|
12435 | } else if (this.isNormalChar(char0)) {
|
12436 | if (char1 === 0x00) {
|
12437 | char1 = null;
|
12438 | }
|
12439 |
|
12440 | text = getCharFromCode(char0);
|
12441 | text += getCharFromCode(char1);
|
12442 | this[this.mode_](packet.pts, text);
|
12443 | this.column_ += text.length;
|
12444 | }
|
12445 |
|
12446 | };
|
12447 | };
|
12448 |
|
12449 | Cea608Stream.prototype = new stream();
|
12450 |
|
12451 |
|
12452 | Cea608Stream.prototype.flushDisplayed = function (pts) {
|
12453 | var content = this.displayed_
|
12454 | .map(function (row, index) {
|
12455 | try {
|
12456 | return row.trim();
|
12457 | } catch (e) {
|
12458 |
|
12459 |
|
12460 |
|
12461 | this.trigger('log', {
|
12462 | level: 'warn',
|
12463 | message: 'Skipping a malformed 608 caption at index ' + index + '.'
|
12464 | });
|
12465 | return '';
|
12466 | }
|
12467 | }, this)
|
12468 | .join('\n')
|
12469 | .replace(/^\n+|\n+$/g, '');
|
12470 |
|
12471 | if (content.length) {
|
12472 | this.trigger('data', {
|
12473 | startPts: this.startPts_,
|
12474 | endPts: pts,
|
12475 | text: content,
|
12476 | stream: this.name_
|
12477 | });
|
12478 | }
|
12479 | };
|
12480 | |
12481 |
|
12482 |
|
12483 |
|
12484 |
|
12485 | Cea608Stream.prototype.reset = function () {
|
12486 | this.mode_ = 'popOn';
|
12487 |
|
12488 |
|
12489 |
|
12490 |
|
12491 | this.topRow_ = 0;
|
12492 | this.startPts_ = 0;
|
12493 | this.displayed_ = createDisplayBuffer();
|
12494 | this.nonDisplayed_ = createDisplayBuffer();
|
12495 | this.lastControlCode_ = null;
|
12496 |
|
12497 | this.column_ = 0;
|
12498 | this.row_ = BOTTOM_ROW;
|
12499 | this.rollUpRows_ = 2;
|
12500 |
|
12501 | this.formatting_ = [];
|
12502 | };
|
12503 | |
12504 |
|
12505 |
|
12506 |
|
12507 |
|
12508 | Cea608Stream.prototype.setConstants = function () {
|
12509 |
|
12510 |
|
12511 |
|
12512 |
|
12513 |
|
12514 |
|
12515 |
|
12516 |
|
12517 |
|
12518 |
|
12519 |
|
12520 |
|
12521 | if (this.dataChannel_ === 0) {
|
12522 | this.BASE_ = 0x10;
|
12523 | this.EXT_ = 0x11;
|
12524 | this.CONTROL_ = (0x14 | this.field_) << 8;
|
12525 | this.OFFSET_ = 0x17;
|
12526 | } else if (this.dataChannel_ === 1) {
|
12527 | this.BASE_ = 0x18;
|
12528 | this.EXT_ = 0x19;
|
12529 | this.CONTROL_ = (0x1c | this.field_) << 8;
|
12530 | this.OFFSET_ = 0x1f;
|
12531 | }
|
12532 |
|
12533 |
|
12534 |
|
12535 |
|
12536 |
|
12537 | this.PADDING_ = 0x0000;
|
12538 |
|
12539 | this.RESUME_CAPTION_LOADING_ = this.CONTROL_ | 0x20;
|
12540 | this.END_OF_CAPTION_ = this.CONTROL_ | 0x2f;
|
12541 |
|
12542 | this.ROLL_UP_2_ROWS_ = this.CONTROL_ | 0x25;
|
12543 | this.ROLL_UP_3_ROWS_ = this.CONTROL_ | 0x26;
|
12544 | this.ROLL_UP_4_ROWS_ = this.CONTROL_ | 0x27;
|
12545 | this.CARRIAGE_RETURN_ = this.CONTROL_ | 0x2d;
|
12546 |
|
12547 | this.RESUME_DIRECT_CAPTIONING_ = this.CONTROL_ | 0x29;
|
12548 |
|
12549 | this.BACKSPACE_ = this.CONTROL_ | 0x21;
|
12550 | this.ERASE_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2c;
|
12551 | this.ERASE_NON_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2e;
|
12552 | };
|
12553 | |
12554 |
|
12555 |
|
12556 |
|
12557 |
|
12558 |
|
12559 |
|
12560 |
|
12561 |
|
12562 |
|
12563 |
|
12564 |
|
12565 |
|
12566 | Cea608Stream.prototype.isSpecialCharacter = function (char0, char1) {
|
12567 | return char0 === this.EXT_ && char1 >= 0x30 && char1 <= 0x3f;
|
12568 | };
|
12569 | |
12570 |
|
12571 |
|
12572 |
|
12573 |
|
12574 |
|
12575 |
|
12576 |
|
12577 |
|
12578 |
|
12579 |
|
12580 |
|
12581 |
|
12582 | Cea608Stream.prototype.isExtCharacter = function (char0, char1) {
|
12583 | return (char0 === this.EXT_ + 1 || char0 === this.EXT_ + 2) && char1 >= 0x20 && char1 <= 0x3f;
|
12584 | };
|
12585 | |
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 |
|
12591 |
|
12592 |
|
12593 |
|
12594 |
|
12595 |
|
12596 |
|
12597 |
|
12598 | Cea608Stream.prototype.isMidRowCode = function (char0, char1) {
|
12599 | return char0 === this.EXT_ && char1 >= 0x20 && char1 <= 0x2f;
|
12600 | };
|
12601 | |
12602 |
|
12603 |
|
12604 |
|
12605 |
|
12606 |
|
12607 |
|
12608 |
|
12609 |
|
12610 |
|
12611 |
|
12612 |
|
12613 |
|
12614 | Cea608Stream.prototype.isOffsetControlCode = function (char0, char1) {
|
12615 | return char0 === this.OFFSET_ && char1 >= 0x21 && char1 <= 0x23;
|
12616 | };
|
12617 | |
12618 |
|
12619 |
|
12620 |
|
12621 |
|
12622 |
|
12623 |
|
12624 |
|
12625 |
|
12626 |
|
12627 |
|
12628 |
|
12629 |
|
12630 | Cea608Stream.prototype.isPAC = function (char0, char1) {
|
12631 | return char0 >= this.BASE_ && char0 < this.BASE_ + 8 && char1 >= 0x40 && char1 <= 0x7f;
|
12632 | };
|
12633 | |
12634 |
|
12635 |
|
12636 |
|
12637 |
|
12638 |
|
12639 |
|
12640 |
|
12641 |
|
12642 |
|
12643 |
|
12644 | Cea608Stream.prototype.isColorPAC = function (char1) {
|
12645 | return char1 >= 0x40 && char1 <= 0x4f || char1 >= 0x60 && char1 <= 0x7f;
|
12646 | };
|
12647 | |
12648 |
|
12649 |
|
12650 |
|
12651 |
|
12652 |
|
12653 |
|
12654 |
|
12655 |
|
12656 |
|
12657 | Cea608Stream.prototype.isNormalChar = function (char) {
|
12658 | return char >= 0x20 && char <= 0x7f;
|
12659 | };
|
12660 | |
12661 |
|
12662 |
|
12663 |
|
12664 |
|
12665 |
|
12666 |
|
12667 |
|
12668 |
|
12669 | Cea608Stream.prototype.setRollUp = function (pts, newBaseRow) {
|
12670 |
|
12671 | if (this.mode_ !== 'rollUp') {
|
12672 | this.row_ = BOTTOM_ROW;
|
12673 | this.mode_ = 'rollUp';
|
12674 |
|
12675 | this.flushDisplayed(pts);
|
12676 | this.nonDisplayed_ = createDisplayBuffer();
|
12677 | this.displayed_ = createDisplayBuffer();
|
12678 | }
|
12679 |
|
12680 | if (newBaseRow !== undefined && newBaseRow !== this.row_) {
|
12681 |
|
12682 | for (var i = 0; i < this.rollUpRows_; i++) {
|
12683 | this.displayed_[newBaseRow - i] = this.displayed_[this.row_ - i];
|
12684 | this.displayed_[this.row_ - i] = '';
|
12685 | }
|
12686 | }
|
12687 |
|
12688 | if (newBaseRow === undefined) {
|
12689 | newBaseRow = this.row_;
|
12690 | }
|
12691 |
|
12692 | this.topRow_ = newBaseRow - this.rollUpRows_ + 1;
|
12693 | };
|
12694 |
|
12695 |
|
12696 |
|
12697 | Cea608Stream.prototype.addFormatting = function (pts, format) {
|
12698 | this.formatting_ = this.formatting_.concat(format);
|
12699 | var text = format.reduce(function (text, format) {
|
12700 | return text + '<' + format + '>';
|
12701 | }, '');
|
12702 | this[this.mode_](pts, text);
|
12703 | };
|
12704 |
|
12705 |
|
12706 |
|
12707 | Cea608Stream.prototype.clearFormatting = function (pts) {
|
12708 | if (!this.formatting_.length) {
|
12709 | return;
|
12710 | }
|
12711 |
|
12712 | var text = this.formatting_.reverse().reduce(function (text, format) {
|
12713 | return text + '</' + format + '>';
|
12714 | }, '');
|
12715 | this.formatting_ = [];
|
12716 | this[this.mode_](pts, text);
|
12717 | };
|
12718 |
|
12719 |
|
12720 | Cea608Stream.prototype.popOn = function (pts, text) {
|
12721 | var baseRow = this.nonDisplayed_[this.row_];
|
12722 |
|
12723 | baseRow += text;
|
12724 | this.nonDisplayed_[this.row_] = baseRow;
|
12725 | };
|
12726 |
|
12727 | Cea608Stream.prototype.rollUp = function (pts, text) {
|
12728 | var baseRow = this.displayed_[this.row_];
|
12729 | baseRow += text;
|
12730 | this.displayed_[this.row_] = baseRow;
|
12731 | };
|
12732 |
|
12733 | Cea608Stream.prototype.shiftRowsUp_ = function () {
|
12734 | var i;
|
12735 |
|
12736 | for (i = 0; i < this.topRow_; i++) {
|
12737 | this.displayed_[i] = '';
|
12738 | }
|
12739 |
|
12740 | for (i = this.row_ + 1; i < BOTTOM_ROW + 1; i++) {
|
12741 | this.displayed_[i] = '';
|
12742 | }
|
12743 |
|
12744 |
|
12745 | for (i = this.topRow_; i < this.row_; i++) {
|
12746 | this.displayed_[i] = this.displayed_[i + 1];
|
12747 | }
|
12748 |
|
12749 |
|
12750 | this.displayed_[this.row_] = '';
|
12751 | };
|
12752 |
|
12753 | Cea608Stream.prototype.paintOn = function (pts, text) {
|
12754 | var baseRow = this.displayed_[this.row_];
|
12755 | baseRow += text;
|
12756 | this.displayed_[this.row_] = baseRow;
|
12757 | };
|
12758 |
|
12759 |
|
12760 | var captionStream = {
|
12761 | CaptionStream: CaptionStream$1,
|
12762 | Cea608Stream: Cea608Stream,
|
12763 | Cea708Stream: Cea708Stream
|
12764 | };
|
12765 | |
12766 |
|
12767 |
|
12768 |
|
12769 |
|
12770 |
|
12771 |
|
12772 | var streamTypes = {
|
12773 | H264_STREAM_TYPE: 0x1B,
|
12774 | ADTS_STREAM_TYPE: 0x0F,
|
12775 | METADATA_STREAM_TYPE: 0x15
|
12776 | };
|
12777 | var MAX_TS = 8589934592;
|
12778 | var RO_THRESH = 4294967296;
|
12779 | var TYPE_SHARED = 'shared';
|
12780 |
|
12781 | var handleRollover$1 = function handleRollover(value, reference) {
|
12782 | var direction = 1;
|
12783 |
|
12784 | if (value > reference) {
|
12785 |
|
12786 |
|
12787 |
|
12788 |
|
12789 |
|
12790 |
|
12791 |
|
12792 | direction = -1;
|
12793 | }
|
12794 |
|
12795 |
|
12796 |
|
12797 | while (Math.abs(reference - value) > RO_THRESH) {
|
12798 | value += direction * MAX_TS;
|
12799 | }
|
12800 |
|
12801 | return value;
|
12802 | };
|
12803 |
|
12804 | var TimestampRolloverStream$1 = function TimestampRolloverStream(type) {
|
12805 | var lastDTS, referenceDTS;
|
12806 | TimestampRolloverStream.prototype.init.call(this);
|
12807 |
|
12808 |
|
12809 |
|
12810 | this.type_ = type || TYPE_SHARED;
|
12811 |
|
12812 | this.push = function (data) {
|
12813 |
|
12814 |
|
12815 | if (this.type_ !== TYPE_SHARED && data.type !== this.type_) {
|
12816 | return;
|
12817 | }
|
12818 |
|
12819 | if (referenceDTS === undefined) {
|
12820 | referenceDTS = data.dts;
|
12821 | }
|
12822 |
|
12823 | data.dts = handleRollover$1(data.dts, referenceDTS);
|
12824 | data.pts = handleRollover$1(data.pts, referenceDTS);
|
12825 | lastDTS = data.dts;
|
12826 | this.trigger('data', data);
|
12827 | };
|
12828 |
|
12829 | this.flush = function () {
|
12830 | referenceDTS = lastDTS;
|
12831 | this.trigger('done');
|
12832 | };
|
12833 |
|
12834 | this.endTimeline = function () {
|
12835 | this.flush();
|
12836 | this.trigger('endedtimeline');
|
12837 | };
|
12838 |
|
12839 | this.discontinuity = function () {
|
12840 | referenceDTS = void 0;
|
12841 | lastDTS = void 0;
|
12842 | };
|
12843 |
|
12844 | this.reset = function () {
|
12845 | this.discontinuity();
|
12846 | this.trigger('reset');
|
12847 | };
|
12848 | };
|
12849 |
|
12850 | TimestampRolloverStream$1.prototype = new stream();
|
12851 | var timestampRolloverStream = {
|
12852 | TimestampRolloverStream: TimestampRolloverStream$1,
|
12853 | handleRollover: handleRollover$1
|
12854 | };
|
12855 |
|
12856 | var percentEncode$1 = function percentEncode(bytes, start, end) {
|
12857 | var i,
|
12858 | result = '';
|
12859 |
|
12860 | for (i = start; i < end; i++) {
|
12861 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
12862 | }
|
12863 |
|
12864 | return result;
|
12865 | },
|
12866 |
|
12867 |
|
12868 | parseUtf8 = function parseUtf8(bytes, start, end) {
|
12869 | return decodeURIComponent(percentEncode$1(bytes, start, end));
|
12870 | },
|
12871 |
|
12872 |
|
12873 | parseIso88591$1 = function parseIso88591(bytes, start, end) {
|
12874 | return unescape(percentEncode$1(bytes, start, end));
|
12875 | },
|
12876 | parseSyncSafeInteger$1 = function parseSyncSafeInteger(data) {
|
12877 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
12878 | },
|
12879 | tagParsers = {
|
12880 | TXXX: function TXXX(tag) {
|
12881 | var i;
|
12882 |
|
12883 | if (tag.data[0] !== 3) {
|
12884 |
|
12885 | return;
|
12886 | }
|
12887 |
|
12888 | for (i = 1; i < tag.data.length; i++) {
|
12889 | if (tag.data[i] === 0) {
|
12890 |
|
12891 | tag.description = parseUtf8(tag.data, 1, i);
|
12892 |
|
12893 | tag.value = parseUtf8(tag.data, i + 1, tag.data.length).replace(/\0*$/, '');
|
12894 | break;
|
12895 | }
|
12896 | }
|
12897 |
|
12898 | tag.data = tag.value;
|
12899 | },
|
12900 | WXXX: function WXXX(tag) {
|
12901 | var i;
|
12902 |
|
12903 | if (tag.data[0] !== 3) {
|
12904 |
|
12905 | return;
|
12906 | }
|
12907 |
|
12908 | for (i = 1; i < tag.data.length; i++) {
|
12909 | if (tag.data[i] === 0) {
|
12910 |
|
12911 | tag.description = parseUtf8(tag.data, 1, i);
|
12912 | tag.url = parseUtf8(tag.data, i + 1, tag.data.length);
|
12913 | break;
|
12914 | }
|
12915 | }
|
12916 | },
|
12917 | PRIV: function PRIV(tag) {
|
12918 | var i;
|
12919 |
|
12920 | for (i = 0; i < tag.data.length; i++) {
|
12921 | if (tag.data[i] === 0) {
|
12922 |
|
12923 | tag.owner = parseIso88591$1(tag.data, 0, i);
|
12924 | break;
|
12925 | }
|
12926 | }
|
12927 |
|
12928 | tag.privateData = tag.data.subarray(i + 1);
|
12929 | tag.data = tag.privateData;
|
12930 | }
|
12931 | },
|
12932 | _MetadataStream;
|
12933 |
|
12934 | _MetadataStream = function MetadataStream(options) {
|
12935 | var settings = {
|
12936 |
|
12937 |
|
12938 |
|
12939 | descriptor: options && options.descriptor
|
12940 | },
|
12941 |
|
12942 | tagSize = 0,
|
12943 |
|
12944 | buffer = [],
|
12945 |
|
12946 | bufferSize = 0,
|
12947 | i;
|
12948 |
|
12949 | _MetadataStream.prototype.init.call(this);
|
12950 |
|
12951 |
|
12952 |
|
12953 | this.dispatchType = streamTypes.METADATA_STREAM_TYPE.toString(16);
|
12954 |
|
12955 | if (settings.descriptor) {
|
12956 | for (i = 0; i < settings.descriptor.length; i++) {
|
12957 | this.dispatchType += ('00' + settings.descriptor[i].toString(16)).slice(-2);
|
12958 | }
|
12959 | }
|
12960 |
|
12961 | this.push = function (chunk) {
|
12962 | var tag, frameStart, frameSize, frame, i, frameHeader;
|
12963 |
|
12964 | if (chunk.type !== 'timed-metadata') {
|
12965 | return;
|
12966 | }
|
12967 |
|
12968 |
|
12969 |
|
12970 |
|
12971 | if (chunk.dataAlignmentIndicator) {
|
12972 | bufferSize = 0;
|
12973 | buffer.length = 0;
|
12974 | }
|
12975 |
|
12976 |
|
12977 | if (buffer.length === 0 && (chunk.data.length < 10 || chunk.data[0] !== 'I'.charCodeAt(0) || chunk.data[1] !== 'D'.charCodeAt(0) || chunk.data[2] !== '3'.charCodeAt(0))) {
|
12978 | this.trigger('log', {
|
12979 | level: 'warn',
|
12980 | message: 'Skipping unrecognized metadata packet'
|
12981 | });
|
12982 | return;
|
12983 | }
|
12984 |
|
12985 |
|
12986 | buffer.push(chunk);
|
12987 | bufferSize += chunk.data.byteLength;
|
12988 |
|
12989 | if (buffer.length === 1) {
|
12990 |
|
12991 |
|
12992 |
|
12993 |
|
12994 | tagSize = parseSyncSafeInteger$1(chunk.data.subarray(6, 10));
|
12995 |
|
12996 |
|
12997 | tagSize += 10;
|
12998 | }
|
12999 |
|
13000 |
|
13001 | if (bufferSize < tagSize) {
|
13002 | return;
|
13003 | }
|
13004 |
|
13005 |
|
13006 | tag = {
|
13007 | data: new Uint8Array(tagSize),
|
13008 | frames: [],
|
13009 | pts: buffer[0].pts,
|
13010 | dts: buffer[0].dts
|
13011 | };
|
13012 |
|
13013 | for (i = 0; i < tagSize;) {
|
13014 | tag.data.set(buffer[0].data.subarray(0, tagSize - i), i);
|
13015 | i += buffer[0].data.byteLength;
|
13016 | bufferSize -= buffer[0].data.byteLength;
|
13017 | buffer.shift();
|
13018 | }
|
13019 |
|
13020 |
|
13021 | frameStart = 10;
|
13022 |
|
13023 | if (tag.data[5] & 0x40) {
|
13024 |
|
13025 | frameStart += 4;
|
13026 |
|
13027 | frameStart += parseSyncSafeInteger$1(tag.data.subarray(10, 14));
|
13028 |
|
13029 | tagSize -= parseSyncSafeInteger$1(tag.data.subarray(16, 20));
|
13030 | }
|
13031 |
|
13032 |
|
13033 |
|
13034 | do {
|
13035 |
|
13036 | frameSize = parseSyncSafeInteger$1(tag.data.subarray(frameStart + 4, frameStart + 8));
|
13037 |
|
13038 | if (frameSize < 1) {
|
13039 | this.trigger('log', {
|
13040 | level: 'warn',
|
13041 | message: 'Malformed ID3 frame encountered. Skipping metadata parsing.'
|
13042 | });
|
13043 | return;
|
13044 | }
|
13045 |
|
13046 | frameHeader = String.fromCharCode(tag.data[frameStart], tag.data[frameStart + 1], tag.data[frameStart + 2], tag.data[frameStart + 3]);
|
13047 | frame = {
|
13048 | id: frameHeader,
|
13049 | data: tag.data.subarray(frameStart + 10, frameStart + frameSize + 10)
|
13050 | };
|
13051 | frame.key = frame.id;
|
13052 |
|
13053 | if (tagParsers[frame.id]) {
|
13054 | tagParsers[frame.id](frame);
|
13055 |
|
13056 |
|
13057 | if (frame.owner === 'com.apple.streaming.transportStreamTimestamp') {
|
13058 | var d = frame.data,
|
13059 | size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
13060 | size *= 4;
|
13061 | size += d[7] & 0x03;
|
13062 | frame.timeStamp = size;
|
13063 |
|
13064 |
|
13065 |
|
13066 |
|
13067 | if (tag.pts === undefined && tag.dts === undefined) {
|
13068 | tag.pts = frame.timeStamp;
|
13069 | tag.dts = frame.timeStamp;
|
13070 | }
|
13071 |
|
13072 | this.trigger('timestamp', frame);
|
13073 | }
|
13074 | }
|
13075 |
|
13076 | tag.frames.push(frame);
|
13077 | frameStart += 10;
|
13078 |
|
13079 | frameStart += frameSize;
|
13080 | } while (frameStart < tagSize);
|
13081 |
|
13082 | this.trigger('data', tag);
|
13083 | };
|
13084 | };
|
13085 |
|
13086 | _MetadataStream.prototype = new stream();
|
13087 | var metadataStream = _MetadataStream;
|
13088 | var TimestampRolloverStream = timestampRolloverStream.TimestampRolloverStream;
|
13089 |
|
13090 | var _TransportPacketStream, _TransportParseStream, _ElementaryStream;
|
13091 |
|
13092 |
|
13093 | var MP2T_PACKET_LENGTH$1 = 188,
|
13094 |
|
13095 | SYNC_BYTE$1 = 0x47;
|
13096 | |
13097 |
|
13098 |
|
13099 |
|
13100 |
|
13101 | _TransportPacketStream = function TransportPacketStream() {
|
13102 | var buffer = new Uint8Array(MP2T_PACKET_LENGTH$1),
|
13103 | bytesInBuffer = 0;
|
13104 |
|
13105 | _TransportPacketStream.prototype.init.call(this);
|
13106 |
|
13107 | |
13108 |
|
13109 |
|
13110 |
|
13111 |
|
13112 | this.push = function (bytes) {
|
13113 | var startIndex = 0,
|
13114 | endIndex = MP2T_PACKET_LENGTH$1,
|
13115 | everything;
|
13116 |
|
13117 |
|
13118 | if (bytesInBuffer) {
|
13119 | everything = new Uint8Array(bytes.byteLength + bytesInBuffer);
|
13120 | everything.set(buffer.subarray(0, bytesInBuffer));
|
13121 | everything.set(bytes, bytesInBuffer);
|
13122 | bytesInBuffer = 0;
|
13123 | } else {
|
13124 | everything = bytes;
|
13125 | }
|
13126 |
|
13127 |
|
13128 | while (endIndex < everything.byteLength) {
|
13129 |
|
13130 | if (everything[startIndex] === SYNC_BYTE$1 && everything[endIndex] === SYNC_BYTE$1) {
|
13131 |
|
13132 |
|
13133 | this.trigger('data', everything.subarray(startIndex, endIndex));
|
13134 | startIndex += MP2T_PACKET_LENGTH$1;
|
13135 | endIndex += MP2T_PACKET_LENGTH$1;
|
13136 | continue;
|
13137 | }
|
13138 |
|
13139 |
|
13140 |
|
13141 |
|
13142 | startIndex++;
|
13143 | endIndex++;
|
13144 | }
|
13145 |
|
13146 |
|
13147 |
|
13148 |
|
13149 | if (startIndex < everything.byteLength) {
|
13150 | buffer.set(everything.subarray(startIndex), 0);
|
13151 | bytesInBuffer = everything.byteLength - startIndex;
|
13152 | }
|
13153 | };
|
13154 | |
13155 |
|
13156 |
|
13157 |
|
13158 |
|
13159 | this.flush = function () {
|
13160 |
|
13161 |
|
13162 |
|
13163 | if (bytesInBuffer === MP2T_PACKET_LENGTH$1 && buffer[0] === SYNC_BYTE$1) {
|
13164 | this.trigger('data', buffer);
|
13165 | bytesInBuffer = 0;
|
13166 | }
|
13167 |
|
13168 | this.trigger('done');
|
13169 | };
|
13170 |
|
13171 | this.endTimeline = function () {
|
13172 | this.flush();
|
13173 | this.trigger('endedtimeline');
|
13174 | };
|
13175 |
|
13176 | this.reset = function () {
|
13177 | bytesInBuffer = 0;
|
13178 | this.trigger('reset');
|
13179 | };
|
13180 | };
|
13181 |
|
13182 | _TransportPacketStream.prototype = new stream();
|
13183 | |
13184 |
|
13185 |
|
13186 |
|
13187 |
|
13188 | _TransportParseStream = function TransportParseStream() {
|
13189 | var parsePsi, parsePat, parsePmt, self;
|
13190 |
|
13191 | _TransportParseStream.prototype.init.call(this);
|
13192 |
|
13193 | self = this;
|
13194 | this.packetsWaitingForPmt = [];
|
13195 | this.programMapTable = undefined;
|
13196 |
|
13197 | parsePsi = function parsePsi(payload, psi) {
|
13198 | var offset = 0;
|
13199 |
|
13200 |
|
13201 |
|
13202 |
|
13203 |
|
13204 |
|
13205 | if (psi.payloadUnitStartIndicator) {
|
13206 | offset += payload[offset] + 1;
|
13207 | }
|
13208 |
|
13209 | if (psi.type === 'pat') {
|
13210 | parsePat(payload.subarray(offset), psi);
|
13211 | } else {
|
13212 | parsePmt(payload.subarray(offset), psi);
|
13213 | }
|
13214 | };
|
13215 |
|
13216 | parsePat = function parsePat(payload, pat) {
|
13217 | pat.section_number = payload[7];
|
13218 |
|
13219 | pat.last_section_number = payload[8];
|
13220 |
|
13221 |
|
13222 | self.pmtPid = (payload[10] & 0x1F) << 8 | payload[11];
|
13223 | pat.pmtPid = self.pmtPid;
|
13224 | };
|
13225 | |
13226 |
|
13227 |
|
13228 |
|
13229 |
|
13230 |
|
13231 |
|
13232 |
|
13233 |
|
13234 |
|
13235 | parsePmt = function parsePmt(payload, pmt) {
|
13236 | var sectionLength, tableEnd, programInfoLength, offset;
|
13237 |
|
13238 |
|
13239 |
|
13240 |
|
13241 |
|
13242 | if (!(payload[5] & 0x01)) {
|
13243 | return;
|
13244 | }
|
13245 |
|
13246 |
|
13247 | self.programMapTable = {
|
13248 | video: null,
|
13249 | audio: null,
|
13250 | 'timed-metadata': {}
|
13251 | };
|
13252 |
|
13253 | sectionLength = (payload[1] & 0x0f) << 8 | payload[2];
|
13254 | tableEnd = 3 + sectionLength - 4;
|
13255 |
|
13256 |
|
13257 | programInfoLength = (payload[10] & 0x0f) << 8 | payload[11];
|
13258 |
|
13259 | offset = 12 + programInfoLength;
|
13260 |
|
13261 | while (offset < tableEnd) {
|
13262 | var streamType = payload[offset];
|
13263 | var pid = (payload[offset + 1] & 0x1F) << 8 | payload[offset + 2];
|
13264 |
|
13265 |
|
13266 |
|
13267 | if (streamType === streamTypes.H264_STREAM_TYPE && self.programMapTable.video === null) {
|
13268 | self.programMapTable.video = pid;
|
13269 | } else if (streamType === streamTypes.ADTS_STREAM_TYPE && self.programMapTable.audio === null) {
|
13270 | self.programMapTable.audio = pid;
|
13271 | } else if (streamType === streamTypes.METADATA_STREAM_TYPE) {
|
13272 |
|
13273 | self.programMapTable['timed-metadata'][pid] = streamType;
|
13274 | }
|
13275 |
|
13276 |
|
13277 |
|
13278 | offset += ((payload[offset + 3] & 0x0F) << 8 | payload[offset + 4]) + 5;
|
13279 | }
|
13280 |
|
13281 |
|
13282 | pmt.programMapTable = self.programMapTable;
|
13283 | };
|
13284 | |
13285 |
|
13286 |
|
13287 |
|
13288 |
|
13289 | this.push = function (packet) {
|
13290 | var result = {},
|
13291 | offset = 4;
|
13292 | result.payloadUnitStartIndicator = !!(packet[1] & 0x40);
|
13293 |
|
13294 | result.pid = packet[1] & 0x1f;
|
13295 | result.pid <<= 8;
|
13296 | result.pid |= packet[2];
|
13297 |
|
13298 |
|
13299 |
|
13300 |
|
13301 |
|
13302 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
13303 | offset += packet[offset] + 1;
|
13304 | }
|
13305 |
|
13306 |
|
13307 | if (result.pid === 0) {
|
13308 | result.type = 'pat';
|
13309 | parsePsi(packet.subarray(offset), result);
|
13310 | this.trigger('data', result);
|
13311 | } else if (result.pid === this.pmtPid) {
|
13312 | result.type = 'pmt';
|
13313 | parsePsi(packet.subarray(offset), result);
|
13314 | this.trigger('data', result);
|
13315 |
|
13316 | while (this.packetsWaitingForPmt.length) {
|
13317 | this.processPes_.apply(this, this.packetsWaitingForPmt.shift());
|
13318 | }
|
13319 | } else if (this.programMapTable === undefined) {
|
13320 |
|
13321 |
|
13322 | this.packetsWaitingForPmt.push([packet, offset, result]);
|
13323 | } else {
|
13324 | this.processPes_(packet, offset, result);
|
13325 | }
|
13326 | };
|
13327 |
|
13328 | this.processPes_ = function (packet, offset, result) {
|
13329 |
|
13330 | if (result.pid === this.programMapTable.video) {
|
13331 | result.streamType = streamTypes.H264_STREAM_TYPE;
|
13332 | } else if (result.pid === this.programMapTable.audio) {
|
13333 | result.streamType = streamTypes.ADTS_STREAM_TYPE;
|
13334 | } else {
|
13335 |
|
13336 |
|
13337 | result.streamType = this.programMapTable['timed-metadata'][result.pid];
|
13338 | }
|
13339 |
|
13340 | result.type = 'pes';
|
13341 | result.data = packet.subarray(offset);
|
13342 | this.trigger('data', result);
|
13343 | };
|
13344 | };
|
13345 |
|
13346 | _TransportParseStream.prototype = new stream();
|
13347 | _TransportParseStream.STREAM_TYPES = {
|
13348 | h264: 0x1b,
|
13349 | adts: 0x0f
|
13350 | };
|
13351 | |
13352 |
|
13353 |
|
13354 |
|
13355 |
|
13356 |
|
13357 |
|
13358 |
|
13359 |
|
13360 | _ElementaryStream = function ElementaryStream() {
|
13361 | var self = this,
|
13362 | segmentHadPmt = false,
|
13363 |
|
13364 | video = {
|
13365 | data: [],
|
13366 | size: 0
|
13367 | },
|
13368 | audio = {
|
13369 | data: [],
|
13370 | size: 0
|
13371 | },
|
13372 | timedMetadata = {
|
13373 | data: [],
|
13374 | size: 0
|
13375 | },
|
13376 | programMapTable,
|
13377 | parsePes = function parsePes(payload, pes) {
|
13378 | var ptsDtsFlags;
|
13379 | var startPrefix = payload[0] << 16 | payload[1] << 8 | payload[2];
|
13380 |
|
13381 | pes.data = new Uint8Array();
|
13382 |
|
13383 |
|
13384 |
|
13385 | if (startPrefix !== 1) {
|
13386 | return;
|
13387 | }
|
13388 |
|
13389 |
|
13390 | pes.packetLength = 6 + (payload[4] << 8 | payload[5]);
|
13391 |
|
13392 | pes.dataAlignmentIndicator = (payload[6] & 0x04) !== 0;
|
13393 |
|
13394 |
|
13395 |
|
13396 | ptsDtsFlags = payload[7];
|
13397 |
|
13398 |
|
13399 |
|
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 |
|
13405 | if (ptsDtsFlags & 0xC0) {
|
13406 |
|
13407 |
|
13408 |
|
13409 | pes.pts = (payload[9] & 0x0E) << 27 | (payload[10] & 0xFF) << 20 | (payload[11] & 0xFE) << 12 | (payload[12] & 0xFF) << 5 | (payload[13] & 0xFE) >>> 3;
|
13410 | pes.pts *= 4;
|
13411 |
|
13412 | pes.pts += (payload[13] & 0x06) >>> 1;
|
13413 |
|
13414 | pes.dts = pes.pts;
|
13415 |
|
13416 | if (ptsDtsFlags & 0x40) {
|
13417 | pes.dts = (payload[14] & 0x0E) << 27 | (payload[15] & 0xFF) << 20 | (payload[16] & 0xFE) << 12 | (payload[17] & 0xFF) << 5 | (payload[18] & 0xFE) >>> 3;
|
13418 | pes.dts *= 4;
|
13419 |
|
13420 | pes.dts += (payload[18] & 0x06) >>> 1;
|
13421 | }
|
13422 | }
|
13423 |
|
13424 |
|
13425 |
|
13426 |
|
13427 | pes.data = payload.subarray(9 + payload[8]);
|
13428 | },
|
13429 |
|
13430 | |
13431 |
|
13432 |
|
13433 | flushStream = function flushStream(stream, type, forceFlush) {
|
13434 | var packetData = new Uint8Array(stream.size),
|
13435 | event = {
|
13436 | type: type
|
13437 | },
|
13438 | i = 0,
|
13439 | offset = 0,
|
13440 | packetFlushable = false,
|
13441 | fragment;
|
13442 |
|
13443 |
|
13444 | if (!stream.data.length || stream.size < 9) {
|
13445 | return;
|
13446 | }
|
13447 |
|
13448 | event.trackId = stream.data[0].pid;
|
13449 |
|
13450 | for (i = 0; i < stream.data.length; i++) {
|
13451 | fragment = stream.data[i];
|
13452 | packetData.set(fragment.data, offset);
|
13453 | offset += fragment.data.byteLength;
|
13454 | }
|
13455 |
|
13456 |
|
13457 | parsePes(packetData, event);
|
13458 |
|
13459 |
|
13460 | packetFlushable = type === 'video' || event.packetLength <= stream.size;
|
13461 |
|
13462 | if (forceFlush || packetFlushable) {
|
13463 | stream.size = 0;
|
13464 | stream.data.length = 0;
|
13465 | }
|
13466 |
|
13467 |
|
13468 |
|
13469 | if (packetFlushable) {
|
13470 | self.trigger('data', event);
|
13471 | }
|
13472 | };
|
13473 |
|
13474 | _ElementaryStream.prototype.init.call(this);
|
13475 | |
13476 |
|
13477 |
|
13478 |
|
13479 |
|
13480 |
|
13481 | this.push = function (data) {
|
13482 | ({
|
13483 | pat: function pat() {
|
13484 |
|
13485 | },
|
13486 | pes: function pes() {
|
13487 | var stream, streamType;
|
13488 |
|
13489 | switch (data.streamType) {
|
13490 | case streamTypes.H264_STREAM_TYPE:
|
13491 | stream = video;
|
13492 | streamType = 'video';
|
13493 | break;
|
13494 |
|
13495 | case streamTypes.ADTS_STREAM_TYPE:
|
13496 | stream = audio;
|
13497 | streamType = 'audio';
|
13498 | break;
|
13499 |
|
13500 | case streamTypes.METADATA_STREAM_TYPE:
|
13501 | stream = timedMetadata;
|
13502 | streamType = 'timed-metadata';
|
13503 | break;
|
13504 |
|
13505 | default:
|
13506 |
|
13507 | return;
|
13508 | }
|
13509 |
|
13510 |
|
13511 |
|
13512 | if (data.payloadUnitStartIndicator) {
|
13513 | flushStream(stream, streamType, true);
|
13514 | }
|
13515 |
|
13516 |
|
13517 |
|
13518 | stream.data.push(data);
|
13519 | stream.size += data.data.byteLength;
|
13520 | },
|
13521 | pmt: function pmt() {
|
13522 | var event = {
|
13523 | type: 'metadata',
|
13524 | tracks: []
|
13525 | };
|
13526 | programMapTable = data.programMapTable;
|
13527 |
|
13528 | if (programMapTable.video !== null) {
|
13529 | event.tracks.push({
|
13530 | timelineStartInfo: {
|
13531 | baseMediaDecodeTime: 0
|
13532 | },
|
13533 | id: +programMapTable.video,
|
13534 | codec: 'avc',
|
13535 | type: 'video'
|
13536 | });
|
13537 | }
|
13538 |
|
13539 | if (programMapTable.audio !== null) {
|
13540 | event.tracks.push({
|
13541 | timelineStartInfo: {
|
13542 | baseMediaDecodeTime: 0
|
13543 | },
|
13544 | id: +programMapTable.audio,
|
13545 | codec: 'adts',
|
13546 | type: 'audio'
|
13547 | });
|
13548 | }
|
13549 |
|
13550 | segmentHadPmt = true;
|
13551 | self.trigger('data', event);
|
13552 | }
|
13553 | })[data.type]();
|
13554 | };
|
13555 |
|
13556 | this.reset = function () {
|
13557 | video.size = 0;
|
13558 | video.data.length = 0;
|
13559 | audio.size = 0;
|
13560 | audio.data.length = 0;
|
13561 | this.trigger('reset');
|
13562 | };
|
13563 | |
13564 |
|
13565 |
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 |
|
13571 |
|
13572 |
|
13573 |
|
13574 | this.flushStreams_ = function () {
|
13575 |
|
13576 |
|
13577 | flushStream(video, 'video');
|
13578 | flushStream(audio, 'audio');
|
13579 | flushStream(timedMetadata, 'timed-metadata');
|
13580 | };
|
13581 |
|
13582 | this.flush = function () {
|
13583 |
|
13584 |
|
13585 |
|
13586 | if (!segmentHadPmt && programMapTable) {
|
13587 | var pmt = {
|
13588 | type: 'metadata',
|
13589 | tracks: []
|
13590 | };
|
13591 |
|
13592 | if (programMapTable.video !== null) {
|
13593 | pmt.tracks.push({
|
13594 | timelineStartInfo: {
|
13595 | baseMediaDecodeTime: 0
|
13596 | },
|
13597 | id: +programMapTable.video,
|
13598 | codec: 'avc',
|
13599 | type: 'video'
|
13600 | });
|
13601 | }
|
13602 |
|
13603 | if (programMapTable.audio !== null) {
|
13604 | pmt.tracks.push({
|
13605 | timelineStartInfo: {
|
13606 | baseMediaDecodeTime: 0
|
13607 | },
|
13608 | id: +programMapTable.audio,
|
13609 | codec: 'adts',
|
13610 | type: 'audio'
|
13611 | });
|
13612 | }
|
13613 |
|
13614 | self.trigger('data', pmt);
|
13615 | }
|
13616 |
|
13617 | segmentHadPmt = false;
|
13618 | this.flushStreams_();
|
13619 | this.trigger('done');
|
13620 | };
|
13621 | };
|
13622 |
|
13623 | _ElementaryStream.prototype = new stream();
|
13624 | var m2ts = {
|
13625 | PAT_PID: 0x0000,
|
13626 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH$1,
|
13627 | TransportPacketStream: _TransportPacketStream,
|
13628 | TransportParseStream: _TransportParseStream,
|
13629 | ElementaryStream: _ElementaryStream,
|
13630 | TimestampRolloverStream: TimestampRolloverStream,
|
13631 | CaptionStream: captionStream.CaptionStream,
|
13632 | Cea608Stream: captionStream.Cea608Stream,
|
13633 | Cea708Stream: captionStream.Cea708Stream,
|
13634 | MetadataStream: metadataStream
|
13635 | };
|
13636 |
|
13637 | for (var type in streamTypes) {
|
13638 | if (streamTypes.hasOwnProperty(type)) {
|
13639 | m2ts[type] = streamTypes[type];
|
13640 | }
|
13641 | }
|
13642 |
|
13643 | var m2ts_1 = m2ts;
|
13644 | var ONE_SECOND_IN_TS$2 = clock.ONE_SECOND_IN_TS;
|
13645 |
|
13646 | var _AdtsStream;
|
13647 |
|
13648 | var ADTS_SAMPLING_FREQUENCIES$1 = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
13649 | |
13650 |
|
13651 |
|
13652 |
|
13653 |
|
13654 |
|
13655 |
|
13656 |
|
13657 |
|
13658 | _AdtsStream = function AdtsStream(handlePartialSegments) {
|
13659 | var buffer,
|
13660 | frameNum = 0;
|
13661 |
|
13662 | _AdtsStream.prototype.init.call(this);
|
13663 |
|
13664 | this.skipWarn_ = function (start, end) {
|
13665 | this.trigger('log', {
|
13666 | level: 'warn',
|
13667 | message: "adts skiping bytes " + start + " to " + end + " in frame " + frameNum + " outside syncword"
|
13668 | });
|
13669 | };
|
13670 |
|
13671 | this.push = function (packet) {
|
13672 | var i = 0,
|
13673 | frameLength,
|
13674 | protectionSkipBytes,
|
13675 | oldBuffer,
|
13676 | sampleCount,
|
13677 | adtsFrameDuration;
|
13678 |
|
13679 | if (!handlePartialSegments) {
|
13680 | frameNum = 0;
|
13681 | }
|
13682 |
|
13683 | if (packet.type !== 'audio') {
|
13684 |
|
13685 | return;
|
13686 | }
|
13687 |
|
13688 |
|
13689 |
|
13690 | if (buffer && buffer.length) {
|
13691 | oldBuffer = buffer;
|
13692 | buffer = new Uint8Array(oldBuffer.byteLength + packet.data.byteLength);
|
13693 | buffer.set(oldBuffer);
|
13694 | buffer.set(packet.data, oldBuffer.byteLength);
|
13695 | } else {
|
13696 | buffer = packet.data;
|
13697 | }
|
13698 |
|
13699 |
|
13700 |
|
13701 | var skip;
|
13702 |
|
13703 |
|
13704 | while (i + 7 < buffer.length) {
|
13705 |
|
13706 | if (buffer[i] !== 0xFF || (buffer[i + 1] & 0xF6) !== 0xF0) {
|
13707 | if (typeof skip !== 'number') {
|
13708 | skip = i;
|
13709 | }
|
13710 |
|
13711 |
|
13712 |
|
13713 | i++;
|
13714 | continue;
|
13715 | }
|
13716 |
|
13717 | if (typeof skip === 'number') {
|
13718 | this.skipWarn_(skip, i);
|
13719 | skip = null;
|
13720 | }
|
13721 |
|
13722 |
|
13723 |
|
13724 | protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
|
13725 |
|
13726 |
|
13727 |
|
13728 | frameLength = (buffer[i + 3] & 0x03) << 11 | buffer[i + 4] << 3 | (buffer[i + 5] & 0xe0) >> 5;
|
13729 | sampleCount = ((buffer[i + 6] & 0x03) + 1) * 1024;
|
13730 | adtsFrameDuration = sampleCount * ONE_SECOND_IN_TS$2 / ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2];
|
13731 |
|
13732 |
|
13733 | if (buffer.byteLength - i < frameLength) {
|
13734 | break;
|
13735 | }
|
13736 |
|
13737 |
|
13738 | this.trigger('data', {
|
13739 | pts: packet.pts + frameNum * adtsFrameDuration,
|
13740 | dts: packet.dts + frameNum * adtsFrameDuration,
|
13741 | sampleCount: sampleCount,
|
13742 | audioobjecttype: (buffer[i + 2] >>> 6 & 0x03) + 1,
|
13743 | channelcount: (buffer[i + 2] & 1) << 2 | (buffer[i + 3] & 0xc0) >>> 6,
|
13744 | samplerate: ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2],
|
13745 | samplingfrequencyindex: (buffer[i + 2] & 0x3c) >>> 2,
|
13746 |
|
13747 | samplesize: 16,
|
13748 |
|
13749 | data: buffer.subarray(i + 7 + protectionSkipBytes, i + frameLength)
|
13750 | });
|
13751 | frameNum++;
|
13752 | i += frameLength;
|
13753 | }
|
13754 |
|
13755 | if (typeof skip === 'number') {
|
13756 | this.skipWarn_(skip, i);
|
13757 | skip = null;
|
13758 | }
|
13759 |
|
13760 |
|
13761 | buffer = buffer.subarray(i);
|
13762 | };
|
13763 |
|
13764 | this.flush = function () {
|
13765 | frameNum = 0;
|
13766 | this.trigger('done');
|
13767 | };
|
13768 |
|
13769 | this.reset = function () {
|
13770 | buffer = void 0;
|
13771 | this.trigger('reset');
|
13772 | };
|
13773 |
|
13774 | this.endTimeline = function () {
|
13775 | buffer = void 0;
|
13776 | this.trigger('endedtimeline');
|
13777 | };
|
13778 | };
|
13779 |
|
13780 | _AdtsStream.prototype = new stream();
|
13781 | var adts = _AdtsStream;
|
13782 | |
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 |
|
13788 |
|
13789 | var ExpGolomb;
|
13790 | |
13791 |
|
13792 |
|
13793 |
|
13794 |
|
13795 | ExpGolomb = function ExpGolomb(workingData) {
|
13796 | var
|
13797 | workingBytesAvailable = workingData.byteLength,
|
13798 |
|
13799 | workingWord = 0,
|
13800 |
|
13801 |
|
13802 | workingBitsAvailable = 0;
|
13803 |
|
13804 |
|
13805 | this.length = function () {
|
13806 | return 8 * workingBytesAvailable;
|
13807 | };
|
13808 |
|
13809 |
|
13810 | this.bitsAvailable = function () {
|
13811 | return 8 * workingBytesAvailable + workingBitsAvailable;
|
13812 | };
|
13813 |
|
13814 |
|
13815 | this.loadWord = function () {
|
13816 | var position = workingData.byteLength - workingBytesAvailable,
|
13817 | workingBytes = new Uint8Array(4),
|
13818 | availableBytes = Math.min(4, workingBytesAvailable);
|
13819 |
|
13820 | if (availableBytes === 0) {
|
13821 | throw new Error('no bytes available');
|
13822 | }
|
13823 |
|
13824 | workingBytes.set(workingData.subarray(position, position + availableBytes));
|
13825 | workingWord = new DataView(workingBytes.buffer).getUint32(0);
|
13826 |
|
13827 | workingBitsAvailable = availableBytes * 8;
|
13828 | workingBytesAvailable -= availableBytes;
|
13829 | };
|
13830 |
|
13831 |
|
13832 | this.skipBits = function (count) {
|
13833 | var skipBytes;
|
13834 |
|
13835 | if (workingBitsAvailable > count) {
|
13836 | workingWord <<= count;
|
13837 | workingBitsAvailable -= count;
|
13838 | } else {
|
13839 | count -= workingBitsAvailable;
|
13840 | skipBytes = Math.floor(count / 8);
|
13841 | count -= skipBytes * 8;
|
13842 | workingBytesAvailable -= skipBytes;
|
13843 | this.loadWord();
|
13844 | workingWord <<= count;
|
13845 | workingBitsAvailable -= count;
|
13846 | }
|
13847 | };
|
13848 |
|
13849 |
|
13850 | this.readBits = function (size) {
|
13851 | var bits = Math.min(workingBitsAvailable, size),
|
13852 |
|
13853 | valu = workingWord >>> 32 - bits;
|
13854 |
|
13855 |
|
13856 | workingBitsAvailable -= bits;
|
13857 |
|
13858 | if (workingBitsAvailable > 0) {
|
13859 | workingWord <<= bits;
|
13860 | } else if (workingBytesAvailable > 0) {
|
13861 | this.loadWord();
|
13862 | }
|
13863 |
|
13864 | bits = size - bits;
|
13865 |
|
13866 | if (bits > 0) {
|
13867 | return valu << bits | this.readBits(bits);
|
13868 | }
|
13869 |
|
13870 | return valu;
|
13871 | };
|
13872 |
|
13873 |
|
13874 | this.skipLeadingZeros = function () {
|
13875 | var leadingZeroCount;
|
13876 |
|
13877 | for (leadingZeroCount = 0; leadingZeroCount < workingBitsAvailable; ++leadingZeroCount) {
|
13878 | if ((workingWord & 0x80000000 >>> leadingZeroCount) !== 0) {
|
13879 |
|
13880 | workingWord <<= leadingZeroCount;
|
13881 | workingBitsAvailable -= leadingZeroCount;
|
13882 | return leadingZeroCount;
|
13883 | }
|
13884 | }
|
13885 |
|
13886 |
|
13887 | this.loadWord();
|
13888 | return leadingZeroCount + this.skipLeadingZeros();
|
13889 | };
|
13890 |
|
13891 |
|
13892 | this.skipUnsignedExpGolomb = function () {
|
13893 | this.skipBits(1 + this.skipLeadingZeros());
|
13894 | };
|
13895 |
|
13896 |
|
13897 | this.skipExpGolomb = function () {
|
13898 | this.skipBits(1 + this.skipLeadingZeros());
|
13899 | };
|
13900 |
|
13901 |
|
13902 | this.readUnsignedExpGolomb = function () {
|
13903 | var clz = this.skipLeadingZeros();
|
13904 |
|
13905 | return this.readBits(clz + 1) - 1;
|
13906 | };
|
13907 |
|
13908 |
|
13909 | this.readExpGolomb = function () {
|
13910 | var valu = this.readUnsignedExpGolomb();
|
13911 |
|
13912 | if (0x01 & valu) {
|
13913 |
|
13914 | return 1 + valu >>> 1;
|
13915 | }
|
13916 |
|
13917 | return -1 * (valu >>> 1);
|
13918 | };
|
13919 |
|
13920 |
|
13921 |
|
13922 | this.readBoolean = function () {
|
13923 | return this.readBits(1) === 1;
|
13924 | };
|
13925 |
|
13926 |
|
13927 | this.readUnsignedByte = function () {
|
13928 | return this.readBits(8);
|
13929 | };
|
13930 |
|
13931 | this.loadWord();
|
13932 | };
|
13933 |
|
13934 | var expGolomb = ExpGolomb;
|
13935 |
|
13936 | var _H264Stream, _NalByteStream;
|
13937 |
|
13938 | var PROFILES_WITH_OPTIONAL_SPS_DATA;
|
13939 | |
13940 |
|
13941 |
|
13942 |
|
13943 | _NalByteStream = function NalByteStream() {
|
13944 | var syncPoint = 0,
|
13945 | i,
|
13946 | buffer;
|
13947 |
|
13948 | _NalByteStream.prototype.init.call(this);
|
13949 | |
13950 |
|
13951 |
|
13952 |
|
13953 |
|
13954 |
|
13955 |
|
13956 |
|
13957 |
|
13958 | this.push = function (data) {
|
13959 | var swapBuffer;
|
13960 |
|
13961 | if (!buffer) {
|
13962 | buffer = data.data;
|
13963 | } else {
|
13964 | swapBuffer = new Uint8Array(buffer.byteLength + data.data.byteLength);
|
13965 | swapBuffer.set(buffer);
|
13966 | swapBuffer.set(data.data, buffer.byteLength);
|
13967 | buffer = swapBuffer;
|
13968 | }
|
13969 |
|
13970 | var len = buffer.byteLength;
|
13971 |
|
13972 |
|
13973 |
|
13974 |
|
13975 |
|
13976 |
|
13977 |
|
13978 |
|
13979 |
|
13980 | for (; syncPoint < len - 3; syncPoint++) {
|
13981 | if (buffer[syncPoint + 2] === 1) {
|
13982 |
|
13983 | i = syncPoint + 5;
|
13984 | break;
|
13985 | }
|
13986 | }
|
13987 |
|
13988 | while (i < len) {
|
13989 |
|
13990 |
|
13991 | switch (buffer[i]) {
|
13992 | case 0:
|
13993 |
|
13994 | if (buffer[i - 1] !== 0) {
|
13995 | i += 2;
|
13996 | break;
|
13997 | } else if (buffer[i - 2] !== 0) {
|
13998 | i++;
|
13999 | break;
|
14000 | }
|
14001 |
|
14002 |
|
14003 | if (syncPoint + 3 !== i - 2) {
|
14004 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
14005 | }
|
14006 |
|
14007 |
|
14008 | do {
|
14009 | i++;
|
14010 | } while (buffer[i] !== 1 && i < len);
|
14011 |
|
14012 | syncPoint = i - 2;
|
14013 | i += 3;
|
14014 | break;
|
14015 |
|
14016 | case 1:
|
14017 |
|
14018 | if (buffer[i - 1] !== 0 || buffer[i - 2] !== 0) {
|
14019 | i += 3;
|
14020 | break;
|
14021 | }
|
14022 |
|
14023 |
|
14024 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
14025 | syncPoint = i - 2;
|
14026 | i += 3;
|
14027 | break;
|
14028 |
|
14029 | default:
|
14030 |
|
14031 |
|
14032 | i += 3;
|
14033 | break;
|
14034 | }
|
14035 | }
|
14036 |
|
14037 |
|
14038 | buffer = buffer.subarray(syncPoint);
|
14039 | i -= syncPoint;
|
14040 | syncPoint = 0;
|
14041 | };
|
14042 |
|
14043 | this.reset = function () {
|
14044 | buffer = null;
|
14045 | syncPoint = 0;
|
14046 | this.trigger('reset');
|
14047 | };
|
14048 |
|
14049 | this.flush = function () {
|
14050 |
|
14051 | if (buffer && buffer.byteLength > 3) {
|
14052 | this.trigger('data', buffer.subarray(syncPoint + 3));
|
14053 | }
|
14054 |
|
14055 |
|
14056 | buffer = null;
|
14057 | syncPoint = 0;
|
14058 | this.trigger('done');
|
14059 | };
|
14060 |
|
14061 | this.endTimeline = function () {
|
14062 | this.flush();
|
14063 | this.trigger('endedtimeline');
|
14064 | };
|
14065 | };
|
14066 |
|
14067 | _NalByteStream.prototype = new stream();
|
14068 |
|
14069 |
|
14070 |
|
14071 | PROFILES_WITH_OPTIONAL_SPS_DATA = {
|
14072 | 100: true,
|
14073 | 110: true,
|
14074 | 122: true,
|
14075 | 244: true,
|
14076 | 44: true,
|
14077 | 83: true,
|
14078 | 86: true,
|
14079 | 118: true,
|
14080 | 128: true,
|
14081 |
|
14082 |
|
14083 | 138: true,
|
14084 | 139: true,
|
14085 | 134: true
|
14086 | };
|
14087 | |
14088 |
|
14089 |
|
14090 |
|
14091 |
|
14092 | _H264Stream = function H264Stream() {
|
14093 | var nalByteStream = new _NalByteStream(),
|
14094 | self,
|
14095 | trackId,
|
14096 | currentPts,
|
14097 | currentDts,
|
14098 | discardEmulationPreventionBytes,
|
14099 | readSequenceParameterSet,
|
14100 | skipScalingList;
|
14101 |
|
14102 | _H264Stream.prototype.init.call(this);
|
14103 |
|
14104 | self = this;
|
14105 | |
14106 |
|
14107 |
|
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 | this.push = function (packet) {
|
14118 | if (packet.type !== 'video') {
|
14119 | return;
|
14120 | }
|
14121 |
|
14122 | trackId = packet.trackId;
|
14123 | currentPts = packet.pts;
|
14124 | currentDts = packet.dts;
|
14125 | nalByteStream.push(packet);
|
14126 | };
|
14127 | |
14128 |
|
14129 |
|
14130 |
|
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 |
|
14136 |
|
14137 | nalByteStream.on('data', function (data) {
|
14138 | var event = {
|
14139 | trackId: trackId,
|
14140 | pts: currentPts,
|
14141 | dts: currentDts,
|
14142 | data: data,
|
14143 | nalUnitTypeCode: data[0] & 0x1f
|
14144 | };
|
14145 |
|
14146 | switch (event.nalUnitTypeCode) {
|
14147 | case 0x05:
|
14148 | event.nalUnitType = 'slice_layer_without_partitioning_rbsp_idr';
|
14149 | break;
|
14150 |
|
14151 | case 0x06:
|
14152 | event.nalUnitType = 'sei_rbsp';
|
14153 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
14154 | break;
|
14155 |
|
14156 | case 0x07:
|
14157 | event.nalUnitType = 'seq_parameter_set_rbsp';
|
14158 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
14159 | event.config = readSequenceParameterSet(event.escapedRBSP);
|
14160 | break;
|
14161 |
|
14162 | case 0x08:
|
14163 | event.nalUnitType = 'pic_parameter_set_rbsp';
|
14164 | break;
|
14165 |
|
14166 | case 0x09:
|
14167 | event.nalUnitType = 'access_unit_delimiter_rbsp';
|
14168 | break;
|
14169 | }
|
14170 |
|
14171 |
|
14172 | self.trigger('data', event);
|
14173 | });
|
14174 | nalByteStream.on('done', function () {
|
14175 | self.trigger('done');
|
14176 | });
|
14177 | nalByteStream.on('partialdone', function () {
|
14178 | self.trigger('partialdone');
|
14179 | });
|
14180 | nalByteStream.on('reset', function () {
|
14181 | self.trigger('reset');
|
14182 | });
|
14183 | nalByteStream.on('endedtimeline', function () {
|
14184 | self.trigger('endedtimeline');
|
14185 | });
|
14186 |
|
14187 | this.flush = function () {
|
14188 | nalByteStream.flush();
|
14189 | };
|
14190 |
|
14191 | this.partialFlush = function () {
|
14192 | nalByteStream.partialFlush();
|
14193 | };
|
14194 |
|
14195 | this.reset = function () {
|
14196 | nalByteStream.reset();
|
14197 | };
|
14198 |
|
14199 | this.endTimeline = function () {
|
14200 | nalByteStream.endTimeline();
|
14201 | };
|
14202 | |
14203 |
|
14204 |
|
14205 |
|
14206 |
|
14207 |
|
14208 |
|
14209 |
|
14210 |
|
14211 |
|
14212 |
|
14213 | skipScalingList = function skipScalingList(count, expGolombDecoder) {
|
14214 | var lastScale = 8,
|
14215 | nextScale = 8,
|
14216 | j,
|
14217 | deltaScale;
|
14218 |
|
14219 | for (j = 0; j < count; j++) {
|
14220 | if (nextScale !== 0) {
|
14221 | deltaScale = expGolombDecoder.readExpGolomb();
|
14222 | nextScale = (lastScale + deltaScale + 256) % 256;
|
14223 | }
|
14224 |
|
14225 | lastScale = nextScale === 0 ? lastScale : nextScale;
|
14226 | }
|
14227 | };
|
14228 | |
14229 |
|
14230 |
|
14231 |
|
14232 |
|
14233 |
|
14234 |
|
14235 |
|
14236 |
|
14237 |
|
14238 | discardEmulationPreventionBytes = function discardEmulationPreventionBytes(data) {
|
14239 | var length = data.byteLength,
|
14240 | emulationPreventionBytesPositions = [],
|
14241 | i = 1,
|
14242 | newLength,
|
14243 | newData;
|
14244 |
|
14245 | while (i < length - 2) {
|
14246 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
14247 | emulationPreventionBytesPositions.push(i + 2);
|
14248 | i += 2;
|
14249 | } else {
|
14250 | i++;
|
14251 | }
|
14252 | }
|
14253 |
|
14254 |
|
14255 |
|
14256 | if (emulationPreventionBytesPositions.length === 0) {
|
14257 | return data;
|
14258 | }
|
14259 |
|
14260 |
|
14261 | newLength = length - emulationPreventionBytesPositions.length;
|
14262 | newData = new Uint8Array(newLength);
|
14263 | var sourceIndex = 0;
|
14264 |
|
14265 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
14266 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
14267 |
|
14268 | sourceIndex++;
|
14269 |
|
14270 | emulationPreventionBytesPositions.shift();
|
14271 | }
|
14272 |
|
14273 | newData[i] = data[sourceIndex];
|
14274 | }
|
14275 |
|
14276 | return newData;
|
14277 | };
|
14278 | |
14279 |
|
14280 |
|
14281 |
|
14282 |
|
14283 |
|
14284 |
|
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 | readSequenceParameterSet = function readSequenceParameterSet(data) {
|
14290 | var frameCropLeftOffset = 0,
|
14291 | frameCropRightOffset = 0,
|
14292 | frameCropTopOffset = 0,
|
14293 | frameCropBottomOffset = 0,
|
14294 | expGolombDecoder,
|
14295 | profileIdc,
|
14296 | levelIdc,
|
14297 | profileCompatibility,
|
14298 | chromaFormatIdc,
|
14299 | picOrderCntType,
|
14300 | numRefFramesInPicOrderCntCycle,
|
14301 | picWidthInMbsMinus1,
|
14302 | picHeightInMapUnitsMinus1,
|
14303 | frameMbsOnlyFlag,
|
14304 | scalingListCount,
|
14305 | sarRatio = [1, 1],
|
14306 | aspectRatioIdc,
|
14307 | i;
|
14308 | expGolombDecoder = new expGolomb(data);
|
14309 | profileIdc = expGolombDecoder.readUnsignedByte();
|
14310 |
|
14311 | profileCompatibility = expGolombDecoder.readUnsignedByte();
|
14312 |
|
14313 | levelIdc = expGolombDecoder.readUnsignedByte();
|
14314 |
|
14315 | expGolombDecoder.skipUnsignedExpGolomb();
|
14316 |
|
14317 |
|
14318 | if (PROFILES_WITH_OPTIONAL_SPS_DATA[profileIdc]) {
|
14319 | chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
|
14320 |
|
14321 | if (chromaFormatIdc === 3) {
|
14322 | expGolombDecoder.skipBits(1);
|
14323 | }
|
14324 |
|
14325 | expGolombDecoder.skipUnsignedExpGolomb();
|
14326 |
|
14327 | expGolombDecoder.skipUnsignedExpGolomb();
|
14328 |
|
14329 | expGolombDecoder.skipBits(1);
|
14330 |
|
14331 | if (expGolombDecoder.readBoolean()) {
|
14332 |
|
14333 | scalingListCount = chromaFormatIdc !== 3 ? 8 : 12;
|
14334 |
|
14335 | for (i = 0; i < scalingListCount; i++) {
|
14336 | if (expGolombDecoder.readBoolean()) {
|
14337 |
|
14338 | if (i < 6) {
|
14339 | skipScalingList(16, expGolombDecoder);
|
14340 | } else {
|
14341 | skipScalingList(64, expGolombDecoder);
|
14342 | }
|
14343 | }
|
14344 | }
|
14345 | }
|
14346 | }
|
14347 |
|
14348 | expGolombDecoder.skipUnsignedExpGolomb();
|
14349 |
|
14350 | picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
|
14351 |
|
14352 | if (picOrderCntType === 0) {
|
14353 | expGolombDecoder.readUnsignedExpGolomb();
|
14354 | } else if (picOrderCntType === 1) {
|
14355 | expGolombDecoder.skipBits(1);
|
14356 |
|
14357 | expGolombDecoder.skipExpGolomb();
|
14358 |
|
14359 | expGolombDecoder.skipExpGolomb();
|
14360 |
|
14361 | numRefFramesInPicOrderCntCycle = expGolombDecoder.readUnsignedExpGolomb();
|
14362 |
|
14363 | for (i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
|
14364 | expGolombDecoder.skipExpGolomb();
|
14365 | }
|
14366 | }
|
14367 |
|
14368 | expGolombDecoder.skipUnsignedExpGolomb();
|
14369 |
|
14370 | expGolombDecoder.skipBits(1);
|
14371 |
|
14372 | picWidthInMbsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
14373 | picHeightInMapUnitsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
14374 | frameMbsOnlyFlag = expGolombDecoder.readBits(1);
|
14375 |
|
14376 | if (frameMbsOnlyFlag === 0) {
|
14377 | expGolombDecoder.skipBits(1);
|
14378 | }
|
14379 |
|
14380 | expGolombDecoder.skipBits(1);
|
14381 |
|
14382 | if (expGolombDecoder.readBoolean()) {
|
14383 |
|
14384 | frameCropLeftOffset = expGolombDecoder.readUnsignedExpGolomb();
|
14385 | frameCropRightOffset = expGolombDecoder.readUnsignedExpGolomb();
|
14386 | frameCropTopOffset = expGolombDecoder.readUnsignedExpGolomb();
|
14387 | frameCropBottomOffset = expGolombDecoder.readUnsignedExpGolomb();
|
14388 | }
|
14389 |
|
14390 | if (expGolombDecoder.readBoolean()) {
|
14391 |
|
14392 | if (expGolombDecoder.readBoolean()) {
|
14393 |
|
14394 | aspectRatioIdc = expGolombDecoder.readUnsignedByte();
|
14395 |
|
14396 | switch (aspectRatioIdc) {
|
14397 | case 1:
|
14398 | sarRatio = [1, 1];
|
14399 | break;
|
14400 |
|
14401 | case 2:
|
14402 | sarRatio = [12, 11];
|
14403 | break;
|
14404 |
|
14405 | case 3:
|
14406 | sarRatio = [10, 11];
|
14407 | break;
|
14408 |
|
14409 | case 4:
|
14410 | sarRatio = [16, 11];
|
14411 | break;
|
14412 |
|
14413 | case 5:
|
14414 | sarRatio = [40, 33];
|
14415 | break;
|
14416 |
|
14417 | case 6:
|
14418 | sarRatio = [24, 11];
|
14419 | break;
|
14420 |
|
14421 | case 7:
|
14422 | sarRatio = [20, 11];
|
14423 | break;
|
14424 |
|
14425 | case 8:
|
14426 | sarRatio = [32, 11];
|
14427 | break;
|
14428 |
|
14429 | case 9:
|
14430 | sarRatio = [80, 33];
|
14431 | break;
|
14432 |
|
14433 | case 10:
|
14434 | sarRatio = [18, 11];
|
14435 | break;
|
14436 |
|
14437 | case 11:
|
14438 | sarRatio = [15, 11];
|
14439 | break;
|
14440 |
|
14441 | case 12:
|
14442 | sarRatio = [64, 33];
|
14443 | break;
|
14444 |
|
14445 | case 13:
|
14446 | sarRatio = [160, 99];
|
14447 | break;
|
14448 |
|
14449 | case 14:
|
14450 | sarRatio = [4, 3];
|
14451 | break;
|
14452 |
|
14453 | case 15:
|
14454 | sarRatio = [3, 2];
|
14455 | break;
|
14456 |
|
14457 | case 16:
|
14458 | sarRatio = [2, 1];
|
14459 | break;
|
14460 |
|
14461 | case 255:
|
14462 | {
|
14463 | sarRatio = [expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte(), expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte()];
|
14464 | break;
|
14465 | }
|
14466 | }
|
14467 |
|
14468 | if (sarRatio) {
|
14469 | sarRatio[0] / sarRatio[1];
|
14470 | }
|
14471 | }
|
14472 | }
|
14473 |
|
14474 | return {
|
14475 | profileIdc: profileIdc,
|
14476 | levelIdc: levelIdc,
|
14477 | profileCompatibility: profileCompatibility,
|
14478 | width: (picWidthInMbsMinus1 + 1) * 16 - frameCropLeftOffset * 2 - frameCropRightOffset * 2,
|
14479 | height: (2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16 - frameCropTopOffset * 2 - frameCropBottomOffset * 2,
|
14480 |
|
14481 | sarRatio: sarRatio
|
14482 | };
|
14483 | };
|
14484 | };
|
14485 |
|
14486 | _H264Stream.prototype = new stream();
|
14487 | var h264 = {
|
14488 | H264Stream: _H264Stream,
|
14489 | NalByteStream: _NalByteStream
|
14490 | };
|
14491 | |
14492 |
|
14493 |
|
14494 |
|
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 | var ADTS_SAMPLING_FREQUENCIES = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
14501 |
|
14502 | var parseId3TagSize = function parseId3TagSize(header, byteIndex) {
|
14503 | var returnSize = header[byteIndex + 6] << 21 | header[byteIndex + 7] << 14 | header[byteIndex + 8] << 7 | header[byteIndex + 9],
|
14504 | flags = header[byteIndex + 5],
|
14505 | footerPresent = (flags & 16) >> 4;
|
14506 |
|
14507 | returnSize = returnSize >= 0 ? returnSize : 0;
|
14508 |
|
14509 | if (footerPresent) {
|
14510 | return returnSize + 20;
|
14511 | }
|
14512 |
|
14513 | return returnSize + 10;
|
14514 | };
|
14515 |
|
14516 | var getId3Offset = function getId3Offset(data, offset) {
|
14517 | if (data.length - offset < 10 || data[offset] !== 'I'.charCodeAt(0) || data[offset + 1] !== 'D'.charCodeAt(0) || data[offset + 2] !== '3'.charCodeAt(0)) {
|
14518 | return offset;
|
14519 | }
|
14520 |
|
14521 | offset += parseId3TagSize(data, offset);
|
14522 | return getId3Offset(data, offset);
|
14523 | };
|
14524 |
|
14525 |
|
14526 | var isLikelyAacData$1 = function isLikelyAacData(data) {
|
14527 | var offset = getId3Offset(data, 0);
|
14528 | return data.length >= offset + 2 && (data[offset] & 0xFF) === 0xFF && (data[offset + 1] & 0xF0) === 0xF0 &&
|
14529 |
|
14530 | (data[offset + 1] & 0x16) === 0x10;
|
14531 | };
|
14532 |
|
14533 | var parseSyncSafeInteger = function parseSyncSafeInteger(data) {
|
14534 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
14535 | };
|
14536 |
|
14537 |
|
14538 |
|
14539 | var percentEncode = function percentEncode(bytes, start, end) {
|
14540 | var i,
|
14541 | result = '';
|
14542 |
|
14543 | for (i = start; i < end; i++) {
|
14544 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
14545 | }
|
14546 |
|
14547 | return result;
|
14548 | };
|
14549 |
|
14550 |
|
14551 |
|
14552 | var parseIso88591 = function parseIso88591(bytes, start, end) {
|
14553 | return unescape(percentEncode(bytes, start, end));
|
14554 | };
|
14555 |
|
14556 | var parseAdtsSize = function parseAdtsSize(header, byteIndex) {
|
14557 | var lowThree = (header[byteIndex + 5] & 0xE0) >> 5,
|
14558 | middle = header[byteIndex + 4] << 3,
|
14559 | highTwo = header[byteIndex + 3] & 0x3 << 11;
|
14560 | return highTwo | middle | lowThree;
|
14561 | };
|
14562 |
|
14563 | var parseType$2 = function parseType(header, byteIndex) {
|
14564 | if (header[byteIndex] === 'I'.charCodeAt(0) && header[byteIndex + 1] === 'D'.charCodeAt(0) && header[byteIndex + 2] === '3'.charCodeAt(0)) {
|
14565 | return 'timed-metadata';
|
14566 | } else if (header[byteIndex] & 0xff === 0xff && (header[byteIndex + 1] & 0xf0) === 0xf0) {
|
14567 | return 'audio';
|
14568 | }
|
14569 |
|
14570 | return null;
|
14571 | };
|
14572 |
|
14573 | var parseSampleRate = function parseSampleRate(packet) {
|
14574 | var i = 0;
|
14575 |
|
14576 | while (i + 5 < packet.length) {
|
14577 | if (packet[i] !== 0xFF || (packet[i + 1] & 0xF6) !== 0xF0) {
|
14578 |
|
14579 |
|
14580 | i++;
|
14581 | continue;
|
14582 | }
|
14583 |
|
14584 | return ADTS_SAMPLING_FREQUENCIES[(packet[i + 2] & 0x3c) >>> 2];
|
14585 | }
|
14586 |
|
14587 | return null;
|
14588 | };
|
14589 |
|
14590 | var parseAacTimestamp = function parseAacTimestamp(packet) {
|
14591 | var frameStart, frameSize, frame, frameHeader;
|
14592 |
|
14593 | frameStart = 10;
|
14594 |
|
14595 | if (packet[5] & 0x40) {
|
14596 |
|
14597 | frameStart += 4;
|
14598 |
|
14599 | frameStart += parseSyncSafeInteger(packet.subarray(10, 14));
|
14600 | }
|
14601 |
|
14602 |
|
14603 |
|
14604 | do {
|
14605 |
|
14606 | frameSize = parseSyncSafeInteger(packet.subarray(frameStart + 4, frameStart + 8));
|
14607 |
|
14608 | if (frameSize < 1) {
|
14609 | return null;
|
14610 | }
|
14611 |
|
14612 | frameHeader = String.fromCharCode(packet[frameStart], packet[frameStart + 1], packet[frameStart + 2], packet[frameStart + 3]);
|
14613 |
|
14614 | if (frameHeader === 'PRIV') {
|
14615 | frame = packet.subarray(frameStart + 10, frameStart + frameSize + 10);
|
14616 |
|
14617 | for (var i = 0; i < frame.byteLength; i++) {
|
14618 | if (frame[i] === 0) {
|
14619 | var owner = parseIso88591(frame, 0, i);
|
14620 |
|
14621 | if (owner === 'com.apple.streaming.transportStreamTimestamp') {
|
14622 | var d = frame.subarray(i + 1);
|
14623 | var size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
14624 | size *= 4;
|
14625 | size += d[7] & 0x03;
|
14626 | return size;
|
14627 | }
|
14628 |
|
14629 | break;
|
14630 | }
|
14631 | }
|
14632 | }
|
14633 |
|
14634 | frameStart += 10;
|
14635 |
|
14636 | frameStart += frameSize;
|
14637 | } while (frameStart < packet.byteLength);
|
14638 |
|
14639 | return null;
|
14640 | };
|
14641 |
|
14642 | var utils = {
|
14643 | isLikelyAacData: isLikelyAacData$1,
|
14644 | parseId3TagSize: parseId3TagSize,
|
14645 | parseAdtsSize: parseAdtsSize,
|
14646 | parseType: parseType$2,
|
14647 | parseSampleRate: parseSampleRate,
|
14648 | parseAacTimestamp: parseAacTimestamp
|
14649 | };
|
14650 |
|
14651 | var _AacStream;
|
14652 | |
14653 |
|
14654 |
|
14655 |
|
14656 |
|
14657 | _AacStream = function AacStream() {
|
14658 | var everything = new Uint8Array(),
|
14659 | timeStamp = 0;
|
14660 |
|
14661 | _AacStream.prototype.init.call(this);
|
14662 |
|
14663 | this.setTimestamp = function (timestamp) {
|
14664 | timeStamp = timestamp;
|
14665 | };
|
14666 |
|
14667 | this.push = function (bytes) {
|
14668 | var frameSize = 0,
|
14669 | byteIndex = 0,
|
14670 | bytesLeft,
|
14671 | chunk,
|
14672 | packet,
|
14673 | tempLength;
|
14674 |
|
14675 |
|
14676 | if (everything.length) {
|
14677 | tempLength = everything.length;
|
14678 | everything = new Uint8Array(bytes.byteLength + tempLength);
|
14679 | everything.set(everything.subarray(0, tempLength));
|
14680 | everything.set(bytes, tempLength);
|
14681 | } else {
|
14682 | everything = bytes;
|
14683 | }
|
14684 |
|
14685 | while (everything.length - byteIndex >= 3) {
|
14686 | if (everything[byteIndex] === 'I'.charCodeAt(0) && everything[byteIndex + 1] === 'D'.charCodeAt(0) && everything[byteIndex + 2] === '3'.charCodeAt(0)) {
|
14687 |
|
14688 |
|
14689 | if (everything.length - byteIndex < 10) {
|
14690 | break;
|
14691 | }
|
14692 |
|
14693 |
|
14694 | frameSize = utils.parseId3TagSize(everything, byteIndex);
|
14695 |
|
14696 |
|
14697 |
|
14698 | if (byteIndex + frameSize > everything.length) {
|
14699 | break;
|
14700 | }
|
14701 |
|
14702 | chunk = {
|
14703 | type: 'timed-metadata',
|
14704 | data: everything.subarray(byteIndex, byteIndex + frameSize)
|
14705 | };
|
14706 | this.trigger('data', chunk);
|
14707 | byteIndex += frameSize;
|
14708 | continue;
|
14709 | } else if ((everything[byteIndex] & 0xff) === 0xff && (everything[byteIndex + 1] & 0xf0) === 0xf0) {
|
14710 |
|
14711 |
|
14712 | if (everything.length - byteIndex < 7) {
|
14713 | break;
|
14714 | }
|
14715 |
|
14716 | frameSize = utils.parseAdtsSize(everything, byteIndex);
|
14717 |
|
14718 |
|
14719 | if (byteIndex + frameSize > everything.length) {
|
14720 | break;
|
14721 | }
|
14722 |
|
14723 | packet = {
|
14724 | type: 'audio',
|
14725 | data: everything.subarray(byteIndex, byteIndex + frameSize),
|
14726 | pts: timeStamp,
|
14727 | dts: timeStamp
|
14728 | };
|
14729 | this.trigger('data', packet);
|
14730 | byteIndex += frameSize;
|
14731 | continue;
|
14732 | }
|
14733 |
|
14734 | byteIndex++;
|
14735 | }
|
14736 |
|
14737 | bytesLeft = everything.length - byteIndex;
|
14738 |
|
14739 | if (bytesLeft > 0) {
|
14740 | everything = everything.subarray(byteIndex);
|
14741 | } else {
|
14742 | everything = new Uint8Array();
|
14743 | }
|
14744 | };
|
14745 |
|
14746 | this.reset = function () {
|
14747 | everything = new Uint8Array();
|
14748 | this.trigger('reset');
|
14749 | };
|
14750 |
|
14751 | this.endTimeline = function () {
|
14752 | everything = new Uint8Array();
|
14753 | this.trigger('endedtimeline');
|
14754 | };
|
14755 | };
|
14756 |
|
14757 | _AacStream.prototype = new stream();
|
14758 | var aac = _AacStream;
|
14759 |
|
14760 | var AUDIO_PROPERTIES = ['audioobjecttype', 'channelcount', 'samplerate', 'samplingfrequencyindex', 'samplesize'];
|
14761 | var audioProperties = AUDIO_PROPERTIES;
|
14762 | var VIDEO_PROPERTIES = ['width', 'height', 'profileIdc', 'levelIdc', 'profileCompatibility', 'sarRatio'];
|
14763 | var videoProperties = VIDEO_PROPERTIES;
|
14764 | var H264Stream = h264.H264Stream;
|
14765 | var isLikelyAacData = utils.isLikelyAacData;
|
14766 | var ONE_SECOND_IN_TS$1 = clock.ONE_SECOND_IN_TS;
|
14767 |
|
14768 | var _VideoSegmentStream, _AudioSegmentStream, _Transmuxer, _CoalesceStream;
|
14769 |
|
14770 | var retriggerForStream = function retriggerForStream(key, event) {
|
14771 | event.stream = key;
|
14772 | this.trigger('log', event);
|
14773 | };
|
14774 |
|
14775 | var addPipelineLogRetriggers = function addPipelineLogRetriggers(transmuxer, pipeline) {
|
14776 | var keys = Object.keys(pipeline);
|
14777 |
|
14778 | for (var i = 0; i < keys.length; i++) {
|
14779 | var key = keys[i];
|
14780 |
|
14781 |
|
14782 | if (key === 'headOfPipeline' || !pipeline[key].on) {
|
14783 | continue;
|
14784 | }
|
14785 |
|
14786 | pipeline[key].on('log', retriggerForStream.bind(transmuxer, key));
|
14787 | }
|
14788 | };
|
14789 | |
14790 |
|
14791 |
|
14792 |
|
14793 |
|
14794 | var arrayEquals = function arrayEquals(a, b) {
|
14795 | var i;
|
14796 |
|
14797 | if (a.length !== b.length) {
|
14798 | return false;
|
14799 | }
|
14800 |
|
14801 |
|
14802 | for (i = 0; i < a.length; i++) {
|
14803 | if (a[i] !== b[i]) {
|
14804 | return false;
|
14805 | }
|
14806 | }
|
14807 |
|
14808 | return true;
|
14809 | };
|
14810 |
|
14811 | var generateSegmentTimingInfo = function generateSegmentTimingInfo(baseMediaDecodeTime, startDts, startPts, endDts, endPts, prependedContentDuration) {
|
14812 | var ptsOffsetFromDts = startPts - startDts,
|
14813 | decodeDuration = endDts - startDts,
|
14814 | presentationDuration = endPts - startPts;
|
14815 |
|
14816 |
|
14817 |
|
14818 |
|
14819 | return {
|
14820 | start: {
|
14821 | dts: baseMediaDecodeTime,
|
14822 | pts: baseMediaDecodeTime + ptsOffsetFromDts
|
14823 | },
|
14824 | end: {
|
14825 | dts: baseMediaDecodeTime + decodeDuration,
|
14826 | pts: baseMediaDecodeTime + presentationDuration
|
14827 | },
|
14828 | prependedContentDuration: prependedContentDuration,
|
14829 | baseMediaDecodeTime: baseMediaDecodeTime
|
14830 | };
|
14831 | };
|
14832 | |
14833 |
|
14834 |
|
14835 |
|
14836 |
|
14837 |
|
14838 |
|
14839 |
|
14840 |
|
14841 |
|
14842 |
|
14843 | _AudioSegmentStream = function AudioSegmentStream(track, options) {
|
14844 | var adtsFrames = [],
|
14845 | sequenceNumber,
|
14846 | earliestAllowedDts = 0,
|
14847 | audioAppendStartTs = 0,
|
14848 | videoBaseMediaDecodeTime = Infinity;
|
14849 | options = options || {};
|
14850 | sequenceNumber = options.firstSequenceNumber || 0;
|
14851 |
|
14852 | _AudioSegmentStream.prototype.init.call(this);
|
14853 |
|
14854 | this.push = function (data) {
|
14855 | trackDecodeInfo.collectDtsInfo(track, data);
|
14856 |
|
14857 | if (track) {
|
14858 | audioProperties.forEach(function (prop) {
|
14859 | track[prop] = data[prop];
|
14860 | });
|
14861 | }
|
14862 |
|
14863 |
|
14864 | adtsFrames.push(data);
|
14865 | };
|
14866 |
|
14867 | this.setEarliestDts = function (earliestDts) {
|
14868 | earliestAllowedDts = earliestDts;
|
14869 | };
|
14870 |
|
14871 | this.setVideoBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
14872 | videoBaseMediaDecodeTime = baseMediaDecodeTime;
|
14873 | };
|
14874 |
|
14875 | this.setAudioAppendStart = function (timestamp) {
|
14876 | audioAppendStartTs = timestamp;
|
14877 | };
|
14878 |
|
14879 | this.flush = function () {
|
14880 | var frames, moof, mdat, boxes, frameDuration, segmentDuration, videoClockCyclesOfSilencePrefixed;
|
14881 |
|
14882 | if (adtsFrames.length === 0) {
|
14883 | this.trigger('done', 'AudioSegmentStream');
|
14884 | return;
|
14885 | }
|
14886 |
|
14887 | frames = audioFrameUtils.trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts);
|
14888 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
14889 |
|
14890 | videoClockCyclesOfSilencePrefixed = audioFrameUtils.prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime);
|
14891 |
|
14892 |
|
14893 | track.samples = audioFrameUtils.generateSampleTable(frames);
|
14894 |
|
14895 | mdat = mp4Generator.mdat(audioFrameUtils.concatenateFrameData(frames));
|
14896 | adtsFrames = [];
|
14897 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
14898 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
14899 |
|
14900 | sequenceNumber++;
|
14901 | boxes.set(moof);
|
14902 | boxes.set(mdat, moof.byteLength);
|
14903 | trackDecodeInfo.clearDtsInfo(track);
|
14904 | frameDuration = Math.ceil(ONE_SECOND_IN_TS$1 * 1024 / track.samplerate);
|
14905 |
|
14906 |
|
14907 |
|
14908 |
|
14909 | if (frames.length) {
|
14910 | segmentDuration = frames.length * frameDuration;
|
14911 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(
|
14912 |
|
14913 |
|
14914 | clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate),
|
14915 | frames[0].dts, frames[0].pts, frames[0].dts + segmentDuration, frames[0].pts + segmentDuration, videoClockCyclesOfSilencePrefixed || 0));
|
14916 | this.trigger('timingInfo', {
|
14917 | start: frames[0].pts,
|
14918 | end: frames[0].pts + segmentDuration
|
14919 | });
|
14920 | }
|
14921 |
|
14922 | this.trigger('data', {
|
14923 | track: track,
|
14924 | boxes: boxes
|
14925 | });
|
14926 | this.trigger('done', 'AudioSegmentStream');
|
14927 | };
|
14928 |
|
14929 | this.reset = function () {
|
14930 | trackDecodeInfo.clearDtsInfo(track);
|
14931 | adtsFrames = [];
|
14932 | this.trigger('reset');
|
14933 | };
|
14934 | };
|
14935 |
|
14936 | _AudioSegmentStream.prototype = new stream();
|
14937 | |
14938 |
|
14939 |
|
14940 |
|
14941 |
|
14942 |
|
14943 |
|
14944 |
|
14945 |
|
14946 |
|
14947 |
|
14948 |
|
14949 | _VideoSegmentStream = function VideoSegmentStream(track, options) {
|
14950 | var sequenceNumber,
|
14951 | nalUnits = [],
|
14952 | gopsToAlignWith = [],
|
14953 | config,
|
14954 | pps;
|
14955 | options = options || {};
|
14956 | sequenceNumber = options.firstSequenceNumber || 0;
|
14957 |
|
14958 | _VideoSegmentStream.prototype.init.call(this);
|
14959 |
|
14960 | delete track.minPTS;
|
14961 | this.gopCache_ = [];
|
14962 | |
14963 |
|
14964 |
|
14965 |
|
14966 |
|
14967 |
|
14968 |
|
14969 |
|
14970 |
|
14971 | this.push = function (nalUnit) {
|
14972 | trackDecodeInfo.collectDtsInfo(track, nalUnit);
|
14973 |
|
14974 | if (nalUnit.nalUnitType === 'seq_parameter_set_rbsp' && !config) {
|
14975 | config = nalUnit.config;
|
14976 | track.sps = [nalUnit.data];
|
14977 | videoProperties.forEach(function (prop) {
|
14978 | track[prop] = config[prop];
|
14979 | }, this);
|
14980 | }
|
14981 |
|
14982 | if (nalUnit.nalUnitType === 'pic_parameter_set_rbsp' && !pps) {
|
14983 | pps = nalUnit.data;
|
14984 | track.pps = [nalUnit.data];
|
14985 | }
|
14986 |
|
14987 |
|
14988 | nalUnits.push(nalUnit);
|
14989 | };
|
14990 | |
14991 |
|
14992 |
|
14993 |
|
14994 |
|
14995 |
|
14996 | this.flush = function () {
|
14997 | var frames,
|
14998 | gopForFusion,
|
14999 | gops,
|
15000 | moof,
|
15001 | mdat,
|
15002 | boxes,
|
15003 | prependedContentDuration = 0,
|
15004 | firstGop,
|
15005 | lastGop;
|
15006 |
|
15007 |
|
15008 | while (nalUnits.length) {
|
15009 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
15010 | break;
|
15011 | }
|
15012 |
|
15013 | nalUnits.shift();
|
15014 | }
|
15015 |
|
15016 |
|
15017 | if (nalUnits.length === 0) {
|
15018 | this.resetStream_();
|
15019 | this.trigger('done', 'VideoSegmentStream');
|
15020 | return;
|
15021 | }
|
15022 |
|
15023 |
|
15024 |
|
15025 |
|
15026 | frames = frameUtils.groupNalsIntoFrames(nalUnits);
|
15027 | gops = frameUtils.groupFramesIntoGops(frames);
|
15028 |
|
15029 |
|
15030 |
|
15031 |
|
15032 |
|
15033 |
|
15034 |
|
15035 |
|
15036 |
|
15037 |
|
15038 |
|
15039 |
|
15040 |
|
15041 |
|
15042 |
|
15043 |
|
15044 |
|
15045 |
|
15046 | if (!gops[0][0].keyFrame) {
|
15047 |
|
15048 | gopForFusion = this.getGopForFusion_(nalUnits[0], track);
|
15049 |
|
15050 | if (gopForFusion) {
|
15051 |
|
15052 |
|
15053 | prependedContentDuration = gopForFusion.duration;
|
15054 | gops.unshift(gopForFusion);
|
15055 |
|
15056 |
|
15057 | gops.byteLength += gopForFusion.byteLength;
|
15058 | gops.nalCount += gopForFusion.nalCount;
|
15059 | gops.pts = gopForFusion.pts;
|
15060 | gops.dts = gopForFusion.dts;
|
15061 | gops.duration += gopForFusion.duration;
|
15062 | } else {
|
15063 |
|
15064 | gops = frameUtils.extendFirstKeyFrame(gops);
|
15065 | }
|
15066 | }
|
15067 |
|
15068 |
|
15069 | if (gopsToAlignWith.length) {
|
15070 | var alignedGops;
|
15071 |
|
15072 | if (options.alignGopsAtEnd) {
|
15073 | alignedGops = this.alignGopsAtEnd_(gops);
|
15074 | } else {
|
15075 | alignedGops = this.alignGopsAtStart_(gops);
|
15076 | }
|
15077 |
|
15078 | if (!alignedGops) {
|
15079 |
|
15080 | this.gopCache_.unshift({
|
15081 | gop: gops.pop(),
|
15082 | pps: track.pps,
|
15083 | sps: track.sps
|
15084 | });
|
15085 |
|
15086 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
15087 |
|
15088 | nalUnits = [];
|
15089 |
|
15090 | this.resetStream_();
|
15091 | this.trigger('done', 'VideoSegmentStream');
|
15092 | return;
|
15093 | }
|
15094 |
|
15095 |
|
15096 |
|
15097 | trackDecodeInfo.clearDtsInfo(track);
|
15098 | gops = alignedGops;
|
15099 | }
|
15100 |
|
15101 | trackDecodeInfo.collectDtsInfo(track, gops);
|
15102 |
|
15103 |
|
15104 | track.samples = frameUtils.generateSampleTable(gops);
|
15105 |
|
15106 | mdat = mp4Generator.mdat(frameUtils.concatenateNalData(gops));
|
15107 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
15108 | this.trigger('processedGopsInfo', gops.map(function (gop) {
|
15109 | return {
|
15110 | pts: gop.pts,
|
15111 | dts: gop.dts,
|
15112 | byteLength: gop.byteLength
|
15113 | };
|
15114 | }));
|
15115 | firstGop = gops[0];
|
15116 | lastGop = gops[gops.length - 1];
|
15117 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(track.baseMediaDecodeTime, firstGop.dts, firstGop.pts, lastGop.dts + lastGop.duration, lastGop.pts + lastGop.duration, prependedContentDuration));
|
15118 | this.trigger('timingInfo', {
|
15119 | start: gops[0].pts,
|
15120 | end: gops[gops.length - 1].pts + gops[gops.length - 1].duration
|
15121 | });
|
15122 |
|
15123 | this.gopCache_.unshift({
|
15124 | gop: gops.pop(),
|
15125 | pps: track.pps,
|
15126 | sps: track.sps
|
15127 | });
|
15128 |
|
15129 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
15130 |
|
15131 | nalUnits = [];
|
15132 | this.trigger('baseMediaDecodeTime', track.baseMediaDecodeTime);
|
15133 | this.trigger('timelineStartInfo', track.timelineStartInfo);
|
15134 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
15135 |
|
15136 |
|
15137 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
15138 |
|
15139 | sequenceNumber++;
|
15140 | boxes.set(moof);
|
15141 | boxes.set(mdat, moof.byteLength);
|
15142 | this.trigger('data', {
|
15143 | track: track,
|
15144 | boxes: boxes
|
15145 | });
|
15146 | this.resetStream_();
|
15147 |
|
15148 | this.trigger('done', 'VideoSegmentStream');
|
15149 | };
|
15150 |
|
15151 | this.reset = function () {
|
15152 | this.resetStream_();
|
15153 | nalUnits = [];
|
15154 | this.gopCache_.length = 0;
|
15155 | gopsToAlignWith.length = 0;
|
15156 | this.trigger('reset');
|
15157 | };
|
15158 |
|
15159 | this.resetStream_ = function () {
|
15160 | trackDecodeInfo.clearDtsInfo(track);
|
15161 |
|
15162 |
|
15163 | config = undefined;
|
15164 | pps = undefined;
|
15165 | };
|
15166 |
|
15167 |
|
15168 |
|
15169 | this.getGopForFusion_ = function (nalUnit) {
|
15170 | var halfSecond = 45000,
|
15171 |
|
15172 | allowableOverlap = 10000,
|
15173 |
|
15174 | nearestDistance = Infinity,
|
15175 | dtsDistance,
|
15176 | nearestGopObj,
|
15177 | currentGop,
|
15178 | currentGopObj,
|
15179 | i;
|
15180 |
|
15181 | for (i = 0; i < this.gopCache_.length; i++) {
|
15182 | currentGopObj = this.gopCache_[i];
|
15183 | currentGop = currentGopObj.gop;
|
15184 |
|
15185 | if (!(track.pps && arrayEquals(track.pps[0], currentGopObj.pps[0])) || !(track.sps && arrayEquals(track.sps[0], currentGopObj.sps[0]))) {
|
15186 | continue;
|
15187 | }
|
15188 |
|
15189 |
|
15190 | if (currentGop.dts < track.timelineStartInfo.dts) {
|
15191 | continue;
|
15192 | }
|
15193 |
|
15194 |
|
15195 | dtsDistance = nalUnit.dts - currentGop.dts - currentGop.duration;
|
15196 |
|
15197 |
|
15198 | if (dtsDistance >= -allowableOverlap && dtsDistance <= halfSecond) {
|
15199 |
|
15200 |
|
15201 | if (!nearestGopObj || nearestDistance > dtsDistance) {
|
15202 | nearestGopObj = currentGopObj;
|
15203 | nearestDistance = dtsDistance;
|
15204 | }
|
15205 | }
|
15206 | }
|
15207 |
|
15208 | if (nearestGopObj) {
|
15209 | return nearestGopObj.gop;
|
15210 | }
|
15211 |
|
15212 | return null;
|
15213 | };
|
15214 |
|
15215 |
|
15216 |
|
15217 | this.alignGopsAtStart_ = function (gops) {
|
15218 | var alignIndex, gopIndex, align, gop, byteLength, nalCount, duration, alignedGops;
|
15219 | byteLength = gops.byteLength;
|
15220 | nalCount = gops.nalCount;
|
15221 | duration = gops.duration;
|
15222 | alignIndex = gopIndex = 0;
|
15223 |
|
15224 | while (alignIndex < gopsToAlignWith.length && gopIndex < gops.length) {
|
15225 | align = gopsToAlignWith[alignIndex];
|
15226 | gop = gops[gopIndex];
|
15227 |
|
15228 | if (align.pts === gop.pts) {
|
15229 | break;
|
15230 | }
|
15231 |
|
15232 | if (gop.pts > align.pts) {
|
15233 |
|
15234 |
|
15235 | alignIndex++;
|
15236 | continue;
|
15237 | }
|
15238 |
|
15239 |
|
15240 |
|
15241 | gopIndex++;
|
15242 | byteLength -= gop.byteLength;
|
15243 | nalCount -= gop.nalCount;
|
15244 | duration -= gop.duration;
|
15245 | }
|
15246 |
|
15247 | if (gopIndex === 0) {
|
15248 |
|
15249 | return gops;
|
15250 | }
|
15251 |
|
15252 | if (gopIndex === gops.length) {
|
15253 |
|
15254 | return null;
|
15255 | }
|
15256 |
|
15257 | alignedGops = gops.slice(gopIndex);
|
15258 | alignedGops.byteLength = byteLength;
|
15259 | alignedGops.duration = duration;
|
15260 | alignedGops.nalCount = nalCount;
|
15261 | alignedGops.pts = alignedGops[0].pts;
|
15262 | alignedGops.dts = alignedGops[0].dts;
|
15263 | return alignedGops;
|
15264 | };
|
15265 |
|
15266 |
|
15267 |
|
15268 | this.alignGopsAtEnd_ = function (gops) {
|
15269 | var alignIndex, gopIndex, align, gop, alignEndIndex, matchFound;
|
15270 | alignIndex = gopsToAlignWith.length - 1;
|
15271 | gopIndex = gops.length - 1;
|
15272 | alignEndIndex = null;
|
15273 | matchFound = false;
|
15274 |
|
15275 | while (alignIndex >= 0 && gopIndex >= 0) {
|
15276 | align = gopsToAlignWith[alignIndex];
|
15277 | gop = gops[gopIndex];
|
15278 |
|
15279 | if (align.pts === gop.pts) {
|
15280 | matchFound = true;
|
15281 | break;
|
15282 | }
|
15283 |
|
15284 | if (align.pts > gop.pts) {
|
15285 | alignIndex--;
|
15286 | continue;
|
15287 | }
|
15288 |
|
15289 | if (alignIndex === gopsToAlignWith.length - 1) {
|
15290 |
|
15291 |
|
15292 |
|
15293 | alignEndIndex = gopIndex;
|
15294 | }
|
15295 |
|
15296 | gopIndex--;
|
15297 | }
|
15298 |
|
15299 | if (!matchFound && alignEndIndex === null) {
|
15300 | return null;
|
15301 | }
|
15302 |
|
15303 | var trimIndex;
|
15304 |
|
15305 | if (matchFound) {
|
15306 | trimIndex = gopIndex;
|
15307 | } else {
|
15308 | trimIndex = alignEndIndex;
|
15309 | }
|
15310 |
|
15311 | if (trimIndex === 0) {
|
15312 | return gops;
|
15313 | }
|
15314 |
|
15315 | var alignedGops = gops.slice(trimIndex);
|
15316 | var metadata = alignedGops.reduce(function (total, gop) {
|
15317 | total.byteLength += gop.byteLength;
|
15318 | total.duration += gop.duration;
|
15319 | total.nalCount += gop.nalCount;
|
15320 | return total;
|
15321 | }, {
|
15322 | byteLength: 0,
|
15323 | duration: 0,
|
15324 | nalCount: 0
|
15325 | });
|
15326 | alignedGops.byteLength = metadata.byteLength;
|
15327 | alignedGops.duration = metadata.duration;
|
15328 | alignedGops.nalCount = metadata.nalCount;
|
15329 | alignedGops.pts = alignedGops[0].pts;
|
15330 | alignedGops.dts = alignedGops[0].dts;
|
15331 | return alignedGops;
|
15332 | };
|
15333 |
|
15334 | this.alignGopsWith = function (newGopsToAlignWith) {
|
15335 | gopsToAlignWith = newGopsToAlignWith;
|
15336 | };
|
15337 | };
|
15338 |
|
15339 | _VideoSegmentStream.prototype = new stream();
|
15340 | |
15341 |
|
15342 |
|
15343 |
|
15344 |
|
15345 |
|
15346 |
|
15347 |
|
15348 |
|
15349 | _CoalesceStream = function CoalesceStream(options, metadataStream) {
|
15350 |
|
15351 |
|
15352 |
|
15353 | this.numberOfTracks = 0;
|
15354 | this.metadataStream = metadataStream;
|
15355 | options = options || {};
|
15356 |
|
15357 | if (typeof options.remux !== 'undefined') {
|
15358 | this.remuxTracks = !!options.remux;
|
15359 | } else {
|
15360 | this.remuxTracks = true;
|
15361 | }
|
15362 |
|
15363 | if (typeof options.keepOriginalTimestamps === 'boolean') {
|
15364 | this.keepOriginalTimestamps = options.keepOriginalTimestamps;
|
15365 | } else {
|
15366 | this.keepOriginalTimestamps = false;
|
15367 | }
|
15368 |
|
15369 | this.pendingTracks = [];
|
15370 | this.videoTrack = null;
|
15371 | this.pendingBoxes = [];
|
15372 | this.pendingCaptions = [];
|
15373 | this.pendingMetadata = [];
|
15374 | this.pendingBytes = 0;
|
15375 | this.emittedTracks = 0;
|
15376 |
|
15377 | _CoalesceStream.prototype.init.call(this);
|
15378 |
|
15379 |
|
15380 | this.push = function (output) {
|
15381 |
|
15382 |
|
15383 | if (output.text) {
|
15384 | return this.pendingCaptions.push(output);
|
15385 | }
|
15386 |
|
15387 |
|
15388 | if (output.frames) {
|
15389 | return this.pendingMetadata.push(output);
|
15390 | }
|
15391 |
|
15392 |
|
15393 |
|
15394 |
|
15395 | this.pendingTracks.push(output.track);
|
15396 | this.pendingBytes += output.boxes.byteLength;
|
15397 |
|
15398 |
|
15399 |
|
15400 |
|
15401 |
|
15402 |
|
15403 | if (output.track.type === 'video') {
|
15404 | this.videoTrack = output.track;
|
15405 | this.pendingBoxes.push(output.boxes);
|
15406 | }
|
15407 |
|
15408 | if (output.track.type === 'audio') {
|
15409 | this.audioTrack = output.track;
|
15410 | this.pendingBoxes.unshift(output.boxes);
|
15411 | }
|
15412 | };
|
15413 | };
|
15414 |
|
15415 | _CoalesceStream.prototype = new stream();
|
15416 |
|
15417 | _CoalesceStream.prototype.flush = function (flushSource) {
|
15418 | var offset = 0,
|
15419 | event = {
|
15420 | captions: [],
|
15421 | captionStreams: {},
|
15422 | metadata: [],
|
15423 | info: {}
|
15424 | },
|
15425 | caption,
|
15426 | id3,
|
15427 | initSegment,
|
15428 | timelineStartPts = 0,
|
15429 | i;
|
15430 |
|
15431 | if (this.pendingTracks.length < this.numberOfTracks) {
|
15432 | if (flushSource !== 'VideoSegmentStream' && flushSource !== 'AudioSegmentStream') {
|
15433 |
|
15434 |
|
15435 |
|
15436 | return;
|
15437 | } else if (this.remuxTracks) {
|
15438 |
|
15439 |
|
15440 | return;
|
15441 | } else if (this.pendingTracks.length === 0) {
|
15442 |
|
15443 |
|
15444 |
|
15445 |
|
15446 |
|
15447 |
|
15448 | this.emittedTracks++;
|
15449 |
|
15450 | if (this.emittedTracks >= this.numberOfTracks) {
|
15451 | this.trigger('done');
|
15452 | this.emittedTracks = 0;
|
15453 | }
|
15454 |
|
15455 | return;
|
15456 | }
|
15457 | }
|
15458 |
|
15459 | if (this.videoTrack) {
|
15460 | timelineStartPts = this.videoTrack.timelineStartInfo.pts;
|
15461 | videoProperties.forEach(function (prop) {
|
15462 | event.info[prop] = this.videoTrack[prop];
|
15463 | }, this);
|
15464 | } else if (this.audioTrack) {
|
15465 | timelineStartPts = this.audioTrack.timelineStartInfo.pts;
|
15466 | audioProperties.forEach(function (prop) {
|
15467 | event.info[prop] = this.audioTrack[prop];
|
15468 | }, this);
|
15469 | }
|
15470 |
|
15471 | if (this.videoTrack || this.audioTrack) {
|
15472 | if (this.pendingTracks.length === 1) {
|
15473 | event.type = this.pendingTracks[0].type;
|
15474 | } else {
|
15475 | event.type = 'combined';
|
15476 | }
|
15477 |
|
15478 | this.emittedTracks += this.pendingTracks.length;
|
15479 | initSegment = mp4Generator.initSegment(this.pendingTracks);
|
15480 |
|
15481 | event.initSegment = new Uint8Array(initSegment.byteLength);
|
15482 |
|
15483 |
|
15484 | event.initSegment.set(initSegment);
|
15485 |
|
15486 | event.data = new Uint8Array(this.pendingBytes);
|
15487 |
|
15488 | for (i = 0; i < this.pendingBoxes.length; i++) {
|
15489 | event.data.set(this.pendingBoxes[i], offset);
|
15490 | offset += this.pendingBoxes[i].byteLength;
|
15491 | }
|
15492 |
|
15493 |
|
15494 |
|
15495 | for (i = 0; i < this.pendingCaptions.length; i++) {
|
15496 | caption = this.pendingCaptions[i];
|
15497 | caption.startTime = clock.metadataTsToSeconds(caption.startPts, timelineStartPts, this.keepOriginalTimestamps);
|
15498 | caption.endTime = clock.metadataTsToSeconds(caption.endPts, timelineStartPts, this.keepOriginalTimestamps);
|
15499 | event.captionStreams[caption.stream] = true;
|
15500 | event.captions.push(caption);
|
15501 | }
|
15502 |
|
15503 |
|
15504 |
|
15505 | for (i = 0; i < this.pendingMetadata.length; i++) {
|
15506 | id3 = this.pendingMetadata[i];
|
15507 | id3.cueTime = clock.metadataTsToSeconds(id3.pts, timelineStartPts, this.keepOriginalTimestamps);
|
15508 | event.metadata.push(id3);
|
15509 | }
|
15510 |
|
15511 |
|
15512 |
|
15513 | event.metadata.dispatchType = this.metadataStream.dispatchType;
|
15514 |
|
15515 | this.pendingTracks.length = 0;
|
15516 | this.videoTrack = null;
|
15517 | this.pendingBoxes.length = 0;
|
15518 | this.pendingCaptions.length = 0;
|
15519 | this.pendingBytes = 0;
|
15520 | this.pendingMetadata.length = 0;
|
15521 |
|
15522 |
|
15523 |
|
15524 | this.trigger('data', event);
|
15525 |
|
15526 |
|
15527 |
|
15528 |
|
15529 | for (i = 0; i < event.captions.length; i++) {
|
15530 | caption = event.captions[i];
|
15531 | this.trigger('caption', caption);
|
15532 | }
|
15533 |
|
15534 |
|
15535 |
|
15536 |
|
15537 |
|
15538 | for (i = 0; i < event.metadata.length; i++) {
|
15539 | id3 = event.metadata[i];
|
15540 | this.trigger('id3Frame', id3);
|
15541 | }
|
15542 | }
|
15543 |
|
15544 |
|
15545 | if (this.emittedTracks >= this.numberOfTracks) {
|
15546 | this.trigger('done');
|
15547 | this.emittedTracks = 0;
|
15548 | }
|
15549 | };
|
15550 |
|
15551 | _CoalesceStream.prototype.setRemux = function (val) {
|
15552 | this.remuxTracks = val;
|
15553 | };
|
15554 | |
15555 |
|
15556 |
|
15557 |
|
15558 |
|
15559 |
|
15560 |
|
15561 |
|
15562 | _Transmuxer = function Transmuxer(options) {
|
15563 | var self = this,
|
15564 | hasFlushed = true,
|
15565 | videoTrack,
|
15566 | audioTrack;
|
15567 |
|
15568 | _Transmuxer.prototype.init.call(this);
|
15569 |
|
15570 | options = options || {};
|
15571 | this.baseMediaDecodeTime = options.baseMediaDecodeTime || 0;
|
15572 | this.transmuxPipeline_ = {};
|
15573 |
|
15574 | this.setupAacPipeline = function () {
|
15575 | var pipeline = {};
|
15576 | this.transmuxPipeline_ = pipeline;
|
15577 | pipeline.type = 'aac';
|
15578 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
15579 |
|
15580 | pipeline.aacStream = new aac();
|
15581 | pipeline.audioTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('audio');
|
15582 | pipeline.timedMetadataTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('timed-metadata');
|
15583 | pipeline.adtsStream = new adts();
|
15584 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
15585 | pipeline.headOfPipeline = pipeline.aacStream;
|
15586 | pipeline.aacStream.pipe(pipeline.audioTimestampRolloverStream).pipe(pipeline.adtsStream);
|
15587 | pipeline.aacStream.pipe(pipeline.timedMetadataTimestampRolloverStream).pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
15588 | pipeline.metadataStream.on('timestamp', function (frame) {
|
15589 | pipeline.aacStream.setTimestamp(frame.timeStamp);
|
15590 | });
|
15591 | pipeline.aacStream.on('data', function (data) {
|
15592 | if (data.type !== 'timed-metadata' && data.type !== 'audio' || pipeline.audioSegmentStream) {
|
15593 | return;
|
15594 | }
|
15595 |
|
15596 | audioTrack = audioTrack || {
|
15597 | timelineStartInfo: {
|
15598 | baseMediaDecodeTime: self.baseMediaDecodeTime
|
15599 | },
|
15600 | codec: 'adts',
|
15601 | type: 'audio'
|
15602 | };
|
15603 |
|
15604 | pipeline.coalesceStream.numberOfTracks++;
|
15605 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
15606 | pipeline.audioSegmentStream.on('log', self.getLogTrigger_('audioSegmentStream'));
|
15607 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
15608 |
|
15609 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
15610 |
|
15611 | self.trigger('trackinfo', {
|
15612 | hasAudio: !!audioTrack,
|
15613 | hasVideo: !!videoTrack
|
15614 | });
|
15615 | });
|
15616 |
|
15617 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
15618 |
|
15619 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
15620 | addPipelineLogRetriggers(this, pipeline);
|
15621 | };
|
15622 |
|
15623 | this.setupTsPipeline = function () {
|
15624 | var pipeline = {};
|
15625 | this.transmuxPipeline_ = pipeline;
|
15626 | pipeline.type = 'ts';
|
15627 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
15628 |
|
15629 | pipeline.packetStream = new m2ts_1.TransportPacketStream();
|
15630 | pipeline.parseStream = new m2ts_1.TransportParseStream();
|
15631 | pipeline.elementaryStream = new m2ts_1.ElementaryStream();
|
15632 | pipeline.timestampRolloverStream = new m2ts_1.TimestampRolloverStream();
|
15633 | pipeline.adtsStream = new adts();
|
15634 | pipeline.h264Stream = new H264Stream();
|
15635 | pipeline.captionStream = new m2ts_1.CaptionStream(options);
|
15636 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
15637 | pipeline.headOfPipeline = pipeline.packetStream;
|
15638 |
|
15639 | pipeline.packetStream.pipe(pipeline.parseStream).pipe(pipeline.elementaryStream).pipe(pipeline.timestampRolloverStream);
|
15640 |
|
15641 |
|
15642 | pipeline.timestampRolloverStream.pipe(pipeline.h264Stream);
|
15643 | pipeline.timestampRolloverStream.pipe(pipeline.adtsStream);
|
15644 | pipeline.timestampRolloverStream.pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
15645 |
|
15646 | pipeline.h264Stream.pipe(pipeline.captionStream).pipe(pipeline.coalesceStream);
|
15647 | pipeline.elementaryStream.on('data', function (data) {
|
15648 | var i;
|
15649 |
|
15650 | if (data.type === 'metadata') {
|
15651 | i = data.tracks.length;
|
15652 |
|
15653 | while (i--) {
|
15654 | if (!videoTrack && data.tracks[i].type === 'video') {
|
15655 | videoTrack = data.tracks[i];
|
15656 | videoTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
15657 | } else if (!audioTrack && data.tracks[i].type === 'audio') {
|
15658 | audioTrack = data.tracks[i];
|
15659 | audioTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
15660 | }
|
15661 | }
|
15662 |
|
15663 |
|
15664 | if (videoTrack && !pipeline.videoSegmentStream) {
|
15665 | pipeline.coalesceStream.numberOfTracks++;
|
15666 | pipeline.videoSegmentStream = new _VideoSegmentStream(videoTrack, options);
|
15667 | pipeline.videoSegmentStream.on('log', self.getLogTrigger_('videoSegmentStream'));
|
15668 | pipeline.videoSegmentStream.on('timelineStartInfo', function (timelineStartInfo) {
|
15669 |
|
15670 |
|
15671 |
|
15672 |
|
15673 | if (audioTrack && !options.keepOriginalTimestamps) {
|
15674 | audioTrack.timelineStartInfo = timelineStartInfo;
|
15675 |
|
15676 |
|
15677 |
|
15678 |
|
15679 | pipeline.audioSegmentStream.setEarliestDts(timelineStartInfo.dts - self.baseMediaDecodeTime);
|
15680 | }
|
15681 | });
|
15682 | pipeline.videoSegmentStream.on('processedGopsInfo', self.trigger.bind(self, 'gopInfo'));
|
15683 | pipeline.videoSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'videoSegmentTimingInfo'));
|
15684 | pipeline.videoSegmentStream.on('baseMediaDecodeTime', function (baseMediaDecodeTime) {
|
15685 | if (audioTrack) {
|
15686 | pipeline.audioSegmentStream.setVideoBaseMediaDecodeTime(baseMediaDecodeTime);
|
15687 | }
|
15688 | });
|
15689 | pipeline.videoSegmentStream.on('timingInfo', self.trigger.bind(self, 'videoTimingInfo'));
|
15690 |
|
15691 | pipeline.h264Stream.pipe(pipeline.videoSegmentStream).pipe(pipeline.coalesceStream);
|
15692 | }
|
15693 |
|
15694 | if (audioTrack && !pipeline.audioSegmentStream) {
|
15695 |
|
15696 | pipeline.coalesceStream.numberOfTracks++;
|
15697 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
15698 | pipeline.audioSegmentStream.on('log', self.getLogTrigger_('audioSegmentStream'));
|
15699 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
15700 | pipeline.audioSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'audioSegmentTimingInfo'));
|
15701 |
|
15702 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
15703 | }
|
15704 |
|
15705 |
|
15706 | self.trigger('trackinfo', {
|
15707 | hasAudio: !!audioTrack,
|
15708 | hasVideo: !!videoTrack
|
15709 | });
|
15710 | }
|
15711 | });
|
15712 |
|
15713 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
15714 | pipeline.coalesceStream.on('id3Frame', function (id3Frame) {
|
15715 | id3Frame.dispatchType = pipeline.metadataStream.dispatchType;
|
15716 | self.trigger('id3Frame', id3Frame);
|
15717 | });
|
15718 | pipeline.coalesceStream.on('caption', this.trigger.bind(this, 'caption'));
|
15719 |
|
15720 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
15721 | addPipelineLogRetriggers(this, pipeline);
|
15722 | };
|
15723 |
|
15724 |
|
15725 | this.setBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
15726 | var pipeline = this.transmuxPipeline_;
|
15727 |
|
15728 | if (!options.keepOriginalTimestamps) {
|
15729 | this.baseMediaDecodeTime = baseMediaDecodeTime;
|
15730 | }
|
15731 |
|
15732 | if (audioTrack) {
|
15733 | audioTrack.timelineStartInfo.dts = undefined;
|
15734 | audioTrack.timelineStartInfo.pts = undefined;
|
15735 | trackDecodeInfo.clearDtsInfo(audioTrack);
|
15736 |
|
15737 | if (pipeline.audioTimestampRolloverStream) {
|
15738 | pipeline.audioTimestampRolloverStream.discontinuity();
|
15739 | }
|
15740 | }
|
15741 |
|
15742 | if (videoTrack) {
|
15743 | if (pipeline.videoSegmentStream) {
|
15744 | pipeline.videoSegmentStream.gopCache_ = [];
|
15745 | }
|
15746 |
|
15747 | videoTrack.timelineStartInfo.dts = undefined;
|
15748 | videoTrack.timelineStartInfo.pts = undefined;
|
15749 | trackDecodeInfo.clearDtsInfo(videoTrack);
|
15750 | pipeline.captionStream.reset();
|
15751 | }
|
15752 |
|
15753 | if (pipeline.timestampRolloverStream) {
|
15754 | pipeline.timestampRolloverStream.discontinuity();
|
15755 | }
|
15756 | };
|
15757 |
|
15758 | this.setAudioAppendStart = function (timestamp) {
|
15759 | if (audioTrack) {
|
15760 | this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(timestamp);
|
15761 | }
|
15762 | };
|
15763 |
|
15764 | this.setRemux = function (val) {
|
15765 | var pipeline = this.transmuxPipeline_;
|
15766 | options.remux = val;
|
15767 |
|
15768 | if (pipeline && pipeline.coalesceStream) {
|
15769 | pipeline.coalesceStream.setRemux(val);
|
15770 | }
|
15771 | };
|
15772 |
|
15773 | this.alignGopsWith = function (gopsToAlignWith) {
|
15774 | if (videoTrack && this.transmuxPipeline_.videoSegmentStream) {
|
15775 | this.transmuxPipeline_.videoSegmentStream.alignGopsWith(gopsToAlignWith);
|
15776 | }
|
15777 | };
|
15778 |
|
15779 | this.getLogTrigger_ = function (key) {
|
15780 | var self = this;
|
15781 | return function (event) {
|
15782 | event.stream = key;
|
15783 | self.trigger('log', event);
|
15784 | };
|
15785 | };
|
15786 |
|
15787 |
|
15788 | this.push = function (data) {
|
15789 | if (hasFlushed) {
|
15790 | var isAac = isLikelyAacData(data);
|
15791 |
|
15792 | if (isAac && this.transmuxPipeline_.type !== 'aac') {
|
15793 | this.setupAacPipeline();
|
15794 | } else if (!isAac && this.transmuxPipeline_.type !== 'ts') {
|
15795 | this.setupTsPipeline();
|
15796 | }
|
15797 |
|
15798 | hasFlushed = false;
|
15799 | }
|
15800 |
|
15801 | this.transmuxPipeline_.headOfPipeline.push(data);
|
15802 | };
|
15803 |
|
15804 |
|
15805 | this.flush = function () {
|
15806 | hasFlushed = true;
|
15807 |
|
15808 | this.transmuxPipeline_.headOfPipeline.flush();
|
15809 | };
|
15810 |
|
15811 | this.endTimeline = function () {
|
15812 | this.transmuxPipeline_.headOfPipeline.endTimeline();
|
15813 | };
|
15814 |
|
15815 | this.reset = function () {
|
15816 | if (this.transmuxPipeline_.headOfPipeline) {
|
15817 | this.transmuxPipeline_.headOfPipeline.reset();
|
15818 | }
|
15819 | };
|
15820 |
|
15821 |
|
15822 | this.resetCaptions = function () {
|
15823 | if (this.transmuxPipeline_.captionStream) {
|
15824 | this.transmuxPipeline_.captionStream.reset();
|
15825 | }
|
15826 | };
|
15827 | };
|
15828 |
|
15829 | _Transmuxer.prototype = new stream();
|
15830 | var transmuxer = {
|
15831 | Transmuxer: _Transmuxer,
|
15832 | VideoSegmentStream: _VideoSegmentStream,
|
15833 | AudioSegmentStream: _AudioSegmentStream,
|
15834 | AUDIO_PROPERTIES: audioProperties,
|
15835 | VIDEO_PROPERTIES: videoProperties,
|
15836 |
|
15837 | generateSegmentTimingInfo: generateSegmentTimingInfo
|
15838 | };
|
15839 | |
15840 |
|
15841 |
|
15842 |
|
15843 |
|
15844 |
|
15845 |
|
15846 | var toUnsigned$3 = function toUnsigned(value) {
|
15847 | return value >>> 0;
|
15848 | };
|
15849 |
|
15850 | var toHexString$1 = function toHexString(value) {
|
15851 | return ('00' + value.toString(16)).slice(-2);
|
15852 | };
|
15853 |
|
15854 | var bin = {
|
15855 | toUnsigned: toUnsigned$3,
|
15856 | toHexString: toHexString$1
|
15857 | };
|
15858 |
|
15859 | var parseType$1 = function parseType(buffer) {
|
15860 | var result = '';
|
15861 | result += String.fromCharCode(buffer[0]);
|
15862 | result += String.fromCharCode(buffer[1]);
|
15863 | result += String.fromCharCode(buffer[2]);
|
15864 | result += String.fromCharCode(buffer[3]);
|
15865 | return result;
|
15866 | };
|
15867 |
|
15868 | var parseType_1 = parseType$1;
|
15869 | var toUnsigned$2 = bin.toUnsigned;
|
15870 |
|
15871 | var findBox = function findBox(data, path) {
|
15872 | var results = [],
|
15873 | i,
|
15874 | size,
|
15875 | type,
|
15876 | end,
|
15877 | subresults;
|
15878 |
|
15879 | if (!path.length) {
|
15880 |
|
15881 | return null;
|
15882 | }
|
15883 |
|
15884 | for (i = 0; i < data.byteLength;) {
|
15885 | size = toUnsigned$2(data[i] << 24 | data[i + 1] << 16 | data[i + 2] << 8 | data[i + 3]);
|
15886 | type = parseType_1(data.subarray(i + 4, i + 8));
|
15887 | end = size > 1 ? i + size : data.byteLength;
|
15888 |
|
15889 | if (type === path[0]) {
|
15890 | if (path.length === 1) {
|
15891 |
|
15892 |
|
15893 | results.push(data.subarray(i + 8, end));
|
15894 | } else {
|
15895 |
|
15896 | subresults = findBox(data.subarray(i + 8, end), path.slice(1));
|
15897 |
|
15898 | if (subresults.length) {
|
15899 | results = results.concat(subresults);
|
15900 | }
|
15901 | }
|
15902 | }
|
15903 |
|
15904 | i = end;
|
15905 | }
|
15906 |
|
15907 |
|
15908 | return results;
|
15909 | };
|
15910 |
|
15911 | var findBox_1 = findBox;
|
15912 | var toUnsigned$1 = bin.toUnsigned;
|
15913 |
|
15914 | var tfdt = function tfdt(data) {
|
15915 | var result = {
|
15916 | version: data[0],
|
15917 | flags: new Uint8Array(data.subarray(1, 4)),
|
15918 | baseMediaDecodeTime: toUnsigned$1(data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7])
|
15919 | };
|
15920 |
|
15921 | if (result.version === 1) {
|
15922 | result.baseMediaDecodeTime *= Math.pow(2, 32);
|
15923 | result.baseMediaDecodeTime += toUnsigned$1(data[8] << 24 | data[9] << 16 | data[10] << 8 | data[11]);
|
15924 | }
|
15925 |
|
15926 | return result;
|
15927 | };
|
15928 |
|
15929 | var parseTfdt = tfdt;
|
15930 |
|
15931 | var parseSampleFlags = function parseSampleFlags(flags) {
|
15932 | return {
|
15933 | isLeading: (flags[0] & 0x0c) >>> 2,
|
15934 | dependsOn: flags[0] & 0x03,
|
15935 | isDependedOn: (flags[1] & 0xc0) >>> 6,
|
15936 | hasRedundancy: (flags[1] & 0x30) >>> 4,
|
15937 | paddingValue: (flags[1] & 0x0e) >>> 1,
|
15938 | isNonSyncSample: flags[1] & 0x01,
|
15939 | degradationPriority: flags[2] << 8 | flags[3]
|
15940 | };
|
15941 | };
|
15942 |
|
15943 | var parseSampleFlags_1 = parseSampleFlags;
|
15944 |
|
15945 | var trun = function trun(data) {
|
15946 | var result = {
|
15947 | version: data[0],
|
15948 | flags: new Uint8Array(data.subarray(1, 4)),
|
15949 | samples: []
|
15950 | },
|
15951 | view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
15952 |
|
15953 | dataOffsetPresent = result.flags[2] & 0x01,
|
15954 |
|
15955 | firstSampleFlagsPresent = result.flags[2] & 0x04,
|
15956 |
|
15957 | sampleDurationPresent = result.flags[1] & 0x01,
|
15958 |
|
15959 | sampleSizePresent = result.flags[1] & 0x02,
|
15960 |
|
15961 | sampleFlagsPresent = result.flags[1] & 0x04,
|
15962 |
|
15963 | sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08,
|
15964 |
|
15965 | sampleCount = view.getUint32(4),
|
15966 | offset = 8,
|
15967 | sample;
|
15968 |
|
15969 | if (dataOffsetPresent) {
|
15970 |
|
15971 | result.dataOffset = view.getInt32(offset);
|
15972 | offset += 4;
|
15973 | }
|
15974 |
|
15975 |
|
15976 |
|
15977 | if (firstSampleFlagsPresent && sampleCount) {
|
15978 | sample = {
|
15979 | flags: parseSampleFlags_1(data.subarray(offset, offset + 4))
|
15980 | };
|
15981 | offset += 4;
|
15982 |
|
15983 | if (sampleDurationPresent) {
|
15984 | sample.duration = view.getUint32(offset);
|
15985 | offset += 4;
|
15986 | }
|
15987 |
|
15988 | if (sampleSizePresent) {
|
15989 | sample.size = view.getUint32(offset);
|
15990 | offset += 4;
|
15991 | }
|
15992 |
|
15993 | if (sampleCompositionTimeOffsetPresent) {
|
15994 | if (result.version === 1) {
|
15995 | sample.compositionTimeOffset = view.getInt32(offset);
|
15996 | } else {
|
15997 | sample.compositionTimeOffset = view.getUint32(offset);
|
15998 | }
|
15999 |
|
16000 | offset += 4;
|
16001 | }
|
16002 |
|
16003 | result.samples.push(sample);
|
16004 | sampleCount--;
|
16005 | }
|
16006 |
|
16007 | while (sampleCount--) {
|
16008 | sample = {};
|
16009 |
|
16010 | if (sampleDurationPresent) {
|
16011 | sample.duration = view.getUint32(offset);
|
16012 | offset += 4;
|
16013 | }
|
16014 |
|
16015 | if (sampleSizePresent) {
|
16016 | sample.size = view.getUint32(offset);
|
16017 | offset += 4;
|
16018 | }
|
16019 |
|
16020 | if (sampleFlagsPresent) {
|
16021 | sample.flags = parseSampleFlags_1(data.subarray(offset, offset + 4));
|
16022 | offset += 4;
|
16023 | }
|
16024 |
|
16025 | if (sampleCompositionTimeOffsetPresent) {
|
16026 | if (result.version === 1) {
|
16027 | sample.compositionTimeOffset = view.getInt32(offset);
|
16028 | } else {
|
16029 | sample.compositionTimeOffset = view.getUint32(offset);
|
16030 | }
|
16031 |
|
16032 | offset += 4;
|
16033 | }
|
16034 |
|
16035 | result.samples.push(sample);
|
16036 | }
|
16037 |
|
16038 | return result;
|
16039 | };
|
16040 |
|
16041 | var parseTrun = trun;
|
16042 |
|
16043 | var tfhd = function tfhd(data) {
|
16044 | var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
16045 | result = {
|
16046 | version: data[0],
|
16047 | flags: new Uint8Array(data.subarray(1, 4)),
|
16048 | trackId: view.getUint32(4)
|
16049 | },
|
16050 | baseDataOffsetPresent = result.flags[2] & 0x01,
|
16051 | sampleDescriptionIndexPresent = result.flags[2] & 0x02,
|
16052 | defaultSampleDurationPresent = result.flags[2] & 0x08,
|
16053 | defaultSampleSizePresent = result.flags[2] & 0x10,
|
16054 | defaultSampleFlagsPresent = result.flags[2] & 0x20,
|
16055 | durationIsEmpty = result.flags[0] & 0x010000,
|
16056 | defaultBaseIsMoof = result.flags[0] & 0x020000,
|
16057 | i;
|
16058 | i = 8;
|
16059 |
|
16060 | if (baseDataOffsetPresent) {
|
16061 | i += 4;
|
16062 |
|
16063 |
|
16064 | result.baseDataOffset = view.getUint32(12);
|
16065 | i += 4;
|
16066 | }
|
16067 |
|
16068 | if (sampleDescriptionIndexPresent) {
|
16069 | result.sampleDescriptionIndex = view.getUint32(i);
|
16070 | i += 4;
|
16071 | }
|
16072 |
|
16073 | if (defaultSampleDurationPresent) {
|
16074 | result.defaultSampleDuration = view.getUint32(i);
|
16075 | i += 4;
|
16076 | }
|
16077 |
|
16078 | if (defaultSampleSizePresent) {
|
16079 | result.defaultSampleSize = view.getUint32(i);
|
16080 | i += 4;
|
16081 | }
|
16082 |
|
16083 | if (defaultSampleFlagsPresent) {
|
16084 | result.defaultSampleFlags = view.getUint32(i);
|
16085 | }
|
16086 |
|
16087 | if (durationIsEmpty) {
|
16088 | result.durationIsEmpty = true;
|
16089 | }
|
16090 |
|
16091 | if (!baseDataOffsetPresent && defaultBaseIsMoof) {
|
16092 | result.baseDataOffsetIsMoof = true;
|
16093 | }
|
16094 |
|
16095 | return result;
|
16096 | };
|
16097 |
|
16098 | var parseTfhd = tfhd;
|
16099 | var discardEmulationPreventionBytes = captionPacketParser.discardEmulationPreventionBytes;
|
16100 | var CaptionStream = captionStream.CaptionStream;
|
16101 | |
16102 |
|
16103 |
|
16104 |
|
16105 |
|
16106 |
|
16107 |
|
16108 |
|
16109 |
|
16110 |
|
16111 |
|
16112 | var mapToSample = function mapToSample(offset, samples) {
|
16113 | var approximateOffset = offset;
|
16114 |
|
16115 | for (var i = 0; i < samples.length; i++) {
|
16116 | var sample = samples[i];
|
16117 |
|
16118 | if (approximateOffset < sample.size) {
|
16119 | return sample;
|
16120 | }
|
16121 |
|
16122 | approximateOffset -= sample.size;
|
16123 | }
|
16124 |
|
16125 | return null;
|
16126 | };
|
16127 | |
16128 |
|
16129 |
|
16130 |
|
16131 |
|
16132 |
|
16133 |
|
16134 |
|
16135 |
|
16136 |
|
16137 |
|
16138 |
|
16139 |
|
16140 |
|
16141 |
|
16142 |
|
16143 | var findSeiNals = function findSeiNals(avcStream, samples, trackId) {
|
16144 | var avcView = new DataView(avcStream.buffer, avcStream.byteOffset, avcStream.byteLength),
|
16145 | result = {
|
16146 | logs: [],
|
16147 | seiNals: []
|
16148 | },
|
16149 | seiNal,
|
16150 | i,
|
16151 | length,
|
16152 | lastMatchedSample;
|
16153 |
|
16154 | for (i = 0; i + 4 < avcStream.length; i += length) {
|
16155 | length = avcView.getUint32(i);
|
16156 | i += 4;
|
16157 |
|
16158 | if (length <= 0) {
|
16159 | continue;
|
16160 | }
|
16161 |
|
16162 | switch (avcStream[i] & 0x1F) {
|
16163 | case 0x06:
|
16164 | var data = avcStream.subarray(i + 1, i + 1 + length);
|
16165 | var matchingSample = mapToSample(i, samples);
|
16166 | seiNal = {
|
16167 | nalUnitType: 'sei_rbsp',
|
16168 | size: length,
|
16169 | data: data,
|
16170 | escapedRBSP: discardEmulationPreventionBytes(data),
|
16171 | trackId: trackId
|
16172 | };
|
16173 |
|
16174 | if (matchingSample) {
|
16175 | seiNal.pts = matchingSample.pts;
|
16176 | seiNal.dts = matchingSample.dts;
|
16177 | lastMatchedSample = matchingSample;
|
16178 | } else if (lastMatchedSample) {
|
16179 |
|
16180 |
|
16181 | seiNal.pts = lastMatchedSample.pts;
|
16182 | seiNal.dts = lastMatchedSample.dts;
|
16183 | } else {
|
16184 | result.logs.push({
|
16185 | level: 'warn',
|
16186 | message: 'We\'ve encountered a nal unit without data at ' + i + ' for trackId ' + trackId + '. See mux.js#223.'
|
16187 | });
|
16188 | break;
|
16189 | }
|
16190 |
|
16191 | result.seiNals.push(seiNal);
|
16192 | break;
|
16193 | }
|
16194 | }
|
16195 |
|
16196 | return result;
|
16197 | };
|
16198 | |
16199 |
|
16200 |
|
16201 |
|
16202 |
|
16203 |
|
16204 |
|
16205 |
|
16206 |
|
16207 |
|
16208 |
|
16209 |
|
16210 |
|
16211 |
|
16212 |
|
16213 | var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
|
16214 | var currentDts = baseMediaDecodeTime;
|
16215 | var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
|
16216 | var defaultSampleSize = tfhd.defaultSampleSize || 0;
|
16217 | var trackId = tfhd.trackId;
|
16218 | var allSamples = [];
|
16219 | truns.forEach(function (trun) {
|
16220 |
|
16221 |
|
16222 |
|
16223 | var trackRun = parseTrun(trun);
|
16224 | var samples = trackRun.samples;
|
16225 | samples.forEach(function (sample) {
|
16226 | if (sample.duration === undefined) {
|
16227 | sample.duration = defaultSampleDuration;
|
16228 | }
|
16229 |
|
16230 | if (sample.size === undefined) {
|
16231 | sample.size = defaultSampleSize;
|
16232 | }
|
16233 |
|
16234 | sample.trackId = trackId;
|
16235 | sample.dts = currentDts;
|
16236 |
|
16237 | if (sample.compositionTimeOffset === undefined) {
|
16238 | sample.compositionTimeOffset = 0;
|
16239 | }
|
16240 |
|
16241 | sample.pts = currentDts + sample.compositionTimeOffset;
|
16242 | currentDts += sample.duration;
|
16243 | });
|
16244 | allSamples = allSamples.concat(samples);
|
16245 | });
|
16246 | return allSamples;
|
16247 | };
|
16248 | |
16249 |
|
16250 |
|
16251 |
|
16252 |
|
16253 |
|
16254 |
|
16255 |
|
16256 |
|
16257 |
|
16258 | var parseCaptionNals = function parseCaptionNals(segment, videoTrackId) {
|
16259 |
|
16260 | var trafs = findBox_1(segment, ['moof', 'traf']);
|
16261 |
|
16262 | var mdats = findBox_1(segment, ['mdat']);
|
16263 | var captionNals = {};
|
16264 | var mdatTrafPairs = [];
|
16265 |
|
16266 | mdats.forEach(function (mdat, index) {
|
16267 | var matchingTraf = trafs[index];
|
16268 | mdatTrafPairs.push({
|
16269 | mdat: mdat,
|
16270 | traf: matchingTraf
|
16271 | });
|
16272 | });
|
16273 | mdatTrafPairs.forEach(function (pair) {
|
16274 | var mdat = pair.mdat;
|
16275 | var traf = pair.traf;
|
16276 | var tfhd = findBox_1(traf, ['tfhd']);
|
16277 |
|
16278 | var headerInfo = parseTfhd(tfhd[0]);
|
16279 | var trackId = headerInfo.trackId;
|
16280 | var tfdt = findBox_1(traf, ['tfdt']);
|
16281 |
|
16282 | var baseMediaDecodeTime = tfdt.length > 0 ? parseTfdt(tfdt[0]).baseMediaDecodeTime : 0;
|
16283 | var truns = findBox_1(traf, ['trun']);
|
16284 | var samples;
|
16285 | var result;
|
16286 |
|
16287 | if (videoTrackId === trackId && truns.length > 0) {
|
16288 | samples = parseSamples(truns, baseMediaDecodeTime, headerInfo);
|
16289 | result = findSeiNals(mdat, samples, trackId);
|
16290 |
|
16291 | if (!captionNals[trackId]) {
|
16292 | captionNals[trackId] = {
|
16293 | seiNals: [],
|
16294 | logs: []
|
16295 | };
|
16296 | }
|
16297 |
|
16298 | captionNals[trackId].seiNals = captionNals[trackId].seiNals.concat(result.seiNals);
|
16299 | captionNals[trackId].logs = captionNals[trackId].logs.concat(result.logs);
|
16300 | }
|
16301 | });
|
16302 | return captionNals;
|
16303 | };
|
16304 | |
16305 |
|
16306 |
|
16307 |
|
16308 |
|
16309 |
|
16310 |
|
16311 |
|
16312 |
|
16313 |
|
16314 |
|
16315 |
|
16316 |
|
16317 |
|
16318 |
|
16319 |
|
16320 |
|
16321 |
|
16322 | var parseEmbeddedCaptions = function parseEmbeddedCaptions(segment, trackId, timescale) {
|
16323 | var captionNals;
|
16324 |
|
16325 | if (trackId === null) {
|
16326 | return null;
|
16327 | }
|
16328 |
|
16329 | captionNals = parseCaptionNals(segment, trackId);
|
16330 | var trackNals = captionNals[trackId] || {};
|
16331 | return {
|
16332 | seiNals: trackNals.seiNals,
|
16333 | logs: trackNals.logs,
|
16334 | timescale: timescale
|
16335 | };
|
16336 | };
|
16337 | |
16338 |
|
16339 |
|
16340 |
|
16341 |
|
16342 | var CaptionParser = function CaptionParser() {
|
16343 | var isInitialized = false;
|
16344 | var captionStream;
|
16345 |
|
16346 | var segmentCache;
|
16347 |
|
16348 | var trackId;
|
16349 |
|
16350 | var timescale;
|
16351 |
|
16352 | var parsedCaptions;
|
16353 |
|
16354 | var parsingPartial;
|
16355 | |
16356 |
|
16357 |
|
16358 |
|
16359 |
|
16360 | this.isInitialized = function () {
|
16361 | return isInitialized;
|
16362 | };
|
16363 | |
16364 |
|
16365 |
|
16366 |
|
16367 |
|
16368 |
|
16369 | this.init = function (options) {
|
16370 | captionStream = new CaptionStream();
|
16371 | isInitialized = true;
|
16372 | parsingPartial = options ? options.isPartial : false;
|
16373 |
|
16374 | captionStream.on('data', function (event) {
|
16375 |
|
16376 | event.startTime = event.startPts / timescale;
|
16377 | event.endTime = event.endPts / timescale;
|
16378 | parsedCaptions.captions.push(event);
|
16379 | parsedCaptions.captionStreams[event.stream] = true;
|
16380 | });
|
16381 | captionStream.on('log', function (log) {
|
16382 | parsedCaptions.logs.push(log);
|
16383 | });
|
16384 | };
|
16385 | |
16386 |
|
16387 |
|
16388 |
|
16389 |
|
16390 |
|
16391 |
|
16392 | this.isNewInit = function (videoTrackIds, timescales) {
|
16393 | if (videoTrackIds && videoTrackIds.length === 0 || timescales && typeof timescales === 'object' && Object.keys(timescales).length === 0) {
|
16394 | return false;
|
16395 | }
|
16396 |
|
16397 | return trackId !== videoTrackIds[0] || timescale !== timescales[trackId];
|
16398 | };
|
16399 | |
16400 |
|
16401 |
|
16402 |
|
16403 |
|
16404 |
|
16405 |
|
16406 |
|
16407 |
|
16408 |
|
16409 |
|
16410 |
|
16411 | this.parse = function (segment, videoTrackIds, timescales) {
|
16412 | var parsedData;
|
16413 |
|
16414 | if (!this.isInitialized()) {
|
16415 | return null;
|
16416 | } else if (!videoTrackIds || !timescales) {
|
16417 | return null;
|
16418 | } else if (this.isNewInit(videoTrackIds, timescales)) {
|
16419 |
|
16420 |
|
16421 | trackId = videoTrackIds[0];
|
16422 | timescale = timescales[trackId];
|
16423 |
|
16424 |
|
16425 | } else if (trackId === null || !timescale) {
|
16426 | segmentCache.push(segment);
|
16427 | return null;
|
16428 | }
|
16429 |
|
16430 |
|
16431 | while (segmentCache.length > 0) {
|
16432 | var cachedSegment = segmentCache.shift();
|
16433 | this.parse(cachedSegment, videoTrackIds, timescales);
|
16434 | }
|
16435 |
|
16436 | parsedData = parseEmbeddedCaptions(segment, trackId, timescale);
|
16437 |
|
16438 | if (parsedData && parsedData.logs) {
|
16439 | parsedCaptions.logs = parsedCaptions.logs.concat(parsedData.logs);
|
16440 | }
|
16441 |
|
16442 | if (parsedData === null || !parsedData.seiNals) {
|
16443 | if (parsedCaptions.logs.length) {
|
16444 | return {
|
16445 | logs: parsedCaptions.logs,
|
16446 | captions: [],
|
16447 | captionStreams: []
|
16448 | };
|
16449 | }
|
16450 |
|
16451 | return null;
|
16452 | }
|
16453 |
|
16454 | this.pushNals(parsedData.seiNals);
|
16455 |
|
16456 | this.flushStream();
|
16457 | return parsedCaptions;
|
16458 | };
|
16459 | |
16460 |
|
16461 |
|
16462 |
|
16463 |
|
16464 |
|
16465 |
|
16466 |
|
16467 | this.pushNals = function (nals) {
|
16468 | if (!this.isInitialized() || !nals || nals.length === 0) {
|
16469 | return null;
|
16470 | }
|
16471 |
|
16472 | nals.forEach(function (nal) {
|
16473 | captionStream.push(nal);
|
16474 | });
|
16475 | };
|
16476 | |
16477 |
|
16478 |
|
16479 |
|
16480 |
|
16481 |
|
16482 | this.flushStream = function () {
|
16483 | if (!this.isInitialized()) {
|
16484 | return null;
|
16485 | }
|
16486 |
|
16487 | if (!parsingPartial) {
|
16488 | captionStream.flush();
|
16489 | } else {
|
16490 | captionStream.partialFlush();
|
16491 | }
|
16492 | };
|
16493 | |
16494 |
|
16495 |
|
16496 |
|
16497 |
|
16498 | this.clearParsedCaptions = function () {
|
16499 | parsedCaptions.captions = [];
|
16500 | parsedCaptions.captionStreams = {};
|
16501 | parsedCaptions.logs = [];
|
16502 | };
|
16503 | |
16504 |
|
16505 |
|
16506 |
|
16507 |
|
16508 |
|
16509 | this.resetCaptionStream = function () {
|
16510 | if (!this.isInitialized()) {
|
16511 | return null;
|
16512 | }
|
16513 |
|
16514 | captionStream.reset();
|
16515 | };
|
16516 | |
16517 |
|
16518 |
|
16519 |
|
16520 |
|
16521 |
|
16522 |
|
16523 | this.clearAllCaptions = function () {
|
16524 | this.clearParsedCaptions();
|
16525 | this.resetCaptionStream();
|
16526 | };
|
16527 | |
16528 |
|
16529 |
|
16530 |
|
16531 |
|
16532 | this.reset = function () {
|
16533 | segmentCache = [];
|
16534 | trackId = null;
|
16535 | timescale = null;
|
16536 |
|
16537 | if (!parsedCaptions) {
|
16538 | parsedCaptions = {
|
16539 | captions: [],
|
16540 |
|
16541 | captionStreams: {},
|
16542 | logs: []
|
16543 | };
|
16544 | } else {
|
16545 | this.clearParsedCaptions();
|
16546 | }
|
16547 |
|
16548 | this.resetCaptionStream();
|
16549 | };
|
16550 |
|
16551 | this.reset();
|
16552 | };
|
16553 |
|
16554 | var captionParser = CaptionParser;
|
16555 | var toUnsigned = bin.toUnsigned;
|
16556 | var toHexString = bin.toHexString;
|
16557 | var timescale, startTime, compositionStartTime, getVideoTrackIds, getTracks, getTimescaleFromMediaHeader;
|
16558 | |
16559 |
|
16560 |
|
16561 |
|
16562 |
|
16563 |
|
16564 |
|
16565 |
|
16566 |
|
16567 |
|
16568 |
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 |
|
16574 |
|
16575 |
|
16576 |
|
16577 | timescale = function timescale(init) {
|
16578 | var result = {},
|
16579 | traks = findBox_1(init, ['moov', 'trak']);
|
16580 |
|
16581 | return traks.reduce(function (result, trak) {
|
16582 | var tkhd, version, index, id, mdhd;
|
16583 | tkhd = findBox_1(trak, ['tkhd'])[0];
|
16584 |
|
16585 | if (!tkhd) {
|
16586 | return null;
|
16587 | }
|
16588 |
|
16589 | version = tkhd[0];
|
16590 | index = version === 0 ? 12 : 20;
|
16591 | id = toUnsigned(tkhd[index] << 24 | tkhd[index + 1] << 16 | tkhd[index + 2] << 8 | tkhd[index + 3]);
|
16592 | mdhd = findBox_1(trak, ['mdia', 'mdhd'])[0];
|
16593 |
|
16594 | if (!mdhd) {
|
16595 | return null;
|
16596 | }
|
16597 |
|
16598 | version = mdhd[0];
|
16599 | index = version === 0 ? 12 : 20;
|
16600 | result[id] = toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]);
|
16601 | return result;
|
16602 | }, result);
|
16603 | };
|
16604 | |
16605 |
|
16606 |
|
16607 |
|
16608 |
|
16609 |
|
16610 |
|
16611 |
|
16612 |
|
16613 |
|
16614 |
|
16615 |
|
16616 |
|
16617 |
|
16618 |
|
16619 |
|
16620 |
|
16621 |
|
16622 | startTime = function startTime(timescale, fragment) {
|
16623 | var trafs, baseTimes, result;
|
16624 |
|
16625 | trafs = findBox_1(fragment, ['moof', 'traf']);
|
16626 |
|
16627 | baseTimes = [].concat.apply([], trafs.map(function (traf) {
|
16628 | return findBox_1(traf, ['tfhd']).map(function (tfhd) {
|
16629 | var id, scale, baseTime;
|
16630 |
|
16631 | id = toUnsigned(tfhd[4] << 24 | tfhd[5] << 16 | tfhd[6] << 8 | tfhd[7]);
|
16632 |
|
16633 | scale = timescale[id] || 90e3;
|
16634 |
|
16635 | baseTime = findBox_1(traf, ['tfdt']).map(function (tfdt) {
|
16636 | var version, result;
|
16637 | version = tfdt[0];
|
16638 | result = toUnsigned(tfdt[4] << 24 | tfdt[5] << 16 | tfdt[6] << 8 | tfdt[7]);
|
16639 |
|
16640 | if (version === 1) {
|
16641 | result *= Math.pow(2, 32);
|
16642 | result += toUnsigned(tfdt[8] << 24 | tfdt[9] << 16 | tfdt[10] << 8 | tfdt[11]);
|
16643 | }
|
16644 |
|
16645 | return result;
|
16646 | })[0];
|
16647 | baseTime = typeof baseTime === 'number' && !isNaN(baseTime) ? baseTime : Infinity;
|
16648 |
|
16649 | return baseTime / scale;
|
16650 | });
|
16651 | }));
|
16652 |
|
16653 | result = Math.min.apply(null, baseTimes);
|
16654 | return isFinite(result) ? result : 0;
|
16655 | };
|
16656 | |
16657 |
|
16658 |
|
16659 |
|
16660 |
|
16661 |
|
16662 |
|
16663 |
|
16664 |
|
16665 |
|
16666 |
|
16667 |
|
16668 |
|
16669 |
|
16670 |
|
16671 |
|
16672 |
|
16673 |
|
16674 |
|
16675 |
|
16676 |
|
16677 | compositionStartTime = function compositionStartTime(timescales, fragment) {
|
16678 | var trafBoxes = findBox_1(fragment, ['moof', 'traf']);
|
16679 | var baseMediaDecodeTime = 0;
|
16680 | var compositionTimeOffset = 0;
|
16681 | var trackId;
|
16682 |
|
16683 | if (trafBoxes && trafBoxes.length) {
|
16684 |
|
16685 |
|
16686 |
|
16687 | var tfhd = findBox_1(trafBoxes[0], ['tfhd'])[0];
|
16688 | var trun = findBox_1(trafBoxes[0], ['trun'])[0];
|
16689 | var tfdt = findBox_1(trafBoxes[0], ['tfdt'])[0];
|
16690 |
|
16691 | if (tfhd) {
|
16692 | var parsedTfhd = parseTfhd(tfhd);
|
16693 | trackId = parsedTfhd.trackId;
|
16694 | }
|
16695 |
|
16696 | if (tfdt) {
|
16697 | var parsedTfdt = parseTfdt(tfdt);
|
16698 | baseMediaDecodeTime = parsedTfdt.baseMediaDecodeTime;
|
16699 | }
|
16700 |
|
16701 | if (trun) {
|
16702 | var parsedTrun = parseTrun(trun);
|
16703 |
|
16704 | if (parsedTrun.samples && parsedTrun.samples.length) {
|
16705 | compositionTimeOffset = parsedTrun.samples[0].compositionTimeOffset || 0;
|
16706 | }
|
16707 | }
|
16708 | }
|
16709 |
|
16710 |
|
16711 |
|
16712 | var timescale = timescales[trackId] || 90e3;
|
16713 |
|
16714 | return (baseMediaDecodeTime + compositionTimeOffset) / timescale;
|
16715 | };
|
16716 | |
16717 |
|
16718 |
|
16719 |
|
16720 |
|
16721 |
|
16722 |
|
16723 |
|
16724 |
|
16725 |
|
16726 |
|
16727 |
|
16728 |
|
16729 | getVideoTrackIds = function getVideoTrackIds(init) {
|
16730 | var traks = findBox_1(init, ['moov', 'trak']);
|
16731 | var videoTrackIds = [];
|
16732 | traks.forEach(function (trak) {
|
16733 | var hdlrs = findBox_1(trak, ['mdia', 'hdlr']);
|
16734 | var tkhds = findBox_1(trak, ['tkhd']);
|
16735 | hdlrs.forEach(function (hdlr, index) {
|
16736 | var handlerType = parseType_1(hdlr.subarray(8, 12));
|
16737 | var tkhd = tkhds[index];
|
16738 | var view;
|
16739 | var version;
|
16740 | var trackId;
|
16741 |
|
16742 | if (handlerType === 'vide') {
|
16743 | view = new DataView(tkhd.buffer, tkhd.byteOffset, tkhd.byteLength);
|
16744 | version = view.getUint8(0);
|
16745 | trackId = version === 0 ? view.getUint32(12) : view.getUint32(20);
|
16746 | videoTrackIds.push(trackId);
|
16747 | }
|
16748 | });
|
16749 | });
|
16750 | return videoTrackIds;
|
16751 | };
|
16752 |
|
16753 | getTimescaleFromMediaHeader = function getTimescaleFromMediaHeader(mdhd) {
|
16754 |
|
16755 | var version = mdhd[0];
|
16756 | var index = version === 0 ? 12 : 20;
|
16757 | return toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]);
|
16758 | };
|
16759 | |
16760 |
|
16761 |
|
16762 |
|
16763 |
|
16764 |
|
16765 | getTracks = function getTracks(init) {
|
16766 | var traks = findBox_1(init, ['moov', 'trak']);
|
16767 | var tracks = [];
|
16768 | traks.forEach(function (trak) {
|
16769 | var track = {};
|
16770 | var tkhd = findBox_1(trak, ['tkhd'])[0];
|
16771 | var view, tkhdVersion;
|
16772 |
|
16773 | if (tkhd) {
|
16774 | view = new DataView(tkhd.buffer, tkhd.byteOffset, tkhd.byteLength);
|
16775 | tkhdVersion = view.getUint8(0);
|
16776 | track.id = tkhdVersion === 0 ? view.getUint32(12) : view.getUint32(20);
|
16777 | }
|
16778 |
|
16779 | var hdlr = findBox_1(trak, ['mdia', 'hdlr'])[0];
|
16780 |
|
16781 | if (hdlr) {
|
16782 | var type = parseType_1(hdlr.subarray(8, 12));
|
16783 |
|
16784 | if (type === 'vide') {
|
16785 | track.type = 'video';
|
16786 | } else if (type === 'soun') {
|
16787 | track.type = 'audio';
|
16788 | } else {
|
16789 | track.type = type;
|
16790 | }
|
16791 | }
|
16792 |
|
16793 |
|
16794 | var stsd = findBox_1(trak, ['mdia', 'minf', 'stbl', 'stsd'])[0];
|
16795 |
|
16796 | if (stsd) {
|
16797 | var sampleDescriptions = stsd.subarray(8);
|
16798 |
|
16799 | track.codec = parseType_1(sampleDescriptions.subarray(4, 8));
|
16800 | var codecBox = findBox_1(sampleDescriptions, [track.codec])[0];
|
16801 | var codecConfig, codecConfigType;
|
16802 |
|
16803 | if (codecBox) {
|
16804 |
|
16805 | if (/^[asm]vc[1-9]$/i.test(track.codec)) {
|
16806 |
|
16807 |
|
16808 | codecConfig = codecBox.subarray(78);
|
16809 | codecConfigType = parseType_1(codecConfig.subarray(4, 8));
|
16810 |
|
16811 | if (codecConfigType === 'avcC' && codecConfig.length > 11) {
|
16812 | track.codec += '.';
|
16813 |
|
16814 |
|
16815 | track.codec += toHexString(codecConfig[9]);
|
16816 |
|
16817 | track.codec += toHexString(codecConfig[10]);
|
16818 |
|
16819 | track.codec += toHexString(codecConfig[11]);
|
16820 | } else {
|
16821 |
|
16822 |
|
16823 | track.codec = 'avc1.4d400d';
|
16824 | }
|
16825 | } else if (/^mp4[a,v]$/i.test(track.codec)) {
|
16826 |
|
16827 | codecConfig = codecBox.subarray(28);
|
16828 | codecConfigType = parseType_1(codecConfig.subarray(4, 8));
|
16829 |
|
16830 | if (codecConfigType === 'esds' && codecConfig.length > 20 && codecConfig[19] !== 0) {
|
16831 | track.codec += '.' + toHexString(codecConfig[19]);
|
16832 |
|
16833 | track.codec += '.' + toHexString(codecConfig[20] >>> 2 & 0x3f).replace(/^0/, '');
|
16834 | } else {
|
16835 |
|
16836 |
|
16837 | track.codec = 'mp4a.40.2';
|
16838 | }
|
16839 | } else {
|
16840 |
|
16841 | track.codec = track.codec.toLowerCase();
|
16842 | }
|
16843 | }
|
16844 | }
|
16845 |
|
16846 | var mdhd = findBox_1(trak, ['mdia', 'mdhd'])[0];
|
16847 |
|
16848 | if (mdhd) {
|
16849 | track.timescale = getTimescaleFromMediaHeader(mdhd);
|
16850 | }
|
16851 |
|
16852 | tracks.push(track);
|
16853 | });
|
16854 | return tracks;
|
16855 | };
|
16856 |
|
16857 | var probe$2 = {
|
16858 |
|
16859 | findBox: findBox_1,
|
16860 | parseType: parseType_1,
|
16861 | timescale: timescale,
|
16862 | startTime: startTime,
|
16863 | compositionStartTime: compositionStartTime,
|
16864 | videoTrackIds: getVideoTrackIds,
|
16865 | tracks: getTracks,
|
16866 | getTimescaleFromMediaHeader: getTimescaleFromMediaHeader
|
16867 | };
|
16868 |
|
16869 | var parsePid = function parsePid(packet) {
|
16870 | var pid = packet[1] & 0x1f;
|
16871 | pid <<= 8;
|
16872 | pid |= packet[2];
|
16873 | return pid;
|
16874 | };
|
16875 |
|
16876 | var parsePayloadUnitStartIndicator = function parsePayloadUnitStartIndicator(packet) {
|
16877 | return !!(packet[1] & 0x40);
|
16878 | };
|
16879 |
|
16880 | var parseAdaptionField = function parseAdaptionField(packet) {
|
16881 | var offset = 0;
|
16882 |
|
16883 |
|
16884 |
|
16885 |
|
16886 |
|
16887 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
16888 | offset += packet[4] + 1;
|
16889 | }
|
16890 |
|
16891 | return offset;
|
16892 | };
|
16893 |
|
16894 | var parseType = function parseType(packet, pmtPid) {
|
16895 | var pid = parsePid(packet);
|
16896 |
|
16897 | if (pid === 0) {
|
16898 | return 'pat';
|
16899 | } else if (pid === pmtPid) {
|
16900 | return 'pmt';
|
16901 | } else if (pmtPid) {
|
16902 | return 'pes';
|
16903 | }
|
16904 |
|
16905 | return null;
|
16906 | };
|
16907 |
|
16908 | var parsePat = function parsePat(packet) {
|
16909 | var pusi = parsePayloadUnitStartIndicator(packet);
|
16910 | var offset = 4 + parseAdaptionField(packet);
|
16911 |
|
16912 | if (pusi) {
|
16913 | offset += packet[offset] + 1;
|
16914 | }
|
16915 |
|
16916 | return (packet[offset + 10] & 0x1f) << 8 | packet[offset + 11];
|
16917 | };
|
16918 |
|
16919 | var parsePmt = function parsePmt(packet) {
|
16920 | var programMapTable = {};
|
16921 | var pusi = parsePayloadUnitStartIndicator(packet);
|
16922 | var payloadOffset = 4 + parseAdaptionField(packet);
|
16923 |
|
16924 | if (pusi) {
|
16925 | payloadOffset += packet[payloadOffset] + 1;
|
16926 | }
|
16927 |
|
16928 |
|
16929 |
|
16930 |
|
16931 |
|
16932 |
|
16933 | if (!(packet[payloadOffset + 5] & 0x01)) {
|
16934 | return;
|
16935 | }
|
16936 |
|
16937 | var sectionLength, tableEnd, programInfoLength;
|
16938 |
|
16939 | sectionLength = (packet[payloadOffset + 1] & 0x0f) << 8 | packet[payloadOffset + 2];
|
16940 | tableEnd = 3 + sectionLength - 4;
|
16941 |
|
16942 |
|
16943 | programInfoLength = (packet[payloadOffset + 10] & 0x0f) << 8 | packet[payloadOffset + 11];
|
16944 |
|
16945 | var offset = 12 + programInfoLength;
|
16946 |
|
16947 | while (offset < tableEnd) {
|
16948 | var i = payloadOffset + offset;
|
16949 |
|
16950 | programMapTable[(packet[i + 1] & 0x1F) << 8 | packet[i + 2]] = packet[i];
|
16951 |
|
16952 |
|
16953 | offset += ((packet[i + 3] & 0x0F) << 8 | packet[i + 4]) + 5;
|
16954 | }
|
16955 |
|
16956 | return programMapTable;
|
16957 | };
|
16958 |
|
16959 | var parsePesType = function parsePesType(packet, programMapTable) {
|
16960 | var pid = parsePid(packet);
|
16961 | var type = programMapTable[pid];
|
16962 |
|
16963 | switch (type) {
|
16964 | case streamTypes.H264_STREAM_TYPE:
|
16965 | return 'video';
|
16966 |
|
16967 | case streamTypes.ADTS_STREAM_TYPE:
|
16968 | return 'audio';
|
16969 |
|
16970 | case streamTypes.METADATA_STREAM_TYPE:
|
16971 | return 'timed-metadata';
|
16972 |
|
16973 | default:
|
16974 | return null;
|
16975 | }
|
16976 | };
|
16977 |
|
16978 | var parsePesTime = function parsePesTime(packet) {
|
16979 | var pusi = parsePayloadUnitStartIndicator(packet);
|
16980 |
|
16981 | if (!pusi) {
|
16982 | return null;
|
16983 | }
|
16984 |
|
16985 | var offset = 4 + parseAdaptionField(packet);
|
16986 |
|
16987 | if (offset >= packet.byteLength) {
|
16988 |
|
16989 |
|
16990 |
|
16991 |
|
16992 |
|
16993 |
|
16994 |
|
16995 |
|
16996 |
|
16997 |
|
16998 | return null;
|
16999 | }
|
17000 |
|
17001 | var pes = null;
|
17002 | var ptsDtsFlags;
|
17003 |
|
17004 |
|
17005 |
|
17006 | ptsDtsFlags = packet[offset + 7];
|
17007 |
|
17008 |
|
17009 |
|
17010 |
|
17011 |
|
17012 |
|
17013 |
|
17014 |
|
17015 | if (ptsDtsFlags & 0xC0) {
|
17016 | pes = {};
|
17017 |
|
17018 |
|
17019 |
|
17020 | pes.pts = (packet[offset + 9] & 0x0E) << 27 | (packet[offset + 10] & 0xFF) << 20 | (packet[offset + 11] & 0xFE) << 12 | (packet[offset + 12] & 0xFF) << 5 | (packet[offset + 13] & 0xFE) >>> 3;
|
17021 | pes.pts *= 4;
|
17022 |
|
17023 | pes.pts += (packet[offset + 13] & 0x06) >>> 1;
|
17024 |
|
17025 | pes.dts = pes.pts;
|
17026 |
|
17027 | if (ptsDtsFlags & 0x40) {
|
17028 | pes.dts = (packet[offset + 14] & 0x0E) << 27 | (packet[offset + 15] & 0xFF) << 20 | (packet[offset + 16] & 0xFE) << 12 | (packet[offset + 17] & 0xFF) << 5 | (packet[offset + 18] & 0xFE) >>> 3;
|
17029 | pes.dts *= 4;
|
17030 |
|
17031 | pes.dts += (packet[offset + 18] & 0x06) >>> 1;
|
17032 | }
|
17033 | }
|
17034 |
|
17035 | return pes;
|
17036 | };
|
17037 |
|
17038 | var parseNalUnitType = function parseNalUnitType(type) {
|
17039 | switch (type) {
|
17040 | case 0x05:
|
17041 | return 'slice_layer_without_partitioning_rbsp_idr';
|
17042 |
|
17043 | case 0x06:
|
17044 | return 'sei_rbsp';
|
17045 |
|
17046 | case 0x07:
|
17047 | return 'seq_parameter_set_rbsp';
|
17048 |
|
17049 | case 0x08:
|
17050 | return 'pic_parameter_set_rbsp';
|
17051 |
|
17052 | case 0x09:
|
17053 | return 'access_unit_delimiter_rbsp';
|
17054 |
|
17055 | default:
|
17056 | return null;
|
17057 | }
|
17058 | };
|
17059 |
|
17060 | var videoPacketContainsKeyFrame = function videoPacketContainsKeyFrame(packet) {
|
17061 | var offset = 4 + parseAdaptionField(packet);
|
17062 | var frameBuffer = packet.subarray(offset);
|
17063 | var frameI = 0;
|
17064 | var frameSyncPoint = 0;
|
17065 | var foundKeyFrame = false;
|
17066 | var nalType;
|
17067 |
|
17068 | for (; frameSyncPoint < frameBuffer.byteLength - 3; frameSyncPoint++) {
|
17069 | if (frameBuffer[frameSyncPoint + 2] === 1) {
|
17070 |
|
17071 | frameI = frameSyncPoint + 5;
|
17072 | break;
|
17073 | }
|
17074 | }
|
17075 |
|
17076 | while (frameI < frameBuffer.byteLength) {
|
17077 |
|
17078 |
|
17079 | switch (frameBuffer[frameI]) {
|
17080 | case 0:
|
17081 |
|
17082 | if (frameBuffer[frameI - 1] !== 0) {
|
17083 | frameI += 2;
|
17084 | break;
|
17085 | } else if (frameBuffer[frameI - 2] !== 0) {
|
17086 | frameI++;
|
17087 | break;
|
17088 | }
|
17089 |
|
17090 | if (frameSyncPoint + 3 !== frameI - 2) {
|
17091 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
17092 |
|
17093 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
17094 | foundKeyFrame = true;
|
17095 | }
|
17096 | }
|
17097 |
|
17098 |
|
17099 | do {
|
17100 | frameI++;
|
17101 | } while (frameBuffer[frameI] !== 1 && frameI < frameBuffer.length);
|
17102 |
|
17103 | frameSyncPoint = frameI - 2;
|
17104 | frameI += 3;
|
17105 | break;
|
17106 |
|
17107 | case 1:
|
17108 |
|
17109 | if (frameBuffer[frameI - 1] !== 0 || frameBuffer[frameI - 2] !== 0) {
|
17110 | frameI += 3;
|
17111 | break;
|
17112 | }
|
17113 |
|
17114 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
17115 |
|
17116 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
17117 | foundKeyFrame = true;
|
17118 | }
|
17119 |
|
17120 | frameSyncPoint = frameI - 2;
|
17121 | frameI += 3;
|
17122 | break;
|
17123 |
|
17124 | default:
|
17125 |
|
17126 |
|
17127 | frameI += 3;
|
17128 | break;
|
17129 | }
|
17130 | }
|
17131 |
|
17132 | frameBuffer = frameBuffer.subarray(frameSyncPoint);
|
17133 | frameI -= frameSyncPoint;
|
17134 | frameSyncPoint = 0;
|
17135 |
|
17136 | if (frameBuffer && frameBuffer.byteLength > 3) {
|
17137 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
17138 |
|
17139 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
17140 | foundKeyFrame = true;
|
17141 | }
|
17142 | }
|
17143 |
|
17144 | return foundKeyFrame;
|
17145 | };
|
17146 |
|
17147 | var probe$1 = {
|
17148 | parseType: parseType,
|
17149 | parsePat: parsePat,
|
17150 | parsePmt: parsePmt,
|
17151 | parsePayloadUnitStartIndicator: parsePayloadUnitStartIndicator,
|
17152 | parsePesType: parsePesType,
|
17153 | parsePesTime: parsePesTime,
|
17154 | videoPacketContainsKeyFrame: videoPacketContainsKeyFrame
|
17155 | };
|
17156 | var handleRollover = timestampRolloverStream.handleRollover;
|
17157 | var probe = {};
|
17158 | probe.ts = probe$1;
|
17159 | probe.aac = utils;
|
17160 | var ONE_SECOND_IN_TS = clock.ONE_SECOND_IN_TS;
|
17161 | var MP2T_PACKET_LENGTH = 188,
|
17162 |
|
17163 | SYNC_BYTE = 0x47;
|
17164 | |
17165 |
|
17166 |
|
17167 |
|
17168 |
|
17169 | var parsePsi_ = function parsePsi_(bytes, pmt) {
|
17170 | var startIndex = 0,
|
17171 | endIndex = MP2T_PACKET_LENGTH,
|
17172 | packet,
|
17173 | type;
|
17174 |
|
17175 | while (endIndex < bytes.byteLength) {
|
17176 |
|
17177 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
17178 |
|
17179 | packet = bytes.subarray(startIndex, endIndex);
|
17180 | type = probe.ts.parseType(packet, pmt.pid);
|
17181 |
|
17182 | switch (type) {
|
17183 | case 'pat':
|
17184 | pmt.pid = probe.ts.parsePat(packet);
|
17185 | break;
|
17186 |
|
17187 | case 'pmt':
|
17188 | var table = probe.ts.parsePmt(packet);
|
17189 | pmt.table = pmt.table || {};
|
17190 | Object.keys(table).forEach(function (key) {
|
17191 | pmt.table[key] = table[key];
|
17192 | });
|
17193 | break;
|
17194 | }
|
17195 |
|
17196 | startIndex += MP2T_PACKET_LENGTH;
|
17197 | endIndex += MP2T_PACKET_LENGTH;
|
17198 | continue;
|
17199 | }
|
17200 |
|
17201 |
|
17202 |
|
17203 |
|
17204 | startIndex++;
|
17205 | endIndex++;
|
17206 | }
|
17207 | };
|
17208 | |
17209 |
|
17210 |
|
17211 |
|
17212 |
|
17213 |
|
17214 | var parseAudioPes_ = function parseAudioPes_(bytes, pmt, result) {
|
17215 | var startIndex = 0,
|
17216 | endIndex = MP2T_PACKET_LENGTH,
|
17217 | packet,
|
17218 | type,
|
17219 | pesType,
|
17220 | pusi,
|
17221 | parsed;
|
17222 | var endLoop = false;
|
17223 |
|
17224 | while (endIndex <= bytes.byteLength) {
|
17225 |
|
17226 | if (bytes[startIndex] === SYNC_BYTE && (bytes[endIndex] === SYNC_BYTE || endIndex === bytes.byteLength)) {
|
17227 |
|
17228 | packet = bytes.subarray(startIndex, endIndex);
|
17229 | type = probe.ts.parseType(packet, pmt.pid);
|
17230 |
|
17231 | switch (type) {
|
17232 | case 'pes':
|
17233 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
17234 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
17235 |
|
17236 | if (pesType === 'audio' && pusi) {
|
17237 | parsed = probe.ts.parsePesTime(packet);
|
17238 |
|
17239 | if (parsed) {
|
17240 | parsed.type = 'audio';
|
17241 | result.audio.push(parsed);
|
17242 | endLoop = true;
|
17243 | }
|
17244 | }
|
17245 |
|
17246 | break;
|
17247 | }
|
17248 |
|
17249 | if (endLoop) {
|
17250 | break;
|
17251 | }
|
17252 |
|
17253 | startIndex += MP2T_PACKET_LENGTH;
|
17254 | endIndex += MP2T_PACKET_LENGTH;
|
17255 | continue;
|
17256 | }
|
17257 |
|
17258 |
|
17259 |
|
17260 |
|
17261 | startIndex++;
|
17262 | endIndex++;
|
17263 | }
|
17264 |
|
17265 |
|
17266 | endIndex = bytes.byteLength;
|
17267 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
17268 | endLoop = false;
|
17269 |
|
17270 | while (startIndex >= 0) {
|
17271 |
|
17272 | if (bytes[startIndex] === SYNC_BYTE && (bytes[endIndex] === SYNC_BYTE || endIndex === bytes.byteLength)) {
|
17273 |
|
17274 | packet = bytes.subarray(startIndex, endIndex);
|
17275 | type = probe.ts.parseType(packet, pmt.pid);
|
17276 |
|
17277 | switch (type) {
|
17278 | case 'pes':
|
17279 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
17280 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
17281 |
|
17282 | if (pesType === 'audio' && pusi) {
|
17283 | parsed = probe.ts.parsePesTime(packet);
|
17284 |
|
17285 | if (parsed) {
|
17286 | parsed.type = 'audio';
|
17287 | result.audio.push(parsed);
|
17288 | endLoop = true;
|
17289 | }
|
17290 | }
|
17291 |
|
17292 | break;
|
17293 | }
|
17294 |
|
17295 | if (endLoop) {
|
17296 | break;
|
17297 | }
|
17298 |
|
17299 | startIndex -= MP2T_PACKET_LENGTH;
|
17300 | endIndex -= MP2T_PACKET_LENGTH;
|
17301 | continue;
|
17302 | }
|
17303 |
|
17304 |
|
17305 |
|
17306 |
|
17307 | startIndex--;
|
17308 | endIndex--;
|
17309 | }
|
17310 | };
|
17311 | |
17312 |
|
17313 |
|
17314 |
|
17315 |
|
17316 |
|
17317 |
|
17318 | var parseVideoPes_ = function parseVideoPes_(bytes, pmt, result) {
|
17319 | var startIndex = 0,
|
17320 | endIndex = MP2T_PACKET_LENGTH,
|
17321 | packet,
|
17322 | type,
|
17323 | pesType,
|
17324 | pusi,
|
17325 | parsed,
|
17326 | frame,
|
17327 | i,
|
17328 | pes;
|
17329 | var endLoop = false;
|
17330 | var currentFrame = {
|
17331 | data: [],
|
17332 | size: 0
|
17333 | };
|
17334 |
|
17335 | while (endIndex < bytes.byteLength) {
|
17336 |
|
17337 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
17338 |
|
17339 | packet = bytes.subarray(startIndex, endIndex);
|
17340 | type = probe.ts.parseType(packet, pmt.pid);
|
17341 |
|
17342 | switch (type) {
|
17343 | case 'pes':
|
17344 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
17345 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
17346 |
|
17347 | if (pesType === 'video') {
|
17348 | if (pusi && !endLoop) {
|
17349 | parsed = probe.ts.parsePesTime(packet);
|
17350 |
|
17351 | if (parsed) {
|
17352 | parsed.type = 'video';
|
17353 | result.video.push(parsed);
|
17354 | endLoop = true;
|
17355 | }
|
17356 | }
|
17357 |
|
17358 | if (!result.firstKeyFrame) {
|
17359 | if (pusi) {
|
17360 | if (currentFrame.size !== 0) {
|
17361 | frame = new Uint8Array(currentFrame.size);
|
17362 | i = 0;
|
17363 |
|
17364 | while (currentFrame.data.length) {
|
17365 | pes = currentFrame.data.shift();
|
17366 | frame.set(pes, i);
|
17367 | i += pes.byteLength;
|
17368 | }
|
17369 |
|
17370 | if (probe.ts.videoPacketContainsKeyFrame(frame)) {
|
17371 | var firstKeyFrame = probe.ts.parsePesTime(frame);
|
17372 |
|
17373 |
|
17374 |
|
17375 | if (firstKeyFrame) {
|
17376 | result.firstKeyFrame = firstKeyFrame;
|
17377 | result.firstKeyFrame.type = 'video';
|
17378 | } else {
|
17379 |
|
17380 | console.warn('Failed to extract PTS/DTS from PES at first keyframe. ' + 'This could be an unusual TS segment, or else mux.js did not ' + 'parse your TS segment correctly. If you know your TS ' + 'segments do contain PTS/DTS on keyframes please file a bug ' + 'report! You can try ffprobe to double check for yourself.');
|
17381 | }
|
17382 | }
|
17383 |
|
17384 | currentFrame.size = 0;
|
17385 | }
|
17386 | }
|
17387 |
|
17388 | currentFrame.data.push(packet);
|
17389 | currentFrame.size += packet.byteLength;
|
17390 | }
|
17391 | }
|
17392 |
|
17393 | break;
|
17394 | }
|
17395 |
|
17396 | if (endLoop && result.firstKeyFrame) {
|
17397 | break;
|
17398 | }
|
17399 |
|
17400 | startIndex += MP2T_PACKET_LENGTH;
|
17401 | endIndex += MP2T_PACKET_LENGTH;
|
17402 | continue;
|
17403 | }
|
17404 |
|
17405 |
|
17406 |
|
17407 |
|
17408 | startIndex++;
|
17409 | endIndex++;
|
17410 | }
|
17411 |
|
17412 |
|
17413 | endIndex = bytes.byteLength;
|
17414 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
17415 | endLoop = false;
|
17416 |
|
17417 | while (startIndex >= 0) {
|
17418 |
|
17419 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
17420 |
|
17421 | packet = bytes.subarray(startIndex, endIndex);
|
17422 | type = probe.ts.parseType(packet, pmt.pid);
|
17423 |
|
17424 | switch (type) {
|
17425 | case 'pes':
|
17426 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
17427 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
17428 |
|
17429 | if (pesType === 'video' && pusi) {
|
17430 | parsed = probe.ts.parsePesTime(packet);
|
17431 |
|
17432 | if (parsed) {
|
17433 | parsed.type = 'video';
|
17434 | result.video.push(parsed);
|
17435 | endLoop = true;
|
17436 | }
|
17437 | }
|
17438 |
|
17439 | break;
|
17440 | }
|
17441 |
|
17442 | if (endLoop) {
|
17443 | break;
|
17444 | }
|
17445 |
|
17446 | startIndex -= MP2T_PACKET_LENGTH;
|
17447 | endIndex -= MP2T_PACKET_LENGTH;
|
17448 | continue;
|
17449 | }
|
17450 |
|
17451 |
|
17452 |
|
17453 |
|
17454 | startIndex--;
|
17455 | endIndex--;
|
17456 | }
|
17457 | };
|
17458 | |
17459 |
|
17460 |
|
17461 |
|
17462 |
|
17463 |
|
17464 | var adjustTimestamp_ = function adjustTimestamp_(segmentInfo, baseTimestamp) {
|
17465 | if (segmentInfo.audio && segmentInfo.audio.length) {
|
17466 | var audioBaseTimestamp = baseTimestamp;
|
17467 |
|
17468 | if (typeof audioBaseTimestamp === 'undefined' || isNaN(audioBaseTimestamp)) {
|
17469 | audioBaseTimestamp = segmentInfo.audio[0].dts;
|
17470 | }
|
17471 |
|
17472 | segmentInfo.audio.forEach(function (info) {
|
17473 | info.dts = handleRollover(info.dts, audioBaseTimestamp);
|
17474 | info.pts = handleRollover(info.pts, audioBaseTimestamp);
|
17475 |
|
17476 | info.dtsTime = info.dts / ONE_SECOND_IN_TS;
|
17477 | info.ptsTime = info.pts / ONE_SECOND_IN_TS;
|
17478 | });
|
17479 | }
|
17480 |
|
17481 | if (segmentInfo.video && segmentInfo.video.length) {
|
17482 | var videoBaseTimestamp = baseTimestamp;
|
17483 |
|
17484 | if (typeof videoBaseTimestamp === 'undefined' || isNaN(videoBaseTimestamp)) {
|
17485 | videoBaseTimestamp = segmentInfo.video[0].dts;
|
17486 | }
|
17487 |
|
17488 | segmentInfo.video.forEach(function (info) {
|
17489 | info.dts = handleRollover(info.dts, videoBaseTimestamp);
|
17490 | info.pts = handleRollover(info.pts, videoBaseTimestamp);
|
17491 |
|
17492 | info.dtsTime = info.dts / ONE_SECOND_IN_TS;
|
17493 | info.ptsTime = info.pts / ONE_SECOND_IN_TS;
|
17494 | });
|
17495 |
|
17496 | if (segmentInfo.firstKeyFrame) {
|
17497 | var frame = segmentInfo.firstKeyFrame;
|
17498 | frame.dts = handleRollover(frame.dts, videoBaseTimestamp);
|
17499 | frame.pts = handleRollover(frame.pts, videoBaseTimestamp);
|
17500 |
|
17501 | frame.dtsTime = frame.dts / ONE_SECOND_IN_TS;
|
17502 | frame.ptsTime = frame.pts / ONE_SECOND_IN_TS;
|
17503 | }
|
17504 | }
|
17505 | };
|
17506 | |
17507 |
|
17508 |
|
17509 |
|
17510 |
|
17511 | var inspectAac_ = function inspectAac_(bytes) {
|
17512 | var endLoop = false,
|
17513 | audioCount = 0,
|
17514 | sampleRate = null,
|
17515 | timestamp = null,
|
17516 | frameSize = 0,
|
17517 | byteIndex = 0,
|
17518 | packet;
|
17519 |
|
17520 | while (bytes.length - byteIndex >= 3) {
|
17521 | var type = probe.aac.parseType(bytes, byteIndex);
|
17522 |
|
17523 | switch (type) {
|
17524 | case 'timed-metadata':
|
17525 |
|
17526 |
|
17527 | if (bytes.length - byteIndex < 10) {
|
17528 | endLoop = true;
|
17529 | break;
|
17530 | }
|
17531 |
|
17532 | frameSize = probe.aac.parseId3TagSize(bytes, byteIndex);
|
17533 |
|
17534 |
|
17535 | if (frameSize > bytes.length) {
|
17536 | endLoop = true;
|
17537 | break;
|
17538 | }
|
17539 |
|
17540 | if (timestamp === null) {
|
17541 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
17542 | timestamp = probe.aac.parseAacTimestamp(packet);
|
17543 | }
|
17544 |
|
17545 | byteIndex += frameSize;
|
17546 | break;
|
17547 |
|
17548 | case 'audio':
|
17549 |
|
17550 |
|
17551 | if (bytes.length - byteIndex < 7) {
|
17552 | endLoop = true;
|
17553 | break;
|
17554 | }
|
17555 |
|
17556 | frameSize = probe.aac.parseAdtsSize(bytes, byteIndex);
|
17557 |
|
17558 |
|
17559 | if (frameSize > bytes.length) {
|
17560 | endLoop = true;
|
17561 | break;
|
17562 | }
|
17563 |
|
17564 | if (sampleRate === null) {
|
17565 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
17566 | sampleRate = probe.aac.parseSampleRate(packet);
|
17567 | }
|
17568 |
|
17569 | audioCount++;
|
17570 | byteIndex += frameSize;
|
17571 | break;
|
17572 |
|
17573 | default:
|
17574 | byteIndex++;
|
17575 | break;
|
17576 | }
|
17577 |
|
17578 | if (endLoop) {
|
17579 | return null;
|
17580 | }
|
17581 | }
|
17582 |
|
17583 | if (sampleRate === null || timestamp === null) {
|
17584 | return null;
|
17585 | }
|
17586 |
|
17587 | var audioTimescale = ONE_SECOND_IN_TS / sampleRate;
|
17588 | var result = {
|
17589 | audio: [{
|
17590 | type: 'audio',
|
17591 | dts: timestamp,
|
17592 | pts: timestamp
|
17593 | }, {
|
17594 | type: 'audio',
|
17595 | dts: timestamp + audioCount * 1024 * audioTimescale,
|
17596 | pts: timestamp + audioCount * 1024 * audioTimescale
|
17597 | }]
|
17598 | };
|
17599 | return result;
|
17600 | };
|
17601 | |
17602 |
|
17603 |
|
17604 |
|
17605 |
|
17606 |
|
17607 |
|
17608 | var inspectTs_ = function inspectTs_(bytes) {
|
17609 | var pmt = {
|
17610 | pid: null,
|
17611 | table: null
|
17612 | };
|
17613 | var result = {};
|
17614 | parsePsi_(bytes, pmt);
|
17615 |
|
17616 | for (var pid in pmt.table) {
|
17617 | if (pmt.table.hasOwnProperty(pid)) {
|
17618 | var type = pmt.table[pid];
|
17619 |
|
17620 | switch (type) {
|
17621 | case streamTypes.H264_STREAM_TYPE:
|
17622 | result.video = [];
|
17623 | parseVideoPes_(bytes, pmt, result);
|
17624 |
|
17625 | if (result.video.length === 0) {
|
17626 | delete result.video;
|
17627 | }
|
17628 |
|
17629 | break;
|
17630 |
|
17631 | case streamTypes.ADTS_STREAM_TYPE:
|
17632 | result.audio = [];
|
17633 | parseAudioPes_(bytes, pmt, result);
|
17634 |
|
17635 | if (result.audio.length === 0) {
|
17636 | delete result.audio;
|
17637 | }
|
17638 |
|
17639 | break;
|
17640 | }
|
17641 | }
|
17642 | }
|
17643 |
|
17644 | return result;
|
17645 | };
|
17646 | |
17647 |
|
17648 |
|
17649 |
|
17650 |
|
17651 |
|
17652 |
|
17653 |
|
17654 |
|
17655 |
|
17656 | var inspect = function inspect(bytes, baseTimestamp) {
|
17657 | var isAacData = probe.aac.isLikelyAacData(bytes);
|
17658 | var result;
|
17659 |
|
17660 | if (isAacData) {
|
17661 | result = inspectAac_(bytes);
|
17662 | } else {
|
17663 | result = inspectTs_(bytes);
|
17664 | }
|
17665 |
|
17666 | if (!result || !result.audio && !result.video) {
|
17667 | return null;
|
17668 | }
|
17669 |
|
17670 | adjustTimestamp_(result, baseTimestamp);
|
17671 | return result;
|
17672 | };
|
17673 |
|
17674 | var tsInspector = {
|
17675 | inspect: inspect,
|
17676 | parseAudioPes_: parseAudioPes_
|
17677 | };
|
17678 |
|
17679 |
|
17680 | |
17681 |
|
17682 |
|
17683 |
|
17684 |
|
17685 |
|
17686 |
|
17687 |
|
17688 | var wireTransmuxerEvents = function wireTransmuxerEvents(self, transmuxer) {
|
17689 | transmuxer.on('data', function (segment) {
|
17690 |
|
17691 |
|
17692 |
|
17693 |
|
17694 | var initArray = segment.initSegment;
|
17695 | segment.initSegment = {
|
17696 | data: initArray.buffer,
|
17697 | byteOffset: initArray.byteOffset,
|
17698 | byteLength: initArray.byteLength
|
17699 | };
|
17700 | var typedArray = segment.data;
|
17701 | segment.data = typedArray.buffer;
|
17702 | self.postMessage({
|
17703 | action: 'data',
|
17704 | segment: segment,
|
17705 | byteOffset: typedArray.byteOffset,
|
17706 | byteLength: typedArray.byteLength
|
17707 | }, [segment.data]);
|
17708 | });
|
17709 | transmuxer.on('done', function (data) {
|
17710 | self.postMessage({
|
17711 | action: 'done'
|
17712 | });
|
17713 | });
|
17714 | transmuxer.on('gopInfo', function (gopInfo) {
|
17715 | self.postMessage({
|
17716 | action: 'gopInfo',
|
17717 | gopInfo: gopInfo
|
17718 | });
|
17719 | });
|
17720 | transmuxer.on('videoSegmentTimingInfo', function (timingInfo) {
|
17721 | var videoSegmentTimingInfo = {
|
17722 | start: {
|
17723 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
17724 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
17725 | },
|
17726 | end: {
|
17727 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
17728 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
17729 | },
|
17730 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
17731 | };
|
17732 |
|
17733 | if (timingInfo.prependedContentDuration) {
|
17734 | videoSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
17735 | }
|
17736 |
|
17737 | self.postMessage({
|
17738 | action: 'videoSegmentTimingInfo',
|
17739 | videoSegmentTimingInfo: videoSegmentTimingInfo
|
17740 | });
|
17741 | });
|
17742 | transmuxer.on('audioSegmentTimingInfo', function (timingInfo) {
|
17743 |
|
17744 | var audioSegmentTimingInfo = {
|
17745 | start: {
|
17746 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
17747 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
17748 | },
|
17749 | end: {
|
17750 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
17751 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
17752 | },
|
17753 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
17754 | };
|
17755 |
|
17756 | if (timingInfo.prependedContentDuration) {
|
17757 | audioSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
17758 | }
|
17759 |
|
17760 | self.postMessage({
|
17761 | action: 'audioSegmentTimingInfo',
|
17762 | audioSegmentTimingInfo: audioSegmentTimingInfo
|
17763 | });
|
17764 | });
|
17765 | transmuxer.on('id3Frame', function (id3Frame) {
|
17766 | self.postMessage({
|
17767 | action: 'id3Frame',
|
17768 | id3Frame: id3Frame
|
17769 | });
|
17770 | });
|
17771 | transmuxer.on('caption', function (caption) {
|
17772 | self.postMessage({
|
17773 | action: 'caption',
|
17774 | caption: caption
|
17775 | });
|
17776 | });
|
17777 | transmuxer.on('trackinfo', function (trackInfo) {
|
17778 | self.postMessage({
|
17779 | action: 'trackinfo',
|
17780 | trackInfo: trackInfo
|
17781 | });
|
17782 | });
|
17783 | transmuxer.on('audioTimingInfo', function (audioTimingInfo) {
|
17784 |
|
17785 | self.postMessage({
|
17786 | action: 'audioTimingInfo',
|
17787 | audioTimingInfo: {
|
17788 | start: clock.videoTsToSeconds(audioTimingInfo.start),
|
17789 | end: clock.videoTsToSeconds(audioTimingInfo.end)
|
17790 | }
|
17791 | });
|
17792 | });
|
17793 | transmuxer.on('videoTimingInfo', function (videoTimingInfo) {
|
17794 | self.postMessage({
|
17795 | action: 'videoTimingInfo',
|
17796 | videoTimingInfo: {
|
17797 | start: clock.videoTsToSeconds(videoTimingInfo.start),
|
17798 | end: clock.videoTsToSeconds(videoTimingInfo.end)
|
17799 | }
|
17800 | });
|
17801 | });
|
17802 | transmuxer.on('log', function (log) {
|
17803 | self.postMessage({
|
17804 | action: 'log',
|
17805 | log: log
|
17806 | });
|
17807 | });
|
17808 | };
|
17809 | |
17810 |
|
17811 |
|
17812 |
|
17813 |
|
17814 |
|
17815 |
|
17816 |
|
17817 |
|
17818 | var MessageHandlers = function () {
|
17819 | function MessageHandlers(self, options) {
|
17820 | this.options = options || {};
|
17821 | this.self = self;
|
17822 | this.init();
|
17823 | }
|
17824 | |
17825 |
|
17826 |
|
17827 |
|
17828 |
|
17829 | var _proto = MessageHandlers.prototype;
|
17830 |
|
17831 | _proto.init = function init() {
|
17832 | if (this.transmuxer) {
|
17833 | this.transmuxer.dispose();
|
17834 | }
|
17835 |
|
17836 | this.transmuxer = new transmuxer.Transmuxer(this.options);
|
17837 | wireTransmuxerEvents(this.self, this.transmuxer);
|
17838 | };
|
17839 |
|
17840 | _proto.pushMp4Captions = function pushMp4Captions(data) {
|
17841 | if (!this.captionParser) {
|
17842 | this.captionParser = new captionParser();
|
17843 | this.captionParser.init();
|
17844 | }
|
17845 |
|
17846 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
17847 | var parsed = this.captionParser.parse(segment, data.trackIds, data.timescales);
|
17848 | this.self.postMessage({
|
17849 | action: 'mp4Captions',
|
17850 | captions: parsed && parsed.captions || [],
|
17851 | logs: parsed && parsed.logs || [],
|
17852 | data: segment.buffer
|
17853 | }, [segment.buffer]);
|
17854 | };
|
17855 |
|
17856 | _proto.probeMp4StartTime = function probeMp4StartTime(_ref) {
|
17857 | var timescales = _ref.timescales,
|
17858 | data = _ref.data;
|
17859 | var startTime = probe$2.startTime(timescales, data);
|
17860 | this.self.postMessage({
|
17861 | action: 'probeMp4StartTime',
|
17862 | startTime: startTime,
|
17863 | data: data
|
17864 | }, [data.buffer]);
|
17865 | };
|
17866 |
|
17867 | _proto.probeMp4Tracks = function probeMp4Tracks(_ref2) {
|
17868 | var data = _ref2.data;
|
17869 | var tracks = probe$2.tracks(data);
|
17870 | this.self.postMessage({
|
17871 | action: 'probeMp4Tracks',
|
17872 | tracks: tracks,
|
17873 | data: data
|
17874 | }, [data.buffer]);
|
17875 | }
|
17876 | |
17877 |
|
17878 |
|
17879 |
|
17880 |
|
17881 |
|
17882 |
|
17883 |
|
17884 |
|
17885 |
|
17886 |
|
17887 |
|
17888 |
|
17889 | ;
|
17890 |
|
17891 | _proto.probeTs = function probeTs(_ref3) {
|
17892 | var data = _ref3.data,
|
17893 | baseStartTime = _ref3.baseStartTime;
|
17894 | var tsStartTime = typeof baseStartTime === 'number' && !isNaN(baseStartTime) ? baseStartTime * clock.ONE_SECOND_IN_TS : void 0;
|
17895 | var timeInfo = tsInspector.inspect(data, tsStartTime);
|
17896 | var result = null;
|
17897 |
|
17898 | if (timeInfo) {
|
17899 | result = {
|
17900 |
|
17901 | hasVideo: timeInfo.video && timeInfo.video.length === 2 || false,
|
17902 | hasAudio: timeInfo.audio && timeInfo.audio.length === 2 || false
|
17903 | };
|
17904 |
|
17905 | if (result.hasVideo) {
|
17906 | result.videoStart = timeInfo.video[0].ptsTime;
|
17907 | }
|
17908 |
|
17909 | if (result.hasAudio) {
|
17910 | result.audioStart = timeInfo.audio[0].ptsTime;
|
17911 | }
|
17912 | }
|
17913 |
|
17914 | this.self.postMessage({
|
17915 | action: 'probeTs',
|
17916 | result: result,
|
17917 | data: data
|
17918 | }, [data.buffer]);
|
17919 | };
|
17920 |
|
17921 | _proto.clearAllMp4Captions = function clearAllMp4Captions() {
|
17922 | if (this.captionParser) {
|
17923 | this.captionParser.clearAllCaptions();
|
17924 | }
|
17925 | };
|
17926 |
|
17927 | _proto.clearParsedMp4Captions = function clearParsedMp4Captions() {
|
17928 | if (this.captionParser) {
|
17929 | this.captionParser.clearParsedCaptions();
|
17930 | }
|
17931 | }
|
17932 | |
17933 |
|
17934 |
|
17935 |
|
17936 |
|
17937 |
|
17938 | ;
|
17939 |
|
17940 | _proto.push = function push(data) {
|
17941 |
|
17942 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
17943 | this.transmuxer.push(segment);
|
17944 | }
|
17945 | |
17946 |
|
17947 |
|
17948 |
|
17949 | ;
|
17950 |
|
17951 | _proto.reset = function reset() {
|
17952 | this.transmuxer.reset();
|
17953 | }
|
17954 | |
17955 |
|
17956 |
|
17957 |
|
17958 |
|
17959 |
|
17960 |
|
17961 | ;
|
17962 |
|
17963 | _proto.setTimestampOffset = function setTimestampOffset(data) {
|
17964 | var timestampOffset = data.timestampOffset || 0;
|
17965 | this.transmuxer.setBaseMediaDecodeTime(Math.round(clock.secondsToVideoTs(timestampOffset)));
|
17966 | };
|
17967 |
|
17968 | _proto.setAudioAppendStart = function setAudioAppendStart(data) {
|
17969 | this.transmuxer.setAudioAppendStart(Math.ceil(clock.secondsToVideoTs(data.appendStart)));
|
17970 | };
|
17971 |
|
17972 | _proto.setRemux = function setRemux(data) {
|
17973 | this.transmuxer.setRemux(data.remux);
|
17974 | }
|
17975 | |
17976 |
|
17977 |
|
17978 |
|
17979 |
|
17980 |
|
17981 | ;
|
17982 |
|
17983 | _proto.flush = function flush(data) {
|
17984 | this.transmuxer.flush();
|
17985 |
|
17986 | self.postMessage({
|
17987 | action: 'done',
|
17988 | type: 'transmuxed'
|
17989 | });
|
17990 | };
|
17991 |
|
17992 | _proto.endTimeline = function endTimeline() {
|
17993 | this.transmuxer.endTimeline();
|
17994 |
|
17995 |
|
17996 | self.postMessage({
|
17997 | action: 'endedtimeline',
|
17998 | type: 'transmuxed'
|
17999 | });
|
18000 | };
|
18001 |
|
18002 | _proto.alignGopsWith = function alignGopsWith(data) {
|
18003 | this.transmuxer.alignGopsWith(data.gopsToAlignWith.slice());
|
18004 | };
|
18005 |
|
18006 | return MessageHandlers;
|
18007 | }();
|
18008 | |
18009 |
|
18010 |
|
18011 |
|
18012 |
|
18013 |
|
18014 |
|
18015 |
|
18016 |
|
18017 | self.onmessage = function (event) {
|
18018 | if (event.data.action === 'init' && event.data.options) {
|
18019 | this.messageHandlers = new MessageHandlers(self, event.data.options);
|
18020 | return;
|
18021 | }
|
18022 |
|
18023 | if (!this.messageHandlers) {
|
18024 | this.messageHandlers = new MessageHandlers(self);
|
18025 | }
|
18026 |
|
18027 | if (event.data && event.data.action && event.data.action !== 'init') {
|
18028 | if (this.messageHandlers[event.data.action]) {
|
18029 | this.messageHandlers[event.data.action](event.data);
|
18030 | }
|
18031 | }
|
18032 | };
|
18033 | }));
|
18034 | var TransmuxWorker = factory(workerCode$1);
|
18035 |
|
18036 |
|
18037 | var handleData_ = function handleData_(event, transmuxedData, callback) {
|
18038 | var _event$data$segment = event.data.segment,
|
18039 | type = _event$data$segment.type,
|
18040 | initSegment = _event$data$segment.initSegment,
|
18041 | captions = _event$data$segment.captions,
|
18042 | captionStreams = _event$data$segment.captionStreams,
|
18043 | metadata = _event$data$segment.metadata,
|
18044 | videoFrameDtsTime = _event$data$segment.videoFrameDtsTime,
|
18045 | videoFramePtsTime = _event$data$segment.videoFramePtsTime;
|
18046 | transmuxedData.buffer.push({
|
18047 | captions: captions,
|
18048 | captionStreams: captionStreams,
|
18049 | metadata: metadata
|
18050 | });
|
18051 | var boxes = event.data.segment.boxes || {
|
18052 | data: event.data.segment.data
|
18053 | };
|
18054 | var result = {
|
18055 | type: type,
|
18056 |
|
18057 | data: new Uint8Array(boxes.data, boxes.data.byteOffset, boxes.data.byteLength),
|
18058 | initSegment: new Uint8Array(initSegment.data, initSegment.byteOffset, initSegment.byteLength)
|
18059 | };
|
18060 |
|
18061 | if (typeof videoFrameDtsTime !== 'undefined') {
|
18062 | result.videoFrameDtsTime = videoFrameDtsTime;
|
18063 | }
|
18064 |
|
18065 | if (typeof videoFramePtsTime !== 'undefined') {
|
18066 | result.videoFramePtsTime = videoFramePtsTime;
|
18067 | }
|
18068 |
|
18069 | callback(result);
|
18070 | };
|
18071 | var handleDone_ = function handleDone_(_ref) {
|
18072 | var transmuxedData = _ref.transmuxedData,
|
18073 | callback = _ref.callback;
|
18074 |
|
18075 |
|
18076 | transmuxedData.buffer = [];
|
18077 |
|
18078 |
|
18079 | callback(transmuxedData);
|
18080 | };
|
18081 | var handleGopInfo_ = function handleGopInfo_(event, transmuxedData) {
|
18082 | transmuxedData.gopInfo = event.data.gopInfo;
|
18083 | };
|
18084 | var processTransmux = function processTransmux(options) {
|
18085 | var transmuxer = options.transmuxer,
|
18086 | bytes = options.bytes,
|
18087 | audioAppendStart = options.audioAppendStart,
|
18088 | gopsToAlignWith = options.gopsToAlignWith,
|
18089 | remux = options.remux,
|
18090 | onData = options.onData,
|
18091 | onTrackInfo = options.onTrackInfo,
|
18092 | onAudioTimingInfo = options.onAudioTimingInfo,
|
18093 | onVideoTimingInfo = options.onVideoTimingInfo,
|
18094 | onVideoSegmentTimingInfo = options.onVideoSegmentTimingInfo,
|
18095 | onAudioSegmentTimingInfo = options.onAudioSegmentTimingInfo,
|
18096 | onId3 = options.onId3,
|
18097 | onCaptions = options.onCaptions,
|
18098 | onDone = options.onDone,
|
18099 | onEndedTimeline = options.onEndedTimeline,
|
18100 | onTransmuxerLog = options.onTransmuxerLog,
|
18101 | isEndOfTimeline = options.isEndOfTimeline;
|
18102 | var transmuxedData = {
|
18103 | buffer: []
|
18104 | };
|
18105 | var waitForEndedTimelineEvent = isEndOfTimeline;
|
18106 |
|
18107 | var handleMessage = function handleMessage(event) {
|
18108 | if (transmuxer.currentTransmux !== options) {
|
18109 |
|
18110 | return;
|
18111 | }
|
18112 |
|
18113 | if (event.data.action === 'data') {
|
18114 | handleData_(event, transmuxedData, onData);
|
18115 | }
|
18116 |
|
18117 | if (event.data.action === 'trackinfo') {
|
18118 | onTrackInfo(event.data.trackInfo);
|
18119 | }
|
18120 |
|
18121 | if (event.data.action === 'gopInfo') {
|
18122 | handleGopInfo_(event, transmuxedData);
|
18123 | }
|
18124 |
|
18125 | if (event.data.action === 'audioTimingInfo') {
|
18126 | onAudioTimingInfo(event.data.audioTimingInfo);
|
18127 | }
|
18128 |
|
18129 | if (event.data.action === 'videoTimingInfo') {
|
18130 | onVideoTimingInfo(event.data.videoTimingInfo);
|
18131 | }
|
18132 |
|
18133 | if (event.data.action === 'videoSegmentTimingInfo') {
|
18134 | onVideoSegmentTimingInfo(event.data.videoSegmentTimingInfo);
|
18135 | }
|
18136 |
|
18137 | if (event.data.action === 'audioSegmentTimingInfo') {
|
18138 | onAudioSegmentTimingInfo(event.data.audioSegmentTimingInfo);
|
18139 | }
|
18140 |
|
18141 | if (event.data.action === 'id3Frame') {
|
18142 | onId3([event.data.id3Frame], event.data.id3Frame.dispatchType);
|
18143 | }
|
18144 |
|
18145 | if (event.data.action === 'caption') {
|
18146 | onCaptions(event.data.caption);
|
18147 | }
|
18148 |
|
18149 | if (event.data.action === 'endedtimeline') {
|
18150 | waitForEndedTimelineEvent = false;
|
18151 | onEndedTimeline();
|
18152 | }
|
18153 |
|
18154 | if (event.data.action === 'log') {
|
18155 | onTransmuxerLog(event.data.log);
|
18156 | }
|
18157 |
|
18158 |
|
18159 | if (event.data.type !== 'transmuxed') {
|
18160 | return;
|
18161 | }
|
18162 |
|
18163 |
|
18164 |
|
18165 |
|
18166 |
|
18167 | if (waitForEndedTimelineEvent) {
|
18168 | return;
|
18169 | }
|
18170 |
|
18171 | transmuxer.onmessage = null;
|
18172 | handleDone_({
|
18173 | transmuxedData: transmuxedData,
|
18174 | callback: onDone
|
18175 | });
|
18176 |
|
18177 |
|
18178 | dequeue(transmuxer);
|
18179 |
|
18180 | };
|
18181 |
|
18182 | transmuxer.onmessage = handleMessage;
|
18183 |
|
18184 | if (audioAppendStart) {
|
18185 | transmuxer.postMessage({
|
18186 | action: 'setAudioAppendStart',
|
18187 | appendStart: audioAppendStart
|
18188 | });
|
18189 | }
|
18190 |
|
18191 |
|
18192 | if (Array.isArray(gopsToAlignWith)) {
|
18193 | transmuxer.postMessage({
|
18194 | action: 'alignGopsWith',
|
18195 | gopsToAlignWith: gopsToAlignWith
|
18196 | });
|
18197 | }
|
18198 |
|
18199 | if (typeof remux !== 'undefined') {
|
18200 | transmuxer.postMessage({
|
18201 | action: 'setRemux',
|
18202 | remux: remux
|
18203 | });
|
18204 | }
|
18205 |
|
18206 | if (bytes.byteLength) {
|
18207 | var buffer = bytes instanceof ArrayBuffer ? bytes : bytes.buffer;
|
18208 | var byteOffset = bytes instanceof ArrayBuffer ? 0 : bytes.byteOffset;
|
18209 | transmuxer.postMessage({
|
18210 | action: 'push',
|
18211 |
|
18212 |
|
18213 |
|
18214 | data: buffer,
|
18215 |
|
18216 |
|
18217 | byteOffset: byteOffset,
|
18218 | byteLength: bytes.byteLength
|
18219 | }, [buffer]);
|
18220 | }
|
18221 |
|
18222 | if (isEndOfTimeline) {
|
18223 | transmuxer.postMessage({
|
18224 | action: 'endTimeline'
|
18225 | });
|
18226 | }
|
18227 |
|
18228 |
|
18229 |
|
18230 | transmuxer.postMessage({
|
18231 | action: 'flush'
|
18232 | });
|
18233 | };
|
18234 | var dequeue = function dequeue(transmuxer) {
|
18235 | transmuxer.currentTransmux = null;
|
18236 |
|
18237 | if (transmuxer.transmuxQueue.length) {
|
18238 | transmuxer.currentTransmux = transmuxer.transmuxQueue.shift();
|
18239 |
|
18240 | if (typeof transmuxer.currentTransmux === 'function') {
|
18241 | transmuxer.currentTransmux();
|
18242 | } else {
|
18243 | processTransmux(transmuxer.currentTransmux);
|
18244 | }
|
18245 | }
|
18246 | };
|
18247 | var processAction = function processAction(transmuxer, action) {
|
18248 | transmuxer.postMessage({
|
18249 | action: action
|
18250 | });
|
18251 | dequeue(transmuxer);
|
18252 | };
|
18253 | var enqueueAction = function enqueueAction(action, transmuxer) {
|
18254 | if (!transmuxer.currentTransmux) {
|
18255 | transmuxer.currentTransmux = action;
|
18256 | processAction(transmuxer, action);
|
18257 | return;
|
18258 | }
|
18259 |
|
18260 | transmuxer.transmuxQueue.push(processAction.bind(null, transmuxer, action));
|
18261 | };
|
18262 | var reset = function reset(transmuxer) {
|
18263 | enqueueAction('reset', transmuxer);
|
18264 | };
|
18265 | var endTimeline = function endTimeline(transmuxer) {
|
18266 | enqueueAction('endTimeline', transmuxer);
|
18267 | };
|
18268 | var transmux = function transmux(options) {
|
18269 | if (!options.transmuxer.currentTransmux) {
|
18270 | options.transmuxer.currentTransmux = options;
|
18271 | processTransmux(options);
|
18272 | return;
|
18273 | }
|
18274 |
|
18275 | options.transmuxer.transmuxQueue.push(options);
|
18276 | };
|
18277 | var createTransmuxer = function createTransmuxer(options) {
|
18278 | var transmuxer = new TransmuxWorker();
|
18279 | transmuxer.currentTransmux = null;
|
18280 | transmuxer.transmuxQueue = [];
|
18281 | var term = transmuxer.terminate;
|
18282 |
|
18283 | transmuxer.terminate = function () {
|
18284 | transmuxer.currentTransmux = null;
|
18285 | transmuxer.transmuxQueue.length = 0;
|
18286 | return term.call(transmuxer);
|
18287 | };
|
18288 |
|
18289 | transmuxer.postMessage({
|
18290 | action: 'init',
|
18291 | options: options
|
18292 | });
|
18293 | return transmuxer;
|
18294 | };
|
18295 | var segmentTransmuxer = {
|
18296 | reset: reset,
|
18297 | endTimeline: endTimeline,
|
18298 | transmux: transmux,
|
18299 | createTransmuxer: createTransmuxer
|
18300 | };
|
18301 |
|
18302 | var workerCallback = function workerCallback(options) {
|
18303 | var transmuxer = options.transmuxer;
|
18304 | var endAction = options.endAction || options.action;
|
18305 | var callback = options.callback;
|
18306 |
|
18307 | var message = _extends_1({}, options, {
|
18308 | endAction: null,
|
18309 | transmuxer: null,
|
18310 | callback: null
|
18311 | });
|
18312 |
|
18313 | var listenForEndEvent = function listenForEndEvent(event) {
|
18314 | if (event.data.action !== endAction) {
|
18315 | return;
|
18316 | }
|
18317 |
|
18318 | transmuxer.removeEventListener('message', listenForEndEvent);
|
18319 |
|
18320 | if (event.data.data) {
|
18321 | event.data.data = new Uint8Array(event.data.data, options.byteOffset || 0, options.byteLength || event.data.data.byteLength);
|
18322 |
|
18323 | if (options.data) {
|
18324 | options.data = event.data.data;
|
18325 | }
|
18326 | }
|
18327 |
|
18328 | callback(event.data);
|
18329 | };
|
18330 |
|
18331 | transmuxer.addEventListener('message', listenForEndEvent);
|
18332 |
|
18333 | if (options.data) {
|
18334 | var isArrayBuffer = options.data instanceof ArrayBuffer;
|
18335 | message.byteOffset = isArrayBuffer ? 0 : options.data.byteOffset;
|
18336 | message.byteLength = options.data.byteLength;
|
18337 | var transfers = [isArrayBuffer ? options.data : options.data.buffer];
|
18338 | transmuxer.postMessage(message, transfers);
|
18339 | } else {
|
18340 | transmuxer.postMessage(message);
|
18341 | }
|
18342 | };
|
18343 |
|
18344 | var REQUEST_ERRORS = {
|
18345 | FAILURE: 2,
|
18346 | TIMEOUT: -101,
|
18347 | ABORTED: -102
|
18348 | };
|
18349 | |
18350 |
|
18351 |
|
18352 |
|
18353 |
|
18354 |
|
18355 | var abortAll = function abortAll(activeXhrs) {
|
18356 | activeXhrs.forEach(function (xhr) {
|
18357 | xhr.abort();
|
18358 | });
|
18359 | };
|
18360 | |
18361 |
|
18362 |
|
18363 |
|
18364 |
|
18365 |
|
18366 |
|
18367 | var getRequestStats = function getRequestStats(request) {
|
18368 | return {
|
18369 | bandwidth: request.bandwidth,
|
18370 | bytesReceived: request.bytesReceived || 0,
|
18371 | roundTripTime: request.roundTripTime || 0
|
18372 | };
|
18373 | };
|
18374 | |
18375 |
|
18376 |
|
18377 |
|
18378 |
|
18379 |
|
18380 |
|
18381 |
|
18382 | var getProgressStats = function getProgressStats(progressEvent) {
|
18383 | var request = progressEvent.target;
|
18384 | var roundTripTime = Date.now() - request.requestTime;
|
18385 | var stats = {
|
18386 | bandwidth: Infinity,
|
18387 | bytesReceived: 0,
|
18388 | roundTripTime: roundTripTime || 0
|
18389 | };
|
18390 | stats.bytesReceived = progressEvent.loaded;
|
18391 |
|
18392 |
|
18393 |
|
18394 | stats.bandwidth = Math.floor(stats.bytesReceived / stats.roundTripTime * 8 * 1000);
|
18395 | return stats;
|
18396 | };
|
18397 | |
18398 |
|
18399 |
|
18400 |
|
18401 |
|
18402 |
|
18403 |
|
18404 |
|
18405 |
|
18406 | var handleErrors = function handleErrors(error, request) {
|
18407 | if (request.timedout) {
|
18408 | return {
|
18409 | status: request.status,
|
18410 | message: 'HLS request timed-out at URL: ' + request.uri,
|
18411 | code: REQUEST_ERRORS.TIMEOUT,
|
18412 | xhr: request
|
18413 | };
|
18414 | }
|
18415 |
|
18416 | if (request.aborted) {
|
18417 | return {
|
18418 | status: request.status,
|
18419 | message: 'HLS request aborted at URL: ' + request.uri,
|
18420 | code: REQUEST_ERRORS.ABORTED,
|
18421 | xhr: request
|
18422 | };
|
18423 | }
|
18424 |
|
18425 | if (error) {
|
18426 | return {
|
18427 | status: request.status,
|
18428 | message: 'HLS request errored at URL: ' + request.uri,
|
18429 | code: REQUEST_ERRORS.FAILURE,
|
18430 | xhr: request
|
18431 | };
|
18432 | }
|
18433 |
|
18434 | if (request.responseType === 'arraybuffer' && request.response.byteLength === 0) {
|
18435 | return {
|
18436 | status: request.status,
|
18437 | message: 'Empty HLS response at URL: ' + request.uri,
|
18438 | code: REQUEST_ERRORS.FAILURE,
|
18439 | xhr: request
|
18440 | };
|
18441 | }
|
18442 |
|
18443 | return null;
|
18444 | };
|
18445 | |
18446 |
|
18447 |
|
18448 |
|
18449 |
|
18450 |
|
18451 |
|
18452 |
|
18453 |
|
18454 |
|
18455 |
|
18456 |
|
18457 | var handleKeyResponse = function handleKeyResponse(segment, objects, finishProcessingFn) {
|
18458 | return function (error, request) {
|
18459 | var response = request.response;
|
18460 | var errorObj = handleErrors(error, request);
|
18461 |
|
18462 | if (errorObj) {
|
18463 | return finishProcessingFn(errorObj, segment);
|
18464 | }
|
18465 |
|
18466 | if (response.byteLength !== 16) {
|
18467 | return finishProcessingFn({
|
18468 | status: request.status,
|
18469 | message: 'Invalid HLS key at URL: ' + request.uri,
|
18470 | code: REQUEST_ERRORS.FAILURE,
|
18471 | xhr: request
|
18472 | }, segment);
|
18473 | }
|
18474 |
|
18475 | var view = new DataView(response);
|
18476 | var bytes = new Uint32Array([view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12)]);
|
18477 |
|
18478 | for (var i = 0; i < objects.length; i++) {
|
18479 | objects[i].bytes = bytes;
|
18480 | }
|
18481 |
|
18482 | return finishProcessingFn(null, segment);
|
18483 | };
|
18484 | };
|
18485 |
|
18486 | var parseInitSegment = function parseInitSegment(segment, _callback) {
|
18487 | var type = detectContainerForBytes(segment.map.bytes);
|
18488 |
|
18489 |
|
18490 | if (type !== 'mp4') {
|
18491 | var uri = segment.map.resolvedUri || segment.map.uri;
|
18492 | return _callback({
|
18493 | internal: true,
|
18494 | message: "Found unsupported " + (type || 'unknown') + " container for initialization segment at URL: " + uri,
|
18495 | code: REQUEST_ERRORS.FAILURE
|
18496 | });
|
18497 | }
|
18498 |
|
18499 | workerCallback({
|
18500 | action: 'probeMp4Tracks',
|
18501 | data: segment.map.bytes,
|
18502 | transmuxer: segment.transmuxer,
|
18503 | callback: function callback(_ref) {
|
18504 | var tracks = _ref.tracks,
|
18505 | data = _ref.data;
|
18506 |
|
18507 | segment.map.bytes = data;
|
18508 | tracks.forEach(function (track) {
|
18509 | segment.map.tracks = segment.map.tracks || {};
|
18510 |
|
18511 | if (segment.map.tracks[track.type]) {
|
18512 | return;
|
18513 | }
|
18514 |
|
18515 | segment.map.tracks[track.type] = track;
|
18516 |
|
18517 | if (typeof track.id === 'number' && track.timescale) {
|
18518 | segment.map.timescales = segment.map.timescales || {};
|
18519 | segment.map.timescales[track.id] = track.timescale;
|
18520 | }
|
18521 | });
|
18522 | return _callback(null);
|
18523 | }
|
18524 | });
|
18525 | };
|
18526 | |
18527 |
|
18528 |
|
18529 |
|
18530 |
|
18531 |
|
18532 |
|
18533 |
|
18534 |
|
18535 |
|
18536 | var handleInitSegmentResponse = function handleInitSegmentResponse(_ref2) {
|
18537 | var segment = _ref2.segment,
|
18538 | finishProcessingFn = _ref2.finishProcessingFn;
|
18539 | return function (error, request) {
|
18540 | var errorObj = handleErrors(error, request);
|
18541 |
|
18542 | if (errorObj) {
|
18543 | return finishProcessingFn(errorObj, segment);
|
18544 | }
|
18545 |
|
18546 | var bytes = new Uint8Array(request.response);
|
18547 |
|
18548 |
|
18549 | if (segment.map.key) {
|
18550 | segment.map.encryptedBytes = bytes;
|
18551 | return finishProcessingFn(null, segment);
|
18552 | }
|
18553 |
|
18554 | segment.map.bytes = bytes;
|
18555 | parseInitSegment(segment, function (parseError) {
|
18556 | if (parseError) {
|
18557 | parseError.xhr = request;
|
18558 | parseError.status = request.status;
|
18559 | return finishProcessingFn(parseError, segment);
|
18560 | }
|
18561 |
|
18562 | finishProcessingFn(null, segment);
|
18563 | });
|
18564 | };
|
18565 | };
|
18566 | |
18567 |
|
18568 |
|
18569 |
|
18570 |
|
18571 |
|
18572 |
|
18573 |
|
18574 |
|
18575 |
|
18576 |
|
18577 |
|
18578 | var handleSegmentResponse = function handleSegmentResponse(_ref3) {
|
18579 | var segment = _ref3.segment,
|
18580 | finishProcessingFn = _ref3.finishProcessingFn,
|
18581 | responseType = _ref3.responseType;
|
18582 | return function (error, request) {
|
18583 | var errorObj = handleErrors(error, request);
|
18584 |
|
18585 | if (errorObj) {
|
18586 | return finishProcessingFn(errorObj, segment);
|
18587 | }
|
18588 |
|
18589 | var newBytes =
|
18590 |
|
18591 |
|
18592 |
|
18593 |
|
18594 | responseType === 'arraybuffer' || !request.responseText ? request.response : stringToArrayBuffer(request.responseText.substring(segment.lastReachedChar || 0));
|
18595 | segment.stats = getRequestStats(request);
|
18596 |
|
18597 | if (segment.key) {
|
18598 | segment.encryptedBytes = new Uint8Array(newBytes);
|
18599 | } else {
|
18600 | segment.bytes = new Uint8Array(newBytes);
|
18601 | }
|
18602 |
|
18603 | return finishProcessingFn(null, segment);
|
18604 | };
|
18605 | };
|
18606 |
|
18607 | var transmuxAndNotify = function transmuxAndNotify(_ref4) {
|
18608 | var segment = _ref4.segment,
|
18609 | bytes = _ref4.bytes,
|
18610 | trackInfoFn = _ref4.trackInfoFn,
|
18611 | timingInfoFn = _ref4.timingInfoFn,
|
18612 | videoSegmentTimingInfoFn = _ref4.videoSegmentTimingInfoFn,
|
18613 | audioSegmentTimingInfoFn = _ref4.audioSegmentTimingInfoFn,
|
18614 | id3Fn = _ref4.id3Fn,
|
18615 | captionsFn = _ref4.captionsFn,
|
18616 | isEndOfTimeline = _ref4.isEndOfTimeline,
|
18617 | endedTimelineFn = _ref4.endedTimelineFn,
|
18618 | dataFn = _ref4.dataFn,
|
18619 | doneFn = _ref4.doneFn,
|
18620 | onTransmuxerLog = _ref4.onTransmuxerLog;
|
18621 | var fmp4Tracks = segment.map && segment.map.tracks || {};
|
18622 | var isMuxed = Boolean(fmp4Tracks.audio && fmp4Tracks.video);
|
18623 |
|
18624 |
|
18625 |
|
18626 | var audioStartFn = timingInfoFn.bind(null, segment, 'audio', 'start');
|
18627 | var audioEndFn = timingInfoFn.bind(null, segment, 'audio', 'end');
|
18628 | var videoStartFn = timingInfoFn.bind(null, segment, 'video', 'start');
|
18629 | var videoEndFn = timingInfoFn.bind(null, segment, 'video', 'end');
|
18630 |
|
18631 | var finish = function finish() {
|
18632 | return transmux({
|
18633 | bytes: bytes,
|
18634 | transmuxer: segment.transmuxer,
|
18635 | audioAppendStart: segment.audioAppendStart,
|
18636 | gopsToAlignWith: segment.gopsToAlignWith,
|
18637 | remux: isMuxed,
|
18638 | onData: function onData(result) {
|
18639 | result.type = result.type === 'combined' ? 'video' : result.type;
|
18640 | dataFn(segment, result);
|
18641 | },
|
18642 | onTrackInfo: function onTrackInfo(trackInfo) {
|
18643 | if (trackInfoFn) {
|
18644 | if (isMuxed) {
|
18645 | trackInfo.isMuxed = true;
|
18646 | }
|
18647 |
|
18648 | trackInfoFn(segment, trackInfo);
|
18649 | }
|
18650 | },
|
18651 | onAudioTimingInfo: function onAudioTimingInfo(audioTimingInfo) {
|
18652 |
|
18653 | if (audioStartFn && typeof audioTimingInfo.start !== 'undefined') {
|
18654 | audioStartFn(audioTimingInfo.start);
|
18655 | audioStartFn = null;
|
18656 | }
|
18657 |
|
18658 |
|
18659 | if (audioEndFn && typeof audioTimingInfo.end !== 'undefined') {
|
18660 | audioEndFn(audioTimingInfo.end);
|
18661 | }
|
18662 | },
|
18663 | onVideoTimingInfo: function onVideoTimingInfo(videoTimingInfo) {
|
18664 |
|
18665 | if (videoStartFn && typeof videoTimingInfo.start !== 'undefined') {
|
18666 | videoStartFn(videoTimingInfo.start);
|
18667 | videoStartFn = null;
|
18668 | }
|
18669 |
|
18670 |
|
18671 | if (videoEndFn && typeof videoTimingInfo.end !== 'undefined') {
|
18672 | videoEndFn(videoTimingInfo.end);
|
18673 | }
|
18674 | },
|
18675 | onVideoSegmentTimingInfo: function onVideoSegmentTimingInfo(videoSegmentTimingInfo) {
|
18676 | videoSegmentTimingInfoFn(videoSegmentTimingInfo);
|
18677 | },
|
18678 | onAudioSegmentTimingInfo: function onAudioSegmentTimingInfo(audioSegmentTimingInfo) {
|
18679 | audioSegmentTimingInfoFn(audioSegmentTimingInfo);
|
18680 | },
|
18681 | onId3: function onId3(id3Frames, dispatchType) {
|
18682 | id3Fn(segment, id3Frames, dispatchType);
|
18683 | },
|
18684 | onCaptions: function onCaptions(captions) {
|
18685 | captionsFn(segment, [captions]);
|
18686 | },
|
18687 | isEndOfTimeline: isEndOfTimeline,
|
18688 | onEndedTimeline: function onEndedTimeline() {
|
18689 | endedTimelineFn();
|
18690 | },
|
18691 | onTransmuxerLog: onTransmuxerLog,
|
18692 | onDone: function onDone(result) {
|
18693 | if (!doneFn) {
|
18694 | return;
|
18695 | }
|
18696 |
|
18697 | result.type = result.type === 'combined' ? 'video' : result.type;
|
18698 | doneFn(null, segment, result);
|
18699 | }
|
18700 | });
|
18701 | };
|
18702 |
|
18703 |
|
18704 |
|
18705 |
|
18706 | workerCallback({
|
18707 | action: 'probeTs',
|
18708 | transmuxer: segment.transmuxer,
|
18709 | data: bytes,
|
18710 | baseStartTime: segment.baseStartTime,
|
18711 | callback: function callback(data) {
|
18712 | segment.bytes = bytes = data.data;
|
18713 | var probeResult = data.result;
|
18714 |
|
18715 | if (probeResult) {
|
18716 | trackInfoFn(segment, {
|
18717 | hasAudio: probeResult.hasAudio,
|
18718 | hasVideo: probeResult.hasVideo,
|
18719 | isMuxed: isMuxed
|
18720 | });
|
18721 | trackInfoFn = null;
|
18722 |
|
18723 | if (probeResult.hasAudio && !isMuxed) {
|
18724 | audioStartFn(probeResult.audioStart);
|
18725 | }
|
18726 |
|
18727 | if (probeResult.hasVideo) {
|
18728 | videoStartFn(probeResult.videoStart);
|
18729 | }
|
18730 |
|
18731 | audioStartFn = null;
|
18732 | videoStartFn = null;
|
18733 | }
|
18734 |
|
18735 | finish();
|
18736 | }
|
18737 | });
|
18738 | };
|
18739 |
|
18740 | var handleSegmentBytes = function handleSegmentBytes(_ref5) {
|
18741 | var segment = _ref5.segment,
|
18742 | bytes = _ref5.bytes,
|
18743 | trackInfoFn = _ref5.trackInfoFn,
|
18744 | timingInfoFn = _ref5.timingInfoFn,
|
18745 | videoSegmentTimingInfoFn = _ref5.videoSegmentTimingInfoFn,
|
18746 | audioSegmentTimingInfoFn = _ref5.audioSegmentTimingInfoFn,
|
18747 | id3Fn = _ref5.id3Fn,
|
18748 | captionsFn = _ref5.captionsFn,
|
18749 | isEndOfTimeline = _ref5.isEndOfTimeline,
|
18750 | endedTimelineFn = _ref5.endedTimelineFn,
|
18751 | dataFn = _ref5.dataFn,
|
18752 | doneFn = _ref5.doneFn,
|
18753 | onTransmuxerLog = _ref5.onTransmuxerLog;
|
18754 | var bytesAsUint8Array = new Uint8Array(bytes);
|
18755 |
|
18756 |
|
18757 |
|
18758 |
|
18759 |
|
18760 | if (isLikelyFmp4MediaSegment(bytesAsUint8Array)) {
|
18761 | segment.isFmp4 = true;
|
18762 | var tracks = segment.map.tracks;
|
18763 | var trackInfo = {
|
18764 | isFmp4: true,
|
18765 | hasVideo: !!tracks.video,
|
18766 | hasAudio: !!tracks.audio
|
18767 | };
|
18768 |
|
18769 |
|
18770 | if (tracks.audio && tracks.audio.codec && tracks.audio.codec !== 'enca') {
|
18771 | trackInfo.audioCodec = tracks.audio.codec;
|
18772 | }
|
18773 |
|
18774 |
|
18775 |
|
18776 | if (tracks.video && tracks.video.codec && tracks.video.codec !== 'encv') {
|
18777 | trackInfo.videoCodec = tracks.video.codec;
|
18778 | }
|
18779 |
|
18780 | if (tracks.video && tracks.audio) {
|
18781 | trackInfo.isMuxed = true;
|
18782 | }
|
18783 |
|
18784 |
|
18785 |
|
18786 | trackInfoFn(segment, trackInfo);
|
18787 |
|
18788 |
|
18789 |
|
18790 |
|
18791 |
|
18792 |
|
18793 | var finishLoading = function finishLoading(captions) {
|
18794 |
|
18795 |
|
18796 |
|
18797 |
|
18798 | dataFn(segment, {
|
18799 | data: bytesAsUint8Array,
|
18800 | type: trackInfo.hasAudio && !trackInfo.isMuxed ? 'audio' : 'video'
|
18801 | });
|
18802 |
|
18803 | if (captions && captions.length) {
|
18804 | captionsFn(segment, captions);
|
18805 | }
|
18806 |
|
18807 | doneFn(null, segment, {});
|
18808 | };
|
18809 |
|
18810 | workerCallback({
|
18811 | action: 'probeMp4StartTime',
|
18812 | timescales: segment.map.timescales,
|
18813 | data: bytesAsUint8Array,
|
18814 | transmuxer: segment.transmuxer,
|
18815 | callback: function callback(_ref6) {
|
18816 | var data = _ref6.data,
|
18817 | startTime = _ref6.startTime;
|
18818 |
|
18819 | bytes = data.buffer;
|
18820 | segment.bytes = bytesAsUint8Array = data;
|
18821 |
|
18822 | if (trackInfo.hasAudio && !trackInfo.isMuxed) {
|
18823 | timingInfoFn(segment, 'audio', 'start', startTime);
|
18824 | }
|
18825 |
|
18826 | if (trackInfo.hasVideo) {
|
18827 | timingInfoFn(segment, 'video', 'start', startTime);
|
18828 | }
|
18829 |
|
18830 |
|
18831 |
|
18832 | if (!tracks.video || !data.byteLength || !segment.transmuxer) {
|
18833 | finishLoading();
|
18834 | return;
|
18835 | }
|
18836 |
|
18837 | workerCallback({
|
18838 | action: 'pushMp4Captions',
|
18839 | endAction: 'mp4Captions',
|
18840 | transmuxer: segment.transmuxer,
|
18841 | data: bytesAsUint8Array,
|
18842 | timescales: segment.map.timescales,
|
18843 | trackIds: [tracks.video.id],
|
18844 | callback: function callback(message) {
|
18845 |
|
18846 | bytes = message.data.buffer;
|
18847 | segment.bytes = bytesAsUint8Array = message.data;
|
18848 | message.logs.forEach(function (log) {
|
18849 | onTransmuxerLog(videojs__default["default"].mergeOptions(log, {
|
18850 | stream: 'mp4CaptionParser'
|
18851 | }));
|
18852 | });
|
18853 | finishLoading(message.captions);
|
18854 | }
|
18855 | });
|
18856 | }
|
18857 | });
|
18858 | return;
|
18859 | }
|
18860 |
|
18861 |
|
18862 | if (!segment.transmuxer) {
|
18863 | doneFn(null, segment, {});
|
18864 | return;
|
18865 | }
|
18866 |
|
18867 | if (typeof segment.container === 'undefined') {
|
18868 | segment.container = detectContainerForBytes(bytesAsUint8Array);
|
18869 | }
|
18870 |
|
18871 | if (segment.container !== 'ts' && segment.container !== 'aac') {
|
18872 | trackInfoFn(segment, {
|
18873 | hasAudio: false,
|
18874 | hasVideo: false
|
18875 | });
|
18876 | doneFn(null, segment, {});
|
18877 | return;
|
18878 | }
|
18879 |
|
18880 |
|
18881 | transmuxAndNotify({
|
18882 | segment: segment,
|
18883 | bytes: bytes,
|
18884 | trackInfoFn: trackInfoFn,
|
18885 | timingInfoFn: timingInfoFn,
|
18886 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
18887 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
18888 | id3Fn: id3Fn,
|
18889 | captionsFn: captionsFn,
|
18890 | isEndOfTimeline: isEndOfTimeline,
|
18891 | endedTimelineFn: endedTimelineFn,
|
18892 | dataFn: dataFn,
|
18893 | doneFn: doneFn,
|
18894 | onTransmuxerLog: onTransmuxerLog
|
18895 | });
|
18896 | };
|
18897 |
|
18898 | var decrypt = function decrypt(_ref7, callback) {
|
18899 | var id = _ref7.id,
|
18900 | key = _ref7.key,
|
18901 | encryptedBytes = _ref7.encryptedBytes,
|
18902 | decryptionWorker = _ref7.decryptionWorker;
|
18903 |
|
18904 | var decryptionHandler = function decryptionHandler(event) {
|
18905 | if (event.data.source === id) {
|
18906 | decryptionWorker.removeEventListener('message', decryptionHandler);
|
18907 | var decrypted = event.data.decrypted;
|
18908 | callback(new Uint8Array(decrypted.bytes, decrypted.byteOffset, decrypted.byteLength));
|
18909 | }
|
18910 | };
|
18911 |
|
18912 | decryptionWorker.addEventListener('message', decryptionHandler);
|
18913 | var keyBytes;
|
18914 |
|
18915 | if (key.bytes.slice) {
|
18916 | keyBytes = key.bytes.slice();
|
18917 | } else {
|
18918 | keyBytes = new Uint32Array(Array.prototype.slice.call(key.bytes));
|
18919 | }
|
18920 |
|
18921 |
|
18922 | decryptionWorker.postMessage(createTransferableMessage({
|
18923 | source: id,
|
18924 | encrypted: encryptedBytes,
|
18925 | key: keyBytes,
|
18926 | iv: key.iv
|
18927 | }), [encryptedBytes.buffer, keyBytes.buffer]);
|
18928 | };
|
18929 | |
18930 |
|
18931 |
|
18932 |
|
18933 |
|
18934 |
|
18935 |
|
18936 |
|
18937 |
|
18938 |
|
18939 |
|
18940 |
|
18941 |
|
18942 |
|
18943 |
|
18944 |
|
18945 |
|
18946 |
|
18947 |
|
18948 |
|
18949 |
|
18950 |
|
18951 |
|
18952 |
|
18953 |
|
18954 |
|
18955 | var decryptSegment = function decryptSegment(_ref8) {
|
18956 | var decryptionWorker = _ref8.decryptionWorker,
|
18957 | segment = _ref8.segment,
|
18958 | trackInfoFn = _ref8.trackInfoFn,
|
18959 | timingInfoFn = _ref8.timingInfoFn,
|
18960 | videoSegmentTimingInfoFn = _ref8.videoSegmentTimingInfoFn,
|
18961 | audioSegmentTimingInfoFn = _ref8.audioSegmentTimingInfoFn,
|
18962 | id3Fn = _ref8.id3Fn,
|
18963 | captionsFn = _ref8.captionsFn,
|
18964 | isEndOfTimeline = _ref8.isEndOfTimeline,
|
18965 | endedTimelineFn = _ref8.endedTimelineFn,
|
18966 | dataFn = _ref8.dataFn,
|
18967 | doneFn = _ref8.doneFn,
|
18968 | onTransmuxerLog = _ref8.onTransmuxerLog;
|
18969 | decrypt({
|
18970 | id: segment.requestId,
|
18971 | key: segment.key,
|
18972 | encryptedBytes: segment.encryptedBytes,
|
18973 | decryptionWorker: decryptionWorker
|
18974 | }, function (decryptedBytes) {
|
18975 | segment.bytes = decryptedBytes;
|
18976 | handleSegmentBytes({
|
18977 | segment: segment,
|
18978 | bytes: segment.bytes,
|
18979 | trackInfoFn: trackInfoFn,
|
18980 | timingInfoFn: timingInfoFn,
|
18981 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
18982 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
18983 | id3Fn: id3Fn,
|
18984 | captionsFn: captionsFn,
|
18985 | isEndOfTimeline: isEndOfTimeline,
|
18986 | endedTimelineFn: endedTimelineFn,
|
18987 | dataFn: dataFn,
|
18988 | doneFn: doneFn,
|
18989 | onTransmuxerLog: onTransmuxerLog
|
18990 | });
|
18991 | });
|
18992 | };
|
18993 | |
18994 |
|
18995 |
|
18996 |
|
18997 |
|
18998 |
|
18999 |
|
19000 |
|
19001 |
|
19002 |
|
19003 |
|
19004 |
|
19005 |
|
19006 |
|
19007 |
|
19008 |
|
19009 |
|
19010 |
|
19011 |
|
19012 |
|
19013 |
|
19014 |
|
19015 |
|
19016 |
|
19017 |
|
19018 |
|
19019 |
|
19020 |
|
19021 |
|
19022 |
|
19023 |
|
19024 | var waitForCompletion = function waitForCompletion(_ref9) {
|
19025 | var activeXhrs = _ref9.activeXhrs,
|
19026 | decryptionWorker = _ref9.decryptionWorker,
|
19027 | trackInfoFn = _ref9.trackInfoFn,
|
19028 | timingInfoFn = _ref9.timingInfoFn,
|
19029 | videoSegmentTimingInfoFn = _ref9.videoSegmentTimingInfoFn,
|
19030 | audioSegmentTimingInfoFn = _ref9.audioSegmentTimingInfoFn,
|
19031 | id3Fn = _ref9.id3Fn,
|
19032 | captionsFn = _ref9.captionsFn,
|
19033 | isEndOfTimeline = _ref9.isEndOfTimeline,
|
19034 | endedTimelineFn = _ref9.endedTimelineFn,
|
19035 | dataFn = _ref9.dataFn,
|
19036 | doneFn = _ref9.doneFn,
|
19037 | onTransmuxerLog = _ref9.onTransmuxerLog;
|
19038 | var count = 0;
|
19039 | var didError = false;
|
19040 | return function (error, segment) {
|
19041 | if (didError) {
|
19042 | return;
|
19043 | }
|
19044 |
|
19045 | if (error) {
|
19046 | didError = true;
|
19047 |
|
19048 | abortAll(activeXhrs);
|
19049 |
|
19050 |
|
19051 |
|
19052 |
|
19053 |
|
19054 |
|
19055 |
|
19056 |
|
19057 |
|
19058 |
|
19059 |
|
19060 | return doneFn(error, segment);
|
19061 | }
|
19062 |
|
19063 | count += 1;
|
19064 |
|
19065 | if (count === activeXhrs.length) {
|
19066 | var segmentFinish = function segmentFinish() {
|
19067 | if (segment.encryptedBytes) {
|
19068 | return decryptSegment({
|
19069 | decryptionWorker: decryptionWorker,
|
19070 | segment: segment,
|
19071 | trackInfoFn: trackInfoFn,
|
19072 | timingInfoFn: timingInfoFn,
|
19073 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
19074 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
19075 | id3Fn: id3Fn,
|
19076 | captionsFn: captionsFn,
|
19077 | isEndOfTimeline: isEndOfTimeline,
|
19078 | endedTimelineFn: endedTimelineFn,
|
19079 | dataFn: dataFn,
|
19080 | doneFn: doneFn,
|
19081 | onTransmuxerLog: onTransmuxerLog
|
19082 | });
|
19083 | }
|
19084 |
|
19085 |
|
19086 | handleSegmentBytes({
|
19087 | segment: segment,
|
19088 | bytes: segment.bytes,
|
19089 | trackInfoFn: trackInfoFn,
|
19090 | timingInfoFn: timingInfoFn,
|
19091 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
19092 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
19093 | id3Fn: id3Fn,
|
19094 | captionsFn: captionsFn,
|
19095 | isEndOfTimeline: isEndOfTimeline,
|
19096 | endedTimelineFn: endedTimelineFn,
|
19097 | dataFn: dataFn,
|
19098 | doneFn: doneFn,
|
19099 | onTransmuxerLog: onTransmuxerLog
|
19100 | });
|
19101 | };
|
19102 |
|
19103 |
|
19104 | segment.endOfAllRequests = Date.now();
|
19105 |
|
19106 | if (segment.map && segment.map.encryptedBytes && !segment.map.bytes) {
|
19107 | return decrypt({
|
19108 | decryptionWorker: decryptionWorker,
|
19109 |
|
19110 |
|
19111 |
|
19112 | id: segment.requestId + '-init',
|
19113 | encryptedBytes: segment.map.encryptedBytes,
|
19114 | key: segment.map.key
|
19115 | }, function (decryptedBytes) {
|
19116 | segment.map.bytes = decryptedBytes;
|
19117 | parseInitSegment(segment, function (parseError) {
|
19118 | if (parseError) {
|
19119 | abortAll(activeXhrs);
|
19120 | return doneFn(parseError, segment);
|
19121 | }
|
19122 |
|
19123 | segmentFinish();
|
19124 | });
|
19125 | });
|
19126 | }
|
19127 |
|
19128 | segmentFinish();
|
19129 | }
|
19130 | };
|
19131 | };
|
19132 | |
19133 |
|
19134 |
|
19135 |
|
19136 |
|
19137 |
|
19138 |
|
19139 |
|
19140 |
|
19141 | var handleLoadEnd = function handleLoadEnd(_ref10) {
|
19142 | var loadendState = _ref10.loadendState,
|
19143 | abortFn = _ref10.abortFn;
|
19144 | return function (event) {
|
19145 | var request = event.target;
|
19146 |
|
19147 | if (request.aborted && abortFn && !loadendState.calledAbortFn) {
|
19148 | abortFn();
|
19149 | loadendState.calledAbortFn = true;
|
19150 | }
|
19151 | };
|
19152 | };
|
19153 | |
19154 |
|
19155 |
|
19156 |
|
19157 |
|
19158 |
|
19159 |
|
19160 |
|
19161 |
|
19162 |
|
19163 |
|
19164 |
|
19165 |
|
19166 |
|
19167 |
|
19168 |
|
19169 |
|
19170 |
|
19171 |
|
19172 |
|
19173 |
|
19174 |
|
19175 |
|
19176 |
|
19177 |
|
19178 |
|
19179 |
|
19180 | var handleProgress = function handleProgress(_ref11) {
|
19181 | var segment = _ref11.segment,
|
19182 | progressFn = _ref11.progressFn;
|
19183 | _ref11.trackInfoFn;
|
19184 | _ref11.timingInfoFn;
|
19185 | _ref11.videoSegmentTimingInfoFn;
|
19186 | _ref11.audioSegmentTimingInfoFn;
|
19187 | _ref11.id3Fn;
|
19188 | _ref11.captionsFn;
|
19189 | _ref11.isEndOfTimeline;
|
19190 | _ref11.endedTimelineFn;
|
19191 | _ref11.dataFn;
|
19192 | return function (event) {
|
19193 | var request = event.target;
|
19194 |
|
19195 | if (request.aborted) {
|
19196 | return;
|
19197 | }
|
19198 |
|
19199 | segment.stats = videojs__default["default"].mergeOptions(segment.stats, getProgressStats(event));
|
19200 |
|
19201 | if (!segment.stats.firstBytesReceivedAt && segment.stats.bytesReceived) {
|
19202 | segment.stats.firstBytesReceivedAt = Date.now();
|
19203 | }
|
19204 |
|
19205 | return progressFn(event, segment);
|
19206 | };
|
19207 | };
|
19208 | |
19209 |
|
19210 |
|
19211 |
|
19212 |
|
19213 |
|
19214 |
|
19215 |
|
19216 |
|
19217 |
|
19218 |
|
19219 |
|
19220 |
|
19221 |
|
19222 |
|
19223 |
|
19224 |
|
19225 |
|
19226 |
|
19227 |
|
19228 |
|
19229 |
|
19230 |
|
19231 |
|
19232 |
|
19233 |
|
19234 |
|
19235 |
|
19236 |
|
19237 |
|
19238 |
|
19239 |
|
19240 |
|
19241 |
|
19242 |
|
19243 |
|
19244 |
|
19245 |
|
19246 |
|
19247 |
|
19248 |
|
19249 |
|
19250 |
|
19251 |
|
19252 |
|
19253 |
|
19254 |
|
19255 |
|
19256 |
|
19257 |
|
19258 |
|
19259 |
|
19260 |
|
19261 |
|
19262 |
|
19263 |
|
19264 |
|
19265 |
|
19266 |
|
19267 |
|
19268 |
|
19269 |
|
19270 |
|
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 |
|
19276 |
|
19277 |
|
19278 | var mediaSegmentRequest = function mediaSegmentRequest(_ref12) {
|
19279 | var xhr = _ref12.xhr,
|
19280 | xhrOptions = _ref12.xhrOptions,
|
19281 | decryptionWorker = _ref12.decryptionWorker,
|
19282 | segment = _ref12.segment,
|
19283 | abortFn = _ref12.abortFn,
|
19284 | progressFn = _ref12.progressFn,
|
19285 | trackInfoFn = _ref12.trackInfoFn,
|
19286 | timingInfoFn = _ref12.timingInfoFn,
|
19287 | videoSegmentTimingInfoFn = _ref12.videoSegmentTimingInfoFn,
|
19288 | audioSegmentTimingInfoFn = _ref12.audioSegmentTimingInfoFn,
|
19289 | id3Fn = _ref12.id3Fn,
|
19290 | captionsFn = _ref12.captionsFn,
|
19291 | isEndOfTimeline = _ref12.isEndOfTimeline,
|
19292 | endedTimelineFn = _ref12.endedTimelineFn,
|
19293 | dataFn = _ref12.dataFn,
|
19294 | doneFn = _ref12.doneFn,
|
19295 | onTransmuxerLog = _ref12.onTransmuxerLog;
|
19296 | var activeXhrs = [];
|
19297 | var finishProcessingFn = waitForCompletion({
|
19298 | activeXhrs: activeXhrs,
|
19299 | decryptionWorker: decryptionWorker,
|
19300 | trackInfoFn: trackInfoFn,
|
19301 | timingInfoFn: timingInfoFn,
|
19302 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
19303 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
19304 | id3Fn: id3Fn,
|
19305 | captionsFn: captionsFn,
|
19306 | isEndOfTimeline: isEndOfTimeline,
|
19307 | endedTimelineFn: endedTimelineFn,
|
19308 | dataFn: dataFn,
|
19309 | doneFn: doneFn,
|
19310 | onTransmuxerLog: onTransmuxerLog
|
19311 | });
|
19312 |
|
19313 | if (segment.key && !segment.key.bytes) {
|
19314 | var objects = [segment.key];
|
19315 |
|
19316 | if (segment.map && !segment.map.bytes && segment.map.key && segment.map.key.resolvedUri === segment.key.resolvedUri) {
|
19317 | objects.push(segment.map.key);
|
19318 | }
|
19319 |
|
19320 | var keyRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
19321 | uri: segment.key.resolvedUri,
|
19322 | responseType: 'arraybuffer'
|
19323 | });
|
19324 | var keyRequestCallback = handleKeyResponse(segment, objects, finishProcessingFn);
|
19325 | var keyXhr = xhr(keyRequestOptions, keyRequestCallback);
|
19326 | activeXhrs.push(keyXhr);
|
19327 | }
|
19328 |
|
19329 |
|
19330 | if (segment.map && !segment.map.bytes) {
|
19331 | var differentMapKey = segment.map.key && (!segment.key || segment.key.resolvedUri !== segment.map.key.resolvedUri);
|
19332 |
|
19333 | if (differentMapKey) {
|
19334 | var mapKeyRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
19335 | uri: segment.map.key.resolvedUri,
|
19336 | responseType: 'arraybuffer'
|
19337 | });
|
19338 | var mapKeyRequestCallback = handleKeyResponse(segment, [segment.map.key], finishProcessingFn);
|
19339 | var mapKeyXhr = xhr(mapKeyRequestOptions, mapKeyRequestCallback);
|
19340 | activeXhrs.push(mapKeyXhr);
|
19341 | }
|
19342 |
|
19343 | var initSegmentOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
19344 | uri: segment.map.resolvedUri,
|
19345 | responseType: 'arraybuffer',
|
19346 | headers: segmentXhrHeaders(segment.map)
|
19347 | });
|
19348 | var initSegmentRequestCallback = handleInitSegmentResponse({
|
19349 | segment: segment,
|
19350 | finishProcessingFn: finishProcessingFn
|
19351 | });
|
19352 | var initSegmentXhr = xhr(initSegmentOptions, initSegmentRequestCallback);
|
19353 | activeXhrs.push(initSegmentXhr);
|
19354 | }
|
19355 |
|
19356 | var segmentRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
19357 | uri: segment.part && segment.part.resolvedUri || segment.resolvedUri,
|
19358 | responseType: 'arraybuffer',
|
19359 | headers: segmentXhrHeaders(segment)
|
19360 | });
|
19361 | var segmentRequestCallback = handleSegmentResponse({
|
19362 | segment: segment,
|
19363 | finishProcessingFn: finishProcessingFn,
|
19364 | responseType: segmentRequestOptions.responseType
|
19365 | });
|
19366 | var segmentXhr = xhr(segmentRequestOptions, segmentRequestCallback);
|
19367 | segmentXhr.addEventListener('progress', handleProgress({
|
19368 | segment: segment,
|
19369 | progressFn: progressFn,
|
19370 | trackInfoFn: trackInfoFn,
|
19371 | timingInfoFn: timingInfoFn,
|
19372 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
19373 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
19374 | id3Fn: id3Fn,
|
19375 | captionsFn: captionsFn,
|
19376 | isEndOfTimeline: isEndOfTimeline,
|
19377 | endedTimelineFn: endedTimelineFn,
|
19378 | dataFn: dataFn
|
19379 | }));
|
19380 | activeXhrs.push(segmentXhr);
|
19381 |
|
19382 |
|
19383 | var loadendState = {};
|
19384 | activeXhrs.forEach(function (activeXhr) {
|
19385 | activeXhr.addEventListener('loadend', handleLoadEnd({
|
19386 | loadendState: loadendState,
|
19387 | abortFn: abortFn
|
19388 | }));
|
19389 | });
|
19390 | return function () {
|
19391 | return abortAll(activeXhrs);
|
19392 | };
|
19393 | };
|
19394 |
|
19395 | |
19396 |
|
19397 |
|
19398 |
|
19399 | var logFn$1 = logger('CodecUtils');
|
19400 | |
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 |
|
19407 |
|
19408 | var getCodecs = function getCodecs(media) {
|
19409 |
|
19410 |
|
19411 | var mediaAttributes = media.attributes || {};
|
19412 |
|
19413 | if (mediaAttributes.CODECS) {
|
19414 | return parseCodecs(mediaAttributes.CODECS);
|
19415 | }
|
19416 | };
|
19417 |
|
19418 | var isMaat = function isMaat(master, media) {
|
19419 | var mediaAttributes = media.attributes || {};
|
19420 | return master && master.mediaGroups && master.mediaGroups.AUDIO && mediaAttributes.AUDIO && master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
19421 | };
|
19422 | var isMuxed = function isMuxed(master, media) {
|
19423 | if (!isMaat(master, media)) {
|
19424 | return true;
|
19425 | }
|
19426 |
|
19427 | var mediaAttributes = media.attributes || {};
|
19428 | var audioGroup = master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
19429 |
|
19430 | for (var groupId in audioGroup) {
|
19431 |
|
19432 |
|
19433 |
|
19434 |
|
19435 | if (!audioGroup[groupId].uri && !audioGroup[groupId].playlists) {
|
19436 | return true;
|
19437 | }
|
19438 | }
|
19439 |
|
19440 | return false;
|
19441 | };
|
19442 | var unwrapCodecList = function unwrapCodecList(codecList) {
|
19443 | var codecs = {};
|
19444 | codecList.forEach(function (_ref) {
|
19445 | var mediaType = _ref.mediaType,
|
19446 | type = _ref.type,
|
19447 | details = _ref.details;
|
19448 | codecs[mediaType] = codecs[mediaType] || [];
|
19449 | codecs[mediaType].push(translateLegacyCodec("" + type + details));
|
19450 | });
|
19451 | Object.keys(codecs).forEach(function (mediaType) {
|
19452 | if (codecs[mediaType].length > 1) {
|
19453 | logFn$1("multiple " + mediaType + " codecs found as attributes: " + codecs[mediaType].join(', ') + ". Setting playlist codecs to null so that we wait for mux.js to probe segments for real codecs.");
|
19454 | codecs[mediaType] = null;
|
19455 | return;
|
19456 | }
|
19457 |
|
19458 | codecs[mediaType] = codecs[mediaType][0];
|
19459 | });
|
19460 | return codecs;
|
19461 | };
|
19462 | var codecCount = function codecCount(codecObj) {
|
19463 | var count = 0;
|
19464 |
|
19465 | if (codecObj.audio) {
|
19466 | count++;
|
19467 | }
|
19468 |
|
19469 | if (codecObj.video) {
|
19470 | count++;
|
19471 | }
|
19472 |
|
19473 | return count;
|
19474 | };
|
19475 | |
19476 |
|
19477 |
|
19478 |
|
19479 |
|
19480 |
|
19481 |
|
19482 |
|
19483 |
|
19484 |
|
19485 |
|
19486 |
|
19487 |
|
19488 | var codecsForPlaylist = function codecsForPlaylist(master, media) {
|
19489 | var mediaAttributes = media.attributes || {};
|
19490 | var codecInfo = unwrapCodecList(getCodecs(media) || []);
|
19491 |
|
19492 |
|
19493 | if (isMaat(master, media) && !codecInfo.audio) {
|
19494 | if (!isMuxed(master, media)) {
|
19495 |
|
19496 |
|
19497 |
|
19498 | var defaultCodecs = unwrapCodecList(codecsFromDefault(master, mediaAttributes.AUDIO) || []);
|
19499 |
|
19500 | if (defaultCodecs.audio) {
|
19501 | codecInfo.audio = defaultCodecs.audio;
|
19502 | }
|
19503 | }
|
19504 | }
|
19505 |
|
19506 | return codecInfo;
|
19507 | };
|
19508 |
|
19509 | var logFn = logger('PlaylistSelector');
|
19510 |
|
19511 | var representationToString = function representationToString(representation) {
|
19512 | if (!representation || !representation.playlist) {
|
19513 | return;
|
19514 | }
|
19515 |
|
19516 | var playlist = representation.playlist;
|
19517 | return JSON.stringify({
|
19518 | id: playlist.id,
|
19519 | bandwidth: representation.bandwidth,
|
19520 | width: representation.width,
|
19521 | height: representation.height,
|
19522 | codecs: playlist.attributes && playlist.attributes.CODECS || ''
|
19523 | });
|
19524 | };
|
19525 |
|
19526 | |
19527 |
|
19528 |
|
19529 |
|
19530 |
|
19531 |
|
19532 |
|
19533 |
|
19534 |
|
19535 |
|
19536 |
|
19537 |
|
19538 | var safeGetComputedStyle = function safeGetComputedStyle(el, property) {
|
19539 | if (!el) {
|
19540 | return '';
|
19541 | }
|
19542 |
|
19543 | var result = window.getComputedStyle(el);
|
19544 |
|
19545 | if (!result) {
|
19546 | return '';
|
19547 | }
|
19548 |
|
19549 | return result[property];
|
19550 | };
|
19551 | |
19552 |
|
19553 |
|
19554 |
|
19555 |
|
19556 |
|
19557 |
|
19558 |
|
19559 |
|
19560 | var stableSort = function stableSort(array, sortFn) {
|
19561 | var newArray = array.slice();
|
19562 | array.sort(function (left, right) {
|
19563 | var cmp = sortFn(left, right);
|
19564 |
|
19565 | if (cmp === 0) {
|
19566 | return newArray.indexOf(left) - newArray.indexOf(right);
|
19567 | }
|
19568 |
|
19569 | return cmp;
|
19570 | });
|
19571 | };
|
19572 | |
19573 |
|
19574 |
|
19575 |
|
19576 |
|
19577 |
|
19578 |
|
19579 |
|
19580 |
|
19581 |
|
19582 |
|
19583 |
|
19584 | var comparePlaylistBandwidth = function comparePlaylistBandwidth(left, right) {
|
19585 | var leftBandwidth;
|
19586 | var rightBandwidth;
|
19587 |
|
19588 | if (left.attributes.BANDWIDTH) {
|
19589 | leftBandwidth = left.attributes.BANDWIDTH;
|
19590 | }
|
19591 |
|
19592 | leftBandwidth = leftBandwidth || window.Number.MAX_VALUE;
|
19593 |
|
19594 | if (right.attributes.BANDWIDTH) {
|
19595 | rightBandwidth = right.attributes.BANDWIDTH;
|
19596 | }
|
19597 |
|
19598 | rightBandwidth = rightBandwidth || window.Number.MAX_VALUE;
|
19599 | return leftBandwidth - rightBandwidth;
|
19600 | };
|
19601 | |
19602 |
|
19603 |
|
19604 |
|
19605 |
|
19606 |
|
19607 |
|
19608 |
|
19609 |
|
19610 |
|
19611 |
|
19612 | var comparePlaylistResolution = function comparePlaylistResolution(left, right) {
|
19613 | var leftWidth;
|
19614 | var rightWidth;
|
19615 |
|
19616 | if (left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
|
19617 | leftWidth = left.attributes.RESOLUTION.width;
|
19618 | }
|
19619 |
|
19620 | leftWidth = leftWidth || window.Number.MAX_VALUE;
|
19621 |
|
19622 | if (right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
|
19623 | rightWidth = right.attributes.RESOLUTION.width;
|
19624 | }
|
19625 |
|
19626 | rightWidth = rightWidth || window.Number.MAX_VALUE;
|
19627 |
|
19628 |
|
19629 | if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
|
19630 | return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
|
19631 | }
|
19632 |
|
19633 | return leftWidth - rightWidth;
|
19634 | };
|
19635 | |
19636 |
|
19637 |
|
19638 |
|
19639 |
|
19640 |
|
19641 |
|
19642 |
|
19643 |
|
19644 |
|
19645 |
|
19646 |
|
19647 |
|
19648 |
|
19649 |
|
19650 |
|
19651 |
|
19652 |
|
19653 |
|
19654 |
|
19655 | var simpleSelector = function simpleSelector(master, playerBandwidth, playerWidth, playerHeight, limitRenditionByPlayerDimensions, masterPlaylistController) {
|
19656 |
|
19657 | if (!master) {
|
19658 | return;
|
19659 | }
|
19660 |
|
19661 | var options = {
|
19662 | bandwidth: playerBandwidth,
|
19663 | width: playerWidth,
|
19664 | height: playerHeight,
|
19665 | limitRenditionByPlayerDimensions: limitRenditionByPlayerDimensions
|
19666 | };
|
19667 | var playlists = master.playlists;
|
19668 |
|
19669 | if (Playlist.isAudioOnly(master)) {
|
19670 | playlists = masterPlaylistController.getAudioTrackPlaylists_();
|
19671 |
|
19672 |
|
19673 | options.audioOnly = true;
|
19674 | }
|
19675 |
|
19676 |
|
19677 | var sortedPlaylistReps = playlists.map(function (playlist) {
|
19678 | var bandwidth;
|
19679 | var width = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width;
|
19680 | var height = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.height;
|
19681 | bandwidth = playlist.attributes && playlist.attributes.BANDWIDTH;
|
19682 | bandwidth = bandwidth || window.Number.MAX_VALUE;
|
19683 | return {
|
19684 | bandwidth: bandwidth,
|
19685 | width: width,
|
19686 | height: height,
|
19687 | playlist: playlist
|
19688 | };
|
19689 | });
|
19690 | stableSort(sortedPlaylistReps, function (left, right) {
|
19691 | return left.bandwidth - right.bandwidth;
|
19692 | });
|
19693 |
|
19694 |
|
19695 | sortedPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
19696 | return !Playlist.isIncompatible(rep.playlist);
|
19697 | });
|
19698 |
|
19699 |
|
19700 | var enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
19701 | return Playlist.isEnabled(rep.playlist);
|
19702 | });
|
19703 |
|
19704 | if (!enabledPlaylistReps.length) {
|
19705 |
|
19706 |
|
19707 |
|
19708 | enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
19709 | return !Playlist.isDisabled(rep.playlist);
|
19710 | });
|
19711 | }
|
19712 |
|
19713 |
|
19714 |
|
19715 | var bandwidthPlaylistReps = enabledPlaylistReps.filter(function (rep) {
|
19716 | return rep.bandwidth * Config.BANDWIDTH_VARIANCE < playerBandwidth;
|
19717 | });
|
19718 | var highestRemainingBandwidthRep = bandwidthPlaylistReps[bandwidthPlaylistReps.length - 1];
|
19719 |
|
19720 |
|
19721 | var bandwidthBestRep = bandwidthPlaylistReps.filter(function (rep) {
|
19722 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
19723 | })[0];
|
19724 |
|
19725 | if (limitRenditionByPlayerDimensions === false) {
|
19726 | var _chosenRep = bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
19727 |
|
19728 | if (_chosenRep && _chosenRep.playlist) {
|
19729 | var type = 'sortedPlaylistReps';
|
19730 |
|
19731 | if (bandwidthBestRep) {
|
19732 | type = 'bandwidthBestRep';
|
19733 | }
|
19734 |
|
19735 | if (enabledPlaylistReps[0]) {
|
19736 | type = 'enabledPlaylistReps';
|
19737 | }
|
19738 |
|
19739 | logFn("choosing " + representationToString(_chosenRep) + " using " + type + " with options", options);
|
19740 | return _chosenRep.playlist;
|
19741 | }
|
19742 |
|
19743 | logFn('could not choose a playlist with options', options);
|
19744 | return null;
|
19745 | }
|
19746 |
|
19747 |
|
19748 | var haveResolution = bandwidthPlaylistReps.filter(function (rep) {
|
19749 | return rep.width && rep.height;
|
19750 | });
|
19751 |
|
19752 | stableSort(haveResolution, function (left, right) {
|
19753 | return left.width - right.width;
|
19754 | });
|
19755 |
|
19756 | var resolutionBestRepList = haveResolution.filter(function (rep) {
|
19757 | return rep.width === playerWidth && rep.height === playerHeight;
|
19758 | });
|
19759 | highestRemainingBandwidthRep = resolutionBestRepList[resolutionBestRepList.length - 1];
|
19760 |
|
19761 | var resolutionBestRep = resolutionBestRepList.filter(function (rep) {
|
19762 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
19763 | })[0];
|
19764 | var resolutionPlusOneList;
|
19765 | var resolutionPlusOneSmallest;
|
19766 | var resolutionPlusOneRep;
|
19767 |
|
19768 |
|
19769 | if (!resolutionBestRep) {
|
19770 | resolutionPlusOneList = haveResolution.filter(function (rep) {
|
19771 | return rep.width > playerWidth || rep.height > playerHeight;
|
19772 | });
|
19773 |
|
19774 | resolutionPlusOneSmallest = resolutionPlusOneList.filter(function (rep) {
|
19775 | return rep.width === resolutionPlusOneList[0].width && rep.height === resolutionPlusOneList[0].height;
|
19776 | });
|
19777 |
|
19778 |
|
19779 | highestRemainingBandwidthRep = resolutionPlusOneSmallest[resolutionPlusOneSmallest.length - 1];
|
19780 | resolutionPlusOneRep = resolutionPlusOneSmallest.filter(function (rep) {
|
19781 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
19782 | })[0];
|
19783 | }
|
19784 |
|
19785 | var leastPixelDiffRep;
|
19786 |
|
19787 |
|
19788 |
|
19789 | if (masterPlaylistController.experimentalLeastPixelDiffSelector) {
|
19790 |
|
19791 | var leastPixelDiffList = haveResolution.map(function (rep) {
|
19792 | rep.pixelDiff = Math.abs(rep.width - playerWidth) + Math.abs(rep.height - playerHeight);
|
19793 | return rep;
|
19794 | });
|
19795 |
|
19796 | stableSort(leastPixelDiffList, function (left, right) {
|
19797 |
|
19798 | if (left.pixelDiff === right.pixelDiff) {
|
19799 | return right.bandwidth - left.bandwidth;
|
19800 | }
|
19801 |
|
19802 | return left.pixelDiff - right.pixelDiff;
|
19803 | });
|
19804 | leastPixelDiffRep = leastPixelDiffList[0];
|
19805 | }
|
19806 |
|
19807 |
|
19808 | var chosenRep = leastPixelDiffRep || resolutionPlusOneRep || resolutionBestRep || bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
19809 |
|
19810 | if (chosenRep && chosenRep.playlist) {
|
19811 | var _type = 'sortedPlaylistReps';
|
19812 |
|
19813 | if (leastPixelDiffRep) {
|
19814 | _type = 'leastPixelDiffRep';
|
19815 | } else if (resolutionPlusOneRep) {
|
19816 | _type = 'resolutionPlusOneRep';
|
19817 | } else if (resolutionBestRep) {
|
19818 | _type = 'resolutionBestRep';
|
19819 | } else if (bandwidthBestRep) {
|
19820 | _type = 'bandwidthBestRep';
|
19821 | } else if (enabledPlaylistReps[0]) {
|
19822 | _type = 'enabledPlaylistReps';
|
19823 | }
|
19824 |
|
19825 | logFn("choosing " + representationToString(chosenRep) + " using " + _type + " with options", options);
|
19826 | return chosenRep.playlist;
|
19827 | }
|
19828 |
|
19829 | logFn('could not choose a playlist with options', options);
|
19830 | return null;
|
19831 | };
|
19832 |
|
19833 | |
19834 |
|
19835 |
|
19836 |
|
19837 |
|
19838 |
|
19839 |
|
19840 |
|
19841 |
|
19842 |
|
19843 |
|
19844 | var lastBandwidthSelector = function lastBandwidthSelector() {
|
19845 | var pixelRatio = this.useDevicePixelRatio ? window.devicePixelRatio || 1 : 1;
|
19846 | return simpleSelector(this.playlists.master, this.systemBandwidth, parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10) * pixelRatio, parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10) * pixelRatio, this.limitRenditionByPlayerDimensions, this.masterPlaylistController_);
|
19847 | };
|
19848 | |
19849 |
|
19850 |
|
19851 |
|
19852 |
|
19853 |
|
19854 |
|
19855 |
|
19856 |
|
19857 |
|
19858 |
|
19859 |
|
19860 |
|
19861 |
|
19862 |
|
19863 | var movingAverageBandwidthSelector = function movingAverageBandwidthSelector(decay) {
|
19864 | var average = -1;
|
19865 | var lastSystemBandwidth = -1;
|
19866 |
|
19867 | if (decay < 0 || decay > 1) {
|
19868 | throw new Error('Moving average bandwidth decay must be between 0 and 1.');
|
19869 | }
|
19870 |
|
19871 | return function () {
|
19872 | var pixelRatio = this.useDevicePixelRatio ? window.devicePixelRatio || 1 : 1;
|
19873 |
|
19874 | if (average < 0) {
|
19875 | average = this.systemBandwidth;
|
19876 | lastSystemBandwidth = this.systemBandwidth;
|
19877 | }
|
19878 |
|
19879 |
|
19880 |
|
19881 |
|
19882 |
|
19883 |
|
19884 | if (this.systemBandwidth > 0 && this.systemBandwidth !== lastSystemBandwidth) {
|
19885 | average = decay * this.systemBandwidth + (1 - decay) * average;
|
19886 | lastSystemBandwidth = this.systemBandwidth;
|
19887 | }
|
19888 |
|
19889 | return simpleSelector(this.playlists.master, average, parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10) * pixelRatio, parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10) * pixelRatio, this.limitRenditionByPlayerDimensions, this.masterPlaylistController_);
|
19890 | };
|
19891 | };
|
19892 | |
19893 |
|
19894 |
|
19895 |
|
19896 |
|
19897 |
|
19898 |
|
19899 |
|
19900 |
|
19901 |
|
19902 |
|
19903 |
|
19904 |
|
19905 |
|
19906 |
|
19907 |
|
19908 |
|
19909 |
|
19910 |
|
19911 |
|
19912 |
|
19913 |
|
19914 |
|
19915 |
|
19916 |
|
19917 |
|
19918 |
|
19919 |
|
19920 |
|
19921 | var minRebufferMaxBandwidthSelector = function minRebufferMaxBandwidthSelector(settings) {
|
19922 | var master = settings.master,
|
19923 | currentTime = settings.currentTime,
|
19924 | bandwidth = settings.bandwidth,
|
19925 | duration = settings.duration,
|
19926 | segmentDuration = settings.segmentDuration,
|
19927 | timeUntilRebuffer = settings.timeUntilRebuffer,
|
19928 | currentTimeline = settings.currentTimeline,
|
19929 | syncController = settings.syncController;
|
19930 |
|
19931 |
|
19932 | var compatiblePlaylists = master.playlists.filter(function (playlist) {
|
19933 | return !Playlist.isIncompatible(playlist);
|
19934 | });
|
19935 |
|
19936 |
|
19937 | var enabledPlaylists = compatiblePlaylists.filter(Playlist.isEnabled);
|
19938 |
|
19939 | if (!enabledPlaylists.length) {
|
19940 |
|
19941 |
|
19942 |
|
19943 | enabledPlaylists = compatiblePlaylists.filter(function (playlist) {
|
19944 | return !Playlist.isDisabled(playlist);
|
19945 | });
|
19946 | }
|
19947 |
|
19948 | var bandwidthPlaylists = enabledPlaylists.filter(Playlist.hasAttribute.bind(null, 'BANDWIDTH'));
|
19949 | var rebufferingEstimates = bandwidthPlaylists.map(function (playlist) {
|
19950 | var syncPoint = syncController.getSyncPoint(playlist, duration, currentTimeline, currentTime);
|
19951 |
|
19952 |
|
19953 | var numRequests = syncPoint ? 1 : 2;
|
19954 | var requestTimeEstimate = Playlist.estimateSegmentRequestTime(segmentDuration, bandwidth, playlist);
|
19955 | var rebufferingImpact = requestTimeEstimate * numRequests - timeUntilRebuffer;
|
19956 | return {
|
19957 | playlist: playlist,
|
19958 | rebufferingImpact: rebufferingImpact
|
19959 | };
|
19960 | });
|
19961 | var noRebufferingPlaylists = rebufferingEstimates.filter(function (estimate) {
|
19962 | return estimate.rebufferingImpact <= 0;
|
19963 | });
|
19964 |
|
19965 | stableSort(noRebufferingPlaylists, function (a, b) {
|
19966 | return comparePlaylistBandwidth(b.playlist, a.playlist);
|
19967 | });
|
19968 |
|
19969 | if (noRebufferingPlaylists.length) {
|
19970 | return noRebufferingPlaylists[0];
|
19971 | }
|
19972 |
|
19973 | stableSort(rebufferingEstimates, function (a, b) {
|
19974 | return a.rebufferingImpact - b.rebufferingImpact;
|
19975 | });
|
19976 | return rebufferingEstimates[0] || null;
|
19977 | };
|
19978 | |
19979 |
|
19980 |
|
19981 |
|
19982 |
|
19983 |
|
19984 |
|
19985 |
|
19986 |
|
19987 |
|
19988 |
|
19989 |
|
19990 | var lowestBitrateCompatibleVariantSelector = function lowestBitrateCompatibleVariantSelector() {
|
19991 | var _this = this;
|
19992 |
|
19993 |
|
19994 |
|
19995 | var playlists = this.playlists.master.playlists.filter(Playlist.isEnabled);
|
19996 |
|
19997 | stableSort(playlists, function (a, b) {
|
19998 | return comparePlaylistBandwidth(a, b);
|
19999 | });
|
20000 |
|
20001 |
|
20002 |
|
20003 |
|
20004 |
|
20005 | var playlistsWithVideo = playlists.filter(function (playlist) {
|
20006 | return !!codecsForPlaylist(_this.playlists.master, playlist).video;
|
20007 | });
|
20008 | return playlistsWithVideo[0] || null;
|
20009 | };
|
20010 |
|
20011 | |
20012 |
|
20013 |
|
20014 |
|
20015 |
|
20016 |
|
20017 |
|
20018 | var concatSegments = function concatSegments(segmentObj) {
|
20019 | var offset = 0;
|
20020 | var tempBuffer;
|
20021 |
|
20022 | if (segmentObj.bytes) {
|
20023 | tempBuffer = new Uint8Array(segmentObj.bytes);
|
20024 |
|
20025 | segmentObj.segments.forEach(function (segment) {
|
20026 | tempBuffer.set(segment, offset);
|
20027 | offset += segment.byteLength;
|
20028 | });
|
20029 | }
|
20030 |
|
20031 | return tempBuffer;
|
20032 | };
|
20033 |
|
20034 | |
20035 |
|
20036 |
|
20037 | |
20038 |
|
20039 |
|
20040 |
|
20041 |
|
20042 |
|
20043 |
|
20044 |
|
20045 |
|
20046 | var createCaptionsTrackIfNotExists = function createCaptionsTrackIfNotExists(inbandTextTracks, tech, captionStream) {
|
20047 | if (!inbandTextTracks[captionStream]) {
|
20048 | tech.trigger({
|
20049 | type: 'usage',
|
20050 | name: 'vhs-608'
|
20051 | });
|
20052 | tech.trigger({
|
20053 | type: 'usage',
|
20054 | name: 'hls-608'
|
20055 | });
|
20056 | var instreamId = captionStream;
|
20057 |
|
20058 | if (/^cc708_/.test(captionStream)) {
|
20059 | instreamId = 'SERVICE' + captionStream.split('_')[1];
|
20060 | }
|
20061 |
|
20062 | var track = tech.textTracks().getTrackById(instreamId);
|
20063 |
|
20064 | if (track) {
|
20065 |
|
20066 |
|
20067 |
|
20068 | inbandTextTracks[captionStream] = track;
|
20069 | } else {
|
20070 |
|
20071 |
|
20072 | var captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
|
20073 | var label = captionStream;
|
20074 | var language = captionStream;
|
20075 | var def = false;
|
20076 | var captionService = captionServices[instreamId];
|
20077 |
|
20078 | if (captionService) {
|
20079 | label = captionService.label;
|
20080 | language = captionService.language;
|
20081 | def = captionService.default;
|
20082 | }
|
20083 |
|
20084 |
|
20085 |
|
20086 | inbandTextTracks[captionStream] = tech.addRemoteTextTrack({
|
20087 | kind: 'captions',
|
20088 | id: instreamId,
|
20089 |
|
20090 | default: def,
|
20091 | label: label,
|
20092 | language: language
|
20093 | }, false).track;
|
20094 | }
|
20095 | }
|
20096 | };
|
20097 | |
20098 |
|
20099 |
|
20100 |
|
20101 |
|
20102 |
|
20103 |
|
20104 |
|
20105 |
|
20106 |
|
20107 | var addCaptionData = function addCaptionData(_ref) {
|
20108 | var inbandTextTracks = _ref.inbandTextTracks,
|
20109 | captionArray = _ref.captionArray,
|
20110 | timestampOffset = _ref.timestampOffset;
|
20111 |
|
20112 | if (!captionArray) {
|
20113 | return;
|
20114 | }
|
20115 |
|
20116 | var Cue = window.WebKitDataCue || window.VTTCue;
|
20117 | captionArray.forEach(function (caption) {
|
20118 | var track = caption.stream;
|
20119 | inbandTextTracks[track].addCue(new Cue(caption.startTime + timestampOffset, caption.endTime + timestampOffset, caption.text));
|
20120 | });
|
20121 | };
|
20122 | |
20123 |
|
20124 |
|
20125 |
|
20126 |
|
20127 |
|
20128 |
|
20129 |
|
20130 |
|
20131 | var deprecateOldCue = function deprecateOldCue(cue) {
|
20132 | Object.defineProperties(cue.frame, {
|
20133 | id: {
|
20134 | get: function get() {
|
20135 | videojs__default["default"].log.warn('cue.frame.id is deprecated. Use cue.value.key instead.');
|
20136 | return cue.value.key;
|
20137 | }
|
20138 | },
|
20139 | value: {
|
20140 | get: function get() {
|
20141 | videojs__default["default"].log.warn('cue.frame.value is deprecated. Use cue.value.data instead.');
|
20142 | return cue.value.data;
|
20143 | }
|
20144 | },
|
20145 | privateData: {
|
20146 | get: function get() {
|
20147 | videojs__default["default"].log.warn('cue.frame.privateData is deprecated. Use cue.value.data instead.');
|
20148 | return cue.value.data;
|
20149 | }
|
20150 | }
|
20151 | });
|
20152 | };
|
20153 | |
20154 |
|
20155 |
|
20156 |
|
20157 |
|
20158 |
|
20159 |
|
20160 |
|
20161 |
|
20162 |
|
20163 |
|
20164 |
|
20165 | var addMetadata = function addMetadata(_ref2) {
|
20166 | var inbandTextTracks = _ref2.inbandTextTracks,
|
20167 | metadataArray = _ref2.metadataArray,
|
20168 | timestampOffset = _ref2.timestampOffset,
|
20169 | videoDuration = _ref2.videoDuration;
|
20170 |
|
20171 | if (!metadataArray) {
|
20172 | return;
|
20173 | }
|
20174 |
|
20175 | var Cue = window.WebKitDataCue || window.VTTCue;
|
20176 | var metadataTrack = inbandTextTracks.metadataTrack_;
|
20177 |
|
20178 | if (!metadataTrack) {
|
20179 | return;
|
20180 | }
|
20181 |
|
20182 | metadataArray.forEach(function (metadata) {
|
20183 | var time = metadata.cueTime + timestampOffset;
|
20184 |
|
20185 |
|
20186 |
|
20187 |
|
20188 | if (typeof time !== 'number' || window.isNaN(time) || time < 0 || !(time < Infinity)) {
|
20189 | return;
|
20190 | }
|
20191 |
|
20192 | metadata.frames.forEach(function (frame) {
|
20193 | var cue = new Cue(time, time, frame.value || frame.url || frame.data || '');
|
20194 | cue.frame = frame;
|
20195 | cue.value = frame;
|
20196 | deprecateOldCue(cue);
|
20197 | metadataTrack.addCue(cue);
|
20198 | });
|
20199 | });
|
20200 |
|
20201 | if (!metadataTrack.cues || !metadataTrack.cues.length) {
|
20202 | return;
|
20203 | }
|
20204 |
|
20205 |
|
20206 |
|
20207 |
|
20208 | var cues = metadataTrack.cues;
|
20209 | var cuesArray = [];
|
20210 |
|
20211 |
|
20212 | for (var i = 0; i < cues.length; i++) {
|
20213 | if (cues[i]) {
|
20214 | cuesArray.push(cues[i]);
|
20215 | }
|
20216 | }
|
20217 |
|
20218 |
|
20219 | var cuesGroupedByStartTime = cuesArray.reduce(function (obj, cue) {
|
20220 | var timeSlot = obj[cue.startTime] || [];
|
20221 | timeSlot.push(cue);
|
20222 | obj[cue.startTime] = timeSlot;
|
20223 | return obj;
|
20224 | }, {});
|
20225 |
|
20226 | var sortedStartTimes = Object.keys(cuesGroupedByStartTime).sort(function (a, b) {
|
20227 | return Number(a) - Number(b);
|
20228 | });
|
20229 |
|
20230 | sortedStartTimes.forEach(function (startTime, idx) {
|
20231 | var cueGroup = cuesGroupedByStartTime[startTime];
|
20232 | var nextTime = Number(sortedStartTimes[idx + 1]) || videoDuration;
|
20233 |
|
20234 | cueGroup.forEach(function (cue) {
|
20235 | cue.endTime = nextTime;
|
20236 | });
|
20237 | });
|
20238 | };
|
20239 | |
20240 |
|
20241 |
|
20242 |
|
20243 |
|
20244 |
|
20245 |
|
20246 |
|
20247 |
|
20248 | var createMetadataTrackIfNotExists = function createMetadataTrackIfNotExists(inbandTextTracks, dispatchType, tech) {
|
20249 | if (inbandTextTracks.metadataTrack_) {
|
20250 | return;
|
20251 | }
|
20252 |
|
20253 | inbandTextTracks.metadataTrack_ = tech.addRemoteTextTrack({
|
20254 | kind: 'metadata',
|
20255 | label: 'Timed Metadata'
|
20256 | }, false).track;
|
20257 | inbandTextTracks.metadataTrack_.inBandMetadataTrackDispatchType = dispatchType;
|
20258 | };
|
20259 | |
20260 |
|
20261 |
|
20262 |
|
20263 |
|
20264 |
|
20265 |
|
20266 |
|
20267 |
|
20268 | var removeCuesFromTrack = function removeCuesFromTrack(start, end, track) {
|
20269 | var i;
|
20270 | var cue;
|
20271 |
|
20272 | if (!track) {
|
20273 | return;
|
20274 | }
|
20275 |
|
20276 | if (!track.cues) {
|
20277 | return;
|
20278 | }
|
20279 |
|
20280 | i = track.cues.length;
|
20281 |
|
20282 | while (i--) {
|
20283 | cue = track.cues[i];
|
20284 |
|
20285 | if (cue.startTime >= start && cue.endTime <= end) {
|
20286 | track.removeCue(cue);
|
20287 | }
|
20288 | }
|
20289 | };
|
20290 | |
20291 |
|
20292 |
|
20293 |
|
20294 |
|
20295 |
|
20296 |
|
20297 |
|
20298 | var removeDuplicateCuesFromTrack = function removeDuplicateCuesFromTrack(track) {
|
20299 | var cues = track.cues;
|
20300 |
|
20301 | if (!cues) {
|
20302 | return;
|
20303 | }
|
20304 |
|
20305 | for (var i = 0; i < cues.length; i++) {
|
20306 | var duplicates = [];
|
20307 | var occurrences = 0;
|
20308 |
|
20309 | for (var j = 0; j < cues.length; j++) {
|
20310 | if (cues[i].startTime === cues[j].startTime && cues[i].endTime === cues[j].endTime && cues[i].text === cues[j].text) {
|
20311 | occurrences++;
|
20312 |
|
20313 | if (occurrences > 1) {
|
20314 | duplicates.push(cues[j]);
|
20315 | }
|
20316 | }
|
20317 | }
|
20318 |
|
20319 | if (duplicates.length) {
|
20320 | duplicates.forEach(function (dupe) {
|
20321 | return track.removeCue(dupe);
|
20322 | });
|
20323 | }
|
20324 | }
|
20325 | };
|
20326 |
|
20327 | |
20328 |
|
20329 |
|
20330 |
|
20331 |
|
20332 |
|
20333 | var ONE_SECOND_IN_TS = 90000,
|
20334 |
|
20335 | secondsToVideoTs,
|
20336 | secondsToAudioTs,
|
20337 | videoTsToSeconds,
|
20338 | audioTsToSeconds,
|
20339 | audioTsToVideoTs,
|
20340 | videoTsToAudioTs,
|
20341 | metadataTsToSeconds;
|
20342 |
|
20343 | secondsToVideoTs = function secondsToVideoTs(seconds) {
|
20344 | return seconds * ONE_SECOND_IN_TS;
|
20345 | };
|
20346 |
|
20347 | secondsToAudioTs = function secondsToAudioTs(seconds, sampleRate) {
|
20348 | return seconds * sampleRate;
|
20349 | };
|
20350 |
|
20351 | videoTsToSeconds = function videoTsToSeconds(timestamp) {
|
20352 | return timestamp / ONE_SECOND_IN_TS;
|
20353 | };
|
20354 |
|
20355 | audioTsToSeconds = function audioTsToSeconds(timestamp, sampleRate) {
|
20356 | return timestamp / sampleRate;
|
20357 | };
|
20358 |
|
20359 | audioTsToVideoTs = function audioTsToVideoTs(timestamp, sampleRate) {
|
20360 | return secondsToVideoTs(audioTsToSeconds(timestamp, sampleRate));
|
20361 | };
|
20362 |
|
20363 | videoTsToAudioTs = function videoTsToAudioTs(timestamp, sampleRate) {
|
20364 | return secondsToAudioTs(videoTsToSeconds(timestamp), sampleRate);
|
20365 | };
|
20366 | |
20367 |
|
20368 |
|
20369 |
|
20370 |
|
20371 |
|
20372 | metadataTsToSeconds = function metadataTsToSeconds(timestamp, timelineStartPts, keepOriginalTimestamps) {
|
20373 | return videoTsToSeconds(keepOriginalTimestamps ? timestamp : timestamp - timelineStartPts);
|
20374 | };
|
20375 |
|
20376 | var clock = {
|
20377 | ONE_SECOND_IN_TS: ONE_SECOND_IN_TS,
|
20378 | secondsToVideoTs: secondsToVideoTs,
|
20379 | secondsToAudioTs: secondsToAudioTs,
|
20380 | videoTsToSeconds: videoTsToSeconds,
|
20381 | audioTsToSeconds: audioTsToSeconds,
|
20382 | audioTsToVideoTs: audioTsToVideoTs,
|
20383 | videoTsToAudioTs: videoTsToAudioTs,
|
20384 | metadataTsToSeconds: metadataTsToSeconds
|
20385 | };
|
20386 |
|
20387 | |
20388 |
|
20389 |
|
20390 |
|
20391 |
|
20392 |
|
20393 |
|
20394 |
|
20395 |
|
20396 |
|
20397 |
|
20398 |
|
20399 |
|
20400 |
|
20401 | var gopsSafeToAlignWith = function gopsSafeToAlignWith(buffer, currentTime, mapping) {
|
20402 | if (typeof currentTime === 'undefined' || currentTime === null || !buffer.length) {
|
20403 | return [];
|
20404 | }
|
20405 |
|
20406 |
|
20407 | var currentTimePts = Math.ceil((currentTime - mapping + 3) * clock.ONE_SECOND_IN_TS);
|
20408 | var i;
|
20409 |
|
20410 | for (i = 0; i < buffer.length; i++) {
|
20411 | if (buffer[i].pts > currentTimePts) {
|
20412 | break;
|
20413 | }
|
20414 | }
|
20415 |
|
20416 | return buffer.slice(i);
|
20417 | };
|
20418 | |
20419 |
|
20420 |
|
20421 |
|
20422 |
|
20423 |
|
20424 |
|
20425 |
|
20426 |
|
20427 |
|
20428 |
|
20429 |
|
20430 |
|
20431 |
|
20432 |
|
20433 | var updateGopBuffer = function updateGopBuffer(buffer, gops, replace) {
|
20434 | if (!gops.length) {
|
20435 | return buffer;
|
20436 | }
|
20437 |
|
20438 | if (replace) {
|
20439 |
|
20440 |
|
20441 |
|
20442 |
|
20443 | return gops.slice();
|
20444 | }
|
20445 |
|
20446 | var start = gops[0].pts;
|
20447 | var i = 0;
|
20448 |
|
20449 | for (i; i < buffer.length; i++) {
|
20450 | if (buffer[i].pts >= start) {
|
20451 | break;
|
20452 | }
|
20453 | }
|
20454 |
|
20455 | return buffer.slice(0, i).concat(gops);
|
20456 | };
|
20457 | |
20458 |
|
20459 |
|
20460 |
|
20461 |
|
20462 |
|
20463 |
|
20464 |
|
20465 |
|
20466 |
|
20467 |
|
20468 |
|
20469 |
|
20470 | var removeGopBuffer = function removeGopBuffer(buffer, start, end, mapping) {
|
20471 | var startPts = Math.ceil((start - mapping) * clock.ONE_SECOND_IN_TS);
|
20472 | var endPts = Math.ceil((end - mapping) * clock.ONE_SECOND_IN_TS);
|
20473 | var updatedBuffer = buffer.slice();
|
20474 | var i = buffer.length;
|
20475 |
|
20476 | while (i--) {
|
20477 | if (buffer[i].pts <= endPts) {
|
20478 | break;
|
20479 | }
|
20480 | }
|
20481 |
|
20482 | if (i === -1) {
|
20483 |
|
20484 | return updatedBuffer;
|
20485 | }
|
20486 |
|
20487 | var j = i + 1;
|
20488 |
|
20489 | while (j--) {
|
20490 | if (buffer[j].pts <= startPts) {
|
20491 | break;
|
20492 | }
|
20493 | }
|
20494 |
|
20495 |
|
20496 | j = Math.max(j, 0);
|
20497 | updatedBuffer.splice(j, i - j + 1);
|
20498 | return updatedBuffer;
|
20499 | };
|
20500 |
|
20501 | var shallowEqual = function shallowEqual(a, b) {
|
20502 |
|
20503 |
|
20504 |
|
20505 | if (!a && !b || !a && b || a && !b) {
|
20506 | return false;
|
20507 | }
|
20508 |
|
20509 |
|
20510 | if (a === b) {
|
20511 | return true;
|
20512 | }
|
20513 |
|
20514 |
|
20515 |
|
20516 | var akeys = Object.keys(a).sort();
|
20517 | var bkeys = Object.keys(b).sort();
|
20518 |
|
20519 | if (akeys.length !== bkeys.length) {
|
20520 | return false;
|
20521 | }
|
20522 |
|
20523 | for (var i = 0; i < akeys.length; i++) {
|
20524 | var key = akeys[i];
|
20525 |
|
20526 | if (key !== bkeys[i]) {
|
20527 | return false;
|
20528 | }
|
20529 |
|
20530 |
|
20531 | if (a[key] !== b[key]) {
|
20532 | return false;
|
20533 | }
|
20534 | }
|
20535 |
|
20536 | return true;
|
20537 | };
|
20538 |
|
20539 |
|
20540 | var QUOTA_EXCEEDED_ERR = 22;
|
20541 |
|
20542 | |
20543 |
|
20544 |
|
20545 |
|
20546 |
|
20547 |
|
20548 |
|
20549 |
|
20550 |
|
20551 |
|
20552 | var getSyncSegmentCandidate = function getSyncSegmentCandidate(currentTimeline, segments, targetTime) {
|
20553 | segments = segments || [];
|
20554 | var timelineSegments = [];
|
20555 | var time = 0;
|
20556 |
|
20557 | for (var i = 0; i < segments.length; i++) {
|
20558 | var segment = segments[i];
|
20559 |
|
20560 | if (currentTimeline === segment.timeline) {
|
20561 | timelineSegments.push(i);
|
20562 | time += segment.duration;
|
20563 |
|
20564 | if (time > targetTime) {
|
20565 | return i;
|
20566 | }
|
20567 | }
|
20568 | }
|
20569 |
|
20570 | if (timelineSegments.length === 0) {
|
20571 | return 0;
|
20572 | }
|
20573 |
|
20574 |
|
20575 | return timelineSegments[timelineSegments.length - 1];
|
20576 | };
|
20577 |
|
20578 |
|
20579 |
|
20580 |
|
20581 | var MIN_BACK_BUFFER = 1;
|
20582 |
|
20583 | var CHECK_BUFFER_DELAY = 500;
|
20584 |
|
20585 | var finite = function finite(num) {
|
20586 | return typeof num === 'number' && isFinite(num);
|
20587 | };
|
20588 |
|
20589 |
|
20590 |
|
20591 |
|
20592 | var MIN_SEGMENT_DURATION_TO_SAVE_STATS = 1 / 60;
|
20593 | var illegalMediaSwitch = function illegalMediaSwitch(loaderType, startingMedia, trackInfo) {
|
20594 |
|
20595 |
|
20596 | if (loaderType !== 'main' || !startingMedia || !trackInfo) {
|
20597 | return null;
|
20598 | }
|
20599 |
|
20600 | if (!trackInfo.hasAudio && !trackInfo.hasVideo) {
|
20601 | return 'Neither audio nor video found in segment.';
|
20602 | }
|
20603 |
|
20604 | if (startingMedia.hasVideo && !trackInfo.hasVideo) {
|
20605 | return 'Only audio found in segment when we expected video.' + ' We can\'t switch to audio only from a stream that had video.' + ' To get rid of this message, please add codec information to the manifest.';
|
20606 | }
|
20607 |
|
20608 | if (!startingMedia.hasVideo && trackInfo.hasVideo) {
|
20609 | return 'Video found in segment when we expected only audio.' + ' We can\'t switch to a stream with video from an audio only stream.' + ' To get rid of this message, please add codec information to the manifest.';
|
20610 | }
|
20611 |
|
20612 | return null;
|
20613 | };
|
20614 | |
20615 |
|
20616 |
|
20617 |
|
20618 |
|
20619 |
|
20620 |
|
20621 |
|
20622 |
|
20623 |
|
20624 |
|
20625 |
|
20626 |
|
20627 |
|
20628 | var safeBackBufferTrimTime = function safeBackBufferTrimTime(seekable, currentTime, targetDuration) {
|
20629 |
|
20630 |
|
20631 |
|
20632 |
|
20633 |
|
20634 | var trimTime = currentTime - Config.BACK_BUFFER_LENGTH;
|
20635 |
|
20636 | if (seekable.length) {
|
20637 |
|
20638 |
|
20639 | trimTime = Math.max(trimTime, seekable.start(0));
|
20640 | }
|
20641 |
|
20642 |
|
20643 |
|
20644 | var maxTrimTime = currentTime - targetDuration;
|
20645 | return Math.min(maxTrimTime, trimTime);
|
20646 | };
|
20647 |
|
20648 | var segmentInfoString = function segmentInfoString(segmentInfo) {
|
20649 | var startOfSegment = segmentInfo.startOfSegment,
|
20650 | duration = segmentInfo.duration,
|
20651 | segment = segmentInfo.segment,
|
20652 | part = segmentInfo.part,
|
20653 | _segmentInfo$playlist = segmentInfo.playlist,
|
20654 | seq = _segmentInfo$playlist.mediaSequence,
|
20655 | id = _segmentInfo$playlist.id,
|
20656 | _segmentInfo$playlist2 = _segmentInfo$playlist.segments,
|
20657 | segments = _segmentInfo$playlist2 === void 0 ? [] : _segmentInfo$playlist2,
|
20658 | index = segmentInfo.mediaIndex,
|
20659 | partIndex = segmentInfo.partIndex,
|
20660 | timeline = segmentInfo.timeline;
|
20661 | var segmentLen = segments.length - 1;
|
20662 | var selection = 'mediaIndex/partIndex increment';
|
20663 |
|
20664 | if (segmentInfo.getMediaInfoForTime) {
|
20665 | selection = "getMediaInfoForTime (" + segmentInfo.getMediaInfoForTime + ")";
|
20666 | } else if (segmentInfo.isSyncRequest) {
|
20667 | selection = 'getSyncSegmentCandidate (isSyncRequest)';
|
20668 | }
|
20669 |
|
20670 | var hasPartIndex = typeof partIndex === 'number';
|
20671 | var name = segmentInfo.segment.uri ? 'segment' : 'pre-segment';
|
20672 | var zeroBasedPartCount = hasPartIndex ? getKnownPartCount({
|
20673 | preloadSegment: segment
|
20674 | }) - 1 : 0;
|
20675 | return name + " [" + (seq + index) + "/" + (seq + segmentLen) + "]" + (hasPartIndex ? " part [" + partIndex + "/" + zeroBasedPartCount + "]" : '') + (" segment start/end [" + segment.start + " => " + segment.end + "]") + (hasPartIndex ? " part start/end [" + part.start + " => " + part.end + "]" : '') + (" startOfSegment [" + startOfSegment + "]") + (" duration [" + duration + "]") + (" timeline [" + timeline + "]") + (" selected by [" + selection + "]") + (" playlist [" + id + "]");
|
20676 | };
|
20677 |
|
20678 | var timingInfoPropertyForMedia = function timingInfoPropertyForMedia(mediaType) {
|
20679 | return mediaType + "TimingInfo";
|
20680 | };
|
20681 | |
20682 |
|
20683 |
|
20684 |
|
20685 |
|
20686 |
|
20687 |
|
20688 |
|
20689 |
|
20690 |
|
20691 |
|
20692 |
|
20693 |
|
20694 |
|
20695 |
|
20696 |
|
20697 |
|
20698 |
|
20699 |
|
20700 |
|
20701 |
|
20702 | var timestampOffsetForSegment = function timestampOffsetForSegment(_ref) {
|
20703 | var segmentTimeline = _ref.segmentTimeline,
|
20704 | currentTimeline = _ref.currentTimeline,
|
20705 | startOfSegment = _ref.startOfSegment,
|
20706 | buffered = _ref.buffered,
|
20707 | overrideCheck = _ref.overrideCheck;
|
20708 |
|
20709 |
|
20710 |
|
20711 |
|
20712 |
|
20713 |
|
20714 |
|
20715 | if (!overrideCheck && segmentTimeline === currentTimeline) {
|
20716 | return null;
|
20717 | }
|
20718 |
|
20719 |
|
20720 |
|
20721 |
|
20722 |
|
20723 |
|
20724 |
|
20725 |
|
20726 |
|
20727 |
|
20728 |
|
20729 |
|
20730 |
|
20731 |
|
20732 |
|
20733 |
|
20734 |
|
20735 |
|
20736 |
|
20737 |
|
20738 |
|
20739 |
|
20740 |
|
20741 |
|
20742 |
|
20743 | if (segmentTimeline < currentTimeline) {
|
20744 | return startOfSegment;
|
20745 | }
|
20746 |
|
20747 |
|
20748 |
|
20749 |
|
20750 |
|
20751 |
|
20752 | return buffered.length ? buffered.end(buffered.length - 1) : startOfSegment;
|
20753 | };
|
20754 | |
20755 |
|
20756 |
|
20757 |
|
20758 |
|
20759 |
|
20760 |
|
20761 |
|
20762 |
|
20763 |
|
20764 |
|
20765 |
|
20766 |
|
20767 |
|
20768 |
|
20769 |
|
20770 |
|
20771 |
|
20772 |
|
20773 |
|
20774 |
|
20775 |
|
20776 |
|
20777 |
|
20778 |
|
20779 |
|
20780 |
|
20781 |
|
20782 |
|
20783 |
|
20784 |
|
20785 |
|
20786 |
|
20787 |
|
20788 |
|
20789 |
|
20790 |
|
20791 |
|
20792 |
|
20793 |
|
20794 |
|
20795 |
|
20796 |
|
20797 |
|
20798 |
|
20799 |
|
20800 |
|
20801 |
|
20802 |
|
20803 |
|
20804 |
|
20805 |
|
20806 |
|
20807 |
|
20808 |
|
20809 |
|
20810 |
|
20811 |
|
20812 |
|
20813 |
|
20814 |
|
20815 |
|
20816 |
|
20817 |
|
20818 |
|
20819 |
|
20820 |
|
20821 |
|
20822 |
|
20823 |
|
20824 |
|
20825 |
|
20826 |
|
20827 |
|
20828 |
|
20829 |
|
20830 |
|
20831 |
|
20832 |
|
20833 |
|
20834 |
|
20835 |
|
20836 |
|
20837 |
|
20838 |
|
20839 |
|
20840 |
|
20841 |
|
20842 |
|
20843 |
|
20844 |
|
20845 |
|
20846 |
|
20847 |
|
20848 |
|
20849 |
|
20850 | var shouldWaitForTimelineChange = function shouldWaitForTimelineChange(_ref2) {
|
20851 | var timelineChangeController = _ref2.timelineChangeController,
|
20852 | currentTimeline = _ref2.currentTimeline,
|
20853 | segmentTimeline = _ref2.segmentTimeline,
|
20854 | loaderType = _ref2.loaderType,
|
20855 | audioDisabled = _ref2.audioDisabled;
|
20856 |
|
20857 | if (currentTimeline === segmentTimeline) {
|
20858 | return false;
|
20859 | }
|
20860 |
|
20861 | if (loaderType === 'audio') {
|
20862 | var lastMainTimelineChange = timelineChangeController.lastTimelineChange({
|
20863 | type: 'main'
|
20864 | });
|
20865 |
|
20866 |
|
20867 |
|
20868 |
|
20869 | return !lastMainTimelineChange || lastMainTimelineChange.to !== segmentTimeline;
|
20870 | }
|
20871 |
|
20872 |
|
20873 |
|
20874 |
|
20875 |
|
20876 | if (loaderType === 'main' && audioDisabled) {
|
20877 | var pendingAudioTimelineChange = timelineChangeController.pendingTimelineChange({
|
20878 | type: 'audio'
|
20879 | });
|
20880 |
|
20881 |
|
20882 |
|
20883 |
|
20884 |
|
20885 |
|
20886 |
|
20887 |
|
20888 |
|
20889 |
|
20890 |
|
20891 |
|
20892 |
|
20893 |
|
20894 |
|
20895 |
|
20896 |
|
20897 |
|
20898 | if (pendingAudioTimelineChange && pendingAudioTimelineChange.to === segmentTimeline) {
|
20899 | return false;
|
20900 | }
|
20901 |
|
20902 | return true;
|
20903 | }
|
20904 |
|
20905 | return false;
|
20906 | };
|
20907 | var mediaDuration = function mediaDuration(audioTimingInfo, videoTimingInfo) {
|
20908 | var audioDuration = audioTimingInfo && typeof audioTimingInfo.start === 'number' && typeof audioTimingInfo.end === 'number' ? audioTimingInfo.end - audioTimingInfo.start : 0;
|
20909 | var videoDuration = videoTimingInfo && typeof videoTimingInfo.start === 'number' && typeof videoTimingInfo.end === 'number' ? videoTimingInfo.end - videoTimingInfo.start : 0;
|
20910 | return Math.max(audioDuration, videoDuration);
|
20911 | };
|
20912 | var segmentTooLong = function segmentTooLong(_ref3) {
|
20913 | var segmentDuration = _ref3.segmentDuration,
|
20914 | maxDuration = _ref3.maxDuration;
|
20915 |
|
20916 |
|
20917 |
|
20918 | if (!segmentDuration) {
|
20919 | return false;
|
20920 | }
|
20921 |
|
20922 |
|
20923 |
|
20924 |
|
20925 |
|
20926 |
|
20927 |
|
20928 |
|
20929 |
|
20930 |
|
20931 |
|
20932 |
|
20933 | return Math.round(segmentDuration) > maxDuration + TIME_FUDGE_FACTOR;
|
20934 | };
|
20935 | var getTroublesomeSegmentDurationMessage = function getTroublesomeSegmentDurationMessage(segmentInfo, sourceType) {
|
20936 |
|
20937 |
|
20938 | if (sourceType !== 'hls') {
|
20939 | return null;
|
20940 | }
|
20941 |
|
20942 | var segmentDuration = mediaDuration(segmentInfo.audioTimingInfo, segmentInfo.videoTimingInfo);
|
20943 |
|
20944 |
|
20945 |
|
20946 |
|
20947 | if (!segmentDuration) {
|
20948 | return null;
|
20949 | }
|
20950 |
|
20951 | var targetDuration = segmentInfo.playlist.targetDuration;
|
20952 | var isSegmentWayTooLong = segmentTooLong({
|
20953 | segmentDuration: segmentDuration,
|
20954 | maxDuration: targetDuration * 2
|
20955 | });
|
20956 | var isSegmentSlightlyTooLong = segmentTooLong({
|
20957 | segmentDuration: segmentDuration,
|
20958 | maxDuration: targetDuration
|
20959 | });
|
20960 | var segmentTooLongMessage = "Segment with index " + segmentInfo.mediaIndex + " " + ("from playlist " + segmentInfo.playlist.id + " ") + ("has a duration of " + segmentDuration + " ") + ("when the reported duration is " + segmentInfo.duration + " ") + ("and the target duration is " + targetDuration + ". ") + 'For HLS content, a duration in excess of the target duration may result in ' + 'playback issues. See the HLS specification section on EXT-X-TARGETDURATION for ' + 'more details: ' + 'https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-4.3.3.1';
|
20961 |
|
20962 | if (isSegmentWayTooLong || isSegmentSlightlyTooLong) {
|
20963 | return {
|
20964 | severity: isSegmentWayTooLong ? 'warn' : 'info',
|
20965 | message: segmentTooLongMessage
|
20966 | };
|
20967 | }
|
20968 |
|
20969 | return null;
|
20970 | };
|
20971 | |
20972 |
|
20973 |
|
20974 |
|
20975 |
|
20976 |
|
20977 |
|
20978 |
|
20979 | var SegmentLoader = function (_videojs$EventTarget) {
|
20980 | inheritsLoose(SegmentLoader, _videojs$EventTarget);
|
20981 |
|
20982 | function SegmentLoader(settings, options) {
|
20983 | var _this;
|
20984 |
|
20985 | _this = _videojs$EventTarget.call(this) || this;
|
20986 |
|
20987 | if (!settings) {
|
20988 | throw new TypeError('Initialization settings are required');
|
20989 | }
|
20990 |
|
20991 | if (typeof settings.currentTime !== 'function') {
|
20992 | throw new TypeError('No currentTime getter specified');
|
20993 | }
|
20994 |
|
20995 | if (!settings.mediaSource) {
|
20996 | throw new TypeError('No MediaSource specified');
|
20997 | }
|
20998 |
|
20999 |
|
21000 | _this.bandwidth = settings.bandwidth;
|
21001 | _this.throughput = {
|
21002 | rate: 0,
|
21003 | count: 0
|
21004 | };
|
21005 | _this.roundTrip = NaN;
|
21006 |
|
21007 | _this.resetStats_();
|
21008 |
|
21009 | _this.mediaIndex = null;
|
21010 | _this.partIndex = null;
|
21011 |
|
21012 | _this.hasPlayed_ = settings.hasPlayed;
|
21013 | _this.currentTime_ = settings.currentTime;
|
21014 | _this.seekable_ = settings.seekable;
|
21015 | _this.seeking_ = settings.seeking;
|
21016 | _this.duration_ = settings.duration;
|
21017 | _this.mediaSource_ = settings.mediaSource;
|
21018 | _this.vhs_ = settings.vhs;
|
21019 | _this.loaderType_ = settings.loaderType;
|
21020 | _this.currentMediaInfo_ = void 0;
|
21021 | _this.startingMediaInfo_ = void 0;
|
21022 | _this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
|
21023 | _this.goalBufferLength_ = settings.goalBufferLength;
|
21024 | _this.sourceType_ = settings.sourceType;
|
21025 | _this.sourceUpdater_ = settings.sourceUpdater;
|
21026 | _this.inbandTextTracks_ = settings.inbandTextTracks;
|
21027 | _this.state_ = 'INIT';
|
21028 | _this.timelineChangeController_ = settings.timelineChangeController;
|
21029 | _this.shouldSaveSegmentTimingInfo_ = true;
|
21030 | _this.parse708captions_ = settings.parse708captions;
|
21031 | _this.captionServices_ = settings.captionServices;
|
21032 | _this.experimentalExactManifestTimings = settings.experimentalExactManifestTimings;
|
21033 |
|
21034 | _this.checkBufferTimeout_ = null;
|
21035 | _this.error_ = void 0;
|
21036 | _this.currentTimeline_ = -1;
|
21037 | _this.pendingSegment_ = null;
|
21038 | _this.xhrOptions_ = null;
|
21039 | _this.pendingSegments_ = [];
|
21040 | _this.audioDisabled_ = false;
|
21041 | _this.isPendingTimestampOffset_ = false;
|
21042 |
|
21043 | _this.gopBuffer_ = [];
|
21044 | _this.timeMapping_ = 0;
|
21045 | _this.safeAppend_ = videojs__default["default"].browser.IE_VERSION >= 11;
|
21046 | _this.appendInitSegment_ = {
|
21047 | audio: true,
|
21048 | video: true
|
21049 | };
|
21050 | _this.playlistOfLastInitSegment_ = {
|
21051 | audio: null,
|
21052 | video: null
|
21053 | };
|
21054 | _this.callQueue_ = [];
|
21055 |
|
21056 |
|
21057 |
|
21058 |
|
21059 |
|
21060 | _this.loadQueue_ = [];
|
21061 | _this.metadataQueue_ = {
|
21062 | id3: [],
|
21063 | caption: []
|
21064 | };
|
21065 | _this.waitingOnRemove_ = false;
|
21066 | _this.quotaExceededErrorRetryTimeout_ = null;
|
21067 |
|
21068 | _this.activeInitSegmentId_ = null;
|
21069 | _this.initSegments_ = {};
|
21070 |
|
21071 | _this.cacheEncryptionKeys_ = settings.cacheEncryptionKeys;
|
21072 | _this.keyCache_ = {};
|
21073 | _this.decrypter_ = settings.decrypter;
|
21074 |
|
21075 |
|
21076 |
|
21077 | _this.syncController_ = settings.syncController;
|
21078 | _this.syncPoint_ = {
|
21079 | segmentIndex: 0,
|
21080 | time: 0
|
21081 | };
|
21082 | _this.transmuxer_ = _this.createTransmuxer_();
|
21083 |
|
21084 | _this.triggerSyncInfoUpdate_ = function () {
|
21085 | return _this.trigger('syncinfoupdate');
|
21086 | };
|
21087 |
|
21088 | _this.syncController_.on('syncinfoupdate', _this.triggerSyncInfoUpdate_);
|
21089 |
|
21090 | _this.mediaSource_.addEventListener('sourceopen', function () {
|
21091 | if (!_this.isEndOfStream_()) {
|
21092 | _this.ended_ = false;
|
21093 | }
|
21094 | });
|
21095 |
|
21096 |
|
21097 | _this.fetchAtBuffer_ = false;
|
21098 | _this.logger_ = logger("SegmentLoader[" + _this.loaderType_ + "]");
|
21099 | Object.defineProperty(assertThisInitialized(_this), 'state', {
|
21100 | get: function get() {
|
21101 | return this.state_;
|
21102 | },
|
21103 | set: function set(newState) {
|
21104 | if (newState !== this.state_) {
|
21105 | this.logger_(this.state_ + " -> " + newState);
|
21106 | this.state_ = newState;
|
21107 | this.trigger('statechange');
|
21108 | }
|
21109 | }
|
21110 | });
|
21111 |
|
21112 | _this.sourceUpdater_.on('ready', function () {
|
21113 | if (_this.hasEnoughInfoToAppend_()) {
|
21114 | _this.processCallQueue_();
|
21115 | }
|
21116 | });
|
21117 |
|
21118 |
|
21119 |
|
21120 |
|
21121 |
|
21122 | if (_this.loaderType_ === 'main') {
|
21123 | _this.timelineChangeController_.on('pendingtimelinechange', function () {
|
21124 | if (_this.hasEnoughInfoToAppend_()) {
|
21125 | _this.processCallQueue_();
|
21126 | }
|
21127 | });
|
21128 | }
|
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 | if (_this.loaderType_ === 'audio') {
|
21134 | _this.timelineChangeController_.on('timelinechange', function () {
|
21135 | if (_this.hasEnoughInfoToLoad_()) {
|
21136 | _this.processLoadQueue_();
|
21137 | }
|
21138 |
|
21139 | if (_this.hasEnoughInfoToAppend_()) {
|
21140 | _this.processCallQueue_();
|
21141 | }
|
21142 | });
|
21143 | }
|
21144 |
|
21145 | return _this;
|
21146 | }
|
21147 |
|
21148 | var _proto = SegmentLoader.prototype;
|
21149 |
|
21150 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
21151 | return segmentTransmuxer.createTransmuxer({
|
21152 | remux: false,
|
21153 | alignGopsAtEnd: this.safeAppend_,
|
21154 | keepOriginalTimestamps: true,
|
21155 | parse708captions: this.parse708captions_,
|
21156 | captionServices: this.captionServices_
|
21157 | });
|
21158 | }
|
21159 | |
21160 |
|
21161 |
|
21162 |
|
21163 |
|
21164 | ;
|
21165 |
|
21166 | _proto.resetStats_ = function resetStats_() {
|
21167 | this.mediaBytesTransferred = 0;
|
21168 | this.mediaRequests = 0;
|
21169 | this.mediaRequestsAborted = 0;
|
21170 | this.mediaRequestsTimedout = 0;
|
21171 | this.mediaRequestsErrored = 0;
|
21172 | this.mediaTransferDuration = 0;
|
21173 | this.mediaSecondsLoaded = 0;
|
21174 | this.mediaAppends = 0;
|
21175 | }
|
21176 | |
21177 |
|
21178 |
|
21179 | ;
|
21180 |
|
21181 | _proto.dispose = function dispose() {
|
21182 | this.trigger('dispose');
|
21183 | this.state = 'DISPOSED';
|
21184 | this.pause();
|
21185 | this.abort_();
|
21186 |
|
21187 | if (this.transmuxer_) {
|
21188 | this.transmuxer_.terminate();
|
21189 | }
|
21190 |
|
21191 | this.resetStats_();
|
21192 |
|
21193 | if (this.checkBufferTimeout_) {
|
21194 | window.clearTimeout(this.checkBufferTimeout_);
|
21195 | }
|
21196 |
|
21197 | if (this.syncController_ && this.triggerSyncInfoUpdate_) {
|
21198 | this.syncController_.off('syncinfoupdate', this.triggerSyncInfoUpdate_);
|
21199 | }
|
21200 |
|
21201 | this.off();
|
21202 | };
|
21203 |
|
21204 | _proto.setAudio = function setAudio(enable) {
|
21205 | this.audioDisabled_ = !enable;
|
21206 |
|
21207 | if (enable) {
|
21208 | this.appendInitSegment_.audio = true;
|
21209 | } else {
|
21210 |
|
21211 | this.sourceUpdater_.removeAudio(0, this.duration_());
|
21212 | }
|
21213 | }
|
21214 | |
21215 |
|
21216 |
|
21217 |
|
21218 | ;
|
21219 |
|
21220 | _proto.abort = function abort() {
|
21221 | if (this.state !== 'WAITING') {
|
21222 | if (this.pendingSegment_) {
|
21223 | this.pendingSegment_ = null;
|
21224 | }
|
21225 |
|
21226 | return;
|
21227 | }
|
21228 |
|
21229 | this.abort_();
|
21230 |
|
21231 |
|
21232 |
|
21233 |
|
21234 | this.state = 'READY';
|
21235 |
|
21236 |
|
21237 | if (!this.paused()) {
|
21238 | this.monitorBuffer_();
|
21239 | }
|
21240 | }
|
21241 | |
21242 |
|
21243 |
|
21244 |
|
21245 |
|
21246 | ;
|
21247 |
|
21248 | _proto.abort_ = function abort_() {
|
21249 | if (this.pendingSegment_ && this.pendingSegment_.abortRequests) {
|
21250 | this.pendingSegment_.abortRequests();
|
21251 | }
|
21252 |
|
21253 |
|
21254 | this.pendingSegment_ = null;
|
21255 | this.callQueue_ = [];
|
21256 | this.loadQueue_ = [];
|
21257 | this.metadataQueue_.id3 = [];
|
21258 | this.metadataQueue_.caption = [];
|
21259 | this.timelineChangeController_.clearPendingTimelineChange(this.loaderType_);
|
21260 | this.waitingOnRemove_ = false;
|
21261 | window.clearTimeout(this.quotaExceededErrorRetryTimeout_);
|
21262 | this.quotaExceededErrorRetryTimeout_ = null;
|
21263 | };
|
21264 |
|
21265 | _proto.checkForAbort_ = function checkForAbort_(requestId) {
|
21266 |
|
21267 |
|
21268 | if (this.state === 'APPENDING' && !this.pendingSegment_) {
|
21269 | this.state = 'READY';
|
21270 | return true;
|
21271 | }
|
21272 |
|
21273 | if (!this.pendingSegment_ || this.pendingSegment_.requestId !== requestId) {
|
21274 | return true;
|
21275 | }
|
21276 |
|
21277 | return false;
|
21278 | }
|
21279 | |
21280 |
|
21281 |
|
21282 |
|
21283 |
|
21284 |
|
21285 | ;
|
21286 |
|
21287 | _proto.error = function error(_error) {
|
21288 | if (typeof _error !== 'undefined') {
|
21289 | this.logger_('error occurred:', _error);
|
21290 | this.error_ = _error;
|
21291 | }
|
21292 |
|
21293 | this.pendingSegment_ = null;
|
21294 | return this.error_;
|
21295 | };
|
21296 |
|
21297 | _proto.endOfStream = function endOfStream() {
|
21298 | this.ended_ = true;
|
21299 |
|
21300 | if (this.transmuxer_) {
|
21301 |
|
21302 | segmentTransmuxer.reset(this.transmuxer_);
|
21303 | }
|
21304 |
|
21305 | this.gopBuffer_.length = 0;
|
21306 | this.pause();
|
21307 | this.trigger('ended');
|
21308 | }
|
21309 | |
21310 |
|
21311 |
|
21312 |
|
21313 |
|
21314 |
|
21315 | ;
|
21316 |
|
21317 | _proto.buffered_ = function buffered_() {
|
21318 | var trackInfo = this.getMediaInfo_();
|
21319 |
|
21320 | if (!this.sourceUpdater_ || !trackInfo) {
|
21321 | return videojs__default["default"].createTimeRanges();
|
21322 | }
|
21323 |
|
21324 | if (this.loaderType_ === 'main') {
|
21325 | var hasAudio = trackInfo.hasAudio,
|
21326 | hasVideo = trackInfo.hasVideo,
|
21327 | isMuxed = trackInfo.isMuxed;
|
21328 |
|
21329 | if (hasVideo && hasAudio && !this.audioDisabled_ && !isMuxed) {
|
21330 | return this.sourceUpdater_.buffered();
|
21331 | }
|
21332 |
|
21333 | if (hasVideo) {
|
21334 | return this.sourceUpdater_.videoBuffered();
|
21335 | }
|
21336 | }
|
21337 |
|
21338 |
|
21339 |
|
21340 | return this.sourceUpdater_.audioBuffered();
|
21341 | }
|
21342 | |
21343 |
|
21344 |
|
21345 |
|
21346 |
|
21347 |
|
21348 |
|
21349 |
|
21350 |
|
21351 |
|
21352 | ;
|
21353 |
|
21354 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
21355 | if (set === void 0) {
|
21356 | set = false;
|
21357 | }
|
21358 |
|
21359 | if (!map) {
|
21360 | return null;
|
21361 | }
|
21362 |
|
21363 | var id = initSegmentId(map);
|
21364 | var storedMap = this.initSegments_[id];
|
21365 |
|
21366 | if (set && !storedMap && map.bytes) {
|
21367 | this.initSegments_[id] = storedMap = {
|
21368 | resolvedUri: map.resolvedUri,
|
21369 | byterange: map.byterange,
|
21370 | bytes: map.bytes,
|
21371 | tracks: map.tracks,
|
21372 | timescales: map.timescales
|
21373 | };
|
21374 | }
|
21375 |
|
21376 | return storedMap || map;
|
21377 | }
|
21378 | |
21379 |
|
21380 |
|
21381 |
|
21382 |
|
21383 |
|
21384 |
|
21385 |
|
21386 |
|
21387 |
|
21388 | ;
|
21389 |
|
21390 | _proto.segmentKey = function segmentKey(key, set) {
|
21391 | if (set === void 0) {
|
21392 | set = false;
|
21393 | }
|
21394 |
|
21395 | if (!key) {
|
21396 | return null;
|
21397 | }
|
21398 |
|
21399 | var id = segmentKeyId(key);
|
21400 | var storedKey = this.keyCache_[id];
|
21401 |
|
21402 |
|
21403 | if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) {
|
21404 | this.keyCache_[id] = storedKey = {
|
21405 | resolvedUri: key.resolvedUri,
|
21406 | bytes: key.bytes
|
21407 | };
|
21408 | }
|
21409 |
|
21410 | var result = {
|
21411 | resolvedUri: (storedKey || key).resolvedUri
|
21412 | };
|
21413 |
|
21414 | if (storedKey) {
|
21415 | result.bytes = storedKey.bytes;
|
21416 | }
|
21417 |
|
21418 | return result;
|
21419 | }
|
21420 | |
21421 |
|
21422 |
|
21423 |
|
21424 |
|
21425 |
|
21426 | ;
|
21427 |
|
21428 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
21429 | return this.playlist_ && !this.paused();
|
21430 | }
|
21431 | |
21432 |
|
21433 |
|
21434 | ;
|
21435 |
|
21436 | _proto.load = function load() {
|
21437 |
|
21438 | this.monitorBuffer_();
|
21439 |
|
21440 |
|
21441 | if (!this.playlist_) {
|
21442 | return;
|
21443 | }
|
21444 |
|
21445 |
|
21446 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
21447 | return this.init_();
|
21448 | }
|
21449 |
|
21450 |
|
21451 |
|
21452 | if (!this.couldBeginLoading_() || this.state !== 'READY' && this.state !== 'INIT') {
|
21453 | return;
|
21454 | }
|
21455 |
|
21456 | this.state = 'READY';
|
21457 | }
|
21458 | |
21459 |
|
21460 |
|
21461 |
|
21462 |
|
21463 |
|
21464 |
|
21465 | ;
|
21466 |
|
21467 | _proto.init_ = function init_() {
|
21468 | this.state = 'READY';
|
21469 |
|
21470 |
|
21471 | this.resetEverything();
|
21472 | return this.monitorBuffer_();
|
21473 | }
|
21474 | |
21475 |
|
21476 |
|
21477 |
|
21478 |
|
21479 | ;
|
21480 |
|
21481 | _proto.playlist = function playlist(newPlaylist, options) {
|
21482 | if (options === void 0) {
|
21483 | options = {};
|
21484 | }
|
21485 |
|
21486 | if (!newPlaylist) {
|
21487 | return;
|
21488 | }
|
21489 |
|
21490 | var oldPlaylist = this.playlist_;
|
21491 | var segmentInfo = this.pendingSegment_;
|
21492 | this.playlist_ = newPlaylist;
|
21493 | this.xhrOptions_ = options;
|
21494 |
|
21495 |
|
21496 |
|
21497 |
|
21498 |
|
21499 |
|
21500 |
|
21501 | if (this.state === 'INIT') {
|
21502 | newPlaylist.syncInfo = {
|
21503 | mediaSequence: newPlaylist.mediaSequence,
|
21504 | time: 0
|
21505 | };
|
21506 |
|
21507 |
|
21508 |
|
21509 |
|
21510 |
|
21511 |
|
21512 |
|
21513 |
|
21514 | if (this.loaderType_ === 'main') {
|
21515 | this.syncController_.setDateTimeMappingForStart(newPlaylist);
|
21516 | }
|
21517 | }
|
21518 |
|
21519 | var oldId = null;
|
21520 |
|
21521 | if (oldPlaylist) {
|
21522 | if (oldPlaylist.id) {
|
21523 | oldId = oldPlaylist.id;
|
21524 | } else if (oldPlaylist.uri) {
|
21525 | oldId = oldPlaylist.uri;
|
21526 | }
|
21527 | }
|
21528 |
|
21529 | this.logger_("playlist update [" + oldId + " => " + (newPlaylist.id || newPlaylist.uri) + "]");
|
21530 |
|
21531 |
|
21532 | this.trigger('syncinfoupdate');
|
21533 |
|
21534 |
|
21535 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
21536 | return this.init_();
|
21537 | }
|
21538 |
|
21539 | if (!oldPlaylist || oldPlaylist.uri !== newPlaylist.uri) {
|
21540 | if (this.mediaIndex !== null) {
|
21541 |
|
21542 |
|
21543 | this.resyncLoader();
|
21544 | }
|
21545 |
|
21546 | this.currentMediaInfo_ = void 0;
|
21547 | this.trigger('playlistupdate');
|
21548 |
|
21549 | return;
|
21550 | }
|
21551 |
|
21552 |
|
21553 |
|
21554 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
21555 | this.logger_("live window shift [" + mediaSequenceDiff + "]");
|
21556 |
|
21557 |
|
21558 |
|
21559 | if (this.mediaIndex !== null) {
|
21560 | this.mediaIndex -= mediaSequenceDiff;
|
21561 |
|
21562 |
|
21563 |
|
21564 | if (this.mediaIndex < 0) {
|
21565 | this.mediaIndex = null;
|
21566 | this.partIndex = null;
|
21567 | } else {
|
21568 | var segment = this.playlist_.segments[this.mediaIndex];
|
21569 |
|
21570 |
|
21571 |
|
21572 | if (this.partIndex && (!segment.parts || !segment.parts.length || !segment.parts[this.partIndex])) {
|
21573 | var mediaIndex = this.mediaIndex;
|
21574 | this.logger_("currently processing part (index " + this.partIndex + ") no longer exists.");
|
21575 | this.resetLoader();
|
21576 |
|
21577 |
|
21578 |
|
21579 | this.mediaIndex = mediaIndex;
|
21580 | }
|
21581 | }
|
21582 | }
|
21583 |
|
21584 |
|
21585 |
|
21586 |
|
21587 | if (segmentInfo) {
|
21588 | segmentInfo.mediaIndex -= mediaSequenceDiff;
|
21589 |
|
21590 | if (segmentInfo.mediaIndex < 0) {
|
21591 | segmentInfo.mediaIndex = null;
|
21592 | segmentInfo.partIndex = null;
|
21593 | } else {
|
21594 |
|
21595 |
|
21596 |
|
21597 | if (segmentInfo.mediaIndex >= 0) {
|
21598 | segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex];
|
21599 | }
|
21600 |
|
21601 | if (segmentInfo.partIndex >= 0 && segmentInfo.segment.parts) {
|
21602 | segmentInfo.part = segmentInfo.segment.parts[segmentInfo.partIndex];
|
21603 | }
|
21604 | }
|
21605 | }
|
21606 |
|
21607 | this.syncController_.saveExpiredSegmentInfo(oldPlaylist, newPlaylist);
|
21608 | }
|
21609 | |
21610 |
|
21611 |
|
21612 |
|
21613 |
|
21614 |
|
21615 | ;
|
21616 |
|
21617 | _proto.pause = function pause() {
|
21618 | if (this.checkBufferTimeout_) {
|
21619 | window.clearTimeout(this.checkBufferTimeout_);
|
21620 | this.checkBufferTimeout_ = null;
|
21621 | }
|
21622 | }
|
21623 | |
21624 |
|
21625 |
|
21626 |
|
21627 |
|
21628 | ;
|
21629 |
|
21630 | _proto.paused = function paused() {
|
21631 | return this.checkBufferTimeout_ === null;
|
21632 | }
|
21633 | |
21634 |
|
21635 |
|
21636 |
|
21637 |
|
21638 |
|
21639 | ;
|
21640 |
|
21641 | _proto.resetEverything = function resetEverything(done) {
|
21642 | this.ended_ = false;
|
21643 | this.appendInitSegment_ = {
|
21644 | audio: true,
|
21645 | video: true
|
21646 | };
|
21647 | this.resetLoader();
|
21648 |
|
21649 |
|
21650 |
|
21651 | this.remove(0, Infinity, done);
|
21652 |
|
21653 | if (this.transmuxer_) {
|
21654 | this.transmuxer_.postMessage({
|
21655 | action: 'clearAllMp4Captions'
|
21656 | });
|
21657 |
|
21658 | this.transmuxer_.postMessage({
|
21659 | action: 'reset'
|
21660 | });
|
21661 | }
|
21662 | }
|
21663 | |
21664 |
|
21665 |
|
21666 |
|
21667 |
|
21668 |
|
21669 | ;
|
21670 |
|
21671 | _proto.resetLoader = function resetLoader() {
|
21672 | this.fetchAtBuffer_ = false;
|
21673 | this.resyncLoader();
|
21674 | }
|
21675 | |
21676 |
|
21677 |
|
21678 |
|
21679 | ;
|
21680 |
|
21681 | _proto.resyncLoader = function resyncLoader() {
|
21682 | if (this.transmuxer_) {
|
21683 |
|
21684 | segmentTransmuxer.reset(this.transmuxer_);
|
21685 | }
|
21686 |
|
21687 | this.mediaIndex = null;
|
21688 | this.partIndex = null;
|
21689 | this.syncPoint_ = null;
|
21690 | this.isPendingTimestampOffset_ = false;
|
21691 | this.callQueue_ = [];
|
21692 | this.loadQueue_ = [];
|
21693 | this.metadataQueue_.id3 = [];
|
21694 | this.metadataQueue_.caption = [];
|
21695 | this.abort();
|
21696 |
|
21697 | if (this.transmuxer_) {
|
21698 | this.transmuxer_.postMessage({
|
21699 | action: 'clearParsedMp4Captions'
|
21700 | });
|
21701 | }
|
21702 | }
|
21703 | |
21704 |
|
21705 |
|
21706 |
|
21707 |
|
21708 |
|
21709 |
|
21710 |
|
21711 |
|
21712 | ;
|
21713 |
|
21714 | _proto.remove = function remove(start, end, done, force) {
|
21715 | if (done === void 0) {
|
21716 | done = function done() {};
|
21717 | }
|
21718 |
|
21719 | if (force === void 0) {
|
21720 | force = false;
|
21721 | }
|
21722 |
|
21723 |
|
21724 |
|
21725 |
|
21726 | if (end === Infinity) {
|
21727 | end = this.duration_();
|
21728 | }
|
21729 |
|
21730 |
|
21731 |
|
21732 |
|
21733 | if (end <= start) {
|
21734 | this.logger_('skipping remove because end ${end} is <= start ${start}');
|
21735 | return;
|
21736 | }
|
21737 |
|
21738 | if (!this.sourceUpdater_ || !this.getMediaInfo_()) {
|
21739 | this.logger_('skipping remove because no source updater or starting media info');
|
21740 |
|
21741 | return;
|
21742 | }
|
21743 |
|
21744 |
|
21745 | var removesRemaining = 1;
|
21746 |
|
21747 | var removeFinished = function removeFinished() {
|
21748 | removesRemaining--;
|
21749 |
|
21750 | if (removesRemaining === 0) {
|
21751 | done();
|
21752 | }
|
21753 | };
|
21754 |
|
21755 | if (force || !this.audioDisabled_) {
|
21756 | removesRemaining++;
|
21757 | this.sourceUpdater_.removeAudio(start, end, removeFinished);
|
21758 | }
|
21759 |
|
21760 |
|
21761 |
|
21762 |
|
21763 |
|
21764 |
|
21765 |
|
21766 |
|
21767 |
|
21768 | if (force || this.loaderType_ === 'main') {
|
21769 | this.gopBuffer_ = removeGopBuffer(this.gopBuffer_, start, end, this.timeMapping_);
|
21770 | removesRemaining++;
|
21771 | this.sourceUpdater_.removeVideo(start, end, removeFinished);
|
21772 | }
|
21773 |
|
21774 |
|
21775 | for (var track in this.inbandTextTracks_) {
|
21776 | removeCuesFromTrack(start, end, this.inbandTextTracks_[track]);
|
21777 | }
|
21778 |
|
21779 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
21780 |
|
21781 | removeFinished();
|
21782 | }
|
21783 | |
21784 |
|
21785 |
|
21786 |
|
21787 |
|
21788 | ;
|
21789 |
|
21790 | _proto.monitorBuffer_ = function monitorBuffer_() {
|
21791 | if (this.checkBufferTimeout_) {
|
21792 | window.clearTimeout(this.checkBufferTimeout_);
|
21793 | }
|
21794 |
|
21795 | this.checkBufferTimeout_ = window.setTimeout(this.monitorBufferTick_.bind(this), 1);
|
21796 | }
|
21797 | |
21798 |
|
21799 |
|
21800 |
|
21801 |
|
21802 |
|
21803 | ;
|
21804 |
|
21805 | _proto.monitorBufferTick_ = function monitorBufferTick_() {
|
21806 | if (this.state === 'READY') {
|
21807 | this.fillBuffer_();
|
21808 | }
|
21809 |
|
21810 | if (this.checkBufferTimeout_) {
|
21811 | window.clearTimeout(this.checkBufferTimeout_);
|
21812 | }
|
21813 |
|
21814 | this.checkBufferTimeout_ = window.setTimeout(this.monitorBufferTick_.bind(this), CHECK_BUFFER_DELAY);
|
21815 | }
|
21816 | |
21817 |
|
21818 |
|
21819 |
|
21820 |
|
21821 |
|
21822 |
|
21823 |
|
21824 |
|
21825 | ;
|
21826 |
|
21827 | _proto.fillBuffer_ = function fillBuffer_() {
|
21828 |
|
21829 |
|
21830 | if (this.sourceUpdater_.updating()) {
|
21831 | return;
|
21832 | }
|
21833 |
|
21834 |
|
21835 | var segmentInfo = this.chooseNextRequest_();
|
21836 |
|
21837 | if (!segmentInfo) {
|
21838 | return;
|
21839 | }
|
21840 |
|
21841 | if (typeof segmentInfo.timestampOffset === 'number') {
|
21842 | this.isPendingTimestampOffset_ = false;
|
21843 | this.timelineChangeController_.pendingTimelineChange({
|
21844 | type: this.loaderType_,
|
21845 | from: this.currentTimeline_,
|
21846 | to: segmentInfo.timeline
|
21847 | });
|
21848 | }
|
21849 |
|
21850 | this.loadSegment_(segmentInfo);
|
21851 | }
|
21852 | |
21853 |
|
21854 |
|
21855 |
|
21856 |
|
21857 |
|
21858 |
|
21859 |
|
21860 |
|
21861 | ;
|
21862 |
|
21863 | _proto.isEndOfStream_ = function isEndOfStream_(mediaIndex, playlist, partIndex) {
|
21864 | if (mediaIndex === void 0) {
|
21865 | mediaIndex = this.mediaIndex;
|
21866 | }
|
21867 |
|
21868 | if (playlist === void 0) {
|
21869 | playlist = this.playlist_;
|
21870 | }
|
21871 |
|
21872 | if (partIndex === void 0) {
|
21873 | partIndex = this.partIndex;
|
21874 | }
|
21875 |
|
21876 | if (!playlist || !this.mediaSource_) {
|
21877 | return false;
|
21878 | }
|
21879 |
|
21880 | var segment = typeof mediaIndex === 'number' && playlist.segments[mediaIndex];
|
21881 |
|
21882 | var appendedLastSegment = mediaIndex + 1 === playlist.segments.length;
|
21883 |
|
21884 | var appendedLastPart = !segment || !segment.parts || partIndex + 1 === segment.parts.length;
|
21885 |
|
21886 |
|
21887 |
|
21888 | return playlist.endList && this.mediaSource_.readyState === 'open' && appendedLastSegment && appendedLastPart;
|
21889 | }
|
21890 | |
21891 |
|
21892 |
|
21893 |
|
21894 |
|
21895 | ;
|
21896 |
|
21897 | _proto.chooseNextRequest_ = function chooseNextRequest_() {
|
21898 | var bufferedEnd = lastBufferedEnd(this.buffered_()) || 0;
|
21899 | var bufferedTime = Math.max(0, bufferedEnd - this.currentTime_());
|
21900 | var preloaded = !this.hasPlayed_() && bufferedTime >= 1;
|
21901 | var haveEnoughBuffer = bufferedTime >= this.goalBufferLength_();
|
21902 | var segments = this.playlist_.segments;
|
21903 |
|
21904 |
|
21905 |
|
21906 |
|
21907 | if (!segments.length || preloaded || haveEnoughBuffer) {
|
21908 | return null;
|
21909 | }
|
21910 |
|
21911 | this.syncPoint_ = this.syncPoint_ || this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
21912 | var next = {
|
21913 | partIndex: null,
|
21914 | mediaIndex: null,
|
21915 | startOfSegment: null,
|
21916 | playlist: this.playlist_,
|
21917 | isSyncRequest: Boolean(!this.syncPoint_)
|
21918 | };
|
21919 |
|
21920 | if (next.isSyncRequest) {
|
21921 | next.mediaIndex = getSyncSegmentCandidate(this.currentTimeline_, segments, bufferedEnd);
|
21922 | } else if (this.mediaIndex !== null) {
|
21923 | var segment = segments[this.mediaIndex];
|
21924 | var partIndex = typeof this.partIndex === 'number' ? this.partIndex : -1;
|
21925 | next.startOfSegment = segment.end ? segment.end : bufferedEnd;
|
21926 |
|
21927 | if (segment.parts && segment.parts[partIndex + 1]) {
|
21928 | next.mediaIndex = this.mediaIndex;
|
21929 | next.partIndex = partIndex + 1;
|
21930 | } else {
|
21931 | next.mediaIndex = this.mediaIndex + 1;
|
21932 | }
|
21933 | } else {
|
21934 |
|
21935 | var _Playlist$getMediaInf = Playlist.getMediaInfoForTime({
|
21936 | experimentalExactManifestTimings: this.experimentalExactManifestTimings,
|
21937 | playlist: this.playlist_,
|
21938 | currentTime: this.fetchAtBuffer_ ? bufferedEnd : this.currentTime_(),
|
21939 | startingPartIndex: this.syncPoint_.partIndex,
|
21940 | startingSegmentIndex: this.syncPoint_.segmentIndex,
|
21941 | startTime: this.syncPoint_.time
|
21942 | }),
|
21943 | segmentIndex = _Playlist$getMediaInf.segmentIndex,
|
21944 | startTime = _Playlist$getMediaInf.startTime,
|
21945 | _partIndex = _Playlist$getMediaInf.partIndex;
|
21946 |
|
21947 | next.getMediaInfoForTime = this.fetchAtBuffer_ ? 'bufferedEnd' : 'currentTime';
|
21948 | next.mediaIndex = segmentIndex;
|
21949 | next.startOfSegment = startTime;
|
21950 | next.partIndex = _partIndex;
|
21951 | }
|
21952 |
|
21953 | var nextSegment = segments[next.mediaIndex];
|
21954 | var nextPart = nextSegment && typeof next.partIndex === 'number' && nextSegment.parts && nextSegment.parts[next.partIndex];
|
21955 |
|
21956 |
|
21957 | if (!nextSegment || typeof next.partIndex === 'number' && !nextPart) {
|
21958 | return null;
|
21959 | }
|
21960 |
|
21961 |
|
21962 |
|
21963 | if (typeof next.partIndex !== 'number' && nextSegment.parts) {
|
21964 | next.partIndex = 0;
|
21965 | }
|
21966 |
|
21967 | var ended = this.mediaSource_ && this.mediaSource_.readyState === 'ended';
|
21968 |
|
21969 |
|
21970 |
|
21971 |
|
21972 | if (next.mediaIndex >= segments.length - 1 && ended && !this.seeking_()) {
|
21973 | return null;
|
21974 | }
|
21975 |
|
21976 | return this.generateSegmentInfo_(next);
|
21977 | };
|
21978 |
|
21979 | _proto.generateSegmentInfo_ = function generateSegmentInfo_(options) {
|
21980 | var playlist = options.playlist,
|
21981 | mediaIndex = options.mediaIndex,
|
21982 | startOfSegment = options.startOfSegment,
|
21983 | isSyncRequest = options.isSyncRequest,
|
21984 | partIndex = options.partIndex,
|
21985 | forceTimestampOffset = options.forceTimestampOffset,
|
21986 | getMediaInfoForTime = options.getMediaInfoForTime;
|
21987 | var segment = playlist.segments[mediaIndex];
|
21988 | var part = typeof partIndex === 'number' && segment.parts[partIndex];
|
21989 | var segmentInfo = {
|
21990 | requestId: 'segment-loader-' + Math.random(),
|
21991 |
|
21992 | uri: part && part.resolvedUri || segment.resolvedUri,
|
21993 |
|
21994 | mediaIndex: mediaIndex,
|
21995 | partIndex: part ? partIndex : null,
|
21996 |
|
21997 |
|
21998 | isSyncRequest: isSyncRequest,
|
21999 | startOfSegment: startOfSegment,
|
22000 |
|
22001 | playlist: playlist,
|
22002 |
|
22003 | bytes: null,
|
22004 |
|
22005 | encryptedBytes: null,
|
22006 |
|
22007 |
|
22008 | timestampOffset: null,
|
22009 |
|
22010 | timeline: segment.timeline,
|
22011 |
|
22012 | duration: part && part.duration || segment.duration,
|
22013 |
|
22014 | segment: segment,
|
22015 | part: part,
|
22016 | byteLength: 0,
|
22017 | transmuxer: this.transmuxer_,
|
22018 |
|
22019 | getMediaInfoForTime: getMediaInfoForTime
|
22020 | };
|
22021 | var overrideCheck = typeof forceTimestampOffset !== 'undefined' ? forceTimestampOffset : this.isPendingTimestampOffset_;
|
22022 | segmentInfo.timestampOffset = this.timestampOffsetForSegment_({
|
22023 | segmentTimeline: segment.timeline,
|
22024 | currentTimeline: this.currentTimeline_,
|
22025 | startOfSegment: startOfSegment,
|
22026 | buffered: this.buffered_(),
|
22027 | overrideCheck: overrideCheck
|
22028 | });
|
22029 | var audioBufferedEnd = lastBufferedEnd(this.sourceUpdater_.audioBuffered());
|
22030 |
|
22031 | if (typeof audioBufferedEnd === 'number') {
|
22032 |
|
22033 |
|
22034 | segmentInfo.audioAppendStart = audioBufferedEnd - this.sourceUpdater_.audioTimestampOffset();
|
22035 | }
|
22036 |
|
22037 | if (this.sourceUpdater_.videoBuffered().length) {
|
22038 | segmentInfo.gopsToAlignWith = gopsSafeToAlignWith(this.gopBuffer_,
|
22039 |
|
22040 | this.currentTime_() - this.sourceUpdater_.videoTimestampOffset(), this.timeMapping_);
|
22041 | }
|
22042 |
|
22043 | return segmentInfo;
|
22044 | }
|
22045 |
|
22046 |
|
22047 | ;
|
22048 |
|
22049 | _proto.timestampOffsetForSegment_ = function timestampOffsetForSegment_(options) {
|
22050 | return timestampOffsetForSegment(options);
|
22051 | }
|
22052 | |
22053 |
|
22054 |
|
22055 |
|
22056 |
|
22057 |
|
22058 |
|
22059 |
|
22060 |
|
22061 | ;
|
22062 |
|
22063 | _proto.earlyAbortWhenNeeded_ = function earlyAbortWhenNeeded_(stats) {
|
22064 | if (this.vhs_.tech_.paused() ||
|
22065 |
|
22066 |
|
22067 | !this.xhrOptions_.timeout ||
|
22068 | !this.playlist_.attributes.BANDWIDTH) {
|
22069 | return;
|
22070 | }
|
22071 |
|
22072 |
|
22073 |
|
22074 |
|
22075 | if (Date.now() - (stats.firstBytesReceivedAt || Date.now()) < 1000) {
|
22076 | return;
|
22077 | }
|
22078 |
|
22079 | var currentTime = this.currentTime_();
|
22080 | var measuredBandwidth = stats.bandwidth;
|
22081 | var segmentDuration = this.pendingSegment_.duration;
|
22082 | var requestTimeRemaining = Playlist.estimateSegmentRequestTime(segmentDuration, measuredBandwidth, this.playlist_, stats.bytesReceived);
|
22083 |
|
22084 |
|
22085 |
|
22086 | var timeUntilRebuffer$1 = timeUntilRebuffer(this.buffered_(), currentTime, this.vhs_.tech_.playbackRate()) - 1;
|
22087 |
|
22088 |
|
22089 | if (requestTimeRemaining <= timeUntilRebuffer$1) {
|
22090 | return;
|
22091 | }
|
22092 |
|
22093 | var switchCandidate = minRebufferMaxBandwidthSelector({
|
22094 | master: this.vhs_.playlists.master,
|
22095 | currentTime: currentTime,
|
22096 | bandwidth: measuredBandwidth,
|
22097 | duration: this.duration_(),
|
22098 | segmentDuration: segmentDuration,
|
22099 | timeUntilRebuffer: timeUntilRebuffer$1,
|
22100 | currentTimeline: this.currentTimeline_,
|
22101 | syncController: this.syncController_
|
22102 | });
|
22103 |
|
22104 | if (!switchCandidate) {
|
22105 | return;
|
22106 | }
|
22107 |
|
22108 | var rebufferingImpact = requestTimeRemaining - timeUntilRebuffer$1;
|
22109 | var timeSavedBySwitching = rebufferingImpact - switchCandidate.rebufferingImpact;
|
22110 | var minimumTimeSaving = 0.5;
|
22111 |
|
22112 |
|
22113 |
|
22114 | if (timeUntilRebuffer$1 <= TIME_FUDGE_FACTOR) {
|
22115 | minimumTimeSaving = 1;
|
22116 | }
|
22117 |
|
22118 | if (!switchCandidate.playlist || switchCandidate.playlist.uri === this.playlist_.uri || timeSavedBySwitching < minimumTimeSaving) {
|
22119 | return;
|
22120 | }
|
22121 |
|
22122 |
|
22123 |
|
22124 |
|
22125 | this.bandwidth = switchCandidate.playlist.attributes.BANDWIDTH * Config.BANDWIDTH_VARIANCE + 1;
|
22126 | this.trigger('earlyabort');
|
22127 | };
|
22128 |
|
22129 | _proto.handleAbort_ = function handleAbort_(segmentInfo) {
|
22130 | this.logger_("Aborting " + segmentInfoString(segmentInfo));
|
22131 | this.mediaRequestsAborted += 1;
|
22132 | }
|
22133 | |
22134 |
|
22135 |
|
22136 |
|
22137 |
|
22138 |
|
22139 |
|
22140 |
|
22141 |
|
22142 | ;
|
22143 |
|
22144 | _proto.handleProgress_ = function handleProgress_(event, simpleSegment) {
|
22145 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
22146 |
|
22147 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22148 | return;
|
22149 | }
|
22150 |
|
22151 | this.trigger('progress');
|
22152 | };
|
22153 |
|
22154 | _proto.handleTrackInfo_ = function handleTrackInfo_(simpleSegment, trackInfo) {
|
22155 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
22156 |
|
22157 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22158 | return;
|
22159 | }
|
22160 |
|
22161 | if (this.checkForIllegalMediaSwitch(trackInfo)) {
|
22162 | return;
|
22163 | }
|
22164 |
|
22165 | trackInfo = trackInfo || {};
|
22166 |
|
22167 |
|
22168 |
|
22169 | if (!shallowEqual(this.currentMediaInfo_, trackInfo)) {
|
22170 | this.appendInitSegment_ = {
|
22171 | audio: true,
|
22172 | video: true
|
22173 | };
|
22174 | this.startingMediaInfo_ = trackInfo;
|
22175 | this.currentMediaInfo_ = trackInfo;
|
22176 | this.logger_('trackinfo update', trackInfo);
|
22177 | this.trigger('trackinfo');
|
22178 | }
|
22179 |
|
22180 |
|
22181 |
|
22182 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22183 | return;
|
22184 | }
|
22185 |
|
22186 |
|
22187 |
|
22188 | this.pendingSegment_.trackInfo = trackInfo;
|
22189 |
|
22190 | if (this.hasEnoughInfoToAppend_()) {
|
22191 | this.processCallQueue_();
|
22192 | }
|
22193 | };
|
22194 |
|
22195 | _proto.handleTimingInfo_ = function handleTimingInfo_(simpleSegment, mediaType, timeType, time) {
|
22196 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
22197 |
|
22198 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22199 | return;
|
22200 | }
|
22201 |
|
22202 | var segmentInfo = this.pendingSegment_;
|
22203 | var timingInfoProperty = timingInfoPropertyForMedia(mediaType);
|
22204 | segmentInfo[timingInfoProperty] = segmentInfo[timingInfoProperty] || {};
|
22205 | segmentInfo[timingInfoProperty][timeType] = time;
|
22206 | this.logger_("timinginfo: " + mediaType + " - " + timeType + " - " + time);
|
22207 |
|
22208 | if (this.hasEnoughInfoToAppend_()) {
|
22209 | this.processCallQueue_();
|
22210 | }
|
22211 | };
|
22212 |
|
22213 | _proto.handleCaptions_ = function handleCaptions_(simpleSegment, captionData) {
|
22214 | var _this2 = this;
|
22215 |
|
22216 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
22217 |
|
22218 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22219 | return;
|
22220 | }
|
22221 |
|
22222 |
|
22223 |
|
22224 | if (captionData.length === 0) {
|
22225 | this.logger_('SegmentLoader received no captions from a caption event');
|
22226 | return;
|
22227 | }
|
22228 |
|
22229 | var segmentInfo = this.pendingSegment_;
|
22230 |
|
22231 |
|
22232 | if (!segmentInfo.hasAppendedData_) {
|
22233 | this.metadataQueue_.caption.push(this.handleCaptions_.bind(this, simpleSegment, captionData));
|
22234 | return;
|
22235 | }
|
22236 |
|
22237 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
22238 | var captionTracks = {};
|
22239 |
|
22240 | captionData.forEach(function (caption) {
|
22241 |
|
22242 |
|
22243 | captionTracks[caption.stream] = captionTracks[caption.stream] || {
|
22244 |
|
22245 | startTime: Infinity,
|
22246 | captions: [],
|
22247 |
|
22248 | endTime: 0
|
22249 | };
|
22250 | var captionTrack = captionTracks[caption.stream];
|
22251 | captionTrack.startTime = Math.min(captionTrack.startTime, caption.startTime + timestampOffset);
|
22252 | captionTrack.endTime = Math.max(captionTrack.endTime, caption.endTime + timestampOffset);
|
22253 | captionTrack.captions.push(caption);
|
22254 | });
|
22255 | Object.keys(captionTracks).forEach(function (trackName) {
|
22256 | var _captionTracks$trackN = captionTracks[trackName],
|
22257 | startTime = _captionTracks$trackN.startTime,
|
22258 | endTime = _captionTracks$trackN.endTime,
|
22259 | captions = _captionTracks$trackN.captions;
|
22260 | var inbandTextTracks = _this2.inbandTextTracks_;
|
22261 |
|
22262 | _this2.logger_("adding cues from " + startTime + " -> " + endTime + " for " + trackName);
|
22263 |
|
22264 | createCaptionsTrackIfNotExists(inbandTextTracks, _this2.vhs_.tech_, trackName);
|
22265 |
|
22266 |
|
22267 |
|
22268 |
|
22269 | removeCuesFromTrack(startTime, endTime, inbandTextTracks[trackName]);
|
22270 | addCaptionData({
|
22271 | captionArray: captions,
|
22272 | inbandTextTracks: inbandTextTracks,
|
22273 | timestampOffset: timestampOffset
|
22274 | });
|
22275 | });
|
22276 |
|
22277 |
|
22278 | if (this.transmuxer_) {
|
22279 | this.transmuxer_.postMessage({
|
22280 | action: 'clearParsedMp4Captions'
|
22281 | });
|
22282 | }
|
22283 | };
|
22284 |
|
22285 | _proto.handleId3_ = function handleId3_(simpleSegment, id3Frames, dispatchType) {
|
22286 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
22287 |
|
22288 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22289 | return;
|
22290 | }
|
22291 |
|
22292 | var segmentInfo = this.pendingSegment_;
|
22293 |
|
22294 | if (!segmentInfo.hasAppendedData_) {
|
22295 | this.metadataQueue_.id3.push(this.handleId3_.bind(this, simpleSegment, id3Frames, dispatchType));
|
22296 | return;
|
22297 | }
|
22298 |
|
22299 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
22300 |
|
22301 |
|
22302 |
|
22303 | createMetadataTrackIfNotExists(this.inbandTextTracks_, dispatchType, this.vhs_.tech_);
|
22304 | addMetadata({
|
22305 | inbandTextTracks: this.inbandTextTracks_,
|
22306 | metadataArray: id3Frames,
|
22307 | timestampOffset: timestampOffset,
|
22308 | videoDuration: this.duration_()
|
22309 | });
|
22310 | };
|
22311 |
|
22312 | _proto.processMetadataQueue_ = function processMetadataQueue_() {
|
22313 | this.metadataQueue_.id3.forEach(function (fn) {
|
22314 | return fn();
|
22315 | });
|
22316 | this.metadataQueue_.caption.forEach(function (fn) {
|
22317 | return fn();
|
22318 | });
|
22319 | this.metadataQueue_.id3 = [];
|
22320 | this.metadataQueue_.caption = [];
|
22321 | };
|
22322 |
|
22323 | _proto.processCallQueue_ = function processCallQueue_() {
|
22324 | var callQueue = this.callQueue_;
|
22325 |
|
22326 |
|
22327 |
|
22328 | this.callQueue_ = [];
|
22329 | callQueue.forEach(function (fun) {
|
22330 | return fun();
|
22331 | });
|
22332 | };
|
22333 |
|
22334 | _proto.processLoadQueue_ = function processLoadQueue_() {
|
22335 | var loadQueue = this.loadQueue_;
|
22336 |
|
22337 |
|
22338 |
|
22339 | this.loadQueue_ = [];
|
22340 | loadQueue.forEach(function (fun) {
|
22341 | return fun();
|
22342 | });
|
22343 | }
|
22344 | |
22345 |
|
22346 |
|
22347 |
|
22348 |
|
22349 |
|
22350 | ;
|
22351 |
|
22352 | _proto.hasEnoughInfoToLoad_ = function hasEnoughInfoToLoad_() {
|
22353 |
|
22354 |
|
22355 | if (this.loaderType_ !== 'audio') {
|
22356 | return true;
|
22357 | }
|
22358 |
|
22359 | var segmentInfo = this.pendingSegment_;
|
22360 |
|
22361 |
|
22362 | if (!segmentInfo) {
|
22363 | return false;
|
22364 | }
|
22365 |
|
22366 |
|
22367 |
|
22368 |
|
22369 |
|
22370 | if (!this.getCurrentMediaInfo_()) {
|
22371 | return true;
|
22372 | }
|
22373 |
|
22374 | if (
|
22375 |
|
22376 |
|
22377 |
|
22378 |
|
22379 |
|
22380 |
|
22381 |
|
22382 |
|
22383 |
|
22384 |
|
22385 |
|
22386 |
|
22387 |
|
22388 |
|
22389 | shouldWaitForTimelineChange({
|
22390 | timelineChangeController: this.timelineChangeController_,
|
22391 | currentTimeline: this.currentTimeline_,
|
22392 | segmentTimeline: segmentInfo.timeline,
|
22393 | loaderType: this.loaderType_,
|
22394 | audioDisabled: this.audioDisabled_
|
22395 | })) {
|
22396 | return false;
|
22397 | }
|
22398 |
|
22399 | return true;
|
22400 | };
|
22401 |
|
22402 | _proto.getCurrentMediaInfo_ = function getCurrentMediaInfo_(segmentInfo) {
|
22403 | if (segmentInfo === void 0) {
|
22404 | segmentInfo = this.pendingSegment_;
|
22405 | }
|
22406 |
|
22407 | return segmentInfo && segmentInfo.trackInfo || this.currentMediaInfo_;
|
22408 | };
|
22409 |
|
22410 | _proto.getMediaInfo_ = function getMediaInfo_(segmentInfo) {
|
22411 | if (segmentInfo === void 0) {
|
22412 | segmentInfo = this.pendingSegment_;
|
22413 | }
|
22414 |
|
22415 | return this.getCurrentMediaInfo_(segmentInfo) || this.startingMediaInfo_;
|
22416 | };
|
22417 |
|
22418 | _proto.hasEnoughInfoToAppend_ = function hasEnoughInfoToAppend_() {
|
22419 | if (!this.sourceUpdater_.ready()) {
|
22420 | return false;
|
22421 | }
|
22422 |
|
22423 |
|
22424 |
|
22425 | if (this.waitingOnRemove_ || this.quotaExceededErrorRetryTimeout_) {
|
22426 | return false;
|
22427 | }
|
22428 |
|
22429 | var segmentInfo = this.pendingSegment_;
|
22430 | var trackInfo = this.getCurrentMediaInfo_();
|
22431 |
|
22432 |
|
22433 |
|
22434 | if (!segmentInfo || !trackInfo) {
|
22435 | return false;
|
22436 | }
|
22437 |
|
22438 | var hasAudio = trackInfo.hasAudio,
|
22439 | hasVideo = trackInfo.hasVideo,
|
22440 | isMuxed = trackInfo.isMuxed;
|
22441 |
|
22442 | if (hasVideo && !segmentInfo.videoTimingInfo) {
|
22443 | return false;
|
22444 | }
|
22445 |
|
22446 |
|
22447 | if (hasAudio && !this.audioDisabled_ && !isMuxed && !segmentInfo.audioTimingInfo) {
|
22448 | return false;
|
22449 | }
|
22450 |
|
22451 | if (shouldWaitForTimelineChange({
|
22452 | timelineChangeController: this.timelineChangeController_,
|
22453 | currentTimeline: this.currentTimeline_,
|
22454 | segmentTimeline: segmentInfo.timeline,
|
22455 | loaderType: this.loaderType_,
|
22456 | audioDisabled: this.audioDisabled_
|
22457 | })) {
|
22458 | return false;
|
22459 | }
|
22460 |
|
22461 | return true;
|
22462 | };
|
22463 |
|
22464 | _proto.handleData_ = function handleData_(simpleSegment, result) {
|
22465 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
22466 |
|
22467 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
22468 | return;
|
22469 | }
|
22470 |
|
22471 |
|
22472 |
|
22473 | if (this.callQueue_.length || !this.hasEnoughInfoToAppend_()) {
|
22474 | this.callQueue_.push(this.handleData_.bind(this, simpleSegment, result));
|
22475 | return;
|
22476 | }
|
22477 |
|
22478 | var segmentInfo = this.pendingSegment_;
|
22479 |
|
22480 | this.setTimeMapping_(segmentInfo.timeline);
|
22481 |
|
22482 | this.updateMediaSecondsLoaded_(segmentInfo.segment);
|
22483 |
|
22484 |
|
22485 |
|
22486 |
|
22487 |
|
22488 | if (this.mediaSource_.readyState === 'closed') {
|
22489 | return;
|
22490 | }
|
22491 |
|
22492 |
|
22493 |
|
22494 | if (simpleSegment.map) {
|
22495 | simpleSegment.map = this.initSegmentForMap(simpleSegment.map, true);
|
22496 |
|
22497 | segmentInfo.segment.map = simpleSegment.map;
|
22498 | }
|
22499 |
|
22500 |
|
22501 | if (simpleSegment.key) {
|
22502 | this.segmentKey(simpleSegment.key, true);
|
22503 | }
|
22504 |
|
22505 | segmentInfo.isFmp4 = simpleSegment.isFmp4;
|
22506 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
22507 |
|
22508 | if (segmentInfo.isFmp4) {
|
22509 | this.trigger('fmp4');
|
22510 | segmentInfo.timingInfo.start = segmentInfo[timingInfoPropertyForMedia(result.type)].start;
|
22511 | } else {
|
22512 | var trackInfo = this.getCurrentMediaInfo_();
|
22513 | var useVideoTimingInfo = this.loaderType_ === 'main' && trackInfo && trackInfo.hasVideo;
|
22514 | var firstVideoFrameTimeForData;
|
22515 |
|
22516 | if (useVideoTimingInfo) {
|
22517 | firstVideoFrameTimeForData = segmentInfo.videoTimingInfo.start;
|
22518 | }
|
22519 |
|
22520 |
|
22521 |
|
22522 |
|
22523 | segmentInfo.timingInfo.start = this.trueSegmentStart_({
|
22524 | currentStart: segmentInfo.timingInfo.start,
|
22525 | playlist: segmentInfo.playlist,
|
22526 | mediaIndex: segmentInfo.mediaIndex,
|
22527 | currentVideoTimestampOffset: this.sourceUpdater_.videoTimestampOffset(),
|
22528 | useVideoTimingInfo: useVideoTimingInfo,
|
22529 | firstVideoFrameTimeForData: firstVideoFrameTimeForData,
|
22530 | videoTimingInfo: segmentInfo.videoTimingInfo,
|
22531 | audioTimingInfo: segmentInfo.audioTimingInfo
|
22532 | });
|
22533 | }
|
22534 |
|
22535 |
|
22536 |
|
22537 |
|
22538 | this.updateAppendInitSegmentStatus(segmentInfo, result.type);
|
22539 |
|
22540 |
|
22541 |
|
22542 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
22543 |
|
22544 |
|
22545 | if (segmentInfo.isSyncRequest) {
|
22546 |
|
22547 |
|
22548 |
|
22549 | this.updateTimingInfoEnd_(segmentInfo);
|
22550 | this.syncController_.saveSegmentTimingInfo({
|
22551 | segmentInfo: segmentInfo,
|
22552 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
22553 | });
|
22554 | var next = this.chooseNextRequest_();
|
22555 |
|
22556 |
|
22557 | if (next.mediaIndex !== segmentInfo.mediaIndex || next.partIndex !== segmentInfo.partIndex) {
|
22558 | this.logger_('sync segment was incorrect, not appending');
|
22559 | return;
|
22560 | }
|
22561 |
|
22562 |
|
22563 | this.logger_('sync segment was correct, appending');
|
22564 | }
|
22565 |
|
22566 |
|
22567 |
|
22568 |
|
22569 |
|
22570 | segmentInfo.hasAppendedData_ = true;
|
22571 |
|
22572 | this.processMetadataQueue_();
|
22573 | this.appendData_(segmentInfo, result);
|
22574 | };
|
22575 |
|
22576 | _proto.updateAppendInitSegmentStatus = function updateAppendInitSegmentStatus(segmentInfo, type) {
|
22577 |
|
22578 | if (this.loaderType_ === 'main' && typeof segmentInfo.timestampOffset === 'number' &&
|
22579 |
|
22580 | !segmentInfo.changedTimestampOffset) {
|
22581 |
|
22582 |
|
22583 | this.appendInitSegment_ = {
|
22584 | audio: true,
|
22585 | video: true
|
22586 | };
|
22587 | }
|
22588 |
|
22589 | if (this.playlistOfLastInitSegment_[type] !== segmentInfo.playlist) {
|
22590 |
|
22591 |
|
22592 | this.appendInitSegment_[type] = true;
|
22593 | }
|
22594 | };
|
22595 |
|
22596 | _proto.getInitSegmentAndUpdateState_ = function getInitSegmentAndUpdateState_(_ref4) {
|
22597 | var type = _ref4.type,
|
22598 | initSegment = _ref4.initSegment,
|
22599 | map = _ref4.map,
|
22600 | playlist = _ref4.playlist;
|
22601 |
|
22602 |
|
22603 |
|
22604 |
|
22605 |
|
22606 |
|
22607 | if (map) {
|
22608 | var id = initSegmentId(map);
|
22609 |
|
22610 | if (this.activeInitSegmentId_ === id) {
|
22611 |
|
22612 | return null;
|
22613 | }
|
22614 |
|
22615 |
|
22616 |
|
22617 |
|
22618 |
|
22619 | initSegment = this.initSegmentForMap(map, true).bytes;
|
22620 | this.activeInitSegmentId_ = id;
|
22621 | }
|
22622 |
|
22623 |
|
22624 |
|
22625 |
|
22626 |
|
22627 |
|
22628 | if (initSegment && this.appendInitSegment_[type]) {
|
22629 |
|
22630 |
|
22631 |
|
22632 | this.playlistOfLastInitSegment_[type] = playlist;
|
22633 |
|
22634 | this.appendInitSegment_[type] = false;
|
22635 |
|
22636 |
|
22637 | this.activeInitSegmentId_ = null;
|
22638 | return initSegment;
|
22639 | }
|
22640 |
|
22641 | return null;
|
22642 | };
|
22643 |
|
22644 | _proto.handleQuotaExceededError_ = function handleQuotaExceededError_(_ref5, error) {
|
22645 | var _this3 = this;
|
22646 |
|
22647 | var segmentInfo = _ref5.segmentInfo,
|
22648 | type = _ref5.type,
|
22649 | bytes = _ref5.bytes;
|
22650 | var audioBuffered = this.sourceUpdater_.audioBuffered();
|
22651 | var videoBuffered = this.sourceUpdater_.videoBuffered();
|
22652 |
|
22653 |
|
22654 |
|
22655 | if (audioBuffered.length > 1) {
|
22656 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the audio buffer: ' + timeRangesToArray(audioBuffered).join(', '));
|
22657 | }
|
22658 |
|
22659 | if (videoBuffered.length > 1) {
|
22660 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the video buffer: ' + timeRangesToArray(videoBuffered).join(', '));
|
22661 | }
|
22662 |
|
22663 | var audioBufferStart = audioBuffered.length ? audioBuffered.start(0) : 0;
|
22664 | var audioBufferEnd = audioBuffered.length ? audioBuffered.end(audioBuffered.length - 1) : 0;
|
22665 | var videoBufferStart = videoBuffered.length ? videoBuffered.start(0) : 0;
|
22666 | var videoBufferEnd = videoBuffered.length ? videoBuffered.end(videoBuffered.length - 1) : 0;
|
22667 |
|
22668 | if (audioBufferEnd - audioBufferStart <= MIN_BACK_BUFFER && videoBufferEnd - videoBufferStart <= MIN_BACK_BUFFER) {
|
22669 |
|
22670 |
|
22671 |
|
22672 |
|
22673 | this.logger_('On QUOTA_EXCEEDED_ERR, single segment too large to append to ' + 'buffer, triggering an error. ' + ("Appended byte length: " + bytes.byteLength + ", ") + ("audio buffer: " + timeRangesToArray(audioBuffered).join(', ') + ", ") + ("video buffer: " + timeRangesToArray(videoBuffered).join(', ') + ", "));
|
22674 | this.error({
|
22675 | message: 'Quota exceeded error with append of a single segment of content',
|
22676 | excludeUntil: Infinity
|
22677 | });
|
22678 | this.trigger('error');
|
22679 | return;
|
22680 | }
|
22681 |
|
22682 |
|
22683 |
|
22684 |
|
22685 |
|
22686 |
|
22687 |
|
22688 |
|
22689 |
|
22690 |
|
22691 |
|
22692 |
|
22693 |
|
22694 | this.waitingOnRemove_ = true;
|
22695 | this.callQueue_.push(this.appendToSourceBuffer_.bind(this, {
|
22696 | segmentInfo: segmentInfo,
|
22697 | type: type,
|
22698 | bytes: bytes
|
22699 | }));
|
22700 | var currentTime = this.currentTime_();
|
22701 |
|
22702 |
|
22703 | var timeToRemoveUntil = currentTime - MIN_BACK_BUFFER;
|
22704 | this.logger_("On QUOTA_EXCEEDED_ERR, removing audio/video from 0 to " + timeToRemoveUntil);
|
22705 | this.remove(0, timeToRemoveUntil, function () {
|
22706 | _this3.logger_("On QUOTA_EXCEEDED_ERR, retrying append in " + MIN_BACK_BUFFER + "s");
|
22707 |
|
22708 | _this3.waitingOnRemove_ = false;
|
22709 |
|
22710 |
|
22711 | _this3.quotaExceededErrorRetryTimeout_ = window.setTimeout(function () {
|
22712 | _this3.logger_('On QUOTA_EXCEEDED_ERR, re-processing call queue');
|
22713 |
|
22714 | _this3.quotaExceededErrorRetryTimeout_ = null;
|
22715 |
|
22716 | _this3.processCallQueue_();
|
22717 | }, MIN_BACK_BUFFER * 1000);
|
22718 | }, true);
|
22719 | };
|
22720 |
|
22721 | _proto.handleAppendError_ = function handleAppendError_(_ref6, error) {
|
22722 | var segmentInfo = _ref6.segmentInfo,
|
22723 | type = _ref6.type,
|
22724 | bytes = _ref6.bytes;
|
22725 |
|
22726 |
|
22727 | if (!error) {
|
22728 | return;
|
22729 | }
|
22730 |
|
22731 | if (error.code === QUOTA_EXCEEDED_ERR) {
|
22732 | this.handleQuotaExceededError_({
|
22733 | segmentInfo: segmentInfo,
|
22734 | type: type,
|
22735 | bytes: bytes
|
22736 | });
|
22737 |
|
22738 |
|
22739 | return;
|
22740 | }
|
22741 |
|
22742 | this.logger_('Received non QUOTA_EXCEEDED_ERR on append', error);
|
22743 | this.error(type + " append of " + bytes.length + "b failed for segment " + ("#" + segmentInfo.mediaIndex + " in playlist " + segmentInfo.playlist.id));
|
22744 |
|
22745 |
|
22746 |
|
22747 |
|
22748 |
|
22749 | this.trigger('appenderror');
|
22750 | };
|
22751 |
|
22752 | _proto.appendToSourceBuffer_ = function appendToSourceBuffer_(_ref7) {
|
22753 | var segmentInfo = _ref7.segmentInfo,
|
22754 | type = _ref7.type,
|
22755 | initSegment = _ref7.initSegment,
|
22756 | data = _ref7.data,
|
22757 | bytes = _ref7.bytes;
|
22758 |
|
22759 |
|
22760 | if (!bytes) {
|
22761 | var segments = [data];
|
22762 | var byteLength = data.byteLength;
|
22763 |
|
22764 | if (initSegment) {
|
22765 |
|
22766 |
|
22767 | segments.unshift(initSegment);
|
22768 | byteLength += initSegment.byteLength;
|
22769 | }
|
22770 |
|
22771 |
|
22772 |
|
22773 | bytes = concatSegments({
|
22774 | bytes: byteLength,
|
22775 | segments: segments
|
22776 | });
|
22777 | }
|
22778 |
|
22779 | this.sourceUpdater_.appendBuffer({
|
22780 | segmentInfo: segmentInfo,
|
22781 | type: type,
|
22782 | bytes: bytes
|
22783 | }, this.handleAppendError_.bind(this, {
|
22784 | segmentInfo: segmentInfo,
|
22785 | type: type,
|
22786 | bytes: bytes
|
22787 | }));
|
22788 | };
|
22789 |
|
22790 | _proto.handleSegmentTimingInfo_ = function handleSegmentTimingInfo_(type, requestId, segmentTimingInfo) {
|
22791 | if (!this.pendingSegment_ || requestId !== this.pendingSegment_.requestId) {
|
22792 | return;
|
22793 | }
|
22794 |
|
22795 | var segment = this.pendingSegment_.segment;
|
22796 | var timingInfoProperty = type + "TimingInfo";
|
22797 |
|
22798 | if (!segment[timingInfoProperty]) {
|
22799 | segment[timingInfoProperty] = {};
|
22800 | }
|
22801 |
|
22802 | segment[timingInfoProperty].transmuxerPrependedSeconds = segmentTimingInfo.prependedContentDuration || 0;
|
22803 | segment[timingInfoProperty].transmuxedPresentationStart = segmentTimingInfo.start.presentation;
|
22804 | segment[timingInfoProperty].transmuxedDecodeStart = segmentTimingInfo.start.decode;
|
22805 | segment[timingInfoProperty].transmuxedPresentationEnd = segmentTimingInfo.end.presentation;
|
22806 | segment[timingInfoProperty].transmuxedDecodeEnd = segmentTimingInfo.end.decode;
|
22807 |
|
22808 | segment[timingInfoProperty].baseMediaDecodeTime = segmentTimingInfo.baseMediaDecodeTime;
|
22809 | };
|
22810 |
|
22811 | _proto.appendData_ = function appendData_(segmentInfo, result) {
|
22812 | var type = result.type,
|
22813 | data = result.data;
|
22814 |
|
22815 | if (!data || !data.byteLength) {
|
22816 | return;
|
22817 | }
|
22818 |
|
22819 | if (type === 'audio' && this.audioDisabled_) {
|
22820 | return;
|
22821 | }
|
22822 |
|
22823 | var initSegment = this.getInitSegmentAndUpdateState_({
|
22824 | type: type,
|
22825 | initSegment: result.initSegment,
|
22826 | playlist: segmentInfo.playlist,
|
22827 | map: segmentInfo.isFmp4 ? segmentInfo.segment.map : null
|
22828 | });
|
22829 | this.appendToSourceBuffer_({
|
22830 | segmentInfo: segmentInfo,
|
22831 | type: type,
|
22832 | initSegment: initSegment,
|
22833 | data: data
|
22834 | });
|
22835 | }
|
22836 | |
22837 |
|
22838 |
|
22839 |
|
22840 |
|
22841 | ;
|
22842 |
|
22843 | _proto.loadSegment_ = function loadSegment_(segmentInfo) {
|
22844 | var _this4 = this;
|
22845 |
|
22846 | this.state = 'WAITING';
|
22847 | this.pendingSegment_ = segmentInfo;
|
22848 | this.trimBackBuffer_(segmentInfo);
|
22849 |
|
22850 | if (typeof segmentInfo.timestampOffset === 'number') {
|
22851 | if (this.transmuxer_) {
|
22852 | this.transmuxer_.postMessage({
|
22853 | action: 'clearAllMp4Captions'
|
22854 | });
|
22855 | }
|
22856 | }
|
22857 |
|
22858 | if (!this.hasEnoughInfoToLoad_()) {
|
22859 | this.loadQueue_.push(function () {
|
22860 |
|
22861 |
|
22862 | var options = _extends_1({}, segmentInfo, {
|
22863 | forceTimestampOffset: true
|
22864 | });
|
22865 |
|
22866 | _extends_1(segmentInfo, _this4.generateSegmentInfo_(options));
|
22867 |
|
22868 | _this4.isPendingTimestampOffset_ = false;
|
22869 |
|
22870 | _this4.updateTransmuxerAndRequestSegment_(segmentInfo);
|
22871 | });
|
22872 | return;
|
22873 | }
|
22874 |
|
22875 | this.updateTransmuxerAndRequestSegment_(segmentInfo);
|
22876 | };
|
22877 |
|
22878 | _proto.updateTransmuxerAndRequestSegment_ = function updateTransmuxerAndRequestSegment_(segmentInfo) {
|
22879 | var _this5 = this;
|
22880 |
|
22881 |
|
22882 |
|
22883 |
|
22884 |
|
22885 |
|
22886 | if (this.shouldUpdateTransmuxerTimestampOffset_(segmentInfo.timestampOffset)) {
|
22887 | this.gopBuffer_.length = 0;
|
22888 |
|
22889 | segmentInfo.gopsToAlignWith = [];
|
22890 | this.timeMapping_ = 0;
|
22891 |
|
22892 | this.transmuxer_.postMessage({
|
22893 | action: 'reset'
|
22894 | });
|
22895 | this.transmuxer_.postMessage({
|
22896 | action: 'setTimestampOffset',
|
22897 | timestampOffset: segmentInfo.timestampOffset
|
22898 | });
|
22899 | }
|
22900 |
|
22901 | var simpleSegment = this.createSimplifiedSegmentObj_(segmentInfo);
|
22902 | var isEndOfStream = this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex);
|
22903 | var isWalkingForward = this.mediaIndex !== null;
|
22904 | var isDiscontinuity = segmentInfo.timeline !== this.currentTimeline_ &&
|
22905 |
|
22906 | segmentInfo.timeline > 0;
|
22907 | var isEndOfTimeline = isEndOfStream || isWalkingForward && isDiscontinuity;
|
22908 | this.logger_("Requesting " + segmentInfoString(segmentInfo));
|
22909 |
|
22910 |
|
22911 |
|
22912 |
|
22913 |
|
22914 | if (simpleSegment.map && !simpleSegment.map.bytes) {
|
22915 | this.logger_('going to request init segment.');
|
22916 | this.appendInitSegment_ = {
|
22917 | video: true,
|
22918 | audio: true
|
22919 | };
|
22920 | }
|
22921 |
|
22922 | segmentInfo.abortRequests = mediaSegmentRequest({
|
22923 | xhr: this.vhs_.xhr,
|
22924 | xhrOptions: this.xhrOptions_,
|
22925 | decryptionWorker: this.decrypter_,
|
22926 | segment: simpleSegment,
|
22927 | abortFn: this.handleAbort_.bind(this, segmentInfo),
|
22928 | progressFn: this.handleProgress_.bind(this),
|
22929 | trackInfoFn: this.handleTrackInfo_.bind(this),
|
22930 | timingInfoFn: this.handleTimingInfo_.bind(this),
|
22931 | videoSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'video', segmentInfo.requestId),
|
22932 | audioSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'audio', segmentInfo.requestId),
|
22933 | captionsFn: this.handleCaptions_.bind(this),
|
22934 | isEndOfTimeline: isEndOfTimeline,
|
22935 | endedTimelineFn: function endedTimelineFn() {
|
22936 | _this5.logger_('received endedtimeline callback');
|
22937 | },
|
22938 | id3Fn: this.handleId3_.bind(this),
|
22939 | dataFn: this.handleData_.bind(this),
|
22940 | doneFn: this.segmentRequestFinished_.bind(this),
|
22941 | onTransmuxerLog: function onTransmuxerLog(_ref8) {
|
22942 | var message = _ref8.message,
|
22943 | level = _ref8.level,
|
22944 | stream = _ref8.stream;
|
22945 |
|
22946 | _this5.logger_(segmentInfoString(segmentInfo) + " logged from transmuxer stream " + stream + " as a " + level + ": " + message);
|
22947 | }
|
22948 | });
|
22949 | }
|
22950 | |
22951 |
|
22952 |
|
22953 |
|
22954 |
|
22955 |
|
22956 |
|
22957 |
|
22958 | ;
|
22959 |
|
22960 | _proto.trimBackBuffer_ = function trimBackBuffer_(segmentInfo) {
|
22961 | var removeToTime = safeBackBufferTrimTime(this.seekable_(), this.currentTime_(), this.playlist_.targetDuration || 10);
|
22962 |
|
22963 |
|
22964 |
|
22965 |
|
22966 |
|
22967 | if (removeToTime > 0) {
|
22968 | this.remove(0, removeToTime);
|
22969 | }
|
22970 | }
|
22971 | |
22972 |
|
22973 |
|
22974 |
|
22975 |
|
22976 |
|
22977 |
|
22978 |
|
22979 |
|
22980 | ;
|
22981 |
|
22982 | _proto.createSimplifiedSegmentObj_ = function createSimplifiedSegmentObj_(segmentInfo) {
|
22983 | var segment = segmentInfo.segment;
|
22984 | var part = segmentInfo.part;
|
22985 | var simpleSegment = {
|
22986 | resolvedUri: part ? part.resolvedUri : segment.resolvedUri,
|
22987 | byterange: part ? part.byterange : segment.byterange,
|
22988 | requestId: segmentInfo.requestId,
|
22989 | transmuxer: segmentInfo.transmuxer,
|
22990 | audioAppendStart: segmentInfo.audioAppendStart,
|
22991 | gopsToAlignWith: segmentInfo.gopsToAlignWith,
|
22992 | part: segmentInfo.part
|
22993 | };
|
22994 | var previousSegment = segmentInfo.playlist.segments[segmentInfo.mediaIndex - 1];
|
22995 |
|
22996 | if (previousSegment && previousSegment.timeline === segment.timeline) {
|
22997 |
|
22998 |
|
22999 |
|
23000 |
|
23001 |
|
23002 |
|
23003 |
|
23004 |
|
23005 | if (previousSegment.videoTimingInfo) {
|
23006 | simpleSegment.baseStartTime = previousSegment.videoTimingInfo.transmuxedDecodeEnd;
|
23007 | } else if (previousSegment.audioTimingInfo) {
|
23008 | simpleSegment.baseStartTime = previousSegment.audioTimingInfo.transmuxedDecodeEnd;
|
23009 | }
|
23010 | }
|
23011 |
|
23012 | if (segment.key) {
|
23013 |
|
23014 |
|
23015 | var iv = segment.key.iv || new Uint32Array([0, 0, 0, segmentInfo.mediaIndex + segmentInfo.playlist.mediaSequence]);
|
23016 | simpleSegment.key = this.segmentKey(segment.key);
|
23017 | simpleSegment.key.iv = iv;
|
23018 | }
|
23019 |
|
23020 | if (segment.map) {
|
23021 | simpleSegment.map = this.initSegmentForMap(segment.map);
|
23022 | }
|
23023 |
|
23024 | return simpleSegment;
|
23025 | };
|
23026 |
|
23027 | _proto.saveTransferStats_ = function saveTransferStats_(stats) {
|
23028 |
|
23029 |
|
23030 | this.mediaRequests += 1;
|
23031 |
|
23032 | if (stats) {
|
23033 | this.mediaBytesTransferred += stats.bytesReceived;
|
23034 | this.mediaTransferDuration += stats.roundTripTime;
|
23035 | }
|
23036 | };
|
23037 |
|
23038 | _proto.saveBandwidthRelatedStats_ = function saveBandwidthRelatedStats_(duration, stats) {
|
23039 |
|
23040 |
|
23041 |
|
23042 | this.pendingSegment_.byteLength = stats.bytesReceived;
|
23043 |
|
23044 | if (duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
23045 | this.logger_("Ignoring segment's bandwidth because its duration of " + duration + (" is less than the min to record " + MIN_SEGMENT_DURATION_TO_SAVE_STATS));
|
23046 | return;
|
23047 | }
|
23048 |
|
23049 | this.bandwidth = stats.bandwidth;
|
23050 | this.roundTrip = stats.roundTripTime;
|
23051 | };
|
23052 |
|
23053 | _proto.handleTimeout_ = function handleTimeout_() {
|
23054 |
|
23055 |
|
23056 | this.mediaRequestsTimedout += 1;
|
23057 | this.bandwidth = 1;
|
23058 | this.roundTrip = NaN;
|
23059 | this.trigger('bandwidthupdate');
|
23060 | }
|
23061 | |
23062 |
|
23063 |
|
23064 |
|
23065 |
|
23066 |
|
23067 | ;
|
23068 |
|
23069 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
23070 |
|
23071 |
|
23072 |
|
23073 |
|
23074 | if (this.callQueue_.length) {
|
23075 | this.callQueue_.push(this.segmentRequestFinished_.bind(this, error, simpleSegment, result));
|
23076 | return;
|
23077 | }
|
23078 |
|
23079 | this.saveTransferStats_(simpleSegment.stats);
|
23080 |
|
23081 | if (!this.pendingSegment_) {
|
23082 | return;
|
23083 | }
|
23084 |
|
23085 |
|
23086 |
|
23087 |
|
23088 |
|
23089 | if (simpleSegment.requestId !== this.pendingSegment_.requestId) {
|
23090 | return;
|
23091 | }
|
23092 |
|
23093 |
|
23094 | if (error) {
|
23095 | this.pendingSegment_ = null;
|
23096 | this.state = 'READY';
|
23097 |
|
23098 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
23099 | return;
|
23100 | }
|
23101 |
|
23102 | this.pause();
|
23103 |
|
23104 |
|
23105 |
|
23106 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
23107 | this.handleTimeout_();
|
23108 | return;
|
23109 | }
|
23110 |
|
23111 |
|
23112 |
|
23113 | this.mediaRequestsErrored += 1;
|
23114 | this.error(error);
|
23115 | this.trigger('error');
|
23116 | return;
|
23117 | }
|
23118 |
|
23119 | var segmentInfo = this.pendingSegment_;
|
23120 |
|
23121 |
|
23122 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
23123 | segmentInfo.endOfAllRequests = simpleSegment.endOfAllRequests;
|
23124 |
|
23125 | if (result.gopInfo) {
|
23126 | this.gopBuffer_ = updateGopBuffer(this.gopBuffer_, result.gopInfo, this.safeAppend_);
|
23127 | }
|
23128 |
|
23129 |
|
23130 |
|
23131 | this.state = 'APPENDING';
|
23132 |
|
23133 | this.trigger('appending');
|
23134 | this.waitForAppendsToComplete_(segmentInfo);
|
23135 | };
|
23136 |
|
23137 | _proto.setTimeMapping_ = function setTimeMapping_(timeline) {
|
23138 | var timelineMapping = this.syncController_.mappingForTimeline(timeline);
|
23139 |
|
23140 | if (timelineMapping !== null) {
|
23141 | this.timeMapping_ = timelineMapping;
|
23142 | }
|
23143 | };
|
23144 |
|
23145 | _proto.updateMediaSecondsLoaded_ = function updateMediaSecondsLoaded_(segment) {
|
23146 | if (typeof segment.start === 'number' && typeof segment.end === 'number') {
|
23147 | this.mediaSecondsLoaded += segment.end - segment.start;
|
23148 | } else {
|
23149 | this.mediaSecondsLoaded += segment.duration;
|
23150 | }
|
23151 | };
|
23152 |
|
23153 | _proto.shouldUpdateTransmuxerTimestampOffset_ = function shouldUpdateTransmuxerTimestampOffset_(timestampOffset) {
|
23154 | if (timestampOffset === null) {
|
23155 | return false;
|
23156 | }
|
23157 |
|
23158 |
|
23159 |
|
23160 | if (this.loaderType_ === 'main' && timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
23161 | return true;
|
23162 | }
|
23163 |
|
23164 | if (!this.audioDisabled_ && timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
23165 | return true;
|
23166 | }
|
23167 |
|
23168 | return false;
|
23169 | };
|
23170 |
|
23171 | _proto.trueSegmentStart_ = function trueSegmentStart_(_ref9) {
|
23172 | var currentStart = _ref9.currentStart,
|
23173 | playlist = _ref9.playlist,
|
23174 | mediaIndex = _ref9.mediaIndex,
|
23175 | firstVideoFrameTimeForData = _ref9.firstVideoFrameTimeForData,
|
23176 | currentVideoTimestampOffset = _ref9.currentVideoTimestampOffset,
|
23177 | useVideoTimingInfo = _ref9.useVideoTimingInfo,
|
23178 | videoTimingInfo = _ref9.videoTimingInfo,
|
23179 | audioTimingInfo = _ref9.audioTimingInfo;
|
23180 |
|
23181 | if (typeof currentStart !== 'undefined') {
|
23182 |
|
23183 | return currentStart;
|
23184 | }
|
23185 |
|
23186 | if (!useVideoTimingInfo) {
|
23187 | return audioTimingInfo.start;
|
23188 | }
|
23189 |
|
23190 | var previousSegment = playlist.segments[mediaIndex - 1];
|
23191 |
|
23192 |
|
23193 |
|
23194 |
|
23195 |
|
23196 | if (mediaIndex === 0 || !previousSegment || typeof previousSegment.start === 'undefined' || previousSegment.end !== firstVideoFrameTimeForData + currentVideoTimestampOffset) {
|
23197 | return firstVideoFrameTimeForData;
|
23198 | }
|
23199 |
|
23200 | return videoTimingInfo.start;
|
23201 | };
|
23202 |
|
23203 | _proto.waitForAppendsToComplete_ = function waitForAppendsToComplete_(segmentInfo) {
|
23204 | var trackInfo = this.getCurrentMediaInfo_(segmentInfo);
|
23205 |
|
23206 | if (!trackInfo) {
|
23207 | this.error({
|
23208 | message: 'No starting media returned, likely due to an unsupported media format.',
|
23209 | blacklistDuration: Infinity
|
23210 | });
|
23211 | this.trigger('error');
|
23212 | return;
|
23213 | }
|
23214 |
|
23215 |
|
23216 |
|
23217 |
|
23218 | var hasAudio = trackInfo.hasAudio,
|
23219 | hasVideo = trackInfo.hasVideo,
|
23220 | isMuxed = trackInfo.isMuxed;
|
23221 | var waitForVideo = this.loaderType_ === 'main' && hasVideo;
|
23222 | var waitForAudio = !this.audioDisabled_ && hasAudio && !isMuxed;
|
23223 | segmentInfo.waitingOnAppends = 0;
|
23224 |
|
23225 | if (!segmentInfo.hasAppendedData_) {
|
23226 | if (!segmentInfo.timingInfo && typeof segmentInfo.timestampOffset === 'number') {
|
23227 |
|
23228 |
|
23229 |
|
23230 |
|
23231 |
|
23232 |
|
23233 |
|
23234 |
|
23235 | this.isPendingTimestampOffset_ = true;
|
23236 | }
|
23237 |
|
23238 |
|
23239 | segmentInfo.timingInfo = {
|
23240 | start: 0
|
23241 | };
|
23242 | segmentInfo.waitingOnAppends++;
|
23243 |
|
23244 | if (!this.isPendingTimestampOffset_) {
|
23245 |
|
23246 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
23247 |
|
23248 |
|
23249 | this.processMetadataQueue_();
|
23250 | }
|
23251 |
|
23252 |
|
23253 | this.checkAppendsDone_(segmentInfo);
|
23254 | return;
|
23255 | }
|
23256 |
|
23257 |
|
23258 | if (waitForVideo) {
|
23259 | segmentInfo.waitingOnAppends++;
|
23260 | }
|
23261 |
|
23262 | if (waitForAudio) {
|
23263 | segmentInfo.waitingOnAppends++;
|
23264 | }
|
23265 |
|
23266 | if (waitForVideo) {
|
23267 | this.sourceUpdater_.videoQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
23268 | }
|
23269 |
|
23270 | if (waitForAudio) {
|
23271 | this.sourceUpdater_.audioQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
23272 | }
|
23273 | };
|
23274 |
|
23275 | _proto.checkAppendsDone_ = function checkAppendsDone_(segmentInfo) {
|
23276 | if (this.checkForAbort_(segmentInfo.requestId)) {
|
23277 | return;
|
23278 | }
|
23279 |
|
23280 | segmentInfo.waitingOnAppends--;
|
23281 |
|
23282 | if (segmentInfo.waitingOnAppends === 0) {
|
23283 | this.handleAppendsDone_();
|
23284 | }
|
23285 | };
|
23286 |
|
23287 | _proto.checkForIllegalMediaSwitch = function checkForIllegalMediaSwitch(trackInfo) {
|
23288 | var illegalMediaSwitchError = illegalMediaSwitch(this.loaderType_, this.getCurrentMediaInfo_(), trackInfo);
|
23289 |
|
23290 | if (illegalMediaSwitchError) {
|
23291 | this.error({
|
23292 | message: illegalMediaSwitchError,
|
23293 | blacklistDuration: Infinity
|
23294 | });
|
23295 | this.trigger('error');
|
23296 | return true;
|
23297 | }
|
23298 |
|
23299 | return false;
|
23300 | };
|
23301 |
|
23302 | _proto.updateSourceBufferTimestampOffset_ = function updateSourceBufferTimestampOffset_(segmentInfo) {
|
23303 | if (segmentInfo.timestampOffset === null ||
|
23304 |
|
23305 | typeof segmentInfo.timingInfo.start !== 'number' ||
|
23306 | segmentInfo.changedTimestampOffset ||
|
23307 | this.loaderType_ !== 'main') {
|
23308 | return;
|
23309 | }
|
23310 |
|
23311 | var didChange = false;
|
23312 |
|
23313 |
|
23314 |
|
23315 |
|
23316 | segmentInfo.timestampOffset -= segmentInfo.timingInfo.start;
|
23317 |
|
23318 |
|
23319 |
|
23320 | segmentInfo.changedTimestampOffset = true;
|
23321 |
|
23322 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
23323 | this.sourceUpdater_.videoTimestampOffset(segmentInfo.timestampOffset);
|
23324 | didChange = true;
|
23325 | }
|
23326 |
|
23327 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
23328 | this.sourceUpdater_.audioTimestampOffset(segmentInfo.timestampOffset);
|
23329 | didChange = true;
|
23330 | }
|
23331 |
|
23332 | if (didChange) {
|
23333 | this.trigger('timestampoffset');
|
23334 | }
|
23335 | };
|
23336 |
|
23337 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_(segmentInfo) {
|
23338 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
23339 | var trackInfo = this.getMediaInfo_();
|
23340 | var useVideoTimingInfo = this.loaderType_ === 'main' && trackInfo && trackInfo.hasVideo;
|
23341 | var prioritizedTimingInfo = useVideoTimingInfo && segmentInfo.videoTimingInfo ? segmentInfo.videoTimingInfo : segmentInfo.audioTimingInfo;
|
23342 |
|
23343 | if (!prioritizedTimingInfo) {
|
23344 | return;
|
23345 | }
|
23346 |
|
23347 | segmentInfo.timingInfo.end = typeof prioritizedTimingInfo.end === 'number' ?
|
23348 |
|
23349 |
|
23350 | prioritizedTimingInfo.end : prioritizedTimingInfo.start + segmentInfo.duration;
|
23351 | }
|
23352 | |
23353 |
|
23354 |
|
23355 |
|
23356 |
|
23357 |
|
23358 |
|
23359 | ;
|
23360 |
|
23361 | _proto.handleAppendsDone_ = function handleAppendsDone_() {
|
23362 |
|
23363 | if (this.pendingSegment_) {
|
23364 | this.trigger('appendsdone');
|
23365 | }
|
23366 |
|
23367 | if (!this.pendingSegment_) {
|
23368 | this.state = 'READY';
|
23369 |
|
23370 |
|
23371 | if (!this.paused()) {
|
23372 | this.monitorBuffer_();
|
23373 | }
|
23374 |
|
23375 | return;
|
23376 | }
|
23377 |
|
23378 | var segmentInfo = this.pendingSegment_;
|
23379 |
|
23380 |
|
23381 |
|
23382 | this.updateTimingInfoEnd_(segmentInfo);
|
23383 |
|
23384 | if (this.shouldSaveSegmentTimingInfo_) {
|
23385 |
|
23386 |
|
23387 |
|
23388 |
|
23389 |
|
23390 |
|
23391 |
|
23392 |
|
23393 |
|
23394 |
|
23395 |
|
23396 |
|
23397 |
|
23398 |
|
23399 |
|
23400 |
|
23401 |
|
23402 | this.syncController_.saveSegmentTimingInfo({
|
23403 | segmentInfo: segmentInfo,
|
23404 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
23405 | });
|
23406 | }
|
23407 |
|
23408 | var segmentDurationMessage = getTroublesomeSegmentDurationMessage(segmentInfo, this.sourceType_);
|
23409 |
|
23410 | if (segmentDurationMessage) {
|
23411 | if (segmentDurationMessage.severity === 'warn') {
|
23412 | videojs__default["default"].log.warn(segmentDurationMessage.message);
|
23413 | } else {
|
23414 | this.logger_(segmentDurationMessage.message);
|
23415 | }
|
23416 | }
|
23417 |
|
23418 | this.recordThroughput_(segmentInfo);
|
23419 | this.pendingSegment_ = null;
|
23420 | this.state = 'READY';
|
23421 |
|
23422 | if (segmentInfo.isSyncRequest) {
|
23423 | this.trigger('syncinfoupdate');
|
23424 |
|
23425 |
|
23426 |
|
23427 |
|
23428 | if (!segmentInfo.hasAppendedData_) {
|
23429 | this.logger_("Throwing away un-appended sync request " + segmentInfoString(segmentInfo));
|
23430 | return;
|
23431 | }
|
23432 | }
|
23433 |
|
23434 | this.logger_("Appended " + segmentInfoString(segmentInfo));
|
23435 | this.addSegmentMetadataCue_(segmentInfo);
|
23436 | this.fetchAtBuffer_ = true;
|
23437 |
|
23438 | if (this.currentTimeline_ !== segmentInfo.timeline) {
|
23439 | this.timelineChangeController_.lastTimelineChange({
|
23440 | type: this.loaderType_,
|
23441 | from: this.currentTimeline_,
|
23442 | to: segmentInfo.timeline
|
23443 | });
|
23444 |
|
23445 |
|
23446 |
|
23447 | if (this.loaderType_ === 'main' && !this.audioDisabled_) {
|
23448 | this.timelineChangeController_.lastTimelineChange({
|
23449 | type: 'audio',
|
23450 | from: this.currentTimeline_,
|
23451 | to: segmentInfo.timeline
|
23452 | });
|
23453 | }
|
23454 | }
|
23455 |
|
23456 | this.currentTimeline_ = segmentInfo.timeline;
|
23457 |
|
23458 |
|
23459 |
|
23460 |
|
23461 | this.trigger('syncinfoupdate');
|
23462 | var segment = segmentInfo.segment;
|
23463 |
|
23464 |
|
23465 |
|
23466 |
|
23467 | if (segment.end && this.currentTime_() - segment.end > segmentInfo.playlist.targetDuration * 3) {
|
23468 | this.resetEverything();
|
23469 | return;
|
23470 | }
|
23471 |
|
23472 | var isWalkingForward = this.mediaIndex !== null;
|
23473 |
|
23474 |
|
23475 | if (isWalkingForward) {
|
23476 | this.trigger('bandwidthupdate');
|
23477 | }
|
23478 |
|
23479 | this.trigger('progress');
|
23480 | this.mediaIndex = segmentInfo.mediaIndex;
|
23481 | this.partIndex = segmentInfo.partIndex;
|
23482 |
|
23483 |
|
23484 |
|
23485 | if (this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex)) {
|
23486 | this.endOfStream();
|
23487 | }
|
23488 |
|
23489 |
|
23490 | this.trigger('appended');
|
23491 |
|
23492 | if (segmentInfo.hasAppendedData_) {
|
23493 | this.mediaAppends++;
|
23494 | }
|
23495 |
|
23496 | if (!this.paused()) {
|
23497 | this.monitorBuffer_();
|
23498 | }
|
23499 | }
|
23500 | |
23501 |
|
23502 |
|
23503 |
|
23504 |
|
23505 |
|
23506 |
|
23507 |
|
23508 |
|
23509 | ;
|
23510 |
|
23511 | _proto.recordThroughput_ = function recordThroughput_(segmentInfo) {
|
23512 | if (segmentInfo.duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
23513 | this.logger_("Ignoring segment's throughput because its duration of " + segmentInfo.duration + (" is less than the min to record " + MIN_SEGMENT_DURATION_TO_SAVE_STATS));
|
23514 | return;
|
23515 | }
|
23516 |
|
23517 | var rate = this.throughput.rate;
|
23518 |
|
23519 |
|
23520 | var segmentProcessingTime = Date.now() - segmentInfo.endOfAllRequests + 1;
|
23521 |
|
23522 | var segmentProcessingThroughput = Math.floor(segmentInfo.byteLength / segmentProcessingTime * 8 * 1000);
|
23523 |
|
23524 |
|
23525 | this.throughput.rate += (segmentProcessingThroughput - rate) / ++this.throughput.count;
|
23526 | }
|
23527 | |
23528 |
|
23529 |
|
23530 |
|
23531 |
|
23532 |
|
23533 |
|
23534 |
|
23535 |
|
23536 | ;
|
23537 |
|
23538 | _proto.addSegmentMetadataCue_ = function addSegmentMetadataCue_(segmentInfo) {
|
23539 | if (!this.segmentMetadataTrack_) {
|
23540 | return;
|
23541 | }
|
23542 |
|
23543 | var segment = segmentInfo.segment;
|
23544 | var start = segment.start;
|
23545 | var end = segment.end;
|
23546 |
|
23547 | if (!finite(start) || !finite(end)) {
|
23548 | return;
|
23549 | }
|
23550 |
|
23551 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
23552 | var Cue = window.WebKitDataCue || window.VTTCue;
|
23553 | var value = {
|
23554 | custom: segment.custom,
|
23555 | dateTimeObject: segment.dateTimeObject,
|
23556 | dateTimeString: segment.dateTimeString,
|
23557 | bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
|
23558 | resolution: segmentInfo.playlist.attributes.RESOLUTION,
|
23559 | codecs: segmentInfo.playlist.attributes.CODECS,
|
23560 | byteLength: segmentInfo.byteLength,
|
23561 | uri: segmentInfo.uri,
|
23562 | timeline: segmentInfo.timeline,
|
23563 | playlist: segmentInfo.playlist.id,
|
23564 | start: start,
|
23565 | end: end
|
23566 | };
|
23567 | var data = JSON.stringify(value);
|
23568 | var cue = new Cue(start, end, data);
|
23569 |
|
23570 |
|
23571 | cue.value = value;
|
23572 | this.segmentMetadataTrack_.addCue(cue);
|
23573 | };
|
23574 |
|
23575 | return SegmentLoader;
|
23576 | }(videojs__default["default"].EventTarget);
|
23577 |
|
23578 | function noop() {}
|
23579 |
|
23580 | var toTitleCase = function toTitleCase(string) {
|
23581 | if (typeof string !== 'string') {
|
23582 | return string;
|
23583 | }
|
23584 |
|
23585 | return string.replace(/./, function (w) {
|
23586 | return w.toUpperCase();
|
23587 | });
|
23588 | };
|
23589 |
|
23590 | var bufferTypes = ['video', 'audio'];
|
23591 |
|
23592 | var _updating = function updating(type, sourceUpdater) {
|
23593 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23594 | return sourceBuffer && sourceBuffer.updating || sourceUpdater.queuePending[type];
|
23595 | };
|
23596 |
|
23597 | var nextQueueIndexOfType = function nextQueueIndexOfType(type, queue) {
|
23598 | for (var i = 0; i < queue.length; i++) {
|
23599 | var queueEntry = queue[i];
|
23600 |
|
23601 | if (queueEntry.type === 'mediaSource') {
|
23602 |
|
23603 |
|
23604 | return null;
|
23605 | }
|
23606 |
|
23607 | if (queueEntry.type === type) {
|
23608 | return i;
|
23609 | }
|
23610 | }
|
23611 |
|
23612 | return null;
|
23613 | };
|
23614 |
|
23615 | var shiftQueue = function shiftQueue(type, sourceUpdater) {
|
23616 | if (sourceUpdater.queue.length === 0) {
|
23617 | return;
|
23618 | }
|
23619 |
|
23620 | var queueIndex = 0;
|
23621 | var queueEntry = sourceUpdater.queue[queueIndex];
|
23622 |
|
23623 | if (queueEntry.type === 'mediaSource') {
|
23624 | if (!sourceUpdater.updating() && sourceUpdater.mediaSource.readyState !== 'closed') {
|
23625 | sourceUpdater.queue.shift();
|
23626 | queueEntry.action(sourceUpdater);
|
23627 |
|
23628 | if (queueEntry.doneFn) {
|
23629 | queueEntry.doneFn();
|
23630 | }
|
23631 |
|
23632 |
|
23633 |
|
23634 |
|
23635 | shiftQueue('audio', sourceUpdater);
|
23636 | shiftQueue('video', sourceUpdater);
|
23637 | }
|
23638 |
|
23639 |
|
23640 |
|
23641 |
|
23642 | return;
|
23643 | }
|
23644 |
|
23645 | if (type === 'mediaSource') {
|
23646 |
|
23647 |
|
23648 |
|
23649 |
|
23650 | return;
|
23651 | }
|
23652 |
|
23653 |
|
23654 |
|
23655 |
|
23656 | if (!sourceUpdater.ready() || sourceUpdater.mediaSource.readyState === 'closed' || _updating(type, sourceUpdater)) {
|
23657 | return;
|
23658 | }
|
23659 |
|
23660 | if (queueEntry.type !== type) {
|
23661 | queueIndex = nextQueueIndexOfType(type, sourceUpdater.queue);
|
23662 |
|
23663 | if (queueIndex === null) {
|
23664 |
|
23665 |
|
23666 |
|
23667 | return;
|
23668 | }
|
23669 |
|
23670 | queueEntry = sourceUpdater.queue[queueIndex];
|
23671 | }
|
23672 |
|
23673 | sourceUpdater.queue.splice(queueIndex, 1);
|
23674 |
|
23675 |
|
23676 |
|
23677 |
|
23678 |
|
23679 |
|
23680 |
|
23681 | sourceUpdater.queuePending[type] = queueEntry;
|
23682 | queueEntry.action(type, sourceUpdater);
|
23683 |
|
23684 | if (!queueEntry.doneFn) {
|
23685 |
|
23686 | sourceUpdater.queuePending[type] = null;
|
23687 | shiftQueue(type, sourceUpdater);
|
23688 | return;
|
23689 | }
|
23690 | };
|
23691 |
|
23692 | var cleanupBuffer = function cleanupBuffer(type, sourceUpdater) {
|
23693 | var buffer = sourceUpdater[type + "Buffer"];
|
23694 | var titleType = toTitleCase(type);
|
23695 |
|
23696 | if (!buffer) {
|
23697 | return;
|
23698 | }
|
23699 |
|
23700 | buffer.removeEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
23701 | buffer.removeEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
23702 | sourceUpdater.codecs[type] = null;
|
23703 | sourceUpdater[type + "Buffer"] = null;
|
23704 | };
|
23705 |
|
23706 | var inSourceBuffers = function inSourceBuffers(mediaSource, sourceBuffer) {
|
23707 | return mediaSource && sourceBuffer && Array.prototype.indexOf.call(mediaSource.sourceBuffers, sourceBuffer) !== -1;
|
23708 | };
|
23709 |
|
23710 | var actions = {
|
23711 | appendBuffer: function appendBuffer(bytes, segmentInfo, onError) {
|
23712 | return function (type, sourceUpdater) {
|
23713 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23714 |
|
23715 |
|
23716 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
23717 | return;
|
23718 | }
|
23719 |
|
23720 | sourceUpdater.logger_("Appending segment " + segmentInfo.mediaIndex + "'s " + bytes.length + " bytes to " + type + "Buffer");
|
23721 |
|
23722 | try {
|
23723 | sourceBuffer.appendBuffer(bytes);
|
23724 | } catch (e) {
|
23725 | sourceUpdater.logger_("Error with code " + e.code + " " + (e.code === QUOTA_EXCEEDED_ERR ? '(QUOTA_EXCEEDED_ERR) ' : '') + ("when appending segment " + segmentInfo.mediaIndex + " to " + type + "Buffer"));
|
23726 | sourceUpdater.queuePending[type] = null;
|
23727 | onError(e);
|
23728 | }
|
23729 | };
|
23730 | },
|
23731 | remove: function remove(start, end) {
|
23732 | return function (type, sourceUpdater) {
|
23733 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23734 |
|
23735 |
|
23736 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
23737 | return;
|
23738 | }
|
23739 |
|
23740 | sourceUpdater.logger_("Removing " + start + " to " + end + " from " + type + "Buffer");
|
23741 |
|
23742 | try {
|
23743 | sourceBuffer.remove(start, end);
|
23744 | } catch (e) {
|
23745 | sourceUpdater.logger_("Remove " + start + " to " + end + " from " + type + "Buffer failed");
|
23746 | }
|
23747 | };
|
23748 | },
|
23749 | timestampOffset: function timestampOffset(offset) {
|
23750 | return function (type, sourceUpdater) {
|
23751 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23752 |
|
23753 |
|
23754 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
23755 | return;
|
23756 | }
|
23757 |
|
23758 | sourceUpdater.logger_("Setting " + type + "timestampOffset to " + offset);
|
23759 | sourceBuffer.timestampOffset = offset;
|
23760 | };
|
23761 | },
|
23762 | callback: function callback(_callback) {
|
23763 | return function (type, sourceUpdater) {
|
23764 | _callback();
|
23765 | };
|
23766 | },
|
23767 | endOfStream: function endOfStream(error) {
|
23768 | return function (sourceUpdater) {
|
23769 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
23770 | return;
|
23771 | }
|
23772 |
|
23773 | sourceUpdater.logger_("Calling mediaSource endOfStream(" + (error || '') + ")");
|
23774 |
|
23775 | try {
|
23776 | sourceUpdater.mediaSource.endOfStream(error);
|
23777 | } catch (e) {
|
23778 | videojs__default["default"].log.warn('Failed to call media source endOfStream', e);
|
23779 | }
|
23780 | };
|
23781 | },
|
23782 | duration: function duration(_duration) {
|
23783 | return function (sourceUpdater) {
|
23784 | sourceUpdater.logger_("Setting mediaSource duration to " + _duration);
|
23785 |
|
23786 | try {
|
23787 | sourceUpdater.mediaSource.duration = _duration;
|
23788 | } catch (e) {
|
23789 | videojs__default["default"].log.warn('Failed to set media source duration', e);
|
23790 | }
|
23791 | };
|
23792 | },
|
23793 | abort: function abort() {
|
23794 | return function (type, sourceUpdater) {
|
23795 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
23796 | return;
|
23797 | }
|
23798 |
|
23799 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23800 |
|
23801 |
|
23802 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
23803 | return;
|
23804 | }
|
23805 |
|
23806 | sourceUpdater.logger_("calling abort on " + type + "Buffer");
|
23807 |
|
23808 | try {
|
23809 | sourceBuffer.abort();
|
23810 | } catch (e) {
|
23811 | videojs__default["default"].log.warn("Failed to abort on " + type + "Buffer", e);
|
23812 | }
|
23813 | };
|
23814 | },
|
23815 | addSourceBuffer: function addSourceBuffer(type, codec) {
|
23816 | return function (sourceUpdater) {
|
23817 | var titleType = toTitleCase(type);
|
23818 | var mime = getMimeForCodec(codec);
|
23819 | sourceUpdater.logger_("Adding " + type + "Buffer with codec " + codec + " to mediaSource");
|
23820 | var sourceBuffer = sourceUpdater.mediaSource.addSourceBuffer(mime);
|
23821 | sourceBuffer.addEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
23822 | sourceBuffer.addEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
23823 | sourceUpdater.codecs[type] = codec;
|
23824 | sourceUpdater[type + "Buffer"] = sourceBuffer;
|
23825 | };
|
23826 | },
|
23827 | removeSourceBuffer: function removeSourceBuffer(type) {
|
23828 | return function (sourceUpdater) {
|
23829 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23830 | cleanupBuffer(type, sourceUpdater);
|
23831 |
|
23832 |
|
23833 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
23834 | return;
|
23835 | }
|
23836 |
|
23837 | sourceUpdater.logger_("Removing " + type + "Buffer with codec " + sourceUpdater.codecs[type] + " from mediaSource");
|
23838 |
|
23839 | try {
|
23840 | sourceUpdater.mediaSource.removeSourceBuffer(sourceBuffer);
|
23841 | } catch (e) {
|
23842 | videojs__default["default"].log.warn("Failed to removeSourceBuffer " + type + "Buffer", e);
|
23843 | }
|
23844 | };
|
23845 | },
|
23846 | changeType: function changeType(codec) {
|
23847 | return function (type, sourceUpdater) {
|
23848 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
23849 | var mime = getMimeForCodec(codec);
|
23850 |
|
23851 |
|
23852 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
23853 | return;
|
23854 | }
|
23855 |
|
23856 |
|
23857 | if (sourceUpdater.codecs[type] === codec) {
|
23858 | return;
|
23859 | }
|
23860 |
|
23861 | sourceUpdater.logger_("changing " + type + "Buffer codec from " + sourceUpdater.codecs[type] + " to " + codec);
|
23862 | sourceBuffer.changeType(mime);
|
23863 | sourceUpdater.codecs[type] = codec;
|
23864 | };
|
23865 | }
|
23866 | };
|
23867 |
|
23868 | var pushQueue = function pushQueue(_ref) {
|
23869 | var type = _ref.type,
|
23870 | sourceUpdater = _ref.sourceUpdater,
|
23871 | action = _ref.action,
|
23872 | doneFn = _ref.doneFn,
|
23873 | name = _ref.name;
|
23874 | sourceUpdater.queue.push({
|
23875 | type: type,
|
23876 | action: action,
|
23877 | doneFn: doneFn,
|
23878 | name: name
|
23879 | });
|
23880 | shiftQueue(type, sourceUpdater);
|
23881 | };
|
23882 |
|
23883 | var onUpdateend = function onUpdateend(type, sourceUpdater) {
|
23884 | return function (e) {
|
23885 |
|
23886 |
|
23887 |
|
23888 |
|
23889 |
|
23890 |
|
23891 | if (sourceUpdater.queuePending[type]) {
|
23892 | var doneFn = sourceUpdater.queuePending[type].doneFn;
|
23893 | sourceUpdater.queuePending[type] = null;
|
23894 |
|
23895 | if (doneFn) {
|
23896 |
|
23897 | doneFn(sourceUpdater[type + "Error_"]);
|
23898 | }
|
23899 | }
|
23900 |
|
23901 | shiftQueue(type, sourceUpdater);
|
23902 | };
|
23903 | };
|
23904 | |
23905 |
|
23906 |
|
23907 |
|
23908 |
|
23909 |
|
23910 |
|
23911 |
|
23912 |
|
23913 |
|
23914 |
|
23915 |
|
23916 | var SourceUpdater = function (_videojs$EventTarget) {
|
23917 | inheritsLoose(SourceUpdater, _videojs$EventTarget);
|
23918 |
|
23919 | function SourceUpdater(mediaSource) {
|
23920 | var _this;
|
23921 |
|
23922 | _this = _videojs$EventTarget.call(this) || this;
|
23923 | _this.mediaSource = mediaSource;
|
23924 |
|
23925 | _this.sourceopenListener_ = function () {
|
23926 | return shiftQueue('mediaSource', assertThisInitialized(_this));
|
23927 | };
|
23928 |
|
23929 | _this.mediaSource.addEventListener('sourceopen', _this.sourceopenListener_);
|
23930 |
|
23931 | _this.logger_ = logger('SourceUpdater');
|
23932 |
|
23933 | _this.audioTimestampOffset_ = 0;
|
23934 | _this.videoTimestampOffset_ = 0;
|
23935 | _this.queue = [];
|
23936 | _this.queuePending = {
|
23937 | audio: null,
|
23938 | video: null
|
23939 | };
|
23940 | _this.delayedAudioAppendQueue_ = [];
|
23941 | _this.videoAppendQueued_ = false;
|
23942 | _this.codecs = {};
|
23943 | _this.onVideoUpdateEnd_ = onUpdateend('video', assertThisInitialized(_this));
|
23944 | _this.onAudioUpdateEnd_ = onUpdateend('audio', assertThisInitialized(_this));
|
23945 |
|
23946 | _this.onVideoError_ = function (e) {
|
23947 |
|
23948 | _this.videoError_ = e;
|
23949 | };
|
23950 |
|
23951 | _this.onAudioError_ = function (e) {
|
23952 |
|
23953 | _this.audioError_ = e;
|
23954 | };
|
23955 |
|
23956 | _this.createdSourceBuffers_ = false;
|
23957 | _this.initializedEme_ = false;
|
23958 | _this.triggeredReady_ = false;
|
23959 | return _this;
|
23960 | }
|
23961 |
|
23962 | var _proto = SourceUpdater.prototype;
|
23963 |
|
23964 | _proto.initializedEme = function initializedEme() {
|
23965 | this.initializedEme_ = true;
|
23966 | this.triggerReady();
|
23967 | };
|
23968 |
|
23969 | _proto.hasCreatedSourceBuffers = function hasCreatedSourceBuffers() {
|
23970 |
|
23971 |
|
23972 | return this.createdSourceBuffers_;
|
23973 | };
|
23974 |
|
23975 | _proto.hasInitializedAnyEme = function hasInitializedAnyEme() {
|
23976 | return this.initializedEme_;
|
23977 | };
|
23978 |
|
23979 | _proto.ready = function ready() {
|
23980 | return this.hasCreatedSourceBuffers() && this.hasInitializedAnyEme();
|
23981 | };
|
23982 |
|
23983 | _proto.createSourceBuffers = function createSourceBuffers(codecs) {
|
23984 | if (this.hasCreatedSourceBuffers()) {
|
23985 |
|
23986 | return;
|
23987 | }
|
23988 |
|
23989 |
|
23990 |
|
23991 | this.addOrChangeSourceBuffers(codecs);
|
23992 | this.createdSourceBuffers_ = true;
|
23993 | this.trigger('createdsourcebuffers');
|
23994 | this.triggerReady();
|
23995 | };
|
23996 |
|
23997 | _proto.triggerReady = function triggerReady() {
|
23998 |
|
23999 |
|
24000 |
|
24001 |
|
24002 |
|
24003 |
|
24004 | if (this.ready() && !this.triggeredReady_) {
|
24005 | this.triggeredReady_ = true;
|
24006 | this.trigger('ready');
|
24007 | }
|
24008 | }
|
24009 | |
24010 |
|
24011 |
|
24012 |
|
24013 |
|
24014 |
|
24015 |
|
24016 |
|
24017 |
|
24018 | ;
|
24019 |
|
24020 | _proto.addSourceBuffer = function addSourceBuffer(type, codec) {
|
24021 | pushQueue({
|
24022 | type: 'mediaSource',
|
24023 | sourceUpdater: this,
|
24024 | action: actions.addSourceBuffer(type, codec),
|
24025 | name: 'addSourceBuffer'
|
24026 | });
|
24027 | }
|
24028 | |
24029 |
|
24030 |
|
24031 |
|
24032 |
|
24033 |
|
24034 | ;
|
24035 |
|
24036 | _proto.abort = function abort(type) {
|
24037 | pushQueue({
|
24038 | type: type,
|
24039 | sourceUpdater: this,
|
24040 | action: actions.abort(type),
|
24041 | name: 'abort'
|
24042 | });
|
24043 | }
|
24044 | |
24045 |
|
24046 |
|
24047 |
|
24048 |
|
24049 |
|
24050 |
|
24051 | ;
|
24052 |
|
24053 | _proto.removeSourceBuffer = function removeSourceBuffer(type) {
|
24054 | if (!this.canRemoveSourceBuffer()) {
|
24055 | videojs__default["default"].log.error('removeSourceBuffer is not supported!');
|
24056 | return;
|
24057 | }
|
24058 |
|
24059 | pushQueue({
|
24060 | type: 'mediaSource',
|
24061 | sourceUpdater: this,
|
24062 | action: actions.removeSourceBuffer(type),
|
24063 | name: 'removeSourceBuffer'
|
24064 | });
|
24065 | }
|
24066 | |
24067 |
|
24068 |
|
24069 |
|
24070 |
|
24071 |
|
24072 |
|
24073 | ;
|
24074 |
|
24075 | _proto.canRemoveSourceBuffer = function canRemoveSourceBuffer() {
|
24076 |
|
24077 |
|
24078 |
|
24079 |
|
24080 | return !videojs__default["default"].browser.IE_VERSION && !videojs__default["default"].browser.IS_FIREFOX && window.MediaSource && window.MediaSource.prototype && typeof window.MediaSource.prototype.removeSourceBuffer === 'function';
|
24081 | }
|
24082 | |
24083 |
|
24084 |
|
24085 |
|
24086 |
|
24087 |
|
24088 |
|
24089 | ;
|
24090 |
|
24091 | SourceUpdater.canChangeType = function canChangeType() {
|
24092 | return window.SourceBuffer && window.SourceBuffer.prototype && typeof window.SourceBuffer.prototype.changeType === 'function';
|
24093 | }
|
24094 | |
24095 |
|
24096 |
|
24097 |
|
24098 |
|
24099 |
|
24100 |
|
24101 | ;
|
24102 |
|
24103 | _proto.canChangeType = function canChangeType() {
|
24104 | return this.constructor.canChangeType();
|
24105 | }
|
24106 | |
24107 |
|
24108 |
|
24109 |
|
24110 |
|
24111 |
|
24112 |
|
24113 |
|
24114 |
|
24115 | ;
|
24116 |
|
24117 | _proto.changeType = function changeType(type, codec) {
|
24118 | if (!this.canChangeType()) {
|
24119 | videojs__default["default"].log.error('changeType is not supported!');
|
24120 | return;
|
24121 | }
|
24122 |
|
24123 | pushQueue({
|
24124 | type: type,
|
24125 | sourceUpdater: this,
|
24126 | action: actions.changeType(codec),
|
24127 | name: 'changeType'
|
24128 | });
|
24129 | }
|
24130 | |
24131 |
|
24132 |
|
24133 |
|
24134 |
|
24135 |
|
24136 |
|
24137 | ;
|
24138 |
|
24139 | _proto.addOrChangeSourceBuffers = function addOrChangeSourceBuffers(codecs) {
|
24140 | var _this2 = this;
|
24141 |
|
24142 | if (!codecs || typeof codecs !== 'object' || Object.keys(codecs).length === 0) {
|
24143 | throw new Error('Cannot addOrChangeSourceBuffers to undefined codecs');
|
24144 | }
|
24145 |
|
24146 | Object.keys(codecs).forEach(function (type) {
|
24147 | var codec = codecs[type];
|
24148 |
|
24149 | if (!_this2.hasCreatedSourceBuffers()) {
|
24150 | return _this2.addSourceBuffer(type, codec);
|
24151 | }
|
24152 |
|
24153 | if (_this2.canChangeType()) {
|
24154 | _this2.changeType(type, codec);
|
24155 | }
|
24156 | });
|
24157 | }
|
24158 | |
24159 |
|
24160 |
|
24161 |
|
24162 |
|
24163 |
|
24164 |
|
24165 | ;
|
24166 |
|
24167 | _proto.appendBuffer = function appendBuffer(options, doneFn) {
|
24168 | var _this3 = this;
|
24169 |
|
24170 | var segmentInfo = options.segmentInfo,
|
24171 | type = options.type,
|
24172 | bytes = options.bytes;
|
24173 | this.processedAppend_ = true;
|
24174 |
|
24175 | if (type === 'audio' && this.videoBuffer && !this.videoAppendQueued_) {
|
24176 | this.delayedAudioAppendQueue_.push([options, doneFn]);
|
24177 | this.logger_("delayed audio append of " + bytes.length + " until video append");
|
24178 | return;
|
24179 | }
|
24180 |
|
24181 |
|
24182 |
|
24183 |
|
24184 |
|
24185 | var onError = doneFn;
|
24186 | pushQueue({
|
24187 | type: type,
|
24188 | sourceUpdater: this,
|
24189 | action: actions.appendBuffer(bytes, segmentInfo || {
|
24190 | mediaIndex: -1
|
24191 | }, onError),
|
24192 | doneFn: doneFn,
|
24193 | name: 'appendBuffer'
|
24194 | });
|
24195 |
|
24196 | if (type === 'video') {
|
24197 | this.videoAppendQueued_ = true;
|
24198 |
|
24199 | if (!this.delayedAudioAppendQueue_.length) {
|
24200 | return;
|
24201 | }
|
24202 |
|
24203 | var queue = this.delayedAudioAppendQueue_.slice();
|
24204 | this.logger_("queuing delayed audio " + queue.length + " appendBuffers");
|
24205 | this.delayedAudioAppendQueue_.length = 0;
|
24206 | queue.forEach(function (que) {
|
24207 | _this3.appendBuffer.apply(_this3, que);
|
24208 | });
|
24209 | }
|
24210 | }
|
24211 | |
24212 |
|
24213 |
|
24214 |
|
24215 |
|
24216 |
|
24217 | ;
|
24218 |
|
24219 | _proto.audioBuffered = function audioBuffered() {
|
24220 |
|
24221 |
|
24222 | if (!inSourceBuffers(this.mediaSource, this.audioBuffer)) {
|
24223 | return videojs__default["default"].createTimeRange();
|
24224 | }
|
24225 |
|
24226 | return this.audioBuffer.buffered ? this.audioBuffer.buffered : videojs__default["default"].createTimeRange();
|
24227 | }
|
24228 | |
24229 |
|
24230 |
|
24231 |
|
24232 |
|
24233 |
|
24234 | ;
|
24235 |
|
24236 | _proto.videoBuffered = function videoBuffered() {
|
24237 |
|
24238 |
|
24239 | if (!inSourceBuffers(this.mediaSource, this.videoBuffer)) {
|
24240 | return videojs__default["default"].createTimeRange();
|
24241 | }
|
24242 |
|
24243 | return this.videoBuffer.buffered ? this.videoBuffer.buffered : videojs__default["default"].createTimeRange();
|
24244 | }
|
24245 | |
24246 |
|
24247 |
|
24248 |
|
24249 |
|
24250 |
|
24251 | ;
|
24252 |
|
24253 | _proto.buffered = function buffered() {
|
24254 | var video = inSourceBuffers(this.mediaSource, this.videoBuffer) ? this.videoBuffer : null;
|
24255 | var audio = inSourceBuffers(this.mediaSource, this.audioBuffer) ? this.audioBuffer : null;
|
24256 |
|
24257 | if (audio && !video) {
|
24258 | return this.audioBuffered();
|
24259 | }
|
24260 |
|
24261 | if (video && !audio) {
|
24262 | return this.videoBuffered();
|
24263 | }
|
24264 |
|
24265 | return bufferIntersection(this.audioBuffered(), this.videoBuffered());
|
24266 | }
|
24267 | |
24268 |
|
24269 |
|
24270 |
|
24271 |
|
24272 |
|
24273 |
|
24274 |
|
24275 |
|
24276 | ;
|
24277 |
|
24278 | _proto.setDuration = function setDuration(duration, doneFn) {
|
24279 | if (doneFn === void 0) {
|
24280 | doneFn = noop;
|
24281 | }
|
24282 |
|
24283 |
|
24284 |
|
24285 |
|
24286 |
|
24287 | pushQueue({
|
24288 | type: 'mediaSource',
|
24289 | sourceUpdater: this,
|
24290 | action: actions.duration(duration),
|
24291 | name: 'duration',
|
24292 | doneFn: doneFn
|
24293 | });
|
24294 | }
|
24295 | |
24296 |
|
24297 |
|
24298 |
|
24299 |
|
24300 |
|
24301 |
|
24302 |
|
24303 |
|
24304 |
|
24305 | ;
|
24306 |
|
24307 | _proto.endOfStream = function endOfStream(error, doneFn) {
|
24308 | if (error === void 0) {
|
24309 | error = null;
|
24310 | }
|
24311 |
|
24312 | if (doneFn === void 0) {
|
24313 | doneFn = noop;
|
24314 | }
|
24315 |
|
24316 | if (typeof error !== 'string') {
|
24317 | error = undefined;
|
24318 | }
|
24319 |
|
24320 |
|
24321 |
|
24322 |
|
24323 |
|
24324 | pushQueue({
|
24325 | type: 'mediaSource',
|
24326 | sourceUpdater: this,
|
24327 | action: actions.endOfStream(error),
|
24328 | name: 'endOfStream',
|
24329 | doneFn: doneFn
|
24330 | });
|
24331 | }
|
24332 | |
24333 |
|
24334 |
|
24335 |
|
24336 |
|
24337 |
|
24338 |
|
24339 |
|
24340 |
|
24341 | ;
|
24342 |
|
24343 | _proto.removeAudio = function removeAudio(start, end, done) {
|
24344 | if (done === void 0) {
|
24345 | done = noop;
|
24346 | }
|
24347 |
|
24348 | if (!this.audioBuffered().length || this.audioBuffered().end(0) === 0) {
|
24349 | done();
|
24350 | return;
|
24351 | }
|
24352 |
|
24353 | pushQueue({
|
24354 | type: 'audio',
|
24355 | sourceUpdater: this,
|
24356 | action: actions.remove(start, end),
|
24357 | doneFn: done,
|
24358 | name: 'remove'
|
24359 | });
|
24360 | }
|
24361 | |
24362 |
|
24363 |
|
24364 |
|
24365 |
|
24366 |
|
24367 |
|
24368 |
|
24369 |
|
24370 | ;
|
24371 |
|
24372 | _proto.removeVideo = function removeVideo(start, end, done) {
|
24373 | if (done === void 0) {
|
24374 | done = noop;
|
24375 | }
|
24376 |
|
24377 | if (!this.videoBuffered().length || this.videoBuffered().end(0) === 0) {
|
24378 | done();
|
24379 | return;
|
24380 | }
|
24381 |
|
24382 | pushQueue({
|
24383 | type: 'video',
|
24384 | sourceUpdater: this,
|
24385 | action: actions.remove(start, end),
|
24386 | doneFn: done,
|
24387 | name: 'remove'
|
24388 | });
|
24389 | }
|
24390 | |
24391 |
|
24392 |
|
24393 |
|
24394 |
|
24395 | ;
|
24396 |
|
24397 | _proto.updating = function updating() {
|
24398 |
|
24399 | if (_updating('audio', this) || _updating('video', this)) {
|
24400 | return true;
|
24401 | }
|
24402 |
|
24403 | return false;
|
24404 | }
|
24405 | |
24406 |
|
24407 |
|
24408 |
|
24409 |
|
24410 | ;
|
24411 |
|
24412 | _proto.audioTimestampOffset = function audioTimestampOffset(offset) {
|
24413 | if (typeof offset !== 'undefined' && this.audioBuffer &&
|
24414 | this.audioTimestampOffset_ !== offset) {
|
24415 | pushQueue({
|
24416 | type: 'audio',
|
24417 | sourceUpdater: this,
|
24418 | action: actions.timestampOffset(offset),
|
24419 | name: 'timestampOffset'
|
24420 | });
|
24421 | this.audioTimestampOffset_ = offset;
|
24422 | }
|
24423 |
|
24424 | return this.audioTimestampOffset_;
|
24425 | }
|
24426 | |
24427 |
|
24428 |
|
24429 |
|
24430 |
|
24431 | ;
|
24432 |
|
24433 | _proto.videoTimestampOffset = function videoTimestampOffset(offset) {
|
24434 | if (typeof offset !== 'undefined' && this.videoBuffer &&
|
24435 | this.videoTimestampOffset !== offset) {
|
24436 | pushQueue({
|
24437 | type: 'video',
|
24438 | sourceUpdater: this,
|
24439 | action: actions.timestampOffset(offset),
|
24440 | name: 'timestampOffset'
|
24441 | });
|
24442 | this.videoTimestampOffset_ = offset;
|
24443 | }
|
24444 |
|
24445 | return this.videoTimestampOffset_;
|
24446 | }
|
24447 | |
24448 |
|
24449 |
|
24450 |
|
24451 |
|
24452 |
|
24453 |
|
24454 | ;
|
24455 |
|
24456 | _proto.audioQueueCallback = function audioQueueCallback(callback) {
|
24457 | if (!this.audioBuffer) {
|
24458 | return;
|
24459 | }
|
24460 |
|
24461 | pushQueue({
|
24462 | type: 'audio',
|
24463 | sourceUpdater: this,
|
24464 | action: actions.callback(callback),
|
24465 | name: 'callback'
|
24466 | });
|
24467 | }
|
24468 | |
24469 |
|
24470 |
|
24471 |
|
24472 |
|
24473 |
|
24474 |
|
24475 | ;
|
24476 |
|
24477 | _proto.videoQueueCallback = function videoQueueCallback(callback) {
|
24478 | if (!this.videoBuffer) {
|
24479 | return;
|
24480 | }
|
24481 |
|
24482 | pushQueue({
|
24483 | type: 'video',
|
24484 | sourceUpdater: this,
|
24485 | action: actions.callback(callback),
|
24486 | name: 'callback'
|
24487 | });
|
24488 | }
|
24489 | |
24490 |
|
24491 |
|
24492 | ;
|
24493 |
|
24494 | _proto.dispose = function dispose() {
|
24495 | var _this4 = this;
|
24496 |
|
24497 | this.trigger('dispose');
|
24498 | bufferTypes.forEach(function (type) {
|
24499 | _this4.abort(type);
|
24500 |
|
24501 | if (_this4.canRemoveSourceBuffer()) {
|
24502 | _this4.removeSourceBuffer(type);
|
24503 | } else {
|
24504 | _this4[type + "QueueCallback"](function () {
|
24505 | return cleanupBuffer(type, _this4);
|
24506 | });
|
24507 | }
|
24508 | });
|
24509 | this.videoAppendQueued_ = false;
|
24510 | this.delayedAudioAppendQueue_.length = 0;
|
24511 |
|
24512 | if (this.sourceopenListener_) {
|
24513 | this.mediaSource.removeEventListener('sourceopen', this.sourceopenListener_);
|
24514 | }
|
24515 |
|
24516 | this.off();
|
24517 | };
|
24518 |
|
24519 | return SourceUpdater;
|
24520 | }(videojs__default["default"].EventTarget);
|
24521 |
|
24522 | var uint8ToUtf8 = function uint8ToUtf8(uintArray) {
|
24523 | return decodeURIComponent(escape(String.fromCharCode.apply(null, uintArray)));
|
24524 | };
|
24525 |
|
24526 | var VTT_LINE_TERMINATORS = new Uint8Array('\n\n'.split('').map(function (char) {
|
24527 | return char.charCodeAt(0);
|
24528 | }));
|
24529 | |
24530 |
|
24531 |
|
24532 |
|
24533 |
|
24534 |
|
24535 |
|
24536 |
|
24537 | var VTTSegmentLoader = function (_SegmentLoader) {
|
24538 | inheritsLoose(VTTSegmentLoader, _SegmentLoader);
|
24539 |
|
24540 | function VTTSegmentLoader(settings, options) {
|
24541 | var _this;
|
24542 |
|
24543 | if (options === void 0) {
|
24544 | options = {};
|
24545 | }
|
24546 |
|
24547 | _this = _SegmentLoader.call(this, settings, options) || this;
|
24548 |
|
24549 |
|
24550 | _this.mediaSource_ = null;
|
24551 | _this.subtitlesTrack_ = null;
|
24552 | _this.loaderType_ = 'subtitle';
|
24553 | _this.featuresNativeTextTracks_ = settings.featuresNativeTextTracks;
|
24554 |
|
24555 |
|
24556 | _this.shouldSaveSegmentTimingInfo_ = false;
|
24557 | return _this;
|
24558 | }
|
24559 |
|
24560 | var _proto = VTTSegmentLoader.prototype;
|
24561 |
|
24562 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
24563 |
|
24564 | return null;
|
24565 | }
|
24566 | |
24567 |
|
24568 |
|
24569 |
|
24570 |
|
24571 |
|
24572 | ;
|
24573 |
|
24574 | _proto.buffered_ = function buffered_() {
|
24575 | if (!this.subtitlesTrack_ || !this.subtitlesTrack_.cues || !this.subtitlesTrack_.cues.length) {
|
24576 | return videojs__default["default"].createTimeRanges();
|
24577 | }
|
24578 |
|
24579 | var cues = this.subtitlesTrack_.cues;
|
24580 | var start = cues[0].startTime;
|
24581 | var end = cues[cues.length - 1].startTime;
|
24582 | return videojs__default["default"].createTimeRanges([[start, end]]);
|
24583 | }
|
24584 | |
24585 |
|
24586 |
|
24587 |
|
24588 |
|
24589 |
|
24590 |
|
24591 |
|
24592 |
|
24593 |
|
24594 | ;
|
24595 |
|
24596 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
24597 | if (set === void 0) {
|
24598 | set = false;
|
24599 | }
|
24600 |
|
24601 | if (!map) {
|
24602 | return null;
|
24603 | }
|
24604 |
|
24605 | var id = initSegmentId(map);
|
24606 | var storedMap = this.initSegments_[id];
|
24607 |
|
24608 | if (set && !storedMap && map.bytes) {
|
24609 |
|
24610 |
|
24611 |
|
24612 |
|
24613 | var combinedByteLength = VTT_LINE_TERMINATORS.byteLength + map.bytes.byteLength;
|
24614 | var combinedSegment = new Uint8Array(combinedByteLength);
|
24615 | combinedSegment.set(map.bytes);
|
24616 | combinedSegment.set(VTT_LINE_TERMINATORS, map.bytes.byteLength);
|
24617 | this.initSegments_[id] = storedMap = {
|
24618 | resolvedUri: map.resolvedUri,
|
24619 | byterange: map.byterange,
|
24620 | bytes: combinedSegment
|
24621 | };
|
24622 | }
|
24623 |
|
24624 | return storedMap || map;
|
24625 | }
|
24626 | |
24627 |
|
24628 |
|
24629 |
|
24630 |
|
24631 |
|
24632 | ;
|
24633 |
|
24634 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
24635 | return this.playlist_ && this.subtitlesTrack_ && !this.paused();
|
24636 | }
|
24637 | |
24638 |
|
24639 |
|
24640 |
|
24641 |
|
24642 |
|
24643 |
|
24644 | ;
|
24645 |
|
24646 | _proto.init_ = function init_() {
|
24647 | this.state = 'READY';
|
24648 | this.resetEverything();
|
24649 | return this.monitorBuffer_();
|
24650 | }
|
24651 | |
24652 |
|
24653 |
|
24654 |
|
24655 |
|
24656 |
|
24657 |
|
24658 |
|
24659 | ;
|
24660 |
|
24661 | _proto.track = function track(_track) {
|
24662 | if (typeof _track === 'undefined') {
|
24663 | return this.subtitlesTrack_;
|
24664 | }
|
24665 |
|
24666 | this.subtitlesTrack_ = _track;
|
24667 |
|
24668 |
|
24669 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
24670 | this.init_();
|
24671 | }
|
24672 |
|
24673 | return this.subtitlesTrack_;
|
24674 | }
|
24675 | |
24676 |
|
24677 |
|
24678 |
|
24679 |
|
24680 |
|
24681 | ;
|
24682 |
|
24683 | _proto.remove = function remove(start, end) {
|
24684 | removeCuesFromTrack(start, end, this.subtitlesTrack_);
|
24685 | }
|
24686 | |
24687 |
|
24688 |
|
24689 |
|
24690 |
|
24691 |
|
24692 |
|
24693 |
|
24694 |
|
24695 | ;
|
24696 |
|
24697 | _proto.fillBuffer_ = function fillBuffer_() {
|
24698 | var _this2 = this;
|
24699 |
|
24700 |
|
24701 | var segmentInfo = this.chooseNextRequest_();
|
24702 |
|
24703 | if (!segmentInfo) {
|
24704 | return;
|
24705 | }
|
24706 |
|
24707 | if (this.syncController_.timestampOffsetForTimeline(segmentInfo.timeline) === null) {
|
24708 |
|
24709 |
|
24710 | var checkTimestampOffset = function checkTimestampOffset() {
|
24711 | _this2.state = 'READY';
|
24712 |
|
24713 | if (!_this2.paused()) {
|
24714 |
|
24715 | _this2.monitorBuffer_();
|
24716 | }
|
24717 | };
|
24718 |
|
24719 | this.syncController_.one('timestampoffset', checkTimestampOffset);
|
24720 | this.state = 'WAITING_ON_TIMELINE';
|
24721 | return;
|
24722 | }
|
24723 |
|
24724 | this.loadSegment_(segmentInfo);
|
24725 | }
|
24726 | ;
|
24727 |
|
24728 | _proto.timestampOffsetForSegment_ = function timestampOffsetForSegment_() {
|
24729 | return null;
|
24730 | };
|
24731 |
|
24732 | _proto.chooseNextRequest_ = function chooseNextRequest_() {
|
24733 | return this.skipEmptySegments_(_SegmentLoader.prototype.chooseNextRequest_.call(this));
|
24734 | }
|
24735 | |
24736 |
|
24737 |
|
24738 |
|
24739 |
|
24740 |
|
24741 |
|
24742 |
|
24743 |
|
24744 |
|
24745 | ;
|
24746 |
|
24747 | _proto.skipEmptySegments_ = function skipEmptySegments_(segmentInfo) {
|
24748 | while (segmentInfo && segmentInfo.segment.empty) {
|
24749 |
|
24750 | if (segmentInfo.mediaIndex + 1 >= segmentInfo.playlist.segments.length) {
|
24751 | segmentInfo = null;
|
24752 | break;
|
24753 | }
|
24754 |
|
24755 | segmentInfo = this.generateSegmentInfo_({
|
24756 | playlist: segmentInfo.playlist,
|
24757 | mediaIndex: segmentInfo.mediaIndex + 1,
|
24758 | startOfSegment: segmentInfo.startOfSegment + segmentInfo.duration,
|
24759 | isSyncRequest: segmentInfo.isSyncRequest
|
24760 | });
|
24761 | }
|
24762 |
|
24763 | return segmentInfo;
|
24764 | };
|
24765 |
|
24766 | _proto.stopForError = function stopForError(error) {
|
24767 | this.error(error);
|
24768 | this.state = 'READY';
|
24769 | this.pause();
|
24770 | this.trigger('error');
|
24771 | }
|
24772 | |
24773 |
|
24774 |
|
24775 |
|
24776 |
|
24777 | ;
|
24778 |
|
24779 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
24780 | var _this3 = this;
|
24781 |
|
24782 | if (!this.subtitlesTrack_) {
|
24783 | this.state = 'READY';
|
24784 | return;
|
24785 | }
|
24786 |
|
24787 | this.saveTransferStats_(simpleSegment.stats);
|
24788 |
|
24789 | if (!this.pendingSegment_) {
|
24790 | this.state = 'READY';
|
24791 | this.mediaRequestsAborted += 1;
|
24792 | return;
|
24793 | }
|
24794 |
|
24795 | if (error) {
|
24796 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
24797 | this.handleTimeout_();
|
24798 | }
|
24799 |
|
24800 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
24801 | this.mediaRequestsAborted += 1;
|
24802 | } else {
|
24803 | this.mediaRequestsErrored += 1;
|
24804 | }
|
24805 |
|
24806 | this.stopForError(error);
|
24807 | return;
|
24808 | }
|
24809 |
|
24810 | var segmentInfo = this.pendingSegment_;
|
24811 |
|
24812 |
|
24813 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
24814 | this.state = 'APPENDING';
|
24815 |
|
24816 | this.trigger('appending');
|
24817 | var segment = segmentInfo.segment;
|
24818 |
|
24819 | if (segment.map) {
|
24820 | segment.map.bytes = simpleSegment.map.bytes;
|
24821 | }
|
24822 |
|
24823 | segmentInfo.bytes = simpleSegment.bytes;
|
24824 |
|
24825 | if (typeof window.WebVTT !== 'function' && this.subtitlesTrack_ && this.subtitlesTrack_.tech_) {
|
24826 | var loadHandler;
|
24827 |
|
24828 | var errorHandler = function errorHandler() {
|
24829 | _this3.subtitlesTrack_.tech_.off('vttjsloaded', loadHandler);
|
24830 |
|
24831 | _this3.stopForError({
|
24832 | message: 'Error loading vtt.js'
|
24833 | });
|
24834 |
|
24835 | return;
|
24836 | };
|
24837 |
|
24838 | loadHandler = function loadHandler() {
|
24839 | _this3.subtitlesTrack_.tech_.off('vttjserror', errorHandler);
|
24840 |
|
24841 | _this3.segmentRequestFinished_(error, simpleSegment, result);
|
24842 | };
|
24843 |
|
24844 | this.state = 'WAITING_ON_VTTJS';
|
24845 | this.subtitlesTrack_.tech_.one('vttjsloaded', loadHandler);
|
24846 | this.subtitlesTrack_.tech_.one('vttjserror', errorHandler);
|
24847 | return;
|
24848 | }
|
24849 |
|
24850 | segment.requested = true;
|
24851 |
|
24852 | try {
|
24853 | this.parseVTTCues_(segmentInfo);
|
24854 | } catch (e) {
|
24855 | this.stopForError({
|
24856 | message: e.message
|
24857 | });
|
24858 | return;
|
24859 | }
|
24860 |
|
24861 | this.updateTimeMapping_(segmentInfo, this.syncController_.timelines[segmentInfo.timeline], this.playlist_);
|
24862 |
|
24863 | if (segmentInfo.cues.length) {
|
24864 | segmentInfo.timingInfo = {
|
24865 | start: segmentInfo.cues[0].startTime,
|
24866 | end: segmentInfo.cues[segmentInfo.cues.length - 1].endTime
|
24867 | };
|
24868 | } else {
|
24869 | segmentInfo.timingInfo = {
|
24870 | start: segmentInfo.startOfSegment,
|
24871 | end: segmentInfo.startOfSegment + segmentInfo.duration
|
24872 | };
|
24873 | }
|
24874 |
|
24875 | if (segmentInfo.isSyncRequest) {
|
24876 | this.trigger('syncinfoupdate');
|
24877 | this.pendingSegment_ = null;
|
24878 | this.state = 'READY';
|
24879 | return;
|
24880 | }
|
24881 |
|
24882 | segmentInfo.byteLength = segmentInfo.bytes.byteLength;
|
24883 | this.mediaSecondsLoaded += segment.duration;
|
24884 |
|
24885 |
|
24886 | segmentInfo.cues.forEach(function (cue) {
|
24887 | _this3.subtitlesTrack_.addCue(_this3.featuresNativeTextTracks_ ? new window.VTTCue(cue.startTime, cue.endTime, cue.text) : cue);
|
24888 | });
|
24889 |
|
24890 |
|
24891 |
|
24892 |
|
24893 | removeDuplicateCuesFromTrack(this.subtitlesTrack_);
|
24894 | this.handleAppendsDone_();
|
24895 | };
|
24896 |
|
24897 | _proto.handleData_ = function handleData_() {
|
24898 |
|
24899 | };
|
24900 |
|
24901 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_() {
|
24902 | }
|
24903 | |
24904 |
|
24905 |
|
24906 |
|
24907 |
|
24908 |
|
24909 |
|
24910 | ;
|
24911 |
|
24912 | _proto.parseVTTCues_ = function parseVTTCues_(segmentInfo) {
|
24913 | var decoder;
|
24914 | var decodeBytesToString = false;
|
24915 |
|
24916 | if (typeof window.TextDecoder === 'function') {
|
24917 | decoder = new window.TextDecoder('utf8');
|
24918 | } else {
|
24919 | decoder = window.WebVTT.StringDecoder();
|
24920 | decodeBytesToString = true;
|
24921 | }
|
24922 |
|
24923 | var parser = new window.WebVTT.Parser(window, window.vttjs, decoder);
|
24924 | segmentInfo.cues = [];
|
24925 | segmentInfo.timestampmap = {
|
24926 | MPEGTS: 0,
|
24927 | LOCAL: 0
|
24928 | };
|
24929 | parser.oncue = segmentInfo.cues.push.bind(segmentInfo.cues);
|
24930 |
|
24931 | parser.ontimestampmap = function (map) {
|
24932 | segmentInfo.timestampmap = map;
|
24933 | };
|
24934 |
|
24935 | parser.onparsingerror = function (error) {
|
24936 | videojs__default["default"].log.warn('Error encountered when parsing cues: ' + error.message);
|
24937 | };
|
24938 |
|
24939 | if (segmentInfo.segment.map) {
|
24940 | var mapData = segmentInfo.segment.map.bytes;
|
24941 |
|
24942 | if (decodeBytesToString) {
|
24943 | mapData = uint8ToUtf8(mapData);
|
24944 | }
|
24945 |
|
24946 | parser.parse(mapData);
|
24947 | }
|
24948 |
|
24949 | var segmentData = segmentInfo.bytes;
|
24950 |
|
24951 | if (decodeBytesToString) {
|
24952 | segmentData = uint8ToUtf8(segmentData);
|
24953 | }
|
24954 |
|
24955 | parser.parse(segmentData);
|
24956 | parser.flush();
|
24957 | }
|
24958 | |
24959 |
|
24960 |
|
24961 |
|
24962 |
|
24963 |
|
24964 |
|
24965 |
|
24966 |
|
24967 |
|
24968 |
|
24969 |
|
24970 |
|
24971 | ;
|
24972 |
|
24973 | _proto.updateTimeMapping_ = function updateTimeMapping_(segmentInfo, mappingObj, playlist) {
|
24974 | var segment = segmentInfo.segment;
|
24975 |
|
24976 | if (!mappingObj) {
|
24977 |
|
24978 |
|
24979 |
|
24980 | return;
|
24981 | }
|
24982 |
|
24983 | if (!segmentInfo.cues.length) {
|
24984 |
|
24985 |
|
24986 |
|
24987 | segment.empty = true;
|
24988 | return;
|
24989 | }
|
24990 |
|
24991 | var timestampmap = segmentInfo.timestampmap;
|
24992 | var diff = timestampmap.MPEGTS / clock.ONE_SECOND_IN_TS - timestampmap.LOCAL + mappingObj.mapping;
|
24993 | segmentInfo.cues.forEach(function (cue) {
|
24994 |
|
24995 | cue.startTime += diff;
|
24996 | cue.endTime += diff;
|
24997 | });
|
24998 |
|
24999 | if (!playlist.syncInfo) {
|
25000 | var firstStart = segmentInfo.cues[0].startTime;
|
25001 | var lastStart = segmentInfo.cues[segmentInfo.cues.length - 1].startTime;
|
25002 | playlist.syncInfo = {
|
25003 | mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
|
25004 | time: Math.min(firstStart, lastStart - segment.duration)
|
25005 | };
|
25006 | }
|
25007 | };
|
25008 |
|
25009 | return VTTSegmentLoader;
|
25010 | }(SegmentLoader);
|
25011 |
|
25012 | |
25013 |
|
25014 |
|
25015 |
|
25016 | |
25017 |
|
25018 |
|
25019 |
|
25020 |
|
25021 |
|
25022 |
|
25023 |
|
25024 |
|
25025 |
|
25026 |
|
25027 |
|
25028 | var findAdCue = function findAdCue(track, mediaTime) {
|
25029 | var cues = track.cues;
|
25030 |
|
25031 | for (var i = 0; i < cues.length; i++) {
|
25032 | var cue = cues[i];
|
25033 |
|
25034 | if (mediaTime >= cue.adStartTime && mediaTime <= cue.adEndTime) {
|
25035 | return cue;
|
25036 | }
|
25037 | }
|
25038 |
|
25039 | return null;
|
25040 | };
|
25041 | var updateAdCues = function updateAdCues(media, track, offset) {
|
25042 | if (offset === void 0) {
|
25043 | offset = 0;
|
25044 | }
|
25045 |
|
25046 | if (!media.segments) {
|
25047 | return;
|
25048 | }
|
25049 |
|
25050 | var mediaTime = offset;
|
25051 | var cue;
|
25052 |
|
25053 | for (var i = 0; i < media.segments.length; i++) {
|
25054 | var segment = media.segments[i];
|
25055 |
|
25056 | if (!cue) {
|
25057 |
|
25058 |
|
25059 |
|
25060 |
|
25061 | cue = findAdCue(track, mediaTime + segment.duration / 2);
|
25062 | }
|
25063 |
|
25064 | if (cue) {
|
25065 | if ('cueIn' in segment) {
|
25066 |
|
25067 | cue.endTime = mediaTime;
|
25068 | cue.adEndTime = mediaTime;
|
25069 | mediaTime += segment.duration;
|
25070 | cue = null;
|
25071 | continue;
|
25072 | }
|
25073 |
|
25074 | if (mediaTime < cue.endTime) {
|
25075 |
|
25076 | mediaTime += segment.duration;
|
25077 | continue;
|
25078 | }
|
25079 |
|
25080 |
|
25081 | cue.endTime += segment.duration;
|
25082 | } else {
|
25083 | if ('cueOut' in segment) {
|
25084 | cue = new window.VTTCue(mediaTime, mediaTime + segment.duration, segment.cueOut);
|
25085 | cue.adStartTime = mediaTime;
|
25086 |
|
25087 |
|
25088 | cue.adEndTime = mediaTime + parseFloat(segment.cueOut);
|
25089 | track.addCue(cue);
|
25090 | }
|
25091 |
|
25092 | if ('cueOutCont' in segment) {
|
25093 |
|
25094 |
|
25095 |
|
25096 | var _segment$cueOutCont$s = segment.cueOutCont.split('/').map(parseFloat),
|
25097 | adOffset = _segment$cueOutCont$s[0],
|
25098 | adTotal = _segment$cueOutCont$s[1];
|
25099 |
|
25100 | cue = new window.VTTCue(mediaTime, mediaTime + segment.duration, '');
|
25101 | cue.adStartTime = mediaTime - adOffset;
|
25102 | cue.adEndTime = cue.adStartTime + adTotal;
|
25103 | track.addCue(cue);
|
25104 | }
|
25105 | }
|
25106 |
|
25107 | mediaTime += segment.duration;
|
25108 | }
|
25109 | };
|
25110 |
|
25111 |
|
25112 |
|
25113 |
|
25114 |
|
25115 |
|
25116 | var MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC = 86400;
|
25117 | var syncPointStrategies = [
|
25118 |
|
25119 | {
|
25120 | name: 'VOD',
|
25121 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
25122 | if (duration !== Infinity) {
|
25123 | var syncPoint = {
|
25124 | time: 0,
|
25125 | segmentIndex: 0,
|
25126 | partIndex: null
|
25127 | };
|
25128 | return syncPoint;
|
25129 | }
|
25130 |
|
25131 | return null;
|
25132 | }
|
25133 | },
|
25134 | {
|
25135 | name: 'ProgramDateTime',
|
25136 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
25137 | if (!Object.keys(syncController.timelineToDatetimeMappings).length) {
|
25138 | return null;
|
25139 | }
|
25140 |
|
25141 | var syncPoint = null;
|
25142 | var lastDistance = null;
|
25143 | var partsAndSegments = getPartsAndSegments(playlist);
|
25144 | currentTime = currentTime || 0;
|
25145 |
|
25146 | for (var i = 0; i < partsAndSegments.length; i++) {
|
25147 |
|
25148 |
|
25149 | var index = playlist.endList || currentTime === 0 ? i : partsAndSegments.length - (i + 1);
|
25150 | var partAndSegment = partsAndSegments[index];
|
25151 | var segment = partAndSegment.segment;
|
25152 | var datetimeMapping = syncController.timelineToDatetimeMappings[segment.timeline];
|
25153 |
|
25154 | if (!datetimeMapping) {
|
25155 | continue;
|
25156 | }
|
25157 |
|
25158 | if (segment.dateTimeObject) {
|
25159 | var segmentTime = segment.dateTimeObject.getTime() / 1000;
|
25160 | var start = segmentTime + datetimeMapping;
|
25161 |
|
25162 | if (segment.parts && typeof partAndSegment.partIndex === 'number') {
|
25163 | for (var z = 0; z < partAndSegment.partIndex; z++) {
|
25164 | start += segment.parts[z].duration;
|
25165 | }
|
25166 | }
|
25167 |
|
25168 | var distance = Math.abs(currentTime - start);
|
25169 |
|
25170 |
|
25171 | if (lastDistance !== null && (distance === 0 || lastDistance < distance)) {
|
25172 | break;
|
25173 | }
|
25174 |
|
25175 | lastDistance = distance;
|
25176 | syncPoint = {
|
25177 | time: start,
|
25178 | segmentIndex: partAndSegment.segmentIndex,
|
25179 | partIndex: partAndSegment.partIndex
|
25180 | };
|
25181 | }
|
25182 | }
|
25183 |
|
25184 | return syncPoint;
|
25185 | }
|
25186 | },
|
25187 |
|
25188 | {
|
25189 | name: 'Segment',
|
25190 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
25191 | var syncPoint = null;
|
25192 | var lastDistance = null;
|
25193 | currentTime = currentTime || 0;
|
25194 | var partsAndSegments = getPartsAndSegments(playlist);
|
25195 |
|
25196 | for (var i = 0; i < partsAndSegments.length; i++) {
|
25197 |
|
25198 |
|
25199 | var index = playlist.endList || currentTime === 0 ? i : partsAndSegments.length - (i + 1);
|
25200 | var partAndSegment = partsAndSegments[index];
|
25201 | var segment = partAndSegment.segment;
|
25202 | var start = partAndSegment.part && partAndSegment.part.start || segment && segment.start;
|
25203 |
|
25204 | if (segment.timeline === currentTimeline && typeof start !== 'undefined') {
|
25205 | var distance = Math.abs(currentTime - start);
|
25206 |
|
25207 |
|
25208 | if (lastDistance !== null && lastDistance < distance) {
|
25209 | break;
|
25210 | }
|
25211 |
|
25212 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
25213 | lastDistance = distance;
|
25214 | syncPoint = {
|
25215 | time: start,
|
25216 | segmentIndex: partAndSegment.segmentIndex,
|
25217 | partIndex: partAndSegment.partIndex
|
25218 | };
|
25219 | }
|
25220 | }
|
25221 | }
|
25222 |
|
25223 | return syncPoint;
|
25224 | }
|
25225 | },
|
25226 |
|
25227 | {
|
25228 | name: 'Discontinuity',
|
25229 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
25230 | var syncPoint = null;
|
25231 | currentTime = currentTime || 0;
|
25232 |
|
25233 | if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
25234 | var lastDistance = null;
|
25235 |
|
25236 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
25237 | var segmentIndex = playlist.discontinuityStarts[i];
|
25238 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
25239 | var discontinuitySync = syncController.discontinuities[discontinuity];
|
25240 |
|
25241 | if (discontinuitySync) {
|
25242 | var distance = Math.abs(currentTime - discontinuitySync.time);
|
25243 |
|
25244 |
|
25245 | if (lastDistance !== null && lastDistance < distance) {
|
25246 | break;
|
25247 | }
|
25248 |
|
25249 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
25250 | lastDistance = distance;
|
25251 | syncPoint = {
|
25252 | time: discontinuitySync.time,
|
25253 | segmentIndex: segmentIndex,
|
25254 | partIndex: null
|
25255 | };
|
25256 | }
|
25257 | }
|
25258 | }
|
25259 | }
|
25260 |
|
25261 | return syncPoint;
|
25262 | }
|
25263 | },
|
25264 |
|
25265 | {
|
25266 | name: 'Playlist',
|
25267 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
25268 | if (playlist.syncInfo) {
|
25269 | var syncPoint = {
|
25270 | time: playlist.syncInfo.time,
|
25271 | segmentIndex: playlist.syncInfo.mediaSequence - playlist.mediaSequence,
|
25272 | partIndex: null
|
25273 | };
|
25274 | return syncPoint;
|
25275 | }
|
25276 |
|
25277 | return null;
|
25278 | }
|
25279 | }];
|
25280 |
|
25281 | var SyncController = function (_videojs$EventTarget) {
|
25282 | inheritsLoose(SyncController, _videojs$EventTarget);
|
25283 |
|
25284 | function SyncController(options) {
|
25285 | var _this;
|
25286 |
|
25287 | _this = _videojs$EventTarget.call(this) || this;
|
25288 |
|
25289 | _this.timelines = [];
|
25290 | _this.discontinuities = [];
|
25291 | _this.timelineToDatetimeMappings = {};
|
25292 | _this.logger_ = logger('SyncController');
|
25293 | return _this;
|
25294 | }
|
25295 | |
25296 |
|
25297 |
|
25298 |
|
25299 |
|
25300 |
|
25301 |
|
25302 |
|
25303 |
|
25304 |
|
25305 |
|
25306 |
|
25307 |
|
25308 |
|
25309 |
|
25310 |
|
25311 |
|
25312 | var _proto = SyncController.prototype;
|
25313 |
|
25314 | _proto.getSyncPoint = function getSyncPoint(playlist, duration, currentTimeline, currentTime) {
|
25315 | var syncPoints = this.runStrategies_(playlist, duration, currentTimeline, currentTime);
|
25316 |
|
25317 | if (!syncPoints.length) {
|
25318 |
|
25319 |
|
25320 |
|
25321 | return null;
|
25322 | }
|
25323 |
|
25324 |
|
25325 |
|
25326 |
|
25327 | return this.selectSyncPoint_(syncPoints, {
|
25328 | key: 'time',
|
25329 | value: currentTime
|
25330 | });
|
25331 | }
|
25332 | |
25333 |
|
25334 |
|
25335 |
|
25336 |
|
25337 |
|
25338 |
|
25339 |
|
25340 |
|
25341 |
|
25342 |
|
25343 | ;
|
25344 |
|
25345 | _proto.getExpiredTime = function getExpiredTime(playlist, duration) {
|
25346 | if (!playlist || !playlist.segments) {
|
25347 | return null;
|
25348 | }
|
25349 |
|
25350 | var syncPoints = this.runStrategies_(playlist, duration, playlist.discontinuitySequence, 0);
|
25351 |
|
25352 | if (!syncPoints.length) {
|
25353 | return null;
|
25354 | }
|
25355 |
|
25356 | var syncPoint = this.selectSyncPoint_(syncPoints, {
|
25357 | key: 'segmentIndex',
|
25358 | value: 0
|
25359 | });
|
25360 |
|
25361 |
|
25362 | if (syncPoint.segmentIndex > 0) {
|
25363 | syncPoint.time *= -1;
|
25364 | }
|
25365 |
|
25366 | return Math.abs(syncPoint.time + sumDurations({
|
25367 | defaultDuration: playlist.targetDuration,
|
25368 | durationList: playlist.segments,
|
25369 | startIndex: syncPoint.segmentIndex,
|
25370 | endIndex: 0
|
25371 | }));
|
25372 | }
|
25373 | |
25374 |
|
25375 |
|
25376 |
|
25377 |
|
25378 |
|
25379 |
|
25380 |
|
25381 |
|
25382 |
|
25383 |
|
25384 |
|
25385 |
|
25386 |
|
25387 | ;
|
25388 |
|
25389 | _proto.runStrategies_ = function runStrategies_(playlist, duration, currentTimeline, currentTime) {
|
25390 | var syncPoints = [];
|
25391 |
|
25392 | for (var i = 0; i < syncPointStrategies.length; i++) {
|
25393 | var strategy = syncPointStrategies[i];
|
25394 | var syncPoint = strategy.run(this, playlist, duration, currentTimeline, currentTime);
|
25395 |
|
25396 | if (syncPoint) {
|
25397 | syncPoint.strategy = strategy.name;
|
25398 | syncPoints.push({
|
25399 | strategy: strategy.name,
|
25400 | syncPoint: syncPoint
|
25401 | });
|
25402 | }
|
25403 | }
|
25404 |
|
25405 | return syncPoints;
|
25406 | }
|
25407 | |
25408 |
|
25409 |
|
25410 |
|
25411 |
|
25412 |
|
25413 |
|
25414 |
|
25415 |
|
25416 |
|
25417 |
|
25418 |
|
25419 |
|
25420 |
|
25421 |
|
25422 | ;
|
25423 |
|
25424 | _proto.selectSyncPoint_ = function selectSyncPoint_(syncPoints, target) {
|
25425 | var bestSyncPoint = syncPoints[0].syncPoint;
|
25426 | var bestDistance = Math.abs(syncPoints[0].syncPoint[target.key] - target.value);
|
25427 | var bestStrategy = syncPoints[0].strategy;
|
25428 |
|
25429 | for (var i = 1; i < syncPoints.length; i++) {
|
25430 | var newDistance = Math.abs(syncPoints[i].syncPoint[target.key] - target.value);
|
25431 |
|
25432 | if (newDistance < bestDistance) {
|
25433 | bestDistance = newDistance;
|
25434 | bestSyncPoint = syncPoints[i].syncPoint;
|
25435 | bestStrategy = syncPoints[i].strategy;
|
25436 | }
|
25437 | }
|
25438 |
|
25439 | this.logger_("syncPoint for [" + target.key + ": " + target.value + "] chosen with strategy" + (" [" + bestStrategy + "]: [time:" + bestSyncPoint.time + ",") + (" segmentIndex:" + bestSyncPoint.segmentIndex) + (typeof bestSyncPoint.partIndex === 'number' ? ",partIndex:" + bestSyncPoint.partIndex : '') + ']');
|
25440 | return bestSyncPoint;
|
25441 | }
|
25442 | |
25443 |
|
25444 |
|
25445 |
|
25446 |
|
25447 |
|
25448 |
|
25449 |
|
25450 | ;
|
25451 |
|
25452 | _proto.saveExpiredSegmentInfo = function saveExpiredSegmentInfo(oldPlaylist, newPlaylist) {
|
25453 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
25454 |
|
25455 | if (mediaSequenceDiff > MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC) {
|
25456 | videojs__default["default"].log.warn("Not saving expired segment info. Media sequence gap " + mediaSequenceDiff + " is too large.");
|
25457 | return;
|
25458 | }
|
25459 |
|
25460 |
|
25461 |
|
25462 | for (var i = mediaSequenceDiff - 1; i >= 0; i--) {
|
25463 | var lastRemovedSegment = oldPlaylist.segments[i];
|
25464 |
|
25465 | if (lastRemovedSegment && typeof lastRemovedSegment.start !== 'undefined') {
|
25466 | newPlaylist.syncInfo = {
|
25467 | mediaSequence: oldPlaylist.mediaSequence + i,
|
25468 | time: lastRemovedSegment.start
|
25469 | };
|
25470 | this.logger_("playlist refresh sync: [time:" + newPlaylist.syncInfo.time + "," + (" mediaSequence: " + newPlaylist.syncInfo.mediaSequence + "]"));
|
25471 | this.trigger('syncinfoupdate');
|
25472 | break;
|
25473 | }
|
25474 | }
|
25475 | }
|
25476 | |
25477 |
|
25478 |
|
25479 |
|
25480 |
|
25481 |
|
25482 | ;
|
25483 |
|
25484 | _proto.setDateTimeMappingForStart = function setDateTimeMappingForStart(playlist) {
|
25485 |
|
25486 |
|
25487 |
|
25488 |
|
25489 | this.timelineToDatetimeMappings = {};
|
25490 |
|
25491 | if (playlist.segments && playlist.segments.length && playlist.segments[0].dateTimeObject) {
|
25492 | var firstSegment = playlist.segments[0];
|
25493 | var playlistTimestamp = firstSegment.dateTimeObject.getTime() / 1000;
|
25494 | this.timelineToDatetimeMappings[firstSegment.timeline] = -playlistTimestamp;
|
25495 | }
|
25496 | }
|
25497 | |
25498 |
|
25499 |
|
25500 |
|
25501 |
|
25502 |
|
25503 |
|
25504 |
|
25505 |
|
25506 |
|
25507 |
|
25508 |
|
25509 | ;
|
25510 |
|
25511 | _proto.saveSegmentTimingInfo = function saveSegmentTimingInfo(_ref) {
|
25512 | var segmentInfo = _ref.segmentInfo,
|
25513 | shouldSaveTimelineMapping = _ref.shouldSaveTimelineMapping;
|
25514 | var didCalculateSegmentTimeMapping = this.calculateSegmentTimeMapping_(segmentInfo, segmentInfo.timingInfo, shouldSaveTimelineMapping);
|
25515 | var segment = segmentInfo.segment;
|
25516 |
|
25517 | if (didCalculateSegmentTimeMapping) {
|
25518 | this.saveDiscontinuitySyncInfo_(segmentInfo);
|
25519 |
|
25520 |
|
25521 | if (!segmentInfo.playlist.syncInfo) {
|
25522 | segmentInfo.playlist.syncInfo = {
|
25523 | mediaSequence: segmentInfo.playlist.mediaSequence + segmentInfo.mediaIndex,
|
25524 | time: segment.start
|
25525 | };
|
25526 | }
|
25527 | }
|
25528 |
|
25529 | var dateTime = segment.dateTimeObject;
|
25530 |
|
25531 | if (segment.discontinuity && shouldSaveTimelineMapping && dateTime) {
|
25532 | this.timelineToDatetimeMappings[segment.timeline] = -(dateTime.getTime() / 1000);
|
25533 | }
|
25534 | };
|
25535 |
|
25536 | _proto.timestampOffsetForTimeline = function timestampOffsetForTimeline(timeline) {
|
25537 | if (typeof this.timelines[timeline] === 'undefined') {
|
25538 | return null;
|
25539 | }
|
25540 |
|
25541 | return this.timelines[timeline].time;
|
25542 | };
|
25543 |
|
25544 | _proto.mappingForTimeline = function mappingForTimeline(timeline) {
|
25545 | if (typeof this.timelines[timeline] === 'undefined') {
|
25546 | return null;
|
25547 | }
|
25548 |
|
25549 | return this.timelines[timeline].mapping;
|
25550 | }
|
25551 | |
25552 |
|
25553 |
|
25554 |
|
25555 |
|
25556 |
|
25557 |
|
25558 |
|
25559 |
|
25560 |
|
25561 |
|
25562 |
|
25563 |
|
25564 |
|
25565 |
|
25566 | ;
|
25567 |
|
25568 | _proto.calculateSegmentTimeMapping_ = function calculateSegmentTimeMapping_(segmentInfo, timingInfo, shouldSaveTimelineMapping) {
|
25569 |
|
25570 | var segment = segmentInfo.segment;
|
25571 | var part = segmentInfo.part;
|
25572 | var mappingObj = this.timelines[segmentInfo.timeline];
|
25573 | var start;
|
25574 | var end;
|
25575 |
|
25576 | if (typeof segmentInfo.timestampOffset === 'number') {
|
25577 | mappingObj = {
|
25578 | time: segmentInfo.startOfSegment,
|
25579 | mapping: segmentInfo.startOfSegment - timingInfo.start
|
25580 | };
|
25581 |
|
25582 | if (shouldSaveTimelineMapping) {
|
25583 | this.timelines[segmentInfo.timeline] = mappingObj;
|
25584 | this.trigger('timestampoffset');
|
25585 | this.logger_("time mapping for timeline " + segmentInfo.timeline + ": " + ("[time: " + mappingObj.time + "] [mapping: " + mappingObj.mapping + "]"));
|
25586 | }
|
25587 |
|
25588 | start = segmentInfo.startOfSegment;
|
25589 | end = timingInfo.end + mappingObj.mapping;
|
25590 | } else if (mappingObj) {
|
25591 | start = timingInfo.start + mappingObj.mapping;
|
25592 | end = timingInfo.end + mappingObj.mapping;
|
25593 | } else {
|
25594 | return false;
|
25595 | }
|
25596 |
|
25597 | if (part) {
|
25598 | part.start = start;
|
25599 | part.end = end;
|
25600 | }
|
25601 |
|
25602 |
|
25603 |
|
25604 |
|
25605 |
|
25606 |
|
25607 | if (!segment.start || start < segment.start) {
|
25608 | segment.start = start;
|
25609 | }
|
25610 |
|
25611 | segment.end = end;
|
25612 | return true;
|
25613 | }
|
25614 | |
25615 |
|
25616 |
|
25617 |
|
25618 |
|
25619 |
|
25620 |
|
25621 |
|
25622 | ;
|
25623 |
|
25624 | _proto.saveDiscontinuitySyncInfo_ = function saveDiscontinuitySyncInfo_(segmentInfo) {
|
25625 | var playlist = segmentInfo.playlist;
|
25626 | var segment = segmentInfo.segment;
|
25627 |
|
25628 |
|
25629 |
|
25630 | if (segment.discontinuity) {
|
25631 | this.discontinuities[segment.timeline] = {
|
25632 | time: segment.start,
|
25633 | accuracy: 0
|
25634 | };
|
25635 | } else if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
25636 |
|
25637 |
|
25638 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
25639 | var segmentIndex = playlist.discontinuityStarts[i];
|
25640 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
25641 | var mediaIndexDiff = segmentIndex - segmentInfo.mediaIndex;
|
25642 | var accuracy = Math.abs(mediaIndexDiff);
|
25643 |
|
25644 | if (!this.discontinuities[discontinuity] || this.discontinuities[discontinuity].accuracy > accuracy) {
|
25645 | var time = void 0;
|
25646 |
|
25647 | if (mediaIndexDiff < 0) {
|
25648 | time = segment.start - sumDurations({
|
25649 | defaultDuration: playlist.targetDuration,
|
25650 | durationList: playlist.segments,
|
25651 | startIndex: segmentInfo.mediaIndex,
|
25652 | endIndex: segmentIndex
|
25653 | });
|
25654 | } else {
|
25655 | time = segment.end + sumDurations({
|
25656 | defaultDuration: playlist.targetDuration,
|
25657 | durationList: playlist.segments,
|
25658 | startIndex: segmentInfo.mediaIndex + 1,
|
25659 | endIndex: segmentIndex
|
25660 | });
|
25661 | }
|
25662 |
|
25663 | this.discontinuities[discontinuity] = {
|
25664 | time: time,
|
25665 | accuracy: accuracy
|
25666 | };
|
25667 | }
|
25668 | }
|
25669 | }
|
25670 | };
|
25671 |
|
25672 | _proto.dispose = function dispose() {
|
25673 | this.trigger('dispose');
|
25674 | this.off();
|
25675 | };
|
25676 |
|
25677 | return SyncController;
|
25678 | }(videojs__default["default"].EventTarget);
|
25679 |
|
25680 | |
25681 |
|
25682 |
|
25683 |
|
25684 |
|
25685 |
|
25686 |
|
25687 |
|
25688 |
|
25689 |
|
25690 | var TimelineChangeController = function (_videojs$EventTarget) {
|
25691 | inheritsLoose(TimelineChangeController, _videojs$EventTarget);
|
25692 |
|
25693 | function TimelineChangeController() {
|
25694 | var _this;
|
25695 |
|
25696 | _this = _videojs$EventTarget.call(this) || this;
|
25697 | _this.pendingTimelineChanges_ = {};
|
25698 | _this.lastTimelineChanges_ = {};
|
25699 | return _this;
|
25700 | }
|
25701 |
|
25702 | var _proto = TimelineChangeController.prototype;
|
25703 |
|
25704 | _proto.clearPendingTimelineChange = function clearPendingTimelineChange(type) {
|
25705 | this.pendingTimelineChanges_[type] = null;
|
25706 | this.trigger('pendingtimelinechange');
|
25707 | };
|
25708 |
|
25709 | _proto.pendingTimelineChange = function pendingTimelineChange(_ref) {
|
25710 | var type = _ref.type,
|
25711 | from = _ref.from,
|
25712 | to = _ref.to;
|
25713 |
|
25714 | if (typeof from === 'number' && typeof to === 'number') {
|
25715 | this.pendingTimelineChanges_[type] = {
|
25716 | type: type,
|
25717 | from: from,
|
25718 | to: to
|
25719 | };
|
25720 | this.trigger('pendingtimelinechange');
|
25721 | }
|
25722 |
|
25723 | return this.pendingTimelineChanges_[type];
|
25724 | };
|
25725 |
|
25726 | _proto.lastTimelineChange = function lastTimelineChange(_ref2) {
|
25727 | var type = _ref2.type,
|
25728 | from = _ref2.from,
|
25729 | to = _ref2.to;
|
25730 |
|
25731 | if (typeof from === 'number' && typeof to === 'number') {
|
25732 | this.lastTimelineChanges_[type] = {
|
25733 | type: type,
|
25734 | from: from,
|
25735 | to: to
|
25736 | };
|
25737 | delete this.pendingTimelineChanges_[type];
|
25738 | this.trigger('timelinechange');
|
25739 | }
|
25740 |
|
25741 | return this.lastTimelineChanges_[type];
|
25742 | };
|
25743 |
|
25744 | _proto.dispose = function dispose() {
|
25745 | this.trigger('dispose');
|
25746 | this.pendingTimelineChanges_ = {};
|
25747 | this.lastTimelineChanges_ = {};
|
25748 | this.off();
|
25749 | };
|
25750 |
|
25751 | return TimelineChangeController;
|
25752 | }(videojs__default["default"].EventTarget);
|
25753 |
|
25754 |
|
25755 | var workerCode = transform(getWorkerString(function () {
|
25756 |
|
25757 | function createCommonjsModule(fn, basedir, module) {
|
25758 | return module = {
|
25759 | path: basedir,
|
25760 | exports: {},
|
25761 | require: function require(path, base) {
|
25762 | return commonjsRequire(path, base === undefined || base === null ? module.path : base);
|
25763 | }
|
25764 | }, fn(module, module.exports), module.exports;
|
25765 | }
|
25766 |
|
25767 | function commonjsRequire() {
|
25768 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
25769 | }
|
25770 |
|
25771 | var createClass = createCommonjsModule(function (module) {
|
25772 | function _defineProperties(target, props) {
|
25773 | for (var i = 0; i < props.length; i++) {
|
25774 | var descriptor = props[i];
|
25775 | descriptor.enumerable = descriptor.enumerable || false;
|
25776 | descriptor.configurable = true;
|
25777 | if ("value" in descriptor) descriptor.writable = true;
|
25778 | Object.defineProperty(target, descriptor.key, descriptor);
|
25779 | }
|
25780 | }
|
25781 |
|
25782 | function _createClass(Constructor, protoProps, staticProps) {
|
25783 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
25784 | if (staticProps) _defineProperties(Constructor, staticProps);
|
25785 | return Constructor;
|
25786 | }
|
25787 |
|
25788 | module.exports = _createClass;
|
25789 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
25790 | });
|
25791 | var setPrototypeOf = createCommonjsModule(function (module) {
|
25792 | function _setPrototypeOf(o, p) {
|
25793 | module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
25794 | o.__proto__ = p;
|
25795 | return o;
|
25796 | };
|
25797 |
|
25798 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
25799 | return _setPrototypeOf(o, p);
|
25800 | }
|
25801 |
|
25802 | module.exports = _setPrototypeOf;
|
25803 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
25804 | });
|
25805 | var inheritsLoose = createCommonjsModule(function (module) {
|
25806 | function _inheritsLoose(subClass, superClass) {
|
25807 | subClass.prototype = Object.create(superClass.prototype);
|
25808 | subClass.prototype.constructor = subClass;
|
25809 | setPrototypeOf(subClass, superClass);
|
25810 | }
|
25811 |
|
25812 | module.exports = _inheritsLoose;
|
25813 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
25814 | });
|
25815 | |
25816 |
|
25817 |
|
25818 |
|
25819 | |
25820 |
|
25821 |
|
25822 |
|
25823 |
|
25824 |
|
25825 | var Stream = function () {
|
25826 | function Stream() {
|
25827 | this.listeners = {};
|
25828 | }
|
25829 | |
25830 |
|
25831 |
|
25832 |
|
25833 |
|
25834 |
|
25835 |
|
25836 |
|
25837 |
|
25838 | var _proto = Stream.prototype;
|
25839 |
|
25840 | _proto.on = function on(type, listener) {
|
25841 | if (!this.listeners[type]) {
|
25842 | this.listeners[type] = [];
|
25843 | }
|
25844 |
|
25845 | this.listeners[type].push(listener);
|
25846 | }
|
25847 | |
25848 |
|
25849 |
|
25850 |
|
25851 |
|
25852 |
|
25853 |
|
25854 |
|
25855 | ;
|
25856 |
|
25857 | _proto.off = function off(type, listener) {
|
25858 | if (!this.listeners[type]) {
|
25859 | return false;
|
25860 | }
|
25861 |
|
25862 | var index = this.listeners[type].indexOf(listener);
|
25863 |
|
25864 |
|
25865 |
|
25866 |
|
25867 |
|
25868 |
|
25869 |
|
25870 |
|
25871 | this.listeners[type] = this.listeners[type].slice(0);
|
25872 | this.listeners[type].splice(index, 1);
|
25873 | return index > -1;
|
25874 | }
|
25875 | |
25876 |
|
25877 |
|
25878 |
|
25879 |
|
25880 |
|
25881 | ;
|
25882 |
|
25883 | _proto.trigger = function trigger(type) {
|
25884 | var callbacks = this.listeners[type];
|
25885 |
|
25886 | if (!callbacks) {
|
25887 | return;
|
25888 | }
|
25889 |
|
25890 |
|
25891 |
|
25892 |
|
25893 |
|
25894 | if (arguments.length === 2) {
|
25895 | var length = callbacks.length;
|
25896 |
|
25897 | for (var i = 0; i < length; ++i) {
|
25898 | callbacks[i].call(this, arguments[1]);
|
25899 | }
|
25900 | } else {
|
25901 | var args = Array.prototype.slice.call(arguments, 1);
|
25902 | var _length = callbacks.length;
|
25903 |
|
25904 | for (var _i = 0; _i < _length; ++_i) {
|
25905 | callbacks[_i].apply(this, args);
|
25906 | }
|
25907 | }
|
25908 | }
|
25909 | |
25910 |
|
25911 |
|
25912 | ;
|
25913 |
|
25914 | _proto.dispose = function dispose() {
|
25915 | this.listeners = {};
|
25916 | }
|
25917 | |
25918 |
|
25919 |
|
25920 |
|
25921 |
|
25922 |
|
25923 |
|
25924 |
|
25925 | ;
|
25926 |
|
25927 | _proto.pipe = function pipe(destination) {
|
25928 | this.on('data', function (data) {
|
25929 | destination.push(data);
|
25930 | });
|
25931 | };
|
25932 |
|
25933 | return Stream;
|
25934 | }();
|
25935 |
|
25936 |
|
25937 | |
25938 |
|
25939 |
|
25940 |
|
25941 |
|
25942 |
|
25943 |
|
25944 |
|
25945 |
|
25946 | function unpad(padded) {
|
25947 | return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
|
25948 | }
|
25949 |
|
25950 |
|
25951 | |
25952 |
|
25953 |
|
25954 |
|
25955 |
|
25956 |
|
25957 |
|
25958 |
|
25959 |
|
25960 |
|
25961 |
|
25962 |
|
25963 |
|
25964 |
|
25965 |
|
25966 |
|
25967 |
|
25968 |
|
25969 |
|
25970 |
|
25971 |
|
25972 |
|
25973 |
|
25974 |
|
25975 |
|
25976 |
|
25977 |
|
25978 |
|
25979 |
|
25980 |
|
25981 |
|
25982 |
|
25983 |
|
25984 |
|
25985 |
|
25986 |
|
25987 |
|
25988 |
|
25989 |
|
25990 | |
25991 |
|
25992 |
|
25993 |
|
25994 |
|
25995 |
|
25996 |
|
25997 | var precompute = function precompute() {
|
25998 | var tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
25999 | var encTable = tables[0];
|
26000 | var decTable = tables[1];
|
26001 | var sbox = encTable[4];
|
26002 | var sboxInv = decTable[4];
|
26003 | var i;
|
26004 | var x;
|
26005 | var xInv;
|
26006 | var d = [];
|
26007 | var th = [];
|
26008 | var x2;
|
26009 | var x4;
|
26010 | var x8;
|
26011 | var s;
|
26012 | var tEnc;
|
26013 | var tDec;
|
26014 |
|
26015 | for (i = 0; i < 256; i++) {
|
26016 | th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
26017 | }
|
26018 |
|
26019 | for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
26020 |
|
26021 | s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
26022 | s = s >> 8 ^ s & 255 ^ 99;
|
26023 | sbox[x] = s;
|
26024 | sboxInv[s] = x;
|
26025 |
|
26026 | x8 = d[x4 = d[x2 = d[x]]];
|
26027 | tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
26028 | tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
26029 |
|
26030 | for (i = 0; i < 4; i++) {
|
26031 | encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
26032 | decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
26033 | }
|
26034 | }
|
26035 |
|
26036 |
|
26037 | for (i = 0; i < 5; i++) {
|
26038 | encTable[i] = encTable[i].slice(0);
|
26039 | decTable[i] = decTable[i].slice(0);
|
26040 | }
|
26041 |
|
26042 | return tables;
|
26043 | };
|
26044 |
|
26045 | var aesTables = null;
|
26046 | |
26047 |
|
26048 |
|
26049 |
|
26050 |
|
26051 |
|
26052 |
|
26053 |
|
26054 | var AES = function () {
|
26055 | function AES(key) {
|
26056 | |
26057 |
|
26058 |
|
26059 |
|
26060 |
|
26061 |
|
26062 |
|
26063 |
|
26064 |
|
26065 |
|
26066 |
|
26067 |
|
26068 |
|
26069 |
|
26070 | if (!aesTables) {
|
26071 | aesTables = precompute();
|
26072 | }
|
26073 |
|
26074 |
|
26075 | this._tables = [[aesTables[0][0].slice(), aesTables[0][1].slice(), aesTables[0][2].slice(), aesTables[0][3].slice(), aesTables[0][4].slice()], [aesTables[1][0].slice(), aesTables[1][1].slice(), aesTables[1][2].slice(), aesTables[1][3].slice(), aesTables[1][4].slice()]];
|
26076 | var i;
|
26077 | var j;
|
26078 | var tmp;
|
26079 | var sbox = this._tables[0][4];
|
26080 | var decTable = this._tables[1];
|
26081 | var keyLen = key.length;
|
26082 | var rcon = 1;
|
26083 |
|
26084 | if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
26085 | throw new Error('Invalid aes key size');
|
26086 | }
|
26087 |
|
26088 | var encKey = key.slice(0);
|
26089 | var decKey = [];
|
26090 | this._key = [encKey, decKey];
|
26091 |
|
26092 | for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
26093 | tmp = encKey[i - 1];
|
26094 |
|
26095 | if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
|
26096 | tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
26097 |
|
26098 | if (i % keyLen === 0) {
|
26099 | tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
26100 | rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
26101 | }
|
26102 | }
|
26103 |
|
26104 | encKey[i] = encKey[i - keyLen] ^ tmp;
|
26105 | }
|
26106 |
|
26107 |
|
26108 | for (j = 0; i; j++, i--) {
|
26109 | tmp = encKey[j & 3 ? i : i - 4];
|
26110 |
|
26111 | if (i <= 4 || j < 4) {
|
26112 | decKey[j] = tmp;
|
26113 | } else {
|
26114 | decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
|
26115 | }
|
26116 | }
|
26117 | }
|
26118 | |
26119 |
|
26120 |
|
26121 |
|
26122 |
|
26123 |
|
26124 |
|
26125 |
|
26126 |
|
26127 |
|
26128 |
|
26129 |
|
26130 |
|
26131 |
|
26132 |
|
26133 | var _proto = AES.prototype;
|
26134 |
|
26135 | _proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
|
26136 | var key = this._key[1];
|
26137 |
|
26138 | var a = encrypted0 ^ key[0];
|
26139 | var b = encrypted3 ^ key[1];
|
26140 | var c = encrypted2 ^ key[2];
|
26141 | var d = encrypted1 ^ key[3];
|
26142 | var a2;
|
26143 | var b2;
|
26144 | var c2;
|
26145 |
|
26146 | var nInnerRounds = key.length / 4 - 2;
|
26147 | var i;
|
26148 | var kIndex = 4;
|
26149 | var table = this._tables[1];
|
26150 |
|
26151 | var table0 = table[0];
|
26152 | var table1 = table[1];
|
26153 | var table2 = table[2];
|
26154 | var table3 = table[3];
|
26155 | var sbox = table[4];
|
26156 |
|
26157 | for (i = 0; i < nInnerRounds; i++) {
|
26158 | a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
|
26159 | b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
|
26160 | c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
|
26161 | d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
|
26162 | kIndex += 4;
|
26163 | a = a2;
|
26164 | b = b2;
|
26165 | c = c2;
|
26166 | }
|
26167 |
|
26168 |
|
26169 | for (i = 0; i < 4; i++) {
|
26170 | out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
|
26171 | a2 = a;
|
26172 | a = b;
|
26173 | b = c;
|
26174 | c = d;
|
26175 | d = a2;
|
26176 | }
|
26177 | };
|
26178 |
|
26179 | return AES;
|
26180 | }();
|
26181 | |
26182 |
|
26183 |
|
26184 |
|
26185 |
|
26186 |
|
26187 |
|
26188 |
|
26189 |
|
26190 | var AsyncStream = function (_Stream) {
|
26191 | inheritsLoose(AsyncStream, _Stream);
|
26192 |
|
26193 | function AsyncStream() {
|
26194 | var _this;
|
26195 |
|
26196 | _this = _Stream.call(this, Stream) || this;
|
26197 | _this.jobs = [];
|
26198 | _this.delay = 1;
|
26199 | _this.timeout_ = null;
|
26200 | return _this;
|
26201 | }
|
26202 | |
26203 |
|
26204 |
|
26205 |
|
26206 |
|
26207 |
|
26208 |
|
26209 | var _proto = AsyncStream.prototype;
|
26210 |
|
26211 | _proto.processJob_ = function processJob_() {
|
26212 | this.jobs.shift()();
|
26213 |
|
26214 | if (this.jobs.length) {
|
26215 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
26216 | } else {
|
26217 | this.timeout_ = null;
|
26218 | }
|
26219 | }
|
26220 | |
26221 |
|
26222 |
|
26223 |
|
26224 |
|
26225 | ;
|
26226 |
|
26227 | _proto.push = function push(job) {
|
26228 | this.jobs.push(job);
|
26229 |
|
26230 | if (!this.timeout_) {
|
26231 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
26232 | }
|
26233 | };
|
26234 |
|
26235 | return AsyncStream;
|
26236 | }(Stream);
|
26237 | |
26238 |
|
26239 |
|
26240 |
|
26241 |
|
26242 |
|
26243 | var ntoh = function ntoh(word) {
|
26244 | return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
|
26245 | };
|
26246 | |
26247 |
|
26248 |
|
26249 |
|
26250 |
|
26251 |
|
26252 |
|
26253 |
|
26254 |
|
26255 |
|
26256 |
|
26257 |
|
26258 |
|
26259 |
|
26260 |
|
26261 | var decrypt = function decrypt(encrypted, key, initVector) {
|
26262 |
|
26263 | var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
|
26264 | var decipher = new AES(Array.prototype.slice.call(key));
|
26265 |
|
26266 | var decrypted = new Uint8Array(encrypted.byteLength);
|
26267 | var decrypted32 = new Int32Array(decrypted.buffer);
|
26268 |
|
26269 |
|
26270 | var init0;
|
26271 | var init1;
|
26272 | var init2;
|
26273 | var init3;
|
26274 | var encrypted0;
|
26275 | var encrypted1;
|
26276 | var encrypted2;
|
26277 | var encrypted3;
|
26278 |
|
26279 | var wordIx;
|
26280 |
|
26281 |
|
26282 | init0 = initVector[0];
|
26283 | init1 = initVector[1];
|
26284 | init2 = initVector[2];
|
26285 | init3 = initVector[3];
|
26286 |
|
26287 |
|
26288 | for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
|
26289 |
|
26290 |
|
26291 | encrypted0 = ntoh(encrypted32[wordIx]);
|
26292 | encrypted1 = ntoh(encrypted32[wordIx + 1]);
|
26293 | encrypted2 = ntoh(encrypted32[wordIx + 2]);
|
26294 | encrypted3 = ntoh(encrypted32[wordIx + 3]);
|
26295 |
|
26296 | decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
|
26297 |
|
26298 |
|
26299 | decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
|
26300 | decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
|
26301 | decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
|
26302 | decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
|
26303 |
|
26304 | init0 = encrypted0;
|
26305 | init1 = encrypted1;
|
26306 | init2 = encrypted2;
|
26307 | init3 = encrypted3;
|
26308 | }
|
26309 |
|
26310 | return decrypted;
|
26311 | };
|
26312 | |
26313 |
|
26314 |
|
26315 |
|
26316 |
|
26317 |
|
26318 |
|
26319 |
|
26320 |
|
26321 |
|
26322 |
|
26323 |
|
26324 |
|
26325 | var Decrypter = function () {
|
26326 | function Decrypter(encrypted, key, initVector, done) {
|
26327 | var step = Decrypter.STEP;
|
26328 | var encrypted32 = new Int32Array(encrypted.buffer);
|
26329 | var decrypted = new Uint8Array(encrypted.byteLength);
|
26330 | var i = 0;
|
26331 | this.asyncStream_ = new AsyncStream();
|
26332 |
|
26333 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
26334 |
|
26335 | for (i = step; i < encrypted32.length; i += step) {
|
26336 | initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
|
26337 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
26338 | }
|
26339 |
|
26340 |
|
26341 | this.asyncStream_.push(function () {
|
26342 |
|
26343 | done(null, unpad(decrypted));
|
26344 | });
|
26345 | }
|
26346 | |
26347 |
|
26348 |
|
26349 |
|
26350 |
|
26351 |
|
26352 |
|
26353 | var _proto = Decrypter.prototype;
|
26354 | |
26355 |
|
26356 |
|
26357 |
|
26358 | _proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
|
26359 | return function () {
|
26360 | var bytes = decrypt(encrypted, key, initVector);
|
26361 | decrypted.set(bytes, encrypted.byteOffset);
|
26362 | };
|
26363 | };
|
26364 |
|
26365 | createClass(Decrypter, null, [{
|
26366 | key: "STEP",
|
26367 | get: function get() {
|
26368 |
|
26369 | return 32000;
|
26370 | }
|
26371 | }]);
|
26372 | return Decrypter;
|
26373 | }();
|
26374 | |
26375 |
|
26376 |
|
26377 |
|
26378 | |
26379 |
|
26380 |
|
26381 |
|
26382 |
|
26383 |
|
26384 |
|
26385 |
|
26386 |
|
26387 |
|
26388 |
|
26389 |
|
26390 | var createTransferableMessage = function createTransferableMessage(message) {
|
26391 | var transferable = {};
|
26392 | Object.keys(message).forEach(function (key) {
|
26393 | var value = message[key];
|
26394 |
|
26395 | if (ArrayBuffer.isView(value)) {
|
26396 | transferable[key] = {
|
26397 | bytes: value.buffer,
|
26398 | byteOffset: value.byteOffset,
|
26399 | byteLength: value.byteLength
|
26400 | };
|
26401 | } else {
|
26402 | transferable[key] = value;
|
26403 | }
|
26404 | });
|
26405 | return transferable;
|
26406 | };
|
26407 |
|
26408 |
|
26409 | |
26410 |
|
26411 |
|
26412 |
|
26413 |
|
26414 |
|
26415 |
|
26416 | self.onmessage = function (event) {
|
26417 | var data = event.data;
|
26418 | var encrypted = new Uint8Array(data.encrypted.bytes, data.encrypted.byteOffset, data.encrypted.byteLength);
|
26419 | var key = new Uint32Array(data.key.bytes, data.key.byteOffset, data.key.byteLength / 4);
|
26420 | var iv = new Uint32Array(data.iv.bytes, data.iv.byteOffset, data.iv.byteLength / 4);
|
26421 |
|
26422 |
|
26423 | new Decrypter(encrypted, key, iv, function (err, bytes) {
|
26424 | self.postMessage(createTransferableMessage({
|
26425 | source: data.source,
|
26426 | decrypted: bytes
|
26427 | }), [bytes.buffer]);
|
26428 | });
|
26429 |
|
26430 | };
|
26431 | }));
|
26432 | var Decrypter = factory(workerCode);
|
26433 |
|
26434 |
|
26435 | |
26436 |
|
26437 |
|
26438 |
|
26439 |
|
26440 |
|
26441 | var audioTrackKind_ = function audioTrackKind_(properties) {
|
26442 | var kind = properties.default ? 'main' : 'alternative';
|
26443 |
|
26444 | if (properties.characteristics && properties.characteristics.indexOf('public.accessibility.describes-video') >= 0) {
|
26445 | kind = 'main-desc';
|
26446 | }
|
26447 |
|
26448 | return kind;
|
26449 | };
|
26450 | |
26451 |
|
26452 |
|
26453 |
|
26454 |
|
26455 |
|
26456 |
|
26457 |
|
26458 |
|
26459 |
|
26460 |
|
26461 | var stopLoaders = function stopLoaders(segmentLoader, mediaType) {
|
26462 | segmentLoader.abort();
|
26463 | segmentLoader.pause();
|
26464 |
|
26465 | if (mediaType && mediaType.activePlaylistLoader) {
|
26466 | mediaType.activePlaylistLoader.pause();
|
26467 | mediaType.activePlaylistLoader = null;
|
26468 | }
|
26469 | };
|
26470 | |
26471 |
|
26472 |
|
26473 |
|
26474 |
|
26475 |
|
26476 |
|
26477 |
|
26478 |
|
26479 |
|
26480 | var startLoaders = function startLoaders(playlistLoader, mediaType) {
|
26481 |
|
26482 |
|
26483 | mediaType.activePlaylistLoader = playlistLoader;
|
26484 | playlistLoader.load();
|
26485 | };
|
26486 | |
26487 |
|
26488 |
|
26489 |
|
26490 |
|
26491 |
|
26492 |
|
26493 |
|
26494 |
|
26495 |
|
26496 |
|
26497 |
|
26498 |
|
26499 |
|
26500 |
|
26501 |
|
26502 | var onGroupChanged = function onGroupChanged(type, settings) {
|
26503 | return function () {
|
26504 | var _settings$segmentLoad = settings.segmentLoaders,
|
26505 | segmentLoader = _settings$segmentLoad[type],
|
26506 | mainSegmentLoader = _settings$segmentLoad.main,
|
26507 | mediaType = settings.mediaTypes[type];
|
26508 | var activeTrack = mediaType.activeTrack();
|
26509 | var activeGroup = mediaType.getActiveGroup();
|
26510 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
26511 | var lastGroup = mediaType.lastGroup_;
|
26512 |
|
26513 | if (activeGroup && lastGroup && activeGroup.id === lastGroup.id) {
|
26514 | return;
|
26515 | }
|
26516 |
|
26517 | mediaType.lastGroup_ = activeGroup;
|
26518 | mediaType.lastTrack_ = activeTrack;
|
26519 | stopLoaders(segmentLoader, mediaType);
|
26520 |
|
26521 | if (!activeGroup || activeGroup.isMasterPlaylist) {
|
26522 |
|
26523 | return;
|
26524 | }
|
26525 |
|
26526 | if (!activeGroup.playlistLoader) {
|
26527 | if (previousActiveLoader) {
|
26528 |
|
26529 |
|
26530 |
|
26531 |
|
26532 | mainSegmentLoader.resetEverything();
|
26533 | }
|
26534 |
|
26535 | return;
|
26536 | }
|
26537 |
|
26538 |
|
26539 | segmentLoader.resyncLoader();
|
26540 | startLoaders(activeGroup.playlistLoader, mediaType);
|
26541 | };
|
26542 | };
|
26543 | var onGroupChanging = function onGroupChanging(type, settings) {
|
26544 | return function () {
|
26545 | var segmentLoader = settings.segmentLoaders[type],
|
26546 | mediaType = settings.mediaTypes[type];
|
26547 | mediaType.lastGroup_ = null;
|
26548 | segmentLoader.abort();
|
26549 | segmentLoader.pause();
|
26550 | };
|
26551 | };
|
26552 | |
26553 |
|
26554 |
|
26555 |
|
26556 |
|
26557 |
|
26558 |
|
26559 |
|
26560 |
|
26561 |
|
26562 |
|
26563 |
|
26564 |
|
26565 |
|
26566 |
|
26567 | var onTrackChanged = function onTrackChanged(type, settings) {
|
26568 | return function () {
|
26569 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
26570 | _settings$segmentLoad2 = settings.segmentLoaders,
|
26571 | segmentLoader = _settings$segmentLoad2[type],
|
26572 | mainSegmentLoader = _settings$segmentLoad2.main,
|
26573 | mediaType = settings.mediaTypes[type];
|
26574 | var activeTrack = mediaType.activeTrack();
|
26575 | var activeGroup = mediaType.getActiveGroup();
|
26576 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
26577 | var lastTrack = mediaType.lastTrack_;
|
26578 |
|
26579 | if (lastTrack && activeTrack && lastTrack.id === activeTrack.id) {
|
26580 | return;
|
26581 | }
|
26582 |
|
26583 | mediaType.lastGroup_ = activeGroup;
|
26584 | mediaType.lastTrack_ = activeTrack;
|
26585 | stopLoaders(segmentLoader, mediaType);
|
26586 |
|
26587 | if (!activeGroup) {
|
26588 |
|
26589 | return;
|
26590 | }
|
26591 |
|
26592 | if (activeGroup.isMasterPlaylist) {
|
26593 |
|
26594 | if (!activeTrack || !lastTrack || activeTrack.id === lastTrack.id) {
|
26595 | return;
|
26596 | }
|
26597 |
|
26598 | var mpc = settings.vhs.masterPlaylistController_;
|
26599 | var newPlaylist = mpc.selectPlaylist();
|
26600 |
|
26601 | if (mpc.media() === newPlaylist) {
|
26602 | return;
|
26603 | }
|
26604 |
|
26605 | mediaType.logger_("track change. Switching master audio from " + lastTrack.id + " to " + activeTrack.id);
|
26606 | masterPlaylistLoader.pause();
|
26607 | mainSegmentLoader.resetEverything();
|
26608 | mpc.fastQualityChange_(newPlaylist);
|
26609 | return;
|
26610 | }
|
26611 |
|
26612 | if (type === 'AUDIO') {
|
26613 | if (!activeGroup.playlistLoader) {
|
26614 |
|
26615 |
|
26616 |
|
26617 | mainSegmentLoader.setAudio(true);
|
26618 |
|
26619 |
|
26620 | mainSegmentLoader.resetEverything();
|
26621 | return;
|
26622 | }
|
26623 |
|
26624 |
|
26625 |
|
26626 |
|
26627 | segmentLoader.setAudio(true);
|
26628 | mainSegmentLoader.setAudio(false);
|
26629 | }
|
26630 |
|
26631 | if (previousActiveLoader === activeGroup.playlistLoader) {
|
26632 |
|
26633 |
|
26634 |
|
26635 | startLoaders(activeGroup.playlistLoader, mediaType);
|
26636 | return;
|
26637 | }
|
26638 |
|
26639 | if (segmentLoader.track) {
|
26640 |
|
26641 | segmentLoader.track(activeTrack);
|
26642 | }
|
26643 |
|
26644 |
|
26645 | segmentLoader.resetEverything();
|
26646 | startLoaders(activeGroup.playlistLoader, mediaType);
|
26647 | };
|
26648 | };
|
26649 | var onError = {
|
26650 | |
26651 |
|
26652 |
|
26653 |
|
26654 |
|
26655 |
|
26656 |
|
26657 |
|
26658 |
|
26659 |
|
26660 |
|
26661 |
|
26662 |
|
26663 | AUDIO: function AUDIO(type, settings) {
|
26664 | return function () {
|
26665 | var segmentLoader = settings.segmentLoaders[type],
|
26666 | mediaType = settings.mediaTypes[type],
|
26667 | blacklistCurrentPlaylist = settings.blacklistCurrentPlaylist;
|
26668 | stopLoaders(segmentLoader, mediaType);
|
26669 |
|
26670 | var activeTrack = mediaType.activeTrack();
|
26671 | var activeGroup = mediaType.activeGroup();
|
26672 | var id = (activeGroup.filter(function (group) {
|
26673 | return group.default;
|
26674 | })[0] || activeGroup[0]).id;
|
26675 | var defaultTrack = mediaType.tracks[id];
|
26676 |
|
26677 | if (activeTrack === defaultTrack) {
|
26678 |
|
26679 |
|
26680 | blacklistCurrentPlaylist({
|
26681 | message: 'Problem encountered loading the default audio track.'
|
26682 | });
|
26683 | return;
|
26684 | }
|
26685 |
|
26686 | videojs__default["default"].log.warn('Problem encountered loading the alternate audio track.' + 'Switching back to default.');
|
26687 |
|
26688 | for (var trackId in mediaType.tracks) {
|
26689 | mediaType.tracks[trackId].enabled = mediaType.tracks[trackId] === defaultTrack;
|
26690 | }
|
26691 |
|
26692 | mediaType.onTrackChanged();
|
26693 | };
|
26694 | },
|
26695 |
|
26696 | |
26697 |
|
26698 |
|
26699 |
|
26700 |
|
26701 |
|
26702 |
|
26703 |
|
26704 |
|
26705 |
|
26706 |
|
26707 |
|
26708 | SUBTITLES: function SUBTITLES(type, settings) {
|
26709 | return function () {
|
26710 | var segmentLoader = settings.segmentLoaders[type],
|
26711 | mediaType = settings.mediaTypes[type];
|
26712 | videojs__default["default"].log.warn('Problem encountered loading the subtitle track.' + 'Disabling subtitle track.');
|
26713 | stopLoaders(segmentLoader, mediaType);
|
26714 | var track = mediaType.activeTrack();
|
26715 |
|
26716 | if (track) {
|
26717 | track.mode = 'disabled';
|
26718 | }
|
26719 |
|
26720 | mediaType.onTrackChanged();
|
26721 | };
|
26722 | }
|
26723 | };
|
26724 | var setupListeners = {
|
26725 | |
26726 |
|
26727 |
|
26728 |
|
26729 |
|
26730 |
|
26731 |
|
26732 |
|
26733 |
|
26734 |
|
26735 |
|
26736 | AUDIO: function AUDIO(type, playlistLoader, settings) {
|
26737 | if (!playlistLoader) {
|
26738 |
|
26739 | return;
|
26740 | }
|
26741 |
|
26742 | var tech = settings.tech,
|
26743 | requestOptions = settings.requestOptions,
|
26744 | segmentLoader = settings.segmentLoaders[type];
|
26745 | playlistLoader.on('loadedmetadata', function () {
|
26746 | var media = playlistLoader.media();
|
26747 | segmentLoader.playlist(media, requestOptions);
|
26748 |
|
26749 |
|
26750 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
26751 | segmentLoader.load();
|
26752 | }
|
26753 | });
|
26754 | playlistLoader.on('loadedplaylist', function () {
|
26755 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
26756 |
|
26757 | if (!tech.paused()) {
|
26758 | segmentLoader.load();
|
26759 | }
|
26760 | });
|
26761 | playlistLoader.on('error', onError[type](type, settings));
|
26762 | },
|
26763 |
|
26764 | |
26765 |
|
26766 |
|
26767 |
|
26768 |
|
26769 |
|
26770 |
|
26771 |
|
26772 |
|
26773 |
|
26774 |
|
26775 | SUBTITLES: function SUBTITLES(type, playlistLoader, settings) {
|
26776 | var tech = settings.tech,
|
26777 | requestOptions = settings.requestOptions,
|
26778 | segmentLoader = settings.segmentLoaders[type],
|
26779 | mediaType = settings.mediaTypes[type];
|
26780 | playlistLoader.on('loadedmetadata', function () {
|
26781 | var media = playlistLoader.media();
|
26782 | segmentLoader.playlist(media, requestOptions);
|
26783 | segmentLoader.track(mediaType.activeTrack());
|
26784 |
|
26785 |
|
26786 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
26787 | segmentLoader.load();
|
26788 | }
|
26789 | });
|
26790 | playlistLoader.on('loadedplaylist', function () {
|
26791 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
26792 |
|
26793 | if (!tech.paused()) {
|
26794 | segmentLoader.load();
|
26795 | }
|
26796 | });
|
26797 | playlistLoader.on('error', onError[type](type, settings));
|
26798 | }
|
26799 | };
|
26800 | var initialize = {
|
26801 | |
26802 |
|
26803 |
|
26804 |
|
26805 |
|
26806 |
|
26807 |
|
26808 |
|
26809 |
|
26810 | 'AUDIO': function AUDIO(type, settings) {
|
26811 | var vhs = settings.vhs,
|
26812 | sourceType = settings.sourceType,
|
26813 | segmentLoader = settings.segmentLoaders[type],
|
26814 | requestOptions = settings.requestOptions,
|
26815 | mediaGroups = settings.master.mediaGroups,
|
26816 | _settings$mediaTypes$ = settings.mediaTypes[type],
|
26817 | groups = _settings$mediaTypes$.groups,
|
26818 | tracks = _settings$mediaTypes$.tracks,
|
26819 | logger_ = _settings$mediaTypes$.logger_,
|
26820 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
26821 | var audioOnlyMaster = isAudioOnly(masterPlaylistLoader.master);
|
26822 |
|
26823 | if (!mediaGroups[type] || Object.keys(mediaGroups[type]).length === 0) {
|
26824 | mediaGroups[type] = {
|
26825 | main: {
|
26826 | default: {
|
26827 | default: true
|
26828 | }
|
26829 | }
|
26830 | };
|
26831 |
|
26832 | if (audioOnlyMaster) {
|
26833 | mediaGroups[type].main.default.playlists = masterPlaylistLoader.master.playlists;
|
26834 | }
|
26835 | }
|
26836 |
|
26837 | for (var groupId in mediaGroups[type]) {
|
26838 | if (!groups[groupId]) {
|
26839 | groups[groupId] = [];
|
26840 | }
|
26841 |
|
26842 | for (var variantLabel in mediaGroups[type][groupId]) {
|
26843 | var properties = mediaGroups[type][groupId][variantLabel];
|
26844 | var playlistLoader = void 0;
|
26845 |
|
26846 | if (audioOnlyMaster) {
|
26847 | logger_("AUDIO group '" + groupId + "' label '" + variantLabel + "' is a master playlist");
|
26848 | properties.isMasterPlaylist = true;
|
26849 | playlistLoader = null;
|
26850 |
|
26851 | } else if (sourceType === 'vhs-json' && properties.playlists) {
|
26852 | playlistLoader = new PlaylistLoader(properties.playlists[0], vhs, requestOptions);
|
26853 | } else if (properties.resolvedUri) {
|
26854 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
26855 |
|
26856 | } else if (properties.playlists && sourceType === 'dash') {
|
26857 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
26858 | } else {
|
26859 |
|
26860 |
|
26861 | playlistLoader = null;
|
26862 | }
|
26863 |
|
26864 | properties = videojs__default["default"].mergeOptions({
|
26865 | id: variantLabel,
|
26866 | playlistLoader: playlistLoader
|
26867 | }, properties);
|
26868 | setupListeners[type](type, properties.playlistLoader, settings);
|
26869 | groups[groupId].push(properties);
|
26870 |
|
26871 | if (typeof tracks[variantLabel] === 'undefined') {
|
26872 | var track = new videojs__default["default"].AudioTrack({
|
26873 | id: variantLabel,
|
26874 | kind: audioTrackKind_(properties),
|
26875 | enabled: false,
|
26876 | language: properties.language,
|
26877 | default: properties.default,
|
26878 | label: variantLabel
|
26879 | });
|
26880 | tracks[variantLabel] = track;
|
26881 | }
|
26882 | }
|
26883 | }
|
26884 |
|
26885 |
|
26886 | segmentLoader.on('error', onError[type](type, settings));
|
26887 | },
|
26888 |
|
26889 | |
26890 |
|
26891 |
|
26892 |
|
26893 |
|
26894 |
|
26895 |
|
26896 |
|
26897 |
|
26898 | 'SUBTITLES': function SUBTITLES(type, settings) {
|
26899 | var tech = settings.tech,
|
26900 | vhs = settings.vhs,
|
26901 | sourceType = settings.sourceType,
|
26902 | segmentLoader = settings.segmentLoaders[type],
|
26903 | requestOptions = settings.requestOptions,
|
26904 | mediaGroups = settings.master.mediaGroups,
|
26905 | _settings$mediaTypes$2 = settings.mediaTypes[type],
|
26906 | groups = _settings$mediaTypes$2.groups,
|
26907 | tracks = _settings$mediaTypes$2.tracks,
|
26908 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
26909 |
|
26910 | for (var groupId in mediaGroups[type]) {
|
26911 | if (!groups[groupId]) {
|
26912 | groups[groupId] = [];
|
26913 | }
|
26914 |
|
26915 | for (var variantLabel in mediaGroups[type][groupId]) {
|
26916 | if (mediaGroups[type][groupId][variantLabel].forced) {
|
26917 |
|
26918 |
|
26919 |
|
26920 |
|
26921 |
|
26922 |
|
26923 |
|
26924 |
|
26925 | continue;
|
26926 | }
|
26927 |
|
26928 | var properties = mediaGroups[type][groupId][variantLabel];
|
26929 | var playlistLoader = void 0;
|
26930 |
|
26931 | if (sourceType === 'hls') {
|
26932 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
26933 | } else if (sourceType === 'dash') {
|
26934 | var playlists = properties.playlists.filter(function (p) {
|
26935 | return p.excludeUntil !== Infinity;
|
26936 | });
|
26937 |
|
26938 | if (!playlists.length) {
|
26939 | return;
|
26940 | }
|
26941 |
|
26942 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
26943 | } else if (sourceType === 'vhs-json') {
|
26944 | playlistLoader = new PlaylistLoader(
|
26945 |
|
26946 | properties.playlists ? properties.playlists[0] : properties.resolvedUri, vhs, requestOptions);
|
26947 | }
|
26948 |
|
26949 | properties = videojs__default["default"].mergeOptions({
|
26950 | id: variantLabel,
|
26951 | playlistLoader: playlistLoader
|
26952 | }, properties);
|
26953 | setupListeners[type](type, properties.playlistLoader, settings);
|
26954 | groups[groupId].push(properties);
|
26955 |
|
26956 | if (typeof tracks[variantLabel] === 'undefined') {
|
26957 | var track = tech.addRemoteTextTrack({
|
26958 | id: variantLabel,
|
26959 | kind: 'subtitles',
|
26960 | default: properties.default && properties.autoselect,
|
26961 | language: properties.language,
|
26962 | label: variantLabel
|
26963 | }, false).track;
|
26964 | tracks[variantLabel] = track;
|
26965 | }
|
26966 | }
|
26967 | }
|
26968 |
|
26969 |
|
26970 | segmentLoader.on('error', onError[type](type, settings));
|
26971 | },
|
26972 |
|
26973 | |
26974 |
|
26975 |
|
26976 |
|
26977 |
|
26978 |
|
26979 |
|
26980 |
|
26981 |
|
26982 | 'CLOSED-CAPTIONS': function CLOSEDCAPTIONS(type, settings) {
|
26983 | var tech = settings.tech,
|
26984 | mediaGroups = settings.master.mediaGroups,
|
26985 | _settings$mediaTypes$3 = settings.mediaTypes[type],
|
26986 | groups = _settings$mediaTypes$3.groups,
|
26987 | tracks = _settings$mediaTypes$3.tracks;
|
26988 |
|
26989 | for (var groupId in mediaGroups[type]) {
|
26990 | if (!groups[groupId]) {
|
26991 | groups[groupId] = [];
|
26992 | }
|
26993 |
|
26994 | for (var variantLabel in mediaGroups[type][groupId]) {
|
26995 | var properties = mediaGroups[type][groupId][variantLabel];
|
26996 |
|
26997 | if (!/^(?:CC|SERVICE)/.test(properties.instreamId)) {
|
26998 | continue;
|
26999 | }
|
27000 |
|
27001 | var captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
|
27002 | var newProps = {
|
27003 | label: variantLabel,
|
27004 | language: properties.language,
|
27005 | instreamId: properties.instreamId,
|
27006 | default: properties.default && properties.autoselect
|
27007 | };
|
27008 |
|
27009 | if (captionServices[newProps.instreamId]) {
|
27010 | newProps = videojs__default["default"].mergeOptions(newProps, captionServices[newProps.instreamId]);
|
27011 | }
|
27012 |
|
27013 | if (newProps.default === undefined) {
|
27014 | delete newProps.default;
|
27015 | }
|
27016 |
|
27017 |
|
27018 |
|
27019 | groups[groupId].push(videojs__default["default"].mergeOptions({
|
27020 | id: variantLabel
|
27021 | }, properties));
|
27022 |
|
27023 | if (typeof tracks[variantLabel] === 'undefined') {
|
27024 | var track = tech.addRemoteTextTrack({
|
27025 | id: newProps.instreamId,
|
27026 | kind: 'captions',
|
27027 | default: newProps.default,
|
27028 | language: newProps.language,
|
27029 | label: newProps.label
|
27030 | }, false).track;
|
27031 | tracks[variantLabel] = track;
|
27032 | }
|
27033 | }
|
27034 | }
|
27035 | }
|
27036 | };
|
27037 |
|
27038 | var groupMatch = function groupMatch(list, media) {
|
27039 | for (var i = 0; i < list.length; i++) {
|
27040 | if (playlistMatch(media, list[i])) {
|
27041 | return true;
|
27042 | }
|
27043 |
|
27044 | if (list[i].playlists && groupMatch(list[i].playlists, media)) {
|
27045 | return true;
|
27046 | }
|
27047 | }
|
27048 |
|
27049 | return false;
|
27050 | };
|
27051 | |
27052 |
|
27053 |
|
27054 |
|
27055 |
|
27056 |
|
27057 |
|
27058 |
|
27059 |
|
27060 |
|
27061 |
|
27062 |
|
27063 |
|
27064 |
|
27065 |
|
27066 |
|
27067 | var activeGroup = function activeGroup(type, settings) {
|
27068 | return function (track) {
|
27069 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
27070 | groups = settings.mediaTypes[type].groups;
|
27071 | var media = masterPlaylistLoader.media();
|
27072 |
|
27073 | if (!media) {
|
27074 | return null;
|
27075 | }
|
27076 |
|
27077 | var variants = null;
|
27078 |
|
27079 | if (media.attributes[type]) {
|
27080 | variants = groups[media.attributes[type]];
|
27081 | }
|
27082 |
|
27083 | var groupKeys = Object.keys(groups);
|
27084 |
|
27085 | if (!variants) {
|
27086 |
|
27087 |
|
27088 |
|
27089 | if (type === 'AUDIO' && groupKeys.length > 1 && isAudioOnly(settings.master)) {
|
27090 | for (var i = 0; i < groupKeys.length; i++) {
|
27091 | var groupPropertyList = groups[groupKeys[i]];
|
27092 |
|
27093 | if (groupMatch(groupPropertyList, media)) {
|
27094 | variants = groupPropertyList;
|
27095 | break;
|
27096 | }
|
27097 | }
|
27098 |
|
27099 | } else if (groups.main) {
|
27100 | variants = groups.main;
|
27101 | } else if (groupKeys.length === 1) {
|
27102 | variants = groups[groupKeys[0]];
|
27103 | }
|
27104 | }
|
27105 |
|
27106 | if (typeof track === 'undefined') {
|
27107 | return variants;
|
27108 | }
|
27109 |
|
27110 | if (track === null || !variants) {
|
27111 |
|
27112 |
|
27113 | return null;
|
27114 | }
|
27115 |
|
27116 | return variants.filter(function (props) {
|
27117 | return props.id === track.id;
|
27118 | })[0] || null;
|
27119 | };
|
27120 | };
|
27121 | var activeTrack = {
|
27122 | |
27123 |
|
27124 |
|
27125 |
|
27126 |
|
27127 |
|
27128 |
|
27129 |
|
27130 |
|
27131 |
|
27132 |
|
27133 |
|
27134 | AUDIO: function AUDIO(type, settings) {
|
27135 | return function () {
|
27136 | var tracks = settings.mediaTypes[type].tracks;
|
27137 |
|
27138 | for (var id in tracks) {
|
27139 | if (tracks[id].enabled) {
|
27140 | return tracks[id];
|
27141 | }
|
27142 | }
|
27143 |
|
27144 | return null;
|
27145 | };
|
27146 | },
|
27147 |
|
27148 | |
27149 |
|
27150 |
|
27151 |
|
27152 |
|
27153 |
|
27154 |
|
27155 |
|
27156 |
|
27157 |
|
27158 |
|
27159 |
|
27160 | SUBTITLES: function SUBTITLES(type, settings) {
|
27161 | return function () {
|
27162 | var tracks = settings.mediaTypes[type].tracks;
|
27163 |
|
27164 | for (var id in tracks) {
|
27165 | if (tracks[id].mode === 'showing' || tracks[id].mode === 'hidden') {
|
27166 | return tracks[id];
|
27167 | }
|
27168 | }
|
27169 |
|
27170 | return null;
|
27171 | };
|
27172 | }
|
27173 | };
|
27174 | var getActiveGroup = function getActiveGroup(type, _ref) {
|
27175 | var mediaTypes = _ref.mediaTypes;
|
27176 | return function () {
|
27177 | var activeTrack_ = mediaTypes[type].activeTrack();
|
27178 |
|
27179 | if (!activeTrack_) {
|
27180 | return null;
|
27181 | }
|
27182 |
|
27183 | return mediaTypes[type].activeGroup(activeTrack_);
|
27184 | };
|
27185 | };
|
27186 | |
27187 |
|
27188 |
|
27189 |
|
27190 |
|
27191 |
|
27192 |
|
27193 |
|
27194 |
|
27195 |
|
27196 |
|
27197 |
|
27198 |
|
27199 |
|
27200 |
|
27201 |
|
27202 |
|
27203 |
|
27204 |
|
27205 |
|
27206 |
|
27207 |
|
27208 |
|
27209 | var setupMediaGroups = function setupMediaGroups(settings) {
|
27210 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
27211 | initialize[type](type, settings);
|
27212 | });
|
27213 | var mediaTypes = settings.mediaTypes,
|
27214 | masterPlaylistLoader = settings.masterPlaylistLoader,
|
27215 | tech = settings.tech,
|
27216 | vhs = settings.vhs,
|
27217 | _settings$segmentLoad3 = settings.segmentLoaders,
|
27218 | audioSegmentLoader = _settings$segmentLoad3['AUDIO'],
|
27219 | mainSegmentLoader = _settings$segmentLoad3.main;
|
27220 |
|
27221 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
27222 | mediaTypes[type].activeGroup = activeGroup(type, settings);
|
27223 | mediaTypes[type].activeTrack = activeTrack[type](type, settings);
|
27224 | mediaTypes[type].onGroupChanged = onGroupChanged(type, settings);
|
27225 | mediaTypes[type].onGroupChanging = onGroupChanging(type, settings);
|
27226 | mediaTypes[type].onTrackChanged = onTrackChanged(type, settings);
|
27227 | mediaTypes[type].getActiveGroup = getActiveGroup(type, settings);
|
27228 | });
|
27229 |
|
27230 |
|
27231 | var audioGroup = mediaTypes.AUDIO.activeGroup();
|
27232 |
|
27233 | if (audioGroup) {
|
27234 | var groupId = (audioGroup.filter(function (group) {
|
27235 | return group.default;
|
27236 | })[0] || audioGroup[0]).id;
|
27237 | mediaTypes.AUDIO.tracks[groupId].enabled = true;
|
27238 | mediaTypes.AUDIO.onGroupChanged();
|
27239 | mediaTypes.AUDIO.onTrackChanged();
|
27240 | var activeAudioGroup = mediaTypes.AUDIO.getActiveGroup();
|
27241 |
|
27242 |
|
27243 |
|
27244 | if (!activeAudioGroup.playlistLoader) {
|
27245 |
|
27246 | mainSegmentLoader.setAudio(true);
|
27247 | } else {
|
27248 |
|
27249 | mainSegmentLoader.setAudio(false);
|
27250 | audioSegmentLoader.setAudio(true);
|
27251 | }
|
27252 | }
|
27253 |
|
27254 | masterPlaylistLoader.on('mediachange', function () {
|
27255 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
27256 | return mediaTypes[type].onGroupChanged();
|
27257 | });
|
27258 | });
|
27259 | masterPlaylistLoader.on('mediachanging', function () {
|
27260 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
27261 | return mediaTypes[type].onGroupChanging();
|
27262 | });
|
27263 | });
|
27264 |
|
27265 | var onAudioTrackChanged = function onAudioTrackChanged() {
|
27266 | mediaTypes.AUDIO.onTrackChanged();
|
27267 | tech.trigger({
|
27268 | type: 'usage',
|
27269 | name: 'vhs-audio-change'
|
27270 | });
|
27271 | tech.trigger({
|
27272 | type: 'usage',
|
27273 | name: 'hls-audio-change'
|
27274 | });
|
27275 | };
|
27276 |
|
27277 | tech.audioTracks().addEventListener('change', onAudioTrackChanged);
|
27278 | tech.remoteTextTracks().addEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
27279 | vhs.on('dispose', function () {
|
27280 | tech.audioTracks().removeEventListener('change', onAudioTrackChanged);
|
27281 | tech.remoteTextTracks().removeEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
27282 | });
|
27283 |
|
27284 | tech.clearTracks('audio');
|
27285 |
|
27286 | for (var id in mediaTypes.AUDIO.tracks) {
|
27287 | tech.audioTracks().addTrack(mediaTypes.AUDIO.tracks[id]);
|
27288 | }
|
27289 | };
|
27290 | |
27291 |
|
27292 |
|
27293 |
|
27294 |
|
27295 |
|
27296 |
|
27297 |
|
27298 |
|
27299 | var createMediaTypes = function createMediaTypes() {
|
27300 | var mediaTypes = {};
|
27301 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
27302 | mediaTypes[type] = {
|
27303 | groups: {},
|
27304 | tracks: {},
|
27305 | activePlaylistLoader: null,
|
27306 | activeGroup: noop,
|
27307 | activeTrack: noop,
|
27308 | getActiveGroup: noop,
|
27309 | onGroupChanged: noop,
|
27310 | onTrackChanged: noop,
|
27311 | lastTrack_: null,
|
27312 | logger_: logger("MediaGroups[" + type + "]")
|
27313 | };
|
27314 | });
|
27315 | return mediaTypes;
|
27316 | };
|
27317 |
|
27318 | var ABORT_EARLY_BLACKLIST_SECONDS = 60 * 2;
|
27319 | var Vhs$1;
|
27320 |
|
27321 |
|
27322 | var loaderStats = ['mediaRequests', 'mediaRequestsAborted', 'mediaRequestsTimedout', 'mediaRequestsErrored', 'mediaTransferDuration', 'mediaBytesTransferred', 'mediaAppends'];
|
27323 |
|
27324 | var sumLoaderStat = function sumLoaderStat(stat) {
|
27325 | return this.audioSegmentLoader_[stat] + this.mainSegmentLoader_[stat];
|
27326 | };
|
27327 |
|
27328 | var shouldSwitchToMedia = function shouldSwitchToMedia(_ref) {
|
27329 | var currentPlaylist = _ref.currentPlaylist,
|
27330 | nextPlaylist = _ref.nextPlaylist,
|
27331 | forwardBuffer = _ref.forwardBuffer,
|
27332 | bufferLowWaterLine = _ref.bufferLowWaterLine,
|
27333 | bufferHighWaterLine = _ref.bufferHighWaterLine,
|
27334 | duration = _ref.duration,
|
27335 | experimentalBufferBasedABR = _ref.experimentalBufferBasedABR,
|
27336 | log = _ref.log;
|
27337 |
|
27338 |
|
27339 | if (!nextPlaylist) {
|
27340 | videojs__default["default"].log.warn('We received no playlist to switch to. Please check your stream.');
|
27341 | return false;
|
27342 | }
|
27343 |
|
27344 | var sharedLogLine = "allowing switch " + (currentPlaylist && currentPlaylist.id || 'null') + " -> " + nextPlaylist.id;
|
27345 |
|
27346 | if (!currentPlaylist) {
|
27347 | log(sharedLogLine + " as current playlist is not set");
|
27348 | return true;
|
27349 | }
|
27350 |
|
27351 |
|
27352 | if (nextPlaylist.id === currentPlaylist.id) {
|
27353 | return false;
|
27354 | }
|
27355 |
|
27356 |
|
27357 |
|
27358 |
|
27359 |
|
27360 | if (!currentPlaylist.endList) {
|
27361 | log(sharedLogLine + " as current playlist is live");
|
27362 | return true;
|
27363 | }
|
27364 |
|
27365 | var maxBufferLowWaterLine = experimentalBufferBasedABR ? Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE : Config.MAX_BUFFER_LOW_WATER_LINE;
|
27366 |
|
27367 |
|
27368 | if (duration < maxBufferLowWaterLine) {
|
27369 | log(sharedLogLine + " as duration < max low water line (" + duration + " < " + maxBufferLowWaterLine + ")");
|
27370 | return true;
|
27371 | }
|
27372 |
|
27373 | var nextBandwidth = nextPlaylist.attributes.BANDWIDTH;
|
27374 | var currBandwidth = currentPlaylist.attributes.BANDWIDTH;
|
27375 |
|
27376 |
|
27377 | if (nextBandwidth < currBandwidth && (!experimentalBufferBasedABR || forwardBuffer < bufferHighWaterLine)) {
|
27378 | var logLine = sharedLogLine + " as next bandwidth < current bandwidth (" + nextBandwidth + " < " + currBandwidth + ")";
|
27379 |
|
27380 | if (experimentalBufferBasedABR) {
|
27381 | logLine += " and forwardBuffer < bufferHighWaterLine (" + forwardBuffer + " < " + bufferHighWaterLine + ")";
|
27382 | }
|
27383 |
|
27384 | log(logLine);
|
27385 | return true;
|
27386 | }
|
27387 |
|
27388 |
|
27389 |
|
27390 | if ((!experimentalBufferBasedABR || nextBandwidth > currBandwidth) && forwardBuffer >= bufferLowWaterLine) {
|
27391 | var _logLine = sharedLogLine + " as forwardBuffer >= bufferLowWaterLine (" + forwardBuffer + " >= " + bufferLowWaterLine + ")";
|
27392 |
|
27393 | if (experimentalBufferBasedABR) {
|
27394 | _logLine += " and next bandwidth > current bandwidth (" + nextBandwidth + " > " + currBandwidth + ")";
|
27395 | }
|
27396 |
|
27397 | log(_logLine);
|
27398 | return true;
|
27399 | }
|
27400 |
|
27401 | log("not " + sharedLogLine + " as no switching criteria met");
|
27402 | return false;
|
27403 | };
|
27404 | |
27405 |
|
27406 |
|
27407 |
|
27408 |
|
27409 |
|
27410 |
|
27411 |
|
27412 |
|
27413 |
|
27414 |
|
27415 | var MasterPlaylistController = function (_videojs$EventTarget) {
|
27416 | inheritsLoose(MasterPlaylistController, _videojs$EventTarget);
|
27417 |
|
27418 | function MasterPlaylistController(options) {
|
27419 | var _this;
|
27420 |
|
27421 | _this = _videojs$EventTarget.call(this) || this;
|
27422 | var src = options.src,
|
27423 | handleManifestRedirects = options.handleManifestRedirects,
|
27424 | withCredentials = options.withCredentials,
|
27425 | tech = options.tech,
|
27426 | bandwidth = options.bandwidth,
|
27427 | externVhs = options.externVhs,
|
27428 | useCueTags = options.useCueTags,
|
27429 | blacklistDuration = options.blacklistDuration,
|
27430 | enableLowInitialPlaylist = options.enableLowInitialPlaylist,
|
27431 | sourceType = options.sourceType,
|
27432 | cacheEncryptionKeys = options.cacheEncryptionKeys,
|
27433 | experimentalBufferBasedABR = options.experimentalBufferBasedABR,
|
27434 | experimentalLeastPixelDiffSelector = options.experimentalLeastPixelDiffSelector,
|
27435 | captionServices = options.captionServices;
|
27436 |
|
27437 | if (!src) {
|
27438 | throw new Error('A non-empty playlist URL or JSON manifest string is required');
|
27439 | }
|
27440 |
|
27441 | var maxPlaylistRetries = options.maxPlaylistRetries;
|
27442 |
|
27443 | if (maxPlaylistRetries === null || typeof maxPlaylistRetries === 'undefined') {
|
27444 | maxPlaylistRetries = Infinity;
|
27445 | }
|
27446 |
|
27447 | Vhs$1 = externVhs;
|
27448 | _this.experimentalBufferBasedABR = Boolean(experimentalBufferBasedABR);
|
27449 | _this.experimentalLeastPixelDiffSelector = Boolean(experimentalLeastPixelDiffSelector);
|
27450 | _this.withCredentials = withCredentials;
|
27451 | _this.tech_ = tech;
|
27452 | _this.vhs_ = tech.vhs;
|
27453 | _this.sourceType_ = sourceType;
|
27454 | _this.useCueTags_ = useCueTags;
|
27455 | _this.blacklistDuration = blacklistDuration;
|
27456 | _this.maxPlaylistRetries = maxPlaylistRetries;
|
27457 | _this.enableLowInitialPlaylist = enableLowInitialPlaylist;
|
27458 |
|
27459 | if (_this.useCueTags_) {
|
27460 | _this.cueTagsTrack_ = _this.tech_.addTextTrack('metadata', 'ad-cues');
|
27461 | _this.cueTagsTrack_.inBandMetadataTrackDispatchType = '';
|
27462 | }
|
27463 |
|
27464 | _this.requestOptions_ = {
|
27465 | withCredentials: withCredentials,
|
27466 | handleManifestRedirects: handleManifestRedirects,
|
27467 | maxPlaylistRetries: maxPlaylistRetries,
|
27468 | timeout: null
|
27469 | };
|
27470 |
|
27471 | _this.on('error', _this.pauseLoading);
|
27472 |
|
27473 | _this.mediaTypes_ = createMediaTypes();
|
27474 | _this.mediaSource = new window.MediaSource();
|
27475 | _this.handleDurationChange_ = _this.handleDurationChange_.bind(assertThisInitialized(_this));
|
27476 | _this.handleSourceOpen_ = _this.handleSourceOpen_.bind(assertThisInitialized(_this));
|
27477 | _this.handleSourceEnded_ = _this.handleSourceEnded_.bind(assertThisInitialized(_this));
|
27478 |
|
27479 | _this.mediaSource.addEventListener('durationchange', _this.handleDurationChange_);
|
27480 |
|
27481 |
|
27482 | _this.mediaSource.addEventListener('sourceopen', _this.handleSourceOpen_);
|
27483 |
|
27484 | _this.mediaSource.addEventListener('sourceended', _this.handleSourceEnded_);
|
27485 |
|
27486 |
|
27487 |
|
27488 | _this.seekable_ = videojs__default["default"].createTimeRanges();
|
27489 | _this.hasPlayed_ = false;
|
27490 | _this.syncController_ = new SyncController(options);
|
27491 | _this.segmentMetadataTrack_ = tech.addRemoteTextTrack({
|
27492 | kind: 'metadata',
|
27493 | label: 'segment-metadata'
|
27494 | }, false).track;
|
27495 | _this.decrypter_ = new Decrypter();
|
27496 | _this.sourceUpdater_ = new SourceUpdater(_this.mediaSource);
|
27497 | _this.inbandTextTracks_ = {};
|
27498 | _this.timelineChangeController_ = new TimelineChangeController();
|
27499 | var segmentLoaderSettings = {
|
27500 | vhs: _this.vhs_,
|
27501 | parse708captions: options.parse708captions,
|
27502 | captionServices: captionServices,
|
27503 | mediaSource: _this.mediaSource,
|
27504 | currentTime: _this.tech_.currentTime.bind(_this.tech_),
|
27505 | seekable: function seekable() {
|
27506 | return _this.seekable();
|
27507 | },
|
27508 | seeking: function seeking() {
|
27509 | return _this.tech_.seeking();
|
27510 | },
|
27511 | duration: function duration() {
|
27512 | return _this.duration();
|
27513 | },
|
27514 | hasPlayed: function hasPlayed() {
|
27515 | return _this.hasPlayed_;
|
27516 | },
|
27517 | goalBufferLength: function goalBufferLength() {
|
27518 | return _this.goalBufferLength();
|
27519 | },
|
27520 | bandwidth: bandwidth,
|
27521 | syncController: _this.syncController_,
|
27522 | decrypter: _this.decrypter_,
|
27523 | sourceType: _this.sourceType_,
|
27524 | inbandTextTracks: _this.inbandTextTracks_,
|
27525 | cacheEncryptionKeys: cacheEncryptionKeys,
|
27526 | sourceUpdater: _this.sourceUpdater_,
|
27527 | timelineChangeController: _this.timelineChangeController_,
|
27528 | experimentalExactManifestTimings: options.experimentalExactManifestTimings
|
27529 | };
|
27530 |
|
27531 |
|
27532 |
|
27533 |
|
27534 | _this.masterPlaylistLoader_ = _this.sourceType_ === 'dash' ? new DashPlaylistLoader(src, _this.vhs_, _this.requestOptions_) : new PlaylistLoader(src, _this.vhs_, _this.requestOptions_);
|
27535 |
|
27536 | _this.setupMasterPlaylistLoaderListeners_();
|
27537 |
|
27538 |
|
27539 |
|
27540 | _this.mainSegmentLoader_ = new SegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
27541 | segmentMetadataTrack: _this.segmentMetadataTrack_,
|
27542 | loaderType: 'main'
|
27543 | }), options);
|
27544 |
|
27545 | _this.audioSegmentLoader_ = new SegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
27546 | loaderType: 'audio'
|
27547 | }), options);
|
27548 | _this.subtitleSegmentLoader_ = new VTTSegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
27549 | loaderType: 'vtt',
|
27550 | featuresNativeTextTracks: _this.tech_.featuresNativeTextTracks
|
27551 | }), options);
|
27552 |
|
27553 | _this.setupSegmentLoaderListeners_();
|
27554 |
|
27555 | if (_this.experimentalBufferBasedABR) {
|
27556 | _this.masterPlaylistLoader_.one('loadedplaylist', function () {
|
27557 | return _this.startABRTimer_();
|
27558 | });
|
27559 |
|
27560 | _this.tech_.on('pause', function () {
|
27561 | return _this.stopABRTimer_();
|
27562 | });
|
27563 |
|
27564 | _this.tech_.on('play', function () {
|
27565 | return _this.startABRTimer_();
|
27566 | });
|
27567 | }
|
27568 |
|
27569 |
|
27570 |
|
27571 |
|
27572 |
|
27573 |
|
27574 |
|
27575 |
|
27576 |
|
27577 | loaderStats.forEach(function (stat) {
|
27578 | _this[stat + '_'] = sumLoaderStat.bind(assertThisInitialized(_this), stat);
|
27579 | });
|
27580 | _this.logger_ = logger('MPC');
|
27581 | _this.triggeredFmp4Usage = false;
|
27582 |
|
27583 | if (_this.tech_.preload() === 'none') {
|
27584 | _this.loadOnPlay_ = function () {
|
27585 | _this.loadOnPlay_ = null;
|
27586 |
|
27587 | _this.masterPlaylistLoader_.load();
|
27588 | };
|
27589 |
|
27590 | _this.tech_.one('play', _this.loadOnPlay_);
|
27591 | } else {
|
27592 | _this.masterPlaylistLoader_.load();
|
27593 | }
|
27594 |
|
27595 | _this.timeToLoadedData__ = -1;
|
27596 | _this.mainAppendsToLoadedData__ = -1;
|
27597 | _this.audioAppendsToLoadedData__ = -1;
|
27598 | var event = _this.tech_.preload() === 'none' ? 'play' : 'loadstart';
|
27599 |
|
27600 | _this.tech_.one(event, function () {
|
27601 | var timeToLoadedDataStart = Date.now();
|
27602 |
|
27603 | _this.tech_.one('loadeddata', function () {
|
27604 | _this.timeToLoadedData__ = Date.now() - timeToLoadedDataStart;
|
27605 | _this.mainAppendsToLoadedData__ = _this.mainSegmentLoader_.mediaAppends;
|
27606 | _this.audioAppendsToLoadedData__ = _this.audioSegmentLoader_.mediaAppends;
|
27607 | });
|
27608 | });
|
27609 |
|
27610 | return _this;
|
27611 | }
|
27612 |
|
27613 | var _proto = MasterPlaylistController.prototype;
|
27614 |
|
27615 | _proto.mainAppendsToLoadedData_ = function mainAppendsToLoadedData_() {
|
27616 | return this.mainAppendsToLoadedData__;
|
27617 | };
|
27618 |
|
27619 | _proto.audioAppendsToLoadedData_ = function audioAppendsToLoadedData_() {
|
27620 | return this.audioAppendsToLoadedData__;
|
27621 | };
|
27622 |
|
27623 | _proto.appendsToLoadedData_ = function appendsToLoadedData_() {
|
27624 | var main = this.mainAppendsToLoadedData_();
|
27625 | var audio = this.audioAppendsToLoadedData_();
|
27626 |
|
27627 | if (main === -1 || audio === -1) {
|
27628 | return -1;
|
27629 | }
|
27630 |
|
27631 | return main + audio;
|
27632 | };
|
27633 |
|
27634 | _proto.timeToLoadedData_ = function timeToLoadedData_() {
|
27635 | return this.timeToLoadedData__;
|
27636 | }
|
27637 | |
27638 |
|
27639 |
|
27640 |
|
27641 |
|
27642 |
|
27643 | ;
|
27644 |
|
27645 | _proto.checkABR_ = function checkABR_() {
|
27646 | var nextPlaylist = this.selectPlaylist();
|
27647 |
|
27648 | if (nextPlaylist && this.shouldSwitchToMedia_(nextPlaylist)) {
|
27649 | this.switchMedia_(nextPlaylist, 'abr');
|
27650 | }
|
27651 | };
|
27652 |
|
27653 | _proto.switchMedia_ = function switchMedia_(playlist, cause, delay) {
|
27654 | var oldMedia = this.media();
|
27655 | var oldId = oldMedia && (oldMedia.id || oldMedia.uri);
|
27656 | var newId = playlist.id || playlist.uri;
|
27657 |
|
27658 | if (oldId && oldId !== newId) {
|
27659 | this.logger_("switch media " + oldId + " -> " + newId + " from " + cause);
|
27660 | this.tech_.trigger({
|
27661 | type: 'usage',
|
27662 | name: "vhs-rendition-change-" + cause
|
27663 | });
|
27664 | }
|
27665 |
|
27666 | this.masterPlaylistLoader_.media(playlist, delay);
|
27667 | }
|
27668 | |
27669 |
|
27670 |
|
27671 |
|
27672 |
|
27673 | ;
|
27674 |
|
27675 | _proto.startABRTimer_ = function startABRTimer_() {
|
27676 | var _this2 = this;
|
27677 |
|
27678 | this.stopABRTimer_();
|
27679 | this.abrTimer_ = window.setInterval(function () {
|
27680 | return _this2.checkABR_();
|
27681 | }, 250);
|
27682 | }
|
27683 | |
27684 |
|
27685 |
|
27686 |
|
27687 |
|
27688 | ;
|
27689 |
|
27690 | _proto.stopABRTimer_ = function stopABRTimer_() {
|
27691 |
|
27692 |
|
27693 | if (this.tech_.scrubbing && this.tech_.scrubbing()) {
|
27694 | return;
|
27695 | }
|
27696 |
|
27697 | window.clearInterval(this.abrTimer_);
|
27698 | this.abrTimer_ = null;
|
27699 | }
|
27700 | |
27701 |
|
27702 |
|
27703 |
|
27704 |
|
27705 | ;
|
27706 |
|
27707 | _proto.getAudioTrackPlaylists_ = function getAudioTrackPlaylists_() {
|
27708 | var master = this.master();
|
27709 | var defaultPlaylists = master && master.playlists || [];
|
27710 |
|
27711 |
|
27712 |
|
27713 | if (!master || !master.mediaGroups || !master.mediaGroups.AUDIO) {
|
27714 | return defaultPlaylists;
|
27715 | }
|
27716 |
|
27717 | var AUDIO = master.mediaGroups.AUDIO;
|
27718 | var groupKeys = Object.keys(AUDIO);
|
27719 | var track;
|
27720 |
|
27721 | if (Object.keys(this.mediaTypes_.AUDIO.groups).length) {
|
27722 | track = this.mediaTypes_.AUDIO.activeTrack();
|
27723 | } else {
|
27724 |
|
27725 | var defaultGroup = AUDIO.main || groupKeys.length && AUDIO[groupKeys[0]];
|
27726 |
|
27727 | for (var label in defaultGroup) {
|
27728 | if (defaultGroup[label].default) {
|
27729 | track = {
|
27730 | label: label
|
27731 | };
|
27732 | break;
|
27733 | }
|
27734 | }
|
27735 | }
|
27736 |
|
27737 |
|
27738 | if (!track) {
|
27739 | return defaultPlaylists;
|
27740 | }
|
27741 |
|
27742 | var playlists = [];
|
27743 |
|
27744 |
|
27745 | for (var group in AUDIO) {
|
27746 | if (AUDIO[group][track.label]) {
|
27747 | var properties = AUDIO[group][track.label];
|
27748 |
|
27749 | if (properties.playlists && properties.playlists.length) {
|
27750 | playlists.push.apply(playlists, properties.playlists);
|
27751 | } else if (properties.uri) {
|
27752 | playlists.push(properties);
|
27753 | } else if (master.playlists.length) {
|
27754 |
|
27755 |
|
27756 |
|
27757 | for (var i = 0; i < master.playlists.length; i++) {
|
27758 | var playlist = master.playlists[i];
|
27759 |
|
27760 | if (playlist.attributes && playlist.attributes.AUDIO && playlist.attributes.AUDIO === group) {
|
27761 | playlists.push(playlist);
|
27762 | }
|
27763 | }
|
27764 | }
|
27765 | }
|
27766 | }
|
27767 |
|
27768 | if (!playlists.length) {
|
27769 | return defaultPlaylists;
|
27770 | }
|
27771 |
|
27772 | return playlists;
|
27773 | }
|
27774 | |
27775 |
|
27776 |
|
27777 |
|
27778 |
|
27779 |
|
27780 | ;
|
27781 |
|
27782 | _proto.setupMasterPlaylistLoaderListeners_ = function setupMasterPlaylistLoaderListeners_() {
|
27783 | var _this3 = this;
|
27784 |
|
27785 | this.masterPlaylistLoader_.on('loadedmetadata', function () {
|
27786 | var media = _this3.masterPlaylistLoader_.media();
|
27787 |
|
27788 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
27789 |
|
27790 |
|
27791 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
27792 | _this3.requestOptions_.timeout = 0;
|
27793 | } else {
|
27794 | _this3.requestOptions_.timeout = requestTimeout;
|
27795 | }
|
27796 |
|
27797 |
|
27798 |
|
27799 | if (media.endList && _this3.tech_.preload() !== 'none') {
|
27800 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
27801 |
|
27802 | _this3.mainSegmentLoader_.load();
|
27803 | }
|
27804 |
|
27805 | setupMediaGroups({
|
27806 | sourceType: _this3.sourceType_,
|
27807 | segmentLoaders: {
|
27808 | AUDIO: _this3.audioSegmentLoader_,
|
27809 | SUBTITLES: _this3.subtitleSegmentLoader_,
|
27810 | main: _this3.mainSegmentLoader_
|
27811 | },
|
27812 | tech: _this3.tech_,
|
27813 | requestOptions: _this3.requestOptions_,
|
27814 | masterPlaylistLoader: _this3.masterPlaylistLoader_,
|
27815 | vhs: _this3.vhs_,
|
27816 | master: _this3.master(),
|
27817 | mediaTypes: _this3.mediaTypes_,
|
27818 | blacklistCurrentPlaylist: _this3.blacklistCurrentPlaylist.bind(_this3)
|
27819 | });
|
27820 |
|
27821 | _this3.triggerPresenceUsage_(_this3.master(), media);
|
27822 |
|
27823 | _this3.setupFirstPlay();
|
27824 |
|
27825 | if (!_this3.mediaTypes_.AUDIO.activePlaylistLoader || _this3.mediaTypes_.AUDIO.activePlaylistLoader.media()) {
|
27826 | _this3.trigger('selectedinitialmedia');
|
27827 | } else {
|
27828 |
|
27829 |
|
27830 |
|
27831 | _this3.mediaTypes_.AUDIO.activePlaylistLoader.one('loadedmetadata', function () {
|
27832 | _this3.trigger('selectedinitialmedia');
|
27833 | });
|
27834 | }
|
27835 | });
|
27836 | this.masterPlaylistLoader_.on('loadedplaylist', function () {
|
27837 | if (_this3.loadOnPlay_) {
|
27838 | _this3.tech_.off('play', _this3.loadOnPlay_);
|
27839 | }
|
27840 |
|
27841 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
27842 |
|
27843 | if (!updatedPlaylist) {
|
27844 |
|
27845 |
|
27846 | _this3.excludeUnsupportedVariants_();
|
27847 |
|
27848 | var selectedMedia;
|
27849 |
|
27850 | if (_this3.enableLowInitialPlaylist) {
|
27851 | selectedMedia = _this3.selectInitialPlaylist();
|
27852 | }
|
27853 |
|
27854 | if (!selectedMedia) {
|
27855 | selectedMedia = _this3.selectPlaylist();
|
27856 | }
|
27857 |
|
27858 | if (!selectedMedia || !_this3.shouldSwitchToMedia_(selectedMedia)) {
|
27859 | return;
|
27860 | }
|
27861 |
|
27862 | _this3.initialMedia_ = selectedMedia;
|
27863 |
|
27864 | _this3.switchMedia_(_this3.initialMedia_, 'initial');
|
27865 |
|
27866 |
|
27867 |
|
27868 |
|
27869 |
|
27870 |
|
27871 |
|
27872 | var haveJsonSource = _this3.sourceType_ === 'vhs-json' && _this3.initialMedia_.segments;
|
27873 |
|
27874 | if (!haveJsonSource) {
|
27875 | return;
|
27876 | }
|
27877 |
|
27878 | updatedPlaylist = _this3.initialMedia_;
|
27879 | }
|
27880 |
|
27881 | _this3.handleUpdatedMediaPlaylist(updatedPlaylist);
|
27882 | });
|
27883 | this.masterPlaylistLoader_.on('error', function () {
|
27884 | _this3.blacklistCurrentPlaylist(_this3.masterPlaylistLoader_.error);
|
27885 | });
|
27886 | this.masterPlaylistLoader_.on('mediachanging', function () {
|
27887 | _this3.mainSegmentLoader_.abort();
|
27888 |
|
27889 | _this3.mainSegmentLoader_.pause();
|
27890 | });
|
27891 | this.masterPlaylistLoader_.on('mediachange', function () {
|
27892 | var media = _this3.masterPlaylistLoader_.media();
|
27893 |
|
27894 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
27895 |
|
27896 |
|
27897 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
27898 | _this3.requestOptions_.timeout = 0;
|
27899 | } else {
|
27900 | _this3.requestOptions_.timeout = requestTimeout;
|
27901 | }
|
27902 |
|
27903 |
|
27904 |
|
27905 |
|
27906 |
|
27907 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
27908 |
|
27909 | _this3.mainSegmentLoader_.load();
|
27910 |
|
27911 | _this3.tech_.trigger({
|
27912 | type: 'mediachange',
|
27913 | bubbles: true
|
27914 | });
|
27915 | });
|
27916 | this.masterPlaylistLoader_.on('playlistunchanged', function () {
|
27917 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
27918 |
|
27919 |
|
27920 |
|
27921 |
|
27922 | if (updatedPlaylist.lastExcludeReason_ === 'playlist-unchanged') {
|
27923 | return;
|
27924 | }
|
27925 |
|
27926 | var playlistOutdated = _this3.stuckAtPlaylistEnd_(updatedPlaylist);
|
27927 |
|
27928 | if (playlistOutdated) {
|
27929 |
|
27930 |
|
27931 |
|
27932 |
|
27933 | _this3.blacklistCurrentPlaylist({
|
27934 | message: 'Playlist no longer updating.',
|
27935 | reason: 'playlist-unchanged'
|
27936 | });
|
27937 |
|
27938 |
|
27939 | _this3.tech_.trigger('playliststuck');
|
27940 | }
|
27941 | });
|
27942 | this.masterPlaylistLoader_.on('renditiondisabled', function () {
|
27943 | _this3.tech_.trigger({
|
27944 | type: 'usage',
|
27945 | name: 'vhs-rendition-disabled'
|
27946 | });
|
27947 |
|
27948 | _this3.tech_.trigger({
|
27949 | type: 'usage',
|
27950 | name: 'hls-rendition-disabled'
|
27951 | });
|
27952 | });
|
27953 | this.masterPlaylistLoader_.on('renditionenabled', function () {
|
27954 | _this3.tech_.trigger({
|
27955 | type: 'usage',
|
27956 | name: 'vhs-rendition-enabled'
|
27957 | });
|
27958 |
|
27959 | _this3.tech_.trigger({
|
27960 | type: 'usage',
|
27961 | name: 'hls-rendition-enabled'
|
27962 | });
|
27963 | });
|
27964 | }
|
27965 | |
27966 |
|
27967 |
|
27968 |
|
27969 |
|
27970 |
|
27971 |
|
27972 |
|
27973 |
|
27974 | ;
|
27975 |
|
27976 | _proto.handleUpdatedMediaPlaylist = function handleUpdatedMediaPlaylist(updatedPlaylist) {
|
27977 | if (this.useCueTags_) {
|
27978 | this.updateAdCues_(updatedPlaylist);
|
27979 | }
|
27980 |
|
27981 |
|
27982 |
|
27983 |
|
27984 |
|
27985 | this.mainSegmentLoader_.playlist(updatedPlaylist, this.requestOptions_);
|
27986 | this.updateDuration(!updatedPlaylist.endList);
|
27987 |
|
27988 |
|
27989 |
|
27990 | if (!this.tech_.paused()) {
|
27991 | this.mainSegmentLoader_.load();
|
27992 |
|
27993 | if (this.audioSegmentLoader_) {
|
27994 | this.audioSegmentLoader_.load();
|
27995 | }
|
27996 | }
|
27997 | }
|
27998 | |
27999 |
|
28000 |
|
28001 |
|
28002 |
|
28003 | ;
|
28004 |
|
28005 | _proto.triggerPresenceUsage_ = function triggerPresenceUsage_(master, media) {
|
28006 | var mediaGroups = master.mediaGroups || {};
|
28007 | var defaultDemuxed = true;
|
28008 | var audioGroupKeys = Object.keys(mediaGroups.AUDIO);
|
28009 |
|
28010 | for (var mediaGroup in mediaGroups.AUDIO) {
|
28011 | for (var label in mediaGroups.AUDIO[mediaGroup]) {
|
28012 | var properties = mediaGroups.AUDIO[mediaGroup][label];
|
28013 |
|
28014 | if (!properties.uri) {
|
28015 | defaultDemuxed = false;
|
28016 | }
|
28017 | }
|
28018 | }
|
28019 |
|
28020 | if (defaultDemuxed) {
|
28021 | this.tech_.trigger({
|
28022 | type: 'usage',
|
28023 | name: 'vhs-demuxed'
|
28024 | });
|
28025 | this.tech_.trigger({
|
28026 | type: 'usage',
|
28027 | name: 'hls-demuxed'
|
28028 | });
|
28029 | }
|
28030 |
|
28031 | if (Object.keys(mediaGroups.SUBTITLES).length) {
|
28032 | this.tech_.trigger({
|
28033 | type: 'usage',
|
28034 | name: 'vhs-webvtt'
|
28035 | });
|
28036 | this.tech_.trigger({
|
28037 | type: 'usage',
|
28038 | name: 'hls-webvtt'
|
28039 | });
|
28040 | }
|
28041 |
|
28042 | if (Vhs$1.Playlist.isAes(media)) {
|
28043 | this.tech_.trigger({
|
28044 | type: 'usage',
|
28045 | name: 'vhs-aes'
|
28046 | });
|
28047 | this.tech_.trigger({
|
28048 | type: 'usage',
|
28049 | name: 'hls-aes'
|
28050 | });
|
28051 | }
|
28052 |
|
28053 | if (audioGroupKeys.length && Object.keys(mediaGroups.AUDIO[audioGroupKeys[0]]).length > 1) {
|
28054 | this.tech_.trigger({
|
28055 | type: 'usage',
|
28056 | name: 'vhs-alternate-audio'
|
28057 | });
|
28058 | this.tech_.trigger({
|
28059 | type: 'usage',
|
28060 | name: 'hls-alternate-audio'
|
28061 | });
|
28062 | }
|
28063 |
|
28064 | if (this.useCueTags_) {
|
28065 | this.tech_.trigger({
|
28066 | type: 'usage',
|
28067 | name: 'vhs-playlist-cue-tags'
|
28068 | });
|
28069 | this.tech_.trigger({
|
28070 | type: 'usage',
|
28071 | name: 'hls-playlist-cue-tags'
|
28072 | });
|
28073 | }
|
28074 | };
|
28075 |
|
28076 | _proto.shouldSwitchToMedia_ = function shouldSwitchToMedia_(nextPlaylist) {
|
28077 | var currentPlaylist = this.masterPlaylistLoader_.media();
|
28078 | var buffered = this.tech_.buffered();
|
28079 | var forwardBuffer = buffered.length ? buffered.end(buffered.length - 1) - this.tech_.currentTime() : 0;
|
28080 | var bufferLowWaterLine = this.bufferLowWaterLine();
|
28081 | var bufferHighWaterLine = this.bufferHighWaterLine();
|
28082 | return shouldSwitchToMedia({
|
28083 | currentPlaylist: currentPlaylist,
|
28084 | nextPlaylist: nextPlaylist,
|
28085 | forwardBuffer: forwardBuffer,
|
28086 | bufferLowWaterLine: bufferLowWaterLine,
|
28087 | bufferHighWaterLine: bufferHighWaterLine,
|
28088 | duration: this.duration(),
|
28089 | experimentalBufferBasedABR: this.experimentalBufferBasedABR,
|
28090 | log: this.logger_
|
28091 | });
|
28092 | }
|
28093 | |
28094 |
|
28095 |
|
28096 |
|
28097 |
|
28098 |
|
28099 | ;
|
28100 |
|
28101 | _proto.setupSegmentLoaderListeners_ = function setupSegmentLoaderListeners_() {
|
28102 | var _this4 = this;
|
28103 |
|
28104 | if (!this.experimentalBufferBasedABR) {
|
28105 | this.mainSegmentLoader_.on('bandwidthupdate', function () {
|
28106 | var nextPlaylist = _this4.selectPlaylist();
|
28107 |
|
28108 | if (_this4.shouldSwitchToMedia_(nextPlaylist)) {
|
28109 | _this4.switchMedia_(nextPlaylist, 'bandwidthupdate');
|
28110 | }
|
28111 |
|
28112 | _this4.tech_.trigger('bandwidthupdate');
|
28113 | });
|
28114 | this.mainSegmentLoader_.on('progress', function () {
|
28115 | _this4.trigger('progress');
|
28116 | });
|
28117 | }
|
28118 |
|
28119 | this.mainSegmentLoader_.on('error', function () {
|
28120 | _this4.blacklistCurrentPlaylist(_this4.mainSegmentLoader_.error());
|
28121 | });
|
28122 | this.mainSegmentLoader_.on('appenderror', function () {
|
28123 | _this4.error = _this4.mainSegmentLoader_.error_;
|
28124 |
|
28125 | _this4.trigger('error');
|
28126 | });
|
28127 | this.mainSegmentLoader_.on('syncinfoupdate', function () {
|
28128 | _this4.onSyncInfoUpdate_();
|
28129 | });
|
28130 | this.mainSegmentLoader_.on('timestampoffset', function () {
|
28131 | _this4.tech_.trigger({
|
28132 | type: 'usage',
|
28133 | name: 'vhs-timestamp-offset'
|
28134 | });
|
28135 |
|
28136 | _this4.tech_.trigger({
|
28137 | type: 'usage',
|
28138 | name: 'hls-timestamp-offset'
|
28139 | });
|
28140 | });
|
28141 | this.audioSegmentLoader_.on('syncinfoupdate', function () {
|
28142 | _this4.onSyncInfoUpdate_();
|
28143 | });
|
28144 | this.audioSegmentLoader_.on('appenderror', function () {
|
28145 | _this4.error = _this4.audioSegmentLoader_.error_;
|
28146 |
|
28147 | _this4.trigger('error');
|
28148 | });
|
28149 | this.mainSegmentLoader_.on('ended', function () {
|
28150 | _this4.logger_('main segment loader ended');
|
28151 |
|
28152 | _this4.onEndOfStream();
|
28153 | });
|
28154 | this.mainSegmentLoader_.on('earlyabort', function (event) {
|
28155 |
|
28156 | if (_this4.experimentalBufferBasedABR) {
|
28157 | return;
|
28158 | }
|
28159 |
|
28160 | _this4.delegateLoaders_('all', ['abort']);
|
28161 |
|
28162 | _this4.blacklistCurrentPlaylist({
|
28163 | message: 'Aborted early because there isn\'t enough bandwidth to complete the ' + 'request without rebuffering.'
|
28164 | }, ABORT_EARLY_BLACKLIST_SECONDS);
|
28165 | });
|
28166 |
|
28167 | var updateCodecs = function updateCodecs() {
|
28168 | if (!_this4.sourceUpdater_.hasCreatedSourceBuffers()) {
|
28169 | return _this4.tryToCreateSourceBuffers_();
|
28170 | }
|
28171 |
|
28172 | var codecs = _this4.getCodecsOrExclude_();
|
28173 |
|
28174 |
|
28175 | if (!codecs) {
|
28176 | return;
|
28177 | }
|
28178 |
|
28179 | _this4.sourceUpdater_.addOrChangeSourceBuffers(codecs);
|
28180 | };
|
28181 |
|
28182 | this.mainSegmentLoader_.on('trackinfo', updateCodecs);
|
28183 | this.audioSegmentLoader_.on('trackinfo', updateCodecs);
|
28184 | this.mainSegmentLoader_.on('fmp4', function () {
|
28185 | if (!_this4.triggeredFmp4Usage) {
|
28186 | _this4.tech_.trigger({
|
28187 | type: 'usage',
|
28188 | name: 'vhs-fmp4'
|
28189 | });
|
28190 |
|
28191 | _this4.tech_.trigger({
|
28192 | type: 'usage',
|
28193 | name: 'hls-fmp4'
|
28194 | });
|
28195 |
|
28196 | _this4.triggeredFmp4Usage = true;
|
28197 | }
|
28198 | });
|
28199 | this.audioSegmentLoader_.on('fmp4', function () {
|
28200 | if (!_this4.triggeredFmp4Usage) {
|
28201 | _this4.tech_.trigger({
|
28202 | type: 'usage',
|
28203 | name: 'vhs-fmp4'
|
28204 | });
|
28205 |
|
28206 | _this4.tech_.trigger({
|
28207 | type: 'usage',
|
28208 | name: 'hls-fmp4'
|
28209 | });
|
28210 |
|
28211 | _this4.triggeredFmp4Usage = true;
|
28212 | }
|
28213 | });
|
28214 | this.audioSegmentLoader_.on('ended', function () {
|
28215 | _this4.logger_('audioSegmentLoader ended');
|
28216 |
|
28217 | _this4.onEndOfStream();
|
28218 | });
|
28219 | };
|
28220 |
|
28221 | _proto.mediaSecondsLoaded_ = function mediaSecondsLoaded_() {
|
28222 | return Math.max(this.audioSegmentLoader_.mediaSecondsLoaded + this.mainSegmentLoader_.mediaSecondsLoaded);
|
28223 | }
|
28224 | |
28225 |
|
28226 |
|
28227 | ;
|
28228 |
|
28229 | _proto.load = function load() {
|
28230 | this.mainSegmentLoader_.load();
|
28231 |
|
28232 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
28233 | this.audioSegmentLoader_.load();
|
28234 | }
|
28235 |
|
28236 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
28237 | this.subtitleSegmentLoader_.load();
|
28238 | }
|
28239 | }
|
28240 | |
28241 |
|
28242 |
|
28243 |
|
28244 |
|
28245 |
|
28246 |
|
28247 |
|
28248 | ;
|
28249 |
|
28250 | _proto.smoothQualityChange_ = function smoothQualityChange_(media) {
|
28251 | if (media === void 0) {
|
28252 | media = this.selectPlaylist();
|
28253 | }
|
28254 |
|
28255 | this.fastQualityChange_(media);
|
28256 | }
|
28257 | |
28258 |
|
28259 |
|
28260 |
|
28261 |
|
28262 |
|
28263 |
|
28264 |
|
28265 | ;
|
28266 |
|
28267 | _proto.fastQualityChange_ = function fastQualityChange_(media) {
|
28268 | var _this5 = this;
|
28269 |
|
28270 | if (media === void 0) {
|
28271 | media = this.selectPlaylist();
|
28272 | }
|
28273 |
|
28274 | if (media === this.masterPlaylistLoader_.media()) {
|
28275 | this.logger_('skipping fastQualityChange because new media is same as old');
|
28276 | return;
|
28277 | }
|
28278 |
|
28279 | this.switchMedia_(media, 'fast-quality');
|
28280 |
|
28281 |
|
28282 |
|
28283 |
|
28284 |
|
28285 |
|
28286 | this.mainSegmentLoader_.resetEverything(function () {
|
28287 |
|
28288 |
|
28289 | if (videojs__default["default"].browser.IE_VERSION || videojs__default["default"].browser.IS_EDGE) {
|
28290 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime() + 0.04);
|
28291 | } else {
|
28292 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime());
|
28293 | }
|
28294 | });
|
28295 | }
|
28296 | |
28297 |
|
28298 |
|
28299 | ;
|
28300 |
|
28301 | _proto.play = function play() {
|
28302 | if (this.setupFirstPlay()) {
|
28303 | return;
|
28304 | }
|
28305 |
|
28306 | if (this.tech_.ended()) {
|
28307 | this.tech_.setCurrentTime(0);
|
28308 | }
|
28309 |
|
28310 | if (this.hasPlayed_) {
|
28311 | this.load();
|
28312 | }
|
28313 |
|
28314 | var seekable = this.tech_.seekable();
|
28315 |
|
28316 |
|
28317 | if (this.tech_.duration() === Infinity) {
|
28318 | if (this.tech_.currentTime() < seekable.start(0)) {
|
28319 | return this.tech_.setCurrentTime(seekable.end(seekable.length - 1));
|
28320 | }
|
28321 | }
|
28322 | }
|
28323 | |
28324 |
|
28325 |
|
28326 |
|
28327 | ;
|
28328 |
|
28329 | _proto.setupFirstPlay = function setupFirstPlay() {
|
28330 | var _this6 = this;
|
28331 |
|
28332 | var media = this.masterPlaylistLoader_.media();
|
28333 |
|
28334 |
|
28335 |
|
28336 |
|
28337 |
|
28338 | if (!media || this.tech_.paused() || this.hasPlayed_) {
|
28339 | return false;
|
28340 | }
|
28341 |
|
28342 |
|
28343 | if (!media.endList) {
|
28344 | var seekable = this.seekable();
|
28345 |
|
28346 | if (!seekable.length) {
|
28347 |
|
28348 |
|
28349 | return false;
|
28350 | }
|
28351 |
|
28352 | if (videojs__default["default"].browser.IE_VERSION && this.tech_.readyState() === 0) {
|
28353 |
|
28354 |
|
28355 | this.tech_.one('loadedmetadata', function () {
|
28356 | _this6.trigger('firstplay');
|
28357 |
|
28358 | _this6.tech_.setCurrentTime(seekable.end(0));
|
28359 |
|
28360 | _this6.hasPlayed_ = true;
|
28361 | });
|
28362 | return false;
|
28363 | }
|
28364 |
|
28365 |
|
28366 | this.trigger('firstplay');
|
28367 |
|
28368 | this.tech_.setCurrentTime(seekable.end(0));
|
28369 | }
|
28370 |
|
28371 | this.hasPlayed_ = true;
|
28372 |
|
28373 | this.load();
|
28374 | return true;
|
28375 | }
|
28376 | |
28377 |
|
28378 |
|
28379 |
|
28380 |
|
28381 | ;
|
28382 |
|
28383 | _proto.handleSourceOpen_ = function handleSourceOpen_() {
|
28384 |
|
28385 |
|
28386 |
|
28387 | this.tryToCreateSourceBuffers_();
|
28388 |
|
28389 |
|
28390 |
|
28391 | if (this.tech_.autoplay()) {
|
28392 | var playPromise = this.tech_.play();
|
28393 |
|
28394 |
|
28395 | if (typeof playPromise !== 'undefined' && typeof playPromise.then === 'function') {
|
28396 | playPromise.then(null, function (e) {});
|
28397 | }
|
28398 | }
|
28399 |
|
28400 | this.trigger('sourceopen');
|
28401 | }
|
28402 | |
28403 |
|
28404 |
|
28405 |
|
28406 |
|
28407 | ;
|
28408 |
|
28409 | _proto.handleSourceEnded_ = function handleSourceEnded_() {
|
28410 | if (!this.inbandTextTracks_.metadataTrack_) {
|
28411 | return;
|
28412 | }
|
28413 |
|
28414 | var cues = this.inbandTextTracks_.metadataTrack_.cues;
|
28415 |
|
28416 | if (!cues || !cues.length) {
|
28417 | return;
|
28418 | }
|
28419 |
|
28420 | var duration = this.duration();
|
28421 | cues[cues.length - 1].endTime = isNaN(duration) || Math.abs(duration) === Infinity ? Number.MAX_VALUE : duration;
|
28422 | }
|
28423 | |
28424 |
|
28425 |
|
28426 |
|
28427 |
|
28428 | ;
|
28429 |
|
28430 | _proto.handleDurationChange_ = function handleDurationChange_() {
|
28431 | this.tech_.trigger('durationchange');
|
28432 | }
|
28433 | |
28434 |
|
28435 |
|
28436 |
|
28437 |
|
28438 |
|
28439 |
|
28440 |
|
28441 | ;
|
28442 |
|
28443 | _proto.onEndOfStream = function onEndOfStream() {
|
28444 | var isEndOfStream = this.mainSegmentLoader_.ended_;
|
28445 |
|
28446 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
28447 | var mainMediaInfo = this.mainSegmentLoader_.getCurrentMediaInfo_();
|
28448 |
|
28449 | if (!mainMediaInfo || mainMediaInfo.hasVideo) {
|
28450 |
|
28451 |
|
28452 |
|
28453 | isEndOfStream = isEndOfStream && this.audioSegmentLoader_.ended_;
|
28454 | } else {
|
28455 |
|
28456 | isEndOfStream = this.audioSegmentLoader_.ended_;
|
28457 | }
|
28458 | }
|
28459 |
|
28460 | if (!isEndOfStream) {
|
28461 | return;
|
28462 | }
|
28463 |
|
28464 | this.stopABRTimer_();
|
28465 | this.sourceUpdater_.endOfStream();
|
28466 | }
|
28467 | |
28468 |
|
28469 |
|
28470 |
|
28471 |
|
28472 |
|
28473 | ;
|
28474 |
|
28475 | _proto.stuckAtPlaylistEnd_ = function stuckAtPlaylistEnd_(playlist) {
|
28476 | var seekable = this.seekable();
|
28477 |
|
28478 | if (!seekable.length) {
|
28479 |
|
28480 | return false;
|
28481 | }
|
28482 |
|
28483 | var expired = this.syncController_.getExpiredTime(playlist, this.duration());
|
28484 |
|
28485 | if (expired === null) {
|
28486 | return false;
|
28487 | }
|
28488 |
|
28489 |
|
28490 |
|
28491 | var absolutePlaylistEnd = Vhs$1.Playlist.playlistEnd(playlist, expired);
|
28492 | var currentTime = this.tech_.currentTime();
|
28493 | var buffered = this.tech_.buffered();
|
28494 |
|
28495 | if (!buffered.length) {
|
28496 |
|
28497 | return absolutePlaylistEnd - currentTime <= SAFE_TIME_DELTA;
|
28498 | }
|
28499 |
|
28500 | var bufferedEnd = buffered.end(buffered.length - 1);
|
28501 |
|
28502 |
|
28503 | return bufferedEnd - currentTime <= SAFE_TIME_DELTA && absolutePlaylistEnd - bufferedEnd <= SAFE_TIME_DELTA;
|
28504 | }
|
28505 | |
28506 |
|
28507 |
|
28508 |
|
28509 |
|
28510 |
|
28511 |
|
28512 |
|
28513 |
|
28514 |
|
28515 | ;
|
28516 |
|
28517 | _proto.blacklistCurrentPlaylist = function blacklistCurrentPlaylist(error, blacklistDuration) {
|
28518 | if (error === void 0) {
|
28519 | error = {};
|
28520 | }
|
28521 |
|
28522 |
|
28523 |
|
28524 |
|
28525 |
|
28526 | var currentPlaylist = error.playlist || this.masterPlaylistLoader_.media();
|
28527 | blacklistDuration = blacklistDuration || error.blacklistDuration || this.blacklistDuration;
|
28528 |
|
28529 |
|
28530 | if (!currentPlaylist) {
|
28531 | this.error = error;
|
28532 |
|
28533 | if (this.mediaSource.readyState !== 'open') {
|
28534 | this.trigger('error');
|
28535 | } else {
|
28536 | this.sourceUpdater_.endOfStream('network');
|
28537 | }
|
28538 |
|
28539 | return;
|
28540 | }
|
28541 |
|
28542 | currentPlaylist.playlistErrors_++;
|
28543 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
28544 | var enabledPlaylists = playlists.filter(isEnabled);
|
28545 | var isFinalRendition = enabledPlaylists.length === 1 && enabledPlaylists[0] === currentPlaylist;
|
28546 |
|
28547 |
|
28548 | if (playlists.length === 1 && blacklistDuration !== Infinity) {
|
28549 | videojs__default["default"].log.warn("Problem encountered with playlist " + currentPlaylist.id + ". " + 'Trying again since it is the only playlist.');
|
28550 | this.tech_.trigger('retryplaylist');
|
28551 |
|
28552 | return this.masterPlaylistLoader_.load(isFinalRendition);
|
28553 | }
|
28554 |
|
28555 | if (isFinalRendition) {
|
28556 |
|
28557 |
|
28558 |
|
28559 |
|
28560 | var reincluded = false;
|
28561 | playlists.forEach(function (playlist) {
|
28562 |
|
28563 | if (playlist === currentPlaylist) {
|
28564 | return;
|
28565 | }
|
28566 |
|
28567 | var excludeUntil = playlist.excludeUntil;
|
28568 |
|
28569 | if (typeof excludeUntil !== 'undefined' && excludeUntil !== Infinity) {
|
28570 | reincluded = true;
|
28571 | delete playlist.excludeUntil;
|
28572 | }
|
28573 | });
|
28574 |
|
28575 | if (reincluded) {
|
28576 | videojs__default["default"].log.warn('Removing other playlists from the exclusion list because the last ' + 'rendition is about to be excluded.');
|
28577 |
|
28578 |
|
28579 |
|
28580 | this.tech_.trigger('retryplaylist');
|
28581 | }
|
28582 | }
|
28583 |
|
28584 |
|
28585 | var excludeUntil;
|
28586 |
|
28587 | if (currentPlaylist.playlistErrors_ > this.maxPlaylistRetries) {
|
28588 | excludeUntil = Infinity;
|
28589 | } else {
|
28590 | excludeUntil = Date.now() + blacklistDuration * 1000;
|
28591 | }
|
28592 |
|
28593 | currentPlaylist.excludeUntil = excludeUntil;
|
28594 |
|
28595 | if (error.reason) {
|
28596 | currentPlaylist.lastExcludeReason_ = error.reason;
|
28597 | }
|
28598 |
|
28599 | this.tech_.trigger('blacklistplaylist');
|
28600 | this.tech_.trigger({
|
28601 | type: 'usage',
|
28602 | name: 'vhs-rendition-blacklisted'
|
28603 | });
|
28604 | this.tech_.trigger({
|
28605 | type: 'usage',
|
28606 | name: 'hls-rendition-blacklisted'
|
28607 | });
|
28608 |
|
28609 |
|
28610 |
|
28611 |
|
28612 |
|
28613 | var nextPlaylist = this.selectPlaylist();
|
28614 |
|
28615 | if (!nextPlaylist) {
|
28616 | this.error = 'Playback cannot continue. No available working or supported playlists.';
|
28617 | this.trigger('error');
|
28618 | return;
|
28619 | }
|
28620 |
|
28621 | var logFn = error.internal ? this.logger_ : videojs__default["default"].log.warn;
|
28622 | var errorMessage = error.message ? ' ' + error.message : '';
|
28623 | logFn((error.internal ? 'Internal problem' : 'Problem') + " encountered with playlist " + currentPlaylist.id + "." + (errorMessage + " Switching to playlist " + nextPlaylist.id + "."));
|
28624 |
|
28625 | if (nextPlaylist.attributes.AUDIO !== currentPlaylist.attributes.AUDIO) {
|
28626 | this.delegateLoaders_('audio', ['abort', 'pause']);
|
28627 | }
|
28628 |
|
28629 |
|
28630 | if (nextPlaylist.attributes.SUBTITLES !== currentPlaylist.attributes.SUBTITLES) {
|
28631 | this.delegateLoaders_('subtitle', ['abort', 'pause']);
|
28632 | }
|
28633 |
|
28634 | this.delegateLoaders_('main', ['abort', 'pause']);
|
28635 | var delayDuration = nextPlaylist.targetDuration / 2 * 1000 || 5 * 1000;
|
28636 | var shouldDelay = typeof nextPlaylist.lastRequest === 'number' && Date.now() - nextPlaylist.lastRequest <= delayDuration;
|
28637 |
|
28638 | return this.switchMedia_(nextPlaylist, 'exclude', isFinalRendition || shouldDelay);
|
28639 | }
|
28640 | |
28641 |
|
28642 |
|
28643 | ;
|
28644 |
|
28645 | _proto.pauseLoading = function pauseLoading() {
|
28646 | this.delegateLoaders_('all', ['abort', 'pause']);
|
28647 | this.stopABRTimer_();
|
28648 | }
|
28649 | |
28650 |
|
28651 |
|
28652 |
|
28653 |
|
28654 |
|
28655 |
|
28656 |
|
28657 |
|
28658 |
|
28659 |
|
28660 |
|
28661 |
|
28662 |
|
28663 | ;
|
28664 |
|
28665 | _proto.delegateLoaders_ = function delegateLoaders_(filter, fnNames) {
|
28666 | var _this7 = this;
|
28667 |
|
28668 | var loaders = [];
|
28669 | var dontFilterPlaylist = filter === 'all';
|
28670 |
|
28671 | if (dontFilterPlaylist || filter === 'main') {
|
28672 | loaders.push(this.masterPlaylistLoader_);
|
28673 | }
|
28674 |
|
28675 | var mediaTypes = [];
|
28676 |
|
28677 | if (dontFilterPlaylist || filter === 'audio') {
|
28678 | mediaTypes.push('AUDIO');
|
28679 | }
|
28680 |
|
28681 | if (dontFilterPlaylist || filter === 'subtitle') {
|
28682 | mediaTypes.push('CLOSED-CAPTIONS');
|
28683 | mediaTypes.push('SUBTITLES');
|
28684 | }
|
28685 |
|
28686 | mediaTypes.forEach(function (mediaType) {
|
28687 | var loader = _this7.mediaTypes_[mediaType] && _this7.mediaTypes_[mediaType].activePlaylistLoader;
|
28688 |
|
28689 | if (loader) {
|
28690 | loaders.push(loader);
|
28691 | }
|
28692 | });
|
28693 | ['main', 'audio', 'subtitle'].forEach(function (name) {
|
28694 | var loader = _this7[name + "SegmentLoader_"];
|
28695 |
|
28696 | if (loader && (filter === name || filter === 'all')) {
|
28697 | loaders.push(loader);
|
28698 | }
|
28699 | });
|
28700 | loaders.forEach(function (loader) {
|
28701 | return fnNames.forEach(function (fnName) {
|
28702 | if (typeof loader[fnName] === 'function') {
|
28703 | loader[fnName]();
|
28704 | }
|
28705 | });
|
28706 | });
|
28707 | }
|
28708 | |
28709 |
|
28710 |
|
28711 |
|
28712 |
|
28713 |
|
28714 | ;
|
28715 |
|
28716 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
28717 | var buffered = findRange(this.tech_.buffered(), currentTime);
|
28718 |
|
28719 | if (!(this.masterPlaylistLoader_ && this.masterPlaylistLoader_.media())) {
|
28720 |
|
28721 | return 0;
|
28722 | }
|
28723 |
|
28724 |
|
28725 |
|
28726 | if (!this.masterPlaylistLoader_.media().segments) {
|
28727 | return 0;
|
28728 | }
|
28729 |
|
28730 |
|
28731 | if (buffered && buffered.length) {
|
28732 | return currentTime;
|
28733 | }
|
28734 |
|
28735 |
|
28736 |
|
28737 | this.mainSegmentLoader_.resetEverything();
|
28738 | this.mainSegmentLoader_.abort();
|
28739 |
|
28740 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
28741 | this.audioSegmentLoader_.resetEverything();
|
28742 | this.audioSegmentLoader_.abort();
|
28743 | }
|
28744 |
|
28745 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
28746 | this.subtitleSegmentLoader_.resetEverything();
|
28747 | this.subtitleSegmentLoader_.abort();
|
28748 | }
|
28749 |
|
28750 |
|
28751 | this.load();
|
28752 | }
|
28753 | |
28754 |
|
28755 |
|
28756 |
|
28757 |
|
28758 | ;
|
28759 |
|
28760 | _proto.duration = function duration() {
|
28761 | if (!this.masterPlaylistLoader_) {
|
28762 | return 0;
|
28763 | }
|
28764 |
|
28765 | var media = this.masterPlaylistLoader_.media();
|
28766 |
|
28767 | if (!media) {
|
28768 |
|
28769 | return 0;
|
28770 | }
|
28771 |
|
28772 |
|
28773 |
|
28774 |
|
28775 |
|
28776 |
|
28777 |
|
28778 |
|
28779 |
|
28780 |
|
28781 |
|
28782 | if (!media.endList) {
|
28783 | return Infinity;
|
28784 | }
|
28785 |
|
28786 |
|
28787 |
|
28788 | if (this.mediaSource) {
|
28789 | return this.mediaSource.duration;
|
28790 | }
|
28791 |
|
28792 | return Vhs$1.Playlist.duration(media);
|
28793 | }
|
28794 | |
28795 |
|
28796 |
|
28797 |
|
28798 |
|
28799 | ;
|
28800 |
|
28801 | _proto.seekable = function seekable() {
|
28802 | return this.seekable_;
|
28803 | };
|
28804 |
|
28805 | _proto.onSyncInfoUpdate_ = function onSyncInfoUpdate_() {
|
28806 | var audioSeekable;
|
28807 |
|
28808 | if (!this.masterPlaylistLoader_) {
|
28809 | return;
|
28810 | }
|
28811 |
|
28812 | var media = this.masterPlaylistLoader_.media();
|
28813 |
|
28814 | if (!media) {
|
28815 | return;
|
28816 | }
|
28817 |
|
28818 | var expired = this.syncController_.getExpiredTime(media, this.duration());
|
28819 |
|
28820 | if (expired === null) {
|
28821 |
|
28822 | return;
|
28823 | }
|
28824 |
|
28825 | var master = this.masterPlaylistLoader_.master;
|
28826 | var mainSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
28827 |
|
28828 | if (mainSeekable.length === 0) {
|
28829 | return;
|
28830 | }
|
28831 |
|
28832 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
28833 | media = this.mediaTypes_.AUDIO.activePlaylistLoader.media();
|
28834 | expired = this.syncController_.getExpiredTime(media, this.duration());
|
28835 |
|
28836 | if (expired === null) {
|
28837 | return;
|
28838 | }
|
28839 |
|
28840 | audioSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
28841 |
|
28842 | if (audioSeekable.length === 0) {
|
28843 | return;
|
28844 | }
|
28845 | }
|
28846 |
|
28847 | var oldEnd;
|
28848 | var oldStart;
|
28849 |
|
28850 | if (this.seekable_ && this.seekable_.length) {
|
28851 | oldEnd = this.seekable_.end(0);
|
28852 | oldStart = this.seekable_.start(0);
|
28853 | }
|
28854 |
|
28855 | if (!audioSeekable) {
|
28856 |
|
28857 |
|
28858 | this.seekable_ = mainSeekable;
|
28859 | } else if (audioSeekable.start(0) > mainSeekable.end(0) || mainSeekable.start(0) > audioSeekable.end(0)) {
|
28860 |
|
28861 | this.seekable_ = mainSeekable;
|
28862 | } else {
|
28863 | this.seekable_ = videojs__default["default"].createTimeRanges([[audioSeekable.start(0) > mainSeekable.start(0) ? audioSeekable.start(0) : mainSeekable.start(0), audioSeekable.end(0) < mainSeekable.end(0) ? audioSeekable.end(0) : mainSeekable.end(0)]]);
|
28864 | }
|
28865 |
|
28866 |
|
28867 | if (this.seekable_ && this.seekable_.length) {
|
28868 | if (this.seekable_.end(0) === oldEnd && this.seekable_.start(0) === oldStart) {
|
28869 | return;
|
28870 | }
|
28871 | }
|
28872 |
|
28873 | this.logger_("seekable updated [" + printableRange(this.seekable_) + "]");
|
28874 | this.tech_.trigger('seekablechanged');
|
28875 | }
|
28876 | |
28877 |
|
28878 |
|
28879 | ;
|
28880 |
|
28881 | _proto.updateDuration = function updateDuration(isLive) {
|
28882 | if (this.updateDuration_) {
|
28883 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
28884 | this.updateDuration_ = null;
|
28885 | }
|
28886 |
|
28887 | if (this.mediaSource.readyState !== 'open') {
|
28888 | this.updateDuration_ = this.updateDuration.bind(this, isLive);
|
28889 | this.mediaSource.addEventListener('sourceopen', this.updateDuration_);
|
28890 | return;
|
28891 | }
|
28892 |
|
28893 | if (isLive) {
|
28894 | var seekable = this.seekable();
|
28895 |
|
28896 | if (!seekable.length) {
|
28897 | return;
|
28898 | }
|
28899 |
|
28900 |
|
28901 |
|
28902 |
|
28903 |
|
28904 |
|
28905 |
|
28906 |
|
28907 |
|
28908 |
|
28909 |
|
28910 |
|
28911 |
|
28912 |
|
28913 |
|
28914 |
|
28915 |
|
28916 |
|
28917 |
|
28918 |
|
28919 |
|
28920 |
|
28921 |
|
28922 |
|
28923 | if (isNaN(this.mediaSource.duration) || this.mediaSource.duration < seekable.end(seekable.length - 1)) {
|
28924 | this.sourceUpdater_.setDuration(seekable.end(seekable.length - 1));
|
28925 | }
|
28926 |
|
28927 | return;
|
28928 | }
|
28929 |
|
28930 | var buffered = this.tech_.buffered();
|
28931 | var duration = Vhs$1.Playlist.duration(this.masterPlaylistLoader_.media());
|
28932 |
|
28933 | if (buffered.length > 0) {
|
28934 | duration = Math.max(duration, buffered.end(buffered.length - 1));
|
28935 | }
|
28936 |
|
28937 | if (this.mediaSource.duration !== duration) {
|
28938 | this.sourceUpdater_.setDuration(duration);
|
28939 | }
|
28940 | }
|
28941 | |
28942 |
|
28943 |
|
28944 |
|
28945 | ;
|
28946 |
|
28947 | _proto.dispose = function dispose() {
|
28948 | var _this8 = this;
|
28949 |
|
28950 | this.trigger('dispose');
|
28951 | this.decrypter_.terminate();
|
28952 | this.masterPlaylistLoader_.dispose();
|
28953 | this.mainSegmentLoader_.dispose();
|
28954 |
|
28955 | if (this.loadOnPlay_) {
|
28956 | this.tech_.off('play', this.loadOnPlay_);
|
28957 | }
|
28958 |
|
28959 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
28960 | var groups = _this8.mediaTypes_[type].groups;
|
28961 |
|
28962 | for (var id in groups) {
|
28963 | groups[id].forEach(function (group) {
|
28964 | if (group.playlistLoader) {
|
28965 | group.playlistLoader.dispose();
|
28966 | }
|
28967 | });
|
28968 | }
|
28969 | });
|
28970 | this.audioSegmentLoader_.dispose();
|
28971 | this.subtitleSegmentLoader_.dispose();
|
28972 | this.sourceUpdater_.dispose();
|
28973 | this.timelineChangeController_.dispose();
|
28974 | this.stopABRTimer_();
|
28975 |
|
28976 | if (this.updateDuration_) {
|
28977 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
28978 | }
|
28979 |
|
28980 | this.mediaSource.removeEventListener('durationchange', this.handleDurationChange_);
|
28981 |
|
28982 | this.mediaSource.removeEventListener('sourceopen', this.handleSourceOpen_);
|
28983 | this.mediaSource.removeEventListener('sourceended', this.handleSourceEnded_);
|
28984 | this.off();
|
28985 | }
|
28986 | |
28987 |
|
28988 |
|
28989 |
|
28990 |
|
28991 | ;
|
28992 |
|
28993 | _proto.master = function master() {
|
28994 | return this.masterPlaylistLoader_.master;
|
28995 | }
|
28996 | |
28997 |
|
28998 |
|
28999 |
|
29000 |
|
29001 | ;
|
29002 |
|
29003 | _proto.media = function media() {
|
29004 |
|
29005 | return this.masterPlaylistLoader_.media() || this.initialMedia_;
|
29006 | };
|
29007 |
|
29008 | _proto.areMediaTypesKnown_ = function areMediaTypesKnown_() {
|
29009 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
29010 | var hasMainMediaInfo = !!this.mainSegmentLoader_.getCurrentMediaInfo_();
|
29011 |
|
29012 |
|
29013 | var hasAudioMediaInfo = !usingAudioLoader ? true : !!this.audioSegmentLoader_.getCurrentMediaInfo_();
|
29014 |
|
29015 | if (!hasMainMediaInfo || !hasAudioMediaInfo) {
|
29016 | return false;
|
29017 | }
|
29018 |
|
29019 | return true;
|
29020 | };
|
29021 |
|
29022 | _proto.getCodecsOrExclude_ = function getCodecsOrExclude_() {
|
29023 | var _this9 = this;
|
29024 |
|
29025 | var media = {
|
29026 | main: this.mainSegmentLoader_.getCurrentMediaInfo_() || {},
|
29027 | audio: this.audioSegmentLoader_.getCurrentMediaInfo_() || {}
|
29028 | };
|
29029 |
|
29030 | media.video = media.main;
|
29031 | var playlistCodecs = codecsForPlaylist(this.master(), this.media());
|
29032 | var codecs = {};
|
29033 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
29034 |
|
29035 | if (media.main.hasVideo) {
|
29036 | codecs.video = playlistCodecs.video || media.main.videoCodec || DEFAULT_VIDEO_CODEC;
|
29037 | }
|
29038 |
|
29039 | if (media.main.isMuxed) {
|
29040 | codecs.video += "," + (playlistCodecs.audio || media.main.audioCodec || DEFAULT_AUDIO_CODEC);
|
29041 | }
|
29042 |
|
29043 | if (media.main.hasAudio && !media.main.isMuxed || media.audio.hasAudio || usingAudioLoader) {
|
29044 | codecs.audio = playlistCodecs.audio || media.main.audioCodec || media.audio.audioCodec || DEFAULT_AUDIO_CODEC;
|
29045 |
|
29046 | media.audio.isFmp4 = media.main.hasAudio && !media.main.isMuxed ? media.main.isFmp4 : media.audio.isFmp4;
|
29047 | }
|
29048 |
|
29049 |
|
29050 | if (!codecs.audio && !codecs.video) {
|
29051 | this.blacklistCurrentPlaylist({
|
29052 | playlist: this.media(),
|
29053 | message: 'Could not determine codecs for playlist.',
|
29054 | blacklistDuration: Infinity
|
29055 | });
|
29056 | return;
|
29057 | }
|
29058 |
|
29059 |
|
29060 | var supportFunction = function supportFunction(isFmp4, codec) {
|
29061 | return isFmp4 ? browserSupportsCodec(codec) : muxerSupportsCodec(codec);
|
29062 | };
|
29063 |
|
29064 | var unsupportedCodecs = {};
|
29065 | var unsupportedAudio;
|
29066 | ['video', 'audio'].forEach(function (type) {
|
29067 | if (codecs.hasOwnProperty(type) && !supportFunction(media[type].isFmp4, codecs[type])) {
|
29068 | var supporter = media[type].isFmp4 ? 'browser' : 'muxer';
|
29069 | unsupportedCodecs[supporter] = unsupportedCodecs[supporter] || [];
|
29070 | unsupportedCodecs[supporter].push(codecs[type]);
|
29071 |
|
29072 | if (type === 'audio') {
|
29073 | unsupportedAudio = supporter;
|
29074 | }
|
29075 | }
|
29076 | });
|
29077 |
|
29078 | if (usingAudioLoader && unsupportedAudio && this.media().attributes.AUDIO) {
|
29079 | var audioGroup = this.media().attributes.AUDIO;
|
29080 | this.master().playlists.forEach(function (variant) {
|
29081 | var variantAudioGroup = variant.attributes && variant.attributes.AUDIO;
|
29082 |
|
29083 | if (variantAudioGroup === audioGroup && variant !== _this9.media()) {
|
29084 | variant.excludeUntil = Infinity;
|
29085 | }
|
29086 | });
|
29087 | this.logger_("excluding audio group " + audioGroup + " as " + unsupportedAudio + " does not support codec(s): \"" + codecs.audio + "\"");
|
29088 | }
|
29089 |
|
29090 |
|
29091 | if (Object.keys(unsupportedCodecs).length) {
|
29092 | var message = Object.keys(unsupportedCodecs).reduce(function (acc, supporter) {
|
29093 | if (acc) {
|
29094 | acc += ', ';
|
29095 | }
|
29096 |
|
29097 | acc += supporter + " does not support codec(s): \"" + unsupportedCodecs[supporter].join(',') + "\"";
|
29098 | return acc;
|
29099 | }, '') + '.';
|
29100 | this.blacklistCurrentPlaylist({
|
29101 | playlist: this.media(),
|
29102 | internal: true,
|
29103 | message: message,
|
29104 | blacklistDuration: Infinity
|
29105 | });
|
29106 | return;
|
29107 | }
|
29108 |
|
29109 |
|
29110 | if (this.sourceUpdater_.hasCreatedSourceBuffers() && !this.sourceUpdater_.canChangeType()) {
|
29111 | var switchMessages = [];
|
29112 | ['video', 'audio'].forEach(function (type) {
|
29113 | var newCodec = (parseCodecs(_this9.sourceUpdater_.codecs[type] || '')[0] || {}).type;
|
29114 | var oldCodec = (parseCodecs(codecs[type] || '')[0] || {}).type;
|
29115 |
|
29116 | if (newCodec && oldCodec && newCodec.toLowerCase() !== oldCodec.toLowerCase()) {
|
29117 | switchMessages.push("\"" + _this9.sourceUpdater_.codecs[type] + "\" -> \"" + codecs[type] + "\"");
|
29118 | }
|
29119 | });
|
29120 |
|
29121 | if (switchMessages.length) {
|
29122 | this.blacklistCurrentPlaylist({
|
29123 | playlist: this.media(),
|
29124 | message: "Codec switching not supported: " + switchMessages.join(', ') + ".",
|
29125 | blacklistDuration: Infinity,
|
29126 | internal: true
|
29127 | });
|
29128 | return;
|
29129 | }
|
29130 | }
|
29131 |
|
29132 |
|
29133 |
|
29134 | return codecs;
|
29135 | }
|
29136 | |
29137 |
|
29138 |
|
29139 |
|
29140 |
|
29141 | ;
|
29142 |
|
29143 | _proto.tryToCreateSourceBuffers_ = function tryToCreateSourceBuffers_() {
|
29144 |
|
29145 |
|
29146 | if (this.mediaSource.readyState !== 'open' || this.sourceUpdater_.hasCreatedSourceBuffers()) {
|
29147 | return;
|
29148 | }
|
29149 |
|
29150 | if (!this.areMediaTypesKnown_()) {
|
29151 | return;
|
29152 | }
|
29153 |
|
29154 | var codecs = this.getCodecsOrExclude_();
|
29155 |
|
29156 | if (!codecs) {
|
29157 | return;
|
29158 | }
|
29159 |
|
29160 | this.sourceUpdater_.createSourceBuffers(codecs);
|
29161 | var codecString = [codecs.video, codecs.audio].filter(Boolean).join(',');
|
29162 | this.excludeIncompatibleVariants_(codecString);
|
29163 | }
|
29164 | |
29165 |
|
29166 |
|
29167 | ;
|
29168 |
|
29169 | _proto.excludeUnsupportedVariants_ = function excludeUnsupportedVariants_() {
|
29170 | var _this10 = this;
|
29171 |
|
29172 | var playlists = this.master().playlists;
|
29173 | var ids = [];
|
29174 |
|
29175 |
|
29176 | Object.keys(playlists).forEach(function (key) {
|
29177 | var variant = playlists[key];
|
29178 |
|
29179 | if (ids.indexOf(variant.id) !== -1) {
|
29180 | return;
|
29181 | }
|
29182 |
|
29183 | ids.push(variant.id);
|
29184 | var codecs = codecsForPlaylist(_this10.master, variant);
|
29185 | var unsupported = [];
|
29186 |
|
29187 | if (codecs.audio && !muxerSupportsCodec(codecs.audio) && !browserSupportsCodec(codecs.audio)) {
|
29188 | unsupported.push("audio codec " + codecs.audio);
|
29189 | }
|
29190 |
|
29191 | if (codecs.video && !muxerSupportsCodec(codecs.video) && !browserSupportsCodec(codecs.video)) {
|
29192 | unsupported.push("video codec " + codecs.video);
|
29193 | }
|
29194 |
|
29195 | if (codecs.text && codecs.text === 'stpp.ttml.im1t') {
|
29196 | unsupported.push("text codec " + codecs.text);
|
29197 | }
|
29198 |
|
29199 | if (unsupported.length) {
|
29200 | variant.excludeUntil = Infinity;
|
29201 |
|
29202 | _this10.logger_("excluding " + variant.id + " for unsupported: " + unsupported.join(', '));
|
29203 | }
|
29204 | });
|
29205 | }
|
29206 | |
29207 |
|
29208 |
|
29209 |
|
29210 |
|
29211 |
|
29212 |
|
29213 |
|
29214 |
|
29215 |
|
29216 |
|
29217 |
|
29218 |
|
29219 |
|
29220 | ;
|
29221 |
|
29222 | _proto.excludeIncompatibleVariants_ = function excludeIncompatibleVariants_(codecString) {
|
29223 | var _this11 = this;
|
29224 |
|
29225 | var ids = [];
|
29226 | var playlists = this.master().playlists;
|
29227 | var codecs = unwrapCodecList(parseCodecs(codecString));
|
29228 | var codecCount_ = codecCount(codecs);
|
29229 | var videoDetails = codecs.video && parseCodecs(codecs.video)[0] || null;
|
29230 | var audioDetails = codecs.audio && parseCodecs(codecs.audio)[0] || null;
|
29231 | Object.keys(playlists).forEach(function (key) {
|
29232 | var variant = playlists[key];
|
29233 |
|
29234 |
|
29235 | if (ids.indexOf(variant.id) !== -1 || variant.excludeUntil === Infinity) {
|
29236 | return;
|
29237 | }
|
29238 |
|
29239 | ids.push(variant.id);
|
29240 | var blacklistReasons = [];
|
29241 |
|
29242 | var variantCodecs = codecsForPlaylist(_this11.masterPlaylistLoader_.master, variant);
|
29243 | var variantCodecCount = codecCount(variantCodecs);
|
29244 |
|
29245 |
|
29246 | if (!variantCodecs.audio && !variantCodecs.video) {
|
29247 | return;
|
29248 | }
|
29249 |
|
29250 |
|
29251 |
|
29252 |
|
29253 | if (variantCodecCount !== codecCount_) {
|
29254 | blacklistReasons.push("codec count \"" + variantCodecCount + "\" !== \"" + codecCount_ + "\"");
|
29255 | }
|
29256 |
|
29257 |
|
29258 |
|
29259 | if (!_this11.sourceUpdater_.canChangeType()) {
|
29260 | var variantVideoDetails = variantCodecs.video && parseCodecs(variantCodecs.video)[0] || null;
|
29261 | var variantAudioDetails = variantCodecs.audio && parseCodecs(variantCodecs.audio)[0] || null;
|
29262 |
|
29263 | if (variantVideoDetails && videoDetails && variantVideoDetails.type.toLowerCase() !== videoDetails.type.toLowerCase()) {
|
29264 | blacklistReasons.push("video codec \"" + variantVideoDetails.type + "\" !== \"" + videoDetails.type + "\"");
|
29265 | }
|
29266 |
|
29267 |
|
29268 | if (variantAudioDetails && audioDetails && variantAudioDetails.type.toLowerCase() !== audioDetails.type.toLowerCase()) {
|
29269 | blacklistReasons.push("audio codec \"" + variantAudioDetails.type + "\" !== \"" + audioDetails.type + "\"");
|
29270 | }
|
29271 | }
|
29272 |
|
29273 | if (blacklistReasons.length) {
|
29274 | variant.excludeUntil = Infinity;
|
29275 |
|
29276 | _this11.logger_("blacklisting " + variant.id + ": " + blacklistReasons.join(' && '));
|
29277 | }
|
29278 | });
|
29279 | };
|
29280 |
|
29281 | _proto.updateAdCues_ = function updateAdCues_(media) {
|
29282 | var offset = 0;
|
29283 | var seekable = this.seekable();
|
29284 |
|
29285 | if (seekable.length) {
|
29286 | offset = seekable.start(0);
|
29287 | }
|
29288 |
|
29289 | updateAdCues(media, this.cueTagsTrack_, offset);
|
29290 | }
|
29291 | |
29292 |
|
29293 |
|
29294 |
|
29295 |
|
29296 | ;
|
29297 |
|
29298 | _proto.goalBufferLength = function goalBufferLength() {
|
29299 | var currentTime = this.tech_.currentTime();
|
29300 | var initial = Config.GOAL_BUFFER_LENGTH;
|
29301 | var rate = Config.GOAL_BUFFER_LENGTH_RATE;
|
29302 | var max = Math.max(initial, Config.MAX_GOAL_BUFFER_LENGTH);
|
29303 | return Math.min(initial + currentTime * rate, max);
|
29304 | }
|
29305 | |
29306 |
|
29307 |
|
29308 |
|
29309 |
|
29310 | ;
|
29311 |
|
29312 | _proto.bufferLowWaterLine = function bufferLowWaterLine() {
|
29313 | var currentTime = this.tech_.currentTime();
|
29314 | var initial = Config.BUFFER_LOW_WATER_LINE;
|
29315 | var rate = Config.BUFFER_LOW_WATER_LINE_RATE;
|
29316 | var max = Math.max(initial, Config.MAX_BUFFER_LOW_WATER_LINE);
|
29317 | var newMax = Math.max(initial, Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE);
|
29318 | return Math.min(initial + currentTime * rate, this.experimentalBufferBasedABR ? newMax : max);
|
29319 | };
|
29320 |
|
29321 | _proto.bufferHighWaterLine = function bufferHighWaterLine() {
|
29322 | return Config.BUFFER_HIGH_WATER_LINE;
|
29323 | };
|
29324 |
|
29325 | return MasterPlaylistController;
|
29326 | }(videojs__default["default"].EventTarget);
|
29327 |
|
29328 | |
29329 |
|
29330 |
|
29331 |
|
29332 |
|
29333 |
|
29334 |
|
29335 |
|
29336 |
|
29337 |
|
29338 |
|
29339 |
|
29340 |
|
29341 | var enableFunction = function enableFunction(loader, playlistID, changePlaylistFn) {
|
29342 | return function (enable) {
|
29343 | var playlist = loader.master.playlists[playlistID];
|
29344 | var incompatible = isIncompatible(playlist);
|
29345 | var currentlyEnabled = isEnabled(playlist);
|
29346 |
|
29347 | if (typeof enable === 'undefined') {
|
29348 | return currentlyEnabled;
|
29349 | }
|
29350 |
|
29351 | if (enable) {
|
29352 | delete playlist.disabled;
|
29353 | } else {
|
29354 | playlist.disabled = true;
|
29355 | }
|
29356 |
|
29357 | if (enable !== currentlyEnabled && !incompatible) {
|
29358 |
|
29359 | changePlaylistFn();
|
29360 |
|
29361 | if (enable) {
|
29362 | loader.trigger('renditionenabled');
|
29363 | } else {
|
29364 | loader.trigger('renditiondisabled');
|
29365 | }
|
29366 | }
|
29367 |
|
29368 | return enable;
|
29369 | };
|
29370 | };
|
29371 | |
29372 |
|
29373 |
|
29374 |
|
29375 |
|
29376 |
|
29377 |
|
29378 |
|
29379 |
|
29380 | var Representation = function Representation(vhsHandler, playlist, id) {
|
29381 | var mpc = vhsHandler.masterPlaylistController_,
|
29382 | smoothQualityChange = vhsHandler.options_.smoothQualityChange;
|
29383 |
|
29384 | var changeType = smoothQualityChange ? 'smooth' : 'fast';
|
29385 | var qualityChangeFunction = mpc[changeType + "QualityChange_"].bind(mpc);
|
29386 |
|
29387 | if (playlist.attributes) {
|
29388 | var resolution = playlist.attributes.RESOLUTION;
|
29389 | this.width = resolution && resolution.width;
|
29390 | this.height = resolution && resolution.height;
|
29391 | this.bandwidth = playlist.attributes.BANDWIDTH;
|
29392 | }
|
29393 |
|
29394 | this.codecs = codecsForPlaylist(mpc.master(), playlist);
|
29395 | this.playlist = playlist;
|
29396 |
|
29397 |
|
29398 | this.id = id;
|
29399 |
|
29400 |
|
29401 | this.enabled = enableFunction(vhsHandler.playlists, playlist.id, qualityChangeFunction);
|
29402 | };
|
29403 | |
29404 |
|
29405 |
|
29406 |
|
29407 |
|
29408 |
|
29409 |
|
29410 |
|
29411 |
|
29412 | var renditionSelectionMixin = function renditionSelectionMixin(vhsHandler) {
|
29413 |
|
29414 | vhsHandler.representations = function () {
|
29415 | var master = vhsHandler.masterPlaylistController_.master();
|
29416 | var playlists = isAudioOnly(master) ? vhsHandler.masterPlaylistController_.getAudioTrackPlaylists_() : master.playlists;
|
29417 |
|
29418 | if (!playlists) {
|
29419 | return [];
|
29420 | }
|
29421 |
|
29422 | return playlists.filter(function (media) {
|
29423 | return !isIncompatible(media);
|
29424 | }).map(function (e, i) {
|
29425 | return new Representation(vhsHandler, e, e.id);
|
29426 | });
|
29427 | };
|
29428 | };
|
29429 |
|
29430 | |
29431 |
|
29432 |
|
29433 |
|
29434 |
|
29435 |
|
29436 |
|
29437 |
|
29438 |
|
29439 |
|
29440 | var timerCancelEvents = ['seeking', 'seeked', 'pause', 'playing', 'error'];
|
29441 | |
29442 |
|
29443 |
|
29444 |
|
29445 | var PlaybackWatcher = function () {
|
29446 | |
29447 |
|
29448 |
|
29449 |
|
29450 |
|
29451 |
|
29452 | function PlaybackWatcher(options) {
|
29453 | var _this = this;
|
29454 |
|
29455 | this.masterPlaylistController_ = options.masterPlaylistController;
|
29456 | this.tech_ = options.tech;
|
29457 | this.seekable = options.seekable;
|
29458 | this.allowSeeksWithinUnsafeLiveWindow = options.allowSeeksWithinUnsafeLiveWindow;
|
29459 | this.liveRangeSafeTimeDelta = options.liveRangeSafeTimeDelta;
|
29460 | this.media = options.media;
|
29461 | this.consecutiveUpdates = 0;
|
29462 | this.lastRecordedTime = null;
|
29463 | this.timer_ = null;
|
29464 | this.checkCurrentTimeTimeout_ = null;
|
29465 | this.logger_ = logger('PlaybackWatcher');
|
29466 | this.logger_('initialize');
|
29467 |
|
29468 | var playHandler = function playHandler() {
|
29469 | return _this.monitorCurrentTime_();
|
29470 | };
|
29471 |
|
29472 | var canPlayHandler = function canPlayHandler() {
|
29473 | return _this.monitorCurrentTime_();
|
29474 | };
|
29475 |
|
29476 | var waitingHandler = function waitingHandler() {
|
29477 | return _this.techWaiting_();
|
29478 | };
|
29479 |
|
29480 | var cancelTimerHandler = function cancelTimerHandler() {
|
29481 | return _this.cancelTimer_();
|
29482 | };
|
29483 |
|
29484 | var mpc = this.masterPlaylistController_;
|
29485 | var loaderTypes = ['main', 'subtitle', 'audio'];
|
29486 | var loaderChecks = {};
|
29487 | loaderTypes.forEach(function (type) {
|
29488 | loaderChecks[type] = {
|
29489 | reset: function reset() {
|
29490 | return _this.resetSegmentDownloads_(type);
|
29491 | },
|
29492 | updateend: function updateend() {
|
29493 | return _this.checkSegmentDownloads_(type);
|
29494 | }
|
29495 | };
|
29496 | mpc[type + "SegmentLoader_"].on('appendsdone', loaderChecks[type].updateend);
|
29497 |
|
29498 |
|
29499 |
|
29500 | mpc[type + "SegmentLoader_"].on('playlistupdate', loaderChecks[type].reset);
|
29501 |
|
29502 |
|
29503 |
|
29504 |
|
29505 | _this.tech_.on(['seeked', 'seeking'], loaderChecks[type].reset);
|
29506 | });
|
29507 | |
29508 |
|
29509 |
|
29510 |
|
29511 |
|
29512 |
|
29513 |
|
29514 |
|
29515 |
|
29516 | var setSeekingHandlers = function setSeekingHandlers(fn) {
|
29517 | ['main', 'audio'].forEach(function (type) {
|
29518 | mpc[type + "SegmentLoader_"][fn]('appended', _this.seekingAppendCheck_);
|
29519 | });
|
29520 | };
|
29521 |
|
29522 | this.seekingAppendCheck_ = function () {
|
29523 | if (_this.fixesBadSeeks_()) {
|
29524 | _this.consecutiveUpdates = 0;
|
29525 | _this.lastRecordedTime = _this.tech_.currentTime();
|
29526 | setSeekingHandlers('off');
|
29527 | }
|
29528 | };
|
29529 |
|
29530 | this.clearSeekingAppendCheck_ = function () {
|
29531 | return setSeekingHandlers('off');
|
29532 | };
|
29533 |
|
29534 | this.watchForBadSeeking_ = function () {
|
29535 | _this.clearSeekingAppendCheck_();
|
29536 |
|
29537 | setSeekingHandlers('on');
|
29538 | };
|
29539 |
|
29540 | this.tech_.on('seeked', this.clearSeekingAppendCheck_);
|
29541 | this.tech_.on('seeking', this.watchForBadSeeking_);
|
29542 | this.tech_.on('waiting', waitingHandler);
|
29543 | this.tech_.on(timerCancelEvents, cancelTimerHandler);
|
29544 | this.tech_.on('canplay', canPlayHandler);
|
29545 | |
29546 |
|
29547 |
|
29548 |
|
29549 |
|
29550 |
|
29551 |
|
29552 |
|
29553 |
|
29554 |
|
29555 |
|
29556 | this.tech_.one('play', playHandler);
|
29557 |
|
29558 | this.dispose = function () {
|
29559 | _this.clearSeekingAppendCheck_();
|
29560 |
|
29561 | _this.logger_('dispose');
|
29562 |
|
29563 | _this.tech_.off('waiting', waitingHandler);
|
29564 |
|
29565 | _this.tech_.off(timerCancelEvents, cancelTimerHandler);
|
29566 |
|
29567 | _this.tech_.off('canplay', canPlayHandler);
|
29568 |
|
29569 | _this.tech_.off('play', playHandler);
|
29570 |
|
29571 | _this.tech_.off('seeking', _this.watchForBadSeeking_);
|
29572 |
|
29573 | _this.tech_.off('seeked', _this.clearSeekingAppendCheck_);
|
29574 |
|
29575 | loaderTypes.forEach(function (type) {
|
29576 | mpc[type + "SegmentLoader_"].off('appendsdone', loaderChecks[type].updateend);
|
29577 | mpc[type + "SegmentLoader_"].off('playlistupdate', loaderChecks[type].reset);
|
29578 |
|
29579 | _this.tech_.off(['seeked', 'seeking'], loaderChecks[type].reset);
|
29580 | });
|
29581 |
|
29582 | if (_this.checkCurrentTimeTimeout_) {
|
29583 | window.clearTimeout(_this.checkCurrentTimeTimeout_);
|
29584 | }
|
29585 |
|
29586 | _this.cancelTimer_();
|
29587 | };
|
29588 | }
|
29589 | |
29590 |
|
29591 |
|
29592 |
|
29593 |
|
29594 |
|
29595 |
|
29596 | var _proto = PlaybackWatcher.prototype;
|
29597 |
|
29598 | _proto.monitorCurrentTime_ = function monitorCurrentTime_() {
|
29599 | this.checkCurrentTime_();
|
29600 |
|
29601 | if (this.checkCurrentTimeTimeout_) {
|
29602 | window.clearTimeout(this.checkCurrentTimeTimeout_);
|
29603 | }
|
29604 |
|
29605 |
|
29606 | this.checkCurrentTimeTimeout_ = window.setTimeout(this.monitorCurrentTime_.bind(this), 250);
|
29607 | }
|
29608 | |
29609 |
|
29610 |
|
29611 |
|
29612 |
|
29613 |
|
29614 |
|
29615 |
|
29616 |
|
29617 |
|
29618 | ;
|
29619 |
|
29620 | _proto.resetSegmentDownloads_ = function resetSegmentDownloads_(type) {
|
29621 | var loader = this.masterPlaylistController_[type + "SegmentLoader_"];
|
29622 |
|
29623 | if (this[type + "StalledDownloads_"] > 0) {
|
29624 | this.logger_("resetting possible stalled download count for " + type + " loader");
|
29625 | }
|
29626 |
|
29627 | this[type + "StalledDownloads_"] = 0;
|
29628 | this[type + "Buffered_"] = loader.buffered_();
|
29629 | }
|
29630 | |
29631 |
|
29632 |
|
29633 |
|
29634 |
|
29635 |
|
29636 |
|
29637 |
|
29638 |
|
29639 |
|
29640 | ;
|
29641 |
|
29642 | _proto.checkSegmentDownloads_ = function checkSegmentDownloads_(type) {
|
29643 | var mpc = this.masterPlaylistController_;
|
29644 | var loader = mpc[type + "SegmentLoader_"];
|
29645 | var buffered = loader.buffered_();
|
29646 | var isBufferedDifferent = isRangeDifferent(this[type + "Buffered_"], buffered);
|
29647 | this[type + "Buffered_"] = buffered;
|
29648 |
|
29649 |
|
29650 |
|
29651 | if (isBufferedDifferent) {
|
29652 | this.resetSegmentDownloads_(type);
|
29653 | return;
|
29654 | }
|
29655 |
|
29656 | this[type + "StalledDownloads_"]++;
|
29657 | this.logger_("found #" + this[type + "StalledDownloads_"] + " " + type + " appends that did not increase buffer (possible stalled download)", {
|
29658 | playlistId: loader.playlist_ && loader.playlist_.id,
|
29659 | buffered: timeRangesToArray(buffered)
|
29660 | });
|
29661 |
|
29662 | if (this[type + "StalledDownloads_"] < 10) {
|
29663 | return;
|
29664 | }
|
29665 |
|
29666 | this.logger_(type + " loader stalled download exclusion");
|
29667 | this.resetSegmentDownloads_(type);
|
29668 | this.tech_.trigger({
|
29669 | type: 'usage',
|
29670 | name: "vhs-" + type + "-download-exclusion"
|
29671 | });
|
29672 |
|
29673 | if (type === 'subtitle') {
|
29674 | return;
|
29675 | }
|
29676 |
|
29677 |
|
29678 |
|
29679 | mpc.blacklistCurrentPlaylist({
|
29680 | message: "Excessive " + type + " segment downloading detected."
|
29681 | }, Infinity);
|
29682 | }
|
29683 | |
29684 |
|
29685 |
|
29686 |
|
29687 |
|
29688 |
|
29689 |
|
29690 | ;
|
29691 |
|
29692 | _proto.checkCurrentTime_ = function checkCurrentTime_() {
|
29693 | if (this.tech_.paused() || this.tech_.seeking()) {
|
29694 | return;
|
29695 | }
|
29696 |
|
29697 | var currentTime = this.tech_.currentTime();
|
29698 | var buffered = this.tech_.buffered();
|
29699 |
|
29700 | if (this.lastRecordedTime === currentTime && (!buffered.length || currentTime + SAFE_TIME_DELTA >= buffered.end(buffered.length - 1))) {
|
29701 |
|
29702 |
|
29703 |
|
29704 |
|
29705 |
|
29706 | return this.techWaiting_();
|
29707 | }
|
29708 |
|
29709 | if (this.consecutiveUpdates >= 5 && currentTime === this.lastRecordedTime) {
|
29710 | this.consecutiveUpdates++;
|
29711 | this.waiting_();
|
29712 | } else if (currentTime === this.lastRecordedTime) {
|
29713 | this.consecutiveUpdates++;
|
29714 | } else {
|
29715 | this.consecutiveUpdates = 0;
|
29716 | this.lastRecordedTime = currentTime;
|
29717 | }
|
29718 | }
|
29719 | |
29720 |
|
29721 |
|
29722 |
|
29723 |
|
29724 |
|
29725 | ;
|
29726 |
|
29727 | _proto.cancelTimer_ = function cancelTimer_() {
|
29728 | this.consecutiveUpdates = 0;
|
29729 |
|
29730 | if (this.timer_) {
|
29731 | this.logger_('cancelTimer_');
|
29732 | clearTimeout(this.timer_);
|
29733 | }
|
29734 |
|
29735 | this.timer_ = null;
|
29736 | }
|
29737 | |
29738 |
|
29739 |
|
29740 |
|
29741 |
|
29742 |
|
29743 | ;
|
29744 |
|
29745 | _proto.fixesBadSeeks_ = function fixesBadSeeks_() {
|
29746 | var seeking = this.tech_.seeking();
|
29747 |
|
29748 | if (!seeking) {
|
29749 | return false;
|
29750 | }
|
29751 |
|
29752 |
|
29753 |
|
29754 |
|
29755 |
|
29756 | var seekable = this.seekable();
|
29757 | var currentTime = this.tech_.currentTime();
|
29758 | var isAfterSeekableRange = this.afterSeekableWindow_(seekable, currentTime, this.media(), this.allowSeeksWithinUnsafeLiveWindow);
|
29759 | var seekTo;
|
29760 |
|
29761 | if (isAfterSeekableRange) {
|
29762 | var seekableEnd = seekable.end(seekable.length - 1);
|
29763 |
|
29764 | seekTo = seekableEnd;
|
29765 | }
|
29766 |
|
29767 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
29768 | var seekableStart = seekable.start(0);
|
29769 |
|
29770 |
|
29771 | seekTo = seekableStart + (
|
29772 |
|
29773 | seekableStart === seekable.end(0) ? 0 : SAFE_TIME_DELTA);
|
29774 | }
|
29775 |
|
29776 | if (typeof seekTo !== 'undefined') {
|
29777 | this.logger_("Trying to seek outside of seekable at time " + currentTime + " with " + ("seekable range " + printableRange(seekable) + ". Seeking to ") + (seekTo + "."));
|
29778 | this.tech_.setCurrentTime(seekTo);
|
29779 | return true;
|
29780 | }
|
29781 |
|
29782 | var sourceUpdater = this.masterPlaylistController_.sourceUpdater_;
|
29783 | var buffered = this.tech_.buffered();
|
29784 | var audioBuffered = sourceUpdater.audioBuffer ? sourceUpdater.audioBuffered() : null;
|
29785 | var videoBuffered = sourceUpdater.videoBuffer ? sourceUpdater.videoBuffered() : null;
|
29786 |
|
29787 |
|
29788 | var twoSegmentDurations = (this.media().targetDuration - TIME_FUDGE_FACTOR) * 2;
|
29789 | var bufferedToCheck = [audioBuffered, videoBuffered];
|
29790 |
|
29791 | for (var i = 0; i < bufferedToCheck.length; i++) {
|
29792 |
|
29793 | if (!bufferedToCheck[i]) {
|
29794 | continue;
|
29795 | }
|
29796 |
|
29797 | var timeAhead = timeAheadOf(bufferedToCheck[i], currentTime);
|
29798 |
|
29799 |
|
29800 | if (timeAhead < twoSegmentDurations) {
|
29801 | return false;
|
29802 | }
|
29803 | }
|
29804 |
|
29805 | var nextRange = findNextRange(buffered, currentTime);
|
29806 |
|
29807 |
|
29808 | if (nextRange.length === 0) {
|
29809 | return false;
|
29810 | }
|
29811 |
|
29812 | seekTo = nextRange.start(0) + SAFE_TIME_DELTA;
|
29813 | this.logger_("Buffered region starts (" + nextRange.start(0) + ") " + (" just beyond seek point (" + currentTime + "). Seeking to " + seekTo + "."));
|
29814 | this.tech_.setCurrentTime(seekTo);
|
29815 | return true;
|
29816 | }
|
29817 | |
29818 |
|
29819 |
|
29820 |
|
29821 |
|
29822 | ;
|
29823 |
|
29824 | _proto.waiting_ = function waiting_() {
|
29825 | if (this.techWaiting_()) {
|
29826 | return;
|
29827 | }
|
29828 |
|
29829 |
|
29830 | var currentTime = this.tech_.currentTime();
|
29831 | var buffered = this.tech_.buffered();
|
29832 | var currentRange = findRange(buffered, currentTime);
|
29833 |
|
29834 |
|
29835 |
|
29836 |
|
29837 |
|
29838 |
|
29839 |
|
29840 |
|
29841 | if (currentRange.length && currentTime + 3 <= currentRange.end(0)) {
|
29842 | this.cancelTimer_();
|
29843 | this.tech_.setCurrentTime(currentTime);
|
29844 | this.logger_("Stopped at " + currentTime + " while inside a buffered region " + ("[" + currentRange.start(0) + " -> " + currentRange.end(0) + "]. Attempting to resume ") + 'playback by seeking to the current time.');
|
29845 |
|
29846 | this.tech_.trigger({
|
29847 | type: 'usage',
|
29848 | name: 'vhs-unknown-waiting'
|
29849 | });
|
29850 | this.tech_.trigger({
|
29851 | type: 'usage',
|
29852 | name: 'hls-unknown-waiting'
|
29853 | });
|
29854 | return;
|
29855 | }
|
29856 | }
|
29857 | |
29858 |
|
29859 |
|
29860 |
|
29861 |
|
29862 |
|
29863 |
|
29864 |
|
29865 | ;
|
29866 |
|
29867 | _proto.techWaiting_ = function techWaiting_() {
|
29868 | var seekable = this.seekable();
|
29869 | var currentTime = this.tech_.currentTime();
|
29870 |
|
29871 | if (this.tech_.seeking() || this.timer_ !== null) {
|
29872 |
|
29873 | return true;
|
29874 | }
|
29875 |
|
29876 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
29877 | var livePoint = seekable.end(seekable.length - 1);
|
29878 | this.logger_("Fell out of live window at time " + currentTime + ". Seeking to " + ("live point (seekable end) " + livePoint));
|
29879 | this.cancelTimer_();
|
29880 | this.tech_.setCurrentTime(livePoint);
|
29881 |
|
29882 | this.tech_.trigger({
|
29883 | type: 'usage',
|
29884 | name: 'vhs-live-resync'
|
29885 | });
|
29886 | this.tech_.trigger({
|
29887 | type: 'usage',
|
29888 | name: 'hls-live-resync'
|
29889 | });
|
29890 | return true;
|
29891 | }
|
29892 |
|
29893 | var sourceUpdater = this.tech_.vhs.masterPlaylistController_.sourceUpdater_;
|
29894 | var buffered = this.tech_.buffered();
|
29895 | var videoUnderflow = this.videoUnderflow_({
|
29896 | audioBuffered: sourceUpdater.audioBuffered(),
|
29897 | videoBuffered: sourceUpdater.videoBuffered(),
|
29898 | currentTime: currentTime
|
29899 | });
|
29900 |
|
29901 | if (videoUnderflow) {
|
29902 |
|
29903 |
|
29904 |
|
29905 |
|
29906 | this.cancelTimer_();
|
29907 | this.tech_.setCurrentTime(currentTime);
|
29908 |
|
29909 | this.tech_.trigger({
|
29910 | type: 'usage',
|
29911 | name: 'vhs-video-underflow'
|
29912 | });
|
29913 | this.tech_.trigger({
|
29914 | type: 'usage',
|
29915 | name: 'hls-video-underflow'
|
29916 | });
|
29917 | return true;
|
29918 | }
|
29919 |
|
29920 | var nextRange = findNextRange(buffered, currentTime);
|
29921 |
|
29922 | if (nextRange.length > 0) {
|
29923 | var difference = nextRange.start(0) - currentTime;
|
29924 | this.logger_("Stopped at " + currentTime + ", setting timer for " + difference + ", seeking " + ("to " + nextRange.start(0)));
|
29925 | this.cancelTimer_();
|
29926 | this.timer_ = setTimeout(this.skipTheGap_.bind(this), difference * 1000, currentTime);
|
29927 | return true;
|
29928 | }
|
29929 |
|
29930 |
|
29931 | return false;
|
29932 | };
|
29933 |
|
29934 | _proto.afterSeekableWindow_ = function afterSeekableWindow_(seekable, currentTime, playlist, allowSeeksWithinUnsafeLiveWindow) {
|
29935 | if (allowSeeksWithinUnsafeLiveWindow === void 0) {
|
29936 | allowSeeksWithinUnsafeLiveWindow = false;
|
29937 | }
|
29938 |
|
29939 | if (!seekable.length) {
|
29940 |
|
29941 | return false;
|
29942 | }
|
29943 |
|
29944 | var allowedEnd = seekable.end(seekable.length - 1) + SAFE_TIME_DELTA;
|
29945 | var isLive = !playlist.endList;
|
29946 |
|
29947 | if (isLive && allowSeeksWithinUnsafeLiveWindow) {
|
29948 | allowedEnd = seekable.end(seekable.length - 1) + playlist.targetDuration * 3;
|
29949 | }
|
29950 |
|
29951 | if (currentTime > allowedEnd) {
|
29952 | return true;
|
29953 | }
|
29954 |
|
29955 | return false;
|
29956 | };
|
29957 |
|
29958 | _proto.beforeSeekableWindow_ = function beforeSeekableWindow_(seekable, currentTime) {
|
29959 | if (seekable.length &&
|
29960 | seekable.start(0) > 0 && currentTime < seekable.start(0) - this.liveRangeSafeTimeDelta) {
|
29961 | return true;
|
29962 | }
|
29963 |
|
29964 | return false;
|
29965 | };
|
29966 |
|
29967 | _proto.videoUnderflow_ = function videoUnderflow_(_ref) {
|
29968 | var videoBuffered = _ref.videoBuffered,
|
29969 | audioBuffered = _ref.audioBuffered,
|
29970 | currentTime = _ref.currentTime;
|
29971 |
|
29972 |
|
29973 | if (!videoBuffered) {
|
29974 | return;
|
29975 | }
|
29976 |
|
29977 | var gap;
|
29978 |
|
29979 | if (videoBuffered.length && audioBuffered.length) {
|
29980 |
|
29981 |
|
29982 |
|
29983 | var lastVideoRange = findRange(videoBuffered, currentTime - 3);
|
29984 | var videoRange = findRange(videoBuffered, currentTime);
|
29985 | var audioRange = findRange(audioBuffered, currentTime);
|
29986 |
|
29987 | if (audioRange.length && !videoRange.length && lastVideoRange.length) {
|
29988 | gap = {
|
29989 | start: lastVideoRange.end(0),
|
29990 | end: audioRange.end(0)
|
29991 | };
|
29992 | }
|
29993 |
|
29994 | } else {
|
29995 | var nextRange = findNextRange(videoBuffered, currentTime);
|
29996 |
|
29997 |
|
29998 | if (!nextRange.length) {
|
29999 | gap = this.gapFromVideoUnderflow_(videoBuffered, currentTime);
|
30000 | }
|
30001 | }
|
30002 |
|
30003 | if (gap) {
|
30004 | this.logger_("Encountered a gap in video from " + gap.start + " to " + gap.end + ". " + ("Seeking to current time " + currentTime));
|
30005 | return true;
|
30006 | }
|
30007 |
|
30008 | return false;
|
30009 | }
|
30010 | |
30011 |
|
30012 |
|
30013 |
|
30014 |
|
30015 |
|
30016 | ;
|
30017 |
|
30018 | _proto.skipTheGap_ = function skipTheGap_(scheduledCurrentTime) {
|
30019 | var buffered = this.tech_.buffered();
|
30020 | var currentTime = this.tech_.currentTime();
|
30021 | var nextRange = findNextRange(buffered, currentTime);
|
30022 | this.cancelTimer_();
|
30023 |
|
30024 | if (nextRange.length === 0 || currentTime !== scheduledCurrentTime) {
|
30025 | return;
|
30026 | }
|
30027 |
|
30028 | this.logger_('skipTheGap_:', 'currentTime:', currentTime, 'scheduled currentTime:', scheduledCurrentTime, 'nextRange start:', nextRange.start(0));
|
30029 |
|
30030 | this.tech_.setCurrentTime(nextRange.start(0) + TIME_FUDGE_FACTOR);
|
30031 | this.tech_.trigger({
|
30032 | type: 'usage',
|
30033 | name: 'vhs-gap-skip'
|
30034 | });
|
30035 | this.tech_.trigger({
|
30036 | type: 'usage',
|
30037 | name: 'hls-gap-skip'
|
30038 | });
|
30039 | };
|
30040 |
|
30041 | _proto.gapFromVideoUnderflow_ = function gapFromVideoUnderflow_(buffered, currentTime) {
|
30042 |
|
30043 |
|
30044 |
|
30045 |
|
30046 |
|
30047 |
|
30048 |
|
30049 |
|
30050 |
|
30051 |
|
30052 |
|
30053 |
|
30054 |
|
30055 |
|
30056 |
|
30057 |
|
30058 |
|
30059 |
|
30060 |
|
30061 |
|
30062 |
|
30063 |
|
30064 | var gaps = findGaps(buffered);
|
30065 |
|
30066 | for (var i = 0; i < gaps.length; i++) {
|
30067 | var start = gaps.start(i);
|
30068 | var end = gaps.end(i);
|
30069 |
|
30070 | if (currentTime - start < 4 && currentTime - start > 2) {
|
30071 | return {
|
30072 | start: start,
|
30073 | end: end
|
30074 | };
|
30075 | }
|
30076 | }
|
30077 |
|
30078 | return null;
|
30079 | };
|
30080 |
|
30081 | return PlaybackWatcher;
|
30082 | }();
|
30083 |
|
30084 | var defaultOptions = {
|
30085 | errorInterval: 30,
|
30086 | getSource: function getSource(next) {
|
30087 | var tech = this.tech({
|
30088 | IWillNotUseThisInPlugins: true
|
30089 | });
|
30090 | var sourceObj = tech.currentSource_ || this.currentSource();
|
30091 | return next(sourceObj);
|
30092 | }
|
30093 | };
|
30094 | |
30095 |
|
30096 |
|
30097 |
|
30098 |
|
30099 |
|
30100 |
|
30101 |
|
30102 | var initPlugin = function initPlugin(player, options) {
|
30103 | var lastCalled = 0;
|
30104 | var seekTo = 0;
|
30105 | var localOptions = videojs__default["default"].mergeOptions(defaultOptions, options);
|
30106 | player.ready(function () {
|
30107 | player.trigger({
|
30108 | type: 'usage',
|
30109 | name: 'vhs-error-reload-initialized'
|
30110 | });
|
30111 | player.trigger({
|
30112 | type: 'usage',
|
30113 | name: 'hls-error-reload-initialized'
|
30114 | });
|
30115 | });
|
30116 | |
30117 |
|
30118 |
|
30119 |
|
30120 |
|
30121 |
|
30122 |
|
30123 | var loadedMetadataHandler = function loadedMetadataHandler() {
|
30124 | if (seekTo) {
|
30125 | player.currentTime(seekTo);
|
30126 | }
|
30127 | };
|
30128 | |
30129 |
|
30130 |
|
30131 |
|
30132 |
|
30133 |
|
30134 |
|
30135 |
|
30136 | var setSource = function setSource(sourceObj) {
|
30137 | if (sourceObj === null || sourceObj === undefined) {
|
30138 | return;
|
30139 | }
|
30140 |
|
30141 | seekTo = player.duration() !== Infinity && player.currentTime() || 0;
|
30142 | player.one('loadedmetadata', loadedMetadataHandler);
|
30143 | player.src(sourceObj);
|
30144 | player.trigger({
|
30145 | type: 'usage',
|
30146 | name: 'vhs-error-reload'
|
30147 | });
|
30148 | player.trigger({
|
30149 | type: 'usage',
|
30150 | name: 'hls-error-reload'
|
30151 | });
|
30152 | player.play();
|
30153 | };
|
30154 | |
30155 |
|
30156 |
|
30157 |
|
30158 |
|
30159 |
|
30160 |
|
30161 |
|
30162 | var errorHandler = function errorHandler() {
|
30163 |
|
30164 |
|
30165 | if (Date.now() - lastCalled < localOptions.errorInterval * 1000) {
|
30166 | player.trigger({
|
30167 | type: 'usage',
|
30168 | name: 'vhs-error-reload-canceled'
|
30169 | });
|
30170 | player.trigger({
|
30171 | type: 'usage',
|
30172 | name: 'hls-error-reload-canceled'
|
30173 | });
|
30174 | return;
|
30175 | }
|
30176 |
|
30177 | if (!localOptions.getSource || typeof localOptions.getSource !== 'function') {
|
30178 | videojs__default["default"].log.error('ERROR: reloadSourceOnError - The option getSource must be a function!');
|
30179 | return;
|
30180 | }
|
30181 |
|
30182 | lastCalled = Date.now();
|
30183 | return localOptions.getSource.call(player, setSource);
|
30184 | };
|
30185 | |
30186 |
|
30187 |
|
30188 |
|
30189 |
|
30190 |
|
30191 |
|
30192 | var cleanupEvents = function cleanupEvents() {
|
30193 | player.off('loadedmetadata', loadedMetadataHandler);
|
30194 | player.off('error', errorHandler);
|
30195 | player.off('dispose', cleanupEvents);
|
30196 | };
|
30197 | |
30198 |
|
30199 |
|
30200 |
|
30201 |
|
30202 |
|
30203 |
|
30204 |
|
30205 | var reinitPlugin = function reinitPlugin(newOptions) {
|
30206 | cleanupEvents();
|
30207 | initPlugin(player, newOptions);
|
30208 | };
|
30209 |
|
30210 | player.on('error', errorHandler);
|
30211 | player.on('dispose', cleanupEvents);
|
30212 |
|
30213 |
|
30214 | player.reloadSourceOnError = reinitPlugin;
|
30215 | };
|
30216 | |
30217 |
|
30218 |
|
30219 |
|
30220 |
|
30221 |
|
30222 |
|
30223 |
|
30224 | var reloadSourceOnError = function reloadSourceOnError(options) {
|
30225 | initPlugin(this, options);
|
30226 | };
|
30227 |
|
30228 | var version$4 = "2.11.1";
|
30229 |
|
30230 | var version$3 = "5.14.1";
|
30231 |
|
30232 | var version$2 = "0.19.2";
|
30233 |
|
30234 | var version$1 = "4.7.0";
|
30235 |
|
30236 | var version = "3.1.2";
|
30237 |
|
30238 | var Vhs = {
|
30239 | PlaylistLoader: PlaylistLoader,
|
30240 | Playlist: Playlist,
|
30241 | utils: utils,
|
30242 | STANDARD_PLAYLIST_SELECTOR: lastBandwidthSelector,
|
30243 | INITIAL_PLAYLIST_SELECTOR: lowestBitrateCompatibleVariantSelector,
|
30244 | lastBandwidthSelector: lastBandwidthSelector,
|
30245 | movingAverageBandwidthSelector: movingAverageBandwidthSelector,
|
30246 | comparePlaylistBandwidth: comparePlaylistBandwidth,
|
30247 | comparePlaylistResolution: comparePlaylistResolution,
|
30248 | xhr: xhrFactory()
|
30249 | };
|
30250 |
|
30251 | Object.keys(Config).forEach(function (prop) {
|
30252 | Object.defineProperty(Vhs, prop, {
|
30253 | get: function get() {
|
30254 | videojs__default["default"].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
30255 | return Config[prop];
|
30256 | },
|
30257 | set: function set(value) {
|
30258 | videojs__default["default"].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
30259 |
|
30260 | if (typeof value !== 'number' || value < 0) {
|
30261 | videojs__default["default"].log.warn("value of Vhs." + prop + " must be greater than or equal to 0");
|
30262 | return;
|
30263 | }
|
30264 |
|
30265 | Config[prop] = value;
|
30266 | }
|
30267 | });
|
30268 | });
|
30269 | var LOCAL_STORAGE_KEY = 'videojs-vhs';
|
30270 | |
30271 |
|
30272 |
|
30273 |
|
30274 |
|
30275 |
|
30276 |
|
30277 |
|
30278 | var handleVhsMediaChange = function handleVhsMediaChange(qualityLevels, playlistLoader) {
|
30279 | var newPlaylist = playlistLoader.media();
|
30280 | var selectedIndex = -1;
|
30281 |
|
30282 | for (var i = 0; i < qualityLevels.length; i++) {
|
30283 | if (qualityLevels[i].id === newPlaylist.id) {
|
30284 | selectedIndex = i;
|
30285 | break;
|
30286 | }
|
30287 | }
|
30288 |
|
30289 | qualityLevels.selectedIndex_ = selectedIndex;
|
30290 | qualityLevels.trigger({
|
30291 | selectedIndex: selectedIndex,
|
30292 | type: 'change'
|
30293 | });
|
30294 | };
|
30295 | |
30296 |
|
30297 |
|
30298 |
|
30299 |
|
30300 |
|
30301 |
|
30302 |
|
30303 |
|
30304 | var handleVhsLoadedMetadata = function handleVhsLoadedMetadata(qualityLevels, vhs) {
|
30305 | vhs.representations().forEach(function (rep) {
|
30306 | qualityLevels.addQualityLevel(rep);
|
30307 | });
|
30308 | handleVhsMediaChange(qualityLevels, vhs.playlists);
|
30309 | };
|
30310 |
|
30311 |
|
30312 |
|
30313 | Vhs.canPlaySource = function () {
|
30314 | return videojs__default["default"].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
30315 | };
|
30316 |
|
30317 | var emeKeySystems = function emeKeySystems(keySystemOptions, mainPlaylist, audioPlaylist) {
|
30318 | if (!keySystemOptions) {
|
30319 | return keySystemOptions;
|
30320 | }
|
30321 |
|
30322 | var codecs = {};
|
30323 |
|
30324 | if (mainPlaylist && mainPlaylist.attributes && mainPlaylist.attributes.CODECS) {
|
30325 | codecs = unwrapCodecList(parseCodecs(mainPlaylist.attributes.CODECS));
|
30326 | }
|
30327 |
|
30328 | if (audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS) {
|
30329 | codecs.audio = audioPlaylist.attributes.CODECS;
|
30330 | }
|
30331 |
|
30332 | var videoContentType = getMimeForCodec(codecs.video);
|
30333 | var audioContentType = getMimeForCodec(codecs.audio);
|
30334 |
|
30335 | var keySystemContentTypes = {};
|
30336 |
|
30337 | for (var keySystem in keySystemOptions) {
|
30338 | keySystemContentTypes[keySystem] = {};
|
30339 |
|
30340 | if (audioContentType) {
|
30341 | keySystemContentTypes[keySystem].audioContentType = audioContentType;
|
30342 | }
|
30343 |
|
30344 | if (videoContentType) {
|
30345 | keySystemContentTypes[keySystem].videoContentType = videoContentType;
|
30346 | }
|
30347 |
|
30348 |
|
30349 |
|
30350 |
|
30351 |
|
30352 |
|
30353 |
|
30354 | if (mainPlaylist.contentProtection && mainPlaylist.contentProtection[keySystem] && mainPlaylist.contentProtection[keySystem].pssh) {
|
30355 | keySystemContentTypes[keySystem].pssh = mainPlaylist.contentProtection[keySystem].pssh;
|
30356 | }
|
30357 |
|
30358 |
|
30359 |
|
30360 | if (typeof keySystemOptions[keySystem] === 'string') {
|
30361 | keySystemContentTypes[keySystem].url = keySystemOptions[keySystem];
|
30362 | }
|
30363 | }
|
30364 |
|
30365 | return videojs__default["default"].mergeOptions(keySystemOptions, keySystemContentTypes);
|
30366 | };
|
30367 | |
30368 |
|
30369 |
|
30370 |
|
30371 |
|
30372 |
|
30373 |
|
30374 |
|
30375 |
|
30376 |
|
30377 | |
30378 |
|
30379 |
|
30380 |
|
30381 |
|
30382 |
|
30383 |
|
30384 |
|
30385 |
|
30386 |
|
30387 |
|
30388 |
|
30389 |
|
30390 |
|
30391 |
|
30392 | var getAllPsshKeySystemsOptions = function getAllPsshKeySystemsOptions(playlists, keySystems) {
|
30393 | return playlists.reduce(function (keySystemsArr, playlist) {
|
30394 | if (!playlist.contentProtection) {
|
30395 | return keySystemsArr;
|
30396 | }
|
30397 |
|
30398 | var keySystemsOptions = keySystems.reduce(function (keySystemsObj, keySystem) {
|
30399 | var keySystemOptions = playlist.contentProtection[keySystem];
|
30400 |
|
30401 | if (keySystemOptions && keySystemOptions.pssh) {
|
30402 | keySystemsObj[keySystem] = {
|
30403 | pssh: keySystemOptions.pssh
|
30404 | };
|
30405 | }
|
30406 |
|
30407 | return keySystemsObj;
|
30408 | }, {});
|
30409 |
|
30410 | if (Object.keys(keySystemsOptions).length) {
|
30411 | keySystemsArr.push(keySystemsOptions);
|
30412 | }
|
30413 |
|
30414 | return keySystemsArr;
|
30415 | }, []);
|
30416 | };
|
30417 | |
30418 |
|
30419 |
|
30420 |
|
30421 |
|
30422 |
|
30423 |
|
30424 |
|
30425 |
|
30426 |
|
30427 |
|
30428 |
|
30429 |
|
30430 |
|
30431 |
|
30432 |
|
30433 |
|
30434 |
|
30435 |
|
30436 |
|
30437 |
|
30438 |
|
30439 |
|
30440 |
|
30441 |
|
30442 |
|
30443 | var waitForKeySessionCreation = function waitForKeySessionCreation(_ref) {
|
30444 | var player = _ref.player,
|
30445 | sourceKeySystems = _ref.sourceKeySystems,
|
30446 | audioMedia = _ref.audioMedia,
|
30447 | mainPlaylists = _ref.mainPlaylists;
|
30448 |
|
30449 | if (!player.eme.initializeMediaKeys) {
|
30450 | return Promise.resolve();
|
30451 | }
|
30452 |
|
30453 |
|
30454 |
|
30455 |
|
30456 |
|
30457 |
|
30458 |
|
30459 |
|
30460 |
|
30461 | var playlists = audioMedia ? mainPlaylists.concat([audioMedia]) : mainPlaylists;
|
30462 | var keySystemsOptionsArr = getAllPsshKeySystemsOptions(playlists, Object.keys(sourceKeySystems));
|
30463 | var initializationFinishedPromises = [];
|
30464 | var keySessionCreatedPromises = [];
|
30465 |
|
30466 |
|
30467 |
|
30468 |
|
30469 |
|
30470 | keySystemsOptionsArr.forEach(function (keySystemsOptions) {
|
30471 | keySessionCreatedPromises.push(new Promise(function (resolve, reject) {
|
30472 | player.tech_.one('keysessioncreated', resolve);
|
30473 | }));
|
30474 | initializationFinishedPromises.push(new Promise(function (resolve, reject) {
|
30475 | player.eme.initializeMediaKeys({
|
30476 | keySystems: keySystemsOptions
|
30477 | }, function (err) {
|
30478 | if (err) {
|
30479 | reject(err);
|
30480 | return;
|
30481 | }
|
30482 |
|
30483 | resolve();
|
30484 | });
|
30485 | }));
|
30486 | });
|
30487 |
|
30488 |
|
30489 |
|
30490 |
|
30491 |
|
30492 |
|
30493 | return Promise.race([
|
30494 |
|
30495 |
|
30496 | Promise.all(initializationFinishedPromises),
|
30497 | Promise.race(keySessionCreatedPromises)]);
|
30498 | };
|
30499 | |
30500 |
|
30501 |
|
30502 |
|
30503 |
|
30504 |
|
30505 |
|
30506 |
|
30507 |
|
30508 |
|
30509 |
|
30510 |
|
30511 |
|
30512 |
|
30513 |
|
30514 |
|
30515 |
|
30516 |
|
30517 | var setupEmeOptions = function setupEmeOptions(_ref2) {
|
30518 | var player = _ref2.player,
|
30519 | sourceKeySystems = _ref2.sourceKeySystems,
|
30520 | media = _ref2.media,
|
30521 | audioMedia = _ref2.audioMedia;
|
30522 | var sourceOptions = emeKeySystems(sourceKeySystems, media, audioMedia);
|
30523 |
|
30524 | if (!sourceOptions) {
|
30525 | return false;
|
30526 | }
|
30527 |
|
30528 | player.currentSource().keySystems = sourceOptions;
|
30529 |
|
30530 |
|
30531 | if (sourceOptions && !player.eme) {
|
30532 | videojs__default["default"].log.warn('DRM encrypted source cannot be decrypted without a DRM plugin');
|
30533 | return false;
|
30534 | }
|
30535 |
|
30536 | return true;
|
30537 | };
|
30538 |
|
30539 | var getVhsLocalStorage = function getVhsLocalStorage() {
|
30540 | if (!window.localStorage) {
|
30541 | return null;
|
30542 | }
|
30543 |
|
30544 | var storedObject = window.localStorage.getItem(LOCAL_STORAGE_KEY);
|
30545 |
|
30546 | if (!storedObject) {
|
30547 | return null;
|
30548 | }
|
30549 |
|
30550 | try {
|
30551 | return JSON.parse(storedObject);
|
30552 | } catch (e) {
|
30553 |
|
30554 | return null;
|
30555 | }
|
30556 | };
|
30557 |
|
30558 | var updateVhsLocalStorage = function updateVhsLocalStorage(options) {
|
30559 | if (!window.localStorage) {
|
30560 | return false;
|
30561 | }
|
30562 |
|
30563 | var objectToStore = getVhsLocalStorage();
|
30564 | objectToStore = objectToStore ? videojs__default["default"].mergeOptions(objectToStore, options) : options;
|
30565 |
|
30566 | try {
|
30567 | window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(objectToStore));
|
30568 | } catch (e) {
|
30569 |
|
30570 |
|
30571 |
|
30572 |
|
30573 | return false;
|
30574 | }
|
30575 |
|
30576 | return objectToStore;
|
30577 | };
|
30578 | |
30579 |
|
30580 |
|
30581 |
|
30582 |
|
30583 |
|
30584 |
|
30585 |
|
30586 |
|
30587 |
|
30588 |
|
30589 |
|
30590 |
|
30591 |
|
30592 | var expandDataUri = function expandDataUri(dataUri) {
|
30593 | if (dataUri.toLowerCase().indexOf('data:application/vnd.videojs.vhs+json,') === 0) {
|
30594 | return JSON.parse(dataUri.substring(dataUri.indexOf(',') + 1));
|
30595 | }
|
30596 |
|
30597 |
|
30598 | return dataUri;
|
30599 | };
|
30600 | |
30601 |
|
30602 |
|
30603 |
|
30604 |
|
30605 | Vhs.supportsNativeHls = function () {
|
30606 | if (!document || !document.createElement) {
|
30607 | return false;
|
30608 | }
|
30609 |
|
30610 | var video = document.createElement('video');
|
30611 |
|
30612 | if (!videojs__default["default"].getTech('Html5').isSupported()) {
|
30613 | return false;
|
30614 | }
|
30615 |
|
30616 |
|
30617 | var canPlay = [
|
30618 | 'application/vnd.apple.mpegurl',
|
30619 | 'audio/mpegurl',
|
30620 | 'audio/x-mpegurl',
|
30621 | 'application/x-mpegurl',
|
30622 | 'video/x-mpegurl', 'video/mpegurl', 'application/mpegurl'];
|
30623 | return canPlay.some(function (canItPlay) {
|
30624 | return /maybe|probably/i.test(video.canPlayType(canItPlay));
|
30625 | });
|
30626 | }();
|
30627 |
|
30628 | Vhs.supportsNativeDash = function () {
|
30629 | if (!document || !document.createElement || !videojs__default["default"].getTech('Html5').isSupported()) {
|
30630 | return false;
|
30631 | }
|
30632 |
|
30633 | return /maybe|probably/i.test(document.createElement('video').canPlayType('application/dash+xml'));
|
30634 | }();
|
30635 |
|
30636 | Vhs.supportsTypeNatively = function (type) {
|
30637 | if (type === 'hls') {
|
30638 | return Vhs.supportsNativeHls;
|
30639 | }
|
30640 |
|
30641 | if (type === 'dash') {
|
30642 | return Vhs.supportsNativeDash;
|
30643 | }
|
30644 |
|
30645 | return false;
|
30646 | };
|
30647 | |
30648 |
|
30649 |
|
30650 |
|
30651 |
|
30652 |
|
30653 | Vhs.isSupported = function () {
|
30654 | return videojs__default["default"].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
30655 | };
|
30656 |
|
30657 | var Component = videojs__default["default"].getComponent('Component');
|
30658 | |
30659 |
|
30660 |
|
30661 |
|
30662 |
|
30663 |
|
30664 |
|
30665 |
|
30666 |
|
30667 |
|
30668 |
|
30669 | var VhsHandler = function (_Component) {
|
30670 | inheritsLoose(VhsHandler, _Component);
|
30671 |
|
30672 | function VhsHandler(source, tech, options) {
|
30673 | var _this;
|
30674 |
|
30675 | _this = _Component.call(this, tech, videojs__default["default"].mergeOptions(options.hls, options.vhs)) || this;
|
30676 |
|
30677 | if (options.hls && Object.keys(options.hls).length) {
|
30678 | videojs__default["default"].log.warn('Using hls options is deprecated. Use vhs instead.');
|
30679 | }
|
30680 |
|
30681 |
|
30682 |
|
30683 | if (typeof options.initialBandwidth === 'number') {
|
30684 | _this.options_.bandwidth = options.initialBandwidth;
|
30685 | }
|
30686 |
|
30687 | _this.logger_ = logger('VhsHandler');
|
30688 |
|
30689 |
|
30690 | if (tech.options_ && tech.options_.playerId) {
|
30691 | var _player = videojs__default["default"](tech.options_.playerId);
|
30692 |
|
30693 | if (!_player.hasOwnProperty('hls')) {
|
30694 | Object.defineProperty(_player, 'hls', {
|
30695 | get: function get() {
|
30696 | videojs__default["default"].log.warn('player.hls is deprecated. Use player.tech().vhs instead.');
|
30697 | tech.trigger({
|
30698 | type: 'usage',
|
30699 | name: 'hls-player-access'
|
30700 | });
|
30701 | return assertThisInitialized(_this);
|
30702 | },
|
30703 | configurable: true
|
30704 | });
|
30705 | }
|
30706 |
|
30707 | if (!_player.hasOwnProperty('vhs')) {
|
30708 | Object.defineProperty(_player, 'vhs', {
|
30709 | get: function get() {
|
30710 | videojs__default["default"].log.warn('player.vhs is deprecated. Use player.tech().vhs instead.');
|
30711 | tech.trigger({
|
30712 | type: 'usage',
|
30713 | name: 'vhs-player-access'
|
30714 | });
|
30715 | return assertThisInitialized(_this);
|
30716 | },
|
30717 | configurable: true
|
30718 | });
|
30719 | }
|
30720 |
|
30721 | if (!_player.hasOwnProperty('dash')) {
|
30722 | Object.defineProperty(_player, 'dash', {
|
30723 | get: function get() {
|
30724 | videojs__default["default"].log.warn('player.dash is deprecated. Use player.tech().vhs instead.');
|
30725 | return assertThisInitialized(_this);
|
30726 | },
|
30727 | configurable: true
|
30728 | });
|
30729 | }
|
30730 |
|
30731 | _this.player_ = _player;
|
30732 | }
|
30733 |
|
30734 | _this.tech_ = tech;
|
30735 | _this.source_ = source;
|
30736 | _this.stats = {};
|
30737 | _this.ignoreNextSeekingEvent_ = false;
|
30738 |
|
30739 | _this.setOptions_();
|
30740 |
|
30741 | if (_this.options_.overrideNative && tech.overrideNativeAudioTracks && tech.overrideNativeVideoTracks) {
|
30742 | tech.overrideNativeAudioTracks(true);
|
30743 | tech.overrideNativeVideoTracks(true);
|
30744 | } else if (_this.options_.overrideNative && (tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
|
30745 |
|
30746 |
|
30747 | throw new Error('Overriding native HLS requires emulated tracks. ' + 'See https://git.io/vMpjB');
|
30748 | }
|
30749 |
|
30750 |
|
30751 |
|
30752 | _this.on(document, ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'], function (event) {
|
30753 | var fullscreenElement = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
|
30754 |
|
30755 | if (fullscreenElement && fullscreenElement.contains(_this.tech_.el())) {
|
30756 | _this.masterPlaylistController_.fastQualityChange_();
|
30757 | } else {
|
30758 |
|
30759 |
|
30760 |
|
30761 | _this.masterPlaylistController_.checkABR_();
|
30762 | }
|
30763 | });
|
30764 |
|
30765 | _this.on(_this.tech_, 'seeking', function () {
|
30766 | if (this.ignoreNextSeekingEvent_) {
|
30767 | this.ignoreNextSeekingEvent_ = false;
|
30768 | return;
|
30769 | }
|
30770 |
|
30771 | this.setCurrentTime(this.tech_.currentTime());
|
30772 | });
|
30773 |
|
30774 | _this.on(_this.tech_, 'error', function () {
|
30775 |
|
30776 |
|
30777 | if (this.tech_.error() && this.masterPlaylistController_) {
|
30778 | this.masterPlaylistController_.pauseLoading();
|
30779 | }
|
30780 | });
|
30781 |
|
30782 | _this.on(_this.tech_, 'play', _this.play);
|
30783 |
|
30784 | return _this;
|
30785 | }
|
30786 |
|
30787 | var _proto = VhsHandler.prototype;
|
30788 |
|
30789 | _proto.setOptions_ = function setOptions_() {
|
30790 | var _this2 = this;
|
30791 |
|
30792 |
|
30793 | this.options_.withCredentials = this.options_.withCredentials || false;
|
30794 | this.options_.handleManifestRedirects = this.options_.handleManifestRedirects === false ? false : true;
|
30795 | this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
|
30796 | this.options_.useDevicePixelRatio = this.options_.useDevicePixelRatio || false;
|
30797 | this.options_.smoothQualityChange = this.options_.smoothQualityChange || false;
|
30798 | this.options_.useBandwidthFromLocalStorage = typeof this.source_.useBandwidthFromLocalStorage !== 'undefined' ? this.source_.useBandwidthFromLocalStorage : this.options_.useBandwidthFromLocalStorage || false;
|
30799 | this.options_.customTagParsers = this.options_.customTagParsers || [];
|
30800 | this.options_.customTagMappers = this.options_.customTagMappers || [];
|
30801 | this.options_.cacheEncryptionKeys = this.options_.cacheEncryptionKeys || false;
|
30802 |
|
30803 | if (typeof this.options_.blacklistDuration !== 'number') {
|
30804 | this.options_.blacklistDuration = 5 * 60;
|
30805 | }
|
30806 |
|
30807 | if (typeof this.options_.bandwidth !== 'number') {
|
30808 | if (this.options_.useBandwidthFromLocalStorage) {
|
30809 | var storedObject = getVhsLocalStorage();
|
30810 |
|
30811 | if (storedObject && storedObject.bandwidth) {
|
30812 | this.options_.bandwidth = storedObject.bandwidth;
|
30813 | this.tech_.trigger({
|
30814 | type: 'usage',
|
30815 | name: 'vhs-bandwidth-from-local-storage'
|
30816 | });
|
30817 | this.tech_.trigger({
|
30818 | type: 'usage',
|
30819 | name: 'hls-bandwidth-from-local-storage'
|
30820 | });
|
30821 | }
|
30822 |
|
30823 | if (storedObject && storedObject.throughput) {
|
30824 | this.options_.throughput = storedObject.throughput;
|
30825 | this.tech_.trigger({
|
30826 | type: 'usage',
|
30827 | name: 'vhs-throughput-from-local-storage'
|
30828 | });
|
30829 | this.tech_.trigger({
|
30830 | type: 'usage',
|
30831 | name: 'hls-throughput-from-local-storage'
|
30832 | });
|
30833 | }
|
30834 | }
|
30835 | }
|
30836 |
|
30837 |
|
30838 |
|
30839 | if (typeof this.options_.bandwidth !== 'number') {
|
30840 | this.options_.bandwidth = Config.INITIAL_BANDWIDTH;
|
30841 | }
|
30842 |
|
30843 |
|
30844 |
|
30845 | this.options_.enableLowInitialPlaylist = this.options_.enableLowInitialPlaylist && this.options_.bandwidth === Config.INITIAL_BANDWIDTH;
|
30846 |
|
30847 | ['withCredentials', 'useDevicePixelRatio', 'limitRenditionByPlayerDimensions', 'bandwidth', 'smoothQualityChange', 'customTagParsers', 'customTagMappers', 'handleManifestRedirects', 'cacheEncryptionKeys', 'playlistSelector', 'initialPlaylistSelector', 'experimentalBufferBasedABR', 'liveRangeSafeTimeDelta', 'experimentalLLHLS', 'experimentalExactManifestTimings', 'experimentalLeastPixelDiffSelector'].forEach(function (option) {
|
30848 | if (typeof _this2.source_[option] !== 'undefined') {
|
30849 | _this2.options_[option] = _this2.source_[option];
|
30850 | }
|
30851 | });
|
30852 | this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
|
30853 | this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
|
30854 | }
|
30855 | |
30856 |
|
30857 |
|
30858 |
|
30859 |
|
30860 | ;
|
30861 |
|
30862 | _proto.src = function src(_src, type) {
|
30863 | var _this3 = this;
|
30864 |
|
30865 |
|
30866 | if (!_src) {
|
30867 | return;
|
30868 | }
|
30869 |
|
30870 | this.setOptions_();
|
30871 |
|
30872 | this.options_.src = expandDataUri(this.source_.src);
|
30873 | this.options_.tech = this.tech_;
|
30874 | this.options_.externVhs = Vhs;
|
30875 | this.options_.sourceType = simpleTypeFromSourceType(type);
|
30876 |
|
30877 | this.options_.seekTo = function (time) {
|
30878 | _this3.tech_.setCurrentTime(time);
|
30879 | };
|
30880 |
|
30881 | if (this.options_.smoothQualityChange) {
|
30882 | videojs__default["default"].log.warn('smoothQualityChange is deprecated and will be removed in the next major version');
|
30883 | }
|
30884 |
|
30885 | this.masterPlaylistController_ = new MasterPlaylistController(this.options_);
|
30886 | var playbackWatcherOptions = videojs__default["default"].mergeOptions({
|
30887 | liveRangeSafeTimeDelta: SAFE_TIME_DELTA
|
30888 | }, this.options_, {
|
30889 | seekable: function seekable() {
|
30890 | return _this3.seekable();
|
30891 | },
|
30892 | media: function media() {
|
30893 | return _this3.masterPlaylistController_.media();
|
30894 | },
|
30895 | masterPlaylistController: this.masterPlaylistController_
|
30896 | });
|
30897 | this.playbackWatcher_ = new PlaybackWatcher(playbackWatcherOptions);
|
30898 | this.masterPlaylistController_.on('error', function () {
|
30899 | var player = videojs__default["default"].players[_this3.tech_.options_.playerId];
|
30900 | var error = _this3.masterPlaylistController_.error;
|
30901 |
|
30902 | if (typeof error === 'object' && !error.code) {
|
30903 | error.code = 3;
|
30904 | } else if (typeof error === 'string') {
|
30905 | error = {
|
30906 | message: error,
|
30907 | code: 3
|
30908 | };
|
30909 | }
|
30910 |
|
30911 | player.error(error);
|
30912 | });
|
30913 | var defaultSelector = this.options_.experimentalBufferBasedABR ? Vhs.movingAverageBandwidthSelector(0.55) : Vhs.STANDARD_PLAYLIST_SELECTOR;
|
30914 |
|
30915 |
|
30916 | this.masterPlaylistController_.selectPlaylist = this.selectPlaylist ? this.selectPlaylist.bind(this) : defaultSelector.bind(this);
|
30917 | this.masterPlaylistController_.selectInitialPlaylist = Vhs.INITIAL_PLAYLIST_SELECTOR.bind(this);
|
30918 |
|
30919 | this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
|
30920 | this.mediaSource = this.masterPlaylistController_.mediaSource;
|
30921 |
|
30922 |
|
30923 |
|
30924 | Object.defineProperties(this, {
|
30925 | selectPlaylist: {
|
30926 | get: function get() {
|
30927 | return this.masterPlaylistController_.selectPlaylist;
|
30928 | },
|
30929 | set: function set(selectPlaylist) {
|
30930 | this.masterPlaylistController_.selectPlaylist = selectPlaylist.bind(this);
|
30931 | }
|
30932 | },
|
30933 | throughput: {
|
30934 | get: function get() {
|
30935 | return this.masterPlaylistController_.mainSegmentLoader_.throughput.rate;
|
30936 | },
|
30937 | set: function set(throughput) {
|
30938 | this.masterPlaylistController_.mainSegmentLoader_.throughput.rate = throughput;
|
30939 |
|
30940 |
|
30941 | this.masterPlaylistController_.mainSegmentLoader_.throughput.count = 1;
|
30942 | }
|
30943 | },
|
30944 | bandwidth: {
|
30945 | get: function get() {
|
30946 | return this.masterPlaylistController_.mainSegmentLoader_.bandwidth;
|
30947 | },
|
30948 | set: function set(bandwidth) {
|
30949 | this.masterPlaylistController_.mainSegmentLoader_.bandwidth = bandwidth;
|
30950 |
|
30951 |
|
30952 |
|
30953 | this.masterPlaylistController_.mainSegmentLoader_.throughput = {
|
30954 | rate: 0,
|
30955 | count: 0
|
30956 | };
|
30957 | }
|
30958 | },
|
30959 |
|
30960 | |
30961 |
|
30962 |
|
30963 |
|
30964 |
|
30965 |
|
30966 |
|
30967 |
|
30968 |
|
30969 | systemBandwidth: {
|
30970 | get: function get() {
|
30971 | var invBandwidth = 1 / (this.bandwidth || 1);
|
30972 | var invThroughput;
|
30973 |
|
30974 | if (this.throughput > 0) {
|
30975 | invThroughput = 1 / this.throughput;
|
30976 | } else {
|
30977 | invThroughput = 0;
|
30978 | }
|
30979 |
|
30980 | var systemBitrate = Math.floor(1 / (invBandwidth + invThroughput));
|
30981 | return systemBitrate;
|
30982 | },
|
30983 | set: function set() {
|
30984 | videojs__default["default"].log.error('The "systemBandwidth" property is read-only');
|
30985 | }
|
30986 | }
|
30987 | });
|
30988 |
|
30989 | if (this.options_.bandwidth) {
|
30990 | this.bandwidth = this.options_.bandwidth;
|
30991 | }
|
30992 |
|
30993 | if (this.options_.throughput) {
|
30994 | this.throughput = this.options_.throughput;
|
30995 | }
|
30996 |
|
30997 | Object.defineProperties(this.stats, {
|
30998 | bandwidth: {
|
30999 | get: function get() {
|
31000 | return _this3.bandwidth || 0;
|
31001 | },
|
31002 | enumerable: true
|
31003 | },
|
31004 | mediaRequests: {
|
31005 | get: function get() {
|
31006 | return _this3.masterPlaylistController_.mediaRequests_() || 0;
|
31007 | },
|
31008 | enumerable: true
|
31009 | },
|
31010 | mediaRequestsAborted: {
|
31011 | get: function get() {
|
31012 | return _this3.masterPlaylistController_.mediaRequestsAborted_() || 0;
|
31013 | },
|
31014 | enumerable: true
|
31015 | },
|
31016 | mediaRequestsTimedout: {
|
31017 | get: function get() {
|
31018 | return _this3.masterPlaylistController_.mediaRequestsTimedout_() || 0;
|
31019 | },
|
31020 | enumerable: true
|
31021 | },
|
31022 | mediaRequestsErrored: {
|
31023 | get: function get() {
|
31024 | return _this3.masterPlaylistController_.mediaRequestsErrored_() || 0;
|
31025 | },
|
31026 | enumerable: true
|
31027 | },
|
31028 | mediaTransferDuration: {
|
31029 | get: function get() {
|
31030 | return _this3.masterPlaylistController_.mediaTransferDuration_() || 0;
|
31031 | },
|
31032 | enumerable: true
|
31033 | },
|
31034 | mediaBytesTransferred: {
|
31035 | get: function get() {
|
31036 | return _this3.masterPlaylistController_.mediaBytesTransferred_() || 0;
|
31037 | },
|
31038 | enumerable: true
|
31039 | },
|
31040 | mediaSecondsLoaded: {
|
31041 | get: function get() {
|
31042 | return _this3.masterPlaylistController_.mediaSecondsLoaded_() || 0;
|
31043 | },
|
31044 | enumerable: true
|
31045 | },
|
31046 | mediaAppends: {
|
31047 | get: function get() {
|
31048 | return _this3.masterPlaylistController_.mediaAppends_() || 0;
|
31049 | },
|
31050 | enumerable: true
|
31051 | },
|
31052 | mainAppendsToLoadedData: {
|
31053 | get: function get() {
|
31054 | return _this3.masterPlaylistController_.mainAppendsToLoadedData_() || 0;
|
31055 | },
|
31056 | enumerable: true
|
31057 | },
|
31058 | audioAppendsToLoadedData: {
|
31059 | get: function get() {
|
31060 | return _this3.masterPlaylistController_.audioAppendsToLoadedData_() || 0;
|
31061 | },
|
31062 | enumerable: true
|
31063 | },
|
31064 | appendsToLoadedData: {
|
31065 | get: function get() {
|
31066 | return _this3.masterPlaylistController_.appendsToLoadedData_() || 0;
|
31067 | },
|
31068 | enumerable: true
|
31069 | },
|
31070 | timeToLoadedData: {
|
31071 | get: function get() {
|
31072 | return _this3.masterPlaylistController_.timeToLoadedData_() || 0;
|
31073 | },
|
31074 | enumerable: true
|
31075 | },
|
31076 | buffered: {
|
31077 | get: function get() {
|
31078 | return timeRangesToArray(_this3.tech_.buffered());
|
31079 | },
|
31080 | enumerable: true
|
31081 | },
|
31082 | currentTime: {
|
31083 | get: function get() {
|
31084 | return _this3.tech_.currentTime();
|
31085 | },
|
31086 | enumerable: true
|
31087 | },
|
31088 | currentSource: {
|
31089 | get: function get() {
|
31090 | return _this3.tech_.currentSource_;
|
31091 | },
|
31092 | enumerable: true
|
31093 | },
|
31094 | currentTech: {
|
31095 | get: function get() {
|
31096 | return _this3.tech_.name_;
|
31097 | },
|
31098 | enumerable: true
|
31099 | },
|
31100 | duration: {
|
31101 | get: function get() {
|
31102 | return _this3.tech_.duration();
|
31103 | },
|
31104 | enumerable: true
|
31105 | },
|
31106 | master: {
|
31107 | get: function get() {
|
31108 | return _this3.playlists.master;
|
31109 | },
|
31110 | enumerable: true
|
31111 | },
|
31112 | playerDimensions: {
|
31113 | get: function get() {
|
31114 | return _this3.tech_.currentDimensions();
|
31115 | },
|
31116 | enumerable: true
|
31117 | },
|
31118 | seekable: {
|
31119 | get: function get() {
|
31120 | return timeRangesToArray(_this3.tech_.seekable());
|
31121 | },
|
31122 | enumerable: true
|
31123 | },
|
31124 | timestamp: {
|
31125 | get: function get() {
|
31126 | return Date.now();
|
31127 | },
|
31128 | enumerable: true
|
31129 | },
|
31130 | videoPlaybackQuality: {
|
31131 | get: function get() {
|
31132 | return _this3.tech_.getVideoPlaybackQuality();
|
31133 | },
|
31134 | enumerable: true
|
31135 | }
|
31136 | });
|
31137 | this.tech_.one('canplay', this.masterPlaylistController_.setupFirstPlay.bind(this.masterPlaylistController_));
|
31138 | this.tech_.on('bandwidthupdate', function () {
|
31139 | if (_this3.options_.useBandwidthFromLocalStorage) {
|
31140 | updateVhsLocalStorage({
|
31141 | bandwidth: _this3.bandwidth,
|
31142 | throughput: Math.round(_this3.throughput)
|
31143 | });
|
31144 | }
|
31145 | });
|
31146 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
31147 |
|
31148 | renditionSelectionMixin(_this3);
|
31149 | });
|
31150 | this.masterPlaylistController_.sourceUpdater_.on('createdsourcebuffers', function () {
|
31151 | _this3.setupEme_();
|
31152 | });
|
31153 |
|
31154 |
|
31155 | this.on(this.masterPlaylistController_, 'progress', function () {
|
31156 | this.tech_.trigger('progress');
|
31157 | });
|
31158 |
|
31159 |
|
31160 | this.on(this.masterPlaylistController_, 'firstplay', function () {
|
31161 | this.ignoreNextSeekingEvent_ = true;
|
31162 | });
|
31163 | this.setupQualityLevels_();
|
31164 |
|
31165 |
|
31166 | if (!this.tech_.el()) {
|
31167 | return;
|
31168 | }
|
31169 |
|
31170 | this.mediaSourceUrl_ = window.URL.createObjectURL(this.masterPlaylistController_.mediaSource);
|
31171 | this.tech_.src(this.mediaSourceUrl_);
|
31172 | }
|
31173 | |
31174 |
|
31175 |
|
31176 |
|
31177 |
|
31178 |
|
31179 |
|
31180 |
|
31181 | ;
|
31182 |
|
31183 | _proto.setupEme_ = function setupEme_() {
|
31184 | var _this4 = this;
|
31185 |
|
31186 | var audioPlaylistLoader = this.masterPlaylistController_.mediaTypes_.AUDIO.activePlaylistLoader;
|
31187 | var didSetupEmeOptions = setupEmeOptions({
|
31188 | player: this.player_,
|
31189 | sourceKeySystems: this.source_.keySystems,
|
31190 | media: this.playlists.media(),
|
31191 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media()
|
31192 | });
|
31193 | this.player_.tech_.on('keystatuschange', function (e) {
|
31194 | if (e.status === 'output-restricted') {
|
31195 | _this4.masterPlaylistController_.blacklistCurrentPlaylist({
|
31196 | playlist: _this4.masterPlaylistController_.media(),
|
31197 | message: "DRM keystatus changed to " + e.status + ". Playlist will fail to play. Check for HDCP content.",
|
31198 | blacklistDuration: Infinity
|
31199 | });
|
31200 | }
|
31201 | });
|
31202 |
|
31203 |
|
31204 | if (videojs__default["default"].browser.IE_VERSION === 11 || !didSetupEmeOptions) {
|
31205 |
|
31206 | this.masterPlaylistController_.sourceUpdater_.initializedEme();
|
31207 | return;
|
31208 | }
|
31209 |
|
31210 | this.logger_('waiting for EME key session creation');
|
31211 | waitForKeySessionCreation({
|
31212 | player: this.player_,
|
31213 | sourceKeySystems: this.source_.keySystems,
|
31214 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media(),
|
31215 | mainPlaylists: this.playlists.master.playlists
|
31216 | }).then(function () {
|
31217 | _this4.logger_('created EME key session');
|
31218 |
|
31219 | _this4.masterPlaylistController_.sourceUpdater_.initializedEme();
|
31220 | }).catch(function (err) {
|
31221 | _this4.logger_('error while creating EME key session', err);
|
31222 |
|
31223 | _this4.player_.error({
|
31224 | message: 'Failed to initialize media keys for EME',
|
31225 | code: 3
|
31226 | });
|
31227 | });
|
31228 | }
|
31229 | |
31230 |
|
31231 |
|
31232 |
|
31233 |
|
31234 |
|
31235 | ;
|
31236 |
|
31237 | _proto.setupQualityLevels_ = function setupQualityLevels_() {
|
31238 | var _this5 = this;
|
31239 |
|
31240 | var player = videojs__default["default"].players[this.tech_.options_.playerId];
|
31241 |
|
31242 |
|
31243 | if (!player || !player.qualityLevels || this.qualityLevels_) {
|
31244 | return;
|
31245 | }
|
31246 |
|
31247 | this.qualityLevels_ = player.qualityLevels();
|
31248 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
31249 | handleVhsLoadedMetadata(_this5.qualityLevels_, _this5);
|
31250 | });
|
31251 | this.playlists.on('mediachange', function () {
|
31252 | handleVhsMediaChange(_this5.qualityLevels_, _this5.playlists);
|
31253 | });
|
31254 | }
|
31255 | |
31256 |
|
31257 |
|
31258 | ;
|
31259 |
|
31260 | VhsHandler.version = function version$5() {
|
31261 | return {
|
31262 | '@videojs/http-streaming': version$4,
|
31263 | 'mux.js': version$3,
|
31264 | 'mpd-parser': version$2,
|
31265 | 'm3u8-parser': version$1,
|
31266 | 'aes-decrypter': version
|
31267 | };
|
31268 | }
|
31269 | |
31270 |
|
31271 |
|
31272 | ;
|
31273 |
|
31274 | _proto.version = function version() {
|
31275 | return this.constructor.version();
|
31276 | };
|
31277 |
|
31278 | _proto.canChangeType = function canChangeType() {
|
31279 | return SourceUpdater.canChangeType();
|
31280 | }
|
31281 | |
31282 |
|
31283 |
|
31284 | ;
|
31285 |
|
31286 | _proto.play = function play() {
|
31287 | this.masterPlaylistController_.play();
|
31288 | }
|
31289 | |
31290 |
|
31291 |
|
31292 | ;
|
31293 |
|
31294 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
31295 | this.masterPlaylistController_.setCurrentTime(currentTime);
|
31296 | }
|
31297 | |
31298 |
|
31299 |
|
31300 | ;
|
31301 |
|
31302 | _proto.duration = function duration() {
|
31303 | return this.masterPlaylistController_.duration();
|
31304 | }
|
31305 | |
31306 |
|
31307 |
|
31308 | ;
|
31309 |
|
31310 | _proto.seekable = function seekable() {
|
31311 | return this.masterPlaylistController_.seekable();
|
31312 | }
|
31313 | |
31314 |
|
31315 |
|
31316 | ;
|
31317 |
|
31318 | _proto.dispose = function dispose() {
|
31319 | if (this.playbackWatcher_) {
|
31320 | this.playbackWatcher_.dispose();
|
31321 | }
|
31322 |
|
31323 | if (this.masterPlaylistController_) {
|
31324 | this.masterPlaylistController_.dispose();
|
31325 | }
|
31326 |
|
31327 | if (this.qualityLevels_) {
|
31328 | this.qualityLevels_.dispose();
|
31329 | }
|
31330 |
|
31331 | if (this.player_) {
|
31332 | delete this.player_.vhs;
|
31333 | delete this.player_.dash;
|
31334 | delete this.player_.hls;
|
31335 | }
|
31336 |
|
31337 | if (this.tech_ && this.tech_.vhs) {
|
31338 | delete this.tech_.vhs;
|
31339 | }
|
31340 |
|
31341 |
|
31342 | if (this.tech_) {
|
31343 | delete this.tech_.hls;
|
31344 | }
|
31345 |
|
31346 | if (this.mediaSourceUrl_ && window.URL.revokeObjectURL) {
|
31347 | window.URL.revokeObjectURL(this.mediaSourceUrl_);
|
31348 | this.mediaSourceUrl_ = null;
|
31349 | }
|
31350 |
|
31351 | _Component.prototype.dispose.call(this);
|
31352 | };
|
31353 |
|
31354 | _proto.convertToProgramTime = function convertToProgramTime(time, callback) {
|
31355 | return getProgramTime({
|
31356 | playlist: this.masterPlaylistController_.media(),
|
31357 | time: time,
|
31358 | callback: callback
|
31359 | });
|
31360 | }
|
31361 | ;
|
31362 |
|
31363 | _proto.seekToProgramTime = function seekToProgramTime$1(programTime, callback, pauseAfterSeek, retryCount) {
|
31364 | if (pauseAfterSeek === void 0) {
|
31365 | pauseAfterSeek = true;
|
31366 | }
|
31367 |
|
31368 | if (retryCount === void 0) {
|
31369 | retryCount = 2;
|
31370 | }
|
31371 |
|
31372 | return seekToProgramTime({
|
31373 | programTime: programTime,
|
31374 | playlist: this.masterPlaylistController_.media(),
|
31375 | retryCount: retryCount,
|
31376 | pauseAfterSeek: pauseAfterSeek,
|
31377 | seekTo: this.options_.seekTo,
|
31378 | tech: this.options_.tech,
|
31379 | callback: callback
|
31380 | });
|
31381 | };
|
31382 |
|
31383 | return VhsHandler;
|
31384 | }(Component);
|
31385 | |
31386 |
|
31387 |
|
31388 |
|
31389 |
|
31390 |
|
31391 |
|
31392 |
|
31393 |
|
31394 | var VhsSourceHandler = {
|
31395 | name: 'videojs-http-streaming',
|
31396 | VERSION: version$4,
|
31397 | canHandleSource: function canHandleSource(srcObj, options) {
|
31398 | if (options === void 0) {
|
31399 | options = {};
|
31400 | }
|
31401 |
|
31402 | var localOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options);
|
31403 | return VhsSourceHandler.canPlayType(srcObj.type, localOptions);
|
31404 | },
|
31405 | handleSource: function handleSource(source, tech, options) {
|
31406 | if (options === void 0) {
|
31407 | options = {};
|
31408 | }
|
31409 |
|
31410 | var localOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options);
|
31411 | tech.vhs = new VhsHandler(source, tech, localOptions);
|
31412 |
|
31413 | if (!videojs__default["default"].hasOwnProperty('hls')) {
|
31414 | Object.defineProperty(tech, 'hls', {
|
31415 | get: function get() {
|
31416 | videojs__default["default"].log.warn('player.tech().hls is deprecated. Use player.tech().vhs instead.');
|
31417 | return tech.vhs;
|
31418 | },
|
31419 | configurable: true
|
31420 | });
|
31421 | }
|
31422 |
|
31423 | tech.vhs.xhr = xhrFactory();
|
31424 | tech.vhs.src(source.src, source.type);
|
31425 | return tech.vhs;
|
31426 | },
|
31427 | canPlayType: function canPlayType(type, options) {
|
31428 | if (options === void 0) {
|
31429 | options = {};
|
31430 | }
|
31431 |
|
31432 | var _videojs$mergeOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options),
|
31433 | _videojs$mergeOptions2 = _videojs$mergeOptions.vhs.overrideNative,
|
31434 | overrideNative = _videojs$mergeOptions2 === void 0 ? !videojs__default["default"].browser.IS_ANY_SAFARI : _videojs$mergeOptions2;
|
31435 |
|
31436 | var supportedType = simpleTypeFromSourceType(type);
|
31437 | var canUseMsePlayback = supportedType && (!Vhs.supportsTypeNatively(supportedType) || overrideNative);
|
31438 | return canUseMsePlayback ? 'maybe' : '';
|
31439 | }
|
31440 | };
|
31441 | |
31442 |
|
31443 |
|
31444 |
|
31445 |
|
31446 |
|
31447 |
|
31448 | var supportsNativeMediaSources = function supportsNativeMediaSources() {
|
31449 | return browserSupportsCodec('avc1.4d400d,mp4a.40.2');
|
31450 | };
|
31451 |
|
31452 |
|
31453 | if (supportsNativeMediaSources()) {
|
31454 | videojs__default["default"].getTech('Html5').registerSourceHandler(VhsSourceHandler, 0);
|
31455 | }
|
31456 |
|
31457 | videojs__default["default"].VhsHandler = VhsHandler;
|
31458 | Object.defineProperty(videojs__default["default"], 'HlsHandler', {
|
31459 | get: function get() {
|
31460 | videojs__default["default"].log.warn('videojs.HlsHandler is deprecated. Use videojs.VhsHandler instead.');
|
31461 | return VhsHandler;
|
31462 | },
|
31463 | configurable: true
|
31464 | });
|
31465 | videojs__default["default"].VhsSourceHandler = VhsSourceHandler;
|
31466 | Object.defineProperty(videojs__default["default"], 'HlsSourceHandler', {
|
31467 | get: function get() {
|
31468 | videojs__default["default"].log.warn('videojs.HlsSourceHandler is deprecated. ' + 'Use videojs.VhsSourceHandler instead.');
|
31469 | return VhsSourceHandler;
|
31470 | },
|
31471 | configurable: true
|
31472 | });
|
31473 | videojs__default["default"].Vhs = Vhs;
|
31474 | Object.defineProperty(videojs__default["default"], 'Hls', {
|
31475 | get: function get() {
|
31476 | videojs__default["default"].log.warn('videojs.Hls is deprecated. Use videojs.Vhs instead.');
|
31477 | return Vhs;
|
31478 | },
|
31479 | configurable: true
|
31480 | });
|
31481 |
|
31482 | if (!videojs__default["default"].use) {
|
31483 | videojs__default["default"].registerComponent('Hls', Vhs);
|
31484 | videojs__default["default"].registerComponent('Vhs', Vhs);
|
31485 | }
|
31486 |
|
31487 | videojs__default["default"].options.vhs = videojs__default["default"].options.vhs || {};
|
31488 | videojs__default["default"].options.hls = videojs__default["default"].options.hls || {};
|
31489 |
|
31490 | if (!videojs__default["default"].getPlugin || !videojs__default["default"].getPlugin('reloadSourceOnError')) {
|
31491 | var registerPlugin = videojs__default["default"].registerPlugin || videojs__default["default"].plugin;
|
31492 | registerPlugin('reloadSourceOnError', reloadSourceOnError);
|
31493 | }
|
31494 |
|
31495 | exports.LOCAL_STORAGE_KEY = LOCAL_STORAGE_KEY;
|
31496 | exports.Vhs = Vhs;
|
31497 | exports.VhsHandler = VhsHandler;
|
31498 | exports.VhsSourceHandler = VhsSourceHandler;
|
31499 | exports.emeKeySystems = emeKeySystems;
|
31500 | exports.expandDataUri = expandDataUri;
|
31501 | exports.getAllPsshKeySystemsOptions = getAllPsshKeySystemsOptions;
|
31502 | exports.setupEmeOptions = setupEmeOptions;
|
31503 | exports.simpleTypeFromSourceType = simpleTypeFromSourceType;
|
31504 | exports.waitForKeySessionCreation = waitForKeySessionCreation;
|
31505 |
|
31506 | Object.defineProperty(exports, '__esModule', { value: true });
|
31507 |
|
31508 | }));
|