1 |
|
2 | 'use strict';
|
3 |
|
4 | Object.defineProperty(exports, '__esModule', { value: true });
|
5 |
|
6 | var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
7 | var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
8 | var document = require('global/document');
|
9 | var window$1 = require('global/window');
|
10 | var _resolveUrl = require('@videojs/vhs-utils/cjs/resolve-url.js');
|
11 | var videojs = require('video.js');
|
12 | var _extends = require('@babel/runtime/helpers/extends');
|
13 | var m3u8Parser = require('m3u8-parser');
|
14 | var codecs_js = require('@videojs/vhs-utils/cjs/codecs.js');
|
15 | var mediaTypes_js = require('@videojs/vhs-utils/cjs/media-types.js');
|
16 | var byteHelpers = require('@videojs/vhs-utils/cjs/byte-helpers');
|
17 | var mpdParser = require('mpd-parser');
|
18 | var parseSidx = require('mux.js/lib/tools/parse-sidx');
|
19 | var id3Helpers = require('@videojs/vhs-utils/cjs/id3-helpers');
|
20 | var containers = require('@videojs/vhs-utils/cjs/containers');
|
21 | var clock = require('mux.js/lib/utils/clock');
|
22 | var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
23 |
|
24 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
25 |
|
26 | var _assertThisInitialized__default = _interopDefaultLegacy(_assertThisInitialized);
|
27 | var _inheritsLoose__default = _interopDefaultLegacy(_inheritsLoose);
|
28 | var document__default = _interopDefaultLegacy(document);
|
29 | var window__default = _interopDefaultLegacy(window$1);
|
30 | var _resolveUrl__default = _interopDefaultLegacy(_resolveUrl);
|
31 | var videojs__default = _interopDefaultLegacy(videojs);
|
32 | var _extends__default = _interopDefaultLegacy(_extends);
|
33 | var parseSidx__default = _interopDefaultLegacy(parseSidx);
|
34 | var _wrapNativeSuper__default = _interopDefaultLegacy(_wrapNativeSuper);
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var resolveUrl = _resolveUrl__default["default"];
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | var resolveManifestRedirect = function resolveManifestRedirect(handleManifestRedirect, url, req) {
|
53 |
|
54 |
|
55 |
|
56 | if (handleManifestRedirect && req && req.responseURL && url !== req.responseURL) {
|
57 | return req.responseURL;
|
58 | }
|
59 |
|
60 | return url;
|
61 | };
|
62 |
|
63 | var logger = function logger(source) {
|
64 | if (videojs__default["default"].log.debug) {
|
65 | return videojs__default["default"].log.debug.bind(videojs__default["default"], 'VHS:', source + " >");
|
66 | }
|
67 |
|
68 | return function () {};
|
69 | };
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | var TIME_FUDGE_FACTOR = 1 / 30;
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | var SAFE_TIME_DELTA = TIME_FUDGE_FACTOR * 3;
|
85 |
|
86 | var filterRanges = function filterRanges(timeRanges, predicate) {
|
87 | var results = [];
|
88 | var i;
|
89 |
|
90 | if (timeRanges && timeRanges.length) {
|
91 |
|
92 | for (i = 0; i < timeRanges.length; i++) {
|
93 | if (predicate(timeRanges.start(i), timeRanges.end(i))) {
|
94 | results.push([timeRanges.start(i), timeRanges.end(i)]);
|
95 | }
|
96 | }
|
97 | }
|
98 |
|
99 | return videojs__default["default"].createTimeRanges(results);
|
100 | };
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | var findRange = function findRange(buffered, time) {
|
112 | return filterRanges(buffered, function (start, end) {
|
113 | return start - SAFE_TIME_DELTA <= time && end + SAFE_TIME_DELTA >= time;
|
114 | });
|
115 | };
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | var findNextRange = function findNextRange(timeRanges, time) {
|
125 | return filterRanges(timeRanges, function (start) {
|
126 | return start - TIME_FUDGE_FACTOR >= time;
|
127 | });
|
128 | };
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | var findGaps = function findGaps(buffered) {
|
137 | if (buffered.length < 2) {
|
138 | return videojs__default["default"].createTimeRanges();
|
139 | }
|
140 |
|
141 | var ranges = [];
|
142 |
|
143 | for (var i = 1; i < buffered.length; i++) {
|
144 | var start = buffered.end(i - 1);
|
145 | var end = buffered.start(i);
|
146 | ranges.push([start, end]);
|
147 | }
|
148 |
|
149 | return videojs__default["default"].createTimeRanges(ranges);
|
150 | };
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | var bufferIntersection = function bufferIntersection(bufferA, bufferB) {
|
160 | var start = null;
|
161 | var end = null;
|
162 | var arity = 0;
|
163 | var extents = [];
|
164 | var ranges = [];
|
165 |
|
166 | if (!bufferA || !bufferA.length || !bufferB || !bufferB.length) {
|
167 | return videojs__default["default"].createTimeRange();
|
168 | }
|
169 |
|
170 |
|
171 |
|
172 | var count = bufferA.length;
|
173 |
|
174 | while (count--) {
|
175 | extents.push({
|
176 | time: bufferA.start(count),
|
177 | type: 'start'
|
178 | });
|
179 | extents.push({
|
180 | time: bufferA.end(count),
|
181 | type: 'end'
|
182 | });
|
183 | }
|
184 |
|
185 | count = bufferB.length;
|
186 |
|
187 | while (count--) {
|
188 | extents.push({
|
189 | time: bufferB.start(count),
|
190 | type: 'start'
|
191 | });
|
192 | extents.push({
|
193 | time: bufferB.end(count),
|
194 | type: 'end'
|
195 | });
|
196 | }
|
197 |
|
198 |
|
199 | extents.sort(function (a, b) {
|
200 | return a.time - b.time;
|
201 | });
|
202 |
|
203 |
|
204 | for (count = 0; count < extents.length; count++) {
|
205 | if (extents[count].type === 'start') {
|
206 | arity++;
|
207 |
|
208 |
|
209 | if (arity === 2) {
|
210 | start = extents[count].time;
|
211 | }
|
212 | } else if (extents[count].type === 'end') {
|
213 | arity--;
|
214 |
|
215 |
|
216 | if (arity === 1) {
|
217 | end = extents[count].time;
|
218 | }
|
219 | }
|
220 |
|
221 |
|
222 | if (start !== null && end !== null) {
|
223 | ranges.push([start, end]);
|
224 | start = null;
|
225 | end = null;
|
226 | }
|
227 | }
|
228 |
|
229 | return videojs__default["default"].createTimeRanges(ranges);
|
230 | };
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | var printableRange = function printableRange(range) {
|
239 | var strArr = [];
|
240 |
|
241 | if (!range || !range.length) {
|
242 | return '';
|
243 | }
|
244 |
|
245 | for (var i = 0; i < range.length; i++) {
|
246 | strArr.push(range.start(i) + ' => ' + range.end(i));
|
247 | }
|
248 |
|
249 | return strArr.join(', ');
|
250 | };
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | var timeUntilRebuffer = function timeUntilRebuffer(buffered, currentTime, playbackRate) {
|
267 | if (playbackRate === void 0) {
|
268 | playbackRate = 1;
|
269 | }
|
270 |
|
271 | var bufferedEnd = buffered.length ? buffered.end(buffered.length - 1) : 0;
|
272 | return (bufferedEnd - currentTime) / playbackRate;
|
273 | };
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | var timeRangesToArray = function timeRangesToArray(timeRanges) {
|
282 | var timeRangesList = [];
|
283 |
|
284 | for (var i = 0; i < timeRanges.length; i++) {
|
285 | timeRangesList.push({
|
286 | start: timeRanges.start(i),
|
287 | end: timeRanges.end(i)
|
288 | });
|
289 | }
|
290 |
|
291 | return timeRangesList;
|
292 | };
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | var isRangeDifferent = function isRangeDifferent(a, b) {
|
307 |
|
308 | if (a === b) {
|
309 | return false;
|
310 | }
|
311 |
|
312 |
|
313 | if (!a && b || !b && a) {
|
314 | return true;
|
315 | }
|
316 |
|
317 |
|
318 | if (a.length !== b.length) {
|
319 | return true;
|
320 | }
|
321 |
|
322 |
|
323 | for (var i = 0; i < a.length; i++) {
|
324 | if (a.start(i) !== b.start(i) || a.end(i) !== b.end(i)) {
|
325 | return true;
|
326 | }
|
327 | }
|
328 |
|
329 |
|
330 |
|
331 | return false;
|
332 | };
|
333 | var lastBufferedEnd = function lastBufferedEnd(a) {
|
334 | if (!a || !a.length || !a.end) {
|
335 | return;
|
336 | }
|
337 |
|
338 | return a.end(a.length - 1);
|
339 | };
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | var timeAheadOf = function timeAheadOf(range, startTime) {
|
356 | var time = 0;
|
357 |
|
358 | if (!range || !range.length) {
|
359 | return time;
|
360 | }
|
361 |
|
362 | for (var i = 0; i < range.length; i++) {
|
363 | var start = range.start(i);
|
364 | var end = range.end(i);
|
365 |
|
366 | if (startTime > end) {
|
367 | continue;
|
368 | }
|
369 |
|
370 |
|
371 | if (startTime > start && startTime <= end) {
|
372 | time += end - startTime;
|
373 | continue;
|
374 | }
|
375 |
|
376 |
|
377 | time += end - start;
|
378 | }
|
379 |
|
380 | return time;
|
381 | };
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 | var createTimeRange = videojs__default["default"].createTimeRange;
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 | var segmentDurationWithParts = function segmentDurationWithParts(playlist, segment) {
|
403 |
|
404 |
|
405 | if (!segment.preload) {
|
406 | return segment.duration;
|
407 | }
|
408 |
|
409 |
|
410 |
|
411 | var result = 0;
|
412 | (segment.parts || []).forEach(function (p) {
|
413 | result += p.duration;
|
414 | });
|
415 |
|
416 |
|
417 | (segment.preloadHints || []).forEach(function (p) {
|
418 | if (p.type === 'PART') {
|
419 | result += playlist.partTargetDuration;
|
420 | }
|
421 | });
|
422 | return result;
|
423 | };
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 | var getPartsAndSegments = function getPartsAndSegments(playlist) {
|
434 | return (playlist.segments || []).reduce(function (acc, segment, si) {
|
435 | if (segment.parts) {
|
436 | segment.parts.forEach(function (part, pi) {
|
437 | acc.push({
|
438 | duration: part.duration,
|
439 | segmentIndex: si,
|
440 | partIndex: pi,
|
441 | part: part,
|
442 | segment: segment
|
443 | });
|
444 | });
|
445 | } else {
|
446 | acc.push({
|
447 | duration: segment.duration,
|
448 | segmentIndex: si,
|
449 | partIndex: null,
|
450 | segment: segment,
|
451 | part: null
|
452 | });
|
453 | }
|
454 |
|
455 | return acc;
|
456 | }, []);
|
457 | };
|
458 | var getLastParts = function getLastParts(media) {
|
459 | var lastSegment = media.segments && media.segments.length && media.segments[media.segments.length - 1];
|
460 | return lastSegment && lastSegment.parts || [];
|
461 | };
|
462 | var getKnownPartCount = function getKnownPartCount(_ref) {
|
463 | var preloadSegment = _ref.preloadSegment;
|
464 |
|
465 | if (!preloadSegment) {
|
466 | return;
|
467 | }
|
468 |
|
469 | var parts = preloadSegment.parts,
|
470 | preloadHints = preloadSegment.preloadHints;
|
471 | var partCount = (preloadHints || []).reduce(function (count, hint) {
|
472 | return count + (hint.type === 'PART' ? 1 : 0);
|
473 | }, 0);
|
474 | partCount += parts && parts.length ? parts.length : 0;
|
475 | return partCount;
|
476 | };
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 | var liveEdgeDelay = function liveEdgeDelay(master, media) {
|
487 | if (media.endList) {
|
488 | return 0;
|
489 | }
|
490 |
|
491 |
|
492 | if (master && master.suggestedPresentationDelay) {
|
493 | return master.suggestedPresentationDelay;
|
494 | }
|
495 |
|
496 | var hasParts = getLastParts(media).length > 0;
|
497 |
|
498 | if (hasParts && media.serverControl && media.serverControl.partHoldBack) {
|
499 | return media.serverControl.partHoldBack;
|
500 | } else if (hasParts && media.partTargetDuration) {
|
501 | return media.partTargetDuration * 3;
|
502 | } else if (media.serverControl && media.serverControl.holdBack) {
|
503 | return media.serverControl.holdBack;
|
504 | } else if (media.targetDuration) {
|
505 | return media.targetDuration * 3;
|
506 | }
|
507 |
|
508 | return 0;
|
509 | };
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 | var backwardDuration = function backwardDuration(playlist, endSequence) {
|
519 | var result = 0;
|
520 | var i = endSequence - playlist.mediaSequence;
|
521 |
|
522 |
|
523 | var segment = playlist.segments[i];
|
524 |
|
525 |
|
526 | if (segment) {
|
527 | if (typeof segment.start !== 'undefined') {
|
528 | return {
|
529 | result: segment.start,
|
530 | precise: true
|
531 | };
|
532 | }
|
533 |
|
534 | if (typeof segment.end !== 'undefined') {
|
535 | return {
|
536 | result: segment.end - segment.duration,
|
537 | precise: true
|
538 | };
|
539 | }
|
540 | }
|
541 |
|
542 | while (i--) {
|
543 | segment = playlist.segments[i];
|
544 |
|
545 | if (typeof segment.end !== 'undefined') {
|
546 | return {
|
547 | result: result + segment.end,
|
548 | precise: true
|
549 | };
|
550 | }
|
551 |
|
552 | result += segmentDurationWithParts(playlist, segment);
|
553 |
|
554 | if (typeof segment.start !== 'undefined') {
|
555 | return {
|
556 | result: result + segment.start,
|
557 | precise: true
|
558 | };
|
559 | }
|
560 | }
|
561 |
|
562 | return {
|
563 | result: result,
|
564 | precise: false
|
565 | };
|
566 | };
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 | var forwardDuration = function forwardDuration(playlist, endSequence) {
|
577 | var result = 0;
|
578 | var segment;
|
579 | var i = endSequence - playlist.mediaSequence;
|
580 |
|
581 |
|
582 | for (; i < playlist.segments.length; i++) {
|
583 | segment = playlist.segments[i];
|
584 |
|
585 | if (typeof segment.start !== 'undefined') {
|
586 | return {
|
587 | result: segment.start - result,
|
588 | precise: true
|
589 | };
|
590 | }
|
591 |
|
592 | result += segmentDurationWithParts(playlist, segment);
|
593 |
|
594 | if (typeof segment.end !== 'undefined') {
|
595 | return {
|
596 | result: segment.end - result,
|
597 | precise: true
|
598 | };
|
599 | }
|
600 | }
|
601 |
|
602 |
|
603 | return {
|
604 | result: -1,
|
605 | precise: false
|
606 | };
|
607 | };
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 | var intervalDuration = function intervalDuration(playlist, endSequence, expired) {
|
624 | if (typeof endSequence === 'undefined') {
|
625 | endSequence = playlist.mediaSequence + playlist.segments.length;
|
626 | }
|
627 |
|
628 | if (endSequence < playlist.mediaSequence) {
|
629 | return 0;
|
630 | }
|
631 |
|
632 |
|
633 | var backward = backwardDuration(playlist, endSequence);
|
634 |
|
635 | if (backward.precise) {
|
636 |
|
637 |
|
638 |
|
639 | return backward.result;
|
640 | }
|
641 |
|
642 |
|
643 |
|
644 | var forward = forwardDuration(playlist, endSequence);
|
645 |
|
646 | if (forward.precise) {
|
647 |
|
648 |
|
649 | return forward.result;
|
650 | }
|
651 |
|
652 |
|
653 | return backward.result + expired;
|
654 | };
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 | var duration = function duration(playlist, endSequence, expired) {
|
673 | if (!playlist) {
|
674 | return 0;
|
675 | }
|
676 |
|
677 | if (typeof expired !== 'number') {
|
678 | expired = 0;
|
679 | }
|
680 |
|
681 |
|
682 |
|
683 | if (typeof endSequence === 'undefined') {
|
684 |
|
685 | if (playlist.totalDuration) {
|
686 | return playlist.totalDuration;
|
687 | }
|
688 |
|
689 |
|
690 | if (!playlist.endList) {
|
691 | return window__default["default"].Infinity;
|
692 | }
|
693 | }
|
694 |
|
695 |
|
696 | return intervalDuration(playlist, endSequence, expired);
|
697 | };
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 | var sumDurations = function sumDurations(_ref2) {
|
712 | var defaultDuration = _ref2.defaultDuration,
|
713 | durationList = _ref2.durationList,
|
714 | startIndex = _ref2.startIndex,
|
715 | endIndex = _ref2.endIndex;
|
716 | var durations = 0;
|
717 |
|
718 | if (startIndex > endIndex) {
|
719 | var _ref3 = [endIndex, startIndex];
|
720 | startIndex = _ref3[0];
|
721 | endIndex = _ref3[1];
|
722 | }
|
723 |
|
724 | if (startIndex < 0) {
|
725 | for (var i = startIndex; i < Math.min(0, endIndex); i++) {
|
726 | durations += defaultDuration;
|
727 | }
|
728 |
|
729 | startIndex = 0;
|
730 | }
|
731 |
|
732 | for (var _i = startIndex; _i < endIndex; _i++) {
|
733 | durations += durationList[_i].duration;
|
734 | }
|
735 |
|
736 | return durations;
|
737 | };
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 | var playlistEnd = function playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding) {
|
759 | if (!playlist || !playlist.segments) {
|
760 | return null;
|
761 | }
|
762 |
|
763 | if (playlist.endList) {
|
764 | return duration(playlist);
|
765 | }
|
766 |
|
767 | if (expired === null) {
|
768 | return null;
|
769 | }
|
770 |
|
771 | expired = expired || 0;
|
772 | var lastSegmentEndTime = intervalDuration(playlist, playlist.mediaSequence + playlist.segments.length, expired);
|
773 |
|
774 | if (useSafeLiveEnd) {
|
775 | liveEdgePadding = typeof liveEdgePadding === 'number' ? liveEdgePadding : liveEdgeDelay(null, playlist);
|
776 | lastSegmentEndTime -= liveEdgePadding;
|
777 | }
|
778 |
|
779 |
|
780 | return Math.max(0, lastSegmentEndTime);
|
781 | };
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 | var seekable = function seekable(playlist, expired, liveEdgePadding) {
|
801 | var useSafeLiveEnd = true;
|
802 | var seekableStart = expired || 0;
|
803 | var seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding);
|
804 |
|
805 | if (seekableEnd === null) {
|
806 | return createTimeRange();
|
807 | }
|
808 |
|
809 | return createTimeRange(seekableStart, seekableEnd);
|
810 | };
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 | var getMediaInfoForTime = function getMediaInfoForTime(_ref4) {
|
826 | var playlist = _ref4.playlist,
|
827 | currentTime = _ref4.currentTime,
|
828 | startingSegmentIndex = _ref4.startingSegmentIndex,
|
829 | startingPartIndex = _ref4.startingPartIndex,
|
830 | startTime = _ref4.startTime,
|
831 | experimentalExactManifestTimings = _ref4.experimentalExactManifestTimings;
|
832 | var time = currentTime - startTime;
|
833 | var partsAndSegments = getPartsAndSegments(playlist);
|
834 | var startIndex = 0;
|
835 |
|
836 | for (var i = 0; i < partsAndSegments.length; i++) {
|
837 | var partAndSegment = partsAndSegments[i];
|
838 |
|
839 | if (startingSegmentIndex !== partAndSegment.segmentIndex) {
|
840 | continue;
|
841 | }
|
842 |
|
843 |
|
844 | if (typeof startingPartIndex === 'number' && typeof partAndSegment.partIndex === 'number' && startingPartIndex !== partAndSegment.partIndex) {
|
845 | continue;
|
846 | }
|
847 |
|
848 | startIndex = i;
|
849 | break;
|
850 | }
|
851 |
|
852 | if (time < 0) {
|
853 |
|
854 |
|
855 | if (startIndex > 0) {
|
856 | for (var _i2 = startIndex - 1; _i2 >= 0; _i2--) {
|
857 | var _partAndSegment = partsAndSegments[_i2];
|
858 | time += _partAndSegment.duration;
|
859 |
|
860 | if (experimentalExactManifestTimings) {
|
861 | if (time < 0) {
|
862 | continue;
|
863 | }
|
864 | } else if (time + TIME_FUDGE_FACTOR <= 0) {
|
865 | continue;
|
866 | }
|
867 |
|
868 | return {
|
869 | partIndex: _partAndSegment.partIndex,
|
870 | segmentIndex: _partAndSegment.segmentIndex,
|
871 | startTime: startTime - sumDurations({
|
872 | defaultDuration: playlist.targetDuration,
|
873 | durationList: partsAndSegments,
|
874 | startIndex: startIndex,
|
875 | endIndex: _i2
|
876 | })
|
877 | };
|
878 | }
|
879 | }
|
880 |
|
881 |
|
882 |
|
883 | return {
|
884 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
885 | segmentIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
886 | startTime: currentTime
|
887 | };
|
888 | }
|
889 |
|
890 |
|
891 |
|
892 |
|
893 | if (startIndex < 0) {
|
894 | for (var _i3 = startIndex; _i3 < 0; _i3++) {
|
895 | time -= playlist.targetDuration;
|
896 |
|
897 | if (time < 0) {
|
898 | return {
|
899 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
900 | segmentIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
901 | startTime: currentTime
|
902 | };
|
903 | }
|
904 | }
|
905 |
|
906 | startIndex = 0;
|
907 | }
|
908 |
|
909 |
|
910 |
|
911 | for (var _i4 = startIndex; _i4 < partsAndSegments.length; _i4++) {
|
912 | var _partAndSegment2 = partsAndSegments[_i4];
|
913 | time -= _partAndSegment2.duration;
|
914 |
|
915 | if (experimentalExactManifestTimings) {
|
916 | if (time > 0) {
|
917 | continue;
|
918 | }
|
919 | } else if (time - TIME_FUDGE_FACTOR >= 0) {
|
920 | continue;
|
921 | }
|
922 |
|
923 | return {
|
924 | partIndex: _partAndSegment2.partIndex,
|
925 | segmentIndex: _partAndSegment2.segmentIndex,
|
926 | startTime: startTime + sumDurations({
|
927 | defaultDuration: playlist.targetDuration,
|
928 | durationList: partsAndSegments,
|
929 | startIndex: startIndex,
|
930 | endIndex: _i4
|
931 | })
|
932 | };
|
933 | }
|
934 |
|
935 |
|
936 | return {
|
937 | segmentIndex: partsAndSegments[partsAndSegments.length - 1].segmentIndex,
|
938 | partIndex: partsAndSegments[partsAndSegments.length - 1].partIndex,
|
939 | startTime: currentTime
|
940 | };
|
941 | };
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 | var isBlacklisted = function isBlacklisted(playlist) {
|
951 | return playlist.excludeUntil && playlist.excludeUntil > Date.now();
|
952 | };
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 | var isIncompatible = function isIncompatible(playlist) {
|
963 | return playlist.excludeUntil && playlist.excludeUntil === Infinity;
|
964 | };
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 | var isEnabled = function isEnabled(playlist) {
|
974 | var blacklisted = isBlacklisted(playlist);
|
975 | return !playlist.disabled && !blacklisted;
|
976 | };
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 | var isDisabled = function isDisabled(playlist) {
|
986 | return playlist.disabled;
|
987 | };
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 | var isAes = function isAes(media) {
|
995 | for (var i = 0; i < media.segments.length; i++) {
|
996 | if (media.segments[i].key) {
|
997 | return true;
|
998 | }
|
999 | }
|
1000 |
|
1001 | return false;
|
1002 | };
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 | var hasAttribute = function hasAttribute(attr, playlist) {
|
1016 | return playlist.attributes && playlist.attributes[attr];
|
1017 | };
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 | var estimateSegmentRequestTime = function estimateSegmentRequestTime(segmentDuration, bandwidth, playlist, bytesReceived) {
|
1036 | if (bytesReceived === void 0) {
|
1037 | bytesReceived = 0;
|
1038 | }
|
1039 |
|
1040 | if (!hasAttribute('BANDWIDTH', playlist)) {
|
1041 | return NaN;
|
1042 | }
|
1043 |
|
1044 | var size = segmentDuration * playlist.attributes.BANDWIDTH;
|
1045 | return (size - bytesReceived * 8) / bandwidth;
|
1046 | };
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 | var isLowestEnabledRendition = function isLowestEnabledRendition(master, media) {
|
1054 | if (master.playlists.length === 1) {
|
1055 | return true;
|
1056 | }
|
1057 |
|
1058 | var currentBandwidth = media.attributes.BANDWIDTH || Number.MAX_VALUE;
|
1059 | return master.playlists.filter(function (playlist) {
|
1060 | if (!isEnabled(playlist)) {
|
1061 | return false;
|
1062 | }
|
1063 |
|
1064 | return (playlist.attributes.BANDWIDTH || 0) < currentBandwidth;
|
1065 | }).length === 0;
|
1066 | };
|
1067 | var playlistMatch = function playlistMatch(a, b) {
|
1068 |
|
1069 |
|
1070 |
|
1071 | if (!a && !b || !a && b || a && !b) {
|
1072 | return false;
|
1073 | }
|
1074 |
|
1075 |
|
1076 | if (a === b) {
|
1077 | return true;
|
1078 | }
|
1079 |
|
1080 |
|
1081 |
|
1082 | if (a.id && b.id && a.id === b.id) {
|
1083 | return true;
|
1084 | }
|
1085 |
|
1086 |
|
1087 |
|
1088 | if (a.resolvedUri && b.resolvedUri && a.resolvedUri === b.resolvedUri) {
|
1089 | return true;
|
1090 | }
|
1091 |
|
1092 |
|
1093 |
|
1094 | if (a.uri && b.uri && a.uri === b.uri) {
|
1095 | return true;
|
1096 | }
|
1097 |
|
1098 | return false;
|
1099 | };
|
1100 |
|
1101 | var someAudioVariant = function someAudioVariant(master, callback) {
|
1102 | var AUDIO = master && master.mediaGroups && master.mediaGroups.AUDIO || {};
|
1103 | var found = false;
|
1104 |
|
1105 | for (var groupName in AUDIO) {
|
1106 | for (var label in AUDIO[groupName]) {
|
1107 | found = callback(AUDIO[groupName][label]);
|
1108 |
|
1109 | if (found) {
|
1110 | break;
|
1111 | }
|
1112 | }
|
1113 |
|
1114 | if (found) {
|
1115 | break;
|
1116 | }
|
1117 | }
|
1118 |
|
1119 | return !!found;
|
1120 | };
|
1121 |
|
1122 | var isAudioOnly = function isAudioOnly(master) {
|
1123 |
|
1124 |
|
1125 | if (!master || !master.playlists || !master.playlists.length) {
|
1126 |
|
1127 |
|
1128 | var found = someAudioVariant(master, function (variant) {
|
1129 | return variant.playlists && variant.playlists.length || variant.uri;
|
1130 | });
|
1131 | return found;
|
1132 | }
|
1133 |
|
1134 |
|
1135 | var _loop = function _loop(i) {
|
1136 | var playlist = master.playlists[i];
|
1137 | var CODECS = playlist.attributes && playlist.attributes.CODECS;
|
1138 |
|
1139 | if (CODECS && CODECS.split(',').every(function (c) {
|
1140 | return codecs_js.isAudioCodec(c);
|
1141 | })) {
|
1142 | return "continue";
|
1143 | }
|
1144 |
|
1145 |
|
1146 | var found = someAudioVariant(master, function (variant) {
|
1147 | return playlistMatch(playlist, variant);
|
1148 | });
|
1149 |
|
1150 | if (found) {
|
1151 | return "continue";
|
1152 | }
|
1153 |
|
1154 |
|
1155 |
|
1156 | return {
|
1157 | v: false
|
1158 | };
|
1159 | };
|
1160 |
|
1161 | for (var i = 0; i < master.playlists.length; i++) {
|
1162 | var _ret = _loop(i);
|
1163 |
|
1164 | if (_ret === "continue") continue;
|
1165 | if (typeof _ret === "object") return _ret.v;
|
1166 | }
|
1167 |
|
1168 |
|
1169 |
|
1170 | return true;
|
1171 | };
|
1172 |
|
1173 | var Playlist = {
|
1174 | liveEdgeDelay: liveEdgeDelay,
|
1175 | duration: duration,
|
1176 | seekable: seekable,
|
1177 | getMediaInfoForTime: getMediaInfoForTime,
|
1178 | isEnabled: isEnabled,
|
1179 | isDisabled: isDisabled,
|
1180 | isBlacklisted: isBlacklisted,
|
1181 | isIncompatible: isIncompatible,
|
1182 | playlistEnd: playlistEnd,
|
1183 | isAes: isAes,
|
1184 | hasAttribute: hasAttribute,
|
1185 | estimateSegmentRequestTime: estimateSegmentRequestTime,
|
1186 | isLowestEnabledRendition: isLowestEnabledRendition,
|
1187 | isAudioOnly: isAudioOnly,
|
1188 | playlistMatch: playlistMatch,
|
1189 | segmentDurationWithParts: segmentDurationWithParts
|
1190 | };
|
1191 |
|
1192 | var log = videojs__default["default"].log;
|
1193 | var createPlaylistID = function createPlaylistID(index, uri) {
|
1194 | return index + "-" + uri;
|
1195 | };
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 | var parseManifest = function parseManifest(_ref) {
|
1216 | var onwarn = _ref.onwarn,
|
1217 | oninfo = _ref.oninfo,
|
1218 | manifestString = _ref.manifestString,
|
1219 | _ref$customTagParsers = _ref.customTagParsers,
|
1220 | customTagParsers = _ref$customTagParsers === void 0 ? [] : _ref$customTagParsers,
|
1221 | _ref$customTagMappers = _ref.customTagMappers,
|
1222 | customTagMappers = _ref$customTagMappers === void 0 ? [] : _ref$customTagMappers,
|
1223 | experimentalLLHLS = _ref.experimentalLLHLS;
|
1224 | var parser = new m3u8Parser.Parser();
|
1225 |
|
1226 | if (onwarn) {
|
1227 | parser.on('warn', onwarn);
|
1228 | }
|
1229 |
|
1230 | if (oninfo) {
|
1231 | parser.on('info', oninfo);
|
1232 | }
|
1233 |
|
1234 | customTagParsers.forEach(function (customParser) {
|
1235 | return parser.addParser(customParser);
|
1236 | });
|
1237 | customTagMappers.forEach(function (mapper) {
|
1238 | return parser.addTagMapper(mapper);
|
1239 | });
|
1240 | parser.push(manifestString);
|
1241 | parser.end();
|
1242 | var manifest = parser.manifest;
|
1243 |
|
1244 |
|
1245 | if (!experimentalLLHLS) {
|
1246 | ['preloadSegment', 'skip', 'serverControl', 'renditionReports', 'partInf', 'partTargetDuration'].forEach(function (k) {
|
1247 | if (manifest.hasOwnProperty(k)) {
|
1248 | delete manifest[k];
|
1249 | }
|
1250 | });
|
1251 |
|
1252 | if (manifest.segments) {
|
1253 | manifest.segments.forEach(function (segment) {
|
1254 | ['parts', 'preloadHints'].forEach(function (k) {
|
1255 | if (segment.hasOwnProperty(k)) {
|
1256 | delete segment[k];
|
1257 | }
|
1258 | });
|
1259 | });
|
1260 | }
|
1261 | }
|
1262 |
|
1263 | if (!manifest.targetDuration) {
|
1264 | var targetDuration = 10;
|
1265 |
|
1266 | if (manifest.segments && manifest.segments.length) {
|
1267 | targetDuration = manifest.segments.reduce(function (acc, s) {
|
1268 | return Math.max(acc, s.duration);
|
1269 | }, 0);
|
1270 | }
|
1271 |
|
1272 | if (onwarn) {
|
1273 | onwarn("manifest has no targetDuration defaulting to " + targetDuration);
|
1274 | }
|
1275 |
|
1276 | manifest.targetDuration = targetDuration;
|
1277 | }
|
1278 |
|
1279 | var parts = getLastParts(manifest);
|
1280 |
|
1281 | if (parts.length && !manifest.partTargetDuration) {
|
1282 | var partTargetDuration = parts.reduce(function (acc, p) {
|
1283 | return Math.max(acc, p.duration);
|
1284 | }, 0);
|
1285 |
|
1286 | if (onwarn) {
|
1287 | onwarn("manifest has no partTargetDuration defaulting to " + partTargetDuration);
|
1288 | 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.');
|
1289 | }
|
1290 |
|
1291 | manifest.partTargetDuration = partTargetDuration;
|
1292 | }
|
1293 |
|
1294 | return manifest;
|
1295 | };
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 | var forEachMediaGroup = function forEachMediaGroup(master, callback) {
|
1307 | if (!master.mediaGroups) {
|
1308 | return;
|
1309 | }
|
1310 |
|
1311 | ['AUDIO', 'SUBTITLES'].forEach(function (mediaType) {
|
1312 | if (!master.mediaGroups[mediaType]) {
|
1313 | return;
|
1314 | }
|
1315 |
|
1316 | for (var groupKey in master.mediaGroups[mediaType]) {
|
1317 | for (var labelKey in master.mediaGroups[mediaType][groupKey]) {
|
1318 | var mediaProperties = master.mediaGroups[mediaType][groupKey][labelKey];
|
1319 | callback(mediaProperties, mediaType, groupKey, labelKey);
|
1320 | }
|
1321 | }
|
1322 | });
|
1323 | };
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 | var setupMediaPlaylist = function setupMediaPlaylist(_ref2) {
|
1340 | var playlist = _ref2.playlist,
|
1341 | uri = _ref2.uri,
|
1342 | id = _ref2.id;
|
1343 | playlist.id = id;
|
1344 | playlist.playlistErrors_ = 0;
|
1345 |
|
1346 | if (uri) {
|
1347 |
|
1348 |
|
1349 |
|
1350 | playlist.uri = uri;
|
1351 | }
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 | playlist.attributes = playlist.attributes || {};
|
1361 | };
|
1362 |
|
1363 |
|
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 | var setupMediaPlaylists = function setupMediaPlaylists(master) {
|
1372 | var i = master.playlists.length;
|
1373 |
|
1374 | while (i--) {
|
1375 | var playlist = master.playlists[i];
|
1376 | setupMediaPlaylist({
|
1377 | playlist: playlist,
|
1378 | id: createPlaylistID(i, playlist.uri)
|
1379 | });
|
1380 | playlist.resolvedUri = resolveUrl(master.uri, playlist.uri);
|
1381 | master.playlists[playlist.id] = playlist;
|
1382 |
|
1383 | master.playlists[playlist.uri] = playlist;
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 | if (!playlist.attributes.BANDWIDTH) {
|
1389 | log.warn('Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute.');
|
1390 | }
|
1391 | }
|
1392 | };
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 | var resolveMediaGroupUris = function resolveMediaGroupUris(master) {
|
1401 | forEachMediaGroup(master, function (properties) {
|
1402 | if (properties.uri) {
|
1403 | properties.resolvedUri = resolveUrl(master.uri, properties.uri);
|
1404 | }
|
1405 | });
|
1406 | };
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 | var masterForMedia = function masterForMedia(media, uri) {
|
1420 | var id = createPlaylistID(0, uri);
|
1421 | var master = {
|
1422 | mediaGroups: {
|
1423 | 'AUDIO': {},
|
1424 | 'VIDEO': {},
|
1425 | 'CLOSED-CAPTIONS': {},
|
1426 | 'SUBTITLES': {}
|
1427 | },
|
1428 | uri: window__default["default"].location.href,
|
1429 | resolvedUri: window__default["default"].location.href,
|
1430 | playlists: [{
|
1431 | uri: uri,
|
1432 | id: id,
|
1433 | resolvedUri: uri,
|
1434 |
|
1435 |
|
1436 | attributes: {}
|
1437 | }]
|
1438 | };
|
1439 |
|
1440 | master.playlists[id] = master.playlists[0];
|
1441 |
|
1442 | master.playlists[uri] = master.playlists[0];
|
1443 | return master;
|
1444 | };
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 | var addPropertiesToMaster = function addPropertiesToMaster(master, uri) {
|
1456 | master.uri = uri;
|
1457 |
|
1458 | for (var i = 0; i < master.playlists.length; i++) {
|
1459 | if (!master.playlists[i].uri) {
|
1460 |
|
1461 |
|
1462 |
|
1463 | var phonyUri = "placeholder-uri-" + i;
|
1464 | master.playlists[i].uri = phonyUri;
|
1465 | }
|
1466 | }
|
1467 |
|
1468 | var audioOnlyMaster = isAudioOnly(master);
|
1469 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
1470 | var groupId = "placeholder-uri-" + mediaType + "-" + groupKey + "-" + labelKey;
|
1471 |
|
1472 | if (!properties.playlists || !properties.playlists.length) {
|
1473 |
|
1474 |
|
1475 |
|
1476 | if (audioOnlyMaster && mediaType === 'AUDIO' && !properties.uri) {
|
1477 | for (var _i = 0; _i < master.playlists.length; _i++) {
|
1478 | var p = master.playlists[_i];
|
1479 |
|
1480 | if (p.attributes && p.attributes.AUDIO && p.attributes.AUDIO === groupKey) {
|
1481 | return;
|
1482 | }
|
1483 | }
|
1484 | }
|
1485 |
|
1486 | properties.playlists = [_extends__default["default"]({}, properties)];
|
1487 | }
|
1488 |
|
1489 | properties.playlists.forEach(function (p, i) {
|
1490 | var id = createPlaylistID(i, groupId);
|
1491 |
|
1492 | if (p.uri) {
|
1493 | p.resolvedUri = p.resolvedUri || resolveUrl(master.uri, p.uri);
|
1494 | } else {
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 | p.uri = i === 0 ? groupId : id;
|
1500 |
|
1501 |
|
1502 | p.resolvedUri = p.uri;
|
1503 | }
|
1504 |
|
1505 | p.id = p.id || id;
|
1506 |
|
1507 |
|
1508 | p.attributes = p.attributes || {};
|
1509 |
|
1510 | master.playlists[p.id] = p;
|
1511 | master.playlists[p.uri] = p;
|
1512 | });
|
1513 | });
|
1514 | setupMediaPlaylists(master);
|
1515 | resolveMediaGroupUris(master);
|
1516 | };
|
1517 |
|
1518 | var mergeOptions$2 = videojs__default["default"].mergeOptions,
|
1519 | EventTarget$1 = videojs__default["default"].EventTarget;
|
1520 |
|
1521 | var addLLHLSQueryDirectives = function addLLHLSQueryDirectives(uri, media) {
|
1522 | if (media.endList || !media.serverControl) {
|
1523 | return uri;
|
1524 | }
|
1525 |
|
1526 | var parameters = {};
|
1527 |
|
1528 | if (media.serverControl.canBlockReload) {
|
1529 | var preloadSegment = media.preloadSegment;
|
1530 |
|
1531 | var nextMSN = media.mediaSequence + media.segments.length;
|
1532 |
|
1533 |
|
1534 |
|
1535 | if (preloadSegment) {
|
1536 | var parts = preloadSegment.parts || [];
|
1537 |
|
1538 | var nextPart = getKnownPartCount(media) - 1;
|
1539 |
|
1540 |
|
1541 |
|
1542 | if (nextPart > -1 && nextPart !== parts.length - 1) {
|
1543 |
|
1544 |
|
1545 | parameters._HLS_part = nextPart;
|
1546 | }
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 | if (nextPart > -1 || parts.length) {
|
1558 | nextMSN--;
|
1559 | }
|
1560 | }
|
1561 |
|
1562 |
|
1563 |
|
1564 | parameters._HLS_msn = nextMSN;
|
1565 | }
|
1566 |
|
1567 | if (media.serverControl && media.serverControl.canSkipUntil) {
|
1568 |
|
1569 |
|
1570 | parameters._HLS_skip = media.serverControl.canSkipDateranges ? 'v2' : 'YES';
|
1571 | }
|
1572 |
|
1573 | if (Object.keys(parameters).length) {
|
1574 | var parsedUri = new window__default["default"].URL(uri);
|
1575 | ['_HLS_skip', '_HLS_msn', '_HLS_part'].forEach(function (name) {
|
1576 | if (!parameters.hasOwnProperty(name)) {
|
1577 | return;
|
1578 | }
|
1579 |
|
1580 | parsedUri.searchParams.set(name, parameters[name]);
|
1581 | });
|
1582 | uri = parsedUri.toString();
|
1583 | }
|
1584 |
|
1585 | return uri;
|
1586 | };
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 | var updateSegment = function updateSegment(a, b) {
|
1599 | if (!a) {
|
1600 | return b;
|
1601 | }
|
1602 |
|
1603 | var result = mergeOptions$2(a, b);
|
1604 |
|
1605 |
|
1606 | if (a.preloadHints && !b.preloadHints) {
|
1607 | delete result.preloadHints;
|
1608 | }
|
1609 |
|
1610 |
|
1611 |
|
1612 | if (a.parts && !b.parts) {
|
1613 | delete result.parts;
|
1614 |
|
1615 |
|
1616 | } else if (a.parts && b.parts) {
|
1617 | for (var i = 0; i < b.parts.length; i++) {
|
1618 | if (a.parts && a.parts[i]) {
|
1619 | result.parts[i] = mergeOptions$2(a.parts[i], b.parts[i]);
|
1620 | }
|
1621 | }
|
1622 | }
|
1623 |
|
1624 |
|
1625 |
|
1626 | if (!a.skipped && b.skipped) {
|
1627 | result.skipped = false;
|
1628 | }
|
1629 |
|
1630 |
|
1631 |
|
1632 | if (a.preload && !b.preload) {
|
1633 | result.preload = false;
|
1634 | }
|
1635 |
|
1636 | return result;
|
1637 | };
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 | var updateSegments = function updateSegments(original, update, offset) {
|
1655 | var oldSegments = original.slice();
|
1656 | var newSegments = update.slice();
|
1657 | offset = offset || 0;
|
1658 | var result = [];
|
1659 | var currentMap;
|
1660 |
|
1661 | for (var newIndex = 0; newIndex < newSegments.length; newIndex++) {
|
1662 | var oldSegment = oldSegments[newIndex + offset];
|
1663 | var newSegment = newSegments[newIndex];
|
1664 |
|
1665 | if (oldSegment) {
|
1666 | currentMap = oldSegment.map || currentMap;
|
1667 | result.push(updateSegment(oldSegment, newSegment));
|
1668 | } else {
|
1669 |
|
1670 | if (currentMap && !newSegment.map) {
|
1671 | newSegment.map = currentMap;
|
1672 | }
|
1673 |
|
1674 | result.push(newSegment);
|
1675 | }
|
1676 | }
|
1677 |
|
1678 | return result;
|
1679 | };
|
1680 | var resolveSegmentUris = function resolveSegmentUris(segment, baseUri) {
|
1681 |
|
1682 |
|
1683 | if (!segment.resolvedUri && segment.uri) {
|
1684 | segment.resolvedUri = resolveUrl(baseUri, segment.uri);
|
1685 | }
|
1686 |
|
1687 | if (segment.key && !segment.key.resolvedUri) {
|
1688 | segment.key.resolvedUri = resolveUrl(baseUri, segment.key.uri);
|
1689 | }
|
1690 |
|
1691 | if (segment.map && !segment.map.resolvedUri) {
|
1692 | segment.map.resolvedUri = resolveUrl(baseUri, segment.map.uri);
|
1693 | }
|
1694 |
|
1695 | if (segment.map && segment.map.key && !segment.map.key.resolvedUri) {
|
1696 | segment.map.key.resolvedUri = resolveUrl(baseUri, segment.map.key.uri);
|
1697 | }
|
1698 |
|
1699 | if (segment.parts && segment.parts.length) {
|
1700 | segment.parts.forEach(function (p) {
|
1701 | if (p.resolvedUri) {
|
1702 | return;
|
1703 | }
|
1704 |
|
1705 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
1706 | });
|
1707 | }
|
1708 |
|
1709 | if (segment.preloadHints && segment.preloadHints.length) {
|
1710 | segment.preloadHints.forEach(function (p) {
|
1711 | if (p.resolvedUri) {
|
1712 | return;
|
1713 | }
|
1714 |
|
1715 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
1716 | });
|
1717 | }
|
1718 | };
|
1719 |
|
1720 | var getAllSegments = function getAllSegments(media) {
|
1721 | var segments = media.segments || [];
|
1722 | var preloadSegment = media.preloadSegment;
|
1723 |
|
1724 |
|
1725 |
|
1726 | if (preloadSegment && preloadSegment.parts && preloadSegment.parts.length) {
|
1727 |
|
1728 |
|
1729 |
|
1730 | if (preloadSegment.preloadHints) {
|
1731 | for (var i = 0; i < preloadSegment.preloadHints.length; i++) {
|
1732 | if (preloadSegment.preloadHints[i].type === 'MAP') {
|
1733 | return segments;
|
1734 | }
|
1735 | }
|
1736 | }
|
1737 |
|
1738 |
|
1739 | preloadSegment.duration = media.targetDuration;
|
1740 | preloadSegment.preload = true;
|
1741 | segments.push(preloadSegment);
|
1742 | }
|
1743 |
|
1744 | return segments;
|
1745 | };
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 | var isPlaylistUnchanged = function isPlaylistUnchanged(a, b) {
|
1751 | return a === b || a.segments && b.segments && a.segments.length === b.segments.length && a.endList === b.endList && a.mediaSequence === b.mediaSequence && a.preloadSegment === b.preloadSegment;
|
1752 | };
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 | var updateMaster$1 = function updateMaster(master, newMedia, unchangedCheck) {
|
1767 | if (unchangedCheck === void 0) {
|
1768 | unchangedCheck = isPlaylistUnchanged;
|
1769 | }
|
1770 |
|
1771 | var result = mergeOptions$2(master, {});
|
1772 | var oldMedia = result.playlists[newMedia.id];
|
1773 |
|
1774 | if (!oldMedia) {
|
1775 | return null;
|
1776 | }
|
1777 |
|
1778 | if (unchangedCheck(oldMedia, newMedia)) {
|
1779 | return null;
|
1780 | }
|
1781 |
|
1782 | newMedia.segments = getAllSegments(newMedia);
|
1783 | var mergedPlaylist = mergeOptions$2(oldMedia, newMedia);
|
1784 |
|
1785 | if (mergedPlaylist.preloadSegment && !newMedia.preloadSegment) {
|
1786 | delete mergedPlaylist.preloadSegment;
|
1787 | }
|
1788 |
|
1789 |
|
1790 | if (oldMedia.segments) {
|
1791 | if (newMedia.skip) {
|
1792 | newMedia.segments = newMedia.segments || [];
|
1793 |
|
1794 |
|
1795 | for (var i = 0; i < newMedia.skip.skippedSegments; i++) {
|
1796 | newMedia.segments.unshift({
|
1797 | skipped: true
|
1798 | });
|
1799 | }
|
1800 | }
|
1801 |
|
1802 | mergedPlaylist.segments = updateSegments(oldMedia.segments, newMedia.segments, newMedia.mediaSequence - oldMedia.mediaSequence);
|
1803 | }
|
1804 |
|
1805 |
|
1806 | mergedPlaylist.segments.forEach(function (segment) {
|
1807 | resolveSegmentUris(segment, mergedPlaylist.resolvedUri);
|
1808 | });
|
1809 |
|
1810 |
|
1811 |
|
1812 | for (var _i = 0; _i < result.playlists.length; _i++) {
|
1813 | if (result.playlists[_i].id === newMedia.id) {
|
1814 | result.playlists[_i] = mergedPlaylist;
|
1815 | }
|
1816 | }
|
1817 |
|
1818 | result.playlists[newMedia.id] = mergedPlaylist;
|
1819 |
|
1820 | result.playlists[newMedia.uri] = mergedPlaylist;
|
1821 |
|
1822 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
1823 | if (!properties.playlists) {
|
1824 | return;
|
1825 | }
|
1826 |
|
1827 | for (var _i2 = 0; _i2 < properties.playlists.length; _i2++) {
|
1828 | if (newMedia.id === properties.playlists[_i2].id) {
|
1829 | properties.playlists[_i2] = mergedPlaylist;
|
1830 | }
|
1831 | }
|
1832 | });
|
1833 | return result;
|
1834 | };
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 | var refreshDelay = function refreshDelay(media, update) {
|
1847 | var segments = media.segments || [];
|
1848 | var lastSegment = segments[segments.length - 1];
|
1849 | var lastPart = lastSegment && lastSegment.parts && lastSegment.parts[lastSegment.parts.length - 1];
|
1850 | var lastDuration = lastPart && lastPart.duration || lastSegment && lastSegment.duration;
|
1851 |
|
1852 | if (update && lastDuration) {
|
1853 | return lastDuration * 1000;
|
1854 | }
|
1855 |
|
1856 |
|
1857 |
|
1858 | return (media.partTargetDuration || media.targetDuration || 10) * 500;
|
1859 | };
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 | var PlaylistLoader = function (_EventTarget) {
|
1871 | _inheritsLoose__default["default"](PlaylistLoader, _EventTarget);
|
1872 |
|
1873 | function PlaylistLoader(src, vhs, options) {
|
1874 | var _this;
|
1875 |
|
1876 | if (options === void 0) {
|
1877 | options = {};
|
1878 | }
|
1879 |
|
1880 | _this = _EventTarget.call(this) || this;
|
1881 |
|
1882 | if (!src) {
|
1883 | throw new Error('A non-empty playlist URL or object is required');
|
1884 | }
|
1885 |
|
1886 | _this.logger_ = logger('PlaylistLoader');
|
1887 | var _options = options,
|
1888 | _options$withCredenti = _options.withCredentials,
|
1889 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
1890 | _options$handleManife = _options.handleManifestRedirects,
|
1891 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
1892 | _this.src = src;
|
1893 | _this.vhs_ = vhs;
|
1894 | _this.withCredentials = withCredentials;
|
1895 | _this.handleManifestRedirects = handleManifestRedirects;
|
1896 | var vhsOptions = vhs.options_;
|
1897 | _this.customTagParsers = vhsOptions && vhsOptions.customTagParsers || [];
|
1898 | _this.customTagMappers = vhsOptions && vhsOptions.customTagMappers || [];
|
1899 | _this.experimentalLLHLS = vhsOptions && vhsOptions.experimentalLLHLS || false;
|
1900 |
|
1901 | if (videojs__default["default"].browser.IE_VERSION) {
|
1902 | _this.experimentalLLHLS = false;
|
1903 | }
|
1904 |
|
1905 |
|
1906 | _this.state = 'HAVE_NOTHING';
|
1907 |
|
1908 | _this.handleMediaupdatetimeout_ = _this.handleMediaupdatetimeout_.bind(_assertThisInitialized__default["default"](_this));
|
1909 |
|
1910 | _this.on('mediaupdatetimeout', _this.handleMediaupdatetimeout_);
|
1911 |
|
1912 | return _this;
|
1913 | }
|
1914 |
|
1915 | var _proto = PlaylistLoader.prototype;
|
1916 |
|
1917 | _proto.handleMediaupdatetimeout_ = function handleMediaupdatetimeout_() {
|
1918 | var _this2 = this;
|
1919 |
|
1920 | if (this.state !== 'HAVE_METADATA') {
|
1921 |
|
1922 | return;
|
1923 | }
|
1924 |
|
1925 | var media = this.media();
|
1926 | var uri = resolveUrl(this.master.uri, media.uri);
|
1927 |
|
1928 | if (this.experimentalLLHLS) {
|
1929 | uri = addLLHLSQueryDirectives(uri, media);
|
1930 | }
|
1931 |
|
1932 | this.state = 'HAVE_CURRENT_METADATA';
|
1933 | this.request = this.vhs_.xhr({
|
1934 | uri: uri,
|
1935 | withCredentials: this.withCredentials
|
1936 | }, function (error, req) {
|
1937 |
|
1938 | if (!_this2.request) {
|
1939 | return;
|
1940 | }
|
1941 |
|
1942 | if (error) {
|
1943 | return _this2.playlistRequestError(_this2.request, _this2.media(), 'HAVE_METADATA');
|
1944 | }
|
1945 |
|
1946 | _this2.haveMetadata({
|
1947 | playlistString: _this2.request.responseText,
|
1948 | url: _this2.media().uri,
|
1949 | id: _this2.media().id
|
1950 | });
|
1951 | });
|
1952 | };
|
1953 |
|
1954 | _proto.playlistRequestError = function playlistRequestError(xhr, playlist, startingState) {
|
1955 | var uri = playlist.uri,
|
1956 | id = playlist.id;
|
1957 |
|
1958 | this.request = null;
|
1959 |
|
1960 | if (startingState) {
|
1961 | this.state = startingState;
|
1962 | }
|
1963 |
|
1964 | this.error = {
|
1965 | playlist: this.master.playlists[id],
|
1966 | status: xhr.status,
|
1967 | message: "HLS playlist request error at URL: " + uri + ".",
|
1968 | responseText: xhr.responseText,
|
1969 | code: xhr.status >= 500 ? 4 : 2
|
1970 | };
|
1971 | this.trigger('error');
|
1972 | };
|
1973 |
|
1974 | _proto.parseManifest_ = function parseManifest_(_ref) {
|
1975 | var _this3 = this;
|
1976 |
|
1977 | var url = _ref.url,
|
1978 | manifestString = _ref.manifestString;
|
1979 | return parseManifest({
|
1980 | onwarn: function onwarn(_ref2) {
|
1981 | var message = _ref2.message;
|
1982 | return _this3.logger_("m3u8-parser warn for " + url + ": " + message);
|
1983 | },
|
1984 | oninfo: function oninfo(_ref3) {
|
1985 | var message = _ref3.message;
|
1986 | return _this3.logger_("m3u8-parser info for " + url + ": " + message);
|
1987 | },
|
1988 | manifestString: manifestString,
|
1989 | customTagParsers: this.customTagParsers,
|
1990 | customTagMappers: this.customTagMappers,
|
1991 | experimentalLLHLS: this.experimentalLLHLS
|
1992 | });
|
1993 | }
|
1994 | |
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 | ;
|
2007 |
|
2008 | _proto.haveMetadata = function haveMetadata(_ref4) {
|
2009 | var playlistString = _ref4.playlistString,
|
2010 | playlistObject = _ref4.playlistObject,
|
2011 | url = _ref4.url,
|
2012 | id = _ref4.id;
|
2013 |
|
2014 | this.request = null;
|
2015 | this.state = 'HAVE_METADATA';
|
2016 | var playlist = playlistObject || this.parseManifest_({
|
2017 | url: url,
|
2018 | manifestString: playlistString
|
2019 | });
|
2020 | playlist.lastRequest = Date.now();
|
2021 | setupMediaPlaylist({
|
2022 | playlist: playlist,
|
2023 | uri: url,
|
2024 | id: id
|
2025 | });
|
2026 |
|
2027 | var update = updateMaster$1(this.master, playlist);
|
2028 | this.targetDuration = playlist.partTargetDuration || playlist.targetDuration;
|
2029 | this.pendingMedia_ = null;
|
2030 |
|
2031 | if (update) {
|
2032 | this.master = update;
|
2033 | this.media_ = this.master.playlists[id];
|
2034 | } else {
|
2035 | this.trigger('playlistunchanged');
|
2036 | }
|
2037 |
|
2038 | this.updateMediaUpdateTimeout_(refreshDelay(this.media(), !!update));
|
2039 | this.trigger('loadedplaylist');
|
2040 | }
|
2041 | |
2042 |
|
2043 |
|
2044 | ;
|
2045 |
|
2046 | _proto.dispose = function dispose() {
|
2047 | this.trigger('dispose');
|
2048 | this.stopRequest();
|
2049 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2050 | window__default["default"].clearTimeout(this.finalRenditionTimeout);
|
2051 | this.off();
|
2052 | };
|
2053 |
|
2054 | _proto.stopRequest = function stopRequest() {
|
2055 | if (this.request) {
|
2056 | var oldRequest = this.request;
|
2057 | this.request = null;
|
2058 | oldRequest.onreadystatechange = null;
|
2059 | oldRequest.abort();
|
2060 | }
|
2061 | }
|
2062 | |
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 | ;
|
2077 |
|
2078 | _proto.media = function media(playlist, shouldDelay) {
|
2079 | var _this4 = this;
|
2080 |
|
2081 |
|
2082 | if (!playlist) {
|
2083 | return this.media_;
|
2084 | }
|
2085 |
|
2086 |
|
2087 | if (this.state === 'HAVE_NOTHING') {
|
2088 | throw new Error('Cannot switch media playlist from ' + this.state);
|
2089 | }
|
2090 |
|
2091 |
|
2092 |
|
2093 | if (typeof playlist === 'string') {
|
2094 | if (!this.master.playlists[playlist]) {
|
2095 | throw new Error('Unknown playlist URI: ' + playlist);
|
2096 | }
|
2097 |
|
2098 | playlist = this.master.playlists[playlist];
|
2099 | }
|
2100 |
|
2101 | window__default["default"].clearTimeout(this.finalRenditionTimeout);
|
2102 |
|
2103 | if (shouldDelay) {
|
2104 | var delay = (playlist.partTargetDuration || playlist.targetDuration) / 2 * 1000 || 5 * 1000;
|
2105 | this.finalRenditionTimeout = window__default["default"].setTimeout(this.media.bind(this, playlist, false), delay);
|
2106 | return;
|
2107 | }
|
2108 |
|
2109 | var startingState = this.state;
|
2110 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
2111 | var masterPlaylistRef = this.master.playlists[playlist.id];
|
2112 |
|
2113 | if (masterPlaylistRef && masterPlaylistRef.endList ||
|
2114 |
|
2115 | playlist.endList && playlist.segments.length) {
|
2116 |
|
2117 | if (this.request) {
|
2118 | this.request.onreadystatechange = null;
|
2119 | this.request.abort();
|
2120 | this.request = null;
|
2121 | }
|
2122 |
|
2123 | this.state = 'HAVE_METADATA';
|
2124 | this.media_ = playlist;
|
2125 |
|
2126 | if (mediaChange) {
|
2127 | this.trigger('mediachanging');
|
2128 |
|
2129 | if (startingState === 'HAVE_MASTER') {
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 | this.trigger('loadedmetadata');
|
2136 | } else {
|
2137 | this.trigger('mediachange');
|
2138 | }
|
2139 | }
|
2140 |
|
2141 | return;
|
2142 | }
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 | this.updateMediaUpdateTimeout_(refreshDelay(playlist, true));
|
2150 |
|
2151 | if (!mediaChange) {
|
2152 | return;
|
2153 | }
|
2154 |
|
2155 | this.state = 'SWITCHING_MEDIA';
|
2156 |
|
2157 | if (this.request) {
|
2158 | if (playlist.resolvedUri === this.request.url) {
|
2159 |
|
2160 |
|
2161 | return;
|
2162 | }
|
2163 |
|
2164 | this.request.onreadystatechange = null;
|
2165 | this.request.abort();
|
2166 | this.request = null;
|
2167 | }
|
2168 |
|
2169 |
|
2170 | if (this.media_) {
|
2171 | this.trigger('mediachanging');
|
2172 | }
|
2173 |
|
2174 | this.pendingMedia_ = playlist;
|
2175 | this.request = this.vhs_.xhr({
|
2176 | uri: playlist.resolvedUri,
|
2177 | withCredentials: this.withCredentials
|
2178 | }, function (error, req) {
|
2179 |
|
2180 | if (!_this4.request) {
|
2181 | return;
|
2182 | }
|
2183 |
|
2184 | playlist.lastRequest = Date.now();
|
2185 | playlist.resolvedUri = resolveManifestRedirect(_this4.handleManifestRedirects, playlist.resolvedUri, req);
|
2186 |
|
2187 | if (error) {
|
2188 | return _this4.playlistRequestError(_this4.request, playlist, startingState);
|
2189 | }
|
2190 |
|
2191 | _this4.haveMetadata({
|
2192 | playlistString: req.responseText,
|
2193 | url: playlist.uri,
|
2194 | id: playlist.id
|
2195 | });
|
2196 |
|
2197 |
|
2198 | if (startingState === 'HAVE_MASTER') {
|
2199 | _this4.trigger('loadedmetadata');
|
2200 | } else {
|
2201 | _this4.trigger('mediachange');
|
2202 | }
|
2203 | });
|
2204 | }
|
2205 | |
2206 |
|
2207 |
|
2208 | ;
|
2209 |
|
2210 | _proto.pause = function pause() {
|
2211 | if (this.mediaUpdateTimeout) {
|
2212 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2213 | this.mediaUpdateTimeout = null;
|
2214 | }
|
2215 |
|
2216 | this.stopRequest();
|
2217 |
|
2218 | if (this.state === 'HAVE_NOTHING') {
|
2219 |
|
2220 |
|
2221 | this.started = false;
|
2222 | }
|
2223 |
|
2224 |
|
2225 | if (this.state === 'SWITCHING_MEDIA') {
|
2226 |
|
2227 |
|
2228 |
|
2229 | if (this.media_) {
|
2230 | this.state = 'HAVE_METADATA';
|
2231 | } else {
|
2232 | this.state = 'HAVE_MASTER';
|
2233 | }
|
2234 | } else if (this.state === 'HAVE_CURRENT_METADATA') {
|
2235 | this.state = 'HAVE_METADATA';
|
2236 | }
|
2237 | }
|
2238 | |
2239 |
|
2240 |
|
2241 | ;
|
2242 |
|
2243 | _proto.load = function load(shouldDelay) {
|
2244 | var _this5 = this;
|
2245 |
|
2246 | if (this.mediaUpdateTimeout) {
|
2247 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2248 | this.mediaUpdateTimeout = null;
|
2249 | }
|
2250 |
|
2251 | var media = this.media();
|
2252 |
|
2253 | if (shouldDelay) {
|
2254 | var delay = media ? (media.partTargetDuration || media.targetDuration) / 2 * 1000 : 5 * 1000;
|
2255 | this.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
2256 | _this5.mediaUpdateTimeout = null;
|
2257 |
|
2258 | _this5.load();
|
2259 | }, delay);
|
2260 | return;
|
2261 | }
|
2262 |
|
2263 | if (!this.started) {
|
2264 | this.start();
|
2265 | return;
|
2266 | }
|
2267 |
|
2268 | if (media && !media.endList) {
|
2269 | this.trigger('mediaupdatetimeout');
|
2270 | } else {
|
2271 | this.trigger('loadedplaylist');
|
2272 | }
|
2273 | };
|
2274 |
|
2275 | _proto.updateMediaUpdateTimeout_ = function updateMediaUpdateTimeout_(delay) {
|
2276 | var _this6 = this;
|
2277 |
|
2278 | if (this.mediaUpdateTimeout) {
|
2279 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2280 | this.mediaUpdateTimeout = null;
|
2281 | }
|
2282 |
|
2283 |
|
2284 | if (!this.media() || this.media().endList) {
|
2285 | return;
|
2286 | }
|
2287 |
|
2288 | this.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
2289 | _this6.mediaUpdateTimeout = null;
|
2290 |
|
2291 | _this6.trigger('mediaupdatetimeout');
|
2292 |
|
2293 | _this6.updateMediaUpdateTimeout_(delay);
|
2294 | }, delay);
|
2295 | }
|
2296 | |
2297 |
|
2298 |
|
2299 | ;
|
2300 |
|
2301 | _proto.start = function start() {
|
2302 | var _this7 = this;
|
2303 |
|
2304 | this.started = true;
|
2305 |
|
2306 | if (typeof this.src === 'object') {
|
2307 |
|
2308 |
|
2309 | if (!this.src.uri) {
|
2310 | this.src.uri = window__default["default"].location.href;
|
2311 | }
|
2312 |
|
2313 |
|
2314 |
|
2315 | this.src.resolvedUri = this.src.uri;
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 | setTimeout(function () {
|
2326 | _this7.setupInitialPlaylist(_this7.src);
|
2327 | }, 0);
|
2328 | return;
|
2329 | }
|
2330 |
|
2331 |
|
2332 | this.request = this.vhs_.xhr({
|
2333 | uri: this.src,
|
2334 | withCredentials: this.withCredentials
|
2335 | }, function (error, req) {
|
2336 |
|
2337 | if (!_this7.request) {
|
2338 | return;
|
2339 | }
|
2340 |
|
2341 |
|
2342 | _this7.request = null;
|
2343 |
|
2344 | if (error) {
|
2345 | _this7.error = {
|
2346 | status: req.status,
|
2347 | message: "HLS playlist request error at URL: " + _this7.src + ".",
|
2348 | responseText: req.responseText,
|
2349 |
|
2350 | code: 2
|
2351 | };
|
2352 |
|
2353 | if (_this7.state === 'HAVE_NOTHING') {
|
2354 | _this7.started = false;
|
2355 | }
|
2356 |
|
2357 | return _this7.trigger('error');
|
2358 | }
|
2359 |
|
2360 | _this7.src = resolveManifestRedirect(_this7.handleManifestRedirects, _this7.src, req);
|
2361 |
|
2362 | var manifest = _this7.parseManifest_({
|
2363 | manifestString: req.responseText,
|
2364 | url: _this7.src
|
2365 | });
|
2366 |
|
2367 | _this7.setupInitialPlaylist(manifest);
|
2368 | });
|
2369 | };
|
2370 |
|
2371 | _proto.srcUri = function srcUri() {
|
2372 | return typeof this.src === 'string' ? this.src : this.src.uri;
|
2373 | }
|
2374 | |
2375 |
|
2376 |
|
2377 |
|
2378 |
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 | ;
|
2393 |
|
2394 | _proto.setupInitialPlaylist = function setupInitialPlaylist(manifest) {
|
2395 | this.state = 'HAVE_MASTER';
|
2396 |
|
2397 | if (manifest.playlists) {
|
2398 | this.master = manifest;
|
2399 | addPropertiesToMaster(this.master, this.srcUri());
|
2400 |
|
2401 |
|
2402 |
|
2403 | manifest.playlists.forEach(function (playlist) {
|
2404 | playlist.segments = getAllSegments(playlist);
|
2405 | playlist.segments.forEach(function (segment) {
|
2406 | resolveSegmentUris(segment, playlist.resolvedUri);
|
2407 | });
|
2408 | });
|
2409 | this.trigger('loadedplaylist');
|
2410 |
|
2411 | if (!this.request) {
|
2412 |
|
2413 |
|
2414 | this.media(this.master.playlists[0]);
|
2415 | }
|
2416 |
|
2417 | return;
|
2418 | }
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 | var uri = this.srcUri() || window__default["default"].location.href;
|
2424 | this.master = masterForMedia(manifest, uri);
|
2425 | this.haveMetadata({
|
2426 | playlistObject: manifest,
|
2427 | url: uri,
|
2428 | id: this.master.playlists[0].id
|
2429 | });
|
2430 | this.trigger('loadedmetadata');
|
2431 | };
|
2432 |
|
2433 | return PlaylistLoader;
|
2434 | }(EventTarget$1);
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 | var videojsXHR = videojs__default["default"].xhr,
|
2440 | mergeOptions$1 = videojs__default["default"].mergeOptions;
|
2441 |
|
2442 | var callbackWrapper = function callbackWrapper(request, error, response, callback) {
|
2443 | var reqResponse = request.responseType === 'arraybuffer' ? request.response : request.responseText;
|
2444 |
|
2445 | if (!error && reqResponse) {
|
2446 | request.responseTime = Date.now();
|
2447 | request.roundTripTime = request.responseTime - request.requestTime;
|
2448 | request.bytesReceived = reqResponse.byteLength || reqResponse.length;
|
2449 |
|
2450 | if (!request.bandwidth) {
|
2451 | request.bandwidth = Math.floor(request.bytesReceived / request.roundTripTime * 8 * 1000);
|
2452 | }
|
2453 | }
|
2454 |
|
2455 | if (response.headers) {
|
2456 | request.responseHeaders = response.headers;
|
2457 | }
|
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 | if (error && error.code === 'ETIMEDOUT') {
|
2463 | request.timedout = true;
|
2464 | }
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 | if (!error && !request.aborted && response.statusCode !== 200 && response.statusCode !== 206 && response.statusCode !== 0) {
|
2470 | error = new Error('XHR Failed with a response of: ' + (request && (reqResponse || request.responseText)));
|
2471 | }
|
2472 |
|
2473 | callback(error, request);
|
2474 | };
|
2475 |
|
2476 | var xhrFactory = function xhrFactory() {
|
2477 | var xhr = function XhrFunction(options, callback) {
|
2478 |
|
2479 | options = mergeOptions$1({
|
2480 | timeout: 45e3
|
2481 | }, options);
|
2482 |
|
2483 |
|
2484 | var beforeRequest = XhrFunction.beforeRequest || videojs__default["default"].Vhs.xhr.beforeRequest;
|
2485 |
|
2486 | if (beforeRequest && typeof beforeRequest === 'function') {
|
2487 | var newOptions = beforeRequest(options);
|
2488 |
|
2489 | if (newOptions) {
|
2490 | options = newOptions;
|
2491 | }
|
2492 | }
|
2493 |
|
2494 |
|
2495 |
|
2496 | var xhrMethod = videojs__default["default"].Vhs.xhr.original === true ? videojsXHR : videojs__default["default"].Vhs.xhr;
|
2497 | var request = xhrMethod(options, function (error, response) {
|
2498 | return callbackWrapper(request, error, response, callback);
|
2499 | });
|
2500 | var originalAbort = request.abort;
|
2501 |
|
2502 | request.abort = function () {
|
2503 | request.aborted = true;
|
2504 | return originalAbort.apply(request, arguments);
|
2505 | };
|
2506 |
|
2507 | request.uri = options.uri;
|
2508 | request.requestTime = Date.now();
|
2509 | return request;
|
2510 | };
|
2511 |
|
2512 | xhr.original = true;
|
2513 | return xhr;
|
2514 | };
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 |
|
2524 | var byterangeStr = function byterangeStr(byterange) {
|
2525 |
|
2526 |
|
2527 | var byterangeEnd;
|
2528 | var byterangeStart = byterange.offset;
|
2529 |
|
2530 | if (typeof byterange.offset === 'bigint' || typeof byterange.length === 'bigint') {
|
2531 | byterangeEnd = window__default["default"].BigInt(byterange.offset) + window__default["default"].BigInt(byterange.length) - window__default["default"].BigInt(1);
|
2532 | } else {
|
2533 | byterangeEnd = byterange.offset + byterange.length - 1;
|
2534 | }
|
2535 |
|
2536 | return 'bytes=' + byterangeStart + '-' + byterangeEnd;
|
2537 | };
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 | var segmentXhrHeaders = function segmentXhrHeaders(segment) {
|
2546 | var headers = {};
|
2547 |
|
2548 | if (segment.byterange) {
|
2549 | headers.Range = byterangeStr(segment.byterange);
|
2550 | }
|
2551 |
|
2552 | return headers;
|
2553 | };
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 |
|
2559 |
|
2560 |
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 | var textRange = function textRange(range, i) {
|
2568 | return range.start(i) + '-' + range.end(i);
|
2569 | };
|
2570 |
|
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 | var formatHexString = function formatHexString(e, i) {
|
2580 | var value = e.toString(16);
|
2581 | return '00'.substring(0, 2 - value.length) + value + (i % 2 ? ' ' : '');
|
2582 | };
|
2583 |
|
2584 | var formatAsciiString = function formatAsciiString(e) {
|
2585 | if (e >= 0x20 && e < 0x7e) {
|
2586 | return String.fromCharCode(e);
|
2587 | }
|
2588 |
|
2589 | return '.';
|
2590 | };
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 |
|
2597 |
|
2598 |
|
2599 |
|
2600 |
|
2601 |
|
2602 |
|
2603 | var createTransferableMessage = function createTransferableMessage(message) {
|
2604 | var transferable = {};
|
2605 | Object.keys(message).forEach(function (key) {
|
2606 | var value = message[key];
|
2607 |
|
2608 | if (byteHelpers.isArrayBufferView(value)) {
|
2609 | transferable[key] = {
|
2610 | bytes: value.buffer,
|
2611 | byteOffset: value.byteOffset,
|
2612 | byteLength: value.byteLength
|
2613 | };
|
2614 | } else {
|
2615 | transferable[key] = value;
|
2616 | }
|
2617 | });
|
2618 | return transferable;
|
2619 | };
|
2620 |
|
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 |
|
2630 | var initSegmentId = function initSegmentId(initSegment) {
|
2631 | var byterange = initSegment.byterange || {
|
2632 | length: Infinity,
|
2633 | offset: 0
|
2634 | };
|
2635 | return [byterange.length, byterange.offset, initSegment.resolvedUri].join(',');
|
2636 | };
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 | var segmentKeyId = function segmentKeyId(key) {
|
2645 | return key.resolvedUri;
|
2646 | };
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 | var hexDump = function hexDump(data) {
|
2657 | var bytes = Array.prototype.slice.call(data);
|
2658 | var step = 16;
|
2659 | var result = '';
|
2660 | var hex;
|
2661 | var ascii;
|
2662 |
|
2663 | for (var j = 0; j < bytes.length / step; j++) {
|
2664 | hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
|
2665 | ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
|
2666 | result += hex + ' ' + ascii + '\n';
|
2667 | }
|
2668 |
|
2669 | return result;
|
2670 | };
|
2671 | var tagDump = function tagDump(_ref) {
|
2672 | var bytes = _ref.bytes;
|
2673 | return hexDump(bytes);
|
2674 | };
|
2675 | var textRanges = function textRanges(ranges) {
|
2676 | var result = '';
|
2677 | var i;
|
2678 |
|
2679 | for (i = 0; i < ranges.length; i++) {
|
2680 | result += textRange(ranges, i) + ' ';
|
2681 | }
|
2682 |
|
2683 | return result;
|
2684 | };
|
2685 |
|
2686 | var utils = Object.freeze({
|
2687 | __proto__: null,
|
2688 | createTransferableMessage: createTransferableMessage,
|
2689 | initSegmentId: initSegmentId,
|
2690 | segmentKeyId: segmentKeyId,
|
2691 | hexDump: hexDump,
|
2692 | tagDump: tagDump,
|
2693 | textRanges: textRanges
|
2694 | });
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 | var SEGMENT_END_FUDGE_PERCENT = 0.25;
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 | var playerTimeToProgramTime = function playerTimeToProgramTime(playerTime, segment) {
|
2717 | if (!segment.dateTimeObject) {
|
2718 |
|
2719 |
|
2720 | return null;
|
2721 | }
|
2722 |
|
2723 | var transmuxerPrependedSeconds = segment.videoTimingInfo.transmuxerPrependedSeconds;
|
2724 | var transmuxedStart = segment.videoTimingInfo.transmuxedPresentationStart;
|
2725 |
|
2726 | var startOfSegment = transmuxedStart + transmuxerPrependedSeconds;
|
2727 | var offsetFromSegmentStart = playerTime - startOfSegment;
|
2728 | return new Date(segment.dateTimeObject.getTime() + offsetFromSegmentStart * 1000);
|
2729 | };
|
2730 | var originalSegmentVideoDuration = function originalSegmentVideoDuration(videoTimingInfo) {
|
2731 | return videoTimingInfo.transmuxedPresentationEnd - videoTimingInfo.transmuxedPresentationStart - videoTimingInfo.transmuxerPrependedSeconds;
|
2732 | };
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 | var findSegmentForProgramTime = function findSegmentForProgramTime(programTime, playlist) {
|
2742 |
|
2743 |
|
2744 |
|
2745 | var dateTimeObject;
|
2746 |
|
2747 | try {
|
2748 | dateTimeObject = new Date(programTime);
|
2749 | } catch (e) {
|
2750 | return null;
|
2751 | }
|
2752 |
|
2753 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
2754 | return null;
|
2755 | }
|
2756 |
|
2757 | var segment = playlist.segments[0];
|
2758 |
|
2759 | if (dateTimeObject < segment.dateTimeObject) {
|
2760 |
|
2761 | return null;
|
2762 | }
|
2763 |
|
2764 | for (var i = 0; i < playlist.segments.length - 1; i++) {
|
2765 | segment = playlist.segments[i];
|
2766 | var nextSegmentStart = playlist.segments[i + 1].dateTimeObject;
|
2767 |
|
2768 | if (dateTimeObject < nextSegmentStart) {
|
2769 | break;
|
2770 | }
|
2771 | }
|
2772 |
|
2773 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
2774 | var lastSegmentStart = lastSegment.dateTimeObject;
|
2775 | var lastSegmentDuration = lastSegment.videoTimingInfo ? originalSegmentVideoDuration(lastSegment.videoTimingInfo) : lastSegment.duration + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT;
|
2776 | var lastSegmentEnd = new Date(lastSegmentStart.getTime() + lastSegmentDuration * 1000);
|
2777 |
|
2778 | if (dateTimeObject > lastSegmentEnd) {
|
2779 |
|
2780 | return null;
|
2781 | }
|
2782 |
|
2783 | if (dateTimeObject > lastSegmentStart) {
|
2784 | segment = lastSegment;
|
2785 | }
|
2786 |
|
2787 | return {
|
2788 | segment: segment,
|
2789 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : Playlist.duration(playlist, playlist.mediaSequence + playlist.segments.indexOf(segment)),
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
2795 | };
|
2796 | };
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 | var findSegmentForPlayerTime = function findSegmentForPlayerTime(time, playlist) {
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
2810 | return null;
|
2811 | }
|
2812 |
|
2813 | var segmentEnd = 0;
|
2814 | var segment;
|
2815 |
|
2816 | for (var i = 0; i < playlist.segments.length; i++) {
|
2817 | segment = playlist.segments[i];
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 | segmentEnd = segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationEnd : segmentEnd + segment.duration;
|
2825 |
|
2826 | if (time <= segmentEnd) {
|
2827 | break;
|
2828 | }
|
2829 | }
|
2830 |
|
2831 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
2832 |
|
2833 | if (lastSegment.videoTimingInfo && lastSegment.videoTimingInfo.transmuxedPresentationEnd < time) {
|
2834 |
|
2835 | return null;
|
2836 | }
|
2837 |
|
2838 | if (time > segmentEnd) {
|
2839 |
|
2840 |
|
2841 |
|
2842 | if (time > segmentEnd + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT) {
|
2843 |
|
2844 |
|
2845 |
|
2846 | return null;
|
2847 | }
|
2848 |
|
2849 | segment = lastSegment;
|
2850 | }
|
2851 |
|
2852 | return {
|
2853 | segment: segment,
|
2854 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : segmentEnd - segment.duration,
|
2855 |
|
2856 |
|
2857 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
2858 | };
|
2859 | };
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 | var getOffsetFromTimestamp = function getOffsetFromTimestamp(comparisonTimeStamp, programTime) {
|
2872 | var segmentDateTime;
|
2873 | var programDateTime;
|
2874 |
|
2875 | try {
|
2876 | segmentDateTime = new Date(comparisonTimeStamp);
|
2877 | programDateTime = new Date(programTime);
|
2878 | } catch (e) {
|
2879 | }
|
2880 |
|
2881 | var segmentTimeEpoch = segmentDateTime.getTime();
|
2882 | var programTimeEpoch = programDateTime.getTime();
|
2883 | return (programTimeEpoch - segmentTimeEpoch) / 1000;
|
2884 | };
|
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 |
|
2891 | var verifyProgramDateTimeTags = function verifyProgramDateTimeTags(playlist) {
|
2892 | if (!playlist.segments || playlist.segments.length === 0) {
|
2893 | return false;
|
2894 | }
|
2895 |
|
2896 | for (var i = 0; i < playlist.segments.length; i++) {
|
2897 | var segment = playlist.segments[i];
|
2898 |
|
2899 | if (!segment.dateTimeObject) {
|
2900 | return false;
|
2901 | }
|
2902 | }
|
2903 |
|
2904 | return true;
|
2905 | };
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 | var getProgramTime = function getProgramTime(_ref) {
|
2923 | var playlist = _ref.playlist,
|
2924 | _ref$time = _ref.time,
|
2925 | time = _ref$time === void 0 ? undefined : _ref$time,
|
2926 | callback = _ref.callback;
|
2927 |
|
2928 | if (!callback) {
|
2929 | throw new Error('getProgramTime: callback must be provided');
|
2930 | }
|
2931 |
|
2932 | if (!playlist || time === undefined) {
|
2933 | return callback({
|
2934 | message: 'getProgramTime: playlist and time must be provided'
|
2935 | });
|
2936 | }
|
2937 |
|
2938 | var matchedSegment = findSegmentForPlayerTime(time, playlist);
|
2939 |
|
2940 | if (!matchedSegment) {
|
2941 | return callback({
|
2942 | message: 'valid programTime was not found'
|
2943 | });
|
2944 | }
|
2945 |
|
2946 | if (matchedSegment.type === 'estimate') {
|
2947 | return callback({
|
2948 | message: 'Accurate programTime could not be determined.' + ' Please seek to e.seekTime and try again',
|
2949 | seekTime: matchedSegment.estimatedStart
|
2950 | });
|
2951 | }
|
2952 |
|
2953 | var programTimeObject = {
|
2954 | mediaSeconds: time
|
2955 | };
|
2956 | var programTime = playerTimeToProgramTime(time, matchedSegment.segment);
|
2957 |
|
2958 | if (programTime) {
|
2959 | programTimeObject.programDateTime = programTime.toISOString();
|
2960 | }
|
2961 |
|
2962 | return callback(null, programTimeObject);
|
2963 | };
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 | var seekToProgramTime = function seekToProgramTime(_ref2) {
|
2980 | var programTime = _ref2.programTime,
|
2981 | playlist = _ref2.playlist,
|
2982 | _ref2$retryCount = _ref2.retryCount,
|
2983 | retryCount = _ref2$retryCount === void 0 ? 2 : _ref2$retryCount,
|
2984 | seekTo = _ref2.seekTo,
|
2985 | _ref2$pauseAfterSeek = _ref2.pauseAfterSeek,
|
2986 | pauseAfterSeek = _ref2$pauseAfterSeek === void 0 ? true : _ref2$pauseAfterSeek,
|
2987 | tech = _ref2.tech,
|
2988 | callback = _ref2.callback;
|
2989 |
|
2990 | if (!callback) {
|
2991 | throw new Error('seekToProgramTime: callback must be provided');
|
2992 | }
|
2993 |
|
2994 | if (typeof programTime === 'undefined' || !playlist || !seekTo) {
|
2995 | return callback({
|
2996 | message: 'seekToProgramTime: programTime, seekTo and playlist must be provided'
|
2997 | });
|
2998 | }
|
2999 |
|
3000 | if (!playlist.endList && !tech.hasStarted_) {
|
3001 | return callback({
|
3002 | message: 'player must be playing a live stream to start buffering'
|
3003 | });
|
3004 | }
|
3005 |
|
3006 | if (!verifyProgramDateTimeTags(playlist)) {
|
3007 | return callback({
|
3008 | message: 'programDateTime tags must be provided in the manifest ' + playlist.resolvedUri
|
3009 | });
|
3010 | }
|
3011 |
|
3012 | var matchedSegment = findSegmentForProgramTime(programTime, playlist);
|
3013 |
|
3014 | if (!matchedSegment) {
|
3015 | return callback({
|
3016 | message: programTime + " was not found in the stream"
|
3017 | });
|
3018 | }
|
3019 |
|
3020 | var segment = matchedSegment.segment;
|
3021 | var mediaOffset = getOffsetFromTimestamp(segment.dateTimeObject, programTime);
|
3022 |
|
3023 | if (matchedSegment.type === 'estimate') {
|
3024 |
|
3025 | if (retryCount === 0) {
|
3026 | return callback({
|
3027 | message: programTime + " is not buffered yet. Try again"
|
3028 | });
|
3029 | }
|
3030 |
|
3031 | seekTo(matchedSegment.estimatedStart + mediaOffset);
|
3032 | tech.one('seeked', function () {
|
3033 | seekToProgramTime({
|
3034 | programTime: programTime,
|
3035 | playlist: playlist,
|
3036 | retryCount: retryCount - 1,
|
3037 | seekTo: seekTo,
|
3038 | pauseAfterSeek: pauseAfterSeek,
|
3039 | tech: tech,
|
3040 | callback: callback
|
3041 | });
|
3042 | });
|
3043 | return;
|
3044 | }
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 | var seekToTime = segment.start + mediaOffset;
|
3050 |
|
3051 | var seekedCallback = function seekedCallback() {
|
3052 | return callback(null, tech.currentTime());
|
3053 | };
|
3054 |
|
3055 |
|
3056 | tech.one('seeked', seekedCallback);
|
3057 |
|
3058 | if (pauseAfterSeek) {
|
3059 | tech.pause();
|
3060 | }
|
3061 |
|
3062 | seekTo(seekToTime);
|
3063 | };
|
3064 |
|
3065 |
|
3066 |
|
3067 | var callbackOnCompleted = function callbackOnCompleted(request, cb) {
|
3068 | if (request.readyState === 4) {
|
3069 | return cb();
|
3070 | }
|
3071 |
|
3072 | return;
|
3073 | };
|
3074 |
|
3075 | var containerRequest = function containerRequest(uri, xhr, cb) {
|
3076 | var bytes = [];
|
3077 | var id3Offset;
|
3078 | var finished = false;
|
3079 |
|
3080 | var endRequestAndCallback = function endRequestAndCallback(err, req, type, _bytes) {
|
3081 | req.abort();
|
3082 | finished = true;
|
3083 | return cb(err, req, type, _bytes);
|
3084 | };
|
3085 |
|
3086 | var progressListener = function progressListener(error, request) {
|
3087 | if (finished) {
|
3088 | return;
|
3089 | }
|
3090 |
|
3091 | if (error) {
|
3092 | return endRequestAndCallback(error, request, '', bytes);
|
3093 | }
|
3094 |
|
3095 |
|
3096 | var newPart = request.responseText.substring(bytes && bytes.byteLength || 0, request.responseText.length);
|
3097 |
|
3098 | bytes = byteHelpers.concatTypedArrays(bytes, byteHelpers.stringToBytes(newPart, true));
|
3099 | id3Offset = id3Offset || id3Helpers.getId3Offset(bytes);
|
3100 |
|
3101 |
|
3102 | if (bytes.length < 10 || id3Offset && bytes.length < id3Offset + 2) {
|
3103 | return callbackOnCompleted(request, function () {
|
3104 | return endRequestAndCallback(error, request, '', bytes);
|
3105 | });
|
3106 | }
|
3107 |
|
3108 | var type = containers.detectContainerForBytes(bytes);
|
3109 |
|
3110 |
|
3111 |
|
3112 | if (type === 'ts' && bytes.length < 188) {
|
3113 | return callbackOnCompleted(request, function () {
|
3114 | return endRequestAndCallback(error, request, '', bytes);
|
3115 | });
|
3116 | }
|
3117 |
|
3118 |
|
3119 |
|
3120 | if (!type && bytes.length < 376) {
|
3121 | return callbackOnCompleted(request, function () {
|
3122 | return endRequestAndCallback(error, request, '', bytes);
|
3123 | });
|
3124 | }
|
3125 |
|
3126 | return endRequestAndCallback(null, request, type, bytes);
|
3127 | };
|
3128 |
|
3129 | var options = {
|
3130 | uri: uri,
|
3131 | beforeSend: function beforeSend(request) {
|
3132 |
|
3133 | request.overrideMimeType('text/plain; charset=x-user-defined');
|
3134 | request.addEventListener('progress', function (_ref) {
|
3135 | _ref.total;
|
3136 | _ref.loaded;
|
3137 | return callbackWrapper(request, null, {
|
3138 | statusCode: request.status
|
3139 | }, progressListener);
|
3140 | });
|
3141 | }
|
3142 | };
|
3143 | var request = xhr(options, function (error, response) {
|
3144 | return callbackWrapper(request, error, response, progressListener);
|
3145 | });
|
3146 | return request;
|
3147 | };
|
3148 |
|
3149 | var EventTarget = videojs__default["default"].EventTarget,
|
3150 | mergeOptions = videojs__default["default"].mergeOptions;
|
3151 |
|
3152 | var dashPlaylistUnchanged = function dashPlaylistUnchanged(a, b) {
|
3153 | if (!isPlaylistUnchanged(a, b)) {
|
3154 | return false;
|
3155 | }
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 | if (a.sidx && b.sidx && (a.sidx.offset !== b.sidx.offset || a.sidx.length !== b.sidx.length)) {
|
3164 | return false;
|
3165 | } else if (!a.sidx && b.sidx || a.sidx && !b.sidx) {
|
3166 | return false;
|
3167 | }
|
3168 |
|
3169 |
|
3170 |
|
3171 | if (a.segments && !b.segments || !a.segments && b.segments) {
|
3172 | return false;
|
3173 | }
|
3174 |
|
3175 |
|
3176 | if (!a.segments && !b.segments) {
|
3177 | return true;
|
3178 | }
|
3179 |
|
3180 |
|
3181 | for (var i = 0; i < a.segments.length; i++) {
|
3182 | var aSegment = a.segments[i];
|
3183 | var bSegment = b.segments[i];
|
3184 |
|
3185 | if (aSegment.uri !== bSegment.uri) {
|
3186 | return false;
|
3187 | }
|
3188 |
|
3189 |
|
3190 | if (!aSegment.byterange && !bSegment.byterange) {
|
3191 | continue;
|
3192 | }
|
3193 |
|
3194 | var aByterange = aSegment.byterange;
|
3195 | var bByterange = bSegment.byterange;
|
3196 |
|
3197 | if (aByterange && !bByterange || !aByterange && bByterange) {
|
3198 | return false;
|
3199 | }
|
3200 |
|
3201 |
|
3202 | if (aByterange.offset !== bByterange.offset || aByterange.length !== bByterange.length) {
|
3203 | return false;
|
3204 | }
|
3205 | }
|
3206 |
|
3207 |
|
3208 | return true;
|
3209 | };
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 | var parseMasterXml = function parseMasterXml(_ref) {
|
3229 | var masterXml = _ref.masterXml,
|
3230 | srcUrl = _ref.srcUrl,
|
3231 | clientOffset = _ref.clientOffset,
|
3232 | sidxMapping = _ref.sidxMapping,
|
3233 | previousManifest = _ref.previousManifest;
|
3234 | var manifest = mpdParser.parse(masterXml, {
|
3235 | manifestUri: srcUrl,
|
3236 | clientOffset: clientOffset,
|
3237 | sidxMapping: sidxMapping,
|
3238 | previousManifest: previousManifest
|
3239 | });
|
3240 | addPropertiesToMaster(manifest, srcUrl);
|
3241 | return manifest;
|
3242 | };
|
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 | var updateMaster = function updateMaster(oldMaster, newMaster, sidxMapping) {
|
3257 | var noChanges = true;
|
3258 | var update = mergeOptions(oldMaster, {
|
3259 |
|
3260 | duration: newMaster.duration,
|
3261 | minimumUpdatePeriod: newMaster.minimumUpdatePeriod,
|
3262 | timelineStarts: newMaster.timelineStarts
|
3263 | });
|
3264 |
|
3265 | for (var i = 0; i < newMaster.playlists.length; i++) {
|
3266 | var playlist = newMaster.playlists[i];
|
3267 |
|
3268 | if (playlist.sidx) {
|
3269 | var sidxKey = mpdParser.generateSidxKey(playlist.sidx);
|
3270 |
|
3271 | if (sidxMapping && sidxMapping[sidxKey] && sidxMapping[sidxKey].sidx) {
|
3272 | mpdParser.addSidxSegmentsToPlaylist(playlist, sidxMapping[sidxKey].sidx, playlist.sidx.resolvedUri);
|
3273 | }
|
3274 | }
|
3275 |
|
3276 | var playlistUpdate = updateMaster$1(update, playlist, dashPlaylistUnchanged);
|
3277 |
|
3278 | if (playlistUpdate) {
|
3279 | update = playlistUpdate;
|
3280 | noChanges = false;
|
3281 | }
|
3282 | }
|
3283 |
|
3284 |
|
3285 | forEachMediaGroup(newMaster, function (properties, type, group, label) {
|
3286 | if (properties.playlists && properties.playlists.length) {
|
3287 | var id = properties.playlists[0].id;
|
3288 |
|
3289 | var _playlistUpdate = updateMaster$1(update, properties.playlists[0], dashPlaylistUnchanged);
|
3290 |
|
3291 | if (_playlistUpdate) {
|
3292 | update = _playlistUpdate;
|
3293 |
|
3294 | update.mediaGroups[type][group][label].playlists[0] = update.playlists[id];
|
3295 | noChanges = false;
|
3296 | }
|
3297 | }
|
3298 | });
|
3299 |
|
3300 | if (newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
3301 | noChanges = false;
|
3302 | }
|
3303 |
|
3304 | if (noChanges) {
|
3305 | return null;
|
3306 | }
|
3307 |
|
3308 | return update;
|
3309 | };
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 | var equivalentSidx = function equivalentSidx(a, b) {
|
3315 | var neitherMap = Boolean(!a.map && !b.map);
|
3316 | var equivalentMap = neitherMap || Boolean(a.map && b.map && a.map.byterange.offset === b.map.byterange.offset && a.map.byterange.length === b.map.byterange.length);
|
3317 | return equivalentMap && a.uri === b.uri && a.byterange.offset === b.byterange.offset && a.byterange.length === b.byterange.length;
|
3318 | };
|
3319 |
|
3320 |
|
3321 | var compareSidxEntry = function compareSidxEntry(playlists, oldSidxMapping) {
|
3322 | var newSidxMapping = {};
|
3323 |
|
3324 | for (var id in playlists) {
|
3325 | var playlist = playlists[id];
|
3326 | var currentSidxInfo = playlist.sidx;
|
3327 |
|
3328 | if (currentSidxInfo) {
|
3329 | var key = mpdParser.generateSidxKey(currentSidxInfo);
|
3330 |
|
3331 | if (!oldSidxMapping[key]) {
|
3332 | break;
|
3333 | }
|
3334 |
|
3335 | var savedSidxInfo = oldSidxMapping[key].sidxInfo;
|
3336 |
|
3337 | if (equivalentSidx(savedSidxInfo, currentSidxInfo)) {
|
3338 | newSidxMapping[key] = oldSidxMapping[key];
|
3339 | }
|
3340 | }
|
3341 | }
|
3342 |
|
3343 | return newSidxMapping;
|
3344 | };
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 | var filterChangedSidxMappings = function filterChangedSidxMappings(master, oldSidxMapping) {
|
3355 | var videoSidx = compareSidxEntry(master.playlists, oldSidxMapping);
|
3356 | var mediaGroupSidx = videoSidx;
|
3357 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
3358 | if (properties.playlists && properties.playlists.length) {
|
3359 | var playlists = properties.playlists;
|
3360 | mediaGroupSidx = mergeOptions(mediaGroupSidx, compareSidxEntry(playlists, oldSidxMapping));
|
3361 | }
|
3362 | });
|
3363 | return mediaGroupSidx;
|
3364 | };
|
3365 |
|
3366 | var DashPlaylistLoader = function (_EventTarget) {
|
3367 | _inheritsLoose__default["default"](DashPlaylistLoader, _EventTarget);
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 | function DashPlaylistLoader(srcUrlOrPlaylist, vhs, options, masterPlaylistLoader) {
|
3373 | var _this;
|
3374 |
|
3375 | if (options === void 0) {
|
3376 | options = {};
|
3377 | }
|
3378 |
|
3379 | _this = _EventTarget.call(this) || this;
|
3380 | _this.masterPlaylistLoader_ = masterPlaylistLoader || _assertThisInitialized__default["default"](_this);
|
3381 |
|
3382 | if (!masterPlaylistLoader) {
|
3383 | _this.isMaster_ = true;
|
3384 | }
|
3385 |
|
3386 | var _options = options,
|
3387 | _options$withCredenti = _options.withCredentials,
|
3388 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
3389 | _options$handleManife = _options.handleManifestRedirects,
|
3390 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
3391 | _this.vhs_ = vhs;
|
3392 | _this.withCredentials = withCredentials;
|
3393 | _this.handleManifestRedirects = handleManifestRedirects;
|
3394 |
|
3395 | if (!srcUrlOrPlaylist) {
|
3396 | throw new Error('A non-empty playlist URL or object is required');
|
3397 | }
|
3398 |
|
3399 |
|
3400 | _this.on('minimumUpdatePeriod', function () {
|
3401 | _this.refreshXml_();
|
3402 | });
|
3403 |
|
3404 |
|
3405 | _this.on('mediaupdatetimeout', function () {
|
3406 | _this.refreshMedia_(_this.media().id);
|
3407 | });
|
3408 |
|
3409 | _this.state = 'HAVE_NOTHING';
|
3410 | _this.loadedPlaylists_ = {};
|
3411 | _this.logger_ = logger('DashPlaylistLoader');
|
3412 |
|
3413 |
|
3414 | if (_this.isMaster_) {
|
3415 | _this.masterPlaylistLoader_.srcUrl = srcUrlOrPlaylist;
|
3416 |
|
3417 |
|
3418 | _this.masterPlaylistLoader_.sidxMapping_ = {};
|
3419 | } else {
|
3420 | _this.childPlaylist_ = srcUrlOrPlaylist;
|
3421 | }
|
3422 |
|
3423 | return _this;
|
3424 | }
|
3425 |
|
3426 | var _proto = DashPlaylistLoader.prototype;
|
3427 |
|
3428 | _proto.requestErrored_ = function requestErrored_(err, request, startingState) {
|
3429 |
|
3430 | if (!this.request) {
|
3431 | return true;
|
3432 | }
|
3433 |
|
3434 |
|
3435 | this.request = null;
|
3436 |
|
3437 | if (err) {
|
3438 |
|
3439 |
|
3440 | this.error = typeof err === 'object' && !(err instanceof Error) ? err : {
|
3441 | status: request.status,
|
3442 | message: 'DASH request error at URL: ' + request.uri,
|
3443 | response: request.response,
|
3444 |
|
3445 | code: 2
|
3446 | };
|
3447 |
|
3448 | if (startingState) {
|
3449 | this.state = startingState;
|
3450 | }
|
3451 |
|
3452 | this.trigger('error');
|
3453 | return true;
|
3454 | }
|
3455 | }
|
3456 | |
3457 |
|
3458 |
|
3459 |
|
3460 | ;
|
3461 |
|
3462 | _proto.addSidxSegments_ = function addSidxSegments_(playlist, startingState, cb) {
|
3463 | var _this2 = this;
|
3464 |
|
3465 | var sidxKey = playlist.sidx && mpdParser.generateSidxKey(playlist.sidx);
|
3466 |
|
3467 | if (!playlist.sidx || !sidxKey || this.masterPlaylistLoader_.sidxMapping_[sidxKey]) {
|
3468 |
|
3469 | this.mediaRequest_ = window__default["default"].setTimeout(function () {
|
3470 | return cb(false);
|
3471 | }, 0);
|
3472 | return;
|
3473 | }
|
3474 |
|
3475 |
|
3476 | var uri = resolveManifestRedirect(this.handleManifestRedirects, playlist.sidx.resolvedUri);
|
3477 |
|
3478 | var fin = function fin(err, request) {
|
3479 | if (_this2.requestErrored_(err, request, startingState)) {
|
3480 | return;
|
3481 | }
|
3482 |
|
3483 | var sidxMapping = _this2.masterPlaylistLoader_.sidxMapping_;
|
3484 | var sidx;
|
3485 |
|
3486 | try {
|
3487 | sidx = parseSidx__default["default"](byteHelpers.toUint8(request.response).subarray(8));
|
3488 | } catch (e) {
|
3489 |
|
3490 | _this2.requestErrored_(e, request, startingState);
|
3491 |
|
3492 | return;
|
3493 | }
|
3494 |
|
3495 | sidxMapping[sidxKey] = {
|
3496 | sidxInfo: playlist.sidx,
|
3497 | sidx: sidx
|
3498 | };
|
3499 | mpdParser.addSidxSegmentsToPlaylist(playlist, sidx, playlist.sidx.resolvedUri);
|
3500 | return cb(true);
|
3501 | };
|
3502 |
|
3503 | this.request = containerRequest(uri, this.vhs_.xhr, function (err, request, container, bytes) {
|
3504 | if (err) {
|
3505 | return fin(err, request);
|
3506 | }
|
3507 |
|
3508 | if (!container || container !== 'mp4') {
|
3509 | return fin({
|
3510 | status: request.status,
|
3511 | message: "Unsupported " + (container || 'unknown') + " container type for sidx segment at URL: " + uri,
|
3512 |
|
3513 |
|
3514 | response: '',
|
3515 | playlist: playlist,
|
3516 | internal: true,
|
3517 | blacklistDuration: Infinity,
|
3518 |
|
3519 | code: 2
|
3520 | }, request);
|
3521 | }
|
3522 |
|
3523 |
|
3524 | var _playlist$sidx$bytera = playlist.sidx.byterange,
|
3525 | offset = _playlist$sidx$bytera.offset,
|
3526 | length = _playlist$sidx$bytera.length;
|
3527 |
|
3528 | if (bytes.length >= length + offset) {
|
3529 | return fin(err, {
|
3530 | response: bytes.subarray(offset, offset + length),
|
3531 | status: request.status,
|
3532 | uri: request.uri
|
3533 | });
|
3534 | }
|
3535 |
|
3536 |
|
3537 | _this2.request = _this2.vhs_.xhr({
|
3538 | uri: uri,
|
3539 | responseType: 'arraybuffer',
|
3540 | headers: segmentXhrHeaders({
|
3541 | byterange: playlist.sidx.byterange
|
3542 | })
|
3543 | }, fin);
|
3544 | });
|
3545 | };
|
3546 |
|
3547 | _proto.dispose = function dispose() {
|
3548 | this.trigger('dispose');
|
3549 | this.stopRequest();
|
3550 | this.loadedPlaylists_ = {};
|
3551 | window__default["default"].clearTimeout(this.minimumUpdatePeriodTimeout_);
|
3552 | window__default["default"].clearTimeout(this.mediaRequest_);
|
3553 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
3554 | this.mediaUpdateTimeout = null;
|
3555 | this.mediaRequest_ = null;
|
3556 | this.minimumUpdatePeriodTimeout_ = null;
|
3557 |
|
3558 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
3559 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
3560 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
3561 | }
|
3562 |
|
3563 | this.off();
|
3564 | };
|
3565 |
|
3566 | _proto.hasPendingRequest = function hasPendingRequest() {
|
3567 | return this.request || this.mediaRequest_;
|
3568 | };
|
3569 |
|
3570 | _proto.stopRequest = function stopRequest() {
|
3571 | if (this.request) {
|
3572 | var oldRequest = this.request;
|
3573 | this.request = null;
|
3574 | oldRequest.onreadystatechange = null;
|
3575 | oldRequest.abort();
|
3576 | }
|
3577 | };
|
3578 |
|
3579 | _proto.media = function media(playlist) {
|
3580 | var _this3 = this;
|
3581 |
|
3582 |
|
3583 | if (!playlist) {
|
3584 | return this.media_;
|
3585 | }
|
3586 |
|
3587 |
|
3588 | if (this.state === 'HAVE_NOTHING') {
|
3589 | throw new Error('Cannot switch media playlist from ' + this.state);
|
3590 | }
|
3591 |
|
3592 | var startingState = this.state;
|
3593 |
|
3594 | if (typeof playlist === 'string') {
|
3595 | if (!this.masterPlaylistLoader_.master.playlists[playlist]) {
|
3596 | throw new Error('Unknown playlist URI: ' + playlist);
|
3597 | }
|
3598 |
|
3599 | playlist = this.masterPlaylistLoader_.master.playlists[playlist];
|
3600 | }
|
3601 |
|
3602 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
3603 |
|
3604 | if (mediaChange && this.loadedPlaylists_[playlist.id] && this.loadedPlaylists_[playlist.id].endList) {
|
3605 | this.state = 'HAVE_METADATA';
|
3606 | this.media_ = playlist;
|
3607 |
|
3608 | if (mediaChange) {
|
3609 | this.trigger('mediachanging');
|
3610 | this.trigger('mediachange');
|
3611 | }
|
3612 |
|
3613 | return;
|
3614 | }
|
3615 |
|
3616 |
|
3617 | if (!mediaChange) {
|
3618 | return;
|
3619 | }
|
3620 |
|
3621 |
|
3622 | if (this.media_) {
|
3623 | this.trigger('mediachanging');
|
3624 | }
|
3625 |
|
3626 | this.addSidxSegments_(playlist, startingState, function (sidxChanged) {
|
3627 |
|
3628 | _this3.haveMetadata({
|
3629 | startingState: startingState,
|
3630 | playlist: playlist
|
3631 | });
|
3632 | });
|
3633 | };
|
3634 |
|
3635 | _proto.haveMetadata = function haveMetadata(_ref2) {
|
3636 | var startingState = _ref2.startingState,
|
3637 | playlist = _ref2.playlist;
|
3638 | this.state = 'HAVE_METADATA';
|
3639 | this.loadedPlaylists_[playlist.id] = playlist;
|
3640 | this.mediaRequest_ = null;
|
3641 |
|
3642 | this.refreshMedia_(playlist.id);
|
3643 |
|
3644 |
|
3645 | if (startingState === 'HAVE_MASTER') {
|
3646 | this.trigger('loadedmetadata');
|
3647 | } else {
|
3648 |
|
3649 | this.trigger('mediachange');
|
3650 | }
|
3651 | };
|
3652 |
|
3653 | _proto.pause = function pause() {
|
3654 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
3655 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
3656 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
3657 | }
|
3658 |
|
3659 | this.stopRequest();
|
3660 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
3661 | this.mediaUpdateTimeout = null;
|
3662 |
|
3663 | if (this.isMaster_) {
|
3664 | window__default["default"].clearTimeout(this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_);
|
3665 | this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_ = null;
|
3666 | }
|
3667 |
|
3668 | if (this.state === 'HAVE_NOTHING') {
|
3669 |
|
3670 |
|
3671 | this.started = false;
|
3672 | }
|
3673 | };
|
3674 |
|
3675 | _proto.load = function load(isFinalRendition) {
|
3676 | var _this4 = this;
|
3677 |
|
3678 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
3679 | this.mediaUpdateTimeout = null;
|
3680 | var media = this.media();
|
3681 |
|
3682 | if (isFinalRendition) {
|
3683 | var delay = media ? media.targetDuration / 2 * 1000 : 5 * 1000;
|
3684 | this.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
3685 | return _this4.load();
|
3686 | }, delay);
|
3687 | return;
|
3688 | }
|
3689 |
|
3690 |
|
3691 |
|
3692 | if (!this.started) {
|
3693 | this.start();
|
3694 | return;
|
3695 | }
|
3696 |
|
3697 | if (media && !media.endList) {
|
3698 |
|
3699 |
|
3700 |
|
3701 | if (this.isMaster_ && !this.minimumUpdatePeriodTimeout_) {
|
3702 |
|
3703 | this.trigger('minimumUpdatePeriod');
|
3704 |
|
3705 | this.updateMinimumUpdatePeriodTimeout_();
|
3706 | }
|
3707 |
|
3708 | this.trigger('mediaupdatetimeout');
|
3709 | } else {
|
3710 | this.trigger('loadedplaylist');
|
3711 | }
|
3712 | };
|
3713 |
|
3714 | _proto.start = function start() {
|
3715 | var _this5 = this;
|
3716 |
|
3717 | this.started = true;
|
3718 |
|
3719 |
|
3720 | if (!this.isMaster_) {
|
3721 | this.mediaRequest_ = window__default["default"].setTimeout(function () {
|
3722 | return _this5.haveMaster_();
|
3723 | }, 0);
|
3724 | return;
|
3725 | }
|
3726 |
|
3727 | this.requestMaster_(function (req, masterChanged) {
|
3728 | _this5.haveMaster_();
|
3729 |
|
3730 | if (!_this5.hasPendingRequest() && !_this5.media_) {
|
3731 | _this5.media(_this5.masterPlaylistLoader_.master.playlists[0]);
|
3732 | }
|
3733 | });
|
3734 | };
|
3735 |
|
3736 | _proto.requestMaster_ = function requestMaster_(cb) {
|
3737 | var _this6 = this;
|
3738 |
|
3739 | this.request = this.vhs_.xhr({
|
3740 | uri: this.masterPlaylistLoader_.srcUrl,
|
3741 | withCredentials: this.withCredentials
|
3742 | }, function (error, req) {
|
3743 | if (_this6.requestErrored_(error, req)) {
|
3744 | if (_this6.state === 'HAVE_NOTHING') {
|
3745 | _this6.started = false;
|
3746 | }
|
3747 |
|
3748 | return;
|
3749 | }
|
3750 |
|
3751 | var masterChanged = req.responseText !== _this6.masterPlaylistLoader_.masterXml_;
|
3752 | _this6.masterPlaylistLoader_.masterXml_ = req.responseText;
|
3753 |
|
3754 | if (req.responseHeaders && req.responseHeaders.date) {
|
3755 | _this6.masterLoaded_ = Date.parse(req.responseHeaders.date);
|
3756 | } else {
|
3757 | _this6.masterLoaded_ = Date.now();
|
3758 | }
|
3759 |
|
3760 | _this6.masterPlaylistLoader_.srcUrl = resolveManifestRedirect(_this6.handleManifestRedirects, _this6.masterPlaylistLoader_.srcUrl, req);
|
3761 |
|
3762 | if (masterChanged) {
|
3763 | _this6.handleMaster_();
|
3764 |
|
3765 | _this6.syncClientServerClock_(function () {
|
3766 | return cb(req, masterChanged);
|
3767 | });
|
3768 |
|
3769 | return;
|
3770 | }
|
3771 |
|
3772 | return cb(req, masterChanged);
|
3773 | });
|
3774 | }
|
3775 | |
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 | ;
|
3783 |
|
3784 | _proto.syncClientServerClock_ = function syncClientServerClock_(done) {
|
3785 | var _this7 = this;
|
3786 |
|
3787 | var utcTiming = mpdParser.parseUTCTiming(this.masterPlaylistLoader_.masterXml_);
|
3788 |
|
3789 |
|
3790 | if (utcTiming === null) {
|
3791 | this.masterPlaylistLoader_.clientOffset_ = this.masterLoaded_ - Date.now();
|
3792 | return done();
|
3793 | }
|
3794 |
|
3795 | if (utcTiming.method === 'DIRECT') {
|
3796 | this.masterPlaylistLoader_.clientOffset_ = utcTiming.value - Date.now();
|
3797 | return done();
|
3798 | }
|
3799 |
|
3800 | this.request = this.vhs_.xhr({
|
3801 | uri: resolveUrl(this.masterPlaylistLoader_.srcUrl, utcTiming.value),
|
3802 | method: utcTiming.method,
|
3803 | withCredentials: this.withCredentials
|
3804 | }, function (error, req) {
|
3805 |
|
3806 | if (!_this7.request) {
|
3807 | return;
|
3808 | }
|
3809 |
|
3810 | if (error) {
|
3811 |
|
3812 |
|
3813 | _this7.masterPlaylistLoader_.clientOffset_ = _this7.masterLoaded_ - Date.now();
|
3814 | return done();
|
3815 | }
|
3816 |
|
3817 | var serverTime;
|
3818 |
|
3819 | if (utcTiming.method === 'HEAD') {
|
3820 | if (!req.responseHeaders || !req.responseHeaders.date) {
|
3821 |
|
3822 |
|
3823 | serverTime = _this7.masterLoaded_;
|
3824 | } else {
|
3825 | serverTime = Date.parse(req.responseHeaders.date);
|
3826 | }
|
3827 | } else {
|
3828 | serverTime = Date.parse(req.responseText);
|
3829 | }
|
3830 |
|
3831 | _this7.masterPlaylistLoader_.clientOffset_ = serverTime - Date.now();
|
3832 | done();
|
3833 | });
|
3834 | };
|
3835 |
|
3836 | _proto.haveMaster_ = function haveMaster_() {
|
3837 | this.state = 'HAVE_MASTER';
|
3838 |
|
3839 | if (this.isMaster_) {
|
3840 |
|
3841 |
|
3842 |
|
3843 | this.trigger('loadedplaylist');
|
3844 | } else if (!this.media_) {
|
3845 |
|
3846 |
|
3847 | this.media(this.childPlaylist_);
|
3848 | }
|
3849 | };
|
3850 |
|
3851 | _proto.handleMaster_ = function handleMaster_() {
|
3852 |
|
3853 | this.mediaRequest_ = null;
|
3854 | var oldMaster = this.masterPlaylistLoader_.master;
|
3855 | var newMaster = parseMasterXml({
|
3856 | masterXml: this.masterPlaylistLoader_.masterXml_,
|
3857 | srcUrl: this.masterPlaylistLoader_.srcUrl,
|
3858 | clientOffset: this.masterPlaylistLoader_.clientOffset_,
|
3859 | sidxMapping: this.masterPlaylistLoader_.sidxMapping_,
|
3860 | previousManifest: oldMaster
|
3861 | });
|
3862 |
|
3863 | if (oldMaster) {
|
3864 | newMaster = updateMaster(oldMaster, newMaster, this.masterPlaylistLoader_.sidxMapping_);
|
3865 | }
|
3866 |
|
3867 |
|
3868 | this.masterPlaylistLoader_.master = newMaster ? newMaster : oldMaster;
|
3869 | var location = this.masterPlaylistLoader_.master.locations && this.masterPlaylistLoader_.master.locations[0];
|
3870 |
|
3871 | if (location && location !== this.masterPlaylistLoader_.srcUrl) {
|
3872 | this.masterPlaylistLoader_.srcUrl = location;
|
3873 | }
|
3874 |
|
3875 | if (!oldMaster || newMaster && newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
3876 | this.updateMinimumUpdatePeriodTimeout_();
|
3877 | }
|
3878 |
|
3879 | return Boolean(newMaster);
|
3880 | };
|
3881 |
|
3882 | _proto.updateMinimumUpdatePeriodTimeout_ = function updateMinimumUpdatePeriodTimeout_() {
|
3883 | var mpl = this.masterPlaylistLoader_;
|
3884 |
|
3885 |
|
3886 | if (mpl.createMupOnMedia_) {
|
3887 | mpl.off('loadedmetadata', mpl.createMupOnMedia_);
|
3888 | mpl.createMupOnMedia_ = null;
|
3889 | }
|
3890 |
|
3891 |
|
3892 | if (mpl.minimumUpdatePeriodTimeout_) {
|
3893 | window__default["default"].clearTimeout(mpl.minimumUpdatePeriodTimeout_);
|
3894 | mpl.minimumUpdatePeriodTimeout_ = null;
|
3895 | }
|
3896 |
|
3897 | var mup = mpl.master && mpl.master.minimumUpdatePeriod;
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 | if (mup === 0) {
|
3903 | if (mpl.media()) {
|
3904 | mup = mpl.media().targetDuration * 1000;
|
3905 | } else {
|
3906 | mpl.createMupOnMedia_ = mpl.updateMinimumUpdatePeriodTimeout_;
|
3907 | mpl.one('loadedmetadata', mpl.createMupOnMedia_);
|
3908 | }
|
3909 | }
|
3910 |
|
3911 |
|
3912 |
|
3913 |
|
3914 | if (typeof mup !== 'number' || mup <= 0) {
|
3915 | if (mup < 0) {
|
3916 | this.logger_("found invalid minimumUpdatePeriod of " + mup + ", not setting a timeout");
|
3917 | }
|
3918 |
|
3919 | return;
|
3920 | }
|
3921 |
|
3922 | this.createMUPTimeout_(mup);
|
3923 | };
|
3924 |
|
3925 | _proto.createMUPTimeout_ = function createMUPTimeout_(mup) {
|
3926 | var mpl = this.masterPlaylistLoader_;
|
3927 | mpl.minimumUpdatePeriodTimeout_ = window__default["default"].setTimeout(function () {
|
3928 | mpl.minimumUpdatePeriodTimeout_ = null;
|
3929 | mpl.trigger('minimumUpdatePeriod');
|
3930 | mpl.createMUPTimeout_(mup);
|
3931 | }, mup);
|
3932 | }
|
3933 | |
3934 |
|
3935 |
|
3936 | ;
|
3937 |
|
3938 | _proto.refreshXml_ = function refreshXml_() {
|
3939 | var _this8 = this;
|
3940 |
|
3941 | this.requestMaster_(function (req, masterChanged) {
|
3942 | if (!masterChanged) {
|
3943 | return;
|
3944 | }
|
3945 |
|
3946 | if (_this8.media_) {
|
3947 | _this8.media_ = _this8.masterPlaylistLoader_.master.playlists[_this8.media_.id];
|
3948 | }
|
3949 |
|
3950 |
|
3951 | _this8.masterPlaylistLoader_.sidxMapping_ = filterChangedSidxMappings(_this8.masterPlaylistLoader_.master, _this8.masterPlaylistLoader_.sidxMapping_);
|
3952 |
|
3953 | _this8.addSidxSegments_(_this8.media(), _this8.state, function (sidxChanged) {
|
3954 |
|
3955 | _this8.refreshMedia_(_this8.media().id);
|
3956 | });
|
3957 | });
|
3958 | }
|
3959 | |
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 | ;
|
3965 |
|
3966 | _proto.refreshMedia_ = function refreshMedia_(mediaID) {
|
3967 | var _this9 = this;
|
3968 |
|
3969 | if (!mediaID) {
|
3970 | throw new Error('refreshMedia_ must take a media id');
|
3971 | }
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 | if (this.media_ && this.isMaster_) {
|
3979 | this.handleMaster_();
|
3980 | }
|
3981 |
|
3982 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
3983 | var mediaChanged = !this.media_ || this.media_ !== playlists[mediaID];
|
3984 |
|
3985 | if (mediaChanged) {
|
3986 | this.media_ = playlists[mediaID];
|
3987 | } else {
|
3988 | this.trigger('playlistunchanged');
|
3989 | }
|
3990 |
|
3991 | if (!this.mediaUpdateTimeout) {
|
3992 | var createMediaUpdateTimeout = function createMediaUpdateTimeout() {
|
3993 | if (_this9.media().endList) {
|
3994 | return;
|
3995 | }
|
3996 |
|
3997 | _this9.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
3998 | _this9.trigger('mediaupdatetimeout');
|
3999 |
|
4000 | createMediaUpdateTimeout();
|
4001 | }, refreshDelay(_this9.media(), Boolean(mediaChanged)));
|
4002 | };
|
4003 |
|
4004 | createMediaUpdateTimeout();
|
4005 | }
|
4006 |
|
4007 | this.trigger('loadedplaylist');
|
4008 | };
|
4009 |
|
4010 | return DashPlaylistLoader;
|
4011 | }(EventTarget);
|
4012 |
|
4013 | var Config = {
|
4014 | GOAL_BUFFER_LENGTH: 30,
|
4015 | MAX_GOAL_BUFFER_LENGTH: 60,
|
4016 | BACK_BUFFER_LENGTH: 30,
|
4017 | GOAL_BUFFER_LENGTH_RATE: 1,
|
4018 |
|
4019 | INITIAL_BANDWIDTH: 4194304,
|
4020 |
|
4021 |
|
4022 | BANDWIDTH_VARIANCE: 1.2,
|
4023 |
|
4024 | BUFFER_LOW_WATER_LINE: 0,
|
4025 | MAX_BUFFER_LOW_WATER_LINE: 30,
|
4026 |
|
4027 | EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE: 16,
|
4028 | BUFFER_LOW_WATER_LINE_RATE: 1,
|
4029 |
|
4030 | BUFFER_HIGH_WATER_LINE: 30
|
4031 | };
|
4032 |
|
4033 | var stringToArrayBuffer = function stringToArrayBuffer(string) {
|
4034 | var view = new Uint8Array(new ArrayBuffer(string.length));
|
4035 |
|
4036 | for (var i = 0; i < string.length; i++) {
|
4037 | view[i] = string.charCodeAt(i);
|
4038 | }
|
4039 |
|
4040 | return view.buffer;
|
4041 | };
|
4042 |
|
4043 |
|
4044 |
|
4045 | var browserWorkerPolyFill = function browserWorkerPolyFill(workerObj) {
|
4046 |
|
4047 | workerObj.on = workerObj.addEventListener;
|
4048 | workerObj.off = workerObj.removeEventListener;
|
4049 | return workerObj;
|
4050 | };
|
4051 |
|
4052 | var createObjectURL = function createObjectURL(str) {
|
4053 | try {
|
4054 | return URL.createObjectURL(new Blob([str], {
|
4055 | type: 'application/javascript'
|
4056 | }));
|
4057 | } catch (e) {
|
4058 | var blob = new BlobBuilder();
|
4059 | blob.append(str);
|
4060 | return URL.createObjectURL(blob.getBlob());
|
4061 | }
|
4062 | };
|
4063 |
|
4064 | var factory = function factory(code) {
|
4065 | return function () {
|
4066 | var objectUrl = createObjectURL(code);
|
4067 | var worker = browserWorkerPolyFill(new Worker(objectUrl));
|
4068 | worker.objURL = objectUrl;
|
4069 | var terminate = worker.terminate;
|
4070 | worker.on = worker.addEventListener;
|
4071 | worker.off = worker.removeEventListener;
|
4072 |
|
4073 | worker.terminate = function () {
|
4074 | URL.revokeObjectURL(objectUrl);
|
4075 | return terminate.call(this);
|
4076 | };
|
4077 |
|
4078 | return worker;
|
4079 | };
|
4080 | };
|
4081 | var transform = function transform(code) {
|
4082 | return "var browserWorkerPolyFill = " + browserWorkerPolyFill.toString() + ";\n" + 'browserWorkerPolyFill(self);\n' + code;
|
4083 | };
|
4084 |
|
4085 | var getWorkerString = function getWorkerString(fn) {
|
4086 | return fn.toString().replace(/^function.+?{/, '').slice(0, -1);
|
4087 | };
|
4088 |
|
4089 |
|
4090 | var workerCode$1 = transform(getWorkerString(function () {
|
4091 | |
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 |
|
4099 |
|
4100 |
|
4101 | var Stream = function Stream() {
|
4102 | this.init = function () {
|
4103 | var listeners = {};
|
4104 | |
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 | this.on = function (type, listener) {
|
4112 | if (!listeners[type]) {
|
4113 | listeners[type] = [];
|
4114 | }
|
4115 |
|
4116 | listeners[type] = listeners[type].concat(listener);
|
4117 | };
|
4118 | |
4119 |
|
4120 |
|
4121 |
|
4122 |
|
4123 |
|
4124 |
|
4125 |
|
4126 | this.off = function (type, listener) {
|
4127 | var index;
|
4128 |
|
4129 | if (!listeners[type]) {
|
4130 | return false;
|
4131 | }
|
4132 |
|
4133 | index = listeners[type].indexOf(listener);
|
4134 | listeners[type] = listeners[type].slice();
|
4135 | listeners[type].splice(index, 1);
|
4136 | return index > -1;
|
4137 | };
|
4138 | |
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 |
|
4144 |
|
4145 | this.trigger = function (type) {
|
4146 | var callbacks, i, length, args;
|
4147 | callbacks = listeners[type];
|
4148 |
|
4149 | if (!callbacks) {
|
4150 | return;
|
4151 | }
|
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 |
|
4157 | if (arguments.length === 2) {
|
4158 | length = callbacks.length;
|
4159 |
|
4160 | for (i = 0; i < length; ++i) {
|
4161 | callbacks[i].call(this, arguments[1]);
|
4162 | }
|
4163 | } else {
|
4164 | args = [];
|
4165 | i = arguments.length;
|
4166 |
|
4167 | for (i = 1; i < arguments.length; ++i) {
|
4168 | args.push(arguments[i]);
|
4169 | }
|
4170 |
|
4171 | length = callbacks.length;
|
4172 |
|
4173 | for (i = 0; i < length; ++i) {
|
4174 | callbacks[i].apply(this, args);
|
4175 | }
|
4176 | }
|
4177 | };
|
4178 | |
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 | this.dispose = function () {
|
4184 | listeners = {};
|
4185 | };
|
4186 | };
|
4187 | };
|
4188 | |
4189 |
|
4190 |
|
4191 |
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 | Stream.prototype.pipe = function (destination) {
|
4200 | this.on('data', function (data) {
|
4201 | destination.push(data);
|
4202 | });
|
4203 | this.on('done', function (flushSource) {
|
4204 | destination.flush(flushSource);
|
4205 | });
|
4206 | this.on('partialdone', function (flushSource) {
|
4207 | destination.partialFlush(flushSource);
|
4208 | });
|
4209 | this.on('endedtimeline', function (flushSource) {
|
4210 | destination.endTimeline(flushSource);
|
4211 | });
|
4212 | this.on('reset', function (flushSource) {
|
4213 | destination.reset(flushSource);
|
4214 | });
|
4215 | return destination;
|
4216 | };
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 | Stream.prototype.push = function (data) {
|
4223 | this.trigger('data', data);
|
4224 | };
|
4225 |
|
4226 | Stream.prototype.flush = function (flushSource) {
|
4227 | this.trigger('done', flushSource);
|
4228 | };
|
4229 |
|
4230 | Stream.prototype.partialFlush = function (flushSource) {
|
4231 | this.trigger('partialdone', flushSource);
|
4232 | };
|
4233 |
|
4234 | Stream.prototype.endTimeline = function (flushSource) {
|
4235 | this.trigger('endedtimeline', flushSource);
|
4236 | };
|
4237 |
|
4238 | Stream.prototype.reset = function (flushSource) {
|
4239 | this.trigger('reset', flushSource);
|
4240 | };
|
4241 |
|
4242 | var stream = Stream;
|
4243 | var MAX_UINT32$1 = Math.pow(2, 32);
|
4244 |
|
4245 | var getUint64$2 = function getUint64(uint8) {
|
4246 | var dv = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
|
4247 | var value;
|
4248 |
|
4249 | if (dv.getBigUint64) {
|
4250 | value = dv.getBigUint64(0);
|
4251 |
|
4252 | if (value < Number.MAX_SAFE_INTEGER) {
|
4253 | return Number(value);
|
4254 | }
|
4255 |
|
4256 | return value;
|
4257 | }
|
4258 |
|
4259 | return dv.getUint32(0) * MAX_UINT32$1 + dv.getUint32(4);
|
4260 | };
|
4261 |
|
4262 | var numbers = {
|
4263 | getUint64: getUint64$2,
|
4264 | MAX_UINT32: MAX_UINT32$1
|
4265 | };
|
4266 | var MAX_UINT32 = numbers.MAX_UINT32;
|
4267 | 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;
|
4268 |
|
4269 | (function () {
|
4270 | var i;
|
4271 | types = {
|
4272 | avc1: [],
|
4273 |
|
4274 | avcC: [],
|
4275 | btrt: [],
|
4276 | dinf: [],
|
4277 | dref: [],
|
4278 | esds: [],
|
4279 | ftyp: [],
|
4280 | hdlr: [],
|
4281 | mdat: [],
|
4282 | mdhd: [],
|
4283 | mdia: [],
|
4284 | mfhd: [],
|
4285 | minf: [],
|
4286 | moof: [],
|
4287 | moov: [],
|
4288 | mp4a: [],
|
4289 |
|
4290 | mvex: [],
|
4291 | mvhd: [],
|
4292 | pasp: [],
|
4293 | sdtp: [],
|
4294 | smhd: [],
|
4295 | stbl: [],
|
4296 | stco: [],
|
4297 | stsc: [],
|
4298 | stsd: [],
|
4299 | stsz: [],
|
4300 | stts: [],
|
4301 | styp: [],
|
4302 | tfdt: [],
|
4303 | tfhd: [],
|
4304 | traf: [],
|
4305 | trak: [],
|
4306 | trun: [],
|
4307 | trex: [],
|
4308 | tkhd: [],
|
4309 | vmhd: []
|
4310 | };
|
4311 |
|
4312 |
|
4313 | if (typeof Uint8Array === 'undefined') {
|
4314 | return;
|
4315 | }
|
4316 |
|
4317 | for (i in types) {
|
4318 | if (types.hasOwnProperty(i)) {
|
4319 | types[i] = [i.charCodeAt(0), i.charCodeAt(1), i.charCodeAt(2), i.charCodeAt(3)];
|
4320 | }
|
4321 | }
|
4322 |
|
4323 | MAJOR_BRAND = new Uint8Array(['i'.charCodeAt(0), 's'.charCodeAt(0), 'o'.charCodeAt(0), 'm'.charCodeAt(0)]);
|
4324 | AVC1_BRAND = new Uint8Array(['a'.charCodeAt(0), 'v'.charCodeAt(0), 'c'.charCodeAt(0), '1'.charCodeAt(0)]);
|
4325 | MINOR_VERSION = new Uint8Array([0, 0, 0, 1]);
|
4326 | VIDEO_HDLR = new Uint8Array([0x00,
|
4327 | 0x00, 0x00, 0x00,
|
4328 | 0x00, 0x00, 0x00, 0x00,
|
4329 | 0x76, 0x69, 0x64, 0x65,
|
4330 | 0x00, 0x00, 0x00, 0x00,
|
4331 | 0x00, 0x00, 0x00, 0x00,
|
4332 | 0x00, 0x00, 0x00, 0x00,
|
4333 | 0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
4334 | ]);
|
4335 | AUDIO_HDLR = new Uint8Array([0x00,
|
4336 | 0x00, 0x00, 0x00,
|
4337 | 0x00, 0x00, 0x00, 0x00,
|
4338 | 0x73, 0x6f, 0x75, 0x6e,
|
4339 | 0x00, 0x00, 0x00, 0x00,
|
4340 | 0x00, 0x00, 0x00, 0x00,
|
4341 | 0x00, 0x00, 0x00, 0x00,
|
4342 | 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
4343 | ]);
|
4344 | HDLR_TYPES = {
|
4345 | video: VIDEO_HDLR,
|
4346 | audio: AUDIO_HDLR
|
4347 | };
|
4348 | DREF = new Uint8Array([0x00,
|
4349 | 0x00, 0x00, 0x00,
|
4350 | 0x00, 0x00, 0x00, 0x01,
|
4351 | 0x00, 0x00, 0x00, 0x0c,
|
4352 | 0x75, 0x72, 0x6c, 0x20,
|
4353 | 0x00,
|
4354 | 0x00, 0x00, 0x01
|
4355 | ]);
|
4356 | SMHD = new Uint8Array([0x00,
|
4357 | 0x00, 0x00, 0x00,
|
4358 | 0x00, 0x00,
|
4359 | 0x00, 0x00
|
4360 | ]);
|
4361 | STCO = new Uint8Array([0x00,
|
4362 | 0x00, 0x00, 0x00,
|
4363 | 0x00, 0x00, 0x00, 0x00
|
4364 | ]);
|
4365 | STSC = STCO;
|
4366 | STSZ = new Uint8Array([0x00,
|
4367 | 0x00, 0x00, 0x00,
|
4368 | 0x00, 0x00, 0x00, 0x00,
|
4369 | 0x00, 0x00, 0x00, 0x00
|
4370 | ]);
|
4371 | STTS = STCO;
|
4372 | VMHD = new Uint8Array([0x00,
|
4373 | 0x00, 0x00, 0x01,
|
4374 | 0x00, 0x00,
|
4375 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
4376 | ]);
|
4377 | })();
|
4378 |
|
4379 | box = function box(type) {
|
4380 | var payload = [],
|
4381 | size = 0,
|
4382 | i,
|
4383 | result,
|
4384 | view;
|
4385 |
|
4386 | for (i = 1; i < arguments.length; i++) {
|
4387 | payload.push(arguments[i]);
|
4388 | }
|
4389 |
|
4390 | i = payload.length;
|
4391 |
|
4392 | while (i--) {
|
4393 | size += payload[i].byteLength;
|
4394 | }
|
4395 |
|
4396 | result = new Uint8Array(size + 8);
|
4397 | view = new DataView(result.buffer, result.byteOffset, result.byteLength);
|
4398 | view.setUint32(0, result.byteLength);
|
4399 | result.set(type, 4);
|
4400 |
|
4401 | for (i = 0, size = 8; i < payload.length; i++) {
|
4402 | result.set(payload[i], size);
|
4403 | size += payload[i].byteLength;
|
4404 | }
|
4405 |
|
4406 | return result;
|
4407 | };
|
4408 |
|
4409 | dinf = function dinf() {
|
4410 | return box(types.dinf, box(types.dref, DREF));
|
4411 | };
|
4412 |
|
4413 | esds = function esds(track) {
|
4414 | return box(types.esds, new Uint8Array([0x00,
|
4415 | 0x00, 0x00, 0x00,
|
4416 |
|
4417 | 0x03,
|
4418 | 0x19,
|
4419 | 0x00, 0x00,
|
4420 | 0x00,
|
4421 |
|
4422 | 0x04,
|
4423 | 0x11,
|
4424 | 0x40,
|
4425 | 0x15,
|
4426 | 0x00, 0x06, 0x00,
|
4427 | 0x00, 0x00, 0xda, 0xc0,
|
4428 | 0x00, 0x00, 0xda, 0xc0,
|
4429 |
|
4430 | 0x05,
|
4431 | 0x02,
|
4432 |
|
4433 |
|
4434 | track.audioobjecttype << 3 | track.samplingfrequencyindex >>> 1, track.samplingfrequencyindex << 7 | track.channelcount << 3, 0x06, 0x01, 0x02
|
4435 | ]));
|
4436 | };
|
4437 |
|
4438 | ftyp = function ftyp() {
|
4439 | return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND, AVC1_BRAND);
|
4440 | };
|
4441 |
|
4442 | hdlr = function hdlr(type) {
|
4443 | return box(types.hdlr, HDLR_TYPES[type]);
|
4444 | };
|
4445 |
|
4446 | mdat = function mdat(data) {
|
4447 | return box(types.mdat, data);
|
4448 | };
|
4449 |
|
4450 | mdhd = function mdhd(track) {
|
4451 | var result = new Uint8Array([0x00,
|
4452 | 0x00, 0x00, 0x00,
|
4453 | 0x00, 0x00, 0x00, 0x02,
|
4454 | 0x00, 0x00, 0x00, 0x03,
|
4455 | 0x00, 0x01, 0x5f, 0x90,
|
4456 | track.duration >>> 24 & 0xFF, track.duration >>> 16 & 0xFF, track.duration >>> 8 & 0xFF, track.duration & 0xFF,
|
4457 | 0x55, 0xc4,
|
4458 | 0x00, 0x00]);
|
4459 |
|
4460 |
|
4461 |
|
4462 | if (track.samplerate) {
|
4463 | result[12] = track.samplerate >>> 24 & 0xFF;
|
4464 | result[13] = track.samplerate >>> 16 & 0xFF;
|
4465 | result[14] = track.samplerate >>> 8 & 0xFF;
|
4466 | result[15] = track.samplerate & 0xFF;
|
4467 | }
|
4468 |
|
4469 | return box(types.mdhd, result);
|
4470 | };
|
4471 |
|
4472 | mdia = function mdia(track) {
|
4473 | return box(types.mdia, mdhd(track), hdlr(track.type), minf(track));
|
4474 | };
|
4475 |
|
4476 | mfhd = function mfhd(sequenceNumber) {
|
4477 | return box(types.mfhd, new Uint8Array([0x00, 0x00, 0x00, 0x00,
|
4478 | (sequenceNumber & 0xFF000000) >> 24, (sequenceNumber & 0xFF0000) >> 16, (sequenceNumber & 0xFF00) >> 8, sequenceNumber & 0xFF
|
4479 | ]));
|
4480 | };
|
4481 |
|
4482 | minf = function minf(track) {
|
4483 | return box(types.minf, track.type === 'video' ? box(types.vmhd, VMHD) : box(types.smhd, SMHD), dinf(), stbl(track));
|
4484 | };
|
4485 |
|
4486 | moof = function moof(sequenceNumber, tracks) {
|
4487 | var trackFragments = [],
|
4488 | i = tracks.length;
|
4489 |
|
4490 | while (i--) {
|
4491 | trackFragments[i] = traf(tracks[i]);
|
4492 | }
|
4493 |
|
4494 | return box.apply(null, [types.moof, mfhd(sequenceNumber)].concat(trackFragments));
|
4495 | };
|
4496 | |
4497 |
|
4498 |
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 | moov = function moov(tracks) {
|
4504 | var i = tracks.length,
|
4505 | boxes = [];
|
4506 |
|
4507 | while (i--) {
|
4508 | boxes[i] = trak(tracks[i]);
|
4509 | }
|
4510 |
|
4511 | return box.apply(null, [types.moov, mvhd(0xffffffff)].concat(boxes).concat(mvex(tracks)));
|
4512 | };
|
4513 |
|
4514 | mvex = function mvex(tracks) {
|
4515 | var i = tracks.length,
|
4516 | boxes = [];
|
4517 |
|
4518 | while (i--) {
|
4519 | boxes[i] = trex(tracks[i]);
|
4520 | }
|
4521 |
|
4522 | return box.apply(null, [types.mvex].concat(boxes));
|
4523 | };
|
4524 |
|
4525 | mvhd = function mvhd(duration) {
|
4526 | var bytes = new Uint8Array([0x00,
|
4527 | 0x00, 0x00, 0x00,
|
4528 | 0x00, 0x00, 0x00, 0x01,
|
4529 | 0x00, 0x00, 0x00, 0x02,
|
4530 | 0x00, 0x01, 0x5f, 0x90,
|
4531 | (duration & 0xFF000000) >> 24, (duration & 0xFF0000) >> 16, (duration & 0xFF00) >> 8, duration & 0xFF,
|
4532 | 0x00, 0x01, 0x00, 0x00,
|
4533 | 0x01, 0x00,
|
4534 | 0x00, 0x00,
|
4535 | 0x00, 0x00, 0x00, 0x00,
|
4536 | 0x00, 0x00, 0x00, 0x00,
|
4537 | 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,
|
4538 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4539 | 0xff, 0xff, 0xff, 0xff
|
4540 | ]);
|
4541 | return box(types.mvhd, bytes);
|
4542 | };
|
4543 |
|
4544 | sdtp = function sdtp(track) {
|
4545 | var samples = track.samples || [],
|
4546 | bytes = new Uint8Array(4 + samples.length),
|
4547 | flags,
|
4548 | i;
|
4549 |
|
4550 |
|
4551 | for (i = 0; i < samples.length; i++) {
|
4552 | flags = samples[i].flags;
|
4553 | bytes[i + 4] = flags.dependsOn << 4 | flags.isDependedOn << 2 | flags.hasRedundancy;
|
4554 | }
|
4555 |
|
4556 | return box(types.sdtp, bytes);
|
4557 | };
|
4558 |
|
4559 | stbl = function stbl(track) {
|
4560 | return box(types.stbl, stsd(track), box(types.stts, STTS), box(types.stsc, STSC), box(types.stsz, STSZ), box(types.stco, STCO));
|
4561 | };
|
4562 |
|
4563 | (function () {
|
4564 | var videoSample, audioSample;
|
4565 |
|
4566 | stsd = function stsd(track) {
|
4567 | return box(types.stsd, new Uint8Array([0x00,
|
4568 | 0x00, 0x00, 0x00,
|
4569 | 0x00, 0x00, 0x00, 0x01]), track.type === 'video' ? videoSample(track) : audioSample(track));
|
4570 | };
|
4571 |
|
4572 | videoSample = function videoSample(track) {
|
4573 | var sps = track.sps || [],
|
4574 | pps = track.pps || [],
|
4575 | sequenceParameterSets = [],
|
4576 | pictureParameterSets = [],
|
4577 | i,
|
4578 | avc1Box;
|
4579 |
|
4580 | for (i = 0; i < sps.length; i++) {
|
4581 | sequenceParameterSets.push((sps[i].byteLength & 0xFF00) >>> 8);
|
4582 | sequenceParameterSets.push(sps[i].byteLength & 0xFF);
|
4583 |
|
4584 | sequenceParameterSets = sequenceParameterSets.concat(Array.prototype.slice.call(sps[i]));
|
4585 | }
|
4586 |
|
4587 |
|
4588 | for (i = 0; i < pps.length; i++) {
|
4589 | pictureParameterSets.push((pps[i].byteLength & 0xFF00) >>> 8);
|
4590 | pictureParameterSets.push(pps[i].byteLength & 0xFF);
|
4591 | pictureParameterSets = pictureParameterSets.concat(Array.prototype.slice.call(pps[i]));
|
4592 | }
|
4593 |
|
4594 | avc1Box = [types.avc1, new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4595 | 0x00, 0x01,
|
4596 | 0x00, 0x00,
|
4597 | 0x00, 0x00,
|
4598 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4599 | (track.width & 0xff00) >> 8, track.width & 0xff,
|
4600 | (track.height & 0xff00) >> 8, track.height & 0xff,
|
4601 | 0x00, 0x48, 0x00, 0x00,
|
4602 | 0x00, 0x48, 0x00, 0x00,
|
4603 | 0x00, 0x00, 0x00, 0x00,
|
4604 | 0x00, 0x01,
|
4605 | 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,
|
4606 | 0x00, 0x18,
|
4607 | 0x11, 0x11
|
4608 | ]), box(types.avcC, new Uint8Array([0x01,
|
4609 | track.profileIdc,
|
4610 | track.profileCompatibility,
|
4611 | track.levelIdc,
|
4612 | 0xff
|
4613 | ].concat([sps.length],
|
4614 | sequenceParameterSets,
|
4615 | [pps.length],
|
4616 | pictureParameterSets
|
4617 | ))), box(types.btrt, new Uint8Array([0x00, 0x1c, 0x9c, 0x80,
|
4618 | 0x00, 0x2d, 0xc6, 0xc0,
|
4619 | 0x00, 0x2d, 0xc6, 0xc0
|
4620 | ]))];
|
4621 |
|
4622 | if (track.sarRatio) {
|
4623 | var hSpacing = track.sarRatio[0],
|
4624 | vSpacing = track.sarRatio[1];
|
4625 | 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])));
|
4626 | }
|
4627 |
|
4628 | return box.apply(null, avc1Box);
|
4629 | };
|
4630 |
|
4631 | audioSample = function audioSample(track) {
|
4632 | return box(types.mp4a, new Uint8Array([
|
4633 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4634 | 0x00, 0x01,
|
4635 |
|
4636 | 0x00, 0x00, 0x00, 0x00,
|
4637 | 0x00, 0x00, 0x00, 0x00,
|
4638 | (track.channelcount & 0xff00) >> 8, track.channelcount & 0xff,
|
4639 | (track.samplesize & 0xff00) >> 8, track.samplesize & 0xff,
|
4640 | 0x00, 0x00,
|
4641 | 0x00, 0x00,
|
4642 | (track.samplerate & 0xff00) >> 8, track.samplerate & 0xff, 0x00, 0x00
|
4643 |
|
4644 | ]), esds(track));
|
4645 | };
|
4646 | })();
|
4647 |
|
4648 | tkhd = function tkhd(track) {
|
4649 | var result = new Uint8Array([0x00,
|
4650 | 0x00, 0x00, 0x07,
|
4651 | 0x00, 0x00, 0x00, 0x00,
|
4652 | 0x00, 0x00, 0x00, 0x00,
|
4653 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4654 | 0x00, 0x00, 0x00, 0x00,
|
4655 | (track.duration & 0xFF000000) >> 24, (track.duration & 0xFF0000) >> 16, (track.duration & 0xFF00) >> 8, track.duration & 0xFF,
|
4656 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4657 | 0x00, 0x00,
|
4658 | 0x00, 0x00,
|
4659 | 0x01, 0x00,
|
4660 | 0x00, 0x00,
|
4661 | 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,
|
4662 | (track.width & 0xFF00) >> 8, track.width & 0xFF, 0x00, 0x00,
|
4663 | (track.height & 0xFF00) >> 8, track.height & 0xFF, 0x00, 0x00
|
4664 | ]);
|
4665 | return box(types.tkhd, result);
|
4666 | };
|
4667 | |
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 | traf = function traf(track) {
|
4674 | var trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable, dataOffset, upperWordBaseMediaDecodeTime, lowerWordBaseMediaDecodeTime;
|
4675 | trackFragmentHeader = box(types.tfhd, new Uint8Array([0x00,
|
4676 | 0x00, 0x00, 0x3a,
|
4677 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4678 | 0x00, 0x00, 0x00, 0x01,
|
4679 | 0x00, 0x00, 0x00, 0x00,
|
4680 | 0x00, 0x00, 0x00, 0x00,
|
4681 | 0x00, 0x00, 0x00, 0x00
|
4682 | ]));
|
4683 | upperWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime / MAX_UINT32);
|
4684 | lowerWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime % MAX_UINT32);
|
4685 | trackFragmentDecodeTime = box(types.tfdt, new Uint8Array([0x01,
|
4686 | 0x00, 0x00, 0x00,
|
4687 |
|
4688 | upperWordBaseMediaDecodeTime >>> 24 & 0xFF, upperWordBaseMediaDecodeTime >>> 16 & 0xFF, upperWordBaseMediaDecodeTime >>> 8 & 0xFF, upperWordBaseMediaDecodeTime & 0xFF, lowerWordBaseMediaDecodeTime >>> 24 & 0xFF, lowerWordBaseMediaDecodeTime >>> 16 & 0xFF, lowerWordBaseMediaDecodeTime >>> 8 & 0xFF, lowerWordBaseMediaDecodeTime & 0xFF]));
|
4689 |
|
4690 |
|
4691 |
|
4692 | dataOffset = 32 +
|
4693 | 20 +
|
4694 | 8 +
|
4695 | 16 +
|
4696 | 8 +
|
4697 | 8;
|
4698 |
|
4699 |
|
4700 | if (track.type === 'audio') {
|
4701 | trackFragmentRun = trun$1(track, dataOffset);
|
4702 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun);
|
4703 | }
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 | sampleDependencyTable = sdtp(track);
|
4709 | trackFragmentRun = trun$1(track, sampleDependencyTable.length + dataOffset);
|
4710 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable);
|
4711 | };
|
4712 | |
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 | trak = function trak(track) {
|
4720 | track.duration = track.duration || 0xffffffff;
|
4721 | return box(types.trak, tkhd(track), mdia(track));
|
4722 | };
|
4723 |
|
4724 | trex = function trex(track) {
|
4725 | var result = new Uint8Array([0x00,
|
4726 | 0x00, 0x00, 0x00,
|
4727 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4728 | 0x00, 0x00, 0x00, 0x01,
|
4729 | 0x00, 0x00, 0x00, 0x00,
|
4730 | 0x00, 0x00, 0x00, 0x00,
|
4731 | 0x00, 0x01, 0x00, 0x01
|
4732 | ]);
|
4733 |
|
4734 |
|
4735 |
|
4736 |
|
4737 | if (track.type !== 'video') {
|
4738 | result[result.length - 1] = 0x00;
|
4739 | }
|
4740 |
|
4741 | return box(types.trex, result);
|
4742 | };
|
4743 |
|
4744 | (function () {
|
4745 | var audioTrun, videoTrun, trunHeader;
|
4746 |
|
4747 |
|
4748 |
|
4749 |
|
4750 | trunHeader = function trunHeader(samples, offset) {
|
4751 | var durationPresent = 0,
|
4752 | sizePresent = 0,
|
4753 | flagsPresent = 0,
|
4754 | compositionTimeOffset = 0;
|
4755 |
|
4756 | if (samples.length) {
|
4757 | if (samples[0].duration !== undefined) {
|
4758 | durationPresent = 0x1;
|
4759 | }
|
4760 |
|
4761 | if (samples[0].size !== undefined) {
|
4762 | sizePresent = 0x2;
|
4763 | }
|
4764 |
|
4765 | if (samples[0].flags !== undefined) {
|
4766 | flagsPresent = 0x4;
|
4767 | }
|
4768 |
|
4769 | if (samples[0].compositionTimeOffset !== undefined) {
|
4770 | compositionTimeOffset = 0x8;
|
4771 | }
|
4772 | }
|
4773 |
|
4774 | return [0x00,
|
4775 | 0x00, durationPresent | sizePresent | flagsPresent | compositionTimeOffset, 0x01,
|
4776 | (samples.length & 0xFF000000) >>> 24, (samples.length & 0xFF0000) >>> 16, (samples.length & 0xFF00) >>> 8, samples.length & 0xFF,
|
4777 | (offset & 0xFF000000) >>> 24, (offset & 0xFF0000) >>> 16, (offset & 0xFF00) >>> 8, offset & 0xFF
|
4778 | ];
|
4779 | };
|
4780 |
|
4781 | videoTrun = function videoTrun(track, offset) {
|
4782 | var bytesOffest, bytes, header, samples, sample, i;
|
4783 | samples = track.samples || [];
|
4784 | offset += 8 + 12 + 16 * samples.length;
|
4785 | header = trunHeader(samples, offset);
|
4786 | bytes = new Uint8Array(header.length + samples.length * 16);
|
4787 | bytes.set(header);
|
4788 | bytesOffest = header.length;
|
4789 |
|
4790 | for (i = 0; i < samples.length; i++) {
|
4791 | sample = samples[i];
|
4792 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
4793 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
4794 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
4795 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
4796 |
|
4797 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
4798 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
4799 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
4800 | bytes[bytesOffest++] = sample.size & 0xFF;
|
4801 |
|
4802 | bytes[bytesOffest++] = sample.flags.isLeading << 2 | sample.flags.dependsOn;
|
4803 | bytes[bytesOffest++] = sample.flags.isDependedOn << 6 | sample.flags.hasRedundancy << 4 | sample.flags.paddingValue << 1 | sample.flags.isNonSyncSample;
|
4804 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0xF0 << 8;
|
4805 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0x0F;
|
4806 |
|
4807 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF000000) >>> 24;
|
4808 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF0000) >>> 16;
|
4809 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF00) >>> 8;
|
4810 | bytes[bytesOffest++] = sample.compositionTimeOffset & 0xFF;
|
4811 | }
|
4812 |
|
4813 | return box(types.trun, bytes);
|
4814 | };
|
4815 |
|
4816 | audioTrun = function audioTrun(track, offset) {
|
4817 | var bytes, bytesOffest, header, samples, sample, i;
|
4818 | samples = track.samples || [];
|
4819 | offset += 8 + 12 + 8 * samples.length;
|
4820 | header = trunHeader(samples, offset);
|
4821 | bytes = new Uint8Array(header.length + samples.length * 8);
|
4822 | bytes.set(header);
|
4823 | bytesOffest = header.length;
|
4824 |
|
4825 | for (i = 0; i < samples.length; i++) {
|
4826 | sample = samples[i];
|
4827 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
4828 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
4829 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
4830 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
4831 |
|
4832 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
4833 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
4834 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
4835 | bytes[bytesOffest++] = sample.size & 0xFF;
|
4836 | }
|
4837 |
|
4838 | return box(types.trun, bytes);
|
4839 | };
|
4840 |
|
4841 | trun$1 = function trun(track, offset) {
|
4842 | if (track.type === 'audio') {
|
4843 | return audioTrun(track, offset);
|
4844 | }
|
4845 |
|
4846 | return videoTrun(track, offset);
|
4847 | };
|
4848 | })();
|
4849 |
|
4850 | var mp4Generator = {
|
4851 | ftyp: ftyp,
|
4852 | mdat: mdat,
|
4853 | moof: moof,
|
4854 | moov: moov,
|
4855 | initSegment: function initSegment(tracks) {
|
4856 | var fileType = ftyp(),
|
4857 | movie = moov(tracks),
|
4858 | result;
|
4859 | result = new Uint8Array(fileType.byteLength + movie.byteLength);
|
4860 | result.set(fileType);
|
4861 | result.set(movie, fileType.byteLength);
|
4862 | return result;
|
4863 | }
|
4864 | };
|
4865 | |
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 |
|
4874 |
|
4875 |
|
4876 | var groupNalsIntoFrames = function groupNalsIntoFrames(nalUnits) {
|
4877 | var i,
|
4878 | currentNal,
|
4879 | currentFrame = [],
|
4880 | frames = [];
|
4881 |
|
4882 | frames.byteLength = 0;
|
4883 | frames.nalCount = 0;
|
4884 | frames.duration = 0;
|
4885 | currentFrame.byteLength = 0;
|
4886 |
|
4887 | for (i = 0; i < nalUnits.length; i++) {
|
4888 | currentNal = nalUnits[i];
|
4889 |
|
4890 | if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
|
4891 |
|
4892 |
|
4893 | if (currentFrame.length) {
|
4894 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
4895 |
|
4896 | frames.byteLength += currentFrame.byteLength;
|
4897 | frames.nalCount += currentFrame.length;
|
4898 | frames.duration += currentFrame.duration;
|
4899 | frames.push(currentFrame);
|
4900 | }
|
4901 |
|
4902 | currentFrame = [currentNal];
|
4903 | currentFrame.byteLength = currentNal.data.byteLength;
|
4904 | currentFrame.pts = currentNal.pts;
|
4905 | currentFrame.dts = currentNal.dts;
|
4906 | } else {
|
4907 |
|
4908 | if (currentNal.nalUnitType === 'slice_layer_without_partitioning_rbsp_idr') {
|
4909 | currentFrame.keyFrame = true;
|
4910 | }
|
4911 |
|
4912 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
4913 | currentFrame.byteLength += currentNal.data.byteLength;
|
4914 | currentFrame.push(currentNal);
|
4915 | }
|
4916 | }
|
4917 |
|
4918 |
|
4919 |
|
4920 | if (frames.length && (!currentFrame.duration || currentFrame.duration <= 0)) {
|
4921 | currentFrame.duration = frames[frames.length - 1].duration;
|
4922 | }
|
4923 |
|
4924 |
|
4925 |
|
4926 | frames.byteLength += currentFrame.byteLength;
|
4927 | frames.nalCount += currentFrame.length;
|
4928 | frames.duration += currentFrame.duration;
|
4929 | frames.push(currentFrame);
|
4930 | return frames;
|
4931 | };
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 | var groupFramesIntoGops = function groupFramesIntoGops(frames) {
|
4938 | var i,
|
4939 | currentFrame,
|
4940 | currentGop = [],
|
4941 | gops = [];
|
4942 |
|
4943 |
|
4944 | currentGop.byteLength = 0;
|
4945 | currentGop.nalCount = 0;
|
4946 | currentGop.duration = 0;
|
4947 | currentGop.pts = frames[0].pts;
|
4948 | currentGop.dts = frames[0].dts;
|
4949 |
|
4950 | gops.byteLength = 0;
|
4951 | gops.nalCount = 0;
|
4952 | gops.duration = 0;
|
4953 | gops.pts = frames[0].pts;
|
4954 | gops.dts = frames[0].dts;
|
4955 |
|
4956 | for (i = 0; i < frames.length; i++) {
|
4957 | currentFrame = frames[i];
|
4958 |
|
4959 | if (currentFrame.keyFrame) {
|
4960 |
|
4961 |
|
4962 | if (currentGop.length) {
|
4963 | gops.push(currentGop);
|
4964 | gops.byteLength += currentGop.byteLength;
|
4965 | gops.nalCount += currentGop.nalCount;
|
4966 | gops.duration += currentGop.duration;
|
4967 | }
|
4968 |
|
4969 | currentGop = [currentFrame];
|
4970 | currentGop.nalCount = currentFrame.length;
|
4971 | currentGop.byteLength = currentFrame.byteLength;
|
4972 | currentGop.pts = currentFrame.pts;
|
4973 | currentGop.dts = currentFrame.dts;
|
4974 | currentGop.duration = currentFrame.duration;
|
4975 | } else {
|
4976 | currentGop.duration += currentFrame.duration;
|
4977 | currentGop.nalCount += currentFrame.length;
|
4978 | currentGop.byteLength += currentFrame.byteLength;
|
4979 | currentGop.push(currentFrame);
|
4980 | }
|
4981 | }
|
4982 |
|
4983 | if (gops.length && currentGop.duration <= 0) {
|
4984 | currentGop.duration = gops[gops.length - 1].duration;
|
4985 | }
|
4986 |
|
4987 | gops.byteLength += currentGop.byteLength;
|
4988 | gops.nalCount += currentGop.nalCount;
|
4989 | gops.duration += currentGop.duration;
|
4990 |
|
4991 | gops.push(currentGop);
|
4992 | return gops;
|
4993 | };
|
4994 | |
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 |
|
5005 | var extendFirstKeyFrame = function extendFirstKeyFrame(gops) {
|
5006 | var currentGop;
|
5007 |
|
5008 | if (!gops[0][0].keyFrame && gops.length > 1) {
|
5009 |
|
5010 | currentGop = gops.shift();
|
5011 | gops.byteLength -= currentGop.byteLength;
|
5012 | gops.nalCount -= currentGop.nalCount;
|
5013 |
|
5014 |
|
5015 |
|
5016 | gops[0][0].dts = currentGop.dts;
|
5017 | gops[0][0].pts = currentGop.pts;
|
5018 | gops[0][0].duration += currentGop.duration;
|
5019 | }
|
5020 |
|
5021 | return gops;
|
5022 | };
|
5023 | |
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 |
|
5029 | var createDefaultSample = function createDefaultSample() {
|
5030 | return {
|
5031 | size: 0,
|
5032 | flags: {
|
5033 | isLeading: 0,
|
5034 | dependsOn: 1,
|
5035 | isDependedOn: 0,
|
5036 | hasRedundancy: 0,
|
5037 | degradationPriority: 0,
|
5038 | isNonSyncSample: 1
|
5039 | }
|
5040 | };
|
5041 | };
|
5042 | |
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 | var sampleForFrame = function sampleForFrame(frame, dataOffset) {
|
5053 | var sample = createDefaultSample();
|
5054 | sample.dataOffset = dataOffset;
|
5055 | sample.compositionTimeOffset = frame.pts - frame.dts;
|
5056 | sample.duration = frame.duration;
|
5057 | sample.size = 4 * frame.length;
|
5058 |
|
5059 | sample.size += frame.byteLength;
|
5060 |
|
5061 | if (frame.keyFrame) {
|
5062 | sample.flags.dependsOn = 2;
|
5063 | sample.flags.isNonSyncSample = 0;
|
5064 | }
|
5065 |
|
5066 | return sample;
|
5067 | };
|
5068 |
|
5069 |
|
5070 | var generateSampleTable$1 = function generateSampleTable(gops, baseDataOffset) {
|
5071 | var h,
|
5072 | i,
|
5073 | sample,
|
5074 | currentGop,
|
5075 | currentFrame,
|
5076 | dataOffset = baseDataOffset || 0,
|
5077 | samples = [];
|
5078 |
|
5079 | for (h = 0; h < gops.length; h++) {
|
5080 | currentGop = gops[h];
|
5081 |
|
5082 | for (i = 0; i < currentGop.length; i++) {
|
5083 | currentFrame = currentGop[i];
|
5084 | sample = sampleForFrame(currentFrame, dataOffset);
|
5085 | dataOffset += sample.size;
|
5086 | samples.push(sample);
|
5087 | }
|
5088 | }
|
5089 |
|
5090 | return samples;
|
5091 | };
|
5092 |
|
5093 |
|
5094 | var concatenateNalData = function concatenateNalData(gops) {
|
5095 | var h,
|
5096 | i,
|
5097 | j,
|
5098 | currentGop,
|
5099 | currentFrame,
|
5100 | currentNal,
|
5101 | dataOffset = 0,
|
5102 | nalsByteLength = gops.byteLength,
|
5103 | numberOfNals = gops.nalCount,
|
5104 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
5105 | data = new Uint8Array(totalByteLength),
|
5106 | view = new DataView(data.buffer);
|
5107 |
|
5108 | for (h = 0; h < gops.length; h++) {
|
5109 | currentGop = gops[h];
|
5110 |
|
5111 | for (i = 0; i < currentGop.length; i++) {
|
5112 | currentFrame = currentGop[i];
|
5113 |
|
5114 | for (j = 0; j < currentFrame.length; j++) {
|
5115 | currentNal = currentFrame[j];
|
5116 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
5117 | dataOffset += 4;
|
5118 | data.set(currentNal.data, dataOffset);
|
5119 | dataOffset += currentNal.data.byteLength;
|
5120 | }
|
5121 | }
|
5122 | }
|
5123 |
|
5124 | return data;
|
5125 | };
|
5126 |
|
5127 |
|
5128 | var generateSampleTableForFrame = function generateSampleTableForFrame(frame, baseDataOffset) {
|
5129 | var sample,
|
5130 | dataOffset = baseDataOffset || 0,
|
5131 | samples = [];
|
5132 | sample = sampleForFrame(frame, dataOffset);
|
5133 | samples.push(sample);
|
5134 | return samples;
|
5135 | };
|
5136 |
|
5137 |
|
5138 | var concatenateNalDataForFrame = function concatenateNalDataForFrame(frame) {
|
5139 | var i,
|
5140 | currentNal,
|
5141 | dataOffset = 0,
|
5142 | nalsByteLength = frame.byteLength,
|
5143 | numberOfNals = frame.length,
|
5144 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
5145 | data = new Uint8Array(totalByteLength),
|
5146 | view = new DataView(data.buffer);
|
5147 |
|
5148 | for (i = 0; i < frame.length; i++) {
|
5149 | currentNal = frame[i];
|
5150 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
5151 | dataOffset += 4;
|
5152 | data.set(currentNal.data, dataOffset);
|
5153 | dataOffset += currentNal.data.byteLength;
|
5154 | }
|
5155 |
|
5156 | return data;
|
5157 | };
|
5158 |
|
5159 | var frameUtils = {
|
5160 | groupNalsIntoFrames: groupNalsIntoFrames,
|
5161 | groupFramesIntoGops: groupFramesIntoGops,
|
5162 | extendFirstKeyFrame: extendFirstKeyFrame,
|
5163 | generateSampleTable: generateSampleTable$1,
|
5164 | concatenateNalData: concatenateNalData,
|
5165 | generateSampleTableForFrame: generateSampleTableForFrame,
|
5166 | concatenateNalDataForFrame: concatenateNalDataForFrame
|
5167 | };
|
5168 | |
5169 |
|
5170 |
|
5171 |
|
5172 |
|
5173 |
|
5174 |
|
5175 | var highPrefix = [33, 16, 5, 32, 164, 27];
|
5176 | var lowPrefix = [33, 65, 108, 84, 1, 2, 4, 8, 168, 2, 4, 8, 17, 191, 252];
|
5177 |
|
5178 | var zeroFill = function zeroFill(count) {
|
5179 | var a = [];
|
5180 |
|
5181 | while (count--) {
|
5182 | a.push(0);
|
5183 | }
|
5184 |
|
5185 | return a;
|
5186 | };
|
5187 |
|
5188 | var makeTable = function makeTable(metaTable) {
|
5189 | return Object.keys(metaTable).reduce(function (obj, key) {
|
5190 | obj[key] = new Uint8Array(metaTable[key].reduce(function (arr, part) {
|
5191 | return arr.concat(part);
|
5192 | }, []));
|
5193 | return obj;
|
5194 | }, {});
|
5195 | };
|
5196 |
|
5197 | var silence;
|
5198 |
|
5199 | var silence_1 = function silence_1() {
|
5200 | if (!silence) {
|
5201 |
|
5202 | var coneOfSilence = {
|
5203 | 96000: [highPrefix, [227, 64], zeroFill(154), [56]],
|
5204 | 88200: [highPrefix, [231], zeroFill(170), [56]],
|
5205 | 64000: [highPrefix, [248, 192], zeroFill(240), [56]],
|
5206 | 48000: [highPrefix, [255, 192], zeroFill(268), [55, 148, 128], zeroFill(54), [112]],
|
5207 | 44100: [highPrefix, [255, 192], zeroFill(268), [55, 163, 128], zeroFill(84), [112]],
|
5208 | 32000: [highPrefix, [255, 192], zeroFill(268), [55, 234], zeroFill(226), [112]],
|
5209 | 24000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 112], zeroFill(126), [224]],
|
5210 | 16000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 255], zeroFill(269), [223, 108], zeroFill(195), [1, 192]],
|
5211 | 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]],
|
5212 | 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]],
|
5213 | 8000: [lowPrefix, zeroFill(268), [3, 121, 16], zeroFill(47), [7]]
|
5214 | };
|
5215 | silence = makeTable(coneOfSilence);
|
5216 | }
|
5217 |
|
5218 | return silence;
|
5219 | };
|
5220 | |
5221 |
|
5222 |
|
5223 |
|
5224 |
|
5225 |
|
5226 |
|
5227 |
|
5228 | var ONE_SECOND_IN_TS$4 = 90000,
|
5229 |
|
5230 | secondsToVideoTs,
|
5231 | secondsToAudioTs,
|
5232 | videoTsToSeconds,
|
5233 | audioTsToSeconds,
|
5234 | audioTsToVideoTs,
|
5235 | videoTsToAudioTs,
|
5236 | metadataTsToSeconds;
|
5237 |
|
5238 | secondsToVideoTs = function secondsToVideoTs(seconds) {
|
5239 | return seconds * ONE_SECOND_IN_TS$4;
|
5240 | };
|
5241 |
|
5242 | secondsToAudioTs = function secondsToAudioTs(seconds, sampleRate) {
|
5243 | return seconds * sampleRate;
|
5244 | };
|
5245 |
|
5246 | videoTsToSeconds = function videoTsToSeconds(timestamp) {
|
5247 | return timestamp / ONE_SECOND_IN_TS$4;
|
5248 | };
|
5249 |
|
5250 | audioTsToSeconds = function audioTsToSeconds(timestamp, sampleRate) {
|
5251 | return timestamp / sampleRate;
|
5252 | };
|
5253 |
|
5254 | audioTsToVideoTs = function audioTsToVideoTs(timestamp, sampleRate) {
|
5255 | return secondsToVideoTs(audioTsToSeconds(timestamp, sampleRate));
|
5256 | };
|
5257 |
|
5258 | videoTsToAudioTs = function videoTsToAudioTs(timestamp, sampleRate) {
|
5259 | return secondsToAudioTs(videoTsToSeconds(timestamp), sampleRate);
|
5260 | };
|
5261 | |
5262 |
|
5263 |
|
5264 |
|
5265 |
|
5266 |
|
5267 | metadataTsToSeconds = function metadataTsToSeconds(timestamp, timelineStartPts, keepOriginalTimestamps) {
|
5268 | return videoTsToSeconds(keepOriginalTimestamps ? timestamp : timestamp - timelineStartPts);
|
5269 | };
|
5270 |
|
5271 | var clock = {
|
5272 | ONE_SECOND_IN_TS: ONE_SECOND_IN_TS$4,
|
5273 | secondsToVideoTs: secondsToVideoTs,
|
5274 | secondsToAudioTs: secondsToAudioTs,
|
5275 | videoTsToSeconds: videoTsToSeconds,
|
5276 | audioTsToSeconds: audioTsToSeconds,
|
5277 | audioTsToVideoTs: audioTsToVideoTs,
|
5278 | videoTsToAudioTs: videoTsToAudioTs,
|
5279 | metadataTsToSeconds: metadataTsToSeconds
|
5280 | };
|
5281 | |
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 | |
5289 |
|
5290 |
|
5291 |
|
5292 | var sumFrameByteLengths = function sumFrameByteLengths(array) {
|
5293 | var i,
|
5294 | currentObj,
|
5295 | sum = 0;
|
5296 |
|
5297 | for (i = 0; i < array.length; i++) {
|
5298 | currentObj = array[i];
|
5299 | sum += currentObj.data.byteLength;
|
5300 | }
|
5301 |
|
5302 | return sum;
|
5303 | };
|
5304 |
|
5305 |
|
5306 |
|
5307 | var prefixWithSilence = function prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime) {
|
5308 | var baseMediaDecodeTimeTs,
|
5309 | frameDuration = 0,
|
5310 | audioGapDuration = 0,
|
5311 | audioFillFrameCount = 0,
|
5312 | audioFillDuration = 0,
|
5313 | silentFrame,
|
5314 | i,
|
5315 | firstFrame;
|
5316 |
|
5317 | if (!frames.length) {
|
5318 | return;
|
5319 | }
|
5320 |
|
5321 | baseMediaDecodeTimeTs = clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate);
|
5322 |
|
5323 | frameDuration = Math.ceil(clock.ONE_SECOND_IN_TS / (track.samplerate / 1024));
|
5324 |
|
5325 | if (audioAppendStartTs && videoBaseMediaDecodeTime) {
|
5326 |
|
5327 | audioGapDuration = baseMediaDecodeTimeTs - Math.max(audioAppendStartTs, videoBaseMediaDecodeTime);
|
5328 |
|
5329 | audioFillFrameCount = Math.floor(audioGapDuration / frameDuration);
|
5330 | audioFillDuration = audioFillFrameCount * frameDuration;
|
5331 | }
|
5332 |
|
5333 |
|
5334 |
|
5335 | if (audioFillFrameCount < 1 || audioFillDuration > clock.ONE_SECOND_IN_TS / 2) {
|
5336 | return;
|
5337 | }
|
5338 |
|
5339 | silentFrame = silence_1()[track.samplerate];
|
5340 |
|
5341 | if (!silentFrame) {
|
5342 |
|
5343 |
|
5344 | silentFrame = frames[0].data;
|
5345 | }
|
5346 |
|
5347 | for (i = 0; i < audioFillFrameCount; i++) {
|
5348 | firstFrame = frames[0];
|
5349 | frames.splice(0, 0, {
|
5350 | data: silentFrame,
|
5351 | dts: firstFrame.dts - frameDuration,
|
5352 | pts: firstFrame.pts - frameDuration
|
5353 | });
|
5354 | }
|
5355 |
|
5356 | track.baseMediaDecodeTime -= Math.floor(clock.videoTsToAudioTs(audioFillDuration, track.samplerate));
|
5357 | return audioFillDuration;
|
5358 | };
|
5359 |
|
5360 |
|
5361 |
|
5362 |
|
5363 |
|
5364 | var trimAdtsFramesByEarliestDts = function trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts) {
|
5365 | if (track.minSegmentDts >= earliestAllowedDts) {
|
5366 | return adtsFrames;
|
5367 | }
|
5368 |
|
5369 |
|
5370 | track.minSegmentDts = Infinity;
|
5371 | return adtsFrames.filter(function (currentFrame) {
|
5372 |
|
5373 | if (currentFrame.dts >= earliestAllowedDts) {
|
5374 | track.minSegmentDts = Math.min(track.minSegmentDts, currentFrame.dts);
|
5375 | track.minSegmentPts = track.minSegmentDts;
|
5376 | return true;
|
5377 | }
|
5378 |
|
5379 |
|
5380 | return false;
|
5381 | });
|
5382 | };
|
5383 |
|
5384 |
|
5385 | var generateSampleTable = function generateSampleTable(frames) {
|
5386 | var i,
|
5387 | currentFrame,
|
5388 | samples = [];
|
5389 |
|
5390 | for (i = 0; i < frames.length; i++) {
|
5391 | currentFrame = frames[i];
|
5392 | samples.push({
|
5393 | size: currentFrame.data.byteLength,
|
5394 | duration: 1024
|
5395 |
|
5396 | });
|
5397 | }
|
5398 |
|
5399 | return samples;
|
5400 | };
|
5401 |
|
5402 |
|
5403 | var concatenateFrameData = function concatenateFrameData(frames) {
|
5404 | var i,
|
5405 | currentFrame,
|
5406 | dataOffset = 0,
|
5407 | data = new Uint8Array(sumFrameByteLengths(frames));
|
5408 |
|
5409 | for (i = 0; i < frames.length; i++) {
|
5410 | currentFrame = frames[i];
|
5411 | data.set(currentFrame.data, dataOffset);
|
5412 | dataOffset += currentFrame.data.byteLength;
|
5413 | }
|
5414 |
|
5415 | return data;
|
5416 | };
|
5417 |
|
5418 | var audioFrameUtils = {
|
5419 | prefixWithSilence: prefixWithSilence,
|
5420 | trimAdtsFramesByEarliestDts: trimAdtsFramesByEarliestDts,
|
5421 | generateSampleTable: generateSampleTable,
|
5422 | concatenateFrameData: concatenateFrameData
|
5423 | };
|
5424 | |
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 | var ONE_SECOND_IN_TS$3 = clock.ONE_SECOND_IN_TS;
|
5432 | |
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 | var collectDtsInfo = function collectDtsInfo(track, data) {
|
5439 | if (typeof data.pts === 'number') {
|
5440 | if (track.timelineStartInfo.pts === undefined) {
|
5441 | track.timelineStartInfo.pts = data.pts;
|
5442 | }
|
5443 |
|
5444 | if (track.minSegmentPts === undefined) {
|
5445 | track.minSegmentPts = data.pts;
|
5446 | } else {
|
5447 | track.minSegmentPts = Math.min(track.minSegmentPts, data.pts);
|
5448 | }
|
5449 |
|
5450 | if (track.maxSegmentPts === undefined) {
|
5451 | track.maxSegmentPts = data.pts;
|
5452 | } else {
|
5453 | track.maxSegmentPts = Math.max(track.maxSegmentPts, data.pts);
|
5454 | }
|
5455 | }
|
5456 |
|
5457 | if (typeof data.dts === 'number') {
|
5458 | if (track.timelineStartInfo.dts === undefined) {
|
5459 | track.timelineStartInfo.dts = data.dts;
|
5460 | }
|
5461 |
|
5462 | if (track.minSegmentDts === undefined) {
|
5463 | track.minSegmentDts = data.dts;
|
5464 | } else {
|
5465 | track.minSegmentDts = Math.min(track.minSegmentDts, data.dts);
|
5466 | }
|
5467 |
|
5468 | if (track.maxSegmentDts === undefined) {
|
5469 | track.maxSegmentDts = data.dts;
|
5470 | } else {
|
5471 | track.maxSegmentDts = Math.max(track.maxSegmentDts, data.dts);
|
5472 | }
|
5473 | }
|
5474 | };
|
5475 | |
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 |
|
5481 | var clearDtsInfo = function clearDtsInfo(track) {
|
5482 | delete track.minSegmentDts;
|
5483 | delete track.maxSegmentDts;
|
5484 | delete track.minSegmentPts;
|
5485 | delete track.maxSegmentPts;
|
5486 | };
|
5487 | |
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 |
|
5494 |
|
5495 |
|
5496 |
|
5497 | var calculateTrackBaseMediaDecodeTime = function calculateTrackBaseMediaDecodeTime(track, keepOriginalTimestamps) {
|
5498 | var baseMediaDecodeTime,
|
5499 | scale,
|
5500 | minSegmentDts = track.minSegmentDts;
|
5501 |
|
5502 | if (!keepOriginalTimestamps) {
|
5503 | minSegmentDts -= track.timelineStartInfo.dts;
|
5504 | }
|
5505 |
|
5506 |
|
5507 |
|
5508 | baseMediaDecodeTime = track.timelineStartInfo.baseMediaDecodeTime;
|
5509 |
|
5510 | baseMediaDecodeTime += minSegmentDts;
|
5511 |
|
5512 | baseMediaDecodeTime = Math.max(0, baseMediaDecodeTime);
|
5513 |
|
5514 | if (track.type === 'audio') {
|
5515 |
|
5516 |
|
5517 | scale = track.samplerate / ONE_SECOND_IN_TS$3;
|
5518 | baseMediaDecodeTime *= scale;
|
5519 | baseMediaDecodeTime = Math.floor(baseMediaDecodeTime);
|
5520 | }
|
5521 |
|
5522 | return baseMediaDecodeTime;
|
5523 | };
|
5524 |
|
5525 | var trackDecodeInfo = {
|
5526 | clearDtsInfo: clearDtsInfo,
|
5527 | calculateTrackBaseMediaDecodeTime: calculateTrackBaseMediaDecodeTime,
|
5528 | collectDtsInfo: collectDtsInfo
|
5529 | };
|
5530 | |
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 | var USER_DATA_REGISTERED_ITU_T_T35 = 4,
|
5547 | RBSP_TRAILING_BITS = 128;
|
5548 | |
5549 |
|
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 | var parseSei = function parseSei(bytes) {
|
5558 | var i = 0,
|
5559 | result = {
|
5560 | payloadType: -1,
|
5561 | payloadSize: 0
|
5562 | },
|
5563 | payloadType = 0,
|
5564 | payloadSize = 0;
|
5565 |
|
5566 | while (i < bytes.byteLength) {
|
5567 |
|
5568 | if (bytes[i] === RBSP_TRAILING_BITS) {
|
5569 | break;
|
5570 | }
|
5571 |
|
5572 |
|
5573 | while (bytes[i] === 0xFF) {
|
5574 | payloadType += 255;
|
5575 | i++;
|
5576 | }
|
5577 |
|
5578 | payloadType += bytes[i++];
|
5579 |
|
5580 | while (bytes[i] === 0xFF) {
|
5581 | payloadSize += 255;
|
5582 | i++;
|
5583 | }
|
5584 |
|
5585 | payloadSize += bytes[i++];
|
5586 |
|
5587 |
|
5588 | if (!result.payload && payloadType === USER_DATA_REGISTERED_ITU_T_T35) {
|
5589 | var userIdentifier = String.fromCharCode(bytes[i + 3], bytes[i + 4], bytes[i + 5], bytes[i + 6]);
|
5590 |
|
5591 | if (userIdentifier === 'GA94') {
|
5592 | result.payloadType = payloadType;
|
5593 | result.payloadSize = payloadSize;
|
5594 | result.payload = bytes.subarray(i, i + payloadSize);
|
5595 | break;
|
5596 | } else {
|
5597 | result.payload = void 0;
|
5598 | }
|
5599 | }
|
5600 |
|
5601 |
|
5602 | i += payloadSize;
|
5603 | payloadType = 0;
|
5604 | payloadSize = 0;
|
5605 | }
|
5606 |
|
5607 | return result;
|
5608 | };
|
5609 |
|
5610 |
|
5611 | var parseUserData = function parseUserData(sei) {
|
5612 |
|
5613 |
|
5614 | if (sei.payload[0] !== 181) {
|
5615 | return null;
|
5616 | }
|
5617 |
|
5618 |
|
5619 | if ((sei.payload[1] << 8 | sei.payload[2]) !== 49) {
|
5620 | return null;
|
5621 | }
|
5622 |
|
5623 |
|
5624 | if (String.fromCharCode(sei.payload[3], sei.payload[4], sei.payload[5], sei.payload[6]) !== 'GA94') {
|
5625 | return null;
|
5626 | }
|
5627 |
|
5628 |
|
5629 | if (sei.payload[7] !== 0x03) {
|
5630 | return null;
|
5631 | }
|
5632 |
|
5633 |
|
5634 |
|
5635 | return sei.payload.subarray(8, sei.payload.length - 1);
|
5636 | };
|
5637 |
|
5638 |
|
5639 | var parseCaptionPackets = function parseCaptionPackets(pts, userData) {
|
5640 | var results = [],
|
5641 | i,
|
5642 | count,
|
5643 | offset,
|
5644 | data;
|
5645 |
|
5646 | if (!(userData[0] & 0x40)) {
|
5647 | return results;
|
5648 | }
|
5649 |
|
5650 |
|
5651 | count = userData[0] & 0x1f;
|
5652 |
|
5653 | for (i = 0; i < count; i++) {
|
5654 | offset = i * 3;
|
5655 | data = {
|
5656 | type: userData[offset + 2] & 0x03,
|
5657 | pts: pts
|
5658 | };
|
5659 |
|
5660 | if (userData[offset + 2] & 0x04) {
|
5661 | data.ccData = userData[offset + 3] << 8 | userData[offset + 4];
|
5662 | results.push(data);
|
5663 | }
|
5664 | }
|
5665 |
|
5666 | return results;
|
5667 | };
|
5668 |
|
5669 | var discardEmulationPreventionBytes$1 = function discardEmulationPreventionBytes(data) {
|
5670 | var length = data.byteLength,
|
5671 | emulationPreventionBytesPositions = [],
|
5672 | i = 1,
|
5673 | newLength,
|
5674 | newData;
|
5675 |
|
5676 | while (i < length - 2) {
|
5677 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
5678 | emulationPreventionBytesPositions.push(i + 2);
|
5679 | i += 2;
|
5680 | } else {
|
5681 | i++;
|
5682 | }
|
5683 | }
|
5684 |
|
5685 |
|
5686 |
|
5687 | if (emulationPreventionBytesPositions.length === 0) {
|
5688 | return data;
|
5689 | }
|
5690 |
|
5691 |
|
5692 | newLength = length - emulationPreventionBytesPositions.length;
|
5693 | newData = new Uint8Array(newLength);
|
5694 | var sourceIndex = 0;
|
5695 |
|
5696 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
5697 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
5698 |
|
5699 | sourceIndex++;
|
5700 |
|
5701 | emulationPreventionBytesPositions.shift();
|
5702 | }
|
5703 |
|
5704 | newData[i] = data[sourceIndex];
|
5705 | }
|
5706 |
|
5707 | return newData;
|
5708 | };
|
5709 |
|
5710 |
|
5711 | var captionPacketParser = {
|
5712 | parseSei: parseSei,
|
5713 | parseUserData: parseUserData,
|
5714 | parseCaptionPackets: parseCaptionPackets,
|
5715 | discardEmulationPreventionBytes: discardEmulationPreventionBytes$1,
|
5716 | USER_DATA_REGISTERED_ITU_T_T35: USER_DATA_REGISTERED_ITU_T_T35
|
5717 | };
|
5718 |
|
5719 |
|
5720 | var CaptionStream$1 = function CaptionStream(options) {
|
5721 | options = options || {};
|
5722 | CaptionStream.prototype.init.call(this);
|
5723 |
|
5724 | this.parse708captions_ = typeof options.parse708captions === 'boolean' ? options.parse708captions : true;
|
5725 | this.captionPackets_ = [];
|
5726 | this.ccStreams_ = [new Cea608Stream(0, 0),
|
5727 | new Cea608Stream(0, 1),
|
5728 | new Cea608Stream(1, 0),
|
5729 | new Cea608Stream(1, 1)
|
5730 | ];
|
5731 |
|
5732 | if (this.parse708captions_) {
|
5733 | this.cc708Stream_ = new Cea708Stream({
|
5734 | captionServices: options.captionServices
|
5735 | });
|
5736 | }
|
5737 |
|
5738 | this.reset();
|
5739 |
|
5740 | this.ccStreams_.forEach(function (cc) {
|
5741 | cc.on('data', this.trigger.bind(this, 'data'));
|
5742 | cc.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
5743 | cc.on('done', this.trigger.bind(this, 'done'));
|
5744 | }, this);
|
5745 |
|
5746 | if (this.parse708captions_) {
|
5747 | this.cc708Stream_.on('data', this.trigger.bind(this, 'data'));
|
5748 | this.cc708Stream_.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
5749 | this.cc708Stream_.on('done', this.trigger.bind(this, 'done'));
|
5750 | }
|
5751 | };
|
5752 |
|
5753 | CaptionStream$1.prototype = new stream();
|
5754 |
|
5755 | CaptionStream$1.prototype.push = function (event) {
|
5756 | var sei, userData, newCaptionPackets;
|
5757 |
|
5758 | if (event.nalUnitType !== 'sei_rbsp') {
|
5759 | return;
|
5760 | }
|
5761 |
|
5762 |
|
5763 | sei = captionPacketParser.parseSei(event.escapedRBSP);
|
5764 |
|
5765 | if (!sei.payload) {
|
5766 | return;
|
5767 | }
|
5768 |
|
5769 |
|
5770 | if (sei.payloadType !== captionPacketParser.USER_DATA_REGISTERED_ITU_T_T35) {
|
5771 | return;
|
5772 | }
|
5773 |
|
5774 |
|
5775 | userData = captionPacketParser.parseUserData(sei);
|
5776 |
|
5777 | if (!userData) {
|
5778 | return;
|
5779 | }
|
5780 |
|
5781 |
|
5782 |
|
5783 |
|
5784 |
|
5785 |
|
5786 |
|
5787 |
|
5788 |
|
5789 | if (event.dts < this.latestDts_) {
|
5790 |
|
5791 | this.ignoreNextEqualDts_ = true;
|
5792 | return;
|
5793 | } else if (event.dts === this.latestDts_ && this.ignoreNextEqualDts_) {
|
5794 | this.numSameDts_--;
|
5795 |
|
5796 | if (!this.numSameDts_) {
|
5797 |
|
5798 | this.ignoreNextEqualDts_ = false;
|
5799 | }
|
5800 |
|
5801 | return;
|
5802 | }
|
5803 |
|
5804 |
|
5805 | newCaptionPackets = captionPacketParser.parseCaptionPackets(event.pts, userData);
|
5806 | this.captionPackets_ = this.captionPackets_.concat(newCaptionPackets);
|
5807 |
|
5808 | if (this.latestDts_ !== event.dts) {
|
5809 | this.numSameDts_ = 0;
|
5810 | }
|
5811 |
|
5812 | this.numSameDts_++;
|
5813 | this.latestDts_ = event.dts;
|
5814 | };
|
5815 |
|
5816 | CaptionStream$1.prototype.flushCCStreams = function (flushType) {
|
5817 | this.ccStreams_.forEach(function (cc) {
|
5818 | return flushType === 'flush' ? cc.flush() : cc.partialFlush();
|
5819 | }, this);
|
5820 | };
|
5821 |
|
5822 | CaptionStream$1.prototype.flushStream = function (flushType) {
|
5823 |
|
5824 | if (!this.captionPackets_.length) {
|
5825 | this.flushCCStreams(flushType);
|
5826 | return;
|
5827 | }
|
5828 |
|
5829 |
|
5830 |
|
5831 | this.captionPackets_.forEach(function (elem, idx) {
|
5832 | elem.presortIndex = idx;
|
5833 | });
|
5834 |
|
5835 | this.captionPackets_.sort(function (a, b) {
|
5836 | if (a.pts === b.pts) {
|
5837 | return a.presortIndex - b.presortIndex;
|
5838 | }
|
5839 |
|
5840 | return a.pts - b.pts;
|
5841 | });
|
5842 | this.captionPackets_.forEach(function (packet) {
|
5843 | if (packet.type < 2) {
|
5844 |
|
5845 | this.dispatchCea608Packet(packet);
|
5846 | } else {
|
5847 |
|
5848 | this.dispatchCea708Packet(packet);
|
5849 | }
|
5850 | }, this);
|
5851 | this.captionPackets_.length = 0;
|
5852 | this.flushCCStreams(flushType);
|
5853 | };
|
5854 |
|
5855 | CaptionStream$1.prototype.flush = function () {
|
5856 | return this.flushStream('flush');
|
5857 | };
|
5858 |
|
5859 |
|
5860 | CaptionStream$1.prototype.partialFlush = function () {
|
5861 | return this.flushStream('partialFlush');
|
5862 | };
|
5863 |
|
5864 | CaptionStream$1.prototype.reset = function () {
|
5865 | this.latestDts_ = null;
|
5866 | this.ignoreNextEqualDts_ = false;
|
5867 | this.numSameDts_ = 0;
|
5868 | this.activeCea608Channel_ = [null, null];
|
5869 | this.ccStreams_.forEach(function (ccStream) {
|
5870 | ccStream.reset();
|
5871 | });
|
5872 | };
|
5873 |
|
5874 | |
5875 |
|
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 | CaptionStream$1.prototype.dispatchCea608Packet = function (packet) {
|
5887 |
|
5888 | if (this.setsTextOrXDSActive(packet)) {
|
5889 | this.activeCea608Channel_[packet.type] = null;
|
5890 | } else if (this.setsChannel1Active(packet)) {
|
5891 | this.activeCea608Channel_[packet.type] = 0;
|
5892 | } else if (this.setsChannel2Active(packet)) {
|
5893 | this.activeCea608Channel_[packet.type] = 1;
|
5894 | }
|
5895 |
|
5896 | if (this.activeCea608Channel_[packet.type] === null) {
|
5897 |
|
5898 |
|
5899 |
|
5900 | return;
|
5901 | }
|
5902 |
|
5903 | this.ccStreams_[(packet.type << 1) + this.activeCea608Channel_[packet.type]].push(packet);
|
5904 | };
|
5905 |
|
5906 | CaptionStream$1.prototype.setsChannel1Active = function (packet) {
|
5907 | return (packet.ccData & 0x7800) === 0x1000;
|
5908 | };
|
5909 |
|
5910 | CaptionStream$1.prototype.setsChannel2Active = function (packet) {
|
5911 | return (packet.ccData & 0x7800) === 0x1800;
|
5912 | };
|
5913 |
|
5914 | CaptionStream$1.prototype.setsTextOrXDSActive = function (packet) {
|
5915 | return (packet.ccData & 0x7100) === 0x0100 || (packet.ccData & 0x78fe) === 0x102a || (packet.ccData & 0x78fe) === 0x182a;
|
5916 | };
|
5917 |
|
5918 | CaptionStream$1.prototype.dispatchCea708Packet = function (packet) {
|
5919 | if (this.parse708captions_) {
|
5920 | this.cc708Stream_.push(packet);
|
5921 | }
|
5922 | };
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 |
|
5928 |
|
5929 |
|
5930 |
|
5931 |
|
5932 |
|
5933 |
|
5934 |
|
5935 |
|
5936 |
|
5937 |
|
5938 |
|
5939 |
|
5940 |
|
5941 |
|
5942 | var CHARACTER_TRANSLATION_708 = {
|
5943 | 0x7f: 0x266a,
|
5944 |
|
5945 | 0x1020: 0x20,
|
5946 |
|
5947 | 0x1021: 0xa0,
|
5948 |
|
5949 | 0x1025: 0x2026,
|
5950 |
|
5951 | 0x102a: 0x0160,
|
5952 |
|
5953 | 0x102c: 0x0152,
|
5954 |
|
5955 | 0x1030: 0x2588,
|
5956 |
|
5957 | 0x1031: 0x2018,
|
5958 |
|
5959 | 0x1032: 0x2019,
|
5960 |
|
5961 | 0x1033: 0x201c,
|
5962 |
|
5963 | 0x1034: 0x201d,
|
5964 |
|
5965 | 0x1035: 0x2022,
|
5966 |
|
5967 | 0x1039: 0x2122,
|
5968 |
|
5969 | 0x103a: 0x0161,
|
5970 |
|
5971 | 0x103c: 0x0153,
|
5972 |
|
5973 | 0x103d: 0x2120,
|
5974 |
|
5975 | 0x103f: 0x0178,
|
5976 |
|
5977 | 0x1076: 0x215b,
|
5978 |
|
5979 | 0x1077: 0x215c,
|
5980 |
|
5981 | 0x1078: 0x215d,
|
5982 |
|
5983 | 0x1079: 0x215e,
|
5984 |
|
5985 | 0x107a: 0x23d0,
|
5986 |
|
5987 | 0x107b: 0x23a4,
|
5988 |
|
5989 | 0x107c: 0x23a3,
|
5990 |
|
5991 | 0x107d: 0x23af,
|
5992 |
|
5993 | 0x107e: 0x23a6,
|
5994 |
|
5995 | 0x107f: 0x23a1,
|
5996 |
|
5997 | 0x10a0: 0x3138
|
5998 |
|
5999 | };
|
6000 |
|
6001 | var get708CharFromCode = function get708CharFromCode(code) {
|
6002 | var newCode = CHARACTER_TRANSLATION_708[code] || code;
|
6003 |
|
6004 | if (code & 0x1000 && code === newCode) {
|
6005 |
|
6006 | return '';
|
6007 | }
|
6008 |
|
6009 | return String.fromCharCode(newCode);
|
6010 | };
|
6011 |
|
6012 | var within708TextBlock = function within708TextBlock(b) {
|
6013 | return 0x20 <= b && b <= 0x7f || 0xa0 <= b && b <= 0xff;
|
6014 | };
|
6015 |
|
6016 | var Cea708Window = function Cea708Window(windowNum) {
|
6017 | this.windowNum = windowNum;
|
6018 | this.reset();
|
6019 | };
|
6020 |
|
6021 | Cea708Window.prototype.reset = function () {
|
6022 | this.clearText();
|
6023 | this.pendingNewLine = false;
|
6024 | this.winAttr = {};
|
6025 | this.penAttr = {};
|
6026 | this.penLoc = {};
|
6027 | this.penColor = {};
|
6028 |
|
6029 |
|
6030 | this.visible = 0;
|
6031 | this.rowLock = 0;
|
6032 | this.columnLock = 0;
|
6033 | this.priority = 0;
|
6034 | this.relativePositioning = 0;
|
6035 | this.anchorVertical = 0;
|
6036 | this.anchorHorizontal = 0;
|
6037 | this.anchorPoint = 0;
|
6038 | this.rowCount = 1;
|
6039 | this.virtualRowCount = this.rowCount + 1;
|
6040 | this.columnCount = 41;
|
6041 | this.windowStyle = 0;
|
6042 | this.penStyle = 0;
|
6043 | };
|
6044 |
|
6045 | Cea708Window.prototype.getText = function () {
|
6046 | return this.rows.join('\n');
|
6047 | };
|
6048 |
|
6049 | Cea708Window.prototype.clearText = function () {
|
6050 | this.rows = [''];
|
6051 | this.rowIdx = 0;
|
6052 | };
|
6053 |
|
6054 | Cea708Window.prototype.newLine = function (pts) {
|
6055 | if (this.rows.length >= this.virtualRowCount && typeof this.beforeRowOverflow === 'function') {
|
6056 | this.beforeRowOverflow(pts);
|
6057 | }
|
6058 |
|
6059 | if (this.rows.length > 0) {
|
6060 | this.rows.push('');
|
6061 | this.rowIdx++;
|
6062 | }
|
6063 |
|
6064 |
|
6065 | while (this.rows.length > this.virtualRowCount) {
|
6066 | this.rows.shift();
|
6067 | this.rowIdx--;
|
6068 | }
|
6069 | };
|
6070 |
|
6071 | Cea708Window.prototype.isEmpty = function () {
|
6072 | if (this.rows.length === 0) {
|
6073 | return true;
|
6074 | } else if (this.rows.length === 1) {
|
6075 | return this.rows[0] === '';
|
6076 | }
|
6077 |
|
6078 | return false;
|
6079 | };
|
6080 |
|
6081 | Cea708Window.prototype.addText = function (text) {
|
6082 | this.rows[this.rowIdx] += text;
|
6083 | };
|
6084 |
|
6085 | Cea708Window.prototype.backspace = function () {
|
6086 | if (!this.isEmpty()) {
|
6087 | var row = this.rows[this.rowIdx];
|
6088 | this.rows[this.rowIdx] = row.substr(0, row.length - 1);
|
6089 | }
|
6090 | };
|
6091 |
|
6092 | var Cea708Service = function Cea708Service(serviceNum, encoding, stream) {
|
6093 | this.serviceNum = serviceNum;
|
6094 | this.text = '';
|
6095 | this.currentWindow = new Cea708Window(-1);
|
6096 | this.windows = [];
|
6097 | this.stream = stream;
|
6098 |
|
6099 | if (typeof encoding === 'string') {
|
6100 | this.createTextDecoder(encoding);
|
6101 | }
|
6102 | };
|
6103 | |
6104 |
|
6105 |
|
6106 |
|
6107 |
|
6108 |
|
6109 |
|
6110 |
|
6111 |
|
6112 | Cea708Service.prototype.init = function (pts, beforeRowOverflow) {
|
6113 | this.startPts = pts;
|
6114 |
|
6115 | for (var win = 0; win < 8; win++) {
|
6116 | this.windows[win] = new Cea708Window(win);
|
6117 |
|
6118 | if (typeof beforeRowOverflow === 'function') {
|
6119 | this.windows[win].beforeRowOverflow = beforeRowOverflow;
|
6120 | }
|
6121 | }
|
6122 | };
|
6123 | |
6124 |
|
6125 |
|
6126 |
|
6127 |
|
6128 |
|
6129 |
|
6130 | Cea708Service.prototype.setCurrentWindow = function (windowNum) {
|
6131 | this.currentWindow = this.windows[windowNum];
|
6132 | };
|
6133 | |
6134 |
|
6135 |
|
6136 |
|
6137 |
|
6138 | Cea708Service.prototype.createTextDecoder = function (encoding) {
|
6139 | if (typeof TextDecoder === 'undefined') {
|
6140 | this.stream.trigger('log', {
|
6141 | level: 'warn',
|
6142 | message: 'The `encoding` option is unsupported without TextDecoder support'
|
6143 | });
|
6144 | } else {
|
6145 | try {
|
6146 | this.textDecoder_ = new TextDecoder(encoding);
|
6147 | } catch (error) {
|
6148 | this.stream.trigger('log', {
|
6149 | level: 'warn',
|
6150 | message: 'TextDecoder could not be created with ' + encoding + ' encoding. ' + error
|
6151 | });
|
6152 | }
|
6153 | }
|
6154 | };
|
6155 |
|
6156 | var Cea708Stream = function Cea708Stream(options) {
|
6157 | options = options || {};
|
6158 | Cea708Stream.prototype.init.call(this);
|
6159 | var self = this;
|
6160 | var captionServices = options.captionServices || {};
|
6161 | var captionServiceEncodings = {};
|
6162 | var serviceProps;
|
6163 |
|
6164 | Object.keys(captionServices).forEach(function (serviceName) {
|
6165 | serviceProps = captionServices[serviceName];
|
6166 |
|
6167 | if (/^SERVICE/.test(serviceName)) {
|
6168 | captionServiceEncodings[serviceName] = serviceProps.encoding;
|
6169 | }
|
6170 | });
|
6171 | this.serviceEncodings = captionServiceEncodings;
|
6172 | this.current708Packet = null;
|
6173 | this.services = {};
|
6174 |
|
6175 | this.push = function (packet) {
|
6176 | if (packet.type === 3) {
|
6177 |
|
6178 | self.new708Packet();
|
6179 | self.add708Bytes(packet);
|
6180 | } else {
|
6181 | if (self.current708Packet === null) {
|
6182 |
|
6183 | self.new708Packet();
|
6184 | }
|
6185 |
|
6186 | self.add708Bytes(packet);
|
6187 | }
|
6188 | };
|
6189 | };
|
6190 |
|
6191 | Cea708Stream.prototype = new stream();
|
6192 | |
6193 |
|
6194 |
|
6195 |
|
6196 | Cea708Stream.prototype.new708Packet = function () {
|
6197 | if (this.current708Packet !== null) {
|
6198 | this.push708Packet();
|
6199 | }
|
6200 |
|
6201 | this.current708Packet = {
|
6202 | data: [],
|
6203 | ptsVals: []
|
6204 | };
|
6205 | };
|
6206 | |
6207 |
|
6208 |
|
6209 |
|
6210 |
|
6211 | Cea708Stream.prototype.add708Bytes = function (packet) {
|
6212 | var data = packet.ccData;
|
6213 | var byte0 = data >>> 8;
|
6214 | var byte1 = data & 0xff;
|
6215 |
|
6216 |
|
6217 | this.current708Packet.ptsVals.push(packet.pts);
|
6218 | this.current708Packet.data.push(byte0);
|
6219 | this.current708Packet.data.push(byte1);
|
6220 | };
|
6221 | |
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 | Cea708Stream.prototype.push708Packet = function () {
|
6227 | var packet708 = this.current708Packet;
|
6228 | var packetData = packet708.data;
|
6229 | var serviceNum = null;
|
6230 | var blockSize = null;
|
6231 | var i = 0;
|
6232 | var b = packetData[i++];
|
6233 | packet708.seq = b >> 6;
|
6234 | packet708.sizeCode = b & 0x3f;
|
6235 |
|
6236 | for (; i < packetData.length; i++) {
|
6237 | b = packetData[i++];
|
6238 | serviceNum = b >> 5;
|
6239 | blockSize = b & 0x1f;
|
6240 |
|
6241 | if (serviceNum === 7 && blockSize > 0) {
|
6242 |
|
6243 | b = packetData[i++];
|
6244 | serviceNum = b;
|
6245 | }
|
6246 |
|
6247 | this.pushServiceBlock(serviceNum, i, blockSize);
|
6248 |
|
6249 | if (blockSize > 0) {
|
6250 | i += blockSize - 1;
|
6251 | }
|
6252 | }
|
6253 | };
|
6254 | |
6255 |
|
6256 |
|
6257 |
|
6258 |
|
6259 |
|
6260 |
|
6261 |
|
6262 |
|
6263 |
|
6264 |
|
6265 |
|
6266 |
|
6267 |
|
6268 | Cea708Stream.prototype.pushServiceBlock = function (serviceNum, start, size) {
|
6269 | var b;
|
6270 | var i = start;
|
6271 | var packetData = this.current708Packet.data;
|
6272 | var service = this.services[serviceNum];
|
6273 |
|
6274 | if (!service) {
|
6275 | service = this.initService(serviceNum, i);
|
6276 | }
|
6277 |
|
6278 | for (; i < start + size && i < packetData.length; i++) {
|
6279 | b = packetData[i];
|
6280 |
|
6281 | if (within708TextBlock(b)) {
|
6282 | i = this.handleText(i, service);
|
6283 | } else if (b === 0x18) {
|
6284 | i = this.multiByteCharacter(i, service);
|
6285 | } else if (b === 0x10) {
|
6286 | i = this.extendedCommands(i, service);
|
6287 | } else if (0x80 <= b && b <= 0x87) {
|
6288 | i = this.setCurrentWindow(i, service);
|
6289 | } else if (0x98 <= b && b <= 0x9f) {
|
6290 | i = this.defineWindow(i, service);
|
6291 | } else if (b === 0x88) {
|
6292 | i = this.clearWindows(i, service);
|
6293 | } else if (b === 0x8c) {
|
6294 | i = this.deleteWindows(i, service);
|
6295 | } else if (b === 0x89) {
|
6296 | i = this.displayWindows(i, service);
|
6297 | } else if (b === 0x8a) {
|
6298 | i = this.hideWindows(i, service);
|
6299 | } else if (b === 0x8b) {
|
6300 | i = this.toggleWindows(i, service);
|
6301 | } else if (b === 0x97) {
|
6302 | i = this.setWindowAttributes(i, service);
|
6303 | } else if (b === 0x90) {
|
6304 | i = this.setPenAttributes(i, service);
|
6305 | } else if (b === 0x91) {
|
6306 | i = this.setPenColor(i, service);
|
6307 | } else if (b === 0x92) {
|
6308 | i = this.setPenLocation(i, service);
|
6309 | } else if (b === 0x8f) {
|
6310 | service = this.reset(i, service);
|
6311 | } else if (b === 0x08) {
|
6312 |
|
6313 | service.currentWindow.backspace();
|
6314 | } else if (b === 0x0c) {
|
6315 |
|
6316 | service.currentWindow.clearText();
|
6317 | } else if (b === 0x0d) {
|
6318 |
|
6319 | service.currentWindow.pendingNewLine = true;
|
6320 | } else if (b === 0x0e) {
|
6321 |
|
6322 | service.currentWindow.clearText();
|
6323 | } else if (b === 0x8d) {
|
6324 |
|
6325 | i++;
|
6326 | } else ;
|
6327 | }
|
6328 | };
|
6329 | |
6330 |
|
6331 |
|
6332 |
|
6333 |
|
6334 |
|
6335 |
|
6336 |
|
6337 |
|
6338 | Cea708Stream.prototype.extendedCommands = function (i, service) {
|
6339 | var packetData = this.current708Packet.data;
|
6340 | var b = packetData[++i];
|
6341 |
|
6342 | if (within708TextBlock(b)) {
|
6343 | i = this.handleText(i, service, {
|
6344 | isExtended: true
|
6345 | });
|
6346 | }
|
6347 |
|
6348 | return i;
|
6349 | };
|
6350 | |
6351 |
|
6352 |
|
6353 |
|
6354 |
|
6355 |
|
6356 |
|
6357 |
|
6358 | Cea708Stream.prototype.getPts = function (byteIndex) {
|
6359 |
|
6360 | return this.current708Packet.ptsVals[Math.floor(byteIndex / 2)];
|
6361 | };
|
6362 | |
6363 |
|
6364 |
|
6365 |
|
6366 |
|
6367 |
|
6368 |
|
6369 |
|
6370 | Cea708Stream.prototype.initService = function (serviceNum, i) {
|
6371 | var serviceName = 'SERVICE' + serviceNum;
|
6372 | var self = this;
|
6373 | var serviceName;
|
6374 | var encoding;
|
6375 |
|
6376 | if (serviceName in this.serviceEncodings) {
|
6377 | encoding = this.serviceEncodings[serviceName];
|
6378 | }
|
6379 |
|
6380 | this.services[serviceNum] = new Cea708Service(serviceNum, encoding, self);
|
6381 | this.services[serviceNum].init(this.getPts(i), function (pts) {
|
6382 | self.flushDisplayed(pts, self.services[serviceNum]);
|
6383 | });
|
6384 | return this.services[serviceNum];
|
6385 | };
|
6386 | |
6387 |
|
6388 |
|
6389 |
|
6390 |
|
6391 |
|
6392 |
|
6393 |
|
6394 |
|
6395 | Cea708Stream.prototype.handleText = function (i, service, options) {
|
6396 | var isExtended = options && options.isExtended;
|
6397 | var isMultiByte = options && options.isMultiByte;
|
6398 | var packetData = this.current708Packet.data;
|
6399 | var extended = isExtended ? 0x1000 : 0x0000;
|
6400 | var currentByte = packetData[i];
|
6401 | var nextByte = packetData[i + 1];
|
6402 | var win = service.currentWindow;
|
6403 | var char;
|
6404 | var charCodeArray;
|
6405 |
|
6406 | if (service.textDecoder_ && !isExtended) {
|
6407 | if (isMultiByte) {
|
6408 | charCodeArray = [currentByte, nextByte];
|
6409 | i++;
|
6410 | } else {
|
6411 | charCodeArray = [currentByte];
|
6412 | }
|
6413 |
|
6414 | char = service.textDecoder_.decode(new Uint8Array(charCodeArray));
|
6415 | } else {
|
6416 | char = get708CharFromCode(extended | currentByte);
|
6417 | }
|
6418 |
|
6419 | if (win.pendingNewLine && !win.isEmpty()) {
|
6420 | win.newLine(this.getPts(i));
|
6421 | }
|
6422 |
|
6423 | win.pendingNewLine = false;
|
6424 | win.addText(char);
|
6425 | return i;
|
6426 | };
|
6427 | |
6428 |
|
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 |
|
6435 |
|
6436 | Cea708Stream.prototype.multiByteCharacter = function (i, service) {
|
6437 | var packetData = this.current708Packet.data;
|
6438 | var firstByte = packetData[i + 1];
|
6439 | var secondByte = packetData[i + 2];
|
6440 |
|
6441 | if (within708TextBlock(firstByte) && within708TextBlock(secondByte)) {
|
6442 | i = this.handleText(++i, service, {
|
6443 | isMultiByte: true
|
6444 | });
|
6445 | }
|
6446 |
|
6447 | return i;
|
6448 | };
|
6449 | |
6450 |
|
6451 |
|
6452 |
|
6453 |
|
6454 |
|
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 | Cea708Stream.prototype.setCurrentWindow = function (i, service) {
|
6461 | var packetData = this.current708Packet.data;
|
6462 | var b = packetData[i];
|
6463 | var windowNum = b & 0x07;
|
6464 | service.setCurrentWindow(windowNum);
|
6465 | return i;
|
6466 | };
|
6467 | |
6468 |
|
6469 |
|
6470 |
|
6471 |
|
6472 |
|
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 |
|
6478 | Cea708Stream.prototype.defineWindow = function (i, service) {
|
6479 | var packetData = this.current708Packet.data;
|
6480 | var b = packetData[i];
|
6481 | var windowNum = b & 0x07;
|
6482 | service.setCurrentWindow(windowNum);
|
6483 | var win = service.currentWindow;
|
6484 | b = packetData[++i];
|
6485 | win.visible = (b & 0x20) >> 5;
|
6486 |
|
6487 | win.rowLock = (b & 0x10) >> 4;
|
6488 |
|
6489 | win.columnLock = (b & 0x08) >> 3;
|
6490 |
|
6491 | win.priority = b & 0x07;
|
6492 |
|
6493 | b = packetData[++i];
|
6494 | win.relativePositioning = (b & 0x80) >> 7;
|
6495 |
|
6496 | win.anchorVertical = b & 0x7f;
|
6497 |
|
6498 | b = packetData[++i];
|
6499 | win.anchorHorizontal = b;
|
6500 |
|
6501 | b = packetData[++i];
|
6502 | win.anchorPoint = (b & 0xf0) >> 4;
|
6503 |
|
6504 | win.rowCount = b & 0x0f;
|
6505 |
|
6506 | b = packetData[++i];
|
6507 | win.columnCount = b & 0x3f;
|
6508 |
|
6509 | b = packetData[++i];
|
6510 | win.windowStyle = (b & 0x38) >> 3;
|
6511 |
|
6512 | win.penStyle = b & 0x07;
|
6513 |
|
6514 |
|
6515 | win.virtualRowCount = win.rowCount + 1;
|
6516 | return i;
|
6517 | };
|
6518 | |
6519 |
|
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 |
|
6526 |
|
6527 |
|
6528 |
|
6529 | Cea708Stream.prototype.setWindowAttributes = function (i, service) {
|
6530 | var packetData = this.current708Packet.data;
|
6531 | var b = packetData[i];
|
6532 | var winAttr = service.currentWindow.winAttr;
|
6533 | b = packetData[++i];
|
6534 | winAttr.fillOpacity = (b & 0xc0) >> 6;
|
6535 |
|
6536 | winAttr.fillRed = (b & 0x30) >> 4;
|
6537 |
|
6538 | winAttr.fillGreen = (b & 0x0c) >> 2;
|
6539 |
|
6540 | winAttr.fillBlue = b & 0x03;
|
6541 |
|
6542 | b = packetData[++i];
|
6543 | winAttr.borderType = (b & 0xc0) >> 6;
|
6544 |
|
6545 | winAttr.borderRed = (b & 0x30) >> 4;
|
6546 |
|
6547 | winAttr.borderGreen = (b & 0x0c) >> 2;
|
6548 |
|
6549 | winAttr.borderBlue = b & 0x03;
|
6550 |
|
6551 | b = packetData[++i];
|
6552 | winAttr.borderType += (b & 0x80) >> 5;
|
6553 |
|
6554 | winAttr.wordWrap = (b & 0x40) >> 6;
|
6555 |
|
6556 | winAttr.printDirection = (b & 0x30) >> 4;
|
6557 |
|
6558 | winAttr.scrollDirection = (b & 0x0c) >> 2;
|
6559 |
|
6560 | winAttr.justify = b & 0x03;
|
6561 |
|
6562 | b = packetData[++i];
|
6563 | winAttr.effectSpeed = (b & 0xf0) >> 4;
|
6564 |
|
6565 | winAttr.effectDirection = (b & 0x0c) >> 2;
|
6566 |
|
6567 | winAttr.displayEffect = b & 0x03;
|
6568 |
|
6569 | return i;
|
6570 | };
|
6571 | |
6572 |
|
6573 |
|
6574 |
|
6575 |
|
6576 |
|
6577 |
|
6578 |
|
6579 | Cea708Stream.prototype.flushDisplayed = function (pts, service) {
|
6580 | var displayedText = [];
|
6581 |
|
6582 |
|
6583 | for (var winId = 0; winId < 8; winId++) {
|
6584 | if (service.windows[winId].visible && !service.windows[winId].isEmpty()) {
|
6585 | displayedText.push(service.windows[winId].getText());
|
6586 | }
|
6587 | }
|
6588 |
|
6589 | service.endPts = pts;
|
6590 | service.text = displayedText.join('\n\n');
|
6591 | this.pushCaption(service);
|
6592 | service.startPts = pts;
|
6593 | };
|
6594 | |
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 | Cea708Stream.prototype.pushCaption = function (service) {
|
6602 | if (service.text !== '') {
|
6603 | this.trigger('data', {
|
6604 | startPts: service.startPts,
|
6605 | endPts: service.endPts,
|
6606 | text: service.text,
|
6607 | stream: 'cc708_' + service.serviceNum
|
6608 | });
|
6609 | service.text = '';
|
6610 | service.startPts = service.endPts;
|
6611 | }
|
6612 | };
|
6613 | |
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 | Cea708Stream.prototype.displayWindows = function (i, service) {
|
6625 | var packetData = this.current708Packet.data;
|
6626 | var b = packetData[++i];
|
6627 | var pts = this.getPts(i);
|
6628 | this.flushDisplayed(pts, service);
|
6629 |
|
6630 | for (var winId = 0; winId < 8; winId++) {
|
6631 | if (b & 0x01 << winId) {
|
6632 | service.windows[winId].visible = 1;
|
6633 | }
|
6634 | }
|
6635 |
|
6636 | return i;
|
6637 | };
|
6638 | |
6639 |
|
6640 |
|
6641 |
|
6642 |
|
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 | Cea708Stream.prototype.hideWindows = function (i, service) {
|
6650 | var packetData = this.current708Packet.data;
|
6651 | var b = packetData[++i];
|
6652 | var pts = this.getPts(i);
|
6653 | this.flushDisplayed(pts, service);
|
6654 |
|
6655 | for (var winId = 0; winId < 8; winId++) {
|
6656 | if (b & 0x01 << winId) {
|
6657 | service.windows[winId].visible = 0;
|
6658 | }
|
6659 | }
|
6660 |
|
6661 | return i;
|
6662 | };
|
6663 | |
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 | Cea708Stream.prototype.toggleWindows = function (i, service) {
|
6675 | var packetData = this.current708Packet.data;
|
6676 | var b = packetData[++i];
|
6677 | var pts = this.getPts(i);
|
6678 | this.flushDisplayed(pts, service);
|
6679 |
|
6680 | for (var winId = 0; winId < 8; winId++) {
|
6681 | if (b & 0x01 << winId) {
|
6682 | service.windows[winId].visible ^= 1;
|
6683 | }
|
6684 | }
|
6685 |
|
6686 | return i;
|
6687 | };
|
6688 | |
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 | Cea708Stream.prototype.clearWindows = function (i, service) {
|
6700 | var packetData = this.current708Packet.data;
|
6701 | var b = packetData[++i];
|
6702 | var pts = this.getPts(i);
|
6703 | this.flushDisplayed(pts, service);
|
6704 |
|
6705 | for (var winId = 0; winId < 8; winId++) {
|
6706 | if (b & 0x01 << winId) {
|
6707 | service.windows[winId].clearText();
|
6708 | }
|
6709 | }
|
6710 |
|
6711 | return i;
|
6712 | };
|
6713 | |
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 |
|
6719 |
|
6720 |
|
6721 |
|
6722 |
|
6723 |
|
6724 | Cea708Stream.prototype.deleteWindows = function (i, service) {
|
6725 | var packetData = this.current708Packet.data;
|
6726 | var b = packetData[++i];
|
6727 | var pts = this.getPts(i);
|
6728 | this.flushDisplayed(pts, service);
|
6729 |
|
6730 | for (var winId = 0; winId < 8; winId++) {
|
6731 | if (b & 0x01 << winId) {
|
6732 | service.windows[winId].reset();
|
6733 | }
|
6734 | }
|
6735 |
|
6736 | return i;
|
6737 | };
|
6738 | |
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 | Cea708Stream.prototype.setPenAttributes = function (i, service) {
|
6750 | var packetData = this.current708Packet.data;
|
6751 | var b = packetData[i];
|
6752 | var penAttr = service.currentWindow.penAttr;
|
6753 | b = packetData[++i];
|
6754 | penAttr.textTag = (b & 0xf0) >> 4;
|
6755 |
|
6756 | penAttr.offset = (b & 0x0c) >> 2;
|
6757 |
|
6758 | penAttr.penSize = b & 0x03;
|
6759 |
|
6760 | b = packetData[++i];
|
6761 | penAttr.italics = (b & 0x80) >> 7;
|
6762 |
|
6763 | penAttr.underline = (b & 0x40) >> 6;
|
6764 |
|
6765 | penAttr.edgeType = (b & 0x38) >> 3;
|
6766 |
|
6767 | penAttr.fontStyle = b & 0x07;
|
6768 |
|
6769 | return i;
|
6770 | };
|
6771 | |
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 | Cea708Stream.prototype.setPenColor = function (i, service) {
|
6783 | var packetData = this.current708Packet.data;
|
6784 | var b = packetData[i];
|
6785 | var penColor = service.currentWindow.penColor;
|
6786 | b = packetData[++i];
|
6787 | penColor.fgOpacity = (b & 0xc0) >> 6;
|
6788 |
|
6789 | penColor.fgRed = (b & 0x30) >> 4;
|
6790 |
|
6791 | penColor.fgGreen = (b & 0x0c) >> 2;
|
6792 |
|
6793 | penColor.fgBlue = b & 0x03;
|
6794 |
|
6795 | b = packetData[++i];
|
6796 | penColor.bgOpacity = (b & 0xc0) >> 6;
|
6797 |
|
6798 | penColor.bgRed = (b & 0x30) >> 4;
|
6799 |
|
6800 | penColor.bgGreen = (b & 0x0c) >> 2;
|
6801 |
|
6802 | penColor.bgBlue = b & 0x03;
|
6803 |
|
6804 | b = packetData[++i];
|
6805 | penColor.edgeRed = (b & 0x30) >> 4;
|
6806 |
|
6807 | penColor.edgeGreen = (b & 0x0c) >> 2;
|
6808 |
|
6809 | penColor.edgeBlue = b & 0x03;
|
6810 |
|
6811 | return i;
|
6812 | };
|
6813 | |
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 | Cea708Stream.prototype.setPenLocation = function (i, service) {
|
6825 | var packetData = this.current708Packet.data;
|
6826 | var b = packetData[i];
|
6827 | var penLoc = service.currentWindow.penLoc;
|
6828 |
|
6829 | service.currentWindow.pendingNewLine = true;
|
6830 | b = packetData[++i];
|
6831 | penLoc.row = b & 0x0f;
|
6832 |
|
6833 | b = packetData[++i];
|
6834 | penLoc.column = b & 0x3f;
|
6835 |
|
6836 | return i;
|
6837 | };
|
6838 | |
6839 |
|
6840 |
|
6841 |
|
6842 |
|
6843 |
|
6844 |
|
6845 |
|
6846 |
|
6847 |
|
6848 |
|
6849 | Cea708Stream.prototype.reset = function (i, service) {
|
6850 | var pts = this.getPts(i);
|
6851 | this.flushDisplayed(pts, service);
|
6852 | return this.initService(service.serviceNum, i);
|
6853 | };
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 |
|
6859 |
|
6860 |
|
6861 |
|
6862 | var CHARACTER_TRANSLATION = {
|
6863 | 0x2a: 0xe1,
|
6864 |
|
6865 | 0x5c: 0xe9,
|
6866 |
|
6867 | 0x5e: 0xed,
|
6868 |
|
6869 | 0x5f: 0xf3,
|
6870 |
|
6871 | 0x60: 0xfa,
|
6872 |
|
6873 | 0x7b: 0xe7,
|
6874 |
|
6875 | 0x7c: 0xf7,
|
6876 |
|
6877 | 0x7d: 0xd1,
|
6878 |
|
6879 | 0x7e: 0xf1,
|
6880 |
|
6881 | 0x7f: 0x2588,
|
6882 |
|
6883 | 0x0130: 0xae,
|
6884 |
|
6885 | 0x0131: 0xb0,
|
6886 |
|
6887 | 0x0132: 0xbd,
|
6888 |
|
6889 | 0x0133: 0xbf,
|
6890 |
|
6891 | 0x0134: 0x2122,
|
6892 |
|
6893 | 0x0135: 0xa2,
|
6894 |
|
6895 | 0x0136: 0xa3,
|
6896 |
|
6897 | 0x0137: 0x266a,
|
6898 |
|
6899 | 0x0138: 0xe0,
|
6900 |
|
6901 | 0x0139: 0xa0,
|
6902 |
|
6903 | 0x013a: 0xe8,
|
6904 |
|
6905 | 0x013b: 0xe2,
|
6906 |
|
6907 | 0x013c: 0xea,
|
6908 |
|
6909 | 0x013d: 0xee,
|
6910 |
|
6911 | 0x013e: 0xf4,
|
6912 |
|
6913 | 0x013f: 0xfb,
|
6914 |
|
6915 | 0x0220: 0xc1,
|
6916 |
|
6917 | 0x0221: 0xc9,
|
6918 |
|
6919 | 0x0222: 0xd3,
|
6920 |
|
6921 | 0x0223: 0xda,
|
6922 |
|
6923 | 0x0224: 0xdc,
|
6924 |
|
6925 | 0x0225: 0xfc,
|
6926 |
|
6927 | 0x0226: 0x2018,
|
6928 |
|
6929 | 0x0227: 0xa1,
|
6930 |
|
6931 | 0x0228: 0x2a,
|
6932 |
|
6933 | 0x0229: 0x27,
|
6934 |
|
6935 | 0x022a: 0x2014,
|
6936 |
|
6937 | 0x022b: 0xa9,
|
6938 |
|
6939 | 0x022c: 0x2120,
|
6940 |
|
6941 | 0x022d: 0x2022,
|
6942 |
|
6943 | 0x022e: 0x201c,
|
6944 |
|
6945 | 0x022f: 0x201d,
|
6946 |
|
6947 | 0x0230: 0xc0,
|
6948 |
|
6949 | 0x0231: 0xc2,
|
6950 |
|
6951 | 0x0232: 0xc7,
|
6952 |
|
6953 | 0x0233: 0xc8,
|
6954 |
|
6955 | 0x0234: 0xca,
|
6956 |
|
6957 | 0x0235: 0xcb,
|
6958 |
|
6959 | 0x0236: 0xeb,
|
6960 |
|
6961 | 0x0237: 0xce,
|
6962 |
|
6963 | 0x0238: 0xcf,
|
6964 |
|
6965 | 0x0239: 0xef,
|
6966 |
|
6967 | 0x023a: 0xd4,
|
6968 |
|
6969 | 0x023b: 0xd9,
|
6970 |
|
6971 | 0x023c: 0xf9,
|
6972 |
|
6973 | 0x023d: 0xdb,
|
6974 |
|
6975 | 0x023e: 0xab,
|
6976 |
|
6977 | 0x023f: 0xbb,
|
6978 |
|
6979 | 0x0320: 0xc3,
|
6980 |
|
6981 | 0x0321: 0xe3,
|
6982 |
|
6983 | 0x0322: 0xcd,
|
6984 |
|
6985 | 0x0323: 0xcc,
|
6986 |
|
6987 | 0x0324: 0xec,
|
6988 |
|
6989 | 0x0325: 0xd2,
|
6990 |
|
6991 | 0x0326: 0xf2,
|
6992 |
|
6993 | 0x0327: 0xd5,
|
6994 |
|
6995 | 0x0328: 0xf5,
|
6996 |
|
6997 | 0x0329: 0x7b,
|
6998 |
|
6999 | 0x032a: 0x7d,
|
7000 |
|
7001 | 0x032b: 0x5c,
|
7002 |
|
7003 | 0x032c: 0x5e,
|
7004 |
|
7005 | 0x032d: 0x5f,
|
7006 |
|
7007 | 0x032e: 0x7c,
|
7008 |
|
7009 | 0x032f: 0x7e,
|
7010 |
|
7011 | 0x0330: 0xc4,
|
7012 |
|
7013 | 0x0331: 0xe4,
|
7014 |
|
7015 | 0x0332: 0xd6,
|
7016 |
|
7017 | 0x0333: 0xf6,
|
7018 |
|
7019 | 0x0334: 0xdf,
|
7020 |
|
7021 | 0x0335: 0xa5,
|
7022 |
|
7023 | 0x0336: 0xa4,
|
7024 |
|
7025 | 0x0337: 0x2502,
|
7026 |
|
7027 | 0x0338: 0xc5,
|
7028 |
|
7029 | 0x0339: 0xe5,
|
7030 |
|
7031 | 0x033a: 0xd8,
|
7032 |
|
7033 | 0x033b: 0xf8,
|
7034 |
|
7035 | 0x033c: 0x250c,
|
7036 |
|
7037 | 0x033d: 0x2510,
|
7038 |
|
7039 | 0x033e: 0x2514,
|
7040 |
|
7041 | 0x033f: 0x2518
|
7042 |
|
7043 | };
|
7044 |
|
7045 | var getCharFromCode = function getCharFromCode(code) {
|
7046 | if (code === null) {
|
7047 | return '';
|
7048 | }
|
7049 |
|
7050 | code = CHARACTER_TRANSLATION[code] || code;
|
7051 | return String.fromCharCode(code);
|
7052 | };
|
7053 |
|
7054 |
|
7055 | var BOTTOM_ROW = 14;
|
7056 |
|
7057 |
|
7058 | var ROWS = [0x1100, 0x1120, 0x1200, 0x1220, 0x1500, 0x1520, 0x1600, 0x1620, 0x1700, 0x1720, 0x1000, 0x1300, 0x1320, 0x1400, 0x1420];
|
7059 |
|
7060 |
|
7061 | var createDisplayBuffer = function createDisplayBuffer() {
|
7062 | var result = [],
|
7063 | i = BOTTOM_ROW + 1;
|
7064 |
|
7065 | while (i--) {
|
7066 | result.push('');
|
7067 | }
|
7068 |
|
7069 | return result;
|
7070 | };
|
7071 |
|
7072 | var Cea608Stream = function Cea608Stream(field, dataChannel) {
|
7073 | Cea608Stream.prototype.init.call(this);
|
7074 | this.field_ = field || 0;
|
7075 | this.dataChannel_ = dataChannel || 0;
|
7076 | this.name_ = 'CC' + ((this.field_ << 1 | this.dataChannel_) + 1);
|
7077 | this.setConstants();
|
7078 | this.reset();
|
7079 |
|
7080 | this.push = function (packet) {
|
7081 | var data, swap, char0, char1, text;
|
7082 |
|
7083 | data = packet.ccData & 0x7f7f;
|
7084 |
|
7085 | if (data === this.lastControlCode_) {
|
7086 | this.lastControlCode_ = null;
|
7087 | return;
|
7088 | }
|
7089 |
|
7090 |
|
7091 | if ((data & 0xf000) === 0x1000) {
|
7092 | this.lastControlCode_ = data;
|
7093 | } else if (data !== this.PADDING_) {
|
7094 | this.lastControlCode_ = null;
|
7095 | }
|
7096 |
|
7097 | char0 = data >>> 8;
|
7098 | char1 = data & 0xff;
|
7099 |
|
7100 | if (data === this.PADDING_) {
|
7101 | return;
|
7102 | } else if (data === this.RESUME_CAPTION_LOADING_) {
|
7103 | this.mode_ = 'popOn';
|
7104 | } else if (data === this.END_OF_CAPTION_) {
|
7105 |
|
7106 |
|
7107 |
|
7108 |
|
7109 | this.mode_ = 'popOn';
|
7110 | this.clearFormatting(packet.pts);
|
7111 |
|
7112 | this.flushDisplayed(packet.pts);
|
7113 |
|
7114 | swap = this.displayed_;
|
7115 | this.displayed_ = this.nonDisplayed_;
|
7116 | this.nonDisplayed_ = swap;
|
7117 |
|
7118 | this.startPts_ = packet.pts;
|
7119 | } else if (data === this.ROLL_UP_2_ROWS_) {
|
7120 | this.rollUpRows_ = 2;
|
7121 | this.setRollUp(packet.pts);
|
7122 | } else if (data === this.ROLL_UP_3_ROWS_) {
|
7123 | this.rollUpRows_ = 3;
|
7124 | this.setRollUp(packet.pts);
|
7125 | } else if (data === this.ROLL_UP_4_ROWS_) {
|
7126 | this.rollUpRows_ = 4;
|
7127 | this.setRollUp(packet.pts);
|
7128 | } else if (data === this.CARRIAGE_RETURN_) {
|
7129 | this.clearFormatting(packet.pts);
|
7130 | this.flushDisplayed(packet.pts);
|
7131 | this.shiftRowsUp_();
|
7132 | this.startPts_ = packet.pts;
|
7133 | } else if (data === this.BACKSPACE_) {
|
7134 | if (this.mode_ === 'popOn') {
|
7135 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
7136 | } else {
|
7137 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
7138 | }
|
7139 | } else if (data === this.ERASE_DISPLAYED_MEMORY_) {
|
7140 | this.flushDisplayed(packet.pts);
|
7141 | this.displayed_ = createDisplayBuffer();
|
7142 | } else if (data === this.ERASE_NON_DISPLAYED_MEMORY_) {
|
7143 | this.nonDisplayed_ = createDisplayBuffer();
|
7144 | } else if (data === this.RESUME_DIRECT_CAPTIONING_) {
|
7145 | if (this.mode_ !== 'paintOn') {
|
7146 |
|
7147 |
|
7148 | this.flushDisplayed(packet.pts);
|
7149 | this.displayed_ = createDisplayBuffer();
|
7150 | }
|
7151 |
|
7152 | this.mode_ = 'paintOn';
|
7153 | this.startPts_ = packet.pts;
|
7154 | } else if (this.isSpecialCharacter(char0, char1)) {
|
7155 |
|
7156 |
|
7157 |
|
7158 |
|
7159 | char0 = (char0 & 0x03) << 8;
|
7160 | text = getCharFromCode(char0 | char1);
|
7161 | this[this.mode_](packet.pts, text);
|
7162 | this.column_++;
|
7163 | } else if (this.isExtCharacter(char0, char1)) {
|
7164 |
|
7165 |
|
7166 |
|
7167 |
|
7168 |
|
7169 | if (this.mode_ === 'popOn') {
|
7170 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
7171 | } else {
|
7172 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
7173 | }
|
7174 |
|
7175 |
|
7176 |
|
7177 |
|
7178 |
|
7179 | char0 = (char0 & 0x03) << 8;
|
7180 | text = getCharFromCode(char0 | char1);
|
7181 | this[this.mode_](packet.pts, text);
|
7182 | this.column_++;
|
7183 | } else if (this.isMidRowCode(char0, char1)) {
|
7184 |
|
7185 | this.clearFormatting(packet.pts);
|
7186 |
|
7187 |
|
7188 | this[this.mode_](packet.pts, ' ');
|
7189 | this.column_++;
|
7190 |
|
7191 | if ((char1 & 0xe) === 0xe) {
|
7192 | this.addFormatting(packet.pts, ['i']);
|
7193 | }
|
7194 |
|
7195 | if ((char1 & 0x1) === 0x1) {
|
7196 | this.addFormatting(packet.pts, ['u']);
|
7197 | }
|
7198 |
|
7199 | } else if (this.isOffsetControlCode(char0, char1)) {
|
7200 |
|
7201 |
|
7202 |
|
7203 |
|
7204 | this.column_ += char1 & 0x03;
|
7205 | } else if (this.isPAC(char0, char1)) {
|
7206 |
|
7207 |
|
7208 | var row = ROWS.indexOf(data & 0x1f20);
|
7209 |
|
7210 | if (this.mode_ === 'rollUp') {
|
7211 |
|
7212 |
|
7213 |
|
7214 | if (row - this.rollUpRows_ + 1 < 0) {
|
7215 | row = this.rollUpRows_ - 1;
|
7216 | }
|
7217 |
|
7218 | this.setRollUp(packet.pts, row);
|
7219 | }
|
7220 |
|
7221 | if (row !== this.row_) {
|
7222 |
|
7223 | this.clearFormatting(packet.pts);
|
7224 | this.row_ = row;
|
7225 | }
|
7226 |
|
7227 |
|
7228 |
|
7229 | if (char1 & 0x1 && this.formatting_.indexOf('u') === -1) {
|
7230 | this.addFormatting(packet.pts, ['u']);
|
7231 | }
|
7232 |
|
7233 | if ((data & 0x10) === 0x10) {
|
7234 |
|
7235 |
|
7236 |
|
7237 |
|
7238 | this.column_ = ((data & 0xe) >> 1) * 4;
|
7239 | }
|
7240 |
|
7241 | if (this.isColorPAC(char1)) {
|
7242 |
|
7243 |
|
7244 |
|
7245 |
|
7246 | if ((char1 & 0xe) === 0xe) {
|
7247 | this.addFormatting(packet.pts, ['i']);
|
7248 | }
|
7249 | }
|
7250 |
|
7251 | } else if (this.isNormalChar(char0)) {
|
7252 | if (char1 === 0x00) {
|
7253 | char1 = null;
|
7254 | }
|
7255 |
|
7256 | text = getCharFromCode(char0);
|
7257 | text += getCharFromCode(char1);
|
7258 | this[this.mode_](packet.pts, text);
|
7259 | this.column_ += text.length;
|
7260 | }
|
7261 |
|
7262 | };
|
7263 | };
|
7264 |
|
7265 | Cea608Stream.prototype = new stream();
|
7266 |
|
7267 |
|
7268 | Cea608Stream.prototype.flushDisplayed = function (pts) {
|
7269 | var content = this.displayed_
|
7270 | .map(function (row, index) {
|
7271 | try {
|
7272 | return row.trim();
|
7273 | } catch (e) {
|
7274 |
|
7275 |
|
7276 |
|
7277 | this.trigger('log', {
|
7278 | level: 'warn',
|
7279 | message: 'Skipping a malformed 608 caption at index ' + index + '.'
|
7280 | });
|
7281 | return '';
|
7282 | }
|
7283 | }, this)
|
7284 | .join('\n')
|
7285 | .replace(/^\n+|\n+$/g, '');
|
7286 |
|
7287 | if (content.length) {
|
7288 | this.trigger('data', {
|
7289 | startPts: this.startPts_,
|
7290 | endPts: pts,
|
7291 | text: content,
|
7292 | stream: this.name_
|
7293 | });
|
7294 | }
|
7295 | };
|
7296 | |
7297 |
|
7298 |
|
7299 |
|
7300 |
|
7301 | Cea608Stream.prototype.reset = function () {
|
7302 | this.mode_ = 'popOn';
|
7303 |
|
7304 |
|
7305 |
|
7306 |
|
7307 | this.topRow_ = 0;
|
7308 | this.startPts_ = 0;
|
7309 | this.displayed_ = createDisplayBuffer();
|
7310 | this.nonDisplayed_ = createDisplayBuffer();
|
7311 | this.lastControlCode_ = null;
|
7312 |
|
7313 | this.column_ = 0;
|
7314 | this.row_ = BOTTOM_ROW;
|
7315 | this.rollUpRows_ = 2;
|
7316 |
|
7317 | this.formatting_ = [];
|
7318 | };
|
7319 | |
7320 |
|
7321 |
|
7322 |
|
7323 |
|
7324 | Cea608Stream.prototype.setConstants = function () {
|
7325 |
|
7326 |
|
7327 |
|
7328 |
|
7329 |
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 |
|
7335 |
|
7336 |
|
7337 | if (this.dataChannel_ === 0) {
|
7338 | this.BASE_ = 0x10;
|
7339 | this.EXT_ = 0x11;
|
7340 | this.CONTROL_ = (0x14 | this.field_) << 8;
|
7341 | this.OFFSET_ = 0x17;
|
7342 | } else if (this.dataChannel_ === 1) {
|
7343 | this.BASE_ = 0x18;
|
7344 | this.EXT_ = 0x19;
|
7345 | this.CONTROL_ = (0x1c | this.field_) << 8;
|
7346 | this.OFFSET_ = 0x1f;
|
7347 | }
|
7348 |
|
7349 |
|
7350 |
|
7351 |
|
7352 |
|
7353 | this.PADDING_ = 0x0000;
|
7354 |
|
7355 | this.RESUME_CAPTION_LOADING_ = this.CONTROL_ | 0x20;
|
7356 | this.END_OF_CAPTION_ = this.CONTROL_ | 0x2f;
|
7357 |
|
7358 | this.ROLL_UP_2_ROWS_ = this.CONTROL_ | 0x25;
|
7359 | this.ROLL_UP_3_ROWS_ = this.CONTROL_ | 0x26;
|
7360 | this.ROLL_UP_4_ROWS_ = this.CONTROL_ | 0x27;
|
7361 | this.CARRIAGE_RETURN_ = this.CONTROL_ | 0x2d;
|
7362 |
|
7363 | this.RESUME_DIRECT_CAPTIONING_ = this.CONTROL_ | 0x29;
|
7364 |
|
7365 | this.BACKSPACE_ = this.CONTROL_ | 0x21;
|
7366 | this.ERASE_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2c;
|
7367 | this.ERASE_NON_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2e;
|
7368 | };
|
7369 | |
7370 |
|
7371 |
|
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 | Cea608Stream.prototype.isSpecialCharacter = function (char0, char1) {
|
7383 | return char0 === this.EXT_ && char1 >= 0x30 && char1 <= 0x3f;
|
7384 | };
|
7385 | |
7386 |
|
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 |
|
7394 |
|
7395 |
|
7396 |
|
7397 |
|
7398 | Cea608Stream.prototype.isExtCharacter = function (char0, char1) {
|
7399 | return (char0 === this.EXT_ + 1 || char0 === this.EXT_ + 2) && char1 >= 0x20 && char1 <= 0x3f;
|
7400 | };
|
7401 | |
7402 |
|
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 |
|
7408 |
|
7409 |
|
7410 |
|
7411 |
|
7412 |
|
7413 |
|
7414 | Cea608Stream.prototype.isMidRowCode = function (char0, char1) {
|
7415 | return char0 === this.EXT_ && char1 >= 0x20 && char1 <= 0x2f;
|
7416 | };
|
7417 | |
7418 |
|
7419 |
|
7420 |
|
7421 |
|
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 |
|
7428 |
|
7429 |
|
7430 | Cea608Stream.prototype.isOffsetControlCode = function (char0, char1) {
|
7431 | return char0 === this.OFFSET_ && char1 >= 0x21 && char1 <= 0x23;
|
7432 | };
|
7433 | |
7434 |
|
7435 |
|
7436 |
|
7437 |
|
7438 |
|
7439 |
|
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 | Cea608Stream.prototype.isPAC = function (char0, char1) {
|
7447 | return char0 >= this.BASE_ && char0 < this.BASE_ + 8 && char1 >= 0x40 && char1 <= 0x7f;
|
7448 | };
|
7449 | |
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 | Cea608Stream.prototype.isColorPAC = function (char1) {
|
7461 | return char1 >= 0x40 && char1 <= 0x4f || char1 >= 0x60 && char1 <= 0x7f;
|
7462 | };
|
7463 | |
7464 |
|
7465 |
|
7466 |
|
7467 |
|
7468 |
|
7469 |
|
7470 |
|
7471 |
|
7472 |
|
7473 | Cea608Stream.prototype.isNormalChar = function (char) {
|
7474 | return char >= 0x20 && char <= 0x7f;
|
7475 | };
|
7476 | |
7477 |
|
7478 |
|
7479 |
|
7480 |
|
7481 |
|
7482 |
|
7483 |
|
7484 |
|
7485 | Cea608Stream.prototype.setRollUp = function (pts, newBaseRow) {
|
7486 |
|
7487 | if (this.mode_ !== 'rollUp') {
|
7488 | this.row_ = BOTTOM_ROW;
|
7489 | this.mode_ = 'rollUp';
|
7490 |
|
7491 | this.flushDisplayed(pts);
|
7492 | this.nonDisplayed_ = createDisplayBuffer();
|
7493 | this.displayed_ = createDisplayBuffer();
|
7494 | }
|
7495 |
|
7496 | if (newBaseRow !== undefined && newBaseRow !== this.row_) {
|
7497 |
|
7498 | for (var i = 0; i < this.rollUpRows_; i++) {
|
7499 | this.displayed_[newBaseRow - i] = this.displayed_[this.row_ - i];
|
7500 | this.displayed_[this.row_ - i] = '';
|
7501 | }
|
7502 | }
|
7503 |
|
7504 | if (newBaseRow === undefined) {
|
7505 | newBaseRow = this.row_;
|
7506 | }
|
7507 |
|
7508 | this.topRow_ = newBaseRow - this.rollUpRows_ + 1;
|
7509 | };
|
7510 |
|
7511 |
|
7512 |
|
7513 | Cea608Stream.prototype.addFormatting = function (pts, format) {
|
7514 | this.formatting_ = this.formatting_.concat(format);
|
7515 | var text = format.reduce(function (text, format) {
|
7516 | return text + '<' + format + '>';
|
7517 | }, '');
|
7518 | this[this.mode_](pts, text);
|
7519 | };
|
7520 |
|
7521 |
|
7522 |
|
7523 | Cea608Stream.prototype.clearFormatting = function (pts) {
|
7524 | if (!this.formatting_.length) {
|
7525 | return;
|
7526 | }
|
7527 |
|
7528 | var text = this.formatting_.reverse().reduce(function (text, format) {
|
7529 | return text + '</' + format + '>';
|
7530 | }, '');
|
7531 | this.formatting_ = [];
|
7532 | this[this.mode_](pts, text);
|
7533 | };
|
7534 |
|
7535 |
|
7536 | Cea608Stream.prototype.popOn = function (pts, text) {
|
7537 | var baseRow = this.nonDisplayed_[this.row_];
|
7538 |
|
7539 | baseRow += text;
|
7540 | this.nonDisplayed_[this.row_] = baseRow;
|
7541 | };
|
7542 |
|
7543 | Cea608Stream.prototype.rollUp = function (pts, text) {
|
7544 | var baseRow = this.displayed_[this.row_];
|
7545 | baseRow += text;
|
7546 | this.displayed_[this.row_] = baseRow;
|
7547 | };
|
7548 |
|
7549 | Cea608Stream.prototype.shiftRowsUp_ = function () {
|
7550 | var i;
|
7551 |
|
7552 | for (i = 0; i < this.topRow_; i++) {
|
7553 | this.displayed_[i] = '';
|
7554 | }
|
7555 |
|
7556 | for (i = this.row_ + 1; i < BOTTOM_ROW + 1; i++) {
|
7557 | this.displayed_[i] = '';
|
7558 | }
|
7559 |
|
7560 |
|
7561 | for (i = this.topRow_; i < this.row_; i++) {
|
7562 | this.displayed_[i] = this.displayed_[i + 1];
|
7563 | }
|
7564 |
|
7565 |
|
7566 | this.displayed_[this.row_] = '';
|
7567 | };
|
7568 |
|
7569 | Cea608Stream.prototype.paintOn = function (pts, text) {
|
7570 | var baseRow = this.displayed_[this.row_];
|
7571 | baseRow += text;
|
7572 | this.displayed_[this.row_] = baseRow;
|
7573 | };
|
7574 |
|
7575 |
|
7576 | var captionStream = {
|
7577 | CaptionStream: CaptionStream$1,
|
7578 | Cea608Stream: Cea608Stream,
|
7579 | Cea708Stream: Cea708Stream
|
7580 | };
|
7581 | |
7582 |
|
7583 |
|
7584 |
|
7585 |
|
7586 |
|
7587 |
|
7588 | var streamTypes = {
|
7589 | H264_STREAM_TYPE: 0x1B,
|
7590 | ADTS_STREAM_TYPE: 0x0F,
|
7591 | METADATA_STREAM_TYPE: 0x15
|
7592 | };
|
7593 | var MAX_TS = 8589934592;
|
7594 | var RO_THRESH = 4294967296;
|
7595 | var TYPE_SHARED = 'shared';
|
7596 |
|
7597 | var handleRollover$1 = function handleRollover(value, reference) {
|
7598 | var direction = 1;
|
7599 |
|
7600 | if (value > reference) {
|
7601 |
|
7602 |
|
7603 |
|
7604 |
|
7605 |
|
7606 |
|
7607 |
|
7608 | direction = -1;
|
7609 | }
|
7610 |
|
7611 |
|
7612 |
|
7613 | while (Math.abs(reference - value) > RO_THRESH) {
|
7614 | value += direction * MAX_TS;
|
7615 | }
|
7616 |
|
7617 | return value;
|
7618 | };
|
7619 |
|
7620 | var TimestampRolloverStream$1 = function TimestampRolloverStream(type) {
|
7621 | var lastDTS, referenceDTS;
|
7622 | TimestampRolloverStream.prototype.init.call(this);
|
7623 |
|
7624 |
|
7625 |
|
7626 | this.type_ = type || TYPE_SHARED;
|
7627 |
|
7628 | this.push = function (data) {
|
7629 |
|
7630 |
|
7631 | if (this.type_ !== TYPE_SHARED && data.type !== this.type_) {
|
7632 | return;
|
7633 | }
|
7634 |
|
7635 | if (referenceDTS === undefined) {
|
7636 | referenceDTS = data.dts;
|
7637 | }
|
7638 |
|
7639 | data.dts = handleRollover$1(data.dts, referenceDTS);
|
7640 | data.pts = handleRollover$1(data.pts, referenceDTS);
|
7641 | lastDTS = data.dts;
|
7642 | this.trigger('data', data);
|
7643 | };
|
7644 |
|
7645 | this.flush = function () {
|
7646 | referenceDTS = lastDTS;
|
7647 | this.trigger('done');
|
7648 | };
|
7649 |
|
7650 | this.endTimeline = function () {
|
7651 | this.flush();
|
7652 | this.trigger('endedtimeline');
|
7653 | };
|
7654 |
|
7655 | this.discontinuity = function () {
|
7656 | referenceDTS = void 0;
|
7657 | lastDTS = void 0;
|
7658 | };
|
7659 |
|
7660 | this.reset = function () {
|
7661 | this.discontinuity();
|
7662 | this.trigger('reset');
|
7663 | };
|
7664 | };
|
7665 |
|
7666 | TimestampRolloverStream$1.prototype = new stream();
|
7667 | var timestampRolloverStream = {
|
7668 | TimestampRolloverStream: TimestampRolloverStream$1,
|
7669 | handleRollover: handleRollover$1
|
7670 | };
|
7671 |
|
7672 | var percentEncode$1 = function percentEncode(bytes, start, end) {
|
7673 | var i,
|
7674 | result = '';
|
7675 |
|
7676 | for (i = start; i < end; i++) {
|
7677 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
7678 | }
|
7679 |
|
7680 | return result;
|
7681 | },
|
7682 |
|
7683 |
|
7684 | parseUtf8 = function parseUtf8(bytes, start, end) {
|
7685 | return decodeURIComponent(percentEncode$1(bytes, start, end));
|
7686 | },
|
7687 |
|
7688 |
|
7689 | parseIso88591$1 = function parseIso88591(bytes, start, end) {
|
7690 | return unescape(percentEncode$1(bytes, start, end));
|
7691 | },
|
7692 | parseSyncSafeInteger$1 = function parseSyncSafeInteger(data) {
|
7693 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
7694 | },
|
7695 | tagParsers = {
|
7696 | TXXX: function TXXX(tag) {
|
7697 | var i;
|
7698 |
|
7699 | if (tag.data[0] !== 3) {
|
7700 |
|
7701 | return;
|
7702 | }
|
7703 |
|
7704 | for (i = 1; i < tag.data.length; i++) {
|
7705 | if (tag.data[i] === 0) {
|
7706 |
|
7707 | tag.description = parseUtf8(tag.data, 1, i);
|
7708 |
|
7709 | tag.value = parseUtf8(tag.data, i + 1, tag.data.length).replace(/\0*$/, '');
|
7710 | break;
|
7711 | }
|
7712 | }
|
7713 |
|
7714 | tag.data = tag.value;
|
7715 | },
|
7716 | WXXX: function WXXX(tag) {
|
7717 | var i;
|
7718 |
|
7719 | if (tag.data[0] !== 3) {
|
7720 |
|
7721 | return;
|
7722 | }
|
7723 |
|
7724 | for (i = 1; i < tag.data.length; i++) {
|
7725 | if (tag.data[i] === 0) {
|
7726 |
|
7727 | tag.description = parseUtf8(tag.data, 1, i);
|
7728 | tag.url = parseUtf8(tag.data, i + 1, tag.data.length);
|
7729 | break;
|
7730 | }
|
7731 | }
|
7732 | },
|
7733 | PRIV: function PRIV(tag) {
|
7734 | var i;
|
7735 |
|
7736 | for (i = 0; i < tag.data.length; i++) {
|
7737 | if (tag.data[i] === 0) {
|
7738 |
|
7739 | tag.owner = parseIso88591$1(tag.data, 0, i);
|
7740 | break;
|
7741 | }
|
7742 | }
|
7743 |
|
7744 | tag.privateData = tag.data.subarray(i + 1);
|
7745 | tag.data = tag.privateData;
|
7746 | }
|
7747 | },
|
7748 | _MetadataStream;
|
7749 |
|
7750 | _MetadataStream = function MetadataStream(options) {
|
7751 | var settings = {
|
7752 |
|
7753 |
|
7754 |
|
7755 | descriptor: options && options.descriptor
|
7756 | },
|
7757 |
|
7758 | tagSize = 0,
|
7759 |
|
7760 | buffer = [],
|
7761 |
|
7762 | bufferSize = 0,
|
7763 | i;
|
7764 |
|
7765 | _MetadataStream.prototype.init.call(this);
|
7766 |
|
7767 |
|
7768 |
|
7769 | this.dispatchType = streamTypes.METADATA_STREAM_TYPE.toString(16);
|
7770 |
|
7771 | if (settings.descriptor) {
|
7772 | for (i = 0; i < settings.descriptor.length; i++) {
|
7773 | this.dispatchType += ('00' + settings.descriptor[i].toString(16)).slice(-2);
|
7774 | }
|
7775 | }
|
7776 |
|
7777 | this.push = function (chunk) {
|
7778 | var tag, frameStart, frameSize, frame, i, frameHeader;
|
7779 |
|
7780 | if (chunk.type !== 'timed-metadata') {
|
7781 | return;
|
7782 | }
|
7783 |
|
7784 |
|
7785 |
|
7786 |
|
7787 | if (chunk.dataAlignmentIndicator) {
|
7788 | bufferSize = 0;
|
7789 | buffer.length = 0;
|
7790 | }
|
7791 |
|
7792 |
|
7793 | 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))) {
|
7794 | this.trigger('log', {
|
7795 | level: 'warn',
|
7796 | message: 'Skipping unrecognized metadata packet'
|
7797 | });
|
7798 | return;
|
7799 | }
|
7800 |
|
7801 |
|
7802 | buffer.push(chunk);
|
7803 | bufferSize += chunk.data.byteLength;
|
7804 |
|
7805 | if (buffer.length === 1) {
|
7806 |
|
7807 |
|
7808 |
|
7809 |
|
7810 | tagSize = parseSyncSafeInteger$1(chunk.data.subarray(6, 10));
|
7811 |
|
7812 |
|
7813 | tagSize += 10;
|
7814 | }
|
7815 |
|
7816 |
|
7817 | if (bufferSize < tagSize) {
|
7818 | return;
|
7819 | }
|
7820 |
|
7821 |
|
7822 | tag = {
|
7823 | data: new Uint8Array(tagSize),
|
7824 | frames: [],
|
7825 | pts: buffer[0].pts,
|
7826 | dts: buffer[0].dts
|
7827 | };
|
7828 |
|
7829 | for (i = 0; i < tagSize;) {
|
7830 | tag.data.set(buffer[0].data.subarray(0, tagSize - i), i);
|
7831 | i += buffer[0].data.byteLength;
|
7832 | bufferSize -= buffer[0].data.byteLength;
|
7833 | buffer.shift();
|
7834 | }
|
7835 |
|
7836 |
|
7837 | frameStart = 10;
|
7838 |
|
7839 | if (tag.data[5] & 0x40) {
|
7840 |
|
7841 | frameStart += 4;
|
7842 |
|
7843 | frameStart += parseSyncSafeInteger$1(tag.data.subarray(10, 14));
|
7844 |
|
7845 | tagSize -= parseSyncSafeInteger$1(tag.data.subarray(16, 20));
|
7846 | }
|
7847 |
|
7848 |
|
7849 |
|
7850 | do {
|
7851 |
|
7852 | frameSize = parseSyncSafeInteger$1(tag.data.subarray(frameStart + 4, frameStart + 8));
|
7853 |
|
7854 | if (frameSize < 1) {
|
7855 | this.trigger('log', {
|
7856 | level: 'warn',
|
7857 | message: 'Malformed ID3 frame encountered. Skipping metadata parsing.'
|
7858 | });
|
7859 | return;
|
7860 | }
|
7861 |
|
7862 | frameHeader = String.fromCharCode(tag.data[frameStart], tag.data[frameStart + 1], tag.data[frameStart + 2], tag.data[frameStart + 3]);
|
7863 | frame = {
|
7864 | id: frameHeader,
|
7865 | data: tag.data.subarray(frameStart + 10, frameStart + frameSize + 10)
|
7866 | };
|
7867 | frame.key = frame.id;
|
7868 |
|
7869 | if (tagParsers[frame.id]) {
|
7870 | tagParsers[frame.id](frame);
|
7871 |
|
7872 |
|
7873 | if (frame.owner === 'com.apple.streaming.transportStreamTimestamp') {
|
7874 | var d = frame.data,
|
7875 | size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
7876 | size *= 4;
|
7877 | size += d[7] & 0x03;
|
7878 | frame.timeStamp = size;
|
7879 |
|
7880 |
|
7881 |
|
7882 |
|
7883 | if (tag.pts === undefined && tag.dts === undefined) {
|
7884 | tag.pts = frame.timeStamp;
|
7885 | tag.dts = frame.timeStamp;
|
7886 | }
|
7887 |
|
7888 | this.trigger('timestamp', frame);
|
7889 | }
|
7890 | }
|
7891 |
|
7892 | tag.frames.push(frame);
|
7893 | frameStart += 10;
|
7894 |
|
7895 | frameStart += frameSize;
|
7896 | } while (frameStart < tagSize);
|
7897 |
|
7898 | this.trigger('data', tag);
|
7899 | };
|
7900 | };
|
7901 |
|
7902 | _MetadataStream.prototype = new stream();
|
7903 | var metadataStream = _MetadataStream;
|
7904 | var TimestampRolloverStream = timestampRolloverStream.TimestampRolloverStream;
|
7905 |
|
7906 | var _TransportPacketStream, _TransportParseStream, _ElementaryStream;
|
7907 |
|
7908 |
|
7909 | var MP2T_PACKET_LENGTH$1 = 188,
|
7910 |
|
7911 | SYNC_BYTE$1 = 0x47;
|
7912 | |
7913 |
|
7914 |
|
7915 |
|
7916 |
|
7917 | _TransportPacketStream = function TransportPacketStream() {
|
7918 | var buffer = new Uint8Array(MP2T_PACKET_LENGTH$1),
|
7919 | bytesInBuffer = 0;
|
7920 |
|
7921 | _TransportPacketStream.prototype.init.call(this);
|
7922 |
|
7923 | |
7924 |
|
7925 |
|
7926 |
|
7927 |
|
7928 | this.push = function (bytes) {
|
7929 | var startIndex = 0,
|
7930 | endIndex = MP2T_PACKET_LENGTH$1,
|
7931 | everything;
|
7932 |
|
7933 |
|
7934 | if (bytesInBuffer) {
|
7935 | everything = new Uint8Array(bytes.byteLength + bytesInBuffer);
|
7936 | everything.set(buffer.subarray(0, bytesInBuffer));
|
7937 | everything.set(bytes, bytesInBuffer);
|
7938 | bytesInBuffer = 0;
|
7939 | } else {
|
7940 | everything = bytes;
|
7941 | }
|
7942 |
|
7943 |
|
7944 | while (endIndex < everything.byteLength) {
|
7945 |
|
7946 | if (everything[startIndex] === SYNC_BYTE$1 && everything[endIndex] === SYNC_BYTE$1) {
|
7947 |
|
7948 |
|
7949 | this.trigger('data', everything.subarray(startIndex, endIndex));
|
7950 | startIndex += MP2T_PACKET_LENGTH$1;
|
7951 | endIndex += MP2T_PACKET_LENGTH$1;
|
7952 | continue;
|
7953 | }
|
7954 |
|
7955 |
|
7956 |
|
7957 |
|
7958 | startIndex++;
|
7959 | endIndex++;
|
7960 | }
|
7961 |
|
7962 |
|
7963 |
|
7964 |
|
7965 | if (startIndex < everything.byteLength) {
|
7966 | buffer.set(everything.subarray(startIndex), 0);
|
7967 | bytesInBuffer = everything.byteLength - startIndex;
|
7968 | }
|
7969 | };
|
7970 | |
7971 |
|
7972 |
|
7973 |
|
7974 |
|
7975 | this.flush = function () {
|
7976 |
|
7977 |
|
7978 |
|
7979 | if (bytesInBuffer === MP2T_PACKET_LENGTH$1 && buffer[0] === SYNC_BYTE$1) {
|
7980 | this.trigger('data', buffer);
|
7981 | bytesInBuffer = 0;
|
7982 | }
|
7983 |
|
7984 | this.trigger('done');
|
7985 | };
|
7986 |
|
7987 | this.endTimeline = function () {
|
7988 | this.flush();
|
7989 | this.trigger('endedtimeline');
|
7990 | };
|
7991 |
|
7992 | this.reset = function () {
|
7993 | bytesInBuffer = 0;
|
7994 | this.trigger('reset');
|
7995 | };
|
7996 | };
|
7997 |
|
7998 | _TransportPacketStream.prototype = new stream();
|
7999 | |
8000 |
|
8001 |
|
8002 |
|
8003 |
|
8004 | _TransportParseStream = function TransportParseStream() {
|
8005 | var parsePsi, parsePat, parsePmt, self;
|
8006 |
|
8007 | _TransportParseStream.prototype.init.call(this);
|
8008 |
|
8009 | self = this;
|
8010 | this.packetsWaitingForPmt = [];
|
8011 | this.programMapTable = undefined;
|
8012 |
|
8013 | parsePsi = function parsePsi(payload, psi) {
|
8014 | var offset = 0;
|
8015 |
|
8016 |
|
8017 |
|
8018 |
|
8019 |
|
8020 |
|
8021 | if (psi.payloadUnitStartIndicator) {
|
8022 | offset += payload[offset] + 1;
|
8023 | }
|
8024 |
|
8025 | if (psi.type === 'pat') {
|
8026 | parsePat(payload.subarray(offset), psi);
|
8027 | } else {
|
8028 | parsePmt(payload.subarray(offset), psi);
|
8029 | }
|
8030 | };
|
8031 |
|
8032 | parsePat = function parsePat(payload, pat) {
|
8033 | pat.section_number = payload[7];
|
8034 |
|
8035 | pat.last_section_number = payload[8];
|
8036 |
|
8037 |
|
8038 | self.pmtPid = (payload[10] & 0x1F) << 8 | payload[11];
|
8039 | pat.pmtPid = self.pmtPid;
|
8040 | };
|
8041 | |
8042 |
|
8043 |
|
8044 |
|
8045 |
|
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 |
|
8051 | parsePmt = function parsePmt(payload, pmt) {
|
8052 | var sectionLength, tableEnd, programInfoLength, offset;
|
8053 |
|
8054 |
|
8055 |
|
8056 |
|
8057 |
|
8058 | if (!(payload[5] & 0x01)) {
|
8059 | return;
|
8060 | }
|
8061 |
|
8062 |
|
8063 | self.programMapTable = {
|
8064 | video: null,
|
8065 | audio: null,
|
8066 | 'timed-metadata': {}
|
8067 | };
|
8068 |
|
8069 | sectionLength = (payload[1] & 0x0f) << 8 | payload[2];
|
8070 | tableEnd = 3 + sectionLength - 4;
|
8071 |
|
8072 |
|
8073 | programInfoLength = (payload[10] & 0x0f) << 8 | payload[11];
|
8074 |
|
8075 | offset = 12 + programInfoLength;
|
8076 |
|
8077 | while (offset < tableEnd) {
|
8078 | var streamType = payload[offset];
|
8079 | var pid = (payload[offset + 1] & 0x1F) << 8 | payload[offset + 2];
|
8080 |
|
8081 |
|
8082 |
|
8083 | if (streamType === streamTypes.H264_STREAM_TYPE && self.programMapTable.video === null) {
|
8084 | self.programMapTable.video = pid;
|
8085 | } else if (streamType === streamTypes.ADTS_STREAM_TYPE && self.programMapTable.audio === null) {
|
8086 | self.programMapTable.audio = pid;
|
8087 | } else if (streamType === streamTypes.METADATA_STREAM_TYPE) {
|
8088 |
|
8089 | self.programMapTable['timed-metadata'][pid] = streamType;
|
8090 | }
|
8091 |
|
8092 |
|
8093 |
|
8094 | offset += ((payload[offset + 3] & 0x0F) << 8 | payload[offset + 4]) + 5;
|
8095 | }
|
8096 |
|
8097 |
|
8098 | pmt.programMapTable = self.programMapTable;
|
8099 | };
|
8100 | |
8101 |
|
8102 |
|
8103 |
|
8104 |
|
8105 | this.push = function (packet) {
|
8106 | var result = {},
|
8107 | offset = 4;
|
8108 | result.payloadUnitStartIndicator = !!(packet[1] & 0x40);
|
8109 |
|
8110 | result.pid = packet[1] & 0x1f;
|
8111 | result.pid <<= 8;
|
8112 | result.pid |= packet[2];
|
8113 |
|
8114 |
|
8115 |
|
8116 |
|
8117 |
|
8118 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
8119 | offset += packet[offset] + 1;
|
8120 | }
|
8121 |
|
8122 |
|
8123 | if (result.pid === 0) {
|
8124 | result.type = 'pat';
|
8125 | parsePsi(packet.subarray(offset), result);
|
8126 | this.trigger('data', result);
|
8127 | } else if (result.pid === this.pmtPid) {
|
8128 | result.type = 'pmt';
|
8129 | parsePsi(packet.subarray(offset), result);
|
8130 | this.trigger('data', result);
|
8131 |
|
8132 | while (this.packetsWaitingForPmt.length) {
|
8133 | this.processPes_.apply(this, this.packetsWaitingForPmt.shift());
|
8134 | }
|
8135 | } else if (this.programMapTable === undefined) {
|
8136 |
|
8137 |
|
8138 | this.packetsWaitingForPmt.push([packet, offset, result]);
|
8139 | } else {
|
8140 | this.processPes_(packet, offset, result);
|
8141 | }
|
8142 | };
|
8143 |
|
8144 | this.processPes_ = function (packet, offset, result) {
|
8145 |
|
8146 | if (result.pid === this.programMapTable.video) {
|
8147 | result.streamType = streamTypes.H264_STREAM_TYPE;
|
8148 | } else if (result.pid === this.programMapTable.audio) {
|
8149 | result.streamType = streamTypes.ADTS_STREAM_TYPE;
|
8150 | } else {
|
8151 |
|
8152 |
|
8153 | result.streamType = this.programMapTable['timed-metadata'][result.pid];
|
8154 | }
|
8155 |
|
8156 | result.type = 'pes';
|
8157 | result.data = packet.subarray(offset);
|
8158 | this.trigger('data', result);
|
8159 | };
|
8160 | };
|
8161 |
|
8162 | _TransportParseStream.prototype = new stream();
|
8163 | _TransportParseStream.STREAM_TYPES = {
|
8164 | h264: 0x1b,
|
8165 | adts: 0x0f
|
8166 | };
|
8167 | |
8168 |
|
8169 |
|
8170 |
|
8171 |
|
8172 |
|
8173 |
|
8174 |
|
8175 |
|
8176 | _ElementaryStream = function ElementaryStream() {
|
8177 | var self = this,
|
8178 | segmentHadPmt = false,
|
8179 |
|
8180 | video = {
|
8181 | data: [],
|
8182 | size: 0
|
8183 | },
|
8184 | audio = {
|
8185 | data: [],
|
8186 | size: 0
|
8187 | },
|
8188 | timedMetadata = {
|
8189 | data: [],
|
8190 | size: 0
|
8191 | },
|
8192 | programMapTable,
|
8193 | parsePes = function parsePes(payload, pes) {
|
8194 | var ptsDtsFlags;
|
8195 | var startPrefix = payload[0] << 16 | payload[1] << 8 | payload[2];
|
8196 |
|
8197 | pes.data = new Uint8Array();
|
8198 |
|
8199 |
|
8200 |
|
8201 | if (startPrefix !== 1) {
|
8202 | return;
|
8203 | }
|
8204 |
|
8205 |
|
8206 | pes.packetLength = 6 + (payload[4] << 8 | payload[5]);
|
8207 |
|
8208 | pes.dataAlignmentIndicator = (payload[6] & 0x04) !== 0;
|
8209 |
|
8210 |
|
8211 |
|
8212 | ptsDtsFlags = payload[7];
|
8213 |
|
8214 |
|
8215 |
|
8216 |
|
8217 |
|
8218 |
|
8219 |
|
8220 |
|
8221 | if (ptsDtsFlags & 0xC0) {
|
8222 |
|
8223 |
|
8224 |
|
8225 | pes.pts = (payload[9] & 0x0E) << 27 | (payload[10] & 0xFF) << 20 | (payload[11] & 0xFE) << 12 | (payload[12] & 0xFF) << 5 | (payload[13] & 0xFE) >>> 3;
|
8226 | pes.pts *= 4;
|
8227 |
|
8228 | pes.pts += (payload[13] & 0x06) >>> 1;
|
8229 |
|
8230 | pes.dts = pes.pts;
|
8231 |
|
8232 | if (ptsDtsFlags & 0x40) {
|
8233 | pes.dts = (payload[14] & 0x0E) << 27 | (payload[15] & 0xFF) << 20 | (payload[16] & 0xFE) << 12 | (payload[17] & 0xFF) << 5 | (payload[18] & 0xFE) >>> 3;
|
8234 | pes.dts *= 4;
|
8235 |
|
8236 | pes.dts += (payload[18] & 0x06) >>> 1;
|
8237 | }
|
8238 | }
|
8239 |
|
8240 |
|
8241 |
|
8242 |
|
8243 | pes.data = payload.subarray(9 + payload[8]);
|
8244 | },
|
8245 |
|
8246 | |
8247 |
|
8248 |
|
8249 | flushStream = function flushStream(stream, type, forceFlush) {
|
8250 | var packetData = new Uint8Array(stream.size),
|
8251 | event = {
|
8252 | type: type
|
8253 | },
|
8254 | i = 0,
|
8255 | offset = 0,
|
8256 | packetFlushable = false,
|
8257 | fragment;
|
8258 |
|
8259 |
|
8260 | if (!stream.data.length || stream.size < 9) {
|
8261 | return;
|
8262 | }
|
8263 |
|
8264 | event.trackId = stream.data[0].pid;
|
8265 |
|
8266 | for (i = 0; i < stream.data.length; i++) {
|
8267 | fragment = stream.data[i];
|
8268 | packetData.set(fragment.data, offset);
|
8269 | offset += fragment.data.byteLength;
|
8270 | }
|
8271 |
|
8272 |
|
8273 | parsePes(packetData, event);
|
8274 |
|
8275 |
|
8276 | packetFlushable = type === 'video' || event.packetLength <= stream.size;
|
8277 |
|
8278 | if (forceFlush || packetFlushable) {
|
8279 | stream.size = 0;
|
8280 | stream.data.length = 0;
|
8281 | }
|
8282 |
|
8283 |
|
8284 |
|
8285 | if (packetFlushable) {
|
8286 | self.trigger('data', event);
|
8287 | }
|
8288 | };
|
8289 |
|
8290 | _ElementaryStream.prototype.init.call(this);
|
8291 | |
8292 |
|
8293 |
|
8294 |
|
8295 |
|
8296 |
|
8297 | this.push = function (data) {
|
8298 | ({
|
8299 | pat: function pat() {
|
8300 |
|
8301 | },
|
8302 | pes: function pes() {
|
8303 | var stream, streamType;
|
8304 |
|
8305 | switch (data.streamType) {
|
8306 | case streamTypes.H264_STREAM_TYPE:
|
8307 | stream = video;
|
8308 | streamType = 'video';
|
8309 | break;
|
8310 |
|
8311 | case streamTypes.ADTS_STREAM_TYPE:
|
8312 | stream = audio;
|
8313 | streamType = 'audio';
|
8314 | break;
|
8315 |
|
8316 | case streamTypes.METADATA_STREAM_TYPE:
|
8317 | stream = timedMetadata;
|
8318 | streamType = 'timed-metadata';
|
8319 | break;
|
8320 |
|
8321 | default:
|
8322 |
|
8323 | return;
|
8324 | }
|
8325 |
|
8326 |
|
8327 |
|
8328 | if (data.payloadUnitStartIndicator) {
|
8329 | flushStream(stream, streamType, true);
|
8330 | }
|
8331 |
|
8332 |
|
8333 |
|
8334 | stream.data.push(data);
|
8335 | stream.size += data.data.byteLength;
|
8336 | },
|
8337 | pmt: function pmt() {
|
8338 | var event = {
|
8339 | type: 'metadata',
|
8340 | tracks: []
|
8341 | };
|
8342 | programMapTable = data.programMapTable;
|
8343 |
|
8344 | if (programMapTable.video !== null) {
|
8345 | event.tracks.push({
|
8346 | timelineStartInfo: {
|
8347 | baseMediaDecodeTime: 0
|
8348 | },
|
8349 | id: +programMapTable.video,
|
8350 | codec: 'avc',
|
8351 | type: 'video'
|
8352 | });
|
8353 | }
|
8354 |
|
8355 | if (programMapTable.audio !== null) {
|
8356 | event.tracks.push({
|
8357 | timelineStartInfo: {
|
8358 | baseMediaDecodeTime: 0
|
8359 | },
|
8360 | id: +programMapTable.audio,
|
8361 | codec: 'adts',
|
8362 | type: 'audio'
|
8363 | });
|
8364 | }
|
8365 |
|
8366 | segmentHadPmt = true;
|
8367 | self.trigger('data', event);
|
8368 | }
|
8369 | })[data.type]();
|
8370 | };
|
8371 |
|
8372 | this.reset = function () {
|
8373 | video.size = 0;
|
8374 | video.data.length = 0;
|
8375 | audio.size = 0;
|
8376 | audio.data.length = 0;
|
8377 | this.trigger('reset');
|
8378 | };
|
8379 | |
8380 |
|
8381 |
|
8382 |
|
8383 |
|
8384 |
|
8385 |
|
8386 |
|
8387 |
|
8388 |
|
8389 |
|
8390 | this.flushStreams_ = function () {
|
8391 |
|
8392 |
|
8393 | flushStream(video, 'video');
|
8394 | flushStream(audio, 'audio');
|
8395 | flushStream(timedMetadata, 'timed-metadata');
|
8396 | };
|
8397 |
|
8398 | this.flush = function () {
|
8399 |
|
8400 |
|
8401 |
|
8402 | if (!segmentHadPmt && programMapTable) {
|
8403 | var pmt = {
|
8404 | type: 'metadata',
|
8405 | tracks: []
|
8406 | };
|
8407 |
|
8408 | if (programMapTable.video !== null) {
|
8409 | pmt.tracks.push({
|
8410 | timelineStartInfo: {
|
8411 | baseMediaDecodeTime: 0
|
8412 | },
|
8413 | id: +programMapTable.video,
|
8414 | codec: 'avc',
|
8415 | type: 'video'
|
8416 | });
|
8417 | }
|
8418 |
|
8419 | if (programMapTable.audio !== null) {
|
8420 | pmt.tracks.push({
|
8421 | timelineStartInfo: {
|
8422 | baseMediaDecodeTime: 0
|
8423 | },
|
8424 | id: +programMapTable.audio,
|
8425 | codec: 'adts',
|
8426 | type: 'audio'
|
8427 | });
|
8428 | }
|
8429 |
|
8430 | self.trigger('data', pmt);
|
8431 | }
|
8432 |
|
8433 | segmentHadPmt = false;
|
8434 | this.flushStreams_();
|
8435 | this.trigger('done');
|
8436 | };
|
8437 | };
|
8438 |
|
8439 | _ElementaryStream.prototype = new stream();
|
8440 | var m2ts = {
|
8441 | PAT_PID: 0x0000,
|
8442 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH$1,
|
8443 | TransportPacketStream: _TransportPacketStream,
|
8444 | TransportParseStream: _TransportParseStream,
|
8445 | ElementaryStream: _ElementaryStream,
|
8446 | TimestampRolloverStream: TimestampRolloverStream,
|
8447 | CaptionStream: captionStream.CaptionStream,
|
8448 | Cea608Stream: captionStream.Cea608Stream,
|
8449 | Cea708Stream: captionStream.Cea708Stream,
|
8450 | MetadataStream: metadataStream
|
8451 | };
|
8452 |
|
8453 | for (var type in streamTypes) {
|
8454 | if (streamTypes.hasOwnProperty(type)) {
|
8455 | m2ts[type] = streamTypes[type];
|
8456 | }
|
8457 | }
|
8458 |
|
8459 | var m2ts_1 = m2ts;
|
8460 | var ONE_SECOND_IN_TS$2 = clock.ONE_SECOND_IN_TS;
|
8461 |
|
8462 | var _AdtsStream;
|
8463 |
|
8464 | var ADTS_SAMPLING_FREQUENCIES$1 = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
8465 | |
8466 |
|
8467 |
|
8468 |
|
8469 |
|
8470 |
|
8471 |
|
8472 |
|
8473 |
|
8474 | _AdtsStream = function AdtsStream(handlePartialSegments) {
|
8475 | var buffer,
|
8476 | frameNum = 0;
|
8477 |
|
8478 | _AdtsStream.prototype.init.call(this);
|
8479 |
|
8480 | this.skipWarn_ = function (start, end) {
|
8481 | this.trigger('log', {
|
8482 | level: 'warn',
|
8483 | message: "adts skiping bytes " + start + " to " + end + " in frame " + frameNum + " outside syncword"
|
8484 | });
|
8485 | };
|
8486 |
|
8487 | this.push = function (packet) {
|
8488 | var i = 0,
|
8489 | frameLength,
|
8490 | protectionSkipBytes,
|
8491 | oldBuffer,
|
8492 | sampleCount,
|
8493 | adtsFrameDuration;
|
8494 |
|
8495 | if (!handlePartialSegments) {
|
8496 | frameNum = 0;
|
8497 | }
|
8498 |
|
8499 | if (packet.type !== 'audio') {
|
8500 |
|
8501 | return;
|
8502 | }
|
8503 |
|
8504 |
|
8505 |
|
8506 | if (buffer && buffer.length) {
|
8507 | oldBuffer = buffer;
|
8508 | buffer = new Uint8Array(oldBuffer.byteLength + packet.data.byteLength);
|
8509 | buffer.set(oldBuffer);
|
8510 | buffer.set(packet.data, oldBuffer.byteLength);
|
8511 | } else {
|
8512 | buffer = packet.data;
|
8513 | }
|
8514 |
|
8515 |
|
8516 |
|
8517 | var skip;
|
8518 |
|
8519 |
|
8520 | while (i + 7 < buffer.length) {
|
8521 |
|
8522 | if (buffer[i] !== 0xFF || (buffer[i + 1] & 0xF6) !== 0xF0) {
|
8523 | if (typeof skip !== 'number') {
|
8524 | skip = i;
|
8525 | }
|
8526 |
|
8527 |
|
8528 |
|
8529 | i++;
|
8530 | continue;
|
8531 | }
|
8532 |
|
8533 | if (typeof skip === 'number') {
|
8534 | this.skipWarn_(skip, i);
|
8535 | skip = null;
|
8536 | }
|
8537 |
|
8538 |
|
8539 |
|
8540 | protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
|
8541 |
|
8542 |
|
8543 |
|
8544 | frameLength = (buffer[i + 3] & 0x03) << 11 | buffer[i + 4] << 3 | (buffer[i + 5] & 0xe0) >> 5;
|
8545 | sampleCount = ((buffer[i + 6] & 0x03) + 1) * 1024;
|
8546 | adtsFrameDuration = sampleCount * ONE_SECOND_IN_TS$2 / ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2];
|
8547 |
|
8548 |
|
8549 | if (buffer.byteLength - i < frameLength) {
|
8550 | break;
|
8551 | }
|
8552 |
|
8553 |
|
8554 | this.trigger('data', {
|
8555 | pts: packet.pts + frameNum * adtsFrameDuration,
|
8556 | dts: packet.dts + frameNum * adtsFrameDuration,
|
8557 | sampleCount: sampleCount,
|
8558 | audioobjecttype: (buffer[i + 2] >>> 6 & 0x03) + 1,
|
8559 | channelcount: (buffer[i + 2] & 1) << 2 | (buffer[i + 3] & 0xc0) >>> 6,
|
8560 | samplerate: ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2],
|
8561 | samplingfrequencyindex: (buffer[i + 2] & 0x3c) >>> 2,
|
8562 |
|
8563 | samplesize: 16,
|
8564 |
|
8565 | data: buffer.subarray(i + 7 + protectionSkipBytes, i + frameLength)
|
8566 | });
|
8567 | frameNum++;
|
8568 | i += frameLength;
|
8569 | }
|
8570 |
|
8571 | if (typeof skip === 'number') {
|
8572 | this.skipWarn_(skip, i);
|
8573 | skip = null;
|
8574 | }
|
8575 |
|
8576 |
|
8577 | buffer = buffer.subarray(i);
|
8578 | };
|
8579 |
|
8580 | this.flush = function () {
|
8581 | frameNum = 0;
|
8582 | this.trigger('done');
|
8583 | };
|
8584 |
|
8585 | this.reset = function () {
|
8586 | buffer = void 0;
|
8587 | this.trigger('reset');
|
8588 | };
|
8589 |
|
8590 | this.endTimeline = function () {
|
8591 | buffer = void 0;
|
8592 | this.trigger('endedtimeline');
|
8593 | };
|
8594 | };
|
8595 |
|
8596 | _AdtsStream.prototype = new stream();
|
8597 | var adts = _AdtsStream;
|
8598 | |
8599 |
|
8600 |
|
8601 |
|
8602 |
|
8603 |
|
8604 |
|
8605 | var ExpGolomb;
|
8606 | |
8607 |
|
8608 |
|
8609 |
|
8610 |
|
8611 | ExpGolomb = function ExpGolomb(workingData) {
|
8612 | var
|
8613 | workingBytesAvailable = workingData.byteLength,
|
8614 |
|
8615 | workingWord = 0,
|
8616 |
|
8617 |
|
8618 | workingBitsAvailable = 0;
|
8619 |
|
8620 |
|
8621 | this.length = function () {
|
8622 | return 8 * workingBytesAvailable;
|
8623 | };
|
8624 |
|
8625 |
|
8626 | this.bitsAvailable = function () {
|
8627 | return 8 * workingBytesAvailable + workingBitsAvailable;
|
8628 | };
|
8629 |
|
8630 |
|
8631 | this.loadWord = function () {
|
8632 | var position = workingData.byteLength - workingBytesAvailable,
|
8633 | workingBytes = new Uint8Array(4),
|
8634 | availableBytes = Math.min(4, workingBytesAvailable);
|
8635 |
|
8636 | if (availableBytes === 0) {
|
8637 | throw new Error('no bytes available');
|
8638 | }
|
8639 |
|
8640 | workingBytes.set(workingData.subarray(position, position + availableBytes));
|
8641 | workingWord = new DataView(workingBytes.buffer).getUint32(0);
|
8642 |
|
8643 | workingBitsAvailable = availableBytes * 8;
|
8644 | workingBytesAvailable -= availableBytes;
|
8645 | };
|
8646 |
|
8647 |
|
8648 | this.skipBits = function (count) {
|
8649 | var skipBytes;
|
8650 |
|
8651 | if (workingBitsAvailable > count) {
|
8652 | workingWord <<= count;
|
8653 | workingBitsAvailable -= count;
|
8654 | } else {
|
8655 | count -= workingBitsAvailable;
|
8656 | skipBytes = Math.floor(count / 8);
|
8657 | count -= skipBytes * 8;
|
8658 | workingBytesAvailable -= skipBytes;
|
8659 | this.loadWord();
|
8660 | workingWord <<= count;
|
8661 | workingBitsAvailable -= count;
|
8662 | }
|
8663 | };
|
8664 |
|
8665 |
|
8666 | this.readBits = function (size) {
|
8667 | var bits = Math.min(workingBitsAvailable, size),
|
8668 |
|
8669 | valu = workingWord >>> 32 - bits;
|
8670 |
|
8671 |
|
8672 | workingBitsAvailable -= bits;
|
8673 |
|
8674 | if (workingBitsAvailable > 0) {
|
8675 | workingWord <<= bits;
|
8676 | } else if (workingBytesAvailable > 0) {
|
8677 | this.loadWord();
|
8678 | }
|
8679 |
|
8680 | bits = size - bits;
|
8681 |
|
8682 | if (bits > 0) {
|
8683 | return valu << bits | this.readBits(bits);
|
8684 | }
|
8685 |
|
8686 | return valu;
|
8687 | };
|
8688 |
|
8689 |
|
8690 | this.skipLeadingZeros = function () {
|
8691 | var leadingZeroCount;
|
8692 |
|
8693 | for (leadingZeroCount = 0; leadingZeroCount < workingBitsAvailable; ++leadingZeroCount) {
|
8694 | if ((workingWord & 0x80000000 >>> leadingZeroCount) !== 0) {
|
8695 |
|
8696 | workingWord <<= leadingZeroCount;
|
8697 | workingBitsAvailable -= leadingZeroCount;
|
8698 | return leadingZeroCount;
|
8699 | }
|
8700 | }
|
8701 |
|
8702 |
|
8703 | this.loadWord();
|
8704 | return leadingZeroCount + this.skipLeadingZeros();
|
8705 | };
|
8706 |
|
8707 |
|
8708 | this.skipUnsignedExpGolomb = function () {
|
8709 | this.skipBits(1 + this.skipLeadingZeros());
|
8710 | };
|
8711 |
|
8712 |
|
8713 | this.skipExpGolomb = function () {
|
8714 | this.skipBits(1 + this.skipLeadingZeros());
|
8715 | };
|
8716 |
|
8717 |
|
8718 | this.readUnsignedExpGolomb = function () {
|
8719 | var clz = this.skipLeadingZeros();
|
8720 |
|
8721 | return this.readBits(clz + 1) - 1;
|
8722 | };
|
8723 |
|
8724 |
|
8725 | this.readExpGolomb = function () {
|
8726 | var valu = this.readUnsignedExpGolomb();
|
8727 |
|
8728 | if (0x01 & valu) {
|
8729 |
|
8730 | return 1 + valu >>> 1;
|
8731 | }
|
8732 |
|
8733 | return -1 * (valu >>> 1);
|
8734 | };
|
8735 |
|
8736 |
|
8737 |
|
8738 | this.readBoolean = function () {
|
8739 | return this.readBits(1) === 1;
|
8740 | };
|
8741 |
|
8742 |
|
8743 | this.readUnsignedByte = function () {
|
8744 | return this.readBits(8);
|
8745 | };
|
8746 |
|
8747 | this.loadWord();
|
8748 | };
|
8749 |
|
8750 | var expGolomb = ExpGolomb;
|
8751 |
|
8752 | var _H264Stream, _NalByteStream;
|
8753 |
|
8754 | var PROFILES_WITH_OPTIONAL_SPS_DATA;
|
8755 | |
8756 |
|
8757 |
|
8758 |
|
8759 | _NalByteStream = function NalByteStream() {
|
8760 | var syncPoint = 0,
|
8761 | i,
|
8762 | buffer;
|
8763 |
|
8764 | _NalByteStream.prototype.init.call(this);
|
8765 | |
8766 |
|
8767 |
|
8768 |
|
8769 |
|
8770 |
|
8771 |
|
8772 |
|
8773 |
|
8774 | this.push = function (data) {
|
8775 | var swapBuffer;
|
8776 |
|
8777 | if (!buffer) {
|
8778 | buffer = data.data;
|
8779 | } else {
|
8780 | swapBuffer = new Uint8Array(buffer.byteLength + data.data.byteLength);
|
8781 | swapBuffer.set(buffer);
|
8782 | swapBuffer.set(data.data, buffer.byteLength);
|
8783 | buffer = swapBuffer;
|
8784 | }
|
8785 |
|
8786 | var len = buffer.byteLength;
|
8787 |
|
8788 |
|
8789 |
|
8790 |
|
8791 |
|
8792 |
|
8793 |
|
8794 |
|
8795 |
|
8796 | for (; syncPoint < len - 3; syncPoint++) {
|
8797 | if (buffer[syncPoint + 2] === 1) {
|
8798 |
|
8799 | i = syncPoint + 5;
|
8800 | break;
|
8801 | }
|
8802 | }
|
8803 |
|
8804 | while (i < len) {
|
8805 |
|
8806 |
|
8807 | switch (buffer[i]) {
|
8808 | case 0:
|
8809 |
|
8810 | if (buffer[i - 1] !== 0) {
|
8811 | i += 2;
|
8812 | break;
|
8813 | } else if (buffer[i - 2] !== 0) {
|
8814 | i++;
|
8815 | break;
|
8816 | }
|
8817 |
|
8818 |
|
8819 | if (syncPoint + 3 !== i - 2) {
|
8820 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
8821 | }
|
8822 |
|
8823 |
|
8824 | do {
|
8825 | i++;
|
8826 | } while (buffer[i] !== 1 && i < len);
|
8827 |
|
8828 | syncPoint = i - 2;
|
8829 | i += 3;
|
8830 | break;
|
8831 |
|
8832 | case 1:
|
8833 |
|
8834 | if (buffer[i - 1] !== 0 || buffer[i - 2] !== 0) {
|
8835 | i += 3;
|
8836 | break;
|
8837 | }
|
8838 |
|
8839 |
|
8840 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
8841 | syncPoint = i - 2;
|
8842 | i += 3;
|
8843 | break;
|
8844 |
|
8845 | default:
|
8846 |
|
8847 |
|
8848 | i += 3;
|
8849 | break;
|
8850 | }
|
8851 | }
|
8852 |
|
8853 |
|
8854 | buffer = buffer.subarray(syncPoint);
|
8855 | i -= syncPoint;
|
8856 | syncPoint = 0;
|
8857 | };
|
8858 |
|
8859 | this.reset = function () {
|
8860 | buffer = null;
|
8861 | syncPoint = 0;
|
8862 | this.trigger('reset');
|
8863 | };
|
8864 |
|
8865 | this.flush = function () {
|
8866 |
|
8867 | if (buffer && buffer.byteLength > 3) {
|
8868 | this.trigger('data', buffer.subarray(syncPoint + 3));
|
8869 | }
|
8870 |
|
8871 |
|
8872 | buffer = null;
|
8873 | syncPoint = 0;
|
8874 | this.trigger('done');
|
8875 | };
|
8876 |
|
8877 | this.endTimeline = function () {
|
8878 | this.flush();
|
8879 | this.trigger('endedtimeline');
|
8880 | };
|
8881 | };
|
8882 |
|
8883 | _NalByteStream.prototype = new stream();
|
8884 |
|
8885 |
|
8886 |
|
8887 | PROFILES_WITH_OPTIONAL_SPS_DATA = {
|
8888 | 100: true,
|
8889 | 110: true,
|
8890 | 122: true,
|
8891 | 244: true,
|
8892 | 44: true,
|
8893 | 83: true,
|
8894 | 86: true,
|
8895 | 118: true,
|
8896 | 128: true,
|
8897 |
|
8898 |
|
8899 | 138: true,
|
8900 | 139: true,
|
8901 | 134: true
|
8902 | };
|
8903 | |
8904 |
|
8905 |
|
8906 |
|
8907 |
|
8908 | _H264Stream = function H264Stream() {
|
8909 | var nalByteStream = new _NalByteStream(),
|
8910 | self,
|
8911 | trackId,
|
8912 | currentPts,
|
8913 | currentDts,
|
8914 | discardEmulationPreventionBytes,
|
8915 | readSequenceParameterSet,
|
8916 | skipScalingList;
|
8917 |
|
8918 | _H264Stream.prototype.init.call(this);
|
8919 |
|
8920 | self = this;
|
8921 | |
8922 |
|
8923 |
|
8924 |
|
8925 |
|
8926 |
|
8927 |
|
8928 |
|
8929 |
|
8930 |
|
8931 |
|
8932 |
|
8933 | this.push = function (packet) {
|
8934 | if (packet.type !== 'video') {
|
8935 | return;
|
8936 | }
|
8937 |
|
8938 | trackId = packet.trackId;
|
8939 | currentPts = packet.pts;
|
8940 | currentDts = packet.dts;
|
8941 | nalByteStream.push(packet);
|
8942 | };
|
8943 | |
8944 |
|
8945 |
|
8946 |
|
8947 |
|
8948 |
|
8949 |
|
8950 |
|
8951 |
|
8952 |
|
8953 | nalByteStream.on('data', function (data) {
|
8954 | var event = {
|
8955 | trackId: trackId,
|
8956 | pts: currentPts,
|
8957 | dts: currentDts,
|
8958 | data: data,
|
8959 | nalUnitTypeCode: data[0] & 0x1f
|
8960 | };
|
8961 |
|
8962 | switch (event.nalUnitTypeCode) {
|
8963 | case 0x05:
|
8964 | event.nalUnitType = 'slice_layer_without_partitioning_rbsp_idr';
|
8965 | break;
|
8966 |
|
8967 | case 0x06:
|
8968 | event.nalUnitType = 'sei_rbsp';
|
8969 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
8970 | break;
|
8971 |
|
8972 | case 0x07:
|
8973 | event.nalUnitType = 'seq_parameter_set_rbsp';
|
8974 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
8975 | event.config = readSequenceParameterSet(event.escapedRBSP);
|
8976 | break;
|
8977 |
|
8978 | case 0x08:
|
8979 | event.nalUnitType = 'pic_parameter_set_rbsp';
|
8980 | break;
|
8981 |
|
8982 | case 0x09:
|
8983 | event.nalUnitType = 'access_unit_delimiter_rbsp';
|
8984 | break;
|
8985 | }
|
8986 |
|
8987 |
|
8988 | self.trigger('data', event);
|
8989 | });
|
8990 | nalByteStream.on('done', function () {
|
8991 | self.trigger('done');
|
8992 | });
|
8993 | nalByteStream.on('partialdone', function () {
|
8994 | self.trigger('partialdone');
|
8995 | });
|
8996 | nalByteStream.on('reset', function () {
|
8997 | self.trigger('reset');
|
8998 | });
|
8999 | nalByteStream.on('endedtimeline', function () {
|
9000 | self.trigger('endedtimeline');
|
9001 | });
|
9002 |
|
9003 | this.flush = function () {
|
9004 | nalByteStream.flush();
|
9005 | };
|
9006 |
|
9007 | this.partialFlush = function () {
|
9008 | nalByteStream.partialFlush();
|
9009 | };
|
9010 |
|
9011 | this.reset = function () {
|
9012 | nalByteStream.reset();
|
9013 | };
|
9014 |
|
9015 | this.endTimeline = function () {
|
9016 | nalByteStream.endTimeline();
|
9017 | };
|
9018 | |
9019 |
|
9020 |
|
9021 |
|
9022 |
|
9023 |
|
9024 |
|
9025 |
|
9026 |
|
9027 |
|
9028 |
|
9029 | skipScalingList = function skipScalingList(count, expGolombDecoder) {
|
9030 | var lastScale = 8,
|
9031 | nextScale = 8,
|
9032 | j,
|
9033 | deltaScale;
|
9034 |
|
9035 | for (j = 0; j < count; j++) {
|
9036 | if (nextScale !== 0) {
|
9037 | deltaScale = expGolombDecoder.readExpGolomb();
|
9038 | nextScale = (lastScale + deltaScale + 256) % 256;
|
9039 | }
|
9040 |
|
9041 | lastScale = nextScale === 0 ? lastScale : nextScale;
|
9042 | }
|
9043 | };
|
9044 | |
9045 |
|
9046 |
|
9047 |
|
9048 |
|
9049 |
|
9050 |
|
9051 |
|
9052 |
|
9053 |
|
9054 | discardEmulationPreventionBytes = function discardEmulationPreventionBytes(data) {
|
9055 | var length = data.byteLength,
|
9056 | emulationPreventionBytesPositions = [],
|
9057 | i = 1,
|
9058 | newLength,
|
9059 | newData;
|
9060 |
|
9061 | while (i < length - 2) {
|
9062 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
9063 | emulationPreventionBytesPositions.push(i + 2);
|
9064 | i += 2;
|
9065 | } else {
|
9066 | i++;
|
9067 | }
|
9068 | }
|
9069 |
|
9070 |
|
9071 |
|
9072 | if (emulationPreventionBytesPositions.length === 0) {
|
9073 | return data;
|
9074 | }
|
9075 |
|
9076 |
|
9077 | newLength = length - emulationPreventionBytesPositions.length;
|
9078 | newData = new Uint8Array(newLength);
|
9079 | var sourceIndex = 0;
|
9080 |
|
9081 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
9082 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
9083 |
|
9084 | sourceIndex++;
|
9085 |
|
9086 | emulationPreventionBytesPositions.shift();
|
9087 | }
|
9088 |
|
9089 | newData[i] = data[sourceIndex];
|
9090 | }
|
9091 |
|
9092 | return newData;
|
9093 | };
|
9094 | |
9095 |
|
9096 |
|
9097 |
|
9098 |
|
9099 |
|
9100 |
|
9101 |
|
9102 |
|
9103 |
|
9104 |
|
9105 | readSequenceParameterSet = function readSequenceParameterSet(data) {
|
9106 | var frameCropLeftOffset = 0,
|
9107 | frameCropRightOffset = 0,
|
9108 | frameCropTopOffset = 0,
|
9109 | frameCropBottomOffset = 0,
|
9110 | expGolombDecoder,
|
9111 | profileIdc,
|
9112 | levelIdc,
|
9113 | profileCompatibility,
|
9114 | chromaFormatIdc,
|
9115 | picOrderCntType,
|
9116 | numRefFramesInPicOrderCntCycle,
|
9117 | picWidthInMbsMinus1,
|
9118 | picHeightInMapUnitsMinus1,
|
9119 | frameMbsOnlyFlag,
|
9120 | scalingListCount,
|
9121 | sarRatio = [1, 1],
|
9122 | aspectRatioIdc,
|
9123 | i;
|
9124 | expGolombDecoder = new expGolomb(data);
|
9125 | profileIdc = expGolombDecoder.readUnsignedByte();
|
9126 |
|
9127 | profileCompatibility = expGolombDecoder.readUnsignedByte();
|
9128 |
|
9129 | levelIdc = expGolombDecoder.readUnsignedByte();
|
9130 |
|
9131 | expGolombDecoder.skipUnsignedExpGolomb();
|
9132 |
|
9133 |
|
9134 | if (PROFILES_WITH_OPTIONAL_SPS_DATA[profileIdc]) {
|
9135 | chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
|
9136 |
|
9137 | if (chromaFormatIdc === 3) {
|
9138 | expGolombDecoder.skipBits(1);
|
9139 | }
|
9140 |
|
9141 | expGolombDecoder.skipUnsignedExpGolomb();
|
9142 |
|
9143 | expGolombDecoder.skipUnsignedExpGolomb();
|
9144 |
|
9145 | expGolombDecoder.skipBits(1);
|
9146 |
|
9147 | if (expGolombDecoder.readBoolean()) {
|
9148 |
|
9149 | scalingListCount = chromaFormatIdc !== 3 ? 8 : 12;
|
9150 |
|
9151 | for (i = 0; i < scalingListCount; i++) {
|
9152 | if (expGolombDecoder.readBoolean()) {
|
9153 |
|
9154 | if (i < 6) {
|
9155 | skipScalingList(16, expGolombDecoder);
|
9156 | } else {
|
9157 | skipScalingList(64, expGolombDecoder);
|
9158 | }
|
9159 | }
|
9160 | }
|
9161 | }
|
9162 | }
|
9163 |
|
9164 | expGolombDecoder.skipUnsignedExpGolomb();
|
9165 |
|
9166 | picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
|
9167 |
|
9168 | if (picOrderCntType === 0) {
|
9169 | expGolombDecoder.readUnsignedExpGolomb();
|
9170 | } else if (picOrderCntType === 1) {
|
9171 | expGolombDecoder.skipBits(1);
|
9172 |
|
9173 | expGolombDecoder.skipExpGolomb();
|
9174 |
|
9175 | expGolombDecoder.skipExpGolomb();
|
9176 |
|
9177 | numRefFramesInPicOrderCntCycle = expGolombDecoder.readUnsignedExpGolomb();
|
9178 |
|
9179 | for (i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
|
9180 | expGolombDecoder.skipExpGolomb();
|
9181 | }
|
9182 | }
|
9183 |
|
9184 | expGolombDecoder.skipUnsignedExpGolomb();
|
9185 |
|
9186 | expGolombDecoder.skipBits(1);
|
9187 |
|
9188 | picWidthInMbsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
9189 | picHeightInMapUnitsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
9190 | frameMbsOnlyFlag = expGolombDecoder.readBits(1);
|
9191 |
|
9192 | if (frameMbsOnlyFlag === 0) {
|
9193 | expGolombDecoder.skipBits(1);
|
9194 | }
|
9195 |
|
9196 | expGolombDecoder.skipBits(1);
|
9197 |
|
9198 | if (expGolombDecoder.readBoolean()) {
|
9199 |
|
9200 | frameCropLeftOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9201 | frameCropRightOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9202 | frameCropTopOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9203 | frameCropBottomOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9204 | }
|
9205 |
|
9206 | if (expGolombDecoder.readBoolean()) {
|
9207 |
|
9208 | if (expGolombDecoder.readBoolean()) {
|
9209 |
|
9210 | aspectRatioIdc = expGolombDecoder.readUnsignedByte();
|
9211 |
|
9212 | switch (aspectRatioIdc) {
|
9213 | case 1:
|
9214 | sarRatio = [1, 1];
|
9215 | break;
|
9216 |
|
9217 | case 2:
|
9218 | sarRatio = [12, 11];
|
9219 | break;
|
9220 |
|
9221 | case 3:
|
9222 | sarRatio = [10, 11];
|
9223 | break;
|
9224 |
|
9225 | case 4:
|
9226 | sarRatio = [16, 11];
|
9227 | break;
|
9228 |
|
9229 | case 5:
|
9230 | sarRatio = [40, 33];
|
9231 | break;
|
9232 |
|
9233 | case 6:
|
9234 | sarRatio = [24, 11];
|
9235 | break;
|
9236 |
|
9237 | case 7:
|
9238 | sarRatio = [20, 11];
|
9239 | break;
|
9240 |
|
9241 | case 8:
|
9242 | sarRatio = [32, 11];
|
9243 | break;
|
9244 |
|
9245 | case 9:
|
9246 | sarRatio = [80, 33];
|
9247 | break;
|
9248 |
|
9249 | case 10:
|
9250 | sarRatio = [18, 11];
|
9251 | break;
|
9252 |
|
9253 | case 11:
|
9254 | sarRatio = [15, 11];
|
9255 | break;
|
9256 |
|
9257 | case 12:
|
9258 | sarRatio = [64, 33];
|
9259 | break;
|
9260 |
|
9261 | case 13:
|
9262 | sarRatio = [160, 99];
|
9263 | break;
|
9264 |
|
9265 | case 14:
|
9266 | sarRatio = [4, 3];
|
9267 | break;
|
9268 |
|
9269 | case 15:
|
9270 | sarRatio = [3, 2];
|
9271 | break;
|
9272 |
|
9273 | case 16:
|
9274 | sarRatio = [2, 1];
|
9275 | break;
|
9276 |
|
9277 | case 255:
|
9278 | {
|
9279 | sarRatio = [expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte(), expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte()];
|
9280 | break;
|
9281 | }
|
9282 | }
|
9283 |
|
9284 | if (sarRatio) {
|
9285 | sarRatio[0] / sarRatio[1];
|
9286 | }
|
9287 | }
|
9288 | }
|
9289 |
|
9290 | return {
|
9291 | profileIdc: profileIdc,
|
9292 | levelIdc: levelIdc,
|
9293 | profileCompatibility: profileCompatibility,
|
9294 | width: (picWidthInMbsMinus1 + 1) * 16 - frameCropLeftOffset * 2 - frameCropRightOffset * 2,
|
9295 | height: (2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16 - frameCropTopOffset * 2 - frameCropBottomOffset * 2,
|
9296 |
|
9297 | sarRatio: sarRatio
|
9298 | };
|
9299 | };
|
9300 | };
|
9301 |
|
9302 | _H264Stream.prototype = new stream();
|
9303 | var h264 = {
|
9304 | H264Stream: _H264Stream,
|
9305 | NalByteStream: _NalByteStream
|
9306 | };
|
9307 | |
9308 |
|
9309 |
|
9310 |
|
9311 |
|
9312 |
|
9313 |
|
9314 |
|
9315 |
|
9316 | var ADTS_SAMPLING_FREQUENCIES = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
9317 |
|
9318 | var parseId3TagSize = function parseId3TagSize(header, byteIndex) {
|
9319 | var returnSize = header[byteIndex + 6] << 21 | header[byteIndex + 7] << 14 | header[byteIndex + 8] << 7 | header[byteIndex + 9],
|
9320 | flags = header[byteIndex + 5],
|
9321 | footerPresent = (flags & 16) >> 4;
|
9322 |
|
9323 | returnSize = returnSize >= 0 ? returnSize : 0;
|
9324 |
|
9325 | if (footerPresent) {
|
9326 | return returnSize + 20;
|
9327 | }
|
9328 |
|
9329 | return returnSize + 10;
|
9330 | };
|
9331 |
|
9332 | var getId3Offset = function getId3Offset(data, offset) {
|
9333 | if (data.length - offset < 10 || data[offset] !== 'I'.charCodeAt(0) || data[offset + 1] !== 'D'.charCodeAt(0) || data[offset + 2] !== '3'.charCodeAt(0)) {
|
9334 | return offset;
|
9335 | }
|
9336 |
|
9337 | offset += parseId3TagSize(data, offset);
|
9338 | return getId3Offset(data, offset);
|
9339 | };
|
9340 |
|
9341 |
|
9342 | var isLikelyAacData$1 = function isLikelyAacData(data) {
|
9343 | var offset = getId3Offset(data, 0);
|
9344 | return data.length >= offset + 2 && (data[offset] & 0xFF) === 0xFF && (data[offset + 1] & 0xF0) === 0xF0 &&
|
9345 |
|
9346 | (data[offset + 1] & 0x16) === 0x10;
|
9347 | };
|
9348 |
|
9349 | var parseSyncSafeInteger = function parseSyncSafeInteger(data) {
|
9350 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
9351 | };
|
9352 |
|
9353 |
|
9354 |
|
9355 | var percentEncode = function percentEncode(bytes, start, end) {
|
9356 | var i,
|
9357 | result = '';
|
9358 |
|
9359 | for (i = start; i < end; i++) {
|
9360 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
9361 | }
|
9362 |
|
9363 | return result;
|
9364 | };
|
9365 |
|
9366 |
|
9367 |
|
9368 | var parseIso88591 = function parseIso88591(bytes, start, end) {
|
9369 | return unescape(percentEncode(bytes, start, end));
|
9370 | };
|
9371 |
|
9372 | var parseAdtsSize = function parseAdtsSize(header, byteIndex) {
|
9373 | var lowThree = (header[byteIndex + 5] & 0xE0) >> 5,
|
9374 | middle = header[byteIndex + 4] << 3,
|
9375 | highTwo = header[byteIndex + 3] & 0x3 << 11;
|
9376 | return highTwo | middle | lowThree;
|
9377 | };
|
9378 |
|
9379 | var parseType$2 = function parseType(header, byteIndex) {
|
9380 | if (header[byteIndex] === 'I'.charCodeAt(0) && header[byteIndex + 1] === 'D'.charCodeAt(0) && header[byteIndex + 2] === '3'.charCodeAt(0)) {
|
9381 | return 'timed-metadata';
|
9382 | } else if (header[byteIndex] & 0xff === 0xff && (header[byteIndex + 1] & 0xf0) === 0xf0) {
|
9383 | return 'audio';
|
9384 | }
|
9385 |
|
9386 | return null;
|
9387 | };
|
9388 |
|
9389 | var parseSampleRate = function parseSampleRate(packet) {
|
9390 | var i = 0;
|
9391 |
|
9392 | while (i + 5 < packet.length) {
|
9393 | if (packet[i] !== 0xFF || (packet[i + 1] & 0xF6) !== 0xF0) {
|
9394 |
|
9395 |
|
9396 | i++;
|
9397 | continue;
|
9398 | }
|
9399 |
|
9400 | return ADTS_SAMPLING_FREQUENCIES[(packet[i + 2] & 0x3c) >>> 2];
|
9401 | }
|
9402 |
|
9403 | return null;
|
9404 | };
|
9405 |
|
9406 | var parseAacTimestamp = function parseAacTimestamp(packet) {
|
9407 | var frameStart, frameSize, frame, frameHeader;
|
9408 |
|
9409 | frameStart = 10;
|
9410 |
|
9411 | if (packet[5] & 0x40) {
|
9412 |
|
9413 | frameStart += 4;
|
9414 |
|
9415 | frameStart += parseSyncSafeInteger(packet.subarray(10, 14));
|
9416 | }
|
9417 |
|
9418 |
|
9419 |
|
9420 | do {
|
9421 |
|
9422 | frameSize = parseSyncSafeInteger(packet.subarray(frameStart + 4, frameStart + 8));
|
9423 |
|
9424 | if (frameSize < 1) {
|
9425 | return null;
|
9426 | }
|
9427 |
|
9428 | frameHeader = String.fromCharCode(packet[frameStart], packet[frameStart + 1], packet[frameStart + 2], packet[frameStart + 3]);
|
9429 |
|
9430 | if (frameHeader === 'PRIV') {
|
9431 | frame = packet.subarray(frameStart + 10, frameStart + frameSize + 10);
|
9432 |
|
9433 | for (var i = 0; i < frame.byteLength; i++) {
|
9434 | if (frame[i] === 0) {
|
9435 | var owner = parseIso88591(frame, 0, i);
|
9436 |
|
9437 | if (owner === 'com.apple.streaming.transportStreamTimestamp') {
|
9438 | var d = frame.subarray(i + 1);
|
9439 | var size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
9440 | size *= 4;
|
9441 | size += d[7] & 0x03;
|
9442 | return size;
|
9443 | }
|
9444 |
|
9445 | break;
|
9446 | }
|
9447 | }
|
9448 | }
|
9449 |
|
9450 | frameStart += 10;
|
9451 |
|
9452 | frameStart += frameSize;
|
9453 | } while (frameStart < packet.byteLength);
|
9454 |
|
9455 | return null;
|
9456 | };
|
9457 |
|
9458 | var utils = {
|
9459 | isLikelyAacData: isLikelyAacData$1,
|
9460 | parseId3TagSize: parseId3TagSize,
|
9461 | parseAdtsSize: parseAdtsSize,
|
9462 | parseType: parseType$2,
|
9463 | parseSampleRate: parseSampleRate,
|
9464 | parseAacTimestamp: parseAacTimestamp
|
9465 | };
|
9466 |
|
9467 | var _AacStream;
|
9468 | |
9469 |
|
9470 |
|
9471 |
|
9472 |
|
9473 | _AacStream = function AacStream() {
|
9474 | var everything = new Uint8Array(),
|
9475 | timeStamp = 0;
|
9476 |
|
9477 | _AacStream.prototype.init.call(this);
|
9478 |
|
9479 | this.setTimestamp = function (timestamp) {
|
9480 | timeStamp = timestamp;
|
9481 | };
|
9482 |
|
9483 | this.push = function (bytes) {
|
9484 | var frameSize = 0,
|
9485 | byteIndex = 0,
|
9486 | bytesLeft,
|
9487 | chunk,
|
9488 | packet,
|
9489 | tempLength;
|
9490 |
|
9491 |
|
9492 | if (everything.length) {
|
9493 | tempLength = everything.length;
|
9494 | everything = new Uint8Array(bytes.byteLength + tempLength);
|
9495 | everything.set(everything.subarray(0, tempLength));
|
9496 | everything.set(bytes, tempLength);
|
9497 | } else {
|
9498 | everything = bytes;
|
9499 | }
|
9500 |
|
9501 | while (everything.length - byteIndex >= 3) {
|
9502 | if (everything[byteIndex] === 'I'.charCodeAt(0) && everything[byteIndex + 1] === 'D'.charCodeAt(0) && everything[byteIndex + 2] === '3'.charCodeAt(0)) {
|
9503 |
|
9504 |
|
9505 | if (everything.length - byteIndex < 10) {
|
9506 | break;
|
9507 | }
|
9508 |
|
9509 |
|
9510 | frameSize = utils.parseId3TagSize(everything, byteIndex);
|
9511 |
|
9512 |
|
9513 |
|
9514 | if (byteIndex + frameSize > everything.length) {
|
9515 | break;
|
9516 | }
|
9517 |
|
9518 | chunk = {
|
9519 | type: 'timed-metadata',
|
9520 | data: everything.subarray(byteIndex, byteIndex + frameSize)
|
9521 | };
|
9522 | this.trigger('data', chunk);
|
9523 | byteIndex += frameSize;
|
9524 | continue;
|
9525 | } else if ((everything[byteIndex] & 0xff) === 0xff && (everything[byteIndex + 1] & 0xf0) === 0xf0) {
|
9526 |
|
9527 |
|
9528 | if (everything.length - byteIndex < 7) {
|
9529 | break;
|
9530 | }
|
9531 |
|
9532 | frameSize = utils.parseAdtsSize(everything, byteIndex);
|
9533 |
|
9534 |
|
9535 | if (byteIndex + frameSize > everything.length) {
|
9536 | break;
|
9537 | }
|
9538 |
|
9539 | packet = {
|
9540 | type: 'audio',
|
9541 | data: everything.subarray(byteIndex, byteIndex + frameSize),
|
9542 | pts: timeStamp,
|
9543 | dts: timeStamp
|
9544 | };
|
9545 | this.trigger('data', packet);
|
9546 | byteIndex += frameSize;
|
9547 | continue;
|
9548 | }
|
9549 |
|
9550 | byteIndex++;
|
9551 | }
|
9552 |
|
9553 | bytesLeft = everything.length - byteIndex;
|
9554 |
|
9555 | if (bytesLeft > 0) {
|
9556 | everything = everything.subarray(byteIndex);
|
9557 | } else {
|
9558 | everything = new Uint8Array();
|
9559 | }
|
9560 | };
|
9561 |
|
9562 | this.reset = function () {
|
9563 | everything = new Uint8Array();
|
9564 | this.trigger('reset');
|
9565 | };
|
9566 |
|
9567 | this.endTimeline = function () {
|
9568 | everything = new Uint8Array();
|
9569 | this.trigger('endedtimeline');
|
9570 | };
|
9571 | };
|
9572 |
|
9573 | _AacStream.prototype = new stream();
|
9574 | var aac = _AacStream;
|
9575 |
|
9576 | var AUDIO_PROPERTIES = ['audioobjecttype', 'channelcount', 'samplerate', 'samplingfrequencyindex', 'samplesize'];
|
9577 | var audioProperties = AUDIO_PROPERTIES;
|
9578 | var VIDEO_PROPERTIES = ['width', 'height', 'profileIdc', 'levelIdc', 'profileCompatibility', 'sarRatio'];
|
9579 | var videoProperties = VIDEO_PROPERTIES;
|
9580 | var H264Stream = h264.H264Stream;
|
9581 | var isLikelyAacData = utils.isLikelyAacData;
|
9582 | var ONE_SECOND_IN_TS$1 = clock.ONE_SECOND_IN_TS;
|
9583 |
|
9584 | var _VideoSegmentStream, _AudioSegmentStream, _Transmuxer, _CoalesceStream;
|
9585 |
|
9586 | var retriggerForStream = function retriggerForStream(key, event) {
|
9587 | event.stream = key;
|
9588 | this.trigger('log', event);
|
9589 | };
|
9590 |
|
9591 | var addPipelineLogRetriggers = function addPipelineLogRetriggers(transmuxer, pipeline) {
|
9592 | var keys = Object.keys(pipeline);
|
9593 |
|
9594 | for (var i = 0; i < keys.length; i++) {
|
9595 | var key = keys[i];
|
9596 |
|
9597 |
|
9598 | if (key === 'headOfPipeline' || !pipeline[key].on) {
|
9599 | continue;
|
9600 | }
|
9601 |
|
9602 | pipeline[key].on('log', retriggerForStream.bind(transmuxer, key));
|
9603 | }
|
9604 | };
|
9605 | |
9606 |
|
9607 |
|
9608 |
|
9609 |
|
9610 | var arrayEquals = function arrayEquals(a, b) {
|
9611 | var i;
|
9612 |
|
9613 | if (a.length !== b.length) {
|
9614 | return false;
|
9615 | }
|
9616 |
|
9617 |
|
9618 | for (i = 0; i < a.length; i++) {
|
9619 | if (a[i] !== b[i]) {
|
9620 | return false;
|
9621 | }
|
9622 | }
|
9623 |
|
9624 | return true;
|
9625 | };
|
9626 |
|
9627 | var generateSegmentTimingInfo = function generateSegmentTimingInfo(baseMediaDecodeTime, startDts, startPts, endDts, endPts, prependedContentDuration) {
|
9628 | var ptsOffsetFromDts = startPts - startDts,
|
9629 | decodeDuration = endDts - startDts,
|
9630 | presentationDuration = endPts - startPts;
|
9631 |
|
9632 |
|
9633 |
|
9634 |
|
9635 | return {
|
9636 | start: {
|
9637 | dts: baseMediaDecodeTime,
|
9638 | pts: baseMediaDecodeTime + ptsOffsetFromDts
|
9639 | },
|
9640 | end: {
|
9641 | dts: baseMediaDecodeTime + decodeDuration,
|
9642 | pts: baseMediaDecodeTime + presentationDuration
|
9643 | },
|
9644 | prependedContentDuration: prependedContentDuration,
|
9645 | baseMediaDecodeTime: baseMediaDecodeTime
|
9646 | };
|
9647 | };
|
9648 | |
9649 |
|
9650 |
|
9651 |
|
9652 |
|
9653 |
|
9654 |
|
9655 |
|
9656 |
|
9657 |
|
9658 |
|
9659 | _AudioSegmentStream = function AudioSegmentStream(track, options) {
|
9660 | var adtsFrames = [],
|
9661 | sequenceNumber,
|
9662 | earliestAllowedDts = 0,
|
9663 | audioAppendStartTs = 0,
|
9664 | videoBaseMediaDecodeTime = Infinity;
|
9665 | options = options || {};
|
9666 | sequenceNumber = options.firstSequenceNumber || 0;
|
9667 |
|
9668 | _AudioSegmentStream.prototype.init.call(this);
|
9669 |
|
9670 | this.push = function (data) {
|
9671 | trackDecodeInfo.collectDtsInfo(track, data);
|
9672 |
|
9673 | if (track) {
|
9674 | audioProperties.forEach(function (prop) {
|
9675 | track[prop] = data[prop];
|
9676 | });
|
9677 | }
|
9678 |
|
9679 |
|
9680 | adtsFrames.push(data);
|
9681 | };
|
9682 |
|
9683 | this.setEarliestDts = function (earliestDts) {
|
9684 | earliestAllowedDts = earliestDts;
|
9685 | };
|
9686 |
|
9687 | this.setVideoBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
9688 | videoBaseMediaDecodeTime = baseMediaDecodeTime;
|
9689 | };
|
9690 |
|
9691 | this.setAudioAppendStart = function (timestamp) {
|
9692 | audioAppendStartTs = timestamp;
|
9693 | };
|
9694 |
|
9695 | this.flush = function () {
|
9696 | var frames, moof, mdat, boxes, frameDuration, segmentDuration, videoClockCyclesOfSilencePrefixed;
|
9697 |
|
9698 | if (adtsFrames.length === 0) {
|
9699 | this.trigger('done', 'AudioSegmentStream');
|
9700 | return;
|
9701 | }
|
9702 |
|
9703 | frames = audioFrameUtils.trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts);
|
9704 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
9705 |
|
9706 | videoClockCyclesOfSilencePrefixed = audioFrameUtils.prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime);
|
9707 |
|
9708 |
|
9709 | track.samples = audioFrameUtils.generateSampleTable(frames);
|
9710 |
|
9711 | mdat = mp4Generator.mdat(audioFrameUtils.concatenateFrameData(frames));
|
9712 | adtsFrames = [];
|
9713 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
9714 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
9715 |
|
9716 | sequenceNumber++;
|
9717 | boxes.set(moof);
|
9718 | boxes.set(mdat, moof.byteLength);
|
9719 | trackDecodeInfo.clearDtsInfo(track);
|
9720 | frameDuration = Math.ceil(ONE_SECOND_IN_TS$1 * 1024 / track.samplerate);
|
9721 |
|
9722 |
|
9723 |
|
9724 |
|
9725 | if (frames.length) {
|
9726 | segmentDuration = frames.length * frameDuration;
|
9727 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(
|
9728 |
|
9729 |
|
9730 | clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate),
|
9731 | frames[0].dts, frames[0].pts, frames[0].dts + segmentDuration, frames[0].pts + segmentDuration, videoClockCyclesOfSilencePrefixed || 0));
|
9732 | this.trigger('timingInfo', {
|
9733 | start: frames[0].pts,
|
9734 | end: frames[0].pts + segmentDuration
|
9735 | });
|
9736 | }
|
9737 |
|
9738 | this.trigger('data', {
|
9739 | track: track,
|
9740 | boxes: boxes
|
9741 | });
|
9742 | this.trigger('done', 'AudioSegmentStream');
|
9743 | };
|
9744 |
|
9745 | this.reset = function () {
|
9746 | trackDecodeInfo.clearDtsInfo(track);
|
9747 | adtsFrames = [];
|
9748 | this.trigger('reset');
|
9749 | };
|
9750 | };
|
9751 |
|
9752 | _AudioSegmentStream.prototype = new stream();
|
9753 | |
9754 |
|
9755 |
|
9756 |
|
9757 |
|
9758 |
|
9759 |
|
9760 |
|
9761 |
|
9762 |
|
9763 |
|
9764 |
|
9765 | _VideoSegmentStream = function VideoSegmentStream(track, options) {
|
9766 | var sequenceNumber,
|
9767 | nalUnits = [],
|
9768 | gopsToAlignWith = [],
|
9769 | config,
|
9770 | pps;
|
9771 | options = options || {};
|
9772 | sequenceNumber = options.firstSequenceNumber || 0;
|
9773 |
|
9774 | _VideoSegmentStream.prototype.init.call(this);
|
9775 |
|
9776 | delete track.minPTS;
|
9777 | this.gopCache_ = [];
|
9778 | |
9779 |
|
9780 |
|
9781 |
|
9782 |
|
9783 |
|
9784 |
|
9785 |
|
9786 |
|
9787 | this.push = function (nalUnit) {
|
9788 | trackDecodeInfo.collectDtsInfo(track, nalUnit);
|
9789 |
|
9790 | if (nalUnit.nalUnitType === 'seq_parameter_set_rbsp' && !config) {
|
9791 | config = nalUnit.config;
|
9792 | track.sps = [nalUnit.data];
|
9793 | videoProperties.forEach(function (prop) {
|
9794 | track[prop] = config[prop];
|
9795 | }, this);
|
9796 | }
|
9797 |
|
9798 | if (nalUnit.nalUnitType === 'pic_parameter_set_rbsp' && !pps) {
|
9799 | pps = nalUnit.data;
|
9800 | track.pps = [nalUnit.data];
|
9801 | }
|
9802 |
|
9803 |
|
9804 | nalUnits.push(nalUnit);
|
9805 | };
|
9806 | |
9807 |
|
9808 |
|
9809 |
|
9810 |
|
9811 |
|
9812 | this.flush = function () {
|
9813 | var frames,
|
9814 | gopForFusion,
|
9815 | gops,
|
9816 | moof,
|
9817 | mdat,
|
9818 | boxes,
|
9819 | prependedContentDuration = 0,
|
9820 | firstGop,
|
9821 | lastGop;
|
9822 |
|
9823 |
|
9824 | while (nalUnits.length) {
|
9825 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
9826 | break;
|
9827 | }
|
9828 |
|
9829 | nalUnits.shift();
|
9830 | }
|
9831 |
|
9832 |
|
9833 | if (nalUnits.length === 0) {
|
9834 | this.resetStream_();
|
9835 | this.trigger('done', 'VideoSegmentStream');
|
9836 | return;
|
9837 | }
|
9838 |
|
9839 |
|
9840 |
|
9841 |
|
9842 | frames = frameUtils.groupNalsIntoFrames(nalUnits);
|
9843 | gops = frameUtils.groupFramesIntoGops(frames);
|
9844 |
|
9845 |
|
9846 |
|
9847 |
|
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 | if (!gops[0][0].keyFrame) {
|
9863 |
|
9864 | gopForFusion = this.getGopForFusion_(nalUnits[0], track);
|
9865 |
|
9866 | if (gopForFusion) {
|
9867 |
|
9868 |
|
9869 | prependedContentDuration = gopForFusion.duration;
|
9870 | gops.unshift(gopForFusion);
|
9871 |
|
9872 |
|
9873 | gops.byteLength += gopForFusion.byteLength;
|
9874 | gops.nalCount += gopForFusion.nalCount;
|
9875 | gops.pts = gopForFusion.pts;
|
9876 | gops.dts = gopForFusion.dts;
|
9877 | gops.duration += gopForFusion.duration;
|
9878 | } else {
|
9879 |
|
9880 | gops = frameUtils.extendFirstKeyFrame(gops);
|
9881 | }
|
9882 | }
|
9883 |
|
9884 |
|
9885 | if (gopsToAlignWith.length) {
|
9886 | var alignedGops;
|
9887 |
|
9888 | if (options.alignGopsAtEnd) {
|
9889 | alignedGops = this.alignGopsAtEnd_(gops);
|
9890 | } else {
|
9891 | alignedGops = this.alignGopsAtStart_(gops);
|
9892 | }
|
9893 |
|
9894 | if (!alignedGops) {
|
9895 |
|
9896 | this.gopCache_.unshift({
|
9897 | gop: gops.pop(),
|
9898 | pps: track.pps,
|
9899 | sps: track.sps
|
9900 | });
|
9901 |
|
9902 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
9903 |
|
9904 | nalUnits = [];
|
9905 |
|
9906 | this.resetStream_();
|
9907 | this.trigger('done', 'VideoSegmentStream');
|
9908 | return;
|
9909 | }
|
9910 |
|
9911 |
|
9912 |
|
9913 | trackDecodeInfo.clearDtsInfo(track);
|
9914 | gops = alignedGops;
|
9915 | }
|
9916 |
|
9917 | trackDecodeInfo.collectDtsInfo(track, gops);
|
9918 |
|
9919 |
|
9920 | track.samples = frameUtils.generateSampleTable(gops);
|
9921 |
|
9922 | mdat = mp4Generator.mdat(frameUtils.concatenateNalData(gops));
|
9923 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
9924 | this.trigger('processedGopsInfo', gops.map(function (gop) {
|
9925 | return {
|
9926 | pts: gop.pts,
|
9927 | dts: gop.dts,
|
9928 | byteLength: gop.byteLength
|
9929 | };
|
9930 | }));
|
9931 | firstGop = gops[0];
|
9932 | lastGop = gops[gops.length - 1];
|
9933 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(track.baseMediaDecodeTime, firstGop.dts, firstGop.pts, lastGop.dts + lastGop.duration, lastGop.pts + lastGop.duration, prependedContentDuration));
|
9934 | this.trigger('timingInfo', {
|
9935 | start: gops[0].pts,
|
9936 | end: gops[gops.length - 1].pts + gops[gops.length - 1].duration
|
9937 | });
|
9938 |
|
9939 | this.gopCache_.unshift({
|
9940 | gop: gops.pop(),
|
9941 | pps: track.pps,
|
9942 | sps: track.sps
|
9943 | });
|
9944 |
|
9945 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
9946 |
|
9947 | nalUnits = [];
|
9948 | this.trigger('baseMediaDecodeTime', track.baseMediaDecodeTime);
|
9949 | this.trigger('timelineStartInfo', track.timelineStartInfo);
|
9950 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
9951 |
|
9952 |
|
9953 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
9954 |
|
9955 | sequenceNumber++;
|
9956 | boxes.set(moof);
|
9957 | boxes.set(mdat, moof.byteLength);
|
9958 | this.trigger('data', {
|
9959 | track: track,
|
9960 | boxes: boxes
|
9961 | });
|
9962 | this.resetStream_();
|
9963 |
|
9964 | this.trigger('done', 'VideoSegmentStream');
|
9965 | };
|
9966 |
|
9967 | this.reset = function () {
|
9968 | this.resetStream_();
|
9969 | nalUnits = [];
|
9970 | this.gopCache_.length = 0;
|
9971 | gopsToAlignWith.length = 0;
|
9972 | this.trigger('reset');
|
9973 | };
|
9974 |
|
9975 | this.resetStream_ = function () {
|
9976 | trackDecodeInfo.clearDtsInfo(track);
|
9977 |
|
9978 |
|
9979 | config = undefined;
|
9980 | pps = undefined;
|
9981 | };
|
9982 |
|
9983 |
|
9984 |
|
9985 | this.getGopForFusion_ = function (nalUnit) {
|
9986 | var halfSecond = 45000,
|
9987 |
|
9988 | allowableOverlap = 10000,
|
9989 |
|
9990 | nearestDistance = Infinity,
|
9991 | dtsDistance,
|
9992 | nearestGopObj,
|
9993 | currentGop,
|
9994 | currentGopObj,
|
9995 | i;
|
9996 |
|
9997 | for (i = 0; i < this.gopCache_.length; i++) {
|
9998 | currentGopObj = this.gopCache_[i];
|
9999 | currentGop = currentGopObj.gop;
|
10000 |
|
10001 | if (!(track.pps && arrayEquals(track.pps[0], currentGopObj.pps[0])) || !(track.sps && arrayEquals(track.sps[0], currentGopObj.sps[0]))) {
|
10002 | continue;
|
10003 | }
|
10004 |
|
10005 |
|
10006 | if (currentGop.dts < track.timelineStartInfo.dts) {
|
10007 | continue;
|
10008 | }
|
10009 |
|
10010 |
|
10011 | dtsDistance = nalUnit.dts - currentGop.dts - currentGop.duration;
|
10012 |
|
10013 |
|
10014 | if (dtsDistance >= -allowableOverlap && dtsDistance <= halfSecond) {
|
10015 |
|
10016 |
|
10017 | if (!nearestGopObj || nearestDistance > dtsDistance) {
|
10018 | nearestGopObj = currentGopObj;
|
10019 | nearestDistance = dtsDistance;
|
10020 | }
|
10021 | }
|
10022 | }
|
10023 |
|
10024 | if (nearestGopObj) {
|
10025 | return nearestGopObj.gop;
|
10026 | }
|
10027 |
|
10028 | return null;
|
10029 | };
|
10030 |
|
10031 |
|
10032 |
|
10033 | this.alignGopsAtStart_ = function (gops) {
|
10034 | var alignIndex, gopIndex, align, gop, byteLength, nalCount, duration, alignedGops;
|
10035 | byteLength = gops.byteLength;
|
10036 | nalCount = gops.nalCount;
|
10037 | duration = gops.duration;
|
10038 | alignIndex = gopIndex = 0;
|
10039 |
|
10040 | while (alignIndex < gopsToAlignWith.length && gopIndex < gops.length) {
|
10041 | align = gopsToAlignWith[alignIndex];
|
10042 | gop = gops[gopIndex];
|
10043 |
|
10044 | if (align.pts === gop.pts) {
|
10045 | break;
|
10046 | }
|
10047 |
|
10048 | if (gop.pts > align.pts) {
|
10049 |
|
10050 |
|
10051 | alignIndex++;
|
10052 | continue;
|
10053 | }
|
10054 |
|
10055 |
|
10056 |
|
10057 | gopIndex++;
|
10058 | byteLength -= gop.byteLength;
|
10059 | nalCount -= gop.nalCount;
|
10060 | duration -= gop.duration;
|
10061 | }
|
10062 |
|
10063 | if (gopIndex === 0) {
|
10064 |
|
10065 | return gops;
|
10066 | }
|
10067 |
|
10068 | if (gopIndex === gops.length) {
|
10069 |
|
10070 | return null;
|
10071 | }
|
10072 |
|
10073 | alignedGops = gops.slice(gopIndex);
|
10074 | alignedGops.byteLength = byteLength;
|
10075 | alignedGops.duration = duration;
|
10076 | alignedGops.nalCount = nalCount;
|
10077 | alignedGops.pts = alignedGops[0].pts;
|
10078 | alignedGops.dts = alignedGops[0].dts;
|
10079 | return alignedGops;
|
10080 | };
|
10081 |
|
10082 |
|
10083 |
|
10084 | this.alignGopsAtEnd_ = function (gops) {
|
10085 | var alignIndex, gopIndex, align, gop, alignEndIndex, matchFound;
|
10086 | alignIndex = gopsToAlignWith.length - 1;
|
10087 | gopIndex = gops.length - 1;
|
10088 | alignEndIndex = null;
|
10089 | matchFound = false;
|
10090 |
|
10091 | while (alignIndex >= 0 && gopIndex >= 0) {
|
10092 | align = gopsToAlignWith[alignIndex];
|
10093 | gop = gops[gopIndex];
|
10094 |
|
10095 | if (align.pts === gop.pts) {
|
10096 | matchFound = true;
|
10097 | break;
|
10098 | }
|
10099 |
|
10100 | if (align.pts > gop.pts) {
|
10101 | alignIndex--;
|
10102 | continue;
|
10103 | }
|
10104 |
|
10105 | if (alignIndex === gopsToAlignWith.length - 1) {
|
10106 |
|
10107 |
|
10108 |
|
10109 | alignEndIndex = gopIndex;
|
10110 | }
|
10111 |
|
10112 | gopIndex--;
|
10113 | }
|
10114 |
|
10115 | if (!matchFound && alignEndIndex === null) {
|
10116 | return null;
|
10117 | }
|
10118 |
|
10119 | var trimIndex;
|
10120 |
|
10121 | if (matchFound) {
|
10122 | trimIndex = gopIndex;
|
10123 | } else {
|
10124 | trimIndex = alignEndIndex;
|
10125 | }
|
10126 |
|
10127 | if (trimIndex === 0) {
|
10128 | return gops;
|
10129 | }
|
10130 |
|
10131 | var alignedGops = gops.slice(trimIndex);
|
10132 | var metadata = alignedGops.reduce(function (total, gop) {
|
10133 | total.byteLength += gop.byteLength;
|
10134 | total.duration += gop.duration;
|
10135 | total.nalCount += gop.nalCount;
|
10136 | return total;
|
10137 | }, {
|
10138 | byteLength: 0,
|
10139 | duration: 0,
|
10140 | nalCount: 0
|
10141 | });
|
10142 | alignedGops.byteLength = metadata.byteLength;
|
10143 | alignedGops.duration = metadata.duration;
|
10144 | alignedGops.nalCount = metadata.nalCount;
|
10145 | alignedGops.pts = alignedGops[0].pts;
|
10146 | alignedGops.dts = alignedGops[0].dts;
|
10147 | return alignedGops;
|
10148 | };
|
10149 |
|
10150 | this.alignGopsWith = function (newGopsToAlignWith) {
|
10151 | gopsToAlignWith = newGopsToAlignWith;
|
10152 | };
|
10153 | };
|
10154 |
|
10155 | _VideoSegmentStream.prototype = new stream();
|
10156 | |
10157 |
|
10158 |
|
10159 |
|
10160 |
|
10161 |
|
10162 |
|
10163 |
|
10164 |
|
10165 | _CoalesceStream = function CoalesceStream(options, metadataStream) {
|
10166 |
|
10167 |
|
10168 |
|
10169 | this.numberOfTracks = 0;
|
10170 | this.metadataStream = metadataStream;
|
10171 | options = options || {};
|
10172 |
|
10173 | if (typeof options.remux !== 'undefined') {
|
10174 | this.remuxTracks = !!options.remux;
|
10175 | } else {
|
10176 | this.remuxTracks = true;
|
10177 | }
|
10178 |
|
10179 | if (typeof options.keepOriginalTimestamps === 'boolean') {
|
10180 | this.keepOriginalTimestamps = options.keepOriginalTimestamps;
|
10181 | } else {
|
10182 | this.keepOriginalTimestamps = false;
|
10183 | }
|
10184 |
|
10185 | this.pendingTracks = [];
|
10186 | this.videoTrack = null;
|
10187 | this.pendingBoxes = [];
|
10188 | this.pendingCaptions = [];
|
10189 | this.pendingMetadata = [];
|
10190 | this.pendingBytes = 0;
|
10191 | this.emittedTracks = 0;
|
10192 |
|
10193 | _CoalesceStream.prototype.init.call(this);
|
10194 |
|
10195 |
|
10196 | this.push = function (output) {
|
10197 |
|
10198 |
|
10199 | if (output.text) {
|
10200 | return this.pendingCaptions.push(output);
|
10201 | }
|
10202 |
|
10203 |
|
10204 | if (output.frames) {
|
10205 | return this.pendingMetadata.push(output);
|
10206 | }
|
10207 |
|
10208 |
|
10209 |
|
10210 |
|
10211 | this.pendingTracks.push(output.track);
|
10212 | this.pendingBytes += output.boxes.byteLength;
|
10213 |
|
10214 |
|
10215 |
|
10216 |
|
10217 |
|
10218 |
|
10219 | if (output.track.type === 'video') {
|
10220 | this.videoTrack = output.track;
|
10221 | this.pendingBoxes.push(output.boxes);
|
10222 | }
|
10223 |
|
10224 | if (output.track.type === 'audio') {
|
10225 | this.audioTrack = output.track;
|
10226 | this.pendingBoxes.unshift(output.boxes);
|
10227 | }
|
10228 | };
|
10229 | };
|
10230 |
|
10231 | _CoalesceStream.prototype = new stream();
|
10232 |
|
10233 | _CoalesceStream.prototype.flush = function (flushSource) {
|
10234 | var offset = 0,
|
10235 | event = {
|
10236 | captions: [],
|
10237 | captionStreams: {},
|
10238 | metadata: [],
|
10239 | info: {}
|
10240 | },
|
10241 | caption,
|
10242 | id3,
|
10243 | initSegment,
|
10244 | timelineStartPts = 0,
|
10245 | i;
|
10246 |
|
10247 | if (this.pendingTracks.length < this.numberOfTracks) {
|
10248 | if (flushSource !== 'VideoSegmentStream' && flushSource !== 'AudioSegmentStream') {
|
10249 |
|
10250 |
|
10251 |
|
10252 | return;
|
10253 | } else if (this.remuxTracks) {
|
10254 |
|
10255 |
|
10256 | return;
|
10257 | } else if (this.pendingTracks.length === 0) {
|
10258 |
|
10259 |
|
10260 |
|
10261 |
|
10262 |
|
10263 |
|
10264 | this.emittedTracks++;
|
10265 |
|
10266 | if (this.emittedTracks >= this.numberOfTracks) {
|
10267 | this.trigger('done');
|
10268 | this.emittedTracks = 0;
|
10269 | }
|
10270 |
|
10271 | return;
|
10272 | }
|
10273 | }
|
10274 |
|
10275 | if (this.videoTrack) {
|
10276 | timelineStartPts = this.videoTrack.timelineStartInfo.pts;
|
10277 | videoProperties.forEach(function (prop) {
|
10278 | event.info[prop] = this.videoTrack[prop];
|
10279 | }, this);
|
10280 | } else if (this.audioTrack) {
|
10281 | timelineStartPts = this.audioTrack.timelineStartInfo.pts;
|
10282 | audioProperties.forEach(function (prop) {
|
10283 | event.info[prop] = this.audioTrack[prop];
|
10284 | }, this);
|
10285 | }
|
10286 |
|
10287 | if (this.videoTrack || this.audioTrack) {
|
10288 | if (this.pendingTracks.length === 1) {
|
10289 | event.type = this.pendingTracks[0].type;
|
10290 | } else {
|
10291 | event.type = 'combined';
|
10292 | }
|
10293 |
|
10294 | this.emittedTracks += this.pendingTracks.length;
|
10295 | initSegment = mp4Generator.initSegment(this.pendingTracks);
|
10296 |
|
10297 | event.initSegment = new Uint8Array(initSegment.byteLength);
|
10298 |
|
10299 |
|
10300 | event.initSegment.set(initSegment);
|
10301 |
|
10302 | event.data = new Uint8Array(this.pendingBytes);
|
10303 |
|
10304 | for (i = 0; i < this.pendingBoxes.length; i++) {
|
10305 | event.data.set(this.pendingBoxes[i], offset);
|
10306 | offset += this.pendingBoxes[i].byteLength;
|
10307 | }
|
10308 |
|
10309 |
|
10310 |
|
10311 | for (i = 0; i < this.pendingCaptions.length; i++) {
|
10312 | caption = this.pendingCaptions[i];
|
10313 | caption.startTime = clock.metadataTsToSeconds(caption.startPts, timelineStartPts, this.keepOriginalTimestamps);
|
10314 | caption.endTime = clock.metadataTsToSeconds(caption.endPts, timelineStartPts, this.keepOriginalTimestamps);
|
10315 | event.captionStreams[caption.stream] = true;
|
10316 | event.captions.push(caption);
|
10317 | }
|
10318 |
|
10319 |
|
10320 |
|
10321 | for (i = 0; i < this.pendingMetadata.length; i++) {
|
10322 | id3 = this.pendingMetadata[i];
|
10323 | id3.cueTime = clock.metadataTsToSeconds(id3.pts, timelineStartPts, this.keepOriginalTimestamps);
|
10324 | event.metadata.push(id3);
|
10325 | }
|
10326 |
|
10327 |
|
10328 |
|
10329 | event.metadata.dispatchType = this.metadataStream.dispatchType;
|
10330 |
|
10331 | this.pendingTracks.length = 0;
|
10332 | this.videoTrack = null;
|
10333 | this.pendingBoxes.length = 0;
|
10334 | this.pendingCaptions.length = 0;
|
10335 | this.pendingBytes = 0;
|
10336 | this.pendingMetadata.length = 0;
|
10337 |
|
10338 |
|
10339 |
|
10340 | this.trigger('data', event);
|
10341 |
|
10342 |
|
10343 |
|
10344 |
|
10345 | for (i = 0; i < event.captions.length; i++) {
|
10346 | caption = event.captions[i];
|
10347 | this.trigger('caption', caption);
|
10348 | }
|
10349 |
|
10350 |
|
10351 |
|
10352 |
|
10353 |
|
10354 | for (i = 0; i < event.metadata.length; i++) {
|
10355 | id3 = event.metadata[i];
|
10356 | this.trigger('id3Frame', id3);
|
10357 | }
|
10358 | }
|
10359 |
|
10360 |
|
10361 | if (this.emittedTracks >= this.numberOfTracks) {
|
10362 | this.trigger('done');
|
10363 | this.emittedTracks = 0;
|
10364 | }
|
10365 | };
|
10366 |
|
10367 | _CoalesceStream.prototype.setRemux = function (val) {
|
10368 | this.remuxTracks = val;
|
10369 | };
|
10370 | |
10371 |
|
10372 |
|
10373 |
|
10374 |
|
10375 |
|
10376 |
|
10377 |
|
10378 | _Transmuxer = function Transmuxer(options) {
|
10379 | var self = this,
|
10380 | hasFlushed = true,
|
10381 | videoTrack,
|
10382 | audioTrack;
|
10383 |
|
10384 | _Transmuxer.prototype.init.call(this);
|
10385 |
|
10386 | options = options || {};
|
10387 | this.baseMediaDecodeTime = options.baseMediaDecodeTime || 0;
|
10388 | this.transmuxPipeline_ = {};
|
10389 |
|
10390 | this.setupAacPipeline = function () {
|
10391 | var pipeline = {};
|
10392 | this.transmuxPipeline_ = pipeline;
|
10393 | pipeline.type = 'aac';
|
10394 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
10395 |
|
10396 | pipeline.aacStream = new aac();
|
10397 | pipeline.audioTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('audio');
|
10398 | pipeline.timedMetadataTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('timed-metadata');
|
10399 | pipeline.adtsStream = new adts();
|
10400 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
10401 | pipeline.headOfPipeline = pipeline.aacStream;
|
10402 | pipeline.aacStream.pipe(pipeline.audioTimestampRolloverStream).pipe(pipeline.adtsStream);
|
10403 | pipeline.aacStream.pipe(pipeline.timedMetadataTimestampRolloverStream).pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
10404 | pipeline.metadataStream.on('timestamp', function (frame) {
|
10405 | pipeline.aacStream.setTimestamp(frame.timeStamp);
|
10406 | });
|
10407 | pipeline.aacStream.on('data', function (data) {
|
10408 | if (data.type !== 'timed-metadata' && data.type !== 'audio' || pipeline.audioSegmentStream) {
|
10409 | return;
|
10410 | }
|
10411 |
|
10412 | audioTrack = audioTrack || {
|
10413 | timelineStartInfo: {
|
10414 | baseMediaDecodeTime: self.baseMediaDecodeTime
|
10415 | },
|
10416 | codec: 'adts',
|
10417 | type: 'audio'
|
10418 | };
|
10419 |
|
10420 | pipeline.coalesceStream.numberOfTracks++;
|
10421 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
10422 | pipeline.audioSegmentStream.on('log', self.getLogTrigger_('audioSegmentStream'));
|
10423 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
10424 |
|
10425 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
10426 |
|
10427 | self.trigger('trackinfo', {
|
10428 | hasAudio: !!audioTrack,
|
10429 | hasVideo: !!videoTrack
|
10430 | });
|
10431 | });
|
10432 |
|
10433 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
10434 |
|
10435 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
10436 | addPipelineLogRetriggers(this, pipeline);
|
10437 | };
|
10438 |
|
10439 | this.setupTsPipeline = function () {
|
10440 | var pipeline = {};
|
10441 | this.transmuxPipeline_ = pipeline;
|
10442 | pipeline.type = 'ts';
|
10443 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
10444 |
|
10445 | pipeline.packetStream = new m2ts_1.TransportPacketStream();
|
10446 | pipeline.parseStream = new m2ts_1.TransportParseStream();
|
10447 | pipeline.elementaryStream = new m2ts_1.ElementaryStream();
|
10448 | pipeline.timestampRolloverStream = new m2ts_1.TimestampRolloverStream();
|
10449 | pipeline.adtsStream = new adts();
|
10450 | pipeline.h264Stream = new H264Stream();
|
10451 | pipeline.captionStream = new m2ts_1.CaptionStream(options);
|
10452 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
10453 | pipeline.headOfPipeline = pipeline.packetStream;
|
10454 |
|
10455 | pipeline.packetStream.pipe(pipeline.parseStream).pipe(pipeline.elementaryStream).pipe(pipeline.timestampRolloverStream);
|
10456 |
|
10457 |
|
10458 | pipeline.timestampRolloverStream.pipe(pipeline.h264Stream);
|
10459 | pipeline.timestampRolloverStream.pipe(pipeline.adtsStream);
|
10460 | pipeline.timestampRolloverStream.pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
10461 |
|
10462 | pipeline.h264Stream.pipe(pipeline.captionStream).pipe(pipeline.coalesceStream);
|
10463 | pipeline.elementaryStream.on('data', function (data) {
|
10464 | var i;
|
10465 |
|
10466 | if (data.type === 'metadata') {
|
10467 | i = data.tracks.length;
|
10468 |
|
10469 | while (i--) {
|
10470 | if (!videoTrack && data.tracks[i].type === 'video') {
|
10471 | videoTrack = data.tracks[i];
|
10472 | videoTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
10473 | } else if (!audioTrack && data.tracks[i].type === 'audio') {
|
10474 | audioTrack = data.tracks[i];
|
10475 | audioTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
10476 | }
|
10477 | }
|
10478 |
|
10479 |
|
10480 | if (videoTrack && !pipeline.videoSegmentStream) {
|
10481 | pipeline.coalesceStream.numberOfTracks++;
|
10482 | pipeline.videoSegmentStream = new _VideoSegmentStream(videoTrack, options);
|
10483 | pipeline.videoSegmentStream.on('log', self.getLogTrigger_('videoSegmentStream'));
|
10484 | pipeline.videoSegmentStream.on('timelineStartInfo', function (timelineStartInfo) {
|
10485 |
|
10486 |
|
10487 |
|
10488 |
|
10489 | if (audioTrack && !options.keepOriginalTimestamps) {
|
10490 | audioTrack.timelineStartInfo = timelineStartInfo;
|
10491 |
|
10492 |
|
10493 |
|
10494 |
|
10495 | pipeline.audioSegmentStream.setEarliestDts(timelineStartInfo.dts - self.baseMediaDecodeTime);
|
10496 | }
|
10497 | });
|
10498 | pipeline.videoSegmentStream.on('processedGopsInfo', self.trigger.bind(self, 'gopInfo'));
|
10499 | pipeline.videoSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'videoSegmentTimingInfo'));
|
10500 | pipeline.videoSegmentStream.on('baseMediaDecodeTime', function (baseMediaDecodeTime) {
|
10501 | if (audioTrack) {
|
10502 | pipeline.audioSegmentStream.setVideoBaseMediaDecodeTime(baseMediaDecodeTime);
|
10503 | }
|
10504 | });
|
10505 | pipeline.videoSegmentStream.on('timingInfo', self.trigger.bind(self, 'videoTimingInfo'));
|
10506 |
|
10507 | pipeline.h264Stream.pipe(pipeline.videoSegmentStream).pipe(pipeline.coalesceStream);
|
10508 | }
|
10509 |
|
10510 | if (audioTrack && !pipeline.audioSegmentStream) {
|
10511 |
|
10512 | pipeline.coalesceStream.numberOfTracks++;
|
10513 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
10514 | pipeline.audioSegmentStream.on('log', self.getLogTrigger_('audioSegmentStream'));
|
10515 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
10516 | pipeline.audioSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'audioSegmentTimingInfo'));
|
10517 |
|
10518 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
10519 | }
|
10520 |
|
10521 |
|
10522 | self.trigger('trackinfo', {
|
10523 | hasAudio: !!audioTrack,
|
10524 | hasVideo: !!videoTrack
|
10525 | });
|
10526 | }
|
10527 | });
|
10528 |
|
10529 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
10530 | pipeline.coalesceStream.on('id3Frame', function (id3Frame) {
|
10531 | id3Frame.dispatchType = pipeline.metadataStream.dispatchType;
|
10532 | self.trigger('id3Frame', id3Frame);
|
10533 | });
|
10534 | pipeline.coalesceStream.on('caption', this.trigger.bind(this, 'caption'));
|
10535 |
|
10536 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
10537 | addPipelineLogRetriggers(this, pipeline);
|
10538 | };
|
10539 |
|
10540 |
|
10541 | this.setBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
10542 | var pipeline = this.transmuxPipeline_;
|
10543 |
|
10544 | if (!options.keepOriginalTimestamps) {
|
10545 | this.baseMediaDecodeTime = baseMediaDecodeTime;
|
10546 | }
|
10547 |
|
10548 | if (audioTrack) {
|
10549 | audioTrack.timelineStartInfo.dts = undefined;
|
10550 | audioTrack.timelineStartInfo.pts = undefined;
|
10551 | trackDecodeInfo.clearDtsInfo(audioTrack);
|
10552 |
|
10553 | if (pipeline.audioTimestampRolloverStream) {
|
10554 | pipeline.audioTimestampRolloverStream.discontinuity();
|
10555 | }
|
10556 | }
|
10557 |
|
10558 | if (videoTrack) {
|
10559 | if (pipeline.videoSegmentStream) {
|
10560 | pipeline.videoSegmentStream.gopCache_ = [];
|
10561 | }
|
10562 |
|
10563 | videoTrack.timelineStartInfo.dts = undefined;
|
10564 | videoTrack.timelineStartInfo.pts = undefined;
|
10565 | trackDecodeInfo.clearDtsInfo(videoTrack);
|
10566 | pipeline.captionStream.reset();
|
10567 | }
|
10568 |
|
10569 | if (pipeline.timestampRolloverStream) {
|
10570 | pipeline.timestampRolloverStream.discontinuity();
|
10571 | }
|
10572 | };
|
10573 |
|
10574 | this.setAudioAppendStart = function (timestamp) {
|
10575 | if (audioTrack) {
|
10576 | this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(timestamp);
|
10577 | }
|
10578 | };
|
10579 |
|
10580 | this.setRemux = function (val) {
|
10581 | var pipeline = this.transmuxPipeline_;
|
10582 | options.remux = val;
|
10583 |
|
10584 | if (pipeline && pipeline.coalesceStream) {
|
10585 | pipeline.coalesceStream.setRemux(val);
|
10586 | }
|
10587 | };
|
10588 |
|
10589 | this.alignGopsWith = function (gopsToAlignWith) {
|
10590 | if (videoTrack && this.transmuxPipeline_.videoSegmentStream) {
|
10591 | this.transmuxPipeline_.videoSegmentStream.alignGopsWith(gopsToAlignWith);
|
10592 | }
|
10593 | };
|
10594 |
|
10595 | this.getLogTrigger_ = function (key) {
|
10596 | var self = this;
|
10597 | return function (event) {
|
10598 | event.stream = key;
|
10599 | self.trigger('log', event);
|
10600 | };
|
10601 | };
|
10602 |
|
10603 |
|
10604 | this.push = function (data) {
|
10605 | if (hasFlushed) {
|
10606 | var isAac = isLikelyAacData(data);
|
10607 |
|
10608 | if (isAac && this.transmuxPipeline_.type !== 'aac') {
|
10609 | this.setupAacPipeline();
|
10610 | } else if (!isAac && this.transmuxPipeline_.type !== 'ts') {
|
10611 | this.setupTsPipeline();
|
10612 | }
|
10613 |
|
10614 | hasFlushed = false;
|
10615 | }
|
10616 |
|
10617 | this.transmuxPipeline_.headOfPipeline.push(data);
|
10618 | };
|
10619 |
|
10620 |
|
10621 | this.flush = function () {
|
10622 | hasFlushed = true;
|
10623 |
|
10624 | this.transmuxPipeline_.headOfPipeline.flush();
|
10625 | };
|
10626 |
|
10627 | this.endTimeline = function () {
|
10628 | this.transmuxPipeline_.headOfPipeline.endTimeline();
|
10629 | };
|
10630 |
|
10631 | this.reset = function () {
|
10632 | if (this.transmuxPipeline_.headOfPipeline) {
|
10633 | this.transmuxPipeline_.headOfPipeline.reset();
|
10634 | }
|
10635 | };
|
10636 |
|
10637 |
|
10638 | this.resetCaptions = function () {
|
10639 | if (this.transmuxPipeline_.captionStream) {
|
10640 | this.transmuxPipeline_.captionStream.reset();
|
10641 | }
|
10642 | };
|
10643 | };
|
10644 |
|
10645 | _Transmuxer.prototype = new stream();
|
10646 | var transmuxer = {
|
10647 | Transmuxer: _Transmuxer,
|
10648 | VideoSegmentStream: _VideoSegmentStream,
|
10649 | AudioSegmentStream: _AudioSegmentStream,
|
10650 | AUDIO_PROPERTIES: audioProperties,
|
10651 | VIDEO_PROPERTIES: videoProperties,
|
10652 |
|
10653 | generateSegmentTimingInfo: generateSegmentTimingInfo
|
10654 | };
|
10655 | |
10656 |
|
10657 |
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 | var toUnsigned$3 = function toUnsigned(value) {
|
10663 | return value >>> 0;
|
10664 | };
|
10665 |
|
10666 | var toHexString$1 = function toHexString(value) {
|
10667 | return ('00' + value.toString(16)).slice(-2);
|
10668 | };
|
10669 |
|
10670 | var bin = {
|
10671 | toUnsigned: toUnsigned$3,
|
10672 | toHexString: toHexString$1
|
10673 | };
|
10674 |
|
10675 | var parseType$1 = function parseType(buffer) {
|
10676 | var result = '';
|
10677 | result += String.fromCharCode(buffer[0]);
|
10678 | result += String.fromCharCode(buffer[1]);
|
10679 | result += String.fromCharCode(buffer[2]);
|
10680 | result += String.fromCharCode(buffer[3]);
|
10681 | return result;
|
10682 | };
|
10683 |
|
10684 | var parseType_1 = parseType$1;
|
10685 | var toUnsigned$2 = bin.toUnsigned;
|
10686 |
|
10687 | var findBox = function findBox(data, path) {
|
10688 | var results = [],
|
10689 | i,
|
10690 | size,
|
10691 | type,
|
10692 | end,
|
10693 | subresults;
|
10694 |
|
10695 | if (!path.length) {
|
10696 |
|
10697 | return null;
|
10698 | }
|
10699 |
|
10700 | for (i = 0; i < data.byteLength;) {
|
10701 | size = toUnsigned$2(data[i] << 24 | data[i + 1] << 16 | data[i + 2] << 8 | data[i + 3]);
|
10702 | type = parseType_1(data.subarray(i + 4, i + 8));
|
10703 | end = size > 1 ? i + size : data.byteLength;
|
10704 |
|
10705 | if (type === path[0]) {
|
10706 | if (path.length === 1) {
|
10707 |
|
10708 |
|
10709 | results.push(data.subarray(i + 8, end));
|
10710 | } else {
|
10711 |
|
10712 | subresults = findBox(data.subarray(i + 8, end), path.slice(1));
|
10713 |
|
10714 | if (subresults.length) {
|
10715 | results = results.concat(subresults);
|
10716 | }
|
10717 | }
|
10718 | }
|
10719 |
|
10720 | i = end;
|
10721 | }
|
10722 |
|
10723 |
|
10724 | return results;
|
10725 | };
|
10726 |
|
10727 | var findBox_1 = findBox;
|
10728 | var toUnsigned$1 = bin.toUnsigned;
|
10729 | var getUint64$1 = numbers.getUint64;
|
10730 |
|
10731 | var tfdt = function tfdt(data) {
|
10732 | var result = {
|
10733 | version: data[0],
|
10734 | flags: new Uint8Array(data.subarray(1, 4))
|
10735 | };
|
10736 |
|
10737 | if (result.version === 1) {
|
10738 | result.baseMediaDecodeTime = getUint64$1(data.subarray(4));
|
10739 | } else {
|
10740 | result.baseMediaDecodeTime = toUnsigned$1(data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);
|
10741 | }
|
10742 |
|
10743 | return result;
|
10744 | };
|
10745 |
|
10746 | var parseTfdt = tfdt;
|
10747 |
|
10748 | var parseSampleFlags = function parseSampleFlags(flags) {
|
10749 | return {
|
10750 | isLeading: (flags[0] & 0x0c) >>> 2,
|
10751 | dependsOn: flags[0] & 0x03,
|
10752 | isDependedOn: (flags[1] & 0xc0) >>> 6,
|
10753 | hasRedundancy: (flags[1] & 0x30) >>> 4,
|
10754 | paddingValue: (flags[1] & 0x0e) >>> 1,
|
10755 | isNonSyncSample: flags[1] & 0x01,
|
10756 | degradationPriority: flags[2] << 8 | flags[3]
|
10757 | };
|
10758 | };
|
10759 |
|
10760 | var parseSampleFlags_1 = parseSampleFlags;
|
10761 |
|
10762 | var trun = function trun(data) {
|
10763 | var result = {
|
10764 | version: data[0],
|
10765 | flags: new Uint8Array(data.subarray(1, 4)),
|
10766 | samples: []
|
10767 | },
|
10768 | view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
10769 |
|
10770 | dataOffsetPresent = result.flags[2] & 0x01,
|
10771 |
|
10772 | firstSampleFlagsPresent = result.flags[2] & 0x04,
|
10773 |
|
10774 | sampleDurationPresent = result.flags[1] & 0x01,
|
10775 |
|
10776 | sampleSizePresent = result.flags[1] & 0x02,
|
10777 |
|
10778 | sampleFlagsPresent = result.flags[1] & 0x04,
|
10779 |
|
10780 | sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08,
|
10781 |
|
10782 | sampleCount = view.getUint32(4),
|
10783 | offset = 8,
|
10784 | sample;
|
10785 |
|
10786 | if (dataOffsetPresent) {
|
10787 |
|
10788 | result.dataOffset = view.getInt32(offset);
|
10789 | offset += 4;
|
10790 | }
|
10791 |
|
10792 |
|
10793 |
|
10794 | if (firstSampleFlagsPresent && sampleCount) {
|
10795 | sample = {
|
10796 | flags: parseSampleFlags_1(data.subarray(offset, offset + 4))
|
10797 | };
|
10798 | offset += 4;
|
10799 |
|
10800 | if (sampleDurationPresent) {
|
10801 | sample.duration = view.getUint32(offset);
|
10802 | offset += 4;
|
10803 | }
|
10804 |
|
10805 | if (sampleSizePresent) {
|
10806 | sample.size = view.getUint32(offset);
|
10807 | offset += 4;
|
10808 | }
|
10809 |
|
10810 | if (sampleCompositionTimeOffsetPresent) {
|
10811 | if (result.version === 1) {
|
10812 | sample.compositionTimeOffset = view.getInt32(offset);
|
10813 | } else {
|
10814 | sample.compositionTimeOffset = view.getUint32(offset);
|
10815 | }
|
10816 |
|
10817 | offset += 4;
|
10818 | }
|
10819 |
|
10820 | result.samples.push(sample);
|
10821 | sampleCount--;
|
10822 | }
|
10823 |
|
10824 | while (sampleCount--) {
|
10825 | sample = {};
|
10826 |
|
10827 | if (sampleDurationPresent) {
|
10828 | sample.duration = view.getUint32(offset);
|
10829 | offset += 4;
|
10830 | }
|
10831 |
|
10832 | if (sampleSizePresent) {
|
10833 | sample.size = view.getUint32(offset);
|
10834 | offset += 4;
|
10835 | }
|
10836 |
|
10837 | if (sampleFlagsPresent) {
|
10838 | sample.flags = parseSampleFlags_1(data.subarray(offset, offset + 4));
|
10839 | offset += 4;
|
10840 | }
|
10841 |
|
10842 | if (sampleCompositionTimeOffsetPresent) {
|
10843 | if (result.version === 1) {
|
10844 | sample.compositionTimeOffset = view.getInt32(offset);
|
10845 | } else {
|
10846 | sample.compositionTimeOffset = view.getUint32(offset);
|
10847 | }
|
10848 |
|
10849 | offset += 4;
|
10850 | }
|
10851 |
|
10852 | result.samples.push(sample);
|
10853 | }
|
10854 |
|
10855 | return result;
|
10856 | };
|
10857 |
|
10858 | var parseTrun = trun;
|
10859 |
|
10860 | var tfhd = function tfhd(data) {
|
10861 | var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
10862 | result = {
|
10863 | version: data[0],
|
10864 | flags: new Uint8Array(data.subarray(1, 4)),
|
10865 | trackId: view.getUint32(4)
|
10866 | },
|
10867 | baseDataOffsetPresent = result.flags[2] & 0x01,
|
10868 | sampleDescriptionIndexPresent = result.flags[2] & 0x02,
|
10869 | defaultSampleDurationPresent = result.flags[2] & 0x08,
|
10870 | defaultSampleSizePresent = result.flags[2] & 0x10,
|
10871 | defaultSampleFlagsPresent = result.flags[2] & 0x20,
|
10872 | durationIsEmpty = result.flags[0] & 0x010000,
|
10873 | defaultBaseIsMoof = result.flags[0] & 0x020000,
|
10874 | i;
|
10875 | i = 8;
|
10876 |
|
10877 | if (baseDataOffsetPresent) {
|
10878 | i += 4;
|
10879 |
|
10880 |
|
10881 | result.baseDataOffset = view.getUint32(12);
|
10882 | i += 4;
|
10883 | }
|
10884 |
|
10885 | if (sampleDescriptionIndexPresent) {
|
10886 | result.sampleDescriptionIndex = view.getUint32(i);
|
10887 | i += 4;
|
10888 | }
|
10889 |
|
10890 | if (defaultSampleDurationPresent) {
|
10891 | result.defaultSampleDuration = view.getUint32(i);
|
10892 | i += 4;
|
10893 | }
|
10894 |
|
10895 | if (defaultSampleSizePresent) {
|
10896 | result.defaultSampleSize = view.getUint32(i);
|
10897 | i += 4;
|
10898 | }
|
10899 |
|
10900 | if (defaultSampleFlagsPresent) {
|
10901 | result.defaultSampleFlags = view.getUint32(i);
|
10902 | }
|
10903 |
|
10904 | if (durationIsEmpty) {
|
10905 | result.durationIsEmpty = true;
|
10906 | }
|
10907 |
|
10908 | if (!baseDataOffsetPresent && defaultBaseIsMoof) {
|
10909 | result.baseDataOffsetIsMoof = true;
|
10910 | }
|
10911 |
|
10912 | return result;
|
10913 | };
|
10914 |
|
10915 | var parseTfhd = tfhd;
|
10916 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
10917 | var win;
|
10918 |
|
10919 | if (typeof window !== "undefined") {
|
10920 | win = window;
|
10921 | } else if (typeof commonjsGlobal !== "undefined") {
|
10922 | win = commonjsGlobal;
|
10923 | } else if (typeof self !== "undefined") {
|
10924 | win = self;
|
10925 | } else {
|
10926 | win = {};
|
10927 | }
|
10928 |
|
10929 | var window_1 = win;
|
10930 | var discardEmulationPreventionBytes = captionPacketParser.discardEmulationPreventionBytes;
|
10931 | var CaptionStream = captionStream.CaptionStream;
|
10932 | |
10933 |
|
10934 |
|
10935 |
|
10936 |
|
10937 |
|
10938 |
|
10939 |
|
10940 |
|
10941 |
|
10942 |
|
10943 | var mapToSample = function mapToSample(offset, samples) {
|
10944 | var approximateOffset = offset;
|
10945 |
|
10946 | for (var i = 0; i < samples.length; i++) {
|
10947 | var sample = samples[i];
|
10948 |
|
10949 | if (approximateOffset < sample.size) {
|
10950 | return sample;
|
10951 | }
|
10952 |
|
10953 | approximateOffset -= sample.size;
|
10954 | }
|
10955 |
|
10956 | return null;
|
10957 | };
|
10958 | |
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 |
|
10966 |
|
10967 |
|
10968 |
|
10969 |
|
10970 |
|
10971 |
|
10972 |
|
10973 |
|
10974 | var findSeiNals = function findSeiNals(avcStream, samples, trackId) {
|
10975 | var avcView = new DataView(avcStream.buffer, avcStream.byteOffset, avcStream.byteLength),
|
10976 | result = {
|
10977 | logs: [],
|
10978 | seiNals: []
|
10979 | },
|
10980 | seiNal,
|
10981 | i,
|
10982 | length,
|
10983 | lastMatchedSample;
|
10984 |
|
10985 | for (i = 0; i + 4 < avcStream.length; i += length) {
|
10986 | length = avcView.getUint32(i);
|
10987 | i += 4;
|
10988 |
|
10989 | if (length <= 0) {
|
10990 | continue;
|
10991 | }
|
10992 |
|
10993 | switch (avcStream[i] & 0x1F) {
|
10994 | case 0x06:
|
10995 | var data = avcStream.subarray(i + 1, i + 1 + length);
|
10996 | var matchingSample = mapToSample(i, samples);
|
10997 | seiNal = {
|
10998 | nalUnitType: 'sei_rbsp',
|
10999 | size: length,
|
11000 | data: data,
|
11001 | escapedRBSP: discardEmulationPreventionBytes(data),
|
11002 | trackId: trackId
|
11003 | };
|
11004 |
|
11005 | if (matchingSample) {
|
11006 | seiNal.pts = matchingSample.pts;
|
11007 | seiNal.dts = matchingSample.dts;
|
11008 | lastMatchedSample = matchingSample;
|
11009 | } else if (lastMatchedSample) {
|
11010 |
|
11011 |
|
11012 | seiNal.pts = lastMatchedSample.pts;
|
11013 | seiNal.dts = lastMatchedSample.dts;
|
11014 | } else {
|
11015 | result.logs.push({
|
11016 | level: 'warn',
|
11017 | message: 'We\'ve encountered a nal unit without data at ' + i + ' for trackId ' + trackId + '. See mux.js#223.'
|
11018 | });
|
11019 | break;
|
11020 | }
|
11021 |
|
11022 | result.seiNals.push(seiNal);
|
11023 | break;
|
11024 | }
|
11025 | }
|
11026 |
|
11027 | return result;
|
11028 | };
|
11029 | |
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 |
|
11035 |
|
11036 |
|
11037 |
|
11038 |
|
11039 |
|
11040 |
|
11041 |
|
11042 |
|
11043 |
|
11044 | var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
|
11045 | var currentDts = baseMediaDecodeTime;
|
11046 | var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
|
11047 | var defaultSampleSize = tfhd.defaultSampleSize || 0;
|
11048 | var trackId = tfhd.trackId;
|
11049 | var allSamples = [];
|
11050 | truns.forEach(function (trun) {
|
11051 |
|
11052 |
|
11053 |
|
11054 | var trackRun = parseTrun(trun);
|
11055 | var samples = trackRun.samples;
|
11056 | samples.forEach(function (sample) {
|
11057 | if (sample.duration === undefined) {
|
11058 | sample.duration = defaultSampleDuration;
|
11059 | }
|
11060 |
|
11061 | if (sample.size === undefined) {
|
11062 | sample.size = defaultSampleSize;
|
11063 | }
|
11064 |
|
11065 | sample.trackId = trackId;
|
11066 | sample.dts = currentDts;
|
11067 |
|
11068 | if (sample.compositionTimeOffset === undefined) {
|
11069 | sample.compositionTimeOffset = 0;
|
11070 | }
|
11071 |
|
11072 | if (typeof currentDts === 'bigint') {
|
11073 | sample.pts = currentDts + window_1.BigInt(sample.compositionTimeOffset);
|
11074 | currentDts += window_1.BigInt(sample.duration);
|
11075 | } else {
|
11076 | sample.pts = currentDts + sample.compositionTimeOffset;
|
11077 | currentDts += sample.duration;
|
11078 | }
|
11079 | });
|
11080 | allSamples = allSamples.concat(samples);
|
11081 | });
|
11082 | return allSamples;
|
11083 | };
|
11084 | |
11085 |
|
11086 |
|
11087 |
|
11088 |
|
11089 |
|
11090 |
|
11091 |
|
11092 |
|
11093 |
|
11094 | var parseCaptionNals = function parseCaptionNals(segment, videoTrackId) {
|
11095 |
|
11096 | var trafs = findBox_1(segment, ['moof', 'traf']);
|
11097 |
|
11098 | var mdats = findBox_1(segment, ['mdat']);
|
11099 | var captionNals = {};
|
11100 | var mdatTrafPairs = [];
|
11101 |
|
11102 | mdats.forEach(function (mdat, index) {
|
11103 | var matchingTraf = trafs[index];
|
11104 | mdatTrafPairs.push({
|
11105 | mdat: mdat,
|
11106 | traf: matchingTraf
|
11107 | });
|
11108 | });
|
11109 | mdatTrafPairs.forEach(function (pair) {
|
11110 | var mdat = pair.mdat;
|
11111 | var traf = pair.traf;
|
11112 | var tfhd = findBox_1(traf, ['tfhd']);
|
11113 |
|
11114 | var headerInfo = parseTfhd(tfhd[0]);
|
11115 | var trackId = headerInfo.trackId;
|
11116 | var tfdt = findBox_1(traf, ['tfdt']);
|
11117 |
|
11118 | var baseMediaDecodeTime = tfdt.length > 0 ? parseTfdt(tfdt[0]).baseMediaDecodeTime : 0;
|
11119 | var truns = findBox_1(traf, ['trun']);
|
11120 | var samples;
|
11121 | var result;
|
11122 |
|
11123 | if (videoTrackId === trackId && truns.length > 0) {
|
11124 | samples = parseSamples(truns, baseMediaDecodeTime, headerInfo);
|
11125 | result = findSeiNals(mdat, samples, trackId);
|
11126 |
|
11127 | if (!captionNals[trackId]) {
|
11128 | captionNals[trackId] = {
|
11129 | seiNals: [],
|
11130 | logs: []
|
11131 | };
|
11132 | }
|
11133 |
|
11134 | captionNals[trackId].seiNals = captionNals[trackId].seiNals.concat(result.seiNals);
|
11135 | captionNals[trackId].logs = captionNals[trackId].logs.concat(result.logs);
|
11136 | }
|
11137 | });
|
11138 | return captionNals;
|
11139 | };
|
11140 | |
11141 |
|
11142 |
|
11143 |
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 |
|
11149 |
|
11150 |
|
11151 |
|
11152 |
|
11153 |
|
11154 |
|
11155 |
|
11156 |
|
11157 |
|
11158 | var parseEmbeddedCaptions = function parseEmbeddedCaptions(segment, trackId, timescale) {
|
11159 | var captionNals;
|
11160 |
|
11161 | if (trackId === null) {
|
11162 | return null;
|
11163 | }
|
11164 |
|
11165 | captionNals = parseCaptionNals(segment, trackId);
|
11166 | var trackNals = captionNals[trackId] || {};
|
11167 | return {
|
11168 | seiNals: trackNals.seiNals,
|
11169 | logs: trackNals.logs,
|
11170 | timescale: timescale
|
11171 | };
|
11172 | };
|
11173 | |
11174 |
|
11175 |
|
11176 |
|
11177 |
|
11178 | var CaptionParser = function CaptionParser() {
|
11179 | var isInitialized = false;
|
11180 | var captionStream;
|
11181 |
|
11182 | var segmentCache;
|
11183 |
|
11184 | var trackId;
|
11185 |
|
11186 | var timescale;
|
11187 |
|
11188 | var parsedCaptions;
|
11189 |
|
11190 | var parsingPartial;
|
11191 | |
11192 |
|
11193 |
|
11194 |
|
11195 |
|
11196 | this.isInitialized = function () {
|
11197 | return isInitialized;
|
11198 | };
|
11199 | |
11200 |
|
11201 |
|
11202 |
|
11203 |
|
11204 |
|
11205 | this.init = function (options) {
|
11206 | captionStream = new CaptionStream();
|
11207 | isInitialized = true;
|
11208 | parsingPartial = options ? options.isPartial : false;
|
11209 |
|
11210 | captionStream.on('data', function (event) {
|
11211 |
|
11212 | event.startTime = event.startPts / timescale;
|
11213 | event.endTime = event.endPts / timescale;
|
11214 | parsedCaptions.captions.push(event);
|
11215 | parsedCaptions.captionStreams[event.stream] = true;
|
11216 | });
|
11217 | captionStream.on('log', function (log) {
|
11218 | parsedCaptions.logs.push(log);
|
11219 | });
|
11220 | };
|
11221 | |
11222 |
|
11223 |
|
11224 |
|
11225 |
|
11226 |
|
11227 |
|
11228 | this.isNewInit = function (videoTrackIds, timescales) {
|
11229 | if (videoTrackIds && videoTrackIds.length === 0 || timescales && typeof timescales === 'object' && Object.keys(timescales).length === 0) {
|
11230 | return false;
|
11231 | }
|
11232 |
|
11233 | return trackId !== videoTrackIds[0] || timescale !== timescales[trackId];
|
11234 | };
|
11235 | |
11236 |
|
11237 |
|
11238 |
|
11239 |
|
11240 |
|
11241 |
|
11242 |
|
11243 |
|
11244 |
|
11245 |
|
11246 |
|
11247 | this.parse = function (segment, videoTrackIds, timescales) {
|
11248 | var parsedData;
|
11249 |
|
11250 | if (!this.isInitialized()) {
|
11251 | return null;
|
11252 | } else if (!videoTrackIds || !timescales) {
|
11253 | return null;
|
11254 | } else if (this.isNewInit(videoTrackIds, timescales)) {
|
11255 |
|
11256 |
|
11257 | trackId = videoTrackIds[0];
|
11258 | timescale = timescales[trackId];
|
11259 |
|
11260 |
|
11261 | } else if (trackId === null || !timescale) {
|
11262 | segmentCache.push(segment);
|
11263 | return null;
|
11264 | }
|
11265 |
|
11266 |
|
11267 | while (segmentCache.length > 0) {
|
11268 | var cachedSegment = segmentCache.shift();
|
11269 | this.parse(cachedSegment, videoTrackIds, timescales);
|
11270 | }
|
11271 |
|
11272 | parsedData = parseEmbeddedCaptions(segment, trackId, timescale);
|
11273 |
|
11274 | if (parsedData && parsedData.logs) {
|
11275 | parsedCaptions.logs = parsedCaptions.logs.concat(parsedData.logs);
|
11276 | }
|
11277 |
|
11278 | if (parsedData === null || !parsedData.seiNals) {
|
11279 | if (parsedCaptions.logs.length) {
|
11280 | return {
|
11281 | logs: parsedCaptions.logs,
|
11282 | captions: [],
|
11283 | captionStreams: []
|
11284 | };
|
11285 | }
|
11286 |
|
11287 | return null;
|
11288 | }
|
11289 |
|
11290 | this.pushNals(parsedData.seiNals);
|
11291 |
|
11292 | this.flushStream();
|
11293 | return parsedCaptions;
|
11294 | };
|
11295 | |
11296 |
|
11297 |
|
11298 |
|
11299 |
|
11300 |
|
11301 |
|
11302 |
|
11303 | this.pushNals = function (nals) {
|
11304 | if (!this.isInitialized() || !nals || nals.length === 0) {
|
11305 | return null;
|
11306 | }
|
11307 |
|
11308 | nals.forEach(function (nal) {
|
11309 | captionStream.push(nal);
|
11310 | });
|
11311 | };
|
11312 | |
11313 |
|
11314 |
|
11315 |
|
11316 |
|
11317 |
|
11318 | this.flushStream = function () {
|
11319 | if (!this.isInitialized()) {
|
11320 | return null;
|
11321 | }
|
11322 |
|
11323 | if (!parsingPartial) {
|
11324 | captionStream.flush();
|
11325 | } else {
|
11326 | captionStream.partialFlush();
|
11327 | }
|
11328 | };
|
11329 | |
11330 |
|
11331 |
|
11332 |
|
11333 |
|
11334 | this.clearParsedCaptions = function () {
|
11335 | parsedCaptions.captions = [];
|
11336 | parsedCaptions.captionStreams = {};
|
11337 | parsedCaptions.logs = [];
|
11338 | };
|
11339 | |
11340 |
|
11341 |
|
11342 |
|
11343 |
|
11344 |
|
11345 | this.resetCaptionStream = function () {
|
11346 | if (!this.isInitialized()) {
|
11347 | return null;
|
11348 | }
|
11349 |
|
11350 | captionStream.reset();
|
11351 | };
|
11352 | |
11353 |
|
11354 |
|
11355 |
|
11356 |
|
11357 |
|
11358 |
|
11359 | this.clearAllCaptions = function () {
|
11360 | this.clearParsedCaptions();
|
11361 | this.resetCaptionStream();
|
11362 | };
|
11363 | |
11364 |
|
11365 |
|
11366 |
|
11367 |
|
11368 | this.reset = function () {
|
11369 | segmentCache = [];
|
11370 | trackId = null;
|
11371 | timescale = null;
|
11372 |
|
11373 | if (!parsedCaptions) {
|
11374 | parsedCaptions = {
|
11375 | captions: [],
|
11376 |
|
11377 | captionStreams: {},
|
11378 | logs: []
|
11379 | };
|
11380 | } else {
|
11381 | this.clearParsedCaptions();
|
11382 | }
|
11383 |
|
11384 | this.resetCaptionStream();
|
11385 | };
|
11386 |
|
11387 | this.reset();
|
11388 | };
|
11389 |
|
11390 | var captionParser = CaptionParser;
|
11391 | var toUnsigned = bin.toUnsigned;
|
11392 | var toHexString = bin.toHexString;
|
11393 | var getUint64 = numbers.getUint64;
|
11394 | var timescale, startTime, compositionStartTime, getVideoTrackIds, getTracks, getTimescaleFromMediaHeader;
|
11395 | |
11396 |
|
11397 |
|
11398 |
|
11399 |
|
11400 |
|
11401 |
|
11402 |
|
11403 |
|
11404 |
|
11405 |
|
11406 |
|
11407 |
|
11408 |
|
11409 |
|
11410 |
|
11411 |
|
11412 |
|
11413 |
|
11414 | timescale = function timescale(init) {
|
11415 | var result = {},
|
11416 | traks = findBox_1(init, ['moov', 'trak']);
|
11417 |
|
11418 | return traks.reduce(function (result, trak) {
|
11419 | var tkhd, version, index, id, mdhd;
|
11420 | tkhd = findBox_1(trak, ['tkhd'])[0];
|
11421 |
|
11422 | if (!tkhd) {
|
11423 | return null;
|
11424 | }
|
11425 |
|
11426 | version = tkhd[0];
|
11427 | index = version === 0 ? 12 : 20;
|
11428 | id = toUnsigned(tkhd[index] << 24 | tkhd[index + 1] << 16 | tkhd[index + 2] << 8 | tkhd[index + 3]);
|
11429 | mdhd = findBox_1(trak, ['mdia', 'mdhd'])[0];
|
11430 |
|
11431 | if (!mdhd) {
|
11432 | return null;
|
11433 | }
|
11434 |
|
11435 | version = mdhd[0];
|
11436 | index = version === 0 ? 12 : 20;
|
11437 | result[id] = toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]);
|
11438 | return result;
|
11439 | }, result);
|
11440 | };
|
11441 | |
11442 |
|
11443 |
|
11444 |
|
11445 |
|
11446 |
|
11447 |
|
11448 |
|
11449 |
|
11450 |
|
11451 |
|
11452 |
|
11453 |
|
11454 |
|
11455 |
|
11456 |
|
11457 |
|
11458 |
|
11459 | startTime = function startTime(timescale, fragment) {
|
11460 | var trafs;
|
11461 |
|
11462 | trafs = findBox_1(fragment, ['moof', 'traf']);
|
11463 |
|
11464 | var lowestTime = trafs.reduce(function (acc, traf) {
|
11465 | var tfhd = findBox_1(traf, ['tfhd'])[0];
|
11466 |
|
11467 | var id = toUnsigned(tfhd[4] << 24 | tfhd[5] << 16 | tfhd[6] << 8 | tfhd[7]);
|
11468 |
|
11469 | var scale = timescale[id] || 90e3;
|
11470 |
|
11471 | var tfdt = findBox_1(traf, ['tfdt'])[0];
|
11472 | var dv = new DataView(tfdt.buffer, tfdt.byteOffset, tfdt.byteLength);
|
11473 | var baseTime;
|
11474 |
|
11475 | if (tfdt[0] === 1) {
|
11476 | baseTime = getUint64(tfdt.subarray(4, 12));
|
11477 | } else {
|
11478 | baseTime = dv.getUint32(4);
|
11479 | }
|
11480 |
|
11481 |
|
11482 | var seconds;
|
11483 |
|
11484 | if (typeof baseTime === 'bigint') {
|
11485 | seconds = baseTime / window_1.BigInt(scale);
|
11486 | } else if (typeof baseTime === 'number' && !isNaN(baseTime)) {
|
11487 | seconds = baseTime / scale;
|
11488 | }
|
11489 |
|
11490 | if (seconds < Number.MAX_SAFE_INTEGER) {
|
11491 | seconds = Number(seconds);
|
11492 | }
|
11493 |
|
11494 | if (seconds < acc) {
|
11495 | acc = seconds;
|
11496 | }
|
11497 |
|
11498 | return acc;
|
11499 | }, Infinity);
|
11500 | return typeof lowestTime === 'bigint' || isFinite(lowestTime) ? lowestTime : 0;
|
11501 | };
|
11502 | |
11503 |
|
11504 |
|
11505 |
|
11506 |
|
11507 |
|
11508 |
|
11509 |
|
11510 |
|
11511 |
|
11512 |
|
11513 |
|
11514 |
|
11515 |
|
11516 |
|
11517 |
|
11518 |
|
11519 |
|
11520 |
|
11521 |
|
11522 |
|
11523 | compositionStartTime = function compositionStartTime(timescales, fragment) {
|
11524 | var trafBoxes = findBox_1(fragment, ['moof', 'traf']);
|
11525 | var baseMediaDecodeTime = 0;
|
11526 | var compositionTimeOffset = 0;
|
11527 | var trackId;
|
11528 |
|
11529 | if (trafBoxes && trafBoxes.length) {
|
11530 |
|
11531 |
|
11532 |
|
11533 | var tfhd = findBox_1(trafBoxes[0], ['tfhd'])[0];
|
11534 | var trun = findBox_1(trafBoxes[0], ['trun'])[0];
|
11535 | var tfdt = findBox_1(trafBoxes[0], ['tfdt'])[0];
|
11536 |
|
11537 | if (tfhd) {
|
11538 | var parsedTfhd = parseTfhd(tfhd);
|
11539 | trackId = parsedTfhd.trackId;
|
11540 | }
|
11541 |
|
11542 | if (tfdt) {
|
11543 | var parsedTfdt = parseTfdt(tfdt);
|
11544 | baseMediaDecodeTime = parsedTfdt.baseMediaDecodeTime;
|
11545 | }
|
11546 |
|
11547 | if (trun) {
|
11548 | var parsedTrun = parseTrun(trun);
|
11549 |
|
11550 | if (parsedTrun.samples && parsedTrun.samples.length) {
|
11551 | compositionTimeOffset = parsedTrun.samples[0].compositionTimeOffset || 0;
|
11552 | }
|
11553 | }
|
11554 | }
|
11555 |
|
11556 |
|
11557 |
|
11558 | var timescale = timescales[trackId] || 90e3;
|
11559 |
|
11560 | if (typeof baseMediaDecodeTime === 'bigint') {
|
11561 | compositionTimeOffset = window_1.BigInt(compositionTimeOffset);
|
11562 | timescale = window_1.BigInt(timescale);
|
11563 | }
|
11564 |
|
11565 | var result = (baseMediaDecodeTime + compositionTimeOffset) / timescale;
|
11566 |
|
11567 | if (typeof result === 'bigint' && result < Number.MAX_SAFE_INTEGER) {
|
11568 | result = Number(result);
|
11569 | }
|
11570 |
|
11571 | return result;
|
11572 | };
|
11573 | |
11574 |
|
11575 |
|
11576 |
|
11577 |
|
11578 |
|
11579 |
|
11580 |
|
11581 |
|
11582 |
|
11583 |
|
11584 |
|
11585 |
|
11586 | getVideoTrackIds = function getVideoTrackIds(init) {
|
11587 | var traks = findBox_1(init, ['moov', 'trak']);
|
11588 | var videoTrackIds = [];
|
11589 | traks.forEach(function (trak) {
|
11590 | var hdlrs = findBox_1(trak, ['mdia', 'hdlr']);
|
11591 | var tkhds = findBox_1(trak, ['tkhd']);
|
11592 | hdlrs.forEach(function (hdlr, index) {
|
11593 | var handlerType = parseType_1(hdlr.subarray(8, 12));
|
11594 | var tkhd = tkhds[index];
|
11595 | var view;
|
11596 | var version;
|
11597 | var trackId;
|
11598 |
|
11599 | if (handlerType === 'vide') {
|
11600 | view = new DataView(tkhd.buffer, tkhd.byteOffset, tkhd.byteLength);
|
11601 | version = view.getUint8(0);
|
11602 | trackId = version === 0 ? view.getUint32(12) : view.getUint32(20);
|
11603 | videoTrackIds.push(trackId);
|
11604 | }
|
11605 | });
|
11606 | });
|
11607 | return videoTrackIds;
|
11608 | };
|
11609 |
|
11610 | getTimescaleFromMediaHeader = function getTimescaleFromMediaHeader(mdhd) {
|
11611 |
|
11612 | var version = mdhd[0];
|
11613 | var index = version === 0 ? 12 : 20;
|
11614 | return toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]);
|
11615 | };
|
11616 | |
11617 |
|
11618 |
|
11619 |
|
11620 |
|
11621 |
|
11622 | getTracks = function getTracks(init) {
|
11623 | var traks = findBox_1(init, ['moov', 'trak']);
|
11624 | var tracks = [];
|
11625 | traks.forEach(function (trak) {
|
11626 | var track = {};
|
11627 | var tkhd = findBox_1(trak, ['tkhd'])[0];
|
11628 | var view, tkhdVersion;
|
11629 |
|
11630 | if (tkhd) {
|
11631 | view = new DataView(tkhd.buffer, tkhd.byteOffset, tkhd.byteLength);
|
11632 | tkhdVersion = view.getUint8(0);
|
11633 | track.id = tkhdVersion === 0 ? view.getUint32(12) : view.getUint32(20);
|
11634 | }
|
11635 |
|
11636 | var hdlr = findBox_1(trak, ['mdia', 'hdlr'])[0];
|
11637 |
|
11638 | if (hdlr) {
|
11639 | var type = parseType_1(hdlr.subarray(8, 12));
|
11640 |
|
11641 | if (type === 'vide') {
|
11642 | track.type = 'video';
|
11643 | } else if (type === 'soun') {
|
11644 | track.type = 'audio';
|
11645 | } else {
|
11646 | track.type = type;
|
11647 | }
|
11648 | }
|
11649 |
|
11650 |
|
11651 | var stsd = findBox_1(trak, ['mdia', 'minf', 'stbl', 'stsd'])[0];
|
11652 |
|
11653 | if (stsd) {
|
11654 | var sampleDescriptions = stsd.subarray(8);
|
11655 |
|
11656 | track.codec = parseType_1(sampleDescriptions.subarray(4, 8));
|
11657 | var codecBox = findBox_1(sampleDescriptions, [track.codec])[0];
|
11658 | var codecConfig, codecConfigType;
|
11659 |
|
11660 | if (codecBox) {
|
11661 |
|
11662 | if (/^[asm]vc[1-9]$/i.test(track.codec)) {
|
11663 |
|
11664 |
|
11665 | codecConfig = codecBox.subarray(78);
|
11666 | codecConfigType = parseType_1(codecConfig.subarray(4, 8));
|
11667 |
|
11668 | if (codecConfigType === 'avcC' && codecConfig.length > 11) {
|
11669 | track.codec += '.';
|
11670 |
|
11671 |
|
11672 | track.codec += toHexString(codecConfig[9]);
|
11673 |
|
11674 | track.codec += toHexString(codecConfig[10]);
|
11675 |
|
11676 | track.codec += toHexString(codecConfig[11]);
|
11677 | } else {
|
11678 |
|
11679 |
|
11680 | track.codec = 'avc1.4d400d';
|
11681 | }
|
11682 | } else if (/^mp4[a,v]$/i.test(track.codec)) {
|
11683 |
|
11684 | codecConfig = codecBox.subarray(28);
|
11685 | codecConfigType = parseType_1(codecConfig.subarray(4, 8));
|
11686 |
|
11687 | if (codecConfigType === 'esds' && codecConfig.length > 20 && codecConfig[19] !== 0) {
|
11688 | track.codec += '.' + toHexString(codecConfig[19]);
|
11689 |
|
11690 | track.codec += '.' + toHexString(codecConfig[20] >>> 2 & 0x3f).replace(/^0/, '');
|
11691 | } else {
|
11692 |
|
11693 |
|
11694 | track.codec = 'mp4a.40.2';
|
11695 | }
|
11696 | } else {
|
11697 |
|
11698 | track.codec = track.codec.toLowerCase();
|
11699 | }
|
11700 | }
|
11701 | }
|
11702 |
|
11703 | var mdhd = findBox_1(trak, ['mdia', 'mdhd'])[0];
|
11704 |
|
11705 | if (mdhd) {
|
11706 | track.timescale = getTimescaleFromMediaHeader(mdhd);
|
11707 | }
|
11708 |
|
11709 | tracks.push(track);
|
11710 | });
|
11711 | return tracks;
|
11712 | };
|
11713 |
|
11714 | var probe$2 = {
|
11715 |
|
11716 | findBox: findBox_1,
|
11717 | parseType: parseType_1,
|
11718 | timescale: timescale,
|
11719 | startTime: startTime,
|
11720 | compositionStartTime: compositionStartTime,
|
11721 | videoTrackIds: getVideoTrackIds,
|
11722 | tracks: getTracks,
|
11723 | getTimescaleFromMediaHeader: getTimescaleFromMediaHeader
|
11724 | };
|
11725 |
|
11726 | var parsePid = function parsePid(packet) {
|
11727 | var pid = packet[1] & 0x1f;
|
11728 | pid <<= 8;
|
11729 | pid |= packet[2];
|
11730 | return pid;
|
11731 | };
|
11732 |
|
11733 | var parsePayloadUnitStartIndicator = function parsePayloadUnitStartIndicator(packet) {
|
11734 | return !!(packet[1] & 0x40);
|
11735 | };
|
11736 |
|
11737 | var parseAdaptionField = function parseAdaptionField(packet) {
|
11738 | var offset = 0;
|
11739 |
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
11745 | offset += packet[4] + 1;
|
11746 | }
|
11747 |
|
11748 | return offset;
|
11749 | };
|
11750 |
|
11751 | var parseType = function parseType(packet, pmtPid) {
|
11752 | var pid = parsePid(packet);
|
11753 |
|
11754 | if (pid === 0) {
|
11755 | return 'pat';
|
11756 | } else if (pid === pmtPid) {
|
11757 | return 'pmt';
|
11758 | } else if (pmtPid) {
|
11759 | return 'pes';
|
11760 | }
|
11761 |
|
11762 | return null;
|
11763 | };
|
11764 |
|
11765 | var parsePat = function parsePat(packet) {
|
11766 | var pusi = parsePayloadUnitStartIndicator(packet);
|
11767 | var offset = 4 + parseAdaptionField(packet);
|
11768 |
|
11769 | if (pusi) {
|
11770 | offset += packet[offset] + 1;
|
11771 | }
|
11772 |
|
11773 | return (packet[offset + 10] & 0x1f) << 8 | packet[offset + 11];
|
11774 | };
|
11775 |
|
11776 | var parsePmt = function parsePmt(packet) {
|
11777 | var programMapTable = {};
|
11778 | var pusi = parsePayloadUnitStartIndicator(packet);
|
11779 | var payloadOffset = 4 + parseAdaptionField(packet);
|
11780 |
|
11781 | if (pusi) {
|
11782 | payloadOffset += packet[payloadOffset] + 1;
|
11783 | }
|
11784 |
|
11785 |
|
11786 |
|
11787 |
|
11788 |
|
11789 |
|
11790 | if (!(packet[payloadOffset + 5] & 0x01)) {
|
11791 | return;
|
11792 | }
|
11793 |
|
11794 | var sectionLength, tableEnd, programInfoLength;
|
11795 |
|
11796 | sectionLength = (packet[payloadOffset + 1] & 0x0f) << 8 | packet[payloadOffset + 2];
|
11797 | tableEnd = 3 + sectionLength - 4;
|
11798 |
|
11799 |
|
11800 | programInfoLength = (packet[payloadOffset + 10] & 0x0f) << 8 | packet[payloadOffset + 11];
|
11801 |
|
11802 | var offset = 12 + programInfoLength;
|
11803 |
|
11804 | while (offset < tableEnd) {
|
11805 | var i = payloadOffset + offset;
|
11806 |
|
11807 | programMapTable[(packet[i + 1] & 0x1F) << 8 | packet[i + 2]] = packet[i];
|
11808 |
|
11809 |
|
11810 | offset += ((packet[i + 3] & 0x0F) << 8 | packet[i + 4]) + 5;
|
11811 | }
|
11812 |
|
11813 | return programMapTable;
|
11814 | };
|
11815 |
|
11816 | var parsePesType = function parsePesType(packet, programMapTable) {
|
11817 | var pid = parsePid(packet);
|
11818 | var type = programMapTable[pid];
|
11819 |
|
11820 | switch (type) {
|
11821 | case streamTypes.H264_STREAM_TYPE:
|
11822 | return 'video';
|
11823 |
|
11824 | case streamTypes.ADTS_STREAM_TYPE:
|
11825 | return 'audio';
|
11826 |
|
11827 | case streamTypes.METADATA_STREAM_TYPE:
|
11828 | return 'timed-metadata';
|
11829 |
|
11830 | default:
|
11831 | return null;
|
11832 | }
|
11833 | };
|
11834 |
|
11835 | var parsePesTime = function parsePesTime(packet) {
|
11836 | var pusi = parsePayloadUnitStartIndicator(packet);
|
11837 |
|
11838 | if (!pusi) {
|
11839 | return null;
|
11840 | }
|
11841 |
|
11842 | var offset = 4 + parseAdaptionField(packet);
|
11843 |
|
11844 | if (offset >= packet.byteLength) {
|
11845 |
|
11846 |
|
11847 |
|
11848 |
|
11849 |
|
11850 |
|
11851 |
|
11852 |
|
11853 |
|
11854 |
|
11855 | return null;
|
11856 | }
|
11857 |
|
11858 | var pes = null;
|
11859 | var ptsDtsFlags;
|
11860 |
|
11861 |
|
11862 |
|
11863 | ptsDtsFlags = packet[offset + 7];
|
11864 |
|
11865 |
|
11866 |
|
11867 |
|
11868 |
|
11869 |
|
11870 |
|
11871 |
|
11872 | if (ptsDtsFlags & 0xC0) {
|
11873 | pes = {};
|
11874 |
|
11875 |
|
11876 |
|
11877 | 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;
|
11878 | pes.pts *= 4;
|
11879 |
|
11880 | pes.pts += (packet[offset + 13] & 0x06) >>> 1;
|
11881 |
|
11882 | pes.dts = pes.pts;
|
11883 |
|
11884 | if (ptsDtsFlags & 0x40) {
|
11885 | 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;
|
11886 | pes.dts *= 4;
|
11887 |
|
11888 | pes.dts += (packet[offset + 18] & 0x06) >>> 1;
|
11889 | }
|
11890 | }
|
11891 |
|
11892 | return pes;
|
11893 | };
|
11894 |
|
11895 | var parseNalUnitType = function parseNalUnitType(type) {
|
11896 | switch (type) {
|
11897 | case 0x05:
|
11898 | return 'slice_layer_without_partitioning_rbsp_idr';
|
11899 |
|
11900 | case 0x06:
|
11901 | return 'sei_rbsp';
|
11902 |
|
11903 | case 0x07:
|
11904 | return 'seq_parameter_set_rbsp';
|
11905 |
|
11906 | case 0x08:
|
11907 | return 'pic_parameter_set_rbsp';
|
11908 |
|
11909 | case 0x09:
|
11910 | return 'access_unit_delimiter_rbsp';
|
11911 |
|
11912 | default:
|
11913 | return null;
|
11914 | }
|
11915 | };
|
11916 |
|
11917 | var videoPacketContainsKeyFrame = function videoPacketContainsKeyFrame(packet) {
|
11918 | var offset = 4 + parseAdaptionField(packet);
|
11919 | var frameBuffer = packet.subarray(offset);
|
11920 | var frameI = 0;
|
11921 | var frameSyncPoint = 0;
|
11922 | var foundKeyFrame = false;
|
11923 | var nalType;
|
11924 |
|
11925 | for (; frameSyncPoint < frameBuffer.byteLength - 3; frameSyncPoint++) {
|
11926 | if (frameBuffer[frameSyncPoint + 2] === 1) {
|
11927 |
|
11928 | frameI = frameSyncPoint + 5;
|
11929 | break;
|
11930 | }
|
11931 | }
|
11932 |
|
11933 | while (frameI < frameBuffer.byteLength) {
|
11934 |
|
11935 |
|
11936 | switch (frameBuffer[frameI]) {
|
11937 | case 0:
|
11938 |
|
11939 | if (frameBuffer[frameI - 1] !== 0) {
|
11940 | frameI += 2;
|
11941 | break;
|
11942 | } else if (frameBuffer[frameI - 2] !== 0) {
|
11943 | frameI++;
|
11944 | break;
|
11945 | }
|
11946 |
|
11947 | if (frameSyncPoint + 3 !== frameI - 2) {
|
11948 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
11949 |
|
11950 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
11951 | foundKeyFrame = true;
|
11952 | }
|
11953 | }
|
11954 |
|
11955 |
|
11956 | do {
|
11957 | frameI++;
|
11958 | } while (frameBuffer[frameI] !== 1 && frameI < frameBuffer.length);
|
11959 |
|
11960 | frameSyncPoint = frameI - 2;
|
11961 | frameI += 3;
|
11962 | break;
|
11963 |
|
11964 | case 1:
|
11965 |
|
11966 | if (frameBuffer[frameI - 1] !== 0 || frameBuffer[frameI - 2] !== 0) {
|
11967 | frameI += 3;
|
11968 | break;
|
11969 | }
|
11970 |
|
11971 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
11972 |
|
11973 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
11974 | foundKeyFrame = true;
|
11975 | }
|
11976 |
|
11977 | frameSyncPoint = frameI - 2;
|
11978 | frameI += 3;
|
11979 | break;
|
11980 |
|
11981 | default:
|
11982 |
|
11983 |
|
11984 | frameI += 3;
|
11985 | break;
|
11986 | }
|
11987 | }
|
11988 |
|
11989 | frameBuffer = frameBuffer.subarray(frameSyncPoint);
|
11990 | frameI -= frameSyncPoint;
|
11991 | frameSyncPoint = 0;
|
11992 |
|
11993 | if (frameBuffer && frameBuffer.byteLength > 3) {
|
11994 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
11995 |
|
11996 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
11997 | foundKeyFrame = true;
|
11998 | }
|
11999 | }
|
12000 |
|
12001 | return foundKeyFrame;
|
12002 | };
|
12003 |
|
12004 | var probe$1 = {
|
12005 | parseType: parseType,
|
12006 | parsePat: parsePat,
|
12007 | parsePmt: parsePmt,
|
12008 | parsePayloadUnitStartIndicator: parsePayloadUnitStartIndicator,
|
12009 | parsePesType: parsePesType,
|
12010 | parsePesTime: parsePesTime,
|
12011 | videoPacketContainsKeyFrame: videoPacketContainsKeyFrame
|
12012 | };
|
12013 | var handleRollover = timestampRolloverStream.handleRollover;
|
12014 | var probe = {};
|
12015 | probe.ts = probe$1;
|
12016 | probe.aac = utils;
|
12017 | var ONE_SECOND_IN_TS = clock.ONE_SECOND_IN_TS;
|
12018 | var MP2T_PACKET_LENGTH = 188,
|
12019 |
|
12020 | SYNC_BYTE = 0x47;
|
12021 | |
12022 |
|
12023 |
|
12024 |
|
12025 |
|
12026 | var parsePsi_ = function parsePsi_(bytes, pmt) {
|
12027 | var startIndex = 0,
|
12028 | endIndex = MP2T_PACKET_LENGTH,
|
12029 | packet,
|
12030 | type;
|
12031 |
|
12032 | while (endIndex < bytes.byteLength) {
|
12033 |
|
12034 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
12035 |
|
12036 | packet = bytes.subarray(startIndex, endIndex);
|
12037 | type = probe.ts.parseType(packet, pmt.pid);
|
12038 |
|
12039 | switch (type) {
|
12040 | case 'pat':
|
12041 | pmt.pid = probe.ts.parsePat(packet);
|
12042 | break;
|
12043 |
|
12044 | case 'pmt':
|
12045 | var table = probe.ts.parsePmt(packet);
|
12046 | pmt.table = pmt.table || {};
|
12047 | Object.keys(table).forEach(function (key) {
|
12048 | pmt.table[key] = table[key];
|
12049 | });
|
12050 | break;
|
12051 | }
|
12052 |
|
12053 | startIndex += MP2T_PACKET_LENGTH;
|
12054 | endIndex += MP2T_PACKET_LENGTH;
|
12055 | continue;
|
12056 | }
|
12057 |
|
12058 |
|
12059 |
|
12060 |
|
12061 | startIndex++;
|
12062 | endIndex++;
|
12063 | }
|
12064 | };
|
12065 | |
12066 |
|
12067 |
|
12068 |
|
12069 |
|
12070 |
|
12071 | var parseAudioPes_ = function parseAudioPes_(bytes, pmt, result) {
|
12072 | var startIndex = 0,
|
12073 | endIndex = MP2T_PACKET_LENGTH,
|
12074 | packet,
|
12075 | type,
|
12076 | pesType,
|
12077 | pusi,
|
12078 | parsed;
|
12079 | var endLoop = false;
|
12080 |
|
12081 | while (endIndex <= bytes.byteLength) {
|
12082 |
|
12083 | if (bytes[startIndex] === SYNC_BYTE && (bytes[endIndex] === SYNC_BYTE || endIndex === bytes.byteLength)) {
|
12084 |
|
12085 | packet = bytes.subarray(startIndex, endIndex);
|
12086 | type = probe.ts.parseType(packet, pmt.pid);
|
12087 |
|
12088 | switch (type) {
|
12089 | case 'pes':
|
12090 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12091 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12092 |
|
12093 | if (pesType === 'audio' && pusi) {
|
12094 | parsed = probe.ts.parsePesTime(packet);
|
12095 |
|
12096 | if (parsed) {
|
12097 | parsed.type = 'audio';
|
12098 | result.audio.push(parsed);
|
12099 | endLoop = true;
|
12100 | }
|
12101 | }
|
12102 |
|
12103 | break;
|
12104 | }
|
12105 |
|
12106 | if (endLoop) {
|
12107 | break;
|
12108 | }
|
12109 |
|
12110 | startIndex += MP2T_PACKET_LENGTH;
|
12111 | endIndex += MP2T_PACKET_LENGTH;
|
12112 | continue;
|
12113 | }
|
12114 |
|
12115 |
|
12116 |
|
12117 |
|
12118 | startIndex++;
|
12119 | endIndex++;
|
12120 | }
|
12121 |
|
12122 |
|
12123 | endIndex = bytes.byteLength;
|
12124 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
12125 | endLoop = false;
|
12126 |
|
12127 | while (startIndex >= 0) {
|
12128 |
|
12129 | if (bytes[startIndex] === SYNC_BYTE && (bytes[endIndex] === SYNC_BYTE || endIndex === bytes.byteLength)) {
|
12130 |
|
12131 | packet = bytes.subarray(startIndex, endIndex);
|
12132 | type = probe.ts.parseType(packet, pmt.pid);
|
12133 |
|
12134 | switch (type) {
|
12135 | case 'pes':
|
12136 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12137 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12138 |
|
12139 | if (pesType === 'audio' && pusi) {
|
12140 | parsed = probe.ts.parsePesTime(packet);
|
12141 |
|
12142 | if (parsed) {
|
12143 | parsed.type = 'audio';
|
12144 | result.audio.push(parsed);
|
12145 | endLoop = true;
|
12146 | }
|
12147 | }
|
12148 |
|
12149 | break;
|
12150 | }
|
12151 |
|
12152 | if (endLoop) {
|
12153 | break;
|
12154 | }
|
12155 |
|
12156 | startIndex -= MP2T_PACKET_LENGTH;
|
12157 | endIndex -= MP2T_PACKET_LENGTH;
|
12158 | continue;
|
12159 | }
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 | startIndex--;
|
12165 | endIndex--;
|
12166 | }
|
12167 | };
|
12168 | |
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 |
|
12174 |
|
12175 | var parseVideoPes_ = function parseVideoPes_(bytes, pmt, result) {
|
12176 | var startIndex = 0,
|
12177 | endIndex = MP2T_PACKET_LENGTH,
|
12178 | packet,
|
12179 | type,
|
12180 | pesType,
|
12181 | pusi,
|
12182 | parsed,
|
12183 | frame,
|
12184 | i,
|
12185 | pes;
|
12186 | var endLoop = false;
|
12187 | var currentFrame = {
|
12188 | data: [],
|
12189 | size: 0
|
12190 | };
|
12191 |
|
12192 | while (endIndex < bytes.byteLength) {
|
12193 |
|
12194 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
12195 |
|
12196 | packet = bytes.subarray(startIndex, endIndex);
|
12197 | type = probe.ts.parseType(packet, pmt.pid);
|
12198 |
|
12199 | switch (type) {
|
12200 | case 'pes':
|
12201 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12202 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12203 |
|
12204 | if (pesType === 'video') {
|
12205 | if (pusi && !endLoop) {
|
12206 | parsed = probe.ts.parsePesTime(packet);
|
12207 |
|
12208 | if (parsed) {
|
12209 | parsed.type = 'video';
|
12210 | result.video.push(parsed);
|
12211 | endLoop = true;
|
12212 | }
|
12213 | }
|
12214 |
|
12215 | if (!result.firstKeyFrame) {
|
12216 | if (pusi) {
|
12217 | if (currentFrame.size !== 0) {
|
12218 | frame = new Uint8Array(currentFrame.size);
|
12219 | i = 0;
|
12220 |
|
12221 | while (currentFrame.data.length) {
|
12222 | pes = currentFrame.data.shift();
|
12223 | frame.set(pes, i);
|
12224 | i += pes.byteLength;
|
12225 | }
|
12226 |
|
12227 | if (probe.ts.videoPacketContainsKeyFrame(frame)) {
|
12228 | var firstKeyFrame = probe.ts.parsePesTime(frame);
|
12229 |
|
12230 |
|
12231 |
|
12232 | if (firstKeyFrame) {
|
12233 | result.firstKeyFrame = firstKeyFrame;
|
12234 | result.firstKeyFrame.type = 'video';
|
12235 | } else {
|
12236 |
|
12237 | 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.');
|
12238 | }
|
12239 | }
|
12240 |
|
12241 | currentFrame.size = 0;
|
12242 | }
|
12243 | }
|
12244 |
|
12245 | currentFrame.data.push(packet);
|
12246 | currentFrame.size += packet.byteLength;
|
12247 | }
|
12248 | }
|
12249 |
|
12250 | break;
|
12251 | }
|
12252 |
|
12253 | if (endLoop && result.firstKeyFrame) {
|
12254 | break;
|
12255 | }
|
12256 |
|
12257 | startIndex += MP2T_PACKET_LENGTH;
|
12258 | endIndex += MP2T_PACKET_LENGTH;
|
12259 | continue;
|
12260 | }
|
12261 |
|
12262 |
|
12263 |
|
12264 |
|
12265 | startIndex++;
|
12266 | endIndex++;
|
12267 | }
|
12268 |
|
12269 |
|
12270 | endIndex = bytes.byteLength;
|
12271 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
12272 | endLoop = false;
|
12273 |
|
12274 | while (startIndex >= 0) {
|
12275 |
|
12276 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
12277 |
|
12278 | packet = bytes.subarray(startIndex, endIndex);
|
12279 | type = probe.ts.parseType(packet, pmt.pid);
|
12280 |
|
12281 | switch (type) {
|
12282 | case 'pes':
|
12283 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12284 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12285 |
|
12286 | if (pesType === 'video' && pusi) {
|
12287 | parsed = probe.ts.parsePesTime(packet);
|
12288 |
|
12289 | if (parsed) {
|
12290 | parsed.type = 'video';
|
12291 | result.video.push(parsed);
|
12292 | endLoop = true;
|
12293 | }
|
12294 | }
|
12295 |
|
12296 | break;
|
12297 | }
|
12298 |
|
12299 | if (endLoop) {
|
12300 | break;
|
12301 | }
|
12302 |
|
12303 | startIndex -= MP2T_PACKET_LENGTH;
|
12304 | endIndex -= MP2T_PACKET_LENGTH;
|
12305 | continue;
|
12306 | }
|
12307 |
|
12308 |
|
12309 |
|
12310 |
|
12311 | startIndex--;
|
12312 | endIndex--;
|
12313 | }
|
12314 | };
|
12315 | |
12316 |
|
12317 |
|
12318 |
|
12319 |
|
12320 |
|
12321 | var adjustTimestamp_ = function adjustTimestamp_(segmentInfo, baseTimestamp) {
|
12322 | if (segmentInfo.audio && segmentInfo.audio.length) {
|
12323 | var audioBaseTimestamp = baseTimestamp;
|
12324 |
|
12325 | if (typeof audioBaseTimestamp === 'undefined' || isNaN(audioBaseTimestamp)) {
|
12326 | audioBaseTimestamp = segmentInfo.audio[0].dts;
|
12327 | }
|
12328 |
|
12329 | segmentInfo.audio.forEach(function (info) {
|
12330 | info.dts = handleRollover(info.dts, audioBaseTimestamp);
|
12331 | info.pts = handleRollover(info.pts, audioBaseTimestamp);
|
12332 |
|
12333 | info.dtsTime = info.dts / ONE_SECOND_IN_TS;
|
12334 | info.ptsTime = info.pts / ONE_SECOND_IN_TS;
|
12335 | });
|
12336 | }
|
12337 |
|
12338 | if (segmentInfo.video && segmentInfo.video.length) {
|
12339 | var videoBaseTimestamp = baseTimestamp;
|
12340 |
|
12341 | if (typeof videoBaseTimestamp === 'undefined' || isNaN(videoBaseTimestamp)) {
|
12342 | videoBaseTimestamp = segmentInfo.video[0].dts;
|
12343 | }
|
12344 |
|
12345 | segmentInfo.video.forEach(function (info) {
|
12346 | info.dts = handleRollover(info.dts, videoBaseTimestamp);
|
12347 | info.pts = handleRollover(info.pts, videoBaseTimestamp);
|
12348 |
|
12349 | info.dtsTime = info.dts / ONE_SECOND_IN_TS;
|
12350 | info.ptsTime = info.pts / ONE_SECOND_IN_TS;
|
12351 | });
|
12352 |
|
12353 | if (segmentInfo.firstKeyFrame) {
|
12354 | var frame = segmentInfo.firstKeyFrame;
|
12355 | frame.dts = handleRollover(frame.dts, videoBaseTimestamp);
|
12356 | frame.pts = handleRollover(frame.pts, videoBaseTimestamp);
|
12357 |
|
12358 | frame.dtsTime = frame.dts / ONE_SECOND_IN_TS;
|
12359 | frame.ptsTime = frame.pts / ONE_SECOND_IN_TS;
|
12360 | }
|
12361 | }
|
12362 | };
|
12363 | |
12364 |
|
12365 |
|
12366 |
|
12367 |
|
12368 | var inspectAac_ = function inspectAac_(bytes) {
|
12369 | var endLoop = false,
|
12370 | audioCount = 0,
|
12371 | sampleRate = null,
|
12372 | timestamp = null,
|
12373 | frameSize = 0,
|
12374 | byteIndex = 0,
|
12375 | packet;
|
12376 |
|
12377 | while (bytes.length - byteIndex >= 3) {
|
12378 | var type = probe.aac.parseType(bytes, byteIndex);
|
12379 |
|
12380 | switch (type) {
|
12381 | case 'timed-metadata':
|
12382 |
|
12383 |
|
12384 | if (bytes.length - byteIndex < 10) {
|
12385 | endLoop = true;
|
12386 | break;
|
12387 | }
|
12388 |
|
12389 | frameSize = probe.aac.parseId3TagSize(bytes, byteIndex);
|
12390 |
|
12391 |
|
12392 | if (frameSize > bytes.length) {
|
12393 | endLoop = true;
|
12394 | break;
|
12395 | }
|
12396 |
|
12397 | if (timestamp === null) {
|
12398 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
12399 | timestamp = probe.aac.parseAacTimestamp(packet);
|
12400 | }
|
12401 |
|
12402 | byteIndex += frameSize;
|
12403 | break;
|
12404 |
|
12405 | case 'audio':
|
12406 |
|
12407 |
|
12408 | if (bytes.length - byteIndex < 7) {
|
12409 | endLoop = true;
|
12410 | break;
|
12411 | }
|
12412 |
|
12413 | frameSize = probe.aac.parseAdtsSize(bytes, byteIndex);
|
12414 |
|
12415 |
|
12416 | if (frameSize > bytes.length) {
|
12417 | endLoop = true;
|
12418 | break;
|
12419 | }
|
12420 |
|
12421 | if (sampleRate === null) {
|
12422 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
12423 | sampleRate = probe.aac.parseSampleRate(packet);
|
12424 | }
|
12425 |
|
12426 | audioCount++;
|
12427 | byteIndex += frameSize;
|
12428 | break;
|
12429 |
|
12430 | default:
|
12431 | byteIndex++;
|
12432 | break;
|
12433 | }
|
12434 |
|
12435 | if (endLoop) {
|
12436 | return null;
|
12437 | }
|
12438 | }
|
12439 |
|
12440 | if (sampleRate === null || timestamp === null) {
|
12441 | return null;
|
12442 | }
|
12443 |
|
12444 | var audioTimescale = ONE_SECOND_IN_TS / sampleRate;
|
12445 | var result = {
|
12446 | audio: [{
|
12447 | type: 'audio',
|
12448 | dts: timestamp,
|
12449 | pts: timestamp
|
12450 | }, {
|
12451 | type: 'audio',
|
12452 | dts: timestamp + audioCount * 1024 * audioTimescale,
|
12453 | pts: timestamp + audioCount * 1024 * audioTimescale
|
12454 | }]
|
12455 | };
|
12456 | return result;
|
12457 | };
|
12458 | |
12459 |
|
12460 |
|
12461 |
|
12462 |
|
12463 |
|
12464 |
|
12465 | var inspectTs_ = function inspectTs_(bytes) {
|
12466 | var pmt = {
|
12467 | pid: null,
|
12468 | table: null
|
12469 | };
|
12470 | var result = {};
|
12471 | parsePsi_(bytes, pmt);
|
12472 |
|
12473 | for (var pid in pmt.table) {
|
12474 | if (pmt.table.hasOwnProperty(pid)) {
|
12475 | var type = pmt.table[pid];
|
12476 |
|
12477 | switch (type) {
|
12478 | case streamTypes.H264_STREAM_TYPE:
|
12479 | result.video = [];
|
12480 | parseVideoPes_(bytes, pmt, result);
|
12481 |
|
12482 | if (result.video.length === 0) {
|
12483 | delete result.video;
|
12484 | }
|
12485 |
|
12486 | break;
|
12487 |
|
12488 | case streamTypes.ADTS_STREAM_TYPE:
|
12489 | result.audio = [];
|
12490 | parseAudioPes_(bytes, pmt, result);
|
12491 |
|
12492 | if (result.audio.length === 0) {
|
12493 | delete result.audio;
|
12494 | }
|
12495 |
|
12496 | break;
|
12497 | }
|
12498 | }
|
12499 | }
|
12500 |
|
12501 | return result;
|
12502 | };
|
12503 | |
12504 |
|
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 |
|
12513 | var inspect = function inspect(bytes, baseTimestamp) {
|
12514 | var isAacData = probe.aac.isLikelyAacData(bytes);
|
12515 | var result;
|
12516 |
|
12517 | if (isAacData) {
|
12518 | result = inspectAac_(bytes);
|
12519 | } else {
|
12520 | result = inspectTs_(bytes);
|
12521 | }
|
12522 |
|
12523 | if (!result || !result.audio && !result.video) {
|
12524 | return null;
|
12525 | }
|
12526 |
|
12527 | adjustTimestamp_(result, baseTimestamp);
|
12528 | return result;
|
12529 | };
|
12530 |
|
12531 | var tsInspector = {
|
12532 | inspect: inspect,
|
12533 | parseAudioPes_: parseAudioPes_
|
12534 | };
|
12535 |
|
12536 |
|
12537 | |
12538 |
|
12539 |
|
12540 |
|
12541 |
|
12542 |
|
12543 |
|
12544 |
|
12545 | var wireTransmuxerEvents = function wireTransmuxerEvents(self, transmuxer) {
|
12546 | transmuxer.on('data', function (segment) {
|
12547 |
|
12548 |
|
12549 |
|
12550 |
|
12551 | var initArray = segment.initSegment;
|
12552 | segment.initSegment = {
|
12553 | data: initArray.buffer,
|
12554 | byteOffset: initArray.byteOffset,
|
12555 | byteLength: initArray.byteLength
|
12556 | };
|
12557 | var typedArray = segment.data;
|
12558 | segment.data = typedArray.buffer;
|
12559 | self.postMessage({
|
12560 | action: 'data',
|
12561 | segment: segment,
|
12562 | byteOffset: typedArray.byteOffset,
|
12563 | byteLength: typedArray.byteLength
|
12564 | }, [segment.data]);
|
12565 | });
|
12566 | transmuxer.on('done', function (data) {
|
12567 | self.postMessage({
|
12568 | action: 'done'
|
12569 | });
|
12570 | });
|
12571 | transmuxer.on('gopInfo', function (gopInfo) {
|
12572 | self.postMessage({
|
12573 | action: 'gopInfo',
|
12574 | gopInfo: gopInfo
|
12575 | });
|
12576 | });
|
12577 | transmuxer.on('videoSegmentTimingInfo', function (timingInfo) {
|
12578 | var videoSegmentTimingInfo = {
|
12579 | start: {
|
12580 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
12581 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
12582 | },
|
12583 | end: {
|
12584 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
12585 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
12586 | },
|
12587 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
12588 | };
|
12589 |
|
12590 | if (timingInfo.prependedContentDuration) {
|
12591 | videoSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
12592 | }
|
12593 |
|
12594 | self.postMessage({
|
12595 | action: 'videoSegmentTimingInfo',
|
12596 | videoSegmentTimingInfo: videoSegmentTimingInfo
|
12597 | });
|
12598 | });
|
12599 | transmuxer.on('audioSegmentTimingInfo', function (timingInfo) {
|
12600 |
|
12601 | var audioSegmentTimingInfo = {
|
12602 | start: {
|
12603 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
12604 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
12605 | },
|
12606 | end: {
|
12607 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
12608 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
12609 | },
|
12610 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
12611 | };
|
12612 |
|
12613 | if (timingInfo.prependedContentDuration) {
|
12614 | audioSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
12615 | }
|
12616 |
|
12617 | self.postMessage({
|
12618 | action: 'audioSegmentTimingInfo',
|
12619 | audioSegmentTimingInfo: audioSegmentTimingInfo
|
12620 | });
|
12621 | });
|
12622 | transmuxer.on('id3Frame', function (id3Frame) {
|
12623 | self.postMessage({
|
12624 | action: 'id3Frame',
|
12625 | id3Frame: id3Frame
|
12626 | });
|
12627 | });
|
12628 | transmuxer.on('caption', function (caption) {
|
12629 | self.postMessage({
|
12630 | action: 'caption',
|
12631 | caption: caption
|
12632 | });
|
12633 | });
|
12634 | transmuxer.on('trackinfo', function (trackInfo) {
|
12635 | self.postMessage({
|
12636 | action: 'trackinfo',
|
12637 | trackInfo: trackInfo
|
12638 | });
|
12639 | });
|
12640 | transmuxer.on('audioTimingInfo', function (audioTimingInfo) {
|
12641 |
|
12642 | self.postMessage({
|
12643 | action: 'audioTimingInfo',
|
12644 | audioTimingInfo: {
|
12645 | start: clock.videoTsToSeconds(audioTimingInfo.start),
|
12646 | end: clock.videoTsToSeconds(audioTimingInfo.end)
|
12647 | }
|
12648 | });
|
12649 | });
|
12650 | transmuxer.on('videoTimingInfo', function (videoTimingInfo) {
|
12651 | self.postMessage({
|
12652 | action: 'videoTimingInfo',
|
12653 | videoTimingInfo: {
|
12654 | start: clock.videoTsToSeconds(videoTimingInfo.start),
|
12655 | end: clock.videoTsToSeconds(videoTimingInfo.end)
|
12656 | }
|
12657 | });
|
12658 | });
|
12659 | transmuxer.on('log', function (log) {
|
12660 | self.postMessage({
|
12661 | action: 'log',
|
12662 | log: log
|
12663 | });
|
12664 | });
|
12665 | };
|
12666 | |
12667 |
|
12668 |
|
12669 |
|
12670 |
|
12671 |
|
12672 |
|
12673 |
|
12674 |
|
12675 | var MessageHandlers = function () {
|
12676 | function MessageHandlers(self, options) {
|
12677 | this.options = options || {};
|
12678 | this.self = self;
|
12679 | this.init();
|
12680 | }
|
12681 | |
12682 |
|
12683 |
|
12684 |
|
12685 |
|
12686 | var _proto = MessageHandlers.prototype;
|
12687 |
|
12688 | _proto.init = function init() {
|
12689 | if (this.transmuxer) {
|
12690 | this.transmuxer.dispose();
|
12691 | }
|
12692 |
|
12693 | this.transmuxer = new transmuxer.Transmuxer(this.options);
|
12694 | wireTransmuxerEvents(this.self, this.transmuxer);
|
12695 | };
|
12696 |
|
12697 | _proto.pushMp4Captions = function pushMp4Captions(data) {
|
12698 | if (!this.captionParser) {
|
12699 | this.captionParser = new captionParser();
|
12700 | this.captionParser.init();
|
12701 | }
|
12702 |
|
12703 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
12704 | var parsed = this.captionParser.parse(segment, data.trackIds, data.timescales);
|
12705 | this.self.postMessage({
|
12706 | action: 'mp4Captions',
|
12707 | captions: parsed && parsed.captions || [],
|
12708 | logs: parsed && parsed.logs || [],
|
12709 | data: segment.buffer
|
12710 | }, [segment.buffer]);
|
12711 | };
|
12712 |
|
12713 | _proto.probeMp4StartTime = function probeMp4StartTime(_ref) {
|
12714 | var timescales = _ref.timescales,
|
12715 | data = _ref.data;
|
12716 | var startTime = probe$2.startTime(timescales, data);
|
12717 | this.self.postMessage({
|
12718 | action: 'probeMp4StartTime',
|
12719 | startTime: startTime,
|
12720 | data: data
|
12721 | }, [data.buffer]);
|
12722 | };
|
12723 |
|
12724 | _proto.probeMp4Tracks = function probeMp4Tracks(_ref2) {
|
12725 | var data = _ref2.data;
|
12726 | var tracks = probe$2.tracks(data);
|
12727 | this.self.postMessage({
|
12728 | action: 'probeMp4Tracks',
|
12729 | tracks: tracks,
|
12730 | data: data
|
12731 | }, [data.buffer]);
|
12732 | }
|
12733 | |
12734 |
|
12735 |
|
12736 |
|
12737 |
|
12738 |
|
12739 |
|
12740 |
|
12741 |
|
12742 |
|
12743 |
|
12744 |
|
12745 |
|
12746 | ;
|
12747 |
|
12748 | _proto.probeTs = function probeTs(_ref3) {
|
12749 | var data = _ref3.data,
|
12750 | baseStartTime = _ref3.baseStartTime;
|
12751 | var tsStartTime = typeof baseStartTime === 'number' && !isNaN(baseStartTime) ? baseStartTime * clock.ONE_SECOND_IN_TS : void 0;
|
12752 | var timeInfo = tsInspector.inspect(data, tsStartTime);
|
12753 | var result = null;
|
12754 |
|
12755 | if (timeInfo) {
|
12756 | result = {
|
12757 |
|
12758 | hasVideo: timeInfo.video && timeInfo.video.length === 2 || false,
|
12759 | hasAudio: timeInfo.audio && timeInfo.audio.length === 2 || false
|
12760 | };
|
12761 |
|
12762 | if (result.hasVideo) {
|
12763 | result.videoStart = timeInfo.video[0].ptsTime;
|
12764 | }
|
12765 |
|
12766 | if (result.hasAudio) {
|
12767 | result.audioStart = timeInfo.audio[0].ptsTime;
|
12768 | }
|
12769 | }
|
12770 |
|
12771 | this.self.postMessage({
|
12772 | action: 'probeTs',
|
12773 | result: result,
|
12774 | data: data
|
12775 | }, [data.buffer]);
|
12776 | };
|
12777 |
|
12778 | _proto.clearAllMp4Captions = function clearAllMp4Captions() {
|
12779 | if (this.captionParser) {
|
12780 | this.captionParser.clearAllCaptions();
|
12781 | }
|
12782 | };
|
12783 |
|
12784 | _proto.clearParsedMp4Captions = function clearParsedMp4Captions() {
|
12785 | if (this.captionParser) {
|
12786 | this.captionParser.clearParsedCaptions();
|
12787 | }
|
12788 | }
|
12789 | |
12790 |
|
12791 |
|
12792 |
|
12793 |
|
12794 |
|
12795 | ;
|
12796 |
|
12797 | _proto.push = function push(data) {
|
12798 |
|
12799 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
12800 | this.transmuxer.push(segment);
|
12801 | }
|
12802 | |
12803 |
|
12804 |
|
12805 |
|
12806 | ;
|
12807 |
|
12808 | _proto.reset = function reset() {
|
12809 | this.transmuxer.reset();
|
12810 | }
|
12811 | |
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 |
|
12817 |
|
12818 | ;
|
12819 |
|
12820 | _proto.setTimestampOffset = function setTimestampOffset(data) {
|
12821 | var timestampOffset = data.timestampOffset || 0;
|
12822 | this.transmuxer.setBaseMediaDecodeTime(Math.round(clock.secondsToVideoTs(timestampOffset)));
|
12823 | };
|
12824 |
|
12825 | _proto.setAudioAppendStart = function setAudioAppendStart(data) {
|
12826 | this.transmuxer.setAudioAppendStart(Math.ceil(clock.secondsToVideoTs(data.appendStart)));
|
12827 | };
|
12828 |
|
12829 | _proto.setRemux = function setRemux(data) {
|
12830 | this.transmuxer.setRemux(data.remux);
|
12831 | }
|
12832 | |
12833 |
|
12834 |
|
12835 |
|
12836 |
|
12837 |
|
12838 | ;
|
12839 |
|
12840 | _proto.flush = function flush(data) {
|
12841 | this.transmuxer.flush();
|
12842 |
|
12843 | self.postMessage({
|
12844 | action: 'done',
|
12845 | type: 'transmuxed'
|
12846 | });
|
12847 | };
|
12848 |
|
12849 | _proto.endTimeline = function endTimeline() {
|
12850 | this.transmuxer.endTimeline();
|
12851 |
|
12852 |
|
12853 | self.postMessage({
|
12854 | action: 'endedtimeline',
|
12855 | type: 'transmuxed'
|
12856 | });
|
12857 | };
|
12858 |
|
12859 | _proto.alignGopsWith = function alignGopsWith(data) {
|
12860 | this.transmuxer.alignGopsWith(data.gopsToAlignWith.slice());
|
12861 | };
|
12862 |
|
12863 | return MessageHandlers;
|
12864 | }();
|
12865 | |
12866 |
|
12867 |
|
12868 |
|
12869 |
|
12870 |
|
12871 |
|
12872 |
|
12873 |
|
12874 | self.onmessage = function (event) {
|
12875 | if (event.data.action === 'init' && event.data.options) {
|
12876 | this.messageHandlers = new MessageHandlers(self, event.data.options);
|
12877 | return;
|
12878 | }
|
12879 |
|
12880 | if (!this.messageHandlers) {
|
12881 | this.messageHandlers = new MessageHandlers(self);
|
12882 | }
|
12883 |
|
12884 | if (event.data && event.data.action && event.data.action !== 'init') {
|
12885 | if (this.messageHandlers[event.data.action]) {
|
12886 | this.messageHandlers[event.data.action](event.data);
|
12887 | }
|
12888 | }
|
12889 | };
|
12890 | }));
|
12891 | var TransmuxWorker = factory(workerCode$1);
|
12892 |
|
12893 |
|
12894 | var handleData_ = function handleData_(event, transmuxedData, callback) {
|
12895 | var _event$data$segment = event.data.segment,
|
12896 | type = _event$data$segment.type,
|
12897 | initSegment = _event$data$segment.initSegment,
|
12898 | captions = _event$data$segment.captions,
|
12899 | captionStreams = _event$data$segment.captionStreams,
|
12900 | metadata = _event$data$segment.metadata,
|
12901 | videoFrameDtsTime = _event$data$segment.videoFrameDtsTime,
|
12902 | videoFramePtsTime = _event$data$segment.videoFramePtsTime;
|
12903 | transmuxedData.buffer.push({
|
12904 | captions: captions,
|
12905 | captionStreams: captionStreams,
|
12906 | metadata: metadata
|
12907 | });
|
12908 | var boxes = event.data.segment.boxes || {
|
12909 | data: event.data.segment.data
|
12910 | };
|
12911 | var result = {
|
12912 | type: type,
|
12913 |
|
12914 | data: new Uint8Array(boxes.data, boxes.data.byteOffset, boxes.data.byteLength),
|
12915 | initSegment: new Uint8Array(initSegment.data, initSegment.byteOffset, initSegment.byteLength)
|
12916 | };
|
12917 |
|
12918 | if (typeof videoFrameDtsTime !== 'undefined') {
|
12919 | result.videoFrameDtsTime = videoFrameDtsTime;
|
12920 | }
|
12921 |
|
12922 | if (typeof videoFramePtsTime !== 'undefined') {
|
12923 | result.videoFramePtsTime = videoFramePtsTime;
|
12924 | }
|
12925 |
|
12926 | callback(result);
|
12927 | };
|
12928 | var handleDone_ = function handleDone_(_ref) {
|
12929 | var transmuxedData = _ref.transmuxedData,
|
12930 | callback = _ref.callback;
|
12931 |
|
12932 |
|
12933 | transmuxedData.buffer = [];
|
12934 |
|
12935 |
|
12936 | callback(transmuxedData);
|
12937 | };
|
12938 | var handleGopInfo_ = function handleGopInfo_(event, transmuxedData) {
|
12939 | transmuxedData.gopInfo = event.data.gopInfo;
|
12940 | };
|
12941 | var processTransmux = function processTransmux(options) {
|
12942 | var transmuxer = options.transmuxer,
|
12943 | bytes = options.bytes,
|
12944 | audioAppendStart = options.audioAppendStart,
|
12945 | gopsToAlignWith = options.gopsToAlignWith,
|
12946 | remux = options.remux,
|
12947 | onData = options.onData,
|
12948 | onTrackInfo = options.onTrackInfo,
|
12949 | onAudioTimingInfo = options.onAudioTimingInfo,
|
12950 | onVideoTimingInfo = options.onVideoTimingInfo,
|
12951 | onVideoSegmentTimingInfo = options.onVideoSegmentTimingInfo,
|
12952 | onAudioSegmentTimingInfo = options.onAudioSegmentTimingInfo,
|
12953 | onId3 = options.onId3,
|
12954 | onCaptions = options.onCaptions,
|
12955 | onDone = options.onDone,
|
12956 | onEndedTimeline = options.onEndedTimeline,
|
12957 | onTransmuxerLog = options.onTransmuxerLog,
|
12958 | isEndOfTimeline = options.isEndOfTimeline;
|
12959 | var transmuxedData = {
|
12960 | buffer: []
|
12961 | };
|
12962 | var waitForEndedTimelineEvent = isEndOfTimeline;
|
12963 |
|
12964 | var handleMessage = function handleMessage(event) {
|
12965 | if (transmuxer.currentTransmux !== options) {
|
12966 |
|
12967 | return;
|
12968 | }
|
12969 |
|
12970 | if (event.data.action === 'data') {
|
12971 | handleData_(event, transmuxedData, onData);
|
12972 | }
|
12973 |
|
12974 | if (event.data.action === 'trackinfo') {
|
12975 | onTrackInfo(event.data.trackInfo);
|
12976 | }
|
12977 |
|
12978 | if (event.data.action === 'gopInfo') {
|
12979 | handleGopInfo_(event, transmuxedData);
|
12980 | }
|
12981 |
|
12982 | if (event.data.action === 'audioTimingInfo') {
|
12983 | onAudioTimingInfo(event.data.audioTimingInfo);
|
12984 | }
|
12985 |
|
12986 | if (event.data.action === 'videoTimingInfo') {
|
12987 | onVideoTimingInfo(event.data.videoTimingInfo);
|
12988 | }
|
12989 |
|
12990 | if (event.data.action === 'videoSegmentTimingInfo') {
|
12991 | onVideoSegmentTimingInfo(event.data.videoSegmentTimingInfo);
|
12992 | }
|
12993 |
|
12994 | if (event.data.action === 'audioSegmentTimingInfo') {
|
12995 | onAudioSegmentTimingInfo(event.data.audioSegmentTimingInfo);
|
12996 | }
|
12997 |
|
12998 | if (event.data.action === 'id3Frame') {
|
12999 | onId3([event.data.id3Frame], event.data.id3Frame.dispatchType);
|
13000 | }
|
13001 |
|
13002 | if (event.data.action === 'caption') {
|
13003 | onCaptions(event.data.caption);
|
13004 | }
|
13005 |
|
13006 | if (event.data.action === 'endedtimeline') {
|
13007 | waitForEndedTimelineEvent = false;
|
13008 | onEndedTimeline();
|
13009 | }
|
13010 |
|
13011 | if (event.data.action === 'log') {
|
13012 | onTransmuxerLog(event.data.log);
|
13013 | }
|
13014 |
|
13015 |
|
13016 | if (event.data.type !== 'transmuxed') {
|
13017 | return;
|
13018 | }
|
13019 |
|
13020 |
|
13021 |
|
13022 |
|
13023 |
|
13024 | if (waitForEndedTimelineEvent) {
|
13025 | return;
|
13026 | }
|
13027 |
|
13028 | transmuxer.onmessage = null;
|
13029 | handleDone_({
|
13030 | transmuxedData: transmuxedData,
|
13031 | callback: onDone
|
13032 | });
|
13033 |
|
13034 |
|
13035 | dequeue(transmuxer);
|
13036 |
|
13037 | };
|
13038 |
|
13039 | transmuxer.onmessage = handleMessage;
|
13040 |
|
13041 | if (audioAppendStart) {
|
13042 | transmuxer.postMessage({
|
13043 | action: 'setAudioAppendStart',
|
13044 | appendStart: audioAppendStart
|
13045 | });
|
13046 | }
|
13047 |
|
13048 |
|
13049 | if (Array.isArray(gopsToAlignWith)) {
|
13050 | transmuxer.postMessage({
|
13051 | action: 'alignGopsWith',
|
13052 | gopsToAlignWith: gopsToAlignWith
|
13053 | });
|
13054 | }
|
13055 |
|
13056 | if (typeof remux !== 'undefined') {
|
13057 | transmuxer.postMessage({
|
13058 | action: 'setRemux',
|
13059 | remux: remux
|
13060 | });
|
13061 | }
|
13062 |
|
13063 | if (bytes.byteLength) {
|
13064 | var buffer = bytes instanceof ArrayBuffer ? bytes : bytes.buffer;
|
13065 | var byteOffset = bytes instanceof ArrayBuffer ? 0 : bytes.byteOffset;
|
13066 | transmuxer.postMessage({
|
13067 | action: 'push',
|
13068 |
|
13069 |
|
13070 |
|
13071 | data: buffer,
|
13072 |
|
13073 |
|
13074 | byteOffset: byteOffset,
|
13075 | byteLength: bytes.byteLength
|
13076 | }, [buffer]);
|
13077 | }
|
13078 |
|
13079 | if (isEndOfTimeline) {
|
13080 | transmuxer.postMessage({
|
13081 | action: 'endTimeline'
|
13082 | });
|
13083 | }
|
13084 |
|
13085 |
|
13086 |
|
13087 | transmuxer.postMessage({
|
13088 | action: 'flush'
|
13089 | });
|
13090 | };
|
13091 | var dequeue = function dequeue(transmuxer) {
|
13092 | transmuxer.currentTransmux = null;
|
13093 |
|
13094 | if (transmuxer.transmuxQueue.length) {
|
13095 | transmuxer.currentTransmux = transmuxer.transmuxQueue.shift();
|
13096 |
|
13097 | if (typeof transmuxer.currentTransmux === 'function') {
|
13098 | transmuxer.currentTransmux();
|
13099 | } else {
|
13100 | processTransmux(transmuxer.currentTransmux);
|
13101 | }
|
13102 | }
|
13103 | };
|
13104 | var processAction = function processAction(transmuxer, action) {
|
13105 | transmuxer.postMessage({
|
13106 | action: action
|
13107 | });
|
13108 | dequeue(transmuxer);
|
13109 | };
|
13110 | var enqueueAction = function enqueueAction(action, transmuxer) {
|
13111 | if (!transmuxer.currentTransmux) {
|
13112 | transmuxer.currentTransmux = action;
|
13113 | processAction(transmuxer, action);
|
13114 | return;
|
13115 | }
|
13116 |
|
13117 | transmuxer.transmuxQueue.push(processAction.bind(null, transmuxer, action));
|
13118 | };
|
13119 | var reset = function reset(transmuxer) {
|
13120 | enqueueAction('reset', transmuxer);
|
13121 | };
|
13122 | var endTimeline = function endTimeline(transmuxer) {
|
13123 | enqueueAction('endTimeline', transmuxer);
|
13124 | };
|
13125 | var transmux = function transmux(options) {
|
13126 | if (!options.transmuxer.currentTransmux) {
|
13127 | options.transmuxer.currentTransmux = options;
|
13128 | processTransmux(options);
|
13129 | return;
|
13130 | }
|
13131 |
|
13132 | options.transmuxer.transmuxQueue.push(options);
|
13133 | };
|
13134 | var createTransmuxer = function createTransmuxer(options) {
|
13135 | var transmuxer = new TransmuxWorker();
|
13136 | transmuxer.currentTransmux = null;
|
13137 | transmuxer.transmuxQueue = [];
|
13138 | var term = transmuxer.terminate;
|
13139 |
|
13140 | transmuxer.terminate = function () {
|
13141 | transmuxer.currentTransmux = null;
|
13142 | transmuxer.transmuxQueue.length = 0;
|
13143 | return term.call(transmuxer);
|
13144 | };
|
13145 |
|
13146 | transmuxer.postMessage({
|
13147 | action: 'init',
|
13148 | options: options
|
13149 | });
|
13150 | return transmuxer;
|
13151 | };
|
13152 | var segmentTransmuxer = {
|
13153 | reset: reset,
|
13154 | endTimeline: endTimeline,
|
13155 | transmux: transmux,
|
13156 | createTransmuxer: createTransmuxer
|
13157 | };
|
13158 |
|
13159 | var workerCallback = function workerCallback(options) {
|
13160 | var transmuxer = options.transmuxer;
|
13161 | var endAction = options.endAction || options.action;
|
13162 | var callback = options.callback;
|
13163 |
|
13164 | var message = _extends__default["default"]({}, options, {
|
13165 | endAction: null,
|
13166 | transmuxer: null,
|
13167 | callback: null
|
13168 | });
|
13169 |
|
13170 | var listenForEndEvent = function listenForEndEvent(event) {
|
13171 | if (event.data.action !== endAction) {
|
13172 | return;
|
13173 | }
|
13174 |
|
13175 | transmuxer.removeEventListener('message', listenForEndEvent);
|
13176 |
|
13177 | if (event.data.data) {
|
13178 | event.data.data = new Uint8Array(event.data.data, options.byteOffset || 0, options.byteLength || event.data.data.byteLength);
|
13179 |
|
13180 | if (options.data) {
|
13181 | options.data = event.data.data;
|
13182 | }
|
13183 | }
|
13184 |
|
13185 | callback(event.data);
|
13186 | };
|
13187 |
|
13188 | transmuxer.addEventListener('message', listenForEndEvent);
|
13189 |
|
13190 | if (options.data) {
|
13191 | var isArrayBuffer = options.data instanceof ArrayBuffer;
|
13192 | message.byteOffset = isArrayBuffer ? 0 : options.data.byteOffset;
|
13193 | message.byteLength = options.data.byteLength;
|
13194 | var transfers = [isArrayBuffer ? options.data : options.data.buffer];
|
13195 | transmuxer.postMessage(message, transfers);
|
13196 | } else {
|
13197 | transmuxer.postMessage(message);
|
13198 | }
|
13199 | };
|
13200 |
|
13201 | var REQUEST_ERRORS = {
|
13202 | FAILURE: 2,
|
13203 | TIMEOUT: -101,
|
13204 | ABORTED: -102
|
13205 | };
|
13206 |
|
13207 |
|
13208 |
|
13209 |
|
13210 |
|
13211 |
|
13212 | var abortAll = function abortAll(activeXhrs) {
|
13213 | activeXhrs.forEach(function (xhr) {
|
13214 | xhr.abort();
|
13215 | });
|
13216 | };
|
13217 |
|
13218 |
|
13219 |
|
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 | var getRequestStats = function getRequestStats(request) {
|
13225 | return {
|
13226 | bandwidth: request.bandwidth,
|
13227 | bytesReceived: request.bytesReceived || 0,
|
13228 | roundTripTime: request.roundTripTime || 0
|
13229 | };
|
13230 | };
|
13231 |
|
13232 |
|
13233 |
|
13234 |
|
13235 |
|
13236 |
|
13237 |
|
13238 |
|
13239 | var getProgressStats = function getProgressStats(progressEvent) {
|
13240 | var request = progressEvent.target;
|
13241 | var roundTripTime = Date.now() - request.requestTime;
|
13242 | var stats = {
|
13243 | bandwidth: Infinity,
|
13244 | bytesReceived: 0,
|
13245 | roundTripTime: roundTripTime || 0
|
13246 | };
|
13247 | stats.bytesReceived = progressEvent.loaded;
|
13248 |
|
13249 |
|
13250 |
|
13251 | stats.bandwidth = Math.floor(stats.bytesReceived / stats.roundTripTime * 8 * 1000);
|
13252 | return stats;
|
13253 | };
|
13254 |
|
13255 |
|
13256 |
|
13257 |
|
13258 |
|
13259 |
|
13260 |
|
13261 |
|
13262 |
|
13263 | var handleErrors = function handleErrors(error, request) {
|
13264 | if (request.timedout) {
|
13265 | return {
|
13266 | status: request.status,
|
13267 | message: 'HLS request timed-out at URL: ' + request.uri,
|
13268 | code: REQUEST_ERRORS.TIMEOUT,
|
13269 | xhr: request
|
13270 | };
|
13271 | }
|
13272 |
|
13273 | if (request.aborted) {
|
13274 | return {
|
13275 | status: request.status,
|
13276 | message: 'HLS request aborted at URL: ' + request.uri,
|
13277 | code: REQUEST_ERRORS.ABORTED,
|
13278 | xhr: request
|
13279 | };
|
13280 | }
|
13281 |
|
13282 | if (error) {
|
13283 | return {
|
13284 | status: request.status,
|
13285 | message: 'HLS request errored at URL: ' + request.uri,
|
13286 | code: REQUEST_ERRORS.FAILURE,
|
13287 | xhr: request
|
13288 | };
|
13289 | }
|
13290 |
|
13291 | if (request.responseType === 'arraybuffer' && request.response.byteLength === 0) {
|
13292 | return {
|
13293 | status: request.status,
|
13294 | message: 'Empty HLS response at URL: ' + request.uri,
|
13295 | code: REQUEST_ERRORS.FAILURE,
|
13296 | xhr: request
|
13297 | };
|
13298 | }
|
13299 |
|
13300 | return null;
|
13301 | };
|
13302 |
|
13303 |
|
13304 |
|
13305 |
|
13306 |
|
13307 |
|
13308 |
|
13309 |
|
13310 |
|
13311 |
|
13312 |
|
13313 |
|
13314 | var handleKeyResponse = function handleKeyResponse(segment, objects, finishProcessingFn) {
|
13315 | return function (error, request) {
|
13316 | var response = request.response;
|
13317 | var errorObj = handleErrors(error, request);
|
13318 |
|
13319 | if (errorObj) {
|
13320 | return finishProcessingFn(errorObj, segment);
|
13321 | }
|
13322 |
|
13323 | if (response.byteLength !== 16) {
|
13324 | return finishProcessingFn({
|
13325 | status: request.status,
|
13326 | message: 'Invalid HLS key at URL: ' + request.uri,
|
13327 | code: REQUEST_ERRORS.FAILURE,
|
13328 | xhr: request
|
13329 | }, segment);
|
13330 | }
|
13331 |
|
13332 | var view = new DataView(response);
|
13333 | var bytes = new Uint32Array([view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12)]);
|
13334 |
|
13335 | for (var i = 0; i < objects.length; i++) {
|
13336 | objects[i].bytes = bytes;
|
13337 | }
|
13338 |
|
13339 | return finishProcessingFn(null, segment);
|
13340 | };
|
13341 | };
|
13342 |
|
13343 | var parseInitSegment = function parseInitSegment(segment, _callback) {
|
13344 | var type = containers.detectContainerForBytes(segment.map.bytes);
|
13345 |
|
13346 |
|
13347 | if (type !== 'mp4') {
|
13348 | var uri = segment.map.resolvedUri || segment.map.uri;
|
13349 | return _callback({
|
13350 | internal: true,
|
13351 | message: "Found unsupported " + (type || 'unknown') + " container for initialization segment at URL: " + uri,
|
13352 | code: REQUEST_ERRORS.FAILURE
|
13353 | });
|
13354 | }
|
13355 |
|
13356 | workerCallback({
|
13357 | action: 'probeMp4Tracks',
|
13358 | data: segment.map.bytes,
|
13359 | transmuxer: segment.transmuxer,
|
13360 | callback: function callback(_ref) {
|
13361 | var tracks = _ref.tracks,
|
13362 | data = _ref.data;
|
13363 |
|
13364 | segment.map.bytes = data;
|
13365 | tracks.forEach(function (track) {
|
13366 | segment.map.tracks = segment.map.tracks || {};
|
13367 |
|
13368 | if (segment.map.tracks[track.type]) {
|
13369 | return;
|
13370 | }
|
13371 |
|
13372 | segment.map.tracks[track.type] = track;
|
13373 |
|
13374 | if (typeof track.id === 'number' && track.timescale) {
|
13375 | segment.map.timescales = segment.map.timescales || {};
|
13376 | segment.map.timescales[track.id] = track.timescale;
|
13377 | }
|
13378 | });
|
13379 | return _callback(null);
|
13380 | }
|
13381 | });
|
13382 | };
|
13383 |
|
13384 |
|
13385 |
|
13386 |
|
13387 |
|
13388 |
|
13389 |
|
13390 |
|
13391 |
|
13392 |
|
13393 | var handleInitSegmentResponse = function handleInitSegmentResponse(_ref2) {
|
13394 | var segment = _ref2.segment,
|
13395 | finishProcessingFn = _ref2.finishProcessingFn;
|
13396 | return function (error, request) {
|
13397 | var errorObj = handleErrors(error, request);
|
13398 |
|
13399 | if (errorObj) {
|
13400 | return finishProcessingFn(errorObj, segment);
|
13401 | }
|
13402 |
|
13403 | var bytes = new Uint8Array(request.response);
|
13404 |
|
13405 |
|
13406 | if (segment.map.key) {
|
13407 | segment.map.encryptedBytes = bytes;
|
13408 | return finishProcessingFn(null, segment);
|
13409 | }
|
13410 |
|
13411 | segment.map.bytes = bytes;
|
13412 | parseInitSegment(segment, function (parseError) {
|
13413 | if (parseError) {
|
13414 | parseError.xhr = request;
|
13415 | parseError.status = request.status;
|
13416 | return finishProcessingFn(parseError, segment);
|
13417 | }
|
13418 |
|
13419 | finishProcessingFn(null, segment);
|
13420 | });
|
13421 | };
|
13422 | };
|
13423 |
|
13424 |
|
13425 |
|
13426 |
|
13427 |
|
13428 |
|
13429 |
|
13430 |
|
13431 |
|
13432 |
|
13433 |
|
13434 |
|
13435 | var handleSegmentResponse = function handleSegmentResponse(_ref3) {
|
13436 | var segment = _ref3.segment,
|
13437 | finishProcessingFn = _ref3.finishProcessingFn,
|
13438 | responseType = _ref3.responseType;
|
13439 | return function (error, request) {
|
13440 | var errorObj = handleErrors(error, request);
|
13441 |
|
13442 | if (errorObj) {
|
13443 | return finishProcessingFn(errorObj, segment);
|
13444 | }
|
13445 |
|
13446 | var newBytes =
|
13447 |
|
13448 |
|
13449 |
|
13450 |
|
13451 | responseType === 'arraybuffer' || !request.responseText ? request.response : stringToArrayBuffer(request.responseText.substring(segment.lastReachedChar || 0));
|
13452 | segment.stats = getRequestStats(request);
|
13453 |
|
13454 | if (segment.key) {
|
13455 | segment.encryptedBytes = new Uint8Array(newBytes);
|
13456 | } else {
|
13457 | segment.bytes = new Uint8Array(newBytes);
|
13458 | }
|
13459 |
|
13460 | return finishProcessingFn(null, segment);
|
13461 | };
|
13462 | };
|
13463 |
|
13464 | var transmuxAndNotify = function transmuxAndNotify(_ref4) {
|
13465 | var segment = _ref4.segment,
|
13466 | bytes = _ref4.bytes,
|
13467 | trackInfoFn = _ref4.trackInfoFn,
|
13468 | timingInfoFn = _ref4.timingInfoFn,
|
13469 | videoSegmentTimingInfoFn = _ref4.videoSegmentTimingInfoFn,
|
13470 | audioSegmentTimingInfoFn = _ref4.audioSegmentTimingInfoFn,
|
13471 | id3Fn = _ref4.id3Fn,
|
13472 | captionsFn = _ref4.captionsFn,
|
13473 | isEndOfTimeline = _ref4.isEndOfTimeline,
|
13474 | endedTimelineFn = _ref4.endedTimelineFn,
|
13475 | dataFn = _ref4.dataFn,
|
13476 | doneFn = _ref4.doneFn,
|
13477 | onTransmuxerLog = _ref4.onTransmuxerLog;
|
13478 | var fmp4Tracks = segment.map && segment.map.tracks || {};
|
13479 | var isMuxed = Boolean(fmp4Tracks.audio && fmp4Tracks.video);
|
13480 |
|
13481 |
|
13482 |
|
13483 | var audioStartFn = timingInfoFn.bind(null, segment, 'audio', 'start');
|
13484 | var audioEndFn = timingInfoFn.bind(null, segment, 'audio', 'end');
|
13485 | var videoStartFn = timingInfoFn.bind(null, segment, 'video', 'start');
|
13486 | var videoEndFn = timingInfoFn.bind(null, segment, 'video', 'end');
|
13487 |
|
13488 | var finish = function finish() {
|
13489 | return transmux({
|
13490 | bytes: bytes,
|
13491 | transmuxer: segment.transmuxer,
|
13492 | audioAppendStart: segment.audioAppendStart,
|
13493 | gopsToAlignWith: segment.gopsToAlignWith,
|
13494 | remux: isMuxed,
|
13495 | onData: function onData(result) {
|
13496 | result.type = result.type === 'combined' ? 'video' : result.type;
|
13497 | dataFn(segment, result);
|
13498 | },
|
13499 | onTrackInfo: function onTrackInfo(trackInfo) {
|
13500 | if (trackInfoFn) {
|
13501 | if (isMuxed) {
|
13502 | trackInfo.isMuxed = true;
|
13503 | }
|
13504 |
|
13505 | trackInfoFn(segment, trackInfo);
|
13506 | }
|
13507 | },
|
13508 | onAudioTimingInfo: function onAudioTimingInfo(audioTimingInfo) {
|
13509 |
|
13510 | if (audioStartFn && typeof audioTimingInfo.start !== 'undefined') {
|
13511 | audioStartFn(audioTimingInfo.start);
|
13512 | audioStartFn = null;
|
13513 | }
|
13514 |
|
13515 |
|
13516 | if (audioEndFn && typeof audioTimingInfo.end !== 'undefined') {
|
13517 | audioEndFn(audioTimingInfo.end);
|
13518 | }
|
13519 | },
|
13520 | onVideoTimingInfo: function onVideoTimingInfo(videoTimingInfo) {
|
13521 |
|
13522 | if (videoStartFn && typeof videoTimingInfo.start !== 'undefined') {
|
13523 | videoStartFn(videoTimingInfo.start);
|
13524 | videoStartFn = null;
|
13525 | }
|
13526 |
|
13527 |
|
13528 | if (videoEndFn && typeof videoTimingInfo.end !== 'undefined') {
|
13529 | videoEndFn(videoTimingInfo.end);
|
13530 | }
|
13531 | },
|
13532 | onVideoSegmentTimingInfo: function onVideoSegmentTimingInfo(videoSegmentTimingInfo) {
|
13533 | videoSegmentTimingInfoFn(videoSegmentTimingInfo);
|
13534 | },
|
13535 | onAudioSegmentTimingInfo: function onAudioSegmentTimingInfo(audioSegmentTimingInfo) {
|
13536 | audioSegmentTimingInfoFn(audioSegmentTimingInfo);
|
13537 | },
|
13538 | onId3: function onId3(id3Frames, dispatchType) {
|
13539 | id3Fn(segment, id3Frames, dispatchType);
|
13540 | },
|
13541 | onCaptions: function onCaptions(captions) {
|
13542 | captionsFn(segment, [captions]);
|
13543 | },
|
13544 | isEndOfTimeline: isEndOfTimeline,
|
13545 | onEndedTimeline: function onEndedTimeline() {
|
13546 | endedTimelineFn();
|
13547 | },
|
13548 | onTransmuxerLog: onTransmuxerLog,
|
13549 | onDone: function onDone(result) {
|
13550 | if (!doneFn) {
|
13551 | return;
|
13552 | }
|
13553 |
|
13554 | result.type = result.type === 'combined' ? 'video' : result.type;
|
13555 | doneFn(null, segment, result);
|
13556 | }
|
13557 | });
|
13558 | };
|
13559 |
|
13560 |
|
13561 |
|
13562 |
|
13563 | workerCallback({
|
13564 | action: 'probeTs',
|
13565 | transmuxer: segment.transmuxer,
|
13566 | data: bytes,
|
13567 | baseStartTime: segment.baseStartTime,
|
13568 | callback: function callback(data) {
|
13569 | segment.bytes = bytes = data.data;
|
13570 | var probeResult = data.result;
|
13571 |
|
13572 | if (probeResult) {
|
13573 | trackInfoFn(segment, {
|
13574 | hasAudio: probeResult.hasAudio,
|
13575 | hasVideo: probeResult.hasVideo,
|
13576 | isMuxed: isMuxed
|
13577 | });
|
13578 | trackInfoFn = null;
|
13579 |
|
13580 | if (probeResult.hasAudio && !isMuxed) {
|
13581 | audioStartFn(probeResult.audioStart);
|
13582 | }
|
13583 |
|
13584 | if (probeResult.hasVideo) {
|
13585 | videoStartFn(probeResult.videoStart);
|
13586 | }
|
13587 |
|
13588 | audioStartFn = null;
|
13589 | videoStartFn = null;
|
13590 | }
|
13591 |
|
13592 | finish();
|
13593 | }
|
13594 | });
|
13595 | };
|
13596 |
|
13597 | var handleSegmentBytes = function handleSegmentBytes(_ref5) {
|
13598 | var segment = _ref5.segment,
|
13599 | bytes = _ref5.bytes,
|
13600 | trackInfoFn = _ref5.trackInfoFn,
|
13601 | timingInfoFn = _ref5.timingInfoFn,
|
13602 | videoSegmentTimingInfoFn = _ref5.videoSegmentTimingInfoFn,
|
13603 | audioSegmentTimingInfoFn = _ref5.audioSegmentTimingInfoFn,
|
13604 | id3Fn = _ref5.id3Fn,
|
13605 | captionsFn = _ref5.captionsFn,
|
13606 | isEndOfTimeline = _ref5.isEndOfTimeline,
|
13607 | endedTimelineFn = _ref5.endedTimelineFn,
|
13608 | dataFn = _ref5.dataFn,
|
13609 | doneFn = _ref5.doneFn,
|
13610 | onTransmuxerLog = _ref5.onTransmuxerLog;
|
13611 | var bytesAsUint8Array = new Uint8Array(bytes);
|
13612 |
|
13613 |
|
13614 |
|
13615 |
|
13616 |
|
13617 | if (containers.isLikelyFmp4MediaSegment(bytesAsUint8Array)) {
|
13618 | segment.isFmp4 = true;
|
13619 | var tracks = segment.map.tracks;
|
13620 | var trackInfo = {
|
13621 | isFmp4: true,
|
13622 | hasVideo: !!tracks.video,
|
13623 | hasAudio: !!tracks.audio
|
13624 | };
|
13625 |
|
13626 |
|
13627 | if (tracks.audio && tracks.audio.codec && tracks.audio.codec !== 'enca') {
|
13628 | trackInfo.audioCodec = tracks.audio.codec;
|
13629 | }
|
13630 |
|
13631 |
|
13632 |
|
13633 | if (tracks.video && tracks.video.codec && tracks.video.codec !== 'encv') {
|
13634 | trackInfo.videoCodec = tracks.video.codec;
|
13635 | }
|
13636 |
|
13637 | if (tracks.video && tracks.audio) {
|
13638 | trackInfo.isMuxed = true;
|
13639 | }
|
13640 |
|
13641 |
|
13642 |
|
13643 | trackInfoFn(segment, trackInfo);
|
13644 |
|
13645 |
|
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 | var finishLoading = function finishLoading(captions) {
|
13651 |
|
13652 |
|
13653 |
|
13654 |
|
13655 | dataFn(segment, {
|
13656 | data: bytesAsUint8Array,
|
13657 | type: trackInfo.hasAudio && !trackInfo.isMuxed ? 'audio' : 'video'
|
13658 | });
|
13659 |
|
13660 | if (captions && captions.length) {
|
13661 | captionsFn(segment, captions);
|
13662 | }
|
13663 |
|
13664 | doneFn(null, segment, {});
|
13665 | };
|
13666 |
|
13667 | workerCallback({
|
13668 | action: 'probeMp4StartTime',
|
13669 | timescales: segment.map.timescales,
|
13670 | data: bytesAsUint8Array,
|
13671 | transmuxer: segment.transmuxer,
|
13672 | callback: function callback(_ref6) {
|
13673 | var data = _ref6.data,
|
13674 | startTime = _ref6.startTime;
|
13675 |
|
13676 | bytes = data.buffer;
|
13677 | segment.bytes = bytesAsUint8Array = data;
|
13678 |
|
13679 | if (trackInfo.hasAudio && !trackInfo.isMuxed) {
|
13680 | timingInfoFn(segment, 'audio', 'start', startTime);
|
13681 | }
|
13682 |
|
13683 | if (trackInfo.hasVideo) {
|
13684 | timingInfoFn(segment, 'video', 'start', startTime);
|
13685 | }
|
13686 |
|
13687 |
|
13688 |
|
13689 | if (!tracks.video || !data.byteLength || !segment.transmuxer) {
|
13690 | finishLoading();
|
13691 | return;
|
13692 | }
|
13693 |
|
13694 | workerCallback({
|
13695 | action: 'pushMp4Captions',
|
13696 | endAction: 'mp4Captions',
|
13697 | transmuxer: segment.transmuxer,
|
13698 | data: bytesAsUint8Array,
|
13699 | timescales: segment.map.timescales,
|
13700 | trackIds: [tracks.video.id],
|
13701 | callback: function callback(message) {
|
13702 |
|
13703 | bytes = message.data.buffer;
|
13704 | segment.bytes = bytesAsUint8Array = message.data;
|
13705 | message.logs.forEach(function (log) {
|
13706 | onTransmuxerLog(videojs__default["default"].mergeOptions(log, {
|
13707 | stream: 'mp4CaptionParser'
|
13708 | }));
|
13709 | });
|
13710 | finishLoading(message.captions);
|
13711 | }
|
13712 | });
|
13713 | }
|
13714 | });
|
13715 | return;
|
13716 | }
|
13717 |
|
13718 |
|
13719 | if (!segment.transmuxer) {
|
13720 | doneFn(null, segment, {});
|
13721 | return;
|
13722 | }
|
13723 |
|
13724 | if (typeof segment.container === 'undefined') {
|
13725 | segment.container = containers.detectContainerForBytes(bytesAsUint8Array);
|
13726 | }
|
13727 |
|
13728 | if (segment.container !== 'ts' && segment.container !== 'aac') {
|
13729 | trackInfoFn(segment, {
|
13730 | hasAudio: false,
|
13731 | hasVideo: false
|
13732 | });
|
13733 | doneFn(null, segment, {});
|
13734 | return;
|
13735 | }
|
13736 |
|
13737 |
|
13738 | transmuxAndNotify({
|
13739 | segment: segment,
|
13740 | bytes: bytes,
|
13741 | trackInfoFn: trackInfoFn,
|
13742 | timingInfoFn: timingInfoFn,
|
13743 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13744 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13745 | id3Fn: id3Fn,
|
13746 | captionsFn: captionsFn,
|
13747 | isEndOfTimeline: isEndOfTimeline,
|
13748 | endedTimelineFn: endedTimelineFn,
|
13749 | dataFn: dataFn,
|
13750 | doneFn: doneFn,
|
13751 | onTransmuxerLog: onTransmuxerLog
|
13752 | });
|
13753 | };
|
13754 |
|
13755 | var decrypt = function decrypt(_ref7, callback) {
|
13756 | var id = _ref7.id,
|
13757 | key = _ref7.key,
|
13758 | encryptedBytes = _ref7.encryptedBytes,
|
13759 | decryptionWorker = _ref7.decryptionWorker;
|
13760 |
|
13761 | var decryptionHandler = function decryptionHandler(event) {
|
13762 | if (event.data.source === id) {
|
13763 | decryptionWorker.removeEventListener('message', decryptionHandler);
|
13764 | var decrypted = event.data.decrypted;
|
13765 | callback(new Uint8Array(decrypted.bytes, decrypted.byteOffset, decrypted.byteLength));
|
13766 | }
|
13767 | };
|
13768 |
|
13769 | decryptionWorker.addEventListener('message', decryptionHandler);
|
13770 | var keyBytes;
|
13771 |
|
13772 | if (key.bytes.slice) {
|
13773 | keyBytes = key.bytes.slice();
|
13774 | } else {
|
13775 | keyBytes = new Uint32Array(Array.prototype.slice.call(key.bytes));
|
13776 | }
|
13777 |
|
13778 |
|
13779 | decryptionWorker.postMessage(createTransferableMessage({
|
13780 | source: id,
|
13781 | encrypted: encryptedBytes,
|
13782 | key: keyBytes,
|
13783 | iv: key.iv
|
13784 | }), [encryptedBytes.buffer, keyBytes.buffer]);
|
13785 | };
|
13786 |
|
13787 |
|
13788 |
|
13789 |
|
13790 |
|
13791 |
|
13792 |
|
13793 |
|
13794 |
|
13795 |
|
13796 |
|
13797 |
|
13798 |
|
13799 |
|
13800 |
|
13801 |
|
13802 |
|
13803 |
|
13804 |
|
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 | var decryptSegment = function decryptSegment(_ref8) {
|
13813 | var decryptionWorker = _ref8.decryptionWorker,
|
13814 | segment = _ref8.segment,
|
13815 | trackInfoFn = _ref8.trackInfoFn,
|
13816 | timingInfoFn = _ref8.timingInfoFn,
|
13817 | videoSegmentTimingInfoFn = _ref8.videoSegmentTimingInfoFn,
|
13818 | audioSegmentTimingInfoFn = _ref8.audioSegmentTimingInfoFn,
|
13819 | id3Fn = _ref8.id3Fn,
|
13820 | captionsFn = _ref8.captionsFn,
|
13821 | isEndOfTimeline = _ref8.isEndOfTimeline,
|
13822 | endedTimelineFn = _ref8.endedTimelineFn,
|
13823 | dataFn = _ref8.dataFn,
|
13824 | doneFn = _ref8.doneFn,
|
13825 | onTransmuxerLog = _ref8.onTransmuxerLog;
|
13826 | decrypt({
|
13827 | id: segment.requestId,
|
13828 | key: segment.key,
|
13829 | encryptedBytes: segment.encryptedBytes,
|
13830 | decryptionWorker: decryptionWorker
|
13831 | }, function (decryptedBytes) {
|
13832 | segment.bytes = decryptedBytes;
|
13833 | handleSegmentBytes({
|
13834 | segment: segment,
|
13835 | bytes: segment.bytes,
|
13836 | trackInfoFn: trackInfoFn,
|
13837 | timingInfoFn: timingInfoFn,
|
13838 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13839 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13840 | id3Fn: id3Fn,
|
13841 | captionsFn: captionsFn,
|
13842 | isEndOfTimeline: isEndOfTimeline,
|
13843 | endedTimelineFn: endedTimelineFn,
|
13844 | dataFn: dataFn,
|
13845 | doneFn: doneFn,
|
13846 | onTransmuxerLog: onTransmuxerLog
|
13847 | });
|
13848 | });
|
13849 | };
|
13850 |
|
13851 |
|
13852 |
|
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 |
|
13871 |
|
13872 |
|
13873 |
|
13874 |
|
13875 |
|
13876 |
|
13877 |
|
13878 |
|
13879 |
|
13880 |
|
13881 | var waitForCompletion = function waitForCompletion(_ref9) {
|
13882 | var activeXhrs = _ref9.activeXhrs,
|
13883 | decryptionWorker = _ref9.decryptionWorker,
|
13884 | trackInfoFn = _ref9.trackInfoFn,
|
13885 | timingInfoFn = _ref9.timingInfoFn,
|
13886 | videoSegmentTimingInfoFn = _ref9.videoSegmentTimingInfoFn,
|
13887 | audioSegmentTimingInfoFn = _ref9.audioSegmentTimingInfoFn,
|
13888 | id3Fn = _ref9.id3Fn,
|
13889 | captionsFn = _ref9.captionsFn,
|
13890 | isEndOfTimeline = _ref9.isEndOfTimeline,
|
13891 | endedTimelineFn = _ref9.endedTimelineFn,
|
13892 | dataFn = _ref9.dataFn,
|
13893 | doneFn = _ref9.doneFn,
|
13894 | onTransmuxerLog = _ref9.onTransmuxerLog;
|
13895 | var count = 0;
|
13896 | var didError = false;
|
13897 | return function (error, segment) {
|
13898 | if (didError) {
|
13899 | return;
|
13900 | }
|
13901 |
|
13902 | if (error) {
|
13903 | didError = true;
|
13904 |
|
13905 | abortAll(activeXhrs);
|
13906 |
|
13907 |
|
13908 |
|
13909 |
|
13910 |
|
13911 |
|
13912 |
|
13913 |
|
13914 |
|
13915 |
|
13916 |
|
13917 | return doneFn(error, segment);
|
13918 | }
|
13919 |
|
13920 | count += 1;
|
13921 |
|
13922 | if (count === activeXhrs.length) {
|
13923 | var segmentFinish = function segmentFinish() {
|
13924 | if (segment.encryptedBytes) {
|
13925 | return decryptSegment({
|
13926 | decryptionWorker: decryptionWorker,
|
13927 | segment: segment,
|
13928 | trackInfoFn: trackInfoFn,
|
13929 | timingInfoFn: timingInfoFn,
|
13930 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13931 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13932 | id3Fn: id3Fn,
|
13933 | captionsFn: captionsFn,
|
13934 | isEndOfTimeline: isEndOfTimeline,
|
13935 | endedTimelineFn: endedTimelineFn,
|
13936 | dataFn: dataFn,
|
13937 | doneFn: doneFn,
|
13938 | onTransmuxerLog: onTransmuxerLog
|
13939 | });
|
13940 | }
|
13941 |
|
13942 |
|
13943 | handleSegmentBytes({
|
13944 | segment: segment,
|
13945 | bytes: segment.bytes,
|
13946 | trackInfoFn: trackInfoFn,
|
13947 | timingInfoFn: timingInfoFn,
|
13948 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13949 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13950 | id3Fn: id3Fn,
|
13951 | captionsFn: captionsFn,
|
13952 | isEndOfTimeline: isEndOfTimeline,
|
13953 | endedTimelineFn: endedTimelineFn,
|
13954 | dataFn: dataFn,
|
13955 | doneFn: doneFn,
|
13956 | onTransmuxerLog: onTransmuxerLog
|
13957 | });
|
13958 | };
|
13959 |
|
13960 |
|
13961 | segment.endOfAllRequests = Date.now();
|
13962 |
|
13963 | if (segment.map && segment.map.encryptedBytes && !segment.map.bytes) {
|
13964 | return decrypt({
|
13965 | decryptionWorker: decryptionWorker,
|
13966 |
|
13967 |
|
13968 |
|
13969 | id: segment.requestId + '-init',
|
13970 | encryptedBytes: segment.map.encryptedBytes,
|
13971 | key: segment.map.key
|
13972 | }, function (decryptedBytes) {
|
13973 | segment.map.bytes = decryptedBytes;
|
13974 | parseInitSegment(segment, function (parseError) {
|
13975 | if (parseError) {
|
13976 | abortAll(activeXhrs);
|
13977 | return doneFn(parseError, segment);
|
13978 | }
|
13979 |
|
13980 | segmentFinish();
|
13981 | });
|
13982 | });
|
13983 | }
|
13984 |
|
13985 | segmentFinish();
|
13986 | }
|
13987 | };
|
13988 | };
|
13989 |
|
13990 |
|
13991 |
|
13992 |
|
13993 |
|
13994 |
|
13995 |
|
13996 |
|
13997 |
|
13998 | var handleLoadEnd = function handleLoadEnd(_ref10) {
|
13999 | var loadendState = _ref10.loadendState,
|
14000 | abortFn = _ref10.abortFn;
|
14001 | return function (event) {
|
14002 | var request = event.target;
|
14003 |
|
14004 | if (request.aborted && abortFn && !loadendState.calledAbortFn) {
|
14005 | abortFn();
|
14006 | loadendState.calledAbortFn = true;
|
14007 | }
|
14008 | };
|
14009 | };
|
14010 |
|
14011 |
|
14012 |
|
14013 |
|
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 |
|
14024 |
|
14025 |
|
14026 |
|
14027 |
|
14028 |
|
14029 |
|
14030 |
|
14031 |
|
14032 |
|
14033 |
|
14034 |
|
14035 |
|
14036 |
|
14037 | var handleProgress = function handleProgress(_ref11) {
|
14038 | var segment = _ref11.segment,
|
14039 | progressFn = _ref11.progressFn;
|
14040 | _ref11.trackInfoFn;
|
14041 | _ref11.timingInfoFn;
|
14042 | _ref11.videoSegmentTimingInfoFn;
|
14043 | _ref11.audioSegmentTimingInfoFn;
|
14044 | _ref11.id3Fn;
|
14045 | _ref11.captionsFn;
|
14046 | _ref11.isEndOfTimeline;
|
14047 | _ref11.endedTimelineFn;
|
14048 | _ref11.dataFn;
|
14049 | return function (event) {
|
14050 | var request = event.target;
|
14051 |
|
14052 | if (request.aborted) {
|
14053 | return;
|
14054 | }
|
14055 |
|
14056 | segment.stats = videojs__default["default"].mergeOptions(segment.stats, getProgressStats(event));
|
14057 |
|
14058 | if (!segment.stats.firstBytesReceivedAt && segment.stats.bytesReceived) {
|
14059 | segment.stats.firstBytesReceivedAt = Date.now();
|
14060 | }
|
14061 |
|
14062 | return progressFn(event, segment);
|
14063 | };
|
14064 | };
|
14065 |
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 |
|
14071 |
|
14072 |
|
14073 |
|
14074 |
|
14075 |
|
14076 |
|
14077 |
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 |
|
14086 |
|
14087 |
|
14088 |
|
14089 |
|
14090 |
|
14091 |
|
14092 |
|
14093 |
|
14094 |
|
14095 |
|
14096 |
|
14097 |
|
14098 |
|
14099 |
|
14100 |
|
14101 |
|
14102 |
|
14103 |
|
14104 |
|
14105 |
|
14106 |
|
14107 |
|
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 |
|
14119 |
|
14120 |
|
14121 |
|
14122 |
|
14123 |
|
14124 |
|
14125 |
|
14126 |
|
14127 |
|
14128 |
|
14129 |
|
14130 |
|
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 | var mediaSegmentRequest = function mediaSegmentRequest(_ref12) {
|
14136 | var xhr = _ref12.xhr,
|
14137 | xhrOptions = _ref12.xhrOptions,
|
14138 | decryptionWorker = _ref12.decryptionWorker,
|
14139 | segment = _ref12.segment,
|
14140 | abortFn = _ref12.abortFn,
|
14141 | progressFn = _ref12.progressFn,
|
14142 | trackInfoFn = _ref12.trackInfoFn,
|
14143 | timingInfoFn = _ref12.timingInfoFn,
|
14144 | videoSegmentTimingInfoFn = _ref12.videoSegmentTimingInfoFn,
|
14145 | audioSegmentTimingInfoFn = _ref12.audioSegmentTimingInfoFn,
|
14146 | id3Fn = _ref12.id3Fn,
|
14147 | captionsFn = _ref12.captionsFn,
|
14148 | isEndOfTimeline = _ref12.isEndOfTimeline,
|
14149 | endedTimelineFn = _ref12.endedTimelineFn,
|
14150 | dataFn = _ref12.dataFn,
|
14151 | doneFn = _ref12.doneFn,
|
14152 | onTransmuxerLog = _ref12.onTransmuxerLog;
|
14153 | var activeXhrs = [];
|
14154 | var finishProcessingFn = waitForCompletion({
|
14155 | activeXhrs: activeXhrs,
|
14156 | decryptionWorker: decryptionWorker,
|
14157 | trackInfoFn: trackInfoFn,
|
14158 | timingInfoFn: timingInfoFn,
|
14159 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
14160 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
14161 | id3Fn: id3Fn,
|
14162 | captionsFn: captionsFn,
|
14163 | isEndOfTimeline: isEndOfTimeline,
|
14164 | endedTimelineFn: endedTimelineFn,
|
14165 | dataFn: dataFn,
|
14166 | doneFn: doneFn,
|
14167 | onTransmuxerLog: onTransmuxerLog
|
14168 | });
|
14169 |
|
14170 | if (segment.key && !segment.key.bytes) {
|
14171 | var objects = [segment.key];
|
14172 |
|
14173 | if (segment.map && !segment.map.bytes && segment.map.key && segment.map.key.resolvedUri === segment.key.resolvedUri) {
|
14174 | objects.push(segment.map.key);
|
14175 | }
|
14176 |
|
14177 | var keyRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14178 | uri: segment.key.resolvedUri,
|
14179 | responseType: 'arraybuffer'
|
14180 | });
|
14181 | var keyRequestCallback = handleKeyResponse(segment, objects, finishProcessingFn);
|
14182 | var keyXhr = xhr(keyRequestOptions, keyRequestCallback);
|
14183 | activeXhrs.push(keyXhr);
|
14184 | }
|
14185 |
|
14186 |
|
14187 | if (segment.map && !segment.map.bytes) {
|
14188 | var differentMapKey = segment.map.key && (!segment.key || segment.key.resolvedUri !== segment.map.key.resolvedUri);
|
14189 |
|
14190 | if (differentMapKey) {
|
14191 | var mapKeyRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14192 | uri: segment.map.key.resolvedUri,
|
14193 | responseType: 'arraybuffer'
|
14194 | });
|
14195 | var mapKeyRequestCallback = handleKeyResponse(segment, [segment.map.key], finishProcessingFn);
|
14196 | var mapKeyXhr = xhr(mapKeyRequestOptions, mapKeyRequestCallback);
|
14197 | activeXhrs.push(mapKeyXhr);
|
14198 | }
|
14199 |
|
14200 | var initSegmentOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14201 | uri: segment.map.resolvedUri,
|
14202 | responseType: 'arraybuffer',
|
14203 | headers: segmentXhrHeaders(segment.map)
|
14204 | });
|
14205 | var initSegmentRequestCallback = handleInitSegmentResponse({
|
14206 | segment: segment,
|
14207 | finishProcessingFn: finishProcessingFn
|
14208 | });
|
14209 | var initSegmentXhr = xhr(initSegmentOptions, initSegmentRequestCallback);
|
14210 | activeXhrs.push(initSegmentXhr);
|
14211 | }
|
14212 |
|
14213 | var segmentRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14214 | uri: segment.part && segment.part.resolvedUri || segment.resolvedUri,
|
14215 | responseType: 'arraybuffer',
|
14216 | headers: segmentXhrHeaders(segment)
|
14217 | });
|
14218 | var segmentRequestCallback = handleSegmentResponse({
|
14219 | segment: segment,
|
14220 | finishProcessingFn: finishProcessingFn,
|
14221 | responseType: segmentRequestOptions.responseType
|
14222 | });
|
14223 | var segmentXhr = xhr(segmentRequestOptions, segmentRequestCallback);
|
14224 | segmentXhr.addEventListener('progress', handleProgress({
|
14225 | segment: segment,
|
14226 | progressFn: progressFn,
|
14227 | trackInfoFn: trackInfoFn,
|
14228 | timingInfoFn: timingInfoFn,
|
14229 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
14230 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
14231 | id3Fn: id3Fn,
|
14232 | captionsFn: captionsFn,
|
14233 | isEndOfTimeline: isEndOfTimeline,
|
14234 | endedTimelineFn: endedTimelineFn,
|
14235 | dataFn: dataFn
|
14236 | }));
|
14237 | activeXhrs.push(segmentXhr);
|
14238 |
|
14239 |
|
14240 | var loadendState = {};
|
14241 | activeXhrs.forEach(function (activeXhr) {
|
14242 | activeXhr.addEventListener('loadend', handleLoadEnd({
|
14243 | loadendState: loadendState,
|
14244 | abortFn: abortFn
|
14245 | }));
|
14246 | });
|
14247 | return function () {
|
14248 | return abortAll(activeXhrs);
|
14249 | };
|
14250 | };
|
14251 |
|
14252 |
|
14253 |
|
14254 |
|
14255 |
|
14256 | var logFn$1 = logger('CodecUtils');
|
14257 |
|
14258 |
|
14259 |
|
14260 |
|
14261 |
|
14262 |
|
14263 |
|
14264 |
|
14265 | var getCodecs = function getCodecs(media) {
|
14266 |
|
14267 |
|
14268 | var mediaAttributes = media.attributes || {};
|
14269 |
|
14270 | if (mediaAttributes.CODECS) {
|
14271 | return codecs_js.parseCodecs(mediaAttributes.CODECS);
|
14272 | }
|
14273 | };
|
14274 |
|
14275 | var isMaat = function isMaat(master, media) {
|
14276 | var mediaAttributes = media.attributes || {};
|
14277 | return master && master.mediaGroups && master.mediaGroups.AUDIO && mediaAttributes.AUDIO && master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
14278 | };
|
14279 | var isMuxed = function isMuxed(master, media) {
|
14280 | if (!isMaat(master, media)) {
|
14281 | return true;
|
14282 | }
|
14283 |
|
14284 | var mediaAttributes = media.attributes || {};
|
14285 | var audioGroup = master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
14286 |
|
14287 | for (var groupId in audioGroup) {
|
14288 |
|
14289 |
|
14290 |
|
14291 |
|
14292 | if (!audioGroup[groupId].uri && !audioGroup[groupId].playlists) {
|
14293 | return true;
|
14294 | }
|
14295 | }
|
14296 |
|
14297 | return false;
|
14298 | };
|
14299 | var unwrapCodecList = function unwrapCodecList(codecList) {
|
14300 | var codecs = {};
|
14301 | codecList.forEach(function (_ref) {
|
14302 | var mediaType = _ref.mediaType,
|
14303 | type = _ref.type,
|
14304 | details = _ref.details;
|
14305 | codecs[mediaType] = codecs[mediaType] || [];
|
14306 | codecs[mediaType].push(codecs_js.translateLegacyCodec("" + type + details));
|
14307 | });
|
14308 | Object.keys(codecs).forEach(function (mediaType) {
|
14309 | if (codecs[mediaType].length > 1) {
|
14310 | 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.");
|
14311 | codecs[mediaType] = null;
|
14312 | return;
|
14313 | }
|
14314 |
|
14315 | codecs[mediaType] = codecs[mediaType][0];
|
14316 | });
|
14317 | return codecs;
|
14318 | };
|
14319 | var codecCount = function codecCount(codecObj) {
|
14320 | var count = 0;
|
14321 |
|
14322 | if (codecObj.audio) {
|
14323 | count++;
|
14324 | }
|
14325 |
|
14326 | if (codecObj.video) {
|
14327 | count++;
|
14328 | }
|
14329 |
|
14330 | return count;
|
14331 | };
|
14332 |
|
14333 |
|
14334 |
|
14335 |
|
14336 |
|
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 | var codecsForPlaylist = function codecsForPlaylist(master, media) {
|
14346 | var mediaAttributes = media.attributes || {};
|
14347 | var codecInfo = unwrapCodecList(getCodecs(media) || []);
|
14348 |
|
14349 |
|
14350 | if (isMaat(master, media) && !codecInfo.audio) {
|
14351 | if (!isMuxed(master, media)) {
|
14352 |
|
14353 |
|
14354 |
|
14355 | var defaultCodecs = unwrapCodecList(codecs_js.codecsFromDefault(master, mediaAttributes.AUDIO) || []);
|
14356 |
|
14357 | if (defaultCodecs.audio) {
|
14358 | codecInfo.audio = defaultCodecs.audio;
|
14359 | }
|
14360 | }
|
14361 | }
|
14362 |
|
14363 | return codecInfo;
|
14364 | };
|
14365 |
|
14366 | var logFn = logger('PlaylistSelector');
|
14367 |
|
14368 | var representationToString = function representationToString(representation) {
|
14369 | if (!representation || !representation.playlist) {
|
14370 | return;
|
14371 | }
|
14372 |
|
14373 | var playlist = representation.playlist;
|
14374 | return JSON.stringify({
|
14375 | id: playlist.id,
|
14376 | bandwidth: representation.bandwidth,
|
14377 | width: representation.width,
|
14378 | height: representation.height,
|
14379 | codecs: playlist.attributes && playlist.attributes.CODECS || ''
|
14380 | });
|
14381 | };
|
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 |
|
14392 |
|
14393 |
|
14394 |
|
14395 | var safeGetComputedStyle = function safeGetComputedStyle(el, property) {
|
14396 | if (!el) {
|
14397 | return '';
|
14398 | }
|
14399 |
|
14400 | var result = window__default["default"].getComputedStyle(el);
|
14401 |
|
14402 | if (!result) {
|
14403 | return '';
|
14404 | }
|
14405 |
|
14406 | return result[property];
|
14407 | };
|
14408 |
|
14409 |
|
14410 |
|
14411 |
|
14412 |
|
14413 |
|
14414 |
|
14415 |
|
14416 |
|
14417 | var stableSort = function stableSort(array, sortFn) {
|
14418 | var newArray = array.slice();
|
14419 | array.sort(function (left, right) {
|
14420 | var cmp = sortFn(left, right);
|
14421 |
|
14422 | if (cmp === 0) {
|
14423 | return newArray.indexOf(left) - newArray.indexOf(right);
|
14424 | }
|
14425 |
|
14426 | return cmp;
|
14427 | });
|
14428 | };
|
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 |
|
14434 |
|
14435 |
|
14436 |
|
14437 |
|
14438 |
|
14439 |
|
14440 |
|
14441 | var comparePlaylistBandwidth = function comparePlaylistBandwidth(left, right) {
|
14442 | var leftBandwidth;
|
14443 | var rightBandwidth;
|
14444 |
|
14445 | if (left.attributes.BANDWIDTH) {
|
14446 | leftBandwidth = left.attributes.BANDWIDTH;
|
14447 | }
|
14448 |
|
14449 | leftBandwidth = leftBandwidth || window__default["default"].Number.MAX_VALUE;
|
14450 |
|
14451 | if (right.attributes.BANDWIDTH) {
|
14452 | rightBandwidth = right.attributes.BANDWIDTH;
|
14453 | }
|
14454 |
|
14455 | rightBandwidth = rightBandwidth || window__default["default"].Number.MAX_VALUE;
|
14456 | return leftBandwidth - rightBandwidth;
|
14457 | };
|
14458 |
|
14459 |
|
14460 |
|
14461 |
|
14462 |
|
14463 |
|
14464 |
|
14465 |
|
14466 |
|
14467 |
|
14468 |
|
14469 | var comparePlaylistResolution = function comparePlaylistResolution(left, right) {
|
14470 | var leftWidth;
|
14471 | var rightWidth;
|
14472 |
|
14473 | if (left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
|
14474 | leftWidth = left.attributes.RESOLUTION.width;
|
14475 | }
|
14476 |
|
14477 | leftWidth = leftWidth || window__default["default"].Number.MAX_VALUE;
|
14478 |
|
14479 | if (right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
|
14480 | rightWidth = right.attributes.RESOLUTION.width;
|
14481 | }
|
14482 |
|
14483 | rightWidth = rightWidth || window__default["default"].Number.MAX_VALUE;
|
14484 |
|
14485 |
|
14486 | if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
|
14487 | return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
|
14488 | }
|
14489 |
|
14490 | return leftWidth - rightWidth;
|
14491 | };
|
14492 |
|
14493 |
|
14494 |
|
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 |
|
14504 |
|
14505 |
|
14506 |
|
14507 |
|
14508 |
|
14509 |
|
14510 |
|
14511 |
|
14512 | var simpleSelector = function simpleSelector(master, playerBandwidth, playerWidth, playerHeight, limitRenditionByPlayerDimensions, masterPlaylistController) {
|
14513 |
|
14514 | if (!master) {
|
14515 | return;
|
14516 | }
|
14517 |
|
14518 | var options = {
|
14519 | bandwidth: playerBandwidth,
|
14520 | width: playerWidth,
|
14521 | height: playerHeight,
|
14522 | limitRenditionByPlayerDimensions: limitRenditionByPlayerDimensions
|
14523 | };
|
14524 | var playlists = master.playlists;
|
14525 |
|
14526 | if (Playlist.isAudioOnly(master)) {
|
14527 | playlists = masterPlaylistController.getAudioTrackPlaylists_();
|
14528 |
|
14529 |
|
14530 | options.audioOnly = true;
|
14531 | }
|
14532 |
|
14533 |
|
14534 | var sortedPlaylistReps = playlists.map(function (playlist) {
|
14535 | var bandwidth;
|
14536 | var width = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width;
|
14537 | var height = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.height;
|
14538 | bandwidth = playlist.attributes && playlist.attributes.BANDWIDTH;
|
14539 | bandwidth = bandwidth || window__default["default"].Number.MAX_VALUE;
|
14540 | return {
|
14541 | bandwidth: bandwidth,
|
14542 | width: width,
|
14543 | height: height,
|
14544 | playlist: playlist
|
14545 | };
|
14546 | });
|
14547 | stableSort(sortedPlaylistReps, function (left, right) {
|
14548 | return left.bandwidth - right.bandwidth;
|
14549 | });
|
14550 |
|
14551 |
|
14552 | sortedPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
14553 | return !Playlist.isIncompatible(rep.playlist);
|
14554 | });
|
14555 |
|
14556 |
|
14557 | var enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
14558 | return Playlist.isEnabled(rep.playlist);
|
14559 | });
|
14560 |
|
14561 | if (!enabledPlaylistReps.length) {
|
14562 |
|
14563 |
|
14564 |
|
14565 | enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
14566 | return !Playlist.isDisabled(rep.playlist);
|
14567 | });
|
14568 | }
|
14569 |
|
14570 |
|
14571 |
|
14572 | var bandwidthPlaylistReps = enabledPlaylistReps.filter(function (rep) {
|
14573 | return rep.bandwidth * Config.BANDWIDTH_VARIANCE < playerBandwidth;
|
14574 | });
|
14575 | var highestRemainingBandwidthRep = bandwidthPlaylistReps[bandwidthPlaylistReps.length - 1];
|
14576 |
|
14577 |
|
14578 | var bandwidthBestRep = bandwidthPlaylistReps.filter(function (rep) {
|
14579 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
14580 | })[0];
|
14581 |
|
14582 | if (limitRenditionByPlayerDimensions === false) {
|
14583 | var _chosenRep = bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
14584 |
|
14585 | if (_chosenRep && _chosenRep.playlist) {
|
14586 | var type = 'sortedPlaylistReps';
|
14587 |
|
14588 | if (bandwidthBestRep) {
|
14589 | type = 'bandwidthBestRep';
|
14590 | }
|
14591 |
|
14592 | if (enabledPlaylistReps[0]) {
|
14593 | type = 'enabledPlaylistReps';
|
14594 | }
|
14595 |
|
14596 | logFn("choosing " + representationToString(_chosenRep) + " using " + type + " with options", options);
|
14597 | return _chosenRep.playlist;
|
14598 | }
|
14599 |
|
14600 | logFn('could not choose a playlist with options', options);
|
14601 | return null;
|
14602 | }
|
14603 |
|
14604 |
|
14605 | var haveResolution = bandwidthPlaylistReps.filter(function (rep) {
|
14606 | return rep.width && rep.height;
|
14607 | });
|
14608 |
|
14609 | stableSort(haveResolution, function (left, right) {
|
14610 | return left.width - right.width;
|
14611 | });
|
14612 |
|
14613 | var resolutionBestRepList = haveResolution.filter(function (rep) {
|
14614 | return rep.width === playerWidth && rep.height === playerHeight;
|
14615 | });
|
14616 | highestRemainingBandwidthRep = resolutionBestRepList[resolutionBestRepList.length - 1];
|
14617 |
|
14618 | var resolutionBestRep = resolutionBestRepList.filter(function (rep) {
|
14619 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
14620 | })[0];
|
14621 | var resolutionPlusOneList;
|
14622 | var resolutionPlusOneSmallest;
|
14623 | var resolutionPlusOneRep;
|
14624 |
|
14625 |
|
14626 | if (!resolutionBestRep) {
|
14627 | resolutionPlusOneList = haveResolution.filter(function (rep) {
|
14628 | return rep.width > playerWidth || rep.height > playerHeight;
|
14629 | });
|
14630 |
|
14631 | resolutionPlusOneSmallest = resolutionPlusOneList.filter(function (rep) {
|
14632 | return rep.width === resolutionPlusOneList[0].width && rep.height === resolutionPlusOneList[0].height;
|
14633 | });
|
14634 |
|
14635 |
|
14636 | highestRemainingBandwidthRep = resolutionPlusOneSmallest[resolutionPlusOneSmallest.length - 1];
|
14637 | resolutionPlusOneRep = resolutionPlusOneSmallest.filter(function (rep) {
|
14638 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
14639 | })[0];
|
14640 | }
|
14641 |
|
14642 | var leastPixelDiffRep;
|
14643 |
|
14644 |
|
14645 |
|
14646 | if (masterPlaylistController.experimentalLeastPixelDiffSelector) {
|
14647 |
|
14648 | var leastPixelDiffList = haveResolution.map(function (rep) {
|
14649 | rep.pixelDiff = Math.abs(rep.width - playerWidth) + Math.abs(rep.height - playerHeight);
|
14650 | return rep;
|
14651 | });
|
14652 |
|
14653 | stableSort(leastPixelDiffList, function (left, right) {
|
14654 |
|
14655 | if (left.pixelDiff === right.pixelDiff) {
|
14656 | return right.bandwidth - left.bandwidth;
|
14657 | }
|
14658 |
|
14659 | return left.pixelDiff - right.pixelDiff;
|
14660 | });
|
14661 | leastPixelDiffRep = leastPixelDiffList[0];
|
14662 | }
|
14663 |
|
14664 |
|
14665 | var chosenRep = leastPixelDiffRep || resolutionPlusOneRep || resolutionBestRep || bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
14666 |
|
14667 | if (chosenRep && chosenRep.playlist) {
|
14668 | var _type = 'sortedPlaylistReps';
|
14669 |
|
14670 | if (leastPixelDiffRep) {
|
14671 | _type = 'leastPixelDiffRep';
|
14672 | } else if (resolutionPlusOneRep) {
|
14673 | _type = 'resolutionPlusOneRep';
|
14674 | } else if (resolutionBestRep) {
|
14675 | _type = 'resolutionBestRep';
|
14676 | } else if (bandwidthBestRep) {
|
14677 | _type = 'bandwidthBestRep';
|
14678 | } else if (enabledPlaylistReps[0]) {
|
14679 | _type = 'enabledPlaylistReps';
|
14680 | }
|
14681 |
|
14682 | logFn("choosing " + representationToString(chosenRep) + " using " + _type + " with options", options);
|
14683 | return chosenRep.playlist;
|
14684 | }
|
14685 |
|
14686 | logFn('could not choose a playlist with options', options);
|
14687 | return null;
|
14688 | };
|
14689 |
|
14690 |
|
14691 |
|
14692 |
|
14693 |
|
14694 |
|
14695 |
|
14696 |
|
14697 |
|
14698 |
|
14699 |
|
14700 |
|
14701 | var lastBandwidthSelector = function lastBandwidthSelector() {
|
14702 | var pixelRatio = this.useDevicePixelRatio ? window__default["default"].devicePixelRatio || 1 : 1;
|
14703 | 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_);
|
14704 | };
|
14705 |
|
14706 |
|
14707 |
|
14708 |
|
14709 |
|
14710 |
|
14711 |
|
14712 |
|
14713 |
|
14714 |
|
14715 |
|
14716 |
|
14717 |
|
14718 |
|
14719 |
|
14720 | var movingAverageBandwidthSelector = function movingAverageBandwidthSelector(decay) {
|
14721 | var average = -1;
|
14722 | var lastSystemBandwidth = -1;
|
14723 |
|
14724 | if (decay < 0 || decay > 1) {
|
14725 | throw new Error('Moving average bandwidth decay must be between 0 and 1.');
|
14726 | }
|
14727 |
|
14728 | return function () {
|
14729 | var pixelRatio = this.useDevicePixelRatio ? window__default["default"].devicePixelRatio || 1 : 1;
|
14730 |
|
14731 | if (average < 0) {
|
14732 | average = this.systemBandwidth;
|
14733 | lastSystemBandwidth = this.systemBandwidth;
|
14734 | }
|
14735 |
|
14736 |
|
14737 |
|
14738 |
|
14739 |
|
14740 |
|
14741 | if (this.systemBandwidth > 0 && this.systemBandwidth !== lastSystemBandwidth) {
|
14742 | average = decay * this.systemBandwidth + (1 - decay) * average;
|
14743 | lastSystemBandwidth = this.systemBandwidth;
|
14744 | }
|
14745 |
|
14746 | 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_);
|
14747 | };
|
14748 | };
|
14749 |
|
14750 |
|
14751 |
|
14752 |
|
14753 |
|
14754 |
|
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 |
|
14760 |
|
14761 |
|
14762 |
|
14763 |
|
14764 |
|
14765 |
|
14766 |
|
14767 |
|
14768 |
|
14769 |
|
14770 |
|
14771 |
|
14772 |
|
14773 |
|
14774 |
|
14775 |
|
14776 |
|
14777 |
|
14778 | var minRebufferMaxBandwidthSelector = function minRebufferMaxBandwidthSelector(settings) {
|
14779 | var master = settings.master,
|
14780 | currentTime = settings.currentTime,
|
14781 | bandwidth = settings.bandwidth,
|
14782 | duration = settings.duration,
|
14783 | segmentDuration = settings.segmentDuration,
|
14784 | timeUntilRebuffer = settings.timeUntilRebuffer,
|
14785 | currentTimeline = settings.currentTimeline,
|
14786 | syncController = settings.syncController;
|
14787 |
|
14788 |
|
14789 | var compatiblePlaylists = master.playlists.filter(function (playlist) {
|
14790 | return !Playlist.isIncompatible(playlist);
|
14791 | });
|
14792 |
|
14793 |
|
14794 | var enabledPlaylists = compatiblePlaylists.filter(Playlist.isEnabled);
|
14795 |
|
14796 | if (!enabledPlaylists.length) {
|
14797 |
|
14798 |
|
14799 |
|
14800 | enabledPlaylists = compatiblePlaylists.filter(function (playlist) {
|
14801 | return !Playlist.isDisabled(playlist);
|
14802 | });
|
14803 | }
|
14804 |
|
14805 | var bandwidthPlaylists = enabledPlaylists.filter(Playlist.hasAttribute.bind(null, 'BANDWIDTH'));
|
14806 | var rebufferingEstimates = bandwidthPlaylists.map(function (playlist) {
|
14807 | var syncPoint = syncController.getSyncPoint(playlist, duration, currentTimeline, currentTime);
|
14808 |
|
14809 |
|
14810 | var numRequests = syncPoint ? 1 : 2;
|
14811 | var requestTimeEstimate = Playlist.estimateSegmentRequestTime(segmentDuration, bandwidth, playlist);
|
14812 | var rebufferingImpact = requestTimeEstimate * numRequests - timeUntilRebuffer;
|
14813 | return {
|
14814 | playlist: playlist,
|
14815 | rebufferingImpact: rebufferingImpact
|
14816 | };
|
14817 | });
|
14818 | var noRebufferingPlaylists = rebufferingEstimates.filter(function (estimate) {
|
14819 | return estimate.rebufferingImpact <= 0;
|
14820 | });
|
14821 |
|
14822 | stableSort(noRebufferingPlaylists, function (a, b) {
|
14823 | return comparePlaylistBandwidth(b.playlist, a.playlist);
|
14824 | });
|
14825 |
|
14826 | if (noRebufferingPlaylists.length) {
|
14827 | return noRebufferingPlaylists[0];
|
14828 | }
|
14829 |
|
14830 | stableSort(rebufferingEstimates, function (a, b) {
|
14831 | return a.rebufferingImpact - b.rebufferingImpact;
|
14832 | });
|
14833 | return rebufferingEstimates[0] || null;
|
14834 | };
|
14835 |
|
14836 |
|
14837 |
|
14838 |
|
14839 |
|
14840 |
|
14841 |
|
14842 |
|
14843 |
|
14844 |
|
14845 |
|
14846 |
|
14847 | var lowestBitrateCompatibleVariantSelector = function lowestBitrateCompatibleVariantSelector() {
|
14848 | var _this = this;
|
14849 |
|
14850 |
|
14851 |
|
14852 | var playlists = this.playlists.master.playlists.filter(Playlist.isEnabled);
|
14853 |
|
14854 | stableSort(playlists, function (a, b) {
|
14855 | return comparePlaylistBandwidth(a, b);
|
14856 | });
|
14857 |
|
14858 |
|
14859 |
|
14860 |
|
14861 |
|
14862 | var playlistsWithVideo = playlists.filter(function (playlist) {
|
14863 | return !!codecsForPlaylist(_this.playlists.master, playlist).video;
|
14864 | });
|
14865 | return playlistsWithVideo[0] || null;
|
14866 | };
|
14867 |
|
14868 |
|
14869 |
|
14870 |
|
14871 |
|
14872 |
|
14873 |
|
14874 |
|
14875 | var concatSegments = function concatSegments(segmentObj) {
|
14876 | var offset = 0;
|
14877 | var tempBuffer;
|
14878 |
|
14879 | if (segmentObj.bytes) {
|
14880 | tempBuffer = new Uint8Array(segmentObj.bytes);
|
14881 |
|
14882 | segmentObj.segments.forEach(function (segment) {
|
14883 | tempBuffer.set(segment, offset);
|
14884 | offset += segment.byteLength;
|
14885 | });
|
14886 | }
|
14887 |
|
14888 | return tempBuffer;
|
14889 | };
|
14890 |
|
14891 |
|
14892 |
|
14893 |
|
14894 |
|
14895 |
|
14896 |
|
14897 |
|
14898 |
|
14899 |
|
14900 |
|
14901 |
|
14902 |
|
14903 | var createCaptionsTrackIfNotExists = function createCaptionsTrackIfNotExists(inbandTextTracks, tech, captionStream) {
|
14904 | if (!inbandTextTracks[captionStream]) {
|
14905 | tech.trigger({
|
14906 | type: 'usage',
|
14907 | name: 'vhs-608'
|
14908 | });
|
14909 | tech.trigger({
|
14910 | type: 'usage',
|
14911 | name: 'hls-608'
|
14912 | });
|
14913 | var instreamId = captionStream;
|
14914 |
|
14915 | if (/^cc708_/.test(captionStream)) {
|
14916 | instreamId = 'SERVICE' + captionStream.split('_')[1];
|
14917 | }
|
14918 |
|
14919 | var track = tech.textTracks().getTrackById(instreamId);
|
14920 |
|
14921 | if (track) {
|
14922 |
|
14923 |
|
14924 |
|
14925 | inbandTextTracks[captionStream] = track;
|
14926 | } else {
|
14927 |
|
14928 |
|
14929 | var captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
|
14930 | var label = captionStream;
|
14931 | var language = captionStream;
|
14932 | var def = false;
|
14933 | var captionService = captionServices[instreamId];
|
14934 |
|
14935 | if (captionService) {
|
14936 | label = captionService.label;
|
14937 | language = captionService.language;
|
14938 | def = captionService.default;
|
14939 | }
|
14940 |
|
14941 |
|
14942 |
|
14943 | inbandTextTracks[captionStream] = tech.addRemoteTextTrack({
|
14944 | kind: 'captions',
|
14945 | id: instreamId,
|
14946 |
|
14947 | default: def,
|
14948 | label: label,
|
14949 | language: language
|
14950 | }, false).track;
|
14951 | }
|
14952 | }
|
14953 | };
|
14954 |
|
14955 |
|
14956 |
|
14957 |
|
14958 |
|
14959 |
|
14960 |
|
14961 |
|
14962 |
|
14963 |
|
14964 | var addCaptionData = function addCaptionData(_ref) {
|
14965 | var inbandTextTracks = _ref.inbandTextTracks,
|
14966 | captionArray = _ref.captionArray,
|
14967 | timestampOffset = _ref.timestampOffset;
|
14968 |
|
14969 | if (!captionArray) {
|
14970 | return;
|
14971 | }
|
14972 |
|
14973 | var Cue = window__default["default"].WebKitDataCue || window__default["default"].VTTCue;
|
14974 | captionArray.forEach(function (caption) {
|
14975 | var track = caption.stream;
|
14976 | inbandTextTracks[track].addCue(new Cue(caption.startTime + timestampOffset, caption.endTime + timestampOffset, caption.text));
|
14977 | });
|
14978 | };
|
14979 |
|
14980 |
|
14981 |
|
14982 |
|
14983 |
|
14984 |
|
14985 |
|
14986 |
|
14987 |
|
14988 | var deprecateOldCue = function deprecateOldCue(cue) {
|
14989 | Object.defineProperties(cue.frame, {
|
14990 | id: {
|
14991 | get: function get() {
|
14992 | videojs__default["default"].log.warn('cue.frame.id is deprecated. Use cue.value.key instead.');
|
14993 | return cue.value.key;
|
14994 | }
|
14995 | },
|
14996 | value: {
|
14997 | get: function get() {
|
14998 | videojs__default["default"].log.warn('cue.frame.value is deprecated. Use cue.value.data instead.');
|
14999 | return cue.value.data;
|
15000 | }
|
15001 | },
|
15002 | privateData: {
|
15003 | get: function get() {
|
15004 | videojs__default["default"].log.warn('cue.frame.privateData is deprecated. Use cue.value.data instead.');
|
15005 | return cue.value.data;
|
15006 | }
|
15007 | }
|
15008 | });
|
15009 | };
|
15010 |
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 |
|
15021 |
|
15022 | var addMetadata = function addMetadata(_ref2) {
|
15023 | var inbandTextTracks = _ref2.inbandTextTracks,
|
15024 | metadataArray = _ref2.metadataArray,
|
15025 | timestampOffset = _ref2.timestampOffset,
|
15026 | videoDuration = _ref2.videoDuration;
|
15027 |
|
15028 | if (!metadataArray) {
|
15029 | return;
|
15030 | }
|
15031 |
|
15032 | var Cue = window__default["default"].WebKitDataCue || window__default["default"].VTTCue;
|
15033 | var metadataTrack = inbandTextTracks.metadataTrack_;
|
15034 |
|
15035 | if (!metadataTrack) {
|
15036 | return;
|
15037 | }
|
15038 |
|
15039 | metadataArray.forEach(function (metadata) {
|
15040 | var time = metadata.cueTime + timestampOffset;
|
15041 |
|
15042 |
|
15043 |
|
15044 |
|
15045 | if (typeof time !== 'number' || window__default["default"].isNaN(time) || time < 0 || !(time < Infinity)) {
|
15046 | return;
|
15047 | }
|
15048 |
|
15049 | metadata.frames.forEach(function (frame) {
|
15050 | var cue = new Cue(time, time, frame.value || frame.url || frame.data || '');
|
15051 | cue.frame = frame;
|
15052 | cue.value = frame;
|
15053 | deprecateOldCue(cue);
|
15054 | metadataTrack.addCue(cue);
|
15055 | });
|
15056 | });
|
15057 |
|
15058 | if (!metadataTrack.cues || !metadataTrack.cues.length) {
|
15059 | return;
|
15060 | }
|
15061 |
|
15062 |
|
15063 |
|
15064 |
|
15065 | var cues = metadataTrack.cues;
|
15066 | var cuesArray = [];
|
15067 |
|
15068 |
|
15069 | for (var i = 0; i < cues.length; i++) {
|
15070 | if (cues[i]) {
|
15071 | cuesArray.push(cues[i]);
|
15072 | }
|
15073 | }
|
15074 |
|
15075 |
|
15076 | var cuesGroupedByStartTime = cuesArray.reduce(function (obj, cue) {
|
15077 | var timeSlot = obj[cue.startTime] || [];
|
15078 | timeSlot.push(cue);
|
15079 | obj[cue.startTime] = timeSlot;
|
15080 | return obj;
|
15081 | }, {});
|
15082 |
|
15083 | var sortedStartTimes = Object.keys(cuesGroupedByStartTime).sort(function (a, b) {
|
15084 | return Number(a) - Number(b);
|
15085 | });
|
15086 |
|
15087 | sortedStartTimes.forEach(function (startTime, idx) {
|
15088 | var cueGroup = cuesGroupedByStartTime[startTime];
|
15089 | var nextTime = Number(sortedStartTimes[idx + 1]) || videoDuration;
|
15090 |
|
15091 | cueGroup.forEach(function (cue) {
|
15092 | cue.endTime = nextTime;
|
15093 | });
|
15094 | });
|
15095 | };
|
15096 |
|
15097 |
|
15098 |
|
15099 |
|
15100 |
|
15101 |
|
15102 |
|
15103 |
|
15104 |
|
15105 | var createMetadataTrackIfNotExists = function createMetadataTrackIfNotExists(inbandTextTracks, dispatchType, tech) {
|
15106 | if (inbandTextTracks.metadataTrack_) {
|
15107 | return;
|
15108 | }
|
15109 |
|
15110 | inbandTextTracks.metadataTrack_ = tech.addRemoteTextTrack({
|
15111 | kind: 'metadata',
|
15112 | label: 'Timed Metadata'
|
15113 | }, false).track;
|
15114 | inbandTextTracks.metadataTrack_.inBandMetadataTrackDispatchType = dispatchType;
|
15115 | };
|
15116 |
|
15117 |
|
15118 |
|
15119 |
|
15120 |
|
15121 |
|
15122 |
|
15123 |
|
15124 |
|
15125 | var removeCuesFromTrack = function removeCuesFromTrack(start, end, track) {
|
15126 | var i;
|
15127 | var cue;
|
15128 |
|
15129 | if (!track) {
|
15130 | return;
|
15131 | }
|
15132 |
|
15133 | if (!track.cues) {
|
15134 | return;
|
15135 | }
|
15136 |
|
15137 | i = track.cues.length;
|
15138 |
|
15139 | while (i--) {
|
15140 | cue = track.cues[i];
|
15141 |
|
15142 | if (cue.startTime >= start && cue.endTime <= end) {
|
15143 | track.removeCue(cue);
|
15144 | }
|
15145 | }
|
15146 | };
|
15147 |
|
15148 |
|
15149 |
|
15150 |
|
15151 |
|
15152 |
|
15153 |
|
15154 |
|
15155 | var removeDuplicateCuesFromTrack = function removeDuplicateCuesFromTrack(track) {
|
15156 | var cues = track.cues;
|
15157 |
|
15158 | if (!cues) {
|
15159 | return;
|
15160 | }
|
15161 |
|
15162 | for (var i = 0; i < cues.length; i++) {
|
15163 | var duplicates = [];
|
15164 | var occurrences = 0;
|
15165 |
|
15166 | for (var j = 0; j < cues.length; j++) {
|
15167 | if (cues[i].startTime === cues[j].startTime && cues[i].endTime === cues[j].endTime && cues[i].text === cues[j].text) {
|
15168 | occurrences++;
|
15169 |
|
15170 | if (occurrences > 1) {
|
15171 | duplicates.push(cues[j]);
|
15172 | }
|
15173 | }
|
15174 | }
|
15175 |
|
15176 | if (duplicates.length) {
|
15177 | duplicates.forEach(function (dupe) {
|
15178 | return track.removeCue(dupe);
|
15179 | });
|
15180 | }
|
15181 | }
|
15182 | };
|
15183 |
|
15184 |
|
15185 |
|
15186 |
|
15187 |
|
15188 |
|
15189 |
|
15190 |
|
15191 |
|
15192 |
|
15193 |
|
15194 |
|
15195 |
|
15196 |
|
15197 |
|
15198 | var gopsSafeToAlignWith = function gopsSafeToAlignWith(buffer, currentTime, mapping) {
|
15199 | if (typeof currentTime === 'undefined' || currentTime === null || !buffer.length) {
|
15200 | return [];
|
15201 | }
|
15202 |
|
15203 |
|
15204 | var currentTimePts = Math.ceil((currentTime - mapping + 3) * clock.ONE_SECOND_IN_TS);
|
15205 | var i;
|
15206 |
|
15207 | for (i = 0; i < buffer.length; i++) {
|
15208 | if (buffer[i].pts > currentTimePts) {
|
15209 | break;
|
15210 | }
|
15211 | }
|
15212 |
|
15213 | return buffer.slice(i);
|
15214 | };
|
15215 |
|
15216 |
|
15217 |
|
15218 |
|
15219 |
|
15220 |
|
15221 |
|
15222 |
|
15223 |
|
15224 |
|
15225 |
|
15226 |
|
15227 |
|
15228 |
|
15229 |
|
15230 | var updateGopBuffer = function updateGopBuffer(buffer, gops, replace) {
|
15231 | if (!gops.length) {
|
15232 | return buffer;
|
15233 | }
|
15234 |
|
15235 | if (replace) {
|
15236 |
|
15237 |
|
15238 |
|
15239 |
|
15240 | return gops.slice();
|
15241 | }
|
15242 |
|
15243 | var start = gops[0].pts;
|
15244 | var i = 0;
|
15245 |
|
15246 | for (i; i < buffer.length; i++) {
|
15247 | if (buffer[i].pts >= start) {
|
15248 | break;
|
15249 | }
|
15250 | }
|
15251 |
|
15252 | return buffer.slice(0, i).concat(gops);
|
15253 | };
|
15254 |
|
15255 |
|
15256 |
|
15257 |
|
15258 |
|
15259 |
|
15260 |
|
15261 |
|
15262 |
|
15263 |
|
15264 |
|
15265 |
|
15266 |
|
15267 | var removeGopBuffer = function removeGopBuffer(buffer, start, end, mapping) {
|
15268 | var startPts = Math.ceil((start - mapping) * clock.ONE_SECOND_IN_TS);
|
15269 | var endPts = Math.ceil((end - mapping) * clock.ONE_SECOND_IN_TS);
|
15270 | var updatedBuffer = buffer.slice();
|
15271 | var i = buffer.length;
|
15272 |
|
15273 | while (i--) {
|
15274 | if (buffer[i].pts <= endPts) {
|
15275 | break;
|
15276 | }
|
15277 | }
|
15278 |
|
15279 | if (i === -1) {
|
15280 |
|
15281 | return updatedBuffer;
|
15282 | }
|
15283 |
|
15284 | var j = i + 1;
|
15285 |
|
15286 | while (j--) {
|
15287 | if (buffer[j].pts <= startPts) {
|
15288 | break;
|
15289 | }
|
15290 | }
|
15291 |
|
15292 |
|
15293 | j = Math.max(j, 0);
|
15294 | updatedBuffer.splice(j, i - j + 1);
|
15295 | return updatedBuffer;
|
15296 | };
|
15297 |
|
15298 | var shallowEqual = function shallowEqual(a, b) {
|
15299 |
|
15300 |
|
15301 |
|
15302 | if (!a && !b || !a && b || a && !b) {
|
15303 | return false;
|
15304 | }
|
15305 |
|
15306 |
|
15307 | if (a === b) {
|
15308 | return true;
|
15309 | }
|
15310 |
|
15311 |
|
15312 |
|
15313 | var akeys = Object.keys(a).sort();
|
15314 | var bkeys = Object.keys(b).sort();
|
15315 |
|
15316 | if (akeys.length !== bkeys.length) {
|
15317 | return false;
|
15318 | }
|
15319 |
|
15320 | for (var i = 0; i < akeys.length; i++) {
|
15321 | var key = akeys[i];
|
15322 |
|
15323 | if (key !== bkeys[i]) {
|
15324 | return false;
|
15325 | }
|
15326 |
|
15327 |
|
15328 | if (a[key] !== b[key]) {
|
15329 | return false;
|
15330 | }
|
15331 | }
|
15332 |
|
15333 | return true;
|
15334 | };
|
15335 |
|
15336 |
|
15337 | var QUOTA_EXCEEDED_ERR = 22;
|
15338 |
|
15339 |
|
15340 |
|
15341 |
|
15342 |
|
15343 |
|
15344 |
|
15345 |
|
15346 |
|
15347 |
|
15348 |
|
15349 | var getSyncSegmentCandidate = function getSyncSegmentCandidate(currentTimeline, segments, targetTime) {
|
15350 | segments = segments || [];
|
15351 | var timelineSegments = [];
|
15352 | var time = 0;
|
15353 |
|
15354 | for (var i = 0; i < segments.length; i++) {
|
15355 | var segment = segments[i];
|
15356 |
|
15357 | if (currentTimeline === segment.timeline) {
|
15358 | timelineSegments.push(i);
|
15359 | time += segment.duration;
|
15360 |
|
15361 | if (time > targetTime) {
|
15362 | return i;
|
15363 | }
|
15364 | }
|
15365 | }
|
15366 |
|
15367 | if (timelineSegments.length === 0) {
|
15368 | return 0;
|
15369 | }
|
15370 |
|
15371 |
|
15372 | return timelineSegments[timelineSegments.length - 1];
|
15373 | };
|
15374 |
|
15375 |
|
15376 |
|
15377 |
|
15378 | var MIN_BACK_BUFFER = 1;
|
15379 |
|
15380 | var CHECK_BUFFER_DELAY = 500;
|
15381 |
|
15382 | var finite = function finite(num) {
|
15383 | return typeof num === 'number' && isFinite(num);
|
15384 | };
|
15385 |
|
15386 |
|
15387 |
|
15388 |
|
15389 | var MIN_SEGMENT_DURATION_TO_SAVE_STATS = 1 / 60;
|
15390 | var illegalMediaSwitch = function illegalMediaSwitch(loaderType, startingMedia, trackInfo) {
|
15391 |
|
15392 |
|
15393 | if (loaderType !== 'main' || !startingMedia || !trackInfo) {
|
15394 | return null;
|
15395 | }
|
15396 |
|
15397 | if (!trackInfo.hasAudio && !trackInfo.hasVideo) {
|
15398 | return 'Neither audio nor video found in segment.';
|
15399 | }
|
15400 |
|
15401 | if (startingMedia.hasVideo && !trackInfo.hasVideo) {
|
15402 | 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.';
|
15403 | }
|
15404 |
|
15405 | if (!startingMedia.hasVideo && trackInfo.hasVideo) {
|
15406 | 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.';
|
15407 | }
|
15408 |
|
15409 | return null;
|
15410 | };
|
15411 |
|
15412 |
|
15413 |
|
15414 |
|
15415 |
|
15416 |
|
15417 |
|
15418 |
|
15419 |
|
15420 |
|
15421 |
|
15422 |
|
15423 |
|
15424 |
|
15425 | var safeBackBufferTrimTime = function safeBackBufferTrimTime(seekable, currentTime, targetDuration) {
|
15426 |
|
15427 |
|
15428 |
|
15429 |
|
15430 |
|
15431 | var trimTime = currentTime - Config.BACK_BUFFER_LENGTH;
|
15432 |
|
15433 | if (seekable.length) {
|
15434 |
|
15435 |
|
15436 | trimTime = Math.max(trimTime, seekable.start(0));
|
15437 | }
|
15438 |
|
15439 |
|
15440 |
|
15441 | var maxTrimTime = currentTime - targetDuration;
|
15442 | return Math.min(maxTrimTime, trimTime);
|
15443 | };
|
15444 | var segmentInfoString = function segmentInfoString(segmentInfo) {
|
15445 | var startOfSegment = segmentInfo.startOfSegment,
|
15446 | duration = segmentInfo.duration,
|
15447 | segment = segmentInfo.segment,
|
15448 | part = segmentInfo.part,
|
15449 | _segmentInfo$playlist = segmentInfo.playlist,
|
15450 | seq = _segmentInfo$playlist.mediaSequence,
|
15451 | id = _segmentInfo$playlist.id,
|
15452 | _segmentInfo$playlist2 = _segmentInfo$playlist.segments,
|
15453 | segments = _segmentInfo$playlist2 === void 0 ? [] : _segmentInfo$playlist2,
|
15454 | index = segmentInfo.mediaIndex,
|
15455 | partIndex = segmentInfo.partIndex,
|
15456 | timeline = segmentInfo.timeline;
|
15457 | var segmentLen = segments.length - 1;
|
15458 | var selection = 'mediaIndex/partIndex increment';
|
15459 |
|
15460 | if (segmentInfo.getMediaInfoForTime) {
|
15461 | selection = "getMediaInfoForTime (" + segmentInfo.getMediaInfoForTime + ")";
|
15462 | } else if (segmentInfo.isSyncRequest) {
|
15463 | selection = 'getSyncSegmentCandidate (isSyncRequest)';
|
15464 | }
|
15465 |
|
15466 | if (segmentInfo.independent) {
|
15467 | selection += " with independent " + segmentInfo.independent;
|
15468 | }
|
15469 |
|
15470 | var hasPartIndex = typeof partIndex === 'number';
|
15471 | var name = segmentInfo.segment.uri ? 'segment' : 'pre-segment';
|
15472 | var zeroBasedPartCount = hasPartIndex ? getKnownPartCount({
|
15473 | preloadSegment: segment
|
15474 | }) - 1 : 0;
|
15475 | 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 + "]");
|
15476 | };
|
15477 |
|
15478 | var timingInfoPropertyForMedia = function timingInfoPropertyForMedia(mediaType) {
|
15479 | return mediaType + "TimingInfo";
|
15480 | };
|
15481 |
|
15482 |
|
15483 |
|
15484 |
|
15485 |
|
15486 |
|
15487 |
|
15488 |
|
15489 |
|
15490 |
|
15491 |
|
15492 |
|
15493 |
|
15494 |
|
15495 |
|
15496 |
|
15497 |
|
15498 |
|
15499 |
|
15500 |
|
15501 |
|
15502 | var timestampOffsetForSegment = function timestampOffsetForSegment(_ref) {
|
15503 | var segmentTimeline = _ref.segmentTimeline,
|
15504 | currentTimeline = _ref.currentTimeline,
|
15505 | startOfSegment = _ref.startOfSegment,
|
15506 | buffered = _ref.buffered,
|
15507 | overrideCheck = _ref.overrideCheck;
|
15508 |
|
15509 |
|
15510 |
|
15511 |
|
15512 |
|
15513 |
|
15514 |
|
15515 | if (!overrideCheck && segmentTimeline === currentTimeline) {
|
15516 | return null;
|
15517 | }
|
15518 |
|
15519 |
|
15520 |
|
15521 |
|
15522 |
|
15523 |
|
15524 |
|
15525 |
|
15526 |
|
15527 |
|
15528 |
|
15529 |
|
15530 |
|
15531 |
|
15532 |
|
15533 |
|
15534 |
|
15535 |
|
15536 |
|
15537 |
|
15538 |
|
15539 |
|
15540 |
|
15541 |
|
15542 |
|
15543 | if (segmentTimeline < currentTimeline) {
|
15544 | return startOfSegment;
|
15545 | }
|
15546 |
|
15547 |
|
15548 |
|
15549 |
|
15550 |
|
15551 |
|
15552 | return buffered.length ? buffered.end(buffered.length - 1) : startOfSegment;
|
15553 | };
|
15554 |
|
15555 |
|
15556 |
|
15557 |
|
15558 |
|
15559 |
|
15560 |
|
15561 |
|
15562 |
|
15563 |
|
15564 |
|
15565 |
|
15566 |
|
15567 |
|
15568 |
|
15569 |
|
15570 |
|
15571 |
|
15572 |
|
15573 |
|
15574 |
|
15575 |
|
15576 |
|
15577 |
|
15578 |
|
15579 |
|
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 |
|
15585 |
|
15586 |
|
15587 |
|
15588 |
|
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 |
|
15594 |
|
15595 |
|
15596 |
|
15597 |
|
15598 |
|
15599 |
|
15600 |
|
15601 |
|
15602 |
|
15603 |
|
15604 |
|
15605 |
|
15606 |
|
15607 |
|
15608 |
|
15609 |
|
15610 |
|
15611 |
|
15612 |
|
15613 |
|
15614 |
|
15615 |
|
15616 |
|
15617 |
|
15618 |
|
15619 |
|
15620 |
|
15621 |
|
15622 |
|
15623 |
|
15624 |
|
15625 |
|
15626 |
|
15627 |
|
15628 |
|
15629 |
|
15630 |
|
15631 |
|
15632 |
|
15633 |
|
15634 |
|
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 |
|
15640 |
|
15641 |
|
15642 |
|
15643 |
|
15644 |
|
15645 |
|
15646 |
|
15647 |
|
15648 |
|
15649 |
|
15650 | var shouldWaitForTimelineChange = function shouldWaitForTimelineChange(_ref2) {
|
15651 | var timelineChangeController = _ref2.timelineChangeController,
|
15652 | currentTimeline = _ref2.currentTimeline,
|
15653 | segmentTimeline = _ref2.segmentTimeline,
|
15654 | loaderType = _ref2.loaderType,
|
15655 | audioDisabled = _ref2.audioDisabled;
|
15656 |
|
15657 | if (currentTimeline === segmentTimeline) {
|
15658 | return false;
|
15659 | }
|
15660 |
|
15661 | if (loaderType === 'audio') {
|
15662 | var lastMainTimelineChange = timelineChangeController.lastTimelineChange({
|
15663 | type: 'main'
|
15664 | });
|
15665 |
|
15666 |
|
15667 |
|
15668 |
|
15669 | return !lastMainTimelineChange || lastMainTimelineChange.to !== segmentTimeline;
|
15670 | }
|
15671 |
|
15672 |
|
15673 |
|
15674 |
|
15675 |
|
15676 | if (loaderType === 'main' && audioDisabled) {
|
15677 | var pendingAudioTimelineChange = timelineChangeController.pendingTimelineChange({
|
15678 | type: 'audio'
|
15679 | });
|
15680 |
|
15681 |
|
15682 |
|
15683 |
|
15684 |
|
15685 |
|
15686 |
|
15687 |
|
15688 |
|
15689 |
|
15690 |
|
15691 |
|
15692 |
|
15693 |
|
15694 |
|
15695 |
|
15696 |
|
15697 |
|
15698 | if (pendingAudioTimelineChange && pendingAudioTimelineChange.to === segmentTimeline) {
|
15699 | return false;
|
15700 | }
|
15701 |
|
15702 | return true;
|
15703 | }
|
15704 |
|
15705 | return false;
|
15706 | };
|
15707 | var mediaDuration = function mediaDuration(timingInfos) {
|
15708 | var maxDuration = 0;
|
15709 | ['video', 'audio'].forEach(function (type) {
|
15710 | var typeTimingInfo = timingInfos[type + "TimingInfo"];
|
15711 |
|
15712 | if (!typeTimingInfo) {
|
15713 | return;
|
15714 | }
|
15715 |
|
15716 | var start = typeTimingInfo.start,
|
15717 | end = typeTimingInfo.end;
|
15718 | var duration;
|
15719 |
|
15720 | if (typeof start === 'bigint' || typeof end === 'bigint') {
|
15721 | duration = window__default["default"].BigInt(end) - window__default["default"].BigInt(start);
|
15722 | } else if (typeof start === 'number' && typeof end === 'number') {
|
15723 | duration = end - start;
|
15724 | }
|
15725 |
|
15726 | if (typeof duration !== 'undefined' && duration > maxDuration) {
|
15727 | maxDuration = duration;
|
15728 | }
|
15729 | });
|
15730 |
|
15731 |
|
15732 | if (typeof maxDuration === 'bigint' && maxDuration < Number.MAX_SAFE_INTEGER) {
|
15733 | maxDuration = Number(maxDuration);
|
15734 | }
|
15735 |
|
15736 | return maxDuration;
|
15737 | };
|
15738 | var segmentTooLong = function segmentTooLong(_ref3) {
|
15739 | var segmentDuration = _ref3.segmentDuration,
|
15740 | maxDuration = _ref3.maxDuration;
|
15741 |
|
15742 |
|
15743 |
|
15744 | if (!segmentDuration) {
|
15745 | return false;
|
15746 | }
|
15747 |
|
15748 |
|
15749 |
|
15750 |
|
15751 |
|
15752 |
|
15753 |
|
15754 |
|
15755 |
|
15756 |
|
15757 |
|
15758 |
|
15759 | return Math.round(segmentDuration) > maxDuration + TIME_FUDGE_FACTOR;
|
15760 | };
|
15761 | var getTroublesomeSegmentDurationMessage = function getTroublesomeSegmentDurationMessage(segmentInfo, sourceType) {
|
15762 |
|
15763 |
|
15764 | if (sourceType !== 'hls') {
|
15765 | return null;
|
15766 | }
|
15767 |
|
15768 | var segmentDuration = mediaDuration({
|
15769 | audioTimingInfo: segmentInfo.audioTimingInfo,
|
15770 | videoTimingInfo: segmentInfo.videoTimingInfo
|
15771 | });
|
15772 |
|
15773 |
|
15774 |
|
15775 |
|
15776 | if (!segmentDuration) {
|
15777 | return null;
|
15778 | }
|
15779 |
|
15780 | var targetDuration = segmentInfo.playlist.targetDuration;
|
15781 | var isSegmentWayTooLong = segmentTooLong({
|
15782 | segmentDuration: segmentDuration,
|
15783 | maxDuration: targetDuration * 2
|
15784 | });
|
15785 | var isSegmentSlightlyTooLong = segmentTooLong({
|
15786 | segmentDuration: segmentDuration,
|
15787 | maxDuration: targetDuration
|
15788 | });
|
15789 | 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';
|
15790 |
|
15791 | if (isSegmentWayTooLong || isSegmentSlightlyTooLong) {
|
15792 | return {
|
15793 | severity: isSegmentWayTooLong ? 'warn' : 'info',
|
15794 | message: segmentTooLongMessage
|
15795 | };
|
15796 | }
|
15797 |
|
15798 | return null;
|
15799 | };
|
15800 |
|
15801 |
|
15802 |
|
15803 |
|
15804 |
|
15805 |
|
15806 |
|
15807 |
|
15808 | var SegmentLoader = function (_videojs$EventTarget) {
|
15809 | _inheritsLoose__default["default"](SegmentLoader, _videojs$EventTarget);
|
15810 |
|
15811 | function SegmentLoader(settings, options) {
|
15812 | var _this;
|
15813 |
|
15814 | _this = _videojs$EventTarget.call(this) || this;
|
15815 |
|
15816 | if (!settings) {
|
15817 | throw new TypeError('Initialization settings are required');
|
15818 | }
|
15819 |
|
15820 | if (typeof settings.currentTime !== 'function') {
|
15821 | throw new TypeError('No currentTime getter specified');
|
15822 | }
|
15823 |
|
15824 | if (!settings.mediaSource) {
|
15825 | throw new TypeError('No MediaSource specified');
|
15826 | }
|
15827 |
|
15828 |
|
15829 | _this.bandwidth = settings.bandwidth;
|
15830 | _this.throughput = {
|
15831 | rate: 0,
|
15832 | count: 0
|
15833 | };
|
15834 | _this.roundTrip = NaN;
|
15835 |
|
15836 | _this.resetStats_();
|
15837 |
|
15838 | _this.mediaIndex = null;
|
15839 | _this.partIndex = null;
|
15840 |
|
15841 | _this.hasPlayed_ = settings.hasPlayed;
|
15842 | _this.currentTime_ = settings.currentTime;
|
15843 | _this.seekable_ = settings.seekable;
|
15844 | _this.seeking_ = settings.seeking;
|
15845 | _this.duration_ = settings.duration;
|
15846 | _this.mediaSource_ = settings.mediaSource;
|
15847 | _this.vhs_ = settings.vhs;
|
15848 | _this.loaderType_ = settings.loaderType;
|
15849 | _this.currentMediaInfo_ = void 0;
|
15850 | _this.startingMediaInfo_ = void 0;
|
15851 | _this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
|
15852 | _this.goalBufferLength_ = settings.goalBufferLength;
|
15853 | _this.sourceType_ = settings.sourceType;
|
15854 | _this.sourceUpdater_ = settings.sourceUpdater;
|
15855 | _this.inbandTextTracks_ = settings.inbandTextTracks;
|
15856 | _this.state_ = 'INIT';
|
15857 | _this.timelineChangeController_ = settings.timelineChangeController;
|
15858 | _this.shouldSaveSegmentTimingInfo_ = true;
|
15859 | _this.parse708captions_ = settings.parse708captions;
|
15860 | _this.useDtsForTimestampOffset_ = settings.useDtsForTimestampOffset;
|
15861 | _this.captionServices_ = settings.captionServices;
|
15862 | _this.experimentalExactManifestTimings = settings.experimentalExactManifestTimings;
|
15863 |
|
15864 | _this.checkBufferTimeout_ = null;
|
15865 | _this.error_ = void 0;
|
15866 | _this.currentTimeline_ = -1;
|
15867 | _this.pendingSegment_ = null;
|
15868 | _this.xhrOptions_ = null;
|
15869 | _this.pendingSegments_ = [];
|
15870 | _this.audioDisabled_ = false;
|
15871 | _this.isPendingTimestampOffset_ = false;
|
15872 |
|
15873 | _this.gopBuffer_ = [];
|
15874 | _this.timeMapping_ = 0;
|
15875 | _this.safeAppend_ = videojs__default["default"].browser.IE_VERSION >= 11;
|
15876 | _this.appendInitSegment_ = {
|
15877 | audio: true,
|
15878 | video: true
|
15879 | };
|
15880 | _this.playlistOfLastInitSegment_ = {
|
15881 | audio: null,
|
15882 | video: null
|
15883 | };
|
15884 | _this.callQueue_ = [];
|
15885 |
|
15886 |
|
15887 |
|
15888 |
|
15889 |
|
15890 | _this.loadQueue_ = [];
|
15891 | _this.metadataQueue_ = {
|
15892 | id3: [],
|
15893 | caption: []
|
15894 | };
|
15895 | _this.waitingOnRemove_ = false;
|
15896 | _this.quotaExceededErrorRetryTimeout_ = null;
|
15897 |
|
15898 | _this.activeInitSegmentId_ = null;
|
15899 | _this.initSegments_ = {};
|
15900 |
|
15901 | _this.cacheEncryptionKeys_ = settings.cacheEncryptionKeys;
|
15902 | _this.keyCache_ = {};
|
15903 | _this.decrypter_ = settings.decrypter;
|
15904 |
|
15905 |
|
15906 |
|
15907 | _this.syncController_ = settings.syncController;
|
15908 | _this.syncPoint_ = {
|
15909 | segmentIndex: 0,
|
15910 | time: 0
|
15911 | };
|
15912 | _this.transmuxer_ = _this.createTransmuxer_();
|
15913 |
|
15914 | _this.triggerSyncInfoUpdate_ = function () {
|
15915 | return _this.trigger('syncinfoupdate');
|
15916 | };
|
15917 |
|
15918 | _this.syncController_.on('syncinfoupdate', _this.triggerSyncInfoUpdate_);
|
15919 |
|
15920 | _this.mediaSource_.addEventListener('sourceopen', function () {
|
15921 | if (!_this.isEndOfStream_()) {
|
15922 | _this.ended_ = false;
|
15923 | }
|
15924 | });
|
15925 |
|
15926 |
|
15927 | _this.fetchAtBuffer_ = false;
|
15928 | _this.logger_ = logger("SegmentLoader[" + _this.loaderType_ + "]");
|
15929 | Object.defineProperty(_assertThisInitialized__default["default"](_this), 'state', {
|
15930 | get: function get() {
|
15931 | return this.state_;
|
15932 | },
|
15933 | set: function set(newState) {
|
15934 | if (newState !== this.state_) {
|
15935 | this.logger_(this.state_ + " -> " + newState);
|
15936 | this.state_ = newState;
|
15937 | this.trigger('statechange');
|
15938 | }
|
15939 | }
|
15940 | });
|
15941 |
|
15942 | _this.sourceUpdater_.on('ready', function () {
|
15943 | if (_this.hasEnoughInfoToAppend_()) {
|
15944 | _this.processCallQueue_();
|
15945 | }
|
15946 | });
|
15947 |
|
15948 |
|
15949 |
|
15950 |
|
15951 |
|
15952 | if (_this.loaderType_ === 'main') {
|
15953 | _this.timelineChangeController_.on('pendingtimelinechange', function () {
|
15954 | if (_this.hasEnoughInfoToAppend_()) {
|
15955 | _this.processCallQueue_();
|
15956 | }
|
15957 | });
|
15958 | }
|
15959 |
|
15960 |
|
15961 |
|
15962 |
|
15963 | if (_this.loaderType_ === 'audio') {
|
15964 | _this.timelineChangeController_.on('timelinechange', function () {
|
15965 | if (_this.hasEnoughInfoToLoad_()) {
|
15966 | _this.processLoadQueue_();
|
15967 | }
|
15968 |
|
15969 | if (_this.hasEnoughInfoToAppend_()) {
|
15970 | _this.processCallQueue_();
|
15971 | }
|
15972 | });
|
15973 | }
|
15974 |
|
15975 | return _this;
|
15976 | }
|
15977 |
|
15978 | var _proto = SegmentLoader.prototype;
|
15979 |
|
15980 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
15981 | return segmentTransmuxer.createTransmuxer({
|
15982 | remux: false,
|
15983 | alignGopsAtEnd: this.safeAppend_,
|
15984 | keepOriginalTimestamps: true,
|
15985 | parse708captions: this.parse708captions_,
|
15986 | captionServices: this.captionServices_
|
15987 | });
|
15988 | }
|
15989 | |
15990 |
|
15991 |
|
15992 |
|
15993 |
|
15994 | ;
|
15995 |
|
15996 | _proto.resetStats_ = function resetStats_() {
|
15997 | this.mediaBytesTransferred = 0;
|
15998 | this.mediaRequests = 0;
|
15999 | this.mediaRequestsAborted = 0;
|
16000 | this.mediaRequestsTimedout = 0;
|
16001 | this.mediaRequestsErrored = 0;
|
16002 | this.mediaTransferDuration = 0;
|
16003 | this.mediaSecondsLoaded = 0;
|
16004 | this.mediaAppends = 0;
|
16005 | }
|
16006 | |
16007 |
|
16008 |
|
16009 | ;
|
16010 |
|
16011 | _proto.dispose = function dispose() {
|
16012 | this.trigger('dispose');
|
16013 | this.state = 'DISPOSED';
|
16014 | this.pause();
|
16015 | this.abort_();
|
16016 |
|
16017 | if (this.transmuxer_) {
|
16018 | this.transmuxer_.terminate();
|
16019 | }
|
16020 |
|
16021 | this.resetStats_();
|
16022 |
|
16023 | if (this.checkBufferTimeout_) {
|
16024 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16025 | }
|
16026 |
|
16027 | if (this.syncController_ && this.triggerSyncInfoUpdate_) {
|
16028 | this.syncController_.off('syncinfoupdate', this.triggerSyncInfoUpdate_);
|
16029 | }
|
16030 |
|
16031 | this.off();
|
16032 | };
|
16033 |
|
16034 | _proto.setAudio = function setAudio(enable) {
|
16035 | this.audioDisabled_ = !enable;
|
16036 |
|
16037 | if (enable) {
|
16038 | this.appendInitSegment_.audio = true;
|
16039 | } else {
|
16040 |
|
16041 | this.sourceUpdater_.removeAudio(0, this.duration_());
|
16042 | }
|
16043 | }
|
16044 | |
16045 |
|
16046 |
|
16047 |
|
16048 | ;
|
16049 |
|
16050 | _proto.abort = function abort() {
|
16051 | if (this.state !== 'WAITING') {
|
16052 | if (this.pendingSegment_) {
|
16053 | this.pendingSegment_ = null;
|
16054 | }
|
16055 |
|
16056 | return;
|
16057 | }
|
16058 |
|
16059 | this.abort_();
|
16060 |
|
16061 |
|
16062 |
|
16063 |
|
16064 | this.state = 'READY';
|
16065 |
|
16066 |
|
16067 | if (!this.paused()) {
|
16068 | this.monitorBuffer_();
|
16069 | }
|
16070 | }
|
16071 | |
16072 |
|
16073 |
|
16074 |
|
16075 |
|
16076 | ;
|
16077 |
|
16078 | _proto.abort_ = function abort_() {
|
16079 | if (this.pendingSegment_ && this.pendingSegment_.abortRequests) {
|
16080 | this.pendingSegment_.abortRequests();
|
16081 | }
|
16082 |
|
16083 |
|
16084 | this.pendingSegment_ = null;
|
16085 | this.callQueue_ = [];
|
16086 | this.loadQueue_ = [];
|
16087 | this.metadataQueue_.id3 = [];
|
16088 | this.metadataQueue_.caption = [];
|
16089 | this.timelineChangeController_.clearPendingTimelineChange(this.loaderType_);
|
16090 | this.waitingOnRemove_ = false;
|
16091 | window__default["default"].clearTimeout(this.quotaExceededErrorRetryTimeout_);
|
16092 | this.quotaExceededErrorRetryTimeout_ = null;
|
16093 | };
|
16094 |
|
16095 | _proto.checkForAbort_ = function checkForAbort_(requestId) {
|
16096 |
|
16097 |
|
16098 | if (this.state === 'APPENDING' && !this.pendingSegment_) {
|
16099 | this.state = 'READY';
|
16100 | return true;
|
16101 | }
|
16102 |
|
16103 | if (!this.pendingSegment_ || this.pendingSegment_.requestId !== requestId) {
|
16104 | return true;
|
16105 | }
|
16106 |
|
16107 | return false;
|
16108 | }
|
16109 | |
16110 |
|
16111 |
|
16112 |
|
16113 |
|
16114 |
|
16115 | ;
|
16116 |
|
16117 | _proto.error = function error(_error) {
|
16118 | if (typeof _error !== 'undefined') {
|
16119 | this.logger_('error occurred:', _error);
|
16120 | this.error_ = _error;
|
16121 | }
|
16122 |
|
16123 | this.pendingSegment_ = null;
|
16124 | return this.error_;
|
16125 | };
|
16126 |
|
16127 | _proto.endOfStream = function endOfStream() {
|
16128 | this.ended_ = true;
|
16129 |
|
16130 | if (this.transmuxer_) {
|
16131 |
|
16132 | segmentTransmuxer.reset(this.transmuxer_);
|
16133 | }
|
16134 |
|
16135 | this.gopBuffer_.length = 0;
|
16136 | this.pause();
|
16137 | this.trigger('ended');
|
16138 | }
|
16139 | |
16140 |
|
16141 |
|
16142 |
|
16143 |
|
16144 |
|
16145 | ;
|
16146 |
|
16147 | _proto.buffered_ = function buffered_() {
|
16148 | var trackInfo = this.getMediaInfo_();
|
16149 |
|
16150 | if (!this.sourceUpdater_ || !trackInfo) {
|
16151 | return videojs__default["default"].createTimeRanges();
|
16152 | }
|
16153 |
|
16154 | if (this.loaderType_ === 'main') {
|
16155 | var hasAudio = trackInfo.hasAudio,
|
16156 | hasVideo = trackInfo.hasVideo,
|
16157 | isMuxed = trackInfo.isMuxed;
|
16158 |
|
16159 | if (hasVideo && hasAudio && !this.audioDisabled_ && !isMuxed) {
|
16160 | return this.sourceUpdater_.buffered();
|
16161 | }
|
16162 |
|
16163 | if (hasVideo) {
|
16164 | return this.sourceUpdater_.videoBuffered();
|
16165 | }
|
16166 | }
|
16167 |
|
16168 |
|
16169 |
|
16170 | return this.sourceUpdater_.audioBuffered();
|
16171 | }
|
16172 | |
16173 |
|
16174 |
|
16175 |
|
16176 |
|
16177 |
|
16178 |
|
16179 |
|
16180 |
|
16181 |
|
16182 | ;
|
16183 |
|
16184 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
16185 | if (set === void 0) {
|
16186 | set = false;
|
16187 | }
|
16188 |
|
16189 | if (!map) {
|
16190 | return null;
|
16191 | }
|
16192 |
|
16193 | var id = initSegmentId(map);
|
16194 | var storedMap = this.initSegments_[id];
|
16195 |
|
16196 | if (set && !storedMap && map.bytes) {
|
16197 | this.initSegments_[id] = storedMap = {
|
16198 | resolvedUri: map.resolvedUri,
|
16199 | byterange: map.byterange,
|
16200 | bytes: map.bytes,
|
16201 | tracks: map.tracks,
|
16202 | timescales: map.timescales
|
16203 | };
|
16204 | }
|
16205 |
|
16206 | return storedMap || map;
|
16207 | }
|
16208 | |
16209 |
|
16210 |
|
16211 |
|
16212 |
|
16213 |
|
16214 |
|
16215 |
|
16216 |
|
16217 |
|
16218 | ;
|
16219 |
|
16220 | _proto.segmentKey = function segmentKey(key, set) {
|
16221 | if (set === void 0) {
|
16222 | set = false;
|
16223 | }
|
16224 |
|
16225 | if (!key) {
|
16226 | return null;
|
16227 | }
|
16228 |
|
16229 | var id = segmentKeyId(key);
|
16230 | var storedKey = this.keyCache_[id];
|
16231 |
|
16232 |
|
16233 | if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) {
|
16234 | this.keyCache_[id] = storedKey = {
|
16235 | resolvedUri: key.resolvedUri,
|
16236 | bytes: key.bytes
|
16237 | };
|
16238 | }
|
16239 |
|
16240 | var result = {
|
16241 | resolvedUri: (storedKey || key).resolvedUri
|
16242 | };
|
16243 |
|
16244 | if (storedKey) {
|
16245 | result.bytes = storedKey.bytes;
|
16246 | }
|
16247 |
|
16248 | return result;
|
16249 | }
|
16250 | |
16251 |
|
16252 |
|
16253 |
|
16254 |
|
16255 |
|
16256 | ;
|
16257 |
|
16258 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
16259 | return this.playlist_ && !this.paused();
|
16260 | }
|
16261 | |
16262 |
|
16263 |
|
16264 | ;
|
16265 |
|
16266 | _proto.load = function load() {
|
16267 |
|
16268 | this.monitorBuffer_();
|
16269 |
|
16270 |
|
16271 | if (!this.playlist_) {
|
16272 | return;
|
16273 | }
|
16274 |
|
16275 |
|
16276 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
16277 | return this.init_();
|
16278 | }
|
16279 |
|
16280 |
|
16281 |
|
16282 | if (!this.couldBeginLoading_() || this.state !== 'READY' && this.state !== 'INIT') {
|
16283 | return;
|
16284 | }
|
16285 |
|
16286 | this.state = 'READY';
|
16287 | }
|
16288 | |
16289 |
|
16290 |
|
16291 |
|
16292 |
|
16293 |
|
16294 |
|
16295 | ;
|
16296 |
|
16297 | _proto.init_ = function init_() {
|
16298 | this.state = 'READY';
|
16299 |
|
16300 |
|
16301 | this.resetEverything();
|
16302 | return this.monitorBuffer_();
|
16303 | }
|
16304 | |
16305 |
|
16306 |
|
16307 |
|
16308 |
|
16309 | ;
|
16310 |
|
16311 | _proto.playlist = function playlist(newPlaylist, options) {
|
16312 | if (options === void 0) {
|
16313 | options = {};
|
16314 | }
|
16315 |
|
16316 | if (!newPlaylist) {
|
16317 | return;
|
16318 | }
|
16319 |
|
16320 | var oldPlaylist = this.playlist_;
|
16321 | var segmentInfo = this.pendingSegment_;
|
16322 | this.playlist_ = newPlaylist;
|
16323 | this.xhrOptions_ = options;
|
16324 |
|
16325 |
|
16326 |
|
16327 |
|
16328 |
|
16329 |
|
16330 |
|
16331 | if (this.state === 'INIT') {
|
16332 | newPlaylist.syncInfo = {
|
16333 | mediaSequence: newPlaylist.mediaSequence,
|
16334 | time: 0
|
16335 | };
|
16336 |
|
16337 |
|
16338 |
|
16339 |
|
16340 |
|
16341 |
|
16342 |
|
16343 |
|
16344 | if (this.loaderType_ === 'main') {
|
16345 | this.syncController_.setDateTimeMappingForStart(newPlaylist);
|
16346 | }
|
16347 | }
|
16348 |
|
16349 | var oldId = null;
|
16350 |
|
16351 | if (oldPlaylist) {
|
16352 | if (oldPlaylist.id) {
|
16353 | oldId = oldPlaylist.id;
|
16354 | } else if (oldPlaylist.uri) {
|
16355 | oldId = oldPlaylist.uri;
|
16356 | }
|
16357 | }
|
16358 |
|
16359 | this.logger_("playlist update [" + oldId + " => " + (newPlaylist.id || newPlaylist.uri) + "]");
|
16360 |
|
16361 |
|
16362 | this.trigger('syncinfoupdate');
|
16363 |
|
16364 |
|
16365 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
16366 | return this.init_();
|
16367 | }
|
16368 |
|
16369 | if (!oldPlaylist || oldPlaylist.uri !== newPlaylist.uri) {
|
16370 | if (this.mediaIndex !== null) {
|
16371 |
|
16372 |
|
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 | if (!newPlaylist.endList) {
|
16380 | this.resetLoader();
|
16381 | } else {
|
16382 | this.resyncLoader();
|
16383 | }
|
16384 | }
|
16385 |
|
16386 | this.currentMediaInfo_ = void 0;
|
16387 | this.trigger('playlistupdate');
|
16388 |
|
16389 | return;
|
16390 | }
|
16391 |
|
16392 |
|
16393 |
|
16394 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
16395 | this.logger_("live window shift [" + mediaSequenceDiff + "]");
|
16396 |
|
16397 |
|
16398 |
|
16399 | if (this.mediaIndex !== null) {
|
16400 | this.mediaIndex -= mediaSequenceDiff;
|
16401 |
|
16402 |
|
16403 |
|
16404 | if (this.mediaIndex < 0) {
|
16405 | this.mediaIndex = null;
|
16406 | this.partIndex = null;
|
16407 | } else {
|
16408 | var segment = this.playlist_.segments[this.mediaIndex];
|
16409 |
|
16410 |
|
16411 |
|
16412 | if (this.partIndex && (!segment.parts || !segment.parts.length || !segment.parts[this.partIndex])) {
|
16413 | var mediaIndex = this.mediaIndex;
|
16414 | this.logger_("currently processing part (index " + this.partIndex + ") no longer exists.");
|
16415 | this.resetLoader();
|
16416 |
|
16417 |
|
16418 |
|
16419 | this.mediaIndex = mediaIndex;
|
16420 | }
|
16421 | }
|
16422 | }
|
16423 |
|
16424 |
|
16425 |
|
16426 |
|
16427 | if (segmentInfo) {
|
16428 | segmentInfo.mediaIndex -= mediaSequenceDiff;
|
16429 |
|
16430 | if (segmentInfo.mediaIndex < 0) {
|
16431 | segmentInfo.mediaIndex = null;
|
16432 | segmentInfo.partIndex = null;
|
16433 | } else {
|
16434 |
|
16435 |
|
16436 |
|
16437 | if (segmentInfo.mediaIndex >= 0) {
|
16438 | segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex];
|
16439 | }
|
16440 |
|
16441 | if (segmentInfo.partIndex >= 0 && segmentInfo.segment.parts) {
|
16442 | segmentInfo.part = segmentInfo.segment.parts[segmentInfo.partIndex];
|
16443 | }
|
16444 | }
|
16445 | }
|
16446 |
|
16447 | this.syncController_.saveExpiredSegmentInfo(oldPlaylist, newPlaylist);
|
16448 | }
|
16449 | |
16450 |
|
16451 |
|
16452 |
|
16453 |
|
16454 |
|
16455 | ;
|
16456 |
|
16457 | _proto.pause = function pause() {
|
16458 | if (this.checkBufferTimeout_) {
|
16459 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16460 | this.checkBufferTimeout_ = null;
|
16461 | }
|
16462 | }
|
16463 | |
16464 |
|
16465 |
|
16466 |
|
16467 |
|
16468 | ;
|
16469 |
|
16470 | _proto.paused = function paused() {
|
16471 | return this.checkBufferTimeout_ === null;
|
16472 | }
|
16473 | |
16474 |
|
16475 |
|
16476 |
|
16477 |
|
16478 |
|
16479 | ;
|
16480 |
|
16481 | _proto.resetEverything = function resetEverything(done) {
|
16482 | this.ended_ = false;
|
16483 | this.appendInitSegment_ = {
|
16484 | audio: true,
|
16485 | video: true
|
16486 | };
|
16487 | this.resetLoader();
|
16488 |
|
16489 |
|
16490 |
|
16491 | this.remove(0, Infinity, done);
|
16492 |
|
16493 | if (this.transmuxer_) {
|
16494 | this.transmuxer_.postMessage({
|
16495 | action: 'clearAllMp4Captions'
|
16496 | });
|
16497 |
|
16498 | this.transmuxer_.postMessage({
|
16499 | action: 'reset'
|
16500 | });
|
16501 | }
|
16502 | }
|
16503 | |
16504 |
|
16505 |
|
16506 |
|
16507 |
|
16508 |
|
16509 | ;
|
16510 |
|
16511 | _proto.resetLoader = function resetLoader() {
|
16512 | this.fetchAtBuffer_ = false;
|
16513 | this.resyncLoader();
|
16514 | }
|
16515 | |
16516 |
|
16517 |
|
16518 |
|
16519 | ;
|
16520 |
|
16521 | _proto.resyncLoader = function resyncLoader() {
|
16522 | if (this.transmuxer_) {
|
16523 |
|
16524 | segmentTransmuxer.reset(this.transmuxer_);
|
16525 | }
|
16526 |
|
16527 | this.mediaIndex = null;
|
16528 | this.partIndex = null;
|
16529 | this.syncPoint_ = null;
|
16530 | this.isPendingTimestampOffset_ = false;
|
16531 | this.callQueue_ = [];
|
16532 | this.loadQueue_ = [];
|
16533 | this.metadataQueue_.id3 = [];
|
16534 | this.metadataQueue_.caption = [];
|
16535 | this.abort();
|
16536 |
|
16537 | if (this.transmuxer_) {
|
16538 | this.transmuxer_.postMessage({
|
16539 | action: 'clearParsedMp4Captions'
|
16540 | });
|
16541 | }
|
16542 | }
|
16543 | |
16544 |
|
16545 |
|
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 |
|
16552 | ;
|
16553 |
|
16554 | _proto.remove = function remove(start, end, done, force) {
|
16555 | if (done === void 0) {
|
16556 | done = function done() {};
|
16557 | }
|
16558 |
|
16559 | if (force === void 0) {
|
16560 | force = false;
|
16561 | }
|
16562 |
|
16563 |
|
16564 |
|
16565 |
|
16566 | if (end === Infinity) {
|
16567 | end = this.duration_();
|
16568 | }
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 | if (end <= start) {
|
16574 | this.logger_('skipping remove because end ${end} is <= start ${start}');
|
16575 | return;
|
16576 | }
|
16577 |
|
16578 | if (!this.sourceUpdater_ || !this.getMediaInfo_()) {
|
16579 | this.logger_('skipping remove because no source updater or starting media info');
|
16580 |
|
16581 | return;
|
16582 | }
|
16583 |
|
16584 |
|
16585 | var removesRemaining = 1;
|
16586 |
|
16587 | var removeFinished = function removeFinished() {
|
16588 | removesRemaining--;
|
16589 |
|
16590 | if (removesRemaining === 0) {
|
16591 | done();
|
16592 | }
|
16593 | };
|
16594 |
|
16595 | if (force || !this.audioDisabled_) {
|
16596 | removesRemaining++;
|
16597 | this.sourceUpdater_.removeAudio(start, end, removeFinished);
|
16598 | }
|
16599 |
|
16600 |
|
16601 |
|
16602 |
|
16603 |
|
16604 |
|
16605 |
|
16606 |
|
16607 |
|
16608 | if (force || this.loaderType_ === 'main') {
|
16609 | this.gopBuffer_ = removeGopBuffer(this.gopBuffer_, start, end, this.timeMapping_);
|
16610 | removesRemaining++;
|
16611 | this.sourceUpdater_.removeVideo(start, end, removeFinished);
|
16612 | }
|
16613 |
|
16614 |
|
16615 | for (var track in this.inbandTextTracks_) {
|
16616 | removeCuesFromTrack(start, end, this.inbandTextTracks_[track]);
|
16617 | }
|
16618 |
|
16619 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
16620 |
|
16621 | removeFinished();
|
16622 | }
|
16623 | |
16624 |
|
16625 |
|
16626 |
|
16627 |
|
16628 | ;
|
16629 |
|
16630 | _proto.monitorBuffer_ = function monitorBuffer_() {
|
16631 | if (this.checkBufferTimeout_) {
|
16632 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16633 | }
|
16634 |
|
16635 | this.checkBufferTimeout_ = window__default["default"].setTimeout(this.monitorBufferTick_.bind(this), 1);
|
16636 | }
|
16637 | |
16638 |
|
16639 |
|
16640 |
|
16641 |
|
16642 |
|
16643 | ;
|
16644 |
|
16645 | _proto.monitorBufferTick_ = function monitorBufferTick_() {
|
16646 | if (this.state === 'READY') {
|
16647 | this.fillBuffer_();
|
16648 | }
|
16649 |
|
16650 | if (this.checkBufferTimeout_) {
|
16651 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16652 | }
|
16653 |
|
16654 | this.checkBufferTimeout_ = window__default["default"].setTimeout(this.monitorBufferTick_.bind(this), CHECK_BUFFER_DELAY);
|
16655 | }
|
16656 | |
16657 |
|
16658 |
|
16659 |
|
16660 |
|
16661 |
|
16662 |
|
16663 |
|
16664 |
|
16665 | ;
|
16666 |
|
16667 | _proto.fillBuffer_ = function fillBuffer_() {
|
16668 |
|
16669 |
|
16670 | if (this.sourceUpdater_.updating()) {
|
16671 | return;
|
16672 | }
|
16673 |
|
16674 |
|
16675 | var segmentInfo = this.chooseNextRequest_();
|
16676 |
|
16677 | if (!segmentInfo) {
|
16678 | return;
|
16679 | }
|
16680 |
|
16681 | if (typeof segmentInfo.timestampOffset === 'number') {
|
16682 | this.isPendingTimestampOffset_ = false;
|
16683 | this.timelineChangeController_.pendingTimelineChange({
|
16684 | type: this.loaderType_,
|
16685 | from: this.currentTimeline_,
|
16686 | to: segmentInfo.timeline
|
16687 | });
|
16688 | }
|
16689 |
|
16690 | this.loadSegment_(segmentInfo);
|
16691 | }
|
16692 | |
16693 |
|
16694 |
|
16695 |
|
16696 |
|
16697 |
|
16698 |
|
16699 |
|
16700 |
|
16701 | ;
|
16702 |
|
16703 | _proto.isEndOfStream_ = function isEndOfStream_(mediaIndex, playlist, partIndex) {
|
16704 | if (mediaIndex === void 0) {
|
16705 | mediaIndex = this.mediaIndex;
|
16706 | }
|
16707 |
|
16708 | if (playlist === void 0) {
|
16709 | playlist = this.playlist_;
|
16710 | }
|
16711 |
|
16712 | if (partIndex === void 0) {
|
16713 | partIndex = this.partIndex;
|
16714 | }
|
16715 |
|
16716 | if (!playlist || !this.mediaSource_) {
|
16717 | return false;
|
16718 | }
|
16719 |
|
16720 | var segment = typeof mediaIndex === 'number' && playlist.segments[mediaIndex];
|
16721 |
|
16722 | var appendedLastSegment = mediaIndex + 1 === playlist.segments.length;
|
16723 |
|
16724 | var appendedLastPart = !segment || !segment.parts || partIndex + 1 === segment.parts.length;
|
16725 |
|
16726 |
|
16727 |
|
16728 | return playlist.endList && this.mediaSource_.readyState === 'open' && appendedLastSegment && appendedLastPart;
|
16729 | }
|
16730 | |
16731 |
|
16732 |
|
16733 |
|
16734 |
|
16735 | ;
|
16736 |
|
16737 | _proto.chooseNextRequest_ = function chooseNextRequest_() {
|
16738 | var buffered = this.buffered_();
|
16739 | var bufferedEnd = lastBufferedEnd(buffered) || 0;
|
16740 | var bufferedTime = timeAheadOf(buffered, this.currentTime_());
|
16741 | var preloaded = !this.hasPlayed_() && bufferedTime >= 1;
|
16742 | var haveEnoughBuffer = bufferedTime >= this.goalBufferLength_();
|
16743 | var segments = this.playlist_.segments;
|
16744 |
|
16745 |
|
16746 |
|
16747 |
|
16748 | if (!segments.length || preloaded || haveEnoughBuffer) {
|
16749 | return null;
|
16750 | }
|
16751 |
|
16752 | this.syncPoint_ = this.syncPoint_ || this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
16753 | var next = {
|
16754 | partIndex: null,
|
16755 | mediaIndex: null,
|
16756 | startOfSegment: null,
|
16757 | playlist: this.playlist_,
|
16758 | isSyncRequest: Boolean(!this.syncPoint_)
|
16759 | };
|
16760 |
|
16761 | if (next.isSyncRequest) {
|
16762 | next.mediaIndex = getSyncSegmentCandidate(this.currentTimeline_, segments, bufferedEnd);
|
16763 | } else if (this.mediaIndex !== null) {
|
16764 | var segment = segments[this.mediaIndex];
|
16765 | var partIndex = typeof this.partIndex === 'number' ? this.partIndex : -1;
|
16766 | next.startOfSegment = segment.end ? segment.end : bufferedEnd;
|
16767 |
|
16768 | if (segment.parts && segment.parts[partIndex + 1]) {
|
16769 | next.mediaIndex = this.mediaIndex;
|
16770 | next.partIndex = partIndex + 1;
|
16771 | } else {
|
16772 | next.mediaIndex = this.mediaIndex + 1;
|
16773 | }
|
16774 | } else {
|
16775 |
|
16776 | var _Playlist$getMediaInf = Playlist.getMediaInfoForTime({
|
16777 | experimentalExactManifestTimings: this.experimentalExactManifestTimings,
|
16778 | playlist: this.playlist_,
|
16779 | currentTime: this.fetchAtBuffer_ ? bufferedEnd : this.currentTime_(),
|
16780 | startingPartIndex: this.syncPoint_.partIndex,
|
16781 | startingSegmentIndex: this.syncPoint_.segmentIndex,
|
16782 | startTime: this.syncPoint_.time
|
16783 | }),
|
16784 | segmentIndex = _Playlist$getMediaInf.segmentIndex,
|
16785 | startTime = _Playlist$getMediaInf.startTime,
|
16786 | _partIndex = _Playlist$getMediaInf.partIndex;
|
16787 |
|
16788 | next.getMediaInfoForTime = this.fetchAtBuffer_ ? "bufferedEnd " + bufferedEnd : "currentTime " + this.currentTime_();
|
16789 | next.mediaIndex = segmentIndex;
|
16790 | next.startOfSegment = startTime;
|
16791 | next.partIndex = _partIndex;
|
16792 | }
|
16793 |
|
16794 | var nextSegment = segments[next.mediaIndex];
|
16795 | var nextPart = nextSegment && typeof next.partIndex === 'number' && nextSegment.parts && nextSegment.parts[next.partIndex];
|
16796 |
|
16797 |
|
16798 | if (!nextSegment || typeof next.partIndex === 'number' && !nextPart) {
|
16799 | return null;
|
16800 | }
|
16801 |
|
16802 |
|
16803 |
|
16804 | if (typeof next.partIndex !== 'number' && nextSegment.parts) {
|
16805 | next.partIndex = 0;
|
16806 | nextPart = nextSegment.parts[0];
|
16807 | }
|
16808 |
|
16809 |
|
16810 |
|
16811 |
|
16812 |
|
16813 | if (!bufferedTime && nextPart && !nextPart.independent) {
|
16814 | if (next.partIndex === 0) {
|
16815 | var lastSegment = segments[next.mediaIndex - 1];
|
16816 | var lastSegmentLastPart = lastSegment.parts && lastSegment.parts.length && lastSegment.parts[lastSegment.parts.length - 1];
|
16817 |
|
16818 | if (lastSegmentLastPart && lastSegmentLastPart.independent) {
|
16819 | next.mediaIndex -= 1;
|
16820 | next.partIndex = lastSegment.parts.length - 1;
|
16821 | next.independent = 'previous segment';
|
16822 | }
|
16823 | } else if (nextSegment.parts[next.partIndex - 1].independent) {
|
16824 | next.partIndex -= 1;
|
16825 | next.independent = 'previous part';
|
16826 | }
|
16827 | }
|
16828 |
|
16829 | var ended = this.mediaSource_ && this.mediaSource_.readyState === 'ended';
|
16830 |
|
16831 |
|
16832 |
|
16833 |
|
16834 | if (next.mediaIndex >= segments.length - 1 && ended && !this.seeking_()) {
|
16835 | return null;
|
16836 | }
|
16837 |
|
16838 | return this.generateSegmentInfo_(next);
|
16839 | };
|
16840 |
|
16841 | _proto.generateSegmentInfo_ = function generateSegmentInfo_(options) {
|
16842 | var independent = options.independent,
|
16843 | playlist = options.playlist,
|
16844 | mediaIndex = options.mediaIndex,
|
16845 | startOfSegment = options.startOfSegment,
|
16846 | isSyncRequest = options.isSyncRequest,
|
16847 | partIndex = options.partIndex,
|
16848 | forceTimestampOffset = options.forceTimestampOffset,
|
16849 | getMediaInfoForTime = options.getMediaInfoForTime;
|
16850 | var segment = playlist.segments[mediaIndex];
|
16851 | var part = typeof partIndex === 'number' && segment.parts[partIndex];
|
16852 | var segmentInfo = {
|
16853 | requestId: 'segment-loader-' + Math.random(),
|
16854 |
|
16855 | uri: part && part.resolvedUri || segment.resolvedUri,
|
16856 |
|
16857 | mediaIndex: mediaIndex,
|
16858 | partIndex: part ? partIndex : null,
|
16859 |
|
16860 |
|
16861 | isSyncRequest: isSyncRequest,
|
16862 | startOfSegment: startOfSegment,
|
16863 |
|
16864 | playlist: playlist,
|
16865 |
|
16866 | bytes: null,
|
16867 |
|
16868 | encryptedBytes: null,
|
16869 |
|
16870 |
|
16871 | timestampOffset: null,
|
16872 |
|
16873 | timeline: segment.timeline,
|
16874 |
|
16875 | duration: part && part.duration || segment.duration,
|
16876 |
|
16877 | segment: segment,
|
16878 | part: part,
|
16879 | byteLength: 0,
|
16880 | transmuxer: this.transmuxer_,
|
16881 |
|
16882 | getMediaInfoForTime: getMediaInfoForTime,
|
16883 | independent: independent
|
16884 | };
|
16885 | var overrideCheck = typeof forceTimestampOffset !== 'undefined' ? forceTimestampOffset : this.isPendingTimestampOffset_;
|
16886 | segmentInfo.timestampOffset = this.timestampOffsetForSegment_({
|
16887 | segmentTimeline: segment.timeline,
|
16888 | currentTimeline: this.currentTimeline_,
|
16889 | startOfSegment: startOfSegment,
|
16890 | buffered: this.buffered_(),
|
16891 | overrideCheck: overrideCheck
|
16892 | });
|
16893 | var audioBufferedEnd = lastBufferedEnd(this.sourceUpdater_.audioBuffered());
|
16894 |
|
16895 | if (typeof audioBufferedEnd === 'number') {
|
16896 |
|
16897 |
|
16898 | segmentInfo.audioAppendStart = audioBufferedEnd - this.sourceUpdater_.audioTimestampOffset();
|
16899 | }
|
16900 |
|
16901 | if (this.sourceUpdater_.videoBuffered().length) {
|
16902 | segmentInfo.gopsToAlignWith = gopsSafeToAlignWith(this.gopBuffer_,
|
16903 |
|
16904 | this.currentTime_() - this.sourceUpdater_.videoTimestampOffset(), this.timeMapping_);
|
16905 | }
|
16906 |
|
16907 | return segmentInfo;
|
16908 | }
|
16909 |
|
16910 |
|
16911 | ;
|
16912 |
|
16913 | _proto.timestampOffsetForSegment_ = function timestampOffsetForSegment_(options) {
|
16914 | return timestampOffsetForSegment(options);
|
16915 | }
|
16916 | |
16917 |
|
16918 |
|
16919 |
|
16920 |
|
16921 |
|
16922 |
|
16923 |
|
16924 |
|
16925 | ;
|
16926 |
|
16927 | _proto.earlyAbortWhenNeeded_ = function earlyAbortWhenNeeded_(stats) {
|
16928 | if (this.vhs_.tech_.paused() ||
|
16929 |
|
16930 |
|
16931 | !this.xhrOptions_.timeout ||
|
16932 | !this.playlist_.attributes.BANDWIDTH) {
|
16933 | return;
|
16934 | }
|
16935 |
|
16936 |
|
16937 |
|
16938 |
|
16939 | if (Date.now() - (stats.firstBytesReceivedAt || Date.now()) < 1000) {
|
16940 | return;
|
16941 | }
|
16942 |
|
16943 | var currentTime = this.currentTime_();
|
16944 | var measuredBandwidth = stats.bandwidth;
|
16945 | var segmentDuration = this.pendingSegment_.duration;
|
16946 | var requestTimeRemaining = Playlist.estimateSegmentRequestTime(segmentDuration, measuredBandwidth, this.playlist_, stats.bytesReceived);
|
16947 |
|
16948 |
|
16949 |
|
16950 | var timeUntilRebuffer$1 = timeUntilRebuffer(this.buffered_(), currentTime, this.vhs_.tech_.playbackRate()) - 1;
|
16951 |
|
16952 |
|
16953 | if (requestTimeRemaining <= timeUntilRebuffer$1) {
|
16954 | return;
|
16955 | }
|
16956 |
|
16957 | var switchCandidate = minRebufferMaxBandwidthSelector({
|
16958 | master: this.vhs_.playlists.master,
|
16959 | currentTime: currentTime,
|
16960 | bandwidth: measuredBandwidth,
|
16961 | duration: this.duration_(),
|
16962 | segmentDuration: segmentDuration,
|
16963 | timeUntilRebuffer: timeUntilRebuffer$1,
|
16964 | currentTimeline: this.currentTimeline_,
|
16965 | syncController: this.syncController_
|
16966 | });
|
16967 |
|
16968 | if (!switchCandidate) {
|
16969 | return;
|
16970 | }
|
16971 |
|
16972 | var rebufferingImpact = requestTimeRemaining - timeUntilRebuffer$1;
|
16973 | var timeSavedBySwitching = rebufferingImpact - switchCandidate.rebufferingImpact;
|
16974 | var minimumTimeSaving = 0.5;
|
16975 |
|
16976 |
|
16977 |
|
16978 | if (timeUntilRebuffer$1 <= TIME_FUDGE_FACTOR) {
|
16979 | minimumTimeSaving = 1;
|
16980 | }
|
16981 |
|
16982 | if (!switchCandidate.playlist || switchCandidate.playlist.uri === this.playlist_.uri || timeSavedBySwitching < minimumTimeSaving) {
|
16983 | return;
|
16984 | }
|
16985 |
|
16986 |
|
16987 |
|
16988 |
|
16989 | this.bandwidth = switchCandidate.playlist.attributes.BANDWIDTH * Config.BANDWIDTH_VARIANCE + 1;
|
16990 | this.trigger('earlyabort');
|
16991 | };
|
16992 |
|
16993 | _proto.handleAbort_ = function handleAbort_(segmentInfo) {
|
16994 | this.logger_("Aborting " + segmentInfoString(segmentInfo));
|
16995 | this.mediaRequestsAborted += 1;
|
16996 | }
|
16997 | |
16998 |
|
16999 |
|
17000 |
|
17001 |
|
17002 |
|
17003 |
|
17004 |
|
17005 |
|
17006 | ;
|
17007 |
|
17008 | _proto.handleProgress_ = function handleProgress_(event, simpleSegment) {
|
17009 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17010 |
|
17011 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17012 | return;
|
17013 | }
|
17014 |
|
17015 | this.trigger('progress');
|
17016 | };
|
17017 |
|
17018 | _proto.handleTrackInfo_ = function handleTrackInfo_(simpleSegment, trackInfo) {
|
17019 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17020 |
|
17021 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17022 | return;
|
17023 | }
|
17024 |
|
17025 | if (this.checkForIllegalMediaSwitch(trackInfo)) {
|
17026 | return;
|
17027 | }
|
17028 |
|
17029 | trackInfo = trackInfo || {};
|
17030 |
|
17031 |
|
17032 |
|
17033 | if (!shallowEqual(this.currentMediaInfo_, trackInfo)) {
|
17034 | this.appendInitSegment_ = {
|
17035 | audio: true,
|
17036 | video: true
|
17037 | };
|
17038 | this.startingMediaInfo_ = trackInfo;
|
17039 | this.currentMediaInfo_ = trackInfo;
|
17040 | this.logger_('trackinfo update', trackInfo);
|
17041 | this.trigger('trackinfo');
|
17042 | }
|
17043 |
|
17044 |
|
17045 |
|
17046 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17047 | return;
|
17048 | }
|
17049 |
|
17050 |
|
17051 |
|
17052 | this.pendingSegment_.trackInfo = trackInfo;
|
17053 |
|
17054 | if (this.hasEnoughInfoToAppend_()) {
|
17055 | this.processCallQueue_();
|
17056 | }
|
17057 | };
|
17058 |
|
17059 | _proto.handleTimingInfo_ = function handleTimingInfo_(simpleSegment, mediaType, timeType, time) {
|
17060 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17061 |
|
17062 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17063 | return;
|
17064 | }
|
17065 |
|
17066 | var segmentInfo = this.pendingSegment_;
|
17067 | var timingInfoProperty = timingInfoPropertyForMedia(mediaType);
|
17068 | segmentInfo[timingInfoProperty] = segmentInfo[timingInfoProperty] || {};
|
17069 | segmentInfo[timingInfoProperty][timeType] = time;
|
17070 | this.logger_("timinginfo: " + mediaType + " - " + timeType + " - " + time);
|
17071 |
|
17072 | if (this.hasEnoughInfoToAppend_()) {
|
17073 | this.processCallQueue_();
|
17074 | }
|
17075 | };
|
17076 |
|
17077 | _proto.handleCaptions_ = function handleCaptions_(simpleSegment, captionData) {
|
17078 | var _this2 = this;
|
17079 |
|
17080 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17081 |
|
17082 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17083 | return;
|
17084 | }
|
17085 |
|
17086 |
|
17087 |
|
17088 | if (captionData.length === 0) {
|
17089 | this.logger_('SegmentLoader received no captions from a caption event');
|
17090 | return;
|
17091 | }
|
17092 |
|
17093 | var segmentInfo = this.pendingSegment_;
|
17094 |
|
17095 |
|
17096 | if (!segmentInfo.hasAppendedData_) {
|
17097 | this.metadataQueue_.caption.push(this.handleCaptions_.bind(this, simpleSegment, captionData));
|
17098 | return;
|
17099 | }
|
17100 |
|
17101 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
17102 | var captionTracks = {};
|
17103 |
|
17104 | captionData.forEach(function (caption) {
|
17105 |
|
17106 |
|
17107 | captionTracks[caption.stream] = captionTracks[caption.stream] || {
|
17108 |
|
17109 | startTime: Infinity,
|
17110 | captions: [],
|
17111 |
|
17112 | endTime: 0
|
17113 | };
|
17114 | var captionTrack = captionTracks[caption.stream];
|
17115 | captionTrack.startTime = Math.min(captionTrack.startTime, caption.startTime + timestampOffset);
|
17116 | captionTrack.endTime = Math.max(captionTrack.endTime, caption.endTime + timestampOffset);
|
17117 | captionTrack.captions.push(caption);
|
17118 | });
|
17119 | Object.keys(captionTracks).forEach(function (trackName) {
|
17120 | var _captionTracks$trackN = captionTracks[trackName],
|
17121 | startTime = _captionTracks$trackN.startTime,
|
17122 | endTime = _captionTracks$trackN.endTime,
|
17123 | captions = _captionTracks$trackN.captions;
|
17124 | var inbandTextTracks = _this2.inbandTextTracks_;
|
17125 |
|
17126 | _this2.logger_("adding cues from " + startTime + " -> " + endTime + " for " + trackName);
|
17127 |
|
17128 | createCaptionsTrackIfNotExists(inbandTextTracks, _this2.vhs_.tech_, trackName);
|
17129 |
|
17130 |
|
17131 |
|
17132 |
|
17133 | removeCuesFromTrack(startTime, endTime, inbandTextTracks[trackName]);
|
17134 | addCaptionData({
|
17135 | captionArray: captions,
|
17136 | inbandTextTracks: inbandTextTracks,
|
17137 | timestampOffset: timestampOffset
|
17138 | });
|
17139 | });
|
17140 |
|
17141 |
|
17142 | if (this.transmuxer_) {
|
17143 | this.transmuxer_.postMessage({
|
17144 | action: 'clearParsedMp4Captions'
|
17145 | });
|
17146 | }
|
17147 | };
|
17148 |
|
17149 | _proto.handleId3_ = function handleId3_(simpleSegment, id3Frames, dispatchType) {
|
17150 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17151 |
|
17152 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17153 | return;
|
17154 | }
|
17155 |
|
17156 | var segmentInfo = this.pendingSegment_;
|
17157 |
|
17158 | if (!segmentInfo.hasAppendedData_) {
|
17159 | this.metadataQueue_.id3.push(this.handleId3_.bind(this, simpleSegment, id3Frames, dispatchType));
|
17160 | return;
|
17161 | }
|
17162 |
|
17163 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
17164 |
|
17165 |
|
17166 |
|
17167 | createMetadataTrackIfNotExists(this.inbandTextTracks_, dispatchType, this.vhs_.tech_);
|
17168 | addMetadata({
|
17169 | inbandTextTracks: this.inbandTextTracks_,
|
17170 | metadataArray: id3Frames,
|
17171 | timestampOffset: timestampOffset,
|
17172 | videoDuration: this.duration_()
|
17173 | });
|
17174 | };
|
17175 |
|
17176 | _proto.processMetadataQueue_ = function processMetadataQueue_() {
|
17177 | this.metadataQueue_.id3.forEach(function (fn) {
|
17178 | return fn();
|
17179 | });
|
17180 | this.metadataQueue_.caption.forEach(function (fn) {
|
17181 | return fn();
|
17182 | });
|
17183 | this.metadataQueue_.id3 = [];
|
17184 | this.metadataQueue_.caption = [];
|
17185 | };
|
17186 |
|
17187 | _proto.processCallQueue_ = function processCallQueue_() {
|
17188 | var callQueue = this.callQueue_;
|
17189 |
|
17190 |
|
17191 |
|
17192 | this.callQueue_ = [];
|
17193 | callQueue.forEach(function (fun) {
|
17194 | return fun();
|
17195 | });
|
17196 | };
|
17197 |
|
17198 | _proto.processLoadQueue_ = function processLoadQueue_() {
|
17199 | var loadQueue = this.loadQueue_;
|
17200 |
|
17201 |
|
17202 |
|
17203 | this.loadQueue_ = [];
|
17204 | loadQueue.forEach(function (fun) {
|
17205 | return fun();
|
17206 | });
|
17207 | }
|
17208 | |
17209 |
|
17210 |
|
17211 |
|
17212 |
|
17213 |
|
17214 | ;
|
17215 |
|
17216 | _proto.hasEnoughInfoToLoad_ = function hasEnoughInfoToLoad_() {
|
17217 |
|
17218 |
|
17219 | if (this.loaderType_ !== 'audio') {
|
17220 | return true;
|
17221 | }
|
17222 |
|
17223 | var segmentInfo = this.pendingSegment_;
|
17224 |
|
17225 |
|
17226 | if (!segmentInfo) {
|
17227 | return false;
|
17228 | }
|
17229 |
|
17230 |
|
17231 |
|
17232 |
|
17233 |
|
17234 | if (!this.getCurrentMediaInfo_()) {
|
17235 | return true;
|
17236 | }
|
17237 |
|
17238 | if (
|
17239 |
|
17240 |
|
17241 |
|
17242 |
|
17243 |
|
17244 |
|
17245 |
|
17246 |
|
17247 |
|
17248 |
|
17249 |
|
17250 |
|
17251 |
|
17252 |
|
17253 | shouldWaitForTimelineChange({
|
17254 | timelineChangeController: this.timelineChangeController_,
|
17255 | currentTimeline: this.currentTimeline_,
|
17256 | segmentTimeline: segmentInfo.timeline,
|
17257 | loaderType: this.loaderType_,
|
17258 | audioDisabled: this.audioDisabled_
|
17259 | })) {
|
17260 | return false;
|
17261 | }
|
17262 |
|
17263 | return true;
|
17264 | };
|
17265 |
|
17266 | _proto.getCurrentMediaInfo_ = function getCurrentMediaInfo_(segmentInfo) {
|
17267 | if (segmentInfo === void 0) {
|
17268 | segmentInfo = this.pendingSegment_;
|
17269 | }
|
17270 |
|
17271 | return segmentInfo && segmentInfo.trackInfo || this.currentMediaInfo_;
|
17272 | };
|
17273 |
|
17274 | _proto.getMediaInfo_ = function getMediaInfo_(segmentInfo) {
|
17275 | if (segmentInfo === void 0) {
|
17276 | segmentInfo = this.pendingSegment_;
|
17277 | }
|
17278 |
|
17279 | return this.getCurrentMediaInfo_(segmentInfo) || this.startingMediaInfo_;
|
17280 | };
|
17281 |
|
17282 | _proto.hasEnoughInfoToAppend_ = function hasEnoughInfoToAppend_() {
|
17283 | if (!this.sourceUpdater_.ready()) {
|
17284 | return false;
|
17285 | }
|
17286 |
|
17287 |
|
17288 |
|
17289 | if (this.waitingOnRemove_ || this.quotaExceededErrorRetryTimeout_) {
|
17290 | return false;
|
17291 | }
|
17292 |
|
17293 | var segmentInfo = this.pendingSegment_;
|
17294 | var trackInfo = this.getCurrentMediaInfo_();
|
17295 |
|
17296 |
|
17297 |
|
17298 | if (!segmentInfo || !trackInfo) {
|
17299 | return false;
|
17300 | }
|
17301 |
|
17302 | var hasAudio = trackInfo.hasAudio,
|
17303 | hasVideo = trackInfo.hasVideo,
|
17304 | isMuxed = trackInfo.isMuxed;
|
17305 |
|
17306 | if (hasVideo && !segmentInfo.videoTimingInfo) {
|
17307 | return false;
|
17308 | }
|
17309 |
|
17310 |
|
17311 | if (hasAudio && !this.audioDisabled_ && !isMuxed && !segmentInfo.audioTimingInfo) {
|
17312 | return false;
|
17313 | }
|
17314 |
|
17315 | if (shouldWaitForTimelineChange({
|
17316 | timelineChangeController: this.timelineChangeController_,
|
17317 | currentTimeline: this.currentTimeline_,
|
17318 | segmentTimeline: segmentInfo.timeline,
|
17319 | loaderType: this.loaderType_,
|
17320 | audioDisabled: this.audioDisabled_
|
17321 | })) {
|
17322 | return false;
|
17323 | }
|
17324 |
|
17325 | return true;
|
17326 | };
|
17327 |
|
17328 | _proto.handleData_ = function handleData_(simpleSegment, result) {
|
17329 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17330 |
|
17331 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17332 | return;
|
17333 | }
|
17334 |
|
17335 |
|
17336 |
|
17337 | if (this.callQueue_.length || !this.hasEnoughInfoToAppend_()) {
|
17338 | this.callQueue_.push(this.handleData_.bind(this, simpleSegment, result));
|
17339 | return;
|
17340 | }
|
17341 |
|
17342 | var segmentInfo = this.pendingSegment_;
|
17343 |
|
17344 | this.setTimeMapping_(segmentInfo.timeline);
|
17345 |
|
17346 | this.updateMediaSecondsLoaded_(segmentInfo.part || segmentInfo.segment);
|
17347 |
|
17348 |
|
17349 |
|
17350 |
|
17351 |
|
17352 | if (this.mediaSource_.readyState === 'closed') {
|
17353 | return;
|
17354 | }
|
17355 |
|
17356 |
|
17357 |
|
17358 | if (simpleSegment.map) {
|
17359 | simpleSegment.map = this.initSegmentForMap(simpleSegment.map, true);
|
17360 |
|
17361 | segmentInfo.segment.map = simpleSegment.map;
|
17362 | }
|
17363 |
|
17364 |
|
17365 | if (simpleSegment.key) {
|
17366 | this.segmentKey(simpleSegment.key, true);
|
17367 | }
|
17368 |
|
17369 | segmentInfo.isFmp4 = simpleSegment.isFmp4;
|
17370 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
17371 |
|
17372 | if (segmentInfo.isFmp4) {
|
17373 | this.trigger('fmp4');
|
17374 | segmentInfo.timingInfo.start = segmentInfo[timingInfoPropertyForMedia(result.type)].start;
|
17375 | } else {
|
17376 | var trackInfo = this.getCurrentMediaInfo_();
|
17377 | var useVideoTimingInfo = this.loaderType_ === 'main' && trackInfo && trackInfo.hasVideo;
|
17378 | var firstVideoFrameTimeForData;
|
17379 |
|
17380 | if (useVideoTimingInfo) {
|
17381 | firstVideoFrameTimeForData = segmentInfo.videoTimingInfo.start;
|
17382 | }
|
17383 |
|
17384 |
|
17385 |
|
17386 |
|
17387 | segmentInfo.timingInfo.start = this.trueSegmentStart_({
|
17388 | currentStart: segmentInfo.timingInfo.start,
|
17389 | playlist: segmentInfo.playlist,
|
17390 | mediaIndex: segmentInfo.mediaIndex,
|
17391 | currentVideoTimestampOffset: this.sourceUpdater_.videoTimestampOffset(),
|
17392 | useVideoTimingInfo: useVideoTimingInfo,
|
17393 | firstVideoFrameTimeForData: firstVideoFrameTimeForData,
|
17394 | videoTimingInfo: segmentInfo.videoTimingInfo,
|
17395 | audioTimingInfo: segmentInfo.audioTimingInfo
|
17396 | });
|
17397 | }
|
17398 |
|
17399 |
|
17400 |
|
17401 |
|
17402 | this.updateAppendInitSegmentStatus(segmentInfo, result.type);
|
17403 |
|
17404 |
|
17405 |
|
17406 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
17407 |
|
17408 |
|
17409 | if (segmentInfo.isSyncRequest) {
|
17410 |
|
17411 |
|
17412 |
|
17413 | this.updateTimingInfoEnd_(segmentInfo);
|
17414 | this.syncController_.saveSegmentTimingInfo({
|
17415 | segmentInfo: segmentInfo,
|
17416 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
17417 | });
|
17418 | var next = this.chooseNextRequest_();
|
17419 |
|
17420 |
|
17421 | if (next.mediaIndex !== segmentInfo.mediaIndex || next.partIndex !== segmentInfo.partIndex) {
|
17422 | this.logger_('sync segment was incorrect, not appending');
|
17423 | return;
|
17424 | }
|
17425 |
|
17426 |
|
17427 | this.logger_('sync segment was correct, appending');
|
17428 | }
|
17429 |
|
17430 |
|
17431 |
|
17432 |
|
17433 |
|
17434 | segmentInfo.hasAppendedData_ = true;
|
17435 |
|
17436 | this.processMetadataQueue_();
|
17437 | this.appendData_(segmentInfo, result);
|
17438 | };
|
17439 |
|
17440 | _proto.updateAppendInitSegmentStatus = function updateAppendInitSegmentStatus(segmentInfo, type) {
|
17441 |
|
17442 | if (this.loaderType_ === 'main' && typeof segmentInfo.timestampOffset === 'number' &&
|
17443 |
|
17444 | !segmentInfo.changedTimestampOffset) {
|
17445 |
|
17446 |
|
17447 | this.appendInitSegment_ = {
|
17448 | audio: true,
|
17449 | video: true
|
17450 | };
|
17451 | }
|
17452 |
|
17453 | if (this.playlistOfLastInitSegment_[type] !== segmentInfo.playlist) {
|
17454 |
|
17455 |
|
17456 | this.appendInitSegment_[type] = true;
|
17457 | }
|
17458 | };
|
17459 |
|
17460 | _proto.getInitSegmentAndUpdateState_ = function getInitSegmentAndUpdateState_(_ref4) {
|
17461 | var type = _ref4.type,
|
17462 | initSegment = _ref4.initSegment,
|
17463 | map = _ref4.map,
|
17464 | playlist = _ref4.playlist;
|
17465 |
|
17466 |
|
17467 |
|
17468 |
|
17469 |
|
17470 |
|
17471 | if (map) {
|
17472 | var id = initSegmentId(map);
|
17473 |
|
17474 | if (this.activeInitSegmentId_ === id) {
|
17475 |
|
17476 | return null;
|
17477 | }
|
17478 |
|
17479 |
|
17480 |
|
17481 |
|
17482 |
|
17483 | initSegment = this.initSegmentForMap(map, true).bytes;
|
17484 | this.activeInitSegmentId_ = id;
|
17485 | }
|
17486 |
|
17487 |
|
17488 |
|
17489 |
|
17490 |
|
17491 |
|
17492 | if (initSegment && this.appendInitSegment_[type]) {
|
17493 |
|
17494 |
|
17495 |
|
17496 | this.playlistOfLastInitSegment_[type] = playlist;
|
17497 |
|
17498 | this.appendInitSegment_[type] = false;
|
17499 |
|
17500 |
|
17501 | this.activeInitSegmentId_ = null;
|
17502 | return initSegment;
|
17503 | }
|
17504 |
|
17505 | return null;
|
17506 | };
|
17507 |
|
17508 | _proto.handleQuotaExceededError_ = function handleQuotaExceededError_(_ref5, error) {
|
17509 | var _this3 = this;
|
17510 |
|
17511 | var segmentInfo = _ref5.segmentInfo,
|
17512 | type = _ref5.type,
|
17513 | bytes = _ref5.bytes;
|
17514 | var audioBuffered = this.sourceUpdater_.audioBuffered();
|
17515 | var videoBuffered = this.sourceUpdater_.videoBuffered();
|
17516 |
|
17517 |
|
17518 |
|
17519 | if (audioBuffered.length > 1) {
|
17520 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the audio buffer: ' + timeRangesToArray(audioBuffered).join(', '));
|
17521 | }
|
17522 |
|
17523 | if (videoBuffered.length > 1) {
|
17524 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the video buffer: ' + timeRangesToArray(videoBuffered).join(', '));
|
17525 | }
|
17526 |
|
17527 | var audioBufferStart = audioBuffered.length ? audioBuffered.start(0) : 0;
|
17528 | var audioBufferEnd = audioBuffered.length ? audioBuffered.end(audioBuffered.length - 1) : 0;
|
17529 | var videoBufferStart = videoBuffered.length ? videoBuffered.start(0) : 0;
|
17530 | var videoBufferEnd = videoBuffered.length ? videoBuffered.end(videoBuffered.length - 1) : 0;
|
17531 |
|
17532 | if (audioBufferEnd - audioBufferStart <= MIN_BACK_BUFFER && videoBufferEnd - videoBufferStart <= MIN_BACK_BUFFER) {
|
17533 |
|
17534 |
|
17535 |
|
17536 |
|
17537 | 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(', ') + ", "));
|
17538 | this.error({
|
17539 | message: 'Quota exceeded error with append of a single segment of content',
|
17540 | excludeUntil: Infinity
|
17541 | });
|
17542 | this.trigger('error');
|
17543 | return;
|
17544 | }
|
17545 |
|
17546 |
|
17547 |
|
17548 |
|
17549 |
|
17550 |
|
17551 |
|
17552 |
|
17553 |
|
17554 |
|
17555 |
|
17556 |
|
17557 |
|
17558 | this.waitingOnRemove_ = true;
|
17559 | this.callQueue_.push(this.appendToSourceBuffer_.bind(this, {
|
17560 | segmentInfo: segmentInfo,
|
17561 | type: type,
|
17562 | bytes: bytes
|
17563 | }));
|
17564 | var currentTime = this.currentTime_();
|
17565 |
|
17566 |
|
17567 | var timeToRemoveUntil = currentTime - MIN_BACK_BUFFER;
|
17568 | this.logger_("On QUOTA_EXCEEDED_ERR, removing audio/video from 0 to " + timeToRemoveUntil);
|
17569 | this.remove(0, timeToRemoveUntil, function () {
|
17570 | _this3.logger_("On QUOTA_EXCEEDED_ERR, retrying append in " + MIN_BACK_BUFFER + "s");
|
17571 |
|
17572 | _this3.waitingOnRemove_ = false;
|
17573 |
|
17574 |
|
17575 | _this3.quotaExceededErrorRetryTimeout_ = window__default["default"].setTimeout(function () {
|
17576 | _this3.logger_('On QUOTA_EXCEEDED_ERR, re-processing call queue');
|
17577 |
|
17578 | _this3.quotaExceededErrorRetryTimeout_ = null;
|
17579 |
|
17580 | _this3.processCallQueue_();
|
17581 | }, MIN_BACK_BUFFER * 1000);
|
17582 | }, true);
|
17583 | };
|
17584 |
|
17585 | _proto.handleAppendError_ = function handleAppendError_(_ref6, error) {
|
17586 | var segmentInfo = _ref6.segmentInfo,
|
17587 | type = _ref6.type,
|
17588 | bytes = _ref6.bytes;
|
17589 |
|
17590 |
|
17591 | if (!error) {
|
17592 | return;
|
17593 | }
|
17594 |
|
17595 | if (error.code === QUOTA_EXCEEDED_ERR) {
|
17596 | this.handleQuotaExceededError_({
|
17597 | segmentInfo: segmentInfo,
|
17598 | type: type,
|
17599 | bytes: bytes
|
17600 | });
|
17601 |
|
17602 |
|
17603 | return;
|
17604 | }
|
17605 |
|
17606 | this.logger_('Received non QUOTA_EXCEEDED_ERR on append', error);
|
17607 | this.error(type + " append of " + bytes.length + "b failed for segment " + ("#" + segmentInfo.mediaIndex + " in playlist " + segmentInfo.playlist.id));
|
17608 |
|
17609 |
|
17610 |
|
17611 |
|
17612 |
|
17613 | this.trigger('appenderror');
|
17614 | };
|
17615 |
|
17616 | _proto.appendToSourceBuffer_ = function appendToSourceBuffer_(_ref7) {
|
17617 | var segmentInfo = _ref7.segmentInfo,
|
17618 | type = _ref7.type,
|
17619 | initSegment = _ref7.initSegment,
|
17620 | data = _ref7.data,
|
17621 | bytes = _ref7.bytes;
|
17622 |
|
17623 |
|
17624 | if (!bytes) {
|
17625 | var segments = [data];
|
17626 | var byteLength = data.byteLength;
|
17627 |
|
17628 | if (initSegment) {
|
17629 |
|
17630 |
|
17631 | segments.unshift(initSegment);
|
17632 | byteLength += initSegment.byteLength;
|
17633 | }
|
17634 |
|
17635 |
|
17636 |
|
17637 | bytes = concatSegments({
|
17638 | bytes: byteLength,
|
17639 | segments: segments
|
17640 | });
|
17641 | }
|
17642 |
|
17643 | this.sourceUpdater_.appendBuffer({
|
17644 | segmentInfo: segmentInfo,
|
17645 | type: type,
|
17646 | bytes: bytes
|
17647 | }, this.handleAppendError_.bind(this, {
|
17648 | segmentInfo: segmentInfo,
|
17649 | type: type,
|
17650 | bytes: bytes
|
17651 | }));
|
17652 | };
|
17653 |
|
17654 | _proto.handleSegmentTimingInfo_ = function handleSegmentTimingInfo_(type, requestId, segmentTimingInfo) {
|
17655 | if (!this.pendingSegment_ || requestId !== this.pendingSegment_.requestId) {
|
17656 | return;
|
17657 | }
|
17658 |
|
17659 | var segment = this.pendingSegment_.segment;
|
17660 | var timingInfoProperty = type + "TimingInfo";
|
17661 |
|
17662 | if (!segment[timingInfoProperty]) {
|
17663 | segment[timingInfoProperty] = {};
|
17664 | }
|
17665 |
|
17666 | segment[timingInfoProperty].transmuxerPrependedSeconds = segmentTimingInfo.prependedContentDuration || 0;
|
17667 | segment[timingInfoProperty].transmuxedPresentationStart = segmentTimingInfo.start.presentation;
|
17668 | segment[timingInfoProperty].transmuxedDecodeStart = segmentTimingInfo.start.decode;
|
17669 | segment[timingInfoProperty].transmuxedPresentationEnd = segmentTimingInfo.end.presentation;
|
17670 | segment[timingInfoProperty].transmuxedDecodeEnd = segmentTimingInfo.end.decode;
|
17671 |
|
17672 | segment[timingInfoProperty].baseMediaDecodeTime = segmentTimingInfo.baseMediaDecodeTime;
|
17673 | };
|
17674 |
|
17675 | _proto.appendData_ = function appendData_(segmentInfo, result) {
|
17676 | var type = result.type,
|
17677 | data = result.data;
|
17678 |
|
17679 | if (!data || !data.byteLength) {
|
17680 | return;
|
17681 | }
|
17682 |
|
17683 | if (type === 'audio' && this.audioDisabled_) {
|
17684 | return;
|
17685 | }
|
17686 |
|
17687 | var initSegment = this.getInitSegmentAndUpdateState_({
|
17688 | type: type,
|
17689 | initSegment: result.initSegment,
|
17690 | playlist: segmentInfo.playlist,
|
17691 | map: segmentInfo.isFmp4 ? segmentInfo.segment.map : null
|
17692 | });
|
17693 | this.appendToSourceBuffer_({
|
17694 | segmentInfo: segmentInfo,
|
17695 | type: type,
|
17696 | initSegment: initSegment,
|
17697 | data: data
|
17698 | });
|
17699 | }
|
17700 | |
17701 |
|
17702 |
|
17703 |
|
17704 |
|
17705 | ;
|
17706 |
|
17707 | _proto.loadSegment_ = function loadSegment_(segmentInfo) {
|
17708 | var _this4 = this;
|
17709 |
|
17710 | this.state = 'WAITING';
|
17711 | this.pendingSegment_ = segmentInfo;
|
17712 | this.trimBackBuffer_(segmentInfo);
|
17713 |
|
17714 | if (typeof segmentInfo.timestampOffset === 'number') {
|
17715 | if (this.transmuxer_) {
|
17716 | this.transmuxer_.postMessage({
|
17717 | action: 'clearAllMp4Captions'
|
17718 | });
|
17719 | }
|
17720 | }
|
17721 |
|
17722 | if (!this.hasEnoughInfoToLoad_()) {
|
17723 | this.loadQueue_.push(function () {
|
17724 |
|
17725 |
|
17726 | var options = _extends__default["default"]({}, segmentInfo, {
|
17727 | forceTimestampOffset: true
|
17728 | });
|
17729 |
|
17730 | _extends__default["default"](segmentInfo, _this4.generateSegmentInfo_(options));
|
17731 |
|
17732 | _this4.isPendingTimestampOffset_ = false;
|
17733 |
|
17734 | _this4.updateTransmuxerAndRequestSegment_(segmentInfo);
|
17735 | });
|
17736 | return;
|
17737 | }
|
17738 |
|
17739 | this.updateTransmuxerAndRequestSegment_(segmentInfo);
|
17740 | };
|
17741 |
|
17742 | _proto.updateTransmuxerAndRequestSegment_ = function updateTransmuxerAndRequestSegment_(segmentInfo) {
|
17743 | var _this5 = this;
|
17744 |
|
17745 |
|
17746 |
|
17747 |
|
17748 |
|
17749 |
|
17750 | if (this.shouldUpdateTransmuxerTimestampOffset_(segmentInfo.timestampOffset)) {
|
17751 | this.gopBuffer_.length = 0;
|
17752 |
|
17753 | segmentInfo.gopsToAlignWith = [];
|
17754 | this.timeMapping_ = 0;
|
17755 |
|
17756 | this.transmuxer_.postMessage({
|
17757 | action: 'reset'
|
17758 | });
|
17759 | this.transmuxer_.postMessage({
|
17760 | action: 'setTimestampOffset',
|
17761 | timestampOffset: segmentInfo.timestampOffset
|
17762 | });
|
17763 | }
|
17764 |
|
17765 | var simpleSegment = this.createSimplifiedSegmentObj_(segmentInfo);
|
17766 | var isEndOfStream = this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex);
|
17767 | var isWalkingForward = this.mediaIndex !== null;
|
17768 | var isDiscontinuity = segmentInfo.timeline !== this.currentTimeline_ &&
|
17769 |
|
17770 | segmentInfo.timeline > 0;
|
17771 | var isEndOfTimeline = isEndOfStream || isWalkingForward && isDiscontinuity;
|
17772 | this.logger_("Requesting " + segmentInfoString(segmentInfo));
|
17773 |
|
17774 |
|
17775 |
|
17776 |
|
17777 |
|
17778 | if (simpleSegment.map && !simpleSegment.map.bytes) {
|
17779 | this.logger_('going to request init segment.');
|
17780 | this.appendInitSegment_ = {
|
17781 | video: true,
|
17782 | audio: true
|
17783 | };
|
17784 | }
|
17785 |
|
17786 | segmentInfo.abortRequests = mediaSegmentRequest({
|
17787 | xhr: this.vhs_.xhr,
|
17788 | xhrOptions: this.xhrOptions_,
|
17789 | decryptionWorker: this.decrypter_,
|
17790 | segment: simpleSegment,
|
17791 | abortFn: this.handleAbort_.bind(this, segmentInfo),
|
17792 | progressFn: this.handleProgress_.bind(this),
|
17793 | trackInfoFn: this.handleTrackInfo_.bind(this),
|
17794 | timingInfoFn: this.handleTimingInfo_.bind(this),
|
17795 | videoSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'video', segmentInfo.requestId),
|
17796 | audioSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'audio', segmentInfo.requestId),
|
17797 | captionsFn: this.handleCaptions_.bind(this),
|
17798 | isEndOfTimeline: isEndOfTimeline,
|
17799 | endedTimelineFn: function endedTimelineFn() {
|
17800 | _this5.logger_('received endedtimeline callback');
|
17801 | },
|
17802 | id3Fn: this.handleId3_.bind(this),
|
17803 | dataFn: this.handleData_.bind(this),
|
17804 | doneFn: this.segmentRequestFinished_.bind(this),
|
17805 | onTransmuxerLog: function onTransmuxerLog(_ref8) {
|
17806 | var message = _ref8.message,
|
17807 | level = _ref8.level,
|
17808 | stream = _ref8.stream;
|
17809 |
|
17810 | _this5.logger_(segmentInfoString(segmentInfo) + " logged from transmuxer stream " + stream + " as a " + level + ": " + message);
|
17811 | }
|
17812 | });
|
17813 | }
|
17814 | |
17815 |
|
17816 |
|
17817 |
|
17818 |
|
17819 |
|
17820 |
|
17821 |
|
17822 | ;
|
17823 |
|
17824 | _proto.trimBackBuffer_ = function trimBackBuffer_(segmentInfo) {
|
17825 | var removeToTime = safeBackBufferTrimTime(this.seekable_(), this.currentTime_(), this.playlist_.targetDuration || 10);
|
17826 |
|
17827 |
|
17828 |
|
17829 |
|
17830 |
|
17831 | if (removeToTime > 0) {
|
17832 | this.remove(0, removeToTime);
|
17833 | }
|
17834 | }
|
17835 | |
17836 |
|
17837 |
|
17838 |
|
17839 |
|
17840 |
|
17841 |
|
17842 |
|
17843 |
|
17844 | ;
|
17845 |
|
17846 | _proto.createSimplifiedSegmentObj_ = function createSimplifiedSegmentObj_(segmentInfo) {
|
17847 | var segment = segmentInfo.segment;
|
17848 | var part = segmentInfo.part;
|
17849 | var simpleSegment = {
|
17850 | resolvedUri: part ? part.resolvedUri : segment.resolvedUri,
|
17851 | byterange: part ? part.byterange : segment.byterange,
|
17852 | requestId: segmentInfo.requestId,
|
17853 | transmuxer: segmentInfo.transmuxer,
|
17854 | audioAppendStart: segmentInfo.audioAppendStart,
|
17855 | gopsToAlignWith: segmentInfo.gopsToAlignWith,
|
17856 | part: segmentInfo.part
|
17857 | };
|
17858 | var previousSegment = segmentInfo.playlist.segments[segmentInfo.mediaIndex - 1];
|
17859 |
|
17860 | if (previousSegment && previousSegment.timeline === segment.timeline) {
|
17861 |
|
17862 |
|
17863 |
|
17864 |
|
17865 |
|
17866 |
|
17867 |
|
17868 |
|
17869 | if (previousSegment.videoTimingInfo) {
|
17870 | simpleSegment.baseStartTime = previousSegment.videoTimingInfo.transmuxedDecodeEnd;
|
17871 | } else if (previousSegment.audioTimingInfo) {
|
17872 | simpleSegment.baseStartTime = previousSegment.audioTimingInfo.transmuxedDecodeEnd;
|
17873 | }
|
17874 | }
|
17875 |
|
17876 | if (segment.key) {
|
17877 |
|
17878 |
|
17879 | var iv = segment.key.iv || new Uint32Array([0, 0, 0, segmentInfo.mediaIndex + segmentInfo.playlist.mediaSequence]);
|
17880 | simpleSegment.key = this.segmentKey(segment.key);
|
17881 | simpleSegment.key.iv = iv;
|
17882 | }
|
17883 |
|
17884 | if (segment.map) {
|
17885 | simpleSegment.map = this.initSegmentForMap(segment.map);
|
17886 | }
|
17887 |
|
17888 | return simpleSegment;
|
17889 | };
|
17890 |
|
17891 | _proto.saveTransferStats_ = function saveTransferStats_(stats) {
|
17892 |
|
17893 |
|
17894 | this.mediaRequests += 1;
|
17895 |
|
17896 | if (stats) {
|
17897 | this.mediaBytesTransferred += stats.bytesReceived;
|
17898 | this.mediaTransferDuration += stats.roundTripTime;
|
17899 | }
|
17900 | };
|
17901 |
|
17902 | _proto.saveBandwidthRelatedStats_ = function saveBandwidthRelatedStats_(duration, stats) {
|
17903 |
|
17904 |
|
17905 |
|
17906 | this.pendingSegment_.byteLength = stats.bytesReceived;
|
17907 |
|
17908 | if (duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
17909 | this.logger_("Ignoring segment's bandwidth because its duration of " + duration + (" is less than the min to record " + MIN_SEGMENT_DURATION_TO_SAVE_STATS));
|
17910 | return;
|
17911 | }
|
17912 |
|
17913 | this.bandwidth = stats.bandwidth;
|
17914 | this.roundTrip = stats.roundTripTime;
|
17915 | };
|
17916 |
|
17917 | _proto.handleTimeout_ = function handleTimeout_() {
|
17918 |
|
17919 |
|
17920 | this.mediaRequestsTimedout += 1;
|
17921 | this.bandwidth = 1;
|
17922 | this.roundTrip = NaN;
|
17923 | this.trigger('bandwidthupdate');
|
17924 | this.trigger('timeout');
|
17925 | }
|
17926 | |
17927 |
|
17928 |
|
17929 |
|
17930 |
|
17931 |
|
17932 | ;
|
17933 |
|
17934 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
17935 |
|
17936 |
|
17937 |
|
17938 |
|
17939 | if (this.callQueue_.length) {
|
17940 | this.callQueue_.push(this.segmentRequestFinished_.bind(this, error, simpleSegment, result));
|
17941 | return;
|
17942 | }
|
17943 |
|
17944 | this.saveTransferStats_(simpleSegment.stats);
|
17945 |
|
17946 | if (!this.pendingSegment_) {
|
17947 | return;
|
17948 | }
|
17949 |
|
17950 |
|
17951 |
|
17952 |
|
17953 |
|
17954 | if (simpleSegment.requestId !== this.pendingSegment_.requestId) {
|
17955 | return;
|
17956 | }
|
17957 |
|
17958 |
|
17959 | if (error) {
|
17960 | this.pendingSegment_ = null;
|
17961 | this.state = 'READY';
|
17962 |
|
17963 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
17964 | return;
|
17965 | }
|
17966 |
|
17967 | this.pause();
|
17968 |
|
17969 |
|
17970 |
|
17971 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
17972 | this.handleTimeout_();
|
17973 | return;
|
17974 | }
|
17975 |
|
17976 |
|
17977 |
|
17978 | this.mediaRequestsErrored += 1;
|
17979 | this.error(error);
|
17980 | this.trigger('error');
|
17981 | return;
|
17982 | }
|
17983 |
|
17984 | var segmentInfo = this.pendingSegment_;
|
17985 |
|
17986 |
|
17987 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
17988 | segmentInfo.endOfAllRequests = simpleSegment.endOfAllRequests;
|
17989 |
|
17990 | if (result.gopInfo) {
|
17991 | this.gopBuffer_ = updateGopBuffer(this.gopBuffer_, result.gopInfo, this.safeAppend_);
|
17992 | }
|
17993 |
|
17994 |
|
17995 |
|
17996 | this.state = 'APPENDING';
|
17997 |
|
17998 | this.trigger('appending');
|
17999 | this.waitForAppendsToComplete_(segmentInfo);
|
18000 | };
|
18001 |
|
18002 | _proto.setTimeMapping_ = function setTimeMapping_(timeline) {
|
18003 | var timelineMapping = this.syncController_.mappingForTimeline(timeline);
|
18004 |
|
18005 | if (timelineMapping !== null) {
|
18006 | this.timeMapping_ = timelineMapping;
|
18007 | }
|
18008 | };
|
18009 |
|
18010 | _proto.updateMediaSecondsLoaded_ = function updateMediaSecondsLoaded_(segment) {
|
18011 | if (typeof segment.start === 'number' && typeof segment.end === 'number') {
|
18012 | this.mediaSecondsLoaded += segment.end - segment.start;
|
18013 | } else {
|
18014 | this.mediaSecondsLoaded += segment.duration;
|
18015 | }
|
18016 | };
|
18017 |
|
18018 | _proto.shouldUpdateTransmuxerTimestampOffset_ = function shouldUpdateTransmuxerTimestampOffset_(timestampOffset) {
|
18019 | if (timestampOffset === null) {
|
18020 | return false;
|
18021 | }
|
18022 |
|
18023 |
|
18024 |
|
18025 | if (this.loaderType_ === 'main' && timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
18026 | return true;
|
18027 | }
|
18028 |
|
18029 | if (!this.audioDisabled_ && timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
18030 | return true;
|
18031 | }
|
18032 |
|
18033 | return false;
|
18034 | };
|
18035 |
|
18036 | _proto.trueSegmentStart_ = function trueSegmentStart_(_ref9) {
|
18037 | var currentStart = _ref9.currentStart,
|
18038 | playlist = _ref9.playlist,
|
18039 | mediaIndex = _ref9.mediaIndex,
|
18040 | firstVideoFrameTimeForData = _ref9.firstVideoFrameTimeForData,
|
18041 | currentVideoTimestampOffset = _ref9.currentVideoTimestampOffset,
|
18042 | useVideoTimingInfo = _ref9.useVideoTimingInfo,
|
18043 | videoTimingInfo = _ref9.videoTimingInfo,
|
18044 | audioTimingInfo = _ref9.audioTimingInfo;
|
18045 |
|
18046 | if (typeof currentStart !== 'undefined') {
|
18047 |
|
18048 | return currentStart;
|
18049 | }
|
18050 |
|
18051 | if (!useVideoTimingInfo) {
|
18052 | return audioTimingInfo.start;
|
18053 | }
|
18054 |
|
18055 | var previousSegment = playlist.segments[mediaIndex - 1];
|
18056 |
|
18057 |
|
18058 |
|
18059 |
|
18060 |
|
18061 | if (mediaIndex === 0 || !previousSegment || typeof previousSegment.start === 'undefined' || previousSegment.end !== firstVideoFrameTimeForData + currentVideoTimestampOffset) {
|
18062 | return firstVideoFrameTimeForData;
|
18063 | }
|
18064 |
|
18065 | return videoTimingInfo.start;
|
18066 | };
|
18067 |
|
18068 | _proto.waitForAppendsToComplete_ = function waitForAppendsToComplete_(segmentInfo) {
|
18069 | var trackInfo = this.getCurrentMediaInfo_(segmentInfo);
|
18070 |
|
18071 | if (!trackInfo) {
|
18072 | this.error({
|
18073 | message: 'No starting media returned, likely due to an unsupported media format.',
|
18074 | blacklistDuration: Infinity
|
18075 | });
|
18076 | this.trigger('error');
|
18077 | return;
|
18078 | }
|
18079 |
|
18080 |
|
18081 |
|
18082 |
|
18083 | var hasAudio = trackInfo.hasAudio,
|
18084 | hasVideo = trackInfo.hasVideo,
|
18085 | isMuxed = trackInfo.isMuxed;
|
18086 | var waitForVideo = this.loaderType_ === 'main' && hasVideo;
|
18087 | var waitForAudio = !this.audioDisabled_ && hasAudio && !isMuxed;
|
18088 | segmentInfo.waitingOnAppends = 0;
|
18089 |
|
18090 | if (!segmentInfo.hasAppendedData_) {
|
18091 | if (!segmentInfo.timingInfo && typeof segmentInfo.timestampOffset === 'number') {
|
18092 |
|
18093 |
|
18094 |
|
18095 |
|
18096 |
|
18097 |
|
18098 |
|
18099 |
|
18100 | this.isPendingTimestampOffset_ = true;
|
18101 | }
|
18102 |
|
18103 |
|
18104 | segmentInfo.timingInfo = {
|
18105 | start: 0
|
18106 | };
|
18107 | segmentInfo.waitingOnAppends++;
|
18108 |
|
18109 | if (!this.isPendingTimestampOffset_) {
|
18110 |
|
18111 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
18112 |
|
18113 |
|
18114 | this.processMetadataQueue_();
|
18115 | }
|
18116 |
|
18117 |
|
18118 | this.checkAppendsDone_(segmentInfo);
|
18119 | return;
|
18120 | }
|
18121 |
|
18122 |
|
18123 | if (waitForVideo) {
|
18124 | segmentInfo.waitingOnAppends++;
|
18125 | }
|
18126 |
|
18127 | if (waitForAudio) {
|
18128 | segmentInfo.waitingOnAppends++;
|
18129 | }
|
18130 |
|
18131 | if (waitForVideo) {
|
18132 | this.sourceUpdater_.videoQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
18133 | }
|
18134 |
|
18135 | if (waitForAudio) {
|
18136 | this.sourceUpdater_.audioQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
18137 | }
|
18138 | };
|
18139 |
|
18140 | _proto.checkAppendsDone_ = function checkAppendsDone_(segmentInfo) {
|
18141 | if (this.checkForAbort_(segmentInfo.requestId)) {
|
18142 | return;
|
18143 | }
|
18144 |
|
18145 | segmentInfo.waitingOnAppends--;
|
18146 |
|
18147 | if (segmentInfo.waitingOnAppends === 0) {
|
18148 | this.handleAppendsDone_();
|
18149 | }
|
18150 | };
|
18151 |
|
18152 | _proto.checkForIllegalMediaSwitch = function checkForIllegalMediaSwitch(trackInfo) {
|
18153 | var illegalMediaSwitchError = illegalMediaSwitch(this.loaderType_, this.getCurrentMediaInfo_(), trackInfo);
|
18154 |
|
18155 | if (illegalMediaSwitchError) {
|
18156 | this.error({
|
18157 | message: illegalMediaSwitchError,
|
18158 | blacklistDuration: Infinity
|
18159 | });
|
18160 | this.trigger('error');
|
18161 | return true;
|
18162 | }
|
18163 |
|
18164 | return false;
|
18165 | };
|
18166 |
|
18167 | _proto.updateSourceBufferTimestampOffset_ = function updateSourceBufferTimestampOffset_(segmentInfo) {
|
18168 | if (segmentInfo.timestampOffset === null ||
|
18169 |
|
18170 | typeof segmentInfo.timingInfo.start !== 'number' ||
|
18171 | segmentInfo.changedTimestampOffset ||
|
18172 | this.loaderType_ !== 'main') {
|
18173 | return;
|
18174 | }
|
18175 |
|
18176 | var didChange = false;
|
18177 |
|
18178 |
|
18179 |
|
18180 |
|
18181 | segmentInfo.timestampOffset -= this.getSegmentStartTimeForTimestampOffsetCalculation_({
|
18182 | videoTimingInfo: segmentInfo.segment.videoTimingInfo,
|
18183 | audioTimingInfo: segmentInfo.segment.audioTimingInfo,
|
18184 | timingInfo: segmentInfo.timingInfo
|
18185 | });
|
18186 |
|
18187 |
|
18188 |
|
18189 | segmentInfo.changedTimestampOffset = true;
|
18190 |
|
18191 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
18192 | this.sourceUpdater_.videoTimestampOffset(segmentInfo.timestampOffset);
|
18193 | didChange = true;
|
18194 | }
|
18195 |
|
18196 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
18197 | this.sourceUpdater_.audioTimestampOffset(segmentInfo.timestampOffset);
|
18198 | didChange = true;
|
18199 | }
|
18200 |
|
18201 | if (didChange) {
|
18202 | this.trigger('timestampoffset');
|
18203 | }
|
18204 | };
|
18205 |
|
18206 | _proto.getSegmentStartTimeForTimestampOffsetCalculation_ = function getSegmentStartTimeForTimestampOffsetCalculation_(_ref10) {
|
18207 | var videoTimingInfo = _ref10.videoTimingInfo,
|
18208 | audioTimingInfo = _ref10.audioTimingInfo,
|
18209 | timingInfo = _ref10.timingInfo;
|
18210 |
|
18211 | if (!this.useDtsForTimestampOffset_) {
|
18212 | return timingInfo.start;
|
18213 | }
|
18214 |
|
18215 | if (videoTimingInfo && typeof videoTimingInfo.transmuxedDecodeStart === 'number') {
|
18216 | return videoTimingInfo.transmuxedDecodeStart;
|
18217 | }
|
18218 |
|
18219 |
|
18220 | if (audioTimingInfo && typeof audioTimingInfo.transmuxedDecodeStart === 'number') {
|
18221 | return audioTimingInfo.transmuxedDecodeStart;
|
18222 | }
|
18223 |
|
18224 |
|
18225 | return timingInfo.start;
|
18226 | };
|
18227 |
|
18228 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_(segmentInfo) {
|
18229 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
18230 | var trackInfo = this.getMediaInfo_();
|
18231 | var useVideoTimingInfo = this.loaderType_ === 'main' && trackInfo && trackInfo.hasVideo;
|
18232 | var prioritizedTimingInfo = useVideoTimingInfo && segmentInfo.videoTimingInfo ? segmentInfo.videoTimingInfo : segmentInfo.audioTimingInfo;
|
18233 |
|
18234 | if (!prioritizedTimingInfo) {
|
18235 | return;
|
18236 | }
|
18237 |
|
18238 | segmentInfo.timingInfo.end = typeof prioritizedTimingInfo.end === 'number' ?
|
18239 |
|
18240 |
|
18241 | prioritizedTimingInfo.end : prioritizedTimingInfo.start + segmentInfo.duration;
|
18242 | }
|
18243 | |
18244 |
|
18245 |
|
18246 |
|
18247 |
|
18248 |
|
18249 |
|
18250 | ;
|
18251 |
|
18252 | _proto.handleAppendsDone_ = function handleAppendsDone_() {
|
18253 |
|
18254 | if (this.pendingSegment_) {
|
18255 | this.trigger('appendsdone');
|
18256 | }
|
18257 |
|
18258 | if (!this.pendingSegment_) {
|
18259 | this.state = 'READY';
|
18260 |
|
18261 |
|
18262 | if (!this.paused()) {
|
18263 | this.monitorBuffer_();
|
18264 | }
|
18265 |
|
18266 | return;
|
18267 | }
|
18268 |
|
18269 | var segmentInfo = this.pendingSegment_;
|
18270 |
|
18271 |
|
18272 |
|
18273 | this.updateTimingInfoEnd_(segmentInfo);
|
18274 |
|
18275 | if (this.shouldSaveSegmentTimingInfo_) {
|
18276 |
|
18277 |
|
18278 |
|
18279 |
|
18280 |
|
18281 |
|
18282 |
|
18283 |
|
18284 |
|
18285 |
|
18286 |
|
18287 |
|
18288 |
|
18289 |
|
18290 |
|
18291 |
|
18292 |
|
18293 | this.syncController_.saveSegmentTimingInfo({
|
18294 | segmentInfo: segmentInfo,
|
18295 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
18296 | });
|
18297 | }
|
18298 |
|
18299 | var segmentDurationMessage = getTroublesomeSegmentDurationMessage(segmentInfo, this.sourceType_);
|
18300 |
|
18301 | if (segmentDurationMessage) {
|
18302 | if (segmentDurationMessage.severity === 'warn') {
|
18303 | videojs__default["default"].log.warn(segmentDurationMessage.message);
|
18304 | } else {
|
18305 | this.logger_(segmentDurationMessage.message);
|
18306 | }
|
18307 | }
|
18308 |
|
18309 | this.recordThroughput_(segmentInfo);
|
18310 | this.pendingSegment_ = null;
|
18311 | this.state = 'READY';
|
18312 |
|
18313 | if (segmentInfo.isSyncRequest) {
|
18314 | this.trigger('syncinfoupdate');
|
18315 |
|
18316 |
|
18317 |
|
18318 |
|
18319 | if (!segmentInfo.hasAppendedData_) {
|
18320 | this.logger_("Throwing away un-appended sync request " + segmentInfoString(segmentInfo));
|
18321 | return;
|
18322 | }
|
18323 | }
|
18324 |
|
18325 | this.logger_("Appended " + segmentInfoString(segmentInfo));
|
18326 | this.addSegmentMetadataCue_(segmentInfo);
|
18327 | this.fetchAtBuffer_ = true;
|
18328 |
|
18329 | if (this.currentTimeline_ !== segmentInfo.timeline) {
|
18330 | this.timelineChangeController_.lastTimelineChange({
|
18331 | type: this.loaderType_,
|
18332 | from: this.currentTimeline_,
|
18333 | to: segmentInfo.timeline
|
18334 | });
|
18335 |
|
18336 |
|
18337 |
|
18338 | if (this.loaderType_ === 'main' && !this.audioDisabled_) {
|
18339 | this.timelineChangeController_.lastTimelineChange({
|
18340 | type: 'audio',
|
18341 | from: this.currentTimeline_,
|
18342 | to: segmentInfo.timeline
|
18343 | });
|
18344 | }
|
18345 | }
|
18346 |
|
18347 | this.currentTimeline_ = segmentInfo.timeline;
|
18348 |
|
18349 |
|
18350 |
|
18351 |
|
18352 | this.trigger('syncinfoupdate');
|
18353 | var segment = segmentInfo.segment;
|
18354 | var part = segmentInfo.part;
|
18355 | var badSegmentGuess = segment.end && this.currentTime_() - segment.end > segmentInfo.playlist.targetDuration * 3;
|
18356 | var badPartGuess = part && part.end && this.currentTime_() - part.end > segmentInfo.playlist.partTargetDuration * 3;
|
18357 |
|
18358 |
|
18359 |
|
18360 |
|
18361 | if (badSegmentGuess || badPartGuess) {
|
18362 | this.logger_("bad " + (badSegmentGuess ? 'segment' : 'part') + " " + segmentInfoString(segmentInfo));
|
18363 | this.resetEverything();
|
18364 | return;
|
18365 | }
|
18366 |
|
18367 | var isWalkingForward = this.mediaIndex !== null;
|
18368 |
|
18369 |
|
18370 | if (isWalkingForward) {
|
18371 | this.trigger('bandwidthupdate');
|
18372 | }
|
18373 |
|
18374 | this.trigger('progress');
|
18375 | this.mediaIndex = segmentInfo.mediaIndex;
|
18376 | this.partIndex = segmentInfo.partIndex;
|
18377 |
|
18378 |
|
18379 |
|
18380 | if (this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex)) {
|
18381 | this.endOfStream();
|
18382 | }
|
18383 |
|
18384 |
|
18385 | this.trigger('appended');
|
18386 |
|
18387 | if (segmentInfo.hasAppendedData_) {
|
18388 | this.mediaAppends++;
|
18389 | }
|
18390 |
|
18391 | if (!this.paused()) {
|
18392 | this.monitorBuffer_();
|
18393 | }
|
18394 | }
|
18395 | |
18396 |
|
18397 |
|
18398 |
|
18399 |
|
18400 |
|
18401 |
|
18402 |
|
18403 |
|
18404 | ;
|
18405 |
|
18406 | _proto.recordThroughput_ = function recordThroughput_(segmentInfo) {
|
18407 | if (segmentInfo.duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
18408 | 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));
|
18409 | return;
|
18410 | }
|
18411 |
|
18412 | var rate = this.throughput.rate;
|
18413 |
|
18414 |
|
18415 | var segmentProcessingTime = Date.now() - segmentInfo.endOfAllRequests + 1;
|
18416 |
|
18417 | var segmentProcessingThroughput = Math.floor(segmentInfo.byteLength / segmentProcessingTime * 8 * 1000);
|
18418 |
|
18419 |
|
18420 | this.throughput.rate += (segmentProcessingThroughput - rate) / ++this.throughput.count;
|
18421 | }
|
18422 | |
18423 |
|
18424 |
|
18425 |
|
18426 |
|
18427 |
|
18428 |
|
18429 |
|
18430 |
|
18431 | ;
|
18432 |
|
18433 | _proto.addSegmentMetadataCue_ = function addSegmentMetadataCue_(segmentInfo) {
|
18434 | if (!this.segmentMetadataTrack_) {
|
18435 | return;
|
18436 | }
|
18437 |
|
18438 | var segment = segmentInfo.segment;
|
18439 | var start = segment.start;
|
18440 | var end = segment.end;
|
18441 |
|
18442 | if (!finite(start) || !finite(end)) {
|
18443 | return;
|
18444 | }
|
18445 |
|
18446 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
18447 | var Cue = window__default["default"].WebKitDataCue || window__default["default"].VTTCue;
|
18448 | var value = {
|
18449 | custom: segment.custom,
|
18450 | dateTimeObject: segment.dateTimeObject,
|
18451 | dateTimeString: segment.dateTimeString,
|
18452 | bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
|
18453 | resolution: segmentInfo.playlist.attributes.RESOLUTION,
|
18454 | codecs: segmentInfo.playlist.attributes.CODECS,
|
18455 | byteLength: segmentInfo.byteLength,
|
18456 | uri: segmentInfo.uri,
|
18457 | timeline: segmentInfo.timeline,
|
18458 | playlist: segmentInfo.playlist.id,
|
18459 | start: start,
|
18460 | end: end
|
18461 | };
|
18462 | var data = JSON.stringify(value);
|
18463 | var cue = new Cue(start, end, data);
|
18464 |
|
18465 |
|
18466 | cue.value = value;
|
18467 | this.segmentMetadataTrack_.addCue(cue);
|
18468 | };
|
18469 |
|
18470 | return SegmentLoader;
|
18471 | }(videojs__default["default"].EventTarget);
|
18472 |
|
18473 | function noop() {}
|
18474 |
|
18475 | var toTitleCase = function toTitleCase(string) {
|
18476 | if (typeof string !== 'string') {
|
18477 | return string;
|
18478 | }
|
18479 |
|
18480 | return string.replace(/./, function (w) {
|
18481 | return w.toUpperCase();
|
18482 | });
|
18483 | };
|
18484 |
|
18485 | var bufferTypes = ['video', 'audio'];
|
18486 |
|
18487 | var _updating = function updating(type, sourceUpdater) {
|
18488 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18489 | return sourceBuffer && sourceBuffer.updating || sourceUpdater.queuePending[type];
|
18490 | };
|
18491 |
|
18492 | var nextQueueIndexOfType = function nextQueueIndexOfType(type, queue) {
|
18493 | for (var i = 0; i < queue.length; i++) {
|
18494 | var queueEntry = queue[i];
|
18495 |
|
18496 | if (queueEntry.type === 'mediaSource') {
|
18497 |
|
18498 |
|
18499 | return null;
|
18500 | }
|
18501 |
|
18502 | if (queueEntry.type === type) {
|
18503 | return i;
|
18504 | }
|
18505 | }
|
18506 |
|
18507 | return null;
|
18508 | };
|
18509 |
|
18510 | var shiftQueue = function shiftQueue(type, sourceUpdater) {
|
18511 | if (sourceUpdater.queue.length === 0) {
|
18512 | return;
|
18513 | }
|
18514 |
|
18515 | var queueIndex = 0;
|
18516 | var queueEntry = sourceUpdater.queue[queueIndex];
|
18517 |
|
18518 | if (queueEntry.type === 'mediaSource') {
|
18519 | if (!sourceUpdater.updating() && sourceUpdater.mediaSource.readyState !== 'closed') {
|
18520 | sourceUpdater.queue.shift();
|
18521 | queueEntry.action(sourceUpdater);
|
18522 |
|
18523 | if (queueEntry.doneFn) {
|
18524 | queueEntry.doneFn();
|
18525 | }
|
18526 |
|
18527 |
|
18528 |
|
18529 |
|
18530 | shiftQueue('audio', sourceUpdater);
|
18531 | shiftQueue('video', sourceUpdater);
|
18532 | }
|
18533 |
|
18534 |
|
18535 |
|
18536 |
|
18537 | return;
|
18538 | }
|
18539 |
|
18540 | if (type === 'mediaSource') {
|
18541 |
|
18542 |
|
18543 |
|
18544 |
|
18545 | return;
|
18546 | }
|
18547 |
|
18548 |
|
18549 |
|
18550 |
|
18551 | if (!sourceUpdater.ready() || sourceUpdater.mediaSource.readyState === 'closed' || _updating(type, sourceUpdater)) {
|
18552 | return;
|
18553 | }
|
18554 |
|
18555 | if (queueEntry.type !== type) {
|
18556 | queueIndex = nextQueueIndexOfType(type, sourceUpdater.queue);
|
18557 |
|
18558 | if (queueIndex === null) {
|
18559 |
|
18560 |
|
18561 |
|
18562 | return;
|
18563 | }
|
18564 |
|
18565 | queueEntry = sourceUpdater.queue[queueIndex];
|
18566 | }
|
18567 |
|
18568 | sourceUpdater.queue.splice(queueIndex, 1);
|
18569 |
|
18570 |
|
18571 |
|
18572 |
|
18573 |
|
18574 |
|
18575 |
|
18576 | sourceUpdater.queuePending[type] = queueEntry;
|
18577 | queueEntry.action(type, sourceUpdater);
|
18578 |
|
18579 | if (!queueEntry.doneFn) {
|
18580 |
|
18581 | sourceUpdater.queuePending[type] = null;
|
18582 | shiftQueue(type, sourceUpdater);
|
18583 | return;
|
18584 | }
|
18585 | };
|
18586 |
|
18587 | var cleanupBuffer = function cleanupBuffer(type, sourceUpdater) {
|
18588 | var buffer = sourceUpdater[type + "Buffer"];
|
18589 | var titleType = toTitleCase(type);
|
18590 |
|
18591 | if (!buffer) {
|
18592 | return;
|
18593 | }
|
18594 |
|
18595 | buffer.removeEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
18596 | buffer.removeEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
18597 | sourceUpdater.codecs[type] = null;
|
18598 | sourceUpdater[type + "Buffer"] = null;
|
18599 | };
|
18600 |
|
18601 | var inSourceBuffers = function inSourceBuffers(mediaSource, sourceBuffer) {
|
18602 | return mediaSource && sourceBuffer && Array.prototype.indexOf.call(mediaSource.sourceBuffers, sourceBuffer) !== -1;
|
18603 | };
|
18604 |
|
18605 | var actions = {
|
18606 | appendBuffer: function appendBuffer(bytes, segmentInfo, onError) {
|
18607 | return function (type, sourceUpdater) {
|
18608 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18609 |
|
18610 |
|
18611 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18612 | return;
|
18613 | }
|
18614 |
|
18615 | sourceUpdater.logger_("Appending segment " + segmentInfo.mediaIndex + "'s " + bytes.length + " bytes to " + type + "Buffer");
|
18616 |
|
18617 | try {
|
18618 | sourceBuffer.appendBuffer(bytes);
|
18619 | } catch (e) {
|
18620 | sourceUpdater.logger_("Error with code " + e.code + " " + (e.code === QUOTA_EXCEEDED_ERR ? '(QUOTA_EXCEEDED_ERR) ' : '') + ("when appending segment " + segmentInfo.mediaIndex + " to " + type + "Buffer"));
|
18621 | sourceUpdater.queuePending[type] = null;
|
18622 | onError(e);
|
18623 | }
|
18624 | };
|
18625 | },
|
18626 | remove: function remove(start, end) {
|
18627 | return function (type, sourceUpdater) {
|
18628 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18629 |
|
18630 |
|
18631 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18632 | return;
|
18633 | }
|
18634 |
|
18635 | sourceUpdater.logger_("Removing " + start + " to " + end + " from " + type + "Buffer");
|
18636 |
|
18637 | try {
|
18638 | sourceBuffer.remove(start, end);
|
18639 | } catch (e) {
|
18640 | sourceUpdater.logger_("Remove " + start + " to " + end + " from " + type + "Buffer failed");
|
18641 | }
|
18642 | };
|
18643 | },
|
18644 | timestampOffset: function timestampOffset(offset) {
|
18645 | return function (type, sourceUpdater) {
|
18646 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18647 |
|
18648 |
|
18649 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18650 | return;
|
18651 | }
|
18652 |
|
18653 | sourceUpdater.logger_("Setting " + type + "timestampOffset to " + offset);
|
18654 | sourceBuffer.timestampOffset = offset;
|
18655 | };
|
18656 | },
|
18657 | callback: function callback(_callback) {
|
18658 | return function (type, sourceUpdater) {
|
18659 | _callback();
|
18660 | };
|
18661 | },
|
18662 | endOfStream: function endOfStream(error) {
|
18663 | return function (sourceUpdater) {
|
18664 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
18665 | return;
|
18666 | }
|
18667 |
|
18668 | sourceUpdater.logger_("Calling mediaSource endOfStream(" + (error || '') + ")");
|
18669 |
|
18670 | try {
|
18671 | sourceUpdater.mediaSource.endOfStream(error);
|
18672 | } catch (e) {
|
18673 | videojs__default["default"].log.warn('Failed to call media source endOfStream', e);
|
18674 | }
|
18675 | };
|
18676 | },
|
18677 | duration: function duration(_duration) {
|
18678 | return function (sourceUpdater) {
|
18679 | sourceUpdater.logger_("Setting mediaSource duration to " + _duration);
|
18680 |
|
18681 | try {
|
18682 | sourceUpdater.mediaSource.duration = _duration;
|
18683 | } catch (e) {
|
18684 | videojs__default["default"].log.warn('Failed to set media source duration', e);
|
18685 | }
|
18686 | };
|
18687 | },
|
18688 | abort: function abort() {
|
18689 | return function (type, sourceUpdater) {
|
18690 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
18691 | return;
|
18692 | }
|
18693 |
|
18694 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18695 |
|
18696 |
|
18697 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18698 | return;
|
18699 | }
|
18700 |
|
18701 | sourceUpdater.logger_("calling abort on " + type + "Buffer");
|
18702 |
|
18703 | try {
|
18704 | sourceBuffer.abort();
|
18705 | } catch (e) {
|
18706 | videojs__default["default"].log.warn("Failed to abort on " + type + "Buffer", e);
|
18707 | }
|
18708 | };
|
18709 | },
|
18710 | addSourceBuffer: function addSourceBuffer(type, codec) {
|
18711 | return function (sourceUpdater) {
|
18712 | var titleType = toTitleCase(type);
|
18713 | var mime = codecs_js.getMimeForCodec(codec);
|
18714 | sourceUpdater.logger_("Adding " + type + "Buffer with codec " + codec + " to mediaSource");
|
18715 | var sourceBuffer = sourceUpdater.mediaSource.addSourceBuffer(mime);
|
18716 | sourceBuffer.addEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
18717 | sourceBuffer.addEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
18718 | sourceUpdater.codecs[type] = codec;
|
18719 | sourceUpdater[type + "Buffer"] = sourceBuffer;
|
18720 | };
|
18721 | },
|
18722 | removeSourceBuffer: function removeSourceBuffer(type) {
|
18723 | return function (sourceUpdater) {
|
18724 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18725 | cleanupBuffer(type, sourceUpdater);
|
18726 |
|
18727 |
|
18728 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18729 | return;
|
18730 | }
|
18731 |
|
18732 | sourceUpdater.logger_("Removing " + type + "Buffer with codec " + sourceUpdater.codecs[type] + " from mediaSource");
|
18733 |
|
18734 | try {
|
18735 | sourceUpdater.mediaSource.removeSourceBuffer(sourceBuffer);
|
18736 | } catch (e) {
|
18737 | videojs__default["default"].log.warn("Failed to removeSourceBuffer " + type + "Buffer", e);
|
18738 | }
|
18739 | };
|
18740 | },
|
18741 | changeType: function changeType(codec) {
|
18742 | return function (type, sourceUpdater) {
|
18743 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18744 | var mime = codecs_js.getMimeForCodec(codec);
|
18745 |
|
18746 |
|
18747 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18748 | return;
|
18749 | }
|
18750 |
|
18751 |
|
18752 | if (sourceUpdater.codecs[type] === codec) {
|
18753 | return;
|
18754 | }
|
18755 |
|
18756 | sourceUpdater.logger_("changing " + type + "Buffer codec from " + sourceUpdater.codecs[type] + " to " + codec);
|
18757 | sourceBuffer.changeType(mime);
|
18758 | sourceUpdater.codecs[type] = codec;
|
18759 | };
|
18760 | }
|
18761 | };
|
18762 |
|
18763 | var pushQueue = function pushQueue(_ref) {
|
18764 | var type = _ref.type,
|
18765 | sourceUpdater = _ref.sourceUpdater,
|
18766 | action = _ref.action,
|
18767 | doneFn = _ref.doneFn,
|
18768 | name = _ref.name;
|
18769 | sourceUpdater.queue.push({
|
18770 | type: type,
|
18771 | action: action,
|
18772 | doneFn: doneFn,
|
18773 | name: name
|
18774 | });
|
18775 | shiftQueue(type, sourceUpdater);
|
18776 | };
|
18777 |
|
18778 | var onUpdateend = function onUpdateend(type, sourceUpdater) {
|
18779 | return function (e) {
|
18780 |
|
18781 |
|
18782 |
|
18783 |
|
18784 |
|
18785 |
|
18786 | if (sourceUpdater.queuePending[type]) {
|
18787 | var doneFn = sourceUpdater.queuePending[type].doneFn;
|
18788 | sourceUpdater.queuePending[type] = null;
|
18789 |
|
18790 | if (doneFn) {
|
18791 |
|
18792 | doneFn(sourceUpdater[type + "Error_"]);
|
18793 | }
|
18794 | }
|
18795 |
|
18796 | shiftQueue(type, sourceUpdater);
|
18797 | };
|
18798 | };
|
18799 |
|
18800 |
|
18801 |
|
18802 |
|
18803 |
|
18804 |
|
18805 |
|
18806 |
|
18807 |
|
18808 |
|
18809 |
|
18810 |
|
18811 | var SourceUpdater = function (_videojs$EventTarget) {
|
18812 | _inheritsLoose__default["default"](SourceUpdater, _videojs$EventTarget);
|
18813 |
|
18814 | function SourceUpdater(mediaSource) {
|
18815 | var _this;
|
18816 |
|
18817 | _this = _videojs$EventTarget.call(this) || this;
|
18818 | _this.mediaSource = mediaSource;
|
18819 |
|
18820 | _this.sourceopenListener_ = function () {
|
18821 | return shiftQueue('mediaSource', _assertThisInitialized__default["default"](_this));
|
18822 | };
|
18823 |
|
18824 | _this.mediaSource.addEventListener('sourceopen', _this.sourceopenListener_);
|
18825 |
|
18826 | _this.logger_ = logger('SourceUpdater');
|
18827 |
|
18828 | _this.audioTimestampOffset_ = 0;
|
18829 | _this.videoTimestampOffset_ = 0;
|
18830 | _this.queue = [];
|
18831 | _this.queuePending = {
|
18832 | audio: null,
|
18833 | video: null
|
18834 | };
|
18835 | _this.delayedAudioAppendQueue_ = [];
|
18836 | _this.videoAppendQueued_ = false;
|
18837 | _this.codecs = {};
|
18838 | _this.onVideoUpdateEnd_ = onUpdateend('video', _assertThisInitialized__default["default"](_this));
|
18839 | _this.onAudioUpdateEnd_ = onUpdateend('audio', _assertThisInitialized__default["default"](_this));
|
18840 |
|
18841 | _this.onVideoError_ = function (e) {
|
18842 |
|
18843 | _this.videoError_ = e;
|
18844 | };
|
18845 |
|
18846 | _this.onAudioError_ = function (e) {
|
18847 |
|
18848 | _this.audioError_ = e;
|
18849 | };
|
18850 |
|
18851 | _this.createdSourceBuffers_ = false;
|
18852 | _this.initializedEme_ = false;
|
18853 | _this.triggeredReady_ = false;
|
18854 | return _this;
|
18855 | }
|
18856 |
|
18857 | var _proto = SourceUpdater.prototype;
|
18858 |
|
18859 | _proto.initializedEme = function initializedEme() {
|
18860 | this.initializedEme_ = true;
|
18861 | this.triggerReady();
|
18862 | };
|
18863 |
|
18864 | _proto.hasCreatedSourceBuffers = function hasCreatedSourceBuffers() {
|
18865 |
|
18866 |
|
18867 | return this.createdSourceBuffers_;
|
18868 | };
|
18869 |
|
18870 | _proto.hasInitializedAnyEme = function hasInitializedAnyEme() {
|
18871 | return this.initializedEme_;
|
18872 | };
|
18873 |
|
18874 | _proto.ready = function ready() {
|
18875 | return this.hasCreatedSourceBuffers() && this.hasInitializedAnyEme();
|
18876 | };
|
18877 |
|
18878 | _proto.createSourceBuffers = function createSourceBuffers(codecs) {
|
18879 | if (this.hasCreatedSourceBuffers()) {
|
18880 |
|
18881 | return;
|
18882 | }
|
18883 |
|
18884 |
|
18885 |
|
18886 | this.addOrChangeSourceBuffers(codecs);
|
18887 | this.createdSourceBuffers_ = true;
|
18888 | this.trigger('createdsourcebuffers');
|
18889 | this.triggerReady();
|
18890 | };
|
18891 |
|
18892 | _proto.triggerReady = function triggerReady() {
|
18893 |
|
18894 |
|
18895 |
|
18896 |
|
18897 |
|
18898 |
|
18899 | if (this.ready() && !this.triggeredReady_) {
|
18900 | this.triggeredReady_ = true;
|
18901 | this.trigger('ready');
|
18902 | }
|
18903 | }
|
18904 | |
18905 |
|
18906 |
|
18907 |
|
18908 |
|
18909 |
|
18910 |
|
18911 |
|
18912 |
|
18913 | ;
|
18914 |
|
18915 | _proto.addSourceBuffer = function addSourceBuffer(type, codec) {
|
18916 | pushQueue({
|
18917 | type: 'mediaSource',
|
18918 | sourceUpdater: this,
|
18919 | action: actions.addSourceBuffer(type, codec),
|
18920 | name: 'addSourceBuffer'
|
18921 | });
|
18922 | }
|
18923 | |
18924 |
|
18925 |
|
18926 |
|
18927 |
|
18928 |
|
18929 | ;
|
18930 |
|
18931 | _proto.abort = function abort(type) {
|
18932 | pushQueue({
|
18933 | type: type,
|
18934 | sourceUpdater: this,
|
18935 | action: actions.abort(type),
|
18936 | name: 'abort'
|
18937 | });
|
18938 | }
|
18939 | |
18940 |
|
18941 |
|
18942 |
|
18943 |
|
18944 |
|
18945 |
|
18946 | ;
|
18947 |
|
18948 | _proto.removeSourceBuffer = function removeSourceBuffer(type) {
|
18949 | if (!this.canRemoveSourceBuffer()) {
|
18950 | videojs__default["default"].log.error('removeSourceBuffer is not supported!');
|
18951 | return;
|
18952 | }
|
18953 |
|
18954 | pushQueue({
|
18955 | type: 'mediaSource',
|
18956 | sourceUpdater: this,
|
18957 | action: actions.removeSourceBuffer(type),
|
18958 | name: 'removeSourceBuffer'
|
18959 | });
|
18960 | }
|
18961 | |
18962 |
|
18963 |
|
18964 |
|
18965 |
|
18966 |
|
18967 |
|
18968 | ;
|
18969 |
|
18970 | _proto.canRemoveSourceBuffer = function canRemoveSourceBuffer() {
|
18971 |
|
18972 |
|
18973 |
|
18974 |
|
18975 | return !videojs__default["default"].browser.IE_VERSION && !videojs__default["default"].browser.IS_FIREFOX && window__default["default"].MediaSource && window__default["default"].MediaSource.prototype && typeof window__default["default"].MediaSource.prototype.removeSourceBuffer === 'function';
|
18976 | }
|
18977 | |
18978 |
|
18979 |
|
18980 |
|
18981 |
|
18982 |
|
18983 |
|
18984 | ;
|
18985 |
|
18986 | SourceUpdater.canChangeType = function canChangeType() {
|
18987 | return window__default["default"].SourceBuffer && window__default["default"].SourceBuffer.prototype && typeof window__default["default"].SourceBuffer.prototype.changeType === 'function';
|
18988 | }
|
18989 | |
18990 |
|
18991 |
|
18992 |
|
18993 |
|
18994 |
|
18995 |
|
18996 | ;
|
18997 |
|
18998 | _proto.canChangeType = function canChangeType() {
|
18999 | return this.constructor.canChangeType();
|
19000 | }
|
19001 | |
19002 |
|
19003 |
|
19004 |
|
19005 |
|
19006 |
|
19007 |
|
19008 |
|
19009 |
|
19010 | ;
|
19011 |
|
19012 | _proto.changeType = function changeType(type, codec) {
|
19013 | if (!this.canChangeType()) {
|
19014 | videojs__default["default"].log.error('changeType is not supported!');
|
19015 | return;
|
19016 | }
|
19017 |
|
19018 | pushQueue({
|
19019 | type: type,
|
19020 | sourceUpdater: this,
|
19021 | action: actions.changeType(codec),
|
19022 | name: 'changeType'
|
19023 | });
|
19024 | }
|
19025 | |
19026 |
|
19027 |
|
19028 |
|
19029 |
|
19030 |
|
19031 |
|
19032 | ;
|
19033 |
|
19034 | _proto.addOrChangeSourceBuffers = function addOrChangeSourceBuffers(codecs) {
|
19035 | var _this2 = this;
|
19036 |
|
19037 | if (!codecs || typeof codecs !== 'object' || Object.keys(codecs).length === 0) {
|
19038 | throw new Error('Cannot addOrChangeSourceBuffers to undefined codecs');
|
19039 | }
|
19040 |
|
19041 | Object.keys(codecs).forEach(function (type) {
|
19042 | var codec = codecs[type];
|
19043 |
|
19044 | if (!_this2.hasCreatedSourceBuffers()) {
|
19045 | return _this2.addSourceBuffer(type, codec);
|
19046 | }
|
19047 |
|
19048 | if (_this2.canChangeType()) {
|
19049 | _this2.changeType(type, codec);
|
19050 | }
|
19051 | });
|
19052 | }
|
19053 | |
19054 |
|
19055 |
|
19056 |
|
19057 |
|
19058 |
|
19059 |
|
19060 | ;
|
19061 |
|
19062 | _proto.appendBuffer = function appendBuffer(options, doneFn) {
|
19063 | var _this3 = this;
|
19064 |
|
19065 | var segmentInfo = options.segmentInfo,
|
19066 | type = options.type,
|
19067 | bytes = options.bytes;
|
19068 | this.processedAppend_ = true;
|
19069 |
|
19070 | if (type === 'audio' && this.videoBuffer && !this.videoAppendQueued_) {
|
19071 | this.delayedAudioAppendQueue_.push([options, doneFn]);
|
19072 | this.logger_("delayed audio append of " + bytes.length + " until video append");
|
19073 | return;
|
19074 | }
|
19075 |
|
19076 |
|
19077 |
|
19078 |
|
19079 |
|
19080 | var onError = doneFn;
|
19081 | pushQueue({
|
19082 | type: type,
|
19083 | sourceUpdater: this,
|
19084 | action: actions.appendBuffer(bytes, segmentInfo || {
|
19085 | mediaIndex: -1
|
19086 | }, onError),
|
19087 | doneFn: doneFn,
|
19088 | name: 'appendBuffer'
|
19089 | });
|
19090 |
|
19091 | if (type === 'video') {
|
19092 | this.videoAppendQueued_ = true;
|
19093 |
|
19094 | if (!this.delayedAudioAppendQueue_.length) {
|
19095 | return;
|
19096 | }
|
19097 |
|
19098 | var queue = this.delayedAudioAppendQueue_.slice();
|
19099 | this.logger_("queuing delayed audio " + queue.length + " appendBuffers");
|
19100 | this.delayedAudioAppendQueue_.length = 0;
|
19101 | queue.forEach(function (que) {
|
19102 | _this3.appendBuffer.apply(_this3, que);
|
19103 | });
|
19104 | }
|
19105 | }
|
19106 | |
19107 |
|
19108 |
|
19109 |
|
19110 |
|
19111 |
|
19112 | ;
|
19113 |
|
19114 | _proto.audioBuffered = function audioBuffered() {
|
19115 |
|
19116 |
|
19117 | if (!inSourceBuffers(this.mediaSource, this.audioBuffer)) {
|
19118 | return videojs__default["default"].createTimeRange();
|
19119 | }
|
19120 |
|
19121 | return this.audioBuffer.buffered ? this.audioBuffer.buffered : videojs__default["default"].createTimeRange();
|
19122 | }
|
19123 | |
19124 |
|
19125 |
|
19126 |
|
19127 |
|
19128 |
|
19129 | ;
|
19130 |
|
19131 | _proto.videoBuffered = function videoBuffered() {
|
19132 |
|
19133 |
|
19134 | if (!inSourceBuffers(this.mediaSource, this.videoBuffer)) {
|
19135 | return videojs__default["default"].createTimeRange();
|
19136 | }
|
19137 |
|
19138 | return this.videoBuffer.buffered ? this.videoBuffer.buffered : videojs__default["default"].createTimeRange();
|
19139 | }
|
19140 | |
19141 |
|
19142 |
|
19143 |
|
19144 |
|
19145 |
|
19146 | ;
|
19147 |
|
19148 | _proto.buffered = function buffered() {
|
19149 | var video = inSourceBuffers(this.mediaSource, this.videoBuffer) ? this.videoBuffer : null;
|
19150 | var audio = inSourceBuffers(this.mediaSource, this.audioBuffer) ? this.audioBuffer : null;
|
19151 |
|
19152 | if (audio && !video) {
|
19153 | return this.audioBuffered();
|
19154 | }
|
19155 |
|
19156 | if (video && !audio) {
|
19157 | return this.videoBuffered();
|
19158 | }
|
19159 |
|
19160 | return bufferIntersection(this.audioBuffered(), this.videoBuffered());
|
19161 | }
|
19162 | |
19163 |
|
19164 |
|
19165 |
|
19166 |
|
19167 |
|
19168 |
|
19169 |
|
19170 |
|
19171 | ;
|
19172 |
|
19173 | _proto.setDuration = function setDuration(duration, doneFn) {
|
19174 | if (doneFn === void 0) {
|
19175 | doneFn = noop;
|
19176 | }
|
19177 |
|
19178 |
|
19179 |
|
19180 |
|
19181 |
|
19182 | pushQueue({
|
19183 | type: 'mediaSource',
|
19184 | sourceUpdater: this,
|
19185 | action: actions.duration(duration),
|
19186 | name: 'duration',
|
19187 | doneFn: doneFn
|
19188 | });
|
19189 | }
|
19190 | |
19191 |
|
19192 |
|
19193 |
|
19194 |
|
19195 |
|
19196 |
|
19197 |
|
19198 |
|
19199 |
|
19200 | ;
|
19201 |
|
19202 | _proto.endOfStream = function endOfStream(error, doneFn) {
|
19203 | if (error === void 0) {
|
19204 | error = null;
|
19205 | }
|
19206 |
|
19207 | if (doneFn === void 0) {
|
19208 | doneFn = noop;
|
19209 | }
|
19210 |
|
19211 | if (typeof error !== 'string') {
|
19212 | error = undefined;
|
19213 | }
|
19214 |
|
19215 |
|
19216 |
|
19217 |
|
19218 |
|
19219 | pushQueue({
|
19220 | type: 'mediaSource',
|
19221 | sourceUpdater: this,
|
19222 | action: actions.endOfStream(error),
|
19223 | name: 'endOfStream',
|
19224 | doneFn: doneFn
|
19225 | });
|
19226 | }
|
19227 | |
19228 |
|
19229 |
|
19230 |
|
19231 |
|
19232 |
|
19233 |
|
19234 |
|
19235 |
|
19236 | ;
|
19237 |
|
19238 | _proto.removeAudio = function removeAudio(start, end, done) {
|
19239 | if (done === void 0) {
|
19240 | done = noop;
|
19241 | }
|
19242 |
|
19243 | if (!this.audioBuffered().length || this.audioBuffered().end(0) === 0) {
|
19244 | done();
|
19245 | return;
|
19246 | }
|
19247 |
|
19248 | pushQueue({
|
19249 | type: 'audio',
|
19250 | sourceUpdater: this,
|
19251 | action: actions.remove(start, end),
|
19252 | doneFn: done,
|
19253 | name: 'remove'
|
19254 | });
|
19255 | }
|
19256 | |
19257 |
|
19258 |
|
19259 |
|
19260 |
|
19261 |
|
19262 |
|
19263 |
|
19264 |
|
19265 | ;
|
19266 |
|
19267 | _proto.removeVideo = function removeVideo(start, end, done) {
|
19268 | if (done === void 0) {
|
19269 | done = noop;
|
19270 | }
|
19271 |
|
19272 | if (!this.videoBuffered().length || this.videoBuffered().end(0) === 0) {
|
19273 | done();
|
19274 | return;
|
19275 | }
|
19276 |
|
19277 | pushQueue({
|
19278 | type: 'video',
|
19279 | sourceUpdater: this,
|
19280 | action: actions.remove(start, end),
|
19281 | doneFn: done,
|
19282 | name: 'remove'
|
19283 | });
|
19284 | }
|
19285 | |
19286 |
|
19287 |
|
19288 |
|
19289 |
|
19290 | ;
|
19291 |
|
19292 | _proto.updating = function updating() {
|
19293 |
|
19294 | if (_updating('audio', this) || _updating('video', this)) {
|
19295 | return true;
|
19296 | }
|
19297 |
|
19298 | return false;
|
19299 | }
|
19300 | |
19301 |
|
19302 |
|
19303 |
|
19304 |
|
19305 | ;
|
19306 |
|
19307 | _proto.audioTimestampOffset = function audioTimestampOffset(offset) {
|
19308 | if (typeof offset !== 'undefined' && this.audioBuffer &&
|
19309 | this.audioTimestampOffset_ !== offset) {
|
19310 | pushQueue({
|
19311 | type: 'audio',
|
19312 | sourceUpdater: this,
|
19313 | action: actions.timestampOffset(offset),
|
19314 | name: 'timestampOffset'
|
19315 | });
|
19316 | this.audioTimestampOffset_ = offset;
|
19317 | }
|
19318 |
|
19319 | return this.audioTimestampOffset_;
|
19320 | }
|
19321 | |
19322 |
|
19323 |
|
19324 |
|
19325 |
|
19326 | ;
|
19327 |
|
19328 | _proto.videoTimestampOffset = function videoTimestampOffset(offset) {
|
19329 | if (typeof offset !== 'undefined' && this.videoBuffer &&
|
19330 | this.videoTimestampOffset !== offset) {
|
19331 | pushQueue({
|
19332 | type: 'video',
|
19333 | sourceUpdater: this,
|
19334 | action: actions.timestampOffset(offset),
|
19335 | name: 'timestampOffset'
|
19336 | });
|
19337 | this.videoTimestampOffset_ = offset;
|
19338 | }
|
19339 |
|
19340 | return this.videoTimestampOffset_;
|
19341 | }
|
19342 | |
19343 |
|
19344 |
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 | ;
|
19350 |
|
19351 | _proto.audioQueueCallback = function audioQueueCallback(callback) {
|
19352 | if (!this.audioBuffer) {
|
19353 | return;
|
19354 | }
|
19355 |
|
19356 | pushQueue({
|
19357 | type: 'audio',
|
19358 | sourceUpdater: this,
|
19359 | action: actions.callback(callback),
|
19360 | name: 'callback'
|
19361 | });
|
19362 | }
|
19363 | |
19364 |
|
19365 |
|
19366 |
|
19367 |
|
19368 |
|
19369 |
|
19370 | ;
|
19371 |
|
19372 | _proto.videoQueueCallback = function videoQueueCallback(callback) {
|
19373 | if (!this.videoBuffer) {
|
19374 | return;
|
19375 | }
|
19376 |
|
19377 | pushQueue({
|
19378 | type: 'video',
|
19379 | sourceUpdater: this,
|
19380 | action: actions.callback(callback),
|
19381 | name: 'callback'
|
19382 | });
|
19383 | }
|
19384 | |
19385 |
|
19386 |
|
19387 | ;
|
19388 |
|
19389 | _proto.dispose = function dispose() {
|
19390 | var _this4 = this;
|
19391 |
|
19392 | this.trigger('dispose');
|
19393 | bufferTypes.forEach(function (type) {
|
19394 | _this4.abort(type);
|
19395 |
|
19396 | if (_this4.canRemoveSourceBuffer()) {
|
19397 | _this4.removeSourceBuffer(type);
|
19398 | } else {
|
19399 | _this4[type + "QueueCallback"](function () {
|
19400 | return cleanupBuffer(type, _this4);
|
19401 | });
|
19402 | }
|
19403 | });
|
19404 | this.videoAppendQueued_ = false;
|
19405 | this.delayedAudioAppendQueue_.length = 0;
|
19406 |
|
19407 | if (this.sourceopenListener_) {
|
19408 | this.mediaSource.removeEventListener('sourceopen', this.sourceopenListener_);
|
19409 | }
|
19410 |
|
19411 | this.off();
|
19412 | };
|
19413 |
|
19414 | return SourceUpdater;
|
19415 | }(videojs__default["default"].EventTarget);
|
19416 |
|
19417 | var uint8ToUtf8 = function uint8ToUtf8(uintArray) {
|
19418 | return decodeURIComponent(escape(String.fromCharCode.apply(null, uintArray)));
|
19419 | };
|
19420 |
|
19421 | var VTT_LINE_TERMINATORS = new Uint8Array('\n\n'.split('').map(function (char) {
|
19422 | return char.charCodeAt(0);
|
19423 | }));
|
19424 |
|
19425 | var NoVttJsError = function (_Error) {
|
19426 | _inheritsLoose__default["default"](NoVttJsError, _Error);
|
19427 |
|
19428 | function NoVttJsError() {
|
19429 | return _Error.call(this, 'Trying to parse received VTT cues, but there is no WebVTT. Make sure vtt.js is loaded.') || this;
|
19430 | }
|
19431 |
|
19432 | return NoVttJsError;
|
19433 | }( _wrapNativeSuper__default["default"](Error));
|
19434 |
|
19435 |
|
19436 |
|
19437 |
|
19438 |
|
19439 |
|
19440 |
|
19441 |
|
19442 |
|
19443 | var VTTSegmentLoader = function (_SegmentLoader) {
|
19444 | _inheritsLoose__default["default"](VTTSegmentLoader, _SegmentLoader);
|
19445 |
|
19446 | function VTTSegmentLoader(settings, options) {
|
19447 | var _this;
|
19448 |
|
19449 | if (options === void 0) {
|
19450 | options = {};
|
19451 | }
|
19452 |
|
19453 | _this = _SegmentLoader.call(this, settings, options) || this;
|
19454 |
|
19455 |
|
19456 | _this.mediaSource_ = null;
|
19457 | _this.subtitlesTrack_ = null;
|
19458 | _this.loaderType_ = 'subtitle';
|
19459 | _this.featuresNativeTextTracks_ = settings.featuresNativeTextTracks;
|
19460 | _this.loadVttJs = settings.loadVttJs;
|
19461 |
|
19462 |
|
19463 | _this.shouldSaveSegmentTimingInfo_ = false;
|
19464 | return _this;
|
19465 | }
|
19466 |
|
19467 | var _proto = VTTSegmentLoader.prototype;
|
19468 |
|
19469 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
19470 |
|
19471 | return null;
|
19472 | }
|
19473 | |
19474 |
|
19475 |
|
19476 |
|
19477 |
|
19478 |
|
19479 | ;
|
19480 |
|
19481 | _proto.buffered_ = function buffered_() {
|
19482 | if (!this.subtitlesTrack_ || !this.subtitlesTrack_.cues || !this.subtitlesTrack_.cues.length) {
|
19483 | return videojs__default["default"].createTimeRanges();
|
19484 | }
|
19485 |
|
19486 | var cues = this.subtitlesTrack_.cues;
|
19487 | var start = cues[0].startTime;
|
19488 | var end = cues[cues.length - 1].startTime;
|
19489 | return videojs__default["default"].createTimeRanges([[start, end]]);
|
19490 | }
|
19491 | |
19492 |
|
19493 |
|
19494 |
|
19495 |
|
19496 |
|
19497 |
|
19498 |
|
19499 |
|
19500 |
|
19501 | ;
|
19502 |
|
19503 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
19504 | if (set === void 0) {
|
19505 | set = false;
|
19506 | }
|
19507 |
|
19508 | if (!map) {
|
19509 | return null;
|
19510 | }
|
19511 |
|
19512 | var id = initSegmentId(map);
|
19513 | var storedMap = this.initSegments_[id];
|
19514 |
|
19515 | if (set && !storedMap && map.bytes) {
|
19516 |
|
19517 |
|
19518 |
|
19519 |
|
19520 | var combinedByteLength = VTT_LINE_TERMINATORS.byteLength + map.bytes.byteLength;
|
19521 | var combinedSegment = new Uint8Array(combinedByteLength);
|
19522 | combinedSegment.set(map.bytes);
|
19523 | combinedSegment.set(VTT_LINE_TERMINATORS, map.bytes.byteLength);
|
19524 | this.initSegments_[id] = storedMap = {
|
19525 | resolvedUri: map.resolvedUri,
|
19526 | byterange: map.byterange,
|
19527 | bytes: combinedSegment
|
19528 | };
|
19529 | }
|
19530 |
|
19531 | return storedMap || map;
|
19532 | }
|
19533 | |
19534 |
|
19535 |
|
19536 |
|
19537 |
|
19538 |
|
19539 | ;
|
19540 |
|
19541 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
19542 | return this.playlist_ && this.subtitlesTrack_ && !this.paused();
|
19543 | }
|
19544 | |
19545 |
|
19546 |
|
19547 |
|
19548 |
|
19549 |
|
19550 |
|
19551 | ;
|
19552 |
|
19553 | _proto.init_ = function init_() {
|
19554 | this.state = 'READY';
|
19555 | this.resetEverything();
|
19556 | return this.monitorBuffer_();
|
19557 | }
|
19558 | |
19559 |
|
19560 |
|
19561 |
|
19562 |
|
19563 |
|
19564 |
|
19565 |
|
19566 | ;
|
19567 |
|
19568 | _proto.track = function track(_track) {
|
19569 | if (typeof _track === 'undefined') {
|
19570 | return this.subtitlesTrack_;
|
19571 | }
|
19572 |
|
19573 | this.subtitlesTrack_ = _track;
|
19574 |
|
19575 |
|
19576 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
19577 | this.init_();
|
19578 | }
|
19579 |
|
19580 | return this.subtitlesTrack_;
|
19581 | }
|
19582 | |
19583 |
|
19584 |
|
19585 |
|
19586 |
|
19587 |
|
19588 | ;
|
19589 |
|
19590 | _proto.remove = function remove(start, end) {
|
19591 | removeCuesFromTrack(start, end, this.subtitlesTrack_);
|
19592 | }
|
19593 | |
19594 |
|
19595 |
|
19596 |
|
19597 |
|
19598 |
|
19599 |
|
19600 |
|
19601 |
|
19602 | ;
|
19603 |
|
19604 | _proto.fillBuffer_ = function fillBuffer_() {
|
19605 | var _this2 = this;
|
19606 |
|
19607 |
|
19608 | var segmentInfo = this.chooseNextRequest_();
|
19609 |
|
19610 | if (!segmentInfo) {
|
19611 | return;
|
19612 | }
|
19613 |
|
19614 | if (this.syncController_.timestampOffsetForTimeline(segmentInfo.timeline) === null) {
|
19615 |
|
19616 |
|
19617 | var checkTimestampOffset = function checkTimestampOffset() {
|
19618 | _this2.state = 'READY';
|
19619 |
|
19620 | if (!_this2.paused()) {
|
19621 |
|
19622 | _this2.monitorBuffer_();
|
19623 | }
|
19624 | };
|
19625 |
|
19626 | this.syncController_.one('timestampoffset', checkTimestampOffset);
|
19627 | this.state = 'WAITING_ON_TIMELINE';
|
19628 | return;
|
19629 | }
|
19630 |
|
19631 | this.loadSegment_(segmentInfo);
|
19632 | }
|
19633 | ;
|
19634 |
|
19635 | _proto.timestampOffsetForSegment_ = function timestampOffsetForSegment_() {
|
19636 | return null;
|
19637 | };
|
19638 |
|
19639 | _proto.chooseNextRequest_ = function chooseNextRequest_() {
|
19640 | return this.skipEmptySegments_(_SegmentLoader.prototype.chooseNextRequest_.call(this));
|
19641 | }
|
19642 | |
19643 |
|
19644 |
|
19645 |
|
19646 |
|
19647 |
|
19648 |
|
19649 |
|
19650 |
|
19651 |
|
19652 | ;
|
19653 |
|
19654 | _proto.skipEmptySegments_ = function skipEmptySegments_(segmentInfo) {
|
19655 | while (segmentInfo && segmentInfo.segment.empty) {
|
19656 |
|
19657 | if (segmentInfo.mediaIndex + 1 >= segmentInfo.playlist.segments.length) {
|
19658 | segmentInfo = null;
|
19659 | break;
|
19660 | }
|
19661 |
|
19662 | segmentInfo = this.generateSegmentInfo_({
|
19663 | playlist: segmentInfo.playlist,
|
19664 | mediaIndex: segmentInfo.mediaIndex + 1,
|
19665 | startOfSegment: segmentInfo.startOfSegment + segmentInfo.duration,
|
19666 | isSyncRequest: segmentInfo.isSyncRequest
|
19667 | });
|
19668 | }
|
19669 |
|
19670 | return segmentInfo;
|
19671 | };
|
19672 |
|
19673 | _proto.stopForError = function stopForError(error) {
|
19674 | this.error(error);
|
19675 | this.state = 'READY';
|
19676 | this.pause();
|
19677 | this.trigger('error');
|
19678 | }
|
19679 | |
19680 |
|
19681 |
|
19682 |
|
19683 |
|
19684 | ;
|
19685 |
|
19686 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
19687 | var _this3 = this;
|
19688 |
|
19689 | if (!this.subtitlesTrack_) {
|
19690 | this.state = 'READY';
|
19691 | return;
|
19692 | }
|
19693 |
|
19694 | this.saveTransferStats_(simpleSegment.stats);
|
19695 |
|
19696 | if (!this.pendingSegment_) {
|
19697 | this.state = 'READY';
|
19698 | this.mediaRequestsAborted += 1;
|
19699 | return;
|
19700 | }
|
19701 |
|
19702 | if (error) {
|
19703 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
19704 | this.handleTimeout_();
|
19705 | }
|
19706 |
|
19707 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
19708 | this.mediaRequestsAborted += 1;
|
19709 | } else {
|
19710 | this.mediaRequestsErrored += 1;
|
19711 | }
|
19712 |
|
19713 | this.stopForError(error);
|
19714 | return;
|
19715 | }
|
19716 |
|
19717 | var segmentInfo = this.pendingSegment_;
|
19718 |
|
19719 |
|
19720 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
19721 |
|
19722 | if (simpleSegment.key) {
|
19723 | this.segmentKey(simpleSegment.key, true);
|
19724 | }
|
19725 |
|
19726 | this.state = 'APPENDING';
|
19727 |
|
19728 | this.trigger('appending');
|
19729 | var segment = segmentInfo.segment;
|
19730 |
|
19731 | if (segment.map) {
|
19732 | segment.map.bytes = simpleSegment.map.bytes;
|
19733 | }
|
19734 |
|
19735 | segmentInfo.bytes = simpleSegment.bytes;
|
19736 |
|
19737 | if (typeof window__default["default"].WebVTT !== 'function' && typeof this.loadVttJs === 'function') {
|
19738 | this.state = 'WAITING_ON_VTTJS';
|
19739 |
|
19740 |
|
19741 | this.loadVttJs().then(function () {
|
19742 | return _this3.segmentRequestFinished_(error, simpleSegment, result);
|
19743 | }, function () {
|
19744 | return _this3.stopForError({
|
19745 | message: 'Error loading vtt.js'
|
19746 | });
|
19747 | });
|
19748 | return;
|
19749 | }
|
19750 |
|
19751 | segment.requested = true;
|
19752 |
|
19753 | try {
|
19754 | this.parseVTTCues_(segmentInfo);
|
19755 | } catch (e) {
|
19756 | this.stopForError({
|
19757 | message: e.message
|
19758 | });
|
19759 | return;
|
19760 | }
|
19761 |
|
19762 | this.updateTimeMapping_(segmentInfo, this.syncController_.timelines[segmentInfo.timeline], this.playlist_);
|
19763 |
|
19764 | if (segmentInfo.cues.length) {
|
19765 | segmentInfo.timingInfo = {
|
19766 | start: segmentInfo.cues[0].startTime,
|
19767 | end: segmentInfo.cues[segmentInfo.cues.length - 1].endTime
|
19768 | };
|
19769 | } else {
|
19770 | segmentInfo.timingInfo = {
|
19771 | start: segmentInfo.startOfSegment,
|
19772 | end: segmentInfo.startOfSegment + segmentInfo.duration
|
19773 | };
|
19774 | }
|
19775 |
|
19776 | if (segmentInfo.isSyncRequest) {
|
19777 | this.trigger('syncinfoupdate');
|
19778 | this.pendingSegment_ = null;
|
19779 | this.state = 'READY';
|
19780 | return;
|
19781 | }
|
19782 |
|
19783 | segmentInfo.byteLength = segmentInfo.bytes.byteLength;
|
19784 | this.mediaSecondsLoaded += segment.duration;
|
19785 |
|
19786 |
|
19787 | segmentInfo.cues.forEach(function (cue) {
|
19788 | _this3.subtitlesTrack_.addCue(_this3.featuresNativeTextTracks_ ? new window__default["default"].VTTCue(cue.startTime, cue.endTime, cue.text) : cue);
|
19789 | });
|
19790 |
|
19791 |
|
19792 |
|
19793 |
|
19794 | removeDuplicateCuesFromTrack(this.subtitlesTrack_);
|
19795 | this.handleAppendsDone_();
|
19796 | };
|
19797 |
|
19798 | _proto.handleData_ = function handleData_() {
|
19799 |
|
19800 | };
|
19801 |
|
19802 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_() {
|
19803 | }
|
19804 | |
19805 |
|
19806 |
|
19807 |
|
19808 |
|
19809 |
|
19810 |
|
19811 |
|
19812 |
|
19813 | ;
|
19814 |
|
19815 | _proto.parseVTTCues_ = function parseVTTCues_(segmentInfo) {
|
19816 | var decoder;
|
19817 | var decodeBytesToString = false;
|
19818 |
|
19819 | if (typeof window__default["default"].WebVTT !== 'function') {
|
19820 |
|
19821 | throw new NoVttJsError();
|
19822 | }
|
19823 |
|
19824 | if (typeof window__default["default"].TextDecoder === 'function') {
|
19825 | decoder = new window__default["default"].TextDecoder('utf8');
|
19826 | } else {
|
19827 | decoder = window__default["default"].WebVTT.StringDecoder();
|
19828 | decodeBytesToString = true;
|
19829 | }
|
19830 |
|
19831 | var parser = new window__default["default"].WebVTT.Parser(window__default["default"], window__default["default"].vttjs, decoder);
|
19832 | segmentInfo.cues = [];
|
19833 | segmentInfo.timestampmap = {
|
19834 | MPEGTS: 0,
|
19835 | LOCAL: 0
|
19836 | };
|
19837 | parser.oncue = segmentInfo.cues.push.bind(segmentInfo.cues);
|
19838 |
|
19839 | parser.ontimestampmap = function (map) {
|
19840 | segmentInfo.timestampmap = map;
|
19841 | };
|
19842 |
|
19843 | parser.onparsingerror = function (error) {
|
19844 | videojs__default["default"].log.warn('Error encountered when parsing cues: ' + error.message);
|
19845 | };
|
19846 |
|
19847 | if (segmentInfo.segment.map) {
|
19848 | var mapData = segmentInfo.segment.map.bytes;
|
19849 |
|
19850 | if (decodeBytesToString) {
|
19851 | mapData = uint8ToUtf8(mapData);
|
19852 | }
|
19853 |
|
19854 | parser.parse(mapData);
|
19855 | }
|
19856 |
|
19857 | var segmentData = segmentInfo.bytes;
|
19858 |
|
19859 | if (decodeBytesToString) {
|
19860 | segmentData = uint8ToUtf8(segmentData);
|
19861 | }
|
19862 |
|
19863 | parser.parse(segmentData);
|
19864 | parser.flush();
|
19865 | }
|
19866 | |
19867 |
|
19868 |
|
19869 |
|
19870 |
|
19871 |
|
19872 |
|
19873 |
|
19874 |
|
19875 |
|
19876 |
|
19877 |
|
19878 |
|
19879 | ;
|
19880 |
|
19881 | _proto.updateTimeMapping_ = function updateTimeMapping_(segmentInfo, mappingObj, playlist) {
|
19882 | var segment = segmentInfo.segment;
|
19883 |
|
19884 | if (!mappingObj) {
|
19885 |
|
19886 |
|
19887 |
|
19888 | return;
|
19889 | }
|
19890 |
|
19891 | if (!segmentInfo.cues.length) {
|
19892 |
|
19893 |
|
19894 |
|
19895 | segment.empty = true;
|
19896 | return;
|
19897 | }
|
19898 |
|
19899 | var timestampmap = segmentInfo.timestampmap;
|
19900 | var diff = timestampmap.MPEGTS / clock.ONE_SECOND_IN_TS - timestampmap.LOCAL + mappingObj.mapping;
|
19901 | segmentInfo.cues.forEach(function (cue) {
|
19902 |
|
19903 | cue.startTime += diff;
|
19904 | cue.endTime += diff;
|
19905 | });
|
19906 |
|
19907 | if (!playlist.syncInfo) {
|
19908 | var firstStart = segmentInfo.cues[0].startTime;
|
19909 | var lastStart = segmentInfo.cues[segmentInfo.cues.length - 1].startTime;
|
19910 | playlist.syncInfo = {
|
19911 | mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
|
19912 | time: Math.min(firstStart, lastStart - segment.duration)
|
19913 | };
|
19914 | }
|
19915 | };
|
19916 |
|
19917 | return VTTSegmentLoader;
|
19918 | }(SegmentLoader);
|
19919 |
|
19920 |
|
19921 |
|
19922 |
|
19923 |
|
19924 |
|
19925 |
|
19926 |
|
19927 |
|
19928 |
|
19929 |
|
19930 |
|
19931 |
|
19932 |
|
19933 |
|
19934 |
|
19935 |
|
19936 | var findAdCue = function findAdCue(track, mediaTime) {
|
19937 | var cues = track.cues;
|
19938 |
|
19939 | for (var i = 0; i < cues.length; i++) {
|
19940 | var cue = cues[i];
|
19941 |
|
19942 | if (mediaTime >= cue.adStartTime && mediaTime <= cue.adEndTime) {
|
19943 | return cue;
|
19944 | }
|
19945 | }
|
19946 |
|
19947 | return null;
|
19948 | };
|
19949 | var updateAdCues = function updateAdCues(media, track, offset) {
|
19950 | if (offset === void 0) {
|
19951 | offset = 0;
|
19952 | }
|
19953 |
|
19954 | if (!media.segments) {
|
19955 | return;
|
19956 | }
|
19957 |
|
19958 | var mediaTime = offset;
|
19959 | var cue;
|
19960 |
|
19961 | for (var i = 0; i < media.segments.length; i++) {
|
19962 | var segment = media.segments[i];
|
19963 |
|
19964 | if (!cue) {
|
19965 |
|
19966 |
|
19967 |
|
19968 |
|
19969 | cue = findAdCue(track, mediaTime + segment.duration / 2);
|
19970 | }
|
19971 |
|
19972 | if (cue) {
|
19973 | if ('cueIn' in segment) {
|
19974 |
|
19975 | cue.endTime = mediaTime;
|
19976 | cue.adEndTime = mediaTime;
|
19977 | mediaTime += segment.duration;
|
19978 | cue = null;
|
19979 | continue;
|
19980 | }
|
19981 |
|
19982 | if (mediaTime < cue.endTime) {
|
19983 |
|
19984 | mediaTime += segment.duration;
|
19985 | continue;
|
19986 | }
|
19987 |
|
19988 |
|
19989 | cue.endTime += segment.duration;
|
19990 | } else {
|
19991 | if ('cueOut' in segment) {
|
19992 | cue = new window__default["default"].VTTCue(mediaTime, mediaTime + segment.duration, segment.cueOut);
|
19993 | cue.adStartTime = mediaTime;
|
19994 |
|
19995 |
|
19996 | cue.adEndTime = mediaTime + parseFloat(segment.cueOut);
|
19997 | track.addCue(cue);
|
19998 | }
|
19999 |
|
20000 | if ('cueOutCont' in segment) {
|
20001 |
|
20002 |
|
20003 |
|
20004 | var _segment$cueOutCont$s = segment.cueOutCont.split('/').map(parseFloat),
|
20005 | adOffset = _segment$cueOutCont$s[0],
|
20006 | adTotal = _segment$cueOutCont$s[1];
|
20007 |
|
20008 | cue = new window__default["default"].VTTCue(mediaTime, mediaTime + segment.duration, '');
|
20009 | cue.adStartTime = mediaTime - adOffset;
|
20010 | cue.adEndTime = cue.adStartTime + adTotal;
|
20011 | track.addCue(cue);
|
20012 | }
|
20013 | }
|
20014 |
|
20015 | mediaTime += segment.duration;
|
20016 | }
|
20017 | };
|
20018 |
|
20019 |
|
20020 |
|
20021 |
|
20022 |
|
20023 |
|
20024 | var MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC = 86400;
|
20025 | var syncPointStrategies = [
|
20026 |
|
20027 | {
|
20028 | name: 'VOD',
|
20029 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
20030 | if (duration !== Infinity) {
|
20031 | var syncPoint = {
|
20032 | time: 0,
|
20033 | segmentIndex: 0,
|
20034 | partIndex: null
|
20035 | };
|
20036 | return syncPoint;
|
20037 | }
|
20038 |
|
20039 | return null;
|
20040 | }
|
20041 | },
|
20042 | {
|
20043 | name: 'ProgramDateTime',
|
20044 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
20045 | if (!Object.keys(syncController.timelineToDatetimeMappings).length) {
|
20046 | return null;
|
20047 | }
|
20048 |
|
20049 | var syncPoint = null;
|
20050 | var lastDistance = null;
|
20051 | var partsAndSegments = getPartsAndSegments(playlist);
|
20052 | currentTime = currentTime || 0;
|
20053 |
|
20054 | for (var i = 0; i < partsAndSegments.length; i++) {
|
20055 |
|
20056 |
|
20057 | var index = playlist.endList || currentTime === 0 ? i : partsAndSegments.length - (i + 1);
|
20058 | var partAndSegment = partsAndSegments[index];
|
20059 | var segment = partAndSegment.segment;
|
20060 | var datetimeMapping = syncController.timelineToDatetimeMappings[segment.timeline];
|
20061 |
|
20062 | if (!datetimeMapping || !segment.dateTimeObject) {
|
20063 | continue;
|
20064 | }
|
20065 |
|
20066 | var segmentTime = segment.dateTimeObject.getTime() / 1000;
|
20067 | var start = segmentTime + datetimeMapping;
|
20068 |
|
20069 | if (segment.parts && typeof partAndSegment.partIndex === 'number') {
|
20070 | for (var z = 0; z < partAndSegment.partIndex; z++) {
|
20071 | start += segment.parts[z].duration;
|
20072 | }
|
20073 | }
|
20074 |
|
20075 | var distance = Math.abs(currentTime - start);
|
20076 |
|
20077 |
|
20078 | if (lastDistance !== null && (distance === 0 || lastDistance < distance)) {
|
20079 | break;
|
20080 | }
|
20081 |
|
20082 | lastDistance = distance;
|
20083 | syncPoint = {
|
20084 | time: start,
|
20085 | segmentIndex: partAndSegment.segmentIndex,
|
20086 | partIndex: partAndSegment.partIndex
|
20087 | };
|
20088 | }
|
20089 |
|
20090 | return syncPoint;
|
20091 | }
|
20092 | },
|
20093 |
|
20094 | {
|
20095 | name: 'Segment',
|
20096 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
20097 | var syncPoint = null;
|
20098 | var lastDistance = null;
|
20099 | currentTime = currentTime || 0;
|
20100 | var partsAndSegments = getPartsAndSegments(playlist);
|
20101 |
|
20102 | for (var i = 0; i < partsAndSegments.length; i++) {
|
20103 |
|
20104 |
|
20105 | var index = playlist.endList || currentTime === 0 ? i : partsAndSegments.length - (i + 1);
|
20106 | var partAndSegment = partsAndSegments[index];
|
20107 | var segment = partAndSegment.segment;
|
20108 | var start = partAndSegment.part && partAndSegment.part.start || segment && segment.start;
|
20109 |
|
20110 | if (segment.timeline === currentTimeline && typeof start !== 'undefined') {
|
20111 | var distance = Math.abs(currentTime - start);
|
20112 |
|
20113 |
|
20114 | if (lastDistance !== null && lastDistance < distance) {
|
20115 | break;
|
20116 | }
|
20117 |
|
20118 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
20119 | lastDistance = distance;
|
20120 | syncPoint = {
|
20121 | time: start,
|
20122 | segmentIndex: partAndSegment.segmentIndex,
|
20123 | partIndex: partAndSegment.partIndex
|
20124 | };
|
20125 | }
|
20126 | }
|
20127 | }
|
20128 |
|
20129 | return syncPoint;
|
20130 | }
|
20131 | },
|
20132 |
|
20133 | {
|
20134 | name: 'Discontinuity',
|
20135 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
20136 | var syncPoint = null;
|
20137 | currentTime = currentTime || 0;
|
20138 |
|
20139 | if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
20140 | var lastDistance = null;
|
20141 |
|
20142 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
20143 | var segmentIndex = playlist.discontinuityStarts[i];
|
20144 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
20145 | var discontinuitySync = syncController.discontinuities[discontinuity];
|
20146 |
|
20147 | if (discontinuitySync) {
|
20148 | var distance = Math.abs(currentTime - discontinuitySync.time);
|
20149 |
|
20150 |
|
20151 | if (lastDistance !== null && lastDistance < distance) {
|
20152 | break;
|
20153 | }
|
20154 |
|
20155 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
20156 | lastDistance = distance;
|
20157 | syncPoint = {
|
20158 | time: discontinuitySync.time,
|
20159 | segmentIndex: segmentIndex,
|
20160 | partIndex: null
|
20161 | };
|
20162 | }
|
20163 | }
|
20164 | }
|
20165 | }
|
20166 |
|
20167 | return syncPoint;
|
20168 | }
|
20169 | },
|
20170 |
|
20171 | {
|
20172 | name: 'Playlist',
|
20173 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
20174 | if (playlist.syncInfo) {
|
20175 | var syncPoint = {
|
20176 | time: playlist.syncInfo.time,
|
20177 | segmentIndex: playlist.syncInfo.mediaSequence - playlist.mediaSequence,
|
20178 | partIndex: null
|
20179 | };
|
20180 | return syncPoint;
|
20181 | }
|
20182 |
|
20183 | return null;
|
20184 | }
|
20185 | }];
|
20186 |
|
20187 | var SyncController = function (_videojs$EventTarget) {
|
20188 | _inheritsLoose__default["default"](SyncController, _videojs$EventTarget);
|
20189 |
|
20190 | function SyncController(options) {
|
20191 | var _this;
|
20192 |
|
20193 | _this = _videojs$EventTarget.call(this) || this;
|
20194 |
|
20195 | _this.timelines = [];
|
20196 | _this.discontinuities = [];
|
20197 | _this.timelineToDatetimeMappings = {};
|
20198 | _this.logger_ = logger('SyncController');
|
20199 | return _this;
|
20200 | }
|
20201 | |
20202 |
|
20203 |
|
20204 |
|
20205 |
|
20206 |
|
20207 |
|
20208 |
|
20209 |
|
20210 |
|
20211 |
|
20212 |
|
20213 |
|
20214 |
|
20215 |
|
20216 |
|
20217 |
|
20218 | var _proto = SyncController.prototype;
|
20219 |
|
20220 | _proto.getSyncPoint = function getSyncPoint(playlist, duration, currentTimeline, currentTime) {
|
20221 | var syncPoints = this.runStrategies_(playlist, duration, currentTimeline, currentTime);
|
20222 |
|
20223 | if (!syncPoints.length) {
|
20224 |
|
20225 |
|
20226 |
|
20227 | return null;
|
20228 | }
|
20229 |
|
20230 |
|
20231 |
|
20232 |
|
20233 | return this.selectSyncPoint_(syncPoints, {
|
20234 | key: 'time',
|
20235 | value: currentTime
|
20236 | });
|
20237 | }
|
20238 | |
20239 |
|
20240 |
|
20241 |
|
20242 |
|
20243 |
|
20244 |
|
20245 |
|
20246 |
|
20247 |
|
20248 |
|
20249 | ;
|
20250 |
|
20251 | _proto.getExpiredTime = function getExpiredTime(playlist, duration) {
|
20252 | if (!playlist || !playlist.segments) {
|
20253 | return null;
|
20254 | }
|
20255 |
|
20256 | var syncPoints = this.runStrategies_(playlist, duration, playlist.discontinuitySequence, 0);
|
20257 |
|
20258 | if (!syncPoints.length) {
|
20259 | return null;
|
20260 | }
|
20261 |
|
20262 | var syncPoint = this.selectSyncPoint_(syncPoints, {
|
20263 | key: 'segmentIndex',
|
20264 | value: 0
|
20265 | });
|
20266 |
|
20267 |
|
20268 | if (syncPoint.segmentIndex > 0) {
|
20269 | syncPoint.time *= -1;
|
20270 | }
|
20271 |
|
20272 | return Math.abs(syncPoint.time + sumDurations({
|
20273 | defaultDuration: playlist.targetDuration,
|
20274 | durationList: playlist.segments,
|
20275 | startIndex: syncPoint.segmentIndex,
|
20276 | endIndex: 0
|
20277 | }));
|
20278 | }
|
20279 | |
20280 |
|
20281 |
|
20282 |
|
20283 |
|
20284 |
|
20285 |
|
20286 |
|
20287 |
|
20288 |
|
20289 |
|
20290 |
|
20291 |
|
20292 |
|
20293 | ;
|
20294 |
|
20295 | _proto.runStrategies_ = function runStrategies_(playlist, duration, currentTimeline, currentTime) {
|
20296 | var syncPoints = [];
|
20297 |
|
20298 | for (var i = 0; i < syncPointStrategies.length; i++) {
|
20299 | var strategy = syncPointStrategies[i];
|
20300 | var syncPoint = strategy.run(this, playlist, duration, currentTimeline, currentTime);
|
20301 |
|
20302 | if (syncPoint) {
|
20303 | syncPoint.strategy = strategy.name;
|
20304 | syncPoints.push({
|
20305 | strategy: strategy.name,
|
20306 | syncPoint: syncPoint
|
20307 | });
|
20308 | }
|
20309 | }
|
20310 |
|
20311 | return syncPoints;
|
20312 | }
|
20313 | |
20314 |
|
20315 |
|
20316 |
|
20317 |
|
20318 |
|
20319 |
|
20320 |
|
20321 |
|
20322 |
|
20323 |
|
20324 |
|
20325 |
|
20326 |
|
20327 |
|
20328 | ;
|
20329 |
|
20330 | _proto.selectSyncPoint_ = function selectSyncPoint_(syncPoints, target) {
|
20331 | var bestSyncPoint = syncPoints[0].syncPoint;
|
20332 | var bestDistance = Math.abs(syncPoints[0].syncPoint[target.key] - target.value);
|
20333 | var bestStrategy = syncPoints[0].strategy;
|
20334 |
|
20335 | for (var i = 1; i < syncPoints.length; i++) {
|
20336 | var newDistance = Math.abs(syncPoints[i].syncPoint[target.key] - target.value);
|
20337 |
|
20338 | if (newDistance < bestDistance) {
|
20339 | bestDistance = newDistance;
|
20340 | bestSyncPoint = syncPoints[i].syncPoint;
|
20341 | bestStrategy = syncPoints[i].strategy;
|
20342 | }
|
20343 | }
|
20344 |
|
20345 | 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 : '') + ']');
|
20346 | return bestSyncPoint;
|
20347 | }
|
20348 | |
20349 |
|
20350 |
|
20351 |
|
20352 |
|
20353 |
|
20354 |
|
20355 |
|
20356 | ;
|
20357 |
|
20358 | _proto.saveExpiredSegmentInfo = function saveExpiredSegmentInfo(oldPlaylist, newPlaylist) {
|
20359 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
20360 |
|
20361 | if (mediaSequenceDiff > MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC) {
|
20362 | videojs__default["default"].log.warn("Not saving expired segment info. Media sequence gap " + mediaSequenceDiff + " is too large.");
|
20363 | return;
|
20364 | }
|
20365 |
|
20366 |
|
20367 |
|
20368 | for (var i = mediaSequenceDiff - 1; i >= 0; i--) {
|
20369 | var lastRemovedSegment = oldPlaylist.segments[i];
|
20370 |
|
20371 | if (lastRemovedSegment && typeof lastRemovedSegment.start !== 'undefined') {
|
20372 | newPlaylist.syncInfo = {
|
20373 | mediaSequence: oldPlaylist.mediaSequence + i,
|
20374 | time: lastRemovedSegment.start
|
20375 | };
|
20376 | this.logger_("playlist refresh sync: [time:" + newPlaylist.syncInfo.time + "," + (" mediaSequence: " + newPlaylist.syncInfo.mediaSequence + "]"));
|
20377 | this.trigger('syncinfoupdate');
|
20378 | break;
|
20379 | }
|
20380 | }
|
20381 | }
|
20382 | |
20383 |
|
20384 |
|
20385 |
|
20386 |
|
20387 |
|
20388 | ;
|
20389 |
|
20390 | _proto.setDateTimeMappingForStart = function setDateTimeMappingForStart(playlist) {
|
20391 |
|
20392 |
|
20393 |
|
20394 |
|
20395 | this.timelineToDatetimeMappings = {};
|
20396 |
|
20397 | if (playlist.segments && playlist.segments.length && playlist.segments[0].dateTimeObject) {
|
20398 | var firstSegment = playlist.segments[0];
|
20399 | var playlistTimestamp = firstSegment.dateTimeObject.getTime() / 1000;
|
20400 | this.timelineToDatetimeMappings[firstSegment.timeline] = -playlistTimestamp;
|
20401 | }
|
20402 | }
|
20403 | |
20404 |
|
20405 |
|
20406 |
|
20407 |
|
20408 |
|
20409 |
|
20410 |
|
20411 |
|
20412 |
|
20413 |
|
20414 |
|
20415 | ;
|
20416 |
|
20417 | _proto.saveSegmentTimingInfo = function saveSegmentTimingInfo(_ref) {
|
20418 | var segmentInfo = _ref.segmentInfo,
|
20419 | shouldSaveTimelineMapping = _ref.shouldSaveTimelineMapping;
|
20420 | var didCalculateSegmentTimeMapping = this.calculateSegmentTimeMapping_(segmentInfo, segmentInfo.timingInfo, shouldSaveTimelineMapping);
|
20421 | var segment = segmentInfo.segment;
|
20422 |
|
20423 | if (didCalculateSegmentTimeMapping) {
|
20424 | this.saveDiscontinuitySyncInfo_(segmentInfo);
|
20425 |
|
20426 |
|
20427 | if (!segmentInfo.playlist.syncInfo) {
|
20428 | segmentInfo.playlist.syncInfo = {
|
20429 | mediaSequence: segmentInfo.playlist.mediaSequence + segmentInfo.mediaIndex,
|
20430 | time: segment.start
|
20431 | };
|
20432 | }
|
20433 | }
|
20434 |
|
20435 | var dateTime = segment.dateTimeObject;
|
20436 |
|
20437 | if (segment.discontinuity && shouldSaveTimelineMapping && dateTime) {
|
20438 | this.timelineToDatetimeMappings[segment.timeline] = -(dateTime.getTime() / 1000);
|
20439 | }
|
20440 | };
|
20441 |
|
20442 | _proto.timestampOffsetForTimeline = function timestampOffsetForTimeline(timeline) {
|
20443 | if (typeof this.timelines[timeline] === 'undefined') {
|
20444 | return null;
|
20445 | }
|
20446 |
|
20447 | return this.timelines[timeline].time;
|
20448 | };
|
20449 |
|
20450 | _proto.mappingForTimeline = function mappingForTimeline(timeline) {
|
20451 | if (typeof this.timelines[timeline] === 'undefined') {
|
20452 | return null;
|
20453 | }
|
20454 |
|
20455 | return this.timelines[timeline].mapping;
|
20456 | }
|
20457 | |
20458 |
|
20459 |
|
20460 |
|
20461 |
|
20462 |
|
20463 |
|
20464 |
|
20465 |
|
20466 |
|
20467 |
|
20468 |
|
20469 |
|
20470 |
|
20471 |
|
20472 | ;
|
20473 |
|
20474 | _proto.calculateSegmentTimeMapping_ = function calculateSegmentTimeMapping_(segmentInfo, timingInfo, shouldSaveTimelineMapping) {
|
20475 |
|
20476 | var segment = segmentInfo.segment;
|
20477 | var part = segmentInfo.part;
|
20478 | var mappingObj = this.timelines[segmentInfo.timeline];
|
20479 | var start;
|
20480 | var end;
|
20481 |
|
20482 | if (typeof segmentInfo.timestampOffset === 'number') {
|
20483 | mappingObj = {
|
20484 | time: segmentInfo.startOfSegment,
|
20485 | mapping: segmentInfo.startOfSegment - timingInfo.start
|
20486 | };
|
20487 |
|
20488 | if (shouldSaveTimelineMapping) {
|
20489 | this.timelines[segmentInfo.timeline] = mappingObj;
|
20490 | this.trigger('timestampoffset');
|
20491 | this.logger_("time mapping for timeline " + segmentInfo.timeline + ": " + ("[time: " + mappingObj.time + "] [mapping: " + mappingObj.mapping + "]"));
|
20492 | }
|
20493 |
|
20494 | start = segmentInfo.startOfSegment;
|
20495 | end = timingInfo.end + mappingObj.mapping;
|
20496 | } else if (mappingObj) {
|
20497 | start = timingInfo.start + mappingObj.mapping;
|
20498 | end = timingInfo.end + mappingObj.mapping;
|
20499 | } else {
|
20500 | return false;
|
20501 | }
|
20502 |
|
20503 | if (part) {
|
20504 | part.start = start;
|
20505 | part.end = end;
|
20506 | }
|
20507 |
|
20508 |
|
20509 |
|
20510 |
|
20511 |
|
20512 |
|
20513 | if (!segment.start || start < segment.start) {
|
20514 | segment.start = start;
|
20515 | }
|
20516 |
|
20517 | segment.end = end;
|
20518 | return true;
|
20519 | }
|
20520 | |
20521 |
|
20522 |
|
20523 |
|
20524 |
|
20525 |
|
20526 |
|
20527 |
|
20528 | ;
|
20529 |
|
20530 | _proto.saveDiscontinuitySyncInfo_ = function saveDiscontinuitySyncInfo_(segmentInfo) {
|
20531 | var playlist = segmentInfo.playlist;
|
20532 | var segment = segmentInfo.segment;
|
20533 |
|
20534 |
|
20535 |
|
20536 | if (segment.discontinuity) {
|
20537 | this.discontinuities[segment.timeline] = {
|
20538 | time: segment.start,
|
20539 | accuracy: 0
|
20540 | };
|
20541 | } else if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
20542 |
|
20543 |
|
20544 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
20545 | var segmentIndex = playlist.discontinuityStarts[i];
|
20546 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
20547 | var mediaIndexDiff = segmentIndex - segmentInfo.mediaIndex;
|
20548 | var accuracy = Math.abs(mediaIndexDiff);
|
20549 |
|
20550 | if (!this.discontinuities[discontinuity] || this.discontinuities[discontinuity].accuracy > accuracy) {
|
20551 | var time = void 0;
|
20552 |
|
20553 | if (mediaIndexDiff < 0) {
|
20554 | time = segment.start - sumDurations({
|
20555 | defaultDuration: playlist.targetDuration,
|
20556 | durationList: playlist.segments,
|
20557 | startIndex: segmentInfo.mediaIndex,
|
20558 | endIndex: segmentIndex
|
20559 | });
|
20560 | } else {
|
20561 | time = segment.end + sumDurations({
|
20562 | defaultDuration: playlist.targetDuration,
|
20563 | durationList: playlist.segments,
|
20564 | startIndex: segmentInfo.mediaIndex + 1,
|
20565 | endIndex: segmentIndex
|
20566 | });
|
20567 | }
|
20568 |
|
20569 | this.discontinuities[discontinuity] = {
|
20570 | time: time,
|
20571 | accuracy: accuracy
|
20572 | };
|
20573 | }
|
20574 | }
|
20575 | }
|
20576 | };
|
20577 |
|
20578 | _proto.dispose = function dispose() {
|
20579 | this.trigger('dispose');
|
20580 | this.off();
|
20581 | };
|
20582 |
|
20583 | return SyncController;
|
20584 | }(videojs__default["default"].EventTarget);
|
20585 |
|
20586 |
|
20587 |
|
20588 |
|
20589 |
|
20590 |
|
20591 |
|
20592 |
|
20593 |
|
20594 |
|
20595 |
|
20596 | var TimelineChangeController = function (_videojs$EventTarget) {
|
20597 | _inheritsLoose__default["default"](TimelineChangeController, _videojs$EventTarget);
|
20598 |
|
20599 | function TimelineChangeController() {
|
20600 | var _this;
|
20601 |
|
20602 | _this = _videojs$EventTarget.call(this) || this;
|
20603 | _this.pendingTimelineChanges_ = {};
|
20604 | _this.lastTimelineChanges_ = {};
|
20605 | return _this;
|
20606 | }
|
20607 |
|
20608 | var _proto = TimelineChangeController.prototype;
|
20609 |
|
20610 | _proto.clearPendingTimelineChange = function clearPendingTimelineChange(type) {
|
20611 | this.pendingTimelineChanges_[type] = null;
|
20612 | this.trigger('pendingtimelinechange');
|
20613 | };
|
20614 |
|
20615 | _proto.pendingTimelineChange = function pendingTimelineChange(_ref) {
|
20616 | var type = _ref.type,
|
20617 | from = _ref.from,
|
20618 | to = _ref.to;
|
20619 |
|
20620 | if (typeof from === 'number' && typeof to === 'number') {
|
20621 | this.pendingTimelineChanges_[type] = {
|
20622 | type: type,
|
20623 | from: from,
|
20624 | to: to
|
20625 | };
|
20626 | this.trigger('pendingtimelinechange');
|
20627 | }
|
20628 |
|
20629 | return this.pendingTimelineChanges_[type];
|
20630 | };
|
20631 |
|
20632 | _proto.lastTimelineChange = function lastTimelineChange(_ref2) {
|
20633 | var type = _ref2.type,
|
20634 | from = _ref2.from,
|
20635 | to = _ref2.to;
|
20636 |
|
20637 | if (typeof from === 'number' && typeof to === 'number') {
|
20638 | this.lastTimelineChanges_[type] = {
|
20639 | type: type,
|
20640 | from: from,
|
20641 | to: to
|
20642 | };
|
20643 | delete this.pendingTimelineChanges_[type];
|
20644 | this.trigger('timelinechange');
|
20645 | }
|
20646 |
|
20647 | return this.lastTimelineChanges_[type];
|
20648 | };
|
20649 |
|
20650 | _proto.dispose = function dispose() {
|
20651 | this.trigger('dispose');
|
20652 | this.pendingTimelineChanges_ = {};
|
20653 | this.lastTimelineChanges_ = {};
|
20654 | this.off();
|
20655 | };
|
20656 |
|
20657 | return TimelineChangeController;
|
20658 | }(videojs__default["default"].EventTarget);
|
20659 |
|
20660 |
|
20661 | var workerCode = transform(getWorkerString(function () {
|
20662 |
|
20663 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
20664 |
|
20665 | function createCommonjsModule(fn, basedir, module) {
|
20666 | return module = {
|
20667 | path: basedir,
|
20668 | exports: {},
|
20669 | require: function require(path, base) {
|
20670 | return commonjsRequire(path, base === undefined || base === null ? module.path : base);
|
20671 | }
|
20672 | }, fn(module, module.exports), module.exports;
|
20673 | }
|
20674 |
|
20675 | function commonjsRequire() {
|
20676 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
20677 | }
|
20678 |
|
20679 | var createClass = createCommonjsModule(function (module) {
|
20680 | function _defineProperties(target, props) {
|
20681 | for (var i = 0; i < props.length; i++) {
|
20682 | var descriptor = props[i];
|
20683 | descriptor.enumerable = descriptor.enumerable || false;
|
20684 | descriptor.configurable = true;
|
20685 | if ("value" in descriptor) descriptor.writable = true;
|
20686 | Object.defineProperty(target, descriptor.key, descriptor);
|
20687 | }
|
20688 | }
|
20689 |
|
20690 | function _createClass(Constructor, protoProps, staticProps) {
|
20691 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
20692 | if (staticProps) _defineProperties(Constructor, staticProps);
|
20693 | return Constructor;
|
20694 | }
|
20695 |
|
20696 | module.exports = _createClass;
|
20697 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20698 | });
|
20699 | var setPrototypeOf = createCommonjsModule(function (module) {
|
20700 | function _setPrototypeOf(o, p) {
|
20701 | module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
20702 | o.__proto__ = p;
|
20703 | return o;
|
20704 | };
|
20705 |
|
20706 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20707 | return _setPrototypeOf(o, p);
|
20708 | }
|
20709 |
|
20710 | module.exports = _setPrototypeOf;
|
20711 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20712 | });
|
20713 | var inheritsLoose = createCommonjsModule(function (module) {
|
20714 | function _inheritsLoose(subClass, superClass) {
|
20715 | subClass.prototype = Object.create(superClass.prototype);
|
20716 | subClass.prototype.constructor = subClass;
|
20717 | setPrototypeOf(subClass, superClass);
|
20718 | }
|
20719 |
|
20720 | module.exports = _inheritsLoose;
|
20721 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20722 | });
|
20723 | |
20724 |
|
20725 |
|
20726 |
|
20727 | |
20728 |
|
20729 |
|
20730 |
|
20731 |
|
20732 |
|
20733 | var Stream = function () {
|
20734 | function Stream() {
|
20735 | this.listeners = {};
|
20736 | }
|
20737 | |
20738 |
|
20739 |
|
20740 |
|
20741 |
|
20742 |
|
20743 |
|
20744 |
|
20745 |
|
20746 | var _proto = Stream.prototype;
|
20747 |
|
20748 | _proto.on = function on(type, listener) {
|
20749 | if (!this.listeners[type]) {
|
20750 | this.listeners[type] = [];
|
20751 | }
|
20752 |
|
20753 | this.listeners[type].push(listener);
|
20754 | }
|
20755 | |
20756 |
|
20757 |
|
20758 |
|
20759 |
|
20760 |
|
20761 |
|
20762 |
|
20763 | ;
|
20764 |
|
20765 | _proto.off = function off(type, listener) {
|
20766 | if (!this.listeners[type]) {
|
20767 | return false;
|
20768 | }
|
20769 |
|
20770 | var index = this.listeners[type].indexOf(listener);
|
20771 |
|
20772 |
|
20773 |
|
20774 |
|
20775 |
|
20776 |
|
20777 |
|
20778 |
|
20779 | this.listeners[type] = this.listeners[type].slice(0);
|
20780 | this.listeners[type].splice(index, 1);
|
20781 | return index > -1;
|
20782 | }
|
20783 | |
20784 |
|
20785 |
|
20786 |
|
20787 |
|
20788 |
|
20789 | ;
|
20790 |
|
20791 | _proto.trigger = function trigger(type) {
|
20792 | var callbacks = this.listeners[type];
|
20793 |
|
20794 | if (!callbacks) {
|
20795 | return;
|
20796 | }
|
20797 |
|
20798 |
|
20799 |
|
20800 |
|
20801 |
|
20802 | if (arguments.length === 2) {
|
20803 | var length = callbacks.length;
|
20804 |
|
20805 | for (var i = 0; i < length; ++i) {
|
20806 | callbacks[i].call(this, arguments[1]);
|
20807 | }
|
20808 | } else {
|
20809 | var args = Array.prototype.slice.call(arguments, 1);
|
20810 | var _length = callbacks.length;
|
20811 |
|
20812 | for (var _i = 0; _i < _length; ++_i) {
|
20813 | callbacks[_i].apply(this, args);
|
20814 | }
|
20815 | }
|
20816 | }
|
20817 | |
20818 |
|
20819 |
|
20820 | ;
|
20821 |
|
20822 | _proto.dispose = function dispose() {
|
20823 | this.listeners = {};
|
20824 | }
|
20825 | |
20826 |
|
20827 |
|
20828 |
|
20829 |
|
20830 |
|
20831 |
|
20832 |
|
20833 | ;
|
20834 |
|
20835 | _proto.pipe = function pipe(destination) {
|
20836 | this.on('data', function (data) {
|
20837 | destination.push(data);
|
20838 | });
|
20839 | };
|
20840 |
|
20841 | return Stream;
|
20842 | }();
|
20843 |
|
20844 |
|
20845 | |
20846 |
|
20847 |
|
20848 |
|
20849 |
|
20850 |
|
20851 |
|
20852 |
|
20853 |
|
20854 | function unpad(padded) {
|
20855 | return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
|
20856 | }
|
20857 |
|
20858 |
|
20859 | |
20860 |
|
20861 |
|
20862 |
|
20863 |
|
20864 |
|
20865 |
|
20866 |
|
20867 |
|
20868 |
|
20869 |
|
20870 |
|
20871 |
|
20872 |
|
20873 |
|
20874 |
|
20875 |
|
20876 |
|
20877 |
|
20878 |
|
20879 |
|
20880 |
|
20881 |
|
20882 |
|
20883 |
|
20884 |
|
20885 |
|
20886 |
|
20887 |
|
20888 |
|
20889 |
|
20890 |
|
20891 |
|
20892 |
|
20893 |
|
20894 |
|
20895 |
|
20896 |
|
20897 |
|
20898 | |
20899 |
|
20900 |
|
20901 |
|
20902 |
|
20903 |
|
20904 |
|
20905 | var precompute = function precompute() {
|
20906 | var tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
20907 | var encTable = tables[0];
|
20908 | var decTable = tables[1];
|
20909 | var sbox = encTable[4];
|
20910 | var sboxInv = decTable[4];
|
20911 | var i;
|
20912 | var x;
|
20913 | var xInv;
|
20914 | var d = [];
|
20915 | var th = [];
|
20916 | var x2;
|
20917 | var x4;
|
20918 | var x8;
|
20919 | var s;
|
20920 | var tEnc;
|
20921 | var tDec;
|
20922 |
|
20923 | for (i = 0; i < 256; i++) {
|
20924 | th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
20925 | }
|
20926 |
|
20927 | for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
20928 |
|
20929 | s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
20930 | s = s >> 8 ^ s & 255 ^ 99;
|
20931 | sbox[x] = s;
|
20932 | sboxInv[s] = x;
|
20933 |
|
20934 | x8 = d[x4 = d[x2 = d[x]]];
|
20935 | tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
20936 | tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
20937 |
|
20938 | for (i = 0; i < 4; i++) {
|
20939 | encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
20940 | decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
20941 | }
|
20942 | }
|
20943 |
|
20944 |
|
20945 | for (i = 0; i < 5; i++) {
|
20946 | encTable[i] = encTable[i].slice(0);
|
20947 | decTable[i] = decTable[i].slice(0);
|
20948 | }
|
20949 |
|
20950 | return tables;
|
20951 | };
|
20952 |
|
20953 | var aesTables = null;
|
20954 | |
20955 |
|
20956 |
|
20957 |
|
20958 |
|
20959 |
|
20960 |
|
20961 |
|
20962 | var AES = function () {
|
20963 | function AES(key) {
|
20964 | |
20965 |
|
20966 |
|
20967 |
|
20968 |
|
20969 |
|
20970 |
|
20971 |
|
20972 |
|
20973 |
|
20974 |
|
20975 |
|
20976 |
|
20977 |
|
20978 | if (!aesTables) {
|
20979 | aesTables = precompute();
|
20980 | }
|
20981 |
|
20982 |
|
20983 | 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()]];
|
20984 | var i;
|
20985 | var j;
|
20986 | var tmp;
|
20987 | var sbox = this._tables[0][4];
|
20988 | var decTable = this._tables[1];
|
20989 | var keyLen = key.length;
|
20990 | var rcon = 1;
|
20991 |
|
20992 | if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
20993 | throw new Error('Invalid aes key size');
|
20994 | }
|
20995 |
|
20996 | var encKey = key.slice(0);
|
20997 | var decKey = [];
|
20998 | this._key = [encKey, decKey];
|
20999 |
|
21000 | for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
21001 | tmp = encKey[i - 1];
|
21002 |
|
21003 | if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
|
21004 | tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
21005 |
|
21006 | if (i % keyLen === 0) {
|
21007 | tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
21008 | rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
21009 | }
|
21010 | }
|
21011 |
|
21012 | encKey[i] = encKey[i - keyLen] ^ tmp;
|
21013 | }
|
21014 |
|
21015 |
|
21016 | for (j = 0; i; j++, i--) {
|
21017 | tmp = encKey[j & 3 ? i : i - 4];
|
21018 |
|
21019 | if (i <= 4 || j < 4) {
|
21020 | decKey[j] = tmp;
|
21021 | } else {
|
21022 | decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
|
21023 | }
|
21024 | }
|
21025 | }
|
21026 | |
21027 |
|
21028 |
|
21029 |
|
21030 |
|
21031 |
|
21032 |
|
21033 |
|
21034 |
|
21035 |
|
21036 |
|
21037 |
|
21038 |
|
21039 |
|
21040 |
|
21041 | var _proto = AES.prototype;
|
21042 |
|
21043 | _proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
|
21044 | var key = this._key[1];
|
21045 |
|
21046 | var a = encrypted0 ^ key[0];
|
21047 | var b = encrypted3 ^ key[1];
|
21048 | var c = encrypted2 ^ key[2];
|
21049 | var d = encrypted1 ^ key[3];
|
21050 | var a2;
|
21051 | var b2;
|
21052 | var c2;
|
21053 |
|
21054 | var nInnerRounds = key.length / 4 - 2;
|
21055 | var i;
|
21056 | var kIndex = 4;
|
21057 | var table = this._tables[1];
|
21058 |
|
21059 | var table0 = table[0];
|
21060 | var table1 = table[1];
|
21061 | var table2 = table[2];
|
21062 | var table3 = table[3];
|
21063 | var sbox = table[4];
|
21064 |
|
21065 | for (i = 0; i < nInnerRounds; i++) {
|
21066 | a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
|
21067 | b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
|
21068 | c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
|
21069 | d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
|
21070 | kIndex += 4;
|
21071 | a = a2;
|
21072 | b = b2;
|
21073 | c = c2;
|
21074 | }
|
21075 |
|
21076 |
|
21077 | for (i = 0; i < 4; i++) {
|
21078 | out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
|
21079 | a2 = a;
|
21080 | a = b;
|
21081 | b = c;
|
21082 | c = d;
|
21083 | d = a2;
|
21084 | }
|
21085 | };
|
21086 |
|
21087 | return AES;
|
21088 | }();
|
21089 | |
21090 |
|
21091 |
|
21092 |
|
21093 |
|
21094 |
|
21095 |
|
21096 |
|
21097 |
|
21098 | var AsyncStream = function (_Stream) {
|
21099 | inheritsLoose(AsyncStream, _Stream);
|
21100 |
|
21101 | function AsyncStream() {
|
21102 | var _this;
|
21103 |
|
21104 | _this = _Stream.call(this, Stream) || this;
|
21105 | _this.jobs = [];
|
21106 | _this.delay = 1;
|
21107 | _this.timeout_ = null;
|
21108 | return _this;
|
21109 | }
|
21110 | |
21111 |
|
21112 |
|
21113 |
|
21114 |
|
21115 |
|
21116 |
|
21117 | var _proto = AsyncStream.prototype;
|
21118 |
|
21119 | _proto.processJob_ = function processJob_() {
|
21120 | this.jobs.shift()();
|
21121 |
|
21122 | if (this.jobs.length) {
|
21123 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
21124 | } else {
|
21125 | this.timeout_ = null;
|
21126 | }
|
21127 | }
|
21128 | |
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 | ;
|
21134 |
|
21135 | _proto.push = function push(job) {
|
21136 | this.jobs.push(job);
|
21137 |
|
21138 | if (!this.timeout_) {
|
21139 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
21140 | }
|
21141 | };
|
21142 |
|
21143 | return AsyncStream;
|
21144 | }(Stream);
|
21145 | |
21146 |
|
21147 |
|
21148 |
|
21149 |
|
21150 |
|
21151 | var ntoh = function ntoh(word) {
|
21152 | return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
|
21153 | };
|
21154 | |
21155 |
|
21156 |
|
21157 |
|
21158 |
|
21159 |
|
21160 |
|
21161 |
|
21162 |
|
21163 |
|
21164 |
|
21165 |
|
21166 |
|
21167 |
|
21168 |
|
21169 | var decrypt = function decrypt(encrypted, key, initVector) {
|
21170 |
|
21171 | var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
|
21172 | var decipher = new AES(Array.prototype.slice.call(key));
|
21173 |
|
21174 | var decrypted = new Uint8Array(encrypted.byteLength);
|
21175 | var decrypted32 = new Int32Array(decrypted.buffer);
|
21176 |
|
21177 |
|
21178 | var init0;
|
21179 | var init1;
|
21180 | var init2;
|
21181 | var init3;
|
21182 | var encrypted0;
|
21183 | var encrypted1;
|
21184 | var encrypted2;
|
21185 | var encrypted3;
|
21186 |
|
21187 | var wordIx;
|
21188 |
|
21189 |
|
21190 | init0 = initVector[0];
|
21191 | init1 = initVector[1];
|
21192 | init2 = initVector[2];
|
21193 | init3 = initVector[3];
|
21194 |
|
21195 |
|
21196 | for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
|
21197 |
|
21198 |
|
21199 | encrypted0 = ntoh(encrypted32[wordIx]);
|
21200 | encrypted1 = ntoh(encrypted32[wordIx + 1]);
|
21201 | encrypted2 = ntoh(encrypted32[wordIx + 2]);
|
21202 | encrypted3 = ntoh(encrypted32[wordIx + 3]);
|
21203 |
|
21204 | decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
|
21205 |
|
21206 |
|
21207 | decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
|
21208 | decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
|
21209 | decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
|
21210 | decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
|
21211 |
|
21212 | init0 = encrypted0;
|
21213 | init1 = encrypted1;
|
21214 | init2 = encrypted2;
|
21215 | init3 = encrypted3;
|
21216 | }
|
21217 |
|
21218 | return decrypted;
|
21219 | };
|
21220 | |
21221 |
|
21222 |
|
21223 |
|
21224 |
|
21225 |
|
21226 |
|
21227 |
|
21228 |
|
21229 |
|
21230 |
|
21231 |
|
21232 |
|
21233 | var Decrypter = function () {
|
21234 | function Decrypter(encrypted, key, initVector, done) {
|
21235 | var step = Decrypter.STEP;
|
21236 | var encrypted32 = new Int32Array(encrypted.buffer);
|
21237 | var decrypted = new Uint8Array(encrypted.byteLength);
|
21238 | var i = 0;
|
21239 | this.asyncStream_ = new AsyncStream();
|
21240 |
|
21241 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
21242 |
|
21243 | for (i = step; i < encrypted32.length; i += step) {
|
21244 | initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
|
21245 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
21246 | }
|
21247 |
|
21248 |
|
21249 | this.asyncStream_.push(function () {
|
21250 |
|
21251 | done(null, unpad(decrypted));
|
21252 | });
|
21253 | }
|
21254 | |
21255 |
|
21256 |
|
21257 |
|
21258 |
|
21259 |
|
21260 |
|
21261 | var _proto = Decrypter.prototype;
|
21262 | |
21263 |
|
21264 |
|
21265 |
|
21266 | _proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
|
21267 | return function () {
|
21268 | var bytes = decrypt(encrypted, key, initVector);
|
21269 | decrypted.set(bytes, encrypted.byteOffset);
|
21270 | };
|
21271 | };
|
21272 |
|
21273 | createClass(Decrypter, null, [{
|
21274 | key: "STEP",
|
21275 | get: function get() {
|
21276 |
|
21277 | return 32000;
|
21278 | }
|
21279 | }]);
|
21280 | return Decrypter;
|
21281 | }();
|
21282 |
|
21283 | var win;
|
21284 |
|
21285 | if (typeof window !== "undefined") {
|
21286 | win = window;
|
21287 | } else if (typeof commonjsGlobal !== "undefined") {
|
21288 | win = commonjsGlobal;
|
21289 | } else if (typeof self !== "undefined") {
|
21290 | win = self;
|
21291 | } else {
|
21292 | win = {};
|
21293 | }
|
21294 |
|
21295 | var window_1 = win;
|
21296 |
|
21297 | var isArrayBufferView = function isArrayBufferView(obj) {
|
21298 | if (ArrayBuffer.isView === 'function') {
|
21299 | return ArrayBuffer.isView(obj);
|
21300 | }
|
21301 |
|
21302 | return obj && obj.buffer instanceof ArrayBuffer;
|
21303 | };
|
21304 |
|
21305 | var BigInt = window_1.BigInt || Number;
|
21306 | [BigInt('0x1'), BigInt('0x100'), BigInt('0x10000'), BigInt('0x1000000'), BigInt('0x100000000'), BigInt('0x10000000000'), BigInt('0x1000000000000'), BigInt('0x100000000000000'), BigInt('0x10000000000000000')];
|
21307 |
|
21308 | (function () {
|
21309 | var a = new Uint16Array([0xFFCC]);
|
21310 | var b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
21311 |
|
21312 | if (b[0] === 0xFF) {
|
21313 | return 'big';
|
21314 | }
|
21315 |
|
21316 | if (b[0] === 0xCC) {
|
21317 | return 'little';
|
21318 | }
|
21319 |
|
21320 | return 'unknown';
|
21321 | })();
|
21322 | |
21323 |
|
21324 |
|
21325 |
|
21326 |
|
21327 |
|
21328 |
|
21329 |
|
21330 |
|
21331 |
|
21332 |
|
21333 |
|
21334 | var createTransferableMessage = function createTransferableMessage(message) {
|
21335 | var transferable = {};
|
21336 | Object.keys(message).forEach(function (key) {
|
21337 | var value = message[key];
|
21338 |
|
21339 | if (isArrayBufferView(value)) {
|
21340 | transferable[key] = {
|
21341 | bytes: value.buffer,
|
21342 | byteOffset: value.byteOffset,
|
21343 | byteLength: value.byteLength
|
21344 | };
|
21345 | } else {
|
21346 | transferable[key] = value;
|
21347 | }
|
21348 | });
|
21349 | return transferable;
|
21350 | };
|
21351 |
|
21352 |
|
21353 | |
21354 |
|
21355 |
|
21356 |
|
21357 |
|
21358 |
|
21359 |
|
21360 | self.onmessage = function (event) {
|
21361 | var data = event.data;
|
21362 | var encrypted = new Uint8Array(data.encrypted.bytes, data.encrypted.byteOffset, data.encrypted.byteLength);
|
21363 | var key = new Uint32Array(data.key.bytes, data.key.byteOffset, data.key.byteLength / 4);
|
21364 | var iv = new Uint32Array(data.iv.bytes, data.iv.byteOffset, data.iv.byteLength / 4);
|
21365 |
|
21366 |
|
21367 | new Decrypter(encrypted, key, iv, function (err, bytes) {
|
21368 | self.postMessage(createTransferableMessage({
|
21369 | source: data.source,
|
21370 | decrypted: bytes
|
21371 | }), [bytes.buffer]);
|
21372 | });
|
21373 |
|
21374 | };
|
21375 | }));
|
21376 | var Decrypter = factory(workerCode);
|
21377 |
|
21378 |
|
21379 |
|
21380 |
|
21381 |
|
21382 |
|
21383 |
|
21384 |
|
21385 | var audioTrackKind_ = function audioTrackKind_(properties) {
|
21386 | var kind = properties.default ? 'main' : 'alternative';
|
21387 |
|
21388 | if (properties.characteristics && properties.characteristics.indexOf('public.accessibility.describes-video') >= 0) {
|
21389 | kind = 'main-desc';
|
21390 | }
|
21391 |
|
21392 | return kind;
|
21393 | };
|
21394 |
|
21395 |
|
21396 |
|
21397 |
|
21398 |
|
21399 |
|
21400 |
|
21401 |
|
21402 |
|
21403 |
|
21404 |
|
21405 | var stopLoaders = function stopLoaders(segmentLoader, mediaType) {
|
21406 | segmentLoader.abort();
|
21407 | segmentLoader.pause();
|
21408 |
|
21409 | if (mediaType && mediaType.activePlaylistLoader) {
|
21410 | mediaType.activePlaylistLoader.pause();
|
21411 | mediaType.activePlaylistLoader = null;
|
21412 | }
|
21413 | };
|
21414 |
|
21415 |
|
21416 |
|
21417 |
|
21418 |
|
21419 |
|
21420 |
|
21421 |
|
21422 |
|
21423 |
|
21424 | var startLoaders = function startLoaders(playlistLoader, mediaType) {
|
21425 |
|
21426 |
|
21427 | mediaType.activePlaylistLoader = playlistLoader;
|
21428 | playlistLoader.load();
|
21429 | };
|
21430 |
|
21431 |
|
21432 |
|
21433 |
|
21434 |
|
21435 |
|
21436 |
|
21437 |
|
21438 |
|
21439 |
|
21440 |
|
21441 |
|
21442 |
|
21443 |
|
21444 |
|
21445 |
|
21446 | var onGroupChanged = function onGroupChanged(type, settings) {
|
21447 | return function () {
|
21448 | var _settings$segmentLoad = settings.segmentLoaders,
|
21449 | segmentLoader = _settings$segmentLoad[type],
|
21450 | mainSegmentLoader = _settings$segmentLoad.main,
|
21451 | mediaType = settings.mediaTypes[type];
|
21452 | var activeTrack = mediaType.activeTrack();
|
21453 | var activeGroup = mediaType.getActiveGroup();
|
21454 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
21455 | var lastGroup = mediaType.lastGroup_;
|
21456 |
|
21457 | if (activeGroup && lastGroup && activeGroup.id === lastGroup.id) {
|
21458 | return;
|
21459 | }
|
21460 |
|
21461 | mediaType.lastGroup_ = activeGroup;
|
21462 | mediaType.lastTrack_ = activeTrack;
|
21463 | stopLoaders(segmentLoader, mediaType);
|
21464 |
|
21465 | if (!activeGroup || activeGroup.isMasterPlaylist) {
|
21466 |
|
21467 | return;
|
21468 | }
|
21469 |
|
21470 | if (!activeGroup.playlistLoader) {
|
21471 | if (previousActiveLoader) {
|
21472 |
|
21473 |
|
21474 |
|
21475 |
|
21476 | mainSegmentLoader.resetEverything();
|
21477 | }
|
21478 |
|
21479 | return;
|
21480 | }
|
21481 |
|
21482 |
|
21483 | segmentLoader.resyncLoader();
|
21484 | startLoaders(activeGroup.playlistLoader, mediaType);
|
21485 | };
|
21486 | };
|
21487 | var onGroupChanging = function onGroupChanging(type, settings) {
|
21488 | return function () {
|
21489 | var segmentLoader = settings.segmentLoaders[type],
|
21490 | mediaType = settings.mediaTypes[type];
|
21491 | mediaType.lastGroup_ = null;
|
21492 | segmentLoader.abort();
|
21493 | segmentLoader.pause();
|
21494 | };
|
21495 | };
|
21496 |
|
21497 |
|
21498 |
|
21499 |
|
21500 |
|
21501 |
|
21502 |
|
21503 |
|
21504 |
|
21505 |
|
21506 |
|
21507 |
|
21508 |
|
21509 |
|
21510 |
|
21511 | var onTrackChanged = function onTrackChanged(type, settings) {
|
21512 | return function () {
|
21513 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
21514 | _settings$segmentLoad2 = settings.segmentLoaders,
|
21515 | segmentLoader = _settings$segmentLoad2[type],
|
21516 | mainSegmentLoader = _settings$segmentLoad2.main,
|
21517 | mediaType = settings.mediaTypes[type];
|
21518 | var activeTrack = mediaType.activeTrack();
|
21519 | var activeGroup = mediaType.getActiveGroup();
|
21520 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
21521 | var lastTrack = mediaType.lastTrack_;
|
21522 |
|
21523 | if (lastTrack && activeTrack && lastTrack.id === activeTrack.id) {
|
21524 | return;
|
21525 | }
|
21526 |
|
21527 | mediaType.lastGroup_ = activeGroup;
|
21528 | mediaType.lastTrack_ = activeTrack;
|
21529 | stopLoaders(segmentLoader, mediaType);
|
21530 |
|
21531 | if (!activeGroup) {
|
21532 |
|
21533 | return;
|
21534 | }
|
21535 |
|
21536 | if (activeGroup.isMasterPlaylist) {
|
21537 |
|
21538 | if (!activeTrack || !lastTrack || activeTrack.id === lastTrack.id) {
|
21539 | return;
|
21540 | }
|
21541 |
|
21542 | var mpc = settings.vhs.masterPlaylistController_;
|
21543 | var newPlaylist = mpc.selectPlaylist();
|
21544 |
|
21545 | if (mpc.media() === newPlaylist) {
|
21546 | return;
|
21547 | }
|
21548 |
|
21549 | mediaType.logger_("track change. Switching master audio from " + lastTrack.id + " to " + activeTrack.id);
|
21550 | masterPlaylistLoader.pause();
|
21551 | mainSegmentLoader.resetEverything();
|
21552 | mpc.fastQualityChange_(newPlaylist);
|
21553 | return;
|
21554 | }
|
21555 |
|
21556 | if (type === 'AUDIO') {
|
21557 | if (!activeGroup.playlistLoader) {
|
21558 |
|
21559 |
|
21560 |
|
21561 | mainSegmentLoader.setAudio(true);
|
21562 |
|
21563 |
|
21564 | mainSegmentLoader.resetEverything();
|
21565 | return;
|
21566 | }
|
21567 |
|
21568 |
|
21569 |
|
21570 |
|
21571 | segmentLoader.setAudio(true);
|
21572 | mainSegmentLoader.setAudio(false);
|
21573 | }
|
21574 |
|
21575 | if (previousActiveLoader === activeGroup.playlistLoader) {
|
21576 |
|
21577 |
|
21578 |
|
21579 | startLoaders(activeGroup.playlistLoader, mediaType);
|
21580 | return;
|
21581 | }
|
21582 |
|
21583 | if (segmentLoader.track) {
|
21584 |
|
21585 | segmentLoader.track(activeTrack);
|
21586 | }
|
21587 |
|
21588 |
|
21589 | segmentLoader.resetEverything();
|
21590 | startLoaders(activeGroup.playlistLoader, mediaType);
|
21591 | };
|
21592 | };
|
21593 | var onError = {
|
21594 | |
21595 |
|
21596 |
|
21597 |
|
21598 |
|
21599 |
|
21600 |
|
21601 |
|
21602 |
|
21603 |
|
21604 |
|
21605 |
|
21606 |
|
21607 | AUDIO: function AUDIO(type, settings) {
|
21608 | return function () {
|
21609 | var segmentLoader = settings.segmentLoaders[type],
|
21610 | mediaType = settings.mediaTypes[type],
|
21611 | blacklistCurrentPlaylist = settings.blacklistCurrentPlaylist;
|
21612 | stopLoaders(segmentLoader, mediaType);
|
21613 |
|
21614 | var activeTrack = mediaType.activeTrack();
|
21615 | var activeGroup = mediaType.activeGroup();
|
21616 | var id = (activeGroup.filter(function (group) {
|
21617 | return group.default;
|
21618 | })[0] || activeGroup[0]).id;
|
21619 | var defaultTrack = mediaType.tracks[id];
|
21620 |
|
21621 | if (activeTrack === defaultTrack) {
|
21622 |
|
21623 |
|
21624 | blacklistCurrentPlaylist({
|
21625 | message: 'Problem encountered loading the default audio track.'
|
21626 | });
|
21627 | return;
|
21628 | }
|
21629 |
|
21630 | videojs__default["default"].log.warn('Problem encountered loading the alternate audio track.' + 'Switching back to default.');
|
21631 |
|
21632 | for (var trackId in mediaType.tracks) {
|
21633 | mediaType.tracks[trackId].enabled = mediaType.tracks[trackId] === defaultTrack;
|
21634 | }
|
21635 |
|
21636 | mediaType.onTrackChanged();
|
21637 | };
|
21638 | },
|
21639 |
|
21640 | |
21641 |
|
21642 |
|
21643 |
|
21644 |
|
21645 |
|
21646 |
|
21647 |
|
21648 |
|
21649 |
|
21650 |
|
21651 |
|
21652 | SUBTITLES: function SUBTITLES(type, settings) {
|
21653 | return function () {
|
21654 | var segmentLoader = settings.segmentLoaders[type],
|
21655 | mediaType = settings.mediaTypes[type];
|
21656 | videojs__default["default"].log.warn('Problem encountered loading the subtitle track.' + 'Disabling subtitle track.');
|
21657 | stopLoaders(segmentLoader, mediaType);
|
21658 | var track = mediaType.activeTrack();
|
21659 |
|
21660 | if (track) {
|
21661 | track.mode = 'disabled';
|
21662 | }
|
21663 |
|
21664 | mediaType.onTrackChanged();
|
21665 | };
|
21666 | }
|
21667 | };
|
21668 | var setupListeners = {
|
21669 | |
21670 |
|
21671 |
|
21672 |
|
21673 |
|
21674 |
|
21675 |
|
21676 |
|
21677 |
|
21678 |
|
21679 |
|
21680 | AUDIO: function AUDIO(type, playlistLoader, settings) {
|
21681 | if (!playlistLoader) {
|
21682 |
|
21683 | return;
|
21684 | }
|
21685 |
|
21686 | var tech = settings.tech,
|
21687 | requestOptions = settings.requestOptions,
|
21688 | segmentLoader = settings.segmentLoaders[type];
|
21689 | playlistLoader.on('loadedmetadata', function () {
|
21690 | var media = playlistLoader.media();
|
21691 | segmentLoader.playlist(media, requestOptions);
|
21692 |
|
21693 |
|
21694 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
21695 | segmentLoader.load();
|
21696 | }
|
21697 | });
|
21698 | playlistLoader.on('loadedplaylist', function () {
|
21699 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
21700 |
|
21701 | if (!tech.paused()) {
|
21702 | segmentLoader.load();
|
21703 | }
|
21704 | });
|
21705 | playlistLoader.on('error', onError[type](type, settings));
|
21706 | },
|
21707 |
|
21708 | |
21709 |
|
21710 |
|
21711 |
|
21712 |
|
21713 |
|
21714 |
|
21715 |
|
21716 |
|
21717 |
|
21718 |
|
21719 | SUBTITLES: function SUBTITLES(type, playlistLoader, settings) {
|
21720 | var tech = settings.tech,
|
21721 | requestOptions = settings.requestOptions,
|
21722 | segmentLoader = settings.segmentLoaders[type],
|
21723 | mediaType = settings.mediaTypes[type];
|
21724 | playlistLoader.on('loadedmetadata', function () {
|
21725 | var media = playlistLoader.media();
|
21726 | segmentLoader.playlist(media, requestOptions);
|
21727 | segmentLoader.track(mediaType.activeTrack());
|
21728 |
|
21729 |
|
21730 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
21731 | segmentLoader.load();
|
21732 | }
|
21733 | });
|
21734 | playlistLoader.on('loadedplaylist', function () {
|
21735 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
21736 |
|
21737 | if (!tech.paused()) {
|
21738 | segmentLoader.load();
|
21739 | }
|
21740 | });
|
21741 | playlistLoader.on('error', onError[type](type, settings));
|
21742 | }
|
21743 | };
|
21744 | var initialize = {
|
21745 | |
21746 |
|
21747 |
|
21748 |
|
21749 |
|
21750 |
|
21751 |
|
21752 |
|
21753 |
|
21754 | 'AUDIO': function AUDIO(type, settings) {
|
21755 | var vhs = settings.vhs,
|
21756 | sourceType = settings.sourceType,
|
21757 | segmentLoader = settings.segmentLoaders[type],
|
21758 | requestOptions = settings.requestOptions,
|
21759 | mediaGroups = settings.master.mediaGroups,
|
21760 | _settings$mediaTypes$ = settings.mediaTypes[type],
|
21761 | groups = _settings$mediaTypes$.groups,
|
21762 | tracks = _settings$mediaTypes$.tracks,
|
21763 | logger_ = _settings$mediaTypes$.logger_,
|
21764 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
21765 | var audioOnlyMaster = isAudioOnly(masterPlaylistLoader.master);
|
21766 |
|
21767 | if (!mediaGroups[type] || Object.keys(mediaGroups[type]).length === 0) {
|
21768 | mediaGroups[type] = {
|
21769 | main: {
|
21770 | default: {
|
21771 | default: true
|
21772 | }
|
21773 | }
|
21774 | };
|
21775 |
|
21776 | if (audioOnlyMaster) {
|
21777 | mediaGroups[type].main.default.playlists = masterPlaylistLoader.master.playlists;
|
21778 | }
|
21779 | }
|
21780 |
|
21781 | for (var groupId in mediaGroups[type]) {
|
21782 | if (!groups[groupId]) {
|
21783 | groups[groupId] = [];
|
21784 | }
|
21785 |
|
21786 | for (var variantLabel in mediaGroups[type][groupId]) {
|
21787 | var properties = mediaGroups[type][groupId][variantLabel];
|
21788 | var playlistLoader = void 0;
|
21789 |
|
21790 | if (audioOnlyMaster) {
|
21791 | logger_("AUDIO group '" + groupId + "' label '" + variantLabel + "' is a master playlist");
|
21792 | properties.isMasterPlaylist = true;
|
21793 | playlistLoader = null;
|
21794 |
|
21795 | } else if (sourceType === 'vhs-json' && properties.playlists) {
|
21796 | playlistLoader = new PlaylistLoader(properties.playlists[0], vhs, requestOptions);
|
21797 | } else if (properties.resolvedUri) {
|
21798 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
21799 |
|
21800 | } else if (properties.playlists && sourceType === 'dash') {
|
21801 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
21802 | } else {
|
21803 |
|
21804 |
|
21805 | playlistLoader = null;
|
21806 | }
|
21807 |
|
21808 | properties = videojs__default["default"].mergeOptions({
|
21809 | id: variantLabel,
|
21810 | playlistLoader: playlistLoader
|
21811 | }, properties);
|
21812 | setupListeners[type](type, properties.playlistLoader, settings);
|
21813 | groups[groupId].push(properties);
|
21814 |
|
21815 | if (typeof tracks[variantLabel] === 'undefined') {
|
21816 | var track = new videojs__default["default"].AudioTrack({
|
21817 | id: variantLabel,
|
21818 | kind: audioTrackKind_(properties),
|
21819 | enabled: false,
|
21820 | language: properties.language,
|
21821 | default: properties.default,
|
21822 | label: variantLabel
|
21823 | });
|
21824 | tracks[variantLabel] = track;
|
21825 | }
|
21826 | }
|
21827 | }
|
21828 |
|
21829 |
|
21830 | segmentLoader.on('error', onError[type](type, settings));
|
21831 | },
|
21832 |
|
21833 | |
21834 |
|
21835 |
|
21836 |
|
21837 |
|
21838 |
|
21839 |
|
21840 |
|
21841 |
|
21842 | 'SUBTITLES': function SUBTITLES(type, settings) {
|
21843 | var tech = settings.tech,
|
21844 | vhs = settings.vhs,
|
21845 | sourceType = settings.sourceType,
|
21846 | segmentLoader = settings.segmentLoaders[type],
|
21847 | requestOptions = settings.requestOptions,
|
21848 | mediaGroups = settings.master.mediaGroups,
|
21849 | _settings$mediaTypes$2 = settings.mediaTypes[type],
|
21850 | groups = _settings$mediaTypes$2.groups,
|
21851 | tracks = _settings$mediaTypes$2.tracks,
|
21852 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
21853 |
|
21854 | for (var groupId in mediaGroups[type]) {
|
21855 | if (!groups[groupId]) {
|
21856 | groups[groupId] = [];
|
21857 | }
|
21858 |
|
21859 | for (var variantLabel in mediaGroups[type][groupId]) {
|
21860 | if (mediaGroups[type][groupId][variantLabel].forced) {
|
21861 |
|
21862 |
|
21863 |
|
21864 |
|
21865 |
|
21866 |
|
21867 |
|
21868 |
|
21869 | continue;
|
21870 | }
|
21871 |
|
21872 | var properties = mediaGroups[type][groupId][variantLabel];
|
21873 | var playlistLoader = void 0;
|
21874 |
|
21875 | if (sourceType === 'hls') {
|
21876 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
21877 | } else if (sourceType === 'dash') {
|
21878 | var playlists = properties.playlists.filter(function (p) {
|
21879 | return p.excludeUntil !== Infinity;
|
21880 | });
|
21881 |
|
21882 | if (!playlists.length) {
|
21883 | return;
|
21884 | }
|
21885 |
|
21886 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
21887 | } else if (sourceType === 'vhs-json') {
|
21888 | playlistLoader = new PlaylistLoader(
|
21889 |
|
21890 | properties.playlists ? properties.playlists[0] : properties.resolvedUri, vhs, requestOptions);
|
21891 | }
|
21892 |
|
21893 | properties = videojs__default["default"].mergeOptions({
|
21894 | id: variantLabel,
|
21895 | playlistLoader: playlistLoader
|
21896 | }, properties);
|
21897 | setupListeners[type](type, properties.playlistLoader, settings);
|
21898 | groups[groupId].push(properties);
|
21899 |
|
21900 | if (typeof tracks[variantLabel] === 'undefined') {
|
21901 | var track = tech.addRemoteTextTrack({
|
21902 | id: variantLabel,
|
21903 | kind: 'subtitles',
|
21904 | default: properties.default && properties.autoselect,
|
21905 | language: properties.language,
|
21906 | label: variantLabel
|
21907 | }, false).track;
|
21908 | tracks[variantLabel] = track;
|
21909 | }
|
21910 | }
|
21911 | }
|
21912 |
|
21913 |
|
21914 | segmentLoader.on('error', onError[type](type, settings));
|
21915 | },
|
21916 |
|
21917 | |
21918 |
|
21919 |
|
21920 |
|
21921 |
|
21922 |
|
21923 |
|
21924 |
|
21925 |
|
21926 | 'CLOSED-CAPTIONS': function CLOSEDCAPTIONS(type, settings) {
|
21927 | var tech = settings.tech,
|
21928 | mediaGroups = settings.master.mediaGroups,
|
21929 | _settings$mediaTypes$3 = settings.mediaTypes[type],
|
21930 | groups = _settings$mediaTypes$3.groups,
|
21931 | tracks = _settings$mediaTypes$3.tracks;
|
21932 |
|
21933 | for (var groupId in mediaGroups[type]) {
|
21934 | if (!groups[groupId]) {
|
21935 | groups[groupId] = [];
|
21936 | }
|
21937 |
|
21938 | for (var variantLabel in mediaGroups[type][groupId]) {
|
21939 | var properties = mediaGroups[type][groupId][variantLabel];
|
21940 |
|
21941 | if (!/^(?:CC|SERVICE)/.test(properties.instreamId)) {
|
21942 | continue;
|
21943 | }
|
21944 |
|
21945 | var captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
|
21946 | var newProps = {
|
21947 | label: variantLabel,
|
21948 | language: properties.language,
|
21949 | instreamId: properties.instreamId,
|
21950 | default: properties.default && properties.autoselect
|
21951 | };
|
21952 |
|
21953 | if (captionServices[newProps.instreamId]) {
|
21954 | newProps = videojs__default["default"].mergeOptions(newProps, captionServices[newProps.instreamId]);
|
21955 | }
|
21956 |
|
21957 | if (newProps.default === undefined) {
|
21958 | delete newProps.default;
|
21959 | }
|
21960 |
|
21961 |
|
21962 |
|
21963 | groups[groupId].push(videojs__default["default"].mergeOptions({
|
21964 | id: variantLabel
|
21965 | }, properties));
|
21966 |
|
21967 | if (typeof tracks[variantLabel] === 'undefined') {
|
21968 | var track = tech.addRemoteTextTrack({
|
21969 | id: newProps.instreamId,
|
21970 | kind: 'captions',
|
21971 | default: newProps.default,
|
21972 | language: newProps.language,
|
21973 | label: newProps.label
|
21974 | }, false).track;
|
21975 | tracks[variantLabel] = track;
|
21976 | }
|
21977 | }
|
21978 | }
|
21979 | }
|
21980 | };
|
21981 |
|
21982 | var groupMatch = function groupMatch(list, media) {
|
21983 | for (var i = 0; i < list.length; i++) {
|
21984 | if (playlistMatch(media, list[i])) {
|
21985 | return true;
|
21986 | }
|
21987 |
|
21988 | if (list[i].playlists && groupMatch(list[i].playlists, media)) {
|
21989 | return true;
|
21990 | }
|
21991 | }
|
21992 |
|
21993 | return false;
|
21994 | };
|
21995 |
|
21996 |
|
21997 |
|
21998 |
|
21999 |
|
22000 |
|
22001 |
|
22002 |
|
22003 |
|
22004 |
|
22005 |
|
22006 |
|
22007 |
|
22008 |
|
22009 |
|
22010 |
|
22011 | var activeGroup = function activeGroup(type, settings) {
|
22012 | return function (track) {
|
22013 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
22014 | groups = settings.mediaTypes[type].groups;
|
22015 | var media = masterPlaylistLoader.media();
|
22016 |
|
22017 | if (!media) {
|
22018 | return null;
|
22019 | }
|
22020 |
|
22021 | var variants = null;
|
22022 |
|
22023 | if (media.attributes[type]) {
|
22024 | variants = groups[media.attributes[type]];
|
22025 | }
|
22026 |
|
22027 | var groupKeys = Object.keys(groups);
|
22028 |
|
22029 | if (!variants) {
|
22030 |
|
22031 |
|
22032 |
|
22033 | if (type === 'AUDIO' && groupKeys.length > 1 && isAudioOnly(settings.master)) {
|
22034 | for (var i = 0; i < groupKeys.length; i++) {
|
22035 | var groupPropertyList = groups[groupKeys[i]];
|
22036 |
|
22037 | if (groupMatch(groupPropertyList, media)) {
|
22038 | variants = groupPropertyList;
|
22039 | break;
|
22040 | }
|
22041 | }
|
22042 |
|
22043 | } else if (groups.main) {
|
22044 | variants = groups.main;
|
22045 | } else if (groupKeys.length === 1) {
|
22046 | variants = groups[groupKeys[0]];
|
22047 | }
|
22048 | }
|
22049 |
|
22050 | if (typeof track === 'undefined') {
|
22051 | return variants;
|
22052 | }
|
22053 |
|
22054 | if (track === null || !variants) {
|
22055 |
|
22056 |
|
22057 | return null;
|
22058 | }
|
22059 |
|
22060 | return variants.filter(function (props) {
|
22061 | return props.id === track.id;
|
22062 | })[0] || null;
|
22063 | };
|
22064 | };
|
22065 | var activeTrack = {
|
22066 | |
22067 |
|
22068 |
|
22069 |
|
22070 |
|
22071 |
|
22072 |
|
22073 |
|
22074 |
|
22075 |
|
22076 |
|
22077 |
|
22078 | AUDIO: function AUDIO(type, settings) {
|
22079 | return function () {
|
22080 | var tracks = settings.mediaTypes[type].tracks;
|
22081 |
|
22082 | for (var id in tracks) {
|
22083 | if (tracks[id].enabled) {
|
22084 | return tracks[id];
|
22085 | }
|
22086 | }
|
22087 |
|
22088 | return null;
|
22089 | };
|
22090 | },
|
22091 |
|
22092 | |
22093 |
|
22094 |
|
22095 |
|
22096 |
|
22097 |
|
22098 |
|
22099 |
|
22100 |
|
22101 |
|
22102 |
|
22103 |
|
22104 | SUBTITLES: function SUBTITLES(type, settings) {
|
22105 | return function () {
|
22106 | var tracks = settings.mediaTypes[type].tracks;
|
22107 |
|
22108 | for (var id in tracks) {
|
22109 | if (tracks[id].mode === 'showing' || tracks[id].mode === 'hidden') {
|
22110 | return tracks[id];
|
22111 | }
|
22112 | }
|
22113 |
|
22114 | return null;
|
22115 | };
|
22116 | }
|
22117 | };
|
22118 | var getActiveGroup = function getActiveGroup(type, _ref) {
|
22119 | var mediaTypes = _ref.mediaTypes;
|
22120 | return function () {
|
22121 | var activeTrack_ = mediaTypes[type].activeTrack();
|
22122 |
|
22123 | if (!activeTrack_) {
|
22124 | return null;
|
22125 | }
|
22126 |
|
22127 | return mediaTypes[type].activeGroup(activeTrack_);
|
22128 | };
|
22129 | };
|
22130 |
|
22131 |
|
22132 |
|
22133 |
|
22134 |
|
22135 |
|
22136 |
|
22137 |
|
22138 |
|
22139 |
|
22140 |
|
22141 |
|
22142 |
|
22143 |
|
22144 |
|
22145 |
|
22146 |
|
22147 |
|
22148 |
|
22149 |
|
22150 |
|
22151 |
|
22152 |
|
22153 | var setupMediaGroups = function setupMediaGroups(settings) {
|
22154 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
22155 | initialize[type](type, settings);
|
22156 | });
|
22157 | var mediaTypes = settings.mediaTypes,
|
22158 | masterPlaylistLoader = settings.masterPlaylistLoader,
|
22159 | tech = settings.tech,
|
22160 | vhs = settings.vhs,
|
22161 | _settings$segmentLoad3 = settings.segmentLoaders,
|
22162 | audioSegmentLoader = _settings$segmentLoad3['AUDIO'],
|
22163 | mainSegmentLoader = _settings$segmentLoad3.main;
|
22164 |
|
22165 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
22166 | mediaTypes[type].activeGroup = activeGroup(type, settings);
|
22167 | mediaTypes[type].activeTrack = activeTrack[type](type, settings);
|
22168 | mediaTypes[type].onGroupChanged = onGroupChanged(type, settings);
|
22169 | mediaTypes[type].onGroupChanging = onGroupChanging(type, settings);
|
22170 | mediaTypes[type].onTrackChanged = onTrackChanged(type, settings);
|
22171 | mediaTypes[type].getActiveGroup = getActiveGroup(type, settings);
|
22172 | });
|
22173 |
|
22174 |
|
22175 | var audioGroup = mediaTypes.AUDIO.activeGroup();
|
22176 |
|
22177 | if (audioGroup) {
|
22178 | var groupId = (audioGroup.filter(function (group) {
|
22179 | return group.default;
|
22180 | })[0] || audioGroup[0]).id;
|
22181 | mediaTypes.AUDIO.tracks[groupId].enabled = true;
|
22182 | mediaTypes.AUDIO.onGroupChanged();
|
22183 | mediaTypes.AUDIO.onTrackChanged();
|
22184 | var activeAudioGroup = mediaTypes.AUDIO.getActiveGroup();
|
22185 |
|
22186 |
|
22187 |
|
22188 | if (!activeAudioGroup.playlistLoader) {
|
22189 |
|
22190 | mainSegmentLoader.setAudio(true);
|
22191 | } else {
|
22192 |
|
22193 | mainSegmentLoader.setAudio(false);
|
22194 | audioSegmentLoader.setAudio(true);
|
22195 | }
|
22196 | }
|
22197 |
|
22198 | masterPlaylistLoader.on('mediachange', function () {
|
22199 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
22200 | return mediaTypes[type].onGroupChanged();
|
22201 | });
|
22202 | });
|
22203 | masterPlaylistLoader.on('mediachanging', function () {
|
22204 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
22205 | return mediaTypes[type].onGroupChanging();
|
22206 | });
|
22207 | });
|
22208 |
|
22209 | var onAudioTrackChanged = function onAudioTrackChanged() {
|
22210 | mediaTypes.AUDIO.onTrackChanged();
|
22211 | tech.trigger({
|
22212 | type: 'usage',
|
22213 | name: 'vhs-audio-change'
|
22214 | });
|
22215 | tech.trigger({
|
22216 | type: 'usage',
|
22217 | name: 'hls-audio-change'
|
22218 | });
|
22219 | };
|
22220 |
|
22221 | tech.audioTracks().addEventListener('change', onAudioTrackChanged);
|
22222 | tech.remoteTextTracks().addEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
22223 | vhs.on('dispose', function () {
|
22224 | tech.audioTracks().removeEventListener('change', onAudioTrackChanged);
|
22225 | tech.remoteTextTracks().removeEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
22226 | });
|
22227 |
|
22228 | tech.clearTracks('audio');
|
22229 |
|
22230 | for (var id in mediaTypes.AUDIO.tracks) {
|
22231 | tech.audioTracks().addTrack(mediaTypes.AUDIO.tracks[id]);
|
22232 | }
|
22233 | };
|
22234 |
|
22235 |
|
22236 |
|
22237 |
|
22238 |
|
22239 |
|
22240 |
|
22241 |
|
22242 |
|
22243 | var createMediaTypes = function createMediaTypes() {
|
22244 | var mediaTypes = {};
|
22245 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
22246 | mediaTypes[type] = {
|
22247 | groups: {},
|
22248 | tracks: {},
|
22249 | activePlaylistLoader: null,
|
22250 | activeGroup: noop,
|
22251 | activeTrack: noop,
|
22252 | getActiveGroup: noop,
|
22253 | onGroupChanged: noop,
|
22254 | onTrackChanged: noop,
|
22255 | lastTrack_: null,
|
22256 | logger_: logger("MediaGroups[" + type + "]")
|
22257 | };
|
22258 | });
|
22259 | return mediaTypes;
|
22260 | };
|
22261 |
|
22262 | var ABORT_EARLY_BLACKLIST_SECONDS = 60 * 2;
|
22263 | var Vhs$1;
|
22264 |
|
22265 |
|
22266 | var loaderStats = ['mediaRequests', 'mediaRequestsAborted', 'mediaRequestsTimedout', 'mediaRequestsErrored', 'mediaTransferDuration', 'mediaBytesTransferred', 'mediaAppends'];
|
22267 |
|
22268 | var sumLoaderStat = function sumLoaderStat(stat) {
|
22269 | return this.audioSegmentLoader_[stat] + this.mainSegmentLoader_[stat];
|
22270 | };
|
22271 |
|
22272 | var shouldSwitchToMedia = function shouldSwitchToMedia(_ref) {
|
22273 | var currentPlaylist = _ref.currentPlaylist,
|
22274 | buffered = _ref.buffered,
|
22275 | currentTime = _ref.currentTime,
|
22276 | nextPlaylist = _ref.nextPlaylist,
|
22277 | bufferLowWaterLine = _ref.bufferLowWaterLine,
|
22278 | bufferHighWaterLine = _ref.bufferHighWaterLine,
|
22279 | duration = _ref.duration,
|
22280 | experimentalBufferBasedABR = _ref.experimentalBufferBasedABR,
|
22281 | log = _ref.log;
|
22282 |
|
22283 |
|
22284 | if (!nextPlaylist) {
|
22285 | videojs__default["default"].log.warn('We received no playlist to switch to. Please check your stream.');
|
22286 | return false;
|
22287 | }
|
22288 |
|
22289 | var sharedLogLine = "allowing switch " + (currentPlaylist && currentPlaylist.id || 'null') + " -> " + nextPlaylist.id;
|
22290 |
|
22291 | if (!currentPlaylist) {
|
22292 | log(sharedLogLine + " as current playlist is not set");
|
22293 | return true;
|
22294 | }
|
22295 |
|
22296 |
|
22297 | if (nextPlaylist.id === currentPlaylist.id) {
|
22298 | return false;
|
22299 | }
|
22300 |
|
22301 |
|
22302 | var isBuffered = Boolean(findRange(buffered, currentTime).length);
|
22303 |
|
22304 |
|
22305 |
|
22306 |
|
22307 | if (!currentPlaylist.endList) {
|
22308 |
|
22309 |
|
22310 | if (!isBuffered && typeof currentPlaylist.partTargetDuration === 'number') {
|
22311 | log("not " + sharedLogLine + " as current playlist is live llhls, but currentTime isn't in buffered.");
|
22312 | return false;
|
22313 | }
|
22314 |
|
22315 | log(sharedLogLine + " as current playlist is live");
|
22316 | return true;
|
22317 | }
|
22318 |
|
22319 | var forwardBuffer = timeAheadOf(buffered, currentTime);
|
22320 | var maxBufferLowWaterLine = experimentalBufferBasedABR ? Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE : Config.MAX_BUFFER_LOW_WATER_LINE;
|
22321 |
|
22322 |
|
22323 | if (duration < maxBufferLowWaterLine) {
|
22324 | log(sharedLogLine + " as duration < max low water line (" + duration + " < " + maxBufferLowWaterLine + ")");
|
22325 | return true;
|
22326 | }
|
22327 |
|
22328 | var nextBandwidth = nextPlaylist.attributes.BANDWIDTH;
|
22329 | var currBandwidth = currentPlaylist.attributes.BANDWIDTH;
|
22330 |
|
22331 |
|
22332 | if (nextBandwidth < currBandwidth && (!experimentalBufferBasedABR || forwardBuffer < bufferHighWaterLine)) {
|
22333 | var logLine = sharedLogLine + " as next bandwidth < current bandwidth (" + nextBandwidth + " < " + currBandwidth + ")";
|
22334 |
|
22335 | if (experimentalBufferBasedABR) {
|
22336 | logLine += " and forwardBuffer < bufferHighWaterLine (" + forwardBuffer + " < " + bufferHighWaterLine + ")";
|
22337 | }
|
22338 |
|
22339 | log(logLine);
|
22340 | return true;
|
22341 | }
|
22342 |
|
22343 |
|
22344 |
|
22345 | if ((!experimentalBufferBasedABR || nextBandwidth > currBandwidth) && forwardBuffer >= bufferLowWaterLine) {
|
22346 | var _logLine = sharedLogLine + " as forwardBuffer >= bufferLowWaterLine (" + forwardBuffer + " >= " + bufferLowWaterLine + ")";
|
22347 |
|
22348 | if (experimentalBufferBasedABR) {
|
22349 | _logLine += " and next bandwidth > current bandwidth (" + nextBandwidth + " > " + currBandwidth + ")";
|
22350 | }
|
22351 |
|
22352 | log(_logLine);
|
22353 | return true;
|
22354 | }
|
22355 |
|
22356 | log("not " + sharedLogLine + " as no switching criteria met");
|
22357 | return false;
|
22358 | };
|
22359 |
|
22360 |
|
22361 |
|
22362 |
|
22363 |
|
22364 |
|
22365 |
|
22366 |
|
22367 |
|
22368 |
|
22369 |
|
22370 | var MasterPlaylistController = function (_videojs$EventTarget) {
|
22371 | _inheritsLoose__default["default"](MasterPlaylistController, _videojs$EventTarget);
|
22372 |
|
22373 | function MasterPlaylistController(options) {
|
22374 | var _this;
|
22375 |
|
22376 | _this = _videojs$EventTarget.call(this) || this;
|
22377 | var src = options.src,
|
22378 | handleManifestRedirects = options.handleManifestRedirects,
|
22379 | withCredentials = options.withCredentials,
|
22380 | tech = options.tech,
|
22381 | bandwidth = options.bandwidth,
|
22382 | externVhs = options.externVhs,
|
22383 | useCueTags = options.useCueTags,
|
22384 | blacklistDuration = options.blacklistDuration,
|
22385 | enableLowInitialPlaylist = options.enableLowInitialPlaylist,
|
22386 | sourceType = options.sourceType,
|
22387 | cacheEncryptionKeys = options.cacheEncryptionKeys,
|
22388 | experimentalBufferBasedABR = options.experimentalBufferBasedABR,
|
22389 | experimentalLeastPixelDiffSelector = options.experimentalLeastPixelDiffSelector,
|
22390 | captionServices = options.captionServices;
|
22391 |
|
22392 | if (!src) {
|
22393 | throw new Error('A non-empty playlist URL or JSON manifest string is required');
|
22394 | }
|
22395 |
|
22396 | var maxPlaylistRetries = options.maxPlaylistRetries;
|
22397 |
|
22398 | if (maxPlaylistRetries === null || typeof maxPlaylistRetries === 'undefined') {
|
22399 | maxPlaylistRetries = Infinity;
|
22400 | }
|
22401 |
|
22402 | Vhs$1 = externVhs;
|
22403 | _this.experimentalBufferBasedABR = Boolean(experimentalBufferBasedABR);
|
22404 | _this.experimentalLeastPixelDiffSelector = Boolean(experimentalLeastPixelDiffSelector);
|
22405 | _this.withCredentials = withCredentials;
|
22406 | _this.tech_ = tech;
|
22407 | _this.vhs_ = tech.vhs;
|
22408 | _this.sourceType_ = sourceType;
|
22409 | _this.useCueTags_ = useCueTags;
|
22410 | _this.blacklistDuration = blacklistDuration;
|
22411 | _this.maxPlaylistRetries = maxPlaylistRetries;
|
22412 | _this.enableLowInitialPlaylist = enableLowInitialPlaylist;
|
22413 |
|
22414 | if (_this.useCueTags_) {
|
22415 | _this.cueTagsTrack_ = _this.tech_.addTextTrack('metadata', 'ad-cues');
|
22416 | _this.cueTagsTrack_.inBandMetadataTrackDispatchType = '';
|
22417 | }
|
22418 |
|
22419 | _this.requestOptions_ = {
|
22420 | withCredentials: withCredentials,
|
22421 | handleManifestRedirects: handleManifestRedirects,
|
22422 | maxPlaylistRetries: maxPlaylistRetries,
|
22423 | timeout: null
|
22424 | };
|
22425 |
|
22426 | _this.on('error', _this.pauseLoading);
|
22427 |
|
22428 | _this.mediaTypes_ = createMediaTypes();
|
22429 | _this.mediaSource = new window__default["default"].MediaSource();
|
22430 | _this.handleDurationChange_ = _this.handleDurationChange_.bind(_assertThisInitialized__default["default"](_this));
|
22431 | _this.handleSourceOpen_ = _this.handleSourceOpen_.bind(_assertThisInitialized__default["default"](_this));
|
22432 | _this.handleSourceEnded_ = _this.handleSourceEnded_.bind(_assertThisInitialized__default["default"](_this));
|
22433 |
|
22434 | _this.mediaSource.addEventListener('durationchange', _this.handleDurationChange_);
|
22435 |
|
22436 |
|
22437 | _this.mediaSource.addEventListener('sourceopen', _this.handleSourceOpen_);
|
22438 |
|
22439 | _this.mediaSource.addEventListener('sourceended', _this.handleSourceEnded_);
|
22440 |
|
22441 |
|
22442 |
|
22443 | _this.seekable_ = videojs__default["default"].createTimeRanges();
|
22444 | _this.hasPlayed_ = false;
|
22445 | _this.syncController_ = new SyncController(options);
|
22446 | _this.segmentMetadataTrack_ = tech.addRemoteTextTrack({
|
22447 | kind: 'metadata',
|
22448 | label: 'segment-metadata'
|
22449 | }, false).track;
|
22450 | _this.decrypter_ = new Decrypter();
|
22451 | _this.sourceUpdater_ = new SourceUpdater(_this.mediaSource);
|
22452 | _this.inbandTextTracks_ = {};
|
22453 | _this.timelineChangeController_ = new TimelineChangeController();
|
22454 | var segmentLoaderSettings = {
|
22455 | vhs: _this.vhs_,
|
22456 | parse708captions: options.parse708captions,
|
22457 | useDtsForTimestampOffset: options.useDtsForTimestampOffset,
|
22458 | captionServices: captionServices,
|
22459 | mediaSource: _this.mediaSource,
|
22460 | currentTime: _this.tech_.currentTime.bind(_this.tech_),
|
22461 | seekable: function seekable() {
|
22462 | return _this.seekable();
|
22463 | },
|
22464 | seeking: function seeking() {
|
22465 | return _this.tech_.seeking();
|
22466 | },
|
22467 | duration: function duration() {
|
22468 | return _this.duration();
|
22469 | },
|
22470 | hasPlayed: function hasPlayed() {
|
22471 | return _this.hasPlayed_;
|
22472 | },
|
22473 | goalBufferLength: function goalBufferLength() {
|
22474 | return _this.goalBufferLength();
|
22475 | },
|
22476 | bandwidth: bandwidth,
|
22477 | syncController: _this.syncController_,
|
22478 | decrypter: _this.decrypter_,
|
22479 | sourceType: _this.sourceType_,
|
22480 | inbandTextTracks: _this.inbandTextTracks_,
|
22481 | cacheEncryptionKeys: cacheEncryptionKeys,
|
22482 | sourceUpdater: _this.sourceUpdater_,
|
22483 | timelineChangeController: _this.timelineChangeController_,
|
22484 | experimentalExactManifestTimings: options.experimentalExactManifestTimings
|
22485 | };
|
22486 |
|
22487 |
|
22488 |
|
22489 |
|
22490 | _this.masterPlaylistLoader_ = _this.sourceType_ === 'dash' ? new DashPlaylistLoader(src, _this.vhs_, _this.requestOptions_) : new PlaylistLoader(src, _this.vhs_, _this.requestOptions_);
|
22491 |
|
22492 | _this.setupMasterPlaylistLoaderListeners_();
|
22493 |
|
22494 |
|
22495 |
|
22496 | _this.mainSegmentLoader_ = new SegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
22497 | segmentMetadataTrack: _this.segmentMetadataTrack_,
|
22498 | loaderType: 'main'
|
22499 | }), options);
|
22500 |
|
22501 | _this.audioSegmentLoader_ = new SegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
22502 | loaderType: 'audio'
|
22503 | }), options);
|
22504 | _this.subtitleSegmentLoader_ = new VTTSegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
22505 | loaderType: 'vtt',
|
22506 | featuresNativeTextTracks: _this.tech_.featuresNativeTextTracks,
|
22507 | loadVttJs: function loadVttJs() {
|
22508 | return new Promise(function (resolve, reject) {
|
22509 | function onLoad() {
|
22510 | tech.off('vttjserror', onError);
|
22511 | resolve();
|
22512 | }
|
22513 |
|
22514 | function onError() {
|
22515 | tech.off('vttjsloaded', onLoad);
|
22516 | reject();
|
22517 | }
|
22518 |
|
22519 | tech.one('vttjsloaded', onLoad);
|
22520 | tech.one('vttjserror', onError);
|
22521 |
|
22522 | tech.addWebVttScript_();
|
22523 | });
|
22524 | }
|
22525 | }), options);
|
22526 |
|
22527 | _this.setupSegmentLoaderListeners_();
|
22528 |
|
22529 | if (_this.experimentalBufferBasedABR) {
|
22530 | _this.masterPlaylistLoader_.one('loadedplaylist', function () {
|
22531 | return _this.startABRTimer_();
|
22532 | });
|
22533 |
|
22534 | _this.tech_.on('pause', function () {
|
22535 | return _this.stopABRTimer_();
|
22536 | });
|
22537 |
|
22538 | _this.tech_.on('play', function () {
|
22539 | return _this.startABRTimer_();
|
22540 | });
|
22541 | }
|
22542 |
|
22543 |
|
22544 |
|
22545 |
|
22546 |
|
22547 |
|
22548 |
|
22549 |
|
22550 |
|
22551 | loaderStats.forEach(function (stat) {
|
22552 | _this[stat + '_'] = sumLoaderStat.bind(_assertThisInitialized__default["default"](_this), stat);
|
22553 | });
|
22554 | _this.logger_ = logger('MPC');
|
22555 | _this.triggeredFmp4Usage = false;
|
22556 |
|
22557 | if (_this.tech_.preload() === 'none') {
|
22558 | _this.loadOnPlay_ = function () {
|
22559 | _this.loadOnPlay_ = null;
|
22560 |
|
22561 | _this.masterPlaylistLoader_.load();
|
22562 | };
|
22563 |
|
22564 | _this.tech_.one('play', _this.loadOnPlay_);
|
22565 | } else {
|
22566 | _this.masterPlaylistLoader_.load();
|
22567 | }
|
22568 |
|
22569 | _this.timeToLoadedData__ = -1;
|
22570 | _this.mainAppendsToLoadedData__ = -1;
|
22571 | _this.audioAppendsToLoadedData__ = -1;
|
22572 | var event = _this.tech_.preload() === 'none' ? 'play' : 'loadstart';
|
22573 |
|
22574 | _this.tech_.one(event, function () {
|
22575 | var timeToLoadedDataStart = Date.now();
|
22576 |
|
22577 | _this.tech_.one('loadeddata', function () {
|
22578 | _this.timeToLoadedData__ = Date.now() - timeToLoadedDataStart;
|
22579 | _this.mainAppendsToLoadedData__ = _this.mainSegmentLoader_.mediaAppends;
|
22580 | _this.audioAppendsToLoadedData__ = _this.audioSegmentLoader_.mediaAppends;
|
22581 | });
|
22582 | });
|
22583 |
|
22584 | return _this;
|
22585 | }
|
22586 |
|
22587 | var _proto = MasterPlaylistController.prototype;
|
22588 |
|
22589 | _proto.mainAppendsToLoadedData_ = function mainAppendsToLoadedData_() {
|
22590 | return this.mainAppendsToLoadedData__;
|
22591 | };
|
22592 |
|
22593 | _proto.audioAppendsToLoadedData_ = function audioAppendsToLoadedData_() {
|
22594 | return this.audioAppendsToLoadedData__;
|
22595 | };
|
22596 |
|
22597 | _proto.appendsToLoadedData_ = function appendsToLoadedData_() {
|
22598 | var main = this.mainAppendsToLoadedData_();
|
22599 | var audio = this.audioAppendsToLoadedData_();
|
22600 |
|
22601 | if (main === -1 || audio === -1) {
|
22602 | return -1;
|
22603 | }
|
22604 |
|
22605 | return main + audio;
|
22606 | };
|
22607 |
|
22608 | _proto.timeToLoadedData_ = function timeToLoadedData_() {
|
22609 | return this.timeToLoadedData__;
|
22610 | }
|
22611 | |
22612 |
|
22613 |
|
22614 |
|
22615 |
|
22616 |
|
22617 | ;
|
22618 |
|
22619 | _proto.checkABR_ = function checkABR_(reason) {
|
22620 | if (reason === void 0) {
|
22621 | reason = 'abr';
|
22622 | }
|
22623 |
|
22624 | var nextPlaylist = this.selectPlaylist();
|
22625 |
|
22626 | if (nextPlaylist && this.shouldSwitchToMedia_(nextPlaylist)) {
|
22627 | this.switchMedia_(nextPlaylist, reason);
|
22628 | }
|
22629 | };
|
22630 |
|
22631 | _proto.switchMedia_ = function switchMedia_(playlist, cause, delay) {
|
22632 | var oldMedia = this.media();
|
22633 | var oldId = oldMedia && (oldMedia.id || oldMedia.uri);
|
22634 | var newId = playlist.id || playlist.uri;
|
22635 |
|
22636 | if (oldId && oldId !== newId) {
|
22637 | this.logger_("switch media " + oldId + " -> " + newId + " from " + cause);
|
22638 | this.tech_.trigger({
|
22639 | type: 'usage',
|
22640 | name: "vhs-rendition-change-" + cause
|
22641 | });
|
22642 | }
|
22643 |
|
22644 | this.masterPlaylistLoader_.media(playlist, delay);
|
22645 | }
|
22646 | |
22647 |
|
22648 |
|
22649 |
|
22650 |
|
22651 | ;
|
22652 |
|
22653 | _proto.startABRTimer_ = function startABRTimer_() {
|
22654 | var _this2 = this;
|
22655 |
|
22656 | this.stopABRTimer_();
|
22657 | this.abrTimer_ = window__default["default"].setInterval(function () {
|
22658 | return _this2.checkABR_();
|
22659 | }, 250);
|
22660 | }
|
22661 | |
22662 |
|
22663 |
|
22664 |
|
22665 |
|
22666 | ;
|
22667 |
|
22668 | _proto.stopABRTimer_ = function stopABRTimer_() {
|
22669 |
|
22670 |
|
22671 | if (this.tech_.scrubbing && this.tech_.scrubbing()) {
|
22672 | return;
|
22673 | }
|
22674 |
|
22675 | window__default["default"].clearInterval(this.abrTimer_);
|
22676 | this.abrTimer_ = null;
|
22677 | }
|
22678 | |
22679 |
|
22680 |
|
22681 |
|
22682 |
|
22683 | ;
|
22684 |
|
22685 | _proto.getAudioTrackPlaylists_ = function getAudioTrackPlaylists_() {
|
22686 | var master = this.master();
|
22687 | var defaultPlaylists = master && master.playlists || [];
|
22688 |
|
22689 |
|
22690 |
|
22691 | if (!master || !master.mediaGroups || !master.mediaGroups.AUDIO) {
|
22692 | return defaultPlaylists;
|
22693 | }
|
22694 |
|
22695 | var AUDIO = master.mediaGroups.AUDIO;
|
22696 | var groupKeys = Object.keys(AUDIO);
|
22697 | var track;
|
22698 |
|
22699 | if (Object.keys(this.mediaTypes_.AUDIO.groups).length) {
|
22700 | track = this.mediaTypes_.AUDIO.activeTrack();
|
22701 | } else {
|
22702 |
|
22703 | var defaultGroup = AUDIO.main || groupKeys.length && AUDIO[groupKeys[0]];
|
22704 |
|
22705 | for (var label in defaultGroup) {
|
22706 | if (defaultGroup[label].default) {
|
22707 | track = {
|
22708 | label: label
|
22709 | };
|
22710 | break;
|
22711 | }
|
22712 | }
|
22713 | }
|
22714 |
|
22715 |
|
22716 | if (!track) {
|
22717 | return defaultPlaylists;
|
22718 | }
|
22719 |
|
22720 | var playlists = [];
|
22721 |
|
22722 |
|
22723 | for (var group in AUDIO) {
|
22724 | if (AUDIO[group][track.label]) {
|
22725 | var properties = AUDIO[group][track.label];
|
22726 |
|
22727 | if (properties.playlists && properties.playlists.length) {
|
22728 | playlists.push.apply(playlists, properties.playlists);
|
22729 | } else if (properties.uri) {
|
22730 | playlists.push(properties);
|
22731 | } else if (master.playlists.length) {
|
22732 |
|
22733 |
|
22734 |
|
22735 | for (var i = 0; i < master.playlists.length; i++) {
|
22736 | var playlist = master.playlists[i];
|
22737 |
|
22738 | if (playlist.attributes && playlist.attributes.AUDIO && playlist.attributes.AUDIO === group) {
|
22739 | playlists.push(playlist);
|
22740 | }
|
22741 | }
|
22742 | }
|
22743 | }
|
22744 | }
|
22745 |
|
22746 | if (!playlists.length) {
|
22747 | return defaultPlaylists;
|
22748 | }
|
22749 |
|
22750 | return playlists;
|
22751 | }
|
22752 | |
22753 |
|
22754 |
|
22755 |
|
22756 |
|
22757 |
|
22758 | ;
|
22759 |
|
22760 | _proto.setupMasterPlaylistLoaderListeners_ = function setupMasterPlaylistLoaderListeners_() {
|
22761 | var _this3 = this;
|
22762 |
|
22763 | this.masterPlaylistLoader_.on('loadedmetadata', function () {
|
22764 | var media = _this3.masterPlaylistLoader_.media();
|
22765 |
|
22766 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
22767 |
|
22768 |
|
22769 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
22770 | _this3.requestOptions_.timeout = 0;
|
22771 | } else {
|
22772 | _this3.requestOptions_.timeout = requestTimeout;
|
22773 | }
|
22774 |
|
22775 |
|
22776 |
|
22777 | if (media.endList && _this3.tech_.preload() !== 'none') {
|
22778 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
22779 |
|
22780 | _this3.mainSegmentLoader_.load();
|
22781 | }
|
22782 |
|
22783 | setupMediaGroups({
|
22784 | sourceType: _this3.sourceType_,
|
22785 | segmentLoaders: {
|
22786 | AUDIO: _this3.audioSegmentLoader_,
|
22787 | SUBTITLES: _this3.subtitleSegmentLoader_,
|
22788 | main: _this3.mainSegmentLoader_
|
22789 | },
|
22790 | tech: _this3.tech_,
|
22791 | requestOptions: _this3.requestOptions_,
|
22792 | masterPlaylistLoader: _this3.masterPlaylistLoader_,
|
22793 | vhs: _this3.vhs_,
|
22794 | master: _this3.master(),
|
22795 | mediaTypes: _this3.mediaTypes_,
|
22796 | blacklistCurrentPlaylist: _this3.blacklistCurrentPlaylist.bind(_this3)
|
22797 | });
|
22798 |
|
22799 | _this3.triggerPresenceUsage_(_this3.master(), media);
|
22800 |
|
22801 | _this3.setupFirstPlay();
|
22802 |
|
22803 | if (!_this3.mediaTypes_.AUDIO.activePlaylistLoader || _this3.mediaTypes_.AUDIO.activePlaylistLoader.media()) {
|
22804 | _this3.trigger('selectedinitialmedia');
|
22805 | } else {
|
22806 |
|
22807 |
|
22808 |
|
22809 | _this3.mediaTypes_.AUDIO.activePlaylistLoader.one('loadedmetadata', function () {
|
22810 | _this3.trigger('selectedinitialmedia');
|
22811 | });
|
22812 | }
|
22813 | });
|
22814 | this.masterPlaylistLoader_.on('loadedplaylist', function () {
|
22815 | if (_this3.loadOnPlay_) {
|
22816 | _this3.tech_.off('play', _this3.loadOnPlay_);
|
22817 | }
|
22818 |
|
22819 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
22820 |
|
22821 | if (!updatedPlaylist) {
|
22822 |
|
22823 |
|
22824 | _this3.excludeUnsupportedVariants_();
|
22825 |
|
22826 | var selectedMedia;
|
22827 |
|
22828 | if (_this3.enableLowInitialPlaylist) {
|
22829 | selectedMedia = _this3.selectInitialPlaylist();
|
22830 | }
|
22831 |
|
22832 | if (!selectedMedia) {
|
22833 | selectedMedia = _this3.selectPlaylist();
|
22834 | }
|
22835 |
|
22836 | if (!selectedMedia || !_this3.shouldSwitchToMedia_(selectedMedia)) {
|
22837 | return;
|
22838 | }
|
22839 |
|
22840 | _this3.initialMedia_ = selectedMedia;
|
22841 |
|
22842 | _this3.switchMedia_(_this3.initialMedia_, 'initial');
|
22843 |
|
22844 |
|
22845 |
|
22846 |
|
22847 |
|
22848 |
|
22849 |
|
22850 | var haveJsonSource = _this3.sourceType_ === 'vhs-json' && _this3.initialMedia_.segments;
|
22851 |
|
22852 | if (!haveJsonSource) {
|
22853 | return;
|
22854 | }
|
22855 |
|
22856 | updatedPlaylist = _this3.initialMedia_;
|
22857 | }
|
22858 |
|
22859 | _this3.handleUpdatedMediaPlaylist(updatedPlaylist);
|
22860 | });
|
22861 | this.masterPlaylistLoader_.on('error', function () {
|
22862 | _this3.blacklistCurrentPlaylist(_this3.masterPlaylistLoader_.error);
|
22863 | });
|
22864 | this.masterPlaylistLoader_.on('mediachanging', function () {
|
22865 | _this3.mainSegmentLoader_.abort();
|
22866 |
|
22867 | _this3.mainSegmentLoader_.pause();
|
22868 | });
|
22869 | this.masterPlaylistLoader_.on('mediachange', function () {
|
22870 | var media = _this3.masterPlaylistLoader_.media();
|
22871 |
|
22872 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
22873 |
|
22874 |
|
22875 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
22876 | _this3.requestOptions_.timeout = 0;
|
22877 | } else {
|
22878 | _this3.requestOptions_.timeout = requestTimeout;
|
22879 | }
|
22880 |
|
22881 | _this3.masterPlaylistLoader_.load();
|
22882 |
|
22883 |
|
22884 |
|
22885 |
|
22886 |
|
22887 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
22888 |
|
22889 | _this3.mainSegmentLoader_.load();
|
22890 |
|
22891 | _this3.tech_.trigger({
|
22892 | type: 'mediachange',
|
22893 | bubbles: true
|
22894 | });
|
22895 | });
|
22896 | this.masterPlaylistLoader_.on('playlistunchanged', function () {
|
22897 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
22898 |
|
22899 |
|
22900 |
|
22901 |
|
22902 | if (updatedPlaylist.lastExcludeReason_ === 'playlist-unchanged') {
|
22903 | return;
|
22904 | }
|
22905 |
|
22906 | var playlistOutdated = _this3.stuckAtPlaylistEnd_(updatedPlaylist);
|
22907 |
|
22908 | if (playlistOutdated) {
|
22909 |
|
22910 |
|
22911 |
|
22912 |
|
22913 | _this3.blacklistCurrentPlaylist({
|
22914 | message: 'Playlist no longer updating.',
|
22915 | reason: 'playlist-unchanged'
|
22916 | });
|
22917 |
|
22918 |
|
22919 | _this3.tech_.trigger('playliststuck');
|
22920 | }
|
22921 | });
|
22922 | this.masterPlaylistLoader_.on('renditiondisabled', function () {
|
22923 | _this3.tech_.trigger({
|
22924 | type: 'usage',
|
22925 | name: 'vhs-rendition-disabled'
|
22926 | });
|
22927 |
|
22928 | _this3.tech_.trigger({
|
22929 | type: 'usage',
|
22930 | name: 'hls-rendition-disabled'
|
22931 | });
|
22932 | });
|
22933 | this.masterPlaylistLoader_.on('renditionenabled', function () {
|
22934 | _this3.tech_.trigger({
|
22935 | type: 'usage',
|
22936 | name: 'vhs-rendition-enabled'
|
22937 | });
|
22938 |
|
22939 | _this3.tech_.trigger({
|
22940 | type: 'usage',
|
22941 | name: 'hls-rendition-enabled'
|
22942 | });
|
22943 | });
|
22944 | }
|
22945 | |
22946 |
|
22947 |
|
22948 |
|
22949 |
|
22950 |
|
22951 |
|
22952 |
|
22953 |
|
22954 | ;
|
22955 |
|
22956 | _proto.handleUpdatedMediaPlaylist = function handleUpdatedMediaPlaylist(updatedPlaylist) {
|
22957 | if (this.useCueTags_) {
|
22958 | this.updateAdCues_(updatedPlaylist);
|
22959 | }
|
22960 |
|
22961 |
|
22962 |
|
22963 |
|
22964 |
|
22965 | this.mainSegmentLoader_.playlist(updatedPlaylist, this.requestOptions_);
|
22966 | this.updateDuration(!updatedPlaylist.endList);
|
22967 |
|
22968 |
|
22969 |
|
22970 | if (!this.tech_.paused()) {
|
22971 | this.mainSegmentLoader_.load();
|
22972 |
|
22973 | if (this.audioSegmentLoader_) {
|
22974 | this.audioSegmentLoader_.load();
|
22975 | }
|
22976 | }
|
22977 | }
|
22978 | |
22979 |
|
22980 |
|
22981 |
|
22982 |
|
22983 | ;
|
22984 |
|
22985 | _proto.triggerPresenceUsage_ = function triggerPresenceUsage_(master, media) {
|
22986 | var mediaGroups = master.mediaGroups || {};
|
22987 | var defaultDemuxed = true;
|
22988 | var audioGroupKeys = Object.keys(mediaGroups.AUDIO);
|
22989 |
|
22990 | for (var mediaGroup in mediaGroups.AUDIO) {
|
22991 | for (var label in mediaGroups.AUDIO[mediaGroup]) {
|
22992 | var properties = mediaGroups.AUDIO[mediaGroup][label];
|
22993 |
|
22994 | if (!properties.uri) {
|
22995 | defaultDemuxed = false;
|
22996 | }
|
22997 | }
|
22998 | }
|
22999 |
|
23000 | if (defaultDemuxed) {
|
23001 | this.tech_.trigger({
|
23002 | type: 'usage',
|
23003 | name: 'vhs-demuxed'
|
23004 | });
|
23005 | this.tech_.trigger({
|
23006 | type: 'usage',
|
23007 | name: 'hls-demuxed'
|
23008 | });
|
23009 | }
|
23010 |
|
23011 | if (Object.keys(mediaGroups.SUBTITLES).length) {
|
23012 | this.tech_.trigger({
|
23013 | type: 'usage',
|
23014 | name: 'vhs-webvtt'
|
23015 | });
|
23016 | this.tech_.trigger({
|
23017 | type: 'usage',
|
23018 | name: 'hls-webvtt'
|
23019 | });
|
23020 | }
|
23021 |
|
23022 | if (Vhs$1.Playlist.isAes(media)) {
|
23023 | this.tech_.trigger({
|
23024 | type: 'usage',
|
23025 | name: 'vhs-aes'
|
23026 | });
|
23027 | this.tech_.trigger({
|
23028 | type: 'usage',
|
23029 | name: 'hls-aes'
|
23030 | });
|
23031 | }
|
23032 |
|
23033 | if (audioGroupKeys.length && Object.keys(mediaGroups.AUDIO[audioGroupKeys[0]]).length > 1) {
|
23034 | this.tech_.trigger({
|
23035 | type: 'usage',
|
23036 | name: 'vhs-alternate-audio'
|
23037 | });
|
23038 | this.tech_.trigger({
|
23039 | type: 'usage',
|
23040 | name: 'hls-alternate-audio'
|
23041 | });
|
23042 | }
|
23043 |
|
23044 | if (this.useCueTags_) {
|
23045 | this.tech_.trigger({
|
23046 | type: 'usage',
|
23047 | name: 'vhs-playlist-cue-tags'
|
23048 | });
|
23049 | this.tech_.trigger({
|
23050 | type: 'usage',
|
23051 | name: 'hls-playlist-cue-tags'
|
23052 | });
|
23053 | }
|
23054 | };
|
23055 |
|
23056 | _proto.shouldSwitchToMedia_ = function shouldSwitchToMedia_(nextPlaylist) {
|
23057 | var currentPlaylist = this.masterPlaylistLoader_.media() || this.masterPlaylistLoader_.pendingMedia_;
|
23058 | var currentTime = this.tech_.currentTime();
|
23059 | var bufferLowWaterLine = this.bufferLowWaterLine();
|
23060 | var bufferHighWaterLine = this.bufferHighWaterLine();
|
23061 | var buffered = this.tech_.buffered();
|
23062 | return shouldSwitchToMedia({
|
23063 | buffered: buffered,
|
23064 | currentTime: currentTime,
|
23065 | currentPlaylist: currentPlaylist,
|
23066 | nextPlaylist: nextPlaylist,
|
23067 | bufferLowWaterLine: bufferLowWaterLine,
|
23068 | bufferHighWaterLine: bufferHighWaterLine,
|
23069 | duration: this.duration(),
|
23070 | experimentalBufferBasedABR: this.experimentalBufferBasedABR,
|
23071 | log: this.logger_
|
23072 | });
|
23073 | }
|
23074 | |
23075 |
|
23076 |
|
23077 |
|
23078 |
|
23079 |
|
23080 | ;
|
23081 |
|
23082 | _proto.setupSegmentLoaderListeners_ = function setupSegmentLoaderListeners_() {
|
23083 | var _this4 = this;
|
23084 |
|
23085 | this.mainSegmentLoader_.on('bandwidthupdate', function () {
|
23086 |
|
23087 |
|
23088 | _this4.checkABR_('bandwidthupdate');
|
23089 |
|
23090 | _this4.tech_.trigger('bandwidthupdate');
|
23091 | });
|
23092 | this.mainSegmentLoader_.on('timeout', function () {
|
23093 | if (_this4.experimentalBufferBasedABR) {
|
23094 |
|
23095 |
|
23096 |
|
23097 |
|
23098 | _this4.mainSegmentLoader_.load();
|
23099 | }
|
23100 | });
|
23101 |
|
23102 |
|
23103 | if (!this.experimentalBufferBasedABR) {
|
23104 | this.mainSegmentLoader_.on('progress', function () {
|
23105 | _this4.trigger('progress');
|
23106 | });
|
23107 | }
|
23108 |
|
23109 | this.mainSegmentLoader_.on('error', function () {
|
23110 | _this4.blacklistCurrentPlaylist(_this4.mainSegmentLoader_.error());
|
23111 | });
|
23112 | this.mainSegmentLoader_.on('appenderror', function () {
|
23113 | _this4.error = _this4.mainSegmentLoader_.error_;
|
23114 |
|
23115 | _this4.trigger('error');
|
23116 | });
|
23117 | this.mainSegmentLoader_.on('syncinfoupdate', function () {
|
23118 | _this4.onSyncInfoUpdate_();
|
23119 | });
|
23120 | this.mainSegmentLoader_.on('timestampoffset', function () {
|
23121 | _this4.tech_.trigger({
|
23122 | type: 'usage',
|
23123 | name: 'vhs-timestamp-offset'
|
23124 | });
|
23125 |
|
23126 | _this4.tech_.trigger({
|
23127 | type: 'usage',
|
23128 | name: 'hls-timestamp-offset'
|
23129 | });
|
23130 | });
|
23131 | this.audioSegmentLoader_.on('syncinfoupdate', function () {
|
23132 | _this4.onSyncInfoUpdate_();
|
23133 | });
|
23134 | this.audioSegmentLoader_.on('appenderror', function () {
|
23135 | _this4.error = _this4.audioSegmentLoader_.error_;
|
23136 |
|
23137 | _this4.trigger('error');
|
23138 | });
|
23139 | this.mainSegmentLoader_.on('ended', function () {
|
23140 | _this4.logger_('main segment loader ended');
|
23141 |
|
23142 | _this4.onEndOfStream();
|
23143 | });
|
23144 | this.mainSegmentLoader_.on('earlyabort', function (event) {
|
23145 |
|
23146 | if (_this4.experimentalBufferBasedABR) {
|
23147 | return;
|
23148 | }
|
23149 |
|
23150 | _this4.delegateLoaders_('all', ['abort']);
|
23151 |
|
23152 | _this4.blacklistCurrentPlaylist({
|
23153 | message: 'Aborted early because there isn\'t enough bandwidth to complete the ' + 'request without rebuffering.'
|
23154 | }, ABORT_EARLY_BLACKLIST_SECONDS);
|
23155 | });
|
23156 |
|
23157 | var updateCodecs = function updateCodecs() {
|
23158 | if (!_this4.sourceUpdater_.hasCreatedSourceBuffers()) {
|
23159 | return _this4.tryToCreateSourceBuffers_();
|
23160 | }
|
23161 |
|
23162 | var codecs = _this4.getCodecsOrExclude_();
|
23163 |
|
23164 |
|
23165 | if (!codecs) {
|
23166 | return;
|
23167 | }
|
23168 |
|
23169 | _this4.sourceUpdater_.addOrChangeSourceBuffers(codecs);
|
23170 | };
|
23171 |
|
23172 | this.mainSegmentLoader_.on('trackinfo', updateCodecs);
|
23173 | this.audioSegmentLoader_.on('trackinfo', updateCodecs);
|
23174 | this.mainSegmentLoader_.on('fmp4', function () {
|
23175 | if (!_this4.triggeredFmp4Usage) {
|
23176 | _this4.tech_.trigger({
|
23177 | type: 'usage',
|
23178 | name: 'vhs-fmp4'
|
23179 | });
|
23180 |
|
23181 | _this4.tech_.trigger({
|
23182 | type: 'usage',
|
23183 | name: 'hls-fmp4'
|
23184 | });
|
23185 |
|
23186 | _this4.triggeredFmp4Usage = true;
|
23187 | }
|
23188 | });
|
23189 | this.audioSegmentLoader_.on('fmp4', function () {
|
23190 | if (!_this4.triggeredFmp4Usage) {
|
23191 | _this4.tech_.trigger({
|
23192 | type: 'usage',
|
23193 | name: 'vhs-fmp4'
|
23194 | });
|
23195 |
|
23196 | _this4.tech_.trigger({
|
23197 | type: 'usage',
|
23198 | name: 'hls-fmp4'
|
23199 | });
|
23200 |
|
23201 | _this4.triggeredFmp4Usage = true;
|
23202 | }
|
23203 | });
|
23204 | this.audioSegmentLoader_.on('ended', function () {
|
23205 | _this4.logger_('audioSegmentLoader ended');
|
23206 |
|
23207 | _this4.onEndOfStream();
|
23208 | });
|
23209 | };
|
23210 |
|
23211 | _proto.mediaSecondsLoaded_ = function mediaSecondsLoaded_() {
|
23212 | return Math.max(this.audioSegmentLoader_.mediaSecondsLoaded + this.mainSegmentLoader_.mediaSecondsLoaded);
|
23213 | }
|
23214 | |
23215 |
|
23216 |
|
23217 | ;
|
23218 |
|
23219 | _proto.load = function load() {
|
23220 | this.mainSegmentLoader_.load();
|
23221 |
|
23222 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23223 | this.audioSegmentLoader_.load();
|
23224 | }
|
23225 |
|
23226 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
23227 | this.subtitleSegmentLoader_.load();
|
23228 | }
|
23229 | }
|
23230 | |
23231 |
|
23232 |
|
23233 |
|
23234 |
|
23235 |
|
23236 |
|
23237 |
|
23238 | ;
|
23239 |
|
23240 | _proto.smoothQualityChange_ = function smoothQualityChange_(media) {
|
23241 | if (media === void 0) {
|
23242 | media = this.selectPlaylist();
|
23243 | }
|
23244 |
|
23245 | this.fastQualityChange_(media);
|
23246 | }
|
23247 | |
23248 |
|
23249 |
|
23250 |
|
23251 |
|
23252 |
|
23253 |
|
23254 |
|
23255 | ;
|
23256 |
|
23257 | _proto.fastQualityChange_ = function fastQualityChange_(media) {
|
23258 | var _this5 = this;
|
23259 |
|
23260 | if (media === void 0) {
|
23261 | media = this.selectPlaylist();
|
23262 | }
|
23263 |
|
23264 | if (media === this.masterPlaylistLoader_.media()) {
|
23265 | this.logger_('skipping fastQualityChange because new media is same as old');
|
23266 | return;
|
23267 | }
|
23268 |
|
23269 | this.switchMedia_(media, 'fast-quality');
|
23270 |
|
23271 |
|
23272 |
|
23273 |
|
23274 |
|
23275 |
|
23276 | this.mainSegmentLoader_.resetEverything(function () {
|
23277 |
|
23278 |
|
23279 | if (videojs__default["default"].browser.IE_VERSION || videojs__default["default"].browser.IS_EDGE) {
|
23280 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime() + 0.04);
|
23281 | } else {
|
23282 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime());
|
23283 | }
|
23284 | });
|
23285 | }
|
23286 | |
23287 |
|
23288 |
|
23289 | ;
|
23290 |
|
23291 | _proto.play = function play() {
|
23292 | if (this.setupFirstPlay()) {
|
23293 | return;
|
23294 | }
|
23295 |
|
23296 | if (this.tech_.ended()) {
|
23297 | this.tech_.setCurrentTime(0);
|
23298 | }
|
23299 |
|
23300 | if (this.hasPlayed_) {
|
23301 | this.load();
|
23302 | }
|
23303 |
|
23304 | var seekable = this.tech_.seekable();
|
23305 |
|
23306 |
|
23307 | if (this.tech_.duration() === Infinity) {
|
23308 | if (this.tech_.currentTime() < seekable.start(0)) {
|
23309 | return this.tech_.setCurrentTime(seekable.end(seekable.length - 1));
|
23310 | }
|
23311 | }
|
23312 | }
|
23313 | |
23314 |
|
23315 |
|
23316 |
|
23317 | ;
|
23318 |
|
23319 | _proto.setupFirstPlay = function setupFirstPlay() {
|
23320 | var _this6 = this;
|
23321 |
|
23322 | var media = this.masterPlaylistLoader_.media();
|
23323 |
|
23324 |
|
23325 |
|
23326 |
|
23327 |
|
23328 | if (!media || this.tech_.paused() || this.hasPlayed_) {
|
23329 | return false;
|
23330 | }
|
23331 |
|
23332 |
|
23333 | if (!media.endList) {
|
23334 | var seekable = this.seekable();
|
23335 |
|
23336 | if (!seekable.length) {
|
23337 |
|
23338 |
|
23339 | return false;
|
23340 | }
|
23341 |
|
23342 | if (videojs__default["default"].browser.IE_VERSION && this.tech_.readyState() === 0) {
|
23343 |
|
23344 |
|
23345 | this.tech_.one('loadedmetadata', function () {
|
23346 | _this6.trigger('firstplay');
|
23347 |
|
23348 | _this6.tech_.setCurrentTime(seekable.end(0));
|
23349 |
|
23350 | _this6.hasPlayed_ = true;
|
23351 | });
|
23352 | return false;
|
23353 | }
|
23354 |
|
23355 |
|
23356 | this.trigger('firstplay');
|
23357 |
|
23358 | this.tech_.setCurrentTime(seekable.end(0));
|
23359 | }
|
23360 |
|
23361 | this.hasPlayed_ = true;
|
23362 |
|
23363 | this.load();
|
23364 | return true;
|
23365 | }
|
23366 | |
23367 |
|
23368 |
|
23369 |
|
23370 |
|
23371 | ;
|
23372 |
|
23373 | _proto.handleSourceOpen_ = function handleSourceOpen_() {
|
23374 |
|
23375 |
|
23376 |
|
23377 | this.tryToCreateSourceBuffers_();
|
23378 |
|
23379 |
|
23380 |
|
23381 | if (this.tech_.autoplay()) {
|
23382 | var playPromise = this.tech_.play();
|
23383 |
|
23384 |
|
23385 | if (typeof playPromise !== 'undefined' && typeof playPromise.then === 'function') {
|
23386 | playPromise.then(null, function (e) {});
|
23387 | }
|
23388 | }
|
23389 |
|
23390 | this.trigger('sourceopen');
|
23391 | }
|
23392 | |
23393 |
|
23394 |
|
23395 |
|
23396 |
|
23397 | ;
|
23398 |
|
23399 | _proto.handleSourceEnded_ = function handleSourceEnded_() {
|
23400 | if (!this.inbandTextTracks_.metadataTrack_) {
|
23401 | return;
|
23402 | }
|
23403 |
|
23404 | var cues = this.inbandTextTracks_.metadataTrack_.cues;
|
23405 |
|
23406 | if (!cues || !cues.length) {
|
23407 | return;
|
23408 | }
|
23409 |
|
23410 | var duration = this.duration();
|
23411 | cues[cues.length - 1].endTime = isNaN(duration) || Math.abs(duration) === Infinity ? Number.MAX_VALUE : duration;
|
23412 | }
|
23413 | |
23414 |
|
23415 |
|
23416 |
|
23417 |
|
23418 | ;
|
23419 |
|
23420 | _proto.handleDurationChange_ = function handleDurationChange_() {
|
23421 | this.tech_.trigger('durationchange');
|
23422 | }
|
23423 | |
23424 |
|
23425 |
|
23426 |
|
23427 |
|
23428 |
|
23429 |
|
23430 |
|
23431 | ;
|
23432 |
|
23433 | _proto.onEndOfStream = function onEndOfStream() {
|
23434 | var isEndOfStream = this.mainSegmentLoader_.ended_;
|
23435 |
|
23436 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23437 | var mainMediaInfo = this.mainSegmentLoader_.getCurrentMediaInfo_();
|
23438 |
|
23439 | if (!mainMediaInfo || mainMediaInfo.hasVideo) {
|
23440 |
|
23441 |
|
23442 |
|
23443 | isEndOfStream = isEndOfStream && this.audioSegmentLoader_.ended_;
|
23444 | } else {
|
23445 |
|
23446 | isEndOfStream = this.audioSegmentLoader_.ended_;
|
23447 | }
|
23448 | }
|
23449 |
|
23450 | if (!isEndOfStream) {
|
23451 | return;
|
23452 | }
|
23453 |
|
23454 | this.stopABRTimer_();
|
23455 | this.sourceUpdater_.endOfStream();
|
23456 | }
|
23457 | |
23458 |
|
23459 |
|
23460 |
|
23461 |
|
23462 |
|
23463 | ;
|
23464 |
|
23465 | _proto.stuckAtPlaylistEnd_ = function stuckAtPlaylistEnd_(playlist) {
|
23466 | var seekable = this.seekable();
|
23467 |
|
23468 | if (!seekable.length) {
|
23469 |
|
23470 | return false;
|
23471 | }
|
23472 |
|
23473 | var expired = this.syncController_.getExpiredTime(playlist, this.duration());
|
23474 |
|
23475 | if (expired === null) {
|
23476 | return false;
|
23477 | }
|
23478 |
|
23479 |
|
23480 |
|
23481 | var absolutePlaylistEnd = Vhs$1.Playlist.playlistEnd(playlist, expired);
|
23482 | var currentTime = this.tech_.currentTime();
|
23483 | var buffered = this.tech_.buffered();
|
23484 |
|
23485 | if (!buffered.length) {
|
23486 |
|
23487 | return absolutePlaylistEnd - currentTime <= SAFE_TIME_DELTA;
|
23488 | }
|
23489 |
|
23490 | var bufferedEnd = buffered.end(buffered.length - 1);
|
23491 |
|
23492 |
|
23493 | return bufferedEnd - currentTime <= SAFE_TIME_DELTA && absolutePlaylistEnd - bufferedEnd <= SAFE_TIME_DELTA;
|
23494 | }
|
23495 | |
23496 |
|
23497 |
|
23498 |
|
23499 |
|
23500 |
|
23501 |
|
23502 |
|
23503 |
|
23504 |
|
23505 | ;
|
23506 |
|
23507 | _proto.blacklistCurrentPlaylist = function blacklistCurrentPlaylist(error, blacklistDuration) {
|
23508 | if (error === void 0) {
|
23509 | error = {};
|
23510 | }
|
23511 |
|
23512 |
|
23513 |
|
23514 |
|
23515 |
|
23516 | var currentPlaylist = error.playlist || this.masterPlaylistLoader_.media();
|
23517 | blacklistDuration = blacklistDuration || error.blacklistDuration || this.blacklistDuration;
|
23518 |
|
23519 |
|
23520 | if (!currentPlaylist) {
|
23521 | this.error = error;
|
23522 |
|
23523 | if (this.mediaSource.readyState !== 'open') {
|
23524 | this.trigger('error');
|
23525 | } else {
|
23526 | this.sourceUpdater_.endOfStream('network');
|
23527 | }
|
23528 |
|
23529 | return;
|
23530 | }
|
23531 |
|
23532 | currentPlaylist.playlistErrors_++;
|
23533 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
23534 | var enabledPlaylists = playlists.filter(isEnabled);
|
23535 | var isFinalRendition = enabledPlaylists.length === 1 && enabledPlaylists[0] === currentPlaylist;
|
23536 |
|
23537 |
|
23538 | if (playlists.length === 1 && blacklistDuration !== Infinity) {
|
23539 | videojs__default["default"].log.warn("Problem encountered with playlist " + currentPlaylist.id + ". " + 'Trying again since it is the only playlist.');
|
23540 | this.tech_.trigger('retryplaylist');
|
23541 |
|
23542 | return this.masterPlaylistLoader_.load(isFinalRendition);
|
23543 | }
|
23544 |
|
23545 | if (isFinalRendition) {
|
23546 |
|
23547 |
|
23548 |
|
23549 |
|
23550 | var reincluded = false;
|
23551 | playlists.forEach(function (playlist) {
|
23552 |
|
23553 | if (playlist === currentPlaylist) {
|
23554 | return;
|
23555 | }
|
23556 |
|
23557 | var excludeUntil = playlist.excludeUntil;
|
23558 |
|
23559 | if (typeof excludeUntil !== 'undefined' && excludeUntil !== Infinity) {
|
23560 | reincluded = true;
|
23561 | delete playlist.excludeUntil;
|
23562 | }
|
23563 | });
|
23564 |
|
23565 | if (reincluded) {
|
23566 | videojs__default["default"].log.warn('Removing other playlists from the exclusion list because the last ' + 'rendition is about to be excluded.');
|
23567 |
|
23568 |
|
23569 |
|
23570 | this.tech_.trigger('retryplaylist');
|
23571 | }
|
23572 | }
|
23573 |
|
23574 |
|
23575 | var excludeUntil;
|
23576 |
|
23577 | if (currentPlaylist.playlistErrors_ > this.maxPlaylistRetries) {
|
23578 | excludeUntil = Infinity;
|
23579 | } else {
|
23580 | excludeUntil = Date.now() + blacklistDuration * 1000;
|
23581 | }
|
23582 |
|
23583 | currentPlaylist.excludeUntil = excludeUntil;
|
23584 |
|
23585 | if (error.reason) {
|
23586 | currentPlaylist.lastExcludeReason_ = error.reason;
|
23587 | }
|
23588 |
|
23589 | this.tech_.trigger('blacklistplaylist');
|
23590 | this.tech_.trigger({
|
23591 | type: 'usage',
|
23592 | name: 'vhs-rendition-blacklisted'
|
23593 | });
|
23594 | this.tech_.trigger({
|
23595 | type: 'usage',
|
23596 | name: 'hls-rendition-blacklisted'
|
23597 | });
|
23598 |
|
23599 |
|
23600 |
|
23601 |
|
23602 |
|
23603 | var nextPlaylist = this.selectPlaylist();
|
23604 |
|
23605 | if (!nextPlaylist) {
|
23606 | this.error = 'Playback cannot continue. No available working or supported playlists.';
|
23607 | this.trigger('error');
|
23608 | return;
|
23609 | }
|
23610 |
|
23611 | var logFn = error.internal ? this.logger_ : videojs__default["default"].log.warn;
|
23612 | var errorMessage = error.message ? ' ' + error.message : '';
|
23613 | logFn((error.internal ? 'Internal problem' : 'Problem') + " encountered with playlist " + currentPlaylist.id + "." + (errorMessage + " Switching to playlist " + nextPlaylist.id + "."));
|
23614 |
|
23615 | if (nextPlaylist.attributes.AUDIO !== currentPlaylist.attributes.AUDIO) {
|
23616 | this.delegateLoaders_('audio', ['abort', 'pause']);
|
23617 | }
|
23618 |
|
23619 |
|
23620 | if (nextPlaylist.attributes.SUBTITLES !== currentPlaylist.attributes.SUBTITLES) {
|
23621 | this.delegateLoaders_('subtitle', ['abort', 'pause']);
|
23622 | }
|
23623 |
|
23624 | this.delegateLoaders_('main', ['abort', 'pause']);
|
23625 | var delayDuration = nextPlaylist.targetDuration / 2 * 1000 || 5 * 1000;
|
23626 | var shouldDelay = typeof nextPlaylist.lastRequest === 'number' && Date.now() - nextPlaylist.lastRequest <= delayDuration;
|
23627 |
|
23628 | return this.switchMedia_(nextPlaylist, 'exclude', isFinalRendition || shouldDelay);
|
23629 | }
|
23630 | |
23631 |
|
23632 |
|
23633 | ;
|
23634 |
|
23635 | _proto.pauseLoading = function pauseLoading() {
|
23636 | this.delegateLoaders_('all', ['abort', 'pause']);
|
23637 | this.stopABRTimer_();
|
23638 | }
|
23639 | |
23640 |
|
23641 |
|
23642 |
|
23643 |
|
23644 |
|
23645 |
|
23646 |
|
23647 |
|
23648 |
|
23649 |
|
23650 |
|
23651 |
|
23652 |
|
23653 | ;
|
23654 |
|
23655 | _proto.delegateLoaders_ = function delegateLoaders_(filter, fnNames) {
|
23656 | var _this7 = this;
|
23657 |
|
23658 | var loaders = [];
|
23659 | var dontFilterPlaylist = filter === 'all';
|
23660 |
|
23661 | if (dontFilterPlaylist || filter === 'main') {
|
23662 | loaders.push(this.masterPlaylistLoader_);
|
23663 | }
|
23664 |
|
23665 | var mediaTypes = [];
|
23666 |
|
23667 | if (dontFilterPlaylist || filter === 'audio') {
|
23668 | mediaTypes.push('AUDIO');
|
23669 | }
|
23670 |
|
23671 | if (dontFilterPlaylist || filter === 'subtitle') {
|
23672 | mediaTypes.push('CLOSED-CAPTIONS');
|
23673 | mediaTypes.push('SUBTITLES');
|
23674 | }
|
23675 |
|
23676 | mediaTypes.forEach(function (mediaType) {
|
23677 | var loader = _this7.mediaTypes_[mediaType] && _this7.mediaTypes_[mediaType].activePlaylistLoader;
|
23678 |
|
23679 | if (loader) {
|
23680 | loaders.push(loader);
|
23681 | }
|
23682 | });
|
23683 | ['main', 'audio', 'subtitle'].forEach(function (name) {
|
23684 | var loader = _this7[name + "SegmentLoader_"];
|
23685 |
|
23686 | if (loader && (filter === name || filter === 'all')) {
|
23687 | loaders.push(loader);
|
23688 | }
|
23689 | });
|
23690 | loaders.forEach(function (loader) {
|
23691 | return fnNames.forEach(function (fnName) {
|
23692 | if (typeof loader[fnName] === 'function') {
|
23693 | loader[fnName]();
|
23694 | }
|
23695 | });
|
23696 | });
|
23697 | }
|
23698 | |
23699 |
|
23700 |
|
23701 |
|
23702 |
|
23703 |
|
23704 | ;
|
23705 |
|
23706 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
23707 | var buffered = findRange(this.tech_.buffered(), currentTime);
|
23708 |
|
23709 | if (!(this.masterPlaylistLoader_ && this.masterPlaylistLoader_.media())) {
|
23710 |
|
23711 | return 0;
|
23712 | }
|
23713 |
|
23714 |
|
23715 |
|
23716 | if (!this.masterPlaylistLoader_.media().segments) {
|
23717 | return 0;
|
23718 | }
|
23719 |
|
23720 |
|
23721 | if (buffered && buffered.length) {
|
23722 | return currentTime;
|
23723 | }
|
23724 |
|
23725 |
|
23726 |
|
23727 | this.mainSegmentLoader_.resetEverything();
|
23728 | this.mainSegmentLoader_.abort();
|
23729 |
|
23730 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23731 | this.audioSegmentLoader_.resetEverything();
|
23732 | this.audioSegmentLoader_.abort();
|
23733 | }
|
23734 |
|
23735 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
23736 | this.subtitleSegmentLoader_.resetEverything();
|
23737 | this.subtitleSegmentLoader_.abort();
|
23738 | }
|
23739 |
|
23740 |
|
23741 | this.load();
|
23742 | }
|
23743 | |
23744 |
|
23745 |
|
23746 |
|
23747 |
|
23748 | ;
|
23749 |
|
23750 | _proto.duration = function duration() {
|
23751 | if (!this.masterPlaylistLoader_) {
|
23752 | return 0;
|
23753 | }
|
23754 |
|
23755 | var media = this.masterPlaylistLoader_.media();
|
23756 |
|
23757 | if (!media) {
|
23758 |
|
23759 | return 0;
|
23760 | }
|
23761 |
|
23762 |
|
23763 |
|
23764 |
|
23765 |
|
23766 |
|
23767 |
|
23768 |
|
23769 |
|
23770 |
|
23771 |
|
23772 | if (!media.endList) {
|
23773 | return Infinity;
|
23774 | }
|
23775 |
|
23776 |
|
23777 |
|
23778 | if (this.mediaSource) {
|
23779 | return this.mediaSource.duration;
|
23780 | }
|
23781 |
|
23782 | return Vhs$1.Playlist.duration(media);
|
23783 | }
|
23784 | |
23785 |
|
23786 |
|
23787 |
|
23788 |
|
23789 | ;
|
23790 |
|
23791 | _proto.seekable = function seekable() {
|
23792 | return this.seekable_;
|
23793 | };
|
23794 |
|
23795 | _proto.onSyncInfoUpdate_ = function onSyncInfoUpdate_() {
|
23796 | var audioSeekable;
|
23797 |
|
23798 |
|
23799 |
|
23800 |
|
23801 |
|
23802 |
|
23803 |
|
23804 |
|
23805 |
|
23806 |
|
23807 |
|
23808 |
|
23809 |
|
23810 |
|
23811 |
|
23812 |
|
23813 |
|
23814 |
|
23815 |
|
23816 | if (!this.masterPlaylistLoader_) {
|
23817 | return;
|
23818 | }
|
23819 |
|
23820 | var media = this.masterPlaylistLoader_.media();
|
23821 |
|
23822 | if (!media) {
|
23823 | return;
|
23824 | }
|
23825 |
|
23826 | var expired = this.syncController_.getExpiredTime(media, this.duration());
|
23827 |
|
23828 | if (expired === null) {
|
23829 |
|
23830 | return;
|
23831 | }
|
23832 |
|
23833 | var master = this.masterPlaylistLoader_.master;
|
23834 | var mainSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
23835 |
|
23836 | if (mainSeekable.length === 0) {
|
23837 | return;
|
23838 | }
|
23839 |
|
23840 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23841 | media = this.mediaTypes_.AUDIO.activePlaylistLoader.media();
|
23842 | expired = this.syncController_.getExpiredTime(media, this.duration());
|
23843 |
|
23844 | if (expired === null) {
|
23845 | return;
|
23846 | }
|
23847 |
|
23848 | audioSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
23849 |
|
23850 | if (audioSeekable.length === 0) {
|
23851 | return;
|
23852 | }
|
23853 | }
|
23854 |
|
23855 | var oldEnd;
|
23856 | var oldStart;
|
23857 |
|
23858 | if (this.seekable_ && this.seekable_.length) {
|
23859 | oldEnd = this.seekable_.end(0);
|
23860 | oldStart = this.seekable_.start(0);
|
23861 | }
|
23862 |
|
23863 | if (!audioSeekable) {
|
23864 |
|
23865 |
|
23866 | this.seekable_ = mainSeekable;
|
23867 | } else if (audioSeekable.start(0) > mainSeekable.end(0) || mainSeekable.start(0) > audioSeekable.end(0)) {
|
23868 |
|
23869 | this.seekable_ = mainSeekable;
|
23870 | } else {
|
23871 | 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)]]);
|
23872 | }
|
23873 |
|
23874 |
|
23875 | if (this.seekable_ && this.seekable_.length) {
|
23876 | if (this.seekable_.end(0) === oldEnd && this.seekable_.start(0) === oldStart) {
|
23877 | return;
|
23878 | }
|
23879 | }
|
23880 |
|
23881 | this.logger_("seekable updated [" + printableRange(this.seekable_) + "]");
|
23882 | this.tech_.trigger('seekablechanged');
|
23883 | }
|
23884 | |
23885 |
|
23886 |
|
23887 | ;
|
23888 |
|
23889 | _proto.updateDuration = function updateDuration(isLive) {
|
23890 | if (this.updateDuration_) {
|
23891 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
23892 | this.updateDuration_ = null;
|
23893 | }
|
23894 |
|
23895 | if (this.mediaSource.readyState !== 'open') {
|
23896 | this.updateDuration_ = this.updateDuration.bind(this, isLive);
|
23897 | this.mediaSource.addEventListener('sourceopen', this.updateDuration_);
|
23898 | return;
|
23899 | }
|
23900 |
|
23901 | if (isLive) {
|
23902 | var seekable = this.seekable();
|
23903 |
|
23904 | if (!seekable.length) {
|
23905 | return;
|
23906 | }
|
23907 |
|
23908 |
|
23909 |
|
23910 |
|
23911 |
|
23912 |
|
23913 |
|
23914 |
|
23915 |
|
23916 |
|
23917 |
|
23918 |
|
23919 |
|
23920 |
|
23921 |
|
23922 |
|
23923 |
|
23924 |
|
23925 |
|
23926 |
|
23927 |
|
23928 |
|
23929 |
|
23930 |
|
23931 | if (isNaN(this.mediaSource.duration) || this.mediaSource.duration < seekable.end(seekable.length - 1)) {
|
23932 | this.sourceUpdater_.setDuration(seekable.end(seekable.length - 1));
|
23933 | }
|
23934 |
|
23935 | return;
|
23936 | }
|
23937 |
|
23938 | var buffered = this.tech_.buffered();
|
23939 | var duration = Vhs$1.Playlist.duration(this.masterPlaylistLoader_.media());
|
23940 |
|
23941 | if (buffered.length > 0) {
|
23942 | duration = Math.max(duration, buffered.end(buffered.length - 1));
|
23943 | }
|
23944 |
|
23945 | if (this.mediaSource.duration !== duration) {
|
23946 | this.sourceUpdater_.setDuration(duration);
|
23947 | }
|
23948 | }
|
23949 | |
23950 |
|
23951 |
|
23952 |
|
23953 | ;
|
23954 |
|
23955 | _proto.dispose = function dispose() {
|
23956 | var _this8 = this;
|
23957 |
|
23958 | this.trigger('dispose');
|
23959 | this.decrypter_.terminate();
|
23960 | this.masterPlaylistLoader_.dispose();
|
23961 | this.mainSegmentLoader_.dispose();
|
23962 |
|
23963 | if (this.loadOnPlay_) {
|
23964 | this.tech_.off('play', this.loadOnPlay_);
|
23965 | }
|
23966 |
|
23967 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
23968 | var groups = _this8.mediaTypes_[type].groups;
|
23969 |
|
23970 | for (var id in groups) {
|
23971 | groups[id].forEach(function (group) {
|
23972 | if (group.playlistLoader) {
|
23973 | group.playlistLoader.dispose();
|
23974 | }
|
23975 | });
|
23976 | }
|
23977 | });
|
23978 | this.audioSegmentLoader_.dispose();
|
23979 | this.subtitleSegmentLoader_.dispose();
|
23980 | this.sourceUpdater_.dispose();
|
23981 | this.timelineChangeController_.dispose();
|
23982 | this.stopABRTimer_();
|
23983 |
|
23984 | if (this.updateDuration_) {
|
23985 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
23986 | }
|
23987 |
|
23988 | this.mediaSource.removeEventListener('durationchange', this.handleDurationChange_);
|
23989 |
|
23990 | this.mediaSource.removeEventListener('sourceopen', this.handleSourceOpen_);
|
23991 | this.mediaSource.removeEventListener('sourceended', this.handleSourceEnded_);
|
23992 | this.off();
|
23993 | }
|
23994 | |
23995 |
|
23996 |
|
23997 |
|
23998 |
|
23999 | ;
|
24000 |
|
24001 | _proto.master = function master() {
|
24002 | return this.masterPlaylistLoader_.master;
|
24003 | }
|
24004 | |
24005 |
|
24006 |
|
24007 |
|
24008 |
|
24009 | ;
|
24010 |
|
24011 | _proto.media = function media() {
|
24012 |
|
24013 | return this.masterPlaylistLoader_.media() || this.initialMedia_;
|
24014 | };
|
24015 |
|
24016 | _proto.areMediaTypesKnown_ = function areMediaTypesKnown_() {
|
24017 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
24018 | var hasMainMediaInfo = !!this.mainSegmentLoader_.getCurrentMediaInfo_();
|
24019 |
|
24020 |
|
24021 | var hasAudioMediaInfo = !usingAudioLoader ? true : !!this.audioSegmentLoader_.getCurrentMediaInfo_();
|
24022 |
|
24023 | if (!hasMainMediaInfo || !hasAudioMediaInfo) {
|
24024 | return false;
|
24025 | }
|
24026 |
|
24027 | return true;
|
24028 | };
|
24029 |
|
24030 | _proto.getCodecsOrExclude_ = function getCodecsOrExclude_() {
|
24031 | var _this9 = this;
|
24032 |
|
24033 | var media = {
|
24034 | main: this.mainSegmentLoader_.getCurrentMediaInfo_() || {},
|
24035 | audio: this.audioSegmentLoader_.getCurrentMediaInfo_() || {}
|
24036 | };
|
24037 |
|
24038 | media.video = media.main;
|
24039 | var playlistCodecs = codecsForPlaylist(this.master(), this.media());
|
24040 | var codecs = {};
|
24041 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
24042 |
|
24043 | if (media.main.hasVideo) {
|
24044 | codecs.video = playlistCodecs.video || media.main.videoCodec || codecs_js.DEFAULT_VIDEO_CODEC;
|
24045 | }
|
24046 |
|
24047 | if (media.main.isMuxed) {
|
24048 | codecs.video += "," + (playlistCodecs.audio || media.main.audioCodec || codecs_js.DEFAULT_AUDIO_CODEC);
|
24049 | }
|
24050 |
|
24051 | if (media.main.hasAudio && !media.main.isMuxed || media.audio.hasAudio || usingAudioLoader) {
|
24052 | codecs.audio = playlistCodecs.audio || media.main.audioCodec || media.audio.audioCodec || codecs_js.DEFAULT_AUDIO_CODEC;
|
24053 |
|
24054 | media.audio.isFmp4 = media.main.hasAudio && !media.main.isMuxed ? media.main.isFmp4 : media.audio.isFmp4;
|
24055 | }
|
24056 |
|
24057 |
|
24058 | if (!codecs.audio && !codecs.video) {
|
24059 | this.blacklistCurrentPlaylist({
|
24060 | playlist: this.media(),
|
24061 | message: 'Could not determine codecs for playlist.',
|
24062 | blacklistDuration: Infinity
|
24063 | });
|
24064 | return;
|
24065 | }
|
24066 |
|
24067 |
|
24068 | var supportFunction = function supportFunction(isFmp4, codec) {
|
24069 | return isFmp4 ? codecs_js.browserSupportsCodec(codec) : codecs_js.muxerSupportsCodec(codec);
|
24070 | };
|
24071 |
|
24072 | var unsupportedCodecs = {};
|
24073 | var unsupportedAudio;
|
24074 | ['video', 'audio'].forEach(function (type) {
|
24075 | if (codecs.hasOwnProperty(type) && !supportFunction(media[type].isFmp4, codecs[type])) {
|
24076 | var supporter = media[type].isFmp4 ? 'browser' : 'muxer';
|
24077 | unsupportedCodecs[supporter] = unsupportedCodecs[supporter] || [];
|
24078 | unsupportedCodecs[supporter].push(codecs[type]);
|
24079 |
|
24080 | if (type === 'audio') {
|
24081 | unsupportedAudio = supporter;
|
24082 | }
|
24083 | }
|
24084 | });
|
24085 |
|
24086 | if (usingAudioLoader && unsupportedAudio && this.media().attributes.AUDIO) {
|
24087 | var audioGroup = this.media().attributes.AUDIO;
|
24088 | this.master().playlists.forEach(function (variant) {
|
24089 | var variantAudioGroup = variant.attributes && variant.attributes.AUDIO;
|
24090 |
|
24091 | if (variantAudioGroup === audioGroup && variant !== _this9.media()) {
|
24092 | variant.excludeUntil = Infinity;
|
24093 | }
|
24094 | });
|
24095 | this.logger_("excluding audio group " + audioGroup + " as " + unsupportedAudio + " does not support codec(s): \"" + codecs.audio + "\"");
|
24096 | }
|
24097 |
|
24098 |
|
24099 | if (Object.keys(unsupportedCodecs).length) {
|
24100 | var message = Object.keys(unsupportedCodecs).reduce(function (acc, supporter) {
|
24101 | if (acc) {
|
24102 | acc += ', ';
|
24103 | }
|
24104 |
|
24105 | acc += supporter + " does not support codec(s): \"" + unsupportedCodecs[supporter].join(',') + "\"";
|
24106 | return acc;
|
24107 | }, '') + '.';
|
24108 | this.blacklistCurrentPlaylist({
|
24109 | playlist: this.media(),
|
24110 | internal: true,
|
24111 | message: message,
|
24112 | blacklistDuration: Infinity
|
24113 | });
|
24114 | return;
|
24115 | }
|
24116 |
|
24117 |
|
24118 | if (this.sourceUpdater_.hasCreatedSourceBuffers() && !this.sourceUpdater_.canChangeType()) {
|
24119 | var switchMessages = [];
|
24120 | ['video', 'audio'].forEach(function (type) {
|
24121 | var newCodec = (codecs_js.parseCodecs(_this9.sourceUpdater_.codecs[type] || '')[0] || {}).type;
|
24122 | var oldCodec = (codecs_js.parseCodecs(codecs[type] || '')[0] || {}).type;
|
24123 |
|
24124 | if (newCodec && oldCodec && newCodec.toLowerCase() !== oldCodec.toLowerCase()) {
|
24125 | switchMessages.push("\"" + _this9.sourceUpdater_.codecs[type] + "\" -> \"" + codecs[type] + "\"");
|
24126 | }
|
24127 | });
|
24128 |
|
24129 | if (switchMessages.length) {
|
24130 | this.blacklistCurrentPlaylist({
|
24131 | playlist: this.media(),
|
24132 | message: "Codec switching not supported: " + switchMessages.join(', ') + ".",
|
24133 | blacklistDuration: Infinity,
|
24134 | internal: true
|
24135 | });
|
24136 | return;
|
24137 | }
|
24138 | }
|
24139 |
|
24140 |
|
24141 |
|
24142 | return codecs;
|
24143 | }
|
24144 | |
24145 |
|
24146 |
|
24147 |
|
24148 |
|
24149 | ;
|
24150 |
|
24151 | _proto.tryToCreateSourceBuffers_ = function tryToCreateSourceBuffers_() {
|
24152 |
|
24153 |
|
24154 | if (this.mediaSource.readyState !== 'open' || this.sourceUpdater_.hasCreatedSourceBuffers()) {
|
24155 | return;
|
24156 | }
|
24157 |
|
24158 | if (!this.areMediaTypesKnown_()) {
|
24159 | return;
|
24160 | }
|
24161 |
|
24162 | var codecs = this.getCodecsOrExclude_();
|
24163 |
|
24164 | if (!codecs) {
|
24165 | return;
|
24166 | }
|
24167 |
|
24168 | this.sourceUpdater_.createSourceBuffers(codecs);
|
24169 | var codecString = [codecs.video, codecs.audio].filter(Boolean).join(',');
|
24170 | this.excludeIncompatibleVariants_(codecString);
|
24171 | }
|
24172 | |
24173 |
|
24174 |
|
24175 | ;
|
24176 |
|
24177 | _proto.excludeUnsupportedVariants_ = function excludeUnsupportedVariants_() {
|
24178 | var _this10 = this;
|
24179 |
|
24180 | var playlists = this.master().playlists;
|
24181 | var ids = [];
|
24182 |
|
24183 |
|
24184 | Object.keys(playlists).forEach(function (key) {
|
24185 | var variant = playlists[key];
|
24186 |
|
24187 | if (ids.indexOf(variant.id) !== -1) {
|
24188 | return;
|
24189 | }
|
24190 |
|
24191 | ids.push(variant.id);
|
24192 | var codecs = codecsForPlaylist(_this10.master, variant);
|
24193 | var unsupported = [];
|
24194 |
|
24195 | if (codecs.audio && !codecs_js.muxerSupportsCodec(codecs.audio) && !codecs_js.browserSupportsCodec(codecs.audio)) {
|
24196 | unsupported.push("audio codec " + codecs.audio);
|
24197 | }
|
24198 |
|
24199 | if (codecs.video && !codecs_js.muxerSupportsCodec(codecs.video) && !codecs_js.browserSupportsCodec(codecs.video)) {
|
24200 | unsupported.push("video codec " + codecs.video);
|
24201 | }
|
24202 |
|
24203 | if (codecs.text && codecs.text === 'stpp.ttml.im1t') {
|
24204 | unsupported.push("text codec " + codecs.text);
|
24205 | }
|
24206 |
|
24207 | if (unsupported.length) {
|
24208 | variant.excludeUntil = Infinity;
|
24209 |
|
24210 | _this10.logger_("excluding " + variant.id + " for unsupported: " + unsupported.join(', '));
|
24211 | }
|
24212 | });
|
24213 | }
|
24214 | |
24215 |
|
24216 |
|
24217 |
|
24218 |
|
24219 |
|
24220 |
|
24221 |
|
24222 |
|
24223 |
|
24224 |
|
24225 |
|
24226 |
|
24227 |
|
24228 | ;
|
24229 |
|
24230 | _proto.excludeIncompatibleVariants_ = function excludeIncompatibleVariants_(codecString) {
|
24231 | var _this11 = this;
|
24232 |
|
24233 | var ids = [];
|
24234 | var playlists = this.master().playlists;
|
24235 | var codecs = unwrapCodecList(codecs_js.parseCodecs(codecString));
|
24236 | var codecCount_ = codecCount(codecs);
|
24237 | var videoDetails = codecs.video && codecs_js.parseCodecs(codecs.video)[0] || null;
|
24238 | var audioDetails = codecs.audio && codecs_js.parseCodecs(codecs.audio)[0] || null;
|
24239 | Object.keys(playlists).forEach(function (key) {
|
24240 | var variant = playlists[key];
|
24241 |
|
24242 |
|
24243 | if (ids.indexOf(variant.id) !== -1 || variant.excludeUntil === Infinity) {
|
24244 | return;
|
24245 | }
|
24246 |
|
24247 | ids.push(variant.id);
|
24248 | var blacklistReasons = [];
|
24249 |
|
24250 | var variantCodecs = codecsForPlaylist(_this11.masterPlaylistLoader_.master, variant);
|
24251 | var variantCodecCount = codecCount(variantCodecs);
|
24252 |
|
24253 |
|
24254 | if (!variantCodecs.audio && !variantCodecs.video) {
|
24255 | return;
|
24256 | }
|
24257 |
|
24258 |
|
24259 |
|
24260 |
|
24261 | if (variantCodecCount !== codecCount_) {
|
24262 | blacklistReasons.push("codec count \"" + variantCodecCount + "\" !== \"" + codecCount_ + "\"");
|
24263 | }
|
24264 |
|
24265 |
|
24266 |
|
24267 | if (!_this11.sourceUpdater_.canChangeType()) {
|
24268 | var variantVideoDetails = variantCodecs.video && codecs_js.parseCodecs(variantCodecs.video)[0] || null;
|
24269 | var variantAudioDetails = variantCodecs.audio && codecs_js.parseCodecs(variantCodecs.audio)[0] || null;
|
24270 |
|
24271 | if (variantVideoDetails && videoDetails && variantVideoDetails.type.toLowerCase() !== videoDetails.type.toLowerCase()) {
|
24272 | blacklistReasons.push("video codec \"" + variantVideoDetails.type + "\" !== \"" + videoDetails.type + "\"");
|
24273 | }
|
24274 |
|
24275 |
|
24276 | if (variantAudioDetails && audioDetails && variantAudioDetails.type.toLowerCase() !== audioDetails.type.toLowerCase()) {
|
24277 | blacklistReasons.push("audio codec \"" + variantAudioDetails.type + "\" !== \"" + audioDetails.type + "\"");
|
24278 | }
|
24279 | }
|
24280 |
|
24281 | if (blacklistReasons.length) {
|
24282 | variant.excludeUntil = Infinity;
|
24283 |
|
24284 | _this11.logger_("blacklisting " + variant.id + ": " + blacklistReasons.join(' && '));
|
24285 | }
|
24286 | });
|
24287 | };
|
24288 |
|
24289 | _proto.updateAdCues_ = function updateAdCues_(media) {
|
24290 | var offset = 0;
|
24291 | var seekable = this.seekable();
|
24292 |
|
24293 | if (seekable.length) {
|
24294 | offset = seekable.start(0);
|
24295 | }
|
24296 |
|
24297 | updateAdCues(media, this.cueTagsTrack_, offset);
|
24298 | }
|
24299 | |
24300 |
|
24301 |
|
24302 |
|
24303 |
|
24304 | ;
|
24305 |
|
24306 | _proto.goalBufferLength = function goalBufferLength() {
|
24307 | var currentTime = this.tech_.currentTime();
|
24308 | var initial = Config.GOAL_BUFFER_LENGTH;
|
24309 | var rate = Config.GOAL_BUFFER_LENGTH_RATE;
|
24310 | var max = Math.max(initial, Config.MAX_GOAL_BUFFER_LENGTH);
|
24311 | return Math.min(initial + currentTime * rate, max);
|
24312 | }
|
24313 | |
24314 |
|
24315 |
|
24316 |
|
24317 |
|
24318 | ;
|
24319 |
|
24320 | _proto.bufferLowWaterLine = function bufferLowWaterLine() {
|
24321 | var currentTime = this.tech_.currentTime();
|
24322 | var initial = Config.BUFFER_LOW_WATER_LINE;
|
24323 | var rate = Config.BUFFER_LOW_WATER_LINE_RATE;
|
24324 | var max = Math.max(initial, Config.MAX_BUFFER_LOW_WATER_LINE);
|
24325 | var newMax = Math.max(initial, Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE);
|
24326 | return Math.min(initial + currentTime * rate, this.experimentalBufferBasedABR ? newMax : max);
|
24327 | };
|
24328 |
|
24329 | _proto.bufferHighWaterLine = function bufferHighWaterLine() {
|
24330 | return Config.BUFFER_HIGH_WATER_LINE;
|
24331 | };
|
24332 |
|
24333 | return MasterPlaylistController;
|
24334 | }(videojs__default["default"].EventTarget);
|
24335 |
|
24336 |
|
24337 |
|
24338 |
|
24339 |
|
24340 |
|
24341 |
|
24342 |
|
24343 |
|
24344 |
|
24345 |
|
24346 |
|
24347 |
|
24348 |
|
24349 | var enableFunction = function enableFunction(loader, playlistID, changePlaylistFn) {
|
24350 | return function (enable) {
|
24351 | var playlist = loader.master.playlists[playlistID];
|
24352 | var incompatible = isIncompatible(playlist);
|
24353 | var currentlyEnabled = isEnabled(playlist);
|
24354 |
|
24355 | if (typeof enable === 'undefined') {
|
24356 | return currentlyEnabled;
|
24357 | }
|
24358 |
|
24359 | if (enable) {
|
24360 | delete playlist.disabled;
|
24361 | } else {
|
24362 | playlist.disabled = true;
|
24363 | }
|
24364 |
|
24365 | if (enable !== currentlyEnabled && !incompatible) {
|
24366 |
|
24367 | changePlaylistFn();
|
24368 |
|
24369 | if (enable) {
|
24370 | loader.trigger('renditionenabled');
|
24371 | } else {
|
24372 | loader.trigger('renditiondisabled');
|
24373 | }
|
24374 | }
|
24375 |
|
24376 | return enable;
|
24377 | };
|
24378 | };
|
24379 |
|
24380 |
|
24381 |
|
24382 |
|
24383 |
|
24384 |
|
24385 |
|
24386 |
|
24387 |
|
24388 | var Representation = function Representation(vhsHandler, playlist, id) {
|
24389 | var mpc = vhsHandler.masterPlaylistController_,
|
24390 | smoothQualityChange = vhsHandler.options_.smoothQualityChange;
|
24391 |
|
24392 | var changeType = smoothQualityChange ? 'smooth' : 'fast';
|
24393 | var qualityChangeFunction = mpc[changeType + "QualityChange_"].bind(mpc);
|
24394 |
|
24395 | if (playlist.attributes) {
|
24396 | var resolution = playlist.attributes.RESOLUTION;
|
24397 | this.width = resolution && resolution.width;
|
24398 | this.height = resolution && resolution.height;
|
24399 | this.bandwidth = playlist.attributes.BANDWIDTH;
|
24400 | this.frameRate = playlist.attributes['FRAME-RATE'];
|
24401 | }
|
24402 |
|
24403 | this.codecs = codecsForPlaylist(mpc.master(), playlist);
|
24404 | this.playlist = playlist;
|
24405 |
|
24406 |
|
24407 | this.id = id;
|
24408 |
|
24409 |
|
24410 | this.enabled = enableFunction(vhsHandler.playlists, playlist.id, qualityChangeFunction);
|
24411 | };
|
24412 |
|
24413 |
|
24414 |
|
24415 |
|
24416 |
|
24417 |
|
24418 |
|
24419 |
|
24420 |
|
24421 | var renditionSelectionMixin = function renditionSelectionMixin(vhsHandler) {
|
24422 |
|
24423 | vhsHandler.representations = function () {
|
24424 | var master = vhsHandler.masterPlaylistController_.master();
|
24425 | var playlists = isAudioOnly(master) ? vhsHandler.masterPlaylistController_.getAudioTrackPlaylists_() : master.playlists;
|
24426 |
|
24427 | if (!playlists) {
|
24428 | return [];
|
24429 | }
|
24430 |
|
24431 | return playlists.filter(function (media) {
|
24432 | return !isIncompatible(media);
|
24433 | }).map(function (e, i) {
|
24434 | return new Representation(vhsHandler, e, e.id);
|
24435 | });
|
24436 | };
|
24437 | };
|
24438 |
|
24439 |
|
24440 |
|
24441 |
|
24442 |
|
24443 |
|
24444 |
|
24445 |
|
24446 |
|
24447 |
|
24448 |
|
24449 | var timerCancelEvents = ['seeking', 'seeked', 'pause', 'playing', 'error'];
|
24450 |
|
24451 |
|
24452 |
|
24453 |
|
24454 | var PlaybackWatcher = function () {
|
24455 | |
24456 |
|
24457 |
|
24458 |
|
24459 |
|
24460 |
|
24461 | function PlaybackWatcher(options) {
|
24462 | var _this = this;
|
24463 |
|
24464 | this.masterPlaylistController_ = options.masterPlaylistController;
|
24465 | this.tech_ = options.tech;
|
24466 | this.seekable = options.seekable;
|
24467 | this.allowSeeksWithinUnsafeLiveWindow = options.allowSeeksWithinUnsafeLiveWindow;
|
24468 | this.liveRangeSafeTimeDelta = options.liveRangeSafeTimeDelta;
|
24469 | this.media = options.media;
|
24470 | this.consecutiveUpdates = 0;
|
24471 | this.lastRecordedTime = null;
|
24472 | this.timer_ = null;
|
24473 | this.checkCurrentTimeTimeout_ = null;
|
24474 | this.logger_ = logger('PlaybackWatcher');
|
24475 | this.logger_('initialize');
|
24476 |
|
24477 | var playHandler = function playHandler() {
|
24478 | return _this.monitorCurrentTime_();
|
24479 | };
|
24480 |
|
24481 | var canPlayHandler = function canPlayHandler() {
|
24482 | return _this.monitorCurrentTime_();
|
24483 | };
|
24484 |
|
24485 | var waitingHandler = function waitingHandler() {
|
24486 | return _this.techWaiting_();
|
24487 | };
|
24488 |
|
24489 | var cancelTimerHandler = function cancelTimerHandler() {
|
24490 | return _this.cancelTimer_();
|
24491 | };
|
24492 |
|
24493 | var mpc = this.masterPlaylistController_;
|
24494 | var loaderTypes = ['main', 'subtitle', 'audio'];
|
24495 | var loaderChecks = {};
|
24496 | loaderTypes.forEach(function (type) {
|
24497 | loaderChecks[type] = {
|
24498 | reset: function reset() {
|
24499 | return _this.resetSegmentDownloads_(type);
|
24500 | },
|
24501 | updateend: function updateend() {
|
24502 | return _this.checkSegmentDownloads_(type);
|
24503 | }
|
24504 | };
|
24505 | mpc[type + "SegmentLoader_"].on('appendsdone', loaderChecks[type].updateend);
|
24506 |
|
24507 |
|
24508 |
|
24509 | mpc[type + "SegmentLoader_"].on('playlistupdate', loaderChecks[type].reset);
|
24510 |
|
24511 |
|
24512 |
|
24513 |
|
24514 | _this.tech_.on(['seeked', 'seeking'], loaderChecks[type].reset);
|
24515 | });
|
24516 | |
24517 |
|
24518 |
|
24519 |
|
24520 |
|
24521 |
|
24522 |
|
24523 |
|
24524 |
|
24525 | var setSeekingHandlers = function setSeekingHandlers(fn) {
|
24526 | ['main', 'audio'].forEach(function (type) {
|
24527 | mpc[type + "SegmentLoader_"][fn]('appended', _this.seekingAppendCheck_);
|
24528 | });
|
24529 | };
|
24530 |
|
24531 | this.seekingAppendCheck_ = function () {
|
24532 | if (_this.fixesBadSeeks_()) {
|
24533 | _this.consecutiveUpdates = 0;
|
24534 | _this.lastRecordedTime = _this.tech_.currentTime();
|
24535 | setSeekingHandlers('off');
|
24536 | }
|
24537 | };
|
24538 |
|
24539 | this.clearSeekingAppendCheck_ = function () {
|
24540 | return setSeekingHandlers('off');
|
24541 | };
|
24542 |
|
24543 | this.watchForBadSeeking_ = function () {
|
24544 | _this.clearSeekingAppendCheck_();
|
24545 |
|
24546 | setSeekingHandlers('on');
|
24547 | };
|
24548 |
|
24549 | this.tech_.on('seeked', this.clearSeekingAppendCheck_);
|
24550 | this.tech_.on('seeking', this.watchForBadSeeking_);
|
24551 | this.tech_.on('waiting', waitingHandler);
|
24552 | this.tech_.on(timerCancelEvents, cancelTimerHandler);
|
24553 | this.tech_.on('canplay', canPlayHandler);
|
24554 | |
24555 |
|
24556 |
|
24557 |
|
24558 |
|
24559 |
|
24560 |
|
24561 |
|
24562 |
|
24563 |
|
24564 |
|
24565 | this.tech_.one('play', playHandler);
|
24566 |
|
24567 | this.dispose = function () {
|
24568 | _this.clearSeekingAppendCheck_();
|
24569 |
|
24570 | _this.logger_('dispose');
|
24571 |
|
24572 | _this.tech_.off('waiting', waitingHandler);
|
24573 |
|
24574 | _this.tech_.off(timerCancelEvents, cancelTimerHandler);
|
24575 |
|
24576 | _this.tech_.off('canplay', canPlayHandler);
|
24577 |
|
24578 | _this.tech_.off('play', playHandler);
|
24579 |
|
24580 | _this.tech_.off('seeking', _this.watchForBadSeeking_);
|
24581 |
|
24582 | _this.tech_.off('seeked', _this.clearSeekingAppendCheck_);
|
24583 |
|
24584 | loaderTypes.forEach(function (type) {
|
24585 | mpc[type + "SegmentLoader_"].off('appendsdone', loaderChecks[type].updateend);
|
24586 | mpc[type + "SegmentLoader_"].off('playlistupdate', loaderChecks[type].reset);
|
24587 |
|
24588 | _this.tech_.off(['seeked', 'seeking'], loaderChecks[type].reset);
|
24589 | });
|
24590 |
|
24591 | if (_this.checkCurrentTimeTimeout_) {
|
24592 | window__default["default"].clearTimeout(_this.checkCurrentTimeTimeout_);
|
24593 | }
|
24594 |
|
24595 | _this.cancelTimer_();
|
24596 | };
|
24597 | }
|
24598 | |
24599 |
|
24600 |
|
24601 |
|
24602 |
|
24603 |
|
24604 |
|
24605 | var _proto = PlaybackWatcher.prototype;
|
24606 |
|
24607 | _proto.monitorCurrentTime_ = function monitorCurrentTime_() {
|
24608 | this.checkCurrentTime_();
|
24609 |
|
24610 | if (this.checkCurrentTimeTimeout_) {
|
24611 | window__default["default"].clearTimeout(this.checkCurrentTimeTimeout_);
|
24612 | }
|
24613 |
|
24614 |
|
24615 | this.checkCurrentTimeTimeout_ = window__default["default"].setTimeout(this.monitorCurrentTime_.bind(this), 250);
|
24616 | }
|
24617 | |
24618 |
|
24619 |
|
24620 |
|
24621 |
|
24622 |
|
24623 |
|
24624 |
|
24625 |
|
24626 |
|
24627 | ;
|
24628 |
|
24629 | _proto.resetSegmentDownloads_ = function resetSegmentDownloads_(type) {
|
24630 | var loader = this.masterPlaylistController_[type + "SegmentLoader_"];
|
24631 |
|
24632 | if (this[type + "StalledDownloads_"] > 0) {
|
24633 | this.logger_("resetting possible stalled download count for " + type + " loader");
|
24634 | }
|
24635 |
|
24636 | this[type + "StalledDownloads_"] = 0;
|
24637 | this[type + "Buffered_"] = loader.buffered_();
|
24638 | }
|
24639 | |
24640 |
|
24641 |
|
24642 |
|
24643 |
|
24644 |
|
24645 |
|
24646 |
|
24647 |
|
24648 |
|
24649 | ;
|
24650 |
|
24651 | _proto.checkSegmentDownloads_ = function checkSegmentDownloads_(type) {
|
24652 | var mpc = this.masterPlaylistController_;
|
24653 | var loader = mpc[type + "SegmentLoader_"];
|
24654 | var buffered = loader.buffered_();
|
24655 | var isBufferedDifferent = isRangeDifferent(this[type + "Buffered_"], buffered);
|
24656 | this[type + "Buffered_"] = buffered;
|
24657 |
|
24658 |
|
24659 |
|
24660 | if (isBufferedDifferent) {
|
24661 | this.resetSegmentDownloads_(type);
|
24662 | return;
|
24663 | }
|
24664 |
|
24665 | this[type + "StalledDownloads_"]++;
|
24666 | this.logger_("found #" + this[type + "StalledDownloads_"] + " " + type + " appends that did not increase buffer (possible stalled download)", {
|
24667 | playlistId: loader.playlist_ && loader.playlist_.id,
|
24668 | buffered: timeRangesToArray(buffered)
|
24669 | });
|
24670 |
|
24671 | if (this[type + "StalledDownloads_"] < 10) {
|
24672 | return;
|
24673 | }
|
24674 |
|
24675 | this.logger_(type + " loader stalled download exclusion");
|
24676 | this.resetSegmentDownloads_(type);
|
24677 | this.tech_.trigger({
|
24678 | type: 'usage',
|
24679 | name: "vhs-" + type + "-download-exclusion"
|
24680 | });
|
24681 |
|
24682 | if (type === 'subtitle') {
|
24683 | return;
|
24684 | }
|
24685 |
|
24686 |
|
24687 |
|
24688 | mpc.blacklistCurrentPlaylist({
|
24689 | message: "Excessive " + type + " segment downloading detected."
|
24690 | }, Infinity);
|
24691 | }
|
24692 | |
24693 |
|
24694 |
|
24695 |
|
24696 |
|
24697 |
|
24698 |
|
24699 | ;
|
24700 |
|
24701 | _proto.checkCurrentTime_ = function checkCurrentTime_() {
|
24702 | if (this.tech_.paused() || this.tech_.seeking()) {
|
24703 | return;
|
24704 | }
|
24705 |
|
24706 | var currentTime = this.tech_.currentTime();
|
24707 | var buffered = this.tech_.buffered();
|
24708 |
|
24709 | if (this.lastRecordedTime === currentTime && (!buffered.length || currentTime + SAFE_TIME_DELTA >= buffered.end(buffered.length - 1))) {
|
24710 |
|
24711 |
|
24712 |
|
24713 |
|
24714 |
|
24715 | return this.techWaiting_();
|
24716 | }
|
24717 |
|
24718 | if (this.consecutiveUpdates >= 5 && currentTime === this.lastRecordedTime) {
|
24719 | this.consecutiveUpdates++;
|
24720 | this.waiting_();
|
24721 | } else if (currentTime === this.lastRecordedTime) {
|
24722 | this.consecutiveUpdates++;
|
24723 | } else {
|
24724 | this.consecutiveUpdates = 0;
|
24725 | this.lastRecordedTime = currentTime;
|
24726 | }
|
24727 | }
|
24728 | |
24729 |
|
24730 |
|
24731 |
|
24732 |
|
24733 |
|
24734 | ;
|
24735 |
|
24736 | _proto.cancelTimer_ = function cancelTimer_() {
|
24737 | this.consecutiveUpdates = 0;
|
24738 |
|
24739 | if (this.timer_) {
|
24740 | this.logger_('cancelTimer_');
|
24741 | clearTimeout(this.timer_);
|
24742 | }
|
24743 |
|
24744 | this.timer_ = null;
|
24745 | }
|
24746 | |
24747 |
|
24748 |
|
24749 |
|
24750 |
|
24751 |
|
24752 | ;
|
24753 |
|
24754 | _proto.fixesBadSeeks_ = function fixesBadSeeks_() {
|
24755 | var seeking = this.tech_.seeking();
|
24756 |
|
24757 | if (!seeking) {
|
24758 | return false;
|
24759 | }
|
24760 |
|
24761 |
|
24762 |
|
24763 |
|
24764 |
|
24765 | var seekable = this.seekable();
|
24766 | var currentTime = this.tech_.currentTime();
|
24767 | var isAfterSeekableRange = this.afterSeekableWindow_(seekable, currentTime, this.media(), this.allowSeeksWithinUnsafeLiveWindow);
|
24768 | var seekTo;
|
24769 |
|
24770 | if (isAfterSeekableRange) {
|
24771 | var seekableEnd = seekable.end(seekable.length - 1);
|
24772 |
|
24773 | seekTo = seekableEnd;
|
24774 | }
|
24775 |
|
24776 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
24777 | var seekableStart = seekable.start(0);
|
24778 |
|
24779 |
|
24780 | seekTo = seekableStart + (
|
24781 |
|
24782 | seekableStart === seekable.end(0) ? 0 : SAFE_TIME_DELTA);
|
24783 | }
|
24784 |
|
24785 | if (typeof seekTo !== 'undefined') {
|
24786 | this.logger_("Trying to seek outside of seekable at time " + currentTime + " with " + ("seekable range " + printableRange(seekable) + ". Seeking to ") + (seekTo + "."));
|
24787 | this.tech_.setCurrentTime(seekTo);
|
24788 | return true;
|
24789 | }
|
24790 |
|
24791 | var sourceUpdater = this.masterPlaylistController_.sourceUpdater_;
|
24792 | var buffered = this.tech_.buffered();
|
24793 | var audioBuffered = sourceUpdater.audioBuffer ? sourceUpdater.audioBuffered() : null;
|
24794 | var videoBuffered = sourceUpdater.videoBuffer ? sourceUpdater.videoBuffered() : null;
|
24795 | var media = this.media();
|
24796 |
|
24797 |
|
24798 | var minAppendedDuration = media.partTargetDuration ? media.partTargetDuration : (media.targetDuration - TIME_FUDGE_FACTOR) * 2;
|
24799 |
|
24800 |
|
24801 | var bufferedToCheck = [audioBuffered, videoBuffered];
|
24802 |
|
24803 | for (var i = 0; i < bufferedToCheck.length; i++) {
|
24804 |
|
24805 | if (!bufferedToCheck[i]) {
|
24806 | continue;
|
24807 | }
|
24808 |
|
24809 | var timeAhead = timeAheadOf(bufferedToCheck[i], currentTime);
|
24810 |
|
24811 |
|
24812 | if (timeAhead < minAppendedDuration) {
|
24813 | return false;
|
24814 | }
|
24815 | }
|
24816 |
|
24817 | var nextRange = findNextRange(buffered, currentTime);
|
24818 |
|
24819 |
|
24820 | if (nextRange.length === 0) {
|
24821 | return false;
|
24822 | }
|
24823 |
|
24824 | seekTo = nextRange.start(0) + SAFE_TIME_DELTA;
|
24825 | this.logger_("Buffered region starts (" + nextRange.start(0) + ") " + (" just beyond seek point (" + currentTime + "). Seeking to " + seekTo + "."));
|
24826 | this.tech_.setCurrentTime(seekTo);
|
24827 | return true;
|
24828 | }
|
24829 | |
24830 |
|
24831 |
|
24832 |
|
24833 |
|
24834 | ;
|
24835 |
|
24836 | _proto.waiting_ = function waiting_() {
|
24837 | if (this.techWaiting_()) {
|
24838 | return;
|
24839 | }
|
24840 |
|
24841 |
|
24842 | var currentTime = this.tech_.currentTime();
|
24843 | var buffered = this.tech_.buffered();
|
24844 | var currentRange = findRange(buffered, currentTime);
|
24845 |
|
24846 |
|
24847 |
|
24848 |
|
24849 |
|
24850 |
|
24851 |
|
24852 |
|
24853 | if (currentRange.length && currentTime + 3 <= currentRange.end(0)) {
|
24854 | this.cancelTimer_();
|
24855 | this.tech_.setCurrentTime(currentTime);
|
24856 | 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.');
|
24857 |
|
24858 | this.tech_.trigger({
|
24859 | type: 'usage',
|
24860 | name: 'vhs-unknown-waiting'
|
24861 | });
|
24862 | this.tech_.trigger({
|
24863 | type: 'usage',
|
24864 | name: 'hls-unknown-waiting'
|
24865 | });
|
24866 | return;
|
24867 | }
|
24868 | }
|
24869 | |
24870 |
|
24871 |
|
24872 |
|
24873 |
|
24874 |
|
24875 |
|
24876 |
|
24877 | ;
|
24878 |
|
24879 | _proto.techWaiting_ = function techWaiting_() {
|
24880 | var seekable = this.seekable();
|
24881 | var currentTime = this.tech_.currentTime();
|
24882 |
|
24883 | if (this.tech_.seeking() || this.timer_ !== null) {
|
24884 |
|
24885 | return true;
|
24886 | }
|
24887 |
|
24888 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
24889 | var livePoint = seekable.end(seekable.length - 1);
|
24890 | this.logger_("Fell out of live window at time " + currentTime + ". Seeking to " + ("live point (seekable end) " + livePoint));
|
24891 | this.cancelTimer_();
|
24892 | this.tech_.setCurrentTime(livePoint);
|
24893 |
|
24894 | this.tech_.trigger({
|
24895 | type: 'usage',
|
24896 | name: 'vhs-live-resync'
|
24897 | });
|
24898 | this.tech_.trigger({
|
24899 | type: 'usage',
|
24900 | name: 'hls-live-resync'
|
24901 | });
|
24902 | return true;
|
24903 | }
|
24904 |
|
24905 | var sourceUpdater = this.tech_.vhs.masterPlaylistController_.sourceUpdater_;
|
24906 | var buffered = this.tech_.buffered();
|
24907 | var videoUnderflow = this.videoUnderflow_({
|
24908 | audioBuffered: sourceUpdater.audioBuffered(),
|
24909 | videoBuffered: sourceUpdater.videoBuffered(),
|
24910 | currentTime: currentTime
|
24911 | });
|
24912 |
|
24913 | if (videoUnderflow) {
|
24914 |
|
24915 |
|
24916 |
|
24917 |
|
24918 | this.cancelTimer_();
|
24919 | this.tech_.setCurrentTime(currentTime);
|
24920 |
|
24921 | this.tech_.trigger({
|
24922 | type: 'usage',
|
24923 | name: 'vhs-video-underflow'
|
24924 | });
|
24925 | this.tech_.trigger({
|
24926 | type: 'usage',
|
24927 | name: 'hls-video-underflow'
|
24928 | });
|
24929 | return true;
|
24930 | }
|
24931 |
|
24932 | var nextRange = findNextRange(buffered, currentTime);
|
24933 |
|
24934 | if (nextRange.length > 0) {
|
24935 | var difference = nextRange.start(0) - currentTime;
|
24936 | this.logger_("Stopped at " + currentTime + ", setting timer for " + difference + ", seeking " + ("to " + nextRange.start(0)));
|
24937 | this.cancelTimer_();
|
24938 | this.timer_ = setTimeout(this.skipTheGap_.bind(this), difference * 1000, currentTime);
|
24939 | return true;
|
24940 | }
|
24941 |
|
24942 |
|
24943 | return false;
|
24944 | };
|
24945 |
|
24946 | _proto.afterSeekableWindow_ = function afterSeekableWindow_(seekable, currentTime, playlist, allowSeeksWithinUnsafeLiveWindow) {
|
24947 | if (allowSeeksWithinUnsafeLiveWindow === void 0) {
|
24948 | allowSeeksWithinUnsafeLiveWindow = false;
|
24949 | }
|
24950 |
|
24951 | if (!seekable.length) {
|
24952 |
|
24953 | return false;
|
24954 | }
|
24955 |
|
24956 | var allowedEnd = seekable.end(seekable.length - 1) + SAFE_TIME_DELTA;
|
24957 | var isLive = !playlist.endList;
|
24958 |
|
24959 | if (isLive && allowSeeksWithinUnsafeLiveWindow) {
|
24960 | allowedEnd = seekable.end(seekable.length - 1) + playlist.targetDuration * 3;
|
24961 | }
|
24962 |
|
24963 | if (currentTime > allowedEnd) {
|
24964 | return true;
|
24965 | }
|
24966 |
|
24967 | return false;
|
24968 | };
|
24969 |
|
24970 | _proto.beforeSeekableWindow_ = function beforeSeekableWindow_(seekable, currentTime) {
|
24971 | if (seekable.length &&
|
24972 | seekable.start(0) > 0 && currentTime < seekable.start(0) - this.liveRangeSafeTimeDelta) {
|
24973 | return true;
|
24974 | }
|
24975 |
|
24976 | return false;
|
24977 | };
|
24978 |
|
24979 | _proto.videoUnderflow_ = function videoUnderflow_(_ref) {
|
24980 | var videoBuffered = _ref.videoBuffered,
|
24981 | audioBuffered = _ref.audioBuffered,
|
24982 | currentTime = _ref.currentTime;
|
24983 |
|
24984 |
|
24985 | if (!videoBuffered) {
|
24986 | return;
|
24987 | }
|
24988 |
|
24989 | var gap;
|
24990 |
|
24991 | if (videoBuffered.length && audioBuffered.length) {
|
24992 |
|
24993 |
|
24994 |
|
24995 | var lastVideoRange = findRange(videoBuffered, currentTime - 3);
|
24996 | var videoRange = findRange(videoBuffered, currentTime);
|
24997 | var audioRange = findRange(audioBuffered, currentTime);
|
24998 |
|
24999 | if (audioRange.length && !videoRange.length && lastVideoRange.length) {
|
25000 | gap = {
|
25001 | start: lastVideoRange.end(0),
|
25002 | end: audioRange.end(0)
|
25003 | };
|
25004 | }
|
25005 |
|
25006 | } else {
|
25007 | var nextRange = findNextRange(videoBuffered, currentTime);
|
25008 |
|
25009 |
|
25010 | if (!nextRange.length) {
|
25011 | gap = this.gapFromVideoUnderflow_(videoBuffered, currentTime);
|
25012 | }
|
25013 | }
|
25014 |
|
25015 | if (gap) {
|
25016 | this.logger_("Encountered a gap in video from " + gap.start + " to " + gap.end + ". " + ("Seeking to current time " + currentTime));
|
25017 | return true;
|
25018 | }
|
25019 |
|
25020 | return false;
|
25021 | }
|
25022 | |
25023 |
|
25024 |
|
25025 |
|
25026 |
|
25027 |
|
25028 | ;
|
25029 |
|
25030 | _proto.skipTheGap_ = function skipTheGap_(scheduledCurrentTime) {
|
25031 | var buffered = this.tech_.buffered();
|
25032 | var currentTime = this.tech_.currentTime();
|
25033 | var nextRange = findNextRange(buffered, currentTime);
|
25034 | this.cancelTimer_();
|
25035 |
|
25036 | if (nextRange.length === 0 || currentTime !== scheduledCurrentTime) {
|
25037 | return;
|
25038 | }
|
25039 |
|
25040 | this.logger_('skipTheGap_:', 'currentTime:', currentTime, 'scheduled currentTime:', scheduledCurrentTime, 'nextRange start:', nextRange.start(0));
|
25041 |
|
25042 | this.tech_.setCurrentTime(nextRange.start(0) + TIME_FUDGE_FACTOR);
|
25043 | this.tech_.trigger({
|
25044 | type: 'usage',
|
25045 | name: 'vhs-gap-skip'
|
25046 | });
|
25047 | this.tech_.trigger({
|
25048 | type: 'usage',
|
25049 | name: 'hls-gap-skip'
|
25050 | });
|
25051 | };
|
25052 |
|
25053 | _proto.gapFromVideoUnderflow_ = function gapFromVideoUnderflow_(buffered, currentTime) {
|
25054 |
|
25055 |
|
25056 |
|
25057 |
|
25058 |
|
25059 |
|
25060 |
|
25061 |
|
25062 |
|
25063 |
|
25064 |
|
25065 |
|
25066 |
|
25067 |
|
25068 |
|
25069 |
|
25070 |
|
25071 |
|
25072 |
|
25073 |
|
25074 |
|
25075 |
|
25076 | var gaps = findGaps(buffered);
|
25077 |
|
25078 | for (var i = 0; i < gaps.length; i++) {
|
25079 | var start = gaps.start(i);
|
25080 | var end = gaps.end(i);
|
25081 |
|
25082 | if (currentTime - start < 4 && currentTime - start > 2) {
|
25083 | return {
|
25084 | start: start,
|
25085 | end: end
|
25086 | };
|
25087 | }
|
25088 | }
|
25089 |
|
25090 | return null;
|
25091 | };
|
25092 |
|
25093 | return PlaybackWatcher;
|
25094 | }();
|
25095 |
|
25096 | var defaultOptions = {
|
25097 | errorInterval: 30,
|
25098 | getSource: function getSource(next) {
|
25099 | var tech = this.tech({
|
25100 | IWillNotUseThisInPlugins: true
|
25101 | });
|
25102 | var sourceObj = tech.currentSource_ || this.currentSource();
|
25103 | return next(sourceObj);
|
25104 | }
|
25105 | };
|
25106 |
|
25107 |
|
25108 |
|
25109 |
|
25110 |
|
25111 |
|
25112 |
|
25113 |
|
25114 | var initPlugin = function initPlugin(player, options) {
|
25115 | var lastCalled = 0;
|
25116 | var seekTo = 0;
|
25117 | var localOptions = videojs__default["default"].mergeOptions(defaultOptions, options);
|
25118 | player.ready(function () {
|
25119 | player.trigger({
|
25120 | type: 'usage',
|
25121 | name: 'vhs-error-reload-initialized'
|
25122 | });
|
25123 | player.trigger({
|
25124 | type: 'usage',
|
25125 | name: 'hls-error-reload-initialized'
|
25126 | });
|
25127 | });
|
25128 | |
25129 |
|
25130 |
|
25131 |
|
25132 |
|
25133 |
|
25134 |
|
25135 | var loadedMetadataHandler = function loadedMetadataHandler() {
|
25136 | if (seekTo) {
|
25137 | player.currentTime(seekTo);
|
25138 | }
|
25139 | };
|
25140 | |
25141 |
|
25142 |
|
25143 |
|
25144 |
|
25145 |
|
25146 |
|
25147 |
|
25148 | var setSource = function setSource(sourceObj) {
|
25149 | if (sourceObj === null || sourceObj === undefined) {
|
25150 | return;
|
25151 | }
|
25152 |
|
25153 | seekTo = player.duration() !== Infinity && player.currentTime() || 0;
|
25154 | player.one('loadedmetadata', loadedMetadataHandler);
|
25155 | player.src(sourceObj);
|
25156 | player.trigger({
|
25157 | type: 'usage',
|
25158 | name: 'vhs-error-reload'
|
25159 | });
|
25160 | player.trigger({
|
25161 | type: 'usage',
|
25162 | name: 'hls-error-reload'
|
25163 | });
|
25164 | player.play();
|
25165 | };
|
25166 | |
25167 |
|
25168 |
|
25169 |
|
25170 |
|
25171 |
|
25172 |
|
25173 |
|
25174 | var errorHandler = function errorHandler() {
|
25175 |
|
25176 |
|
25177 | if (Date.now() - lastCalled < localOptions.errorInterval * 1000) {
|
25178 | player.trigger({
|
25179 | type: 'usage',
|
25180 | name: 'vhs-error-reload-canceled'
|
25181 | });
|
25182 | player.trigger({
|
25183 | type: 'usage',
|
25184 | name: 'hls-error-reload-canceled'
|
25185 | });
|
25186 | return;
|
25187 | }
|
25188 |
|
25189 | if (!localOptions.getSource || typeof localOptions.getSource !== 'function') {
|
25190 | videojs__default["default"].log.error('ERROR: reloadSourceOnError - The option getSource must be a function!');
|
25191 | return;
|
25192 | }
|
25193 |
|
25194 | lastCalled = Date.now();
|
25195 | return localOptions.getSource.call(player, setSource);
|
25196 | };
|
25197 | |
25198 |
|
25199 |
|
25200 |
|
25201 |
|
25202 |
|
25203 |
|
25204 | var cleanupEvents = function cleanupEvents() {
|
25205 | player.off('loadedmetadata', loadedMetadataHandler);
|
25206 | player.off('error', errorHandler);
|
25207 | player.off('dispose', cleanupEvents);
|
25208 | };
|
25209 | |
25210 |
|
25211 |
|
25212 |
|
25213 |
|
25214 |
|
25215 |
|
25216 |
|
25217 | var reinitPlugin = function reinitPlugin(newOptions) {
|
25218 | cleanupEvents();
|
25219 | initPlugin(player, newOptions);
|
25220 | };
|
25221 |
|
25222 | player.on('error', errorHandler);
|
25223 | player.on('dispose', cleanupEvents);
|
25224 |
|
25225 |
|
25226 | player.reloadSourceOnError = reinitPlugin;
|
25227 | };
|
25228 |
|
25229 |
|
25230 |
|
25231 |
|
25232 |
|
25233 |
|
25234 |
|
25235 |
|
25236 | var reloadSourceOnError = function reloadSourceOnError(options) {
|
25237 | initPlugin(this, options);
|
25238 | };
|
25239 |
|
25240 | var version$4 = "2.16.0";
|
25241 |
|
25242 | var version$3 = "6.0.1";
|
25243 |
|
25244 | var version$2 = "0.22.1";
|
25245 |
|
25246 | var version$1 = "4.8.0";
|
25247 |
|
25248 | var version = "3.1.3";
|
25249 |
|
25250 | var Vhs = {
|
25251 | PlaylistLoader: PlaylistLoader,
|
25252 | Playlist: Playlist,
|
25253 | utils: utils,
|
25254 | STANDARD_PLAYLIST_SELECTOR: lastBandwidthSelector,
|
25255 | INITIAL_PLAYLIST_SELECTOR: lowestBitrateCompatibleVariantSelector,
|
25256 | lastBandwidthSelector: lastBandwidthSelector,
|
25257 | movingAverageBandwidthSelector: movingAverageBandwidthSelector,
|
25258 | comparePlaylistBandwidth: comparePlaylistBandwidth,
|
25259 | comparePlaylistResolution: comparePlaylistResolution,
|
25260 | xhr: xhrFactory()
|
25261 | };
|
25262 |
|
25263 | Object.keys(Config).forEach(function (prop) {
|
25264 | Object.defineProperty(Vhs, prop, {
|
25265 | get: function get() {
|
25266 | videojs__default["default"].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
25267 | return Config[prop];
|
25268 | },
|
25269 | set: function set(value) {
|
25270 | videojs__default["default"].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
25271 |
|
25272 | if (typeof value !== 'number' || value < 0) {
|
25273 | videojs__default["default"].log.warn("value of Vhs." + prop + " must be greater than or equal to 0");
|
25274 | return;
|
25275 | }
|
25276 |
|
25277 | Config[prop] = value;
|
25278 | }
|
25279 | });
|
25280 | });
|
25281 | var LOCAL_STORAGE_KEY = 'videojs-vhs';
|
25282 |
|
25283 |
|
25284 |
|
25285 |
|
25286 |
|
25287 |
|
25288 |
|
25289 |
|
25290 | var handleVhsMediaChange = function handleVhsMediaChange(qualityLevels, playlistLoader) {
|
25291 | var newPlaylist = playlistLoader.media();
|
25292 | var selectedIndex = -1;
|
25293 |
|
25294 | for (var i = 0; i < qualityLevels.length; i++) {
|
25295 | if (qualityLevels[i].id === newPlaylist.id) {
|
25296 | selectedIndex = i;
|
25297 | break;
|
25298 | }
|
25299 | }
|
25300 |
|
25301 | qualityLevels.selectedIndex_ = selectedIndex;
|
25302 | qualityLevels.trigger({
|
25303 | selectedIndex: selectedIndex,
|
25304 | type: 'change'
|
25305 | });
|
25306 | };
|
25307 |
|
25308 |
|
25309 |
|
25310 |
|
25311 |
|
25312 |
|
25313 |
|
25314 |
|
25315 |
|
25316 | var handleVhsLoadedMetadata = function handleVhsLoadedMetadata(qualityLevels, vhs) {
|
25317 | vhs.representations().forEach(function (rep) {
|
25318 | qualityLevels.addQualityLevel(rep);
|
25319 | });
|
25320 | handleVhsMediaChange(qualityLevels, vhs.playlists);
|
25321 | };
|
25322 |
|
25323 |
|
25324 |
|
25325 | Vhs.canPlaySource = function () {
|
25326 | return videojs__default["default"].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
25327 | };
|
25328 |
|
25329 | var emeKeySystems = function emeKeySystems(keySystemOptions, mainPlaylist, audioPlaylist) {
|
25330 | if (!keySystemOptions) {
|
25331 | return keySystemOptions;
|
25332 | }
|
25333 |
|
25334 | var codecs = {};
|
25335 |
|
25336 | if (mainPlaylist && mainPlaylist.attributes && mainPlaylist.attributes.CODECS) {
|
25337 | codecs = unwrapCodecList(codecs_js.parseCodecs(mainPlaylist.attributes.CODECS));
|
25338 | }
|
25339 |
|
25340 | if (audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS) {
|
25341 | codecs.audio = audioPlaylist.attributes.CODECS;
|
25342 | }
|
25343 |
|
25344 | var videoContentType = codecs_js.getMimeForCodec(codecs.video);
|
25345 | var audioContentType = codecs_js.getMimeForCodec(codecs.audio);
|
25346 |
|
25347 | var keySystemContentTypes = {};
|
25348 |
|
25349 | for (var keySystem in keySystemOptions) {
|
25350 | keySystemContentTypes[keySystem] = {};
|
25351 |
|
25352 | if (audioContentType) {
|
25353 | keySystemContentTypes[keySystem].audioContentType = audioContentType;
|
25354 | }
|
25355 |
|
25356 | if (videoContentType) {
|
25357 | keySystemContentTypes[keySystem].videoContentType = videoContentType;
|
25358 | }
|
25359 |
|
25360 |
|
25361 |
|
25362 |
|
25363 |
|
25364 |
|
25365 |
|
25366 | if (mainPlaylist.contentProtection && mainPlaylist.contentProtection[keySystem] && mainPlaylist.contentProtection[keySystem].pssh) {
|
25367 | keySystemContentTypes[keySystem].pssh = mainPlaylist.contentProtection[keySystem].pssh;
|
25368 | }
|
25369 |
|
25370 |
|
25371 |
|
25372 | if (typeof keySystemOptions[keySystem] === 'string') {
|
25373 | keySystemContentTypes[keySystem].url = keySystemOptions[keySystem];
|
25374 | }
|
25375 | }
|
25376 |
|
25377 | return videojs__default["default"].mergeOptions(keySystemOptions, keySystemContentTypes);
|
25378 | };
|
25379 |
|
25380 |
|
25381 |
|
25382 |
|
25383 |
|
25384 |
|
25385 |
|
25386 |
|
25387 |
|
25388 |
|
25389 |
|
25390 |
|
25391 |
|
25392 |
|
25393 |
|
25394 |
|
25395 |
|
25396 |
|
25397 |
|
25398 |
|
25399 |
|
25400 |
|
25401 |
|
25402 |
|
25403 |
|
25404 | var getAllPsshKeySystemsOptions = function getAllPsshKeySystemsOptions(playlists, keySystems) {
|
25405 | return playlists.reduce(function (keySystemsArr, playlist) {
|
25406 | if (!playlist.contentProtection) {
|
25407 | return keySystemsArr;
|
25408 | }
|
25409 |
|
25410 | var keySystemsOptions = keySystems.reduce(function (keySystemsObj, keySystem) {
|
25411 | var keySystemOptions = playlist.contentProtection[keySystem];
|
25412 |
|
25413 | if (keySystemOptions && keySystemOptions.pssh) {
|
25414 | keySystemsObj[keySystem] = {
|
25415 | pssh: keySystemOptions.pssh
|
25416 | };
|
25417 | }
|
25418 |
|
25419 | return keySystemsObj;
|
25420 | }, {});
|
25421 |
|
25422 | if (Object.keys(keySystemsOptions).length) {
|
25423 | keySystemsArr.push(keySystemsOptions);
|
25424 | }
|
25425 |
|
25426 | return keySystemsArr;
|
25427 | }, []);
|
25428 | };
|
25429 |
|
25430 |
|
25431 |
|
25432 |
|
25433 |
|
25434 |
|
25435 |
|
25436 |
|
25437 |
|
25438 |
|
25439 |
|
25440 |
|
25441 |
|
25442 |
|
25443 |
|
25444 |
|
25445 |
|
25446 |
|
25447 |
|
25448 |
|
25449 |
|
25450 |
|
25451 |
|
25452 |
|
25453 |
|
25454 |
|
25455 | var waitForKeySessionCreation = function waitForKeySessionCreation(_ref) {
|
25456 | var player = _ref.player,
|
25457 | sourceKeySystems = _ref.sourceKeySystems,
|
25458 | audioMedia = _ref.audioMedia,
|
25459 | mainPlaylists = _ref.mainPlaylists;
|
25460 |
|
25461 | if (!player.eme.initializeMediaKeys) {
|
25462 | return Promise.resolve();
|
25463 | }
|
25464 |
|
25465 |
|
25466 |
|
25467 |
|
25468 |
|
25469 |
|
25470 |
|
25471 |
|
25472 |
|
25473 | var playlists = audioMedia ? mainPlaylists.concat([audioMedia]) : mainPlaylists;
|
25474 | var keySystemsOptionsArr = getAllPsshKeySystemsOptions(playlists, Object.keys(sourceKeySystems));
|
25475 | var initializationFinishedPromises = [];
|
25476 | var keySessionCreatedPromises = [];
|
25477 |
|
25478 |
|
25479 |
|
25480 |
|
25481 |
|
25482 | keySystemsOptionsArr.forEach(function (keySystemsOptions) {
|
25483 | keySessionCreatedPromises.push(new Promise(function (resolve, reject) {
|
25484 | player.tech_.one('keysessioncreated', resolve);
|
25485 | }));
|
25486 | initializationFinishedPromises.push(new Promise(function (resolve, reject) {
|
25487 | player.eme.initializeMediaKeys({
|
25488 | keySystems: keySystemsOptions
|
25489 | }, function (err) {
|
25490 | if (err) {
|
25491 | reject(err);
|
25492 | return;
|
25493 | }
|
25494 |
|
25495 | resolve();
|
25496 | });
|
25497 | }));
|
25498 | });
|
25499 |
|
25500 |
|
25501 |
|
25502 |
|
25503 |
|
25504 |
|
25505 | return Promise.race([
|
25506 |
|
25507 |
|
25508 | Promise.all(initializationFinishedPromises),
|
25509 | Promise.race(keySessionCreatedPromises)]);
|
25510 | };
|
25511 |
|
25512 |
|
25513 |
|
25514 |
|
25515 |
|
25516 |
|
25517 |
|
25518 |
|
25519 |
|
25520 |
|
25521 |
|
25522 |
|
25523 |
|
25524 |
|
25525 |
|
25526 |
|
25527 |
|
25528 |
|
25529 | var setupEmeOptions = function setupEmeOptions(_ref2) {
|
25530 | var player = _ref2.player,
|
25531 | sourceKeySystems = _ref2.sourceKeySystems,
|
25532 | media = _ref2.media,
|
25533 | audioMedia = _ref2.audioMedia;
|
25534 | var sourceOptions = emeKeySystems(sourceKeySystems, media, audioMedia);
|
25535 |
|
25536 | if (!sourceOptions) {
|
25537 | return false;
|
25538 | }
|
25539 |
|
25540 | player.currentSource().keySystems = sourceOptions;
|
25541 |
|
25542 |
|
25543 | if (sourceOptions && !player.eme) {
|
25544 | videojs__default["default"].log.warn('DRM encrypted source cannot be decrypted without a DRM plugin');
|
25545 | return false;
|
25546 | }
|
25547 |
|
25548 | return true;
|
25549 | };
|
25550 |
|
25551 | var getVhsLocalStorage = function getVhsLocalStorage() {
|
25552 | if (!window__default["default"].localStorage) {
|
25553 | return null;
|
25554 | }
|
25555 |
|
25556 | var storedObject = window__default["default"].localStorage.getItem(LOCAL_STORAGE_KEY);
|
25557 |
|
25558 | if (!storedObject) {
|
25559 | return null;
|
25560 | }
|
25561 |
|
25562 | try {
|
25563 | return JSON.parse(storedObject);
|
25564 | } catch (e) {
|
25565 |
|
25566 | return null;
|
25567 | }
|
25568 | };
|
25569 |
|
25570 | var updateVhsLocalStorage = function updateVhsLocalStorage(options) {
|
25571 | if (!window__default["default"].localStorage) {
|
25572 | return false;
|
25573 | }
|
25574 |
|
25575 | var objectToStore = getVhsLocalStorage();
|
25576 | objectToStore = objectToStore ? videojs__default["default"].mergeOptions(objectToStore, options) : options;
|
25577 |
|
25578 | try {
|
25579 | window__default["default"].localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(objectToStore));
|
25580 | } catch (e) {
|
25581 |
|
25582 |
|
25583 |
|
25584 |
|
25585 | return false;
|
25586 | }
|
25587 |
|
25588 | return objectToStore;
|
25589 | };
|
25590 |
|
25591 |
|
25592 |
|
25593 |
|
25594 |
|
25595 |
|
25596 |
|
25597 |
|
25598 |
|
25599 |
|
25600 |
|
25601 |
|
25602 |
|
25603 |
|
25604 | var expandDataUri = function expandDataUri(dataUri) {
|
25605 | if (dataUri.toLowerCase().indexOf('data:application/vnd.videojs.vhs+json,') === 0) {
|
25606 | return JSON.parse(dataUri.substring(dataUri.indexOf(',') + 1));
|
25607 | }
|
25608 |
|
25609 |
|
25610 | return dataUri;
|
25611 | };
|
25612 |
|
25613 |
|
25614 |
|
25615 |
|
25616 |
|
25617 | Vhs.supportsNativeHls = function () {
|
25618 | if (!document__default["default"] || !document__default["default"].createElement) {
|
25619 | return false;
|
25620 | }
|
25621 |
|
25622 | var video = document__default["default"].createElement('video');
|
25623 |
|
25624 | if (!videojs__default["default"].getTech('Html5').isSupported()) {
|
25625 | return false;
|
25626 | }
|
25627 |
|
25628 |
|
25629 | var canPlay = [
|
25630 | 'application/vnd.apple.mpegurl',
|
25631 | 'audio/mpegurl',
|
25632 | 'audio/x-mpegurl',
|
25633 | 'application/x-mpegurl',
|
25634 | 'video/x-mpegurl', 'video/mpegurl', 'application/mpegurl'];
|
25635 | return canPlay.some(function (canItPlay) {
|
25636 | return /maybe|probably/i.test(video.canPlayType(canItPlay));
|
25637 | });
|
25638 | }();
|
25639 |
|
25640 | Vhs.supportsNativeDash = function () {
|
25641 | if (!document__default["default"] || !document__default["default"].createElement || !videojs__default["default"].getTech('Html5').isSupported()) {
|
25642 | return false;
|
25643 | }
|
25644 |
|
25645 | return /maybe|probably/i.test(document__default["default"].createElement('video').canPlayType('application/dash+xml'));
|
25646 | }();
|
25647 |
|
25648 | Vhs.supportsTypeNatively = function (type) {
|
25649 | if (type === 'hls') {
|
25650 | return Vhs.supportsNativeHls;
|
25651 | }
|
25652 |
|
25653 | if (type === 'dash') {
|
25654 | return Vhs.supportsNativeDash;
|
25655 | }
|
25656 |
|
25657 | return false;
|
25658 | };
|
25659 |
|
25660 |
|
25661 |
|
25662 |
|
25663 |
|
25664 |
|
25665 | Vhs.isSupported = function () {
|
25666 | return videojs__default["default"].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
25667 | };
|
25668 |
|
25669 | var Component = videojs__default["default"].getComponent('Component');
|
25670 |
|
25671 |
|
25672 |
|
25673 |
|
25674 |
|
25675 |
|
25676 |
|
25677 |
|
25678 |
|
25679 |
|
25680 |
|
25681 | var VhsHandler = function (_Component) {
|
25682 | _inheritsLoose__default["default"](VhsHandler, _Component);
|
25683 |
|
25684 | function VhsHandler(source, tech, options) {
|
25685 | var _this;
|
25686 |
|
25687 | _this = _Component.call(this, tech, videojs__default["default"].mergeOptions(options.hls, options.vhs)) || this;
|
25688 |
|
25689 | if (options.hls && Object.keys(options.hls).length) {
|
25690 | videojs__default["default"].log.warn('Using hls options is deprecated. Please rename `hls` to `vhs` in your options object.');
|
25691 | }
|
25692 |
|
25693 |
|
25694 |
|
25695 | if (typeof options.initialBandwidth === 'number') {
|
25696 | _this.options_.bandwidth = options.initialBandwidth;
|
25697 | }
|
25698 |
|
25699 | _this.logger_ = logger('VhsHandler');
|
25700 |
|
25701 |
|
25702 | if (tech.options_ && tech.options_.playerId) {
|
25703 | var _player = videojs__default["default"](tech.options_.playerId);
|
25704 |
|
25705 | if (!_player.hasOwnProperty('hls')) {
|
25706 | Object.defineProperty(_player, 'hls', {
|
25707 | get: function get() {
|
25708 | videojs__default["default"].log.warn('player.hls is deprecated. Use player.tech().vhs instead.');
|
25709 | tech.trigger({
|
25710 | type: 'usage',
|
25711 | name: 'hls-player-access'
|
25712 | });
|
25713 | return _assertThisInitialized__default["default"](_this);
|
25714 | },
|
25715 | configurable: true
|
25716 | });
|
25717 | }
|
25718 |
|
25719 | if (!_player.hasOwnProperty('vhs')) {
|
25720 | Object.defineProperty(_player, 'vhs', {
|
25721 | get: function get() {
|
25722 | videojs__default["default"].log.warn('player.vhs is deprecated. Use player.tech().vhs instead.');
|
25723 | tech.trigger({
|
25724 | type: 'usage',
|
25725 | name: 'vhs-player-access'
|
25726 | });
|
25727 | return _assertThisInitialized__default["default"](_this);
|
25728 | },
|
25729 | configurable: true
|
25730 | });
|
25731 | }
|
25732 |
|
25733 | if (!_player.hasOwnProperty('dash')) {
|
25734 | Object.defineProperty(_player, 'dash', {
|
25735 | get: function get() {
|
25736 | videojs__default["default"].log.warn('player.dash is deprecated. Use player.tech().vhs instead.');
|
25737 | return _assertThisInitialized__default["default"](_this);
|
25738 | },
|
25739 | configurable: true
|
25740 | });
|
25741 | }
|
25742 |
|
25743 | _this.player_ = _player;
|
25744 | }
|
25745 |
|
25746 | _this.tech_ = tech;
|
25747 | _this.source_ = source;
|
25748 | _this.stats = {};
|
25749 | _this.ignoreNextSeekingEvent_ = false;
|
25750 |
|
25751 | _this.setOptions_();
|
25752 |
|
25753 | if (_this.options_.overrideNative && tech.overrideNativeAudioTracks && tech.overrideNativeVideoTracks) {
|
25754 | tech.overrideNativeAudioTracks(true);
|
25755 | tech.overrideNativeVideoTracks(true);
|
25756 | } else if (_this.options_.overrideNative && (tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
|
25757 |
|
25758 |
|
25759 | throw new Error('Overriding native HLS requires emulated tracks. ' + 'See https://git.io/vMpjB');
|
25760 | }
|
25761 |
|
25762 |
|
25763 |
|
25764 | _this.on(document__default["default"], ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'], function (event) {
|
25765 | var fullscreenElement = document__default["default"].fullscreenElement || document__default["default"].webkitFullscreenElement || document__default["default"].mozFullScreenElement || document__default["default"].msFullscreenElement;
|
25766 |
|
25767 | if (fullscreenElement && fullscreenElement.contains(_this.tech_.el())) {
|
25768 | _this.masterPlaylistController_.fastQualityChange_();
|
25769 | } else {
|
25770 |
|
25771 |
|
25772 |
|
25773 | _this.masterPlaylistController_.checkABR_();
|
25774 | }
|
25775 | });
|
25776 |
|
25777 | _this.on(_this.tech_, 'seeking', function () {
|
25778 | if (this.ignoreNextSeekingEvent_) {
|
25779 | this.ignoreNextSeekingEvent_ = false;
|
25780 | return;
|
25781 | }
|
25782 |
|
25783 | this.setCurrentTime(this.tech_.currentTime());
|
25784 | });
|
25785 |
|
25786 | _this.on(_this.tech_, 'error', function () {
|
25787 |
|
25788 |
|
25789 | if (this.tech_.error() && this.masterPlaylistController_) {
|
25790 | this.masterPlaylistController_.pauseLoading();
|
25791 | }
|
25792 | });
|
25793 |
|
25794 | _this.on(_this.tech_, 'play', _this.play);
|
25795 |
|
25796 | return _this;
|
25797 | }
|
25798 |
|
25799 | var _proto = VhsHandler.prototype;
|
25800 |
|
25801 | _proto.setOptions_ = function setOptions_() {
|
25802 | var _this2 = this;
|
25803 |
|
25804 |
|
25805 | this.options_.withCredentials = this.options_.withCredentials || false;
|
25806 | this.options_.handleManifestRedirects = this.options_.handleManifestRedirects === false ? false : true;
|
25807 | this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
|
25808 | this.options_.useDevicePixelRatio = this.options_.useDevicePixelRatio || false;
|
25809 | this.options_.smoothQualityChange = this.options_.smoothQualityChange || false;
|
25810 | this.options_.useBandwidthFromLocalStorage = typeof this.source_.useBandwidthFromLocalStorage !== 'undefined' ? this.source_.useBandwidthFromLocalStorage : this.options_.useBandwidthFromLocalStorage || false;
|
25811 | this.options_.useNetworkInformationApi = this.options_.useNetworkInformationApi || false;
|
25812 | this.options_.useDtsForTimestampOffset = this.options_.useDtsForTimestampOffset || false;
|
25813 | this.options_.customTagParsers = this.options_.customTagParsers || [];
|
25814 | this.options_.customTagMappers = this.options_.customTagMappers || [];
|
25815 | this.options_.cacheEncryptionKeys = this.options_.cacheEncryptionKeys || false;
|
25816 |
|
25817 | if (typeof this.options_.blacklistDuration !== 'number') {
|
25818 | this.options_.blacklistDuration = 5 * 60;
|
25819 | }
|
25820 |
|
25821 | if (typeof this.options_.bandwidth !== 'number') {
|
25822 | if (this.options_.useBandwidthFromLocalStorage) {
|
25823 | var storedObject = getVhsLocalStorage();
|
25824 |
|
25825 | if (storedObject && storedObject.bandwidth) {
|
25826 | this.options_.bandwidth = storedObject.bandwidth;
|
25827 | this.tech_.trigger({
|
25828 | type: 'usage',
|
25829 | name: 'vhs-bandwidth-from-local-storage'
|
25830 | });
|
25831 | this.tech_.trigger({
|
25832 | type: 'usage',
|
25833 | name: 'hls-bandwidth-from-local-storage'
|
25834 | });
|
25835 | }
|
25836 |
|
25837 | if (storedObject && storedObject.throughput) {
|
25838 | this.options_.throughput = storedObject.throughput;
|
25839 | this.tech_.trigger({
|
25840 | type: 'usage',
|
25841 | name: 'vhs-throughput-from-local-storage'
|
25842 | });
|
25843 | this.tech_.trigger({
|
25844 | type: 'usage',
|
25845 | name: 'hls-throughput-from-local-storage'
|
25846 | });
|
25847 | }
|
25848 | }
|
25849 | }
|
25850 |
|
25851 |
|
25852 |
|
25853 | if (typeof this.options_.bandwidth !== 'number') {
|
25854 | this.options_.bandwidth = Config.INITIAL_BANDWIDTH;
|
25855 | }
|
25856 |
|
25857 |
|
25858 |
|
25859 | this.options_.enableLowInitialPlaylist = this.options_.enableLowInitialPlaylist && this.options_.bandwidth === Config.INITIAL_BANDWIDTH;
|
25860 |
|
25861 | ['withCredentials', 'useDevicePixelRatio', 'limitRenditionByPlayerDimensions', 'bandwidth', 'smoothQualityChange', 'customTagParsers', 'customTagMappers', 'handleManifestRedirects', 'cacheEncryptionKeys', 'playlistSelector', 'initialPlaylistSelector', 'experimentalBufferBasedABR', 'liveRangeSafeTimeDelta', 'experimentalLLHLS', 'useNetworkInformationApi', 'useDtsForTimestampOffset', 'experimentalExactManifestTimings', 'experimentalLeastPixelDiffSelector'].forEach(function (option) {
|
25862 | if (typeof _this2.source_[option] !== 'undefined') {
|
25863 | _this2.options_[option] = _this2.source_[option];
|
25864 | }
|
25865 | });
|
25866 | this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
|
25867 | this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
|
25868 | }
|
25869 | |
25870 |
|
25871 |
|
25872 |
|
25873 |
|
25874 | ;
|
25875 |
|
25876 | _proto.src = function src(_src, type) {
|
25877 | var _this3 = this;
|
25878 |
|
25879 |
|
25880 | if (!_src) {
|
25881 | return;
|
25882 | }
|
25883 |
|
25884 | this.setOptions_();
|
25885 |
|
25886 | this.options_.src = expandDataUri(this.source_.src);
|
25887 | this.options_.tech = this.tech_;
|
25888 | this.options_.externVhs = Vhs;
|
25889 | this.options_.sourceType = mediaTypes_js.simpleTypeFromSourceType(type);
|
25890 |
|
25891 | this.options_.seekTo = function (time) {
|
25892 | _this3.tech_.setCurrentTime(time);
|
25893 | };
|
25894 |
|
25895 | if (this.options_.smoothQualityChange) {
|
25896 | videojs__default["default"].log.warn('smoothQualityChange is deprecated and will be removed in the next major version');
|
25897 | }
|
25898 |
|
25899 | this.masterPlaylistController_ = new MasterPlaylistController(this.options_);
|
25900 | var playbackWatcherOptions = videojs__default["default"].mergeOptions({
|
25901 | liveRangeSafeTimeDelta: SAFE_TIME_DELTA
|
25902 | }, this.options_, {
|
25903 | seekable: function seekable() {
|
25904 | return _this3.seekable();
|
25905 | },
|
25906 | media: function media() {
|
25907 | return _this3.masterPlaylistController_.media();
|
25908 | },
|
25909 | masterPlaylistController: this.masterPlaylistController_
|
25910 | });
|
25911 | this.playbackWatcher_ = new PlaybackWatcher(playbackWatcherOptions);
|
25912 | this.masterPlaylistController_.on('error', function () {
|
25913 | var player = videojs__default["default"].players[_this3.tech_.options_.playerId];
|
25914 | var error = _this3.masterPlaylistController_.error;
|
25915 |
|
25916 | if (typeof error === 'object' && !error.code) {
|
25917 | error.code = 3;
|
25918 | } else if (typeof error === 'string') {
|
25919 | error = {
|
25920 | message: error,
|
25921 | code: 3
|
25922 | };
|
25923 | }
|
25924 |
|
25925 | player.error(error);
|
25926 | });
|
25927 | var defaultSelector = this.options_.experimentalBufferBasedABR ? Vhs.movingAverageBandwidthSelector(0.55) : Vhs.STANDARD_PLAYLIST_SELECTOR;
|
25928 |
|
25929 |
|
25930 | this.masterPlaylistController_.selectPlaylist = this.selectPlaylist ? this.selectPlaylist.bind(this) : defaultSelector.bind(this);
|
25931 | this.masterPlaylistController_.selectInitialPlaylist = Vhs.INITIAL_PLAYLIST_SELECTOR.bind(this);
|
25932 |
|
25933 | this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
|
25934 | this.mediaSource = this.masterPlaylistController_.mediaSource;
|
25935 |
|
25936 |
|
25937 |
|
25938 | Object.defineProperties(this, {
|
25939 | selectPlaylist: {
|
25940 | get: function get() {
|
25941 | return this.masterPlaylistController_.selectPlaylist;
|
25942 | },
|
25943 | set: function set(selectPlaylist) {
|
25944 | this.masterPlaylistController_.selectPlaylist = selectPlaylist.bind(this);
|
25945 | }
|
25946 | },
|
25947 | throughput: {
|
25948 | get: function get() {
|
25949 | return this.masterPlaylistController_.mainSegmentLoader_.throughput.rate;
|
25950 | },
|
25951 | set: function set(throughput) {
|
25952 | this.masterPlaylistController_.mainSegmentLoader_.throughput.rate = throughput;
|
25953 |
|
25954 |
|
25955 | this.masterPlaylistController_.mainSegmentLoader_.throughput.count = 1;
|
25956 | }
|
25957 | },
|
25958 | bandwidth: {
|
25959 | get: function get() {
|
25960 | var playerBandwidthEst = this.masterPlaylistController_.mainSegmentLoader_.bandwidth;
|
25961 | var networkInformation = window__default["default"].navigator.connection || window__default["default"].navigator.mozConnection || window__default["default"].navigator.webkitConnection;
|
25962 | var tenMbpsAsBitsPerSecond = 10e6;
|
25963 |
|
25964 | if (this.options_.useNetworkInformationApi && networkInformation) {
|
25965 |
|
25966 |
|
25967 | var networkInfoBandwidthEstBitsPerSec = networkInformation.downlink * 1000 * 1000;
|
25968 |
|
25969 |
|
25970 |
|
25971 | if (networkInfoBandwidthEstBitsPerSec >= tenMbpsAsBitsPerSecond && playerBandwidthEst >= tenMbpsAsBitsPerSecond) {
|
25972 | playerBandwidthEst = Math.max(playerBandwidthEst, networkInfoBandwidthEstBitsPerSec);
|
25973 | } else {
|
25974 | playerBandwidthEst = networkInfoBandwidthEstBitsPerSec;
|
25975 | }
|
25976 | }
|
25977 |
|
25978 | return playerBandwidthEst;
|
25979 | },
|
25980 | set: function set(bandwidth) {
|
25981 | this.masterPlaylistController_.mainSegmentLoader_.bandwidth = bandwidth;
|
25982 |
|
25983 |
|
25984 |
|
25985 | this.masterPlaylistController_.mainSegmentLoader_.throughput = {
|
25986 | rate: 0,
|
25987 | count: 0
|
25988 | };
|
25989 | }
|
25990 | },
|
25991 |
|
25992 | |
25993 |
|
25994 |
|
25995 |
|
25996 |
|
25997 |
|
25998 |
|
25999 |
|
26000 |
|
26001 | systemBandwidth: {
|
26002 | get: function get() {
|
26003 | var invBandwidth = 1 / (this.bandwidth || 1);
|
26004 | var invThroughput;
|
26005 |
|
26006 | if (this.throughput > 0) {
|
26007 | invThroughput = 1 / this.throughput;
|
26008 | } else {
|
26009 | invThroughput = 0;
|
26010 | }
|
26011 |
|
26012 | var systemBitrate = Math.floor(1 / (invBandwidth + invThroughput));
|
26013 | return systemBitrate;
|
26014 | },
|
26015 | set: function set() {
|
26016 | videojs__default["default"].log.error('The "systemBandwidth" property is read-only');
|
26017 | }
|
26018 | }
|
26019 | });
|
26020 |
|
26021 | if (this.options_.bandwidth) {
|
26022 | this.bandwidth = this.options_.bandwidth;
|
26023 | }
|
26024 |
|
26025 | if (this.options_.throughput) {
|
26026 | this.throughput = this.options_.throughput;
|
26027 | }
|
26028 |
|
26029 | Object.defineProperties(this.stats, {
|
26030 | bandwidth: {
|
26031 | get: function get() {
|
26032 | return _this3.bandwidth || 0;
|
26033 | },
|
26034 | enumerable: true
|
26035 | },
|
26036 | mediaRequests: {
|
26037 | get: function get() {
|
26038 | return _this3.masterPlaylistController_.mediaRequests_() || 0;
|
26039 | },
|
26040 | enumerable: true
|
26041 | },
|
26042 | mediaRequestsAborted: {
|
26043 | get: function get() {
|
26044 | return _this3.masterPlaylistController_.mediaRequestsAborted_() || 0;
|
26045 | },
|
26046 | enumerable: true
|
26047 | },
|
26048 | mediaRequestsTimedout: {
|
26049 | get: function get() {
|
26050 | return _this3.masterPlaylistController_.mediaRequestsTimedout_() || 0;
|
26051 | },
|
26052 | enumerable: true
|
26053 | },
|
26054 | mediaRequestsErrored: {
|
26055 | get: function get() {
|
26056 | return _this3.masterPlaylistController_.mediaRequestsErrored_() || 0;
|
26057 | },
|
26058 | enumerable: true
|
26059 | },
|
26060 | mediaTransferDuration: {
|
26061 | get: function get() {
|
26062 | return _this3.masterPlaylistController_.mediaTransferDuration_() || 0;
|
26063 | },
|
26064 | enumerable: true
|
26065 | },
|
26066 | mediaBytesTransferred: {
|
26067 | get: function get() {
|
26068 | return _this3.masterPlaylistController_.mediaBytesTransferred_() || 0;
|
26069 | },
|
26070 | enumerable: true
|
26071 | },
|
26072 | mediaSecondsLoaded: {
|
26073 | get: function get() {
|
26074 | return _this3.masterPlaylistController_.mediaSecondsLoaded_() || 0;
|
26075 | },
|
26076 | enumerable: true
|
26077 | },
|
26078 | mediaAppends: {
|
26079 | get: function get() {
|
26080 | return _this3.masterPlaylistController_.mediaAppends_() || 0;
|
26081 | },
|
26082 | enumerable: true
|
26083 | },
|
26084 | mainAppendsToLoadedData: {
|
26085 | get: function get() {
|
26086 | return _this3.masterPlaylistController_.mainAppendsToLoadedData_() || 0;
|
26087 | },
|
26088 | enumerable: true
|
26089 | },
|
26090 | audioAppendsToLoadedData: {
|
26091 | get: function get() {
|
26092 | return _this3.masterPlaylistController_.audioAppendsToLoadedData_() || 0;
|
26093 | },
|
26094 | enumerable: true
|
26095 | },
|
26096 | appendsToLoadedData: {
|
26097 | get: function get() {
|
26098 | return _this3.masterPlaylistController_.appendsToLoadedData_() || 0;
|
26099 | },
|
26100 | enumerable: true
|
26101 | },
|
26102 | timeToLoadedData: {
|
26103 | get: function get() {
|
26104 | return _this3.masterPlaylistController_.timeToLoadedData_() || 0;
|
26105 | },
|
26106 | enumerable: true
|
26107 | },
|
26108 | buffered: {
|
26109 | get: function get() {
|
26110 | return timeRangesToArray(_this3.tech_.buffered());
|
26111 | },
|
26112 | enumerable: true
|
26113 | },
|
26114 | currentTime: {
|
26115 | get: function get() {
|
26116 | return _this3.tech_.currentTime();
|
26117 | },
|
26118 | enumerable: true
|
26119 | },
|
26120 | currentSource: {
|
26121 | get: function get() {
|
26122 | return _this3.tech_.currentSource_;
|
26123 | },
|
26124 | enumerable: true
|
26125 | },
|
26126 | currentTech: {
|
26127 | get: function get() {
|
26128 | return _this3.tech_.name_;
|
26129 | },
|
26130 | enumerable: true
|
26131 | },
|
26132 | duration: {
|
26133 | get: function get() {
|
26134 | return _this3.tech_.duration();
|
26135 | },
|
26136 | enumerable: true
|
26137 | },
|
26138 | master: {
|
26139 | get: function get() {
|
26140 | return _this3.playlists.master;
|
26141 | },
|
26142 | enumerable: true
|
26143 | },
|
26144 | playerDimensions: {
|
26145 | get: function get() {
|
26146 | return _this3.tech_.currentDimensions();
|
26147 | },
|
26148 | enumerable: true
|
26149 | },
|
26150 | seekable: {
|
26151 | get: function get() {
|
26152 | return timeRangesToArray(_this3.tech_.seekable());
|
26153 | },
|
26154 | enumerable: true
|
26155 | },
|
26156 | timestamp: {
|
26157 | get: function get() {
|
26158 | return Date.now();
|
26159 | },
|
26160 | enumerable: true
|
26161 | },
|
26162 | videoPlaybackQuality: {
|
26163 | get: function get() {
|
26164 | return _this3.tech_.getVideoPlaybackQuality();
|
26165 | },
|
26166 | enumerable: true
|
26167 | }
|
26168 | });
|
26169 | this.tech_.one('canplay', this.masterPlaylistController_.setupFirstPlay.bind(this.masterPlaylistController_));
|
26170 | this.tech_.on('bandwidthupdate', function () {
|
26171 | if (_this3.options_.useBandwidthFromLocalStorage) {
|
26172 | updateVhsLocalStorage({
|
26173 | bandwidth: _this3.bandwidth,
|
26174 | throughput: Math.round(_this3.throughput)
|
26175 | });
|
26176 | }
|
26177 | });
|
26178 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
26179 |
|
26180 | renditionSelectionMixin(_this3);
|
26181 | });
|
26182 | this.masterPlaylistController_.sourceUpdater_.on('createdsourcebuffers', function () {
|
26183 | _this3.setupEme_();
|
26184 | });
|
26185 |
|
26186 |
|
26187 | this.on(this.masterPlaylistController_, 'progress', function () {
|
26188 | this.tech_.trigger('progress');
|
26189 | });
|
26190 |
|
26191 |
|
26192 | this.on(this.masterPlaylistController_, 'firstplay', function () {
|
26193 | this.ignoreNextSeekingEvent_ = true;
|
26194 | });
|
26195 | this.setupQualityLevels_();
|
26196 |
|
26197 |
|
26198 | if (!this.tech_.el()) {
|
26199 | return;
|
26200 | }
|
26201 |
|
26202 | this.mediaSourceUrl_ = window__default["default"].URL.createObjectURL(this.masterPlaylistController_.mediaSource);
|
26203 | this.tech_.src(this.mediaSourceUrl_);
|
26204 | };
|
26205 |
|
26206 | _proto.createKeySessions_ = function createKeySessions_() {
|
26207 | var _this4 = this;
|
26208 |
|
26209 | var audioPlaylistLoader = this.masterPlaylistController_.mediaTypes_.AUDIO.activePlaylistLoader;
|
26210 | this.logger_('waiting for EME key session creation');
|
26211 | waitForKeySessionCreation({
|
26212 | player: this.player_,
|
26213 | sourceKeySystems: this.source_.keySystems,
|
26214 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media(),
|
26215 | mainPlaylists: this.playlists.master.playlists
|
26216 | }).then(function () {
|
26217 | _this4.logger_('created EME key session');
|
26218 |
|
26219 | _this4.masterPlaylistController_.sourceUpdater_.initializedEme();
|
26220 | }).catch(function (err) {
|
26221 | _this4.logger_('error while creating EME key session', err);
|
26222 |
|
26223 | _this4.player_.error({
|
26224 | message: 'Failed to initialize media keys for EME',
|
26225 | code: 3
|
26226 | });
|
26227 | });
|
26228 | };
|
26229 |
|
26230 | _proto.handleWaitingForKey_ = function handleWaitingForKey_() {
|
26231 |
|
26232 |
|
26233 |
|
26234 |
|
26235 |
|
26236 |
|
26237 |
|
26238 |
|
26239 | this.logger_('waitingforkey fired, attempting to create any new key sessions');
|
26240 | this.createKeySessions_();
|
26241 | }
|
26242 | |
26243 |
|
26244 |
|
26245 |
|
26246 |
|
26247 |
|
26248 |
|
26249 |
|
26250 | ;
|
26251 |
|
26252 | _proto.setupEme_ = function setupEme_() {
|
26253 | var _this5 = this;
|
26254 |
|
26255 | var audioPlaylistLoader = this.masterPlaylistController_.mediaTypes_.AUDIO.activePlaylistLoader;
|
26256 | var didSetupEmeOptions = setupEmeOptions({
|
26257 | player: this.player_,
|
26258 | sourceKeySystems: this.source_.keySystems,
|
26259 | media: this.playlists.media(),
|
26260 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media()
|
26261 | });
|
26262 | this.player_.tech_.on('keystatuschange', function (e) {
|
26263 | if (e.status !== 'output-restricted') {
|
26264 | return;
|
26265 | }
|
26266 |
|
26267 | var masterPlaylist = _this5.masterPlaylistController_.master();
|
26268 |
|
26269 | if (!masterPlaylist || !masterPlaylist.playlists) {
|
26270 | return;
|
26271 | }
|
26272 |
|
26273 | var excludedHDPlaylists = [];
|
26274 |
|
26275 | masterPlaylist.playlists.forEach(function (playlist) {
|
26276 | if (playlist && playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.height >= 720) {
|
26277 | if (!playlist.excludeUntil || playlist.excludeUntil < Infinity) {
|
26278 | playlist.excludeUntil = Infinity;
|
26279 | excludedHDPlaylists.push(playlist);
|
26280 | }
|
26281 | }
|
26282 | });
|
26283 |
|
26284 | if (excludedHDPlaylists.length) {
|
26285 | var _videojs$log;
|
26286 |
|
26287 | (_videojs$log = videojs__default["default"].log).warn.apply(_videojs$log, ['DRM keystatus changed to "output-restricted." Removing the following HD playlists ' + 'that will most likely fail to play and clearing the buffer. ' + 'This may be due to HDCP restrictions on the stream and the capabilities of the current device.'].concat(excludedHDPlaylists));
|
26288 |
|
26289 |
|
26290 | _this5.masterPlaylistController_.fastQualityChange_();
|
26291 | }
|
26292 | });
|
26293 | this.handleWaitingForKey_ = this.handleWaitingForKey_.bind(this);
|
26294 | this.player_.tech_.on('waitingforkey', this.handleWaitingForKey_);
|
26295 |
|
26296 |
|
26297 | if (videojs__default["default"].browser.IE_VERSION === 11 || !didSetupEmeOptions) {
|
26298 |
|
26299 | this.masterPlaylistController_.sourceUpdater_.initializedEme();
|
26300 | return;
|
26301 | }
|
26302 |
|
26303 | this.createKeySessions_();
|
26304 | }
|
26305 | |
26306 |
|
26307 |
|
26308 |
|
26309 |
|
26310 |
|
26311 | ;
|
26312 |
|
26313 | _proto.setupQualityLevels_ = function setupQualityLevels_() {
|
26314 | var _this6 = this;
|
26315 |
|
26316 | var player = videojs__default["default"].players[this.tech_.options_.playerId];
|
26317 |
|
26318 |
|
26319 | if (!player || !player.qualityLevels || this.qualityLevels_) {
|
26320 | return;
|
26321 | }
|
26322 |
|
26323 | this.qualityLevels_ = player.qualityLevels();
|
26324 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
26325 | handleVhsLoadedMetadata(_this6.qualityLevels_, _this6);
|
26326 | });
|
26327 | this.playlists.on('mediachange', function () {
|
26328 | handleVhsMediaChange(_this6.qualityLevels_, _this6.playlists);
|
26329 | });
|
26330 | }
|
26331 | |
26332 |
|
26333 |
|
26334 | ;
|
26335 |
|
26336 | VhsHandler.version = function version$5() {
|
26337 | return {
|
26338 | '@videojs/http-streaming': version$4,
|
26339 | 'mux.js': version$3,
|
26340 | 'mpd-parser': version$2,
|
26341 | 'm3u8-parser': version$1,
|
26342 | 'aes-decrypter': version
|
26343 | };
|
26344 | }
|
26345 | |
26346 |
|
26347 |
|
26348 | ;
|
26349 |
|
26350 | _proto.version = function version() {
|
26351 | return this.constructor.version();
|
26352 | };
|
26353 |
|
26354 | _proto.canChangeType = function canChangeType() {
|
26355 | return SourceUpdater.canChangeType();
|
26356 | }
|
26357 | |
26358 |
|
26359 |
|
26360 | ;
|
26361 |
|
26362 | _proto.play = function play() {
|
26363 | this.masterPlaylistController_.play();
|
26364 | }
|
26365 | |
26366 |
|
26367 |
|
26368 | ;
|
26369 |
|
26370 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
26371 | this.masterPlaylistController_.setCurrentTime(currentTime);
|
26372 | }
|
26373 | |
26374 |
|
26375 |
|
26376 | ;
|
26377 |
|
26378 | _proto.duration = function duration() {
|
26379 | return this.masterPlaylistController_.duration();
|
26380 | }
|
26381 | |
26382 |
|
26383 |
|
26384 | ;
|
26385 |
|
26386 | _proto.seekable = function seekable() {
|
26387 | return this.masterPlaylistController_.seekable();
|
26388 | }
|
26389 | |
26390 |
|
26391 |
|
26392 | ;
|
26393 |
|
26394 | _proto.dispose = function dispose() {
|
26395 | if (this.playbackWatcher_) {
|
26396 | this.playbackWatcher_.dispose();
|
26397 | }
|
26398 |
|
26399 | if (this.masterPlaylistController_) {
|
26400 | this.masterPlaylistController_.dispose();
|
26401 | }
|
26402 |
|
26403 | if (this.qualityLevels_) {
|
26404 | this.qualityLevels_.dispose();
|
26405 | }
|
26406 |
|
26407 | if (this.player_) {
|
26408 | delete this.player_.vhs;
|
26409 | delete this.player_.dash;
|
26410 | delete this.player_.hls;
|
26411 | }
|
26412 |
|
26413 | if (this.tech_ && this.tech_.vhs) {
|
26414 | delete this.tech_.vhs;
|
26415 | }
|
26416 |
|
26417 |
|
26418 | if (this.tech_) {
|
26419 | delete this.tech_.hls;
|
26420 | }
|
26421 |
|
26422 | if (this.mediaSourceUrl_ && window__default["default"].URL.revokeObjectURL) {
|
26423 | window__default["default"].URL.revokeObjectURL(this.mediaSourceUrl_);
|
26424 | this.mediaSourceUrl_ = null;
|
26425 | }
|
26426 |
|
26427 | if (this.tech_) {
|
26428 | this.tech_.off('waitingforkey', this.handleWaitingForKey_);
|
26429 | }
|
26430 |
|
26431 | _Component.prototype.dispose.call(this);
|
26432 | };
|
26433 |
|
26434 | _proto.convertToProgramTime = function convertToProgramTime(time, callback) {
|
26435 | return getProgramTime({
|
26436 | playlist: this.masterPlaylistController_.media(),
|
26437 | time: time,
|
26438 | callback: callback
|
26439 | });
|
26440 | }
|
26441 | ;
|
26442 |
|
26443 | _proto.seekToProgramTime = function seekToProgramTime$1(programTime, callback, pauseAfterSeek, retryCount) {
|
26444 | if (pauseAfterSeek === void 0) {
|
26445 | pauseAfterSeek = true;
|
26446 | }
|
26447 |
|
26448 | if (retryCount === void 0) {
|
26449 | retryCount = 2;
|
26450 | }
|
26451 |
|
26452 | return seekToProgramTime({
|
26453 | programTime: programTime,
|
26454 | playlist: this.masterPlaylistController_.media(),
|
26455 | retryCount: retryCount,
|
26456 | pauseAfterSeek: pauseAfterSeek,
|
26457 | seekTo: this.options_.seekTo,
|
26458 | tech: this.options_.tech,
|
26459 | callback: callback
|
26460 | });
|
26461 | };
|
26462 |
|
26463 | return VhsHandler;
|
26464 | }(Component);
|
26465 |
|
26466 |
|
26467 |
|
26468 |
|
26469 |
|
26470 |
|
26471 |
|
26472 |
|
26473 |
|
26474 | var VhsSourceHandler = {
|
26475 | name: 'videojs-http-streaming',
|
26476 | VERSION: version$4,
|
26477 | canHandleSource: function canHandleSource(srcObj, options) {
|
26478 | if (options === void 0) {
|
26479 | options = {};
|
26480 | }
|
26481 |
|
26482 | var localOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options);
|
26483 | return VhsSourceHandler.canPlayType(srcObj.type, localOptions);
|
26484 | },
|
26485 | handleSource: function handleSource(source, tech, options) {
|
26486 | if (options === void 0) {
|
26487 | options = {};
|
26488 | }
|
26489 |
|
26490 | var localOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options);
|
26491 | tech.vhs = new VhsHandler(source, tech, localOptions);
|
26492 |
|
26493 | if (!videojs__default["default"].hasOwnProperty('hls')) {
|
26494 | Object.defineProperty(tech, 'hls', {
|
26495 | get: function get() {
|
26496 | videojs__default["default"].log.warn('player.tech().hls is deprecated. Use player.tech().vhs instead.');
|
26497 | return tech.vhs;
|
26498 | },
|
26499 | configurable: true
|
26500 | });
|
26501 | }
|
26502 |
|
26503 | tech.vhs.xhr = xhrFactory();
|
26504 | tech.vhs.src(source.src, source.type);
|
26505 | return tech.vhs;
|
26506 | },
|
26507 | canPlayType: function canPlayType(type, options) {
|
26508 | var simpleType = mediaTypes_js.simpleTypeFromSourceType(type);
|
26509 |
|
26510 | if (!simpleType) {
|
26511 | return '';
|
26512 | }
|
26513 |
|
26514 | var overrideNative = VhsSourceHandler.getOverrideNative(options);
|
26515 | var supportsTypeNatively = Vhs.supportsTypeNatively(simpleType);
|
26516 | var canUseMsePlayback = !supportsTypeNatively || overrideNative;
|
26517 | return canUseMsePlayback ? 'maybe' : '';
|
26518 | },
|
26519 | getOverrideNative: function getOverrideNative(options) {
|
26520 | if (options === void 0) {
|
26521 | options = {};
|
26522 | }
|
26523 |
|
26524 | var _options = options,
|
26525 | _options$vhs = _options.vhs,
|
26526 | vhs = _options$vhs === void 0 ? {} : _options$vhs,
|
26527 | _options$hls = _options.hls,
|
26528 | hls = _options$hls === void 0 ? {} : _options$hls;
|
26529 | var defaultOverrideNative = !(videojs__default["default"].browser.IS_ANY_SAFARI || videojs__default["default"].browser.IS_IOS);
|
26530 | var _vhs$overrideNative = vhs.overrideNative,
|
26531 | overrideNative = _vhs$overrideNative === void 0 ? defaultOverrideNative : _vhs$overrideNative;
|
26532 | var _hls$overrideNative = hls.overrideNative,
|
26533 | legacyOverrideNative = _hls$overrideNative === void 0 ? false : _hls$overrideNative;
|
26534 | return legacyOverrideNative || overrideNative;
|
26535 | }
|
26536 | };
|
26537 |
|
26538 |
|
26539 |
|
26540 |
|
26541 |
|
26542 |
|
26543 |
|
26544 | var supportsNativeMediaSources = function supportsNativeMediaSources() {
|
26545 | return codecs_js.browserSupportsCodec('avc1.4d400d,mp4a.40.2');
|
26546 | };
|
26547 |
|
26548 |
|
26549 | if (supportsNativeMediaSources()) {
|
26550 | videojs__default["default"].getTech('Html5').registerSourceHandler(VhsSourceHandler, 0);
|
26551 | }
|
26552 |
|
26553 | videojs__default["default"].VhsHandler = VhsHandler;
|
26554 | Object.defineProperty(videojs__default["default"], 'HlsHandler', {
|
26555 | get: function get() {
|
26556 | videojs__default["default"].log.warn('videojs.HlsHandler is deprecated. Use videojs.VhsHandler instead.');
|
26557 | return VhsHandler;
|
26558 | },
|
26559 | configurable: true
|
26560 | });
|
26561 | videojs__default["default"].VhsSourceHandler = VhsSourceHandler;
|
26562 | Object.defineProperty(videojs__default["default"], 'HlsSourceHandler', {
|
26563 | get: function get() {
|
26564 | videojs__default["default"].log.warn('videojs.HlsSourceHandler is deprecated. ' + 'Use videojs.VhsSourceHandler instead.');
|
26565 | return VhsSourceHandler;
|
26566 | },
|
26567 | configurable: true
|
26568 | });
|
26569 | videojs__default["default"].Vhs = Vhs;
|
26570 | Object.defineProperty(videojs__default["default"], 'Hls', {
|
26571 | get: function get() {
|
26572 | videojs__default["default"].log.warn('videojs.Hls is deprecated. Use videojs.Vhs instead.');
|
26573 | return Vhs;
|
26574 | },
|
26575 | configurable: true
|
26576 | });
|
26577 |
|
26578 | if (!videojs__default["default"].use) {
|
26579 | videojs__default["default"].registerComponent('Hls', Vhs);
|
26580 | videojs__default["default"].registerComponent('Vhs', Vhs);
|
26581 | }
|
26582 |
|
26583 | videojs__default["default"].options.vhs = videojs__default["default"].options.vhs || {};
|
26584 | videojs__default["default"].options.hls = videojs__default["default"].options.hls || {};
|
26585 |
|
26586 | if (!videojs__default["default"].getPlugin || !videojs__default["default"].getPlugin('reloadSourceOnError')) {
|
26587 | var registerPlugin = videojs__default["default"].registerPlugin || videojs__default["default"].plugin;
|
26588 | registerPlugin('reloadSourceOnError', reloadSourceOnError);
|
26589 | }
|
26590 |
|
26591 | Object.defineProperty(exports, 'simpleTypeFromSourceType', {
|
26592 | enumerable: true,
|
26593 | get: function () { return mediaTypes_js.simpleTypeFromSourceType; }
|
26594 | });
|
26595 | exports.LOCAL_STORAGE_KEY = LOCAL_STORAGE_KEY;
|
26596 | exports.Vhs = Vhs;
|
26597 | exports.VhsHandler = VhsHandler;
|
26598 | exports.VhsSourceHandler = VhsSourceHandler;
|
26599 | exports.emeKeySystems = emeKeySystems;
|
26600 | exports.expandDataUri = expandDataUri;
|
26601 | exports.getAllPsshKeySystemsOptions = getAllPsshKeySystemsOptions;
|
26602 | exports.setupEmeOptions = setupEmeOptions;
|
26603 | exports.waitForKeySessionCreation = waitForKeySessionCreation;
|