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 = 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 mpdParser = require('mpd-parser');
|
17 | var parseSidx = require('mux.js/lib/tools/parse-sidx');
|
18 | var id3Helpers = require('@videojs/vhs-utils/cjs/id3-helpers');
|
19 | var containers = require('@videojs/vhs-utils/cjs/containers');
|
20 | var byteHelpers = require('@videojs/vhs-utils/cjs/byte-helpers');
|
21 | var clock = require('mux.js/lib/utils/clock');
|
22 |
|
23 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
24 |
|
25 | var _assertThisInitialized__default = _interopDefaultLegacy(_assertThisInitialized);
|
26 | var _inheritsLoose__default = _interopDefaultLegacy(_inheritsLoose);
|
27 | var document__default = _interopDefaultLegacy(document);
|
28 | var window__default = _interopDefaultLegacy(window);
|
29 | var _resolveUrl__default = _interopDefaultLegacy(_resolveUrl);
|
30 | var videojs__default = _interopDefaultLegacy(videojs);
|
31 | var _extends__default = _interopDefaultLegacy(_extends);
|
32 | var parseSidx__default = _interopDefaultLegacy(parseSidx);
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | var resolveUrl = _resolveUrl__default["default"];
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | var resolveManifestRedirect = function resolveManifestRedirect(handleManifestRedirect, url, req) {
|
51 |
|
52 |
|
53 |
|
54 | if (handleManifestRedirect && req && req.responseURL && url !== req.responseURL) {
|
55 | return req.responseURL;
|
56 | }
|
57 |
|
58 | return url;
|
59 | };
|
60 |
|
61 | var logger = function logger(source) {
|
62 | if (videojs__default["default"].log.debug) {
|
63 | return videojs__default["default"].log.debug.bind(videojs__default["default"], 'VHS:', source + " >");
|
64 | }
|
65 |
|
66 | return function () {};
|
67 | };
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | var TIME_FUDGE_FACTOR = 1 / 30;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | var SAFE_TIME_DELTA = TIME_FUDGE_FACTOR * 3;
|
83 |
|
84 | var filterRanges = function filterRanges(timeRanges, predicate) {
|
85 | var results = [];
|
86 | var i;
|
87 |
|
88 | if (timeRanges && timeRanges.length) {
|
89 |
|
90 | for (i = 0; i < timeRanges.length; i++) {
|
91 | if (predicate(timeRanges.start(i), timeRanges.end(i))) {
|
92 | results.push([timeRanges.start(i), timeRanges.end(i)]);
|
93 | }
|
94 | }
|
95 | }
|
96 |
|
97 | return videojs__default["default"].createTimeRanges(results);
|
98 | };
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | var findRange = function findRange(buffered, time) {
|
110 | return filterRanges(buffered, function (start, end) {
|
111 | return start - SAFE_TIME_DELTA <= time && end + SAFE_TIME_DELTA >= time;
|
112 | });
|
113 | };
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | var findNextRange = function findNextRange(timeRanges, time) {
|
123 | return filterRanges(timeRanges, function (start) {
|
124 | return start - TIME_FUDGE_FACTOR >= time;
|
125 | });
|
126 | };
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | var findGaps = function findGaps(buffered) {
|
135 | if (buffered.length < 2) {
|
136 | return videojs__default["default"].createTimeRanges();
|
137 | }
|
138 |
|
139 | var ranges = [];
|
140 |
|
141 | for (var i = 1; i < buffered.length; i++) {
|
142 | var start = buffered.end(i - 1);
|
143 | var end = buffered.start(i);
|
144 | ranges.push([start, end]);
|
145 | }
|
146 |
|
147 | return videojs__default["default"].createTimeRanges(ranges);
|
148 | };
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | var bufferIntersection = function bufferIntersection(bufferA, bufferB) {
|
158 | var start = null;
|
159 | var end = null;
|
160 | var arity = 0;
|
161 | var extents = [];
|
162 | var ranges = [];
|
163 |
|
164 | if (!bufferA || !bufferA.length || !bufferB || !bufferB.length) {
|
165 | return videojs__default["default"].createTimeRange();
|
166 | }
|
167 |
|
168 |
|
169 |
|
170 | var count = bufferA.length;
|
171 |
|
172 | while (count--) {
|
173 | extents.push({
|
174 | time: bufferA.start(count),
|
175 | type: 'start'
|
176 | });
|
177 | extents.push({
|
178 | time: bufferA.end(count),
|
179 | type: 'end'
|
180 | });
|
181 | }
|
182 |
|
183 | count = bufferB.length;
|
184 |
|
185 | while (count--) {
|
186 | extents.push({
|
187 | time: bufferB.start(count),
|
188 | type: 'start'
|
189 | });
|
190 | extents.push({
|
191 | time: bufferB.end(count),
|
192 | type: 'end'
|
193 | });
|
194 | }
|
195 |
|
196 |
|
197 | extents.sort(function (a, b) {
|
198 | return a.time - b.time;
|
199 | });
|
200 |
|
201 |
|
202 | for (count = 0; count < extents.length; count++) {
|
203 | if (extents[count].type === 'start') {
|
204 | arity++;
|
205 |
|
206 |
|
207 | if (arity === 2) {
|
208 | start = extents[count].time;
|
209 | }
|
210 | } else if (extents[count].type === 'end') {
|
211 | arity--;
|
212 |
|
213 |
|
214 | if (arity === 1) {
|
215 | end = extents[count].time;
|
216 | }
|
217 | }
|
218 |
|
219 |
|
220 | if (start !== null && end !== null) {
|
221 | ranges.push([start, end]);
|
222 | start = null;
|
223 | end = null;
|
224 | }
|
225 | }
|
226 |
|
227 | return videojs__default["default"].createTimeRanges(ranges);
|
228 | };
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | var printableRange = function printableRange(range) {
|
237 | var strArr = [];
|
238 |
|
239 | if (!range || !range.length) {
|
240 | return '';
|
241 | }
|
242 |
|
243 | for (var i = 0; i < range.length; i++) {
|
244 | strArr.push(range.start(i) + ' => ' + range.end(i));
|
245 | }
|
246 |
|
247 | return strArr.join(', ');
|
248 | };
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | var timeUntilRebuffer = function timeUntilRebuffer(buffered, currentTime, playbackRate) {
|
265 | if (playbackRate === void 0) {
|
266 | playbackRate = 1;
|
267 | }
|
268 |
|
269 | var bufferedEnd = buffered.length ? buffered.end(buffered.length - 1) : 0;
|
270 | return (bufferedEnd - currentTime) / playbackRate;
|
271 | };
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | var timeRangesToArray = function timeRangesToArray(timeRanges) {
|
280 | var timeRangesList = [];
|
281 |
|
282 | for (var i = 0; i < timeRanges.length; i++) {
|
283 | timeRangesList.push({
|
284 | start: timeRanges.start(i),
|
285 | end: timeRanges.end(i)
|
286 | });
|
287 | }
|
288 |
|
289 | return timeRangesList;
|
290 | };
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | var isRangeDifferent = function isRangeDifferent(a, b) {
|
305 |
|
306 | if (a === b) {
|
307 | return false;
|
308 | }
|
309 |
|
310 |
|
311 | if (!a && b || !b && a) {
|
312 | return true;
|
313 | }
|
314 |
|
315 |
|
316 | if (a.length !== b.length) {
|
317 | return true;
|
318 | }
|
319 |
|
320 |
|
321 | for (var i = 0; i < a.length; i++) {
|
322 | if (a.start(i) !== b.start(i) || a.end(i) !== b.end(i)) {
|
323 | return true;
|
324 | }
|
325 | }
|
326 |
|
327 |
|
328 |
|
329 | return false;
|
330 | };
|
331 | var lastBufferedEnd = function lastBufferedEnd(a) {
|
332 | if (!a || !a.length || !a.end) {
|
333 | return;
|
334 | }
|
335 |
|
336 | return a.end(a.length - 1);
|
337 | };
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 | var timeAheadOf = function timeAheadOf(range, startTime) {
|
354 | var time = 0;
|
355 |
|
356 | if (!range || !range.length) {
|
357 | return time;
|
358 | }
|
359 |
|
360 | for (var i = 0; i < range.length; i++) {
|
361 | var start = range.start(i);
|
362 | var end = range.end(i);
|
363 |
|
364 | if (startTime > end) {
|
365 | continue;
|
366 | }
|
367 |
|
368 |
|
369 | if (startTime > start && startTime <= end) {
|
370 | time += end - startTime;
|
371 | continue;
|
372 | }
|
373 |
|
374 |
|
375 | time += end - start;
|
376 | }
|
377 |
|
378 | return time;
|
379 | };
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 | var createTimeRange = videojs__default["default"].createTimeRange;
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 | var getPartsAndSegments = function getPartsAndSegments(playlist) {
|
397 | return (playlist.segments || []).reduce(function (acc, segment, si) {
|
398 | if (segment.parts) {
|
399 | segment.parts.forEach(function (part, pi) {
|
400 | acc.push({
|
401 | duration: part.duration,
|
402 | segmentIndex: si,
|
403 | partIndex: pi,
|
404 | part: part,
|
405 | segment: segment
|
406 | });
|
407 | });
|
408 | } else {
|
409 | acc.push({
|
410 | duration: segment.duration,
|
411 | segmentIndex: si,
|
412 | partIndex: null,
|
413 | segment: segment,
|
414 | part: null
|
415 | });
|
416 | }
|
417 |
|
418 | return acc;
|
419 | }, []);
|
420 | };
|
421 | var getLastParts = function getLastParts(media) {
|
422 | var lastSegment = media.segments && media.segments.length && media.segments[media.segments.length - 1];
|
423 | return lastSegment && lastSegment.parts || [];
|
424 | };
|
425 | var getKnownPartCount = function getKnownPartCount(_ref) {
|
426 | var preloadSegment = _ref.preloadSegment;
|
427 |
|
428 | if (!preloadSegment) {
|
429 | return;
|
430 | }
|
431 |
|
432 | var parts = preloadSegment.parts,
|
433 | preloadHints = preloadSegment.preloadHints;
|
434 | var partCount = (preloadHints || []).reduce(function (count, hint) {
|
435 | return count + (hint.type === 'PART' ? 1 : 0);
|
436 | }, 0);
|
437 | partCount += parts && parts.length ? parts.length : 0;
|
438 | return partCount;
|
439 | };
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 | var liveEdgeDelay = function liveEdgeDelay(master, media) {
|
450 | if (media.endList) {
|
451 | return 0;
|
452 | }
|
453 |
|
454 |
|
455 | if (master && master.suggestedPresentationDelay) {
|
456 | return master.suggestedPresentationDelay;
|
457 | }
|
458 |
|
459 | var hasParts = getLastParts(media).length > 0;
|
460 |
|
461 | if (hasParts && media.serverControl && media.serverControl.partHoldBack) {
|
462 | return media.serverControl.partHoldBack;
|
463 | } else if (hasParts && media.partTargetDuration) {
|
464 | return media.partTargetDuration * 3;
|
465 | } else if (media.serverControl && media.serverControl.holdBack) {
|
466 | return media.serverControl.holdBack;
|
467 | } else if (media.targetDuration) {
|
468 | return media.targetDuration * 3;
|
469 | }
|
470 |
|
471 | return 0;
|
472 | };
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 | var backwardDuration = function backwardDuration(playlist, endSequence) {
|
482 | var result = 0;
|
483 | var i = endSequence - playlist.mediaSequence;
|
484 |
|
485 |
|
486 | var segment = playlist.segments[i];
|
487 |
|
488 |
|
489 | if (segment) {
|
490 | if (typeof segment.start !== 'undefined') {
|
491 | return {
|
492 | result: segment.start,
|
493 | precise: true
|
494 | };
|
495 | }
|
496 |
|
497 | if (typeof segment.end !== 'undefined') {
|
498 | return {
|
499 | result: segment.end - segment.duration,
|
500 | precise: true
|
501 | };
|
502 | }
|
503 | }
|
504 |
|
505 | while (i--) {
|
506 | segment = playlist.segments[i];
|
507 |
|
508 | if (typeof segment.end !== 'undefined') {
|
509 | return {
|
510 | result: result + segment.end,
|
511 | precise: true
|
512 | };
|
513 | }
|
514 |
|
515 | result += segment.duration;
|
516 |
|
517 | if (typeof segment.start !== 'undefined') {
|
518 | return {
|
519 | result: result + segment.start,
|
520 | precise: true
|
521 | };
|
522 | }
|
523 | }
|
524 |
|
525 | return {
|
526 | result: result,
|
527 | precise: false
|
528 | };
|
529 | };
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 | var forwardDuration = function forwardDuration(playlist, endSequence) {
|
540 | var result = 0;
|
541 | var segment;
|
542 | var i = endSequence - playlist.mediaSequence;
|
543 |
|
544 |
|
545 | for (; i < playlist.segments.length; i++) {
|
546 | segment = playlist.segments[i];
|
547 |
|
548 | if (typeof segment.start !== 'undefined') {
|
549 | return {
|
550 | result: segment.start - result,
|
551 | precise: true
|
552 | };
|
553 | }
|
554 |
|
555 | result += segment.duration;
|
556 |
|
557 | if (typeof segment.end !== 'undefined') {
|
558 | return {
|
559 | result: segment.end - result,
|
560 | precise: true
|
561 | };
|
562 | }
|
563 | }
|
564 |
|
565 |
|
566 | return {
|
567 | result: -1,
|
568 | precise: false
|
569 | };
|
570 | };
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 | var intervalDuration = function intervalDuration(playlist, endSequence, expired) {
|
587 | if (typeof endSequence === 'undefined') {
|
588 | endSequence = playlist.mediaSequence + playlist.segments.length;
|
589 | }
|
590 |
|
591 | if (endSequence < playlist.mediaSequence) {
|
592 | return 0;
|
593 | }
|
594 |
|
595 |
|
596 | var backward = backwardDuration(playlist, endSequence);
|
597 |
|
598 | if (backward.precise) {
|
599 |
|
600 |
|
601 |
|
602 | return backward.result;
|
603 | }
|
604 |
|
605 |
|
606 |
|
607 | var forward = forwardDuration(playlist, endSequence);
|
608 |
|
609 | if (forward.precise) {
|
610 |
|
611 |
|
612 | return forward.result;
|
613 | }
|
614 |
|
615 |
|
616 | return backward.result + expired;
|
617 | };
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 | var duration = function duration(playlist, endSequence, expired) {
|
636 | if (!playlist) {
|
637 | return 0;
|
638 | }
|
639 |
|
640 | if (typeof expired !== 'number') {
|
641 | expired = 0;
|
642 | }
|
643 |
|
644 |
|
645 |
|
646 | if (typeof endSequence === 'undefined') {
|
647 |
|
648 | if (playlist.totalDuration) {
|
649 | return playlist.totalDuration;
|
650 | }
|
651 |
|
652 |
|
653 | if (!playlist.endList) {
|
654 | return window__default["default"].Infinity;
|
655 | }
|
656 | }
|
657 |
|
658 |
|
659 | return intervalDuration(playlist, endSequence, expired);
|
660 | };
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 | var sumDurations = function sumDurations(_ref2) {
|
675 | var defaultDuration = _ref2.defaultDuration,
|
676 | durationList = _ref2.durationList,
|
677 | startIndex = _ref2.startIndex,
|
678 | endIndex = _ref2.endIndex;
|
679 | var durations = 0;
|
680 |
|
681 | if (startIndex > endIndex) {
|
682 | var _ref3 = [endIndex, startIndex];
|
683 | startIndex = _ref3[0];
|
684 | endIndex = _ref3[1];
|
685 | }
|
686 |
|
687 | if (startIndex < 0) {
|
688 | for (var i = startIndex; i < Math.min(0, endIndex); i++) {
|
689 | durations += defaultDuration;
|
690 | }
|
691 |
|
692 | startIndex = 0;
|
693 | }
|
694 |
|
695 | for (var _i = startIndex; _i < endIndex; _i++) {
|
696 | durations += durationList[_i].duration;
|
697 | }
|
698 |
|
699 | return durations;
|
700 | };
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 | var playlistEnd = function playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding) {
|
722 | if (!playlist || !playlist.segments) {
|
723 | return null;
|
724 | }
|
725 |
|
726 | if (playlist.endList) {
|
727 | return duration(playlist);
|
728 | }
|
729 |
|
730 | if (expired === null) {
|
731 | return null;
|
732 | }
|
733 |
|
734 | expired = expired || 0;
|
735 | var lastSegmentTime = intervalDuration(playlist, playlist.mediaSequence + playlist.segments.length, expired);
|
736 |
|
737 | if (useSafeLiveEnd) {
|
738 | liveEdgePadding = typeof liveEdgePadding === 'number' ? liveEdgePadding : liveEdgeDelay(null, playlist);
|
739 | lastSegmentTime -= liveEdgePadding;
|
740 | }
|
741 |
|
742 |
|
743 | return Math.max(0, lastSegmentTime);
|
744 | };
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 | var seekable = function seekable(playlist, expired, liveEdgePadding) {
|
764 | var useSafeLiveEnd = true;
|
765 | var seekableStart = expired || 0;
|
766 | var seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding);
|
767 |
|
768 | if (seekableEnd === null) {
|
769 | return createTimeRange();
|
770 | }
|
771 |
|
772 | return createTimeRange(seekableStart, seekableEnd);
|
773 | };
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 | var getMediaInfoForTime = function getMediaInfoForTime(_ref4) {
|
789 | var playlist = _ref4.playlist,
|
790 | currentTime = _ref4.currentTime,
|
791 | startingSegmentIndex = _ref4.startingSegmentIndex,
|
792 | startingPartIndex = _ref4.startingPartIndex,
|
793 | startTime = _ref4.startTime,
|
794 | experimentalExactManifestTimings = _ref4.experimentalExactManifestTimings;
|
795 | var time = currentTime - startTime;
|
796 | var partsAndSegments = getPartsAndSegments(playlist);
|
797 | var startIndex = 0;
|
798 |
|
799 | for (var i = 0; i < partsAndSegments.length; i++) {
|
800 | var partAndSegment = partsAndSegments[i];
|
801 |
|
802 | if (startingSegmentIndex !== partAndSegment.segmentIndex) {
|
803 | continue;
|
804 | }
|
805 |
|
806 |
|
807 | if (typeof startingPartIndex === 'number' && typeof partAndSegment.partIndex === 'number' && startingPartIndex !== partAndSegment.partIndex) {
|
808 | continue;
|
809 | }
|
810 |
|
811 | startIndex = i;
|
812 | break;
|
813 | }
|
814 |
|
815 | if (time < 0) {
|
816 |
|
817 |
|
818 | if (startIndex > 0) {
|
819 | for (var _i2 = startIndex - 1; _i2 >= 0; _i2--) {
|
820 | var _partAndSegment = partsAndSegments[_i2];
|
821 | time += _partAndSegment.duration;
|
822 |
|
823 | if (experimentalExactManifestTimings) {
|
824 | if (time < 0) {
|
825 | continue;
|
826 | }
|
827 | } else if (time + TIME_FUDGE_FACTOR <= 0) {
|
828 | continue;
|
829 | }
|
830 |
|
831 | return {
|
832 | partIndex: _partAndSegment.partIndex,
|
833 | segmentIndex: _partAndSegment.segmentIndex,
|
834 | startTime: startTime - sumDurations({
|
835 | defaultDuration: playlist.targetDuration,
|
836 | durationList: partsAndSegments,
|
837 | startIndex: startIndex,
|
838 | endIndex: _i2
|
839 | })
|
840 | };
|
841 | }
|
842 | }
|
843 |
|
844 |
|
845 |
|
846 | return {
|
847 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
848 | segmentIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
849 | startTime: currentTime
|
850 | };
|
851 | }
|
852 |
|
853 |
|
854 |
|
855 |
|
856 | if (startIndex < 0) {
|
857 | for (var _i3 = startIndex; _i3 < 0; _i3++) {
|
858 | time -= playlist.targetDuration;
|
859 |
|
860 | if (time < 0) {
|
861 | return {
|
862 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
863 | segmentIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
864 | startTime: currentTime
|
865 | };
|
866 | }
|
867 | }
|
868 |
|
869 | startIndex = 0;
|
870 | }
|
871 |
|
872 |
|
873 |
|
874 | for (var _i4 = startIndex; _i4 < partsAndSegments.length; _i4++) {
|
875 | var _partAndSegment2 = partsAndSegments[_i4];
|
876 | time -= _partAndSegment2.duration;
|
877 |
|
878 | if (experimentalExactManifestTimings) {
|
879 | if (time > 0) {
|
880 | continue;
|
881 | }
|
882 | } else if (time - TIME_FUDGE_FACTOR >= 0) {
|
883 | continue;
|
884 | }
|
885 |
|
886 | return {
|
887 | partIndex: _partAndSegment2.partIndex,
|
888 | segmentIndex: _partAndSegment2.segmentIndex,
|
889 | startTime: startTime + sumDurations({
|
890 | defaultDuration: playlist.targetDuration,
|
891 | durationList: partsAndSegments,
|
892 | startIndex: startIndex,
|
893 | endIndex: _i4
|
894 | })
|
895 | };
|
896 | }
|
897 |
|
898 |
|
899 | return {
|
900 | segmentIndex: partsAndSegments[partsAndSegments.length - 1].segmentIndex,
|
901 | partIndex: partsAndSegments[partsAndSegments.length - 1].partIndex,
|
902 | startTime: currentTime
|
903 | };
|
904 | };
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 | var isBlacklisted = function isBlacklisted(playlist) {
|
914 | return playlist.excludeUntil && playlist.excludeUntil > Date.now();
|
915 | };
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 | var isIncompatible = function isIncompatible(playlist) {
|
926 | return playlist.excludeUntil && playlist.excludeUntil === Infinity;
|
927 | };
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 | var isEnabled = function isEnabled(playlist) {
|
937 | var blacklisted = isBlacklisted(playlist);
|
938 | return !playlist.disabled && !blacklisted;
|
939 | };
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 | var isDisabled = function isDisabled(playlist) {
|
949 | return playlist.disabled;
|
950 | };
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 | var isAes = function isAes(media) {
|
958 | for (var i = 0; i < media.segments.length; i++) {
|
959 | if (media.segments[i].key) {
|
960 | return true;
|
961 | }
|
962 | }
|
963 |
|
964 | return false;
|
965 | };
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 | var hasAttribute = function hasAttribute(attr, playlist) {
|
979 | return playlist.attributes && playlist.attributes[attr];
|
980 | };
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 | var estimateSegmentRequestTime = function estimateSegmentRequestTime(segmentDuration, bandwidth, playlist, bytesReceived) {
|
999 | if (bytesReceived === void 0) {
|
1000 | bytesReceived = 0;
|
1001 | }
|
1002 |
|
1003 | if (!hasAttribute('BANDWIDTH', playlist)) {
|
1004 | return NaN;
|
1005 | }
|
1006 |
|
1007 | var size = segmentDuration * playlist.attributes.BANDWIDTH;
|
1008 | return (size - bytesReceived * 8) / bandwidth;
|
1009 | };
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 | var isLowestEnabledRendition = function isLowestEnabledRendition(master, media) {
|
1017 | if (master.playlists.length === 1) {
|
1018 | return true;
|
1019 | }
|
1020 |
|
1021 | var currentBandwidth = media.attributes.BANDWIDTH || Number.MAX_VALUE;
|
1022 | return master.playlists.filter(function (playlist) {
|
1023 | if (!isEnabled(playlist)) {
|
1024 | return false;
|
1025 | }
|
1026 |
|
1027 | return (playlist.attributes.BANDWIDTH || 0) < currentBandwidth;
|
1028 | }).length === 0;
|
1029 | };
|
1030 | var playlistMatch = function playlistMatch(a, b) {
|
1031 |
|
1032 |
|
1033 |
|
1034 | if (!a && !b || !a && b || a && !b) {
|
1035 | return false;
|
1036 | }
|
1037 |
|
1038 |
|
1039 | if (a === b) {
|
1040 | return true;
|
1041 | }
|
1042 |
|
1043 |
|
1044 |
|
1045 | if (a.id && b.id && a.id === b.id) {
|
1046 | return true;
|
1047 | }
|
1048 |
|
1049 |
|
1050 |
|
1051 | if (a.resolvedUri && b.resolvedUri && a.resolvedUri === b.resolvedUri) {
|
1052 | return true;
|
1053 | }
|
1054 |
|
1055 |
|
1056 |
|
1057 | if (a.uri && b.uri && a.uri === b.uri) {
|
1058 | return true;
|
1059 | }
|
1060 |
|
1061 | return false;
|
1062 | };
|
1063 |
|
1064 | var someAudioVariant = function someAudioVariant(master, callback) {
|
1065 | var AUDIO = master && master.mediaGroups && master.mediaGroups.AUDIO || {};
|
1066 | var found = false;
|
1067 |
|
1068 | for (var groupName in AUDIO) {
|
1069 | for (var label in AUDIO[groupName]) {
|
1070 | found = callback(AUDIO[groupName][label]);
|
1071 |
|
1072 | if (found) {
|
1073 | break;
|
1074 | }
|
1075 | }
|
1076 |
|
1077 | if (found) {
|
1078 | break;
|
1079 | }
|
1080 | }
|
1081 |
|
1082 | return !!found;
|
1083 | };
|
1084 |
|
1085 | var isAudioOnly = function isAudioOnly(master) {
|
1086 |
|
1087 |
|
1088 | if (!master || !master.playlists || !master.playlists.length) {
|
1089 |
|
1090 |
|
1091 | var found = someAudioVariant(master, function (variant) {
|
1092 | return variant.playlists && variant.playlists.length || variant.uri;
|
1093 | });
|
1094 | return found;
|
1095 | }
|
1096 |
|
1097 |
|
1098 | var _loop = function _loop(i) {
|
1099 | var playlist = master.playlists[i];
|
1100 | var CODECS = playlist.attributes && playlist.attributes.CODECS;
|
1101 |
|
1102 | if (CODECS && CODECS.split(',').every(function (c) {
|
1103 | return codecs_js.isAudioCodec(c);
|
1104 | })) {
|
1105 | return "continue";
|
1106 | }
|
1107 |
|
1108 |
|
1109 | var found = someAudioVariant(master, function (variant) {
|
1110 | return playlistMatch(playlist, variant);
|
1111 | });
|
1112 |
|
1113 | if (found) {
|
1114 | return "continue";
|
1115 | }
|
1116 |
|
1117 |
|
1118 |
|
1119 | return {
|
1120 | v: false
|
1121 | };
|
1122 | };
|
1123 |
|
1124 | for (var i = 0; i < master.playlists.length; i++) {
|
1125 | var _ret = _loop(i);
|
1126 |
|
1127 | if (_ret === "continue") continue;
|
1128 | if (typeof _ret === "object") return _ret.v;
|
1129 | }
|
1130 |
|
1131 |
|
1132 |
|
1133 | return true;
|
1134 | };
|
1135 |
|
1136 | var Playlist = {
|
1137 | liveEdgeDelay: liveEdgeDelay,
|
1138 | duration: duration,
|
1139 | seekable: seekable,
|
1140 | getMediaInfoForTime: getMediaInfoForTime,
|
1141 | isEnabled: isEnabled,
|
1142 | isDisabled: isDisabled,
|
1143 | isBlacklisted: isBlacklisted,
|
1144 | isIncompatible: isIncompatible,
|
1145 | playlistEnd: playlistEnd,
|
1146 | isAes: isAes,
|
1147 | hasAttribute: hasAttribute,
|
1148 | estimateSegmentRequestTime: estimateSegmentRequestTime,
|
1149 | isLowestEnabledRendition: isLowestEnabledRendition,
|
1150 | isAudioOnly: isAudioOnly,
|
1151 | playlistMatch: playlistMatch
|
1152 | };
|
1153 |
|
1154 | var log = videojs__default["default"].log;
|
1155 | var createPlaylistID = function createPlaylistID(index, uri) {
|
1156 | return index + "-" + uri;
|
1157 | };
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 | var parseManifest = function parseManifest(_ref) {
|
1178 | var onwarn = _ref.onwarn,
|
1179 | oninfo = _ref.oninfo,
|
1180 | manifestString = _ref.manifestString,
|
1181 | _ref$customTagParsers = _ref.customTagParsers,
|
1182 | customTagParsers = _ref$customTagParsers === void 0 ? [] : _ref$customTagParsers,
|
1183 | _ref$customTagMappers = _ref.customTagMappers,
|
1184 | customTagMappers = _ref$customTagMappers === void 0 ? [] : _ref$customTagMappers,
|
1185 | experimentalLLHLS = _ref.experimentalLLHLS;
|
1186 | var parser = new m3u8Parser.Parser();
|
1187 |
|
1188 | if (onwarn) {
|
1189 | parser.on('warn', onwarn);
|
1190 | }
|
1191 |
|
1192 | if (oninfo) {
|
1193 | parser.on('info', oninfo);
|
1194 | }
|
1195 |
|
1196 | customTagParsers.forEach(function (customParser) {
|
1197 | return parser.addParser(customParser);
|
1198 | });
|
1199 | customTagMappers.forEach(function (mapper) {
|
1200 | return parser.addTagMapper(mapper);
|
1201 | });
|
1202 | parser.push(manifestString);
|
1203 | parser.end();
|
1204 | var manifest = parser.manifest;
|
1205 |
|
1206 |
|
1207 | if (!experimentalLLHLS) {
|
1208 | ['preloadSegment', 'skip', 'serverControl', 'renditionReports', 'partInf', 'partTargetDuration'].forEach(function (k) {
|
1209 | if (manifest.hasOwnProperty(k)) {
|
1210 | delete manifest[k];
|
1211 | }
|
1212 | });
|
1213 |
|
1214 | if (manifest.segments) {
|
1215 | manifest.segments.forEach(function (segment) {
|
1216 | ['parts', 'preloadHints'].forEach(function (k) {
|
1217 | if (segment.hasOwnProperty(k)) {
|
1218 | delete segment[k];
|
1219 | }
|
1220 | });
|
1221 | });
|
1222 | }
|
1223 | }
|
1224 |
|
1225 | if (!manifest.targetDuration) {
|
1226 | var targetDuration = 10;
|
1227 |
|
1228 | if (manifest.segments && manifest.segments.length) {
|
1229 | targetDuration = manifest.segments.reduce(function (acc, s) {
|
1230 | return Math.max(acc, s.duration);
|
1231 | }, 0);
|
1232 | }
|
1233 |
|
1234 | if (onwarn) {
|
1235 | onwarn("manifest has no targetDuration defaulting to " + targetDuration);
|
1236 | }
|
1237 |
|
1238 | manifest.targetDuration = targetDuration;
|
1239 | }
|
1240 |
|
1241 | var parts = getLastParts(manifest);
|
1242 |
|
1243 | if (parts.length && !manifest.partTargetDuration) {
|
1244 | var partTargetDuration = parts.reduce(function (acc, p) {
|
1245 | return Math.max(acc, p.duration);
|
1246 | }, 0);
|
1247 |
|
1248 | if (onwarn) {
|
1249 | onwarn("manifest has no partTargetDuration defaulting to " + partTargetDuration);
|
1250 | 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.');
|
1251 | }
|
1252 |
|
1253 | manifest.partTargetDuration = partTargetDuration;
|
1254 | }
|
1255 |
|
1256 | return manifest;
|
1257 | };
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 | var forEachMediaGroup = function forEachMediaGroup(master, callback) {
|
1269 | if (!master.mediaGroups) {
|
1270 | return;
|
1271 | }
|
1272 |
|
1273 | ['AUDIO', 'SUBTITLES'].forEach(function (mediaType) {
|
1274 | if (!master.mediaGroups[mediaType]) {
|
1275 | return;
|
1276 | }
|
1277 |
|
1278 | for (var groupKey in master.mediaGroups[mediaType]) {
|
1279 | for (var labelKey in master.mediaGroups[mediaType][groupKey]) {
|
1280 | var mediaProperties = master.mediaGroups[mediaType][groupKey][labelKey];
|
1281 | callback(mediaProperties, mediaType, groupKey, labelKey);
|
1282 | }
|
1283 | }
|
1284 | });
|
1285 | };
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 | var setupMediaPlaylist = function setupMediaPlaylist(_ref2) {
|
1302 | var playlist = _ref2.playlist,
|
1303 | uri = _ref2.uri,
|
1304 | id = _ref2.id;
|
1305 | playlist.id = id;
|
1306 | playlist.playlistErrors_ = 0;
|
1307 |
|
1308 | if (uri) {
|
1309 |
|
1310 |
|
1311 |
|
1312 | playlist.uri = uri;
|
1313 | }
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 | playlist.attributes = playlist.attributes || {};
|
1323 | };
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 | var setupMediaPlaylists = function setupMediaPlaylists(master) {
|
1334 | var i = master.playlists.length;
|
1335 |
|
1336 | while (i--) {
|
1337 | var playlist = master.playlists[i];
|
1338 | setupMediaPlaylist({
|
1339 | playlist: playlist,
|
1340 | id: createPlaylistID(i, playlist.uri)
|
1341 | });
|
1342 | playlist.resolvedUri = resolveUrl(master.uri, playlist.uri);
|
1343 | master.playlists[playlist.id] = playlist;
|
1344 |
|
1345 | master.playlists[playlist.uri] = playlist;
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 | if (!playlist.attributes.BANDWIDTH) {
|
1351 | log.warn('Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute.');
|
1352 | }
|
1353 | }
|
1354 | };
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 | var resolveMediaGroupUris = function resolveMediaGroupUris(master) {
|
1363 | forEachMediaGroup(master, function (properties) {
|
1364 | if (properties.uri) {
|
1365 | properties.resolvedUri = resolveUrl(master.uri, properties.uri);
|
1366 | }
|
1367 | });
|
1368 | };
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 | var masterForMedia = function masterForMedia(media, uri) {
|
1382 | var id = createPlaylistID(0, uri);
|
1383 | var master = {
|
1384 | mediaGroups: {
|
1385 | 'AUDIO': {},
|
1386 | 'VIDEO': {},
|
1387 | 'CLOSED-CAPTIONS': {},
|
1388 | 'SUBTITLES': {}
|
1389 | },
|
1390 | uri: window__default["default"].location.href,
|
1391 | resolvedUri: window__default["default"].location.href,
|
1392 | playlists: [{
|
1393 | uri: uri,
|
1394 | id: id,
|
1395 | resolvedUri: uri,
|
1396 |
|
1397 |
|
1398 | attributes: {}
|
1399 | }]
|
1400 | };
|
1401 |
|
1402 | master.playlists[id] = master.playlists[0];
|
1403 |
|
1404 | master.playlists[uri] = master.playlists[0];
|
1405 | return master;
|
1406 | };
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 | var addPropertiesToMaster = function addPropertiesToMaster(master, uri) {
|
1418 | master.uri = uri;
|
1419 |
|
1420 | for (var i = 0; i < master.playlists.length; i++) {
|
1421 | if (!master.playlists[i].uri) {
|
1422 |
|
1423 |
|
1424 |
|
1425 | var phonyUri = "placeholder-uri-" + i;
|
1426 | master.playlists[i].uri = phonyUri;
|
1427 | }
|
1428 | }
|
1429 |
|
1430 | var audioOnlyMaster = isAudioOnly(master);
|
1431 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
1432 | var groupId = "placeholder-uri-" + mediaType + "-" + groupKey + "-" + labelKey;
|
1433 |
|
1434 | if (!properties.playlists || !properties.playlists.length) {
|
1435 |
|
1436 |
|
1437 |
|
1438 | if (audioOnlyMaster && mediaType === 'AUDIO' && !properties.uri) {
|
1439 | for (var _i = 0; _i < master.playlists.length; _i++) {
|
1440 | var p = master.playlists[_i];
|
1441 |
|
1442 | if (p.attributes && p.attributes.AUDIO && p.attributes.AUDIO === groupKey) {
|
1443 | return;
|
1444 | }
|
1445 | }
|
1446 | }
|
1447 |
|
1448 | properties.playlists = [_extends__default["default"]({}, properties)];
|
1449 | }
|
1450 |
|
1451 | properties.playlists.forEach(function (p, i) {
|
1452 | var id = createPlaylistID(i, groupId);
|
1453 |
|
1454 | if (p.uri) {
|
1455 | p.resolvedUri = p.resolvedUri || resolveUrl(master.uri, p.uri);
|
1456 | } else {
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 | p.uri = i === 0 ? groupId : id;
|
1462 |
|
1463 |
|
1464 | p.resolvedUri = p.uri;
|
1465 | }
|
1466 |
|
1467 | p.id = p.id || id;
|
1468 |
|
1469 |
|
1470 | p.attributes = p.attributes || {};
|
1471 |
|
1472 | master.playlists[p.id] = p;
|
1473 | master.playlists[p.uri] = p;
|
1474 | });
|
1475 | });
|
1476 | setupMediaPlaylists(master);
|
1477 | resolveMediaGroupUris(master);
|
1478 | };
|
1479 |
|
1480 | var mergeOptions$2 = videojs__default["default"].mergeOptions,
|
1481 | EventTarget$1 = videojs__default["default"].EventTarget;
|
1482 |
|
1483 | var addLLHLSQueryDirectives = function addLLHLSQueryDirectives(uri, media) {
|
1484 | if (media.endList || !media.serverControl) {
|
1485 | return uri;
|
1486 | }
|
1487 |
|
1488 | var parameters = {};
|
1489 |
|
1490 | if (media.serverControl.canBlockReload) {
|
1491 | var preloadSegment = media.preloadSegment;
|
1492 |
|
1493 | var nextMSN = media.mediaSequence + media.segments.length;
|
1494 |
|
1495 |
|
1496 |
|
1497 | if (preloadSegment) {
|
1498 | var parts = preloadSegment.parts || [];
|
1499 |
|
1500 | var nextPart = getKnownPartCount(media) - 1;
|
1501 |
|
1502 |
|
1503 |
|
1504 | if (nextPart > -1 && nextPart !== parts.length - 1) {
|
1505 |
|
1506 |
|
1507 | parameters._HLS_part = nextPart;
|
1508 | }
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 | if (nextPart > -1 || parts.length) {
|
1520 | nextMSN--;
|
1521 | }
|
1522 | }
|
1523 |
|
1524 |
|
1525 |
|
1526 | parameters._HLS_msn = nextMSN;
|
1527 | }
|
1528 |
|
1529 | if (media.serverControl && media.serverControl.canSkipUntil) {
|
1530 |
|
1531 |
|
1532 | parameters._HLS_skip = media.serverControl.canSkipDateranges ? 'v2' : 'YES';
|
1533 | }
|
1534 |
|
1535 | if (Object.keys(parameters).length) {
|
1536 | var parsedUri = new window__default["default"].URL(uri);
|
1537 | ['_HLS_skip', '_HLS_msn', '_HLS_part'].forEach(function (name) {
|
1538 | if (!parameters.hasOwnProperty(name)) {
|
1539 | return;
|
1540 | }
|
1541 |
|
1542 | parsedUri.searchParams.set(name, parameters[name]);
|
1543 | });
|
1544 | uri = parsedUri.toString();
|
1545 | }
|
1546 |
|
1547 | return uri;
|
1548 | };
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 | var updateSegment = function updateSegment(a, b) {
|
1561 | if (!a) {
|
1562 | return b;
|
1563 | }
|
1564 |
|
1565 | var result = mergeOptions$2(a, b);
|
1566 |
|
1567 |
|
1568 | if (a.preloadHints && !b.preloadHints) {
|
1569 | delete result.preloadHints;
|
1570 | }
|
1571 |
|
1572 |
|
1573 |
|
1574 | if (a.parts && !b.parts) {
|
1575 | delete result.parts;
|
1576 |
|
1577 |
|
1578 | } else if (a.parts && b.parts) {
|
1579 | for (var i = 0; i < b.parts.length; i++) {
|
1580 | if (a.parts && a.parts[i]) {
|
1581 | result.parts[i] = mergeOptions$2(a.parts[i], b.parts[i]);
|
1582 | }
|
1583 | }
|
1584 | }
|
1585 |
|
1586 |
|
1587 |
|
1588 | if (!a.skipped && b.skipped) {
|
1589 | result.skipped = false;
|
1590 | }
|
1591 |
|
1592 |
|
1593 |
|
1594 | if (a.preload && !b.preload) {
|
1595 | result.preload = false;
|
1596 | }
|
1597 |
|
1598 | return result;
|
1599 | };
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 | var updateSegments = function updateSegments(original, update, offset) {
|
1617 | var oldSegments = original.slice();
|
1618 | var newSegments = update.slice();
|
1619 | offset = offset || 0;
|
1620 | var result = [];
|
1621 | var currentMap;
|
1622 |
|
1623 | for (var newIndex = 0; newIndex < newSegments.length; newIndex++) {
|
1624 | var oldSegment = oldSegments[newIndex + offset];
|
1625 | var newSegment = newSegments[newIndex];
|
1626 |
|
1627 | if (oldSegment) {
|
1628 | currentMap = oldSegment.map || currentMap;
|
1629 | result.push(updateSegment(oldSegment, newSegment));
|
1630 | } else {
|
1631 |
|
1632 | if (currentMap && !newSegment.map) {
|
1633 | newSegment.map = currentMap;
|
1634 | }
|
1635 |
|
1636 | result.push(newSegment);
|
1637 | }
|
1638 | }
|
1639 |
|
1640 | return result;
|
1641 | };
|
1642 | var resolveSegmentUris = function resolveSegmentUris(segment, baseUri) {
|
1643 |
|
1644 |
|
1645 | if (!segment.resolvedUri && segment.uri) {
|
1646 | segment.resolvedUri = resolveUrl(baseUri, segment.uri);
|
1647 | }
|
1648 |
|
1649 | if (segment.key && !segment.key.resolvedUri) {
|
1650 | segment.key.resolvedUri = resolveUrl(baseUri, segment.key.uri);
|
1651 | }
|
1652 |
|
1653 | if (segment.map && !segment.map.resolvedUri) {
|
1654 | segment.map.resolvedUri = resolveUrl(baseUri, segment.map.uri);
|
1655 | }
|
1656 |
|
1657 | if (segment.map && segment.map.key && !segment.map.key.resolvedUri) {
|
1658 | segment.map.key.resolvedUri = resolveUrl(baseUri, segment.map.key.uri);
|
1659 | }
|
1660 |
|
1661 | if (segment.parts && segment.parts.length) {
|
1662 | segment.parts.forEach(function (p) {
|
1663 | if (p.resolvedUri) {
|
1664 | return;
|
1665 | }
|
1666 |
|
1667 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
1668 | });
|
1669 | }
|
1670 |
|
1671 | if (segment.preloadHints && segment.preloadHints.length) {
|
1672 | segment.preloadHints.forEach(function (p) {
|
1673 | if (p.resolvedUri) {
|
1674 | return;
|
1675 | }
|
1676 |
|
1677 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
1678 | });
|
1679 | }
|
1680 | };
|
1681 |
|
1682 | var getAllSegments = function getAllSegments(media) {
|
1683 | var segments = media.segments || [];
|
1684 | var preloadSegment = media.preloadSegment;
|
1685 |
|
1686 |
|
1687 |
|
1688 | if (preloadSegment && preloadSegment.parts && preloadSegment.parts.length) {
|
1689 |
|
1690 |
|
1691 |
|
1692 | if (preloadSegment.preloadHints) {
|
1693 | for (var i = 0; i < preloadSegment.preloadHints.length; i++) {
|
1694 | if (preloadSegment.preloadHints[i].type === 'MAP') {
|
1695 | return segments;
|
1696 | }
|
1697 | }
|
1698 | }
|
1699 |
|
1700 |
|
1701 | preloadSegment.duration = media.targetDuration;
|
1702 | preloadSegment.preload = true;
|
1703 | segments.push(preloadSegment);
|
1704 | }
|
1705 |
|
1706 | return segments;
|
1707 | };
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 | var isPlaylistUnchanged = function isPlaylistUnchanged(a, b) {
|
1713 | return a === b || a.segments && b.segments && a.segments.length === b.segments.length && a.endList === b.endList && a.mediaSequence === b.mediaSequence;
|
1714 | };
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 | var updateMaster$1 = function updateMaster(master, newMedia, unchangedCheck) {
|
1729 | if (unchangedCheck === void 0) {
|
1730 | unchangedCheck = isPlaylistUnchanged;
|
1731 | }
|
1732 |
|
1733 | var result = mergeOptions$2(master, {});
|
1734 | var oldMedia = result.playlists[newMedia.id];
|
1735 |
|
1736 | if (!oldMedia) {
|
1737 | return null;
|
1738 | }
|
1739 |
|
1740 | if (unchangedCheck(oldMedia, newMedia)) {
|
1741 | return null;
|
1742 | }
|
1743 |
|
1744 | newMedia.segments = getAllSegments(newMedia);
|
1745 | var mergedPlaylist = mergeOptions$2(oldMedia, newMedia);
|
1746 |
|
1747 | if (mergedPlaylist.preloadSegment && !newMedia.preloadSegment) {
|
1748 | delete mergedPlaylist.preloadSegment;
|
1749 | }
|
1750 |
|
1751 |
|
1752 | if (oldMedia.segments) {
|
1753 | if (newMedia.skip) {
|
1754 | newMedia.segments = newMedia.segments || [];
|
1755 |
|
1756 |
|
1757 | for (var i = 0; i < newMedia.skip.skippedSegments; i++) {
|
1758 | newMedia.segments.unshift({
|
1759 | skipped: true
|
1760 | });
|
1761 | }
|
1762 | }
|
1763 |
|
1764 | mergedPlaylist.segments = updateSegments(oldMedia.segments, newMedia.segments, newMedia.mediaSequence - oldMedia.mediaSequence);
|
1765 | }
|
1766 |
|
1767 |
|
1768 | mergedPlaylist.segments.forEach(function (segment) {
|
1769 | resolveSegmentUris(segment, mergedPlaylist.resolvedUri);
|
1770 | });
|
1771 |
|
1772 |
|
1773 |
|
1774 | for (var _i = 0; _i < result.playlists.length; _i++) {
|
1775 | if (result.playlists[_i].id === newMedia.id) {
|
1776 | result.playlists[_i] = mergedPlaylist;
|
1777 | }
|
1778 | }
|
1779 |
|
1780 | result.playlists[newMedia.id] = mergedPlaylist;
|
1781 |
|
1782 | result.playlists[newMedia.uri] = mergedPlaylist;
|
1783 |
|
1784 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
1785 | if (!properties.playlists) {
|
1786 | return;
|
1787 | }
|
1788 |
|
1789 | for (var _i2 = 0; _i2 < properties.playlists.length; _i2++) {
|
1790 | if (newMedia.id === properties.playlists[_i2].id) {
|
1791 | properties.playlists[_i2] = newMedia;
|
1792 | }
|
1793 | }
|
1794 | });
|
1795 | return result;
|
1796 | };
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 | var refreshDelay = function refreshDelay(media, update) {
|
1809 | var segments = media.segments || [];
|
1810 | var lastSegment = segments[segments.length - 1];
|
1811 | var lastPart = lastSegment && lastSegment.parts && lastSegment.parts[lastSegment.parts.length - 1];
|
1812 | var lastDuration = lastPart && lastPart.duration || lastSegment && lastSegment.duration;
|
1813 |
|
1814 | if (update && lastDuration) {
|
1815 | return lastDuration * 1000;
|
1816 | }
|
1817 |
|
1818 |
|
1819 |
|
1820 | return (media.partTargetDuration || media.targetDuration || 10) * 500;
|
1821 | };
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 | var PlaylistLoader = function (_EventTarget) {
|
1833 | _inheritsLoose__default["default"](PlaylistLoader, _EventTarget);
|
1834 |
|
1835 | function PlaylistLoader(src, vhs, options) {
|
1836 | var _this;
|
1837 |
|
1838 | if (options === void 0) {
|
1839 | options = {};
|
1840 | }
|
1841 |
|
1842 | _this = _EventTarget.call(this) || this;
|
1843 |
|
1844 | if (!src) {
|
1845 | throw new Error('A non-empty playlist URL or object is required');
|
1846 | }
|
1847 |
|
1848 | _this.logger_ = logger('PlaylistLoader');
|
1849 | var _options = options,
|
1850 | _options$withCredenti = _options.withCredentials,
|
1851 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
1852 | _options$handleManife = _options.handleManifestRedirects,
|
1853 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
1854 | _this.src = src;
|
1855 | _this.vhs_ = vhs;
|
1856 | _this.withCredentials = withCredentials;
|
1857 | _this.handleManifestRedirects = handleManifestRedirects;
|
1858 | var vhsOptions = vhs.options_;
|
1859 | _this.customTagParsers = vhsOptions && vhsOptions.customTagParsers || [];
|
1860 | _this.customTagMappers = vhsOptions && vhsOptions.customTagMappers || [];
|
1861 | _this.experimentalLLHLS = vhsOptions && vhsOptions.experimentalLLHLS || false;
|
1862 |
|
1863 | if (videojs__default["default"].browser.IE_VERSION) {
|
1864 | _this.experimentalLLHLS = false;
|
1865 | }
|
1866 |
|
1867 |
|
1868 | _this.state = 'HAVE_NOTHING';
|
1869 |
|
1870 | _this.handleMediaupdatetimeout_ = _this.handleMediaupdatetimeout_.bind(_assertThisInitialized__default["default"](_this));
|
1871 |
|
1872 | _this.on('mediaupdatetimeout', _this.handleMediaupdatetimeout_);
|
1873 |
|
1874 | return _this;
|
1875 | }
|
1876 |
|
1877 | var _proto = PlaylistLoader.prototype;
|
1878 |
|
1879 | _proto.handleMediaupdatetimeout_ = function handleMediaupdatetimeout_() {
|
1880 | var _this2 = this;
|
1881 |
|
1882 | if (this.state !== 'HAVE_METADATA') {
|
1883 |
|
1884 | return;
|
1885 | }
|
1886 |
|
1887 | var media = this.media();
|
1888 | var uri = resolveUrl(this.master.uri, media.uri);
|
1889 |
|
1890 | if (this.experimentalLLHLS) {
|
1891 | uri = addLLHLSQueryDirectives(uri, media);
|
1892 | }
|
1893 |
|
1894 | this.state = 'HAVE_CURRENT_METADATA';
|
1895 | this.request = this.vhs_.xhr({
|
1896 | uri: uri,
|
1897 | withCredentials: this.withCredentials
|
1898 | }, function (error, req) {
|
1899 |
|
1900 | if (!_this2.request) {
|
1901 | return;
|
1902 | }
|
1903 |
|
1904 | if (error) {
|
1905 | return _this2.playlistRequestError(_this2.request, _this2.media(), 'HAVE_METADATA');
|
1906 | }
|
1907 |
|
1908 | _this2.haveMetadata({
|
1909 | playlistString: _this2.request.responseText,
|
1910 | url: _this2.media().uri,
|
1911 | id: _this2.media().id
|
1912 | });
|
1913 | });
|
1914 | };
|
1915 |
|
1916 | _proto.playlistRequestError = function playlistRequestError(xhr, playlist, startingState) {
|
1917 | var uri = playlist.uri,
|
1918 | id = playlist.id;
|
1919 |
|
1920 | this.request = null;
|
1921 |
|
1922 | if (startingState) {
|
1923 | this.state = startingState;
|
1924 | }
|
1925 |
|
1926 | this.error = {
|
1927 | playlist: this.master.playlists[id],
|
1928 | status: xhr.status,
|
1929 | message: "HLS playlist request error at URL: " + uri + ".",
|
1930 | responseText: xhr.responseText,
|
1931 | code: xhr.status >= 500 ? 4 : 2
|
1932 | };
|
1933 | this.trigger('error');
|
1934 | };
|
1935 |
|
1936 | _proto.parseManifest_ = function parseManifest_(_ref) {
|
1937 | var _this3 = this;
|
1938 |
|
1939 | var url = _ref.url,
|
1940 | manifestString = _ref.manifestString;
|
1941 | return parseManifest({
|
1942 | onwarn: function onwarn(_ref2) {
|
1943 | var message = _ref2.message;
|
1944 | return _this3.logger_("m3u8-parser warn for " + url + ": " + message);
|
1945 | },
|
1946 | oninfo: function oninfo(_ref3) {
|
1947 | var message = _ref3.message;
|
1948 | return _this3.logger_("m3u8-parser info for " + url + ": " + message);
|
1949 | },
|
1950 | manifestString: manifestString,
|
1951 | customTagParsers: this.customTagParsers,
|
1952 | customTagMappers: this.customTagMappers,
|
1953 | experimentalLLHLS: this.experimentalLLHLS
|
1954 | });
|
1955 | }
|
1956 | |
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 | ;
|
1969 |
|
1970 | _proto.haveMetadata = function haveMetadata(_ref4) {
|
1971 | var playlistString = _ref4.playlistString,
|
1972 | playlistObject = _ref4.playlistObject,
|
1973 | url = _ref4.url,
|
1974 | id = _ref4.id;
|
1975 |
|
1976 | this.request = null;
|
1977 | this.state = 'HAVE_METADATA';
|
1978 | var playlist = playlistObject || this.parseManifest_({
|
1979 | url: url,
|
1980 | manifestString: playlistString
|
1981 | });
|
1982 | playlist.lastRequest = Date.now();
|
1983 | setupMediaPlaylist({
|
1984 | playlist: playlist,
|
1985 | uri: url,
|
1986 | id: id
|
1987 | });
|
1988 |
|
1989 | var update = updateMaster$1(this.master, playlist);
|
1990 | this.targetDuration = playlist.partTargetDuration || playlist.targetDuration;
|
1991 |
|
1992 | if (update) {
|
1993 | this.master = update;
|
1994 | this.media_ = this.master.playlists[id];
|
1995 | } else {
|
1996 | this.trigger('playlistunchanged');
|
1997 | }
|
1998 |
|
1999 | this.updateMediaUpdateTimeout_(refreshDelay(this.media(), !!update));
|
2000 | this.trigger('loadedplaylist');
|
2001 | }
|
2002 | |
2003 |
|
2004 |
|
2005 | ;
|
2006 |
|
2007 | _proto.dispose = function dispose() {
|
2008 | this.trigger('dispose');
|
2009 | this.stopRequest();
|
2010 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2011 | window__default["default"].clearTimeout(this.finalRenditionTimeout);
|
2012 | this.off();
|
2013 | };
|
2014 |
|
2015 | _proto.stopRequest = function stopRequest() {
|
2016 | if (this.request) {
|
2017 | var oldRequest = this.request;
|
2018 | this.request = null;
|
2019 | oldRequest.onreadystatechange = null;
|
2020 | oldRequest.abort();
|
2021 | }
|
2022 | }
|
2023 | |
2024 |
|
2025 |
|
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 |
|
2036 |
|
2037 | ;
|
2038 |
|
2039 | _proto.media = function media(playlist, shouldDelay) {
|
2040 | var _this4 = this;
|
2041 |
|
2042 |
|
2043 | if (!playlist) {
|
2044 | return this.media_;
|
2045 | }
|
2046 |
|
2047 |
|
2048 | if (this.state === 'HAVE_NOTHING') {
|
2049 | throw new Error('Cannot switch media playlist from ' + this.state);
|
2050 | }
|
2051 |
|
2052 |
|
2053 |
|
2054 | if (typeof playlist === 'string') {
|
2055 | if (!this.master.playlists[playlist]) {
|
2056 | throw new Error('Unknown playlist URI: ' + playlist);
|
2057 | }
|
2058 |
|
2059 | playlist = this.master.playlists[playlist];
|
2060 | }
|
2061 |
|
2062 | window__default["default"].clearTimeout(this.finalRenditionTimeout);
|
2063 |
|
2064 | if (shouldDelay) {
|
2065 | var delay = (playlist.partTargetDuration || playlist.targetDuration) / 2 * 1000 || 5 * 1000;
|
2066 | this.finalRenditionTimeout = window__default["default"].setTimeout(this.media.bind(this, playlist, false), delay);
|
2067 | return;
|
2068 | }
|
2069 |
|
2070 | var startingState = this.state;
|
2071 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
2072 | var masterPlaylistRef = this.master.playlists[playlist.id];
|
2073 |
|
2074 | if (masterPlaylistRef && masterPlaylistRef.endList ||
|
2075 |
|
2076 | playlist.endList && playlist.segments.length) {
|
2077 |
|
2078 | if (this.request) {
|
2079 | this.request.onreadystatechange = null;
|
2080 | this.request.abort();
|
2081 | this.request = null;
|
2082 | }
|
2083 |
|
2084 | this.state = 'HAVE_METADATA';
|
2085 | this.media_ = playlist;
|
2086 |
|
2087 | if (mediaChange) {
|
2088 | this.trigger('mediachanging');
|
2089 |
|
2090 | if (startingState === 'HAVE_MASTER') {
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 | this.trigger('loadedmetadata');
|
2097 | } else {
|
2098 | this.trigger('mediachange');
|
2099 | }
|
2100 | }
|
2101 |
|
2102 | return;
|
2103 | }
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 | this.updateMediaUpdateTimeout_(refreshDelay(playlist, true));
|
2111 |
|
2112 | if (!mediaChange) {
|
2113 | return;
|
2114 | }
|
2115 |
|
2116 | this.state = 'SWITCHING_MEDIA';
|
2117 |
|
2118 | if (this.request) {
|
2119 | if (playlist.resolvedUri === this.request.url) {
|
2120 |
|
2121 |
|
2122 | return;
|
2123 | }
|
2124 |
|
2125 | this.request.onreadystatechange = null;
|
2126 | this.request.abort();
|
2127 | this.request = null;
|
2128 | }
|
2129 |
|
2130 |
|
2131 | if (this.media_) {
|
2132 | this.trigger('mediachanging');
|
2133 | }
|
2134 |
|
2135 | this.request = this.vhs_.xhr({
|
2136 | uri: playlist.resolvedUri,
|
2137 | withCredentials: this.withCredentials
|
2138 | }, function (error, req) {
|
2139 |
|
2140 | if (!_this4.request) {
|
2141 | return;
|
2142 | }
|
2143 |
|
2144 | playlist.lastRequest = Date.now();
|
2145 | playlist.resolvedUri = resolveManifestRedirect(_this4.handleManifestRedirects, playlist.resolvedUri, req);
|
2146 |
|
2147 | if (error) {
|
2148 | return _this4.playlistRequestError(_this4.request, playlist, startingState);
|
2149 | }
|
2150 |
|
2151 | _this4.haveMetadata({
|
2152 | playlistString: req.responseText,
|
2153 | url: playlist.uri,
|
2154 | id: playlist.id
|
2155 | });
|
2156 |
|
2157 |
|
2158 | if (startingState === 'HAVE_MASTER') {
|
2159 | _this4.trigger('loadedmetadata');
|
2160 | } else {
|
2161 | _this4.trigger('mediachange');
|
2162 | }
|
2163 | });
|
2164 | }
|
2165 | |
2166 |
|
2167 |
|
2168 | ;
|
2169 |
|
2170 | _proto.pause = function pause() {
|
2171 | if (this.mediaUpdateTimeout) {
|
2172 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2173 | this.mediaUpdateTimeout = null;
|
2174 | }
|
2175 |
|
2176 | this.stopRequest();
|
2177 |
|
2178 | if (this.state === 'HAVE_NOTHING') {
|
2179 |
|
2180 |
|
2181 | this.started = false;
|
2182 | }
|
2183 |
|
2184 |
|
2185 | if (this.state === 'SWITCHING_MEDIA') {
|
2186 |
|
2187 |
|
2188 |
|
2189 | if (this.media_) {
|
2190 | this.state = 'HAVE_METADATA';
|
2191 | } else {
|
2192 | this.state = 'HAVE_MASTER';
|
2193 | }
|
2194 | } else if (this.state === 'HAVE_CURRENT_METADATA') {
|
2195 | this.state = 'HAVE_METADATA';
|
2196 | }
|
2197 | }
|
2198 | |
2199 |
|
2200 |
|
2201 | ;
|
2202 |
|
2203 | _proto.load = function load(shouldDelay) {
|
2204 | var _this5 = this;
|
2205 |
|
2206 | if (this.mediaUpdateTimeout) {
|
2207 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2208 | this.mediaUpdateTimeout = null;
|
2209 | }
|
2210 |
|
2211 | var media = this.media();
|
2212 |
|
2213 | if (shouldDelay) {
|
2214 | var delay = media ? (media.partTargetDuration || media.targetDuration) / 2 * 1000 : 5 * 1000;
|
2215 | this.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
2216 | _this5.mediaUpdateTimeout = null;
|
2217 |
|
2218 | _this5.load();
|
2219 | }, delay);
|
2220 | return;
|
2221 | }
|
2222 |
|
2223 | if (!this.started) {
|
2224 | this.start();
|
2225 | return;
|
2226 | }
|
2227 |
|
2228 | if (media && !media.endList) {
|
2229 | this.trigger('mediaupdatetimeout');
|
2230 | } else {
|
2231 | this.trigger('loadedplaylist');
|
2232 | }
|
2233 | };
|
2234 |
|
2235 | _proto.updateMediaUpdateTimeout_ = function updateMediaUpdateTimeout_(delay) {
|
2236 | var _this6 = this;
|
2237 |
|
2238 | if (this.mediaUpdateTimeout) {
|
2239 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
2240 | this.mediaUpdateTimeout = null;
|
2241 | }
|
2242 |
|
2243 |
|
2244 | if (!this.media() || this.media().endList) {
|
2245 | return;
|
2246 | }
|
2247 |
|
2248 | this.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
2249 | _this6.mediaUpdateTimeout = null;
|
2250 |
|
2251 | _this6.trigger('mediaupdatetimeout');
|
2252 |
|
2253 | _this6.updateMediaUpdateTimeout_(delay);
|
2254 | }, delay);
|
2255 | }
|
2256 | |
2257 |
|
2258 |
|
2259 | ;
|
2260 |
|
2261 | _proto.start = function start() {
|
2262 | var _this7 = this;
|
2263 |
|
2264 | this.started = true;
|
2265 |
|
2266 | if (typeof this.src === 'object') {
|
2267 |
|
2268 |
|
2269 | if (!this.src.uri) {
|
2270 | this.src.uri = window__default["default"].location.href;
|
2271 | }
|
2272 |
|
2273 |
|
2274 |
|
2275 | this.src.resolvedUri = this.src.uri;
|
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 |
|
2284 |
|
2285 | setTimeout(function () {
|
2286 | _this7.setupInitialPlaylist(_this7.src);
|
2287 | }, 0);
|
2288 | return;
|
2289 | }
|
2290 |
|
2291 |
|
2292 | this.request = this.vhs_.xhr({
|
2293 | uri: this.src,
|
2294 | withCredentials: this.withCredentials
|
2295 | }, function (error, req) {
|
2296 |
|
2297 | if (!_this7.request) {
|
2298 | return;
|
2299 | }
|
2300 |
|
2301 |
|
2302 | _this7.request = null;
|
2303 |
|
2304 | if (error) {
|
2305 | _this7.error = {
|
2306 | status: req.status,
|
2307 | message: "HLS playlist request error at URL: " + _this7.src + ".",
|
2308 | responseText: req.responseText,
|
2309 |
|
2310 | code: 2
|
2311 | };
|
2312 |
|
2313 | if (_this7.state === 'HAVE_NOTHING') {
|
2314 | _this7.started = false;
|
2315 | }
|
2316 |
|
2317 | return _this7.trigger('error');
|
2318 | }
|
2319 |
|
2320 | _this7.src = resolveManifestRedirect(_this7.handleManifestRedirects, _this7.src, req);
|
2321 |
|
2322 | var manifest = _this7.parseManifest_({
|
2323 | manifestString: req.responseText,
|
2324 | url: _this7.src
|
2325 | });
|
2326 |
|
2327 | _this7.setupInitialPlaylist(manifest);
|
2328 | });
|
2329 | };
|
2330 |
|
2331 | _proto.srcUri = function srcUri() {
|
2332 | return typeof this.src === 'string' ? this.src : this.src.uri;
|
2333 | }
|
2334 | |
2335 |
|
2336 |
|
2337 |
|
2338 |
|
2339 |
|
2340 |
|
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 | ;
|
2353 |
|
2354 | _proto.setupInitialPlaylist = function setupInitialPlaylist(manifest) {
|
2355 | this.state = 'HAVE_MASTER';
|
2356 |
|
2357 | if (manifest.playlists) {
|
2358 | this.master = manifest;
|
2359 | addPropertiesToMaster(this.master, this.srcUri());
|
2360 |
|
2361 |
|
2362 |
|
2363 | manifest.playlists.forEach(function (playlist) {
|
2364 | playlist.segments = getAllSegments(playlist);
|
2365 | playlist.segments.forEach(function (segment) {
|
2366 | resolveSegmentUris(segment, playlist.resolvedUri);
|
2367 | });
|
2368 | });
|
2369 | this.trigger('loadedplaylist');
|
2370 |
|
2371 | if (!this.request) {
|
2372 |
|
2373 |
|
2374 | this.media(this.master.playlists[0]);
|
2375 | }
|
2376 |
|
2377 | return;
|
2378 | }
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 | var uri = this.srcUri() || window__default["default"].location.href;
|
2384 | this.master = masterForMedia(manifest, uri);
|
2385 | this.haveMetadata({
|
2386 | playlistObject: manifest,
|
2387 | url: uri,
|
2388 | id: this.master.playlists[0].id
|
2389 | });
|
2390 | this.trigger('loadedmetadata');
|
2391 | };
|
2392 |
|
2393 | return PlaylistLoader;
|
2394 | }(EventTarget$1);
|
2395 |
|
2396 |
|
2397 |
|
2398 |
|
2399 | var videojsXHR = videojs__default["default"].xhr,
|
2400 | mergeOptions$1 = videojs__default["default"].mergeOptions;
|
2401 |
|
2402 | var callbackWrapper = function callbackWrapper(request, error, response, callback) {
|
2403 | var reqResponse = request.responseType === 'arraybuffer' ? request.response : request.responseText;
|
2404 |
|
2405 | if (!error && reqResponse) {
|
2406 | request.responseTime = Date.now();
|
2407 | request.roundTripTime = request.responseTime - request.requestTime;
|
2408 | request.bytesReceived = reqResponse.byteLength || reqResponse.length;
|
2409 |
|
2410 | if (!request.bandwidth) {
|
2411 | request.bandwidth = Math.floor(request.bytesReceived / request.roundTripTime * 8 * 1000);
|
2412 | }
|
2413 | }
|
2414 |
|
2415 | if (response.headers) {
|
2416 | request.responseHeaders = response.headers;
|
2417 | }
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 | if (error && error.code === 'ETIMEDOUT') {
|
2423 | request.timedout = true;
|
2424 | }
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 | if (!error && !request.aborted && response.statusCode !== 200 && response.statusCode !== 206 && response.statusCode !== 0) {
|
2430 | error = new Error('XHR Failed with a response of: ' + (request && (reqResponse || request.responseText)));
|
2431 | }
|
2432 |
|
2433 | callback(error, request);
|
2434 | };
|
2435 |
|
2436 | var xhrFactory = function xhrFactory() {
|
2437 | var xhr = function XhrFunction(options, callback) {
|
2438 |
|
2439 | options = mergeOptions$1({
|
2440 | timeout: 45e3
|
2441 | }, options);
|
2442 |
|
2443 |
|
2444 | var beforeRequest = XhrFunction.beforeRequest || videojs__default["default"].Vhs.xhr.beforeRequest;
|
2445 |
|
2446 | if (beforeRequest && typeof beforeRequest === 'function') {
|
2447 | var newOptions = beforeRequest(options);
|
2448 |
|
2449 | if (newOptions) {
|
2450 | options = newOptions;
|
2451 | }
|
2452 | }
|
2453 |
|
2454 |
|
2455 |
|
2456 | var xhrMethod = videojs__default["default"].Vhs.xhr.original === true ? videojsXHR : videojs__default["default"].Vhs.xhr;
|
2457 | var request = xhrMethod(options, function (error, response) {
|
2458 | return callbackWrapper(request, error, response, callback);
|
2459 | });
|
2460 | var originalAbort = request.abort;
|
2461 |
|
2462 | request.abort = function () {
|
2463 | request.aborted = true;
|
2464 | return originalAbort.apply(request, arguments);
|
2465 | };
|
2466 |
|
2467 | request.uri = options.uri;
|
2468 | request.requestTime = Date.now();
|
2469 | return request;
|
2470 | };
|
2471 |
|
2472 | xhr.original = true;
|
2473 | return xhr;
|
2474 | };
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 | var byterangeStr = function byterangeStr(byterange) {
|
2485 |
|
2486 |
|
2487 | var byterangeEnd = byterange.offset + byterange.length - 1;
|
2488 | var byterangeStart = byterange.offset;
|
2489 | return 'bytes=' + byterangeStart + '-' + byterangeEnd;
|
2490 | };
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 | var segmentXhrHeaders = function segmentXhrHeaders(segment) {
|
2500 | var headers = {};
|
2501 |
|
2502 | if (segment.byterange) {
|
2503 | headers.Range = byterangeStr(segment.byterange);
|
2504 | }
|
2505 |
|
2506 | return headers;
|
2507 | };
|
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 | var textRange = function textRange(range, i) {
|
2521 | return range.start(i) + '-' + range.end(i);
|
2522 | };
|
2523 |
|
2524 |
|
2525 |
|
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 | var formatHexString = function formatHexString(e, i) {
|
2533 | var value = e.toString(16);
|
2534 | return '00'.substring(0, 2 - value.length) + value + (i % 2 ? ' ' : '');
|
2535 | };
|
2536 |
|
2537 | var formatAsciiString = function formatAsciiString(e) {
|
2538 | if (e >= 0x20 && e < 0x7e) {
|
2539 | return String.fromCharCode(e);
|
2540 | }
|
2541 |
|
2542 | return '.';
|
2543 | };
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 | var createTransferableMessage = function createTransferableMessage(message) {
|
2557 | var transferable = {};
|
2558 | Object.keys(message).forEach(function (key) {
|
2559 | var value = message[key];
|
2560 |
|
2561 | if (ArrayBuffer.isView(value)) {
|
2562 | transferable[key] = {
|
2563 | bytes: value.buffer,
|
2564 | byteOffset: value.byteOffset,
|
2565 | byteLength: value.byteLength
|
2566 | };
|
2567 | } else {
|
2568 | transferable[key] = value;
|
2569 | }
|
2570 | });
|
2571 | return transferable;
|
2572 | };
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 |
|
2581 |
|
2582 |
|
2583 | var initSegmentId = function initSegmentId(initSegment) {
|
2584 | var byterange = initSegment.byterange || {
|
2585 | length: Infinity,
|
2586 | offset: 0
|
2587 | };
|
2588 | return [byterange.length, byterange.offset, initSegment.resolvedUri].join(',');
|
2589 | };
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 |
|
2597 | var segmentKeyId = function segmentKeyId(key) {
|
2598 | return key.resolvedUri;
|
2599 | };
|
2600 |
|
2601 |
|
2602 |
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 | var hexDump = function hexDump(data) {
|
2610 | var bytes = Array.prototype.slice.call(data);
|
2611 | var step = 16;
|
2612 | var result = '';
|
2613 | var hex;
|
2614 | var ascii;
|
2615 |
|
2616 | for (var j = 0; j < bytes.length / step; j++) {
|
2617 | hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
|
2618 | ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
|
2619 | result += hex + ' ' + ascii + '\n';
|
2620 | }
|
2621 |
|
2622 | return result;
|
2623 | };
|
2624 | var tagDump = function tagDump(_ref) {
|
2625 | var bytes = _ref.bytes;
|
2626 | return hexDump(bytes);
|
2627 | };
|
2628 | var textRanges = function textRanges(ranges) {
|
2629 | var result = '';
|
2630 | var i;
|
2631 |
|
2632 | for (i = 0; i < ranges.length; i++) {
|
2633 | result += textRange(ranges, i) + ' ';
|
2634 | }
|
2635 |
|
2636 | return result;
|
2637 | };
|
2638 |
|
2639 | var utils = Object.freeze({
|
2640 | __proto__: null,
|
2641 | createTransferableMessage: createTransferableMessage,
|
2642 | initSegmentId: initSegmentId,
|
2643 | segmentKeyId: segmentKeyId,
|
2644 | hexDump: hexDump,
|
2645 | tagDump: tagDump,
|
2646 | textRanges: textRanges
|
2647 | });
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 | var SEGMENT_END_FUDGE_PERCENT = 0.25;
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 | var playerTimeToProgramTime = function playerTimeToProgramTime(playerTime, segment) {
|
2670 | if (!segment.dateTimeObject) {
|
2671 |
|
2672 |
|
2673 | return null;
|
2674 | }
|
2675 |
|
2676 | var transmuxerPrependedSeconds = segment.videoTimingInfo.transmuxerPrependedSeconds;
|
2677 | var transmuxedStart = segment.videoTimingInfo.transmuxedPresentationStart;
|
2678 |
|
2679 | var startOfSegment = transmuxedStart + transmuxerPrependedSeconds;
|
2680 | var offsetFromSegmentStart = playerTime - startOfSegment;
|
2681 | return new Date(segment.dateTimeObject.getTime() + offsetFromSegmentStart * 1000);
|
2682 | };
|
2683 | var originalSegmentVideoDuration = function originalSegmentVideoDuration(videoTimingInfo) {
|
2684 | return videoTimingInfo.transmuxedPresentationEnd - videoTimingInfo.transmuxedPresentationStart - videoTimingInfo.transmuxerPrependedSeconds;
|
2685 | };
|
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 | var findSegmentForProgramTime = function findSegmentForProgramTime(programTime, playlist) {
|
2695 |
|
2696 |
|
2697 |
|
2698 | var dateTimeObject;
|
2699 |
|
2700 | try {
|
2701 | dateTimeObject = new Date(programTime);
|
2702 | } catch (e) {
|
2703 | return null;
|
2704 | }
|
2705 |
|
2706 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
2707 | return null;
|
2708 | }
|
2709 |
|
2710 | var segment = playlist.segments[0];
|
2711 |
|
2712 | if (dateTimeObject < segment.dateTimeObject) {
|
2713 |
|
2714 | return null;
|
2715 | }
|
2716 |
|
2717 | for (var i = 0; i < playlist.segments.length - 1; i++) {
|
2718 | segment = playlist.segments[i];
|
2719 | var nextSegmentStart = playlist.segments[i + 1].dateTimeObject;
|
2720 |
|
2721 | if (dateTimeObject < nextSegmentStart) {
|
2722 | break;
|
2723 | }
|
2724 | }
|
2725 |
|
2726 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
2727 | var lastSegmentStart = lastSegment.dateTimeObject;
|
2728 | var lastSegmentDuration = lastSegment.videoTimingInfo ? originalSegmentVideoDuration(lastSegment.videoTimingInfo) : lastSegment.duration + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT;
|
2729 | var lastSegmentEnd = new Date(lastSegmentStart.getTime() + lastSegmentDuration * 1000);
|
2730 |
|
2731 | if (dateTimeObject > lastSegmentEnd) {
|
2732 |
|
2733 | return null;
|
2734 | }
|
2735 |
|
2736 | if (dateTimeObject > lastSegmentStart) {
|
2737 | segment = lastSegment;
|
2738 | }
|
2739 |
|
2740 | return {
|
2741 | segment: segment,
|
2742 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : Playlist.duration(playlist, playlist.mediaSequence + playlist.segments.indexOf(segment)),
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
2748 | };
|
2749 | };
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 |
|
2757 | var findSegmentForPlayerTime = function findSegmentForPlayerTime(time, playlist) {
|
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
2763 | return null;
|
2764 | }
|
2765 |
|
2766 | var segmentEnd = 0;
|
2767 | var segment;
|
2768 |
|
2769 | for (var i = 0; i < playlist.segments.length; i++) {
|
2770 | segment = playlist.segments[i];
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 | segmentEnd = segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationEnd : segmentEnd + segment.duration;
|
2778 |
|
2779 | if (time <= segmentEnd) {
|
2780 | break;
|
2781 | }
|
2782 | }
|
2783 |
|
2784 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
2785 |
|
2786 | if (lastSegment.videoTimingInfo && lastSegment.videoTimingInfo.transmuxedPresentationEnd < time) {
|
2787 |
|
2788 | return null;
|
2789 | }
|
2790 |
|
2791 | if (time > segmentEnd) {
|
2792 |
|
2793 |
|
2794 |
|
2795 | if (time > segmentEnd + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT) {
|
2796 |
|
2797 |
|
2798 |
|
2799 | return null;
|
2800 | }
|
2801 |
|
2802 | segment = lastSegment;
|
2803 | }
|
2804 |
|
2805 | return {
|
2806 | segment: segment,
|
2807 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : segmentEnd - segment.duration,
|
2808 |
|
2809 |
|
2810 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
2811 | };
|
2812 | };
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 | var getOffsetFromTimestamp = function getOffsetFromTimestamp(comparisonTimeStamp, programTime) {
|
2825 | var segmentDateTime;
|
2826 | var programDateTime;
|
2827 |
|
2828 | try {
|
2829 | segmentDateTime = new Date(comparisonTimeStamp);
|
2830 | programDateTime = new Date(programTime);
|
2831 | } catch (e) {
|
2832 | }
|
2833 |
|
2834 | var segmentTimeEpoch = segmentDateTime.getTime();
|
2835 | var programTimeEpoch = programDateTime.getTime();
|
2836 | return (programTimeEpoch - segmentTimeEpoch) / 1000;
|
2837 | };
|
2838 |
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 | var verifyProgramDateTimeTags = function verifyProgramDateTimeTags(playlist) {
|
2845 | if (!playlist.segments || playlist.segments.length === 0) {
|
2846 | return false;
|
2847 | }
|
2848 |
|
2849 | for (var i = 0; i < playlist.segments.length; i++) {
|
2850 | var segment = playlist.segments[i];
|
2851 |
|
2852 | if (!segment.dateTimeObject) {
|
2853 | return false;
|
2854 | }
|
2855 | }
|
2856 |
|
2857 | return true;
|
2858 | };
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 | var getProgramTime = function getProgramTime(_ref) {
|
2876 | var playlist = _ref.playlist,
|
2877 | _ref$time = _ref.time,
|
2878 | time = _ref$time === void 0 ? undefined : _ref$time,
|
2879 | callback = _ref.callback;
|
2880 |
|
2881 | if (!callback) {
|
2882 | throw new Error('getProgramTime: callback must be provided');
|
2883 | }
|
2884 |
|
2885 | if (!playlist || time === undefined) {
|
2886 | return callback({
|
2887 | message: 'getProgramTime: playlist and time must be provided'
|
2888 | });
|
2889 | }
|
2890 |
|
2891 | var matchedSegment = findSegmentForPlayerTime(time, playlist);
|
2892 |
|
2893 | if (!matchedSegment) {
|
2894 | return callback({
|
2895 | message: 'valid programTime was not found'
|
2896 | });
|
2897 | }
|
2898 |
|
2899 | if (matchedSegment.type === 'estimate') {
|
2900 | return callback({
|
2901 | message: 'Accurate programTime could not be determined.' + ' Please seek to e.seekTime and try again',
|
2902 | seekTime: matchedSegment.estimatedStart
|
2903 | });
|
2904 | }
|
2905 |
|
2906 | var programTimeObject = {
|
2907 | mediaSeconds: time
|
2908 | };
|
2909 | var programTime = playerTimeToProgramTime(time, matchedSegment.segment);
|
2910 |
|
2911 | if (programTime) {
|
2912 | programTimeObject.programDateTime = programTime.toISOString();
|
2913 | }
|
2914 |
|
2915 | return callback(null, programTimeObject);
|
2916 | };
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 |
|
2932 | var seekToProgramTime = function seekToProgramTime(_ref2) {
|
2933 | var programTime = _ref2.programTime,
|
2934 | playlist = _ref2.playlist,
|
2935 | _ref2$retryCount = _ref2.retryCount,
|
2936 | retryCount = _ref2$retryCount === void 0 ? 2 : _ref2$retryCount,
|
2937 | seekTo = _ref2.seekTo,
|
2938 | _ref2$pauseAfterSeek = _ref2.pauseAfterSeek,
|
2939 | pauseAfterSeek = _ref2$pauseAfterSeek === void 0 ? true : _ref2$pauseAfterSeek,
|
2940 | tech = _ref2.tech,
|
2941 | callback = _ref2.callback;
|
2942 |
|
2943 | if (!callback) {
|
2944 | throw new Error('seekToProgramTime: callback must be provided');
|
2945 | }
|
2946 |
|
2947 | if (typeof programTime === 'undefined' || !playlist || !seekTo) {
|
2948 | return callback({
|
2949 | message: 'seekToProgramTime: programTime, seekTo and playlist must be provided'
|
2950 | });
|
2951 | }
|
2952 |
|
2953 | if (!playlist.endList && !tech.hasStarted_) {
|
2954 | return callback({
|
2955 | message: 'player must be playing a live stream to start buffering'
|
2956 | });
|
2957 | }
|
2958 |
|
2959 | if (!verifyProgramDateTimeTags(playlist)) {
|
2960 | return callback({
|
2961 | message: 'programDateTime tags must be provided in the manifest ' + playlist.resolvedUri
|
2962 | });
|
2963 | }
|
2964 |
|
2965 | var matchedSegment = findSegmentForProgramTime(programTime, playlist);
|
2966 |
|
2967 | if (!matchedSegment) {
|
2968 | return callback({
|
2969 | message: programTime + " was not found in the stream"
|
2970 | });
|
2971 | }
|
2972 |
|
2973 | var segment = matchedSegment.segment;
|
2974 | var mediaOffset = getOffsetFromTimestamp(segment.dateTimeObject, programTime);
|
2975 |
|
2976 | if (matchedSegment.type === 'estimate') {
|
2977 |
|
2978 | if (retryCount === 0) {
|
2979 | return callback({
|
2980 | message: programTime + " is not buffered yet. Try again"
|
2981 | });
|
2982 | }
|
2983 |
|
2984 | seekTo(matchedSegment.estimatedStart + mediaOffset);
|
2985 | tech.one('seeked', function () {
|
2986 | seekToProgramTime({
|
2987 | programTime: programTime,
|
2988 | playlist: playlist,
|
2989 | retryCount: retryCount - 1,
|
2990 | seekTo: seekTo,
|
2991 | pauseAfterSeek: pauseAfterSeek,
|
2992 | tech: tech,
|
2993 | callback: callback
|
2994 | });
|
2995 | });
|
2996 | return;
|
2997 | }
|
2998 |
|
2999 |
|
3000 |
|
3001 |
|
3002 | var seekToTime = segment.start + mediaOffset;
|
3003 |
|
3004 | var seekedCallback = function seekedCallback() {
|
3005 | return callback(null, tech.currentTime());
|
3006 | };
|
3007 |
|
3008 |
|
3009 | tech.one('seeked', seekedCallback);
|
3010 |
|
3011 | if (pauseAfterSeek) {
|
3012 | tech.pause();
|
3013 | }
|
3014 |
|
3015 | seekTo(seekToTime);
|
3016 | };
|
3017 |
|
3018 |
|
3019 |
|
3020 | var callbackOnCompleted = function callbackOnCompleted(request, cb) {
|
3021 | if (request.readyState === 4) {
|
3022 | return cb();
|
3023 | }
|
3024 |
|
3025 | return;
|
3026 | };
|
3027 |
|
3028 | var containerRequest = function containerRequest(uri, xhr, cb) {
|
3029 | var bytes = [];
|
3030 | var id3Offset;
|
3031 | var finished = false;
|
3032 |
|
3033 | var endRequestAndCallback = function endRequestAndCallback(err, req, type, _bytes) {
|
3034 | req.abort();
|
3035 | finished = true;
|
3036 | return cb(err, req, type, _bytes);
|
3037 | };
|
3038 |
|
3039 | var progressListener = function progressListener(error, request) {
|
3040 | if (finished) {
|
3041 | return;
|
3042 | }
|
3043 |
|
3044 | if (error) {
|
3045 | return endRequestAndCallback(error, request, '', bytes);
|
3046 | }
|
3047 |
|
3048 |
|
3049 | var newPart = request.responseText.substring(bytes && bytes.byteLength || 0, request.responseText.length);
|
3050 |
|
3051 | bytes = byteHelpers.concatTypedArrays(bytes, byteHelpers.stringToBytes(newPart, true));
|
3052 | id3Offset = id3Offset || id3Helpers.getId3Offset(bytes);
|
3053 |
|
3054 |
|
3055 | if (bytes.length < 10 || id3Offset && bytes.length < id3Offset + 2) {
|
3056 | return callbackOnCompleted(request, function () {
|
3057 | return endRequestAndCallback(error, request, '', bytes);
|
3058 | });
|
3059 | }
|
3060 |
|
3061 | var type = containers.detectContainerForBytes(bytes);
|
3062 |
|
3063 |
|
3064 |
|
3065 | if (type === 'ts' && bytes.length < 188) {
|
3066 | return callbackOnCompleted(request, function () {
|
3067 | return endRequestAndCallback(error, request, '', bytes);
|
3068 | });
|
3069 | }
|
3070 |
|
3071 |
|
3072 |
|
3073 | if (!type && bytes.length < 376) {
|
3074 | return callbackOnCompleted(request, function () {
|
3075 | return endRequestAndCallback(error, request, '', bytes);
|
3076 | });
|
3077 | }
|
3078 |
|
3079 | return endRequestAndCallback(null, request, type, bytes);
|
3080 | };
|
3081 |
|
3082 | var options = {
|
3083 | uri: uri,
|
3084 | beforeSend: function beforeSend(request) {
|
3085 |
|
3086 | request.overrideMimeType('text/plain; charset=x-user-defined');
|
3087 | request.addEventListener('progress', function (_ref) {
|
3088 | _ref.total;
|
3089 | _ref.loaded;
|
3090 | return callbackWrapper(request, null, {
|
3091 | statusCode: request.status
|
3092 | }, progressListener);
|
3093 | });
|
3094 | }
|
3095 | };
|
3096 | var request = xhr(options, function (error, response) {
|
3097 | return callbackWrapper(request, error, response, progressListener);
|
3098 | });
|
3099 | return request;
|
3100 | };
|
3101 |
|
3102 | var EventTarget = videojs__default["default"].EventTarget,
|
3103 | mergeOptions = videojs__default["default"].mergeOptions;
|
3104 |
|
3105 | var dashPlaylistUnchanged = function dashPlaylistUnchanged(a, b) {
|
3106 | if (!isPlaylistUnchanged(a, b)) {
|
3107 | return false;
|
3108 | }
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 |
|
3116 | if (a.sidx && b.sidx && (a.sidx.offset !== b.sidx.offset || a.sidx.length !== b.sidx.length)) {
|
3117 | return false;
|
3118 | } else if (!a.sidx && b.sidx || a.sidx && !b.sidx) {
|
3119 | return false;
|
3120 | }
|
3121 |
|
3122 |
|
3123 |
|
3124 | if (a.segments && !b.segments || !a.segments && b.segments) {
|
3125 | return false;
|
3126 | }
|
3127 |
|
3128 |
|
3129 | if (!a.segments && !b.segments) {
|
3130 | return true;
|
3131 | }
|
3132 |
|
3133 |
|
3134 | for (var i = 0; i < a.segments.length; i++) {
|
3135 | var aSegment = a.segments[i];
|
3136 | var bSegment = b.segments[i];
|
3137 |
|
3138 | if (aSegment.uri !== bSegment.uri) {
|
3139 | return false;
|
3140 | }
|
3141 |
|
3142 |
|
3143 | if (!aSegment.byterange && !bSegment.byterange) {
|
3144 | continue;
|
3145 | }
|
3146 |
|
3147 | var aByterange = aSegment.byterange;
|
3148 | var bByterange = bSegment.byterange;
|
3149 |
|
3150 | if (aByterange && !bByterange || !aByterange && bByterange) {
|
3151 | return false;
|
3152 | }
|
3153 |
|
3154 |
|
3155 | if (aByterange.offset !== bByterange.offset || aByterange.length !== bByterange.length) {
|
3156 | return false;
|
3157 | }
|
3158 | }
|
3159 |
|
3160 |
|
3161 | return true;
|
3162 | };
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 | var parseMasterXml = function parseMasterXml(_ref) {
|
3182 | var masterXml = _ref.masterXml,
|
3183 | srcUrl = _ref.srcUrl,
|
3184 | clientOffset = _ref.clientOffset,
|
3185 | sidxMapping = _ref.sidxMapping;
|
3186 | var master = mpdParser.parse(masterXml, {
|
3187 | manifestUri: srcUrl,
|
3188 | clientOffset: clientOffset,
|
3189 | sidxMapping: sidxMapping
|
3190 | });
|
3191 | addPropertiesToMaster(master, srcUrl);
|
3192 | return master;
|
3193 | };
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 | var updateMaster = function updateMaster(oldMaster, newMaster, sidxMapping) {
|
3208 | var noChanges = true;
|
3209 | var update = mergeOptions(oldMaster, {
|
3210 |
|
3211 | duration: newMaster.duration,
|
3212 | minimumUpdatePeriod: newMaster.minimumUpdatePeriod
|
3213 | });
|
3214 |
|
3215 | for (var i = 0; i < newMaster.playlists.length; i++) {
|
3216 | var playlist = newMaster.playlists[i];
|
3217 |
|
3218 | if (playlist.sidx) {
|
3219 | var sidxKey = mpdParser.generateSidxKey(playlist.sidx);
|
3220 |
|
3221 | if (sidxMapping && sidxMapping[sidxKey] && sidxMapping[sidxKey].sidx) {
|
3222 | mpdParser.addSidxSegmentsToPlaylist(playlist, sidxMapping[sidxKey].sidx, playlist.sidx.resolvedUri);
|
3223 | }
|
3224 | }
|
3225 |
|
3226 | var playlistUpdate = updateMaster$1(update, playlist, dashPlaylistUnchanged);
|
3227 |
|
3228 | if (playlistUpdate) {
|
3229 | update = playlistUpdate;
|
3230 | noChanges = false;
|
3231 | }
|
3232 | }
|
3233 |
|
3234 |
|
3235 | forEachMediaGroup(newMaster, function (properties, type, group, label) {
|
3236 | if (properties.playlists && properties.playlists.length) {
|
3237 | var id = properties.playlists[0].id;
|
3238 |
|
3239 | var _playlistUpdate = updateMaster$1(update, properties.playlists[0], dashPlaylistUnchanged);
|
3240 |
|
3241 | if (_playlistUpdate) {
|
3242 | update = _playlistUpdate;
|
3243 |
|
3244 | update.mediaGroups[type][group][label].playlists[0] = update.playlists[id];
|
3245 | noChanges = false;
|
3246 | }
|
3247 | }
|
3248 | });
|
3249 |
|
3250 | if (newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
3251 | noChanges = false;
|
3252 | }
|
3253 |
|
3254 | if (noChanges) {
|
3255 | return null;
|
3256 | }
|
3257 |
|
3258 | return update;
|
3259 | };
|
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 | var equivalentSidx = function equivalentSidx(a, b) {
|
3265 | var neitherMap = Boolean(!a.map && !b.map);
|
3266 | var equivalentMap = neitherMap || Boolean(a.map && b.map && a.map.byterange.offset === b.map.byterange.offset && a.map.byterange.length === b.map.byterange.length);
|
3267 | return equivalentMap && a.uri === b.uri && a.byterange.offset === b.byterange.offset && a.byterange.length === b.byterange.length;
|
3268 | };
|
3269 |
|
3270 |
|
3271 | var compareSidxEntry = function compareSidxEntry(playlists, oldSidxMapping) {
|
3272 | var newSidxMapping = {};
|
3273 |
|
3274 | for (var id in playlists) {
|
3275 | var playlist = playlists[id];
|
3276 | var currentSidxInfo = playlist.sidx;
|
3277 |
|
3278 | if (currentSidxInfo) {
|
3279 | var key = mpdParser.generateSidxKey(currentSidxInfo);
|
3280 |
|
3281 | if (!oldSidxMapping[key]) {
|
3282 | break;
|
3283 | }
|
3284 |
|
3285 | var savedSidxInfo = oldSidxMapping[key].sidxInfo;
|
3286 |
|
3287 | if (equivalentSidx(savedSidxInfo, currentSidxInfo)) {
|
3288 | newSidxMapping[key] = oldSidxMapping[key];
|
3289 | }
|
3290 | }
|
3291 | }
|
3292 |
|
3293 | return newSidxMapping;
|
3294 | };
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 | var filterChangedSidxMappings = function filterChangedSidxMappings(master, oldSidxMapping) {
|
3305 | var videoSidx = compareSidxEntry(master.playlists, oldSidxMapping);
|
3306 | var mediaGroupSidx = videoSidx;
|
3307 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
3308 | if (properties.playlists && properties.playlists.length) {
|
3309 | var playlists = properties.playlists;
|
3310 | mediaGroupSidx = mergeOptions(mediaGroupSidx, compareSidxEntry(playlists, oldSidxMapping));
|
3311 | }
|
3312 | });
|
3313 | return mediaGroupSidx;
|
3314 | };
|
3315 |
|
3316 | var DashPlaylistLoader = function (_EventTarget) {
|
3317 | _inheritsLoose__default["default"](DashPlaylistLoader, _EventTarget);
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 | function DashPlaylistLoader(srcUrlOrPlaylist, vhs, options, masterPlaylistLoader) {
|
3323 | var _this;
|
3324 |
|
3325 | if (options === void 0) {
|
3326 | options = {};
|
3327 | }
|
3328 |
|
3329 | _this = _EventTarget.call(this) || this;
|
3330 | _this.masterPlaylistLoader_ = masterPlaylistLoader || _assertThisInitialized__default["default"](_this);
|
3331 |
|
3332 | if (!masterPlaylistLoader) {
|
3333 | _this.isMaster_ = true;
|
3334 | }
|
3335 |
|
3336 | var _options = options,
|
3337 | _options$withCredenti = _options.withCredentials,
|
3338 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
3339 | _options$handleManife = _options.handleManifestRedirects,
|
3340 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
3341 | _this.vhs_ = vhs;
|
3342 | _this.withCredentials = withCredentials;
|
3343 | _this.handleManifestRedirects = handleManifestRedirects;
|
3344 |
|
3345 | if (!srcUrlOrPlaylist) {
|
3346 | throw new Error('A non-empty playlist URL or object is required');
|
3347 | }
|
3348 |
|
3349 |
|
3350 | _this.on('minimumUpdatePeriod', function () {
|
3351 | _this.refreshXml_();
|
3352 | });
|
3353 |
|
3354 |
|
3355 | _this.on('mediaupdatetimeout', function () {
|
3356 | _this.refreshMedia_(_this.media().id);
|
3357 | });
|
3358 |
|
3359 | _this.state = 'HAVE_NOTHING';
|
3360 | _this.loadedPlaylists_ = {};
|
3361 | _this.logger_ = logger('DashPlaylistLoader');
|
3362 |
|
3363 |
|
3364 | if (_this.isMaster_) {
|
3365 | _this.masterPlaylistLoader_.srcUrl = srcUrlOrPlaylist;
|
3366 |
|
3367 |
|
3368 | _this.masterPlaylistLoader_.sidxMapping_ = {};
|
3369 | } else {
|
3370 | _this.childPlaylist_ = srcUrlOrPlaylist;
|
3371 | }
|
3372 |
|
3373 | return _this;
|
3374 | }
|
3375 |
|
3376 | var _proto = DashPlaylistLoader.prototype;
|
3377 |
|
3378 | _proto.requestErrored_ = function requestErrored_(err, request, startingState) {
|
3379 |
|
3380 | if (!this.request) {
|
3381 | return true;
|
3382 | }
|
3383 |
|
3384 |
|
3385 | this.request = null;
|
3386 |
|
3387 | if (err) {
|
3388 |
|
3389 |
|
3390 | this.error = typeof err === 'object' && !(err instanceof Error) ? err : {
|
3391 | status: request.status,
|
3392 | message: 'DASH request error at URL: ' + request.uri,
|
3393 | response: request.response,
|
3394 |
|
3395 | code: 2
|
3396 | };
|
3397 |
|
3398 | if (startingState) {
|
3399 | this.state = startingState;
|
3400 | }
|
3401 |
|
3402 | this.trigger('error');
|
3403 | return true;
|
3404 | }
|
3405 | }
|
3406 | |
3407 |
|
3408 |
|
3409 |
|
3410 | ;
|
3411 |
|
3412 | _proto.addSidxSegments_ = function addSidxSegments_(playlist, startingState, cb) {
|
3413 | var _this2 = this;
|
3414 |
|
3415 | var sidxKey = playlist.sidx && mpdParser.generateSidxKey(playlist.sidx);
|
3416 |
|
3417 | if (!playlist.sidx || !sidxKey || this.masterPlaylistLoader_.sidxMapping_[sidxKey]) {
|
3418 |
|
3419 | this.mediaRequest_ = window__default["default"].setTimeout(function () {
|
3420 | return cb(false);
|
3421 | }, 0);
|
3422 | return;
|
3423 | }
|
3424 |
|
3425 |
|
3426 | var uri = resolveManifestRedirect(this.handleManifestRedirects, playlist.sidx.resolvedUri);
|
3427 |
|
3428 | var fin = function fin(err, request) {
|
3429 | if (_this2.requestErrored_(err, request, startingState)) {
|
3430 | return;
|
3431 | }
|
3432 |
|
3433 | var sidxMapping = _this2.masterPlaylistLoader_.sidxMapping_;
|
3434 | var sidx;
|
3435 |
|
3436 | try {
|
3437 | sidx = parseSidx__default["default"](byteHelpers.toUint8(request.response).subarray(8));
|
3438 | } catch (e) {
|
3439 |
|
3440 | _this2.requestErrored_(e, request, startingState);
|
3441 |
|
3442 | return;
|
3443 | }
|
3444 |
|
3445 | sidxMapping[sidxKey] = {
|
3446 | sidxInfo: playlist.sidx,
|
3447 | sidx: sidx
|
3448 | };
|
3449 | mpdParser.addSidxSegmentsToPlaylist(playlist, sidx, playlist.sidx.resolvedUri);
|
3450 | return cb(true);
|
3451 | };
|
3452 |
|
3453 | this.request = containerRequest(uri, this.vhs_.xhr, function (err, request, container, bytes) {
|
3454 | if (err) {
|
3455 | return fin(err, request);
|
3456 | }
|
3457 |
|
3458 | if (!container || container !== 'mp4') {
|
3459 | return fin({
|
3460 | status: request.status,
|
3461 | message: "Unsupported " + (container || 'unknown') + " container type for sidx segment at URL: " + uri,
|
3462 |
|
3463 |
|
3464 | response: '',
|
3465 | playlist: playlist,
|
3466 | internal: true,
|
3467 | blacklistDuration: Infinity,
|
3468 |
|
3469 | code: 2
|
3470 | }, request);
|
3471 | }
|
3472 |
|
3473 |
|
3474 | var _playlist$sidx$bytera = playlist.sidx.byterange,
|
3475 | offset = _playlist$sidx$bytera.offset,
|
3476 | length = _playlist$sidx$bytera.length;
|
3477 |
|
3478 | if (bytes.length >= length + offset) {
|
3479 | return fin(err, {
|
3480 | response: bytes.subarray(offset, offset + length),
|
3481 | status: request.status,
|
3482 | uri: request.uri
|
3483 | });
|
3484 | }
|
3485 |
|
3486 |
|
3487 | _this2.request = _this2.vhs_.xhr({
|
3488 | uri: uri,
|
3489 | responseType: 'arraybuffer',
|
3490 | headers: segmentXhrHeaders({
|
3491 | byterange: playlist.sidx.byterange
|
3492 | })
|
3493 | }, fin);
|
3494 | });
|
3495 | };
|
3496 |
|
3497 | _proto.dispose = function dispose() {
|
3498 | this.trigger('dispose');
|
3499 | this.stopRequest();
|
3500 | this.loadedPlaylists_ = {};
|
3501 | window__default["default"].clearTimeout(this.minimumUpdatePeriodTimeout_);
|
3502 | window__default["default"].clearTimeout(this.mediaRequest_);
|
3503 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
3504 | this.mediaUpdateTimeout = null;
|
3505 | this.mediaRequest_ = null;
|
3506 | this.minimumUpdatePeriodTimeout_ = null;
|
3507 |
|
3508 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
3509 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
3510 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
3511 | }
|
3512 |
|
3513 | this.off();
|
3514 | };
|
3515 |
|
3516 | _proto.hasPendingRequest = function hasPendingRequest() {
|
3517 | return this.request || this.mediaRequest_;
|
3518 | };
|
3519 |
|
3520 | _proto.stopRequest = function stopRequest() {
|
3521 | if (this.request) {
|
3522 | var oldRequest = this.request;
|
3523 | this.request = null;
|
3524 | oldRequest.onreadystatechange = null;
|
3525 | oldRequest.abort();
|
3526 | }
|
3527 | };
|
3528 |
|
3529 | _proto.media = function media(playlist) {
|
3530 | var _this3 = this;
|
3531 |
|
3532 |
|
3533 | if (!playlist) {
|
3534 | return this.media_;
|
3535 | }
|
3536 |
|
3537 |
|
3538 | if (this.state === 'HAVE_NOTHING') {
|
3539 | throw new Error('Cannot switch media playlist from ' + this.state);
|
3540 | }
|
3541 |
|
3542 | var startingState = this.state;
|
3543 |
|
3544 | if (typeof playlist === 'string') {
|
3545 | if (!this.masterPlaylistLoader_.master.playlists[playlist]) {
|
3546 | throw new Error('Unknown playlist URI: ' + playlist);
|
3547 | }
|
3548 |
|
3549 | playlist = this.masterPlaylistLoader_.master.playlists[playlist];
|
3550 | }
|
3551 |
|
3552 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
3553 |
|
3554 | if (mediaChange && this.loadedPlaylists_[playlist.id] && this.loadedPlaylists_[playlist.id].endList) {
|
3555 | this.state = 'HAVE_METADATA';
|
3556 | this.media_ = playlist;
|
3557 |
|
3558 | if (mediaChange) {
|
3559 | this.trigger('mediachanging');
|
3560 | this.trigger('mediachange');
|
3561 | }
|
3562 |
|
3563 | return;
|
3564 | }
|
3565 |
|
3566 |
|
3567 | if (!mediaChange) {
|
3568 | return;
|
3569 | }
|
3570 |
|
3571 |
|
3572 | if (this.media_) {
|
3573 | this.trigger('mediachanging');
|
3574 | }
|
3575 |
|
3576 | this.addSidxSegments_(playlist, startingState, function (sidxChanged) {
|
3577 |
|
3578 | _this3.haveMetadata({
|
3579 | startingState: startingState,
|
3580 | playlist: playlist
|
3581 | });
|
3582 | });
|
3583 | };
|
3584 |
|
3585 | _proto.haveMetadata = function haveMetadata(_ref2) {
|
3586 | var startingState = _ref2.startingState,
|
3587 | playlist = _ref2.playlist;
|
3588 | this.state = 'HAVE_METADATA';
|
3589 | this.loadedPlaylists_[playlist.id] = playlist;
|
3590 | this.mediaRequest_ = null;
|
3591 |
|
3592 | this.refreshMedia_(playlist.id);
|
3593 |
|
3594 |
|
3595 | if (startingState === 'HAVE_MASTER') {
|
3596 | this.trigger('loadedmetadata');
|
3597 | } else {
|
3598 |
|
3599 | this.trigger('mediachange');
|
3600 | }
|
3601 | };
|
3602 |
|
3603 | _proto.pause = function pause() {
|
3604 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
3605 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
3606 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
3607 | }
|
3608 |
|
3609 | this.stopRequest();
|
3610 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
3611 | this.mediaUpdateTimeout = null;
|
3612 |
|
3613 | if (this.isMaster_) {
|
3614 | window__default["default"].clearTimeout(this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_);
|
3615 | this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_ = null;
|
3616 | }
|
3617 |
|
3618 | if (this.state === 'HAVE_NOTHING') {
|
3619 |
|
3620 |
|
3621 | this.started = false;
|
3622 | }
|
3623 | };
|
3624 |
|
3625 | _proto.load = function load(isFinalRendition) {
|
3626 | var _this4 = this;
|
3627 |
|
3628 | window__default["default"].clearTimeout(this.mediaUpdateTimeout);
|
3629 | this.mediaUpdateTimeout = null;
|
3630 | var media = this.media();
|
3631 |
|
3632 | if (isFinalRendition) {
|
3633 | var delay = media ? media.targetDuration / 2 * 1000 : 5 * 1000;
|
3634 | this.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
3635 | return _this4.load();
|
3636 | }, delay);
|
3637 | return;
|
3638 | }
|
3639 |
|
3640 |
|
3641 |
|
3642 | if (!this.started) {
|
3643 | this.start();
|
3644 | return;
|
3645 | }
|
3646 |
|
3647 | if (media && !media.endList) {
|
3648 |
|
3649 |
|
3650 |
|
3651 | if (this.isMaster_ && !this.minimumUpdatePeriodTimeout_) {
|
3652 |
|
3653 | this.trigger('minimumUpdatePeriod');
|
3654 |
|
3655 | this.updateMinimumUpdatePeriodTimeout_();
|
3656 | }
|
3657 |
|
3658 | this.trigger('mediaupdatetimeout');
|
3659 | } else {
|
3660 | this.trigger('loadedplaylist');
|
3661 | }
|
3662 | };
|
3663 |
|
3664 | _proto.start = function start() {
|
3665 | var _this5 = this;
|
3666 |
|
3667 | this.started = true;
|
3668 |
|
3669 |
|
3670 | if (!this.isMaster_) {
|
3671 | this.mediaRequest_ = window__default["default"].setTimeout(function () {
|
3672 | return _this5.haveMaster_();
|
3673 | }, 0);
|
3674 | return;
|
3675 | }
|
3676 |
|
3677 | this.requestMaster_(function (req, masterChanged) {
|
3678 | _this5.haveMaster_();
|
3679 |
|
3680 | if (!_this5.hasPendingRequest() && !_this5.media_) {
|
3681 | _this5.media(_this5.masterPlaylistLoader_.master.playlists[0]);
|
3682 | }
|
3683 | });
|
3684 | };
|
3685 |
|
3686 | _proto.requestMaster_ = function requestMaster_(cb) {
|
3687 | var _this6 = this;
|
3688 |
|
3689 | this.request = this.vhs_.xhr({
|
3690 | uri: this.masterPlaylistLoader_.srcUrl,
|
3691 | withCredentials: this.withCredentials
|
3692 | }, function (error, req) {
|
3693 | if (_this6.requestErrored_(error, req)) {
|
3694 | if (_this6.state === 'HAVE_NOTHING') {
|
3695 | _this6.started = false;
|
3696 | }
|
3697 |
|
3698 | return;
|
3699 | }
|
3700 |
|
3701 | var masterChanged = req.responseText !== _this6.masterPlaylistLoader_.masterXml_;
|
3702 | _this6.masterPlaylistLoader_.masterXml_ = req.responseText;
|
3703 |
|
3704 | if (req.responseHeaders && req.responseHeaders.date) {
|
3705 | _this6.masterLoaded_ = Date.parse(req.responseHeaders.date);
|
3706 | } else {
|
3707 | _this6.masterLoaded_ = Date.now();
|
3708 | }
|
3709 |
|
3710 | _this6.masterPlaylistLoader_.srcUrl = resolveManifestRedirect(_this6.handleManifestRedirects, _this6.masterPlaylistLoader_.srcUrl, req);
|
3711 |
|
3712 | if (masterChanged) {
|
3713 | _this6.handleMaster_();
|
3714 |
|
3715 | _this6.syncClientServerClock_(function () {
|
3716 | return cb(req, masterChanged);
|
3717 | });
|
3718 |
|
3719 | return;
|
3720 | }
|
3721 |
|
3722 | return cb(req, masterChanged);
|
3723 | });
|
3724 | }
|
3725 | |
3726 |
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 | ;
|
3733 |
|
3734 | _proto.syncClientServerClock_ = function syncClientServerClock_(done) {
|
3735 | var _this7 = this;
|
3736 |
|
3737 | var utcTiming = mpdParser.parseUTCTiming(this.masterPlaylistLoader_.masterXml_);
|
3738 |
|
3739 |
|
3740 | if (utcTiming === null) {
|
3741 | this.masterPlaylistLoader_.clientOffset_ = this.masterLoaded_ - Date.now();
|
3742 | return done();
|
3743 | }
|
3744 |
|
3745 | if (utcTiming.method === 'DIRECT') {
|
3746 | this.masterPlaylistLoader_.clientOffset_ = utcTiming.value - Date.now();
|
3747 | return done();
|
3748 | }
|
3749 |
|
3750 | this.request = this.vhs_.xhr({
|
3751 | uri: resolveUrl(this.masterPlaylistLoader_.srcUrl, utcTiming.value),
|
3752 | method: utcTiming.method,
|
3753 | withCredentials: this.withCredentials
|
3754 | }, function (error, req) {
|
3755 |
|
3756 | if (!_this7.request) {
|
3757 | return;
|
3758 | }
|
3759 |
|
3760 | if (error) {
|
3761 |
|
3762 |
|
3763 | _this7.masterPlaylistLoader_.clientOffset_ = _this7.masterLoaded_ - Date.now();
|
3764 | return done();
|
3765 | }
|
3766 |
|
3767 | var serverTime;
|
3768 |
|
3769 | if (utcTiming.method === 'HEAD') {
|
3770 | if (!req.responseHeaders || !req.responseHeaders.date) {
|
3771 |
|
3772 |
|
3773 | serverTime = _this7.masterLoaded_;
|
3774 | } else {
|
3775 | serverTime = Date.parse(req.responseHeaders.date);
|
3776 | }
|
3777 | } else {
|
3778 | serverTime = Date.parse(req.responseText);
|
3779 | }
|
3780 |
|
3781 | _this7.masterPlaylistLoader_.clientOffset_ = serverTime - Date.now();
|
3782 | done();
|
3783 | });
|
3784 | };
|
3785 |
|
3786 | _proto.haveMaster_ = function haveMaster_() {
|
3787 | this.state = 'HAVE_MASTER';
|
3788 |
|
3789 | if (this.isMaster_) {
|
3790 |
|
3791 |
|
3792 |
|
3793 | this.trigger('loadedplaylist');
|
3794 | } else if (!this.media_) {
|
3795 |
|
3796 |
|
3797 | this.media(this.childPlaylist_);
|
3798 | }
|
3799 | };
|
3800 |
|
3801 | _proto.handleMaster_ = function handleMaster_() {
|
3802 |
|
3803 | this.mediaRequest_ = null;
|
3804 | var newMaster = parseMasterXml({
|
3805 | masterXml: this.masterPlaylistLoader_.masterXml_,
|
3806 | srcUrl: this.masterPlaylistLoader_.srcUrl,
|
3807 | clientOffset: this.masterPlaylistLoader_.clientOffset_,
|
3808 | sidxMapping: this.masterPlaylistLoader_.sidxMapping_
|
3809 | });
|
3810 | var oldMaster = this.masterPlaylistLoader_.master;
|
3811 |
|
3812 | if (oldMaster) {
|
3813 | newMaster = updateMaster(oldMaster, newMaster, this.masterPlaylistLoader_.sidxMapping_);
|
3814 | }
|
3815 |
|
3816 |
|
3817 | this.masterPlaylistLoader_.master = newMaster ? newMaster : oldMaster;
|
3818 | var location = this.masterPlaylistLoader_.master.locations && this.masterPlaylistLoader_.master.locations[0];
|
3819 |
|
3820 | if (location && location !== this.masterPlaylistLoader_.srcUrl) {
|
3821 | this.masterPlaylistLoader_.srcUrl = location;
|
3822 | }
|
3823 |
|
3824 | if (!oldMaster || newMaster && newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
3825 | this.updateMinimumUpdatePeriodTimeout_();
|
3826 | }
|
3827 |
|
3828 | return Boolean(newMaster);
|
3829 | };
|
3830 |
|
3831 | _proto.updateMinimumUpdatePeriodTimeout_ = function updateMinimumUpdatePeriodTimeout_() {
|
3832 | var mpl = this.masterPlaylistLoader_;
|
3833 |
|
3834 |
|
3835 | if (mpl.createMupOnMedia_) {
|
3836 | mpl.off('loadedmetadata', mpl.createMupOnMedia_);
|
3837 | mpl.createMupOnMedia_ = null;
|
3838 | }
|
3839 |
|
3840 |
|
3841 | if (mpl.minimumUpdatePeriodTimeout_) {
|
3842 | window__default["default"].clearTimeout(mpl.minimumUpdatePeriodTimeout_);
|
3843 | mpl.minimumUpdatePeriodTimeout_ = null;
|
3844 | }
|
3845 |
|
3846 | var mup = mpl.master && mpl.master.minimumUpdatePeriod;
|
3847 |
|
3848 |
|
3849 |
|
3850 |
|
3851 | if (mup === 0) {
|
3852 | if (mpl.media()) {
|
3853 | mup = mpl.media().targetDuration * 1000;
|
3854 | } else {
|
3855 | mpl.createMupOnMedia_ = mpl.updateMinimumUpdatePeriodTimeout_;
|
3856 | mpl.one('loadedmetadata', mpl.createMupOnMedia_);
|
3857 | }
|
3858 | }
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 | if (typeof mup !== 'number' || mup <= 0) {
|
3864 | if (mup < 0) {
|
3865 | this.logger_("found invalid minimumUpdatePeriod of " + mup + ", not setting a timeout");
|
3866 | }
|
3867 |
|
3868 | return;
|
3869 | }
|
3870 |
|
3871 | this.createMUPTimeout_(mup);
|
3872 | };
|
3873 |
|
3874 | _proto.createMUPTimeout_ = function createMUPTimeout_(mup) {
|
3875 | var mpl = this.masterPlaylistLoader_;
|
3876 | mpl.minimumUpdatePeriodTimeout_ = window__default["default"].setTimeout(function () {
|
3877 | mpl.minimumUpdatePeriodTimeout_ = null;
|
3878 | mpl.trigger('minimumUpdatePeriod');
|
3879 | mpl.createMUPTimeout_(mup);
|
3880 | }, mup);
|
3881 | }
|
3882 | |
3883 |
|
3884 |
|
3885 | ;
|
3886 |
|
3887 | _proto.refreshXml_ = function refreshXml_() {
|
3888 | var _this8 = this;
|
3889 |
|
3890 | this.requestMaster_(function (req, masterChanged) {
|
3891 | if (!masterChanged) {
|
3892 | return;
|
3893 | }
|
3894 |
|
3895 | if (_this8.media_) {
|
3896 | _this8.media_ = _this8.masterPlaylistLoader_.master.playlists[_this8.media_.id];
|
3897 | }
|
3898 |
|
3899 |
|
3900 | _this8.masterPlaylistLoader_.sidxMapping_ = filterChangedSidxMappings(_this8.masterPlaylistLoader_.master, _this8.masterPlaylistLoader_.sidxMapping_);
|
3901 |
|
3902 | _this8.addSidxSegments_(_this8.media(), _this8.state, function (sidxChanged) {
|
3903 |
|
3904 | _this8.refreshMedia_(_this8.media().id);
|
3905 | });
|
3906 | });
|
3907 | }
|
3908 | |
3909 |
|
3910 |
|
3911 |
|
3912 |
|
3913 | ;
|
3914 |
|
3915 | _proto.refreshMedia_ = function refreshMedia_(mediaID) {
|
3916 | var _this9 = this;
|
3917 |
|
3918 | if (!mediaID) {
|
3919 | throw new Error('refreshMedia_ must take a media id');
|
3920 | }
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 | if (this.media_ && this.isMaster_) {
|
3928 | this.handleMaster_();
|
3929 | }
|
3930 |
|
3931 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
3932 | var mediaChanged = !this.media_ || this.media_ !== playlists[mediaID];
|
3933 |
|
3934 | if (mediaChanged) {
|
3935 | this.media_ = playlists[mediaID];
|
3936 | } else {
|
3937 | this.trigger('playlistunchanged');
|
3938 | }
|
3939 |
|
3940 | if (!this.mediaUpdateTimeout) {
|
3941 | var createMediaUpdateTimeout = function createMediaUpdateTimeout() {
|
3942 | if (_this9.media().endList) {
|
3943 | return;
|
3944 | }
|
3945 |
|
3946 | _this9.mediaUpdateTimeout = window__default["default"].setTimeout(function () {
|
3947 | _this9.trigger('mediaupdatetimeout');
|
3948 |
|
3949 | createMediaUpdateTimeout();
|
3950 | }, refreshDelay(_this9.media(), Boolean(mediaChanged)));
|
3951 | };
|
3952 |
|
3953 | createMediaUpdateTimeout();
|
3954 | }
|
3955 |
|
3956 | this.trigger('loadedplaylist');
|
3957 | };
|
3958 |
|
3959 | return DashPlaylistLoader;
|
3960 | }(EventTarget);
|
3961 |
|
3962 | var Config = {
|
3963 | GOAL_BUFFER_LENGTH: 30,
|
3964 | MAX_GOAL_BUFFER_LENGTH: 60,
|
3965 | BACK_BUFFER_LENGTH: 30,
|
3966 | GOAL_BUFFER_LENGTH_RATE: 1,
|
3967 |
|
3968 | INITIAL_BANDWIDTH: 4194304,
|
3969 |
|
3970 |
|
3971 | BANDWIDTH_VARIANCE: 1.2,
|
3972 |
|
3973 | BUFFER_LOW_WATER_LINE: 0,
|
3974 | MAX_BUFFER_LOW_WATER_LINE: 30,
|
3975 |
|
3976 | EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE: 16,
|
3977 | BUFFER_LOW_WATER_LINE_RATE: 1,
|
3978 |
|
3979 | BUFFER_HIGH_WATER_LINE: 30
|
3980 | };
|
3981 |
|
3982 | var stringToArrayBuffer = function stringToArrayBuffer(string) {
|
3983 | var view = new Uint8Array(new ArrayBuffer(string.length));
|
3984 |
|
3985 | for (var i = 0; i < string.length; i++) {
|
3986 | view[i] = string.charCodeAt(i);
|
3987 | }
|
3988 |
|
3989 | return view.buffer;
|
3990 | };
|
3991 |
|
3992 |
|
3993 |
|
3994 | var browserWorkerPolyFill = function browserWorkerPolyFill(workerObj) {
|
3995 |
|
3996 | workerObj.on = workerObj.addEventListener;
|
3997 | workerObj.off = workerObj.removeEventListener;
|
3998 | return workerObj;
|
3999 | };
|
4000 |
|
4001 | var createObjectURL = function createObjectURL(str) {
|
4002 | try {
|
4003 | return URL.createObjectURL(new Blob([str], {
|
4004 | type: 'application/javascript'
|
4005 | }));
|
4006 | } catch (e) {
|
4007 | var blob = new BlobBuilder();
|
4008 | blob.append(str);
|
4009 | return URL.createObjectURL(blob.getBlob());
|
4010 | }
|
4011 | };
|
4012 |
|
4013 | var factory = function factory(code) {
|
4014 | return function () {
|
4015 | var objectUrl = createObjectURL(code);
|
4016 | var worker = browserWorkerPolyFill(new Worker(objectUrl));
|
4017 | worker.objURL = objectUrl;
|
4018 | var terminate = worker.terminate;
|
4019 | worker.on = worker.addEventListener;
|
4020 | worker.off = worker.removeEventListener;
|
4021 |
|
4022 | worker.terminate = function () {
|
4023 | URL.revokeObjectURL(objectUrl);
|
4024 | return terminate.call(this);
|
4025 | };
|
4026 |
|
4027 | return worker;
|
4028 | };
|
4029 | };
|
4030 | var transform = function transform(code) {
|
4031 | return "var browserWorkerPolyFill = " + browserWorkerPolyFill.toString() + ";\n" + 'browserWorkerPolyFill(self);\n' + code;
|
4032 | };
|
4033 |
|
4034 | var getWorkerString = function getWorkerString(fn) {
|
4035 | return fn.toString().replace(/^function.+?{/, '').slice(0, -1);
|
4036 | };
|
4037 |
|
4038 |
|
4039 | var workerCode$1 = transform(getWorkerString(function () {
|
4040 | |
4041 |
|
4042 |
|
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 |
|
4050 | var Stream = function Stream() {
|
4051 | this.init = function () {
|
4052 | var listeners = {};
|
4053 | |
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 | this.on = function (type, listener) {
|
4061 | if (!listeners[type]) {
|
4062 | listeners[type] = [];
|
4063 | }
|
4064 |
|
4065 | listeners[type] = listeners[type].concat(listener);
|
4066 | };
|
4067 | |
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 |
|
4075 | this.off = function (type, listener) {
|
4076 | var index;
|
4077 |
|
4078 | if (!listeners[type]) {
|
4079 | return false;
|
4080 | }
|
4081 |
|
4082 | index = listeners[type].indexOf(listener);
|
4083 | listeners[type] = listeners[type].slice();
|
4084 | listeners[type].splice(index, 1);
|
4085 | return index > -1;
|
4086 | };
|
4087 | |
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 | this.trigger = function (type) {
|
4095 | var callbacks, i, length, args;
|
4096 | callbacks = listeners[type];
|
4097 |
|
4098 | if (!callbacks) {
|
4099 | return;
|
4100 | }
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 | if (arguments.length === 2) {
|
4107 | length = callbacks.length;
|
4108 |
|
4109 | for (i = 0; i < length; ++i) {
|
4110 | callbacks[i].call(this, arguments[1]);
|
4111 | }
|
4112 | } else {
|
4113 | args = [];
|
4114 | i = arguments.length;
|
4115 |
|
4116 | for (i = 1; i < arguments.length; ++i) {
|
4117 | args.push(arguments[i]);
|
4118 | }
|
4119 |
|
4120 | length = callbacks.length;
|
4121 |
|
4122 | for (i = 0; i < length; ++i) {
|
4123 | callbacks[i].apply(this, args);
|
4124 | }
|
4125 | }
|
4126 | };
|
4127 | |
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 | this.dispose = function () {
|
4133 | listeners = {};
|
4134 | };
|
4135 | };
|
4136 | };
|
4137 | |
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 |
|
4144 |
|
4145 |
|
4146 |
|
4147 |
|
4148 | Stream.prototype.pipe = function (destination) {
|
4149 | this.on('data', function (data) {
|
4150 | destination.push(data);
|
4151 | });
|
4152 | this.on('done', function (flushSource) {
|
4153 | destination.flush(flushSource);
|
4154 | });
|
4155 | this.on('partialdone', function (flushSource) {
|
4156 | destination.partialFlush(flushSource);
|
4157 | });
|
4158 | this.on('endedtimeline', function (flushSource) {
|
4159 | destination.endTimeline(flushSource);
|
4160 | });
|
4161 | this.on('reset', function (flushSource) {
|
4162 | destination.reset(flushSource);
|
4163 | });
|
4164 | return destination;
|
4165 | };
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 | Stream.prototype.push = function (data) {
|
4172 | this.trigger('data', data);
|
4173 | };
|
4174 |
|
4175 | Stream.prototype.flush = function (flushSource) {
|
4176 | this.trigger('done', flushSource);
|
4177 | };
|
4178 |
|
4179 | Stream.prototype.partialFlush = function (flushSource) {
|
4180 | this.trigger('partialdone', flushSource);
|
4181 | };
|
4182 |
|
4183 | Stream.prototype.endTimeline = function (flushSource) {
|
4184 | this.trigger('endedtimeline', flushSource);
|
4185 | };
|
4186 |
|
4187 | Stream.prototype.reset = function (flushSource) {
|
4188 | this.trigger('reset', flushSource);
|
4189 | };
|
4190 |
|
4191 | var stream = Stream;
|
4192 | |
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 | var UINT32_MAX = Math.pow(2, 32) - 1;
|
4203 | 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;
|
4204 |
|
4205 | (function () {
|
4206 | var i;
|
4207 | types = {
|
4208 | avc1: [],
|
4209 |
|
4210 | avcC: [],
|
4211 | btrt: [],
|
4212 | dinf: [],
|
4213 | dref: [],
|
4214 | esds: [],
|
4215 | ftyp: [],
|
4216 | hdlr: [],
|
4217 | mdat: [],
|
4218 | mdhd: [],
|
4219 | mdia: [],
|
4220 | mfhd: [],
|
4221 | minf: [],
|
4222 | moof: [],
|
4223 | moov: [],
|
4224 | mp4a: [],
|
4225 |
|
4226 | mvex: [],
|
4227 | mvhd: [],
|
4228 | pasp: [],
|
4229 | sdtp: [],
|
4230 | smhd: [],
|
4231 | stbl: [],
|
4232 | stco: [],
|
4233 | stsc: [],
|
4234 | stsd: [],
|
4235 | stsz: [],
|
4236 | stts: [],
|
4237 | styp: [],
|
4238 | tfdt: [],
|
4239 | tfhd: [],
|
4240 | traf: [],
|
4241 | trak: [],
|
4242 | trun: [],
|
4243 | trex: [],
|
4244 | tkhd: [],
|
4245 | vmhd: []
|
4246 | };
|
4247 |
|
4248 |
|
4249 | if (typeof Uint8Array === 'undefined') {
|
4250 | return;
|
4251 | }
|
4252 |
|
4253 | for (i in types) {
|
4254 | if (types.hasOwnProperty(i)) {
|
4255 | types[i] = [i.charCodeAt(0), i.charCodeAt(1), i.charCodeAt(2), i.charCodeAt(3)];
|
4256 | }
|
4257 | }
|
4258 |
|
4259 | MAJOR_BRAND = new Uint8Array(['i'.charCodeAt(0), 's'.charCodeAt(0), 'o'.charCodeAt(0), 'm'.charCodeAt(0)]);
|
4260 | AVC1_BRAND = new Uint8Array(['a'.charCodeAt(0), 'v'.charCodeAt(0), 'c'.charCodeAt(0), '1'.charCodeAt(0)]);
|
4261 | MINOR_VERSION = new Uint8Array([0, 0, 0, 1]);
|
4262 | VIDEO_HDLR = new Uint8Array([0x00,
|
4263 | 0x00, 0x00, 0x00,
|
4264 | 0x00, 0x00, 0x00, 0x00,
|
4265 | 0x76, 0x69, 0x64, 0x65,
|
4266 | 0x00, 0x00, 0x00, 0x00,
|
4267 | 0x00, 0x00, 0x00, 0x00,
|
4268 | 0x00, 0x00, 0x00, 0x00,
|
4269 | 0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
4270 | ]);
|
4271 | AUDIO_HDLR = new Uint8Array([0x00,
|
4272 | 0x00, 0x00, 0x00,
|
4273 | 0x00, 0x00, 0x00, 0x00,
|
4274 | 0x73, 0x6f, 0x75, 0x6e,
|
4275 | 0x00, 0x00, 0x00, 0x00,
|
4276 | 0x00, 0x00, 0x00, 0x00,
|
4277 | 0x00, 0x00, 0x00, 0x00,
|
4278 | 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
4279 | ]);
|
4280 | HDLR_TYPES = {
|
4281 | video: VIDEO_HDLR,
|
4282 | audio: AUDIO_HDLR
|
4283 | };
|
4284 | DREF = new Uint8Array([0x00,
|
4285 | 0x00, 0x00, 0x00,
|
4286 | 0x00, 0x00, 0x00, 0x01,
|
4287 | 0x00, 0x00, 0x00, 0x0c,
|
4288 | 0x75, 0x72, 0x6c, 0x20,
|
4289 | 0x00,
|
4290 | 0x00, 0x00, 0x01
|
4291 | ]);
|
4292 | SMHD = new Uint8Array([0x00,
|
4293 | 0x00, 0x00, 0x00,
|
4294 | 0x00, 0x00,
|
4295 | 0x00, 0x00
|
4296 | ]);
|
4297 | STCO = new Uint8Array([0x00,
|
4298 | 0x00, 0x00, 0x00,
|
4299 | 0x00, 0x00, 0x00, 0x00
|
4300 | ]);
|
4301 | STSC = STCO;
|
4302 | STSZ = new Uint8Array([0x00,
|
4303 | 0x00, 0x00, 0x00,
|
4304 | 0x00, 0x00, 0x00, 0x00,
|
4305 | 0x00, 0x00, 0x00, 0x00
|
4306 | ]);
|
4307 | STTS = STCO;
|
4308 | VMHD = new Uint8Array([0x00,
|
4309 | 0x00, 0x00, 0x01,
|
4310 | 0x00, 0x00,
|
4311 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
4312 | ]);
|
4313 | })();
|
4314 |
|
4315 | box = function box(type) {
|
4316 | var payload = [],
|
4317 | size = 0,
|
4318 | i,
|
4319 | result,
|
4320 | view;
|
4321 |
|
4322 | for (i = 1; i < arguments.length; i++) {
|
4323 | payload.push(arguments[i]);
|
4324 | }
|
4325 |
|
4326 | i = payload.length;
|
4327 |
|
4328 | while (i--) {
|
4329 | size += payload[i].byteLength;
|
4330 | }
|
4331 |
|
4332 | result = new Uint8Array(size + 8);
|
4333 | view = new DataView(result.buffer, result.byteOffset, result.byteLength);
|
4334 | view.setUint32(0, result.byteLength);
|
4335 | result.set(type, 4);
|
4336 |
|
4337 | for (i = 0, size = 8; i < payload.length; i++) {
|
4338 | result.set(payload[i], size);
|
4339 | size += payload[i].byteLength;
|
4340 | }
|
4341 |
|
4342 | return result;
|
4343 | };
|
4344 |
|
4345 | dinf = function dinf() {
|
4346 | return box(types.dinf, box(types.dref, DREF));
|
4347 | };
|
4348 |
|
4349 | esds = function esds(track) {
|
4350 | return box(types.esds, new Uint8Array([0x00,
|
4351 | 0x00, 0x00, 0x00,
|
4352 |
|
4353 | 0x03,
|
4354 | 0x19,
|
4355 | 0x00, 0x00,
|
4356 | 0x00,
|
4357 |
|
4358 | 0x04,
|
4359 | 0x11,
|
4360 | 0x40,
|
4361 | 0x15,
|
4362 | 0x00, 0x06, 0x00,
|
4363 | 0x00, 0x00, 0xda, 0xc0,
|
4364 | 0x00, 0x00, 0xda, 0xc0,
|
4365 |
|
4366 | 0x05,
|
4367 | 0x02,
|
4368 |
|
4369 |
|
4370 | track.audioobjecttype << 3 | track.samplingfrequencyindex >>> 1, track.samplingfrequencyindex << 7 | track.channelcount << 3, 0x06, 0x01, 0x02
|
4371 | ]));
|
4372 | };
|
4373 |
|
4374 | ftyp = function ftyp() {
|
4375 | return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND, AVC1_BRAND);
|
4376 | };
|
4377 |
|
4378 | hdlr = function hdlr(type) {
|
4379 | return box(types.hdlr, HDLR_TYPES[type]);
|
4380 | };
|
4381 |
|
4382 | mdat = function mdat(data) {
|
4383 | return box(types.mdat, data);
|
4384 | };
|
4385 |
|
4386 | mdhd = function mdhd(track) {
|
4387 | var result = new Uint8Array([0x00,
|
4388 | 0x00, 0x00, 0x00,
|
4389 | 0x00, 0x00, 0x00, 0x02,
|
4390 | 0x00, 0x00, 0x00, 0x03,
|
4391 | 0x00, 0x01, 0x5f, 0x90,
|
4392 | track.duration >>> 24 & 0xFF, track.duration >>> 16 & 0xFF, track.duration >>> 8 & 0xFF, track.duration & 0xFF,
|
4393 | 0x55, 0xc4,
|
4394 | 0x00, 0x00]);
|
4395 |
|
4396 |
|
4397 |
|
4398 | if (track.samplerate) {
|
4399 | result[12] = track.samplerate >>> 24 & 0xFF;
|
4400 | result[13] = track.samplerate >>> 16 & 0xFF;
|
4401 | result[14] = track.samplerate >>> 8 & 0xFF;
|
4402 | result[15] = track.samplerate & 0xFF;
|
4403 | }
|
4404 |
|
4405 | return box(types.mdhd, result);
|
4406 | };
|
4407 |
|
4408 | mdia = function mdia(track) {
|
4409 | return box(types.mdia, mdhd(track), hdlr(track.type), minf(track));
|
4410 | };
|
4411 |
|
4412 | mfhd = function mfhd(sequenceNumber) {
|
4413 | return box(types.mfhd, new Uint8Array([0x00, 0x00, 0x00, 0x00,
|
4414 | (sequenceNumber & 0xFF000000) >> 24, (sequenceNumber & 0xFF0000) >> 16, (sequenceNumber & 0xFF00) >> 8, sequenceNumber & 0xFF
|
4415 | ]));
|
4416 | };
|
4417 |
|
4418 | minf = function minf(track) {
|
4419 | return box(types.minf, track.type === 'video' ? box(types.vmhd, VMHD) : box(types.smhd, SMHD), dinf(), stbl(track));
|
4420 | };
|
4421 |
|
4422 | moof = function moof(sequenceNumber, tracks) {
|
4423 | var trackFragments = [],
|
4424 | i = tracks.length;
|
4425 |
|
4426 | while (i--) {
|
4427 | trackFragments[i] = traf(tracks[i]);
|
4428 | }
|
4429 |
|
4430 | return box.apply(null, [types.moof, mfhd(sequenceNumber)].concat(trackFragments));
|
4431 | };
|
4432 | |
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 |
|
4438 |
|
4439 | moov = function moov(tracks) {
|
4440 | var i = tracks.length,
|
4441 | boxes = [];
|
4442 |
|
4443 | while (i--) {
|
4444 | boxes[i] = trak(tracks[i]);
|
4445 | }
|
4446 |
|
4447 | return box.apply(null, [types.moov, mvhd(0xffffffff)].concat(boxes).concat(mvex(tracks)));
|
4448 | };
|
4449 |
|
4450 | mvex = function mvex(tracks) {
|
4451 | var i = tracks.length,
|
4452 | boxes = [];
|
4453 |
|
4454 | while (i--) {
|
4455 | boxes[i] = trex(tracks[i]);
|
4456 | }
|
4457 |
|
4458 | return box.apply(null, [types.mvex].concat(boxes));
|
4459 | };
|
4460 |
|
4461 | mvhd = function mvhd(duration) {
|
4462 | var bytes = new Uint8Array([0x00,
|
4463 | 0x00, 0x00, 0x00,
|
4464 | 0x00, 0x00, 0x00, 0x01,
|
4465 | 0x00, 0x00, 0x00, 0x02,
|
4466 | 0x00, 0x01, 0x5f, 0x90,
|
4467 | (duration & 0xFF000000) >> 24, (duration & 0xFF0000) >> 16, (duration & 0xFF00) >> 8, duration & 0xFF,
|
4468 | 0x00, 0x01, 0x00, 0x00,
|
4469 | 0x01, 0x00,
|
4470 | 0x00, 0x00,
|
4471 | 0x00, 0x00, 0x00, 0x00,
|
4472 | 0x00, 0x00, 0x00, 0x00,
|
4473 | 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,
|
4474 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4475 | 0xff, 0xff, 0xff, 0xff
|
4476 | ]);
|
4477 | return box(types.mvhd, bytes);
|
4478 | };
|
4479 |
|
4480 | sdtp = function sdtp(track) {
|
4481 | var samples = track.samples || [],
|
4482 | bytes = new Uint8Array(4 + samples.length),
|
4483 | flags,
|
4484 | i;
|
4485 |
|
4486 |
|
4487 | for (i = 0; i < samples.length; i++) {
|
4488 | flags = samples[i].flags;
|
4489 | bytes[i + 4] = flags.dependsOn << 4 | flags.isDependedOn << 2 | flags.hasRedundancy;
|
4490 | }
|
4491 |
|
4492 | return box(types.sdtp, bytes);
|
4493 | };
|
4494 |
|
4495 | stbl = function stbl(track) {
|
4496 | return box(types.stbl, stsd(track), box(types.stts, STTS), box(types.stsc, STSC), box(types.stsz, STSZ), box(types.stco, STCO));
|
4497 | };
|
4498 |
|
4499 | (function () {
|
4500 | var videoSample, audioSample;
|
4501 |
|
4502 | stsd = function stsd(track) {
|
4503 | return box(types.stsd, new Uint8Array([0x00,
|
4504 | 0x00, 0x00, 0x00,
|
4505 | 0x00, 0x00, 0x00, 0x01]), track.type === 'video' ? videoSample(track) : audioSample(track));
|
4506 | };
|
4507 |
|
4508 | videoSample = function videoSample(track) {
|
4509 | var sps = track.sps || [],
|
4510 | pps = track.pps || [],
|
4511 | sequenceParameterSets = [],
|
4512 | pictureParameterSets = [],
|
4513 | i,
|
4514 | avc1Box;
|
4515 |
|
4516 | for (i = 0; i < sps.length; i++) {
|
4517 | sequenceParameterSets.push((sps[i].byteLength & 0xFF00) >>> 8);
|
4518 | sequenceParameterSets.push(sps[i].byteLength & 0xFF);
|
4519 |
|
4520 | sequenceParameterSets = sequenceParameterSets.concat(Array.prototype.slice.call(sps[i]));
|
4521 | }
|
4522 |
|
4523 |
|
4524 | for (i = 0; i < pps.length; i++) {
|
4525 | pictureParameterSets.push((pps[i].byteLength & 0xFF00) >>> 8);
|
4526 | pictureParameterSets.push(pps[i].byteLength & 0xFF);
|
4527 | pictureParameterSets = pictureParameterSets.concat(Array.prototype.slice.call(pps[i]));
|
4528 | }
|
4529 |
|
4530 | avc1Box = [types.avc1, new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4531 | 0x00, 0x01,
|
4532 | 0x00, 0x00,
|
4533 | 0x00, 0x00,
|
4534 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4535 | (track.width & 0xff00) >> 8, track.width & 0xff,
|
4536 | (track.height & 0xff00) >> 8, track.height & 0xff,
|
4537 | 0x00, 0x48, 0x00, 0x00,
|
4538 | 0x00, 0x48, 0x00, 0x00,
|
4539 | 0x00, 0x00, 0x00, 0x00,
|
4540 | 0x00, 0x01,
|
4541 | 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,
|
4542 | 0x00, 0x18,
|
4543 | 0x11, 0x11
|
4544 | ]), box(types.avcC, new Uint8Array([0x01,
|
4545 | track.profileIdc,
|
4546 | track.profileCompatibility,
|
4547 | track.levelIdc,
|
4548 | 0xff
|
4549 | ].concat([sps.length],
|
4550 | sequenceParameterSets,
|
4551 | [pps.length],
|
4552 | pictureParameterSets
|
4553 | ))), box(types.btrt, new Uint8Array([0x00, 0x1c, 0x9c, 0x80,
|
4554 | 0x00, 0x2d, 0xc6, 0xc0,
|
4555 | 0x00, 0x2d, 0xc6, 0xc0
|
4556 | ]))];
|
4557 |
|
4558 | if (track.sarRatio) {
|
4559 | var hSpacing = track.sarRatio[0],
|
4560 | vSpacing = track.sarRatio[1];
|
4561 | 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])));
|
4562 | }
|
4563 |
|
4564 | return box.apply(null, avc1Box);
|
4565 | };
|
4566 |
|
4567 | audioSample = function audioSample(track) {
|
4568 | return box(types.mp4a, new Uint8Array([
|
4569 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4570 | 0x00, 0x01,
|
4571 |
|
4572 | 0x00, 0x00, 0x00, 0x00,
|
4573 | 0x00, 0x00, 0x00, 0x00,
|
4574 | (track.channelcount & 0xff00) >> 8, track.channelcount & 0xff,
|
4575 | (track.samplesize & 0xff00) >> 8, track.samplesize & 0xff,
|
4576 | 0x00, 0x00,
|
4577 | 0x00, 0x00,
|
4578 | (track.samplerate & 0xff00) >> 8, track.samplerate & 0xff, 0x00, 0x00
|
4579 |
|
4580 | ]), esds(track));
|
4581 | };
|
4582 | })();
|
4583 |
|
4584 | tkhd = function tkhd(track) {
|
4585 | var result = new Uint8Array([0x00,
|
4586 | 0x00, 0x00, 0x07,
|
4587 | 0x00, 0x00, 0x00, 0x00,
|
4588 | 0x00, 0x00, 0x00, 0x00,
|
4589 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4590 | 0x00, 0x00, 0x00, 0x00,
|
4591 | (track.duration & 0xFF000000) >> 24, (track.duration & 0xFF0000) >> 16, (track.duration & 0xFF00) >> 8, track.duration & 0xFF,
|
4592 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4593 | 0x00, 0x00,
|
4594 | 0x00, 0x00,
|
4595 | 0x01, 0x00,
|
4596 | 0x00, 0x00,
|
4597 | 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,
|
4598 | (track.width & 0xFF00) >> 8, track.width & 0xFF, 0x00, 0x00,
|
4599 | (track.height & 0xFF00) >> 8, track.height & 0xFF, 0x00, 0x00
|
4600 | ]);
|
4601 | return box(types.tkhd, result);
|
4602 | };
|
4603 | |
4604 |
|
4605 |
|
4606 |
|
4607 |
|
4608 |
|
4609 | traf = function traf(track) {
|
4610 | var trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable, dataOffset, upperWordBaseMediaDecodeTime, lowerWordBaseMediaDecodeTime;
|
4611 | trackFragmentHeader = box(types.tfhd, new Uint8Array([0x00,
|
4612 | 0x00, 0x00, 0x3a,
|
4613 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4614 | 0x00, 0x00, 0x00, 0x01,
|
4615 | 0x00, 0x00, 0x00, 0x00,
|
4616 | 0x00, 0x00, 0x00, 0x00,
|
4617 | 0x00, 0x00, 0x00, 0x00
|
4618 | ]));
|
4619 | upperWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime / (UINT32_MAX + 1));
|
4620 | lowerWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime % (UINT32_MAX + 1));
|
4621 | trackFragmentDecodeTime = box(types.tfdt, new Uint8Array([0x01,
|
4622 | 0x00, 0x00, 0x00,
|
4623 |
|
4624 | upperWordBaseMediaDecodeTime >>> 24 & 0xFF, upperWordBaseMediaDecodeTime >>> 16 & 0xFF, upperWordBaseMediaDecodeTime >>> 8 & 0xFF, upperWordBaseMediaDecodeTime & 0xFF, lowerWordBaseMediaDecodeTime >>> 24 & 0xFF, lowerWordBaseMediaDecodeTime >>> 16 & 0xFF, lowerWordBaseMediaDecodeTime >>> 8 & 0xFF, lowerWordBaseMediaDecodeTime & 0xFF]));
|
4625 |
|
4626 |
|
4627 |
|
4628 | dataOffset = 32 +
|
4629 | 20 +
|
4630 | 8 +
|
4631 | 16 +
|
4632 | 8 +
|
4633 | 8;
|
4634 |
|
4635 |
|
4636 | if (track.type === 'audio') {
|
4637 | trackFragmentRun = trun$1(track, dataOffset);
|
4638 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun);
|
4639 | }
|
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 | sampleDependencyTable = sdtp(track);
|
4645 | trackFragmentRun = trun$1(track, sampleDependencyTable.length + dataOffset);
|
4646 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable);
|
4647 | };
|
4648 | |
4649 |
|
4650 |
|
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 | trak = function trak(track) {
|
4656 | track.duration = track.duration || 0xffffffff;
|
4657 | return box(types.trak, tkhd(track), mdia(track));
|
4658 | };
|
4659 |
|
4660 | trex = function trex(track) {
|
4661 | var result = new Uint8Array([0x00,
|
4662 | 0x00, 0x00, 0x00,
|
4663 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4664 | 0x00, 0x00, 0x00, 0x01,
|
4665 | 0x00, 0x00, 0x00, 0x00,
|
4666 | 0x00, 0x00, 0x00, 0x00,
|
4667 | 0x00, 0x01, 0x00, 0x01
|
4668 | ]);
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 | if (track.type !== 'video') {
|
4674 | result[result.length - 1] = 0x00;
|
4675 | }
|
4676 |
|
4677 | return box(types.trex, result);
|
4678 | };
|
4679 |
|
4680 | (function () {
|
4681 | var audioTrun, videoTrun, trunHeader;
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 | trunHeader = function trunHeader(samples, offset) {
|
4687 | var durationPresent = 0,
|
4688 | sizePresent = 0,
|
4689 | flagsPresent = 0,
|
4690 | compositionTimeOffset = 0;
|
4691 |
|
4692 | if (samples.length) {
|
4693 | if (samples[0].duration !== undefined) {
|
4694 | durationPresent = 0x1;
|
4695 | }
|
4696 |
|
4697 | if (samples[0].size !== undefined) {
|
4698 | sizePresent = 0x2;
|
4699 | }
|
4700 |
|
4701 | if (samples[0].flags !== undefined) {
|
4702 | flagsPresent = 0x4;
|
4703 | }
|
4704 |
|
4705 | if (samples[0].compositionTimeOffset !== undefined) {
|
4706 | compositionTimeOffset = 0x8;
|
4707 | }
|
4708 | }
|
4709 |
|
4710 | return [0x00,
|
4711 | 0x00, durationPresent | sizePresent | flagsPresent | compositionTimeOffset, 0x01,
|
4712 | (samples.length & 0xFF000000) >>> 24, (samples.length & 0xFF0000) >>> 16, (samples.length & 0xFF00) >>> 8, samples.length & 0xFF,
|
4713 | (offset & 0xFF000000) >>> 24, (offset & 0xFF0000) >>> 16, (offset & 0xFF00) >>> 8, offset & 0xFF
|
4714 | ];
|
4715 | };
|
4716 |
|
4717 | videoTrun = function videoTrun(track, offset) {
|
4718 | var bytesOffest, bytes, header, samples, sample, i;
|
4719 | samples = track.samples || [];
|
4720 | offset += 8 + 12 + 16 * samples.length;
|
4721 | header = trunHeader(samples, offset);
|
4722 | bytes = new Uint8Array(header.length + samples.length * 16);
|
4723 | bytes.set(header);
|
4724 | bytesOffest = header.length;
|
4725 |
|
4726 | for (i = 0; i < samples.length; i++) {
|
4727 | sample = samples[i];
|
4728 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
4729 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
4730 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
4731 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
4732 |
|
4733 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
4734 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
4735 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
4736 | bytes[bytesOffest++] = sample.size & 0xFF;
|
4737 |
|
4738 | bytes[bytesOffest++] = sample.flags.isLeading << 2 | sample.flags.dependsOn;
|
4739 | bytes[bytesOffest++] = sample.flags.isDependedOn << 6 | sample.flags.hasRedundancy << 4 | sample.flags.paddingValue << 1 | sample.flags.isNonSyncSample;
|
4740 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0xF0 << 8;
|
4741 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0x0F;
|
4742 |
|
4743 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF000000) >>> 24;
|
4744 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF0000) >>> 16;
|
4745 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF00) >>> 8;
|
4746 | bytes[bytesOffest++] = sample.compositionTimeOffset & 0xFF;
|
4747 | }
|
4748 |
|
4749 | return box(types.trun, bytes);
|
4750 | };
|
4751 |
|
4752 | audioTrun = function audioTrun(track, offset) {
|
4753 | var bytes, bytesOffest, header, samples, sample, i;
|
4754 | samples = track.samples || [];
|
4755 | offset += 8 + 12 + 8 * samples.length;
|
4756 | header = trunHeader(samples, offset);
|
4757 | bytes = new Uint8Array(header.length + samples.length * 8);
|
4758 | bytes.set(header);
|
4759 | bytesOffest = header.length;
|
4760 |
|
4761 | for (i = 0; i < samples.length; i++) {
|
4762 | sample = samples[i];
|
4763 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
4764 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
4765 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
4766 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
4767 |
|
4768 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
4769 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
4770 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
4771 | bytes[bytesOffest++] = sample.size & 0xFF;
|
4772 | }
|
4773 |
|
4774 | return box(types.trun, bytes);
|
4775 | };
|
4776 |
|
4777 | trun$1 = function trun(track, offset) {
|
4778 | if (track.type === 'audio') {
|
4779 | return audioTrun(track, offset);
|
4780 | }
|
4781 |
|
4782 | return videoTrun(track, offset);
|
4783 | };
|
4784 | })();
|
4785 |
|
4786 | var mp4Generator = {
|
4787 | ftyp: ftyp,
|
4788 | mdat: mdat,
|
4789 | moof: moof,
|
4790 | moov: moov,
|
4791 | initSegment: function initSegment(tracks) {
|
4792 | var fileType = ftyp(),
|
4793 | movie = moov(tracks),
|
4794 | result;
|
4795 | result = new Uint8Array(fileType.byteLength + movie.byteLength);
|
4796 | result.set(fileType);
|
4797 | result.set(movie, fileType.byteLength);
|
4798 | return result;
|
4799 | }
|
4800 | };
|
4801 | |
4802 |
|
4803 |
|
4804 |
|
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 |
|
4810 |
|
4811 |
|
4812 | var groupNalsIntoFrames = function groupNalsIntoFrames(nalUnits) {
|
4813 | var i,
|
4814 | currentNal,
|
4815 | currentFrame = [],
|
4816 | frames = [];
|
4817 |
|
4818 | frames.byteLength = 0;
|
4819 | frames.nalCount = 0;
|
4820 | frames.duration = 0;
|
4821 | currentFrame.byteLength = 0;
|
4822 |
|
4823 | for (i = 0; i < nalUnits.length; i++) {
|
4824 | currentNal = nalUnits[i];
|
4825 |
|
4826 | if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
|
4827 |
|
4828 |
|
4829 | if (currentFrame.length) {
|
4830 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
4831 |
|
4832 | frames.byteLength += currentFrame.byteLength;
|
4833 | frames.nalCount += currentFrame.length;
|
4834 | frames.duration += currentFrame.duration;
|
4835 | frames.push(currentFrame);
|
4836 | }
|
4837 |
|
4838 | currentFrame = [currentNal];
|
4839 | currentFrame.byteLength = currentNal.data.byteLength;
|
4840 | currentFrame.pts = currentNal.pts;
|
4841 | currentFrame.dts = currentNal.dts;
|
4842 | } else {
|
4843 |
|
4844 | if (currentNal.nalUnitType === 'slice_layer_without_partitioning_rbsp_idr') {
|
4845 | currentFrame.keyFrame = true;
|
4846 | }
|
4847 |
|
4848 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
4849 | currentFrame.byteLength += currentNal.data.byteLength;
|
4850 | currentFrame.push(currentNal);
|
4851 | }
|
4852 | }
|
4853 |
|
4854 |
|
4855 |
|
4856 | if (frames.length && (!currentFrame.duration || currentFrame.duration <= 0)) {
|
4857 | currentFrame.duration = frames[frames.length - 1].duration;
|
4858 | }
|
4859 |
|
4860 |
|
4861 |
|
4862 | frames.byteLength += currentFrame.byteLength;
|
4863 | frames.nalCount += currentFrame.length;
|
4864 | frames.duration += currentFrame.duration;
|
4865 | frames.push(currentFrame);
|
4866 | return frames;
|
4867 | };
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 | var groupFramesIntoGops = function groupFramesIntoGops(frames) {
|
4874 | var i,
|
4875 | currentFrame,
|
4876 | currentGop = [],
|
4877 | gops = [];
|
4878 |
|
4879 |
|
4880 | currentGop.byteLength = 0;
|
4881 | currentGop.nalCount = 0;
|
4882 | currentGop.duration = 0;
|
4883 | currentGop.pts = frames[0].pts;
|
4884 | currentGop.dts = frames[0].dts;
|
4885 |
|
4886 | gops.byteLength = 0;
|
4887 | gops.nalCount = 0;
|
4888 | gops.duration = 0;
|
4889 | gops.pts = frames[0].pts;
|
4890 | gops.dts = frames[0].dts;
|
4891 |
|
4892 | for (i = 0; i < frames.length; i++) {
|
4893 | currentFrame = frames[i];
|
4894 |
|
4895 | if (currentFrame.keyFrame) {
|
4896 |
|
4897 |
|
4898 | if (currentGop.length) {
|
4899 | gops.push(currentGop);
|
4900 | gops.byteLength += currentGop.byteLength;
|
4901 | gops.nalCount += currentGop.nalCount;
|
4902 | gops.duration += currentGop.duration;
|
4903 | }
|
4904 |
|
4905 | currentGop = [currentFrame];
|
4906 | currentGop.nalCount = currentFrame.length;
|
4907 | currentGop.byteLength = currentFrame.byteLength;
|
4908 | currentGop.pts = currentFrame.pts;
|
4909 | currentGop.dts = currentFrame.dts;
|
4910 | currentGop.duration = currentFrame.duration;
|
4911 | } else {
|
4912 | currentGop.duration += currentFrame.duration;
|
4913 | currentGop.nalCount += currentFrame.length;
|
4914 | currentGop.byteLength += currentFrame.byteLength;
|
4915 | currentGop.push(currentFrame);
|
4916 | }
|
4917 | }
|
4918 |
|
4919 | if (gops.length && currentGop.duration <= 0) {
|
4920 | currentGop.duration = gops[gops.length - 1].duration;
|
4921 | }
|
4922 |
|
4923 | gops.byteLength += currentGop.byteLength;
|
4924 | gops.nalCount += currentGop.nalCount;
|
4925 | gops.duration += currentGop.duration;
|
4926 |
|
4927 | gops.push(currentGop);
|
4928 | return gops;
|
4929 | };
|
4930 | |
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 |
|
4938 |
|
4939 |
|
4940 |
|
4941 | var extendFirstKeyFrame = function extendFirstKeyFrame(gops) {
|
4942 | var currentGop;
|
4943 |
|
4944 | if (!gops[0][0].keyFrame && gops.length > 1) {
|
4945 |
|
4946 | currentGop = gops.shift();
|
4947 | gops.byteLength -= currentGop.byteLength;
|
4948 | gops.nalCount -= currentGop.nalCount;
|
4949 |
|
4950 |
|
4951 |
|
4952 | gops[0][0].dts = currentGop.dts;
|
4953 | gops[0][0].pts = currentGop.pts;
|
4954 | gops[0][0].duration += currentGop.duration;
|
4955 | }
|
4956 |
|
4957 | return gops;
|
4958 | };
|
4959 | |
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 | var createDefaultSample = function createDefaultSample() {
|
4966 | return {
|
4967 | size: 0,
|
4968 | flags: {
|
4969 | isLeading: 0,
|
4970 | dependsOn: 1,
|
4971 | isDependedOn: 0,
|
4972 | hasRedundancy: 0,
|
4973 | degradationPriority: 0,
|
4974 | isNonSyncSample: 1
|
4975 | }
|
4976 | };
|
4977 | };
|
4978 | |
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 |
|
4984 |
|
4985 |
|
4986 |
|
4987 |
|
4988 | var sampleForFrame = function sampleForFrame(frame, dataOffset) {
|
4989 | var sample = createDefaultSample();
|
4990 | sample.dataOffset = dataOffset;
|
4991 | sample.compositionTimeOffset = frame.pts - frame.dts;
|
4992 | sample.duration = frame.duration;
|
4993 | sample.size = 4 * frame.length;
|
4994 |
|
4995 | sample.size += frame.byteLength;
|
4996 |
|
4997 | if (frame.keyFrame) {
|
4998 | sample.flags.dependsOn = 2;
|
4999 | sample.flags.isNonSyncSample = 0;
|
5000 | }
|
5001 |
|
5002 | return sample;
|
5003 | };
|
5004 |
|
5005 |
|
5006 | var generateSampleTable$1 = function generateSampleTable(gops, baseDataOffset) {
|
5007 | var h,
|
5008 | i,
|
5009 | sample,
|
5010 | currentGop,
|
5011 | currentFrame,
|
5012 | dataOffset = baseDataOffset || 0,
|
5013 | samples = [];
|
5014 |
|
5015 | for (h = 0; h < gops.length; h++) {
|
5016 | currentGop = gops[h];
|
5017 |
|
5018 | for (i = 0; i < currentGop.length; i++) {
|
5019 | currentFrame = currentGop[i];
|
5020 | sample = sampleForFrame(currentFrame, dataOffset);
|
5021 | dataOffset += sample.size;
|
5022 | samples.push(sample);
|
5023 | }
|
5024 | }
|
5025 |
|
5026 | return samples;
|
5027 | };
|
5028 |
|
5029 |
|
5030 | var concatenateNalData = function concatenateNalData(gops) {
|
5031 | var h,
|
5032 | i,
|
5033 | j,
|
5034 | currentGop,
|
5035 | currentFrame,
|
5036 | currentNal,
|
5037 | dataOffset = 0,
|
5038 | nalsByteLength = gops.byteLength,
|
5039 | numberOfNals = gops.nalCount,
|
5040 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
5041 | data = new Uint8Array(totalByteLength),
|
5042 | view = new DataView(data.buffer);
|
5043 |
|
5044 | for (h = 0; h < gops.length; h++) {
|
5045 | currentGop = gops[h];
|
5046 |
|
5047 | for (i = 0; i < currentGop.length; i++) {
|
5048 | currentFrame = currentGop[i];
|
5049 |
|
5050 | for (j = 0; j < currentFrame.length; j++) {
|
5051 | currentNal = currentFrame[j];
|
5052 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
5053 | dataOffset += 4;
|
5054 | data.set(currentNal.data, dataOffset);
|
5055 | dataOffset += currentNal.data.byteLength;
|
5056 | }
|
5057 | }
|
5058 | }
|
5059 |
|
5060 | return data;
|
5061 | };
|
5062 |
|
5063 |
|
5064 | var generateSampleTableForFrame = function generateSampleTableForFrame(frame, baseDataOffset) {
|
5065 | var sample,
|
5066 | dataOffset = baseDataOffset || 0,
|
5067 | samples = [];
|
5068 | sample = sampleForFrame(frame, dataOffset);
|
5069 | samples.push(sample);
|
5070 | return samples;
|
5071 | };
|
5072 |
|
5073 |
|
5074 | var concatenateNalDataForFrame = function concatenateNalDataForFrame(frame) {
|
5075 | var i,
|
5076 | currentNal,
|
5077 | dataOffset = 0,
|
5078 | nalsByteLength = frame.byteLength,
|
5079 | numberOfNals = frame.length,
|
5080 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
5081 | data = new Uint8Array(totalByteLength),
|
5082 | view = new DataView(data.buffer);
|
5083 |
|
5084 | for (i = 0; i < frame.length; i++) {
|
5085 | currentNal = frame[i];
|
5086 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
5087 | dataOffset += 4;
|
5088 | data.set(currentNal.data, dataOffset);
|
5089 | dataOffset += currentNal.data.byteLength;
|
5090 | }
|
5091 |
|
5092 | return data;
|
5093 | };
|
5094 |
|
5095 | var frameUtils = {
|
5096 | groupNalsIntoFrames: groupNalsIntoFrames,
|
5097 | groupFramesIntoGops: groupFramesIntoGops,
|
5098 | extendFirstKeyFrame: extendFirstKeyFrame,
|
5099 | generateSampleTable: generateSampleTable$1,
|
5100 | concatenateNalData: concatenateNalData,
|
5101 | generateSampleTableForFrame: generateSampleTableForFrame,
|
5102 | concatenateNalDataForFrame: concatenateNalDataForFrame
|
5103 | };
|
5104 | |
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 |
|
5111 | var highPrefix = [33, 16, 5, 32, 164, 27];
|
5112 | var lowPrefix = [33, 65, 108, 84, 1, 2, 4, 8, 168, 2, 4, 8, 17, 191, 252];
|
5113 |
|
5114 | var zeroFill = function zeroFill(count) {
|
5115 | var a = [];
|
5116 |
|
5117 | while (count--) {
|
5118 | a.push(0);
|
5119 | }
|
5120 |
|
5121 | return a;
|
5122 | };
|
5123 |
|
5124 | var makeTable = function makeTable(metaTable) {
|
5125 | return Object.keys(metaTable).reduce(function (obj, key) {
|
5126 | obj[key] = new Uint8Array(metaTable[key].reduce(function (arr, part) {
|
5127 | return arr.concat(part);
|
5128 | }, []));
|
5129 | return obj;
|
5130 | }, {});
|
5131 | };
|
5132 |
|
5133 | var silence;
|
5134 |
|
5135 | var silence_1 = function silence_1() {
|
5136 | if (!silence) {
|
5137 |
|
5138 | var coneOfSilence = {
|
5139 | 96000: [highPrefix, [227, 64], zeroFill(154), [56]],
|
5140 | 88200: [highPrefix, [231], zeroFill(170), [56]],
|
5141 | 64000: [highPrefix, [248, 192], zeroFill(240), [56]],
|
5142 | 48000: [highPrefix, [255, 192], zeroFill(268), [55, 148, 128], zeroFill(54), [112]],
|
5143 | 44100: [highPrefix, [255, 192], zeroFill(268), [55, 163, 128], zeroFill(84), [112]],
|
5144 | 32000: [highPrefix, [255, 192], zeroFill(268), [55, 234], zeroFill(226), [112]],
|
5145 | 24000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 112], zeroFill(126), [224]],
|
5146 | 16000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 255], zeroFill(269), [223, 108], zeroFill(195), [1, 192]],
|
5147 | 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]],
|
5148 | 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]],
|
5149 | 8000: [lowPrefix, zeroFill(268), [3, 121, 16], zeroFill(47), [7]]
|
5150 | };
|
5151 | silence = makeTable(coneOfSilence);
|
5152 | }
|
5153 |
|
5154 | return silence;
|
5155 | };
|
5156 | |
5157 |
|
5158 |
|
5159 |
|
5160 |
|
5161 |
|
5162 |
|
5163 |
|
5164 | var ONE_SECOND_IN_TS$4 = 90000,
|
5165 |
|
5166 | secondsToVideoTs,
|
5167 | secondsToAudioTs,
|
5168 | videoTsToSeconds,
|
5169 | audioTsToSeconds,
|
5170 | audioTsToVideoTs,
|
5171 | videoTsToAudioTs,
|
5172 | metadataTsToSeconds;
|
5173 |
|
5174 | secondsToVideoTs = function secondsToVideoTs(seconds) {
|
5175 | return seconds * ONE_SECOND_IN_TS$4;
|
5176 | };
|
5177 |
|
5178 | secondsToAudioTs = function secondsToAudioTs(seconds, sampleRate) {
|
5179 | return seconds * sampleRate;
|
5180 | };
|
5181 |
|
5182 | videoTsToSeconds = function videoTsToSeconds(timestamp) {
|
5183 | return timestamp / ONE_SECOND_IN_TS$4;
|
5184 | };
|
5185 |
|
5186 | audioTsToSeconds = function audioTsToSeconds(timestamp, sampleRate) {
|
5187 | return timestamp / sampleRate;
|
5188 | };
|
5189 |
|
5190 | audioTsToVideoTs = function audioTsToVideoTs(timestamp, sampleRate) {
|
5191 | return secondsToVideoTs(audioTsToSeconds(timestamp, sampleRate));
|
5192 | };
|
5193 |
|
5194 | videoTsToAudioTs = function videoTsToAudioTs(timestamp, sampleRate) {
|
5195 | return secondsToAudioTs(videoTsToSeconds(timestamp), sampleRate);
|
5196 | };
|
5197 | |
5198 |
|
5199 |
|
5200 |
|
5201 |
|
5202 |
|
5203 | metadataTsToSeconds = function metadataTsToSeconds(timestamp, timelineStartPts, keepOriginalTimestamps) {
|
5204 | return videoTsToSeconds(keepOriginalTimestamps ? timestamp : timestamp - timelineStartPts);
|
5205 | };
|
5206 |
|
5207 | var clock = {
|
5208 | ONE_SECOND_IN_TS: ONE_SECOND_IN_TS$4,
|
5209 | secondsToVideoTs: secondsToVideoTs,
|
5210 | secondsToAudioTs: secondsToAudioTs,
|
5211 | videoTsToSeconds: videoTsToSeconds,
|
5212 | audioTsToSeconds: audioTsToSeconds,
|
5213 | audioTsToVideoTs: audioTsToVideoTs,
|
5214 | videoTsToAudioTs: videoTsToAudioTs,
|
5215 | metadataTsToSeconds: metadataTsToSeconds
|
5216 | };
|
5217 | |
5218 |
|
5219 |
|
5220 |
|
5221 |
|
5222 |
|
5223 |
|
5224 | |
5225 |
|
5226 |
|
5227 |
|
5228 | var sumFrameByteLengths = function sumFrameByteLengths(array) {
|
5229 | var i,
|
5230 | currentObj,
|
5231 | sum = 0;
|
5232 |
|
5233 | for (i = 0; i < array.length; i++) {
|
5234 | currentObj = array[i];
|
5235 | sum += currentObj.data.byteLength;
|
5236 | }
|
5237 |
|
5238 | return sum;
|
5239 | };
|
5240 |
|
5241 |
|
5242 |
|
5243 | var prefixWithSilence = function prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime) {
|
5244 | var baseMediaDecodeTimeTs,
|
5245 | frameDuration = 0,
|
5246 | audioGapDuration = 0,
|
5247 | audioFillFrameCount = 0,
|
5248 | audioFillDuration = 0,
|
5249 | silentFrame,
|
5250 | i,
|
5251 | firstFrame;
|
5252 |
|
5253 | if (!frames.length) {
|
5254 | return;
|
5255 | }
|
5256 |
|
5257 | baseMediaDecodeTimeTs = clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate);
|
5258 |
|
5259 | frameDuration = Math.ceil(clock.ONE_SECOND_IN_TS / (track.samplerate / 1024));
|
5260 |
|
5261 | if (audioAppendStartTs && videoBaseMediaDecodeTime) {
|
5262 |
|
5263 | audioGapDuration = baseMediaDecodeTimeTs - Math.max(audioAppendStartTs, videoBaseMediaDecodeTime);
|
5264 |
|
5265 | audioFillFrameCount = Math.floor(audioGapDuration / frameDuration);
|
5266 | audioFillDuration = audioFillFrameCount * frameDuration;
|
5267 | }
|
5268 |
|
5269 |
|
5270 |
|
5271 | if (audioFillFrameCount < 1 || audioFillDuration > clock.ONE_SECOND_IN_TS / 2) {
|
5272 | return;
|
5273 | }
|
5274 |
|
5275 | silentFrame = silence_1()[track.samplerate];
|
5276 |
|
5277 | if (!silentFrame) {
|
5278 |
|
5279 |
|
5280 | silentFrame = frames[0].data;
|
5281 | }
|
5282 |
|
5283 | for (i = 0; i < audioFillFrameCount; i++) {
|
5284 | firstFrame = frames[0];
|
5285 | frames.splice(0, 0, {
|
5286 | data: silentFrame,
|
5287 | dts: firstFrame.dts - frameDuration,
|
5288 | pts: firstFrame.pts - frameDuration
|
5289 | });
|
5290 | }
|
5291 |
|
5292 | track.baseMediaDecodeTime -= Math.floor(clock.videoTsToAudioTs(audioFillDuration, track.samplerate));
|
5293 | return audioFillDuration;
|
5294 | };
|
5295 |
|
5296 |
|
5297 |
|
5298 |
|
5299 |
|
5300 | var trimAdtsFramesByEarliestDts = function trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts) {
|
5301 | if (track.minSegmentDts >= earliestAllowedDts) {
|
5302 | return adtsFrames;
|
5303 | }
|
5304 |
|
5305 |
|
5306 | track.minSegmentDts = Infinity;
|
5307 | return adtsFrames.filter(function (currentFrame) {
|
5308 |
|
5309 | if (currentFrame.dts >= earliestAllowedDts) {
|
5310 | track.minSegmentDts = Math.min(track.minSegmentDts, currentFrame.dts);
|
5311 | track.minSegmentPts = track.minSegmentDts;
|
5312 | return true;
|
5313 | }
|
5314 |
|
5315 |
|
5316 | return false;
|
5317 | });
|
5318 | };
|
5319 |
|
5320 |
|
5321 | var generateSampleTable = function generateSampleTable(frames) {
|
5322 | var i,
|
5323 | currentFrame,
|
5324 | samples = [];
|
5325 |
|
5326 | for (i = 0; i < frames.length; i++) {
|
5327 | currentFrame = frames[i];
|
5328 | samples.push({
|
5329 | size: currentFrame.data.byteLength,
|
5330 | duration: 1024
|
5331 |
|
5332 | });
|
5333 | }
|
5334 |
|
5335 | return samples;
|
5336 | };
|
5337 |
|
5338 |
|
5339 | var concatenateFrameData = function concatenateFrameData(frames) {
|
5340 | var i,
|
5341 | currentFrame,
|
5342 | dataOffset = 0,
|
5343 | data = new Uint8Array(sumFrameByteLengths(frames));
|
5344 |
|
5345 | for (i = 0; i < frames.length; i++) {
|
5346 | currentFrame = frames[i];
|
5347 | data.set(currentFrame.data, dataOffset);
|
5348 | dataOffset += currentFrame.data.byteLength;
|
5349 | }
|
5350 |
|
5351 | return data;
|
5352 | };
|
5353 |
|
5354 | var audioFrameUtils = {
|
5355 | prefixWithSilence: prefixWithSilence,
|
5356 | trimAdtsFramesByEarliestDts: trimAdtsFramesByEarliestDts,
|
5357 | generateSampleTable: generateSampleTable,
|
5358 | concatenateFrameData: concatenateFrameData
|
5359 | };
|
5360 | |
5361 |
|
5362 |
|
5363 |
|
5364 |
|
5365 |
|
5366 |
|
5367 | var ONE_SECOND_IN_TS$3 = clock.ONE_SECOND_IN_TS;
|
5368 | |
5369 |
|
5370 |
|
5371 |
|
5372 |
|
5373 |
|
5374 | var collectDtsInfo = function collectDtsInfo(track, data) {
|
5375 | if (typeof data.pts === 'number') {
|
5376 | if (track.timelineStartInfo.pts === undefined) {
|
5377 | track.timelineStartInfo.pts = data.pts;
|
5378 | }
|
5379 |
|
5380 | if (track.minSegmentPts === undefined) {
|
5381 | track.minSegmentPts = data.pts;
|
5382 | } else {
|
5383 | track.minSegmentPts = Math.min(track.minSegmentPts, data.pts);
|
5384 | }
|
5385 |
|
5386 | if (track.maxSegmentPts === undefined) {
|
5387 | track.maxSegmentPts = data.pts;
|
5388 | } else {
|
5389 | track.maxSegmentPts = Math.max(track.maxSegmentPts, data.pts);
|
5390 | }
|
5391 | }
|
5392 |
|
5393 | if (typeof data.dts === 'number') {
|
5394 | if (track.timelineStartInfo.dts === undefined) {
|
5395 | track.timelineStartInfo.dts = data.dts;
|
5396 | }
|
5397 |
|
5398 | if (track.minSegmentDts === undefined) {
|
5399 | track.minSegmentDts = data.dts;
|
5400 | } else {
|
5401 | track.minSegmentDts = Math.min(track.minSegmentDts, data.dts);
|
5402 | }
|
5403 |
|
5404 | if (track.maxSegmentDts === undefined) {
|
5405 | track.maxSegmentDts = data.dts;
|
5406 | } else {
|
5407 | track.maxSegmentDts = Math.max(track.maxSegmentDts, data.dts);
|
5408 | }
|
5409 | }
|
5410 | };
|
5411 | |
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 |
|
5417 | var clearDtsInfo = function clearDtsInfo(track) {
|
5418 | delete track.minSegmentDts;
|
5419 | delete track.maxSegmentDts;
|
5420 | delete track.minSegmentPts;
|
5421 | delete track.maxSegmentPts;
|
5422 | };
|
5423 | |
5424 |
|
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 | var calculateTrackBaseMediaDecodeTime = function calculateTrackBaseMediaDecodeTime(track, keepOriginalTimestamps) {
|
5434 | var baseMediaDecodeTime,
|
5435 | scale,
|
5436 | minSegmentDts = track.minSegmentDts;
|
5437 |
|
5438 | if (!keepOriginalTimestamps) {
|
5439 | minSegmentDts -= track.timelineStartInfo.dts;
|
5440 | }
|
5441 |
|
5442 |
|
5443 |
|
5444 | baseMediaDecodeTime = track.timelineStartInfo.baseMediaDecodeTime;
|
5445 |
|
5446 | baseMediaDecodeTime += minSegmentDts;
|
5447 |
|
5448 | baseMediaDecodeTime = Math.max(0, baseMediaDecodeTime);
|
5449 |
|
5450 | if (track.type === 'audio') {
|
5451 |
|
5452 |
|
5453 | scale = track.samplerate / ONE_SECOND_IN_TS$3;
|
5454 | baseMediaDecodeTime *= scale;
|
5455 | baseMediaDecodeTime = Math.floor(baseMediaDecodeTime);
|
5456 | }
|
5457 |
|
5458 | return baseMediaDecodeTime;
|
5459 | };
|
5460 |
|
5461 | var trackDecodeInfo = {
|
5462 | clearDtsInfo: clearDtsInfo,
|
5463 | calculateTrackBaseMediaDecodeTime: calculateTrackBaseMediaDecodeTime,
|
5464 | collectDtsInfo: collectDtsInfo
|
5465 | };
|
5466 | |
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 |
|
5481 |
|
5482 | var USER_DATA_REGISTERED_ITU_T_T35 = 4,
|
5483 | RBSP_TRAILING_BITS = 128;
|
5484 | |
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 | var parseSei = function parseSei(bytes) {
|
5494 | var i = 0,
|
5495 | result = {
|
5496 | payloadType: -1,
|
5497 | payloadSize: 0
|
5498 | },
|
5499 | payloadType = 0,
|
5500 | payloadSize = 0;
|
5501 |
|
5502 | while (i < bytes.byteLength) {
|
5503 |
|
5504 | if (bytes[i] === RBSP_TRAILING_BITS) {
|
5505 | break;
|
5506 | }
|
5507 |
|
5508 |
|
5509 | while (bytes[i] === 0xFF) {
|
5510 | payloadType += 255;
|
5511 | i++;
|
5512 | }
|
5513 |
|
5514 | payloadType += bytes[i++];
|
5515 |
|
5516 | while (bytes[i] === 0xFF) {
|
5517 | payloadSize += 255;
|
5518 | i++;
|
5519 | }
|
5520 |
|
5521 | payloadSize += bytes[i++];
|
5522 |
|
5523 |
|
5524 | if (!result.payload && payloadType === USER_DATA_REGISTERED_ITU_T_T35) {
|
5525 | var userIdentifier = String.fromCharCode(bytes[i + 3], bytes[i + 4], bytes[i + 5], bytes[i + 6]);
|
5526 |
|
5527 | if (userIdentifier === 'GA94') {
|
5528 | result.payloadType = payloadType;
|
5529 | result.payloadSize = payloadSize;
|
5530 | result.payload = bytes.subarray(i, i + payloadSize);
|
5531 | break;
|
5532 | } else {
|
5533 | result.payload = void 0;
|
5534 | }
|
5535 | }
|
5536 |
|
5537 |
|
5538 | i += payloadSize;
|
5539 | payloadType = 0;
|
5540 | payloadSize = 0;
|
5541 | }
|
5542 |
|
5543 | return result;
|
5544 | };
|
5545 |
|
5546 |
|
5547 | var parseUserData = function parseUserData(sei) {
|
5548 |
|
5549 |
|
5550 | if (sei.payload[0] !== 181) {
|
5551 | return null;
|
5552 | }
|
5553 |
|
5554 |
|
5555 | if ((sei.payload[1] << 8 | sei.payload[2]) !== 49) {
|
5556 | return null;
|
5557 | }
|
5558 |
|
5559 |
|
5560 | if (String.fromCharCode(sei.payload[3], sei.payload[4], sei.payload[5], sei.payload[6]) !== 'GA94') {
|
5561 | return null;
|
5562 | }
|
5563 |
|
5564 |
|
5565 | if (sei.payload[7] !== 0x03) {
|
5566 | return null;
|
5567 | }
|
5568 |
|
5569 |
|
5570 |
|
5571 | return sei.payload.subarray(8, sei.payload.length - 1);
|
5572 | };
|
5573 |
|
5574 |
|
5575 | var parseCaptionPackets = function parseCaptionPackets(pts, userData) {
|
5576 | var results = [],
|
5577 | i,
|
5578 | count,
|
5579 | offset,
|
5580 | data;
|
5581 |
|
5582 | if (!(userData[0] & 0x40)) {
|
5583 | return results;
|
5584 | }
|
5585 |
|
5586 |
|
5587 | count = userData[0] & 0x1f;
|
5588 |
|
5589 | for (i = 0; i < count; i++) {
|
5590 | offset = i * 3;
|
5591 | data = {
|
5592 | type: userData[offset + 2] & 0x03,
|
5593 | pts: pts
|
5594 | };
|
5595 |
|
5596 | if (userData[offset + 2] & 0x04) {
|
5597 | data.ccData = userData[offset + 3] << 8 | userData[offset + 4];
|
5598 | results.push(data);
|
5599 | }
|
5600 | }
|
5601 |
|
5602 | return results;
|
5603 | };
|
5604 |
|
5605 | var discardEmulationPreventionBytes$1 = function discardEmulationPreventionBytes(data) {
|
5606 | var length = data.byteLength,
|
5607 | emulationPreventionBytesPositions = [],
|
5608 | i = 1,
|
5609 | newLength,
|
5610 | newData;
|
5611 |
|
5612 | while (i < length - 2) {
|
5613 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
5614 | emulationPreventionBytesPositions.push(i + 2);
|
5615 | i += 2;
|
5616 | } else {
|
5617 | i++;
|
5618 | }
|
5619 | }
|
5620 |
|
5621 |
|
5622 |
|
5623 | if (emulationPreventionBytesPositions.length === 0) {
|
5624 | return data;
|
5625 | }
|
5626 |
|
5627 |
|
5628 | newLength = length - emulationPreventionBytesPositions.length;
|
5629 | newData = new Uint8Array(newLength);
|
5630 | var sourceIndex = 0;
|
5631 |
|
5632 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
5633 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
5634 |
|
5635 | sourceIndex++;
|
5636 |
|
5637 | emulationPreventionBytesPositions.shift();
|
5638 | }
|
5639 |
|
5640 | newData[i] = data[sourceIndex];
|
5641 | }
|
5642 |
|
5643 | return newData;
|
5644 | };
|
5645 |
|
5646 |
|
5647 | var captionPacketParser = {
|
5648 | parseSei: parseSei,
|
5649 | parseUserData: parseUserData,
|
5650 | parseCaptionPackets: parseCaptionPackets,
|
5651 | discardEmulationPreventionBytes: discardEmulationPreventionBytes$1,
|
5652 | USER_DATA_REGISTERED_ITU_T_T35: USER_DATA_REGISTERED_ITU_T_T35
|
5653 | };
|
5654 |
|
5655 |
|
5656 | var CaptionStream$1 = function CaptionStream(options) {
|
5657 | options = options || {};
|
5658 | CaptionStream.prototype.init.call(this);
|
5659 |
|
5660 | this.parse708captions_ = typeof options.parse708captions === 'boolean' ? options.parse708captions : true;
|
5661 | this.captionPackets_ = [];
|
5662 | this.ccStreams_ = [new Cea608Stream(0, 0),
|
5663 | new Cea608Stream(0, 1),
|
5664 | new Cea608Stream(1, 0),
|
5665 | new Cea608Stream(1, 1)
|
5666 | ];
|
5667 |
|
5668 | if (this.parse708captions_) {
|
5669 | this.cc708Stream_ = new Cea708Stream({
|
5670 | captionServices: options.captionServices
|
5671 | });
|
5672 | }
|
5673 |
|
5674 | this.reset();
|
5675 |
|
5676 | this.ccStreams_.forEach(function (cc) {
|
5677 | cc.on('data', this.trigger.bind(this, 'data'));
|
5678 | cc.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
5679 | cc.on('done', this.trigger.bind(this, 'done'));
|
5680 | }, this);
|
5681 |
|
5682 | if (this.parse708captions_) {
|
5683 | this.cc708Stream_.on('data', this.trigger.bind(this, 'data'));
|
5684 | this.cc708Stream_.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
5685 | this.cc708Stream_.on('done', this.trigger.bind(this, 'done'));
|
5686 | }
|
5687 | };
|
5688 |
|
5689 | CaptionStream$1.prototype = new stream();
|
5690 |
|
5691 | CaptionStream$1.prototype.push = function (event) {
|
5692 | var sei, userData, newCaptionPackets;
|
5693 |
|
5694 | if (event.nalUnitType !== 'sei_rbsp') {
|
5695 | return;
|
5696 | }
|
5697 |
|
5698 |
|
5699 | sei = captionPacketParser.parseSei(event.escapedRBSP);
|
5700 |
|
5701 | if (!sei.payload) {
|
5702 | return;
|
5703 | }
|
5704 |
|
5705 |
|
5706 | if (sei.payloadType !== captionPacketParser.USER_DATA_REGISTERED_ITU_T_T35) {
|
5707 | return;
|
5708 | }
|
5709 |
|
5710 |
|
5711 | userData = captionPacketParser.parseUserData(sei);
|
5712 |
|
5713 | if (!userData) {
|
5714 | return;
|
5715 | }
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 | if (event.dts < this.latestDts_) {
|
5726 |
|
5727 | this.ignoreNextEqualDts_ = true;
|
5728 | return;
|
5729 | } else if (event.dts === this.latestDts_ && this.ignoreNextEqualDts_) {
|
5730 | this.numSameDts_--;
|
5731 |
|
5732 | if (!this.numSameDts_) {
|
5733 |
|
5734 | this.ignoreNextEqualDts_ = false;
|
5735 | }
|
5736 |
|
5737 | return;
|
5738 | }
|
5739 |
|
5740 |
|
5741 | newCaptionPackets = captionPacketParser.parseCaptionPackets(event.pts, userData);
|
5742 | this.captionPackets_ = this.captionPackets_.concat(newCaptionPackets);
|
5743 |
|
5744 | if (this.latestDts_ !== event.dts) {
|
5745 | this.numSameDts_ = 0;
|
5746 | }
|
5747 |
|
5748 | this.numSameDts_++;
|
5749 | this.latestDts_ = event.dts;
|
5750 | };
|
5751 |
|
5752 | CaptionStream$1.prototype.flushCCStreams = function (flushType) {
|
5753 | this.ccStreams_.forEach(function (cc) {
|
5754 | return flushType === 'flush' ? cc.flush() : cc.partialFlush();
|
5755 | }, this);
|
5756 | };
|
5757 |
|
5758 | CaptionStream$1.prototype.flushStream = function (flushType) {
|
5759 |
|
5760 | if (!this.captionPackets_.length) {
|
5761 | this.flushCCStreams(flushType);
|
5762 | return;
|
5763 | }
|
5764 |
|
5765 |
|
5766 |
|
5767 | this.captionPackets_.forEach(function (elem, idx) {
|
5768 | elem.presortIndex = idx;
|
5769 | });
|
5770 |
|
5771 | this.captionPackets_.sort(function (a, b) {
|
5772 | if (a.pts === b.pts) {
|
5773 | return a.presortIndex - b.presortIndex;
|
5774 | }
|
5775 |
|
5776 | return a.pts - b.pts;
|
5777 | });
|
5778 | this.captionPackets_.forEach(function (packet) {
|
5779 | if (packet.type < 2) {
|
5780 |
|
5781 | this.dispatchCea608Packet(packet);
|
5782 | } else {
|
5783 |
|
5784 | this.dispatchCea708Packet(packet);
|
5785 | }
|
5786 | }, this);
|
5787 | this.captionPackets_.length = 0;
|
5788 | this.flushCCStreams(flushType);
|
5789 | };
|
5790 |
|
5791 | CaptionStream$1.prototype.flush = function () {
|
5792 | return this.flushStream('flush');
|
5793 | };
|
5794 |
|
5795 |
|
5796 | CaptionStream$1.prototype.partialFlush = function () {
|
5797 | return this.flushStream('partialFlush');
|
5798 | };
|
5799 |
|
5800 | CaptionStream$1.prototype.reset = function () {
|
5801 | this.latestDts_ = null;
|
5802 | this.ignoreNextEqualDts_ = false;
|
5803 | this.numSameDts_ = 0;
|
5804 | this.activeCea608Channel_ = [null, null];
|
5805 | this.ccStreams_.forEach(function (ccStream) {
|
5806 | ccStream.reset();
|
5807 | });
|
5808 | };
|
5809 |
|
5810 | |
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 | CaptionStream$1.prototype.dispatchCea608Packet = function (packet) {
|
5823 |
|
5824 | if (this.setsTextOrXDSActive(packet)) {
|
5825 | this.activeCea608Channel_[packet.type] = null;
|
5826 | } else if (this.setsChannel1Active(packet)) {
|
5827 | this.activeCea608Channel_[packet.type] = 0;
|
5828 | } else if (this.setsChannel2Active(packet)) {
|
5829 | this.activeCea608Channel_[packet.type] = 1;
|
5830 | }
|
5831 |
|
5832 | if (this.activeCea608Channel_[packet.type] === null) {
|
5833 |
|
5834 |
|
5835 |
|
5836 | return;
|
5837 | }
|
5838 |
|
5839 | this.ccStreams_[(packet.type << 1) + this.activeCea608Channel_[packet.type]].push(packet);
|
5840 | };
|
5841 |
|
5842 | CaptionStream$1.prototype.setsChannel1Active = function (packet) {
|
5843 | return (packet.ccData & 0x7800) === 0x1000;
|
5844 | };
|
5845 |
|
5846 | CaptionStream$1.prototype.setsChannel2Active = function (packet) {
|
5847 | return (packet.ccData & 0x7800) === 0x1800;
|
5848 | };
|
5849 |
|
5850 | CaptionStream$1.prototype.setsTextOrXDSActive = function (packet) {
|
5851 | return (packet.ccData & 0x7100) === 0x0100 || (packet.ccData & 0x78fe) === 0x102a || (packet.ccData & 0x78fe) === 0x182a;
|
5852 | };
|
5853 |
|
5854 | CaptionStream$1.prototype.dispatchCea708Packet = function (packet) {
|
5855 | if (this.parse708captions_) {
|
5856 | this.cc708Stream_.push(packet);
|
5857 | }
|
5858 | };
|
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 |
|
5878 | var CHARACTER_TRANSLATION_708 = {
|
5879 | 0x7f: 0x266a,
|
5880 |
|
5881 | 0x1020: 0x20,
|
5882 |
|
5883 | 0x1021: 0xa0,
|
5884 |
|
5885 | 0x1025: 0x2026,
|
5886 |
|
5887 | 0x102a: 0x0160,
|
5888 |
|
5889 | 0x102c: 0x0152,
|
5890 |
|
5891 | 0x1030: 0x2588,
|
5892 |
|
5893 | 0x1031: 0x2018,
|
5894 |
|
5895 | 0x1032: 0x2019,
|
5896 |
|
5897 | 0x1033: 0x201c,
|
5898 |
|
5899 | 0x1034: 0x201d,
|
5900 |
|
5901 | 0x1035: 0x2022,
|
5902 |
|
5903 | 0x1039: 0x2122,
|
5904 |
|
5905 | 0x103a: 0x0161,
|
5906 |
|
5907 | 0x103c: 0x0153,
|
5908 |
|
5909 | 0x103d: 0x2120,
|
5910 |
|
5911 | 0x103f: 0x0178,
|
5912 |
|
5913 | 0x1076: 0x215b,
|
5914 |
|
5915 | 0x1077: 0x215c,
|
5916 |
|
5917 | 0x1078: 0x215d,
|
5918 |
|
5919 | 0x1079: 0x215e,
|
5920 |
|
5921 | 0x107a: 0x23d0,
|
5922 |
|
5923 | 0x107b: 0x23a4,
|
5924 |
|
5925 | 0x107c: 0x23a3,
|
5926 |
|
5927 | 0x107d: 0x23af,
|
5928 |
|
5929 | 0x107e: 0x23a6,
|
5930 |
|
5931 | 0x107f: 0x23a1,
|
5932 |
|
5933 | 0x10a0: 0x3138
|
5934 |
|
5935 | };
|
5936 |
|
5937 | var get708CharFromCode = function get708CharFromCode(code) {
|
5938 | var newCode = CHARACTER_TRANSLATION_708[code] || code;
|
5939 |
|
5940 | if (code & 0x1000 && code === newCode) {
|
5941 |
|
5942 | return '';
|
5943 | }
|
5944 |
|
5945 | return String.fromCharCode(newCode);
|
5946 | };
|
5947 |
|
5948 | var within708TextBlock = function within708TextBlock(b) {
|
5949 | return 0x20 <= b && b <= 0x7f || 0xa0 <= b && b <= 0xff;
|
5950 | };
|
5951 |
|
5952 | var Cea708Window = function Cea708Window(windowNum) {
|
5953 | this.windowNum = windowNum;
|
5954 | this.reset();
|
5955 | };
|
5956 |
|
5957 | Cea708Window.prototype.reset = function () {
|
5958 | this.clearText();
|
5959 | this.pendingNewLine = false;
|
5960 | this.winAttr = {};
|
5961 | this.penAttr = {};
|
5962 | this.penLoc = {};
|
5963 | this.penColor = {};
|
5964 |
|
5965 |
|
5966 | this.visible = 0;
|
5967 | this.rowLock = 0;
|
5968 | this.columnLock = 0;
|
5969 | this.priority = 0;
|
5970 | this.relativePositioning = 0;
|
5971 | this.anchorVertical = 0;
|
5972 | this.anchorHorizontal = 0;
|
5973 | this.anchorPoint = 0;
|
5974 | this.rowCount = 1;
|
5975 | this.virtualRowCount = this.rowCount + 1;
|
5976 | this.columnCount = 41;
|
5977 | this.windowStyle = 0;
|
5978 | this.penStyle = 0;
|
5979 | };
|
5980 |
|
5981 | Cea708Window.prototype.getText = function () {
|
5982 | return this.rows.join('\n');
|
5983 | };
|
5984 |
|
5985 | Cea708Window.prototype.clearText = function () {
|
5986 | this.rows = [''];
|
5987 | this.rowIdx = 0;
|
5988 | };
|
5989 |
|
5990 | Cea708Window.prototype.newLine = function (pts) {
|
5991 | if (this.rows.length >= this.virtualRowCount && typeof this.beforeRowOverflow === 'function') {
|
5992 | this.beforeRowOverflow(pts);
|
5993 | }
|
5994 |
|
5995 | if (this.rows.length > 0) {
|
5996 | this.rows.push('');
|
5997 | this.rowIdx++;
|
5998 | }
|
5999 |
|
6000 |
|
6001 | while (this.rows.length > this.virtualRowCount) {
|
6002 | this.rows.shift();
|
6003 | this.rowIdx--;
|
6004 | }
|
6005 | };
|
6006 |
|
6007 | Cea708Window.prototype.isEmpty = function () {
|
6008 | if (this.rows.length === 0) {
|
6009 | return true;
|
6010 | } else if (this.rows.length === 1) {
|
6011 | return this.rows[0] === '';
|
6012 | }
|
6013 |
|
6014 | return false;
|
6015 | };
|
6016 |
|
6017 | Cea708Window.prototype.addText = function (text) {
|
6018 | this.rows[this.rowIdx] += text;
|
6019 | };
|
6020 |
|
6021 | Cea708Window.prototype.backspace = function () {
|
6022 | if (!this.isEmpty()) {
|
6023 | var row = this.rows[this.rowIdx];
|
6024 | this.rows[this.rowIdx] = row.substr(0, row.length - 1);
|
6025 | }
|
6026 | };
|
6027 |
|
6028 | var Cea708Service = function Cea708Service(serviceNum, encoding, stream) {
|
6029 | this.serviceNum = serviceNum;
|
6030 | this.text = '';
|
6031 | this.currentWindow = new Cea708Window(-1);
|
6032 | this.windows = [];
|
6033 | this.stream = stream;
|
6034 |
|
6035 | if (typeof encoding === 'string') {
|
6036 | this.createTextDecoder(encoding);
|
6037 | }
|
6038 | };
|
6039 | |
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 | Cea708Service.prototype.init = function (pts, beforeRowOverflow) {
|
6049 | this.startPts = pts;
|
6050 |
|
6051 | for (var win = 0; win < 8; win++) {
|
6052 | this.windows[win] = new Cea708Window(win);
|
6053 |
|
6054 | if (typeof beforeRowOverflow === 'function') {
|
6055 | this.windows[win].beforeRowOverflow = beforeRowOverflow;
|
6056 | }
|
6057 | }
|
6058 | };
|
6059 | |
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 | Cea708Service.prototype.setCurrentWindow = function (windowNum) {
|
6067 | this.currentWindow = this.windows[windowNum];
|
6068 | };
|
6069 | |
6070 |
|
6071 |
|
6072 |
|
6073 |
|
6074 | Cea708Service.prototype.createTextDecoder = function (encoding) {
|
6075 | if (typeof TextDecoder === 'undefined') {
|
6076 | this.stream.trigger('log', {
|
6077 | level: 'warn',
|
6078 | message: 'The `encoding` option is unsupported without TextDecoder support'
|
6079 | });
|
6080 | } else {
|
6081 | try {
|
6082 | this.textDecoder_ = new TextDecoder(encoding);
|
6083 | } catch (error) {
|
6084 | this.stream.trigger('log', {
|
6085 | level: 'warn',
|
6086 | message: 'TextDecoder could not be created with ' + encoding + ' encoding. ' + error
|
6087 | });
|
6088 | }
|
6089 | }
|
6090 | };
|
6091 |
|
6092 | var Cea708Stream = function Cea708Stream(options) {
|
6093 | options = options || {};
|
6094 | Cea708Stream.prototype.init.call(this);
|
6095 | var self = this;
|
6096 | var captionServices = options.captionServices || {};
|
6097 | var captionServiceEncodings = {};
|
6098 | var serviceProps;
|
6099 |
|
6100 | Object.keys(captionServices).forEach(function (serviceName) {
|
6101 | serviceProps = captionServices[serviceName];
|
6102 |
|
6103 | if (/^SERVICE/.test(serviceName)) {
|
6104 | captionServiceEncodings[serviceName] = serviceProps.encoding;
|
6105 | }
|
6106 | });
|
6107 | this.serviceEncodings = captionServiceEncodings;
|
6108 | this.current708Packet = null;
|
6109 | this.services = {};
|
6110 |
|
6111 | this.push = function (packet) {
|
6112 | if (packet.type === 3) {
|
6113 |
|
6114 | self.new708Packet();
|
6115 | self.add708Bytes(packet);
|
6116 | } else {
|
6117 | if (self.current708Packet === null) {
|
6118 |
|
6119 | self.new708Packet();
|
6120 | }
|
6121 |
|
6122 | self.add708Bytes(packet);
|
6123 | }
|
6124 | };
|
6125 | };
|
6126 |
|
6127 | Cea708Stream.prototype = new stream();
|
6128 | |
6129 |
|
6130 |
|
6131 |
|
6132 | Cea708Stream.prototype.new708Packet = function () {
|
6133 | if (this.current708Packet !== null) {
|
6134 | this.push708Packet();
|
6135 | }
|
6136 |
|
6137 | this.current708Packet = {
|
6138 | data: [],
|
6139 | ptsVals: []
|
6140 | };
|
6141 | };
|
6142 | |
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 | Cea708Stream.prototype.add708Bytes = function (packet) {
|
6148 | var data = packet.ccData;
|
6149 | var byte0 = data >>> 8;
|
6150 | var byte1 = data & 0xff;
|
6151 |
|
6152 |
|
6153 | this.current708Packet.ptsVals.push(packet.pts);
|
6154 | this.current708Packet.data.push(byte0);
|
6155 | this.current708Packet.data.push(byte1);
|
6156 | };
|
6157 | |
6158 |
|
6159 |
|
6160 |
|
6161 |
|
6162 | Cea708Stream.prototype.push708Packet = function () {
|
6163 | var packet708 = this.current708Packet;
|
6164 | var packetData = packet708.data;
|
6165 | var serviceNum = null;
|
6166 | var blockSize = null;
|
6167 | var i = 0;
|
6168 | var b = packetData[i++];
|
6169 | packet708.seq = b >> 6;
|
6170 | packet708.sizeCode = b & 0x3f;
|
6171 |
|
6172 | for (; i < packetData.length; i++) {
|
6173 | b = packetData[i++];
|
6174 | serviceNum = b >> 5;
|
6175 | blockSize = b & 0x1f;
|
6176 |
|
6177 | if (serviceNum === 7 && blockSize > 0) {
|
6178 |
|
6179 | b = packetData[i++];
|
6180 | serviceNum = b;
|
6181 | }
|
6182 |
|
6183 | this.pushServiceBlock(serviceNum, i, blockSize);
|
6184 |
|
6185 | if (blockSize > 0) {
|
6186 | i += blockSize - 1;
|
6187 | }
|
6188 | }
|
6189 | };
|
6190 | |
6191 |
|
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 |
|
6198 |
|
6199 |
|
6200 |
|
6201 |
|
6202 |
|
6203 |
|
6204 | Cea708Stream.prototype.pushServiceBlock = function (serviceNum, start, size) {
|
6205 | var b;
|
6206 | var i = start;
|
6207 | var packetData = this.current708Packet.data;
|
6208 | var service = this.services[serviceNum];
|
6209 |
|
6210 | if (!service) {
|
6211 | service = this.initService(serviceNum, i);
|
6212 | }
|
6213 |
|
6214 | for (; i < start + size && i < packetData.length; i++) {
|
6215 | b = packetData[i];
|
6216 |
|
6217 | if (within708TextBlock(b)) {
|
6218 | i = this.handleText(i, service);
|
6219 | } else if (b === 0x18) {
|
6220 | i = this.multiByteCharacter(i, service);
|
6221 | } else if (b === 0x10) {
|
6222 | i = this.extendedCommands(i, service);
|
6223 | } else if (0x80 <= b && b <= 0x87) {
|
6224 | i = this.setCurrentWindow(i, service);
|
6225 | } else if (0x98 <= b && b <= 0x9f) {
|
6226 | i = this.defineWindow(i, service);
|
6227 | } else if (b === 0x88) {
|
6228 | i = this.clearWindows(i, service);
|
6229 | } else if (b === 0x8c) {
|
6230 | i = this.deleteWindows(i, service);
|
6231 | } else if (b === 0x89) {
|
6232 | i = this.displayWindows(i, service);
|
6233 | } else if (b === 0x8a) {
|
6234 | i = this.hideWindows(i, service);
|
6235 | } else if (b === 0x8b) {
|
6236 | i = this.toggleWindows(i, service);
|
6237 | } else if (b === 0x97) {
|
6238 | i = this.setWindowAttributes(i, service);
|
6239 | } else if (b === 0x90) {
|
6240 | i = this.setPenAttributes(i, service);
|
6241 | } else if (b === 0x91) {
|
6242 | i = this.setPenColor(i, service);
|
6243 | } else if (b === 0x92) {
|
6244 | i = this.setPenLocation(i, service);
|
6245 | } else if (b === 0x8f) {
|
6246 | service = this.reset(i, service);
|
6247 | } else if (b === 0x08) {
|
6248 |
|
6249 | service.currentWindow.backspace();
|
6250 | } else if (b === 0x0c) {
|
6251 |
|
6252 | service.currentWindow.clearText();
|
6253 | } else if (b === 0x0d) {
|
6254 |
|
6255 | service.currentWindow.pendingNewLine = true;
|
6256 | } else if (b === 0x0e) {
|
6257 |
|
6258 | service.currentWindow.clearText();
|
6259 | } else if (b === 0x8d) {
|
6260 |
|
6261 | i++;
|
6262 | } else ;
|
6263 | }
|
6264 | };
|
6265 | |
6266 |
|
6267 |
|
6268 |
|
6269 |
|
6270 |
|
6271 |
|
6272 |
|
6273 |
|
6274 | Cea708Stream.prototype.extendedCommands = function (i, service) {
|
6275 | var packetData = this.current708Packet.data;
|
6276 | var b = packetData[++i];
|
6277 |
|
6278 | if (within708TextBlock(b)) {
|
6279 | i = this.handleText(i, service, {
|
6280 | isExtended: true
|
6281 | });
|
6282 | }
|
6283 |
|
6284 | return i;
|
6285 | };
|
6286 | |
6287 |
|
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 |
|
6294 | Cea708Stream.prototype.getPts = function (byteIndex) {
|
6295 |
|
6296 | return this.current708Packet.ptsVals[Math.floor(byteIndex / 2)];
|
6297 | };
|
6298 | |
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 |
|
6305 |
|
6306 | Cea708Stream.prototype.initService = function (serviceNum, i) {
|
6307 | var serviceName = 'SERVICE' + serviceNum;
|
6308 | var self = this;
|
6309 | var serviceName;
|
6310 | var encoding;
|
6311 |
|
6312 | if (serviceName in this.serviceEncodings) {
|
6313 | encoding = this.serviceEncodings[serviceName];
|
6314 | }
|
6315 |
|
6316 | this.services[serviceNum] = new Cea708Service(serviceNum, encoding, self);
|
6317 | this.services[serviceNum].init(this.getPts(i), function (pts) {
|
6318 | self.flushDisplayed(pts, self.services[serviceNum]);
|
6319 | });
|
6320 | return this.services[serviceNum];
|
6321 | };
|
6322 | |
6323 |
|
6324 |
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 |
|
6330 |
|
6331 | Cea708Stream.prototype.handleText = function (i, service, options) {
|
6332 | var isExtended = options && options.isExtended;
|
6333 | var isMultiByte = options && options.isMultiByte;
|
6334 | var packetData = this.current708Packet.data;
|
6335 | var extended = isExtended ? 0x1000 : 0x0000;
|
6336 | var currentByte = packetData[i];
|
6337 | var nextByte = packetData[i + 1];
|
6338 | var win = service.currentWindow;
|
6339 | var char;
|
6340 | var charCodeArray;
|
6341 |
|
6342 | if (service.textDecoder_ && !isExtended) {
|
6343 | if (isMultiByte) {
|
6344 | charCodeArray = [currentByte, nextByte];
|
6345 | i++;
|
6346 | } else {
|
6347 | charCodeArray = [currentByte];
|
6348 | }
|
6349 |
|
6350 | char = service.textDecoder_.decode(new Uint8Array(charCodeArray));
|
6351 | } else {
|
6352 | char = get708CharFromCode(extended | currentByte);
|
6353 | }
|
6354 |
|
6355 | if (win.pendingNewLine && !win.isEmpty()) {
|
6356 | win.newLine(this.getPts(i));
|
6357 | }
|
6358 |
|
6359 | win.pendingNewLine = false;
|
6360 | win.addText(char);
|
6361 | return i;
|
6362 | };
|
6363 | |
6364 |
|
6365 |
|
6366 |
|
6367 |
|
6368 |
|
6369 |
|
6370 |
|
6371 |
|
6372 | Cea708Stream.prototype.multiByteCharacter = function (i, service) {
|
6373 | var packetData = this.current708Packet.data;
|
6374 | var firstByte = packetData[i + 1];
|
6375 | var secondByte = packetData[i + 2];
|
6376 |
|
6377 | if (within708TextBlock(firstByte) && within708TextBlock(secondByte)) {
|
6378 | i = this.handleText(++i, service, {
|
6379 | isMultiByte: true
|
6380 | });
|
6381 | }
|
6382 |
|
6383 | return i;
|
6384 | };
|
6385 | |
6386 |
|
6387 |
|
6388 |
|
6389 |
|
6390 |
|
6391 |
|
6392 |
|
6393 |
|
6394 |
|
6395 |
|
6396 | Cea708Stream.prototype.setCurrentWindow = function (i, service) {
|
6397 | var packetData = this.current708Packet.data;
|
6398 | var b = packetData[i];
|
6399 | var windowNum = b & 0x07;
|
6400 | service.setCurrentWindow(windowNum);
|
6401 | return i;
|
6402 | };
|
6403 | |
6404 |
|
6405 |
|
6406 |
|
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 |
|
6414 | Cea708Stream.prototype.defineWindow = function (i, service) {
|
6415 | var packetData = this.current708Packet.data;
|
6416 | var b = packetData[i];
|
6417 | var windowNum = b & 0x07;
|
6418 | service.setCurrentWindow(windowNum);
|
6419 | var win = service.currentWindow;
|
6420 | b = packetData[++i];
|
6421 | win.visible = (b & 0x20) >> 5;
|
6422 |
|
6423 | win.rowLock = (b & 0x10) >> 4;
|
6424 |
|
6425 | win.columnLock = (b & 0x08) >> 3;
|
6426 |
|
6427 | win.priority = b & 0x07;
|
6428 |
|
6429 | b = packetData[++i];
|
6430 | win.relativePositioning = (b & 0x80) >> 7;
|
6431 |
|
6432 | win.anchorVertical = b & 0x7f;
|
6433 |
|
6434 | b = packetData[++i];
|
6435 | win.anchorHorizontal = b;
|
6436 |
|
6437 | b = packetData[++i];
|
6438 | win.anchorPoint = (b & 0xf0) >> 4;
|
6439 |
|
6440 | win.rowCount = b & 0x0f;
|
6441 |
|
6442 | b = packetData[++i];
|
6443 | win.columnCount = b & 0x3f;
|
6444 |
|
6445 | b = packetData[++i];
|
6446 | win.windowStyle = (b & 0x38) >> 3;
|
6447 |
|
6448 | win.penStyle = b & 0x07;
|
6449 |
|
6450 |
|
6451 | win.virtualRowCount = win.rowCount + 1;
|
6452 | return i;
|
6453 | };
|
6454 | |
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 |
|
6464 |
|
6465 | Cea708Stream.prototype.setWindowAttributes = function (i, service) {
|
6466 | var packetData = this.current708Packet.data;
|
6467 | var b = packetData[i];
|
6468 | var winAttr = service.currentWindow.winAttr;
|
6469 | b = packetData[++i];
|
6470 | winAttr.fillOpacity = (b & 0xc0) >> 6;
|
6471 |
|
6472 | winAttr.fillRed = (b & 0x30) >> 4;
|
6473 |
|
6474 | winAttr.fillGreen = (b & 0x0c) >> 2;
|
6475 |
|
6476 | winAttr.fillBlue = b & 0x03;
|
6477 |
|
6478 | b = packetData[++i];
|
6479 | winAttr.borderType = (b & 0xc0) >> 6;
|
6480 |
|
6481 | winAttr.borderRed = (b & 0x30) >> 4;
|
6482 |
|
6483 | winAttr.borderGreen = (b & 0x0c) >> 2;
|
6484 |
|
6485 | winAttr.borderBlue = b & 0x03;
|
6486 |
|
6487 | b = packetData[++i];
|
6488 | winAttr.borderType += (b & 0x80) >> 5;
|
6489 |
|
6490 | winAttr.wordWrap = (b & 0x40) >> 6;
|
6491 |
|
6492 | winAttr.printDirection = (b & 0x30) >> 4;
|
6493 |
|
6494 | winAttr.scrollDirection = (b & 0x0c) >> 2;
|
6495 |
|
6496 | winAttr.justify = b & 0x03;
|
6497 |
|
6498 | b = packetData[++i];
|
6499 | winAttr.effectSpeed = (b & 0xf0) >> 4;
|
6500 |
|
6501 | winAttr.effectDirection = (b & 0x0c) >> 2;
|
6502 |
|
6503 | winAttr.displayEffect = b & 0x03;
|
6504 |
|
6505 | return i;
|
6506 | };
|
6507 | |
6508 |
|
6509 |
|
6510 |
|
6511 |
|
6512 |
|
6513 |
|
6514 |
|
6515 | Cea708Stream.prototype.flushDisplayed = function (pts, service) {
|
6516 | var displayedText = [];
|
6517 |
|
6518 |
|
6519 | for (var winId = 0; winId < 8; winId++) {
|
6520 | if (service.windows[winId].visible && !service.windows[winId].isEmpty()) {
|
6521 | displayedText.push(service.windows[winId].getText());
|
6522 | }
|
6523 | }
|
6524 |
|
6525 | service.endPts = pts;
|
6526 | service.text = displayedText.join('\n\n');
|
6527 | this.pushCaption(service);
|
6528 | service.startPts = pts;
|
6529 | };
|
6530 | |
6531 |
|
6532 |
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 | Cea708Stream.prototype.pushCaption = function (service) {
|
6538 | if (service.text !== '') {
|
6539 | this.trigger('data', {
|
6540 | startPts: service.startPts,
|
6541 | endPts: service.endPts,
|
6542 | text: service.text,
|
6543 | stream: 'cc708_' + service.serviceNum
|
6544 | });
|
6545 | service.text = '';
|
6546 | service.startPts = service.endPts;
|
6547 | }
|
6548 | };
|
6549 | |
6550 |
|
6551 |
|
6552 |
|
6553 |
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 | Cea708Stream.prototype.displayWindows = function (i, service) {
|
6561 | var packetData = this.current708Packet.data;
|
6562 | var b = packetData[++i];
|
6563 | var pts = this.getPts(i);
|
6564 | this.flushDisplayed(pts, service);
|
6565 |
|
6566 | for (var winId = 0; winId < 8; winId++) {
|
6567 | if (b & 0x01 << winId) {
|
6568 | service.windows[winId].visible = 1;
|
6569 | }
|
6570 | }
|
6571 |
|
6572 | return i;
|
6573 | };
|
6574 | |
6575 |
|
6576 |
|
6577 |
|
6578 |
|
6579 |
|
6580 |
|
6581 |
|
6582 |
|
6583 |
|
6584 |
|
6585 | Cea708Stream.prototype.hideWindows = function (i, service) {
|
6586 | var packetData = this.current708Packet.data;
|
6587 | var b = packetData[++i];
|
6588 | var pts = this.getPts(i);
|
6589 | this.flushDisplayed(pts, service);
|
6590 |
|
6591 | for (var winId = 0; winId < 8; winId++) {
|
6592 | if (b & 0x01 << winId) {
|
6593 | service.windows[winId].visible = 0;
|
6594 | }
|
6595 | }
|
6596 |
|
6597 | return i;
|
6598 | };
|
6599 | |
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 |
|
6609 |
|
6610 | Cea708Stream.prototype.toggleWindows = function (i, service) {
|
6611 | var packetData = this.current708Packet.data;
|
6612 | var b = packetData[++i];
|
6613 | var pts = this.getPts(i);
|
6614 | this.flushDisplayed(pts, service);
|
6615 |
|
6616 | for (var winId = 0; winId < 8; winId++) {
|
6617 | if (b & 0x01 << winId) {
|
6618 | service.windows[winId].visible ^= 1;
|
6619 | }
|
6620 | }
|
6621 |
|
6622 | return i;
|
6623 | };
|
6624 | |
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 |
|
6633 |
|
6634 |
|
6635 | Cea708Stream.prototype.clearWindows = function (i, service) {
|
6636 | var packetData = this.current708Packet.data;
|
6637 | var b = packetData[++i];
|
6638 | var pts = this.getPts(i);
|
6639 | this.flushDisplayed(pts, service);
|
6640 |
|
6641 | for (var winId = 0; winId < 8; winId++) {
|
6642 | if (b & 0x01 << winId) {
|
6643 | service.windows[winId].clearText();
|
6644 | }
|
6645 | }
|
6646 |
|
6647 | return i;
|
6648 | };
|
6649 | |
6650 |
|
6651 |
|
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 |
|
6659 |
|
6660 | Cea708Stream.prototype.deleteWindows = function (i, service) {
|
6661 | var packetData = this.current708Packet.data;
|
6662 | var b = packetData[++i];
|
6663 | var pts = this.getPts(i);
|
6664 | this.flushDisplayed(pts, service);
|
6665 |
|
6666 | for (var winId = 0; winId < 8; winId++) {
|
6667 | if (b & 0x01 << winId) {
|
6668 | service.windows[winId].reset();
|
6669 | }
|
6670 | }
|
6671 |
|
6672 | return i;
|
6673 | };
|
6674 | |
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 | Cea708Stream.prototype.setPenAttributes = function (i, service) {
|
6686 | var packetData = this.current708Packet.data;
|
6687 | var b = packetData[i];
|
6688 | var penAttr = service.currentWindow.penAttr;
|
6689 | b = packetData[++i];
|
6690 | penAttr.textTag = (b & 0xf0) >> 4;
|
6691 |
|
6692 | penAttr.offset = (b & 0x0c) >> 2;
|
6693 |
|
6694 | penAttr.penSize = b & 0x03;
|
6695 |
|
6696 | b = packetData[++i];
|
6697 | penAttr.italics = (b & 0x80) >> 7;
|
6698 |
|
6699 | penAttr.underline = (b & 0x40) >> 6;
|
6700 |
|
6701 | penAttr.edgeType = (b & 0x38) >> 3;
|
6702 |
|
6703 | penAttr.fontStyle = b & 0x07;
|
6704 |
|
6705 | return i;
|
6706 | };
|
6707 | |
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 | Cea708Stream.prototype.setPenColor = function (i, service) {
|
6719 | var packetData = this.current708Packet.data;
|
6720 | var b = packetData[i];
|
6721 | var penColor = service.currentWindow.penColor;
|
6722 | b = packetData[++i];
|
6723 | penColor.fgOpacity = (b & 0xc0) >> 6;
|
6724 |
|
6725 | penColor.fgRed = (b & 0x30) >> 4;
|
6726 |
|
6727 | penColor.fgGreen = (b & 0x0c) >> 2;
|
6728 |
|
6729 | penColor.fgBlue = b & 0x03;
|
6730 |
|
6731 | b = packetData[++i];
|
6732 | penColor.bgOpacity = (b & 0xc0) >> 6;
|
6733 |
|
6734 | penColor.bgRed = (b & 0x30) >> 4;
|
6735 |
|
6736 | penColor.bgGreen = (b & 0x0c) >> 2;
|
6737 |
|
6738 | penColor.bgBlue = b & 0x03;
|
6739 |
|
6740 | b = packetData[++i];
|
6741 | penColor.edgeRed = (b & 0x30) >> 4;
|
6742 |
|
6743 | penColor.edgeGreen = (b & 0x0c) >> 2;
|
6744 |
|
6745 | penColor.edgeBlue = b & 0x03;
|
6746 |
|
6747 | return i;
|
6748 | };
|
6749 | |
6750 |
|
6751 |
|
6752 |
|
6753 |
|
6754 |
|
6755 |
|
6756 |
|
6757 |
|
6758 |
|
6759 |
|
6760 | Cea708Stream.prototype.setPenLocation = function (i, service) {
|
6761 | var packetData = this.current708Packet.data;
|
6762 | var b = packetData[i];
|
6763 | var penLoc = service.currentWindow.penLoc;
|
6764 |
|
6765 | service.currentWindow.pendingNewLine = true;
|
6766 | b = packetData[++i];
|
6767 | penLoc.row = b & 0x0f;
|
6768 |
|
6769 | b = packetData[++i];
|
6770 | penLoc.column = b & 0x3f;
|
6771 |
|
6772 | return i;
|
6773 | };
|
6774 | |
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 | Cea708Stream.prototype.reset = function (i, service) {
|
6786 | var pts = this.getPts(i);
|
6787 | this.flushDisplayed(pts, service);
|
6788 | return this.initService(service.serviceNum, i);
|
6789 | };
|
6790 |
|
6791 |
|
6792 |
|
6793 |
|
6794 |
|
6795 |
|
6796 |
|
6797 |
|
6798 | var CHARACTER_TRANSLATION = {
|
6799 | 0x2a: 0xe1,
|
6800 |
|
6801 | 0x5c: 0xe9,
|
6802 |
|
6803 | 0x5e: 0xed,
|
6804 |
|
6805 | 0x5f: 0xf3,
|
6806 |
|
6807 | 0x60: 0xfa,
|
6808 |
|
6809 | 0x7b: 0xe7,
|
6810 |
|
6811 | 0x7c: 0xf7,
|
6812 |
|
6813 | 0x7d: 0xd1,
|
6814 |
|
6815 | 0x7e: 0xf1,
|
6816 |
|
6817 | 0x7f: 0x2588,
|
6818 |
|
6819 | 0x0130: 0xae,
|
6820 |
|
6821 | 0x0131: 0xb0,
|
6822 |
|
6823 | 0x0132: 0xbd,
|
6824 |
|
6825 | 0x0133: 0xbf,
|
6826 |
|
6827 | 0x0134: 0x2122,
|
6828 |
|
6829 | 0x0135: 0xa2,
|
6830 |
|
6831 | 0x0136: 0xa3,
|
6832 |
|
6833 | 0x0137: 0x266a,
|
6834 |
|
6835 | 0x0138: 0xe0,
|
6836 |
|
6837 | 0x0139: 0xa0,
|
6838 |
|
6839 | 0x013a: 0xe8,
|
6840 |
|
6841 | 0x013b: 0xe2,
|
6842 |
|
6843 | 0x013c: 0xea,
|
6844 |
|
6845 | 0x013d: 0xee,
|
6846 |
|
6847 | 0x013e: 0xf4,
|
6848 |
|
6849 | 0x013f: 0xfb,
|
6850 |
|
6851 | 0x0220: 0xc1,
|
6852 |
|
6853 | 0x0221: 0xc9,
|
6854 |
|
6855 | 0x0222: 0xd3,
|
6856 |
|
6857 | 0x0223: 0xda,
|
6858 |
|
6859 | 0x0224: 0xdc,
|
6860 |
|
6861 | 0x0225: 0xfc,
|
6862 |
|
6863 | 0x0226: 0x2018,
|
6864 |
|
6865 | 0x0227: 0xa1,
|
6866 |
|
6867 | 0x0228: 0x2a,
|
6868 |
|
6869 | 0x0229: 0x27,
|
6870 |
|
6871 | 0x022a: 0x2014,
|
6872 |
|
6873 | 0x022b: 0xa9,
|
6874 |
|
6875 | 0x022c: 0x2120,
|
6876 |
|
6877 | 0x022d: 0x2022,
|
6878 |
|
6879 | 0x022e: 0x201c,
|
6880 |
|
6881 | 0x022f: 0x201d,
|
6882 |
|
6883 | 0x0230: 0xc0,
|
6884 |
|
6885 | 0x0231: 0xc2,
|
6886 |
|
6887 | 0x0232: 0xc7,
|
6888 |
|
6889 | 0x0233: 0xc8,
|
6890 |
|
6891 | 0x0234: 0xca,
|
6892 |
|
6893 | 0x0235: 0xcb,
|
6894 |
|
6895 | 0x0236: 0xeb,
|
6896 |
|
6897 | 0x0237: 0xce,
|
6898 |
|
6899 | 0x0238: 0xcf,
|
6900 |
|
6901 | 0x0239: 0xef,
|
6902 |
|
6903 | 0x023a: 0xd4,
|
6904 |
|
6905 | 0x023b: 0xd9,
|
6906 |
|
6907 | 0x023c: 0xf9,
|
6908 |
|
6909 | 0x023d: 0xdb,
|
6910 |
|
6911 | 0x023e: 0xab,
|
6912 |
|
6913 | 0x023f: 0xbb,
|
6914 |
|
6915 | 0x0320: 0xc3,
|
6916 |
|
6917 | 0x0321: 0xe3,
|
6918 |
|
6919 | 0x0322: 0xcd,
|
6920 |
|
6921 | 0x0323: 0xcc,
|
6922 |
|
6923 | 0x0324: 0xec,
|
6924 |
|
6925 | 0x0325: 0xd2,
|
6926 |
|
6927 | 0x0326: 0xf2,
|
6928 |
|
6929 | 0x0327: 0xd5,
|
6930 |
|
6931 | 0x0328: 0xf5,
|
6932 |
|
6933 | 0x0329: 0x7b,
|
6934 |
|
6935 | 0x032a: 0x7d,
|
6936 |
|
6937 | 0x032b: 0x5c,
|
6938 |
|
6939 | 0x032c: 0x5e,
|
6940 |
|
6941 | 0x032d: 0x5f,
|
6942 |
|
6943 | 0x032e: 0x7c,
|
6944 |
|
6945 | 0x032f: 0x7e,
|
6946 |
|
6947 | 0x0330: 0xc4,
|
6948 |
|
6949 | 0x0331: 0xe4,
|
6950 |
|
6951 | 0x0332: 0xd6,
|
6952 |
|
6953 | 0x0333: 0xf6,
|
6954 |
|
6955 | 0x0334: 0xdf,
|
6956 |
|
6957 | 0x0335: 0xa5,
|
6958 |
|
6959 | 0x0336: 0xa4,
|
6960 |
|
6961 | 0x0337: 0x2502,
|
6962 |
|
6963 | 0x0338: 0xc5,
|
6964 |
|
6965 | 0x0339: 0xe5,
|
6966 |
|
6967 | 0x033a: 0xd8,
|
6968 |
|
6969 | 0x033b: 0xf8,
|
6970 |
|
6971 | 0x033c: 0x250c,
|
6972 |
|
6973 | 0x033d: 0x2510,
|
6974 |
|
6975 | 0x033e: 0x2514,
|
6976 |
|
6977 | 0x033f: 0x2518
|
6978 |
|
6979 | };
|
6980 |
|
6981 | var getCharFromCode = function getCharFromCode(code) {
|
6982 | if (code === null) {
|
6983 | return '';
|
6984 | }
|
6985 |
|
6986 | code = CHARACTER_TRANSLATION[code] || code;
|
6987 | return String.fromCharCode(code);
|
6988 | };
|
6989 |
|
6990 |
|
6991 | var BOTTOM_ROW = 14;
|
6992 |
|
6993 |
|
6994 | var ROWS = [0x1100, 0x1120, 0x1200, 0x1220, 0x1500, 0x1520, 0x1600, 0x1620, 0x1700, 0x1720, 0x1000, 0x1300, 0x1320, 0x1400, 0x1420];
|
6995 |
|
6996 |
|
6997 | var createDisplayBuffer = function createDisplayBuffer() {
|
6998 | var result = [],
|
6999 | i = BOTTOM_ROW + 1;
|
7000 |
|
7001 | while (i--) {
|
7002 | result.push('');
|
7003 | }
|
7004 |
|
7005 | return result;
|
7006 | };
|
7007 |
|
7008 | var Cea608Stream = function Cea608Stream(field, dataChannel) {
|
7009 | Cea608Stream.prototype.init.call(this);
|
7010 | this.field_ = field || 0;
|
7011 | this.dataChannel_ = dataChannel || 0;
|
7012 | this.name_ = 'CC' + ((this.field_ << 1 | this.dataChannel_) + 1);
|
7013 | this.setConstants();
|
7014 | this.reset();
|
7015 |
|
7016 | this.push = function (packet) {
|
7017 | var data, swap, char0, char1, text;
|
7018 |
|
7019 | data = packet.ccData & 0x7f7f;
|
7020 |
|
7021 | if (data === this.lastControlCode_) {
|
7022 | this.lastControlCode_ = null;
|
7023 | return;
|
7024 | }
|
7025 |
|
7026 |
|
7027 | if ((data & 0xf000) === 0x1000) {
|
7028 | this.lastControlCode_ = data;
|
7029 | } else if (data !== this.PADDING_) {
|
7030 | this.lastControlCode_ = null;
|
7031 | }
|
7032 |
|
7033 | char0 = data >>> 8;
|
7034 | char1 = data & 0xff;
|
7035 |
|
7036 | if (data === this.PADDING_) {
|
7037 | return;
|
7038 | } else if (data === this.RESUME_CAPTION_LOADING_) {
|
7039 | this.mode_ = 'popOn';
|
7040 | } else if (data === this.END_OF_CAPTION_) {
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 | this.mode_ = 'popOn';
|
7046 | this.clearFormatting(packet.pts);
|
7047 |
|
7048 | this.flushDisplayed(packet.pts);
|
7049 |
|
7050 | swap = this.displayed_;
|
7051 | this.displayed_ = this.nonDisplayed_;
|
7052 | this.nonDisplayed_ = swap;
|
7053 |
|
7054 | this.startPts_ = packet.pts;
|
7055 | } else if (data === this.ROLL_UP_2_ROWS_) {
|
7056 | this.rollUpRows_ = 2;
|
7057 | this.setRollUp(packet.pts);
|
7058 | } else if (data === this.ROLL_UP_3_ROWS_) {
|
7059 | this.rollUpRows_ = 3;
|
7060 | this.setRollUp(packet.pts);
|
7061 | } else if (data === this.ROLL_UP_4_ROWS_) {
|
7062 | this.rollUpRows_ = 4;
|
7063 | this.setRollUp(packet.pts);
|
7064 | } else if (data === this.CARRIAGE_RETURN_) {
|
7065 | this.clearFormatting(packet.pts);
|
7066 | this.flushDisplayed(packet.pts);
|
7067 | this.shiftRowsUp_();
|
7068 | this.startPts_ = packet.pts;
|
7069 | } else if (data === this.BACKSPACE_) {
|
7070 | if (this.mode_ === 'popOn') {
|
7071 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
7072 | } else {
|
7073 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
7074 | }
|
7075 | } else if (data === this.ERASE_DISPLAYED_MEMORY_) {
|
7076 | this.flushDisplayed(packet.pts);
|
7077 | this.displayed_ = createDisplayBuffer();
|
7078 | } else if (data === this.ERASE_NON_DISPLAYED_MEMORY_) {
|
7079 | this.nonDisplayed_ = createDisplayBuffer();
|
7080 | } else if (data === this.RESUME_DIRECT_CAPTIONING_) {
|
7081 | if (this.mode_ !== 'paintOn') {
|
7082 |
|
7083 |
|
7084 | this.flushDisplayed(packet.pts);
|
7085 | this.displayed_ = createDisplayBuffer();
|
7086 | }
|
7087 |
|
7088 | this.mode_ = 'paintOn';
|
7089 | this.startPts_ = packet.pts;
|
7090 | } else if (this.isSpecialCharacter(char0, char1)) {
|
7091 |
|
7092 |
|
7093 |
|
7094 |
|
7095 | char0 = (char0 & 0x03) << 8;
|
7096 | text = getCharFromCode(char0 | char1);
|
7097 | this[this.mode_](packet.pts, text);
|
7098 | this.column_++;
|
7099 | } else if (this.isExtCharacter(char0, char1)) {
|
7100 |
|
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 | if (this.mode_ === 'popOn') {
|
7106 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
7107 | } else {
|
7108 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
7109 | }
|
7110 |
|
7111 |
|
7112 |
|
7113 |
|
7114 |
|
7115 | char0 = (char0 & 0x03) << 8;
|
7116 | text = getCharFromCode(char0 | char1);
|
7117 | this[this.mode_](packet.pts, text);
|
7118 | this.column_++;
|
7119 | } else if (this.isMidRowCode(char0, char1)) {
|
7120 |
|
7121 | this.clearFormatting(packet.pts);
|
7122 |
|
7123 |
|
7124 | this[this.mode_](packet.pts, ' ');
|
7125 | this.column_++;
|
7126 |
|
7127 | if ((char1 & 0xe) === 0xe) {
|
7128 | this.addFormatting(packet.pts, ['i']);
|
7129 | }
|
7130 |
|
7131 | if ((char1 & 0x1) === 0x1) {
|
7132 | this.addFormatting(packet.pts, ['u']);
|
7133 | }
|
7134 |
|
7135 | } else if (this.isOffsetControlCode(char0, char1)) {
|
7136 |
|
7137 |
|
7138 |
|
7139 |
|
7140 | this.column_ += char1 & 0x03;
|
7141 | } else if (this.isPAC(char0, char1)) {
|
7142 |
|
7143 |
|
7144 | var row = ROWS.indexOf(data & 0x1f20);
|
7145 |
|
7146 | if (this.mode_ === 'rollUp') {
|
7147 |
|
7148 |
|
7149 |
|
7150 | if (row - this.rollUpRows_ + 1 < 0) {
|
7151 | row = this.rollUpRows_ - 1;
|
7152 | }
|
7153 |
|
7154 | this.setRollUp(packet.pts, row);
|
7155 | }
|
7156 |
|
7157 | if (row !== this.row_) {
|
7158 |
|
7159 | this.clearFormatting(packet.pts);
|
7160 | this.row_ = row;
|
7161 | }
|
7162 |
|
7163 |
|
7164 |
|
7165 | if (char1 & 0x1 && this.formatting_.indexOf('u') === -1) {
|
7166 | this.addFormatting(packet.pts, ['u']);
|
7167 | }
|
7168 |
|
7169 | if ((data & 0x10) === 0x10) {
|
7170 |
|
7171 |
|
7172 |
|
7173 |
|
7174 | this.column_ = ((data & 0xe) >> 1) * 4;
|
7175 | }
|
7176 |
|
7177 | if (this.isColorPAC(char1)) {
|
7178 |
|
7179 |
|
7180 |
|
7181 |
|
7182 | if ((char1 & 0xe) === 0xe) {
|
7183 | this.addFormatting(packet.pts, ['i']);
|
7184 | }
|
7185 | }
|
7186 |
|
7187 | } else if (this.isNormalChar(char0)) {
|
7188 | if (char1 === 0x00) {
|
7189 | char1 = null;
|
7190 | }
|
7191 |
|
7192 | text = getCharFromCode(char0);
|
7193 | text += getCharFromCode(char1);
|
7194 | this[this.mode_](packet.pts, text);
|
7195 | this.column_ += text.length;
|
7196 | }
|
7197 |
|
7198 | };
|
7199 | };
|
7200 |
|
7201 | Cea608Stream.prototype = new stream();
|
7202 |
|
7203 |
|
7204 | Cea608Stream.prototype.flushDisplayed = function (pts) {
|
7205 | var content = this.displayed_
|
7206 | .map(function (row, index) {
|
7207 | try {
|
7208 | return row.trim();
|
7209 | } catch (e) {
|
7210 |
|
7211 |
|
7212 |
|
7213 | this.trigger('log', {
|
7214 | level: 'warn',
|
7215 | message: 'Skipping a malformed 608 caption at index ' + index + '.'
|
7216 | });
|
7217 | return '';
|
7218 | }
|
7219 | }, this)
|
7220 | .join('\n')
|
7221 | .replace(/^\n+|\n+$/g, '');
|
7222 |
|
7223 | if (content.length) {
|
7224 | this.trigger('data', {
|
7225 | startPts: this.startPts_,
|
7226 | endPts: pts,
|
7227 | text: content,
|
7228 | stream: this.name_
|
7229 | });
|
7230 | }
|
7231 | };
|
7232 | |
7233 |
|
7234 |
|
7235 |
|
7236 |
|
7237 | Cea608Stream.prototype.reset = function () {
|
7238 | this.mode_ = 'popOn';
|
7239 |
|
7240 |
|
7241 |
|
7242 |
|
7243 | this.topRow_ = 0;
|
7244 | this.startPts_ = 0;
|
7245 | this.displayed_ = createDisplayBuffer();
|
7246 | this.nonDisplayed_ = createDisplayBuffer();
|
7247 | this.lastControlCode_ = null;
|
7248 |
|
7249 | this.column_ = 0;
|
7250 | this.row_ = BOTTOM_ROW;
|
7251 | this.rollUpRows_ = 2;
|
7252 |
|
7253 | this.formatting_ = [];
|
7254 | };
|
7255 | |
7256 |
|
7257 |
|
7258 |
|
7259 |
|
7260 | Cea608Stream.prototype.setConstants = function () {
|
7261 |
|
7262 |
|
7263 |
|
7264 |
|
7265 |
|
7266 |
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 |
|
7272 |
|
7273 | if (this.dataChannel_ === 0) {
|
7274 | this.BASE_ = 0x10;
|
7275 | this.EXT_ = 0x11;
|
7276 | this.CONTROL_ = (0x14 | this.field_) << 8;
|
7277 | this.OFFSET_ = 0x17;
|
7278 | } else if (this.dataChannel_ === 1) {
|
7279 | this.BASE_ = 0x18;
|
7280 | this.EXT_ = 0x19;
|
7281 | this.CONTROL_ = (0x1c | this.field_) << 8;
|
7282 | this.OFFSET_ = 0x1f;
|
7283 | }
|
7284 |
|
7285 |
|
7286 |
|
7287 |
|
7288 |
|
7289 | this.PADDING_ = 0x0000;
|
7290 |
|
7291 | this.RESUME_CAPTION_LOADING_ = this.CONTROL_ | 0x20;
|
7292 | this.END_OF_CAPTION_ = this.CONTROL_ | 0x2f;
|
7293 |
|
7294 | this.ROLL_UP_2_ROWS_ = this.CONTROL_ | 0x25;
|
7295 | this.ROLL_UP_3_ROWS_ = this.CONTROL_ | 0x26;
|
7296 | this.ROLL_UP_4_ROWS_ = this.CONTROL_ | 0x27;
|
7297 | this.CARRIAGE_RETURN_ = this.CONTROL_ | 0x2d;
|
7298 |
|
7299 | this.RESUME_DIRECT_CAPTIONING_ = this.CONTROL_ | 0x29;
|
7300 |
|
7301 | this.BACKSPACE_ = this.CONTROL_ | 0x21;
|
7302 | this.ERASE_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2c;
|
7303 | this.ERASE_NON_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2e;
|
7304 | };
|
7305 | |
7306 |
|
7307 |
|
7308 |
|
7309 |
|
7310 |
|
7311 |
|
7312 |
|
7313 |
|
7314 |
|
7315 |
|
7316 |
|
7317 |
|
7318 | Cea608Stream.prototype.isSpecialCharacter = function (char0, char1) {
|
7319 | return char0 === this.EXT_ && char1 >= 0x30 && char1 <= 0x3f;
|
7320 | };
|
7321 | |
7322 |
|
7323 |
|
7324 |
|
7325 |
|
7326 |
|
7327 |
|
7328 |
|
7329 |
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 | Cea608Stream.prototype.isExtCharacter = function (char0, char1) {
|
7335 | return (char0 === this.EXT_ + 1 || char0 === this.EXT_ + 2) && char1 >= 0x20 && char1 <= 0x3f;
|
7336 | };
|
7337 | |
7338 |
|
7339 |
|
7340 |
|
7341 |
|
7342 |
|
7343 |
|
7344 |
|
7345 |
|
7346 |
|
7347 |
|
7348 |
|
7349 |
|
7350 | Cea608Stream.prototype.isMidRowCode = function (char0, char1) {
|
7351 | return char0 === this.EXT_ && char1 >= 0x20 && char1 <= 0x2f;
|
7352 | };
|
7353 | |
7354 |
|
7355 |
|
7356 |
|
7357 |
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 |
|
7363 |
|
7364 |
|
7365 |
|
7366 | Cea608Stream.prototype.isOffsetControlCode = function (char0, char1) {
|
7367 | return char0 === this.OFFSET_ && char1 >= 0x21 && char1 <= 0x23;
|
7368 | };
|
7369 | |
7370 |
|
7371 |
|
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 | Cea608Stream.prototype.isPAC = function (char0, char1) {
|
7383 | return char0 >= this.BASE_ && char0 < this.BASE_ + 8 && char1 >= 0x40 && char1 <= 0x7f;
|
7384 | };
|
7385 | |
7386 |
|
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 |
|
7394 |
|
7395 |
|
7396 | Cea608Stream.prototype.isColorPAC = function (char1) {
|
7397 | return char1 >= 0x40 && char1 <= 0x4f || char1 >= 0x60 && char1 <= 0x7f;
|
7398 | };
|
7399 | |
7400 |
|
7401 |
|
7402 |
|
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 |
|
7408 |
|
7409 | Cea608Stream.prototype.isNormalChar = function (char) {
|
7410 | return char >= 0x20 && char <= 0x7f;
|
7411 | };
|
7412 | |
7413 |
|
7414 |
|
7415 |
|
7416 |
|
7417 |
|
7418 |
|
7419 |
|
7420 |
|
7421 | Cea608Stream.prototype.setRollUp = function (pts, newBaseRow) {
|
7422 |
|
7423 | if (this.mode_ !== 'rollUp') {
|
7424 | this.row_ = BOTTOM_ROW;
|
7425 | this.mode_ = 'rollUp';
|
7426 |
|
7427 | this.flushDisplayed(pts);
|
7428 | this.nonDisplayed_ = createDisplayBuffer();
|
7429 | this.displayed_ = createDisplayBuffer();
|
7430 | }
|
7431 |
|
7432 | if (newBaseRow !== undefined && newBaseRow !== this.row_) {
|
7433 |
|
7434 | for (var i = 0; i < this.rollUpRows_; i++) {
|
7435 | this.displayed_[newBaseRow - i] = this.displayed_[this.row_ - i];
|
7436 | this.displayed_[this.row_ - i] = '';
|
7437 | }
|
7438 | }
|
7439 |
|
7440 | if (newBaseRow === undefined) {
|
7441 | newBaseRow = this.row_;
|
7442 | }
|
7443 |
|
7444 | this.topRow_ = newBaseRow - this.rollUpRows_ + 1;
|
7445 | };
|
7446 |
|
7447 |
|
7448 |
|
7449 | Cea608Stream.prototype.addFormatting = function (pts, format) {
|
7450 | this.formatting_ = this.formatting_.concat(format);
|
7451 | var text = format.reduce(function (text, format) {
|
7452 | return text + '<' + format + '>';
|
7453 | }, '');
|
7454 | this[this.mode_](pts, text);
|
7455 | };
|
7456 |
|
7457 |
|
7458 |
|
7459 | Cea608Stream.prototype.clearFormatting = function (pts) {
|
7460 | if (!this.formatting_.length) {
|
7461 | return;
|
7462 | }
|
7463 |
|
7464 | var text = this.formatting_.reverse().reduce(function (text, format) {
|
7465 | return text + '</' + format + '>';
|
7466 | }, '');
|
7467 | this.formatting_ = [];
|
7468 | this[this.mode_](pts, text);
|
7469 | };
|
7470 |
|
7471 |
|
7472 | Cea608Stream.prototype.popOn = function (pts, text) {
|
7473 | var baseRow = this.nonDisplayed_[this.row_];
|
7474 |
|
7475 | baseRow += text;
|
7476 | this.nonDisplayed_[this.row_] = baseRow;
|
7477 | };
|
7478 |
|
7479 | Cea608Stream.prototype.rollUp = function (pts, text) {
|
7480 | var baseRow = this.displayed_[this.row_];
|
7481 | baseRow += text;
|
7482 | this.displayed_[this.row_] = baseRow;
|
7483 | };
|
7484 |
|
7485 | Cea608Stream.prototype.shiftRowsUp_ = function () {
|
7486 | var i;
|
7487 |
|
7488 | for (i = 0; i < this.topRow_; i++) {
|
7489 | this.displayed_[i] = '';
|
7490 | }
|
7491 |
|
7492 | for (i = this.row_ + 1; i < BOTTOM_ROW + 1; i++) {
|
7493 | this.displayed_[i] = '';
|
7494 | }
|
7495 |
|
7496 |
|
7497 | for (i = this.topRow_; i < this.row_; i++) {
|
7498 | this.displayed_[i] = this.displayed_[i + 1];
|
7499 | }
|
7500 |
|
7501 |
|
7502 | this.displayed_[this.row_] = '';
|
7503 | };
|
7504 |
|
7505 | Cea608Stream.prototype.paintOn = function (pts, text) {
|
7506 | var baseRow = this.displayed_[this.row_];
|
7507 | baseRow += text;
|
7508 | this.displayed_[this.row_] = baseRow;
|
7509 | };
|
7510 |
|
7511 |
|
7512 | var captionStream = {
|
7513 | CaptionStream: CaptionStream$1,
|
7514 | Cea608Stream: Cea608Stream,
|
7515 | Cea708Stream: Cea708Stream
|
7516 | };
|
7517 | |
7518 |
|
7519 |
|
7520 |
|
7521 |
|
7522 |
|
7523 |
|
7524 | var streamTypes = {
|
7525 | H264_STREAM_TYPE: 0x1B,
|
7526 | ADTS_STREAM_TYPE: 0x0F,
|
7527 | METADATA_STREAM_TYPE: 0x15
|
7528 | };
|
7529 | var MAX_TS = 8589934592;
|
7530 | var RO_THRESH = 4294967296;
|
7531 | var TYPE_SHARED = 'shared';
|
7532 |
|
7533 | var handleRollover$1 = function handleRollover(value, reference) {
|
7534 | var direction = 1;
|
7535 |
|
7536 | if (value > reference) {
|
7537 |
|
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 |
|
7543 |
|
7544 | direction = -1;
|
7545 | }
|
7546 |
|
7547 |
|
7548 |
|
7549 | while (Math.abs(reference - value) > RO_THRESH) {
|
7550 | value += direction * MAX_TS;
|
7551 | }
|
7552 |
|
7553 | return value;
|
7554 | };
|
7555 |
|
7556 | var TimestampRolloverStream$1 = function TimestampRolloverStream(type) {
|
7557 | var lastDTS, referenceDTS;
|
7558 | TimestampRolloverStream.prototype.init.call(this);
|
7559 |
|
7560 |
|
7561 |
|
7562 | this.type_ = type || TYPE_SHARED;
|
7563 |
|
7564 | this.push = function (data) {
|
7565 |
|
7566 |
|
7567 | if (this.type_ !== TYPE_SHARED && data.type !== this.type_) {
|
7568 | return;
|
7569 | }
|
7570 |
|
7571 | if (referenceDTS === undefined) {
|
7572 | referenceDTS = data.dts;
|
7573 | }
|
7574 |
|
7575 | data.dts = handleRollover$1(data.dts, referenceDTS);
|
7576 | data.pts = handleRollover$1(data.pts, referenceDTS);
|
7577 | lastDTS = data.dts;
|
7578 | this.trigger('data', data);
|
7579 | };
|
7580 |
|
7581 | this.flush = function () {
|
7582 | referenceDTS = lastDTS;
|
7583 | this.trigger('done');
|
7584 | };
|
7585 |
|
7586 | this.endTimeline = function () {
|
7587 | this.flush();
|
7588 | this.trigger('endedtimeline');
|
7589 | };
|
7590 |
|
7591 | this.discontinuity = function () {
|
7592 | referenceDTS = void 0;
|
7593 | lastDTS = void 0;
|
7594 | };
|
7595 |
|
7596 | this.reset = function () {
|
7597 | this.discontinuity();
|
7598 | this.trigger('reset');
|
7599 | };
|
7600 | };
|
7601 |
|
7602 | TimestampRolloverStream$1.prototype = new stream();
|
7603 | var timestampRolloverStream = {
|
7604 | TimestampRolloverStream: TimestampRolloverStream$1,
|
7605 | handleRollover: handleRollover$1
|
7606 | };
|
7607 |
|
7608 | var percentEncode$1 = function percentEncode(bytes, start, end) {
|
7609 | var i,
|
7610 | result = '';
|
7611 |
|
7612 | for (i = start; i < end; i++) {
|
7613 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
7614 | }
|
7615 |
|
7616 | return result;
|
7617 | },
|
7618 |
|
7619 |
|
7620 | parseUtf8 = function parseUtf8(bytes, start, end) {
|
7621 | return decodeURIComponent(percentEncode$1(bytes, start, end));
|
7622 | },
|
7623 |
|
7624 |
|
7625 | parseIso88591$1 = function parseIso88591(bytes, start, end) {
|
7626 | return unescape(percentEncode$1(bytes, start, end));
|
7627 | },
|
7628 | parseSyncSafeInteger$1 = function parseSyncSafeInteger(data) {
|
7629 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
7630 | },
|
7631 | tagParsers = {
|
7632 | TXXX: function TXXX(tag) {
|
7633 | var i;
|
7634 |
|
7635 | if (tag.data[0] !== 3) {
|
7636 |
|
7637 | return;
|
7638 | }
|
7639 |
|
7640 | for (i = 1; i < tag.data.length; i++) {
|
7641 | if (tag.data[i] === 0) {
|
7642 |
|
7643 | tag.description = parseUtf8(tag.data, 1, i);
|
7644 |
|
7645 | tag.value = parseUtf8(tag.data, i + 1, tag.data.length).replace(/\0*$/, '');
|
7646 | break;
|
7647 | }
|
7648 | }
|
7649 |
|
7650 | tag.data = tag.value;
|
7651 | },
|
7652 | WXXX: function WXXX(tag) {
|
7653 | var i;
|
7654 |
|
7655 | if (tag.data[0] !== 3) {
|
7656 |
|
7657 | return;
|
7658 | }
|
7659 |
|
7660 | for (i = 1; i < tag.data.length; i++) {
|
7661 | if (tag.data[i] === 0) {
|
7662 |
|
7663 | tag.description = parseUtf8(tag.data, 1, i);
|
7664 | tag.url = parseUtf8(tag.data, i + 1, tag.data.length);
|
7665 | break;
|
7666 | }
|
7667 | }
|
7668 | },
|
7669 | PRIV: function PRIV(tag) {
|
7670 | var i;
|
7671 |
|
7672 | for (i = 0; i < tag.data.length; i++) {
|
7673 | if (tag.data[i] === 0) {
|
7674 |
|
7675 | tag.owner = parseIso88591$1(tag.data, 0, i);
|
7676 | break;
|
7677 | }
|
7678 | }
|
7679 |
|
7680 | tag.privateData = tag.data.subarray(i + 1);
|
7681 | tag.data = tag.privateData;
|
7682 | }
|
7683 | },
|
7684 | _MetadataStream;
|
7685 |
|
7686 | _MetadataStream = function MetadataStream(options) {
|
7687 | var settings = {
|
7688 |
|
7689 |
|
7690 |
|
7691 | descriptor: options && options.descriptor
|
7692 | },
|
7693 |
|
7694 | tagSize = 0,
|
7695 |
|
7696 | buffer = [],
|
7697 |
|
7698 | bufferSize = 0,
|
7699 | i;
|
7700 |
|
7701 | _MetadataStream.prototype.init.call(this);
|
7702 |
|
7703 |
|
7704 |
|
7705 | this.dispatchType = streamTypes.METADATA_STREAM_TYPE.toString(16);
|
7706 |
|
7707 | if (settings.descriptor) {
|
7708 | for (i = 0; i < settings.descriptor.length; i++) {
|
7709 | this.dispatchType += ('00' + settings.descriptor[i].toString(16)).slice(-2);
|
7710 | }
|
7711 | }
|
7712 |
|
7713 | this.push = function (chunk) {
|
7714 | var tag, frameStart, frameSize, frame, i, frameHeader;
|
7715 |
|
7716 | if (chunk.type !== 'timed-metadata') {
|
7717 | return;
|
7718 | }
|
7719 |
|
7720 |
|
7721 |
|
7722 |
|
7723 | if (chunk.dataAlignmentIndicator) {
|
7724 | bufferSize = 0;
|
7725 | buffer.length = 0;
|
7726 | }
|
7727 |
|
7728 |
|
7729 | 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))) {
|
7730 | this.trigger('log', {
|
7731 | level: 'warn',
|
7732 | message: 'Skipping unrecognized metadata packet'
|
7733 | });
|
7734 | return;
|
7735 | }
|
7736 |
|
7737 |
|
7738 | buffer.push(chunk);
|
7739 | bufferSize += chunk.data.byteLength;
|
7740 |
|
7741 | if (buffer.length === 1) {
|
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 | tagSize = parseSyncSafeInteger$1(chunk.data.subarray(6, 10));
|
7747 |
|
7748 |
|
7749 | tagSize += 10;
|
7750 | }
|
7751 |
|
7752 |
|
7753 | if (bufferSize < tagSize) {
|
7754 | return;
|
7755 | }
|
7756 |
|
7757 |
|
7758 | tag = {
|
7759 | data: new Uint8Array(tagSize),
|
7760 | frames: [],
|
7761 | pts: buffer[0].pts,
|
7762 | dts: buffer[0].dts
|
7763 | };
|
7764 |
|
7765 | for (i = 0; i < tagSize;) {
|
7766 | tag.data.set(buffer[0].data.subarray(0, tagSize - i), i);
|
7767 | i += buffer[0].data.byteLength;
|
7768 | bufferSize -= buffer[0].data.byteLength;
|
7769 | buffer.shift();
|
7770 | }
|
7771 |
|
7772 |
|
7773 | frameStart = 10;
|
7774 |
|
7775 | if (tag.data[5] & 0x40) {
|
7776 |
|
7777 | frameStart += 4;
|
7778 |
|
7779 | frameStart += parseSyncSafeInteger$1(tag.data.subarray(10, 14));
|
7780 |
|
7781 | tagSize -= parseSyncSafeInteger$1(tag.data.subarray(16, 20));
|
7782 | }
|
7783 |
|
7784 |
|
7785 |
|
7786 | do {
|
7787 |
|
7788 | frameSize = parseSyncSafeInteger$1(tag.data.subarray(frameStart + 4, frameStart + 8));
|
7789 |
|
7790 | if (frameSize < 1) {
|
7791 | this.trigger('log', {
|
7792 | level: 'warn',
|
7793 | message: 'Malformed ID3 frame encountered. Skipping metadata parsing.'
|
7794 | });
|
7795 | return;
|
7796 | }
|
7797 |
|
7798 | frameHeader = String.fromCharCode(tag.data[frameStart], tag.data[frameStart + 1], tag.data[frameStart + 2], tag.data[frameStart + 3]);
|
7799 | frame = {
|
7800 | id: frameHeader,
|
7801 | data: tag.data.subarray(frameStart + 10, frameStart + frameSize + 10)
|
7802 | };
|
7803 | frame.key = frame.id;
|
7804 |
|
7805 | if (tagParsers[frame.id]) {
|
7806 | tagParsers[frame.id](frame);
|
7807 |
|
7808 |
|
7809 | if (frame.owner === 'com.apple.streaming.transportStreamTimestamp') {
|
7810 | var d = frame.data,
|
7811 | size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
7812 | size *= 4;
|
7813 | size += d[7] & 0x03;
|
7814 | frame.timeStamp = size;
|
7815 |
|
7816 |
|
7817 |
|
7818 |
|
7819 | if (tag.pts === undefined && tag.dts === undefined) {
|
7820 | tag.pts = frame.timeStamp;
|
7821 | tag.dts = frame.timeStamp;
|
7822 | }
|
7823 |
|
7824 | this.trigger('timestamp', frame);
|
7825 | }
|
7826 | }
|
7827 |
|
7828 | tag.frames.push(frame);
|
7829 | frameStart += 10;
|
7830 |
|
7831 | frameStart += frameSize;
|
7832 | } while (frameStart < tagSize);
|
7833 |
|
7834 | this.trigger('data', tag);
|
7835 | };
|
7836 | };
|
7837 |
|
7838 | _MetadataStream.prototype = new stream();
|
7839 | var metadataStream = _MetadataStream;
|
7840 | var TimestampRolloverStream = timestampRolloverStream.TimestampRolloverStream;
|
7841 |
|
7842 | var _TransportPacketStream, _TransportParseStream, _ElementaryStream;
|
7843 |
|
7844 |
|
7845 | var MP2T_PACKET_LENGTH$1 = 188,
|
7846 |
|
7847 | SYNC_BYTE$1 = 0x47;
|
7848 | |
7849 |
|
7850 |
|
7851 |
|
7852 |
|
7853 | _TransportPacketStream = function TransportPacketStream() {
|
7854 | var buffer = new Uint8Array(MP2T_PACKET_LENGTH$1),
|
7855 | bytesInBuffer = 0;
|
7856 |
|
7857 | _TransportPacketStream.prototype.init.call(this);
|
7858 |
|
7859 | |
7860 |
|
7861 |
|
7862 |
|
7863 |
|
7864 | this.push = function (bytes) {
|
7865 | var startIndex = 0,
|
7866 | endIndex = MP2T_PACKET_LENGTH$1,
|
7867 | everything;
|
7868 |
|
7869 |
|
7870 | if (bytesInBuffer) {
|
7871 | everything = new Uint8Array(bytes.byteLength + bytesInBuffer);
|
7872 | everything.set(buffer.subarray(0, bytesInBuffer));
|
7873 | everything.set(bytes, bytesInBuffer);
|
7874 | bytesInBuffer = 0;
|
7875 | } else {
|
7876 | everything = bytes;
|
7877 | }
|
7878 |
|
7879 |
|
7880 | while (endIndex < everything.byteLength) {
|
7881 |
|
7882 | if (everything[startIndex] === SYNC_BYTE$1 && everything[endIndex] === SYNC_BYTE$1) {
|
7883 |
|
7884 |
|
7885 | this.trigger('data', everything.subarray(startIndex, endIndex));
|
7886 | startIndex += MP2T_PACKET_LENGTH$1;
|
7887 | endIndex += MP2T_PACKET_LENGTH$1;
|
7888 | continue;
|
7889 | }
|
7890 |
|
7891 |
|
7892 |
|
7893 |
|
7894 | startIndex++;
|
7895 | endIndex++;
|
7896 | }
|
7897 |
|
7898 |
|
7899 |
|
7900 |
|
7901 | if (startIndex < everything.byteLength) {
|
7902 | buffer.set(everything.subarray(startIndex), 0);
|
7903 | bytesInBuffer = everything.byteLength - startIndex;
|
7904 | }
|
7905 | };
|
7906 | |
7907 |
|
7908 |
|
7909 |
|
7910 |
|
7911 | this.flush = function () {
|
7912 |
|
7913 |
|
7914 |
|
7915 | if (bytesInBuffer === MP2T_PACKET_LENGTH$1 && buffer[0] === SYNC_BYTE$1) {
|
7916 | this.trigger('data', buffer);
|
7917 | bytesInBuffer = 0;
|
7918 | }
|
7919 |
|
7920 | this.trigger('done');
|
7921 | };
|
7922 |
|
7923 | this.endTimeline = function () {
|
7924 | this.flush();
|
7925 | this.trigger('endedtimeline');
|
7926 | };
|
7927 |
|
7928 | this.reset = function () {
|
7929 | bytesInBuffer = 0;
|
7930 | this.trigger('reset');
|
7931 | };
|
7932 | };
|
7933 |
|
7934 | _TransportPacketStream.prototype = new stream();
|
7935 | |
7936 |
|
7937 |
|
7938 |
|
7939 |
|
7940 | _TransportParseStream = function TransportParseStream() {
|
7941 | var parsePsi, parsePat, parsePmt, self;
|
7942 |
|
7943 | _TransportParseStream.prototype.init.call(this);
|
7944 |
|
7945 | self = this;
|
7946 | this.packetsWaitingForPmt = [];
|
7947 | this.programMapTable = undefined;
|
7948 |
|
7949 | parsePsi = function parsePsi(payload, psi) {
|
7950 | var offset = 0;
|
7951 |
|
7952 |
|
7953 |
|
7954 |
|
7955 |
|
7956 |
|
7957 | if (psi.payloadUnitStartIndicator) {
|
7958 | offset += payload[offset] + 1;
|
7959 | }
|
7960 |
|
7961 | if (psi.type === 'pat') {
|
7962 | parsePat(payload.subarray(offset), psi);
|
7963 | } else {
|
7964 | parsePmt(payload.subarray(offset), psi);
|
7965 | }
|
7966 | };
|
7967 |
|
7968 | parsePat = function parsePat(payload, pat) {
|
7969 | pat.section_number = payload[7];
|
7970 |
|
7971 | pat.last_section_number = payload[8];
|
7972 |
|
7973 |
|
7974 | self.pmtPid = (payload[10] & 0x1F) << 8 | payload[11];
|
7975 | pat.pmtPid = self.pmtPid;
|
7976 | };
|
7977 | |
7978 |
|
7979 |
|
7980 |
|
7981 |
|
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 | parsePmt = function parsePmt(payload, pmt) {
|
7988 | var sectionLength, tableEnd, programInfoLength, offset;
|
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 | if (!(payload[5] & 0x01)) {
|
7995 | return;
|
7996 | }
|
7997 |
|
7998 |
|
7999 | self.programMapTable = {
|
8000 | video: null,
|
8001 | audio: null,
|
8002 | 'timed-metadata': {}
|
8003 | };
|
8004 |
|
8005 | sectionLength = (payload[1] & 0x0f) << 8 | payload[2];
|
8006 | tableEnd = 3 + sectionLength - 4;
|
8007 |
|
8008 |
|
8009 | programInfoLength = (payload[10] & 0x0f) << 8 | payload[11];
|
8010 |
|
8011 | offset = 12 + programInfoLength;
|
8012 |
|
8013 | while (offset < tableEnd) {
|
8014 | var streamType = payload[offset];
|
8015 | var pid = (payload[offset + 1] & 0x1F) << 8 | payload[offset + 2];
|
8016 |
|
8017 |
|
8018 |
|
8019 | if (streamType === streamTypes.H264_STREAM_TYPE && self.programMapTable.video === null) {
|
8020 | self.programMapTable.video = pid;
|
8021 | } else if (streamType === streamTypes.ADTS_STREAM_TYPE && self.programMapTable.audio === null) {
|
8022 | self.programMapTable.audio = pid;
|
8023 | } else if (streamType === streamTypes.METADATA_STREAM_TYPE) {
|
8024 |
|
8025 | self.programMapTable['timed-metadata'][pid] = streamType;
|
8026 | }
|
8027 |
|
8028 |
|
8029 |
|
8030 | offset += ((payload[offset + 3] & 0x0F) << 8 | payload[offset + 4]) + 5;
|
8031 | }
|
8032 |
|
8033 |
|
8034 | pmt.programMapTable = self.programMapTable;
|
8035 | };
|
8036 | |
8037 |
|
8038 |
|
8039 |
|
8040 |
|
8041 | this.push = function (packet) {
|
8042 | var result = {},
|
8043 | offset = 4;
|
8044 | result.payloadUnitStartIndicator = !!(packet[1] & 0x40);
|
8045 |
|
8046 | result.pid = packet[1] & 0x1f;
|
8047 | result.pid <<= 8;
|
8048 | result.pid |= packet[2];
|
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 |
|
8054 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
8055 | offset += packet[offset] + 1;
|
8056 | }
|
8057 |
|
8058 |
|
8059 | if (result.pid === 0) {
|
8060 | result.type = 'pat';
|
8061 | parsePsi(packet.subarray(offset), result);
|
8062 | this.trigger('data', result);
|
8063 | } else if (result.pid === this.pmtPid) {
|
8064 | result.type = 'pmt';
|
8065 | parsePsi(packet.subarray(offset), result);
|
8066 | this.trigger('data', result);
|
8067 |
|
8068 | while (this.packetsWaitingForPmt.length) {
|
8069 | this.processPes_.apply(this, this.packetsWaitingForPmt.shift());
|
8070 | }
|
8071 | } else if (this.programMapTable === undefined) {
|
8072 |
|
8073 |
|
8074 | this.packetsWaitingForPmt.push([packet, offset, result]);
|
8075 | } else {
|
8076 | this.processPes_(packet, offset, result);
|
8077 | }
|
8078 | };
|
8079 |
|
8080 | this.processPes_ = function (packet, offset, result) {
|
8081 |
|
8082 | if (result.pid === this.programMapTable.video) {
|
8083 | result.streamType = streamTypes.H264_STREAM_TYPE;
|
8084 | } else if (result.pid === this.programMapTable.audio) {
|
8085 | result.streamType = streamTypes.ADTS_STREAM_TYPE;
|
8086 | } else {
|
8087 |
|
8088 |
|
8089 | result.streamType = this.programMapTable['timed-metadata'][result.pid];
|
8090 | }
|
8091 |
|
8092 | result.type = 'pes';
|
8093 | result.data = packet.subarray(offset);
|
8094 | this.trigger('data', result);
|
8095 | };
|
8096 | };
|
8097 |
|
8098 | _TransportParseStream.prototype = new stream();
|
8099 | _TransportParseStream.STREAM_TYPES = {
|
8100 | h264: 0x1b,
|
8101 | adts: 0x0f
|
8102 | };
|
8103 | |
8104 |
|
8105 |
|
8106 |
|
8107 |
|
8108 |
|
8109 |
|
8110 |
|
8111 |
|
8112 | _ElementaryStream = function ElementaryStream() {
|
8113 | var self = this,
|
8114 | segmentHadPmt = false,
|
8115 |
|
8116 | video = {
|
8117 | data: [],
|
8118 | size: 0
|
8119 | },
|
8120 | audio = {
|
8121 | data: [],
|
8122 | size: 0
|
8123 | },
|
8124 | timedMetadata = {
|
8125 | data: [],
|
8126 | size: 0
|
8127 | },
|
8128 | programMapTable,
|
8129 | parsePes = function parsePes(payload, pes) {
|
8130 | var ptsDtsFlags;
|
8131 | var startPrefix = payload[0] << 16 | payload[1] << 8 | payload[2];
|
8132 |
|
8133 | pes.data = new Uint8Array();
|
8134 |
|
8135 |
|
8136 |
|
8137 | if (startPrefix !== 1) {
|
8138 | return;
|
8139 | }
|
8140 |
|
8141 |
|
8142 | pes.packetLength = 6 + (payload[4] << 8 | payload[5]);
|
8143 |
|
8144 | pes.dataAlignmentIndicator = (payload[6] & 0x04) !== 0;
|
8145 |
|
8146 |
|
8147 |
|
8148 | ptsDtsFlags = payload[7];
|
8149 |
|
8150 |
|
8151 |
|
8152 |
|
8153 |
|
8154 |
|
8155 |
|
8156 |
|
8157 | if (ptsDtsFlags & 0xC0) {
|
8158 |
|
8159 |
|
8160 |
|
8161 | pes.pts = (payload[9] & 0x0E) << 27 | (payload[10] & 0xFF) << 20 | (payload[11] & 0xFE) << 12 | (payload[12] & 0xFF) << 5 | (payload[13] & 0xFE) >>> 3;
|
8162 | pes.pts *= 4;
|
8163 |
|
8164 | pes.pts += (payload[13] & 0x06) >>> 1;
|
8165 |
|
8166 | pes.dts = pes.pts;
|
8167 |
|
8168 | if (ptsDtsFlags & 0x40) {
|
8169 | pes.dts = (payload[14] & 0x0E) << 27 | (payload[15] & 0xFF) << 20 | (payload[16] & 0xFE) << 12 | (payload[17] & 0xFF) << 5 | (payload[18] & 0xFE) >>> 3;
|
8170 | pes.dts *= 4;
|
8171 |
|
8172 | pes.dts += (payload[18] & 0x06) >>> 1;
|
8173 | }
|
8174 | }
|
8175 |
|
8176 |
|
8177 |
|
8178 |
|
8179 | pes.data = payload.subarray(9 + payload[8]);
|
8180 | },
|
8181 |
|
8182 | |
8183 |
|
8184 |
|
8185 | flushStream = function flushStream(stream, type, forceFlush) {
|
8186 | var packetData = new Uint8Array(stream.size),
|
8187 | event = {
|
8188 | type: type
|
8189 | },
|
8190 | i = 0,
|
8191 | offset = 0,
|
8192 | packetFlushable = false,
|
8193 | fragment;
|
8194 |
|
8195 |
|
8196 | if (!stream.data.length || stream.size < 9) {
|
8197 | return;
|
8198 | }
|
8199 |
|
8200 | event.trackId = stream.data[0].pid;
|
8201 |
|
8202 | for (i = 0; i < stream.data.length; i++) {
|
8203 | fragment = stream.data[i];
|
8204 | packetData.set(fragment.data, offset);
|
8205 | offset += fragment.data.byteLength;
|
8206 | }
|
8207 |
|
8208 |
|
8209 | parsePes(packetData, event);
|
8210 |
|
8211 |
|
8212 | packetFlushable = type === 'video' || event.packetLength <= stream.size;
|
8213 |
|
8214 | if (forceFlush || packetFlushable) {
|
8215 | stream.size = 0;
|
8216 | stream.data.length = 0;
|
8217 | }
|
8218 |
|
8219 |
|
8220 |
|
8221 | if (packetFlushable) {
|
8222 | self.trigger('data', event);
|
8223 | }
|
8224 | };
|
8225 |
|
8226 | _ElementaryStream.prototype.init.call(this);
|
8227 | |
8228 |
|
8229 |
|
8230 |
|
8231 |
|
8232 |
|
8233 | this.push = function (data) {
|
8234 | ({
|
8235 | pat: function pat() {
|
8236 |
|
8237 | },
|
8238 | pes: function pes() {
|
8239 | var stream, streamType;
|
8240 |
|
8241 | switch (data.streamType) {
|
8242 | case streamTypes.H264_STREAM_TYPE:
|
8243 | stream = video;
|
8244 | streamType = 'video';
|
8245 | break;
|
8246 |
|
8247 | case streamTypes.ADTS_STREAM_TYPE:
|
8248 | stream = audio;
|
8249 | streamType = 'audio';
|
8250 | break;
|
8251 |
|
8252 | case streamTypes.METADATA_STREAM_TYPE:
|
8253 | stream = timedMetadata;
|
8254 | streamType = 'timed-metadata';
|
8255 | break;
|
8256 |
|
8257 | default:
|
8258 |
|
8259 | return;
|
8260 | }
|
8261 |
|
8262 |
|
8263 |
|
8264 | if (data.payloadUnitStartIndicator) {
|
8265 | flushStream(stream, streamType, true);
|
8266 | }
|
8267 |
|
8268 |
|
8269 |
|
8270 | stream.data.push(data);
|
8271 | stream.size += data.data.byteLength;
|
8272 | },
|
8273 | pmt: function pmt() {
|
8274 | var event = {
|
8275 | type: 'metadata',
|
8276 | tracks: []
|
8277 | };
|
8278 | programMapTable = data.programMapTable;
|
8279 |
|
8280 | if (programMapTable.video !== null) {
|
8281 | event.tracks.push({
|
8282 | timelineStartInfo: {
|
8283 | baseMediaDecodeTime: 0
|
8284 | },
|
8285 | id: +programMapTable.video,
|
8286 | codec: 'avc',
|
8287 | type: 'video'
|
8288 | });
|
8289 | }
|
8290 |
|
8291 | if (programMapTable.audio !== null) {
|
8292 | event.tracks.push({
|
8293 | timelineStartInfo: {
|
8294 | baseMediaDecodeTime: 0
|
8295 | },
|
8296 | id: +programMapTable.audio,
|
8297 | codec: 'adts',
|
8298 | type: 'audio'
|
8299 | });
|
8300 | }
|
8301 |
|
8302 | segmentHadPmt = true;
|
8303 | self.trigger('data', event);
|
8304 | }
|
8305 | })[data.type]();
|
8306 | };
|
8307 |
|
8308 | this.reset = function () {
|
8309 | video.size = 0;
|
8310 | video.data.length = 0;
|
8311 | audio.size = 0;
|
8312 | audio.data.length = 0;
|
8313 | this.trigger('reset');
|
8314 | };
|
8315 | |
8316 |
|
8317 |
|
8318 |
|
8319 |
|
8320 |
|
8321 |
|
8322 |
|
8323 |
|
8324 |
|
8325 |
|
8326 | this.flushStreams_ = function () {
|
8327 |
|
8328 |
|
8329 | flushStream(video, 'video');
|
8330 | flushStream(audio, 'audio');
|
8331 | flushStream(timedMetadata, 'timed-metadata');
|
8332 | };
|
8333 |
|
8334 | this.flush = function () {
|
8335 |
|
8336 |
|
8337 |
|
8338 | if (!segmentHadPmt && programMapTable) {
|
8339 | var pmt = {
|
8340 | type: 'metadata',
|
8341 | tracks: []
|
8342 | };
|
8343 |
|
8344 | if (programMapTable.video !== null) {
|
8345 | pmt.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 | pmt.tracks.push({
|
8357 | timelineStartInfo: {
|
8358 | baseMediaDecodeTime: 0
|
8359 | },
|
8360 | id: +programMapTable.audio,
|
8361 | codec: 'adts',
|
8362 | type: 'audio'
|
8363 | });
|
8364 | }
|
8365 |
|
8366 | self.trigger('data', pmt);
|
8367 | }
|
8368 |
|
8369 | segmentHadPmt = false;
|
8370 | this.flushStreams_();
|
8371 | this.trigger('done');
|
8372 | };
|
8373 | };
|
8374 |
|
8375 | _ElementaryStream.prototype = new stream();
|
8376 | var m2ts = {
|
8377 | PAT_PID: 0x0000,
|
8378 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH$1,
|
8379 | TransportPacketStream: _TransportPacketStream,
|
8380 | TransportParseStream: _TransportParseStream,
|
8381 | ElementaryStream: _ElementaryStream,
|
8382 | TimestampRolloverStream: TimestampRolloverStream,
|
8383 | CaptionStream: captionStream.CaptionStream,
|
8384 | Cea608Stream: captionStream.Cea608Stream,
|
8385 | Cea708Stream: captionStream.Cea708Stream,
|
8386 | MetadataStream: metadataStream
|
8387 | };
|
8388 |
|
8389 | for (var type in streamTypes) {
|
8390 | if (streamTypes.hasOwnProperty(type)) {
|
8391 | m2ts[type] = streamTypes[type];
|
8392 | }
|
8393 | }
|
8394 |
|
8395 | var m2ts_1 = m2ts;
|
8396 | var ONE_SECOND_IN_TS$2 = clock.ONE_SECOND_IN_TS;
|
8397 |
|
8398 | var _AdtsStream;
|
8399 |
|
8400 | var ADTS_SAMPLING_FREQUENCIES$1 = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
8401 | |
8402 |
|
8403 |
|
8404 |
|
8405 |
|
8406 |
|
8407 |
|
8408 |
|
8409 |
|
8410 | _AdtsStream = function AdtsStream(handlePartialSegments) {
|
8411 | var buffer,
|
8412 | frameNum = 0;
|
8413 |
|
8414 | _AdtsStream.prototype.init.call(this);
|
8415 |
|
8416 | this.skipWarn_ = function (start, end) {
|
8417 | this.trigger('log', {
|
8418 | level: 'warn',
|
8419 | message: "adts skiping bytes " + start + " to " + end + " in frame " + frameNum + " outside syncword"
|
8420 | });
|
8421 | };
|
8422 |
|
8423 | this.push = function (packet) {
|
8424 | var i = 0,
|
8425 | frameLength,
|
8426 | protectionSkipBytes,
|
8427 | oldBuffer,
|
8428 | sampleCount,
|
8429 | adtsFrameDuration;
|
8430 |
|
8431 | if (!handlePartialSegments) {
|
8432 | frameNum = 0;
|
8433 | }
|
8434 |
|
8435 | if (packet.type !== 'audio') {
|
8436 |
|
8437 | return;
|
8438 | }
|
8439 |
|
8440 |
|
8441 |
|
8442 | if (buffer && buffer.length) {
|
8443 | oldBuffer = buffer;
|
8444 | buffer = new Uint8Array(oldBuffer.byteLength + packet.data.byteLength);
|
8445 | buffer.set(oldBuffer);
|
8446 | buffer.set(packet.data, oldBuffer.byteLength);
|
8447 | } else {
|
8448 | buffer = packet.data;
|
8449 | }
|
8450 |
|
8451 |
|
8452 |
|
8453 | var skip;
|
8454 |
|
8455 |
|
8456 | while (i + 7 < buffer.length) {
|
8457 |
|
8458 | if (buffer[i] !== 0xFF || (buffer[i + 1] & 0xF6) !== 0xF0) {
|
8459 | if (typeof skip !== 'number') {
|
8460 | skip = i;
|
8461 | }
|
8462 |
|
8463 |
|
8464 |
|
8465 | i++;
|
8466 | continue;
|
8467 | }
|
8468 |
|
8469 | if (typeof skip === 'number') {
|
8470 | this.skipWarn_(skip, i);
|
8471 | skip = null;
|
8472 | }
|
8473 |
|
8474 |
|
8475 |
|
8476 | protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
|
8477 |
|
8478 |
|
8479 |
|
8480 | frameLength = (buffer[i + 3] & 0x03) << 11 | buffer[i + 4] << 3 | (buffer[i + 5] & 0xe0) >> 5;
|
8481 | sampleCount = ((buffer[i + 6] & 0x03) + 1) * 1024;
|
8482 | adtsFrameDuration = sampleCount * ONE_SECOND_IN_TS$2 / ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2];
|
8483 |
|
8484 |
|
8485 | if (buffer.byteLength - i < frameLength) {
|
8486 | break;
|
8487 | }
|
8488 |
|
8489 |
|
8490 | this.trigger('data', {
|
8491 | pts: packet.pts + frameNum * adtsFrameDuration,
|
8492 | dts: packet.dts + frameNum * adtsFrameDuration,
|
8493 | sampleCount: sampleCount,
|
8494 | audioobjecttype: (buffer[i + 2] >>> 6 & 0x03) + 1,
|
8495 | channelcount: (buffer[i + 2] & 1) << 2 | (buffer[i + 3] & 0xc0) >>> 6,
|
8496 | samplerate: ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2],
|
8497 | samplingfrequencyindex: (buffer[i + 2] & 0x3c) >>> 2,
|
8498 |
|
8499 | samplesize: 16,
|
8500 |
|
8501 | data: buffer.subarray(i + 7 + protectionSkipBytes, i + frameLength)
|
8502 | });
|
8503 | frameNum++;
|
8504 | i += frameLength;
|
8505 | }
|
8506 |
|
8507 | if (typeof skip === 'number') {
|
8508 | this.skipWarn_(skip, i);
|
8509 | skip = null;
|
8510 | }
|
8511 |
|
8512 |
|
8513 | buffer = buffer.subarray(i);
|
8514 | };
|
8515 |
|
8516 | this.flush = function () {
|
8517 | frameNum = 0;
|
8518 | this.trigger('done');
|
8519 | };
|
8520 |
|
8521 | this.reset = function () {
|
8522 | buffer = void 0;
|
8523 | this.trigger('reset');
|
8524 | };
|
8525 |
|
8526 | this.endTimeline = function () {
|
8527 | buffer = void 0;
|
8528 | this.trigger('endedtimeline');
|
8529 | };
|
8530 | };
|
8531 |
|
8532 | _AdtsStream.prototype = new stream();
|
8533 | var adts = _AdtsStream;
|
8534 | |
8535 |
|
8536 |
|
8537 |
|
8538 |
|
8539 |
|
8540 |
|
8541 | var ExpGolomb;
|
8542 | |
8543 |
|
8544 |
|
8545 |
|
8546 |
|
8547 | ExpGolomb = function ExpGolomb(workingData) {
|
8548 | var
|
8549 | workingBytesAvailable = workingData.byteLength,
|
8550 |
|
8551 | workingWord = 0,
|
8552 |
|
8553 |
|
8554 | workingBitsAvailable = 0;
|
8555 |
|
8556 |
|
8557 | this.length = function () {
|
8558 | return 8 * workingBytesAvailable;
|
8559 | };
|
8560 |
|
8561 |
|
8562 | this.bitsAvailable = function () {
|
8563 | return 8 * workingBytesAvailable + workingBitsAvailable;
|
8564 | };
|
8565 |
|
8566 |
|
8567 | this.loadWord = function () {
|
8568 | var position = workingData.byteLength - workingBytesAvailable,
|
8569 | workingBytes = new Uint8Array(4),
|
8570 | availableBytes = Math.min(4, workingBytesAvailable);
|
8571 |
|
8572 | if (availableBytes === 0) {
|
8573 | throw new Error('no bytes available');
|
8574 | }
|
8575 |
|
8576 | workingBytes.set(workingData.subarray(position, position + availableBytes));
|
8577 | workingWord = new DataView(workingBytes.buffer).getUint32(0);
|
8578 |
|
8579 | workingBitsAvailable = availableBytes * 8;
|
8580 | workingBytesAvailable -= availableBytes;
|
8581 | };
|
8582 |
|
8583 |
|
8584 | this.skipBits = function (count) {
|
8585 | var skipBytes;
|
8586 |
|
8587 | if (workingBitsAvailable > count) {
|
8588 | workingWord <<= count;
|
8589 | workingBitsAvailable -= count;
|
8590 | } else {
|
8591 | count -= workingBitsAvailable;
|
8592 | skipBytes = Math.floor(count / 8);
|
8593 | count -= skipBytes * 8;
|
8594 | workingBytesAvailable -= skipBytes;
|
8595 | this.loadWord();
|
8596 | workingWord <<= count;
|
8597 | workingBitsAvailable -= count;
|
8598 | }
|
8599 | };
|
8600 |
|
8601 |
|
8602 | this.readBits = function (size) {
|
8603 | var bits = Math.min(workingBitsAvailable, size),
|
8604 |
|
8605 | valu = workingWord >>> 32 - bits;
|
8606 |
|
8607 |
|
8608 | workingBitsAvailable -= bits;
|
8609 |
|
8610 | if (workingBitsAvailable > 0) {
|
8611 | workingWord <<= bits;
|
8612 | } else if (workingBytesAvailable > 0) {
|
8613 | this.loadWord();
|
8614 | }
|
8615 |
|
8616 | bits = size - bits;
|
8617 |
|
8618 | if (bits > 0) {
|
8619 | return valu << bits | this.readBits(bits);
|
8620 | }
|
8621 |
|
8622 | return valu;
|
8623 | };
|
8624 |
|
8625 |
|
8626 | this.skipLeadingZeros = function () {
|
8627 | var leadingZeroCount;
|
8628 |
|
8629 | for (leadingZeroCount = 0; leadingZeroCount < workingBitsAvailable; ++leadingZeroCount) {
|
8630 | if ((workingWord & 0x80000000 >>> leadingZeroCount) !== 0) {
|
8631 |
|
8632 | workingWord <<= leadingZeroCount;
|
8633 | workingBitsAvailable -= leadingZeroCount;
|
8634 | return leadingZeroCount;
|
8635 | }
|
8636 | }
|
8637 |
|
8638 |
|
8639 | this.loadWord();
|
8640 | return leadingZeroCount + this.skipLeadingZeros();
|
8641 | };
|
8642 |
|
8643 |
|
8644 | this.skipUnsignedExpGolomb = function () {
|
8645 | this.skipBits(1 + this.skipLeadingZeros());
|
8646 | };
|
8647 |
|
8648 |
|
8649 | this.skipExpGolomb = function () {
|
8650 | this.skipBits(1 + this.skipLeadingZeros());
|
8651 | };
|
8652 |
|
8653 |
|
8654 | this.readUnsignedExpGolomb = function () {
|
8655 | var clz = this.skipLeadingZeros();
|
8656 |
|
8657 | return this.readBits(clz + 1) - 1;
|
8658 | };
|
8659 |
|
8660 |
|
8661 | this.readExpGolomb = function () {
|
8662 | var valu = this.readUnsignedExpGolomb();
|
8663 |
|
8664 | if (0x01 & valu) {
|
8665 |
|
8666 | return 1 + valu >>> 1;
|
8667 | }
|
8668 |
|
8669 | return -1 * (valu >>> 1);
|
8670 | };
|
8671 |
|
8672 |
|
8673 |
|
8674 | this.readBoolean = function () {
|
8675 | return this.readBits(1) === 1;
|
8676 | };
|
8677 |
|
8678 |
|
8679 | this.readUnsignedByte = function () {
|
8680 | return this.readBits(8);
|
8681 | };
|
8682 |
|
8683 | this.loadWord();
|
8684 | };
|
8685 |
|
8686 | var expGolomb = ExpGolomb;
|
8687 |
|
8688 | var _H264Stream, _NalByteStream;
|
8689 |
|
8690 | var PROFILES_WITH_OPTIONAL_SPS_DATA;
|
8691 | |
8692 |
|
8693 |
|
8694 |
|
8695 | _NalByteStream = function NalByteStream() {
|
8696 | var syncPoint = 0,
|
8697 | i,
|
8698 | buffer;
|
8699 |
|
8700 | _NalByteStream.prototype.init.call(this);
|
8701 | |
8702 |
|
8703 |
|
8704 |
|
8705 |
|
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 | this.push = function (data) {
|
8711 | var swapBuffer;
|
8712 |
|
8713 | if (!buffer) {
|
8714 | buffer = data.data;
|
8715 | } else {
|
8716 | swapBuffer = new Uint8Array(buffer.byteLength + data.data.byteLength);
|
8717 | swapBuffer.set(buffer);
|
8718 | swapBuffer.set(data.data, buffer.byteLength);
|
8719 | buffer = swapBuffer;
|
8720 | }
|
8721 |
|
8722 | var len = buffer.byteLength;
|
8723 |
|
8724 |
|
8725 |
|
8726 |
|
8727 |
|
8728 |
|
8729 |
|
8730 |
|
8731 |
|
8732 | for (; syncPoint < len - 3; syncPoint++) {
|
8733 | if (buffer[syncPoint + 2] === 1) {
|
8734 |
|
8735 | i = syncPoint + 5;
|
8736 | break;
|
8737 | }
|
8738 | }
|
8739 |
|
8740 | while (i < len) {
|
8741 |
|
8742 |
|
8743 | switch (buffer[i]) {
|
8744 | case 0:
|
8745 |
|
8746 | if (buffer[i - 1] !== 0) {
|
8747 | i += 2;
|
8748 | break;
|
8749 | } else if (buffer[i - 2] !== 0) {
|
8750 | i++;
|
8751 | break;
|
8752 | }
|
8753 |
|
8754 |
|
8755 | if (syncPoint + 3 !== i - 2) {
|
8756 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
8757 | }
|
8758 |
|
8759 |
|
8760 | do {
|
8761 | i++;
|
8762 | } while (buffer[i] !== 1 && i < len);
|
8763 |
|
8764 | syncPoint = i - 2;
|
8765 | i += 3;
|
8766 | break;
|
8767 |
|
8768 | case 1:
|
8769 |
|
8770 | if (buffer[i - 1] !== 0 || buffer[i - 2] !== 0) {
|
8771 | i += 3;
|
8772 | break;
|
8773 | }
|
8774 |
|
8775 |
|
8776 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
8777 | syncPoint = i - 2;
|
8778 | i += 3;
|
8779 | break;
|
8780 |
|
8781 | default:
|
8782 |
|
8783 |
|
8784 | i += 3;
|
8785 | break;
|
8786 | }
|
8787 | }
|
8788 |
|
8789 |
|
8790 | buffer = buffer.subarray(syncPoint);
|
8791 | i -= syncPoint;
|
8792 | syncPoint = 0;
|
8793 | };
|
8794 |
|
8795 | this.reset = function () {
|
8796 | buffer = null;
|
8797 | syncPoint = 0;
|
8798 | this.trigger('reset');
|
8799 | };
|
8800 |
|
8801 | this.flush = function () {
|
8802 |
|
8803 | if (buffer && buffer.byteLength > 3) {
|
8804 | this.trigger('data', buffer.subarray(syncPoint + 3));
|
8805 | }
|
8806 |
|
8807 |
|
8808 | buffer = null;
|
8809 | syncPoint = 0;
|
8810 | this.trigger('done');
|
8811 | };
|
8812 |
|
8813 | this.endTimeline = function () {
|
8814 | this.flush();
|
8815 | this.trigger('endedtimeline');
|
8816 | };
|
8817 | };
|
8818 |
|
8819 | _NalByteStream.prototype = new stream();
|
8820 |
|
8821 |
|
8822 |
|
8823 | PROFILES_WITH_OPTIONAL_SPS_DATA = {
|
8824 | 100: true,
|
8825 | 110: true,
|
8826 | 122: true,
|
8827 | 244: true,
|
8828 | 44: true,
|
8829 | 83: true,
|
8830 | 86: true,
|
8831 | 118: true,
|
8832 | 128: true,
|
8833 |
|
8834 |
|
8835 | 138: true,
|
8836 | 139: true,
|
8837 | 134: true
|
8838 | };
|
8839 | |
8840 |
|
8841 |
|
8842 |
|
8843 |
|
8844 | _H264Stream = function H264Stream() {
|
8845 | var nalByteStream = new _NalByteStream(),
|
8846 | self,
|
8847 | trackId,
|
8848 | currentPts,
|
8849 | currentDts,
|
8850 | discardEmulationPreventionBytes,
|
8851 | readSequenceParameterSet,
|
8852 | skipScalingList;
|
8853 |
|
8854 | _H264Stream.prototype.init.call(this);
|
8855 |
|
8856 | self = this;
|
8857 | |
8858 |
|
8859 |
|
8860 |
|
8861 |
|
8862 |
|
8863 |
|
8864 |
|
8865 |
|
8866 |
|
8867 |
|
8868 |
|
8869 | this.push = function (packet) {
|
8870 | if (packet.type !== 'video') {
|
8871 | return;
|
8872 | }
|
8873 |
|
8874 | trackId = packet.trackId;
|
8875 | currentPts = packet.pts;
|
8876 | currentDts = packet.dts;
|
8877 | nalByteStream.push(packet);
|
8878 | };
|
8879 | |
8880 |
|
8881 |
|
8882 |
|
8883 |
|
8884 |
|
8885 |
|
8886 |
|
8887 |
|
8888 |
|
8889 | nalByteStream.on('data', function (data) {
|
8890 | var event = {
|
8891 | trackId: trackId,
|
8892 | pts: currentPts,
|
8893 | dts: currentDts,
|
8894 | data: data,
|
8895 | nalUnitTypeCode: data[0] & 0x1f
|
8896 | };
|
8897 |
|
8898 | switch (event.nalUnitTypeCode) {
|
8899 | case 0x05:
|
8900 | event.nalUnitType = 'slice_layer_without_partitioning_rbsp_idr';
|
8901 | break;
|
8902 |
|
8903 | case 0x06:
|
8904 | event.nalUnitType = 'sei_rbsp';
|
8905 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
8906 | break;
|
8907 |
|
8908 | case 0x07:
|
8909 | event.nalUnitType = 'seq_parameter_set_rbsp';
|
8910 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
8911 | event.config = readSequenceParameterSet(event.escapedRBSP);
|
8912 | break;
|
8913 |
|
8914 | case 0x08:
|
8915 | event.nalUnitType = 'pic_parameter_set_rbsp';
|
8916 | break;
|
8917 |
|
8918 | case 0x09:
|
8919 | event.nalUnitType = 'access_unit_delimiter_rbsp';
|
8920 | break;
|
8921 | }
|
8922 |
|
8923 |
|
8924 | self.trigger('data', event);
|
8925 | });
|
8926 | nalByteStream.on('done', function () {
|
8927 | self.trigger('done');
|
8928 | });
|
8929 | nalByteStream.on('partialdone', function () {
|
8930 | self.trigger('partialdone');
|
8931 | });
|
8932 | nalByteStream.on('reset', function () {
|
8933 | self.trigger('reset');
|
8934 | });
|
8935 | nalByteStream.on('endedtimeline', function () {
|
8936 | self.trigger('endedtimeline');
|
8937 | });
|
8938 |
|
8939 | this.flush = function () {
|
8940 | nalByteStream.flush();
|
8941 | };
|
8942 |
|
8943 | this.partialFlush = function () {
|
8944 | nalByteStream.partialFlush();
|
8945 | };
|
8946 |
|
8947 | this.reset = function () {
|
8948 | nalByteStream.reset();
|
8949 | };
|
8950 |
|
8951 | this.endTimeline = function () {
|
8952 | nalByteStream.endTimeline();
|
8953 | };
|
8954 | |
8955 |
|
8956 |
|
8957 |
|
8958 |
|
8959 |
|
8960 |
|
8961 |
|
8962 |
|
8963 |
|
8964 |
|
8965 | skipScalingList = function skipScalingList(count, expGolombDecoder) {
|
8966 | var lastScale = 8,
|
8967 | nextScale = 8,
|
8968 | j,
|
8969 | deltaScale;
|
8970 |
|
8971 | for (j = 0; j < count; j++) {
|
8972 | if (nextScale !== 0) {
|
8973 | deltaScale = expGolombDecoder.readExpGolomb();
|
8974 | nextScale = (lastScale + deltaScale + 256) % 256;
|
8975 | }
|
8976 |
|
8977 | lastScale = nextScale === 0 ? lastScale : nextScale;
|
8978 | }
|
8979 | };
|
8980 | |
8981 |
|
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 |
|
8987 |
|
8988 |
|
8989 |
|
8990 | discardEmulationPreventionBytes = function discardEmulationPreventionBytes(data) {
|
8991 | var length = data.byteLength,
|
8992 | emulationPreventionBytesPositions = [],
|
8993 | i = 1,
|
8994 | newLength,
|
8995 | newData;
|
8996 |
|
8997 | while (i < length - 2) {
|
8998 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
8999 | emulationPreventionBytesPositions.push(i + 2);
|
9000 | i += 2;
|
9001 | } else {
|
9002 | i++;
|
9003 | }
|
9004 | }
|
9005 |
|
9006 |
|
9007 |
|
9008 | if (emulationPreventionBytesPositions.length === 0) {
|
9009 | return data;
|
9010 | }
|
9011 |
|
9012 |
|
9013 | newLength = length - emulationPreventionBytesPositions.length;
|
9014 | newData = new Uint8Array(newLength);
|
9015 | var sourceIndex = 0;
|
9016 |
|
9017 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
9018 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
9019 |
|
9020 | sourceIndex++;
|
9021 |
|
9022 | emulationPreventionBytesPositions.shift();
|
9023 | }
|
9024 |
|
9025 | newData[i] = data[sourceIndex];
|
9026 | }
|
9027 |
|
9028 | return newData;
|
9029 | };
|
9030 | |
9031 |
|
9032 |
|
9033 |
|
9034 |
|
9035 |
|
9036 |
|
9037 |
|
9038 |
|
9039 |
|
9040 |
|
9041 | readSequenceParameterSet = function readSequenceParameterSet(data) {
|
9042 | var frameCropLeftOffset = 0,
|
9043 | frameCropRightOffset = 0,
|
9044 | frameCropTopOffset = 0,
|
9045 | frameCropBottomOffset = 0,
|
9046 | expGolombDecoder,
|
9047 | profileIdc,
|
9048 | levelIdc,
|
9049 | profileCompatibility,
|
9050 | chromaFormatIdc,
|
9051 | picOrderCntType,
|
9052 | numRefFramesInPicOrderCntCycle,
|
9053 | picWidthInMbsMinus1,
|
9054 | picHeightInMapUnitsMinus1,
|
9055 | frameMbsOnlyFlag,
|
9056 | scalingListCount,
|
9057 | sarRatio = [1, 1],
|
9058 | aspectRatioIdc,
|
9059 | i;
|
9060 | expGolombDecoder = new expGolomb(data);
|
9061 | profileIdc = expGolombDecoder.readUnsignedByte();
|
9062 |
|
9063 | profileCompatibility = expGolombDecoder.readUnsignedByte();
|
9064 |
|
9065 | levelIdc = expGolombDecoder.readUnsignedByte();
|
9066 |
|
9067 | expGolombDecoder.skipUnsignedExpGolomb();
|
9068 |
|
9069 |
|
9070 | if (PROFILES_WITH_OPTIONAL_SPS_DATA[profileIdc]) {
|
9071 | chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
|
9072 |
|
9073 | if (chromaFormatIdc === 3) {
|
9074 | expGolombDecoder.skipBits(1);
|
9075 | }
|
9076 |
|
9077 | expGolombDecoder.skipUnsignedExpGolomb();
|
9078 |
|
9079 | expGolombDecoder.skipUnsignedExpGolomb();
|
9080 |
|
9081 | expGolombDecoder.skipBits(1);
|
9082 |
|
9083 | if (expGolombDecoder.readBoolean()) {
|
9084 |
|
9085 | scalingListCount = chromaFormatIdc !== 3 ? 8 : 12;
|
9086 |
|
9087 | for (i = 0; i < scalingListCount; i++) {
|
9088 | if (expGolombDecoder.readBoolean()) {
|
9089 |
|
9090 | if (i < 6) {
|
9091 | skipScalingList(16, expGolombDecoder);
|
9092 | } else {
|
9093 | skipScalingList(64, expGolombDecoder);
|
9094 | }
|
9095 | }
|
9096 | }
|
9097 | }
|
9098 | }
|
9099 |
|
9100 | expGolombDecoder.skipUnsignedExpGolomb();
|
9101 |
|
9102 | picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
|
9103 |
|
9104 | if (picOrderCntType === 0) {
|
9105 | expGolombDecoder.readUnsignedExpGolomb();
|
9106 | } else if (picOrderCntType === 1) {
|
9107 | expGolombDecoder.skipBits(1);
|
9108 |
|
9109 | expGolombDecoder.skipExpGolomb();
|
9110 |
|
9111 | expGolombDecoder.skipExpGolomb();
|
9112 |
|
9113 | numRefFramesInPicOrderCntCycle = expGolombDecoder.readUnsignedExpGolomb();
|
9114 |
|
9115 | for (i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
|
9116 | expGolombDecoder.skipExpGolomb();
|
9117 | }
|
9118 | }
|
9119 |
|
9120 | expGolombDecoder.skipUnsignedExpGolomb();
|
9121 |
|
9122 | expGolombDecoder.skipBits(1);
|
9123 |
|
9124 | picWidthInMbsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
9125 | picHeightInMapUnitsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
9126 | frameMbsOnlyFlag = expGolombDecoder.readBits(1);
|
9127 |
|
9128 | if (frameMbsOnlyFlag === 0) {
|
9129 | expGolombDecoder.skipBits(1);
|
9130 | }
|
9131 |
|
9132 | expGolombDecoder.skipBits(1);
|
9133 |
|
9134 | if (expGolombDecoder.readBoolean()) {
|
9135 |
|
9136 | frameCropLeftOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9137 | frameCropRightOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9138 | frameCropTopOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9139 | frameCropBottomOffset = expGolombDecoder.readUnsignedExpGolomb();
|
9140 | }
|
9141 |
|
9142 | if (expGolombDecoder.readBoolean()) {
|
9143 |
|
9144 | if (expGolombDecoder.readBoolean()) {
|
9145 |
|
9146 | aspectRatioIdc = expGolombDecoder.readUnsignedByte();
|
9147 |
|
9148 | switch (aspectRatioIdc) {
|
9149 | case 1:
|
9150 | sarRatio = [1, 1];
|
9151 | break;
|
9152 |
|
9153 | case 2:
|
9154 | sarRatio = [12, 11];
|
9155 | break;
|
9156 |
|
9157 | case 3:
|
9158 | sarRatio = [10, 11];
|
9159 | break;
|
9160 |
|
9161 | case 4:
|
9162 | sarRatio = [16, 11];
|
9163 | break;
|
9164 |
|
9165 | case 5:
|
9166 | sarRatio = [40, 33];
|
9167 | break;
|
9168 |
|
9169 | case 6:
|
9170 | sarRatio = [24, 11];
|
9171 | break;
|
9172 |
|
9173 | case 7:
|
9174 | sarRatio = [20, 11];
|
9175 | break;
|
9176 |
|
9177 | case 8:
|
9178 | sarRatio = [32, 11];
|
9179 | break;
|
9180 |
|
9181 | case 9:
|
9182 | sarRatio = [80, 33];
|
9183 | break;
|
9184 |
|
9185 | case 10:
|
9186 | sarRatio = [18, 11];
|
9187 | break;
|
9188 |
|
9189 | case 11:
|
9190 | sarRatio = [15, 11];
|
9191 | break;
|
9192 |
|
9193 | case 12:
|
9194 | sarRatio = [64, 33];
|
9195 | break;
|
9196 |
|
9197 | case 13:
|
9198 | sarRatio = [160, 99];
|
9199 | break;
|
9200 |
|
9201 | case 14:
|
9202 | sarRatio = [4, 3];
|
9203 | break;
|
9204 |
|
9205 | case 15:
|
9206 | sarRatio = [3, 2];
|
9207 | break;
|
9208 |
|
9209 | case 16:
|
9210 | sarRatio = [2, 1];
|
9211 | break;
|
9212 |
|
9213 | case 255:
|
9214 | {
|
9215 | sarRatio = [expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte(), expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte()];
|
9216 | break;
|
9217 | }
|
9218 | }
|
9219 |
|
9220 | if (sarRatio) {
|
9221 | sarRatio[0] / sarRatio[1];
|
9222 | }
|
9223 | }
|
9224 | }
|
9225 |
|
9226 | return {
|
9227 | profileIdc: profileIdc,
|
9228 | levelIdc: levelIdc,
|
9229 | profileCompatibility: profileCompatibility,
|
9230 | width: (picWidthInMbsMinus1 + 1) * 16 - frameCropLeftOffset * 2 - frameCropRightOffset * 2,
|
9231 | height: (2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16 - frameCropTopOffset * 2 - frameCropBottomOffset * 2,
|
9232 |
|
9233 | sarRatio: sarRatio
|
9234 | };
|
9235 | };
|
9236 | };
|
9237 |
|
9238 | _H264Stream.prototype = new stream();
|
9239 | var h264 = {
|
9240 | H264Stream: _H264Stream,
|
9241 | NalByteStream: _NalByteStream
|
9242 | };
|
9243 | |
9244 |
|
9245 |
|
9246 |
|
9247 |
|
9248 |
|
9249 |
|
9250 |
|
9251 |
|
9252 | var ADTS_SAMPLING_FREQUENCIES = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
9253 |
|
9254 | var parseId3TagSize = function parseId3TagSize(header, byteIndex) {
|
9255 | var returnSize = header[byteIndex + 6] << 21 | header[byteIndex + 7] << 14 | header[byteIndex + 8] << 7 | header[byteIndex + 9],
|
9256 | flags = header[byteIndex + 5],
|
9257 | footerPresent = (flags & 16) >> 4;
|
9258 |
|
9259 | returnSize = returnSize >= 0 ? returnSize : 0;
|
9260 |
|
9261 | if (footerPresent) {
|
9262 | return returnSize + 20;
|
9263 | }
|
9264 |
|
9265 | return returnSize + 10;
|
9266 | };
|
9267 |
|
9268 | var getId3Offset = function getId3Offset(data, offset) {
|
9269 | if (data.length - offset < 10 || data[offset] !== 'I'.charCodeAt(0) || data[offset + 1] !== 'D'.charCodeAt(0) || data[offset + 2] !== '3'.charCodeAt(0)) {
|
9270 | return offset;
|
9271 | }
|
9272 |
|
9273 | offset += parseId3TagSize(data, offset);
|
9274 | return getId3Offset(data, offset);
|
9275 | };
|
9276 |
|
9277 |
|
9278 | var isLikelyAacData$1 = function isLikelyAacData(data) {
|
9279 | var offset = getId3Offset(data, 0);
|
9280 | return data.length >= offset + 2 && (data[offset] & 0xFF) === 0xFF && (data[offset + 1] & 0xF0) === 0xF0 &&
|
9281 |
|
9282 | (data[offset + 1] & 0x16) === 0x10;
|
9283 | };
|
9284 |
|
9285 | var parseSyncSafeInteger = function parseSyncSafeInteger(data) {
|
9286 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
9287 | };
|
9288 |
|
9289 |
|
9290 |
|
9291 | var percentEncode = function percentEncode(bytes, start, end) {
|
9292 | var i,
|
9293 | result = '';
|
9294 |
|
9295 | for (i = start; i < end; i++) {
|
9296 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
9297 | }
|
9298 |
|
9299 | return result;
|
9300 | };
|
9301 |
|
9302 |
|
9303 |
|
9304 | var parseIso88591 = function parseIso88591(bytes, start, end) {
|
9305 | return unescape(percentEncode(bytes, start, end));
|
9306 | };
|
9307 |
|
9308 | var parseAdtsSize = function parseAdtsSize(header, byteIndex) {
|
9309 | var lowThree = (header[byteIndex + 5] & 0xE0) >> 5,
|
9310 | middle = header[byteIndex + 4] << 3,
|
9311 | highTwo = header[byteIndex + 3] & 0x3 << 11;
|
9312 | return highTwo | middle | lowThree;
|
9313 | };
|
9314 |
|
9315 | var parseType$2 = function parseType(header, byteIndex) {
|
9316 | if (header[byteIndex] === 'I'.charCodeAt(0) && header[byteIndex + 1] === 'D'.charCodeAt(0) && header[byteIndex + 2] === '3'.charCodeAt(0)) {
|
9317 | return 'timed-metadata';
|
9318 | } else if (header[byteIndex] & 0xff === 0xff && (header[byteIndex + 1] & 0xf0) === 0xf0) {
|
9319 | return 'audio';
|
9320 | }
|
9321 |
|
9322 | return null;
|
9323 | };
|
9324 |
|
9325 | var parseSampleRate = function parseSampleRate(packet) {
|
9326 | var i = 0;
|
9327 |
|
9328 | while (i + 5 < packet.length) {
|
9329 | if (packet[i] !== 0xFF || (packet[i + 1] & 0xF6) !== 0xF0) {
|
9330 |
|
9331 |
|
9332 | i++;
|
9333 | continue;
|
9334 | }
|
9335 |
|
9336 | return ADTS_SAMPLING_FREQUENCIES[(packet[i + 2] & 0x3c) >>> 2];
|
9337 | }
|
9338 |
|
9339 | return null;
|
9340 | };
|
9341 |
|
9342 | var parseAacTimestamp = function parseAacTimestamp(packet) {
|
9343 | var frameStart, frameSize, frame, frameHeader;
|
9344 |
|
9345 | frameStart = 10;
|
9346 |
|
9347 | if (packet[5] & 0x40) {
|
9348 |
|
9349 | frameStart += 4;
|
9350 |
|
9351 | frameStart += parseSyncSafeInteger(packet.subarray(10, 14));
|
9352 | }
|
9353 |
|
9354 |
|
9355 |
|
9356 | do {
|
9357 |
|
9358 | frameSize = parseSyncSafeInteger(packet.subarray(frameStart + 4, frameStart + 8));
|
9359 |
|
9360 | if (frameSize < 1) {
|
9361 | return null;
|
9362 | }
|
9363 |
|
9364 | frameHeader = String.fromCharCode(packet[frameStart], packet[frameStart + 1], packet[frameStart + 2], packet[frameStart + 3]);
|
9365 |
|
9366 | if (frameHeader === 'PRIV') {
|
9367 | frame = packet.subarray(frameStart + 10, frameStart + frameSize + 10);
|
9368 |
|
9369 | for (var i = 0; i < frame.byteLength; i++) {
|
9370 | if (frame[i] === 0) {
|
9371 | var owner = parseIso88591(frame, 0, i);
|
9372 |
|
9373 | if (owner === 'com.apple.streaming.transportStreamTimestamp') {
|
9374 | var d = frame.subarray(i + 1);
|
9375 | var size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
9376 | size *= 4;
|
9377 | size += d[7] & 0x03;
|
9378 | return size;
|
9379 | }
|
9380 |
|
9381 | break;
|
9382 | }
|
9383 | }
|
9384 | }
|
9385 |
|
9386 | frameStart += 10;
|
9387 |
|
9388 | frameStart += frameSize;
|
9389 | } while (frameStart < packet.byteLength);
|
9390 |
|
9391 | return null;
|
9392 | };
|
9393 |
|
9394 | var utils = {
|
9395 | isLikelyAacData: isLikelyAacData$1,
|
9396 | parseId3TagSize: parseId3TagSize,
|
9397 | parseAdtsSize: parseAdtsSize,
|
9398 | parseType: parseType$2,
|
9399 | parseSampleRate: parseSampleRate,
|
9400 | parseAacTimestamp: parseAacTimestamp
|
9401 | };
|
9402 |
|
9403 | var _AacStream;
|
9404 | |
9405 |
|
9406 |
|
9407 |
|
9408 |
|
9409 | _AacStream = function AacStream() {
|
9410 | var everything = new Uint8Array(),
|
9411 | timeStamp = 0;
|
9412 |
|
9413 | _AacStream.prototype.init.call(this);
|
9414 |
|
9415 | this.setTimestamp = function (timestamp) {
|
9416 | timeStamp = timestamp;
|
9417 | };
|
9418 |
|
9419 | this.push = function (bytes) {
|
9420 | var frameSize = 0,
|
9421 | byteIndex = 0,
|
9422 | bytesLeft,
|
9423 | chunk,
|
9424 | packet,
|
9425 | tempLength;
|
9426 |
|
9427 |
|
9428 | if (everything.length) {
|
9429 | tempLength = everything.length;
|
9430 | everything = new Uint8Array(bytes.byteLength + tempLength);
|
9431 | everything.set(everything.subarray(0, tempLength));
|
9432 | everything.set(bytes, tempLength);
|
9433 | } else {
|
9434 | everything = bytes;
|
9435 | }
|
9436 |
|
9437 | while (everything.length - byteIndex >= 3) {
|
9438 | if (everything[byteIndex] === 'I'.charCodeAt(0) && everything[byteIndex + 1] === 'D'.charCodeAt(0) && everything[byteIndex + 2] === '3'.charCodeAt(0)) {
|
9439 |
|
9440 |
|
9441 | if (everything.length - byteIndex < 10) {
|
9442 | break;
|
9443 | }
|
9444 |
|
9445 |
|
9446 | frameSize = utils.parseId3TagSize(everything, byteIndex);
|
9447 |
|
9448 |
|
9449 |
|
9450 | if (byteIndex + frameSize > everything.length) {
|
9451 | break;
|
9452 | }
|
9453 |
|
9454 | chunk = {
|
9455 | type: 'timed-metadata',
|
9456 | data: everything.subarray(byteIndex, byteIndex + frameSize)
|
9457 | };
|
9458 | this.trigger('data', chunk);
|
9459 | byteIndex += frameSize;
|
9460 | continue;
|
9461 | } else if ((everything[byteIndex] & 0xff) === 0xff && (everything[byteIndex + 1] & 0xf0) === 0xf0) {
|
9462 |
|
9463 |
|
9464 | if (everything.length - byteIndex < 7) {
|
9465 | break;
|
9466 | }
|
9467 |
|
9468 | frameSize = utils.parseAdtsSize(everything, byteIndex);
|
9469 |
|
9470 |
|
9471 | if (byteIndex + frameSize > everything.length) {
|
9472 | break;
|
9473 | }
|
9474 |
|
9475 | packet = {
|
9476 | type: 'audio',
|
9477 | data: everything.subarray(byteIndex, byteIndex + frameSize),
|
9478 | pts: timeStamp,
|
9479 | dts: timeStamp
|
9480 | };
|
9481 | this.trigger('data', packet);
|
9482 | byteIndex += frameSize;
|
9483 | continue;
|
9484 | }
|
9485 |
|
9486 | byteIndex++;
|
9487 | }
|
9488 |
|
9489 | bytesLeft = everything.length - byteIndex;
|
9490 |
|
9491 | if (bytesLeft > 0) {
|
9492 | everything = everything.subarray(byteIndex);
|
9493 | } else {
|
9494 | everything = new Uint8Array();
|
9495 | }
|
9496 | };
|
9497 |
|
9498 | this.reset = function () {
|
9499 | everything = new Uint8Array();
|
9500 | this.trigger('reset');
|
9501 | };
|
9502 |
|
9503 | this.endTimeline = function () {
|
9504 | everything = new Uint8Array();
|
9505 | this.trigger('endedtimeline');
|
9506 | };
|
9507 | };
|
9508 |
|
9509 | _AacStream.prototype = new stream();
|
9510 | var aac = _AacStream;
|
9511 |
|
9512 | var AUDIO_PROPERTIES = ['audioobjecttype', 'channelcount', 'samplerate', 'samplingfrequencyindex', 'samplesize'];
|
9513 | var audioProperties = AUDIO_PROPERTIES;
|
9514 | var VIDEO_PROPERTIES = ['width', 'height', 'profileIdc', 'levelIdc', 'profileCompatibility', 'sarRatio'];
|
9515 | var videoProperties = VIDEO_PROPERTIES;
|
9516 | var H264Stream = h264.H264Stream;
|
9517 | var isLikelyAacData = utils.isLikelyAacData;
|
9518 | var ONE_SECOND_IN_TS$1 = clock.ONE_SECOND_IN_TS;
|
9519 |
|
9520 | var _VideoSegmentStream, _AudioSegmentStream, _Transmuxer, _CoalesceStream;
|
9521 |
|
9522 | var retriggerForStream = function retriggerForStream(key, event) {
|
9523 | event.stream = key;
|
9524 | this.trigger('log', event);
|
9525 | };
|
9526 |
|
9527 | var addPipelineLogRetriggers = function addPipelineLogRetriggers(transmuxer, pipeline) {
|
9528 | var keys = Object.keys(pipeline);
|
9529 |
|
9530 | for (var i = 0; i < keys.length; i++) {
|
9531 | var key = keys[i];
|
9532 |
|
9533 |
|
9534 | if (key === 'headOfPipeline' || !pipeline[key].on) {
|
9535 | continue;
|
9536 | }
|
9537 |
|
9538 | pipeline[key].on('log', retriggerForStream.bind(transmuxer, key));
|
9539 | }
|
9540 | };
|
9541 | |
9542 |
|
9543 |
|
9544 |
|
9545 |
|
9546 | var arrayEquals = function arrayEquals(a, b) {
|
9547 | var i;
|
9548 |
|
9549 | if (a.length !== b.length) {
|
9550 | return false;
|
9551 | }
|
9552 |
|
9553 |
|
9554 | for (i = 0; i < a.length; i++) {
|
9555 | if (a[i] !== b[i]) {
|
9556 | return false;
|
9557 | }
|
9558 | }
|
9559 |
|
9560 | return true;
|
9561 | };
|
9562 |
|
9563 | var generateSegmentTimingInfo = function generateSegmentTimingInfo(baseMediaDecodeTime, startDts, startPts, endDts, endPts, prependedContentDuration) {
|
9564 | var ptsOffsetFromDts = startPts - startDts,
|
9565 | decodeDuration = endDts - startDts,
|
9566 | presentationDuration = endPts - startPts;
|
9567 |
|
9568 |
|
9569 |
|
9570 |
|
9571 | return {
|
9572 | start: {
|
9573 | dts: baseMediaDecodeTime,
|
9574 | pts: baseMediaDecodeTime + ptsOffsetFromDts
|
9575 | },
|
9576 | end: {
|
9577 | dts: baseMediaDecodeTime + decodeDuration,
|
9578 | pts: baseMediaDecodeTime + presentationDuration
|
9579 | },
|
9580 | prependedContentDuration: prependedContentDuration,
|
9581 | baseMediaDecodeTime: baseMediaDecodeTime
|
9582 | };
|
9583 | };
|
9584 | |
9585 |
|
9586 |
|
9587 |
|
9588 |
|
9589 |
|
9590 |
|
9591 |
|
9592 |
|
9593 |
|
9594 |
|
9595 | _AudioSegmentStream = function AudioSegmentStream(track, options) {
|
9596 | var adtsFrames = [],
|
9597 | sequenceNumber,
|
9598 | earliestAllowedDts = 0,
|
9599 | audioAppendStartTs = 0,
|
9600 | videoBaseMediaDecodeTime = Infinity;
|
9601 | options = options || {};
|
9602 | sequenceNumber = options.firstSequenceNumber || 0;
|
9603 |
|
9604 | _AudioSegmentStream.prototype.init.call(this);
|
9605 |
|
9606 | this.push = function (data) {
|
9607 | trackDecodeInfo.collectDtsInfo(track, data);
|
9608 |
|
9609 | if (track) {
|
9610 | audioProperties.forEach(function (prop) {
|
9611 | track[prop] = data[prop];
|
9612 | });
|
9613 | }
|
9614 |
|
9615 |
|
9616 | adtsFrames.push(data);
|
9617 | };
|
9618 |
|
9619 | this.setEarliestDts = function (earliestDts) {
|
9620 | earliestAllowedDts = earliestDts;
|
9621 | };
|
9622 |
|
9623 | this.setVideoBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
9624 | videoBaseMediaDecodeTime = baseMediaDecodeTime;
|
9625 | };
|
9626 |
|
9627 | this.setAudioAppendStart = function (timestamp) {
|
9628 | audioAppendStartTs = timestamp;
|
9629 | };
|
9630 |
|
9631 | this.flush = function () {
|
9632 | var frames, moof, mdat, boxes, frameDuration, segmentDuration, videoClockCyclesOfSilencePrefixed;
|
9633 |
|
9634 | if (adtsFrames.length === 0) {
|
9635 | this.trigger('done', 'AudioSegmentStream');
|
9636 | return;
|
9637 | }
|
9638 |
|
9639 | frames = audioFrameUtils.trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts);
|
9640 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
9641 |
|
9642 | videoClockCyclesOfSilencePrefixed = audioFrameUtils.prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime);
|
9643 |
|
9644 |
|
9645 | track.samples = audioFrameUtils.generateSampleTable(frames);
|
9646 |
|
9647 | mdat = mp4Generator.mdat(audioFrameUtils.concatenateFrameData(frames));
|
9648 | adtsFrames = [];
|
9649 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
9650 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
9651 |
|
9652 | sequenceNumber++;
|
9653 | boxes.set(moof);
|
9654 | boxes.set(mdat, moof.byteLength);
|
9655 | trackDecodeInfo.clearDtsInfo(track);
|
9656 | frameDuration = Math.ceil(ONE_SECOND_IN_TS$1 * 1024 / track.samplerate);
|
9657 |
|
9658 |
|
9659 |
|
9660 |
|
9661 | if (frames.length) {
|
9662 | segmentDuration = frames.length * frameDuration;
|
9663 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(
|
9664 |
|
9665 |
|
9666 | clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate),
|
9667 | frames[0].dts, frames[0].pts, frames[0].dts + segmentDuration, frames[0].pts + segmentDuration, videoClockCyclesOfSilencePrefixed || 0));
|
9668 | this.trigger('timingInfo', {
|
9669 | start: frames[0].pts,
|
9670 | end: frames[0].pts + segmentDuration
|
9671 | });
|
9672 | }
|
9673 |
|
9674 | this.trigger('data', {
|
9675 | track: track,
|
9676 | boxes: boxes
|
9677 | });
|
9678 | this.trigger('done', 'AudioSegmentStream');
|
9679 | };
|
9680 |
|
9681 | this.reset = function () {
|
9682 | trackDecodeInfo.clearDtsInfo(track);
|
9683 | adtsFrames = [];
|
9684 | this.trigger('reset');
|
9685 | };
|
9686 | };
|
9687 |
|
9688 | _AudioSegmentStream.prototype = new stream();
|
9689 | |
9690 |
|
9691 |
|
9692 |
|
9693 |
|
9694 |
|
9695 |
|
9696 |
|
9697 |
|
9698 |
|
9699 |
|
9700 |
|
9701 | _VideoSegmentStream = function VideoSegmentStream(track, options) {
|
9702 | var sequenceNumber,
|
9703 | nalUnits = [],
|
9704 | gopsToAlignWith = [],
|
9705 | config,
|
9706 | pps;
|
9707 | options = options || {};
|
9708 | sequenceNumber = options.firstSequenceNumber || 0;
|
9709 |
|
9710 | _VideoSegmentStream.prototype.init.call(this);
|
9711 |
|
9712 | delete track.minPTS;
|
9713 | this.gopCache_ = [];
|
9714 | |
9715 |
|
9716 |
|
9717 |
|
9718 |
|
9719 |
|
9720 |
|
9721 |
|
9722 |
|
9723 | this.push = function (nalUnit) {
|
9724 | trackDecodeInfo.collectDtsInfo(track, nalUnit);
|
9725 |
|
9726 | if (nalUnit.nalUnitType === 'seq_parameter_set_rbsp' && !config) {
|
9727 | config = nalUnit.config;
|
9728 | track.sps = [nalUnit.data];
|
9729 | videoProperties.forEach(function (prop) {
|
9730 | track[prop] = config[prop];
|
9731 | }, this);
|
9732 | }
|
9733 |
|
9734 | if (nalUnit.nalUnitType === 'pic_parameter_set_rbsp' && !pps) {
|
9735 | pps = nalUnit.data;
|
9736 | track.pps = [nalUnit.data];
|
9737 | }
|
9738 |
|
9739 |
|
9740 | nalUnits.push(nalUnit);
|
9741 | };
|
9742 | |
9743 |
|
9744 |
|
9745 |
|
9746 |
|
9747 |
|
9748 | this.flush = function () {
|
9749 | var frames,
|
9750 | gopForFusion,
|
9751 | gops,
|
9752 | moof,
|
9753 | mdat,
|
9754 | boxes,
|
9755 | prependedContentDuration = 0,
|
9756 | firstGop,
|
9757 | lastGop;
|
9758 |
|
9759 |
|
9760 | while (nalUnits.length) {
|
9761 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
9762 | break;
|
9763 | }
|
9764 |
|
9765 | nalUnits.shift();
|
9766 | }
|
9767 |
|
9768 |
|
9769 | if (nalUnits.length === 0) {
|
9770 | this.resetStream_();
|
9771 | this.trigger('done', 'VideoSegmentStream');
|
9772 | return;
|
9773 | }
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 | frames = frameUtils.groupNalsIntoFrames(nalUnits);
|
9779 | gops = frameUtils.groupFramesIntoGops(frames);
|
9780 |
|
9781 |
|
9782 |
|
9783 |
|
9784 |
|
9785 |
|
9786 |
|
9787 |
|
9788 |
|
9789 |
|
9790 |
|
9791 |
|
9792 |
|
9793 |
|
9794 |
|
9795 |
|
9796 |
|
9797 |
|
9798 | if (!gops[0][0].keyFrame) {
|
9799 |
|
9800 | gopForFusion = this.getGopForFusion_(nalUnits[0], track);
|
9801 |
|
9802 | if (gopForFusion) {
|
9803 |
|
9804 |
|
9805 | prependedContentDuration = gopForFusion.duration;
|
9806 | gops.unshift(gopForFusion);
|
9807 |
|
9808 |
|
9809 | gops.byteLength += gopForFusion.byteLength;
|
9810 | gops.nalCount += gopForFusion.nalCount;
|
9811 | gops.pts = gopForFusion.pts;
|
9812 | gops.dts = gopForFusion.dts;
|
9813 | gops.duration += gopForFusion.duration;
|
9814 | } else {
|
9815 |
|
9816 | gops = frameUtils.extendFirstKeyFrame(gops);
|
9817 | }
|
9818 | }
|
9819 |
|
9820 |
|
9821 | if (gopsToAlignWith.length) {
|
9822 | var alignedGops;
|
9823 |
|
9824 | if (options.alignGopsAtEnd) {
|
9825 | alignedGops = this.alignGopsAtEnd_(gops);
|
9826 | } else {
|
9827 | alignedGops = this.alignGopsAtStart_(gops);
|
9828 | }
|
9829 |
|
9830 | if (!alignedGops) {
|
9831 |
|
9832 | this.gopCache_.unshift({
|
9833 | gop: gops.pop(),
|
9834 | pps: track.pps,
|
9835 | sps: track.sps
|
9836 | });
|
9837 |
|
9838 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
9839 |
|
9840 | nalUnits = [];
|
9841 |
|
9842 | this.resetStream_();
|
9843 | this.trigger('done', 'VideoSegmentStream');
|
9844 | return;
|
9845 | }
|
9846 |
|
9847 |
|
9848 |
|
9849 | trackDecodeInfo.clearDtsInfo(track);
|
9850 | gops = alignedGops;
|
9851 | }
|
9852 |
|
9853 | trackDecodeInfo.collectDtsInfo(track, gops);
|
9854 |
|
9855 |
|
9856 | track.samples = frameUtils.generateSampleTable(gops);
|
9857 |
|
9858 | mdat = mp4Generator.mdat(frameUtils.concatenateNalData(gops));
|
9859 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
9860 | this.trigger('processedGopsInfo', gops.map(function (gop) {
|
9861 | return {
|
9862 | pts: gop.pts,
|
9863 | dts: gop.dts,
|
9864 | byteLength: gop.byteLength
|
9865 | };
|
9866 | }));
|
9867 | firstGop = gops[0];
|
9868 | lastGop = gops[gops.length - 1];
|
9869 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(track.baseMediaDecodeTime, firstGop.dts, firstGop.pts, lastGop.dts + lastGop.duration, lastGop.pts + lastGop.duration, prependedContentDuration));
|
9870 | this.trigger('timingInfo', {
|
9871 | start: gops[0].pts,
|
9872 | end: gops[gops.length - 1].pts + gops[gops.length - 1].duration
|
9873 | });
|
9874 |
|
9875 | this.gopCache_.unshift({
|
9876 | gop: gops.pop(),
|
9877 | pps: track.pps,
|
9878 | sps: track.sps
|
9879 | });
|
9880 |
|
9881 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
9882 |
|
9883 | nalUnits = [];
|
9884 | this.trigger('baseMediaDecodeTime', track.baseMediaDecodeTime);
|
9885 | this.trigger('timelineStartInfo', track.timelineStartInfo);
|
9886 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
9887 |
|
9888 |
|
9889 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
9890 |
|
9891 | sequenceNumber++;
|
9892 | boxes.set(moof);
|
9893 | boxes.set(mdat, moof.byteLength);
|
9894 | this.trigger('data', {
|
9895 | track: track,
|
9896 | boxes: boxes
|
9897 | });
|
9898 | this.resetStream_();
|
9899 |
|
9900 | this.trigger('done', 'VideoSegmentStream');
|
9901 | };
|
9902 |
|
9903 | this.reset = function () {
|
9904 | this.resetStream_();
|
9905 | nalUnits = [];
|
9906 | this.gopCache_.length = 0;
|
9907 | gopsToAlignWith.length = 0;
|
9908 | this.trigger('reset');
|
9909 | };
|
9910 |
|
9911 | this.resetStream_ = function () {
|
9912 | trackDecodeInfo.clearDtsInfo(track);
|
9913 |
|
9914 |
|
9915 | config = undefined;
|
9916 | pps = undefined;
|
9917 | };
|
9918 |
|
9919 |
|
9920 |
|
9921 | this.getGopForFusion_ = function (nalUnit) {
|
9922 | var halfSecond = 45000,
|
9923 |
|
9924 | allowableOverlap = 10000,
|
9925 |
|
9926 | nearestDistance = Infinity,
|
9927 | dtsDistance,
|
9928 | nearestGopObj,
|
9929 | currentGop,
|
9930 | currentGopObj,
|
9931 | i;
|
9932 |
|
9933 | for (i = 0; i < this.gopCache_.length; i++) {
|
9934 | currentGopObj = this.gopCache_[i];
|
9935 | currentGop = currentGopObj.gop;
|
9936 |
|
9937 | if (!(track.pps && arrayEquals(track.pps[0], currentGopObj.pps[0])) || !(track.sps && arrayEquals(track.sps[0], currentGopObj.sps[0]))) {
|
9938 | continue;
|
9939 | }
|
9940 |
|
9941 |
|
9942 | if (currentGop.dts < track.timelineStartInfo.dts) {
|
9943 | continue;
|
9944 | }
|
9945 |
|
9946 |
|
9947 | dtsDistance = nalUnit.dts - currentGop.dts - currentGop.duration;
|
9948 |
|
9949 |
|
9950 | if (dtsDistance >= -allowableOverlap && dtsDistance <= halfSecond) {
|
9951 |
|
9952 |
|
9953 | if (!nearestGopObj || nearestDistance > dtsDistance) {
|
9954 | nearestGopObj = currentGopObj;
|
9955 | nearestDistance = dtsDistance;
|
9956 | }
|
9957 | }
|
9958 | }
|
9959 |
|
9960 | if (nearestGopObj) {
|
9961 | return nearestGopObj.gop;
|
9962 | }
|
9963 |
|
9964 | return null;
|
9965 | };
|
9966 |
|
9967 |
|
9968 |
|
9969 | this.alignGopsAtStart_ = function (gops) {
|
9970 | var alignIndex, gopIndex, align, gop, byteLength, nalCount, duration, alignedGops;
|
9971 | byteLength = gops.byteLength;
|
9972 | nalCount = gops.nalCount;
|
9973 | duration = gops.duration;
|
9974 | alignIndex = gopIndex = 0;
|
9975 |
|
9976 | while (alignIndex < gopsToAlignWith.length && gopIndex < gops.length) {
|
9977 | align = gopsToAlignWith[alignIndex];
|
9978 | gop = gops[gopIndex];
|
9979 |
|
9980 | if (align.pts === gop.pts) {
|
9981 | break;
|
9982 | }
|
9983 |
|
9984 | if (gop.pts > align.pts) {
|
9985 |
|
9986 |
|
9987 | alignIndex++;
|
9988 | continue;
|
9989 | }
|
9990 |
|
9991 |
|
9992 |
|
9993 | gopIndex++;
|
9994 | byteLength -= gop.byteLength;
|
9995 | nalCount -= gop.nalCount;
|
9996 | duration -= gop.duration;
|
9997 | }
|
9998 |
|
9999 | if (gopIndex === 0) {
|
10000 |
|
10001 | return gops;
|
10002 | }
|
10003 |
|
10004 | if (gopIndex === gops.length) {
|
10005 |
|
10006 | return null;
|
10007 | }
|
10008 |
|
10009 | alignedGops = gops.slice(gopIndex);
|
10010 | alignedGops.byteLength = byteLength;
|
10011 | alignedGops.duration = duration;
|
10012 | alignedGops.nalCount = nalCount;
|
10013 | alignedGops.pts = alignedGops[0].pts;
|
10014 | alignedGops.dts = alignedGops[0].dts;
|
10015 | return alignedGops;
|
10016 | };
|
10017 |
|
10018 |
|
10019 |
|
10020 | this.alignGopsAtEnd_ = function (gops) {
|
10021 | var alignIndex, gopIndex, align, gop, alignEndIndex, matchFound;
|
10022 | alignIndex = gopsToAlignWith.length - 1;
|
10023 | gopIndex = gops.length - 1;
|
10024 | alignEndIndex = null;
|
10025 | matchFound = false;
|
10026 |
|
10027 | while (alignIndex >= 0 && gopIndex >= 0) {
|
10028 | align = gopsToAlignWith[alignIndex];
|
10029 | gop = gops[gopIndex];
|
10030 |
|
10031 | if (align.pts === gop.pts) {
|
10032 | matchFound = true;
|
10033 | break;
|
10034 | }
|
10035 |
|
10036 | if (align.pts > gop.pts) {
|
10037 | alignIndex--;
|
10038 | continue;
|
10039 | }
|
10040 |
|
10041 | if (alignIndex === gopsToAlignWith.length - 1) {
|
10042 |
|
10043 |
|
10044 |
|
10045 | alignEndIndex = gopIndex;
|
10046 | }
|
10047 |
|
10048 | gopIndex--;
|
10049 | }
|
10050 |
|
10051 | if (!matchFound && alignEndIndex === null) {
|
10052 | return null;
|
10053 | }
|
10054 |
|
10055 | var trimIndex;
|
10056 |
|
10057 | if (matchFound) {
|
10058 | trimIndex = gopIndex;
|
10059 | } else {
|
10060 | trimIndex = alignEndIndex;
|
10061 | }
|
10062 |
|
10063 | if (trimIndex === 0) {
|
10064 | return gops;
|
10065 | }
|
10066 |
|
10067 | var alignedGops = gops.slice(trimIndex);
|
10068 | var metadata = alignedGops.reduce(function (total, gop) {
|
10069 | total.byteLength += gop.byteLength;
|
10070 | total.duration += gop.duration;
|
10071 | total.nalCount += gop.nalCount;
|
10072 | return total;
|
10073 | }, {
|
10074 | byteLength: 0,
|
10075 | duration: 0,
|
10076 | nalCount: 0
|
10077 | });
|
10078 | alignedGops.byteLength = metadata.byteLength;
|
10079 | alignedGops.duration = metadata.duration;
|
10080 | alignedGops.nalCount = metadata.nalCount;
|
10081 | alignedGops.pts = alignedGops[0].pts;
|
10082 | alignedGops.dts = alignedGops[0].dts;
|
10083 | return alignedGops;
|
10084 | };
|
10085 |
|
10086 | this.alignGopsWith = function (newGopsToAlignWith) {
|
10087 | gopsToAlignWith = newGopsToAlignWith;
|
10088 | };
|
10089 | };
|
10090 |
|
10091 | _VideoSegmentStream.prototype = new stream();
|
10092 | |
10093 |
|
10094 |
|
10095 |
|
10096 |
|
10097 |
|
10098 |
|
10099 |
|
10100 |
|
10101 | _CoalesceStream = function CoalesceStream(options, metadataStream) {
|
10102 |
|
10103 |
|
10104 |
|
10105 | this.numberOfTracks = 0;
|
10106 | this.metadataStream = metadataStream;
|
10107 | options = options || {};
|
10108 |
|
10109 | if (typeof options.remux !== 'undefined') {
|
10110 | this.remuxTracks = !!options.remux;
|
10111 | } else {
|
10112 | this.remuxTracks = true;
|
10113 | }
|
10114 |
|
10115 | if (typeof options.keepOriginalTimestamps === 'boolean') {
|
10116 | this.keepOriginalTimestamps = options.keepOriginalTimestamps;
|
10117 | } else {
|
10118 | this.keepOriginalTimestamps = false;
|
10119 | }
|
10120 |
|
10121 | this.pendingTracks = [];
|
10122 | this.videoTrack = null;
|
10123 | this.pendingBoxes = [];
|
10124 | this.pendingCaptions = [];
|
10125 | this.pendingMetadata = [];
|
10126 | this.pendingBytes = 0;
|
10127 | this.emittedTracks = 0;
|
10128 |
|
10129 | _CoalesceStream.prototype.init.call(this);
|
10130 |
|
10131 |
|
10132 | this.push = function (output) {
|
10133 |
|
10134 |
|
10135 | if (output.text) {
|
10136 | return this.pendingCaptions.push(output);
|
10137 | }
|
10138 |
|
10139 |
|
10140 | if (output.frames) {
|
10141 | return this.pendingMetadata.push(output);
|
10142 | }
|
10143 |
|
10144 |
|
10145 |
|
10146 |
|
10147 | this.pendingTracks.push(output.track);
|
10148 | this.pendingBytes += output.boxes.byteLength;
|
10149 |
|
10150 |
|
10151 |
|
10152 |
|
10153 |
|
10154 |
|
10155 | if (output.track.type === 'video') {
|
10156 | this.videoTrack = output.track;
|
10157 | this.pendingBoxes.push(output.boxes);
|
10158 | }
|
10159 |
|
10160 | if (output.track.type === 'audio') {
|
10161 | this.audioTrack = output.track;
|
10162 | this.pendingBoxes.unshift(output.boxes);
|
10163 | }
|
10164 | };
|
10165 | };
|
10166 |
|
10167 | _CoalesceStream.prototype = new stream();
|
10168 |
|
10169 | _CoalesceStream.prototype.flush = function (flushSource) {
|
10170 | var offset = 0,
|
10171 | event = {
|
10172 | captions: [],
|
10173 | captionStreams: {},
|
10174 | metadata: [],
|
10175 | info: {}
|
10176 | },
|
10177 | caption,
|
10178 | id3,
|
10179 | initSegment,
|
10180 | timelineStartPts = 0,
|
10181 | i;
|
10182 |
|
10183 | if (this.pendingTracks.length < this.numberOfTracks) {
|
10184 | if (flushSource !== 'VideoSegmentStream' && flushSource !== 'AudioSegmentStream') {
|
10185 |
|
10186 |
|
10187 |
|
10188 | return;
|
10189 | } else if (this.remuxTracks) {
|
10190 |
|
10191 |
|
10192 | return;
|
10193 | } else if (this.pendingTracks.length === 0) {
|
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 |
|
10199 |
|
10200 | this.emittedTracks++;
|
10201 |
|
10202 | if (this.emittedTracks >= this.numberOfTracks) {
|
10203 | this.trigger('done');
|
10204 | this.emittedTracks = 0;
|
10205 | }
|
10206 |
|
10207 | return;
|
10208 | }
|
10209 | }
|
10210 |
|
10211 | if (this.videoTrack) {
|
10212 | timelineStartPts = this.videoTrack.timelineStartInfo.pts;
|
10213 | videoProperties.forEach(function (prop) {
|
10214 | event.info[prop] = this.videoTrack[prop];
|
10215 | }, this);
|
10216 | } else if (this.audioTrack) {
|
10217 | timelineStartPts = this.audioTrack.timelineStartInfo.pts;
|
10218 | audioProperties.forEach(function (prop) {
|
10219 | event.info[prop] = this.audioTrack[prop];
|
10220 | }, this);
|
10221 | }
|
10222 |
|
10223 | if (this.videoTrack || this.audioTrack) {
|
10224 | if (this.pendingTracks.length === 1) {
|
10225 | event.type = this.pendingTracks[0].type;
|
10226 | } else {
|
10227 | event.type = 'combined';
|
10228 | }
|
10229 |
|
10230 | this.emittedTracks += this.pendingTracks.length;
|
10231 | initSegment = mp4Generator.initSegment(this.pendingTracks);
|
10232 |
|
10233 | event.initSegment = new Uint8Array(initSegment.byteLength);
|
10234 |
|
10235 |
|
10236 | event.initSegment.set(initSegment);
|
10237 |
|
10238 | event.data = new Uint8Array(this.pendingBytes);
|
10239 |
|
10240 | for (i = 0; i < this.pendingBoxes.length; i++) {
|
10241 | event.data.set(this.pendingBoxes[i], offset);
|
10242 | offset += this.pendingBoxes[i].byteLength;
|
10243 | }
|
10244 |
|
10245 |
|
10246 |
|
10247 | for (i = 0; i < this.pendingCaptions.length; i++) {
|
10248 | caption = this.pendingCaptions[i];
|
10249 | caption.startTime = clock.metadataTsToSeconds(caption.startPts, timelineStartPts, this.keepOriginalTimestamps);
|
10250 | caption.endTime = clock.metadataTsToSeconds(caption.endPts, timelineStartPts, this.keepOriginalTimestamps);
|
10251 | event.captionStreams[caption.stream] = true;
|
10252 | event.captions.push(caption);
|
10253 | }
|
10254 |
|
10255 |
|
10256 |
|
10257 | for (i = 0; i < this.pendingMetadata.length; i++) {
|
10258 | id3 = this.pendingMetadata[i];
|
10259 | id3.cueTime = clock.metadataTsToSeconds(id3.pts, timelineStartPts, this.keepOriginalTimestamps);
|
10260 | event.metadata.push(id3);
|
10261 | }
|
10262 |
|
10263 |
|
10264 |
|
10265 | event.metadata.dispatchType = this.metadataStream.dispatchType;
|
10266 |
|
10267 | this.pendingTracks.length = 0;
|
10268 | this.videoTrack = null;
|
10269 | this.pendingBoxes.length = 0;
|
10270 | this.pendingCaptions.length = 0;
|
10271 | this.pendingBytes = 0;
|
10272 | this.pendingMetadata.length = 0;
|
10273 |
|
10274 |
|
10275 |
|
10276 | this.trigger('data', event);
|
10277 |
|
10278 |
|
10279 |
|
10280 |
|
10281 | for (i = 0; i < event.captions.length; i++) {
|
10282 | caption = event.captions[i];
|
10283 | this.trigger('caption', caption);
|
10284 | }
|
10285 |
|
10286 |
|
10287 |
|
10288 |
|
10289 |
|
10290 | for (i = 0; i < event.metadata.length; i++) {
|
10291 | id3 = event.metadata[i];
|
10292 | this.trigger('id3Frame', id3);
|
10293 | }
|
10294 | }
|
10295 |
|
10296 |
|
10297 | if (this.emittedTracks >= this.numberOfTracks) {
|
10298 | this.trigger('done');
|
10299 | this.emittedTracks = 0;
|
10300 | }
|
10301 | };
|
10302 |
|
10303 | _CoalesceStream.prototype.setRemux = function (val) {
|
10304 | this.remuxTracks = val;
|
10305 | };
|
10306 | |
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 | _Transmuxer = function Transmuxer(options) {
|
10315 | var self = this,
|
10316 | hasFlushed = true,
|
10317 | videoTrack,
|
10318 | audioTrack;
|
10319 |
|
10320 | _Transmuxer.prototype.init.call(this);
|
10321 |
|
10322 | options = options || {};
|
10323 | this.baseMediaDecodeTime = options.baseMediaDecodeTime || 0;
|
10324 | this.transmuxPipeline_ = {};
|
10325 |
|
10326 | this.setupAacPipeline = function () {
|
10327 | var pipeline = {};
|
10328 | this.transmuxPipeline_ = pipeline;
|
10329 | pipeline.type = 'aac';
|
10330 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
10331 |
|
10332 | pipeline.aacStream = new aac();
|
10333 | pipeline.audioTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('audio');
|
10334 | pipeline.timedMetadataTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('timed-metadata');
|
10335 | pipeline.adtsStream = new adts();
|
10336 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
10337 | pipeline.headOfPipeline = pipeline.aacStream;
|
10338 | pipeline.aacStream.pipe(pipeline.audioTimestampRolloverStream).pipe(pipeline.adtsStream);
|
10339 | pipeline.aacStream.pipe(pipeline.timedMetadataTimestampRolloverStream).pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
10340 | pipeline.metadataStream.on('timestamp', function (frame) {
|
10341 | pipeline.aacStream.setTimestamp(frame.timeStamp);
|
10342 | });
|
10343 | pipeline.aacStream.on('data', function (data) {
|
10344 | if (data.type !== 'timed-metadata' && data.type !== 'audio' || pipeline.audioSegmentStream) {
|
10345 | return;
|
10346 | }
|
10347 |
|
10348 | audioTrack = audioTrack || {
|
10349 | timelineStartInfo: {
|
10350 | baseMediaDecodeTime: self.baseMediaDecodeTime
|
10351 | },
|
10352 | codec: 'adts',
|
10353 | type: 'audio'
|
10354 | };
|
10355 |
|
10356 | pipeline.coalesceStream.numberOfTracks++;
|
10357 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
10358 | pipeline.audioSegmentStream.on('log', self.getLogTrigger_('audioSegmentStream'));
|
10359 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
10360 |
|
10361 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
10362 |
|
10363 | self.trigger('trackinfo', {
|
10364 | hasAudio: !!audioTrack,
|
10365 | hasVideo: !!videoTrack
|
10366 | });
|
10367 | });
|
10368 |
|
10369 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
10370 |
|
10371 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
10372 | addPipelineLogRetriggers(this, pipeline);
|
10373 | };
|
10374 |
|
10375 | this.setupTsPipeline = function () {
|
10376 | var pipeline = {};
|
10377 | this.transmuxPipeline_ = pipeline;
|
10378 | pipeline.type = 'ts';
|
10379 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
10380 |
|
10381 | pipeline.packetStream = new m2ts_1.TransportPacketStream();
|
10382 | pipeline.parseStream = new m2ts_1.TransportParseStream();
|
10383 | pipeline.elementaryStream = new m2ts_1.ElementaryStream();
|
10384 | pipeline.timestampRolloverStream = new m2ts_1.TimestampRolloverStream();
|
10385 | pipeline.adtsStream = new adts();
|
10386 | pipeline.h264Stream = new H264Stream();
|
10387 | pipeline.captionStream = new m2ts_1.CaptionStream(options);
|
10388 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
10389 | pipeline.headOfPipeline = pipeline.packetStream;
|
10390 |
|
10391 | pipeline.packetStream.pipe(pipeline.parseStream).pipe(pipeline.elementaryStream).pipe(pipeline.timestampRolloverStream);
|
10392 |
|
10393 |
|
10394 | pipeline.timestampRolloverStream.pipe(pipeline.h264Stream);
|
10395 | pipeline.timestampRolloverStream.pipe(pipeline.adtsStream);
|
10396 | pipeline.timestampRolloverStream.pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
10397 |
|
10398 | pipeline.h264Stream.pipe(pipeline.captionStream).pipe(pipeline.coalesceStream);
|
10399 | pipeline.elementaryStream.on('data', function (data) {
|
10400 | var i;
|
10401 |
|
10402 | if (data.type === 'metadata') {
|
10403 | i = data.tracks.length;
|
10404 |
|
10405 | while (i--) {
|
10406 | if (!videoTrack && data.tracks[i].type === 'video') {
|
10407 | videoTrack = data.tracks[i];
|
10408 | videoTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
10409 | } else if (!audioTrack && data.tracks[i].type === 'audio') {
|
10410 | audioTrack = data.tracks[i];
|
10411 | audioTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
10412 | }
|
10413 | }
|
10414 |
|
10415 |
|
10416 | if (videoTrack && !pipeline.videoSegmentStream) {
|
10417 | pipeline.coalesceStream.numberOfTracks++;
|
10418 | pipeline.videoSegmentStream = new _VideoSegmentStream(videoTrack, options);
|
10419 | pipeline.videoSegmentStream.on('log', self.getLogTrigger_('videoSegmentStream'));
|
10420 | pipeline.videoSegmentStream.on('timelineStartInfo', function (timelineStartInfo) {
|
10421 |
|
10422 |
|
10423 |
|
10424 |
|
10425 | if (audioTrack && !options.keepOriginalTimestamps) {
|
10426 | audioTrack.timelineStartInfo = timelineStartInfo;
|
10427 |
|
10428 |
|
10429 |
|
10430 |
|
10431 | pipeline.audioSegmentStream.setEarliestDts(timelineStartInfo.dts - self.baseMediaDecodeTime);
|
10432 | }
|
10433 | });
|
10434 | pipeline.videoSegmentStream.on('processedGopsInfo', self.trigger.bind(self, 'gopInfo'));
|
10435 | pipeline.videoSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'videoSegmentTimingInfo'));
|
10436 | pipeline.videoSegmentStream.on('baseMediaDecodeTime', function (baseMediaDecodeTime) {
|
10437 | if (audioTrack) {
|
10438 | pipeline.audioSegmentStream.setVideoBaseMediaDecodeTime(baseMediaDecodeTime);
|
10439 | }
|
10440 | });
|
10441 | pipeline.videoSegmentStream.on('timingInfo', self.trigger.bind(self, 'videoTimingInfo'));
|
10442 |
|
10443 | pipeline.h264Stream.pipe(pipeline.videoSegmentStream).pipe(pipeline.coalesceStream);
|
10444 | }
|
10445 |
|
10446 | if (audioTrack && !pipeline.audioSegmentStream) {
|
10447 |
|
10448 | pipeline.coalesceStream.numberOfTracks++;
|
10449 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
10450 | pipeline.audioSegmentStream.on('log', self.getLogTrigger_('audioSegmentStream'));
|
10451 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
10452 | pipeline.audioSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'audioSegmentTimingInfo'));
|
10453 |
|
10454 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
10455 | }
|
10456 |
|
10457 |
|
10458 | self.trigger('trackinfo', {
|
10459 | hasAudio: !!audioTrack,
|
10460 | hasVideo: !!videoTrack
|
10461 | });
|
10462 | }
|
10463 | });
|
10464 |
|
10465 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
10466 | pipeline.coalesceStream.on('id3Frame', function (id3Frame) {
|
10467 | id3Frame.dispatchType = pipeline.metadataStream.dispatchType;
|
10468 | self.trigger('id3Frame', id3Frame);
|
10469 | });
|
10470 | pipeline.coalesceStream.on('caption', this.trigger.bind(this, 'caption'));
|
10471 |
|
10472 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
10473 | addPipelineLogRetriggers(this, pipeline);
|
10474 | };
|
10475 |
|
10476 |
|
10477 | this.setBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
10478 | var pipeline = this.transmuxPipeline_;
|
10479 |
|
10480 | if (!options.keepOriginalTimestamps) {
|
10481 | this.baseMediaDecodeTime = baseMediaDecodeTime;
|
10482 | }
|
10483 |
|
10484 | if (audioTrack) {
|
10485 | audioTrack.timelineStartInfo.dts = undefined;
|
10486 | audioTrack.timelineStartInfo.pts = undefined;
|
10487 | trackDecodeInfo.clearDtsInfo(audioTrack);
|
10488 |
|
10489 | if (pipeline.audioTimestampRolloverStream) {
|
10490 | pipeline.audioTimestampRolloverStream.discontinuity();
|
10491 | }
|
10492 | }
|
10493 |
|
10494 | if (videoTrack) {
|
10495 | if (pipeline.videoSegmentStream) {
|
10496 | pipeline.videoSegmentStream.gopCache_ = [];
|
10497 | }
|
10498 |
|
10499 | videoTrack.timelineStartInfo.dts = undefined;
|
10500 | videoTrack.timelineStartInfo.pts = undefined;
|
10501 | trackDecodeInfo.clearDtsInfo(videoTrack);
|
10502 | pipeline.captionStream.reset();
|
10503 | }
|
10504 |
|
10505 | if (pipeline.timestampRolloverStream) {
|
10506 | pipeline.timestampRolloverStream.discontinuity();
|
10507 | }
|
10508 | };
|
10509 |
|
10510 | this.setAudioAppendStart = function (timestamp) {
|
10511 | if (audioTrack) {
|
10512 | this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(timestamp);
|
10513 | }
|
10514 | };
|
10515 |
|
10516 | this.setRemux = function (val) {
|
10517 | var pipeline = this.transmuxPipeline_;
|
10518 | options.remux = val;
|
10519 |
|
10520 | if (pipeline && pipeline.coalesceStream) {
|
10521 | pipeline.coalesceStream.setRemux(val);
|
10522 | }
|
10523 | };
|
10524 |
|
10525 | this.alignGopsWith = function (gopsToAlignWith) {
|
10526 | if (videoTrack && this.transmuxPipeline_.videoSegmentStream) {
|
10527 | this.transmuxPipeline_.videoSegmentStream.alignGopsWith(gopsToAlignWith);
|
10528 | }
|
10529 | };
|
10530 |
|
10531 | this.getLogTrigger_ = function (key) {
|
10532 | var self = this;
|
10533 | return function (event) {
|
10534 | event.stream = key;
|
10535 | self.trigger('log', event);
|
10536 | };
|
10537 | };
|
10538 |
|
10539 |
|
10540 | this.push = function (data) {
|
10541 | if (hasFlushed) {
|
10542 | var isAac = isLikelyAacData(data);
|
10543 |
|
10544 | if (isAac && this.transmuxPipeline_.type !== 'aac') {
|
10545 | this.setupAacPipeline();
|
10546 | } else if (!isAac && this.transmuxPipeline_.type !== 'ts') {
|
10547 | this.setupTsPipeline();
|
10548 | }
|
10549 |
|
10550 | hasFlushed = false;
|
10551 | }
|
10552 |
|
10553 | this.transmuxPipeline_.headOfPipeline.push(data);
|
10554 | };
|
10555 |
|
10556 |
|
10557 | this.flush = function () {
|
10558 | hasFlushed = true;
|
10559 |
|
10560 | this.transmuxPipeline_.headOfPipeline.flush();
|
10561 | };
|
10562 |
|
10563 | this.endTimeline = function () {
|
10564 | this.transmuxPipeline_.headOfPipeline.endTimeline();
|
10565 | };
|
10566 |
|
10567 | this.reset = function () {
|
10568 | if (this.transmuxPipeline_.headOfPipeline) {
|
10569 | this.transmuxPipeline_.headOfPipeline.reset();
|
10570 | }
|
10571 | };
|
10572 |
|
10573 |
|
10574 | this.resetCaptions = function () {
|
10575 | if (this.transmuxPipeline_.captionStream) {
|
10576 | this.transmuxPipeline_.captionStream.reset();
|
10577 | }
|
10578 | };
|
10579 | };
|
10580 |
|
10581 | _Transmuxer.prototype = new stream();
|
10582 | var transmuxer = {
|
10583 | Transmuxer: _Transmuxer,
|
10584 | VideoSegmentStream: _VideoSegmentStream,
|
10585 | AudioSegmentStream: _AudioSegmentStream,
|
10586 | AUDIO_PROPERTIES: audioProperties,
|
10587 | VIDEO_PROPERTIES: videoProperties,
|
10588 |
|
10589 | generateSegmentTimingInfo: generateSegmentTimingInfo
|
10590 | };
|
10591 | |
10592 |
|
10593 |
|
10594 |
|
10595 |
|
10596 |
|
10597 |
|
10598 | var toUnsigned$3 = function toUnsigned(value) {
|
10599 | return value >>> 0;
|
10600 | };
|
10601 |
|
10602 | var toHexString$1 = function toHexString(value) {
|
10603 | return ('00' + value.toString(16)).slice(-2);
|
10604 | };
|
10605 |
|
10606 | var bin = {
|
10607 | toUnsigned: toUnsigned$3,
|
10608 | toHexString: toHexString$1
|
10609 | };
|
10610 |
|
10611 | var parseType$1 = function parseType(buffer) {
|
10612 | var result = '';
|
10613 | result += String.fromCharCode(buffer[0]);
|
10614 | result += String.fromCharCode(buffer[1]);
|
10615 | result += String.fromCharCode(buffer[2]);
|
10616 | result += String.fromCharCode(buffer[3]);
|
10617 | return result;
|
10618 | };
|
10619 |
|
10620 | var parseType_1 = parseType$1;
|
10621 | var toUnsigned$2 = bin.toUnsigned;
|
10622 |
|
10623 | var findBox = function findBox(data, path) {
|
10624 | var results = [],
|
10625 | i,
|
10626 | size,
|
10627 | type,
|
10628 | end,
|
10629 | subresults;
|
10630 |
|
10631 | if (!path.length) {
|
10632 |
|
10633 | return null;
|
10634 | }
|
10635 |
|
10636 | for (i = 0; i < data.byteLength;) {
|
10637 | size = toUnsigned$2(data[i] << 24 | data[i + 1] << 16 | data[i + 2] << 8 | data[i + 3]);
|
10638 | type = parseType_1(data.subarray(i + 4, i + 8));
|
10639 | end = size > 1 ? i + size : data.byteLength;
|
10640 |
|
10641 | if (type === path[0]) {
|
10642 | if (path.length === 1) {
|
10643 |
|
10644 |
|
10645 | results.push(data.subarray(i + 8, end));
|
10646 | } else {
|
10647 |
|
10648 | subresults = findBox(data.subarray(i + 8, end), path.slice(1));
|
10649 |
|
10650 | if (subresults.length) {
|
10651 | results = results.concat(subresults);
|
10652 | }
|
10653 | }
|
10654 | }
|
10655 |
|
10656 | i = end;
|
10657 | }
|
10658 |
|
10659 |
|
10660 | return results;
|
10661 | };
|
10662 |
|
10663 | var findBox_1 = findBox;
|
10664 | var toUnsigned$1 = bin.toUnsigned;
|
10665 |
|
10666 | var tfdt = function tfdt(data) {
|
10667 | var result = {
|
10668 | version: data[0],
|
10669 | flags: new Uint8Array(data.subarray(1, 4)),
|
10670 | baseMediaDecodeTime: toUnsigned$1(data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7])
|
10671 | };
|
10672 |
|
10673 | if (result.version === 1) {
|
10674 | result.baseMediaDecodeTime *= Math.pow(2, 32);
|
10675 | result.baseMediaDecodeTime += toUnsigned$1(data[8] << 24 | data[9] << 16 | data[10] << 8 | data[11]);
|
10676 | }
|
10677 |
|
10678 | return result;
|
10679 | };
|
10680 |
|
10681 | var parseTfdt = tfdt;
|
10682 |
|
10683 | var parseSampleFlags = function parseSampleFlags(flags) {
|
10684 | return {
|
10685 | isLeading: (flags[0] & 0x0c) >>> 2,
|
10686 | dependsOn: flags[0] & 0x03,
|
10687 | isDependedOn: (flags[1] & 0xc0) >>> 6,
|
10688 | hasRedundancy: (flags[1] & 0x30) >>> 4,
|
10689 | paddingValue: (flags[1] & 0x0e) >>> 1,
|
10690 | isNonSyncSample: flags[1] & 0x01,
|
10691 | degradationPriority: flags[2] << 8 | flags[3]
|
10692 | };
|
10693 | };
|
10694 |
|
10695 | var parseSampleFlags_1 = parseSampleFlags;
|
10696 |
|
10697 | var trun = function trun(data) {
|
10698 | var result = {
|
10699 | version: data[0],
|
10700 | flags: new Uint8Array(data.subarray(1, 4)),
|
10701 | samples: []
|
10702 | },
|
10703 | view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
10704 |
|
10705 | dataOffsetPresent = result.flags[2] & 0x01,
|
10706 |
|
10707 | firstSampleFlagsPresent = result.flags[2] & 0x04,
|
10708 |
|
10709 | sampleDurationPresent = result.flags[1] & 0x01,
|
10710 |
|
10711 | sampleSizePresent = result.flags[1] & 0x02,
|
10712 |
|
10713 | sampleFlagsPresent = result.flags[1] & 0x04,
|
10714 |
|
10715 | sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08,
|
10716 |
|
10717 | sampleCount = view.getUint32(4),
|
10718 | offset = 8,
|
10719 | sample;
|
10720 |
|
10721 | if (dataOffsetPresent) {
|
10722 |
|
10723 | result.dataOffset = view.getInt32(offset);
|
10724 | offset += 4;
|
10725 | }
|
10726 |
|
10727 |
|
10728 |
|
10729 | if (firstSampleFlagsPresent && sampleCount) {
|
10730 | sample = {
|
10731 | flags: parseSampleFlags_1(data.subarray(offset, offset + 4))
|
10732 | };
|
10733 | offset += 4;
|
10734 |
|
10735 | if (sampleDurationPresent) {
|
10736 | sample.duration = view.getUint32(offset);
|
10737 | offset += 4;
|
10738 | }
|
10739 |
|
10740 | if (sampleSizePresent) {
|
10741 | sample.size = view.getUint32(offset);
|
10742 | offset += 4;
|
10743 | }
|
10744 |
|
10745 | if (sampleCompositionTimeOffsetPresent) {
|
10746 | if (result.version === 1) {
|
10747 | sample.compositionTimeOffset = view.getInt32(offset);
|
10748 | } else {
|
10749 | sample.compositionTimeOffset = view.getUint32(offset);
|
10750 | }
|
10751 |
|
10752 | offset += 4;
|
10753 | }
|
10754 |
|
10755 | result.samples.push(sample);
|
10756 | sampleCount--;
|
10757 | }
|
10758 |
|
10759 | while (sampleCount--) {
|
10760 | sample = {};
|
10761 |
|
10762 | if (sampleDurationPresent) {
|
10763 | sample.duration = view.getUint32(offset);
|
10764 | offset += 4;
|
10765 | }
|
10766 |
|
10767 | if (sampleSizePresent) {
|
10768 | sample.size = view.getUint32(offset);
|
10769 | offset += 4;
|
10770 | }
|
10771 |
|
10772 | if (sampleFlagsPresent) {
|
10773 | sample.flags = parseSampleFlags_1(data.subarray(offset, offset + 4));
|
10774 | offset += 4;
|
10775 | }
|
10776 |
|
10777 | if (sampleCompositionTimeOffsetPresent) {
|
10778 | if (result.version === 1) {
|
10779 | sample.compositionTimeOffset = view.getInt32(offset);
|
10780 | } else {
|
10781 | sample.compositionTimeOffset = view.getUint32(offset);
|
10782 | }
|
10783 |
|
10784 | offset += 4;
|
10785 | }
|
10786 |
|
10787 | result.samples.push(sample);
|
10788 | }
|
10789 |
|
10790 | return result;
|
10791 | };
|
10792 |
|
10793 | var parseTrun = trun;
|
10794 |
|
10795 | var tfhd = function tfhd(data) {
|
10796 | var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
10797 | result = {
|
10798 | version: data[0],
|
10799 | flags: new Uint8Array(data.subarray(1, 4)),
|
10800 | trackId: view.getUint32(4)
|
10801 | },
|
10802 | baseDataOffsetPresent = result.flags[2] & 0x01,
|
10803 | sampleDescriptionIndexPresent = result.flags[2] & 0x02,
|
10804 | defaultSampleDurationPresent = result.flags[2] & 0x08,
|
10805 | defaultSampleSizePresent = result.flags[2] & 0x10,
|
10806 | defaultSampleFlagsPresent = result.flags[2] & 0x20,
|
10807 | durationIsEmpty = result.flags[0] & 0x010000,
|
10808 | defaultBaseIsMoof = result.flags[0] & 0x020000,
|
10809 | i;
|
10810 | i = 8;
|
10811 |
|
10812 | if (baseDataOffsetPresent) {
|
10813 | i += 4;
|
10814 |
|
10815 |
|
10816 | result.baseDataOffset = view.getUint32(12);
|
10817 | i += 4;
|
10818 | }
|
10819 |
|
10820 | if (sampleDescriptionIndexPresent) {
|
10821 | result.sampleDescriptionIndex = view.getUint32(i);
|
10822 | i += 4;
|
10823 | }
|
10824 |
|
10825 | if (defaultSampleDurationPresent) {
|
10826 | result.defaultSampleDuration = view.getUint32(i);
|
10827 | i += 4;
|
10828 | }
|
10829 |
|
10830 | if (defaultSampleSizePresent) {
|
10831 | result.defaultSampleSize = view.getUint32(i);
|
10832 | i += 4;
|
10833 | }
|
10834 |
|
10835 | if (defaultSampleFlagsPresent) {
|
10836 | result.defaultSampleFlags = view.getUint32(i);
|
10837 | }
|
10838 |
|
10839 | if (durationIsEmpty) {
|
10840 | result.durationIsEmpty = true;
|
10841 | }
|
10842 |
|
10843 | if (!baseDataOffsetPresent && defaultBaseIsMoof) {
|
10844 | result.baseDataOffsetIsMoof = true;
|
10845 | }
|
10846 |
|
10847 | return result;
|
10848 | };
|
10849 |
|
10850 | var parseTfhd = tfhd;
|
10851 | var discardEmulationPreventionBytes = captionPacketParser.discardEmulationPreventionBytes;
|
10852 | var CaptionStream = captionStream.CaptionStream;
|
10853 | |
10854 |
|
10855 |
|
10856 |
|
10857 |
|
10858 |
|
10859 |
|
10860 |
|
10861 |
|
10862 |
|
10863 |
|
10864 | var mapToSample = function mapToSample(offset, samples) {
|
10865 | var approximateOffset = offset;
|
10866 |
|
10867 | for (var i = 0; i < samples.length; i++) {
|
10868 | var sample = samples[i];
|
10869 |
|
10870 | if (approximateOffset < sample.size) {
|
10871 | return sample;
|
10872 | }
|
10873 |
|
10874 | approximateOffset -= sample.size;
|
10875 | }
|
10876 |
|
10877 | return null;
|
10878 | };
|
10879 | |
10880 |
|
10881 |
|
10882 |
|
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 |
|
10888 |
|
10889 |
|
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 |
|
10895 | var findSeiNals = function findSeiNals(avcStream, samples, trackId) {
|
10896 | var avcView = new DataView(avcStream.buffer, avcStream.byteOffset, avcStream.byteLength),
|
10897 | result = {
|
10898 | logs: [],
|
10899 | seiNals: []
|
10900 | },
|
10901 | seiNal,
|
10902 | i,
|
10903 | length,
|
10904 | lastMatchedSample;
|
10905 |
|
10906 | for (i = 0; i + 4 < avcStream.length; i += length) {
|
10907 | length = avcView.getUint32(i);
|
10908 | i += 4;
|
10909 |
|
10910 | if (length <= 0) {
|
10911 | continue;
|
10912 | }
|
10913 |
|
10914 | switch (avcStream[i] & 0x1F) {
|
10915 | case 0x06:
|
10916 | var data = avcStream.subarray(i + 1, i + 1 + length);
|
10917 | var matchingSample = mapToSample(i, samples);
|
10918 | seiNal = {
|
10919 | nalUnitType: 'sei_rbsp',
|
10920 | size: length,
|
10921 | data: data,
|
10922 | escapedRBSP: discardEmulationPreventionBytes(data),
|
10923 | trackId: trackId
|
10924 | };
|
10925 |
|
10926 | if (matchingSample) {
|
10927 | seiNal.pts = matchingSample.pts;
|
10928 | seiNal.dts = matchingSample.dts;
|
10929 | lastMatchedSample = matchingSample;
|
10930 | } else if (lastMatchedSample) {
|
10931 |
|
10932 |
|
10933 | seiNal.pts = lastMatchedSample.pts;
|
10934 | seiNal.dts = lastMatchedSample.dts;
|
10935 | } else {
|
10936 | result.logs.push({
|
10937 | level: 'warn',
|
10938 | message: 'We\'ve encountered a nal unit without data at ' + i + ' for trackId ' + trackId + '. See mux.js#223.'
|
10939 | });
|
10940 | break;
|
10941 | }
|
10942 |
|
10943 | result.seiNals.push(seiNal);
|
10944 | break;
|
10945 | }
|
10946 | }
|
10947 |
|
10948 | return result;
|
10949 | };
|
10950 | |
10951 |
|
10952 |
|
10953 |
|
10954 |
|
10955 |
|
10956 |
|
10957 |
|
10958 |
|
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 | var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
|
10966 | var currentDts = baseMediaDecodeTime;
|
10967 | var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
|
10968 | var defaultSampleSize = tfhd.defaultSampleSize || 0;
|
10969 | var trackId = tfhd.trackId;
|
10970 | var allSamples = [];
|
10971 | truns.forEach(function (trun) {
|
10972 |
|
10973 |
|
10974 |
|
10975 | var trackRun = parseTrun(trun);
|
10976 | var samples = trackRun.samples;
|
10977 | samples.forEach(function (sample) {
|
10978 | if (sample.duration === undefined) {
|
10979 | sample.duration = defaultSampleDuration;
|
10980 | }
|
10981 |
|
10982 | if (sample.size === undefined) {
|
10983 | sample.size = defaultSampleSize;
|
10984 | }
|
10985 |
|
10986 | sample.trackId = trackId;
|
10987 | sample.dts = currentDts;
|
10988 |
|
10989 | if (sample.compositionTimeOffset === undefined) {
|
10990 | sample.compositionTimeOffset = 0;
|
10991 | }
|
10992 |
|
10993 | sample.pts = currentDts + sample.compositionTimeOffset;
|
10994 | currentDts += sample.duration;
|
10995 | });
|
10996 | allSamples = allSamples.concat(samples);
|
10997 | });
|
10998 | return allSamples;
|
10999 | };
|
11000 | |
11001 |
|
11002 |
|
11003 |
|
11004 |
|
11005 |
|
11006 |
|
11007 |
|
11008 |
|
11009 |
|
11010 | var parseCaptionNals = function parseCaptionNals(segment, videoTrackId) {
|
11011 |
|
11012 | var trafs = findBox_1(segment, ['moof', 'traf']);
|
11013 |
|
11014 | var mdats = findBox_1(segment, ['mdat']);
|
11015 | var captionNals = {};
|
11016 | var mdatTrafPairs = [];
|
11017 |
|
11018 | mdats.forEach(function (mdat, index) {
|
11019 | var matchingTraf = trafs[index];
|
11020 | mdatTrafPairs.push({
|
11021 | mdat: mdat,
|
11022 | traf: matchingTraf
|
11023 | });
|
11024 | });
|
11025 | mdatTrafPairs.forEach(function (pair) {
|
11026 | var mdat = pair.mdat;
|
11027 | var traf = pair.traf;
|
11028 | var tfhd = findBox_1(traf, ['tfhd']);
|
11029 |
|
11030 | var headerInfo = parseTfhd(tfhd[0]);
|
11031 | var trackId = headerInfo.trackId;
|
11032 | var tfdt = findBox_1(traf, ['tfdt']);
|
11033 |
|
11034 | var baseMediaDecodeTime = tfdt.length > 0 ? parseTfdt(tfdt[0]).baseMediaDecodeTime : 0;
|
11035 | var truns = findBox_1(traf, ['trun']);
|
11036 | var samples;
|
11037 | var result;
|
11038 |
|
11039 | if (videoTrackId === trackId && truns.length > 0) {
|
11040 | samples = parseSamples(truns, baseMediaDecodeTime, headerInfo);
|
11041 | result = findSeiNals(mdat, samples, trackId);
|
11042 |
|
11043 | if (!captionNals[trackId]) {
|
11044 | captionNals[trackId] = {
|
11045 | seiNals: [],
|
11046 | logs: []
|
11047 | };
|
11048 | }
|
11049 |
|
11050 | captionNals[trackId].seiNals = captionNals[trackId].seiNals.concat(result.seiNals);
|
11051 | captionNals[trackId].logs = captionNals[trackId].logs.concat(result.logs);
|
11052 | }
|
11053 | });
|
11054 | return captionNals;
|
11055 | };
|
11056 | |
11057 |
|
11058 |
|
11059 |
|
11060 |
|
11061 |
|
11062 |
|
11063 |
|
11064 |
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 | var parseEmbeddedCaptions = function parseEmbeddedCaptions(segment, trackId, timescale) {
|
11075 | var captionNals;
|
11076 |
|
11077 | if (trackId === null) {
|
11078 | return null;
|
11079 | }
|
11080 |
|
11081 | captionNals = parseCaptionNals(segment, trackId);
|
11082 | var trackNals = captionNals[trackId] || {};
|
11083 | return {
|
11084 | seiNals: trackNals.seiNals,
|
11085 | logs: trackNals.logs,
|
11086 | timescale: timescale
|
11087 | };
|
11088 | };
|
11089 | |
11090 |
|
11091 |
|
11092 |
|
11093 |
|
11094 | var CaptionParser = function CaptionParser() {
|
11095 | var isInitialized = false;
|
11096 | var captionStream;
|
11097 |
|
11098 | var segmentCache;
|
11099 |
|
11100 | var trackId;
|
11101 |
|
11102 | var timescale;
|
11103 |
|
11104 | var parsedCaptions;
|
11105 |
|
11106 | var parsingPartial;
|
11107 | |
11108 |
|
11109 |
|
11110 |
|
11111 |
|
11112 | this.isInitialized = function () {
|
11113 | return isInitialized;
|
11114 | };
|
11115 | |
11116 |
|
11117 |
|
11118 |
|
11119 |
|
11120 |
|
11121 | this.init = function (options) {
|
11122 | captionStream = new CaptionStream();
|
11123 | isInitialized = true;
|
11124 | parsingPartial = options ? options.isPartial : false;
|
11125 |
|
11126 | captionStream.on('data', function (event) {
|
11127 |
|
11128 | event.startTime = event.startPts / timescale;
|
11129 | event.endTime = event.endPts / timescale;
|
11130 | parsedCaptions.captions.push(event);
|
11131 | parsedCaptions.captionStreams[event.stream] = true;
|
11132 | });
|
11133 | captionStream.on('log', function (log) {
|
11134 | parsedCaptions.logs.push(log);
|
11135 | });
|
11136 | };
|
11137 | |
11138 |
|
11139 |
|
11140 |
|
11141 |
|
11142 |
|
11143 |
|
11144 | this.isNewInit = function (videoTrackIds, timescales) {
|
11145 | if (videoTrackIds && videoTrackIds.length === 0 || timescales && typeof timescales === 'object' && Object.keys(timescales).length === 0) {
|
11146 | return false;
|
11147 | }
|
11148 |
|
11149 | return trackId !== videoTrackIds[0] || timescale !== timescales[trackId];
|
11150 | };
|
11151 | |
11152 |
|
11153 |
|
11154 |
|
11155 |
|
11156 |
|
11157 |
|
11158 |
|
11159 |
|
11160 |
|
11161 |
|
11162 |
|
11163 | this.parse = function (segment, videoTrackIds, timescales) {
|
11164 | var parsedData;
|
11165 |
|
11166 | if (!this.isInitialized()) {
|
11167 | return null;
|
11168 | } else if (!videoTrackIds || !timescales) {
|
11169 | return null;
|
11170 | } else if (this.isNewInit(videoTrackIds, timescales)) {
|
11171 |
|
11172 |
|
11173 | trackId = videoTrackIds[0];
|
11174 | timescale = timescales[trackId];
|
11175 |
|
11176 |
|
11177 | } else if (trackId === null || !timescale) {
|
11178 | segmentCache.push(segment);
|
11179 | return null;
|
11180 | }
|
11181 |
|
11182 |
|
11183 | while (segmentCache.length > 0) {
|
11184 | var cachedSegment = segmentCache.shift();
|
11185 | this.parse(cachedSegment, videoTrackIds, timescales);
|
11186 | }
|
11187 |
|
11188 | parsedData = parseEmbeddedCaptions(segment, trackId, timescale);
|
11189 |
|
11190 | if (parsedData && parsedData.logs) {
|
11191 | parsedCaptions.logs = parsedCaptions.logs.concat(parsedData.logs);
|
11192 | }
|
11193 |
|
11194 | if (parsedData === null || !parsedData.seiNals) {
|
11195 | if (parsedCaptions.logs.length) {
|
11196 | return {
|
11197 | logs: parsedCaptions.logs,
|
11198 | captions: [],
|
11199 | captionStreams: []
|
11200 | };
|
11201 | }
|
11202 |
|
11203 | return null;
|
11204 | }
|
11205 |
|
11206 | this.pushNals(parsedData.seiNals);
|
11207 |
|
11208 | this.flushStream();
|
11209 | return parsedCaptions;
|
11210 | };
|
11211 | |
11212 |
|
11213 |
|
11214 |
|
11215 |
|
11216 |
|
11217 |
|
11218 |
|
11219 | this.pushNals = function (nals) {
|
11220 | if (!this.isInitialized() || !nals || nals.length === 0) {
|
11221 | return null;
|
11222 | }
|
11223 |
|
11224 | nals.forEach(function (nal) {
|
11225 | captionStream.push(nal);
|
11226 | });
|
11227 | };
|
11228 | |
11229 |
|
11230 |
|
11231 |
|
11232 |
|
11233 |
|
11234 | this.flushStream = function () {
|
11235 | if (!this.isInitialized()) {
|
11236 | return null;
|
11237 | }
|
11238 |
|
11239 | if (!parsingPartial) {
|
11240 | captionStream.flush();
|
11241 | } else {
|
11242 | captionStream.partialFlush();
|
11243 | }
|
11244 | };
|
11245 | |
11246 |
|
11247 |
|
11248 |
|
11249 |
|
11250 | this.clearParsedCaptions = function () {
|
11251 | parsedCaptions.captions = [];
|
11252 | parsedCaptions.captionStreams = {};
|
11253 | parsedCaptions.logs = [];
|
11254 | };
|
11255 | |
11256 |
|
11257 |
|
11258 |
|
11259 |
|
11260 |
|
11261 | this.resetCaptionStream = function () {
|
11262 | if (!this.isInitialized()) {
|
11263 | return null;
|
11264 | }
|
11265 |
|
11266 | captionStream.reset();
|
11267 | };
|
11268 | |
11269 |
|
11270 |
|
11271 |
|
11272 |
|
11273 |
|
11274 |
|
11275 | this.clearAllCaptions = function () {
|
11276 | this.clearParsedCaptions();
|
11277 | this.resetCaptionStream();
|
11278 | };
|
11279 | |
11280 |
|
11281 |
|
11282 |
|
11283 |
|
11284 | this.reset = function () {
|
11285 | segmentCache = [];
|
11286 | trackId = null;
|
11287 | timescale = null;
|
11288 |
|
11289 | if (!parsedCaptions) {
|
11290 | parsedCaptions = {
|
11291 | captions: [],
|
11292 |
|
11293 | captionStreams: {},
|
11294 | logs: []
|
11295 | };
|
11296 | } else {
|
11297 | this.clearParsedCaptions();
|
11298 | }
|
11299 |
|
11300 | this.resetCaptionStream();
|
11301 | };
|
11302 |
|
11303 | this.reset();
|
11304 | };
|
11305 |
|
11306 | var captionParser = CaptionParser;
|
11307 | var toUnsigned = bin.toUnsigned;
|
11308 | var toHexString = bin.toHexString;
|
11309 | var timescale, startTime, compositionStartTime, getVideoTrackIds, getTracks, getTimescaleFromMediaHeader;
|
11310 | |
11311 |
|
11312 |
|
11313 |
|
11314 |
|
11315 |
|
11316 |
|
11317 |
|
11318 |
|
11319 |
|
11320 |
|
11321 |
|
11322 |
|
11323 |
|
11324 |
|
11325 |
|
11326 |
|
11327 |
|
11328 |
|
11329 | timescale = function timescale(init) {
|
11330 | var result = {},
|
11331 | traks = findBox_1(init, ['moov', 'trak']);
|
11332 |
|
11333 | return traks.reduce(function (result, trak) {
|
11334 | var tkhd, version, index, id, mdhd;
|
11335 | tkhd = findBox_1(trak, ['tkhd'])[0];
|
11336 |
|
11337 | if (!tkhd) {
|
11338 | return null;
|
11339 | }
|
11340 |
|
11341 | version = tkhd[0];
|
11342 | index = version === 0 ? 12 : 20;
|
11343 | id = toUnsigned(tkhd[index] << 24 | tkhd[index + 1] << 16 | tkhd[index + 2] << 8 | tkhd[index + 3]);
|
11344 | mdhd = findBox_1(trak, ['mdia', 'mdhd'])[0];
|
11345 |
|
11346 | if (!mdhd) {
|
11347 | return null;
|
11348 | }
|
11349 |
|
11350 | version = mdhd[0];
|
11351 | index = version === 0 ? 12 : 20;
|
11352 | result[id] = toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]);
|
11353 | return result;
|
11354 | }, result);
|
11355 | };
|
11356 | |
11357 |
|
11358 |
|
11359 |
|
11360 |
|
11361 |
|
11362 |
|
11363 |
|
11364 |
|
11365 |
|
11366 |
|
11367 |
|
11368 |
|
11369 |
|
11370 |
|
11371 |
|
11372 |
|
11373 |
|
11374 | startTime = function startTime(timescale, fragment) {
|
11375 | var trafs, baseTimes, result;
|
11376 |
|
11377 | trafs = findBox_1(fragment, ['moof', 'traf']);
|
11378 |
|
11379 | baseTimes = [].concat.apply([], trafs.map(function (traf) {
|
11380 | return findBox_1(traf, ['tfhd']).map(function (tfhd) {
|
11381 | var id, scale, baseTime;
|
11382 |
|
11383 | id = toUnsigned(tfhd[4] << 24 | tfhd[5] << 16 | tfhd[6] << 8 | tfhd[7]);
|
11384 |
|
11385 | scale = timescale[id] || 90e3;
|
11386 |
|
11387 | baseTime = findBox_1(traf, ['tfdt']).map(function (tfdt) {
|
11388 | var version, result;
|
11389 | version = tfdt[0];
|
11390 | result = toUnsigned(tfdt[4] << 24 | tfdt[5] << 16 | tfdt[6] << 8 | tfdt[7]);
|
11391 |
|
11392 | if (version === 1) {
|
11393 | result *= Math.pow(2, 32);
|
11394 | result += toUnsigned(tfdt[8] << 24 | tfdt[9] << 16 | tfdt[10] << 8 | tfdt[11]);
|
11395 | }
|
11396 |
|
11397 | return result;
|
11398 | })[0];
|
11399 | baseTime = typeof baseTime === 'number' && !isNaN(baseTime) ? baseTime : Infinity;
|
11400 |
|
11401 | return baseTime / scale;
|
11402 | });
|
11403 | }));
|
11404 |
|
11405 | result = Math.min.apply(null, baseTimes);
|
11406 | return isFinite(result) ? result : 0;
|
11407 | };
|
11408 | |
11409 |
|
11410 |
|
11411 |
|
11412 |
|
11413 |
|
11414 |
|
11415 |
|
11416 |
|
11417 |
|
11418 |
|
11419 |
|
11420 |
|
11421 |
|
11422 |
|
11423 |
|
11424 |
|
11425 |
|
11426 |
|
11427 |
|
11428 |
|
11429 | compositionStartTime = function compositionStartTime(timescales, fragment) {
|
11430 | var trafBoxes = findBox_1(fragment, ['moof', 'traf']);
|
11431 | var baseMediaDecodeTime = 0;
|
11432 | var compositionTimeOffset = 0;
|
11433 | var trackId;
|
11434 |
|
11435 | if (trafBoxes && trafBoxes.length) {
|
11436 |
|
11437 |
|
11438 |
|
11439 | var tfhd = findBox_1(trafBoxes[0], ['tfhd'])[0];
|
11440 | var trun = findBox_1(trafBoxes[0], ['trun'])[0];
|
11441 | var tfdt = findBox_1(trafBoxes[0], ['tfdt'])[0];
|
11442 |
|
11443 | if (tfhd) {
|
11444 | var parsedTfhd = parseTfhd(tfhd);
|
11445 | trackId = parsedTfhd.trackId;
|
11446 | }
|
11447 |
|
11448 | if (tfdt) {
|
11449 | var parsedTfdt = parseTfdt(tfdt);
|
11450 | baseMediaDecodeTime = parsedTfdt.baseMediaDecodeTime;
|
11451 | }
|
11452 |
|
11453 | if (trun) {
|
11454 | var parsedTrun = parseTrun(trun);
|
11455 |
|
11456 | if (parsedTrun.samples && parsedTrun.samples.length) {
|
11457 | compositionTimeOffset = parsedTrun.samples[0].compositionTimeOffset || 0;
|
11458 | }
|
11459 | }
|
11460 | }
|
11461 |
|
11462 |
|
11463 |
|
11464 | var timescale = timescales[trackId] || 90e3;
|
11465 |
|
11466 | return (baseMediaDecodeTime + compositionTimeOffset) / timescale;
|
11467 | };
|
11468 | |
11469 |
|
11470 |
|
11471 |
|
11472 |
|
11473 |
|
11474 |
|
11475 |
|
11476 |
|
11477 |
|
11478 |
|
11479 |
|
11480 |
|
11481 | getVideoTrackIds = function getVideoTrackIds(init) {
|
11482 | var traks = findBox_1(init, ['moov', 'trak']);
|
11483 | var videoTrackIds = [];
|
11484 | traks.forEach(function (trak) {
|
11485 | var hdlrs = findBox_1(trak, ['mdia', 'hdlr']);
|
11486 | var tkhds = findBox_1(trak, ['tkhd']);
|
11487 | hdlrs.forEach(function (hdlr, index) {
|
11488 | var handlerType = parseType_1(hdlr.subarray(8, 12));
|
11489 | var tkhd = tkhds[index];
|
11490 | var view;
|
11491 | var version;
|
11492 | var trackId;
|
11493 |
|
11494 | if (handlerType === 'vide') {
|
11495 | view = new DataView(tkhd.buffer, tkhd.byteOffset, tkhd.byteLength);
|
11496 | version = view.getUint8(0);
|
11497 | trackId = version === 0 ? view.getUint32(12) : view.getUint32(20);
|
11498 | videoTrackIds.push(trackId);
|
11499 | }
|
11500 | });
|
11501 | });
|
11502 | return videoTrackIds;
|
11503 | };
|
11504 |
|
11505 | getTimescaleFromMediaHeader = function getTimescaleFromMediaHeader(mdhd) {
|
11506 |
|
11507 | var version = mdhd[0];
|
11508 | var index = version === 0 ? 12 : 20;
|
11509 | return toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]);
|
11510 | };
|
11511 | |
11512 |
|
11513 |
|
11514 |
|
11515 |
|
11516 |
|
11517 | getTracks = function getTracks(init) {
|
11518 | var traks = findBox_1(init, ['moov', 'trak']);
|
11519 | var tracks = [];
|
11520 | traks.forEach(function (trak) {
|
11521 | var track = {};
|
11522 | var tkhd = findBox_1(trak, ['tkhd'])[0];
|
11523 | var view, tkhdVersion;
|
11524 |
|
11525 | if (tkhd) {
|
11526 | view = new DataView(tkhd.buffer, tkhd.byteOffset, tkhd.byteLength);
|
11527 | tkhdVersion = view.getUint8(0);
|
11528 | track.id = tkhdVersion === 0 ? view.getUint32(12) : view.getUint32(20);
|
11529 | }
|
11530 |
|
11531 | var hdlr = findBox_1(trak, ['mdia', 'hdlr'])[0];
|
11532 |
|
11533 | if (hdlr) {
|
11534 | var type = parseType_1(hdlr.subarray(8, 12));
|
11535 |
|
11536 | if (type === 'vide') {
|
11537 | track.type = 'video';
|
11538 | } else if (type === 'soun') {
|
11539 | track.type = 'audio';
|
11540 | } else {
|
11541 | track.type = type;
|
11542 | }
|
11543 | }
|
11544 |
|
11545 |
|
11546 | var stsd = findBox_1(trak, ['mdia', 'minf', 'stbl', 'stsd'])[0];
|
11547 |
|
11548 | if (stsd) {
|
11549 | var sampleDescriptions = stsd.subarray(8);
|
11550 |
|
11551 | track.codec = parseType_1(sampleDescriptions.subarray(4, 8));
|
11552 | var codecBox = findBox_1(sampleDescriptions, [track.codec])[0];
|
11553 | var codecConfig, codecConfigType;
|
11554 |
|
11555 | if (codecBox) {
|
11556 |
|
11557 | if (/^[asm]vc[1-9]$/i.test(track.codec)) {
|
11558 |
|
11559 |
|
11560 | codecConfig = codecBox.subarray(78);
|
11561 | codecConfigType = parseType_1(codecConfig.subarray(4, 8));
|
11562 |
|
11563 | if (codecConfigType === 'avcC' && codecConfig.length > 11) {
|
11564 | track.codec += '.';
|
11565 |
|
11566 |
|
11567 | track.codec += toHexString(codecConfig[9]);
|
11568 |
|
11569 | track.codec += toHexString(codecConfig[10]);
|
11570 |
|
11571 | track.codec += toHexString(codecConfig[11]);
|
11572 | } else {
|
11573 |
|
11574 |
|
11575 | track.codec = 'avc1.4d400d';
|
11576 | }
|
11577 | } else if (/^mp4[a,v]$/i.test(track.codec)) {
|
11578 |
|
11579 | codecConfig = codecBox.subarray(28);
|
11580 | codecConfigType = parseType_1(codecConfig.subarray(4, 8));
|
11581 |
|
11582 | if (codecConfigType === 'esds' && codecConfig.length > 20 && codecConfig[19] !== 0) {
|
11583 | track.codec += '.' + toHexString(codecConfig[19]);
|
11584 |
|
11585 | track.codec += '.' + toHexString(codecConfig[20] >>> 2 & 0x3f).replace(/^0/, '');
|
11586 | } else {
|
11587 |
|
11588 |
|
11589 | track.codec = 'mp4a.40.2';
|
11590 | }
|
11591 | } else {
|
11592 |
|
11593 | track.codec = track.codec.toLowerCase();
|
11594 | }
|
11595 | }
|
11596 | }
|
11597 |
|
11598 | var mdhd = findBox_1(trak, ['mdia', 'mdhd'])[0];
|
11599 |
|
11600 | if (mdhd) {
|
11601 | track.timescale = getTimescaleFromMediaHeader(mdhd);
|
11602 | }
|
11603 |
|
11604 | tracks.push(track);
|
11605 | });
|
11606 | return tracks;
|
11607 | };
|
11608 |
|
11609 | var probe$2 = {
|
11610 |
|
11611 | findBox: findBox_1,
|
11612 | parseType: parseType_1,
|
11613 | timescale: timescale,
|
11614 | startTime: startTime,
|
11615 | compositionStartTime: compositionStartTime,
|
11616 | videoTrackIds: getVideoTrackIds,
|
11617 | tracks: getTracks,
|
11618 | getTimescaleFromMediaHeader: getTimescaleFromMediaHeader
|
11619 | };
|
11620 |
|
11621 | var parsePid = function parsePid(packet) {
|
11622 | var pid = packet[1] & 0x1f;
|
11623 | pid <<= 8;
|
11624 | pid |= packet[2];
|
11625 | return pid;
|
11626 | };
|
11627 |
|
11628 | var parsePayloadUnitStartIndicator = function parsePayloadUnitStartIndicator(packet) {
|
11629 | return !!(packet[1] & 0x40);
|
11630 | };
|
11631 |
|
11632 | var parseAdaptionField = function parseAdaptionField(packet) {
|
11633 | var offset = 0;
|
11634 |
|
11635 |
|
11636 |
|
11637 |
|
11638 |
|
11639 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
11640 | offset += packet[4] + 1;
|
11641 | }
|
11642 |
|
11643 | return offset;
|
11644 | };
|
11645 |
|
11646 | var parseType = function parseType(packet, pmtPid) {
|
11647 | var pid = parsePid(packet);
|
11648 |
|
11649 | if (pid === 0) {
|
11650 | return 'pat';
|
11651 | } else if (pid === pmtPid) {
|
11652 | return 'pmt';
|
11653 | } else if (pmtPid) {
|
11654 | return 'pes';
|
11655 | }
|
11656 |
|
11657 | return null;
|
11658 | };
|
11659 |
|
11660 | var parsePat = function parsePat(packet) {
|
11661 | var pusi = parsePayloadUnitStartIndicator(packet);
|
11662 | var offset = 4 + parseAdaptionField(packet);
|
11663 |
|
11664 | if (pusi) {
|
11665 | offset += packet[offset] + 1;
|
11666 | }
|
11667 |
|
11668 | return (packet[offset + 10] & 0x1f) << 8 | packet[offset + 11];
|
11669 | };
|
11670 |
|
11671 | var parsePmt = function parsePmt(packet) {
|
11672 | var programMapTable = {};
|
11673 | var pusi = parsePayloadUnitStartIndicator(packet);
|
11674 | var payloadOffset = 4 + parseAdaptionField(packet);
|
11675 |
|
11676 | if (pusi) {
|
11677 | payloadOffset += packet[payloadOffset] + 1;
|
11678 | }
|
11679 |
|
11680 |
|
11681 |
|
11682 |
|
11683 |
|
11684 |
|
11685 | if (!(packet[payloadOffset + 5] & 0x01)) {
|
11686 | return;
|
11687 | }
|
11688 |
|
11689 | var sectionLength, tableEnd, programInfoLength;
|
11690 |
|
11691 | sectionLength = (packet[payloadOffset + 1] & 0x0f) << 8 | packet[payloadOffset + 2];
|
11692 | tableEnd = 3 + sectionLength - 4;
|
11693 |
|
11694 |
|
11695 | programInfoLength = (packet[payloadOffset + 10] & 0x0f) << 8 | packet[payloadOffset + 11];
|
11696 |
|
11697 | var offset = 12 + programInfoLength;
|
11698 |
|
11699 | while (offset < tableEnd) {
|
11700 | var i = payloadOffset + offset;
|
11701 |
|
11702 | programMapTable[(packet[i + 1] & 0x1F) << 8 | packet[i + 2]] = packet[i];
|
11703 |
|
11704 |
|
11705 | offset += ((packet[i + 3] & 0x0F) << 8 | packet[i + 4]) + 5;
|
11706 | }
|
11707 |
|
11708 | return programMapTable;
|
11709 | };
|
11710 |
|
11711 | var parsePesType = function parsePesType(packet, programMapTable) {
|
11712 | var pid = parsePid(packet);
|
11713 | var type = programMapTable[pid];
|
11714 |
|
11715 | switch (type) {
|
11716 | case streamTypes.H264_STREAM_TYPE:
|
11717 | return 'video';
|
11718 |
|
11719 | case streamTypes.ADTS_STREAM_TYPE:
|
11720 | return 'audio';
|
11721 |
|
11722 | case streamTypes.METADATA_STREAM_TYPE:
|
11723 | return 'timed-metadata';
|
11724 |
|
11725 | default:
|
11726 | return null;
|
11727 | }
|
11728 | };
|
11729 |
|
11730 | var parsePesTime = function parsePesTime(packet) {
|
11731 | var pusi = parsePayloadUnitStartIndicator(packet);
|
11732 |
|
11733 | if (!pusi) {
|
11734 | return null;
|
11735 | }
|
11736 |
|
11737 | var offset = 4 + parseAdaptionField(packet);
|
11738 |
|
11739 | if (offset >= packet.byteLength) {
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 |
|
11747 |
|
11748 |
|
11749 |
|
11750 | return null;
|
11751 | }
|
11752 |
|
11753 | var pes = null;
|
11754 | var ptsDtsFlags;
|
11755 |
|
11756 |
|
11757 |
|
11758 | ptsDtsFlags = packet[offset + 7];
|
11759 |
|
11760 |
|
11761 |
|
11762 |
|
11763 |
|
11764 |
|
11765 |
|
11766 |
|
11767 | if (ptsDtsFlags & 0xC0) {
|
11768 | pes = {};
|
11769 |
|
11770 |
|
11771 |
|
11772 | 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;
|
11773 | pes.pts *= 4;
|
11774 |
|
11775 | pes.pts += (packet[offset + 13] & 0x06) >>> 1;
|
11776 |
|
11777 | pes.dts = pes.pts;
|
11778 |
|
11779 | if (ptsDtsFlags & 0x40) {
|
11780 | 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;
|
11781 | pes.dts *= 4;
|
11782 |
|
11783 | pes.dts += (packet[offset + 18] & 0x06) >>> 1;
|
11784 | }
|
11785 | }
|
11786 |
|
11787 | return pes;
|
11788 | };
|
11789 |
|
11790 | var parseNalUnitType = function parseNalUnitType(type) {
|
11791 | switch (type) {
|
11792 | case 0x05:
|
11793 | return 'slice_layer_without_partitioning_rbsp_idr';
|
11794 |
|
11795 | case 0x06:
|
11796 | return 'sei_rbsp';
|
11797 |
|
11798 | case 0x07:
|
11799 | return 'seq_parameter_set_rbsp';
|
11800 |
|
11801 | case 0x08:
|
11802 | return 'pic_parameter_set_rbsp';
|
11803 |
|
11804 | case 0x09:
|
11805 | return 'access_unit_delimiter_rbsp';
|
11806 |
|
11807 | default:
|
11808 | return null;
|
11809 | }
|
11810 | };
|
11811 |
|
11812 | var videoPacketContainsKeyFrame = function videoPacketContainsKeyFrame(packet) {
|
11813 | var offset = 4 + parseAdaptionField(packet);
|
11814 | var frameBuffer = packet.subarray(offset);
|
11815 | var frameI = 0;
|
11816 | var frameSyncPoint = 0;
|
11817 | var foundKeyFrame = false;
|
11818 | var nalType;
|
11819 |
|
11820 | for (; frameSyncPoint < frameBuffer.byteLength - 3; frameSyncPoint++) {
|
11821 | if (frameBuffer[frameSyncPoint + 2] === 1) {
|
11822 |
|
11823 | frameI = frameSyncPoint + 5;
|
11824 | break;
|
11825 | }
|
11826 | }
|
11827 |
|
11828 | while (frameI < frameBuffer.byteLength) {
|
11829 |
|
11830 |
|
11831 | switch (frameBuffer[frameI]) {
|
11832 | case 0:
|
11833 |
|
11834 | if (frameBuffer[frameI - 1] !== 0) {
|
11835 | frameI += 2;
|
11836 | break;
|
11837 | } else if (frameBuffer[frameI - 2] !== 0) {
|
11838 | frameI++;
|
11839 | break;
|
11840 | }
|
11841 |
|
11842 | if (frameSyncPoint + 3 !== frameI - 2) {
|
11843 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
11844 |
|
11845 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
11846 | foundKeyFrame = true;
|
11847 | }
|
11848 | }
|
11849 |
|
11850 |
|
11851 | do {
|
11852 | frameI++;
|
11853 | } while (frameBuffer[frameI] !== 1 && frameI < frameBuffer.length);
|
11854 |
|
11855 | frameSyncPoint = frameI - 2;
|
11856 | frameI += 3;
|
11857 | break;
|
11858 |
|
11859 | case 1:
|
11860 |
|
11861 | if (frameBuffer[frameI - 1] !== 0 || frameBuffer[frameI - 2] !== 0) {
|
11862 | frameI += 3;
|
11863 | break;
|
11864 | }
|
11865 |
|
11866 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
11867 |
|
11868 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
11869 | foundKeyFrame = true;
|
11870 | }
|
11871 |
|
11872 | frameSyncPoint = frameI - 2;
|
11873 | frameI += 3;
|
11874 | break;
|
11875 |
|
11876 | default:
|
11877 |
|
11878 |
|
11879 | frameI += 3;
|
11880 | break;
|
11881 | }
|
11882 | }
|
11883 |
|
11884 | frameBuffer = frameBuffer.subarray(frameSyncPoint);
|
11885 | frameI -= frameSyncPoint;
|
11886 | frameSyncPoint = 0;
|
11887 |
|
11888 | if (frameBuffer && frameBuffer.byteLength > 3) {
|
11889 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
11890 |
|
11891 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
11892 | foundKeyFrame = true;
|
11893 | }
|
11894 | }
|
11895 |
|
11896 | return foundKeyFrame;
|
11897 | };
|
11898 |
|
11899 | var probe$1 = {
|
11900 | parseType: parseType,
|
11901 | parsePat: parsePat,
|
11902 | parsePmt: parsePmt,
|
11903 | parsePayloadUnitStartIndicator: parsePayloadUnitStartIndicator,
|
11904 | parsePesType: parsePesType,
|
11905 | parsePesTime: parsePesTime,
|
11906 | videoPacketContainsKeyFrame: videoPacketContainsKeyFrame
|
11907 | };
|
11908 | var handleRollover = timestampRolloverStream.handleRollover;
|
11909 | var probe = {};
|
11910 | probe.ts = probe$1;
|
11911 | probe.aac = utils;
|
11912 | var ONE_SECOND_IN_TS = clock.ONE_SECOND_IN_TS;
|
11913 | var MP2T_PACKET_LENGTH = 188,
|
11914 |
|
11915 | SYNC_BYTE = 0x47;
|
11916 | |
11917 |
|
11918 |
|
11919 |
|
11920 |
|
11921 | var parsePsi_ = function parsePsi_(bytes, pmt) {
|
11922 | var startIndex = 0,
|
11923 | endIndex = MP2T_PACKET_LENGTH,
|
11924 | packet,
|
11925 | type;
|
11926 |
|
11927 | while (endIndex < bytes.byteLength) {
|
11928 |
|
11929 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
11930 |
|
11931 | packet = bytes.subarray(startIndex, endIndex);
|
11932 | type = probe.ts.parseType(packet, pmt.pid);
|
11933 |
|
11934 | switch (type) {
|
11935 | case 'pat':
|
11936 | pmt.pid = probe.ts.parsePat(packet);
|
11937 | break;
|
11938 |
|
11939 | case 'pmt':
|
11940 | var table = probe.ts.parsePmt(packet);
|
11941 | pmt.table = pmt.table || {};
|
11942 | Object.keys(table).forEach(function (key) {
|
11943 | pmt.table[key] = table[key];
|
11944 | });
|
11945 | break;
|
11946 | }
|
11947 |
|
11948 | startIndex += MP2T_PACKET_LENGTH;
|
11949 | endIndex += MP2T_PACKET_LENGTH;
|
11950 | continue;
|
11951 | }
|
11952 |
|
11953 |
|
11954 |
|
11955 |
|
11956 | startIndex++;
|
11957 | endIndex++;
|
11958 | }
|
11959 | };
|
11960 | |
11961 |
|
11962 |
|
11963 |
|
11964 |
|
11965 |
|
11966 | var parseAudioPes_ = function parseAudioPes_(bytes, pmt, result) {
|
11967 | var startIndex = 0,
|
11968 | endIndex = MP2T_PACKET_LENGTH,
|
11969 | packet,
|
11970 | type,
|
11971 | pesType,
|
11972 | pusi,
|
11973 | parsed;
|
11974 | var endLoop = false;
|
11975 |
|
11976 | while (endIndex <= bytes.byteLength) {
|
11977 |
|
11978 | if (bytes[startIndex] === SYNC_BYTE && (bytes[endIndex] === SYNC_BYTE || endIndex === bytes.byteLength)) {
|
11979 |
|
11980 | packet = bytes.subarray(startIndex, endIndex);
|
11981 | type = probe.ts.parseType(packet, pmt.pid);
|
11982 |
|
11983 | switch (type) {
|
11984 | case 'pes':
|
11985 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
11986 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
11987 |
|
11988 | if (pesType === 'audio' && pusi) {
|
11989 | parsed = probe.ts.parsePesTime(packet);
|
11990 |
|
11991 | if (parsed) {
|
11992 | parsed.type = 'audio';
|
11993 | result.audio.push(parsed);
|
11994 | endLoop = true;
|
11995 | }
|
11996 | }
|
11997 |
|
11998 | break;
|
11999 | }
|
12000 |
|
12001 | if (endLoop) {
|
12002 | break;
|
12003 | }
|
12004 |
|
12005 | startIndex += MP2T_PACKET_LENGTH;
|
12006 | endIndex += MP2T_PACKET_LENGTH;
|
12007 | continue;
|
12008 | }
|
12009 |
|
12010 |
|
12011 |
|
12012 |
|
12013 | startIndex++;
|
12014 | endIndex++;
|
12015 | }
|
12016 |
|
12017 |
|
12018 | endIndex = bytes.byteLength;
|
12019 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
12020 | endLoop = false;
|
12021 |
|
12022 | while (startIndex >= 0) {
|
12023 |
|
12024 | if (bytes[startIndex] === SYNC_BYTE && (bytes[endIndex] === SYNC_BYTE || endIndex === bytes.byteLength)) {
|
12025 |
|
12026 | packet = bytes.subarray(startIndex, endIndex);
|
12027 | type = probe.ts.parseType(packet, pmt.pid);
|
12028 |
|
12029 | switch (type) {
|
12030 | case 'pes':
|
12031 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12032 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12033 |
|
12034 | if (pesType === 'audio' && pusi) {
|
12035 | parsed = probe.ts.parsePesTime(packet);
|
12036 |
|
12037 | if (parsed) {
|
12038 | parsed.type = 'audio';
|
12039 | result.audio.push(parsed);
|
12040 | endLoop = true;
|
12041 | }
|
12042 | }
|
12043 |
|
12044 | break;
|
12045 | }
|
12046 |
|
12047 | if (endLoop) {
|
12048 | break;
|
12049 | }
|
12050 |
|
12051 | startIndex -= MP2T_PACKET_LENGTH;
|
12052 | endIndex -= MP2T_PACKET_LENGTH;
|
12053 | continue;
|
12054 | }
|
12055 |
|
12056 |
|
12057 |
|
12058 |
|
12059 | startIndex--;
|
12060 | endIndex--;
|
12061 | }
|
12062 | };
|
12063 | |
12064 |
|
12065 |
|
12066 |
|
12067 |
|
12068 |
|
12069 |
|
12070 | var parseVideoPes_ = function parseVideoPes_(bytes, pmt, result) {
|
12071 | var startIndex = 0,
|
12072 | endIndex = MP2T_PACKET_LENGTH,
|
12073 | packet,
|
12074 | type,
|
12075 | pesType,
|
12076 | pusi,
|
12077 | parsed,
|
12078 | frame,
|
12079 | i,
|
12080 | pes;
|
12081 | var endLoop = false;
|
12082 | var currentFrame = {
|
12083 | data: [],
|
12084 | size: 0
|
12085 | };
|
12086 |
|
12087 | while (endIndex < bytes.byteLength) {
|
12088 |
|
12089 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
12090 |
|
12091 | packet = bytes.subarray(startIndex, endIndex);
|
12092 | type = probe.ts.parseType(packet, pmt.pid);
|
12093 |
|
12094 | switch (type) {
|
12095 | case 'pes':
|
12096 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12097 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12098 |
|
12099 | if (pesType === 'video') {
|
12100 | if (pusi && !endLoop) {
|
12101 | parsed = probe.ts.parsePesTime(packet);
|
12102 |
|
12103 | if (parsed) {
|
12104 | parsed.type = 'video';
|
12105 | result.video.push(parsed);
|
12106 | endLoop = true;
|
12107 | }
|
12108 | }
|
12109 |
|
12110 | if (!result.firstKeyFrame) {
|
12111 | if (pusi) {
|
12112 | if (currentFrame.size !== 0) {
|
12113 | frame = new Uint8Array(currentFrame.size);
|
12114 | i = 0;
|
12115 |
|
12116 | while (currentFrame.data.length) {
|
12117 | pes = currentFrame.data.shift();
|
12118 | frame.set(pes, i);
|
12119 | i += pes.byteLength;
|
12120 | }
|
12121 |
|
12122 | if (probe.ts.videoPacketContainsKeyFrame(frame)) {
|
12123 | var firstKeyFrame = probe.ts.parsePesTime(frame);
|
12124 |
|
12125 |
|
12126 |
|
12127 | if (firstKeyFrame) {
|
12128 | result.firstKeyFrame = firstKeyFrame;
|
12129 | result.firstKeyFrame.type = 'video';
|
12130 | } else {
|
12131 |
|
12132 | 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.');
|
12133 | }
|
12134 | }
|
12135 |
|
12136 | currentFrame.size = 0;
|
12137 | }
|
12138 | }
|
12139 |
|
12140 | currentFrame.data.push(packet);
|
12141 | currentFrame.size += packet.byteLength;
|
12142 | }
|
12143 | }
|
12144 |
|
12145 | break;
|
12146 | }
|
12147 |
|
12148 | if (endLoop && result.firstKeyFrame) {
|
12149 | break;
|
12150 | }
|
12151 |
|
12152 | startIndex += MP2T_PACKET_LENGTH;
|
12153 | endIndex += MP2T_PACKET_LENGTH;
|
12154 | continue;
|
12155 | }
|
12156 |
|
12157 |
|
12158 |
|
12159 |
|
12160 | startIndex++;
|
12161 | endIndex++;
|
12162 | }
|
12163 |
|
12164 |
|
12165 | endIndex = bytes.byteLength;
|
12166 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
12167 | endLoop = false;
|
12168 |
|
12169 | while (startIndex >= 0) {
|
12170 |
|
12171 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
12172 |
|
12173 | packet = bytes.subarray(startIndex, endIndex);
|
12174 | type = probe.ts.parseType(packet, pmt.pid);
|
12175 |
|
12176 | switch (type) {
|
12177 | case 'pes':
|
12178 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
12179 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
12180 |
|
12181 | if (pesType === 'video' && pusi) {
|
12182 | parsed = probe.ts.parsePesTime(packet);
|
12183 |
|
12184 | if (parsed) {
|
12185 | parsed.type = 'video';
|
12186 | result.video.push(parsed);
|
12187 | endLoop = true;
|
12188 | }
|
12189 | }
|
12190 |
|
12191 | break;
|
12192 | }
|
12193 |
|
12194 | if (endLoop) {
|
12195 | break;
|
12196 | }
|
12197 |
|
12198 | startIndex -= MP2T_PACKET_LENGTH;
|
12199 | endIndex -= MP2T_PACKET_LENGTH;
|
12200 | continue;
|
12201 | }
|
12202 |
|
12203 |
|
12204 |
|
12205 |
|
12206 | startIndex--;
|
12207 | endIndex--;
|
12208 | }
|
12209 | };
|
12210 | |
12211 |
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 | var adjustTimestamp_ = function adjustTimestamp_(segmentInfo, baseTimestamp) {
|
12217 | if (segmentInfo.audio && segmentInfo.audio.length) {
|
12218 | var audioBaseTimestamp = baseTimestamp;
|
12219 |
|
12220 | if (typeof audioBaseTimestamp === 'undefined' || isNaN(audioBaseTimestamp)) {
|
12221 | audioBaseTimestamp = segmentInfo.audio[0].dts;
|
12222 | }
|
12223 |
|
12224 | segmentInfo.audio.forEach(function (info) {
|
12225 | info.dts = handleRollover(info.dts, audioBaseTimestamp);
|
12226 | info.pts = handleRollover(info.pts, audioBaseTimestamp);
|
12227 |
|
12228 | info.dtsTime = info.dts / ONE_SECOND_IN_TS;
|
12229 | info.ptsTime = info.pts / ONE_SECOND_IN_TS;
|
12230 | });
|
12231 | }
|
12232 |
|
12233 | if (segmentInfo.video && segmentInfo.video.length) {
|
12234 | var videoBaseTimestamp = baseTimestamp;
|
12235 |
|
12236 | if (typeof videoBaseTimestamp === 'undefined' || isNaN(videoBaseTimestamp)) {
|
12237 | videoBaseTimestamp = segmentInfo.video[0].dts;
|
12238 | }
|
12239 |
|
12240 | segmentInfo.video.forEach(function (info) {
|
12241 | info.dts = handleRollover(info.dts, videoBaseTimestamp);
|
12242 | info.pts = handleRollover(info.pts, videoBaseTimestamp);
|
12243 |
|
12244 | info.dtsTime = info.dts / ONE_SECOND_IN_TS;
|
12245 | info.ptsTime = info.pts / ONE_SECOND_IN_TS;
|
12246 | });
|
12247 |
|
12248 | if (segmentInfo.firstKeyFrame) {
|
12249 | var frame = segmentInfo.firstKeyFrame;
|
12250 | frame.dts = handleRollover(frame.dts, videoBaseTimestamp);
|
12251 | frame.pts = handleRollover(frame.pts, videoBaseTimestamp);
|
12252 |
|
12253 | frame.dtsTime = frame.dts / ONE_SECOND_IN_TS;
|
12254 | frame.ptsTime = frame.pts / ONE_SECOND_IN_TS;
|
12255 | }
|
12256 | }
|
12257 | };
|
12258 | |
12259 |
|
12260 |
|
12261 |
|
12262 |
|
12263 | var inspectAac_ = function inspectAac_(bytes) {
|
12264 | var endLoop = false,
|
12265 | audioCount = 0,
|
12266 | sampleRate = null,
|
12267 | timestamp = null,
|
12268 | frameSize = 0,
|
12269 | byteIndex = 0,
|
12270 | packet;
|
12271 |
|
12272 | while (bytes.length - byteIndex >= 3) {
|
12273 | var type = probe.aac.parseType(bytes, byteIndex);
|
12274 |
|
12275 | switch (type) {
|
12276 | case 'timed-metadata':
|
12277 |
|
12278 |
|
12279 | if (bytes.length - byteIndex < 10) {
|
12280 | endLoop = true;
|
12281 | break;
|
12282 | }
|
12283 |
|
12284 | frameSize = probe.aac.parseId3TagSize(bytes, byteIndex);
|
12285 |
|
12286 |
|
12287 | if (frameSize > bytes.length) {
|
12288 | endLoop = true;
|
12289 | break;
|
12290 | }
|
12291 |
|
12292 | if (timestamp === null) {
|
12293 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
12294 | timestamp = probe.aac.parseAacTimestamp(packet);
|
12295 | }
|
12296 |
|
12297 | byteIndex += frameSize;
|
12298 | break;
|
12299 |
|
12300 | case 'audio':
|
12301 |
|
12302 |
|
12303 | if (bytes.length - byteIndex < 7) {
|
12304 | endLoop = true;
|
12305 | break;
|
12306 | }
|
12307 |
|
12308 | frameSize = probe.aac.parseAdtsSize(bytes, byteIndex);
|
12309 |
|
12310 |
|
12311 | if (frameSize > bytes.length) {
|
12312 | endLoop = true;
|
12313 | break;
|
12314 | }
|
12315 |
|
12316 | if (sampleRate === null) {
|
12317 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
12318 | sampleRate = probe.aac.parseSampleRate(packet);
|
12319 | }
|
12320 |
|
12321 | audioCount++;
|
12322 | byteIndex += frameSize;
|
12323 | break;
|
12324 |
|
12325 | default:
|
12326 | byteIndex++;
|
12327 | break;
|
12328 | }
|
12329 |
|
12330 | if (endLoop) {
|
12331 | return null;
|
12332 | }
|
12333 | }
|
12334 |
|
12335 | if (sampleRate === null || timestamp === null) {
|
12336 | return null;
|
12337 | }
|
12338 |
|
12339 | var audioTimescale = ONE_SECOND_IN_TS / sampleRate;
|
12340 | var result = {
|
12341 | audio: [{
|
12342 | type: 'audio',
|
12343 | dts: timestamp,
|
12344 | pts: timestamp
|
12345 | }, {
|
12346 | type: 'audio',
|
12347 | dts: timestamp + audioCount * 1024 * audioTimescale,
|
12348 | pts: timestamp + audioCount * 1024 * audioTimescale
|
12349 | }]
|
12350 | };
|
12351 | return result;
|
12352 | };
|
12353 | |
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 |
|
12359 |
|
12360 | var inspectTs_ = function inspectTs_(bytes) {
|
12361 | var pmt = {
|
12362 | pid: null,
|
12363 | table: null
|
12364 | };
|
12365 | var result = {};
|
12366 | parsePsi_(bytes, pmt);
|
12367 |
|
12368 | for (var pid in pmt.table) {
|
12369 | if (pmt.table.hasOwnProperty(pid)) {
|
12370 | var type = pmt.table[pid];
|
12371 |
|
12372 | switch (type) {
|
12373 | case streamTypes.H264_STREAM_TYPE:
|
12374 | result.video = [];
|
12375 | parseVideoPes_(bytes, pmt, result);
|
12376 |
|
12377 | if (result.video.length === 0) {
|
12378 | delete result.video;
|
12379 | }
|
12380 |
|
12381 | break;
|
12382 |
|
12383 | case streamTypes.ADTS_STREAM_TYPE:
|
12384 | result.audio = [];
|
12385 | parseAudioPes_(bytes, pmt, result);
|
12386 |
|
12387 | if (result.audio.length === 0) {
|
12388 | delete result.audio;
|
12389 | }
|
12390 |
|
12391 | break;
|
12392 | }
|
12393 | }
|
12394 | }
|
12395 |
|
12396 | return result;
|
12397 | };
|
12398 | |
12399 |
|
12400 |
|
12401 |
|
12402 |
|
12403 |
|
12404 |
|
12405 |
|
12406 |
|
12407 |
|
12408 | var inspect = function inspect(bytes, baseTimestamp) {
|
12409 | var isAacData = probe.aac.isLikelyAacData(bytes);
|
12410 | var result;
|
12411 |
|
12412 | if (isAacData) {
|
12413 | result = inspectAac_(bytes);
|
12414 | } else {
|
12415 | result = inspectTs_(bytes);
|
12416 | }
|
12417 |
|
12418 | if (!result || !result.audio && !result.video) {
|
12419 | return null;
|
12420 | }
|
12421 |
|
12422 | adjustTimestamp_(result, baseTimestamp);
|
12423 | return result;
|
12424 | };
|
12425 |
|
12426 | var tsInspector = {
|
12427 | inspect: inspect,
|
12428 | parseAudioPes_: parseAudioPes_
|
12429 | };
|
12430 |
|
12431 |
|
12432 | |
12433 |
|
12434 |
|
12435 |
|
12436 |
|
12437 |
|
12438 |
|
12439 |
|
12440 | var wireTransmuxerEvents = function wireTransmuxerEvents(self, transmuxer) {
|
12441 | transmuxer.on('data', function (segment) {
|
12442 |
|
12443 |
|
12444 |
|
12445 |
|
12446 | var initArray = segment.initSegment;
|
12447 | segment.initSegment = {
|
12448 | data: initArray.buffer,
|
12449 | byteOffset: initArray.byteOffset,
|
12450 | byteLength: initArray.byteLength
|
12451 | };
|
12452 | var typedArray = segment.data;
|
12453 | segment.data = typedArray.buffer;
|
12454 | self.postMessage({
|
12455 | action: 'data',
|
12456 | segment: segment,
|
12457 | byteOffset: typedArray.byteOffset,
|
12458 | byteLength: typedArray.byteLength
|
12459 | }, [segment.data]);
|
12460 | });
|
12461 | transmuxer.on('done', function (data) {
|
12462 | self.postMessage({
|
12463 | action: 'done'
|
12464 | });
|
12465 | });
|
12466 | transmuxer.on('gopInfo', function (gopInfo) {
|
12467 | self.postMessage({
|
12468 | action: 'gopInfo',
|
12469 | gopInfo: gopInfo
|
12470 | });
|
12471 | });
|
12472 | transmuxer.on('videoSegmentTimingInfo', function (timingInfo) {
|
12473 | var videoSegmentTimingInfo = {
|
12474 | start: {
|
12475 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
12476 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
12477 | },
|
12478 | end: {
|
12479 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
12480 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
12481 | },
|
12482 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
12483 | };
|
12484 |
|
12485 | if (timingInfo.prependedContentDuration) {
|
12486 | videoSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
12487 | }
|
12488 |
|
12489 | self.postMessage({
|
12490 | action: 'videoSegmentTimingInfo',
|
12491 | videoSegmentTimingInfo: videoSegmentTimingInfo
|
12492 | });
|
12493 | });
|
12494 | transmuxer.on('audioSegmentTimingInfo', function (timingInfo) {
|
12495 |
|
12496 | var audioSegmentTimingInfo = {
|
12497 | start: {
|
12498 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
12499 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
12500 | },
|
12501 | end: {
|
12502 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
12503 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
12504 | },
|
12505 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
12506 | };
|
12507 |
|
12508 | if (timingInfo.prependedContentDuration) {
|
12509 | audioSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
12510 | }
|
12511 |
|
12512 | self.postMessage({
|
12513 | action: 'audioSegmentTimingInfo',
|
12514 | audioSegmentTimingInfo: audioSegmentTimingInfo
|
12515 | });
|
12516 | });
|
12517 | transmuxer.on('id3Frame', function (id3Frame) {
|
12518 | self.postMessage({
|
12519 | action: 'id3Frame',
|
12520 | id3Frame: id3Frame
|
12521 | });
|
12522 | });
|
12523 | transmuxer.on('caption', function (caption) {
|
12524 | self.postMessage({
|
12525 | action: 'caption',
|
12526 | caption: caption
|
12527 | });
|
12528 | });
|
12529 | transmuxer.on('trackinfo', function (trackInfo) {
|
12530 | self.postMessage({
|
12531 | action: 'trackinfo',
|
12532 | trackInfo: trackInfo
|
12533 | });
|
12534 | });
|
12535 | transmuxer.on('audioTimingInfo', function (audioTimingInfo) {
|
12536 |
|
12537 | self.postMessage({
|
12538 | action: 'audioTimingInfo',
|
12539 | audioTimingInfo: {
|
12540 | start: clock.videoTsToSeconds(audioTimingInfo.start),
|
12541 | end: clock.videoTsToSeconds(audioTimingInfo.end)
|
12542 | }
|
12543 | });
|
12544 | });
|
12545 | transmuxer.on('videoTimingInfo', function (videoTimingInfo) {
|
12546 | self.postMessage({
|
12547 | action: 'videoTimingInfo',
|
12548 | videoTimingInfo: {
|
12549 | start: clock.videoTsToSeconds(videoTimingInfo.start),
|
12550 | end: clock.videoTsToSeconds(videoTimingInfo.end)
|
12551 | }
|
12552 | });
|
12553 | });
|
12554 | transmuxer.on('log', function (log) {
|
12555 | self.postMessage({
|
12556 | action: 'log',
|
12557 | log: log
|
12558 | });
|
12559 | });
|
12560 | };
|
12561 | |
12562 |
|
12563 |
|
12564 |
|
12565 |
|
12566 |
|
12567 |
|
12568 |
|
12569 |
|
12570 | var MessageHandlers = function () {
|
12571 | function MessageHandlers(self, options) {
|
12572 | this.options = options || {};
|
12573 | this.self = self;
|
12574 | this.init();
|
12575 | }
|
12576 | |
12577 |
|
12578 |
|
12579 |
|
12580 |
|
12581 | var _proto = MessageHandlers.prototype;
|
12582 |
|
12583 | _proto.init = function init() {
|
12584 | if (this.transmuxer) {
|
12585 | this.transmuxer.dispose();
|
12586 | }
|
12587 |
|
12588 | this.transmuxer = new transmuxer.Transmuxer(this.options);
|
12589 | wireTransmuxerEvents(this.self, this.transmuxer);
|
12590 | };
|
12591 |
|
12592 | _proto.pushMp4Captions = function pushMp4Captions(data) {
|
12593 | if (!this.captionParser) {
|
12594 | this.captionParser = new captionParser();
|
12595 | this.captionParser.init();
|
12596 | }
|
12597 |
|
12598 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
12599 | var parsed = this.captionParser.parse(segment, data.trackIds, data.timescales);
|
12600 | this.self.postMessage({
|
12601 | action: 'mp4Captions',
|
12602 | captions: parsed && parsed.captions || [],
|
12603 | logs: parsed && parsed.logs || [],
|
12604 | data: segment.buffer
|
12605 | }, [segment.buffer]);
|
12606 | };
|
12607 |
|
12608 | _proto.probeMp4StartTime = function probeMp4StartTime(_ref) {
|
12609 | var timescales = _ref.timescales,
|
12610 | data = _ref.data;
|
12611 | var startTime = probe$2.startTime(timescales, data);
|
12612 | this.self.postMessage({
|
12613 | action: 'probeMp4StartTime',
|
12614 | startTime: startTime,
|
12615 | data: data
|
12616 | }, [data.buffer]);
|
12617 | };
|
12618 |
|
12619 | _proto.probeMp4Tracks = function probeMp4Tracks(_ref2) {
|
12620 | var data = _ref2.data;
|
12621 | var tracks = probe$2.tracks(data);
|
12622 | this.self.postMessage({
|
12623 | action: 'probeMp4Tracks',
|
12624 | tracks: tracks,
|
12625 | data: data
|
12626 | }, [data.buffer]);
|
12627 | }
|
12628 | |
12629 |
|
12630 |
|
12631 |
|
12632 |
|
12633 |
|
12634 |
|
12635 |
|
12636 |
|
12637 |
|
12638 |
|
12639 |
|
12640 |
|
12641 | ;
|
12642 |
|
12643 | _proto.probeTs = function probeTs(_ref3) {
|
12644 | var data = _ref3.data,
|
12645 | baseStartTime = _ref3.baseStartTime;
|
12646 | var tsStartTime = typeof baseStartTime === 'number' && !isNaN(baseStartTime) ? baseStartTime * clock.ONE_SECOND_IN_TS : void 0;
|
12647 | var timeInfo = tsInspector.inspect(data, tsStartTime);
|
12648 | var result = null;
|
12649 |
|
12650 | if (timeInfo) {
|
12651 | result = {
|
12652 |
|
12653 | hasVideo: timeInfo.video && timeInfo.video.length === 2 || false,
|
12654 | hasAudio: timeInfo.audio && timeInfo.audio.length === 2 || false
|
12655 | };
|
12656 |
|
12657 | if (result.hasVideo) {
|
12658 | result.videoStart = timeInfo.video[0].ptsTime;
|
12659 | }
|
12660 |
|
12661 | if (result.hasAudio) {
|
12662 | result.audioStart = timeInfo.audio[0].ptsTime;
|
12663 | }
|
12664 | }
|
12665 |
|
12666 | this.self.postMessage({
|
12667 | action: 'probeTs',
|
12668 | result: result,
|
12669 | data: data
|
12670 | }, [data.buffer]);
|
12671 | };
|
12672 |
|
12673 | _proto.clearAllMp4Captions = function clearAllMp4Captions() {
|
12674 | if (this.captionParser) {
|
12675 | this.captionParser.clearAllCaptions();
|
12676 | }
|
12677 | };
|
12678 |
|
12679 | _proto.clearParsedMp4Captions = function clearParsedMp4Captions() {
|
12680 | if (this.captionParser) {
|
12681 | this.captionParser.clearParsedCaptions();
|
12682 | }
|
12683 | }
|
12684 | |
12685 |
|
12686 |
|
12687 |
|
12688 |
|
12689 |
|
12690 | ;
|
12691 |
|
12692 | _proto.push = function push(data) {
|
12693 |
|
12694 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
12695 | this.transmuxer.push(segment);
|
12696 | }
|
12697 | |
12698 |
|
12699 |
|
12700 |
|
12701 | ;
|
12702 |
|
12703 | _proto.reset = function reset() {
|
12704 | this.transmuxer.reset();
|
12705 | }
|
12706 | |
12707 |
|
12708 |
|
12709 |
|
12710 |
|
12711 |
|
12712 |
|
12713 | ;
|
12714 |
|
12715 | _proto.setTimestampOffset = function setTimestampOffset(data) {
|
12716 | var timestampOffset = data.timestampOffset || 0;
|
12717 | this.transmuxer.setBaseMediaDecodeTime(Math.round(clock.secondsToVideoTs(timestampOffset)));
|
12718 | };
|
12719 |
|
12720 | _proto.setAudioAppendStart = function setAudioAppendStart(data) {
|
12721 | this.transmuxer.setAudioAppendStart(Math.ceil(clock.secondsToVideoTs(data.appendStart)));
|
12722 | };
|
12723 |
|
12724 | _proto.setRemux = function setRemux(data) {
|
12725 | this.transmuxer.setRemux(data.remux);
|
12726 | }
|
12727 | |
12728 |
|
12729 |
|
12730 |
|
12731 |
|
12732 |
|
12733 | ;
|
12734 |
|
12735 | _proto.flush = function flush(data) {
|
12736 | this.transmuxer.flush();
|
12737 |
|
12738 | self.postMessage({
|
12739 | action: 'done',
|
12740 | type: 'transmuxed'
|
12741 | });
|
12742 | };
|
12743 |
|
12744 | _proto.endTimeline = function endTimeline() {
|
12745 | this.transmuxer.endTimeline();
|
12746 |
|
12747 |
|
12748 | self.postMessage({
|
12749 | action: 'endedtimeline',
|
12750 | type: 'transmuxed'
|
12751 | });
|
12752 | };
|
12753 |
|
12754 | _proto.alignGopsWith = function alignGopsWith(data) {
|
12755 | this.transmuxer.alignGopsWith(data.gopsToAlignWith.slice());
|
12756 | };
|
12757 |
|
12758 | return MessageHandlers;
|
12759 | }();
|
12760 | |
12761 |
|
12762 |
|
12763 |
|
12764 |
|
12765 |
|
12766 |
|
12767 |
|
12768 |
|
12769 | self.onmessage = function (event) {
|
12770 | if (event.data.action === 'init' && event.data.options) {
|
12771 | this.messageHandlers = new MessageHandlers(self, event.data.options);
|
12772 | return;
|
12773 | }
|
12774 |
|
12775 | if (!this.messageHandlers) {
|
12776 | this.messageHandlers = new MessageHandlers(self);
|
12777 | }
|
12778 |
|
12779 | if (event.data && event.data.action && event.data.action !== 'init') {
|
12780 | if (this.messageHandlers[event.data.action]) {
|
12781 | this.messageHandlers[event.data.action](event.data);
|
12782 | }
|
12783 | }
|
12784 | };
|
12785 | }));
|
12786 | var TransmuxWorker = factory(workerCode$1);
|
12787 |
|
12788 |
|
12789 | var handleData_ = function handleData_(event, transmuxedData, callback) {
|
12790 | var _event$data$segment = event.data.segment,
|
12791 | type = _event$data$segment.type,
|
12792 | initSegment = _event$data$segment.initSegment,
|
12793 | captions = _event$data$segment.captions,
|
12794 | captionStreams = _event$data$segment.captionStreams,
|
12795 | metadata = _event$data$segment.metadata,
|
12796 | videoFrameDtsTime = _event$data$segment.videoFrameDtsTime,
|
12797 | videoFramePtsTime = _event$data$segment.videoFramePtsTime;
|
12798 | transmuxedData.buffer.push({
|
12799 | captions: captions,
|
12800 | captionStreams: captionStreams,
|
12801 | metadata: metadata
|
12802 | });
|
12803 | var boxes = event.data.segment.boxes || {
|
12804 | data: event.data.segment.data
|
12805 | };
|
12806 | var result = {
|
12807 | type: type,
|
12808 |
|
12809 | data: new Uint8Array(boxes.data, boxes.data.byteOffset, boxes.data.byteLength),
|
12810 | initSegment: new Uint8Array(initSegment.data, initSegment.byteOffset, initSegment.byteLength)
|
12811 | };
|
12812 |
|
12813 | if (typeof videoFrameDtsTime !== 'undefined') {
|
12814 | result.videoFrameDtsTime = videoFrameDtsTime;
|
12815 | }
|
12816 |
|
12817 | if (typeof videoFramePtsTime !== 'undefined') {
|
12818 | result.videoFramePtsTime = videoFramePtsTime;
|
12819 | }
|
12820 |
|
12821 | callback(result);
|
12822 | };
|
12823 | var handleDone_ = function handleDone_(_ref) {
|
12824 | var transmuxedData = _ref.transmuxedData,
|
12825 | callback = _ref.callback;
|
12826 |
|
12827 |
|
12828 | transmuxedData.buffer = [];
|
12829 |
|
12830 |
|
12831 | callback(transmuxedData);
|
12832 | };
|
12833 | var handleGopInfo_ = function handleGopInfo_(event, transmuxedData) {
|
12834 | transmuxedData.gopInfo = event.data.gopInfo;
|
12835 | };
|
12836 | var processTransmux = function processTransmux(options) {
|
12837 | var transmuxer = options.transmuxer,
|
12838 | bytes = options.bytes,
|
12839 | audioAppendStart = options.audioAppendStart,
|
12840 | gopsToAlignWith = options.gopsToAlignWith,
|
12841 | remux = options.remux,
|
12842 | onData = options.onData,
|
12843 | onTrackInfo = options.onTrackInfo,
|
12844 | onAudioTimingInfo = options.onAudioTimingInfo,
|
12845 | onVideoTimingInfo = options.onVideoTimingInfo,
|
12846 | onVideoSegmentTimingInfo = options.onVideoSegmentTimingInfo,
|
12847 | onAudioSegmentTimingInfo = options.onAudioSegmentTimingInfo,
|
12848 | onId3 = options.onId3,
|
12849 | onCaptions = options.onCaptions,
|
12850 | onDone = options.onDone,
|
12851 | onEndedTimeline = options.onEndedTimeline,
|
12852 | onTransmuxerLog = options.onTransmuxerLog,
|
12853 | isEndOfTimeline = options.isEndOfTimeline;
|
12854 | var transmuxedData = {
|
12855 | buffer: []
|
12856 | };
|
12857 | var waitForEndedTimelineEvent = isEndOfTimeline;
|
12858 |
|
12859 | var handleMessage = function handleMessage(event) {
|
12860 | if (transmuxer.currentTransmux !== options) {
|
12861 |
|
12862 | return;
|
12863 | }
|
12864 |
|
12865 | if (event.data.action === 'data') {
|
12866 | handleData_(event, transmuxedData, onData);
|
12867 | }
|
12868 |
|
12869 | if (event.data.action === 'trackinfo') {
|
12870 | onTrackInfo(event.data.trackInfo);
|
12871 | }
|
12872 |
|
12873 | if (event.data.action === 'gopInfo') {
|
12874 | handleGopInfo_(event, transmuxedData);
|
12875 | }
|
12876 |
|
12877 | if (event.data.action === 'audioTimingInfo') {
|
12878 | onAudioTimingInfo(event.data.audioTimingInfo);
|
12879 | }
|
12880 |
|
12881 | if (event.data.action === 'videoTimingInfo') {
|
12882 | onVideoTimingInfo(event.data.videoTimingInfo);
|
12883 | }
|
12884 |
|
12885 | if (event.data.action === 'videoSegmentTimingInfo') {
|
12886 | onVideoSegmentTimingInfo(event.data.videoSegmentTimingInfo);
|
12887 | }
|
12888 |
|
12889 | if (event.data.action === 'audioSegmentTimingInfo') {
|
12890 | onAudioSegmentTimingInfo(event.data.audioSegmentTimingInfo);
|
12891 | }
|
12892 |
|
12893 | if (event.data.action === 'id3Frame') {
|
12894 | onId3([event.data.id3Frame], event.data.id3Frame.dispatchType);
|
12895 | }
|
12896 |
|
12897 | if (event.data.action === 'caption') {
|
12898 | onCaptions(event.data.caption);
|
12899 | }
|
12900 |
|
12901 | if (event.data.action === 'endedtimeline') {
|
12902 | waitForEndedTimelineEvent = false;
|
12903 | onEndedTimeline();
|
12904 | }
|
12905 |
|
12906 | if (event.data.action === 'log') {
|
12907 | onTransmuxerLog(event.data.log);
|
12908 | }
|
12909 |
|
12910 |
|
12911 | if (event.data.type !== 'transmuxed') {
|
12912 | return;
|
12913 | }
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 | if (waitForEndedTimelineEvent) {
|
12920 | return;
|
12921 | }
|
12922 |
|
12923 | transmuxer.onmessage = null;
|
12924 | handleDone_({
|
12925 | transmuxedData: transmuxedData,
|
12926 | callback: onDone
|
12927 | });
|
12928 |
|
12929 |
|
12930 | dequeue(transmuxer);
|
12931 |
|
12932 | };
|
12933 |
|
12934 | transmuxer.onmessage = handleMessage;
|
12935 |
|
12936 | if (audioAppendStart) {
|
12937 | transmuxer.postMessage({
|
12938 | action: 'setAudioAppendStart',
|
12939 | appendStart: audioAppendStart
|
12940 | });
|
12941 | }
|
12942 |
|
12943 |
|
12944 | if (Array.isArray(gopsToAlignWith)) {
|
12945 | transmuxer.postMessage({
|
12946 | action: 'alignGopsWith',
|
12947 | gopsToAlignWith: gopsToAlignWith
|
12948 | });
|
12949 | }
|
12950 |
|
12951 | if (typeof remux !== 'undefined') {
|
12952 | transmuxer.postMessage({
|
12953 | action: 'setRemux',
|
12954 | remux: remux
|
12955 | });
|
12956 | }
|
12957 |
|
12958 | if (bytes.byteLength) {
|
12959 | var buffer = bytes instanceof ArrayBuffer ? bytes : bytes.buffer;
|
12960 | var byteOffset = bytes instanceof ArrayBuffer ? 0 : bytes.byteOffset;
|
12961 | transmuxer.postMessage({
|
12962 | action: 'push',
|
12963 |
|
12964 |
|
12965 |
|
12966 | data: buffer,
|
12967 |
|
12968 |
|
12969 | byteOffset: byteOffset,
|
12970 | byteLength: bytes.byteLength
|
12971 | }, [buffer]);
|
12972 | }
|
12973 |
|
12974 | if (isEndOfTimeline) {
|
12975 | transmuxer.postMessage({
|
12976 | action: 'endTimeline'
|
12977 | });
|
12978 | }
|
12979 |
|
12980 |
|
12981 |
|
12982 | transmuxer.postMessage({
|
12983 | action: 'flush'
|
12984 | });
|
12985 | };
|
12986 | var dequeue = function dequeue(transmuxer) {
|
12987 | transmuxer.currentTransmux = null;
|
12988 |
|
12989 | if (transmuxer.transmuxQueue.length) {
|
12990 | transmuxer.currentTransmux = transmuxer.transmuxQueue.shift();
|
12991 |
|
12992 | if (typeof transmuxer.currentTransmux === 'function') {
|
12993 | transmuxer.currentTransmux();
|
12994 | } else {
|
12995 | processTransmux(transmuxer.currentTransmux);
|
12996 | }
|
12997 | }
|
12998 | };
|
12999 | var processAction = function processAction(transmuxer, action) {
|
13000 | transmuxer.postMessage({
|
13001 | action: action
|
13002 | });
|
13003 | dequeue(transmuxer);
|
13004 | };
|
13005 | var enqueueAction = function enqueueAction(action, transmuxer) {
|
13006 | if (!transmuxer.currentTransmux) {
|
13007 | transmuxer.currentTransmux = action;
|
13008 | processAction(transmuxer, action);
|
13009 | return;
|
13010 | }
|
13011 |
|
13012 | transmuxer.transmuxQueue.push(processAction.bind(null, transmuxer, action));
|
13013 | };
|
13014 | var reset = function reset(transmuxer) {
|
13015 | enqueueAction('reset', transmuxer);
|
13016 | };
|
13017 | var endTimeline = function endTimeline(transmuxer) {
|
13018 | enqueueAction('endTimeline', transmuxer);
|
13019 | };
|
13020 | var transmux = function transmux(options) {
|
13021 | if (!options.transmuxer.currentTransmux) {
|
13022 | options.transmuxer.currentTransmux = options;
|
13023 | processTransmux(options);
|
13024 | return;
|
13025 | }
|
13026 |
|
13027 | options.transmuxer.transmuxQueue.push(options);
|
13028 | };
|
13029 | var createTransmuxer = function createTransmuxer(options) {
|
13030 | var transmuxer = new TransmuxWorker();
|
13031 | transmuxer.currentTransmux = null;
|
13032 | transmuxer.transmuxQueue = [];
|
13033 | var term = transmuxer.terminate;
|
13034 |
|
13035 | transmuxer.terminate = function () {
|
13036 | transmuxer.currentTransmux = null;
|
13037 | transmuxer.transmuxQueue.length = 0;
|
13038 | return term.call(transmuxer);
|
13039 | };
|
13040 |
|
13041 | transmuxer.postMessage({
|
13042 | action: 'init',
|
13043 | options: options
|
13044 | });
|
13045 | return transmuxer;
|
13046 | };
|
13047 | var segmentTransmuxer = {
|
13048 | reset: reset,
|
13049 | endTimeline: endTimeline,
|
13050 | transmux: transmux,
|
13051 | createTransmuxer: createTransmuxer
|
13052 | };
|
13053 |
|
13054 | var workerCallback = function workerCallback(options) {
|
13055 | var transmuxer = options.transmuxer;
|
13056 | var endAction = options.endAction || options.action;
|
13057 | var callback = options.callback;
|
13058 |
|
13059 | var message = _extends__default["default"]({}, options, {
|
13060 | endAction: null,
|
13061 | transmuxer: null,
|
13062 | callback: null
|
13063 | });
|
13064 |
|
13065 | var listenForEndEvent = function listenForEndEvent(event) {
|
13066 | if (event.data.action !== endAction) {
|
13067 | return;
|
13068 | }
|
13069 |
|
13070 | transmuxer.removeEventListener('message', listenForEndEvent);
|
13071 |
|
13072 | if (event.data.data) {
|
13073 | event.data.data = new Uint8Array(event.data.data, options.byteOffset || 0, options.byteLength || event.data.data.byteLength);
|
13074 |
|
13075 | if (options.data) {
|
13076 | options.data = event.data.data;
|
13077 | }
|
13078 | }
|
13079 |
|
13080 | callback(event.data);
|
13081 | };
|
13082 |
|
13083 | transmuxer.addEventListener('message', listenForEndEvent);
|
13084 |
|
13085 | if (options.data) {
|
13086 | var isArrayBuffer = options.data instanceof ArrayBuffer;
|
13087 | message.byteOffset = isArrayBuffer ? 0 : options.data.byteOffset;
|
13088 | message.byteLength = options.data.byteLength;
|
13089 | var transfers = [isArrayBuffer ? options.data : options.data.buffer];
|
13090 | transmuxer.postMessage(message, transfers);
|
13091 | } else {
|
13092 | transmuxer.postMessage(message);
|
13093 | }
|
13094 | };
|
13095 |
|
13096 | var REQUEST_ERRORS = {
|
13097 | FAILURE: 2,
|
13098 | TIMEOUT: -101,
|
13099 | ABORTED: -102
|
13100 | };
|
13101 |
|
13102 |
|
13103 |
|
13104 |
|
13105 |
|
13106 |
|
13107 | var abortAll = function abortAll(activeXhrs) {
|
13108 | activeXhrs.forEach(function (xhr) {
|
13109 | xhr.abort();
|
13110 | });
|
13111 | };
|
13112 |
|
13113 |
|
13114 |
|
13115 |
|
13116 |
|
13117 |
|
13118 |
|
13119 | var getRequestStats = function getRequestStats(request) {
|
13120 | return {
|
13121 | bandwidth: request.bandwidth,
|
13122 | bytesReceived: request.bytesReceived || 0,
|
13123 | roundTripTime: request.roundTripTime || 0
|
13124 | };
|
13125 | };
|
13126 |
|
13127 |
|
13128 |
|
13129 |
|
13130 |
|
13131 |
|
13132 |
|
13133 |
|
13134 | var getProgressStats = function getProgressStats(progressEvent) {
|
13135 | var request = progressEvent.target;
|
13136 | var roundTripTime = Date.now() - request.requestTime;
|
13137 | var stats = {
|
13138 | bandwidth: Infinity,
|
13139 | bytesReceived: 0,
|
13140 | roundTripTime: roundTripTime || 0
|
13141 | };
|
13142 | stats.bytesReceived = progressEvent.loaded;
|
13143 |
|
13144 |
|
13145 |
|
13146 | stats.bandwidth = Math.floor(stats.bytesReceived / stats.roundTripTime * 8 * 1000);
|
13147 | return stats;
|
13148 | };
|
13149 |
|
13150 |
|
13151 |
|
13152 |
|
13153 |
|
13154 |
|
13155 |
|
13156 |
|
13157 |
|
13158 | var handleErrors = function handleErrors(error, request) {
|
13159 | if (request.timedout) {
|
13160 | return {
|
13161 | status: request.status,
|
13162 | message: 'HLS request timed-out at URL: ' + request.uri,
|
13163 | code: REQUEST_ERRORS.TIMEOUT,
|
13164 | xhr: request
|
13165 | };
|
13166 | }
|
13167 |
|
13168 | if (request.aborted) {
|
13169 | return {
|
13170 | status: request.status,
|
13171 | message: 'HLS request aborted at URL: ' + request.uri,
|
13172 | code: REQUEST_ERRORS.ABORTED,
|
13173 | xhr: request
|
13174 | };
|
13175 | }
|
13176 |
|
13177 | if (error) {
|
13178 | return {
|
13179 | status: request.status,
|
13180 | message: 'HLS request errored at URL: ' + request.uri,
|
13181 | code: REQUEST_ERRORS.FAILURE,
|
13182 | xhr: request
|
13183 | };
|
13184 | }
|
13185 |
|
13186 | if (request.responseType === 'arraybuffer' && request.response.byteLength === 0) {
|
13187 | return {
|
13188 | status: request.status,
|
13189 | message: 'Empty HLS response at URL: ' + request.uri,
|
13190 | code: REQUEST_ERRORS.FAILURE,
|
13191 | xhr: request
|
13192 | };
|
13193 | }
|
13194 |
|
13195 | return null;
|
13196 | };
|
13197 |
|
13198 |
|
13199 |
|
13200 |
|
13201 |
|
13202 |
|
13203 |
|
13204 |
|
13205 |
|
13206 |
|
13207 |
|
13208 |
|
13209 | var handleKeyResponse = function handleKeyResponse(segment, objects, finishProcessingFn) {
|
13210 | return function (error, request) {
|
13211 | var response = request.response;
|
13212 | var errorObj = handleErrors(error, request);
|
13213 |
|
13214 | if (errorObj) {
|
13215 | return finishProcessingFn(errorObj, segment);
|
13216 | }
|
13217 |
|
13218 | if (response.byteLength !== 16) {
|
13219 | return finishProcessingFn({
|
13220 | status: request.status,
|
13221 | message: 'Invalid HLS key at URL: ' + request.uri,
|
13222 | code: REQUEST_ERRORS.FAILURE,
|
13223 | xhr: request
|
13224 | }, segment);
|
13225 | }
|
13226 |
|
13227 | var view = new DataView(response);
|
13228 | var bytes = new Uint32Array([view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12)]);
|
13229 |
|
13230 | for (var i = 0; i < objects.length; i++) {
|
13231 | objects[i].bytes = bytes;
|
13232 | }
|
13233 |
|
13234 | return finishProcessingFn(null, segment);
|
13235 | };
|
13236 | };
|
13237 |
|
13238 | var parseInitSegment = function parseInitSegment(segment, _callback) {
|
13239 | var type = containers.detectContainerForBytes(segment.map.bytes);
|
13240 |
|
13241 |
|
13242 | if (type !== 'mp4') {
|
13243 | var uri = segment.map.resolvedUri || segment.map.uri;
|
13244 | return _callback({
|
13245 | internal: true,
|
13246 | message: "Found unsupported " + (type || 'unknown') + " container for initialization segment at URL: " + uri,
|
13247 | code: REQUEST_ERRORS.FAILURE
|
13248 | });
|
13249 | }
|
13250 |
|
13251 | workerCallback({
|
13252 | action: 'probeMp4Tracks',
|
13253 | data: segment.map.bytes,
|
13254 | transmuxer: segment.transmuxer,
|
13255 | callback: function callback(_ref) {
|
13256 | var tracks = _ref.tracks,
|
13257 | data = _ref.data;
|
13258 |
|
13259 | segment.map.bytes = data;
|
13260 | tracks.forEach(function (track) {
|
13261 | segment.map.tracks = segment.map.tracks || {};
|
13262 |
|
13263 | if (segment.map.tracks[track.type]) {
|
13264 | return;
|
13265 | }
|
13266 |
|
13267 | segment.map.tracks[track.type] = track;
|
13268 |
|
13269 | if (typeof track.id === 'number' && track.timescale) {
|
13270 | segment.map.timescales = segment.map.timescales || {};
|
13271 | segment.map.timescales[track.id] = track.timescale;
|
13272 | }
|
13273 | });
|
13274 | return _callback(null);
|
13275 | }
|
13276 | });
|
13277 | };
|
13278 |
|
13279 |
|
13280 |
|
13281 |
|
13282 |
|
13283 |
|
13284 |
|
13285 |
|
13286 |
|
13287 |
|
13288 | var handleInitSegmentResponse = function handleInitSegmentResponse(_ref2) {
|
13289 | var segment = _ref2.segment,
|
13290 | finishProcessingFn = _ref2.finishProcessingFn;
|
13291 | return function (error, request) {
|
13292 | var errorObj = handleErrors(error, request);
|
13293 |
|
13294 | if (errorObj) {
|
13295 | return finishProcessingFn(errorObj, segment);
|
13296 | }
|
13297 |
|
13298 | var bytes = new Uint8Array(request.response);
|
13299 |
|
13300 |
|
13301 | if (segment.map.key) {
|
13302 | segment.map.encryptedBytes = bytes;
|
13303 | return finishProcessingFn(null, segment);
|
13304 | }
|
13305 |
|
13306 | segment.map.bytes = bytes;
|
13307 | parseInitSegment(segment, function (parseError) {
|
13308 | if (parseError) {
|
13309 | parseError.xhr = request;
|
13310 | parseError.status = request.status;
|
13311 | return finishProcessingFn(parseError, segment);
|
13312 | }
|
13313 |
|
13314 | finishProcessingFn(null, segment);
|
13315 | });
|
13316 | };
|
13317 | };
|
13318 |
|
13319 |
|
13320 |
|
13321 |
|
13322 |
|
13323 |
|
13324 |
|
13325 |
|
13326 |
|
13327 |
|
13328 |
|
13329 |
|
13330 | var handleSegmentResponse = function handleSegmentResponse(_ref3) {
|
13331 | var segment = _ref3.segment,
|
13332 | finishProcessingFn = _ref3.finishProcessingFn,
|
13333 | responseType = _ref3.responseType;
|
13334 | return function (error, request) {
|
13335 | var errorObj = handleErrors(error, request);
|
13336 |
|
13337 | if (errorObj) {
|
13338 | return finishProcessingFn(errorObj, segment);
|
13339 | }
|
13340 |
|
13341 | var newBytes =
|
13342 |
|
13343 |
|
13344 |
|
13345 |
|
13346 | responseType === 'arraybuffer' || !request.responseText ? request.response : stringToArrayBuffer(request.responseText.substring(segment.lastReachedChar || 0));
|
13347 | segment.stats = getRequestStats(request);
|
13348 |
|
13349 | if (segment.key) {
|
13350 | segment.encryptedBytes = new Uint8Array(newBytes);
|
13351 | } else {
|
13352 | segment.bytes = new Uint8Array(newBytes);
|
13353 | }
|
13354 |
|
13355 | return finishProcessingFn(null, segment);
|
13356 | };
|
13357 | };
|
13358 |
|
13359 | var transmuxAndNotify = function transmuxAndNotify(_ref4) {
|
13360 | var segment = _ref4.segment,
|
13361 | bytes = _ref4.bytes,
|
13362 | trackInfoFn = _ref4.trackInfoFn,
|
13363 | timingInfoFn = _ref4.timingInfoFn,
|
13364 | videoSegmentTimingInfoFn = _ref4.videoSegmentTimingInfoFn,
|
13365 | audioSegmentTimingInfoFn = _ref4.audioSegmentTimingInfoFn,
|
13366 | id3Fn = _ref4.id3Fn,
|
13367 | captionsFn = _ref4.captionsFn,
|
13368 | isEndOfTimeline = _ref4.isEndOfTimeline,
|
13369 | endedTimelineFn = _ref4.endedTimelineFn,
|
13370 | dataFn = _ref4.dataFn,
|
13371 | doneFn = _ref4.doneFn,
|
13372 | onTransmuxerLog = _ref4.onTransmuxerLog;
|
13373 | var fmp4Tracks = segment.map && segment.map.tracks || {};
|
13374 | var isMuxed = Boolean(fmp4Tracks.audio && fmp4Tracks.video);
|
13375 |
|
13376 |
|
13377 |
|
13378 | var audioStartFn = timingInfoFn.bind(null, segment, 'audio', 'start');
|
13379 | var audioEndFn = timingInfoFn.bind(null, segment, 'audio', 'end');
|
13380 | var videoStartFn = timingInfoFn.bind(null, segment, 'video', 'start');
|
13381 | var videoEndFn = timingInfoFn.bind(null, segment, 'video', 'end');
|
13382 |
|
13383 | var finish = function finish() {
|
13384 | return transmux({
|
13385 | bytes: bytes,
|
13386 | transmuxer: segment.transmuxer,
|
13387 | audioAppendStart: segment.audioAppendStart,
|
13388 | gopsToAlignWith: segment.gopsToAlignWith,
|
13389 | remux: isMuxed,
|
13390 | onData: function onData(result) {
|
13391 | result.type = result.type === 'combined' ? 'video' : result.type;
|
13392 | dataFn(segment, result);
|
13393 | },
|
13394 | onTrackInfo: function onTrackInfo(trackInfo) {
|
13395 | if (trackInfoFn) {
|
13396 | if (isMuxed) {
|
13397 | trackInfo.isMuxed = true;
|
13398 | }
|
13399 |
|
13400 | trackInfoFn(segment, trackInfo);
|
13401 | }
|
13402 | },
|
13403 | onAudioTimingInfo: function onAudioTimingInfo(audioTimingInfo) {
|
13404 |
|
13405 | if (audioStartFn && typeof audioTimingInfo.start !== 'undefined') {
|
13406 | audioStartFn(audioTimingInfo.start);
|
13407 | audioStartFn = null;
|
13408 | }
|
13409 |
|
13410 |
|
13411 | if (audioEndFn && typeof audioTimingInfo.end !== 'undefined') {
|
13412 | audioEndFn(audioTimingInfo.end);
|
13413 | }
|
13414 | },
|
13415 | onVideoTimingInfo: function onVideoTimingInfo(videoTimingInfo) {
|
13416 |
|
13417 | if (videoStartFn && typeof videoTimingInfo.start !== 'undefined') {
|
13418 | videoStartFn(videoTimingInfo.start);
|
13419 | videoStartFn = null;
|
13420 | }
|
13421 |
|
13422 |
|
13423 | if (videoEndFn && typeof videoTimingInfo.end !== 'undefined') {
|
13424 | videoEndFn(videoTimingInfo.end);
|
13425 | }
|
13426 | },
|
13427 | onVideoSegmentTimingInfo: function onVideoSegmentTimingInfo(videoSegmentTimingInfo) {
|
13428 | videoSegmentTimingInfoFn(videoSegmentTimingInfo);
|
13429 | },
|
13430 | onAudioSegmentTimingInfo: function onAudioSegmentTimingInfo(audioSegmentTimingInfo) {
|
13431 | audioSegmentTimingInfoFn(audioSegmentTimingInfo);
|
13432 | },
|
13433 | onId3: function onId3(id3Frames, dispatchType) {
|
13434 | id3Fn(segment, id3Frames, dispatchType);
|
13435 | },
|
13436 | onCaptions: function onCaptions(captions) {
|
13437 | captionsFn(segment, [captions]);
|
13438 | },
|
13439 | isEndOfTimeline: isEndOfTimeline,
|
13440 | onEndedTimeline: function onEndedTimeline() {
|
13441 | endedTimelineFn();
|
13442 | },
|
13443 | onTransmuxerLog: onTransmuxerLog,
|
13444 | onDone: function onDone(result) {
|
13445 | if (!doneFn) {
|
13446 | return;
|
13447 | }
|
13448 |
|
13449 | result.type = result.type === 'combined' ? 'video' : result.type;
|
13450 | doneFn(null, segment, result);
|
13451 | }
|
13452 | });
|
13453 | };
|
13454 |
|
13455 |
|
13456 |
|
13457 |
|
13458 | workerCallback({
|
13459 | action: 'probeTs',
|
13460 | transmuxer: segment.transmuxer,
|
13461 | data: bytes,
|
13462 | baseStartTime: segment.baseStartTime,
|
13463 | callback: function callback(data) {
|
13464 | segment.bytes = bytes = data.data;
|
13465 | var probeResult = data.result;
|
13466 |
|
13467 | if (probeResult) {
|
13468 | trackInfoFn(segment, {
|
13469 | hasAudio: probeResult.hasAudio,
|
13470 | hasVideo: probeResult.hasVideo,
|
13471 | isMuxed: isMuxed
|
13472 | });
|
13473 | trackInfoFn = null;
|
13474 |
|
13475 | if (probeResult.hasAudio && !isMuxed) {
|
13476 | audioStartFn(probeResult.audioStart);
|
13477 | }
|
13478 |
|
13479 | if (probeResult.hasVideo) {
|
13480 | videoStartFn(probeResult.videoStart);
|
13481 | }
|
13482 |
|
13483 | audioStartFn = null;
|
13484 | videoStartFn = null;
|
13485 | }
|
13486 |
|
13487 | finish();
|
13488 | }
|
13489 | });
|
13490 | };
|
13491 |
|
13492 | var handleSegmentBytes = function handleSegmentBytes(_ref5) {
|
13493 | var segment = _ref5.segment,
|
13494 | bytes = _ref5.bytes,
|
13495 | trackInfoFn = _ref5.trackInfoFn,
|
13496 | timingInfoFn = _ref5.timingInfoFn,
|
13497 | videoSegmentTimingInfoFn = _ref5.videoSegmentTimingInfoFn,
|
13498 | audioSegmentTimingInfoFn = _ref5.audioSegmentTimingInfoFn,
|
13499 | id3Fn = _ref5.id3Fn,
|
13500 | captionsFn = _ref5.captionsFn,
|
13501 | isEndOfTimeline = _ref5.isEndOfTimeline,
|
13502 | endedTimelineFn = _ref5.endedTimelineFn,
|
13503 | dataFn = _ref5.dataFn,
|
13504 | doneFn = _ref5.doneFn,
|
13505 | onTransmuxerLog = _ref5.onTransmuxerLog;
|
13506 | var bytesAsUint8Array = new Uint8Array(bytes);
|
13507 |
|
13508 |
|
13509 |
|
13510 |
|
13511 |
|
13512 | if (containers.isLikelyFmp4MediaSegment(bytesAsUint8Array)) {
|
13513 | segment.isFmp4 = true;
|
13514 | var tracks = segment.map.tracks;
|
13515 | var trackInfo = {
|
13516 | isFmp4: true,
|
13517 | hasVideo: !!tracks.video,
|
13518 | hasAudio: !!tracks.audio
|
13519 | };
|
13520 |
|
13521 |
|
13522 | if (tracks.audio && tracks.audio.codec && tracks.audio.codec !== 'enca') {
|
13523 | trackInfo.audioCodec = tracks.audio.codec;
|
13524 | }
|
13525 |
|
13526 |
|
13527 |
|
13528 | if (tracks.video && tracks.video.codec && tracks.video.codec !== 'encv') {
|
13529 | trackInfo.videoCodec = tracks.video.codec;
|
13530 | }
|
13531 |
|
13532 | if (tracks.video && tracks.audio) {
|
13533 | trackInfo.isMuxed = true;
|
13534 | }
|
13535 |
|
13536 |
|
13537 |
|
13538 | trackInfoFn(segment, trackInfo);
|
13539 |
|
13540 |
|
13541 |
|
13542 |
|
13543 |
|
13544 |
|
13545 | var finishLoading = function finishLoading(captions) {
|
13546 |
|
13547 |
|
13548 |
|
13549 |
|
13550 | dataFn(segment, {
|
13551 | data: bytesAsUint8Array,
|
13552 | type: trackInfo.hasAudio && !trackInfo.isMuxed ? 'audio' : 'video'
|
13553 | });
|
13554 |
|
13555 | if (captions && captions.length) {
|
13556 | captionsFn(segment, captions);
|
13557 | }
|
13558 |
|
13559 | doneFn(null, segment, {});
|
13560 | };
|
13561 |
|
13562 | workerCallback({
|
13563 | action: 'probeMp4StartTime',
|
13564 | timescales: segment.map.timescales,
|
13565 | data: bytesAsUint8Array,
|
13566 | transmuxer: segment.transmuxer,
|
13567 | callback: function callback(_ref6) {
|
13568 | var data = _ref6.data,
|
13569 | startTime = _ref6.startTime;
|
13570 |
|
13571 | bytes = data.buffer;
|
13572 | segment.bytes = bytesAsUint8Array = data;
|
13573 |
|
13574 | if (trackInfo.hasAudio && !trackInfo.isMuxed) {
|
13575 | timingInfoFn(segment, 'audio', 'start', startTime);
|
13576 | }
|
13577 |
|
13578 | if (trackInfo.hasVideo) {
|
13579 | timingInfoFn(segment, 'video', 'start', startTime);
|
13580 | }
|
13581 |
|
13582 |
|
13583 |
|
13584 | if (!tracks.video || !data.byteLength || !segment.transmuxer) {
|
13585 | finishLoading();
|
13586 | return;
|
13587 | }
|
13588 |
|
13589 | workerCallback({
|
13590 | action: 'pushMp4Captions',
|
13591 | endAction: 'mp4Captions',
|
13592 | transmuxer: segment.transmuxer,
|
13593 | data: bytesAsUint8Array,
|
13594 | timescales: segment.map.timescales,
|
13595 | trackIds: [tracks.video.id],
|
13596 | callback: function callback(message) {
|
13597 |
|
13598 | bytes = message.data.buffer;
|
13599 | segment.bytes = bytesAsUint8Array = message.data;
|
13600 | message.logs.forEach(function (log) {
|
13601 | onTransmuxerLog(videojs__default["default"].mergeOptions(log, {
|
13602 | stream: 'mp4CaptionParser'
|
13603 | }));
|
13604 | });
|
13605 | finishLoading(message.captions);
|
13606 | }
|
13607 | });
|
13608 | }
|
13609 | });
|
13610 | return;
|
13611 | }
|
13612 |
|
13613 |
|
13614 | if (!segment.transmuxer) {
|
13615 | doneFn(null, segment, {});
|
13616 | return;
|
13617 | }
|
13618 |
|
13619 | if (typeof segment.container === 'undefined') {
|
13620 | segment.container = containers.detectContainerForBytes(bytesAsUint8Array);
|
13621 | }
|
13622 |
|
13623 | if (segment.container !== 'ts' && segment.container !== 'aac') {
|
13624 | trackInfoFn(segment, {
|
13625 | hasAudio: false,
|
13626 | hasVideo: false
|
13627 | });
|
13628 | doneFn(null, segment, {});
|
13629 | return;
|
13630 | }
|
13631 |
|
13632 |
|
13633 | transmuxAndNotify({
|
13634 | segment: segment,
|
13635 | bytes: bytes,
|
13636 | trackInfoFn: trackInfoFn,
|
13637 | timingInfoFn: timingInfoFn,
|
13638 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13639 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13640 | id3Fn: id3Fn,
|
13641 | captionsFn: captionsFn,
|
13642 | isEndOfTimeline: isEndOfTimeline,
|
13643 | endedTimelineFn: endedTimelineFn,
|
13644 | dataFn: dataFn,
|
13645 | doneFn: doneFn,
|
13646 | onTransmuxerLog: onTransmuxerLog
|
13647 | });
|
13648 | };
|
13649 |
|
13650 | var decrypt = function decrypt(_ref7, callback) {
|
13651 | var id = _ref7.id,
|
13652 | key = _ref7.key,
|
13653 | encryptedBytes = _ref7.encryptedBytes,
|
13654 | decryptionWorker = _ref7.decryptionWorker;
|
13655 |
|
13656 | var decryptionHandler = function decryptionHandler(event) {
|
13657 | if (event.data.source === id) {
|
13658 | decryptionWorker.removeEventListener('message', decryptionHandler);
|
13659 | var decrypted = event.data.decrypted;
|
13660 | callback(new Uint8Array(decrypted.bytes, decrypted.byteOffset, decrypted.byteLength));
|
13661 | }
|
13662 | };
|
13663 |
|
13664 | decryptionWorker.addEventListener('message', decryptionHandler);
|
13665 | var keyBytes;
|
13666 |
|
13667 | if (key.bytes.slice) {
|
13668 | keyBytes = key.bytes.slice();
|
13669 | } else {
|
13670 | keyBytes = new Uint32Array(Array.prototype.slice.call(key.bytes));
|
13671 | }
|
13672 |
|
13673 |
|
13674 | decryptionWorker.postMessage(createTransferableMessage({
|
13675 | source: id,
|
13676 | encrypted: encryptedBytes,
|
13677 | key: keyBytes,
|
13678 | iv: key.iv
|
13679 | }), [encryptedBytes.buffer, keyBytes.buffer]);
|
13680 | };
|
13681 |
|
13682 |
|
13683 |
|
13684 |
|
13685 |
|
13686 |
|
13687 |
|
13688 |
|
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 |
|
13698 |
|
13699 |
|
13700 |
|
13701 |
|
13702 |
|
13703 |
|
13704 |
|
13705 |
|
13706 |
|
13707 | var decryptSegment = function decryptSegment(_ref8) {
|
13708 | var decryptionWorker = _ref8.decryptionWorker,
|
13709 | segment = _ref8.segment,
|
13710 | trackInfoFn = _ref8.trackInfoFn,
|
13711 | timingInfoFn = _ref8.timingInfoFn,
|
13712 | videoSegmentTimingInfoFn = _ref8.videoSegmentTimingInfoFn,
|
13713 | audioSegmentTimingInfoFn = _ref8.audioSegmentTimingInfoFn,
|
13714 | id3Fn = _ref8.id3Fn,
|
13715 | captionsFn = _ref8.captionsFn,
|
13716 | isEndOfTimeline = _ref8.isEndOfTimeline,
|
13717 | endedTimelineFn = _ref8.endedTimelineFn,
|
13718 | dataFn = _ref8.dataFn,
|
13719 | doneFn = _ref8.doneFn,
|
13720 | onTransmuxerLog = _ref8.onTransmuxerLog;
|
13721 | decrypt({
|
13722 | id: segment.requestId,
|
13723 | key: segment.key,
|
13724 | encryptedBytes: segment.encryptedBytes,
|
13725 | decryptionWorker: decryptionWorker
|
13726 | }, function (decryptedBytes) {
|
13727 | segment.bytes = decryptedBytes;
|
13728 | handleSegmentBytes({
|
13729 | segment: segment,
|
13730 | bytes: segment.bytes,
|
13731 | trackInfoFn: trackInfoFn,
|
13732 | timingInfoFn: timingInfoFn,
|
13733 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13734 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13735 | id3Fn: id3Fn,
|
13736 | captionsFn: captionsFn,
|
13737 | isEndOfTimeline: isEndOfTimeline,
|
13738 | endedTimelineFn: endedTimelineFn,
|
13739 | dataFn: dataFn,
|
13740 | doneFn: doneFn,
|
13741 | onTransmuxerLog: onTransmuxerLog
|
13742 | });
|
13743 | });
|
13744 | };
|
13745 |
|
13746 |
|
13747 |
|
13748 |
|
13749 |
|
13750 |
|
13751 |
|
13752 |
|
13753 |
|
13754 |
|
13755 |
|
13756 |
|
13757 |
|
13758 |
|
13759 |
|
13760 |
|
13761 |
|
13762 |
|
13763 |
|
13764 |
|
13765 |
|
13766 |
|
13767 |
|
13768 |
|
13769 |
|
13770 |
|
13771 |
|
13772 |
|
13773 |
|
13774 |
|
13775 |
|
13776 | var waitForCompletion = function waitForCompletion(_ref9) {
|
13777 | var activeXhrs = _ref9.activeXhrs,
|
13778 | decryptionWorker = _ref9.decryptionWorker,
|
13779 | trackInfoFn = _ref9.trackInfoFn,
|
13780 | timingInfoFn = _ref9.timingInfoFn,
|
13781 | videoSegmentTimingInfoFn = _ref9.videoSegmentTimingInfoFn,
|
13782 | audioSegmentTimingInfoFn = _ref9.audioSegmentTimingInfoFn,
|
13783 | id3Fn = _ref9.id3Fn,
|
13784 | captionsFn = _ref9.captionsFn,
|
13785 | isEndOfTimeline = _ref9.isEndOfTimeline,
|
13786 | endedTimelineFn = _ref9.endedTimelineFn,
|
13787 | dataFn = _ref9.dataFn,
|
13788 | doneFn = _ref9.doneFn,
|
13789 | onTransmuxerLog = _ref9.onTransmuxerLog;
|
13790 | var count = 0;
|
13791 | var didError = false;
|
13792 | return function (error, segment) {
|
13793 | if (didError) {
|
13794 | return;
|
13795 | }
|
13796 |
|
13797 | if (error) {
|
13798 | didError = true;
|
13799 |
|
13800 | abortAll(activeXhrs);
|
13801 |
|
13802 |
|
13803 |
|
13804 |
|
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 | return doneFn(error, segment);
|
13813 | }
|
13814 |
|
13815 | count += 1;
|
13816 |
|
13817 | if (count === activeXhrs.length) {
|
13818 | var segmentFinish = function segmentFinish() {
|
13819 | if (segment.encryptedBytes) {
|
13820 | return decryptSegment({
|
13821 | decryptionWorker: decryptionWorker,
|
13822 | segment: segment,
|
13823 | trackInfoFn: trackInfoFn,
|
13824 | timingInfoFn: timingInfoFn,
|
13825 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13826 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13827 | id3Fn: id3Fn,
|
13828 | captionsFn: captionsFn,
|
13829 | isEndOfTimeline: isEndOfTimeline,
|
13830 | endedTimelineFn: endedTimelineFn,
|
13831 | dataFn: dataFn,
|
13832 | doneFn: doneFn,
|
13833 | onTransmuxerLog: onTransmuxerLog
|
13834 | });
|
13835 | }
|
13836 |
|
13837 |
|
13838 | handleSegmentBytes({
|
13839 | segment: segment,
|
13840 | bytes: segment.bytes,
|
13841 | trackInfoFn: trackInfoFn,
|
13842 | timingInfoFn: timingInfoFn,
|
13843 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13844 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13845 | id3Fn: id3Fn,
|
13846 | captionsFn: captionsFn,
|
13847 | isEndOfTimeline: isEndOfTimeline,
|
13848 | endedTimelineFn: endedTimelineFn,
|
13849 | dataFn: dataFn,
|
13850 | doneFn: doneFn,
|
13851 | onTransmuxerLog: onTransmuxerLog
|
13852 | });
|
13853 | };
|
13854 |
|
13855 |
|
13856 | segment.endOfAllRequests = Date.now();
|
13857 |
|
13858 | if (segment.map && segment.map.encryptedBytes && !segment.map.bytes) {
|
13859 | return decrypt({
|
13860 | decryptionWorker: decryptionWorker,
|
13861 |
|
13862 |
|
13863 |
|
13864 | id: segment.requestId + '-init',
|
13865 | encryptedBytes: segment.map.encryptedBytes,
|
13866 | key: segment.map.key
|
13867 | }, function (decryptedBytes) {
|
13868 | segment.map.bytes = decryptedBytes;
|
13869 | parseInitSegment(segment, function (parseError) {
|
13870 | if (parseError) {
|
13871 | abortAll(activeXhrs);
|
13872 | return doneFn(parseError, segment);
|
13873 | }
|
13874 |
|
13875 | segmentFinish();
|
13876 | });
|
13877 | });
|
13878 | }
|
13879 |
|
13880 | segmentFinish();
|
13881 | }
|
13882 | };
|
13883 | };
|
13884 |
|
13885 |
|
13886 |
|
13887 |
|
13888 |
|
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 | var handleLoadEnd = function handleLoadEnd(_ref10) {
|
13894 | var loadendState = _ref10.loadendState,
|
13895 | abortFn = _ref10.abortFn;
|
13896 | return function (event) {
|
13897 | var request = event.target;
|
13898 |
|
13899 | if (request.aborted && abortFn && !loadendState.calledAbortFn) {
|
13900 | abortFn();
|
13901 | loadendState.calledAbortFn = true;
|
13902 | }
|
13903 | };
|
13904 | };
|
13905 |
|
13906 |
|
13907 |
|
13908 |
|
13909 |
|
13910 |
|
13911 |
|
13912 |
|
13913 |
|
13914 |
|
13915 |
|
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 |
|
13921 |
|
13922 |
|
13923 |
|
13924 |
|
13925 |
|
13926 |
|
13927 |
|
13928 |
|
13929 |
|
13930 |
|
13931 |
|
13932 | var handleProgress = function handleProgress(_ref11) {
|
13933 | var segment = _ref11.segment,
|
13934 | progressFn = _ref11.progressFn;
|
13935 | _ref11.trackInfoFn;
|
13936 | _ref11.timingInfoFn;
|
13937 | _ref11.videoSegmentTimingInfoFn;
|
13938 | _ref11.audioSegmentTimingInfoFn;
|
13939 | _ref11.id3Fn;
|
13940 | _ref11.captionsFn;
|
13941 | _ref11.isEndOfTimeline;
|
13942 | _ref11.endedTimelineFn;
|
13943 | _ref11.dataFn;
|
13944 | return function (event) {
|
13945 | var request = event.target;
|
13946 |
|
13947 | if (request.aborted) {
|
13948 | return;
|
13949 | }
|
13950 |
|
13951 | segment.stats = videojs__default["default"].mergeOptions(segment.stats, getProgressStats(event));
|
13952 |
|
13953 | if (!segment.stats.firstBytesReceivedAt && segment.stats.bytesReceived) {
|
13954 | segment.stats.firstBytesReceivedAt = Date.now();
|
13955 | }
|
13956 |
|
13957 | return progressFn(event, segment);
|
13958 | };
|
13959 | };
|
13960 |
|
13961 |
|
13962 |
|
13963 |
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 |
|
13973 |
|
13974 |
|
13975 |
|
13976 |
|
13977 |
|
13978 |
|
13979 |
|
13980 |
|
13981 |
|
13982 |
|
13983 |
|
13984 |
|
13985 |
|
13986 |
|
13987 |
|
13988 |
|
13989 |
|
13990 |
|
13991 |
|
13992 |
|
13993 |
|
13994 |
|
13995 |
|
13996 |
|
13997 |
|
13998 |
|
13999 |
|
14000 |
|
14001 |
|
14002 |
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 |
|
14010 |
|
14011 |
|
14012 |
|
14013 |
|
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 |
|
14024 |
|
14025 |
|
14026 |
|
14027 |
|
14028 |
|
14029 |
|
14030 | var mediaSegmentRequest = function mediaSegmentRequest(_ref12) {
|
14031 | var xhr = _ref12.xhr,
|
14032 | xhrOptions = _ref12.xhrOptions,
|
14033 | decryptionWorker = _ref12.decryptionWorker,
|
14034 | segment = _ref12.segment,
|
14035 | abortFn = _ref12.abortFn,
|
14036 | progressFn = _ref12.progressFn,
|
14037 | trackInfoFn = _ref12.trackInfoFn,
|
14038 | timingInfoFn = _ref12.timingInfoFn,
|
14039 | videoSegmentTimingInfoFn = _ref12.videoSegmentTimingInfoFn,
|
14040 | audioSegmentTimingInfoFn = _ref12.audioSegmentTimingInfoFn,
|
14041 | id3Fn = _ref12.id3Fn,
|
14042 | captionsFn = _ref12.captionsFn,
|
14043 | isEndOfTimeline = _ref12.isEndOfTimeline,
|
14044 | endedTimelineFn = _ref12.endedTimelineFn,
|
14045 | dataFn = _ref12.dataFn,
|
14046 | doneFn = _ref12.doneFn,
|
14047 | onTransmuxerLog = _ref12.onTransmuxerLog;
|
14048 | var activeXhrs = [];
|
14049 | var finishProcessingFn = waitForCompletion({
|
14050 | activeXhrs: activeXhrs,
|
14051 | decryptionWorker: decryptionWorker,
|
14052 | trackInfoFn: trackInfoFn,
|
14053 | timingInfoFn: timingInfoFn,
|
14054 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
14055 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
14056 | id3Fn: id3Fn,
|
14057 | captionsFn: captionsFn,
|
14058 | isEndOfTimeline: isEndOfTimeline,
|
14059 | endedTimelineFn: endedTimelineFn,
|
14060 | dataFn: dataFn,
|
14061 | doneFn: doneFn,
|
14062 | onTransmuxerLog: onTransmuxerLog
|
14063 | });
|
14064 |
|
14065 | if (segment.key && !segment.key.bytes) {
|
14066 | var objects = [segment.key];
|
14067 |
|
14068 | if (segment.map && !segment.map.bytes && segment.map.key && segment.map.key.resolvedUri === segment.key.resolvedUri) {
|
14069 | objects.push(segment.map.key);
|
14070 | }
|
14071 |
|
14072 | var keyRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14073 | uri: segment.key.resolvedUri,
|
14074 | responseType: 'arraybuffer'
|
14075 | });
|
14076 | var keyRequestCallback = handleKeyResponse(segment, objects, finishProcessingFn);
|
14077 | var keyXhr = xhr(keyRequestOptions, keyRequestCallback);
|
14078 | activeXhrs.push(keyXhr);
|
14079 | }
|
14080 |
|
14081 |
|
14082 | if (segment.map && !segment.map.bytes) {
|
14083 | var differentMapKey = segment.map.key && (!segment.key || segment.key.resolvedUri !== segment.map.key.resolvedUri);
|
14084 |
|
14085 | if (differentMapKey) {
|
14086 | var mapKeyRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14087 | uri: segment.map.key.resolvedUri,
|
14088 | responseType: 'arraybuffer'
|
14089 | });
|
14090 | var mapKeyRequestCallback = handleKeyResponse(segment, [segment.map.key], finishProcessingFn);
|
14091 | var mapKeyXhr = xhr(mapKeyRequestOptions, mapKeyRequestCallback);
|
14092 | activeXhrs.push(mapKeyXhr);
|
14093 | }
|
14094 |
|
14095 | var initSegmentOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14096 | uri: segment.map.resolvedUri,
|
14097 | responseType: 'arraybuffer',
|
14098 | headers: segmentXhrHeaders(segment.map)
|
14099 | });
|
14100 | var initSegmentRequestCallback = handleInitSegmentResponse({
|
14101 | segment: segment,
|
14102 | finishProcessingFn: finishProcessingFn
|
14103 | });
|
14104 | var initSegmentXhr = xhr(initSegmentOptions, initSegmentRequestCallback);
|
14105 | activeXhrs.push(initSegmentXhr);
|
14106 | }
|
14107 |
|
14108 | var segmentRequestOptions = videojs__default["default"].mergeOptions(xhrOptions, {
|
14109 | uri: segment.part && segment.part.resolvedUri || segment.resolvedUri,
|
14110 | responseType: 'arraybuffer',
|
14111 | headers: segmentXhrHeaders(segment)
|
14112 | });
|
14113 | var segmentRequestCallback = handleSegmentResponse({
|
14114 | segment: segment,
|
14115 | finishProcessingFn: finishProcessingFn,
|
14116 | responseType: segmentRequestOptions.responseType
|
14117 | });
|
14118 | var segmentXhr = xhr(segmentRequestOptions, segmentRequestCallback);
|
14119 | segmentXhr.addEventListener('progress', handleProgress({
|
14120 | segment: segment,
|
14121 | progressFn: progressFn,
|
14122 | trackInfoFn: trackInfoFn,
|
14123 | timingInfoFn: timingInfoFn,
|
14124 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
14125 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
14126 | id3Fn: id3Fn,
|
14127 | captionsFn: captionsFn,
|
14128 | isEndOfTimeline: isEndOfTimeline,
|
14129 | endedTimelineFn: endedTimelineFn,
|
14130 | dataFn: dataFn
|
14131 | }));
|
14132 | activeXhrs.push(segmentXhr);
|
14133 |
|
14134 |
|
14135 | var loadendState = {};
|
14136 | activeXhrs.forEach(function (activeXhr) {
|
14137 | activeXhr.addEventListener('loadend', handleLoadEnd({
|
14138 | loadendState: loadendState,
|
14139 | abortFn: abortFn
|
14140 | }));
|
14141 | });
|
14142 | return function () {
|
14143 | return abortAll(activeXhrs);
|
14144 | };
|
14145 | };
|
14146 |
|
14147 |
|
14148 |
|
14149 |
|
14150 |
|
14151 | var logFn$1 = logger('CodecUtils');
|
14152 |
|
14153 |
|
14154 |
|
14155 |
|
14156 |
|
14157 |
|
14158 |
|
14159 |
|
14160 | var getCodecs = function getCodecs(media) {
|
14161 |
|
14162 |
|
14163 | var mediaAttributes = media.attributes || {};
|
14164 |
|
14165 | if (mediaAttributes.CODECS) {
|
14166 | return codecs_js.parseCodecs(mediaAttributes.CODECS);
|
14167 | }
|
14168 | };
|
14169 |
|
14170 | var isMaat = function isMaat(master, media) {
|
14171 | var mediaAttributes = media.attributes || {};
|
14172 | return master && master.mediaGroups && master.mediaGroups.AUDIO && mediaAttributes.AUDIO && master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
14173 | };
|
14174 | var isMuxed = function isMuxed(master, media) {
|
14175 | if (!isMaat(master, media)) {
|
14176 | return true;
|
14177 | }
|
14178 |
|
14179 | var mediaAttributes = media.attributes || {};
|
14180 | var audioGroup = master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
14181 |
|
14182 | for (var groupId in audioGroup) {
|
14183 |
|
14184 |
|
14185 |
|
14186 |
|
14187 | if (!audioGroup[groupId].uri && !audioGroup[groupId].playlists) {
|
14188 | return true;
|
14189 | }
|
14190 | }
|
14191 |
|
14192 | return false;
|
14193 | };
|
14194 | var unwrapCodecList = function unwrapCodecList(codecList) {
|
14195 | var codecs = {};
|
14196 | codecList.forEach(function (_ref) {
|
14197 | var mediaType = _ref.mediaType,
|
14198 | type = _ref.type,
|
14199 | details = _ref.details;
|
14200 | codecs[mediaType] = codecs[mediaType] || [];
|
14201 | codecs[mediaType].push(codecs_js.translateLegacyCodec("" + type + details));
|
14202 | });
|
14203 | Object.keys(codecs).forEach(function (mediaType) {
|
14204 | if (codecs[mediaType].length > 1) {
|
14205 | 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.");
|
14206 | codecs[mediaType] = null;
|
14207 | return;
|
14208 | }
|
14209 |
|
14210 | codecs[mediaType] = codecs[mediaType][0];
|
14211 | });
|
14212 | return codecs;
|
14213 | };
|
14214 | var codecCount = function codecCount(codecObj) {
|
14215 | var count = 0;
|
14216 |
|
14217 | if (codecObj.audio) {
|
14218 | count++;
|
14219 | }
|
14220 |
|
14221 | if (codecObj.video) {
|
14222 | count++;
|
14223 | }
|
14224 |
|
14225 | return count;
|
14226 | };
|
14227 |
|
14228 |
|
14229 |
|
14230 |
|
14231 |
|
14232 |
|
14233 |
|
14234 |
|
14235 |
|
14236 |
|
14237 |
|
14238 |
|
14239 |
|
14240 | var codecsForPlaylist = function codecsForPlaylist(master, media) {
|
14241 | var mediaAttributes = media.attributes || {};
|
14242 | var codecInfo = unwrapCodecList(getCodecs(media) || []);
|
14243 |
|
14244 |
|
14245 | if (isMaat(master, media) && !codecInfo.audio) {
|
14246 | if (!isMuxed(master, media)) {
|
14247 |
|
14248 |
|
14249 |
|
14250 | var defaultCodecs = unwrapCodecList(codecs_js.codecsFromDefault(master, mediaAttributes.AUDIO) || []);
|
14251 |
|
14252 | if (defaultCodecs.audio) {
|
14253 | codecInfo.audio = defaultCodecs.audio;
|
14254 | }
|
14255 | }
|
14256 | }
|
14257 |
|
14258 | return codecInfo;
|
14259 | };
|
14260 |
|
14261 | var logFn = logger('PlaylistSelector');
|
14262 |
|
14263 | var representationToString = function representationToString(representation) {
|
14264 | if (!representation || !representation.playlist) {
|
14265 | return;
|
14266 | }
|
14267 |
|
14268 | var playlist = representation.playlist;
|
14269 | return JSON.stringify({
|
14270 | id: playlist.id,
|
14271 | bandwidth: representation.bandwidth,
|
14272 | width: representation.width,
|
14273 | height: representation.height,
|
14274 | codecs: playlist.attributes && playlist.attributes.CODECS || ''
|
14275 | });
|
14276 | };
|
14277 |
|
14278 |
|
14279 |
|
14280 |
|
14281 |
|
14282 |
|
14283 |
|
14284 |
|
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 | var safeGetComputedStyle = function safeGetComputedStyle(el, property) {
|
14291 | if (!el) {
|
14292 | return '';
|
14293 | }
|
14294 |
|
14295 | var result = window__default["default"].getComputedStyle(el);
|
14296 |
|
14297 | if (!result) {
|
14298 | return '';
|
14299 | }
|
14300 |
|
14301 | return result[property];
|
14302 | };
|
14303 |
|
14304 |
|
14305 |
|
14306 |
|
14307 |
|
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 | var stableSort = function stableSort(array, sortFn) {
|
14313 | var newArray = array.slice();
|
14314 | array.sort(function (left, right) {
|
14315 | var cmp = sortFn(left, right);
|
14316 |
|
14317 | if (cmp === 0) {
|
14318 | return newArray.indexOf(left) - newArray.indexOf(right);
|
14319 | }
|
14320 |
|
14321 | return cmp;
|
14322 | });
|
14323 | };
|
14324 |
|
14325 |
|
14326 |
|
14327 |
|
14328 |
|
14329 |
|
14330 |
|
14331 |
|
14332 |
|
14333 |
|
14334 |
|
14335 |
|
14336 | var comparePlaylistBandwidth = function comparePlaylistBandwidth(left, right) {
|
14337 | var leftBandwidth;
|
14338 | var rightBandwidth;
|
14339 |
|
14340 | if (left.attributes.BANDWIDTH) {
|
14341 | leftBandwidth = left.attributes.BANDWIDTH;
|
14342 | }
|
14343 |
|
14344 | leftBandwidth = leftBandwidth || window__default["default"].Number.MAX_VALUE;
|
14345 |
|
14346 | if (right.attributes.BANDWIDTH) {
|
14347 | rightBandwidth = right.attributes.BANDWIDTH;
|
14348 | }
|
14349 |
|
14350 | rightBandwidth = rightBandwidth || window__default["default"].Number.MAX_VALUE;
|
14351 | return leftBandwidth - rightBandwidth;
|
14352 | };
|
14353 |
|
14354 |
|
14355 |
|
14356 |
|
14357 |
|
14358 |
|
14359 |
|
14360 |
|
14361 |
|
14362 |
|
14363 |
|
14364 | var comparePlaylistResolution = function comparePlaylistResolution(left, right) {
|
14365 | var leftWidth;
|
14366 | var rightWidth;
|
14367 |
|
14368 | if (left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
|
14369 | leftWidth = left.attributes.RESOLUTION.width;
|
14370 | }
|
14371 |
|
14372 | leftWidth = leftWidth || window__default["default"].Number.MAX_VALUE;
|
14373 |
|
14374 | if (right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
|
14375 | rightWidth = right.attributes.RESOLUTION.width;
|
14376 | }
|
14377 |
|
14378 | rightWidth = rightWidth || window__default["default"].Number.MAX_VALUE;
|
14379 |
|
14380 |
|
14381 | if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
|
14382 | return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
|
14383 | }
|
14384 |
|
14385 | return leftWidth - rightWidth;
|
14386 | };
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 |
|
14392 |
|
14393 |
|
14394 |
|
14395 |
|
14396 |
|
14397 |
|
14398 |
|
14399 |
|
14400 |
|
14401 |
|
14402 |
|
14403 |
|
14404 |
|
14405 |
|
14406 |
|
14407 | var simpleSelector = function simpleSelector(master, playerBandwidth, playerWidth, playerHeight, limitRenditionByPlayerDimensions, masterPlaylistController) {
|
14408 |
|
14409 | if (!master) {
|
14410 | return;
|
14411 | }
|
14412 |
|
14413 | var options = {
|
14414 | bandwidth: playerBandwidth,
|
14415 | width: playerWidth,
|
14416 | height: playerHeight,
|
14417 | limitRenditionByPlayerDimensions: limitRenditionByPlayerDimensions
|
14418 | };
|
14419 | var playlists = master.playlists;
|
14420 |
|
14421 | if (Playlist.isAudioOnly(master)) {
|
14422 | playlists = masterPlaylistController.getAudioTrackPlaylists_();
|
14423 |
|
14424 |
|
14425 | options.audioOnly = true;
|
14426 | }
|
14427 |
|
14428 |
|
14429 | var sortedPlaylistReps = playlists.map(function (playlist) {
|
14430 | var bandwidth;
|
14431 | var width = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width;
|
14432 | var height = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.height;
|
14433 | bandwidth = playlist.attributes && playlist.attributes.BANDWIDTH;
|
14434 | bandwidth = bandwidth || window__default["default"].Number.MAX_VALUE;
|
14435 | return {
|
14436 | bandwidth: bandwidth,
|
14437 | width: width,
|
14438 | height: height,
|
14439 | playlist: playlist
|
14440 | };
|
14441 | });
|
14442 | stableSort(sortedPlaylistReps, function (left, right) {
|
14443 | return left.bandwidth - right.bandwidth;
|
14444 | });
|
14445 |
|
14446 |
|
14447 | sortedPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
14448 | return !Playlist.isIncompatible(rep.playlist);
|
14449 | });
|
14450 |
|
14451 |
|
14452 | var enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
14453 | return Playlist.isEnabled(rep.playlist);
|
14454 | });
|
14455 |
|
14456 | if (!enabledPlaylistReps.length) {
|
14457 |
|
14458 |
|
14459 |
|
14460 | enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
14461 | return !Playlist.isDisabled(rep.playlist);
|
14462 | });
|
14463 | }
|
14464 |
|
14465 |
|
14466 |
|
14467 | var bandwidthPlaylistReps = enabledPlaylistReps.filter(function (rep) {
|
14468 | return rep.bandwidth * Config.BANDWIDTH_VARIANCE < playerBandwidth;
|
14469 | });
|
14470 | var highestRemainingBandwidthRep = bandwidthPlaylistReps[bandwidthPlaylistReps.length - 1];
|
14471 |
|
14472 |
|
14473 | var bandwidthBestRep = bandwidthPlaylistReps.filter(function (rep) {
|
14474 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
14475 | })[0];
|
14476 |
|
14477 | if (limitRenditionByPlayerDimensions === false) {
|
14478 | var _chosenRep = bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
14479 |
|
14480 | if (_chosenRep && _chosenRep.playlist) {
|
14481 | var type = 'sortedPlaylistReps';
|
14482 |
|
14483 | if (bandwidthBestRep) {
|
14484 | type = 'bandwidthBestRep';
|
14485 | }
|
14486 |
|
14487 | if (enabledPlaylistReps[0]) {
|
14488 | type = 'enabledPlaylistReps';
|
14489 | }
|
14490 |
|
14491 | logFn("choosing " + representationToString(_chosenRep) + " using " + type + " with options", options);
|
14492 | return _chosenRep.playlist;
|
14493 | }
|
14494 |
|
14495 | logFn('could not choose a playlist with options', options);
|
14496 | return null;
|
14497 | }
|
14498 |
|
14499 |
|
14500 | var haveResolution = bandwidthPlaylistReps.filter(function (rep) {
|
14501 | return rep.width && rep.height;
|
14502 | });
|
14503 |
|
14504 | stableSort(haveResolution, function (left, right) {
|
14505 | return left.width - right.width;
|
14506 | });
|
14507 |
|
14508 | var resolutionBestRepList = haveResolution.filter(function (rep) {
|
14509 | return rep.width === playerWidth && rep.height === playerHeight;
|
14510 | });
|
14511 | highestRemainingBandwidthRep = resolutionBestRepList[resolutionBestRepList.length - 1];
|
14512 |
|
14513 | var resolutionBestRep = resolutionBestRepList.filter(function (rep) {
|
14514 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
14515 | })[0];
|
14516 | var resolutionPlusOneList;
|
14517 | var resolutionPlusOneSmallest;
|
14518 | var resolutionPlusOneRep;
|
14519 |
|
14520 |
|
14521 | if (!resolutionBestRep) {
|
14522 | resolutionPlusOneList = haveResolution.filter(function (rep) {
|
14523 | return rep.width > playerWidth || rep.height > playerHeight;
|
14524 | });
|
14525 |
|
14526 | resolutionPlusOneSmallest = resolutionPlusOneList.filter(function (rep) {
|
14527 | return rep.width === resolutionPlusOneList[0].width && rep.height === resolutionPlusOneList[0].height;
|
14528 | });
|
14529 |
|
14530 |
|
14531 | highestRemainingBandwidthRep = resolutionPlusOneSmallest[resolutionPlusOneSmallest.length - 1];
|
14532 | resolutionPlusOneRep = resolutionPlusOneSmallest.filter(function (rep) {
|
14533 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
14534 | })[0];
|
14535 | }
|
14536 |
|
14537 | var leastPixelDiffRep;
|
14538 |
|
14539 |
|
14540 |
|
14541 | if (masterPlaylistController.experimentalLeastPixelDiffSelector) {
|
14542 |
|
14543 | var leastPixelDiffList = haveResolution.map(function (rep) {
|
14544 | rep.pixelDiff = Math.abs(rep.width - playerWidth) + Math.abs(rep.height - playerHeight);
|
14545 | return rep;
|
14546 | });
|
14547 |
|
14548 | stableSort(leastPixelDiffList, function (left, right) {
|
14549 |
|
14550 | if (left.pixelDiff === right.pixelDiff) {
|
14551 | return right.bandwidth - left.bandwidth;
|
14552 | }
|
14553 |
|
14554 | return left.pixelDiff - right.pixelDiff;
|
14555 | });
|
14556 | leastPixelDiffRep = leastPixelDiffList[0];
|
14557 | }
|
14558 |
|
14559 |
|
14560 | var chosenRep = leastPixelDiffRep || resolutionPlusOneRep || resolutionBestRep || bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
14561 |
|
14562 | if (chosenRep && chosenRep.playlist) {
|
14563 | var _type = 'sortedPlaylistReps';
|
14564 |
|
14565 | if (leastPixelDiffRep) {
|
14566 | _type = 'leastPixelDiffRep';
|
14567 | } else if (resolutionPlusOneRep) {
|
14568 | _type = 'resolutionPlusOneRep';
|
14569 | } else if (resolutionBestRep) {
|
14570 | _type = 'resolutionBestRep';
|
14571 | } else if (bandwidthBestRep) {
|
14572 | _type = 'bandwidthBestRep';
|
14573 | } else if (enabledPlaylistReps[0]) {
|
14574 | _type = 'enabledPlaylistReps';
|
14575 | }
|
14576 |
|
14577 | logFn("choosing " + representationToString(chosenRep) + " using " + _type + " with options", options);
|
14578 | return chosenRep.playlist;
|
14579 | }
|
14580 |
|
14581 | logFn('could not choose a playlist with options', options);
|
14582 | return null;
|
14583 | };
|
14584 |
|
14585 |
|
14586 |
|
14587 |
|
14588 |
|
14589 |
|
14590 |
|
14591 |
|
14592 |
|
14593 |
|
14594 |
|
14595 |
|
14596 | var lastBandwidthSelector = function lastBandwidthSelector() {
|
14597 | var pixelRatio = this.useDevicePixelRatio ? window__default["default"].devicePixelRatio || 1 : 1;
|
14598 | 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_);
|
14599 | };
|
14600 |
|
14601 |
|
14602 |
|
14603 |
|
14604 |
|
14605 |
|
14606 |
|
14607 |
|
14608 |
|
14609 |
|
14610 |
|
14611 |
|
14612 |
|
14613 |
|
14614 |
|
14615 | var movingAverageBandwidthSelector = function movingAverageBandwidthSelector(decay) {
|
14616 | var average = -1;
|
14617 | var lastSystemBandwidth = -1;
|
14618 |
|
14619 | if (decay < 0 || decay > 1) {
|
14620 | throw new Error('Moving average bandwidth decay must be between 0 and 1.');
|
14621 | }
|
14622 |
|
14623 | return function () {
|
14624 | var pixelRatio = this.useDevicePixelRatio ? window__default["default"].devicePixelRatio || 1 : 1;
|
14625 |
|
14626 | if (average < 0) {
|
14627 | average = this.systemBandwidth;
|
14628 | lastSystemBandwidth = this.systemBandwidth;
|
14629 | }
|
14630 |
|
14631 |
|
14632 |
|
14633 |
|
14634 |
|
14635 |
|
14636 | if (this.systemBandwidth > 0 && this.systemBandwidth !== lastSystemBandwidth) {
|
14637 | average = decay * this.systemBandwidth + (1 - decay) * average;
|
14638 | lastSystemBandwidth = this.systemBandwidth;
|
14639 | }
|
14640 |
|
14641 | 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_);
|
14642 | };
|
14643 | };
|
14644 |
|
14645 |
|
14646 |
|
14647 |
|
14648 |
|
14649 |
|
14650 |
|
14651 |
|
14652 |
|
14653 |
|
14654 |
|
14655 |
|
14656 |
|
14657 |
|
14658 |
|
14659 |
|
14660 |
|
14661 |
|
14662 |
|
14663 |
|
14664 |
|
14665 |
|
14666 |
|
14667 |
|
14668 |
|
14669 |
|
14670 |
|
14671 |
|
14672 |
|
14673 | var minRebufferMaxBandwidthSelector = function minRebufferMaxBandwidthSelector(settings) {
|
14674 | var master = settings.master,
|
14675 | currentTime = settings.currentTime,
|
14676 | bandwidth = settings.bandwidth,
|
14677 | duration = settings.duration,
|
14678 | segmentDuration = settings.segmentDuration,
|
14679 | timeUntilRebuffer = settings.timeUntilRebuffer,
|
14680 | currentTimeline = settings.currentTimeline,
|
14681 | syncController = settings.syncController;
|
14682 |
|
14683 |
|
14684 | var compatiblePlaylists = master.playlists.filter(function (playlist) {
|
14685 | return !Playlist.isIncompatible(playlist);
|
14686 | });
|
14687 |
|
14688 |
|
14689 | var enabledPlaylists = compatiblePlaylists.filter(Playlist.isEnabled);
|
14690 |
|
14691 | if (!enabledPlaylists.length) {
|
14692 |
|
14693 |
|
14694 |
|
14695 | enabledPlaylists = compatiblePlaylists.filter(function (playlist) {
|
14696 | return !Playlist.isDisabled(playlist);
|
14697 | });
|
14698 | }
|
14699 |
|
14700 | var bandwidthPlaylists = enabledPlaylists.filter(Playlist.hasAttribute.bind(null, 'BANDWIDTH'));
|
14701 | var rebufferingEstimates = bandwidthPlaylists.map(function (playlist) {
|
14702 | var syncPoint = syncController.getSyncPoint(playlist, duration, currentTimeline, currentTime);
|
14703 |
|
14704 |
|
14705 | var numRequests = syncPoint ? 1 : 2;
|
14706 | var requestTimeEstimate = Playlist.estimateSegmentRequestTime(segmentDuration, bandwidth, playlist);
|
14707 | var rebufferingImpact = requestTimeEstimate * numRequests - timeUntilRebuffer;
|
14708 | return {
|
14709 | playlist: playlist,
|
14710 | rebufferingImpact: rebufferingImpact
|
14711 | };
|
14712 | });
|
14713 | var noRebufferingPlaylists = rebufferingEstimates.filter(function (estimate) {
|
14714 | return estimate.rebufferingImpact <= 0;
|
14715 | });
|
14716 |
|
14717 | stableSort(noRebufferingPlaylists, function (a, b) {
|
14718 | return comparePlaylistBandwidth(b.playlist, a.playlist);
|
14719 | });
|
14720 |
|
14721 | if (noRebufferingPlaylists.length) {
|
14722 | return noRebufferingPlaylists[0];
|
14723 | }
|
14724 |
|
14725 | stableSort(rebufferingEstimates, function (a, b) {
|
14726 | return a.rebufferingImpact - b.rebufferingImpact;
|
14727 | });
|
14728 | return rebufferingEstimates[0] || null;
|
14729 | };
|
14730 |
|
14731 |
|
14732 |
|
14733 |
|
14734 |
|
14735 |
|
14736 |
|
14737 |
|
14738 |
|
14739 |
|
14740 |
|
14741 |
|
14742 | var lowestBitrateCompatibleVariantSelector = function lowestBitrateCompatibleVariantSelector() {
|
14743 | var _this = this;
|
14744 |
|
14745 |
|
14746 |
|
14747 | var playlists = this.playlists.master.playlists.filter(Playlist.isEnabled);
|
14748 |
|
14749 | stableSort(playlists, function (a, b) {
|
14750 | return comparePlaylistBandwidth(a, b);
|
14751 | });
|
14752 |
|
14753 |
|
14754 |
|
14755 |
|
14756 |
|
14757 | var playlistsWithVideo = playlists.filter(function (playlist) {
|
14758 | return !!codecsForPlaylist(_this.playlists.master, playlist).video;
|
14759 | });
|
14760 | return playlistsWithVideo[0] || null;
|
14761 | };
|
14762 |
|
14763 |
|
14764 |
|
14765 |
|
14766 |
|
14767 |
|
14768 |
|
14769 |
|
14770 | var concatSegments = function concatSegments(segmentObj) {
|
14771 | var offset = 0;
|
14772 | var tempBuffer;
|
14773 |
|
14774 | if (segmentObj.bytes) {
|
14775 | tempBuffer = new Uint8Array(segmentObj.bytes);
|
14776 |
|
14777 | segmentObj.segments.forEach(function (segment) {
|
14778 | tempBuffer.set(segment, offset);
|
14779 | offset += segment.byteLength;
|
14780 | });
|
14781 | }
|
14782 |
|
14783 | return tempBuffer;
|
14784 | };
|
14785 |
|
14786 |
|
14787 |
|
14788 |
|
14789 |
|
14790 |
|
14791 |
|
14792 |
|
14793 |
|
14794 |
|
14795 |
|
14796 |
|
14797 |
|
14798 | var createCaptionsTrackIfNotExists = function createCaptionsTrackIfNotExists(inbandTextTracks, tech, captionStream) {
|
14799 | if (!inbandTextTracks[captionStream]) {
|
14800 | tech.trigger({
|
14801 | type: 'usage',
|
14802 | name: 'vhs-608'
|
14803 | });
|
14804 | tech.trigger({
|
14805 | type: 'usage',
|
14806 | name: 'hls-608'
|
14807 | });
|
14808 | var instreamId = captionStream;
|
14809 |
|
14810 | if (/^cc708_/.test(captionStream)) {
|
14811 | instreamId = 'SERVICE' + captionStream.split('_')[1];
|
14812 | }
|
14813 |
|
14814 | var track = tech.textTracks().getTrackById(instreamId);
|
14815 |
|
14816 | if (track) {
|
14817 |
|
14818 |
|
14819 |
|
14820 | inbandTextTracks[captionStream] = track;
|
14821 | } else {
|
14822 |
|
14823 |
|
14824 | var captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
|
14825 | var label = captionStream;
|
14826 | var language = captionStream;
|
14827 | var def = false;
|
14828 | var captionService = captionServices[instreamId];
|
14829 |
|
14830 | if (captionService) {
|
14831 | label = captionService.label;
|
14832 | language = captionService.language;
|
14833 | def = captionService.default;
|
14834 | }
|
14835 |
|
14836 |
|
14837 |
|
14838 | inbandTextTracks[captionStream] = tech.addRemoteTextTrack({
|
14839 | kind: 'captions',
|
14840 | id: instreamId,
|
14841 |
|
14842 | default: def,
|
14843 | label: label,
|
14844 | language: language
|
14845 | }, false).track;
|
14846 | }
|
14847 | }
|
14848 | };
|
14849 |
|
14850 |
|
14851 |
|
14852 |
|
14853 |
|
14854 |
|
14855 |
|
14856 |
|
14857 |
|
14858 |
|
14859 | var addCaptionData = function addCaptionData(_ref) {
|
14860 | var inbandTextTracks = _ref.inbandTextTracks,
|
14861 | captionArray = _ref.captionArray,
|
14862 | timestampOffset = _ref.timestampOffset;
|
14863 |
|
14864 | if (!captionArray) {
|
14865 | return;
|
14866 | }
|
14867 |
|
14868 | var Cue = window__default["default"].WebKitDataCue || window__default["default"].VTTCue;
|
14869 | captionArray.forEach(function (caption) {
|
14870 | var track = caption.stream;
|
14871 | inbandTextTracks[track].addCue(new Cue(caption.startTime + timestampOffset, caption.endTime + timestampOffset, caption.text));
|
14872 | });
|
14873 | };
|
14874 |
|
14875 |
|
14876 |
|
14877 |
|
14878 |
|
14879 |
|
14880 |
|
14881 |
|
14882 |
|
14883 | var deprecateOldCue = function deprecateOldCue(cue) {
|
14884 | Object.defineProperties(cue.frame, {
|
14885 | id: {
|
14886 | get: function get() {
|
14887 | videojs__default["default"].log.warn('cue.frame.id is deprecated. Use cue.value.key instead.');
|
14888 | return cue.value.key;
|
14889 | }
|
14890 | },
|
14891 | value: {
|
14892 | get: function get() {
|
14893 | videojs__default["default"].log.warn('cue.frame.value is deprecated. Use cue.value.data instead.');
|
14894 | return cue.value.data;
|
14895 | }
|
14896 | },
|
14897 | privateData: {
|
14898 | get: function get() {
|
14899 | videojs__default["default"].log.warn('cue.frame.privateData is deprecated. Use cue.value.data instead.');
|
14900 | return cue.value.data;
|
14901 | }
|
14902 | }
|
14903 | });
|
14904 | };
|
14905 |
|
14906 |
|
14907 |
|
14908 |
|
14909 |
|
14910 |
|
14911 |
|
14912 |
|
14913 |
|
14914 |
|
14915 |
|
14916 |
|
14917 | var addMetadata = function addMetadata(_ref2) {
|
14918 | var inbandTextTracks = _ref2.inbandTextTracks,
|
14919 | metadataArray = _ref2.metadataArray,
|
14920 | timestampOffset = _ref2.timestampOffset,
|
14921 | videoDuration = _ref2.videoDuration;
|
14922 |
|
14923 | if (!metadataArray) {
|
14924 | return;
|
14925 | }
|
14926 |
|
14927 | var Cue = window__default["default"].WebKitDataCue || window__default["default"].VTTCue;
|
14928 | var metadataTrack = inbandTextTracks.metadataTrack_;
|
14929 |
|
14930 | if (!metadataTrack) {
|
14931 | return;
|
14932 | }
|
14933 |
|
14934 | metadataArray.forEach(function (metadata) {
|
14935 | var time = metadata.cueTime + timestampOffset;
|
14936 |
|
14937 |
|
14938 |
|
14939 |
|
14940 | if (typeof time !== 'number' || window__default["default"].isNaN(time) || time < 0 || !(time < Infinity)) {
|
14941 | return;
|
14942 | }
|
14943 |
|
14944 | metadata.frames.forEach(function (frame) {
|
14945 | var cue = new Cue(time, time, frame.value || frame.url || frame.data || '');
|
14946 | cue.frame = frame;
|
14947 | cue.value = frame;
|
14948 | deprecateOldCue(cue);
|
14949 | metadataTrack.addCue(cue);
|
14950 | });
|
14951 | });
|
14952 |
|
14953 | if (!metadataTrack.cues || !metadataTrack.cues.length) {
|
14954 | return;
|
14955 | }
|
14956 |
|
14957 |
|
14958 |
|
14959 |
|
14960 | var cues = metadataTrack.cues;
|
14961 | var cuesArray = [];
|
14962 |
|
14963 |
|
14964 | for (var i = 0; i < cues.length; i++) {
|
14965 | if (cues[i]) {
|
14966 | cuesArray.push(cues[i]);
|
14967 | }
|
14968 | }
|
14969 |
|
14970 |
|
14971 | var cuesGroupedByStartTime = cuesArray.reduce(function (obj, cue) {
|
14972 | var timeSlot = obj[cue.startTime] || [];
|
14973 | timeSlot.push(cue);
|
14974 | obj[cue.startTime] = timeSlot;
|
14975 | return obj;
|
14976 | }, {});
|
14977 |
|
14978 | var sortedStartTimes = Object.keys(cuesGroupedByStartTime).sort(function (a, b) {
|
14979 | return Number(a) - Number(b);
|
14980 | });
|
14981 |
|
14982 | sortedStartTimes.forEach(function (startTime, idx) {
|
14983 | var cueGroup = cuesGroupedByStartTime[startTime];
|
14984 | var nextTime = Number(sortedStartTimes[idx + 1]) || videoDuration;
|
14985 |
|
14986 | cueGroup.forEach(function (cue) {
|
14987 | cue.endTime = nextTime;
|
14988 | });
|
14989 | });
|
14990 | };
|
14991 |
|
14992 |
|
14993 |
|
14994 |
|
14995 |
|
14996 |
|
14997 |
|
14998 |
|
14999 |
|
15000 | var createMetadataTrackIfNotExists = function createMetadataTrackIfNotExists(inbandTextTracks, dispatchType, tech) {
|
15001 | if (inbandTextTracks.metadataTrack_) {
|
15002 | return;
|
15003 | }
|
15004 |
|
15005 | inbandTextTracks.metadataTrack_ = tech.addRemoteTextTrack({
|
15006 | kind: 'metadata',
|
15007 | label: 'Timed Metadata'
|
15008 | }, false).track;
|
15009 | inbandTextTracks.metadataTrack_.inBandMetadataTrackDispatchType = dispatchType;
|
15010 | };
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 | var removeCuesFromTrack = function removeCuesFromTrack(start, end, track) {
|
15021 | var i;
|
15022 | var cue;
|
15023 |
|
15024 | if (!track) {
|
15025 | return;
|
15026 | }
|
15027 |
|
15028 | if (!track.cues) {
|
15029 | return;
|
15030 | }
|
15031 |
|
15032 | i = track.cues.length;
|
15033 |
|
15034 | while (i--) {
|
15035 | cue = track.cues[i];
|
15036 |
|
15037 | if (cue.startTime >= start && cue.endTime <= end) {
|
15038 | track.removeCue(cue);
|
15039 | }
|
15040 | }
|
15041 | };
|
15042 |
|
15043 |
|
15044 |
|
15045 |
|
15046 |
|
15047 |
|
15048 |
|
15049 |
|
15050 | var removeDuplicateCuesFromTrack = function removeDuplicateCuesFromTrack(track) {
|
15051 | var cues = track.cues;
|
15052 |
|
15053 | if (!cues) {
|
15054 | return;
|
15055 | }
|
15056 |
|
15057 | for (var i = 0; i < cues.length; i++) {
|
15058 | var duplicates = [];
|
15059 | var occurrences = 0;
|
15060 |
|
15061 | for (var j = 0; j < cues.length; j++) {
|
15062 | if (cues[i].startTime === cues[j].startTime && cues[i].endTime === cues[j].endTime && cues[i].text === cues[j].text) {
|
15063 | occurrences++;
|
15064 |
|
15065 | if (occurrences > 1) {
|
15066 | duplicates.push(cues[j]);
|
15067 | }
|
15068 | }
|
15069 | }
|
15070 |
|
15071 | if (duplicates.length) {
|
15072 | duplicates.forEach(function (dupe) {
|
15073 | return track.removeCue(dupe);
|
15074 | });
|
15075 | }
|
15076 | }
|
15077 | };
|
15078 |
|
15079 |
|
15080 |
|
15081 |
|
15082 |
|
15083 |
|
15084 |
|
15085 |
|
15086 |
|
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 |
|
15092 |
|
15093 | var gopsSafeToAlignWith = function gopsSafeToAlignWith(buffer, currentTime, mapping) {
|
15094 | if (typeof currentTime === 'undefined' || currentTime === null || !buffer.length) {
|
15095 | return [];
|
15096 | }
|
15097 |
|
15098 |
|
15099 | var currentTimePts = Math.ceil((currentTime - mapping + 3) * clock.ONE_SECOND_IN_TS);
|
15100 | var i;
|
15101 |
|
15102 | for (i = 0; i < buffer.length; i++) {
|
15103 | if (buffer[i].pts > currentTimePts) {
|
15104 | break;
|
15105 | }
|
15106 | }
|
15107 |
|
15108 | return buffer.slice(i);
|
15109 | };
|
15110 |
|
15111 |
|
15112 |
|
15113 |
|
15114 |
|
15115 |
|
15116 |
|
15117 |
|
15118 |
|
15119 |
|
15120 |
|
15121 |
|
15122 |
|
15123 |
|
15124 |
|
15125 | var updateGopBuffer = function updateGopBuffer(buffer, gops, replace) {
|
15126 | if (!gops.length) {
|
15127 | return buffer;
|
15128 | }
|
15129 |
|
15130 | if (replace) {
|
15131 |
|
15132 |
|
15133 |
|
15134 |
|
15135 | return gops.slice();
|
15136 | }
|
15137 |
|
15138 | var start = gops[0].pts;
|
15139 | var i = 0;
|
15140 |
|
15141 | for (i; i < buffer.length; i++) {
|
15142 | if (buffer[i].pts >= start) {
|
15143 | break;
|
15144 | }
|
15145 | }
|
15146 |
|
15147 | return buffer.slice(0, i).concat(gops);
|
15148 | };
|
15149 |
|
15150 |
|
15151 |
|
15152 |
|
15153 |
|
15154 |
|
15155 |
|
15156 |
|
15157 |
|
15158 |
|
15159 |
|
15160 |
|
15161 |
|
15162 | var removeGopBuffer = function removeGopBuffer(buffer, start, end, mapping) {
|
15163 | var startPts = Math.ceil((start - mapping) * clock.ONE_SECOND_IN_TS);
|
15164 | var endPts = Math.ceil((end - mapping) * clock.ONE_SECOND_IN_TS);
|
15165 | var updatedBuffer = buffer.slice();
|
15166 | var i = buffer.length;
|
15167 |
|
15168 | while (i--) {
|
15169 | if (buffer[i].pts <= endPts) {
|
15170 | break;
|
15171 | }
|
15172 | }
|
15173 |
|
15174 | if (i === -1) {
|
15175 |
|
15176 | return updatedBuffer;
|
15177 | }
|
15178 |
|
15179 | var j = i + 1;
|
15180 |
|
15181 | while (j--) {
|
15182 | if (buffer[j].pts <= startPts) {
|
15183 | break;
|
15184 | }
|
15185 | }
|
15186 |
|
15187 |
|
15188 | j = Math.max(j, 0);
|
15189 | updatedBuffer.splice(j, i - j + 1);
|
15190 | return updatedBuffer;
|
15191 | };
|
15192 |
|
15193 | var shallowEqual = function shallowEqual(a, b) {
|
15194 |
|
15195 |
|
15196 |
|
15197 | if (!a && !b || !a && b || a && !b) {
|
15198 | return false;
|
15199 | }
|
15200 |
|
15201 |
|
15202 | if (a === b) {
|
15203 | return true;
|
15204 | }
|
15205 |
|
15206 |
|
15207 |
|
15208 | var akeys = Object.keys(a).sort();
|
15209 | var bkeys = Object.keys(b).sort();
|
15210 |
|
15211 | if (akeys.length !== bkeys.length) {
|
15212 | return false;
|
15213 | }
|
15214 |
|
15215 | for (var i = 0; i < akeys.length; i++) {
|
15216 | var key = akeys[i];
|
15217 |
|
15218 | if (key !== bkeys[i]) {
|
15219 | return false;
|
15220 | }
|
15221 |
|
15222 |
|
15223 | if (a[key] !== b[key]) {
|
15224 | return false;
|
15225 | }
|
15226 | }
|
15227 |
|
15228 | return true;
|
15229 | };
|
15230 |
|
15231 |
|
15232 | var QUOTA_EXCEEDED_ERR = 22;
|
15233 |
|
15234 |
|
15235 |
|
15236 |
|
15237 |
|
15238 |
|
15239 |
|
15240 |
|
15241 |
|
15242 |
|
15243 |
|
15244 | var getSyncSegmentCandidate = function getSyncSegmentCandidate(currentTimeline, segments, targetTime) {
|
15245 | segments = segments || [];
|
15246 | var timelineSegments = [];
|
15247 | var time = 0;
|
15248 |
|
15249 | for (var i = 0; i < segments.length; i++) {
|
15250 | var segment = segments[i];
|
15251 |
|
15252 | if (currentTimeline === segment.timeline) {
|
15253 | timelineSegments.push(i);
|
15254 | time += segment.duration;
|
15255 |
|
15256 | if (time > targetTime) {
|
15257 | return i;
|
15258 | }
|
15259 | }
|
15260 | }
|
15261 |
|
15262 | if (timelineSegments.length === 0) {
|
15263 | return 0;
|
15264 | }
|
15265 |
|
15266 |
|
15267 | return timelineSegments[timelineSegments.length - 1];
|
15268 | };
|
15269 |
|
15270 |
|
15271 |
|
15272 |
|
15273 | var MIN_BACK_BUFFER = 1;
|
15274 |
|
15275 | var CHECK_BUFFER_DELAY = 500;
|
15276 |
|
15277 | var finite = function finite(num) {
|
15278 | return typeof num === 'number' && isFinite(num);
|
15279 | };
|
15280 |
|
15281 |
|
15282 |
|
15283 |
|
15284 | var MIN_SEGMENT_DURATION_TO_SAVE_STATS = 1 / 60;
|
15285 | var illegalMediaSwitch = function illegalMediaSwitch(loaderType, startingMedia, trackInfo) {
|
15286 |
|
15287 |
|
15288 | if (loaderType !== 'main' || !startingMedia || !trackInfo) {
|
15289 | return null;
|
15290 | }
|
15291 |
|
15292 | if (!trackInfo.hasAudio && !trackInfo.hasVideo) {
|
15293 | return 'Neither audio nor video found in segment.';
|
15294 | }
|
15295 |
|
15296 | if (startingMedia.hasVideo && !trackInfo.hasVideo) {
|
15297 | 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.';
|
15298 | }
|
15299 |
|
15300 | if (!startingMedia.hasVideo && trackInfo.hasVideo) {
|
15301 | 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.';
|
15302 | }
|
15303 |
|
15304 | return null;
|
15305 | };
|
15306 |
|
15307 |
|
15308 |
|
15309 |
|
15310 |
|
15311 |
|
15312 |
|
15313 |
|
15314 |
|
15315 |
|
15316 |
|
15317 |
|
15318 |
|
15319 |
|
15320 | var safeBackBufferTrimTime = function safeBackBufferTrimTime(seekable, currentTime, targetDuration) {
|
15321 |
|
15322 |
|
15323 |
|
15324 |
|
15325 |
|
15326 | var trimTime = currentTime - Config.BACK_BUFFER_LENGTH;
|
15327 |
|
15328 | if (seekable.length) {
|
15329 |
|
15330 |
|
15331 | trimTime = Math.max(trimTime, seekable.start(0));
|
15332 | }
|
15333 |
|
15334 |
|
15335 |
|
15336 | var maxTrimTime = currentTime - targetDuration;
|
15337 | return Math.min(maxTrimTime, trimTime);
|
15338 | };
|
15339 |
|
15340 | var segmentInfoString = function segmentInfoString(segmentInfo) {
|
15341 | var startOfSegment = segmentInfo.startOfSegment,
|
15342 | duration = segmentInfo.duration,
|
15343 | segment = segmentInfo.segment,
|
15344 | part = segmentInfo.part,
|
15345 | _segmentInfo$playlist = segmentInfo.playlist,
|
15346 | seq = _segmentInfo$playlist.mediaSequence,
|
15347 | id = _segmentInfo$playlist.id,
|
15348 | _segmentInfo$playlist2 = _segmentInfo$playlist.segments,
|
15349 | segments = _segmentInfo$playlist2 === void 0 ? [] : _segmentInfo$playlist2,
|
15350 | index = segmentInfo.mediaIndex,
|
15351 | partIndex = segmentInfo.partIndex,
|
15352 | timeline = segmentInfo.timeline;
|
15353 | var segmentLen = segments.length - 1;
|
15354 | var selection = 'mediaIndex/partIndex increment';
|
15355 |
|
15356 | if (segmentInfo.getMediaInfoForTime) {
|
15357 | selection = "getMediaInfoForTime (" + segmentInfo.getMediaInfoForTime + ")";
|
15358 | } else if (segmentInfo.isSyncRequest) {
|
15359 | selection = 'getSyncSegmentCandidate (isSyncRequest)';
|
15360 | }
|
15361 |
|
15362 | var hasPartIndex = typeof partIndex === 'number';
|
15363 | var name = segmentInfo.segment.uri ? 'segment' : 'pre-segment';
|
15364 | var zeroBasedPartCount = hasPartIndex ? getKnownPartCount({
|
15365 | preloadSegment: segment
|
15366 | }) - 1 : 0;
|
15367 | 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 + "]");
|
15368 | };
|
15369 |
|
15370 | var timingInfoPropertyForMedia = function timingInfoPropertyForMedia(mediaType) {
|
15371 | return mediaType + "TimingInfo";
|
15372 | };
|
15373 |
|
15374 |
|
15375 |
|
15376 |
|
15377 |
|
15378 |
|
15379 |
|
15380 |
|
15381 |
|
15382 |
|
15383 |
|
15384 |
|
15385 |
|
15386 |
|
15387 |
|
15388 |
|
15389 |
|
15390 |
|
15391 |
|
15392 |
|
15393 |
|
15394 | var timestampOffsetForSegment = function timestampOffsetForSegment(_ref) {
|
15395 | var segmentTimeline = _ref.segmentTimeline,
|
15396 | currentTimeline = _ref.currentTimeline,
|
15397 | startOfSegment = _ref.startOfSegment,
|
15398 | buffered = _ref.buffered,
|
15399 | overrideCheck = _ref.overrideCheck;
|
15400 |
|
15401 |
|
15402 |
|
15403 |
|
15404 |
|
15405 |
|
15406 |
|
15407 | if (!overrideCheck && segmentTimeline === currentTimeline) {
|
15408 | return null;
|
15409 | }
|
15410 |
|
15411 |
|
15412 |
|
15413 |
|
15414 |
|
15415 |
|
15416 |
|
15417 |
|
15418 |
|
15419 |
|
15420 |
|
15421 |
|
15422 |
|
15423 |
|
15424 |
|
15425 |
|
15426 |
|
15427 |
|
15428 |
|
15429 |
|
15430 |
|
15431 |
|
15432 |
|
15433 |
|
15434 |
|
15435 | if (segmentTimeline < currentTimeline) {
|
15436 | return startOfSegment;
|
15437 | }
|
15438 |
|
15439 |
|
15440 |
|
15441 |
|
15442 |
|
15443 |
|
15444 | return buffered.length ? buffered.end(buffered.length - 1) : startOfSegment;
|
15445 | };
|
15446 |
|
15447 |
|
15448 |
|
15449 |
|
15450 |
|
15451 |
|
15452 |
|
15453 |
|
15454 |
|
15455 |
|
15456 |
|
15457 |
|
15458 |
|
15459 |
|
15460 |
|
15461 |
|
15462 |
|
15463 |
|
15464 |
|
15465 |
|
15466 |
|
15467 |
|
15468 |
|
15469 |
|
15470 |
|
15471 |
|
15472 |
|
15473 |
|
15474 |
|
15475 |
|
15476 |
|
15477 |
|
15478 |
|
15479 |
|
15480 |
|
15481 |
|
15482 |
|
15483 |
|
15484 |
|
15485 |
|
15486 |
|
15487 |
|
15488 |
|
15489 |
|
15490 |
|
15491 |
|
15492 |
|
15493 |
|
15494 |
|
15495 |
|
15496 |
|
15497 |
|
15498 |
|
15499 |
|
15500 |
|
15501 |
|
15502 |
|
15503 |
|
15504 |
|
15505 |
|
15506 |
|
15507 |
|
15508 |
|
15509 |
|
15510 |
|
15511 |
|
15512 |
|
15513 |
|
15514 |
|
15515 |
|
15516 |
|
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 | var shouldWaitForTimelineChange = function shouldWaitForTimelineChange(_ref2) {
|
15543 | var timelineChangeController = _ref2.timelineChangeController,
|
15544 | currentTimeline = _ref2.currentTimeline,
|
15545 | segmentTimeline = _ref2.segmentTimeline,
|
15546 | loaderType = _ref2.loaderType,
|
15547 | audioDisabled = _ref2.audioDisabled;
|
15548 |
|
15549 | if (currentTimeline === segmentTimeline) {
|
15550 | return false;
|
15551 | }
|
15552 |
|
15553 | if (loaderType === 'audio') {
|
15554 | var lastMainTimelineChange = timelineChangeController.lastTimelineChange({
|
15555 | type: 'main'
|
15556 | });
|
15557 |
|
15558 |
|
15559 |
|
15560 |
|
15561 | return !lastMainTimelineChange || lastMainTimelineChange.to !== segmentTimeline;
|
15562 | }
|
15563 |
|
15564 |
|
15565 |
|
15566 |
|
15567 |
|
15568 | if (loaderType === 'main' && audioDisabled) {
|
15569 | var pendingAudioTimelineChange = timelineChangeController.pendingTimelineChange({
|
15570 | type: 'audio'
|
15571 | });
|
15572 |
|
15573 |
|
15574 |
|
15575 |
|
15576 |
|
15577 |
|
15578 |
|
15579 |
|
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 |
|
15585 |
|
15586 |
|
15587 |
|
15588 |
|
15589 |
|
15590 | if (pendingAudioTimelineChange && pendingAudioTimelineChange.to === segmentTimeline) {
|
15591 | return false;
|
15592 | }
|
15593 |
|
15594 | return true;
|
15595 | }
|
15596 |
|
15597 | return false;
|
15598 | };
|
15599 | var mediaDuration = function mediaDuration(audioTimingInfo, videoTimingInfo) {
|
15600 | var audioDuration = audioTimingInfo && typeof audioTimingInfo.start === 'number' && typeof audioTimingInfo.end === 'number' ? audioTimingInfo.end - audioTimingInfo.start : 0;
|
15601 | var videoDuration = videoTimingInfo && typeof videoTimingInfo.start === 'number' && typeof videoTimingInfo.end === 'number' ? videoTimingInfo.end - videoTimingInfo.start : 0;
|
15602 | return Math.max(audioDuration, videoDuration);
|
15603 | };
|
15604 | var segmentTooLong = function segmentTooLong(_ref3) {
|
15605 | var segmentDuration = _ref3.segmentDuration,
|
15606 | maxDuration = _ref3.maxDuration;
|
15607 |
|
15608 |
|
15609 |
|
15610 | if (!segmentDuration) {
|
15611 | return false;
|
15612 | }
|
15613 |
|
15614 |
|
15615 |
|
15616 |
|
15617 |
|
15618 |
|
15619 |
|
15620 |
|
15621 |
|
15622 |
|
15623 |
|
15624 |
|
15625 | return Math.round(segmentDuration) > maxDuration + TIME_FUDGE_FACTOR;
|
15626 | };
|
15627 | var getTroublesomeSegmentDurationMessage = function getTroublesomeSegmentDurationMessage(segmentInfo, sourceType) {
|
15628 |
|
15629 |
|
15630 | if (sourceType !== 'hls') {
|
15631 | return null;
|
15632 | }
|
15633 |
|
15634 | var segmentDuration = mediaDuration(segmentInfo.audioTimingInfo, segmentInfo.videoTimingInfo);
|
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 | if (!segmentDuration) {
|
15640 | return null;
|
15641 | }
|
15642 |
|
15643 | var targetDuration = segmentInfo.playlist.targetDuration;
|
15644 | var isSegmentWayTooLong = segmentTooLong({
|
15645 | segmentDuration: segmentDuration,
|
15646 | maxDuration: targetDuration * 2
|
15647 | });
|
15648 | var isSegmentSlightlyTooLong = segmentTooLong({
|
15649 | segmentDuration: segmentDuration,
|
15650 | maxDuration: targetDuration
|
15651 | });
|
15652 | 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';
|
15653 |
|
15654 | if (isSegmentWayTooLong || isSegmentSlightlyTooLong) {
|
15655 | return {
|
15656 | severity: isSegmentWayTooLong ? 'warn' : 'info',
|
15657 | message: segmentTooLongMessage
|
15658 | };
|
15659 | }
|
15660 |
|
15661 | return null;
|
15662 | };
|
15663 |
|
15664 |
|
15665 |
|
15666 |
|
15667 |
|
15668 |
|
15669 |
|
15670 |
|
15671 | var SegmentLoader = function (_videojs$EventTarget) {
|
15672 | _inheritsLoose__default["default"](SegmentLoader, _videojs$EventTarget);
|
15673 |
|
15674 | function SegmentLoader(settings, options) {
|
15675 | var _this;
|
15676 |
|
15677 | _this = _videojs$EventTarget.call(this) || this;
|
15678 |
|
15679 | if (!settings) {
|
15680 | throw new TypeError('Initialization settings are required');
|
15681 | }
|
15682 |
|
15683 | if (typeof settings.currentTime !== 'function') {
|
15684 | throw new TypeError('No currentTime getter specified');
|
15685 | }
|
15686 |
|
15687 | if (!settings.mediaSource) {
|
15688 | throw new TypeError('No MediaSource specified');
|
15689 | }
|
15690 |
|
15691 |
|
15692 | _this.bandwidth = settings.bandwidth;
|
15693 | _this.throughput = {
|
15694 | rate: 0,
|
15695 | count: 0
|
15696 | };
|
15697 | _this.roundTrip = NaN;
|
15698 |
|
15699 | _this.resetStats_();
|
15700 |
|
15701 | _this.mediaIndex = null;
|
15702 | _this.partIndex = null;
|
15703 |
|
15704 | _this.hasPlayed_ = settings.hasPlayed;
|
15705 | _this.currentTime_ = settings.currentTime;
|
15706 | _this.seekable_ = settings.seekable;
|
15707 | _this.seeking_ = settings.seeking;
|
15708 | _this.duration_ = settings.duration;
|
15709 | _this.mediaSource_ = settings.mediaSource;
|
15710 | _this.vhs_ = settings.vhs;
|
15711 | _this.loaderType_ = settings.loaderType;
|
15712 | _this.currentMediaInfo_ = void 0;
|
15713 | _this.startingMediaInfo_ = void 0;
|
15714 | _this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
|
15715 | _this.goalBufferLength_ = settings.goalBufferLength;
|
15716 | _this.sourceType_ = settings.sourceType;
|
15717 | _this.sourceUpdater_ = settings.sourceUpdater;
|
15718 | _this.inbandTextTracks_ = settings.inbandTextTracks;
|
15719 | _this.state_ = 'INIT';
|
15720 | _this.timelineChangeController_ = settings.timelineChangeController;
|
15721 | _this.shouldSaveSegmentTimingInfo_ = true;
|
15722 | _this.parse708captions_ = settings.parse708captions;
|
15723 | _this.captionServices_ = settings.captionServices;
|
15724 | _this.experimentalExactManifestTimings = settings.experimentalExactManifestTimings;
|
15725 |
|
15726 | _this.checkBufferTimeout_ = null;
|
15727 | _this.error_ = void 0;
|
15728 | _this.currentTimeline_ = -1;
|
15729 | _this.pendingSegment_ = null;
|
15730 | _this.xhrOptions_ = null;
|
15731 | _this.pendingSegments_ = [];
|
15732 | _this.audioDisabled_ = false;
|
15733 | _this.isPendingTimestampOffset_ = false;
|
15734 |
|
15735 | _this.gopBuffer_ = [];
|
15736 | _this.timeMapping_ = 0;
|
15737 | _this.safeAppend_ = videojs__default["default"].browser.IE_VERSION >= 11;
|
15738 | _this.appendInitSegment_ = {
|
15739 | audio: true,
|
15740 | video: true
|
15741 | };
|
15742 | _this.playlistOfLastInitSegment_ = {
|
15743 | audio: null,
|
15744 | video: null
|
15745 | };
|
15746 | _this.callQueue_ = [];
|
15747 |
|
15748 |
|
15749 |
|
15750 |
|
15751 |
|
15752 | _this.loadQueue_ = [];
|
15753 | _this.metadataQueue_ = {
|
15754 | id3: [],
|
15755 | caption: []
|
15756 | };
|
15757 | _this.waitingOnRemove_ = false;
|
15758 | _this.quotaExceededErrorRetryTimeout_ = null;
|
15759 |
|
15760 | _this.activeInitSegmentId_ = null;
|
15761 | _this.initSegments_ = {};
|
15762 |
|
15763 | _this.cacheEncryptionKeys_ = settings.cacheEncryptionKeys;
|
15764 | _this.keyCache_ = {};
|
15765 | _this.decrypter_ = settings.decrypter;
|
15766 |
|
15767 |
|
15768 |
|
15769 | _this.syncController_ = settings.syncController;
|
15770 | _this.syncPoint_ = {
|
15771 | segmentIndex: 0,
|
15772 | time: 0
|
15773 | };
|
15774 | _this.transmuxer_ = _this.createTransmuxer_();
|
15775 |
|
15776 | _this.triggerSyncInfoUpdate_ = function () {
|
15777 | return _this.trigger('syncinfoupdate');
|
15778 | };
|
15779 |
|
15780 | _this.syncController_.on('syncinfoupdate', _this.triggerSyncInfoUpdate_);
|
15781 |
|
15782 | _this.mediaSource_.addEventListener('sourceopen', function () {
|
15783 | if (!_this.isEndOfStream_()) {
|
15784 | _this.ended_ = false;
|
15785 | }
|
15786 | });
|
15787 |
|
15788 |
|
15789 | _this.fetchAtBuffer_ = false;
|
15790 | _this.logger_ = logger("SegmentLoader[" + _this.loaderType_ + "]");
|
15791 | Object.defineProperty(_assertThisInitialized__default["default"](_this), 'state', {
|
15792 | get: function get() {
|
15793 | return this.state_;
|
15794 | },
|
15795 | set: function set(newState) {
|
15796 | if (newState !== this.state_) {
|
15797 | this.logger_(this.state_ + " -> " + newState);
|
15798 | this.state_ = newState;
|
15799 | this.trigger('statechange');
|
15800 | }
|
15801 | }
|
15802 | });
|
15803 |
|
15804 | _this.sourceUpdater_.on('ready', function () {
|
15805 | if (_this.hasEnoughInfoToAppend_()) {
|
15806 | _this.processCallQueue_();
|
15807 | }
|
15808 | });
|
15809 |
|
15810 |
|
15811 |
|
15812 |
|
15813 |
|
15814 | if (_this.loaderType_ === 'main') {
|
15815 | _this.timelineChangeController_.on('pendingtimelinechange', function () {
|
15816 | if (_this.hasEnoughInfoToAppend_()) {
|
15817 | _this.processCallQueue_();
|
15818 | }
|
15819 | });
|
15820 | }
|
15821 |
|
15822 |
|
15823 |
|
15824 |
|
15825 | if (_this.loaderType_ === 'audio') {
|
15826 | _this.timelineChangeController_.on('timelinechange', function () {
|
15827 | if (_this.hasEnoughInfoToLoad_()) {
|
15828 | _this.processLoadQueue_();
|
15829 | }
|
15830 |
|
15831 | if (_this.hasEnoughInfoToAppend_()) {
|
15832 | _this.processCallQueue_();
|
15833 | }
|
15834 | });
|
15835 | }
|
15836 |
|
15837 | return _this;
|
15838 | }
|
15839 |
|
15840 | var _proto = SegmentLoader.prototype;
|
15841 |
|
15842 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
15843 | return segmentTransmuxer.createTransmuxer({
|
15844 | remux: false,
|
15845 | alignGopsAtEnd: this.safeAppend_,
|
15846 | keepOriginalTimestamps: true,
|
15847 | parse708captions: this.parse708captions_,
|
15848 | captionServices: this.captionServices_
|
15849 | });
|
15850 | }
|
15851 | |
15852 |
|
15853 |
|
15854 |
|
15855 |
|
15856 | ;
|
15857 |
|
15858 | _proto.resetStats_ = function resetStats_() {
|
15859 | this.mediaBytesTransferred = 0;
|
15860 | this.mediaRequests = 0;
|
15861 | this.mediaRequestsAborted = 0;
|
15862 | this.mediaRequestsTimedout = 0;
|
15863 | this.mediaRequestsErrored = 0;
|
15864 | this.mediaTransferDuration = 0;
|
15865 | this.mediaSecondsLoaded = 0;
|
15866 | this.mediaAppends = 0;
|
15867 | }
|
15868 | |
15869 |
|
15870 |
|
15871 | ;
|
15872 |
|
15873 | _proto.dispose = function dispose() {
|
15874 | this.trigger('dispose');
|
15875 | this.state = 'DISPOSED';
|
15876 | this.pause();
|
15877 | this.abort_();
|
15878 |
|
15879 | if (this.transmuxer_) {
|
15880 | this.transmuxer_.terminate();
|
15881 | }
|
15882 |
|
15883 | this.resetStats_();
|
15884 |
|
15885 | if (this.checkBufferTimeout_) {
|
15886 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
15887 | }
|
15888 |
|
15889 | if (this.syncController_ && this.triggerSyncInfoUpdate_) {
|
15890 | this.syncController_.off('syncinfoupdate', this.triggerSyncInfoUpdate_);
|
15891 | }
|
15892 |
|
15893 | this.off();
|
15894 | };
|
15895 |
|
15896 | _proto.setAudio = function setAudio(enable) {
|
15897 | this.audioDisabled_ = !enable;
|
15898 |
|
15899 | if (enable) {
|
15900 | this.appendInitSegment_.audio = true;
|
15901 | } else {
|
15902 |
|
15903 | this.sourceUpdater_.removeAudio(0, this.duration_());
|
15904 | }
|
15905 | }
|
15906 | |
15907 |
|
15908 |
|
15909 |
|
15910 | ;
|
15911 |
|
15912 | _proto.abort = function abort() {
|
15913 | if (this.state !== 'WAITING') {
|
15914 | if (this.pendingSegment_) {
|
15915 | this.pendingSegment_ = null;
|
15916 | }
|
15917 |
|
15918 | return;
|
15919 | }
|
15920 |
|
15921 | this.abort_();
|
15922 |
|
15923 |
|
15924 |
|
15925 |
|
15926 | this.state = 'READY';
|
15927 |
|
15928 |
|
15929 | if (!this.paused()) {
|
15930 | this.monitorBuffer_();
|
15931 | }
|
15932 | }
|
15933 | |
15934 |
|
15935 |
|
15936 |
|
15937 |
|
15938 | ;
|
15939 |
|
15940 | _proto.abort_ = function abort_() {
|
15941 | if (this.pendingSegment_ && this.pendingSegment_.abortRequests) {
|
15942 | this.pendingSegment_.abortRequests();
|
15943 | }
|
15944 |
|
15945 |
|
15946 | this.pendingSegment_ = null;
|
15947 | this.callQueue_ = [];
|
15948 | this.loadQueue_ = [];
|
15949 | this.metadataQueue_.id3 = [];
|
15950 | this.metadataQueue_.caption = [];
|
15951 | this.timelineChangeController_.clearPendingTimelineChange(this.loaderType_);
|
15952 | this.waitingOnRemove_ = false;
|
15953 | window__default["default"].clearTimeout(this.quotaExceededErrorRetryTimeout_);
|
15954 | this.quotaExceededErrorRetryTimeout_ = null;
|
15955 | };
|
15956 |
|
15957 | _proto.checkForAbort_ = function checkForAbort_(requestId) {
|
15958 |
|
15959 |
|
15960 | if (this.state === 'APPENDING' && !this.pendingSegment_) {
|
15961 | this.state = 'READY';
|
15962 | return true;
|
15963 | }
|
15964 |
|
15965 | if (!this.pendingSegment_ || this.pendingSegment_.requestId !== requestId) {
|
15966 | return true;
|
15967 | }
|
15968 |
|
15969 | return false;
|
15970 | }
|
15971 | |
15972 |
|
15973 |
|
15974 |
|
15975 |
|
15976 |
|
15977 | ;
|
15978 |
|
15979 | _proto.error = function error(_error) {
|
15980 | if (typeof _error !== 'undefined') {
|
15981 | this.logger_('error occurred:', _error);
|
15982 | this.error_ = _error;
|
15983 | }
|
15984 |
|
15985 | this.pendingSegment_ = null;
|
15986 | return this.error_;
|
15987 | };
|
15988 |
|
15989 | _proto.endOfStream = function endOfStream() {
|
15990 | this.ended_ = true;
|
15991 |
|
15992 | if (this.transmuxer_) {
|
15993 |
|
15994 | segmentTransmuxer.reset(this.transmuxer_);
|
15995 | }
|
15996 |
|
15997 | this.gopBuffer_.length = 0;
|
15998 | this.pause();
|
15999 | this.trigger('ended');
|
16000 | }
|
16001 | |
16002 |
|
16003 |
|
16004 |
|
16005 |
|
16006 |
|
16007 | ;
|
16008 |
|
16009 | _proto.buffered_ = function buffered_() {
|
16010 | var trackInfo = this.getMediaInfo_();
|
16011 |
|
16012 | if (!this.sourceUpdater_ || !trackInfo) {
|
16013 | return videojs__default["default"].createTimeRanges();
|
16014 | }
|
16015 |
|
16016 | if (this.loaderType_ === 'main') {
|
16017 | var hasAudio = trackInfo.hasAudio,
|
16018 | hasVideo = trackInfo.hasVideo,
|
16019 | isMuxed = trackInfo.isMuxed;
|
16020 |
|
16021 | if (hasVideo && hasAudio && !this.audioDisabled_ && !isMuxed) {
|
16022 | return this.sourceUpdater_.buffered();
|
16023 | }
|
16024 |
|
16025 | if (hasVideo) {
|
16026 | return this.sourceUpdater_.videoBuffered();
|
16027 | }
|
16028 | }
|
16029 |
|
16030 |
|
16031 |
|
16032 | return this.sourceUpdater_.audioBuffered();
|
16033 | }
|
16034 | |
16035 |
|
16036 |
|
16037 |
|
16038 |
|
16039 |
|
16040 |
|
16041 |
|
16042 |
|
16043 |
|
16044 | ;
|
16045 |
|
16046 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
16047 | if (set === void 0) {
|
16048 | set = false;
|
16049 | }
|
16050 |
|
16051 | if (!map) {
|
16052 | return null;
|
16053 | }
|
16054 |
|
16055 | var id = initSegmentId(map);
|
16056 | var storedMap = this.initSegments_[id];
|
16057 |
|
16058 | if (set && !storedMap && map.bytes) {
|
16059 | this.initSegments_[id] = storedMap = {
|
16060 | resolvedUri: map.resolvedUri,
|
16061 | byterange: map.byterange,
|
16062 | bytes: map.bytes,
|
16063 | tracks: map.tracks,
|
16064 | timescales: map.timescales
|
16065 | };
|
16066 | }
|
16067 |
|
16068 | return storedMap || map;
|
16069 | }
|
16070 | |
16071 |
|
16072 |
|
16073 |
|
16074 |
|
16075 |
|
16076 |
|
16077 |
|
16078 |
|
16079 |
|
16080 | ;
|
16081 |
|
16082 | _proto.segmentKey = function segmentKey(key, set) {
|
16083 | if (set === void 0) {
|
16084 | set = false;
|
16085 | }
|
16086 |
|
16087 | if (!key) {
|
16088 | return null;
|
16089 | }
|
16090 |
|
16091 | var id = segmentKeyId(key);
|
16092 | var storedKey = this.keyCache_[id];
|
16093 |
|
16094 |
|
16095 | if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) {
|
16096 | this.keyCache_[id] = storedKey = {
|
16097 | resolvedUri: key.resolvedUri,
|
16098 | bytes: key.bytes
|
16099 | };
|
16100 | }
|
16101 |
|
16102 | var result = {
|
16103 | resolvedUri: (storedKey || key).resolvedUri
|
16104 | };
|
16105 |
|
16106 | if (storedKey) {
|
16107 | result.bytes = storedKey.bytes;
|
16108 | }
|
16109 |
|
16110 | return result;
|
16111 | }
|
16112 | |
16113 |
|
16114 |
|
16115 |
|
16116 |
|
16117 |
|
16118 | ;
|
16119 |
|
16120 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
16121 | return this.playlist_ && !this.paused();
|
16122 | }
|
16123 | |
16124 |
|
16125 |
|
16126 | ;
|
16127 |
|
16128 | _proto.load = function load() {
|
16129 |
|
16130 | this.monitorBuffer_();
|
16131 |
|
16132 |
|
16133 | if (!this.playlist_) {
|
16134 | return;
|
16135 | }
|
16136 |
|
16137 |
|
16138 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
16139 | return this.init_();
|
16140 | }
|
16141 |
|
16142 |
|
16143 |
|
16144 | if (!this.couldBeginLoading_() || this.state !== 'READY' && this.state !== 'INIT') {
|
16145 | return;
|
16146 | }
|
16147 |
|
16148 | this.state = 'READY';
|
16149 | }
|
16150 | |
16151 |
|
16152 |
|
16153 |
|
16154 |
|
16155 |
|
16156 |
|
16157 | ;
|
16158 |
|
16159 | _proto.init_ = function init_() {
|
16160 | this.state = 'READY';
|
16161 |
|
16162 |
|
16163 | this.resetEverything();
|
16164 | return this.monitorBuffer_();
|
16165 | }
|
16166 | |
16167 |
|
16168 |
|
16169 |
|
16170 |
|
16171 | ;
|
16172 |
|
16173 | _proto.playlist = function playlist(newPlaylist, options) {
|
16174 | if (options === void 0) {
|
16175 | options = {};
|
16176 | }
|
16177 |
|
16178 | if (!newPlaylist) {
|
16179 | return;
|
16180 | }
|
16181 |
|
16182 | var oldPlaylist = this.playlist_;
|
16183 | var segmentInfo = this.pendingSegment_;
|
16184 | this.playlist_ = newPlaylist;
|
16185 | this.xhrOptions_ = options;
|
16186 |
|
16187 |
|
16188 |
|
16189 |
|
16190 |
|
16191 |
|
16192 |
|
16193 | if (this.state === 'INIT') {
|
16194 | newPlaylist.syncInfo = {
|
16195 | mediaSequence: newPlaylist.mediaSequence,
|
16196 | time: 0
|
16197 | };
|
16198 |
|
16199 |
|
16200 |
|
16201 |
|
16202 |
|
16203 |
|
16204 |
|
16205 |
|
16206 | if (this.loaderType_ === 'main') {
|
16207 | this.syncController_.setDateTimeMappingForStart(newPlaylist);
|
16208 | }
|
16209 | }
|
16210 |
|
16211 | var oldId = null;
|
16212 |
|
16213 | if (oldPlaylist) {
|
16214 | if (oldPlaylist.id) {
|
16215 | oldId = oldPlaylist.id;
|
16216 | } else if (oldPlaylist.uri) {
|
16217 | oldId = oldPlaylist.uri;
|
16218 | }
|
16219 | }
|
16220 |
|
16221 | this.logger_("playlist update [" + oldId + " => " + (newPlaylist.id || newPlaylist.uri) + "]");
|
16222 |
|
16223 |
|
16224 | this.trigger('syncinfoupdate');
|
16225 |
|
16226 |
|
16227 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
16228 | return this.init_();
|
16229 | }
|
16230 |
|
16231 | if (!oldPlaylist || oldPlaylist.uri !== newPlaylist.uri) {
|
16232 | if (this.mediaIndex !== null) {
|
16233 |
|
16234 |
|
16235 | this.resyncLoader();
|
16236 | }
|
16237 |
|
16238 | this.currentMediaInfo_ = void 0;
|
16239 | this.trigger('playlistupdate');
|
16240 |
|
16241 | return;
|
16242 | }
|
16243 |
|
16244 |
|
16245 |
|
16246 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
16247 | this.logger_("live window shift [" + mediaSequenceDiff + "]");
|
16248 |
|
16249 |
|
16250 |
|
16251 | if (this.mediaIndex !== null) {
|
16252 | this.mediaIndex -= mediaSequenceDiff;
|
16253 |
|
16254 |
|
16255 |
|
16256 | if (this.mediaIndex < 0) {
|
16257 | this.mediaIndex = null;
|
16258 | this.partIndex = null;
|
16259 | } else {
|
16260 | var segment = this.playlist_.segments[this.mediaIndex];
|
16261 |
|
16262 |
|
16263 |
|
16264 | if (this.partIndex && (!segment.parts || !segment.parts.length || !segment.parts[this.partIndex])) {
|
16265 | var mediaIndex = this.mediaIndex;
|
16266 | this.logger_("currently processing part (index " + this.partIndex + ") no longer exists.");
|
16267 | this.resetLoader();
|
16268 |
|
16269 |
|
16270 |
|
16271 | this.mediaIndex = mediaIndex;
|
16272 | }
|
16273 | }
|
16274 | }
|
16275 |
|
16276 |
|
16277 |
|
16278 |
|
16279 | if (segmentInfo) {
|
16280 | segmentInfo.mediaIndex -= mediaSequenceDiff;
|
16281 |
|
16282 | if (segmentInfo.mediaIndex < 0) {
|
16283 | segmentInfo.mediaIndex = null;
|
16284 | segmentInfo.partIndex = null;
|
16285 | } else {
|
16286 |
|
16287 |
|
16288 |
|
16289 | if (segmentInfo.mediaIndex >= 0) {
|
16290 | segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex];
|
16291 | }
|
16292 |
|
16293 | if (segmentInfo.partIndex >= 0 && segmentInfo.segment.parts) {
|
16294 | segmentInfo.part = segmentInfo.segment.parts[segmentInfo.partIndex];
|
16295 | }
|
16296 | }
|
16297 | }
|
16298 |
|
16299 | this.syncController_.saveExpiredSegmentInfo(oldPlaylist, newPlaylist);
|
16300 | }
|
16301 | |
16302 |
|
16303 |
|
16304 |
|
16305 |
|
16306 |
|
16307 | ;
|
16308 |
|
16309 | _proto.pause = function pause() {
|
16310 | if (this.checkBufferTimeout_) {
|
16311 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16312 | this.checkBufferTimeout_ = null;
|
16313 | }
|
16314 | }
|
16315 | |
16316 |
|
16317 |
|
16318 |
|
16319 |
|
16320 | ;
|
16321 |
|
16322 | _proto.paused = function paused() {
|
16323 | return this.checkBufferTimeout_ === null;
|
16324 | }
|
16325 | |
16326 |
|
16327 |
|
16328 |
|
16329 |
|
16330 |
|
16331 | ;
|
16332 |
|
16333 | _proto.resetEverything = function resetEverything(done) {
|
16334 | this.ended_ = false;
|
16335 | this.appendInitSegment_ = {
|
16336 | audio: true,
|
16337 | video: true
|
16338 | };
|
16339 | this.resetLoader();
|
16340 |
|
16341 |
|
16342 |
|
16343 | this.remove(0, Infinity, done);
|
16344 |
|
16345 | if (this.transmuxer_) {
|
16346 | this.transmuxer_.postMessage({
|
16347 | action: 'clearAllMp4Captions'
|
16348 | });
|
16349 |
|
16350 | this.transmuxer_.postMessage({
|
16351 | action: 'reset'
|
16352 | });
|
16353 | }
|
16354 | }
|
16355 | |
16356 |
|
16357 |
|
16358 |
|
16359 |
|
16360 |
|
16361 | ;
|
16362 |
|
16363 | _proto.resetLoader = function resetLoader() {
|
16364 | this.fetchAtBuffer_ = false;
|
16365 | this.resyncLoader();
|
16366 | }
|
16367 | |
16368 |
|
16369 |
|
16370 |
|
16371 | ;
|
16372 |
|
16373 | _proto.resyncLoader = function resyncLoader() {
|
16374 | if (this.transmuxer_) {
|
16375 |
|
16376 | segmentTransmuxer.reset(this.transmuxer_);
|
16377 | }
|
16378 |
|
16379 | this.mediaIndex = null;
|
16380 | this.partIndex = null;
|
16381 | this.syncPoint_ = null;
|
16382 | this.isPendingTimestampOffset_ = false;
|
16383 | this.callQueue_ = [];
|
16384 | this.loadQueue_ = [];
|
16385 | this.metadataQueue_.id3 = [];
|
16386 | this.metadataQueue_.caption = [];
|
16387 | this.abort();
|
16388 |
|
16389 | if (this.transmuxer_) {
|
16390 | this.transmuxer_.postMessage({
|
16391 | action: 'clearParsedMp4Captions'
|
16392 | });
|
16393 | }
|
16394 | }
|
16395 | |
16396 |
|
16397 |
|
16398 |
|
16399 |
|
16400 |
|
16401 |
|
16402 |
|
16403 |
|
16404 | ;
|
16405 |
|
16406 | _proto.remove = function remove(start, end, done, force) {
|
16407 | if (done === void 0) {
|
16408 | done = function done() {};
|
16409 | }
|
16410 |
|
16411 | if (force === void 0) {
|
16412 | force = false;
|
16413 | }
|
16414 |
|
16415 |
|
16416 |
|
16417 |
|
16418 | if (end === Infinity) {
|
16419 | end = this.duration_();
|
16420 | }
|
16421 |
|
16422 |
|
16423 |
|
16424 |
|
16425 | if (end <= start) {
|
16426 | this.logger_('skipping remove because end ${end} is <= start ${start}');
|
16427 | return;
|
16428 | }
|
16429 |
|
16430 | if (!this.sourceUpdater_ || !this.getMediaInfo_()) {
|
16431 | this.logger_('skipping remove because no source updater or starting media info');
|
16432 |
|
16433 | return;
|
16434 | }
|
16435 |
|
16436 |
|
16437 | var removesRemaining = 1;
|
16438 |
|
16439 | var removeFinished = function removeFinished() {
|
16440 | removesRemaining--;
|
16441 |
|
16442 | if (removesRemaining === 0) {
|
16443 | done();
|
16444 | }
|
16445 | };
|
16446 |
|
16447 | if (force || !this.audioDisabled_) {
|
16448 | removesRemaining++;
|
16449 | this.sourceUpdater_.removeAudio(start, end, removeFinished);
|
16450 | }
|
16451 |
|
16452 |
|
16453 |
|
16454 |
|
16455 |
|
16456 |
|
16457 |
|
16458 |
|
16459 |
|
16460 | if (force || this.loaderType_ === 'main') {
|
16461 | this.gopBuffer_ = removeGopBuffer(this.gopBuffer_, start, end, this.timeMapping_);
|
16462 | removesRemaining++;
|
16463 | this.sourceUpdater_.removeVideo(start, end, removeFinished);
|
16464 | }
|
16465 |
|
16466 |
|
16467 | for (var track in this.inbandTextTracks_) {
|
16468 | removeCuesFromTrack(start, end, this.inbandTextTracks_[track]);
|
16469 | }
|
16470 |
|
16471 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
16472 |
|
16473 | removeFinished();
|
16474 | }
|
16475 | |
16476 |
|
16477 |
|
16478 |
|
16479 |
|
16480 | ;
|
16481 |
|
16482 | _proto.monitorBuffer_ = function monitorBuffer_() {
|
16483 | if (this.checkBufferTimeout_) {
|
16484 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16485 | }
|
16486 |
|
16487 | this.checkBufferTimeout_ = window__default["default"].setTimeout(this.monitorBufferTick_.bind(this), 1);
|
16488 | }
|
16489 | |
16490 |
|
16491 |
|
16492 |
|
16493 |
|
16494 |
|
16495 | ;
|
16496 |
|
16497 | _proto.monitorBufferTick_ = function monitorBufferTick_() {
|
16498 | if (this.state === 'READY') {
|
16499 | this.fillBuffer_();
|
16500 | }
|
16501 |
|
16502 | if (this.checkBufferTimeout_) {
|
16503 | window__default["default"].clearTimeout(this.checkBufferTimeout_);
|
16504 | }
|
16505 |
|
16506 | this.checkBufferTimeout_ = window__default["default"].setTimeout(this.monitorBufferTick_.bind(this), CHECK_BUFFER_DELAY);
|
16507 | }
|
16508 | |
16509 |
|
16510 |
|
16511 |
|
16512 |
|
16513 |
|
16514 |
|
16515 |
|
16516 |
|
16517 | ;
|
16518 |
|
16519 | _proto.fillBuffer_ = function fillBuffer_() {
|
16520 |
|
16521 |
|
16522 | if (this.sourceUpdater_.updating()) {
|
16523 | return;
|
16524 | }
|
16525 |
|
16526 |
|
16527 | var segmentInfo = this.chooseNextRequest_();
|
16528 |
|
16529 | if (!segmentInfo) {
|
16530 | return;
|
16531 | }
|
16532 |
|
16533 | if (typeof segmentInfo.timestampOffset === 'number') {
|
16534 | this.isPendingTimestampOffset_ = false;
|
16535 | this.timelineChangeController_.pendingTimelineChange({
|
16536 | type: this.loaderType_,
|
16537 | from: this.currentTimeline_,
|
16538 | to: segmentInfo.timeline
|
16539 | });
|
16540 | }
|
16541 |
|
16542 | this.loadSegment_(segmentInfo);
|
16543 | }
|
16544 | |
16545 |
|
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 |
|
16552 |
|
16553 | ;
|
16554 |
|
16555 | _proto.isEndOfStream_ = function isEndOfStream_(mediaIndex, playlist, partIndex) {
|
16556 | if (mediaIndex === void 0) {
|
16557 | mediaIndex = this.mediaIndex;
|
16558 | }
|
16559 |
|
16560 | if (playlist === void 0) {
|
16561 | playlist = this.playlist_;
|
16562 | }
|
16563 |
|
16564 | if (partIndex === void 0) {
|
16565 | partIndex = this.partIndex;
|
16566 | }
|
16567 |
|
16568 | if (!playlist || !this.mediaSource_) {
|
16569 | return false;
|
16570 | }
|
16571 |
|
16572 | var segment = typeof mediaIndex === 'number' && playlist.segments[mediaIndex];
|
16573 |
|
16574 | var appendedLastSegment = mediaIndex + 1 === playlist.segments.length;
|
16575 |
|
16576 | var appendedLastPart = !segment || !segment.parts || partIndex + 1 === segment.parts.length;
|
16577 |
|
16578 |
|
16579 |
|
16580 | return playlist.endList && this.mediaSource_.readyState === 'open' && appendedLastSegment && appendedLastPart;
|
16581 | }
|
16582 | |
16583 |
|
16584 |
|
16585 |
|
16586 |
|
16587 | ;
|
16588 |
|
16589 | _proto.chooseNextRequest_ = function chooseNextRequest_() {
|
16590 | var bufferedEnd = lastBufferedEnd(this.buffered_()) || 0;
|
16591 | var bufferedTime = Math.max(0, bufferedEnd - this.currentTime_());
|
16592 | var preloaded = !this.hasPlayed_() && bufferedTime >= 1;
|
16593 | var haveEnoughBuffer = bufferedTime >= this.goalBufferLength_();
|
16594 | var segments = this.playlist_.segments;
|
16595 |
|
16596 |
|
16597 |
|
16598 |
|
16599 | if (!segments.length || preloaded || haveEnoughBuffer) {
|
16600 | return null;
|
16601 | }
|
16602 |
|
16603 | this.syncPoint_ = this.syncPoint_ || this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
16604 | var next = {
|
16605 | partIndex: null,
|
16606 | mediaIndex: null,
|
16607 | startOfSegment: null,
|
16608 | playlist: this.playlist_,
|
16609 | isSyncRequest: Boolean(!this.syncPoint_)
|
16610 | };
|
16611 |
|
16612 | if (next.isSyncRequest) {
|
16613 | next.mediaIndex = getSyncSegmentCandidate(this.currentTimeline_, segments, bufferedEnd);
|
16614 | } else if (this.mediaIndex !== null) {
|
16615 | var segment = segments[this.mediaIndex];
|
16616 | var partIndex = typeof this.partIndex === 'number' ? this.partIndex : -1;
|
16617 | next.startOfSegment = segment.end ? segment.end : bufferedEnd;
|
16618 |
|
16619 | if (segment.parts && segment.parts[partIndex + 1]) {
|
16620 | next.mediaIndex = this.mediaIndex;
|
16621 | next.partIndex = partIndex + 1;
|
16622 | } else {
|
16623 | next.mediaIndex = this.mediaIndex + 1;
|
16624 | }
|
16625 | } else {
|
16626 |
|
16627 | var _Playlist$getMediaInf = Playlist.getMediaInfoForTime({
|
16628 | experimentalExactManifestTimings: this.experimentalExactManifestTimings,
|
16629 | playlist: this.playlist_,
|
16630 | currentTime: this.fetchAtBuffer_ ? bufferedEnd : this.currentTime_(),
|
16631 | startingPartIndex: this.syncPoint_.partIndex,
|
16632 | startingSegmentIndex: this.syncPoint_.segmentIndex,
|
16633 | startTime: this.syncPoint_.time
|
16634 | }),
|
16635 | segmentIndex = _Playlist$getMediaInf.segmentIndex,
|
16636 | startTime = _Playlist$getMediaInf.startTime,
|
16637 | _partIndex = _Playlist$getMediaInf.partIndex;
|
16638 |
|
16639 | next.getMediaInfoForTime = this.fetchAtBuffer_ ? 'bufferedEnd' : 'currentTime';
|
16640 | next.mediaIndex = segmentIndex;
|
16641 | next.startOfSegment = startTime;
|
16642 | next.partIndex = _partIndex;
|
16643 | }
|
16644 |
|
16645 | var nextSegment = segments[next.mediaIndex];
|
16646 | var nextPart = nextSegment && typeof next.partIndex === 'number' && nextSegment.parts && nextSegment.parts[next.partIndex];
|
16647 |
|
16648 |
|
16649 | if (!nextSegment || typeof next.partIndex === 'number' && !nextPart) {
|
16650 | return null;
|
16651 | }
|
16652 |
|
16653 |
|
16654 |
|
16655 | if (typeof next.partIndex !== 'number' && nextSegment.parts) {
|
16656 | next.partIndex = 0;
|
16657 | }
|
16658 |
|
16659 | var ended = this.mediaSource_ && this.mediaSource_.readyState === 'ended';
|
16660 |
|
16661 |
|
16662 |
|
16663 |
|
16664 | if (next.mediaIndex >= segments.length - 1 && ended && !this.seeking_()) {
|
16665 | return null;
|
16666 | }
|
16667 |
|
16668 | return this.generateSegmentInfo_(next);
|
16669 | };
|
16670 |
|
16671 | _proto.generateSegmentInfo_ = function generateSegmentInfo_(options) {
|
16672 | var playlist = options.playlist,
|
16673 | mediaIndex = options.mediaIndex,
|
16674 | startOfSegment = options.startOfSegment,
|
16675 | isSyncRequest = options.isSyncRequest,
|
16676 | partIndex = options.partIndex,
|
16677 | forceTimestampOffset = options.forceTimestampOffset,
|
16678 | getMediaInfoForTime = options.getMediaInfoForTime;
|
16679 | var segment = playlist.segments[mediaIndex];
|
16680 | var part = typeof partIndex === 'number' && segment.parts[partIndex];
|
16681 | var segmentInfo = {
|
16682 | requestId: 'segment-loader-' + Math.random(),
|
16683 |
|
16684 | uri: part && part.resolvedUri || segment.resolvedUri,
|
16685 |
|
16686 | mediaIndex: mediaIndex,
|
16687 | partIndex: part ? partIndex : null,
|
16688 |
|
16689 |
|
16690 | isSyncRequest: isSyncRequest,
|
16691 | startOfSegment: startOfSegment,
|
16692 |
|
16693 | playlist: playlist,
|
16694 |
|
16695 | bytes: null,
|
16696 |
|
16697 | encryptedBytes: null,
|
16698 |
|
16699 |
|
16700 | timestampOffset: null,
|
16701 |
|
16702 | timeline: segment.timeline,
|
16703 |
|
16704 | duration: part && part.duration || segment.duration,
|
16705 |
|
16706 | segment: segment,
|
16707 | part: part,
|
16708 | byteLength: 0,
|
16709 | transmuxer: this.transmuxer_,
|
16710 |
|
16711 | getMediaInfoForTime: getMediaInfoForTime
|
16712 | };
|
16713 | var overrideCheck = typeof forceTimestampOffset !== 'undefined' ? forceTimestampOffset : this.isPendingTimestampOffset_;
|
16714 | segmentInfo.timestampOffset = this.timestampOffsetForSegment_({
|
16715 | segmentTimeline: segment.timeline,
|
16716 | currentTimeline: this.currentTimeline_,
|
16717 | startOfSegment: startOfSegment,
|
16718 | buffered: this.buffered_(),
|
16719 | overrideCheck: overrideCheck
|
16720 | });
|
16721 | var audioBufferedEnd = lastBufferedEnd(this.sourceUpdater_.audioBuffered());
|
16722 |
|
16723 | if (typeof audioBufferedEnd === 'number') {
|
16724 |
|
16725 |
|
16726 | segmentInfo.audioAppendStart = audioBufferedEnd - this.sourceUpdater_.audioTimestampOffset();
|
16727 | }
|
16728 |
|
16729 | if (this.sourceUpdater_.videoBuffered().length) {
|
16730 | segmentInfo.gopsToAlignWith = gopsSafeToAlignWith(this.gopBuffer_,
|
16731 |
|
16732 | this.currentTime_() - this.sourceUpdater_.videoTimestampOffset(), this.timeMapping_);
|
16733 | }
|
16734 |
|
16735 | return segmentInfo;
|
16736 | }
|
16737 |
|
16738 |
|
16739 | ;
|
16740 |
|
16741 | _proto.timestampOffsetForSegment_ = function timestampOffsetForSegment_(options) {
|
16742 | return timestampOffsetForSegment(options);
|
16743 | }
|
16744 | |
16745 |
|
16746 |
|
16747 |
|
16748 |
|
16749 |
|
16750 |
|
16751 |
|
16752 |
|
16753 | ;
|
16754 |
|
16755 | _proto.earlyAbortWhenNeeded_ = function earlyAbortWhenNeeded_(stats) {
|
16756 | if (this.vhs_.tech_.paused() ||
|
16757 |
|
16758 |
|
16759 | !this.xhrOptions_.timeout ||
|
16760 | !this.playlist_.attributes.BANDWIDTH) {
|
16761 | return;
|
16762 | }
|
16763 |
|
16764 |
|
16765 |
|
16766 |
|
16767 | if (Date.now() - (stats.firstBytesReceivedAt || Date.now()) < 1000) {
|
16768 | return;
|
16769 | }
|
16770 |
|
16771 | var currentTime = this.currentTime_();
|
16772 | var measuredBandwidth = stats.bandwidth;
|
16773 | var segmentDuration = this.pendingSegment_.duration;
|
16774 | var requestTimeRemaining = Playlist.estimateSegmentRequestTime(segmentDuration, measuredBandwidth, this.playlist_, stats.bytesReceived);
|
16775 |
|
16776 |
|
16777 |
|
16778 | var timeUntilRebuffer$1 = timeUntilRebuffer(this.buffered_(), currentTime, this.vhs_.tech_.playbackRate()) - 1;
|
16779 |
|
16780 |
|
16781 | if (requestTimeRemaining <= timeUntilRebuffer$1) {
|
16782 | return;
|
16783 | }
|
16784 |
|
16785 | var switchCandidate = minRebufferMaxBandwidthSelector({
|
16786 | master: this.vhs_.playlists.master,
|
16787 | currentTime: currentTime,
|
16788 | bandwidth: measuredBandwidth,
|
16789 | duration: this.duration_(),
|
16790 | segmentDuration: segmentDuration,
|
16791 | timeUntilRebuffer: timeUntilRebuffer$1,
|
16792 | currentTimeline: this.currentTimeline_,
|
16793 | syncController: this.syncController_
|
16794 | });
|
16795 |
|
16796 | if (!switchCandidate) {
|
16797 | return;
|
16798 | }
|
16799 |
|
16800 | var rebufferingImpact = requestTimeRemaining - timeUntilRebuffer$1;
|
16801 | var timeSavedBySwitching = rebufferingImpact - switchCandidate.rebufferingImpact;
|
16802 | var minimumTimeSaving = 0.5;
|
16803 |
|
16804 |
|
16805 |
|
16806 | if (timeUntilRebuffer$1 <= TIME_FUDGE_FACTOR) {
|
16807 | minimumTimeSaving = 1;
|
16808 | }
|
16809 |
|
16810 | if (!switchCandidate.playlist || switchCandidate.playlist.uri === this.playlist_.uri || timeSavedBySwitching < minimumTimeSaving) {
|
16811 | return;
|
16812 | }
|
16813 |
|
16814 |
|
16815 |
|
16816 |
|
16817 | this.bandwidth = switchCandidate.playlist.attributes.BANDWIDTH * Config.BANDWIDTH_VARIANCE + 1;
|
16818 | this.trigger('earlyabort');
|
16819 | };
|
16820 |
|
16821 | _proto.handleAbort_ = function handleAbort_(segmentInfo) {
|
16822 | this.logger_("Aborting " + segmentInfoString(segmentInfo));
|
16823 | this.mediaRequestsAborted += 1;
|
16824 | }
|
16825 | |
16826 |
|
16827 |
|
16828 |
|
16829 |
|
16830 |
|
16831 |
|
16832 |
|
16833 |
|
16834 | ;
|
16835 |
|
16836 | _proto.handleProgress_ = function handleProgress_(event, simpleSegment) {
|
16837 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
16838 |
|
16839 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
16840 | return;
|
16841 | }
|
16842 |
|
16843 | this.trigger('progress');
|
16844 | };
|
16845 |
|
16846 | _proto.handleTrackInfo_ = function handleTrackInfo_(simpleSegment, trackInfo) {
|
16847 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
16848 |
|
16849 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
16850 | return;
|
16851 | }
|
16852 |
|
16853 | if (this.checkForIllegalMediaSwitch(trackInfo)) {
|
16854 | return;
|
16855 | }
|
16856 |
|
16857 | trackInfo = trackInfo || {};
|
16858 |
|
16859 |
|
16860 |
|
16861 | if (!shallowEqual(this.currentMediaInfo_, trackInfo)) {
|
16862 | this.appendInitSegment_ = {
|
16863 | audio: true,
|
16864 | video: true
|
16865 | };
|
16866 | this.startingMediaInfo_ = trackInfo;
|
16867 | this.currentMediaInfo_ = trackInfo;
|
16868 | this.logger_('trackinfo update', trackInfo);
|
16869 | this.trigger('trackinfo');
|
16870 | }
|
16871 |
|
16872 |
|
16873 |
|
16874 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
16875 | return;
|
16876 | }
|
16877 |
|
16878 |
|
16879 |
|
16880 | this.pendingSegment_.trackInfo = trackInfo;
|
16881 |
|
16882 | if (this.hasEnoughInfoToAppend_()) {
|
16883 | this.processCallQueue_();
|
16884 | }
|
16885 | };
|
16886 |
|
16887 | _proto.handleTimingInfo_ = function handleTimingInfo_(simpleSegment, mediaType, timeType, time) {
|
16888 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
16889 |
|
16890 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
16891 | return;
|
16892 | }
|
16893 |
|
16894 | var segmentInfo = this.pendingSegment_;
|
16895 | var timingInfoProperty = timingInfoPropertyForMedia(mediaType);
|
16896 | segmentInfo[timingInfoProperty] = segmentInfo[timingInfoProperty] || {};
|
16897 | segmentInfo[timingInfoProperty][timeType] = time;
|
16898 | this.logger_("timinginfo: " + mediaType + " - " + timeType + " - " + time);
|
16899 |
|
16900 | if (this.hasEnoughInfoToAppend_()) {
|
16901 | this.processCallQueue_();
|
16902 | }
|
16903 | };
|
16904 |
|
16905 | _proto.handleCaptions_ = function handleCaptions_(simpleSegment, captionData) {
|
16906 | var _this2 = this;
|
16907 |
|
16908 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
16909 |
|
16910 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
16911 | return;
|
16912 | }
|
16913 |
|
16914 |
|
16915 |
|
16916 | if (captionData.length === 0) {
|
16917 | this.logger_('SegmentLoader received no captions from a caption event');
|
16918 | return;
|
16919 | }
|
16920 |
|
16921 | var segmentInfo = this.pendingSegment_;
|
16922 |
|
16923 |
|
16924 | if (!segmentInfo.hasAppendedData_) {
|
16925 | this.metadataQueue_.caption.push(this.handleCaptions_.bind(this, simpleSegment, captionData));
|
16926 | return;
|
16927 | }
|
16928 |
|
16929 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
16930 | var captionTracks = {};
|
16931 |
|
16932 | captionData.forEach(function (caption) {
|
16933 |
|
16934 |
|
16935 | captionTracks[caption.stream] = captionTracks[caption.stream] || {
|
16936 |
|
16937 | startTime: Infinity,
|
16938 | captions: [],
|
16939 |
|
16940 | endTime: 0
|
16941 | };
|
16942 | var captionTrack = captionTracks[caption.stream];
|
16943 | captionTrack.startTime = Math.min(captionTrack.startTime, caption.startTime + timestampOffset);
|
16944 | captionTrack.endTime = Math.max(captionTrack.endTime, caption.endTime + timestampOffset);
|
16945 | captionTrack.captions.push(caption);
|
16946 | });
|
16947 | Object.keys(captionTracks).forEach(function (trackName) {
|
16948 | var _captionTracks$trackN = captionTracks[trackName],
|
16949 | startTime = _captionTracks$trackN.startTime,
|
16950 | endTime = _captionTracks$trackN.endTime,
|
16951 | captions = _captionTracks$trackN.captions;
|
16952 | var inbandTextTracks = _this2.inbandTextTracks_;
|
16953 |
|
16954 | _this2.logger_("adding cues from " + startTime + " -> " + endTime + " for " + trackName);
|
16955 |
|
16956 | createCaptionsTrackIfNotExists(inbandTextTracks, _this2.vhs_.tech_, trackName);
|
16957 |
|
16958 |
|
16959 |
|
16960 |
|
16961 | removeCuesFromTrack(startTime, endTime, inbandTextTracks[trackName]);
|
16962 | addCaptionData({
|
16963 | captionArray: captions,
|
16964 | inbandTextTracks: inbandTextTracks,
|
16965 | timestampOffset: timestampOffset
|
16966 | });
|
16967 | });
|
16968 |
|
16969 |
|
16970 | if (this.transmuxer_) {
|
16971 | this.transmuxer_.postMessage({
|
16972 | action: 'clearParsedMp4Captions'
|
16973 | });
|
16974 | }
|
16975 | };
|
16976 |
|
16977 | _proto.handleId3_ = function handleId3_(simpleSegment, id3Frames, dispatchType) {
|
16978 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
16979 |
|
16980 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
16981 | return;
|
16982 | }
|
16983 |
|
16984 | var segmentInfo = this.pendingSegment_;
|
16985 |
|
16986 | if (!segmentInfo.hasAppendedData_) {
|
16987 | this.metadataQueue_.id3.push(this.handleId3_.bind(this, simpleSegment, id3Frames, dispatchType));
|
16988 | return;
|
16989 | }
|
16990 |
|
16991 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
16992 |
|
16993 |
|
16994 |
|
16995 | createMetadataTrackIfNotExists(this.inbandTextTracks_, dispatchType, this.vhs_.tech_);
|
16996 | addMetadata({
|
16997 | inbandTextTracks: this.inbandTextTracks_,
|
16998 | metadataArray: id3Frames,
|
16999 | timestampOffset: timestampOffset,
|
17000 | videoDuration: this.duration_()
|
17001 | });
|
17002 | };
|
17003 |
|
17004 | _proto.processMetadataQueue_ = function processMetadataQueue_() {
|
17005 | this.metadataQueue_.id3.forEach(function (fn) {
|
17006 | return fn();
|
17007 | });
|
17008 | this.metadataQueue_.caption.forEach(function (fn) {
|
17009 | return fn();
|
17010 | });
|
17011 | this.metadataQueue_.id3 = [];
|
17012 | this.metadataQueue_.caption = [];
|
17013 | };
|
17014 |
|
17015 | _proto.processCallQueue_ = function processCallQueue_() {
|
17016 | var callQueue = this.callQueue_;
|
17017 |
|
17018 |
|
17019 |
|
17020 | this.callQueue_ = [];
|
17021 | callQueue.forEach(function (fun) {
|
17022 | return fun();
|
17023 | });
|
17024 | };
|
17025 |
|
17026 | _proto.processLoadQueue_ = function processLoadQueue_() {
|
17027 | var loadQueue = this.loadQueue_;
|
17028 |
|
17029 |
|
17030 |
|
17031 | this.loadQueue_ = [];
|
17032 | loadQueue.forEach(function (fun) {
|
17033 | return fun();
|
17034 | });
|
17035 | }
|
17036 | |
17037 |
|
17038 |
|
17039 |
|
17040 |
|
17041 |
|
17042 | ;
|
17043 |
|
17044 | _proto.hasEnoughInfoToLoad_ = function hasEnoughInfoToLoad_() {
|
17045 |
|
17046 |
|
17047 | if (this.loaderType_ !== 'audio') {
|
17048 | return true;
|
17049 | }
|
17050 |
|
17051 | var segmentInfo = this.pendingSegment_;
|
17052 |
|
17053 |
|
17054 | if (!segmentInfo) {
|
17055 | return false;
|
17056 | }
|
17057 |
|
17058 |
|
17059 |
|
17060 |
|
17061 |
|
17062 | if (!this.getCurrentMediaInfo_()) {
|
17063 | return true;
|
17064 | }
|
17065 |
|
17066 | if (
|
17067 |
|
17068 |
|
17069 |
|
17070 |
|
17071 |
|
17072 |
|
17073 |
|
17074 |
|
17075 |
|
17076 |
|
17077 |
|
17078 |
|
17079 |
|
17080 |
|
17081 | shouldWaitForTimelineChange({
|
17082 | timelineChangeController: this.timelineChangeController_,
|
17083 | currentTimeline: this.currentTimeline_,
|
17084 | segmentTimeline: segmentInfo.timeline,
|
17085 | loaderType: this.loaderType_,
|
17086 | audioDisabled: this.audioDisabled_
|
17087 | })) {
|
17088 | return false;
|
17089 | }
|
17090 |
|
17091 | return true;
|
17092 | };
|
17093 |
|
17094 | _proto.getCurrentMediaInfo_ = function getCurrentMediaInfo_(segmentInfo) {
|
17095 | if (segmentInfo === void 0) {
|
17096 | segmentInfo = this.pendingSegment_;
|
17097 | }
|
17098 |
|
17099 | return segmentInfo && segmentInfo.trackInfo || this.currentMediaInfo_;
|
17100 | };
|
17101 |
|
17102 | _proto.getMediaInfo_ = function getMediaInfo_(segmentInfo) {
|
17103 | if (segmentInfo === void 0) {
|
17104 | segmentInfo = this.pendingSegment_;
|
17105 | }
|
17106 |
|
17107 | return this.getCurrentMediaInfo_(segmentInfo) || this.startingMediaInfo_;
|
17108 | };
|
17109 |
|
17110 | _proto.hasEnoughInfoToAppend_ = function hasEnoughInfoToAppend_() {
|
17111 | if (!this.sourceUpdater_.ready()) {
|
17112 | return false;
|
17113 | }
|
17114 |
|
17115 |
|
17116 |
|
17117 | if (this.waitingOnRemove_ || this.quotaExceededErrorRetryTimeout_) {
|
17118 | return false;
|
17119 | }
|
17120 |
|
17121 | var segmentInfo = this.pendingSegment_;
|
17122 | var trackInfo = this.getCurrentMediaInfo_();
|
17123 |
|
17124 |
|
17125 |
|
17126 | if (!segmentInfo || !trackInfo) {
|
17127 | return false;
|
17128 | }
|
17129 |
|
17130 | var hasAudio = trackInfo.hasAudio,
|
17131 | hasVideo = trackInfo.hasVideo,
|
17132 | isMuxed = trackInfo.isMuxed;
|
17133 |
|
17134 | if (hasVideo && !segmentInfo.videoTimingInfo) {
|
17135 | return false;
|
17136 | }
|
17137 |
|
17138 |
|
17139 | if (hasAudio && !this.audioDisabled_ && !isMuxed && !segmentInfo.audioTimingInfo) {
|
17140 | return false;
|
17141 | }
|
17142 |
|
17143 | if (shouldWaitForTimelineChange({
|
17144 | timelineChangeController: this.timelineChangeController_,
|
17145 | currentTimeline: this.currentTimeline_,
|
17146 | segmentTimeline: segmentInfo.timeline,
|
17147 | loaderType: this.loaderType_,
|
17148 | audioDisabled: this.audioDisabled_
|
17149 | })) {
|
17150 | return false;
|
17151 | }
|
17152 |
|
17153 | return true;
|
17154 | };
|
17155 |
|
17156 | _proto.handleData_ = function handleData_(simpleSegment, result) {
|
17157 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
17158 |
|
17159 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
17160 | return;
|
17161 | }
|
17162 |
|
17163 |
|
17164 |
|
17165 | if (this.callQueue_.length || !this.hasEnoughInfoToAppend_()) {
|
17166 | this.callQueue_.push(this.handleData_.bind(this, simpleSegment, result));
|
17167 | return;
|
17168 | }
|
17169 |
|
17170 | var segmentInfo = this.pendingSegment_;
|
17171 |
|
17172 | this.setTimeMapping_(segmentInfo.timeline);
|
17173 |
|
17174 | this.updateMediaSecondsLoaded_(segmentInfo.segment);
|
17175 |
|
17176 |
|
17177 |
|
17178 |
|
17179 |
|
17180 | if (this.mediaSource_.readyState === 'closed') {
|
17181 | return;
|
17182 | }
|
17183 |
|
17184 |
|
17185 |
|
17186 | if (simpleSegment.map) {
|
17187 | simpleSegment.map = this.initSegmentForMap(simpleSegment.map, true);
|
17188 |
|
17189 | segmentInfo.segment.map = simpleSegment.map;
|
17190 | }
|
17191 |
|
17192 |
|
17193 | if (simpleSegment.key) {
|
17194 | this.segmentKey(simpleSegment.key, true);
|
17195 | }
|
17196 |
|
17197 | segmentInfo.isFmp4 = simpleSegment.isFmp4;
|
17198 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
17199 |
|
17200 | if (segmentInfo.isFmp4) {
|
17201 | this.trigger('fmp4');
|
17202 | segmentInfo.timingInfo.start = segmentInfo[timingInfoPropertyForMedia(result.type)].start;
|
17203 | } else {
|
17204 | var trackInfo = this.getCurrentMediaInfo_();
|
17205 | var useVideoTimingInfo = this.loaderType_ === 'main' && trackInfo && trackInfo.hasVideo;
|
17206 | var firstVideoFrameTimeForData;
|
17207 |
|
17208 | if (useVideoTimingInfo) {
|
17209 | firstVideoFrameTimeForData = segmentInfo.videoTimingInfo.start;
|
17210 | }
|
17211 |
|
17212 |
|
17213 |
|
17214 |
|
17215 | segmentInfo.timingInfo.start = this.trueSegmentStart_({
|
17216 | currentStart: segmentInfo.timingInfo.start,
|
17217 | playlist: segmentInfo.playlist,
|
17218 | mediaIndex: segmentInfo.mediaIndex,
|
17219 | currentVideoTimestampOffset: this.sourceUpdater_.videoTimestampOffset(),
|
17220 | useVideoTimingInfo: useVideoTimingInfo,
|
17221 | firstVideoFrameTimeForData: firstVideoFrameTimeForData,
|
17222 | videoTimingInfo: segmentInfo.videoTimingInfo,
|
17223 | audioTimingInfo: segmentInfo.audioTimingInfo
|
17224 | });
|
17225 | }
|
17226 |
|
17227 |
|
17228 |
|
17229 |
|
17230 | this.updateAppendInitSegmentStatus(segmentInfo, result.type);
|
17231 |
|
17232 |
|
17233 |
|
17234 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
17235 |
|
17236 |
|
17237 | if (segmentInfo.isSyncRequest) {
|
17238 |
|
17239 |
|
17240 |
|
17241 | this.updateTimingInfoEnd_(segmentInfo);
|
17242 | this.syncController_.saveSegmentTimingInfo({
|
17243 | segmentInfo: segmentInfo,
|
17244 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
17245 | });
|
17246 | var next = this.chooseNextRequest_();
|
17247 |
|
17248 |
|
17249 | if (next.mediaIndex !== segmentInfo.mediaIndex || next.partIndex !== segmentInfo.partIndex) {
|
17250 | this.logger_('sync segment was incorrect, not appending');
|
17251 | return;
|
17252 | }
|
17253 |
|
17254 |
|
17255 | this.logger_('sync segment was correct, appending');
|
17256 | }
|
17257 |
|
17258 |
|
17259 |
|
17260 |
|
17261 |
|
17262 | segmentInfo.hasAppendedData_ = true;
|
17263 |
|
17264 | this.processMetadataQueue_();
|
17265 | this.appendData_(segmentInfo, result);
|
17266 | };
|
17267 |
|
17268 | _proto.updateAppendInitSegmentStatus = function updateAppendInitSegmentStatus(segmentInfo, type) {
|
17269 |
|
17270 | if (this.loaderType_ === 'main' && typeof segmentInfo.timestampOffset === 'number' &&
|
17271 |
|
17272 | !segmentInfo.changedTimestampOffset) {
|
17273 |
|
17274 |
|
17275 | this.appendInitSegment_ = {
|
17276 | audio: true,
|
17277 | video: true
|
17278 | };
|
17279 | }
|
17280 |
|
17281 | if (this.playlistOfLastInitSegment_[type] !== segmentInfo.playlist) {
|
17282 |
|
17283 |
|
17284 | this.appendInitSegment_[type] = true;
|
17285 | }
|
17286 | };
|
17287 |
|
17288 | _proto.getInitSegmentAndUpdateState_ = function getInitSegmentAndUpdateState_(_ref4) {
|
17289 | var type = _ref4.type,
|
17290 | initSegment = _ref4.initSegment,
|
17291 | map = _ref4.map,
|
17292 | playlist = _ref4.playlist;
|
17293 |
|
17294 |
|
17295 |
|
17296 |
|
17297 |
|
17298 |
|
17299 | if (map) {
|
17300 | var id = initSegmentId(map);
|
17301 |
|
17302 | if (this.activeInitSegmentId_ === id) {
|
17303 |
|
17304 | return null;
|
17305 | }
|
17306 |
|
17307 |
|
17308 |
|
17309 |
|
17310 |
|
17311 | initSegment = this.initSegmentForMap(map, true).bytes;
|
17312 | this.activeInitSegmentId_ = id;
|
17313 | }
|
17314 |
|
17315 |
|
17316 |
|
17317 |
|
17318 |
|
17319 |
|
17320 | if (initSegment && this.appendInitSegment_[type]) {
|
17321 |
|
17322 |
|
17323 |
|
17324 | this.playlistOfLastInitSegment_[type] = playlist;
|
17325 |
|
17326 | this.appendInitSegment_[type] = false;
|
17327 |
|
17328 |
|
17329 | this.activeInitSegmentId_ = null;
|
17330 | return initSegment;
|
17331 | }
|
17332 |
|
17333 | return null;
|
17334 | };
|
17335 |
|
17336 | _proto.handleQuotaExceededError_ = function handleQuotaExceededError_(_ref5, error) {
|
17337 | var _this3 = this;
|
17338 |
|
17339 | var segmentInfo = _ref5.segmentInfo,
|
17340 | type = _ref5.type,
|
17341 | bytes = _ref5.bytes;
|
17342 | var audioBuffered = this.sourceUpdater_.audioBuffered();
|
17343 | var videoBuffered = this.sourceUpdater_.videoBuffered();
|
17344 |
|
17345 |
|
17346 |
|
17347 | if (audioBuffered.length > 1) {
|
17348 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the audio buffer: ' + timeRangesToArray(audioBuffered).join(', '));
|
17349 | }
|
17350 |
|
17351 | if (videoBuffered.length > 1) {
|
17352 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the video buffer: ' + timeRangesToArray(videoBuffered).join(', '));
|
17353 | }
|
17354 |
|
17355 | var audioBufferStart = audioBuffered.length ? audioBuffered.start(0) : 0;
|
17356 | var audioBufferEnd = audioBuffered.length ? audioBuffered.end(audioBuffered.length - 1) : 0;
|
17357 | var videoBufferStart = videoBuffered.length ? videoBuffered.start(0) : 0;
|
17358 | var videoBufferEnd = videoBuffered.length ? videoBuffered.end(videoBuffered.length - 1) : 0;
|
17359 |
|
17360 | if (audioBufferEnd - audioBufferStart <= MIN_BACK_BUFFER && videoBufferEnd - videoBufferStart <= MIN_BACK_BUFFER) {
|
17361 |
|
17362 |
|
17363 |
|
17364 |
|
17365 | 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(', ') + ", "));
|
17366 | this.error({
|
17367 | message: 'Quota exceeded error with append of a single segment of content',
|
17368 | excludeUntil: Infinity
|
17369 | });
|
17370 | this.trigger('error');
|
17371 | return;
|
17372 | }
|
17373 |
|
17374 |
|
17375 |
|
17376 |
|
17377 |
|
17378 |
|
17379 |
|
17380 |
|
17381 |
|
17382 |
|
17383 |
|
17384 |
|
17385 |
|
17386 | this.waitingOnRemove_ = true;
|
17387 | this.callQueue_.push(this.appendToSourceBuffer_.bind(this, {
|
17388 | segmentInfo: segmentInfo,
|
17389 | type: type,
|
17390 | bytes: bytes
|
17391 | }));
|
17392 | var currentTime = this.currentTime_();
|
17393 |
|
17394 |
|
17395 | var timeToRemoveUntil = currentTime - MIN_BACK_BUFFER;
|
17396 | this.logger_("On QUOTA_EXCEEDED_ERR, removing audio/video from 0 to " + timeToRemoveUntil);
|
17397 | this.remove(0, timeToRemoveUntil, function () {
|
17398 | _this3.logger_("On QUOTA_EXCEEDED_ERR, retrying append in " + MIN_BACK_BUFFER + "s");
|
17399 |
|
17400 | _this3.waitingOnRemove_ = false;
|
17401 |
|
17402 |
|
17403 | _this3.quotaExceededErrorRetryTimeout_ = window__default["default"].setTimeout(function () {
|
17404 | _this3.logger_('On QUOTA_EXCEEDED_ERR, re-processing call queue');
|
17405 |
|
17406 | _this3.quotaExceededErrorRetryTimeout_ = null;
|
17407 |
|
17408 | _this3.processCallQueue_();
|
17409 | }, MIN_BACK_BUFFER * 1000);
|
17410 | }, true);
|
17411 | };
|
17412 |
|
17413 | _proto.handleAppendError_ = function handleAppendError_(_ref6, error) {
|
17414 | var segmentInfo = _ref6.segmentInfo,
|
17415 | type = _ref6.type,
|
17416 | bytes = _ref6.bytes;
|
17417 |
|
17418 |
|
17419 | if (!error) {
|
17420 | return;
|
17421 | }
|
17422 |
|
17423 | if (error.code === QUOTA_EXCEEDED_ERR) {
|
17424 | this.handleQuotaExceededError_({
|
17425 | segmentInfo: segmentInfo,
|
17426 | type: type,
|
17427 | bytes: bytes
|
17428 | });
|
17429 |
|
17430 |
|
17431 | return;
|
17432 | }
|
17433 |
|
17434 | this.logger_('Received non QUOTA_EXCEEDED_ERR on append', error);
|
17435 | this.error(type + " append of " + bytes.length + "b failed for segment " + ("#" + segmentInfo.mediaIndex + " in playlist " + segmentInfo.playlist.id));
|
17436 |
|
17437 |
|
17438 |
|
17439 |
|
17440 |
|
17441 | this.trigger('appenderror');
|
17442 | };
|
17443 |
|
17444 | _proto.appendToSourceBuffer_ = function appendToSourceBuffer_(_ref7) {
|
17445 | var segmentInfo = _ref7.segmentInfo,
|
17446 | type = _ref7.type,
|
17447 | initSegment = _ref7.initSegment,
|
17448 | data = _ref7.data,
|
17449 | bytes = _ref7.bytes;
|
17450 |
|
17451 |
|
17452 | if (!bytes) {
|
17453 | var segments = [data];
|
17454 | var byteLength = data.byteLength;
|
17455 |
|
17456 | if (initSegment) {
|
17457 |
|
17458 |
|
17459 | segments.unshift(initSegment);
|
17460 | byteLength += initSegment.byteLength;
|
17461 | }
|
17462 |
|
17463 |
|
17464 |
|
17465 | bytes = concatSegments({
|
17466 | bytes: byteLength,
|
17467 | segments: segments
|
17468 | });
|
17469 | }
|
17470 |
|
17471 | this.sourceUpdater_.appendBuffer({
|
17472 | segmentInfo: segmentInfo,
|
17473 | type: type,
|
17474 | bytes: bytes
|
17475 | }, this.handleAppendError_.bind(this, {
|
17476 | segmentInfo: segmentInfo,
|
17477 | type: type,
|
17478 | bytes: bytes
|
17479 | }));
|
17480 | };
|
17481 |
|
17482 | _proto.handleSegmentTimingInfo_ = function handleSegmentTimingInfo_(type, requestId, segmentTimingInfo) {
|
17483 | if (!this.pendingSegment_ || requestId !== this.pendingSegment_.requestId) {
|
17484 | return;
|
17485 | }
|
17486 |
|
17487 | var segment = this.pendingSegment_.segment;
|
17488 | var timingInfoProperty = type + "TimingInfo";
|
17489 |
|
17490 | if (!segment[timingInfoProperty]) {
|
17491 | segment[timingInfoProperty] = {};
|
17492 | }
|
17493 |
|
17494 | segment[timingInfoProperty].transmuxerPrependedSeconds = segmentTimingInfo.prependedContentDuration || 0;
|
17495 | segment[timingInfoProperty].transmuxedPresentationStart = segmentTimingInfo.start.presentation;
|
17496 | segment[timingInfoProperty].transmuxedDecodeStart = segmentTimingInfo.start.decode;
|
17497 | segment[timingInfoProperty].transmuxedPresentationEnd = segmentTimingInfo.end.presentation;
|
17498 | segment[timingInfoProperty].transmuxedDecodeEnd = segmentTimingInfo.end.decode;
|
17499 |
|
17500 | segment[timingInfoProperty].baseMediaDecodeTime = segmentTimingInfo.baseMediaDecodeTime;
|
17501 | };
|
17502 |
|
17503 | _proto.appendData_ = function appendData_(segmentInfo, result) {
|
17504 | var type = result.type,
|
17505 | data = result.data;
|
17506 |
|
17507 | if (!data || !data.byteLength) {
|
17508 | return;
|
17509 | }
|
17510 |
|
17511 | if (type === 'audio' && this.audioDisabled_) {
|
17512 | return;
|
17513 | }
|
17514 |
|
17515 | var initSegment = this.getInitSegmentAndUpdateState_({
|
17516 | type: type,
|
17517 | initSegment: result.initSegment,
|
17518 | playlist: segmentInfo.playlist,
|
17519 | map: segmentInfo.isFmp4 ? segmentInfo.segment.map : null
|
17520 | });
|
17521 | this.appendToSourceBuffer_({
|
17522 | segmentInfo: segmentInfo,
|
17523 | type: type,
|
17524 | initSegment: initSegment,
|
17525 | data: data
|
17526 | });
|
17527 | }
|
17528 | |
17529 |
|
17530 |
|
17531 |
|
17532 |
|
17533 | ;
|
17534 |
|
17535 | _proto.loadSegment_ = function loadSegment_(segmentInfo) {
|
17536 | var _this4 = this;
|
17537 |
|
17538 | this.state = 'WAITING';
|
17539 | this.pendingSegment_ = segmentInfo;
|
17540 | this.trimBackBuffer_(segmentInfo);
|
17541 |
|
17542 | if (typeof segmentInfo.timestampOffset === 'number') {
|
17543 | if (this.transmuxer_) {
|
17544 | this.transmuxer_.postMessage({
|
17545 | action: 'clearAllMp4Captions'
|
17546 | });
|
17547 | }
|
17548 | }
|
17549 |
|
17550 | if (!this.hasEnoughInfoToLoad_()) {
|
17551 | this.loadQueue_.push(function () {
|
17552 |
|
17553 |
|
17554 | var options = _extends__default["default"]({}, segmentInfo, {
|
17555 | forceTimestampOffset: true
|
17556 | });
|
17557 |
|
17558 | _extends__default["default"](segmentInfo, _this4.generateSegmentInfo_(options));
|
17559 |
|
17560 | _this4.isPendingTimestampOffset_ = false;
|
17561 |
|
17562 | _this4.updateTransmuxerAndRequestSegment_(segmentInfo);
|
17563 | });
|
17564 | return;
|
17565 | }
|
17566 |
|
17567 | this.updateTransmuxerAndRequestSegment_(segmentInfo);
|
17568 | };
|
17569 |
|
17570 | _proto.updateTransmuxerAndRequestSegment_ = function updateTransmuxerAndRequestSegment_(segmentInfo) {
|
17571 | var _this5 = this;
|
17572 |
|
17573 |
|
17574 |
|
17575 |
|
17576 |
|
17577 |
|
17578 | if (this.shouldUpdateTransmuxerTimestampOffset_(segmentInfo.timestampOffset)) {
|
17579 | this.gopBuffer_.length = 0;
|
17580 |
|
17581 | segmentInfo.gopsToAlignWith = [];
|
17582 | this.timeMapping_ = 0;
|
17583 |
|
17584 | this.transmuxer_.postMessage({
|
17585 | action: 'reset'
|
17586 | });
|
17587 | this.transmuxer_.postMessage({
|
17588 | action: 'setTimestampOffset',
|
17589 | timestampOffset: segmentInfo.timestampOffset
|
17590 | });
|
17591 | }
|
17592 |
|
17593 | var simpleSegment = this.createSimplifiedSegmentObj_(segmentInfo);
|
17594 | var isEndOfStream = this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex);
|
17595 | var isWalkingForward = this.mediaIndex !== null;
|
17596 | var isDiscontinuity = segmentInfo.timeline !== this.currentTimeline_ &&
|
17597 |
|
17598 | segmentInfo.timeline > 0;
|
17599 | var isEndOfTimeline = isEndOfStream || isWalkingForward && isDiscontinuity;
|
17600 | this.logger_("Requesting " + segmentInfoString(segmentInfo));
|
17601 |
|
17602 |
|
17603 |
|
17604 |
|
17605 |
|
17606 | if (simpleSegment.map && !simpleSegment.map.bytes) {
|
17607 | this.logger_('going to request init segment.');
|
17608 | this.appendInitSegment_ = {
|
17609 | video: true,
|
17610 | audio: true
|
17611 | };
|
17612 | }
|
17613 |
|
17614 | segmentInfo.abortRequests = mediaSegmentRequest({
|
17615 | xhr: this.vhs_.xhr,
|
17616 | xhrOptions: this.xhrOptions_,
|
17617 | decryptionWorker: this.decrypter_,
|
17618 | segment: simpleSegment,
|
17619 | abortFn: this.handleAbort_.bind(this, segmentInfo),
|
17620 | progressFn: this.handleProgress_.bind(this),
|
17621 | trackInfoFn: this.handleTrackInfo_.bind(this),
|
17622 | timingInfoFn: this.handleTimingInfo_.bind(this),
|
17623 | videoSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'video', segmentInfo.requestId),
|
17624 | audioSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'audio', segmentInfo.requestId),
|
17625 | captionsFn: this.handleCaptions_.bind(this),
|
17626 | isEndOfTimeline: isEndOfTimeline,
|
17627 | endedTimelineFn: function endedTimelineFn() {
|
17628 | _this5.logger_('received endedtimeline callback');
|
17629 | },
|
17630 | id3Fn: this.handleId3_.bind(this),
|
17631 | dataFn: this.handleData_.bind(this),
|
17632 | doneFn: this.segmentRequestFinished_.bind(this),
|
17633 | onTransmuxerLog: function onTransmuxerLog(_ref8) {
|
17634 | var message = _ref8.message,
|
17635 | level = _ref8.level,
|
17636 | stream = _ref8.stream;
|
17637 |
|
17638 | _this5.logger_(segmentInfoString(segmentInfo) + " logged from transmuxer stream " + stream + " as a " + level + ": " + message);
|
17639 | }
|
17640 | });
|
17641 | }
|
17642 | |
17643 |
|
17644 |
|
17645 |
|
17646 |
|
17647 |
|
17648 |
|
17649 |
|
17650 | ;
|
17651 |
|
17652 | _proto.trimBackBuffer_ = function trimBackBuffer_(segmentInfo) {
|
17653 | var removeToTime = safeBackBufferTrimTime(this.seekable_(), this.currentTime_(), this.playlist_.targetDuration || 10);
|
17654 |
|
17655 |
|
17656 |
|
17657 |
|
17658 |
|
17659 | if (removeToTime > 0) {
|
17660 | this.remove(0, removeToTime);
|
17661 | }
|
17662 | }
|
17663 | |
17664 |
|
17665 |
|
17666 |
|
17667 |
|
17668 |
|
17669 |
|
17670 |
|
17671 |
|
17672 | ;
|
17673 |
|
17674 | _proto.createSimplifiedSegmentObj_ = function createSimplifiedSegmentObj_(segmentInfo) {
|
17675 | var segment = segmentInfo.segment;
|
17676 | var part = segmentInfo.part;
|
17677 | var simpleSegment = {
|
17678 | resolvedUri: part ? part.resolvedUri : segment.resolvedUri,
|
17679 | byterange: part ? part.byterange : segment.byterange,
|
17680 | requestId: segmentInfo.requestId,
|
17681 | transmuxer: segmentInfo.transmuxer,
|
17682 | audioAppendStart: segmentInfo.audioAppendStart,
|
17683 | gopsToAlignWith: segmentInfo.gopsToAlignWith,
|
17684 | part: segmentInfo.part
|
17685 | };
|
17686 | var previousSegment = segmentInfo.playlist.segments[segmentInfo.mediaIndex - 1];
|
17687 |
|
17688 | if (previousSegment && previousSegment.timeline === segment.timeline) {
|
17689 |
|
17690 |
|
17691 |
|
17692 |
|
17693 |
|
17694 |
|
17695 |
|
17696 |
|
17697 | if (previousSegment.videoTimingInfo) {
|
17698 | simpleSegment.baseStartTime = previousSegment.videoTimingInfo.transmuxedDecodeEnd;
|
17699 | } else if (previousSegment.audioTimingInfo) {
|
17700 | simpleSegment.baseStartTime = previousSegment.audioTimingInfo.transmuxedDecodeEnd;
|
17701 | }
|
17702 | }
|
17703 |
|
17704 | if (segment.key) {
|
17705 |
|
17706 |
|
17707 | var iv = segment.key.iv || new Uint32Array([0, 0, 0, segmentInfo.mediaIndex + segmentInfo.playlist.mediaSequence]);
|
17708 | simpleSegment.key = this.segmentKey(segment.key);
|
17709 | simpleSegment.key.iv = iv;
|
17710 | }
|
17711 |
|
17712 | if (segment.map) {
|
17713 | simpleSegment.map = this.initSegmentForMap(segment.map);
|
17714 | }
|
17715 |
|
17716 | return simpleSegment;
|
17717 | };
|
17718 |
|
17719 | _proto.saveTransferStats_ = function saveTransferStats_(stats) {
|
17720 |
|
17721 |
|
17722 | this.mediaRequests += 1;
|
17723 |
|
17724 | if (stats) {
|
17725 | this.mediaBytesTransferred += stats.bytesReceived;
|
17726 | this.mediaTransferDuration += stats.roundTripTime;
|
17727 | }
|
17728 | };
|
17729 |
|
17730 | _proto.saveBandwidthRelatedStats_ = function saveBandwidthRelatedStats_(duration, stats) {
|
17731 |
|
17732 |
|
17733 |
|
17734 | this.pendingSegment_.byteLength = stats.bytesReceived;
|
17735 |
|
17736 | if (duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
17737 | this.logger_("Ignoring segment's bandwidth because its duration of " + duration + (" is less than the min to record " + MIN_SEGMENT_DURATION_TO_SAVE_STATS));
|
17738 | return;
|
17739 | }
|
17740 |
|
17741 | this.bandwidth = stats.bandwidth;
|
17742 | this.roundTrip = stats.roundTripTime;
|
17743 | };
|
17744 |
|
17745 | _proto.handleTimeout_ = function handleTimeout_() {
|
17746 |
|
17747 |
|
17748 | this.mediaRequestsTimedout += 1;
|
17749 | this.bandwidth = 1;
|
17750 | this.roundTrip = NaN;
|
17751 | this.trigger('bandwidthupdate');
|
17752 | }
|
17753 | |
17754 |
|
17755 |
|
17756 |
|
17757 |
|
17758 |
|
17759 | ;
|
17760 |
|
17761 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
17762 |
|
17763 |
|
17764 |
|
17765 |
|
17766 | if (this.callQueue_.length) {
|
17767 | this.callQueue_.push(this.segmentRequestFinished_.bind(this, error, simpleSegment, result));
|
17768 | return;
|
17769 | }
|
17770 |
|
17771 | this.saveTransferStats_(simpleSegment.stats);
|
17772 |
|
17773 | if (!this.pendingSegment_) {
|
17774 | return;
|
17775 | }
|
17776 |
|
17777 |
|
17778 |
|
17779 |
|
17780 |
|
17781 | if (simpleSegment.requestId !== this.pendingSegment_.requestId) {
|
17782 | return;
|
17783 | }
|
17784 |
|
17785 |
|
17786 | if (error) {
|
17787 | this.pendingSegment_ = null;
|
17788 | this.state = 'READY';
|
17789 |
|
17790 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
17791 | return;
|
17792 | }
|
17793 |
|
17794 | this.pause();
|
17795 |
|
17796 |
|
17797 |
|
17798 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
17799 | this.handleTimeout_();
|
17800 | return;
|
17801 | }
|
17802 |
|
17803 |
|
17804 |
|
17805 | this.mediaRequestsErrored += 1;
|
17806 | this.error(error);
|
17807 | this.trigger('error');
|
17808 | return;
|
17809 | }
|
17810 |
|
17811 | var segmentInfo = this.pendingSegment_;
|
17812 |
|
17813 |
|
17814 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
17815 | segmentInfo.endOfAllRequests = simpleSegment.endOfAllRequests;
|
17816 |
|
17817 | if (result.gopInfo) {
|
17818 | this.gopBuffer_ = updateGopBuffer(this.gopBuffer_, result.gopInfo, this.safeAppend_);
|
17819 | }
|
17820 |
|
17821 |
|
17822 |
|
17823 | this.state = 'APPENDING';
|
17824 |
|
17825 | this.trigger('appending');
|
17826 | this.waitForAppendsToComplete_(segmentInfo);
|
17827 | };
|
17828 |
|
17829 | _proto.setTimeMapping_ = function setTimeMapping_(timeline) {
|
17830 | var timelineMapping = this.syncController_.mappingForTimeline(timeline);
|
17831 |
|
17832 | if (timelineMapping !== null) {
|
17833 | this.timeMapping_ = timelineMapping;
|
17834 | }
|
17835 | };
|
17836 |
|
17837 | _proto.updateMediaSecondsLoaded_ = function updateMediaSecondsLoaded_(segment) {
|
17838 | if (typeof segment.start === 'number' && typeof segment.end === 'number') {
|
17839 | this.mediaSecondsLoaded += segment.end - segment.start;
|
17840 | } else {
|
17841 | this.mediaSecondsLoaded += segment.duration;
|
17842 | }
|
17843 | };
|
17844 |
|
17845 | _proto.shouldUpdateTransmuxerTimestampOffset_ = function shouldUpdateTransmuxerTimestampOffset_(timestampOffset) {
|
17846 | if (timestampOffset === null) {
|
17847 | return false;
|
17848 | }
|
17849 |
|
17850 |
|
17851 |
|
17852 | if (this.loaderType_ === 'main' && timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
17853 | return true;
|
17854 | }
|
17855 |
|
17856 | if (!this.audioDisabled_ && timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
17857 | return true;
|
17858 | }
|
17859 |
|
17860 | return false;
|
17861 | };
|
17862 |
|
17863 | _proto.trueSegmentStart_ = function trueSegmentStart_(_ref9) {
|
17864 | var currentStart = _ref9.currentStart,
|
17865 | playlist = _ref9.playlist,
|
17866 | mediaIndex = _ref9.mediaIndex,
|
17867 | firstVideoFrameTimeForData = _ref9.firstVideoFrameTimeForData,
|
17868 | currentVideoTimestampOffset = _ref9.currentVideoTimestampOffset,
|
17869 | useVideoTimingInfo = _ref9.useVideoTimingInfo,
|
17870 | videoTimingInfo = _ref9.videoTimingInfo,
|
17871 | audioTimingInfo = _ref9.audioTimingInfo;
|
17872 |
|
17873 | if (typeof currentStart !== 'undefined') {
|
17874 |
|
17875 | return currentStart;
|
17876 | }
|
17877 |
|
17878 | if (!useVideoTimingInfo) {
|
17879 | return audioTimingInfo.start;
|
17880 | }
|
17881 |
|
17882 | var previousSegment = playlist.segments[mediaIndex - 1];
|
17883 |
|
17884 |
|
17885 |
|
17886 |
|
17887 |
|
17888 | if (mediaIndex === 0 || !previousSegment || typeof previousSegment.start === 'undefined' || previousSegment.end !== firstVideoFrameTimeForData + currentVideoTimestampOffset) {
|
17889 | return firstVideoFrameTimeForData;
|
17890 | }
|
17891 |
|
17892 | return videoTimingInfo.start;
|
17893 | };
|
17894 |
|
17895 | _proto.waitForAppendsToComplete_ = function waitForAppendsToComplete_(segmentInfo) {
|
17896 | var trackInfo = this.getCurrentMediaInfo_(segmentInfo);
|
17897 |
|
17898 | if (!trackInfo) {
|
17899 | this.error({
|
17900 | message: 'No starting media returned, likely due to an unsupported media format.',
|
17901 | blacklistDuration: Infinity
|
17902 | });
|
17903 | this.trigger('error');
|
17904 | return;
|
17905 | }
|
17906 |
|
17907 |
|
17908 |
|
17909 |
|
17910 | var hasAudio = trackInfo.hasAudio,
|
17911 | hasVideo = trackInfo.hasVideo,
|
17912 | isMuxed = trackInfo.isMuxed;
|
17913 | var waitForVideo = this.loaderType_ === 'main' && hasVideo;
|
17914 | var waitForAudio = !this.audioDisabled_ && hasAudio && !isMuxed;
|
17915 | segmentInfo.waitingOnAppends = 0;
|
17916 |
|
17917 | if (!segmentInfo.hasAppendedData_) {
|
17918 | if (!segmentInfo.timingInfo && typeof segmentInfo.timestampOffset === 'number') {
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 |
|
17926 |
|
17927 | this.isPendingTimestampOffset_ = true;
|
17928 | }
|
17929 |
|
17930 |
|
17931 | segmentInfo.timingInfo = {
|
17932 | start: 0
|
17933 | };
|
17934 | segmentInfo.waitingOnAppends++;
|
17935 |
|
17936 | if (!this.isPendingTimestampOffset_) {
|
17937 |
|
17938 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
17939 |
|
17940 |
|
17941 | this.processMetadataQueue_();
|
17942 | }
|
17943 |
|
17944 |
|
17945 | this.checkAppendsDone_(segmentInfo);
|
17946 | return;
|
17947 | }
|
17948 |
|
17949 |
|
17950 | if (waitForVideo) {
|
17951 | segmentInfo.waitingOnAppends++;
|
17952 | }
|
17953 |
|
17954 | if (waitForAudio) {
|
17955 | segmentInfo.waitingOnAppends++;
|
17956 | }
|
17957 |
|
17958 | if (waitForVideo) {
|
17959 | this.sourceUpdater_.videoQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
17960 | }
|
17961 |
|
17962 | if (waitForAudio) {
|
17963 | this.sourceUpdater_.audioQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
17964 | }
|
17965 | };
|
17966 |
|
17967 | _proto.checkAppendsDone_ = function checkAppendsDone_(segmentInfo) {
|
17968 | if (this.checkForAbort_(segmentInfo.requestId)) {
|
17969 | return;
|
17970 | }
|
17971 |
|
17972 | segmentInfo.waitingOnAppends--;
|
17973 |
|
17974 | if (segmentInfo.waitingOnAppends === 0) {
|
17975 | this.handleAppendsDone_();
|
17976 | }
|
17977 | };
|
17978 |
|
17979 | _proto.checkForIllegalMediaSwitch = function checkForIllegalMediaSwitch(trackInfo) {
|
17980 | var illegalMediaSwitchError = illegalMediaSwitch(this.loaderType_, this.getCurrentMediaInfo_(), trackInfo);
|
17981 |
|
17982 | if (illegalMediaSwitchError) {
|
17983 | this.error({
|
17984 | message: illegalMediaSwitchError,
|
17985 | blacklistDuration: Infinity
|
17986 | });
|
17987 | this.trigger('error');
|
17988 | return true;
|
17989 | }
|
17990 |
|
17991 | return false;
|
17992 | };
|
17993 |
|
17994 | _proto.updateSourceBufferTimestampOffset_ = function updateSourceBufferTimestampOffset_(segmentInfo) {
|
17995 | if (segmentInfo.timestampOffset === null ||
|
17996 |
|
17997 | typeof segmentInfo.timingInfo.start !== 'number' ||
|
17998 | segmentInfo.changedTimestampOffset ||
|
17999 | this.loaderType_ !== 'main') {
|
18000 | return;
|
18001 | }
|
18002 |
|
18003 | var didChange = false;
|
18004 |
|
18005 |
|
18006 |
|
18007 |
|
18008 | segmentInfo.timestampOffset -= segmentInfo.timingInfo.start;
|
18009 |
|
18010 |
|
18011 |
|
18012 | segmentInfo.changedTimestampOffset = true;
|
18013 |
|
18014 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
18015 | this.sourceUpdater_.videoTimestampOffset(segmentInfo.timestampOffset);
|
18016 | didChange = true;
|
18017 | }
|
18018 |
|
18019 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
18020 | this.sourceUpdater_.audioTimestampOffset(segmentInfo.timestampOffset);
|
18021 | didChange = true;
|
18022 | }
|
18023 |
|
18024 | if (didChange) {
|
18025 | this.trigger('timestampoffset');
|
18026 | }
|
18027 | };
|
18028 |
|
18029 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_(segmentInfo) {
|
18030 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
18031 | var trackInfo = this.getMediaInfo_();
|
18032 | var useVideoTimingInfo = this.loaderType_ === 'main' && trackInfo && trackInfo.hasVideo;
|
18033 | var prioritizedTimingInfo = useVideoTimingInfo && segmentInfo.videoTimingInfo ? segmentInfo.videoTimingInfo : segmentInfo.audioTimingInfo;
|
18034 |
|
18035 | if (!prioritizedTimingInfo) {
|
18036 | return;
|
18037 | }
|
18038 |
|
18039 | segmentInfo.timingInfo.end = typeof prioritizedTimingInfo.end === 'number' ?
|
18040 |
|
18041 |
|
18042 | prioritizedTimingInfo.end : prioritizedTimingInfo.start + segmentInfo.duration;
|
18043 | }
|
18044 | |
18045 |
|
18046 |
|
18047 |
|
18048 |
|
18049 |
|
18050 |
|
18051 | ;
|
18052 |
|
18053 | _proto.handleAppendsDone_ = function handleAppendsDone_() {
|
18054 |
|
18055 | if (this.pendingSegment_) {
|
18056 | this.trigger('appendsdone');
|
18057 | }
|
18058 |
|
18059 | if (!this.pendingSegment_) {
|
18060 | this.state = 'READY';
|
18061 |
|
18062 |
|
18063 | if (!this.paused()) {
|
18064 | this.monitorBuffer_();
|
18065 | }
|
18066 |
|
18067 | return;
|
18068 | }
|
18069 |
|
18070 | var segmentInfo = this.pendingSegment_;
|
18071 |
|
18072 |
|
18073 |
|
18074 | this.updateTimingInfoEnd_(segmentInfo);
|
18075 |
|
18076 | if (this.shouldSaveSegmentTimingInfo_) {
|
18077 |
|
18078 |
|
18079 |
|
18080 |
|
18081 |
|
18082 |
|
18083 |
|
18084 |
|
18085 |
|
18086 |
|
18087 |
|
18088 |
|
18089 |
|
18090 |
|
18091 |
|
18092 |
|
18093 |
|
18094 | this.syncController_.saveSegmentTimingInfo({
|
18095 | segmentInfo: segmentInfo,
|
18096 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
18097 | });
|
18098 | }
|
18099 |
|
18100 | var segmentDurationMessage = getTroublesomeSegmentDurationMessage(segmentInfo, this.sourceType_);
|
18101 |
|
18102 | if (segmentDurationMessage) {
|
18103 | if (segmentDurationMessage.severity === 'warn') {
|
18104 | videojs__default["default"].log.warn(segmentDurationMessage.message);
|
18105 | } else {
|
18106 | this.logger_(segmentDurationMessage.message);
|
18107 | }
|
18108 | }
|
18109 |
|
18110 | this.recordThroughput_(segmentInfo);
|
18111 | this.pendingSegment_ = null;
|
18112 | this.state = 'READY';
|
18113 |
|
18114 | if (segmentInfo.isSyncRequest) {
|
18115 | this.trigger('syncinfoupdate');
|
18116 |
|
18117 |
|
18118 |
|
18119 |
|
18120 | if (!segmentInfo.hasAppendedData_) {
|
18121 | this.logger_("Throwing away un-appended sync request " + segmentInfoString(segmentInfo));
|
18122 | return;
|
18123 | }
|
18124 | }
|
18125 |
|
18126 | this.logger_("Appended " + segmentInfoString(segmentInfo));
|
18127 | this.addSegmentMetadataCue_(segmentInfo);
|
18128 | this.fetchAtBuffer_ = true;
|
18129 |
|
18130 | if (this.currentTimeline_ !== segmentInfo.timeline) {
|
18131 | this.timelineChangeController_.lastTimelineChange({
|
18132 | type: this.loaderType_,
|
18133 | from: this.currentTimeline_,
|
18134 | to: segmentInfo.timeline
|
18135 | });
|
18136 |
|
18137 |
|
18138 |
|
18139 | if (this.loaderType_ === 'main' && !this.audioDisabled_) {
|
18140 | this.timelineChangeController_.lastTimelineChange({
|
18141 | type: 'audio',
|
18142 | from: this.currentTimeline_,
|
18143 | to: segmentInfo.timeline
|
18144 | });
|
18145 | }
|
18146 | }
|
18147 |
|
18148 | this.currentTimeline_ = segmentInfo.timeline;
|
18149 |
|
18150 |
|
18151 |
|
18152 |
|
18153 | this.trigger('syncinfoupdate');
|
18154 | var segment = segmentInfo.segment;
|
18155 |
|
18156 |
|
18157 |
|
18158 |
|
18159 | if (segment.end && this.currentTime_() - segment.end > segmentInfo.playlist.targetDuration * 3) {
|
18160 | this.resetEverything();
|
18161 | return;
|
18162 | }
|
18163 |
|
18164 | var isWalkingForward = this.mediaIndex !== null;
|
18165 |
|
18166 |
|
18167 | if (isWalkingForward) {
|
18168 | this.trigger('bandwidthupdate');
|
18169 | }
|
18170 |
|
18171 | this.trigger('progress');
|
18172 | this.mediaIndex = segmentInfo.mediaIndex;
|
18173 | this.partIndex = segmentInfo.partIndex;
|
18174 |
|
18175 |
|
18176 |
|
18177 | if (this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex)) {
|
18178 | this.endOfStream();
|
18179 | }
|
18180 |
|
18181 |
|
18182 | this.trigger('appended');
|
18183 |
|
18184 | if (segmentInfo.hasAppendedData_) {
|
18185 | this.mediaAppends++;
|
18186 | }
|
18187 |
|
18188 | if (!this.paused()) {
|
18189 | this.monitorBuffer_();
|
18190 | }
|
18191 | }
|
18192 | |
18193 |
|
18194 |
|
18195 |
|
18196 |
|
18197 |
|
18198 |
|
18199 |
|
18200 |
|
18201 | ;
|
18202 |
|
18203 | _proto.recordThroughput_ = function recordThroughput_(segmentInfo) {
|
18204 | if (segmentInfo.duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
18205 | 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));
|
18206 | return;
|
18207 | }
|
18208 |
|
18209 | var rate = this.throughput.rate;
|
18210 |
|
18211 |
|
18212 | var segmentProcessingTime = Date.now() - segmentInfo.endOfAllRequests + 1;
|
18213 |
|
18214 | var segmentProcessingThroughput = Math.floor(segmentInfo.byteLength / segmentProcessingTime * 8 * 1000);
|
18215 |
|
18216 |
|
18217 | this.throughput.rate += (segmentProcessingThroughput - rate) / ++this.throughput.count;
|
18218 | }
|
18219 | |
18220 |
|
18221 |
|
18222 |
|
18223 |
|
18224 |
|
18225 |
|
18226 |
|
18227 |
|
18228 | ;
|
18229 |
|
18230 | _proto.addSegmentMetadataCue_ = function addSegmentMetadataCue_(segmentInfo) {
|
18231 | if (!this.segmentMetadataTrack_) {
|
18232 | return;
|
18233 | }
|
18234 |
|
18235 | var segment = segmentInfo.segment;
|
18236 | var start = segment.start;
|
18237 | var end = segment.end;
|
18238 |
|
18239 | if (!finite(start) || !finite(end)) {
|
18240 | return;
|
18241 | }
|
18242 |
|
18243 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
18244 | var Cue = window__default["default"].WebKitDataCue || window__default["default"].VTTCue;
|
18245 | var value = {
|
18246 | custom: segment.custom,
|
18247 | dateTimeObject: segment.dateTimeObject,
|
18248 | dateTimeString: segment.dateTimeString,
|
18249 | bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
|
18250 | resolution: segmentInfo.playlist.attributes.RESOLUTION,
|
18251 | codecs: segmentInfo.playlist.attributes.CODECS,
|
18252 | byteLength: segmentInfo.byteLength,
|
18253 | uri: segmentInfo.uri,
|
18254 | timeline: segmentInfo.timeline,
|
18255 | playlist: segmentInfo.playlist.id,
|
18256 | start: start,
|
18257 | end: end
|
18258 | };
|
18259 | var data = JSON.stringify(value);
|
18260 | var cue = new Cue(start, end, data);
|
18261 |
|
18262 |
|
18263 | cue.value = value;
|
18264 | this.segmentMetadataTrack_.addCue(cue);
|
18265 | };
|
18266 |
|
18267 | return SegmentLoader;
|
18268 | }(videojs__default["default"].EventTarget);
|
18269 |
|
18270 | function noop() {}
|
18271 |
|
18272 | var toTitleCase = function toTitleCase(string) {
|
18273 | if (typeof string !== 'string') {
|
18274 | return string;
|
18275 | }
|
18276 |
|
18277 | return string.replace(/./, function (w) {
|
18278 | return w.toUpperCase();
|
18279 | });
|
18280 | };
|
18281 |
|
18282 | var bufferTypes = ['video', 'audio'];
|
18283 |
|
18284 | var _updating = function updating(type, sourceUpdater) {
|
18285 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18286 | return sourceBuffer && sourceBuffer.updating || sourceUpdater.queuePending[type];
|
18287 | };
|
18288 |
|
18289 | var nextQueueIndexOfType = function nextQueueIndexOfType(type, queue) {
|
18290 | for (var i = 0; i < queue.length; i++) {
|
18291 | var queueEntry = queue[i];
|
18292 |
|
18293 | if (queueEntry.type === 'mediaSource') {
|
18294 |
|
18295 |
|
18296 | return null;
|
18297 | }
|
18298 |
|
18299 | if (queueEntry.type === type) {
|
18300 | return i;
|
18301 | }
|
18302 | }
|
18303 |
|
18304 | return null;
|
18305 | };
|
18306 |
|
18307 | var shiftQueue = function shiftQueue(type, sourceUpdater) {
|
18308 | if (sourceUpdater.queue.length === 0) {
|
18309 | return;
|
18310 | }
|
18311 |
|
18312 | var queueIndex = 0;
|
18313 | var queueEntry = sourceUpdater.queue[queueIndex];
|
18314 |
|
18315 | if (queueEntry.type === 'mediaSource') {
|
18316 | if (!sourceUpdater.updating() && sourceUpdater.mediaSource.readyState !== 'closed') {
|
18317 | sourceUpdater.queue.shift();
|
18318 | queueEntry.action(sourceUpdater);
|
18319 |
|
18320 | if (queueEntry.doneFn) {
|
18321 | queueEntry.doneFn();
|
18322 | }
|
18323 |
|
18324 |
|
18325 |
|
18326 |
|
18327 | shiftQueue('audio', sourceUpdater);
|
18328 | shiftQueue('video', sourceUpdater);
|
18329 | }
|
18330 |
|
18331 |
|
18332 |
|
18333 |
|
18334 | return;
|
18335 | }
|
18336 |
|
18337 | if (type === 'mediaSource') {
|
18338 |
|
18339 |
|
18340 |
|
18341 |
|
18342 | return;
|
18343 | }
|
18344 |
|
18345 |
|
18346 |
|
18347 |
|
18348 | if (!sourceUpdater.ready() || sourceUpdater.mediaSource.readyState === 'closed' || _updating(type, sourceUpdater)) {
|
18349 | return;
|
18350 | }
|
18351 |
|
18352 | if (queueEntry.type !== type) {
|
18353 | queueIndex = nextQueueIndexOfType(type, sourceUpdater.queue);
|
18354 |
|
18355 | if (queueIndex === null) {
|
18356 |
|
18357 |
|
18358 |
|
18359 | return;
|
18360 | }
|
18361 |
|
18362 | queueEntry = sourceUpdater.queue[queueIndex];
|
18363 | }
|
18364 |
|
18365 | sourceUpdater.queue.splice(queueIndex, 1);
|
18366 |
|
18367 |
|
18368 |
|
18369 |
|
18370 |
|
18371 |
|
18372 |
|
18373 | sourceUpdater.queuePending[type] = queueEntry;
|
18374 | queueEntry.action(type, sourceUpdater);
|
18375 |
|
18376 | if (!queueEntry.doneFn) {
|
18377 |
|
18378 | sourceUpdater.queuePending[type] = null;
|
18379 | shiftQueue(type, sourceUpdater);
|
18380 | return;
|
18381 | }
|
18382 | };
|
18383 |
|
18384 | var cleanupBuffer = function cleanupBuffer(type, sourceUpdater) {
|
18385 | var buffer = sourceUpdater[type + "Buffer"];
|
18386 | var titleType = toTitleCase(type);
|
18387 |
|
18388 | if (!buffer) {
|
18389 | return;
|
18390 | }
|
18391 |
|
18392 | buffer.removeEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
18393 | buffer.removeEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
18394 | sourceUpdater.codecs[type] = null;
|
18395 | sourceUpdater[type + "Buffer"] = null;
|
18396 | };
|
18397 |
|
18398 | var inSourceBuffers = function inSourceBuffers(mediaSource, sourceBuffer) {
|
18399 | return mediaSource && sourceBuffer && Array.prototype.indexOf.call(mediaSource.sourceBuffers, sourceBuffer) !== -1;
|
18400 | };
|
18401 |
|
18402 | var actions = {
|
18403 | appendBuffer: function appendBuffer(bytes, segmentInfo, onError) {
|
18404 | return function (type, sourceUpdater) {
|
18405 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18406 |
|
18407 |
|
18408 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18409 | return;
|
18410 | }
|
18411 |
|
18412 | sourceUpdater.logger_("Appending segment " + segmentInfo.mediaIndex + "'s " + bytes.length + " bytes to " + type + "Buffer");
|
18413 |
|
18414 | try {
|
18415 | sourceBuffer.appendBuffer(bytes);
|
18416 | } catch (e) {
|
18417 | sourceUpdater.logger_("Error with code " + e.code + " " + (e.code === QUOTA_EXCEEDED_ERR ? '(QUOTA_EXCEEDED_ERR) ' : '') + ("when appending segment " + segmentInfo.mediaIndex + " to " + type + "Buffer"));
|
18418 | sourceUpdater.queuePending[type] = null;
|
18419 | onError(e);
|
18420 | }
|
18421 | };
|
18422 | },
|
18423 | remove: function remove(start, end) {
|
18424 | return function (type, sourceUpdater) {
|
18425 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18426 |
|
18427 |
|
18428 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18429 | return;
|
18430 | }
|
18431 |
|
18432 | sourceUpdater.logger_("Removing " + start + " to " + end + " from " + type + "Buffer");
|
18433 |
|
18434 | try {
|
18435 | sourceBuffer.remove(start, end);
|
18436 | } catch (e) {
|
18437 | sourceUpdater.logger_("Remove " + start + " to " + end + " from " + type + "Buffer failed");
|
18438 | }
|
18439 | };
|
18440 | },
|
18441 | timestampOffset: function timestampOffset(offset) {
|
18442 | return function (type, sourceUpdater) {
|
18443 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18444 |
|
18445 |
|
18446 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18447 | return;
|
18448 | }
|
18449 |
|
18450 | sourceUpdater.logger_("Setting " + type + "timestampOffset to " + offset);
|
18451 | sourceBuffer.timestampOffset = offset;
|
18452 | };
|
18453 | },
|
18454 | callback: function callback(_callback) {
|
18455 | return function (type, sourceUpdater) {
|
18456 | _callback();
|
18457 | };
|
18458 | },
|
18459 | endOfStream: function endOfStream(error) {
|
18460 | return function (sourceUpdater) {
|
18461 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
18462 | return;
|
18463 | }
|
18464 |
|
18465 | sourceUpdater.logger_("Calling mediaSource endOfStream(" + (error || '') + ")");
|
18466 |
|
18467 | try {
|
18468 | sourceUpdater.mediaSource.endOfStream(error);
|
18469 | } catch (e) {
|
18470 | videojs__default["default"].log.warn('Failed to call media source endOfStream', e);
|
18471 | }
|
18472 | };
|
18473 | },
|
18474 | duration: function duration(_duration) {
|
18475 | return function (sourceUpdater) {
|
18476 | sourceUpdater.logger_("Setting mediaSource duration to " + _duration);
|
18477 |
|
18478 | try {
|
18479 | sourceUpdater.mediaSource.duration = _duration;
|
18480 | } catch (e) {
|
18481 | videojs__default["default"].log.warn('Failed to set media source duration', e);
|
18482 | }
|
18483 | };
|
18484 | },
|
18485 | abort: function abort() {
|
18486 | return function (type, sourceUpdater) {
|
18487 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
18488 | return;
|
18489 | }
|
18490 |
|
18491 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18492 |
|
18493 |
|
18494 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18495 | return;
|
18496 | }
|
18497 |
|
18498 | sourceUpdater.logger_("calling abort on " + type + "Buffer");
|
18499 |
|
18500 | try {
|
18501 | sourceBuffer.abort();
|
18502 | } catch (e) {
|
18503 | videojs__default["default"].log.warn("Failed to abort on " + type + "Buffer", e);
|
18504 | }
|
18505 | };
|
18506 | },
|
18507 | addSourceBuffer: function addSourceBuffer(type, codec) {
|
18508 | return function (sourceUpdater) {
|
18509 | var titleType = toTitleCase(type);
|
18510 | var mime = codecs_js.getMimeForCodec(codec);
|
18511 | sourceUpdater.logger_("Adding " + type + "Buffer with codec " + codec + " to mediaSource");
|
18512 | var sourceBuffer = sourceUpdater.mediaSource.addSourceBuffer(mime);
|
18513 | sourceBuffer.addEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
18514 | sourceBuffer.addEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
18515 | sourceUpdater.codecs[type] = codec;
|
18516 | sourceUpdater[type + "Buffer"] = sourceBuffer;
|
18517 | };
|
18518 | },
|
18519 | removeSourceBuffer: function removeSourceBuffer(type) {
|
18520 | return function (sourceUpdater) {
|
18521 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18522 | cleanupBuffer(type, sourceUpdater);
|
18523 |
|
18524 |
|
18525 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18526 | return;
|
18527 | }
|
18528 |
|
18529 | sourceUpdater.logger_("Removing " + type + "Buffer with codec " + sourceUpdater.codecs[type] + " from mediaSource");
|
18530 |
|
18531 | try {
|
18532 | sourceUpdater.mediaSource.removeSourceBuffer(sourceBuffer);
|
18533 | } catch (e) {
|
18534 | videojs__default["default"].log.warn("Failed to removeSourceBuffer " + type + "Buffer", e);
|
18535 | }
|
18536 | };
|
18537 | },
|
18538 | changeType: function changeType(codec) {
|
18539 | return function (type, sourceUpdater) {
|
18540 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
18541 | var mime = codecs_js.getMimeForCodec(codec);
|
18542 |
|
18543 |
|
18544 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
18545 | return;
|
18546 | }
|
18547 |
|
18548 |
|
18549 | if (sourceUpdater.codecs[type] === codec) {
|
18550 | return;
|
18551 | }
|
18552 |
|
18553 | sourceUpdater.logger_("changing " + type + "Buffer codec from " + sourceUpdater.codecs[type] + " to " + codec);
|
18554 | sourceBuffer.changeType(mime);
|
18555 | sourceUpdater.codecs[type] = codec;
|
18556 | };
|
18557 | }
|
18558 | };
|
18559 |
|
18560 | var pushQueue = function pushQueue(_ref) {
|
18561 | var type = _ref.type,
|
18562 | sourceUpdater = _ref.sourceUpdater,
|
18563 | action = _ref.action,
|
18564 | doneFn = _ref.doneFn,
|
18565 | name = _ref.name;
|
18566 | sourceUpdater.queue.push({
|
18567 | type: type,
|
18568 | action: action,
|
18569 | doneFn: doneFn,
|
18570 | name: name
|
18571 | });
|
18572 | shiftQueue(type, sourceUpdater);
|
18573 | };
|
18574 |
|
18575 | var onUpdateend = function onUpdateend(type, sourceUpdater) {
|
18576 | return function (e) {
|
18577 |
|
18578 |
|
18579 |
|
18580 |
|
18581 |
|
18582 |
|
18583 | if (sourceUpdater.queuePending[type]) {
|
18584 | var doneFn = sourceUpdater.queuePending[type].doneFn;
|
18585 | sourceUpdater.queuePending[type] = null;
|
18586 |
|
18587 | if (doneFn) {
|
18588 |
|
18589 | doneFn(sourceUpdater[type + "Error_"]);
|
18590 | }
|
18591 | }
|
18592 |
|
18593 | shiftQueue(type, sourceUpdater);
|
18594 | };
|
18595 | };
|
18596 |
|
18597 |
|
18598 |
|
18599 |
|
18600 |
|
18601 |
|
18602 |
|
18603 |
|
18604 |
|
18605 |
|
18606 |
|
18607 |
|
18608 | var SourceUpdater = function (_videojs$EventTarget) {
|
18609 | _inheritsLoose__default["default"](SourceUpdater, _videojs$EventTarget);
|
18610 |
|
18611 | function SourceUpdater(mediaSource) {
|
18612 | var _this;
|
18613 |
|
18614 | _this = _videojs$EventTarget.call(this) || this;
|
18615 | _this.mediaSource = mediaSource;
|
18616 |
|
18617 | _this.sourceopenListener_ = function () {
|
18618 | return shiftQueue('mediaSource', _assertThisInitialized__default["default"](_this));
|
18619 | };
|
18620 |
|
18621 | _this.mediaSource.addEventListener('sourceopen', _this.sourceopenListener_);
|
18622 |
|
18623 | _this.logger_ = logger('SourceUpdater');
|
18624 |
|
18625 | _this.audioTimestampOffset_ = 0;
|
18626 | _this.videoTimestampOffset_ = 0;
|
18627 | _this.queue = [];
|
18628 | _this.queuePending = {
|
18629 | audio: null,
|
18630 | video: null
|
18631 | };
|
18632 | _this.delayedAudioAppendQueue_ = [];
|
18633 | _this.videoAppendQueued_ = false;
|
18634 | _this.codecs = {};
|
18635 | _this.onVideoUpdateEnd_ = onUpdateend('video', _assertThisInitialized__default["default"](_this));
|
18636 | _this.onAudioUpdateEnd_ = onUpdateend('audio', _assertThisInitialized__default["default"](_this));
|
18637 |
|
18638 | _this.onVideoError_ = function (e) {
|
18639 |
|
18640 | _this.videoError_ = e;
|
18641 | };
|
18642 |
|
18643 | _this.onAudioError_ = function (e) {
|
18644 |
|
18645 | _this.audioError_ = e;
|
18646 | };
|
18647 |
|
18648 | _this.createdSourceBuffers_ = false;
|
18649 | _this.initializedEme_ = false;
|
18650 | _this.triggeredReady_ = false;
|
18651 | return _this;
|
18652 | }
|
18653 |
|
18654 | var _proto = SourceUpdater.prototype;
|
18655 |
|
18656 | _proto.initializedEme = function initializedEme() {
|
18657 | this.initializedEme_ = true;
|
18658 | this.triggerReady();
|
18659 | };
|
18660 |
|
18661 | _proto.hasCreatedSourceBuffers = function hasCreatedSourceBuffers() {
|
18662 |
|
18663 |
|
18664 | return this.createdSourceBuffers_;
|
18665 | };
|
18666 |
|
18667 | _proto.hasInitializedAnyEme = function hasInitializedAnyEme() {
|
18668 | return this.initializedEme_;
|
18669 | };
|
18670 |
|
18671 | _proto.ready = function ready() {
|
18672 | return this.hasCreatedSourceBuffers() && this.hasInitializedAnyEme();
|
18673 | };
|
18674 |
|
18675 | _proto.createSourceBuffers = function createSourceBuffers(codecs) {
|
18676 | if (this.hasCreatedSourceBuffers()) {
|
18677 |
|
18678 | return;
|
18679 | }
|
18680 |
|
18681 |
|
18682 |
|
18683 | this.addOrChangeSourceBuffers(codecs);
|
18684 | this.createdSourceBuffers_ = true;
|
18685 | this.trigger('createdsourcebuffers');
|
18686 | this.triggerReady();
|
18687 | };
|
18688 |
|
18689 | _proto.triggerReady = function triggerReady() {
|
18690 |
|
18691 |
|
18692 |
|
18693 |
|
18694 |
|
18695 |
|
18696 | if (this.ready() && !this.triggeredReady_) {
|
18697 | this.triggeredReady_ = true;
|
18698 | this.trigger('ready');
|
18699 | }
|
18700 | }
|
18701 | |
18702 |
|
18703 |
|
18704 |
|
18705 |
|
18706 |
|
18707 |
|
18708 |
|
18709 |
|
18710 | ;
|
18711 |
|
18712 | _proto.addSourceBuffer = function addSourceBuffer(type, codec) {
|
18713 | pushQueue({
|
18714 | type: 'mediaSource',
|
18715 | sourceUpdater: this,
|
18716 | action: actions.addSourceBuffer(type, codec),
|
18717 | name: 'addSourceBuffer'
|
18718 | });
|
18719 | }
|
18720 | |
18721 |
|
18722 |
|
18723 |
|
18724 |
|
18725 |
|
18726 | ;
|
18727 |
|
18728 | _proto.abort = function abort(type) {
|
18729 | pushQueue({
|
18730 | type: type,
|
18731 | sourceUpdater: this,
|
18732 | action: actions.abort(type),
|
18733 | name: 'abort'
|
18734 | });
|
18735 | }
|
18736 | |
18737 |
|
18738 |
|
18739 |
|
18740 |
|
18741 |
|
18742 |
|
18743 | ;
|
18744 |
|
18745 | _proto.removeSourceBuffer = function removeSourceBuffer(type) {
|
18746 | if (!this.canRemoveSourceBuffer()) {
|
18747 | videojs__default["default"].log.error('removeSourceBuffer is not supported!');
|
18748 | return;
|
18749 | }
|
18750 |
|
18751 | pushQueue({
|
18752 | type: 'mediaSource',
|
18753 | sourceUpdater: this,
|
18754 | action: actions.removeSourceBuffer(type),
|
18755 | name: 'removeSourceBuffer'
|
18756 | });
|
18757 | }
|
18758 | |
18759 |
|
18760 |
|
18761 |
|
18762 |
|
18763 |
|
18764 |
|
18765 | ;
|
18766 |
|
18767 | _proto.canRemoveSourceBuffer = function canRemoveSourceBuffer() {
|
18768 |
|
18769 |
|
18770 |
|
18771 |
|
18772 | 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';
|
18773 | }
|
18774 | |
18775 |
|
18776 |
|
18777 |
|
18778 |
|
18779 |
|
18780 |
|
18781 | ;
|
18782 |
|
18783 | SourceUpdater.canChangeType = function canChangeType() {
|
18784 | return window__default["default"].SourceBuffer && window__default["default"].SourceBuffer.prototype && typeof window__default["default"].SourceBuffer.prototype.changeType === 'function';
|
18785 | }
|
18786 | |
18787 |
|
18788 |
|
18789 |
|
18790 |
|
18791 |
|
18792 |
|
18793 | ;
|
18794 |
|
18795 | _proto.canChangeType = function canChangeType() {
|
18796 | return this.constructor.canChangeType();
|
18797 | }
|
18798 | |
18799 |
|
18800 |
|
18801 |
|
18802 |
|
18803 |
|
18804 |
|
18805 |
|
18806 |
|
18807 | ;
|
18808 |
|
18809 | _proto.changeType = function changeType(type, codec) {
|
18810 | if (!this.canChangeType()) {
|
18811 | videojs__default["default"].log.error('changeType is not supported!');
|
18812 | return;
|
18813 | }
|
18814 |
|
18815 | pushQueue({
|
18816 | type: type,
|
18817 | sourceUpdater: this,
|
18818 | action: actions.changeType(codec),
|
18819 | name: 'changeType'
|
18820 | });
|
18821 | }
|
18822 | |
18823 |
|
18824 |
|
18825 |
|
18826 |
|
18827 |
|
18828 |
|
18829 | ;
|
18830 |
|
18831 | _proto.addOrChangeSourceBuffers = function addOrChangeSourceBuffers(codecs) {
|
18832 | var _this2 = this;
|
18833 |
|
18834 | if (!codecs || typeof codecs !== 'object' || Object.keys(codecs).length === 0) {
|
18835 | throw new Error('Cannot addOrChangeSourceBuffers to undefined codecs');
|
18836 | }
|
18837 |
|
18838 | Object.keys(codecs).forEach(function (type) {
|
18839 | var codec = codecs[type];
|
18840 |
|
18841 | if (!_this2.hasCreatedSourceBuffers()) {
|
18842 | return _this2.addSourceBuffer(type, codec);
|
18843 | }
|
18844 |
|
18845 | if (_this2.canChangeType()) {
|
18846 | _this2.changeType(type, codec);
|
18847 | }
|
18848 | });
|
18849 | }
|
18850 | |
18851 |
|
18852 |
|
18853 |
|
18854 |
|
18855 |
|
18856 |
|
18857 | ;
|
18858 |
|
18859 | _proto.appendBuffer = function appendBuffer(options, doneFn) {
|
18860 | var _this3 = this;
|
18861 |
|
18862 | var segmentInfo = options.segmentInfo,
|
18863 | type = options.type,
|
18864 | bytes = options.bytes;
|
18865 | this.processedAppend_ = true;
|
18866 |
|
18867 | if (type === 'audio' && this.videoBuffer && !this.videoAppendQueued_) {
|
18868 | this.delayedAudioAppendQueue_.push([options, doneFn]);
|
18869 | this.logger_("delayed audio append of " + bytes.length + " until video append");
|
18870 | return;
|
18871 | }
|
18872 |
|
18873 |
|
18874 |
|
18875 |
|
18876 |
|
18877 | var onError = doneFn;
|
18878 | pushQueue({
|
18879 | type: type,
|
18880 | sourceUpdater: this,
|
18881 | action: actions.appendBuffer(bytes, segmentInfo || {
|
18882 | mediaIndex: -1
|
18883 | }, onError),
|
18884 | doneFn: doneFn,
|
18885 | name: 'appendBuffer'
|
18886 | });
|
18887 |
|
18888 | if (type === 'video') {
|
18889 | this.videoAppendQueued_ = true;
|
18890 |
|
18891 | if (!this.delayedAudioAppendQueue_.length) {
|
18892 | return;
|
18893 | }
|
18894 |
|
18895 | var queue = this.delayedAudioAppendQueue_.slice();
|
18896 | this.logger_("queuing delayed audio " + queue.length + " appendBuffers");
|
18897 | this.delayedAudioAppendQueue_.length = 0;
|
18898 | queue.forEach(function (que) {
|
18899 | _this3.appendBuffer.apply(_this3, que);
|
18900 | });
|
18901 | }
|
18902 | }
|
18903 | |
18904 |
|
18905 |
|
18906 |
|
18907 |
|
18908 |
|
18909 | ;
|
18910 |
|
18911 | _proto.audioBuffered = function audioBuffered() {
|
18912 |
|
18913 |
|
18914 | if (!inSourceBuffers(this.mediaSource, this.audioBuffer)) {
|
18915 | return videojs__default["default"].createTimeRange();
|
18916 | }
|
18917 |
|
18918 | return this.audioBuffer.buffered ? this.audioBuffer.buffered : videojs__default["default"].createTimeRange();
|
18919 | }
|
18920 | |
18921 |
|
18922 |
|
18923 |
|
18924 |
|
18925 |
|
18926 | ;
|
18927 |
|
18928 | _proto.videoBuffered = function videoBuffered() {
|
18929 |
|
18930 |
|
18931 | if (!inSourceBuffers(this.mediaSource, this.videoBuffer)) {
|
18932 | return videojs__default["default"].createTimeRange();
|
18933 | }
|
18934 |
|
18935 | return this.videoBuffer.buffered ? this.videoBuffer.buffered : videojs__default["default"].createTimeRange();
|
18936 | }
|
18937 | |
18938 |
|
18939 |
|
18940 |
|
18941 |
|
18942 |
|
18943 | ;
|
18944 |
|
18945 | _proto.buffered = function buffered() {
|
18946 | var video = inSourceBuffers(this.mediaSource, this.videoBuffer) ? this.videoBuffer : null;
|
18947 | var audio = inSourceBuffers(this.mediaSource, this.audioBuffer) ? this.audioBuffer : null;
|
18948 |
|
18949 | if (audio && !video) {
|
18950 | return this.audioBuffered();
|
18951 | }
|
18952 |
|
18953 | if (video && !audio) {
|
18954 | return this.videoBuffered();
|
18955 | }
|
18956 |
|
18957 | return bufferIntersection(this.audioBuffered(), this.videoBuffered());
|
18958 | }
|
18959 | |
18960 |
|
18961 |
|
18962 |
|
18963 |
|
18964 |
|
18965 |
|
18966 |
|
18967 |
|
18968 | ;
|
18969 |
|
18970 | _proto.setDuration = function setDuration(duration, doneFn) {
|
18971 | if (doneFn === void 0) {
|
18972 | doneFn = noop;
|
18973 | }
|
18974 |
|
18975 |
|
18976 |
|
18977 |
|
18978 |
|
18979 | pushQueue({
|
18980 | type: 'mediaSource',
|
18981 | sourceUpdater: this,
|
18982 | action: actions.duration(duration),
|
18983 | name: 'duration',
|
18984 | doneFn: doneFn
|
18985 | });
|
18986 | }
|
18987 | |
18988 |
|
18989 |
|
18990 |
|
18991 |
|
18992 |
|
18993 |
|
18994 |
|
18995 |
|
18996 |
|
18997 | ;
|
18998 |
|
18999 | _proto.endOfStream = function endOfStream(error, doneFn) {
|
19000 | if (error === void 0) {
|
19001 | error = null;
|
19002 | }
|
19003 |
|
19004 | if (doneFn === void 0) {
|
19005 | doneFn = noop;
|
19006 | }
|
19007 |
|
19008 | if (typeof error !== 'string') {
|
19009 | error = undefined;
|
19010 | }
|
19011 |
|
19012 |
|
19013 |
|
19014 |
|
19015 |
|
19016 | pushQueue({
|
19017 | type: 'mediaSource',
|
19018 | sourceUpdater: this,
|
19019 | action: actions.endOfStream(error),
|
19020 | name: 'endOfStream',
|
19021 | doneFn: doneFn
|
19022 | });
|
19023 | }
|
19024 | |
19025 |
|
19026 |
|
19027 |
|
19028 |
|
19029 |
|
19030 |
|
19031 |
|
19032 |
|
19033 | ;
|
19034 |
|
19035 | _proto.removeAudio = function removeAudio(start, end, done) {
|
19036 | if (done === void 0) {
|
19037 | done = noop;
|
19038 | }
|
19039 |
|
19040 | if (!this.audioBuffered().length || this.audioBuffered().end(0) === 0) {
|
19041 | done();
|
19042 | return;
|
19043 | }
|
19044 |
|
19045 | pushQueue({
|
19046 | type: 'audio',
|
19047 | sourceUpdater: this,
|
19048 | action: actions.remove(start, end),
|
19049 | doneFn: done,
|
19050 | name: 'remove'
|
19051 | });
|
19052 | }
|
19053 | |
19054 |
|
19055 |
|
19056 |
|
19057 |
|
19058 |
|
19059 |
|
19060 |
|
19061 |
|
19062 | ;
|
19063 |
|
19064 | _proto.removeVideo = function removeVideo(start, end, done) {
|
19065 | if (done === void 0) {
|
19066 | done = noop;
|
19067 | }
|
19068 |
|
19069 | if (!this.videoBuffered().length || this.videoBuffered().end(0) === 0) {
|
19070 | done();
|
19071 | return;
|
19072 | }
|
19073 |
|
19074 | pushQueue({
|
19075 | type: 'video',
|
19076 | sourceUpdater: this,
|
19077 | action: actions.remove(start, end),
|
19078 | doneFn: done,
|
19079 | name: 'remove'
|
19080 | });
|
19081 | }
|
19082 | |
19083 |
|
19084 |
|
19085 |
|
19086 |
|
19087 | ;
|
19088 |
|
19089 | _proto.updating = function updating() {
|
19090 |
|
19091 | if (_updating('audio', this) || _updating('video', this)) {
|
19092 | return true;
|
19093 | }
|
19094 |
|
19095 | return false;
|
19096 | }
|
19097 | |
19098 |
|
19099 |
|
19100 |
|
19101 |
|
19102 | ;
|
19103 |
|
19104 | _proto.audioTimestampOffset = function audioTimestampOffset(offset) {
|
19105 | if (typeof offset !== 'undefined' && this.audioBuffer &&
|
19106 | this.audioTimestampOffset_ !== offset) {
|
19107 | pushQueue({
|
19108 | type: 'audio',
|
19109 | sourceUpdater: this,
|
19110 | action: actions.timestampOffset(offset),
|
19111 | name: 'timestampOffset'
|
19112 | });
|
19113 | this.audioTimestampOffset_ = offset;
|
19114 | }
|
19115 |
|
19116 | return this.audioTimestampOffset_;
|
19117 | }
|
19118 | |
19119 |
|
19120 |
|
19121 |
|
19122 |
|
19123 | ;
|
19124 |
|
19125 | _proto.videoTimestampOffset = function videoTimestampOffset(offset) {
|
19126 | if (typeof offset !== 'undefined' && this.videoBuffer &&
|
19127 | this.videoTimestampOffset !== offset) {
|
19128 | pushQueue({
|
19129 | type: 'video',
|
19130 | sourceUpdater: this,
|
19131 | action: actions.timestampOffset(offset),
|
19132 | name: 'timestampOffset'
|
19133 | });
|
19134 | this.videoTimestampOffset_ = offset;
|
19135 | }
|
19136 |
|
19137 | return this.videoTimestampOffset_;
|
19138 | }
|
19139 | |
19140 |
|
19141 |
|
19142 |
|
19143 |
|
19144 |
|
19145 |
|
19146 | ;
|
19147 |
|
19148 | _proto.audioQueueCallback = function audioQueueCallback(callback) {
|
19149 | if (!this.audioBuffer) {
|
19150 | return;
|
19151 | }
|
19152 |
|
19153 | pushQueue({
|
19154 | type: 'audio',
|
19155 | sourceUpdater: this,
|
19156 | action: actions.callback(callback),
|
19157 | name: 'callback'
|
19158 | });
|
19159 | }
|
19160 | |
19161 |
|
19162 |
|
19163 |
|
19164 |
|
19165 |
|
19166 |
|
19167 | ;
|
19168 |
|
19169 | _proto.videoQueueCallback = function videoQueueCallback(callback) {
|
19170 | if (!this.videoBuffer) {
|
19171 | return;
|
19172 | }
|
19173 |
|
19174 | pushQueue({
|
19175 | type: 'video',
|
19176 | sourceUpdater: this,
|
19177 | action: actions.callback(callback),
|
19178 | name: 'callback'
|
19179 | });
|
19180 | }
|
19181 | |
19182 |
|
19183 |
|
19184 | ;
|
19185 |
|
19186 | _proto.dispose = function dispose() {
|
19187 | var _this4 = this;
|
19188 |
|
19189 | this.trigger('dispose');
|
19190 | bufferTypes.forEach(function (type) {
|
19191 | _this4.abort(type);
|
19192 |
|
19193 | if (_this4.canRemoveSourceBuffer()) {
|
19194 | _this4.removeSourceBuffer(type);
|
19195 | } else {
|
19196 | _this4[type + "QueueCallback"](function () {
|
19197 | return cleanupBuffer(type, _this4);
|
19198 | });
|
19199 | }
|
19200 | });
|
19201 | this.videoAppendQueued_ = false;
|
19202 | this.delayedAudioAppendQueue_.length = 0;
|
19203 |
|
19204 | if (this.sourceopenListener_) {
|
19205 | this.mediaSource.removeEventListener('sourceopen', this.sourceopenListener_);
|
19206 | }
|
19207 |
|
19208 | this.off();
|
19209 | };
|
19210 |
|
19211 | return SourceUpdater;
|
19212 | }(videojs__default["default"].EventTarget);
|
19213 |
|
19214 | var uint8ToUtf8 = function uint8ToUtf8(uintArray) {
|
19215 | return decodeURIComponent(escape(String.fromCharCode.apply(null, uintArray)));
|
19216 | };
|
19217 |
|
19218 | var VTT_LINE_TERMINATORS = new Uint8Array('\n\n'.split('').map(function (char) {
|
19219 | return char.charCodeAt(0);
|
19220 | }));
|
19221 |
|
19222 |
|
19223 |
|
19224 |
|
19225 |
|
19226 |
|
19227 |
|
19228 |
|
19229 | var VTTSegmentLoader = function (_SegmentLoader) {
|
19230 | _inheritsLoose__default["default"](VTTSegmentLoader, _SegmentLoader);
|
19231 |
|
19232 | function VTTSegmentLoader(settings, options) {
|
19233 | var _this;
|
19234 |
|
19235 | if (options === void 0) {
|
19236 | options = {};
|
19237 | }
|
19238 |
|
19239 | _this = _SegmentLoader.call(this, settings, options) || this;
|
19240 |
|
19241 |
|
19242 | _this.mediaSource_ = null;
|
19243 | _this.subtitlesTrack_ = null;
|
19244 | _this.loaderType_ = 'subtitle';
|
19245 | _this.featuresNativeTextTracks_ = settings.featuresNativeTextTracks;
|
19246 |
|
19247 |
|
19248 | _this.shouldSaveSegmentTimingInfo_ = false;
|
19249 | return _this;
|
19250 | }
|
19251 |
|
19252 | var _proto = VTTSegmentLoader.prototype;
|
19253 |
|
19254 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
19255 |
|
19256 | return null;
|
19257 | }
|
19258 | |
19259 |
|
19260 |
|
19261 |
|
19262 |
|
19263 |
|
19264 | ;
|
19265 |
|
19266 | _proto.buffered_ = function buffered_() {
|
19267 | if (!this.subtitlesTrack_ || !this.subtitlesTrack_.cues || !this.subtitlesTrack_.cues.length) {
|
19268 | return videojs__default["default"].createTimeRanges();
|
19269 | }
|
19270 |
|
19271 | var cues = this.subtitlesTrack_.cues;
|
19272 | var start = cues[0].startTime;
|
19273 | var end = cues[cues.length - 1].startTime;
|
19274 | return videojs__default["default"].createTimeRanges([[start, end]]);
|
19275 | }
|
19276 | |
19277 |
|
19278 |
|
19279 |
|
19280 |
|
19281 |
|
19282 |
|
19283 |
|
19284 |
|
19285 |
|
19286 | ;
|
19287 |
|
19288 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
19289 | if (set === void 0) {
|
19290 | set = false;
|
19291 | }
|
19292 |
|
19293 | if (!map) {
|
19294 | return null;
|
19295 | }
|
19296 |
|
19297 | var id = initSegmentId(map);
|
19298 | var storedMap = this.initSegments_[id];
|
19299 |
|
19300 | if (set && !storedMap && map.bytes) {
|
19301 |
|
19302 |
|
19303 |
|
19304 |
|
19305 | var combinedByteLength = VTT_LINE_TERMINATORS.byteLength + map.bytes.byteLength;
|
19306 | var combinedSegment = new Uint8Array(combinedByteLength);
|
19307 | combinedSegment.set(map.bytes);
|
19308 | combinedSegment.set(VTT_LINE_TERMINATORS, map.bytes.byteLength);
|
19309 | this.initSegments_[id] = storedMap = {
|
19310 | resolvedUri: map.resolvedUri,
|
19311 | byterange: map.byterange,
|
19312 | bytes: combinedSegment
|
19313 | };
|
19314 | }
|
19315 |
|
19316 | return storedMap || map;
|
19317 | }
|
19318 | |
19319 |
|
19320 |
|
19321 |
|
19322 |
|
19323 |
|
19324 | ;
|
19325 |
|
19326 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
19327 | return this.playlist_ && this.subtitlesTrack_ && !this.paused();
|
19328 | }
|
19329 | |
19330 |
|
19331 |
|
19332 |
|
19333 |
|
19334 |
|
19335 |
|
19336 | ;
|
19337 |
|
19338 | _proto.init_ = function init_() {
|
19339 | this.state = 'READY';
|
19340 | this.resetEverything();
|
19341 | return this.monitorBuffer_();
|
19342 | }
|
19343 | |
19344 |
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 |
|
19350 |
|
19351 | ;
|
19352 |
|
19353 | _proto.track = function track(_track) {
|
19354 | if (typeof _track === 'undefined') {
|
19355 | return this.subtitlesTrack_;
|
19356 | }
|
19357 |
|
19358 | this.subtitlesTrack_ = _track;
|
19359 |
|
19360 |
|
19361 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
19362 | this.init_();
|
19363 | }
|
19364 |
|
19365 | return this.subtitlesTrack_;
|
19366 | }
|
19367 | |
19368 |
|
19369 |
|
19370 |
|
19371 |
|
19372 |
|
19373 | ;
|
19374 |
|
19375 | _proto.remove = function remove(start, end) {
|
19376 | removeCuesFromTrack(start, end, this.subtitlesTrack_);
|
19377 | }
|
19378 | |
19379 |
|
19380 |
|
19381 |
|
19382 |
|
19383 |
|
19384 |
|
19385 |
|
19386 |
|
19387 | ;
|
19388 |
|
19389 | _proto.fillBuffer_ = function fillBuffer_() {
|
19390 | var _this2 = this;
|
19391 |
|
19392 |
|
19393 | var segmentInfo = this.chooseNextRequest_();
|
19394 |
|
19395 | if (!segmentInfo) {
|
19396 | return;
|
19397 | }
|
19398 |
|
19399 | if (this.syncController_.timestampOffsetForTimeline(segmentInfo.timeline) === null) {
|
19400 |
|
19401 |
|
19402 | var checkTimestampOffset = function checkTimestampOffset() {
|
19403 | _this2.state = 'READY';
|
19404 |
|
19405 | if (!_this2.paused()) {
|
19406 |
|
19407 | _this2.monitorBuffer_();
|
19408 | }
|
19409 | };
|
19410 |
|
19411 | this.syncController_.one('timestampoffset', checkTimestampOffset);
|
19412 | this.state = 'WAITING_ON_TIMELINE';
|
19413 | return;
|
19414 | }
|
19415 |
|
19416 | this.loadSegment_(segmentInfo);
|
19417 | }
|
19418 | ;
|
19419 |
|
19420 | _proto.timestampOffsetForSegment_ = function timestampOffsetForSegment_() {
|
19421 | return null;
|
19422 | };
|
19423 |
|
19424 | _proto.chooseNextRequest_ = function chooseNextRequest_() {
|
19425 | return this.skipEmptySegments_(_SegmentLoader.prototype.chooseNextRequest_.call(this));
|
19426 | }
|
19427 | |
19428 |
|
19429 |
|
19430 |
|
19431 |
|
19432 |
|
19433 |
|
19434 |
|
19435 |
|
19436 |
|
19437 | ;
|
19438 |
|
19439 | _proto.skipEmptySegments_ = function skipEmptySegments_(segmentInfo) {
|
19440 | while (segmentInfo && segmentInfo.segment.empty) {
|
19441 |
|
19442 | if (segmentInfo.mediaIndex + 1 >= segmentInfo.playlist.segments.length) {
|
19443 | segmentInfo = null;
|
19444 | break;
|
19445 | }
|
19446 |
|
19447 | segmentInfo = this.generateSegmentInfo_({
|
19448 | playlist: segmentInfo.playlist,
|
19449 | mediaIndex: segmentInfo.mediaIndex + 1,
|
19450 | startOfSegment: segmentInfo.startOfSegment + segmentInfo.duration,
|
19451 | isSyncRequest: segmentInfo.isSyncRequest
|
19452 | });
|
19453 | }
|
19454 |
|
19455 | return segmentInfo;
|
19456 | };
|
19457 |
|
19458 | _proto.stopForError = function stopForError(error) {
|
19459 | this.error(error);
|
19460 | this.state = 'READY';
|
19461 | this.pause();
|
19462 | this.trigger('error');
|
19463 | }
|
19464 | |
19465 |
|
19466 |
|
19467 |
|
19468 |
|
19469 | ;
|
19470 |
|
19471 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
19472 | var _this3 = this;
|
19473 |
|
19474 | if (!this.subtitlesTrack_) {
|
19475 | this.state = 'READY';
|
19476 | return;
|
19477 | }
|
19478 |
|
19479 | this.saveTransferStats_(simpleSegment.stats);
|
19480 |
|
19481 | if (!this.pendingSegment_) {
|
19482 | this.state = 'READY';
|
19483 | this.mediaRequestsAborted += 1;
|
19484 | return;
|
19485 | }
|
19486 |
|
19487 | if (error) {
|
19488 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
19489 | this.handleTimeout_();
|
19490 | }
|
19491 |
|
19492 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
19493 | this.mediaRequestsAborted += 1;
|
19494 | } else {
|
19495 | this.mediaRequestsErrored += 1;
|
19496 | }
|
19497 |
|
19498 | this.stopForError(error);
|
19499 | return;
|
19500 | }
|
19501 |
|
19502 | var segmentInfo = this.pendingSegment_;
|
19503 |
|
19504 |
|
19505 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
19506 | this.state = 'APPENDING';
|
19507 |
|
19508 | this.trigger('appending');
|
19509 | var segment = segmentInfo.segment;
|
19510 |
|
19511 | if (segment.map) {
|
19512 | segment.map.bytes = simpleSegment.map.bytes;
|
19513 | }
|
19514 |
|
19515 | segmentInfo.bytes = simpleSegment.bytes;
|
19516 |
|
19517 | if (typeof window__default["default"].WebVTT !== 'function' && this.subtitlesTrack_ && this.subtitlesTrack_.tech_) {
|
19518 | var loadHandler;
|
19519 |
|
19520 | var errorHandler = function errorHandler() {
|
19521 | _this3.subtitlesTrack_.tech_.off('vttjsloaded', loadHandler);
|
19522 |
|
19523 | _this3.stopForError({
|
19524 | message: 'Error loading vtt.js'
|
19525 | });
|
19526 |
|
19527 | return;
|
19528 | };
|
19529 |
|
19530 | loadHandler = function loadHandler() {
|
19531 | _this3.subtitlesTrack_.tech_.off('vttjserror', errorHandler);
|
19532 |
|
19533 | _this3.segmentRequestFinished_(error, simpleSegment, result);
|
19534 | };
|
19535 |
|
19536 | this.state = 'WAITING_ON_VTTJS';
|
19537 | this.subtitlesTrack_.tech_.one('vttjsloaded', loadHandler);
|
19538 | this.subtitlesTrack_.tech_.one('vttjserror', errorHandler);
|
19539 | return;
|
19540 | }
|
19541 |
|
19542 | segment.requested = true;
|
19543 |
|
19544 | try {
|
19545 | this.parseVTTCues_(segmentInfo);
|
19546 | } catch (e) {
|
19547 | this.stopForError({
|
19548 | message: e.message
|
19549 | });
|
19550 | return;
|
19551 | }
|
19552 |
|
19553 | this.updateTimeMapping_(segmentInfo, this.syncController_.timelines[segmentInfo.timeline], this.playlist_);
|
19554 |
|
19555 | if (segmentInfo.cues.length) {
|
19556 | segmentInfo.timingInfo = {
|
19557 | start: segmentInfo.cues[0].startTime,
|
19558 | end: segmentInfo.cues[segmentInfo.cues.length - 1].endTime
|
19559 | };
|
19560 | } else {
|
19561 | segmentInfo.timingInfo = {
|
19562 | start: segmentInfo.startOfSegment,
|
19563 | end: segmentInfo.startOfSegment + segmentInfo.duration
|
19564 | };
|
19565 | }
|
19566 |
|
19567 | if (segmentInfo.isSyncRequest) {
|
19568 | this.trigger('syncinfoupdate');
|
19569 | this.pendingSegment_ = null;
|
19570 | this.state = 'READY';
|
19571 | return;
|
19572 | }
|
19573 |
|
19574 | segmentInfo.byteLength = segmentInfo.bytes.byteLength;
|
19575 | this.mediaSecondsLoaded += segment.duration;
|
19576 |
|
19577 |
|
19578 | segmentInfo.cues.forEach(function (cue) {
|
19579 | _this3.subtitlesTrack_.addCue(_this3.featuresNativeTextTracks_ ? new window__default["default"].VTTCue(cue.startTime, cue.endTime, cue.text) : cue);
|
19580 | });
|
19581 |
|
19582 |
|
19583 |
|
19584 |
|
19585 | removeDuplicateCuesFromTrack(this.subtitlesTrack_);
|
19586 | this.handleAppendsDone_();
|
19587 | };
|
19588 |
|
19589 | _proto.handleData_ = function handleData_() {
|
19590 |
|
19591 | };
|
19592 |
|
19593 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_() {
|
19594 | }
|
19595 | |
19596 |
|
19597 |
|
19598 |
|
19599 |
|
19600 |
|
19601 |
|
19602 | ;
|
19603 |
|
19604 | _proto.parseVTTCues_ = function parseVTTCues_(segmentInfo) {
|
19605 | var decoder;
|
19606 | var decodeBytesToString = false;
|
19607 |
|
19608 | if (typeof window__default["default"].TextDecoder === 'function') {
|
19609 | decoder = new window__default["default"].TextDecoder('utf8');
|
19610 | } else {
|
19611 | decoder = window__default["default"].WebVTT.StringDecoder();
|
19612 | decodeBytesToString = true;
|
19613 | }
|
19614 |
|
19615 | var parser = new window__default["default"].WebVTT.Parser(window__default["default"], window__default["default"].vttjs, decoder);
|
19616 | segmentInfo.cues = [];
|
19617 | segmentInfo.timestampmap = {
|
19618 | MPEGTS: 0,
|
19619 | LOCAL: 0
|
19620 | };
|
19621 | parser.oncue = segmentInfo.cues.push.bind(segmentInfo.cues);
|
19622 |
|
19623 | parser.ontimestampmap = function (map) {
|
19624 | segmentInfo.timestampmap = map;
|
19625 | };
|
19626 |
|
19627 | parser.onparsingerror = function (error) {
|
19628 | videojs__default["default"].log.warn('Error encountered when parsing cues: ' + error.message);
|
19629 | };
|
19630 |
|
19631 | if (segmentInfo.segment.map) {
|
19632 | var mapData = segmentInfo.segment.map.bytes;
|
19633 |
|
19634 | if (decodeBytesToString) {
|
19635 | mapData = uint8ToUtf8(mapData);
|
19636 | }
|
19637 |
|
19638 | parser.parse(mapData);
|
19639 | }
|
19640 |
|
19641 | var segmentData = segmentInfo.bytes;
|
19642 |
|
19643 | if (decodeBytesToString) {
|
19644 | segmentData = uint8ToUtf8(segmentData);
|
19645 | }
|
19646 |
|
19647 | parser.parse(segmentData);
|
19648 | parser.flush();
|
19649 | }
|
19650 | |
19651 |
|
19652 |
|
19653 |
|
19654 |
|
19655 |
|
19656 |
|
19657 |
|
19658 |
|
19659 |
|
19660 |
|
19661 |
|
19662 |
|
19663 | ;
|
19664 |
|
19665 | _proto.updateTimeMapping_ = function updateTimeMapping_(segmentInfo, mappingObj, playlist) {
|
19666 | var segment = segmentInfo.segment;
|
19667 |
|
19668 | if (!mappingObj) {
|
19669 |
|
19670 |
|
19671 |
|
19672 | return;
|
19673 | }
|
19674 |
|
19675 | if (!segmentInfo.cues.length) {
|
19676 |
|
19677 |
|
19678 |
|
19679 | segment.empty = true;
|
19680 | return;
|
19681 | }
|
19682 |
|
19683 | var timestampmap = segmentInfo.timestampmap;
|
19684 | var diff = timestampmap.MPEGTS / clock.ONE_SECOND_IN_TS - timestampmap.LOCAL + mappingObj.mapping;
|
19685 | segmentInfo.cues.forEach(function (cue) {
|
19686 |
|
19687 | cue.startTime += diff;
|
19688 | cue.endTime += diff;
|
19689 | });
|
19690 |
|
19691 | if (!playlist.syncInfo) {
|
19692 | var firstStart = segmentInfo.cues[0].startTime;
|
19693 | var lastStart = segmentInfo.cues[segmentInfo.cues.length - 1].startTime;
|
19694 | playlist.syncInfo = {
|
19695 | mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
|
19696 | time: Math.min(firstStart, lastStart - segment.duration)
|
19697 | };
|
19698 | }
|
19699 | };
|
19700 |
|
19701 | return VTTSegmentLoader;
|
19702 | }(SegmentLoader);
|
19703 |
|
19704 |
|
19705 |
|
19706 |
|
19707 |
|
19708 |
|
19709 |
|
19710 |
|
19711 |
|
19712 |
|
19713 |
|
19714 |
|
19715 |
|
19716 |
|
19717 |
|
19718 |
|
19719 |
|
19720 | var findAdCue = function findAdCue(track, mediaTime) {
|
19721 | var cues = track.cues;
|
19722 |
|
19723 | for (var i = 0; i < cues.length; i++) {
|
19724 | var cue = cues[i];
|
19725 |
|
19726 | if (mediaTime >= cue.adStartTime && mediaTime <= cue.adEndTime) {
|
19727 | return cue;
|
19728 | }
|
19729 | }
|
19730 |
|
19731 | return null;
|
19732 | };
|
19733 | var updateAdCues = function updateAdCues(media, track, offset) {
|
19734 | if (offset === void 0) {
|
19735 | offset = 0;
|
19736 | }
|
19737 |
|
19738 | if (!media.segments) {
|
19739 | return;
|
19740 | }
|
19741 |
|
19742 | var mediaTime = offset;
|
19743 | var cue;
|
19744 |
|
19745 | for (var i = 0; i < media.segments.length; i++) {
|
19746 | var segment = media.segments[i];
|
19747 |
|
19748 | if (!cue) {
|
19749 |
|
19750 |
|
19751 |
|
19752 |
|
19753 | cue = findAdCue(track, mediaTime + segment.duration / 2);
|
19754 | }
|
19755 |
|
19756 | if (cue) {
|
19757 | if ('cueIn' in segment) {
|
19758 |
|
19759 | cue.endTime = mediaTime;
|
19760 | cue.adEndTime = mediaTime;
|
19761 | mediaTime += segment.duration;
|
19762 | cue = null;
|
19763 | continue;
|
19764 | }
|
19765 |
|
19766 | if (mediaTime < cue.endTime) {
|
19767 |
|
19768 | mediaTime += segment.duration;
|
19769 | continue;
|
19770 | }
|
19771 |
|
19772 |
|
19773 | cue.endTime += segment.duration;
|
19774 | } else {
|
19775 | if ('cueOut' in segment) {
|
19776 | cue = new window__default["default"].VTTCue(mediaTime, mediaTime + segment.duration, segment.cueOut);
|
19777 | cue.adStartTime = mediaTime;
|
19778 |
|
19779 |
|
19780 | cue.adEndTime = mediaTime + parseFloat(segment.cueOut);
|
19781 | track.addCue(cue);
|
19782 | }
|
19783 |
|
19784 | if ('cueOutCont' in segment) {
|
19785 |
|
19786 |
|
19787 |
|
19788 | var _segment$cueOutCont$s = segment.cueOutCont.split('/').map(parseFloat),
|
19789 | adOffset = _segment$cueOutCont$s[0],
|
19790 | adTotal = _segment$cueOutCont$s[1];
|
19791 |
|
19792 | cue = new window__default["default"].VTTCue(mediaTime, mediaTime + segment.duration, '');
|
19793 | cue.adStartTime = mediaTime - adOffset;
|
19794 | cue.adEndTime = cue.adStartTime + adTotal;
|
19795 | track.addCue(cue);
|
19796 | }
|
19797 | }
|
19798 |
|
19799 | mediaTime += segment.duration;
|
19800 | }
|
19801 | };
|
19802 |
|
19803 |
|
19804 |
|
19805 |
|
19806 |
|
19807 |
|
19808 | var MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC = 86400;
|
19809 | var syncPointStrategies = [
|
19810 |
|
19811 | {
|
19812 | name: 'VOD',
|
19813 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
19814 | if (duration !== Infinity) {
|
19815 | var syncPoint = {
|
19816 | time: 0,
|
19817 | segmentIndex: 0,
|
19818 | partIndex: null
|
19819 | };
|
19820 | return syncPoint;
|
19821 | }
|
19822 |
|
19823 | return null;
|
19824 | }
|
19825 | },
|
19826 | {
|
19827 | name: 'ProgramDateTime',
|
19828 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
19829 | if (!Object.keys(syncController.timelineToDatetimeMappings).length) {
|
19830 | return null;
|
19831 | }
|
19832 |
|
19833 | var syncPoint = null;
|
19834 | var lastDistance = null;
|
19835 | var partsAndSegments = getPartsAndSegments(playlist);
|
19836 | currentTime = currentTime || 0;
|
19837 |
|
19838 | for (var i = 0; i < partsAndSegments.length; i++) {
|
19839 |
|
19840 |
|
19841 | var index = playlist.endList || currentTime === 0 ? i : partsAndSegments.length - (i + 1);
|
19842 | var partAndSegment = partsAndSegments[index];
|
19843 | var segment = partAndSegment.segment;
|
19844 | var datetimeMapping = syncController.timelineToDatetimeMappings[segment.timeline];
|
19845 |
|
19846 | if (!datetimeMapping) {
|
19847 | continue;
|
19848 | }
|
19849 |
|
19850 | if (segment.dateTimeObject) {
|
19851 | var segmentTime = segment.dateTimeObject.getTime() / 1000;
|
19852 | var start = segmentTime + datetimeMapping;
|
19853 |
|
19854 | if (segment.parts && typeof partAndSegment.partIndex === 'number') {
|
19855 | for (var z = 0; z < partAndSegment.partIndex; z++) {
|
19856 | start += segment.parts[z].duration;
|
19857 | }
|
19858 | }
|
19859 |
|
19860 | var distance = Math.abs(currentTime - start);
|
19861 |
|
19862 |
|
19863 | if (lastDistance !== null && (distance === 0 || lastDistance < distance)) {
|
19864 | break;
|
19865 | }
|
19866 |
|
19867 | lastDistance = distance;
|
19868 | syncPoint = {
|
19869 | time: start,
|
19870 | segmentIndex: partAndSegment.segmentIndex,
|
19871 | partIndex: partAndSegment.partIndex
|
19872 | };
|
19873 | }
|
19874 | }
|
19875 |
|
19876 | return syncPoint;
|
19877 | }
|
19878 | },
|
19879 |
|
19880 | {
|
19881 | name: 'Segment',
|
19882 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
19883 | var syncPoint = null;
|
19884 | var lastDistance = null;
|
19885 | currentTime = currentTime || 0;
|
19886 | var partsAndSegments = getPartsAndSegments(playlist);
|
19887 |
|
19888 | for (var i = 0; i < partsAndSegments.length; i++) {
|
19889 |
|
19890 |
|
19891 | var index = playlist.endList || currentTime === 0 ? i : partsAndSegments.length - (i + 1);
|
19892 | var partAndSegment = partsAndSegments[index];
|
19893 | var segment = partAndSegment.segment;
|
19894 | var start = partAndSegment.part && partAndSegment.part.start || segment && segment.start;
|
19895 |
|
19896 | if (segment.timeline === currentTimeline && typeof start !== 'undefined') {
|
19897 | var distance = Math.abs(currentTime - start);
|
19898 |
|
19899 |
|
19900 | if (lastDistance !== null && lastDistance < distance) {
|
19901 | break;
|
19902 | }
|
19903 |
|
19904 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
19905 | lastDistance = distance;
|
19906 | syncPoint = {
|
19907 | time: start,
|
19908 | segmentIndex: partAndSegment.segmentIndex,
|
19909 | partIndex: partAndSegment.partIndex
|
19910 | };
|
19911 | }
|
19912 | }
|
19913 | }
|
19914 |
|
19915 | return syncPoint;
|
19916 | }
|
19917 | },
|
19918 |
|
19919 | {
|
19920 | name: 'Discontinuity',
|
19921 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
19922 | var syncPoint = null;
|
19923 | currentTime = currentTime || 0;
|
19924 |
|
19925 | if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
19926 | var lastDistance = null;
|
19927 |
|
19928 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
19929 | var segmentIndex = playlist.discontinuityStarts[i];
|
19930 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
19931 | var discontinuitySync = syncController.discontinuities[discontinuity];
|
19932 |
|
19933 | if (discontinuitySync) {
|
19934 | var distance = Math.abs(currentTime - discontinuitySync.time);
|
19935 |
|
19936 |
|
19937 | if (lastDistance !== null && lastDistance < distance) {
|
19938 | break;
|
19939 | }
|
19940 |
|
19941 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
19942 | lastDistance = distance;
|
19943 | syncPoint = {
|
19944 | time: discontinuitySync.time,
|
19945 | segmentIndex: segmentIndex,
|
19946 | partIndex: null
|
19947 | };
|
19948 | }
|
19949 | }
|
19950 | }
|
19951 | }
|
19952 |
|
19953 | return syncPoint;
|
19954 | }
|
19955 | },
|
19956 |
|
19957 | {
|
19958 | name: 'Playlist',
|
19959 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
19960 | if (playlist.syncInfo) {
|
19961 | var syncPoint = {
|
19962 | time: playlist.syncInfo.time,
|
19963 | segmentIndex: playlist.syncInfo.mediaSequence - playlist.mediaSequence,
|
19964 | partIndex: null
|
19965 | };
|
19966 | return syncPoint;
|
19967 | }
|
19968 |
|
19969 | return null;
|
19970 | }
|
19971 | }];
|
19972 |
|
19973 | var SyncController = function (_videojs$EventTarget) {
|
19974 | _inheritsLoose__default["default"](SyncController, _videojs$EventTarget);
|
19975 |
|
19976 | function SyncController(options) {
|
19977 | var _this;
|
19978 |
|
19979 | _this = _videojs$EventTarget.call(this) || this;
|
19980 |
|
19981 | _this.timelines = [];
|
19982 | _this.discontinuities = [];
|
19983 | _this.timelineToDatetimeMappings = {};
|
19984 | _this.logger_ = logger('SyncController');
|
19985 | return _this;
|
19986 | }
|
19987 | |
19988 |
|
19989 |
|
19990 |
|
19991 |
|
19992 |
|
19993 |
|
19994 |
|
19995 |
|
19996 |
|
19997 |
|
19998 |
|
19999 |
|
20000 |
|
20001 |
|
20002 |
|
20003 |
|
20004 | var _proto = SyncController.prototype;
|
20005 |
|
20006 | _proto.getSyncPoint = function getSyncPoint(playlist, duration, currentTimeline, currentTime) {
|
20007 | var syncPoints = this.runStrategies_(playlist, duration, currentTimeline, currentTime);
|
20008 |
|
20009 | if (!syncPoints.length) {
|
20010 |
|
20011 |
|
20012 |
|
20013 | return null;
|
20014 | }
|
20015 |
|
20016 |
|
20017 |
|
20018 |
|
20019 | return this.selectSyncPoint_(syncPoints, {
|
20020 | key: 'time',
|
20021 | value: currentTime
|
20022 | });
|
20023 | }
|
20024 | |
20025 |
|
20026 |
|
20027 |
|
20028 |
|
20029 |
|
20030 |
|
20031 |
|
20032 |
|
20033 |
|
20034 |
|
20035 | ;
|
20036 |
|
20037 | _proto.getExpiredTime = function getExpiredTime(playlist, duration) {
|
20038 | if (!playlist || !playlist.segments) {
|
20039 | return null;
|
20040 | }
|
20041 |
|
20042 | var syncPoints = this.runStrategies_(playlist, duration, playlist.discontinuitySequence, 0);
|
20043 |
|
20044 | if (!syncPoints.length) {
|
20045 | return null;
|
20046 | }
|
20047 |
|
20048 | var syncPoint = this.selectSyncPoint_(syncPoints, {
|
20049 | key: 'segmentIndex',
|
20050 | value: 0
|
20051 | });
|
20052 |
|
20053 |
|
20054 | if (syncPoint.segmentIndex > 0) {
|
20055 | syncPoint.time *= -1;
|
20056 | }
|
20057 |
|
20058 | return Math.abs(syncPoint.time + sumDurations({
|
20059 | defaultDuration: playlist.targetDuration,
|
20060 | durationList: playlist.segments,
|
20061 | startIndex: syncPoint.segmentIndex,
|
20062 | endIndex: 0
|
20063 | }));
|
20064 | }
|
20065 | |
20066 |
|
20067 |
|
20068 |
|
20069 |
|
20070 |
|
20071 |
|
20072 |
|
20073 |
|
20074 |
|
20075 |
|
20076 |
|
20077 |
|
20078 |
|
20079 | ;
|
20080 |
|
20081 | _proto.runStrategies_ = function runStrategies_(playlist, duration, currentTimeline, currentTime) {
|
20082 | var syncPoints = [];
|
20083 |
|
20084 | for (var i = 0; i < syncPointStrategies.length; i++) {
|
20085 | var strategy = syncPointStrategies[i];
|
20086 | var syncPoint = strategy.run(this, playlist, duration, currentTimeline, currentTime);
|
20087 |
|
20088 | if (syncPoint) {
|
20089 | syncPoint.strategy = strategy.name;
|
20090 | syncPoints.push({
|
20091 | strategy: strategy.name,
|
20092 | syncPoint: syncPoint
|
20093 | });
|
20094 | }
|
20095 | }
|
20096 |
|
20097 | return syncPoints;
|
20098 | }
|
20099 | |
20100 |
|
20101 |
|
20102 |
|
20103 |
|
20104 |
|
20105 |
|
20106 |
|
20107 |
|
20108 |
|
20109 |
|
20110 |
|
20111 |
|
20112 |
|
20113 |
|
20114 | ;
|
20115 |
|
20116 | _proto.selectSyncPoint_ = function selectSyncPoint_(syncPoints, target) {
|
20117 | var bestSyncPoint = syncPoints[0].syncPoint;
|
20118 | var bestDistance = Math.abs(syncPoints[0].syncPoint[target.key] - target.value);
|
20119 | var bestStrategy = syncPoints[0].strategy;
|
20120 |
|
20121 | for (var i = 1; i < syncPoints.length; i++) {
|
20122 | var newDistance = Math.abs(syncPoints[i].syncPoint[target.key] - target.value);
|
20123 |
|
20124 | if (newDistance < bestDistance) {
|
20125 | bestDistance = newDistance;
|
20126 | bestSyncPoint = syncPoints[i].syncPoint;
|
20127 | bestStrategy = syncPoints[i].strategy;
|
20128 | }
|
20129 | }
|
20130 |
|
20131 | 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 : '') + ']');
|
20132 | return bestSyncPoint;
|
20133 | }
|
20134 | |
20135 |
|
20136 |
|
20137 |
|
20138 |
|
20139 |
|
20140 |
|
20141 |
|
20142 | ;
|
20143 |
|
20144 | _proto.saveExpiredSegmentInfo = function saveExpiredSegmentInfo(oldPlaylist, newPlaylist) {
|
20145 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
20146 |
|
20147 | if (mediaSequenceDiff > MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC) {
|
20148 | videojs__default["default"].log.warn("Not saving expired segment info. Media sequence gap " + mediaSequenceDiff + " is too large.");
|
20149 | return;
|
20150 | }
|
20151 |
|
20152 |
|
20153 |
|
20154 | for (var i = mediaSequenceDiff - 1; i >= 0; i--) {
|
20155 | var lastRemovedSegment = oldPlaylist.segments[i];
|
20156 |
|
20157 | if (lastRemovedSegment && typeof lastRemovedSegment.start !== 'undefined') {
|
20158 | newPlaylist.syncInfo = {
|
20159 | mediaSequence: oldPlaylist.mediaSequence + i,
|
20160 | time: lastRemovedSegment.start
|
20161 | };
|
20162 | this.logger_("playlist refresh sync: [time:" + newPlaylist.syncInfo.time + "," + (" mediaSequence: " + newPlaylist.syncInfo.mediaSequence + "]"));
|
20163 | this.trigger('syncinfoupdate');
|
20164 | break;
|
20165 | }
|
20166 | }
|
20167 | }
|
20168 | |
20169 |
|
20170 |
|
20171 |
|
20172 |
|
20173 |
|
20174 | ;
|
20175 |
|
20176 | _proto.setDateTimeMappingForStart = function setDateTimeMappingForStart(playlist) {
|
20177 |
|
20178 |
|
20179 |
|
20180 |
|
20181 | this.timelineToDatetimeMappings = {};
|
20182 |
|
20183 | if (playlist.segments && playlist.segments.length && playlist.segments[0].dateTimeObject) {
|
20184 | var firstSegment = playlist.segments[0];
|
20185 | var playlistTimestamp = firstSegment.dateTimeObject.getTime() / 1000;
|
20186 | this.timelineToDatetimeMappings[firstSegment.timeline] = -playlistTimestamp;
|
20187 | }
|
20188 | }
|
20189 | |
20190 |
|
20191 |
|
20192 |
|
20193 |
|
20194 |
|
20195 |
|
20196 |
|
20197 |
|
20198 |
|
20199 |
|
20200 |
|
20201 | ;
|
20202 |
|
20203 | _proto.saveSegmentTimingInfo = function saveSegmentTimingInfo(_ref) {
|
20204 | var segmentInfo = _ref.segmentInfo,
|
20205 | shouldSaveTimelineMapping = _ref.shouldSaveTimelineMapping;
|
20206 | var didCalculateSegmentTimeMapping = this.calculateSegmentTimeMapping_(segmentInfo, segmentInfo.timingInfo, shouldSaveTimelineMapping);
|
20207 | var segment = segmentInfo.segment;
|
20208 |
|
20209 | if (didCalculateSegmentTimeMapping) {
|
20210 | this.saveDiscontinuitySyncInfo_(segmentInfo);
|
20211 |
|
20212 |
|
20213 | if (!segmentInfo.playlist.syncInfo) {
|
20214 | segmentInfo.playlist.syncInfo = {
|
20215 | mediaSequence: segmentInfo.playlist.mediaSequence + segmentInfo.mediaIndex,
|
20216 | time: segment.start
|
20217 | };
|
20218 | }
|
20219 | }
|
20220 |
|
20221 | var dateTime = segment.dateTimeObject;
|
20222 |
|
20223 | if (segment.discontinuity && shouldSaveTimelineMapping && dateTime) {
|
20224 | this.timelineToDatetimeMappings[segment.timeline] = -(dateTime.getTime() / 1000);
|
20225 | }
|
20226 | };
|
20227 |
|
20228 | _proto.timestampOffsetForTimeline = function timestampOffsetForTimeline(timeline) {
|
20229 | if (typeof this.timelines[timeline] === 'undefined') {
|
20230 | return null;
|
20231 | }
|
20232 |
|
20233 | return this.timelines[timeline].time;
|
20234 | };
|
20235 |
|
20236 | _proto.mappingForTimeline = function mappingForTimeline(timeline) {
|
20237 | if (typeof this.timelines[timeline] === 'undefined') {
|
20238 | return null;
|
20239 | }
|
20240 |
|
20241 | return this.timelines[timeline].mapping;
|
20242 | }
|
20243 | |
20244 |
|
20245 |
|
20246 |
|
20247 |
|
20248 |
|
20249 |
|
20250 |
|
20251 |
|
20252 |
|
20253 |
|
20254 |
|
20255 |
|
20256 |
|
20257 |
|
20258 | ;
|
20259 |
|
20260 | _proto.calculateSegmentTimeMapping_ = function calculateSegmentTimeMapping_(segmentInfo, timingInfo, shouldSaveTimelineMapping) {
|
20261 |
|
20262 | var segment = segmentInfo.segment;
|
20263 | var part = segmentInfo.part;
|
20264 | var mappingObj = this.timelines[segmentInfo.timeline];
|
20265 | var start;
|
20266 | var end;
|
20267 |
|
20268 | if (typeof segmentInfo.timestampOffset === 'number') {
|
20269 | mappingObj = {
|
20270 | time: segmentInfo.startOfSegment,
|
20271 | mapping: segmentInfo.startOfSegment - timingInfo.start
|
20272 | };
|
20273 |
|
20274 | if (shouldSaveTimelineMapping) {
|
20275 | this.timelines[segmentInfo.timeline] = mappingObj;
|
20276 | this.trigger('timestampoffset');
|
20277 | this.logger_("time mapping for timeline " + segmentInfo.timeline + ": " + ("[time: " + mappingObj.time + "] [mapping: " + mappingObj.mapping + "]"));
|
20278 | }
|
20279 |
|
20280 | start = segmentInfo.startOfSegment;
|
20281 | end = timingInfo.end + mappingObj.mapping;
|
20282 | } else if (mappingObj) {
|
20283 | start = timingInfo.start + mappingObj.mapping;
|
20284 | end = timingInfo.end + mappingObj.mapping;
|
20285 | } else {
|
20286 | return false;
|
20287 | }
|
20288 |
|
20289 | if (part) {
|
20290 | part.start = start;
|
20291 | part.end = end;
|
20292 | }
|
20293 |
|
20294 |
|
20295 |
|
20296 |
|
20297 |
|
20298 |
|
20299 | if (!segment.start || start < segment.start) {
|
20300 | segment.start = start;
|
20301 | }
|
20302 |
|
20303 | segment.end = end;
|
20304 | return true;
|
20305 | }
|
20306 | |
20307 |
|
20308 |
|
20309 |
|
20310 |
|
20311 |
|
20312 |
|
20313 |
|
20314 | ;
|
20315 |
|
20316 | _proto.saveDiscontinuitySyncInfo_ = function saveDiscontinuitySyncInfo_(segmentInfo) {
|
20317 | var playlist = segmentInfo.playlist;
|
20318 | var segment = segmentInfo.segment;
|
20319 |
|
20320 |
|
20321 |
|
20322 | if (segment.discontinuity) {
|
20323 | this.discontinuities[segment.timeline] = {
|
20324 | time: segment.start,
|
20325 | accuracy: 0
|
20326 | };
|
20327 | } else if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
20328 |
|
20329 |
|
20330 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
20331 | var segmentIndex = playlist.discontinuityStarts[i];
|
20332 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
20333 | var mediaIndexDiff = segmentIndex - segmentInfo.mediaIndex;
|
20334 | var accuracy = Math.abs(mediaIndexDiff);
|
20335 |
|
20336 | if (!this.discontinuities[discontinuity] || this.discontinuities[discontinuity].accuracy > accuracy) {
|
20337 | var time = void 0;
|
20338 |
|
20339 | if (mediaIndexDiff < 0) {
|
20340 | time = segment.start - sumDurations({
|
20341 | defaultDuration: playlist.targetDuration,
|
20342 | durationList: playlist.segments,
|
20343 | startIndex: segmentInfo.mediaIndex,
|
20344 | endIndex: segmentIndex
|
20345 | });
|
20346 | } else {
|
20347 | time = segment.end + sumDurations({
|
20348 | defaultDuration: playlist.targetDuration,
|
20349 | durationList: playlist.segments,
|
20350 | startIndex: segmentInfo.mediaIndex + 1,
|
20351 | endIndex: segmentIndex
|
20352 | });
|
20353 | }
|
20354 |
|
20355 | this.discontinuities[discontinuity] = {
|
20356 | time: time,
|
20357 | accuracy: accuracy
|
20358 | };
|
20359 | }
|
20360 | }
|
20361 | }
|
20362 | };
|
20363 |
|
20364 | _proto.dispose = function dispose() {
|
20365 | this.trigger('dispose');
|
20366 | this.off();
|
20367 | };
|
20368 |
|
20369 | return SyncController;
|
20370 | }(videojs__default["default"].EventTarget);
|
20371 |
|
20372 |
|
20373 |
|
20374 |
|
20375 |
|
20376 |
|
20377 |
|
20378 |
|
20379 |
|
20380 |
|
20381 |
|
20382 | var TimelineChangeController = function (_videojs$EventTarget) {
|
20383 | _inheritsLoose__default["default"](TimelineChangeController, _videojs$EventTarget);
|
20384 |
|
20385 | function TimelineChangeController() {
|
20386 | var _this;
|
20387 |
|
20388 | _this = _videojs$EventTarget.call(this) || this;
|
20389 | _this.pendingTimelineChanges_ = {};
|
20390 | _this.lastTimelineChanges_ = {};
|
20391 | return _this;
|
20392 | }
|
20393 |
|
20394 | var _proto = TimelineChangeController.prototype;
|
20395 |
|
20396 | _proto.clearPendingTimelineChange = function clearPendingTimelineChange(type) {
|
20397 | this.pendingTimelineChanges_[type] = null;
|
20398 | this.trigger('pendingtimelinechange');
|
20399 | };
|
20400 |
|
20401 | _proto.pendingTimelineChange = function pendingTimelineChange(_ref) {
|
20402 | var type = _ref.type,
|
20403 | from = _ref.from,
|
20404 | to = _ref.to;
|
20405 |
|
20406 | if (typeof from === 'number' && typeof to === 'number') {
|
20407 | this.pendingTimelineChanges_[type] = {
|
20408 | type: type,
|
20409 | from: from,
|
20410 | to: to
|
20411 | };
|
20412 | this.trigger('pendingtimelinechange');
|
20413 | }
|
20414 |
|
20415 | return this.pendingTimelineChanges_[type];
|
20416 | };
|
20417 |
|
20418 | _proto.lastTimelineChange = function lastTimelineChange(_ref2) {
|
20419 | var type = _ref2.type,
|
20420 | from = _ref2.from,
|
20421 | to = _ref2.to;
|
20422 |
|
20423 | if (typeof from === 'number' && typeof to === 'number') {
|
20424 | this.lastTimelineChanges_[type] = {
|
20425 | type: type,
|
20426 | from: from,
|
20427 | to: to
|
20428 | };
|
20429 | delete this.pendingTimelineChanges_[type];
|
20430 | this.trigger('timelinechange');
|
20431 | }
|
20432 |
|
20433 | return this.lastTimelineChanges_[type];
|
20434 | };
|
20435 |
|
20436 | _proto.dispose = function dispose() {
|
20437 | this.trigger('dispose');
|
20438 | this.pendingTimelineChanges_ = {};
|
20439 | this.lastTimelineChanges_ = {};
|
20440 | this.off();
|
20441 | };
|
20442 |
|
20443 | return TimelineChangeController;
|
20444 | }(videojs__default["default"].EventTarget);
|
20445 |
|
20446 |
|
20447 | var workerCode = transform(getWorkerString(function () {
|
20448 |
|
20449 | function createCommonjsModule(fn, basedir, module) {
|
20450 | return module = {
|
20451 | path: basedir,
|
20452 | exports: {},
|
20453 | require: function require(path, base) {
|
20454 | return commonjsRequire(path, base === undefined || base === null ? module.path : base);
|
20455 | }
|
20456 | }, fn(module, module.exports), module.exports;
|
20457 | }
|
20458 |
|
20459 | function commonjsRequire() {
|
20460 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
20461 | }
|
20462 |
|
20463 | var createClass = createCommonjsModule(function (module) {
|
20464 | function _defineProperties(target, props) {
|
20465 | for (var i = 0; i < props.length; i++) {
|
20466 | var descriptor = props[i];
|
20467 | descriptor.enumerable = descriptor.enumerable || false;
|
20468 | descriptor.configurable = true;
|
20469 | if ("value" in descriptor) descriptor.writable = true;
|
20470 | Object.defineProperty(target, descriptor.key, descriptor);
|
20471 | }
|
20472 | }
|
20473 |
|
20474 | function _createClass(Constructor, protoProps, staticProps) {
|
20475 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
20476 | if (staticProps) _defineProperties(Constructor, staticProps);
|
20477 | return Constructor;
|
20478 | }
|
20479 |
|
20480 | module.exports = _createClass;
|
20481 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20482 | });
|
20483 | var setPrototypeOf = createCommonjsModule(function (module) {
|
20484 | function _setPrototypeOf(o, p) {
|
20485 | module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
20486 | o.__proto__ = p;
|
20487 | return o;
|
20488 | };
|
20489 |
|
20490 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20491 | return _setPrototypeOf(o, p);
|
20492 | }
|
20493 |
|
20494 | module.exports = _setPrototypeOf;
|
20495 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20496 | });
|
20497 | var inheritsLoose = createCommonjsModule(function (module) {
|
20498 | function _inheritsLoose(subClass, superClass) {
|
20499 | subClass.prototype = Object.create(superClass.prototype);
|
20500 | subClass.prototype.constructor = subClass;
|
20501 | setPrototypeOf(subClass, superClass);
|
20502 | }
|
20503 |
|
20504 | module.exports = _inheritsLoose;
|
20505 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
20506 | });
|
20507 | |
20508 |
|
20509 |
|
20510 |
|
20511 | |
20512 |
|
20513 |
|
20514 |
|
20515 |
|
20516 |
|
20517 | var Stream = function () {
|
20518 | function Stream() {
|
20519 | this.listeners = {};
|
20520 | }
|
20521 | |
20522 |
|
20523 |
|
20524 |
|
20525 |
|
20526 |
|
20527 |
|
20528 |
|
20529 |
|
20530 | var _proto = Stream.prototype;
|
20531 |
|
20532 | _proto.on = function on(type, listener) {
|
20533 | if (!this.listeners[type]) {
|
20534 | this.listeners[type] = [];
|
20535 | }
|
20536 |
|
20537 | this.listeners[type].push(listener);
|
20538 | }
|
20539 | |
20540 |
|
20541 |
|
20542 |
|
20543 |
|
20544 |
|
20545 |
|
20546 |
|
20547 | ;
|
20548 |
|
20549 | _proto.off = function off(type, listener) {
|
20550 | if (!this.listeners[type]) {
|
20551 | return false;
|
20552 | }
|
20553 |
|
20554 | var index = this.listeners[type].indexOf(listener);
|
20555 |
|
20556 |
|
20557 |
|
20558 |
|
20559 |
|
20560 |
|
20561 |
|
20562 |
|
20563 | this.listeners[type] = this.listeners[type].slice(0);
|
20564 | this.listeners[type].splice(index, 1);
|
20565 | return index > -1;
|
20566 | }
|
20567 | |
20568 |
|
20569 |
|
20570 |
|
20571 |
|
20572 |
|
20573 | ;
|
20574 |
|
20575 | _proto.trigger = function trigger(type) {
|
20576 | var callbacks = this.listeners[type];
|
20577 |
|
20578 | if (!callbacks) {
|
20579 | return;
|
20580 | }
|
20581 |
|
20582 |
|
20583 |
|
20584 |
|
20585 |
|
20586 | if (arguments.length === 2) {
|
20587 | var length = callbacks.length;
|
20588 |
|
20589 | for (var i = 0; i < length; ++i) {
|
20590 | callbacks[i].call(this, arguments[1]);
|
20591 | }
|
20592 | } else {
|
20593 | var args = Array.prototype.slice.call(arguments, 1);
|
20594 | var _length = callbacks.length;
|
20595 |
|
20596 | for (var _i = 0; _i < _length; ++_i) {
|
20597 | callbacks[_i].apply(this, args);
|
20598 | }
|
20599 | }
|
20600 | }
|
20601 | |
20602 |
|
20603 |
|
20604 | ;
|
20605 |
|
20606 | _proto.dispose = function dispose() {
|
20607 | this.listeners = {};
|
20608 | }
|
20609 | |
20610 |
|
20611 |
|
20612 |
|
20613 |
|
20614 |
|
20615 |
|
20616 |
|
20617 | ;
|
20618 |
|
20619 | _proto.pipe = function pipe(destination) {
|
20620 | this.on('data', function (data) {
|
20621 | destination.push(data);
|
20622 | });
|
20623 | };
|
20624 |
|
20625 | return Stream;
|
20626 | }();
|
20627 |
|
20628 |
|
20629 | |
20630 |
|
20631 |
|
20632 |
|
20633 |
|
20634 |
|
20635 |
|
20636 |
|
20637 |
|
20638 | function unpad(padded) {
|
20639 | return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
|
20640 | }
|
20641 |
|
20642 |
|
20643 | |
20644 |
|
20645 |
|
20646 |
|
20647 |
|
20648 |
|
20649 |
|
20650 |
|
20651 |
|
20652 |
|
20653 |
|
20654 |
|
20655 |
|
20656 |
|
20657 |
|
20658 |
|
20659 |
|
20660 |
|
20661 |
|
20662 |
|
20663 |
|
20664 |
|
20665 |
|
20666 |
|
20667 |
|
20668 |
|
20669 |
|
20670 |
|
20671 |
|
20672 |
|
20673 |
|
20674 |
|
20675 |
|
20676 |
|
20677 |
|
20678 |
|
20679 |
|
20680 |
|
20681 |
|
20682 | |
20683 |
|
20684 |
|
20685 |
|
20686 |
|
20687 |
|
20688 |
|
20689 | var precompute = function precompute() {
|
20690 | var tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
20691 | var encTable = tables[0];
|
20692 | var decTable = tables[1];
|
20693 | var sbox = encTable[4];
|
20694 | var sboxInv = decTable[4];
|
20695 | var i;
|
20696 | var x;
|
20697 | var xInv;
|
20698 | var d = [];
|
20699 | var th = [];
|
20700 | var x2;
|
20701 | var x4;
|
20702 | var x8;
|
20703 | var s;
|
20704 | var tEnc;
|
20705 | var tDec;
|
20706 |
|
20707 | for (i = 0; i < 256; i++) {
|
20708 | th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
20709 | }
|
20710 |
|
20711 | for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
20712 |
|
20713 | s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
20714 | s = s >> 8 ^ s & 255 ^ 99;
|
20715 | sbox[x] = s;
|
20716 | sboxInv[s] = x;
|
20717 |
|
20718 | x8 = d[x4 = d[x2 = d[x]]];
|
20719 | tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
20720 | tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
20721 |
|
20722 | for (i = 0; i < 4; i++) {
|
20723 | encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
20724 | decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
20725 | }
|
20726 | }
|
20727 |
|
20728 |
|
20729 | for (i = 0; i < 5; i++) {
|
20730 | encTable[i] = encTable[i].slice(0);
|
20731 | decTable[i] = decTable[i].slice(0);
|
20732 | }
|
20733 |
|
20734 | return tables;
|
20735 | };
|
20736 |
|
20737 | var aesTables = null;
|
20738 | |
20739 |
|
20740 |
|
20741 |
|
20742 |
|
20743 |
|
20744 |
|
20745 |
|
20746 | var AES = function () {
|
20747 | function AES(key) {
|
20748 | |
20749 |
|
20750 |
|
20751 |
|
20752 |
|
20753 |
|
20754 |
|
20755 |
|
20756 |
|
20757 |
|
20758 |
|
20759 |
|
20760 |
|
20761 |
|
20762 | if (!aesTables) {
|
20763 | aesTables = precompute();
|
20764 | }
|
20765 |
|
20766 |
|
20767 | 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()]];
|
20768 | var i;
|
20769 | var j;
|
20770 | var tmp;
|
20771 | var sbox = this._tables[0][4];
|
20772 | var decTable = this._tables[1];
|
20773 | var keyLen = key.length;
|
20774 | var rcon = 1;
|
20775 |
|
20776 | if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
20777 | throw new Error('Invalid aes key size');
|
20778 | }
|
20779 |
|
20780 | var encKey = key.slice(0);
|
20781 | var decKey = [];
|
20782 | this._key = [encKey, decKey];
|
20783 |
|
20784 | for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
20785 | tmp = encKey[i - 1];
|
20786 |
|
20787 | if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
|
20788 | tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
20789 |
|
20790 | if (i % keyLen === 0) {
|
20791 | tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
20792 | rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
20793 | }
|
20794 | }
|
20795 |
|
20796 | encKey[i] = encKey[i - keyLen] ^ tmp;
|
20797 | }
|
20798 |
|
20799 |
|
20800 | for (j = 0; i; j++, i--) {
|
20801 | tmp = encKey[j & 3 ? i : i - 4];
|
20802 |
|
20803 | if (i <= 4 || j < 4) {
|
20804 | decKey[j] = tmp;
|
20805 | } else {
|
20806 | decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
|
20807 | }
|
20808 | }
|
20809 | }
|
20810 | |
20811 |
|
20812 |
|
20813 |
|
20814 |
|
20815 |
|
20816 |
|
20817 |
|
20818 |
|
20819 |
|
20820 |
|
20821 |
|
20822 |
|
20823 |
|
20824 |
|
20825 | var _proto = AES.prototype;
|
20826 |
|
20827 | _proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
|
20828 | var key = this._key[1];
|
20829 |
|
20830 | var a = encrypted0 ^ key[0];
|
20831 | var b = encrypted3 ^ key[1];
|
20832 | var c = encrypted2 ^ key[2];
|
20833 | var d = encrypted1 ^ key[3];
|
20834 | var a2;
|
20835 | var b2;
|
20836 | var c2;
|
20837 |
|
20838 | var nInnerRounds = key.length / 4 - 2;
|
20839 | var i;
|
20840 | var kIndex = 4;
|
20841 | var table = this._tables[1];
|
20842 |
|
20843 | var table0 = table[0];
|
20844 | var table1 = table[1];
|
20845 | var table2 = table[2];
|
20846 | var table3 = table[3];
|
20847 | var sbox = table[4];
|
20848 |
|
20849 | for (i = 0; i < nInnerRounds; i++) {
|
20850 | a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
|
20851 | b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
|
20852 | c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
|
20853 | d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
|
20854 | kIndex += 4;
|
20855 | a = a2;
|
20856 | b = b2;
|
20857 | c = c2;
|
20858 | }
|
20859 |
|
20860 |
|
20861 | for (i = 0; i < 4; i++) {
|
20862 | out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
|
20863 | a2 = a;
|
20864 | a = b;
|
20865 | b = c;
|
20866 | c = d;
|
20867 | d = a2;
|
20868 | }
|
20869 | };
|
20870 |
|
20871 | return AES;
|
20872 | }();
|
20873 | |
20874 |
|
20875 |
|
20876 |
|
20877 |
|
20878 |
|
20879 |
|
20880 |
|
20881 |
|
20882 | var AsyncStream = function (_Stream) {
|
20883 | inheritsLoose(AsyncStream, _Stream);
|
20884 |
|
20885 | function AsyncStream() {
|
20886 | var _this;
|
20887 |
|
20888 | _this = _Stream.call(this, Stream) || this;
|
20889 | _this.jobs = [];
|
20890 | _this.delay = 1;
|
20891 | _this.timeout_ = null;
|
20892 | return _this;
|
20893 | }
|
20894 | |
20895 |
|
20896 |
|
20897 |
|
20898 |
|
20899 |
|
20900 |
|
20901 | var _proto = AsyncStream.prototype;
|
20902 |
|
20903 | _proto.processJob_ = function processJob_() {
|
20904 | this.jobs.shift()();
|
20905 |
|
20906 | if (this.jobs.length) {
|
20907 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
20908 | } else {
|
20909 | this.timeout_ = null;
|
20910 | }
|
20911 | }
|
20912 | |
20913 |
|
20914 |
|
20915 |
|
20916 |
|
20917 | ;
|
20918 |
|
20919 | _proto.push = function push(job) {
|
20920 | this.jobs.push(job);
|
20921 |
|
20922 | if (!this.timeout_) {
|
20923 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
20924 | }
|
20925 | };
|
20926 |
|
20927 | return AsyncStream;
|
20928 | }(Stream);
|
20929 | |
20930 |
|
20931 |
|
20932 |
|
20933 |
|
20934 |
|
20935 | var ntoh = function ntoh(word) {
|
20936 | return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
|
20937 | };
|
20938 | |
20939 |
|
20940 |
|
20941 |
|
20942 |
|
20943 |
|
20944 |
|
20945 |
|
20946 |
|
20947 |
|
20948 |
|
20949 |
|
20950 |
|
20951 |
|
20952 |
|
20953 | var decrypt = function decrypt(encrypted, key, initVector) {
|
20954 |
|
20955 | var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
|
20956 | var decipher = new AES(Array.prototype.slice.call(key));
|
20957 |
|
20958 | var decrypted = new Uint8Array(encrypted.byteLength);
|
20959 | var decrypted32 = new Int32Array(decrypted.buffer);
|
20960 |
|
20961 |
|
20962 | var init0;
|
20963 | var init1;
|
20964 | var init2;
|
20965 | var init3;
|
20966 | var encrypted0;
|
20967 | var encrypted1;
|
20968 | var encrypted2;
|
20969 | var encrypted3;
|
20970 |
|
20971 | var wordIx;
|
20972 |
|
20973 |
|
20974 | init0 = initVector[0];
|
20975 | init1 = initVector[1];
|
20976 | init2 = initVector[2];
|
20977 | init3 = initVector[3];
|
20978 |
|
20979 |
|
20980 | for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
|
20981 |
|
20982 |
|
20983 | encrypted0 = ntoh(encrypted32[wordIx]);
|
20984 | encrypted1 = ntoh(encrypted32[wordIx + 1]);
|
20985 | encrypted2 = ntoh(encrypted32[wordIx + 2]);
|
20986 | encrypted3 = ntoh(encrypted32[wordIx + 3]);
|
20987 |
|
20988 | decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
|
20989 |
|
20990 |
|
20991 | decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
|
20992 | decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
|
20993 | decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
|
20994 | decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
|
20995 |
|
20996 | init0 = encrypted0;
|
20997 | init1 = encrypted1;
|
20998 | init2 = encrypted2;
|
20999 | init3 = encrypted3;
|
21000 | }
|
21001 |
|
21002 | return decrypted;
|
21003 | };
|
21004 | |
21005 |
|
21006 |
|
21007 |
|
21008 |
|
21009 |
|
21010 |
|
21011 |
|
21012 |
|
21013 |
|
21014 |
|
21015 |
|
21016 |
|
21017 | var Decrypter = function () {
|
21018 | function Decrypter(encrypted, key, initVector, done) {
|
21019 | var step = Decrypter.STEP;
|
21020 | var encrypted32 = new Int32Array(encrypted.buffer);
|
21021 | var decrypted = new Uint8Array(encrypted.byteLength);
|
21022 | var i = 0;
|
21023 | this.asyncStream_ = new AsyncStream();
|
21024 |
|
21025 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
21026 |
|
21027 | for (i = step; i < encrypted32.length; i += step) {
|
21028 | initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
|
21029 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
21030 | }
|
21031 |
|
21032 |
|
21033 | this.asyncStream_.push(function () {
|
21034 |
|
21035 | done(null, unpad(decrypted));
|
21036 | });
|
21037 | }
|
21038 | |
21039 |
|
21040 |
|
21041 |
|
21042 |
|
21043 |
|
21044 |
|
21045 | var _proto = Decrypter.prototype;
|
21046 | |
21047 |
|
21048 |
|
21049 |
|
21050 | _proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
|
21051 | return function () {
|
21052 | var bytes = decrypt(encrypted, key, initVector);
|
21053 | decrypted.set(bytes, encrypted.byteOffset);
|
21054 | };
|
21055 | };
|
21056 |
|
21057 | createClass(Decrypter, null, [{
|
21058 | key: "STEP",
|
21059 | get: function get() {
|
21060 |
|
21061 | return 32000;
|
21062 | }
|
21063 | }]);
|
21064 | return Decrypter;
|
21065 | }();
|
21066 | |
21067 |
|
21068 |
|
21069 |
|
21070 | |
21071 |
|
21072 |
|
21073 |
|
21074 |
|
21075 |
|
21076 |
|
21077 |
|
21078 |
|
21079 |
|
21080 |
|
21081 |
|
21082 | var createTransferableMessage = function createTransferableMessage(message) {
|
21083 | var transferable = {};
|
21084 | Object.keys(message).forEach(function (key) {
|
21085 | var value = message[key];
|
21086 |
|
21087 | if (ArrayBuffer.isView(value)) {
|
21088 | transferable[key] = {
|
21089 | bytes: value.buffer,
|
21090 | byteOffset: value.byteOffset,
|
21091 | byteLength: value.byteLength
|
21092 | };
|
21093 | } else {
|
21094 | transferable[key] = value;
|
21095 | }
|
21096 | });
|
21097 | return transferable;
|
21098 | };
|
21099 |
|
21100 |
|
21101 | |
21102 |
|
21103 |
|
21104 |
|
21105 |
|
21106 |
|
21107 |
|
21108 | self.onmessage = function (event) {
|
21109 | var data = event.data;
|
21110 | var encrypted = new Uint8Array(data.encrypted.bytes, data.encrypted.byteOffset, data.encrypted.byteLength);
|
21111 | var key = new Uint32Array(data.key.bytes, data.key.byteOffset, data.key.byteLength / 4);
|
21112 | var iv = new Uint32Array(data.iv.bytes, data.iv.byteOffset, data.iv.byteLength / 4);
|
21113 |
|
21114 |
|
21115 | new Decrypter(encrypted, key, iv, function (err, bytes) {
|
21116 | self.postMessage(createTransferableMessage({
|
21117 | source: data.source,
|
21118 | decrypted: bytes
|
21119 | }), [bytes.buffer]);
|
21120 | });
|
21121 |
|
21122 | };
|
21123 | }));
|
21124 | var Decrypter = factory(workerCode);
|
21125 |
|
21126 |
|
21127 |
|
21128 |
|
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 | var audioTrackKind_ = function audioTrackKind_(properties) {
|
21134 | var kind = properties.default ? 'main' : 'alternative';
|
21135 |
|
21136 | if (properties.characteristics && properties.characteristics.indexOf('public.accessibility.describes-video') >= 0) {
|
21137 | kind = 'main-desc';
|
21138 | }
|
21139 |
|
21140 | return kind;
|
21141 | };
|
21142 |
|
21143 |
|
21144 |
|
21145 |
|
21146 |
|
21147 |
|
21148 |
|
21149 |
|
21150 |
|
21151 |
|
21152 |
|
21153 | var stopLoaders = function stopLoaders(segmentLoader, mediaType) {
|
21154 | segmentLoader.abort();
|
21155 | segmentLoader.pause();
|
21156 |
|
21157 | if (mediaType && mediaType.activePlaylistLoader) {
|
21158 | mediaType.activePlaylistLoader.pause();
|
21159 | mediaType.activePlaylistLoader = null;
|
21160 | }
|
21161 | };
|
21162 |
|
21163 |
|
21164 |
|
21165 |
|
21166 |
|
21167 |
|
21168 |
|
21169 |
|
21170 |
|
21171 |
|
21172 | var startLoaders = function startLoaders(playlistLoader, mediaType) {
|
21173 |
|
21174 |
|
21175 | mediaType.activePlaylistLoader = playlistLoader;
|
21176 | playlistLoader.load();
|
21177 | };
|
21178 |
|
21179 |
|
21180 |
|
21181 |
|
21182 |
|
21183 |
|
21184 |
|
21185 |
|
21186 |
|
21187 |
|
21188 |
|
21189 |
|
21190 |
|
21191 |
|
21192 |
|
21193 |
|
21194 | var onGroupChanged = function onGroupChanged(type, settings) {
|
21195 | return function () {
|
21196 | var _settings$segmentLoad = settings.segmentLoaders,
|
21197 | segmentLoader = _settings$segmentLoad[type],
|
21198 | mainSegmentLoader = _settings$segmentLoad.main,
|
21199 | mediaType = settings.mediaTypes[type];
|
21200 | var activeTrack = mediaType.activeTrack();
|
21201 | var activeGroup = mediaType.getActiveGroup();
|
21202 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
21203 | var lastGroup = mediaType.lastGroup_;
|
21204 |
|
21205 | if (activeGroup && lastGroup && activeGroup.id === lastGroup.id) {
|
21206 | return;
|
21207 | }
|
21208 |
|
21209 | mediaType.lastGroup_ = activeGroup;
|
21210 | mediaType.lastTrack_ = activeTrack;
|
21211 | stopLoaders(segmentLoader, mediaType);
|
21212 |
|
21213 | if (!activeGroup || activeGroup.isMasterPlaylist) {
|
21214 |
|
21215 | return;
|
21216 | }
|
21217 |
|
21218 | if (!activeGroup.playlistLoader) {
|
21219 | if (previousActiveLoader) {
|
21220 |
|
21221 |
|
21222 |
|
21223 |
|
21224 | mainSegmentLoader.resetEverything();
|
21225 | }
|
21226 |
|
21227 | return;
|
21228 | }
|
21229 |
|
21230 |
|
21231 | segmentLoader.resyncLoader();
|
21232 | startLoaders(activeGroup.playlistLoader, mediaType);
|
21233 | };
|
21234 | };
|
21235 | var onGroupChanging = function onGroupChanging(type, settings) {
|
21236 | return function () {
|
21237 | var segmentLoader = settings.segmentLoaders[type],
|
21238 | mediaType = settings.mediaTypes[type];
|
21239 | mediaType.lastGroup_ = null;
|
21240 | segmentLoader.abort();
|
21241 | segmentLoader.pause();
|
21242 | };
|
21243 | };
|
21244 |
|
21245 |
|
21246 |
|
21247 |
|
21248 |
|
21249 |
|
21250 |
|
21251 |
|
21252 |
|
21253 |
|
21254 |
|
21255 |
|
21256 |
|
21257 |
|
21258 |
|
21259 | var onTrackChanged = function onTrackChanged(type, settings) {
|
21260 | return function () {
|
21261 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
21262 | _settings$segmentLoad2 = settings.segmentLoaders,
|
21263 | segmentLoader = _settings$segmentLoad2[type],
|
21264 | mainSegmentLoader = _settings$segmentLoad2.main,
|
21265 | mediaType = settings.mediaTypes[type];
|
21266 | var activeTrack = mediaType.activeTrack();
|
21267 | var activeGroup = mediaType.getActiveGroup();
|
21268 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
21269 | var lastTrack = mediaType.lastTrack_;
|
21270 |
|
21271 | if (lastTrack && activeTrack && lastTrack.id === activeTrack.id) {
|
21272 | return;
|
21273 | }
|
21274 |
|
21275 | mediaType.lastGroup_ = activeGroup;
|
21276 | mediaType.lastTrack_ = activeTrack;
|
21277 | stopLoaders(segmentLoader, mediaType);
|
21278 |
|
21279 | if (!activeGroup) {
|
21280 |
|
21281 | return;
|
21282 | }
|
21283 |
|
21284 | if (activeGroup.isMasterPlaylist) {
|
21285 |
|
21286 | if (!activeTrack || !lastTrack || activeTrack.id === lastTrack.id) {
|
21287 | return;
|
21288 | }
|
21289 |
|
21290 | var mpc = settings.vhs.masterPlaylistController_;
|
21291 | var newPlaylist = mpc.selectPlaylist();
|
21292 |
|
21293 | if (mpc.media() === newPlaylist) {
|
21294 | return;
|
21295 | }
|
21296 |
|
21297 | mediaType.logger_("track change. Switching master audio from " + lastTrack.id + " to " + activeTrack.id);
|
21298 | masterPlaylistLoader.pause();
|
21299 | mainSegmentLoader.resetEverything();
|
21300 | mpc.fastQualityChange_(newPlaylist);
|
21301 | return;
|
21302 | }
|
21303 |
|
21304 | if (type === 'AUDIO') {
|
21305 | if (!activeGroup.playlistLoader) {
|
21306 |
|
21307 |
|
21308 |
|
21309 | mainSegmentLoader.setAudio(true);
|
21310 |
|
21311 |
|
21312 | mainSegmentLoader.resetEverything();
|
21313 | return;
|
21314 | }
|
21315 |
|
21316 |
|
21317 |
|
21318 |
|
21319 | segmentLoader.setAudio(true);
|
21320 | mainSegmentLoader.setAudio(false);
|
21321 | }
|
21322 |
|
21323 | if (previousActiveLoader === activeGroup.playlistLoader) {
|
21324 |
|
21325 |
|
21326 |
|
21327 | startLoaders(activeGroup.playlistLoader, mediaType);
|
21328 | return;
|
21329 | }
|
21330 |
|
21331 | if (segmentLoader.track) {
|
21332 |
|
21333 | segmentLoader.track(activeTrack);
|
21334 | }
|
21335 |
|
21336 |
|
21337 | segmentLoader.resetEverything();
|
21338 | startLoaders(activeGroup.playlistLoader, mediaType);
|
21339 | };
|
21340 | };
|
21341 | var onError = {
|
21342 | |
21343 |
|
21344 |
|
21345 |
|
21346 |
|
21347 |
|
21348 |
|
21349 |
|
21350 |
|
21351 |
|
21352 |
|
21353 |
|
21354 |
|
21355 | AUDIO: function AUDIO(type, settings) {
|
21356 | return function () {
|
21357 | var segmentLoader = settings.segmentLoaders[type],
|
21358 | mediaType = settings.mediaTypes[type],
|
21359 | blacklistCurrentPlaylist = settings.blacklistCurrentPlaylist;
|
21360 | stopLoaders(segmentLoader, mediaType);
|
21361 |
|
21362 | var activeTrack = mediaType.activeTrack();
|
21363 | var activeGroup = mediaType.activeGroup();
|
21364 | var id = (activeGroup.filter(function (group) {
|
21365 | return group.default;
|
21366 | })[0] || activeGroup[0]).id;
|
21367 | var defaultTrack = mediaType.tracks[id];
|
21368 |
|
21369 | if (activeTrack === defaultTrack) {
|
21370 |
|
21371 |
|
21372 | blacklistCurrentPlaylist({
|
21373 | message: 'Problem encountered loading the default audio track.'
|
21374 | });
|
21375 | return;
|
21376 | }
|
21377 |
|
21378 | videojs__default["default"].log.warn('Problem encountered loading the alternate audio track.' + 'Switching back to default.');
|
21379 |
|
21380 | for (var trackId in mediaType.tracks) {
|
21381 | mediaType.tracks[trackId].enabled = mediaType.tracks[trackId] === defaultTrack;
|
21382 | }
|
21383 |
|
21384 | mediaType.onTrackChanged();
|
21385 | };
|
21386 | },
|
21387 |
|
21388 | |
21389 |
|
21390 |
|
21391 |
|
21392 |
|
21393 |
|
21394 |
|
21395 |
|
21396 |
|
21397 |
|
21398 |
|
21399 |
|
21400 | SUBTITLES: function SUBTITLES(type, settings) {
|
21401 | return function () {
|
21402 | var segmentLoader = settings.segmentLoaders[type],
|
21403 | mediaType = settings.mediaTypes[type];
|
21404 | videojs__default["default"].log.warn('Problem encountered loading the subtitle track.' + 'Disabling subtitle track.');
|
21405 | stopLoaders(segmentLoader, mediaType);
|
21406 | var track = mediaType.activeTrack();
|
21407 |
|
21408 | if (track) {
|
21409 | track.mode = 'disabled';
|
21410 | }
|
21411 |
|
21412 | mediaType.onTrackChanged();
|
21413 | };
|
21414 | }
|
21415 | };
|
21416 | var setupListeners = {
|
21417 | |
21418 |
|
21419 |
|
21420 |
|
21421 |
|
21422 |
|
21423 |
|
21424 |
|
21425 |
|
21426 |
|
21427 |
|
21428 | AUDIO: function AUDIO(type, playlistLoader, settings) {
|
21429 | if (!playlistLoader) {
|
21430 |
|
21431 | return;
|
21432 | }
|
21433 |
|
21434 | var tech = settings.tech,
|
21435 | requestOptions = settings.requestOptions,
|
21436 | segmentLoader = settings.segmentLoaders[type];
|
21437 | playlistLoader.on('loadedmetadata', function () {
|
21438 | var media = playlistLoader.media();
|
21439 | segmentLoader.playlist(media, requestOptions);
|
21440 |
|
21441 |
|
21442 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
21443 | segmentLoader.load();
|
21444 | }
|
21445 | });
|
21446 | playlistLoader.on('loadedplaylist', function () {
|
21447 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
21448 |
|
21449 | if (!tech.paused()) {
|
21450 | segmentLoader.load();
|
21451 | }
|
21452 | });
|
21453 | playlistLoader.on('error', onError[type](type, settings));
|
21454 | },
|
21455 |
|
21456 | |
21457 |
|
21458 |
|
21459 |
|
21460 |
|
21461 |
|
21462 |
|
21463 |
|
21464 |
|
21465 |
|
21466 |
|
21467 | SUBTITLES: function SUBTITLES(type, playlistLoader, settings) {
|
21468 | var tech = settings.tech,
|
21469 | requestOptions = settings.requestOptions,
|
21470 | segmentLoader = settings.segmentLoaders[type],
|
21471 | mediaType = settings.mediaTypes[type];
|
21472 | playlistLoader.on('loadedmetadata', function () {
|
21473 | var media = playlistLoader.media();
|
21474 | segmentLoader.playlist(media, requestOptions);
|
21475 | segmentLoader.track(mediaType.activeTrack());
|
21476 |
|
21477 |
|
21478 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
21479 | segmentLoader.load();
|
21480 | }
|
21481 | });
|
21482 | playlistLoader.on('loadedplaylist', function () {
|
21483 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
21484 |
|
21485 | if (!tech.paused()) {
|
21486 | segmentLoader.load();
|
21487 | }
|
21488 | });
|
21489 | playlistLoader.on('error', onError[type](type, settings));
|
21490 | }
|
21491 | };
|
21492 | var initialize = {
|
21493 | |
21494 |
|
21495 |
|
21496 |
|
21497 |
|
21498 |
|
21499 |
|
21500 |
|
21501 |
|
21502 | 'AUDIO': function AUDIO(type, settings) {
|
21503 | var vhs = settings.vhs,
|
21504 | sourceType = settings.sourceType,
|
21505 | segmentLoader = settings.segmentLoaders[type],
|
21506 | requestOptions = settings.requestOptions,
|
21507 | mediaGroups = settings.master.mediaGroups,
|
21508 | _settings$mediaTypes$ = settings.mediaTypes[type],
|
21509 | groups = _settings$mediaTypes$.groups,
|
21510 | tracks = _settings$mediaTypes$.tracks,
|
21511 | logger_ = _settings$mediaTypes$.logger_,
|
21512 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
21513 | var audioOnlyMaster = isAudioOnly(masterPlaylistLoader.master);
|
21514 |
|
21515 | if (!mediaGroups[type] || Object.keys(mediaGroups[type]).length === 0) {
|
21516 | mediaGroups[type] = {
|
21517 | main: {
|
21518 | default: {
|
21519 | default: true
|
21520 | }
|
21521 | }
|
21522 | };
|
21523 |
|
21524 | if (audioOnlyMaster) {
|
21525 | mediaGroups[type].main.default.playlists = masterPlaylistLoader.master.playlists;
|
21526 | }
|
21527 | }
|
21528 |
|
21529 | for (var groupId in mediaGroups[type]) {
|
21530 | if (!groups[groupId]) {
|
21531 | groups[groupId] = [];
|
21532 | }
|
21533 |
|
21534 | for (var variantLabel in mediaGroups[type][groupId]) {
|
21535 | var properties = mediaGroups[type][groupId][variantLabel];
|
21536 | var playlistLoader = void 0;
|
21537 |
|
21538 | if (audioOnlyMaster) {
|
21539 | logger_("AUDIO group '" + groupId + "' label '" + variantLabel + "' is a master playlist");
|
21540 | properties.isMasterPlaylist = true;
|
21541 | playlistLoader = null;
|
21542 |
|
21543 | } else if (sourceType === 'vhs-json' && properties.playlists) {
|
21544 | playlistLoader = new PlaylistLoader(properties.playlists[0], vhs, requestOptions);
|
21545 | } else if (properties.resolvedUri) {
|
21546 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
21547 |
|
21548 | } else if (properties.playlists && sourceType === 'dash') {
|
21549 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
21550 | } else {
|
21551 |
|
21552 |
|
21553 | playlistLoader = null;
|
21554 | }
|
21555 |
|
21556 | properties = videojs__default["default"].mergeOptions({
|
21557 | id: variantLabel,
|
21558 | playlistLoader: playlistLoader
|
21559 | }, properties);
|
21560 | setupListeners[type](type, properties.playlistLoader, settings);
|
21561 | groups[groupId].push(properties);
|
21562 |
|
21563 | if (typeof tracks[variantLabel] === 'undefined') {
|
21564 | var track = new videojs__default["default"].AudioTrack({
|
21565 | id: variantLabel,
|
21566 | kind: audioTrackKind_(properties),
|
21567 | enabled: false,
|
21568 | language: properties.language,
|
21569 | default: properties.default,
|
21570 | label: variantLabel
|
21571 | });
|
21572 | tracks[variantLabel] = track;
|
21573 | }
|
21574 | }
|
21575 | }
|
21576 |
|
21577 |
|
21578 | segmentLoader.on('error', onError[type](type, settings));
|
21579 | },
|
21580 |
|
21581 | |
21582 |
|
21583 |
|
21584 |
|
21585 |
|
21586 |
|
21587 |
|
21588 |
|
21589 |
|
21590 | 'SUBTITLES': function SUBTITLES(type, settings) {
|
21591 | var tech = settings.tech,
|
21592 | vhs = settings.vhs,
|
21593 | sourceType = settings.sourceType,
|
21594 | segmentLoader = settings.segmentLoaders[type],
|
21595 | requestOptions = settings.requestOptions,
|
21596 | mediaGroups = settings.master.mediaGroups,
|
21597 | _settings$mediaTypes$2 = settings.mediaTypes[type],
|
21598 | groups = _settings$mediaTypes$2.groups,
|
21599 | tracks = _settings$mediaTypes$2.tracks,
|
21600 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
21601 |
|
21602 | for (var groupId in mediaGroups[type]) {
|
21603 | if (!groups[groupId]) {
|
21604 | groups[groupId] = [];
|
21605 | }
|
21606 |
|
21607 | for (var variantLabel in mediaGroups[type][groupId]) {
|
21608 | if (mediaGroups[type][groupId][variantLabel].forced) {
|
21609 |
|
21610 |
|
21611 |
|
21612 |
|
21613 |
|
21614 |
|
21615 |
|
21616 |
|
21617 | continue;
|
21618 | }
|
21619 |
|
21620 | var properties = mediaGroups[type][groupId][variantLabel];
|
21621 | var playlistLoader = void 0;
|
21622 |
|
21623 | if (sourceType === 'hls') {
|
21624 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
21625 | } else if (sourceType === 'dash') {
|
21626 | var playlists = properties.playlists.filter(function (p) {
|
21627 | return p.excludeUntil !== Infinity;
|
21628 | });
|
21629 |
|
21630 | if (!playlists.length) {
|
21631 | return;
|
21632 | }
|
21633 |
|
21634 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
21635 | } else if (sourceType === 'vhs-json') {
|
21636 | playlistLoader = new PlaylistLoader(
|
21637 |
|
21638 | properties.playlists ? properties.playlists[0] : properties.resolvedUri, vhs, requestOptions);
|
21639 | }
|
21640 |
|
21641 | properties = videojs__default["default"].mergeOptions({
|
21642 | id: variantLabel,
|
21643 | playlistLoader: playlistLoader
|
21644 | }, properties);
|
21645 | setupListeners[type](type, properties.playlistLoader, settings);
|
21646 | groups[groupId].push(properties);
|
21647 |
|
21648 | if (typeof tracks[variantLabel] === 'undefined') {
|
21649 | var track = tech.addRemoteTextTrack({
|
21650 | id: variantLabel,
|
21651 | kind: 'subtitles',
|
21652 | default: properties.default && properties.autoselect,
|
21653 | language: properties.language,
|
21654 | label: variantLabel
|
21655 | }, false).track;
|
21656 | tracks[variantLabel] = track;
|
21657 | }
|
21658 | }
|
21659 | }
|
21660 |
|
21661 |
|
21662 | segmentLoader.on('error', onError[type](type, settings));
|
21663 | },
|
21664 |
|
21665 | |
21666 |
|
21667 |
|
21668 |
|
21669 |
|
21670 |
|
21671 |
|
21672 |
|
21673 |
|
21674 | 'CLOSED-CAPTIONS': function CLOSEDCAPTIONS(type, settings) {
|
21675 | var tech = settings.tech,
|
21676 | mediaGroups = settings.master.mediaGroups,
|
21677 | _settings$mediaTypes$3 = settings.mediaTypes[type],
|
21678 | groups = _settings$mediaTypes$3.groups,
|
21679 | tracks = _settings$mediaTypes$3.tracks;
|
21680 |
|
21681 | for (var groupId in mediaGroups[type]) {
|
21682 | if (!groups[groupId]) {
|
21683 | groups[groupId] = [];
|
21684 | }
|
21685 |
|
21686 | for (var variantLabel in mediaGroups[type][groupId]) {
|
21687 | var properties = mediaGroups[type][groupId][variantLabel];
|
21688 |
|
21689 | if (!/^(?:CC|SERVICE)/.test(properties.instreamId)) {
|
21690 | continue;
|
21691 | }
|
21692 |
|
21693 | var captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
|
21694 | var newProps = {
|
21695 | label: variantLabel,
|
21696 | language: properties.language,
|
21697 | instreamId: properties.instreamId,
|
21698 | default: properties.default && properties.autoselect
|
21699 | };
|
21700 |
|
21701 | if (captionServices[newProps.instreamId]) {
|
21702 | newProps = videojs__default["default"].mergeOptions(newProps, captionServices[newProps.instreamId]);
|
21703 | }
|
21704 |
|
21705 | if (newProps.default === undefined) {
|
21706 | delete newProps.default;
|
21707 | }
|
21708 |
|
21709 |
|
21710 |
|
21711 | groups[groupId].push(videojs__default["default"].mergeOptions({
|
21712 | id: variantLabel
|
21713 | }, properties));
|
21714 |
|
21715 | if (typeof tracks[variantLabel] === 'undefined') {
|
21716 | var track = tech.addRemoteTextTrack({
|
21717 | id: newProps.instreamId,
|
21718 | kind: 'captions',
|
21719 | default: newProps.default,
|
21720 | language: newProps.language,
|
21721 | label: newProps.label
|
21722 | }, false).track;
|
21723 | tracks[variantLabel] = track;
|
21724 | }
|
21725 | }
|
21726 | }
|
21727 | }
|
21728 | };
|
21729 |
|
21730 | var groupMatch = function groupMatch(list, media) {
|
21731 | for (var i = 0; i < list.length; i++) {
|
21732 | if (playlistMatch(media, list[i])) {
|
21733 | return true;
|
21734 | }
|
21735 |
|
21736 | if (list[i].playlists && groupMatch(list[i].playlists, media)) {
|
21737 | return true;
|
21738 | }
|
21739 | }
|
21740 |
|
21741 | return false;
|
21742 | };
|
21743 |
|
21744 |
|
21745 |
|
21746 |
|
21747 |
|
21748 |
|
21749 |
|
21750 |
|
21751 |
|
21752 |
|
21753 |
|
21754 |
|
21755 |
|
21756 |
|
21757 |
|
21758 |
|
21759 | var activeGroup = function activeGroup(type, settings) {
|
21760 | return function (track) {
|
21761 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
21762 | groups = settings.mediaTypes[type].groups;
|
21763 | var media = masterPlaylistLoader.media();
|
21764 |
|
21765 | if (!media) {
|
21766 | return null;
|
21767 | }
|
21768 |
|
21769 | var variants = null;
|
21770 |
|
21771 | if (media.attributes[type]) {
|
21772 | variants = groups[media.attributes[type]];
|
21773 | }
|
21774 |
|
21775 | var groupKeys = Object.keys(groups);
|
21776 |
|
21777 | if (!variants) {
|
21778 |
|
21779 |
|
21780 |
|
21781 | if (type === 'AUDIO' && groupKeys.length > 1 && isAudioOnly(settings.master)) {
|
21782 | for (var i = 0; i < groupKeys.length; i++) {
|
21783 | var groupPropertyList = groups[groupKeys[i]];
|
21784 |
|
21785 | if (groupMatch(groupPropertyList, media)) {
|
21786 | variants = groupPropertyList;
|
21787 | break;
|
21788 | }
|
21789 | }
|
21790 |
|
21791 | } else if (groups.main) {
|
21792 | variants = groups.main;
|
21793 | } else if (groupKeys.length === 1) {
|
21794 | variants = groups[groupKeys[0]];
|
21795 | }
|
21796 | }
|
21797 |
|
21798 | if (typeof track === 'undefined') {
|
21799 | return variants;
|
21800 | }
|
21801 |
|
21802 | if (track === null || !variants) {
|
21803 |
|
21804 |
|
21805 | return null;
|
21806 | }
|
21807 |
|
21808 | return variants.filter(function (props) {
|
21809 | return props.id === track.id;
|
21810 | })[0] || null;
|
21811 | };
|
21812 | };
|
21813 | var activeTrack = {
|
21814 | |
21815 |
|
21816 |
|
21817 |
|
21818 |
|
21819 |
|
21820 |
|
21821 |
|
21822 |
|
21823 |
|
21824 |
|
21825 |
|
21826 | AUDIO: function AUDIO(type, settings) {
|
21827 | return function () {
|
21828 | var tracks = settings.mediaTypes[type].tracks;
|
21829 |
|
21830 | for (var id in tracks) {
|
21831 | if (tracks[id].enabled) {
|
21832 | return tracks[id];
|
21833 | }
|
21834 | }
|
21835 |
|
21836 | return null;
|
21837 | };
|
21838 | },
|
21839 |
|
21840 | |
21841 |
|
21842 |
|
21843 |
|
21844 |
|
21845 |
|
21846 |
|
21847 |
|
21848 |
|
21849 |
|
21850 |
|
21851 |
|
21852 | SUBTITLES: function SUBTITLES(type, settings) {
|
21853 | return function () {
|
21854 | var tracks = settings.mediaTypes[type].tracks;
|
21855 |
|
21856 | for (var id in tracks) {
|
21857 | if (tracks[id].mode === 'showing' || tracks[id].mode === 'hidden') {
|
21858 | return tracks[id];
|
21859 | }
|
21860 | }
|
21861 |
|
21862 | return null;
|
21863 | };
|
21864 | }
|
21865 | };
|
21866 | var getActiveGroup = function getActiveGroup(type, _ref) {
|
21867 | var mediaTypes = _ref.mediaTypes;
|
21868 | return function () {
|
21869 | var activeTrack_ = mediaTypes[type].activeTrack();
|
21870 |
|
21871 | if (!activeTrack_) {
|
21872 | return null;
|
21873 | }
|
21874 |
|
21875 | return mediaTypes[type].activeGroup(activeTrack_);
|
21876 | };
|
21877 | };
|
21878 |
|
21879 |
|
21880 |
|
21881 |
|
21882 |
|
21883 |
|
21884 |
|
21885 |
|
21886 |
|
21887 |
|
21888 |
|
21889 |
|
21890 |
|
21891 |
|
21892 |
|
21893 |
|
21894 |
|
21895 |
|
21896 |
|
21897 |
|
21898 |
|
21899 |
|
21900 |
|
21901 | var setupMediaGroups = function setupMediaGroups(settings) {
|
21902 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
21903 | initialize[type](type, settings);
|
21904 | });
|
21905 | var mediaTypes = settings.mediaTypes,
|
21906 | masterPlaylistLoader = settings.masterPlaylistLoader,
|
21907 | tech = settings.tech,
|
21908 | vhs = settings.vhs,
|
21909 | _settings$segmentLoad3 = settings.segmentLoaders,
|
21910 | audioSegmentLoader = _settings$segmentLoad3['AUDIO'],
|
21911 | mainSegmentLoader = _settings$segmentLoad3.main;
|
21912 |
|
21913 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
21914 | mediaTypes[type].activeGroup = activeGroup(type, settings);
|
21915 | mediaTypes[type].activeTrack = activeTrack[type](type, settings);
|
21916 | mediaTypes[type].onGroupChanged = onGroupChanged(type, settings);
|
21917 | mediaTypes[type].onGroupChanging = onGroupChanging(type, settings);
|
21918 | mediaTypes[type].onTrackChanged = onTrackChanged(type, settings);
|
21919 | mediaTypes[type].getActiveGroup = getActiveGroup(type, settings);
|
21920 | });
|
21921 |
|
21922 |
|
21923 | var audioGroup = mediaTypes.AUDIO.activeGroup();
|
21924 |
|
21925 | if (audioGroup) {
|
21926 | var groupId = (audioGroup.filter(function (group) {
|
21927 | return group.default;
|
21928 | })[0] || audioGroup[0]).id;
|
21929 | mediaTypes.AUDIO.tracks[groupId].enabled = true;
|
21930 | mediaTypes.AUDIO.onGroupChanged();
|
21931 | mediaTypes.AUDIO.onTrackChanged();
|
21932 | var activeAudioGroup = mediaTypes.AUDIO.getActiveGroup();
|
21933 |
|
21934 |
|
21935 |
|
21936 | if (!activeAudioGroup.playlistLoader) {
|
21937 |
|
21938 | mainSegmentLoader.setAudio(true);
|
21939 | } else {
|
21940 |
|
21941 | mainSegmentLoader.setAudio(false);
|
21942 | audioSegmentLoader.setAudio(true);
|
21943 | }
|
21944 | }
|
21945 |
|
21946 | masterPlaylistLoader.on('mediachange', function () {
|
21947 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
21948 | return mediaTypes[type].onGroupChanged();
|
21949 | });
|
21950 | });
|
21951 | masterPlaylistLoader.on('mediachanging', function () {
|
21952 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
21953 | return mediaTypes[type].onGroupChanging();
|
21954 | });
|
21955 | });
|
21956 |
|
21957 | var onAudioTrackChanged = function onAudioTrackChanged() {
|
21958 | mediaTypes.AUDIO.onTrackChanged();
|
21959 | tech.trigger({
|
21960 | type: 'usage',
|
21961 | name: 'vhs-audio-change'
|
21962 | });
|
21963 | tech.trigger({
|
21964 | type: 'usage',
|
21965 | name: 'hls-audio-change'
|
21966 | });
|
21967 | };
|
21968 |
|
21969 | tech.audioTracks().addEventListener('change', onAudioTrackChanged);
|
21970 | tech.remoteTextTracks().addEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
21971 | vhs.on('dispose', function () {
|
21972 | tech.audioTracks().removeEventListener('change', onAudioTrackChanged);
|
21973 | tech.remoteTextTracks().removeEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
21974 | });
|
21975 |
|
21976 | tech.clearTracks('audio');
|
21977 |
|
21978 | for (var id in mediaTypes.AUDIO.tracks) {
|
21979 | tech.audioTracks().addTrack(mediaTypes.AUDIO.tracks[id]);
|
21980 | }
|
21981 | };
|
21982 |
|
21983 |
|
21984 |
|
21985 |
|
21986 |
|
21987 |
|
21988 |
|
21989 |
|
21990 |
|
21991 | var createMediaTypes = function createMediaTypes() {
|
21992 | var mediaTypes = {};
|
21993 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
21994 | mediaTypes[type] = {
|
21995 | groups: {},
|
21996 | tracks: {},
|
21997 | activePlaylistLoader: null,
|
21998 | activeGroup: noop,
|
21999 | activeTrack: noop,
|
22000 | getActiveGroup: noop,
|
22001 | onGroupChanged: noop,
|
22002 | onTrackChanged: noop,
|
22003 | lastTrack_: null,
|
22004 | logger_: logger("MediaGroups[" + type + "]")
|
22005 | };
|
22006 | });
|
22007 | return mediaTypes;
|
22008 | };
|
22009 |
|
22010 | var ABORT_EARLY_BLACKLIST_SECONDS = 60 * 2;
|
22011 | var Vhs$1;
|
22012 |
|
22013 |
|
22014 | var loaderStats = ['mediaRequests', 'mediaRequestsAborted', 'mediaRequestsTimedout', 'mediaRequestsErrored', 'mediaTransferDuration', 'mediaBytesTransferred', 'mediaAppends'];
|
22015 |
|
22016 | var sumLoaderStat = function sumLoaderStat(stat) {
|
22017 | return this.audioSegmentLoader_[stat] + this.mainSegmentLoader_[stat];
|
22018 | };
|
22019 |
|
22020 | var shouldSwitchToMedia = function shouldSwitchToMedia(_ref) {
|
22021 | var currentPlaylist = _ref.currentPlaylist,
|
22022 | nextPlaylist = _ref.nextPlaylist,
|
22023 | forwardBuffer = _ref.forwardBuffer,
|
22024 | bufferLowWaterLine = _ref.bufferLowWaterLine,
|
22025 | bufferHighWaterLine = _ref.bufferHighWaterLine,
|
22026 | duration = _ref.duration,
|
22027 | experimentalBufferBasedABR = _ref.experimentalBufferBasedABR,
|
22028 | log = _ref.log;
|
22029 |
|
22030 |
|
22031 | if (!nextPlaylist) {
|
22032 | videojs__default["default"].log.warn('We received no playlist to switch to. Please check your stream.');
|
22033 | return false;
|
22034 | }
|
22035 |
|
22036 | var sharedLogLine = "allowing switch " + (currentPlaylist && currentPlaylist.id || 'null') + " -> " + nextPlaylist.id;
|
22037 |
|
22038 | if (!currentPlaylist) {
|
22039 | log(sharedLogLine + " as current playlist is not set");
|
22040 | return true;
|
22041 | }
|
22042 |
|
22043 |
|
22044 | if (nextPlaylist.id === currentPlaylist.id) {
|
22045 | return false;
|
22046 | }
|
22047 |
|
22048 |
|
22049 |
|
22050 |
|
22051 |
|
22052 | if (!currentPlaylist.endList) {
|
22053 | log(sharedLogLine + " as current playlist is live");
|
22054 | return true;
|
22055 | }
|
22056 |
|
22057 | var maxBufferLowWaterLine = experimentalBufferBasedABR ? Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE : Config.MAX_BUFFER_LOW_WATER_LINE;
|
22058 |
|
22059 |
|
22060 | if (duration < maxBufferLowWaterLine) {
|
22061 | log(sharedLogLine + " as duration < max low water line (" + duration + " < " + maxBufferLowWaterLine + ")");
|
22062 | return true;
|
22063 | }
|
22064 |
|
22065 | var nextBandwidth = nextPlaylist.attributes.BANDWIDTH;
|
22066 | var currBandwidth = currentPlaylist.attributes.BANDWIDTH;
|
22067 |
|
22068 |
|
22069 | if (nextBandwidth < currBandwidth && (!experimentalBufferBasedABR || forwardBuffer < bufferHighWaterLine)) {
|
22070 | var logLine = sharedLogLine + " as next bandwidth < current bandwidth (" + nextBandwidth + " < " + currBandwidth + ")";
|
22071 |
|
22072 | if (experimentalBufferBasedABR) {
|
22073 | logLine += " and forwardBuffer < bufferHighWaterLine (" + forwardBuffer + " < " + bufferHighWaterLine + ")";
|
22074 | }
|
22075 |
|
22076 | log(logLine);
|
22077 | return true;
|
22078 | }
|
22079 |
|
22080 |
|
22081 |
|
22082 | if ((!experimentalBufferBasedABR || nextBandwidth > currBandwidth) && forwardBuffer >= bufferLowWaterLine) {
|
22083 | var _logLine = sharedLogLine + " as forwardBuffer >= bufferLowWaterLine (" + forwardBuffer + " >= " + bufferLowWaterLine + ")";
|
22084 |
|
22085 | if (experimentalBufferBasedABR) {
|
22086 | _logLine += " and next bandwidth > current bandwidth (" + nextBandwidth + " > " + currBandwidth + ")";
|
22087 | }
|
22088 |
|
22089 | log(_logLine);
|
22090 | return true;
|
22091 | }
|
22092 |
|
22093 | log("not " + sharedLogLine + " as no switching criteria met");
|
22094 | return false;
|
22095 | };
|
22096 |
|
22097 |
|
22098 |
|
22099 |
|
22100 |
|
22101 |
|
22102 |
|
22103 |
|
22104 |
|
22105 |
|
22106 |
|
22107 | var MasterPlaylistController = function (_videojs$EventTarget) {
|
22108 | _inheritsLoose__default["default"](MasterPlaylistController, _videojs$EventTarget);
|
22109 |
|
22110 | function MasterPlaylistController(options) {
|
22111 | var _this;
|
22112 |
|
22113 | _this = _videojs$EventTarget.call(this) || this;
|
22114 | var src = options.src,
|
22115 | handleManifestRedirects = options.handleManifestRedirects,
|
22116 | withCredentials = options.withCredentials,
|
22117 | tech = options.tech,
|
22118 | bandwidth = options.bandwidth,
|
22119 | externVhs = options.externVhs,
|
22120 | useCueTags = options.useCueTags,
|
22121 | blacklistDuration = options.blacklistDuration,
|
22122 | enableLowInitialPlaylist = options.enableLowInitialPlaylist,
|
22123 | sourceType = options.sourceType,
|
22124 | cacheEncryptionKeys = options.cacheEncryptionKeys,
|
22125 | experimentalBufferBasedABR = options.experimentalBufferBasedABR,
|
22126 | experimentalLeastPixelDiffSelector = options.experimentalLeastPixelDiffSelector,
|
22127 | captionServices = options.captionServices;
|
22128 |
|
22129 | if (!src) {
|
22130 | throw new Error('A non-empty playlist URL or JSON manifest string is required');
|
22131 | }
|
22132 |
|
22133 | var maxPlaylistRetries = options.maxPlaylistRetries;
|
22134 |
|
22135 | if (maxPlaylistRetries === null || typeof maxPlaylistRetries === 'undefined') {
|
22136 | maxPlaylistRetries = Infinity;
|
22137 | }
|
22138 |
|
22139 | Vhs$1 = externVhs;
|
22140 | _this.experimentalBufferBasedABR = Boolean(experimentalBufferBasedABR);
|
22141 | _this.experimentalLeastPixelDiffSelector = Boolean(experimentalLeastPixelDiffSelector);
|
22142 | _this.withCredentials = withCredentials;
|
22143 | _this.tech_ = tech;
|
22144 | _this.vhs_ = tech.vhs;
|
22145 | _this.sourceType_ = sourceType;
|
22146 | _this.useCueTags_ = useCueTags;
|
22147 | _this.blacklistDuration = blacklistDuration;
|
22148 | _this.maxPlaylistRetries = maxPlaylistRetries;
|
22149 | _this.enableLowInitialPlaylist = enableLowInitialPlaylist;
|
22150 |
|
22151 | if (_this.useCueTags_) {
|
22152 | _this.cueTagsTrack_ = _this.tech_.addTextTrack('metadata', 'ad-cues');
|
22153 | _this.cueTagsTrack_.inBandMetadataTrackDispatchType = '';
|
22154 | }
|
22155 |
|
22156 | _this.requestOptions_ = {
|
22157 | withCredentials: withCredentials,
|
22158 | handleManifestRedirects: handleManifestRedirects,
|
22159 | maxPlaylistRetries: maxPlaylistRetries,
|
22160 | timeout: null
|
22161 | };
|
22162 |
|
22163 | _this.on('error', _this.pauseLoading);
|
22164 |
|
22165 | _this.mediaTypes_ = createMediaTypes();
|
22166 | _this.mediaSource = new window__default["default"].MediaSource();
|
22167 | _this.handleDurationChange_ = _this.handleDurationChange_.bind(_assertThisInitialized__default["default"](_this));
|
22168 | _this.handleSourceOpen_ = _this.handleSourceOpen_.bind(_assertThisInitialized__default["default"](_this));
|
22169 | _this.handleSourceEnded_ = _this.handleSourceEnded_.bind(_assertThisInitialized__default["default"](_this));
|
22170 |
|
22171 | _this.mediaSource.addEventListener('durationchange', _this.handleDurationChange_);
|
22172 |
|
22173 |
|
22174 | _this.mediaSource.addEventListener('sourceopen', _this.handleSourceOpen_);
|
22175 |
|
22176 | _this.mediaSource.addEventListener('sourceended', _this.handleSourceEnded_);
|
22177 |
|
22178 |
|
22179 |
|
22180 | _this.seekable_ = videojs__default["default"].createTimeRanges();
|
22181 | _this.hasPlayed_ = false;
|
22182 | _this.syncController_ = new SyncController(options);
|
22183 | _this.segmentMetadataTrack_ = tech.addRemoteTextTrack({
|
22184 | kind: 'metadata',
|
22185 | label: 'segment-metadata'
|
22186 | }, false).track;
|
22187 | _this.decrypter_ = new Decrypter();
|
22188 | _this.sourceUpdater_ = new SourceUpdater(_this.mediaSource);
|
22189 | _this.inbandTextTracks_ = {};
|
22190 | _this.timelineChangeController_ = new TimelineChangeController();
|
22191 | var segmentLoaderSettings = {
|
22192 | vhs: _this.vhs_,
|
22193 | parse708captions: options.parse708captions,
|
22194 | captionServices: captionServices,
|
22195 | mediaSource: _this.mediaSource,
|
22196 | currentTime: _this.tech_.currentTime.bind(_this.tech_),
|
22197 | seekable: function seekable() {
|
22198 | return _this.seekable();
|
22199 | },
|
22200 | seeking: function seeking() {
|
22201 | return _this.tech_.seeking();
|
22202 | },
|
22203 | duration: function duration() {
|
22204 | return _this.duration();
|
22205 | },
|
22206 | hasPlayed: function hasPlayed() {
|
22207 | return _this.hasPlayed_;
|
22208 | },
|
22209 | goalBufferLength: function goalBufferLength() {
|
22210 | return _this.goalBufferLength();
|
22211 | },
|
22212 | bandwidth: bandwidth,
|
22213 | syncController: _this.syncController_,
|
22214 | decrypter: _this.decrypter_,
|
22215 | sourceType: _this.sourceType_,
|
22216 | inbandTextTracks: _this.inbandTextTracks_,
|
22217 | cacheEncryptionKeys: cacheEncryptionKeys,
|
22218 | sourceUpdater: _this.sourceUpdater_,
|
22219 | timelineChangeController: _this.timelineChangeController_,
|
22220 | experimentalExactManifestTimings: options.experimentalExactManifestTimings
|
22221 | };
|
22222 |
|
22223 |
|
22224 |
|
22225 |
|
22226 | _this.masterPlaylistLoader_ = _this.sourceType_ === 'dash' ? new DashPlaylistLoader(src, _this.vhs_, _this.requestOptions_) : new PlaylistLoader(src, _this.vhs_, _this.requestOptions_);
|
22227 |
|
22228 | _this.setupMasterPlaylistLoaderListeners_();
|
22229 |
|
22230 |
|
22231 |
|
22232 | _this.mainSegmentLoader_ = new SegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
22233 | segmentMetadataTrack: _this.segmentMetadataTrack_,
|
22234 | loaderType: 'main'
|
22235 | }), options);
|
22236 |
|
22237 | _this.audioSegmentLoader_ = new SegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
22238 | loaderType: 'audio'
|
22239 | }), options);
|
22240 | _this.subtitleSegmentLoader_ = new VTTSegmentLoader(videojs__default["default"].mergeOptions(segmentLoaderSettings, {
|
22241 | loaderType: 'vtt',
|
22242 | featuresNativeTextTracks: _this.tech_.featuresNativeTextTracks
|
22243 | }), options);
|
22244 |
|
22245 | _this.setupSegmentLoaderListeners_();
|
22246 |
|
22247 | if (_this.experimentalBufferBasedABR) {
|
22248 | _this.masterPlaylistLoader_.one('loadedplaylist', function () {
|
22249 | return _this.startABRTimer_();
|
22250 | });
|
22251 |
|
22252 | _this.tech_.on('pause', function () {
|
22253 | return _this.stopABRTimer_();
|
22254 | });
|
22255 |
|
22256 | _this.tech_.on('play', function () {
|
22257 | return _this.startABRTimer_();
|
22258 | });
|
22259 | }
|
22260 |
|
22261 |
|
22262 |
|
22263 |
|
22264 |
|
22265 |
|
22266 |
|
22267 |
|
22268 |
|
22269 | loaderStats.forEach(function (stat) {
|
22270 | _this[stat + '_'] = sumLoaderStat.bind(_assertThisInitialized__default["default"](_this), stat);
|
22271 | });
|
22272 | _this.logger_ = logger('MPC');
|
22273 | _this.triggeredFmp4Usage = false;
|
22274 |
|
22275 | if (_this.tech_.preload() === 'none') {
|
22276 | _this.loadOnPlay_ = function () {
|
22277 | _this.loadOnPlay_ = null;
|
22278 |
|
22279 | _this.masterPlaylistLoader_.load();
|
22280 | };
|
22281 |
|
22282 | _this.tech_.one('play', _this.loadOnPlay_);
|
22283 | } else {
|
22284 | _this.masterPlaylistLoader_.load();
|
22285 | }
|
22286 |
|
22287 | _this.timeToLoadedData__ = -1;
|
22288 | _this.mainAppendsToLoadedData__ = -1;
|
22289 | _this.audioAppendsToLoadedData__ = -1;
|
22290 | var event = _this.tech_.preload() === 'none' ? 'play' : 'loadstart';
|
22291 |
|
22292 | _this.tech_.one(event, function () {
|
22293 | var timeToLoadedDataStart = Date.now();
|
22294 |
|
22295 | _this.tech_.one('loadeddata', function () {
|
22296 | _this.timeToLoadedData__ = Date.now() - timeToLoadedDataStart;
|
22297 | _this.mainAppendsToLoadedData__ = _this.mainSegmentLoader_.mediaAppends;
|
22298 | _this.audioAppendsToLoadedData__ = _this.audioSegmentLoader_.mediaAppends;
|
22299 | });
|
22300 | });
|
22301 |
|
22302 | return _this;
|
22303 | }
|
22304 |
|
22305 | var _proto = MasterPlaylistController.prototype;
|
22306 |
|
22307 | _proto.mainAppendsToLoadedData_ = function mainAppendsToLoadedData_() {
|
22308 | return this.mainAppendsToLoadedData__;
|
22309 | };
|
22310 |
|
22311 | _proto.audioAppendsToLoadedData_ = function audioAppendsToLoadedData_() {
|
22312 | return this.audioAppendsToLoadedData__;
|
22313 | };
|
22314 |
|
22315 | _proto.appendsToLoadedData_ = function appendsToLoadedData_() {
|
22316 | var main = this.mainAppendsToLoadedData_();
|
22317 | var audio = this.audioAppendsToLoadedData_();
|
22318 |
|
22319 | if (main === -1 || audio === -1) {
|
22320 | return -1;
|
22321 | }
|
22322 |
|
22323 | return main + audio;
|
22324 | };
|
22325 |
|
22326 | _proto.timeToLoadedData_ = function timeToLoadedData_() {
|
22327 | return this.timeToLoadedData__;
|
22328 | }
|
22329 | |
22330 |
|
22331 |
|
22332 |
|
22333 |
|
22334 |
|
22335 | ;
|
22336 |
|
22337 | _proto.checkABR_ = function checkABR_() {
|
22338 | var nextPlaylist = this.selectPlaylist();
|
22339 |
|
22340 | if (nextPlaylist && this.shouldSwitchToMedia_(nextPlaylist)) {
|
22341 | this.switchMedia_(nextPlaylist, 'abr');
|
22342 | }
|
22343 | };
|
22344 |
|
22345 | _proto.switchMedia_ = function switchMedia_(playlist, cause, delay) {
|
22346 | var oldMedia = this.media();
|
22347 | var oldId = oldMedia && (oldMedia.id || oldMedia.uri);
|
22348 | var newId = playlist.id || playlist.uri;
|
22349 |
|
22350 | if (oldId && oldId !== newId) {
|
22351 | this.logger_("switch media " + oldId + " -> " + newId + " from " + cause);
|
22352 | this.tech_.trigger({
|
22353 | type: 'usage',
|
22354 | name: "vhs-rendition-change-" + cause
|
22355 | });
|
22356 | }
|
22357 |
|
22358 | this.masterPlaylistLoader_.media(playlist, delay);
|
22359 | }
|
22360 | |
22361 |
|
22362 |
|
22363 |
|
22364 |
|
22365 | ;
|
22366 |
|
22367 | _proto.startABRTimer_ = function startABRTimer_() {
|
22368 | var _this2 = this;
|
22369 |
|
22370 | this.stopABRTimer_();
|
22371 | this.abrTimer_ = window__default["default"].setInterval(function () {
|
22372 | return _this2.checkABR_();
|
22373 | }, 250);
|
22374 | }
|
22375 | |
22376 |
|
22377 |
|
22378 |
|
22379 |
|
22380 | ;
|
22381 |
|
22382 | _proto.stopABRTimer_ = function stopABRTimer_() {
|
22383 |
|
22384 |
|
22385 | if (this.tech_.scrubbing && this.tech_.scrubbing()) {
|
22386 | return;
|
22387 | }
|
22388 |
|
22389 | window__default["default"].clearInterval(this.abrTimer_);
|
22390 | this.abrTimer_ = null;
|
22391 | }
|
22392 | |
22393 |
|
22394 |
|
22395 |
|
22396 |
|
22397 | ;
|
22398 |
|
22399 | _proto.getAudioTrackPlaylists_ = function getAudioTrackPlaylists_() {
|
22400 | var master = this.master();
|
22401 | var defaultPlaylists = master && master.playlists || [];
|
22402 |
|
22403 |
|
22404 |
|
22405 | if (!master || !master.mediaGroups || !master.mediaGroups.AUDIO) {
|
22406 | return defaultPlaylists;
|
22407 | }
|
22408 |
|
22409 | var AUDIO = master.mediaGroups.AUDIO;
|
22410 | var groupKeys = Object.keys(AUDIO);
|
22411 | var track;
|
22412 |
|
22413 | if (Object.keys(this.mediaTypes_.AUDIO.groups).length) {
|
22414 | track = this.mediaTypes_.AUDIO.activeTrack();
|
22415 | } else {
|
22416 |
|
22417 | var defaultGroup = AUDIO.main || groupKeys.length && AUDIO[groupKeys[0]];
|
22418 |
|
22419 | for (var label in defaultGroup) {
|
22420 | if (defaultGroup[label].default) {
|
22421 | track = {
|
22422 | label: label
|
22423 | };
|
22424 | break;
|
22425 | }
|
22426 | }
|
22427 | }
|
22428 |
|
22429 |
|
22430 | if (!track) {
|
22431 | return defaultPlaylists;
|
22432 | }
|
22433 |
|
22434 | var playlists = [];
|
22435 |
|
22436 |
|
22437 | for (var group in AUDIO) {
|
22438 | if (AUDIO[group][track.label]) {
|
22439 | var properties = AUDIO[group][track.label];
|
22440 |
|
22441 | if (properties.playlists && properties.playlists.length) {
|
22442 | playlists.push.apply(playlists, properties.playlists);
|
22443 | } else if (properties.uri) {
|
22444 | playlists.push(properties);
|
22445 | } else if (master.playlists.length) {
|
22446 |
|
22447 |
|
22448 |
|
22449 | for (var i = 0; i < master.playlists.length; i++) {
|
22450 | var playlist = master.playlists[i];
|
22451 |
|
22452 | if (playlist.attributes && playlist.attributes.AUDIO && playlist.attributes.AUDIO === group) {
|
22453 | playlists.push(playlist);
|
22454 | }
|
22455 | }
|
22456 | }
|
22457 | }
|
22458 | }
|
22459 |
|
22460 | if (!playlists.length) {
|
22461 | return defaultPlaylists;
|
22462 | }
|
22463 |
|
22464 | return playlists;
|
22465 | }
|
22466 | |
22467 |
|
22468 |
|
22469 |
|
22470 |
|
22471 |
|
22472 | ;
|
22473 |
|
22474 | _proto.setupMasterPlaylistLoaderListeners_ = function setupMasterPlaylistLoaderListeners_() {
|
22475 | var _this3 = this;
|
22476 |
|
22477 | this.masterPlaylistLoader_.on('loadedmetadata', function () {
|
22478 | var media = _this3.masterPlaylistLoader_.media();
|
22479 |
|
22480 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
22481 |
|
22482 |
|
22483 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
22484 | _this3.requestOptions_.timeout = 0;
|
22485 | } else {
|
22486 | _this3.requestOptions_.timeout = requestTimeout;
|
22487 | }
|
22488 |
|
22489 |
|
22490 |
|
22491 | if (media.endList && _this3.tech_.preload() !== 'none') {
|
22492 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
22493 |
|
22494 | _this3.mainSegmentLoader_.load();
|
22495 | }
|
22496 |
|
22497 | setupMediaGroups({
|
22498 | sourceType: _this3.sourceType_,
|
22499 | segmentLoaders: {
|
22500 | AUDIO: _this3.audioSegmentLoader_,
|
22501 | SUBTITLES: _this3.subtitleSegmentLoader_,
|
22502 | main: _this3.mainSegmentLoader_
|
22503 | },
|
22504 | tech: _this3.tech_,
|
22505 | requestOptions: _this3.requestOptions_,
|
22506 | masterPlaylistLoader: _this3.masterPlaylistLoader_,
|
22507 | vhs: _this3.vhs_,
|
22508 | master: _this3.master(),
|
22509 | mediaTypes: _this3.mediaTypes_,
|
22510 | blacklistCurrentPlaylist: _this3.blacklistCurrentPlaylist.bind(_this3)
|
22511 | });
|
22512 |
|
22513 | _this3.triggerPresenceUsage_(_this3.master(), media);
|
22514 |
|
22515 | _this3.setupFirstPlay();
|
22516 |
|
22517 | if (!_this3.mediaTypes_.AUDIO.activePlaylistLoader || _this3.mediaTypes_.AUDIO.activePlaylistLoader.media()) {
|
22518 | _this3.trigger('selectedinitialmedia');
|
22519 | } else {
|
22520 |
|
22521 |
|
22522 |
|
22523 | _this3.mediaTypes_.AUDIO.activePlaylistLoader.one('loadedmetadata', function () {
|
22524 | _this3.trigger('selectedinitialmedia');
|
22525 | });
|
22526 | }
|
22527 | });
|
22528 | this.masterPlaylistLoader_.on('loadedplaylist', function () {
|
22529 | if (_this3.loadOnPlay_) {
|
22530 | _this3.tech_.off('play', _this3.loadOnPlay_);
|
22531 | }
|
22532 |
|
22533 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
22534 |
|
22535 | if (!updatedPlaylist) {
|
22536 |
|
22537 |
|
22538 | _this3.excludeUnsupportedVariants_();
|
22539 |
|
22540 | var selectedMedia;
|
22541 |
|
22542 | if (_this3.enableLowInitialPlaylist) {
|
22543 | selectedMedia = _this3.selectInitialPlaylist();
|
22544 | }
|
22545 |
|
22546 | if (!selectedMedia) {
|
22547 | selectedMedia = _this3.selectPlaylist();
|
22548 | }
|
22549 |
|
22550 | if (!selectedMedia || !_this3.shouldSwitchToMedia_(selectedMedia)) {
|
22551 | return;
|
22552 | }
|
22553 |
|
22554 | _this3.initialMedia_ = selectedMedia;
|
22555 |
|
22556 | _this3.switchMedia_(_this3.initialMedia_, 'initial');
|
22557 |
|
22558 |
|
22559 |
|
22560 |
|
22561 |
|
22562 |
|
22563 |
|
22564 | var haveJsonSource = _this3.sourceType_ === 'vhs-json' && _this3.initialMedia_.segments;
|
22565 |
|
22566 | if (!haveJsonSource) {
|
22567 | return;
|
22568 | }
|
22569 |
|
22570 | updatedPlaylist = _this3.initialMedia_;
|
22571 | }
|
22572 |
|
22573 | _this3.handleUpdatedMediaPlaylist(updatedPlaylist);
|
22574 | });
|
22575 | this.masterPlaylistLoader_.on('error', function () {
|
22576 | _this3.blacklistCurrentPlaylist(_this3.masterPlaylistLoader_.error);
|
22577 | });
|
22578 | this.masterPlaylistLoader_.on('mediachanging', function () {
|
22579 | _this3.mainSegmentLoader_.abort();
|
22580 |
|
22581 | _this3.mainSegmentLoader_.pause();
|
22582 | });
|
22583 | this.masterPlaylistLoader_.on('mediachange', function () {
|
22584 | var media = _this3.masterPlaylistLoader_.media();
|
22585 |
|
22586 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
22587 |
|
22588 |
|
22589 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
22590 | _this3.requestOptions_.timeout = 0;
|
22591 | } else {
|
22592 | _this3.requestOptions_.timeout = requestTimeout;
|
22593 | }
|
22594 |
|
22595 |
|
22596 |
|
22597 |
|
22598 |
|
22599 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
22600 |
|
22601 | _this3.mainSegmentLoader_.load();
|
22602 |
|
22603 | _this3.tech_.trigger({
|
22604 | type: 'mediachange',
|
22605 | bubbles: true
|
22606 | });
|
22607 | });
|
22608 | this.masterPlaylistLoader_.on('playlistunchanged', function () {
|
22609 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
22610 |
|
22611 |
|
22612 |
|
22613 |
|
22614 | if (updatedPlaylist.lastExcludeReason_ === 'playlist-unchanged') {
|
22615 | return;
|
22616 | }
|
22617 |
|
22618 | var playlistOutdated = _this3.stuckAtPlaylistEnd_(updatedPlaylist);
|
22619 |
|
22620 | if (playlistOutdated) {
|
22621 |
|
22622 |
|
22623 |
|
22624 |
|
22625 | _this3.blacklistCurrentPlaylist({
|
22626 | message: 'Playlist no longer updating.',
|
22627 | reason: 'playlist-unchanged'
|
22628 | });
|
22629 |
|
22630 |
|
22631 | _this3.tech_.trigger('playliststuck');
|
22632 | }
|
22633 | });
|
22634 | this.masterPlaylistLoader_.on('renditiondisabled', function () {
|
22635 | _this3.tech_.trigger({
|
22636 | type: 'usage',
|
22637 | name: 'vhs-rendition-disabled'
|
22638 | });
|
22639 |
|
22640 | _this3.tech_.trigger({
|
22641 | type: 'usage',
|
22642 | name: 'hls-rendition-disabled'
|
22643 | });
|
22644 | });
|
22645 | this.masterPlaylistLoader_.on('renditionenabled', function () {
|
22646 | _this3.tech_.trigger({
|
22647 | type: 'usage',
|
22648 | name: 'vhs-rendition-enabled'
|
22649 | });
|
22650 |
|
22651 | _this3.tech_.trigger({
|
22652 | type: 'usage',
|
22653 | name: 'hls-rendition-enabled'
|
22654 | });
|
22655 | });
|
22656 | }
|
22657 | |
22658 |
|
22659 |
|
22660 |
|
22661 |
|
22662 |
|
22663 |
|
22664 |
|
22665 |
|
22666 | ;
|
22667 |
|
22668 | _proto.handleUpdatedMediaPlaylist = function handleUpdatedMediaPlaylist(updatedPlaylist) {
|
22669 | if (this.useCueTags_) {
|
22670 | this.updateAdCues_(updatedPlaylist);
|
22671 | }
|
22672 |
|
22673 |
|
22674 |
|
22675 |
|
22676 |
|
22677 | this.mainSegmentLoader_.playlist(updatedPlaylist, this.requestOptions_);
|
22678 | this.updateDuration(!updatedPlaylist.endList);
|
22679 |
|
22680 |
|
22681 |
|
22682 | if (!this.tech_.paused()) {
|
22683 | this.mainSegmentLoader_.load();
|
22684 |
|
22685 | if (this.audioSegmentLoader_) {
|
22686 | this.audioSegmentLoader_.load();
|
22687 | }
|
22688 | }
|
22689 | }
|
22690 | |
22691 |
|
22692 |
|
22693 |
|
22694 |
|
22695 | ;
|
22696 |
|
22697 | _proto.triggerPresenceUsage_ = function triggerPresenceUsage_(master, media) {
|
22698 | var mediaGroups = master.mediaGroups || {};
|
22699 | var defaultDemuxed = true;
|
22700 | var audioGroupKeys = Object.keys(mediaGroups.AUDIO);
|
22701 |
|
22702 | for (var mediaGroup in mediaGroups.AUDIO) {
|
22703 | for (var label in mediaGroups.AUDIO[mediaGroup]) {
|
22704 | var properties = mediaGroups.AUDIO[mediaGroup][label];
|
22705 |
|
22706 | if (!properties.uri) {
|
22707 | defaultDemuxed = false;
|
22708 | }
|
22709 | }
|
22710 | }
|
22711 |
|
22712 | if (defaultDemuxed) {
|
22713 | this.tech_.trigger({
|
22714 | type: 'usage',
|
22715 | name: 'vhs-demuxed'
|
22716 | });
|
22717 | this.tech_.trigger({
|
22718 | type: 'usage',
|
22719 | name: 'hls-demuxed'
|
22720 | });
|
22721 | }
|
22722 |
|
22723 | if (Object.keys(mediaGroups.SUBTITLES).length) {
|
22724 | this.tech_.trigger({
|
22725 | type: 'usage',
|
22726 | name: 'vhs-webvtt'
|
22727 | });
|
22728 | this.tech_.trigger({
|
22729 | type: 'usage',
|
22730 | name: 'hls-webvtt'
|
22731 | });
|
22732 | }
|
22733 |
|
22734 | if (Vhs$1.Playlist.isAes(media)) {
|
22735 | this.tech_.trigger({
|
22736 | type: 'usage',
|
22737 | name: 'vhs-aes'
|
22738 | });
|
22739 | this.tech_.trigger({
|
22740 | type: 'usage',
|
22741 | name: 'hls-aes'
|
22742 | });
|
22743 | }
|
22744 |
|
22745 | if (audioGroupKeys.length && Object.keys(mediaGroups.AUDIO[audioGroupKeys[0]]).length > 1) {
|
22746 | this.tech_.trigger({
|
22747 | type: 'usage',
|
22748 | name: 'vhs-alternate-audio'
|
22749 | });
|
22750 | this.tech_.trigger({
|
22751 | type: 'usage',
|
22752 | name: 'hls-alternate-audio'
|
22753 | });
|
22754 | }
|
22755 |
|
22756 | if (this.useCueTags_) {
|
22757 | this.tech_.trigger({
|
22758 | type: 'usage',
|
22759 | name: 'vhs-playlist-cue-tags'
|
22760 | });
|
22761 | this.tech_.trigger({
|
22762 | type: 'usage',
|
22763 | name: 'hls-playlist-cue-tags'
|
22764 | });
|
22765 | }
|
22766 | };
|
22767 |
|
22768 | _proto.shouldSwitchToMedia_ = function shouldSwitchToMedia_(nextPlaylist) {
|
22769 | var currentPlaylist = this.masterPlaylistLoader_.media();
|
22770 | var buffered = this.tech_.buffered();
|
22771 | var forwardBuffer = buffered.length ? buffered.end(buffered.length - 1) - this.tech_.currentTime() : 0;
|
22772 | var bufferLowWaterLine = this.bufferLowWaterLine();
|
22773 | var bufferHighWaterLine = this.bufferHighWaterLine();
|
22774 | return shouldSwitchToMedia({
|
22775 | currentPlaylist: currentPlaylist,
|
22776 | nextPlaylist: nextPlaylist,
|
22777 | forwardBuffer: forwardBuffer,
|
22778 | bufferLowWaterLine: bufferLowWaterLine,
|
22779 | bufferHighWaterLine: bufferHighWaterLine,
|
22780 | duration: this.duration(),
|
22781 | experimentalBufferBasedABR: this.experimentalBufferBasedABR,
|
22782 | log: this.logger_
|
22783 | });
|
22784 | }
|
22785 | |
22786 |
|
22787 |
|
22788 |
|
22789 |
|
22790 |
|
22791 | ;
|
22792 |
|
22793 | _proto.setupSegmentLoaderListeners_ = function setupSegmentLoaderListeners_() {
|
22794 | var _this4 = this;
|
22795 |
|
22796 | if (!this.experimentalBufferBasedABR) {
|
22797 | this.mainSegmentLoader_.on('bandwidthupdate', function () {
|
22798 | var nextPlaylist = _this4.selectPlaylist();
|
22799 |
|
22800 | if (_this4.shouldSwitchToMedia_(nextPlaylist)) {
|
22801 | _this4.switchMedia_(nextPlaylist, 'bandwidthupdate');
|
22802 | }
|
22803 |
|
22804 | _this4.tech_.trigger('bandwidthupdate');
|
22805 | });
|
22806 | this.mainSegmentLoader_.on('progress', function () {
|
22807 | _this4.trigger('progress');
|
22808 | });
|
22809 | }
|
22810 |
|
22811 | this.mainSegmentLoader_.on('error', function () {
|
22812 | _this4.blacklistCurrentPlaylist(_this4.mainSegmentLoader_.error());
|
22813 | });
|
22814 | this.mainSegmentLoader_.on('appenderror', function () {
|
22815 | _this4.error = _this4.mainSegmentLoader_.error_;
|
22816 |
|
22817 | _this4.trigger('error');
|
22818 | });
|
22819 | this.mainSegmentLoader_.on('syncinfoupdate', function () {
|
22820 | _this4.onSyncInfoUpdate_();
|
22821 | });
|
22822 | this.mainSegmentLoader_.on('timestampoffset', function () {
|
22823 | _this4.tech_.trigger({
|
22824 | type: 'usage',
|
22825 | name: 'vhs-timestamp-offset'
|
22826 | });
|
22827 |
|
22828 | _this4.tech_.trigger({
|
22829 | type: 'usage',
|
22830 | name: 'hls-timestamp-offset'
|
22831 | });
|
22832 | });
|
22833 | this.audioSegmentLoader_.on('syncinfoupdate', function () {
|
22834 | _this4.onSyncInfoUpdate_();
|
22835 | });
|
22836 | this.audioSegmentLoader_.on('appenderror', function () {
|
22837 | _this4.error = _this4.audioSegmentLoader_.error_;
|
22838 |
|
22839 | _this4.trigger('error');
|
22840 | });
|
22841 | this.mainSegmentLoader_.on('ended', function () {
|
22842 | _this4.logger_('main segment loader ended');
|
22843 |
|
22844 | _this4.onEndOfStream();
|
22845 | });
|
22846 | this.mainSegmentLoader_.on('earlyabort', function (event) {
|
22847 |
|
22848 | if (_this4.experimentalBufferBasedABR) {
|
22849 | return;
|
22850 | }
|
22851 |
|
22852 | _this4.delegateLoaders_('all', ['abort']);
|
22853 |
|
22854 | _this4.blacklistCurrentPlaylist({
|
22855 | message: 'Aborted early because there isn\'t enough bandwidth to complete the ' + 'request without rebuffering.'
|
22856 | }, ABORT_EARLY_BLACKLIST_SECONDS);
|
22857 | });
|
22858 |
|
22859 | var updateCodecs = function updateCodecs() {
|
22860 | if (!_this4.sourceUpdater_.hasCreatedSourceBuffers()) {
|
22861 | return _this4.tryToCreateSourceBuffers_();
|
22862 | }
|
22863 |
|
22864 | var codecs = _this4.getCodecsOrExclude_();
|
22865 |
|
22866 |
|
22867 | if (!codecs) {
|
22868 | return;
|
22869 | }
|
22870 |
|
22871 | _this4.sourceUpdater_.addOrChangeSourceBuffers(codecs);
|
22872 | };
|
22873 |
|
22874 | this.mainSegmentLoader_.on('trackinfo', updateCodecs);
|
22875 | this.audioSegmentLoader_.on('trackinfo', updateCodecs);
|
22876 | this.mainSegmentLoader_.on('fmp4', function () {
|
22877 | if (!_this4.triggeredFmp4Usage) {
|
22878 | _this4.tech_.trigger({
|
22879 | type: 'usage',
|
22880 | name: 'vhs-fmp4'
|
22881 | });
|
22882 |
|
22883 | _this4.tech_.trigger({
|
22884 | type: 'usage',
|
22885 | name: 'hls-fmp4'
|
22886 | });
|
22887 |
|
22888 | _this4.triggeredFmp4Usage = true;
|
22889 | }
|
22890 | });
|
22891 | this.audioSegmentLoader_.on('fmp4', function () {
|
22892 | if (!_this4.triggeredFmp4Usage) {
|
22893 | _this4.tech_.trigger({
|
22894 | type: 'usage',
|
22895 | name: 'vhs-fmp4'
|
22896 | });
|
22897 |
|
22898 | _this4.tech_.trigger({
|
22899 | type: 'usage',
|
22900 | name: 'hls-fmp4'
|
22901 | });
|
22902 |
|
22903 | _this4.triggeredFmp4Usage = true;
|
22904 | }
|
22905 | });
|
22906 | this.audioSegmentLoader_.on('ended', function () {
|
22907 | _this4.logger_('audioSegmentLoader ended');
|
22908 |
|
22909 | _this4.onEndOfStream();
|
22910 | });
|
22911 | };
|
22912 |
|
22913 | _proto.mediaSecondsLoaded_ = function mediaSecondsLoaded_() {
|
22914 | return Math.max(this.audioSegmentLoader_.mediaSecondsLoaded + this.mainSegmentLoader_.mediaSecondsLoaded);
|
22915 | }
|
22916 | |
22917 |
|
22918 |
|
22919 | ;
|
22920 |
|
22921 | _proto.load = function load() {
|
22922 | this.mainSegmentLoader_.load();
|
22923 |
|
22924 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
22925 | this.audioSegmentLoader_.load();
|
22926 | }
|
22927 |
|
22928 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
22929 | this.subtitleSegmentLoader_.load();
|
22930 | }
|
22931 | }
|
22932 | |
22933 |
|
22934 |
|
22935 |
|
22936 |
|
22937 |
|
22938 |
|
22939 |
|
22940 | ;
|
22941 |
|
22942 | _proto.smoothQualityChange_ = function smoothQualityChange_(media) {
|
22943 | if (media === void 0) {
|
22944 | media = this.selectPlaylist();
|
22945 | }
|
22946 |
|
22947 | this.fastQualityChange_(media);
|
22948 | }
|
22949 | |
22950 |
|
22951 |
|
22952 |
|
22953 |
|
22954 |
|
22955 |
|
22956 |
|
22957 | ;
|
22958 |
|
22959 | _proto.fastQualityChange_ = function fastQualityChange_(media) {
|
22960 | var _this5 = this;
|
22961 |
|
22962 | if (media === void 0) {
|
22963 | media = this.selectPlaylist();
|
22964 | }
|
22965 |
|
22966 | if (media === this.masterPlaylistLoader_.media()) {
|
22967 | this.logger_('skipping fastQualityChange because new media is same as old');
|
22968 | return;
|
22969 | }
|
22970 |
|
22971 | this.switchMedia_(media, 'fast-quality');
|
22972 |
|
22973 |
|
22974 |
|
22975 |
|
22976 |
|
22977 |
|
22978 | this.mainSegmentLoader_.resetEverything(function () {
|
22979 |
|
22980 |
|
22981 | if (videojs__default["default"].browser.IE_VERSION || videojs__default["default"].browser.IS_EDGE) {
|
22982 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime() + 0.04);
|
22983 | } else {
|
22984 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime());
|
22985 | }
|
22986 | });
|
22987 | }
|
22988 | |
22989 |
|
22990 |
|
22991 | ;
|
22992 |
|
22993 | _proto.play = function play() {
|
22994 | if (this.setupFirstPlay()) {
|
22995 | return;
|
22996 | }
|
22997 |
|
22998 | if (this.tech_.ended()) {
|
22999 | this.tech_.setCurrentTime(0);
|
23000 | }
|
23001 |
|
23002 | if (this.hasPlayed_) {
|
23003 | this.load();
|
23004 | }
|
23005 |
|
23006 | var seekable = this.tech_.seekable();
|
23007 |
|
23008 |
|
23009 | if (this.tech_.duration() === Infinity) {
|
23010 | if (this.tech_.currentTime() < seekable.start(0)) {
|
23011 | return this.tech_.setCurrentTime(seekable.end(seekable.length - 1));
|
23012 | }
|
23013 | }
|
23014 | }
|
23015 | |
23016 |
|
23017 |
|
23018 |
|
23019 | ;
|
23020 |
|
23021 | _proto.setupFirstPlay = function setupFirstPlay() {
|
23022 | var _this6 = this;
|
23023 |
|
23024 | var media = this.masterPlaylistLoader_.media();
|
23025 |
|
23026 |
|
23027 |
|
23028 |
|
23029 |
|
23030 | if (!media || this.tech_.paused() || this.hasPlayed_) {
|
23031 | return false;
|
23032 | }
|
23033 |
|
23034 |
|
23035 | if (!media.endList) {
|
23036 | var seekable = this.seekable();
|
23037 |
|
23038 | if (!seekable.length) {
|
23039 |
|
23040 |
|
23041 | return false;
|
23042 | }
|
23043 |
|
23044 | if (videojs__default["default"].browser.IE_VERSION && this.tech_.readyState() === 0) {
|
23045 |
|
23046 |
|
23047 | this.tech_.one('loadedmetadata', function () {
|
23048 | _this6.trigger('firstplay');
|
23049 |
|
23050 | _this6.tech_.setCurrentTime(seekable.end(0));
|
23051 |
|
23052 | _this6.hasPlayed_ = true;
|
23053 | });
|
23054 | return false;
|
23055 | }
|
23056 |
|
23057 |
|
23058 | this.trigger('firstplay');
|
23059 |
|
23060 | this.tech_.setCurrentTime(seekable.end(0));
|
23061 | }
|
23062 |
|
23063 | this.hasPlayed_ = true;
|
23064 |
|
23065 | this.load();
|
23066 | return true;
|
23067 | }
|
23068 | |
23069 |
|
23070 |
|
23071 |
|
23072 |
|
23073 | ;
|
23074 |
|
23075 | _proto.handleSourceOpen_ = function handleSourceOpen_() {
|
23076 |
|
23077 |
|
23078 |
|
23079 | this.tryToCreateSourceBuffers_();
|
23080 |
|
23081 |
|
23082 |
|
23083 | if (this.tech_.autoplay()) {
|
23084 | var playPromise = this.tech_.play();
|
23085 |
|
23086 |
|
23087 | if (typeof playPromise !== 'undefined' && typeof playPromise.then === 'function') {
|
23088 | playPromise.then(null, function (e) {});
|
23089 | }
|
23090 | }
|
23091 |
|
23092 | this.trigger('sourceopen');
|
23093 | }
|
23094 | |
23095 |
|
23096 |
|
23097 |
|
23098 |
|
23099 | ;
|
23100 |
|
23101 | _proto.handleSourceEnded_ = function handleSourceEnded_() {
|
23102 | if (!this.inbandTextTracks_.metadataTrack_) {
|
23103 | return;
|
23104 | }
|
23105 |
|
23106 | var cues = this.inbandTextTracks_.metadataTrack_.cues;
|
23107 |
|
23108 | if (!cues || !cues.length) {
|
23109 | return;
|
23110 | }
|
23111 |
|
23112 | var duration = this.duration();
|
23113 | cues[cues.length - 1].endTime = isNaN(duration) || Math.abs(duration) === Infinity ? Number.MAX_VALUE : duration;
|
23114 | }
|
23115 | |
23116 |
|
23117 |
|
23118 |
|
23119 |
|
23120 | ;
|
23121 |
|
23122 | _proto.handleDurationChange_ = function handleDurationChange_() {
|
23123 | this.tech_.trigger('durationchange');
|
23124 | }
|
23125 | |
23126 |
|
23127 |
|
23128 |
|
23129 |
|
23130 |
|
23131 |
|
23132 |
|
23133 | ;
|
23134 |
|
23135 | _proto.onEndOfStream = function onEndOfStream() {
|
23136 | var isEndOfStream = this.mainSegmentLoader_.ended_;
|
23137 |
|
23138 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23139 | var mainMediaInfo = this.mainSegmentLoader_.getCurrentMediaInfo_();
|
23140 |
|
23141 | if (!mainMediaInfo || mainMediaInfo.hasVideo) {
|
23142 |
|
23143 |
|
23144 |
|
23145 | isEndOfStream = isEndOfStream && this.audioSegmentLoader_.ended_;
|
23146 | } else {
|
23147 |
|
23148 | isEndOfStream = this.audioSegmentLoader_.ended_;
|
23149 | }
|
23150 | }
|
23151 |
|
23152 | if (!isEndOfStream) {
|
23153 | return;
|
23154 | }
|
23155 |
|
23156 | this.stopABRTimer_();
|
23157 | this.sourceUpdater_.endOfStream();
|
23158 | }
|
23159 | |
23160 |
|
23161 |
|
23162 |
|
23163 |
|
23164 |
|
23165 | ;
|
23166 |
|
23167 | _proto.stuckAtPlaylistEnd_ = function stuckAtPlaylistEnd_(playlist) {
|
23168 | var seekable = this.seekable();
|
23169 |
|
23170 | if (!seekable.length) {
|
23171 |
|
23172 | return false;
|
23173 | }
|
23174 |
|
23175 | var expired = this.syncController_.getExpiredTime(playlist, this.duration());
|
23176 |
|
23177 | if (expired === null) {
|
23178 | return false;
|
23179 | }
|
23180 |
|
23181 |
|
23182 |
|
23183 | var absolutePlaylistEnd = Vhs$1.Playlist.playlistEnd(playlist, expired);
|
23184 | var currentTime = this.tech_.currentTime();
|
23185 | var buffered = this.tech_.buffered();
|
23186 |
|
23187 | if (!buffered.length) {
|
23188 |
|
23189 | return absolutePlaylistEnd - currentTime <= SAFE_TIME_DELTA;
|
23190 | }
|
23191 |
|
23192 | var bufferedEnd = buffered.end(buffered.length - 1);
|
23193 |
|
23194 |
|
23195 | return bufferedEnd - currentTime <= SAFE_TIME_DELTA && absolutePlaylistEnd - bufferedEnd <= SAFE_TIME_DELTA;
|
23196 | }
|
23197 | |
23198 |
|
23199 |
|
23200 |
|
23201 |
|
23202 |
|
23203 |
|
23204 |
|
23205 |
|
23206 |
|
23207 | ;
|
23208 |
|
23209 | _proto.blacklistCurrentPlaylist = function blacklistCurrentPlaylist(error, blacklistDuration) {
|
23210 | if (error === void 0) {
|
23211 | error = {};
|
23212 | }
|
23213 |
|
23214 |
|
23215 |
|
23216 |
|
23217 |
|
23218 | var currentPlaylist = error.playlist || this.masterPlaylistLoader_.media();
|
23219 | blacklistDuration = blacklistDuration || error.blacklistDuration || this.blacklistDuration;
|
23220 |
|
23221 |
|
23222 | if (!currentPlaylist) {
|
23223 | this.error = error;
|
23224 |
|
23225 | if (this.mediaSource.readyState !== 'open') {
|
23226 | this.trigger('error');
|
23227 | } else {
|
23228 | this.sourceUpdater_.endOfStream('network');
|
23229 | }
|
23230 |
|
23231 | return;
|
23232 | }
|
23233 |
|
23234 | currentPlaylist.playlistErrors_++;
|
23235 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
23236 | var enabledPlaylists = playlists.filter(isEnabled);
|
23237 | var isFinalRendition = enabledPlaylists.length === 1 && enabledPlaylists[0] === currentPlaylist;
|
23238 |
|
23239 |
|
23240 | if (playlists.length === 1 && blacklistDuration !== Infinity) {
|
23241 | videojs__default["default"].log.warn("Problem encountered with playlist " + currentPlaylist.id + ". " + 'Trying again since it is the only playlist.');
|
23242 | this.tech_.trigger('retryplaylist');
|
23243 |
|
23244 | return this.masterPlaylistLoader_.load(isFinalRendition);
|
23245 | }
|
23246 |
|
23247 | if (isFinalRendition) {
|
23248 |
|
23249 |
|
23250 |
|
23251 |
|
23252 | var reincluded = false;
|
23253 | playlists.forEach(function (playlist) {
|
23254 |
|
23255 | if (playlist === currentPlaylist) {
|
23256 | return;
|
23257 | }
|
23258 |
|
23259 | var excludeUntil = playlist.excludeUntil;
|
23260 |
|
23261 | if (typeof excludeUntil !== 'undefined' && excludeUntil !== Infinity) {
|
23262 | reincluded = true;
|
23263 | delete playlist.excludeUntil;
|
23264 | }
|
23265 | });
|
23266 |
|
23267 | if (reincluded) {
|
23268 | videojs__default["default"].log.warn('Removing other playlists from the exclusion list because the last ' + 'rendition is about to be excluded.');
|
23269 |
|
23270 |
|
23271 |
|
23272 | this.tech_.trigger('retryplaylist');
|
23273 | }
|
23274 | }
|
23275 |
|
23276 |
|
23277 | var excludeUntil;
|
23278 |
|
23279 | if (currentPlaylist.playlistErrors_ > this.maxPlaylistRetries) {
|
23280 | excludeUntil = Infinity;
|
23281 | } else {
|
23282 | excludeUntil = Date.now() + blacklistDuration * 1000;
|
23283 | }
|
23284 |
|
23285 | currentPlaylist.excludeUntil = excludeUntil;
|
23286 |
|
23287 | if (error.reason) {
|
23288 | currentPlaylist.lastExcludeReason_ = error.reason;
|
23289 | }
|
23290 |
|
23291 | this.tech_.trigger('blacklistplaylist');
|
23292 | this.tech_.trigger({
|
23293 | type: 'usage',
|
23294 | name: 'vhs-rendition-blacklisted'
|
23295 | });
|
23296 | this.tech_.trigger({
|
23297 | type: 'usage',
|
23298 | name: 'hls-rendition-blacklisted'
|
23299 | });
|
23300 |
|
23301 |
|
23302 |
|
23303 |
|
23304 |
|
23305 | var nextPlaylist = this.selectPlaylist();
|
23306 |
|
23307 | if (!nextPlaylist) {
|
23308 | this.error = 'Playback cannot continue. No available working or supported playlists.';
|
23309 | this.trigger('error');
|
23310 | return;
|
23311 | }
|
23312 |
|
23313 | var logFn = error.internal ? this.logger_ : videojs__default["default"].log.warn;
|
23314 | var errorMessage = error.message ? ' ' + error.message : '';
|
23315 | logFn((error.internal ? 'Internal problem' : 'Problem') + " encountered with playlist " + currentPlaylist.id + "." + (errorMessage + " Switching to playlist " + nextPlaylist.id + "."));
|
23316 |
|
23317 | if (nextPlaylist.attributes.AUDIO !== currentPlaylist.attributes.AUDIO) {
|
23318 | this.delegateLoaders_('audio', ['abort', 'pause']);
|
23319 | }
|
23320 |
|
23321 |
|
23322 | if (nextPlaylist.attributes.SUBTITLES !== currentPlaylist.attributes.SUBTITLES) {
|
23323 | this.delegateLoaders_('subtitle', ['abort', 'pause']);
|
23324 | }
|
23325 |
|
23326 | this.delegateLoaders_('main', ['abort', 'pause']);
|
23327 | var delayDuration = nextPlaylist.targetDuration / 2 * 1000 || 5 * 1000;
|
23328 | var shouldDelay = typeof nextPlaylist.lastRequest === 'number' && Date.now() - nextPlaylist.lastRequest <= delayDuration;
|
23329 |
|
23330 | return this.switchMedia_(nextPlaylist, 'exclude', isFinalRendition || shouldDelay);
|
23331 | }
|
23332 | |
23333 |
|
23334 |
|
23335 | ;
|
23336 |
|
23337 | _proto.pauseLoading = function pauseLoading() {
|
23338 | this.delegateLoaders_('all', ['abort', 'pause']);
|
23339 | this.stopABRTimer_();
|
23340 | }
|
23341 | |
23342 |
|
23343 |
|
23344 |
|
23345 |
|
23346 |
|
23347 |
|
23348 |
|
23349 |
|
23350 |
|
23351 |
|
23352 |
|
23353 |
|
23354 |
|
23355 | ;
|
23356 |
|
23357 | _proto.delegateLoaders_ = function delegateLoaders_(filter, fnNames) {
|
23358 | var _this7 = this;
|
23359 |
|
23360 | var loaders = [];
|
23361 | var dontFilterPlaylist = filter === 'all';
|
23362 |
|
23363 | if (dontFilterPlaylist || filter === 'main') {
|
23364 | loaders.push(this.masterPlaylistLoader_);
|
23365 | }
|
23366 |
|
23367 | var mediaTypes = [];
|
23368 |
|
23369 | if (dontFilterPlaylist || filter === 'audio') {
|
23370 | mediaTypes.push('AUDIO');
|
23371 | }
|
23372 |
|
23373 | if (dontFilterPlaylist || filter === 'subtitle') {
|
23374 | mediaTypes.push('CLOSED-CAPTIONS');
|
23375 | mediaTypes.push('SUBTITLES');
|
23376 | }
|
23377 |
|
23378 | mediaTypes.forEach(function (mediaType) {
|
23379 | var loader = _this7.mediaTypes_[mediaType] && _this7.mediaTypes_[mediaType].activePlaylistLoader;
|
23380 |
|
23381 | if (loader) {
|
23382 | loaders.push(loader);
|
23383 | }
|
23384 | });
|
23385 | ['main', 'audio', 'subtitle'].forEach(function (name) {
|
23386 | var loader = _this7[name + "SegmentLoader_"];
|
23387 |
|
23388 | if (loader && (filter === name || filter === 'all')) {
|
23389 | loaders.push(loader);
|
23390 | }
|
23391 | });
|
23392 | loaders.forEach(function (loader) {
|
23393 | return fnNames.forEach(function (fnName) {
|
23394 | if (typeof loader[fnName] === 'function') {
|
23395 | loader[fnName]();
|
23396 | }
|
23397 | });
|
23398 | });
|
23399 | }
|
23400 | |
23401 |
|
23402 |
|
23403 |
|
23404 |
|
23405 |
|
23406 | ;
|
23407 |
|
23408 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
23409 | var buffered = findRange(this.tech_.buffered(), currentTime);
|
23410 |
|
23411 | if (!(this.masterPlaylistLoader_ && this.masterPlaylistLoader_.media())) {
|
23412 |
|
23413 | return 0;
|
23414 | }
|
23415 |
|
23416 |
|
23417 |
|
23418 | if (!this.masterPlaylistLoader_.media().segments) {
|
23419 | return 0;
|
23420 | }
|
23421 |
|
23422 |
|
23423 | if (buffered && buffered.length) {
|
23424 | return currentTime;
|
23425 | }
|
23426 |
|
23427 |
|
23428 |
|
23429 | this.mainSegmentLoader_.resetEverything();
|
23430 | this.mainSegmentLoader_.abort();
|
23431 |
|
23432 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23433 | this.audioSegmentLoader_.resetEverything();
|
23434 | this.audioSegmentLoader_.abort();
|
23435 | }
|
23436 |
|
23437 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
23438 | this.subtitleSegmentLoader_.resetEverything();
|
23439 | this.subtitleSegmentLoader_.abort();
|
23440 | }
|
23441 |
|
23442 |
|
23443 | this.load();
|
23444 | }
|
23445 | |
23446 |
|
23447 |
|
23448 |
|
23449 |
|
23450 | ;
|
23451 |
|
23452 | _proto.duration = function duration() {
|
23453 | if (!this.masterPlaylistLoader_) {
|
23454 | return 0;
|
23455 | }
|
23456 |
|
23457 | var media = this.masterPlaylistLoader_.media();
|
23458 |
|
23459 | if (!media) {
|
23460 |
|
23461 | return 0;
|
23462 | }
|
23463 |
|
23464 |
|
23465 |
|
23466 |
|
23467 |
|
23468 |
|
23469 |
|
23470 |
|
23471 |
|
23472 |
|
23473 |
|
23474 | if (!media.endList) {
|
23475 | return Infinity;
|
23476 | }
|
23477 |
|
23478 |
|
23479 |
|
23480 | if (this.mediaSource) {
|
23481 | return this.mediaSource.duration;
|
23482 | }
|
23483 |
|
23484 | return Vhs$1.Playlist.duration(media);
|
23485 | }
|
23486 | |
23487 |
|
23488 |
|
23489 |
|
23490 |
|
23491 | ;
|
23492 |
|
23493 | _proto.seekable = function seekable() {
|
23494 | return this.seekable_;
|
23495 | };
|
23496 |
|
23497 | _proto.onSyncInfoUpdate_ = function onSyncInfoUpdate_() {
|
23498 | var audioSeekable;
|
23499 |
|
23500 | if (!this.masterPlaylistLoader_) {
|
23501 | return;
|
23502 | }
|
23503 |
|
23504 | var media = this.masterPlaylistLoader_.media();
|
23505 |
|
23506 | if (!media) {
|
23507 | return;
|
23508 | }
|
23509 |
|
23510 | var expired = this.syncController_.getExpiredTime(media, this.duration());
|
23511 |
|
23512 | if (expired === null) {
|
23513 |
|
23514 | return;
|
23515 | }
|
23516 |
|
23517 | var master = this.masterPlaylistLoader_.master;
|
23518 | var mainSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
23519 |
|
23520 | if (mainSeekable.length === 0) {
|
23521 | return;
|
23522 | }
|
23523 |
|
23524 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
23525 | media = this.mediaTypes_.AUDIO.activePlaylistLoader.media();
|
23526 | expired = this.syncController_.getExpiredTime(media, this.duration());
|
23527 |
|
23528 | if (expired === null) {
|
23529 | return;
|
23530 | }
|
23531 |
|
23532 | audioSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
23533 |
|
23534 | if (audioSeekable.length === 0) {
|
23535 | return;
|
23536 | }
|
23537 | }
|
23538 |
|
23539 | var oldEnd;
|
23540 | var oldStart;
|
23541 |
|
23542 | if (this.seekable_ && this.seekable_.length) {
|
23543 | oldEnd = this.seekable_.end(0);
|
23544 | oldStart = this.seekable_.start(0);
|
23545 | }
|
23546 |
|
23547 | if (!audioSeekable) {
|
23548 |
|
23549 |
|
23550 | this.seekable_ = mainSeekable;
|
23551 | } else if (audioSeekable.start(0) > mainSeekable.end(0) || mainSeekable.start(0) > audioSeekable.end(0)) {
|
23552 |
|
23553 | this.seekable_ = mainSeekable;
|
23554 | } else {
|
23555 | 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)]]);
|
23556 | }
|
23557 |
|
23558 |
|
23559 | if (this.seekable_ && this.seekable_.length) {
|
23560 | if (this.seekable_.end(0) === oldEnd && this.seekable_.start(0) === oldStart) {
|
23561 | return;
|
23562 | }
|
23563 | }
|
23564 |
|
23565 | this.logger_("seekable updated [" + printableRange(this.seekable_) + "]");
|
23566 | this.tech_.trigger('seekablechanged');
|
23567 | }
|
23568 | |
23569 |
|
23570 |
|
23571 | ;
|
23572 |
|
23573 | _proto.updateDuration = function updateDuration(isLive) {
|
23574 | if (this.updateDuration_) {
|
23575 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
23576 | this.updateDuration_ = null;
|
23577 | }
|
23578 |
|
23579 | if (this.mediaSource.readyState !== 'open') {
|
23580 | this.updateDuration_ = this.updateDuration.bind(this, isLive);
|
23581 | this.mediaSource.addEventListener('sourceopen', this.updateDuration_);
|
23582 | return;
|
23583 | }
|
23584 |
|
23585 | if (isLive) {
|
23586 | var seekable = this.seekable();
|
23587 |
|
23588 | if (!seekable.length) {
|
23589 | return;
|
23590 | }
|
23591 |
|
23592 |
|
23593 |
|
23594 |
|
23595 |
|
23596 |
|
23597 |
|
23598 |
|
23599 |
|
23600 |
|
23601 |
|
23602 |
|
23603 |
|
23604 |
|
23605 |
|
23606 |
|
23607 |
|
23608 |
|
23609 |
|
23610 |
|
23611 |
|
23612 |
|
23613 |
|
23614 |
|
23615 | if (isNaN(this.mediaSource.duration) || this.mediaSource.duration < seekable.end(seekable.length - 1)) {
|
23616 | this.sourceUpdater_.setDuration(seekable.end(seekable.length - 1));
|
23617 | }
|
23618 |
|
23619 | return;
|
23620 | }
|
23621 |
|
23622 | var buffered = this.tech_.buffered();
|
23623 | var duration = Vhs$1.Playlist.duration(this.masterPlaylistLoader_.media());
|
23624 |
|
23625 | if (buffered.length > 0) {
|
23626 | duration = Math.max(duration, buffered.end(buffered.length - 1));
|
23627 | }
|
23628 |
|
23629 | if (this.mediaSource.duration !== duration) {
|
23630 | this.sourceUpdater_.setDuration(duration);
|
23631 | }
|
23632 | }
|
23633 | |
23634 |
|
23635 |
|
23636 |
|
23637 | ;
|
23638 |
|
23639 | _proto.dispose = function dispose() {
|
23640 | var _this8 = this;
|
23641 |
|
23642 | this.trigger('dispose');
|
23643 | this.decrypter_.terminate();
|
23644 | this.masterPlaylistLoader_.dispose();
|
23645 | this.mainSegmentLoader_.dispose();
|
23646 |
|
23647 | if (this.loadOnPlay_) {
|
23648 | this.tech_.off('play', this.loadOnPlay_);
|
23649 | }
|
23650 |
|
23651 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
23652 | var groups = _this8.mediaTypes_[type].groups;
|
23653 |
|
23654 | for (var id in groups) {
|
23655 | groups[id].forEach(function (group) {
|
23656 | if (group.playlistLoader) {
|
23657 | group.playlistLoader.dispose();
|
23658 | }
|
23659 | });
|
23660 | }
|
23661 | });
|
23662 | this.audioSegmentLoader_.dispose();
|
23663 | this.subtitleSegmentLoader_.dispose();
|
23664 | this.sourceUpdater_.dispose();
|
23665 | this.timelineChangeController_.dispose();
|
23666 | this.stopABRTimer_();
|
23667 |
|
23668 | if (this.updateDuration_) {
|
23669 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
23670 | }
|
23671 |
|
23672 | this.mediaSource.removeEventListener('durationchange', this.handleDurationChange_);
|
23673 |
|
23674 | this.mediaSource.removeEventListener('sourceopen', this.handleSourceOpen_);
|
23675 | this.mediaSource.removeEventListener('sourceended', this.handleSourceEnded_);
|
23676 | this.off();
|
23677 | }
|
23678 | |
23679 |
|
23680 |
|
23681 |
|
23682 |
|
23683 | ;
|
23684 |
|
23685 | _proto.master = function master() {
|
23686 | return this.masterPlaylistLoader_.master;
|
23687 | }
|
23688 | |
23689 |
|
23690 |
|
23691 |
|
23692 |
|
23693 | ;
|
23694 |
|
23695 | _proto.media = function media() {
|
23696 |
|
23697 | return this.masterPlaylistLoader_.media() || this.initialMedia_;
|
23698 | };
|
23699 |
|
23700 | _proto.areMediaTypesKnown_ = function areMediaTypesKnown_() {
|
23701 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
23702 | var hasMainMediaInfo = !!this.mainSegmentLoader_.getCurrentMediaInfo_();
|
23703 |
|
23704 |
|
23705 | var hasAudioMediaInfo = !usingAudioLoader ? true : !!this.audioSegmentLoader_.getCurrentMediaInfo_();
|
23706 |
|
23707 | if (!hasMainMediaInfo || !hasAudioMediaInfo) {
|
23708 | return false;
|
23709 | }
|
23710 |
|
23711 | return true;
|
23712 | };
|
23713 |
|
23714 | _proto.getCodecsOrExclude_ = function getCodecsOrExclude_() {
|
23715 | var _this9 = this;
|
23716 |
|
23717 | var media = {
|
23718 | main: this.mainSegmentLoader_.getCurrentMediaInfo_() || {},
|
23719 | audio: this.audioSegmentLoader_.getCurrentMediaInfo_() || {}
|
23720 | };
|
23721 |
|
23722 | media.video = media.main;
|
23723 | var playlistCodecs = codecsForPlaylist(this.master(), this.media());
|
23724 | var codecs = {};
|
23725 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
23726 |
|
23727 | if (media.main.hasVideo) {
|
23728 | codecs.video = playlistCodecs.video || media.main.videoCodec || codecs_js.DEFAULT_VIDEO_CODEC;
|
23729 | }
|
23730 |
|
23731 | if (media.main.isMuxed) {
|
23732 | codecs.video += "," + (playlistCodecs.audio || media.main.audioCodec || codecs_js.DEFAULT_AUDIO_CODEC);
|
23733 | }
|
23734 |
|
23735 | if (media.main.hasAudio && !media.main.isMuxed || media.audio.hasAudio || usingAudioLoader) {
|
23736 | codecs.audio = playlistCodecs.audio || media.main.audioCodec || media.audio.audioCodec || codecs_js.DEFAULT_AUDIO_CODEC;
|
23737 |
|
23738 | media.audio.isFmp4 = media.main.hasAudio && !media.main.isMuxed ? media.main.isFmp4 : media.audio.isFmp4;
|
23739 | }
|
23740 |
|
23741 |
|
23742 | if (!codecs.audio && !codecs.video) {
|
23743 | this.blacklistCurrentPlaylist({
|
23744 | playlist: this.media(),
|
23745 | message: 'Could not determine codecs for playlist.',
|
23746 | blacklistDuration: Infinity
|
23747 | });
|
23748 | return;
|
23749 | }
|
23750 |
|
23751 |
|
23752 | var supportFunction = function supportFunction(isFmp4, codec) {
|
23753 | return isFmp4 ? codecs_js.browserSupportsCodec(codec) : codecs_js.muxerSupportsCodec(codec);
|
23754 | };
|
23755 |
|
23756 | var unsupportedCodecs = {};
|
23757 | var unsupportedAudio;
|
23758 | ['video', 'audio'].forEach(function (type) {
|
23759 | if (codecs.hasOwnProperty(type) && !supportFunction(media[type].isFmp4, codecs[type])) {
|
23760 | var supporter = media[type].isFmp4 ? 'browser' : 'muxer';
|
23761 | unsupportedCodecs[supporter] = unsupportedCodecs[supporter] || [];
|
23762 | unsupportedCodecs[supporter].push(codecs[type]);
|
23763 |
|
23764 | if (type === 'audio') {
|
23765 | unsupportedAudio = supporter;
|
23766 | }
|
23767 | }
|
23768 | });
|
23769 |
|
23770 | if (usingAudioLoader && unsupportedAudio && this.media().attributes.AUDIO) {
|
23771 | var audioGroup = this.media().attributes.AUDIO;
|
23772 | this.master().playlists.forEach(function (variant) {
|
23773 | var variantAudioGroup = variant.attributes && variant.attributes.AUDIO;
|
23774 |
|
23775 | if (variantAudioGroup === audioGroup && variant !== _this9.media()) {
|
23776 | variant.excludeUntil = Infinity;
|
23777 | }
|
23778 | });
|
23779 | this.logger_("excluding audio group " + audioGroup + " as " + unsupportedAudio + " does not support codec(s): \"" + codecs.audio + "\"");
|
23780 | }
|
23781 |
|
23782 |
|
23783 | if (Object.keys(unsupportedCodecs).length) {
|
23784 | var message = Object.keys(unsupportedCodecs).reduce(function (acc, supporter) {
|
23785 | if (acc) {
|
23786 | acc += ', ';
|
23787 | }
|
23788 |
|
23789 | acc += supporter + " does not support codec(s): \"" + unsupportedCodecs[supporter].join(',') + "\"";
|
23790 | return acc;
|
23791 | }, '') + '.';
|
23792 | this.blacklistCurrentPlaylist({
|
23793 | playlist: this.media(),
|
23794 | internal: true,
|
23795 | message: message,
|
23796 | blacklistDuration: Infinity
|
23797 | });
|
23798 | return;
|
23799 | }
|
23800 |
|
23801 |
|
23802 | if (this.sourceUpdater_.hasCreatedSourceBuffers() && !this.sourceUpdater_.canChangeType()) {
|
23803 | var switchMessages = [];
|
23804 | ['video', 'audio'].forEach(function (type) {
|
23805 | var newCodec = (codecs_js.parseCodecs(_this9.sourceUpdater_.codecs[type] || '')[0] || {}).type;
|
23806 | var oldCodec = (codecs_js.parseCodecs(codecs[type] || '')[0] || {}).type;
|
23807 |
|
23808 | if (newCodec && oldCodec && newCodec.toLowerCase() !== oldCodec.toLowerCase()) {
|
23809 | switchMessages.push("\"" + _this9.sourceUpdater_.codecs[type] + "\" -> \"" + codecs[type] + "\"");
|
23810 | }
|
23811 | });
|
23812 |
|
23813 | if (switchMessages.length) {
|
23814 | this.blacklistCurrentPlaylist({
|
23815 | playlist: this.media(),
|
23816 | message: "Codec switching not supported: " + switchMessages.join(', ') + ".",
|
23817 | blacklistDuration: Infinity,
|
23818 | internal: true
|
23819 | });
|
23820 | return;
|
23821 | }
|
23822 | }
|
23823 |
|
23824 |
|
23825 |
|
23826 | return codecs;
|
23827 | }
|
23828 | |
23829 |
|
23830 |
|
23831 |
|
23832 |
|
23833 | ;
|
23834 |
|
23835 | _proto.tryToCreateSourceBuffers_ = function tryToCreateSourceBuffers_() {
|
23836 |
|
23837 |
|
23838 | if (this.mediaSource.readyState !== 'open' || this.sourceUpdater_.hasCreatedSourceBuffers()) {
|
23839 | return;
|
23840 | }
|
23841 |
|
23842 | if (!this.areMediaTypesKnown_()) {
|
23843 | return;
|
23844 | }
|
23845 |
|
23846 | var codecs = this.getCodecsOrExclude_();
|
23847 |
|
23848 | if (!codecs) {
|
23849 | return;
|
23850 | }
|
23851 |
|
23852 | this.sourceUpdater_.createSourceBuffers(codecs);
|
23853 | var codecString = [codecs.video, codecs.audio].filter(Boolean).join(',');
|
23854 | this.excludeIncompatibleVariants_(codecString);
|
23855 | }
|
23856 | |
23857 |
|
23858 |
|
23859 | ;
|
23860 |
|
23861 | _proto.excludeUnsupportedVariants_ = function excludeUnsupportedVariants_() {
|
23862 | var _this10 = this;
|
23863 |
|
23864 | var playlists = this.master().playlists;
|
23865 | var ids = [];
|
23866 |
|
23867 |
|
23868 | Object.keys(playlists).forEach(function (key) {
|
23869 | var variant = playlists[key];
|
23870 |
|
23871 | if (ids.indexOf(variant.id) !== -1) {
|
23872 | return;
|
23873 | }
|
23874 |
|
23875 | ids.push(variant.id);
|
23876 | var codecs = codecsForPlaylist(_this10.master, variant);
|
23877 | var unsupported = [];
|
23878 |
|
23879 | if (codecs.audio && !codecs_js.muxerSupportsCodec(codecs.audio) && !codecs_js.browserSupportsCodec(codecs.audio)) {
|
23880 | unsupported.push("audio codec " + codecs.audio);
|
23881 | }
|
23882 |
|
23883 | if (codecs.video && !codecs_js.muxerSupportsCodec(codecs.video) && !codecs_js.browserSupportsCodec(codecs.video)) {
|
23884 | unsupported.push("video codec " + codecs.video);
|
23885 | }
|
23886 |
|
23887 | if (codecs.text && codecs.text === 'stpp.ttml.im1t') {
|
23888 | unsupported.push("text codec " + codecs.text);
|
23889 | }
|
23890 |
|
23891 | if (unsupported.length) {
|
23892 | variant.excludeUntil = Infinity;
|
23893 |
|
23894 | _this10.logger_("excluding " + variant.id + " for unsupported: " + unsupported.join(', '));
|
23895 | }
|
23896 | });
|
23897 | }
|
23898 | |
23899 |
|
23900 |
|
23901 |
|
23902 |
|
23903 |
|
23904 |
|
23905 |
|
23906 |
|
23907 |
|
23908 |
|
23909 |
|
23910 |
|
23911 |
|
23912 | ;
|
23913 |
|
23914 | _proto.excludeIncompatibleVariants_ = function excludeIncompatibleVariants_(codecString) {
|
23915 | var _this11 = this;
|
23916 |
|
23917 | var ids = [];
|
23918 | var playlists = this.master().playlists;
|
23919 | var codecs = unwrapCodecList(codecs_js.parseCodecs(codecString));
|
23920 | var codecCount_ = codecCount(codecs);
|
23921 | var videoDetails = codecs.video && codecs_js.parseCodecs(codecs.video)[0] || null;
|
23922 | var audioDetails = codecs.audio && codecs_js.parseCodecs(codecs.audio)[0] || null;
|
23923 | Object.keys(playlists).forEach(function (key) {
|
23924 | var variant = playlists[key];
|
23925 |
|
23926 |
|
23927 | if (ids.indexOf(variant.id) !== -1 || variant.excludeUntil === Infinity) {
|
23928 | return;
|
23929 | }
|
23930 |
|
23931 | ids.push(variant.id);
|
23932 | var blacklistReasons = [];
|
23933 |
|
23934 | var variantCodecs = codecsForPlaylist(_this11.masterPlaylistLoader_.master, variant);
|
23935 | var variantCodecCount = codecCount(variantCodecs);
|
23936 |
|
23937 |
|
23938 | if (!variantCodecs.audio && !variantCodecs.video) {
|
23939 | return;
|
23940 | }
|
23941 |
|
23942 |
|
23943 |
|
23944 |
|
23945 | if (variantCodecCount !== codecCount_) {
|
23946 | blacklistReasons.push("codec count \"" + variantCodecCount + "\" !== \"" + codecCount_ + "\"");
|
23947 | }
|
23948 |
|
23949 |
|
23950 |
|
23951 | if (!_this11.sourceUpdater_.canChangeType()) {
|
23952 | var variantVideoDetails = variantCodecs.video && codecs_js.parseCodecs(variantCodecs.video)[0] || null;
|
23953 | var variantAudioDetails = variantCodecs.audio && codecs_js.parseCodecs(variantCodecs.audio)[0] || null;
|
23954 |
|
23955 | if (variantVideoDetails && videoDetails && variantVideoDetails.type.toLowerCase() !== videoDetails.type.toLowerCase()) {
|
23956 | blacklistReasons.push("video codec \"" + variantVideoDetails.type + "\" !== \"" + videoDetails.type + "\"");
|
23957 | }
|
23958 |
|
23959 |
|
23960 | if (variantAudioDetails && audioDetails && variantAudioDetails.type.toLowerCase() !== audioDetails.type.toLowerCase()) {
|
23961 | blacklistReasons.push("audio codec \"" + variantAudioDetails.type + "\" !== \"" + audioDetails.type + "\"");
|
23962 | }
|
23963 | }
|
23964 |
|
23965 | if (blacklistReasons.length) {
|
23966 | variant.excludeUntil = Infinity;
|
23967 |
|
23968 | _this11.logger_("blacklisting " + variant.id + ": " + blacklistReasons.join(' && '));
|
23969 | }
|
23970 | });
|
23971 | };
|
23972 |
|
23973 | _proto.updateAdCues_ = function updateAdCues_(media) {
|
23974 | var offset = 0;
|
23975 | var seekable = this.seekable();
|
23976 |
|
23977 | if (seekable.length) {
|
23978 | offset = seekable.start(0);
|
23979 | }
|
23980 |
|
23981 | updateAdCues(media, this.cueTagsTrack_, offset);
|
23982 | }
|
23983 | |
23984 |
|
23985 |
|
23986 |
|
23987 |
|
23988 | ;
|
23989 |
|
23990 | _proto.goalBufferLength = function goalBufferLength() {
|
23991 | var currentTime = this.tech_.currentTime();
|
23992 | var initial = Config.GOAL_BUFFER_LENGTH;
|
23993 | var rate = Config.GOAL_BUFFER_LENGTH_RATE;
|
23994 | var max = Math.max(initial, Config.MAX_GOAL_BUFFER_LENGTH);
|
23995 | return Math.min(initial + currentTime * rate, max);
|
23996 | }
|
23997 | |
23998 |
|
23999 |
|
24000 |
|
24001 |
|
24002 | ;
|
24003 |
|
24004 | _proto.bufferLowWaterLine = function bufferLowWaterLine() {
|
24005 | var currentTime = this.tech_.currentTime();
|
24006 | var initial = Config.BUFFER_LOW_WATER_LINE;
|
24007 | var rate = Config.BUFFER_LOW_WATER_LINE_RATE;
|
24008 | var max = Math.max(initial, Config.MAX_BUFFER_LOW_WATER_LINE);
|
24009 | var newMax = Math.max(initial, Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE);
|
24010 | return Math.min(initial + currentTime * rate, this.experimentalBufferBasedABR ? newMax : max);
|
24011 | };
|
24012 |
|
24013 | _proto.bufferHighWaterLine = function bufferHighWaterLine() {
|
24014 | return Config.BUFFER_HIGH_WATER_LINE;
|
24015 | };
|
24016 |
|
24017 | return MasterPlaylistController;
|
24018 | }(videojs__default["default"].EventTarget);
|
24019 |
|
24020 |
|
24021 |
|
24022 |
|
24023 |
|
24024 |
|
24025 |
|
24026 |
|
24027 |
|
24028 |
|
24029 |
|
24030 |
|
24031 |
|
24032 |
|
24033 | var enableFunction = function enableFunction(loader, playlistID, changePlaylistFn) {
|
24034 | return function (enable) {
|
24035 | var playlist = loader.master.playlists[playlistID];
|
24036 | var incompatible = isIncompatible(playlist);
|
24037 | var currentlyEnabled = isEnabled(playlist);
|
24038 |
|
24039 | if (typeof enable === 'undefined') {
|
24040 | return currentlyEnabled;
|
24041 | }
|
24042 |
|
24043 | if (enable) {
|
24044 | delete playlist.disabled;
|
24045 | } else {
|
24046 | playlist.disabled = true;
|
24047 | }
|
24048 |
|
24049 | if (enable !== currentlyEnabled && !incompatible) {
|
24050 |
|
24051 | changePlaylistFn();
|
24052 |
|
24053 | if (enable) {
|
24054 | loader.trigger('renditionenabled');
|
24055 | } else {
|
24056 | loader.trigger('renditiondisabled');
|
24057 | }
|
24058 | }
|
24059 |
|
24060 | return enable;
|
24061 | };
|
24062 | };
|
24063 |
|
24064 |
|
24065 |
|
24066 |
|
24067 |
|
24068 |
|
24069 |
|
24070 |
|
24071 |
|
24072 | var Representation = function Representation(vhsHandler, playlist, id) {
|
24073 | var mpc = vhsHandler.masterPlaylistController_,
|
24074 | smoothQualityChange = vhsHandler.options_.smoothQualityChange;
|
24075 |
|
24076 | var changeType = smoothQualityChange ? 'smooth' : 'fast';
|
24077 | var qualityChangeFunction = mpc[changeType + "QualityChange_"].bind(mpc);
|
24078 |
|
24079 | if (playlist.attributes) {
|
24080 | var resolution = playlist.attributes.RESOLUTION;
|
24081 | this.width = resolution && resolution.width;
|
24082 | this.height = resolution && resolution.height;
|
24083 | this.bandwidth = playlist.attributes.BANDWIDTH;
|
24084 | }
|
24085 |
|
24086 | this.codecs = codecsForPlaylist(mpc.master(), playlist);
|
24087 | this.playlist = playlist;
|
24088 |
|
24089 |
|
24090 | this.id = id;
|
24091 |
|
24092 |
|
24093 | this.enabled = enableFunction(vhsHandler.playlists, playlist.id, qualityChangeFunction);
|
24094 | };
|
24095 |
|
24096 |
|
24097 |
|
24098 |
|
24099 |
|
24100 |
|
24101 |
|
24102 |
|
24103 |
|
24104 | var renditionSelectionMixin = function renditionSelectionMixin(vhsHandler) {
|
24105 |
|
24106 | vhsHandler.representations = function () {
|
24107 | var master = vhsHandler.masterPlaylistController_.master();
|
24108 | var playlists = isAudioOnly(master) ? vhsHandler.masterPlaylistController_.getAudioTrackPlaylists_() : master.playlists;
|
24109 |
|
24110 | if (!playlists) {
|
24111 | return [];
|
24112 | }
|
24113 |
|
24114 | return playlists.filter(function (media) {
|
24115 | return !isIncompatible(media);
|
24116 | }).map(function (e, i) {
|
24117 | return new Representation(vhsHandler, e, e.id);
|
24118 | });
|
24119 | };
|
24120 | };
|
24121 |
|
24122 |
|
24123 |
|
24124 |
|
24125 |
|
24126 |
|
24127 |
|
24128 |
|
24129 |
|
24130 |
|
24131 |
|
24132 | var timerCancelEvents = ['seeking', 'seeked', 'pause', 'playing', 'error'];
|
24133 |
|
24134 |
|
24135 |
|
24136 |
|
24137 | var PlaybackWatcher = function () {
|
24138 | |
24139 |
|
24140 |
|
24141 |
|
24142 |
|
24143 |
|
24144 | function PlaybackWatcher(options) {
|
24145 | var _this = this;
|
24146 |
|
24147 | this.masterPlaylistController_ = options.masterPlaylistController;
|
24148 | this.tech_ = options.tech;
|
24149 | this.seekable = options.seekable;
|
24150 | this.allowSeeksWithinUnsafeLiveWindow = options.allowSeeksWithinUnsafeLiveWindow;
|
24151 | this.liveRangeSafeTimeDelta = options.liveRangeSafeTimeDelta;
|
24152 | this.media = options.media;
|
24153 | this.consecutiveUpdates = 0;
|
24154 | this.lastRecordedTime = null;
|
24155 | this.timer_ = null;
|
24156 | this.checkCurrentTimeTimeout_ = null;
|
24157 | this.logger_ = logger('PlaybackWatcher');
|
24158 | this.logger_('initialize');
|
24159 |
|
24160 | var playHandler = function playHandler() {
|
24161 | return _this.monitorCurrentTime_();
|
24162 | };
|
24163 |
|
24164 | var canPlayHandler = function canPlayHandler() {
|
24165 | return _this.monitorCurrentTime_();
|
24166 | };
|
24167 |
|
24168 | var waitingHandler = function waitingHandler() {
|
24169 | return _this.techWaiting_();
|
24170 | };
|
24171 |
|
24172 | var cancelTimerHandler = function cancelTimerHandler() {
|
24173 | return _this.cancelTimer_();
|
24174 | };
|
24175 |
|
24176 | var mpc = this.masterPlaylistController_;
|
24177 | var loaderTypes = ['main', 'subtitle', 'audio'];
|
24178 | var loaderChecks = {};
|
24179 | loaderTypes.forEach(function (type) {
|
24180 | loaderChecks[type] = {
|
24181 | reset: function reset() {
|
24182 | return _this.resetSegmentDownloads_(type);
|
24183 | },
|
24184 | updateend: function updateend() {
|
24185 | return _this.checkSegmentDownloads_(type);
|
24186 | }
|
24187 | };
|
24188 | mpc[type + "SegmentLoader_"].on('appendsdone', loaderChecks[type].updateend);
|
24189 |
|
24190 |
|
24191 |
|
24192 | mpc[type + "SegmentLoader_"].on('playlistupdate', loaderChecks[type].reset);
|
24193 |
|
24194 |
|
24195 |
|
24196 |
|
24197 | _this.tech_.on(['seeked', 'seeking'], loaderChecks[type].reset);
|
24198 | });
|
24199 | |
24200 |
|
24201 |
|
24202 |
|
24203 |
|
24204 |
|
24205 |
|
24206 |
|
24207 |
|
24208 | var setSeekingHandlers = function setSeekingHandlers(fn) {
|
24209 | ['main', 'audio'].forEach(function (type) {
|
24210 | mpc[type + "SegmentLoader_"][fn]('appended', _this.seekingAppendCheck_);
|
24211 | });
|
24212 | };
|
24213 |
|
24214 | this.seekingAppendCheck_ = function () {
|
24215 | if (_this.fixesBadSeeks_()) {
|
24216 | _this.consecutiveUpdates = 0;
|
24217 | _this.lastRecordedTime = _this.tech_.currentTime();
|
24218 | setSeekingHandlers('off');
|
24219 | }
|
24220 | };
|
24221 |
|
24222 | this.clearSeekingAppendCheck_ = function () {
|
24223 | return setSeekingHandlers('off');
|
24224 | };
|
24225 |
|
24226 | this.watchForBadSeeking_ = function () {
|
24227 | _this.clearSeekingAppendCheck_();
|
24228 |
|
24229 | setSeekingHandlers('on');
|
24230 | };
|
24231 |
|
24232 | this.tech_.on('seeked', this.clearSeekingAppendCheck_);
|
24233 | this.tech_.on('seeking', this.watchForBadSeeking_);
|
24234 | this.tech_.on('waiting', waitingHandler);
|
24235 | this.tech_.on(timerCancelEvents, cancelTimerHandler);
|
24236 | this.tech_.on('canplay', canPlayHandler);
|
24237 | |
24238 |
|
24239 |
|
24240 |
|
24241 |
|
24242 |
|
24243 |
|
24244 |
|
24245 |
|
24246 |
|
24247 |
|
24248 | this.tech_.one('play', playHandler);
|
24249 |
|
24250 | this.dispose = function () {
|
24251 | _this.clearSeekingAppendCheck_();
|
24252 |
|
24253 | _this.logger_('dispose');
|
24254 |
|
24255 | _this.tech_.off('waiting', waitingHandler);
|
24256 |
|
24257 | _this.tech_.off(timerCancelEvents, cancelTimerHandler);
|
24258 |
|
24259 | _this.tech_.off('canplay', canPlayHandler);
|
24260 |
|
24261 | _this.tech_.off('play', playHandler);
|
24262 |
|
24263 | _this.tech_.off('seeking', _this.watchForBadSeeking_);
|
24264 |
|
24265 | _this.tech_.off('seeked', _this.clearSeekingAppendCheck_);
|
24266 |
|
24267 | loaderTypes.forEach(function (type) {
|
24268 | mpc[type + "SegmentLoader_"].off('appendsdone', loaderChecks[type].updateend);
|
24269 | mpc[type + "SegmentLoader_"].off('playlistupdate', loaderChecks[type].reset);
|
24270 |
|
24271 | _this.tech_.off(['seeked', 'seeking'], loaderChecks[type].reset);
|
24272 | });
|
24273 |
|
24274 | if (_this.checkCurrentTimeTimeout_) {
|
24275 | window__default["default"].clearTimeout(_this.checkCurrentTimeTimeout_);
|
24276 | }
|
24277 |
|
24278 | _this.cancelTimer_();
|
24279 | };
|
24280 | }
|
24281 | |
24282 |
|
24283 |
|
24284 |
|
24285 |
|
24286 |
|
24287 |
|
24288 | var _proto = PlaybackWatcher.prototype;
|
24289 |
|
24290 | _proto.monitorCurrentTime_ = function monitorCurrentTime_() {
|
24291 | this.checkCurrentTime_();
|
24292 |
|
24293 | if (this.checkCurrentTimeTimeout_) {
|
24294 | window__default["default"].clearTimeout(this.checkCurrentTimeTimeout_);
|
24295 | }
|
24296 |
|
24297 |
|
24298 | this.checkCurrentTimeTimeout_ = window__default["default"].setTimeout(this.monitorCurrentTime_.bind(this), 250);
|
24299 | }
|
24300 | |
24301 |
|
24302 |
|
24303 |
|
24304 |
|
24305 |
|
24306 |
|
24307 |
|
24308 |
|
24309 |
|
24310 | ;
|
24311 |
|
24312 | _proto.resetSegmentDownloads_ = function resetSegmentDownloads_(type) {
|
24313 | var loader = this.masterPlaylistController_[type + "SegmentLoader_"];
|
24314 |
|
24315 | if (this[type + "StalledDownloads_"] > 0) {
|
24316 | this.logger_("resetting possible stalled download count for " + type + " loader");
|
24317 | }
|
24318 |
|
24319 | this[type + "StalledDownloads_"] = 0;
|
24320 | this[type + "Buffered_"] = loader.buffered_();
|
24321 | }
|
24322 | |
24323 |
|
24324 |
|
24325 |
|
24326 |
|
24327 |
|
24328 |
|
24329 |
|
24330 |
|
24331 |
|
24332 | ;
|
24333 |
|
24334 | _proto.checkSegmentDownloads_ = function checkSegmentDownloads_(type) {
|
24335 | var mpc = this.masterPlaylistController_;
|
24336 | var loader = mpc[type + "SegmentLoader_"];
|
24337 | var buffered = loader.buffered_();
|
24338 | var isBufferedDifferent = isRangeDifferent(this[type + "Buffered_"], buffered);
|
24339 | this[type + "Buffered_"] = buffered;
|
24340 |
|
24341 |
|
24342 |
|
24343 | if (isBufferedDifferent) {
|
24344 | this.resetSegmentDownloads_(type);
|
24345 | return;
|
24346 | }
|
24347 |
|
24348 | this[type + "StalledDownloads_"]++;
|
24349 | this.logger_("found #" + this[type + "StalledDownloads_"] + " " + type + " appends that did not increase buffer (possible stalled download)", {
|
24350 | playlistId: loader.playlist_ && loader.playlist_.id,
|
24351 | buffered: timeRangesToArray(buffered)
|
24352 | });
|
24353 |
|
24354 | if (this[type + "StalledDownloads_"] < 10) {
|
24355 | return;
|
24356 | }
|
24357 |
|
24358 | this.logger_(type + " loader stalled download exclusion");
|
24359 | this.resetSegmentDownloads_(type);
|
24360 | this.tech_.trigger({
|
24361 | type: 'usage',
|
24362 | name: "vhs-" + type + "-download-exclusion"
|
24363 | });
|
24364 |
|
24365 | if (type === 'subtitle') {
|
24366 | return;
|
24367 | }
|
24368 |
|
24369 |
|
24370 |
|
24371 | mpc.blacklistCurrentPlaylist({
|
24372 | message: "Excessive " + type + " segment downloading detected."
|
24373 | }, Infinity);
|
24374 | }
|
24375 | |
24376 |
|
24377 |
|
24378 |
|
24379 |
|
24380 |
|
24381 |
|
24382 | ;
|
24383 |
|
24384 | _proto.checkCurrentTime_ = function checkCurrentTime_() {
|
24385 | if (this.tech_.paused() || this.tech_.seeking()) {
|
24386 | return;
|
24387 | }
|
24388 |
|
24389 | var currentTime = this.tech_.currentTime();
|
24390 | var buffered = this.tech_.buffered();
|
24391 |
|
24392 | if (this.lastRecordedTime === currentTime && (!buffered.length || currentTime + SAFE_TIME_DELTA >= buffered.end(buffered.length - 1))) {
|
24393 |
|
24394 |
|
24395 |
|
24396 |
|
24397 |
|
24398 | return this.techWaiting_();
|
24399 | }
|
24400 |
|
24401 | if (this.consecutiveUpdates >= 5 && currentTime === this.lastRecordedTime) {
|
24402 | this.consecutiveUpdates++;
|
24403 | this.waiting_();
|
24404 | } else if (currentTime === this.lastRecordedTime) {
|
24405 | this.consecutiveUpdates++;
|
24406 | } else {
|
24407 | this.consecutiveUpdates = 0;
|
24408 | this.lastRecordedTime = currentTime;
|
24409 | }
|
24410 | }
|
24411 | |
24412 |
|
24413 |
|
24414 |
|
24415 |
|
24416 |
|
24417 | ;
|
24418 |
|
24419 | _proto.cancelTimer_ = function cancelTimer_() {
|
24420 | this.consecutiveUpdates = 0;
|
24421 |
|
24422 | if (this.timer_) {
|
24423 | this.logger_('cancelTimer_');
|
24424 | clearTimeout(this.timer_);
|
24425 | }
|
24426 |
|
24427 | this.timer_ = null;
|
24428 | }
|
24429 | |
24430 |
|
24431 |
|
24432 |
|
24433 |
|
24434 |
|
24435 | ;
|
24436 |
|
24437 | _proto.fixesBadSeeks_ = function fixesBadSeeks_() {
|
24438 | var seeking = this.tech_.seeking();
|
24439 |
|
24440 | if (!seeking) {
|
24441 | return false;
|
24442 | }
|
24443 |
|
24444 |
|
24445 |
|
24446 |
|
24447 |
|
24448 | var seekable = this.seekable();
|
24449 | var currentTime = this.tech_.currentTime();
|
24450 | var isAfterSeekableRange = this.afterSeekableWindow_(seekable, currentTime, this.media(), this.allowSeeksWithinUnsafeLiveWindow);
|
24451 | var seekTo;
|
24452 |
|
24453 | if (isAfterSeekableRange) {
|
24454 | var seekableEnd = seekable.end(seekable.length - 1);
|
24455 |
|
24456 | seekTo = seekableEnd;
|
24457 | }
|
24458 |
|
24459 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
24460 | var seekableStart = seekable.start(0);
|
24461 |
|
24462 |
|
24463 | seekTo = seekableStart + (
|
24464 |
|
24465 | seekableStart === seekable.end(0) ? 0 : SAFE_TIME_DELTA);
|
24466 | }
|
24467 |
|
24468 | if (typeof seekTo !== 'undefined') {
|
24469 | this.logger_("Trying to seek outside of seekable at time " + currentTime + " with " + ("seekable range " + printableRange(seekable) + ". Seeking to ") + (seekTo + "."));
|
24470 | this.tech_.setCurrentTime(seekTo);
|
24471 | return true;
|
24472 | }
|
24473 |
|
24474 | var sourceUpdater = this.masterPlaylistController_.sourceUpdater_;
|
24475 | var buffered = this.tech_.buffered();
|
24476 | var audioBuffered = sourceUpdater.audioBuffer ? sourceUpdater.audioBuffered() : null;
|
24477 | var videoBuffered = sourceUpdater.videoBuffer ? sourceUpdater.videoBuffered() : null;
|
24478 |
|
24479 |
|
24480 | var twoSegmentDurations = (this.media().targetDuration - TIME_FUDGE_FACTOR) * 2;
|
24481 | var bufferedToCheck = [audioBuffered, videoBuffered];
|
24482 |
|
24483 | for (var i = 0; i < bufferedToCheck.length; i++) {
|
24484 |
|
24485 | if (!bufferedToCheck[i]) {
|
24486 | continue;
|
24487 | }
|
24488 |
|
24489 | var timeAhead = timeAheadOf(bufferedToCheck[i], currentTime);
|
24490 |
|
24491 |
|
24492 | if (timeAhead < twoSegmentDurations) {
|
24493 | return false;
|
24494 | }
|
24495 | }
|
24496 |
|
24497 | var nextRange = findNextRange(buffered, currentTime);
|
24498 |
|
24499 |
|
24500 | if (nextRange.length === 0) {
|
24501 | return false;
|
24502 | }
|
24503 |
|
24504 | seekTo = nextRange.start(0) + SAFE_TIME_DELTA;
|
24505 | this.logger_("Buffered region starts (" + nextRange.start(0) + ") " + (" just beyond seek point (" + currentTime + "). Seeking to " + seekTo + "."));
|
24506 | this.tech_.setCurrentTime(seekTo);
|
24507 | return true;
|
24508 | }
|
24509 | |
24510 |
|
24511 |
|
24512 |
|
24513 |
|
24514 | ;
|
24515 |
|
24516 | _proto.waiting_ = function waiting_() {
|
24517 | if (this.techWaiting_()) {
|
24518 | return;
|
24519 | }
|
24520 |
|
24521 |
|
24522 | var currentTime = this.tech_.currentTime();
|
24523 | var buffered = this.tech_.buffered();
|
24524 | var currentRange = findRange(buffered, currentTime);
|
24525 |
|
24526 |
|
24527 |
|
24528 |
|
24529 |
|
24530 |
|
24531 |
|
24532 |
|
24533 | if (currentRange.length && currentTime + 3 <= currentRange.end(0)) {
|
24534 | this.cancelTimer_();
|
24535 | this.tech_.setCurrentTime(currentTime);
|
24536 | 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.');
|
24537 |
|
24538 | this.tech_.trigger({
|
24539 | type: 'usage',
|
24540 | name: 'vhs-unknown-waiting'
|
24541 | });
|
24542 | this.tech_.trigger({
|
24543 | type: 'usage',
|
24544 | name: 'hls-unknown-waiting'
|
24545 | });
|
24546 | return;
|
24547 | }
|
24548 | }
|
24549 | |
24550 |
|
24551 |
|
24552 |
|
24553 |
|
24554 |
|
24555 |
|
24556 |
|
24557 | ;
|
24558 |
|
24559 | _proto.techWaiting_ = function techWaiting_() {
|
24560 | var seekable = this.seekable();
|
24561 | var currentTime = this.tech_.currentTime();
|
24562 |
|
24563 | if (this.tech_.seeking() || this.timer_ !== null) {
|
24564 |
|
24565 | return true;
|
24566 | }
|
24567 |
|
24568 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
24569 | var livePoint = seekable.end(seekable.length - 1);
|
24570 | this.logger_("Fell out of live window at time " + currentTime + ". Seeking to " + ("live point (seekable end) " + livePoint));
|
24571 | this.cancelTimer_();
|
24572 | this.tech_.setCurrentTime(livePoint);
|
24573 |
|
24574 | this.tech_.trigger({
|
24575 | type: 'usage',
|
24576 | name: 'vhs-live-resync'
|
24577 | });
|
24578 | this.tech_.trigger({
|
24579 | type: 'usage',
|
24580 | name: 'hls-live-resync'
|
24581 | });
|
24582 | return true;
|
24583 | }
|
24584 |
|
24585 | var sourceUpdater = this.tech_.vhs.masterPlaylistController_.sourceUpdater_;
|
24586 | var buffered = this.tech_.buffered();
|
24587 | var videoUnderflow = this.videoUnderflow_({
|
24588 | audioBuffered: sourceUpdater.audioBuffered(),
|
24589 | videoBuffered: sourceUpdater.videoBuffered(),
|
24590 | currentTime: currentTime
|
24591 | });
|
24592 |
|
24593 | if (videoUnderflow) {
|
24594 |
|
24595 |
|
24596 |
|
24597 |
|
24598 | this.cancelTimer_();
|
24599 | this.tech_.setCurrentTime(currentTime);
|
24600 |
|
24601 | this.tech_.trigger({
|
24602 | type: 'usage',
|
24603 | name: 'vhs-video-underflow'
|
24604 | });
|
24605 | this.tech_.trigger({
|
24606 | type: 'usage',
|
24607 | name: 'hls-video-underflow'
|
24608 | });
|
24609 | return true;
|
24610 | }
|
24611 |
|
24612 | var nextRange = findNextRange(buffered, currentTime);
|
24613 |
|
24614 | if (nextRange.length > 0) {
|
24615 | var difference = nextRange.start(0) - currentTime;
|
24616 | this.logger_("Stopped at " + currentTime + ", setting timer for " + difference + ", seeking " + ("to " + nextRange.start(0)));
|
24617 | this.cancelTimer_();
|
24618 | this.timer_ = setTimeout(this.skipTheGap_.bind(this), difference * 1000, currentTime);
|
24619 | return true;
|
24620 | }
|
24621 |
|
24622 |
|
24623 | return false;
|
24624 | };
|
24625 |
|
24626 | _proto.afterSeekableWindow_ = function afterSeekableWindow_(seekable, currentTime, playlist, allowSeeksWithinUnsafeLiveWindow) {
|
24627 | if (allowSeeksWithinUnsafeLiveWindow === void 0) {
|
24628 | allowSeeksWithinUnsafeLiveWindow = false;
|
24629 | }
|
24630 |
|
24631 | if (!seekable.length) {
|
24632 |
|
24633 | return false;
|
24634 | }
|
24635 |
|
24636 | var allowedEnd = seekable.end(seekable.length - 1) + SAFE_TIME_DELTA;
|
24637 | var isLive = !playlist.endList;
|
24638 |
|
24639 | if (isLive && allowSeeksWithinUnsafeLiveWindow) {
|
24640 | allowedEnd = seekable.end(seekable.length - 1) + playlist.targetDuration * 3;
|
24641 | }
|
24642 |
|
24643 | if (currentTime > allowedEnd) {
|
24644 | return true;
|
24645 | }
|
24646 |
|
24647 | return false;
|
24648 | };
|
24649 |
|
24650 | _proto.beforeSeekableWindow_ = function beforeSeekableWindow_(seekable, currentTime) {
|
24651 | if (seekable.length &&
|
24652 | seekable.start(0) > 0 && currentTime < seekable.start(0) - this.liveRangeSafeTimeDelta) {
|
24653 | return true;
|
24654 | }
|
24655 |
|
24656 | return false;
|
24657 | };
|
24658 |
|
24659 | _proto.videoUnderflow_ = function videoUnderflow_(_ref) {
|
24660 | var videoBuffered = _ref.videoBuffered,
|
24661 | audioBuffered = _ref.audioBuffered,
|
24662 | currentTime = _ref.currentTime;
|
24663 |
|
24664 |
|
24665 | if (!videoBuffered) {
|
24666 | return;
|
24667 | }
|
24668 |
|
24669 | var gap;
|
24670 |
|
24671 | if (videoBuffered.length && audioBuffered.length) {
|
24672 |
|
24673 |
|
24674 |
|
24675 | var lastVideoRange = findRange(videoBuffered, currentTime - 3);
|
24676 | var videoRange = findRange(videoBuffered, currentTime);
|
24677 | var audioRange = findRange(audioBuffered, currentTime);
|
24678 |
|
24679 | if (audioRange.length && !videoRange.length && lastVideoRange.length) {
|
24680 | gap = {
|
24681 | start: lastVideoRange.end(0),
|
24682 | end: audioRange.end(0)
|
24683 | };
|
24684 | }
|
24685 |
|
24686 | } else {
|
24687 | var nextRange = findNextRange(videoBuffered, currentTime);
|
24688 |
|
24689 |
|
24690 | if (!nextRange.length) {
|
24691 | gap = this.gapFromVideoUnderflow_(videoBuffered, currentTime);
|
24692 | }
|
24693 | }
|
24694 |
|
24695 | if (gap) {
|
24696 | this.logger_("Encountered a gap in video from " + gap.start + " to " + gap.end + ". " + ("Seeking to current time " + currentTime));
|
24697 | return true;
|
24698 | }
|
24699 |
|
24700 | return false;
|
24701 | }
|
24702 | |
24703 |
|
24704 |
|
24705 |
|
24706 |
|
24707 |
|
24708 | ;
|
24709 |
|
24710 | _proto.skipTheGap_ = function skipTheGap_(scheduledCurrentTime) {
|
24711 | var buffered = this.tech_.buffered();
|
24712 | var currentTime = this.tech_.currentTime();
|
24713 | var nextRange = findNextRange(buffered, currentTime);
|
24714 | this.cancelTimer_();
|
24715 |
|
24716 | if (nextRange.length === 0 || currentTime !== scheduledCurrentTime) {
|
24717 | return;
|
24718 | }
|
24719 |
|
24720 | this.logger_('skipTheGap_:', 'currentTime:', currentTime, 'scheduled currentTime:', scheduledCurrentTime, 'nextRange start:', nextRange.start(0));
|
24721 |
|
24722 | this.tech_.setCurrentTime(nextRange.start(0) + TIME_FUDGE_FACTOR);
|
24723 | this.tech_.trigger({
|
24724 | type: 'usage',
|
24725 | name: 'vhs-gap-skip'
|
24726 | });
|
24727 | this.tech_.trigger({
|
24728 | type: 'usage',
|
24729 | name: 'hls-gap-skip'
|
24730 | });
|
24731 | };
|
24732 |
|
24733 | _proto.gapFromVideoUnderflow_ = function gapFromVideoUnderflow_(buffered, currentTime) {
|
24734 |
|
24735 |
|
24736 |
|
24737 |
|
24738 |
|
24739 |
|
24740 |
|
24741 |
|
24742 |
|
24743 |
|
24744 |
|
24745 |
|
24746 |
|
24747 |
|
24748 |
|
24749 |
|
24750 |
|
24751 |
|
24752 |
|
24753 |
|
24754 |
|
24755 |
|
24756 | var gaps = findGaps(buffered);
|
24757 |
|
24758 | for (var i = 0; i < gaps.length; i++) {
|
24759 | var start = gaps.start(i);
|
24760 | var end = gaps.end(i);
|
24761 |
|
24762 | if (currentTime - start < 4 && currentTime - start > 2) {
|
24763 | return {
|
24764 | start: start,
|
24765 | end: end
|
24766 | };
|
24767 | }
|
24768 | }
|
24769 |
|
24770 | return null;
|
24771 | };
|
24772 |
|
24773 | return PlaybackWatcher;
|
24774 | }();
|
24775 |
|
24776 | var defaultOptions = {
|
24777 | errorInterval: 30,
|
24778 | getSource: function getSource(next) {
|
24779 | var tech = this.tech({
|
24780 | IWillNotUseThisInPlugins: true
|
24781 | });
|
24782 | var sourceObj = tech.currentSource_ || this.currentSource();
|
24783 | return next(sourceObj);
|
24784 | }
|
24785 | };
|
24786 |
|
24787 |
|
24788 |
|
24789 |
|
24790 |
|
24791 |
|
24792 |
|
24793 |
|
24794 | var initPlugin = function initPlugin(player, options) {
|
24795 | var lastCalled = 0;
|
24796 | var seekTo = 0;
|
24797 | var localOptions = videojs__default["default"].mergeOptions(defaultOptions, options);
|
24798 | player.ready(function () {
|
24799 | player.trigger({
|
24800 | type: 'usage',
|
24801 | name: 'vhs-error-reload-initialized'
|
24802 | });
|
24803 | player.trigger({
|
24804 | type: 'usage',
|
24805 | name: 'hls-error-reload-initialized'
|
24806 | });
|
24807 | });
|
24808 | |
24809 |
|
24810 |
|
24811 |
|
24812 |
|
24813 |
|
24814 |
|
24815 | var loadedMetadataHandler = function loadedMetadataHandler() {
|
24816 | if (seekTo) {
|
24817 | player.currentTime(seekTo);
|
24818 | }
|
24819 | };
|
24820 | |
24821 |
|
24822 |
|
24823 |
|
24824 |
|
24825 |
|
24826 |
|
24827 |
|
24828 | var setSource = function setSource(sourceObj) {
|
24829 | if (sourceObj === null || sourceObj === undefined) {
|
24830 | return;
|
24831 | }
|
24832 |
|
24833 | seekTo = player.duration() !== Infinity && player.currentTime() || 0;
|
24834 | player.one('loadedmetadata', loadedMetadataHandler);
|
24835 | player.src(sourceObj);
|
24836 | player.trigger({
|
24837 | type: 'usage',
|
24838 | name: 'vhs-error-reload'
|
24839 | });
|
24840 | player.trigger({
|
24841 | type: 'usage',
|
24842 | name: 'hls-error-reload'
|
24843 | });
|
24844 | player.play();
|
24845 | };
|
24846 | |
24847 |
|
24848 |
|
24849 |
|
24850 |
|
24851 |
|
24852 |
|
24853 |
|
24854 | var errorHandler = function errorHandler() {
|
24855 |
|
24856 |
|
24857 | if (Date.now() - lastCalled < localOptions.errorInterval * 1000) {
|
24858 | player.trigger({
|
24859 | type: 'usage',
|
24860 | name: 'vhs-error-reload-canceled'
|
24861 | });
|
24862 | player.trigger({
|
24863 | type: 'usage',
|
24864 | name: 'hls-error-reload-canceled'
|
24865 | });
|
24866 | return;
|
24867 | }
|
24868 |
|
24869 | if (!localOptions.getSource || typeof localOptions.getSource !== 'function') {
|
24870 | videojs__default["default"].log.error('ERROR: reloadSourceOnError - The option getSource must be a function!');
|
24871 | return;
|
24872 | }
|
24873 |
|
24874 | lastCalled = Date.now();
|
24875 | return localOptions.getSource.call(player, setSource);
|
24876 | };
|
24877 | |
24878 |
|
24879 |
|
24880 |
|
24881 |
|
24882 |
|
24883 |
|
24884 | var cleanupEvents = function cleanupEvents() {
|
24885 | player.off('loadedmetadata', loadedMetadataHandler);
|
24886 | player.off('error', errorHandler);
|
24887 | player.off('dispose', cleanupEvents);
|
24888 | };
|
24889 | |
24890 |
|
24891 |
|
24892 |
|
24893 |
|
24894 |
|
24895 |
|
24896 |
|
24897 | var reinitPlugin = function reinitPlugin(newOptions) {
|
24898 | cleanupEvents();
|
24899 | initPlugin(player, newOptions);
|
24900 | };
|
24901 |
|
24902 | player.on('error', errorHandler);
|
24903 | player.on('dispose', cleanupEvents);
|
24904 |
|
24905 |
|
24906 | player.reloadSourceOnError = reinitPlugin;
|
24907 | };
|
24908 |
|
24909 |
|
24910 |
|
24911 |
|
24912 |
|
24913 |
|
24914 |
|
24915 |
|
24916 | var reloadSourceOnError = function reloadSourceOnError(options) {
|
24917 | initPlugin(this, options);
|
24918 | };
|
24919 |
|
24920 | var version$4 = "2.11.1";
|
24921 |
|
24922 | var version$3 = "5.14.1";
|
24923 |
|
24924 | var version$2 = "0.19.2";
|
24925 |
|
24926 | var version$1 = "4.7.0";
|
24927 |
|
24928 | var version = "3.1.2";
|
24929 |
|
24930 | var Vhs = {
|
24931 | PlaylistLoader: PlaylistLoader,
|
24932 | Playlist: Playlist,
|
24933 | utils: utils,
|
24934 | STANDARD_PLAYLIST_SELECTOR: lastBandwidthSelector,
|
24935 | INITIAL_PLAYLIST_SELECTOR: lowestBitrateCompatibleVariantSelector,
|
24936 | lastBandwidthSelector: lastBandwidthSelector,
|
24937 | movingAverageBandwidthSelector: movingAverageBandwidthSelector,
|
24938 | comparePlaylistBandwidth: comparePlaylistBandwidth,
|
24939 | comparePlaylistResolution: comparePlaylistResolution,
|
24940 | xhr: xhrFactory()
|
24941 | };
|
24942 |
|
24943 | Object.keys(Config).forEach(function (prop) {
|
24944 | Object.defineProperty(Vhs, prop, {
|
24945 | get: function get() {
|
24946 | videojs__default["default"].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
24947 | return Config[prop];
|
24948 | },
|
24949 | set: function set(value) {
|
24950 | videojs__default["default"].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
24951 |
|
24952 | if (typeof value !== 'number' || value < 0) {
|
24953 | videojs__default["default"].log.warn("value of Vhs." + prop + " must be greater than or equal to 0");
|
24954 | return;
|
24955 | }
|
24956 |
|
24957 | Config[prop] = value;
|
24958 | }
|
24959 | });
|
24960 | });
|
24961 | var LOCAL_STORAGE_KEY = 'videojs-vhs';
|
24962 |
|
24963 |
|
24964 |
|
24965 |
|
24966 |
|
24967 |
|
24968 |
|
24969 |
|
24970 | var handleVhsMediaChange = function handleVhsMediaChange(qualityLevels, playlistLoader) {
|
24971 | var newPlaylist = playlistLoader.media();
|
24972 | var selectedIndex = -1;
|
24973 |
|
24974 | for (var i = 0; i < qualityLevels.length; i++) {
|
24975 | if (qualityLevels[i].id === newPlaylist.id) {
|
24976 | selectedIndex = i;
|
24977 | break;
|
24978 | }
|
24979 | }
|
24980 |
|
24981 | qualityLevels.selectedIndex_ = selectedIndex;
|
24982 | qualityLevels.trigger({
|
24983 | selectedIndex: selectedIndex,
|
24984 | type: 'change'
|
24985 | });
|
24986 | };
|
24987 |
|
24988 |
|
24989 |
|
24990 |
|
24991 |
|
24992 |
|
24993 |
|
24994 |
|
24995 |
|
24996 | var handleVhsLoadedMetadata = function handleVhsLoadedMetadata(qualityLevels, vhs) {
|
24997 | vhs.representations().forEach(function (rep) {
|
24998 | qualityLevels.addQualityLevel(rep);
|
24999 | });
|
25000 | handleVhsMediaChange(qualityLevels, vhs.playlists);
|
25001 | };
|
25002 |
|
25003 |
|
25004 |
|
25005 | Vhs.canPlaySource = function () {
|
25006 | return videojs__default["default"].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
25007 | };
|
25008 |
|
25009 | var emeKeySystems = function emeKeySystems(keySystemOptions, mainPlaylist, audioPlaylist) {
|
25010 | if (!keySystemOptions) {
|
25011 | return keySystemOptions;
|
25012 | }
|
25013 |
|
25014 | var codecs = {};
|
25015 |
|
25016 | if (mainPlaylist && mainPlaylist.attributes && mainPlaylist.attributes.CODECS) {
|
25017 | codecs = unwrapCodecList(codecs_js.parseCodecs(mainPlaylist.attributes.CODECS));
|
25018 | }
|
25019 |
|
25020 | if (audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS) {
|
25021 | codecs.audio = audioPlaylist.attributes.CODECS;
|
25022 | }
|
25023 |
|
25024 | var videoContentType = codecs_js.getMimeForCodec(codecs.video);
|
25025 | var audioContentType = codecs_js.getMimeForCodec(codecs.audio);
|
25026 |
|
25027 | var keySystemContentTypes = {};
|
25028 |
|
25029 | for (var keySystem in keySystemOptions) {
|
25030 | keySystemContentTypes[keySystem] = {};
|
25031 |
|
25032 | if (audioContentType) {
|
25033 | keySystemContentTypes[keySystem].audioContentType = audioContentType;
|
25034 | }
|
25035 |
|
25036 | if (videoContentType) {
|
25037 | keySystemContentTypes[keySystem].videoContentType = videoContentType;
|
25038 | }
|
25039 |
|
25040 |
|
25041 |
|
25042 |
|
25043 |
|
25044 |
|
25045 |
|
25046 | if (mainPlaylist.contentProtection && mainPlaylist.contentProtection[keySystem] && mainPlaylist.contentProtection[keySystem].pssh) {
|
25047 | keySystemContentTypes[keySystem].pssh = mainPlaylist.contentProtection[keySystem].pssh;
|
25048 | }
|
25049 |
|
25050 |
|
25051 |
|
25052 | if (typeof keySystemOptions[keySystem] === 'string') {
|
25053 | keySystemContentTypes[keySystem].url = keySystemOptions[keySystem];
|
25054 | }
|
25055 | }
|
25056 |
|
25057 | return videojs__default["default"].mergeOptions(keySystemOptions, keySystemContentTypes);
|
25058 | };
|
25059 |
|
25060 |
|
25061 |
|
25062 |
|
25063 |
|
25064 |
|
25065 |
|
25066 |
|
25067 |
|
25068 |
|
25069 |
|
25070 |
|
25071 |
|
25072 |
|
25073 |
|
25074 |
|
25075 |
|
25076 |
|
25077 |
|
25078 |
|
25079 |
|
25080 |
|
25081 |
|
25082 |
|
25083 |
|
25084 | var getAllPsshKeySystemsOptions = function getAllPsshKeySystemsOptions(playlists, keySystems) {
|
25085 | return playlists.reduce(function (keySystemsArr, playlist) {
|
25086 | if (!playlist.contentProtection) {
|
25087 | return keySystemsArr;
|
25088 | }
|
25089 |
|
25090 | var keySystemsOptions = keySystems.reduce(function (keySystemsObj, keySystem) {
|
25091 | var keySystemOptions = playlist.contentProtection[keySystem];
|
25092 |
|
25093 | if (keySystemOptions && keySystemOptions.pssh) {
|
25094 | keySystemsObj[keySystem] = {
|
25095 | pssh: keySystemOptions.pssh
|
25096 | };
|
25097 | }
|
25098 |
|
25099 | return keySystemsObj;
|
25100 | }, {});
|
25101 |
|
25102 | if (Object.keys(keySystemsOptions).length) {
|
25103 | keySystemsArr.push(keySystemsOptions);
|
25104 | }
|
25105 |
|
25106 | return keySystemsArr;
|
25107 | }, []);
|
25108 | };
|
25109 |
|
25110 |
|
25111 |
|
25112 |
|
25113 |
|
25114 |
|
25115 |
|
25116 |
|
25117 |
|
25118 |
|
25119 |
|
25120 |
|
25121 |
|
25122 |
|
25123 |
|
25124 |
|
25125 |
|
25126 |
|
25127 |
|
25128 |
|
25129 |
|
25130 |
|
25131 |
|
25132 |
|
25133 |
|
25134 |
|
25135 | var waitForKeySessionCreation = function waitForKeySessionCreation(_ref) {
|
25136 | var player = _ref.player,
|
25137 | sourceKeySystems = _ref.sourceKeySystems,
|
25138 | audioMedia = _ref.audioMedia,
|
25139 | mainPlaylists = _ref.mainPlaylists;
|
25140 |
|
25141 | if (!player.eme.initializeMediaKeys) {
|
25142 | return Promise.resolve();
|
25143 | }
|
25144 |
|
25145 |
|
25146 |
|
25147 |
|
25148 |
|
25149 |
|
25150 |
|
25151 |
|
25152 |
|
25153 | var playlists = audioMedia ? mainPlaylists.concat([audioMedia]) : mainPlaylists;
|
25154 | var keySystemsOptionsArr = getAllPsshKeySystemsOptions(playlists, Object.keys(sourceKeySystems));
|
25155 | var initializationFinishedPromises = [];
|
25156 | var keySessionCreatedPromises = [];
|
25157 |
|
25158 |
|
25159 |
|
25160 |
|
25161 |
|
25162 | keySystemsOptionsArr.forEach(function (keySystemsOptions) {
|
25163 | keySessionCreatedPromises.push(new Promise(function (resolve, reject) {
|
25164 | player.tech_.one('keysessioncreated', resolve);
|
25165 | }));
|
25166 | initializationFinishedPromises.push(new Promise(function (resolve, reject) {
|
25167 | player.eme.initializeMediaKeys({
|
25168 | keySystems: keySystemsOptions
|
25169 | }, function (err) {
|
25170 | if (err) {
|
25171 | reject(err);
|
25172 | return;
|
25173 | }
|
25174 |
|
25175 | resolve();
|
25176 | });
|
25177 | }));
|
25178 | });
|
25179 |
|
25180 |
|
25181 |
|
25182 |
|
25183 |
|
25184 |
|
25185 | return Promise.race([
|
25186 |
|
25187 |
|
25188 | Promise.all(initializationFinishedPromises),
|
25189 | Promise.race(keySessionCreatedPromises)]);
|
25190 | };
|
25191 |
|
25192 |
|
25193 |
|
25194 |
|
25195 |
|
25196 |
|
25197 |
|
25198 |
|
25199 |
|
25200 |
|
25201 |
|
25202 |
|
25203 |
|
25204 |
|
25205 |
|
25206 |
|
25207 |
|
25208 |
|
25209 | var setupEmeOptions = function setupEmeOptions(_ref2) {
|
25210 | var player = _ref2.player,
|
25211 | sourceKeySystems = _ref2.sourceKeySystems,
|
25212 | media = _ref2.media,
|
25213 | audioMedia = _ref2.audioMedia;
|
25214 | var sourceOptions = emeKeySystems(sourceKeySystems, media, audioMedia);
|
25215 |
|
25216 | if (!sourceOptions) {
|
25217 | return false;
|
25218 | }
|
25219 |
|
25220 | player.currentSource().keySystems = sourceOptions;
|
25221 |
|
25222 |
|
25223 | if (sourceOptions && !player.eme) {
|
25224 | videojs__default["default"].log.warn('DRM encrypted source cannot be decrypted without a DRM plugin');
|
25225 | return false;
|
25226 | }
|
25227 |
|
25228 | return true;
|
25229 | };
|
25230 |
|
25231 | var getVhsLocalStorage = function getVhsLocalStorage() {
|
25232 | if (!window__default["default"].localStorage) {
|
25233 | return null;
|
25234 | }
|
25235 |
|
25236 | var storedObject = window__default["default"].localStorage.getItem(LOCAL_STORAGE_KEY);
|
25237 |
|
25238 | if (!storedObject) {
|
25239 | return null;
|
25240 | }
|
25241 |
|
25242 | try {
|
25243 | return JSON.parse(storedObject);
|
25244 | } catch (e) {
|
25245 |
|
25246 | return null;
|
25247 | }
|
25248 | };
|
25249 |
|
25250 | var updateVhsLocalStorage = function updateVhsLocalStorage(options) {
|
25251 | if (!window__default["default"].localStorage) {
|
25252 | return false;
|
25253 | }
|
25254 |
|
25255 | var objectToStore = getVhsLocalStorage();
|
25256 | objectToStore = objectToStore ? videojs__default["default"].mergeOptions(objectToStore, options) : options;
|
25257 |
|
25258 | try {
|
25259 | window__default["default"].localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(objectToStore));
|
25260 | } catch (e) {
|
25261 |
|
25262 |
|
25263 |
|
25264 |
|
25265 | return false;
|
25266 | }
|
25267 |
|
25268 | return objectToStore;
|
25269 | };
|
25270 |
|
25271 |
|
25272 |
|
25273 |
|
25274 |
|
25275 |
|
25276 |
|
25277 |
|
25278 |
|
25279 |
|
25280 |
|
25281 |
|
25282 |
|
25283 |
|
25284 | var expandDataUri = function expandDataUri(dataUri) {
|
25285 | if (dataUri.toLowerCase().indexOf('data:application/vnd.videojs.vhs+json,') === 0) {
|
25286 | return JSON.parse(dataUri.substring(dataUri.indexOf(',') + 1));
|
25287 | }
|
25288 |
|
25289 |
|
25290 | return dataUri;
|
25291 | };
|
25292 |
|
25293 |
|
25294 |
|
25295 |
|
25296 |
|
25297 | Vhs.supportsNativeHls = function () {
|
25298 | if (!document__default["default"] || !document__default["default"].createElement) {
|
25299 | return false;
|
25300 | }
|
25301 |
|
25302 | var video = document__default["default"].createElement('video');
|
25303 |
|
25304 | if (!videojs__default["default"].getTech('Html5').isSupported()) {
|
25305 | return false;
|
25306 | }
|
25307 |
|
25308 |
|
25309 | var canPlay = [
|
25310 | 'application/vnd.apple.mpegurl',
|
25311 | 'audio/mpegurl',
|
25312 | 'audio/x-mpegurl',
|
25313 | 'application/x-mpegurl',
|
25314 | 'video/x-mpegurl', 'video/mpegurl', 'application/mpegurl'];
|
25315 | return canPlay.some(function (canItPlay) {
|
25316 | return /maybe|probably/i.test(video.canPlayType(canItPlay));
|
25317 | });
|
25318 | }();
|
25319 |
|
25320 | Vhs.supportsNativeDash = function () {
|
25321 | if (!document__default["default"] || !document__default["default"].createElement || !videojs__default["default"].getTech('Html5').isSupported()) {
|
25322 | return false;
|
25323 | }
|
25324 |
|
25325 | return /maybe|probably/i.test(document__default["default"].createElement('video').canPlayType('application/dash+xml'));
|
25326 | }();
|
25327 |
|
25328 | Vhs.supportsTypeNatively = function (type) {
|
25329 | if (type === 'hls') {
|
25330 | return Vhs.supportsNativeHls;
|
25331 | }
|
25332 |
|
25333 | if (type === 'dash') {
|
25334 | return Vhs.supportsNativeDash;
|
25335 | }
|
25336 |
|
25337 | return false;
|
25338 | };
|
25339 |
|
25340 |
|
25341 |
|
25342 |
|
25343 |
|
25344 |
|
25345 | Vhs.isSupported = function () {
|
25346 | return videojs__default["default"].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
25347 | };
|
25348 |
|
25349 | var Component = videojs__default["default"].getComponent('Component');
|
25350 |
|
25351 |
|
25352 |
|
25353 |
|
25354 |
|
25355 |
|
25356 |
|
25357 |
|
25358 |
|
25359 |
|
25360 |
|
25361 | var VhsHandler = function (_Component) {
|
25362 | _inheritsLoose__default["default"](VhsHandler, _Component);
|
25363 |
|
25364 | function VhsHandler(source, tech, options) {
|
25365 | var _this;
|
25366 |
|
25367 | _this = _Component.call(this, tech, videojs__default["default"].mergeOptions(options.hls, options.vhs)) || this;
|
25368 |
|
25369 | if (options.hls && Object.keys(options.hls).length) {
|
25370 | videojs__default["default"].log.warn('Using hls options is deprecated. Use vhs instead.');
|
25371 | }
|
25372 |
|
25373 |
|
25374 |
|
25375 | if (typeof options.initialBandwidth === 'number') {
|
25376 | _this.options_.bandwidth = options.initialBandwidth;
|
25377 | }
|
25378 |
|
25379 | _this.logger_ = logger('VhsHandler');
|
25380 |
|
25381 |
|
25382 | if (tech.options_ && tech.options_.playerId) {
|
25383 | var _player = videojs__default["default"](tech.options_.playerId);
|
25384 |
|
25385 | if (!_player.hasOwnProperty('hls')) {
|
25386 | Object.defineProperty(_player, 'hls', {
|
25387 | get: function get() {
|
25388 | videojs__default["default"].log.warn('player.hls is deprecated. Use player.tech().vhs instead.');
|
25389 | tech.trigger({
|
25390 | type: 'usage',
|
25391 | name: 'hls-player-access'
|
25392 | });
|
25393 | return _assertThisInitialized__default["default"](_this);
|
25394 | },
|
25395 | configurable: true
|
25396 | });
|
25397 | }
|
25398 |
|
25399 | if (!_player.hasOwnProperty('vhs')) {
|
25400 | Object.defineProperty(_player, 'vhs', {
|
25401 | get: function get() {
|
25402 | videojs__default["default"].log.warn('player.vhs is deprecated. Use player.tech().vhs instead.');
|
25403 | tech.trigger({
|
25404 | type: 'usage',
|
25405 | name: 'vhs-player-access'
|
25406 | });
|
25407 | return _assertThisInitialized__default["default"](_this);
|
25408 | },
|
25409 | configurable: true
|
25410 | });
|
25411 | }
|
25412 |
|
25413 | if (!_player.hasOwnProperty('dash')) {
|
25414 | Object.defineProperty(_player, 'dash', {
|
25415 | get: function get() {
|
25416 | videojs__default["default"].log.warn('player.dash is deprecated. Use player.tech().vhs instead.');
|
25417 | return _assertThisInitialized__default["default"](_this);
|
25418 | },
|
25419 | configurable: true
|
25420 | });
|
25421 | }
|
25422 |
|
25423 | _this.player_ = _player;
|
25424 | }
|
25425 |
|
25426 | _this.tech_ = tech;
|
25427 | _this.source_ = source;
|
25428 | _this.stats = {};
|
25429 | _this.ignoreNextSeekingEvent_ = false;
|
25430 |
|
25431 | _this.setOptions_();
|
25432 |
|
25433 | if (_this.options_.overrideNative && tech.overrideNativeAudioTracks && tech.overrideNativeVideoTracks) {
|
25434 | tech.overrideNativeAudioTracks(true);
|
25435 | tech.overrideNativeVideoTracks(true);
|
25436 | } else if (_this.options_.overrideNative && (tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
|
25437 |
|
25438 |
|
25439 | throw new Error('Overriding native HLS requires emulated tracks. ' + 'See https://git.io/vMpjB');
|
25440 | }
|
25441 |
|
25442 |
|
25443 |
|
25444 | _this.on(document__default["default"], ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'], function (event) {
|
25445 | var fullscreenElement = document__default["default"].fullscreenElement || document__default["default"].webkitFullscreenElement || document__default["default"].mozFullScreenElement || document__default["default"].msFullscreenElement;
|
25446 |
|
25447 | if (fullscreenElement && fullscreenElement.contains(_this.tech_.el())) {
|
25448 | _this.masterPlaylistController_.fastQualityChange_();
|
25449 | } else {
|
25450 |
|
25451 |
|
25452 |
|
25453 | _this.masterPlaylistController_.checkABR_();
|
25454 | }
|
25455 | });
|
25456 |
|
25457 | _this.on(_this.tech_, 'seeking', function () {
|
25458 | if (this.ignoreNextSeekingEvent_) {
|
25459 | this.ignoreNextSeekingEvent_ = false;
|
25460 | return;
|
25461 | }
|
25462 |
|
25463 | this.setCurrentTime(this.tech_.currentTime());
|
25464 | });
|
25465 |
|
25466 | _this.on(_this.tech_, 'error', function () {
|
25467 |
|
25468 |
|
25469 | if (this.tech_.error() && this.masterPlaylistController_) {
|
25470 | this.masterPlaylistController_.pauseLoading();
|
25471 | }
|
25472 | });
|
25473 |
|
25474 | _this.on(_this.tech_, 'play', _this.play);
|
25475 |
|
25476 | return _this;
|
25477 | }
|
25478 |
|
25479 | var _proto = VhsHandler.prototype;
|
25480 |
|
25481 | _proto.setOptions_ = function setOptions_() {
|
25482 | var _this2 = this;
|
25483 |
|
25484 |
|
25485 | this.options_.withCredentials = this.options_.withCredentials || false;
|
25486 | this.options_.handleManifestRedirects = this.options_.handleManifestRedirects === false ? false : true;
|
25487 | this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
|
25488 | this.options_.useDevicePixelRatio = this.options_.useDevicePixelRatio || false;
|
25489 | this.options_.smoothQualityChange = this.options_.smoothQualityChange || false;
|
25490 | this.options_.useBandwidthFromLocalStorage = typeof this.source_.useBandwidthFromLocalStorage !== 'undefined' ? this.source_.useBandwidthFromLocalStorage : this.options_.useBandwidthFromLocalStorage || false;
|
25491 | this.options_.customTagParsers = this.options_.customTagParsers || [];
|
25492 | this.options_.customTagMappers = this.options_.customTagMappers || [];
|
25493 | this.options_.cacheEncryptionKeys = this.options_.cacheEncryptionKeys || false;
|
25494 |
|
25495 | if (typeof this.options_.blacklistDuration !== 'number') {
|
25496 | this.options_.blacklistDuration = 5 * 60;
|
25497 | }
|
25498 |
|
25499 | if (typeof this.options_.bandwidth !== 'number') {
|
25500 | if (this.options_.useBandwidthFromLocalStorage) {
|
25501 | var storedObject = getVhsLocalStorage();
|
25502 |
|
25503 | if (storedObject && storedObject.bandwidth) {
|
25504 | this.options_.bandwidth = storedObject.bandwidth;
|
25505 | this.tech_.trigger({
|
25506 | type: 'usage',
|
25507 | name: 'vhs-bandwidth-from-local-storage'
|
25508 | });
|
25509 | this.tech_.trigger({
|
25510 | type: 'usage',
|
25511 | name: 'hls-bandwidth-from-local-storage'
|
25512 | });
|
25513 | }
|
25514 |
|
25515 | if (storedObject && storedObject.throughput) {
|
25516 | this.options_.throughput = storedObject.throughput;
|
25517 | this.tech_.trigger({
|
25518 | type: 'usage',
|
25519 | name: 'vhs-throughput-from-local-storage'
|
25520 | });
|
25521 | this.tech_.trigger({
|
25522 | type: 'usage',
|
25523 | name: 'hls-throughput-from-local-storage'
|
25524 | });
|
25525 | }
|
25526 | }
|
25527 | }
|
25528 |
|
25529 |
|
25530 |
|
25531 | if (typeof this.options_.bandwidth !== 'number') {
|
25532 | this.options_.bandwidth = Config.INITIAL_BANDWIDTH;
|
25533 | }
|
25534 |
|
25535 |
|
25536 |
|
25537 | this.options_.enableLowInitialPlaylist = this.options_.enableLowInitialPlaylist && this.options_.bandwidth === Config.INITIAL_BANDWIDTH;
|
25538 |
|
25539 | ['withCredentials', 'useDevicePixelRatio', 'limitRenditionByPlayerDimensions', 'bandwidth', 'smoothQualityChange', 'customTagParsers', 'customTagMappers', 'handleManifestRedirects', 'cacheEncryptionKeys', 'playlistSelector', 'initialPlaylistSelector', 'experimentalBufferBasedABR', 'liveRangeSafeTimeDelta', 'experimentalLLHLS', 'experimentalExactManifestTimings', 'experimentalLeastPixelDiffSelector'].forEach(function (option) {
|
25540 | if (typeof _this2.source_[option] !== 'undefined') {
|
25541 | _this2.options_[option] = _this2.source_[option];
|
25542 | }
|
25543 | });
|
25544 | this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
|
25545 | this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
|
25546 | }
|
25547 | |
25548 |
|
25549 |
|
25550 |
|
25551 |
|
25552 | ;
|
25553 |
|
25554 | _proto.src = function src(_src, type) {
|
25555 | var _this3 = this;
|
25556 |
|
25557 |
|
25558 | if (!_src) {
|
25559 | return;
|
25560 | }
|
25561 |
|
25562 | this.setOptions_();
|
25563 |
|
25564 | this.options_.src = expandDataUri(this.source_.src);
|
25565 | this.options_.tech = this.tech_;
|
25566 | this.options_.externVhs = Vhs;
|
25567 | this.options_.sourceType = mediaTypes_js.simpleTypeFromSourceType(type);
|
25568 |
|
25569 | this.options_.seekTo = function (time) {
|
25570 | _this3.tech_.setCurrentTime(time);
|
25571 | };
|
25572 |
|
25573 | if (this.options_.smoothQualityChange) {
|
25574 | videojs__default["default"].log.warn('smoothQualityChange is deprecated and will be removed in the next major version');
|
25575 | }
|
25576 |
|
25577 | this.masterPlaylistController_ = new MasterPlaylistController(this.options_);
|
25578 | var playbackWatcherOptions = videojs__default["default"].mergeOptions({
|
25579 | liveRangeSafeTimeDelta: SAFE_TIME_DELTA
|
25580 | }, this.options_, {
|
25581 | seekable: function seekable() {
|
25582 | return _this3.seekable();
|
25583 | },
|
25584 | media: function media() {
|
25585 | return _this3.masterPlaylistController_.media();
|
25586 | },
|
25587 | masterPlaylistController: this.masterPlaylistController_
|
25588 | });
|
25589 | this.playbackWatcher_ = new PlaybackWatcher(playbackWatcherOptions);
|
25590 | this.masterPlaylistController_.on('error', function () {
|
25591 | var player = videojs__default["default"].players[_this3.tech_.options_.playerId];
|
25592 | var error = _this3.masterPlaylistController_.error;
|
25593 |
|
25594 | if (typeof error === 'object' && !error.code) {
|
25595 | error.code = 3;
|
25596 | } else if (typeof error === 'string') {
|
25597 | error = {
|
25598 | message: error,
|
25599 | code: 3
|
25600 | };
|
25601 | }
|
25602 |
|
25603 | player.error(error);
|
25604 | });
|
25605 | var defaultSelector = this.options_.experimentalBufferBasedABR ? Vhs.movingAverageBandwidthSelector(0.55) : Vhs.STANDARD_PLAYLIST_SELECTOR;
|
25606 |
|
25607 |
|
25608 | this.masterPlaylistController_.selectPlaylist = this.selectPlaylist ? this.selectPlaylist.bind(this) : defaultSelector.bind(this);
|
25609 | this.masterPlaylistController_.selectInitialPlaylist = Vhs.INITIAL_PLAYLIST_SELECTOR.bind(this);
|
25610 |
|
25611 | this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
|
25612 | this.mediaSource = this.masterPlaylistController_.mediaSource;
|
25613 |
|
25614 |
|
25615 |
|
25616 | Object.defineProperties(this, {
|
25617 | selectPlaylist: {
|
25618 | get: function get() {
|
25619 | return this.masterPlaylistController_.selectPlaylist;
|
25620 | },
|
25621 | set: function set(selectPlaylist) {
|
25622 | this.masterPlaylistController_.selectPlaylist = selectPlaylist.bind(this);
|
25623 | }
|
25624 | },
|
25625 | throughput: {
|
25626 | get: function get() {
|
25627 | return this.masterPlaylistController_.mainSegmentLoader_.throughput.rate;
|
25628 | },
|
25629 | set: function set(throughput) {
|
25630 | this.masterPlaylistController_.mainSegmentLoader_.throughput.rate = throughput;
|
25631 |
|
25632 |
|
25633 | this.masterPlaylistController_.mainSegmentLoader_.throughput.count = 1;
|
25634 | }
|
25635 | },
|
25636 | bandwidth: {
|
25637 | get: function get() {
|
25638 | return this.masterPlaylistController_.mainSegmentLoader_.bandwidth;
|
25639 | },
|
25640 | set: function set(bandwidth) {
|
25641 | this.masterPlaylistController_.mainSegmentLoader_.bandwidth = bandwidth;
|
25642 |
|
25643 |
|
25644 |
|
25645 | this.masterPlaylistController_.mainSegmentLoader_.throughput = {
|
25646 | rate: 0,
|
25647 | count: 0
|
25648 | };
|
25649 | }
|
25650 | },
|
25651 |
|
25652 | |
25653 |
|
25654 |
|
25655 |
|
25656 |
|
25657 |
|
25658 |
|
25659 |
|
25660 |
|
25661 | systemBandwidth: {
|
25662 | get: function get() {
|
25663 | var invBandwidth = 1 / (this.bandwidth || 1);
|
25664 | var invThroughput;
|
25665 |
|
25666 | if (this.throughput > 0) {
|
25667 | invThroughput = 1 / this.throughput;
|
25668 | } else {
|
25669 | invThroughput = 0;
|
25670 | }
|
25671 |
|
25672 | var systemBitrate = Math.floor(1 / (invBandwidth + invThroughput));
|
25673 | return systemBitrate;
|
25674 | },
|
25675 | set: function set() {
|
25676 | videojs__default["default"].log.error('The "systemBandwidth" property is read-only');
|
25677 | }
|
25678 | }
|
25679 | });
|
25680 |
|
25681 | if (this.options_.bandwidth) {
|
25682 | this.bandwidth = this.options_.bandwidth;
|
25683 | }
|
25684 |
|
25685 | if (this.options_.throughput) {
|
25686 | this.throughput = this.options_.throughput;
|
25687 | }
|
25688 |
|
25689 | Object.defineProperties(this.stats, {
|
25690 | bandwidth: {
|
25691 | get: function get() {
|
25692 | return _this3.bandwidth || 0;
|
25693 | },
|
25694 | enumerable: true
|
25695 | },
|
25696 | mediaRequests: {
|
25697 | get: function get() {
|
25698 | return _this3.masterPlaylistController_.mediaRequests_() || 0;
|
25699 | },
|
25700 | enumerable: true
|
25701 | },
|
25702 | mediaRequestsAborted: {
|
25703 | get: function get() {
|
25704 | return _this3.masterPlaylistController_.mediaRequestsAborted_() || 0;
|
25705 | },
|
25706 | enumerable: true
|
25707 | },
|
25708 | mediaRequestsTimedout: {
|
25709 | get: function get() {
|
25710 | return _this3.masterPlaylistController_.mediaRequestsTimedout_() || 0;
|
25711 | },
|
25712 | enumerable: true
|
25713 | },
|
25714 | mediaRequestsErrored: {
|
25715 | get: function get() {
|
25716 | return _this3.masterPlaylistController_.mediaRequestsErrored_() || 0;
|
25717 | },
|
25718 | enumerable: true
|
25719 | },
|
25720 | mediaTransferDuration: {
|
25721 | get: function get() {
|
25722 | return _this3.masterPlaylistController_.mediaTransferDuration_() || 0;
|
25723 | },
|
25724 | enumerable: true
|
25725 | },
|
25726 | mediaBytesTransferred: {
|
25727 | get: function get() {
|
25728 | return _this3.masterPlaylistController_.mediaBytesTransferred_() || 0;
|
25729 | },
|
25730 | enumerable: true
|
25731 | },
|
25732 | mediaSecondsLoaded: {
|
25733 | get: function get() {
|
25734 | return _this3.masterPlaylistController_.mediaSecondsLoaded_() || 0;
|
25735 | },
|
25736 | enumerable: true
|
25737 | },
|
25738 | mediaAppends: {
|
25739 | get: function get() {
|
25740 | return _this3.masterPlaylistController_.mediaAppends_() || 0;
|
25741 | },
|
25742 | enumerable: true
|
25743 | },
|
25744 | mainAppendsToLoadedData: {
|
25745 | get: function get() {
|
25746 | return _this3.masterPlaylistController_.mainAppendsToLoadedData_() || 0;
|
25747 | },
|
25748 | enumerable: true
|
25749 | },
|
25750 | audioAppendsToLoadedData: {
|
25751 | get: function get() {
|
25752 | return _this3.masterPlaylistController_.audioAppendsToLoadedData_() || 0;
|
25753 | },
|
25754 | enumerable: true
|
25755 | },
|
25756 | appendsToLoadedData: {
|
25757 | get: function get() {
|
25758 | return _this3.masterPlaylistController_.appendsToLoadedData_() || 0;
|
25759 | },
|
25760 | enumerable: true
|
25761 | },
|
25762 | timeToLoadedData: {
|
25763 | get: function get() {
|
25764 | return _this3.masterPlaylistController_.timeToLoadedData_() || 0;
|
25765 | },
|
25766 | enumerable: true
|
25767 | },
|
25768 | buffered: {
|
25769 | get: function get() {
|
25770 | return timeRangesToArray(_this3.tech_.buffered());
|
25771 | },
|
25772 | enumerable: true
|
25773 | },
|
25774 | currentTime: {
|
25775 | get: function get() {
|
25776 | return _this3.tech_.currentTime();
|
25777 | },
|
25778 | enumerable: true
|
25779 | },
|
25780 | currentSource: {
|
25781 | get: function get() {
|
25782 | return _this3.tech_.currentSource_;
|
25783 | },
|
25784 | enumerable: true
|
25785 | },
|
25786 | currentTech: {
|
25787 | get: function get() {
|
25788 | return _this3.tech_.name_;
|
25789 | },
|
25790 | enumerable: true
|
25791 | },
|
25792 | duration: {
|
25793 | get: function get() {
|
25794 | return _this3.tech_.duration();
|
25795 | },
|
25796 | enumerable: true
|
25797 | },
|
25798 | master: {
|
25799 | get: function get() {
|
25800 | return _this3.playlists.master;
|
25801 | },
|
25802 | enumerable: true
|
25803 | },
|
25804 | playerDimensions: {
|
25805 | get: function get() {
|
25806 | return _this3.tech_.currentDimensions();
|
25807 | },
|
25808 | enumerable: true
|
25809 | },
|
25810 | seekable: {
|
25811 | get: function get() {
|
25812 | return timeRangesToArray(_this3.tech_.seekable());
|
25813 | },
|
25814 | enumerable: true
|
25815 | },
|
25816 | timestamp: {
|
25817 | get: function get() {
|
25818 | return Date.now();
|
25819 | },
|
25820 | enumerable: true
|
25821 | },
|
25822 | videoPlaybackQuality: {
|
25823 | get: function get() {
|
25824 | return _this3.tech_.getVideoPlaybackQuality();
|
25825 | },
|
25826 | enumerable: true
|
25827 | }
|
25828 | });
|
25829 | this.tech_.one('canplay', this.masterPlaylistController_.setupFirstPlay.bind(this.masterPlaylistController_));
|
25830 | this.tech_.on('bandwidthupdate', function () {
|
25831 | if (_this3.options_.useBandwidthFromLocalStorage) {
|
25832 | updateVhsLocalStorage({
|
25833 | bandwidth: _this3.bandwidth,
|
25834 | throughput: Math.round(_this3.throughput)
|
25835 | });
|
25836 | }
|
25837 | });
|
25838 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
25839 |
|
25840 | renditionSelectionMixin(_this3);
|
25841 | });
|
25842 | this.masterPlaylistController_.sourceUpdater_.on('createdsourcebuffers', function () {
|
25843 | _this3.setupEme_();
|
25844 | });
|
25845 |
|
25846 |
|
25847 | this.on(this.masterPlaylistController_, 'progress', function () {
|
25848 | this.tech_.trigger('progress');
|
25849 | });
|
25850 |
|
25851 |
|
25852 | this.on(this.masterPlaylistController_, 'firstplay', function () {
|
25853 | this.ignoreNextSeekingEvent_ = true;
|
25854 | });
|
25855 | this.setupQualityLevels_();
|
25856 |
|
25857 |
|
25858 | if (!this.tech_.el()) {
|
25859 | return;
|
25860 | }
|
25861 |
|
25862 | this.mediaSourceUrl_ = window__default["default"].URL.createObjectURL(this.masterPlaylistController_.mediaSource);
|
25863 | this.tech_.src(this.mediaSourceUrl_);
|
25864 | }
|
25865 | |
25866 |
|
25867 |
|
25868 |
|
25869 |
|
25870 |
|
25871 |
|
25872 |
|
25873 | ;
|
25874 |
|
25875 | _proto.setupEme_ = function setupEme_() {
|
25876 | var _this4 = this;
|
25877 |
|
25878 | var audioPlaylistLoader = this.masterPlaylistController_.mediaTypes_.AUDIO.activePlaylistLoader;
|
25879 | var didSetupEmeOptions = setupEmeOptions({
|
25880 | player: this.player_,
|
25881 | sourceKeySystems: this.source_.keySystems,
|
25882 | media: this.playlists.media(),
|
25883 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media()
|
25884 | });
|
25885 | this.player_.tech_.on('keystatuschange', function (e) {
|
25886 | if (e.status === 'output-restricted') {
|
25887 | _this4.masterPlaylistController_.blacklistCurrentPlaylist({
|
25888 | playlist: _this4.masterPlaylistController_.media(),
|
25889 | message: "DRM keystatus changed to " + e.status + ". Playlist will fail to play. Check for HDCP content.",
|
25890 | blacklistDuration: Infinity
|
25891 | });
|
25892 | }
|
25893 | });
|
25894 |
|
25895 |
|
25896 | if (videojs__default["default"].browser.IE_VERSION === 11 || !didSetupEmeOptions) {
|
25897 |
|
25898 | this.masterPlaylistController_.sourceUpdater_.initializedEme();
|
25899 | return;
|
25900 | }
|
25901 |
|
25902 | this.logger_('waiting for EME key session creation');
|
25903 | waitForKeySessionCreation({
|
25904 | player: this.player_,
|
25905 | sourceKeySystems: this.source_.keySystems,
|
25906 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media(),
|
25907 | mainPlaylists: this.playlists.master.playlists
|
25908 | }).then(function () {
|
25909 | _this4.logger_('created EME key session');
|
25910 |
|
25911 | _this4.masterPlaylistController_.sourceUpdater_.initializedEme();
|
25912 | }).catch(function (err) {
|
25913 | _this4.logger_('error while creating EME key session', err);
|
25914 |
|
25915 | _this4.player_.error({
|
25916 | message: 'Failed to initialize media keys for EME',
|
25917 | code: 3
|
25918 | });
|
25919 | });
|
25920 | }
|
25921 | |
25922 |
|
25923 |
|
25924 |
|
25925 |
|
25926 |
|
25927 | ;
|
25928 |
|
25929 | _proto.setupQualityLevels_ = function setupQualityLevels_() {
|
25930 | var _this5 = this;
|
25931 |
|
25932 | var player = videojs__default["default"].players[this.tech_.options_.playerId];
|
25933 |
|
25934 |
|
25935 | if (!player || !player.qualityLevels || this.qualityLevels_) {
|
25936 | return;
|
25937 | }
|
25938 |
|
25939 | this.qualityLevels_ = player.qualityLevels();
|
25940 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
25941 | handleVhsLoadedMetadata(_this5.qualityLevels_, _this5);
|
25942 | });
|
25943 | this.playlists.on('mediachange', function () {
|
25944 | handleVhsMediaChange(_this5.qualityLevels_, _this5.playlists);
|
25945 | });
|
25946 | }
|
25947 | |
25948 |
|
25949 |
|
25950 | ;
|
25951 |
|
25952 | VhsHandler.version = function version$5() {
|
25953 | return {
|
25954 | '@videojs/http-streaming': version$4,
|
25955 | 'mux.js': version$3,
|
25956 | 'mpd-parser': version$2,
|
25957 | 'm3u8-parser': version$1,
|
25958 | 'aes-decrypter': version
|
25959 | };
|
25960 | }
|
25961 | |
25962 |
|
25963 |
|
25964 | ;
|
25965 |
|
25966 | _proto.version = function version() {
|
25967 | return this.constructor.version();
|
25968 | };
|
25969 |
|
25970 | _proto.canChangeType = function canChangeType() {
|
25971 | return SourceUpdater.canChangeType();
|
25972 | }
|
25973 | |
25974 |
|
25975 |
|
25976 | ;
|
25977 |
|
25978 | _proto.play = function play() {
|
25979 | this.masterPlaylistController_.play();
|
25980 | }
|
25981 | |
25982 |
|
25983 |
|
25984 | ;
|
25985 |
|
25986 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
25987 | this.masterPlaylistController_.setCurrentTime(currentTime);
|
25988 | }
|
25989 | |
25990 |
|
25991 |
|
25992 | ;
|
25993 |
|
25994 | _proto.duration = function duration() {
|
25995 | return this.masterPlaylistController_.duration();
|
25996 | }
|
25997 | |
25998 |
|
25999 |
|
26000 | ;
|
26001 |
|
26002 | _proto.seekable = function seekable() {
|
26003 | return this.masterPlaylistController_.seekable();
|
26004 | }
|
26005 | |
26006 |
|
26007 |
|
26008 | ;
|
26009 |
|
26010 | _proto.dispose = function dispose() {
|
26011 | if (this.playbackWatcher_) {
|
26012 | this.playbackWatcher_.dispose();
|
26013 | }
|
26014 |
|
26015 | if (this.masterPlaylistController_) {
|
26016 | this.masterPlaylistController_.dispose();
|
26017 | }
|
26018 |
|
26019 | if (this.qualityLevels_) {
|
26020 | this.qualityLevels_.dispose();
|
26021 | }
|
26022 |
|
26023 | if (this.player_) {
|
26024 | delete this.player_.vhs;
|
26025 | delete this.player_.dash;
|
26026 | delete this.player_.hls;
|
26027 | }
|
26028 |
|
26029 | if (this.tech_ && this.tech_.vhs) {
|
26030 | delete this.tech_.vhs;
|
26031 | }
|
26032 |
|
26033 |
|
26034 | if (this.tech_) {
|
26035 | delete this.tech_.hls;
|
26036 | }
|
26037 |
|
26038 | if (this.mediaSourceUrl_ && window__default["default"].URL.revokeObjectURL) {
|
26039 | window__default["default"].URL.revokeObjectURL(this.mediaSourceUrl_);
|
26040 | this.mediaSourceUrl_ = null;
|
26041 | }
|
26042 |
|
26043 | _Component.prototype.dispose.call(this);
|
26044 | };
|
26045 |
|
26046 | _proto.convertToProgramTime = function convertToProgramTime(time, callback) {
|
26047 | return getProgramTime({
|
26048 | playlist: this.masterPlaylistController_.media(),
|
26049 | time: time,
|
26050 | callback: callback
|
26051 | });
|
26052 | }
|
26053 | ;
|
26054 |
|
26055 | _proto.seekToProgramTime = function seekToProgramTime$1(programTime, callback, pauseAfterSeek, retryCount) {
|
26056 | if (pauseAfterSeek === void 0) {
|
26057 | pauseAfterSeek = true;
|
26058 | }
|
26059 |
|
26060 | if (retryCount === void 0) {
|
26061 | retryCount = 2;
|
26062 | }
|
26063 |
|
26064 | return seekToProgramTime({
|
26065 | programTime: programTime,
|
26066 | playlist: this.masterPlaylistController_.media(),
|
26067 | retryCount: retryCount,
|
26068 | pauseAfterSeek: pauseAfterSeek,
|
26069 | seekTo: this.options_.seekTo,
|
26070 | tech: this.options_.tech,
|
26071 | callback: callback
|
26072 | });
|
26073 | };
|
26074 |
|
26075 | return VhsHandler;
|
26076 | }(Component);
|
26077 |
|
26078 |
|
26079 |
|
26080 |
|
26081 |
|
26082 |
|
26083 |
|
26084 |
|
26085 |
|
26086 | var VhsSourceHandler = {
|
26087 | name: 'videojs-http-streaming',
|
26088 | VERSION: version$4,
|
26089 | canHandleSource: function canHandleSource(srcObj, options) {
|
26090 | if (options === void 0) {
|
26091 | options = {};
|
26092 | }
|
26093 |
|
26094 | var localOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options);
|
26095 | return VhsSourceHandler.canPlayType(srcObj.type, localOptions);
|
26096 | },
|
26097 | handleSource: function handleSource(source, tech, options) {
|
26098 | if (options === void 0) {
|
26099 | options = {};
|
26100 | }
|
26101 |
|
26102 | var localOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options);
|
26103 | tech.vhs = new VhsHandler(source, tech, localOptions);
|
26104 |
|
26105 | if (!videojs__default["default"].hasOwnProperty('hls')) {
|
26106 | Object.defineProperty(tech, 'hls', {
|
26107 | get: function get() {
|
26108 | videojs__default["default"].log.warn('player.tech().hls is deprecated. Use player.tech().vhs instead.');
|
26109 | return tech.vhs;
|
26110 | },
|
26111 | configurable: true
|
26112 | });
|
26113 | }
|
26114 |
|
26115 | tech.vhs.xhr = xhrFactory();
|
26116 | tech.vhs.src(source.src, source.type);
|
26117 | return tech.vhs;
|
26118 | },
|
26119 | canPlayType: function canPlayType(type, options) {
|
26120 | if (options === void 0) {
|
26121 | options = {};
|
26122 | }
|
26123 |
|
26124 | var _videojs$mergeOptions = videojs__default["default"].mergeOptions(videojs__default["default"].options, options),
|
26125 | _videojs$mergeOptions2 = _videojs$mergeOptions.vhs.overrideNative,
|
26126 | overrideNative = _videojs$mergeOptions2 === void 0 ? !videojs__default["default"].browser.IS_ANY_SAFARI : _videojs$mergeOptions2;
|
26127 |
|
26128 | var supportedType = mediaTypes_js.simpleTypeFromSourceType(type);
|
26129 | var canUseMsePlayback = supportedType && (!Vhs.supportsTypeNatively(supportedType) || overrideNative);
|
26130 | return canUseMsePlayback ? 'maybe' : '';
|
26131 | }
|
26132 | };
|
26133 |
|
26134 |
|
26135 |
|
26136 |
|
26137 |
|
26138 |
|
26139 |
|
26140 | var supportsNativeMediaSources = function supportsNativeMediaSources() {
|
26141 | return codecs_js.browserSupportsCodec('avc1.4d400d,mp4a.40.2');
|
26142 | };
|
26143 |
|
26144 |
|
26145 | if (supportsNativeMediaSources()) {
|
26146 | videojs__default["default"].getTech('Html5').registerSourceHandler(VhsSourceHandler, 0);
|
26147 | }
|
26148 |
|
26149 | videojs__default["default"].VhsHandler = VhsHandler;
|
26150 | Object.defineProperty(videojs__default["default"], 'HlsHandler', {
|
26151 | get: function get() {
|
26152 | videojs__default["default"].log.warn('videojs.HlsHandler is deprecated. Use videojs.VhsHandler instead.');
|
26153 | return VhsHandler;
|
26154 | },
|
26155 | configurable: true
|
26156 | });
|
26157 | videojs__default["default"].VhsSourceHandler = VhsSourceHandler;
|
26158 | Object.defineProperty(videojs__default["default"], 'HlsSourceHandler', {
|
26159 | get: function get() {
|
26160 | videojs__default["default"].log.warn('videojs.HlsSourceHandler is deprecated. ' + 'Use videojs.VhsSourceHandler instead.');
|
26161 | return VhsSourceHandler;
|
26162 | },
|
26163 | configurable: true
|
26164 | });
|
26165 | videojs__default["default"].Vhs = Vhs;
|
26166 | Object.defineProperty(videojs__default["default"], 'Hls', {
|
26167 | get: function get() {
|
26168 | videojs__default["default"].log.warn('videojs.Hls is deprecated. Use videojs.Vhs instead.');
|
26169 | return Vhs;
|
26170 | },
|
26171 | configurable: true
|
26172 | });
|
26173 |
|
26174 | if (!videojs__default["default"].use) {
|
26175 | videojs__default["default"].registerComponent('Hls', Vhs);
|
26176 | videojs__default["default"].registerComponent('Vhs', Vhs);
|
26177 | }
|
26178 |
|
26179 | videojs__default["default"].options.vhs = videojs__default["default"].options.vhs || {};
|
26180 | videojs__default["default"].options.hls = videojs__default["default"].options.hls || {};
|
26181 |
|
26182 | if (!videojs__default["default"].getPlugin || !videojs__default["default"].getPlugin('reloadSourceOnError')) {
|
26183 | var registerPlugin = videojs__default["default"].registerPlugin || videojs__default["default"].plugin;
|
26184 | registerPlugin('reloadSourceOnError', reloadSourceOnError);
|
26185 | }
|
26186 |
|
26187 | Object.defineProperty(exports, 'simpleTypeFromSourceType', {
|
26188 | enumerable: true,
|
26189 | get: function () { return mediaTypes_js.simpleTypeFromSourceType; }
|
26190 | });
|
26191 | exports.LOCAL_STORAGE_KEY = LOCAL_STORAGE_KEY;
|
26192 | exports.Vhs = Vhs;
|
26193 | exports.VhsHandler = VhsHandler;
|
26194 | exports.VhsSourceHandler = VhsSourceHandler;
|
26195 | exports.emeKeySystems = emeKeySystems;
|
26196 | exports.expandDataUri = expandDataUri;
|
26197 | exports.getAllPsshKeySystemsOptions = getAllPsshKeySystemsOptions;
|
26198 | exports.setupEmeOptions = setupEmeOptions;
|
26199 | exports.waitForKeySessionCreation = waitForKeySessionCreation;
|