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 m3u8Parser = require('m3u8-parser');
|
13 | var codecs_js = require('@videojs/vhs-utils/cjs/codecs.js');
|
14 | var mediaTypes_js = require('@videojs/vhs-utils/cjs/media-types.js');
|
15 | var mpdParser = require('mpd-parser');
|
16 | var parseSidx = require('mux.js/lib/tools/parse-sidx');
|
17 | var id3Helpers = require('@videojs/vhs-utils/cjs/id3-helpers');
|
18 | var containers = require('@videojs/vhs-utils/cjs/containers');
|
19 | var byteHelpers = require('@videojs/vhs-utils/cjs/byte-helpers');
|
20 | var tsInspector = require('mux.js/lib/tools/ts-inspector.js');
|
21 | var clock = require('mux.js/lib/utils/clock');
|
22 | var mp4probe = require('mux.js/lib/mp4/probe');
|
23 |
|
24 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
25 |
|
26 | var _assertThisInitialized__default = _interopDefaultLegacy(_assertThisInitialized);
|
27 | var _inheritsLoose__default = _interopDefaultLegacy(_inheritsLoose);
|
28 | var document__default = _interopDefaultLegacy(document);
|
29 | var window__default = _interopDefaultLegacy(window);
|
30 | var _resolveUrl__default = _interopDefaultLegacy(_resolveUrl);
|
31 | var videojs__default = _interopDefaultLegacy(videojs);
|
32 | var parseSidx__default = _interopDefaultLegacy(parseSidx);
|
33 | var tsInspector__default = _interopDefaultLegacy(tsInspector);
|
34 | var mp4probe__default = _interopDefaultLegacy(mp4probe);
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var resolveUrl = _resolveUrl__default['default'];
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | var resolveManifestRedirect = function resolveManifestRedirect(handleManifestRedirect, url, req) {
|
53 |
|
54 |
|
55 |
|
56 | if (handleManifestRedirect && req && req.responseURL && url !== req.responseURL) {
|
57 | return req.responseURL;
|
58 | }
|
59 |
|
60 | return url;
|
61 | };
|
62 |
|
63 | var logger = function logger(source) {
|
64 | if (videojs__default['default'].log.debug) {
|
65 | return videojs__default['default'].log.debug.bind(videojs__default['default'], 'VHS:', source + " >");
|
66 | }
|
67 |
|
68 | return function () {};
|
69 | };
|
70 |
|
71 | var log = videojs__default['default'].log;
|
72 | var createPlaylistID = function createPlaylistID(index, uri) {
|
73 | return index + "-" + uri;
|
74 | };
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | var parseManifest = function parseManifest(_ref) {
|
95 | var onwarn = _ref.onwarn,
|
96 | oninfo = _ref.oninfo,
|
97 | manifestString = _ref.manifestString,
|
98 | _ref$customTagParsers = _ref.customTagParsers,
|
99 | customTagParsers = _ref$customTagParsers === void 0 ? [] : _ref$customTagParsers,
|
100 | _ref$customTagMappers = _ref.customTagMappers,
|
101 | customTagMappers = _ref$customTagMappers === void 0 ? [] : _ref$customTagMappers,
|
102 | experimentalLLHLS = _ref.experimentalLLHLS;
|
103 | var parser = new m3u8Parser.Parser();
|
104 |
|
105 | if (onwarn) {
|
106 | parser.on('warn', onwarn);
|
107 | }
|
108 |
|
109 | if (oninfo) {
|
110 | parser.on('info', oninfo);
|
111 | }
|
112 |
|
113 | customTagParsers.forEach(function (customParser) {
|
114 | return parser.addParser(customParser);
|
115 | });
|
116 | customTagMappers.forEach(function (mapper) {
|
117 | return parser.addTagMapper(mapper);
|
118 | });
|
119 | parser.push(manifestString);
|
120 | parser.end();
|
121 | var manifest = parser.manifest;
|
122 |
|
123 |
|
124 | if (!experimentalLLHLS) {
|
125 | ['preloadSegment', 'skip', 'serverControl', 'renditionReports', 'partInf', 'partTargetDuration'].forEach(function (k) {
|
126 | if (manifest.hasOwnProperty(k)) {
|
127 | delete manifest[k];
|
128 | }
|
129 | });
|
130 |
|
131 | if (manifest.segments) {
|
132 | manifest.segments.forEach(function (segment) {
|
133 | ['parts', 'preloadHints'].forEach(function (k) {
|
134 | if (segment.hasOwnProperty(k)) {
|
135 | delete segment[k];
|
136 | }
|
137 | });
|
138 | });
|
139 | }
|
140 | }
|
141 |
|
142 | if (!manifest.targetDuration) {
|
143 | var targetDuration = 10;
|
144 |
|
145 | if (manifest.segments && manifest.segments.length) {
|
146 | targetDuration = manifest.segments.reduce(function (acc, s) {
|
147 | return Math.max(acc, s.duration);
|
148 | }, 0);
|
149 | }
|
150 |
|
151 | if (onwarn) {
|
152 | onwarn("manifest has no targetDuration defaulting to " + targetDuration);
|
153 | }
|
154 |
|
155 | manifest.targetDuration = targetDuration;
|
156 | }
|
157 |
|
158 | return manifest;
|
159 | };
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | var forEachMediaGroup = function forEachMediaGroup(master, callback) {
|
171 | ['AUDIO', 'SUBTITLES'].forEach(function (mediaType) {
|
172 | for (var groupKey in master.mediaGroups[mediaType]) {
|
173 | for (var labelKey in master.mediaGroups[mediaType][groupKey]) {
|
174 | var mediaProperties = master.mediaGroups[mediaType][groupKey][labelKey];
|
175 | callback(mediaProperties, mediaType, groupKey, labelKey);
|
176 | }
|
177 | }
|
178 | });
|
179 | };
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | var setupMediaPlaylist = function setupMediaPlaylist(_ref2) {
|
196 | var playlist = _ref2.playlist,
|
197 | uri = _ref2.uri,
|
198 | id = _ref2.id;
|
199 | playlist.id = id;
|
200 |
|
201 | if (uri) {
|
202 |
|
203 |
|
204 |
|
205 | playlist.uri = uri;
|
206 | }
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | playlist.attributes = playlist.attributes || {};
|
216 | };
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | var setupMediaPlaylists = function setupMediaPlaylists(master) {
|
227 | var i = master.playlists.length;
|
228 |
|
229 | while (i--) {
|
230 | var playlist = master.playlists[i];
|
231 | setupMediaPlaylist({
|
232 | playlist: playlist,
|
233 | id: createPlaylistID(i, playlist.uri)
|
234 | });
|
235 | playlist.resolvedUri = resolveUrl(master.uri, playlist.uri);
|
236 | master.playlists[playlist.id] = playlist;
|
237 |
|
238 | master.playlists[playlist.uri] = playlist;
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | if (!playlist.attributes.BANDWIDTH) {
|
244 | log.warn('Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute.');
|
245 | }
|
246 | }
|
247 | };
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | var resolveMediaGroupUris = function resolveMediaGroupUris(master) {
|
256 | forEachMediaGroup(master, function (properties) {
|
257 | if (properties.uri) {
|
258 | properties.resolvedUri = resolveUrl(master.uri, properties.uri);
|
259 | }
|
260 | });
|
261 | };
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | var masterForMedia = function masterForMedia(media, uri) {
|
275 | var id = createPlaylistID(0, uri);
|
276 | var master = {
|
277 | mediaGroups: {
|
278 | 'AUDIO': {},
|
279 | 'VIDEO': {},
|
280 | 'CLOSED-CAPTIONS': {},
|
281 | 'SUBTITLES': {}
|
282 | },
|
283 | uri: window__default['default'].location.href,
|
284 | resolvedUri: window__default['default'].location.href,
|
285 | playlists: [{
|
286 | uri: uri,
|
287 | id: id,
|
288 | resolvedUri: uri,
|
289 |
|
290 |
|
291 | attributes: {}
|
292 | }]
|
293 | };
|
294 |
|
295 | master.playlists[id] = master.playlists[0];
|
296 |
|
297 | master.playlists[uri] = master.playlists[0];
|
298 | return master;
|
299 | };
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 | var addPropertiesToMaster = function addPropertiesToMaster(master, uri) {
|
311 | master.uri = uri;
|
312 |
|
313 | for (var i = 0; i < master.playlists.length; i++) {
|
314 | if (!master.playlists[i].uri) {
|
315 |
|
316 |
|
317 |
|
318 | var phonyUri = "placeholder-uri-" + i;
|
319 | master.playlists[i].uri = phonyUri;
|
320 | }
|
321 | }
|
322 |
|
323 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
324 | if (!properties.playlists || !properties.playlists.length || properties.playlists[0].uri) {
|
325 | return;
|
326 | }
|
327 |
|
328 |
|
329 |
|
330 | var phonyUri = "placeholder-uri-" + mediaType + "-" + groupKey + "-" + labelKey;
|
331 | var id = createPlaylistID(0, phonyUri);
|
332 | properties.playlists[0].uri = phonyUri;
|
333 | properties.playlists[0].id = id;
|
334 |
|
335 | master.playlists[id] = properties.playlists[0];
|
336 | master.playlists[phonyUri] = properties.playlists[0];
|
337 | });
|
338 | setupMediaPlaylists(master);
|
339 | resolveMediaGroupUris(master);
|
340 | };
|
341 |
|
342 | var mergeOptions$2 = videojs__default['default'].mergeOptions,
|
343 | EventTarget$1 = videojs__default['default'].EventTarget;
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | var updateSegment = function updateSegment(a, b) {
|
355 | if (!a) {
|
356 | return b;
|
357 | }
|
358 |
|
359 | var result = mergeOptions$2(a, b);
|
360 |
|
361 |
|
362 | if (a.parts && !b.parts) {
|
363 | delete result.parts;
|
364 |
|
365 |
|
366 | } else if (a.parts && b.parts) {
|
367 | for (var i = 0; i < b.parts.length; i++) {
|
368 | if (a.parts && a.parts[i]) {
|
369 | result.parts[i] = mergeOptions$2(a.parts[i], b.parts[i]);
|
370 | }
|
371 | }
|
372 | }
|
373 |
|
374 | return result;
|
375 | };
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | var updateSegments = function updateSegments(original, update, offset) {
|
393 | var oldSegments = original.slice();
|
394 | var result = update.slice();
|
395 | offset = offset || 0;
|
396 | var length = Math.min(original.length, update.length + offset);
|
397 |
|
398 | for (var i = offset; i < length; i++) {
|
399 | var newIndex = i - offset;
|
400 | result[newIndex] = updateSegment(oldSegments[i], result[newIndex]);
|
401 | }
|
402 |
|
403 | return result;
|
404 | };
|
405 | var resolveSegmentUris = function resolveSegmentUris(segment, baseUri) {
|
406 |
|
407 |
|
408 | if (!segment.resolvedUri && segment.uri) {
|
409 | segment.resolvedUri = resolveUrl(baseUri, segment.uri);
|
410 | }
|
411 |
|
412 | if (segment.key && !segment.key.resolvedUri) {
|
413 | segment.key.resolvedUri = resolveUrl(baseUri, segment.key.uri);
|
414 | }
|
415 |
|
416 | if (segment.map && !segment.map.resolvedUri) {
|
417 | segment.map.resolvedUri = resolveUrl(baseUri, segment.map.uri);
|
418 | }
|
419 |
|
420 | if (segment.parts && segment.parts.length) {
|
421 | segment.parts.forEach(function (p) {
|
422 | if (p.resolvedUri) {
|
423 | return;
|
424 | }
|
425 |
|
426 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
427 | });
|
428 | }
|
429 |
|
430 | if (segment.preloadHints && segment.preloadHints.length) {
|
431 | segment.preloadHints.forEach(function (p) {
|
432 | if (p.resolvedUri) {
|
433 | return;
|
434 | }
|
435 |
|
436 | p.resolvedUri = resolveUrl(baseUri, p.uri);
|
437 | });
|
438 | }
|
439 | };
|
440 |
|
441 | var getAllSegments = function getAllSegments(media) {
|
442 | var segments = media.segments || [];
|
443 |
|
444 |
|
445 |
|
446 | if (media.preloadSegment && media.preloadSegment.parts) {
|
447 | segments.push(media.preloadSegment);
|
448 | }
|
449 |
|
450 | return segments;
|
451 | };
|
452 |
|
453 |
|
454 |
|
455 |
|
456 | var isPlaylistUnchanged = function isPlaylistUnchanged(a, b) {
|
457 | return a === b || a.segments && b.segments && a.segments.length === b.segments.length && a.endList === b.endList && a.mediaSequence === b.mediaSequence;
|
458 | };
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 | var updateMaster$1 = function updateMaster(master, media, unchangedCheck) {
|
473 | if (unchangedCheck === void 0) {
|
474 | unchangedCheck = isPlaylistUnchanged;
|
475 | }
|
476 |
|
477 | var result = mergeOptions$2(master, {});
|
478 | var playlist = result.playlists[media.id];
|
479 |
|
480 | if (!playlist) {
|
481 | return null;
|
482 | }
|
483 |
|
484 | if (unchangedCheck(playlist, media)) {
|
485 | return null;
|
486 | }
|
487 |
|
488 | var mergedPlaylist = mergeOptions$2(playlist, media);
|
489 | media.segments = getAllSegments(media);
|
490 |
|
491 | if (playlist.segments) {
|
492 | mergedPlaylist.segments = updateSegments(playlist.segments, media.segments, media.mediaSequence - playlist.mediaSequence);
|
493 | }
|
494 |
|
495 |
|
496 | mergedPlaylist.segments.forEach(function (segment) {
|
497 | resolveSegmentUris(segment, mergedPlaylist.resolvedUri);
|
498 | });
|
499 |
|
500 |
|
501 |
|
502 | for (var i = 0; i < result.playlists.length; i++) {
|
503 | if (result.playlists[i].id === media.id) {
|
504 | result.playlists[i] = mergedPlaylist;
|
505 | }
|
506 | }
|
507 |
|
508 | result.playlists[media.id] = mergedPlaylist;
|
509 |
|
510 | result.playlists[media.uri] = mergedPlaylist;
|
511 | return result;
|
512 | };
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 | var refreshDelay = function refreshDelay(media, update) {
|
525 | var lastSegment = media.segments[media.segments.length - 1];
|
526 | var lastPart = lastSegment && lastSegment.parts && lastSegment.parts[lastSegment.parts.length - 1];
|
527 | var lastDuration = lastPart && lastPart.duration || lastSegment && lastSegment.duration;
|
528 |
|
529 | if (update && lastDuration) {
|
530 | return lastDuration * 1000;
|
531 | }
|
532 |
|
533 |
|
534 |
|
535 | return (media.partTargetDuration || media.targetDuration || 10) * 500;
|
536 | };
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 | var PlaylistLoader = function (_EventTarget) {
|
548 | _inheritsLoose__default['default'](PlaylistLoader, _EventTarget);
|
549 |
|
550 | function PlaylistLoader(src, vhs, options) {
|
551 | var _this;
|
552 |
|
553 | if (options === void 0) {
|
554 | options = {};
|
555 | }
|
556 |
|
557 | _this = _EventTarget.call(this) || this;
|
558 |
|
559 | if (!src) {
|
560 | throw new Error('A non-empty playlist URL or object is required');
|
561 | }
|
562 |
|
563 | _this.logger_ = logger('PlaylistLoader');
|
564 | var _options = options,
|
565 | _options$withCredenti = _options.withCredentials,
|
566 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
567 | _options$handleManife = _options.handleManifestRedirects,
|
568 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
569 | _this.src = src;
|
570 | _this.vhs_ = vhs;
|
571 | _this.withCredentials = withCredentials;
|
572 | _this.handleManifestRedirects = handleManifestRedirects;
|
573 | var vhsOptions = vhs.options_;
|
574 | _this.customTagParsers = vhsOptions && vhsOptions.customTagParsers || [];
|
575 | _this.customTagMappers = vhsOptions && vhsOptions.customTagMappers || [];
|
576 | _this.experimentalLLHLS = vhsOptions && vhsOptions.experimentalLLHLS || false;
|
577 |
|
578 | _this.state = 'HAVE_NOTHING';
|
579 |
|
580 | _this.on('mediaupdatetimeout', function () {
|
581 | if (_this.state !== 'HAVE_METADATA') {
|
582 |
|
583 | return;
|
584 | }
|
585 |
|
586 | _this.state = 'HAVE_CURRENT_METADATA';
|
587 | _this.request = _this.vhs_.xhr({
|
588 | uri: resolveUrl(_this.master.uri, _this.media().uri),
|
589 | withCredentials: _this.withCredentials
|
590 | }, function (error, req) {
|
591 |
|
592 | if (!_this.request) {
|
593 | return;
|
594 | }
|
595 |
|
596 | if (error) {
|
597 | return _this.playlistRequestError(_this.request, _this.media(), 'HAVE_METADATA');
|
598 | }
|
599 |
|
600 | _this.haveMetadata({
|
601 | playlistString: _this.request.responseText,
|
602 | url: _this.media().uri,
|
603 | id: _this.media().id
|
604 | });
|
605 | });
|
606 | });
|
607 |
|
608 | return _this;
|
609 | }
|
610 |
|
611 | var _proto = PlaylistLoader.prototype;
|
612 |
|
613 | _proto.playlistRequestError = function playlistRequestError(xhr, playlist, startingState) {
|
614 | var uri = playlist.uri,
|
615 | id = playlist.id;
|
616 |
|
617 | this.request = null;
|
618 |
|
619 | if (startingState) {
|
620 | this.state = startingState;
|
621 | }
|
622 |
|
623 | this.error = {
|
624 | playlist: this.master.playlists[id],
|
625 | status: xhr.status,
|
626 | message: "HLS playlist request error at URL: " + uri + ".",
|
627 | responseText: xhr.responseText,
|
628 | code: xhr.status >= 500 ? 4 : 2
|
629 | };
|
630 | this.trigger('error');
|
631 | }
|
632 | |
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 | ;
|
645 |
|
646 | _proto.haveMetadata = function haveMetadata(_ref) {
|
647 | var _this2 = this;
|
648 |
|
649 | var playlistString = _ref.playlistString,
|
650 | playlistObject = _ref.playlistObject,
|
651 | url = _ref.url,
|
652 | id = _ref.id;
|
653 |
|
654 | this.request = null;
|
655 | this.state = 'HAVE_METADATA';
|
656 | var playlist = playlistObject || parseManifest({
|
657 | onwarn: function onwarn(_ref2) {
|
658 | var message = _ref2.message;
|
659 | return _this2.logger_("m3u8-parser warn for " + id + ": " + message);
|
660 | },
|
661 | oninfo: function oninfo(_ref3) {
|
662 | var message = _ref3.message;
|
663 | return _this2.logger_("m3u8-parser info for " + id + ": " + message);
|
664 | },
|
665 | manifestString: playlistString,
|
666 | customTagParsers: this.customTagParsers,
|
667 | customTagMappers: this.customTagMappers,
|
668 | experimentalLLHLS: this.experimentalLLHLS
|
669 | });
|
670 | playlist.lastRequest = Date.now();
|
671 | setupMediaPlaylist({
|
672 | playlist: playlist,
|
673 | uri: url,
|
674 | id: id
|
675 | });
|
676 |
|
677 | var update = updateMaster$1(this.master, playlist);
|
678 | this.targetDuration = playlist.partTargetDuration || playlist.targetDuration;
|
679 |
|
680 | if (update) {
|
681 | this.master = update;
|
682 | this.media_ = this.master.playlists[id];
|
683 | } else {
|
684 | this.trigger('playlistunchanged');
|
685 | }
|
686 |
|
687 |
|
688 | if (!this.media().endList) {
|
689 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
690 | this.mediaUpdateTimeout = window__default['default'].setTimeout(function () {
|
691 | _this2.trigger('mediaupdatetimeout');
|
692 | }, refreshDelay(this.media(), !!update));
|
693 | }
|
694 |
|
695 | this.trigger('loadedplaylist');
|
696 | }
|
697 | |
698 |
|
699 |
|
700 | ;
|
701 |
|
702 | _proto.dispose = function dispose() {
|
703 | this.trigger('dispose');
|
704 | this.stopRequest();
|
705 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
706 | window__default['default'].clearTimeout(this.finalRenditionTimeout);
|
707 | this.off();
|
708 | };
|
709 |
|
710 | _proto.stopRequest = function stopRequest() {
|
711 | if (this.request) {
|
712 | var oldRequest = this.request;
|
713 | this.request = null;
|
714 | oldRequest.onreadystatechange = null;
|
715 | oldRequest.abort();
|
716 | }
|
717 | }
|
718 | |
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 | ;
|
733 |
|
734 | _proto.media = function media(playlist, shouldDelay) {
|
735 | var _this3 = this;
|
736 |
|
737 |
|
738 | if (!playlist) {
|
739 | return this.media_;
|
740 | }
|
741 |
|
742 |
|
743 | if (this.state === 'HAVE_NOTHING') {
|
744 | throw new Error('Cannot switch media playlist from ' + this.state);
|
745 | }
|
746 |
|
747 |
|
748 |
|
749 | if (typeof playlist === 'string') {
|
750 | if (!this.master.playlists[playlist]) {
|
751 | throw new Error('Unknown playlist URI: ' + playlist);
|
752 | }
|
753 |
|
754 | playlist = this.master.playlists[playlist];
|
755 | }
|
756 |
|
757 | window__default['default'].clearTimeout(this.finalRenditionTimeout);
|
758 |
|
759 | if (shouldDelay) {
|
760 | var delay = (playlist.partTargetDuration || playlist.targetDuration) / 2 * 1000 || 5 * 1000;
|
761 | this.finalRenditionTimeout = window__default['default'].setTimeout(this.media.bind(this, playlist, false), delay);
|
762 | return;
|
763 | }
|
764 |
|
765 | var startingState = this.state;
|
766 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
767 |
|
768 | if (this.master.playlists[playlist.id].endList ||
|
769 |
|
770 | playlist.endList && playlist.segments.length) {
|
771 |
|
772 | if (this.request) {
|
773 | this.request.onreadystatechange = null;
|
774 | this.request.abort();
|
775 | this.request = null;
|
776 | }
|
777 |
|
778 | this.state = 'HAVE_METADATA';
|
779 | this.media_ = playlist;
|
780 |
|
781 | if (mediaChange) {
|
782 | this.trigger('mediachanging');
|
783 |
|
784 | if (startingState === 'HAVE_MASTER') {
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 | this.trigger('loadedmetadata');
|
791 | } else {
|
792 | this.trigger('mediachange');
|
793 | }
|
794 | }
|
795 |
|
796 | return;
|
797 | }
|
798 |
|
799 |
|
800 | if (!mediaChange) {
|
801 | return;
|
802 | }
|
803 |
|
804 | this.state = 'SWITCHING_MEDIA';
|
805 |
|
806 | if (this.request) {
|
807 | if (playlist.resolvedUri === this.request.url) {
|
808 |
|
809 |
|
810 | return;
|
811 | }
|
812 |
|
813 | this.request.onreadystatechange = null;
|
814 | this.request.abort();
|
815 | this.request = null;
|
816 | }
|
817 |
|
818 |
|
819 | if (this.media_) {
|
820 | this.trigger('mediachanging');
|
821 | }
|
822 |
|
823 | this.request = this.vhs_.xhr({
|
824 | uri: playlist.resolvedUri,
|
825 | withCredentials: this.withCredentials
|
826 | }, function (error, req) {
|
827 |
|
828 | if (!_this3.request) {
|
829 | return;
|
830 | }
|
831 |
|
832 | playlist.lastRequest = Date.now();
|
833 | playlist.resolvedUri = resolveManifestRedirect(_this3.handleManifestRedirects, playlist.resolvedUri, req);
|
834 |
|
835 | if (error) {
|
836 | return _this3.playlistRequestError(_this3.request, playlist, startingState);
|
837 | }
|
838 |
|
839 | _this3.haveMetadata({
|
840 | playlistString: req.responseText,
|
841 | url: playlist.uri,
|
842 | id: playlist.id
|
843 | });
|
844 |
|
845 |
|
846 | if (startingState === 'HAVE_MASTER') {
|
847 | _this3.trigger('loadedmetadata');
|
848 | } else {
|
849 | _this3.trigger('mediachange');
|
850 | }
|
851 | });
|
852 | }
|
853 | |
854 |
|
855 |
|
856 | ;
|
857 |
|
858 | _proto.pause = function pause() {
|
859 | this.stopRequest();
|
860 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
861 |
|
862 | if (this.state === 'HAVE_NOTHING') {
|
863 |
|
864 |
|
865 | this.started = false;
|
866 | }
|
867 |
|
868 |
|
869 | if (this.state === 'SWITCHING_MEDIA') {
|
870 |
|
871 |
|
872 |
|
873 | if (this.media_) {
|
874 | this.state = 'HAVE_METADATA';
|
875 | } else {
|
876 | this.state = 'HAVE_MASTER';
|
877 | }
|
878 | } else if (this.state === 'HAVE_CURRENT_METADATA') {
|
879 | this.state = 'HAVE_METADATA';
|
880 | }
|
881 | }
|
882 | |
883 |
|
884 |
|
885 | ;
|
886 |
|
887 | _proto.load = function load(shouldDelay) {
|
888 | var _this4 = this;
|
889 |
|
890 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
891 | var media = this.media();
|
892 |
|
893 | if (shouldDelay) {
|
894 | var delay = media ? (media.partTargetDuration || media.targetDuration) / 2 * 1000 : 5 * 1000;
|
895 | this.mediaUpdateTimeout = window__default['default'].setTimeout(function () {
|
896 | return _this4.load();
|
897 | }, delay);
|
898 | return;
|
899 | }
|
900 |
|
901 | if (!this.started) {
|
902 | this.start();
|
903 | return;
|
904 | }
|
905 |
|
906 | if (media && !media.endList) {
|
907 | this.trigger('mediaupdatetimeout');
|
908 | } else {
|
909 | this.trigger('loadedplaylist');
|
910 | }
|
911 | }
|
912 | |
913 |
|
914 |
|
915 | ;
|
916 |
|
917 | _proto.start = function start() {
|
918 | var _this5 = this;
|
919 |
|
920 | this.started = true;
|
921 |
|
922 | if (typeof this.src === 'object') {
|
923 |
|
924 |
|
925 | if (!this.src.uri) {
|
926 | this.src.uri = window__default['default'].location.href;
|
927 | }
|
928 |
|
929 |
|
930 |
|
931 | this.src.resolvedUri = this.src.uri;
|
932 |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 | setTimeout(function () {
|
942 | _this5.setupInitialPlaylist(_this5.src);
|
943 | }, 0);
|
944 | return;
|
945 | }
|
946 |
|
947 |
|
948 | this.request = this.vhs_.xhr({
|
949 | uri: this.src,
|
950 | withCredentials: this.withCredentials
|
951 | }, function (error, req) {
|
952 |
|
953 | if (!_this5.request) {
|
954 | return;
|
955 | }
|
956 |
|
957 |
|
958 | _this5.request = null;
|
959 |
|
960 | if (error) {
|
961 | _this5.error = {
|
962 | status: req.status,
|
963 | message: "HLS playlist request error at URL: " + _this5.src + ".",
|
964 | responseText: req.responseText,
|
965 |
|
966 | code: 2
|
967 | };
|
968 |
|
969 | if (_this5.state === 'HAVE_NOTHING') {
|
970 | _this5.started = false;
|
971 | }
|
972 |
|
973 | return _this5.trigger('error');
|
974 | }
|
975 |
|
976 | _this5.src = resolveManifestRedirect(_this5.handleManifestRedirects, _this5.src, req);
|
977 | var manifest = parseManifest({
|
978 | manifestString: req.responseText,
|
979 | customTagParsers: _this5.customTagParsers,
|
980 | customTagMappers: _this5.customTagMappers,
|
981 | llhls: _this5.llhls
|
982 | });
|
983 |
|
984 | _this5.setupInitialPlaylist(manifest);
|
985 | });
|
986 | };
|
987 |
|
988 | _proto.srcUri = function srcUri() {
|
989 | return typeof this.src === 'string' ? this.src : this.src.uri;
|
990 | }
|
991 | |
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 | ;
|
1010 |
|
1011 | _proto.setupInitialPlaylist = function setupInitialPlaylist(manifest) {
|
1012 | this.state = 'HAVE_MASTER';
|
1013 |
|
1014 | if (manifest.playlists) {
|
1015 | this.master = manifest;
|
1016 | addPropertiesToMaster(this.master, this.srcUri());
|
1017 |
|
1018 |
|
1019 |
|
1020 | manifest.playlists.forEach(function (playlist) {
|
1021 | playlist.segments = getAllSegments(playlist);
|
1022 | playlist.segments.forEach(function (segment) {
|
1023 | resolveSegmentUris(segment, playlist.resolvedUri);
|
1024 | });
|
1025 | });
|
1026 | this.trigger('loadedplaylist');
|
1027 |
|
1028 | if (!this.request) {
|
1029 |
|
1030 |
|
1031 | this.media(this.master.playlists[0]);
|
1032 | }
|
1033 |
|
1034 | return;
|
1035 | }
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 | var uri = this.srcUri() || window__default['default'].location.href;
|
1041 | this.master = masterForMedia(manifest, uri);
|
1042 | this.haveMetadata({
|
1043 | playlistObject: manifest,
|
1044 | url: uri,
|
1045 | id: this.master.playlists[0].id
|
1046 | });
|
1047 | this.trigger('loadedmetadata');
|
1048 | };
|
1049 |
|
1050 | return PlaylistLoader;
|
1051 | }(EventTarget$1);
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 | var TIME_FUDGE_FACTOR = 1 / 30;
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 | var SAFE_TIME_DELTA = TIME_FUDGE_FACTOR * 3;
|
1067 |
|
1068 | var filterRanges = function filterRanges(timeRanges, predicate) {
|
1069 | var results = [];
|
1070 | var i;
|
1071 |
|
1072 | if (timeRanges && timeRanges.length) {
|
1073 |
|
1074 | for (i = 0; i < timeRanges.length; i++) {
|
1075 | if (predicate(timeRanges.start(i), timeRanges.end(i))) {
|
1076 | results.push([timeRanges.start(i), timeRanges.end(i)]);
|
1077 | }
|
1078 | }
|
1079 | }
|
1080 |
|
1081 | return videojs__default['default'].createTimeRanges(results);
|
1082 | };
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 | var findRange = function findRange(buffered, time) {
|
1094 | return filterRanges(buffered, function (start, end) {
|
1095 | return start - SAFE_TIME_DELTA <= time && end + SAFE_TIME_DELTA >= time;
|
1096 | });
|
1097 | };
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 | var findNextRange = function findNextRange(timeRanges, time) {
|
1107 | return filterRanges(timeRanges, function (start) {
|
1108 | return start - TIME_FUDGE_FACTOR >= time;
|
1109 | });
|
1110 | };
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 | var findGaps = function findGaps(buffered) {
|
1119 | if (buffered.length < 2) {
|
1120 | return videojs__default['default'].createTimeRanges();
|
1121 | }
|
1122 |
|
1123 | var ranges = [];
|
1124 |
|
1125 | for (var i = 1; i < buffered.length; i++) {
|
1126 | var start = buffered.end(i - 1);
|
1127 | var end = buffered.start(i);
|
1128 | ranges.push([start, end]);
|
1129 | }
|
1130 |
|
1131 | return videojs__default['default'].createTimeRanges(ranges);
|
1132 | };
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 | var bufferIntersection = function bufferIntersection(bufferA, bufferB) {
|
1142 | var start = null;
|
1143 | var end = null;
|
1144 | var arity = 0;
|
1145 | var extents = [];
|
1146 | var ranges = [];
|
1147 |
|
1148 | if (!bufferA || !bufferA.length || !bufferB || !bufferB.length) {
|
1149 | return videojs__default['default'].createTimeRange();
|
1150 | }
|
1151 |
|
1152 |
|
1153 |
|
1154 | var count = bufferA.length;
|
1155 |
|
1156 | while (count--) {
|
1157 | extents.push({
|
1158 | time: bufferA.start(count),
|
1159 | type: 'start'
|
1160 | });
|
1161 | extents.push({
|
1162 | time: bufferA.end(count),
|
1163 | type: 'end'
|
1164 | });
|
1165 | }
|
1166 |
|
1167 | count = bufferB.length;
|
1168 |
|
1169 | while (count--) {
|
1170 | extents.push({
|
1171 | time: bufferB.start(count),
|
1172 | type: 'start'
|
1173 | });
|
1174 | extents.push({
|
1175 | time: bufferB.end(count),
|
1176 | type: 'end'
|
1177 | });
|
1178 | }
|
1179 |
|
1180 |
|
1181 | extents.sort(function (a, b) {
|
1182 | return a.time - b.time;
|
1183 | });
|
1184 |
|
1185 |
|
1186 | for (count = 0; count < extents.length; count++) {
|
1187 | if (extents[count].type === 'start') {
|
1188 | arity++;
|
1189 |
|
1190 |
|
1191 | if (arity === 2) {
|
1192 | start = extents[count].time;
|
1193 | }
|
1194 | } else if (extents[count].type === 'end') {
|
1195 | arity--;
|
1196 |
|
1197 |
|
1198 | if (arity === 1) {
|
1199 | end = extents[count].time;
|
1200 | }
|
1201 | }
|
1202 |
|
1203 |
|
1204 | if (start !== null && end !== null) {
|
1205 | ranges.push([start, end]);
|
1206 | start = null;
|
1207 | end = null;
|
1208 | }
|
1209 | }
|
1210 |
|
1211 | return videojs__default['default'].createTimeRanges(ranges);
|
1212 | };
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 | var printableRange = function printableRange(range) {
|
1221 | var strArr = [];
|
1222 |
|
1223 | if (!range || !range.length) {
|
1224 | return '';
|
1225 | }
|
1226 |
|
1227 | for (var i = 0; i < range.length; i++) {
|
1228 | strArr.push(range.start(i) + ' => ' + range.end(i));
|
1229 | }
|
1230 |
|
1231 | return strArr.join(', ');
|
1232 | };
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 | var timeUntilRebuffer = function timeUntilRebuffer(buffered, currentTime, playbackRate) {
|
1249 | if (playbackRate === void 0) {
|
1250 | playbackRate = 1;
|
1251 | }
|
1252 |
|
1253 | var bufferedEnd = buffered.length ? buffered.end(buffered.length - 1) : 0;
|
1254 | return (bufferedEnd - currentTime) / playbackRate;
|
1255 | };
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 | var timeRangesToArray = function timeRangesToArray(timeRanges) {
|
1264 | var timeRangesList = [];
|
1265 |
|
1266 | for (var i = 0; i < timeRanges.length; i++) {
|
1267 | timeRangesList.push({
|
1268 | start: timeRanges.start(i),
|
1269 | end: timeRanges.end(i)
|
1270 | });
|
1271 | }
|
1272 |
|
1273 | return timeRangesList;
|
1274 | };
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 | var isRangeDifferent = function isRangeDifferent(a, b) {
|
1289 |
|
1290 | if (a === b) {
|
1291 | return false;
|
1292 | }
|
1293 |
|
1294 |
|
1295 | if (!a && b || !b && a) {
|
1296 | return true;
|
1297 | }
|
1298 |
|
1299 |
|
1300 | if (a.length !== b.length) {
|
1301 | return true;
|
1302 | }
|
1303 |
|
1304 |
|
1305 | for (var i = 0; i < a.length; i++) {
|
1306 | if (a.start(i) !== b.start(i) || a.end(i) !== b.end(i)) {
|
1307 | return true;
|
1308 | }
|
1309 | }
|
1310 |
|
1311 |
|
1312 |
|
1313 | return false;
|
1314 | };
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 | var createTimeRange = videojs__default['default'].createTimeRange;
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 | var getPartsAndSegments = function getPartsAndSegments(playlist) {
|
1332 | return (playlist.segments || []).reduce(function (acc, segment, si) {
|
1333 | if (segment.parts) {
|
1334 | segment.parts.forEach(function (part, pi) {
|
1335 | acc.push({
|
1336 | duration: part.duration,
|
1337 | segmentIndex: si,
|
1338 | partIndex: pi
|
1339 | });
|
1340 | });
|
1341 | } else {
|
1342 | acc.push({
|
1343 | duration: segment.duration,
|
1344 | segmentIndex: si,
|
1345 | partIndex: null
|
1346 | });
|
1347 | }
|
1348 |
|
1349 | return acc;
|
1350 | }, []);
|
1351 | };
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 | var liveEdgeDelay = function liveEdgeDelay(master, media) {
|
1363 | if (media.endList) {
|
1364 | return 0;
|
1365 | }
|
1366 |
|
1367 |
|
1368 | if (master && master.suggestedPresentationDelay) {
|
1369 | return master.suggestedPresentationDelay;
|
1370 | }
|
1371 |
|
1372 | var lastSegment = media.segments && media.segments.length && media.segments[media.segments.length - 1];
|
1373 | var hasParts = lastSegment && lastSegment.parts && lastSegment.parts.length;
|
1374 |
|
1375 | if (hasParts && media.serverControl && media.serverControl.partHoldBack) {
|
1376 | return media.serverControl.partHoldBack;
|
1377 | } else if (hasParts && media.partTargetDuration) {
|
1378 | return media.partTargetDuration * 3;
|
1379 | } else if (media.serverControl && media.serverControl.holdBack) {
|
1380 | return media.serverControl.holdBack;
|
1381 | } else if (media.targetDuration) {
|
1382 | return media.targetDuration * 3;
|
1383 | }
|
1384 |
|
1385 | return 0;
|
1386 | };
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 | var backwardDuration = function backwardDuration(playlist, endSequence) {
|
1396 | var result = 0;
|
1397 | var i = endSequence - playlist.mediaSequence;
|
1398 |
|
1399 |
|
1400 | var segment = playlist.segments[i];
|
1401 |
|
1402 |
|
1403 | if (segment) {
|
1404 | if (typeof segment.start !== 'undefined') {
|
1405 | return {
|
1406 | result: segment.start,
|
1407 | precise: true
|
1408 | };
|
1409 | }
|
1410 |
|
1411 | if (typeof segment.end !== 'undefined') {
|
1412 | return {
|
1413 | result: segment.end - segment.duration,
|
1414 | precise: true
|
1415 | };
|
1416 | }
|
1417 | }
|
1418 |
|
1419 | while (i--) {
|
1420 | segment = playlist.segments[i];
|
1421 |
|
1422 | if (typeof segment.end !== 'undefined') {
|
1423 | return {
|
1424 | result: result + segment.end,
|
1425 | precise: true
|
1426 | };
|
1427 | }
|
1428 |
|
1429 | result += segment.duration;
|
1430 |
|
1431 | if (typeof segment.start !== 'undefined') {
|
1432 | return {
|
1433 | result: result + segment.start,
|
1434 | precise: true
|
1435 | };
|
1436 | }
|
1437 | }
|
1438 |
|
1439 | return {
|
1440 | result: result,
|
1441 | precise: false
|
1442 | };
|
1443 | };
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 | var forwardDuration = function forwardDuration(playlist, endSequence) {
|
1454 | var result = 0;
|
1455 | var segment;
|
1456 | var i = endSequence - playlist.mediaSequence;
|
1457 |
|
1458 |
|
1459 | for (; i < playlist.segments.length; i++) {
|
1460 | segment = playlist.segments[i];
|
1461 |
|
1462 | if (typeof segment.start !== 'undefined') {
|
1463 | return {
|
1464 | result: segment.start - result,
|
1465 | precise: true
|
1466 | };
|
1467 | }
|
1468 |
|
1469 | result += segment.duration;
|
1470 |
|
1471 | if (typeof segment.end !== 'undefined') {
|
1472 | return {
|
1473 | result: segment.end - result,
|
1474 | precise: true
|
1475 | };
|
1476 | }
|
1477 | }
|
1478 |
|
1479 |
|
1480 | return {
|
1481 | result: -1,
|
1482 | precise: false
|
1483 | };
|
1484 | };
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 | var intervalDuration = function intervalDuration(playlist, endSequence, expired) {
|
1501 | if (typeof endSequence === 'undefined') {
|
1502 | endSequence = playlist.mediaSequence + playlist.segments.length;
|
1503 | }
|
1504 |
|
1505 | if (endSequence < playlist.mediaSequence) {
|
1506 | return 0;
|
1507 | }
|
1508 |
|
1509 |
|
1510 | var backward = backwardDuration(playlist, endSequence);
|
1511 |
|
1512 | if (backward.precise) {
|
1513 |
|
1514 |
|
1515 |
|
1516 | return backward.result;
|
1517 | }
|
1518 |
|
1519 |
|
1520 |
|
1521 | var forward = forwardDuration(playlist, endSequence);
|
1522 |
|
1523 | if (forward.precise) {
|
1524 |
|
1525 |
|
1526 | return forward.result;
|
1527 | }
|
1528 |
|
1529 |
|
1530 | return backward.result + expired;
|
1531 | };
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 | var duration = function duration(playlist, endSequence, expired) {
|
1550 | if (!playlist) {
|
1551 | return 0;
|
1552 | }
|
1553 |
|
1554 | if (typeof expired !== 'number') {
|
1555 | expired = 0;
|
1556 | }
|
1557 |
|
1558 |
|
1559 |
|
1560 | if (typeof endSequence === 'undefined') {
|
1561 |
|
1562 | if (playlist.totalDuration) {
|
1563 | return playlist.totalDuration;
|
1564 | }
|
1565 |
|
1566 |
|
1567 | if (!playlist.endList) {
|
1568 | return window__default['default'].Infinity;
|
1569 | }
|
1570 | }
|
1571 |
|
1572 |
|
1573 | return intervalDuration(playlist, endSequence, expired);
|
1574 | };
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 | var sumDurations = function sumDurations(playlist, startIndex, endIndex) {
|
1588 | var durations = 0;
|
1589 |
|
1590 | if (startIndex > endIndex) {
|
1591 | var _ref = [endIndex, startIndex];
|
1592 | startIndex = _ref[0];
|
1593 | endIndex = _ref[1];
|
1594 | }
|
1595 |
|
1596 | if (startIndex < 0) {
|
1597 | for (var i = startIndex; i < Math.min(0, endIndex); i++) {
|
1598 | durations += playlist.targetDuration;
|
1599 | }
|
1600 |
|
1601 | startIndex = 0;
|
1602 | }
|
1603 |
|
1604 | for (var _i = startIndex; _i < endIndex; _i++) {
|
1605 | durations += playlist.segments[_i].duration;
|
1606 | }
|
1607 |
|
1608 | return durations;
|
1609 | };
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 | var playlistEnd = function playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding) {
|
1631 | if (!playlist || !playlist.segments) {
|
1632 | return null;
|
1633 | }
|
1634 |
|
1635 | if (playlist.endList) {
|
1636 | return duration(playlist);
|
1637 | }
|
1638 |
|
1639 | if (expired === null) {
|
1640 | return null;
|
1641 | }
|
1642 |
|
1643 | expired = expired || 0;
|
1644 | var lastSegmentTime = intervalDuration(playlist, playlist.mediaSequence + playlist.segments.length, expired);
|
1645 |
|
1646 | if (useSafeLiveEnd) {
|
1647 | liveEdgePadding = typeof liveEdgePadding === 'number' ? liveEdgePadding : liveEdgeDelay(null, playlist);
|
1648 | lastSegmentTime -= liveEdgePadding;
|
1649 | }
|
1650 |
|
1651 |
|
1652 | return Math.max(0, lastSegmentTime);
|
1653 | };
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 | var seekable = function seekable(playlist, expired, liveEdgePadding) {
|
1673 | var useSafeLiveEnd = true;
|
1674 | var seekableStart = expired || 0;
|
1675 | var seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding);
|
1676 |
|
1677 | if (seekableEnd === null) {
|
1678 | return createTimeRange();
|
1679 | }
|
1680 |
|
1681 | return createTimeRange(seekableStart, seekableEnd);
|
1682 | };
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 | var getMediaInfoForTime = function getMediaInfoForTime(playlist, currentTime, startIndex, startTime) {
|
1696 | var partsAndSegments = getPartsAndSegments(playlist);
|
1697 | var time = currentTime - startTime;
|
1698 |
|
1699 | if (time < 0) {
|
1700 |
|
1701 |
|
1702 | if (startIndex > 0) {
|
1703 | for (var i = startIndex - 1; i >= 0; i--) {
|
1704 | var segment = partsAndSegments[i];
|
1705 | time += segment.duration + TIME_FUDGE_FACTOR;
|
1706 |
|
1707 | if (time > 0) {
|
1708 | return {
|
1709 | mediaIndex: segment.segmentIndex,
|
1710 | startTime: startTime - sumDurations(playlist, startIndex, segment.segmentIndex),
|
1711 | partIndex: segment.partIndex
|
1712 | };
|
1713 | }
|
1714 | }
|
1715 | }
|
1716 |
|
1717 |
|
1718 |
|
1719 | return {
|
1720 | mediaIndex: partsAndSegments[0] && partsAndSegments[0].segmentIndex || 0,
|
1721 | partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
|
1722 | startTime: currentTime
|
1723 | };
|
1724 | }
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 | if (startIndex < 0) {
|
1730 | for (var _i2 = startIndex; _i2 < 0; _i2++) {
|
1731 | time -= playlist.targetDuration;
|
1732 |
|
1733 | if (time < 0) {
|
1734 | return {
|
1735 | mediaIndex: partsAndSegments[0].segmentIndex,
|
1736 | startTime: currentTime
|
1737 | };
|
1738 | }
|
1739 | }
|
1740 |
|
1741 | startIndex = 0;
|
1742 | }
|
1743 |
|
1744 |
|
1745 |
|
1746 | for (var _i3 = startIndex; _i3 < partsAndSegments.length; _i3++) {
|
1747 | var partSegment = partsAndSegments[_i3];
|
1748 | time -= partSegment.duration + TIME_FUDGE_FACTOR;
|
1749 |
|
1750 | if (time < 0) {
|
1751 | return {
|
1752 | mediaIndex: partSegment.segmentIndex,
|
1753 | startTime: startTime + sumDurations(playlist, startIndex, partSegment.segmentIndex),
|
1754 | partIndex: partSegment.partIndex
|
1755 | };
|
1756 | }
|
1757 | }
|
1758 |
|
1759 |
|
1760 | return {
|
1761 | mediaIndex: partsAndSegments[partsAndSegments.length - 1].segmentIndex,
|
1762 | partIndex: partsAndSegments[partsAndSegments.length - 1].partIndex,
|
1763 | startTime: currentTime
|
1764 | };
|
1765 | };
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 | var isBlacklisted = function isBlacklisted(playlist) {
|
1775 | return playlist.excludeUntil && playlist.excludeUntil > Date.now();
|
1776 | };
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 | var isIncompatible = function isIncompatible(playlist) {
|
1787 | return playlist.excludeUntil && playlist.excludeUntil === Infinity;
|
1788 | };
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 | var isEnabled = function isEnabled(playlist) {
|
1798 | var blacklisted = isBlacklisted(playlist);
|
1799 | return !playlist.disabled && !blacklisted;
|
1800 | };
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 | var isDisabled = function isDisabled(playlist) {
|
1810 | return playlist.disabled;
|
1811 | };
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 | var isAes = function isAes(media) {
|
1819 | for (var i = 0; i < media.segments.length; i++) {
|
1820 | if (media.segments[i].key) {
|
1821 | return true;
|
1822 | }
|
1823 | }
|
1824 |
|
1825 | return false;
|
1826 | };
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 | var hasAttribute = function hasAttribute(attr, playlist) {
|
1840 | return playlist.attributes && playlist.attributes[attr];
|
1841 | };
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 | var estimateSegmentRequestTime = function estimateSegmentRequestTime(segmentDuration, bandwidth, playlist, bytesReceived) {
|
1860 | if (bytesReceived === void 0) {
|
1861 | bytesReceived = 0;
|
1862 | }
|
1863 |
|
1864 | if (!hasAttribute('BANDWIDTH', playlist)) {
|
1865 | return NaN;
|
1866 | }
|
1867 |
|
1868 | var size = segmentDuration * playlist.attributes.BANDWIDTH;
|
1869 | return (size - bytesReceived * 8) / bandwidth;
|
1870 | };
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 | var isLowestEnabledRendition = function isLowestEnabledRendition(master, media) {
|
1878 | if (master.playlists.length === 1) {
|
1879 | return true;
|
1880 | }
|
1881 |
|
1882 | var currentBandwidth = media.attributes.BANDWIDTH || Number.MAX_VALUE;
|
1883 | return master.playlists.filter(function (playlist) {
|
1884 | if (!isEnabled(playlist)) {
|
1885 | return false;
|
1886 | }
|
1887 |
|
1888 | return (playlist.attributes.BANDWIDTH || 0) < currentBandwidth;
|
1889 | }).length === 0;
|
1890 | };
|
1891 | var playlistMatch = function playlistMatch(a, b) {
|
1892 |
|
1893 |
|
1894 |
|
1895 | if (!a && !b || !a && b || a && !b) {
|
1896 | return false;
|
1897 | }
|
1898 |
|
1899 |
|
1900 | if (a === b) {
|
1901 | return true;
|
1902 | }
|
1903 |
|
1904 |
|
1905 |
|
1906 | if (a.id && b.id && a.id === b.id) {
|
1907 | return true;
|
1908 | }
|
1909 |
|
1910 |
|
1911 |
|
1912 | if (a.resolvedUri && b.resolvedUri && a.resolvedUri === b.resolvedUri) {
|
1913 | return true;
|
1914 | }
|
1915 |
|
1916 |
|
1917 |
|
1918 | if (a.uri && b.uri && a.uri === b.uri) {
|
1919 | return true;
|
1920 | }
|
1921 |
|
1922 | return false;
|
1923 | };
|
1924 |
|
1925 | var someAudioVariant = function someAudioVariant(master, callback) {
|
1926 | var AUDIO = master && master.mediaGroups && master.mediaGroups.AUDIO || {};
|
1927 | var found = false;
|
1928 |
|
1929 | for (var groupName in AUDIO) {
|
1930 | for (var label in AUDIO[groupName]) {
|
1931 | found = callback(AUDIO[groupName][label]);
|
1932 |
|
1933 | if (found) {
|
1934 | break;
|
1935 | }
|
1936 | }
|
1937 |
|
1938 | if (found) {
|
1939 | break;
|
1940 | }
|
1941 | }
|
1942 |
|
1943 | return !!found;
|
1944 | };
|
1945 |
|
1946 | var isAudioOnly = function isAudioOnly(master) {
|
1947 |
|
1948 |
|
1949 | if (!master || !master.playlists || !master.playlists.length) {
|
1950 |
|
1951 |
|
1952 | var found = someAudioVariant(master, function (variant) {
|
1953 | return variant.playlists && variant.playlists.length || variant.uri;
|
1954 | });
|
1955 | return found;
|
1956 | }
|
1957 |
|
1958 |
|
1959 | var _loop = function _loop(i) {
|
1960 | var playlist = master.playlists[i];
|
1961 | var CODECS = playlist.attributes && playlist.attributes.CODECS;
|
1962 |
|
1963 | if (CODECS && CODECS.split(',').every(function (c) {
|
1964 | return codecs_js.isAudioCodec(c);
|
1965 | })) {
|
1966 | return "continue";
|
1967 | }
|
1968 |
|
1969 |
|
1970 | var found = someAudioVariant(master, function (variant) {
|
1971 | return playlistMatch(playlist, variant);
|
1972 | });
|
1973 |
|
1974 | if (found) {
|
1975 | return "continue";
|
1976 | }
|
1977 |
|
1978 |
|
1979 |
|
1980 | return {
|
1981 | v: false
|
1982 | };
|
1983 | };
|
1984 |
|
1985 | for (var i = 0; i < master.playlists.length; i++) {
|
1986 | var _ret = _loop(i);
|
1987 |
|
1988 | if (_ret === "continue") continue;
|
1989 | if (typeof _ret === "object") return _ret.v;
|
1990 | }
|
1991 |
|
1992 |
|
1993 |
|
1994 | return true;
|
1995 | };
|
1996 |
|
1997 | var Playlist = {
|
1998 | liveEdgeDelay: liveEdgeDelay,
|
1999 | duration: duration,
|
2000 | seekable: seekable,
|
2001 | getMediaInfoForTime: getMediaInfoForTime,
|
2002 | isEnabled: isEnabled,
|
2003 | isDisabled: isDisabled,
|
2004 | isBlacklisted: isBlacklisted,
|
2005 | isIncompatible: isIncompatible,
|
2006 | playlistEnd: playlistEnd,
|
2007 | isAes: isAes,
|
2008 | hasAttribute: hasAttribute,
|
2009 | estimateSegmentRequestTime: estimateSegmentRequestTime,
|
2010 | isLowestEnabledRendition: isLowestEnabledRendition,
|
2011 | isAudioOnly: isAudioOnly,
|
2012 | playlistMatch: playlistMatch
|
2013 | };
|
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 | var videojsXHR = videojs__default['default'].xhr,
|
2019 | mergeOptions$1 = videojs__default['default'].mergeOptions;
|
2020 |
|
2021 | var callbackWrapper = function callbackWrapper(request, error, response, callback) {
|
2022 | var reqResponse = request.responseType === 'arraybuffer' ? request.response : request.responseText;
|
2023 |
|
2024 | if (!error && reqResponse) {
|
2025 | request.responseTime = Date.now();
|
2026 | request.roundTripTime = request.responseTime - request.requestTime;
|
2027 | request.bytesReceived = reqResponse.byteLength || reqResponse.length;
|
2028 |
|
2029 | if (!request.bandwidth) {
|
2030 | request.bandwidth = Math.floor(request.bytesReceived / request.roundTripTime * 8 * 1000);
|
2031 | }
|
2032 | }
|
2033 |
|
2034 | if (response.headers) {
|
2035 | request.responseHeaders = response.headers;
|
2036 | }
|
2037 |
|
2038 |
|
2039 |
|
2040 |
|
2041 | if (error && error.code === 'ETIMEDOUT') {
|
2042 | request.timedout = true;
|
2043 | }
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 | if (!error && !request.aborted && response.statusCode !== 200 && response.statusCode !== 206 && response.statusCode !== 0) {
|
2049 | error = new Error('XHR Failed with a response of: ' + (request && (reqResponse || request.responseText)));
|
2050 | }
|
2051 |
|
2052 | callback(error, request);
|
2053 | };
|
2054 |
|
2055 | var xhrFactory = function xhrFactory() {
|
2056 | var xhr = function XhrFunction(options, callback) {
|
2057 |
|
2058 | options = mergeOptions$1({
|
2059 | timeout: 45e3
|
2060 | }, options);
|
2061 |
|
2062 |
|
2063 | var beforeRequest = XhrFunction.beforeRequest || videojs__default['default'].Vhs.xhr.beforeRequest;
|
2064 |
|
2065 | if (beforeRequest && typeof beforeRequest === 'function') {
|
2066 | var newOptions = beforeRequest(options);
|
2067 |
|
2068 | if (newOptions) {
|
2069 | options = newOptions;
|
2070 | }
|
2071 | }
|
2072 |
|
2073 |
|
2074 |
|
2075 | var xhrMethod = videojs__default['default'].Vhs.xhr.original === true ? videojsXHR : videojs__default['default'].Vhs.xhr;
|
2076 | var request = xhrMethod(options, function (error, response) {
|
2077 | return callbackWrapper(request, error, response, callback);
|
2078 | });
|
2079 | var originalAbort = request.abort;
|
2080 |
|
2081 | request.abort = function () {
|
2082 | request.aborted = true;
|
2083 | return originalAbort.apply(request, arguments);
|
2084 | };
|
2085 |
|
2086 | request.uri = options.uri;
|
2087 | request.requestTime = Date.now();
|
2088 | return request;
|
2089 | };
|
2090 |
|
2091 | xhr.original = true;
|
2092 | return xhr;
|
2093 | };
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 | var byterangeStr = function byterangeStr(byterange) {
|
2104 |
|
2105 |
|
2106 | var byterangeEnd = byterange.offset + byterange.length - 1;
|
2107 | var byterangeStart = byterange.offset;
|
2108 | return 'bytes=' + byterangeStart + '-' + byterangeEnd;
|
2109 | };
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 | var segmentXhrHeaders = function segmentXhrHeaders(segment) {
|
2119 | var headers = {};
|
2120 |
|
2121 | if (segment.byterange) {
|
2122 | headers.Range = byterangeStr(segment.byterange);
|
2123 | }
|
2124 |
|
2125 | return headers;
|
2126 | };
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 | var textRange = function textRange(range, i) {
|
2140 | return range.start(i) + '-' + range.end(i);
|
2141 | };
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 | var formatHexString = function formatHexString(e, i) {
|
2152 | var value = e.toString(16);
|
2153 | return '00'.substring(0, 2 - value.length) + value + (i % 2 ? ' ' : '');
|
2154 | };
|
2155 |
|
2156 | var formatAsciiString = function formatAsciiString(e) {
|
2157 | if (e >= 0x20 && e < 0x7e) {
|
2158 | return String.fromCharCode(e);
|
2159 | }
|
2160 |
|
2161 | return '.';
|
2162 | };
|
2163 |
|
2164 |
|
2165 |
|
2166 |
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 | var createTransferableMessage = function createTransferableMessage(message) {
|
2176 | var transferable = {};
|
2177 | Object.keys(message).forEach(function (key) {
|
2178 | var value = message[key];
|
2179 |
|
2180 | if (ArrayBuffer.isView(value)) {
|
2181 | transferable[key] = {
|
2182 | bytes: value.buffer,
|
2183 | byteOffset: value.byteOffset,
|
2184 | byteLength: value.byteLength
|
2185 | };
|
2186 | } else {
|
2187 | transferable[key] = value;
|
2188 | }
|
2189 | });
|
2190 | return transferable;
|
2191 | };
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 | var initSegmentId = function initSegmentId(initSegment) {
|
2203 | var byterange = initSegment.byterange || {
|
2204 | length: Infinity,
|
2205 | offset: 0
|
2206 | };
|
2207 | return [byterange.length, byterange.offset, initSegment.resolvedUri].join(',');
|
2208 | };
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 | var segmentKeyId = function segmentKeyId(key) {
|
2217 | return key.resolvedUri;
|
2218 | };
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 | var hexDump = function hexDump(data) {
|
2229 | var bytes = Array.prototype.slice.call(data);
|
2230 | var step = 16;
|
2231 | var result = '';
|
2232 | var hex;
|
2233 | var ascii;
|
2234 |
|
2235 | for (var j = 0; j < bytes.length / step; j++) {
|
2236 | hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
|
2237 | ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
|
2238 | result += hex + ' ' + ascii + '\n';
|
2239 | }
|
2240 |
|
2241 | return result;
|
2242 | };
|
2243 | var tagDump = function tagDump(_ref) {
|
2244 | var bytes = _ref.bytes;
|
2245 | return hexDump(bytes);
|
2246 | };
|
2247 | var textRanges = function textRanges(ranges) {
|
2248 | var result = '';
|
2249 | var i;
|
2250 |
|
2251 | for (i = 0; i < ranges.length; i++) {
|
2252 | result += textRange(ranges, i) + ' ';
|
2253 | }
|
2254 |
|
2255 | return result;
|
2256 | };
|
2257 |
|
2258 | var utils = Object.freeze({
|
2259 | __proto__: null,
|
2260 | createTransferableMessage: createTransferableMessage,
|
2261 | initSegmentId: initSegmentId,
|
2262 | segmentKeyId: segmentKeyId,
|
2263 | hexDump: hexDump,
|
2264 | tagDump: tagDump,
|
2265 | textRanges: textRanges
|
2266 | });
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 | var SEGMENT_END_FUDGE_PERCENT = 0.25;
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 | var playerTimeToProgramTime = function playerTimeToProgramTime(playerTime, segment) {
|
2289 | if (!segment.dateTimeObject) {
|
2290 |
|
2291 |
|
2292 | return null;
|
2293 | }
|
2294 |
|
2295 | var transmuxerPrependedSeconds = segment.videoTimingInfo.transmuxerPrependedSeconds;
|
2296 | var transmuxedStart = segment.videoTimingInfo.transmuxedPresentationStart;
|
2297 |
|
2298 | var startOfSegment = transmuxedStart + transmuxerPrependedSeconds;
|
2299 | var offsetFromSegmentStart = playerTime - startOfSegment;
|
2300 | return new Date(segment.dateTimeObject.getTime() + offsetFromSegmentStart * 1000);
|
2301 | };
|
2302 | var originalSegmentVideoDuration = function originalSegmentVideoDuration(videoTimingInfo) {
|
2303 | return videoTimingInfo.transmuxedPresentationEnd - videoTimingInfo.transmuxedPresentationStart - videoTimingInfo.transmuxerPrependedSeconds;
|
2304 | };
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 | var findSegmentForProgramTime = function findSegmentForProgramTime(programTime, playlist) {
|
2314 |
|
2315 |
|
2316 |
|
2317 | var dateTimeObject;
|
2318 |
|
2319 | try {
|
2320 | dateTimeObject = new Date(programTime);
|
2321 | } catch (e) {
|
2322 | return null;
|
2323 | }
|
2324 |
|
2325 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
2326 | return null;
|
2327 | }
|
2328 |
|
2329 | var segment = playlist.segments[0];
|
2330 |
|
2331 | if (dateTimeObject < segment.dateTimeObject) {
|
2332 |
|
2333 | return null;
|
2334 | }
|
2335 |
|
2336 | for (var i = 0; i < playlist.segments.length - 1; i++) {
|
2337 | segment = playlist.segments[i];
|
2338 | var nextSegmentStart = playlist.segments[i + 1].dateTimeObject;
|
2339 |
|
2340 | if (dateTimeObject < nextSegmentStart) {
|
2341 | break;
|
2342 | }
|
2343 | }
|
2344 |
|
2345 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
2346 | var lastSegmentStart = lastSegment.dateTimeObject;
|
2347 | var lastSegmentDuration = lastSegment.videoTimingInfo ? originalSegmentVideoDuration(lastSegment.videoTimingInfo) : lastSegment.duration + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT;
|
2348 | var lastSegmentEnd = new Date(lastSegmentStart.getTime() + lastSegmentDuration * 1000);
|
2349 |
|
2350 | if (dateTimeObject > lastSegmentEnd) {
|
2351 |
|
2352 | return null;
|
2353 | }
|
2354 |
|
2355 | if (dateTimeObject > lastSegmentStart) {
|
2356 | segment = lastSegment;
|
2357 | }
|
2358 |
|
2359 | return {
|
2360 | segment: segment,
|
2361 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : Playlist.duration(playlist, playlist.mediaSequence + playlist.segments.indexOf(segment)),
|
2362 |
|
2363 |
|
2364 |
|
2365 |
|
2366 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
2367 | };
|
2368 | };
|
2369 |
|
2370 |
|
2371 |
|
2372 |
|
2373 |
|
2374 |
|
2375 |
|
2376 | var findSegmentForPlayerTime = function findSegmentForPlayerTime(time, playlist) {
|
2377 |
|
2378 |
|
2379 |
|
2380 |
|
2381 | if (!playlist || !playlist.segments || playlist.segments.length === 0) {
|
2382 | return null;
|
2383 | }
|
2384 |
|
2385 | var segmentEnd = 0;
|
2386 | var segment;
|
2387 |
|
2388 | for (var i = 0; i < playlist.segments.length; i++) {
|
2389 | segment = playlist.segments[i];
|
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 | segmentEnd = segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationEnd : segmentEnd + segment.duration;
|
2397 |
|
2398 | if (time <= segmentEnd) {
|
2399 | break;
|
2400 | }
|
2401 | }
|
2402 |
|
2403 | var lastSegment = playlist.segments[playlist.segments.length - 1];
|
2404 |
|
2405 | if (lastSegment.videoTimingInfo && lastSegment.videoTimingInfo.transmuxedPresentationEnd < time) {
|
2406 |
|
2407 | return null;
|
2408 | }
|
2409 |
|
2410 | if (time > segmentEnd) {
|
2411 |
|
2412 |
|
2413 |
|
2414 | if (time > segmentEnd + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT) {
|
2415 |
|
2416 |
|
2417 |
|
2418 | return null;
|
2419 | }
|
2420 |
|
2421 | segment = lastSegment;
|
2422 | }
|
2423 |
|
2424 | return {
|
2425 | segment: segment,
|
2426 | estimatedStart: segment.videoTimingInfo ? segment.videoTimingInfo.transmuxedPresentationStart : segmentEnd - segment.duration,
|
2427 |
|
2428 |
|
2429 | type: segment.videoTimingInfo ? 'accurate' : 'estimate'
|
2430 | };
|
2431 | };
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 | var getOffsetFromTimestamp = function getOffsetFromTimestamp(comparisonTimeStamp, programTime) {
|
2444 | var segmentDateTime;
|
2445 | var programDateTime;
|
2446 |
|
2447 | try {
|
2448 | segmentDateTime = new Date(comparisonTimeStamp);
|
2449 | programDateTime = new Date(programTime);
|
2450 | } catch (e) {
|
2451 | }
|
2452 |
|
2453 | var segmentTimeEpoch = segmentDateTime.getTime();
|
2454 | var programTimeEpoch = programDateTime.getTime();
|
2455 | return (programTimeEpoch - segmentTimeEpoch) / 1000;
|
2456 | };
|
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 |
|
2463 | var verifyProgramDateTimeTags = function verifyProgramDateTimeTags(playlist) {
|
2464 | if (!playlist.segments || playlist.segments.length === 0) {
|
2465 | return false;
|
2466 | }
|
2467 |
|
2468 | for (var i = 0; i < playlist.segments.length; i++) {
|
2469 | var segment = playlist.segments[i];
|
2470 |
|
2471 | if (!segment.dateTimeObject) {
|
2472 | return false;
|
2473 | }
|
2474 | }
|
2475 |
|
2476 | return true;
|
2477 | };
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 | var getProgramTime = function getProgramTime(_ref) {
|
2495 | var playlist = _ref.playlist,
|
2496 | _ref$time = _ref.time,
|
2497 | time = _ref$time === void 0 ? undefined : _ref$time,
|
2498 | callback = _ref.callback;
|
2499 |
|
2500 | if (!callback) {
|
2501 | throw new Error('getProgramTime: callback must be provided');
|
2502 | }
|
2503 |
|
2504 | if (!playlist || time === undefined) {
|
2505 | return callback({
|
2506 | message: 'getProgramTime: playlist and time must be provided'
|
2507 | });
|
2508 | }
|
2509 |
|
2510 | var matchedSegment = findSegmentForPlayerTime(time, playlist);
|
2511 |
|
2512 | if (!matchedSegment) {
|
2513 | return callback({
|
2514 | message: 'valid programTime was not found'
|
2515 | });
|
2516 | }
|
2517 |
|
2518 | if (matchedSegment.type === 'estimate') {
|
2519 | return callback({
|
2520 | message: 'Accurate programTime could not be determined.' + ' Please seek to e.seekTime and try again',
|
2521 | seekTime: matchedSegment.estimatedStart
|
2522 | });
|
2523 | }
|
2524 |
|
2525 | var programTimeObject = {
|
2526 | mediaSeconds: time
|
2527 | };
|
2528 | var programTime = playerTimeToProgramTime(time, matchedSegment.segment);
|
2529 |
|
2530 | if (programTime) {
|
2531 | programTimeObject.programDateTime = programTime.toISOString();
|
2532 | }
|
2533 |
|
2534 | return callback(null, programTimeObject);
|
2535 | };
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 | var seekToProgramTime = function seekToProgramTime(_ref2) {
|
2552 | var programTime = _ref2.programTime,
|
2553 | playlist = _ref2.playlist,
|
2554 | _ref2$retryCount = _ref2.retryCount,
|
2555 | retryCount = _ref2$retryCount === void 0 ? 2 : _ref2$retryCount,
|
2556 | seekTo = _ref2.seekTo,
|
2557 | _ref2$pauseAfterSeek = _ref2.pauseAfterSeek,
|
2558 | pauseAfterSeek = _ref2$pauseAfterSeek === void 0 ? true : _ref2$pauseAfterSeek,
|
2559 | tech = _ref2.tech,
|
2560 | callback = _ref2.callback;
|
2561 |
|
2562 | if (!callback) {
|
2563 | throw new Error('seekToProgramTime: callback must be provided');
|
2564 | }
|
2565 |
|
2566 | if (typeof programTime === 'undefined' || !playlist || !seekTo) {
|
2567 | return callback({
|
2568 | message: 'seekToProgramTime: programTime, seekTo and playlist must be provided'
|
2569 | });
|
2570 | }
|
2571 |
|
2572 | if (!playlist.endList && !tech.hasStarted_) {
|
2573 | return callback({
|
2574 | message: 'player must be playing a live stream to start buffering'
|
2575 | });
|
2576 | }
|
2577 |
|
2578 | if (!verifyProgramDateTimeTags(playlist)) {
|
2579 | return callback({
|
2580 | message: 'programDateTime tags must be provided in the manifest ' + playlist.resolvedUri
|
2581 | });
|
2582 | }
|
2583 |
|
2584 | var matchedSegment = findSegmentForProgramTime(programTime, playlist);
|
2585 |
|
2586 | if (!matchedSegment) {
|
2587 | return callback({
|
2588 | message: programTime + " was not found in the stream"
|
2589 | });
|
2590 | }
|
2591 |
|
2592 | var segment = matchedSegment.segment;
|
2593 | var mediaOffset = getOffsetFromTimestamp(segment.dateTimeObject, programTime);
|
2594 |
|
2595 | if (matchedSegment.type === 'estimate') {
|
2596 |
|
2597 | if (retryCount === 0) {
|
2598 | return callback({
|
2599 | message: programTime + " is not buffered yet. Try again"
|
2600 | });
|
2601 | }
|
2602 |
|
2603 | seekTo(matchedSegment.estimatedStart + mediaOffset);
|
2604 | tech.one('seeked', function () {
|
2605 | seekToProgramTime({
|
2606 | programTime: programTime,
|
2607 | playlist: playlist,
|
2608 | retryCount: retryCount - 1,
|
2609 | seekTo: seekTo,
|
2610 | pauseAfterSeek: pauseAfterSeek,
|
2611 | tech: tech,
|
2612 | callback: callback
|
2613 | });
|
2614 | });
|
2615 | return;
|
2616 | }
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 | var seekToTime = segment.start + mediaOffset;
|
2622 |
|
2623 | var seekedCallback = function seekedCallback() {
|
2624 | return callback(null, tech.currentTime());
|
2625 | };
|
2626 |
|
2627 |
|
2628 | tech.one('seeked', seekedCallback);
|
2629 |
|
2630 | if (pauseAfterSeek) {
|
2631 | tech.pause();
|
2632 | }
|
2633 |
|
2634 | seekTo(seekToTime);
|
2635 | };
|
2636 |
|
2637 |
|
2638 |
|
2639 | var callbackOnCompleted = function callbackOnCompleted(request, cb) {
|
2640 | if (request.readyState === 4) {
|
2641 | return cb();
|
2642 | }
|
2643 |
|
2644 | return;
|
2645 | };
|
2646 |
|
2647 | var containerRequest = function containerRequest(uri, xhr, cb) {
|
2648 | var bytes = [];
|
2649 | var id3Offset;
|
2650 | var finished = false;
|
2651 |
|
2652 | var endRequestAndCallback = function endRequestAndCallback(err, req, type, _bytes) {
|
2653 | req.abort();
|
2654 | finished = true;
|
2655 | return cb(err, req, type, _bytes);
|
2656 | };
|
2657 |
|
2658 | var progressListener = function progressListener(error, request) {
|
2659 | if (finished) {
|
2660 | return;
|
2661 | }
|
2662 |
|
2663 | if (error) {
|
2664 | return endRequestAndCallback(error, request, '', bytes);
|
2665 | }
|
2666 |
|
2667 |
|
2668 | var newPart = request.responseText.substring(bytes && bytes.byteLength || 0, request.responseText.length);
|
2669 |
|
2670 | bytes = byteHelpers.concatTypedArrays(bytes, byteHelpers.stringToBytes(newPart, true));
|
2671 | id3Offset = id3Offset || id3Helpers.getId3Offset(bytes);
|
2672 |
|
2673 |
|
2674 | if (bytes.length < 10 || id3Offset && bytes.length < id3Offset + 2) {
|
2675 | return callbackOnCompleted(request, function () {
|
2676 | return endRequestAndCallback(error, request, '', bytes);
|
2677 | });
|
2678 | }
|
2679 |
|
2680 | var type = containers.detectContainerForBytes(bytes);
|
2681 |
|
2682 |
|
2683 |
|
2684 | if (type === 'ts' && bytes.length < 188) {
|
2685 | return callbackOnCompleted(request, function () {
|
2686 | return endRequestAndCallback(error, request, '', bytes);
|
2687 | });
|
2688 | }
|
2689 |
|
2690 |
|
2691 |
|
2692 | if (!type && bytes.length < 376) {
|
2693 | return callbackOnCompleted(request, function () {
|
2694 | return endRequestAndCallback(error, request, '', bytes);
|
2695 | });
|
2696 | }
|
2697 |
|
2698 | return endRequestAndCallback(null, request, type, bytes);
|
2699 | };
|
2700 |
|
2701 | var options = {
|
2702 | uri: uri,
|
2703 | beforeSend: function beforeSend(request) {
|
2704 |
|
2705 | request.overrideMimeType('text/plain; charset=x-user-defined');
|
2706 | request.addEventListener('progress', function (_ref) {
|
2707 | _ref.total;
|
2708 | _ref.loaded;
|
2709 | return callbackWrapper(request, null, {
|
2710 | statusCode: request.status
|
2711 | }, progressListener);
|
2712 | });
|
2713 | }
|
2714 | };
|
2715 | var request = xhr(options, function (error, response) {
|
2716 | return callbackWrapper(request, error, response, progressListener);
|
2717 | });
|
2718 | return request;
|
2719 | };
|
2720 |
|
2721 | var EventTarget = videojs__default['default'].EventTarget,
|
2722 | mergeOptions = videojs__default['default'].mergeOptions;
|
2723 |
|
2724 | var dashPlaylistUnchanged = function dashPlaylistUnchanged(a, b) {
|
2725 | if (!isPlaylistUnchanged(a, b)) {
|
2726 | return false;
|
2727 | }
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 | if (a.sidx && b.sidx && (a.sidx.offset !== b.sidx.offset || a.sidx.length !== b.sidx.length)) {
|
2736 | return false;
|
2737 | } else if (!a.sidx && b.sidx || a.sidx && !b.sidx) {
|
2738 | return false;
|
2739 | }
|
2740 |
|
2741 |
|
2742 |
|
2743 | if (a.segments && !b.segments || !a.segments && b.segments) {
|
2744 | return false;
|
2745 | }
|
2746 |
|
2747 |
|
2748 | if (!a.segments && !b.segments) {
|
2749 | return true;
|
2750 | }
|
2751 |
|
2752 |
|
2753 | for (var i = 0; i < a.segments.length; i++) {
|
2754 | var aSegment = a.segments[i];
|
2755 | var bSegment = b.segments[i];
|
2756 |
|
2757 | if (aSegment.uri !== bSegment.uri) {
|
2758 | return false;
|
2759 | }
|
2760 |
|
2761 |
|
2762 | if (!aSegment.byterange && !bSegment.byterange) {
|
2763 | continue;
|
2764 | }
|
2765 |
|
2766 | var aByterange = aSegment.byterange;
|
2767 | var bByterange = bSegment.byterange;
|
2768 |
|
2769 | if (aByterange && !bByterange || !aByterange && bByterange) {
|
2770 | return false;
|
2771 | }
|
2772 |
|
2773 |
|
2774 | if (aByterange.offset !== bByterange.offset || aByterange.length !== bByterange.length) {
|
2775 | return false;
|
2776 | }
|
2777 | }
|
2778 |
|
2779 |
|
2780 | return true;
|
2781 | };
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 | var parseMasterXml = function parseMasterXml(_ref) {
|
2801 | var masterXml = _ref.masterXml,
|
2802 | srcUrl = _ref.srcUrl,
|
2803 | clientOffset = _ref.clientOffset,
|
2804 | sidxMapping = _ref.sidxMapping;
|
2805 | var master = mpdParser.parse(masterXml, {
|
2806 | manifestUri: srcUrl,
|
2807 | clientOffset: clientOffset,
|
2808 | sidxMapping: sidxMapping
|
2809 | });
|
2810 | addPropertiesToMaster(master, srcUrl);
|
2811 | return master;
|
2812 | };
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 | var updateMaster = function updateMaster(oldMaster, newMaster, sidxMapping) {
|
2827 | var noChanges = true;
|
2828 | var update = mergeOptions(oldMaster, {
|
2829 |
|
2830 | duration: newMaster.duration,
|
2831 | minimumUpdatePeriod: newMaster.minimumUpdatePeriod
|
2832 | });
|
2833 |
|
2834 | for (var i = 0; i < newMaster.playlists.length; i++) {
|
2835 | var playlist = newMaster.playlists[i];
|
2836 |
|
2837 | if (playlist.sidx) {
|
2838 | var sidxKey = mpdParser.generateSidxKey(playlist.sidx);
|
2839 |
|
2840 | if (sidxMapping && sidxMapping[sidxKey]) {
|
2841 | mpdParser.addSidxSegmentsToPlaylist(playlist, sidxMapping[sidxKey].sidx, playlist.sidx.resolvedUri);
|
2842 | }
|
2843 | }
|
2844 |
|
2845 | var playlistUpdate = updateMaster$1(update, playlist, dashPlaylistUnchanged);
|
2846 |
|
2847 | if (playlistUpdate) {
|
2848 | update = playlistUpdate;
|
2849 | noChanges = false;
|
2850 | }
|
2851 | }
|
2852 |
|
2853 |
|
2854 | forEachMediaGroup(newMaster, function (properties, type, group, label) {
|
2855 | if (properties.playlists && properties.playlists.length) {
|
2856 | var id = properties.playlists[0].id;
|
2857 |
|
2858 | var _playlistUpdate = updateMaster$1(update, properties.playlists[0], dashPlaylistUnchanged);
|
2859 |
|
2860 | if (_playlistUpdate) {
|
2861 | update = _playlistUpdate;
|
2862 |
|
2863 | update.mediaGroups[type][group][label].playlists[0] = update.playlists[id];
|
2864 | noChanges = false;
|
2865 | }
|
2866 | }
|
2867 | });
|
2868 |
|
2869 | if (newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
2870 | noChanges = false;
|
2871 | }
|
2872 |
|
2873 | if (noChanges) {
|
2874 | return null;
|
2875 | }
|
2876 |
|
2877 | return update;
|
2878 | };
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 | var equivalentSidx = function equivalentSidx(a, b) {
|
2884 | var neitherMap = Boolean(!a.map && !b.map);
|
2885 | var equivalentMap = neitherMap || Boolean(a.map && b.map && a.map.byterange.offset === b.map.byterange.offset && a.map.byterange.length === b.map.byterange.length);
|
2886 | return equivalentMap && a.uri === b.uri && a.byterange.offset === b.byterange.offset && a.byterange.length === b.byterange.length;
|
2887 | };
|
2888 |
|
2889 |
|
2890 | var compareSidxEntry = function compareSidxEntry(playlists, oldSidxMapping) {
|
2891 | var newSidxMapping = {};
|
2892 |
|
2893 | for (var id in playlists) {
|
2894 | var playlist = playlists[id];
|
2895 | var currentSidxInfo = playlist.sidx;
|
2896 |
|
2897 | if (currentSidxInfo) {
|
2898 | var key = mpdParser.generateSidxKey(currentSidxInfo);
|
2899 |
|
2900 | if (!oldSidxMapping[key]) {
|
2901 | break;
|
2902 | }
|
2903 |
|
2904 | var savedSidxInfo = oldSidxMapping[key].sidxInfo;
|
2905 |
|
2906 | if (equivalentSidx(savedSidxInfo, currentSidxInfo)) {
|
2907 | newSidxMapping[key] = oldSidxMapping[key];
|
2908 | }
|
2909 | }
|
2910 | }
|
2911 |
|
2912 | return newSidxMapping;
|
2913 | };
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 | var filterChangedSidxMappings = function filterChangedSidxMappings(master, oldSidxMapping) {
|
2924 | var videoSidx = compareSidxEntry(master.playlists, oldSidxMapping);
|
2925 | var mediaGroupSidx = videoSidx;
|
2926 | forEachMediaGroup(master, function (properties, mediaType, groupKey, labelKey) {
|
2927 | if (properties.playlists && properties.playlists.length) {
|
2928 | var playlists = properties.playlists;
|
2929 | mediaGroupSidx = mergeOptions(mediaGroupSidx, compareSidxEntry(playlists, oldSidxMapping));
|
2930 | }
|
2931 | });
|
2932 | return mediaGroupSidx;
|
2933 | };
|
2934 |
|
2935 | var DashPlaylistLoader = function (_EventTarget) {
|
2936 | _inheritsLoose__default['default'](DashPlaylistLoader, _EventTarget);
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 | function DashPlaylistLoader(srcUrlOrPlaylist, vhs, options, masterPlaylistLoader) {
|
2942 | var _this;
|
2943 |
|
2944 | if (options === void 0) {
|
2945 | options = {};
|
2946 | }
|
2947 |
|
2948 | _this = _EventTarget.call(this) || this;
|
2949 | _this.masterPlaylistLoader_ = masterPlaylistLoader || _assertThisInitialized__default['default'](_this);
|
2950 |
|
2951 | if (!masterPlaylistLoader) {
|
2952 | _this.isMaster_ = true;
|
2953 | }
|
2954 |
|
2955 | var _options = options,
|
2956 | _options$withCredenti = _options.withCredentials,
|
2957 | withCredentials = _options$withCredenti === void 0 ? false : _options$withCredenti,
|
2958 | _options$handleManife = _options.handleManifestRedirects,
|
2959 | handleManifestRedirects = _options$handleManife === void 0 ? false : _options$handleManife;
|
2960 | _this.vhs_ = vhs;
|
2961 | _this.withCredentials = withCredentials;
|
2962 | _this.handleManifestRedirects = handleManifestRedirects;
|
2963 |
|
2964 | if (!srcUrlOrPlaylist) {
|
2965 | throw new Error('A non-empty playlist URL or object is required');
|
2966 | }
|
2967 |
|
2968 |
|
2969 | _this.on('minimumUpdatePeriod', function () {
|
2970 | _this.refreshXml_();
|
2971 | });
|
2972 |
|
2973 |
|
2974 | _this.on('mediaupdatetimeout', function () {
|
2975 | _this.refreshMedia_(_this.media().id);
|
2976 | });
|
2977 |
|
2978 | _this.state = 'HAVE_NOTHING';
|
2979 | _this.loadedPlaylists_ = {};
|
2980 | _this.logger_ = logger('DashPlaylistLoader');
|
2981 |
|
2982 |
|
2983 | if (_this.isMaster_) {
|
2984 | _this.masterPlaylistLoader_.srcUrl = srcUrlOrPlaylist;
|
2985 |
|
2986 |
|
2987 | _this.masterPlaylistLoader_.sidxMapping_ = {};
|
2988 | } else {
|
2989 | _this.childPlaylist_ = srcUrlOrPlaylist;
|
2990 | }
|
2991 |
|
2992 | return _this;
|
2993 | }
|
2994 |
|
2995 | var _proto = DashPlaylistLoader.prototype;
|
2996 |
|
2997 | _proto.requestErrored_ = function requestErrored_(err, request, startingState) {
|
2998 |
|
2999 | if (!this.request) {
|
3000 | return true;
|
3001 | }
|
3002 |
|
3003 |
|
3004 | this.request = null;
|
3005 |
|
3006 | if (err) {
|
3007 |
|
3008 |
|
3009 | this.error = typeof err === 'object' && !(err instanceof Error) ? err : {
|
3010 | status: request.status,
|
3011 | message: 'DASH request error at URL: ' + request.uri,
|
3012 | response: request.response,
|
3013 |
|
3014 | code: 2
|
3015 | };
|
3016 |
|
3017 | if (startingState) {
|
3018 | this.state = startingState;
|
3019 | }
|
3020 |
|
3021 | this.trigger('error');
|
3022 | return true;
|
3023 | }
|
3024 | }
|
3025 | |
3026 |
|
3027 |
|
3028 |
|
3029 | ;
|
3030 |
|
3031 | _proto.addSidxSegments_ = function addSidxSegments_(playlist, startingState, cb) {
|
3032 | var _this2 = this;
|
3033 |
|
3034 | var sidxKey = playlist.sidx && mpdParser.generateSidxKey(playlist.sidx);
|
3035 |
|
3036 | if (!playlist.sidx || !sidxKey || this.masterPlaylistLoader_.sidxMapping_[sidxKey]) {
|
3037 |
|
3038 | this.mediaRequest_ = window__default['default'].setTimeout(function () {
|
3039 | return cb(false);
|
3040 | }, 0);
|
3041 | return;
|
3042 | }
|
3043 |
|
3044 |
|
3045 | var uri = resolveManifestRedirect(this.handleManifestRedirects, playlist.sidx.resolvedUri);
|
3046 |
|
3047 | var fin = function fin(err, request) {
|
3048 | if (_this2.requestErrored_(err, request, startingState)) {
|
3049 | return;
|
3050 | }
|
3051 |
|
3052 | var sidxMapping = _this2.masterPlaylistLoader_.sidxMapping_;
|
3053 | var sidx;
|
3054 |
|
3055 | try {
|
3056 | sidx = parseSidx__default['default'](byteHelpers.toUint8(request.response).subarray(8));
|
3057 | } catch (e) {
|
3058 |
|
3059 | _this2.requestErrored_(e, request, startingState);
|
3060 |
|
3061 | return;
|
3062 | }
|
3063 |
|
3064 | sidxMapping[sidxKey] = {
|
3065 | sidxInfo: playlist.sidx,
|
3066 | sidx: sidx
|
3067 | };
|
3068 | mpdParser.addSidxSegmentsToPlaylist(playlist, sidx, playlist.sidx.resolvedUri);
|
3069 | return cb(true);
|
3070 | };
|
3071 |
|
3072 | this.request = containerRequest(uri, this.vhs_.xhr, function (err, request, container, bytes) {
|
3073 | if (err) {
|
3074 | return fin(err, request);
|
3075 | }
|
3076 |
|
3077 | if (!container || container !== 'mp4') {
|
3078 | return fin({
|
3079 | status: request.status,
|
3080 | message: "Unsupported " + (container || 'unknown') + " container type for sidx segment at URL: " + uri,
|
3081 |
|
3082 |
|
3083 | response: '',
|
3084 | playlist: playlist,
|
3085 | internal: true,
|
3086 | blacklistDuration: Infinity,
|
3087 |
|
3088 | code: 2
|
3089 | }, request);
|
3090 | }
|
3091 |
|
3092 |
|
3093 | var _playlist$sidx$bytera = playlist.sidx.byterange,
|
3094 | offset = _playlist$sidx$bytera.offset,
|
3095 | length = _playlist$sidx$bytera.length;
|
3096 |
|
3097 | if (bytes.length >= length + offset) {
|
3098 | return fin(err, {
|
3099 | response: bytes.subarray(offset, offset + length),
|
3100 | status: request.status,
|
3101 | uri: request.uri
|
3102 | });
|
3103 | }
|
3104 |
|
3105 |
|
3106 | _this2.request = _this2.vhs_.xhr({
|
3107 | uri: uri,
|
3108 | responseType: 'arraybuffer',
|
3109 | headers: segmentXhrHeaders({
|
3110 | byterange: playlist.sidx.byterange
|
3111 | })
|
3112 | }, fin);
|
3113 | });
|
3114 | };
|
3115 |
|
3116 | _proto.dispose = function dispose() {
|
3117 | this.trigger('dispose');
|
3118 | this.stopRequest();
|
3119 | this.loadedPlaylists_ = {};
|
3120 | window__default['default'].clearTimeout(this.minimumUpdatePeriodTimeout_);
|
3121 | window__default['default'].clearTimeout(this.mediaRequest_);
|
3122 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
3123 | this.mediaUpdateTimeout = null;
|
3124 | this.mediaRequest_ = null;
|
3125 | this.minimumUpdatePeriodTimeout_ = null;
|
3126 |
|
3127 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
3128 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
3129 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
3130 | }
|
3131 |
|
3132 | this.off();
|
3133 | };
|
3134 |
|
3135 | _proto.hasPendingRequest = function hasPendingRequest() {
|
3136 | return this.request || this.mediaRequest_;
|
3137 | };
|
3138 |
|
3139 | _proto.stopRequest = function stopRequest() {
|
3140 | if (this.request) {
|
3141 | var oldRequest = this.request;
|
3142 | this.request = null;
|
3143 | oldRequest.onreadystatechange = null;
|
3144 | oldRequest.abort();
|
3145 | }
|
3146 | };
|
3147 |
|
3148 | _proto.media = function media(playlist) {
|
3149 | var _this3 = this;
|
3150 |
|
3151 |
|
3152 | if (!playlist) {
|
3153 | return this.media_;
|
3154 | }
|
3155 |
|
3156 |
|
3157 | if (this.state === 'HAVE_NOTHING') {
|
3158 | throw new Error('Cannot switch media playlist from ' + this.state);
|
3159 | }
|
3160 |
|
3161 | var startingState = this.state;
|
3162 |
|
3163 | if (typeof playlist === 'string') {
|
3164 | if (!this.masterPlaylistLoader_.master.playlists[playlist]) {
|
3165 | throw new Error('Unknown playlist URI: ' + playlist);
|
3166 | }
|
3167 |
|
3168 | playlist = this.masterPlaylistLoader_.master.playlists[playlist];
|
3169 | }
|
3170 |
|
3171 | var mediaChange = !this.media_ || playlist.id !== this.media_.id;
|
3172 |
|
3173 | if (mediaChange && this.loadedPlaylists_[playlist.id] && this.loadedPlaylists_[playlist.id].endList) {
|
3174 | this.state = 'HAVE_METADATA';
|
3175 | this.media_ = playlist;
|
3176 |
|
3177 | if (mediaChange) {
|
3178 | this.trigger('mediachanging');
|
3179 | this.trigger('mediachange');
|
3180 | }
|
3181 |
|
3182 | return;
|
3183 | }
|
3184 |
|
3185 |
|
3186 | if (!mediaChange) {
|
3187 | return;
|
3188 | }
|
3189 |
|
3190 |
|
3191 | if (this.media_) {
|
3192 | this.trigger('mediachanging');
|
3193 | }
|
3194 |
|
3195 | this.addSidxSegments_(playlist, startingState, function (sidxChanged) {
|
3196 |
|
3197 | _this3.haveMetadata({
|
3198 | startingState: startingState,
|
3199 | playlist: playlist
|
3200 | });
|
3201 | });
|
3202 | };
|
3203 |
|
3204 | _proto.haveMetadata = function haveMetadata(_ref2) {
|
3205 | var startingState = _ref2.startingState,
|
3206 | playlist = _ref2.playlist;
|
3207 | this.state = 'HAVE_METADATA';
|
3208 | this.loadedPlaylists_[playlist.id] = playlist;
|
3209 | this.mediaRequest_ = null;
|
3210 |
|
3211 | this.refreshMedia_(playlist.id);
|
3212 |
|
3213 |
|
3214 | if (startingState === 'HAVE_MASTER') {
|
3215 | this.trigger('loadedmetadata');
|
3216 | } else {
|
3217 |
|
3218 | this.trigger('mediachange');
|
3219 | }
|
3220 | };
|
3221 |
|
3222 | _proto.pause = function pause() {
|
3223 | if (this.masterPlaylistLoader_.createMupOnMedia_) {
|
3224 | this.off('loadedmetadata', this.masterPlaylistLoader_.createMupOnMedia_);
|
3225 | this.masterPlaylistLoader_.createMupOnMedia_ = null;
|
3226 | }
|
3227 |
|
3228 | this.stopRequest();
|
3229 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
3230 | window__default['default'].clearTimeout(this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_);
|
3231 | this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_ = null;
|
3232 | this.mediaUpdateTimeout = null;
|
3233 |
|
3234 | if (this.state === 'HAVE_NOTHING') {
|
3235 |
|
3236 |
|
3237 | this.started = false;
|
3238 | }
|
3239 | };
|
3240 |
|
3241 | _proto.load = function load(isFinalRendition) {
|
3242 | var _this4 = this;
|
3243 |
|
3244 | window__default['default'].clearTimeout(this.mediaUpdateTimeout);
|
3245 | this.mediaUpdateTimeout = null;
|
3246 | var media = this.media();
|
3247 |
|
3248 | if (isFinalRendition) {
|
3249 | var delay = media ? media.targetDuration / 2 * 1000 : 5 * 1000;
|
3250 | this.mediaUpdateTimeout = window__default['default'].setTimeout(function () {
|
3251 | return _this4.load();
|
3252 | }, delay);
|
3253 | return;
|
3254 | }
|
3255 |
|
3256 |
|
3257 |
|
3258 | if (!this.started) {
|
3259 | this.start();
|
3260 | return;
|
3261 | }
|
3262 |
|
3263 | if (media && !media.endList) {
|
3264 | this.trigger('mediaupdatetimeout');
|
3265 | } else {
|
3266 | this.trigger('loadedplaylist');
|
3267 | }
|
3268 | };
|
3269 |
|
3270 | _proto.start = function start() {
|
3271 | var _this5 = this;
|
3272 |
|
3273 | this.started = true;
|
3274 |
|
3275 |
|
3276 | if (!this.isMaster_) {
|
3277 | this.mediaRequest_ = window__default['default'].setTimeout(function () {
|
3278 | return _this5.haveMaster_();
|
3279 | }, 0);
|
3280 | return;
|
3281 | }
|
3282 |
|
3283 | this.requestMaster_(function (req, masterChanged) {
|
3284 | _this5.haveMaster_();
|
3285 |
|
3286 | if (!_this5.hasPendingRequest() && !_this5.media_) {
|
3287 | _this5.media(_this5.masterPlaylistLoader_.master.playlists[0]);
|
3288 | }
|
3289 | });
|
3290 | };
|
3291 |
|
3292 | _proto.requestMaster_ = function requestMaster_(cb) {
|
3293 | var _this6 = this;
|
3294 |
|
3295 | this.request = this.vhs_.xhr({
|
3296 | uri: this.masterPlaylistLoader_.srcUrl,
|
3297 | withCredentials: this.withCredentials
|
3298 | }, function (error, req) {
|
3299 | if (_this6.requestErrored_(error, req)) {
|
3300 | if (_this6.state === 'HAVE_NOTHING') {
|
3301 | _this6.started = false;
|
3302 | }
|
3303 |
|
3304 | return;
|
3305 | }
|
3306 |
|
3307 | var masterChanged = req.responseText !== _this6.masterPlaylistLoader_.masterXml_;
|
3308 | _this6.masterPlaylistLoader_.masterXml_ = req.responseText;
|
3309 |
|
3310 | if (req.responseHeaders && req.responseHeaders.date) {
|
3311 | _this6.masterLoaded_ = Date.parse(req.responseHeaders.date);
|
3312 | } else {
|
3313 | _this6.masterLoaded_ = Date.now();
|
3314 | }
|
3315 |
|
3316 | _this6.masterPlaylistLoader_.srcUrl = resolveManifestRedirect(_this6.handleManifestRedirects, _this6.masterPlaylistLoader_.srcUrl, req);
|
3317 |
|
3318 | if (masterChanged) {
|
3319 | _this6.handleMaster_();
|
3320 |
|
3321 | _this6.syncClientServerClock_(function () {
|
3322 | return cb(req, masterChanged);
|
3323 | });
|
3324 |
|
3325 | return;
|
3326 | }
|
3327 |
|
3328 | return cb(req, masterChanged);
|
3329 | });
|
3330 | }
|
3331 | |
3332 |
|
3333 |
|
3334 |
|
3335 |
|
3336 |
|
3337 |
|
3338 | ;
|
3339 |
|
3340 | _proto.syncClientServerClock_ = function syncClientServerClock_(done) {
|
3341 | var _this7 = this;
|
3342 |
|
3343 | var utcTiming = mpdParser.parseUTCTiming(this.masterPlaylistLoader_.masterXml_);
|
3344 |
|
3345 |
|
3346 | if (utcTiming === null) {
|
3347 | this.masterPlaylistLoader_.clientOffset_ = this.masterLoaded_ - Date.now();
|
3348 | return done();
|
3349 | }
|
3350 |
|
3351 | if (utcTiming.method === 'DIRECT') {
|
3352 | this.masterPlaylistLoader_.clientOffset_ = utcTiming.value - Date.now();
|
3353 | return done();
|
3354 | }
|
3355 |
|
3356 | this.request = this.vhs_.xhr({
|
3357 | uri: resolveUrl(this.masterPlaylistLoader_.srcUrl, utcTiming.value),
|
3358 | method: utcTiming.method,
|
3359 | withCredentials: this.withCredentials
|
3360 | }, function (error, req) {
|
3361 |
|
3362 | if (!_this7.request) {
|
3363 | return;
|
3364 | }
|
3365 |
|
3366 | if (error) {
|
3367 |
|
3368 |
|
3369 | _this7.masterPlaylistLoader_.clientOffset_ = _this7.masterLoaded_ - Date.now();
|
3370 | return done();
|
3371 | }
|
3372 |
|
3373 | var serverTime;
|
3374 |
|
3375 | if (utcTiming.method === 'HEAD') {
|
3376 | if (!req.responseHeaders || !req.responseHeaders.date) {
|
3377 |
|
3378 |
|
3379 | serverTime = _this7.masterLoaded_;
|
3380 | } else {
|
3381 | serverTime = Date.parse(req.responseHeaders.date);
|
3382 | }
|
3383 | } else {
|
3384 | serverTime = Date.parse(req.responseText);
|
3385 | }
|
3386 |
|
3387 | _this7.masterPlaylistLoader_.clientOffset_ = serverTime - Date.now();
|
3388 | done();
|
3389 | });
|
3390 | };
|
3391 |
|
3392 | _proto.haveMaster_ = function haveMaster_() {
|
3393 | this.state = 'HAVE_MASTER';
|
3394 |
|
3395 | if (this.isMaster_) {
|
3396 |
|
3397 |
|
3398 |
|
3399 | this.trigger('loadedplaylist');
|
3400 | } else if (!this.media_) {
|
3401 |
|
3402 |
|
3403 | this.media(this.childPlaylist_);
|
3404 | }
|
3405 | };
|
3406 |
|
3407 | _proto.handleMaster_ = function handleMaster_() {
|
3408 |
|
3409 | this.mediaRequest_ = null;
|
3410 | var newMaster = parseMasterXml({
|
3411 | masterXml: this.masterPlaylistLoader_.masterXml_,
|
3412 | srcUrl: this.masterPlaylistLoader_.srcUrl,
|
3413 | clientOffset: this.masterPlaylistLoader_.clientOffset_,
|
3414 | sidxMapping: this.masterPlaylistLoader_.sidxMapping_
|
3415 | });
|
3416 | var oldMaster = this.masterPlaylistLoader_.master;
|
3417 |
|
3418 | if (oldMaster) {
|
3419 | newMaster = updateMaster(oldMaster, newMaster, this.masterPlaylistLoader_.sidxMapping_);
|
3420 | }
|
3421 |
|
3422 |
|
3423 | this.masterPlaylistLoader_.master = newMaster ? newMaster : oldMaster;
|
3424 | var location = this.masterPlaylistLoader_.master.locations && this.masterPlaylistLoader_.master.locations[0];
|
3425 |
|
3426 | if (location && location !== this.masterPlaylistLoader_.srcUrl) {
|
3427 | this.masterPlaylistLoader_.srcUrl = location;
|
3428 | }
|
3429 |
|
3430 | if (!oldMaster || newMaster && newMaster.minimumUpdatePeriod !== oldMaster.minimumUpdatePeriod) {
|
3431 | this.updateMinimumUpdatePeriodTimeout_();
|
3432 | }
|
3433 |
|
3434 | return Boolean(newMaster);
|
3435 | };
|
3436 |
|
3437 | _proto.updateMinimumUpdatePeriodTimeout_ = function updateMinimumUpdatePeriodTimeout_() {
|
3438 | var mpl = this.masterPlaylistLoader_;
|
3439 |
|
3440 |
|
3441 | if (mpl.createMupOnMedia_) {
|
3442 | mpl.off('loadedmetadata', mpl.createMupOnMedia_);
|
3443 | mpl.createMupOnMedia_ = null;
|
3444 | }
|
3445 |
|
3446 |
|
3447 | if (mpl.minimumUpdatePeriodTimeout_) {
|
3448 | window__default['default'].clearTimeout(mpl.minimumUpdatePeriodTimeout_);
|
3449 | mpl.minimumUpdatePeriodTimeout_ = null;
|
3450 | }
|
3451 |
|
3452 | var mup = mpl.master && mpl.master.minimumUpdatePeriod;
|
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 | if (mup === 0) {
|
3458 | if (mpl.media()) {
|
3459 | mup = mpl.media().targetDuration * 1000;
|
3460 | } else {
|
3461 | mpl.createMupOnMedia_ = mpl.updateMinimumUpdatePeriodTimeout_;
|
3462 | mpl.one('loadedmetadata', mpl.createMupOnMedia_);
|
3463 | }
|
3464 | }
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 | if (typeof mup !== 'number' || mup <= 0) {
|
3470 | if (mup < 0) {
|
3471 | this.logger_("found invalid minimumUpdatePeriod of " + mup + ", not setting a timeout");
|
3472 | }
|
3473 |
|
3474 | return;
|
3475 | }
|
3476 |
|
3477 | this.createMUPTimeout_(mup);
|
3478 | };
|
3479 |
|
3480 | _proto.createMUPTimeout_ = function createMUPTimeout_(mup) {
|
3481 | var mpl = this.masterPlaylistLoader_;
|
3482 | mpl.minimumUpdatePeriodTimeout_ = window__default['default'].setTimeout(function () {
|
3483 | mpl.minimumUpdatePeriodTimeout_ = null;
|
3484 | mpl.trigger('minimumUpdatePeriod');
|
3485 | mpl.createMUPTimeout_(mup);
|
3486 | }, mup);
|
3487 | }
|
3488 | |
3489 |
|
3490 |
|
3491 | ;
|
3492 |
|
3493 | _proto.refreshXml_ = function refreshXml_() {
|
3494 | var _this8 = this;
|
3495 |
|
3496 | this.requestMaster_(function (req, masterChanged) {
|
3497 | if (!masterChanged) {
|
3498 | return;
|
3499 | }
|
3500 |
|
3501 | if (_this8.media_) {
|
3502 | _this8.media_ = _this8.masterPlaylistLoader_.master.playlists[_this8.media_.id];
|
3503 | }
|
3504 |
|
3505 |
|
3506 | _this8.masterPlaylistLoader_.sidxMapping_ = filterChangedSidxMappings(_this8.masterPlaylistLoader_.master, _this8.masterPlaylistLoader_.sidxMapping_);
|
3507 |
|
3508 | _this8.addSidxSegments_(_this8.media(), _this8.state, function (sidxChanged) {
|
3509 |
|
3510 | _this8.refreshMedia_(_this8.media().id);
|
3511 | });
|
3512 | });
|
3513 | }
|
3514 | |
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 | ;
|
3520 |
|
3521 | _proto.refreshMedia_ = function refreshMedia_(mediaID) {
|
3522 | var _this9 = this;
|
3523 |
|
3524 | if (!mediaID) {
|
3525 | throw new Error('refreshMedia_ must take a media id');
|
3526 | }
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 | if (this.media_ && this.isMaster_) {
|
3534 | this.handleMaster_();
|
3535 | }
|
3536 |
|
3537 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
3538 | var mediaChanged = !this.media_ || this.media_ !== playlists[mediaID];
|
3539 |
|
3540 | if (mediaChanged) {
|
3541 | this.media_ = playlists[mediaID];
|
3542 | } else {
|
3543 | this.trigger('playlistunchanged');
|
3544 | }
|
3545 |
|
3546 | if (!this.mediaUpdateTimeout) {
|
3547 | var createMediaUpdateTimeout = function createMediaUpdateTimeout() {
|
3548 | if (_this9.media().endList) {
|
3549 | return;
|
3550 | }
|
3551 |
|
3552 | _this9.mediaUpdateTimeout = window__default['default'].setTimeout(function () {
|
3553 | _this9.trigger('mediaupdatetimeout');
|
3554 |
|
3555 | createMediaUpdateTimeout();
|
3556 | }, refreshDelay(_this9.media(), Boolean(mediaChanged)));
|
3557 | };
|
3558 |
|
3559 | createMediaUpdateTimeout();
|
3560 | }
|
3561 |
|
3562 | this.trigger('loadedplaylist');
|
3563 | };
|
3564 |
|
3565 | return DashPlaylistLoader;
|
3566 | }(EventTarget);
|
3567 |
|
3568 | var Config = {
|
3569 | GOAL_BUFFER_LENGTH: 30,
|
3570 | MAX_GOAL_BUFFER_LENGTH: 60,
|
3571 | BACK_BUFFER_LENGTH: 30,
|
3572 | GOAL_BUFFER_LENGTH_RATE: 1,
|
3573 |
|
3574 | INITIAL_BANDWIDTH: 4194304,
|
3575 |
|
3576 |
|
3577 | BANDWIDTH_VARIANCE: 1.2,
|
3578 |
|
3579 | BUFFER_LOW_WATER_LINE: 0,
|
3580 | MAX_BUFFER_LOW_WATER_LINE: 30,
|
3581 |
|
3582 | EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE: 16,
|
3583 | BUFFER_LOW_WATER_LINE_RATE: 1,
|
3584 |
|
3585 | BUFFER_HIGH_WATER_LINE: 30
|
3586 | };
|
3587 |
|
3588 | var stringToArrayBuffer = function stringToArrayBuffer(string) {
|
3589 | var view = new Uint8Array(new ArrayBuffer(string.length));
|
3590 |
|
3591 | for (var i = 0; i < string.length; i++) {
|
3592 | view[i] = string.charCodeAt(i);
|
3593 | }
|
3594 |
|
3595 | return view.buffer;
|
3596 | };
|
3597 |
|
3598 |
|
3599 |
|
3600 | var browserWorkerPolyFill = function browserWorkerPolyFill(workerObj) {
|
3601 |
|
3602 | workerObj.on = workerObj.addEventListener;
|
3603 | workerObj.off = workerObj.removeEventListener;
|
3604 | return workerObj;
|
3605 | };
|
3606 |
|
3607 | var createObjectURL = function createObjectURL(str) {
|
3608 | try {
|
3609 | return URL.createObjectURL(new Blob([str], {
|
3610 | type: 'application/javascript'
|
3611 | }));
|
3612 | } catch (e) {
|
3613 | var blob = new BlobBuilder();
|
3614 | blob.append(str);
|
3615 | return URL.createObjectURL(blob.getBlob());
|
3616 | }
|
3617 | };
|
3618 |
|
3619 | var factory = function factory(code) {
|
3620 | return function () {
|
3621 | var objectUrl = createObjectURL(code);
|
3622 | var worker = browserWorkerPolyFill(new Worker(objectUrl));
|
3623 | worker.objURL = objectUrl;
|
3624 | var terminate = worker.terminate;
|
3625 | worker.on = worker.addEventListener;
|
3626 | worker.off = worker.removeEventListener;
|
3627 |
|
3628 | worker.terminate = function () {
|
3629 | URL.revokeObjectURL(objectUrl);
|
3630 | return terminate.call(this);
|
3631 | };
|
3632 |
|
3633 | return worker;
|
3634 | };
|
3635 | };
|
3636 | var transform = function transform(code) {
|
3637 | return "var browserWorkerPolyFill = " + browserWorkerPolyFill.toString() + ";\n" + 'browserWorkerPolyFill(self);\n' + code;
|
3638 | };
|
3639 |
|
3640 | var getWorkerString = function getWorkerString(fn) {
|
3641 | return fn.toString().replace(/^function.+?{/, '').slice(0, -1);
|
3642 | };
|
3643 |
|
3644 |
|
3645 | var workerCode$1 = transform(getWorkerString(function () {
|
3646 | |
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 | var Stream = function Stream() {
|
3657 | this.init = function () {
|
3658 | var listeners = {};
|
3659 | |
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 | this.on = function (type, listener) {
|
3667 | if (!listeners[type]) {
|
3668 | listeners[type] = [];
|
3669 | }
|
3670 |
|
3671 | listeners[type] = listeners[type].concat(listener);
|
3672 | };
|
3673 | |
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 | this.off = function (type, listener) {
|
3682 | var index;
|
3683 |
|
3684 | if (!listeners[type]) {
|
3685 | return false;
|
3686 | }
|
3687 |
|
3688 | index = listeners[type].indexOf(listener);
|
3689 | listeners[type] = listeners[type].slice();
|
3690 | listeners[type].splice(index, 1);
|
3691 | return index > -1;
|
3692 | };
|
3693 | |
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 |
|
3700 | this.trigger = function (type) {
|
3701 | var callbacks, i, length, args;
|
3702 | callbacks = listeners[type];
|
3703 |
|
3704 | if (!callbacks) {
|
3705 | return;
|
3706 | }
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 | if (arguments.length === 2) {
|
3713 | length = callbacks.length;
|
3714 |
|
3715 | for (i = 0; i < length; ++i) {
|
3716 | callbacks[i].call(this, arguments[1]);
|
3717 | }
|
3718 | } else {
|
3719 | args = [];
|
3720 | i = arguments.length;
|
3721 |
|
3722 | for (i = 1; i < arguments.length; ++i) {
|
3723 | args.push(arguments[i]);
|
3724 | }
|
3725 |
|
3726 | length = callbacks.length;
|
3727 |
|
3728 | for (i = 0; i < length; ++i) {
|
3729 | callbacks[i].apply(this, args);
|
3730 | }
|
3731 | }
|
3732 | };
|
3733 | |
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 | this.dispose = function () {
|
3739 | listeners = {};
|
3740 | };
|
3741 | };
|
3742 | };
|
3743 | |
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 | Stream.prototype.pipe = function (destination) {
|
3755 | this.on('data', function (data) {
|
3756 | destination.push(data);
|
3757 | });
|
3758 | this.on('done', function (flushSource) {
|
3759 | destination.flush(flushSource);
|
3760 | });
|
3761 | this.on('partialdone', function (flushSource) {
|
3762 | destination.partialFlush(flushSource);
|
3763 | });
|
3764 | this.on('endedtimeline', function (flushSource) {
|
3765 | destination.endTimeline(flushSource);
|
3766 | });
|
3767 | this.on('reset', function (flushSource) {
|
3768 | destination.reset(flushSource);
|
3769 | });
|
3770 | return destination;
|
3771 | };
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 | Stream.prototype.push = function (data) {
|
3778 | this.trigger('data', data);
|
3779 | };
|
3780 |
|
3781 | Stream.prototype.flush = function (flushSource) {
|
3782 | this.trigger('done', flushSource);
|
3783 | };
|
3784 |
|
3785 | Stream.prototype.partialFlush = function (flushSource) {
|
3786 | this.trigger('partialdone', flushSource);
|
3787 | };
|
3788 |
|
3789 | Stream.prototype.endTimeline = function (flushSource) {
|
3790 | this.trigger('endedtimeline', flushSource);
|
3791 | };
|
3792 |
|
3793 | Stream.prototype.reset = function (flushSource) {
|
3794 | this.trigger('reset', flushSource);
|
3795 | };
|
3796 |
|
3797 | var stream = Stream;
|
3798 | |
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 | var UINT32_MAX = Math.pow(2, 32) - 1;
|
3809 | 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;
|
3810 |
|
3811 | (function () {
|
3812 | var i;
|
3813 | types = {
|
3814 | avc1: [],
|
3815 |
|
3816 | avcC: [],
|
3817 | btrt: [],
|
3818 | dinf: [],
|
3819 | dref: [],
|
3820 | esds: [],
|
3821 | ftyp: [],
|
3822 | hdlr: [],
|
3823 | mdat: [],
|
3824 | mdhd: [],
|
3825 | mdia: [],
|
3826 | mfhd: [],
|
3827 | minf: [],
|
3828 | moof: [],
|
3829 | moov: [],
|
3830 | mp4a: [],
|
3831 |
|
3832 | mvex: [],
|
3833 | mvhd: [],
|
3834 | pasp: [],
|
3835 | sdtp: [],
|
3836 | smhd: [],
|
3837 | stbl: [],
|
3838 | stco: [],
|
3839 | stsc: [],
|
3840 | stsd: [],
|
3841 | stsz: [],
|
3842 | stts: [],
|
3843 | styp: [],
|
3844 | tfdt: [],
|
3845 | tfhd: [],
|
3846 | traf: [],
|
3847 | trak: [],
|
3848 | trun: [],
|
3849 | trex: [],
|
3850 | tkhd: [],
|
3851 | vmhd: []
|
3852 | };
|
3853 |
|
3854 |
|
3855 | if (typeof Uint8Array === 'undefined') {
|
3856 | return;
|
3857 | }
|
3858 |
|
3859 | for (i in types) {
|
3860 | if (types.hasOwnProperty(i)) {
|
3861 | types[i] = [i.charCodeAt(0), i.charCodeAt(1), i.charCodeAt(2), i.charCodeAt(3)];
|
3862 | }
|
3863 | }
|
3864 |
|
3865 | MAJOR_BRAND = new Uint8Array(['i'.charCodeAt(0), 's'.charCodeAt(0), 'o'.charCodeAt(0), 'm'.charCodeAt(0)]);
|
3866 | AVC1_BRAND = new Uint8Array(['a'.charCodeAt(0), 'v'.charCodeAt(0), 'c'.charCodeAt(0), '1'.charCodeAt(0)]);
|
3867 | MINOR_VERSION = new Uint8Array([0, 0, 0, 1]);
|
3868 | VIDEO_HDLR = new Uint8Array([0x00,
|
3869 | 0x00, 0x00, 0x00,
|
3870 | 0x00, 0x00, 0x00, 0x00,
|
3871 | 0x76, 0x69, 0x64, 0x65,
|
3872 | 0x00, 0x00, 0x00, 0x00,
|
3873 | 0x00, 0x00, 0x00, 0x00,
|
3874 | 0x00, 0x00, 0x00, 0x00,
|
3875 | 0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
3876 | ]);
|
3877 | AUDIO_HDLR = new Uint8Array([0x00,
|
3878 | 0x00, 0x00, 0x00,
|
3879 | 0x00, 0x00, 0x00, 0x00,
|
3880 | 0x73, 0x6f, 0x75, 0x6e,
|
3881 | 0x00, 0x00, 0x00, 0x00,
|
3882 | 0x00, 0x00, 0x00, 0x00,
|
3883 | 0x00, 0x00, 0x00, 0x00,
|
3884 | 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00
|
3885 | ]);
|
3886 | HDLR_TYPES = {
|
3887 | video: VIDEO_HDLR,
|
3888 | audio: AUDIO_HDLR
|
3889 | };
|
3890 | DREF = new Uint8Array([0x00,
|
3891 | 0x00, 0x00, 0x00,
|
3892 | 0x00, 0x00, 0x00, 0x01,
|
3893 | 0x00, 0x00, 0x00, 0x0c,
|
3894 | 0x75, 0x72, 0x6c, 0x20,
|
3895 | 0x00,
|
3896 | 0x00, 0x00, 0x01
|
3897 | ]);
|
3898 | SMHD = new Uint8Array([0x00,
|
3899 | 0x00, 0x00, 0x00,
|
3900 | 0x00, 0x00,
|
3901 | 0x00, 0x00
|
3902 | ]);
|
3903 | STCO = new Uint8Array([0x00,
|
3904 | 0x00, 0x00, 0x00,
|
3905 | 0x00, 0x00, 0x00, 0x00
|
3906 | ]);
|
3907 | STSC = STCO;
|
3908 | STSZ = new Uint8Array([0x00,
|
3909 | 0x00, 0x00, 0x00,
|
3910 | 0x00, 0x00, 0x00, 0x00,
|
3911 | 0x00, 0x00, 0x00, 0x00
|
3912 | ]);
|
3913 | STTS = STCO;
|
3914 | VMHD = new Uint8Array([0x00,
|
3915 | 0x00, 0x00, 0x01,
|
3916 | 0x00, 0x00,
|
3917 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
3918 | ]);
|
3919 | })();
|
3920 |
|
3921 | box = function box(type) {
|
3922 | var payload = [],
|
3923 | size = 0,
|
3924 | i,
|
3925 | result,
|
3926 | view;
|
3927 |
|
3928 | for (i = 1; i < arguments.length; i++) {
|
3929 | payload.push(arguments[i]);
|
3930 | }
|
3931 |
|
3932 | i = payload.length;
|
3933 |
|
3934 | while (i--) {
|
3935 | size += payload[i].byteLength;
|
3936 | }
|
3937 |
|
3938 | result = new Uint8Array(size + 8);
|
3939 | view = new DataView(result.buffer, result.byteOffset, result.byteLength);
|
3940 | view.setUint32(0, result.byteLength);
|
3941 | result.set(type, 4);
|
3942 |
|
3943 | for (i = 0, size = 8; i < payload.length; i++) {
|
3944 | result.set(payload[i], size);
|
3945 | size += payload[i].byteLength;
|
3946 | }
|
3947 |
|
3948 | return result;
|
3949 | };
|
3950 |
|
3951 | dinf = function dinf() {
|
3952 | return box(types.dinf, box(types.dref, DREF));
|
3953 | };
|
3954 |
|
3955 | esds = function esds(track) {
|
3956 | return box(types.esds, new Uint8Array([0x00,
|
3957 | 0x00, 0x00, 0x00,
|
3958 |
|
3959 | 0x03,
|
3960 | 0x19,
|
3961 | 0x00, 0x00,
|
3962 | 0x00,
|
3963 |
|
3964 | 0x04,
|
3965 | 0x11,
|
3966 | 0x40,
|
3967 | 0x15,
|
3968 | 0x00, 0x06, 0x00,
|
3969 | 0x00, 0x00, 0xda, 0xc0,
|
3970 | 0x00, 0x00, 0xda, 0xc0,
|
3971 |
|
3972 | 0x05,
|
3973 | 0x02,
|
3974 |
|
3975 |
|
3976 | track.audioobjecttype << 3 | track.samplingfrequencyindex >>> 1, track.samplingfrequencyindex << 7 | track.channelcount << 3, 0x06, 0x01, 0x02
|
3977 | ]));
|
3978 | };
|
3979 |
|
3980 | ftyp = function ftyp() {
|
3981 | return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND, AVC1_BRAND);
|
3982 | };
|
3983 |
|
3984 | hdlr = function hdlr(type) {
|
3985 | return box(types.hdlr, HDLR_TYPES[type]);
|
3986 | };
|
3987 |
|
3988 | mdat = function mdat(data) {
|
3989 | return box(types.mdat, data);
|
3990 | };
|
3991 |
|
3992 | mdhd = function mdhd(track) {
|
3993 | var result = new Uint8Array([0x00,
|
3994 | 0x00, 0x00, 0x00,
|
3995 | 0x00, 0x00, 0x00, 0x02,
|
3996 | 0x00, 0x00, 0x00, 0x03,
|
3997 | 0x00, 0x01, 0x5f, 0x90,
|
3998 | track.duration >>> 24 & 0xFF, track.duration >>> 16 & 0xFF, track.duration >>> 8 & 0xFF, track.duration & 0xFF,
|
3999 | 0x55, 0xc4,
|
4000 | 0x00, 0x00]);
|
4001 |
|
4002 |
|
4003 |
|
4004 | if (track.samplerate) {
|
4005 | result[12] = track.samplerate >>> 24 & 0xFF;
|
4006 | result[13] = track.samplerate >>> 16 & 0xFF;
|
4007 | result[14] = track.samplerate >>> 8 & 0xFF;
|
4008 | result[15] = track.samplerate & 0xFF;
|
4009 | }
|
4010 |
|
4011 | return box(types.mdhd, result);
|
4012 | };
|
4013 |
|
4014 | mdia = function mdia(track) {
|
4015 | return box(types.mdia, mdhd(track), hdlr(track.type), minf(track));
|
4016 | };
|
4017 |
|
4018 | mfhd = function mfhd(sequenceNumber) {
|
4019 | return box(types.mfhd, new Uint8Array([0x00, 0x00, 0x00, 0x00,
|
4020 | (sequenceNumber & 0xFF000000) >> 24, (sequenceNumber & 0xFF0000) >> 16, (sequenceNumber & 0xFF00) >> 8, sequenceNumber & 0xFF
|
4021 | ]));
|
4022 | };
|
4023 |
|
4024 | minf = function minf(track) {
|
4025 | return box(types.minf, track.type === 'video' ? box(types.vmhd, VMHD) : box(types.smhd, SMHD), dinf(), stbl(track));
|
4026 | };
|
4027 |
|
4028 | moof = function moof(sequenceNumber, tracks) {
|
4029 | var trackFragments = [],
|
4030 | i = tracks.length;
|
4031 |
|
4032 | while (i--) {
|
4033 | trackFragments[i] = traf(tracks[i]);
|
4034 | }
|
4035 |
|
4036 | return box.apply(null, [types.moof, mfhd(sequenceNumber)].concat(trackFragments));
|
4037 | };
|
4038 | |
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 |
|
4045 | moov = function moov(tracks) {
|
4046 | var i = tracks.length,
|
4047 | boxes = [];
|
4048 |
|
4049 | while (i--) {
|
4050 | boxes[i] = trak(tracks[i]);
|
4051 | }
|
4052 |
|
4053 | return box.apply(null, [types.moov, mvhd(0xffffffff)].concat(boxes).concat(mvex(tracks)));
|
4054 | };
|
4055 |
|
4056 | mvex = function mvex(tracks) {
|
4057 | var i = tracks.length,
|
4058 | boxes = [];
|
4059 |
|
4060 | while (i--) {
|
4061 | boxes[i] = trex(tracks[i]);
|
4062 | }
|
4063 |
|
4064 | return box.apply(null, [types.mvex].concat(boxes));
|
4065 | };
|
4066 |
|
4067 | mvhd = function mvhd(duration) {
|
4068 | var bytes = new Uint8Array([0x00,
|
4069 | 0x00, 0x00, 0x00,
|
4070 | 0x00, 0x00, 0x00, 0x01,
|
4071 | 0x00, 0x00, 0x00, 0x02,
|
4072 | 0x00, 0x01, 0x5f, 0x90,
|
4073 | (duration & 0xFF000000) >> 24, (duration & 0xFF0000) >> 16, (duration & 0xFF00) >> 8, duration & 0xFF,
|
4074 | 0x00, 0x01, 0x00, 0x00,
|
4075 | 0x01, 0x00,
|
4076 | 0x00, 0x00,
|
4077 | 0x00, 0x00, 0x00, 0x00,
|
4078 | 0x00, 0x00, 0x00, 0x00,
|
4079 | 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,
|
4080 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4081 | 0xff, 0xff, 0xff, 0xff
|
4082 | ]);
|
4083 | return box(types.mvhd, bytes);
|
4084 | };
|
4085 |
|
4086 | sdtp = function sdtp(track) {
|
4087 | var samples = track.samples || [],
|
4088 | bytes = new Uint8Array(4 + samples.length),
|
4089 | flags,
|
4090 | i;
|
4091 |
|
4092 |
|
4093 | for (i = 0; i < samples.length; i++) {
|
4094 | flags = samples[i].flags;
|
4095 | bytes[i + 4] = flags.dependsOn << 4 | flags.isDependedOn << 2 | flags.hasRedundancy;
|
4096 | }
|
4097 |
|
4098 | return box(types.sdtp, bytes);
|
4099 | };
|
4100 |
|
4101 | stbl = function stbl(track) {
|
4102 | return box(types.stbl, stsd(track), box(types.stts, STTS), box(types.stsc, STSC), box(types.stsz, STSZ), box(types.stco, STCO));
|
4103 | };
|
4104 |
|
4105 | (function () {
|
4106 | var videoSample, audioSample;
|
4107 |
|
4108 | stsd = function stsd(track) {
|
4109 | return box(types.stsd, new Uint8Array([0x00,
|
4110 | 0x00, 0x00, 0x00,
|
4111 | 0x00, 0x00, 0x00, 0x01]), track.type === 'video' ? videoSample(track) : audioSample(track));
|
4112 | };
|
4113 |
|
4114 | videoSample = function videoSample(track) {
|
4115 | var sps = track.sps || [],
|
4116 | pps = track.pps || [],
|
4117 | sequenceParameterSets = [],
|
4118 | pictureParameterSets = [],
|
4119 | i,
|
4120 | avc1Box;
|
4121 |
|
4122 | for (i = 0; i < sps.length; i++) {
|
4123 | sequenceParameterSets.push((sps[i].byteLength & 0xFF00) >>> 8);
|
4124 | sequenceParameterSets.push(sps[i].byteLength & 0xFF);
|
4125 |
|
4126 | sequenceParameterSets = sequenceParameterSets.concat(Array.prototype.slice.call(sps[i]));
|
4127 | }
|
4128 |
|
4129 |
|
4130 | for (i = 0; i < pps.length; i++) {
|
4131 | pictureParameterSets.push((pps[i].byteLength & 0xFF00) >>> 8);
|
4132 | pictureParameterSets.push(pps[i].byteLength & 0xFF);
|
4133 | pictureParameterSets = pictureParameterSets.concat(Array.prototype.slice.call(pps[i]));
|
4134 | }
|
4135 |
|
4136 | avc1Box = [types.avc1, new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4137 | 0x00, 0x01,
|
4138 | 0x00, 0x00,
|
4139 | 0x00, 0x00,
|
4140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4141 | (track.width & 0xff00) >> 8, track.width & 0xff,
|
4142 | (track.height & 0xff00) >> 8, track.height & 0xff,
|
4143 | 0x00, 0x48, 0x00, 0x00,
|
4144 | 0x00, 0x48, 0x00, 0x00,
|
4145 | 0x00, 0x00, 0x00, 0x00,
|
4146 | 0x00, 0x01,
|
4147 | 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,
|
4148 | 0x00, 0x18,
|
4149 | 0x11, 0x11
|
4150 | ]), box(types.avcC, new Uint8Array([0x01,
|
4151 | track.profileIdc,
|
4152 | track.profileCompatibility,
|
4153 | track.levelIdc,
|
4154 | 0xff
|
4155 | ].concat([sps.length],
|
4156 | sequenceParameterSets,
|
4157 | [pps.length],
|
4158 | pictureParameterSets
|
4159 | ))), box(types.btrt, new Uint8Array([0x00, 0x1c, 0x9c, 0x80,
|
4160 | 0x00, 0x2d, 0xc6, 0xc0,
|
4161 | 0x00, 0x2d, 0xc6, 0xc0
|
4162 | ]))];
|
4163 |
|
4164 | if (track.sarRatio) {
|
4165 | var hSpacing = track.sarRatio[0],
|
4166 | vSpacing = track.sarRatio[1];
|
4167 | 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])));
|
4168 | }
|
4169 |
|
4170 | return box.apply(null, avc1Box);
|
4171 | };
|
4172 |
|
4173 | audioSample = function audioSample(track) {
|
4174 | return box(types.mp4a, new Uint8Array([
|
4175 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4176 | 0x00, 0x01,
|
4177 |
|
4178 | 0x00, 0x00, 0x00, 0x00,
|
4179 | 0x00, 0x00, 0x00, 0x00,
|
4180 | (track.channelcount & 0xff00) >> 8, track.channelcount & 0xff,
|
4181 | (track.samplesize & 0xff00) >> 8, track.samplesize & 0xff,
|
4182 | 0x00, 0x00,
|
4183 | 0x00, 0x00,
|
4184 | (track.samplerate & 0xff00) >> 8, track.samplerate & 0xff, 0x00, 0x00
|
4185 |
|
4186 | ]), esds(track));
|
4187 | };
|
4188 | })();
|
4189 |
|
4190 | tkhd = function tkhd(track) {
|
4191 | var result = new Uint8Array([0x00,
|
4192 | 0x00, 0x00, 0x07,
|
4193 | 0x00, 0x00, 0x00, 0x00,
|
4194 | 0x00, 0x00, 0x00, 0x00,
|
4195 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4196 | 0x00, 0x00, 0x00, 0x00,
|
4197 | (track.duration & 0xFF000000) >> 24, (track.duration & 0xFF0000) >> 16, (track.duration & 0xFF00) >> 8, track.duration & 0xFF,
|
4198 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
4199 | 0x00, 0x00,
|
4200 | 0x00, 0x00,
|
4201 | 0x01, 0x00,
|
4202 | 0x00, 0x00,
|
4203 | 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,
|
4204 | (track.width & 0xFF00) >> 8, track.width & 0xFF, 0x00, 0x00,
|
4205 | (track.height & 0xFF00) >> 8, track.height & 0xFF, 0x00, 0x00
|
4206 | ]);
|
4207 | return box(types.tkhd, result);
|
4208 | };
|
4209 | |
4210 |
|
4211 |
|
4212 |
|
4213 |
|
4214 |
|
4215 | traf = function traf(track) {
|
4216 | var trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable, dataOffset, upperWordBaseMediaDecodeTime, lowerWordBaseMediaDecodeTime;
|
4217 | trackFragmentHeader = box(types.tfhd, new Uint8Array([0x00,
|
4218 | 0x00, 0x00, 0x3a,
|
4219 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4220 | 0x00, 0x00, 0x00, 0x01,
|
4221 | 0x00, 0x00, 0x00, 0x00,
|
4222 | 0x00, 0x00, 0x00, 0x00,
|
4223 | 0x00, 0x00, 0x00, 0x00
|
4224 | ]));
|
4225 | upperWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime / (UINT32_MAX + 1));
|
4226 | lowerWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime % (UINT32_MAX + 1));
|
4227 | trackFragmentDecodeTime = box(types.tfdt, new Uint8Array([0x01,
|
4228 | 0x00, 0x00, 0x00,
|
4229 |
|
4230 | upperWordBaseMediaDecodeTime >>> 24 & 0xFF, upperWordBaseMediaDecodeTime >>> 16 & 0xFF, upperWordBaseMediaDecodeTime >>> 8 & 0xFF, upperWordBaseMediaDecodeTime & 0xFF, lowerWordBaseMediaDecodeTime >>> 24 & 0xFF, lowerWordBaseMediaDecodeTime >>> 16 & 0xFF, lowerWordBaseMediaDecodeTime >>> 8 & 0xFF, lowerWordBaseMediaDecodeTime & 0xFF]));
|
4231 |
|
4232 |
|
4233 |
|
4234 | dataOffset = 32 +
|
4235 | 20 +
|
4236 | 8 +
|
4237 | 16 +
|
4238 | 8 +
|
4239 | 8;
|
4240 |
|
4241 |
|
4242 | if (track.type === 'audio') {
|
4243 | trackFragmentRun = trun$1(track, dataOffset);
|
4244 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun);
|
4245 | }
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 | sampleDependencyTable = sdtp(track);
|
4251 | trackFragmentRun = trun$1(track, sampleDependencyTable.length + dataOffset);
|
4252 | return box(types.traf, trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun, sampleDependencyTable);
|
4253 | };
|
4254 | |
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 | trak = function trak(track) {
|
4262 | track.duration = track.duration || 0xffffffff;
|
4263 | return box(types.trak, tkhd(track), mdia(track));
|
4264 | };
|
4265 |
|
4266 | trex = function trex(track) {
|
4267 | var result = new Uint8Array([0x00,
|
4268 | 0x00, 0x00, 0x00,
|
4269 | (track.id & 0xFF000000) >> 24, (track.id & 0xFF0000) >> 16, (track.id & 0xFF00) >> 8, track.id & 0xFF,
|
4270 | 0x00, 0x00, 0x00, 0x01,
|
4271 | 0x00, 0x00, 0x00, 0x00,
|
4272 | 0x00, 0x00, 0x00, 0x00,
|
4273 | 0x00, 0x01, 0x00, 0x01
|
4274 | ]);
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 | if (track.type !== 'video') {
|
4280 | result[result.length - 1] = 0x00;
|
4281 | }
|
4282 |
|
4283 | return box(types.trex, result);
|
4284 | };
|
4285 |
|
4286 | (function () {
|
4287 | var audioTrun, videoTrun, trunHeader;
|
4288 |
|
4289 |
|
4290 |
|
4291 |
|
4292 | trunHeader = function trunHeader(samples, offset) {
|
4293 | var durationPresent = 0,
|
4294 | sizePresent = 0,
|
4295 | flagsPresent = 0,
|
4296 | compositionTimeOffset = 0;
|
4297 |
|
4298 | if (samples.length) {
|
4299 | if (samples[0].duration !== undefined) {
|
4300 | durationPresent = 0x1;
|
4301 | }
|
4302 |
|
4303 | if (samples[0].size !== undefined) {
|
4304 | sizePresent = 0x2;
|
4305 | }
|
4306 |
|
4307 | if (samples[0].flags !== undefined) {
|
4308 | flagsPresent = 0x4;
|
4309 | }
|
4310 |
|
4311 | if (samples[0].compositionTimeOffset !== undefined) {
|
4312 | compositionTimeOffset = 0x8;
|
4313 | }
|
4314 | }
|
4315 |
|
4316 | return [0x00,
|
4317 | 0x00, durationPresent | sizePresent | flagsPresent | compositionTimeOffset, 0x01,
|
4318 | (samples.length & 0xFF000000) >>> 24, (samples.length & 0xFF0000) >>> 16, (samples.length & 0xFF00) >>> 8, samples.length & 0xFF,
|
4319 | (offset & 0xFF000000) >>> 24, (offset & 0xFF0000) >>> 16, (offset & 0xFF00) >>> 8, offset & 0xFF
|
4320 | ];
|
4321 | };
|
4322 |
|
4323 | videoTrun = function videoTrun(track, offset) {
|
4324 | var bytesOffest, bytes, header, samples, sample, i;
|
4325 | samples = track.samples || [];
|
4326 | offset += 8 + 12 + 16 * samples.length;
|
4327 | header = trunHeader(samples, offset);
|
4328 | bytes = new Uint8Array(header.length + samples.length * 16);
|
4329 | bytes.set(header);
|
4330 | bytesOffest = header.length;
|
4331 |
|
4332 | for (i = 0; i < samples.length; i++) {
|
4333 | sample = samples[i];
|
4334 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
4335 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
4336 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
4337 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
4338 |
|
4339 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
4340 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
4341 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
4342 | bytes[bytesOffest++] = sample.size & 0xFF;
|
4343 |
|
4344 | bytes[bytesOffest++] = sample.flags.isLeading << 2 | sample.flags.dependsOn;
|
4345 | bytes[bytesOffest++] = sample.flags.isDependedOn << 6 | sample.flags.hasRedundancy << 4 | sample.flags.paddingValue << 1 | sample.flags.isNonSyncSample;
|
4346 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0xF0 << 8;
|
4347 | bytes[bytesOffest++] = sample.flags.degradationPriority & 0x0F;
|
4348 |
|
4349 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF000000) >>> 24;
|
4350 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF0000) >>> 16;
|
4351 | bytes[bytesOffest++] = (sample.compositionTimeOffset & 0xFF00) >>> 8;
|
4352 | bytes[bytesOffest++] = sample.compositionTimeOffset & 0xFF;
|
4353 | }
|
4354 |
|
4355 | return box(types.trun, bytes);
|
4356 | };
|
4357 |
|
4358 | audioTrun = function audioTrun(track, offset) {
|
4359 | var bytes, bytesOffest, header, samples, sample, i;
|
4360 | samples = track.samples || [];
|
4361 | offset += 8 + 12 + 8 * samples.length;
|
4362 | header = trunHeader(samples, offset);
|
4363 | bytes = new Uint8Array(header.length + samples.length * 8);
|
4364 | bytes.set(header);
|
4365 | bytesOffest = header.length;
|
4366 |
|
4367 | for (i = 0; i < samples.length; i++) {
|
4368 | sample = samples[i];
|
4369 | bytes[bytesOffest++] = (sample.duration & 0xFF000000) >>> 24;
|
4370 | bytes[bytesOffest++] = (sample.duration & 0xFF0000) >>> 16;
|
4371 | bytes[bytesOffest++] = (sample.duration & 0xFF00) >>> 8;
|
4372 | bytes[bytesOffest++] = sample.duration & 0xFF;
|
4373 |
|
4374 | bytes[bytesOffest++] = (sample.size & 0xFF000000) >>> 24;
|
4375 | bytes[bytesOffest++] = (sample.size & 0xFF0000) >>> 16;
|
4376 | bytes[bytesOffest++] = (sample.size & 0xFF00) >>> 8;
|
4377 | bytes[bytesOffest++] = sample.size & 0xFF;
|
4378 | }
|
4379 |
|
4380 | return box(types.trun, bytes);
|
4381 | };
|
4382 |
|
4383 | trun$1 = function trun(track, offset) {
|
4384 | if (track.type === 'audio') {
|
4385 | return audioTrun(track, offset);
|
4386 | }
|
4387 |
|
4388 | return videoTrun(track, offset);
|
4389 | };
|
4390 | })();
|
4391 |
|
4392 | var mp4Generator = {
|
4393 | ftyp: ftyp,
|
4394 | mdat: mdat,
|
4395 | moof: moof,
|
4396 | moov: moov,
|
4397 | initSegment: function initSegment(tracks) {
|
4398 | var fileType = ftyp(),
|
4399 | movie = moov(tracks),
|
4400 | result;
|
4401 | result = new Uint8Array(fileType.byteLength + movie.byteLength);
|
4402 | result.set(fileType);
|
4403 | result.set(movie, fileType.byteLength);
|
4404 | return result;
|
4405 | }
|
4406 | };
|
4407 | |
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 |
|
4414 |
|
4415 |
|
4416 |
|
4417 |
|
4418 | var groupNalsIntoFrames = function groupNalsIntoFrames(nalUnits) {
|
4419 | var i,
|
4420 | currentNal,
|
4421 | currentFrame = [],
|
4422 | frames = [];
|
4423 |
|
4424 | frames.byteLength = 0;
|
4425 | frames.nalCount = 0;
|
4426 | frames.duration = 0;
|
4427 | currentFrame.byteLength = 0;
|
4428 |
|
4429 | for (i = 0; i < nalUnits.length; i++) {
|
4430 | currentNal = nalUnits[i];
|
4431 |
|
4432 | if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
|
4433 |
|
4434 |
|
4435 | if (currentFrame.length) {
|
4436 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
4437 |
|
4438 | frames.byteLength += currentFrame.byteLength;
|
4439 | frames.nalCount += currentFrame.length;
|
4440 | frames.duration += currentFrame.duration;
|
4441 | frames.push(currentFrame);
|
4442 | }
|
4443 |
|
4444 | currentFrame = [currentNal];
|
4445 | currentFrame.byteLength = currentNal.data.byteLength;
|
4446 | currentFrame.pts = currentNal.pts;
|
4447 | currentFrame.dts = currentNal.dts;
|
4448 | } else {
|
4449 |
|
4450 | if (currentNal.nalUnitType === 'slice_layer_without_partitioning_rbsp_idr') {
|
4451 | currentFrame.keyFrame = true;
|
4452 | }
|
4453 |
|
4454 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
4455 | currentFrame.byteLength += currentNal.data.byteLength;
|
4456 | currentFrame.push(currentNal);
|
4457 | }
|
4458 | }
|
4459 |
|
4460 |
|
4461 |
|
4462 | if (frames.length && (!currentFrame.duration || currentFrame.duration <= 0)) {
|
4463 | currentFrame.duration = frames[frames.length - 1].duration;
|
4464 | }
|
4465 |
|
4466 |
|
4467 |
|
4468 | frames.byteLength += currentFrame.byteLength;
|
4469 | frames.nalCount += currentFrame.length;
|
4470 | frames.duration += currentFrame.duration;
|
4471 | frames.push(currentFrame);
|
4472 | return frames;
|
4473 | };
|
4474 |
|
4475 |
|
4476 |
|
4477 |
|
4478 |
|
4479 | var groupFramesIntoGops = function groupFramesIntoGops(frames) {
|
4480 | var i,
|
4481 | currentFrame,
|
4482 | currentGop = [],
|
4483 | gops = [];
|
4484 |
|
4485 |
|
4486 | currentGop.byteLength = 0;
|
4487 | currentGop.nalCount = 0;
|
4488 | currentGop.duration = 0;
|
4489 | currentGop.pts = frames[0].pts;
|
4490 | currentGop.dts = frames[0].dts;
|
4491 |
|
4492 | gops.byteLength = 0;
|
4493 | gops.nalCount = 0;
|
4494 | gops.duration = 0;
|
4495 | gops.pts = frames[0].pts;
|
4496 | gops.dts = frames[0].dts;
|
4497 |
|
4498 | for (i = 0; i < frames.length; i++) {
|
4499 | currentFrame = frames[i];
|
4500 |
|
4501 | if (currentFrame.keyFrame) {
|
4502 |
|
4503 |
|
4504 | if (currentGop.length) {
|
4505 | gops.push(currentGop);
|
4506 | gops.byteLength += currentGop.byteLength;
|
4507 | gops.nalCount += currentGop.nalCount;
|
4508 | gops.duration += currentGop.duration;
|
4509 | }
|
4510 |
|
4511 | currentGop = [currentFrame];
|
4512 | currentGop.nalCount = currentFrame.length;
|
4513 | currentGop.byteLength = currentFrame.byteLength;
|
4514 | currentGop.pts = currentFrame.pts;
|
4515 | currentGop.dts = currentFrame.dts;
|
4516 | currentGop.duration = currentFrame.duration;
|
4517 | } else {
|
4518 | currentGop.duration += currentFrame.duration;
|
4519 | currentGop.nalCount += currentFrame.length;
|
4520 | currentGop.byteLength += currentFrame.byteLength;
|
4521 | currentGop.push(currentFrame);
|
4522 | }
|
4523 | }
|
4524 |
|
4525 | if (gops.length && currentGop.duration <= 0) {
|
4526 | currentGop.duration = gops[gops.length - 1].duration;
|
4527 | }
|
4528 |
|
4529 | gops.byteLength += currentGop.byteLength;
|
4530 | gops.nalCount += currentGop.nalCount;
|
4531 | gops.duration += currentGop.duration;
|
4532 |
|
4533 | gops.push(currentGop);
|
4534 | return gops;
|
4535 | };
|
4536 | |
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 |
|
4544 |
|
4545 |
|
4546 |
|
4547 | var extendFirstKeyFrame = function extendFirstKeyFrame(gops) {
|
4548 | var currentGop;
|
4549 |
|
4550 | if (!gops[0][0].keyFrame && gops.length > 1) {
|
4551 |
|
4552 | currentGop = gops.shift();
|
4553 | gops.byteLength -= currentGop.byteLength;
|
4554 | gops.nalCount -= currentGop.nalCount;
|
4555 |
|
4556 |
|
4557 |
|
4558 | gops[0][0].dts = currentGop.dts;
|
4559 | gops[0][0].pts = currentGop.pts;
|
4560 | gops[0][0].duration += currentGop.duration;
|
4561 | }
|
4562 |
|
4563 | return gops;
|
4564 | };
|
4565 | |
4566 |
|
4567 |
|
4568 |
|
4569 |
|
4570 |
|
4571 | var createDefaultSample = function createDefaultSample() {
|
4572 | return {
|
4573 | size: 0,
|
4574 | flags: {
|
4575 | isLeading: 0,
|
4576 | dependsOn: 1,
|
4577 | isDependedOn: 0,
|
4578 | hasRedundancy: 0,
|
4579 | degradationPriority: 0,
|
4580 | isNonSyncSample: 1
|
4581 | }
|
4582 | };
|
4583 | };
|
4584 | |
4585 |
|
4586 |
|
4587 |
|
4588 |
|
4589 |
|
4590 |
|
4591 |
|
4592 |
|
4593 |
|
4594 | var sampleForFrame = function sampleForFrame(frame, dataOffset) {
|
4595 | var sample = createDefaultSample();
|
4596 | sample.dataOffset = dataOffset;
|
4597 | sample.compositionTimeOffset = frame.pts - frame.dts;
|
4598 | sample.duration = frame.duration;
|
4599 | sample.size = 4 * frame.length;
|
4600 |
|
4601 | sample.size += frame.byteLength;
|
4602 |
|
4603 | if (frame.keyFrame) {
|
4604 | sample.flags.dependsOn = 2;
|
4605 | sample.flags.isNonSyncSample = 0;
|
4606 | }
|
4607 |
|
4608 | return sample;
|
4609 | };
|
4610 |
|
4611 |
|
4612 | var generateSampleTable$1 = function generateSampleTable(gops, baseDataOffset) {
|
4613 | var h,
|
4614 | i,
|
4615 | sample,
|
4616 | currentGop,
|
4617 | currentFrame,
|
4618 | dataOffset = baseDataOffset || 0,
|
4619 | samples = [];
|
4620 |
|
4621 | for (h = 0; h < gops.length; h++) {
|
4622 | currentGop = gops[h];
|
4623 |
|
4624 | for (i = 0; i < currentGop.length; i++) {
|
4625 | currentFrame = currentGop[i];
|
4626 | sample = sampleForFrame(currentFrame, dataOffset);
|
4627 | dataOffset += sample.size;
|
4628 | samples.push(sample);
|
4629 | }
|
4630 | }
|
4631 |
|
4632 | return samples;
|
4633 | };
|
4634 |
|
4635 |
|
4636 | var concatenateNalData = function concatenateNalData(gops) {
|
4637 | var h,
|
4638 | i,
|
4639 | j,
|
4640 | currentGop,
|
4641 | currentFrame,
|
4642 | currentNal,
|
4643 | dataOffset = 0,
|
4644 | nalsByteLength = gops.byteLength,
|
4645 | numberOfNals = gops.nalCount,
|
4646 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
4647 | data = new Uint8Array(totalByteLength),
|
4648 | view = new DataView(data.buffer);
|
4649 |
|
4650 | for (h = 0; h < gops.length; h++) {
|
4651 | currentGop = gops[h];
|
4652 |
|
4653 | for (i = 0; i < currentGop.length; i++) {
|
4654 | currentFrame = currentGop[i];
|
4655 |
|
4656 | for (j = 0; j < currentFrame.length; j++) {
|
4657 | currentNal = currentFrame[j];
|
4658 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
4659 | dataOffset += 4;
|
4660 | data.set(currentNal.data, dataOffset);
|
4661 | dataOffset += currentNal.data.byteLength;
|
4662 | }
|
4663 | }
|
4664 | }
|
4665 |
|
4666 | return data;
|
4667 | };
|
4668 |
|
4669 |
|
4670 | var generateSampleTableForFrame = function generateSampleTableForFrame(frame, baseDataOffset) {
|
4671 | var sample,
|
4672 | dataOffset = baseDataOffset || 0,
|
4673 | samples = [];
|
4674 | sample = sampleForFrame(frame, dataOffset);
|
4675 | samples.push(sample);
|
4676 | return samples;
|
4677 | };
|
4678 |
|
4679 |
|
4680 | var concatenateNalDataForFrame = function concatenateNalDataForFrame(frame) {
|
4681 | var i,
|
4682 | currentNal,
|
4683 | dataOffset = 0,
|
4684 | nalsByteLength = frame.byteLength,
|
4685 | numberOfNals = frame.length,
|
4686 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
4687 | data = new Uint8Array(totalByteLength),
|
4688 | view = new DataView(data.buffer);
|
4689 |
|
4690 | for (i = 0; i < frame.length; i++) {
|
4691 | currentNal = frame[i];
|
4692 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
4693 | dataOffset += 4;
|
4694 | data.set(currentNal.data, dataOffset);
|
4695 | dataOffset += currentNal.data.byteLength;
|
4696 | }
|
4697 |
|
4698 | return data;
|
4699 | };
|
4700 |
|
4701 | var frameUtils = {
|
4702 | groupNalsIntoFrames: groupNalsIntoFrames,
|
4703 | groupFramesIntoGops: groupFramesIntoGops,
|
4704 | extendFirstKeyFrame: extendFirstKeyFrame,
|
4705 | generateSampleTable: generateSampleTable$1,
|
4706 | concatenateNalData: concatenateNalData,
|
4707 | generateSampleTableForFrame: generateSampleTableForFrame,
|
4708 | concatenateNalDataForFrame: concatenateNalDataForFrame
|
4709 | };
|
4710 | |
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 | var highPrefix = [33, 16, 5, 32, 164, 27];
|
4718 | var lowPrefix = [33, 65, 108, 84, 1, 2, 4, 8, 168, 2, 4, 8, 17, 191, 252];
|
4719 |
|
4720 | var zeroFill = function zeroFill(count) {
|
4721 | var a = [];
|
4722 |
|
4723 | while (count--) {
|
4724 | a.push(0);
|
4725 | }
|
4726 |
|
4727 | return a;
|
4728 | };
|
4729 |
|
4730 | var makeTable = function makeTable(metaTable) {
|
4731 | return Object.keys(metaTable).reduce(function (obj, key) {
|
4732 | obj[key] = new Uint8Array(metaTable[key].reduce(function (arr, part) {
|
4733 | return arr.concat(part);
|
4734 | }, []));
|
4735 | return obj;
|
4736 | }, {});
|
4737 | };
|
4738 |
|
4739 | var silence;
|
4740 |
|
4741 | var silence_1 = function silence_1() {
|
4742 | if (!silence) {
|
4743 |
|
4744 | var coneOfSilence = {
|
4745 | 96000: [highPrefix, [227, 64], zeroFill(154), [56]],
|
4746 | 88200: [highPrefix, [231], zeroFill(170), [56]],
|
4747 | 64000: [highPrefix, [248, 192], zeroFill(240), [56]],
|
4748 | 48000: [highPrefix, [255, 192], zeroFill(268), [55, 148, 128], zeroFill(54), [112]],
|
4749 | 44100: [highPrefix, [255, 192], zeroFill(268), [55, 163, 128], zeroFill(84), [112]],
|
4750 | 32000: [highPrefix, [255, 192], zeroFill(268), [55, 234], zeroFill(226), [112]],
|
4751 | 24000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 112], zeroFill(126), [224]],
|
4752 | 16000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 255], zeroFill(269), [223, 108], zeroFill(195), [1, 192]],
|
4753 | 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]],
|
4754 | 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]],
|
4755 | 8000: [lowPrefix, zeroFill(268), [3, 121, 16], zeroFill(47), [7]]
|
4756 | };
|
4757 | silence = makeTable(coneOfSilence);
|
4758 | }
|
4759 |
|
4760 | return silence;
|
4761 | };
|
4762 | |
4763 |
|
4764 |
|
4765 |
|
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 | var ONE_SECOND_IN_TS$4 = 90000,
|
4771 |
|
4772 | secondsToVideoTs,
|
4773 | secondsToAudioTs,
|
4774 | videoTsToSeconds,
|
4775 | audioTsToSeconds,
|
4776 | audioTsToVideoTs,
|
4777 | videoTsToAudioTs,
|
4778 | metadataTsToSeconds;
|
4779 |
|
4780 | secondsToVideoTs = function secondsToVideoTs(seconds) {
|
4781 | return seconds * ONE_SECOND_IN_TS$4;
|
4782 | };
|
4783 |
|
4784 | secondsToAudioTs = function secondsToAudioTs(seconds, sampleRate) {
|
4785 | return seconds * sampleRate;
|
4786 | };
|
4787 |
|
4788 | videoTsToSeconds = function videoTsToSeconds(timestamp) {
|
4789 | return timestamp / ONE_SECOND_IN_TS$4;
|
4790 | };
|
4791 |
|
4792 | audioTsToSeconds = function audioTsToSeconds(timestamp, sampleRate) {
|
4793 | return timestamp / sampleRate;
|
4794 | };
|
4795 |
|
4796 | audioTsToVideoTs = function audioTsToVideoTs(timestamp, sampleRate) {
|
4797 | return secondsToVideoTs(audioTsToSeconds(timestamp, sampleRate));
|
4798 | };
|
4799 |
|
4800 | videoTsToAudioTs = function videoTsToAudioTs(timestamp, sampleRate) {
|
4801 | return secondsToAudioTs(videoTsToSeconds(timestamp), sampleRate);
|
4802 | };
|
4803 | |
4804 |
|
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 | metadataTsToSeconds = function metadataTsToSeconds(timestamp, timelineStartPts, keepOriginalTimestamps) {
|
4810 | return videoTsToSeconds(keepOriginalTimestamps ? timestamp : timestamp - timelineStartPts);
|
4811 | };
|
4812 |
|
4813 | var clock = {
|
4814 | ONE_SECOND_IN_TS: ONE_SECOND_IN_TS$4,
|
4815 | secondsToVideoTs: secondsToVideoTs,
|
4816 | secondsToAudioTs: secondsToAudioTs,
|
4817 | videoTsToSeconds: videoTsToSeconds,
|
4818 | audioTsToSeconds: audioTsToSeconds,
|
4819 | audioTsToVideoTs: audioTsToVideoTs,
|
4820 | videoTsToAudioTs: videoTsToAudioTs,
|
4821 | metadataTsToSeconds: metadataTsToSeconds
|
4822 | };
|
4823 | |
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 | |
4831 |
|
4832 |
|
4833 |
|
4834 | var sumFrameByteLengths = function sumFrameByteLengths(array) {
|
4835 | var i,
|
4836 | currentObj,
|
4837 | sum = 0;
|
4838 |
|
4839 | for (i = 0; i < array.length; i++) {
|
4840 | currentObj = array[i];
|
4841 | sum += currentObj.data.byteLength;
|
4842 | }
|
4843 |
|
4844 | return sum;
|
4845 | };
|
4846 |
|
4847 |
|
4848 |
|
4849 | var prefixWithSilence = function prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime) {
|
4850 | var baseMediaDecodeTimeTs,
|
4851 | frameDuration = 0,
|
4852 | audioGapDuration = 0,
|
4853 | audioFillFrameCount = 0,
|
4854 | audioFillDuration = 0,
|
4855 | silentFrame,
|
4856 | i,
|
4857 | firstFrame;
|
4858 |
|
4859 | if (!frames.length) {
|
4860 | return;
|
4861 | }
|
4862 |
|
4863 | baseMediaDecodeTimeTs = clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate);
|
4864 |
|
4865 | frameDuration = Math.ceil(clock.ONE_SECOND_IN_TS / (track.samplerate / 1024));
|
4866 |
|
4867 | if (audioAppendStartTs && videoBaseMediaDecodeTime) {
|
4868 |
|
4869 | audioGapDuration = baseMediaDecodeTimeTs - Math.max(audioAppendStartTs, videoBaseMediaDecodeTime);
|
4870 |
|
4871 | audioFillFrameCount = Math.floor(audioGapDuration / frameDuration);
|
4872 | audioFillDuration = audioFillFrameCount * frameDuration;
|
4873 | }
|
4874 |
|
4875 |
|
4876 |
|
4877 | if (audioFillFrameCount < 1 || audioFillDuration > clock.ONE_SECOND_IN_TS / 2) {
|
4878 | return;
|
4879 | }
|
4880 |
|
4881 | silentFrame = silence_1()[track.samplerate];
|
4882 |
|
4883 | if (!silentFrame) {
|
4884 |
|
4885 |
|
4886 | silentFrame = frames[0].data;
|
4887 | }
|
4888 |
|
4889 | for (i = 0; i < audioFillFrameCount; i++) {
|
4890 | firstFrame = frames[0];
|
4891 | frames.splice(0, 0, {
|
4892 | data: silentFrame,
|
4893 | dts: firstFrame.dts - frameDuration,
|
4894 | pts: firstFrame.pts - frameDuration
|
4895 | });
|
4896 | }
|
4897 |
|
4898 | track.baseMediaDecodeTime -= Math.floor(clock.videoTsToAudioTs(audioFillDuration, track.samplerate));
|
4899 | return audioFillDuration;
|
4900 | };
|
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 | var trimAdtsFramesByEarliestDts = function trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts) {
|
4907 | if (track.minSegmentDts >= earliestAllowedDts) {
|
4908 | return adtsFrames;
|
4909 | }
|
4910 |
|
4911 |
|
4912 | track.minSegmentDts = Infinity;
|
4913 | return adtsFrames.filter(function (currentFrame) {
|
4914 |
|
4915 | if (currentFrame.dts >= earliestAllowedDts) {
|
4916 | track.minSegmentDts = Math.min(track.minSegmentDts, currentFrame.dts);
|
4917 | track.minSegmentPts = track.minSegmentDts;
|
4918 | return true;
|
4919 | }
|
4920 |
|
4921 |
|
4922 | return false;
|
4923 | });
|
4924 | };
|
4925 |
|
4926 |
|
4927 | var generateSampleTable = function generateSampleTable(frames) {
|
4928 | var i,
|
4929 | currentFrame,
|
4930 | samples = [];
|
4931 |
|
4932 | for (i = 0; i < frames.length; i++) {
|
4933 | currentFrame = frames[i];
|
4934 | samples.push({
|
4935 | size: currentFrame.data.byteLength,
|
4936 | duration: 1024
|
4937 |
|
4938 | });
|
4939 | }
|
4940 |
|
4941 | return samples;
|
4942 | };
|
4943 |
|
4944 |
|
4945 | var concatenateFrameData = function concatenateFrameData(frames) {
|
4946 | var i,
|
4947 | currentFrame,
|
4948 | dataOffset = 0,
|
4949 | data = new Uint8Array(sumFrameByteLengths(frames));
|
4950 |
|
4951 | for (i = 0; i < frames.length; i++) {
|
4952 | currentFrame = frames[i];
|
4953 | data.set(currentFrame.data, dataOffset);
|
4954 | dataOffset += currentFrame.data.byteLength;
|
4955 | }
|
4956 |
|
4957 | return data;
|
4958 | };
|
4959 |
|
4960 | var audioFrameUtils = {
|
4961 | prefixWithSilence: prefixWithSilence,
|
4962 | trimAdtsFramesByEarliestDts: trimAdtsFramesByEarliestDts,
|
4963 | generateSampleTable: generateSampleTable,
|
4964 | concatenateFrameData: concatenateFrameData
|
4965 | };
|
4966 | |
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 | var ONE_SECOND_IN_TS$3 = clock.ONE_SECOND_IN_TS;
|
4974 | |
4975 |
|
4976 |
|
4977 |
|
4978 |
|
4979 |
|
4980 | var collectDtsInfo = function collectDtsInfo(track, data) {
|
4981 | if (typeof data.pts === 'number') {
|
4982 | if (track.timelineStartInfo.pts === undefined) {
|
4983 | track.timelineStartInfo.pts = data.pts;
|
4984 | }
|
4985 |
|
4986 | if (track.minSegmentPts === undefined) {
|
4987 | track.minSegmentPts = data.pts;
|
4988 | } else {
|
4989 | track.minSegmentPts = Math.min(track.minSegmentPts, data.pts);
|
4990 | }
|
4991 |
|
4992 | if (track.maxSegmentPts === undefined) {
|
4993 | track.maxSegmentPts = data.pts;
|
4994 | } else {
|
4995 | track.maxSegmentPts = Math.max(track.maxSegmentPts, data.pts);
|
4996 | }
|
4997 | }
|
4998 |
|
4999 | if (typeof data.dts === 'number') {
|
5000 | if (track.timelineStartInfo.dts === undefined) {
|
5001 | track.timelineStartInfo.dts = data.dts;
|
5002 | }
|
5003 |
|
5004 | if (track.minSegmentDts === undefined) {
|
5005 | track.minSegmentDts = data.dts;
|
5006 | } else {
|
5007 | track.minSegmentDts = Math.min(track.minSegmentDts, data.dts);
|
5008 | }
|
5009 |
|
5010 | if (track.maxSegmentDts === undefined) {
|
5011 | track.maxSegmentDts = data.dts;
|
5012 | } else {
|
5013 | track.maxSegmentDts = Math.max(track.maxSegmentDts, data.dts);
|
5014 | }
|
5015 | }
|
5016 | };
|
5017 | |
5018 |
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 | var clearDtsInfo = function clearDtsInfo(track) {
|
5024 | delete track.minSegmentDts;
|
5025 | delete track.maxSegmentDts;
|
5026 | delete track.minSegmentPts;
|
5027 | delete track.maxSegmentPts;
|
5028 | };
|
5029 | |
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 | var calculateTrackBaseMediaDecodeTime = function calculateTrackBaseMediaDecodeTime(track, keepOriginalTimestamps) {
|
5040 | var baseMediaDecodeTime,
|
5041 | scale,
|
5042 | minSegmentDts = track.minSegmentDts;
|
5043 |
|
5044 | if (!keepOriginalTimestamps) {
|
5045 | minSegmentDts -= track.timelineStartInfo.dts;
|
5046 | }
|
5047 |
|
5048 |
|
5049 |
|
5050 | baseMediaDecodeTime = track.timelineStartInfo.baseMediaDecodeTime;
|
5051 |
|
5052 | baseMediaDecodeTime += minSegmentDts;
|
5053 |
|
5054 | baseMediaDecodeTime = Math.max(0, baseMediaDecodeTime);
|
5055 |
|
5056 | if (track.type === 'audio') {
|
5057 |
|
5058 |
|
5059 | scale = track.samplerate / ONE_SECOND_IN_TS$3;
|
5060 | baseMediaDecodeTime *= scale;
|
5061 | baseMediaDecodeTime = Math.floor(baseMediaDecodeTime);
|
5062 | }
|
5063 |
|
5064 | return baseMediaDecodeTime;
|
5065 | };
|
5066 |
|
5067 | var trackDecodeInfo = {
|
5068 | clearDtsInfo: clearDtsInfo,
|
5069 | calculateTrackBaseMediaDecodeTime: calculateTrackBaseMediaDecodeTime,
|
5070 | collectDtsInfo: collectDtsInfo
|
5071 | };
|
5072 | |
5073 |
|
5074 |
|
5075 |
|
5076 |
|
5077 |
|
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 |
|
5083 |
|
5084 |
|
5085 |
|
5086 |
|
5087 |
|
5088 | var USER_DATA_REGISTERED_ITU_T_T35 = 4,
|
5089 | RBSP_TRAILING_BITS = 128;
|
5090 | |
5091 |
|
5092 |
|
5093 |
|
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 |
|
5099 | var parseSei = function parseSei(bytes) {
|
5100 | var i = 0,
|
5101 | result = {
|
5102 | payloadType: -1,
|
5103 | payloadSize: 0
|
5104 | },
|
5105 | payloadType = 0,
|
5106 | payloadSize = 0;
|
5107 |
|
5108 | while (i < bytes.byteLength) {
|
5109 |
|
5110 | if (bytes[i] === RBSP_TRAILING_BITS) {
|
5111 | break;
|
5112 | }
|
5113 |
|
5114 |
|
5115 | while (bytes[i] === 0xFF) {
|
5116 | payloadType += 255;
|
5117 | i++;
|
5118 | }
|
5119 |
|
5120 | payloadType += bytes[i++];
|
5121 |
|
5122 | while (bytes[i] === 0xFF) {
|
5123 | payloadSize += 255;
|
5124 | i++;
|
5125 | }
|
5126 |
|
5127 | payloadSize += bytes[i++];
|
5128 |
|
5129 |
|
5130 | if (!result.payload && payloadType === USER_DATA_REGISTERED_ITU_T_T35) {
|
5131 | var userIdentifier = String.fromCharCode(bytes[i + 3], bytes[i + 4], bytes[i + 5], bytes[i + 6]);
|
5132 |
|
5133 | if (userIdentifier === 'GA94') {
|
5134 | result.payloadType = payloadType;
|
5135 | result.payloadSize = payloadSize;
|
5136 | result.payload = bytes.subarray(i, i + payloadSize);
|
5137 | break;
|
5138 | } else {
|
5139 | result.payload = void 0;
|
5140 | }
|
5141 | }
|
5142 |
|
5143 |
|
5144 | i += payloadSize;
|
5145 | payloadType = 0;
|
5146 | payloadSize = 0;
|
5147 | }
|
5148 |
|
5149 | return result;
|
5150 | };
|
5151 |
|
5152 |
|
5153 | var parseUserData = function parseUserData(sei) {
|
5154 |
|
5155 |
|
5156 | if (sei.payload[0] !== 181) {
|
5157 | return null;
|
5158 | }
|
5159 |
|
5160 |
|
5161 | if ((sei.payload[1] << 8 | sei.payload[2]) !== 49) {
|
5162 | return null;
|
5163 | }
|
5164 |
|
5165 |
|
5166 | if (String.fromCharCode(sei.payload[3], sei.payload[4], sei.payload[5], sei.payload[6]) !== 'GA94') {
|
5167 | return null;
|
5168 | }
|
5169 |
|
5170 |
|
5171 | if (sei.payload[7] !== 0x03) {
|
5172 | return null;
|
5173 | }
|
5174 |
|
5175 |
|
5176 |
|
5177 | return sei.payload.subarray(8, sei.payload.length - 1);
|
5178 | };
|
5179 |
|
5180 |
|
5181 | var parseCaptionPackets = function parseCaptionPackets(pts, userData) {
|
5182 | var results = [],
|
5183 | i,
|
5184 | count,
|
5185 | offset,
|
5186 | data;
|
5187 |
|
5188 | if (!(userData[0] & 0x40)) {
|
5189 | return results;
|
5190 | }
|
5191 |
|
5192 |
|
5193 | count = userData[0] & 0x1f;
|
5194 |
|
5195 | for (i = 0; i < count; i++) {
|
5196 | offset = i * 3;
|
5197 | data = {
|
5198 | type: userData[offset + 2] & 0x03,
|
5199 | pts: pts
|
5200 | };
|
5201 |
|
5202 | if (userData[offset + 2] & 0x04) {
|
5203 | data.ccData = userData[offset + 3] << 8 | userData[offset + 4];
|
5204 | results.push(data);
|
5205 | }
|
5206 | }
|
5207 |
|
5208 | return results;
|
5209 | };
|
5210 |
|
5211 | var discardEmulationPreventionBytes$1 = function discardEmulationPreventionBytes(data) {
|
5212 | var length = data.byteLength,
|
5213 | emulationPreventionBytesPositions = [],
|
5214 | i = 1,
|
5215 | newLength,
|
5216 | newData;
|
5217 |
|
5218 | while (i < length - 2) {
|
5219 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
5220 | emulationPreventionBytesPositions.push(i + 2);
|
5221 | i += 2;
|
5222 | } else {
|
5223 | i++;
|
5224 | }
|
5225 | }
|
5226 |
|
5227 |
|
5228 |
|
5229 | if (emulationPreventionBytesPositions.length === 0) {
|
5230 | return data;
|
5231 | }
|
5232 |
|
5233 |
|
5234 | newLength = length - emulationPreventionBytesPositions.length;
|
5235 | newData = new Uint8Array(newLength);
|
5236 | var sourceIndex = 0;
|
5237 |
|
5238 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
5239 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
5240 |
|
5241 | sourceIndex++;
|
5242 |
|
5243 | emulationPreventionBytesPositions.shift();
|
5244 | }
|
5245 |
|
5246 | newData[i] = data[sourceIndex];
|
5247 | }
|
5248 |
|
5249 | return newData;
|
5250 | };
|
5251 |
|
5252 |
|
5253 | var captionPacketParser = {
|
5254 | parseSei: parseSei,
|
5255 | parseUserData: parseUserData,
|
5256 | parseCaptionPackets: parseCaptionPackets,
|
5257 | discardEmulationPreventionBytes: discardEmulationPreventionBytes$1,
|
5258 | USER_DATA_REGISTERED_ITU_T_T35: USER_DATA_REGISTERED_ITU_T_T35
|
5259 | };
|
5260 |
|
5261 |
|
5262 | var CaptionStream$1 = function CaptionStream(options) {
|
5263 | options = options || {};
|
5264 | CaptionStream.prototype.init.call(this);
|
5265 |
|
5266 | this.parse708captions_ = typeof options.parse708captions === 'boolean' ? options.parse708captions : true;
|
5267 | this.captionPackets_ = [];
|
5268 | this.ccStreams_ = [new Cea608Stream(0, 0),
|
5269 | new Cea608Stream(0, 1),
|
5270 | new Cea608Stream(1, 0),
|
5271 | new Cea608Stream(1, 1)
|
5272 | ];
|
5273 |
|
5274 | if (this.parse708captions_) {
|
5275 | this.cc708Stream_ = new Cea708Stream();
|
5276 | }
|
5277 |
|
5278 | this.reset();
|
5279 |
|
5280 | this.ccStreams_.forEach(function (cc) {
|
5281 | cc.on('data', this.trigger.bind(this, 'data'));
|
5282 | cc.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
5283 | cc.on('done', this.trigger.bind(this, 'done'));
|
5284 | }, this);
|
5285 |
|
5286 | if (this.parse708captions_) {
|
5287 | this.cc708Stream_.on('data', this.trigger.bind(this, 'data'));
|
5288 | this.cc708Stream_.on('partialdone', this.trigger.bind(this, 'partialdone'));
|
5289 | this.cc708Stream_.on('done', this.trigger.bind(this, 'done'));
|
5290 | }
|
5291 | };
|
5292 |
|
5293 | CaptionStream$1.prototype = new stream();
|
5294 |
|
5295 | CaptionStream$1.prototype.push = function (event) {
|
5296 | var sei, userData, newCaptionPackets;
|
5297 |
|
5298 | if (event.nalUnitType !== 'sei_rbsp') {
|
5299 | return;
|
5300 | }
|
5301 |
|
5302 |
|
5303 | sei = captionPacketParser.parseSei(event.escapedRBSP);
|
5304 |
|
5305 | if (!sei.payload) {
|
5306 | return;
|
5307 | }
|
5308 |
|
5309 |
|
5310 | if (sei.payloadType !== captionPacketParser.USER_DATA_REGISTERED_ITU_T_T35) {
|
5311 | return;
|
5312 | }
|
5313 |
|
5314 |
|
5315 | userData = captionPacketParser.parseUserData(sei);
|
5316 |
|
5317 | if (!userData) {
|
5318 | return;
|
5319 | }
|
5320 |
|
5321 |
|
5322 |
|
5323 |
|
5324 |
|
5325 |
|
5326 |
|
5327 |
|
5328 |
|
5329 | if (event.dts < this.latestDts_) {
|
5330 |
|
5331 | this.ignoreNextEqualDts_ = true;
|
5332 | return;
|
5333 | } else if (event.dts === this.latestDts_ && this.ignoreNextEqualDts_) {
|
5334 | this.numSameDts_--;
|
5335 |
|
5336 | if (!this.numSameDts_) {
|
5337 |
|
5338 | this.ignoreNextEqualDts_ = false;
|
5339 | }
|
5340 |
|
5341 | return;
|
5342 | }
|
5343 |
|
5344 |
|
5345 | newCaptionPackets = captionPacketParser.parseCaptionPackets(event.pts, userData);
|
5346 | this.captionPackets_ = this.captionPackets_.concat(newCaptionPackets);
|
5347 |
|
5348 | if (this.latestDts_ !== event.dts) {
|
5349 | this.numSameDts_ = 0;
|
5350 | }
|
5351 |
|
5352 | this.numSameDts_++;
|
5353 | this.latestDts_ = event.dts;
|
5354 | };
|
5355 |
|
5356 | CaptionStream$1.prototype.flushCCStreams = function (flushType) {
|
5357 | this.ccStreams_.forEach(function (cc) {
|
5358 | return flushType === 'flush' ? cc.flush() : cc.partialFlush();
|
5359 | }, this);
|
5360 | };
|
5361 |
|
5362 | CaptionStream$1.prototype.flushStream = function (flushType) {
|
5363 |
|
5364 | if (!this.captionPackets_.length) {
|
5365 | this.flushCCStreams(flushType);
|
5366 | return;
|
5367 | }
|
5368 |
|
5369 |
|
5370 |
|
5371 | this.captionPackets_.forEach(function (elem, idx) {
|
5372 | elem.presortIndex = idx;
|
5373 | });
|
5374 |
|
5375 | this.captionPackets_.sort(function (a, b) {
|
5376 | if (a.pts === b.pts) {
|
5377 | return a.presortIndex - b.presortIndex;
|
5378 | }
|
5379 |
|
5380 | return a.pts - b.pts;
|
5381 | });
|
5382 | this.captionPackets_.forEach(function (packet) {
|
5383 | if (packet.type < 2) {
|
5384 |
|
5385 | this.dispatchCea608Packet(packet);
|
5386 | } else {
|
5387 |
|
5388 | this.dispatchCea708Packet(packet);
|
5389 | }
|
5390 | }, this);
|
5391 | this.captionPackets_.length = 0;
|
5392 | this.flushCCStreams(flushType);
|
5393 | };
|
5394 |
|
5395 | CaptionStream$1.prototype.flush = function () {
|
5396 | return this.flushStream('flush');
|
5397 | };
|
5398 |
|
5399 |
|
5400 | CaptionStream$1.prototype.partialFlush = function () {
|
5401 | return this.flushStream('partialFlush');
|
5402 | };
|
5403 |
|
5404 | CaptionStream$1.prototype.reset = function () {
|
5405 | this.latestDts_ = null;
|
5406 | this.ignoreNextEqualDts_ = false;
|
5407 | this.numSameDts_ = 0;
|
5408 | this.activeCea608Channel_ = [null, null];
|
5409 | this.ccStreams_.forEach(function (ccStream) {
|
5410 | ccStream.reset();
|
5411 | });
|
5412 | };
|
5413 |
|
5414 | |
5415 |
|
5416 |
|
5417 |
|
5418 |
|
5419 |
|
5420 |
|
5421 |
|
5422 |
|
5423 |
|
5424 |
|
5425 |
|
5426 | CaptionStream$1.prototype.dispatchCea608Packet = function (packet) {
|
5427 |
|
5428 | if (this.setsTextOrXDSActive(packet)) {
|
5429 | this.activeCea608Channel_[packet.type] = null;
|
5430 | } else if (this.setsChannel1Active(packet)) {
|
5431 | this.activeCea608Channel_[packet.type] = 0;
|
5432 | } else if (this.setsChannel2Active(packet)) {
|
5433 | this.activeCea608Channel_[packet.type] = 1;
|
5434 | }
|
5435 |
|
5436 | if (this.activeCea608Channel_[packet.type] === null) {
|
5437 |
|
5438 |
|
5439 |
|
5440 | return;
|
5441 | }
|
5442 |
|
5443 | this.ccStreams_[(packet.type << 1) + this.activeCea608Channel_[packet.type]].push(packet);
|
5444 | };
|
5445 |
|
5446 | CaptionStream$1.prototype.setsChannel1Active = function (packet) {
|
5447 | return (packet.ccData & 0x7800) === 0x1000;
|
5448 | };
|
5449 |
|
5450 | CaptionStream$1.prototype.setsChannel2Active = function (packet) {
|
5451 | return (packet.ccData & 0x7800) === 0x1800;
|
5452 | };
|
5453 |
|
5454 | CaptionStream$1.prototype.setsTextOrXDSActive = function (packet) {
|
5455 | return (packet.ccData & 0x7100) === 0x0100 || (packet.ccData & 0x78fe) === 0x102a || (packet.ccData & 0x78fe) === 0x182a;
|
5456 | };
|
5457 |
|
5458 | CaptionStream$1.prototype.dispatchCea708Packet = function (packet) {
|
5459 | if (this.parse708captions_) {
|
5460 | this.cc708Stream_.push(packet);
|
5461 | }
|
5462 | };
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 |
|
5481 |
|
5482 | var CHARACTER_TRANSLATION_708 = {
|
5483 | 0x7f: 0x266a,
|
5484 |
|
5485 | 0x1020: 0x20,
|
5486 |
|
5487 | 0x1021: 0xa0,
|
5488 |
|
5489 | 0x1025: 0x2026,
|
5490 |
|
5491 | 0x102a: 0x0160,
|
5492 |
|
5493 | 0x102c: 0x0152,
|
5494 |
|
5495 | 0x1030: 0x2588,
|
5496 |
|
5497 | 0x1031: 0x2018,
|
5498 |
|
5499 | 0x1032: 0x2019,
|
5500 |
|
5501 | 0x1033: 0x201c,
|
5502 |
|
5503 | 0x1034: 0x201d,
|
5504 |
|
5505 | 0x1035: 0x2022,
|
5506 |
|
5507 | 0x1039: 0x2122,
|
5508 |
|
5509 | 0x103a: 0x0161,
|
5510 |
|
5511 | 0x103c: 0x0153,
|
5512 |
|
5513 | 0x103d: 0x2120,
|
5514 |
|
5515 | 0x103f: 0x0178,
|
5516 |
|
5517 | 0x1076: 0x215b,
|
5518 |
|
5519 | 0x1077: 0x215c,
|
5520 |
|
5521 | 0x1078: 0x215d,
|
5522 |
|
5523 | 0x1079: 0x215e,
|
5524 |
|
5525 | 0x107a: 0x23d0,
|
5526 |
|
5527 | 0x107b: 0x23a4,
|
5528 |
|
5529 | 0x107c: 0x23a3,
|
5530 |
|
5531 | 0x107d: 0x23af,
|
5532 |
|
5533 | 0x107e: 0x23a6,
|
5534 |
|
5535 | 0x107f: 0x23a1,
|
5536 |
|
5537 | 0x10a0: 0x3138
|
5538 |
|
5539 | };
|
5540 |
|
5541 | var get708CharFromCode = function get708CharFromCode(code) {
|
5542 | var newCode = CHARACTER_TRANSLATION_708[code] || code;
|
5543 |
|
5544 | if (code & 0x1000 && code === newCode) {
|
5545 |
|
5546 | return '';
|
5547 | }
|
5548 |
|
5549 | return String.fromCharCode(newCode);
|
5550 | };
|
5551 |
|
5552 | var within708TextBlock = function within708TextBlock(b) {
|
5553 | return 0x20 <= b && b <= 0x7f || 0xa0 <= b && b <= 0xff;
|
5554 | };
|
5555 |
|
5556 | var Cea708Window = function Cea708Window(windowNum) {
|
5557 | this.windowNum = windowNum;
|
5558 | this.reset();
|
5559 | };
|
5560 |
|
5561 | Cea708Window.prototype.reset = function () {
|
5562 | this.clearText();
|
5563 | this.pendingNewLine = false;
|
5564 | this.winAttr = {};
|
5565 | this.penAttr = {};
|
5566 | this.penLoc = {};
|
5567 | this.penColor = {};
|
5568 |
|
5569 |
|
5570 | this.visible = 0;
|
5571 | this.rowLock = 0;
|
5572 | this.columnLock = 0;
|
5573 | this.priority = 0;
|
5574 | this.relativePositioning = 0;
|
5575 | this.anchorVertical = 0;
|
5576 | this.anchorHorizontal = 0;
|
5577 | this.anchorPoint = 0;
|
5578 | this.rowCount = 1;
|
5579 | this.virtualRowCount = this.rowCount + 1;
|
5580 | this.columnCount = 41;
|
5581 | this.windowStyle = 0;
|
5582 | this.penStyle = 0;
|
5583 | };
|
5584 |
|
5585 | Cea708Window.prototype.getText = function () {
|
5586 | return this.rows.join('\n');
|
5587 | };
|
5588 |
|
5589 | Cea708Window.prototype.clearText = function () {
|
5590 | this.rows = [''];
|
5591 | this.rowIdx = 0;
|
5592 | };
|
5593 |
|
5594 | Cea708Window.prototype.newLine = function (pts) {
|
5595 | if (this.rows.length >= this.virtualRowCount && typeof this.beforeRowOverflow === 'function') {
|
5596 | this.beforeRowOverflow(pts);
|
5597 | }
|
5598 |
|
5599 | if (this.rows.length > 0) {
|
5600 | this.rows.push('');
|
5601 | this.rowIdx++;
|
5602 | }
|
5603 |
|
5604 |
|
5605 | while (this.rows.length > this.virtualRowCount) {
|
5606 | this.rows.shift();
|
5607 | this.rowIdx--;
|
5608 | }
|
5609 | };
|
5610 |
|
5611 | Cea708Window.prototype.isEmpty = function () {
|
5612 | if (this.rows.length === 0) {
|
5613 | return true;
|
5614 | } else if (this.rows.length === 1) {
|
5615 | return this.rows[0] === '';
|
5616 | }
|
5617 |
|
5618 | return false;
|
5619 | };
|
5620 |
|
5621 | Cea708Window.prototype.addText = function (text) {
|
5622 | this.rows[this.rowIdx] += text;
|
5623 | };
|
5624 |
|
5625 | Cea708Window.prototype.backspace = function () {
|
5626 | if (!this.isEmpty()) {
|
5627 | var row = this.rows[this.rowIdx];
|
5628 | this.rows[this.rowIdx] = row.substr(0, row.length - 1);
|
5629 | }
|
5630 | };
|
5631 |
|
5632 | var Cea708Service = function Cea708Service(serviceNum) {
|
5633 | this.serviceNum = serviceNum;
|
5634 | this.text = '';
|
5635 | this.currentWindow = new Cea708Window(-1);
|
5636 | this.windows = [];
|
5637 | };
|
5638 | |
5639 |
|
5640 |
|
5641 |
|
5642 |
|
5643 |
|
5644 |
|
5645 |
|
5646 |
|
5647 | Cea708Service.prototype.init = function (pts, beforeRowOverflow) {
|
5648 | this.startPts = pts;
|
5649 |
|
5650 | for (var win = 0; win < 8; win++) {
|
5651 | this.windows[win] = new Cea708Window(win);
|
5652 |
|
5653 | if (typeof beforeRowOverflow === 'function') {
|
5654 | this.windows[win].beforeRowOverflow = beforeRowOverflow;
|
5655 | }
|
5656 | }
|
5657 | };
|
5658 | |
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 | Cea708Service.prototype.setCurrentWindow = function (windowNum) {
|
5666 | this.currentWindow = this.windows[windowNum];
|
5667 | };
|
5668 |
|
5669 | var Cea708Stream = function Cea708Stream() {
|
5670 | Cea708Stream.prototype.init.call(this);
|
5671 | var self = this;
|
5672 | this.current708Packet = null;
|
5673 | this.services = {};
|
5674 |
|
5675 | this.push = function (packet) {
|
5676 | if (packet.type === 3) {
|
5677 |
|
5678 | self.new708Packet();
|
5679 | self.add708Bytes(packet);
|
5680 | } else {
|
5681 | if (self.current708Packet === null) {
|
5682 |
|
5683 | self.new708Packet();
|
5684 | }
|
5685 |
|
5686 | self.add708Bytes(packet);
|
5687 | }
|
5688 | };
|
5689 | };
|
5690 |
|
5691 | Cea708Stream.prototype = new stream();
|
5692 | |
5693 |
|
5694 |
|
5695 |
|
5696 | Cea708Stream.prototype.new708Packet = function () {
|
5697 | if (this.current708Packet !== null) {
|
5698 | this.push708Packet();
|
5699 | }
|
5700 |
|
5701 | this.current708Packet = {
|
5702 | data: [],
|
5703 | ptsVals: []
|
5704 | };
|
5705 | };
|
5706 | |
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 | Cea708Stream.prototype.add708Bytes = function (packet) {
|
5712 | var data = packet.ccData;
|
5713 | var byte0 = data >>> 8;
|
5714 | var byte1 = data & 0xff;
|
5715 |
|
5716 |
|
5717 | this.current708Packet.ptsVals.push(packet.pts);
|
5718 | this.current708Packet.data.push(byte0);
|
5719 | this.current708Packet.data.push(byte1);
|
5720 | };
|
5721 | |
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 | Cea708Stream.prototype.push708Packet = function () {
|
5727 | var packet708 = this.current708Packet;
|
5728 | var packetData = packet708.data;
|
5729 | var serviceNum = null;
|
5730 | var blockSize = null;
|
5731 | var i = 0;
|
5732 | var b = packetData[i++];
|
5733 | packet708.seq = b >> 6;
|
5734 | packet708.sizeCode = b & 0x3f;
|
5735 |
|
5736 | for (; i < packetData.length; i++) {
|
5737 | b = packetData[i++];
|
5738 | serviceNum = b >> 5;
|
5739 | blockSize = b & 0x1f;
|
5740 |
|
5741 | if (serviceNum === 7 && blockSize > 0) {
|
5742 |
|
5743 | b = packetData[i++];
|
5744 | serviceNum = b;
|
5745 | }
|
5746 |
|
5747 | this.pushServiceBlock(serviceNum, i, blockSize);
|
5748 |
|
5749 | if (blockSize > 0) {
|
5750 | i += blockSize - 1;
|
5751 | }
|
5752 | }
|
5753 | };
|
5754 | |
5755 |
|
5756 |
|
5757 |
|
5758 |
|
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 |
|
5764 |
|
5765 |
|
5766 |
|
5767 |
|
5768 | Cea708Stream.prototype.pushServiceBlock = function (serviceNum, start, size) {
|
5769 | var b;
|
5770 | var i = start;
|
5771 | var packetData = this.current708Packet.data;
|
5772 | var service = this.services[serviceNum];
|
5773 |
|
5774 | if (!service) {
|
5775 | service = this.initService(serviceNum, i);
|
5776 | }
|
5777 |
|
5778 | for (; i < start + size && i < packetData.length; i++) {
|
5779 | b = packetData[i];
|
5780 |
|
5781 | if (within708TextBlock(b)) {
|
5782 | i = this.handleText(i, service);
|
5783 | } else if (b === 0x10) {
|
5784 | i = this.extendedCommands(i, service);
|
5785 | } else if (0x80 <= b && b <= 0x87) {
|
5786 | i = this.setCurrentWindow(i, service);
|
5787 | } else if (0x98 <= b && b <= 0x9f) {
|
5788 | i = this.defineWindow(i, service);
|
5789 | } else if (b === 0x88) {
|
5790 | i = this.clearWindows(i, service);
|
5791 | } else if (b === 0x8c) {
|
5792 | i = this.deleteWindows(i, service);
|
5793 | } else if (b === 0x89) {
|
5794 | i = this.displayWindows(i, service);
|
5795 | } else if (b === 0x8a) {
|
5796 | i = this.hideWindows(i, service);
|
5797 | } else if (b === 0x8b) {
|
5798 | i = this.toggleWindows(i, service);
|
5799 | } else if (b === 0x97) {
|
5800 | i = this.setWindowAttributes(i, service);
|
5801 | } else if (b === 0x90) {
|
5802 | i = this.setPenAttributes(i, service);
|
5803 | } else if (b === 0x91) {
|
5804 | i = this.setPenColor(i, service);
|
5805 | } else if (b === 0x92) {
|
5806 | i = this.setPenLocation(i, service);
|
5807 | } else if (b === 0x8f) {
|
5808 | service = this.reset(i, service);
|
5809 | } else if (b === 0x08) {
|
5810 |
|
5811 | service.currentWindow.backspace();
|
5812 | } else if (b === 0x0c) {
|
5813 |
|
5814 | service.currentWindow.clearText();
|
5815 | } else if (b === 0x0d) {
|
5816 |
|
5817 | service.currentWindow.pendingNewLine = true;
|
5818 | } else if (b === 0x0e) {
|
5819 |
|
5820 | service.currentWindow.clearText();
|
5821 | } else if (b === 0x8d) {
|
5822 |
|
5823 | i++;
|
5824 | } else ;
|
5825 | }
|
5826 | };
|
5827 | |
5828 |
|
5829 |
|
5830 |
|
5831 |
|
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 | Cea708Stream.prototype.extendedCommands = function (i, service) {
|
5837 | var packetData = this.current708Packet.data;
|
5838 | var b = packetData[++i];
|
5839 |
|
5840 | if (within708TextBlock(b)) {
|
5841 | i = this.handleText(i, service, true);
|
5842 | }
|
5843 |
|
5844 | return i;
|
5845 | };
|
5846 | |
5847 |
|
5848 |
|
5849 |
|
5850 |
|
5851 |
|
5852 |
|
5853 |
|
5854 | Cea708Stream.prototype.getPts = function (byteIndex) {
|
5855 |
|
5856 | return this.current708Packet.ptsVals[Math.floor(byteIndex / 2)];
|
5857 | };
|
5858 | |
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 | Cea708Stream.prototype.initService = function (serviceNum, i) {
|
5867 | var self = this;
|
5868 | this.services[serviceNum] = new Cea708Service(serviceNum);
|
5869 | this.services[serviceNum].init(this.getPts(i), function (pts) {
|
5870 | self.flushDisplayed(pts, self.services[serviceNum]);
|
5871 | });
|
5872 | return this.services[serviceNum];
|
5873 | };
|
5874 | |
5875 |
|
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 | Cea708Stream.prototype.handleText = function (i, service, isExtended) {
|
5884 | var packetData = this.current708Packet.data;
|
5885 | var b = packetData[i];
|
5886 | var extended = isExtended ? 0x1000 : 0x0000;
|
5887 | var char = get708CharFromCode(extended | b);
|
5888 | var win = service.currentWindow;
|
5889 |
|
5890 | if (win.pendingNewLine && !win.isEmpty()) {
|
5891 | win.newLine(this.getPts(i));
|
5892 | }
|
5893 |
|
5894 | win.pendingNewLine = false;
|
5895 | win.addText(char);
|
5896 | return i;
|
5897 | };
|
5898 | |
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 |
|
5908 |
|
5909 | Cea708Stream.prototype.setCurrentWindow = function (i, service) {
|
5910 | var packetData = this.current708Packet.data;
|
5911 | var b = packetData[i];
|
5912 | var windowNum = b & 0x07;
|
5913 | service.setCurrentWindow(windowNum);
|
5914 | return i;
|
5915 | };
|
5916 | |
5917 |
|
5918 |
|
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 | Cea708Stream.prototype.defineWindow = function (i, service) {
|
5928 | var packetData = this.current708Packet.data;
|
5929 | var b = packetData[i];
|
5930 | var windowNum = b & 0x07;
|
5931 | service.setCurrentWindow(windowNum);
|
5932 | var win = service.currentWindow;
|
5933 | b = packetData[++i];
|
5934 | win.visible = (b & 0x20) >> 5;
|
5935 |
|
5936 | win.rowLock = (b & 0x10) >> 4;
|
5937 |
|
5938 | win.columnLock = (b & 0x08) >> 3;
|
5939 |
|
5940 | win.priority = b & 0x07;
|
5941 |
|
5942 | b = packetData[++i];
|
5943 | win.relativePositioning = (b & 0x80) >> 7;
|
5944 |
|
5945 | win.anchorVertical = b & 0x7f;
|
5946 |
|
5947 | b = packetData[++i];
|
5948 | win.anchorHorizontal = b;
|
5949 |
|
5950 | b = packetData[++i];
|
5951 | win.anchorPoint = (b & 0xf0) >> 4;
|
5952 |
|
5953 | win.rowCount = b & 0x0f;
|
5954 |
|
5955 | b = packetData[++i];
|
5956 | win.columnCount = b & 0x3f;
|
5957 |
|
5958 | b = packetData[++i];
|
5959 | win.windowStyle = (b & 0x38) >> 3;
|
5960 |
|
5961 | win.penStyle = b & 0x07;
|
5962 |
|
5963 |
|
5964 | win.virtualRowCount = win.rowCount + 1;
|
5965 | return i;
|
5966 | };
|
5967 | |
5968 |
|
5969 |
|
5970 |
|
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 |
|
5978 | Cea708Stream.prototype.setWindowAttributes = function (i, service) {
|
5979 | var packetData = this.current708Packet.data;
|
5980 | var b = packetData[i];
|
5981 | var winAttr = service.currentWindow.winAttr;
|
5982 | b = packetData[++i];
|
5983 | winAttr.fillOpacity = (b & 0xc0) >> 6;
|
5984 |
|
5985 | winAttr.fillRed = (b & 0x30) >> 4;
|
5986 |
|
5987 | winAttr.fillGreen = (b & 0x0c) >> 2;
|
5988 |
|
5989 | winAttr.fillBlue = b & 0x03;
|
5990 |
|
5991 | b = packetData[++i];
|
5992 | winAttr.borderType = (b & 0xc0) >> 6;
|
5993 |
|
5994 | winAttr.borderRed = (b & 0x30) >> 4;
|
5995 |
|
5996 | winAttr.borderGreen = (b & 0x0c) >> 2;
|
5997 |
|
5998 | winAttr.borderBlue = b & 0x03;
|
5999 |
|
6000 | b = packetData[++i];
|
6001 | winAttr.borderType += (b & 0x80) >> 5;
|
6002 |
|
6003 | winAttr.wordWrap = (b & 0x40) >> 6;
|
6004 |
|
6005 | winAttr.printDirection = (b & 0x30) >> 4;
|
6006 |
|
6007 | winAttr.scrollDirection = (b & 0x0c) >> 2;
|
6008 |
|
6009 | winAttr.justify = b & 0x03;
|
6010 |
|
6011 | b = packetData[++i];
|
6012 | winAttr.effectSpeed = (b & 0xf0) >> 4;
|
6013 |
|
6014 | winAttr.effectDirection = (b & 0x0c) >> 2;
|
6015 |
|
6016 | winAttr.displayEffect = b & 0x03;
|
6017 |
|
6018 | return i;
|
6019 | };
|
6020 | |
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 |
|
6028 | Cea708Stream.prototype.flushDisplayed = function (pts, service) {
|
6029 | var displayedText = [];
|
6030 |
|
6031 |
|
6032 | for (var winId = 0; winId < 8; winId++) {
|
6033 | if (service.windows[winId].visible && !service.windows[winId].isEmpty()) {
|
6034 | displayedText.push(service.windows[winId].getText());
|
6035 | }
|
6036 | }
|
6037 |
|
6038 | service.endPts = pts;
|
6039 | service.text = displayedText.join('\n\n');
|
6040 | this.pushCaption(service);
|
6041 | service.startPts = pts;
|
6042 | };
|
6043 | |
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 |
|
6049 |
|
6050 | Cea708Stream.prototype.pushCaption = function (service) {
|
6051 | if (service.text !== '') {
|
6052 | this.trigger('data', {
|
6053 | startPts: service.startPts,
|
6054 | endPts: service.endPts,
|
6055 | text: service.text,
|
6056 | stream: 'cc708_' + service.serviceNum
|
6057 | });
|
6058 | service.text = '';
|
6059 | service.startPts = service.endPts;
|
6060 | }
|
6061 | };
|
6062 | |
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 |
|
6070 |
|
6071 |
|
6072 |
|
6073 | Cea708Stream.prototype.displayWindows = function (i, service) {
|
6074 | var packetData = this.current708Packet.data;
|
6075 | var b = packetData[++i];
|
6076 | var pts = this.getPts(i);
|
6077 | this.flushDisplayed(pts, service);
|
6078 |
|
6079 | for (var winId = 0; winId < 8; winId++) {
|
6080 | if (b & 0x01 << winId) {
|
6081 | service.windows[winId].visible = 1;
|
6082 | }
|
6083 | }
|
6084 |
|
6085 | return i;
|
6086 | };
|
6087 | |
6088 |
|
6089 |
|
6090 |
|
6091 |
|
6092 |
|
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 | Cea708Stream.prototype.hideWindows = function (i, service) {
|
6099 | var packetData = this.current708Packet.data;
|
6100 | var b = packetData[++i];
|
6101 | var pts = this.getPts(i);
|
6102 | this.flushDisplayed(pts, service);
|
6103 |
|
6104 | for (var winId = 0; winId < 8; winId++) {
|
6105 | if (b & 0x01 << winId) {
|
6106 | service.windows[winId].visible = 0;
|
6107 | }
|
6108 | }
|
6109 |
|
6110 | return i;
|
6111 | };
|
6112 | |
6113 |
|
6114 |
|
6115 |
|
6116 |
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 |
|
6122 |
|
6123 | Cea708Stream.prototype.toggleWindows = function (i, service) {
|
6124 | var packetData = this.current708Packet.data;
|
6125 | var b = packetData[++i];
|
6126 | var pts = this.getPts(i);
|
6127 | this.flushDisplayed(pts, service);
|
6128 |
|
6129 | for (var winId = 0; winId < 8; winId++) {
|
6130 | if (b & 0x01 << winId) {
|
6131 | service.windows[winId].visible ^= 1;
|
6132 | }
|
6133 | }
|
6134 |
|
6135 | return i;
|
6136 | };
|
6137 | |
6138 |
|
6139 |
|
6140 |
|
6141 |
|
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 |
|
6148 | Cea708Stream.prototype.clearWindows = function (i, service) {
|
6149 | var packetData = this.current708Packet.data;
|
6150 | var b = packetData[++i];
|
6151 | var pts = this.getPts(i);
|
6152 | this.flushDisplayed(pts, service);
|
6153 |
|
6154 | for (var winId = 0; winId < 8; winId++) {
|
6155 | if (b & 0x01 << winId) {
|
6156 | service.windows[winId].clearText();
|
6157 | }
|
6158 | }
|
6159 |
|
6160 | return i;
|
6161 | };
|
6162 | |
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 | Cea708Stream.prototype.deleteWindows = function (i, service) {
|
6174 | var packetData = this.current708Packet.data;
|
6175 | var b = packetData[++i];
|
6176 | var pts = this.getPts(i);
|
6177 | this.flushDisplayed(pts, service);
|
6178 |
|
6179 | for (var winId = 0; winId < 8; winId++) {
|
6180 | if (b & 0x01 << winId) {
|
6181 | service.windows[winId].reset();
|
6182 | }
|
6183 | }
|
6184 |
|
6185 | return i;
|
6186 | };
|
6187 | |
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 |
|
6198 | Cea708Stream.prototype.setPenAttributes = function (i, service) {
|
6199 | var packetData = this.current708Packet.data;
|
6200 | var b = packetData[i];
|
6201 | var penAttr = service.currentWindow.penAttr;
|
6202 | b = packetData[++i];
|
6203 | penAttr.textTag = (b & 0xf0) >> 4;
|
6204 |
|
6205 | penAttr.offset = (b & 0x0c) >> 2;
|
6206 |
|
6207 | penAttr.penSize = b & 0x03;
|
6208 |
|
6209 | b = packetData[++i];
|
6210 | penAttr.italics = (b & 0x80) >> 7;
|
6211 |
|
6212 | penAttr.underline = (b & 0x40) >> 6;
|
6213 |
|
6214 | penAttr.edgeType = (b & 0x38) >> 3;
|
6215 |
|
6216 | penAttr.fontStyle = b & 0x07;
|
6217 |
|
6218 | return i;
|
6219 | };
|
6220 | |
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 |
|
6227 |
|
6228 |
|
6229 |
|
6230 |
|
6231 | Cea708Stream.prototype.setPenColor = function (i, service) {
|
6232 | var packetData = this.current708Packet.data;
|
6233 | var b = packetData[i];
|
6234 | var penColor = service.currentWindow.penColor;
|
6235 | b = packetData[++i];
|
6236 | penColor.fgOpacity = (b & 0xc0) >> 6;
|
6237 |
|
6238 | penColor.fgRed = (b & 0x30) >> 4;
|
6239 |
|
6240 | penColor.fgGreen = (b & 0x0c) >> 2;
|
6241 |
|
6242 | penColor.fgBlue = b & 0x03;
|
6243 |
|
6244 | b = packetData[++i];
|
6245 | penColor.bgOpacity = (b & 0xc0) >> 6;
|
6246 |
|
6247 | penColor.bgRed = (b & 0x30) >> 4;
|
6248 |
|
6249 | penColor.bgGreen = (b & 0x0c) >> 2;
|
6250 |
|
6251 | penColor.bgBlue = b & 0x03;
|
6252 |
|
6253 | b = packetData[++i];
|
6254 | penColor.edgeRed = (b & 0x30) >> 4;
|
6255 |
|
6256 | penColor.edgeGreen = (b & 0x0c) >> 2;
|
6257 |
|
6258 | penColor.edgeBlue = b & 0x03;
|
6259 |
|
6260 | return i;
|
6261 | };
|
6262 | |
6263 |
|
6264 |
|
6265 |
|
6266 |
|
6267 |
|
6268 |
|
6269 |
|
6270 |
|
6271 |
|
6272 |
|
6273 | Cea708Stream.prototype.setPenLocation = function (i, service) {
|
6274 | var packetData = this.current708Packet.data;
|
6275 | var b = packetData[i];
|
6276 | var penLoc = service.currentWindow.penLoc;
|
6277 |
|
6278 | service.currentWindow.pendingNewLine = true;
|
6279 | b = packetData[++i];
|
6280 | penLoc.row = b & 0x0f;
|
6281 |
|
6282 | b = packetData[++i];
|
6283 | penLoc.column = b & 0x3f;
|
6284 |
|
6285 | return i;
|
6286 | };
|
6287 | |
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 |
|
6294 |
|
6295 |
|
6296 |
|
6297 |
|
6298 | Cea708Stream.prototype.reset = function (i, service) {
|
6299 | var pts = this.getPts(i);
|
6300 | this.flushDisplayed(pts, service);
|
6301 | return this.initService(service.serviceNum, i);
|
6302 | };
|
6303 |
|
6304 |
|
6305 |
|
6306 |
|
6307 |
|
6308 |
|
6309 |
|
6310 |
|
6311 | var CHARACTER_TRANSLATION = {
|
6312 | 0x2a: 0xe1,
|
6313 |
|
6314 | 0x5c: 0xe9,
|
6315 |
|
6316 | 0x5e: 0xed,
|
6317 |
|
6318 | 0x5f: 0xf3,
|
6319 |
|
6320 | 0x60: 0xfa,
|
6321 |
|
6322 | 0x7b: 0xe7,
|
6323 |
|
6324 | 0x7c: 0xf7,
|
6325 |
|
6326 | 0x7d: 0xd1,
|
6327 |
|
6328 | 0x7e: 0xf1,
|
6329 |
|
6330 | 0x7f: 0x2588,
|
6331 |
|
6332 | 0x0130: 0xae,
|
6333 |
|
6334 | 0x0131: 0xb0,
|
6335 |
|
6336 | 0x0132: 0xbd,
|
6337 |
|
6338 | 0x0133: 0xbf,
|
6339 |
|
6340 | 0x0134: 0x2122,
|
6341 |
|
6342 | 0x0135: 0xa2,
|
6343 |
|
6344 | 0x0136: 0xa3,
|
6345 |
|
6346 | 0x0137: 0x266a,
|
6347 |
|
6348 | 0x0138: 0xe0,
|
6349 |
|
6350 | 0x0139: 0xa0,
|
6351 |
|
6352 | 0x013a: 0xe8,
|
6353 |
|
6354 | 0x013b: 0xe2,
|
6355 |
|
6356 | 0x013c: 0xea,
|
6357 |
|
6358 | 0x013d: 0xee,
|
6359 |
|
6360 | 0x013e: 0xf4,
|
6361 |
|
6362 | 0x013f: 0xfb,
|
6363 |
|
6364 | 0x0220: 0xc1,
|
6365 |
|
6366 | 0x0221: 0xc9,
|
6367 |
|
6368 | 0x0222: 0xd3,
|
6369 |
|
6370 | 0x0223: 0xda,
|
6371 |
|
6372 | 0x0224: 0xdc,
|
6373 |
|
6374 | 0x0225: 0xfc,
|
6375 |
|
6376 | 0x0226: 0x2018,
|
6377 |
|
6378 | 0x0227: 0xa1,
|
6379 |
|
6380 | 0x0228: 0x2a,
|
6381 |
|
6382 | 0x0229: 0x27,
|
6383 |
|
6384 | 0x022a: 0x2014,
|
6385 |
|
6386 | 0x022b: 0xa9,
|
6387 |
|
6388 | 0x022c: 0x2120,
|
6389 |
|
6390 | 0x022d: 0x2022,
|
6391 |
|
6392 | 0x022e: 0x201c,
|
6393 |
|
6394 | 0x022f: 0x201d,
|
6395 |
|
6396 | 0x0230: 0xc0,
|
6397 |
|
6398 | 0x0231: 0xc2,
|
6399 |
|
6400 | 0x0232: 0xc7,
|
6401 |
|
6402 | 0x0233: 0xc8,
|
6403 |
|
6404 | 0x0234: 0xca,
|
6405 |
|
6406 | 0x0235: 0xcb,
|
6407 |
|
6408 | 0x0236: 0xeb,
|
6409 |
|
6410 | 0x0237: 0xce,
|
6411 |
|
6412 | 0x0238: 0xcf,
|
6413 |
|
6414 | 0x0239: 0xef,
|
6415 |
|
6416 | 0x023a: 0xd4,
|
6417 |
|
6418 | 0x023b: 0xd9,
|
6419 |
|
6420 | 0x023c: 0xf9,
|
6421 |
|
6422 | 0x023d: 0xdb,
|
6423 |
|
6424 | 0x023e: 0xab,
|
6425 |
|
6426 | 0x023f: 0xbb,
|
6427 |
|
6428 | 0x0320: 0xc3,
|
6429 |
|
6430 | 0x0321: 0xe3,
|
6431 |
|
6432 | 0x0322: 0xcd,
|
6433 |
|
6434 | 0x0323: 0xcc,
|
6435 |
|
6436 | 0x0324: 0xec,
|
6437 |
|
6438 | 0x0325: 0xd2,
|
6439 |
|
6440 | 0x0326: 0xf2,
|
6441 |
|
6442 | 0x0327: 0xd5,
|
6443 |
|
6444 | 0x0328: 0xf5,
|
6445 |
|
6446 | 0x0329: 0x7b,
|
6447 |
|
6448 | 0x032a: 0x7d,
|
6449 |
|
6450 | 0x032b: 0x5c,
|
6451 |
|
6452 | 0x032c: 0x5e,
|
6453 |
|
6454 | 0x032d: 0x5f,
|
6455 |
|
6456 | 0x032e: 0x7c,
|
6457 |
|
6458 | 0x032f: 0x7e,
|
6459 |
|
6460 | 0x0330: 0xc4,
|
6461 |
|
6462 | 0x0331: 0xe4,
|
6463 |
|
6464 | 0x0332: 0xd6,
|
6465 |
|
6466 | 0x0333: 0xf6,
|
6467 |
|
6468 | 0x0334: 0xdf,
|
6469 |
|
6470 | 0x0335: 0xa5,
|
6471 |
|
6472 | 0x0336: 0xa4,
|
6473 |
|
6474 | 0x0337: 0x2502,
|
6475 |
|
6476 | 0x0338: 0xc5,
|
6477 |
|
6478 | 0x0339: 0xe5,
|
6479 |
|
6480 | 0x033a: 0xd8,
|
6481 |
|
6482 | 0x033b: 0xf8,
|
6483 |
|
6484 | 0x033c: 0x250c,
|
6485 |
|
6486 | 0x033d: 0x2510,
|
6487 |
|
6488 | 0x033e: 0x2514,
|
6489 |
|
6490 | 0x033f: 0x2518
|
6491 |
|
6492 | };
|
6493 |
|
6494 | var getCharFromCode = function getCharFromCode(code) {
|
6495 | if (code === null) {
|
6496 | return '';
|
6497 | }
|
6498 |
|
6499 | code = CHARACTER_TRANSLATION[code] || code;
|
6500 | return String.fromCharCode(code);
|
6501 | };
|
6502 |
|
6503 |
|
6504 | var BOTTOM_ROW = 14;
|
6505 |
|
6506 |
|
6507 | var ROWS = [0x1100, 0x1120, 0x1200, 0x1220, 0x1500, 0x1520, 0x1600, 0x1620, 0x1700, 0x1720, 0x1000, 0x1300, 0x1320, 0x1400, 0x1420];
|
6508 |
|
6509 |
|
6510 | var createDisplayBuffer = function createDisplayBuffer() {
|
6511 | var result = [],
|
6512 | i = BOTTOM_ROW + 1;
|
6513 |
|
6514 | while (i--) {
|
6515 | result.push('');
|
6516 | }
|
6517 |
|
6518 | return result;
|
6519 | };
|
6520 |
|
6521 | var Cea608Stream = function Cea608Stream(field, dataChannel) {
|
6522 | Cea608Stream.prototype.init.call(this);
|
6523 | this.field_ = field || 0;
|
6524 | this.dataChannel_ = dataChannel || 0;
|
6525 | this.name_ = 'CC' + ((this.field_ << 1 | this.dataChannel_) + 1);
|
6526 | this.setConstants();
|
6527 | this.reset();
|
6528 |
|
6529 | this.push = function (packet) {
|
6530 | var data, swap, char0, char1, text;
|
6531 |
|
6532 | data = packet.ccData & 0x7f7f;
|
6533 |
|
6534 | if (data === this.lastControlCode_) {
|
6535 | this.lastControlCode_ = null;
|
6536 | return;
|
6537 | }
|
6538 |
|
6539 |
|
6540 | if ((data & 0xf000) === 0x1000) {
|
6541 | this.lastControlCode_ = data;
|
6542 | } else if (data !== this.PADDING_) {
|
6543 | this.lastControlCode_ = null;
|
6544 | }
|
6545 |
|
6546 | char0 = data >>> 8;
|
6547 | char1 = data & 0xff;
|
6548 |
|
6549 | if (data === this.PADDING_) {
|
6550 | return;
|
6551 | } else if (data === this.RESUME_CAPTION_LOADING_) {
|
6552 | this.mode_ = 'popOn';
|
6553 | } else if (data === this.END_OF_CAPTION_) {
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 | this.mode_ = 'popOn';
|
6559 | this.clearFormatting(packet.pts);
|
6560 |
|
6561 | this.flushDisplayed(packet.pts);
|
6562 |
|
6563 | swap = this.displayed_;
|
6564 | this.displayed_ = this.nonDisplayed_;
|
6565 | this.nonDisplayed_ = swap;
|
6566 |
|
6567 | this.startPts_ = packet.pts;
|
6568 | } else if (data === this.ROLL_UP_2_ROWS_) {
|
6569 | this.rollUpRows_ = 2;
|
6570 | this.setRollUp(packet.pts);
|
6571 | } else if (data === this.ROLL_UP_3_ROWS_) {
|
6572 | this.rollUpRows_ = 3;
|
6573 | this.setRollUp(packet.pts);
|
6574 | } else if (data === this.ROLL_UP_4_ROWS_) {
|
6575 | this.rollUpRows_ = 4;
|
6576 | this.setRollUp(packet.pts);
|
6577 | } else if (data === this.CARRIAGE_RETURN_) {
|
6578 | this.clearFormatting(packet.pts);
|
6579 | this.flushDisplayed(packet.pts);
|
6580 | this.shiftRowsUp_();
|
6581 | this.startPts_ = packet.pts;
|
6582 | } else if (data === this.BACKSPACE_) {
|
6583 | if (this.mode_ === 'popOn') {
|
6584 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
6585 | } else {
|
6586 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
6587 | }
|
6588 | } else if (data === this.ERASE_DISPLAYED_MEMORY_) {
|
6589 | this.flushDisplayed(packet.pts);
|
6590 | this.displayed_ = createDisplayBuffer();
|
6591 | } else if (data === this.ERASE_NON_DISPLAYED_MEMORY_) {
|
6592 | this.nonDisplayed_ = createDisplayBuffer();
|
6593 | } else if (data === this.RESUME_DIRECT_CAPTIONING_) {
|
6594 | if (this.mode_ !== 'paintOn') {
|
6595 |
|
6596 |
|
6597 | this.flushDisplayed(packet.pts);
|
6598 | this.displayed_ = createDisplayBuffer();
|
6599 | }
|
6600 |
|
6601 | this.mode_ = 'paintOn';
|
6602 | this.startPts_ = packet.pts;
|
6603 | } else if (this.isSpecialCharacter(char0, char1)) {
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 | char0 = (char0 & 0x03) << 8;
|
6609 | text = getCharFromCode(char0 | char1);
|
6610 | this[this.mode_](packet.pts, text);
|
6611 | this.column_++;
|
6612 | } else if (this.isExtCharacter(char0, char1)) {
|
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 | if (this.mode_ === 'popOn') {
|
6619 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
6620 | } else {
|
6621 | this.displayed_[this.row_] = this.displayed_[this.row_].slice(0, -1);
|
6622 | }
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 | char0 = (char0 & 0x03) << 8;
|
6629 | text = getCharFromCode(char0 | char1);
|
6630 | this[this.mode_](packet.pts, text);
|
6631 | this.column_++;
|
6632 | } else if (this.isMidRowCode(char0, char1)) {
|
6633 |
|
6634 | this.clearFormatting(packet.pts);
|
6635 |
|
6636 |
|
6637 | this[this.mode_](packet.pts, ' ');
|
6638 | this.column_++;
|
6639 |
|
6640 | if ((char1 & 0xe) === 0xe) {
|
6641 | this.addFormatting(packet.pts, ['i']);
|
6642 | }
|
6643 |
|
6644 | if ((char1 & 0x1) === 0x1) {
|
6645 | this.addFormatting(packet.pts, ['u']);
|
6646 | }
|
6647 |
|
6648 | } else if (this.isOffsetControlCode(char0, char1)) {
|
6649 |
|
6650 |
|
6651 |
|
6652 |
|
6653 | this.column_ += char1 & 0x03;
|
6654 | } else if (this.isPAC(char0, char1)) {
|
6655 |
|
6656 |
|
6657 | var row = ROWS.indexOf(data & 0x1f20);
|
6658 |
|
6659 | if (this.mode_ === 'rollUp') {
|
6660 |
|
6661 |
|
6662 |
|
6663 | if (row - this.rollUpRows_ + 1 < 0) {
|
6664 | row = this.rollUpRows_ - 1;
|
6665 | }
|
6666 |
|
6667 | this.setRollUp(packet.pts, row);
|
6668 | }
|
6669 |
|
6670 | if (row !== this.row_) {
|
6671 |
|
6672 | this.clearFormatting(packet.pts);
|
6673 | this.row_ = row;
|
6674 | }
|
6675 |
|
6676 |
|
6677 |
|
6678 | if (char1 & 0x1 && this.formatting_.indexOf('u') === -1) {
|
6679 | this.addFormatting(packet.pts, ['u']);
|
6680 | }
|
6681 |
|
6682 | if ((data & 0x10) === 0x10) {
|
6683 |
|
6684 |
|
6685 |
|
6686 |
|
6687 | this.column_ = ((data & 0xe) >> 1) * 4;
|
6688 | }
|
6689 |
|
6690 | if (this.isColorPAC(char1)) {
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 | if ((char1 & 0xe) === 0xe) {
|
6696 | this.addFormatting(packet.pts, ['i']);
|
6697 | }
|
6698 | }
|
6699 |
|
6700 | } else if (this.isNormalChar(char0)) {
|
6701 | if (char1 === 0x00) {
|
6702 | char1 = null;
|
6703 | }
|
6704 |
|
6705 | text = getCharFromCode(char0);
|
6706 | text += getCharFromCode(char1);
|
6707 | this[this.mode_](packet.pts, text);
|
6708 | this.column_ += text.length;
|
6709 | }
|
6710 |
|
6711 | };
|
6712 | };
|
6713 |
|
6714 | Cea608Stream.prototype = new stream();
|
6715 |
|
6716 |
|
6717 | Cea608Stream.prototype.flushDisplayed = function (pts) {
|
6718 | var content = this.displayed_
|
6719 | .map(function (row) {
|
6720 | try {
|
6721 | return row.trim();
|
6722 | } catch (e) {
|
6723 |
|
6724 |
|
6725 |
|
6726 |
|
6727 | console.error('Skipping malformed caption.');
|
6728 | return '';
|
6729 | }
|
6730 | })
|
6731 | .join('\n')
|
6732 | .replace(/^\n+|\n+$/g, '');
|
6733 |
|
6734 | if (content.length) {
|
6735 | this.trigger('data', {
|
6736 | startPts: this.startPts_,
|
6737 | endPts: pts,
|
6738 | text: content,
|
6739 | stream: this.name_
|
6740 | });
|
6741 | }
|
6742 | };
|
6743 | |
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 | Cea608Stream.prototype.reset = function () {
|
6749 | this.mode_ = 'popOn';
|
6750 |
|
6751 |
|
6752 |
|
6753 |
|
6754 | this.topRow_ = 0;
|
6755 | this.startPts_ = 0;
|
6756 | this.displayed_ = createDisplayBuffer();
|
6757 | this.nonDisplayed_ = createDisplayBuffer();
|
6758 | this.lastControlCode_ = null;
|
6759 |
|
6760 | this.column_ = 0;
|
6761 | this.row_ = BOTTOM_ROW;
|
6762 | this.rollUpRows_ = 2;
|
6763 |
|
6764 | this.formatting_ = [];
|
6765 | };
|
6766 | |
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 | Cea608Stream.prototype.setConstants = function () {
|
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 | if (this.dataChannel_ === 0) {
|
6785 | this.BASE_ = 0x10;
|
6786 | this.EXT_ = 0x11;
|
6787 | this.CONTROL_ = (0x14 | this.field_) << 8;
|
6788 | this.OFFSET_ = 0x17;
|
6789 | } else if (this.dataChannel_ === 1) {
|
6790 | this.BASE_ = 0x18;
|
6791 | this.EXT_ = 0x19;
|
6792 | this.CONTROL_ = (0x1c | this.field_) << 8;
|
6793 | this.OFFSET_ = 0x1f;
|
6794 | }
|
6795 |
|
6796 |
|
6797 |
|
6798 |
|
6799 |
|
6800 | this.PADDING_ = 0x0000;
|
6801 |
|
6802 | this.RESUME_CAPTION_LOADING_ = this.CONTROL_ | 0x20;
|
6803 | this.END_OF_CAPTION_ = this.CONTROL_ | 0x2f;
|
6804 |
|
6805 | this.ROLL_UP_2_ROWS_ = this.CONTROL_ | 0x25;
|
6806 | this.ROLL_UP_3_ROWS_ = this.CONTROL_ | 0x26;
|
6807 | this.ROLL_UP_4_ROWS_ = this.CONTROL_ | 0x27;
|
6808 | this.CARRIAGE_RETURN_ = this.CONTROL_ | 0x2d;
|
6809 |
|
6810 | this.RESUME_DIRECT_CAPTIONING_ = this.CONTROL_ | 0x29;
|
6811 |
|
6812 | this.BACKSPACE_ = this.CONTROL_ | 0x21;
|
6813 | this.ERASE_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2c;
|
6814 | this.ERASE_NON_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2e;
|
6815 | };
|
6816 | |
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 |
|
6827 |
|
6828 |
|
6829 | Cea608Stream.prototype.isSpecialCharacter = function (char0, char1) {
|
6830 | return char0 === this.EXT_ && char1 >= 0x30 && char1 <= 0x3f;
|
6831 | };
|
6832 | |
6833 |
|
6834 |
|
6835 |
|
6836 |
|
6837 |
|
6838 |
|
6839 |
|
6840 |
|
6841 |
|
6842 |
|
6843 |
|
6844 |
|
6845 | Cea608Stream.prototype.isExtCharacter = function (char0, char1) {
|
6846 | return (char0 === this.EXT_ + 1 || char0 === this.EXT_ + 2) && char1 >= 0x20 && char1 <= 0x3f;
|
6847 | };
|
6848 | |
6849 |
|
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 |
|
6859 |
|
6860 |
|
6861 | Cea608Stream.prototype.isMidRowCode = function (char0, char1) {
|
6862 | return char0 === this.EXT_ && char1 >= 0x20 && char1 <= 0x2f;
|
6863 | };
|
6864 | |
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 |
|
6873 |
|
6874 |
|
6875 |
|
6876 |
|
6877 | Cea608Stream.prototype.isOffsetControlCode = function (char0, char1) {
|
6878 | return char0 === this.OFFSET_ && char1 >= 0x21 && char1 <= 0x23;
|
6879 | };
|
6880 | |
6881 |
|
6882 |
|
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 |
|
6888 |
|
6889 |
|
6890 |
|
6891 |
|
6892 |
|
6893 | Cea608Stream.prototype.isPAC = function (char0, char1) {
|
6894 | return char0 >= this.BASE_ && char0 < this.BASE_ + 8 && char1 >= 0x40 && char1 <= 0x7f;
|
6895 | };
|
6896 | |
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 |
|
6906 |
|
6907 | Cea608Stream.prototype.isColorPAC = function (char1) {
|
6908 | return char1 >= 0x40 && char1 <= 0x4f || char1 >= 0x60 && char1 <= 0x7f;
|
6909 | };
|
6910 | |
6911 |
|
6912 |
|
6913 |
|
6914 |
|
6915 |
|
6916 |
|
6917 |
|
6918 |
|
6919 |
|
6920 | Cea608Stream.prototype.isNormalChar = function (char) {
|
6921 | return char >= 0x20 && char <= 0x7f;
|
6922 | };
|
6923 | |
6924 |
|
6925 |
|
6926 |
|
6927 |
|
6928 |
|
6929 |
|
6930 |
|
6931 |
|
6932 | Cea608Stream.prototype.setRollUp = function (pts, newBaseRow) {
|
6933 |
|
6934 | if (this.mode_ !== 'rollUp') {
|
6935 | this.row_ = BOTTOM_ROW;
|
6936 | this.mode_ = 'rollUp';
|
6937 |
|
6938 | this.flushDisplayed(pts);
|
6939 | this.nonDisplayed_ = createDisplayBuffer();
|
6940 | this.displayed_ = createDisplayBuffer();
|
6941 | }
|
6942 |
|
6943 | if (newBaseRow !== undefined && newBaseRow !== this.row_) {
|
6944 |
|
6945 | for (var i = 0; i < this.rollUpRows_; i++) {
|
6946 | this.displayed_[newBaseRow - i] = this.displayed_[this.row_ - i];
|
6947 | this.displayed_[this.row_ - i] = '';
|
6948 | }
|
6949 | }
|
6950 |
|
6951 | if (newBaseRow === undefined) {
|
6952 | newBaseRow = this.row_;
|
6953 | }
|
6954 |
|
6955 | this.topRow_ = newBaseRow - this.rollUpRows_ + 1;
|
6956 | };
|
6957 |
|
6958 |
|
6959 |
|
6960 | Cea608Stream.prototype.addFormatting = function (pts, format) {
|
6961 | this.formatting_ = this.formatting_.concat(format);
|
6962 | var text = format.reduce(function (text, format) {
|
6963 | return text + '<' + format + '>';
|
6964 | }, '');
|
6965 | this[this.mode_](pts, text);
|
6966 | };
|
6967 |
|
6968 |
|
6969 |
|
6970 | Cea608Stream.prototype.clearFormatting = function (pts) {
|
6971 | if (!this.formatting_.length) {
|
6972 | return;
|
6973 | }
|
6974 |
|
6975 | var text = this.formatting_.reverse().reduce(function (text, format) {
|
6976 | return text + '</' + format + '>';
|
6977 | }, '');
|
6978 | this.formatting_ = [];
|
6979 | this[this.mode_](pts, text);
|
6980 | };
|
6981 |
|
6982 |
|
6983 | Cea608Stream.prototype.popOn = function (pts, text) {
|
6984 | var baseRow = this.nonDisplayed_[this.row_];
|
6985 |
|
6986 | baseRow += text;
|
6987 | this.nonDisplayed_[this.row_] = baseRow;
|
6988 | };
|
6989 |
|
6990 | Cea608Stream.prototype.rollUp = function (pts, text) {
|
6991 | var baseRow = this.displayed_[this.row_];
|
6992 | baseRow += text;
|
6993 | this.displayed_[this.row_] = baseRow;
|
6994 | };
|
6995 |
|
6996 | Cea608Stream.prototype.shiftRowsUp_ = function () {
|
6997 | var i;
|
6998 |
|
6999 | for (i = 0; i < this.topRow_; i++) {
|
7000 | this.displayed_[i] = '';
|
7001 | }
|
7002 |
|
7003 | for (i = this.row_ + 1; i < BOTTOM_ROW + 1; i++) {
|
7004 | this.displayed_[i] = '';
|
7005 | }
|
7006 |
|
7007 |
|
7008 | for (i = this.topRow_; i < this.row_; i++) {
|
7009 | this.displayed_[i] = this.displayed_[i + 1];
|
7010 | }
|
7011 |
|
7012 |
|
7013 | this.displayed_[this.row_] = '';
|
7014 | };
|
7015 |
|
7016 | Cea608Stream.prototype.paintOn = function (pts, text) {
|
7017 | var baseRow = this.displayed_[this.row_];
|
7018 | baseRow += text;
|
7019 | this.displayed_[this.row_] = baseRow;
|
7020 | };
|
7021 |
|
7022 |
|
7023 | var captionStream = {
|
7024 | CaptionStream: CaptionStream$1,
|
7025 | Cea608Stream: Cea608Stream,
|
7026 | Cea708Stream: Cea708Stream
|
7027 | };
|
7028 | |
7029 |
|
7030 |
|
7031 |
|
7032 |
|
7033 |
|
7034 |
|
7035 | var streamTypes = {
|
7036 | H264_STREAM_TYPE: 0x1B,
|
7037 | ADTS_STREAM_TYPE: 0x0F,
|
7038 | METADATA_STREAM_TYPE: 0x15
|
7039 | };
|
7040 | var MAX_TS = 8589934592;
|
7041 | var RO_THRESH = 4294967296;
|
7042 | var TYPE_SHARED = 'shared';
|
7043 |
|
7044 | var handleRollover = function handleRollover(value, reference) {
|
7045 | var direction = 1;
|
7046 |
|
7047 | if (value > reference) {
|
7048 |
|
7049 |
|
7050 |
|
7051 |
|
7052 |
|
7053 |
|
7054 |
|
7055 | direction = -1;
|
7056 | }
|
7057 |
|
7058 |
|
7059 |
|
7060 | while (Math.abs(reference - value) > RO_THRESH) {
|
7061 | value += direction * MAX_TS;
|
7062 | }
|
7063 |
|
7064 | return value;
|
7065 | };
|
7066 |
|
7067 | var TimestampRolloverStream$1 = function TimestampRolloverStream(type) {
|
7068 | var lastDTS, referenceDTS;
|
7069 | TimestampRolloverStream.prototype.init.call(this);
|
7070 |
|
7071 |
|
7072 |
|
7073 | this.type_ = type || TYPE_SHARED;
|
7074 |
|
7075 | this.push = function (data) {
|
7076 |
|
7077 |
|
7078 | if (this.type_ !== TYPE_SHARED && data.type !== this.type_) {
|
7079 | return;
|
7080 | }
|
7081 |
|
7082 | if (referenceDTS === undefined) {
|
7083 | referenceDTS = data.dts;
|
7084 | }
|
7085 |
|
7086 | data.dts = handleRollover(data.dts, referenceDTS);
|
7087 | data.pts = handleRollover(data.pts, referenceDTS);
|
7088 | lastDTS = data.dts;
|
7089 | this.trigger('data', data);
|
7090 | };
|
7091 |
|
7092 | this.flush = function () {
|
7093 | referenceDTS = lastDTS;
|
7094 | this.trigger('done');
|
7095 | };
|
7096 |
|
7097 | this.endTimeline = function () {
|
7098 | this.flush();
|
7099 | this.trigger('endedtimeline');
|
7100 | };
|
7101 |
|
7102 | this.discontinuity = function () {
|
7103 | referenceDTS = void 0;
|
7104 | lastDTS = void 0;
|
7105 | };
|
7106 |
|
7107 | this.reset = function () {
|
7108 | this.discontinuity();
|
7109 | this.trigger('reset');
|
7110 | };
|
7111 | };
|
7112 |
|
7113 | TimestampRolloverStream$1.prototype = new stream();
|
7114 | var timestampRolloverStream = {
|
7115 | TimestampRolloverStream: TimestampRolloverStream$1,
|
7116 | handleRollover: handleRollover
|
7117 | };
|
7118 |
|
7119 | var percentEncode$1 = function percentEncode(bytes, start, end) {
|
7120 | var i,
|
7121 | result = '';
|
7122 |
|
7123 | for (i = start; i < end; i++) {
|
7124 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
7125 | }
|
7126 |
|
7127 | return result;
|
7128 | },
|
7129 |
|
7130 |
|
7131 | parseUtf8 = function parseUtf8(bytes, start, end) {
|
7132 | return decodeURIComponent(percentEncode$1(bytes, start, end));
|
7133 | },
|
7134 |
|
7135 |
|
7136 | parseIso88591$1 = function parseIso88591(bytes, start, end) {
|
7137 | return unescape(percentEncode$1(bytes, start, end));
|
7138 | },
|
7139 | parseSyncSafeInteger$1 = function parseSyncSafeInteger(data) {
|
7140 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
7141 | },
|
7142 | tagParsers = {
|
7143 | TXXX: function TXXX(tag) {
|
7144 | var i;
|
7145 |
|
7146 | if (tag.data[0] !== 3) {
|
7147 |
|
7148 | return;
|
7149 | }
|
7150 |
|
7151 | for (i = 1; i < tag.data.length; i++) {
|
7152 | if (tag.data[i] === 0) {
|
7153 |
|
7154 | tag.description = parseUtf8(tag.data, 1, i);
|
7155 |
|
7156 | tag.value = parseUtf8(tag.data, i + 1, tag.data.length).replace(/\0*$/, '');
|
7157 | break;
|
7158 | }
|
7159 | }
|
7160 |
|
7161 | tag.data = tag.value;
|
7162 | },
|
7163 | WXXX: function WXXX(tag) {
|
7164 | var i;
|
7165 |
|
7166 | if (tag.data[0] !== 3) {
|
7167 |
|
7168 | return;
|
7169 | }
|
7170 |
|
7171 | for (i = 1; i < tag.data.length; i++) {
|
7172 | if (tag.data[i] === 0) {
|
7173 |
|
7174 | tag.description = parseUtf8(tag.data, 1, i);
|
7175 | tag.url = parseUtf8(tag.data, i + 1, tag.data.length);
|
7176 | break;
|
7177 | }
|
7178 | }
|
7179 | },
|
7180 | PRIV: function PRIV(tag) {
|
7181 | var i;
|
7182 |
|
7183 | for (i = 0; i < tag.data.length; i++) {
|
7184 | if (tag.data[i] === 0) {
|
7185 |
|
7186 | tag.owner = parseIso88591$1(tag.data, 0, i);
|
7187 | break;
|
7188 | }
|
7189 | }
|
7190 |
|
7191 | tag.privateData = tag.data.subarray(i + 1);
|
7192 | tag.data = tag.privateData;
|
7193 | }
|
7194 | },
|
7195 | _MetadataStream;
|
7196 |
|
7197 | _MetadataStream = function MetadataStream(options) {
|
7198 | var settings = {
|
7199 | debug: !!(options && options.debug),
|
7200 |
|
7201 |
|
7202 |
|
7203 | descriptor: options && options.descriptor
|
7204 | },
|
7205 |
|
7206 | tagSize = 0,
|
7207 |
|
7208 | buffer = [],
|
7209 |
|
7210 | bufferSize = 0,
|
7211 | i;
|
7212 |
|
7213 | _MetadataStream.prototype.init.call(this);
|
7214 |
|
7215 |
|
7216 |
|
7217 | this.dispatchType = streamTypes.METADATA_STREAM_TYPE.toString(16);
|
7218 |
|
7219 | if (settings.descriptor) {
|
7220 | for (i = 0; i < settings.descriptor.length; i++) {
|
7221 | this.dispatchType += ('00' + settings.descriptor[i].toString(16)).slice(-2);
|
7222 | }
|
7223 | }
|
7224 |
|
7225 | this.push = function (chunk) {
|
7226 | var tag, frameStart, frameSize, frame, i, frameHeader;
|
7227 |
|
7228 | if (chunk.type !== 'timed-metadata') {
|
7229 | return;
|
7230 | }
|
7231 |
|
7232 |
|
7233 |
|
7234 |
|
7235 | if (chunk.dataAlignmentIndicator) {
|
7236 | bufferSize = 0;
|
7237 | buffer.length = 0;
|
7238 | }
|
7239 |
|
7240 |
|
7241 | 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))) {
|
7242 | if (settings.debug) {
|
7243 |
|
7244 | console.log('Skipping unrecognized metadata packet');
|
7245 | }
|
7246 |
|
7247 | return;
|
7248 | }
|
7249 |
|
7250 |
|
7251 | buffer.push(chunk);
|
7252 | bufferSize += chunk.data.byteLength;
|
7253 |
|
7254 | if (buffer.length === 1) {
|
7255 |
|
7256 |
|
7257 |
|
7258 |
|
7259 | tagSize = parseSyncSafeInteger$1(chunk.data.subarray(6, 10));
|
7260 |
|
7261 |
|
7262 | tagSize += 10;
|
7263 | }
|
7264 |
|
7265 |
|
7266 | if (bufferSize < tagSize) {
|
7267 | return;
|
7268 | }
|
7269 |
|
7270 |
|
7271 | tag = {
|
7272 | data: new Uint8Array(tagSize),
|
7273 | frames: [],
|
7274 | pts: buffer[0].pts,
|
7275 | dts: buffer[0].dts
|
7276 | };
|
7277 |
|
7278 | for (i = 0; i < tagSize;) {
|
7279 | tag.data.set(buffer[0].data.subarray(0, tagSize - i), i);
|
7280 | i += buffer[0].data.byteLength;
|
7281 | bufferSize -= buffer[0].data.byteLength;
|
7282 | buffer.shift();
|
7283 | }
|
7284 |
|
7285 |
|
7286 | frameStart = 10;
|
7287 |
|
7288 | if (tag.data[5] & 0x40) {
|
7289 |
|
7290 | frameStart += 4;
|
7291 |
|
7292 | frameStart += parseSyncSafeInteger$1(tag.data.subarray(10, 14));
|
7293 |
|
7294 | tagSize -= parseSyncSafeInteger$1(tag.data.subarray(16, 20));
|
7295 | }
|
7296 |
|
7297 |
|
7298 |
|
7299 | do {
|
7300 |
|
7301 | frameSize = parseSyncSafeInteger$1(tag.data.subarray(frameStart + 4, frameStart + 8));
|
7302 |
|
7303 | if (frameSize < 1) {
|
7304 |
|
7305 | return console.log('Malformed ID3 frame encountered. Skipping metadata parsing.');
|
7306 | }
|
7307 |
|
7308 | frameHeader = String.fromCharCode(tag.data[frameStart], tag.data[frameStart + 1], tag.data[frameStart + 2], tag.data[frameStart + 3]);
|
7309 | frame = {
|
7310 | id: frameHeader,
|
7311 | data: tag.data.subarray(frameStart + 10, frameStart + frameSize + 10)
|
7312 | };
|
7313 | frame.key = frame.id;
|
7314 |
|
7315 | if (tagParsers[frame.id]) {
|
7316 | tagParsers[frame.id](frame);
|
7317 |
|
7318 |
|
7319 | if (frame.owner === 'com.apple.streaming.transportStreamTimestamp') {
|
7320 | var d = frame.data,
|
7321 | size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
7322 | size *= 4;
|
7323 | size += d[7] & 0x03;
|
7324 | frame.timeStamp = size;
|
7325 |
|
7326 |
|
7327 |
|
7328 |
|
7329 | if (tag.pts === undefined && tag.dts === undefined) {
|
7330 | tag.pts = frame.timeStamp;
|
7331 | tag.dts = frame.timeStamp;
|
7332 | }
|
7333 |
|
7334 | this.trigger('timestamp', frame);
|
7335 | }
|
7336 | }
|
7337 |
|
7338 | tag.frames.push(frame);
|
7339 | frameStart += 10;
|
7340 |
|
7341 | frameStart += frameSize;
|
7342 | } while (frameStart < tagSize);
|
7343 |
|
7344 | this.trigger('data', tag);
|
7345 | };
|
7346 | };
|
7347 |
|
7348 | _MetadataStream.prototype = new stream();
|
7349 | var metadataStream = _MetadataStream;
|
7350 | var TimestampRolloverStream = timestampRolloverStream.TimestampRolloverStream;
|
7351 |
|
7352 | var _TransportPacketStream, _TransportParseStream, _ElementaryStream;
|
7353 |
|
7354 |
|
7355 | var MP2T_PACKET_LENGTH = 188,
|
7356 |
|
7357 | SYNC_BYTE = 0x47;
|
7358 | |
7359 |
|
7360 |
|
7361 |
|
7362 |
|
7363 | _TransportPacketStream = function TransportPacketStream() {
|
7364 | var buffer = new Uint8Array(MP2T_PACKET_LENGTH),
|
7365 | bytesInBuffer = 0;
|
7366 |
|
7367 | _TransportPacketStream.prototype.init.call(this);
|
7368 |
|
7369 | |
7370 |
|
7371 |
|
7372 |
|
7373 |
|
7374 | this.push = function (bytes) {
|
7375 | var startIndex = 0,
|
7376 | endIndex = MP2T_PACKET_LENGTH,
|
7377 | everything;
|
7378 |
|
7379 |
|
7380 | if (bytesInBuffer) {
|
7381 | everything = new Uint8Array(bytes.byteLength + bytesInBuffer);
|
7382 | everything.set(buffer.subarray(0, bytesInBuffer));
|
7383 | everything.set(bytes, bytesInBuffer);
|
7384 | bytesInBuffer = 0;
|
7385 | } else {
|
7386 | everything = bytes;
|
7387 | }
|
7388 |
|
7389 |
|
7390 | while (endIndex < everything.byteLength) {
|
7391 |
|
7392 | if (everything[startIndex] === SYNC_BYTE && everything[endIndex] === SYNC_BYTE) {
|
7393 |
|
7394 |
|
7395 | this.trigger('data', everything.subarray(startIndex, endIndex));
|
7396 | startIndex += MP2T_PACKET_LENGTH;
|
7397 | endIndex += MP2T_PACKET_LENGTH;
|
7398 | continue;
|
7399 | }
|
7400 |
|
7401 |
|
7402 |
|
7403 |
|
7404 | startIndex++;
|
7405 | endIndex++;
|
7406 | }
|
7407 |
|
7408 |
|
7409 |
|
7410 |
|
7411 | if (startIndex < everything.byteLength) {
|
7412 | buffer.set(everything.subarray(startIndex), 0);
|
7413 | bytesInBuffer = everything.byteLength - startIndex;
|
7414 | }
|
7415 | };
|
7416 | |
7417 |
|
7418 |
|
7419 |
|
7420 |
|
7421 | this.flush = function () {
|
7422 |
|
7423 |
|
7424 |
|
7425 | if (bytesInBuffer === MP2T_PACKET_LENGTH && buffer[0] === SYNC_BYTE) {
|
7426 | this.trigger('data', buffer);
|
7427 | bytesInBuffer = 0;
|
7428 | }
|
7429 |
|
7430 | this.trigger('done');
|
7431 | };
|
7432 |
|
7433 | this.endTimeline = function () {
|
7434 | this.flush();
|
7435 | this.trigger('endedtimeline');
|
7436 | };
|
7437 |
|
7438 | this.reset = function () {
|
7439 | bytesInBuffer = 0;
|
7440 | this.trigger('reset');
|
7441 | };
|
7442 | };
|
7443 |
|
7444 | _TransportPacketStream.prototype = new stream();
|
7445 | |
7446 |
|
7447 |
|
7448 |
|
7449 |
|
7450 | _TransportParseStream = function TransportParseStream() {
|
7451 | var parsePsi, parsePat, parsePmt, self;
|
7452 |
|
7453 | _TransportParseStream.prototype.init.call(this);
|
7454 |
|
7455 | self = this;
|
7456 | this.packetsWaitingForPmt = [];
|
7457 | this.programMapTable = undefined;
|
7458 |
|
7459 | parsePsi = function parsePsi(payload, psi) {
|
7460 | var offset = 0;
|
7461 |
|
7462 |
|
7463 |
|
7464 |
|
7465 |
|
7466 |
|
7467 | if (psi.payloadUnitStartIndicator) {
|
7468 | offset += payload[offset] + 1;
|
7469 | }
|
7470 |
|
7471 | if (psi.type === 'pat') {
|
7472 | parsePat(payload.subarray(offset), psi);
|
7473 | } else {
|
7474 | parsePmt(payload.subarray(offset), psi);
|
7475 | }
|
7476 | };
|
7477 |
|
7478 | parsePat = function parsePat(payload, pat) {
|
7479 | pat.section_number = payload[7];
|
7480 |
|
7481 | pat.last_section_number = payload[8];
|
7482 |
|
7483 |
|
7484 | self.pmtPid = (payload[10] & 0x1F) << 8 | payload[11];
|
7485 | pat.pmtPid = self.pmtPid;
|
7486 | };
|
7487 | |
7488 |
|
7489 |
|
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 |
|
7495 |
|
7496 |
|
7497 | parsePmt = function parsePmt(payload, pmt) {
|
7498 | var sectionLength, tableEnd, programInfoLength, offset;
|
7499 |
|
7500 |
|
7501 |
|
7502 |
|
7503 |
|
7504 | if (!(payload[5] & 0x01)) {
|
7505 | return;
|
7506 | }
|
7507 |
|
7508 |
|
7509 | self.programMapTable = {
|
7510 | video: null,
|
7511 | audio: null,
|
7512 | 'timed-metadata': {}
|
7513 | };
|
7514 |
|
7515 | sectionLength = (payload[1] & 0x0f) << 8 | payload[2];
|
7516 | tableEnd = 3 + sectionLength - 4;
|
7517 |
|
7518 |
|
7519 | programInfoLength = (payload[10] & 0x0f) << 8 | payload[11];
|
7520 |
|
7521 | offset = 12 + programInfoLength;
|
7522 |
|
7523 | while (offset < tableEnd) {
|
7524 | var streamType = payload[offset];
|
7525 | var pid = (payload[offset + 1] & 0x1F) << 8 | payload[offset + 2];
|
7526 |
|
7527 |
|
7528 |
|
7529 | if (streamType === streamTypes.H264_STREAM_TYPE && self.programMapTable.video === null) {
|
7530 | self.programMapTable.video = pid;
|
7531 | } else if (streamType === streamTypes.ADTS_STREAM_TYPE && self.programMapTable.audio === null) {
|
7532 | self.programMapTable.audio = pid;
|
7533 | } else if (streamType === streamTypes.METADATA_STREAM_TYPE) {
|
7534 |
|
7535 | self.programMapTable['timed-metadata'][pid] = streamType;
|
7536 | }
|
7537 |
|
7538 |
|
7539 |
|
7540 | offset += ((payload[offset + 3] & 0x0F) << 8 | payload[offset + 4]) + 5;
|
7541 | }
|
7542 |
|
7543 |
|
7544 | pmt.programMapTable = self.programMapTable;
|
7545 | };
|
7546 | |
7547 |
|
7548 |
|
7549 |
|
7550 |
|
7551 | this.push = function (packet) {
|
7552 | var result = {},
|
7553 | offset = 4;
|
7554 | result.payloadUnitStartIndicator = !!(packet[1] & 0x40);
|
7555 |
|
7556 | result.pid = packet[1] & 0x1f;
|
7557 | result.pid <<= 8;
|
7558 | result.pid |= packet[2];
|
7559 |
|
7560 |
|
7561 |
|
7562 |
|
7563 |
|
7564 | if ((packet[3] & 0x30) >>> 4 > 0x01) {
|
7565 | offset += packet[offset] + 1;
|
7566 | }
|
7567 |
|
7568 |
|
7569 | if (result.pid === 0) {
|
7570 | result.type = 'pat';
|
7571 | parsePsi(packet.subarray(offset), result);
|
7572 | this.trigger('data', result);
|
7573 | } else if (result.pid === this.pmtPid) {
|
7574 | result.type = 'pmt';
|
7575 | parsePsi(packet.subarray(offset), result);
|
7576 | this.trigger('data', result);
|
7577 |
|
7578 | while (this.packetsWaitingForPmt.length) {
|
7579 | this.processPes_.apply(this, this.packetsWaitingForPmt.shift());
|
7580 | }
|
7581 | } else if (this.programMapTable === undefined) {
|
7582 |
|
7583 |
|
7584 | this.packetsWaitingForPmt.push([packet, offset, result]);
|
7585 | } else {
|
7586 | this.processPes_(packet, offset, result);
|
7587 | }
|
7588 | };
|
7589 |
|
7590 | this.processPes_ = function (packet, offset, result) {
|
7591 |
|
7592 | if (result.pid === this.programMapTable.video) {
|
7593 | result.streamType = streamTypes.H264_STREAM_TYPE;
|
7594 | } else if (result.pid === this.programMapTable.audio) {
|
7595 | result.streamType = streamTypes.ADTS_STREAM_TYPE;
|
7596 | } else {
|
7597 |
|
7598 |
|
7599 | result.streamType = this.programMapTable['timed-metadata'][result.pid];
|
7600 | }
|
7601 |
|
7602 | result.type = 'pes';
|
7603 | result.data = packet.subarray(offset);
|
7604 | this.trigger('data', result);
|
7605 | };
|
7606 | };
|
7607 |
|
7608 | _TransportParseStream.prototype = new stream();
|
7609 | _TransportParseStream.STREAM_TYPES = {
|
7610 | h264: 0x1b,
|
7611 | adts: 0x0f
|
7612 | };
|
7613 | |
7614 |
|
7615 |
|
7616 |
|
7617 |
|
7618 |
|
7619 |
|
7620 |
|
7621 |
|
7622 | _ElementaryStream = function ElementaryStream() {
|
7623 | var self = this,
|
7624 |
|
7625 | video = {
|
7626 | data: [],
|
7627 | size: 0
|
7628 | },
|
7629 | audio = {
|
7630 | data: [],
|
7631 | size: 0
|
7632 | },
|
7633 | timedMetadata = {
|
7634 | data: [],
|
7635 | size: 0
|
7636 | },
|
7637 | programMapTable,
|
7638 | parsePes = function parsePes(payload, pes) {
|
7639 | var ptsDtsFlags;
|
7640 | var startPrefix = payload[0] << 16 | payload[1] << 8 | payload[2];
|
7641 |
|
7642 | pes.data = new Uint8Array();
|
7643 |
|
7644 |
|
7645 |
|
7646 | if (startPrefix !== 1) {
|
7647 | return;
|
7648 | }
|
7649 |
|
7650 |
|
7651 | pes.packetLength = 6 + (payload[4] << 8 | payload[5]);
|
7652 |
|
7653 | pes.dataAlignmentIndicator = (payload[6] & 0x04) !== 0;
|
7654 |
|
7655 |
|
7656 |
|
7657 | ptsDtsFlags = payload[7];
|
7658 |
|
7659 |
|
7660 |
|
7661 |
|
7662 |
|
7663 |
|
7664 |
|
7665 |
|
7666 | if (ptsDtsFlags & 0xC0) {
|
7667 |
|
7668 |
|
7669 |
|
7670 | pes.pts = (payload[9] & 0x0E) << 27 | (payload[10] & 0xFF) << 20 | (payload[11] & 0xFE) << 12 | (payload[12] & 0xFF) << 5 | (payload[13] & 0xFE) >>> 3;
|
7671 | pes.pts *= 4;
|
7672 |
|
7673 | pes.pts += (payload[13] & 0x06) >>> 1;
|
7674 |
|
7675 | pes.dts = pes.pts;
|
7676 |
|
7677 | if (ptsDtsFlags & 0x40) {
|
7678 | pes.dts = (payload[14] & 0x0E) << 27 | (payload[15] & 0xFF) << 20 | (payload[16] & 0xFE) << 12 | (payload[17] & 0xFF) << 5 | (payload[18] & 0xFE) >>> 3;
|
7679 | pes.dts *= 4;
|
7680 |
|
7681 | pes.dts += (payload[18] & 0x06) >>> 1;
|
7682 | }
|
7683 | }
|
7684 |
|
7685 |
|
7686 |
|
7687 |
|
7688 | pes.data = payload.subarray(9 + payload[8]);
|
7689 | },
|
7690 |
|
7691 | |
7692 |
|
7693 |
|
7694 | flushStream = function flushStream(stream, type, forceFlush) {
|
7695 | var packetData = new Uint8Array(stream.size),
|
7696 | event = {
|
7697 | type: type
|
7698 | },
|
7699 | i = 0,
|
7700 | offset = 0,
|
7701 | packetFlushable = false,
|
7702 | fragment;
|
7703 |
|
7704 |
|
7705 | if (!stream.data.length || stream.size < 9) {
|
7706 | return;
|
7707 | }
|
7708 |
|
7709 | event.trackId = stream.data[0].pid;
|
7710 |
|
7711 | for (i = 0; i < stream.data.length; i++) {
|
7712 | fragment = stream.data[i];
|
7713 | packetData.set(fragment.data, offset);
|
7714 | offset += fragment.data.byteLength;
|
7715 | }
|
7716 |
|
7717 |
|
7718 | parsePes(packetData, event);
|
7719 |
|
7720 |
|
7721 | packetFlushable = type === 'video' || event.packetLength <= stream.size;
|
7722 |
|
7723 | if (forceFlush || packetFlushable) {
|
7724 | stream.size = 0;
|
7725 | stream.data.length = 0;
|
7726 | }
|
7727 |
|
7728 |
|
7729 |
|
7730 | if (packetFlushable) {
|
7731 | self.trigger('data', event);
|
7732 | }
|
7733 | };
|
7734 |
|
7735 | _ElementaryStream.prototype.init.call(this);
|
7736 | |
7737 |
|
7738 |
|
7739 |
|
7740 |
|
7741 |
|
7742 | this.push = function (data) {
|
7743 | ({
|
7744 | pat: function pat() {
|
7745 |
|
7746 | },
|
7747 | pes: function pes() {
|
7748 | var stream, streamType;
|
7749 |
|
7750 | switch (data.streamType) {
|
7751 | case streamTypes.H264_STREAM_TYPE:
|
7752 | stream = video;
|
7753 | streamType = 'video';
|
7754 | break;
|
7755 |
|
7756 | case streamTypes.ADTS_STREAM_TYPE:
|
7757 | stream = audio;
|
7758 | streamType = 'audio';
|
7759 | break;
|
7760 |
|
7761 | case streamTypes.METADATA_STREAM_TYPE:
|
7762 | stream = timedMetadata;
|
7763 | streamType = 'timed-metadata';
|
7764 | break;
|
7765 |
|
7766 | default:
|
7767 |
|
7768 | return;
|
7769 | }
|
7770 |
|
7771 |
|
7772 |
|
7773 | if (data.payloadUnitStartIndicator) {
|
7774 | flushStream(stream, streamType, true);
|
7775 | }
|
7776 |
|
7777 |
|
7778 |
|
7779 | stream.data.push(data);
|
7780 | stream.size += data.data.byteLength;
|
7781 | },
|
7782 | pmt: function pmt() {
|
7783 | var event = {
|
7784 | type: 'metadata',
|
7785 | tracks: []
|
7786 | };
|
7787 | programMapTable = data.programMapTable;
|
7788 |
|
7789 | if (programMapTable.video !== null) {
|
7790 | event.tracks.push({
|
7791 | timelineStartInfo: {
|
7792 | baseMediaDecodeTime: 0
|
7793 | },
|
7794 | id: +programMapTable.video,
|
7795 | codec: 'avc',
|
7796 | type: 'video'
|
7797 | });
|
7798 | }
|
7799 |
|
7800 | if (programMapTable.audio !== null) {
|
7801 | event.tracks.push({
|
7802 | timelineStartInfo: {
|
7803 | baseMediaDecodeTime: 0
|
7804 | },
|
7805 | id: +programMapTable.audio,
|
7806 | codec: 'adts',
|
7807 | type: 'audio'
|
7808 | });
|
7809 | }
|
7810 |
|
7811 | self.trigger('data', event);
|
7812 | }
|
7813 | })[data.type]();
|
7814 | };
|
7815 |
|
7816 | this.reset = function () {
|
7817 | video.size = 0;
|
7818 | video.data.length = 0;
|
7819 | audio.size = 0;
|
7820 | audio.data.length = 0;
|
7821 | this.trigger('reset');
|
7822 | };
|
7823 | |
7824 |
|
7825 |
|
7826 |
|
7827 |
|
7828 |
|
7829 |
|
7830 |
|
7831 |
|
7832 |
|
7833 |
|
7834 | this.flushStreams_ = function () {
|
7835 |
|
7836 |
|
7837 | flushStream(video, 'video');
|
7838 | flushStream(audio, 'audio');
|
7839 | flushStream(timedMetadata, 'timed-metadata');
|
7840 | };
|
7841 |
|
7842 | this.flush = function () {
|
7843 | this.flushStreams_();
|
7844 | this.trigger('done');
|
7845 | };
|
7846 | };
|
7847 |
|
7848 | _ElementaryStream.prototype = new stream();
|
7849 | var m2ts = {
|
7850 | PAT_PID: 0x0000,
|
7851 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH,
|
7852 | TransportPacketStream: _TransportPacketStream,
|
7853 | TransportParseStream: _TransportParseStream,
|
7854 | ElementaryStream: _ElementaryStream,
|
7855 | TimestampRolloverStream: TimestampRolloverStream,
|
7856 | CaptionStream: captionStream.CaptionStream,
|
7857 | Cea608Stream: captionStream.Cea608Stream,
|
7858 | Cea708Stream: captionStream.Cea708Stream,
|
7859 | MetadataStream: metadataStream
|
7860 | };
|
7861 |
|
7862 | for (var type in streamTypes) {
|
7863 | if (streamTypes.hasOwnProperty(type)) {
|
7864 | m2ts[type] = streamTypes[type];
|
7865 | }
|
7866 | }
|
7867 |
|
7868 | var m2ts_1 = m2ts;
|
7869 | var ONE_SECOND_IN_TS$2 = clock.ONE_SECOND_IN_TS;
|
7870 |
|
7871 | var _AdtsStream;
|
7872 |
|
7873 | var ADTS_SAMPLING_FREQUENCIES$1 = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
7874 | |
7875 |
|
7876 |
|
7877 |
|
7878 |
|
7879 |
|
7880 |
|
7881 |
|
7882 |
|
7883 | _AdtsStream = function AdtsStream(handlePartialSegments) {
|
7884 | var buffer,
|
7885 | frameNum = 0;
|
7886 |
|
7887 | _AdtsStream.prototype.init.call(this);
|
7888 |
|
7889 | this.push = function (packet) {
|
7890 | var i = 0,
|
7891 | frameLength,
|
7892 | protectionSkipBytes,
|
7893 | frameEnd,
|
7894 | oldBuffer,
|
7895 | sampleCount,
|
7896 | adtsFrameDuration;
|
7897 |
|
7898 | if (!handlePartialSegments) {
|
7899 | frameNum = 0;
|
7900 | }
|
7901 |
|
7902 | if (packet.type !== 'audio') {
|
7903 |
|
7904 | return;
|
7905 | }
|
7906 |
|
7907 |
|
7908 |
|
7909 | if (buffer) {
|
7910 | oldBuffer = buffer;
|
7911 | buffer = new Uint8Array(oldBuffer.byteLength + packet.data.byteLength);
|
7912 | buffer.set(oldBuffer);
|
7913 | buffer.set(packet.data, oldBuffer.byteLength);
|
7914 | } else {
|
7915 | buffer = packet.data;
|
7916 | }
|
7917 |
|
7918 |
|
7919 |
|
7920 | while (i + 5 < buffer.length) {
|
7921 |
|
7922 | if (buffer[i] !== 0xFF || (buffer[i + 1] & 0xF6) !== 0xF0) {
|
7923 |
|
7924 |
|
7925 | i++;
|
7926 | continue;
|
7927 | }
|
7928 |
|
7929 |
|
7930 |
|
7931 | protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
|
7932 |
|
7933 |
|
7934 | frameLength = (buffer[i + 3] & 0x03) << 11 | buffer[i + 4] << 3 | (buffer[i + 5] & 0xe0) >> 5;
|
7935 | sampleCount = ((buffer[i + 6] & 0x03) + 1) * 1024;
|
7936 | adtsFrameDuration = sampleCount * ONE_SECOND_IN_TS$2 / ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2];
|
7937 | frameEnd = i + frameLength;
|
7938 |
|
7939 |
|
7940 | if (buffer.byteLength < frameEnd) {
|
7941 | return;
|
7942 | }
|
7943 |
|
7944 |
|
7945 | this.trigger('data', {
|
7946 | pts: packet.pts + frameNum * adtsFrameDuration,
|
7947 | dts: packet.dts + frameNum * adtsFrameDuration,
|
7948 | sampleCount: sampleCount,
|
7949 | audioobjecttype: (buffer[i + 2] >>> 6 & 0x03) + 1,
|
7950 | channelcount: (buffer[i + 2] & 1) << 2 | (buffer[i + 3] & 0xc0) >>> 6,
|
7951 | samplerate: ADTS_SAMPLING_FREQUENCIES$1[(buffer[i + 2] & 0x3c) >>> 2],
|
7952 | samplingfrequencyindex: (buffer[i + 2] & 0x3c) >>> 2,
|
7953 |
|
7954 | samplesize: 16,
|
7955 | data: buffer.subarray(i + 7 + protectionSkipBytes, frameEnd)
|
7956 | });
|
7957 | frameNum++;
|
7958 |
|
7959 | if (buffer.byteLength === frameEnd) {
|
7960 | buffer = undefined;
|
7961 | return;
|
7962 | }
|
7963 |
|
7964 |
|
7965 | buffer = buffer.subarray(frameEnd);
|
7966 | }
|
7967 | };
|
7968 |
|
7969 | this.flush = function () {
|
7970 | frameNum = 0;
|
7971 | this.trigger('done');
|
7972 | };
|
7973 |
|
7974 | this.reset = function () {
|
7975 | buffer = void 0;
|
7976 | this.trigger('reset');
|
7977 | };
|
7978 |
|
7979 | this.endTimeline = function () {
|
7980 | buffer = void 0;
|
7981 | this.trigger('endedtimeline');
|
7982 | };
|
7983 | };
|
7984 |
|
7985 | _AdtsStream.prototype = new stream();
|
7986 | var adts = _AdtsStream;
|
7987 | |
7988 |
|
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 | var ExpGolomb;
|
7995 | |
7996 |
|
7997 |
|
7998 |
|
7999 |
|
8000 | ExpGolomb = function ExpGolomb(workingData) {
|
8001 | var
|
8002 | workingBytesAvailable = workingData.byteLength,
|
8003 |
|
8004 | workingWord = 0,
|
8005 |
|
8006 |
|
8007 | workingBitsAvailable = 0;
|
8008 |
|
8009 |
|
8010 | this.length = function () {
|
8011 | return 8 * workingBytesAvailable;
|
8012 | };
|
8013 |
|
8014 |
|
8015 | this.bitsAvailable = function () {
|
8016 | return 8 * workingBytesAvailable + workingBitsAvailable;
|
8017 | };
|
8018 |
|
8019 |
|
8020 | this.loadWord = function () {
|
8021 | var position = workingData.byteLength - workingBytesAvailable,
|
8022 | workingBytes = new Uint8Array(4),
|
8023 | availableBytes = Math.min(4, workingBytesAvailable);
|
8024 |
|
8025 | if (availableBytes === 0) {
|
8026 | throw new Error('no bytes available');
|
8027 | }
|
8028 |
|
8029 | workingBytes.set(workingData.subarray(position, position + availableBytes));
|
8030 | workingWord = new DataView(workingBytes.buffer).getUint32(0);
|
8031 |
|
8032 | workingBitsAvailable = availableBytes * 8;
|
8033 | workingBytesAvailable -= availableBytes;
|
8034 | };
|
8035 |
|
8036 |
|
8037 | this.skipBits = function (count) {
|
8038 | var skipBytes;
|
8039 |
|
8040 | if (workingBitsAvailable > count) {
|
8041 | workingWord <<= count;
|
8042 | workingBitsAvailable -= count;
|
8043 | } else {
|
8044 | count -= workingBitsAvailable;
|
8045 | skipBytes = Math.floor(count / 8);
|
8046 | count -= skipBytes * 8;
|
8047 | workingBytesAvailable -= skipBytes;
|
8048 | this.loadWord();
|
8049 | workingWord <<= count;
|
8050 | workingBitsAvailable -= count;
|
8051 | }
|
8052 | };
|
8053 |
|
8054 |
|
8055 | this.readBits = function (size) {
|
8056 | var bits = Math.min(workingBitsAvailable, size),
|
8057 |
|
8058 | valu = workingWord >>> 32 - bits;
|
8059 |
|
8060 |
|
8061 | workingBitsAvailable -= bits;
|
8062 |
|
8063 | if (workingBitsAvailable > 0) {
|
8064 | workingWord <<= bits;
|
8065 | } else if (workingBytesAvailable > 0) {
|
8066 | this.loadWord();
|
8067 | }
|
8068 |
|
8069 | bits = size - bits;
|
8070 |
|
8071 | if (bits > 0) {
|
8072 | return valu << bits | this.readBits(bits);
|
8073 | }
|
8074 |
|
8075 | return valu;
|
8076 | };
|
8077 |
|
8078 |
|
8079 | this.skipLeadingZeros = function () {
|
8080 | var leadingZeroCount;
|
8081 |
|
8082 | for (leadingZeroCount = 0; leadingZeroCount < workingBitsAvailable; ++leadingZeroCount) {
|
8083 | if ((workingWord & 0x80000000 >>> leadingZeroCount) !== 0) {
|
8084 |
|
8085 | workingWord <<= leadingZeroCount;
|
8086 | workingBitsAvailable -= leadingZeroCount;
|
8087 | return leadingZeroCount;
|
8088 | }
|
8089 | }
|
8090 |
|
8091 |
|
8092 | this.loadWord();
|
8093 | return leadingZeroCount + this.skipLeadingZeros();
|
8094 | };
|
8095 |
|
8096 |
|
8097 | this.skipUnsignedExpGolomb = function () {
|
8098 | this.skipBits(1 + this.skipLeadingZeros());
|
8099 | };
|
8100 |
|
8101 |
|
8102 | this.skipExpGolomb = function () {
|
8103 | this.skipBits(1 + this.skipLeadingZeros());
|
8104 | };
|
8105 |
|
8106 |
|
8107 | this.readUnsignedExpGolomb = function () {
|
8108 | var clz = this.skipLeadingZeros();
|
8109 |
|
8110 | return this.readBits(clz + 1) - 1;
|
8111 | };
|
8112 |
|
8113 |
|
8114 | this.readExpGolomb = function () {
|
8115 | var valu = this.readUnsignedExpGolomb();
|
8116 |
|
8117 | if (0x01 & valu) {
|
8118 |
|
8119 | return 1 + valu >>> 1;
|
8120 | }
|
8121 |
|
8122 | return -1 * (valu >>> 1);
|
8123 | };
|
8124 |
|
8125 |
|
8126 |
|
8127 | this.readBoolean = function () {
|
8128 | return this.readBits(1) === 1;
|
8129 | };
|
8130 |
|
8131 |
|
8132 | this.readUnsignedByte = function () {
|
8133 | return this.readBits(8);
|
8134 | };
|
8135 |
|
8136 | this.loadWord();
|
8137 | };
|
8138 |
|
8139 | var expGolomb = ExpGolomb;
|
8140 |
|
8141 | var _H264Stream, _NalByteStream;
|
8142 |
|
8143 | var PROFILES_WITH_OPTIONAL_SPS_DATA;
|
8144 | |
8145 |
|
8146 |
|
8147 |
|
8148 | _NalByteStream = function NalByteStream() {
|
8149 | var syncPoint = 0,
|
8150 | i,
|
8151 | buffer;
|
8152 |
|
8153 | _NalByteStream.prototype.init.call(this);
|
8154 | |
8155 |
|
8156 |
|
8157 |
|
8158 |
|
8159 |
|
8160 |
|
8161 |
|
8162 |
|
8163 | this.push = function (data) {
|
8164 | var swapBuffer;
|
8165 |
|
8166 | if (!buffer) {
|
8167 | buffer = data.data;
|
8168 | } else {
|
8169 | swapBuffer = new Uint8Array(buffer.byteLength + data.data.byteLength);
|
8170 | swapBuffer.set(buffer);
|
8171 | swapBuffer.set(data.data, buffer.byteLength);
|
8172 | buffer = swapBuffer;
|
8173 | }
|
8174 |
|
8175 | var len = buffer.byteLength;
|
8176 |
|
8177 |
|
8178 |
|
8179 |
|
8180 |
|
8181 |
|
8182 |
|
8183 |
|
8184 |
|
8185 | for (; syncPoint < len - 3; syncPoint++) {
|
8186 | if (buffer[syncPoint + 2] === 1) {
|
8187 |
|
8188 | i = syncPoint + 5;
|
8189 | break;
|
8190 | }
|
8191 | }
|
8192 |
|
8193 | while (i < len) {
|
8194 |
|
8195 |
|
8196 | switch (buffer[i]) {
|
8197 | case 0:
|
8198 |
|
8199 | if (buffer[i - 1] !== 0) {
|
8200 | i += 2;
|
8201 | break;
|
8202 | } else if (buffer[i - 2] !== 0) {
|
8203 | i++;
|
8204 | break;
|
8205 | }
|
8206 |
|
8207 |
|
8208 | if (syncPoint + 3 !== i - 2) {
|
8209 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
8210 | }
|
8211 |
|
8212 |
|
8213 | do {
|
8214 | i++;
|
8215 | } while (buffer[i] !== 1 && i < len);
|
8216 |
|
8217 | syncPoint = i - 2;
|
8218 | i += 3;
|
8219 | break;
|
8220 |
|
8221 | case 1:
|
8222 |
|
8223 | if (buffer[i - 1] !== 0 || buffer[i - 2] !== 0) {
|
8224 | i += 3;
|
8225 | break;
|
8226 | }
|
8227 |
|
8228 |
|
8229 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
8230 | syncPoint = i - 2;
|
8231 | i += 3;
|
8232 | break;
|
8233 |
|
8234 | default:
|
8235 |
|
8236 |
|
8237 | i += 3;
|
8238 | break;
|
8239 | }
|
8240 | }
|
8241 |
|
8242 |
|
8243 | buffer = buffer.subarray(syncPoint);
|
8244 | i -= syncPoint;
|
8245 | syncPoint = 0;
|
8246 | };
|
8247 |
|
8248 | this.reset = function () {
|
8249 | buffer = null;
|
8250 | syncPoint = 0;
|
8251 | this.trigger('reset');
|
8252 | };
|
8253 |
|
8254 | this.flush = function () {
|
8255 |
|
8256 | if (buffer && buffer.byteLength > 3) {
|
8257 | this.trigger('data', buffer.subarray(syncPoint + 3));
|
8258 | }
|
8259 |
|
8260 |
|
8261 | buffer = null;
|
8262 | syncPoint = 0;
|
8263 | this.trigger('done');
|
8264 | };
|
8265 |
|
8266 | this.endTimeline = function () {
|
8267 | this.flush();
|
8268 | this.trigger('endedtimeline');
|
8269 | };
|
8270 | };
|
8271 |
|
8272 | _NalByteStream.prototype = new stream();
|
8273 |
|
8274 |
|
8275 |
|
8276 | PROFILES_WITH_OPTIONAL_SPS_DATA = {
|
8277 | 100: true,
|
8278 | 110: true,
|
8279 | 122: true,
|
8280 | 244: true,
|
8281 | 44: true,
|
8282 | 83: true,
|
8283 | 86: true,
|
8284 | 118: true,
|
8285 | 128: true,
|
8286 | 138: true,
|
8287 | 139: true,
|
8288 | 134: true
|
8289 | };
|
8290 | |
8291 |
|
8292 |
|
8293 |
|
8294 |
|
8295 | _H264Stream = function H264Stream() {
|
8296 | var nalByteStream = new _NalByteStream(),
|
8297 | self,
|
8298 | trackId,
|
8299 | currentPts,
|
8300 | currentDts,
|
8301 | discardEmulationPreventionBytes,
|
8302 | readSequenceParameterSet,
|
8303 | skipScalingList;
|
8304 |
|
8305 | _H264Stream.prototype.init.call(this);
|
8306 |
|
8307 | self = this;
|
8308 | |
8309 |
|
8310 |
|
8311 |
|
8312 |
|
8313 |
|
8314 |
|
8315 |
|
8316 |
|
8317 |
|
8318 |
|
8319 |
|
8320 | this.push = function (packet) {
|
8321 | if (packet.type !== 'video') {
|
8322 | return;
|
8323 | }
|
8324 |
|
8325 | trackId = packet.trackId;
|
8326 | currentPts = packet.pts;
|
8327 | currentDts = packet.dts;
|
8328 | nalByteStream.push(packet);
|
8329 | };
|
8330 | |
8331 |
|
8332 |
|
8333 |
|
8334 |
|
8335 |
|
8336 |
|
8337 |
|
8338 |
|
8339 |
|
8340 | nalByteStream.on('data', function (data) {
|
8341 | var event = {
|
8342 | trackId: trackId,
|
8343 | pts: currentPts,
|
8344 | dts: currentDts,
|
8345 | data: data
|
8346 | };
|
8347 |
|
8348 | switch (data[0] & 0x1f) {
|
8349 | case 0x05:
|
8350 | event.nalUnitType = 'slice_layer_without_partitioning_rbsp_idr';
|
8351 | break;
|
8352 |
|
8353 | case 0x06:
|
8354 | event.nalUnitType = 'sei_rbsp';
|
8355 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
8356 | break;
|
8357 |
|
8358 | case 0x07:
|
8359 | event.nalUnitType = 'seq_parameter_set_rbsp';
|
8360 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
8361 | event.config = readSequenceParameterSet(event.escapedRBSP);
|
8362 | break;
|
8363 |
|
8364 | case 0x08:
|
8365 | event.nalUnitType = 'pic_parameter_set_rbsp';
|
8366 | break;
|
8367 |
|
8368 | case 0x09:
|
8369 | event.nalUnitType = 'access_unit_delimiter_rbsp';
|
8370 | break;
|
8371 | }
|
8372 |
|
8373 |
|
8374 | self.trigger('data', event);
|
8375 | });
|
8376 | nalByteStream.on('done', function () {
|
8377 | self.trigger('done');
|
8378 | });
|
8379 | nalByteStream.on('partialdone', function () {
|
8380 | self.trigger('partialdone');
|
8381 | });
|
8382 | nalByteStream.on('reset', function () {
|
8383 | self.trigger('reset');
|
8384 | });
|
8385 | nalByteStream.on('endedtimeline', function () {
|
8386 | self.trigger('endedtimeline');
|
8387 | });
|
8388 |
|
8389 | this.flush = function () {
|
8390 | nalByteStream.flush();
|
8391 | };
|
8392 |
|
8393 | this.partialFlush = function () {
|
8394 | nalByteStream.partialFlush();
|
8395 | };
|
8396 |
|
8397 | this.reset = function () {
|
8398 | nalByteStream.reset();
|
8399 | };
|
8400 |
|
8401 | this.endTimeline = function () {
|
8402 | nalByteStream.endTimeline();
|
8403 | };
|
8404 | |
8405 |
|
8406 |
|
8407 |
|
8408 |
|
8409 |
|
8410 |
|
8411 |
|
8412 |
|
8413 |
|
8414 |
|
8415 | skipScalingList = function skipScalingList(count, expGolombDecoder) {
|
8416 | var lastScale = 8,
|
8417 | nextScale = 8,
|
8418 | j,
|
8419 | deltaScale;
|
8420 |
|
8421 | for (j = 0; j < count; j++) {
|
8422 | if (nextScale !== 0) {
|
8423 | deltaScale = expGolombDecoder.readExpGolomb();
|
8424 | nextScale = (lastScale + deltaScale + 256) % 256;
|
8425 | }
|
8426 |
|
8427 | lastScale = nextScale === 0 ? lastScale : nextScale;
|
8428 | }
|
8429 | };
|
8430 | |
8431 |
|
8432 |
|
8433 |
|
8434 |
|
8435 |
|
8436 |
|
8437 |
|
8438 |
|
8439 |
|
8440 | discardEmulationPreventionBytes = function discardEmulationPreventionBytes(data) {
|
8441 | var length = data.byteLength,
|
8442 | emulationPreventionBytesPositions = [],
|
8443 | i = 1,
|
8444 | newLength,
|
8445 | newData;
|
8446 |
|
8447 | while (i < length - 2) {
|
8448 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
8449 | emulationPreventionBytesPositions.push(i + 2);
|
8450 | i += 2;
|
8451 | } else {
|
8452 | i++;
|
8453 | }
|
8454 | }
|
8455 |
|
8456 |
|
8457 |
|
8458 | if (emulationPreventionBytesPositions.length === 0) {
|
8459 | return data;
|
8460 | }
|
8461 |
|
8462 |
|
8463 | newLength = length - emulationPreventionBytesPositions.length;
|
8464 | newData = new Uint8Array(newLength);
|
8465 | var sourceIndex = 0;
|
8466 |
|
8467 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
8468 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
8469 |
|
8470 | sourceIndex++;
|
8471 |
|
8472 | emulationPreventionBytesPositions.shift();
|
8473 | }
|
8474 |
|
8475 | newData[i] = data[sourceIndex];
|
8476 | }
|
8477 |
|
8478 | return newData;
|
8479 | };
|
8480 | |
8481 |
|
8482 |
|
8483 |
|
8484 |
|
8485 |
|
8486 |
|
8487 |
|
8488 |
|
8489 |
|
8490 |
|
8491 | readSequenceParameterSet = function readSequenceParameterSet(data) {
|
8492 | var frameCropLeftOffset = 0,
|
8493 | frameCropRightOffset = 0,
|
8494 | frameCropTopOffset = 0,
|
8495 | frameCropBottomOffset = 0,
|
8496 | sarScale = 1,
|
8497 | expGolombDecoder,
|
8498 | profileIdc,
|
8499 | levelIdc,
|
8500 | profileCompatibility,
|
8501 | chromaFormatIdc,
|
8502 | picOrderCntType,
|
8503 | numRefFramesInPicOrderCntCycle,
|
8504 | picWidthInMbsMinus1,
|
8505 | picHeightInMapUnitsMinus1,
|
8506 | frameMbsOnlyFlag,
|
8507 | scalingListCount,
|
8508 | sarRatio,
|
8509 | aspectRatioIdc,
|
8510 | i;
|
8511 | expGolombDecoder = new expGolomb(data);
|
8512 | profileIdc = expGolombDecoder.readUnsignedByte();
|
8513 |
|
8514 | profileCompatibility = expGolombDecoder.readUnsignedByte();
|
8515 |
|
8516 | levelIdc = expGolombDecoder.readUnsignedByte();
|
8517 |
|
8518 | expGolombDecoder.skipUnsignedExpGolomb();
|
8519 |
|
8520 |
|
8521 | if (PROFILES_WITH_OPTIONAL_SPS_DATA[profileIdc]) {
|
8522 | chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
|
8523 |
|
8524 | if (chromaFormatIdc === 3) {
|
8525 | expGolombDecoder.skipBits(1);
|
8526 | }
|
8527 |
|
8528 | expGolombDecoder.skipUnsignedExpGolomb();
|
8529 |
|
8530 | expGolombDecoder.skipUnsignedExpGolomb();
|
8531 |
|
8532 | expGolombDecoder.skipBits(1);
|
8533 |
|
8534 | if (expGolombDecoder.readBoolean()) {
|
8535 |
|
8536 | scalingListCount = chromaFormatIdc !== 3 ? 8 : 12;
|
8537 |
|
8538 | for (i = 0; i < scalingListCount; i++) {
|
8539 | if (expGolombDecoder.readBoolean()) {
|
8540 |
|
8541 | if (i < 6) {
|
8542 | skipScalingList(16, expGolombDecoder);
|
8543 | } else {
|
8544 | skipScalingList(64, expGolombDecoder);
|
8545 | }
|
8546 | }
|
8547 | }
|
8548 | }
|
8549 | }
|
8550 |
|
8551 | expGolombDecoder.skipUnsignedExpGolomb();
|
8552 |
|
8553 | picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
|
8554 |
|
8555 | if (picOrderCntType === 0) {
|
8556 | expGolombDecoder.readUnsignedExpGolomb();
|
8557 | } else if (picOrderCntType === 1) {
|
8558 | expGolombDecoder.skipBits(1);
|
8559 |
|
8560 | expGolombDecoder.skipExpGolomb();
|
8561 |
|
8562 | expGolombDecoder.skipExpGolomb();
|
8563 |
|
8564 | numRefFramesInPicOrderCntCycle = expGolombDecoder.readUnsignedExpGolomb();
|
8565 |
|
8566 | for (i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
|
8567 | expGolombDecoder.skipExpGolomb();
|
8568 | }
|
8569 | }
|
8570 |
|
8571 | expGolombDecoder.skipUnsignedExpGolomb();
|
8572 |
|
8573 | expGolombDecoder.skipBits(1);
|
8574 |
|
8575 | picWidthInMbsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
8576 | picHeightInMapUnitsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
8577 | frameMbsOnlyFlag = expGolombDecoder.readBits(1);
|
8578 |
|
8579 | if (frameMbsOnlyFlag === 0) {
|
8580 | expGolombDecoder.skipBits(1);
|
8581 | }
|
8582 |
|
8583 | expGolombDecoder.skipBits(1);
|
8584 |
|
8585 | if (expGolombDecoder.readBoolean()) {
|
8586 |
|
8587 | frameCropLeftOffset = expGolombDecoder.readUnsignedExpGolomb();
|
8588 | frameCropRightOffset = expGolombDecoder.readUnsignedExpGolomb();
|
8589 | frameCropTopOffset = expGolombDecoder.readUnsignedExpGolomb();
|
8590 | frameCropBottomOffset = expGolombDecoder.readUnsignedExpGolomb();
|
8591 | }
|
8592 |
|
8593 | if (expGolombDecoder.readBoolean()) {
|
8594 |
|
8595 | if (expGolombDecoder.readBoolean()) {
|
8596 |
|
8597 | aspectRatioIdc = expGolombDecoder.readUnsignedByte();
|
8598 |
|
8599 | switch (aspectRatioIdc) {
|
8600 | case 1:
|
8601 | sarRatio = [1, 1];
|
8602 | break;
|
8603 |
|
8604 | case 2:
|
8605 | sarRatio = [12, 11];
|
8606 | break;
|
8607 |
|
8608 | case 3:
|
8609 | sarRatio = [10, 11];
|
8610 | break;
|
8611 |
|
8612 | case 4:
|
8613 | sarRatio = [16, 11];
|
8614 | break;
|
8615 |
|
8616 | case 5:
|
8617 | sarRatio = [40, 33];
|
8618 | break;
|
8619 |
|
8620 | case 6:
|
8621 | sarRatio = [24, 11];
|
8622 | break;
|
8623 |
|
8624 | case 7:
|
8625 | sarRatio = [20, 11];
|
8626 | break;
|
8627 |
|
8628 | case 8:
|
8629 | sarRatio = [32, 11];
|
8630 | break;
|
8631 |
|
8632 | case 9:
|
8633 | sarRatio = [80, 33];
|
8634 | break;
|
8635 |
|
8636 | case 10:
|
8637 | sarRatio = [18, 11];
|
8638 | break;
|
8639 |
|
8640 | case 11:
|
8641 | sarRatio = [15, 11];
|
8642 | break;
|
8643 |
|
8644 | case 12:
|
8645 | sarRatio = [64, 33];
|
8646 | break;
|
8647 |
|
8648 | case 13:
|
8649 | sarRatio = [160, 99];
|
8650 | break;
|
8651 |
|
8652 | case 14:
|
8653 | sarRatio = [4, 3];
|
8654 | break;
|
8655 |
|
8656 | case 15:
|
8657 | sarRatio = [3, 2];
|
8658 | break;
|
8659 |
|
8660 | case 16:
|
8661 | sarRatio = [2, 1];
|
8662 | break;
|
8663 |
|
8664 | case 255:
|
8665 | {
|
8666 | sarRatio = [expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte(), expGolombDecoder.readUnsignedByte() << 8 | expGolombDecoder.readUnsignedByte()];
|
8667 | break;
|
8668 | }
|
8669 | }
|
8670 |
|
8671 | if (sarRatio) {
|
8672 | sarScale = sarRatio[0] / sarRatio[1];
|
8673 | }
|
8674 | }
|
8675 | }
|
8676 |
|
8677 | return {
|
8678 | profileIdc: profileIdc,
|
8679 | levelIdc: levelIdc,
|
8680 | profileCompatibility: profileCompatibility,
|
8681 | width: Math.ceil(((picWidthInMbsMinus1 + 1) * 16 - frameCropLeftOffset * 2 - frameCropRightOffset * 2) * sarScale),
|
8682 | height: (2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16 - frameCropTopOffset * 2 - frameCropBottomOffset * 2,
|
8683 | sarRatio: sarRatio
|
8684 | };
|
8685 | };
|
8686 | };
|
8687 |
|
8688 | _H264Stream.prototype = new stream();
|
8689 | var h264 = {
|
8690 | H264Stream: _H264Stream,
|
8691 | NalByteStream: _NalByteStream
|
8692 | };
|
8693 | |
8694 |
|
8695 |
|
8696 |
|
8697 |
|
8698 |
|
8699 |
|
8700 |
|
8701 |
|
8702 | var ADTS_SAMPLING_FREQUENCIES = [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
|
8703 |
|
8704 | var parseId3TagSize = function parseId3TagSize(header, byteIndex) {
|
8705 | var returnSize = header[byteIndex + 6] << 21 | header[byteIndex + 7] << 14 | header[byteIndex + 8] << 7 | header[byteIndex + 9],
|
8706 | flags = header[byteIndex + 5],
|
8707 | footerPresent = (flags & 16) >> 4;
|
8708 |
|
8709 | returnSize = returnSize >= 0 ? returnSize : 0;
|
8710 |
|
8711 | if (footerPresent) {
|
8712 | return returnSize + 20;
|
8713 | }
|
8714 |
|
8715 | return returnSize + 10;
|
8716 | };
|
8717 |
|
8718 | var getId3Offset = function getId3Offset(data, offset) {
|
8719 | if (data.length - offset < 10 || data[offset] !== 'I'.charCodeAt(0) || data[offset + 1] !== 'D'.charCodeAt(0) || data[offset + 2] !== '3'.charCodeAt(0)) {
|
8720 | return offset;
|
8721 | }
|
8722 |
|
8723 | offset += parseId3TagSize(data, offset);
|
8724 | return getId3Offset(data, offset);
|
8725 | };
|
8726 |
|
8727 |
|
8728 | var isLikelyAacData$2 = function isLikelyAacData(data) {
|
8729 | var offset = getId3Offset(data, 0);
|
8730 | return data.length >= offset + 2 && (data[offset] & 0xFF) === 0xFF && (data[offset + 1] & 0xF0) === 0xF0 &&
|
8731 |
|
8732 | (data[offset + 1] & 0x16) === 0x10;
|
8733 | };
|
8734 |
|
8735 | var parseSyncSafeInteger = function parseSyncSafeInteger(data) {
|
8736 | return data[0] << 21 | data[1] << 14 | data[2] << 7 | data[3];
|
8737 | };
|
8738 |
|
8739 |
|
8740 |
|
8741 | var percentEncode = function percentEncode(bytes, start, end) {
|
8742 | var i,
|
8743 | result = '';
|
8744 |
|
8745 | for (i = start; i < end; i++) {
|
8746 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
8747 | }
|
8748 |
|
8749 | return result;
|
8750 | };
|
8751 |
|
8752 |
|
8753 |
|
8754 | var parseIso88591 = function parseIso88591(bytes, start, end) {
|
8755 | return unescape(percentEncode(bytes, start, end));
|
8756 | };
|
8757 |
|
8758 | var parseAdtsSize = function parseAdtsSize(header, byteIndex) {
|
8759 | var lowThree = (header[byteIndex + 5] & 0xE0) >> 5,
|
8760 | middle = header[byteIndex + 4] << 3,
|
8761 | highTwo = header[byteIndex + 3] & 0x3 << 11;
|
8762 | return highTwo | middle | lowThree;
|
8763 | };
|
8764 |
|
8765 | var parseType$1 = function parseType(header, byteIndex) {
|
8766 | if (header[byteIndex] === 'I'.charCodeAt(0) && header[byteIndex + 1] === 'D'.charCodeAt(0) && header[byteIndex + 2] === '3'.charCodeAt(0)) {
|
8767 | return 'timed-metadata';
|
8768 | } else if (header[byteIndex] & 0xff === 0xff && (header[byteIndex + 1] & 0xf0) === 0xf0) {
|
8769 | return 'audio';
|
8770 | }
|
8771 |
|
8772 | return null;
|
8773 | };
|
8774 |
|
8775 | var parseSampleRate = function parseSampleRate(packet) {
|
8776 | var i = 0;
|
8777 |
|
8778 | while (i + 5 < packet.length) {
|
8779 | if (packet[i] !== 0xFF || (packet[i + 1] & 0xF6) !== 0xF0) {
|
8780 |
|
8781 |
|
8782 | i++;
|
8783 | continue;
|
8784 | }
|
8785 |
|
8786 | return ADTS_SAMPLING_FREQUENCIES[(packet[i + 2] & 0x3c) >>> 2];
|
8787 | }
|
8788 |
|
8789 | return null;
|
8790 | };
|
8791 |
|
8792 | var parseAacTimestamp = function parseAacTimestamp(packet) {
|
8793 | var frameStart, frameSize, frame, frameHeader;
|
8794 |
|
8795 | frameStart = 10;
|
8796 |
|
8797 | if (packet[5] & 0x40) {
|
8798 |
|
8799 | frameStart += 4;
|
8800 |
|
8801 | frameStart += parseSyncSafeInteger(packet.subarray(10, 14));
|
8802 | }
|
8803 |
|
8804 |
|
8805 |
|
8806 | do {
|
8807 |
|
8808 | frameSize = parseSyncSafeInteger(packet.subarray(frameStart + 4, frameStart + 8));
|
8809 |
|
8810 | if (frameSize < 1) {
|
8811 | return null;
|
8812 | }
|
8813 |
|
8814 | frameHeader = String.fromCharCode(packet[frameStart], packet[frameStart + 1], packet[frameStart + 2], packet[frameStart + 3]);
|
8815 |
|
8816 | if (frameHeader === 'PRIV') {
|
8817 | frame = packet.subarray(frameStart + 10, frameStart + frameSize + 10);
|
8818 |
|
8819 | for (var i = 0; i < frame.byteLength; i++) {
|
8820 | if (frame[i] === 0) {
|
8821 | var owner = parseIso88591(frame, 0, i);
|
8822 |
|
8823 | if (owner === 'com.apple.streaming.transportStreamTimestamp') {
|
8824 | var d = frame.subarray(i + 1);
|
8825 | var size = (d[3] & 0x01) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
|
8826 | size *= 4;
|
8827 | size += d[7] & 0x03;
|
8828 | return size;
|
8829 | }
|
8830 |
|
8831 | break;
|
8832 | }
|
8833 | }
|
8834 | }
|
8835 |
|
8836 | frameStart += 10;
|
8837 |
|
8838 | frameStart += frameSize;
|
8839 | } while (frameStart < packet.byteLength);
|
8840 |
|
8841 | return null;
|
8842 | };
|
8843 |
|
8844 | var utils = {
|
8845 | isLikelyAacData: isLikelyAacData$2,
|
8846 | parseId3TagSize: parseId3TagSize,
|
8847 | parseAdtsSize: parseAdtsSize,
|
8848 | parseType: parseType$1,
|
8849 | parseSampleRate: parseSampleRate,
|
8850 | parseAacTimestamp: parseAacTimestamp
|
8851 | };
|
8852 |
|
8853 | var _AacStream;
|
8854 | |
8855 |
|
8856 |
|
8857 |
|
8858 |
|
8859 | _AacStream = function AacStream() {
|
8860 | var everything = new Uint8Array(),
|
8861 | timeStamp = 0;
|
8862 |
|
8863 | _AacStream.prototype.init.call(this);
|
8864 |
|
8865 | this.setTimestamp = function (timestamp) {
|
8866 | timeStamp = timestamp;
|
8867 | };
|
8868 |
|
8869 | this.push = function (bytes) {
|
8870 | var frameSize = 0,
|
8871 | byteIndex = 0,
|
8872 | bytesLeft,
|
8873 | chunk,
|
8874 | packet,
|
8875 | tempLength;
|
8876 |
|
8877 |
|
8878 | if (everything.length) {
|
8879 | tempLength = everything.length;
|
8880 | everything = new Uint8Array(bytes.byteLength + tempLength);
|
8881 | everything.set(everything.subarray(0, tempLength));
|
8882 | everything.set(bytes, tempLength);
|
8883 | } else {
|
8884 | everything = bytes;
|
8885 | }
|
8886 |
|
8887 | while (everything.length - byteIndex >= 3) {
|
8888 | if (everything[byteIndex] === 'I'.charCodeAt(0) && everything[byteIndex + 1] === 'D'.charCodeAt(0) && everything[byteIndex + 2] === '3'.charCodeAt(0)) {
|
8889 |
|
8890 |
|
8891 | if (everything.length - byteIndex < 10) {
|
8892 | break;
|
8893 | }
|
8894 |
|
8895 |
|
8896 | frameSize = utils.parseId3TagSize(everything, byteIndex);
|
8897 |
|
8898 |
|
8899 |
|
8900 | if (byteIndex + frameSize > everything.length) {
|
8901 | break;
|
8902 | }
|
8903 |
|
8904 | chunk = {
|
8905 | type: 'timed-metadata',
|
8906 | data: everything.subarray(byteIndex, byteIndex + frameSize)
|
8907 | };
|
8908 | this.trigger('data', chunk);
|
8909 | byteIndex += frameSize;
|
8910 | continue;
|
8911 | } else if ((everything[byteIndex] & 0xff) === 0xff && (everything[byteIndex + 1] & 0xf0) === 0xf0) {
|
8912 |
|
8913 |
|
8914 | if (everything.length - byteIndex < 7) {
|
8915 | break;
|
8916 | }
|
8917 |
|
8918 | frameSize = utils.parseAdtsSize(everything, byteIndex);
|
8919 |
|
8920 |
|
8921 | if (byteIndex + frameSize > everything.length) {
|
8922 | break;
|
8923 | }
|
8924 |
|
8925 | packet = {
|
8926 | type: 'audio',
|
8927 | data: everything.subarray(byteIndex, byteIndex + frameSize),
|
8928 | pts: timeStamp,
|
8929 | dts: timeStamp
|
8930 | };
|
8931 | this.trigger('data', packet);
|
8932 | byteIndex += frameSize;
|
8933 | continue;
|
8934 | }
|
8935 |
|
8936 | byteIndex++;
|
8937 | }
|
8938 |
|
8939 | bytesLeft = everything.length - byteIndex;
|
8940 |
|
8941 | if (bytesLeft > 0) {
|
8942 | everything = everything.subarray(byteIndex);
|
8943 | } else {
|
8944 | everything = new Uint8Array();
|
8945 | }
|
8946 | };
|
8947 |
|
8948 | this.reset = function () {
|
8949 | everything = new Uint8Array();
|
8950 | this.trigger('reset');
|
8951 | };
|
8952 |
|
8953 | this.endTimeline = function () {
|
8954 | everything = new Uint8Array();
|
8955 | this.trigger('endedtimeline');
|
8956 | };
|
8957 | };
|
8958 |
|
8959 | _AacStream.prototype = new stream();
|
8960 | var aac = _AacStream;
|
8961 |
|
8962 | var AUDIO_PROPERTIES = ['audioobjecttype', 'channelcount', 'samplerate', 'samplingfrequencyindex', 'samplesize'];
|
8963 | var audioProperties = AUDIO_PROPERTIES;
|
8964 | var VIDEO_PROPERTIES = ['width', 'height', 'profileIdc', 'levelIdc', 'profileCompatibility', 'sarRatio'];
|
8965 | var videoProperties = VIDEO_PROPERTIES;
|
8966 | var H264Stream = h264.H264Stream;
|
8967 | var isLikelyAacData$1 = utils.isLikelyAacData;
|
8968 | var ONE_SECOND_IN_TS$1 = clock.ONE_SECOND_IN_TS;
|
8969 |
|
8970 | var _VideoSegmentStream, _AudioSegmentStream, _Transmuxer, _CoalesceStream;
|
8971 | |
8972 |
|
8973 |
|
8974 |
|
8975 |
|
8976 | var arrayEquals = function arrayEquals(a, b) {
|
8977 | var i;
|
8978 |
|
8979 | if (a.length !== b.length) {
|
8980 | return false;
|
8981 | }
|
8982 |
|
8983 |
|
8984 | for (i = 0; i < a.length; i++) {
|
8985 | if (a[i] !== b[i]) {
|
8986 | return false;
|
8987 | }
|
8988 | }
|
8989 |
|
8990 | return true;
|
8991 | };
|
8992 |
|
8993 | var generateSegmentTimingInfo = function generateSegmentTimingInfo(baseMediaDecodeTime, startDts, startPts, endDts, endPts, prependedContentDuration) {
|
8994 | var ptsOffsetFromDts = startPts - startDts,
|
8995 | decodeDuration = endDts - startDts,
|
8996 | presentationDuration = endPts - startPts;
|
8997 |
|
8998 |
|
8999 |
|
9000 |
|
9001 | return {
|
9002 | start: {
|
9003 | dts: baseMediaDecodeTime,
|
9004 | pts: baseMediaDecodeTime + ptsOffsetFromDts
|
9005 | },
|
9006 | end: {
|
9007 | dts: baseMediaDecodeTime + decodeDuration,
|
9008 | pts: baseMediaDecodeTime + presentationDuration
|
9009 | },
|
9010 | prependedContentDuration: prependedContentDuration,
|
9011 | baseMediaDecodeTime: baseMediaDecodeTime
|
9012 | };
|
9013 | };
|
9014 | |
9015 |
|
9016 |
|
9017 |
|
9018 |
|
9019 |
|
9020 |
|
9021 |
|
9022 |
|
9023 |
|
9024 |
|
9025 | _AudioSegmentStream = function AudioSegmentStream(track, options) {
|
9026 | var adtsFrames = [],
|
9027 | sequenceNumber = 0,
|
9028 | earliestAllowedDts = 0,
|
9029 | audioAppendStartTs = 0,
|
9030 | videoBaseMediaDecodeTime = Infinity;
|
9031 | options = options || {};
|
9032 |
|
9033 | _AudioSegmentStream.prototype.init.call(this);
|
9034 |
|
9035 | this.push = function (data) {
|
9036 | trackDecodeInfo.collectDtsInfo(track, data);
|
9037 |
|
9038 | if (track) {
|
9039 | audioProperties.forEach(function (prop) {
|
9040 | track[prop] = data[prop];
|
9041 | });
|
9042 | }
|
9043 |
|
9044 |
|
9045 | adtsFrames.push(data);
|
9046 | };
|
9047 |
|
9048 | this.setEarliestDts = function (earliestDts) {
|
9049 | earliestAllowedDts = earliestDts;
|
9050 | };
|
9051 |
|
9052 | this.setVideoBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
9053 | videoBaseMediaDecodeTime = baseMediaDecodeTime;
|
9054 | };
|
9055 |
|
9056 | this.setAudioAppendStart = function (timestamp) {
|
9057 | audioAppendStartTs = timestamp;
|
9058 | };
|
9059 |
|
9060 | this.flush = function () {
|
9061 | var frames, moof, mdat, boxes, frameDuration, segmentDuration, videoClockCyclesOfSilencePrefixed;
|
9062 |
|
9063 | if (adtsFrames.length === 0) {
|
9064 | this.trigger('done', 'AudioSegmentStream');
|
9065 | return;
|
9066 | }
|
9067 |
|
9068 | frames = audioFrameUtils.trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts);
|
9069 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
9070 |
|
9071 | videoClockCyclesOfSilencePrefixed = audioFrameUtils.prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime);
|
9072 |
|
9073 |
|
9074 | track.samples = audioFrameUtils.generateSampleTable(frames);
|
9075 |
|
9076 | mdat = mp4Generator.mdat(audioFrameUtils.concatenateFrameData(frames));
|
9077 | adtsFrames = [];
|
9078 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
9079 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
9080 |
|
9081 | sequenceNumber++;
|
9082 | boxes.set(moof);
|
9083 | boxes.set(mdat, moof.byteLength);
|
9084 | trackDecodeInfo.clearDtsInfo(track);
|
9085 | frameDuration = Math.ceil(ONE_SECOND_IN_TS$1 * 1024 / track.samplerate);
|
9086 |
|
9087 |
|
9088 |
|
9089 |
|
9090 | if (frames.length) {
|
9091 | segmentDuration = frames.length * frameDuration;
|
9092 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(
|
9093 |
|
9094 |
|
9095 | clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate),
|
9096 | frames[0].dts, frames[0].pts, frames[0].dts + segmentDuration, frames[0].pts + segmentDuration, videoClockCyclesOfSilencePrefixed || 0));
|
9097 | this.trigger('timingInfo', {
|
9098 | start: frames[0].pts,
|
9099 | end: frames[0].pts + segmentDuration
|
9100 | });
|
9101 | }
|
9102 |
|
9103 | this.trigger('data', {
|
9104 | track: track,
|
9105 | boxes: boxes
|
9106 | });
|
9107 | this.trigger('done', 'AudioSegmentStream');
|
9108 | };
|
9109 |
|
9110 | this.reset = function () {
|
9111 | trackDecodeInfo.clearDtsInfo(track);
|
9112 | adtsFrames = [];
|
9113 | this.trigger('reset');
|
9114 | };
|
9115 | };
|
9116 |
|
9117 | _AudioSegmentStream.prototype = new stream();
|
9118 | |
9119 |
|
9120 |
|
9121 |
|
9122 |
|
9123 |
|
9124 |
|
9125 |
|
9126 |
|
9127 |
|
9128 |
|
9129 |
|
9130 | _VideoSegmentStream = function VideoSegmentStream(track, options) {
|
9131 | var sequenceNumber = 0,
|
9132 | nalUnits = [],
|
9133 | gopsToAlignWith = [],
|
9134 | config,
|
9135 | pps;
|
9136 | options = options || {};
|
9137 |
|
9138 | _VideoSegmentStream.prototype.init.call(this);
|
9139 |
|
9140 | delete track.minPTS;
|
9141 | this.gopCache_ = [];
|
9142 | |
9143 |
|
9144 |
|
9145 |
|
9146 |
|
9147 |
|
9148 |
|
9149 |
|
9150 |
|
9151 | this.push = function (nalUnit) {
|
9152 | trackDecodeInfo.collectDtsInfo(track, nalUnit);
|
9153 |
|
9154 | if (nalUnit.nalUnitType === 'seq_parameter_set_rbsp' && !config) {
|
9155 | config = nalUnit.config;
|
9156 | track.sps = [nalUnit.data];
|
9157 | videoProperties.forEach(function (prop) {
|
9158 | track[prop] = config[prop];
|
9159 | }, this);
|
9160 | }
|
9161 |
|
9162 | if (nalUnit.nalUnitType === 'pic_parameter_set_rbsp' && !pps) {
|
9163 | pps = nalUnit.data;
|
9164 | track.pps = [nalUnit.data];
|
9165 | }
|
9166 |
|
9167 |
|
9168 | nalUnits.push(nalUnit);
|
9169 | };
|
9170 | |
9171 |
|
9172 |
|
9173 |
|
9174 |
|
9175 |
|
9176 | this.flush = function () {
|
9177 | var frames,
|
9178 | gopForFusion,
|
9179 | gops,
|
9180 | moof,
|
9181 | mdat,
|
9182 | boxes,
|
9183 | prependedContentDuration = 0,
|
9184 | firstGop,
|
9185 | lastGop;
|
9186 |
|
9187 |
|
9188 | while (nalUnits.length) {
|
9189 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
9190 | break;
|
9191 | }
|
9192 |
|
9193 | nalUnits.shift();
|
9194 | }
|
9195 |
|
9196 |
|
9197 | if (nalUnits.length === 0) {
|
9198 | this.resetStream_();
|
9199 | this.trigger('done', 'VideoSegmentStream');
|
9200 | return;
|
9201 | }
|
9202 |
|
9203 |
|
9204 |
|
9205 |
|
9206 | frames = frameUtils.groupNalsIntoFrames(nalUnits);
|
9207 | gops = frameUtils.groupFramesIntoGops(frames);
|
9208 |
|
9209 |
|
9210 |
|
9211 |
|
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 |
|
9226 | if (!gops[0][0].keyFrame) {
|
9227 |
|
9228 | gopForFusion = this.getGopForFusion_(nalUnits[0], track);
|
9229 |
|
9230 | if (gopForFusion) {
|
9231 |
|
9232 |
|
9233 | prependedContentDuration = gopForFusion.duration;
|
9234 | gops.unshift(gopForFusion);
|
9235 |
|
9236 |
|
9237 | gops.byteLength += gopForFusion.byteLength;
|
9238 | gops.nalCount += gopForFusion.nalCount;
|
9239 | gops.pts = gopForFusion.pts;
|
9240 | gops.dts = gopForFusion.dts;
|
9241 | gops.duration += gopForFusion.duration;
|
9242 | } else {
|
9243 |
|
9244 | gops = frameUtils.extendFirstKeyFrame(gops);
|
9245 | }
|
9246 | }
|
9247 |
|
9248 |
|
9249 | if (gopsToAlignWith.length) {
|
9250 | var alignedGops;
|
9251 |
|
9252 | if (options.alignGopsAtEnd) {
|
9253 | alignedGops = this.alignGopsAtEnd_(gops);
|
9254 | } else {
|
9255 | alignedGops = this.alignGopsAtStart_(gops);
|
9256 | }
|
9257 |
|
9258 | if (!alignedGops) {
|
9259 |
|
9260 | this.gopCache_.unshift({
|
9261 | gop: gops.pop(),
|
9262 | pps: track.pps,
|
9263 | sps: track.sps
|
9264 | });
|
9265 |
|
9266 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
9267 |
|
9268 | nalUnits = [];
|
9269 |
|
9270 | this.resetStream_();
|
9271 | this.trigger('done', 'VideoSegmentStream');
|
9272 | return;
|
9273 | }
|
9274 |
|
9275 |
|
9276 |
|
9277 | trackDecodeInfo.clearDtsInfo(track);
|
9278 | gops = alignedGops;
|
9279 | }
|
9280 |
|
9281 | trackDecodeInfo.collectDtsInfo(track, gops);
|
9282 |
|
9283 |
|
9284 | track.samples = frameUtils.generateSampleTable(gops);
|
9285 |
|
9286 | mdat = mp4Generator.mdat(frameUtils.concatenateNalData(gops));
|
9287 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
9288 | this.trigger('processedGopsInfo', gops.map(function (gop) {
|
9289 | return {
|
9290 | pts: gop.pts,
|
9291 | dts: gop.dts,
|
9292 | byteLength: gop.byteLength
|
9293 | };
|
9294 | }));
|
9295 | firstGop = gops[0];
|
9296 | lastGop = gops[gops.length - 1];
|
9297 | this.trigger('segmentTimingInfo', generateSegmentTimingInfo(track.baseMediaDecodeTime, firstGop.dts, firstGop.pts, lastGop.dts + lastGop.duration, lastGop.pts + lastGop.duration, prependedContentDuration));
|
9298 | this.trigger('timingInfo', {
|
9299 | start: gops[0].pts,
|
9300 | end: gops[gops.length - 1].pts + gops[gops.length - 1].duration
|
9301 | });
|
9302 |
|
9303 | this.gopCache_.unshift({
|
9304 | gop: gops.pop(),
|
9305 | pps: track.pps,
|
9306 | sps: track.sps
|
9307 | });
|
9308 |
|
9309 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
9310 |
|
9311 | nalUnits = [];
|
9312 | this.trigger('baseMediaDecodeTime', track.baseMediaDecodeTime);
|
9313 | this.trigger('timelineStartInfo', track.timelineStartInfo);
|
9314 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
9315 |
|
9316 |
|
9317 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
9318 |
|
9319 | sequenceNumber++;
|
9320 | boxes.set(moof);
|
9321 | boxes.set(mdat, moof.byteLength);
|
9322 | this.trigger('data', {
|
9323 | track: track,
|
9324 | boxes: boxes
|
9325 | });
|
9326 | this.resetStream_();
|
9327 |
|
9328 | this.trigger('done', 'VideoSegmentStream');
|
9329 | };
|
9330 |
|
9331 | this.reset = function () {
|
9332 | this.resetStream_();
|
9333 | nalUnits = [];
|
9334 | this.gopCache_.length = 0;
|
9335 | gopsToAlignWith.length = 0;
|
9336 | this.trigger('reset');
|
9337 | };
|
9338 |
|
9339 | this.resetStream_ = function () {
|
9340 | trackDecodeInfo.clearDtsInfo(track);
|
9341 |
|
9342 |
|
9343 | config = undefined;
|
9344 | pps = undefined;
|
9345 | };
|
9346 |
|
9347 |
|
9348 |
|
9349 | this.getGopForFusion_ = function (nalUnit) {
|
9350 | var halfSecond = 45000,
|
9351 |
|
9352 | allowableOverlap = 10000,
|
9353 |
|
9354 | nearestDistance = Infinity,
|
9355 | dtsDistance,
|
9356 | nearestGopObj,
|
9357 | currentGop,
|
9358 | currentGopObj,
|
9359 | i;
|
9360 |
|
9361 | for (i = 0; i < this.gopCache_.length; i++) {
|
9362 | currentGopObj = this.gopCache_[i];
|
9363 | currentGop = currentGopObj.gop;
|
9364 |
|
9365 | if (!(track.pps && arrayEquals(track.pps[0], currentGopObj.pps[0])) || !(track.sps && arrayEquals(track.sps[0], currentGopObj.sps[0]))) {
|
9366 | continue;
|
9367 | }
|
9368 |
|
9369 |
|
9370 | if (currentGop.dts < track.timelineStartInfo.dts) {
|
9371 | continue;
|
9372 | }
|
9373 |
|
9374 |
|
9375 | dtsDistance = nalUnit.dts - currentGop.dts - currentGop.duration;
|
9376 |
|
9377 |
|
9378 | if (dtsDistance >= -allowableOverlap && dtsDistance <= halfSecond) {
|
9379 |
|
9380 |
|
9381 | if (!nearestGopObj || nearestDistance > dtsDistance) {
|
9382 | nearestGopObj = currentGopObj;
|
9383 | nearestDistance = dtsDistance;
|
9384 | }
|
9385 | }
|
9386 | }
|
9387 |
|
9388 | if (nearestGopObj) {
|
9389 | return nearestGopObj.gop;
|
9390 | }
|
9391 |
|
9392 | return null;
|
9393 | };
|
9394 |
|
9395 |
|
9396 |
|
9397 | this.alignGopsAtStart_ = function (gops) {
|
9398 | var alignIndex, gopIndex, align, gop, byteLength, nalCount, duration, alignedGops;
|
9399 | byteLength = gops.byteLength;
|
9400 | nalCount = gops.nalCount;
|
9401 | duration = gops.duration;
|
9402 | alignIndex = gopIndex = 0;
|
9403 |
|
9404 | while (alignIndex < gopsToAlignWith.length && gopIndex < gops.length) {
|
9405 | align = gopsToAlignWith[alignIndex];
|
9406 | gop = gops[gopIndex];
|
9407 |
|
9408 | if (align.pts === gop.pts) {
|
9409 | break;
|
9410 | }
|
9411 |
|
9412 | if (gop.pts > align.pts) {
|
9413 |
|
9414 |
|
9415 | alignIndex++;
|
9416 | continue;
|
9417 | }
|
9418 |
|
9419 |
|
9420 |
|
9421 | gopIndex++;
|
9422 | byteLength -= gop.byteLength;
|
9423 | nalCount -= gop.nalCount;
|
9424 | duration -= gop.duration;
|
9425 | }
|
9426 |
|
9427 | if (gopIndex === 0) {
|
9428 |
|
9429 | return gops;
|
9430 | }
|
9431 |
|
9432 | if (gopIndex === gops.length) {
|
9433 |
|
9434 | return null;
|
9435 | }
|
9436 |
|
9437 | alignedGops = gops.slice(gopIndex);
|
9438 | alignedGops.byteLength = byteLength;
|
9439 | alignedGops.duration = duration;
|
9440 | alignedGops.nalCount = nalCount;
|
9441 | alignedGops.pts = alignedGops[0].pts;
|
9442 | alignedGops.dts = alignedGops[0].dts;
|
9443 | return alignedGops;
|
9444 | };
|
9445 |
|
9446 |
|
9447 |
|
9448 | this.alignGopsAtEnd_ = function (gops) {
|
9449 | var alignIndex, gopIndex, align, gop, alignEndIndex, matchFound;
|
9450 | alignIndex = gopsToAlignWith.length - 1;
|
9451 | gopIndex = gops.length - 1;
|
9452 | alignEndIndex = null;
|
9453 | matchFound = false;
|
9454 |
|
9455 | while (alignIndex >= 0 && gopIndex >= 0) {
|
9456 | align = gopsToAlignWith[alignIndex];
|
9457 | gop = gops[gopIndex];
|
9458 |
|
9459 | if (align.pts === gop.pts) {
|
9460 | matchFound = true;
|
9461 | break;
|
9462 | }
|
9463 |
|
9464 | if (align.pts > gop.pts) {
|
9465 | alignIndex--;
|
9466 | continue;
|
9467 | }
|
9468 |
|
9469 | if (alignIndex === gopsToAlignWith.length - 1) {
|
9470 |
|
9471 |
|
9472 |
|
9473 | alignEndIndex = gopIndex;
|
9474 | }
|
9475 |
|
9476 | gopIndex--;
|
9477 | }
|
9478 |
|
9479 | if (!matchFound && alignEndIndex === null) {
|
9480 | return null;
|
9481 | }
|
9482 |
|
9483 | var trimIndex;
|
9484 |
|
9485 | if (matchFound) {
|
9486 | trimIndex = gopIndex;
|
9487 | } else {
|
9488 | trimIndex = alignEndIndex;
|
9489 | }
|
9490 |
|
9491 | if (trimIndex === 0) {
|
9492 | return gops;
|
9493 | }
|
9494 |
|
9495 | var alignedGops = gops.slice(trimIndex);
|
9496 | var metadata = alignedGops.reduce(function (total, gop) {
|
9497 | total.byteLength += gop.byteLength;
|
9498 | total.duration += gop.duration;
|
9499 | total.nalCount += gop.nalCount;
|
9500 | return total;
|
9501 | }, {
|
9502 | byteLength: 0,
|
9503 | duration: 0,
|
9504 | nalCount: 0
|
9505 | });
|
9506 | alignedGops.byteLength = metadata.byteLength;
|
9507 | alignedGops.duration = metadata.duration;
|
9508 | alignedGops.nalCount = metadata.nalCount;
|
9509 | alignedGops.pts = alignedGops[0].pts;
|
9510 | alignedGops.dts = alignedGops[0].dts;
|
9511 | return alignedGops;
|
9512 | };
|
9513 |
|
9514 | this.alignGopsWith = function (newGopsToAlignWith) {
|
9515 | gopsToAlignWith = newGopsToAlignWith;
|
9516 | };
|
9517 | };
|
9518 |
|
9519 | _VideoSegmentStream.prototype = new stream();
|
9520 | |
9521 |
|
9522 |
|
9523 |
|
9524 |
|
9525 |
|
9526 |
|
9527 |
|
9528 |
|
9529 | _CoalesceStream = function CoalesceStream(options, metadataStream) {
|
9530 |
|
9531 |
|
9532 |
|
9533 | this.numberOfTracks = 0;
|
9534 | this.metadataStream = metadataStream;
|
9535 | options = options || {};
|
9536 |
|
9537 | if (typeof options.remux !== 'undefined') {
|
9538 | this.remuxTracks = !!options.remux;
|
9539 | } else {
|
9540 | this.remuxTracks = true;
|
9541 | }
|
9542 |
|
9543 | if (typeof options.keepOriginalTimestamps === 'boolean') {
|
9544 | this.keepOriginalTimestamps = options.keepOriginalTimestamps;
|
9545 | } else {
|
9546 | this.keepOriginalTimestamps = false;
|
9547 | }
|
9548 |
|
9549 | this.pendingTracks = [];
|
9550 | this.videoTrack = null;
|
9551 | this.pendingBoxes = [];
|
9552 | this.pendingCaptions = [];
|
9553 | this.pendingMetadata = [];
|
9554 | this.pendingBytes = 0;
|
9555 | this.emittedTracks = 0;
|
9556 |
|
9557 | _CoalesceStream.prototype.init.call(this);
|
9558 |
|
9559 |
|
9560 | this.push = function (output) {
|
9561 |
|
9562 |
|
9563 | if (output.text) {
|
9564 | return this.pendingCaptions.push(output);
|
9565 | }
|
9566 |
|
9567 |
|
9568 | if (output.frames) {
|
9569 | return this.pendingMetadata.push(output);
|
9570 | }
|
9571 |
|
9572 |
|
9573 |
|
9574 |
|
9575 | this.pendingTracks.push(output.track);
|
9576 | this.pendingBytes += output.boxes.byteLength;
|
9577 |
|
9578 |
|
9579 |
|
9580 |
|
9581 |
|
9582 |
|
9583 | if (output.track.type === 'video') {
|
9584 | this.videoTrack = output.track;
|
9585 | this.pendingBoxes.push(output.boxes);
|
9586 | }
|
9587 |
|
9588 | if (output.track.type === 'audio') {
|
9589 | this.audioTrack = output.track;
|
9590 | this.pendingBoxes.unshift(output.boxes);
|
9591 | }
|
9592 | };
|
9593 | };
|
9594 |
|
9595 | _CoalesceStream.prototype = new stream();
|
9596 |
|
9597 | _CoalesceStream.prototype.flush = function (flushSource) {
|
9598 | var offset = 0,
|
9599 | event = {
|
9600 | captions: [],
|
9601 | captionStreams: {},
|
9602 | metadata: [],
|
9603 | info: {}
|
9604 | },
|
9605 | caption,
|
9606 | id3,
|
9607 | initSegment,
|
9608 | timelineStartPts = 0,
|
9609 | i;
|
9610 |
|
9611 | if (this.pendingTracks.length < this.numberOfTracks) {
|
9612 | if (flushSource !== 'VideoSegmentStream' && flushSource !== 'AudioSegmentStream') {
|
9613 |
|
9614 |
|
9615 |
|
9616 | return;
|
9617 | } else if (this.remuxTracks) {
|
9618 |
|
9619 |
|
9620 | return;
|
9621 | } else if (this.pendingTracks.length === 0) {
|
9622 |
|
9623 |
|
9624 |
|
9625 |
|
9626 |
|
9627 |
|
9628 | this.emittedTracks++;
|
9629 |
|
9630 | if (this.emittedTracks >= this.numberOfTracks) {
|
9631 | this.trigger('done');
|
9632 | this.emittedTracks = 0;
|
9633 | }
|
9634 |
|
9635 | return;
|
9636 | }
|
9637 | }
|
9638 |
|
9639 | if (this.videoTrack) {
|
9640 | timelineStartPts = this.videoTrack.timelineStartInfo.pts;
|
9641 | videoProperties.forEach(function (prop) {
|
9642 | event.info[prop] = this.videoTrack[prop];
|
9643 | }, this);
|
9644 | } else if (this.audioTrack) {
|
9645 | timelineStartPts = this.audioTrack.timelineStartInfo.pts;
|
9646 | audioProperties.forEach(function (prop) {
|
9647 | event.info[prop] = this.audioTrack[prop];
|
9648 | }, this);
|
9649 | }
|
9650 |
|
9651 | if (this.videoTrack || this.audioTrack) {
|
9652 | if (this.pendingTracks.length === 1) {
|
9653 | event.type = this.pendingTracks[0].type;
|
9654 | } else {
|
9655 | event.type = 'combined';
|
9656 | }
|
9657 |
|
9658 | this.emittedTracks += this.pendingTracks.length;
|
9659 | initSegment = mp4Generator.initSegment(this.pendingTracks);
|
9660 |
|
9661 | event.initSegment = new Uint8Array(initSegment.byteLength);
|
9662 |
|
9663 |
|
9664 | event.initSegment.set(initSegment);
|
9665 |
|
9666 | event.data = new Uint8Array(this.pendingBytes);
|
9667 |
|
9668 | for (i = 0; i < this.pendingBoxes.length; i++) {
|
9669 | event.data.set(this.pendingBoxes[i], offset);
|
9670 | offset += this.pendingBoxes[i].byteLength;
|
9671 | }
|
9672 |
|
9673 |
|
9674 |
|
9675 | for (i = 0; i < this.pendingCaptions.length; i++) {
|
9676 | caption = this.pendingCaptions[i];
|
9677 | caption.startTime = clock.metadataTsToSeconds(caption.startPts, timelineStartPts, this.keepOriginalTimestamps);
|
9678 | caption.endTime = clock.metadataTsToSeconds(caption.endPts, timelineStartPts, this.keepOriginalTimestamps);
|
9679 | event.captionStreams[caption.stream] = true;
|
9680 | event.captions.push(caption);
|
9681 | }
|
9682 |
|
9683 |
|
9684 |
|
9685 | for (i = 0; i < this.pendingMetadata.length; i++) {
|
9686 | id3 = this.pendingMetadata[i];
|
9687 | id3.cueTime = clock.metadataTsToSeconds(id3.pts, timelineStartPts, this.keepOriginalTimestamps);
|
9688 | event.metadata.push(id3);
|
9689 | }
|
9690 |
|
9691 |
|
9692 |
|
9693 | event.metadata.dispatchType = this.metadataStream.dispatchType;
|
9694 |
|
9695 | this.pendingTracks.length = 0;
|
9696 | this.videoTrack = null;
|
9697 | this.pendingBoxes.length = 0;
|
9698 | this.pendingCaptions.length = 0;
|
9699 | this.pendingBytes = 0;
|
9700 | this.pendingMetadata.length = 0;
|
9701 |
|
9702 |
|
9703 |
|
9704 | this.trigger('data', event);
|
9705 |
|
9706 |
|
9707 |
|
9708 |
|
9709 | for (i = 0; i < event.captions.length; i++) {
|
9710 | caption = event.captions[i];
|
9711 | this.trigger('caption', caption);
|
9712 | }
|
9713 |
|
9714 |
|
9715 |
|
9716 |
|
9717 |
|
9718 | for (i = 0; i < event.metadata.length; i++) {
|
9719 | id3 = event.metadata[i];
|
9720 | this.trigger('id3Frame', id3);
|
9721 | }
|
9722 | }
|
9723 |
|
9724 |
|
9725 | if (this.emittedTracks >= this.numberOfTracks) {
|
9726 | this.trigger('done');
|
9727 | this.emittedTracks = 0;
|
9728 | }
|
9729 | };
|
9730 |
|
9731 | _CoalesceStream.prototype.setRemux = function (val) {
|
9732 | this.remuxTracks = val;
|
9733 | };
|
9734 | |
9735 |
|
9736 |
|
9737 |
|
9738 |
|
9739 |
|
9740 |
|
9741 |
|
9742 | _Transmuxer = function Transmuxer(options) {
|
9743 | var self = this,
|
9744 | hasFlushed = true,
|
9745 | videoTrack,
|
9746 | audioTrack;
|
9747 |
|
9748 | _Transmuxer.prototype.init.call(this);
|
9749 |
|
9750 | options = options || {};
|
9751 | this.baseMediaDecodeTime = options.baseMediaDecodeTime || 0;
|
9752 | this.transmuxPipeline_ = {};
|
9753 |
|
9754 | this.setupAacPipeline = function () {
|
9755 | var pipeline = {};
|
9756 | this.transmuxPipeline_ = pipeline;
|
9757 | pipeline.type = 'aac';
|
9758 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
9759 |
|
9760 | pipeline.aacStream = new aac();
|
9761 | pipeline.audioTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('audio');
|
9762 | pipeline.timedMetadataTimestampRolloverStream = new m2ts_1.TimestampRolloverStream('timed-metadata');
|
9763 | pipeline.adtsStream = new adts();
|
9764 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
9765 | pipeline.headOfPipeline = pipeline.aacStream;
|
9766 | pipeline.aacStream.pipe(pipeline.audioTimestampRolloverStream).pipe(pipeline.adtsStream);
|
9767 | pipeline.aacStream.pipe(pipeline.timedMetadataTimestampRolloverStream).pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
9768 | pipeline.metadataStream.on('timestamp', function (frame) {
|
9769 | pipeline.aacStream.setTimestamp(frame.timeStamp);
|
9770 | });
|
9771 | pipeline.aacStream.on('data', function (data) {
|
9772 | if (data.type !== 'timed-metadata' && data.type !== 'audio' || pipeline.audioSegmentStream) {
|
9773 | return;
|
9774 | }
|
9775 |
|
9776 | audioTrack = audioTrack || {
|
9777 | timelineStartInfo: {
|
9778 | baseMediaDecodeTime: self.baseMediaDecodeTime
|
9779 | },
|
9780 | codec: 'adts',
|
9781 | type: 'audio'
|
9782 | };
|
9783 |
|
9784 | pipeline.coalesceStream.numberOfTracks++;
|
9785 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
9786 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
9787 |
|
9788 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
9789 |
|
9790 | self.trigger('trackinfo', {
|
9791 | hasAudio: !!audioTrack,
|
9792 | hasVideo: !!videoTrack
|
9793 | });
|
9794 | });
|
9795 |
|
9796 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
9797 |
|
9798 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
9799 | };
|
9800 |
|
9801 | this.setupTsPipeline = function () {
|
9802 | var pipeline = {};
|
9803 | this.transmuxPipeline_ = pipeline;
|
9804 | pipeline.type = 'ts';
|
9805 | pipeline.metadataStream = new m2ts_1.MetadataStream();
|
9806 |
|
9807 | pipeline.packetStream = new m2ts_1.TransportPacketStream();
|
9808 | pipeline.parseStream = new m2ts_1.TransportParseStream();
|
9809 | pipeline.elementaryStream = new m2ts_1.ElementaryStream();
|
9810 | pipeline.timestampRolloverStream = new m2ts_1.TimestampRolloverStream();
|
9811 | pipeline.adtsStream = new adts();
|
9812 | pipeline.h264Stream = new H264Stream();
|
9813 | pipeline.captionStream = new m2ts_1.CaptionStream(options);
|
9814 | pipeline.coalesceStream = new _CoalesceStream(options, pipeline.metadataStream);
|
9815 | pipeline.headOfPipeline = pipeline.packetStream;
|
9816 |
|
9817 | pipeline.packetStream.pipe(pipeline.parseStream).pipe(pipeline.elementaryStream).pipe(pipeline.timestampRolloverStream);
|
9818 |
|
9819 |
|
9820 | pipeline.timestampRolloverStream.pipe(pipeline.h264Stream);
|
9821 | pipeline.timestampRolloverStream.pipe(pipeline.adtsStream);
|
9822 | pipeline.timestampRolloverStream.pipe(pipeline.metadataStream).pipe(pipeline.coalesceStream);
|
9823 |
|
9824 | pipeline.h264Stream.pipe(pipeline.captionStream).pipe(pipeline.coalesceStream);
|
9825 | pipeline.elementaryStream.on('data', function (data) {
|
9826 | var i;
|
9827 |
|
9828 | if (data.type === 'metadata') {
|
9829 | i = data.tracks.length;
|
9830 |
|
9831 | while (i--) {
|
9832 | if (!videoTrack && data.tracks[i].type === 'video') {
|
9833 | videoTrack = data.tracks[i];
|
9834 | videoTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
9835 | } else if (!audioTrack && data.tracks[i].type === 'audio') {
|
9836 | audioTrack = data.tracks[i];
|
9837 | audioTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
9838 | }
|
9839 | }
|
9840 |
|
9841 |
|
9842 | if (videoTrack && !pipeline.videoSegmentStream) {
|
9843 | pipeline.coalesceStream.numberOfTracks++;
|
9844 | pipeline.videoSegmentStream = new _VideoSegmentStream(videoTrack, options);
|
9845 | pipeline.videoSegmentStream.on('timelineStartInfo', function (timelineStartInfo) {
|
9846 |
|
9847 |
|
9848 |
|
9849 |
|
9850 | if (audioTrack && !options.keepOriginalTimestamps) {
|
9851 | audioTrack.timelineStartInfo = timelineStartInfo;
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 | pipeline.audioSegmentStream.setEarliestDts(timelineStartInfo.dts - self.baseMediaDecodeTime);
|
9857 | }
|
9858 | });
|
9859 | pipeline.videoSegmentStream.on('processedGopsInfo', self.trigger.bind(self, 'gopInfo'));
|
9860 | pipeline.videoSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'videoSegmentTimingInfo'));
|
9861 | pipeline.videoSegmentStream.on('baseMediaDecodeTime', function (baseMediaDecodeTime) {
|
9862 | if (audioTrack) {
|
9863 | pipeline.audioSegmentStream.setVideoBaseMediaDecodeTime(baseMediaDecodeTime);
|
9864 | }
|
9865 | });
|
9866 | pipeline.videoSegmentStream.on('timingInfo', self.trigger.bind(self, 'videoTimingInfo'));
|
9867 |
|
9868 | pipeline.h264Stream.pipe(pipeline.videoSegmentStream).pipe(pipeline.coalesceStream);
|
9869 | }
|
9870 |
|
9871 | if (audioTrack && !pipeline.audioSegmentStream) {
|
9872 |
|
9873 | pipeline.coalesceStream.numberOfTracks++;
|
9874 | pipeline.audioSegmentStream = new _AudioSegmentStream(audioTrack, options);
|
9875 | pipeline.audioSegmentStream.on('timingInfo', self.trigger.bind(self, 'audioTimingInfo'));
|
9876 | pipeline.audioSegmentStream.on('segmentTimingInfo', self.trigger.bind(self, 'audioSegmentTimingInfo'));
|
9877 |
|
9878 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream).pipe(pipeline.coalesceStream);
|
9879 | }
|
9880 |
|
9881 |
|
9882 | self.trigger('trackinfo', {
|
9883 | hasAudio: !!audioTrack,
|
9884 | hasVideo: !!videoTrack
|
9885 | });
|
9886 | }
|
9887 | });
|
9888 |
|
9889 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
9890 | pipeline.coalesceStream.on('id3Frame', function (id3Frame) {
|
9891 | id3Frame.dispatchType = pipeline.metadataStream.dispatchType;
|
9892 | self.trigger('id3Frame', id3Frame);
|
9893 | });
|
9894 | pipeline.coalesceStream.on('caption', this.trigger.bind(this, 'caption'));
|
9895 |
|
9896 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
9897 | };
|
9898 |
|
9899 |
|
9900 | this.setBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
9901 | var pipeline = this.transmuxPipeline_;
|
9902 |
|
9903 | if (!options.keepOriginalTimestamps) {
|
9904 | this.baseMediaDecodeTime = baseMediaDecodeTime;
|
9905 | }
|
9906 |
|
9907 | if (audioTrack) {
|
9908 | audioTrack.timelineStartInfo.dts = undefined;
|
9909 | audioTrack.timelineStartInfo.pts = undefined;
|
9910 | trackDecodeInfo.clearDtsInfo(audioTrack);
|
9911 |
|
9912 | if (pipeline.audioTimestampRolloverStream) {
|
9913 | pipeline.audioTimestampRolloverStream.discontinuity();
|
9914 | }
|
9915 | }
|
9916 |
|
9917 | if (videoTrack) {
|
9918 | if (pipeline.videoSegmentStream) {
|
9919 | pipeline.videoSegmentStream.gopCache_ = [];
|
9920 | }
|
9921 |
|
9922 | videoTrack.timelineStartInfo.dts = undefined;
|
9923 | videoTrack.timelineStartInfo.pts = undefined;
|
9924 | trackDecodeInfo.clearDtsInfo(videoTrack);
|
9925 | pipeline.captionStream.reset();
|
9926 | }
|
9927 |
|
9928 | if (pipeline.timestampRolloverStream) {
|
9929 | pipeline.timestampRolloverStream.discontinuity();
|
9930 | }
|
9931 | };
|
9932 |
|
9933 | this.setAudioAppendStart = function (timestamp) {
|
9934 | if (audioTrack) {
|
9935 | this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(timestamp);
|
9936 | }
|
9937 | };
|
9938 |
|
9939 | this.setRemux = function (val) {
|
9940 | var pipeline = this.transmuxPipeline_;
|
9941 | options.remux = val;
|
9942 |
|
9943 | if (pipeline && pipeline.coalesceStream) {
|
9944 | pipeline.coalesceStream.setRemux(val);
|
9945 | }
|
9946 | };
|
9947 |
|
9948 | this.alignGopsWith = function (gopsToAlignWith) {
|
9949 | if (videoTrack && this.transmuxPipeline_.videoSegmentStream) {
|
9950 | this.transmuxPipeline_.videoSegmentStream.alignGopsWith(gopsToAlignWith);
|
9951 | }
|
9952 | };
|
9953 |
|
9954 |
|
9955 | this.push = function (data) {
|
9956 | if (hasFlushed) {
|
9957 | var isAac = isLikelyAacData$1(data);
|
9958 |
|
9959 | if (isAac && this.transmuxPipeline_.type !== 'aac') {
|
9960 | this.setupAacPipeline();
|
9961 | } else if (!isAac && this.transmuxPipeline_.type !== 'ts') {
|
9962 | this.setupTsPipeline();
|
9963 | }
|
9964 |
|
9965 | hasFlushed = false;
|
9966 | }
|
9967 |
|
9968 | this.transmuxPipeline_.headOfPipeline.push(data);
|
9969 | };
|
9970 |
|
9971 |
|
9972 | this.flush = function () {
|
9973 | hasFlushed = true;
|
9974 |
|
9975 | this.transmuxPipeline_.headOfPipeline.flush();
|
9976 | };
|
9977 |
|
9978 | this.endTimeline = function () {
|
9979 | this.transmuxPipeline_.headOfPipeline.endTimeline();
|
9980 | };
|
9981 |
|
9982 | this.reset = function () {
|
9983 | if (this.transmuxPipeline_.headOfPipeline) {
|
9984 | this.transmuxPipeline_.headOfPipeline.reset();
|
9985 | }
|
9986 | };
|
9987 |
|
9988 |
|
9989 | this.resetCaptions = function () {
|
9990 | if (this.transmuxPipeline_.captionStream) {
|
9991 | this.transmuxPipeline_.captionStream.reset();
|
9992 | }
|
9993 | };
|
9994 | };
|
9995 |
|
9996 | _Transmuxer.prototype = new stream();
|
9997 | var transmuxer$1 = {
|
9998 | Transmuxer: _Transmuxer,
|
9999 | VideoSegmentStream: _VideoSegmentStream,
|
10000 | AudioSegmentStream: _AudioSegmentStream,
|
10001 | AUDIO_PROPERTIES: audioProperties,
|
10002 | VIDEO_PROPERTIES: videoProperties,
|
10003 |
|
10004 | generateSegmentTimingInfo: generateSegmentTimingInfo
|
10005 | };
|
10006 | |
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 | var codecs = {
|
10014 | Adts: adts,
|
10015 | h264: h264
|
10016 | };
|
10017 | var ONE_SECOND_IN_TS = clock.ONE_SECOND_IN_TS;
|
10018 | |
10019 |
|
10020 |
|
10021 |
|
10022 |
|
10023 |
|
10024 | var AudioSegmentStream = function AudioSegmentStream(track, options) {
|
10025 | var adtsFrames = [],
|
10026 | sequenceNumber = 0,
|
10027 | earliestAllowedDts = 0,
|
10028 | audioAppendStartTs = 0,
|
10029 | videoBaseMediaDecodeTime = Infinity,
|
10030 | segmentStartPts = null,
|
10031 | segmentEndPts = null;
|
10032 | options = options || {};
|
10033 | AudioSegmentStream.prototype.init.call(this);
|
10034 |
|
10035 | this.push = function (data) {
|
10036 | trackDecodeInfo.collectDtsInfo(track, data);
|
10037 |
|
10038 | if (track) {
|
10039 | audioProperties.forEach(function (prop) {
|
10040 | track[prop] = data[prop];
|
10041 | });
|
10042 | }
|
10043 |
|
10044 |
|
10045 | adtsFrames.push(data);
|
10046 | };
|
10047 |
|
10048 | this.setEarliestDts = function (earliestDts) {
|
10049 | earliestAllowedDts = earliestDts;
|
10050 | };
|
10051 |
|
10052 | this.setVideoBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
10053 | videoBaseMediaDecodeTime = baseMediaDecodeTime;
|
10054 | };
|
10055 |
|
10056 | this.setAudioAppendStart = function (timestamp) {
|
10057 | audioAppendStartTs = timestamp;
|
10058 | };
|
10059 |
|
10060 | this.processFrames_ = function () {
|
10061 | var frames, moof, mdat, boxes, timingInfo;
|
10062 |
|
10063 | if (adtsFrames.length === 0) {
|
10064 | return;
|
10065 | }
|
10066 |
|
10067 | frames = audioFrameUtils.trimAdtsFramesByEarliestDts(adtsFrames, track, earliestAllowedDts);
|
10068 |
|
10069 | if (frames.length === 0) {
|
10070 |
|
10071 |
|
10072 | return;
|
10073 | }
|
10074 |
|
10075 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
10076 | audioFrameUtils.prefixWithSilence(track, frames, audioAppendStartTs, videoBaseMediaDecodeTime);
|
10077 |
|
10078 |
|
10079 | track.samples = audioFrameUtils.generateSampleTable(frames);
|
10080 |
|
10081 | mdat = mp4Generator.mdat(audioFrameUtils.concatenateFrameData(frames));
|
10082 | adtsFrames = [];
|
10083 | moof = mp4Generator.moof(sequenceNumber, [track]);
|
10084 |
|
10085 | sequenceNumber++;
|
10086 | track.initSegment = mp4Generator.initSegment([track]);
|
10087 |
|
10088 |
|
10089 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
10090 | boxes.set(moof);
|
10091 | boxes.set(mdat, moof.byteLength);
|
10092 | trackDecodeInfo.clearDtsInfo(track);
|
10093 |
|
10094 | if (segmentStartPts === null) {
|
10095 | segmentEndPts = segmentStartPts = frames[0].pts;
|
10096 | }
|
10097 |
|
10098 | segmentEndPts += frames.length * (ONE_SECOND_IN_TS * 1024 / track.samplerate);
|
10099 | timingInfo = {
|
10100 | start: segmentStartPts
|
10101 | };
|
10102 | this.trigger('timingInfo', timingInfo);
|
10103 | this.trigger('data', {
|
10104 | track: track,
|
10105 | boxes: boxes
|
10106 | });
|
10107 | };
|
10108 |
|
10109 | this.flush = function () {
|
10110 | this.processFrames_();
|
10111 |
|
10112 | this.trigger('timingInfo', {
|
10113 | start: segmentStartPts,
|
10114 | end: segmentEndPts
|
10115 | });
|
10116 | this.resetTiming_();
|
10117 | this.trigger('done', 'AudioSegmentStream');
|
10118 | };
|
10119 |
|
10120 | this.partialFlush = function () {
|
10121 | this.processFrames_();
|
10122 | this.trigger('partialdone', 'AudioSegmentStream');
|
10123 | };
|
10124 |
|
10125 | this.endTimeline = function () {
|
10126 | this.flush();
|
10127 | this.trigger('endedtimeline', 'AudioSegmentStream');
|
10128 | };
|
10129 |
|
10130 | this.resetTiming_ = function () {
|
10131 | trackDecodeInfo.clearDtsInfo(track);
|
10132 | segmentStartPts = null;
|
10133 | segmentEndPts = null;
|
10134 | };
|
10135 |
|
10136 | this.reset = function () {
|
10137 | this.resetTiming_();
|
10138 | adtsFrames = [];
|
10139 | this.trigger('reset');
|
10140 | };
|
10141 | };
|
10142 |
|
10143 | AudioSegmentStream.prototype = new stream();
|
10144 | var audioSegmentStream = AudioSegmentStream;
|
10145 |
|
10146 | var VideoSegmentStream = function VideoSegmentStream(track, options) {
|
10147 | var sequenceNumber = 0,
|
10148 | nalUnits = [],
|
10149 | frameCache = [],
|
10150 |
|
10151 | config,
|
10152 | pps,
|
10153 | segmentStartPts = null,
|
10154 | segmentEndPts = null,
|
10155 | gops,
|
10156 | ensureNextFrameIsKeyFrame = true;
|
10157 | options = options || {};
|
10158 | VideoSegmentStream.prototype.init.call(this);
|
10159 |
|
10160 | this.push = function (nalUnit) {
|
10161 | trackDecodeInfo.collectDtsInfo(track, nalUnit);
|
10162 |
|
10163 | if (typeof track.timelineStartInfo.dts === 'undefined') {
|
10164 | track.timelineStartInfo.dts = nalUnit.dts;
|
10165 | }
|
10166 |
|
10167 |
|
10168 | if (nalUnit.nalUnitType === 'seq_parameter_set_rbsp' && !config) {
|
10169 | config = nalUnit.config;
|
10170 | track.sps = [nalUnit.data];
|
10171 | videoProperties.forEach(function (prop) {
|
10172 | track[prop] = config[prop];
|
10173 | }, this);
|
10174 | }
|
10175 |
|
10176 | if (nalUnit.nalUnitType === 'pic_parameter_set_rbsp' && !pps) {
|
10177 | pps = nalUnit.data;
|
10178 | track.pps = [nalUnit.data];
|
10179 | }
|
10180 |
|
10181 |
|
10182 | nalUnits.push(nalUnit);
|
10183 | };
|
10184 |
|
10185 | this.processNals_ = function (cacheLastFrame) {
|
10186 | var i;
|
10187 | nalUnits = frameCache.concat(nalUnits);
|
10188 |
|
10189 |
|
10190 | while (nalUnits.length) {
|
10191 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
10192 | break;
|
10193 | }
|
10194 |
|
10195 | nalUnits.shift();
|
10196 | }
|
10197 |
|
10198 |
|
10199 | if (nalUnits.length === 0) {
|
10200 | return;
|
10201 | }
|
10202 |
|
10203 | var frames = frameUtils.groupNalsIntoFrames(nalUnits);
|
10204 |
|
10205 | if (!frames.length) {
|
10206 | return;
|
10207 | }
|
10208 |
|
10209 |
|
10210 |
|
10211 | frameCache = frames[frames.length - 1];
|
10212 |
|
10213 | if (cacheLastFrame) {
|
10214 | frames.pop();
|
10215 | frames.duration -= frameCache.duration;
|
10216 | frames.nalCount -= frameCache.length;
|
10217 | frames.byteLength -= frameCache.byteLength;
|
10218 | }
|
10219 |
|
10220 | if (!frames.length) {
|
10221 | nalUnits = [];
|
10222 | return;
|
10223 | }
|
10224 |
|
10225 | this.trigger('timelineStartInfo', track.timelineStartInfo);
|
10226 |
|
10227 | if (ensureNextFrameIsKeyFrame) {
|
10228 | gops = frameUtils.groupFramesIntoGops(frames);
|
10229 |
|
10230 | if (!gops[0][0].keyFrame) {
|
10231 | gops = frameUtils.extendFirstKeyFrame(gops);
|
10232 |
|
10233 | if (!gops[0][0].keyFrame) {
|
10234 |
|
10235 |
|
10236 | nalUnits = [].concat.apply([], frames).concat(frameCache);
|
10237 | frameCache = [];
|
10238 | return;
|
10239 | }
|
10240 |
|
10241 | frames = [].concat.apply([], gops);
|
10242 | frames.duration = gops.duration;
|
10243 | }
|
10244 |
|
10245 | ensureNextFrameIsKeyFrame = false;
|
10246 | }
|
10247 |
|
10248 | if (segmentStartPts === null) {
|
10249 | segmentStartPts = frames[0].pts;
|
10250 | segmentEndPts = segmentStartPts;
|
10251 | }
|
10252 |
|
10253 | segmentEndPts += frames.duration;
|
10254 | this.trigger('timingInfo', {
|
10255 | start: segmentStartPts,
|
10256 | end: segmentEndPts
|
10257 | });
|
10258 |
|
10259 | for (i = 0; i < frames.length; i++) {
|
10260 | var frame = frames[i];
|
10261 | track.samples = frameUtils.generateSampleTableForFrame(frame);
|
10262 | var mdat = mp4Generator.mdat(frameUtils.concatenateNalDataForFrame(frame));
|
10263 | trackDecodeInfo.clearDtsInfo(track);
|
10264 | trackDecodeInfo.collectDtsInfo(track, frame);
|
10265 | track.baseMediaDecodeTime = trackDecodeInfo.calculateTrackBaseMediaDecodeTime(track, options.keepOriginalTimestamps);
|
10266 | var moof = mp4Generator.moof(sequenceNumber, [track]);
|
10267 | sequenceNumber++;
|
10268 | track.initSegment = mp4Generator.initSegment([track]);
|
10269 | var boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
10270 | boxes.set(moof);
|
10271 | boxes.set(mdat, moof.byteLength);
|
10272 | this.trigger('data', {
|
10273 | track: track,
|
10274 | boxes: boxes,
|
10275 | sequence: sequenceNumber,
|
10276 | videoFrameDts: frame.dts,
|
10277 | videoFramePts: frame.pts
|
10278 | });
|
10279 | }
|
10280 |
|
10281 | nalUnits = [];
|
10282 | };
|
10283 |
|
10284 | this.resetTimingAndConfig_ = function () {
|
10285 | config = undefined;
|
10286 | pps = undefined;
|
10287 | segmentStartPts = null;
|
10288 | segmentEndPts = null;
|
10289 | };
|
10290 |
|
10291 | this.partialFlush = function () {
|
10292 | this.processNals_(true);
|
10293 | this.trigger('partialdone', 'VideoSegmentStream');
|
10294 | };
|
10295 |
|
10296 | this.flush = function () {
|
10297 | this.processNals_(false);
|
10298 |
|
10299 |
|
10300 | this.resetTimingAndConfig_();
|
10301 | this.trigger('done', 'VideoSegmentStream');
|
10302 | };
|
10303 |
|
10304 | this.endTimeline = function () {
|
10305 | this.flush();
|
10306 | this.trigger('endedtimeline', 'VideoSegmentStream');
|
10307 | };
|
10308 |
|
10309 | this.reset = function () {
|
10310 | this.resetTimingAndConfig_();
|
10311 | frameCache = [];
|
10312 | nalUnits = [];
|
10313 | ensureNextFrameIsKeyFrame = true;
|
10314 | this.trigger('reset');
|
10315 | };
|
10316 | };
|
10317 |
|
10318 | VideoSegmentStream.prototype = new stream();
|
10319 | var videoSegmentStream = VideoSegmentStream;
|
10320 | var isLikelyAacData = utils.isLikelyAacData;
|
10321 |
|
10322 | var createPipeline = function createPipeline(object) {
|
10323 | object.prototype = new stream();
|
10324 | object.prototype.init.call(object);
|
10325 | return object;
|
10326 | };
|
10327 |
|
10328 | var tsPipeline = function tsPipeline(options) {
|
10329 | var pipeline = {
|
10330 | type: 'ts',
|
10331 | tracks: {
|
10332 | audio: null,
|
10333 | video: null
|
10334 | },
|
10335 | packet: new m2ts_1.TransportPacketStream(),
|
10336 | parse: new m2ts_1.TransportParseStream(),
|
10337 | elementary: new m2ts_1.ElementaryStream(),
|
10338 | timestampRollover: new m2ts_1.TimestampRolloverStream(),
|
10339 | adts: new codecs.Adts(),
|
10340 | h264: new codecs.h264.H264Stream(),
|
10341 | captionStream: new m2ts_1.CaptionStream(options),
|
10342 | metadataStream: new m2ts_1.MetadataStream()
|
10343 | };
|
10344 | pipeline.headOfPipeline = pipeline.packet;
|
10345 |
|
10346 | pipeline.packet.pipe(pipeline.parse).pipe(pipeline.elementary).pipe(pipeline.timestampRollover);
|
10347 |
|
10348 | pipeline.timestampRollover.pipe(pipeline.h264);
|
10349 |
|
10350 | pipeline.h264.pipe(pipeline.captionStream);
|
10351 | pipeline.timestampRollover.pipe(pipeline.metadataStream);
|
10352 |
|
10353 | pipeline.timestampRollover.pipe(pipeline.adts);
|
10354 | pipeline.elementary.on('data', function (data) {
|
10355 | if (data.type !== 'metadata') {
|
10356 | return;
|
10357 | }
|
10358 |
|
10359 | for (var i = 0; i < data.tracks.length; i++) {
|
10360 | if (!pipeline.tracks[data.tracks[i].type]) {
|
10361 | pipeline.tracks[data.tracks[i].type] = data.tracks[i];
|
10362 | pipeline.tracks[data.tracks[i].type].timelineStartInfo.baseMediaDecodeTime = options.baseMediaDecodeTime;
|
10363 | }
|
10364 | }
|
10365 |
|
10366 | if (pipeline.tracks.video && !pipeline.videoSegmentStream) {
|
10367 | pipeline.videoSegmentStream = new videoSegmentStream(pipeline.tracks.video, options);
|
10368 | pipeline.videoSegmentStream.on('timelineStartInfo', function (timelineStartInfo) {
|
10369 | if (pipeline.tracks.audio && !options.keepOriginalTimestamps) {
|
10370 | pipeline.audioSegmentStream.setEarliestDts(timelineStartInfo.dts - options.baseMediaDecodeTime);
|
10371 | }
|
10372 | });
|
10373 | pipeline.videoSegmentStream.on('timingInfo', pipeline.trigger.bind(pipeline, 'videoTimingInfo'));
|
10374 | pipeline.videoSegmentStream.on('data', function (data) {
|
10375 | pipeline.trigger('data', {
|
10376 | type: 'video',
|
10377 | data: data
|
10378 | });
|
10379 | });
|
10380 | pipeline.videoSegmentStream.on('done', pipeline.trigger.bind(pipeline, 'done'));
|
10381 | pipeline.videoSegmentStream.on('partialdone', pipeline.trigger.bind(pipeline, 'partialdone'));
|
10382 | pipeline.videoSegmentStream.on('endedtimeline', pipeline.trigger.bind(pipeline, 'endedtimeline'));
|
10383 | pipeline.h264.pipe(pipeline.videoSegmentStream);
|
10384 | }
|
10385 |
|
10386 | if (pipeline.tracks.audio && !pipeline.audioSegmentStream) {
|
10387 | pipeline.audioSegmentStream = new audioSegmentStream(pipeline.tracks.audio, options);
|
10388 | pipeline.audioSegmentStream.on('data', function (data) {
|
10389 | pipeline.trigger('data', {
|
10390 | type: 'audio',
|
10391 | data: data
|
10392 | });
|
10393 | });
|
10394 | pipeline.audioSegmentStream.on('done', pipeline.trigger.bind(pipeline, 'done'));
|
10395 | pipeline.audioSegmentStream.on('partialdone', pipeline.trigger.bind(pipeline, 'partialdone'));
|
10396 | pipeline.audioSegmentStream.on('endedtimeline', pipeline.trigger.bind(pipeline, 'endedtimeline'));
|
10397 | pipeline.audioSegmentStream.on('timingInfo', pipeline.trigger.bind(pipeline, 'audioTimingInfo'));
|
10398 | pipeline.adts.pipe(pipeline.audioSegmentStream);
|
10399 | }
|
10400 |
|
10401 |
|
10402 | pipeline.trigger('trackinfo', {
|
10403 | hasAudio: !!pipeline.tracks.audio,
|
10404 | hasVideo: !!pipeline.tracks.video
|
10405 | });
|
10406 | });
|
10407 | pipeline.captionStream.on('data', function (caption) {
|
10408 | var timelineStartPts;
|
10409 |
|
10410 | if (pipeline.tracks.video) {
|
10411 | timelineStartPts = pipeline.tracks.video.timelineStartInfo.pts || 0;
|
10412 | } else {
|
10413 |
|
10414 |
|
10415 |
|
10416 | timelineStartPts = 0;
|
10417 | }
|
10418 |
|
10419 |
|
10420 |
|
10421 | caption.startTime = clock.metadataTsToSeconds(caption.startPts, timelineStartPts, options.keepOriginalTimestamps);
|
10422 | caption.endTime = clock.metadataTsToSeconds(caption.endPts, timelineStartPts, options.keepOriginalTimestamps);
|
10423 | pipeline.trigger('caption', caption);
|
10424 | });
|
10425 | pipeline = createPipeline(pipeline);
|
10426 | pipeline.metadataStream.on('data', pipeline.trigger.bind(pipeline, 'id3Frame'));
|
10427 | return pipeline;
|
10428 | };
|
10429 |
|
10430 | var aacPipeline = function aacPipeline(options) {
|
10431 | var pipeline = {
|
10432 | type: 'aac',
|
10433 | tracks: {
|
10434 | audio: null
|
10435 | },
|
10436 | metadataStream: new m2ts_1.MetadataStream(),
|
10437 | aacStream: new aac(),
|
10438 | audioRollover: new m2ts_1.TimestampRolloverStream('audio'),
|
10439 | timedMetadataRollover: new m2ts_1.TimestampRolloverStream('timed-metadata'),
|
10440 | adtsStream: new adts(true)
|
10441 | };
|
10442 |
|
10443 | pipeline.headOfPipeline = pipeline.aacStream;
|
10444 | pipeline.aacStream.pipe(pipeline.audioRollover).pipe(pipeline.adtsStream);
|
10445 | pipeline.aacStream.pipe(pipeline.timedMetadataRollover).pipe(pipeline.metadataStream);
|
10446 | pipeline.metadataStream.on('timestamp', function (frame) {
|
10447 | pipeline.aacStream.setTimestamp(frame.timeStamp);
|
10448 | });
|
10449 | pipeline.aacStream.on('data', function (data) {
|
10450 | if (data.type !== 'timed-metadata' && data.type !== 'audio' || pipeline.audioSegmentStream) {
|
10451 | return;
|
10452 | }
|
10453 |
|
10454 | pipeline.tracks.audio = pipeline.tracks.audio || {
|
10455 | timelineStartInfo: {
|
10456 | baseMediaDecodeTime: options.baseMediaDecodeTime
|
10457 | },
|
10458 | codec: 'adts',
|
10459 | type: 'audio'
|
10460 | };
|
10461 |
|
10462 | pipeline.audioSegmentStream = new audioSegmentStream(pipeline.tracks.audio, options);
|
10463 | pipeline.audioSegmentStream.on('data', function (data) {
|
10464 | pipeline.trigger('data', {
|
10465 | type: 'audio',
|
10466 | data: data
|
10467 | });
|
10468 | });
|
10469 | pipeline.audioSegmentStream.on('partialdone', pipeline.trigger.bind(pipeline, 'partialdone'));
|
10470 | pipeline.audioSegmentStream.on('done', pipeline.trigger.bind(pipeline, 'done'));
|
10471 | pipeline.audioSegmentStream.on('endedtimeline', pipeline.trigger.bind(pipeline, 'endedtimeline'));
|
10472 | pipeline.audioSegmentStream.on('timingInfo', pipeline.trigger.bind(pipeline, 'audioTimingInfo'));
|
10473 |
|
10474 | pipeline.adtsStream.pipe(pipeline.audioSegmentStream);
|
10475 | pipeline.trigger('trackinfo', {
|
10476 | hasAudio: !!pipeline.tracks.audio,
|
10477 | hasVideo: !!pipeline.tracks.video
|
10478 | });
|
10479 | });
|
10480 |
|
10481 | pipeline = createPipeline(pipeline);
|
10482 | pipeline.metadataStream.on('data', pipeline.trigger.bind(pipeline, 'id3Frame'));
|
10483 | return pipeline;
|
10484 | };
|
10485 |
|
10486 | var setupPipelineListeners = function setupPipelineListeners(pipeline, transmuxer) {
|
10487 | pipeline.on('data', transmuxer.trigger.bind(transmuxer, 'data'));
|
10488 | pipeline.on('done', transmuxer.trigger.bind(transmuxer, 'done'));
|
10489 | pipeline.on('partialdone', transmuxer.trigger.bind(transmuxer, 'partialdone'));
|
10490 | pipeline.on('endedtimeline', transmuxer.trigger.bind(transmuxer, 'endedtimeline'));
|
10491 | pipeline.on('audioTimingInfo', transmuxer.trigger.bind(transmuxer, 'audioTimingInfo'));
|
10492 | pipeline.on('videoTimingInfo', transmuxer.trigger.bind(transmuxer, 'videoTimingInfo'));
|
10493 | pipeline.on('trackinfo', transmuxer.trigger.bind(transmuxer, 'trackinfo'));
|
10494 | pipeline.on('id3Frame', function (event) {
|
10495 |
|
10496 | event.dispatchType = pipeline.metadataStream.dispatchType;
|
10497 |
|
10498 | event.cueTime = clock.videoTsToSeconds(event.pts);
|
10499 | transmuxer.trigger('id3Frame', event);
|
10500 | });
|
10501 | pipeline.on('caption', function (event) {
|
10502 | transmuxer.trigger('caption', event);
|
10503 | });
|
10504 | };
|
10505 |
|
10506 | var Transmuxer = function Transmuxer(options) {
|
10507 | var pipeline = null,
|
10508 | hasFlushed = true;
|
10509 | options = options || {};
|
10510 | Transmuxer.prototype.init.call(this);
|
10511 | options.baseMediaDecodeTime = options.baseMediaDecodeTime || 0;
|
10512 |
|
10513 | this.push = function (bytes) {
|
10514 | if (hasFlushed) {
|
10515 | var isAac = isLikelyAacData(bytes);
|
10516 |
|
10517 | if (isAac && (!pipeline || pipeline.type !== 'aac')) {
|
10518 | pipeline = aacPipeline(options);
|
10519 | setupPipelineListeners(pipeline, this);
|
10520 | } else if (!isAac && (!pipeline || pipeline.type !== 'ts')) {
|
10521 | pipeline = tsPipeline(options);
|
10522 | setupPipelineListeners(pipeline, this);
|
10523 | }
|
10524 |
|
10525 | hasFlushed = false;
|
10526 | }
|
10527 |
|
10528 | pipeline.headOfPipeline.push(bytes);
|
10529 | };
|
10530 |
|
10531 | this.flush = function () {
|
10532 | if (!pipeline) {
|
10533 | return;
|
10534 | }
|
10535 |
|
10536 | hasFlushed = true;
|
10537 | pipeline.headOfPipeline.flush();
|
10538 | };
|
10539 |
|
10540 | this.partialFlush = function () {
|
10541 | if (!pipeline) {
|
10542 | return;
|
10543 | }
|
10544 |
|
10545 | pipeline.headOfPipeline.partialFlush();
|
10546 | };
|
10547 |
|
10548 | this.endTimeline = function () {
|
10549 | if (!pipeline) {
|
10550 | return;
|
10551 | }
|
10552 |
|
10553 | pipeline.headOfPipeline.endTimeline();
|
10554 | };
|
10555 |
|
10556 | this.reset = function () {
|
10557 | if (!pipeline) {
|
10558 | return;
|
10559 | }
|
10560 |
|
10561 | pipeline.headOfPipeline.reset();
|
10562 | };
|
10563 |
|
10564 | this.setBaseMediaDecodeTime = function (baseMediaDecodeTime) {
|
10565 | if (!options.keepOriginalTimestamps) {
|
10566 | options.baseMediaDecodeTime = baseMediaDecodeTime;
|
10567 | }
|
10568 |
|
10569 | if (!pipeline) {
|
10570 | return;
|
10571 | }
|
10572 |
|
10573 | if (pipeline.tracks.audio) {
|
10574 | pipeline.tracks.audio.timelineStartInfo.dts = undefined;
|
10575 | pipeline.tracks.audio.timelineStartInfo.pts = undefined;
|
10576 | trackDecodeInfo.clearDtsInfo(pipeline.tracks.audio);
|
10577 |
|
10578 | if (pipeline.audioRollover) {
|
10579 | pipeline.audioRollover.discontinuity();
|
10580 | }
|
10581 | }
|
10582 |
|
10583 | if (pipeline.tracks.video) {
|
10584 | if (pipeline.videoSegmentStream) {
|
10585 | pipeline.videoSegmentStream.gopCache_ = [];
|
10586 | }
|
10587 |
|
10588 | pipeline.tracks.video.timelineStartInfo.dts = undefined;
|
10589 | pipeline.tracks.video.timelineStartInfo.pts = undefined;
|
10590 | trackDecodeInfo.clearDtsInfo(pipeline.tracks.video);
|
10591 | }
|
10592 |
|
10593 | if (pipeline.timestampRollover) {
|
10594 | pipeline.timestampRollover.discontinuity();
|
10595 | }
|
10596 | };
|
10597 |
|
10598 | this.setRemux = function (val) {
|
10599 | options.remux = val;
|
10600 |
|
10601 | if (pipeline && pipeline.coalesceStream) {
|
10602 | pipeline.coalesceStream.setRemux(val);
|
10603 | }
|
10604 | };
|
10605 |
|
10606 | this.setAudioAppendStart = function (audioAppendStart) {
|
10607 | if (!pipeline || !pipeline.tracks.audio || !pipeline.audioSegmentStream) {
|
10608 | return;
|
10609 | }
|
10610 |
|
10611 | pipeline.audioSegmentStream.setAudioAppendStart(audioAppendStart);
|
10612 | };
|
10613 |
|
10614 |
|
10615 |
|
10616 |
|
10617 | this.alignGopsWith = function (gopsToAlignWith) {
|
10618 | return;
|
10619 | };
|
10620 | };
|
10621 |
|
10622 | Transmuxer.prototype = new stream();
|
10623 | var transmuxer = Transmuxer;
|
10624 | |
10625 |
|
10626 |
|
10627 |
|
10628 |
|
10629 |
|
10630 |
|
10631 | var toUnsigned$2 = function toUnsigned(value) {
|
10632 | return value >>> 0;
|
10633 | };
|
10634 |
|
10635 | var toHexString = function toHexString(value) {
|
10636 | return ('00' + value.toString(16)).slice(-2);
|
10637 | };
|
10638 |
|
10639 | var bin = {
|
10640 | toUnsigned: toUnsigned$2,
|
10641 | toHexString: toHexString
|
10642 | };
|
10643 |
|
10644 | var parseType = function parseType(buffer) {
|
10645 | var result = '';
|
10646 | result += String.fromCharCode(buffer[0]);
|
10647 | result += String.fromCharCode(buffer[1]);
|
10648 | result += String.fromCharCode(buffer[2]);
|
10649 | result += String.fromCharCode(buffer[3]);
|
10650 | return result;
|
10651 | };
|
10652 |
|
10653 | var parseType_1 = parseType;
|
10654 | var toUnsigned$1 = bin.toUnsigned;
|
10655 |
|
10656 | var findBox = function findBox(data, path) {
|
10657 | var results = [],
|
10658 | i,
|
10659 | size,
|
10660 | type,
|
10661 | end,
|
10662 | subresults;
|
10663 |
|
10664 | if (!path.length) {
|
10665 |
|
10666 | return null;
|
10667 | }
|
10668 |
|
10669 | for (i = 0; i < data.byteLength;) {
|
10670 | size = toUnsigned$1(data[i] << 24 | data[i + 1] << 16 | data[i + 2] << 8 | data[i + 3]);
|
10671 | type = parseType_1(data.subarray(i + 4, i + 8));
|
10672 | end = size > 1 ? i + size : data.byteLength;
|
10673 |
|
10674 | if (type === path[0]) {
|
10675 | if (path.length === 1) {
|
10676 |
|
10677 |
|
10678 | results.push(data.subarray(i + 8, end));
|
10679 | } else {
|
10680 |
|
10681 | subresults = findBox(data.subarray(i + 8, end), path.slice(1));
|
10682 |
|
10683 | if (subresults.length) {
|
10684 | results = results.concat(subresults);
|
10685 | }
|
10686 | }
|
10687 | }
|
10688 |
|
10689 | i = end;
|
10690 | }
|
10691 |
|
10692 |
|
10693 | return results;
|
10694 | };
|
10695 |
|
10696 | var findBox_1 = findBox;
|
10697 | var toUnsigned = bin.toUnsigned;
|
10698 |
|
10699 | var tfdt = function tfdt(data) {
|
10700 | var result = {
|
10701 | version: data[0],
|
10702 | flags: new Uint8Array(data.subarray(1, 4)),
|
10703 | baseMediaDecodeTime: toUnsigned(data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7])
|
10704 | };
|
10705 |
|
10706 | if (result.version === 1) {
|
10707 | result.baseMediaDecodeTime *= Math.pow(2, 32);
|
10708 | result.baseMediaDecodeTime += toUnsigned(data[8] << 24 | data[9] << 16 | data[10] << 8 | data[11]);
|
10709 | }
|
10710 |
|
10711 | return result;
|
10712 | };
|
10713 |
|
10714 | var parseTfdt = tfdt;
|
10715 |
|
10716 | var parseSampleFlags = function parseSampleFlags(flags) {
|
10717 | return {
|
10718 | isLeading: (flags[0] & 0x0c) >>> 2,
|
10719 | dependsOn: flags[0] & 0x03,
|
10720 | isDependedOn: (flags[1] & 0xc0) >>> 6,
|
10721 | hasRedundancy: (flags[1] & 0x30) >>> 4,
|
10722 | paddingValue: (flags[1] & 0x0e) >>> 1,
|
10723 | isNonSyncSample: flags[1] & 0x01,
|
10724 | degradationPriority: flags[2] << 8 | flags[3]
|
10725 | };
|
10726 | };
|
10727 |
|
10728 | var parseSampleFlags_1 = parseSampleFlags;
|
10729 |
|
10730 | var trun = function trun(data) {
|
10731 | var result = {
|
10732 | version: data[0],
|
10733 | flags: new Uint8Array(data.subarray(1, 4)),
|
10734 | samples: []
|
10735 | },
|
10736 | view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
10737 |
|
10738 | dataOffsetPresent = result.flags[2] & 0x01,
|
10739 |
|
10740 | firstSampleFlagsPresent = result.flags[2] & 0x04,
|
10741 |
|
10742 | sampleDurationPresent = result.flags[1] & 0x01,
|
10743 |
|
10744 | sampleSizePresent = result.flags[1] & 0x02,
|
10745 |
|
10746 | sampleFlagsPresent = result.flags[1] & 0x04,
|
10747 |
|
10748 | sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08,
|
10749 |
|
10750 | sampleCount = view.getUint32(4),
|
10751 | offset = 8,
|
10752 | sample;
|
10753 |
|
10754 | if (dataOffsetPresent) {
|
10755 |
|
10756 | result.dataOffset = view.getInt32(offset);
|
10757 | offset += 4;
|
10758 | }
|
10759 |
|
10760 |
|
10761 |
|
10762 | if (firstSampleFlagsPresent && sampleCount) {
|
10763 | sample = {
|
10764 | flags: parseSampleFlags_1(data.subarray(offset, offset + 4))
|
10765 | };
|
10766 | offset += 4;
|
10767 |
|
10768 | if (sampleDurationPresent) {
|
10769 | sample.duration = view.getUint32(offset);
|
10770 | offset += 4;
|
10771 | }
|
10772 |
|
10773 | if (sampleSizePresent) {
|
10774 | sample.size = view.getUint32(offset);
|
10775 | offset += 4;
|
10776 | }
|
10777 |
|
10778 | if (sampleCompositionTimeOffsetPresent) {
|
10779 | if (result.version === 1) {
|
10780 | sample.compositionTimeOffset = view.getInt32(offset);
|
10781 | } else {
|
10782 | sample.compositionTimeOffset = view.getUint32(offset);
|
10783 | }
|
10784 |
|
10785 | offset += 4;
|
10786 | }
|
10787 |
|
10788 | result.samples.push(sample);
|
10789 | sampleCount--;
|
10790 | }
|
10791 |
|
10792 | while (sampleCount--) {
|
10793 | sample = {};
|
10794 |
|
10795 | if (sampleDurationPresent) {
|
10796 | sample.duration = view.getUint32(offset);
|
10797 | offset += 4;
|
10798 | }
|
10799 |
|
10800 | if (sampleSizePresent) {
|
10801 | sample.size = view.getUint32(offset);
|
10802 | offset += 4;
|
10803 | }
|
10804 |
|
10805 | if (sampleFlagsPresent) {
|
10806 | sample.flags = parseSampleFlags_1(data.subarray(offset, offset + 4));
|
10807 | offset += 4;
|
10808 | }
|
10809 |
|
10810 | if (sampleCompositionTimeOffsetPresent) {
|
10811 | if (result.version === 1) {
|
10812 | sample.compositionTimeOffset = view.getInt32(offset);
|
10813 | } else {
|
10814 | sample.compositionTimeOffset = view.getUint32(offset);
|
10815 | }
|
10816 |
|
10817 | offset += 4;
|
10818 | }
|
10819 |
|
10820 | result.samples.push(sample);
|
10821 | }
|
10822 |
|
10823 | return result;
|
10824 | };
|
10825 |
|
10826 | var parseTrun = trun;
|
10827 |
|
10828 | var tfhd = function tfhd(data) {
|
10829 | var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
|
10830 | result = {
|
10831 | version: data[0],
|
10832 | flags: new Uint8Array(data.subarray(1, 4)),
|
10833 | trackId: view.getUint32(4)
|
10834 | },
|
10835 | baseDataOffsetPresent = result.flags[2] & 0x01,
|
10836 | sampleDescriptionIndexPresent = result.flags[2] & 0x02,
|
10837 | defaultSampleDurationPresent = result.flags[2] & 0x08,
|
10838 | defaultSampleSizePresent = result.flags[2] & 0x10,
|
10839 | defaultSampleFlagsPresent = result.flags[2] & 0x20,
|
10840 | durationIsEmpty = result.flags[0] & 0x010000,
|
10841 | defaultBaseIsMoof = result.flags[0] & 0x020000,
|
10842 | i;
|
10843 | i = 8;
|
10844 |
|
10845 | if (baseDataOffsetPresent) {
|
10846 | i += 4;
|
10847 |
|
10848 |
|
10849 | result.baseDataOffset = view.getUint32(12);
|
10850 | i += 4;
|
10851 | }
|
10852 |
|
10853 | if (sampleDescriptionIndexPresent) {
|
10854 | result.sampleDescriptionIndex = view.getUint32(i);
|
10855 | i += 4;
|
10856 | }
|
10857 |
|
10858 | if (defaultSampleDurationPresent) {
|
10859 | result.defaultSampleDuration = view.getUint32(i);
|
10860 | i += 4;
|
10861 | }
|
10862 |
|
10863 | if (defaultSampleSizePresent) {
|
10864 | result.defaultSampleSize = view.getUint32(i);
|
10865 | i += 4;
|
10866 | }
|
10867 |
|
10868 | if (defaultSampleFlagsPresent) {
|
10869 | result.defaultSampleFlags = view.getUint32(i);
|
10870 | }
|
10871 |
|
10872 | if (durationIsEmpty) {
|
10873 | result.durationIsEmpty = true;
|
10874 | }
|
10875 |
|
10876 | if (!baseDataOffsetPresent && defaultBaseIsMoof) {
|
10877 | result.baseDataOffsetIsMoof = true;
|
10878 | }
|
10879 |
|
10880 | return result;
|
10881 | };
|
10882 |
|
10883 | var parseTfhd = tfhd;
|
10884 | var discardEmulationPreventionBytes = captionPacketParser.discardEmulationPreventionBytes;
|
10885 | var CaptionStream = captionStream.CaptionStream;
|
10886 | |
10887 |
|
10888 |
|
10889 |
|
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 |
|
10895 |
|
10896 |
|
10897 | var mapToSample = function mapToSample(offset, samples) {
|
10898 | var approximateOffset = offset;
|
10899 |
|
10900 | for (var i = 0; i < samples.length; i++) {
|
10901 | var sample = samples[i];
|
10902 |
|
10903 | if (approximateOffset < sample.size) {
|
10904 | return sample;
|
10905 | }
|
10906 |
|
10907 | approximateOffset -= sample.size;
|
10908 | }
|
10909 |
|
10910 | return null;
|
10911 | };
|
10912 | |
10913 |
|
10914 |
|
10915 |
|
10916 |
|
10917 |
|
10918 |
|
10919 |
|
10920 |
|
10921 |
|
10922 |
|
10923 |
|
10924 |
|
10925 |
|
10926 |
|
10927 |
|
10928 | var findSeiNals = function findSeiNals(avcStream, samples, trackId) {
|
10929 | var avcView = new DataView(avcStream.buffer, avcStream.byteOffset, avcStream.byteLength),
|
10930 | result = [],
|
10931 | seiNal,
|
10932 | i,
|
10933 | length,
|
10934 | lastMatchedSample;
|
10935 |
|
10936 | for (i = 0; i + 4 < avcStream.length; i += length) {
|
10937 | length = avcView.getUint32(i);
|
10938 | i += 4;
|
10939 |
|
10940 | if (length <= 0) {
|
10941 | continue;
|
10942 | }
|
10943 |
|
10944 | switch (avcStream[i] & 0x1F) {
|
10945 | case 0x06:
|
10946 | var data = avcStream.subarray(i + 1, i + 1 + length);
|
10947 | var matchingSample = mapToSample(i, samples);
|
10948 | seiNal = {
|
10949 | nalUnitType: 'sei_rbsp',
|
10950 | size: length,
|
10951 | data: data,
|
10952 | escapedRBSP: discardEmulationPreventionBytes(data),
|
10953 | trackId: trackId
|
10954 | };
|
10955 |
|
10956 | if (matchingSample) {
|
10957 | seiNal.pts = matchingSample.pts;
|
10958 | seiNal.dts = matchingSample.dts;
|
10959 | lastMatchedSample = matchingSample;
|
10960 | } else if (lastMatchedSample) {
|
10961 |
|
10962 |
|
10963 | seiNal.pts = lastMatchedSample.pts;
|
10964 | seiNal.dts = lastMatchedSample.dts;
|
10965 | } else {
|
10966 |
|
10967 | console.log("We've encountered a nal unit without data. See mux.js#233.");
|
10968 | break;
|
10969 | }
|
10970 |
|
10971 | result.push(seiNal);
|
10972 | break;
|
10973 | }
|
10974 | }
|
10975 |
|
10976 | return result;
|
10977 | };
|
10978 | |
10979 |
|
10980 |
|
10981 |
|
10982 |
|
10983 |
|
10984 |
|
10985 |
|
10986 |
|
10987 |
|
10988 |
|
10989 |
|
10990 |
|
10991 |
|
10992 |
|
10993 | var parseSamples = function parseSamples(truns, baseMediaDecodeTime, tfhd) {
|
10994 | var currentDts = baseMediaDecodeTime;
|
10995 | var defaultSampleDuration = tfhd.defaultSampleDuration || 0;
|
10996 | var defaultSampleSize = tfhd.defaultSampleSize || 0;
|
10997 | var trackId = tfhd.trackId;
|
10998 | var allSamples = [];
|
10999 | truns.forEach(function (trun) {
|
11000 |
|
11001 |
|
11002 |
|
11003 | var trackRun = parseTrun(trun);
|
11004 | var samples = trackRun.samples;
|
11005 | samples.forEach(function (sample) {
|
11006 | if (sample.duration === undefined) {
|
11007 | sample.duration = defaultSampleDuration;
|
11008 | }
|
11009 |
|
11010 | if (sample.size === undefined) {
|
11011 | sample.size = defaultSampleSize;
|
11012 | }
|
11013 |
|
11014 | sample.trackId = trackId;
|
11015 | sample.dts = currentDts;
|
11016 |
|
11017 | if (sample.compositionTimeOffset === undefined) {
|
11018 | sample.compositionTimeOffset = 0;
|
11019 | }
|
11020 |
|
11021 | sample.pts = currentDts + sample.compositionTimeOffset;
|
11022 | currentDts += sample.duration;
|
11023 | });
|
11024 | allSamples = allSamples.concat(samples);
|
11025 | });
|
11026 | return allSamples;
|
11027 | };
|
11028 | |
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 |
|
11035 |
|
11036 |
|
11037 |
|
11038 | var parseCaptionNals = function parseCaptionNals(segment, videoTrackId) {
|
11039 |
|
11040 | var trafs = findBox_1(segment, ['moof', 'traf']);
|
11041 |
|
11042 | var mdats = findBox_1(segment, ['mdat']);
|
11043 | var captionNals = {};
|
11044 | var mdatTrafPairs = [];
|
11045 |
|
11046 | mdats.forEach(function (mdat, index) {
|
11047 | var matchingTraf = trafs[index];
|
11048 | mdatTrafPairs.push({
|
11049 | mdat: mdat,
|
11050 | traf: matchingTraf
|
11051 | });
|
11052 | });
|
11053 | mdatTrafPairs.forEach(function (pair) {
|
11054 | var mdat = pair.mdat;
|
11055 | var traf = pair.traf;
|
11056 | var tfhd = findBox_1(traf, ['tfhd']);
|
11057 |
|
11058 | var headerInfo = parseTfhd(tfhd[0]);
|
11059 | var trackId = headerInfo.trackId;
|
11060 | var tfdt = findBox_1(traf, ['tfdt']);
|
11061 |
|
11062 | var baseMediaDecodeTime = tfdt.length > 0 ? parseTfdt(tfdt[0]).baseMediaDecodeTime : 0;
|
11063 | var truns = findBox_1(traf, ['trun']);
|
11064 | var samples;
|
11065 | var seiNals;
|
11066 |
|
11067 | if (videoTrackId === trackId && truns.length > 0) {
|
11068 | samples = parseSamples(truns, baseMediaDecodeTime, headerInfo);
|
11069 | seiNals = findSeiNals(mdat, samples, trackId);
|
11070 |
|
11071 | if (!captionNals[trackId]) {
|
11072 | captionNals[trackId] = [];
|
11073 | }
|
11074 |
|
11075 | captionNals[trackId] = captionNals[trackId].concat(seiNals);
|
11076 | }
|
11077 | });
|
11078 | return captionNals;
|
11079 | };
|
11080 | |
11081 |
|
11082 |
|
11083 |
|
11084 |
|
11085 |
|
11086 |
|
11087 |
|
11088 |
|
11089 |
|
11090 |
|
11091 |
|
11092 |
|
11093 |
|
11094 |
|
11095 |
|
11096 |
|
11097 |
|
11098 | var parseEmbeddedCaptions = function parseEmbeddedCaptions(segment, trackId, timescale) {
|
11099 | var seiNals;
|
11100 |
|
11101 | if (trackId === null) {
|
11102 | return null;
|
11103 | }
|
11104 |
|
11105 | seiNals = parseCaptionNals(segment, trackId);
|
11106 | return {
|
11107 | seiNals: seiNals[trackId],
|
11108 | timescale: timescale
|
11109 | };
|
11110 | };
|
11111 | |
11112 |
|
11113 |
|
11114 |
|
11115 |
|
11116 | var CaptionParser = function CaptionParser() {
|
11117 | var isInitialized = false;
|
11118 | var captionStream;
|
11119 |
|
11120 | var segmentCache;
|
11121 |
|
11122 | var trackId;
|
11123 |
|
11124 | var timescale;
|
11125 |
|
11126 | var parsedCaptions;
|
11127 |
|
11128 | var parsingPartial;
|
11129 | |
11130 |
|
11131 |
|
11132 |
|
11133 |
|
11134 | this.isInitialized = function () {
|
11135 | return isInitialized;
|
11136 | };
|
11137 | |
11138 |
|
11139 |
|
11140 |
|
11141 |
|
11142 |
|
11143 | this.init = function (options) {
|
11144 | captionStream = new CaptionStream();
|
11145 | isInitialized = true;
|
11146 | parsingPartial = options ? options.isPartial : false;
|
11147 |
|
11148 | captionStream.on('data', function (event) {
|
11149 |
|
11150 | event.startTime = event.startPts / timescale;
|
11151 | event.endTime = event.endPts / timescale;
|
11152 | parsedCaptions.captions.push(event);
|
11153 | parsedCaptions.captionStreams[event.stream] = true;
|
11154 | });
|
11155 | };
|
11156 | |
11157 |
|
11158 |
|
11159 |
|
11160 |
|
11161 |
|
11162 |
|
11163 | this.isNewInit = function (videoTrackIds, timescales) {
|
11164 | if (videoTrackIds && videoTrackIds.length === 0 || timescales && typeof timescales === 'object' && Object.keys(timescales).length === 0) {
|
11165 | return false;
|
11166 | }
|
11167 |
|
11168 | return trackId !== videoTrackIds[0] || timescale !== timescales[trackId];
|
11169 | };
|
11170 | |
11171 |
|
11172 |
|
11173 |
|
11174 |
|
11175 |
|
11176 |
|
11177 |
|
11178 |
|
11179 |
|
11180 |
|
11181 |
|
11182 | this.parse = function (segment, videoTrackIds, timescales) {
|
11183 | var parsedData;
|
11184 |
|
11185 | if (!this.isInitialized()) {
|
11186 | return null;
|
11187 | } else if (!videoTrackIds || !timescales) {
|
11188 | return null;
|
11189 | } else if (this.isNewInit(videoTrackIds, timescales)) {
|
11190 |
|
11191 |
|
11192 | trackId = videoTrackIds[0];
|
11193 | timescale = timescales[trackId];
|
11194 |
|
11195 |
|
11196 | } else if (trackId === null || !timescale) {
|
11197 | segmentCache.push(segment);
|
11198 | return null;
|
11199 | }
|
11200 |
|
11201 |
|
11202 | while (segmentCache.length > 0) {
|
11203 | var cachedSegment = segmentCache.shift();
|
11204 | this.parse(cachedSegment, videoTrackIds, timescales);
|
11205 | }
|
11206 |
|
11207 | parsedData = parseEmbeddedCaptions(segment, trackId, timescale);
|
11208 |
|
11209 | if (parsedData === null || !parsedData.seiNals) {
|
11210 | return null;
|
11211 | }
|
11212 |
|
11213 | this.pushNals(parsedData.seiNals);
|
11214 |
|
11215 | this.flushStream();
|
11216 | return parsedCaptions;
|
11217 | };
|
11218 | |
11219 |
|
11220 |
|
11221 |
|
11222 |
|
11223 |
|
11224 |
|
11225 |
|
11226 | this.pushNals = function (nals) {
|
11227 | if (!this.isInitialized() || !nals || nals.length === 0) {
|
11228 | return null;
|
11229 | }
|
11230 |
|
11231 | nals.forEach(function (nal) {
|
11232 | captionStream.push(nal);
|
11233 | });
|
11234 | };
|
11235 | |
11236 |
|
11237 |
|
11238 |
|
11239 |
|
11240 |
|
11241 | this.flushStream = function () {
|
11242 | if (!this.isInitialized()) {
|
11243 | return null;
|
11244 | }
|
11245 |
|
11246 | if (!parsingPartial) {
|
11247 | captionStream.flush();
|
11248 | } else {
|
11249 | captionStream.partialFlush();
|
11250 | }
|
11251 | };
|
11252 | |
11253 |
|
11254 |
|
11255 |
|
11256 |
|
11257 | this.clearParsedCaptions = function () {
|
11258 | parsedCaptions.captions = [];
|
11259 | parsedCaptions.captionStreams = {};
|
11260 | };
|
11261 | |
11262 |
|
11263 |
|
11264 |
|
11265 |
|
11266 |
|
11267 | this.resetCaptionStream = function () {
|
11268 | if (!this.isInitialized()) {
|
11269 | return null;
|
11270 | }
|
11271 |
|
11272 | captionStream.reset();
|
11273 | };
|
11274 | |
11275 |
|
11276 |
|
11277 |
|
11278 |
|
11279 |
|
11280 |
|
11281 | this.clearAllCaptions = function () {
|
11282 | this.clearParsedCaptions();
|
11283 | this.resetCaptionStream();
|
11284 | };
|
11285 | |
11286 |
|
11287 |
|
11288 |
|
11289 |
|
11290 | this.reset = function () {
|
11291 | segmentCache = [];
|
11292 | trackId = null;
|
11293 | timescale = null;
|
11294 |
|
11295 | if (!parsedCaptions) {
|
11296 | parsedCaptions = {
|
11297 | captions: [],
|
11298 |
|
11299 | captionStreams: {}
|
11300 | };
|
11301 | } else {
|
11302 | this.clearParsedCaptions();
|
11303 | }
|
11304 |
|
11305 | this.resetCaptionStream();
|
11306 | };
|
11307 |
|
11308 | this.reset();
|
11309 | };
|
11310 |
|
11311 | var captionParser = CaptionParser;
|
11312 |
|
11313 |
|
11314 | var typeFromStreamString = function typeFromStreamString(streamString) {
|
11315 | if (streamString === 'AudioSegmentStream') {
|
11316 | return 'audio';
|
11317 | }
|
11318 |
|
11319 | return streamString === 'VideoSegmentStream' ? 'video' : '';
|
11320 | };
|
11321 | |
11322 |
|
11323 |
|
11324 |
|
11325 |
|
11326 |
|
11327 |
|
11328 |
|
11329 |
|
11330 | var wireFullTransmuxerEvents = function wireFullTransmuxerEvents(self, transmuxer) {
|
11331 | transmuxer.on('data', function (segment) {
|
11332 |
|
11333 |
|
11334 |
|
11335 |
|
11336 | var initArray = segment.initSegment;
|
11337 | segment.initSegment = {
|
11338 | data: initArray.buffer,
|
11339 | byteOffset: initArray.byteOffset,
|
11340 | byteLength: initArray.byteLength
|
11341 | };
|
11342 | var typedArray = segment.data;
|
11343 | segment.data = typedArray.buffer;
|
11344 | self.postMessage({
|
11345 | action: 'data',
|
11346 | segment: segment,
|
11347 | byteOffset: typedArray.byteOffset,
|
11348 | byteLength: typedArray.byteLength
|
11349 | }, [segment.data]);
|
11350 | });
|
11351 | transmuxer.on('done', function (data) {
|
11352 | self.postMessage({
|
11353 | action: 'done'
|
11354 | });
|
11355 | });
|
11356 | transmuxer.on('gopInfo', function (gopInfo) {
|
11357 | self.postMessage({
|
11358 | action: 'gopInfo',
|
11359 | gopInfo: gopInfo
|
11360 | });
|
11361 | });
|
11362 | transmuxer.on('videoSegmentTimingInfo', function (timingInfo) {
|
11363 | var videoSegmentTimingInfo = {
|
11364 | start: {
|
11365 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
11366 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
11367 | },
|
11368 | end: {
|
11369 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
11370 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
11371 | },
|
11372 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
11373 | };
|
11374 |
|
11375 | if (timingInfo.prependedContentDuration) {
|
11376 | videoSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
11377 | }
|
11378 |
|
11379 | self.postMessage({
|
11380 | action: 'videoSegmentTimingInfo',
|
11381 | videoSegmentTimingInfo: videoSegmentTimingInfo
|
11382 | });
|
11383 | });
|
11384 | transmuxer.on('audioSegmentTimingInfo', function (timingInfo) {
|
11385 |
|
11386 | var audioSegmentTimingInfo = {
|
11387 | start: {
|
11388 | decode: clock.videoTsToSeconds(timingInfo.start.dts),
|
11389 | presentation: clock.videoTsToSeconds(timingInfo.start.pts)
|
11390 | },
|
11391 | end: {
|
11392 | decode: clock.videoTsToSeconds(timingInfo.end.dts),
|
11393 | presentation: clock.videoTsToSeconds(timingInfo.end.pts)
|
11394 | },
|
11395 | baseMediaDecodeTime: clock.videoTsToSeconds(timingInfo.baseMediaDecodeTime)
|
11396 | };
|
11397 |
|
11398 | if (timingInfo.prependedContentDuration) {
|
11399 | audioSegmentTimingInfo.prependedContentDuration = clock.videoTsToSeconds(timingInfo.prependedContentDuration);
|
11400 | }
|
11401 |
|
11402 | self.postMessage({
|
11403 | action: 'audioSegmentTimingInfo',
|
11404 | audioSegmentTimingInfo: audioSegmentTimingInfo
|
11405 | });
|
11406 | });
|
11407 | transmuxer.on('id3Frame', function (id3Frame) {
|
11408 | self.postMessage({
|
11409 | action: 'id3Frame',
|
11410 | id3Frame: id3Frame
|
11411 | });
|
11412 | });
|
11413 | transmuxer.on('caption', function (caption) {
|
11414 | self.postMessage({
|
11415 | action: 'caption',
|
11416 | caption: caption
|
11417 | });
|
11418 | });
|
11419 | transmuxer.on('trackinfo', function (trackInfo) {
|
11420 | self.postMessage({
|
11421 | action: 'trackinfo',
|
11422 | trackInfo: trackInfo
|
11423 | });
|
11424 | });
|
11425 | transmuxer.on('audioTimingInfo', function (audioTimingInfo) {
|
11426 |
|
11427 | self.postMessage({
|
11428 | action: 'audioTimingInfo',
|
11429 | audioTimingInfo: {
|
11430 | start: clock.videoTsToSeconds(audioTimingInfo.start),
|
11431 | end: clock.videoTsToSeconds(audioTimingInfo.end)
|
11432 | }
|
11433 | });
|
11434 | });
|
11435 | transmuxer.on('videoTimingInfo', function (videoTimingInfo) {
|
11436 | self.postMessage({
|
11437 | action: 'videoTimingInfo',
|
11438 | videoTimingInfo: {
|
11439 | start: clock.videoTsToSeconds(videoTimingInfo.start),
|
11440 | end: clock.videoTsToSeconds(videoTimingInfo.end)
|
11441 | }
|
11442 | });
|
11443 | });
|
11444 | };
|
11445 |
|
11446 | var wirePartialTransmuxerEvents = function wirePartialTransmuxerEvents(self, transmuxer) {
|
11447 | transmuxer.on('data', function (event) {
|
11448 |
|
11449 |
|
11450 |
|
11451 |
|
11452 | var initSegment = {
|
11453 | data: event.data.track.initSegment.buffer,
|
11454 | byteOffset: event.data.track.initSegment.byteOffset,
|
11455 | byteLength: event.data.track.initSegment.byteLength
|
11456 | };
|
11457 | var boxes = {
|
11458 | data: event.data.boxes.buffer,
|
11459 | byteOffset: event.data.boxes.byteOffset,
|
11460 | byteLength: event.data.boxes.byteLength
|
11461 | };
|
11462 | var segment = {
|
11463 | boxes: boxes,
|
11464 | initSegment: initSegment,
|
11465 | type: event.type,
|
11466 | sequence: event.data.sequence
|
11467 | };
|
11468 |
|
11469 | if (typeof event.data.videoFrameDts !== 'undefined') {
|
11470 | segment.videoFrameDtsTime = clock.videoTsToSeconds(event.data.videoFrameDts);
|
11471 | }
|
11472 |
|
11473 | if (typeof event.data.videoFramePts !== 'undefined') {
|
11474 | segment.videoFramePtsTime = clock.videoTsToSeconds(event.data.videoFramePts);
|
11475 | }
|
11476 |
|
11477 | self.postMessage({
|
11478 | action: 'data',
|
11479 | segment: segment
|
11480 | }, [segment.boxes.data, segment.initSegment.data]);
|
11481 | });
|
11482 | transmuxer.on('id3Frame', function (id3Frame) {
|
11483 | self.postMessage({
|
11484 | action: 'id3Frame',
|
11485 | id3Frame: id3Frame
|
11486 | });
|
11487 | });
|
11488 | transmuxer.on('caption', function (caption) {
|
11489 | self.postMessage({
|
11490 | action: 'caption',
|
11491 | caption: caption
|
11492 | });
|
11493 | });
|
11494 | transmuxer.on('done', function (data) {
|
11495 | self.postMessage({
|
11496 | action: 'done',
|
11497 | type: typeFromStreamString(data)
|
11498 | });
|
11499 | });
|
11500 | transmuxer.on('partialdone', function (data) {
|
11501 | self.postMessage({
|
11502 | action: 'partialdone',
|
11503 | type: typeFromStreamString(data)
|
11504 | });
|
11505 | });
|
11506 | transmuxer.on('endedsegment', function (data) {
|
11507 | self.postMessage({
|
11508 | action: 'endedSegment',
|
11509 | type: typeFromStreamString(data)
|
11510 | });
|
11511 | });
|
11512 | transmuxer.on('trackinfo', function (trackInfo) {
|
11513 | self.postMessage({
|
11514 | action: 'trackinfo',
|
11515 | trackInfo: trackInfo
|
11516 | });
|
11517 | });
|
11518 | transmuxer.on('audioTimingInfo', function (audioTimingInfo) {
|
11519 |
|
11520 |
|
11521 |
|
11522 |
|
11523 | if (audioTimingInfo.start === null) {
|
11524 | self.postMessage({
|
11525 | action: 'audioTimingInfo',
|
11526 | audioTimingInfo: audioTimingInfo
|
11527 | });
|
11528 | return;
|
11529 | }
|
11530 |
|
11531 |
|
11532 | var timingInfoInSeconds = {
|
11533 | start: clock.videoTsToSeconds(audioTimingInfo.start)
|
11534 | };
|
11535 |
|
11536 | if (audioTimingInfo.end) {
|
11537 | timingInfoInSeconds.end = clock.videoTsToSeconds(audioTimingInfo.end);
|
11538 | }
|
11539 |
|
11540 | self.postMessage({
|
11541 | action: 'audioTimingInfo',
|
11542 | audioTimingInfo: timingInfoInSeconds
|
11543 | });
|
11544 | });
|
11545 | transmuxer.on('videoTimingInfo', function (videoTimingInfo) {
|
11546 | var timingInfoInSeconds = {
|
11547 | start: clock.videoTsToSeconds(videoTimingInfo.start)
|
11548 | };
|
11549 |
|
11550 | if (videoTimingInfo.end) {
|
11551 | timingInfoInSeconds.end = clock.videoTsToSeconds(videoTimingInfo.end);
|
11552 | }
|
11553 |
|
11554 | self.postMessage({
|
11555 | action: 'videoTimingInfo',
|
11556 | videoTimingInfo: timingInfoInSeconds
|
11557 | });
|
11558 | });
|
11559 | };
|
11560 | |
11561 |
|
11562 |
|
11563 |
|
11564 |
|
11565 |
|
11566 |
|
11567 |
|
11568 |
|
11569 | var MessageHandlers = function () {
|
11570 | function MessageHandlers(self, options) {
|
11571 | this.options = options || {};
|
11572 | this.self = self;
|
11573 | this.init();
|
11574 | }
|
11575 | |
11576 |
|
11577 |
|
11578 |
|
11579 |
|
11580 | var _proto = MessageHandlers.prototype;
|
11581 |
|
11582 | _proto.init = function init() {
|
11583 | if (this.transmuxer) {
|
11584 | this.transmuxer.dispose();
|
11585 | }
|
11586 |
|
11587 | this.transmuxer = this.options.handlePartialData ? new transmuxer(this.options) : new transmuxer$1.Transmuxer(this.options);
|
11588 |
|
11589 | if (this.options.handlePartialData) {
|
11590 | wirePartialTransmuxerEvents(this.self, this.transmuxer);
|
11591 | } else {
|
11592 | wireFullTransmuxerEvents(this.self, this.transmuxer);
|
11593 | }
|
11594 | };
|
11595 |
|
11596 | _proto.pushMp4Captions = function pushMp4Captions(data) {
|
11597 | if (!this.captionParser) {
|
11598 | this.captionParser = new captionParser();
|
11599 | this.captionParser.init();
|
11600 | }
|
11601 |
|
11602 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
11603 | var parsed = this.captionParser.parse(segment, data.trackIds, data.timescales);
|
11604 | this.self.postMessage({
|
11605 | action: 'mp4Captions',
|
11606 | captions: parsed && parsed.captions || [],
|
11607 | data: segment.buffer
|
11608 | }, [segment.buffer]);
|
11609 | };
|
11610 |
|
11611 | _proto.clearAllMp4Captions = function clearAllMp4Captions() {
|
11612 | if (this.captionParser) {
|
11613 | this.captionParser.clearAllCaptions();
|
11614 | }
|
11615 | };
|
11616 |
|
11617 | _proto.clearParsedMp4Captions = function clearParsedMp4Captions() {
|
11618 | if (this.captionParser) {
|
11619 | this.captionParser.clearParsedCaptions();
|
11620 | }
|
11621 | }
|
11622 | |
11623 |
|
11624 |
|
11625 |
|
11626 |
|
11627 |
|
11628 | ;
|
11629 |
|
11630 | _proto.push = function push(data) {
|
11631 |
|
11632 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
11633 | this.transmuxer.push(segment);
|
11634 | }
|
11635 | |
11636 |
|
11637 |
|
11638 |
|
11639 | ;
|
11640 |
|
11641 | _proto.reset = function reset() {
|
11642 | this.transmuxer.reset();
|
11643 | }
|
11644 | |
11645 |
|
11646 |
|
11647 |
|
11648 |
|
11649 |
|
11650 |
|
11651 | ;
|
11652 |
|
11653 | _proto.setTimestampOffset = function setTimestampOffset(data) {
|
11654 | var timestampOffset = data.timestampOffset || 0;
|
11655 | this.transmuxer.setBaseMediaDecodeTime(Math.round(clock.secondsToVideoTs(timestampOffset)));
|
11656 | };
|
11657 |
|
11658 | _proto.setAudioAppendStart = function setAudioAppendStart(data) {
|
11659 | this.transmuxer.setAudioAppendStart(Math.ceil(clock.secondsToVideoTs(data.appendStart)));
|
11660 | };
|
11661 |
|
11662 | _proto.setRemux = function setRemux(data) {
|
11663 | this.transmuxer.setRemux(data.remux);
|
11664 | }
|
11665 | |
11666 |
|
11667 |
|
11668 |
|
11669 |
|
11670 |
|
11671 | ;
|
11672 |
|
11673 | _proto.flush = function flush(data) {
|
11674 | this.transmuxer.flush();
|
11675 |
|
11676 | self.postMessage({
|
11677 | action: 'done',
|
11678 | type: 'transmuxed'
|
11679 | });
|
11680 | };
|
11681 |
|
11682 | _proto.partialFlush = function partialFlush(data) {
|
11683 | this.transmuxer.partialFlush();
|
11684 |
|
11685 | self.postMessage({
|
11686 | action: 'partialdone',
|
11687 | type: 'transmuxed'
|
11688 | });
|
11689 | };
|
11690 |
|
11691 | _proto.endTimeline = function endTimeline() {
|
11692 | this.transmuxer.endTimeline();
|
11693 |
|
11694 |
|
11695 | self.postMessage({
|
11696 | action: 'endedtimeline',
|
11697 | type: 'transmuxed'
|
11698 | });
|
11699 | };
|
11700 |
|
11701 | _proto.alignGopsWith = function alignGopsWith(data) {
|
11702 | this.transmuxer.alignGopsWith(data.gopsToAlignWith.slice());
|
11703 | };
|
11704 |
|
11705 | return MessageHandlers;
|
11706 | }();
|
11707 | |
11708 |
|
11709 |
|
11710 |
|
11711 |
|
11712 |
|
11713 |
|
11714 |
|
11715 |
|
11716 | self.onmessage = function (event) {
|
11717 | if (event.data.action === 'init' && event.data.options) {
|
11718 | this.messageHandlers = new MessageHandlers(self, event.data.options);
|
11719 | return;
|
11720 | }
|
11721 |
|
11722 | if (!this.messageHandlers) {
|
11723 | this.messageHandlers = new MessageHandlers(self);
|
11724 | }
|
11725 |
|
11726 | if (event.data && event.data.action && event.data.action !== 'init') {
|
11727 | if (this.messageHandlers[event.data.action]) {
|
11728 | this.messageHandlers[event.data.action](event.data);
|
11729 | }
|
11730 | }
|
11731 | };
|
11732 | }));
|
11733 | var TransmuxWorker = factory(workerCode$1);
|
11734 |
|
11735 |
|
11736 | var handleData_ = function handleData_(event, transmuxedData, callback) {
|
11737 | var _event$data$segment = event.data.segment,
|
11738 | type = _event$data$segment.type,
|
11739 | initSegment = _event$data$segment.initSegment,
|
11740 | captions = _event$data$segment.captions,
|
11741 | captionStreams = _event$data$segment.captionStreams,
|
11742 | metadata = _event$data$segment.metadata,
|
11743 | videoFrameDtsTime = _event$data$segment.videoFrameDtsTime,
|
11744 | videoFramePtsTime = _event$data$segment.videoFramePtsTime;
|
11745 | transmuxedData.buffer.push({
|
11746 | captions: captions,
|
11747 | captionStreams: captionStreams,
|
11748 | metadata: metadata
|
11749 | });
|
11750 |
|
11751 | var boxes = event.data.segment.boxes || {
|
11752 | data: event.data.segment.data
|
11753 | };
|
11754 | var result = {
|
11755 | type: type,
|
11756 |
|
11757 | data: new Uint8Array(boxes.data, boxes.data.byteOffset, boxes.data.byteLength),
|
11758 | initSegment: new Uint8Array(initSegment.data, initSegment.byteOffset, initSegment.byteLength)
|
11759 | };
|
11760 |
|
11761 | if (typeof videoFrameDtsTime !== 'undefined') {
|
11762 | result.videoFrameDtsTime = videoFrameDtsTime;
|
11763 | }
|
11764 |
|
11765 | if (typeof videoFramePtsTime !== 'undefined') {
|
11766 | result.videoFramePtsTime = videoFramePtsTime;
|
11767 | }
|
11768 |
|
11769 | callback(result);
|
11770 | };
|
11771 | var handleDone_ = function handleDone_(_ref) {
|
11772 | var transmuxedData = _ref.transmuxedData,
|
11773 | callback = _ref.callback;
|
11774 |
|
11775 |
|
11776 | transmuxedData.buffer = [];
|
11777 |
|
11778 |
|
11779 | callback(transmuxedData);
|
11780 | };
|
11781 | var handleGopInfo_ = function handleGopInfo_(event, transmuxedData) {
|
11782 | transmuxedData.gopInfo = event.data.gopInfo;
|
11783 | };
|
11784 | var processTransmux = function processTransmux(options) {
|
11785 | var transmuxer = options.transmuxer,
|
11786 | bytes = options.bytes,
|
11787 | audioAppendStart = options.audioAppendStart,
|
11788 | gopsToAlignWith = options.gopsToAlignWith,
|
11789 | isPartial = options.isPartial,
|
11790 | remux = options.remux,
|
11791 | onData = options.onData,
|
11792 | onTrackInfo = options.onTrackInfo,
|
11793 | onAudioTimingInfo = options.onAudioTimingInfo,
|
11794 | onVideoTimingInfo = options.onVideoTimingInfo,
|
11795 | onVideoSegmentTimingInfo = options.onVideoSegmentTimingInfo,
|
11796 | onAudioSegmentTimingInfo = options.onAudioSegmentTimingInfo,
|
11797 | onId3 = options.onId3,
|
11798 | onCaptions = options.onCaptions,
|
11799 | onDone = options.onDone,
|
11800 | onEndedTimeline = options.onEndedTimeline,
|
11801 | isEndOfTimeline = options.isEndOfTimeline;
|
11802 | var transmuxedData = {
|
11803 | isPartial: isPartial,
|
11804 | buffer: []
|
11805 | };
|
11806 | var waitForEndedTimelineEvent = isEndOfTimeline;
|
11807 |
|
11808 | var handleMessage = function handleMessage(event) {
|
11809 | if (transmuxer.currentTransmux !== options) {
|
11810 |
|
11811 | return;
|
11812 | }
|
11813 |
|
11814 | if (event.data.action === 'data') {
|
11815 | handleData_(event, transmuxedData, onData);
|
11816 | }
|
11817 |
|
11818 | if (event.data.action === 'trackinfo') {
|
11819 | onTrackInfo(event.data.trackInfo);
|
11820 | }
|
11821 |
|
11822 | if (event.data.action === 'gopInfo') {
|
11823 | handleGopInfo_(event, transmuxedData);
|
11824 | }
|
11825 |
|
11826 | if (event.data.action === 'audioTimingInfo') {
|
11827 | onAudioTimingInfo(event.data.audioTimingInfo);
|
11828 | }
|
11829 |
|
11830 | if (event.data.action === 'videoTimingInfo') {
|
11831 | onVideoTimingInfo(event.data.videoTimingInfo);
|
11832 | }
|
11833 |
|
11834 | if (event.data.action === 'videoSegmentTimingInfo') {
|
11835 | onVideoSegmentTimingInfo(event.data.videoSegmentTimingInfo);
|
11836 | }
|
11837 |
|
11838 | if (event.data.action === 'audioSegmentTimingInfo') {
|
11839 | onAudioSegmentTimingInfo(event.data.audioSegmentTimingInfo);
|
11840 | }
|
11841 |
|
11842 | if (event.data.action === 'id3Frame') {
|
11843 | onId3([event.data.id3Frame], event.data.id3Frame.dispatchType);
|
11844 | }
|
11845 |
|
11846 | if (event.data.action === 'caption') {
|
11847 | onCaptions(event.data.caption);
|
11848 | }
|
11849 |
|
11850 | if (event.data.action === 'endedtimeline') {
|
11851 | waitForEndedTimelineEvent = false;
|
11852 | onEndedTimeline();
|
11853 | }
|
11854 |
|
11855 |
|
11856 | if (event.data.type !== 'transmuxed') {
|
11857 | return;
|
11858 | }
|
11859 |
|
11860 |
|
11861 |
|
11862 |
|
11863 |
|
11864 | if (waitForEndedTimelineEvent) {
|
11865 | return;
|
11866 | }
|
11867 |
|
11868 | transmuxer.onmessage = null;
|
11869 | handleDone_({
|
11870 | transmuxedData: transmuxedData,
|
11871 | callback: onDone
|
11872 | });
|
11873 |
|
11874 |
|
11875 | dequeue(transmuxer);
|
11876 |
|
11877 | };
|
11878 |
|
11879 | transmuxer.onmessage = handleMessage;
|
11880 |
|
11881 | if (audioAppendStart) {
|
11882 | transmuxer.postMessage({
|
11883 | action: 'setAudioAppendStart',
|
11884 | appendStart: audioAppendStart
|
11885 | });
|
11886 | }
|
11887 |
|
11888 |
|
11889 | if (Array.isArray(gopsToAlignWith)) {
|
11890 | transmuxer.postMessage({
|
11891 | action: 'alignGopsWith',
|
11892 | gopsToAlignWith: gopsToAlignWith
|
11893 | });
|
11894 | }
|
11895 |
|
11896 | if (typeof remux !== 'undefined') {
|
11897 | transmuxer.postMessage({
|
11898 | action: 'setRemux',
|
11899 | remux: remux
|
11900 | });
|
11901 | }
|
11902 |
|
11903 | if (bytes.byteLength) {
|
11904 | var buffer = bytes instanceof ArrayBuffer ? bytes : bytes.buffer;
|
11905 | var byteOffset = bytes instanceof ArrayBuffer ? 0 : bytes.byteOffset;
|
11906 | transmuxer.postMessage({
|
11907 | action: 'push',
|
11908 |
|
11909 |
|
11910 |
|
11911 | data: buffer,
|
11912 |
|
11913 |
|
11914 | byteOffset: byteOffset,
|
11915 | byteLength: bytes.byteLength
|
11916 | }, [buffer]);
|
11917 | }
|
11918 |
|
11919 |
|
11920 |
|
11921 | transmuxer.postMessage({
|
11922 | action: isPartial ? 'partialFlush' : 'flush'
|
11923 | });
|
11924 |
|
11925 | if (isEndOfTimeline) {
|
11926 | transmuxer.postMessage({
|
11927 | action: 'endTimeline'
|
11928 | });
|
11929 | }
|
11930 | };
|
11931 | var dequeue = function dequeue(transmuxer) {
|
11932 | transmuxer.currentTransmux = null;
|
11933 |
|
11934 | if (transmuxer.transmuxQueue.length) {
|
11935 | transmuxer.currentTransmux = transmuxer.transmuxQueue.shift();
|
11936 |
|
11937 | if (typeof transmuxer.currentTransmux === 'function') {
|
11938 | transmuxer.currentTransmux();
|
11939 | } else {
|
11940 | processTransmux(transmuxer.currentTransmux);
|
11941 | }
|
11942 | }
|
11943 | };
|
11944 | var processAction = function processAction(transmuxer, action) {
|
11945 | transmuxer.postMessage({
|
11946 | action: action
|
11947 | });
|
11948 | dequeue(transmuxer);
|
11949 | };
|
11950 | var enqueueAction = function enqueueAction(action, transmuxer) {
|
11951 | if (!transmuxer.currentTransmux) {
|
11952 | transmuxer.currentTransmux = action;
|
11953 | processAction(transmuxer, action);
|
11954 | return;
|
11955 | }
|
11956 |
|
11957 | transmuxer.transmuxQueue.push(processAction.bind(null, transmuxer, action));
|
11958 | };
|
11959 | var reset = function reset(transmuxer) {
|
11960 | enqueueAction('reset', transmuxer);
|
11961 | };
|
11962 | var endTimeline = function endTimeline(transmuxer) {
|
11963 | enqueueAction('endTimeline', transmuxer);
|
11964 | };
|
11965 | var transmux = function transmux(options) {
|
11966 | if (!options.transmuxer.currentTransmux) {
|
11967 | options.transmuxer.currentTransmux = options;
|
11968 | processTransmux(options);
|
11969 | return;
|
11970 | }
|
11971 |
|
11972 | options.transmuxer.transmuxQueue.push(options);
|
11973 | };
|
11974 | var createTransmuxer = function createTransmuxer(options) {
|
11975 | var transmuxer = new TransmuxWorker();
|
11976 | transmuxer.currentTransmux = null;
|
11977 | transmuxer.transmuxQueue = [];
|
11978 | var term = transmuxer.terminate;
|
11979 |
|
11980 | transmuxer.terminate = function () {
|
11981 | transmuxer.currentTransmux = null;
|
11982 | transmuxer.transmuxQueue.length = 0;
|
11983 | return term.call(transmuxer);
|
11984 | };
|
11985 |
|
11986 | transmuxer.postMessage({
|
11987 | action: 'init',
|
11988 | options: options
|
11989 | });
|
11990 | return transmuxer;
|
11991 | };
|
11992 | var segmentTransmuxer = {
|
11993 | reset: reset,
|
11994 | endTimeline: endTimeline,
|
11995 | transmux: transmux,
|
11996 | createTransmuxer: createTransmuxer
|
11997 | };
|
11998 |
|
11999 |
|
12000 |
|
12001 |
|
12002 |
|
12003 |
|
12004 |
|
12005 |
|
12006 |
|
12007 |
|
12008 |
|
12009 |
|
12010 |
|
12011 |
|
12012 |
|
12013 | var probeTsSegment = function probeTsSegment(bytes, baseStartTime) {
|
12014 | var tsStartTime = typeof baseStartTime === 'number' && !isNaN(baseStartTime) ? baseStartTime * clock.ONE_SECOND_IN_TS : void 0;
|
12015 | var timeInfo = tsInspector__default['default'].inspect(bytes, tsStartTime);
|
12016 |
|
12017 | if (!timeInfo) {
|
12018 | return null;
|
12019 | }
|
12020 |
|
12021 | var result = {
|
12022 |
|
12023 | hasVideo: timeInfo.video && timeInfo.video.length === 2 || false,
|
12024 | hasAudio: timeInfo.audio && timeInfo.audio.length === 2 || false
|
12025 | };
|
12026 |
|
12027 | if (result.hasVideo) {
|
12028 | result.videoStart = timeInfo.video[0].ptsTime;
|
12029 | }
|
12030 |
|
12031 | if (result.hasAudio) {
|
12032 | result.audioStart = timeInfo.audio[0].ptsTime;
|
12033 | }
|
12034 |
|
12035 | return result;
|
12036 | };
|
12037 |
|
12038 |
|
12039 |
|
12040 |
|
12041 |
|
12042 |
|
12043 |
|
12044 |
|
12045 | var concatSegments = function concatSegments(segmentObj) {
|
12046 | var offset = 0;
|
12047 | var tempBuffer;
|
12048 |
|
12049 | if (segmentObj.bytes) {
|
12050 | tempBuffer = new Uint8Array(segmentObj.bytes);
|
12051 |
|
12052 | segmentObj.segments.forEach(function (segment) {
|
12053 | tempBuffer.set(segment, offset);
|
12054 | offset += segment.byteLength;
|
12055 | });
|
12056 | }
|
12057 |
|
12058 | return tempBuffer;
|
12059 | };
|
12060 |
|
12061 | var REQUEST_ERRORS = {
|
12062 | FAILURE: 2,
|
12063 | TIMEOUT: -101,
|
12064 | ABORTED: -102
|
12065 | };
|
12066 |
|
12067 |
|
12068 |
|
12069 |
|
12070 |
|
12071 |
|
12072 | var abortAll = function abortAll(activeXhrs) {
|
12073 | activeXhrs.forEach(function (xhr) {
|
12074 | xhr.abort();
|
12075 | });
|
12076 | };
|
12077 |
|
12078 |
|
12079 |
|
12080 |
|
12081 |
|
12082 |
|
12083 |
|
12084 | var getRequestStats = function getRequestStats(request) {
|
12085 | return {
|
12086 | bandwidth: request.bandwidth,
|
12087 | bytesReceived: request.bytesReceived || 0,
|
12088 | roundTripTime: request.roundTripTime || 0
|
12089 | };
|
12090 | };
|
12091 |
|
12092 |
|
12093 |
|
12094 |
|
12095 |
|
12096 |
|
12097 |
|
12098 |
|
12099 | var getProgressStats = function getProgressStats(progressEvent) {
|
12100 | var request = progressEvent.target;
|
12101 | var roundTripTime = Date.now() - request.requestTime;
|
12102 | var stats = {
|
12103 | bandwidth: Infinity,
|
12104 | bytesReceived: 0,
|
12105 | roundTripTime: roundTripTime || 0
|
12106 | };
|
12107 | stats.bytesReceived = progressEvent.loaded;
|
12108 |
|
12109 |
|
12110 |
|
12111 | stats.bandwidth = Math.floor(stats.bytesReceived / stats.roundTripTime * 8 * 1000);
|
12112 | return stats;
|
12113 | };
|
12114 |
|
12115 |
|
12116 |
|
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 |
|
12122 |
|
12123 | var handleErrors = function handleErrors(error, request) {
|
12124 | if (request.timedout) {
|
12125 | return {
|
12126 | status: request.status,
|
12127 | message: 'HLS request timed-out at URL: ' + request.uri,
|
12128 | code: REQUEST_ERRORS.TIMEOUT,
|
12129 | xhr: request
|
12130 | };
|
12131 | }
|
12132 |
|
12133 | if (request.aborted) {
|
12134 | return {
|
12135 | status: request.status,
|
12136 | message: 'HLS request aborted at URL: ' + request.uri,
|
12137 | code: REQUEST_ERRORS.ABORTED,
|
12138 | xhr: request
|
12139 | };
|
12140 | }
|
12141 |
|
12142 | if (error) {
|
12143 | return {
|
12144 | status: request.status,
|
12145 | message: 'HLS request errored at URL: ' + request.uri,
|
12146 | code: REQUEST_ERRORS.FAILURE,
|
12147 | xhr: request
|
12148 | };
|
12149 | }
|
12150 |
|
12151 | return null;
|
12152 | };
|
12153 |
|
12154 |
|
12155 |
|
12156 |
|
12157 |
|
12158 |
|
12159 |
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 | var handleKeyResponse = function handleKeyResponse(segment, finishProcessingFn) {
|
12165 | return function (error, request) {
|
12166 | var response = request.response;
|
12167 | var errorObj = handleErrors(error, request);
|
12168 |
|
12169 | if (errorObj) {
|
12170 | return finishProcessingFn(errorObj, segment);
|
12171 | }
|
12172 |
|
12173 | if (response.byteLength !== 16) {
|
12174 | return finishProcessingFn({
|
12175 | status: request.status,
|
12176 | message: 'Invalid HLS key at URL: ' + request.uri,
|
12177 | code: REQUEST_ERRORS.FAILURE,
|
12178 | xhr: request
|
12179 | }, segment);
|
12180 | }
|
12181 |
|
12182 | var view = new DataView(response);
|
12183 | segment.key.bytes = new Uint32Array([view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12)]);
|
12184 | return finishProcessingFn(null, segment);
|
12185 | };
|
12186 | };
|
12187 |
|
12188 |
|
12189 |
|
12190 |
|
12191 |
|
12192 |
|
12193 |
|
12194 |
|
12195 |
|
12196 |
|
12197 | var handleInitSegmentResponse = function handleInitSegmentResponse(_ref) {
|
12198 | var segment = _ref.segment,
|
12199 | finishProcessingFn = _ref.finishProcessingFn;
|
12200 | return function (error, request) {
|
12201 | var response = request.response;
|
12202 | var errorObj = handleErrors(error, request);
|
12203 |
|
12204 | if (errorObj) {
|
12205 | return finishProcessingFn(errorObj, segment);
|
12206 | }
|
12207 |
|
12208 |
|
12209 | if (response.byteLength === 0) {
|
12210 | return finishProcessingFn({
|
12211 | status: request.status,
|
12212 | message: 'Empty HLS segment content at URL: ' + request.uri,
|
12213 | code: REQUEST_ERRORS.FAILURE,
|
12214 | xhr: request
|
12215 | }, segment);
|
12216 | }
|
12217 |
|
12218 | segment.map.bytes = new Uint8Array(request.response);
|
12219 | var type = containers.detectContainerForBytes(segment.map.bytes);
|
12220 |
|
12221 |
|
12222 | if (type !== 'mp4') {
|
12223 | return finishProcessingFn({
|
12224 | status: request.status,
|
12225 | message: "Found unsupported " + (type || 'unknown') + " container for initialization segment at URL: " + request.uri,
|
12226 | code: REQUEST_ERRORS.FAILURE,
|
12227 | internal: true,
|
12228 | xhr: request
|
12229 | }, segment);
|
12230 | }
|
12231 |
|
12232 | var tracks = mp4probe__default['default'].tracks(segment.map.bytes);
|
12233 | tracks.forEach(function (track) {
|
12234 | segment.map.tracks = segment.map.tracks || {};
|
12235 |
|
12236 | if (segment.map.tracks[track.type]) {
|
12237 | return;
|
12238 | }
|
12239 |
|
12240 | segment.map.tracks[track.type] = track;
|
12241 |
|
12242 | if (typeof track.id === 'number' && track.timescale) {
|
12243 | segment.map.timescales = segment.map.timescales || {};
|
12244 | segment.map.timescales[track.id] = track.timescale;
|
12245 | }
|
12246 | });
|
12247 | return finishProcessingFn(null, segment);
|
12248 | };
|
12249 | };
|
12250 |
|
12251 |
|
12252 |
|
12253 |
|
12254 |
|
12255 |
|
12256 |
|
12257 |
|
12258 |
|
12259 |
|
12260 |
|
12261 |
|
12262 | var handleSegmentResponse = function handleSegmentResponse(_ref2) {
|
12263 | var segment = _ref2.segment,
|
12264 | finishProcessingFn = _ref2.finishProcessingFn,
|
12265 | responseType = _ref2.responseType;
|
12266 | return function (error, request) {
|
12267 | var response = request.response;
|
12268 | var errorObj = handleErrors(error, request);
|
12269 |
|
12270 | if (errorObj) {
|
12271 | return finishProcessingFn(errorObj, segment);
|
12272 | }
|
12273 |
|
12274 | var newBytes =
|
12275 |
|
12276 |
|
12277 |
|
12278 |
|
12279 | responseType === 'arraybuffer' || !request.responseText ? request.response : stringToArrayBuffer(request.responseText.substring(segment.lastReachedChar || 0));
|
12280 |
|
12281 | if (response.byteLength === 0) {
|
12282 | return finishProcessingFn({
|
12283 | status: request.status,
|
12284 | message: 'Empty HLS segment content at URL: ' + request.uri,
|
12285 | code: REQUEST_ERRORS.FAILURE,
|
12286 | xhr: request
|
12287 | }, segment);
|
12288 | }
|
12289 |
|
12290 | segment.stats = getRequestStats(request);
|
12291 |
|
12292 | if (segment.key) {
|
12293 | segment.encryptedBytes = new Uint8Array(newBytes);
|
12294 | } else {
|
12295 | segment.bytes = new Uint8Array(newBytes);
|
12296 | }
|
12297 |
|
12298 | return finishProcessingFn(null, segment);
|
12299 | };
|
12300 | };
|
12301 |
|
12302 | var transmuxAndNotify = function transmuxAndNotify(_ref3) {
|
12303 | var segment = _ref3.segment,
|
12304 | bytes = _ref3.bytes,
|
12305 | isPartial = _ref3.isPartial,
|
12306 | trackInfoFn = _ref3.trackInfoFn,
|
12307 | timingInfoFn = _ref3.timingInfoFn,
|
12308 | videoSegmentTimingInfoFn = _ref3.videoSegmentTimingInfoFn,
|
12309 | audioSegmentTimingInfoFn = _ref3.audioSegmentTimingInfoFn,
|
12310 | id3Fn = _ref3.id3Fn,
|
12311 | captionsFn = _ref3.captionsFn,
|
12312 | isEndOfTimeline = _ref3.isEndOfTimeline,
|
12313 | endedTimelineFn = _ref3.endedTimelineFn,
|
12314 | dataFn = _ref3.dataFn,
|
12315 | doneFn = _ref3.doneFn;
|
12316 | var fmp4Tracks = segment.map && segment.map.tracks || {};
|
12317 | var isMuxed = Boolean(fmp4Tracks.audio && fmp4Tracks.video);
|
12318 |
|
12319 |
|
12320 |
|
12321 | var audioStartFn = timingInfoFn.bind(null, segment, 'audio', 'start');
|
12322 | var audioEndFn = timingInfoFn.bind(null, segment, 'audio', 'end');
|
12323 | var videoStartFn = timingInfoFn.bind(null, segment, 'video', 'start');
|
12324 | var videoEndFn = timingInfoFn.bind(null, segment, 'video', 'end');
|
12325 |
|
12326 | if (!isPartial && !segment.lastReachedChar) {
|
12327 |
|
12328 |
|
12329 |
|
12330 |
|
12331 | var probeResult = probeTsSegment(bytes, segment.baseStartTime);
|
12332 |
|
12333 | if (probeResult) {
|
12334 | trackInfoFn(segment, {
|
12335 | hasAudio: probeResult.hasAudio,
|
12336 | hasVideo: probeResult.hasVideo,
|
12337 | isMuxed: isMuxed
|
12338 | });
|
12339 | trackInfoFn = null;
|
12340 |
|
12341 | if (probeResult.hasAudio && !isMuxed) {
|
12342 | audioStartFn(probeResult.audioStart);
|
12343 | }
|
12344 |
|
12345 | if (probeResult.hasVideo) {
|
12346 | videoStartFn(probeResult.videoStart);
|
12347 | }
|
12348 |
|
12349 | audioStartFn = null;
|
12350 | videoStartFn = null;
|
12351 | }
|
12352 | }
|
12353 |
|
12354 | transmux({
|
12355 | bytes: bytes,
|
12356 | transmuxer: segment.transmuxer,
|
12357 | audioAppendStart: segment.audioAppendStart,
|
12358 | gopsToAlignWith: segment.gopsToAlignWith,
|
12359 | isPartial: isPartial,
|
12360 | remux: isMuxed,
|
12361 | onData: function onData(result) {
|
12362 | result.type = result.type === 'combined' ? 'video' : result.type;
|
12363 | dataFn(segment, result);
|
12364 | },
|
12365 | onTrackInfo: function onTrackInfo(trackInfo) {
|
12366 | if (trackInfoFn) {
|
12367 | if (isMuxed) {
|
12368 | trackInfo.isMuxed = true;
|
12369 | }
|
12370 |
|
12371 | trackInfoFn(segment, trackInfo);
|
12372 | }
|
12373 | },
|
12374 | onAudioTimingInfo: function onAudioTimingInfo(audioTimingInfo) {
|
12375 |
|
12376 | if (audioStartFn && typeof audioTimingInfo.start !== 'undefined') {
|
12377 | audioStartFn(audioTimingInfo.start);
|
12378 | audioStartFn = null;
|
12379 | }
|
12380 |
|
12381 |
|
12382 | if (audioEndFn && typeof audioTimingInfo.end !== 'undefined') {
|
12383 | audioEndFn(audioTimingInfo.end);
|
12384 | }
|
12385 | },
|
12386 | onVideoTimingInfo: function onVideoTimingInfo(videoTimingInfo) {
|
12387 |
|
12388 | if (videoStartFn && typeof videoTimingInfo.start !== 'undefined') {
|
12389 | videoStartFn(videoTimingInfo.start);
|
12390 | videoStartFn = null;
|
12391 | }
|
12392 |
|
12393 |
|
12394 | if (videoEndFn && typeof videoTimingInfo.end !== 'undefined') {
|
12395 | videoEndFn(videoTimingInfo.end);
|
12396 | }
|
12397 | },
|
12398 | onVideoSegmentTimingInfo: function onVideoSegmentTimingInfo(videoSegmentTimingInfo) {
|
12399 | videoSegmentTimingInfoFn(videoSegmentTimingInfo);
|
12400 | },
|
12401 | onAudioSegmentTimingInfo: function onAudioSegmentTimingInfo(audioSegmentTimingInfo) {
|
12402 | audioSegmentTimingInfoFn(audioSegmentTimingInfo);
|
12403 | },
|
12404 | onId3: function onId3(id3Frames, dispatchType) {
|
12405 | id3Fn(segment, id3Frames, dispatchType);
|
12406 | },
|
12407 | onCaptions: function onCaptions(captions) {
|
12408 | captionsFn(segment, [captions]);
|
12409 | },
|
12410 |
|
12411 |
|
12412 |
|
12413 | isEndOfTimeline: isEndOfTimeline && !isPartial,
|
12414 | onEndedTimeline: function onEndedTimeline() {
|
12415 | endedTimelineFn();
|
12416 | },
|
12417 | onDone: function onDone(result) {
|
12418 |
|
12419 |
|
12420 | if (!doneFn || isPartial) {
|
12421 | return;
|
12422 | }
|
12423 |
|
12424 | result.type = result.type === 'combined' ? 'video' : result.type;
|
12425 | doneFn(null, segment, result);
|
12426 | }
|
12427 | });
|
12428 | };
|
12429 |
|
12430 | var handleSegmentBytes = function handleSegmentBytes(_ref4) {
|
12431 | var segment = _ref4.segment,
|
12432 | bytes = _ref4.bytes,
|
12433 | isPartial = _ref4.isPartial,
|
12434 | trackInfoFn = _ref4.trackInfoFn,
|
12435 | timingInfoFn = _ref4.timingInfoFn,
|
12436 | videoSegmentTimingInfoFn = _ref4.videoSegmentTimingInfoFn,
|
12437 | audioSegmentTimingInfoFn = _ref4.audioSegmentTimingInfoFn,
|
12438 | id3Fn = _ref4.id3Fn,
|
12439 | captionsFn = _ref4.captionsFn,
|
12440 | isEndOfTimeline = _ref4.isEndOfTimeline,
|
12441 | endedTimelineFn = _ref4.endedTimelineFn,
|
12442 | dataFn = _ref4.dataFn,
|
12443 | doneFn = _ref4.doneFn;
|
12444 | var bytesAsUint8Array = new Uint8Array(bytes);
|
12445 |
|
12446 |
|
12447 |
|
12448 |
|
12449 |
|
12450 | if (containers.isLikelyFmp4MediaSegment(bytesAsUint8Array)) {
|
12451 | segment.isFmp4 = true;
|
12452 | var tracks = segment.map.tracks;
|
12453 | var trackInfo = {
|
12454 | isFmp4: true,
|
12455 | hasVideo: !!tracks.video,
|
12456 | hasAudio: !!tracks.audio
|
12457 | };
|
12458 |
|
12459 |
|
12460 | if (tracks.audio && tracks.audio.codec && tracks.audio.codec !== 'enca') {
|
12461 | trackInfo.audioCodec = tracks.audio.codec;
|
12462 | }
|
12463 |
|
12464 |
|
12465 |
|
12466 | if (tracks.video && tracks.video.codec && tracks.video.codec !== 'encv') {
|
12467 | trackInfo.videoCodec = tracks.video.codec;
|
12468 | }
|
12469 |
|
12470 | if (tracks.video && tracks.audio) {
|
12471 | trackInfo.isMuxed = true;
|
12472 | }
|
12473 |
|
12474 |
|
12475 |
|
12476 | trackInfoFn(segment, trackInfo);
|
12477 |
|
12478 |
|
12479 |
|
12480 |
|
12481 |
|
12482 |
|
12483 | var timingInfo = mp4probe__default['default'].startTime(segment.map.timescales, bytesAsUint8Array);
|
12484 |
|
12485 | if (trackInfo.hasAudio && !trackInfo.isMuxed) {
|
12486 | timingInfoFn(segment, 'audio', 'start', timingInfo);
|
12487 | }
|
12488 |
|
12489 | if (trackInfo.hasVideo) {
|
12490 | timingInfoFn(segment, 'video', 'start', timingInfo);
|
12491 | }
|
12492 |
|
12493 | var finishLoading = function finishLoading(captions) {
|
12494 |
|
12495 |
|
12496 |
|
12497 |
|
12498 | dataFn(segment, {
|
12499 | data: bytes,
|
12500 | type: trackInfo.hasAudio && !trackInfo.isMuxed ? 'audio' : 'video'
|
12501 | });
|
12502 |
|
12503 | if (captions && captions.length) {
|
12504 | captionsFn(segment, captions);
|
12505 | }
|
12506 |
|
12507 | doneFn(null, segment, {});
|
12508 | };
|
12509 |
|
12510 |
|
12511 |
|
12512 | if (!tracks.video || !bytes.byteLength || !segment.transmuxer) {
|
12513 | finishLoading();
|
12514 | return;
|
12515 | }
|
12516 |
|
12517 | var buffer = bytes instanceof ArrayBuffer ? bytes : bytes.buffer;
|
12518 | var byteOffset = bytes instanceof ArrayBuffer ? 0 : bytes.byteOffset;
|
12519 |
|
12520 | var listenForCaptions = function listenForCaptions(event) {
|
12521 | if (event.data.action !== 'mp4Captions') {
|
12522 | return;
|
12523 | }
|
12524 |
|
12525 | segment.transmuxer.removeEventListener('message', listenForCaptions);
|
12526 | var data = event.data.data;
|
12527 |
|
12528 | segment.bytes = bytes = new Uint8Array(data, data.byteOffset || 0, data.byteLength);
|
12529 | finishLoading(event.data.captions);
|
12530 | };
|
12531 |
|
12532 | segment.transmuxer.addEventListener('message', listenForCaptions);
|
12533 |
|
12534 | segment.transmuxer.postMessage({
|
12535 | action: 'pushMp4Captions',
|
12536 | timescales: segment.map.timescales,
|
12537 | trackIds: [tracks.video.id],
|
12538 | data: buffer,
|
12539 | byteOffset: byteOffset,
|
12540 | byteLength: bytes.byteLength
|
12541 | }, [buffer]);
|
12542 | return;
|
12543 | }
|
12544 |
|
12545 |
|
12546 | if (!segment.transmuxer) {
|
12547 | doneFn(null, segment, {});
|
12548 | return;
|
12549 | }
|
12550 |
|
12551 | if (typeof segment.container === 'undefined') {
|
12552 | segment.container = containers.detectContainerForBytes(bytesAsUint8Array);
|
12553 | }
|
12554 |
|
12555 | if (segment.container !== 'ts' && segment.container !== 'aac') {
|
12556 | trackInfoFn(segment, {
|
12557 | hasAudio: false,
|
12558 | hasVideo: false
|
12559 | });
|
12560 | doneFn(null, segment, {});
|
12561 | return;
|
12562 | }
|
12563 |
|
12564 |
|
12565 | transmuxAndNotify({
|
12566 | segment: segment,
|
12567 | bytes: bytes,
|
12568 | isPartial: isPartial,
|
12569 | trackInfoFn: trackInfoFn,
|
12570 | timingInfoFn: timingInfoFn,
|
12571 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
12572 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
12573 | id3Fn: id3Fn,
|
12574 | captionsFn: captionsFn,
|
12575 | isEndOfTimeline: isEndOfTimeline,
|
12576 | endedTimelineFn: endedTimelineFn,
|
12577 | dataFn: dataFn,
|
12578 | doneFn: doneFn
|
12579 | });
|
12580 | };
|
12581 |
|
12582 |
|
12583 |
|
12584 |
|
12585 |
|
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 |
|
12591 |
|
12592 |
|
12593 |
|
12594 |
|
12595 |
|
12596 |
|
12597 |
|
12598 |
|
12599 |
|
12600 |
|
12601 |
|
12602 |
|
12603 |
|
12604 |
|
12605 |
|
12606 |
|
12607 | var decryptSegment = function decryptSegment(_ref5) {
|
12608 | var decryptionWorker = _ref5.decryptionWorker,
|
12609 | segment = _ref5.segment,
|
12610 | trackInfoFn = _ref5.trackInfoFn,
|
12611 | timingInfoFn = _ref5.timingInfoFn,
|
12612 | videoSegmentTimingInfoFn = _ref5.videoSegmentTimingInfoFn,
|
12613 | audioSegmentTimingInfoFn = _ref5.audioSegmentTimingInfoFn,
|
12614 | id3Fn = _ref5.id3Fn,
|
12615 | captionsFn = _ref5.captionsFn,
|
12616 | isEndOfTimeline = _ref5.isEndOfTimeline,
|
12617 | endedTimelineFn = _ref5.endedTimelineFn,
|
12618 | dataFn = _ref5.dataFn,
|
12619 | doneFn = _ref5.doneFn;
|
12620 |
|
12621 | var decryptionHandler = function decryptionHandler(event) {
|
12622 | if (event.data.source === segment.requestId) {
|
12623 | decryptionWorker.removeEventListener('message', decryptionHandler);
|
12624 | var decrypted = event.data.decrypted;
|
12625 | segment.bytes = new Uint8Array(decrypted.bytes, decrypted.byteOffset, decrypted.byteLength);
|
12626 | handleSegmentBytes({
|
12627 | segment: segment,
|
12628 | bytes: segment.bytes,
|
12629 | isPartial: false,
|
12630 | trackInfoFn: trackInfoFn,
|
12631 | timingInfoFn: timingInfoFn,
|
12632 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
12633 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
12634 | id3Fn: id3Fn,
|
12635 | captionsFn: captionsFn,
|
12636 | isEndOfTimeline: isEndOfTimeline,
|
12637 | endedTimelineFn: endedTimelineFn,
|
12638 | dataFn: dataFn,
|
12639 | doneFn: doneFn
|
12640 | });
|
12641 | }
|
12642 | };
|
12643 |
|
12644 | decryptionWorker.addEventListener('message', decryptionHandler);
|
12645 | var keyBytes;
|
12646 |
|
12647 | if (segment.key.bytes.slice) {
|
12648 | keyBytes = segment.key.bytes.slice();
|
12649 | } else {
|
12650 | keyBytes = new Uint32Array(Array.prototype.slice.call(segment.key.bytes));
|
12651 | }
|
12652 |
|
12653 |
|
12654 |
|
12655 | decryptionWorker.postMessage(createTransferableMessage({
|
12656 | source: segment.requestId,
|
12657 | encrypted: segment.encryptedBytes,
|
12658 | key: keyBytes,
|
12659 | iv: segment.key.iv
|
12660 | }), [segment.encryptedBytes.buffer, keyBytes.buffer]);
|
12661 | };
|
12662 |
|
12663 |
|
12664 |
|
12665 |
|
12666 |
|
12667 |
|
12668 |
|
12669 |
|
12670 |
|
12671 |
|
12672 |
|
12673 |
|
12674 |
|
12675 |
|
12676 |
|
12677 |
|
12678 |
|
12679 |
|
12680 |
|
12681 |
|
12682 |
|
12683 |
|
12684 |
|
12685 |
|
12686 |
|
12687 |
|
12688 |
|
12689 |
|
12690 |
|
12691 |
|
12692 |
|
12693 | var waitForCompletion = function waitForCompletion(_ref6) {
|
12694 | var activeXhrs = _ref6.activeXhrs,
|
12695 | decryptionWorker = _ref6.decryptionWorker,
|
12696 | trackInfoFn = _ref6.trackInfoFn,
|
12697 | timingInfoFn = _ref6.timingInfoFn,
|
12698 | videoSegmentTimingInfoFn = _ref6.videoSegmentTimingInfoFn,
|
12699 | audioSegmentTimingInfoFn = _ref6.audioSegmentTimingInfoFn,
|
12700 | id3Fn = _ref6.id3Fn,
|
12701 | captionsFn = _ref6.captionsFn,
|
12702 | isEndOfTimeline = _ref6.isEndOfTimeline,
|
12703 | endedTimelineFn = _ref6.endedTimelineFn,
|
12704 | dataFn = _ref6.dataFn,
|
12705 | doneFn = _ref6.doneFn;
|
12706 | var count = 0;
|
12707 | var didError = false;
|
12708 | return function (error, segment) {
|
12709 | if (didError) {
|
12710 | return;
|
12711 | }
|
12712 |
|
12713 | if (error) {
|
12714 | didError = true;
|
12715 |
|
12716 | abortAll(activeXhrs);
|
12717 |
|
12718 |
|
12719 |
|
12720 |
|
12721 |
|
12722 |
|
12723 |
|
12724 |
|
12725 |
|
12726 |
|
12727 |
|
12728 | return doneFn(error, segment);
|
12729 | }
|
12730 |
|
12731 | count += 1;
|
12732 |
|
12733 | if (count === activeXhrs.length) {
|
12734 |
|
12735 | segment.endOfAllRequests = Date.now();
|
12736 |
|
12737 | if (segment.encryptedBytes) {
|
12738 | return decryptSegment({
|
12739 | decryptionWorker: decryptionWorker,
|
12740 | segment: segment,
|
12741 | trackInfoFn: trackInfoFn,
|
12742 | timingInfoFn: timingInfoFn,
|
12743 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
12744 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
12745 | id3Fn: id3Fn,
|
12746 | captionsFn: captionsFn,
|
12747 | isEndOfTimeline: isEndOfTimeline,
|
12748 | endedTimelineFn: endedTimelineFn,
|
12749 | dataFn: dataFn,
|
12750 | doneFn: doneFn
|
12751 | });
|
12752 | }
|
12753 |
|
12754 |
|
12755 | handleSegmentBytes({
|
12756 | segment: segment,
|
12757 | bytes: segment.bytes,
|
12758 | isPartial: false,
|
12759 | trackInfoFn: trackInfoFn,
|
12760 | timingInfoFn: timingInfoFn,
|
12761 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
12762 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
12763 | id3Fn: id3Fn,
|
12764 | captionsFn: captionsFn,
|
12765 | isEndOfTimeline: isEndOfTimeline,
|
12766 | endedTimelineFn: endedTimelineFn,
|
12767 | dataFn: dataFn,
|
12768 | doneFn: doneFn
|
12769 | });
|
12770 | }
|
12771 | };
|
12772 | };
|
12773 |
|
12774 |
|
12775 |
|
12776 |
|
12777 |
|
12778 |
|
12779 |
|
12780 |
|
12781 |
|
12782 | var handleLoadEnd = function handleLoadEnd(_ref7) {
|
12783 | var loadendState = _ref7.loadendState,
|
12784 | abortFn = _ref7.abortFn;
|
12785 | return function (event) {
|
12786 | var request = event.target;
|
12787 |
|
12788 | if (request.aborted && abortFn && !loadendState.calledAbortFn) {
|
12789 | abortFn();
|
12790 | loadendState.calledAbortFn = true;
|
12791 | }
|
12792 | };
|
12793 | };
|
12794 |
|
12795 |
|
12796 |
|
12797 |
|
12798 |
|
12799 |
|
12800 |
|
12801 |
|
12802 |
|
12803 |
|
12804 |
|
12805 |
|
12806 |
|
12807 |
|
12808 |
|
12809 |
|
12810 |
|
12811 |
|
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 |
|
12817 |
|
12818 |
|
12819 |
|
12820 |
|
12821 | var handleProgress = function handleProgress(_ref8) {
|
12822 | var segment = _ref8.segment,
|
12823 | progressFn = _ref8.progressFn,
|
12824 | trackInfoFn = _ref8.trackInfoFn,
|
12825 | timingInfoFn = _ref8.timingInfoFn,
|
12826 | videoSegmentTimingInfoFn = _ref8.videoSegmentTimingInfoFn,
|
12827 | audioSegmentTimingInfoFn = _ref8.audioSegmentTimingInfoFn,
|
12828 | id3Fn = _ref8.id3Fn,
|
12829 | captionsFn = _ref8.captionsFn,
|
12830 | isEndOfTimeline = _ref8.isEndOfTimeline,
|
12831 | endedTimelineFn = _ref8.endedTimelineFn,
|
12832 | dataFn = _ref8.dataFn,
|
12833 | handlePartialData = _ref8.handlePartialData;
|
12834 | return function (event) {
|
12835 | var request = event.target;
|
12836 |
|
12837 | if (request.aborted) {
|
12838 | return;
|
12839 | }
|
12840 |
|
12841 |
|
12842 | if (handlePartialData && !segment.key &&
|
12843 |
|
12844 |
|
12845 |
|
12846 |
|
12847 | request.responseText &&
|
12848 | request.responseText.length >= 8) {
|
12849 | var newBytes = stringToArrayBuffer(request.responseText.substring(segment.lastReachedChar || 0));
|
12850 |
|
12851 | if (segment.lastReachedChar || !containers.isLikelyFmp4MediaSegment(new Uint8Array(newBytes))) {
|
12852 | segment.lastReachedChar = request.responseText.length;
|
12853 | handleSegmentBytes({
|
12854 | segment: segment,
|
12855 | bytes: newBytes,
|
12856 | isPartial: true,
|
12857 | trackInfoFn: trackInfoFn,
|
12858 | timingInfoFn: timingInfoFn,
|
12859 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
12860 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
12861 | id3Fn: id3Fn,
|
12862 | captionsFn: captionsFn,
|
12863 | isEndOfTimeline: isEndOfTimeline,
|
12864 | endedTimelineFn: endedTimelineFn,
|
12865 | dataFn: dataFn
|
12866 | });
|
12867 | }
|
12868 | }
|
12869 |
|
12870 | segment.stats = videojs__default['default'].mergeOptions(segment.stats, getProgressStats(event));
|
12871 |
|
12872 | if (!segment.stats.firstBytesReceivedAt && segment.stats.bytesReceived) {
|
12873 | segment.stats.firstBytesReceivedAt = Date.now();
|
12874 | }
|
12875 |
|
12876 | return progressFn(event, segment);
|
12877 | };
|
12878 | };
|
12879 |
|
12880 |
|
12881 |
|
12882 |
|
12883 |
|
12884 |
|
12885 |
|
12886 |
|
12887 |
|
12888 |
|
12889 |
|
12890 |
|
12891 |
|
12892 |
|
12893 |
|
12894 |
|
12895 |
|
12896 |
|
12897 |
|
12898 |
|
12899 |
|
12900 |
|
12901 |
|
12902 |
|
12903 |
|
12904 |
|
12905 |
|
12906 |
|
12907 |
|
12908 |
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 |
|
12921 |
|
12922 |
|
12923 |
|
12924 |
|
12925 |
|
12926 |
|
12927 |
|
12928 |
|
12929 |
|
12930 |
|
12931 |
|
12932 |
|
12933 |
|
12934 |
|
12935 |
|
12936 |
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 |
|
12944 |
|
12945 |
|
12946 |
|
12947 |
|
12948 |
|
12949 | var mediaSegmentRequest = function mediaSegmentRequest(_ref9) {
|
12950 | var xhr = _ref9.xhr,
|
12951 | xhrOptions = _ref9.xhrOptions,
|
12952 | decryptionWorker = _ref9.decryptionWorker,
|
12953 | segment = _ref9.segment,
|
12954 | abortFn = _ref9.abortFn,
|
12955 | progressFn = _ref9.progressFn,
|
12956 | trackInfoFn = _ref9.trackInfoFn,
|
12957 | timingInfoFn = _ref9.timingInfoFn,
|
12958 | videoSegmentTimingInfoFn = _ref9.videoSegmentTimingInfoFn,
|
12959 | audioSegmentTimingInfoFn = _ref9.audioSegmentTimingInfoFn,
|
12960 | id3Fn = _ref9.id3Fn,
|
12961 | captionsFn = _ref9.captionsFn,
|
12962 | isEndOfTimeline = _ref9.isEndOfTimeline,
|
12963 | endedTimelineFn = _ref9.endedTimelineFn,
|
12964 | dataFn = _ref9.dataFn,
|
12965 | doneFn = _ref9.doneFn,
|
12966 | handlePartialData = _ref9.handlePartialData;
|
12967 | var activeXhrs = [];
|
12968 | var finishProcessingFn = waitForCompletion({
|
12969 | activeXhrs: activeXhrs,
|
12970 | decryptionWorker: decryptionWorker,
|
12971 | trackInfoFn: trackInfoFn,
|
12972 | timingInfoFn: timingInfoFn,
|
12973 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
12974 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
12975 | id3Fn: id3Fn,
|
12976 | captionsFn: captionsFn,
|
12977 | isEndOfTimeline: isEndOfTimeline,
|
12978 | endedTimelineFn: endedTimelineFn,
|
12979 | dataFn: dataFn,
|
12980 | doneFn: doneFn
|
12981 | });
|
12982 |
|
12983 | if (segment.key && !segment.key.bytes) {
|
12984 | var keyRequestOptions = videojs__default['default'].mergeOptions(xhrOptions, {
|
12985 | uri: segment.key.resolvedUri,
|
12986 | responseType: 'arraybuffer'
|
12987 | });
|
12988 | var keyRequestCallback = handleKeyResponse(segment, finishProcessingFn);
|
12989 | var keyXhr = xhr(keyRequestOptions, keyRequestCallback);
|
12990 | activeXhrs.push(keyXhr);
|
12991 | }
|
12992 |
|
12993 |
|
12994 | if (segment.map && !segment.map.bytes) {
|
12995 | var initSegmentOptions = videojs__default['default'].mergeOptions(xhrOptions, {
|
12996 | uri: segment.map.resolvedUri,
|
12997 | responseType: 'arraybuffer',
|
12998 | headers: segmentXhrHeaders(segment.map)
|
12999 | });
|
13000 | var initSegmentRequestCallback = handleInitSegmentResponse({
|
13001 | segment: segment,
|
13002 | finishProcessingFn: finishProcessingFn
|
13003 | });
|
13004 | var initSegmentXhr = xhr(initSegmentOptions, initSegmentRequestCallback);
|
13005 | activeXhrs.push(initSegmentXhr);
|
13006 | }
|
13007 |
|
13008 | var segmentRequestOptions = videojs__default['default'].mergeOptions(xhrOptions, {
|
13009 | uri: segment.part && segment.part.resolvedUri || segment.resolvedUri,
|
13010 | responseType: 'arraybuffer',
|
13011 | headers: segmentXhrHeaders(segment)
|
13012 | });
|
13013 |
|
13014 | if (handlePartialData) {
|
13015 |
|
13016 |
|
13017 | segmentRequestOptions.responseType = 'text';
|
13018 |
|
13019 | segmentRequestOptions.beforeSend = function (xhrObject) {
|
13020 |
|
13021 |
|
13022 | xhrObject.overrideMimeType('text/plain; charset=x-user-defined');
|
13023 | };
|
13024 | }
|
13025 |
|
13026 | var segmentRequestCallback = handleSegmentResponse({
|
13027 | segment: segment,
|
13028 | finishProcessingFn: finishProcessingFn,
|
13029 | responseType: segmentRequestOptions.responseType
|
13030 | });
|
13031 | var segmentXhr = xhr(segmentRequestOptions, segmentRequestCallback);
|
13032 | segmentXhr.addEventListener('progress', handleProgress({
|
13033 | segment: segment,
|
13034 | progressFn: progressFn,
|
13035 | trackInfoFn: trackInfoFn,
|
13036 | timingInfoFn: timingInfoFn,
|
13037 | videoSegmentTimingInfoFn: videoSegmentTimingInfoFn,
|
13038 | audioSegmentTimingInfoFn: audioSegmentTimingInfoFn,
|
13039 | id3Fn: id3Fn,
|
13040 | captionsFn: captionsFn,
|
13041 | isEndOfTimeline: isEndOfTimeline,
|
13042 | endedTimelineFn: endedTimelineFn,
|
13043 | dataFn: dataFn,
|
13044 | handlePartialData: handlePartialData
|
13045 | }));
|
13046 | activeXhrs.push(segmentXhr);
|
13047 |
|
13048 |
|
13049 | var loadendState = {};
|
13050 | activeXhrs.forEach(function (activeXhr) {
|
13051 | activeXhr.addEventListener('loadend', handleLoadEnd({
|
13052 | loadendState: loadendState,
|
13053 | abortFn: abortFn
|
13054 | }));
|
13055 | });
|
13056 | return function () {
|
13057 | return abortAll(activeXhrs);
|
13058 | };
|
13059 | };
|
13060 |
|
13061 |
|
13062 |
|
13063 |
|
13064 |
|
13065 | var logFn$1 = logger('CodecUtils');
|
13066 |
|
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 |
|
13073 |
|
13074 | var getCodecs = function getCodecs(media) {
|
13075 |
|
13076 |
|
13077 | var mediaAttributes = media.attributes || {};
|
13078 |
|
13079 | if (mediaAttributes.CODECS) {
|
13080 | return codecs_js.parseCodecs(mediaAttributes.CODECS);
|
13081 | }
|
13082 | };
|
13083 |
|
13084 | var isMaat = function isMaat(master, media) {
|
13085 | var mediaAttributes = media.attributes || {};
|
13086 | return master && master.mediaGroups && master.mediaGroups.AUDIO && mediaAttributes.AUDIO && master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
13087 | };
|
13088 | var isMuxed = function isMuxed(master, media) {
|
13089 | if (!isMaat(master, media)) {
|
13090 | return true;
|
13091 | }
|
13092 |
|
13093 | var mediaAttributes = media.attributes || {};
|
13094 | var audioGroup = master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
13095 |
|
13096 | for (var groupId in audioGroup) {
|
13097 |
|
13098 |
|
13099 |
|
13100 |
|
13101 | if (!audioGroup[groupId].uri && !audioGroup[groupId].playlists) {
|
13102 | return true;
|
13103 | }
|
13104 | }
|
13105 |
|
13106 | return false;
|
13107 | };
|
13108 | var unwrapCodecList = function unwrapCodecList(codecList) {
|
13109 | var codecs = {};
|
13110 | codecList.forEach(function (_ref) {
|
13111 | var mediaType = _ref.mediaType,
|
13112 | type = _ref.type,
|
13113 | details = _ref.details;
|
13114 | codecs[mediaType] = codecs[mediaType] || [];
|
13115 | codecs[mediaType].push(codecs_js.translateLegacyCodec("" + type + details));
|
13116 | });
|
13117 | Object.keys(codecs).forEach(function (mediaType) {
|
13118 | if (codecs[mediaType].length > 1) {
|
13119 | 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.");
|
13120 | codecs[mediaType] = null;
|
13121 | return;
|
13122 | }
|
13123 |
|
13124 | codecs[mediaType] = codecs[mediaType][0];
|
13125 | });
|
13126 | return codecs;
|
13127 | };
|
13128 | var codecCount = function codecCount(codecObj) {
|
13129 | var count = 0;
|
13130 |
|
13131 | if (codecObj.audio) {
|
13132 | count++;
|
13133 | }
|
13134 |
|
13135 | if (codecObj.video) {
|
13136 | count++;
|
13137 | }
|
13138 |
|
13139 | return count;
|
13140 | };
|
13141 |
|
13142 |
|
13143 |
|
13144 |
|
13145 |
|
13146 |
|
13147 |
|
13148 |
|
13149 |
|
13150 |
|
13151 |
|
13152 |
|
13153 |
|
13154 | var codecsForPlaylist = function codecsForPlaylist(master, media) {
|
13155 | var mediaAttributes = media.attributes || {};
|
13156 | var codecInfo = unwrapCodecList(getCodecs(media) || []);
|
13157 |
|
13158 |
|
13159 | if (isMaat(master, media) && !codecInfo.audio) {
|
13160 | if (!isMuxed(master, media)) {
|
13161 |
|
13162 |
|
13163 |
|
13164 | var defaultCodecs = unwrapCodecList(codecs_js.codecsFromDefault(master, mediaAttributes.AUDIO) || []);
|
13165 |
|
13166 | if (defaultCodecs.audio) {
|
13167 | codecInfo.audio = defaultCodecs.audio;
|
13168 | }
|
13169 | }
|
13170 | }
|
13171 |
|
13172 | return codecInfo;
|
13173 | };
|
13174 |
|
13175 | var logFn = logger('PlaylistSelector');
|
13176 |
|
13177 | var representationToString = function representationToString(representation) {
|
13178 | if (!representation || !representation.playlist) {
|
13179 | return;
|
13180 | }
|
13181 |
|
13182 | var playlist = representation.playlist;
|
13183 | return JSON.stringify({
|
13184 | id: playlist.id,
|
13185 | bandwidth: representation.bandwidth,
|
13186 | width: representation.width,
|
13187 | height: representation.height,
|
13188 | codecs: playlist.attributes && playlist.attributes.CODECS || ''
|
13189 | });
|
13190 | };
|
13191 |
|
13192 |
|
13193 |
|
13194 |
|
13195 |
|
13196 |
|
13197 |
|
13198 |
|
13199 |
|
13200 |
|
13201 |
|
13202 |
|
13203 |
|
13204 | var safeGetComputedStyle = function safeGetComputedStyle(el, property) {
|
13205 | if (!el) {
|
13206 | return '';
|
13207 | }
|
13208 |
|
13209 | var result = window__default['default'].getComputedStyle(el);
|
13210 |
|
13211 | if (!result) {
|
13212 | return '';
|
13213 | }
|
13214 |
|
13215 | return result[property];
|
13216 | };
|
13217 |
|
13218 |
|
13219 |
|
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 |
|
13225 |
|
13226 | var stableSort = function stableSort(array, sortFn) {
|
13227 | var newArray = array.slice();
|
13228 | array.sort(function (left, right) {
|
13229 | var cmp = sortFn(left, right);
|
13230 |
|
13231 | if (cmp === 0) {
|
13232 | return newArray.indexOf(left) - newArray.indexOf(right);
|
13233 | }
|
13234 |
|
13235 | return cmp;
|
13236 | });
|
13237 | };
|
13238 |
|
13239 |
|
13240 |
|
13241 |
|
13242 |
|
13243 |
|
13244 |
|
13245 |
|
13246 |
|
13247 |
|
13248 |
|
13249 |
|
13250 | var comparePlaylistBandwidth = function comparePlaylistBandwidth(left, right) {
|
13251 | var leftBandwidth;
|
13252 | var rightBandwidth;
|
13253 |
|
13254 | if (left.attributes.BANDWIDTH) {
|
13255 | leftBandwidth = left.attributes.BANDWIDTH;
|
13256 | }
|
13257 |
|
13258 | leftBandwidth = leftBandwidth || window__default['default'].Number.MAX_VALUE;
|
13259 |
|
13260 | if (right.attributes.BANDWIDTH) {
|
13261 | rightBandwidth = right.attributes.BANDWIDTH;
|
13262 | }
|
13263 |
|
13264 | rightBandwidth = rightBandwidth || window__default['default'].Number.MAX_VALUE;
|
13265 | return leftBandwidth - rightBandwidth;
|
13266 | };
|
13267 |
|
13268 |
|
13269 |
|
13270 |
|
13271 |
|
13272 |
|
13273 |
|
13274 |
|
13275 |
|
13276 |
|
13277 |
|
13278 | var comparePlaylistResolution = function comparePlaylistResolution(left, right) {
|
13279 | var leftWidth;
|
13280 | var rightWidth;
|
13281 |
|
13282 | if (left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
|
13283 | leftWidth = left.attributes.RESOLUTION.width;
|
13284 | }
|
13285 |
|
13286 | leftWidth = leftWidth || window__default['default'].Number.MAX_VALUE;
|
13287 |
|
13288 | if (right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
|
13289 | rightWidth = right.attributes.RESOLUTION.width;
|
13290 | }
|
13291 |
|
13292 | rightWidth = rightWidth || window__default['default'].Number.MAX_VALUE;
|
13293 |
|
13294 |
|
13295 | if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
|
13296 | return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
|
13297 | }
|
13298 |
|
13299 | return leftWidth - rightWidth;
|
13300 | };
|
13301 |
|
13302 |
|
13303 |
|
13304 |
|
13305 |
|
13306 |
|
13307 |
|
13308 |
|
13309 |
|
13310 |
|
13311 |
|
13312 |
|
13313 |
|
13314 |
|
13315 |
|
13316 |
|
13317 |
|
13318 |
|
13319 |
|
13320 |
|
13321 | var simpleSelector = function simpleSelector(master, playerBandwidth, playerWidth, playerHeight, limitRenditionByPlayerDimensions, masterPlaylistController) {
|
13322 |
|
13323 | if (!master) {
|
13324 | return;
|
13325 | }
|
13326 |
|
13327 | var options = {
|
13328 | bandwidth: playerBandwidth,
|
13329 | width: playerWidth,
|
13330 | height: playerHeight,
|
13331 | limitRenditionByPlayerDimensions: limitRenditionByPlayerDimensions
|
13332 | };
|
13333 | var playlists = master.playlists;
|
13334 |
|
13335 | if (Playlist.isAudioOnly(master)) {
|
13336 | playlists = masterPlaylistController.getAudioTrackPlaylists_();
|
13337 |
|
13338 |
|
13339 | options.audioOnly = true;
|
13340 | }
|
13341 |
|
13342 |
|
13343 | var sortedPlaylistReps = playlists.map(function (playlist) {
|
13344 | var bandwidth;
|
13345 | var width = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width;
|
13346 | var height = playlist.attributes && playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.height;
|
13347 | bandwidth = playlist.attributes && playlist.attributes.BANDWIDTH;
|
13348 | bandwidth = bandwidth || window__default['default'].Number.MAX_VALUE;
|
13349 | return {
|
13350 | bandwidth: bandwidth,
|
13351 | width: width,
|
13352 | height: height,
|
13353 | playlist: playlist
|
13354 | };
|
13355 | });
|
13356 | stableSort(sortedPlaylistReps, function (left, right) {
|
13357 | return left.bandwidth - right.bandwidth;
|
13358 | });
|
13359 |
|
13360 |
|
13361 | sortedPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
13362 | return !Playlist.isIncompatible(rep.playlist);
|
13363 | });
|
13364 |
|
13365 |
|
13366 | var enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
13367 | return Playlist.isEnabled(rep.playlist);
|
13368 | });
|
13369 |
|
13370 | if (!enabledPlaylistReps.length) {
|
13371 |
|
13372 |
|
13373 |
|
13374 | enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
13375 | return !Playlist.isDisabled(rep.playlist);
|
13376 | });
|
13377 | }
|
13378 |
|
13379 |
|
13380 |
|
13381 | var bandwidthPlaylistReps = enabledPlaylistReps.filter(function (rep) {
|
13382 | return rep.bandwidth * Config.BANDWIDTH_VARIANCE < playerBandwidth;
|
13383 | });
|
13384 | var highestRemainingBandwidthRep = bandwidthPlaylistReps[bandwidthPlaylistReps.length - 1];
|
13385 |
|
13386 |
|
13387 | var bandwidthBestRep = bandwidthPlaylistReps.filter(function (rep) {
|
13388 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
13389 | })[0];
|
13390 |
|
13391 | if (limitRenditionByPlayerDimensions === false) {
|
13392 | var _chosenRep = bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
13393 |
|
13394 | if (_chosenRep && _chosenRep.playlist) {
|
13395 | var type = 'sortedPlaylistReps';
|
13396 |
|
13397 | if (bandwidthBestRep) {
|
13398 | type = 'bandwidthBestRep';
|
13399 | }
|
13400 |
|
13401 | if (enabledPlaylistReps[0]) {
|
13402 | type = 'enabledPlaylistReps';
|
13403 | }
|
13404 |
|
13405 | logFn("choosing " + representationToString(_chosenRep) + " using " + type + " with options", options);
|
13406 | return _chosenRep.playlist;
|
13407 | }
|
13408 |
|
13409 | logFn('could not choose a playlist with options', options);
|
13410 | return null;
|
13411 | }
|
13412 |
|
13413 |
|
13414 | var haveResolution = bandwidthPlaylistReps.filter(function (rep) {
|
13415 | return rep.width && rep.height;
|
13416 | });
|
13417 |
|
13418 | stableSort(haveResolution, function (left, right) {
|
13419 | return left.width - right.width;
|
13420 | });
|
13421 |
|
13422 | var resolutionBestRepList = haveResolution.filter(function (rep) {
|
13423 | return rep.width === playerWidth && rep.height === playerHeight;
|
13424 | });
|
13425 | highestRemainingBandwidthRep = resolutionBestRepList[resolutionBestRepList.length - 1];
|
13426 |
|
13427 | var resolutionBestRep = resolutionBestRepList.filter(function (rep) {
|
13428 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
13429 | })[0];
|
13430 | var resolutionPlusOneList;
|
13431 | var resolutionPlusOneSmallest;
|
13432 | var resolutionPlusOneRep;
|
13433 |
|
13434 |
|
13435 | if (!resolutionBestRep) {
|
13436 | resolutionPlusOneList = haveResolution.filter(function (rep) {
|
13437 | return rep.width > playerWidth || rep.height > playerHeight;
|
13438 | });
|
13439 |
|
13440 | resolutionPlusOneSmallest = resolutionPlusOneList.filter(function (rep) {
|
13441 | return rep.width === resolutionPlusOneList[0].width && rep.height === resolutionPlusOneList[0].height;
|
13442 | });
|
13443 |
|
13444 |
|
13445 | highestRemainingBandwidthRep = resolutionPlusOneSmallest[resolutionPlusOneSmallest.length - 1];
|
13446 | resolutionPlusOneRep = resolutionPlusOneSmallest.filter(function (rep) {
|
13447 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
13448 | })[0];
|
13449 | }
|
13450 |
|
13451 |
|
13452 | var chosenRep = resolutionPlusOneRep || resolutionBestRep || bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
13453 |
|
13454 | if (chosenRep && chosenRep.playlist) {
|
13455 | var _type = 'sortedPlaylistReps';
|
13456 |
|
13457 | if (resolutionPlusOneRep) {
|
13458 | _type = 'resolutionPlusOneRep';
|
13459 | } else if (resolutionBestRep) {
|
13460 | _type = 'resolutionBestRep';
|
13461 | } else if (bandwidthBestRep) {
|
13462 | _type = 'bandwidthBestRep';
|
13463 | } else if (enabledPlaylistReps[0]) {
|
13464 | _type = 'enabledPlaylistReps';
|
13465 | }
|
13466 |
|
13467 | logFn("choosing " + representationToString(chosenRep) + " using " + _type + " with options", options);
|
13468 | return chosenRep.playlist;
|
13469 | }
|
13470 |
|
13471 | logFn('could not choose a playlist with options', options);
|
13472 | return null;
|
13473 | };
|
13474 |
|
13475 |
|
13476 |
|
13477 |
|
13478 |
|
13479 |
|
13480 |
|
13481 |
|
13482 |
|
13483 |
|
13484 |
|
13485 |
|
13486 | var lastBandwidthSelector = function lastBandwidthSelector() {
|
13487 | var pixelRatio = this.useDevicePixelRatio ? window__default['default'].devicePixelRatio || 1 : 1;
|
13488 | 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_);
|
13489 | };
|
13490 |
|
13491 |
|
13492 |
|
13493 |
|
13494 |
|
13495 |
|
13496 |
|
13497 |
|
13498 |
|
13499 |
|
13500 |
|
13501 |
|
13502 |
|
13503 |
|
13504 |
|
13505 | var movingAverageBandwidthSelector = function movingAverageBandwidthSelector(decay) {
|
13506 | var average = -1;
|
13507 |
|
13508 | if (decay < 0 || decay > 1) {
|
13509 | throw new Error('Moving average bandwidth decay must be between 0 and 1.');
|
13510 | }
|
13511 |
|
13512 | return function () {
|
13513 | var pixelRatio = this.useDevicePixelRatio ? window__default['default'].devicePixelRatio || 1 : 1;
|
13514 |
|
13515 | if (average < 0) {
|
13516 | average = this.systemBandwidth;
|
13517 | }
|
13518 |
|
13519 | average = decay * this.systemBandwidth + (1 - decay) * average;
|
13520 | 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_);
|
13521 | };
|
13522 | };
|
13523 |
|
13524 |
|
13525 |
|
13526 |
|
13527 |
|
13528 |
|
13529 |
|
13530 |
|
13531 |
|
13532 |
|
13533 |
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 |
|
13539 |
|
13540 |
|
13541 |
|
13542 |
|
13543 |
|
13544 |
|
13545 |
|
13546 |
|
13547 |
|
13548 |
|
13549 |
|
13550 |
|
13551 |
|
13552 | var minRebufferMaxBandwidthSelector = function minRebufferMaxBandwidthSelector(settings) {
|
13553 | var master = settings.master,
|
13554 | currentTime = settings.currentTime,
|
13555 | bandwidth = settings.bandwidth,
|
13556 | duration = settings.duration,
|
13557 | segmentDuration = settings.segmentDuration,
|
13558 | timeUntilRebuffer = settings.timeUntilRebuffer,
|
13559 | currentTimeline = settings.currentTimeline,
|
13560 | syncController = settings.syncController;
|
13561 |
|
13562 |
|
13563 | var compatiblePlaylists = master.playlists.filter(function (playlist) {
|
13564 | return !Playlist.isIncompatible(playlist);
|
13565 | });
|
13566 |
|
13567 |
|
13568 | var enabledPlaylists = compatiblePlaylists.filter(Playlist.isEnabled);
|
13569 |
|
13570 | if (!enabledPlaylists.length) {
|
13571 |
|
13572 |
|
13573 |
|
13574 | enabledPlaylists = compatiblePlaylists.filter(function (playlist) {
|
13575 | return !Playlist.isDisabled(playlist);
|
13576 | });
|
13577 | }
|
13578 |
|
13579 | var bandwidthPlaylists = enabledPlaylists.filter(Playlist.hasAttribute.bind(null, 'BANDWIDTH'));
|
13580 | var rebufferingEstimates = bandwidthPlaylists.map(function (playlist) {
|
13581 | var syncPoint = syncController.getSyncPoint(playlist, duration, currentTimeline, currentTime);
|
13582 |
|
13583 |
|
13584 | var numRequests = syncPoint ? 1 : 2;
|
13585 | var requestTimeEstimate = Playlist.estimateSegmentRequestTime(segmentDuration, bandwidth, playlist);
|
13586 | var rebufferingImpact = requestTimeEstimate * numRequests - timeUntilRebuffer;
|
13587 | return {
|
13588 | playlist: playlist,
|
13589 | rebufferingImpact: rebufferingImpact
|
13590 | };
|
13591 | });
|
13592 | var noRebufferingPlaylists = rebufferingEstimates.filter(function (estimate) {
|
13593 | return estimate.rebufferingImpact <= 0;
|
13594 | });
|
13595 |
|
13596 | stableSort(noRebufferingPlaylists, function (a, b) {
|
13597 | return comparePlaylistBandwidth(b.playlist, a.playlist);
|
13598 | });
|
13599 |
|
13600 | if (noRebufferingPlaylists.length) {
|
13601 | return noRebufferingPlaylists[0];
|
13602 | }
|
13603 |
|
13604 | stableSort(rebufferingEstimates, function (a, b) {
|
13605 | return a.rebufferingImpact - b.rebufferingImpact;
|
13606 | });
|
13607 | return rebufferingEstimates[0] || null;
|
13608 | };
|
13609 |
|
13610 |
|
13611 |
|
13612 |
|
13613 |
|
13614 |
|
13615 |
|
13616 |
|
13617 |
|
13618 |
|
13619 |
|
13620 |
|
13621 | var lowestBitrateCompatibleVariantSelector = function lowestBitrateCompatibleVariantSelector() {
|
13622 | var _this = this;
|
13623 |
|
13624 |
|
13625 |
|
13626 | var playlists = this.playlists.master.playlists.filter(Playlist.isEnabled);
|
13627 |
|
13628 | stableSort(playlists, function (a, b) {
|
13629 | return comparePlaylistBandwidth(a, b);
|
13630 | });
|
13631 |
|
13632 |
|
13633 |
|
13634 |
|
13635 |
|
13636 | var playlistsWithVideo = playlists.filter(function (playlist) {
|
13637 | return !!codecsForPlaylist(_this.playlists.master, playlist).video;
|
13638 | });
|
13639 | return playlistsWithVideo[0] || null;
|
13640 | };
|
13641 |
|
13642 |
|
13643 |
|
13644 |
|
13645 |
|
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 |
|
13651 |
|
13652 |
|
13653 |
|
13654 | var createCaptionsTrackIfNotExists = function createCaptionsTrackIfNotExists(inbandTextTracks, tech, captionStream) {
|
13655 | if (!inbandTextTracks[captionStream]) {
|
13656 | tech.trigger({
|
13657 | type: 'usage',
|
13658 | name: 'vhs-608'
|
13659 | });
|
13660 | tech.trigger({
|
13661 | type: 'usage',
|
13662 | name: 'hls-608'
|
13663 | });
|
13664 | var track = tech.textTracks().getTrackById(captionStream);
|
13665 |
|
13666 | if (track) {
|
13667 |
|
13668 |
|
13669 |
|
13670 | inbandTextTracks[captionStream] = track;
|
13671 | } else {
|
13672 |
|
13673 |
|
13674 | inbandTextTracks[captionStream] = tech.addRemoteTextTrack({
|
13675 | kind: 'captions',
|
13676 | id: captionStream,
|
13677 | label: captionStream
|
13678 | }, false).track;
|
13679 | }
|
13680 | }
|
13681 | };
|
13682 |
|
13683 |
|
13684 |
|
13685 |
|
13686 |
|
13687 |
|
13688 |
|
13689 |
|
13690 |
|
13691 |
|
13692 | var addCaptionData = function addCaptionData(_ref) {
|
13693 | var inbandTextTracks = _ref.inbandTextTracks,
|
13694 | captionArray = _ref.captionArray,
|
13695 | timestampOffset = _ref.timestampOffset;
|
13696 |
|
13697 | if (!captionArray) {
|
13698 | return;
|
13699 | }
|
13700 |
|
13701 | var Cue = window__default['default'].WebKitDataCue || window__default['default'].VTTCue;
|
13702 | captionArray.forEach(function (caption) {
|
13703 | var track = caption.stream;
|
13704 | inbandTextTracks[track].addCue(new Cue(caption.startTime + timestampOffset, caption.endTime + timestampOffset, caption.text));
|
13705 | });
|
13706 | };
|
13707 |
|
13708 |
|
13709 |
|
13710 |
|
13711 |
|
13712 |
|
13713 |
|
13714 |
|
13715 |
|
13716 | var deprecateOldCue = function deprecateOldCue(cue) {
|
13717 | Object.defineProperties(cue.frame, {
|
13718 | id: {
|
13719 | get: function get() {
|
13720 | videojs__default['default'].log.warn('cue.frame.id is deprecated. Use cue.value.key instead.');
|
13721 | return cue.value.key;
|
13722 | }
|
13723 | },
|
13724 | value: {
|
13725 | get: function get() {
|
13726 | videojs__default['default'].log.warn('cue.frame.value is deprecated. Use cue.value.data instead.');
|
13727 | return cue.value.data;
|
13728 | }
|
13729 | },
|
13730 | privateData: {
|
13731 | get: function get() {
|
13732 | videojs__default['default'].log.warn('cue.frame.privateData is deprecated. Use cue.value.data instead.');
|
13733 | return cue.value.data;
|
13734 | }
|
13735 | }
|
13736 | });
|
13737 | };
|
13738 |
|
13739 |
|
13740 |
|
13741 |
|
13742 |
|
13743 |
|
13744 |
|
13745 |
|
13746 |
|
13747 |
|
13748 |
|
13749 |
|
13750 | var addMetadata = function addMetadata(_ref2) {
|
13751 | var inbandTextTracks = _ref2.inbandTextTracks,
|
13752 | metadataArray = _ref2.metadataArray,
|
13753 | timestampOffset = _ref2.timestampOffset,
|
13754 | videoDuration = _ref2.videoDuration;
|
13755 |
|
13756 | if (!metadataArray) {
|
13757 | return;
|
13758 | }
|
13759 |
|
13760 | var Cue = window__default['default'].WebKitDataCue || window__default['default'].VTTCue;
|
13761 | var metadataTrack = inbandTextTracks.metadataTrack_;
|
13762 |
|
13763 | if (!metadataTrack) {
|
13764 | return;
|
13765 | }
|
13766 |
|
13767 | metadataArray.forEach(function (metadata) {
|
13768 | var time = metadata.cueTime + timestampOffset;
|
13769 |
|
13770 |
|
13771 |
|
13772 |
|
13773 | if (typeof time !== 'number' || window__default['default'].isNaN(time) || time < 0 || !(time < Infinity)) {
|
13774 | return;
|
13775 | }
|
13776 |
|
13777 | metadata.frames.forEach(function (frame) {
|
13778 | var cue = new Cue(time, time, frame.value || frame.url || frame.data || '');
|
13779 | cue.frame = frame;
|
13780 | cue.value = frame;
|
13781 | deprecateOldCue(cue);
|
13782 | metadataTrack.addCue(cue);
|
13783 | });
|
13784 | });
|
13785 |
|
13786 | if (!metadataTrack.cues || !metadataTrack.cues.length) {
|
13787 | return;
|
13788 | }
|
13789 |
|
13790 |
|
13791 |
|
13792 |
|
13793 | var cues = metadataTrack.cues;
|
13794 | var cuesArray = [];
|
13795 |
|
13796 |
|
13797 | for (var i = 0; i < cues.length; i++) {
|
13798 | if (cues[i]) {
|
13799 | cuesArray.push(cues[i]);
|
13800 | }
|
13801 | }
|
13802 |
|
13803 |
|
13804 | var cuesGroupedByStartTime = cuesArray.reduce(function (obj, cue) {
|
13805 | var timeSlot = obj[cue.startTime] || [];
|
13806 | timeSlot.push(cue);
|
13807 | obj[cue.startTime] = timeSlot;
|
13808 | return obj;
|
13809 | }, {});
|
13810 |
|
13811 | var sortedStartTimes = Object.keys(cuesGroupedByStartTime).sort(function (a, b) {
|
13812 | return Number(a) - Number(b);
|
13813 | });
|
13814 |
|
13815 | sortedStartTimes.forEach(function (startTime, idx) {
|
13816 | var cueGroup = cuesGroupedByStartTime[startTime];
|
13817 | var nextTime = Number(sortedStartTimes[idx + 1]) || videoDuration;
|
13818 |
|
13819 | cueGroup.forEach(function (cue) {
|
13820 | cue.endTime = nextTime;
|
13821 | });
|
13822 | });
|
13823 | };
|
13824 |
|
13825 |
|
13826 |
|
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 |
|
13832 |
|
13833 | var createMetadataTrackIfNotExists = function createMetadataTrackIfNotExists(inbandTextTracks, dispatchType, tech) {
|
13834 | if (inbandTextTracks.metadataTrack_) {
|
13835 | return;
|
13836 | }
|
13837 |
|
13838 | inbandTextTracks.metadataTrack_ = tech.addRemoteTextTrack({
|
13839 | kind: 'metadata',
|
13840 | label: 'Timed Metadata'
|
13841 | }, false).track;
|
13842 | inbandTextTracks.metadataTrack_.inBandMetadataTrackDispatchType = dispatchType;
|
13843 | };
|
13844 |
|
13845 |
|
13846 |
|
13847 |
|
13848 |
|
13849 |
|
13850 |
|
13851 |
|
13852 |
|
13853 | var removeCuesFromTrack = function removeCuesFromTrack(start, end, track) {
|
13854 | var i;
|
13855 | var cue;
|
13856 |
|
13857 | if (!track) {
|
13858 | return;
|
13859 | }
|
13860 |
|
13861 | if (!track.cues) {
|
13862 | return;
|
13863 | }
|
13864 |
|
13865 | i = track.cues.length;
|
13866 |
|
13867 | while (i--) {
|
13868 | cue = track.cues[i];
|
13869 |
|
13870 | if (cue.startTime >= start && cue.endTime <= end) {
|
13871 | track.removeCue(cue);
|
13872 | }
|
13873 | }
|
13874 | };
|
13875 |
|
13876 |
|
13877 |
|
13878 |
|
13879 |
|
13880 |
|
13881 |
|
13882 |
|
13883 | var removeDuplicateCuesFromTrack = function removeDuplicateCuesFromTrack(track) {
|
13884 | var cues = track.cues;
|
13885 |
|
13886 | if (!cues) {
|
13887 | return;
|
13888 | }
|
13889 |
|
13890 | for (var i = 0; i < cues.length; i++) {
|
13891 | var duplicates = [];
|
13892 | var occurrences = 0;
|
13893 |
|
13894 | for (var j = 0; j < cues.length; j++) {
|
13895 | if (cues[i].startTime === cues[j].startTime && cues[i].endTime === cues[j].endTime && cues[i].text === cues[j].text) {
|
13896 | occurrences++;
|
13897 |
|
13898 | if (occurrences > 1) {
|
13899 | duplicates.push(cues[j]);
|
13900 | }
|
13901 | }
|
13902 | }
|
13903 |
|
13904 | if (duplicates.length) {
|
13905 | duplicates.forEach(function (dupe) {
|
13906 | return track.removeCue(dupe);
|
13907 | });
|
13908 | }
|
13909 | }
|
13910 | };
|
13911 |
|
13912 |
|
13913 |
|
13914 |
|
13915 |
|
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 |
|
13921 |
|
13922 |
|
13923 |
|
13924 |
|
13925 |
|
13926 | var gopsSafeToAlignWith = function gopsSafeToAlignWith(buffer, currentTime, mapping) {
|
13927 | if (typeof currentTime === 'undefined' || currentTime === null || !buffer.length) {
|
13928 | return [];
|
13929 | }
|
13930 |
|
13931 |
|
13932 | var currentTimePts = Math.ceil((currentTime - mapping + 3) * clock.ONE_SECOND_IN_TS);
|
13933 | var i;
|
13934 |
|
13935 | for (i = 0; i < buffer.length; i++) {
|
13936 | if (buffer[i].pts > currentTimePts) {
|
13937 | break;
|
13938 | }
|
13939 | }
|
13940 |
|
13941 | return buffer.slice(i);
|
13942 | };
|
13943 |
|
13944 |
|
13945 |
|
13946 |
|
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 |
|
13952 |
|
13953 |
|
13954 |
|
13955 |
|
13956 |
|
13957 |
|
13958 | var updateGopBuffer = function updateGopBuffer(buffer, gops, replace) {
|
13959 | if (!gops.length) {
|
13960 | return buffer;
|
13961 | }
|
13962 |
|
13963 | if (replace) {
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 | return gops.slice();
|
13969 | }
|
13970 |
|
13971 | var start = gops[0].pts;
|
13972 | var i = 0;
|
13973 |
|
13974 | for (i; i < buffer.length; i++) {
|
13975 | if (buffer[i].pts >= start) {
|
13976 | break;
|
13977 | }
|
13978 | }
|
13979 |
|
13980 | return buffer.slice(0, i).concat(gops);
|
13981 | };
|
13982 |
|
13983 |
|
13984 |
|
13985 |
|
13986 |
|
13987 |
|
13988 |
|
13989 |
|
13990 |
|
13991 |
|
13992 |
|
13993 |
|
13994 |
|
13995 | var removeGopBuffer = function removeGopBuffer(buffer, start, end, mapping) {
|
13996 | var startPts = Math.ceil((start - mapping) * clock.ONE_SECOND_IN_TS);
|
13997 | var endPts = Math.ceil((end - mapping) * clock.ONE_SECOND_IN_TS);
|
13998 | var updatedBuffer = buffer.slice();
|
13999 | var i = buffer.length;
|
14000 |
|
14001 | while (i--) {
|
14002 | if (buffer[i].pts <= endPts) {
|
14003 | break;
|
14004 | }
|
14005 | }
|
14006 |
|
14007 | if (i === -1) {
|
14008 |
|
14009 | return updatedBuffer;
|
14010 | }
|
14011 |
|
14012 | var j = i + 1;
|
14013 |
|
14014 | while (j--) {
|
14015 | if (buffer[j].pts <= startPts) {
|
14016 | break;
|
14017 | }
|
14018 | }
|
14019 |
|
14020 |
|
14021 | j = Math.max(j, 0);
|
14022 | updatedBuffer.splice(j, i - j + 1);
|
14023 | return updatedBuffer;
|
14024 | };
|
14025 |
|
14026 | var shallowEqual = function shallowEqual(a, b) {
|
14027 |
|
14028 |
|
14029 |
|
14030 | if (!a && !b || !a && b || a && !b) {
|
14031 | return false;
|
14032 | }
|
14033 |
|
14034 |
|
14035 | if (a === b) {
|
14036 | return true;
|
14037 | }
|
14038 |
|
14039 |
|
14040 |
|
14041 | var akeys = Object.keys(a).sort();
|
14042 | var bkeys = Object.keys(b).sort();
|
14043 |
|
14044 | if (akeys.length !== bkeys.length) {
|
14045 | return false;
|
14046 | }
|
14047 |
|
14048 | for (var i = 0; i < akeys.length; i++) {
|
14049 | var key = akeys[i];
|
14050 |
|
14051 | if (key !== bkeys[i]) {
|
14052 | return false;
|
14053 | }
|
14054 |
|
14055 |
|
14056 | if (a[key] !== b[key]) {
|
14057 | return false;
|
14058 | }
|
14059 | }
|
14060 |
|
14061 | return true;
|
14062 | };
|
14063 |
|
14064 |
|
14065 | var QUOTA_EXCEEDED_ERR = 22;
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 |
|
14071 | var MIN_BACK_BUFFER = 1;
|
14072 |
|
14073 | var CHECK_BUFFER_DELAY = 500;
|
14074 |
|
14075 | var finite = function finite(num) {
|
14076 | return typeof num === 'number' && isFinite(num);
|
14077 | };
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 | var MIN_SEGMENT_DURATION_TO_SAVE_STATS = 1 / 60;
|
14083 | var illegalMediaSwitch = function illegalMediaSwitch(loaderType, startingMedia, trackInfo) {
|
14084 |
|
14085 |
|
14086 | if (loaderType !== 'main' || !startingMedia || !trackInfo) {
|
14087 | return null;
|
14088 | }
|
14089 |
|
14090 | if (!trackInfo.hasAudio && !trackInfo.hasVideo) {
|
14091 | return 'Neither audio nor video found in segment.';
|
14092 | }
|
14093 |
|
14094 | if (startingMedia.hasVideo && !trackInfo.hasVideo) {
|
14095 | 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.';
|
14096 | }
|
14097 |
|
14098 | if (!startingMedia.hasVideo && trackInfo.hasVideo) {
|
14099 | 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.';
|
14100 | }
|
14101 |
|
14102 | return null;
|
14103 | };
|
14104 |
|
14105 |
|
14106 |
|
14107 |
|
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 | var safeBackBufferTrimTime = function safeBackBufferTrimTime(seekable, currentTime, targetDuration) {
|
14119 |
|
14120 |
|
14121 |
|
14122 |
|
14123 |
|
14124 | var trimTime = currentTime - Config.BACK_BUFFER_LENGTH;
|
14125 |
|
14126 | if (seekable.length) {
|
14127 |
|
14128 |
|
14129 | trimTime = Math.max(trimTime, seekable.start(0));
|
14130 | }
|
14131 |
|
14132 |
|
14133 |
|
14134 | var maxTrimTime = currentTime - targetDuration;
|
14135 | return Math.min(maxTrimTime, trimTime);
|
14136 | };
|
14137 |
|
14138 | var segmentInfoString = function segmentInfoString(segmentInfo) {
|
14139 | var _segmentInfo$segment = segmentInfo.segment,
|
14140 | start = _segmentInfo$segment.start,
|
14141 | end = _segmentInfo$segment.end,
|
14142 | parts = _segmentInfo$segment.parts,
|
14143 | _segmentInfo$playlist = segmentInfo.playlist,
|
14144 | seq = _segmentInfo$playlist.mediaSequence,
|
14145 | id = _segmentInfo$playlist.id,
|
14146 | _segmentInfo$playlist2 = _segmentInfo$playlist.segments,
|
14147 | segments = _segmentInfo$playlist2 === void 0 ? [] : _segmentInfo$playlist2,
|
14148 | index = segmentInfo.mediaIndex,
|
14149 | partIndex = segmentInfo.partIndex,
|
14150 | timeline = segmentInfo.timeline;
|
14151 | var name = segmentInfo.segment.uri ? 'segment' : 'pre-segment';
|
14152 | return [name + " [" + index + "/" + (segments.length - 1) + "]", partIndex ? "part [" + partIndex + "/" + (parts.length - 1) + "]" : '', "mediaSequenceNumber [" + seq + "/" + (seq + segments.length - 1) + "]", "playlist [" + id + "]", "start/end [" + start + " => " + end + "]", "timeline [" + timeline + "]"].join(' ');
|
14153 | };
|
14154 |
|
14155 | var timingInfoPropertyForMedia = function timingInfoPropertyForMedia(mediaType) {
|
14156 | return mediaType + "TimingInfo";
|
14157 | };
|
14158 |
|
14159 |
|
14160 |
|
14161 |
|
14162 |
|
14163 |
|
14164 |
|
14165 |
|
14166 |
|
14167 |
|
14168 |
|
14169 |
|
14170 |
|
14171 |
|
14172 |
|
14173 |
|
14174 |
|
14175 |
|
14176 |
|
14177 |
|
14178 |
|
14179 | var timestampOffsetForSegment = function timestampOffsetForSegment(_ref) {
|
14180 | var segmentTimeline = _ref.segmentTimeline,
|
14181 | currentTimeline = _ref.currentTimeline,
|
14182 | startOfSegment = _ref.startOfSegment,
|
14183 | buffered = _ref.buffered,
|
14184 | overrideCheck = _ref.overrideCheck;
|
14185 |
|
14186 |
|
14187 |
|
14188 |
|
14189 |
|
14190 |
|
14191 |
|
14192 | if (!overrideCheck && segmentTimeline === currentTimeline) {
|
14193 | return null;
|
14194 | }
|
14195 |
|
14196 |
|
14197 |
|
14198 |
|
14199 |
|
14200 |
|
14201 |
|
14202 |
|
14203 |
|
14204 |
|
14205 |
|
14206 |
|
14207 |
|
14208 |
|
14209 |
|
14210 |
|
14211 |
|
14212 |
|
14213 |
|
14214 |
|
14215 |
|
14216 |
|
14217 |
|
14218 |
|
14219 |
|
14220 | if (segmentTimeline < currentTimeline) {
|
14221 | return startOfSegment;
|
14222 | }
|
14223 |
|
14224 |
|
14225 |
|
14226 |
|
14227 |
|
14228 |
|
14229 | return buffered.length ? buffered.end(buffered.length - 1) : startOfSegment;
|
14230 | };
|
14231 |
|
14232 |
|
14233 |
|
14234 |
|
14235 |
|
14236 |
|
14237 |
|
14238 |
|
14239 |
|
14240 |
|
14241 |
|
14242 |
|
14243 |
|
14244 |
|
14245 |
|
14246 |
|
14247 |
|
14248 |
|
14249 |
|
14250 |
|
14251 |
|
14252 |
|
14253 |
|
14254 |
|
14255 |
|
14256 |
|
14257 |
|
14258 |
|
14259 |
|
14260 |
|
14261 |
|
14262 |
|
14263 |
|
14264 |
|
14265 |
|
14266 |
|
14267 |
|
14268 |
|
14269 |
|
14270 |
|
14271 |
|
14272 |
|
14273 |
|
14274 |
|
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 |
|
14280 |
|
14281 |
|
14282 |
|
14283 |
|
14284 |
|
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 |
|
14291 |
|
14292 |
|
14293 |
|
14294 |
|
14295 |
|
14296 |
|
14297 |
|
14298 |
|
14299 |
|
14300 |
|
14301 |
|
14302 |
|
14303 |
|
14304 |
|
14305 |
|
14306 |
|
14307 |
|
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 |
|
14314 |
|
14315 |
|
14316 |
|
14317 |
|
14318 |
|
14319 |
|
14320 |
|
14321 |
|
14322 |
|
14323 |
|
14324 |
|
14325 |
|
14326 |
|
14327 | var shouldWaitForTimelineChange = function shouldWaitForTimelineChange(_ref2) {
|
14328 | var timelineChangeController = _ref2.timelineChangeController,
|
14329 | currentTimeline = _ref2.currentTimeline,
|
14330 | segmentTimeline = _ref2.segmentTimeline,
|
14331 | loaderType = _ref2.loaderType,
|
14332 | audioDisabled = _ref2.audioDisabled;
|
14333 |
|
14334 | if (currentTimeline === segmentTimeline) {
|
14335 | return false;
|
14336 | }
|
14337 |
|
14338 | if (loaderType === 'audio') {
|
14339 | var lastMainTimelineChange = timelineChangeController.lastTimelineChange({
|
14340 | type: 'main'
|
14341 | });
|
14342 |
|
14343 |
|
14344 |
|
14345 |
|
14346 | return !lastMainTimelineChange || lastMainTimelineChange.to !== segmentTimeline;
|
14347 | }
|
14348 |
|
14349 |
|
14350 |
|
14351 |
|
14352 |
|
14353 | if (loaderType === 'main' && audioDisabled) {
|
14354 | var pendingAudioTimelineChange = timelineChangeController.pendingTimelineChange({
|
14355 | type: 'audio'
|
14356 | });
|
14357 |
|
14358 |
|
14359 |
|
14360 |
|
14361 |
|
14362 |
|
14363 |
|
14364 |
|
14365 |
|
14366 |
|
14367 |
|
14368 |
|
14369 |
|
14370 |
|
14371 |
|
14372 |
|
14373 |
|
14374 |
|
14375 | if (pendingAudioTimelineChange && pendingAudioTimelineChange.to === segmentTimeline) {
|
14376 | return false;
|
14377 | }
|
14378 |
|
14379 | return true;
|
14380 | }
|
14381 |
|
14382 | return false;
|
14383 | };
|
14384 | var mediaDuration = function mediaDuration(audioTimingInfo, videoTimingInfo) {
|
14385 | var audioDuration = audioTimingInfo && typeof audioTimingInfo.start === 'number' && typeof audioTimingInfo.end === 'number' ? audioTimingInfo.end - audioTimingInfo.start : 0;
|
14386 | var videoDuration = videoTimingInfo && typeof videoTimingInfo.start === 'number' && typeof videoTimingInfo.end === 'number' ? videoTimingInfo.end - videoTimingInfo.start : 0;
|
14387 | return Math.max(audioDuration, videoDuration);
|
14388 | };
|
14389 | var segmentTooLong = function segmentTooLong(_ref3) {
|
14390 | var segmentDuration = _ref3.segmentDuration,
|
14391 | maxDuration = _ref3.maxDuration;
|
14392 |
|
14393 |
|
14394 |
|
14395 | if (!segmentDuration) {
|
14396 | return false;
|
14397 | }
|
14398 |
|
14399 |
|
14400 |
|
14401 |
|
14402 |
|
14403 |
|
14404 |
|
14405 |
|
14406 |
|
14407 |
|
14408 |
|
14409 |
|
14410 | return Math.round(segmentDuration) > maxDuration + TIME_FUDGE_FACTOR;
|
14411 | };
|
14412 | var getTroublesomeSegmentDurationMessage = function getTroublesomeSegmentDurationMessage(segmentInfo, sourceType) {
|
14413 |
|
14414 |
|
14415 | if (sourceType !== 'hls') {
|
14416 | return null;
|
14417 | }
|
14418 |
|
14419 | var segmentDuration = mediaDuration(segmentInfo.audioTimingInfo, segmentInfo.videoTimingInfo);
|
14420 |
|
14421 |
|
14422 |
|
14423 |
|
14424 | if (!segmentDuration) {
|
14425 | return null;
|
14426 | }
|
14427 |
|
14428 | var targetDuration = segmentInfo.playlist.targetDuration;
|
14429 | var isSegmentWayTooLong = segmentTooLong({
|
14430 | segmentDuration: segmentDuration,
|
14431 | maxDuration: targetDuration * 2
|
14432 | });
|
14433 | var isSegmentSlightlyTooLong = segmentTooLong({
|
14434 | segmentDuration: segmentDuration,
|
14435 | maxDuration: targetDuration
|
14436 | });
|
14437 | 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';
|
14438 |
|
14439 | if (isSegmentWayTooLong || isSegmentSlightlyTooLong) {
|
14440 | return {
|
14441 | severity: isSegmentWayTooLong ? 'warn' : 'info',
|
14442 | message: segmentTooLongMessage
|
14443 | };
|
14444 | }
|
14445 |
|
14446 | return null;
|
14447 | };
|
14448 |
|
14449 |
|
14450 |
|
14451 |
|
14452 |
|
14453 |
|
14454 |
|
14455 |
|
14456 | var SegmentLoader = function (_videojs$EventTarget) {
|
14457 | _inheritsLoose__default['default'](SegmentLoader, _videojs$EventTarget);
|
14458 |
|
14459 | function SegmentLoader(settings, options) {
|
14460 | var _this;
|
14461 |
|
14462 | _this = _videojs$EventTarget.call(this) || this;
|
14463 |
|
14464 | if (!settings) {
|
14465 | throw new TypeError('Initialization settings are required');
|
14466 | }
|
14467 |
|
14468 | if (typeof settings.currentTime !== 'function') {
|
14469 | throw new TypeError('No currentTime getter specified');
|
14470 | }
|
14471 |
|
14472 | if (!settings.mediaSource) {
|
14473 | throw new TypeError('No MediaSource specified');
|
14474 | }
|
14475 |
|
14476 |
|
14477 | _this.bandwidth = settings.bandwidth;
|
14478 | _this.throughput = {
|
14479 | rate: 0,
|
14480 | count: 0
|
14481 | };
|
14482 | _this.roundTrip = NaN;
|
14483 |
|
14484 | _this.resetStats_();
|
14485 |
|
14486 | _this.mediaIndex = null;
|
14487 | _this.partIndex = null;
|
14488 |
|
14489 | _this.hasPlayed_ = settings.hasPlayed;
|
14490 | _this.currentTime_ = settings.currentTime;
|
14491 | _this.seekable_ = settings.seekable;
|
14492 | _this.seeking_ = settings.seeking;
|
14493 | _this.duration_ = settings.duration;
|
14494 | _this.mediaSource_ = settings.mediaSource;
|
14495 | _this.vhs_ = settings.vhs;
|
14496 | _this.loaderType_ = settings.loaderType;
|
14497 | _this.currentMediaInfo_ = void 0;
|
14498 | _this.startingMediaInfo_ = void 0;
|
14499 | _this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
|
14500 | _this.goalBufferLength_ = settings.goalBufferLength;
|
14501 | _this.sourceType_ = settings.sourceType;
|
14502 | _this.sourceUpdater_ = settings.sourceUpdater;
|
14503 | _this.inbandTextTracks_ = settings.inbandTextTracks;
|
14504 | _this.state_ = 'INIT';
|
14505 | _this.handlePartialData_ = settings.handlePartialData;
|
14506 | _this.timelineChangeController_ = settings.timelineChangeController;
|
14507 | _this.shouldSaveSegmentTimingInfo_ = true;
|
14508 | _this.parse708captions_ = settings.parse708captions;
|
14509 |
|
14510 | _this.checkBufferTimeout_ = null;
|
14511 | _this.error_ = void 0;
|
14512 | _this.currentTimeline_ = -1;
|
14513 | _this.pendingSegment_ = null;
|
14514 | _this.xhrOptions_ = null;
|
14515 | _this.pendingSegments_ = [];
|
14516 | _this.audioDisabled_ = false;
|
14517 | _this.isPendingTimestampOffset_ = false;
|
14518 |
|
14519 | _this.gopBuffer_ = [];
|
14520 | _this.timeMapping_ = 0;
|
14521 | _this.safeAppend_ = videojs__default['default'].browser.IE_VERSION >= 11;
|
14522 | _this.appendInitSegment_ = {
|
14523 | audio: true,
|
14524 | video: true
|
14525 | };
|
14526 | _this.playlistOfLastInitSegment_ = {
|
14527 | audio: null,
|
14528 | video: null
|
14529 | };
|
14530 | _this.callQueue_ = [];
|
14531 |
|
14532 |
|
14533 |
|
14534 |
|
14535 |
|
14536 | _this.loadQueue_ = [];
|
14537 | _this.metadataQueue_ = {
|
14538 | id3: [],
|
14539 | caption: []
|
14540 | };
|
14541 | _this.waitingOnRemove_ = false;
|
14542 | _this.quotaExceededErrorRetryTimeout_ = null;
|
14543 |
|
14544 | _this.activeInitSegmentId_ = null;
|
14545 | _this.initSegments_ = {};
|
14546 |
|
14547 | _this.cacheEncryptionKeys_ = settings.cacheEncryptionKeys;
|
14548 | _this.keyCache_ = {};
|
14549 | _this.decrypter_ = settings.decrypter;
|
14550 |
|
14551 |
|
14552 |
|
14553 | _this.syncController_ = settings.syncController;
|
14554 | _this.syncPoint_ = {
|
14555 | segmentIndex: 0,
|
14556 | time: 0
|
14557 | };
|
14558 | _this.transmuxer_ = _this.createTransmuxer_();
|
14559 |
|
14560 | _this.triggerSyncInfoUpdate_ = function () {
|
14561 | return _this.trigger('syncinfoupdate');
|
14562 | };
|
14563 |
|
14564 | _this.syncController_.on('syncinfoupdate', _this.triggerSyncInfoUpdate_);
|
14565 |
|
14566 | _this.mediaSource_.addEventListener('sourceopen', function () {
|
14567 | if (!_this.isEndOfStream_()) {
|
14568 | _this.ended_ = false;
|
14569 | }
|
14570 | });
|
14571 |
|
14572 |
|
14573 | _this.fetchAtBuffer_ = false;
|
14574 | _this.logger_ = logger("SegmentLoader[" + _this.loaderType_ + "]");
|
14575 | Object.defineProperty(_assertThisInitialized__default['default'](_this), 'state', {
|
14576 | get: function get() {
|
14577 | return this.state_;
|
14578 | },
|
14579 | set: function set(newState) {
|
14580 | if (newState !== this.state_) {
|
14581 | this.logger_(this.state_ + " -> " + newState);
|
14582 | this.state_ = newState;
|
14583 | this.trigger('statechange');
|
14584 | }
|
14585 | }
|
14586 | });
|
14587 |
|
14588 | _this.sourceUpdater_.on('ready', function () {
|
14589 | if (_this.hasEnoughInfoToAppend_()) {
|
14590 | _this.processCallQueue_();
|
14591 | }
|
14592 | });
|
14593 |
|
14594 |
|
14595 |
|
14596 |
|
14597 |
|
14598 | if (_this.loaderType_ === 'main') {
|
14599 | _this.timelineChangeController_.on('pendingtimelinechange', function () {
|
14600 | if (_this.hasEnoughInfoToAppend_()) {
|
14601 | _this.processCallQueue_();
|
14602 | }
|
14603 | });
|
14604 | }
|
14605 |
|
14606 |
|
14607 |
|
14608 |
|
14609 | if (_this.loaderType_ === 'audio') {
|
14610 | _this.timelineChangeController_.on('timelinechange', function () {
|
14611 | if (_this.hasEnoughInfoToLoad_()) {
|
14612 | _this.processLoadQueue_();
|
14613 | }
|
14614 |
|
14615 | if (_this.hasEnoughInfoToAppend_()) {
|
14616 | _this.processCallQueue_();
|
14617 | }
|
14618 | });
|
14619 | }
|
14620 |
|
14621 | return _this;
|
14622 | }
|
14623 |
|
14624 | var _proto = SegmentLoader.prototype;
|
14625 |
|
14626 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
14627 | return segmentTransmuxer.createTransmuxer({
|
14628 | remux: false,
|
14629 | alignGopsAtEnd: this.safeAppend_,
|
14630 | keepOriginalTimestamps: true,
|
14631 | handlePartialData: this.handlePartialData_,
|
14632 | parse708captions: this.parse708captions_
|
14633 | });
|
14634 | }
|
14635 | |
14636 |
|
14637 |
|
14638 |
|
14639 |
|
14640 | ;
|
14641 |
|
14642 | _proto.resetStats_ = function resetStats_() {
|
14643 | this.mediaBytesTransferred = 0;
|
14644 | this.mediaRequests = 0;
|
14645 | this.mediaRequestsAborted = 0;
|
14646 | this.mediaRequestsTimedout = 0;
|
14647 | this.mediaRequestsErrored = 0;
|
14648 | this.mediaTransferDuration = 0;
|
14649 | this.mediaSecondsLoaded = 0;
|
14650 | }
|
14651 | |
14652 |
|
14653 |
|
14654 | ;
|
14655 |
|
14656 | _proto.dispose = function dispose() {
|
14657 | this.trigger('dispose');
|
14658 | this.state = 'DISPOSED';
|
14659 | this.pause();
|
14660 | this.abort_();
|
14661 |
|
14662 | if (this.transmuxer_) {
|
14663 | this.transmuxer_.terminate();
|
14664 | }
|
14665 |
|
14666 | this.resetStats_();
|
14667 |
|
14668 | if (this.checkBufferTimeout_) {
|
14669 | window__default['default'].clearTimeout(this.checkBufferTimeout_);
|
14670 | }
|
14671 |
|
14672 | if (this.syncController_ && this.triggerSyncInfoUpdate_) {
|
14673 | this.syncController_.off('syncinfoupdate', this.triggerSyncInfoUpdate_);
|
14674 | }
|
14675 |
|
14676 | this.off();
|
14677 | };
|
14678 |
|
14679 | _proto.setAudio = function setAudio(enable) {
|
14680 | this.audioDisabled_ = !enable;
|
14681 |
|
14682 | if (enable) {
|
14683 | this.appendInitSegment_.audio = true;
|
14684 | } else {
|
14685 |
|
14686 | this.sourceUpdater_.removeAudio(0, this.duration_());
|
14687 | }
|
14688 | }
|
14689 | |
14690 |
|
14691 |
|
14692 |
|
14693 | ;
|
14694 |
|
14695 | _proto.abort = function abort() {
|
14696 | if (this.state !== 'WAITING') {
|
14697 | if (this.pendingSegment_) {
|
14698 | this.pendingSegment_ = null;
|
14699 | }
|
14700 |
|
14701 | return;
|
14702 | }
|
14703 |
|
14704 | this.abort_();
|
14705 |
|
14706 |
|
14707 |
|
14708 |
|
14709 | this.state = 'READY';
|
14710 |
|
14711 |
|
14712 | if (!this.paused()) {
|
14713 | this.monitorBuffer_();
|
14714 | }
|
14715 | }
|
14716 | |
14717 |
|
14718 |
|
14719 |
|
14720 |
|
14721 | ;
|
14722 |
|
14723 | _proto.abort_ = function abort_() {
|
14724 | if (this.pendingSegment_ && this.pendingSegment_.abortRequests) {
|
14725 | this.pendingSegment_.abortRequests();
|
14726 | }
|
14727 |
|
14728 |
|
14729 | this.pendingSegment_ = null;
|
14730 | this.callQueue_ = [];
|
14731 | this.loadQueue_ = [];
|
14732 | this.metadataQueue_.id3 = [];
|
14733 | this.metadataQueue_.caption = [];
|
14734 | this.timelineChangeController_.clearPendingTimelineChange(this.loaderType_);
|
14735 | this.waitingOnRemove_ = false;
|
14736 | window__default['default'].clearTimeout(this.quotaExceededErrorRetryTimeout_);
|
14737 | this.quotaExceededErrorRetryTimeout_ = null;
|
14738 | };
|
14739 |
|
14740 | _proto.checkForAbort_ = function checkForAbort_(requestId) {
|
14741 |
|
14742 |
|
14743 | if (this.state === 'APPENDING' && !this.pendingSegment_) {
|
14744 | this.state = 'READY';
|
14745 | return true;
|
14746 | }
|
14747 |
|
14748 | if (!this.pendingSegment_ || this.pendingSegment_.requestId !== requestId) {
|
14749 | return true;
|
14750 | }
|
14751 |
|
14752 | return false;
|
14753 | }
|
14754 | |
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 |
|
14760 | ;
|
14761 |
|
14762 | _proto.error = function error(_error) {
|
14763 | if (typeof _error !== 'undefined') {
|
14764 | this.logger_('error occurred:', _error);
|
14765 | this.error_ = _error;
|
14766 | }
|
14767 |
|
14768 | this.pendingSegment_ = null;
|
14769 | return this.error_;
|
14770 | };
|
14771 |
|
14772 | _proto.endOfStream = function endOfStream() {
|
14773 | this.ended_ = true;
|
14774 |
|
14775 | if (this.transmuxer_) {
|
14776 |
|
14777 | segmentTransmuxer.reset(this.transmuxer_);
|
14778 | }
|
14779 |
|
14780 | this.gopBuffer_.length = 0;
|
14781 | this.pause();
|
14782 | this.trigger('ended');
|
14783 | }
|
14784 | |
14785 |
|
14786 |
|
14787 |
|
14788 |
|
14789 |
|
14790 | ;
|
14791 |
|
14792 | _proto.buffered_ = function buffered_() {
|
14793 | if (!this.sourceUpdater_ || !this.startingMediaInfo_) {
|
14794 | return videojs__default['default'].createTimeRanges();
|
14795 | }
|
14796 |
|
14797 | if (this.loaderType_ === 'main') {
|
14798 | var _this$startingMediaIn = this.startingMediaInfo_,
|
14799 | hasAudio = _this$startingMediaIn.hasAudio,
|
14800 | hasVideo = _this$startingMediaIn.hasVideo,
|
14801 | isMuxed = _this$startingMediaIn.isMuxed;
|
14802 |
|
14803 | if (hasVideo && hasAudio && !this.audioDisabled_ && !isMuxed) {
|
14804 | return this.sourceUpdater_.buffered();
|
14805 | }
|
14806 |
|
14807 | if (hasVideo) {
|
14808 | return this.sourceUpdater_.videoBuffered();
|
14809 | }
|
14810 | }
|
14811 |
|
14812 |
|
14813 |
|
14814 | return this.sourceUpdater_.audioBuffered();
|
14815 | }
|
14816 | |
14817 |
|
14818 |
|
14819 |
|
14820 |
|
14821 |
|
14822 |
|
14823 |
|
14824 |
|
14825 |
|
14826 | ;
|
14827 |
|
14828 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
14829 | if (set === void 0) {
|
14830 | set = false;
|
14831 | }
|
14832 |
|
14833 | if (!map) {
|
14834 | return null;
|
14835 | }
|
14836 |
|
14837 | var id = initSegmentId(map);
|
14838 | var storedMap = this.initSegments_[id];
|
14839 |
|
14840 | if (set && !storedMap && map.bytes) {
|
14841 | this.initSegments_[id] = storedMap = {
|
14842 | resolvedUri: map.resolvedUri,
|
14843 | byterange: map.byterange,
|
14844 | bytes: map.bytes,
|
14845 | tracks: map.tracks,
|
14846 | timescales: map.timescales
|
14847 | };
|
14848 | }
|
14849 |
|
14850 | return storedMap || map;
|
14851 | }
|
14852 | |
14853 |
|
14854 |
|
14855 |
|
14856 |
|
14857 |
|
14858 |
|
14859 |
|
14860 |
|
14861 |
|
14862 | ;
|
14863 |
|
14864 | _proto.segmentKey = function segmentKey(key, set) {
|
14865 | if (set === void 0) {
|
14866 | set = false;
|
14867 | }
|
14868 |
|
14869 | if (!key) {
|
14870 | return null;
|
14871 | }
|
14872 |
|
14873 | var id = segmentKeyId(key);
|
14874 | var storedKey = this.keyCache_[id];
|
14875 |
|
14876 |
|
14877 | if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) {
|
14878 | this.keyCache_[id] = storedKey = {
|
14879 | resolvedUri: key.resolvedUri,
|
14880 | bytes: key.bytes
|
14881 | };
|
14882 | }
|
14883 |
|
14884 | var result = {
|
14885 | resolvedUri: (storedKey || key).resolvedUri
|
14886 | };
|
14887 |
|
14888 | if (storedKey) {
|
14889 | result.bytes = storedKey.bytes;
|
14890 | }
|
14891 |
|
14892 | return result;
|
14893 | }
|
14894 | |
14895 |
|
14896 |
|
14897 |
|
14898 |
|
14899 |
|
14900 | ;
|
14901 |
|
14902 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
14903 | return this.playlist_ && !this.paused();
|
14904 | }
|
14905 | |
14906 |
|
14907 |
|
14908 | ;
|
14909 |
|
14910 | _proto.load = function load() {
|
14911 |
|
14912 | this.monitorBuffer_();
|
14913 |
|
14914 |
|
14915 | if (!this.playlist_) {
|
14916 | return;
|
14917 | }
|
14918 |
|
14919 |
|
14920 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
14921 | return this.init_();
|
14922 | }
|
14923 |
|
14924 |
|
14925 |
|
14926 | if (!this.couldBeginLoading_() || this.state !== 'READY' && this.state !== 'INIT') {
|
14927 | return;
|
14928 | }
|
14929 |
|
14930 | this.state = 'READY';
|
14931 | }
|
14932 | |
14933 |
|
14934 |
|
14935 |
|
14936 |
|
14937 |
|
14938 |
|
14939 | ;
|
14940 |
|
14941 | _proto.init_ = function init_() {
|
14942 | this.state = 'READY';
|
14943 |
|
14944 |
|
14945 | this.resetEverything();
|
14946 | return this.monitorBuffer_();
|
14947 | }
|
14948 | |
14949 |
|
14950 |
|
14951 |
|
14952 |
|
14953 | ;
|
14954 |
|
14955 | _proto.playlist = function playlist(newPlaylist, options) {
|
14956 | if (options === void 0) {
|
14957 | options = {};
|
14958 | }
|
14959 |
|
14960 | if (!newPlaylist) {
|
14961 | return;
|
14962 | }
|
14963 |
|
14964 | var oldPlaylist = this.playlist_;
|
14965 | var segmentInfo = this.pendingSegment_;
|
14966 | this.playlist_ = newPlaylist;
|
14967 | this.xhrOptions_ = options;
|
14968 |
|
14969 |
|
14970 |
|
14971 |
|
14972 |
|
14973 |
|
14974 |
|
14975 | if (this.state === 'INIT') {
|
14976 | newPlaylist.syncInfo = {
|
14977 | mediaSequence: newPlaylist.mediaSequence,
|
14978 | time: 0
|
14979 | };
|
14980 |
|
14981 |
|
14982 |
|
14983 |
|
14984 |
|
14985 |
|
14986 |
|
14987 |
|
14988 | if (this.loaderType_ === 'main') {
|
14989 | this.syncController_.setDateTimeMappingForStart(newPlaylist);
|
14990 | }
|
14991 | }
|
14992 |
|
14993 | var oldId = null;
|
14994 |
|
14995 | if (oldPlaylist) {
|
14996 | if (oldPlaylist.id) {
|
14997 | oldId = oldPlaylist.id;
|
14998 | } else if (oldPlaylist.uri) {
|
14999 | oldId = oldPlaylist.uri;
|
15000 | }
|
15001 | }
|
15002 |
|
15003 | this.logger_("playlist update [" + oldId + " => " + (newPlaylist.id || newPlaylist.uri) + "]");
|
15004 |
|
15005 |
|
15006 | this.trigger('syncinfoupdate');
|
15007 |
|
15008 |
|
15009 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
15010 | return this.init_();
|
15011 | }
|
15012 |
|
15013 | if (!oldPlaylist || oldPlaylist.uri !== newPlaylist.uri) {
|
15014 | if (this.mediaIndex !== null || this.handlePartialData_) {
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 | this.resyncLoader();
|
15021 | }
|
15022 |
|
15023 | this.currentMediaInfo_ = void 0;
|
15024 | this.trigger('playlistupdate');
|
15025 |
|
15026 | return;
|
15027 | }
|
15028 |
|
15029 |
|
15030 |
|
15031 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
15032 | this.logger_("live window shift [" + mediaSequenceDiff + "]");
|
15033 |
|
15034 |
|
15035 |
|
15036 | if (this.mediaIndex !== null) {
|
15037 | this.mediaIndex -= mediaSequenceDiff;
|
15038 |
|
15039 |
|
15040 |
|
15041 | if (this.mediaIndex < 0) {
|
15042 | this.mediaIndex = null;
|
15043 | this.partIndex = null;
|
15044 | } else {
|
15045 | var segment = this.playlist_.segments[this.mediaIndex];
|
15046 |
|
15047 |
|
15048 |
|
15049 | if (this.partIndex && (!segment.parts || !segment.parts.length || !segment.parts[this.partIndex])) {
|
15050 | var mediaIndex = this.mediaIndex;
|
15051 | this.logger_("currently processing part (index " + this.partIndex + ") no longer exists.");
|
15052 | this.resetLoader();
|
15053 |
|
15054 |
|
15055 |
|
15056 | this.mediaIndex = mediaIndex;
|
15057 | }
|
15058 | }
|
15059 | }
|
15060 |
|
15061 |
|
15062 |
|
15063 |
|
15064 | if (segmentInfo) {
|
15065 | segmentInfo.mediaIndex -= mediaSequenceDiff;
|
15066 |
|
15067 | if (segmentInfo.mediaIndex < 0) {
|
15068 | segmentInfo.mediaIndex = null;
|
15069 | segmentInfo.partIndex = null;
|
15070 | } else {
|
15071 |
|
15072 |
|
15073 |
|
15074 | if (segmentInfo.mediaIndex >= 0) {
|
15075 | segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex];
|
15076 | }
|
15077 |
|
15078 | if (segmentInfo.partIndex >= 0 && segmentInfo.segment.parts) {
|
15079 | segmentInfo.part = segmentInfo.segment.parts[segmentInfo.partIndex];
|
15080 | }
|
15081 | }
|
15082 | }
|
15083 |
|
15084 | this.syncController_.saveExpiredSegmentInfo(oldPlaylist, newPlaylist);
|
15085 | }
|
15086 | |
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 |
|
15092 | ;
|
15093 |
|
15094 | _proto.pause = function pause() {
|
15095 | if (this.checkBufferTimeout_) {
|
15096 | window__default['default'].clearTimeout(this.checkBufferTimeout_);
|
15097 | this.checkBufferTimeout_ = null;
|
15098 | }
|
15099 | }
|
15100 | |
15101 |
|
15102 |
|
15103 |
|
15104 |
|
15105 | ;
|
15106 |
|
15107 | _proto.paused = function paused() {
|
15108 | return this.checkBufferTimeout_ === null;
|
15109 | }
|
15110 | |
15111 |
|
15112 |
|
15113 |
|
15114 |
|
15115 |
|
15116 | ;
|
15117 |
|
15118 | _proto.resetEverything = function resetEverything(done) {
|
15119 | this.ended_ = false;
|
15120 | this.appendInitSegment_ = {
|
15121 | audio: true,
|
15122 | video: true
|
15123 | };
|
15124 | this.resetLoader();
|
15125 |
|
15126 |
|
15127 |
|
15128 | this.remove(0, Infinity, done);
|
15129 |
|
15130 | if (this.transmuxer_) {
|
15131 | this.transmuxer_.postMessage({
|
15132 | action: 'clearAllMp4Captions'
|
15133 | });
|
15134 | }
|
15135 | }
|
15136 | |
15137 |
|
15138 |
|
15139 |
|
15140 |
|
15141 |
|
15142 | ;
|
15143 |
|
15144 | _proto.resetLoader = function resetLoader() {
|
15145 | this.fetchAtBuffer_ = false;
|
15146 | this.resyncLoader();
|
15147 | }
|
15148 | |
15149 |
|
15150 |
|
15151 |
|
15152 | ;
|
15153 |
|
15154 | _proto.resyncLoader = function resyncLoader() {
|
15155 | if (this.transmuxer_) {
|
15156 |
|
15157 | segmentTransmuxer.reset(this.transmuxer_);
|
15158 | }
|
15159 |
|
15160 | this.mediaIndex = null;
|
15161 | this.partIndex = null;
|
15162 | this.syncPoint_ = null;
|
15163 | this.isPendingTimestampOffset_ = false;
|
15164 | this.callQueue_ = [];
|
15165 | this.loadQueue_ = [];
|
15166 | this.metadataQueue_.id3 = [];
|
15167 | this.metadataQueue_.caption = [];
|
15168 | this.abort();
|
15169 |
|
15170 | if (this.transmuxer_) {
|
15171 | this.transmuxer_.postMessage({
|
15172 | action: 'clearParsedMp4Captions'
|
15173 | });
|
15174 | }
|
15175 | }
|
15176 | |
15177 |
|
15178 |
|
15179 |
|
15180 |
|
15181 |
|
15182 |
|
15183 |
|
15184 |
|
15185 | ;
|
15186 |
|
15187 | _proto.remove = function remove(start, end, done, force) {
|
15188 | if (done === void 0) {
|
15189 | done = function done() {};
|
15190 | }
|
15191 |
|
15192 | if (force === void 0) {
|
15193 | force = false;
|
15194 | }
|
15195 |
|
15196 |
|
15197 |
|
15198 |
|
15199 | if (end === Infinity) {
|
15200 | end = this.duration_();
|
15201 | }
|
15202 |
|
15203 | if (!this.sourceUpdater_ || !this.startingMediaInfo_) {
|
15204 | this.logger_('skipping remove because no source updater or starting media info');
|
15205 |
|
15206 | return;
|
15207 | }
|
15208 |
|
15209 |
|
15210 | var removesRemaining = 1;
|
15211 |
|
15212 | var removeFinished = function removeFinished() {
|
15213 | removesRemaining--;
|
15214 |
|
15215 | if (removesRemaining === 0) {
|
15216 | done();
|
15217 | }
|
15218 | };
|
15219 |
|
15220 | if (force || !this.audioDisabled_) {
|
15221 | removesRemaining++;
|
15222 | this.sourceUpdater_.removeAudio(start, end, removeFinished);
|
15223 | }
|
15224 |
|
15225 |
|
15226 |
|
15227 |
|
15228 |
|
15229 |
|
15230 |
|
15231 |
|
15232 |
|
15233 | if (force || this.loaderType_ === 'main') {
|
15234 | this.gopBuffer_ = removeGopBuffer(this.gopBuffer_, start, end, this.timeMapping_);
|
15235 | removesRemaining++;
|
15236 | this.sourceUpdater_.removeVideo(start, end, removeFinished);
|
15237 | }
|
15238 |
|
15239 |
|
15240 | for (var track in this.inbandTextTracks_) {
|
15241 | removeCuesFromTrack(start, end, this.inbandTextTracks_[track]);
|
15242 | }
|
15243 |
|
15244 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
15245 |
|
15246 | removeFinished();
|
15247 | }
|
15248 | |
15249 |
|
15250 |
|
15251 |
|
15252 |
|
15253 | ;
|
15254 |
|
15255 | _proto.monitorBuffer_ = function monitorBuffer_() {
|
15256 | if (this.checkBufferTimeout_) {
|
15257 | window__default['default'].clearTimeout(this.checkBufferTimeout_);
|
15258 | }
|
15259 |
|
15260 | this.checkBufferTimeout_ = window__default['default'].setTimeout(this.monitorBufferTick_.bind(this), 1);
|
15261 | }
|
15262 | |
15263 |
|
15264 |
|
15265 |
|
15266 |
|
15267 |
|
15268 | ;
|
15269 |
|
15270 | _proto.monitorBufferTick_ = function monitorBufferTick_() {
|
15271 | if (this.state === 'READY') {
|
15272 | this.fillBuffer_();
|
15273 | }
|
15274 |
|
15275 | if (this.checkBufferTimeout_) {
|
15276 | window__default['default'].clearTimeout(this.checkBufferTimeout_);
|
15277 | }
|
15278 |
|
15279 | this.checkBufferTimeout_ = window__default['default'].setTimeout(this.monitorBufferTick_.bind(this), CHECK_BUFFER_DELAY);
|
15280 | }
|
15281 | |
15282 |
|
15283 |
|
15284 |
|
15285 |
|
15286 |
|
15287 |
|
15288 |
|
15289 |
|
15290 | ;
|
15291 |
|
15292 | _proto.fillBuffer_ = function fillBuffer_() {
|
15293 |
|
15294 |
|
15295 | if (this.sourceUpdater_.updating()) {
|
15296 | return;
|
15297 | }
|
15298 |
|
15299 | if (!this.syncPoint_) {
|
15300 | this.syncPoint_ = this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
15301 | }
|
15302 |
|
15303 | var buffered = this.buffered_();
|
15304 |
|
15305 | var segmentInfo = this.checkBuffer_(buffered, this.playlist_, this.mediaIndex, this.hasPlayed_(), this.currentTime_(), this.syncPoint_, this.partIndex);
|
15306 |
|
15307 | if (!segmentInfo) {
|
15308 | return;
|
15309 | }
|
15310 |
|
15311 | segmentInfo.timestampOffset = timestampOffsetForSegment({
|
15312 | segmentTimeline: segmentInfo.timeline,
|
15313 | currentTimeline: this.currentTimeline_,
|
15314 | startOfSegment: segmentInfo.startOfSegment,
|
15315 | buffered: buffered,
|
15316 | overrideCheck: this.isPendingTimestampOffset_
|
15317 | });
|
15318 | this.isPendingTimestampOffset_ = false;
|
15319 |
|
15320 | if (typeof segmentInfo.timestampOffset === 'number') {
|
15321 | this.timelineChangeController_.pendingTimelineChange({
|
15322 | type: this.loaderType_,
|
15323 | from: this.currentTimeline_,
|
15324 | to: segmentInfo.timeline
|
15325 | });
|
15326 | }
|
15327 |
|
15328 | this.loadSegment_(segmentInfo);
|
15329 | }
|
15330 | |
15331 |
|
15332 |
|
15333 |
|
15334 |
|
15335 |
|
15336 |
|
15337 |
|
15338 |
|
15339 | ;
|
15340 |
|
15341 | _proto.isEndOfStream_ = function isEndOfStream_(mediaIndex, playlist, partIndex) {
|
15342 | if (mediaIndex === void 0) {
|
15343 | mediaIndex = this.mediaIndex;
|
15344 | }
|
15345 |
|
15346 | if (playlist === void 0) {
|
15347 | playlist = this.playlist_;
|
15348 | }
|
15349 |
|
15350 | if (partIndex === void 0) {
|
15351 | partIndex = this.partIndex;
|
15352 | }
|
15353 |
|
15354 | if (!playlist || !this.mediaSource_) {
|
15355 | return false;
|
15356 | }
|
15357 |
|
15358 | var segment = typeof mediaIndex === 'number' && playlist.segments[mediaIndex];
|
15359 |
|
15360 | var appendedLastSegment = mediaIndex + 1 === playlist.segments.length;
|
15361 |
|
15362 | var appendedLastPart = !segment || !segment.parts || partIndex + 1 === segment.parts.length;
|
15363 |
|
15364 |
|
15365 |
|
15366 | return playlist.endList && this.mediaSource_.readyState === 'open' && appendedLastSegment && appendedLastPart;
|
15367 | }
|
15368 | |
15369 |
|
15370 |
|
15371 |
|
15372 |
|
15373 |
|
15374 |
|
15375 |
|
15376 |
|
15377 |
|
15378 |
|
15379 |
|
15380 | ;
|
15381 |
|
15382 | _proto.checkBuffer_ = function checkBuffer_(buffered, playlist, currentMediaIndex, hasPlayed, currentTime, syncPoint, currentPartIndex) {
|
15383 | var lastBufferedEnd = 0;
|
15384 |
|
15385 | if (buffered.length) {
|
15386 | lastBufferedEnd = buffered.end(buffered.length - 1);
|
15387 | }
|
15388 |
|
15389 | var bufferedTime = Math.max(0, lastBufferedEnd - currentTime);
|
15390 |
|
15391 | if (!playlist.segments.length) {
|
15392 | return null;
|
15393 | }
|
15394 |
|
15395 |
|
15396 |
|
15397 | if (bufferedTime >= this.goalBufferLength_()) {
|
15398 | return null;
|
15399 | }
|
15400 |
|
15401 |
|
15402 |
|
15403 | if (!hasPlayed && bufferedTime >= 1) {
|
15404 | return null;
|
15405 | }
|
15406 |
|
15407 | var nextPartIndex = null;
|
15408 | var nextMediaIndex = null;
|
15409 | var startOfSegment;
|
15410 | var isSyncRequest = false;
|
15411 |
|
15412 |
|
15413 |
|
15414 |
|
15415 | if (syncPoint === null) {
|
15416 | nextMediaIndex = this.getSyncSegmentCandidate_(playlist);
|
15417 | isSyncRequest = true;
|
15418 | } else if (currentMediaIndex !== null) {
|
15419 |
|
15420 | var segment = playlist.segments[currentMediaIndex];
|
15421 | var partIndex = typeof currentPartIndex === 'number' ? currentPartIndex : -1;
|
15422 | startOfSegment = segment.end ? segment.end : lastBufferedEnd;
|
15423 |
|
15424 | if (segment.parts && segment.parts[partIndex + 1]) {
|
15425 | nextMediaIndex = currentMediaIndex;
|
15426 | nextPartIndex = partIndex + 1;
|
15427 | } else {
|
15428 | nextMediaIndex = currentMediaIndex + 1;
|
15429 | }
|
15430 |
|
15431 |
|
15432 |
|
15433 | } else {
|
15434 |
|
15435 | var mediaSourceInfo = Playlist.getMediaInfoForTime(playlist, this.fetchAtBuffer_ ? lastBufferedEnd : currentTime, syncPoint.segmentIndex, syncPoint.time);
|
15436 | nextMediaIndex = mediaSourceInfo.mediaIndex;
|
15437 | startOfSegment = mediaSourceInfo.startTime;
|
15438 | nextPartIndex = mediaSourceInfo.partIndex;
|
15439 | }
|
15440 |
|
15441 | if (typeof nextPartIndex !== 'number' && playlist.segments[nextMediaIndex] && playlist.segments[nextMediaIndex].parts) {
|
15442 | nextPartIndex = 0;
|
15443 | }
|
15444 |
|
15445 | var segmentInfo = this.generateSegmentInfo_(playlist, nextMediaIndex, startOfSegment, isSyncRequest, nextPartIndex);
|
15446 |
|
15447 | if (!segmentInfo) {
|
15448 | return;
|
15449 | }
|
15450 |
|
15451 |
|
15452 |
|
15453 |
|
15454 | if (this.mediaSource_ && this.playlist_ && segmentInfo.mediaIndex === this.playlist_.segments.length - 1 && this.mediaSource_.readyState === 'ended' && !this.seeking_()) {
|
15455 | return;
|
15456 | }
|
15457 |
|
15458 | this.logger_("checkBuffer_ returning " + segmentInfo.uri, {
|
15459 | segmentInfo: segmentInfo,
|
15460 | playlist: playlist,
|
15461 | currentMediaIndex: currentMediaIndex,
|
15462 | currentPartIndex: currentPartIndex,
|
15463 | nextPartIndex: nextPartIndex,
|
15464 | nextMediaIndex: nextMediaIndex,
|
15465 | startOfSegment: startOfSegment,
|
15466 | isSyncRequest: isSyncRequest
|
15467 | });
|
15468 | return segmentInfo;
|
15469 | }
|
15470 | |
15471 |
|
15472 |
|
15473 |
|
15474 |
|
15475 |
|
15476 |
|
15477 |
|
15478 |
|
15479 | ;
|
15480 |
|
15481 | _proto.getSyncSegmentCandidate_ = function getSyncSegmentCandidate_(playlist) {
|
15482 | var _this2 = this;
|
15483 |
|
15484 | if (this.currentTimeline_ === -1) {
|
15485 | return 0;
|
15486 | }
|
15487 |
|
15488 | var segmentIndexArray = playlist.segments.map(function (s, i) {
|
15489 | return {
|
15490 | timeline: s.timeline,
|
15491 | segmentIndex: i
|
15492 | };
|
15493 | }).filter(function (s) {
|
15494 | return s.timeline === _this2.currentTimeline_;
|
15495 | });
|
15496 |
|
15497 | if (segmentIndexArray.length) {
|
15498 | return segmentIndexArray[Math.min(segmentIndexArray.length - 1, 1)].segmentIndex;
|
15499 | }
|
15500 |
|
15501 | return Math.max(playlist.segments.length - 1, 0);
|
15502 | };
|
15503 |
|
15504 | _proto.generateSegmentInfo_ = function generateSegmentInfo_(playlist, mediaIndex, startOfSegment, isSyncRequest, partIndex) {
|
15505 | if (mediaIndex < 0 || mediaIndex >= playlist.segments.length) {
|
15506 | return null;
|
15507 | }
|
15508 |
|
15509 | var segment = playlist.segments[mediaIndex];
|
15510 |
|
15511 | if (segment.parts && segment.parts.length && partIndex >= segment.parts.length) {
|
15512 | return null;
|
15513 | }
|
15514 |
|
15515 | var part = segment.parts && segment.parts.length && segment.parts[partIndex];
|
15516 | var audioBuffered = this.sourceUpdater_.audioBuffered();
|
15517 | var videoBuffered = this.sourceUpdater_.videoBuffered();
|
15518 | var audioAppendStart;
|
15519 | var gopsToAlignWith;
|
15520 |
|
15521 | if (audioBuffered.length) {
|
15522 |
|
15523 |
|
15524 | audioAppendStart = audioBuffered.end(audioBuffered.length - 1) - this.sourceUpdater_.audioTimestampOffset();
|
15525 | }
|
15526 |
|
15527 | if (videoBuffered.length) {
|
15528 | gopsToAlignWith = gopsSafeToAlignWith(this.gopBuffer_,
|
15529 |
|
15530 | this.currentTime_() - this.sourceUpdater_.videoTimestampOffset(), this.timeMapping_);
|
15531 | }
|
15532 |
|
15533 | return {
|
15534 | requestId: 'segment-loader-' + Math.random(),
|
15535 |
|
15536 | uri: part && part.resolvedUri || segment.resolvedUri,
|
15537 |
|
15538 | mediaIndex: mediaIndex,
|
15539 | partIndex: part ? partIndex : null,
|
15540 |
|
15541 |
|
15542 | isSyncRequest: isSyncRequest,
|
15543 | startOfSegment: startOfSegment,
|
15544 |
|
15545 | playlist: playlist,
|
15546 |
|
15547 | bytes: null,
|
15548 |
|
15549 | encryptedBytes: null,
|
15550 |
|
15551 |
|
15552 | timestampOffset: null,
|
15553 |
|
15554 | timeline: segment.timeline,
|
15555 |
|
15556 | duration: segment.duration,
|
15557 |
|
15558 | segment: segment,
|
15559 | part: part,
|
15560 | byteLength: 0,
|
15561 | transmuxer: this.transmuxer_,
|
15562 | audioAppendStart: audioAppendStart,
|
15563 | gopsToAlignWith: gopsToAlignWith
|
15564 | };
|
15565 | }
|
15566 | |
15567 |
|
15568 |
|
15569 |
|
15570 |
|
15571 |
|
15572 |
|
15573 |
|
15574 |
|
15575 | ;
|
15576 |
|
15577 | _proto.earlyAbortWhenNeeded_ = function earlyAbortWhenNeeded_(stats) {
|
15578 | if (this.vhs_.tech_.paused() ||
|
15579 |
|
15580 |
|
15581 | !this.xhrOptions_.timeout ||
|
15582 | !this.playlist_.attributes.BANDWIDTH) {
|
15583 | return;
|
15584 | }
|
15585 |
|
15586 |
|
15587 |
|
15588 |
|
15589 | if (Date.now() - (stats.firstBytesReceivedAt || Date.now()) < 1000) {
|
15590 | return;
|
15591 | }
|
15592 |
|
15593 | var currentTime = this.currentTime_();
|
15594 | var measuredBandwidth = stats.bandwidth;
|
15595 | var segmentDuration = this.pendingSegment_.duration;
|
15596 | var requestTimeRemaining = Playlist.estimateSegmentRequestTime(segmentDuration, measuredBandwidth, this.playlist_, stats.bytesReceived);
|
15597 |
|
15598 |
|
15599 |
|
15600 | var timeUntilRebuffer$1 = timeUntilRebuffer(this.buffered_(), currentTime, this.vhs_.tech_.playbackRate()) - 1;
|
15601 |
|
15602 |
|
15603 | if (requestTimeRemaining <= timeUntilRebuffer$1) {
|
15604 | return;
|
15605 | }
|
15606 |
|
15607 | var switchCandidate = minRebufferMaxBandwidthSelector({
|
15608 | master: this.vhs_.playlists.master,
|
15609 | currentTime: currentTime,
|
15610 | bandwidth: measuredBandwidth,
|
15611 | duration: this.duration_(),
|
15612 | segmentDuration: segmentDuration,
|
15613 | timeUntilRebuffer: timeUntilRebuffer$1,
|
15614 | currentTimeline: this.currentTimeline_,
|
15615 | syncController: this.syncController_
|
15616 | });
|
15617 |
|
15618 | if (!switchCandidate) {
|
15619 | return;
|
15620 | }
|
15621 |
|
15622 | var rebufferingImpact = requestTimeRemaining - timeUntilRebuffer$1;
|
15623 | var timeSavedBySwitching = rebufferingImpact - switchCandidate.rebufferingImpact;
|
15624 | var minimumTimeSaving = 0.5;
|
15625 |
|
15626 |
|
15627 |
|
15628 | if (timeUntilRebuffer$1 <= TIME_FUDGE_FACTOR) {
|
15629 | minimumTimeSaving = 1;
|
15630 | }
|
15631 |
|
15632 | if (!switchCandidate.playlist || switchCandidate.playlist.uri === this.playlist_.uri || timeSavedBySwitching < minimumTimeSaving) {
|
15633 | return;
|
15634 | }
|
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 | this.bandwidth = switchCandidate.playlist.attributes.BANDWIDTH * Config.BANDWIDTH_VARIANCE + 1;
|
15640 | this.trigger('earlyabort');
|
15641 | };
|
15642 |
|
15643 | _proto.handleAbort_ = function handleAbort_(segmentInfo) {
|
15644 | this.logger_("Aborting " + segmentInfoString(segmentInfo));
|
15645 | this.mediaRequestsAborted += 1;
|
15646 | }
|
15647 | |
15648 |
|
15649 |
|
15650 |
|
15651 |
|
15652 |
|
15653 |
|
15654 |
|
15655 |
|
15656 | ;
|
15657 |
|
15658 | _proto.handleProgress_ = function handleProgress_(event, simpleSegment) {
|
15659 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
15660 |
|
15661 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15662 | return;
|
15663 | }
|
15664 |
|
15665 | this.trigger('progress');
|
15666 | };
|
15667 |
|
15668 | _proto.handleTrackInfo_ = function handleTrackInfo_(simpleSegment, trackInfo) {
|
15669 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
15670 |
|
15671 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15672 | return;
|
15673 | }
|
15674 |
|
15675 | if (this.checkForIllegalMediaSwitch(trackInfo)) {
|
15676 | return;
|
15677 | }
|
15678 |
|
15679 | trackInfo = trackInfo || {};
|
15680 |
|
15681 |
|
15682 |
|
15683 | if (!shallowEqual(this.currentMediaInfo_, trackInfo)) {
|
15684 | this.appendInitSegment_ = {
|
15685 | audio: true,
|
15686 | video: true
|
15687 | };
|
15688 | this.startingMediaInfo_ = trackInfo;
|
15689 | this.currentMediaInfo_ = trackInfo;
|
15690 | this.logger_('trackinfo update', trackInfo);
|
15691 | this.trigger('trackinfo');
|
15692 | }
|
15693 |
|
15694 |
|
15695 |
|
15696 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15697 | return;
|
15698 | }
|
15699 |
|
15700 |
|
15701 |
|
15702 | this.pendingSegment_.trackInfo = trackInfo;
|
15703 |
|
15704 | if (this.hasEnoughInfoToAppend_()) {
|
15705 | this.processCallQueue_();
|
15706 | }
|
15707 | };
|
15708 |
|
15709 | _proto.handleTimingInfo_ = function handleTimingInfo_(simpleSegment, mediaType, timeType, time) {
|
15710 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
15711 |
|
15712 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15713 | return;
|
15714 | }
|
15715 |
|
15716 | var segmentInfo = this.pendingSegment_;
|
15717 | var timingInfoProperty = timingInfoPropertyForMedia(mediaType);
|
15718 | segmentInfo[timingInfoProperty] = segmentInfo[timingInfoProperty] || {};
|
15719 | segmentInfo[timingInfoProperty][timeType] = time;
|
15720 | this.logger_("timinginfo: " + mediaType + " - " + timeType + " - " + time);
|
15721 |
|
15722 | if (this.hasEnoughInfoToAppend_()) {
|
15723 | this.processCallQueue_();
|
15724 | }
|
15725 | };
|
15726 |
|
15727 | _proto.handleCaptions_ = function handleCaptions_(simpleSegment, captionData) {
|
15728 | var _this3 = this;
|
15729 |
|
15730 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
15731 |
|
15732 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15733 | return;
|
15734 | }
|
15735 |
|
15736 |
|
15737 |
|
15738 | if (captionData.length === 0) {
|
15739 | this.logger_('SegmentLoader received no captions from a caption event');
|
15740 | return;
|
15741 | }
|
15742 |
|
15743 | var segmentInfo = this.pendingSegment_;
|
15744 |
|
15745 |
|
15746 | if (!segmentInfo.hasAppendedData_) {
|
15747 | this.metadataQueue_.caption.push(this.handleCaptions_.bind(this, simpleSegment, captionData));
|
15748 | return;
|
15749 | }
|
15750 |
|
15751 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
15752 | var captionTracks = {};
|
15753 |
|
15754 | captionData.forEach(function (caption) {
|
15755 |
|
15756 |
|
15757 | captionTracks[caption.stream] = captionTracks[caption.stream] || {
|
15758 |
|
15759 | startTime: Infinity,
|
15760 | captions: [],
|
15761 |
|
15762 | endTime: 0
|
15763 | };
|
15764 | var captionTrack = captionTracks[caption.stream];
|
15765 | captionTrack.startTime = Math.min(captionTrack.startTime, caption.startTime + timestampOffset);
|
15766 | captionTrack.endTime = Math.max(captionTrack.endTime, caption.endTime + timestampOffset);
|
15767 | captionTrack.captions.push(caption);
|
15768 | });
|
15769 | Object.keys(captionTracks).forEach(function (trackName) {
|
15770 | var _captionTracks$trackN = captionTracks[trackName],
|
15771 | startTime = _captionTracks$trackN.startTime,
|
15772 | endTime = _captionTracks$trackN.endTime,
|
15773 | captions = _captionTracks$trackN.captions;
|
15774 | var inbandTextTracks = _this3.inbandTextTracks_;
|
15775 |
|
15776 | _this3.logger_("adding cues from " + startTime + " -> " + endTime + " for " + trackName);
|
15777 |
|
15778 | createCaptionsTrackIfNotExists(inbandTextTracks, _this3.vhs_.tech_, trackName);
|
15779 |
|
15780 |
|
15781 |
|
15782 |
|
15783 | removeCuesFromTrack(startTime, endTime, inbandTextTracks[trackName]);
|
15784 | addCaptionData({
|
15785 | captionArray: captions,
|
15786 | inbandTextTracks: inbandTextTracks,
|
15787 | timestampOffset: timestampOffset
|
15788 | });
|
15789 | });
|
15790 |
|
15791 |
|
15792 | if (this.transmuxer_) {
|
15793 | this.transmuxer_.postMessage({
|
15794 | action: 'clearParsedMp4Captions'
|
15795 | });
|
15796 | }
|
15797 | };
|
15798 |
|
15799 | _proto.handleId3_ = function handleId3_(simpleSegment, id3Frames, dispatchType) {
|
15800 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
15801 |
|
15802 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15803 | return;
|
15804 | }
|
15805 |
|
15806 | var segmentInfo = this.pendingSegment_;
|
15807 |
|
15808 | if (!segmentInfo.hasAppendedData_) {
|
15809 | this.metadataQueue_.id3.push(this.handleId3_.bind(this, simpleSegment, id3Frames, dispatchType));
|
15810 | return;
|
15811 | }
|
15812 |
|
15813 | var timestampOffset = this.sourceUpdater_.videoTimestampOffset() === null ? this.sourceUpdater_.audioTimestampOffset() : this.sourceUpdater_.videoTimestampOffset();
|
15814 |
|
15815 |
|
15816 |
|
15817 | createMetadataTrackIfNotExists(this.inbandTextTracks_, dispatchType, this.vhs_.tech_);
|
15818 | addMetadata({
|
15819 | inbandTextTracks: this.inbandTextTracks_,
|
15820 | metadataArray: id3Frames,
|
15821 | timestampOffset: timestampOffset,
|
15822 | videoDuration: this.duration_()
|
15823 | });
|
15824 | };
|
15825 |
|
15826 | _proto.processMetadataQueue_ = function processMetadataQueue_() {
|
15827 | this.metadataQueue_.id3.forEach(function (fn) {
|
15828 | return fn();
|
15829 | });
|
15830 | this.metadataQueue_.caption.forEach(function (fn) {
|
15831 | return fn();
|
15832 | });
|
15833 | this.metadataQueue_.id3 = [];
|
15834 | this.metadataQueue_.caption = [];
|
15835 | };
|
15836 |
|
15837 | _proto.processCallQueue_ = function processCallQueue_() {
|
15838 | var callQueue = this.callQueue_;
|
15839 |
|
15840 |
|
15841 |
|
15842 | this.callQueue_ = [];
|
15843 | callQueue.forEach(function (fun) {
|
15844 | return fun();
|
15845 | });
|
15846 | };
|
15847 |
|
15848 | _proto.processLoadQueue_ = function processLoadQueue_() {
|
15849 | var loadQueue = this.loadQueue_;
|
15850 |
|
15851 |
|
15852 |
|
15853 | this.loadQueue_ = [];
|
15854 | loadQueue.forEach(function (fun) {
|
15855 | return fun();
|
15856 | });
|
15857 | }
|
15858 | |
15859 |
|
15860 |
|
15861 |
|
15862 |
|
15863 |
|
15864 | ;
|
15865 |
|
15866 | _proto.hasEnoughInfoToLoad_ = function hasEnoughInfoToLoad_() {
|
15867 |
|
15868 |
|
15869 | if (this.loaderType_ !== 'audio') {
|
15870 | return true;
|
15871 | }
|
15872 |
|
15873 | var segmentInfo = this.pendingSegment_;
|
15874 |
|
15875 |
|
15876 | if (!segmentInfo) {
|
15877 | return false;
|
15878 | }
|
15879 |
|
15880 |
|
15881 |
|
15882 |
|
15883 |
|
15884 | if (!this.currentMediaInfo_) {
|
15885 | return true;
|
15886 | }
|
15887 |
|
15888 | if (
|
15889 |
|
15890 |
|
15891 |
|
15892 |
|
15893 |
|
15894 |
|
15895 |
|
15896 |
|
15897 |
|
15898 |
|
15899 |
|
15900 |
|
15901 |
|
15902 |
|
15903 | shouldWaitForTimelineChange({
|
15904 | timelineChangeController: this.timelineChangeController_,
|
15905 | currentTimeline: this.currentTimeline_,
|
15906 | segmentTimeline: segmentInfo.timeline,
|
15907 | loaderType: this.loaderType_,
|
15908 | audioDisabled: this.audioDisabled_
|
15909 | })) {
|
15910 | return false;
|
15911 | }
|
15912 |
|
15913 | return true;
|
15914 | };
|
15915 |
|
15916 | _proto.hasEnoughInfoToAppend_ = function hasEnoughInfoToAppend_() {
|
15917 | if (!this.sourceUpdater_.ready()) {
|
15918 | return false;
|
15919 | }
|
15920 |
|
15921 |
|
15922 |
|
15923 | if (this.waitingOnRemove_ || this.quotaExceededErrorRetryTimeout_) {
|
15924 | return false;
|
15925 | }
|
15926 |
|
15927 | var segmentInfo = this.pendingSegment_;
|
15928 |
|
15929 |
|
15930 |
|
15931 | if (!segmentInfo || !segmentInfo.trackInfo) {
|
15932 | return false;
|
15933 | }
|
15934 |
|
15935 | if (!this.handlePartialData_) {
|
15936 | var _this$currentMediaInf = this.currentMediaInfo_,
|
15937 | hasAudio = _this$currentMediaInf.hasAudio,
|
15938 | hasVideo = _this$currentMediaInf.hasVideo,
|
15939 | isMuxed = _this$currentMediaInf.isMuxed;
|
15940 |
|
15941 | if (hasVideo && !segmentInfo.videoTimingInfo) {
|
15942 | return false;
|
15943 | }
|
15944 |
|
15945 |
|
15946 | if (hasAudio && !this.audioDisabled_ && !isMuxed && !segmentInfo.audioTimingInfo) {
|
15947 | return false;
|
15948 | }
|
15949 | }
|
15950 |
|
15951 | if (shouldWaitForTimelineChange({
|
15952 | timelineChangeController: this.timelineChangeController_,
|
15953 | currentTimeline: this.currentTimeline_,
|
15954 | segmentTimeline: segmentInfo.timeline,
|
15955 | loaderType: this.loaderType_,
|
15956 | audioDisabled: this.audioDisabled_
|
15957 | })) {
|
15958 | return false;
|
15959 | }
|
15960 |
|
15961 | return true;
|
15962 | };
|
15963 |
|
15964 | _proto.handleData_ = function handleData_(simpleSegment, result) {
|
15965 | this.earlyAbortWhenNeeded_(simpleSegment.stats);
|
15966 |
|
15967 | if (this.checkForAbort_(simpleSegment.requestId)) {
|
15968 | return;
|
15969 | }
|
15970 |
|
15971 |
|
15972 |
|
15973 | if (this.callQueue_.length || !this.hasEnoughInfoToAppend_()) {
|
15974 | this.callQueue_.push(this.handleData_.bind(this, simpleSegment, result));
|
15975 | return;
|
15976 | }
|
15977 |
|
15978 | var segmentInfo = this.pendingSegment_;
|
15979 |
|
15980 | this.setTimeMapping_(segmentInfo.timeline);
|
15981 |
|
15982 | this.updateMediaSecondsLoaded_(segmentInfo.segment);
|
15983 |
|
15984 |
|
15985 |
|
15986 |
|
15987 |
|
15988 | if (this.mediaSource_.readyState === 'closed') {
|
15989 | return;
|
15990 | }
|
15991 |
|
15992 |
|
15993 |
|
15994 | if (simpleSegment.map) {
|
15995 | simpleSegment.map = this.initSegmentForMap(simpleSegment.map, true);
|
15996 |
|
15997 | segmentInfo.segment.map = simpleSegment.map;
|
15998 | }
|
15999 |
|
16000 |
|
16001 | if (simpleSegment.key) {
|
16002 | this.segmentKey(simpleSegment.key, true);
|
16003 | }
|
16004 |
|
16005 | segmentInfo.isFmp4 = simpleSegment.isFmp4;
|
16006 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
16007 |
|
16008 | if (segmentInfo.isFmp4) {
|
16009 | this.trigger('fmp4');
|
16010 | segmentInfo.timingInfo.start = segmentInfo[timingInfoPropertyForMedia(result.type)].start;
|
16011 | } else {
|
16012 | var useVideoTimingInfo = this.loaderType_ === 'main' && this.currentMediaInfo_.hasVideo;
|
16013 | var firstVideoFrameTimeForData;
|
16014 |
|
16015 | if (useVideoTimingInfo) {
|
16016 | firstVideoFrameTimeForData = this.handlePartialData_ ? result.videoFramePtsTime : segmentInfo.videoTimingInfo.start;
|
16017 | }
|
16018 |
|
16019 |
|
16020 |
|
16021 |
|
16022 | segmentInfo.timingInfo.start = this.trueSegmentStart_({
|
16023 | currentStart: segmentInfo.timingInfo.start,
|
16024 | playlist: segmentInfo.playlist,
|
16025 | mediaIndex: segmentInfo.mediaIndex,
|
16026 | currentVideoTimestampOffset: this.sourceUpdater_.videoTimestampOffset(),
|
16027 | useVideoTimingInfo: useVideoTimingInfo,
|
16028 | firstVideoFrameTimeForData: firstVideoFrameTimeForData,
|
16029 | videoTimingInfo: segmentInfo.videoTimingInfo,
|
16030 | audioTimingInfo: segmentInfo.audioTimingInfo
|
16031 | });
|
16032 | }
|
16033 |
|
16034 |
|
16035 |
|
16036 |
|
16037 | this.updateAppendInitSegmentStatus(segmentInfo, result.type);
|
16038 |
|
16039 |
|
16040 |
|
16041 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
16042 |
|
16043 |
|
16044 |
|
16045 |
|
16046 | segmentInfo.hasAppendedData_ = true;
|
16047 |
|
16048 | this.processMetadataQueue_();
|
16049 | this.appendData_(segmentInfo, result);
|
16050 | };
|
16051 |
|
16052 | _proto.updateAppendInitSegmentStatus = function updateAppendInitSegmentStatus(segmentInfo, type) {
|
16053 |
|
16054 | if (this.loaderType_ === 'main' && typeof segmentInfo.timestampOffset === 'number' &&
|
16055 |
|
16056 | !segmentInfo.changedTimestampOffset) {
|
16057 |
|
16058 |
|
16059 | this.appendInitSegment_ = {
|
16060 | audio: true,
|
16061 | video: true
|
16062 | };
|
16063 | }
|
16064 |
|
16065 | if (this.playlistOfLastInitSegment_[type] !== segmentInfo.playlist) {
|
16066 |
|
16067 |
|
16068 | this.appendInitSegment_[type] = true;
|
16069 | }
|
16070 | };
|
16071 |
|
16072 | _proto.getInitSegmentAndUpdateState_ = function getInitSegmentAndUpdateState_(_ref4) {
|
16073 | var type = _ref4.type,
|
16074 | initSegment = _ref4.initSegment,
|
16075 | map = _ref4.map,
|
16076 | playlist = _ref4.playlist;
|
16077 |
|
16078 |
|
16079 |
|
16080 |
|
16081 |
|
16082 |
|
16083 | if (map) {
|
16084 | var id = initSegmentId(map);
|
16085 |
|
16086 | if (this.activeInitSegmentId_ === id) {
|
16087 |
|
16088 | return null;
|
16089 | }
|
16090 |
|
16091 |
|
16092 |
|
16093 |
|
16094 |
|
16095 | initSegment = this.initSegmentForMap(map, true).bytes;
|
16096 | this.activeInitSegmentId_ = id;
|
16097 | }
|
16098 |
|
16099 |
|
16100 |
|
16101 |
|
16102 |
|
16103 |
|
16104 | if (initSegment && this.appendInitSegment_[type]) {
|
16105 |
|
16106 |
|
16107 |
|
16108 | this.playlistOfLastInitSegment_[type] = playlist;
|
16109 |
|
16110 |
|
16111 | this.appendInitSegment_[type] = map ? true : false;
|
16112 |
|
16113 |
|
16114 | this.activeInitSegmentId_ = null;
|
16115 | return initSegment;
|
16116 | }
|
16117 |
|
16118 | return null;
|
16119 | };
|
16120 |
|
16121 | _proto.handleQuotaExceededError_ = function handleQuotaExceededError_(_ref5, error) {
|
16122 | var _this4 = this;
|
16123 |
|
16124 | var segmentInfo = _ref5.segmentInfo,
|
16125 | type = _ref5.type,
|
16126 | bytes = _ref5.bytes;
|
16127 | var audioBuffered = this.sourceUpdater_.audioBuffered();
|
16128 | var videoBuffered = this.sourceUpdater_.videoBuffered();
|
16129 |
|
16130 |
|
16131 |
|
16132 | if (audioBuffered.length > 1) {
|
16133 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the audio buffer: ' + timeRangesToArray(audioBuffered).join(', '));
|
16134 | }
|
16135 |
|
16136 | if (videoBuffered.length > 1) {
|
16137 | this.logger_('On QUOTA_EXCEEDED_ERR, found gaps in the video buffer: ' + timeRangesToArray(videoBuffered).join(', '));
|
16138 | }
|
16139 |
|
16140 | var audioBufferStart = audioBuffered.length ? audioBuffered.start(0) : 0;
|
16141 | var audioBufferEnd = audioBuffered.length ? audioBuffered.end(audioBuffered.length - 1) : 0;
|
16142 | var videoBufferStart = videoBuffered.length ? videoBuffered.start(0) : 0;
|
16143 | var videoBufferEnd = videoBuffered.length ? videoBuffered.end(videoBuffered.length - 1) : 0;
|
16144 |
|
16145 | if (audioBufferEnd - audioBufferStart <= MIN_BACK_BUFFER && videoBufferEnd - videoBufferStart <= MIN_BACK_BUFFER) {
|
16146 |
|
16147 |
|
16148 |
|
16149 |
|
16150 | 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(', ') + ", "));
|
16151 | this.error({
|
16152 | message: 'Quota exceeded error with append of a single segment of content',
|
16153 |
|
16154 |
|
16155 | blacklistDuration: Infinity
|
16156 | });
|
16157 | this.trigger('error');
|
16158 | return;
|
16159 | }
|
16160 |
|
16161 |
|
16162 |
|
16163 |
|
16164 |
|
16165 |
|
16166 |
|
16167 |
|
16168 |
|
16169 |
|
16170 |
|
16171 |
|
16172 |
|
16173 | this.waitingOnRemove_ = true;
|
16174 | this.callQueue_.push(this.appendToSourceBuffer_.bind(this, {
|
16175 | segmentInfo: segmentInfo,
|
16176 | type: type,
|
16177 | bytes: bytes
|
16178 | }));
|
16179 | var currentTime = this.currentTime_();
|
16180 |
|
16181 |
|
16182 | var timeToRemoveUntil = currentTime - MIN_BACK_BUFFER;
|
16183 | this.logger_("On QUOTA_EXCEEDED_ERR, removing audio/video from 0 to " + timeToRemoveUntil);
|
16184 | this.remove(0, timeToRemoveUntil, function () {
|
16185 | _this4.logger_("On QUOTA_EXCEEDED_ERR, retrying append in " + MIN_BACK_BUFFER + "s");
|
16186 |
|
16187 | _this4.waitingOnRemove_ = false;
|
16188 |
|
16189 |
|
16190 | _this4.quotaExceededErrorRetryTimeout_ = window__default['default'].setTimeout(function () {
|
16191 | _this4.logger_('On QUOTA_EXCEEDED_ERR, re-processing call queue');
|
16192 |
|
16193 | _this4.quotaExceededErrorRetryTimeout_ = null;
|
16194 |
|
16195 | _this4.processCallQueue_();
|
16196 | }, MIN_BACK_BUFFER * 1000);
|
16197 | }, true);
|
16198 | };
|
16199 |
|
16200 | _proto.handleAppendError_ = function handleAppendError_(_ref6, error) {
|
16201 | var segmentInfo = _ref6.segmentInfo,
|
16202 | type = _ref6.type,
|
16203 | bytes = _ref6.bytes;
|
16204 |
|
16205 |
|
16206 | if (!error) {
|
16207 | return;
|
16208 | }
|
16209 |
|
16210 | if (error.code === QUOTA_EXCEEDED_ERR) {
|
16211 | this.handleQuotaExceededError_({
|
16212 | segmentInfo: segmentInfo,
|
16213 | type: type,
|
16214 | bytes: bytes
|
16215 | });
|
16216 |
|
16217 |
|
16218 | return;
|
16219 | }
|
16220 |
|
16221 | this.logger_('Received non QUOTA_EXCEEDED_ERR on append', error);
|
16222 | this.error(type + " append of " + bytes.length + "b failed for segment " + ("#" + segmentInfo.mediaIndex + " in playlist " + segmentInfo.playlist.id));
|
16223 |
|
16224 |
|
16225 |
|
16226 |
|
16227 |
|
16228 | this.trigger('appenderror');
|
16229 | };
|
16230 |
|
16231 | _proto.appendToSourceBuffer_ = function appendToSourceBuffer_(_ref7) {
|
16232 | var segmentInfo = _ref7.segmentInfo,
|
16233 | type = _ref7.type,
|
16234 | initSegment = _ref7.initSegment,
|
16235 | data = _ref7.data,
|
16236 | bytes = _ref7.bytes;
|
16237 |
|
16238 |
|
16239 | if (!bytes) {
|
16240 | var segments = [data];
|
16241 | var byteLength = data.byteLength;
|
16242 |
|
16243 | if (initSegment) {
|
16244 |
|
16245 |
|
16246 | segments.unshift(initSegment);
|
16247 | byteLength += initSegment.byteLength;
|
16248 | }
|
16249 |
|
16250 |
|
16251 |
|
16252 | bytes = concatSegments({
|
16253 | bytes: byteLength,
|
16254 | segments: segments
|
16255 | });
|
16256 | }
|
16257 |
|
16258 | this.sourceUpdater_.appendBuffer({
|
16259 | segmentInfo: segmentInfo,
|
16260 | type: type,
|
16261 | bytes: bytes
|
16262 | }, this.handleAppendError_.bind(this, {
|
16263 | segmentInfo: segmentInfo,
|
16264 | type: type,
|
16265 | bytes: bytes
|
16266 | }));
|
16267 | };
|
16268 |
|
16269 | _proto.handleSegmentTimingInfo_ = function handleSegmentTimingInfo_(type, requestId, segmentTimingInfo) {
|
16270 | if (!this.pendingSegment_ || requestId !== this.pendingSegment_.requestId) {
|
16271 | return;
|
16272 | }
|
16273 |
|
16274 | var segment = this.pendingSegment_.segment;
|
16275 | var timingInfoProperty = type + "TimingInfo";
|
16276 |
|
16277 | if (!segment[timingInfoProperty]) {
|
16278 | segment[timingInfoProperty] = {};
|
16279 | }
|
16280 |
|
16281 | segment[timingInfoProperty].transmuxerPrependedSeconds = segmentTimingInfo.prependedContentDuration || 0;
|
16282 | segment[timingInfoProperty].transmuxedPresentationStart = segmentTimingInfo.start.presentation;
|
16283 | segment[timingInfoProperty].transmuxedDecodeStart = segmentTimingInfo.start.decode;
|
16284 | segment[timingInfoProperty].transmuxedPresentationEnd = segmentTimingInfo.end.presentation;
|
16285 | segment[timingInfoProperty].transmuxedDecodeEnd = segmentTimingInfo.end.decode;
|
16286 |
|
16287 | segment[timingInfoProperty].baseMediaDecodeTime = segmentTimingInfo.baseMediaDecodeTime;
|
16288 | };
|
16289 |
|
16290 | _proto.appendData_ = function appendData_(segmentInfo, result) {
|
16291 | var type = result.type,
|
16292 | data = result.data;
|
16293 |
|
16294 | if (!data || !data.byteLength) {
|
16295 | return;
|
16296 | }
|
16297 |
|
16298 | if (type === 'audio' && this.audioDisabled_) {
|
16299 | return;
|
16300 | }
|
16301 |
|
16302 | var initSegment = this.getInitSegmentAndUpdateState_({
|
16303 | type: type,
|
16304 | initSegment: result.initSegment,
|
16305 | playlist: segmentInfo.playlist,
|
16306 | map: segmentInfo.isFmp4 ? segmentInfo.segment.map : null
|
16307 | });
|
16308 | this.appendToSourceBuffer_({
|
16309 | segmentInfo: segmentInfo,
|
16310 | type: type,
|
16311 | initSegment: initSegment,
|
16312 | data: data
|
16313 | });
|
16314 | }
|
16315 | |
16316 |
|
16317 |
|
16318 |
|
16319 |
|
16320 | ;
|
16321 |
|
16322 | _proto.loadSegment_ = function loadSegment_(segmentInfo) {
|
16323 | var _this5 = this;
|
16324 |
|
16325 | this.state = 'WAITING';
|
16326 | this.pendingSegment_ = segmentInfo;
|
16327 | this.trimBackBuffer_(segmentInfo);
|
16328 |
|
16329 | if (typeof segmentInfo.timestampOffset === 'number') {
|
16330 | if (this.transmuxer_) {
|
16331 | this.transmuxer_.postMessage({
|
16332 | action: 'clearAllMp4Captions'
|
16333 | });
|
16334 | }
|
16335 | }
|
16336 |
|
16337 | if (!this.hasEnoughInfoToLoad_()) {
|
16338 | this.loadQueue_.push(function () {
|
16339 | var buffered = _this5.buffered_();
|
16340 |
|
16341 | if (typeof segmentInfo.timestampOffset === 'number') {
|
16342 |
|
16343 |
|
16344 |
|
16345 |
|
16346 |
|
16347 |
|
16348 |
|
16349 |
|
16350 |
|
16351 | segmentInfo.timestampOffset = timestampOffsetForSegment({
|
16352 | segmentTimeline: segmentInfo.timeline,
|
16353 | currentTimeline: _this5.currentTimeline_,
|
16354 | startOfSegment: segmentInfo.startOfSegment,
|
16355 | buffered: buffered,
|
16356 | overrideCheck: true
|
16357 | });
|
16358 | }
|
16359 |
|
16360 | delete segmentInfo.audioAppendStart;
|
16361 |
|
16362 | var audioBuffered = _this5.sourceUpdater_.audioBuffered();
|
16363 |
|
16364 | if (audioBuffered.length) {
|
16365 |
|
16366 |
|
16367 |
|
16368 |
|
16369 |
|
16370 | segmentInfo.audioAppendStart = audioBuffered.end(audioBuffered.length - 1) - _this5.sourceUpdater_.audioTimestampOffset();
|
16371 | }
|
16372 |
|
16373 | _this5.updateTransmuxerAndRequestSegment_(segmentInfo);
|
16374 | });
|
16375 | return;
|
16376 | }
|
16377 |
|
16378 | this.updateTransmuxerAndRequestSegment_(segmentInfo);
|
16379 | };
|
16380 |
|
16381 | _proto.updateTransmuxerAndRequestSegment_ = function updateTransmuxerAndRequestSegment_(segmentInfo) {
|
16382 | var _this6 = this;
|
16383 |
|
16384 |
|
16385 |
|
16386 |
|
16387 |
|
16388 |
|
16389 | if (this.shouldUpdateTransmuxerTimestampOffset_(segmentInfo.timestampOffset)) {
|
16390 | this.gopBuffer_.length = 0;
|
16391 |
|
16392 | segmentInfo.gopsToAlignWith = [];
|
16393 | this.timeMapping_ = 0;
|
16394 |
|
16395 | this.transmuxer_.postMessage({
|
16396 | action: 'reset'
|
16397 | });
|
16398 | this.transmuxer_.postMessage({
|
16399 | action: 'setTimestampOffset',
|
16400 | timestampOffset: segmentInfo.timestampOffset
|
16401 | });
|
16402 | }
|
16403 |
|
16404 | var simpleSegment = this.createSimplifiedSegmentObj_(segmentInfo);
|
16405 | var isEndOfStream = this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex);
|
16406 | var isWalkingForward = this.mediaIndex !== null;
|
16407 | var isDiscontinuity = segmentInfo.timeline !== this.currentTimeline_ &&
|
16408 |
|
16409 | segmentInfo.timeline > 0;
|
16410 | var isEndOfTimeline = isEndOfStream || isWalkingForward && isDiscontinuity;
|
16411 | this.logger_("Requesting " + segmentInfoString(segmentInfo));
|
16412 | segmentInfo.abortRequests = mediaSegmentRequest({
|
16413 | xhr: this.vhs_.xhr,
|
16414 | xhrOptions: this.xhrOptions_,
|
16415 | decryptionWorker: this.decrypter_,
|
16416 | segment: simpleSegment,
|
16417 | handlePartialData: this.handlePartialData_,
|
16418 | abortFn: this.handleAbort_.bind(this, segmentInfo),
|
16419 | progressFn: this.handleProgress_.bind(this),
|
16420 | trackInfoFn: this.handleTrackInfo_.bind(this),
|
16421 | timingInfoFn: this.handleTimingInfo_.bind(this),
|
16422 | videoSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'video', segmentInfo.requestId),
|
16423 | audioSegmentTimingInfoFn: this.handleSegmentTimingInfo_.bind(this, 'audio', segmentInfo.requestId),
|
16424 | captionsFn: this.handleCaptions_.bind(this),
|
16425 | isEndOfTimeline: isEndOfTimeline,
|
16426 | endedTimelineFn: function endedTimelineFn() {
|
16427 | _this6.logger_('received endedtimeline callback');
|
16428 | },
|
16429 | id3Fn: this.handleId3_.bind(this),
|
16430 | dataFn: this.handleData_.bind(this),
|
16431 | doneFn: this.segmentRequestFinished_.bind(this)
|
16432 | });
|
16433 | }
|
16434 | |
16435 |
|
16436 |
|
16437 |
|
16438 |
|
16439 |
|
16440 |
|
16441 |
|
16442 | ;
|
16443 |
|
16444 | _proto.trimBackBuffer_ = function trimBackBuffer_(segmentInfo) {
|
16445 | var removeToTime = safeBackBufferTrimTime(this.seekable_(), this.currentTime_(), this.playlist_.targetDuration || 10);
|
16446 |
|
16447 |
|
16448 |
|
16449 |
|
16450 |
|
16451 | if (removeToTime > 0) {
|
16452 | this.remove(0, removeToTime);
|
16453 | }
|
16454 | }
|
16455 | |
16456 |
|
16457 |
|
16458 |
|
16459 |
|
16460 |
|
16461 |
|
16462 |
|
16463 |
|
16464 | ;
|
16465 |
|
16466 | _proto.createSimplifiedSegmentObj_ = function createSimplifiedSegmentObj_(segmentInfo) {
|
16467 | var segment = segmentInfo.segment;
|
16468 | var part = segmentInfo.part;
|
16469 | var simpleSegment = {
|
16470 | resolvedUri: part ? part.resolvedUri : segment.resolvedUri,
|
16471 | byterange: part ? part.byterange : segment.byterange,
|
16472 | requestId: segmentInfo.requestId,
|
16473 | transmuxer: segmentInfo.transmuxer,
|
16474 | audioAppendStart: segmentInfo.audioAppendStart,
|
16475 | gopsToAlignWith: segmentInfo.gopsToAlignWith,
|
16476 | part: segmentInfo.part
|
16477 | };
|
16478 | var previousSegment = segmentInfo.playlist.segments[segmentInfo.mediaIndex - 1];
|
16479 |
|
16480 | if (previousSegment && previousSegment.timeline === segment.timeline) {
|
16481 |
|
16482 |
|
16483 |
|
16484 |
|
16485 |
|
16486 |
|
16487 |
|
16488 |
|
16489 | if (previousSegment.videoTimingInfo) {
|
16490 | simpleSegment.baseStartTime = previousSegment.videoTimingInfo.transmuxedDecodeEnd;
|
16491 | } else if (previousSegment.audioTimingInfo) {
|
16492 | simpleSegment.baseStartTime = previousSegment.audioTimingInfo.transmuxedDecodeEnd;
|
16493 | }
|
16494 | }
|
16495 |
|
16496 | if (segment.key) {
|
16497 |
|
16498 |
|
16499 | var iv = segment.key.iv || new Uint32Array([0, 0, 0, segmentInfo.mediaIndex + segmentInfo.playlist.mediaSequence]);
|
16500 | simpleSegment.key = this.segmentKey(segment.key);
|
16501 | simpleSegment.key.iv = iv;
|
16502 | }
|
16503 |
|
16504 | if (segment.map) {
|
16505 | simpleSegment.map = this.initSegmentForMap(segment.map);
|
16506 | }
|
16507 |
|
16508 | return simpleSegment;
|
16509 | };
|
16510 |
|
16511 | _proto.saveTransferStats_ = function saveTransferStats_(stats) {
|
16512 |
|
16513 |
|
16514 | this.mediaRequests += 1;
|
16515 |
|
16516 | if (stats) {
|
16517 | this.mediaBytesTransferred += stats.bytesReceived;
|
16518 | this.mediaTransferDuration += stats.roundTripTime;
|
16519 | }
|
16520 | };
|
16521 |
|
16522 | _proto.saveBandwidthRelatedStats_ = function saveBandwidthRelatedStats_(duration, stats) {
|
16523 |
|
16524 |
|
16525 |
|
16526 | this.pendingSegment_.byteLength = stats.bytesReceived;
|
16527 |
|
16528 | if (duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
16529 | this.logger_("Ignoring segment's bandwidth because its duration of " + duration + (" is less than the min to record " + MIN_SEGMENT_DURATION_TO_SAVE_STATS));
|
16530 | return;
|
16531 | }
|
16532 |
|
16533 | this.bandwidth = stats.bandwidth;
|
16534 | this.roundTrip = stats.roundTripTime;
|
16535 | };
|
16536 |
|
16537 | _proto.handleTimeout_ = function handleTimeout_() {
|
16538 |
|
16539 |
|
16540 | this.mediaRequestsTimedout += 1;
|
16541 | this.bandwidth = 1;
|
16542 | this.roundTrip = NaN;
|
16543 | this.trigger('bandwidthupdate');
|
16544 | }
|
16545 | |
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 | ;
|
16552 |
|
16553 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
16554 |
|
16555 |
|
16556 |
|
16557 |
|
16558 | if (this.callQueue_.length) {
|
16559 | this.callQueue_.push(this.segmentRequestFinished_.bind(this, error, simpleSegment, result));
|
16560 | return;
|
16561 | }
|
16562 |
|
16563 | this.saveTransferStats_(simpleSegment.stats);
|
16564 |
|
16565 | if (!this.pendingSegment_) {
|
16566 | return;
|
16567 | }
|
16568 |
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 | if (simpleSegment.requestId !== this.pendingSegment_.requestId) {
|
16574 | return;
|
16575 | }
|
16576 |
|
16577 |
|
16578 | if (error) {
|
16579 | this.pendingSegment_ = null;
|
16580 | this.state = 'READY';
|
16581 |
|
16582 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
16583 | return;
|
16584 | }
|
16585 |
|
16586 | this.pause();
|
16587 |
|
16588 |
|
16589 |
|
16590 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
16591 | this.handleTimeout_();
|
16592 | return;
|
16593 | }
|
16594 |
|
16595 |
|
16596 |
|
16597 | this.mediaRequestsErrored += 1;
|
16598 | this.error(error);
|
16599 | this.trigger('error');
|
16600 | return;
|
16601 | }
|
16602 |
|
16603 | var segmentInfo = this.pendingSegment_;
|
16604 |
|
16605 |
|
16606 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
16607 | segmentInfo.endOfAllRequests = simpleSegment.endOfAllRequests;
|
16608 |
|
16609 | if (result.gopInfo) {
|
16610 | this.gopBuffer_ = updateGopBuffer(this.gopBuffer_, result.gopInfo, this.safeAppend_);
|
16611 | }
|
16612 |
|
16613 |
|
16614 |
|
16615 | this.state = 'APPENDING';
|
16616 |
|
16617 | this.trigger('appending');
|
16618 | this.waitForAppendsToComplete_(segmentInfo);
|
16619 | };
|
16620 |
|
16621 | _proto.setTimeMapping_ = function setTimeMapping_(timeline) {
|
16622 | var timelineMapping = this.syncController_.mappingForTimeline(timeline);
|
16623 |
|
16624 | if (timelineMapping !== null) {
|
16625 | this.timeMapping_ = timelineMapping;
|
16626 | }
|
16627 | };
|
16628 |
|
16629 | _proto.updateMediaSecondsLoaded_ = function updateMediaSecondsLoaded_(segment) {
|
16630 | if (typeof segment.start === 'number' && typeof segment.end === 'number') {
|
16631 | this.mediaSecondsLoaded += segment.end - segment.start;
|
16632 | } else {
|
16633 | this.mediaSecondsLoaded += segment.duration;
|
16634 | }
|
16635 | };
|
16636 |
|
16637 | _proto.shouldUpdateTransmuxerTimestampOffset_ = function shouldUpdateTransmuxerTimestampOffset_(timestampOffset) {
|
16638 | if (timestampOffset === null) {
|
16639 | return false;
|
16640 | }
|
16641 |
|
16642 |
|
16643 |
|
16644 | if (this.loaderType_ === 'main' && timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
16645 | return true;
|
16646 | }
|
16647 |
|
16648 | if (!this.audioDisabled_ && timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
16649 | return true;
|
16650 | }
|
16651 |
|
16652 | return false;
|
16653 | };
|
16654 |
|
16655 | _proto.trueSegmentStart_ = function trueSegmentStart_(_ref8) {
|
16656 | var currentStart = _ref8.currentStart,
|
16657 | playlist = _ref8.playlist,
|
16658 | mediaIndex = _ref8.mediaIndex,
|
16659 | firstVideoFrameTimeForData = _ref8.firstVideoFrameTimeForData,
|
16660 | currentVideoTimestampOffset = _ref8.currentVideoTimestampOffset,
|
16661 | useVideoTimingInfo = _ref8.useVideoTimingInfo,
|
16662 | videoTimingInfo = _ref8.videoTimingInfo,
|
16663 | audioTimingInfo = _ref8.audioTimingInfo;
|
16664 |
|
16665 | if (typeof currentStart !== 'undefined') {
|
16666 |
|
16667 | return currentStart;
|
16668 | }
|
16669 |
|
16670 | if (!useVideoTimingInfo) {
|
16671 | return audioTimingInfo.start;
|
16672 | }
|
16673 |
|
16674 | var previousSegment = playlist.segments[mediaIndex - 1];
|
16675 |
|
16676 |
|
16677 |
|
16678 |
|
16679 |
|
16680 | if (mediaIndex === 0 || !previousSegment || typeof previousSegment.start === 'undefined' || previousSegment.end !== firstVideoFrameTimeForData + currentVideoTimestampOffset) {
|
16681 | return firstVideoFrameTimeForData;
|
16682 | }
|
16683 |
|
16684 | return videoTimingInfo.start;
|
16685 | };
|
16686 |
|
16687 | _proto.waitForAppendsToComplete_ = function waitForAppendsToComplete_(segmentInfo) {
|
16688 | if (!this.currentMediaInfo_) {
|
16689 | this.error({
|
16690 | message: 'No starting media returned, likely due to an unsupported media format.',
|
16691 | blacklistDuration: Infinity
|
16692 | });
|
16693 | this.trigger('error');
|
16694 | return;
|
16695 | }
|
16696 |
|
16697 |
|
16698 |
|
16699 |
|
16700 | var _this$currentMediaInf2 = this.currentMediaInfo_,
|
16701 | hasAudio = _this$currentMediaInf2.hasAudio,
|
16702 | hasVideo = _this$currentMediaInf2.hasVideo,
|
16703 | isMuxed = _this$currentMediaInf2.isMuxed;
|
16704 | var waitForVideo = this.loaderType_ === 'main' && hasVideo;
|
16705 |
|
16706 | var waitForAudio = !this.audioDisabled_ && hasAudio && !isMuxed;
|
16707 | segmentInfo.waitingOnAppends = 0;
|
16708 |
|
16709 | if (!segmentInfo.hasAppendedData_) {
|
16710 | if (!segmentInfo.timingInfo && typeof segmentInfo.timestampOffset === 'number') {
|
16711 |
|
16712 |
|
16713 |
|
16714 |
|
16715 |
|
16716 |
|
16717 |
|
16718 |
|
16719 | this.isPendingTimestampOffset_ = true;
|
16720 | }
|
16721 |
|
16722 |
|
16723 | segmentInfo.timingInfo = {
|
16724 | start: 0
|
16725 | };
|
16726 | segmentInfo.waitingOnAppends++;
|
16727 |
|
16728 | if (!this.isPendingTimestampOffset_) {
|
16729 |
|
16730 | this.updateSourceBufferTimestampOffset_(segmentInfo);
|
16731 |
|
16732 |
|
16733 | this.processMetadataQueue_();
|
16734 | }
|
16735 |
|
16736 |
|
16737 | this.checkAppendsDone_(segmentInfo);
|
16738 | return;
|
16739 | }
|
16740 |
|
16741 |
|
16742 | if (waitForVideo) {
|
16743 | segmentInfo.waitingOnAppends++;
|
16744 | }
|
16745 |
|
16746 | if (waitForAudio) {
|
16747 | segmentInfo.waitingOnAppends++;
|
16748 | }
|
16749 |
|
16750 | if (waitForVideo) {
|
16751 | this.sourceUpdater_.videoQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
16752 | }
|
16753 |
|
16754 | if (waitForAudio) {
|
16755 | this.sourceUpdater_.audioQueueCallback(this.checkAppendsDone_.bind(this, segmentInfo));
|
16756 | }
|
16757 | };
|
16758 |
|
16759 | _proto.checkAppendsDone_ = function checkAppendsDone_(segmentInfo) {
|
16760 | if (this.checkForAbort_(segmentInfo.requestId)) {
|
16761 | return;
|
16762 | }
|
16763 |
|
16764 | segmentInfo.waitingOnAppends--;
|
16765 |
|
16766 | if (segmentInfo.waitingOnAppends === 0) {
|
16767 | this.handleAppendsDone_();
|
16768 | }
|
16769 | };
|
16770 |
|
16771 | _proto.checkForIllegalMediaSwitch = function checkForIllegalMediaSwitch(trackInfo) {
|
16772 | var illegalMediaSwitchError = illegalMediaSwitch(this.loaderType_, this.currentMediaInfo_, trackInfo);
|
16773 |
|
16774 | if (illegalMediaSwitchError) {
|
16775 | this.error({
|
16776 | message: illegalMediaSwitchError,
|
16777 | blacklistDuration: Infinity
|
16778 | });
|
16779 | this.trigger('error');
|
16780 | return true;
|
16781 | }
|
16782 |
|
16783 | return false;
|
16784 | };
|
16785 |
|
16786 | _proto.updateSourceBufferTimestampOffset_ = function updateSourceBufferTimestampOffset_(segmentInfo) {
|
16787 | if (segmentInfo.timestampOffset === null ||
|
16788 |
|
16789 | typeof segmentInfo.timingInfo.start !== 'number' ||
|
16790 | segmentInfo.changedTimestampOffset ||
|
16791 | this.loaderType_ !== 'main') {
|
16792 | return;
|
16793 | }
|
16794 |
|
16795 | var didChange = false;
|
16796 |
|
16797 |
|
16798 |
|
16799 |
|
16800 | segmentInfo.timestampOffset -= segmentInfo.timingInfo.start;
|
16801 |
|
16802 |
|
16803 |
|
16804 | segmentInfo.changedTimestampOffset = true;
|
16805 |
|
16806 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.videoTimestampOffset()) {
|
16807 | this.sourceUpdater_.videoTimestampOffset(segmentInfo.timestampOffset);
|
16808 | didChange = true;
|
16809 | }
|
16810 |
|
16811 | if (segmentInfo.timestampOffset !== this.sourceUpdater_.audioTimestampOffset()) {
|
16812 | this.sourceUpdater_.audioTimestampOffset(segmentInfo.timestampOffset);
|
16813 | didChange = true;
|
16814 | }
|
16815 |
|
16816 | if (didChange) {
|
16817 | this.trigger('timestampoffset');
|
16818 | }
|
16819 | };
|
16820 |
|
16821 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_(segmentInfo) {
|
16822 | segmentInfo.timingInfo = segmentInfo.timingInfo || {};
|
16823 | var useVideoTimingInfo = this.loaderType_ === 'main' && this.currentMediaInfo_.hasVideo;
|
16824 | var prioritizedTimingInfo = useVideoTimingInfo && segmentInfo.videoTimingInfo ? segmentInfo.videoTimingInfo : segmentInfo.audioTimingInfo;
|
16825 |
|
16826 | if (!prioritizedTimingInfo) {
|
16827 | return;
|
16828 | }
|
16829 |
|
16830 | segmentInfo.timingInfo.end = typeof prioritizedTimingInfo.end === 'number' ?
|
16831 |
|
16832 |
|
16833 | prioritizedTimingInfo.end : prioritizedTimingInfo.start + segmentInfo.duration;
|
16834 | }
|
16835 | |
16836 |
|
16837 |
|
16838 |
|
16839 |
|
16840 |
|
16841 |
|
16842 | ;
|
16843 |
|
16844 | _proto.handleAppendsDone_ = function handleAppendsDone_() {
|
16845 |
|
16846 | if (this.pendingSegment_) {
|
16847 | this.trigger('appendsdone');
|
16848 | }
|
16849 |
|
16850 | if (!this.pendingSegment_) {
|
16851 | this.state = 'READY';
|
16852 |
|
16853 |
|
16854 | if (!this.paused()) {
|
16855 | this.monitorBuffer_();
|
16856 | }
|
16857 |
|
16858 | return;
|
16859 | }
|
16860 |
|
16861 | var segmentInfo = this.pendingSegment_;
|
16862 |
|
16863 |
|
16864 |
|
16865 | this.updateTimingInfoEnd_(segmentInfo);
|
16866 |
|
16867 | if (this.shouldSaveSegmentTimingInfo_) {
|
16868 |
|
16869 |
|
16870 |
|
16871 |
|
16872 |
|
16873 |
|
16874 |
|
16875 |
|
16876 |
|
16877 |
|
16878 |
|
16879 |
|
16880 |
|
16881 |
|
16882 |
|
16883 |
|
16884 |
|
16885 | this.syncController_.saveSegmentTimingInfo({
|
16886 | segmentInfo: segmentInfo,
|
16887 | shouldSaveTimelineMapping: this.loaderType_ === 'main'
|
16888 | });
|
16889 | }
|
16890 |
|
16891 | this.logger_("Appended " + segmentInfoString(segmentInfo));
|
16892 | var segmentDurationMessage = getTroublesomeSegmentDurationMessage(segmentInfo, this.sourceType_);
|
16893 |
|
16894 | if (segmentDurationMessage) {
|
16895 | if (segmentDurationMessage.severity === 'warn') {
|
16896 | videojs__default['default'].log.warn(segmentDurationMessage.message);
|
16897 | } else {
|
16898 | this.logger_(segmentDurationMessage.message);
|
16899 | }
|
16900 | }
|
16901 |
|
16902 | this.recordThroughput_(segmentInfo);
|
16903 | this.pendingSegment_ = null;
|
16904 | this.state = 'READY';
|
16905 |
|
16906 |
|
16907 | if (segmentInfo.isSyncRequest) {
|
16908 | this.trigger('syncinfoupdate');
|
16909 | return;
|
16910 | }
|
16911 |
|
16912 | this.addSegmentMetadataCue_(segmentInfo);
|
16913 | this.fetchAtBuffer_ = true;
|
16914 |
|
16915 | if (this.currentTimeline_ !== segmentInfo.timeline) {
|
16916 | this.timelineChangeController_.lastTimelineChange({
|
16917 | type: this.loaderType_,
|
16918 | from: this.currentTimeline_,
|
16919 | to: segmentInfo.timeline
|
16920 | });
|
16921 |
|
16922 |
|
16923 |
|
16924 | if (this.loaderType_ === 'main' && !this.audioDisabled_) {
|
16925 | this.timelineChangeController_.lastTimelineChange({
|
16926 | type: 'audio',
|
16927 | from: this.currentTimeline_,
|
16928 | to: segmentInfo.timeline
|
16929 | });
|
16930 | }
|
16931 | }
|
16932 |
|
16933 | this.currentTimeline_ = segmentInfo.timeline;
|
16934 |
|
16935 |
|
16936 |
|
16937 |
|
16938 | this.trigger('syncinfoupdate');
|
16939 | var segment = segmentInfo.segment;
|
16940 |
|
16941 |
|
16942 |
|
16943 |
|
16944 | if (segment.end && this.currentTime_() - segment.end > segmentInfo.playlist.targetDuration * 3) {
|
16945 | this.resetEverything();
|
16946 | return;
|
16947 | }
|
16948 |
|
16949 | var isWalkingForward = this.mediaIndex !== null;
|
16950 |
|
16951 |
|
16952 | if (isWalkingForward) {
|
16953 | this.trigger('bandwidthupdate');
|
16954 | }
|
16955 |
|
16956 | this.trigger('progress');
|
16957 | this.mediaIndex = segmentInfo.mediaIndex;
|
16958 | this.partIndex = segmentInfo.partIndex;
|
16959 |
|
16960 |
|
16961 |
|
16962 | if (this.isEndOfStream_(segmentInfo.mediaIndex, segmentInfo.playlist, segmentInfo.partIndex)) {
|
16963 | this.endOfStream();
|
16964 | }
|
16965 |
|
16966 |
|
16967 | this.trigger('appended');
|
16968 |
|
16969 | if (!this.paused()) {
|
16970 | this.monitorBuffer_();
|
16971 | }
|
16972 | }
|
16973 | |
16974 |
|
16975 |
|
16976 |
|
16977 |
|
16978 |
|
16979 |
|
16980 |
|
16981 |
|
16982 | ;
|
16983 |
|
16984 | _proto.recordThroughput_ = function recordThroughput_(segmentInfo) {
|
16985 | if (segmentInfo.duration < MIN_SEGMENT_DURATION_TO_SAVE_STATS) {
|
16986 | 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));
|
16987 | return;
|
16988 | }
|
16989 |
|
16990 | var rate = this.throughput.rate;
|
16991 |
|
16992 |
|
16993 | var segmentProcessingTime = Date.now() - segmentInfo.endOfAllRequests + 1;
|
16994 |
|
16995 | var segmentProcessingThroughput = Math.floor(segmentInfo.byteLength / segmentProcessingTime * 8 * 1000);
|
16996 |
|
16997 |
|
16998 | this.throughput.rate += (segmentProcessingThroughput - rate) / ++this.throughput.count;
|
16999 | }
|
17000 | |
17001 |
|
17002 |
|
17003 |
|
17004 |
|
17005 |
|
17006 |
|
17007 |
|
17008 |
|
17009 | ;
|
17010 |
|
17011 | _proto.addSegmentMetadataCue_ = function addSegmentMetadataCue_(segmentInfo) {
|
17012 | if (!this.segmentMetadataTrack_) {
|
17013 | return;
|
17014 | }
|
17015 |
|
17016 | var segment = segmentInfo.segment;
|
17017 | var start = segment.start;
|
17018 | var end = segment.end;
|
17019 |
|
17020 | if (!finite(start) || !finite(end)) {
|
17021 | return;
|
17022 | }
|
17023 |
|
17024 | removeCuesFromTrack(start, end, this.segmentMetadataTrack_);
|
17025 | var Cue = window__default['default'].WebKitDataCue || window__default['default'].VTTCue;
|
17026 | var value = {
|
17027 | custom: segment.custom,
|
17028 | dateTimeObject: segment.dateTimeObject,
|
17029 | dateTimeString: segment.dateTimeString,
|
17030 | bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
|
17031 | resolution: segmentInfo.playlist.attributes.RESOLUTION,
|
17032 | codecs: segmentInfo.playlist.attributes.CODECS,
|
17033 | byteLength: segmentInfo.byteLength,
|
17034 | uri: segmentInfo.uri,
|
17035 | timeline: segmentInfo.timeline,
|
17036 | playlist: segmentInfo.playlist.id,
|
17037 | start: start,
|
17038 | end: end
|
17039 | };
|
17040 | var data = JSON.stringify(value);
|
17041 | var cue = new Cue(start, end, data);
|
17042 |
|
17043 |
|
17044 | cue.value = value;
|
17045 | this.segmentMetadataTrack_.addCue(cue);
|
17046 | };
|
17047 |
|
17048 | return SegmentLoader;
|
17049 | }(videojs__default['default'].EventTarget);
|
17050 |
|
17051 | function noop() {}
|
17052 |
|
17053 | var toTitleCase = function toTitleCase(string) {
|
17054 | if (typeof string !== 'string') {
|
17055 | return string;
|
17056 | }
|
17057 |
|
17058 | return string.replace(/./, function (w) {
|
17059 | return w.toUpperCase();
|
17060 | });
|
17061 | };
|
17062 |
|
17063 | var bufferTypes = ['video', 'audio'];
|
17064 |
|
17065 | var _updating = function updating(type, sourceUpdater) {
|
17066 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17067 | return sourceBuffer && sourceBuffer.updating || sourceUpdater.queuePending[type];
|
17068 | };
|
17069 |
|
17070 | var nextQueueIndexOfType = function nextQueueIndexOfType(type, queue) {
|
17071 | for (var i = 0; i < queue.length; i++) {
|
17072 | var queueEntry = queue[i];
|
17073 |
|
17074 | if (queueEntry.type === 'mediaSource') {
|
17075 |
|
17076 |
|
17077 | return null;
|
17078 | }
|
17079 |
|
17080 | if (queueEntry.type === type) {
|
17081 | return i;
|
17082 | }
|
17083 | }
|
17084 |
|
17085 | return null;
|
17086 | };
|
17087 |
|
17088 | var shiftQueue = function shiftQueue(type, sourceUpdater) {
|
17089 | if (sourceUpdater.queue.length === 0) {
|
17090 | return;
|
17091 | }
|
17092 |
|
17093 | var queueIndex = 0;
|
17094 | var queueEntry = sourceUpdater.queue[queueIndex];
|
17095 |
|
17096 | if (queueEntry.type === 'mediaSource') {
|
17097 | if (!sourceUpdater.updating() && sourceUpdater.mediaSource.readyState !== 'closed') {
|
17098 | sourceUpdater.queue.shift();
|
17099 | queueEntry.action(sourceUpdater);
|
17100 |
|
17101 | if (queueEntry.doneFn) {
|
17102 | queueEntry.doneFn();
|
17103 | }
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 | shiftQueue('audio', sourceUpdater);
|
17109 | shiftQueue('video', sourceUpdater);
|
17110 | }
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 | return;
|
17116 | }
|
17117 |
|
17118 | if (type === 'mediaSource') {
|
17119 |
|
17120 |
|
17121 |
|
17122 |
|
17123 | return;
|
17124 | }
|
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 | if (!sourceUpdater.ready() || sourceUpdater.mediaSource.readyState === 'closed' || _updating(type, sourceUpdater)) {
|
17130 | return;
|
17131 | }
|
17132 |
|
17133 | if (queueEntry.type !== type) {
|
17134 | queueIndex = nextQueueIndexOfType(type, sourceUpdater.queue);
|
17135 |
|
17136 | if (queueIndex === null) {
|
17137 |
|
17138 |
|
17139 |
|
17140 | return;
|
17141 | }
|
17142 |
|
17143 | queueEntry = sourceUpdater.queue[queueIndex];
|
17144 | }
|
17145 |
|
17146 | sourceUpdater.queue.splice(queueIndex, 1);
|
17147 |
|
17148 |
|
17149 |
|
17150 |
|
17151 |
|
17152 |
|
17153 |
|
17154 | sourceUpdater.queuePending[type] = queueEntry;
|
17155 | queueEntry.action(type, sourceUpdater);
|
17156 |
|
17157 | if (!queueEntry.doneFn) {
|
17158 |
|
17159 | sourceUpdater.queuePending[type] = null;
|
17160 | shiftQueue(type, sourceUpdater);
|
17161 | return;
|
17162 | }
|
17163 | };
|
17164 |
|
17165 | var cleanupBuffer = function cleanupBuffer(type, sourceUpdater) {
|
17166 | var buffer = sourceUpdater[type + "Buffer"];
|
17167 | var titleType = toTitleCase(type);
|
17168 |
|
17169 | if (!buffer) {
|
17170 | return;
|
17171 | }
|
17172 |
|
17173 | buffer.removeEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
17174 | buffer.removeEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
17175 | sourceUpdater.codecs[type] = null;
|
17176 | sourceUpdater[type + "Buffer"] = null;
|
17177 | };
|
17178 |
|
17179 | var inSourceBuffers = function inSourceBuffers(mediaSource, sourceBuffer) {
|
17180 | return mediaSource && sourceBuffer && Array.prototype.indexOf.call(mediaSource.sourceBuffers, sourceBuffer) !== -1;
|
17181 | };
|
17182 |
|
17183 | var actions = {
|
17184 | appendBuffer: function appendBuffer(bytes, segmentInfo, onError) {
|
17185 | return function (type, sourceUpdater) {
|
17186 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17187 |
|
17188 |
|
17189 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
17190 | return;
|
17191 | }
|
17192 |
|
17193 | sourceUpdater.logger_("Appending segment " + segmentInfo.mediaIndex + "'s " + bytes.length + " bytes to " + type + "Buffer");
|
17194 |
|
17195 | try {
|
17196 | sourceBuffer.appendBuffer(bytes);
|
17197 | } catch (e) {
|
17198 | sourceUpdater.logger_("Error with code " + e.code + " " + (e.code === QUOTA_EXCEEDED_ERR ? '(QUOTA_EXCEEDED_ERR) ' : '') + ("when appending segment " + segmentInfo.mediaIndex + " to " + type + "Buffer"));
|
17199 | sourceUpdater.queuePending[type] = null;
|
17200 | onError(e);
|
17201 | }
|
17202 | };
|
17203 | },
|
17204 | remove: function remove(start, end) {
|
17205 | return function (type, sourceUpdater) {
|
17206 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17207 |
|
17208 |
|
17209 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
17210 | return;
|
17211 | }
|
17212 |
|
17213 | sourceUpdater.logger_("Removing " + start + " to " + end + " from " + type + "Buffer");
|
17214 |
|
17215 | try {
|
17216 | sourceBuffer.remove(start, end);
|
17217 | } catch (e) {
|
17218 | sourceUpdater.logger_("Remove " + start + " to " + end + " from " + type + "Buffer failed");
|
17219 | }
|
17220 | };
|
17221 | },
|
17222 | timestampOffset: function timestampOffset(offset) {
|
17223 | return function (type, sourceUpdater) {
|
17224 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17225 |
|
17226 |
|
17227 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
17228 | return;
|
17229 | }
|
17230 |
|
17231 | sourceUpdater.logger_("Setting " + type + "timestampOffset to " + offset);
|
17232 | sourceBuffer.timestampOffset = offset;
|
17233 | };
|
17234 | },
|
17235 | callback: function callback(_callback) {
|
17236 | return function (type, sourceUpdater) {
|
17237 | _callback();
|
17238 | };
|
17239 | },
|
17240 | endOfStream: function endOfStream(error) {
|
17241 | return function (sourceUpdater) {
|
17242 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
17243 | return;
|
17244 | }
|
17245 |
|
17246 | sourceUpdater.logger_("Calling mediaSource endOfStream(" + (error || '') + ")");
|
17247 |
|
17248 | try {
|
17249 | sourceUpdater.mediaSource.endOfStream(error);
|
17250 | } catch (e) {
|
17251 | videojs__default['default'].log.warn('Failed to call media source endOfStream', e);
|
17252 | }
|
17253 | };
|
17254 | },
|
17255 | duration: function duration(_duration) {
|
17256 | return function (sourceUpdater) {
|
17257 | sourceUpdater.logger_("Setting mediaSource duration to " + _duration);
|
17258 |
|
17259 | try {
|
17260 | sourceUpdater.mediaSource.duration = _duration;
|
17261 | } catch (e) {
|
17262 | videojs__default['default'].log.warn('Failed to set media source duration', e);
|
17263 | }
|
17264 | };
|
17265 | },
|
17266 | abort: function abort() {
|
17267 | return function (type, sourceUpdater) {
|
17268 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
17269 | return;
|
17270 | }
|
17271 |
|
17272 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17273 |
|
17274 |
|
17275 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
17276 | return;
|
17277 | }
|
17278 |
|
17279 | sourceUpdater.logger_("calling abort on " + type + "Buffer");
|
17280 |
|
17281 | try {
|
17282 | sourceBuffer.abort();
|
17283 | } catch (e) {
|
17284 | videojs__default['default'].log.warn("Failed to abort on " + type + "Buffer", e);
|
17285 | }
|
17286 | };
|
17287 | },
|
17288 | addSourceBuffer: function addSourceBuffer(type, codec) {
|
17289 | return function (sourceUpdater) {
|
17290 | var titleType = toTitleCase(type);
|
17291 | var mime = codecs_js.getMimeForCodec(codec);
|
17292 | sourceUpdater.logger_("Adding " + type + "Buffer with codec " + codec + " to mediaSource");
|
17293 | var sourceBuffer = sourceUpdater.mediaSource.addSourceBuffer(mime);
|
17294 | sourceBuffer.addEventListener('updateend', sourceUpdater["on" + titleType + "UpdateEnd_"]);
|
17295 | sourceBuffer.addEventListener('error', sourceUpdater["on" + titleType + "Error_"]);
|
17296 | sourceUpdater.codecs[type] = codec;
|
17297 | sourceUpdater[type + "Buffer"] = sourceBuffer;
|
17298 | };
|
17299 | },
|
17300 | removeSourceBuffer: function removeSourceBuffer(type) {
|
17301 | return function (sourceUpdater) {
|
17302 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17303 | cleanupBuffer(type, sourceUpdater);
|
17304 |
|
17305 |
|
17306 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
17307 | return;
|
17308 | }
|
17309 |
|
17310 | sourceUpdater.logger_("Removing " + type + "Buffer with codec " + sourceUpdater.codecs[type] + " from mediaSource");
|
17311 |
|
17312 | try {
|
17313 | sourceUpdater.mediaSource.removeSourceBuffer(sourceBuffer);
|
17314 | } catch (e) {
|
17315 | videojs__default['default'].log.warn("Failed to removeSourceBuffer " + type + "Buffer", e);
|
17316 | }
|
17317 | };
|
17318 | },
|
17319 | changeType: function changeType(codec) {
|
17320 | return function (type, sourceUpdater) {
|
17321 | var sourceBuffer = sourceUpdater[type + "Buffer"];
|
17322 | var mime = codecs_js.getMimeForCodec(codec);
|
17323 |
|
17324 |
|
17325 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
17326 | return;
|
17327 | }
|
17328 |
|
17329 |
|
17330 | if (sourceUpdater.codecs[type] === codec) {
|
17331 | return;
|
17332 | }
|
17333 |
|
17334 | sourceUpdater.logger_("changing " + type + "Buffer codec from " + sourceUpdater.codecs[type] + " to " + codec);
|
17335 | sourceBuffer.changeType(mime);
|
17336 | sourceUpdater.codecs[type] = codec;
|
17337 | };
|
17338 | }
|
17339 | };
|
17340 |
|
17341 | var pushQueue = function pushQueue(_ref) {
|
17342 | var type = _ref.type,
|
17343 | sourceUpdater = _ref.sourceUpdater,
|
17344 | action = _ref.action,
|
17345 | doneFn = _ref.doneFn,
|
17346 | name = _ref.name;
|
17347 | sourceUpdater.queue.push({
|
17348 | type: type,
|
17349 | action: action,
|
17350 | doneFn: doneFn,
|
17351 | name: name
|
17352 | });
|
17353 | shiftQueue(type, sourceUpdater);
|
17354 | };
|
17355 |
|
17356 | var onUpdateend = function onUpdateend(type, sourceUpdater) {
|
17357 | return function (e) {
|
17358 |
|
17359 |
|
17360 |
|
17361 |
|
17362 |
|
17363 |
|
17364 | if (sourceUpdater.queuePending[type]) {
|
17365 | var doneFn = sourceUpdater.queuePending[type].doneFn;
|
17366 | sourceUpdater.queuePending[type] = null;
|
17367 |
|
17368 | if (doneFn) {
|
17369 |
|
17370 | doneFn(sourceUpdater[type + "Error_"]);
|
17371 | }
|
17372 | }
|
17373 |
|
17374 | shiftQueue(type, sourceUpdater);
|
17375 | };
|
17376 | };
|
17377 |
|
17378 |
|
17379 |
|
17380 |
|
17381 |
|
17382 |
|
17383 |
|
17384 |
|
17385 |
|
17386 |
|
17387 |
|
17388 |
|
17389 | var SourceUpdater = function (_videojs$EventTarget) {
|
17390 | _inheritsLoose__default['default'](SourceUpdater, _videojs$EventTarget);
|
17391 |
|
17392 | function SourceUpdater(mediaSource) {
|
17393 | var _this;
|
17394 |
|
17395 | _this = _videojs$EventTarget.call(this) || this;
|
17396 | _this.mediaSource = mediaSource;
|
17397 |
|
17398 | _this.sourceopenListener_ = function () {
|
17399 | return shiftQueue('mediaSource', _assertThisInitialized__default['default'](_this));
|
17400 | };
|
17401 |
|
17402 | _this.mediaSource.addEventListener('sourceopen', _this.sourceopenListener_);
|
17403 |
|
17404 | _this.logger_ = logger('SourceUpdater');
|
17405 |
|
17406 | _this.audioTimestampOffset_ = 0;
|
17407 | _this.videoTimestampOffset_ = 0;
|
17408 | _this.queue = [];
|
17409 | _this.queuePending = {
|
17410 | audio: null,
|
17411 | video: null
|
17412 | };
|
17413 | _this.delayedAudioAppendQueue_ = [];
|
17414 | _this.videoAppendQueued_ = false;
|
17415 | _this.codecs = {};
|
17416 | _this.onVideoUpdateEnd_ = onUpdateend('video', _assertThisInitialized__default['default'](_this));
|
17417 | _this.onAudioUpdateEnd_ = onUpdateend('audio', _assertThisInitialized__default['default'](_this));
|
17418 |
|
17419 | _this.onVideoError_ = function (e) {
|
17420 |
|
17421 | _this.videoError_ = e;
|
17422 | };
|
17423 |
|
17424 | _this.onAudioError_ = function (e) {
|
17425 |
|
17426 | _this.audioError_ = e;
|
17427 | };
|
17428 |
|
17429 | _this.createdSourceBuffers_ = false;
|
17430 | _this.initializedEme_ = false;
|
17431 | _this.triggeredReady_ = false;
|
17432 | return _this;
|
17433 | }
|
17434 |
|
17435 | var _proto = SourceUpdater.prototype;
|
17436 |
|
17437 | _proto.initializedEme = function initializedEme() {
|
17438 | this.initializedEme_ = true;
|
17439 | this.triggerReady();
|
17440 | };
|
17441 |
|
17442 | _proto.hasCreatedSourceBuffers = function hasCreatedSourceBuffers() {
|
17443 |
|
17444 |
|
17445 | return this.createdSourceBuffers_;
|
17446 | };
|
17447 |
|
17448 | _proto.hasInitializedAnyEme = function hasInitializedAnyEme() {
|
17449 | return this.initializedEme_;
|
17450 | };
|
17451 |
|
17452 | _proto.ready = function ready() {
|
17453 | return this.hasCreatedSourceBuffers() && this.hasInitializedAnyEme();
|
17454 | };
|
17455 |
|
17456 | _proto.createSourceBuffers = function createSourceBuffers(codecs) {
|
17457 | if (this.hasCreatedSourceBuffers()) {
|
17458 |
|
17459 | return;
|
17460 | }
|
17461 |
|
17462 |
|
17463 |
|
17464 | this.addOrChangeSourceBuffers(codecs);
|
17465 | this.createdSourceBuffers_ = true;
|
17466 | this.trigger('createdsourcebuffers');
|
17467 | this.triggerReady();
|
17468 | };
|
17469 |
|
17470 | _proto.triggerReady = function triggerReady() {
|
17471 |
|
17472 |
|
17473 |
|
17474 |
|
17475 |
|
17476 |
|
17477 | if (this.ready() && !this.triggeredReady_) {
|
17478 | this.triggeredReady_ = true;
|
17479 | this.trigger('ready');
|
17480 | }
|
17481 | }
|
17482 | |
17483 |
|
17484 |
|
17485 |
|
17486 |
|
17487 |
|
17488 |
|
17489 |
|
17490 |
|
17491 | ;
|
17492 |
|
17493 | _proto.addSourceBuffer = function addSourceBuffer(type, codec) {
|
17494 | pushQueue({
|
17495 | type: 'mediaSource',
|
17496 | sourceUpdater: this,
|
17497 | action: actions.addSourceBuffer(type, codec),
|
17498 | name: 'addSourceBuffer'
|
17499 | });
|
17500 | }
|
17501 | |
17502 |
|
17503 |
|
17504 |
|
17505 |
|
17506 |
|
17507 | ;
|
17508 |
|
17509 | _proto.abort = function abort(type) {
|
17510 | pushQueue({
|
17511 | type: type,
|
17512 | sourceUpdater: this,
|
17513 | action: actions.abort(type),
|
17514 | name: 'abort'
|
17515 | });
|
17516 | }
|
17517 | |
17518 |
|
17519 |
|
17520 |
|
17521 |
|
17522 |
|
17523 |
|
17524 | ;
|
17525 |
|
17526 | _proto.removeSourceBuffer = function removeSourceBuffer(type) {
|
17527 | if (!this.canRemoveSourceBuffer()) {
|
17528 | videojs__default['default'].log.error('removeSourceBuffer is not supported!');
|
17529 | return;
|
17530 | }
|
17531 |
|
17532 | pushQueue({
|
17533 | type: 'mediaSource',
|
17534 | sourceUpdater: this,
|
17535 | action: actions.removeSourceBuffer(type),
|
17536 | name: 'removeSourceBuffer'
|
17537 | });
|
17538 | }
|
17539 | |
17540 |
|
17541 |
|
17542 |
|
17543 |
|
17544 |
|
17545 |
|
17546 | ;
|
17547 |
|
17548 | _proto.canRemoveSourceBuffer = function canRemoveSourceBuffer() {
|
17549 |
|
17550 |
|
17551 |
|
17552 |
|
17553 | 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';
|
17554 | }
|
17555 | |
17556 |
|
17557 |
|
17558 |
|
17559 |
|
17560 |
|
17561 |
|
17562 | ;
|
17563 |
|
17564 | SourceUpdater.canChangeType = function canChangeType() {
|
17565 | return window__default['default'].SourceBuffer && window__default['default'].SourceBuffer.prototype && typeof window__default['default'].SourceBuffer.prototype.changeType === 'function';
|
17566 | }
|
17567 | |
17568 |
|
17569 |
|
17570 |
|
17571 |
|
17572 |
|
17573 |
|
17574 | ;
|
17575 |
|
17576 | _proto.canChangeType = function canChangeType() {
|
17577 | return this.constructor.canChangeType();
|
17578 | }
|
17579 | |
17580 |
|
17581 |
|
17582 |
|
17583 |
|
17584 |
|
17585 |
|
17586 |
|
17587 |
|
17588 | ;
|
17589 |
|
17590 | _proto.changeType = function changeType(type, codec) {
|
17591 | if (!this.canChangeType()) {
|
17592 | videojs__default['default'].log.error('changeType is not supported!');
|
17593 | return;
|
17594 | }
|
17595 |
|
17596 | pushQueue({
|
17597 | type: type,
|
17598 | sourceUpdater: this,
|
17599 | action: actions.changeType(codec),
|
17600 | name: 'changeType'
|
17601 | });
|
17602 | }
|
17603 | |
17604 |
|
17605 |
|
17606 |
|
17607 |
|
17608 |
|
17609 |
|
17610 | ;
|
17611 |
|
17612 | _proto.addOrChangeSourceBuffers = function addOrChangeSourceBuffers(codecs) {
|
17613 | var _this2 = this;
|
17614 |
|
17615 | if (!codecs || typeof codecs !== 'object' || Object.keys(codecs).length === 0) {
|
17616 | throw new Error('Cannot addOrChangeSourceBuffers to undefined codecs');
|
17617 | }
|
17618 |
|
17619 | Object.keys(codecs).forEach(function (type) {
|
17620 | var codec = codecs[type];
|
17621 |
|
17622 | if (!_this2.hasCreatedSourceBuffers()) {
|
17623 | return _this2.addSourceBuffer(type, codec);
|
17624 | }
|
17625 |
|
17626 | if (_this2.canChangeType()) {
|
17627 | _this2.changeType(type, codec);
|
17628 | }
|
17629 | });
|
17630 | }
|
17631 | |
17632 |
|
17633 |
|
17634 |
|
17635 |
|
17636 |
|
17637 |
|
17638 | ;
|
17639 |
|
17640 | _proto.appendBuffer = function appendBuffer(options, doneFn) {
|
17641 | var _this3 = this;
|
17642 |
|
17643 | var segmentInfo = options.segmentInfo,
|
17644 | type = options.type,
|
17645 | bytes = options.bytes;
|
17646 | this.processedAppend_ = true;
|
17647 |
|
17648 | if (type === 'audio' && this.videoBuffer && !this.videoAppendQueued_) {
|
17649 | this.delayedAudioAppendQueue_.push([options, doneFn]);
|
17650 | this.logger_("delayed audio append of " + bytes.length + " until video append");
|
17651 | return;
|
17652 | }
|
17653 |
|
17654 |
|
17655 |
|
17656 |
|
17657 |
|
17658 | var onError = doneFn;
|
17659 | pushQueue({
|
17660 | type: type,
|
17661 | sourceUpdater: this,
|
17662 | action: actions.appendBuffer(bytes, segmentInfo || {
|
17663 | mediaIndex: -1
|
17664 | }, onError),
|
17665 | doneFn: doneFn,
|
17666 | name: 'appendBuffer'
|
17667 | });
|
17668 |
|
17669 | if (type === 'video') {
|
17670 | this.videoAppendQueued_ = true;
|
17671 |
|
17672 | if (!this.delayedAudioAppendQueue_.length) {
|
17673 | return;
|
17674 | }
|
17675 |
|
17676 | var queue = this.delayedAudioAppendQueue_.slice();
|
17677 | this.logger_("queuing delayed audio " + queue.length + " appendBuffers");
|
17678 | this.delayedAudioAppendQueue_.length = 0;
|
17679 | queue.forEach(function (que) {
|
17680 | _this3.appendBuffer.apply(_this3, que);
|
17681 | });
|
17682 | }
|
17683 | }
|
17684 | |
17685 |
|
17686 |
|
17687 |
|
17688 |
|
17689 |
|
17690 | ;
|
17691 |
|
17692 | _proto.audioBuffered = function audioBuffered() {
|
17693 |
|
17694 |
|
17695 | if (!inSourceBuffers(this.mediaSource, this.audioBuffer)) {
|
17696 | return videojs__default['default'].createTimeRange();
|
17697 | }
|
17698 |
|
17699 | return this.audioBuffer.buffered ? this.audioBuffer.buffered : videojs__default['default'].createTimeRange();
|
17700 | }
|
17701 | |
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 | ;
|
17708 |
|
17709 | _proto.videoBuffered = function videoBuffered() {
|
17710 |
|
17711 |
|
17712 | if (!inSourceBuffers(this.mediaSource, this.videoBuffer)) {
|
17713 | return videojs__default['default'].createTimeRange();
|
17714 | }
|
17715 |
|
17716 | return this.videoBuffer.buffered ? this.videoBuffer.buffered : videojs__default['default'].createTimeRange();
|
17717 | }
|
17718 | |
17719 |
|
17720 |
|
17721 |
|
17722 |
|
17723 |
|
17724 | ;
|
17725 |
|
17726 | _proto.buffered = function buffered() {
|
17727 | var video = inSourceBuffers(this.mediaSource, this.videoBuffer) ? this.videoBuffer : null;
|
17728 | var audio = inSourceBuffers(this.mediaSource, this.audioBuffer) ? this.audioBuffer : null;
|
17729 |
|
17730 | if (audio && !video) {
|
17731 | return this.audioBuffered();
|
17732 | }
|
17733 |
|
17734 | if (video && !audio) {
|
17735 | return this.videoBuffered();
|
17736 | }
|
17737 |
|
17738 | return bufferIntersection(this.audioBuffered(), this.videoBuffered());
|
17739 | }
|
17740 | |
17741 |
|
17742 |
|
17743 |
|
17744 |
|
17745 |
|
17746 |
|
17747 |
|
17748 |
|
17749 | ;
|
17750 |
|
17751 | _proto.setDuration = function setDuration(duration, doneFn) {
|
17752 | if (doneFn === void 0) {
|
17753 | doneFn = noop;
|
17754 | }
|
17755 |
|
17756 |
|
17757 |
|
17758 |
|
17759 |
|
17760 | pushQueue({
|
17761 | type: 'mediaSource',
|
17762 | sourceUpdater: this,
|
17763 | action: actions.duration(duration),
|
17764 | name: 'duration',
|
17765 | doneFn: doneFn
|
17766 | });
|
17767 | }
|
17768 | |
17769 |
|
17770 |
|
17771 |
|
17772 |
|
17773 |
|
17774 |
|
17775 |
|
17776 |
|
17777 |
|
17778 | ;
|
17779 |
|
17780 | _proto.endOfStream = function endOfStream(error, doneFn) {
|
17781 | if (error === void 0) {
|
17782 | error = null;
|
17783 | }
|
17784 |
|
17785 | if (doneFn === void 0) {
|
17786 | doneFn = noop;
|
17787 | }
|
17788 |
|
17789 | if (typeof error !== 'string') {
|
17790 | error = undefined;
|
17791 | }
|
17792 |
|
17793 |
|
17794 |
|
17795 |
|
17796 |
|
17797 | pushQueue({
|
17798 | type: 'mediaSource',
|
17799 | sourceUpdater: this,
|
17800 | action: actions.endOfStream(error),
|
17801 | name: 'endOfStream',
|
17802 | doneFn: doneFn
|
17803 | });
|
17804 | }
|
17805 | |
17806 |
|
17807 |
|
17808 |
|
17809 |
|
17810 |
|
17811 |
|
17812 |
|
17813 |
|
17814 | ;
|
17815 |
|
17816 | _proto.removeAudio = function removeAudio(start, end, done) {
|
17817 | if (done === void 0) {
|
17818 | done = noop;
|
17819 | }
|
17820 |
|
17821 | if (!this.audioBuffered().length || this.audioBuffered().end(0) === 0) {
|
17822 | done();
|
17823 | return;
|
17824 | }
|
17825 |
|
17826 | pushQueue({
|
17827 | type: 'audio',
|
17828 | sourceUpdater: this,
|
17829 | action: actions.remove(start, end),
|
17830 | doneFn: done,
|
17831 | name: 'remove'
|
17832 | });
|
17833 | }
|
17834 | |
17835 |
|
17836 |
|
17837 |
|
17838 |
|
17839 |
|
17840 |
|
17841 |
|
17842 |
|
17843 | ;
|
17844 |
|
17845 | _proto.removeVideo = function removeVideo(start, end, done) {
|
17846 | if (done === void 0) {
|
17847 | done = noop;
|
17848 | }
|
17849 |
|
17850 | if (!this.videoBuffered().length || this.videoBuffered().end(0) === 0) {
|
17851 | done();
|
17852 | return;
|
17853 | }
|
17854 |
|
17855 | pushQueue({
|
17856 | type: 'video',
|
17857 | sourceUpdater: this,
|
17858 | action: actions.remove(start, end),
|
17859 | doneFn: done,
|
17860 | name: 'remove'
|
17861 | });
|
17862 | }
|
17863 | |
17864 |
|
17865 |
|
17866 |
|
17867 |
|
17868 | ;
|
17869 |
|
17870 | _proto.updating = function updating() {
|
17871 |
|
17872 | if (_updating('audio', this) || _updating('video', this)) {
|
17873 | return true;
|
17874 | }
|
17875 |
|
17876 | return false;
|
17877 | }
|
17878 | |
17879 |
|
17880 |
|
17881 |
|
17882 |
|
17883 | ;
|
17884 |
|
17885 | _proto.audioTimestampOffset = function audioTimestampOffset(offset) {
|
17886 | if (typeof offset !== 'undefined' && this.audioBuffer &&
|
17887 | this.audioTimestampOffset_ !== offset) {
|
17888 | pushQueue({
|
17889 | type: 'audio',
|
17890 | sourceUpdater: this,
|
17891 | action: actions.timestampOffset(offset),
|
17892 | name: 'timestampOffset'
|
17893 | });
|
17894 | this.audioTimestampOffset_ = offset;
|
17895 | }
|
17896 |
|
17897 | return this.audioTimestampOffset_;
|
17898 | }
|
17899 | |
17900 |
|
17901 |
|
17902 |
|
17903 |
|
17904 | ;
|
17905 |
|
17906 | _proto.videoTimestampOffset = function videoTimestampOffset(offset) {
|
17907 | if (typeof offset !== 'undefined' && this.videoBuffer &&
|
17908 | this.videoTimestampOffset !== offset) {
|
17909 | pushQueue({
|
17910 | type: 'video',
|
17911 | sourceUpdater: this,
|
17912 | action: actions.timestampOffset(offset),
|
17913 | name: 'timestampOffset'
|
17914 | });
|
17915 | this.videoTimestampOffset_ = offset;
|
17916 | }
|
17917 |
|
17918 | return this.videoTimestampOffset_;
|
17919 | }
|
17920 | |
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 |
|
17926 |
|
17927 | ;
|
17928 |
|
17929 | _proto.audioQueueCallback = function audioQueueCallback(callback) {
|
17930 | if (!this.audioBuffer) {
|
17931 | return;
|
17932 | }
|
17933 |
|
17934 | pushQueue({
|
17935 | type: 'audio',
|
17936 | sourceUpdater: this,
|
17937 | action: actions.callback(callback),
|
17938 | name: 'callback'
|
17939 | });
|
17940 | }
|
17941 | |
17942 |
|
17943 |
|
17944 |
|
17945 |
|
17946 |
|
17947 |
|
17948 | ;
|
17949 |
|
17950 | _proto.videoQueueCallback = function videoQueueCallback(callback) {
|
17951 | if (!this.videoBuffer) {
|
17952 | return;
|
17953 | }
|
17954 |
|
17955 | pushQueue({
|
17956 | type: 'video',
|
17957 | sourceUpdater: this,
|
17958 | action: actions.callback(callback),
|
17959 | name: 'callback'
|
17960 | });
|
17961 | }
|
17962 | |
17963 |
|
17964 |
|
17965 | ;
|
17966 |
|
17967 | _proto.dispose = function dispose() {
|
17968 | var _this4 = this;
|
17969 |
|
17970 | this.trigger('dispose');
|
17971 | bufferTypes.forEach(function (type) {
|
17972 | _this4.abort(type);
|
17973 |
|
17974 | if (_this4.canRemoveSourceBuffer()) {
|
17975 | _this4.removeSourceBuffer(type);
|
17976 | } else {
|
17977 | _this4[type + "QueueCallback"](function () {
|
17978 | return cleanupBuffer(type, _this4);
|
17979 | });
|
17980 | }
|
17981 | });
|
17982 | this.videoAppendQueued_ = false;
|
17983 | this.delayedAudioAppendQueue_.length = 0;
|
17984 |
|
17985 | if (this.sourceopenListener_) {
|
17986 | this.mediaSource.removeEventListener('sourceopen', this.sourceopenListener_);
|
17987 | }
|
17988 |
|
17989 | this.off();
|
17990 | };
|
17991 |
|
17992 | return SourceUpdater;
|
17993 | }(videojs__default['default'].EventTarget);
|
17994 |
|
17995 | var uint8ToUtf8 = function uint8ToUtf8(uintArray) {
|
17996 | return decodeURIComponent(escape(String.fromCharCode.apply(null, uintArray)));
|
17997 | };
|
17998 |
|
17999 | var VTT_LINE_TERMINATORS = new Uint8Array('\n\n'.split('').map(function (char) {
|
18000 | return char.charCodeAt(0);
|
18001 | }));
|
18002 |
|
18003 |
|
18004 |
|
18005 |
|
18006 |
|
18007 |
|
18008 |
|
18009 |
|
18010 | var VTTSegmentLoader = function (_SegmentLoader) {
|
18011 | _inheritsLoose__default['default'](VTTSegmentLoader, _SegmentLoader);
|
18012 |
|
18013 | function VTTSegmentLoader(settings, options) {
|
18014 | var _this;
|
18015 |
|
18016 | if (options === void 0) {
|
18017 | options = {};
|
18018 | }
|
18019 |
|
18020 | _this = _SegmentLoader.call(this, settings, options) || this;
|
18021 |
|
18022 | _this.handlePartialData_ = false;
|
18023 |
|
18024 |
|
18025 | _this.mediaSource_ = null;
|
18026 | _this.subtitlesTrack_ = null;
|
18027 | _this.loaderType_ = 'subtitle';
|
18028 | _this.featuresNativeTextTracks_ = settings.featuresNativeTextTracks;
|
18029 |
|
18030 |
|
18031 | _this.shouldSaveSegmentTimingInfo_ = false;
|
18032 | return _this;
|
18033 | }
|
18034 |
|
18035 | var _proto = VTTSegmentLoader.prototype;
|
18036 |
|
18037 | _proto.createTransmuxer_ = function createTransmuxer_() {
|
18038 |
|
18039 | return null;
|
18040 | }
|
18041 | |
18042 |
|
18043 |
|
18044 |
|
18045 |
|
18046 |
|
18047 | ;
|
18048 |
|
18049 | _proto.buffered_ = function buffered_() {
|
18050 | if (!this.subtitlesTrack_ || !this.subtitlesTrack_.cues || !this.subtitlesTrack_.cues.length) {
|
18051 | return videojs__default['default'].createTimeRanges();
|
18052 | }
|
18053 |
|
18054 | var cues = this.subtitlesTrack_.cues;
|
18055 | var start = cues[0].startTime;
|
18056 | var end = cues[cues.length - 1].startTime;
|
18057 | return videojs__default['default'].createTimeRanges([[start, end]]);
|
18058 | }
|
18059 | |
18060 |
|
18061 |
|
18062 |
|
18063 |
|
18064 |
|
18065 |
|
18066 |
|
18067 |
|
18068 |
|
18069 | ;
|
18070 |
|
18071 | _proto.initSegmentForMap = function initSegmentForMap(map, set) {
|
18072 | if (set === void 0) {
|
18073 | set = false;
|
18074 | }
|
18075 |
|
18076 | if (!map) {
|
18077 | return null;
|
18078 | }
|
18079 |
|
18080 | var id = initSegmentId(map);
|
18081 | var storedMap = this.initSegments_[id];
|
18082 |
|
18083 | if (set && !storedMap && map.bytes) {
|
18084 |
|
18085 |
|
18086 |
|
18087 |
|
18088 | var combinedByteLength = VTT_LINE_TERMINATORS.byteLength + map.bytes.byteLength;
|
18089 | var combinedSegment = new Uint8Array(combinedByteLength);
|
18090 | combinedSegment.set(map.bytes);
|
18091 | combinedSegment.set(VTT_LINE_TERMINATORS, map.bytes.byteLength);
|
18092 | this.initSegments_[id] = storedMap = {
|
18093 | resolvedUri: map.resolvedUri,
|
18094 | byterange: map.byterange,
|
18095 | bytes: combinedSegment
|
18096 | };
|
18097 | }
|
18098 |
|
18099 | return storedMap || map;
|
18100 | }
|
18101 | |
18102 |
|
18103 |
|
18104 |
|
18105 |
|
18106 |
|
18107 | ;
|
18108 |
|
18109 | _proto.couldBeginLoading_ = function couldBeginLoading_() {
|
18110 | return this.playlist_ && this.subtitlesTrack_ && !this.paused();
|
18111 | }
|
18112 | |
18113 |
|
18114 |
|
18115 |
|
18116 |
|
18117 |
|
18118 |
|
18119 | ;
|
18120 |
|
18121 | _proto.init_ = function init_() {
|
18122 | this.state = 'READY';
|
18123 | this.resetEverything();
|
18124 | return this.monitorBuffer_();
|
18125 | }
|
18126 | |
18127 |
|
18128 |
|
18129 |
|
18130 |
|
18131 |
|
18132 |
|
18133 |
|
18134 | ;
|
18135 |
|
18136 | _proto.track = function track(_track) {
|
18137 | if (typeof _track === 'undefined') {
|
18138 | return this.subtitlesTrack_;
|
18139 | }
|
18140 |
|
18141 | this.subtitlesTrack_ = _track;
|
18142 |
|
18143 |
|
18144 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
18145 | this.init_();
|
18146 | }
|
18147 |
|
18148 | return this.subtitlesTrack_;
|
18149 | }
|
18150 | |
18151 |
|
18152 |
|
18153 |
|
18154 |
|
18155 |
|
18156 | ;
|
18157 |
|
18158 | _proto.remove = function remove(start, end) {
|
18159 | removeCuesFromTrack(start, end, this.subtitlesTrack_);
|
18160 | }
|
18161 | |
18162 |
|
18163 |
|
18164 |
|
18165 |
|
18166 |
|
18167 |
|
18168 |
|
18169 |
|
18170 | ;
|
18171 |
|
18172 | _proto.fillBuffer_ = function fillBuffer_() {
|
18173 | var _this2 = this;
|
18174 |
|
18175 | if (!this.syncPoint_) {
|
18176 | this.syncPoint_ = this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
18177 | }
|
18178 |
|
18179 |
|
18180 | var segmentInfo = this.checkBuffer_(this.buffered_(), this.playlist_, this.mediaIndex, this.hasPlayed_(), this.currentTime_(), this.syncPoint_);
|
18181 | segmentInfo = this.skipEmptySegments_(segmentInfo);
|
18182 |
|
18183 | if (!segmentInfo) {
|
18184 | return;
|
18185 | }
|
18186 |
|
18187 | if (this.syncController_.timestampOffsetForTimeline(segmentInfo.timeline) === null) {
|
18188 |
|
18189 |
|
18190 | var checkTimestampOffset = function checkTimestampOffset() {
|
18191 | _this2.state = 'READY';
|
18192 |
|
18193 | if (!_this2.paused()) {
|
18194 |
|
18195 | _this2.monitorBuffer_();
|
18196 | }
|
18197 | };
|
18198 |
|
18199 | this.syncController_.one('timestampoffset', checkTimestampOffset);
|
18200 | this.state = 'WAITING_ON_TIMELINE';
|
18201 | return;
|
18202 | }
|
18203 |
|
18204 | this.loadSegment_(segmentInfo);
|
18205 | }
|
18206 | |
18207 |
|
18208 |
|
18209 |
|
18210 |
|
18211 |
|
18212 |
|
18213 |
|
18214 |
|
18215 |
|
18216 | ;
|
18217 |
|
18218 | _proto.skipEmptySegments_ = function skipEmptySegments_(segmentInfo) {
|
18219 | while (segmentInfo && segmentInfo.segment.empty) {
|
18220 | segmentInfo = this.generateSegmentInfo_(segmentInfo.playlist, segmentInfo.mediaIndex + 1, segmentInfo.startOfSegment + segmentInfo.duration, segmentInfo.isSyncRequest);
|
18221 | }
|
18222 |
|
18223 | return segmentInfo;
|
18224 | };
|
18225 |
|
18226 | _proto.stopForError = function stopForError(error) {
|
18227 | this.error(error);
|
18228 | this.state = 'READY';
|
18229 | this.pause();
|
18230 | this.trigger('error');
|
18231 | }
|
18232 | |
18233 |
|
18234 |
|
18235 |
|
18236 |
|
18237 | ;
|
18238 |
|
18239 | _proto.segmentRequestFinished_ = function segmentRequestFinished_(error, simpleSegment, result) {
|
18240 | var _this3 = this;
|
18241 |
|
18242 | if (!this.subtitlesTrack_) {
|
18243 | this.state = 'READY';
|
18244 | return;
|
18245 | }
|
18246 |
|
18247 | this.saveTransferStats_(simpleSegment.stats);
|
18248 |
|
18249 | if (!this.pendingSegment_) {
|
18250 | this.state = 'READY';
|
18251 | this.mediaRequestsAborted += 1;
|
18252 | return;
|
18253 | }
|
18254 |
|
18255 | if (error) {
|
18256 | if (error.code === REQUEST_ERRORS.TIMEOUT) {
|
18257 | this.handleTimeout_();
|
18258 | }
|
18259 |
|
18260 | if (error.code === REQUEST_ERRORS.ABORTED) {
|
18261 | this.mediaRequestsAborted += 1;
|
18262 | } else {
|
18263 | this.mediaRequestsErrored += 1;
|
18264 | }
|
18265 |
|
18266 | this.stopForError(error);
|
18267 | return;
|
18268 | }
|
18269 |
|
18270 | var segmentInfo = this.pendingSegment_;
|
18271 |
|
18272 |
|
18273 | this.saveBandwidthRelatedStats_(segmentInfo.duration, simpleSegment.stats);
|
18274 | this.state = 'APPENDING';
|
18275 |
|
18276 | this.trigger('appending');
|
18277 | var segment = segmentInfo.segment;
|
18278 |
|
18279 | if (segment.map) {
|
18280 | segment.map.bytes = simpleSegment.map.bytes;
|
18281 | }
|
18282 |
|
18283 | segmentInfo.bytes = simpleSegment.bytes;
|
18284 |
|
18285 | if (typeof window__default['default'].WebVTT !== 'function' && this.subtitlesTrack_ && this.subtitlesTrack_.tech_) {
|
18286 | var loadHandler;
|
18287 |
|
18288 | var errorHandler = function errorHandler() {
|
18289 | _this3.subtitlesTrack_.tech_.off('vttjsloaded', loadHandler);
|
18290 |
|
18291 | _this3.stopForError({
|
18292 | message: 'Error loading vtt.js'
|
18293 | });
|
18294 |
|
18295 | return;
|
18296 | };
|
18297 |
|
18298 | loadHandler = function loadHandler() {
|
18299 | _this3.subtitlesTrack_.tech_.off('vttjserror', errorHandler);
|
18300 |
|
18301 | _this3.segmentRequestFinished_(error, simpleSegment, result);
|
18302 | };
|
18303 |
|
18304 | this.state = 'WAITING_ON_VTTJS';
|
18305 | this.subtitlesTrack_.tech_.one('vttjsloaded', loadHandler);
|
18306 | this.subtitlesTrack_.tech_.one('vttjserror', errorHandler);
|
18307 | return;
|
18308 | }
|
18309 |
|
18310 | segment.requested = true;
|
18311 |
|
18312 | try {
|
18313 | this.parseVTTCues_(segmentInfo);
|
18314 | } catch (e) {
|
18315 | this.stopForError({
|
18316 | message: e.message
|
18317 | });
|
18318 | return;
|
18319 | }
|
18320 |
|
18321 | this.updateTimeMapping_(segmentInfo, this.syncController_.timelines[segmentInfo.timeline], this.playlist_);
|
18322 |
|
18323 | if (segmentInfo.cues.length) {
|
18324 | segmentInfo.timingInfo = {
|
18325 | start: segmentInfo.cues[0].startTime,
|
18326 | end: segmentInfo.cues[segmentInfo.cues.length - 1].endTime
|
18327 | };
|
18328 | } else {
|
18329 | segmentInfo.timingInfo = {
|
18330 | start: segmentInfo.startOfSegment,
|
18331 | end: segmentInfo.startOfSegment + segmentInfo.duration
|
18332 | };
|
18333 | }
|
18334 |
|
18335 | if (segmentInfo.isSyncRequest) {
|
18336 | this.trigger('syncinfoupdate');
|
18337 | this.pendingSegment_ = null;
|
18338 | this.state = 'READY';
|
18339 | return;
|
18340 | }
|
18341 |
|
18342 | segmentInfo.byteLength = segmentInfo.bytes.byteLength;
|
18343 | this.mediaSecondsLoaded += segment.duration;
|
18344 |
|
18345 |
|
18346 | segmentInfo.cues.forEach(function (cue) {
|
18347 | _this3.subtitlesTrack_.addCue(_this3.featuresNativeTextTracks_ ? new window__default['default'].VTTCue(cue.startTime, cue.endTime, cue.text) : cue);
|
18348 | });
|
18349 |
|
18350 |
|
18351 |
|
18352 |
|
18353 | removeDuplicateCuesFromTrack(this.subtitlesTrack_);
|
18354 | this.handleAppendsDone_();
|
18355 | };
|
18356 |
|
18357 | _proto.handleData_ = function handleData_() {
|
18358 |
|
18359 | };
|
18360 |
|
18361 | _proto.updateTimingInfoEnd_ = function updateTimingInfoEnd_() {
|
18362 | }
|
18363 | |
18364 |
|
18365 |
|
18366 |
|
18367 |
|
18368 |
|
18369 |
|
18370 | ;
|
18371 |
|
18372 | _proto.parseVTTCues_ = function parseVTTCues_(segmentInfo) {
|
18373 | var decoder;
|
18374 | var decodeBytesToString = false;
|
18375 |
|
18376 | if (typeof window__default['default'].TextDecoder === 'function') {
|
18377 | decoder = new window__default['default'].TextDecoder('utf8');
|
18378 | } else {
|
18379 | decoder = window__default['default'].WebVTT.StringDecoder();
|
18380 | decodeBytesToString = true;
|
18381 | }
|
18382 |
|
18383 | var parser = new window__default['default'].WebVTT.Parser(window__default['default'], window__default['default'].vttjs, decoder);
|
18384 | segmentInfo.cues = [];
|
18385 | segmentInfo.timestampmap = {
|
18386 | MPEGTS: 0,
|
18387 | LOCAL: 0
|
18388 | };
|
18389 | parser.oncue = segmentInfo.cues.push.bind(segmentInfo.cues);
|
18390 |
|
18391 | parser.ontimestampmap = function (map) {
|
18392 | segmentInfo.timestampmap = map;
|
18393 | };
|
18394 |
|
18395 | parser.onparsingerror = function (error) {
|
18396 | videojs__default['default'].log.warn('Error encountered when parsing cues: ' + error.message);
|
18397 | };
|
18398 |
|
18399 | if (segmentInfo.segment.map) {
|
18400 | var mapData = segmentInfo.segment.map.bytes;
|
18401 |
|
18402 | if (decodeBytesToString) {
|
18403 | mapData = uint8ToUtf8(mapData);
|
18404 | }
|
18405 |
|
18406 | parser.parse(mapData);
|
18407 | }
|
18408 |
|
18409 | var segmentData = segmentInfo.bytes;
|
18410 |
|
18411 | if (decodeBytesToString) {
|
18412 | segmentData = uint8ToUtf8(segmentData);
|
18413 | }
|
18414 |
|
18415 | parser.parse(segmentData);
|
18416 | parser.flush();
|
18417 | }
|
18418 | |
18419 |
|
18420 |
|
18421 |
|
18422 |
|
18423 |
|
18424 |
|
18425 |
|
18426 |
|
18427 |
|
18428 |
|
18429 |
|
18430 |
|
18431 | ;
|
18432 |
|
18433 | _proto.updateTimeMapping_ = function updateTimeMapping_(segmentInfo, mappingObj, playlist) {
|
18434 | var segment = segmentInfo.segment;
|
18435 |
|
18436 | if (!mappingObj) {
|
18437 |
|
18438 |
|
18439 |
|
18440 | return;
|
18441 | }
|
18442 |
|
18443 | if (!segmentInfo.cues.length) {
|
18444 |
|
18445 |
|
18446 |
|
18447 | segment.empty = true;
|
18448 | return;
|
18449 | }
|
18450 |
|
18451 | var timestampmap = segmentInfo.timestampmap;
|
18452 | var diff = timestampmap.MPEGTS / clock.ONE_SECOND_IN_TS - timestampmap.LOCAL + mappingObj.mapping;
|
18453 | segmentInfo.cues.forEach(function (cue) {
|
18454 |
|
18455 | cue.startTime += diff;
|
18456 | cue.endTime += diff;
|
18457 | });
|
18458 |
|
18459 | if (!playlist.syncInfo) {
|
18460 | var firstStart = segmentInfo.cues[0].startTime;
|
18461 | var lastStart = segmentInfo.cues[segmentInfo.cues.length - 1].startTime;
|
18462 | playlist.syncInfo = {
|
18463 | mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
|
18464 | time: Math.min(firstStart, lastStart - segment.duration)
|
18465 | };
|
18466 | }
|
18467 | };
|
18468 |
|
18469 | return VTTSegmentLoader;
|
18470 | }(SegmentLoader);
|
18471 |
|
18472 |
|
18473 |
|
18474 |
|
18475 |
|
18476 |
|
18477 |
|
18478 |
|
18479 |
|
18480 |
|
18481 |
|
18482 |
|
18483 |
|
18484 |
|
18485 |
|
18486 |
|
18487 |
|
18488 | var findAdCue = function findAdCue(track, mediaTime) {
|
18489 | var cues = track.cues;
|
18490 |
|
18491 | for (var i = 0; i < cues.length; i++) {
|
18492 | var cue = cues[i];
|
18493 |
|
18494 | if (mediaTime >= cue.adStartTime && mediaTime <= cue.adEndTime) {
|
18495 | return cue;
|
18496 | }
|
18497 | }
|
18498 |
|
18499 | return null;
|
18500 | };
|
18501 | var updateAdCues = function updateAdCues(media, track, offset) {
|
18502 | if (offset === void 0) {
|
18503 | offset = 0;
|
18504 | }
|
18505 |
|
18506 | if (!media.segments) {
|
18507 | return;
|
18508 | }
|
18509 |
|
18510 | var mediaTime = offset;
|
18511 | var cue;
|
18512 |
|
18513 | for (var i = 0; i < media.segments.length; i++) {
|
18514 | var segment = media.segments[i];
|
18515 |
|
18516 | if (!cue) {
|
18517 |
|
18518 |
|
18519 |
|
18520 |
|
18521 | cue = findAdCue(track, mediaTime + segment.duration / 2);
|
18522 | }
|
18523 |
|
18524 | if (cue) {
|
18525 | if ('cueIn' in segment) {
|
18526 |
|
18527 | cue.endTime = mediaTime;
|
18528 | cue.adEndTime = mediaTime;
|
18529 | mediaTime += segment.duration;
|
18530 | cue = null;
|
18531 | continue;
|
18532 | }
|
18533 |
|
18534 | if (mediaTime < cue.endTime) {
|
18535 |
|
18536 | mediaTime += segment.duration;
|
18537 | continue;
|
18538 | }
|
18539 |
|
18540 |
|
18541 | cue.endTime += segment.duration;
|
18542 | } else {
|
18543 | if ('cueOut' in segment) {
|
18544 | cue = new window__default['default'].VTTCue(mediaTime, mediaTime + segment.duration, segment.cueOut);
|
18545 | cue.adStartTime = mediaTime;
|
18546 |
|
18547 |
|
18548 | cue.adEndTime = mediaTime + parseFloat(segment.cueOut);
|
18549 | track.addCue(cue);
|
18550 | }
|
18551 |
|
18552 | if ('cueOutCont' in segment) {
|
18553 |
|
18554 |
|
18555 |
|
18556 | var _segment$cueOutCont$s = segment.cueOutCont.split('/').map(parseFloat),
|
18557 | adOffset = _segment$cueOutCont$s[0],
|
18558 | adTotal = _segment$cueOutCont$s[1];
|
18559 |
|
18560 | cue = new window__default['default'].VTTCue(mediaTime, mediaTime + segment.duration, '');
|
18561 | cue.adStartTime = mediaTime - adOffset;
|
18562 | cue.adEndTime = cue.adStartTime + adTotal;
|
18563 | track.addCue(cue);
|
18564 | }
|
18565 | }
|
18566 |
|
18567 | mediaTime += segment.duration;
|
18568 | }
|
18569 | };
|
18570 |
|
18571 | var getSegmentIndex = function getSegmentIndex(i, playlist, currentTime) {
|
18572 | if (currentTime === void 0) {
|
18573 | currentTime = 0;
|
18574 | }
|
18575 |
|
18576 | var segments = playlist.segments;
|
18577 | return playlist.endList || currentTime === 0 ? i : segments.length - (i + 1);
|
18578 | };
|
18579 |
|
18580 | var syncPointStrategies = [
|
18581 |
|
18582 | {
|
18583 | name: 'VOD',
|
18584 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
18585 | if (duration !== Infinity) {
|
18586 | var syncPoint = {
|
18587 | time: 0,
|
18588 | segmentIndex: 0
|
18589 | };
|
18590 | return syncPoint;
|
18591 | }
|
18592 |
|
18593 | return null;
|
18594 | }
|
18595 | },
|
18596 | {
|
18597 | name: 'ProgramDateTime',
|
18598 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
18599 | if (!Object.keys(syncController.timelineToDatetimeMappings).length) {
|
18600 | return null;
|
18601 | }
|
18602 |
|
18603 | var segments = playlist.segments || [];
|
18604 | var syncPoint = null;
|
18605 | var lastDistance = null;
|
18606 | currentTime = currentTime || 0;
|
18607 |
|
18608 | for (var i = 0; i < segments.length; i++) {
|
18609 | var segmentIndex = getSegmentIndex(i, playlist, currentTime);
|
18610 | var segment = segments[segmentIndex];
|
18611 | var datetimeMapping = syncController.timelineToDatetimeMappings[segment.timeline];
|
18612 |
|
18613 | if (!datetimeMapping) {
|
18614 | continue;
|
18615 | }
|
18616 |
|
18617 | if (segment.dateTimeObject) {
|
18618 | var segmentTime = segment.dateTimeObject.getTime() / 1000;
|
18619 | var segmentStart = segmentTime + datetimeMapping;
|
18620 | var distance = Math.abs(currentTime - segmentStart);
|
18621 |
|
18622 |
|
18623 | if (lastDistance !== null && (distance === 0 || lastDistance < distance)) {
|
18624 | break;
|
18625 | }
|
18626 |
|
18627 | lastDistance = distance;
|
18628 | syncPoint = {
|
18629 | time: segmentStart,
|
18630 | segmentIndex: segmentIndex
|
18631 | };
|
18632 | }
|
18633 | }
|
18634 |
|
18635 | return syncPoint;
|
18636 | }
|
18637 | },
|
18638 |
|
18639 | {
|
18640 | name: 'Segment',
|
18641 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
18642 | var segments = playlist.segments || [];
|
18643 | var syncPoint = null;
|
18644 | var lastDistance = null;
|
18645 | currentTime = currentTime || 0;
|
18646 |
|
18647 | for (var i = 0; i < segments.length; i++) {
|
18648 | var segmentIndex = getSegmentIndex(i, playlist, currentTime);
|
18649 | var segment = segments[segmentIndex];
|
18650 |
|
18651 | if (segment.timeline === currentTimeline && typeof segment.start !== 'undefined') {
|
18652 | var distance = Math.abs(currentTime - segment.start);
|
18653 |
|
18654 |
|
18655 | if (lastDistance !== null && lastDistance < distance) {
|
18656 | break;
|
18657 | }
|
18658 |
|
18659 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
18660 | lastDistance = distance;
|
18661 | syncPoint = {
|
18662 | time: segment.start,
|
18663 | segmentIndex: segmentIndex
|
18664 | };
|
18665 | }
|
18666 | }
|
18667 | }
|
18668 |
|
18669 | return syncPoint;
|
18670 | }
|
18671 | },
|
18672 |
|
18673 | {
|
18674 | name: 'Discontinuity',
|
18675 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
18676 | var syncPoint = null;
|
18677 | currentTime = currentTime || 0;
|
18678 |
|
18679 | if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
18680 | var lastDistance = null;
|
18681 |
|
18682 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
18683 | var segmentIndex = playlist.discontinuityStarts[i];
|
18684 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
18685 | var discontinuitySync = syncController.discontinuities[discontinuity];
|
18686 |
|
18687 | if (discontinuitySync) {
|
18688 | var distance = Math.abs(currentTime - discontinuitySync.time);
|
18689 |
|
18690 |
|
18691 | if (lastDistance !== null && lastDistance < distance) {
|
18692 | break;
|
18693 | }
|
18694 |
|
18695 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
18696 | lastDistance = distance;
|
18697 | syncPoint = {
|
18698 | time: discontinuitySync.time,
|
18699 | segmentIndex: segmentIndex
|
18700 | };
|
18701 | }
|
18702 | }
|
18703 | }
|
18704 | }
|
18705 |
|
18706 | return syncPoint;
|
18707 | }
|
18708 | },
|
18709 |
|
18710 | {
|
18711 | name: 'Playlist',
|
18712 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
18713 | if (playlist.syncInfo) {
|
18714 | var syncPoint = {
|
18715 | time: playlist.syncInfo.time,
|
18716 | segmentIndex: playlist.syncInfo.mediaSequence - playlist.mediaSequence
|
18717 | };
|
18718 | return syncPoint;
|
18719 | }
|
18720 |
|
18721 | return null;
|
18722 | }
|
18723 | }];
|
18724 |
|
18725 | var SyncController = function (_videojs$EventTarget) {
|
18726 | _inheritsLoose__default['default'](SyncController, _videojs$EventTarget);
|
18727 |
|
18728 | function SyncController(options) {
|
18729 | var _this;
|
18730 |
|
18731 | _this = _videojs$EventTarget.call(this) || this;
|
18732 |
|
18733 | _this.timelines = [];
|
18734 | _this.discontinuities = [];
|
18735 | _this.timelineToDatetimeMappings = {};
|
18736 | _this.logger_ = logger('SyncController');
|
18737 | return _this;
|
18738 | }
|
18739 | |
18740 |
|
18741 |
|
18742 |
|
18743 |
|
18744 |
|
18745 |
|
18746 |
|
18747 |
|
18748 |
|
18749 |
|
18750 |
|
18751 |
|
18752 |
|
18753 |
|
18754 |
|
18755 |
|
18756 | var _proto = SyncController.prototype;
|
18757 |
|
18758 | _proto.getSyncPoint = function getSyncPoint(playlist, duration, currentTimeline, currentTime) {
|
18759 | var syncPoints = this.runStrategies_(playlist, duration, currentTimeline, currentTime);
|
18760 |
|
18761 | if (!syncPoints.length) {
|
18762 |
|
18763 |
|
18764 |
|
18765 | return null;
|
18766 | }
|
18767 |
|
18768 |
|
18769 |
|
18770 |
|
18771 | return this.selectSyncPoint_(syncPoints, {
|
18772 | key: 'time',
|
18773 | value: currentTime
|
18774 | });
|
18775 | }
|
18776 | |
18777 |
|
18778 |
|
18779 |
|
18780 |
|
18781 |
|
18782 |
|
18783 |
|
18784 |
|
18785 |
|
18786 |
|
18787 | ;
|
18788 |
|
18789 | _proto.getExpiredTime = function getExpiredTime(playlist, duration) {
|
18790 | if (!playlist || !playlist.segments) {
|
18791 | return null;
|
18792 | }
|
18793 |
|
18794 | var syncPoints = this.runStrategies_(playlist, duration, playlist.discontinuitySequence, 0);
|
18795 |
|
18796 | if (!syncPoints.length) {
|
18797 | return null;
|
18798 | }
|
18799 |
|
18800 | var syncPoint = this.selectSyncPoint_(syncPoints, {
|
18801 | key: 'segmentIndex',
|
18802 | value: 0
|
18803 | });
|
18804 |
|
18805 |
|
18806 | if (syncPoint.segmentIndex > 0) {
|
18807 | syncPoint.time *= -1;
|
18808 | }
|
18809 |
|
18810 | return Math.abs(syncPoint.time + sumDurations(playlist, syncPoint.segmentIndex, 0));
|
18811 | }
|
18812 | |
18813 |
|
18814 |
|
18815 |
|
18816 |
|
18817 |
|
18818 |
|
18819 |
|
18820 |
|
18821 |
|
18822 |
|
18823 |
|
18824 |
|
18825 |
|
18826 | ;
|
18827 |
|
18828 | _proto.runStrategies_ = function runStrategies_(playlist, duration, currentTimeline, currentTime) {
|
18829 | var syncPoints = [];
|
18830 |
|
18831 | for (var i = 0; i < syncPointStrategies.length; i++) {
|
18832 | var strategy = syncPointStrategies[i];
|
18833 | var syncPoint = strategy.run(this, playlist, duration, currentTimeline, currentTime);
|
18834 |
|
18835 | if (syncPoint) {
|
18836 | syncPoint.strategy = strategy.name;
|
18837 | syncPoints.push({
|
18838 | strategy: strategy.name,
|
18839 | syncPoint: syncPoint
|
18840 | });
|
18841 | }
|
18842 | }
|
18843 |
|
18844 | return syncPoints;
|
18845 | }
|
18846 | |
18847 |
|
18848 |
|
18849 |
|
18850 |
|
18851 |
|
18852 |
|
18853 |
|
18854 |
|
18855 |
|
18856 |
|
18857 |
|
18858 |
|
18859 |
|
18860 |
|
18861 | ;
|
18862 |
|
18863 | _proto.selectSyncPoint_ = function selectSyncPoint_(syncPoints, target) {
|
18864 | var bestSyncPoint = syncPoints[0].syncPoint;
|
18865 | var bestDistance = Math.abs(syncPoints[0].syncPoint[target.key] - target.value);
|
18866 | var bestStrategy = syncPoints[0].strategy;
|
18867 |
|
18868 | for (var i = 1; i < syncPoints.length; i++) {
|
18869 | var newDistance = Math.abs(syncPoints[i].syncPoint[target.key] - target.value);
|
18870 |
|
18871 | if (newDistance < bestDistance) {
|
18872 | bestDistance = newDistance;
|
18873 | bestSyncPoint = syncPoints[i].syncPoint;
|
18874 | bestStrategy = syncPoints[i].strategy;
|
18875 | }
|
18876 | }
|
18877 |
|
18878 | this.logger_("syncPoint for [" + target.key + ": " + target.value + "] chosen with strategy" + (" [" + bestStrategy + "]: [time:" + bestSyncPoint.time + ",") + (" segmentIndex:" + bestSyncPoint.segmentIndex + "]"));
|
18879 | return bestSyncPoint;
|
18880 | }
|
18881 | |
18882 |
|
18883 |
|
18884 |
|
18885 |
|
18886 |
|
18887 |
|
18888 |
|
18889 | ;
|
18890 |
|
18891 | _proto.saveExpiredSegmentInfo = function saveExpiredSegmentInfo(oldPlaylist, newPlaylist) {
|
18892 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
18893 |
|
18894 |
|
18895 | for (var i = mediaSequenceDiff - 1; i >= 0; i--) {
|
18896 | var lastRemovedSegment = oldPlaylist.segments[i];
|
18897 |
|
18898 | if (lastRemovedSegment && typeof lastRemovedSegment.start !== 'undefined') {
|
18899 | newPlaylist.syncInfo = {
|
18900 | mediaSequence: oldPlaylist.mediaSequence + i,
|
18901 | time: lastRemovedSegment.start
|
18902 | };
|
18903 | this.logger_("playlist refresh sync: [time:" + newPlaylist.syncInfo.time + "," + (" mediaSequence: " + newPlaylist.syncInfo.mediaSequence + "]"));
|
18904 | this.trigger('syncinfoupdate');
|
18905 | break;
|
18906 | }
|
18907 | }
|
18908 | }
|
18909 | |
18910 |
|
18911 |
|
18912 |
|
18913 |
|
18914 |
|
18915 | ;
|
18916 |
|
18917 | _proto.setDateTimeMappingForStart = function setDateTimeMappingForStart(playlist) {
|
18918 |
|
18919 |
|
18920 |
|
18921 |
|
18922 | this.timelineToDatetimeMappings = {};
|
18923 |
|
18924 | if (playlist.segments && playlist.segments.length && playlist.segments[0].dateTimeObject) {
|
18925 | var firstSegment = playlist.segments[0];
|
18926 | var playlistTimestamp = firstSegment.dateTimeObject.getTime() / 1000;
|
18927 | this.timelineToDatetimeMappings[firstSegment.timeline] = -playlistTimestamp;
|
18928 | }
|
18929 | }
|
18930 | |
18931 |
|
18932 |
|
18933 |
|
18934 |
|
18935 |
|
18936 |
|
18937 |
|
18938 |
|
18939 |
|
18940 |
|
18941 |
|
18942 | ;
|
18943 |
|
18944 | _proto.saveSegmentTimingInfo = function saveSegmentTimingInfo(_ref) {
|
18945 | var segmentInfo = _ref.segmentInfo,
|
18946 | shouldSaveTimelineMapping = _ref.shouldSaveTimelineMapping;
|
18947 | var didCalculateSegmentTimeMapping = this.calculateSegmentTimeMapping_(segmentInfo, segmentInfo.timingInfo, shouldSaveTimelineMapping);
|
18948 | var segment = segmentInfo.segment;
|
18949 |
|
18950 | if (didCalculateSegmentTimeMapping) {
|
18951 | this.saveDiscontinuitySyncInfo_(segmentInfo);
|
18952 |
|
18953 |
|
18954 | if (!segmentInfo.playlist.syncInfo) {
|
18955 | segmentInfo.playlist.syncInfo = {
|
18956 | mediaSequence: segmentInfo.playlist.mediaSequence + segmentInfo.mediaIndex,
|
18957 | time: segment.start
|
18958 | };
|
18959 | }
|
18960 | }
|
18961 |
|
18962 | var dateTime = segment.dateTimeObject;
|
18963 |
|
18964 | if (segment.discontinuity && shouldSaveTimelineMapping && dateTime) {
|
18965 | this.timelineToDatetimeMappings[segment.timeline] = -(dateTime.getTime() / 1000);
|
18966 | }
|
18967 | };
|
18968 |
|
18969 | _proto.timestampOffsetForTimeline = function timestampOffsetForTimeline(timeline) {
|
18970 | if (typeof this.timelines[timeline] === 'undefined') {
|
18971 | return null;
|
18972 | }
|
18973 |
|
18974 | return this.timelines[timeline].time;
|
18975 | };
|
18976 |
|
18977 | _proto.mappingForTimeline = function mappingForTimeline(timeline) {
|
18978 | if (typeof this.timelines[timeline] === 'undefined') {
|
18979 | return null;
|
18980 | }
|
18981 |
|
18982 | return this.timelines[timeline].mapping;
|
18983 | }
|
18984 | |
18985 |
|
18986 |
|
18987 |
|
18988 |
|
18989 |
|
18990 |
|
18991 |
|
18992 |
|
18993 |
|
18994 |
|
18995 |
|
18996 |
|
18997 |
|
18998 |
|
18999 | ;
|
19000 |
|
19001 | _proto.calculateSegmentTimeMapping_ = function calculateSegmentTimeMapping_(segmentInfo, timingInfo, shouldSaveTimelineMapping) {
|
19002 | var segment = segmentInfo.segment;
|
19003 | var mappingObj = this.timelines[segmentInfo.timeline];
|
19004 |
|
19005 | if (typeof segmentInfo.timestampOffset === 'number') {
|
19006 | mappingObj = {
|
19007 | time: segmentInfo.startOfSegment,
|
19008 | mapping: segmentInfo.startOfSegment - timingInfo.start
|
19009 | };
|
19010 |
|
19011 | if (shouldSaveTimelineMapping) {
|
19012 | this.timelines[segmentInfo.timeline] = mappingObj;
|
19013 | this.trigger('timestampoffset');
|
19014 | this.logger_("time mapping for timeline " + segmentInfo.timeline + ": " + ("[time: " + mappingObj.time + "] [mapping: " + mappingObj.mapping + "]"));
|
19015 | }
|
19016 |
|
19017 | segment.start = segmentInfo.startOfSegment;
|
19018 | segment.end = timingInfo.end + mappingObj.mapping;
|
19019 | } else if (mappingObj) {
|
19020 | segment.start = timingInfo.start + mappingObj.mapping;
|
19021 | segment.end = timingInfo.end + mappingObj.mapping;
|
19022 | } else {
|
19023 | return false;
|
19024 | }
|
19025 |
|
19026 | return true;
|
19027 | }
|
19028 | |
19029 |
|
19030 |
|
19031 |
|
19032 |
|
19033 |
|
19034 |
|
19035 |
|
19036 | ;
|
19037 |
|
19038 | _proto.saveDiscontinuitySyncInfo_ = function saveDiscontinuitySyncInfo_(segmentInfo) {
|
19039 | var playlist = segmentInfo.playlist;
|
19040 | var segment = segmentInfo.segment;
|
19041 |
|
19042 |
|
19043 |
|
19044 | if (segment.discontinuity) {
|
19045 | this.discontinuities[segment.timeline] = {
|
19046 | time: segment.start,
|
19047 | accuracy: 0
|
19048 | };
|
19049 | } else if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
19050 |
|
19051 |
|
19052 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
19053 | var segmentIndex = playlist.discontinuityStarts[i];
|
19054 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
19055 | var mediaIndexDiff = segmentIndex - segmentInfo.mediaIndex;
|
19056 | var accuracy = Math.abs(mediaIndexDiff);
|
19057 |
|
19058 | if (!this.discontinuities[discontinuity] || this.discontinuities[discontinuity].accuracy > accuracy) {
|
19059 | var time = void 0;
|
19060 |
|
19061 | if (mediaIndexDiff < 0) {
|
19062 | time = segment.start - sumDurations(playlist, segmentInfo.mediaIndex, segmentIndex);
|
19063 | } else {
|
19064 | time = segment.end + sumDurations(playlist, segmentInfo.mediaIndex + 1, segmentIndex);
|
19065 | }
|
19066 |
|
19067 | this.discontinuities[discontinuity] = {
|
19068 | time: time,
|
19069 | accuracy: accuracy
|
19070 | };
|
19071 | }
|
19072 | }
|
19073 | }
|
19074 | };
|
19075 |
|
19076 | _proto.dispose = function dispose() {
|
19077 | this.trigger('dispose');
|
19078 | this.off();
|
19079 | };
|
19080 |
|
19081 | return SyncController;
|
19082 | }(videojs__default['default'].EventTarget);
|
19083 |
|
19084 |
|
19085 |
|
19086 |
|
19087 |
|
19088 |
|
19089 |
|
19090 |
|
19091 |
|
19092 |
|
19093 |
|
19094 | var TimelineChangeController = function (_videojs$EventTarget) {
|
19095 | _inheritsLoose__default['default'](TimelineChangeController, _videojs$EventTarget);
|
19096 |
|
19097 | function TimelineChangeController() {
|
19098 | var _this;
|
19099 |
|
19100 | _this = _videojs$EventTarget.call(this) || this;
|
19101 | _this.pendingTimelineChanges_ = {};
|
19102 | _this.lastTimelineChanges_ = {};
|
19103 | return _this;
|
19104 | }
|
19105 |
|
19106 | var _proto = TimelineChangeController.prototype;
|
19107 |
|
19108 | _proto.clearPendingTimelineChange = function clearPendingTimelineChange(type) {
|
19109 | this.pendingTimelineChanges_[type] = null;
|
19110 | this.trigger('pendingtimelinechange');
|
19111 | };
|
19112 |
|
19113 | _proto.pendingTimelineChange = function pendingTimelineChange(_ref) {
|
19114 | var type = _ref.type,
|
19115 | from = _ref.from,
|
19116 | to = _ref.to;
|
19117 |
|
19118 | if (typeof from === 'number' && typeof to === 'number') {
|
19119 | this.pendingTimelineChanges_[type] = {
|
19120 | type: type,
|
19121 | from: from,
|
19122 | to: to
|
19123 | };
|
19124 | this.trigger('pendingtimelinechange');
|
19125 | }
|
19126 |
|
19127 | return this.pendingTimelineChanges_[type];
|
19128 | };
|
19129 |
|
19130 | _proto.lastTimelineChange = function lastTimelineChange(_ref2) {
|
19131 | var type = _ref2.type,
|
19132 | from = _ref2.from,
|
19133 | to = _ref2.to;
|
19134 |
|
19135 | if (typeof from === 'number' && typeof to === 'number') {
|
19136 | this.lastTimelineChanges_[type] = {
|
19137 | type: type,
|
19138 | from: from,
|
19139 | to: to
|
19140 | };
|
19141 | delete this.pendingTimelineChanges_[type];
|
19142 | this.trigger('timelinechange');
|
19143 | }
|
19144 |
|
19145 | return this.lastTimelineChanges_[type];
|
19146 | };
|
19147 |
|
19148 | _proto.dispose = function dispose() {
|
19149 | this.trigger('dispose');
|
19150 | this.pendingTimelineChanges_ = {};
|
19151 | this.lastTimelineChanges_ = {};
|
19152 | this.off();
|
19153 | };
|
19154 |
|
19155 | return TimelineChangeController;
|
19156 | }(videojs__default['default'].EventTarget);
|
19157 |
|
19158 |
|
19159 | var workerCode = transform(getWorkerString(function () {
|
19160 |
|
19161 | function createCommonjsModule(fn, basedir, module) {
|
19162 | return module = {
|
19163 | path: basedir,
|
19164 | exports: {},
|
19165 | require: function require(path, base) {
|
19166 | return commonjsRequire(path, base === undefined || base === null ? module.path : base);
|
19167 | }
|
19168 | }, fn(module, module.exports), module.exports;
|
19169 | }
|
19170 |
|
19171 | function commonjsRequire() {
|
19172 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
19173 | }
|
19174 |
|
19175 | var createClass = createCommonjsModule(function (module) {
|
19176 | function _defineProperties(target, props) {
|
19177 | for (var i = 0; i < props.length; i++) {
|
19178 | var descriptor = props[i];
|
19179 | descriptor.enumerable = descriptor.enumerable || false;
|
19180 | descriptor.configurable = true;
|
19181 | if ("value" in descriptor) descriptor.writable = true;
|
19182 | Object.defineProperty(target, descriptor.key, descriptor);
|
19183 | }
|
19184 | }
|
19185 |
|
19186 | function _createClass(Constructor, protoProps, staticProps) {
|
19187 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
19188 | if (staticProps) _defineProperties(Constructor, staticProps);
|
19189 | return Constructor;
|
19190 | }
|
19191 |
|
19192 | module.exports = _createClass;
|
19193 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
19194 | });
|
19195 | var setPrototypeOf = createCommonjsModule(function (module) {
|
19196 | function _setPrototypeOf(o, p) {
|
19197 | module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
19198 | o.__proto__ = p;
|
19199 | return o;
|
19200 | };
|
19201 |
|
19202 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
19203 | return _setPrototypeOf(o, p);
|
19204 | }
|
19205 |
|
19206 | module.exports = _setPrototypeOf;
|
19207 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
19208 | });
|
19209 | var inheritsLoose = createCommonjsModule(function (module) {
|
19210 | function _inheritsLoose(subClass, superClass) {
|
19211 | subClass.prototype = Object.create(superClass.prototype);
|
19212 | subClass.prototype.constructor = subClass;
|
19213 | setPrototypeOf(subClass, superClass);
|
19214 | }
|
19215 |
|
19216 | module.exports = _inheritsLoose;
|
19217 | module.exports["default"] = module.exports, module.exports.__esModule = true;
|
19218 | });
|
19219 | |
19220 |
|
19221 |
|
19222 |
|
19223 | |
19224 |
|
19225 |
|
19226 |
|
19227 |
|
19228 |
|
19229 | var Stream = function () {
|
19230 | function Stream() {
|
19231 | this.listeners = {};
|
19232 | }
|
19233 | |
19234 |
|
19235 |
|
19236 |
|
19237 |
|
19238 |
|
19239 |
|
19240 |
|
19241 |
|
19242 | var _proto = Stream.prototype;
|
19243 |
|
19244 | _proto.on = function on(type, listener) {
|
19245 | if (!this.listeners[type]) {
|
19246 | this.listeners[type] = [];
|
19247 | }
|
19248 |
|
19249 | this.listeners[type].push(listener);
|
19250 | }
|
19251 | |
19252 |
|
19253 |
|
19254 |
|
19255 |
|
19256 |
|
19257 |
|
19258 |
|
19259 | ;
|
19260 |
|
19261 | _proto.off = function off(type, listener) {
|
19262 | if (!this.listeners[type]) {
|
19263 | return false;
|
19264 | }
|
19265 |
|
19266 | var index = this.listeners[type].indexOf(listener);
|
19267 |
|
19268 |
|
19269 |
|
19270 |
|
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 | this.listeners[type] = this.listeners[type].slice(0);
|
19276 | this.listeners[type].splice(index, 1);
|
19277 | return index > -1;
|
19278 | }
|
19279 | |
19280 |
|
19281 |
|
19282 |
|
19283 |
|
19284 |
|
19285 | ;
|
19286 |
|
19287 | _proto.trigger = function trigger(type) {
|
19288 | var callbacks = this.listeners[type];
|
19289 |
|
19290 | if (!callbacks) {
|
19291 | return;
|
19292 | }
|
19293 |
|
19294 |
|
19295 |
|
19296 |
|
19297 |
|
19298 | if (arguments.length === 2) {
|
19299 | var length = callbacks.length;
|
19300 |
|
19301 | for (var i = 0; i < length; ++i) {
|
19302 | callbacks[i].call(this, arguments[1]);
|
19303 | }
|
19304 | } else {
|
19305 | var args = Array.prototype.slice.call(arguments, 1);
|
19306 | var _length = callbacks.length;
|
19307 |
|
19308 | for (var _i = 0; _i < _length; ++_i) {
|
19309 | callbacks[_i].apply(this, args);
|
19310 | }
|
19311 | }
|
19312 | }
|
19313 | |
19314 |
|
19315 |
|
19316 | ;
|
19317 |
|
19318 | _proto.dispose = function dispose() {
|
19319 | this.listeners = {};
|
19320 | }
|
19321 | |
19322 |
|
19323 |
|
19324 |
|
19325 |
|
19326 |
|
19327 |
|
19328 |
|
19329 | ;
|
19330 |
|
19331 | _proto.pipe = function pipe(destination) {
|
19332 | this.on('data', function (data) {
|
19333 | destination.push(data);
|
19334 | });
|
19335 | };
|
19336 |
|
19337 | return Stream;
|
19338 | }();
|
19339 |
|
19340 |
|
19341 | |
19342 |
|
19343 |
|
19344 |
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 |
|
19350 | function unpad(padded) {
|
19351 | return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
|
19352 | }
|
19353 |
|
19354 |
|
19355 | |
19356 |
|
19357 |
|
19358 |
|
19359 |
|
19360 |
|
19361 |
|
19362 |
|
19363 |
|
19364 |
|
19365 |
|
19366 |
|
19367 |
|
19368 |
|
19369 |
|
19370 |
|
19371 |
|
19372 |
|
19373 |
|
19374 |
|
19375 |
|
19376 |
|
19377 |
|
19378 |
|
19379 |
|
19380 |
|
19381 |
|
19382 |
|
19383 |
|
19384 |
|
19385 |
|
19386 |
|
19387 |
|
19388 |
|
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 | |
19395 |
|
19396 |
|
19397 |
|
19398 |
|
19399 |
|
19400 |
|
19401 | var precompute = function precompute() {
|
19402 | var tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
19403 | var encTable = tables[0];
|
19404 | var decTable = tables[1];
|
19405 | var sbox = encTable[4];
|
19406 | var sboxInv = decTable[4];
|
19407 | var i;
|
19408 | var x;
|
19409 | var xInv;
|
19410 | var d = [];
|
19411 | var th = [];
|
19412 | var x2;
|
19413 | var x4;
|
19414 | var x8;
|
19415 | var s;
|
19416 | var tEnc;
|
19417 | var tDec;
|
19418 |
|
19419 | for (i = 0; i < 256; i++) {
|
19420 | th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
19421 | }
|
19422 |
|
19423 | for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
19424 |
|
19425 | s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
19426 | s = s >> 8 ^ s & 255 ^ 99;
|
19427 | sbox[x] = s;
|
19428 | sboxInv[s] = x;
|
19429 |
|
19430 | x8 = d[x4 = d[x2 = d[x]]];
|
19431 | tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
19432 | tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
19433 |
|
19434 | for (i = 0; i < 4; i++) {
|
19435 | encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
19436 | decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
19437 | }
|
19438 | }
|
19439 |
|
19440 |
|
19441 | for (i = 0; i < 5; i++) {
|
19442 | encTable[i] = encTable[i].slice(0);
|
19443 | decTable[i] = decTable[i].slice(0);
|
19444 | }
|
19445 |
|
19446 | return tables;
|
19447 | };
|
19448 |
|
19449 | var aesTables = null;
|
19450 | |
19451 |
|
19452 |
|
19453 |
|
19454 |
|
19455 |
|
19456 |
|
19457 |
|
19458 | var AES = function () {
|
19459 | function AES(key) {
|
19460 | |
19461 |
|
19462 |
|
19463 |
|
19464 |
|
19465 |
|
19466 |
|
19467 |
|
19468 |
|
19469 |
|
19470 |
|
19471 |
|
19472 |
|
19473 |
|
19474 | if (!aesTables) {
|
19475 | aesTables = precompute();
|
19476 | }
|
19477 |
|
19478 |
|
19479 | 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()]];
|
19480 | var i;
|
19481 | var j;
|
19482 | var tmp;
|
19483 | var sbox = this._tables[0][4];
|
19484 | var decTable = this._tables[1];
|
19485 | var keyLen = key.length;
|
19486 | var rcon = 1;
|
19487 |
|
19488 | if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
19489 | throw new Error('Invalid aes key size');
|
19490 | }
|
19491 |
|
19492 | var encKey = key.slice(0);
|
19493 | var decKey = [];
|
19494 | this._key = [encKey, decKey];
|
19495 |
|
19496 | for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
19497 | tmp = encKey[i - 1];
|
19498 |
|
19499 | if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
|
19500 | tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
19501 |
|
19502 | if (i % keyLen === 0) {
|
19503 | tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
19504 | rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
19505 | }
|
19506 | }
|
19507 |
|
19508 | encKey[i] = encKey[i - keyLen] ^ tmp;
|
19509 | }
|
19510 |
|
19511 |
|
19512 | for (j = 0; i; j++, i--) {
|
19513 | tmp = encKey[j & 3 ? i : i - 4];
|
19514 |
|
19515 | if (i <= 4 || j < 4) {
|
19516 | decKey[j] = tmp;
|
19517 | } else {
|
19518 | decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
|
19519 | }
|
19520 | }
|
19521 | }
|
19522 | |
19523 |
|
19524 |
|
19525 |
|
19526 |
|
19527 |
|
19528 |
|
19529 |
|
19530 |
|
19531 |
|
19532 |
|
19533 |
|
19534 |
|
19535 |
|
19536 |
|
19537 | var _proto = AES.prototype;
|
19538 |
|
19539 | _proto.decrypt = function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
|
19540 | var key = this._key[1];
|
19541 |
|
19542 | var a = encrypted0 ^ key[0];
|
19543 | var b = encrypted3 ^ key[1];
|
19544 | var c = encrypted2 ^ key[2];
|
19545 | var d = encrypted1 ^ key[3];
|
19546 | var a2;
|
19547 | var b2;
|
19548 | var c2;
|
19549 |
|
19550 | var nInnerRounds = key.length / 4 - 2;
|
19551 | var i;
|
19552 | var kIndex = 4;
|
19553 | var table = this._tables[1];
|
19554 |
|
19555 | var table0 = table[0];
|
19556 | var table1 = table[1];
|
19557 | var table2 = table[2];
|
19558 | var table3 = table[3];
|
19559 | var sbox = table[4];
|
19560 |
|
19561 | for (i = 0; i < nInnerRounds; i++) {
|
19562 | a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
|
19563 | b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
|
19564 | c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
|
19565 | d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
|
19566 | kIndex += 4;
|
19567 | a = a2;
|
19568 | b = b2;
|
19569 | c = c2;
|
19570 | }
|
19571 |
|
19572 |
|
19573 | for (i = 0; i < 4; i++) {
|
19574 | out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
|
19575 | a2 = a;
|
19576 | a = b;
|
19577 | b = c;
|
19578 | c = d;
|
19579 | d = a2;
|
19580 | }
|
19581 | };
|
19582 |
|
19583 | return AES;
|
19584 | }();
|
19585 | |
19586 |
|
19587 |
|
19588 |
|
19589 |
|
19590 |
|
19591 |
|
19592 |
|
19593 |
|
19594 | var AsyncStream = function (_Stream) {
|
19595 | inheritsLoose(AsyncStream, _Stream);
|
19596 |
|
19597 | function AsyncStream() {
|
19598 | var _this;
|
19599 |
|
19600 | _this = _Stream.call(this, Stream) || this;
|
19601 | _this.jobs = [];
|
19602 | _this.delay = 1;
|
19603 | _this.timeout_ = null;
|
19604 | return _this;
|
19605 | }
|
19606 | |
19607 |
|
19608 |
|
19609 |
|
19610 |
|
19611 |
|
19612 |
|
19613 | var _proto = AsyncStream.prototype;
|
19614 |
|
19615 | _proto.processJob_ = function processJob_() {
|
19616 | this.jobs.shift()();
|
19617 |
|
19618 | if (this.jobs.length) {
|
19619 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
19620 | } else {
|
19621 | this.timeout_ = null;
|
19622 | }
|
19623 | }
|
19624 | |
19625 |
|
19626 |
|
19627 |
|
19628 |
|
19629 | ;
|
19630 |
|
19631 | _proto.push = function push(job) {
|
19632 | this.jobs.push(job);
|
19633 |
|
19634 | if (!this.timeout_) {
|
19635 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
19636 | }
|
19637 | };
|
19638 |
|
19639 | return AsyncStream;
|
19640 | }(Stream);
|
19641 | |
19642 |
|
19643 |
|
19644 |
|
19645 |
|
19646 |
|
19647 | var ntoh = function ntoh(word) {
|
19648 | return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
|
19649 | };
|
19650 | |
19651 |
|
19652 |
|
19653 |
|
19654 |
|
19655 |
|
19656 |
|
19657 |
|
19658 |
|
19659 |
|
19660 |
|
19661 |
|
19662 |
|
19663 |
|
19664 |
|
19665 | var decrypt = function decrypt(encrypted, key, initVector) {
|
19666 |
|
19667 | var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
|
19668 | var decipher = new AES(Array.prototype.slice.call(key));
|
19669 |
|
19670 | var decrypted = new Uint8Array(encrypted.byteLength);
|
19671 | var decrypted32 = new Int32Array(decrypted.buffer);
|
19672 |
|
19673 |
|
19674 | var init0;
|
19675 | var init1;
|
19676 | var init2;
|
19677 | var init3;
|
19678 | var encrypted0;
|
19679 | var encrypted1;
|
19680 | var encrypted2;
|
19681 | var encrypted3;
|
19682 |
|
19683 | var wordIx;
|
19684 |
|
19685 |
|
19686 | init0 = initVector[0];
|
19687 | init1 = initVector[1];
|
19688 | init2 = initVector[2];
|
19689 | init3 = initVector[3];
|
19690 |
|
19691 |
|
19692 | for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
|
19693 |
|
19694 |
|
19695 | encrypted0 = ntoh(encrypted32[wordIx]);
|
19696 | encrypted1 = ntoh(encrypted32[wordIx + 1]);
|
19697 | encrypted2 = ntoh(encrypted32[wordIx + 2]);
|
19698 | encrypted3 = ntoh(encrypted32[wordIx + 3]);
|
19699 |
|
19700 | decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
|
19701 |
|
19702 |
|
19703 | decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
|
19704 | decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
|
19705 | decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
|
19706 | decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
|
19707 |
|
19708 | init0 = encrypted0;
|
19709 | init1 = encrypted1;
|
19710 | init2 = encrypted2;
|
19711 | init3 = encrypted3;
|
19712 | }
|
19713 |
|
19714 | return decrypted;
|
19715 | };
|
19716 | |
19717 |
|
19718 |
|
19719 |
|
19720 |
|
19721 |
|
19722 |
|
19723 |
|
19724 |
|
19725 |
|
19726 |
|
19727 |
|
19728 |
|
19729 | var Decrypter = function () {
|
19730 | function Decrypter(encrypted, key, initVector, done) {
|
19731 | var step = Decrypter.STEP;
|
19732 | var encrypted32 = new Int32Array(encrypted.buffer);
|
19733 | var decrypted = new Uint8Array(encrypted.byteLength);
|
19734 | var i = 0;
|
19735 | this.asyncStream_ = new AsyncStream();
|
19736 |
|
19737 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
19738 |
|
19739 | for (i = step; i < encrypted32.length; i += step) {
|
19740 | initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
|
19741 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
19742 | }
|
19743 |
|
19744 |
|
19745 | this.asyncStream_.push(function () {
|
19746 |
|
19747 | done(null, unpad(decrypted));
|
19748 | });
|
19749 | }
|
19750 | |
19751 |
|
19752 |
|
19753 |
|
19754 |
|
19755 |
|
19756 |
|
19757 | var _proto = Decrypter.prototype;
|
19758 | |
19759 |
|
19760 |
|
19761 |
|
19762 | _proto.decryptChunk_ = function decryptChunk_(encrypted, key, initVector, decrypted) {
|
19763 | return function () {
|
19764 | var bytes = decrypt(encrypted, key, initVector);
|
19765 | decrypted.set(bytes, encrypted.byteOffset);
|
19766 | };
|
19767 | };
|
19768 |
|
19769 | createClass(Decrypter, null, [{
|
19770 | key: "STEP",
|
19771 | get: function get() {
|
19772 |
|
19773 | return 32000;
|
19774 | }
|
19775 | }]);
|
19776 | return Decrypter;
|
19777 | }();
|
19778 | |
19779 |
|
19780 |
|
19781 |
|
19782 | |
19783 |
|
19784 |
|
19785 |
|
19786 |
|
19787 |
|
19788 |
|
19789 |
|
19790 |
|
19791 |
|
19792 |
|
19793 |
|
19794 | var createTransferableMessage = function createTransferableMessage(message) {
|
19795 | var transferable = {};
|
19796 | Object.keys(message).forEach(function (key) {
|
19797 | var value = message[key];
|
19798 |
|
19799 | if (ArrayBuffer.isView(value)) {
|
19800 | transferable[key] = {
|
19801 | bytes: value.buffer,
|
19802 | byteOffset: value.byteOffset,
|
19803 | byteLength: value.byteLength
|
19804 | };
|
19805 | } else {
|
19806 | transferable[key] = value;
|
19807 | }
|
19808 | });
|
19809 | return transferable;
|
19810 | };
|
19811 |
|
19812 |
|
19813 | |
19814 |
|
19815 |
|
19816 |
|
19817 |
|
19818 |
|
19819 |
|
19820 | self.onmessage = function (event) {
|
19821 | var data = event.data;
|
19822 | var encrypted = new Uint8Array(data.encrypted.bytes, data.encrypted.byteOffset, data.encrypted.byteLength);
|
19823 | var key = new Uint32Array(data.key.bytes, data.key.byteOffset, data.key.byteLength / 4);
|
19824 | var iv = new Uint32Array(data.iv.bytes, data.iv.byteOffset, data.iv.byteLength / 4);
|
19825 |
|
19826 |
|
19827 | new Decrypter(encrypted, key, iv, function (err, bytes) {
|
19828 | self.postMessage(createTransferableMessage({
|
19829 | source: data.source,
|
19830 | decrypted: bytes
|
19831 | }), [bytes.buffer]);
|
19832 | });
|
19833 |
|
19834 | };
|
19835 | }));
|
19836 | var Decrypter = factory(workerCode);
|
19837 |
|
19838 |
|
19839 |
|
19840 |
|
19841 |
|
19842 |
|
19843 |
|
19844 |
|
19845 | var audioTrackKind_ = function audioTrackKind_(properties) {
|
19846 | var kind = properties.default ? 'main' : 'alternative';
|
19847 |
|
19848 | if (properties.characteristics && properties.characteristics.indexOf('public.accessibility.describes-video') >= 0) {
|
19849 | kind = 'main-desc';
|
19850 | }
|
19851 |
|
19852 | return kind;
|
19853 | };
|
19854 |
|
19855 |
|
19856 |
|
19857 |
|
19858 |
|
19859 |
|
19860 |
|
19861 |
|
19862 |
|
19863 |
|
19864 |
|
19865 | var stopLoaders = function stopLoaders(segmentLoader, mediaType) {
|
19866 | segmentLoader.abort();
|
19867 | segmentLoader.pause();
|
19868 |
|
19869 | if (mediaType && mediaType.activePlaylistLoader) {
|
19870 | mediaType.activePlaylistLoader.pause();
|
19871 | mediaType.activePlaylistLoader = null;
|
19872 | }
|
19873 | };
|
19874 |
|
19875 |
|
19876 |
|
19877 |
|
19878 |
|
19879 |
|
19880 |
|
19881 |
|
19882 |
|
19883 |
|
19884 | var startLoaders = function startLoaders(playlistLoader, mediaType) {
|
19885 |
|
19886 |
|
19887 | mediaType.activePlaylistLoader = playlistLoader;
|
19888 | playlistLoader.load();
|
19889 | };
|
19890 |
|
19891 |
|
19892 |
|
19893 |
|
19894 |
|
19895 |
|
19896 |
|
19897 |
|
19898 |
|
19899 |
|
19900 |
|
19901 |
|
19902 |
|
19903 |
|
19904 |
|
19905 |
|
19906 | var onGroupChanged = function onGroupChanged(type, settings) {
|
19907 | return function () {
|
19908 | var _settings$segmentLoad = settings.segmentLoaders,
|
19909 | segmentLoader = _settings$segmentLoad[type],
|
19910 | mainSegmentLoader = _settings$segmentLoad.main,
|
19911 | mediaType = settings.mediaTypes[type];
|
19912 | var activeTrack = mediaType.activeTrack();
|
19913 | var activeGroup = mediaType.getActiveGroup();
|
19914 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
19915 | var lastGroup = mediaType.lastGroup_;
|
19916 |
|
19917 | if (activeGroup && lastGroup && activeGroup.id === lastGroup.id) {
|
19918 | return;
|
19919 | }
|
19920 |
|
19921 | mediaType.lastGroup_ = activeGroup;
|
19922 | mediaType.lastTrack_ = activeTrack;
|
19923 | stopLoaders(segmentLoader, mediaType);
|
19924 |
|
19925 | if (!activeGroup || activeGroup.isMasterPlaylist) {
|
19926 |
|
19927 | return;
|
19928 | }
|
19929 |
|
19930 | if (!activeGroup.playlistLoader) {
|
19931 | if (previousActiveLoader) {
|
19932 |
|
19933 |
|
19934 |
|
19935 |
|
19936 | mainSegmentLoader.resetEverything();
|
19937 | }
|
19938 |
|
19939 | return;
|
19940 | }
|
19941 |
|
19942 |
|
19943 | segmentLoader.resyncLoader();
|
19944 | startLoaders(activeGroup.playlistLoader, mediaType);
|
19945 | };
|
19946 | };
|
19947 | var onGroupChanging = function onGroupChanging(type, settings) {
|
19948 | return function () {
|
19949 | var segmentLoader = settings.segmentLoaders[type],
|
19950 | mediaType = settings.mediaTypes[type];
|
19951 | mediaType.lastGroup_ = null;
|
19952 | segmentLoader.abort();
|
19953 | segmentLoader.pause();
|
19954 | };
|
19955 | };
|
19956 |
|
19957 |
|
19958 |
|
19959 |
|
19960 |
|
19961 |
|
19962 |
|
19963 |
|
19964 |
|
19965 |
|
19966 |
|
19967 |
|
19968 |
|
19969 |
|
19970 |
|
19971 | var onTrackChanged = function onTrackChanged(type, settings) {
|
19972 | return function () {
|
19973 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
19974 | _settings$segmentLoad2 = settings.segmentLoaders,
|
19975 | segmentLoader = _settings$segmentLoad2[type],
|
19976 | mainSegmentLoader = _settings$segmentLoad2.main,
|
19977 | mediaType = settings.mediaTypes[type];
|
19978 | var activeTrack = mediaType.activeTrack();
|
19979 | var activeGroup = mediaType.getActiveGroup();
|
19980 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
19981 | var lastTrack = mediaType.lastTrack_;
|
19982 |
|
19983 | if (lastTrack && activeTrack && lastTrack.id === activeTrack.id) {
|
19984 | return;
|
19985 | }
|
19986 |
|
19987 | mediaType.lastGroup_ = activeGroup;
|
19988 | mediaType.lastTrack_ = activeTrack;
|
19989 | stopLoaders(segmentLoader, mediaType);
|
19990 |
|
19991 | if (!activeGroup) {
|
19992 |
|
19993 | return;
|
19994 | }
|
19995 |
|
19996 | if (activeGroup.isMasterPlaylist) {
|
19997 |
|
19998 | if (!activeTrack || !lastTrack || activeTrack.id === lastTrack.id) {
|
19999 | return;
|
20000 | }
|
20001 |
|
20002 | var mpc = settings.vhs.masterPlaylistController_;
|
20003 | var newPlaylist = mpc.selectPlaylist();
|
20004 |
|
20005 | if (mpc.media() === newPlaylist) {
|
20006 | return;
|
20007 | }
|
20008 |
|
20009 | mediaType.logger_("track change. Switching master audio from " + lastTrack.id + " to " + activeTrack.id);
|
20010 | masterPlaylistLoader.pause();
|
20011 | mainSegmentLoader.resetEverything();
|
20012 | mpc.fastQualityChange_(newPlaylist);
|
20013 | return;
|
20014 | }
|
20015 |
|
20016 | if (type === 'AUDIO') {
|
20017 | if (!activeGroup.playlistLoader) {
|
20018 |
|
20019 |
|
20020 |
|
20021 | mainSegmentLoader.setAudio(true);
|
20022 |
|
20023 |
|
20024 | mainSegmentLoader.resetEverything();
|
20025 | return;
|
20026 | }
|
20027 |
|
20028 |
|
20029 |
|
20030 |
|
20031 | segmentLoader.setAudio(true);
|
20032 | mainSegmentLoader.setAudio(false);
|
20033 | }
|
20034 |
|
20035 | if (previousActiveLoader === activeGroup.playlistLoader) {
|
20036 |
|
20037 |
|
20038 |
|
20039 | startLoaders(activeGroup.playlistLoader, mediaType);
|
20040 | return;
|
20041 | }
|
20042 |
|
20043 | if (segmentLoader.track) {
|
20044 |
|
20045 | segmentLoader.track(activeTrack);
|
20046 | }
|
20047 |
|
20048 |
|
20049 | segmentLoader.resetEverything();
|
20050 | startLoaders(activeGroup.playlistLoader, mediaType);
|
20051 | };
|
20052 | };
|
20053 | var onError = {
|
20054 | |
20055 |
|
20056 |
|
20057 |
|
20058 |
|
20059 |
|
20060 |
|
20061 |
|
20062 |
|
20063 |
|
20064 |
|
20065 |
|
20066 |
|
20067 | AUDIO: function AUDIO(type, settings) {
|
20068 | return function () {
|
20069 | var segmentLoader = settings.segmentLoaders[type],
|
20070 | mediaType = settings.mediaTypes[type],
|
20071 | blacklistCurrentPlaylist = settings.blacklistCurrentPlaylist;
|
20072 | stopLoaders(segmentLoader, mediaType);
|
20073 |
|
20074 | var activeTrack = mediaType.activeTrack();
|
20075 | var activeGroup = mediaType.activeGroup();
|
20076 | var id = (activeGroup.filter(function (group) {
|
20077 | return group.default;
|
20078 | })[0] || activeGroup[0]).id;
|
20079 | var defaultTrack = mediaType.tracks[id];
|
20080 |
|
20081 | if (activeTrack === defaultTrack) {
|
20082 |
|
20083 |
|
20084 | blacklistCurrentPlaylist({
|
20085 | message: 'Problem encountered loading the default audio track.'
|
20086 | });
|
20087 | return;
|
20088 | }
|
20089 |
|
20090 | videojs__default['default'].log.warn('Problem encountered loading the alternate audio track.' + 'Switching back to default.');
|
20091 |
|
20092 | for (var trackId in mediaType.tracks) {
|
20093 | mediaType.tracks[trackId].enabled = mediaType.tracks[trackId] === defaultTrack;
|
20094 | }
|
20095 |
|
20096 | mediaType.onTrackChanged();
|
20097 | };
|
20098 | },
|
20099 |
|
20100 | |
20101 |
|
20102 |
|
20103 |
|
20104 |
|
20105 |
|
20106 |
|
20107 |
|
20108 |
|
20109 |
|
20110 |
|
20111 |
|
20112 | SUBTITLES: function SUBTITLES(type, settings) {
|
20113 | return function () {
|
20114 | var segmentLoader = settings.segmentLoaders[type],
|
20115 | mediaType = settings.mediaTypes[type];
|
20116 | videojs__default['default'].log.warn('Problem encountered loading the subtitle track.' + 'Disabling subtitle track.');
|
20117 | stopLoaders(segmentLoader, mediaType);
|
20118 | var track = mediaType.activeTrack();
|
20119 |
|
20120 | if (track) {
|
20121 | track.mode = 'disabled';
|
20122 | }
|
20123 |
|
20124 | mediaType.onTrackChanged();
|
20125 | };
|
20126 | }
|
20127 | };
|
20128 | var setupListeners = {
|
20129 | |
20130 |
|
20131 |
|
20132 |
|
20133 |
|
20134 |
|
20135 |
|
20136 |
|
20137 |
|
20138 |
|
20139 |
|
20140 | AUDIO: function AUDIO(type, playlistLoader, settings) {
|
20141 | if (!playlistLoader) {
|
20142 |
|
20143 | return;
|
20144 | }
|
20145 |
|
20146 | var tech = settings.tech,
|
20147 | requestOptions = settings.requestOptions,
|
20148 | segmentLoader = settings.segmentLoaders[type];
|
20149 | playlistLoader.on('loadedmetadata', function () {
|
20150 | var media = playlistLoader.media();
|
20151 | segmentLoader.playlist(media, requestOptions);
|
20152 |
|
20153 |
|
20154 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
20155 | segmentLoader.load();
|
20156 | }
|
20157 | });
|
20158 | playlistLoader.on('loadedplaylist', function () {
|
20159 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
20160 |
|
20161 | if (!tech.paused()) {
|
20162 | segmentLoader.load();
|
20163 | }
|
20164 | });
|
20165 | playlistLoader.on('error', onError[type](type, settings));
|
20166 | },
|
20167 |
|
20168 | |
20169 |
|
20170 |
|
20171 |
|
20172 |
|
20173 |
|
20174 |
|
20175 |
|
20176 |
|
20177 |
|
20178 |
|
20179 | SUBTITLES: function SUBTITLES(type, playlistLoader, settings) {
|
20180 | var tech = settings.tech,
|
20181 | requestOptions = settings.requestOptions,
|
20182 | segmentLoader = settings.segmentLoaders[type],
|
20183 | mediaType = settings.mediaTypes[type];
|
20184 | playlistLoader.on('loadedmetadata', function () {
|
20185 | var media = playlistLoader.media();
|
20186 | segmentLoader.playlist(media, requestOptions);
|
20187 | segmentLoader.track(mediaType.activeTrack());
|
20188 |
|
20189 |
|
20190 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
20191 | segmentLoader.load();
|
20192 | }
|
20193 | });
|
20194 | playlistLoader.on('loadedplaylist', function () {
|
20195 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
20196 |
|
20197 | if (!tech.paused()) {
|
20198 | segmentLoader.load();
|
20199 | }
|
20200 | });
|
20201 | playlistLoader.on('error', onError[type](type, settings));
|
20202 | }
|
20203 | };
|
20204 | var initialize = {
|
20205 | |
20206 |
|
20207 |
|
20208 |
|
20209 |
|
20210 |
|
20211 |
|
20212 |
|
20213 |
|
20214 | 'AUDIO': function AUDIO(type, settings) {
|
20215 | var vhs = settings.vhs,
|
20216 | sourceType = settings.sourceType,
|
20217 | segmentLoader = settings.segmentLoaders[type],
|
20218 | requestOptions = settings.requestOptions,
|
20219 | mediaGroups = settings.master.mediaGroups,
|
20220 | _settings$mediaTypes$ = settings.mediaTypes[type],
|
20221 | groups = _settings$mediaTypes$.groups,
|
20222 | tracks = _settings$mediaTypes$.tracks,
|
20223 | logger_ = _settings$mediaTypes$.logger_,
|
20224 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
20225 | var audioOnlyMaster = isAudioOnly(masterPlaylistLoader.master);
|
20226 |
|
20227 | if (!mediaGroups[type] || Object.keys(mediaGroups[type]).length === 0) {
|
20228 | mediaGroups[type] = {
|
20229 | main: {
|
20230 | default: {
|
20231 | default: true
|
20232 | }
|
20233 | }
|
20234 | };
|
20235 | }
|
20236 |
|
20237 | for (var groupId in mediaGroups[type]) {
|
20238 | if (!groups[groupId]) {
|
20239 | groups[groupId] = [];
|
20240 | }
|
20241 |
|
20242 | for (var variantLabel in mediaGroups[type][groupId]) {
|
20243 | var properties = mediaGroups[type][groupId][variantLabel];
|
20244 | var playlistLoader = void 0;
|
20245 |
|
20246 | if (audioOnlyMaster) {
|
20247 | logger_("AUDIO group '" + groupId + "' label '" + variantLabel + "' is a master playlist");
|
20248 | properties.isMasterPlaylist = true;
|
20249 | playlistLoader = null;
|
20250 |
|
20251 | } else if (sourceType === 'vhs-json' && properties.playlists) {
|
20252 | playlistLoader = new PlaylistLoader(properties.playlists[0], vhs, requestOptions);
|
20253 | } else if (properties.resolvedUri) {
|
20254 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
20255 | } else if (properties.playlists && sourceType === 'dash') {
|
20256 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
20257 | } else {
|
20258 |
|
20259 |
|
20260 | playlistLoader = null;
|
20261 | }
|
20262 |
|
20263 | properties = videojs__default['default'].mergeOptions({
|
20264 | id: variantLabel,
|
20265 | playlistLoader: playlistLoader
|
20266 | }, properties);
|
20267 | setupListeners[type](type, properties.playlistLoader, settings);
|
20268 | groups[groupId].push(properties);
|
20269 |
|
20270 | if (typeof tracks[variantLabel] === 'undefined') {
|
20271 | var track = new videojs__default['default'].AudioTrack({
|
20272 | id: variantLabel,
|
20273 | kind: audioTrackKind_(properties),
|
20274 | enabled: false,
|
20275 | language: properties.language,
|
20276 | default: properties.default,
|
20277 | label: variantLabel
|
20278 | });
|
20279 | tracks[variantLabel] = track;
|
20280 | }
|
20281 | }
|
20282 | }
|
20283 |
|
20284 |
|
20285 | segmentLoader.on('error', onError[type](type, settings));
|
20286 | },
|
20287 |
|
20288 | |
20289 |
|
20290 |
|
20291 |
|
20292 |
|
20293 |
|
20294 |
|
20295 |
|
20296 |
|
20297 | 'SUBTITLES': function SUBTITLES(type, settings) {
|
20298 | var tech = settings.tech,
|
20299 | vhs = settings.vhs,
|
20300 | sourceType = settings.sourceType,
|
20301 | segmentLoader = settings.segmentLoaders[type],
|
20302 | requestOptions = settings.requestOptions,
|
20303 | mediaGroups = settings.master.mediaGroups,
|
20304 | _settings$mediaTypes$2 = settings.mediaTypes[type],
|
20305 | groups = _settings$mediaTypes$2.groups,
|
20306 | tracks = _settings$mediaTypes$2.tracks,
|
20307 | masterPlaylistLoader = settings.masterPlaylistLoader;
|
20308 |
|
20309 | for (var groupId in mediaGroups[type]) {
|
20310 | if (!groups[groupId]) {
|
20311 | groups[groupId] = [];
|
20312 | }
|
20313 |
|
20314 | for (var variantLabel in mediaGroups[type][groupId]) {
|
20315 | if (mediaGroups[type][groupId][variantLabel].forced) {
|
20316 |
|
20317 |
|
20318 |
|
20319 |
|
20320 |
|
20321 |
|
20322 |
|
20323 |
|
20324 | continue;
|
20325 | }
|
20326 |
|
20327 | var properties = mediaGroups[type][groupId][variantLabel];
|
20328 | var playlistLoader = void 0;
|
20329 |
|
20330 | if (sourceType === 'hls') {
|
20331 | playlistLoader = new PlaylistLoader(properties.resolvedUri, vhs, requestOptions);
|
20332 | } else if (sourceType === 'dash') {
|
20333 | var playlists = properties.playlists.filter(function (p) {
|
20334 | return p.excludeUntil !== Infinity;
|
20335 | });
|
20336 |
|
20337 | if (!playlists.length) {
|
20338 | return;
|
20339 | }
|
20340 |
|
20341 | playlistLoader = new DashPlaylistLoader(properties.playlists[0], vhs, requestOptions, masterPlaylistLoader);
|
20342 | } else if (sourceType === 'vhs-json') {
|
20343 | playlistLoader = new PlaylistLoader(
|
20344 |
|
20345 | properties.playlists ? properties.playlists[0] : properties.resolvedUri, vhs, requestOptions);
|
20346 | }
|
20347 |
|
20348 | properties = videojs__default['default'].mergeOptions({
|
20349 | id: variantLabel,
|
20350 | playlistLoader: playlistLoader
|
20351 | }, properties);
|
20352 | setupListeners[type](type, properties.playlistLoader, settings);
|
20353 | groups[groupId].push(properties);
|
20354 |
|
20355 | if (typeof tracks[variantLabel] === 'undefined') {
|
20356 | var track = tech.addRemoteTextTrack({
|
20357 | id: variantLabel,
|
20358 | kind: 'subtitles',
|
20359 | default: properties.default && properties.autoselect,
|
20360 | language: properties.language,
|
20361 | label: variantLabel
|
20362 | }, false).track;
|
20363 | tracks[variantLabel] = track;
|
20364 | }
|
20365 | }
|
20366 | }
|
20367 |
|
20368 |
|
20369 | segmentLoader.on('error', onError[type](type, settings));
|
20370 | },
|
20371 |
|
20372 | |
20373 |
|
20374 |
|
20375 |
|
20376 |
|
20377 |
|
20378 |
|
20379 |
|
20380 |
|
20381 | 'CLOSED-CAPTIONS': function CLOSEDCAPTIONS(type, settings) {
|
20382 | var tech = settings.tech,
|
20383 | mediaGroups = settings.master.mediaGroups,
|
20384 | _settings$mediaTypes$3 = settings.mediaTypes[type],
|
20385 | groups = _settings$mediaTypes$3.groups,
|
20386 | tracks = _settings$mediaTypes$3.tracks;
|
20387 |
|
20388 | for (var groupId in mediaGroups[type]) {
|
20389 | if (!groups[groupId]) {
|
20390 | groups[groupId] = [];
|
20391 | }
|
20392 |
|
20393 | for (var variantLabel in mediaGroups[type][groupId]) {
|
20394 | var properties = mediaGroups[type][groupId][variantLabel];
|
20395 |
|
20396 |
|
20397 | if (!properties.instreamId.match(/CC\d/)) {
|
20398 | continue;
|
20399 | }
|
20400 |
|
20401 |
|
20402 |
|
20403 | groups[groupId].push(videojs__default['default'].mergeOptions({
|
20404 | id: variantLabel
|
20405 | }, properties));
|
20406 |
|
20407 | if (typeof tracks[variantLabel] === 'undefined') {
|
20408 | var track = tech.addRemoteTextTrack({
|
20409 | id: properties.instreamId,
|
20410 | kind: 'captions',
|
20411 | default: properties.default && properties.autoselect,
|
20412 | language: properties.language,
|
20413 | label: variantLabel
|
20414 | }, false).track;
|
20415 | tracks[variantLabel] = track;
|
20416 | }
|
20417 | }
|
20418 | }
|
20419 | }
|
20420 | };
|
20421 |
|
20422 |
|
20423 |
|
20424 |
|
20425 |
|
20426 |
|
20427 |
|
20428 |
|
20429 |
|
20430 |
|
20431 |
|
20432 |
|
20433 |
|
20434 |
|
20435 |
|
20436 | var activeGroup = function activeGroup(type, settings) {
|
20437 | return function (track) {
|
20438 | var masterPlaylistLoader = settings.masterPlaylistLoader,
|
20439 | groups = settings.mediaTypes[type].groups;
|
20440 | var media = masterPlaylistLoader.media();
|
20441 |
|
20442 | if (!media) {
|
20443 | return null;
|
20444 | }
|
20445 |
|
20446 | var variants = null;
|
20447 |
|
20448 | if (media.attributes[type]) {
|
20449 | variants = groups[media.attributes[type]];
|
20450 | }
|
20451 |
|
20452 | var groupKeys = Object.keys(groups);
|
20453 |
|
20454 | if (!variants) {
|
20455 |
|
20456 | if (groups.main) {
|
20457 | variants = groups.main;
|
20458 | } else if (groupKeys.length === 1) {
|
20459 | variants = groups[groupKeys[0]];
|
20460 | }
|
20461 | }
|
20462 |
|
20463 | if (typeof track === 'undefined') {
|
20464 | return variants;
|
20465 | }
|
20466 |
|
20467 | if (track === null || !variants) {
|
20468 |
|
20469 |
|
20470 | return null;
|
20471 | }
|
20472 |
|
20473 | return variants.filter(function (props) {
|
20474 | return props.id === track.id;
|
20475 | })[0] || null;
|
20476 | };
|
20477 | };
|
20478 | var activeTrack = {
|
20479 | |
20480 |
|
20481 |
|
20482 |
|
20483 |
|
20484 |
|
20485 |
|
20486 |
|
20487 |
|
20488 |
|
20489 |
|
20490 |
|
20491 | AUDIO: function AUDIO(type, settings) {
|
20492 | return function () {
|
20493 | var tracks = settings.mediaTypes[type].tracks;
|
20494 |
|
20495 | for (var id in tracks) {
|
20496 | if (tracks[id].enabled) {
|
20497 | return tracks[id];
|
20498 | }
|
20499 | }
|
20500 |
|
20501 | return null;
|
20502 | };
|
20503 | },
|
20504 |
|
20505 | |
20506 |
|
20507 |
|
20508 |
|
20509 |
|
20510 |
|
20511 |
|
20512 |
|
20513 |
|
20514 |
|
20515 |
|
20516 |
|
20517 | SUBTITLES: function SUBTITLES(type, settings) {
|
20518 | return function () {
|
20519 | var tracks = settings.mediaTypes[type].tracks;
|
20520 |
|
20521 | for (var id in tracks) {
|
20522 | if (tracks[id].mode === 'showing' || tracks[id].mode === 'hidden') {
|
20523 | return tracks[id];
|
20524 | }
|
20525 | }
|
20526 |
|
20527 | return null;
|
20528 | };
|
20529 | }
|
20530 | };
|
20531 | var getActiveGroup = function getActiveGroup(type, _ref) {
|
20532 | var mediaTypes = _ref.mediaTypes;
|
20533 | return function () {
|
20534 | var activeTrack_ = mediaTypes[type].activeTrack();
|
20535 |
|
20536 | if (!activeTrack_) {
|
20537 | return null;
|
20538 | }
|
20539 |
|
20540 | return mediaTypes[type].activeGroup(activeTrack_);
|
20541 | };
|
20542 | };
|
20543 |
|
20544 |
|
20545 |
|
20546 |
|
20547 |
|
20548 |
|
20549 |
|
20550 |
|
20551 |
|
20552 |
|
20553 |
|
20554 |
|
20555 |
|
20556 |
|
20557 |
|
20558 |
|
20559 |
|
20560 |
|
20561 |
|
20562 |
|
20563 |
|
20564 |
|
20565 |
|
20566 | var setupMediaGroups = function setupMediaGroups(settings) {
|
20567 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
20568 | initialize[type](type, settings);
|
20569 | });
|
20570 | var mediaTypes = settings.mediaTypes,
|
20571 | masterPlaylistLoader = settings.masterPlaylistLoader,
|
20572 | tech = settings.tech,
|
20573 | vhs = settings.vhs;
|
20574 |
|
20575 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
20576 | mediaTypes[type].activeGroup = activeGroup(type, settings);
|
20577 | mediaTypes[type].activeTrack = activeTrack[type](type, settings);
|
20578 | mediaTypes[type].onGroupChanged = onGroupChanged(type, settings);
|
20579 | mediaTypes[type].onGroupChanging = onGroupChanging(type, settings);
|
20580 | mediaTypes[type].onTrackChanged = onTrackChanged(type, settings);
|
20581 | mediaTypes[type].getActiveGroup = getActiveGroup(type, settings);
|
20582 | });
|
20583 |
|
20584 |
|
20585 | var audioGroup = mediaTypes.AUDIO.activeGroup();
|
20586 |
|
20587 | if (audioGroup) {
|
20588 | var groupId = (audioGroup.filter(function (group) {
|
20589 | return group.default;
|
20590 | })[0] || audioGroup[0]).id;
|
20591 | mediaTypes.AUDIO.tracks[groupId].enabled = true;
|
20592 | mediaTypes.AUDIO.onGroupChanged();
|
20593 | mediaTypes.AUDIO.onTrackChanged();
|
20594 | }
|
20595 |
|
20596 | masterPlaylistLoader.on('mediachange', function () {
|
20597 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
20598 | return mediaTypes[type].onGroupChanged();
|
20599 | });
|
20600 | });
|
20601 | masterPlaylistLoader.on('mediachanging', function () {
|
20602 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
20603 | return mediaTypes[type].onGroupChanging();
|
20604 | });
|
20605 | });
|
20606 |
|
20607 | var onAudioTrackChanged = function onAudioTrackChanged() {
|
20608 | mediaTypes.AUDIO.onTrackChanged();
|
20609 | tech.trigger({
|
20610 | type: 'usage',
|
20611 | name: 'vhs-audio-change'
|
20612 | });
|
20613 | tech.trigger({
|
20614 | type: 'usage',
|
20615 | name: 'hls-audio-change'
|
20616 | });
|
20617 | };
|
20618 |
|
20619 | tech.audioTracks().addEventListener('change', onAudioTrackChanged);
|
20620 | tech.remoteTextTracks().addEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
20621 | vhs.on('dispose', function () {
|
20622 | tech.audioTracks().removeEventListener('change', onAudioTrackChanged);
|
20623 | tech.remoteTextTracks().removeEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
20624 | });
|
20625 |
|
20626 | tech.clearTracks('audio');
|
20627 |
|
20628 | for (var id in mediaTypes.AUDIO.tracks) {
|
20629 | tech.audioTracks().addTrack(mediaTypes.AUDIO.tracks[id]);
|
20630 | }
|
20631 | };
|
20632 |
|
20633 |
|
20634 |
|
20635 |
|
20636 |
|
20637 |
|
20638 |
|
20639 |
|
20640 |
|
20641 | var createMediaTypes = function createMediaTypes() {
|
20642 | var mediaTypes = {};
|
20643 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
20644 | mediaTypes[type] = {
|
20645 | groups: {},
|
20646 | tracks: {},
|
20647 | activePlaylistLoader: null,
|
20648 | activeGroup: noop,
|
20649 | activeTrack: noop,
|
20650 | getActiveGroup: noop,
|
20651 | onGroupChanged: noop,
|
20652 | onTrackChanged: noop,
|
20653 | lastTrack_: null,
|
20654 | logger_: logger("MediaGroups[" + type + "]")
|
20655 | };
|
20656 | });
|
20657 | return mediaTypes;
|
20658 | };
|
20659 |
|
20660 | var ABORT_EARLY_BLACKLIST_SECONDS = 60 * 2;
|
20661 | var Vhs$1;
|
20662 |
|
20663 |
|
20664 | var loaderStats = ['mediaRequests', 'mediaRequestsAborted', 'mediaRequestsTimedout', 'mediaRequestsErrored', 'mediaTransferDuration', 'mediaBytesTransferred'];
|
20665 |
|
20666 | var sumLoaderStat = function sumLoaderStat(stat) {
|
20667 | return this.audioSegmentLoader_[stat] + this.mainSegmentLoader_[stat];
|
20668 | };
|
20669 |
|
20670 | var shouldSwitchToMedia = function shouldSwitchToMedia(_ref) {
|
20671 | var currentPlaylist = _ref.currentPlaylist,
|
20672 | nextPlaylist = _ref.nextPlaylist,
|
20673 | forwardBuffer = _ref.forwardBuffer,
|
20674 | bufferLowWaterLine = _ref.bufferLowWaterLine,
|
20675 | bufferHighWaterLine = _ref.bufferHighWaterLine,
|
20676 | duration = _ref.duration,
|
20677 | experimentalBufferBasedABR = _ref.experimentalBufferBasedABR,
|
20678 | log = _ref.log;
|
20679 |
|
20680 |
|
20681 | if (!nextPlaylist) {
|
20682 | videojs__default['default'].log.warn('We received no playlist to switch to. Please check your stream.');
|
20683 | return false;
|
20684 | }
|
20685 |
|
20686 | var sharedLogLine = "allowing switch " + (currentPlaylist && currentPlaylist.id || 'null') + " -> " + nextPlaylist.id;
|
20687 |
|
20688 |
|
20689 |
|
20690 |
|
20691 | if (!currentPlaylist || !currentPlaylist.endList) {
|
20692 | log(sharedLogLine + " as current playlist " + (!currentPlaylist ? 'is not set' : 'is live'));
|
20693 | return true;
|
20694 | }
|
20695 |
|
20696 |
|
20697 | if (nextPlaylist.id === currentPlaylist.id) {
|
20698 | return false;
|
20699 | }
|
20700 |
|
20701 | var maxBufferLowWaterLine = experimentalBufferBasedABR ? Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE : Config.MAX_BUFFER_LOW_WATER_LINE;
|
20702 |
|
20703 |
|
20704 | if (duration < maxBufferLowWaterLine) {
|
20705 | log(sharedLogLine + " as duration < max low water line (" + duration + " < " + maxBufferLowWaterLine + ")");
|
20706 | return true;
|
20707 | }
|
20708 |
|
20709 | var nextBandwidth = nextPlaylist.attributes.BANDWIDTH;
|
20710 | var currBandwidth = currentPlaylist.attributes.BANDWIDTH;
|
20711 |
|
20712 |
|
20713 | if (nextBandwidth < currBandwidth && (!experimentalBufferBasedABR || forwardBuffer < bufferHighWaterLine)) {
|
20714 | var logLine = sharedLogLine + " as next bandwidth < current bandwidth (" + nextBandwidth + " < " + currBandwidth + ")";
|
20715 |
|
20716 | if (experimentalBufferBasedABR) {
|
20717 | logLine += " and forwardBuffer < bufferHighWaterLine (" + forwardBuffer + " < " + bufferHighWaterLine + ")";
|
20718 | }
|
20719 |
|
20720 | log(logLine);
|
20721 | return true;
|
20722 | }
|
20723 |
|
20724 |
|
20725 |
|
20726 | if ((!experimentalBufferBasedABR || nextBandwidth > currBandwidth) && forwardBuffer >= bufferLowWaterLine) {
|
20727 | var _logLine = sharedLogLine + " as forwardBuffer >= bufferLowWaterLine (" + forwardBuffer + " >= " + bufferLowWaterLine + ")";
|
20728 |
|
20729 | if (experimentalBufferBasedABR) {
|
20730 | _logLine += " and next bandwidth > current bandwidth (" + nextBandwidth + " > " + currBandwidth + ")";
|
20731 | }
|
20732 |
|
20733 | log(_logLine);
|
20734 | return true;
|
20735 | }
|
20736 |
|
20737 | log("not " + sharedLogLine + " as no switching criteria met");
|
20738 | return false;
|
20739 | };
|
20740 |
|
20741 |
|
20742 |
|
20743 |
|
20744 |
|
20745 |
|
20746 |
|
20747 |
|
20748 |
|
20749 |
|
20750 |
|
20751 | var MasterPlaylistController = function (_videojs$EventTarget) {
|
20752 | _inheritsLoose__default['default'](MasterPlaylistController, _videojs$EventTarget);
|
20753 |
|
20754 | function MasterPlaylistController(options) {
|
20755 | var _this;
|
20756 |
|
20757 | _this = _videojs$EventTarget.call(this) || this;
|
20758 | var src = options.src,
|
20759 | handleManifestRedirects = options.handleManifestRedirects,
|
20760 | withCredentials = options.withCredentials,
|
20761 | tech = options.tech,
|
20762 | bandwidth = options.bandwidth,
|
20763 | externVhs = options.externVhs,
|
20764 | useCueTags = options.useCueTags,
|
20765 | blacklistDuration = options.blacklistDuration,
|
20766 | enableLowInitialPlaylist = options.enableLowInitialPlaylist,
|
20767 | sourceType = options.sourceType,
|
20768 | cacheEncryptionKeys = options.cacheEncryptionKeys,
|
20769 | handlePartialData = options.handlePartialData,
|
20770 | experimentalBufferBasedABR = options.experimentalBufferBasedABR;
|
20771 |
|
20772 | if (!src) {
|
20773 | throw new Error('A non-empty playlist URL or JSON manifest string is required');
|
20774 | }
|
20775 |
|
20776 | Vhs$1 = externVhs;
|
20777 | _this.experimentalBufferBasedABR = Boolean(experimentalBufferBasedABR);
|
20778 | _this.withCredentials = withCredentials;
|
20779 | _this.tech_ = tech;
|
20780 | _this.vhs_ = tech.vhs;
|
20781 | _this.sourceType_ = sourceType;
|
20782 | _this.useCueTags_ = useCueTags;
|
20783 | _this.blacklistDuration = blacklistDuration;
|
20784 | _this.enableLowInitialPlaylist = enableLowInitialPlaylist;
|
20785 |
|
20786 | if (_this.useCueTags_) {
|
20787 | _this.cueTagsTrack_ = _this.tech_.addTextTrack('metadata', 'ad-cues');
|
20788 | _this.cueTagsTrack_.inBandMetadataTrackDispatchType = '';
|
20789 | }
|
20790 |
|
20791 | _this.requestOptions_ = {
|
20792 | withCredentials: withCredentials,
|
20793 | handleManifestRedirects: handleManifestRedirects,
|
20794 | timeout: null
|
20795 | };
|
20796 |
|
20797 | _this.on('error', _this.pauseLoading);
|
20798 |
|
20799 | _this.mediaTypes_ = createMediaTypes();
|
20800 | _this.mediaSource = new window__default['default'].MediaSource();
|
20801 | _this.handleDurationChange_ = _this.handleDurationChange_.bind(_assertThisInitialized__default['default'](_this));
|
20802 | _this.handleSourceOpen_ = _this.handleSourceOpen_.bind(_assertThisInitialized__default['default'](_this));
|
20803 | _this.handleSourceEnded_ = _this.handleSourceEnded_.bind(_assertThisInitialized__default['default'](_this));
|
20804 |
|
20805 | _this.mediaSource.addEventListener('durationchange', _this.handleDurationChange_);
|
20806 |
|
20807 |
|
20808 | _this.mediaSource.addEventListener('sourceopen', _this.handleSourceOpen_);
|
20809 |
|
20810 | _this.mediaSource.addEventListener('sourceended', _this.handleSourceEnded_);
|
20811 |
|
20812 |
|
20813 |
|
20814 | _this.seekable_ = videojs__default['default'].createTimeRanges();
|
20815 | _this.hasPlayed_ = false;
|
20816 | _this.syncController_ = new SyncController(options);
|
20817 | _this.segmentMetadataTrack_ = tech.addRemoteTextTrack({
|
20818 | kind: 'metadata',
|
20819 | label: 'segment-metadata'
|
20820 | }, false).track;
|
20821 | _this.decrypter_ = new Decrypter();
|
20822 | _this.sourceUpdater_ = new SourceUpdater(_this.mediaSource);
|
20823 | _this.inbandTextTracks_ = {};
|
20824 | _this.timelineChangeController_ = new TimelineChangeController();
|
20825 | var segmentLoaderSettings = {
|
20826 | vhs: _this.vhs_,
|
20827 | parse708captions: options.parse708captions,
|
20828 | mediaSource: _this.mediaSource,
|
20829 | currentTime: _this.tech_.currentTime.bind(_this.tech_),
|
20830 | seekable: function seekable() {
|
20831 | return _this.seekable();
|
20832 | },
|
20833 | seeking: function seeking() {
|
20834 | return _this.tech_.seeking();
|
20835 | },
|
20836 | duration: function duration() {
|
20837 | return _this.duration();
|
20838 | },
|
20839 | hasPlayed: function hasPlayed() {
|
20840 | return _this.hasPlayed_;
|
20841 | },
|
20842 | goalBufferLength: function goalBufferLength() {
|
20843 | return _this.goalBufferLength();
|
20844 | },
|
20845 | bandwidth: bandwidth,
|
20846 | syncController: _this.syncController_,
|
20847 | decrypter: _this.decrypter_,
|
20848 | sourceType: _this.sourceType_,
|
20849 | inbandTextTracks: _this.inbandTextTracks_,
|
20850 | cacheEncryptionKeys: cacheEncryptionKeys,
|
20851 | handlePartialData: handlePartialData,
|
20852 | sourceUpdater: _this.sourceUpdater_,
|
20853 | timelineChangeController: _this.timelineChangeController_
|
20854 | };
|
20855 |
|
20856 |
|
20857 |
|
20858 |
|
20859 | _this.masterPlaylistLoader_ = _this.sourceType_ === 'dash' ? new DashPlaylistLoader(src, _this.vhs_, _this.requestOptions_) : new PlaylistLoader(src, _this.vhs_, _this.requestOptions_);
|
20860 |
|
20861 | _this.setupMasterPlaylistLoaderListeners_();
|
20862 |
|
20863 |
|
20864 |
|
20865 | _this.mainSegmentLoader_ = new SegmentLoader(videojs__default['default'].mergeOptions(segmentLoaderSettings, {
|
20866 | segmentMetadataTrack: _this.segmentMetadataTrack_,
|
20867 | loaderType: 'main'
|
20868 | }), options);
|
20869 |
|
20870 | _this.audioSegmentLoader_ = new SegmentLoader(videojs__default['default'].mergeOptions(segmentLoaderSettings, {
|
20871 | loaderType: 'audio'
|
20872 | }), options);
|
20873 | _this.subtitleSegmentLoader_ = new VTTSegmentLoader(videojs__default['default'].mergeOptions(segmentLoaderSettings, {
|
20874 | loaderType: 'vtt',
|
20875 | featuresNativeTextTracks: _this.tech_.featuresNativeTextTracks
|
20876 | }), options);
|
20877 |
|
20878 | _this.setupSegmentLoaderListeners_();
|
20879 |
|
20880 | if (_this.experimentalBufferBasedABR) {
|
20881 | _this.masterPlaylistLoader_.one('loadedplaylist', function () {
|
20882 | return _this.startABRTimer_();
|
20883 | });
|
20884 |
|
20885 | _this.tech_.on('pause', function () {
|
20886 | return _this.stopABRTimer_();
|
20887 | });
|
20888 |
|
20889 | _this.tech_.on('play', function () {
|
20890 | return _this.startABRTimer_();
|
20891 | });
|
20892 | }
|
20893 |
|
20894 |
|
20895 |
|
20896 |
|
20897 |
|
20898 |
|
20899 |
|
20900 |
|
20901 | loaderStats.forEach(function (stat) {
|
20902 | _this[stat + '_'] = sumLoaderStat.bind(_assertThisInitialized__default['default'](_this), stat);
|
20903 | });
|
20904 | _this.logger_ = logger('MPC');
|
20905 | _this.triggeredFmp4Usage = false;
|
20906 |
|
20907 | if (_this.tech_.preload() === 'none') {
|
20908 | _this.loadOnPlay_ = function () {
|
20909 | _this.loadOnPlay_ = null;
|
20910 |
|
20911 | _this.masterPlaylistLoader_.load();
|
20912 | };
|
20913 |
|
20914 | _this.tech_.one('play', _this.loadOnPlay_);
|
20915 | } else {
|
20916 | _this.masterPlaylistLoader_.load();
|
20917 | }
|
20918 |
|
20919 | return _this;
|
20920 | }
|
20921 | |
20922 |
|
20923 |
|
20924 |
|
20925 |
|
20926 |
|
20927 |
|
20928 |
|
20929 | var _proto = MasterPlaylistController.prototype;
|
20930 |
|
20931 | _proto.checkABR_ = function checkABR_() {
|
20932 | var nextPlaylist = this.selectPlaylist();
|
20933 |
|
20934 | if (this.shouldSwitchToMedia_(nextPlaylist)) {
|
20935 | this.switchMedia_(nextPlaylist, 'abr');
|
20936 | }
|
20937 | };
|
20938 |
|
20939 | _proto.switchMedia_ = function switchMedia_(playlist, cause, delay) {
|
20940 | var oldMedia = this.media();
|
20941 | var oldId = oldMedia && (oldMedia.id || oldMedia.uri);
|
20942 | var newId = playlist.id || playlist.uri;
|
20943 |
|
20944 | if (oldId && oldId !== newId) {
|
20945 | this.logger_("switch media " + oldId + " -> " + newId + " from " + cause);
|
20946 | this.tech_.trigger({
|
20947 | type: 'usage',
|
20948 | name: "vhs-rendition-change-" + cause
|
20949 | });
|
20950 | }
|
20951 |
|
20952 | this.masterPlaylistLoader_.media(playlist, delay);
|
20953 | }
|
20954 | |
20955 |
|
20956 |
|
20957 |
|
20958 |
|
20959 | ;
|
20960 |
|
20961 | _proto.startABRTimer_ = function startABRTimer_() {
|
20962 | var _this2 = this;
|
20963 |
|
20964 | this.stopABRTimer_();
|
20965 | this.abrTimer_ = window__default['default'].setInterval(function () {
|
20966 | return _this2.checkABR_();
|
20967 | }, 250);
|
20968 | }
|
20969 | |
20970 |
|
20971 |
|
20972 |
|
20973 |
|
20974 | ;
|
20975 |
|
20976 | _proto.stopABRTimer_ = function stopABRTimer_() {
|
20977 |
|
20978 |
|
20979 | if (this.tech_.scrubbing && this.tech_.scrubbing()) {
|
20980 | return;
|
20981 | }
|
20982 |
|
20983 | window__default['default'].clearInterval(this.abrTimer_);
|
20984 | this.abrTimer_ = null;
|
20985 | }
|
20986 | |
20987 |
|
20988 |
|
20989 |
|
20990 |
|
20991 | ;
|
20992 |
|
20993 | _proto.getAudioTrackPlaylists_ = function getAudioTrackPlaylists_() {
|
20994 | var master = this.master();
|
20995 |
|
20996 |
|
20997 |
|
20998 | if (!master || !master.mediaGroups || !master.mediaGroups.AUDIO) {
|
20999 | return master && master.playlists || [];
|
21000 | }
|
21001 |
|
21002 | var AUDIO = master.mediaGroups.AUDIO;
|
21003 | var groupKeys = Object.keys(AUDIO);
|
21004 | var track;
|
21005 |
|
21006 | if (Object.keys(this.mediaTypes_.AUDIO.groups).length) {
|
21007 | track = this.mediaTypes_.AUDIO.activeTrack();
|
21008 | } else {
|
21009 |
|
21010 | var defaultGroup = AUDIO.main || groupKeys.length && AUDIO[groupKeys[0]];
|
21011 |
|
21012 | for (var label in defaultGroup) {
|
21013 | if (defaultGroup[label].default) {
|
21014 | track = {
|
21015 | label: label
|
21016 | };
|
21017 | break;
|
21018 | }
|
21019 | }
|
21020 | }
|
21021 |
|
21022 |
|
21023 | if (!track) {
|
21024 | return [];
|
21025 | }
|
21026 |
|
21027 | var playlists = [];
|
21028 |
|
21029 |
|
21030 | for (var group in AUDIO) {
|
21031 | if (AUDIO[group][track.label]) {
|
21032 | var properties = AUDIO[group][track.label];
|
21033 |
|
21034 | if (properties.playlists) {
|
21035 | playlists.push.apply(playlists, properties.playlists);
|
21036 | } else {
|
21037 | playlists.push(properties);
|
21038 | }
|
21039 | }
|
21040 | }
|
21041 |
|
21042 | return playlists;
|
21043 | }
|
21044 | |
21045 |
|
21046 |
|
21047 |
|
21048 |
|
21049 |
|
21050 | ;
|
21051 |
|
21052 | _proto.setupMasterPlaylistLoaderListeners_ = function setupMasterPlaylistLoaderListeners_() {
|
21053 | var _this3 = this;
|
21054 |
|
21055 | this.masterPlaylistLoader_.on('loadedmetadata', function () {
|
21056 | var media = _this3.masterPlaylistLoader_.media();
|
21057 |
|
21058 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
21059 |
|
21060 |
|
21061 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
21062 | _this3.requestOptions_.timeout = 0;
|
21063 | } else {
|
21064 | _this3.requestOptions_.timeout = requestTimeout;
|
21065 | }
|
21066 |
|
21067 |
|
21068 |
|
21069 | if (media.endList && _this3.tech_.preload() !== 'none') {
|
21070 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
21071 |
|
21072 | _this3.mainSegmentLoader_.load();
|
21073 | }
|
21074 |
|
21075 | setupMediaGroups({
|
21076 | sourceType: _this3.sourceType_,
|
21077 | segmentLoaders: {
|
21078 | AUDIO: _this3.audioSegmentLoader_,
|
21079 | SUBTITLES: _this3.subtitleSegmentLoader_,
|
21080 | main: _this3.mainSegmentLoader_
|
21081 | },
|
21082 | tech: _this3.tech_,
|
21083 | requestOptions: _this3.requestOptions_,
|
21084 | masterPlaylistLoader: _this3.masterPlaylistLoader_,
|
21085 | vhs: _this3.vhs_,
|
21086 | master: _this3.master(),
|
21087 | mediaTypes: _this3.mediaTypes_,
|
21088 | blacklistCurrentPlaylist: _this3.blacklistCurrentPlaylist.bind(_this3)
|
21089 | });
|
21090 |
|
21091 | _this3.triggerPresenceUsage_(_this3.master(), media);
|
21092 |
|
21093 | _this3.setupFirstPlay();
|
21094 |
|
21095 | if (!_this3.mediaTypes_.AUDIO.activePlaylistLoader || _this3.mediaTypes_.AUDIO.activePlaylistLoader.media()) {
|
21096 | _this3.trigger('selectedinitialmedia');
|
21097 | } else {
|
21098 |
|
21099 |
|
21100 |
|
21101 | _this3.mediaTypes_.AUDIO.activePlaylistLoader.one('loadedmetadata', function () {
|
21102 | _this3.trigger('selectedinitialmedia');
|
21103 | });
|
21104 | }
|
21105 | });
|
21106 | this.masterPlaylistLoader_.on('loadedplaylist', function () {
|
21107 | if (_this3.loadOnPlay_) {
|
21108 | _this3.tech_.off('play', _this3.loadOnPlay_);
|
21109 | }
|
21110 |
|
21111 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
21112 |
|
21113 | if (!updatedPlaylist) {
|
21114 |
|
21115 |
|
21116 | _this3.excludeUnsupportedVariants_();
|
21117 |
|
21118 | var selectedMedia;
|
21119 |
|
21120 | if (_this3.enableLowInitialPlaylist) {
|
21121 | selectedMedia = _this3.selectInitialPlaylist();
|
21122 | }
|
21123 |
|
21124 | if (!selectedMedia) {
|
21125 | selectedMedia = _this3.selectPlaylist();
|
21126 | }
|
21127 |
|
21128 | if (!selectedMedia || !_this3.shouldSwitchToMedia_(selectedMedia)) {
|
21129 | return;
|
21130 | }
|
21131 |
|
21132 | _this3.initialMedia_ = selectedMedia;
|
21133 |
|
21134 | _this3.switchMedia_(_this3.initialMedia_, 'initial');
|
21135 |
|
21136 |
|
21137 |
|
21138 |
|
21139 |
|
21140 |
|
21141 |
|
21142 | var haveJsonSource = _this3.sourceType_ === 'vhs-json' && _this3.initialMedia_.segments;
|
21143 |
|
21144 | if (!haveJsonSource) {
|
21145 | return;
|
21146 | }
|
21147 |
|
21148 | updatedPlaylist = _this3.initialMedia_;
|
21149 | }
|
21150 |
|
21151 | _this3.handleUpdatedMediaPlaylist(updatedPlaylist);
|
21152 | });
|
21153 | this.masterPlaylistLoader_.on('error', function () {
|
21154 | _this3.blacklistCurrentPlaylist(_this3.masterPlaylistLoader_.error);
|
21155 | });
|
21156 | this.masterPlaylistLoader_.on('mediachanging', function () {
|
21157 | _this3.mainSegmentLoader_.abort();
|
21158 |
|
21159 | _this3.mainSegmentLoader_.pause();
|
21160 | });
|
21161 | this.masterPlaylistLoader_.on('mediachange', function () {
|
21162 | var media = _this3.masterPlaylistLoader_.media();
|
21163 |
|
21164 | var requestTimeout = media.targetDuration * 1.5 * 1000;
|
21165 |
|
21166 |
|
21167 | if (isLowestEnabledRendition(_this3.masterPlaylistLoader_.master, _this3.masterPlaylistLoader_.media())) {
|
21168 | _this3.requestOptions_.timeout = 0;
|
21169 | } else {
|
21170 | _this3.requestOptions_.timeout = requestTimeout;
|
21171 | }
|
21172 |
|
21173 |
|
21174 |
|
21175 |
|
21176 |
|
21177 | _this3.mainSegmentLoader_.playlist(media, _this3.requestOptions_);
|
21178 |
|
21179 | _this3.mainSegmentLoader_.load();
|
21180 |
|
21181 | _this3.tech_.trigger({
|
21182 | type: 'mediachange',
|
21183 | bubbles: true
|
21184 | });
|
21185 | });
|
21186 | this.masterPlaylistLoader_.on('playlistunchanged', function () {
|
21187 | var updatedPlaylist = _this3.masterPlaylistLoader_.media();
|
21188 |
|
21189 |
|
21190 |
|
21191 |
|
21192 | if (updatedPlaylist.lastExcludeReason_ === 'playlist-unchanged') {
|
21193 | return;
|
21194 | }
|
21195 |
|
21196 | var playlistOutdated = _this3.stuckAtPlaylistEnd_(updatedPlaylist);
|
21197 |
|
21198 | if (playlistOutdated) {
|
21199 |
|
21200 |
|
21201 |
|
21202 |
|
21203 | _this3.blacklistCurrentPlaylist({
|
21204 | message: 'Playlist no longer updating.',
|
21205 | reason: 'playlist-unchanged'
|
21206 | });
|
21207 |
|
21208 |
|
21209 | _this3.tech_.trigger('playliststuck');
|
21210 | }
|
21211 | });
|
21212 | this.masterPlaylistLoader_.on('renditiondisabled', function () {
|
21213 | _this3.tech_.trigger({
|
21214 | type: 'usage',
|
21215 | name: 'vhs-rendition-disabled'
|
21216 | });
|
21217 |
|
21218 | _this3.tech_.trigger({
|
21219 | type: 'usage',
|
21220 | name: 'hls-rendition-disabled'
|
21221 | });
|
21222 | });
|
21223 | this.masterPlaylistLoader_.on('renditionenabled', function () {
|
21224 | _this3.tech_.trigger({
|
21225 | type: 'usage',
|
21226 | name: 'vhs-rendition-enabled'
|
21227 | });
|
21228 |
|
21229 | _this3.tech_.trigger({
|
21230 | type: 'usage',
|
21231 | name: 'hls-rendition-enabled'
|
21232 | });
|
21233 | });
|
21234 | }
|
21235 | |
21236 |
|
21237 |
|
21238 |
|
21239 |
|
21240 |
|
21241 |
|
21242 |
|
21243 |
|
21244 | ;
|
21245 |
|
21246 | _proto.handleUpdatedMediaPlaylist = function handleUpdatedMediaPlaylist(updatedPlaylist) {
|
21247 | if (this.useCueTags_) {
|
21248 | this.updateAdCues_(updatedPlaylist);
|
21249 | }
|
21250 |
|
21251 |
|
21252 |
|
21253 |
|
21254 |
|
21255 | this.mainSegmentLoader_.playlist(updatedPlaylist, this.requestOptions_);
|
21256 | this.updateDuration(!updatedPlaylist.endList);
|
21257 |
|
21258 |
|
21259 |
|
21260 | if (!this.tech_.paused()) {
|
21261 | this.mainSegmentLoader_.load();
|
21262 |
|
21263 | if (this.audioSegmentLoader_) {
|
21264 | this.audioSegmentLoader_.load();
|
21265 | }
|
21266 | }
|
21267 | }
|
21268 | |
21269 |
|
21270 |
|
21271 |
|
21272 |
|
21273 | ;
|
21274 |
|
21275 | _proto.triggerPresenceUsage_ = function triggerPresenceUsage_(master, media) {
|
21276 | var mediaGroups = master.mediaGroups || {};
|
21277 | var defaultDemuxed = true;
|
21278 | var audioGroupKeys = Object.keys(mediaGroups.AUDIO);
|
21279 |
|
21280 | for (var mediaGroup in mediaGroups.AUDIO) {
|
21281 | for (var label in mediaGroups.AUDIO[mediaGroup]) {
|
21282 | var properties = mediaGroups.AUDIO[mediaGroup][label];
|
21283 |
|
21284 | if (!properties.uri) {
|
21285 | defaultDemuxed = false;
|
21286 | }
|
21287 | }
|
21288 | }
|
21289 |
|
21290 | if (defaultDemuxed) {
|
21291 | this.tech_.trigger({
|
21292 | type: 'usage',
|
21293 | name: 'vhs-demuxed'
|
21294 | });
|
21295 | this.tech_.trigger({
|
21296 | type: 'usage',
|
21297 | name: 'hls-demuxed'
|
21298 | });
|
21299 | }
|
21300 |
|
21301 | if (Object.keys(mediaGroups.SUBTITLES).length) {
|
21302 | this.tech_.trigger({
|
21303 | type: 'usage',
|
21304 | name: 'vhs-webvtt'
|
21305 | });
|
21306 | this.tech_.trigger({
|
21307 | type: 'usage',
|
21308 | name: 'hls-webvtt'
|
21309 | });
|
21310 | }
|
21311 |
|
21312 | if (Vhs$1.Playlist.isAes(media)) {
|
21313 | this.tech_.trigger({
|
21314 | type: 'usage',
|
21315 | name: 'vhs-aes'
|
21316 | });
|
21317 | this.tech_.trigger({
|
21318 | type: 'usage',
|
21319 | name: 'hls-aes'
|
21320 | });
|
21321 | }
|
21322 |
|
21323 | if (audioGroupKeys.length && Object.keys(mediaGroups.AUDIO[audioGroupKeys[0]]).length > 1) {
|
21324 | this.tech_.trigger({
|
21325 | type: 'usage',
|
21326 | name: 'vhs-alternate-audio'
|
21327 | });
|
21328 | this.tech_.trigger({
|
21329 | type: 'usage',
|
21330 | name: 'hls-alternate-audio'
|
21331 | });
|
21332 | }
|
21333 |
|
21334 | if (this.useCueTags_) {
|
21335 | this.tech_.trigger({
|
21336 | type: 'usage',
|
21337 | name: 'vhs-playlist-cue-tags'
|
21338 | });
|
21339 | this.tech_.trigger({
|
21340 | type: 'usage',
|
21341 | name: 'hls-playlist-cue-tags'
|
21342 | });
|
21343 | }
|
21344 | };
|
21345 |
|
21346 | _proto.shouldSwitchToMedia_ = function shouldSwitchToMedia_(nextPlaylist) {
|
21347 | var currentPlaylist = this.masterPlaylistLoader_.media();
|
21348 | var buffered = this.tech_.buffered();
|
21349 | var forwardBuffer = buffered.length ? buffered.end(buffered.length - 1) - this.tech_.currentTime() : 0;
|
21350 | var bufferLowWaterLine = this.bufferLowWaterLine();
|
21351 | var bufferHighWaterLine = this.bufferHighWaterLine();
|
21352 | return shouldSwitchToMedia({
|
21353 | currentPlaylist: currentPlaylist,
|
21354 | nextPlaylist: nextPlaylist,
|
21355 | forwardBuffer: forwardBuffer,
|
21356 | bufferLowWaterLine: bufferLowWaterLine,
|
21357 | bufferHighWaterLine: bufferHighWaterLine,
|
21358 | duration: this.duration(),
|
21359 | experimentalBufferBasedABR: this.experimentalBufferBasedABR,
|
21360 | log: this.logger_
|
21361 | });
|
21362 | }
|
21363 | |
21364 |
|
21365 |
|
21366 |
|
21367 |
|
21368 |
|
21369 | ;
|
21370 |
|
21371 | _proto.setupSegmentLoaderListeners_ = function setupSegmentLoaderListeners_() {
|
21372 | var _this4 = this;
|
21373 |
|
21374 | if (!this.experimentalBufferBasedABR) {
|
21375 | this.mainSegmentLoader_.on('bandwidthupdate', function () {
|
21376 | var nextPlaylist = _this4.selectPlaylist();
|
21377 |
|
21378 | if (_this4.shouldSwitchToMedia_(nextPlaylist)) {
|
21379 | _this4.switchMedia_(nextPlaylist, 'bandwidthupdate');
|
21380 | }
|
21381 |
|
21382 | _this4.tech_.trigger('bandwidthupdate');
|
21383 | });
|
21384 | this.mainSegmentLoader_.on('progress', function () {
|
21385 | _this4.trigger('progress');
|
21386 | });
|
21387 | }
|
21388 |
|
21389 | this.mainSegmentLoader_.on('error', function () {
|
21390 | _this4.blacklistCurrentPlaylist(_this4.mainSegmentLoader_.error());
|
21391 | });
|
21392 | this.mainSegmentLoader_.on('appenderror', function () {
|
21393 | _this4.error = _this4.mainSegmentLoader_.error_;
|
21394 |
|
21395 | _this4.trigger('error');
|
21396 | });
|
21397 | this.mainSegmentLoader_.on('syncinfoupdate', function () {
|
21398 | _this4.onSyncInfoUpdate_();
|
21399 | });
|
21400 | this.mainSegmentLoader_.on('timestampoffset', function () {
|
21401 | _this4.tech_.trigger({
|
21402 | type: 'usage',
|
21403 | name: 'vhs-timestamp-offset'
|
21404 | });
|
21405 |
|
21406 | _this4.tech_.trigger({
|
21407 | type: 'usage',
|
21408 | name: 'hls-timestamp-offset'
|
21409 | });
|
21410 | });
|
21411 | this.audioSegmentLoader_.on('syncinfoupdate', function () {
|
21412 | _this4.onSyncInfoUpdate_();
|
21413 | });
|
21414 | this.audioSegmentLoader_.on('appenderror', function () {
|
21415 | _this4.error = _this4.audioSegmentLoader_.error_;
|
21416 |
|
21417 | _this4.trigger('error');
|
21418 | });
|
21419 | this.mainSegmentLoader_.on('ended', function () {
|
21420 | _this4.logger_('main segment loader ended');
|
21421 |
|
21422 | _this4.onEndOfStream();
|
21423 | });
|
21424 | this.mainSegmentLoader_.on('earlyabort', function (event) {
|
21425 |
|
21426 | if (_this4.experimentalBufferBasedABR) {
|
21427 | return;
|
21428 | }
|
21429 |
|
21430 | _this4.delegateLoaders_('all', ['abort']);
|
21431 |
|
21432 | _this4.blacklistCurrentPlaylist({
|
21433 | message: 'Aborted early because there isn\'t enough bandwidth to complete the ' + 'request without rebuffering.'
|
21434 | }, ABORT_EARLY_BLACKLIST_SECONDS);
|
21435 | });
|
21436 |
|
21437 | var updateCodecs = function updateCodecs() {
|
21438 | if (!_this4.sourceUpdater_.hasCreatedSourceBuffers()) {
|
21439 | return _this4.tryToCreateSourceBuffers_();
|
21440 | }
|
21441 |
|
21442 | var codecs = _this4.getCodecsOrExclude_();
|
21443 |
|
21444 |
|
21445 | if (!codecs) {
|
21446 | return;
|
21447 | }
|
21448 |
|
21449 | _this4.sourceUpdater_.addOrChangeSourceBuffers(codecs);
|
21450 | };
|
21451 |
|
21452 | this.mainSegmentLoader_.on('trackinfo', updateCodecs);
|
21453 | this.audioSegmentLoader_.on('trackinfo', updateCodecs);
|
21454 | this.mainSegmentLoader_.on('fmp4', function () {
|
21455 | if (!_this4.triggeredFmp4Usage) {
|
21456 | _this4.tech_.trigger({
|
21457 | type: 'usage',
|
21458 | name: 'vhs-fmp4'
|
21459 | });
|
21460 |
|
21461 | _this4.tech_.trigger({
|
21462 | type: 'usage',
|
21463 | name: 'hls-fmp4'
|
21464 | });
|
21465 |
|
21466 | _this4.triggeredFmp4Usage = true;
|
21467 | }
|
21468 | });
|
21469 | this.audioSegmentLoader_.on('fmp4', function () {
|
21470 | if (!_this4.triggeredFmp4Usage) {
|
21471 | _this4.tech_.trigger({
|
21472 | type: 'usage',
|
21473 | name: 'vhs-fmp4'
|
21474 | });
|
21475 |
|
21476 | _this4.tech_.trigger({
|
21477 | type: 'usage',
|
21478 | name: 'hls-fmp4'
|
21479 | });
|
21480 |
|
21481 | _this4.triggeredFmp4Usage = true;
|
21482 | }
|
21483 | });
|
21484 | this.audioSegmentLoader_.on('ended', function () {
|
21485 | _this4.logger_('audioSegmentLoader ended');
|
21486 |
|
21487 | _this4.onEndOfStream();
|
21488 | });
|
21489 | };
|
21490 |
|
21491 | _proto.mediaSecondsLoaded_ = function mediaSecondsLoaded_() {
|
21492 | return Math.max(this.audioSegmentLoader_.mediaSecondsLoaded + this.mainSegmentLoader_.mediaSecondsLoaded);
|
21493 | }
|
21494 | |
21495 |
|
21496 |
|
21497 | ;
|
21498 |
|
21499 | _proto.load = function load() {
|
21500 | this.mainSegmentLoader_.load();
|
21501 |
|
21502 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
21503 | this.audioSegmentLoader_.load();
|
21504 | }
|
21505 |
|
21506 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
21507 | this.subtitleSegmentLoader_.load();
|
21508 | }
|
21509 | }
|
21510 | |
21511 |
|
21512 |
|
21513 |
|
21514 |
|
21515 |
|
21516 |
|
21517 | ;
|
21518 |
|
21519 | _proto.smoothQualityChange_ = function smoothQualityChange_(media) {
|
21520 | if (media === void 0) {
|
21521 | media = this.selectPlaylist();
|
21522 | }
|
21523 |
|
21524 | if (media === this.masterPlaylistLoader_.media()) {
|
21525 | return;
|
21526 | }
|
21527 |
|
21528 | this.switchMedia_(media, 'smooth-quality');
|
21529 | this.mainSegmentLoader_.resetLoader();
|
21530 | }
|
21531 | |
21532 |
|
21533 |
|
21534 |
|
21535 |
|
21536 |
|
21537 |
|
21538 |
|
21539 | ;
|
21540 |
|
21541 | _proto.fastQualityChange_ = function fastQualityChange_(media) {
|
21542 | var _this5 = this;
|
21543 |
|
21544 | if (media === void 0) {
|
21545 | media = this.selectPlaylist();
|
21546 | }
|
21547 |
|
21548 | if (media === this.masterPlaylistLoader_.media()) {
|
21549 | this.logger_('skipping fastQualityChange because new media is same as old');
|
21550 | return;
|
21551 | }
|
21552 |
|
21553 | this.switchMedia_(media, 'fast-quality');
|
21554 |
|
21555 |
|
21556 |
|
21557 |
|
21558 |
|
21559 |
|
21560 | this.mainSegmentLoader_.resetEverything(function () {
|
21561 |
|
21562 |
|
21563 | if (videojs__default['default'].browser.IE_VERSION || videojs__default['default'].browser.IS_EDGE) {
|
21564 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime() + 0.04);
|
21565 | } else {
|
21566 | _this5.tech_.setCurrentTime(_this5.tech_.currentTime());
|
21567 | }
|
21568 | });
|
21569 | }
|
21570 | |
21571 |
|
21572 |
|
21573 | ;
|
21574 |
|
21575 | _proto.play = function play() {
|
21576 | if (this.setupFirstPlay()) {
|
21577 | return;
|
21578 | }
|
21579 |
|
21580 | if (this.tech_.ended()) {
|
21581 | this.tech_.setCurrentTime(0);
|
21582 | }
|
21583 |
|
21584 | if (this.hasPlayed_) {
|
21585 | this.load();
|
21586 | }
|
21587 |
|
21588 | var seekable = this.tech_.seekable();
|
21589 |
|
21590 |
|
21591 | if (this.tech_.duration() === Infinity) {
|
21592 | if (this.tech_.currentTime() < seekable.start(0)) {
|
21593 | return this.tech_.setCurrentTime(seekable.end(seekable.length - 1));
|
21594 | }
|
21595 | }
|
21596 | }
|
21597 | |
21598 |
|
21599 |
|
21600 |
|
21601 | ;
|
21602 |
|
21603 | _proto.setupFirstPlay = function setupFirstPlay() {
|
21604 | var _this6 = this;
|
21605 |
|
21606 | var media = this.masterPlaylistLoader_.media();
|
21607 |
|
21608 |
|
21609 |
|
21610 |
|
21611 |
|
21612 | if (!media || this.tech_.paused() || this.hasPlayed_) {
|
21613 | return false;
|
21614 | }
|
21615 |
|
21616 |
|
21617 | if (!media.endList) {
|
21618 | var seekable = this.seekable();
|
21619 |
|
21620 | if (!seekable.length) {
|
21621 |
|
21622 |
|
21623 | return false;
|
21624 | }
|
21625 |
|
21626 | if (videojs__default['default'].browser.IE_VERSION && this.tech_.readyState() === 0) {
|
21627 |
|
21628 |
|
21629 | this.tech_.one('loadedmetadata', function () {
|
21630 | _this6.trigger('firstplay');
|
21631 |
|
21632 | _this6.tech_.setCurrentTime(seekable.end(0));
|
21633 |
|
21634 | _this6.hasPlayed_ = true;
|
21635 | });
|
21636 | return false;
|
21637 | }
|
21638 |
|
21639 |
|
21640 | this.trigger('firstplay');
|
21641 |
|
21642 | this.tech_.setCurrentTime(seekable.end(0));
|
21643 | }
|
21644 |
|
21645 | this.hasPlayed_ = true;
|
21646 |
|
21647 | this.load();
|
21648 | return true;
|
21649 | }
|
21650 | |
21651 |
|
21652 |
|
21653 |
|
21654 |
|
21655 | ;
|
21656 |
|
21657 | _proto.handleSourceOpen_ = function handleSourceOpen_() {
|
21658 |
|
21659 |
|
21660 |
|
21661 | this.tryToCreateSourceBuffers_();
|
21662 |
|
21663 |
|
21664 |
|
21665 | if (this.tech_.autoplay()) {
|
21666 | var playPromise = this.tech_.play();
|
21667 |
|
21668 |
|
21669 | if (typeof playPromise !== 'undefined' && typeof playPromise.then === 'function') {
|
21670 | playPromise.then(null, function (e) {});
|
21671 | }
|
21672 | }
|
21673 |
|
21674 | this.trigger('sourceopen');
|
21675 | }
|
21676 | |
21677 |
|
21678 |
|
21679 |
|
21680 |
|
21681 | ;
|
21682 |
|
21683 | _proto.handleSourceEnded_ = function handleSourceEnded_() {
|
21684 | if (!this.inbandTextTracks_.metadataTrack_) {
|
21685 | return;
|
21686 | }
|
21687 |
|
21688 | var cues = this.inbandTextTracks_.metadataTrack_.cues;
|
21689 |
|
21690 | if (!cues || !cues.length) {
|
21691 | return;
|
21692 | }
|
21693 |
|
21694 | var duration = this.duration();
|
21695 | cues[cues.length - 1].endTime = isNaN(duration) || Math.abs(duration) === Infinity ? Number.MAX_VALUE : duration;
|
21696 | }
|
21697 | |
21698 |
|
21699 |
|
21700 |
|
21701 |
|
21702 | ;
|
21703 |
|
21704 | _proto.handleDurationChange_ = function handleDurationChange_() {
|
21705 | this.tech_.trigger('durationchange');
|
21706 | }
|
21707 | |
21708 |
|
21709 |
|
21710 |
|
21711 |
|
21712 |
|
21713 |
|
21714 |
|
21715 | ;
|
21716 |
|
21717 | _proto.onEndOfStream = function onEndOfStream() {
|
21718 | var isEndOfStream = this.mainSegmentLoader_.ended_;
|
21719 |
|
21720 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
21721 |
|
21722 | if (!this.mainSegmentLoader_.currentMediaInfo_ || this.mainSegmentLoader_.currentMediaInfo_.hasVideo) {
|
21723 |
|
21724 |
|
21725 |
|
21726 | isEndOfStream = isEndOfStream && this.audioSegmentLoader_.ended_;
|
21727 | } else {
|
21728 |
|
21729 | isEndOfStream = this.audioSegmentLoader_.ended_;
|
21730 | }
|
21731 | }
|
21732 |
|
21733 | if (!isEndOfStream) {
|
21734 | return;
|
21735 | }
|
21736 |
|
21737 | this.stopABRTimer_();
|
21738 | this.sourceUpdater_.endOfStream();
|
21739 | }
|
21740 | |
21741 |
|
21742 |
|
21743 |
|
21744 |
|
21745 |
|
21746 | ;
|
21747 |
|
21748 | _proto.stuckAtPlaylistEnd_ = function stuckAtPlaylistEnd_(playlist) {
|
21749 | var seekable = this.seekable();
|
21750 |
|
21751 | if (!seekable.length) {
|
21752 |
|
21753 | return false;
|
21754 | }
|
21755 |
|
21756 | var expired = this.syncController_.getExpiredTime(playlist, this.duration());
|
21757 |
|
21758 | if (expired === null) {
|
21759 | return false;
|
21760 | }
|
21761 |
|
21762 |
|
21763 |
|
21764 | var absolutePlaylistEnd = Vhs$1.Playlist.playlistEnd(playlist, expired);
|
21765 | var currentTime = this.tech_.currentTime();
|
21766 | var buffered = this.tech_.buffered();
|
21767 |
|
21768 | if (!buffered.length) {
|
21769 |
|
21770 | return absolutePlaylistEnd - currentTime <= SAFE_TIME_DELTA;
|
21771 | }
|
21772 |
|
21773 | var bufferedEnd = buffered.end(buffered.length - 1);
|
21774 |
|
21775 |
|
21776 | return bufferedEnd - currentTime <= SAFE_TIME_DELTA && absolutePlaylistEnd - bufferedEnd <= SAFE_TIME_DELTA;
|
21777 | }
|
21778 | |
21779 |
|
21780 |
|
21781 |
|
21782 |
|
21783 |
|
21784 |
|
21785 |
|
21786 |
|
21787 |
|
21788 | ;
|
21789 |
|
21790 | _proto.blacklistCurrentPlaylist = function blacklistCurrentPlaylist(error, blacklistDuration) {
|
21791 | if (error === void 0) {
|
21792 | error = {};
|
21793 | }
|
21794 |
|
21795 |
|
21796 |
|
21797 |
|
21798 |
|
21799 | var currentPlaylist = error.playlist || this.masterPlaylistLoader_.media();
|
21800 | blacklistDuration = blacklistDuration || error.blacklistDuration || this.blacklistDuration;
|
21801 |
|
21802 |
|
21803 | if (!currentPlaylist) {
|
21804 | this.error = error;
|
21805 |
|
21806 | if (this.mediaSource.readyState !== 'open') {
|
21807 | this.trigger('error');
|
21808 | } else {
|
21809 | this.sourceUpdater_.endOfStream('network');
|
21810 | }
|
21811 |
|
21812 | return;
|
21813 | }
|
21814 |
|
21815 | var playlists = this.masterPlaylistLoader_.master.playlists;
|
21816 | var enabledPlaylists = playlists.filter(isEnabled);
|
21817 | var isFinalRendition = enabledPlaylists.length === 1 && enabledPlaylists[0] === currentPlaylist;
|
21818 |
|
21819 |
|
21820 | if (playlists.length === 1 && blacklistDuration !== Infinity) {
|
21821 | videojs__default['default'].log.warn("Problem encountered with playlist " + currentPlaylist.id + ". " + 'Trying again since it is the only playlist.');
|
21822 | this.tech_.trigger('retryplaylist');
|
21823 |
|
21824 | return this.masterPlaylistLoader_.load(isFinalRendition);
|
21825 | }
|
21826 |
|
21827 | if (isFinalRendition) {
|
21828 |
|
21829 |
|
21830 |
|
21831 |
|
21832 | var reincluded = false;
|
21833 | playlists.forEach(function (playlist) {
|
21834 |
|
21835 | if (playlist === currentPlaylist) {
|
21836 | return;
|
21837 | }
|
21838 |
|
21839 | var excludeUntil = playlist.excludeUntil;
|
21840 |
|
21841 | if (typeof excludeUntil !== 'undefined' && excludeUntil !== Infinity) {
|
21842 | reincluded = true;
|
21843 | delete playlist.excludeUntil;
|
21844 | }
|
21845 | });
|
21846 |
|
21847 | if (reincluded) {
|
21848 | videojs__default['default'].log.warn('Removing other playlists from the exclusion list because the last ' + 'rendition is about to be excluded.');
|
21849 |
|
21850 |
|
21851 |
|
21852 | this.tech_.trigger('retryplaylist');
|
21853 | }
|
21854 | }
|
21855 |
|
21856 |
|
21857 | currentPlaylist.excludeUntil = Date.now() + blacklistDuration * 1000;
|
21858 |
|
21859 | if (error.reason) {
|
21860 | currentPlaylist.lastExcludeReason_ = error.reason;
|
21861 | }
|
21862 |
|
21863 | this.tech_.trigger('blacklistplaylist');
|
21864 | this.tech_.trigger({
|
21865 | type: 'usage',
|
21866 | name: 'vhs-rendition-blacklisted'
|
21867 | });
|
21868 | this.tech_.trigger({
|
21869 | type: 'usage',
|
21870 | name: 'hls-rendition-blacklisted'
|
21871 | });
|
21872 |
|
21873 |
|
21874 |
|
21875 |
|
21876 |
|
21877 | var nextPlaylist = this.selectPlaylist();
|
21878 |
|
21879 | if (!nextPlaylist) {
|
21880 | this.error = 'Playback cannot continue. No available working or supported playlists.';
|
21881 | this.trigger('error');
|
21882 | return;
|
21883 | }
|
21884 |
|
21885 | var logFn = error.internal ? this.logger_ : videojs__default['default'].log.warn;
|
21886 | var errorMessage = error.message ? ' ' + error.message : '';
|
21887 | logFn((error.internal ? 'Internal problem' : 'Problem') + " encountered with playlist " + currentPlaylist.id + "." + (errorMessage + " Switching to playlist " + nextPlaylist.id + "."));
|
21888 |
|
21889 | if (nextPlaylist.attributes.AUDIO !== currentPlaylist.attributes.AUDIO) {
|
21890 | this.delegateLoaders_('audio', ['abort', 'pause']);
|
21891 | }
|
21892 |
|
21893 |
|
21894 | if (nextPlaylist.attributes.SUBTITLES !== currentPlaylist.attributes.SUBTITLES) {
|
21895 | this.delegateLoaders_('subtitle', ['abort', 'pause']);
|
21896 | }
|
21897 |
|
21898 | this.delegateLoaders_('main', ['abort', 'pause']);
|
21899 | var delayDuration = nextPlaylist.targetDuration / 2 * 1000 || 5 * 1000;
|
21900 | var shouldDelay = typeof nextPlaylist.lastRequest === 'number' && Date.now() - nextPlaylist.lastRequest <= delayDuration;
|
21901 |
|
21902 | return this.switchMedia_(nextPlaylist, 'exclude', isFinalRendition || shouldDelay);
|
21903 | }
|
21904 | |
21905 |
|
21906 |
|
21907 | ;
|
21908 |
|
21909 | _proto.pauseLoading = function pauseLoading() {
|
21910 | this.delegateLoaders_('all', ['abort', 'pause']);
|
21911 | this.stopABRTimer_();
|
21912 | }
|
21913 | |
21914 |
|
21915 |
|
21916 |
|
21917 |
|
21918 |
|
21919 |
|
21920 |
|
21921 |
|
21922 |
|
21923 |
|
21924 |
|
21925 |
|
21926 |
|
21927 | ;
|
21928 |
|
21929 | _proto.delegateLoaders_ = function delegateLoaders_(filter, fnNames) {
|
21930 | var _this7 = this;
|
21931 |
|
21932 | var loaders = [];
|
21933 | var dontFilterPlaylist = filter === 'all';
|
21934 |
|
21935 | if (dontFilterPlaylist || filter === 'main') {
|
21936 | loaders.push(this.masterPlaylistLoader_);
|
21937 | }
|
21938 |
|
21939 | var mediaTypes = [];
|
21940 |
|
21941 | if (dontFilterPlaylist || filter === 'audio') {
|
21942 | mediaTypes.push('AUDIO');
|
21943 | }
|
21944 |
|
21945 | if (dontFilterPlaylist || filter === 'subtitle') {
|
21946 | mediaTypes.push('CLOSED-CAPTIONS');
|
21947 | mediaTypes.push('SUBTITLES');
|
21948 | }
|
21949 |
|
21950 | mediaTypes.forEach(function (mediaType) {
|
21951 | var loader = _this7.mediaTypes_[mediaType] && _this7.mediaTypes_[mediaType].activePlaylistLoader;
|
21952 |
|
21953 | if (loader) {
|
21954 | loaders.push(loader);
|
21955 | }
|
21956 | });
|
21957 | ['main', 'audio', 'subtitle'].forEach(function (name) {
|
21958 | var loader = _this7[name + "SegmentLoader_"];
|
21959 |
|
21960 | if (loader && (filter === name || filter === 'all')) {
|
21961 | loaders.push(loader);
|
21962 | }
|
21963 | });
|
21964 | loaders.forEach(function (loader) {
|
21965 | return fnNames.forEach(function (fnName) {
|
21966 | if (typeof loader[fnName] === 'function') {
|
21967 | loader[fnName]();
|
21968 | }
|
21969 | });
|
21970 | });
|
21971 | }
|
21972 | |
21973 |
|
21974 |
|
21975 |
|
21976 |
|
21977 |
|
21978 | ;
|
21979 |
|
21980 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
21981 | var buffered = findRange(this.tech_.buffered(), currentTime);
|
21982 |
|
21983 | if (!(this.masterPlaylistLoader_ && this.masterPlaylistLoader_.media())) {
|
21984 |
|
21985 | return 0;
|
21986 | }
|
21987 |
|
21988 |
|
21989 |
|
21990 | if (!this.masterPlaylistLoader_.media().segments) {
|
21991 | return 0;
|
21992 | }
|
21993 |
|
21994 |
|
21995 | if (buffered && buffered.length) {
|
21996 | return currentTime;
|
21997 | }
|
21998 |
|
21999 |
|
22000 |
|
22001 | this.mainSegmentLoader_.resetEverything();
|
22002 | this.mainSegmentLoader_.abort();
|
22003 |
|
22004 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
22005 | this.audioSegmentLoader_.resetEverything();
|
22006 | this.audioSegmentLoader_.abort();
|
22007 | }
|
22008 |
|
22009 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
22010 | this.subtitleSegmentLoader_.resetEverything();
|
22011 | this.subtitleSegmentLoader_.abort();
|
22012 | }
|
22013 |
|
22014 |
|
22015 | this.load();
|
22016 | }
|
22017 | |
22018 |
|
22019 |
|
22020 |
|
22021 |
|
22022 | ;
|
22023 |
|
22024 | _proto.duration = function duration() {
|
22025 | if (!this.masterPlaylistLoader_) {
|
22026 | return 0;
|
22027 | }
|
22028 |
|
22029 | var media = this.masterPlaylistLoader_.media();
|
22030 |
|
22031 | if (!media) {
|
22032 |
|
22033 | return 0;
|
22034 | }
|
22035 |
|
22036 |
|
22037 |
|
22038 |
|
22039 |
|
22040 |
|
22041 |
|
22042 |
|
22043 |
|
22044 |
|
22045 |
|
22046 | if (!media.endList) {
|
22047 | return Infinity;
|
22048 | }
|
22049 |
|
22050 |
|
22051 |
|
22052 | if (this.mediaSource) {
|
22053 | return this.mediaSource.duration;
|
22054 | }
|
22055 |
|
22056 | return Vhs$1.Playlist.duration(media);
|
22057 | }
|
22058 | |
22059 |
|
22060 |
|
22061 |
|
22062 |
|
22063 | ;
|
22064 |
|
22065 | _proto.seekable = function seekable() {
|
22066 | return this.seekable_;
|
22067 | };
|
22068 |
|
22069 | _proto.onSyncInfoUpdate_ = function onSyncInfoUpdate_() {
|
22070 | var audioSeekable;
|
22071 |
|
22072 | if (!this.masterPlaylistLoader_) {
|
22073 | return;
|
22074 | }
|
22075 |
|
22076 | var media = this.masterPlaylistLoader_.media();
|
22077 |
|
22078 | if (!media) {
|
22079 | return;
|
22080 | }
|
22081 |
|
22082 | var expired = this.syncController_.getExpiredTime(media, this.duration());
|
22083 |
|
22084 | if (expired === null) {
|
22085 |
|
22086 | return;
|
22087 | }
|
22088 |
|
22089 | var master = this.masterPlaylistLoader_.master;
|
22090 | var mainSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
22091 |
|
22092 | if (mainSeekable.length === 0) {
|
22093 | return;
|
22094 | }
|
22095 |
|
22096 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
22097 | media = this.mediaTypes_.AUDIO.activePlaylistLoader.media();
|
22098 | expired = this.syncController_.getExpiredTime(media, this.duration());
|
22099 |
|
22100 | if (expired === null) {
|
22101 | return;
|
22102 | }
|
22103 |
|
22104 | audioSeekable = Vhs$1.Playlist.seekable(media, expired, Vhs$1.Playlist.liveEdgeDelay(master, media));
|
22105 |
|
22106 | if (audioSeekable.length === 0) {
|
22107 | return;
|
22108 | }
|
22109 | }
|
22110 |
|
22111 | var oldEnd;
|
22112 | var oldStart;
|
22113 |
|
22114 | if (this.seekable_ && this.seekable_.length) {
|
22115 | oldEnd = this.seekable_.end(0);
|
22116 | oldStart = this.seekable_.start(0);
|
22117 | }
|
22118 |
|
22119 | if (!audioSeekable) {
|
22120 |
|
22121 |
|
22122 | this.seekable_ = mainSeekable;
|
22123 | } else if (audioSeekable.start(0) > mainSeekable.end(0) || mainSeekable.start(0) > audioSeekable.end(0)) {
|
22124 |
|
22125 | this.seekable_ = mainSeekable;
|
22126 | } else {
|
22127 | 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)]]);
|
22128 | }
|
22129 |
|
22130 |
|
22131 | if (this.seekable_ && this.seekable_.length) {
|
22132 | if (this.seekable_.end(0) === oldEnd && this.seekable_.start(0) === oldStart) {
|
22133 | return;
|
22134 | }
|
22135 | }
|
22136 |
|
22137 | this.logger_("seekable updated [" + printableRange(this.seekable_) + "]");
|
22138 | this.tech_.trigger('seekablechanged');
|
22139 | }
|
22140 | |
22141 |
|
22142 |
|
22143 | ;
|
22144 |
|
22145 | _proto.updateDuration = function updateDuration(isLive) {
|
22146 | if (this.updateDuration_) {
|
22147 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
22148 | this.updateDuration_ = null;
|
22149 | }
|
22150 |
|
22151 | if (this.mediaSource.readyState !== 'open') {
|
22152 | this.updateDuration_ = this.updateDuration.bind(this, isLive);
|
22153 | this.mediaSource.addEventListener('sourceopen', this.updateDuration_);
|
22154 | return;
|
22155 | }
|
22156 |
|
22157 | if (isLive) {
|
22158 | var seekable = this.seekable();
|
22159 |
|
22160 | if (!seekable.length) {
|
22161 | return;
|
22162 | }
|
22163 |
|
22164 |
|
22165 |
|
22166 |
|
22167 |
|
22168 |
|
22169 |
|
22170 |
|
22171 |
|
22172 |
|
22173 |
|
22174 |
|
22175 |
|
22176 |
|
22177 |
|
22178 |
|
22179 |
|
22180 |
|
22181 |
|
22182 |
|
22183 |
|
22184 |
|
22185 |
|
22186 |
|
22187 | if (isNaN(this.mediaSource.duration) || this.mediaSource.duration < seekable.end(seekable.length - 1)) {
|
22188 | this.sourceUpdater_.setDuration(seekable.end(seekable.length - 1));
|
22189 | }
|
22190 |
|
22191 | return;
|
22192 | }
|
22193 |
|
22194 | var buffered = this.tech_.buffered();
|
22195 | var duration = Vhs$1.Playlist.duration(this.masterPlaylistLoader_.media());
|
22196 |
|
22197 | if (buffered.length > 0) {
|
22198 | duration = Math.max(duration, buffered.end(buffered.length - 1));
|
22199 | }
|
22200 |
|
22201 | if (this.mediaSource.duration !== duration) {
|
22202 | this.sourceUpdater_.setDuration(duration);
|
22203 | }
|
22204 | }
|
22205 | |
22206 |
|
22207 |
|
22208 |
|
22209 | ;
|
22210 |
|
22211 | _proto.dispose = function dispose() {
|
22212 | var _this8 = this;
|
22213 |
|
22214 | this.trigger('dispose');
|
22215 | this.decrypter_.terminate();
|
22216 | this.masterPlaylistLoader_.dispose();
|
22217 | this.mainSegmentLoader_.dispose();
|
22218 |
|
22219 | if (this.loadOnPlay_) {
|
22220 | this.tech_.off('play', this.loadOnPlay_);
|
22221 | }
|
22222 |
|
22223 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
22224 | var groups = _this8.mediaTypes_[type].groups;
|
22225 |
|
22226 | for (var id in groups) {
|
22227 | groups[id].forEach(function (group) {
|
22228 | if (group.playlistLoader) {
|
22229 | group.playlistLoader.dispose();
|
22230 | }
|
22231 | });
|
22232 | }
|
22233 | });
|
22234 | this.audioSegmentLoader_.dispose();
|
22235 | this.subtitleSegmentLoader_.dispose();
|
22236 | this.sourceUpdater_.dispose();
|
22237 | this.timelineChangeController_.dispose();
|
22238 | this.stopABRTimer_();
|
22239 |
|
22240 | if (this.updateDuration_) {
|
22241 | this.mediaSource.removeEventListener('sourceopen', this.updateDuration_);
|
22242 | }
|
22243 |
|
22244 | this.mediaSource.removeEventListener('durationchange', this.handleDurationChange_);
|
22245 |
|
22246 | this.mediaSource.removeEventListener('sourceopen', this.handleSourceOpen_);
|
22247 | this.mediaSource.removeEventListener('sourceended', this.handleSourceEnded_);
|
22248 | this.off();
|
22249 | }
|
22250 | |
22251 |
|
22252 |
|
22253 |
|
22254 |
|
22255 | ;
|
22256 |
|
22257 | _proto.master = function master() {
|
22258 | return this.masterPlaylistLoader_.master;
|
22259 | }
|
22260 | |
22261 |
|
22262 |
|
22263 |
|
22264 |
|
22265 | ;
|
22266 |
|
22267 | _proto.media = function media() {
|
22268 |
|
22269 | return this.masterPlaylistLoader_.media() || this.initialMedia_;
|
22270 | };
|
22271 |
|
22272 | _proto.areMediaTypesKnown_ = function areMediaTypesKnown_() {
|
22273 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
22274 |
|
22275 | if (!this.mainSegmentLoader_.currentMediaInfo_ || usingAudioLoader && !this.audioSegmentLoader_.currentMediaInfo_) {
|
22276 | return false;
|
22277 | }
|
22278 |
|
22279 | return true;
|
22280 | };
|
22281 |
|
22282 | _proto.getCodecsOrExclude_ = function getCodecsOrExclude_() {
|
22283 | var _this9 = this;
|
22284 |
|
22285 | var media = {
|
22286 | main: this.mainSegmentLoader_.currentMediaInfo_ || {},
|
22287 | audio: this.audioSegmentLoader_.currentMediaInfo_ || {}
|
22288 | };
|
22289 |
|
22290 | media.video = media.main;
|
22291 | var playlistCodecs = codecsForPlaylist(this.master(), this.media());
|
22292 | var codecs = {};
|
22293 | var usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;
|
22294 |
|
22295 | if (media.main.hasVideo) {
|
22296 | codecs.video = playlistCodecs.video || media.main.videoCodec || codecs_js.DEFAULT_VIDEO_CODEC;
|
22297 | }
|
22298 |
|
22299 | if (media.main.isMuxed) {
|
22300 | codecs.video += "," + (playlistCodecs.audio || media.main.audioCodec || codecs_js.DEFAULT_AUDIO_CODEC);
|
22301 | }
|
22302 |
|
22303 | if (media.main.hasAudio && !media.main.isMuxed || media.audio.hasAudio || usingAudioLoader) {
|
22304 | codecs.audio = playlistCodecs.audio || media.main.audioCodec || media.audio.audioCodec || codecs_js.DEFAULT_AUDIO_CODEC;
|
22305 |
|
22306 | media.audio.isFmp4 = media.main.hasAudio && !media.main.isMuxed ? media.main.isFmp4 : media.audio.isFmp4;
|
22307 | }
|
22308 |
|
22309 |
|
22310 | if (!codecs.audio && !codecs.video) {
|
22311 | this.blacklistCurrentPlaylist({
|
22312 | playlist: this.media(),
|
22313 | message: 'Could not determine codecs for playlist.',
|
22314 | blacklistDuration: Infinity
|
22315 | });
|
22316 | return;
|
22317 | }
|
22318 |
|
22319 |
|
22320 | var supportFunction = function supportFunction(isFmp4, codec) {
|
22321 | return isFmp4 ? codecs_js.browserSupportsCodec(codec) : codecs_js.muxerSupportsCodec(codec);
|
22322 | };
|
22323 |
|
22324 | var unsupportedCodecs = {};
|
22325 | var unsupportedAudio;
|
22326 | ['video', 'audio'].forEach(function (type) {
|
22327 | if (codecs.hasOwnProperty(type) && !supportFunction(media[type].isFmp4, codecs[type])) {
|
22328 | var supporter = media[type].isFmp4 ? 'browser' : 'muxer';
|
22329 | unsupportedCodecs[supporter] = unsupportedCodecs[supporter] || [];
|
22330 | unsupportedCodecs[supporter].push(codecs[type]);
|
22331 |
|
22332 | if (type === 'audio') {
|
22333 | unsupportedAudio = supporter;
|
22334 | }
|
22335 | }
|
22336 | });
|
22337 |
|
22338 | if (usingAudioLoader && unsupportedAudio && this.media().attributes.AUDIO) {
|
22339 | var audioGroup = this.media().attributes.AUDIO;
|
22340 | this.master().playlists.forEach(function (variant) {
|
22341 | var variantAudioGroup = variant.attributes && variant.attributes.AUDIO;
|
22342 |
|
22343 | if (variantAudioGroup === audioGroup && variant !== _this9.media()) {
|
22344 | variant.excludeUntil = Infinity;
|
22345 | }
|
22346 | });
|
22347 | this.logger_("excluding audio group " + audioGroup + " as " + unsupportedAudio + " does not support codec(s): \"" + codecs.audio + "\"");
|
22348 | }
|
22349 |
|
22350 |
|
22351 | if (Object.keys(unsupportedCodecs).length) {
|
22352 | var message = Object.keys(unsupportedCodecs).reduce(function (acc, supporter) {
|
22353 | if (acc) {
|
22354 | acc += ', ';
|
22355 | }
|
22356 |
|
22357 | acc += supporter + " does not support codec(s): \"" + unsupportedCodecs[supporter].join(',') + "\"";
|
22358 | return acc;
|
22359 | }, '') + '.';
|
22360 | this.blacklistCurrentPlaylist({
|
22361 | playlist: this.media(),
|
22362 | internal: true,
|
22363 | message: message,
|
22364 | blacklistDuration: Infinity
|
22365 | });
|
22366 | return;
|
22367 | }
|
22368 |
|
22369 |
|
22370 | if (this.sourceUpdater_.hasCreatedSourceBuffers() && !this.sourceUpdater_.canChangeType()) {
|
22371 | var switchMessages = [];
|
22372 | ['video', 'audio'].forEach(function (type) {
|
22373 | var newCodec = (codecs_js.parseCodecs(_this9.sourceUpdater_.codecs[type] || '')[0] || {}).type;
|
22374 | var oldCodec = (codecs_js.parseCodecs(codecs[type] || '')[0] || {}).type;
|
22375 |
|
22376 | if (newCodec && oldCodec && newCodec.toLowerCase() !== oldCodec.toLowerCase()) {
|
22377 | switchMessages.push("\"" + _this9.sourceUpdater_.codecs[type] + "\" -> \"" + codecs[type] + "\"");
|
22378 | }
|
22379 | });
|
22380 |
|
22381 | if (switchMessages.length) {
|
22382 | this.blacklistCurrentPlaylist({
|
22383 | playlist: this.media(),
|
22384 | message: "Codec switching not supported: " + switchMessages.join(', ') + ".",
|
22385 | blacklistDuration: Infinity,
|
22386 | internal: true
|
22387 | });
|
22388 | return;
|
22389 | }
|
22390 | }
|
22391 |
|
22392 |
|
22393 |
|
22394 | return codecs;
|
22395 | }
|
22396 | |
22397 |
|
22398 |
|
22399 |
|
22400 |
|
22401 | ;
|
22402 |
|
22403 | _proto.tryToCreateSourceBuffers_ = function tryToCreateSourceBuffers_() {
|
22404 |
|
22405 |
|
22406 | if (this.mediaSource.readyState !== 'open' || this.sourceUpdater_.hasCreatedSourceBuffers()) {
|
22407 | return;
|
22408 | }
|
22409 |
|
22410 | if (!this.areMediaTypesKnown_()) {
|
22411 | return;
|
22412 | }
|
22413 |
|
22414 | var codecs = this.getCodecsOrExclude_();
|
22415 |
|
22416 | if (!codecs) {
|
22417 | return;
|
22418 | }
|
22419 |
|
22420 | this.sourceUpdater_.createSourceBuffers(codecs);
|
22421 | var codecString = [codecs.video, codecs.audio].filter(Boolean).join(',');
|
22422 | this.excludeIncompatibleVariants_(codecString);
|
22423 | }
|
22424 | |
22425 |
|
22426 |
|
22427 | ;
|
22428 |
|
22429 | _proto.excludeUnsupportedVariants_ = function excludeUnsupportedVariants_() {
|
22430 | var _this10 = this;
|
22431 |
|
22432 | var playlists = this.master().playlists;
|
22433 | var ids = [];
|
22434 |
|
22435 |
|
22436 | Object.keys(playlists).forEach(function (key) {
|
22437 | var variant = playlists[key];
|
22438 |
|
22439 | if (ids.indexOf(variant.id) !== -1) {
|
22440 | return;
|
22441 | }
|
22442 |
|
22443 | ids.push(variant.id);
|
22444 | var codecs = codecsForPlaylist(_this10.master, variant);
|
22445 | var unsupported = [];
|
22446 |
|
22447 | if (codecs.audio && !codecs_js.muxerSupportsCodec(codecs.audio) && !codecs_js.browserSupportsCodec(codecs.audio)) {
|
22448 | unsupported.push("audio codec " + codecs.audio);
|
22449 | }
|
22450 |
|
22451 | if (codecs.video && !codecs_js.muxerSupportsCodec(codecs.video) && !codecs_js.browserSupportsCodec(codecs.video)) {
|
22452 | unsupported.push("video codec " + codecs.video);
|
22453 | }
|
22454 |
|
22455 | if (codecs.text && codecs.text === 'stpp.ttml.im1t') {
|
22456 | unsupported.push("text codec " + codecs.text);
|
22457 | }
|
22458 |
|
22459 | if (unsupported.length) {
|
22460 | variant.excludeUntil = Infinity;
|
22461 |
|
22462 | _this10.logger_("excluding " + variant.id + " for unsupported: " + unsupported.join(', '));
|
22463 | }
|
22464 | });
|
22465 | }
|
22466 | |
22467 |
|
22468 |
|
22469 |
|
22470 |
|
22471 |
|
22472 |
|
22473 |
|
22474 |
|
22475 |
|
22476 |
|
22477 |
|
22478 |
|
22479 |
|
22480 | ;
|
22481 |
|
22482 | _proto.excludeIncompatibleVariants_ = function excludeIncompatibleVariants_(codecString) {
|
22483 | var _this11 = this;
|
22484 |
|
22485 | var ids = [];
|
22486 | var playlists = this.master().playlists;
|
22487 | var codecs = unwrapCodecList(codecs_js.parseCodecs(codecString));
|
22488 | var codecCount_ = codecCount(codecs);
|
22489 | var videoDetails = codecs.video && codecs_js.parseCodecs(codecs.video)[0] || null;
|
22490 | var audioDetails = codecs.audio && codecs_js.parseCodecs(codecs.audio)[0] || null;
|
22491 | Object.keys(playlists).forEach(function (key) {
|
22492 | var variant = playlists[key];
|
22493 |
|
22494 |
|
22495 | if (ids.indexOf(variant.id) !== -1 || variant.excludeUntil === Infinity) {
|
22496 | return;
|
22497 | }
|
22498 |
|
22499 | ids.push(variant.id);
|
22500 | var blacklistReasons = [];
|
22501 |
|
22502 | var variantCodecs = codecsForPlaylist(_this11.masterPlaylistLoader_.master, variant);
|
22503 | var variantCodecCount = codecCount(variantCodecs);
|
22504 |
|
22505 |
|
22506 | if (!variantCodecs.audio && !variantCodecs.video) {
|
22507 | return;
|
22508 | }
|
22509 |
|
22510 |
|
22511 |
|
22512 |
|
22513 | if (variantCodecCount !== codecCount_) {
|
22514 | blacklistReasons.push("codec count \"" + variantCodecCount + "\" !== \"" + codecCount_ + "\"");
|
22515 | }
|
22516 |
|
22517 |
|
22518 |
|
22519 | if (!_this11.sourceUpdater_.canChangeType()) {
|
22520 | var variantVideoDetails = variantCodecs.video && codecs_js.parseCodecs(variantCodecs.video)[0] || null;
|
22521 | var variantAudioDetails = variantCodecs.audio && codecs_js.parseCodecs(variantCodecs.audio)[0] || null;
|
22522 |
|
22523 | if (variantVideoDetails && videoDetails && variantVideoDetails.type.toLowerCase() !== videoDetails.type.toLowerCase()) {
|
22524 | blacklistReasons.push("video codec \"" + variantVideoDetails.type + "\" !== \"" + videoDetails.type + "\"");
|
22525 | }
|
22526 |
|
22527 |
|
22528 | if (variantAudioDetails && audioDetails && variantAudioDetails.type.toLowerCase() !== audioDetails.type.toLowerCase()) {
|
22529 | blacklistReasons.push("audio codec \"" + variantAudioDetails.type + "\" !== \"" + audioDetails.type + "\"");
|
22530 | }
|
22531 | }
|
22532 |
|
22533 | if (blacklistReasons.length) {
|
22534 | variant.excludeUntil = Infinity;
|
22535 |
|
22536 | _this11.logger_("blacklisting " + variant.id + ": " + blacklistReasons.join(' && '));
|
22537 | }
|
22538 | });
|
22539 | };
|
22540 |
|
22541 | _proto.updateAdCues_ = function updateAdCues_(media) {
|
22542 | var offset = 0;
|
22543 | var seekable = this.seekable();
|
22544 |
|
22545 | if (seekable.length) {
|
22546 | offset = seekable.start(0);
|
22547 | }
|
22548 |
|
22549 | updateAdCues(media, this.cueTagsTrack_, offset);
|
22550 | }
|
22551 | |
22552 |
|
22553 |
|
22554 |
|
22555 |
|
22556 | ;
|
22557 |
|
22558 | _proto.goalBufferLength = function goalBufferLength() {
|
22559 | var currentTime = this.tech_.currentTime();
|
22560 | var initial = Config.GOAL_BUFFER_LENGTH;
|
22561 | var rate = Config.GOAL_BUFFER_LENGTH_RATE;
|
22562 | var max = Math.max(initial, Config.MAX_GOAL_BUFFER_LENGTH);
|
22563 | return Math.min(initial + currentTime * rate, max);
|
22564 | }
|
22565 | |
22566 |
|
22567 |
|
22568 |
|
22569 |
|
22570 | ;
|
22571 |
|
22572 | _proto.bufferLowWaterLine = function bufferLowWaterLine() {
|
22573 | var currentTime = this.tech_.currentTime();
|
22574 | var initial = Config.BUFFER_LOW_WATER_LINE;
|
22575 | var rate = Config.BUFFER_LOW_WATER_LINE_RATE;
|
22576 | var max = Math.max(initial, Config.MAX_BUFFER_LOW_WATER_LINE);
|
22577 | var newMax = Math.max(initial, Config.EXPERIMENTAL_MAX_BUFFER_LOW_WATER_LINE);
|
22578 | return Math.min(initial + currentTime * rate, this.experimentalBufferBasedABR ? newMax : max);
|
22579 | };
|
22580 |
|
22581 | _proto.bufferHighWaterLine = function bufferHighWaterLine() {
|
22582 | return Config.BUFFER_HIGH_WATER_LINE;
|
22583 | };
|
22584 |
|
22585 | return MasterPlaylistController;
|
22586 | }(videojs__default['default'].EventTarget);
|
22587 |
|
22588 |
|
22589 |
|
22590 |
|
22591 |
|
22592 |
|
22593 |
|
22594 |
|
22595 |
|
22596 |
|
22597 |
|
22598 |
|
22599 |
|
22600 |
|
22601 | var enableFunction = function enableFunction(loader, playlistID, changePlaylistFn) {
|
22602 | return function (enable) {
|
22603 | var playlist = loader.master.playlists[playlistID];
|
22604 | var incompatible = isIncompatible(playlist);
|
22605 | var currentlyEnabled = isEnabled(playlist);
|
22606 |
|
22607 | if (typeof enable === 'undefined') {
|
22608 | return currentlyEnabled;
|
22609 | }
|
22610 |
|
22611 | if (enable) {
|
22612 | delete playlist.disabled;
|
22613 | } else {
|
22614 | playlist.disabled = true;
|
22615 | }
|
22616 |
|
22617 | if (enable !== currentlyEnabled && !incompatible) {
|
22618 |
|
22619 | changePlaylistFn();
|
22620 |
|
22621 | if (enable) {
|
22622 | loader.trigger('renditionenabled');
|
22623 | } else {
|
22624 | loader.trigger('renditiondisabled');
|
22625 | }
|
22626 | }
|
22627 |
|
22628 | return enable;
|
22629 | };
|
22630 | };
|
22631 |
|
22632 |
|
22633 |
|
22634 |
|
22635 |
|
22636 |
|
22637 |
|
22638 |
|
22639 |
|
22640 | var Representation = function Representation(vhsHandler, playlist, id) {
|
22641 | var mpc = vhsHandler.masterPlaylistController_,
|
22642 | smoothQualityChange = vhsHandler.options_.smoothQualityChange;
|
22643 |
|
22644 | var changeType = smoothQualityChange ? 'smooth' : 'fast';
|
22645 | var qualityChangeFunction = mpc[changeType + "QualityChange_"].bind(mpc);
|
22646 |
|
22647 | if (playlist.attributes) {
|
22648 | var resolution = playlist.attributes.RESOLUTION;
|
22649 | this.width = resolution && resolution.width;
|
22650 | this.height = resolution && resolution.height;
|
22651 | this.bandwidth = playlist.attributes.BANDWIDTH;
|
22652 | }
|
22653 |
|
22654 | this.codecs = codecsForPlaylist(mpc.master(), playlist);
|
22655 | this.playlist = playlist;
|
22656 |
|
22657 |
|
22658 | this.id = id;
|
22659 |
|
22660 |
|
22661 | this.enabled = enableFunction(vhsHandler.playlists, playlist.id, qualityChangeFunction);
|
22662 | };
|
22663 |
|
22664 |
|
22665 |
|
22666 |
|
22667 |
|
22668 |
|
22669 |
|
22670 |
|
22671 |
|
22672 | var renditionSelectionMixin = function renditionSelectionMixin(vhsHandler) {
|
22673 |
|
22674 | vhsHandler.representations = function () {
|
22675 | var master = vhsHandler.masterPlaylistController_.master();
|
22676 | var playlists = isAudioOnly(master) ? vhsHandler.masterPlaylistController_.getAudioTrackPlaylists_() : master.playlists;
|
22677 |
|
22678 | if (!playlists) {
|
22679 | return [];
|
22680 | }
|
22681 |
|
22682 | return playlists.filter(function (media) {
|
22683 | return !isIncompatible(media);
|
22684 | }).map(function (e, i) {
|
22685 | return new Representation(vhsHandler, e, e.id);
|
22686 | });
|
22687 | };
|
22688 | };
|
22689 |
|
22690 |
|
22691 |
|
22692 |
|
22693 |
|
22694 |
|
22695 |
|
22696 |
|
22697 |
|
22698 |
|
22699 |
|
22700 | var timerCancelEvents = ['seeking', 'seeked', 'pause', 'playing', 'error'];
|
22701 |
|
22702 |
|
22703 |
|
22704 |
|
22705 |
|
22706 |
|
22707 |
|
22708 |
|
22709 |
|
22710 |
|
22711 |
|
22712 |
|
22713 |
|
22714 |
|
22715 |
|
22716 |
|
22717 | var closeToBufferedContent = function closeToBufferedContent(_ref) {
|
22718 | var buffered = _ref.buffered,
|
22719 | targetDuration = _ref.targetDuration,
|
22720 | currentTime = _ref.currentTime;
|
22721 |
|
22722 | if (!buffered.length) {
|
22723 | return false;
|
22724 | }
|
22725 |
|
22726 |
|
22727 |
|
22728 | if (buffered.end(0) - buffered.start(0) < targetDuration * 2) {
|
22729 | return false;
|
22730 | }
|
22731 |
|
22732 |
|
22733 |
|
22734 |
|
22735 | if (currentTime > buffered.start(0)) {
|
22736 | return false;
|
22737 | }
|
22738 |
|
22739 |
|
22740 |
|
22741 |
|
22742 | return buffered.start(0) - currentTime < targetDuration;
|
22743 | };
|
22744 |
|
22745 |
|
22746 |
|
22747 |
|
22748 | var PlaybackWatcher = function () {
|
22749 | |
22750 |
|
22751 |
|
22752 |
|
22753 |
|
22754 |
|
22755 | function PlaybackWatcher(options) {
|
22756 | var _this = this;
|
22757 |
|
22758 | this.masterPlaylistController_ = options.masterPlaylistController;
|
22759 | this.tech_ = options.tech;
|
22760 | this.seekable = options.seekable;
|
22761 | this.allowSeeksWithinUnsafeLiveWindow = options.allowSeeksWithinUnsafeLiveWindow;
|
22762 | this.liveRangeSafeTimeDelta = options.liveRangeSafeTimeDelta;
|
22763 | this.media = options.media;
|
22764 | this.consecutiveUpdates = 0;
|
22765 | this.lastRecordedTime = null;
|
22766 | this.timer_ = null;
|
22767 | this.checkCurrentTimeTimeout_ = null;
|
22768 | this.logger_ = logger('PlaybackWatcher');
|
22769 | this.logger_('initialize');
|
22770 |
|
22771 | var playHandler = function playHandler() {
|
22772 | return _this.monitorCurrentTime_();
|
22773 | };
|
22774 |
|
22775 | var canPlayHandler = function canPlayHandler() {
|
22776 | return _this.monitorCurrentTime_();
|
22777 | };
|
22778 |
|
22779 | var waitingHandler = function waitingHandler() {
|
22780 | return _this.techWaiting_();
|
22781 | };
|
22782 |
|
22783 | var cancelTimerHandler = function cancelTimerHandler() {
|
22784 | return _this.cancelTimer_();
|
22785 | };
|
22786 |
|
22787 | var fixesBadSeeksHandler = function fixesBadSeeksHandler() {
|
22788 | return _this.fixesBadSeeks_();
|
22789 | };
|
22790 |
|
22791 | var mpc = this.masterPlaylistController_;
|
22792 | var loaderTypes = ['main', 'subtitle', 'audio'];
|
22793 | var loaderChecks = {};
|
22794 | loaderTypes.forEach(function (type) {
|
22795 | loaderChecks[type] = {
|
22796 | reset: function reset() {
|
22797 | return _this.resetSegmentDownloads_(type);
|
22798 | },
|
22799 | updateend: function updateend() {
|
22800 | return _this.checkSegmentDownloads_(type);
|
22801 | }
|
22802 | };
|
22803 | mpc[type + "SegmentLoader_"].on('appendsdone', loaderChecks[type].updateend);
|
22804 |
|
22805 |
|
22806 |
|
22807 | mpc[type + "SegmentLoader_"].on('playlistupdate', loaderChecks[type].reset);
|
22808 |
|
22809 |
|
22810 |
|
22811 |
|
22812 | _this.tech_.on(['seeked', 'seeking'], loaderChecks[type].reset);
|
22813 | });
|
22814 | this.tech_.on('seekablechanged', fixesBadSeeksHandler);
|
22815 | this.tech_.on('waiting', waitingHandler);
|
22816 | this.tech_.on(timerCancelEvents, cancelTimerHandler);
|
22817 | this.tech_.on('canplay', canPlayHandler);
|
22818 | |
22819 |
|
22820 |
|
22821 |
|
22822 |
|
22823 |
|
22824 |
|
22825 |
|
22826 |
|
22827 |
|
22828 |
|
22829 | this.tech_.one('play', playHandler);
|
22830 |
|
22831 | this.dispose = function () {
|
22832 | _this.logger_('dispose');
|
22833 |
|
22834 | _this.tech_.off('seekablechanged', fixesBadSeeksHandler);
|
22835 |
|
22836 | _this.tech_.off('waiting', waitingHandler);
|
22837 |
|
22838 | _this.tech_.off(timerCancelEvents, cancelTimerHandler);
|
22839 |
|
22840 | _this.tech_.off('canplay', canPlayHandler);
|
22841 |
|
22842 | _this.tech_.off('play', playHandler);
|
22843 |
|
22844 | loaderTypes.forEach(function (type) {
|
22845 | mpc[type + "SegmentLoader_"].off('appendsdone', loaderChecks[type].updateend);
|
22846 | mpc[type + "SegmentLoader_"].off('playlistupdate', loaderChecks[type].reset);
|
22847 |
|
22848 | _this.tech_.off(['seeked', 'seeking'], loaderChecks[type].reset);
|
22849 | });
|
22850 |
|
22851 | if (_this.checkCurrentTimeTimeout_) {
|
22852 | window__default['default'].clearTimeout(_this.checkCurrentTimeTimeout_);
|
22853 | }
|
22854 |
|
22855 | _this.cancelTimer_();
|
22856 | };
|
22857 | }
|
22858 | |
22859 |
|
22860 |
|
22861 |
|
22862 |
|
22863 |
|
22864 |
|
22865 | var _proto = PlaybackWatcher.prototype;
|
22866 |
|
22867 | _proto.monitorCurrentTime_ = function monitorCurrentTime_() {
|
22868 | this.checkCurrentTime_();
|
22869 |
|
22870 | if (this.checkCurrentTimeTimeout_) {
|
22871 | window__default['default'].clearTimeout(this.checkCurrentTimeTimeout_);
|
22872 | }
|
22873 |
|
22874 |
|
22875 | this.checkCurrentTimeTimeout_ = window__default['default'].setTimeout(this.monitorCurrentTime_.bind(this), 250);
|
22876 | }
|
22877 | |
22878 |
|
22879 |
|
22880 |
|
22881 |
|
22882 |
|
22883 |
|
22884 |
|
22885 |
|
22886 |
|
22887 | ;
|
22888 |
|
22889 | _proto.resetSegmentDownloads_ = function resetSegmentDownloads_(type) {
|
22890 | var loader = this.masterPlaylistController_[type + "SegmentLoader_"];
|
22891 |
|
22892 | if (this[type + "StalledDownloads_"] > 0) {
|
22893 | this.logger_("resetting possible stalled download count for " + type + " loader");
|
22894 | }
|
22895 |
|
22896 | this[type + "StalledDownloads_"] = 0;
|
22897 | this[type + "Buffered_"] = loader.buffered_();
|
22898 | }
|
22899 | |
22900 |
|
22901 |
|
22902 |
|
22903 |
|
22904 |
|
22905 |
|
22906 |
|
22907 |
|
22908 |
|
22909 | ;
|
22910 |
|
22911 | _proto.checkSegmentDownloads_ = function checkSegmentDownloads_(type) {
|
22912 | var mpc = this.masterPlaylistController_;
|
22913 | var loader = mpc[type + "SegmentLoader_"];
|
22914 | var buffered = loader.buffered_();
|
22915 | var isBufferedDifferent = isRangeDifferent(this[type + "Buffered_"], buffered);
|
22916 | this[type + "Buffered_"] = buffered;
|
22917 |
|
22918 |
|
22919 |
|
22920 | if (isBufferedDifferent) {
|
22921 | this.resetSegmentDownloads_(type);
|
22922 | return;
|
22923 | }
|
22924 |
|
22925 | this[type + "StalledDownloads_"]++;
|
22926 | this.logger_("found #" + this[type + "StalledDownloads_"] + " " + type + " appends that did not increase buffer (possible stalled download)", {
|
22927 | playlistId: loader.playlist_ && loader.playlist_.id,
|
22928 | buffered: timeRangesToArray(buffered)
|
22929 | });
|
22930 |
|
22931 | if (this[type + "StalledDownloads_"] < 10) {
|
22932 | return;
|
22933 | }
|
22934 |
|
22935 | this.logger_(type + " loader stalled download exclusion");
|
22936 | this.resetSegmentDownloads_(type);
|
22937 | this.tech_.trigger({
|
22938 | type: 'usage',
|
22939 | name: "vhs-" + type + "-download-exclusion"
|
22940 | });
|
22941 |
|
22942 | if (type === 'subtitle') {
|
22943 | return;
|
22944 | }
|
22945 |
|
22946 |
|
22947 |
|
22948 | mpc.blacklistCurrentPlaylist({
|
22949 | message: "Excessive " + type + " segment downloading detected."
|
22950 | }, Infinity);
|
22951 | }
|
22952 | |
22953 |
|
22954 |
|
22955 |
|
22956 |
|
22957 |
|
22958 |
|
22959 | ;
|
22960 |
|
22961 | _proto.checkCurrentTime_ = function checkCurrentTime_() {
|
22962 | if (this.tech_.seeking() && this.fixesBadSeeks_()) {
|
22963 | this.consecutiveUpdates = 0;
|
22964 | this.lastRecordedTime = this.tech_.currentTime();
|
22965 | return;
|
22966 | }
|
22967 |
|
22968 | if (this.tech_.paused() || this.tech_.seeking()) {
|
22969 | return;
|
22970 | }
|
22971 |
|
22972 | var currentTime = this.tech_.currentTime();
|
22973 | var buffered = this.tech_.buffered();
|
22974 |
|
22975 | if (this.lastRecordedTime === currentTime && (!buffered.length || currentTime + SAFE_TIME_DELTA >= buffered.end(buffered.length - 1))) {
|
22976 |
|
22977 |
|
22978 |
|
22979 |
|
22980 |
|
22981 | return this.techWaiting_();
|
22982 | }
|
22983 |
|
22984 | if (this.consecutiveUpdates >= 5 && currentTime === this.lastRecordedTime) {
|
22985 | this.consecutiveUpdates++;
|
22986 | this.waiting_();
|
22987 | } else if (currentTime === this.lastRecordedTime) {
|
22988 | this.consecutiveUpdates++;
|
22989 | } else {
|
22990 | this.consecutiveUpdates = 0;
|
22991 | this.lastRecordedTime = currentTime;
|
22992 | }
|
22993 | }
|
22994 | |
22995 |
|
22996 |
|
22997 |
|
22998 |
|
22999 |
|
23000 | ;
|
23001 |
|
23002 | _proto.cancelTimer_ = function cancelTimer_() {
|
23003 | this.consecutiveUpdates = 0;
|
23004 |
|
23005 | if (this.timer_) {
|
23006 | this.logger_('cancelTimer_');
|
23007 | clearTimeout(this.timer_);
|
23008 | }
|
23009 |
|
23010 | this.timer_ = null;
|
23011 | }
|
23012 | |
23013 |
|
23014 |
|
23015 |
|
23016 |
|
23017 |
|
23018 | ;
|
23019 |
|
23020 | _proto.fixesBadSeeks_ = function fixesBadSeeks_() {
|
23021 | var seeking = this.tech_.seeking();
|
23022 |
|
23023 | if (!seeking) {
|
23024 | return false;
|
23025 | }
|
23026 |
|
23027 | var seekable = this.seekable();
|
23028 | var currentTime = this.tech_.currentTime();
|
23029 | var isAfterSeekableRange = this.afterSeekableWindow_(seekable, currentTime, this.media(), this.allowSeeksWithinUnsafeLiveWindow);
|
23030 | var seekTo;
|
23031 |
|
23032 | if (isAfterSeekableRange) {
|
23033 | var seekableEnd = seekable.end(seekable.length - 1);
|
23034 |
|
23035 | seekTo = seekableEnd;
|
23036 | }
|
23037 |
|
23038 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
23039 | var seekableStart = seekable.start(0);
|
23040 |
|
23041 |
|
23042 | seekTo = seekableStart + (
|
23043 |
|
23044 | seekableStart === seekable.end(0) ? 0 : SAFE_TIME_DELTA);
|
23045 | }
|
23046 |
|
23047 | if (typeof seekTo !== 'undefined') {
|
23048 | this.logger_("Trying to seek outside of seekable at time " + currentTime + " with " + ("seekable range " + printableRange(seekable) + ". Seeking to ") + (seekTo + "."));
|
23049 | this.tech_.setCurrentTime(seekTo);
|
23050 | return true;
|
23051 | }
|
23052 |
|
23053 | var buffered = this.tech_.buffered();
|
23054 |
|
23055 | if (closeToBufferedContent({
|
23056 | buffered: buffered,
|
23057 | targetDuration: this.media().targetDuration,
|
23058 | currentTime: currentTime
|
23059 | })) {
|
23060 | seekTo = buffered.start(0) + SAFE_TIME_DELTA;
|
23061 | this.logger_("Buffered region starts (" + buffered.start(0) + ") " + (" just beyond seek point (" + currentTime + "). Seeking to " + seekTo + "."));
|
23062 | this.tech_.setCurrentTime(seekTo);
|
23063 | return true;
|
23064 | }
|
23065 |
|
23066 | return false;
|
23067 | }
|
23068 | |
23069 |
|
23070 |
|
23071 |
|
23072 |
|
23073 | ;
|
23074 |
|
23075 | _proto.waiting_ = function waiting_() {
|
23076 | if (this.techWaiting_()) {
|
23077 | return;
|
23078 | }
|
23079 |
|
23080 |
|
23081 | var currentTime = this.tech_.currentTime();
|
23082 | var buffered = this.tech_.buffered();
|
23083 | var currentRange = findRange(buffered, currentTime);
|
23084 |
|
23085 |
|
23086 |
|
23087 |
|
23088 |
|
23089 |
|
23090 |
|
23091 |
|
23092 | if (currentRange.length && currentTime + 3 <= currentRange.end(0)) {
|
23093 | this.cancelTimer_();
|
23094 | this.tech_.setCurrentTime(currentTime);
|
23095 | 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.');
|
23096 |
|
23097 | this.tech_.trigger({
|
23098 | type: 'usage',
|
23099 | name: 'vhs-unknown-waiting'
|
23100 | });
|
23101 | this.tech_.trigger({
|
23102 | type: 'usage',
|
23103 | name: 'hls-unknown-waiting'
|
23104 | });
|
23105 | return;
|
23106 | }
|
23107 | }
|
23108 | |
23109 |
|
23110 |
|
23111 |
|
23112 |
|
23113 |
|
23114 |
|
23115 |
|
23116 | ;
|
23117 |
|
23118 | _proto.techWaiting_ = function techWaiting_() {
|
23119 | var seekable = this.seekable();
|
23120 | var currentTime = this.tech_.currentTime();
|
23121 |
|
23122 | if (this.tech_.seeking() && this.fixesBadSeeks_()) {
|
23123 |
|
23124 | return true;
|
23125 | }
|
23126 |
|
23127 | if (this.tech_.seeking() || this.timer_ !== null) {
|
23128 |
|
23129 | return true;
|
23130 | }
|
23131 |
|
23132 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
23133 | var livePoint = seekable.end(seekable.length - 1);
|
23134 | this.logger_("Fell out of live window at time " + currentTime + ". Seeking to " + ("live point (seekable end) " + livePoint));
|
23135 | this.cancelTimer_();
|
23136 | this.tech_.setCurrentTime(livePoint);
|
23137 |
|
23138 | this.tech_.trigger({
|
23139 | type: 'usage',
|
23140 | name: 'vhs-live-resync'
|
23141 | });
|
23142 | this.tech_.trigger({
|
23143 | type: 'usage',
|
23144 | name: 'hls-live-resync'
|
23145 | });
|
23146 | return true;
|
23147 | }
|
23148 |
|
23149 | var sourceUpdater = this.tech_.vhs.masterPlaylistController_.sourceUpdater_;
|
23150 | var buffered = this.tech_.buffered();
|
23151 | var videoUnderflow = this.videoUnderflow_({
|
23152 | audioBuffered: sourceUpdater.audioBuffered(),
|
23153 | videoBuffered: sourceUpdater.videoBuffered(),
|
23154 | currentTime: currentTime
|
23155 | });
|
23156 |
|
23157 | if (videoUnderflow) {
|
23158 |
|
23159 |
|
23160 |
|
23161 |
|
23162 | this.cancelTimer_();
|
23163 | this.tech_.setCurrentTime(currentTime);
|
23164 |
|
23165 | this.tech_.trigger({
|
23166 | type: 'usage',
|
23167 | name: 'vhs-video-underflow'
|
23168 | });
|
23169 | this.tech_.trigger({
|
23170 | type: 'usage',
|
23171 | name: 'hls-video-underflow'
|
23172 | });
|
23173 | return true;
|
23174 | }
|
23175 |
|
23176 | var nextRange = findNextRange(buffered, currentTime);
|
23177 |
|
23178 | if (nextRange.length > 0) {
|
23179 | var difference = nextRange.start(0) - currentTime;
|
23180 | this.logger_("Stopped at " + currentTime + ", setting timer for " + difference + ", seeking " + ("to " + nextRange.start(0)));
|
23181 | this.cancelTimer_();
|
23182 | this.timer_ = setTimeout(this.skipTheGap_.bind(this), difference * 1000, currentTime);
|
23183 | return true;
|
23184 | }
|
23185 |
|
23186 |
|
23187 | return false;
|
23188 | };
|
23189 |
|
23190 | _proto.afterSeekableWindow_ = function afterSeekableWindow_(seekable, currentTime, playlist, allowSeeksWithinUnsafeLiveWindow) {
|
23191 | if (allowSeeksWithinUnsafeLiveWindow === void 0) {
|
23192 | allowSeeksWithinUnsafeLiveWindow = false;
|
23193 | }
|
23194 |
|
23195 | if (!seekable.length) {
|
23196 |
|
23197 | return false;
|
23198 | }
|
23199 |
|
23200 | var allowedEnd = seekable.end(seekable.length - 1) + SAFE_TIME_DELTA;
|
23201 | var isLive = !playlist.endList;
|
23202 |
|
23203 | if (isLive && allowSeeksWithinUnsafeLiveWindow) {
|
23204 | allowedEnd = seekable.end(seekable.length - 1) + playlist.targetDuration * 3;
|
23205 | }
|
23206 |
|
23207 | if (currentTime > allowedEnd) {
|
23208 | return true;
|
23209 | }
|
23210 |
|
23211 | return false;
|
23212 | };
|
23213 |
|
23214 | _proto.beforeSeekableWindow_ = function beforeSeekableWindow_(seekable, currentTime) {
|
23215 | if (seekable.length &&
|
23216 | seekable.start(0) > 0 && currentTime < seekable.start(0) - this.liveRangeSafeTimeDelta) {
|
23217 | return true;
|
23218 | }
|
23219 |
|
23220 | return false;
|
23221 | };
|
23222 |
|
23223 | _proto.videoUnderflow_ = function videoUnderflow_(_ref2) {
|
23224 | var videoBuffered = _ref2.videoBuffered,
|
23225 | audioBuffered = _ref2.audioBuffered,
|
23226 | currentTime = _ref2.currentTime;
|
23227 |
|
23228 |
|
23229 | if (!videoBuffered) {
|
23230 | return;
|
23231 | }
|
23232 |
|
23233 | var gap;
|
23234 |
|
23235 | if (videoBuffered.length && audioBuffered.length) {
|
23236 |
|
23237 |
|
23238 |
|
23239 | var lastVideoRange = findRange(videoBuffered, currentTime - 3);
|
23240 | var videoRange = findRange(videoBuffered, currentTime);
|
23241 | var audioRange = findRange(audioBuffered, currentTime);
|
23242 |
|
23243 | if (audioRange.length && !videoRange.length && lastVideoRange.length) {
|
23244 | gap = {
|
23245 | start: lastVideoRange.end(0),
|
23246 | end: audioRange.end(0)
|
23247 | };
|
23248 | }
|
23249 |
|
23250 | } else {
|
23251 | var nextRange = findNextRange(videoBuffered, currentTime);
|
23252 |
|
23253 |
|
23254 | if (!nextRange.length) {
|
23255 | gap = this.gapFromVideoUnderflow_(videoBuffered, currentTime);
|
23256 | }
|
23257 | }
|
23258 |
|
23259 | if (gap) {
|
23260 | this.logger_("Encountered a gap in video from " + gap.start + " to " + gap.end + ". " + ("Seeking to current time " + currentTime));
|
23261 | return true;
|
23262 | }
|
23263 |
|
23264 | return false;
|
23265 | }
|
23266 | |
23267 |
|
23268 |
|
23269 |
|
23270 |
|
23271 |
|
23272 | ;
|
23273 |
|
23274 | _proto.skipTheGap_ = function skipTheGap_(scheduledCurrentTime) {
|
23275 | var buffered = this.tech_.buffered();
|
23276 | var currentTime = this.tech_.currentTime();
|
23277 | var nextRange = findNextRange(buffered, currentTime);
|
23278 | this.cancelTimer_();
|
23279 |
|
23280 | if (nextRange.length === 0 || currentTime !== scheduledCurrentTime) {
|
23281 | return;
|
23282 | }
|
23283 |
|
23284 | this.logger_('skipTheGap_:', 'currentTime:', currentTime, 'scheduled currentTime:', scheduledCurrentTime, 'nextRange start:', nextRange.start(0));
|
23285 |
|
23286 | this.tech_.setCurrentTime(nextRange.start(0) + TIME_FUDGE_FACTOR);
|
23287 | this.tech_.trigger({
|
23288 | type: 'usage',
|
23289 | name: 'vhs-gap-skip'
|
23290 | });
|
23291 | this.tech_.trigger({
|
23292 | type: 'usage',
|
23293 | name: 'hls-gap-skip'
|
23294 | });
|
23295 | };
|
23296 |
|
23297 | _proto.gapFromVideoUnderflow_ = function gapFromVideoUnderflow_(buffered, currentTime) {
|
23298 |
|
23299 |
|
23300 |
|
23301 |
|
23302 |
|
23303 |
|
23304 |
|
23305 |
|
23306 |
|
23307 |
|
23308 |
|
23309 |
|
23310 |
|
23311 |
|
23312 |
|
23313 |
|
23314 |
|
23315 |
|
23316 |
|
23317 |
|
23318 |
|
23319 |
|
23320 | var gaps = findGaps(buffered);
|
23321 |
|
23322 | for (var i = 0; i < gaps.length; i++) {
|
23323 | var start = gaps.start(i);
|
23324 | var end = gaps.end(i);
|
23325 |
|
23326 | if (currentTime - start < 4 && currentTime - start > 2) {
|
23327 | return {
|
23328 | start: start,
|
23329 | end: end
|
23330 | };
|
23331 | }
|
23332 | }
|
23333 |
|
23334 | return null;
|
23335 | };
|
23336 |
|
23337 | return PlaybackWatcher;
|
23338 | }();
|
23339 |
|
23340 | var defaultOptions = {
|
23341 | errorInterval: 30,
|
23342 | getSource: function getSource(next) {
|
23343 | var tech = this.tech({
|
23344 | IWillNotUseThisInPlugins: true
|
23345 | });
|
23346 | var sourceObj = tech.currentSource_ || this.currentSource();
|
23347 | return next(sourceObj);
|
23348 | }
|
23349 | };
|
23350 |
|
23351 |
|
23352 |
|
23353 |
|
23354 |
|
23355 |
|
23356 |
|
23357 |
|
23358 | var initPlugin = function initPlugin(player, options) {
|
23359 | var lastCalled = 0;
|
23360 | var seekTo = 0;
|
23361 | var localOptions = videojs__default['default'].mergeOptions(defaultOptions, options);
|
23362 | player.ready(function () {
|
23363 | player.trigger({
|
23364 | type: 'usage',
|
23365 | name: 'vhs-error-reload-initialized'
|
23366 | });
|
23367 | player.trigger({
|
23368 | type: 'usage',
|
23369 | name: 'hls-error-reload-initialized'
|
23370 | });
|
23371 | });
|
23372 | |
23373 |
|
23374 |
|
23375 |
|
23376 |
|
23377 |
|
23378 |
|
23379 | var loadedMetadataHandler = function loadedMetadataHandler() {
|
23380 | if (seekTo) {
|
23381 | player.currentTime(seekTo);
|
23382 | }
|
23383 | };
|
23384 | |
23385 |
|
23386 |
|
23387 |
|
23388 |
|
23389 |
|
23390 |
|
23391 |
|
23392 | var setSource = function setSource(sourceObj) {
|
23393 | if (sourceObj === null || sourceObj === undefined) {
|
23394 | return;
|
23395 | }
|
23396 |
|
23397 | seekTo = player.duration() !== Infinity && player.currentTime() || 0;
|
23398 | player.one('loadedmetadata', loadedMetadataHandler);
|
23399 | player.src(sourceObj);
|
23400 | player.trigger({
|
23401 | type: 'usage',
|
23402 | name: 'vhs-error-reload'
|
23403 | });
|
23404 | player.trigger({
|
23405 | type: 'usage',
|
23406 | name: 'hls-error-reload'
|
23407 | });
|
23408 | player.play();
|
23409 | };
|
23410 | |
23411 |
|
23412 |
|
23413 |
|
23414 |
|
23415 |
|
23416 |
|
23417 |
|
23418 | var errorHandler = function errorHandler() {
|
23419 |
|
23420 |
|
23421 | if (Date.now() - lastCalled < localOptions.errorInterval * 1000) {
|
23422 | player.trigger({
|
23423 | type: 'usage',
|
23424 | name: 'vhs-error-reload-canceled'
|
23425 | });
|
23426 | player.trigger({
|
23427 | type: 'usage',
|
23428 | name: 'hls-error-reload-canceled'
|
23429 | });
|
23430 | return;
|
23431 | }
|
23432 |
|
23433 | if (!localOptions.getSource || typeof localOptions.getSource !== 'function') {
|
23434 | videojs__default['default'].log.error('ERROR: reloadSourceOnError - The option getSource must be a function!');
|
23435 | return;
|
23436 | }
|
23437 |
|
23438 | lastCalled = Date.now();
|
23439 | return localOptions.getSource.call(player, setSource);
|
23440 | };
|
23441 | |
23442 |
|
23443 |
|
23444 |
|
23445 |
|
23446 |
|
23447 |
|
23448 | var cleanupEvents = function cleanupEvents() {
|
23449 | player.off('loadedmetadata', loadedMetadataHandler);
|
23450 | player.off('error', errorHandler);
|
23451 | player.off('dispose', cleanupEvents);
|
23452 | };
|
23453 | |
23454 |
|
23455 |
|
23456 |
|
23457 |
|
23458 |
|
23459 |
|
23460 |
|
23461 | var reinitPlugin = function reinitPlugin(newOptions) {
|
23462 | cleanupEvents();
|
23463 | initPlugin(player, newOptions);
|
23464 | };
|
23465 |
|
23466 | player.on('error', errorHandler);
|
23467 | player.on('dispose', cleanupEvents);
|
23468 |
|
23469 |
|
23470 | player.reloadSourceOnError = reinitPlugin;
|
23471 | };
|
23472 |
|
23473 |
|
23474 |
|
23475 |
|
23476 |
|
23477 |
|
23478 |
|
23479 |
|
23480 | var reloadSourceOnError = function reloadSourceOnError(options) {
|
23481 | initPlugin(this, options);
|
23482 | };
|
23483 |
|
23484 | var version$4 = "2.7.0";
|
23485 |
|
23486 | var version$3 = "5.11.0";
|
23487 |
|
23488 | var version$2 = "0.16.0";
|
23489 |
|
23490 | var version$1 = "4.6.0";
|
23491 |
|
23492 | var version = "3.1.2";
|
23493 |
|
23494 | var Vhs = {
|
23495 | PlaylistLoader: PlaylistLoader,
|
23496 | Playlist: Playlist,
|
23497 | utils: utils,
|
23498 | STANDARD_PLAYLIST_SELECTOR: lastBandwidthSelector,
|
23499 | INITIAL_PLAYLIST_SELECTOR: lowestBitrateCompatibleVariantSelector,
|
23500 | lastBandwidthSelector: lastBandwidthSelector,
|
23501 | movingAverageBandwidthSelector: movingAverageBandwidthSelector,
|
23502 | comparePlaylistBandwidth: comparePlaylistBandwidth,
|
23503 | comparePlaylistResolution: comparePlaylistResolution,
|
23504 | xhr: xhrFactory()
|
23505 | };
|
23506 |
|
23507 | Object.keys(Config).forEach(function (prop) {
|
23508 | Object.defineProperty(Vhs, prop, {
|
23509 | get: function get() {
|
23510 | videojs__default['default'].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
23511 | return Config[prop];
|
23512 | },
|
23513 | set: function set(value) {
|
23514 | videojs__default['default'].log.warn("using Vhs." + prop + " is UNSAFE be sure you know what you are doing");
|
23515 |
|
23516 | if (typeof value !== 'number' || value < 0) {
|
23517 | videojs__default['default'].log.warn("value of Vhs." + prop + " must be greater than or equal to 0");
|
23518 | return;
|
23519 | }
|
23520 |
|
23521 | Config[prop] = value;
|
23522 | }
|
23523 | });
|
23524 | });
|
23525 | var LOCAL_STORAGE_KEY = 'videojs-vhs';
|
23526 |
|
23527 |
|
23528 |
|
23529 |
|
23530 |
|
23531 |
|
23532 |
|
23533 |
|
23534 | var handleVhsMediaChange = function handleVhsMediaChange(qualityLevels, playlistLoader) {
|
23535 | var newPlaylist = playlistLoader.media();
|
23536 | var selectedIndex = -1;
|
23537 |
|
23538 | for (var i = 0; i < qualityLevels.length; i++) {
|
23539 | if (qualityLevels[i].id === newPlaylist.id) {
|
23540 | selectedIndex = i;
|
23541 | break;
|
23542 | }
|
23543 | }
|
23544 |
|
23545 | qualityLevels.selectedIndex_ = selectedIndex;
|
23546 | qualityLevels.trigger({
|
23547 | selectedIndex: selectedIndex,
|
23548 | type: 'change'
|
23549 | });
|
23550 | };
|
23551 |
|
23552 |
|
23553 |
|
23554 |
|
23555 |
|
23556 |
|
23557 |
|
23558 |
|
23559 |
|
23560 | var handleVhsLoadedMetadata = function handleVhsLoadedMetadata(qualityLevels, vhs) {
|
23561 | vhs.representations().forEach(function (rep) {
|
23562 | qualityLevels.addQualityLevel(rep);
|
23563 | });
|
23564 | handleVhsMediaChange(qualityLevels, vhs.playlists);
|
23565 | };
|
23566 |
|
23567 |
|
23568 |
|
23569 | Vhs.canPlaySource = function () {
|
23570 | return videojs__default['default'].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
23571 | };
|
23572 |
|
23573 | var emeKeySystems = function emeKeySystems(keySystemOptions, mainPlaylist, audioPlaylist) {
|
23574 | if (!keySystemOptions) {
|
23575 | return keySystemOptions;
|
23576 | }
|
23577 |
|
23578 | var codecs = {};
|
23579 |
|
23580 | if (mainPlaylist && mainPlaylist.attributes && mainPlaylist.attributes.CODECS) {
|
23581 | codecs = unwrapCodecList(codecs_js.parseCodecs(mainPlaylist.attributes.CODECS));
|
23582 | }
|
23583 |
|
23584 | if (audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS) {
|
23585 | codecs.audio = audioPlaylist.attributes.CODECS;
|
23586 | }
|
23587 |
|
23588 | var videoContentType = codecs_js.getMimeForCodec(codecs.video);
|
23589 | var audioContentType = codecs_js.getMimeForCodec(codecs.audio);
|
23590 |
|
23591 | var keySystemContentTypes = {};
|
23592 |
|
23593 | for (var keySystem in keySystemOptions) {
|
23594 | keySystemContentTypes[keySystem] = {};
|
23595 |
|
23596 | if (audioContentType) {
|
23597 | keySystemContentTypes[keySystem].audioContentType = audioContentType;
|
23598 | }
|
23599 |
|
23600 | if (videoContentType) {
|
23601 | keySystemContentTypes[keySystem].videoContentType = videoContentType;
|
23602 | }
|
23603 |
|
23604 |
|
23605 |
|
23606 |
|
23607 |
|
23608 |
|
23609 |
|
23610 | if (mainPlaylist.contentProtection && mainPlaylist.contentProtection[keySystem] && mainPlaylist.contentProtection[keySystem].pssh) {
|
23611 | keySystemContentTypes[keySystem].pssh = mainPlaylist.contentProtection[keySystem].pssh;
|
23612 | }
|
23613 |
|
23614 |
|
23615 |
|
23616 | if (typeof keySystemOptions[keySystem] === 'string') {
|
23617 | keySystemContentTypes[keySystem].url = keySystemOptions[keySystem];
|
23618 | }
|
23619 | }
|
23620 |
|
23621 | return videojs__default['default'].mergeOptions(keySystemOptions, keySystemContentTypes);
|
23622 | };
|
23623 |
|
23624 |
|
23625 |
|
23626 |
|
23627 |
|
23628 |
|
23629 |
|
23630 |
|
23631 |
|
23632 |
|
23633 |
|
23634 |
|
23635 |
|
23636 |
|
23637 |
|
23638 |
|
23639 |
|
23640 |
|
23641 |
|
23642 |
|
23643 |
|
23644 |
|
23645 |
|
23646 |
|
23647 |
|
23648 | var getAllPsshKeySystemsOptions = function getAllPsshKeySystemsOptions(playlists, keySystems) {
|
23649 | return playlists.reduce(function (keySystemsArr, playlist) {
|
23650 | if (!playlist.contentProtection) {
|
23651 | return keySystemsArr;
|
23652 | }
|
23653 |
|
23654 | var keySystemsOptions = keySystems.reduce(function (keySystemsObj, keySystem) {
|
23655 | var keySystemOptions = playlist.contentProtection[keySystem];
|
23656 |
|
23657 | if (keySystemOptions && keySystemOptions.pssh) {
|
23658 | keySystemsObj[keySystem] = {
|
23659 | pssh: keySystemOptions.pssh
|
23660 | };
|
23661 | }
|
23662 |
|
23663 | return keySystemsObj;
|
23664 | }, {});
|
23665 |
|
23666 | if (Object.keys(keySystemsOptions).length) {
|
23667 | keySystemsArr.push(keySystemsOptions);
|
23668 | }
|
23669 |
|
23670 | return keySystemsArr;
|
23671 | }, []);
|
23672 | };
|
23673 |
|
23674 |
|
23675 |
|
23676 |
|
23677 |
|
23678 |
|
23679 |
|
23680 |
|
23681 |
|
23682 |
|
23683 |
|
23684 |
|
23685 |
|
23686 |
|
23687 |
|
23688 |
|
23689 |
|
23690 |
|
23691 |
|
23692 |
|
23693 |
|
23694 |
|
23695 |
|
23696 |
|
23697 |
|
23698 |
|
23699 | var waitForKeySessionCreation = function waitForKeySessionCreation(_ref) {
|
23700 | var player = _ref.player,
|
23701 | sourceKeySystems = _ref.sourceKeySystems,
|
23702 | audioMedia = _ref.audioMedia,
|
23703 | mainPlaylists = _ref.mainPlaylists;
|
23704 |
|
23705 | if (!player.eme.initializeMediaKeys) {
|
23706 | return Promise.resolve();
|
23707 | }
|
23708 |
|
23709 |
|
23710 |
|
23711 |
|
23712 |
|
23713 |
|
23714 |
|
23715 |
|
23716 |
|
23717 | var playlists = audioMedia ? mainPlaylists.concat([audioMedia]) : mainPlaylists;
|
23718 | var keySystemsOptionsArr = getAllPsshKeySystemsOptions(playlists, Object.keys(sourceKeySystems));
|
23719 | var initializationFinishedPromises = [];
|
23720 | var keySessionCreatedPromises = [];
|
23721 |
|
23722 |
|
23723 |
|
23724 |
|
23725 |
|
23726 | keySystemsOptionsArr.forEach(function (keySystemsOptions) {
|
23727 | keySessionCreatedPromises.push(new Promise(function (resolve, reject) {
|
23728 | player.tech_.one('keysessioncreated', resolve);
|
23729 | }));
|
23730 | initializationFinishedPromises.push(new Promise(function (resolve, reject) {
|
23731 | player.eme.initializeMediaKeys({
|
23732 | keySystems: keySystemsOptions
|
23733 | }, function (err) {
|
23734 | if (err) {
|
23735 | reject(err);
|
23736 | return;
|
23737 | }
|
23738 |
|
23739 | resolve();
|
23740 | });
|
23741 | }));
|
23742 | });
|
23743 |
|
23744 |
|
23745 |
|
23746 |
|
23747 |
|
23748 |
|
23749 | return Promise.race([
|
23750 |
|
23751 |
|
23752 | Promise.all(initializationFinishedPromises),
|
23753 | Promise.race(keySessionCreatedPromises)]);
|
23754 | };
|
23755 |
|
23756 |
|
23757 |
|
23758 |
|
23759 |
|
23760 |
|
23761 |
|
23762 |
|
23763 |
|
23764 |
|
23765 |
|
23766 |
|
23767 |
|
23768 |
|
23769 |
|
23770 |
|
23771 |
|
23772 |
|
23773 | var setupEmeOptions = function setupEmeOptions(_ref2) {
|
23774 | var player = _ref2.player,
|
23775 | sourceKeySystems = _ref2.sourceKeySystems,
|
23776 | media = _ref2.media,
|
23777 | audioMedia = _ref2.audioMedia;
|
23778 | var sourceOptions = emeKeySystems(sourceKeySystems, media, audioMedia);
|
23779 |
|
23780 | if (!sourceOptions) {
|
23781 | return false;
|
23782 | }
|
23783 |
|
23784 | player.currentSource().keySystems = sourceOptions;
|
23785 |
|
23786 |
|
23787 | if (sourceOptions && !player.eme) {
|
23788 | videojs__default['default'].log.warn('DRM encrypted source cannot be decrypted without a DRM plugin');
|
23789 | return false;
|
23790 | }
|
23791 |
|
23792 | return true;
|
23793 | };
|
23794 |
|
23795 | var getVhsLocalStorage = function getVhsLocalStorage() {
|
23796 | if (!window__default['default'].localStorage) {
|
23797 | return null;
|
23798 | }
|
23799 |
|
23800 | var storedObject = window__default['default'].localStorage.getItem(LOCAL_STORAGE_KEY);
|
23801 |
|
23802 | if (!storedObject) {
|
23803 | return null;
|
23804 | }
|
23805 |
|
23806 | try {
|
23807 | return JSON.parse(storedObject);
|
23808 | } catch (e) {
|
23809 |
|
23810 | return null;
|
23811 | }
|
23812 | };
|
23813 |
|
23814 | var updateVhsLocalStorage = function updateVhsLocalStorage(options) {
|
23815 | if (!window__default['default'].localStorage) {
|
23816 | return false;
|
23817 | }
|
23818 |
|
23819 | var objectToStore = getVhsLocalStorage();
|
23820 | objectToStore = objectToStore ? videojs__default['default'].mergeOptions(objectToStore, options) : options;
|
23821 |
|
23822 | try {
|
23823 | window__default['default'].localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(objectToStore));
|
23824 | } catch (e) {
|
23825 |
|
23826 |
|
23827 |
|
23828 |
|
23829 | return false;
|
23830 | }
|
23831 |
|
23832 | return objectToStore;
|
23833 | };
|
23834 |
|
23835 |
|
23836 |
|
23837 |
|
23838 |
|
23839 |
|
23840 |
|
23841 |
|
23842 |
|
23843 |
|
23844 |
|
23845 |
|
23846 |
|
23847 |
|
23848 | var expandDataUri = function expandDataUri(dataUri) {
|
23849 | if (dataUri.toLowerCase().indexOf('data:application/vnd.videojs.vhs+json,') === 0) {
|
23850 | return JSON.parse(dataUri.substring(dataUri.indexOf(',') + 1));
|
23851 | }
|
23852 |
|
23853 |
|
23854 | return dataUri;
|
23855 | };
|
23856 |
|
23857 |
|
23858 |
|
23859 |
|
23860 |
|
23861 | Vhs.supportsNativeHls = function () {
|
23862 | if (!document__default['default'] || !document__default['default'].createElement) {
|
23863 | return false;
|
23864 | }
|
23865 |
|
23866 | var video = document__default['default'].createElement('video');
|
23867 |
|
23868 | if (!videojs__default['default'].getTech('Html5').isSupported()) {
|
23869 | return false;
|
23870 | }
|
23871 |
|
23872 |
|
23873 | var canPlay = [
|
23874 | 'application/vnd.apple.mpegurl',
|
23875 | 'audio/mpegurl',
|
23876 | 'audio/x-mpegurl',
|
23877 | 'application/x-mpegurl',
|
23878 | 'video/x-mpegurl', 'video/mpegurl', 'application/mpegurl'];
|
23879 | return canPlay.some(function (canItPlay) {
|
23880 | return /maybe|probably/i.test(video.canPlayType(canItPlay));
|
23881 | });
|
23882 | }();
|
23883 |
|
23884 | Vhs.supportsNativeDash = function () {
|
23885 | if (!document__default['default'] || !document__default['default'].createElement || !videojs__default['default'].getTech('Html5').isSupported()) {
|
23886 | return false;
|
23887 | }
|
23888 |
|
23889 | return /maybe|probably/i.test(document__default['default'].createElement('video').canPlayType('application/dash+xml'));
|
23890 | }();
|
23891 |
|
23892 | Vhs.supportsTypeNatively = function (type) {
|
23893 | if (type === 'hls') {
|
23894 | return Vhs.supportsNativeHls;
|
23895 | }
|
23896 |
|
23897 | if (type === 'dash') {
|
23898 | return Vhs.supportsNativeDash;
|
23899 | }
|
23900 |
|
23901 | return false;
|
23902 | };
|
23903 |
|
23904 |
|
23905 |
|
23906 |
|
23907 |
|
23908 |
|
23909 | Vhs.isSupported = function () {
|
23910 | return videojs__default['default'].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
23911 | };
|
23912 |
|
23913 | var Component = videojs__default['default'].getComponent('Component');
|
23914 |
|
23915 |
|
23916 |
|
23917 |
|
23918 |
|
23919 |
|
23920 |
|
23921 |
|
23922 |
|
23923 |
|
23924 |
|
23925 | var VhsHandler = function (_Component) {
|
23926 | _inheritsLoose__default['default'](VhsHandler, _Component);
|
23927 |
|
23928 | function VhsHandler(source, tech, options) {
|
23929 | var _this;
|
23930 |
|
23931 | _this = _Component.call(this, tech, videojs__default['default'].mergeOptions(options.hls, options.vhs)) || this;
|
23932 |
|
23933 | if (options.hls && Object.keys(options.hls).length) {
|
23934 | videojs__default['default'].log.warn('Using hls options is deprecated. Use vhs instead.');
|
23935 | }
|
23936 |
|
23937 | _this.logger_ = logger('VhsHandler');
|
23938 |
|
23939 |
|
23940 | if (tech.options_ && tech.options_.playerId) {
|
23941 | var _player = videojs__default['default'](tech.options_.playerId);
|
23942 |
|
23943 | if (!_player.hasOwnProperty('hls')) {
|
23944 | Object.defineProperty(_player, 'hls', {
|
23945 | get: function get() {
|
23946 | videojs__default['default'].log.warn('player.hls is deprecated. Use player.tech().vhs instead.');
|
23947 | tech.trigger({
|
23948 | type: 'usage',
|
23949 | name: 'hls-player-access'
|
23950 | });
|
23951 | return _assertThisInitialized__default['default'](_this);
|
23952 | },
|
23953 | configurable: true
|
23954 | });
|
23955 | }
|
23956 |
|
23957 | if (!_player.hasOwnProperty('vhs')) {
|
23958 | Object.defineProperty(_player, 'vhs', {
|
23959 | get: function get() {
|
23960 | videojs__default['default'].log.warn('player.vhs is deprecated. Use player.tech().vhs instead.');
|
23961 | tech.trigger({
|
23962 | type: 'usage',
|
23963 | name: 'vhs-player-access'
|
23964 | });
|
23965 | return _assertThisInitialized__default['default'](_this);
|
23966 | },
|
23967 | configurable: true
|
23968 | });
|
23969 | }
|
23970 |
|
23971 | if (!_player.hasOwnProperty('dash')) {
|
23972 | Object.defineProperty(_player, 'dash', {
|
23973 | get: function get() {
|
23974 | videojs__default['default'].log.warn('player.dash is deprecated. Use player.tech().vhs instead.');
|
23975 | return _assertThisInitialized__default['default'](_this);
|
23976 | },
|
23977 | configurable: true
|
23978 | });
|
23979 | }
|
23980 |
|
23981 | _this.player_ = _player;
|
23982 | }
|
23983 |
|
23984 | _this.tech_ = tech;
|
23985 | _this.source_ = source;
|
23986 | _this.stats = {};
|
23987 | _this.ignoreNextSeekingEvent_ = false;
|
23988 |
|
23989 | _this.setOptions_();
|
23990 |
|
23991 | if (_this.options_.overrideNative && tech.overrideNativeAudioTracks && tech.overrideNativeVideoTracks) {
|
23992 | tech.overrideNativeAudioTracks(true);
|
23993 | tech.overrideNativeVideoTracks(true);
|
23994 | } else if (_this.options_.overrideNative && (tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
|
23995 |
|
23996 |
|
23997 | throw new Error('Overriding native HLS requires emulated tracks. ' + 'See https://git.io/vMpjB');
|
23998 | }
|
23999 |
|
24000 |
|
24001 |
|
24002 | _this.on(document__default['default'], ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'], function (event) {
|
24003 | var fullscreenElement = document__default['default'].fullscreenElement || document__default['default'].webkitFullscreenElement || document__default['default'].mozFullScreenElement || document__default['default'].msFullscreenElement;
|
24004 |
|
24005 | if (fullscreenElement && fullscreenElement.contains(_this.tech_.el())) {
|
24006 | _this.masterPlaylistController_.smoothQualityChange_();
|
24007 | }
|
24008 | });
|
24009 |
|
24010 | _this.on(_this.tech_, 'seeking', function () {
|
24011 | if (this.ignoreNextSeekingEvent_) {
|
24012 | this.ignoreNextSeekingEvent_ = false;
|
24013 | return;
|
24014 | }
|
24015 |
|
24016 | this.setCurrentTime(this.tech_.currentTime());
|
24017 | });
|
24018 |
|
24019 | _this.on(_this.tech_, 'error', function () {
|
24020 |
|
24021 |
|
24022 | if (this.tech_.error() && this.masterPlaylistController_) {
|
24023 | this.masterPlaylistController_.pauseLoading();
|
24024 | }
|
24025 | });
|
24026 |
|
24027 | _this.on(_this.tech_, 'play', _this.play);
|
24028 |
|
24029 | return _this;
|
24030 | }
|
24031 |
|
24032 | var _proto = VhsHandler.prototype;
|
24033 |
|
24034 | _proto.setOptions_ = function setOptions_() {
|
24035 | var _this2 = this;
|
24036 |
|
24037 |
|
24038 | this.options_.withCredentials = this.options_.withCredentials || false;
|
24039 | this.options_.handleManifestRedirects = this.options_.handleManifestRedirects === false ? false : true;
|
24040 | this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
|
24041 | this.options_.useDevicePixelRatio = this.options_.useDevicePixelRatio || false;
|
24042 | this.options_.smoothQualityChange = this.options_.smoothQualityChange || false;
|
24043 | this.options_.useBandwidthFromLocalStorage = typeof this.source_.useBandwidthFromLocalStorage !== 'undefined' ? this.source_.useBandwidthFromLocalStorage : this.options_.useBandwidthFromLocalStorage || false;
|
24044 | this.options_.customTagParsers = this.options_.customTagParsers || [];
|
24045 | this.options_.customTagMappers = this.options_.customTagMappers || [];
|
24046 | this.options_.cacheEncryptionKeys = this.options_.cacheEncryptionKeys || false;
|
24047 | this.options_.handlePartialData = this.options_.handlePartialData || false;
|
24048 |
|
24049 | if (typeof this.options_.blacklistDuration !== 'number') {
|
24050 | this.options_.blacklistDuration = 5 * 60;
|
24051 | }
|
24052 |
|
24053 | if (typeof this.options_.bandwidth !== 'number') {
|
24054 | if (this.options_.useBandwidthFromLocalStorage) {
|
24055 | var storedObject = getVhsLocalStorage();
|
24056 |
|
24057 | if (storedObject && storedObject.bandwidth) {
|
24058 | this.options_.bandwidth = storedObject.bandwidth;
|
24059 | this.tech_.trigger({
|
24060 | type: 'usage',
|
24061 | name: 'vhs-bandwidth-from-local-storage'
|
24062 | });
|
24063 | this.tech_.trigger({
|
24064 | type: 'usage',
|
24065 | name: 'hls-bandwidth-from-local-storage'
|
24066 | });
|
24067 | }
|
24068 |
|
24069 | if (storedObject && storedObject.throughput) {
|
24070 | this.options_.throughput = storedObject.throughput;
|
24071 | this.tech_.trigger({
|
24072 | type: 'usage',
|
24073 | name: 'vhs-throughput-from-local-storage'
|
24074 | });
|
24075 | this.tech_.trigger({
|
24076 | type: 'usage',
|
24077 | name: 'hls-throughput-from-local-storage'
|
24078 | });
|
24079 | }
|
24080 | }
|
24081 | }
|
24082 |
|
24083 |
|
24084 |
|
24085 | if (typeof this.options_.bandwidth !== 'number') {
|
24086 | this.options_.bandwidth = Config.INITIAL_BANDWIDTH;
|
24087 | }
|
24088 |
|
24089 |
|
24090 |
|
24091 | this.options_.enableLowInitialPlaylist = this.options_.enableLowInitialPlaylist && this.options_.bandwidth === Config.INITIAL_BANDWIDTH;
|
24092 |
|
24093 | ['withCredentials', 'useDevicePixelRatio', 'limitRenditionByPlayerDimensions', 'bandwidth', 'smoothQualityChange', 'customTagParsers', 'customTagMappers', 'handleManifestRedirects', 'cacheEncryptionKeys', 'handlePartialData', 'playlistSelector', 'initialPlaylistSelector', 'experimentalBufferBasedABR', 'liveRangeSafeTimeDelta', 'experimentalLLHLS'].forEach(function (option) {
|
24094 | if (typeof _this2.source_[option] !== 'undefined') {
|
24095 | _this2.options_[option] = _this2.source_[option];
|
24096 | }
|
24097 | });
|
24098 | this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
|
24099 | this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
|
24100 | }
|
24101 | |
24102 |
|
24103 |
|
24104 |
|
24105 |
|
24106 | ;
|
24107 |
|
24108 | _proto.src = function src(_src, type) {
|
24109 | var _this3 = this;
|
24110 |
|
24111 |
|
24112 | if (!_src) {
|
24113 | return;
|
24114 | }
|
24115 |
|
24116 | this.setOptions_();
|
24117 |
|
24118 | this.options_.src = expandDataUri(this.source_.src);
|
24119 | this.options_.tech = this.tech_;
|
24120 | this.options_.externVhs = Vhs;
|
24121 | this.options_.sourceType = mediaTypes_js.simpleTypeFromSourceType(type);
|
24122 |
|
24123 | this.options_.seekTo = function (time) {
|
24124 | _this3.tech_.setCurrentTime(time);
|
24125 | };
|
24126 |
|
24127 | this.masterPlaylistController_ = new MasterPlaylistController(this.options_);
|
24128 | var playbackWatcherOptions = videojs__default['default'].mergeOptions({
|
24129 | liveRangeSafeTimeDelta: SAFE_TIME_DELTA
|
24130 | }, this.options_, {
|
24131 | seekable: function seekable() {
|
24132 | return _this3.seekable();
|
24133 | },
|
24134 | media: function media() {
|
24135 | return _this3.masterPlaylistController_.media();
|
24136 | },
|
24137 | masterPlaylistController: this.masterPlaylistController_
|
24138 | });
|
24139 | this.playbackWatcher_ = new PlaybackWatcher(playbackWatcherOptions);
|
24140 | this.masterPlaylistController_.on('error', function () {
|
24141 | var player = videojs__default['default'].players[_this3.tech_.options_.playerId];
|
24142 | var error = _this3.masterPlaylistController_.error;
|
24143 |
|
24144 | if (typeof error === 'object' && !error.code) {
|
24145 | error.code = 3;
|
24146 | } else if (typeof error === 'string') {
|
24147 | error = {
|
24148 | message: error,
|
24149 | code: 3
|
24150 | };
|
24151 | }
|
24152 |
|
24153 | player.error(error);
|
24154 | });
|
24155 | var defaultSelector = this.options_.experimentalBufferBasedABR ? Vhs.movingAverageBandwidthSelector(0.55) : Vhs.STANDARD_PLAYLIST_SELECTOR;
|
24156 |
|
24157 |
|
24158 | this.masterPlaylistController_.selectPlaylist = this.selectPlaylist ? this.selectPlaylist.bind(this) : defaultSelector.bind(this);
|
24159 | this.masterPlaylistController_.selectInitialPlaylist = Vhs.INITIAL_PLAYLIST_SELECTOR.bind(this);
|
24160 |
|
24161 | this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
|
24162 | this.mediaSource = this.masterPlaylistController_.mediaSource;
|
24163 |
|
24164 |
|
24165 |
|
24166 | Object.defineProperties(this, {
|
24167 | selectPlaylist: {
|
24168 | get: function get() {
|
24169 | return this.masterPlaylistController_.selectPlaylist;
|
24170 | },
|
24171 | set: function set(selectPlaylist) {
|
24172 | this.masterPlaylistController_.selectPlaylist = selectPlaylist.bind(this);
|
24173 | }
|
24174 | },
|
24175 | throughput: {
|
24176 | get: function get() {
|
24177 | return this.masterPlaylistController_.mainSegmentLoader_.throughput.rate;
|
24178 | },
|
24179 | set: function set(throughput) {
|
24180 | this.masterPlaylistController_.mainSegmentLoader_.throughput.rate = throughput;
|
24181 |
|
24182 |
|
24183 | this.masterPlaylistController_.mainSegmentLoader_.throughput.count = 1;
|
24184 | }
|
24185 | },
|
24186 | bandwidth: {
|
24187 | get: function get() {
|
24188 | return this.masterPlaylistController_.mainSegmentLoader_.bandwidth;
|
24189 | },
|
24190 | set: function set(bandwidth) {
|
24191 | this.masterPlaylistController_.mainSegmentLoader_.bandwidth = bandwidth;
|
24192 |
|
24193 |
|
24194 |
|
24195 | this.masterPlaylistController_.mainSegmentLoader_.throughput = {
|
24196 | rate: 0,
|
24197 | count: 0
|
24198 | };
|
24199 | }
|
24200 | },
|
24201 |
|
24202 | |
24203 |
|
24204 |
|
24205 |
|
24206 |
|
24207 |
|
24208 |
|
24209 |
|
24210 |
|
24211 | systemBandwidth: {
|
24212 | get: function get() {
|
24213 | var invBandwidth = 1 / (this.bandwidth || 1);
|
24214 | var invThroughput;
|
24215 |
|
24216 | if (this.throughput > 0) {
|
24217 | invThroughput = 1 / this.throughput;
|
24218 | } else {
|
24219 | invThroughput = 0;
|
24220 | }
|
24221 |
|
24222 | var systemBitrate = Math.floor(1 / (invBandwidth + invThroughput));
|
24223 | return systemBitrate;
|
24224 | },
|
24225 | set: function set() {
|
24226 | videojs__default['default'].log.error('The "systemBandwidth" property is read-only');
|
24227 | }
|
24228 | }
|
24229 | });
|
24230 |
|
24231 | if (this.options_.bandwidth) {
|
24232 | this.bandwidth = this.options_.bandwidth;
|
24233 | }
|
24234 |
|
24235 | if (this.options_.throughput) {
|
24236 | this.throughput = this.options_.throughput;
|
24237 | }
|
24238 |
|
24239 | Object.defineProperties(this.stats, {
|
24240 | bandwidth: {
|
24241 | get: function get() {
|
24242 | return _this3.bandwidth || 0;
|
24243 | },
|
24244 | enumerable: true
|
24245 | },
|
24246 | mediaRequests: {
|
24247 | get: function get() {
|
24248 | return _this3.masterPlaylistController_.mediaRequests_() || 0;
|
24249 | },
|
24250 | enumerable: true
|
24251 | },
|
24252 | mediaRequestsAborted: {
|
24253 | get: function get() {
|
24254 | return _this3.masterPlaylistController_.mediaRequestsAborted_() || 0;
|
24255 | },
|
24256 | enumerable: true
|
24257 | },
|
24258 | mediaRequestsTimedout: {
|
24259 | get: function get() {
|
24260 | return _this3.masterPlaylistController_.mediaRequestsTimedout_() || 0;
|
24261 | },
|
24262 | enumerable: true
|
24263 | },
|
24264 | mediaRequestsErrored: {
|
24265 | get: function get() {
|
24266 | return _this3.masterPlaylistController_.mediaRequestsErrored_() || 0;
|
24267 | },
|
24268 | enumerable: true
|
24269 | },
|
24270 | mediaTransferDuration: {
|
24271 | get: function get() {
|
24272 | return _this3.masterPlaylistController_.mediaTransferDuration_() || 0;
|
24273 | },
|
24274 | enumerable: true
|
24275 | },
|
24276 | mediaBytesTransferred: {
|
24277 | get: function get() {
|
24278 | return _this3.masterPlaylistController_.mediaBytesTransferred_() || 0;
|
24279 | },
|
24280 | enumerable: true
|
24281 | },
|
24282 | mediaSecondsLoaded: {
|
24283 | get: function get() {
|
24284 | return _this3.masterPlaylistController_.mediaSecondsLoaded_() || 0;
|
24285 | },
|
24286 | enumerable: true
|
24287 | },
|
24288 | buffered: {
|
24289 | get: function get() {
|
24290 | return timeRangesToArray(_this3.tech_.buffered());
|
24291 | },
|
24292 | enumerable: true
|
24293 | },
|
24294 | currentTime: {
|
24295 | get: function get() {
|
24296 | return _this3.tech_.currentTime();
|
24297 | },
|
24298 | enumerable: true
|
24299 | },
|
24300 | currentSource: {
|
24301 | get: function get() {
|
24302 | return _this3.tech_.currentSource_;
|
24303 | },
|
24304 | enumerable: true
|
24305 | },
|
24306 | currentTech: {
|
24307 | get: function get() {
|
24308 | return _this3.tech_.name_;
|
24309 | },
|
24310 | enumerable: true
|
24311 | },
|
24312 | duration: {
|
24313 | get: function get() {
|
24314 | return _this3.tech_.duration();
|
24315 | },
|
24316 | enumerable: true
|
24317 | },
|
24318 | master: {
|
24319 | get: function get() {
|
24320 | return _this3.playlists.master;
|
24321 | },
|
24322 | enumerable: true
|
24323 | },
|
24324 | playerDimensions: {
|
24325 | get: function get() {
|
24326 | return _this3.tech_.currentDimensions();
|
24327 | },
|
24328 | enumerable: true
|
24329 | },
|
24330 | seekable: {
|
24331 | get: function get() {
|
24332 | return timeRangesToArray(_this3.tech_.seekable());
|
24333 | },
|
24334 | enumerable: true
|
24335 | },
|
24336 | timestamp: {
|
24337 | get: function get() {
|
24338 | return Date.now();
|
24339 | },
|
24340 | enumerable: true
|
24341 | },
|
24342 | videoPlaybackQuality: {
|
24343 | get: function get() {
|
24344 | return _this3.tech_.getVideoPlaybackQuality();
|
24345 | },
|
24346 | enumerable: true
|
24347 | }
|
24348 | });
|
24349 | this.tech_.one('canplay', this.masterPlaylistController_.setupFirstPlay.bind(this.masterPlaylistController_));
|
24350 | this.tech_.on('bandwidthupdate', function () {
|
24351 | if (_this3.options_.useBandwidthFromLocalStorage) {
|
24352 | updateVhsLocalStorage({
|
24353 | bandwidth: _this3.bandwidth,
|
24354 | throughput: Math.round(_this3.throughput)
|
24355 | });
|
24356 | }
|
24357 | });
|
24358 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
24359 |
|
24360 | renditionSelectionMixin(_this3);
|
24361 | });
|
24362 | this.masterPlaylistController_.sourceUpdater_.on('createdsourcebuffers', function () {
|
24363 | _this3.setupEme_();
|
24364 | });
|
24365 |
|
24366 |
|
24367 | this.on(this.masterPlaylistController_, 'progress', function () {
|
24368 | this.tech_.trigger('progress');
|
24369 | });
|
24370 |
|
24371 |
|
24372 | this.on(this.masterPlaylistController_, 'firstplay', function () {
|
24373 | this.ignoreNextSeekingEvent_ = true;
|
24374 | });
|
24375 | this.setupQualityLevels_();
|
24376 |
|
24377 |
|
24378 | if (!this.tech_.el()) {
|
24379 | return;
|
24380 | }
|
24381 |
|
24382 | this.mediaSourceUrl_ = window__default['default'].URL.createObjectURL(this.masterPlaylistController_.mediaSource);
|
24383 | this.tech_.src(this.mediaSourceUrl_);
|
24384 | }
|
24385 | |
24386 |
|
24387 |
|
24388 |
|
24389 |
|
24390 |
|
24391 |
|
24392 |
|
24393 | ;
|
24394 |
|
24395 | _proto.setupEme_ = function setupEme_() {
|
24396 | var _this4 = this;
|
24397 |
|
24398 | var audioPlaylistLoader = this.masterPlaylistController_.mediaTypes_.AUDIO.activePlaylistLoader;
|
24399 | var didSetupEmeOptions = setupEmeOptions({
|
24400 | player: this.player_,
|
24401 | sourceKeySystems: this.source_.keySystems,
|
24402 | media: this.playlists.media(),
|
24403 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media()
|
24404 | });
|
24405 |
|
24406 |
|
24407 | if (videojs__default['default'].browser.IE_VERSION === 11 || !didSetupEmeOptions) {
|
24408 |
|
24409 | this.masterPlaylistController_.sourceUpdater_.initializedEme();
|
24410 | return;
|
24411 | }
|
24412 |
|
24413 | this.logger_('waiting for EME key session creation');
|
24414 | waitForKeySessionCreation({
|
24415 | player: this.player_,
|
24416 | sourceKeySystems: this.source_.keySystems,
|
24417 | audioMedia: audioPlaylistLoader && audioPlaylistLoader.media(),
|
24418 | mainPlaylists: this.playlists.master.playlists
|
24419 | }).then(function () {
|
24420 | _this4.logger_('created EME key session');
|
24421 |
|
24422 | _this4.masterPlaylistController_.sourceUpdater_.initializedEme();
|
24423 | }).catch(function (err) {
|
24424 | _this4.logger_('error while creating EME key session', err);
|
24425 |
|
24426 | _this4.player_.error({
|
24427 | message: 'Failed to initialize media keys for EME',
|
24428 | code: 3
|
24429 | });
|
24430 | });
|
24431 | }
|
24432 | |
24433 |
|
24434 |
|
24435 |
|
24436 |
|
24437 |
|
24438 | ;
|
24439 |
|
24440 | _proto.setupQualityLevels_ = function setupQualityLevels_() {
|
24441 | var _this5 = this;
|
24442 |
|
24443 | var player = videojs__default['default'].players[this.tech_.options_.playerId];
|
24444 |
|
24445 |
|
24446 | if (!player || !player.qualityLevels || this.qualityLevels_) {
|
24447 | return;
|
24448 | }
|
24449 |
|
24450 | this.qualityLevels_ = player.qualityLevels();
|
24451 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
24452 | handleVhsLoadedMetadata(_this5.qualityLevels_, _this5);
|
24453 | });
|
24454 | this.playlists.on('mediachange', function () {
|
24455 | handleVhsMediaChange(_this5.qualityLevels_, _this5.playlists);
|
24456 | });
|
24457 | }
|
24458 | |
24459 |
|
24460 |
|
24461 | ;
|
24462 |
|
24463 | VhsHandler.version = function version$5() {
|
24464 | return {
|
24465 | '@videojs/http-streaming': version$4,
|
24466 | 'mux.js': version$3,
|
24467 | 'mpd-parser': version$2,
|
24468 | 'm3u8-parser': version$1,
|
24469 | 'aes-decrypter': version
|
24470 | };
|
24471 | }
|
24472 | |
24473 |
|
24474 |
|
24475 | ;
|
24476 |
|
24477 | _proto.version = function version() {
|
24478 | return this.constructor.version();
|
24479 | };
|
24480 |
|
24481 | _proto.canChangeType = function canChangeType() {
|
24482 | return SourceUpdater.canChangeType();
|
24483 | }
|
24484 | |
24485 |
|
24486 |
|
24487 | ;
|
24488 |
|
24489 | _proto.play = function play() {
|
24490 | this.masterPlaylistController_.play();
|
24491 | }
|
24492 | |
24493 |
|
24494 |
|
24495 | ;
|
24496 |
|
24497 | _proto.setCurrentTime = function setCurrentTime(currentTime) {
|
24498 | this.masterPlaylistController_.setCurrentTime(currentTime);
|
24499 | }
|
24500 | |
24501 |
|
24502 |
|
24503 | ;
|
24504 |
|
24505 | _proto.duration = function duration() {
|
24506 | return this.masterPlaylistController_.duration();
|
24507 | }
|
24508 | |
24509 |
|
24510 |
|
24511 | ;
|
24512 |
|
24513 | _proto.seekable = function seekable() {
|
24514 | return this.masterPlaylistController_.seekable();
|
24515 | }
|
24516 | |
24517 |
|
24518 |
|
24519 | ;
|
24520 |
|
24521 | _proto.dispose = function dispose() {
|
24522 | if (this.playbackWatcher_) {
|
24523 | this.playbackWatcher_.dispose();
|
24524 | }
|
24525 |
|
24526 | if (this.masterPlaylistController_) {
|
24527 | this.masterPlaylistController_.dispose();
|
24528 | }
|
24529 |
|
24530 | if (this.qualityLevels_) {
|
24531 | this.qualityLevels_.dispose();
|
24532 | }
|
24533 |
|
24534 | if (this.player_) {
|
24535 | delete this.player_.vhs;
|
24536 | delete this.player_.dash;
|
24537 | delete this.player_.hls;
|
24538 | }
|
24539 |
|
24540 | if (this.tech_ && this.tech_.vhs) {
|
24541 | delete this.tech_.vhs;
|
24542 | }
|
24543 |
|
24544 |
|
24545 | if (this.tech_) {
|
24546 | delete this.tech_.hls;
|
24547 | }
|
24548 |
|
24549 | if (this.mediaSourceUrl_ && window__default['default'].URL.revokeObjectURL) {
|
24550 | window__default['default'].URL.revokeObjectURL(this.mediaSourceUrl_);
|
24551 | this.mediaSourceUrl_ = null;
|
24552 | }
|
24553 |
|
24554 | _Component.prototype.dispose.call(this);
|
24555 | };
|
24556 |
|
24557 | _proto.convertToProgramTime = function convertToProgramTime(time, callback) {
|
24558 | return getProgramTime({
|
24559 | playlist: this.masterPlaylistController_.media(),
|
24560 | time: time,
|
24561 | callback: callback
|
24562 | });
|
24563 | }
|
24564 | ;
|
24565 |
|
24566 | _proto.seekToProgramTime = function seekToProgramTime$1(programTime, callback, pauseAfterSeek, retryCount) {
|
24567 | if (pauseAfterSeek === void 0) {
|
24568 | pauseAfterSeek = true;
|
24569 | }
|
24570 |
|
24571 | if (retryCount === void 0) {
|
24572 | retryCount = 2;
|
24573 | }
|
24574 |
|
24575 | return seekToProgramTime({
|
24576 | programTime: programTime,
|
24577 | playlist: this.masterPlaylistController_.media(),
|
24578 | retryCount: retryCount,
|
24579 | pauseAfterSeek: pauseAfterSeek,
|
24580 | seekTo: this.options_.seekTo,
|
24581 | tech: this.options_.tech,
|
24582 | callback: callback
|
24583 | });
|
24584 | };
|
24585 |
|
24586 | return VhsHandler;
|
24587 | }(Component);
|
24588 |
|
24589 |
|
24590 |
|
24591 |
|
24592 |
|
24593 |
|
24594 |
|
24595 |
|
24596 |
|
24597 | var VhsSourceHandler = {
|
24598 | name: 'videojs-http-streaming',
|
24599 | VERSION: version$4,
|
24600 | canHandleSource: function canHandleSource(srcObj, options) {
|
24601 | if (options === void 0) {
|
24602 | options = {};
|
24603 | }
|
24604 |
|
24605 | var localOptions = videojs__default['default'].mergeOptions(videojs__default['default'].options, options);
|
24606 | return VhsSourceHandler.canPlayType(srcObj.type, localOptions);
|
24607 | },
|
24608 | handleSource: function handleSource(source, tech, options) {
|
24609 | if (options === void 0) {
|
24610 | options = {};
|
24611 | }
|
24612 |
|
24613 | var localOptions = videojs__default['default'].mergeOptions(videojs__default['default'].options, options);
|
24614 | tech.vhs = new VhsHandler(source, tech, localOptions);
|
24615 |
|
24616 | if (!videojs__default['default'].hasOwnProperty('hls')) {
|
24617 | Object.defineProperty(tech, 'hls', {
|
24618 | get: function get() {
|
24619 | videojs__default['default'].log.warn('player.tech().hls is deprecated. Use player.tech().vhs instead.');
|
24620 | return tech.vhs;
|
24621 | },
|
24622 | configurable: true
|
24623 | });
|
24624 | }
|
24625 |
|
24626 | tech.vhs.xhr = xhrFactory();
|
24627 | tech.vhs.src(source.src, source.type);
|
24628 | return tech.vhs;
|
24629 | },
|
24630 | canPlayType: function canPlayType(type, options) {
|
24631 | if (options === void 0) {
|
24632 | options = {};
|
24633 | }
|
24634 |
|
24635 | var _videojs$mergeOptions = videojs__default['default'].mergeOptions(videojs__default['default'].options, options),
|
24636 | _videojs$mergeOptions2 = _videojs$mergeOptions.vhs.overrideNative,
|
24637 | overrideNative = _videojs$mergeOptions2 === void 0 ? !videojs__default['default'].browser.IS_ANY_SAFARI : _videojs$mergeOptions2;
|
24638 |
|
24639 | var supportedType = mediaTypes_js.simpleTypeFromSourceType(type);
|
24640 | var canUseMsePlayback = supportedType && (!Vhs.supportsTypeNatively(supportedType) || overrideNative);
|
24641 | return canUseMsePlayback ? 'maybe' : '';
|
24642 | }
|
24643 | };
|
24644 |
|
24645 |
|
24646 |
|
24647 |
|
24648 |
|
24649 |
|
24650 |
|
24651 | var supportsNativeMediaSources = function supportsNativeMediaSources() {
|
24652 | return codecs_js.browserSupportsCodec('avc1.4d400d,mp4a.40.2');
|
24653 | };
|
24654 |
|
24655 |
|
24656 | if (supportsNativeMediaSources()) {
|
24657 | videojs__default['default'].getTech('Html5').registerSourceHandler(VhsSourceHandler, 0);
|
24658 | }
|
24659 |
|
24660 | videojs__default['default'].VhsHandler = VhsHandler;
|
24661 | Object.defineProperty(videojs__default['default'], 'HlsHandler', {
|
24662 | get: function get() {
|
24663 | videojs__default['default'].log.warn('videojs.HlsHandler is deprecated. Use videojs.VhsHandler instead.');
|
24664 | return VhsHandler;
|
24665 | },
|
24666 | configurable: true
|
24667 | });
|
24668 | videojs__default['default'].VhsSourceHandler = VhsSourceHandler;
|
24669 | Object.defineProperty(videojs__default['default'], 'HlsSourceHandler', {
|
24670 | get: function get() {
|
24671 | videojs__default['default'].log.warn('videojs.HlsSourceHandler is deprecated. ' + 'Use videojs.VhsSourceHandler instead.');
|
24672 | return VhsSourceHandler;
|
24673 | },
|
24674 | configurable: true
|
24675 | });
|
24676 | videojs__default['default'].Vhs = Vhs;
|
24677 | Object.defineProperty(videojs__default['default'], 'Hls', {
|
24678 | get: function get() {
|
24679 | videojs__default['default'].log.warn('videojs.Hls is deprecated. Use videojs.Vhs instead.');
|
24680 | return Vhs;
|
24681 | },
|
24682 | configurable: true
|
24683 | });
|
24684 |
|
24685 | if (!videojs__default['default'].use) {
|
24686 | videojs__default['default'].registerComponent('Hls', Vhs);
|
24687 | videojs__default['default'].registerComponent('Vhs', Vhs);
|
24688 | }
|
24689 |
|
24690 | videojs__default['default'].options.vhs = videojs__default['default'].options.vhs || {};
|
24691 | videojs__default['default'].options.hls = videojs__default['default'].options.hls || {};
|
24692 |
|
24693 | if (videojs__default['default'].registerPlugin) {
|
24694 | videojs__default['default'].registerPlugin('reloadSourceOnError', reloadSourceOnError);
|
24695 | } else {
|
24696 | videojs__default['default'].plugin('reloadSourceOnError', reloadSourceOnError);
|
24697 | }
|
24698 |
|
24699 | Object.defineProperty(exports, 'simpleTypeFromSourceType', {
|
24700 | enumerable: true,
|
24701 | get: function () {
|
24702 | return mediaTypes_js.simpleTypeFromSourceType;
|
24703 | }
|
24704 | });
|
24705 | exports.LOCAL_STORAGE_KEY = LOCAL_STORAGE_KEY;
|
24706 | exports.Vhs = Vhs;
|
24707 | exports.VhsHandler = VhsHandler;
|
24708 | exports.VhsSourceHandler = VhsSourceHandler;
|
24709 | exports.emeKeySystems = emeKeySystems;
|
24710 | exports.expandDataUri = expandDataUri;
|
24711 | exports.getAllPsshKeySystemsOptions = getAllPsshKeySystemsOptions;
|
24712 | exports.setupEmeOptions = setupEmeOptions;
|
24713 | exports.waitForKeySessionCreation = waitForKeySessionCreation;
|