1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.videojsContribHls = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | Object.defineProperty(exports, '__esModule', {
|
14 | value: true
|
15 | });
|
16 |
|
17 | var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
20 |
|
21 | var _globalWindow = require('global/window');
|
22 |
|
23 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | var findAdCue = function findAdCue(track, mediaTime) {
|
29 | var cues = track.cues;
|
30 |
|
31 | for (var i = 0; i < cues.length; i++) {
|
32 | var cue = cues[i];
|
33 |
|
34 | if (mediaTime >= cue.adStartTime && mediaTime <= cue.adEndTime) {
|
35 | return cue;
|
36 | }
|
37 | }
|
38 | return null;
|
39 | };
|
40 |
|
41 | var updateAdCues = function updateAdCues(media, track) {
|
42 | var offset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
|
43 |
|
44 | if (!media.segments) {
|
45 | return;
|
46 | }
|
47 |
|
48 | var mediaTime = offset;
|
49 | var cue = undefined;
|
50 |
|
51 | for (var i = 0; i < media.segments.length; i++) {
|
52 | var segment = media.segments[i];
|
53 |
|
54 | if (!cue) {
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | cue = findAdCue(track, mediaTime + segment.duration / 2);
|
60 | }
|
61 |
|
62 | if (cue) {
|
63 | if ('cueIn' in segment) {
|
64 |
|
65 | cue.endTime = mediaTime;
|
66 | cue.adEndTime = mediaTime;
|
67 | mediaTime += segment.duration;
|
68 | cue = null;
|
69 | continue;
|
70 | }
|
71 |
|
72 | if (mediaTime < cue.endTime) {
|
73 |
|
74 | mediaTime += segment.duration;
|
75 | continue;
|
76 | }
|
77 |
|
78 |
|
79 | cue.endTime += segment.duration;
|
80 | } else {
|
81 | if ('cueOut' in segment) {
|
82 | cue = new _globalWindow2['default'].VTTCue(mediaTime, mediaTime + segment.duration, segment.cueOut);
|
83 | cue.adStartTime = mediaTime;
|
84 |
|
85 |
|
86 | cue.adEndTime = mediaTime + parseFloat(segment.cueOut);
|
87 | track.addCue(cue);
|
88 | }
|
89 |
|
90 | if ('cueOutCont' in segment) {
|
91 |
|
92 | var adOffset = undefined;
|
93 | var adTotal = undefined;
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | var _segment$cueOutCont$split$map = segment.cueOutCont.split('/').map(parseFloat);
|
99 |
|
100 | var _segment$cueOutCont$split$map2 = _slicedToArray(_segment$cueOutCont$split$map, 2);
|
101 |
|
102 | adOffset = _segment$cueOutCont$split$map2[0];
|
103 | adTotal = _segment$cueOutCont$split$map2[1];
|
104 |
|
105 | cue = new _globalWindow2['default'].VTTCue(mediaTime, mediaTime + segment.duration, '');
|
106 | cue.adStartTime = mediaTime - adOffset;
|
107 | cue.adEndTime = cue.adStartTime + adTotal;
|
108 | track.addCue(cue);
|
109 | }
|
110 | }
|
111 | mediaTime += segment.duration;
|
112 | }
|
113 | };
|
114 |
|
115 | exports['default'] = {
|
116 | updateAdCues: updateAdCues,
|
117 | findAdCue: findAdCue
|
118 | };
|
119 | module.exports = exports['default'];
|
120 | },{"global/window":32}],2:[function(require,module,exports){
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | 'use strict';
|
132 |
|
133 | Object.defineProperty(exports, '__esModule', {
|
134 | value: true
|
135 | });
|
136 | var textRange = function textRange(range, i) {
|
137 | return range.start(i) + '-' + range.end(i);
|
138 | };
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | var formatHexString = function formatHexString(e, i) {
|
147 | var value = e.toString(16);
|
148 |
|
149 | return '00'.substring(0, 2 - value.length) + value + (i % 2 ? ' ' : '');
|
150 | };
|
151 | var formatAsciiString = function formatAsciiString(e) {
|
152 | if (e >= 0x20 && e < 0x7e) {
|
153 | return String.fromCharCode(e);
|
154 | }
|
155 | return '.';
|
156 | };
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | var createTransferableMessage = function createTransferableMessage(message) {
|
169 | var transferable = {};
|
170 |
|
171 | Object.keys(message).forEach(function (key) {
|
172 | var value = message[key];
|
173 |
|
174 | if (ArrayBuffer.isView(value)) {
|
175 | transferable[key] = {
|
176 | bytes: value.buffer,
|
177 | byteOffset: value.byteOffset,
|
178 | byteLength: value.byteLength
|
179 | };
|
180 | } else {
|
181 | transferable[key] = value;
|
182 | }
|
183 | });
|
184 |
|
185 | return transferable;
|
186 | };
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | var initSegmentId = function initSegmentId(initSegment) {
|
193 | var byterange = initSegment.byterange || {
|
194 | length: Infinity,
|
195 | offset: 0
|
196 | };
|
197 |
|
198 | return [byterange.length, byterange.offset, initSegment.resolvedUri].join(',');
|
199 | };
|
200 |
|
201 |
|
202 |
|
203 |
|
204 | var utils = {
|
205 | hexDump: function hexDump(data) {
|
206 | var bytes = Array.prototype.slice.call(data);
|
207 | var step = 16;
|
208 | var result = '';
|
209 | var hex = undefined;
|
210 | var ascii = undefined;
|
211 |
|
212 | for (var j = 0; j < bytes.length / step; j++) {
|
213 | hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
|
214 | ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
|
215 | result += hex + ' ' + ascii + '\n';
|
216 | }
|
217 | return result;
|
218 | },
|
219 | tagDump: function tagDump(tag) {
|
220 | return utils.hexDump(tag.bytes);
|
221 | },
|
222 | textRanges: function textRanges(ranges) {
|
223 | var result = '';
|
224 | var i = undefined;
|
225 |
|
226 | for (i = 0; i < ranges.length; i++) {
|
227 | result += textRange(ranges, i) + ' ';
|
228 | }
|
229 | return result;
|
230 | },
|
231 | createTransferableMessage: createTransferableMessage,
|
232 | initSegmentId: initSegmentId
|
233 | };
|
234 |
|
235 | exports['default'] = utils;
|
236 | module.exports = exports['default'];
|
237 | },{}],3:[function(require,module,exports){
|
238 | "use strict";
|
239 |
|
240 | Object.defineProperty(exports, "__esModule", {
|
241 | value: true
|
242 | });
|
243 | exports["default"] = {
|
244 | GOAL_BUFFER_LENGTH: 30,
|
245 | MAX_GOAL_BUFFER_LENGTH: 60,
|
246 | GOAL_BUFFER_LENGTH_RATE: 1,
|
247 |
|
248 |
|
249 | BANDWIDTH_VARIANCE: 1.2,
|
250 |
|
251 | BUFFER_LOW_WATER_LINE: 0,
|
252 | MAX_BUFFER_LOW_WATER_LINE: 30,
|
253 | BUFFER_LOW_WATER_LINE_RATE: 1
|
254 | };
|
255 | module.exports = exports["default"];
|
256 | },{}],4:[function(require,module,exports){
|
257 | 'use strict';
|
258 |
|
259 | Object.defineProperty(exports, '__esModule', {
|
260 | value: true
|
261 | });
|
262 |
|
263 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
264 |
|
265 | var _globalWindow = require('global/window');
|
266 |
|
267 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
268 |
|
269 | var _aesDecrypter = require('aes-decrypter');
|
270 |
|
271 | var _binUtils = require('./bin-utils');
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | var DecrypterWorker = function DecrypterWorker(self) {
|
282 | self.onmessage = function (event) {
|
283 | var data = event.data;
|
284 | var encrypted = new Uint8Array(data.encrypted.bytes, data.encrypted.byteOffset, data.encrypted.byteLength);
|
285 | var key = new Uint32Array(data.key.bytes, data.key.byteOffset, data.key.byteLength / 4);
|
286 | var iv = new Uint32Array(data.iv.bytes, data.iv.byteOffset, data.iv.byteLength / 4);
|
287 |
|
288 |
|
289 | new _aesDecrypter.Decrypter(encrypted, key, iv, function (err, bytes) {
|
290 | _globalWindow2['default'].postMessage((0, _binUtils.createTransferableMessage)({
|
291 | source: data.source,
|
292 | decrypted: bytes
|
293 | }), [bytes.buffer]);
|
294 | });
|
295 |
|
296 | };
|
297 | };
|
298 |
|
299 | exports['default'] = function (self) {
|
300 | return new DecrypterWorker(self);
|
301 | };
|
302 |
|
303 | module.exports = exports['default'];
|
304 | },{"./bin-utils":2,"aes-decrypter":25,"global/window":32}],5:[function(require,module,exports){
|
305 | (function (global){
|
306 |
|
307 |
|
308 |
|
309 | 'use strict';
|
310 |
|
311 | Object.defineProperty(exports, '__esModule', {
|
312 | value: true
|
313 | });
|
314 |
|
315 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
316 |
|
317 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
318 |
|
319 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
320 |
|
321 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
322 |
|
323 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
324 |
|
325 | var _playlistLoader = require('./playlist-loader');
|
326 |
|
327 | var _playlistLoader2 = _interopRequireDefault(_playlistLoader);
|
328 |
|
329 | var _segmentLoader = require('./segment-loader');
|
330 |
|
331 | var _segmentLoader2 = _interopRequireDefault(_segmentLoader);
|
332 |
|
333 | var _vttSegmentLoader = require('./vtt-segment-loader');
|
334 |
|
335 | var _vttSegmentLoader2 = _interopRequireDefault(_vttSegmentLoader);
|
336 |
|
337 | var _ranges = require('./ranges');
|
338 |
|
339 | var _ranges2 = _interopRequireDefault(_ranges);
|
340 |
|
341 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
342 |
|
343 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
344 |
|
345 | var _adCueTags = require('./ad-cue-tags');
|
346 |
|
347 | var _adCueTags2 = _interopRequireDefault(_adCueTags);
|
348 |
|
349 | var _syncController = require('./sync-controller');
|
350 |
|
351 | var _syncController2 = _interopRequireDefault(_syncController);
|
352 |
|
353 | var _videojsContribMediaSourcesEs5CodecUtils = require('videojs-contrib-media-sources/es5/codec-utils');
|
354 |
|
355 | var _webworkify = require('webworkify');
|
356 |
|
357 | var _webworkify2 = _interopRequireDefault(_webworkify);
|
358 |
|
359 | var _decrypterWorker = require('./decrypter-worker');
|
360 |
|
361 | var _decrypterWorker2 = _interopRequireDefault(_decrypterWorker);
|
362 |
|
363 | var _config = require('./config');
|
364 |
|
365 | var _config2 = _interopRequireDefault(_config);
|
366 |
|
367 | var _utilCodecsJs = require('./util/codecs.js');
|
368 |
|
369 | var _mediaGroups = require('./media-groups');
|
370 |
|
371 | var ABORT_EARLY_BLACKLIST_SECONDS = 60 * 2;
|
372 |
|
373 | var Hls = undefined;
|
374 |
|
375 |
|
376 | var defaultCodecs = {
|
377 | videoCodec: 'avc1',
|
378 | videoObjectTypeIndicator: '.4d400d',
|
379 |
|
380 | audioProfile: '2'
|
381 | };
|
382 |
|
383 |
|
384 |
|
385 | var loaderStats = ['mediaRequests', 'mediaRequestsAborted', 'mediaRequestsTimedout', 'mediaRequestsErrored', 'mediaTransferDuration', 'mediaBytesTransferred'];
|
386 | var sumLoaderStat = function sumLoaderStat(stat) {
|
387 | return this.audioSegmentLoader_[stat] + this.mainSegmentLoader_[stat];
|
388 | };
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | var mapLegacyAvcCodecs_ = function mapLegacyAvcCodecs_(codecString) {
|
400 | return codecString.replace(/avc1\.(\d+)\.(\d+)/i, function (match) {
|
401 | return (0, _videojsContribMediaSourcesEs5CodecUtils.translateLegacyCodecs)([match])[0];
|
402 | });
|
403 | };
|
404 |
|
405 | exports.mapLegacyAvcCodecs_ = mapLegacyAvcCodecs_;
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 | var makeMimeTypeString = function makeMimeTypeString(type, container, codecs) {
|
414 |
|
415 |
|
416 |
|
417 | return type + '/' + container + '; codecs="' + codecs.filter(function (c) {
|
418 | return !!c;
|
419 | }).join(', ') + '"';
|
420 | };
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 | var getContainerType = function getContainerType(media) {
|
428 |
|
429 |
|
430 |
|
431 |
|
432 | if (media.segments && media.segments.length && media.segments[0].map) {
|
433 | return 'mp4';
|
434 | }
|
435 | return 'mp2t';
|
436 | };
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | var getCodecs = function getCodecs(media) {
|
445 |
|
446 |
|
447 | var mediaAttributes = media.attributes || {};
|
448 |
|
449 | if (mediaAttributes.CODECS) {
|
450 | return (0, _utilCodecsJs.parseCodecs)(mediaAttributes.CODECS);
|
451 | }
|
452 | return defaultCodecs;
|
453 | };
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 | var mimeTypesForPlaylist_ = function mimeTypesForPlaylist_(master, media) {
|
470 | var containerType = getContainerType(media);
|
471 | var codecInfo = getCodecs(media);
|
472 | var mediaAttributes = media.attributes || {};
|
473 |
|
474 | var isMuxed = true;
|
475 | var isMaat = false;
|
476 |
|
477 | if (!media) {
|
478 |
|
479 | return [];
|
480 | }
|
481 |
|
482 | if (master.mediaGroups.AUDIO && mediaAttributes.AUDIO) {
|
483 | var audioGroup = master.mediaGroups.AUDIO[mediaAttributes.AUDIO];
|
484 |
|
485 |
|
486 | if (audioGroup) {
|
487 | isMaat = true;
|
488 |
|
489 | isMuxed = false;
|
490 |
|
491 | for (var groupId in audioGroup) {
|
492 | if (!audioGroup[groupId].uri) {
|
493 | isMuxed = true;
|
494 | break;
|
495 | }
|
496 | }
|
497 | }
|
498 | }
|
499 |
|
500 |
|
501 |
|
502 | if (isMaat && !codecInfo.audioProfile) {
|
503 | _videoJs2['default'].log.warn('Multiple audio tracks present but no audio codec string is specified. ' + 'Attempting to use the default audio codec (mp4a.40.2)');
|
504 | codecInfo.audioProfile = defaultCodecs.audioProfile;
|
505 | }
|
506 |
|
507 |
|
508 | var codecStrings = {};
|
509 |
|
510 | if (codecInfo.videoCodec) {
|
511 | codecStrings.video = '' + codecInfo.videoCodec + codecInfo.videoObjectTypeIndicator;
|
512 | }
|
513 |
|
514 | if (codecInfo.audioProfile) {
|
515 | codecStrings.audio = 'mp4a.40.' + codecInfo.audioProfile;
|
516 | }
|
517 |
|
518 |
|
519 |
|
520 | var justAudio = makeMimeTypeString('audio', containerType, [codecStrings.audio]);
|
521 | var justVideo = makeMimeTypeString('video', containerType, [codecStrings.video]);
|
522 | var bothVideoAudio = makeMimeTypeString('video', containerType, [codecStrings.video, codecStrings.audio]);
|
523 |
|
524 | if (isMaat) {
|
525 | if (!isMuxed && codecStrings.video) {
|
526 | return [justVideo, justAudio];
|
527 | }
|
528 |
|
529 |
|
530 |
|
531 | return [bothVideoAudio, justAudio];
|
532 | }
|
533 |
|
534 |
|
535 |
|
536 | if (!codecStrings.video) {
|
537 | return [justAudio];
|
538 | }
|
539 |
|
540 |
|
541 |
|
542 | return [bothVideoAudio];
|
543 | };
|
544 |
|
545 | exports.mimeTypesForPlaylist_ = mimeTypesForPlaylist_;
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 | var MasterPlaylistController = (function (_videojs$EventTarget) {
|
557 | _inherits(MasterPlaylistController, _videojs$EventTarget);
|
558 |
|
559 | function MasterPlaylistController(options) {
|
560 | var _this = this;
|
561 |
|
562 | _classCallCheck(this, MasterPlaylistController);
|
563 |
|
564 | _get(Object.getPrototypeOf(MasterPlaylistController.prototype), 'constructor', this).call(this);
|
565 |
|
566 | var url = options.url;
|
567 | var withCredentials = options.withCredentials;
|
568 | var mode = options.mode;
|
569 | var tech = options.tech;
|
570 | var bandwidth = options.bandwidth;
|
571 | var externHls = options.externHls;
|
572 | var useCueTags = options.useCueTags;
|
573 | var blacklistDuration = options.blacklistDuration;
|
574 | var enableLowInitialPlaylist = options.enableLowInitialPlaylist;
|
575 |
|
576 | if (!url) {
|
577 | throw new Error('A non-empty playlist URL is required');
|
578 | }
|
579 |
|
580 | Hls = externHls;
|
581 |
|
582 | this.withCredentials = withCredentials;
|
583 | this.tech_ = tech;
|
584 | this.hls_ = tech.hls;
|
585 | this.mode_ = mode;
|
586 | this.useCueTags_ = useCueTags;
|
587 | this.blacklistDuration = blacklistDuration;
|
588 | this.enableLowInitialPlaylist = enableLowInitialPlaylist;
|
589 | if (this.useCueTags_) {
|
590 | this.cueTagsTrack_ = this.tech_.addTextTrack('metadata', 'ad-cues');
|
591 | this.cueTagsTrack_.inBandMetadataTrackDispatchType = '';
|
592 | }
|
593 |
|
594 | this.requestOptions_ = {
|
595 | withCredentials: this.withCredentials,
|
596 | timeout: null
|
597 | };
|
598 |
|
599 | this.mediaTypes_ = (0, _mediaGroups.createMediaTypes)();
|
600 |
|
601 | this.mediaSource = new _videoJs2['default'].MediaSource({ mode: mode });
|
602 |
|
603 |
|
604 | this.mediaSource.addEventListener('sourceopen', this.handleSourceOpen_.bind(this));
|
605 |
|
606 | this.seekable_ = _videoJs2['default'].createTimeRanges();
|
607 | this.hasPlayed_ = function () {
|
608 | return false;
|
609 | };
|
610 |
|
611 | this.syncController_ = new _syncController2['default'](options);
|
612 | this.segmentMetadataTrack_ = tech.addRemoteTextTrack({
|
613 | kind: 'metadata',
|
614 | label: 'segment-metadata'
|
615 | }, false).track;
|
616 |
|
617 | this.decrypter_ = (0, _webworkify2['default'])(_decrypterWorker2['default']);
|
618 |
|
619 | var segmentLoaderSettings = {
|
620 | hls: this.hls_,
|
621 | mediaSource: this.mediaSource,
|
622 | currentTime: this.tech_.currentTime.bind(this.tech_),
|
623 | seekable: function seekable() {
|
624 | return _this.seekable();
|
625 | },
|
626 | seeking: function seeking() {
|
627 | return _this.tech_.seeking();
|
628 | },
|
629 | duration: function duration() {
|
630 | return _this.mediaSource.duration;
|
631 | },
|
632 | hasPlayed: function hasPlayed() {
|
633 | return _this.hasPlayed_();
|
634 | },
|
635 | goalBufferLength: function goalBufferLength() {
|
636 | return _this.goalBufferLength();
|
637 | },
|
638 | bandwidth: bandwidth,
|
639 | syncController: this.syncController_,
|
640 | decrypter: this.decrypter_
|
641 | };
|
642 |
|
643 |
|
644 | this.masterPlaylistLoader_ = new _playlistLoader2['default'](url, this.hls_, this.withCredentials);
|
645 | this.setupMasterPlaylistLoaderListeners_();
|
646 |
|
647 |
|
648 |
|
649 | this.mainSegmentLoader_ = new _segmentLoader2['default'](_videoJs2['default'].mergeOptions(segmentLoaderSettings, {
|
650 | segmentMetadataTrack: this.segmentMetadataTrack_,
|
651 | loaderType: 'main'
|
652 | }), options);
|
653 |
|
654 |
|
655 | this.audioSegmentLoader_ = new _segmentLoader2['default'](_videoJs2['default'].mergeOptions(segmentLoaderSettings, {
|
656 | loaderType: 'audio'
|
657 | }), options);
|
658 |
|
659 | this.subtitleSegmentLoader_ = new _vttSegmentLoader2['default'](_videoJs2['default'].mergeOptions(segmentLoaderSettings, {
|
660 | loaderType: 'vtt'
|
661 | }), options);
|
662 |
|
663 | this.setupSegmentLoaderListeners_();
|
664 |
|
665 |
|
666 | loaderStats.forEach(function (stat) {
|
667 | _this[stat + '_'] = sumLoaderStat.bind(_this, stat);
|
668 | });
|
669 |
|
670 | this.masterPlaylistLoader_.load();
|
671 | }
|
672 |
|
673 | |
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 | _createClass(MasterPlaylistController, [{
|
681 | key: 'setupMasterPlaylistLoaderListeners_',
|
682 | value: function setupMasterPlaylistLoaderListeners_() {
|
683 | var _this2 = this;
|
684 |
|
685 | this.masterPlaylistLoader_.on('loadedmetadata', function () {
|
686 | var media = _this2.masterPlaylistLoader_.media();
|
687 | var requestTimeout = _this2.masterPlaylistLoader_.targetDuration * 1.5 * 1000;
|
688 |
|
689 |
|
690 |
|
691 | if (_this2.masterPlaylistLoader_.isLowestEnabledRendition_()) {
|
692 | _this2.requestOptions_.timeout = 0;
|
693 | } else {
|
694 | _this2.requestOptions_.timeout = requestTimeout;
|
695 | }
|
696 |
|
697 |
|
698 |
|
699 | if (media.endList && _this2.tech_.preload() !== 'none') {
|
700 | _this2.mainSegmentLoader_.playlist(media, _this2.requestOptions_);
|
701 | _this2.mainSegmentLoader_.load();
|
702 | }
|
703 |
|
704 | (0, _mediaGroups.setupMediaGroups)({
|
705 | segmentLoaders: {
|
706 | AUDIO: _this2.audioSegmentLoader_,
|
707 | SUBTITLES: _this2.subtitleSegmentLoader_,
|
708 | main: _this2.mainSegmentLoader_
|
709 | },
|
710 | tech: _this2.tech_,
|
711 | requestOptions: _this2.requestOptions_,
|
712 | masterPlaylistLoader: _this2.masterPlaylistLoader_,
|
713 | mode: _this2.mode_,
|
714 | hls: _this2.hls_,
|
715 | master: _this2.master(),
|
716 | mediaTypes: _this2.mediaTypes_,
|
717 | blacklistCurrentPlaylist: _this2.blacklistCurrentPlaylist.bind(_this2)
|
718 | });
|
719 |
|
720 | _this2.triggerPresenceUsage_(_this2.master(), media);
|
721 |
|
722 | try {
|
723 | _this2.setupSourceBuffers_();
|
724 | } catch (e) {
|
725 | _videoJs2['default'].log.warn('Failed to create SourceBuffers', e);
|
726 | return _this2.mediaSource.endOfStream('decode');
|
727 | }
|
728 | _this2.setupFirstPlay();
|
729 |
|
730 | _this2.trigger('selectedinitialmedia');
|
731 | });
|
732 |
|
733 | this.masterPlaylistLoader_.on('loadedplaylist', function () {
|
734 | var updatedPlaylist = _this2.masterPlaylistLoader_.media();
|
735 |
|
736 | if (!updatedPlaylist) {
|
737 | var selectedMedia = undefined;
|
738 |
|
739 | if (_this2.enableLowInitialPlaylist) {
|
740 | selectedMedia = _this2.selectInitialPlaylist();
|
741 | }
|
742 |
|
743 | if (!selectedMedia) {
|
744 | selectedMedia = _this2.selectPlaylist();
|
745 | }
|
746 |
|
747 | _this2.initialMedia_ = selectedMedia;
|
748 | _this2.masterPlaylistLoader_.media(_this2.initialMedia_);
|
749 | return;
|
750 | }
|
751 |
|
752 | if (_this2.useCueTags_) {
|
753 | _this2.updateAdCues_(updatedPlaylist);
|
754 | }
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 | _this2.mainSegmentLoader_.playlist(updatedPlaylist, _this2.requestOptions_);
|
761 | _this2.updateDuration();
|
762 |
|
763 |
|
764 |
|
765 |
|
766 | if (!_this2.tech_.paused()) {
|
767 | _this2.mainSegmentLoader_.load();
|
768 | }
|
769 |
|
770 | if (!updatedPlaylist.endList) {
|
771 | (function () {
|
772 | var addSeekableRange = function addSeekableRange() {
|
773 | var seekable = _this2.seekable();
|
774 |
|
775 | if (seekable.length !== 0) {
|
776 | _this2.mediaSource.addSeekableRange_(seekable.start(0), seekable.end(0));
|
777 | }
|
778 | };
|
779 |
|
780 | if (_this2.duration() !== Infinity) {
|
781 | (function () {
|
782 | var onDurationchange = function onDurationchange() {
|
783 | if (_this2.duration() === Infinity) {
|
784 | addSeekableRange();
|
785 | } else {
|
786 | _this2.tech_.one('durationchange', onDurationchange);
|
787 | }
|
788 | };
|
789 |
|
790 | _this2.tech_.one('durationchange', onDurationchange);
|
791 | })();
|
792 | } else {
|
793 | addSeekableRange();
|
794 | }
|
795 | })();
|
796 | }
|
797 | });
|
798 |
|
799 | this.masterPlaylistLoader_.on('error', function () {
|
800 | _this2.blacklistCurrentPlaylist(_this2.masterPlaylistLoader_.error);
|
801 | });
|
802 |
|
803 | this.masterPlaylistLoader_.on('mediachanging', function () {
|
804 | _this2.mainSegmentLoader_.abort();
|
805 | _this2.mainSegmentLoader_.pause();
|
806 | });
|
807 |
|
808 | this.masterPlaylistLoader_.on('mediachange', function () {
|
809 | var media = _this2.masterPlaylistLoader_.media();
|
810 | var requestTimeout = _this2.masterPlaylistLoader_.targetDuration * 1.5 * 1000;
|
811 |
|
812 |
|
813 |
|
814 | if (_this2.masterPlaylistLoader_.isLowestEnabledRendition_()) {
|
815 | _this2.requestOptions_.timeout = 0;
|
816 | } else {
|
817 | _this2.requestOptions_.timeout = requestTimeout;
|
818 | }
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 | _this2.mainSegmentLoader_.playlist(media, _this2.requestOptions_);
|
825 | _this2.mainSegmentLoader_.load();
|
826 |
|
827 | _this2.tech_.trigger({
|
828 | type: 'mediachange',
|
829 | bubbles: true
|
830 | });
|
831 | });
|
832 |
|
833 | this.masterPlaylistLoader_.on('playlistunchanged', function () {
|
834 | var updatedPlaylist = _this2.masterPlaylistLoader_.media();
|
835 | var playlistOutdated = _this2.stuckAtPlaylistEnd_(updatedPlaylist);
|
836 |
|
837 | if (playlistOutdated) {
|
838 |
|
839 |
|
840 |
|
841 |
|
842 | _this2.blacklistCurrentPlaylist({
|
843 | message: 'Playlist no longer updating.'
|
844 | });
|
845 |
|
846 | _this2.tech_.trigger('playliststuck');
|
847 | }
|
848 | });
|
849 |
|
850 | this.masterPlaylistLoader_.on('renditiondisabled', function () {
|
851 | _this2.tech_.trigger({ type: 'usage', name: 'hls-rendition-disabled' });
|
852 | });
|
853 | this.masterPlaylistLoader_.on('renditionenabled', function () {
|
854 | _this2.tech_.trigger({ type: 'usage', name: 'hls-rendition-enabled' });
|
855 | });
|
856 | }
|
857 |
|
858 | |
859 |
|
860 |
|
861 |
|
862 |
|
863 | }, {
|
864 | key: 'triggerPresenceUsage_',
|
865 | value: function triggerPresenceUsage_(master, media) {
|
866 | var mediaGroups = master.mediaGroups || {};
|
867 | var defaultDemuxed = true;
|
868 | var audioGroupKeys = Object.keys(mediaGroups.AUDIO);
|
869 |
|
870 | for (var mediaGroup in mediaGroups.AUDIO) {
|
871 | for (var label in mediaGroups.AUDIO[mediaGroup]) {
|
872 | var properties = mediaGroups.AUDIO[mediaGroup][label];
|
873 |
|
874 | if (!properties.uri) {
|
875 | defaultDemuxed = false;
|
876 | }
|
877 | }
|
878 | }
|
879 |
|
880 | if (defaultDemuxed) {
|
881 | this.tech_.trigger({ type: 'usage', name: 'hls-demuxed' });
|
882 | }
|
883 |
|
884 | if (Object.keys(mediaGroups.SUBTITLES).length) {
|
885 | this.tech_.trigger({ type: 'usage', name: 'hls-webvtt' });
|
886 | }
|
887 |
|
888 | if (Hls.Playlist.isAes(media)) {
|
889 | this.tech_.trigger({ type: 'usage', name: 'hls-aes' });
|
890 | }
|
891 |
|
892 | if (Hls.Playlist.isFmp4(media)) {
|
893 | this.tech_.trigger({ type: 'usage', name: 'hls-fmp4' });
|
894 | }
|
895 |
|
896 | if (audioGroupKeys.length && Object.keys(mediaGroups.AUDIO[audioGroupKeys[0]]).length > 1) {
|
897 | this.tech_.trigger({ type: 'usage', name: 'hls-alternate-audio' });
|
898 | }
|
899 |
|
900 | if (this.useCueTags_) {
|
901 | this.tech_.trigger({ type: 'usage', name: 'hls-playlist-cue-tags' });
|
902 | }
|
903 | }
|
904 |
|
905 | |
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 | }, {
|
912 | key: 'setupSegmentLoaderListeners_',
|
913 | value: function setupSegmentLoaderListeners_() {
|
914 | var _this3 = this;
|
915 |
|
916 | this.mainSegmentLoader_.on('bandwidthupdate', function () {
|
917 | var nextPlaylist = _this3.selectPlaylist();
|
918 | var currentPlaylist = _this3.masterPlaylistLoader_.media();
|
919 | var buffered = _this3.tech_.buffered();
|
920 | var forwardBuffer = buffered.length ? buffered.end(buffered.length - 1) - _this3.tech_.currentTime() : 0;
|
921 |
|
922 | var bufferLowWaterLine = _this3.bufferLowWaterLine();
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 | if (!currentPlaylist.endList ||
|
929 |
|
930 |
|
931 | _this3.duration() < _config2['default'].MAX_BUFFER_LOW_WATER_LINE ||
|
932 |
|
933 | nextPlaylist.attributes.BANDWIDTH < currentPlaylist.attributes.BANDWIDTH ||
|
934 |
|
935 |
|
936 | forwardBuffer >= bufferLowWaterLine) {
|
937 | _this3.masterPlaylistLoader_.media(nextPlaylist);
|
938 | }
|
939 |
|
940 | _this3.tech_.trigger('bandwidthupdate');
|
941 | });
|
942 | this.mainSegmentLoader_.on('progress', function () {
|
943 | _this3.trigger('progress');
|
944 | });
|
945 |
|
946 | this.mainSegmentLoader_.on('error', function () {
|
947 | _this3.blacklistCurrentPlaylist(_this3.mainSegmentLoader_.error());
|
948 | });
|
949 |
|
950 | this.mainSegmentLoader_.on('syncinfoupdate', function () {
|
951 | _this3.onSyncInfoUpdate_();
|
952 | });
|
953 |
|
954 | this.mainSegmentLoader_.on('timestampoffset', function () {
|
955 | _this3.tech_.trigger({ type: 'usage', name: 'hls-timestamp-offset' });
|
956 | });
|
957 | this.audioSegmentLoader_.on('syncinfoupdate', function () {
|
958 | _this3.onSyncInfoUpdate_();
|
959 | });
|
960 |
|
961 | this.mainSegmentLoader_.on('ended', function () {
|
962 | _this3.onEndOfStream();
|
963 | });
|
964 |
|
965 | this.mainSegmentLoader_.on('earlyabort', function () {
|
966 | _this3.blacklistCurrentPlaylist({
|
967 | message: 'Aborted early because there isn\'t enough bandwidth to complete the ' + 'request without rebuffering.'
|
968 | }, ABORT_EARLY_BLACKLIST_SECONDS);
|
969 | });
|
970 |
|
971 | this.mainSegmentLoader_.on('reseteverything', function () {
|
972 |
|
973 |
|
974 | _this3.tech_.trigger('hls-reset');
|
975 | });
|
976 |
|
977 | this.mainSegmentLoader_.on('segmenttimemapping', function (event) {
|
978 |
|
979 |
|
980 | _this3.tech_.trigger({
|
981 | type: 'hls-segment-time-mapping',
|
982 | mapping: event.mapping
|
983 | });
|
984 | });
|
985 |
|
986 | this.audioSegmentLoader_.on('ended', function () {
|
987 | _this3.onEndOfStream();
|
988 | });
|
989 | }
|
990 | }, {
|
991 | key: 'mediaSecondsLoaded_',
|
992 | value: function mediaSecondsLoaded_() {
|
993 | return Math.max(this.audioSegmentLoader_.mediaSecondsLoaded + this.mainSegmentLoader_.mediaSecondsLoaded);
|
994 | }
|
995 |
|
996 | |
997 |
|
998 |
|
999 | }, {
|
1000 | key: 'load',
|
1001 | value: function load() {
|
1002 | this.mainSegmentLoader_.load();
|
1003 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
1004 | this.audioSegmentLoader_.load();
|
1005 | }
|
1006 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
1007 | this.subtitleSegmentLoader_.load();
|
1008 | }
|
1009 | }
|
1010 |
|
1011 | |
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 | }, {
|
1020 | key: 'fastQualityChange_',
|
1021 | value: function fastQualityChange_() {
|
1022 | var media = this.selectPlaylist();
|
1023 |
|
1024 | if (media !== this.masterPlaylistLoader_.media()) {
|
1025 | this.masterPlaylistLoader_.media(media);
|
1026 |
|
1027 | this.mainSegmentLoader_.resetLoader();
|
1028 |
|
1029 | }
|
1030 | }
|
1031 |
|
1032 | |
1033 |
|
1034 |
|
1035 | }, {
|
1036 | key: 'play',
|
1037 | value: function play() {
|
1038 | if (this.setupFirstPlay()) {
|
1039 | return;
|
1040 | }
|
1041 |
|
1042 | if (this.tech_.ended()) {
|
1043 | this.tech_.setCurrentTime(0);
|
1044 | }
|
1045 |
|
1046 | if (this.hasPlayed_()) {
|
1047 | this.load();
|
1048 | }
|
1049 |
|
1050 | var seekable = this.tech_.seekable();
|
1051 |
|
1052 |
|
1053 |
|
1054 | if (this.tech_.duration() === Infinity) {
|
1055 | if (this.tech_.currentTime() < seekable.start(0)) {
|
1056 | return this.tech_.setCurrentTime(seekable.end(seekable.length - 1));
|
1057 | }
|
1058 | }
|
1059 | }
|
1060 |
|
1061 | |
1062 |
|
1063 |
|
1064 |
|
1065 | }, {
|
1066 | key: 'setupFirstPlay',
|
1067 | value: function setupFirstPlay() {
|
1068 | var _this4 = this;
|
1069 |
|
1070 | var media = this.masterPlaylistLoader_.media();
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 | if (!media || this.tech_.paused() || this.hasPlayed_()) {
|
1078 | return false;
|
1079 | }
|
1080 |
|
1081 |
|
1082 | if (!media.endList) {
|
1083 | var _ret3 = (function () {
|
1084 | var seekable = _this4.seekable();
|
1085 |
|
1086 | if (!seekable.length) {
|
1087 |
|
1088 |
|
1089 | return {
|
1090 | v: false
|
1091 | };
|
1092 | }
|
1093 |
|
1094 | if (_videoJs2['default'].browser.IE_VERSION && _this4.mode_ === 'html5' && _this4.tech_.readyState() === 0) {
|
1095 |
|
1096 |
|
1097 | _this4.tech_.one('loadedmetadata', function () {
|
1098 | _this4.trigger('firstplay');
|
1099 | _this4.tech_.setCurrentTime(seekable.end(0));
|
1100 | _this4.hasPlayed_ = function () {
|
1101 | return true;
|
1102 | };
|
1103 | });
|
1104 |
|
1105 | return {
|
1106 | v: false
|
1107 | };
|
1108 | }
|
1109 |
|
1110 |
|
1111 | _this4.trigger('firstplay');
|
1112 |
|
1113 | _this4.tech_.setCurrentTime(seekable.end(0));
|
1114 | })();
|
1115 |
|
1116 | if (typeof _ret3 === 'object') return _ret3.v;
|
1117 | }
|
1118 |
|
1119 | this.hasPlayed_ = function () {
|
1120 | return true;
|
1121 | };
|
1122 |
|
1123 | this.load();
|
1124 | return true;
|
1125 | }
|
1126 |
|
1127 | |
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 | }, {
|
1133 | key: 'handleSourceOpen_',
|
1134 | value: function handleSourceOpen_() {
|
1135 |
|
1136 |
|
1137 |
|
1138 | try {
|
1139 | this.setupSourceBuffers_();
|
1140 | } catch (e) {
|
1141 | _videoJs2['default'].log.warn('Failed to create Source Buffers', e);
|
1142 | return this.mediaSource.endOfStream('decode');
|
1143 | }
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 | if (this.tech_.autoplay()) {
|
1149 | this.tech_.play();
|
1150 | }
|
1151 |
|
1152 | this.trigger('sourceopen');
|
1153 | }
|
1154 |
|
1155 | |
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 | }, {
|
1164 | key: 'onEndOfStream',
|
1165 | value: function onEndOfStream() {
|
1166 | var isEndOfStream = this.mainSegmentLoader_.ended_;
|
1167 |
|
1168 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
1169 |
|
1170 |
|
1171 | isEndOfStream = isEndOfStream && this.audioSegmentLoader_.ended_;
|
1172 | }
|
1173 |
|
1174 | if (isEndOfStream) {
|
1175 | this.mediaSource.endOfStream();
|
1176 | }
|
1177 | }
|
1178 |
|
1179 | |
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 | }, {
|
1185 | key: 'stuckAtPlaylistEnd_',
|
1186 | value: function stuckAtPlaylistEnd_(playlist) {
|
1187 | var seekable = this.seekable();
|
1188 |
|
1189 | if (!seekable.length) {
|
1190 |
|
1191 | return false;
|
1192 | }
|
1193 |
|
1194 | var expired = this.syncController_.getExpiredTime(playlist, this.mediaSource.duration);
|
1195 |
|
1196 | if (expired === null) {
|
1197 | return false;
|
1198 | }
|
1199 |
|
1200 |
|
1201 |
|
1202 | var absolutePlaylistEnd = Hls.Playlist.playlistEnd(playlist, expired);
|
1203 | var currentTime = this.tech_.currentTime();
|
1204 | var buffered = this.tech_.buffered();
|
1205 |
|
1206 | if (!buffered.length) {
|
1207 |
|
1208 | return absolutePlaylistEnd - currentTime <= _ranges2['default'].SAFE_TIME_DELTA;
|
1209 | }
|
1210 | var bufferedEnd = buffered.end(buffered.length - 1);
|
1211 |
|
1212 |
|
1213 |
|
1214 | return bufferedEnd - currentTime <= _ranges2['default'].SAFE_TIME_DELTA && absolutePlaylistEnd - bufferedEnd <= _ranges2['default'].SAFE_TIME_DELTA;
|
1215 | }
|
1216 |
|
1217 | |
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 | }, {
|
1228 | key: 'blacklistCurrentPlaylist',
|
1229 | value: function blacklistCurrentPlaylist(error, blacklistDuration) {
|
1230 | if (error === undefined) error = {};
|
1231 |
|
1232 | var currentPlaylist = undefined;
|
1233 | var nextPlaylist = undefined;
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 | currentPlaylist = error.playlist || this.masterPlaylistLoader_.media();
|
1240 |
|
1241 | blacklistDuration = blacklistDuration || error.blacklistDuration || this.blacklistDuration;
|
1242 |
|
1243 |
|
1244 |
|
1245 | if (!currentPlaylist) {
|
1246 | this.error = error;
|
1247 |
|
1248 | try {
|
1249 | return this.mediaSource.endOfStream('network');
|
1250 | } catch (e) {
|
1251 | return this.trigger('error');
|
1252 | }
|
1253 | }
|
1254 |
|
1255 | var isFinalRendition = this.masterPlaylistLoader_.isFinalRendition_();
|
1256 |
|
1257 | if (isFinalRendition) {
|
1258 |
|
1259 | _videoJs2['default'].log.warn('Problem encountered with the current ' + 'HLS playlist. Trying again since it is the final playlist.');
|
1260 |
|
1261 | this.tech_.trigger('retryplaylist');
|
1262 | return this.masterPlaylistLoader_.load(isFinalRendition);
|
1263 | }
|
1264 |
|
1265 | currentPlaylist.excludeUntil = Date.now() + blacklistDuration * 1000;
|
1266 | this.tech_.trigger('blacklistplaylist');
|
1267 | this.tech_.trigger({ type: 'usage', name: 'hls-rendition-blacklisted' });
|
1268 |
|
1269 |
|
1270 | nextPlaylist = this.selectPlaylist();
|
1271 | _videoJs2['default'].log.warn('Problem encountered with the current HLS playlist.' + (error.message ? ' ' + error.message : '') + ' Switching to another playlist.');
|
1272 |
|
1273 | return this.masterPlaylistLoader_.media(nextPlaylist);
|
1274 | }
|
1275 |
|
1276 | |
1277 |
|
1278 |
|
1279 | }, {
|
1280 | key: 'pauseLoading',
|
1281 | value: function pauseLoading() {
|
1282 | this.mainSegmentLoader_.pause();
|
1283 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
1284 | this.audioSegmentLoader_.pause();
|
1285 | }
|
1286 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
1287 | this.subtitleSegmentLoader_.pause();
|
1288 | }
|
1289 | }
|
1290 |
|
1291 | |
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 | }, {
|
1298 | key: 'setCurrentTime',
|
1299 | value: function setCurrentTime(currentTime) {
|
1300 | var buffered = _ranges2['default'].findRange(this.tech_.buffered(), currentTime);
|
1301 |
|
1302 | if (!(this.masterPlaylistLoader_ && this.masterPlaylistLoader_.media())) {
|
1303 |
|
1304 | return 0;
|
1305 | }
|
1306 |
|
1307 |
|
1308 |
|
1309 | if (!this.masterPlaylistLoader_.media().segments) {
|
1310 | return 0;
|
1311 | }
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 | if (buffered && buffered.length && this.mode_ !== 'flash') {
|
1317 | return currentTime;
|
1318 | }
|
1319 |
|
1320 |
|
1321 |
|
1322 | this.mainSegmentLoader_.resetEverything();
|
1323 | this.mainSegmentLoader_.abort();
|
1324 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
1325 | this.audioSegmentLoader_.resetEverything();
|
1326 | this.audioSegmentLoader_.abort();
|
1327 | }
|
1328 | if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) {
|
1329 | this.subtitleSegmentLoader_.resetEverything();
|
1330 | this.subtitleSegmentLoader_.abort();
|
1331 | }
|
1332 |
|
1333 |
|
1334 | this.load();
|
1335 | }
|
1336 |
|
1337 | |
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 | }, {
|
1343 | key: 'duration',
|
1344 | value: function duration() {
|
1345 | if (!this.masterPlaylistLoader_) {
|
1346 | return 0;
|
1347 | }
|
1348 |
|
1349 | if (this.mediaSource) {
|
1350 | return this.mediaSource.duration;
|
1351 | }
|
1352 |
|
1353 | return Hls.Playlist.duration(this.masterPlaylistLoader_.media());
|
1354 | }
|
1355 |
|
1356 | |
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 | }, {
|
1362 | key: 'seekable',
|
1363 | value: function seekable() {
|
1364 | return this.seekable_;
|
1365 | }
|
1366 | }, {
|
1367 | key: 'onSyncInfoUpdate_',
|
1368 | value: function onSyncInfoUpdate_() {
|
1369 | var mainSeekable = undefined;
|
1370 | var audioSeekable = undefined;
|
1371 |
|
1372 | if (!this.masterPlaylistLoader_) {
|
1373 | return;
|
1374 | }
|
1375 |
|
1376 | var media = this.masterPlaylistLoader_.media();
|
1377 |
|
1378 | if (!media) {
|
1379 | return;
|
1380 | }
|
1381 |
|
1382 | var expired = this.syncController_.getExpiredTime(media, this.mediaSource.duration);
|
1383 |
|
1384 | if (expired === null) {
|
1385 |
|
1386 | return;
|
1387 | }
|
1388 |
|
1389 | mainSeekable = Hls.Playlist.seekable(media, expired);
|
1390 |
|
1391 | if (mainSeekable.length === 0) {
|
1392 | return;
|
1393 | }
|
1394 |
|
1395 | if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
|
1396 | media = this.mediaTypes_.AUDIO.activePlaylistLoader.media();
|
1397 | expired = this.syncController_.getExpiredTime(media, this.mediaSource.duration);
|
1398 |
|
1399 | if (expired === null) {
|
1400 | return;
|
1401 | }
|
1402 |
|
1403 | audioSeekable = Hls.Playlist.seekable(media, expired);
|
1404 |
|
1405 | if (audioSeekable.length === 0) {
|
1406 | return;
|
1407 | }
|
1408 | }
|
1409 |
|
1410 | if (!audioSeekable) {
|
1411 |
|
1412 |
|
1413 | this.seekable_ = mainSeekable;
|
1414 | } else if (audioSeekable.start(0) > mainSeekable.end(0) || mainSeekable.start(0) > audioSeekable.end(0)) {
|
1415 |
|
1416 | this.seekable_ = mainSeekable;
|
1417 | } else {
|
1418 | this.seekable_ = _videoJs2['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)]]);
|
1419 | }
|
1420 |
|
1421 | this.tech_.trigger('seekablechanged');
|
1422 | }
|
1423 |
|
1424 | |
1425 |
|
1426 |
|
1427 | }, {
|
1428 | key: 'updateDuration',
|
1429 | value: function updateDuration() {
|
1430 | var _this5 = this;
|
1431 |
|
1432 | var oldDuration = this.mediaSource.duration;
|
1433 | var newDuration = Hls.Playlist.duration(this.masterPlaylistLoader_.media());
|
1434 | var buffered = this.tech_.buffered();
|
1435 | var setDuration = function setDuration() {
|
1436 | _this5.mediaSource.duration = newDuration;
|
1437 | _this5.tech_.trigger('durationchange');
|
1438 |
|
1439 | _this5.mediaSource.removeEventListener('sourceopen', setDuration);
|
1440 | };
|
1441 |
|
1442 | if (buffered.length > 0) {
|
1443 | newDuration = Math.max(newDuration, buffered.end(buffered.length - 1));
|
1444 | }
|
1445 |
|
1446 |
|
1447 | if (oldDuration !== newDuration) {
|
1448 |
|
1449 | if (this.mediaSource.readyState !== 'open') {
|
1450 | this.mediaSource.addEventListener('sourceopen', setDuration);
|
1451 | } else {
|
1452 | setDuration();
|
1453 | }
|
1454 | }
|
1455 | }
|
1456 |
|
1457 | |
1458 |
|
1459 |
|
1460 |
|
1461 | }, {
|
1462 | key: 'dispose',
|
1463 | value: function dispose() {
|
1464 | var _this6 = this;
|
1465 |
|
1466 | this.decrypter_.terminate();
|
1467 | this.masterPlaylistLoader_.dispose();
|
1468 | this.mainSegmentLoader_.dispose();
|
1469 |
|
1470 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
1471 | var groups = _this6.mediaTypes_[type].groups;
|
1472 |
|
1473 | for (var id in groups) {
|
1474 | groups[id].forEach(function (group) {
|
1475 | if (group.playlistLoader) {
|
1476 | group.playlistLoader.dispose();
|
1477 | }
|
1478 | });
|
1479 | }
|
1480 | });
|
1481 |
|
1482 | this.audioSegmentLoader_.dispose();
|
1483 | this.subtitleSegmentLoader_.dispose();
|
1484 | }
|
1485 |
|
1486 | |
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 | }, {
|
1492 | key: 'master',
|
1493 | value: function master() {
|
1494 | return this.masterPlaylistLoader_.master;
|
1495 | }
|
1496 |
|
1497 | |
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 | }, {
|
1503 | key: 'media',
|
1504 | value: function media() {
|
1505 |
|
1506 | return this.masterPlaylistLoader_.media() || this.initialMedia_;
|
1507 | }
|
1508 |
|
1509 | |
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 | }, {
|
1515 | key: 'setupSourceBuffers_',
|
1516 | value: function setupSourceBuffers_() {
|
1517 | var media = this.masterPlaylistLoader_.media();
|
1518 | var mimeTypes = undefined;
|
1519 |
|
1520 |
|
1521 |
|
1522 | if (!media || this.mediaSource.readyState !== 'open') {
|
1523 | return;
|
1524 | }
|
1525 |
|
1526 | mimeTypes = mimeTypesForPlaylist_(this.masterPlaylistLoader_.master, media);
|
1527 | if (mimeTypes.length < 1) {
|
1528 | this.error = 'No compatible SourceBuffer configuration for the variant stream:' + media.resolvedUri;
|
1529 | return this.mediaSource.endOfStream('decode');
|
1530 | }
|
1531 | this.mainSegmentLoader_.mimeType(mimeTypes[0]);
|
1532 | if (mimeTypes[1]) {
|
1533 | this.audioSegmentLoader_.mimeType(mimeTypes[1]);
|
1534 | }
|
1535 |
|
1536 |
|
1537 |
|
1538 | this.excludeIncompatibleVariants_(media);
|
1539 | }
|
1540 |
|
1541 | |
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 | }, {
|
1556 | key: 'excludeIncompatibleVariants_',
|
1557 | value: function excludeIncompatibleVariants_(media) {
|
1558 | var master = this.masterPlaylistLoader_.master;
|
1559 | var codecCount = 2;
|
1560 | var videoCodec = null;
|
1561 | var codecs = undefined;
|
1562 |
|
1563 | if (media.attributes.CODECS) {
|
1564 | codecs = (0, _utilCodecsJs.parseCodecs)(media.attributes.CODECS);
|
1565 | videoCodec = codecs.videoCodec;
|
1566 | codecCount = codecs.codecCount;
|
1567 | }
|
1568 | master.playlists.forEach(function (variant) {
|
1569 | var variantCodecs = {
|
1570 | codecCount: 2,
|
1571 | videoCodec: null
|
1572 | };
|
1573 |
|
1574 | if (variant.attributes.CODECS) {
|
1575 | var codecString = variant.attributes.CODECS;
|
1576 |
|
1577 | variantCodecs = (0, _utilCodecsJs.parseCodecs)(codecString);
|
1578 |
|
1579 | if (window.MediaSource && window.MediaSource.isTypeSupported && !window.MediaSource.isTypeSupported('video/mp4; codecs="' + mapLegacyAvcCodecs_(codecString) + '"')) {
|
1580 | variant.excludeUntil = Infinity;
|
1581 | }
|
1582 | }
|
1583 |
|
1584 |
|
1585 |
|
1586 | if (variantCodecs.codecCount !== codecCount) {
|
1587 | variant.excludeUntil = Infinity;
|
1588 | }
|
1589 |
|
1590 |
|
1591 |
|
1592 | if (variantCodecs.videoCodec !== videoCodec) {
|
1593 | variant.excludeUntil = Infinity;
|
1594 | }
|
1595 | });
|
1596 | }
|
1597 | }, {
|
1598 | key: 'updateAdCues_',
|
1599 | value: function updateAdCues_(media) {
|
1600 | var offset = 0;
|
1601 | var seekable = this.seekable();
|
1602 |
|
1603 | if (seekable.length) {
|
1604 | offset = seekable.start(0);
|
1605 | }
|
1606 |
|
1607 | _adCueTags2['default'].updateAdCues(media, this.cueTagsTrack_, offset);
|
1608 | }
|
1609 |
|
1610 | |
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 | }, {
|
1616 | key: 'goalBufferLength',
|
1617 | value: function goalBufferLength() {
|
1618 | var currentTime = this.tech_.currentTime();
|
1619 | var initial = _config2['default'].GOAL_BUFFER_LENGTH;
|
1620 | var rate = _config2['default'].GOAL_BUFFER_LENGTH_RATE;
|
1621 | var max = Math.max(initial, _config2['default'].MAX_GOAL_BUFFER_LENGTH);
|
1622 |
|
1623 | return Math.min(initial + currentTime * rate, max);
|
1624 | }
|
1625 |
|
1626 | |
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 | }, {
|
1632 | key: 'bufferLowWaterLine',
|
1633 | value: function bufferLowWaterLine() {
|
1634 | var currentTime = this.tech_.currentTime();
|
1635 | var initial = _config2['default'].BUFFER_LOW_WATER_LINE;
|
1636 | var rate = _config2['default'].BUFFER_LOW_WATER_LINE_RATE;
|
1637 | var max = Math.max(initial, _config2['default'].MAX_BUFFER_LOW_WATER_LINE);
|
1638 |
|
1639 | return Math.min(initial + currentTime * rate, max);
|
1640 | }
|
1641 | }]);
|
1642 |
|
1643 | return MasterPlaylistController;
|
1644 | })(_videoJs2['default'].EventTarget);
|
1645 |
|
1646 | exports.MasterPlaylistController = MasterPlaylistController;
|
1647 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1648 | },{"./ad-cue-tags":1,"./config":3,"./decrypter-worker":4,"./media-groups":6,"./playlist-loader":9,"./ranges":12,"./segment-loader":16,"./sync-controller":18,"./util/codecs.js":19,"./vtt-segment-loader":20,"videojs-contrib-media-sources/es5/codec-utils":65,"webworkify":76}],6:[function(require,module,exports){
|
1649 | (function (global){
|
1650 | 'use strict';
|
1651 |
|
1652 | Object.defineProperty(exports, '__esModule', {
|
1653 | value: true
|
1654 | });
|
1655 |
|
1656 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
1657 |
|
1658 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
1659 |
|
1660 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
1661 |
|
1662 | var _playlistLoader = require('./playlist-loader');
|
1663 |
|
1664 | var _playlistLoader2 = _interopRequireDefault(_playlistLoader);
|
1665 |
|
1666 | var noop = function noop() {};
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 | var audioTrackKind_ = function audioTrackKind_(properties) {
|
1674 | var kind = properties['default'] ? 'main' : 'alternative';
|
1675 |
|
1676 | if (properties.characteristics && properties.characteristics.indexOf('public.accessibility.describes-video') >= 0) {
|
1677 | kind = 'main-desc';
|
1678 | }
|
1679 |
|
1680 | return kind;
|
1681 | };
|
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 | var stopLoaders = function stopLoaders(segmentLoader, mediaType) {
|
1693 | segmentLoader.abort();
|
1694 | segmentLoader.pause();
|
1695 |
|
1696 | if (mediaType && mediaType.activePlaylistLoader) {
|
1697 | mediaType.activePlaylistLoader.pause();
|
1698 | mediaType.activePlaylistLoader = null;
|
1699 | }
|
1700 | };
|
1701 |
|
1702 | exports.stopLoaders = stopLoaders;
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 | var startLoaders = function startLoaders(playlistLoader, mediaType) {
|
1713 |
|
1714 |
|
1715 | mediaType.activePlaylistLoader = playlistLoader;
|
1716 | playlistLoader.load();
|
1717 | };
|
1718 |
|
1719 | exports.startLoaders = startLoaders;
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 | var onGroupChanged = function onGroupChanged(type, settings) {
|
1736 | return function () {
|
1737 | var _settings$segmentLoaders = settings.segmentLoaders;
|
1738 | var segmentLoader = _settings$segmentLoaders[type];
|
1739 | var mainSegmentLoader = _settings$segmentLoaders.main;
|
1740 | var mediaType = settings.mediaTypes[type];
|
1741 |
|
1742 | var activeTrack = mediaType.activeTrack();
|
1743 | var activeGroup = mediaType.activeGroup(activeTrack);
|
1744 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
1745 |
|
1746 | stopLoaders(segmentLoader, mediaType);
|
1747 |
|
1748 | if (!activeGroup) {
|
1749 |
|
1750 | return;
|
1751 | }
|
1752 |
|
1753 | if (!activeGroup.playlistLoader) {
|
1754 | if (previousActiveLoader) {
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 | mainSegmentLoader.resetEverything();
|
1760 | }
|
1761 | return;
|
1762 | }
|
1763 |
|
1764 |
|
1765 | segmentLoader.resyncLoader();
|
1766 |
|
1767 | startLoaders(activeGroup.playlistLoader, mediaType);
|
1768 | };
|
1769 | };
|
1770 |
|
1771 | exports.onGroupChanged = onGroupChanged;
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 | var onTrackChanged = function onTrackChanged(type, settings) {
|
1787 | return function () {
|
1788 | var _settings$segmentLoaders2 = settings.segmentLoaders;
|
1789 | var segmentLoader = _settings$segmentLoaders2[type];
|
1790 | var mainSegmentLoader = _settings$segmentLoaders2.main;
|
1791 | var mediaType = settings.mediaTypes[type];
|
1792 |
|
1793 | var activeTrack = mediaType.activeTrack();
|
1794 | var activeGroup = mediaType.activeGroup(activeTrack);
|
1795 | var previousActiveLoader = mediaType.activePlaylistLoader;
|
1796 |
|
1797 | stopLoaders(segmentLoader, mediaType);
|
1798 |
|
1799 | if (!activeGroup) {
|
1800 |
|
1801 | return;
|
1802 | }
|
1803 |
|
1804 | if (!activeGroup.playlistLoader) {
|
1805 |
|
1806 |
|
1807 |
|
1808 | mainSegmentLoader.resetEverything();
|
1809 | return;
|
1810 | }
|
1811 |
|
1812 | if (previousActiveLoader === activeGroup.playlistLoader) {
|
1813 |
|
1814 |
|
1815 |
|
1816 | startLoaders(activeGroup.playlistLoader, mediaType);
|
1817 | return;
|
1818 | }
|
1819 |
|
1820 | if (segmentLoader.track) {
|
1821 |
|
1822 | segmentLoader.track(activeTrack);
|
1823 | }
|
1824 |
|
1825 |
|
1826 | segmentLoader.resetEverything();
|
1827 |
|
1828 | startLoaders(activeGroup.playlistLoader, mediaType);
|
1829 | };
|
1830 | };
|
1831 |
|
1832 | exports.onTrackChanged = onTrackChanged;
|
1833 | var onError = {
|
1834 | |
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 | AUDIO: function AUDIO(type, settings) {
|
1848 | return function () {
|
1849 | var segmentLoader = settings.segmentLoaders[type];
|
1850 | var mediaType = settings.mediaTypes[type];
|
1851 | var blacklistCurrentPlaylist = settings.blacklistCurrentPlaylist;
|
1852 |
|
1853 | stopLoaders(segmentLoader, mediaType);
|
1854 |
|
1855 |
|
1856 | var activeTrack = mediaType.activeTrack();
|
1857 | var activeGroup = mediaType.activeGroup();
|
1858 | var id = (activeGroup.filter(function (group) {
|
1859 | return group['default'];
|
1860 | })[0] || activeGroup[0]).id;
|
1861 | var defaultTrack = mediaType.tracks[id];
|
1862 |
|
1863 | if (activeTrack === defaultTrack) {
|
1864 |
|
1865 |
|
1866 | blacklistCurrentPlaylist({
|
1867 | message: 'Problem encountered loading the default audio track.'
|
1868 | });
|
1869 | return;
|
1870 | }
|
1871 |
|
1872 | _videoJs2['default'].log.warn('Problem encountered loading the alternate audio track.' + 'Switching back to default.');
|
1873 |
|
1874 | for (var trackId in mediaType.tracks) {
|
1875 | mediaType.tracks[trackId].enabled = mediaType.tracks[trackId] === defaultTrack;
|
1876 | }
|
1877 |
|
1878 | mediaType.onTrackChanged();
|
1879 | };
|
1880 | },
|
1881 | |
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 | SUBTITLES: function SUBTITLES(type, settings) {
|
1894 | return function () {
|
1895 | var segmentLoader = settings.segmentLoaders[type];
|
1896 | var mediaType = settings.mediaTypes[type];
|
1897 |
|
1898 | _videoJs2['default'].log.warn('Problem encountered loading the subtitle track.' + 'Disabling subtitle track.');
|
1899 |
|
1900 | stopLoaders(segmentLoader, mediaType);
|
1901 |
|
1902 | var track = mediaType.activeTrack();
|
1903 |
|
1904 | if (track) {
|
1905 | track.mode = 'disabled';
|
1906 | }
|
1907 |
|
1908 | mediaType.onTrackChanged();
|
1909 | };
|
1910 | }
|
1911 | };
|
1912 |
|
1913 | exports.onError = onError;
|
1914 | var setupListeners = {
|
1915 | |
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 | AUDIO: function AUDIO(type, playlistLoader, settings) {
|
1927 | if (!playlistLoader) {
|
1928 |
|
1929 | return;
|
1930 | }
|
1931 |
|
1932 | var tech = settings.tech;
|
1933 | var requestOptions = settings.requestOptions;
|
1934 | var segmentLoader = settings.segmentLoaders[type];
|
1935 |
|
1936 | playlistLoader.on('loadedmetadata', function () {
|
1937 | var media = playlistLoader.media();
|
1938 |
|
1939 | segmentLoader.playlist(media, requestOptions);
|
1940 |
|
1941 |
|
1942 |
|
1943 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
1944 | segmentLoader.load();
|
1945 | }
|
1946 | });
|
1947 |
|
1948 | playlistLoader.on('loadedplaylist', function () {
|
1949 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
1950 |
|
1951 |
|
1952 | if (!tech.paused()) {
|
1953 | segmentLoader.load();
|
1954 | }
|
1955 | });
|
1956 |
|
1957 | playlistLoader.on('error', onError[type](type, settings));
|
1958 | },
|
1959 | |
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 | SUBTITLES: function SUBTITLES(type, playlistLoader, settings) {
|
1971 | var tech = settings.tech;
|
1972 | var requestOptions = settings.requestOptions;
|
1973 | var segmentLoader = settings.segmentLoaders[type];
|
1974 | var mediaType = settings.mediaTypes[type];
|
1975 |
|
1976 | playlistLoader.on('loadedmetadata', function () {
|
1977 | var media = playlistLoader.media();
|
1978 |
|
1979 | segmentLoader.playlist(media, requestOptions);
|
1980 | segmentLoader.track(mediaType.activeTrack());
|
1981 |
|
1982 |
|
1983 |
|
1984 | if (!tech.paused() || media.endList && tech.preload() !== 'none') {
|
1985 | segmentLoader.load();
|
1986 | }
|
1987 | });
|
1988 |
|
1989 | playlistLoader.on('loadedplaylist', function () {
|
1990 | segmentLoader.playlist(playlistLoader.media(), requestOptions);
|
1991 |
|
1992 |
|
1993 | if (!tech.paused()) {
|
1994 | segmentLoader.load();
|
1995 | }
|
1996 | });
|
1997 |
|
1998 | playlistLoader.on('error', onError[type](type, settings));
|
1999 | }
|
2000 | };
|
2001 |
|
2002 | exports.setupListeners = setupListeners;
|
2003 | var initialize = {
|
2004 | |
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 | 'AUDIO': function AUDIO(type, settings) {
|
2014 | var mode = settings.mode;
|
2015 | var hls = settings.hls;
|
2016 | var segmentLoader = settings.segmentLoaders[type];
|
2017 | var withCredentials = settings.requestOptions.withCredentials;
|
2018 | var mediaGroups = settings.master.mediaGroups;
|
2019 | var _settings$mediaTypes$type = settings.mediaTypes[type];
|
2020 | var groups = _settings$mediaTypes$type.groups;
|
2021 | var tracks = _settings$mediaTypes$type.tracks;
|
2022 |
|
2023 |
|
2024 |
|
2025 |
|
2026 | if (!mediaGroups[type] || Object.keys(mediaGroups[type]).length === 0 || mode !== 'html5') {
|
2027 | mediaGroups[type] = { main: { 'default': { 'default': true } } };
|
2028 | }
|
2029 |
|
2030 | for (var groupId in mediaGroups[type]) {
|
2031 | if (!groups[groupId]) {
|
2032 | groups[groupId] = [];
|
2033 | }
|
2034 |
|
2035 | for (var variantLabel in mediaGroups[type][groupId]) {
|
2036 | var properties = mediaGroups[type][groupId][variantLabel];
|
2037 | var playlistLoader = undefined;
|
2038 |
|
2039 | if (properties.resolvedUri) {
|
2040 | playlistLoader = new _playlistLoader2['default'](properties.resolvedUri, hls, withCredentials);
|
2041 | } else {
|
2042 |
|
2043 |
|
2044 | playlistLoader = null;
|
2045 | }
|
2046 |
|
2047 | properties = _videoJs2['default'].mergeOptions({ id: variantLabel, playlistLoader: playlistLoader }, properties);
|
2048 |
|
2049 | setupListeners[type](type, properties.playlistLoader, settings);
|
2050 |
|
2051 | groups[groupId].push(properties);
|
2052 |
|
2053 | if (typeof tracks[variantLabel] === 'undefined') {
|
2054 | var track = new _videoJs2['default'].AudioTrack({
|
2055 | id: variantLabel,
|
2056 | kind: audioTrackKind_(properties),
|
2057 | enabled: false,
|
2058 | language: properties.language,
|
2059 | 'default': properties['default'],
|
2060 | label: variantLabel
|
2061 | });
|
2062 |
|
2063 | tracks[variantLabel] = track;
|
2064 | }
|
2065 | }
|
2066 | }
|
2067 |
|
2068 |
|
2069 | segmentLoader.on('error', onError[type](type, settings));
|
2070 | },
|
2071 | |
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 | 'SUBTITLES': function SUBTITLES(type, settings) {
|
2081 | var tech = settings.tech;
|
2082 | var hls = settings.hls;
|
2083 | var segmentLoader = settings.segmentLoaders[type];
|
2084 | var withCredentials = settings.requestOptions.withCredentials;
|
2085 | var mediaGroups = settings.master.mediaGroups;
|
2086 | var _settings$mediaTypes$type2 = settings.mediaTypes[type];
|
2087 | var groups = _settings$mediaTypes$type2.groups;
|
2088 | var tracks = _settings$mediaTypes$type2.tracks;
|
2089 |
|
2090 | for (var groupId in mediaGroups[type]) {
|
2091 | if (!groups[groupId]) {
|
2092 | groups[groupId] = [];
|
2093 | }
|
2094 |
|
2095 | for (var variantLabel in mediaGroups[type][groupId]) {
|
2096 | if (mediaGroups[type][groupId][variantLabel].forced) {
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 | continue;
|
2106 | }
|
2107 |
|
2108 | var properties = mediaGroups[type][groupId][variantLabel];
|
2109 |
|
2110 | properties = _videoJs2['default'].mergeOptions({
|
2111 | id: variantLabel,
|
2112 | playlistLoader: new _playlistLoader2['default'](properties.resolvedUri, hls, withCredentials)
|
2113 | }, properties);
|
2114 |
|
2115 | setupListeners[type](type, properties.playlistLoader, settings);
|
2116 |
|
2117 | groups[groupId].push(properties);
|
2118 |
|
2119 | if (typeof tracks[variantLabel] === 'undefined') {
|
2120 | var track = tech.addRemoteTextTrack({
|
2121 | id: variantLabel,
|
2122 | kind: 'subtitles',
|
2123 | enabled: false,
|
2124 | language: properties.language,
|
2125 | label: variantLabel
|
2126 | }, false).track;
|
2127 |
|
2128 | tracks[variantLabel] = track;
|
2129 | }
|
2130 | }
|
2131 | }
|
2132 |
|
2133 |
|
2134 | segmentLoader.on('error', onError[type](type, settings));
|
2135 | },
|
2136 | |
2137 |
|
2138 |
|
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 | 'CLOSED-CAPTIONS': function CLOSEDCAPTIONS(type, settings) {
|
2146 | var tech = settings.tech;
|
2147 | var mediaGroups = settings.master.mediaGroups;
|
2148 | var _settings$mediaTypes$type3 = settings.mediaTypes[type];
|
2149 | var groups = _settings$mediaTypes$type3.groups;
|
2150 | var tracks = _settings$mediaTypes$type3.tracks;
|
2151 |
|
2152 | for (var groupId in mediaGroups[type]) {
|
2153 | if (!groups[groupId]) {
|
2154 | groups[groupId] = [];
|
2155 | }
|
2156 |
|
2157 | for (var variantLabel in mediaGroups[type][groupId]) {
|
2158 | var properties = mediaGroups[type][groupId][variantLabel];
|
2159 |
|
2160 |
|
2161 |
|
2162 | if (!properties.instreamId.match(/CC\d/)) {
|
2163 | continue;
|
2164 | }
|
2165 |
|
2166 |
|
2167 |
|
2168 | groups[groupId].push(_videoJs2['default'].mergeOptions({ id: variantLabel }, properties));
|
2169 |
|
2170 | if (typeof tracks[variantLabel] === 'undefined') {
|
2171 | var track = tech.addRemoteTextTrack({
|
2172 | id: properties.instreamId,
|
2173 | kind: 'captions',
|
2174 | enabled: false,
|
2175 | language: properties.language,
|
2176 | label: variantLabel
|
2177 | }, false).track;
|
2178 |
|
2179 | tracks[variantLabel] = track;
|
2180 | }
|
2181 | }
|
2182 | }
|
2183 | }
|
2184 | };
|
2185 |
|
2186 | exports.initialize = initialize;
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 | var activeGroup = function activeGroup(type, settings) {
|
2202 | return function (track) {
|
2203 | var masterPlaylistLoader = settings.masterPlaylistLoader;
|
2204 | var groups = settings.mediaTypes[type].groups;
|
2205 |
|
2206 | var media = masterPlaylistLoader.media();
|
2207 |
|
2208 | if (!media) {
|
2209 | return null;
|
2210 | }
|
2211 |
|
2212 | var variants = null;
|
2213 |
|
2214 | if (media.attributes[type]) {
|
2215 | variants = groups[media.attributes[type]];
|
2216 | }
|
2217 |
|
2218 | variants = variants || groups.main;
|
2219 |
|
2220 | if (typeof track === 'undefined') {
|
2221 | return variants;
|
2222 | }
|
2223 |
|
2224 | if (track === null) {
|
2225 |
|
2226 |
|
2227 | return null;
|
2228 | }
|
2229 |
|
2230 | return variants.filter(function (props) {
|
2231 | return props.id === track.id;
|
2232 | })[0] || null;
|
2233 | };
|
2234 | };
|
2235 |
|
2236 | exports.activeGroup = activeGroup;
|
2237 | var activeTrack = {
|
2238 | |
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 | AUDIO: function AUDIO(type, settings) {
|
2251 | return function () {
|
2252 | var tracks = settings.mediaTypes[type].tracks;
|
2253 |
|
2254 | for (var id in tracks) {
|
2255 | if (tracks[id].enabled) {
|
2256 | return tracks[id];
|
2257 | }
|
2258 | }
|
2259 |
|
2260 | return null;
|
2261 | };
|
2262 | },
|
2263 | |
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 | SUBTITLES: function SUBTITLES(type, settings) {
|
2276 | return function () {
|
2277 | var tracks = settings.mediaTypes[type].tracks;
|
2278 |
|
2279 | for (var id in tracks) {
|
2280 | if (tracks[id].mode === 'showing') {
|
2281 | return tracks[id];
|
2282 | }
|
2283 | }
|
2284 |
|
2285 | return null;
|
2286 | };
|
2287 | }
|
2288 | };
|
2289 |
|
2290 | exports.activeTrack = activeTrack;
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 | var setupMediaGroups = function setupMediaGroups(settings) {
|
2322 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
2323 | initialize[type](type, settings);
|
2324 | });
|
2325 |
|
2326 | var mediaTypes = settings.mediaTypes;
|
2327 | var masterPlaylistLoader = settings.masterPlaylistLoader;
|
2328 | var tech = settings.tech;
|
2329 | var hls = settings.hls;
|
2330 |
|
2331 |
|
2332 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
2333 | mediaTypes[type].activeGroup = activeGroup(type, settings);
|
2334 | mediaTypes[type].activeTrack = activeTrack[type](type, settings);
|
2335 | mediaTypes[type].onGroupChanged = onGroupChanged(type, settings);
|
2336 | mediaTypes[type].onTrackChanged = onTrackChanged(type, settings);
|
2337 | });
|
2338 |
|
2339 |
|
2340 |
|
2341 | var audioGroup = mediaTypes.AUDIO.activeGroup();
|
2342 | var groupId = (audioGroup.filter(function (group) {
|
2343 | return group['default'];
|
2344 | })[0] || audioGroup[0]).id;
|
2345 |
|
2346 | mediaTypes.AUDIO.tracks[groupId].enabled = true;
|
2347 | mediaTypes.AUDIO.onTrackChanged();
|
2348 |
|
2349 | masterPlaylistLoader.on('mediachange', function () {
|
2350 | ['AUDIO', 'SUBTITLES'].forEach(function (type) {
|
2351 | return mediaTypes[type].onGroupChanged();
|
2352 | });
|
2353 | });
|
2354 |
|
2355 |
|
2356 | var onAudioTrackChanged = function onAudioTrackChanged() {
|
2357 | mediaTypes.AUDIO.onTrackChanged();
|
2358 | tech.trigger({ type: 'usage', name: 'hls-audio-change' });
|
2359 | };
|
2360 |
|
2361 | tech.audioTracks().addEventListener('change', onAudioTrackChanged);
|
2362 | tech.remoteTextTracks().addEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
2363 |
|
2364 | hls.on('dispose', function () {
|
2365 | tech.audioTracks().removeEventListener('change', onAudioTrackChanged);
|
2366 | tech.remoteTextTracks().removeEventListener('change', mediaTypes.SUBTITLES.onTrackChanged);
|
2367 | });
|
2368 |
|
2369 |
|
2370 | tech.clearTracks('audio');
|
2371 |
|
2372 | for (var id in mediaTypes.AUDIO.tracks) {
|
2373 | tech.audioTracks().addTrack(mediaTypes.AUDIO.tracks[id]);
|
2374 | }
|
2375 | };
|
2376 |
|
2377 | exports.setupMediaGroups = setupMediaGroups;
|
2378 |
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 | var createMediaTypes = function createMediaTypes() {
|
2387 | var mediaTypes = {};
|
2388 |
|
2389 | ['AUDIO', 'SUBTITLES', 'CLOSED-CAPTIONS'].forEach(function (type) {
|
2390 | mediaTypes[type] = {
|
2391 | groups: {},
|
2392 | tracks: {},
|
2393 | activePlaylistLoader: null,
|
2394 | activeGroup: noop,
|
2395 | activeTrack: noop,
|
2396 | onGroupChanged: noop,
|
2397 | onTrackChanged: noop
|
2398 | };
|
2399 | });
|
2400 |
|
2401 | return mediaTypes;
|
2402 | };
|
2403 | exports.createMediaTypes = createMediaTypes;
|
2404 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2405 | },{"./playlist-loader":9}],7:[function(require,module,exports){
|
2406 | (function (global){
|
2407 | 'use strict';
|
2408 |
|
2409 | Object.defineProperty(exports, '__esModule', {
|
2410 | value: true
|
2411 | });
|
2412 |
|
2413 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
2414 |
|
2415 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
2416 |
|
2417 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
2418 |
|
2419 | var _binUtils = require('./bin-utils');
|
2420 |
|
2421 | var REQUEST_ERRORS = {
|
2422 | FAILURE: 2,
|
2423 | TIMEOUT: -101,
|
2424 | ABORTED: -102
|
2425 | };
|
2426 |
|
2427 | exports.REQUEST_ERRORS = REQUEST_ERRORS;
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 | var byterangeStr = function byterangeStr(byterange) {
|
2436 | var byterangeStart = undefined;
|
2437 | var byterangeEnd = undefined;
|
2438 |
|
2439 |
|
2440 |
|
2441 | byterangeEnd = byterange.offset + byterange.length - 1;
|
2442 | byterangeStart = byterange.offset;
|
2443 | return 'bytes=' + byterangeStart + '-' + byterangeEnd;
|
2444 | };
|
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 | var segmentXhrHeaders = function segmentXhrHeaders(segment) {
|
2453 | var headers = {};
|
2454 |
|
2455 | if (segment.byterange) {
|
2456 | headers.Range = byterangeStr(segment.byterange);
|
2457 | }
|
2458 | return headers;
|
2459 | };
|
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 |
|
2465 |
|
2466 | var abortAll = function abortAll(activeXhrs) {
|
2467 | activeXhrs.forEach(function (xhr) {
|
2468 | xhr.abort();
|
2469 | });
|
2470 | };
|
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 | var getRequestStats = function getRequestStats(request) {
|
2478 | return {
|
2479 | bandwidth: request.bandwidth,
|
2480 | bytesReceived: request.bytesReceived || 0,
|
2481 | roundTripTime: request.roundTripTime || 0
|
2482 | };
|
2483 | };
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 | var getProgressStats = function getProgressStats(progressEvent) {
|
2492 | var request = progressEvent.target;
|
2493 | var roundTripTime = Date.now() - request.requestTime;
|
2494 | var stats = {
|
2495 | bandwidth: Infinity,
|
2496 | bytesReceived: 0,
|
2497 | roundTripTime: roundTripTime || 0
|
2498 | };
|
2499 |
|
2500 | stats.bytesReceived = progressEvent.loaded;
|
2501 |
|
2502 |
|
2503 |
|
2504 | stats.bandwidth = Math.floor(stats.bytesReceived / stats.roundTripTime * 8 * 1000);
|
2505 |
|
2506 | return stats;
|
2507 | };
|
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 | var handleErrors = function handleErrors(error, request) {
|
2517 | if (request.timedout) {
|
2518 | return {
|
2519 | status: request.status,
|
2520 | message: 'HLS request timed-out at URL: ' + request.uri,
|
2521 | code: REQUEST_ERRORS.TIMEOUT,
|
2522 | xhr: request
|
2523 | };
|
2524 | }
|
2525 |
|
2526 | if (request.aborted) {
|
2527 | return {
|
2528 | status: request.status,
|
2529 | message: 'HLS request aborted at URL: ' + request.uri,
|
2530 | code: REQUEST_ERRORS.ABORTED,
|
2531 | xhr: request
|
2532 | };
|
2533 | }
|
2534 |
|
2535 | if (error) {
|
2536 | return {
|
2537 | status: request.status,
|
2538 | message: 'HLS request errored at URL: ' + request.uri,
|
2539 | code: REQUEST_ERRORS.FAILURE,
|
2540 | xhr: request
|
2541 | };
|
2542 | }
|
2543 |
|
2544 | return null;
|
2545 | };
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 | var handleKeyResponse = function handleKeyResponse(segment, finishProcessingFn) {
|
2557 | return function (error, request) {
|
2558 | var response = request.response;
|
2559 | var errorObj = handleErrors(error, request);
|
2560 |
|
2561 | if (errorObj) {
|
2562 | return finishProcessingFn(errorObj, segment);
|
2563 | }
|
2564 |
|
2565 | if (response.byteLength !== 16) {
|
2566 | return finishProcessingFn({
|
2567 | status: request.status,
|
2568 | message: 'Invalid HLS key at URL: ' + request.uri,
|
2569 | code: REQUEST_ERRORS.FAILURE,
|
2570 | xhr: request
|
2571 | }, segment);
|
2572 | }
|
2573 |
|
2574 | var view = new DataView(response);
|
2575 |
|
2576 | segment.key.bytes = new Uint32Array([view.getUint32(0), view.getUint32(4), view.getUint32(8), view.getUint32(12)]);
|
2577 | return finishProcessingFn(null, segment);
|
2578 | };
|
2579 | };
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 | var handleInitSegmentResponse = function handleInitSegmentResponse(segment, finishProcessingFn) {
|
2590 | return function (error, request) {
|
2591 | var response = request.response;
|
2592 | var errorObj = handleErrors(error, request);
|
2593 |
|
2594 | if (errorObj) {
|
2595 | return finishProcessingFn(errorObj, segment);
|
2596 | }
|
2597 |
|
2598 |
|
2599 | if (response.byteLength === 0) {
|
2600 | return finishProcessingFn({
|
2601 | status: request.status,
|
2602 | message: 'Empty HLS segment content at URL: ' + request.uri,
|
2603 | code: REQUEST_ERRORS.FAILURE,
|
2604 | xhr: request
|
2605 | }, segment);
|
2606 | }
|
2607 |
|
2608 | segment.map.bytes = new Uint8Array(request.response);
|
2609 | return finishProcessingFn(null, segment);
|
2610 | };
|
2611 | };
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 | var handleSegmentResponse = function handleSegmentResponse(segment, finishProcessingFn) {
|
2624 | return function (error, request) {
|
2625 | var response = request.response;
|
2626 | var errorObj = handleErrors(error, request);
|
2627 |
|
2628 | if (errorObj) {
|
2629 | return finishProcessingFn(errorObj, segment);
|
2630 | }
|
2631 |
|
2632 |
|
2633 | if (response.byteLength === 0) {
|
2634 | return finishProcessingFn({
|
2635 | status: request.status,
|
2636 | message: 'Empty HLS segment content at URL: ' + request.uri,
|
2637 | code: REQUEST_ERRORS.FAILURE,
|
2638 | xhr: request
|
2639 | }, segment);
|
2640 | }
|
2641 |
|
2642 | segment.stats = getRequestStats(request);
|
2643 |
|
2644 | if (segment.key) {
|
2645 | segment.encryptedBytes = new Uint8Array(request.response);
|
2646 | } else {
|
2647 | segment.bytes = new Uint8Array(request.response);
|
2648 | }
|
2649 |
|
2650 | return finishProcessingFn(null, segment);
|
2651 | };
|
2652 | };
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 | var decryptSegment = function decryptSegment(decrypter, segment, doneFn) {
|
2663 | var decryptionHandler = function decryptionHandler(event) {
|
2664 | if (event.data.source === segment.requestId) {
|
2665 | decrypter.removeEventListener('message', decryptionHandler);
|
2666 | var decrypted = event.data.decrypted;
|
2667 |
|
2668 | segment.bytes = new Uint8Array(decrypted.bytes, decrypted.byteOffset, decrypted.byteLength);
|
2669 | return doneFn(null, segment);
|
2670 | }
|
2671 | };
|
2672 |
|
2673 | decrypter.addEventListener('message', decryptionHandler);
|
2674 |
|
2675 |
|
2676 |
|
2677 | decrypter.postMessage((0, _binUtils.createTransferableMessage)({
|
2678 | source: segment.requestId,
|
2679 | encrypted: segment.encryptedBytes,
|
2680 | key: segment.key.bytes,
|
2681 | iv: segment.key.iv
|
2682 | }), [segment.encryptedBytes.buffer, segment.key.bytes.buffer]);
|
2683 | };
|
2684 |
|
2685 |
|
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 | var getMostImportantError = function getMostImportantError(errors) {
|
2692 | return errors.reduce(function (prev, err) {
|
2693 | return err.code > prev.code ? err : prev;
|
2694 | });
|
2695 | };
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 | var waitForCompletion = function waitForCompletion(activeXhrs, decrypter, doneFn) {
|
2709 | var errors = [];
|
2710 | var count = 0;
|
2711 |
|
2712 | return function (error, segment) {
|
2713 | if (error) {
|
2714 |
|
2715 | abortAll(activeXhrs);
|
2716 | errors.push(error);
|
2717 | }
|
2718 | count += 1;
|
2719 |
|
2720 | if (count === activeXhrs.length) {
|
2721 |
|
2722 | segment.endOfAllRequests = Date.now();
|
2723 |
|
2724 | if (errors.length > 0) {
|
2725 | var worstError = getMostImportantError(errors);
|
2726 |
|
2727 | return doneFn(worstError, segment);
|
2728 | }
|
2729 | if (segment.encryptedBytes) {
|
2730 | return decryptSegment(decrypter, segment, doneFn);
|
2731 | }
|
2732 |
|
2733 | return doneFn(null, segment);
|
2734 | }
|
2735 | };
|
2736 | };
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 |
|
2748 | var handleProgress = function handleProgress(segment, progressFn) {
|
2749 | return function (event) {
|
2750 | segment.stats = _videoJs2['default'].mergeOptions(segment.stats, getProgressStats(event));
|
2751 |
|
2752 |
|
2753 | if (!segment.stats.firstBytesReceivedAt && segment.stats.bytesReceived) {
|
2754 | segment.stats.firstBytesReceivedAt = Date.now();
|
2755 | }
|
2756 |
|
2757 | return progressFn(event, segment);
|
2758 | };
|
2759 | };
|
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 | var mediaSegmentRequest = function mediaSegmentRequest(xhr, xhrOptions, decryptionWorker, segment, progressFn, doneFn) {
|
2810 | var activeXhrs = [];
|
2811 | var finishProcessingFn = waitForCompletion(activeXhrs, decryptionWorker, doneFn);
|
2812 |
|
2813 |
|
2814 | if (segment.key) {
|
2815 | var keyRequestOptions = _videoJs2['default'].mergeOptions(xhrOptions, {
|
2816 | uri: segment.key.resolvedUri,
|
2817 | responseType: 'arraybuffer'
|
2818 | });
|
2819 | var keyRequestCallback = handleKeyResponse(segment, finishProcessingFn);
|
2820 | var keyXhr = xhr(keyRequestOptions, keyRequestCallback);
|
2821 |
|
2822 | activeXhrs.push(keyXhr);
|
2823 | }
|
2824 |
|
2825 |
|
2826 | if (segment.map && !segment.map.bytes) {
|
2827 | var initSegmentOptions = _videoJs2['default'].mergeOptions(xhrOptions, {
|
2828 | uri: segment.map.resolvedUri,
|
2829 | responseType: 'arraybuffer',
|
2830 | headers: segmentXhrHeaders(segment.map)
|
2831 | });
|
2832 | var initSegmentRequestCallback = handleInitSegmentResponse(segment, finishProcessingFn);
|
2833 | var initSegmentXhr = xhr(initSegmentOptions, initSegmentRequestCallback);
|
2834 |
|
2835 | activeXhrs.push(initSegmentXhr);
|
2836 | }
|
2837 |
|
2838 | var segmentRequestOptions = _videoJs2['default'].mergeOptions(xhrOptions, {
|
2839 | uri: segment.resolvedUri,
|
2840 | responseType: 'arraybuffer',
|
2841 | headers: segmentXhrHeaders(segment)
|
2842 | });
|
2843 | var segmentRequestCallback = handleSegmentResponse(segment, finishProcessingFn);
|
2844 | var segmentXhr = xhr(segmentRequestOptions, segmentRequestCallback);
|
2845 |
|
2846 | segmentXhr.addEventListener('progress', handleProgress(segment, progressFn));
|
2847 | activeXhrs.push(segmentXhr);
|
2848 |
|
2849 | return function () {
|
2850 | return abortAll(activeXhrs);
|
2851 | };
|
2852 | };
|
2853 | exports.mediaSegmentRequest = mediaSegmentRequest;
|
2854 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2855 | },{"./bin-utils":2}],8:[function(require,module,exports){
|
2856 | (function (global){
|
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 | 'use strict';
|
2868 |
|
2869 | Object.defineProperty(exports, '__esModule', {
|
2870 | value: true
|
2871 | });
|
2872 |
|
2873 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
2874 |
|
2875 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
2876 |
|
2877 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
2878 |
|
2879 | var _globalWindow = require('global/window');
|
2880 |
|
2881 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
2882 |
|
2883 | var _ranges = require('./ranges');
|
2884 |
|
2885 | var _ranges2 = _interopRequireDefault(_ranges);
|
2886 |
|
2887 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
2888 |
|
2889 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
2890 |
|
2891 |
|
2892 | var timerCancelEvents = ['seeking', 'seeked', 'pause', 'playing', 'error'];
|
2893 |
|
2894 |
|
2895 |
|
2896 |
|
2897 |
|
2898 | var PlaybackWatcher = (function () {
|
2899 | |
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 | function PlaybackWatcher(options) {
|
2906 | var _this = this;
|
2907 |
|
2908 | _classCallCheck(this, PlaybackWatcher);
|
2909 |
|
2910 | this.tech_ = options.tech;
|
2911 | this.seekable = options.seekable;
|
2912 |
|
2913 | this.consecutiveUpdates = 0;
|
2914 | this.lastRecordedTime = null;
|
2915 | this.timer_ = null;
|
2916 | this.checkCurrentTimeTimeout_ = null;
|
2917 |
|
2918 | if (options.debug) {
|
2919 | this.logger_ = _videoJs2['default'].log.bind(_videoJs2['default'], 'playback-watcher ->');
|
2920 | }
|
2921 | this.logger_('initialize');
|
2922 |
|
2923 | var canPlayHandler = function canPlayHandler() {
|
2924 | return _this.monitorCurrentTime_();
|
2925 | };
|
2926 | var waitingHandler = function waitingHandler() {
|
2927 | return _this.techWaiting_();
|
2928 | };
|
2929 | var cancelTimerHandler = function cancelTimerHandler() {
|
2930 | return _this.cancelTimer_();
|
2931 | };
|
2932 | var fixesBadSeeksHandler = function fixesBadSeeksHandler() {
|
2933 | return _this.fixesBadSeeks_();
|
2934 | };
|
2935 |
|
2936 | this.tech_.on('seekablechanged', fixesBadSeeksHandler);
|
2937 | this.tech_.on('waiting', waitingHandler);
|
2938 | this.tech_.on(timerCancelEvents, cancelTimerHandler);
|
2939 | this.tech_.on('canplay', canPlayHandler);
|
2940 |
|
2941 |
|
2942 | this.dispose = function () {
|
2943 | _this.logger_('dispose');
|
2944 | _this.tech_.off('seekablechanged', fixesBadSeeksHandler);
|
2945 | _this.tech_.off('waiting', waitingHandler);
|
2946 | _this.tech_.off(timerCancelEvents, cancelTimerHandler);
|
2947 | _this.tech_.off('canplay', canPlayHandler);
|
2948 | if (_this.checkCurrentTimeTimeout_) {
|
2949 | _globalWindow2['default'].clearTimeout(_this.checkCurrentTimeTimeout_);
|
2950 | }
|
2951 | _this.cancelTimer_();
|
2952 | };
|
2953 | }
|
2954 |
|
2955 | |
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 | _createClass(PlaybackWatcher, [{
|
2962 | key: 'monitorCurrentTime_',
|
2963 | value: function monitorCurrentTime_() {
|
2964 | this.checkCurrentTime_();
|
2965 |
|
2966 | if (this.checkCurrentTimeTimeout_) {
|
2967 | _globalWindow2['default'].clearTimeout(this.checkCurrentTimeTimeout_);
|
2968 | }
|
2969 |
|
2970 |
|
2971 | this.checkCurrentTimeTimeout_ = _globalWindow2['default'].setTimeout(this.monitorCurrentTime_.bind(this), 250);
|
2972 | }
|
2973 |
|
2974 | |
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 | }, {
|
2982 | key: 'checkCurrentTime_',
|
2983 | value: function checkCurrentTime_() {
|
2984 | if (this.tech_.seeking() && this.fixesBadSeeks_()) {
|
2985 | this.consecutiveUpdates = 0;
|
2986 | this.lastRecordedTime = this.tech_.currentTime();
|
2987 | return;
|
2988 | }
|
2989 |
|
2990 | if (this.tech_.paused() || this.tech_.seeking()) {
|
2991 | return;
|
2992 | }
|
2993 |
|
2994 | var currentTime = this.tech_.currentTime();
|
2995 | var buffered = this.tech_.buffered();
|
2996 |
|
2997 | if (this.lastRecordedTime === currentTime && (!buffered.length || currentTime + _ranges2['default'].SAFE_TIME_DELTA >= buffered.end(buffered.length - 1))) {
|
2998 |
|
2999 |
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 | return this.techWaiting_();
|
3006 | }
|
3007 |
|
3008 | if (this.consecutiveUpdates >= 5 && currentTime === this.lastRecordedTime) {
|
3009 | this.consecutiveUpdates++;
|
3010 | this.waiting_();
|
3011 | } else if (currentTime === this.lastRecordedTime) {
|
3012 | this.consecutiveUpdates++;
|
3013 | } else {
|
3014 | this.consecutiveUpdates = 0;
|
3015 | this.lastRecordedTime = currentTime;
|
3016 | }
|
3017 | }
|
3018 |
|
3019 | |
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 | }, {
|
3026 | key: 'cancelTimer_',
|
3027 | value: function cancelTimer_() {
|
3028 | this.consecutiveUpdates = 0;
|
3029 |
|
3030 | if (this.timer_) {
|
3031 | this.logger_('cancelTimer_');
|
3032 | clearTimeout(this.timer_);
|
3033 | }
|
3034 |
|
3035 | this.timer_ = null;
|
3036 | }
|
3037 |
|
3038 | |
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 | }, {
|
3045 | key: 'fixesBadSeeks_',
|
3046 | value: function fixesBadSeeks_() {
|
3047 | var seeking = this.tech_.seeking();
|
3048 | var seekable = this.seekable();
|
3049 | var currentTime = this.tech_.currentTime();
|
3050 | var seekTo = undefined;
|
3051 |
|
3052 | if (seeking && this.afterSeekableWindow_(seekable, currentTime)) {
|
3053 | var seekableEnd = seekable.end(seekable.length - 1);
|
3054 |
|
3055 |
|
3056 | seekTo = seekableEnd;
|
3057 | }
|
3058 |
|
3059 | if (seeking && this.beforeSeekableWindow_(seekable, currentTime)) {
|
3060 | var seekableStart = seekable.start(0);
|
3061 |
|
3062 |
|
3063 |
|
3064 | seekTo = seekableStart + _ranges2['default'].SAFE_TIME_DELTA;
|
3065 | }
|
3066 |
|
3067 | if (typeof seekTo !== 'undefined') {
|
3068 | this.logger_('Trying to seek outside of seekable at time ' + currentTime + ' with ' + ('seekable range ' + _ranges2['default'].printableRange(seekable) + '. Seeking to ') + (seekTo + '.'));
|
3069 |
|
3070 | this.tech_.setCurrentTime(seekTo);
|
3071 | return true;
|
3072 | }
|
3073 |
|
3074 | return false;
|
3075 | }
|
3076 |
|
3077 | |
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 | }, {
|
3083 | key: 'waiting_',
|
3084 | value: function waiting_() {
|
3085 | if (this.techWaiting_()) {
|
3086 | return;
|
3087 | }
|
3088 |
|
3089 |
|
3090 | var currentTime = this.tech_.currentTime();
|
3091 | var buffered = this.tech_.buffered();
|
3092 | var currentRange = _ranges2['default'].findRange(buffered, currentTime);
|
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 |
|
3102 | if (currentRange.length && currentTime + 3 <= currentRange.end(0)) {
|
3103 | this.cancelTimer_();
|
3104 | this.tech_.setCurrentTime(currentTime);
|
3105 |
|
3106 | 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.');
|
3107 |
|
3108 |
|
3109 | this.tech_.trigger({ type: 'usage', name: 'hls-unknown-waiting' });
|
3110 | return;
|
3111 | }
|
3112 | }
|
3113 |
|
3114 | |
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 | }, {
|
3123 | key: 'techWaiting_',
|
3124 | value: function techWaiting_() {
|
3125 | var seekable = this.seekable();
|
3126 | var currentTime = this.tech_.currentTime();
|
3127 |
|
3128 | if (this.tech_.seeking() && this.fixesBadSeeks_()) {
|
3129 |
|
3130 | return true;
|
3131 | }
|
3132 |
|
3133 | if (this.tech_.seeking() || this.timer_ !== null) {
|
3134 |
|
3135 | return true;
|
3136 | }
|
3137 |
|
3138 | if (this.beforeSeekableWindow_(seekable, currentTime)) {
|
3139 | var livePoint = seekable.end(seekable.length - 1);
|
3140 |
|
3141 | this.logger_('Fell out of live window at time ' + currentTime + '. Seeking to ' + ('live point (seekable end) ' + livePoint));
|
3142 | this.cancelTimer_();
|
3143 | this.tech_.setCurrentTime(livePoint);
|
3144 |
|
3145 |
|
3146 | this.tech_.trigger({ type: 'usage', name: 'hls-live-resync' });
|
3147 | return true;
|
3148 | }
|
3149 |
|
3150 | var buffered = this.tech_.buffered();
|
3151 | var nextRange = _ranges2['default'].findNextRange(buffered, currentTime);
|
3152 |
|
3153 | if (this.videoUnderflow_(nextRange, buffered, currentTime)) {
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 | this.cancelTimer_();
|
3159 | this.tech_.setCurrentTime(currentTime);
|
3160 |
|
3161 |
|
3162 | this.tech_.trigger({ type: 'usage', name: 'hls-video-underflow' });
|
3163 | return true;
|
3164 | }
|
3165 |
|
3166 |
|
3167 | if (nextRange.length > 0) {
|
3168 | var difference = nextRange.start(0) - currentTime;
|
3169 |
|
3170 | this.logger_('Stopped at ' + currentTime + ', setting timer for ' + difference + ', seeking ' + ('to ' + nextRange.start(0)));
|
3171 |
|
3172 | this.timer_ = setTimeout(this.skipTheGap_.bind(this), difference * 1000, currentTime);
|
3173 | return true;
|
3174 | }
|
3175 |
|
3176 |
|
3177 | return false;
|
3178 | }
|
3179 | }, {
|
3180 | key: 'afterSeekableWindow_',
|
3181 | value: function afterSeekableWindow_(seekable, currentTime) {
|
3182 | if (!seekable.length) {
|
3183 |
|
3184 | return false;
|
3185 | }
|
3186 |
|
3187 | if (currentTime > seekable.end(seekable.length - 1) + _ranges2['default'].SAFE_TIME_DELTA) {
|
3188 | return true;
|
3189 | }
|
3190 |
|
3191 | return false;
|
3192 | }
|
3193 | }, {
|
3194 | key: 'beforeSeekableWindow_',
|
3195 | value: function beforeSeekableWindow_(seekable, currentTime) {
|
3196 | if (seekable.length &&
|
3197 |
|
3198 | seekable.start(0) > 0 && currentTime < seekable.start(0) - _ranges2['default'].SAFE_TIME_DELTA) {
|
3199 | return true;
|
3200 | }
|
3201 |
|
3202 | return false;
|
3203 | }
|
3204 | }, {
|
3205 | key: 'videoUnderflow_',
|
3206 | value: function videoUnderflow_(nextRange, buffered, currentTime) {
|
3207 | if (nextRange.length === 0) {
|
3208 |
|
3209 |
|
3210 | var gap = this.gapFromVideoUnderflow_(buffered, currentTime);
|
3211 |
|
3212 | if (gap) {
|
3213 | this.logger_('Encountered a gap in video from ' + gap.start + ' to ' + gap.end + '. ' + ('Seeking to current time ' + currentTime));
|
3214 |
|
3215 | return true;
|
3216 | }
|
3217 | }
|
3218 |
|
3219 | return false;
|
3220 | }
|
3221 |
|
3222 | |
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 | }, {
|
3229 | key: 'skipTheGap_',
|
3230 | value: function skipTheGap_(scheduledCurrentTime) {
|
3231 | var buffered = this.tech_.buffered();
|
3232 | var currentTime = this.tech_.currentTime();
|
3233 | var nextRange = _ranges2['default'].findNextRange(buffered, currentTime);
|
3234 |
|
3235 | this.cancelTimer_();
|
3236 |
|
3237 | if (nextRange.length === 0 || currentTime !== scheduledCurrentTime) {
|
3238 | return;
|
3239 | }
|
3240 |
|
3241 | this.logger_('skipTheGap_:', 'currentTime:', currentTime, 'scheduled currentTime:', scheduledCurrentTime, 'nextRange start:', nextRange.start(0));
|
3242 |
|
3243 |
|
3244 | this.tech_.setCurrentTime(nextRange.start(0) + _ranges2['default'].TIME_FUDGE_FACTOR);
|
3245 |
|
3246 | this.tech_.trigger({ type: 'usage', name: 'hls-gap-skip' });
|
3247 | }
|
3248 | }, {
|
3249 | key: 'gapFromVideoUnderflow_',
|
3250 | value: function gapFromVideoUnderflow_(buffered, currentTime) {
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 | var gaps = _ranges2['default'].findGaps(buffered);
|
3274 |
|
3275 | for (var i = 0; i < gaps.length; i++) {
|
3276 | var start = gaps.start(i);
|
3277 | var end = gaps.end(i);
|
3278 |
|
3279 |
|
3280 | if (currentTime - start < 4 && currentTime - start > 2) {
|
3281 | return {
|
3282 | start: start,
|
3283 | end: end
|
3284 | };
|
3285 | }
|
3286 | }
|
3287 |
|
3288 | return null;
|
3289 | }
|
3290 |
|
3291 | |
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 | }, {
|
3298 | key: 'logger_',
|
3299 | value: function logger_() {}
|
3300 | }]);
|
3301 |
|
3302 | return PlaybackWatcher;
|
3303 | })();
|
3304 |
|
3305 | exports['default'] = PlaybackWatcher;
|
3306 | module.exports = exports['default'];
|
3307 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3308 | },{"./ranges":12,"global/window":32}],9:[function(require,module,exports){
|
3309 | (function (global){
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 | 'use strict';
|
3318 |
|
3319 | Object.defineProperty(exports, '__esModule', {
|
3320 | value: true
|
3321 | });
|
3322 |
|
3323 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
3324 |
|
3325 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
3326 |
|
3327 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
3328 |
|
3329 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
3330 |
|
3331 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
3332 |
|
3333 | var _resolveUrl = require('./resolve-url');
|
3334 |
|
3335 | var _resolveUrl2 = _interopRequireDefault(_resolveUrl);
|
3336 |
|
3337 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
3338 |
|
3339 | var _playlistJs = require('./playlist.js');
|
3340 |
|
3341 | var _m3u8Parser = require('m3u8-parser');
|
3342 |
|
3343 | var _m3u8Parser2 = _interopRequireDefault(_m3u8Parser);
|
3344 |
|
3345 | var _globalWindow = require('global/window');
|
3346 |
|
3347 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 |
|
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 | var updateSegments = function updateSegments(original, update, offset) {
|
3365 | var result = update.slice();
|
3366 |
|
3367 | offset = offset || 0;
|
3368 | var length = Math.min(original.length, update.length + offset);
|
3369 |
|
3370 | for (var i = offset; i < length; i++) {
|
3371 | result[i - offset] = (0, _videoJs.mergeOptions)(original[i], result[i - offset]);
|
3372 | }
|
3373 | return result;
|
3374 | };
|
3375 |
|
3376 | exports.updateSegments = updateSegments;
|
3377 |
|
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 | var updateMaster = function updateMaster(master, media) {
|
3390 | var result = (0, _videoJs.mergeOptions)(master, {});
|
3391 | var playlist = result.playlists.filter(function (p) {
|
3392 | return p.uri === media.uri;
|
3393 | })[0];
|
3394 |
|
3395 | if (!playlist) {
|
3396 | return null;
|
3397 | }
|
3398 |
|
3399 |
|
3400 |
|
3401 | if (playlist.segments && media.segments && playlist.segments.length === media.segments.length && playlist.mediaSequence === media.mediaSequence) {
|
3402 | return null;
|
3403 | }
|
3404 |
|
3405 | var mergedPlaylist = (0, _videoJs.mergeOptions)(playlist, media);
|
3406 |
|
3407 |
|
3408 | if (playlist.segments) {
|
3409 | mergedPlaylist.segments = updateSegments(playlist.segments, media.segments, media.mediaSequence - playlist.mediaSequence);
|
3410 | }
|
3411 |
|
3412 |
|
3413 | mergedPlaylist.segments.forEach(function (segment) {
|
3414 | if (!segment.resolvedUri) {
|
3415 | segment.resolvedUri = (0, _resolveUrl2['default'])(mergedPlaylist.resolvedUri, segment.uri);
|
3416 | }
|
3417 | if (segment.key && !segment.key.resolvedUri) {
|
3418 | segment.key.resolvedUri = (0, _resolveUrl2['default'])(mergedPlaylist.resolvedUri, segment.key.uri);
|
3419 | }
|
3420 | if (segment.map && !segment.map.resolvedUri) {
|
3421 | segment.map.resolvedUri = (0, _resolveUrl2['default'])(mergedPlaylist.resolvedUri, segment.map.uri);
|
3422 | }
|
3423 | });
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 | for (var i = 0; i < result.playlists.length; i++) {
|
3429 | if (result.playlists[i].uri === media.uri) {
|
3430 | result.playlists[i] = mergedPlaylist;
|
3431 | }
|
3432 | }
|
3433 | result.playlists[media.uri] = mergedPlaylist;
|
3434 |
|
3435 | return result;
|
3436 | };
|
3437 |
|
3438 | exports.updateMaster = updateMaster;
|
3439 | var setupMediaPlaylists = function setupMediaPlaylists(master) {
|
3440 |
|
3441 | var i = master.playlists.length;
|
3442 |
|
3443 | while (i--) {
|
3444 | var playlist = master.playlists[i];
|
3445 |
|
3446 | master.playlists[playlist.uri] = playlist;
|
3447 | playlist.resolvedUri = (0, _resolveUrl2['default'])(master.uri, playlist.uri);
|
3448 |
|
3449 | if (!playlist.attributes) {
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 | playlist.attributes = {};
|
3456 |
|
3457 | _videoJs.log.warn('Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute.');
|
3458 | }
|
3459 | }
|
3460 | };
|
3461 |
|
3462 | exports.setupMediaPlaylists = setupMediaPlaylists;
|
3463 | var resolveMediaGroupUris = function resolveMediaGroupUris(master) {
|
3464 | ['AUDIO', 'SUBTITLES'].forEach(function (mediaType) {
|
3465 | for (var groupKey in master.mediaGroups[mediaType]) {
|
3466 | for (var labelKey in master.mediaGroups[mediaType][groupKey]) {
|
3467 | var mediaProperties = master.mediaGroups[mediaType][groupKey][labelKey];
|
3468 |
|
3469 | if (mediaProperties.uri) {
|
3470 | mediaProperties.resolvedUri = (0, _resolveUrl2['default'])(master.uri, mediaProperties.uri);
|
3471 | }
|
3472 | }
|
3473 | }
|
3474 | });
|
3475 | };
|
3476 |
|
3477 | exports.resolveMediaGroupUris = resolveMediaGroupUris;
|
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 |
|
3488 | var refreshDelay = function refreshDelay(media, update) {
|
3489 | var lastSegment = media.segments[media.segments.length - 1];
|
3490 | var delay = undefined;
|
3491 |
|
3492 | if (update && lastSegment && lastSegment.duration) {
|
3493 | delay = lastSegment.duration * 1000;
|
3494 | } else {
|
3495 |
|
3496 |
|
3497 | delay = (media.targetDuration || 10) * 500;
|
3498 | }
|
3499 | return delay;
|
3500 | };
|
3501 |
|
3502 | exports.refreshDelay = refreshDelay;
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 |
|
3512 |
|
3513 | var PlaylistLoader = (function (_EventTarget) {
|
3514 | _inherits(PlaylistLoader, _EventTarget);
|
3515 |
|
3516 | function PlaylistLoader(srcUrl, hls, withCredentials) {
|
3517 | var _this = this;
|
3518 |
|
3519 | _classCallCheck(this, PlaylistLoader);
|
3520 |
|
3521 | _get(Object.getPrototypeOf(PlaylistLoader.prototype), 'constructor', this).call(this);
|
3522 |
|
3523 | this.srcUrl = srcUrl;
|
3524 | this.hls_ = hls;
|
3525 | this.withCredentials = withCredentials;
|
3526 |
|
3527 | if (!this.srcUrl) {
|
3528 | throw new Error('A non-empty playlist URL is required');
|
3529 | }
|
3530 |
|
3531 |
|
3532 | this.state = 'HAVE_NOTHING';
|
3533 |
|
3534 |
|
3535 | this.on('mediaupdatetimeout', function () {
|
3536 | if (_this.state !== 'HAVE_METADATA') {
|
3537 |
|
3538 | return;
|
3539 | }
|
3540 |
|
3541 | _this.state = 'HAVE_CURRENT_METADATA';
|
3542 |
|
3543 | _this.request = _this.hls_.xhr({
|
3544 | uri: (0, _resolveUrl2['default'])(_this.master.uri, _this.media().uri),
|
3545 | withCredentials: _this.withCredentials
|
3546 | }, function (error, req) {
|
3547 |
|
3548 | if (!_this.request) {
|
3549 | return;
|
3550 | }
|
3551 |
|
3552 | if (error) {
|
3553 | return _this.playlistRequestError(_this.request, _this.media().uri, 'HAVE_METADATA');
|
3554 | }
|
3555 |
|
3556 | _this.haveMetadata(_this.request, _this.media().uri);
|
3557 | });
|
3558 | });
|
3559 | }
|
3560 |
|
3561 | _createClass(PlaylistLoader, [{
|
3562 | key: 'playlistRequestError',
|
3563 | value: function playlistRequestError(xhr, url, startingState) {
|
3564 |
|
3565 | this.request = null;
|
3566 |
|
3567 | if (startingState) {
|
3568 | this.state = startingState;
|
3569 | }
|
3570 |
|
3571 | this.error = {
|
3572 | playlist: this.master.playlists[url],
|
3573 | status: xhr.status,
|
3574 | message: 'HLS playlist request error at URL: ' + url,
|
3575 | responseText: xhr.responseText,
|
3576 | code: xhr.status >= 500 ? 4 : 2
|
3577 | };
|
3578 |
|
3579 | this.trigger('error');
|
3580 | }
|
3581 |
|
3582 |
|
3583 |
|
3584 | }, {
|
3585 | key: 'haveMetadata',
|
3586 | value: function haveMetadata(xhr, url) {
|
3587 | var _this2 = this;
|
3588 |
|
3589 |
|
3590 | this.request = null;
|
3591 | this.state = 'HAVE_METADATA';
|
3592 |
|
3593 | var parser = new _m3u8Parser2['default'].Parser();
|
3594 |
|
3595 | parser.push(xhr.responseText);
|
3596 | parser.end();
|
3597 | parser.manifest.uri = url;
|
3598 |
|
3599 |
|
3600 | parser.manifest.attributes = parser.manifest.attributes || {};
|
3601 |
|
3602 |
|
3603 | var update = updateMaster(this.master, parser.manifest);
|
3604 |
|
3605 | this.targetDuration = parser.manifest.targetDuration;
|
3606 |
|
3607 | if (update) {
|
3608 | this.master = update;
|
3609 | this.media_ = this.master.playlists[parser.manifest.uri];
|
3610 | } else {
|
3611 | this.trigger('playlistunchanged');
|
3612 | }
|
3613 |
|
3614 |
|
3615 | if (!this.media().endList) {
|
3616 | _globalWindow2['default'].clearTimeout(this.mediaUpdateTimeout);
|
3617 | this.mediaUpdateTimeout = _globalWindow2['default'].setTimeout(function () {
|
3618 | _this2.trigger('mediaupdatetimeout');
|
3619 | }, refreshDelay(this.media(), !!update));
|
3620 | }
|
3621 |
|
3622 | this.trigger('loadedplaylist');
|
3623 | }
|
3624 |
|
3625 | |
3626 |
|
3627 |
|
3628 | }, {
|
3629 | key: 'dispose',
|
3630 | value: function dispose() {
|
3631 | this.stopRequest();
|
3632 | _globalWindow2['default'].clearTimeout(this.mediaUpdateTimeout);
|
3633 | }
|
3634 | }, {
|
3635 | key: 'stopRequest',
|
3636 | value: function stopRequest() {
|
3637 | if (this.request) {
|
3638 | var oldRequest = this.request;
|
3639 |
|
3640 | this.request = null;
|
3641 | oldRequest.onreadystatechange = null;
|
3642 | oldRequest.abort();
|
3643 | }
|
3644 | }
|
3645 |
|
3646 | |
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 | }, {
|
3652 | key: 'enabledPlaylists_',
|
3653 | value: function enabledPlaylists_() {
|
3654 | return this.master.playlists.filter(_playlistJs.isEnabled).length;
|
3655 | }
|
3656 |
|
3657 | |
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 | }, {
|
3663 | key: 'isLowestEnabledRendition_',
|
3664 | value: function isLowestEnabledRendition_() {
|
3665 | if (this.master.playlists.length === 1) {
|
3666 | return true;
|
3667 | }
|
3668 |
|
3669 | var currentBandwidth = this.media().attributes.BANDWIDTH || Number.MAX_VALUE;
|
3670 |
|
3671 | return this.master.playlists.filter(function (playlist) {
|
3672 | if (!(0, _playlistJs.isEnabled)(playlist)) {
|
3673 | return false;
|
3674 | }
|
3675 |
|
3676 | return (playlist.attributes.BANDWIDTH || 0) < currentBandwidth;
|
3677 | }).length === 0;
|
3678 | }
|
3679 |
|
3680 | |
3681 |
|
3682 |
|
3683 |
|
3684 |
|
3685 | }, {
|
3686 | key: 'isFinalRendition_',
|
3687 | value: function isFinalRendition_() {
|
3688 | return this.master.playlists.filter(_playlistJs.isEnabled).length === 1;
|
3689 | }
|
3690 |
|
3691 | |
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 |
|
3700 |
|
3701 |
|
3702 |
|
3703 | }, {
|
3704 | key: 'media',
|
3705 | value: function media(playlist) {
|
3706 | var _this3 = this;
|
3707 |
|
3708 |
|
3709 | if (!playlist) {
|
3710 | return this.media_;
|
3711 | }
|
3712 |
|
3713 |
|
3714 | if (this.state === 'HAVE_NOTHING') {
|
3715 | throw new Error('Cannot switch media playlist from ' + this.state);
|
3716 | }
|
3717 |
|
3718 | var startingState = this.state;
|
3719 |
|
3720 |
|
3721 |
|
3722 | if (typeof playlist === 'string') {
|
3723 | if (!this.master.playlists[playlist]) {
|
3724 | throw new Error('Unknown playlist URI: ' + playlist);
|
3725 | }
|
3726 | playlist = this.master.playlists[playlist];
|
3727 | }
|
3728 |
|
3729 | var mediaChange = !this.media_ || playlist.uri !== this.media_.uri;
|
3730 |
|
3731 |
|
3732 | if (this.master.playlists[playlist.uri].endList) {
|
3733 |
|
3734 | if (this.request) {
|
3735 | this.request.onreadystatechange = null;
|
3736 | this.request.abort();
|
3737 | this.request = null;
|
3738 | }
|
3739 | this.state = 'HAVE_METADATA';
|
3740 | this.media_ = playlist;
|
3741 |
|
3742 |
|
3743 | if (mediaChange) {
|
3744 | this.trigger('mediachanging');
|
3745 | this.trigger('mediachange');
|
3746 | }
|
3747 | return;
|
3748 | }
|
3749 |
|
3750 |
|
3751 | if (!mediaChange) {
|
3752 | return;
|
3753 | }
|
3754 |
|
3755 | this.state = 'SWITCHING_MEDIA';
|
3756 |
|
3757 |
|
3758 | if (this.request) {
|
3759 | if ((0, _resolveUrl2['default'])(this.master.uri, playlist.uri) === this.request.url) {
|
3760 |
|
3761 |
|
3762 | return;
|
3763 | }
|
3764 | this.request.onreadystatechange = null;
|
3765 | this.request.abort();
|
3766 | this.request = null;
|
3767 | }
|
3768 |
|
3769 |
|
3770 | if (this.media_) {
|
3771 | this.trigger('mediachanging');
|
3772 | }
|
3773 |
|
3774 | this.request = this.hls_.xhr({
|
3775 | uri: (0, _resolveUrl2['default'])(this.master.uri, playlist.uri),
|
3776 | withCredentials: this.withCredentials
|
3777 | }, function (error, req) {
|
3778 |
|
3779 | if (!_this3.request) {
|
3780 | return;
|
3781 | }
|
3782 |
|
3783 | if (error) {
|
3784 | return _this3.playlistRequestError(_this3.request, playlist.uri, startingState);
|
3785 | }
|
3786 |
|
3787 | _this3.haveMetadata(req, playlist.uri);
|
3788 |
|
3789 |
|
3790 | if (startingState === 'HAVE_MASTER') {
|
3791 | _this3.trigger('loadedmetadata');
|
3792 | } else {
|
3793 | _this3.trigger('mediachange');
|
3794 | }
|
3795 | });
|
3796 | }
|
3797 |
|
3798 | |
3799 |
|
3800 |
|
3801 | }, {
|
3802 | key: 'pause',
|
3803 | value: function pause() {
|
3804 | this.stopRequest();
|
3805 | _globalWindow2['default'].clearTimeout(this.mediaUpdateTimeout);
|
3806 | if (this.state === 'HAVE_NOTHING') {
|
3807 |
|
3808 |
|
3809 | this.started = false;
|
3810 | }
|
3811 |
|
3812 | if (this.state === 'SWITCHING_MEDIA') {
|
3813 |
|
3814 |
|
3815 |
|
3816 | if (this.media_) {
|
3817 | this.state = 'HAVE_METADATA';
|
3818 | } else {
|
3819 | this.state = 'HAVE_MASTER';
|
3820 | }
|
3821 | } else if (this.state === 'HAVE_CURRENT_METADATA') {
|
3822 | this.state = 'HAVE_METADATA';
|
3823 | }
|
3824 | }
|
3825 |
|
3826 | |
3827 |
|
3828 |
|
3829 | }, {
|
3830 | key: 'load',
|
3831 | value: function load(isFinalRendition) {
|
3832 | var _this4 = this;
|
3833 |
|
3834 | _globalWindow2['default'].clearTimeout(this.mediaUpdateTimeout);
|
3835 |
|
3836 | var media = this.media();
|
3837 |
|
3838 | if (isFinalRendition) {
|
3839 | var delay = media ? media.targetDuration / 2 * 1000 : 5 * 1000;
|
3840 |
|
3841 | this.mediaUpdateTimeout = _globalWindow2['default'].setTimeout(function () {
|
3842 | return _this4.load();
|
3843 | }, delay);
|
3844 | return;
|
3845 | }
|
3846 |
|
3847 | if (!this.started) {
|
3848 | this.start();
|
3849 | return;
|
3850 | }
|
3851 |
|
3852 | if (media && !media.endList) {
|
3853 | this.trigger('mediaupdatetimeout');
|
3854 | } else {
|
3855 | this.trigger('loadedplaylist');
|
3856 | }
|
3857 | }
|
3858 |
|
3859 | |
3860 |
|
3861 |
|
3862 | }, {
|
3863 | key: 'start',
|
3864 | value: function start() {
|
3865 | var _this5 = this;
|
3866 |
|
3867 | this.started = true;
|
3868 |
|
3869 |
|
3870 | this.request = this.hls_.xhr({
|
3871 | uri: this.srcUrl,
|
3872 | withCredentials: this.withCredentials
|
3873 | }, function (error, req) {
|
3874 |
|
3875 | if (!_this5.request) {
|
3876 | return;
|
3877 | }
|
3878 |
|
3879 |
|
3880 | _this5.request = null;
|
3881 |
|
3882 | if (error) {
|
3883 | _this5.error = {
|
3884 | status: req.status,
|
3885 | message: 'HLS playlist request error at URL: ' + _this5.srcUrl,
|
3886 | responseText: req.responseText,
|
3887 |
|
3888 | code: 2
|
3889 | };
|
3890 | if (_this5.state === 'HAVE_NOTHING') {
|
3891 | _this5.started = false;
|
3892 | }
|
3893 | return _this5.trigger('error');
|
3894 | }
|
3895 |
|
3896 | var parser = new _m3u8Parser2['default'].Parser();
|
3897 |
|
3898 | parser.push(req.responseText);
|
3899 | parser.end();
|
3900 |
|
3901 | _this5.state = 'HAVE_MASTER';
|
3902 |
|
3903 | parser.manifest.uri = _this5.srcUrl;
|
3904 |
|
3905 |
|
3906 | if (parser.manifest.playlists) {
|
3907 | _this5.master = parser.manifest;
|
3908 |
|
3909 | setupMediaPlaylists(_this5.master);
|
3910 | resolveMediaGroupUris(_this5.master);
|
3911 |
|
3912 | _this5.trigger('loadedplaylist');
|
3913 | if (!_this5.request) {
|
3914 |
|
3915 |
|
3916 | _this5.media(parser.manifest.playlists[0]);
|
3917 | }
|
3918 | return;
|
3919 | }
|
3920 |
|
3921 |
|
3922 |
|
3923 | _this5.master = {
|
3924 | mediaGroups: {
|
3925 | 'AUDIO': {},
|
3926 | 'VIDEO': {},
|
3927 | 'CLOSED-CAPTIONS': {},
|
3928 | 'SUBTITLES': {}
|
3929 | },
|
3930 | uri: _globalWindow2['default'].location.href,
|
3931 | playlists: [{
|
3932 | uri: _this5.srcUrl
|
3933 | }]
|
3934 | };
|
3935 | _this5.master.playlists[_this5.srcUrl] = _this5.master.playlists[0];
|
3936 | _this5.master.playlists[0].resolvedUri = _this5.srcUrl;
|
3937 |
|
3938 |
|
3939 | _this5.master.playlists[0].attributes = _this5.master.playlists[0].attributes || {};
|
3940 | _this5.haveMetadata(req, _this5.srcUrl);
|
3941 | return _this5.trigger('loadedmetadata');
|
3942 | });
|
3943 | }
|
3944 | }]);
|
3945 |
|
3946 | return PlaylistLoader;
|
3947 | })(_videoJs.EventTarget);
|
3948 |
|
3949 | exports['default'] = PlaylistLoader;
|
3950 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3951 | },{"./playlist.js":11,"./resolve-url":15,"global/window":32,"m3u8-parser":33}],10:[function(require,module,exports){
|
3952 | 'use strict';
|
3953 |
|
3954 | Object.defineProperty(exports, '__esModule', {
|
3955 | value: true
|
3956 | });
|
3957 |
|
3958 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
3959 |
|
3960 | var _config = require('./config');
|
3961 |
|
3962 | var _config2 = _interopRequireDefault(_config);
|
3963 |
|
3964 | var _playlist = require('./playlist');
|
3965 |
|
3966 | var _playlist2 = _interopRequireDefault(_playlist);
|
3967 |
|
3968 | var _utilCodecsJs = require('./util/codecs.js');
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 | var safeGetComputedStyle = function safeGetComputedStyle(el, property) {
|
3983 | var result = undefined;
|
3984 |
|
3985 | if (!el) {
|
3986 | return '';
|
3987 | }
|
3988 |
|
3989 | result = window.getComputedStyle(el);
|
3990 | if (!result) {
|
3991 | return '';
|
3992 | }
|
3993 |
|
3994 | return result[property];
|
3995 | };
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 |
|
4004 | var stableSort = function stableSort(array, sortFn) {
|
4005 | var newArray = array.slice();
|
4006 |
|
4007 | array.sort(function (left, right) {
|
4008 | var cmp = sortFn(left, right);
|
4009 |
|
4010 | if (cmp === 0) {
|
4011 | return newArray.indexOf(left) - newArray.indexOf(right);
|
4012 | }
|
4013 | return cmp;
|
4014 | });
|
4015 | };
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 |
|
4025 |
|
4026 |
|
4027 | var comparePlaylistBandwidth = function comparePlaylistBandwidth(left, right) {
|
4028 | var leftBandwidth = undefined;
|
4029 | var rightBandwidth = undefined;
|
4030 |
|
4031 | if (left.attributes.BANDWIDTH) {
|
4032 | leftBandwidth = left.attributes.BANDWIDTH;
|
4033 | }
|
4034 | leftBandwidth = leftBandwidth || window.Number.MAX_VALUE;
|
4035 | if (right.attributes.BANDWIDTH) {
|
4036 | rightBandwidth = right.attributes.BANDWIDTH;
|
4037 | }
|
4038 | rightBandwidth = rightBandwidth || window.Number.MAX_VALUE;
|
4039 |
|
4040 | return leftBandwidth - rightBandwidth;
|
4041 | };
|
4042 |
|
4043 | exports.comparePlaylistBandwidth = comparePlaylistBandwidth;
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 |
|
4050 |
|
4051 |
|
4052 |
|
4053 | var comparePlaylistResolution = function comparePlaylistResolution(left, right) {
|
4054 | var leftWidth = undefined;
|
4055 | var rightWidth = undefined;
|
4056 |
|
4057 | if (left.attributes.RESOLUTION && left.attributes.RESOLUTION.width) {
|
4058 | leftWidth = left.attributes.RESOLUTION.width;
|
4059 | }
|
4060 |
|
4061 | leftWidth = leftWidth || window.Number.MAX_VALUE;
|
4062 |
|
4063 | if (right.attributes.RESOLUTION && right.attributes.RESOLUTION.width) {
|
4064 | rightWidth = right.attributes.RESOLUTION.width;
|
4065 | }
|
4066 |
|
4067 | rightWidth = rightWidth || window.Number.MAX_VALUE;
|
4068 |
|
4069 |
|
4070 |
|
4071 | if (leftWidth === rightWidth && left.attributes.BANDWIDTH && right.attributes.BANDWIDTH) {
|
4072 | return left.attributes.BANDWIDTH - right.attributes.BANDWIDTH;
|
4073 | }
|
4074 | return leftWidth - rightWidth;
|
4075 | };
|
4076 |
|
4077 | exports.comparePlaylistResolution = comparePlaylistResolution;
|
4078 |
|
4079 |
|
4080 |
|
4081 |
|
4082 |
|
4083 |
|
4084 |
|
4085 |
|
4086 |
|
4087 |
|
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 | var simpleSelector = function simpleSelector(master, playerBandwidth, playerWidth, playerHeight) {
|
4094 |
|
4095 | var sortedPlaylistReps = master.playlists.map(function (playlist) {
|
4096 | var width = undefined;
|
4097 | var height = undefined;
|
4098 | var bandwidth = undefined;
|
4099 |
|
4100 | width = playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width;
|
4101 | height = playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.height;
|
4102 | bandwidth = playlist.attributes.BANDWIDTH;
|
4103 |
|
4104 | bandwidth = bandwidth || window.Number.MAX_VALUE;
|
4105 |
|
4106 | return {
|
4107 | bandwidth: bandwidth,
|
4108 | width: width,
|
4109 | height: height,
|
4110 | playlist: playlist
|
4111 | };
|
4112 | });
|
4113 |
|
4114 | stableSort(sortedPlaylistReps, function (left, right) {
|
4115 | return left.bandwidth - right.bandwidth;
|
4116 | });
|
4117 |
|
4118 |
|
4119 |
|
4120 | sortedPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
4121 | return !_playlist2['default'].isIncompatible(rep.playlist);
|
4122 | });
|
4123 |
|
4124 |
|
4125 |
|
4126 | var enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
4127 | return _playlist2['default'].isEnabled(rep.playlist);
|
4128 | });
|
4129 |
|
4130 | if (!enabledPlaylistReps.length) {
|
4131 |
|
4132 |
|
4133 |
|
4134 | enabledPlaylistReps = sortedPlaylistReps.filter(function (rep) {
|
4135 | return !_playlist2['default'].isDisabled(rep.playlist);
|
4136 | });
|
4137 | }
|
4138 |
|
4139 |
|
4140 |
|
4141 | var bandwidthPlaylistReps = enabledPlaylistReps.filter(function (rep) {
|
4142 | return rep.bandwidth * _config2['default'].BANDWIDTH_VARIANCE < playerBandwidth;
|
4143 | });
|
4144 |
|
4145 | var highestRemainingBandwidthRep = bandwidthPlaylistReps[bandwidthPlaylistReps.length - 1];
|
4146 |
|
4147 |
|
4148 |
|
4149 | var bandwidthBestRep = bandwidthPlaylistReps.filter(function (rep) {
|
4150 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
4151 | })[0];
|
4152 |
|
4153 |
|
4154 | var haveResolution = bandwidthPlaylistReps.filter(function (rep) {
|
4155 | return rep.width && rep.height;
|
4156 | });
|
4157 |
|
4158 |
|
4159 | stableSort(haveResolution, function (left, right) {
|
4160 | return left.width - right.width;
|
4161 | });
|
4162 |
|
4163 |
|
4164 | var resolutionBestRepList = haveResolution.filter(function (rep) {
|
4165 | return rep.width === playerWidth && rep.height === playerHeight;
|
4166 | });
|
4167 |
|
4168 | highestRemainingBandwidthRep = resolutionBestRepList[resolutionBestRepList.length - 1];
|
4169 |
|
4170 | var resolutionBestRep = resolutionBestRepList.filter(function (rep) {
|
4171 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
4172 | })[0];
|
4173 |
|
4174 | var resolutionPlusOneList = undefined;
|
4175 | var resolutionPlusOneSmallest = undefined;
|
4176 | var resolutionPlusOneRep = undefined;
|
4177 |
|
4178 |
|
4179 |
|
4180 | if (!resolutionBestRep) {
|
4181 | resolutionPlusOneList = haveResolution.filter(function (rep) {
|
4182 | return rep.width > playerWidth || rep.height > playerHeight;
|
4183 | });
|
4184 |
|
4185 |
|
4186 | resolutionPlusOneSmallest = resolutionPlusOneList.filter(function (rep) {
|
4187 | return rep.width === resolutionPlusOneList[0].width && rep.height === resolutionPlusOneList[0].height;
|
4188 | });
|
4189 |
|
4190 |
|
4191 |
|
4192 | highestRemainingBandwidthRep = resolutionPlusOneSmallest[resolutionPlusOneSmallest.length - 1];
|
4193 | resolutionPlusOneRep = resolutionPlusOneSmallest.filter(function (rep) {
|
4194 | return rep.bandwidth === highestRemainingBandwidthRep.bandwidth;
|
4195 | })[0];
|
4196 | }
|
4197 |
|
4198 |
|
4199 | var chosenRep = resolutionPlusOneRep || resolutionBestRep || bandwidthBestRep || enabledPlaylistReps[0] || sortedPlaylistReps[0];
|
4200 |
|
4201 | return chosenRep ? chosenRep.playlist : null;
|
4202 | };
|
4203 |
|
4204 | exports.simpleSelector = simpleSelector;
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 |
|
4212 |
|
4213 |
|
4214 |
|
4215 |
|
4216 |
|
4217 | var lastBandwidthSelector = function lastBandwidthSelector() {
|
4218 | return simpleSelector(this.playlists.master, this.systemBandwidth, parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10), parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10));
|
4219 | };
|
4220 |
|
4221 | exports.lastBandwidthSelector = lastBandwidthSelector;
|
4222 |
|
4223 |
|
4224 |
|
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 |
|
4234 |
|
4235 |
|
4236 | var movingAverageBandwidthSelector = function movingAverageBandwidthSelector(decay) {
|
4237 | var average = -1;
|
4238 |
|
4239 | if (decay < 0 || decay > 1) {
|
4240 | throw new Error('Moving average bandwidth decay must be between 0 and 1.');
|
4241 | }
|
4242 |
|
4243 | return function () {
|
4244 | if (average < 0) {
|
4245 | average = this.systemBandwidth;
|
4246 | }
|
4247 |
|
4248 | average = decay * this.systemBandwidth + (1 - decay) * average;
|
4249 | return simpleSelector(this.playlists.master, average, parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10), parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10));
|
4250 | };
|
4251 | };
|
4252 |
|
4253 | exports.movingAverageBandwidthSelector = movingAverageBandwidthSelector;
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 |
|
4265 |
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 |
|
4282 | var minRebufferMaxBandwidthSelector = function minRebufferMaxBandwidthSelector(settings) {
|
4283 | var master = settings.master;
|
4284 | var currentTime = settings.currentTime;
|
4285 | var bandwidth = settings.bandwidth;
|
4286 | var duration = settings.duration;
|
4287 | var segmentDuration = settings.segmentDuration;
|
4288 | var timeUntilRebuffer = settings.timeUntilRebuffer;
|
4289 | var currentTimeline = settings.currentTimeline;
|
4290 | var syncController = settings.syncController;
|
4291 |
|
4292 |
|
4293 |
|
4294 | var compatiblePlaylists = master.playlists.filter(function (playlist) {
|
4295 | return !_playlist2['default'].isIncompatible(playlist);
|
4296 | });
|
4297 |
|
4298 |
|
4299 |
|
4300 | var enabledPlaylists = compatiblePlaylists.filter(_playlist2['default'].isEnabled);
|
4301 |
|
4302 | if (!enabledPlaylists.length) {
|
4303 |
|
4304 |
|
4305 |
|
4306 | enabledPlaylists = compatiblePlaylists.filter(function (playlist) {
|
4307 | return !_playlist2['default'].isDisabled(playlist);
|
4308 | });
|
4309 | }
|
4310 |
|
4311 | var bandwidthPlaylists = enabledPlaylists.filter(_playlist2['default'].hasAttribute.bind(null, 'BANDWIDTH'));
|
4312 |
|
4313 | var rebufferingEstimates = bandwidthPlaylists.map(function (playlist) {
|
4314 | var syncPoint = syncController.getSyncPoint(playlist, duration, currentTimeline, currentTime);
|
4315 |
|
4316 |
|
4317 | var numRequests = syncPoint ? 1 : 2;
|
4318 | var requestTimeEstimate = _playlist2['default'].estimateSegmentRequestTime(segmentDuration, bandwidth, playlist);
|
4319 | var rebufferingImpact = requestTimeEstimate * numRequests - timeUntilRebuffer;
|
4320 |
|
4321 | return {
|
4322 | playlist: playlist,
|
4323 | rebufferingImpact: rebufferingImpact
|
4324 | };
|
4325 | });
|
4326 |
|
4327 | var noRebufferingPlaylists = rebufferingEstimates.filter(function (estimate) {
|
4328 | return estimate.rebufferingImpact <= 0;
|
4329 | });
|
4330 |
|
4331 |
|
4332 | stableSort(noRebufferingPlaylists, function (a, b) {
|
4333 | return comparePlaylistBandwidth(b.playlist, a.playlist);
|
4334 | });
|
4335 |
|
4336 | if (noRebufferingPlaylists.length) {
|
4337 | return noRebufferingPlaylists[0];
|
4338 | }
|
4339 |
|
4340 | stableSort(rebufferingEstimates, function (a, b) {
|
4341 | return a.rebufferingImpact - b.rebufferingImpact;
|
4342 | });
|
4343 |
|
4344 | return rebufferingEstimates[0] || null;
|
4345 | };
|
4346 |
|
4347 | exports.minRebufferMaxBandwidthSelector = minRebufferMaxBandwidthSelector;
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 | var lowestBitrateCompatibleVariantSelector = function lowestBitrateCompatibleVariantSelector() {
|
4360 |
|
4361 |
|
4362 | var playlists = this.playlists.master.playlists.filter(_playlist2['default'].isEnabled);
|
4363 |
|
4364 |
|
4365 | stableSort(playlists, function (a, b) {
|
4366 | return comparePlaylistBandwidth(a, b);
|
4367 | });
|
4368 |
|
4369 |
|
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 | var playlistsWithVideo = playlists.filter(function (playlist) {
|
4375 | return (0, _utilCodecsJs.parseCodecs)(playlist.attributes.CODECS).videoCodec;
|
4376 | });
|
4377 |
|
4378 | return playlistsWithVideo[0] || null;
|
4379 | };
|
4380 | exports.lowestBitrateCompatibleVariantSelector = lowestBitrateCompatibleVariantSelector;
|
4381 | },{"./config":3,"./playlist":11,"./util/codecs.js":19}],11:[function(require,module,exports){
|
4382 | (function (global){
|
4383 |
|
4384 |
|
4385 |
|
4386 |
|
4387 |
|
4388 | 'use strict';
|
4389 |
|
4390 | Object.defineProperty(exports, '__esModule', {
|
4391 | value: true
|
4392 | });
|
4393 |
|
4394 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
4395 |
|
4396 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
4397 |
|
4398 | var _globalWindow = require('global/window');
|
4399 |
|
4400 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
4401 |
|
4402 |
|
4403 |
|
4404 |
|
4405 |
|
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 | var backwardDuration = function backwardDuration(playlist, endSequence) {
|
4411 | var result = 0;
|
4412 | var i = endSequence - playlist.mediaSequence;
|
4413 |
|
4414 |
|
4415 | var segment = playlist.segments[i];
|
4416 |
|
4417 |
|
4418 |
|
4419 | if (segment) {
|
4420 | if (typeof segment.start !== 'undefined') {
|
4421 | return { result: segment.start, precise: true };
|
4422 | }
|
4423 | if (typeof segment.end !== 'undefined') {
|
4424 | return {
|
4425 | result: segment.end - segment.duration,
|
4426 | precise: true
|
4427 | };
|
4428 | }
|
4429 | }
|
4430 | while (i--) {
|
4431 | segment = playlist.segments[i];
|
4432 | if (typeof segment.end !== 'undefined') {
|
4433 | return { result: result + segment.end, precise: true };
|
4434 | }
|
4435 |
|
4436 | result += segment.duration;
|
4437 |
|
4438 | if (typeof segment.start !== 'undefined') {
|
4439 | return { result: result + segment.start, precise: true };
|
4440 | }
|
4441 | }
|
4442 | return { result: result, precise: false };
|
4443 | };
|
4444 |
|
4445 |
|
4446 |
|
4447 |
|
4448 |
|
4449 |
|
4450 |
|
4451 |
|
4452 | var forwardDuration = function forwardDuration(playlist, endSequence) {
|
4453 | var result = 0;
|
4454 | var segment = undefined;
|
4455 | var i = endSequence - playlist.mediaSequence;
|
4456 |
|
4457 |
|
4458 |
|
4459 | for (; i < playlist.segments.length; i++) {
|
4460 | segment = playlist.segments[i];
|
4461 | if (typeof segment.start !== 'undefined') {
|
4462 | return {
|
4463 | result: segment.start - result,
|
4464 | precise: true
|
4465 | };
|
4466 | }
|
4467 |
|
4468 | result += segment.duration;
|
4469 |
|
4470 | if (typeof segment.end !== 'undefined') {
|
4471 | return {
|
4472 | result: segment.end - result,
|
4473 | precise: true
|
4474 | };
|
4475 | }
|
4476 | }
|
4477 |
|
4478 | return { result: -1, precise: false };
|
4479 | };
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 |
|
4488 |
|
4489 |
|
4490 |
|
4491 |
|
4492 |
|
4493 |
|
4494 | var intervalDuration = function intervalDuration(playlist, endSequence, expired) {
|
4495 | var backward = undefined;
|
4496 | var forward = undefined;
|
4497 |
|
4498 | if (typeof endSequence === 'undefined') {
|
4499 | endSequence = playlist.mediaSequence + playlist.segments.length;
|
4500 | }
|
4501 |
|
4502 | if (endSequence < playlist.mediaSequence) {
|
4503 | return 0;
|
4504 | }
|
4505 |
|
4506 |
|
4507 | backward = backwardDuration(playlist, endSequence);
|
4508 | if (backward.precise) {
|
4509 |
|
4510 |
|
4511 |
|
4512 | return backward.result;
|
4513 | }
|
4514 |
|
4515 |
|
4516 |
|
4517 | forward = forwardDuration(playlist, endSequence);
|
4518 | if (forward.precise) {
|
4519 |
|
4520 |
|
4521 | return forward.result;
|
4522 | }
|
4523 |
|
4524 |
|
4525 | return backward.result + expired;
|
4526 | };
|
4527 |
|
4528 |
|
4529 |
|
4530 |
|
4531 |
|
4532 |
|
4533 |
|
4534 |
|
4535 |
|
4536 |
|
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 | var duration = function duration(playlist, endSequence, expired) {
|
4544 | if (!playlist) {
|
4545 | return 0;
|
4546 | }
|
4547 |
|
4548 | if (typeof expired !== 'number') {
|
4549 | expired = 0;
|
4550 | }
|
4551 |
|
4552 |
|
4553 |
|
4554 | if (typeof endSequence === 'undefined') {
|
4555 |
|
4556 | if (playlist.totalDuration) {
|
4557 | return playlist.totalDuration;
|
4558 | }
|
4559 |
|
4560 |
|
4561 | if (!playlist.endList) {
|
4562 | return _globalWindow2['default'].Infinity;
|
4563 | }
|
4564 | }
|
4565 |
|
4566 |
|
4567 | return intervalDuration(playlist, endSequence, expired);
|
4568 | };
|
4569 |
|
4570 | exports.duration = duration;
|
4571 |
|
4572 |
|
4573 |
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 |
|
4579 |
|
4580 |
|
4581 |
|
4582 | var sumDurations = function sumDurations(playlist, startIndex, endIndex) {
|
4583 | var durations = 0;
|
4584 |
|
4585 | if (startIndex > endIndex) {
|
4586 | var _ref = [endIndex, startIndex];
|
4587 | startIndex = _ref[0];
|
4588 | endIndex = _ref[1];
|
4589 | }
|
4590 |
|
4591 | if (startIndex < 0) {
|
4592 | for (var i = startIndex; i < Math.min(0, endIndex); i++) {
|
4593 | durations += playlist.targetDuration;
|
4594 | }
|
4595 | startIndex = 0;
|
4596 | }
|
4597 |
|
4598 | for (var i = startIndex; i < endIndex; i++) {
|
4599 | durations += playlist.segments[i].duration;
|
4600 | }
|
4601 |
|
4602 | return durations;
|
4603 | };
|
4604 |
|
4605 | exports.sumDurations = sumDurations;
|
4606 |
|
4607 |
|
4608 |
|
4609 |
|
4610 |
|
4611 |
|
4612 |
|
4613 |
|
4614 |
|
4615 |
|
4616 |
|
4617 |
|
4618 | var safeLiveIndex = function safeLiveIndex(playlist) {
|
4619 | if (!playlist.segments.length) {
|
4620 | return 0;
|
4621 | }
|
4622 |
|
4623 | var i = playlist.segments.length - 1;
|
4624 | var distanceFromEnd = playlist.segments[i].duration || playlist.targetDuration;
|
4625 | var safeDistance = distanceFromEnd + playlist.targetDuration * 2;
|
4626 |
|
4627 | while (i--) {
|
4628 | distanceFromEnd += playlist.segments[i].duration;
|
4629 |
|
4630 | if (distanceFromEnd >= safeDistance) {
|
4631 | break;
|
4632 | }
|
4633 | }
|
4634 |
|
4635 | return Math.max(0, i);
|
4636 | };
|
4637 |
|
4638 | exports.safeLiveIndex = safeLiveIndex;
|
4639 |
|
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 |
|
4652 | var playlistEnd = function playlistEnd(playlist, expired, useSafeLiveEnd) {
|
4653 | if (!playlist || !playlist.segments) {
|
4654 | return null;
|
4655 | }
|
4656 | if (playlist.endList) {
|
4657 | return duration(playlist);
|
4658 | }
|
4659 |
|
4660 | if (expired === null) {
|
4661 | return null;
|
4662 | }
|
4663 |
|
4664 | expired = expired || 0;
|
4665 |
|
4666 | var endSequence = useSafeLiveEnd ? safeLiveIndex(playlist) : playlist.segments.length;
|
4667 |
|
4668 | return intervalDuration(playlist, playlist.mediaSequence + endSequence, expired);
|
4669 | };
|
4670 |
|
4671 | exports.playlistEnd = playlistEnd;
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 |
|
4687 | var seekable = function seekable(playlist, expired) {
|
4688 | var useSafeLiveEnd = true;
|
4689 | var seekableStart = expired || 0;
|
4690 | var seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd);
|
4691 |
|
4692 | if (seekableEnd === null) {
|
4693 | return (0, _videoJs.createTimeRange)();
|
4694 | }
|
4695 | return (0, _videoJs.createTimeRange)(seekableStart, seekableEnd);
|
4696 | };
|
4697 |
|
4698 | exports.seekable = seekable;
|
4699 | var isWholeNumber = function isWholeNumber(num) {
|
4700 | return num - Math.floor(num) === 0;
|
4701 | };
|
4702 |
|
4703 | var roundSignificantDigit = function roundSignificantDigit(increment, num) {
|
4704 |
|
4705 | if (isWholeNumber(num)) {
|
4706 | return num + increment * 0.1;
|
4707 | }
|
4708 |
|
4709 | var numDecimalDigits = num.toString().split('.')[1].length;
|
4710 |
|
4711 | for (var i = 1; i <= numDecimalDigits; i++) {
|
4712 | var scale = Math.pow(10, i);
|
4713 | var temp = num * scale;
|
4714 |
|
4715 | if (isWholeNumber(temp) || i === numDecimalDigits) {
|
4716 | return (temp + increment) / scale;
|
4717 | }
|
4718 | }
|
4719 | };
|
4720 |
|
4721 | var ceilLeastSignificantDigit = roundSignificantDigit.bind(null, 1);
|
4722 | var floorLeastSignificantDigit = roundSignificantDigit.bind(null, -1);
|
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 |
|
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 |
|
4735 | var getMediaInfoForTime = function getMediaInfoForTime(playlist, currentTime, startIndex, startTime) {
|
4736 | var i = undefined;
|
4737 | var segment = undefined;
|
4738 | var numSegments = playlist.segments.length;
|
4739 |
|
4740 | var time = currentTime - startTime;
|
4741 |
|
4742 | if (time < 0) {
|
4743 |
|
4744 |
|
4745 | if (startIndex > 0) {
|
4746 | for (i = startIndex - 1; i >= 0; i--) {
|
4747 | segment = playlist.segments[i];
|
4748 | time += floorLeastSignificantDigit(segment.duration);
|
4749 | if (time > 0) {
|
4750 | return {
|
4751 | mediaIndex: i,
|
4752 | startTime: startTime - sumDurations(playlist, startIndex, i)
|
4753 | };
|
4754 | }
|
4755 | }
|
4756 | }
|
4757 |
|
4758 |
|
4759 | return {
|
4760 | mediaIndex: 0,
|
4761 | startTime: currentTime
|
4762 | };
|
4763 | }
|
4764 |
|
4765 |
|
4766 |
|
4767 |
|
4768 | if (startIndex < 0) {
|
4769 | for (i = startIndex; i < 0; i++) {
|
4770 | time -= playlist.targetDuration;
|
4771 | if (time < 0) {
|
4772 | return {
|
4773 | mediaIndex: 0,
|
4774 | startTime: currentTime
|
4775 | };
|
4776 | }
|
4777 | }
|
4778 | startIndex = 0;
|
4779 | }
|
4780 |
|
4781 |
|
4782 |
|
4783 | for (i = startIndex; i < numSegments; i++) {
|
4784 | segment = playlist.segments[i];
|
4785 | time -= ceilLeastSignificantDigit(segment.duration);
|
4786 | if (time < 0) {
|
4787 | return {
|
4788 | mediaIndex: i,
|
4789 | startTime: startTime + sumDurations(playlist, startIndex, i)
|
4790 | };
|
4791 | }
|
4792 | }
|
4793 |
|
4794 |
|
4795 | return {
|
4796 | mediaIndex: numSegments - 1,
|
4797 | startTime: currentTime
|
4798 | };
|
4799 | };
|
4800 |
|
4801 | exports.getMediaInfoForTime = getMediaInfoForTime;
|
4802 |
|
4803 |
|
4804 |
|
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 | var isBlacklisted = function isBlacklisted(playlist) {
|
4810 | return playlist.excludeUntil && playlist.excludeUntil > Date.now();
|
4811 | };
|
4812 |
|
4813 | exports.isBlacklisted = isBlacklisted;
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 | var isIncompatible = function isIncompatible(playlist) {
|
4823 | return playlist.excludeUntil && playlist.excludeUntil === Infinity;
|
4824 | };
|
4825 |
|
4826 | exports.isIncompatible = isIncompatible;
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 |
|
4833 |
|
4834 | var isEnabled = function isEnabled(playlist) {
|
4835 | var blacklisted = isBlacklisted(playlist);
|
4836 |
|
4837 | return !playlist.disabled && !blacklisted;
|
4838 | };
|
4839 |
|
4840 | exports.isEnabled = isEnabled;
|
4841 |
|
4842 |
|
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 | var isDisabled = function isDisabled(playlist) {
|
4849 | return playlist.disabled;
|
4850 | };
|
4851 |
|
4852 | exports.isDisabled = isDisabled;
|
4853 |
|
4854 |
|
4855 |
|
4856 |
|
4857 |
|
4858 | var isAes = function isAes(media) {
|
4859 | for (var i = 0; i < media.segments.length; i++) {
|
4860 | if (media.segments[i].key) {
|
4861 | return true;
|
4862 | }
|
4863 | }
|
4864 | return false;
|
4865 | };
|
4866 |
|
4867 | exports.isAes = isAes;
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 | var isFmp4 = function isFmp4(media) {
|
4874 | for (var i = 0; i < media.segments.length; i++) {
|
4875 | if (media.segments[i].map) {
|
4876 | return true;
|
4877 | }
|
4878 | }
|
4879 | return false;
|
4880 | };
|
4881 |
|
4882 | exports.isFmp4 = isFmp4;
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 | var hasAttribute = function hasAttribute(attr, playlist) {
|
4895 | return playlist.attributes && playlist.attributes[attr];
|
4896 | };
|
4897 |
|
4898 | exports.hasAttribute = hasAttribute;
|
4899 |
|
4900 |
|
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 |
|
4907 |
|
4908 |
|
4909 |
|
4910 |
|
4911 |
|
4912 |
|
4913 |
|
4914 |
|
4915 | var estimateSegmentRequestTime = function estimateSegmentRequestTime(segmentDuration, bandwidth, playlist) {
|
4916 | var bytesReceived = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
|
4917 |
|
4918 | if (!hasAttribute('BANDWIDTH', playlist)) {
|
4919 | return NaN;
|
4920 | }
|
4921 |
|
4922 | var size = segmentDuration * playlist.attributes.BANDWIDTH;
|
4923 |
|
4924 | return (size - bytesReceived * 8) / bandwidth;
|
4925 | };
|
4926 |
|
4927 | exports.estimateSegmentRequestTime = estimateSegmentRequestTime;
|
4928 |
|
4929 | exports['default'] = {
|
4930 | duration: duration,
|
4931 | seekable: seekable,
|
4932 | safeLiveIndex: safeLiveIndex,
|
4933 | getMediaInfoForTime: getMediaInfoForTime,
|
4934 | isEnabled: isEnabled,
|
4935 | isDisabled: isDisabled,
|
4936 | isBlacklisted: isBlacklisted,
|
4937 | isIncompatible: isIncompatible,
|
4938 | playlistEnd: playlistEnd,
|
4939 | isAes: isAes,
|
4940 | isFmp4: isFmp4,
|
4941 | hasAttribute: hasAttribute,
|
4942 | estimateSegmentRequestTime: estimateSegmentRequestTime
|
4943 | };
|
4944 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4945 | },{"global/window":32}],12:[function(require,module,exports){
|
4946 | (function (global){
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 | 'use strict';
|
4955 |
|
4956 | Object.defineProperty(exports, '__esModule', {
|
4957 | value: true
|
4958 | });
|
4959 |
|
4960 | var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
|
4961 |
|
4962 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
4963 |
|
4964 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
4965 |
|
4966 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
4967 |
|
4968 |
|
4969 | var TIME_FUDGE_FACTOR = 1 / 30;
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 |
|
4975 | var SAFE_TIME_DELTA = TIME_FUDGE_FACTOR * 3;
|
4976 |
|
4977 |
|
4978 |
|
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 |
|
4984 | var clamp = function clamp(num, _ref) {
|
4985 | var _ref2 = _slicedToArray(_ref, 2);
|
4986 |
|
4987 | var start = _ref2[0];
|
4988 | var end = _ref2[1];
|
4989 |
|
4990 | return Math.min(Math.max(start, num), end);
|
4991 | };
|
4992 | var filterRanges = function filterRanges(timeRanges, predicate) {
|
4993 | var results = [];
|
4994 | var i = undefined;
|
4995 |
|
4996 | if (timeRanges && timeRanges.length) {
|
4997 |
|
4998 | for (i = 0; i < timeRanges.length; i++) {
|
4999 | if (predicate(timeRanges.start(i), timeRanges.end(i))) {
|
5000 | results.push([timeRanges.start(i), timeRanges.end(i)]);
|
5001 | }
|
5002 | }
|
5003 | }
|
5004 |
|
5005 | return _videoJs2['default'].createTimeRanges(results);
|
5006 | };
|
5007 |
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 |
|
5013 |
|
5014 |
|
5015 | var findRange = function findRange(buffered, time) {
|
5016 | return filterRanges(buffered, function (start, end) {
|
5017 | return start - TIME_FUDGE_FACTOR <= time && end + TIME_FUDGE_FACTOR >= time;
|
5018 | });
|
5019 | };
|
5020 |
|
5021 |
|
5022 |
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 | var findNextRange = function findNextRange(timeRanges, time) {
|
5028 | return filterRanges(timeRanges, function (start) {
|
5029 | return start - TIME_FUDGE_FACTOR >= time;
|
5030 | });
|
5031 | };
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 | var findGaps = function findGaps(buffered) {
|
5039 | if (buffered.length < 2) {
|
5040 | return _videoJs2['default'].createTimeRanges();
|
5041 | }
|
5042 |
|
5043 | var ranges = [];
|
5044 |
|
5045 | for (var i = 1; i < buffered.length; i++) {
|
5046 | var start = buffered.end(i - 1);
|
5047 | var end = buffered.start(i);
|
5048 |
|
5049 | ranges.push([start, end]);
|
5050 | }
|
5051 |
|
5052 | return _videoJs2['default'].createTimeRanges(ranges);
|
5053 | };
|
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 | var findSoleUncommonTimeRangesEnd = function findSoleUncommonTimeRangesEnd(original, update) {
|
5065 | var i = undefined;
|
5066 | var start = undefined;
|
5067 | var end = undefined;
|
5068 | var result = [];
|
5069 | var edges = [];
|
5070 |
|
5071 |
|
5072 |
|
5073 |
|
5074 |
|
5075 |
|
5076 | var overlapsCurrentEnd = function overlapsCurrentEnd(span) {
|
5077 | return span[0] <= end && span[1] >= end;
|
5078 | };
|
5079 |
|
5080 | if (original) {
|
5081 |
|
5082 | for (i = 0; i < original.length; i++) {
|
5083 | start = original.start(i);
|
5084 | end = original.end(i);
|
5085 |
|
5086 | edges.push([start, end]);
|
5087 | }
|
5088 | }
|
5089 |
|
5090 | if (update) {
|
5091 |
|
5092 |
|
5093 | for (i = 0; i < update.length; i++) {
|
5094 | start = update.start(i);
|
5095 | end = update.end(i);
|
5096 |
|
5097 | if (edges.some(overlapsCurrentEnd)) {
|
5098 | continue;
|
5099 | }
|
5100 |
|
5101 |
|
5102 | result.push(end);
|
5103 | }
|
5104 | }
|
5105 |
|
5106 |
|
5107 |
|
5108 | if (result.length !== 1) {
|
5109 | return null;
|
5110 | }
|
5111 |
|
5112 | return result[0];
|
5113 | };
|
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 | var bufferIntersection = function bufferIntersection(bufferA, bufferB) {
|
5122 | var start = null;
|
5123 | var end = null;
|
5124 | var arity = 0;
|
5125 | var extents = [];
|
5126 | var ranges = [];
|
5127 |
|
5128 | if (!bufferA || !bufferA.length || !bufferB || !bufferB.length) {
|
5129 | return _videoJs2['default'].createTimeRange();
|
5130 | }
|
5131 |
|
5132 |
|
5133 |
|
5134 | var count = bufferA.length;
|
5135 |
|
5136 |
|
5137 | while (count--) {
|
5138 | extents.push({ time: bufferA.start(count), type: 'start' });
|
5139 | extents.push({ time: bufferA.end(count), type: 'end' });
|
5140 | }
|
5141 | count = bufferB.length;
|
5142 | while (count--) {
|
5143 | extents.push({ time: bufferB.start(count), type: 'start' });
|
5144 | extents.push({ time: bufferB.end(count), type: 'end' });
|
5145 | }
|
5146 |
|
5147 | extents.sort(function (a, b) {
|
5148 | return a.time - b.time;
|
5149 | });
|
5150 |
|
5151 |
|
5152 |
|
5153 | for (count = 0; count < extents.length; count++) {
|
5154 | if (extents[count].type === 'start') {
|
5155 | arity++;
|
5156 |
|
5157 |
|
5158 |
|
5159 | if (arity === 2) {
|
5160 | start = extents[count].time;
|
5161 | }
|
5162 | } else if (extents[count].type === 'end') {
|
5163 | arity--;
|
5164 |
|
5165 |
|
5166 |
|
5167 | if (arity === 1) {
|
5168 | end = extents[count].time;
|
5169 | }
|
5170 | }
|
5171 |
|
5172 |
|
5173 | if (start !== null && end !== null) {
|
5174 | ranges.push([start, end]);
|
5175 | start = null;
|
5176 | end = null;
|
5177 | }
|
5178 | }
|
5179 |
|
5180 | return _videoJs2['default'].createTimeRanges(ranges);
|
5181 | };
|
5182 |
|
5183 |
|
5184 |
|
5185 |
|
5186 |
|
5187 |
|
5188 |
|
5189 |
|
5190 |
|
5191 |
|
5192 |
|
5193 |
|
5194 |
|
5195 | var calculateBufferedPercent = function calculateBufferedPercent(adjustedRange, referenceRange, currentTime, buffered) {
|
5196 | var referenceDuration = referenceRange.end(0) - referenceRange.start(0);
|
5197 | var adjustedDuration = adjustedRange.end(0) - adjustedRange.start(0);
|
5198 | var bufferMissingFromAdjusted = referenceDuration - adjustedDuration;
|
5199 | var adjustedIntersection = bufferIntersection(adjustedRange, buffered);
|
5200 | var referenceIntersection = bufferIntersection(referenceRange, buffered);
|
5201 | var adjustedOverlap = 0;
|
5202 | var referenceOverlap = 0;
|
5203 |
|
5204 | var count = adjustedIntersection.length;
|
5205 |
|
5206 | while (count--) {
|
5207 | adjustedOverlap += adjustedIntersection.end(count) - adjustedIntersection.start(count);
|
5208 |
|
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 | if (adjustedIntersection.start(count) === currentTime) {
|
5214 | adjustedOverlap += bufferMissingFromAdjusted;
|
5215 | }
|
5216 | }
|
5217 |
|
5218 | count = referenceIntersection.length;
|
5219 |
|
5220 | while (count--) {
|
5221 | referenceOverlap += referenceIntersection.end(count) - referenceIntersection.start(count);
|
5222 | }
|
5223 |
|
5224 |
|
5225 |
|
5226 | return Math.max(adjustedOverlap, referenceOverlap) / referenceDuration * 100;
|
5227 | };
|
5228 |
|
5229 |
|
5230 |
|
5231 |
|
5232 |
|
5233 |
|
5234 |
|
5235 |
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 | var getSegmentBufferedPercent = function getSegmentBufferedPercent(startOfSegment, segmentDuration, currentTime, buffered) {
|
5242 | var endOfSegment = startOfSegment + segmentDuration;
|
5243 |
|
5244 |
|
5245 | var originalSegmentRange = _videoJs2['default'].createTimeRanges([[startOfSegment, endOfSegment]]);
|
5246 |
|
5247 |
|
5248 |
|
5249 |
|
5250 |
|
5251 |
|
5252 |
|
5253 | var adjustedSegmentRange = _videoJs2['default'].createTimeRanges([[clamp(startOfSegment, [currentTime, endOfSegment]), endOfSegment]]);
|
5254 |
|
5255 |
|
5256 |
|
5257 | if (adjustedSegmentRange.start(0) === adjustedSegmentRange.end(0)) {
|
5258 | return 0;
|
5259 | }
|
5260 |
|
5261 | var percent = calculateBufferedPercent(adjustedSegmentRange, originalSegmentRange, currentTime, buffered);
|
5262 |
|
5263 |
|
5264 |
|
5265 | if (isNaN(percent) || percent === Infinity || percent === -Infinity) {
|
5266 | return 0;
|
5267 | }
|
5268 |
|
5269 | return percent;
|
5270 | };
|
5271 |
|
5272 |
|
5273 |
|
5274 |
|
5275 |
|
5276 |
|
5277 |
|
5278 | var printableRange = function printableRange(range) {
|
5279 | var strArr = [];
|
5280 |
|
5281 | if (!range || !range.length) {
|
5282 | return '';
|
5283 | }
|
5284 |
|
5285 | for (var i = 0; i < range.length; i++) {
|
5286 | strArr.push(range.start(i) + ' => ' + range.end(i));
|
5287 | }
|
5288 |
|
5289 | return strArr.join(', ');
|
5290 | };
|
5291 |
|
5292 |
|
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 |
|
5299 |
|
5300 |
|
5301 |
|
5302 |
|
5303 |
|
5304 |
|
5305 |
|
5306 | var timeUntilRebuffer = function timeUntilRebuffer(buffered, currentTime) {
|
5307 | var playbackRate = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2];
|
5308 |
|
5309 | var bufferedEnd = buffered.length ? buffered.end(buffered.length - 1) : 0;
|
5310 |
|
5311 | return (bufferedEnd - currentTime) / playbackRate;
|
5312 | };
|
5313 |
|
5314 | exports['default'] = {
|
5315 | findRange: findRange,
|
5316 | findNextRange: findNextRange,
|
5317 | findGaps: findGaps,
|
5318 | findSoleUncommonTimeRangesEnd: findSoleUncommonTimeRangesEnd,
|
5319 | getSegmentBufferedPercent: getSegmentBufferedPercent,
|
5320 | TIME_FUDGE_FACTOR: TIME_FUDGE_FACTOR,
|
5321 | SAFE_TIME_DELTA: SAFE_TIME_DELTA,
|
5322 | printableRange: printableRange,
|
5323 | timeUntilRebuffer: timeUntilRebuffer
|
5324 | };
|
5325 | module.exports = exports['default'];
|
5326 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5327 | },{}],13:[function(require,module,exports){
|
5328 | (function (global){
|
5329 | 'use strict';
|
5330 |
|
5331 | Object.defineProperty(exports, '__esModule', {
|
5332 | value: true
|
5333 | });
|
5334 |
|
5335 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
5336 |
|
5337 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
5338 |
|
5339 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
5340 |
|
5341 | var defaultOptions = {
|
5342 | errorInterval: 30,
|
5343 | getSource: function getSource(next) {
|
5344 | var tech = this.tech({ IWillNotUseThisInPlugins: true });
|
5345 | var sourceObj = tech.currentSource_;
|
5346 |
|
5347 | return next(sourceObj);
|
5348 | }
|
5349 | };
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 | var initPlugin = function initPlugin(player, options) {
|
5359 | var lastCalled = 0;
|
5360 | var seekTo = 0;
|
5361 | var localOptions = _videoJs2['default'].mergeOptions(defaultOptions, options);
|
5362 |
|
5363 | player.ready(function () {
|
5364 | player.trigger({ type: 'usage', name: 'hls-error-reload-initialized' });
|
5365 | });
|
5366 |
|
5367 | |
5368 |
|
5369 |
|
5370 |
|
5371 |
|
5372 |
|
5373 | var loadedMetadataHandler = function loadedMetadataHandler() {
|
5374 | if (seekTo) {
|
5375 | player.currentTime(seekTo);
|
5376 | }
|
5377 | };
|
5378 |
|
5379 | |
5380 |
|
5381 |
|
5382 |
|
5383 |
|
5384 |
|
5385 | var setSource = function setSource(sourceObj) {
|
5386 | if (sourceObj === null || sourceObj === undefined) {
|
5387 | return;
|
5388 | }
|
5389 | seekTo = player.duration() !== Infinity && player.currentTime() || 0;
|
5390 |
|
5391 | player.one('loadedmetadata', loadedMetadataHandler);
|
5392 |
|
5393 | player.src(sourceObj);
|
5394 | player.trigger({ type: 'usage', name: 'hls-error-reload' });
|
5395 | player.play();
|
5396 | };
|
5397 |
|
5398 | |
5399 |
|
5400 |
|
5401 |
|
5402 |
|
5403 |
|
5404 | var errorHandler = function errorHandler() {
|
5405 |
|
5406 |
|
5407 | if (Date.now() - lastCalled < localOptions.errorInterval * 1000) {
|
5408 | player.trigger({ type: 'usage', name: 'hls-error-reload-canceled' });
|
5409 | return;
|
5410 | }
|
5411 |
|
5412 | if (!localOptions.getSource || typeof localOptions.getSource !== 'function') {
|
5413 | _videoJs2['default'].log.error('ERROR: reloadSourceOnError - The option getSource must be a function!');
|
5414 | return;
|
5415 | }
|
5416 | lastCalled = Date.now();
|
5417 |
|
5418 | return localOptions.getSource.call(player, setSource);
|
5419 | };
|
5420 |
|
5421 | |
5422 |
|
5423 |
|
5424 |
|
5425 |
|
5426 | var cleanupEvents = function cleanupEvents() {
|
5427 | player.off('loadedmetadata', loadedMetadataHandler);
|
5428 | player.off('error', errorHandler);
|
5429 | player.off('dispose', cleanupEvents);
|
5430 | };
|
5431 |
|
5432 | |
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 | var reinitPlugin = function reinitPlugin(newOptions) {
|
5439 | cleanupEvents();
|
5440 | initPlugin(player, newOptions);
|
5441 | };
|
5442 |
|
5443 | player.on('error', errorHandler);
|
5444 | player.on('dispose', cleanupEvents);
|
5445 |
|
5446 |
|
5447 |
|
5448 | player.reloadSourceOnError = reinitPlugin;
|
5449 | };
|
5450 |
|
5451 |
|
5452 |
|
5453 |
|
5454 |
|
5455 |
|
5456 |
|
5457 | var reloadSourceOnError = function reloadSourceOnError(options) {
|
5458 | initPlugin(this, options);
|
5459 | };
|
5460 |
|
5461 | exports['default'] = reloadSourceOnError;
|
5462 | module.exports = exports['default'];
|
5463 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5464 | },{}],14:[function(require,module,exports){
|
5465 | 'use strict';
|
5466 |
|
5467 | Object.defineProperty(exports, '__esModule', {
|
5468 | value: true
|
5469 | });
|
5470 |
|
5471 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
5472 |
|
5473 | var _playlistJs = require('./playlist.js');
|
5474 |
|
5475 |
|
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 |
|
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 | var enableFunction = function enableFunction(loader, playlistUri, changePlaylistFn) {
|
5488 | return function (enable) {
|
5489 | var playlist = loader.master.playlists[playlistUri];
|
5490 | var incompatible = (0, _playlistJs.isIncompatible)(playlist);
|
5491 | var currentlyEnabled = (0, _playlistJs.isEnabled)(playlist);
|
5492 |
|
5493 | if (typeof enable === 'undefined') {
|
5494 | return currentlyEnabled;
|
5495 | }
|
5496 |
|
5497 | if (enable) {
|
5498 | delete playlist.disabled;
|
5499 | } else {
|
5500 | playlist.disabled = true;
|
5501 | }
|
5502 |
|
5503 | if (enable !== currentlyEnabled && !incompatible) {
|
5504 |
|
5505 | changePlaylistFn();
|
5506 | if (enable) {
|
5507 | loader.trigger('renditionenabled');
|
5508 | } else {
|
5509 | loader.trigger('renditiondisabled');
|
5510 | }
|
5511 | }
|
5512 | return enable;
|
5513 | };
|
5514 | };
|
5515 |
|
5516 |
|
5517 |
|
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 | var Representation = function Representation(hlsHandler, playlist, id) {
|
5525 | _classCallCheck(this, Representation);
|
5526 |
|
5527 |
|
5528 | var fastChangeFunction = hlsHandler.masterPlaylistController_.fastQualityChange_.bind(hlsHandler.masterPlaylistController_);
|
5529 |
|
5530 |
|
5531 | if (playlist.attributes.RESOLUTION) {
|
5532 | var resolution = playlist.attributes.RESOLUTION;
|
5533 |
|
5534 | this.width = resolution.width;
|
5535 | this.height = resolution.height;
|
5536 | }
|
5537 |
|
5538 | this.bandwidth = playlist.attributes.BANDWIDTH;
|
5539 |
|
5540 |
|
5541 |
|
5542 | this.id = id;
|
5543 |
|
5544 |
|
5545 |
|
5546 | this.enabled = enableFunction(hlsHandler.playlists, playlist.uri, fastChangeFunction);
|
5547 | }
|
5548 |
|
5549 |
|
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 | ;
|
5556 |
|
5557 | var renditionSelectionMixin = function renditionSelectionMixin(hlsHandler) {
|
5558 | var playlists = hlsHandler.playlists;
|
5559 |
|
5560 |
|
5561 | hlsHandler.representations = function () {
|
5562 | return playlists.master.playlists.filter(function (media) {
|
5563 | return !(0, _playlistJs.isIncompatible)(media);
|
5564 | }).map(function (e, i) {
|
5565 | return new Representation(hlsHandler, e, e.uri);
|
5566 | });
|
5567 | };
|
5568 | };
|
5569 |
|
5570 | exports['default'] = renditionSelectionMixin;
|
5571 | module.exports = exports['default'];
|
5572 | },{"./playlist.js":11}],15:[function(require,module,exports){
|
5573 |
|
5574 |
|
5575 |
|
5576 |
|
5577 | 'use strict';
|
5578 |
|
5579 | Object.defineProperty(exports, '__esModule', {
|
5580 | value: true
|
5581 | });
|
5582 |
|
5583 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
5584 |
|
5585 | var _urlToolkit = require('url-toolkit');
|
5586 |
|
5587 | var _urlToolkit2 = _interopRequireDefault(_urlToolkit);
|
5588 |
|
5589 | var _globalWindow = require('global/window');
|
5590 |
|
5591 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
5592 |
|
5593 | var resolveUrl = function resolveUrl(baseURL, relativeURL) {
|
5594 |
|
5595 | if (/^[a-z]+:/i.test(relativeURL)) {
|
5596 | return relativeURL;
|
5597 | }
|
5598 |
|
5599 |
|
5600 | if (!/\/\//i.test(baseURL)) {
|
5601 | baseURL = _urlToolkit2['default'].buildAbsoluteURL(_globalWindow2['default'].location.href, baseURL);
|
5602 | }
|
5603 |
|
5604 | return _urlToolkit2['default'].buildAbsoluteURL(baseURL, relativeURL);
|
5605 | };
|
5606 |
|
5607 | exports['default'] = resolveUrl;
|
5608 | module.exports = exports['default'];
|
5609 | },{"global/window":32,"url-toolkit":63}],16:[function(require,module,exports){
|
5610 | (function (global){
|
5611 |
|
5612 |
|
5613 |
|
5614 | 'use strict';
|
5615 |
|
5616 | Object.defineProperty(exports, '__esModule', {
|
5617 | value: true
|
5618 | });
|
5619 |
|
5620 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
5621 |
|
5622 | var _get = function get(_x4, _x5, _x6) { var _again = true; _function: while (_again) { var object = _x4, property = _x5, receiver = _x6; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x4 = parent; _x5 = property; _x6 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
5623 |
|
5624 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
5625 |
|
5626 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
5627 |
|
5628 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
5629 |
|
5630 | var _playlist = require('./playlist');
|
5631 |
|
5632 | var _playlist2 = _interopRequireDefault(_playlist);
|
5633 |
|
5634 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
5635 |
|
5636 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
5637 |
|
5638 | var _sourceUpdater = require('./source-updater');
|
5639 |
|
5640 | var _sourceUpdater2 = _interopRequireDefault(_sourceUpdater);
|
5641 |
|
5642 | var _config = require('./config');
|
5643 |
|
5644 | var _config2 = _interopRequireDefault(_config);
|
5645 |
|
5646 | var _globalWindow = require('global/window');
|
5647 |
|
5648 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
5649 |
|
5650 | var _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs = require('videojs-contrib-media-sources/es5/remove-cues-from-track.js');
|
5651 |
|
5652 | var _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs2 = _interopRequireDefault(_videojsContribMediaSourcesEs5RemoveCuesFromTrackJs);
|
5653 |
|
5654 | var _binUtils = require('./bin-utils');
|
5655 |
|
5656 | var _mediaSegmentRequest = require('./media-segment-request');
|
5657 |
|
5658 | var _ranges = require('./ranges');
|
5659 |
|
5660 | var _playlistSelectors = require('./playlist-selectors');
|
5661 |
|
5662 |
|
5663 | var CHECK_BUFFER_DELAY = 500;
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 | var detectEndOfStream = function detectEndOfStream(playlist, mediaSource, segmentIndex) {
|
5676 | if (!playlist || !mediaSource) {
|
5677 | return false;
|
5678 | }
|
5679 |
|
5680 | var segments = playlist.segments;
|
5681 |
|
5682 |
|
5683 |
|
5684 | var appendedLastSegment = segmentIndex === segments.length;
|
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 | return playlist.endList && mediaSource.readyState === 'open' && appendedLastSegment;
|
5690 | };
|
5691 |
|
5692 | var finite = function finite(num) {
|
5693 | return typeof num === 'number' && isFinite(num);
|
5694 | };
|
5695 |
|
5696 | var illegalMediaSwitch = function illegalMediaSwitch(loaderType, startingMedia, newSegmentMedia) {
|
5697 |
|
5698 |
|
5699 | if (loaderType !== 'main' || !startingMedia || !newSegmentMedia) {
|
5700 | return null;
|
5701 | }
|
5702 |
|
5703 | if (!newSegmentMedia.containsAudio && !newSegmentMedia.containsVideo) {
|
5704 | return 'Neither audio nor video found in segment.';
|
5705 | }
|
5706 |
|
5707 | if (startingMedia.containsVideo && !newSegmentMedia.containsVideo) {
|
5708 | 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.';
|
5709 | }
|
5710 |
|
5711 | if (!startingMedia.containsVideo && newSegmentMedia.containsVideo) {
|
5712 | 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.';
|
5713 | }
|
5714 |
|
5715 | return null;
|
5716 | };
|
5717 |
|
5718 | exports.illegalMediaSwitch = illegalMediaSwitch;
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 | var safeBackBufferTrimTime = function safeBackBufferTrimTime(seekable, currentTime, targetDuration) {
|
5733 | var removeToTime = undefined;
|
5734 |
|
5735 | if (seekable.length && seekable.start(0) > 0 && seekable.start(0) < currentTime) {
|
5736 |
|
5737 | removeToTime = seekable.start(0);
|
5738 | } else {
|
5739 |
|
5740 | removeToTime = currentTime - 30;
|
5741 | }
|
5742 |
|
5743 |
|
5744 |
|
5745 |
|
5746 | return Math.min(removeToTime, currentTime - targetDuration);
|
5747 | };
|
5748 |
|
5749 | exports.safeBackBufferTrimTime = safeBackBufferTrimTime;
|
5750 |
|
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 |
|
5757 |
|
5758 | var SegmentLoader = (function (_videojs$EventTarget) {
|
5759 | _inherits(SegmentLoader, _videojs$EventTarget);
|
5760 |
|
5761 | function SegmentLoader(settings) {
|
5762 | var _this = this;
|
5763 |
|
5764 | var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
5765 |
|
5766 | _classCallCheck(this, SegmentLoader);
|
5767 |
|
5768 | _get(Object.getPrototypeOf(SegmentLoader.prototype), 'constructor', this).call(this);
|
5769 |
|
5770 | if (!settings) {
|
5771 | throw new TypeError('Initialization settings are required');
|
5772 | }
|
5773 | if (typeof settings.currentTime !== 'function') {
|
5774 | throw new TypeError('No currentTime getter specified');
|
5775 | }
|
5776 | if (!settings.mediaSource) {
|
5777 | throw new TypeError('No MediaSource specified');
|
5778 | }
|
5779 |
|
5780 | this.state = 'INIT';
|
5781 | this.bandwidth = settings.bandwidth;
|
5782 | this.throughput = { rate: 0, count: 0 };
|
5783 | this.roundTrip = NaN;
|
5784 | this.resetStats_();
|
5785 | this.mediaIndex = null;
|
5786 |
|
5787 |
|
5788 | this.hasPlayed_ = settings.hasPlayed;
|
5789 | this.currentTime_ = settings.currentTime;
|
5790 | this.seekable_ = settings.seekable;
|
5791 | this.seeking_ = settings.seeking;
|
5792 | this.duration_ = settings.duration;
|
5793 | this.mediaSource_ = settings.mediaSource;
|
5794 | this.hls_ = settings.hls;
|
5795 | this.loaderType_ = settings.loaderType;
|
5796 | this.startingMedia_ = void 0;
|
5797 | this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
|
5798 | this.goalBufferLength_ = settings.goalBufferLength;
|
5799 |
|
5800 |
|
5801 | this.checkBufferTimeout_ = null;
|
5802 | this.error_ = void 0;
|
5803 | this.currentTimeline_ = -1;
|
5804 | this.pendingSegment_ = null;
|
5805 | this.mimeType_ = null;
|
5806 | this.sourceUpdater_ = null;
|
5807 | this.xhrOptions_ = null;
|
5808 |
|
5809 |
|
5810 | this.activeInitSegmentId_ = null;
|
5811 | this.initSegments_ = {};
|
5812 |
|
5813 | this.decrypter_ = settings.decrypter;
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 | this.syncController_ = settings.syncController;
|
5819 | this.syncPoint_ = {
|
5820 | segmentIndex: 0,
|
5821 | time: 0
|
5822 | };
|
5823 |
|
5824 | this.syncController_.on('syncinfoupdate', function () {
|
5825 | return _this.trigger('syncinfoupdate');
|
5826 | });
|
5827 |
|
5828 | this.mediaSource_.addEventListener('sourceopen', function () {
|
5829 | return _this.ended_ = false;
|
5830 | });
|
5831 |
|
5832 |
|
5833 | this.fetchAtBuffer_ = false;
|
5834 |
|
5835 | if (options.debug) {
|
5836 | this.logger_ = _videoJs2['default'].log.bind(_videoJs2['default'], 'segment-loader', this.loaderType_, '->');
|
5837 | }
|
5838 | }
|
5839 |
|
5840 | |
5841 |
|
5842 |
|
5843 |
|
5844 |
|
5845 |
|
5846 | _createClass(SegmentLoader, [{
|
5847 | key: 'resetStats_',
|
5848 | value: function resetStats_() {
|
5849 | this.mediaBytesTransferred = 0;
|
5850 | this.mediaRequests = 0;
|
5851 | this.mediaRequestsAborted = 0;
|
5852 | this.mediaRequestsTimedout = 0;
|
5853 | this.mediaRequestsErrored = 0;
|
5854 | this.mediaTransferDuration = 0;
|
5855 | this.mediaSecondsLoaded = 0;
|
5856 | }
|
5857 |
|
5858 | |
5859 |
|
5860 |
|
5861 | }, {
|
5862 | key: 'dispose',
|
5863 | value: function dispose() {
|
5864 | this.state = 'DISPOSED';
|
5865 | this.pause();
|
5866 | this.abort_();
|
5867 | if (this.sourceUpdater_) {
|
5868 | this.sourceUpdater_.dispose();
|
5869 | }
|
5870 | this.resetStats_();
|
5871 | }
|
5872 |
|
5873 | |
5874 |
|
5875 |
|
5876 |
|
5877 | }, {
|
5878 | key: 'abort',
|
5879 | value: function abort() {
|
5880 | if (this.state !== 'WAITING') {
|
5881 | if (this.pendingSegment_) {
|
5882 | this.pendingSegment_ = null;
|
5883 | }
|
5884 | return;
|
5885 | }
|
5886 |
|
5887 | this.abort_();
|
5888 |
|
5889 |
|
5890 |
|
5891 |
|
5892 |
|
5893 | this.state = 'READY';
|
5894 |
|
5895 |
|
5896 |
|
5897 | if (!this.paused()) {
|
5898 | this.monitorBuffer_();
|
5899 | }
|
5900 | }
|
5901 |
|
5902 | |
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 | }, {
|
5908 | key: 'abort_',
|
5909 | value: function abort_() {
|
5910 | if (this.pendingSegment_) {
|
5911 | this.pendingSegment_.abortRequests();
|
5912 | }
|
5913 |
|
5914 |
|
5915 | this.pendingSegment_ = null;
|
5916 | }
|
5917 |
|
5918 | |
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 | }, {
|
5925 | key: 'error',
|
5926 | value: function error(_error) {
|
5927 | if (typeof _error !== 'undefined') {
|
5928 | this.error_ = _error;
|
5929 | }
|
5930 |
|
5931 | this.pendingSegment_ = null;
|
5932 | return this.error_;
|
5933 | }
|
5934 | }, {
|
5935 | key: 'endOfStream',
|
5936 | value: function endOfStream() {
|
5937 | this.ended_ = true;
|
5938 | this.pause();
|
5939 | this.trigger('ended');
|
5940 | }
|
5941 |
|
5942 | |
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 |
|
5948 | }, {
|
5949 | key: 'buffered_',
|
5950 | value: function buffered_() {
|
5951 | if (!this.sourceUpdater_) {
|
5952 | return _videoJs2['default'].createTimeRanges();
|
5953 | }
|
5954 |
|
5955 | return this.sourceUpdater_.buffered();
|
5956 | }
|
5957 |
|
5958 | |
5959 |
|
5960 |
|
5961 |
|
5962 |
|
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 |
|
5968 | }, {
|
5969 | key: 'initSegment',
|
5970 | value: function initSegment(map) {
|
5971 | var set = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
5972 |
|
5973 | if (!map) {
|
5974 | return null;
|
5975 | }
|
5976 |
|
5977 | var id = (0, _binUtils.initSegmentId)(map);
|
5978 | var storedMap = this.initSegments_[id];
|
5979 |
|
5980 | if (set && !storedMap && map.bytes) {
|
5981 | this.initSegments_[id] = storedMap = {
|
5982 | resolvedUri: map.resolvedUri,
|
5983 | byterange: map.byterange,
|
5984 | bytes: map.bytes
|
5985 | };
|
5986 | }
|
5987 |
|
5988 | return storedMap || map;
|
5989 | }
|
5990 |
|
5991 | |
5992 |
|
5993 |
|
5994 |
|
5995 |
|
5996 |
|
5997 | }, {
|
5998 | key: 'couldBeginLoading_',
|
5999 | value: function couldBeginLoading_() {
|
6000 | return this.playlist_ && (
|
6001 |
|
6002 |
|
6003 |
|
6004 | this.sourceUpdater_ || this.mimeType_ && this.state === 'INIT') && !this.paused();
|
6005 | }
|
6006 |
|
6007 | |
6008 |
|
6009 |
|
6010 | }, {
|
6011 | key: 'load',
|
6012 | value: function load() {
|
6013 |
|
6014 | this.monitorBuffer_();
|
6015 |
|
6016 |
|
6017 |
|
6018 | if (!this.playlist_) {
|
6019 | return;
|
6020 | }
|
6021 |
|
6022 |
|
6023 | this.syncController_.setDateTimeMapping(this.playlist_);
|
6024 |
|
6025 |
|
6026 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
6027 | return this.init_();
|
6028 | }
|
6029 |
|
6030 |
|
6031 |
|
6032 | if (!this.couldBeginLoading_() || this.state !== 'READY' && this.state !== 'INIT') {
|
6033 | return;
|
6034 | }
|
6035 |
|
6036 | this.state = 'READY';
|
6037 | }
|
6038 |
|
6039 | |
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 |
|
6046 | }, {
|
6047 | key: 'init_',
|
6048 | value: function init_() {
|
6049 | this.state = 'READY';
|
6050 | this.sourceUpdater_ = new _sourceUpdater2['default'](this.mediaSource_, this.mimeType_);
|
6051 | this.resetEverything();
|
6052 | return this.monitorBuffer_();
|
6053 | }
|
6054 |
|
6055 | |
6056 |
|
6057 |
|
6058 |
|
6059 |
|
6060 | }, {
|
6061 | key: 'playlist',
|
6062 | value: function playlist(newPlaylist) {
|
6063 | var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
6064 |
|
6065 | if (!newPlaylist) {
|
6066 | return;
|
6067 | }
|
6068 |
|
6069 | var oldPlaylist = this.playlist_;
|
6070 | var segmentInfo = this.pendingSegment_;
|
6071 |
|
6072 | this.playlist_ = newPlaylist;
|
6073 | this.xhrOptions_ = options;
|
6074 |
|
6075 |
|
6076 |
|
6077 |
|
6078 | if (!this.hasPlayed_()) {
|
6079 | newPlaylist.syncInfo = {
|
6080 | mediaSequence: newPlaylist.mediaSequence,
|
6081 | time: 0
|
6082 | };
|
6083 | }
|
6084 |
|
6085 |
|
6086 |
|
6087 | this.trigger('syncinfoupdate');
|
6088 |
|
6089 |
|
6090 |
|
6091 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
6092 | return this.init_();
|
6093 | }
|
6094 |
|
6095 | if (!oldPlaylist || oldPlaylist.uri !== newPlaylist.uri) {
|
6096 | if (this.mediaIndex !== null) {
|
6097 |
|
6098 |
|
6099 | this.resyncLoader();
|
6100 | }
|
6101 |
|
6102 |
|
6103 | return;
|
6104 | }
|
6105 |
|
6106 |
|
6107 |
|
6108 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
6109 |
|
6110 | this.logger_('mediaSequenceDiff', mediaSequenceDiff);
|
6111 |
|
6112 |
|
6113 |
|
6114 |
|
6115 | if (this.mediaIndex !== null) {
|
6116 | this.mediaIndex -= mediaSequenceDiff;
|
6117 | }
|
6118 |
|
6119 |
|
6120 |
|
6121 |
|
6122 | if (segmentInfo) {
|
6123 | segmentInfo.mediaIndex -= mediaSequenceDiff;
|
6124 |
|
6125 |
|
6126 |
|
6127 |
|
6128 | if (segmentInfo.mediaIndex >= 0) {
|
6129 | segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex];
|
6130 | }
|
6131 | }
|
6132 |
|
6133 | this.syncController_.saveExpiredSegmentInfo(oldPlaylist, newPlaylist);
|
6134 | }
|
6135 |
|
6136 | |
6137 |
|
6138 |
|
6139 |
|
6140 |
|
6141 |
|
6142 | }, {
|
6143 | key: 'pause',
|
6144 | value: function pause() {
|
6145 | if (this.checkBufferTimeout_) {
|
6146 | _globalWindow2['default'].clearTimeout(this.checkBufferTimeout_);
|
6147 |
|
6148 | this.checkBufferTimeout_ = null;
|
6149 | }
|
6150 | }
|
6151 |
|
6152 | |
6153 |
|
6154 |
|
6155 |
|
6156 |
|
6157 | }, {
|
6158 | key: 'paused',
|
6159 | value: function paused() {
|
6160 | return this.checkBufferTimeout_ === null;
|
6161 | }
|
6162 |
|
6163 | |
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 | }, {
|
6170 | key: 'mimeType',
|
6171 | value: function mimeType(_mimeType) {
|
6172 | if (this.mimeType_) {
|
6173 | return;
|
6174 | }
|
6175 |
|
6176 | this.mimeType_ = _mimeType;
|
6177 |
|
6178 |
|
6179 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
6180 | this.init_();
|
6181 | }
|
6182 | }
|
6183 |
|
6184 | |
6185 |
|
6186 |
|
6187 | }, {
|
6188 | key: 'resetEverything',
|
6189 | value: function resetEverything() {
|
6190 | this.ended_ = false;
|
6191 | this.resetLoader();
|
6192 | this.remove(0, this.duration_());
|
6193 | this.trigger('reseteverything');
|
6194 | }
|
6195 |
|
6196 | |
6197 |
|
6198 |
|
6199 |
|
6200 |
|
6201 |
|
6202 | }, {
|
6203 | key: 'resetLoader',
|
6204 | value: function resetLoader() {
|
6205 | this.fetchAtBuffer_ = false;
|
6206 | this.resyncLoader();
|
6207 | }
|
6208 |
|
6209 | |
6210 |
|
6211 |
|
6212 |
|
6213 | }, {
|
6214 | key: 'resyncLoader',
|
6215 | value: function resyncLoader() {
|
6216 | this.mediaIndex = null;
|
6217 | this.syncPoint_ = null;
|
6218 | this.abort();
|
6219 | }
|
6220 |
|
6221 | |
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 | }, {
|
6227 | key: 'remove',
|
6228 | value: function remove(start, end) {
|
6229 | if (this.sourceUpdater_) {
|
6230 | this.sourceUpdater_.remove(start, end);
|
6231 | }
|
6232 | (0, _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs2['default'])(start, end, this.segmentMetadataTrack_);
|
6233 | }
|
6234 |
|
6235 | |
6236 |
|
6237 |
|
6238 |
|
6239 |
|
6240 | }, {
|
6241 | key: 'monitorBuffer_',
|
6242 | value: function monitorBuffer_() {
|
6243 | if (this.checkBufferTimeout_) {
|
6244 | _globalWindow2['default'].clearTimeout(this.checkBufferTimeout_);
|
6245 | }
|
6246 |
|
6247 | this.checkBufferTimeout_ = _globalWindow2['default'].setTimeout(this.monitorBufferTick_.bind(this), 1);
|
6248 | }
|
6249 |
|
6250 | |
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 | }, {
|
6257 | key: 'monitorBufferTick_',
|
6258 | value: function monitorBufferTick_() {
|
6259 | if (this.state === 'READY') {
|
6260 | this.fillBuffer_();
|
6261 | }
|
6262 |
|
6263 | if (this.checkBufferTimeout_) {
|
6264 | _globalWindow2['default'].clearTimeout(this.checkBufferTimeout_);
|
6265 | }
|
6266 |
|
6267 | this.checkBufferTimeout_ = _globalWindow2['default'].setTimeout(this.monitorBufferTick_.bind(this), CHECK_BUFFER_DELAY);
|
6268 | }
|
6269 |
|
6270 | |
6271 |
|
6272 |
|
6273 |
|
6274 |
|
6275 |
|
6276 |
|
6277 |
|
6278 |
|
6279 | }, {
|
6280 | key: 'fillBuffer_',
|
6281 | value: function fillBuffer_() {
|
6282 | if (this.sourceUpdater_.updating()) {
|
6283 | return;
|
6284 | }
|
6285 |
|
6286 | if (!this.syncPoint_) {
|
6287 | this.syncPoint_ = this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
6288 | }
|
6289 |
|
6290 |
|
6291 | var segmentInfo = this.checkBuffer_(this.buffered_(), this.playlist_, this.mediaIndex, this.hasPlayed_(), this.currentTime_(), this.syncPoint_);
|
6292 |
|
6293 | if (!segmentInfo) {
|
6294 | return;
|
6295 | }
|
6296 |
|
6297 | var isEndOfStream = detectEndOfStream(this.playlist_, this.mediaSource_, segmentInfo.mediaIndex);
|
6298 |
|
6299 | if (isEndOfStream) {
|
6300 | this.endOfStream();
|
6301 | return;
|
6302 | }
|
6303 |
|
6304 | if (segmentInfo.mediaIndex === this.playlist_.segments.length - 1 && this.mediaSource_.readyState === 'ended' && !this.seeking_()) {
|
6305 | return;
|
6306 | }
|
6307 |
|
6308 |
|
6309 |
|
6310 |
|
6311 |
|
6312 |
|
6313 |
|
6314 | if (segmentInfo.timeline !== this.currentTimeline_ || segmentInfo.startOfSegment !== null && segmentInfo.startOfSegment < this.sourceUpdater_.timestampOffset()) {
|
6315 | this.syncController_.reset();
|
6316 | segmentInfo.timestampOffset = segmentInfo.startOfSegment;
|
6317 | }
|
6318 |
|
6319 | this.loadSegment_(segmentInfo);
|
6320 | }
|
6321 |
|
6322 | |
6323 |
|
6324 |
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 |
|
6330 |
|
6331 |
|
6332 |
|
6333 |
|
6334 | }, {
|
6335 | key: 'checkBuffer_',
|
6336 | value: function checkBuffer_(buffered, playlist, mediaIndex, hasPlayed, currentTime, syncPoint) {
|
6337 | var lastBufferedEnd = 0;
|
6338 | var startOfSegment = undefined;
|
6339 |
|
6340 | if (buffered.length) {
|
6341 | lastBufferedEnd = buffered.end(buffered.length - 1);
|
6342 | }
|
6343 |
|
6344 | var bufferedTime = Math.max(0, lastBufferedEnd - currentTime);
|
6345 |
|
6346 | if (!playlist.segments.length) {
|
6347 | return null;
|
6348 | }
|
6349 |
|
6350 |
|
6351 |
|
6352 | if (bufferedTime >= this.goalBufferLength_()) {
|
6353 | return null;
|
6354 | }
|
6355 |
|
6356 |
|
6357 |
|
6358 | if (!hasPlayed && bufferedTime >= 1) {
|
6359 | return null;
|
6360 | }
|
6361 |
|
6362 | this.logger_('checkBuffer_', 'mediaIndex:', mediaIndex, 'hasPlayed:', hasPlayed, 'currentTime:', currentTime, 'syncPoint:', syncPoint, 'fetchAtBuffer:', this.fetchAtBuffer_, 'bufferedTime:', bufferedTime);
|
6363 |
|
6364 |
|
6365 |
|
6366 |
|
6367 |
|
6368 | if (syncPoint === null) {
|
6369 | mediaIndex = this.getSyncSegmentCandidate_(playlist);
|
6370 | this.logger_('getSync', 'mediaIndex:', mediaIndex);
|
6371 | return this.generateSegmentInfo_(playlist, mediaIndex, null, true);
|
6372 | }
|
6373 |
|
6374 |
|
6375 | if (mediaIndex !== null) {
|
6376 | this.logger_('walkForward', 'mediaIndex:', mediaIndex + 1);
|
6377 | var segment = playlist.segments[mediaIndex];
|
6378 |
|
6379 | if (segment && segment.end) {
|
6380 | startOfSegment = segment.end;
|
6381 | } else {
|
6382 | startOfSegment = lastBufferedEnd;
|
6383 | }
|
6384 | return this.generateSegmentInfo_(playlist, mediaIndex + 1, startOfSegment, false);
|
6385 | }
|
6386 |
|
6387 |
|
6388 |
|
6389 |
|
6390 | if (this.fetchAtBuffer_) {
|
6391 |
|
6392 | var mediaSourceInfo = _playlist2['default'].getMediaInfoForTime(playlist, lastBufferedEnd, syncPoint.segmentIndex, syncPoint.time);
|
6393 |
|
6394 | mediaIndex = mediaSourceInfo.mediaIndex;
|
6395 | startOfSegment = mediaSourceInfo.startTime;
|
6396 | } else {
|
6397 |
|
6398 | var mediaSourceInfo = _playlist2['default'].getMediaInfoForTime(playlist, currentTime, syncPoint.segmentIndex, syncPoint.time);
|
6399 |
|
6400 | mediaIndex = mediaSourceInfo.mediaIndex;
|
6401 | startOfSegment = mediaSourceInfo.startTime;
|
6402 | }
|
6403 | this.logger_('getMediaIndexForTime', 'mediaIndex:', mediaIndex, 'startOfSegment:', startOfSegment);
|
6404 |
|
6405 | return this.generateSegmentInfo_(playlist, mediaIndex, startOfSegment, false);
|
6406 | }
|
6407 |
|
6408 | |
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 | }, {
|
6418 | key: 'getSyncSegmentCandidate_',
|
6419 | value: function getSyncSegmentCandidate_(playlist) {
|
6420 | var _this2 = this;
|
6421 |
|
6422 | if (this.currentTimeline_ === -1) {
|
6423 | return 0;
|
6424 | }
|
6425 |
|
6426 | var segmentIndexArray = playlist.segments.map(function (s, i) {
|
6427 | return {
|
6428 | timeline: s.timeline,
|
6429 | segmentIndex: i
|
6430 | };
|
6431 | }).filter(function (s) {
|
6432 | return s.timeline === _this2.currentTimeline_;
|
6433 | });
|
6434 |
|
6435 | if (segmentIndexArray.length) {
|
6436 | return segmentIndexArray[Math.min(segmentIndexArray.length - 1, 1)].segmentIndex;
|
6437 | }
|
6438 |
|
6439 | return Math.max(playlist.segments.length - 1, 0);
|
6440 | }
|
6441 | }, {
|
6442 | key: 'generateSegmentInfo_',
|
6443 | value: function generateSegmentInfo_(playlist, mediaIndex, startOfSegment, isSyncRequest) {
|
6444 | if (mediaIndex < 0 || mediaIndex >= playlist.segments.length) {
|
6445 | return null;
|
6446 | }
|
6447 |
|
6448 | var segment = playlist.segments[mediaIndex];
|
6449 |
|
6450 | return {
|
6451 | requestId: 'segment-loader-' + Math.random(),
|
6452 |
|
6453 | uri: segment.resolvedUri,
|
6454 |
|
6455 | mediaIndex: mediaIndex,
|
6456 |
|
6457 |
|
6458 | isSyncRequest: isSyncRequest,
|
6459 | startOfSegment: startOfSegment,
|
6460 |
|
6461 | playlist: playlist,
|
6462 |
|
6463 | bytes: null,
|
6464 |
|
6465 | encryptedBytes: null,
|
6466 |
|
6467 |
|
6468 | timestampOffset: null,
|
6469 |
|
6470 | timeline: segment.timeline,
|
6471 |
|
6472 | duration: segment.duration,
|
6473 |
|
6474 | segment: segment
|
6475 | };
|
6476 | }
|
6477 |
|
6478 | |
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 | }, {
|
6489 | key: 'abortRequestEarly_',
|
6490 | value: function abortRequestEarly_(stats) {
|
6491 | if (this.hls_.tech_.paused() ||
|
6492 |
|
6493 |
|
6494 |
|
6495 | !this.xhrOptions_.timeout ||
|
6496 |
|
6497 | !this.playlist_.attributes.BANDWIDTH) {
|
6498 | return false;
|
6499 | }
|
6500 |
|
6501 |
|
6502 |
|
6503 |
|
6504 | if (Date.now() - (stats.firstBytesReceivedAt || Date.now()) < 1000) {
|
6505 | return false;
|
6506 | }
|
6507 |
|
6508 | var currentTime = this.currentTime_();
|
6509 | var measuredBandwidth = stats.bandwidth;
|
6510 | var segmentDuration = this.pendingSegment_.duration;
|
6511 |
|
6512 | var requestTimeRemaining = _playlist2['default'].estimateSegmentRequestTime(segmentDuration, measuredBandwidth, this.playlist_, stats.bytesReceived);
|
6513 |
|
6514 |
|
6515 |
|
6516 |
|
6517 | var timeUntilRebuffer = (0, _ranges.timeUntilRebuffer)(this.buffered_(), currentTime, this.hls_.tech_.playbackRate()) - 1;
|
6518 |
|
6519 |
|
6520 |
|
6521 | if (requestTimeRemaining <= timeUntilRebuffer) {
|
6522 | return false;
|
6523 | }
|
6524 |
|
6525 | var switchCandidate = (0, _playlistSelectors.minRebufferMaxBandwidthSelector)({
|
6526 | master: this.hls_.playlists.master,
|
6527 | currentTime: currentTime,
|
6528 | bandwidth: measuredBandwidth,
|
6529 | duration: this.duration_(),
|
6530 | segmentDuration: segmentDuration,
|
6531 | timeUntilRebuffer: timeUntilRebuffer,
|
6532 | currentTimeline: this.currentTimeline_,
|
6533 | syncController: this.syncController_
|
6534 | });
|
6535 |
|
6536 | if (!switchCandidate) {
|
6537 | return;
|
6538 | }
|
6539 |
|
6540 | var rebufferingImpact = requestTimeRemaining - timeUntilRebuffer;
|
6541 |
|
6542 | var timeSavedBySwitching = rebufferingImpact - switchCandidate.rebufferingImpact;
|
6543 |
|
6544 | var minimumTimeSaving = 0.5;
|
6545 |
|
6546 |
|
6547 |
|
6548 |
|
6549 | if (timeUntilRebuffer <= _ranges.TIME_FUDGE_FACTOR) {
|
6550 | minimumTimeSaving = 1;
|
6551 | }
|
6552 |
|
6553 | if (!switchCandidate.playlist || switchCandidate.playlist.uri === this.playlist_.uri || timeSavedBySwitching < minimumTimeSaving) {
|
6554 | return false;
|
6555 | }
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 | this.bandwidth = switchCandidate.playlist.attributes.BANDWIDTH * _config2['default'].BANDWIDTH_VARIANCE + 1;
|
6561 | this.abort();
|
6562 | this.trigger('earlyabort');
|
6563 | return true;
|
6564 | }
|
6565 |
|
6566 | |
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 | }, {
|
6576 | key: 'handleProgress_',
|
6577 | value: function handleProgress_(event, simpleSegment) {
|
6578 | if (!this.pendingSegment_ || simpleSegment.requestId !== this.pendingSegment_.requestId || this.abortRequestEarly_(simpleSegment.stats)) {
|
6579 | return;
|
6580 | }
|
6581 |
|
6582 | this.trigger('progress');
|
6583 | }
|
6584 |
|
6585 | |
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 | }, {
|
6591 | key: 'loadSegment_',
|
6592 | value: function loadSegment_(segmentInfo) {
|
6593 | this.state = 'WAITING';
|
6594 | this.pendingSegment_ = segmentInfo;
|
6595 | this.trimBackBuffer_(segmentInfo);
|
6596 |
|
6597 | segmentInfo.abortRequests = (0, _mediaSegmentRequest.mediaSegmentRequest)(this.hls_.xhr, this.xhrOptions_, this.decrypter_, this.createSimplifiedSegmentObj_(segmentInfo),
|
6598 |
|
6599 | this.handleProgress_.bind(this), this.segmentRequestFinished_.bind(this));
|
6600 | }
|
6601 |
|
6602 | |
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 |
|
6609 |
|
6610 | }, {
|
6611 | key: 'trimBackBuffer_',
|
6612 | value: function trimBackBuffer_(segmentInfo) {
|
6613 | var removeToTime = safeBackBufferTrimTime(this.seekable_(), this.currentTime_(), this.playlist_.targetDuration || 10);
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 | if (removeToTime > 0) {
|
6622 | this.remove(0, removeToTime);
|
6623 | }
|
6624 | }
|
6625 |
|
6626 | |
6627 |
|
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 |
|
6633 |
|
6634 |
|
6635 | }, {
|
6636 | key: 'createSimplifiedSegmentObj_',
|
6637 | value: function createSimplifiedSegmentObj_(segmentInfo) {
|
6638 | var segment = segmentInfo.segment;
|
6639 | var simpleSegment = {
|
6640 | resolvedUri: segment.resolvedUri,
|
6641 | byterange: segment.byterange,
|
6642 | requestId: segmentInfo.requestId
|
6643 | };
|
6644 |
|
6645 | if (segment.key) {
|
6646 |
|
6647 |
|
6648 | var iv = segment.key.iv || new Uint32Array([0, 0, 0, segmentInfo.mediaIndex + segmentInfo.playlist.mediaSequence]);
|
6649 |
|
6650 | simpleSegment.key = {
|
6651 | resolvedUri: segment.key.resolvedUri,
|
6652 | iv: iv
|
6653 | };
|
6654 | }
|
6655 |
|
6656 | if (segment.map) {
|
6657 | simpleSegment.map = this.initSegment(segment.map);
|
6658 | }
|
6659 |
|
6660 | return simpleSegment;
|
6661 | }
|
6662 |
|
6663 | |
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 | }, {
|
6670 | key: 'segmentRequestFinished_',
|
6671 | value: function segmentRequestFinished_(error, simpleSegment) {
|
6672 |
|
6673 |
|
6674 | this.mediaRequests += 1;
|
6675 |
|
6676 | if (simpleSegment.stats) {
|
6677 | this.mediaBytesTransferred += simpleSegment.stats.bytesReceived;
|
6678 | this.mediaTransferDuration += simpleSegment.stats.roundTripTime;
|
6679 | }
|
6680 |
|
6681 |
|
6682 | if (!this.pendingSegment_) {
|
6683 | this.mediaRequestsAborted += 1;
|
6684 | return;
|
6685 | }
|
6686 |
|
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 | if (simpleSegment.requestId !== this.pendingSegment_.requestId) {
|
6692 | return;
|
6693 | }
|
6694 |
|
6695 |
|
6696 | if (error) {
|
6697 | this.pendingSegment_ = null;
|
6698 | this.state = 'READY';
|
6699 |
|
6700 |
|
6701 |
|
6702 |
|
6703 | if (error.code === _mediaSegmentRequest.REQUEST_ERRORS.ABORTED) {
|
6704 | this.mediaRequestsAborted += 1;
|
6705 | return;
|
6706 | }
|
6707 |
|
6708 | this.pause();
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 | if (error.code === _mediaSegmentRequest.REQUEST_ERRORS.TIMEOUT) {
|
6714 | this.mediaRequestsTimedout += 1;
|
6715 | this.bandwidth = 1;
|
6716 | this.roundTrip = NaN;
|
6717 | this.trigger('bandwidthupdate');
|
6718 | return;
|
6719 | }
|
6720 |
|
6721 |
|
6722 |
|
6723 | this.mediaRequestsErrored += 1;
|
6724 | this.error(error);
|
6725 | this.trigger('error');
|
6726 | return;
|
6727 | }
|
6728 |
|
6729 |
|
6730 |
|
6731 | this.bandwidth = simpleSegment.stats.bandwidth;
|
6732 | this.roundTrip = simpleSegment.stats.roundTripTime;
|
6733 |
|
6734 |
|
6735 |
|
6736 | if (simpleSegment.map) {
|
6737 | simpleSegment.map = this.initSegment(simpleSegment.map, true);
|
6738 | }
|
6739 |
|
6740 | this.processSegmentResponse_(simpleSegment);
|
6741 | }
|
6742 |
|
6743 | |
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 | }, {
|
6750 | key: 'processSegmentResponse_',
|
6751 | value: function processSegmentResponse_(simpleSegment) {
|
6752 | var segmentInfo = this.pendingSegment_;
|
6753 |
|
6754 | segmentInfo.bytes = simpleSegment.bytes;
|
6755 | if (simpleSegment.map) {
|
6756 | segmentInfo.segment.map.bytes = simpleSegment.map.bytes;
|
6757 | }
|
6758 |
|
6759 | segmentInfo.endOfAllRequests = simpleSegment.endOfAllRequests;
|
6760 | this.handleSegment_();
|
6761 | }
|
6762 |
|
6763 | |
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 | }, {
|
6769 | key: 'handleSegment_',
|
6770 | value: function handleSegment_() {
|
6771 | var _this3 = this;
|
6772 |
|
6773 | if (!this.pendingSegment_) {
|
6774 | this.state = 'READY';
|
6775 | return;
|
6776 | }
|
6777 |
|
6778 | var segmentInfo = this.pendingSegment_;
|
6779 | var segment = segmentInfo.segment;
|
6780 | var timingInfo = this.syncController_.probeSegmentInfo(segmentInfo);
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 | if (typeof this.startingMedia_ === 'undefined' && timingInfo && (
|
6786 |
|
6787 |
|
6788 | timingInfo.containsAudio || timingInfo.containsVideo)) {
|
6789 | this.startingMedia_ = {
|
6790 | containsAudio: timingInfo.containsAudio,
|
6791 | containsVideo: timingInfo.containsVideo
|
6792 | };
|
6793 | }
|
6794 |
|
6795 | var illegalMediaSwitchError = illegalMediaSwitch(this.loaderType_, this.startingMedia_, timingInfo);
|
6796 |
|
6797 | if (illegalMediaSwitchError) {
|
6798 | this.error({
|
6799 | message: illegalMediaSwitchError,
|
6800 | blacklistDuration: Infinity
|
6801 | });
|
6802 | this.trigger('error');
|
6803 | return;
|
6804 | }
|
6805 |
|
6806 | if (segmentInfo.isSyncRequest) {
|
6807 | this.trigger('syncinfoupdate');
|
6808 | this.pendingSegment_ = null;
|
6809 | this.state = 'READY';
|
6810 | return;
|
6811 | }
|
6812 |
|
6813 | if (segmentInfo.timestampOffset !== null && segmentInfo.timestampOffset !== this.sourceUpdater_.timestampOffset()) {
|
6814 | this.sourceUpdater_.timestampOffset(segmentInfo.timestampOffset);
|
6815 |
|
6816 | this.trigger('timestampoffset');
|
6817 | }
|
6818 |
|
6819 | var timelineMapping = this.syncController_.mappingForTimeline(segmentInfo.timeline);
|
6820 |
|
6821 | if (timelineMapping !== null) {
|
6822 | this.trigger({
|
6823 | type: 'segmenttimemapping',
|
6824 | mapping: timelineMapping
|
6825 | });
|
6826 | }
|
6827 |
|
6828 | this.state = 'APPENDING';
|
6829 |
|
6830 |
|
6831 |
|
6832 | if (segment.map) {
|
6833 | (function () {
|
6834 | var initId = (0, _binUtils.initSegmentId)(segment.map);
|
6835 |
|
6836 | if (!_this3.activeInitSegmentId_ || _this3.activeInitSegmentId_ !== initId) {
|
6837 | var initSegment = _this3.initSegment(segment.map);
|
6838 |
|
6839 | _this3.sourceUpdater_.appendBuffer(initSegment.bytes, function () {
|
6840 | _this3.activeInitSegmentId_ = initId;
|
6841 | });
|
6842 | }
|
6843 | })();
|
6844 | }
|
6845 |
|
6846 | segmentInfo.byteLength = segmentInfo.bytes.byteLength;
|
6847 | if (typeof segment.start === 'number' && typeof segment.end === 'number') {
|
6848 | this.mediaSecondsLoaded += segment.end - segment.start;
|
6849 | } else {
|
6850 | this.mediaSecondsLoaded += segment.duration;
|
6851 | }
|
6852 |
|
6853 | this.sourceUpdater_.appendBuffer(segmentInfo.bytes, this.handleUpdateEnd_.bind(this));
|
6854 | }
|
6855 |
|
6856 | |
6857 |
|
6858 |
|
6859 |
|
6860 |
|
6861 |
|
6862 |
|
6863 | }, {
|
6864 | key: 'handleUpdateEnd_',
|
6865 | value: function handleUpdateEnd_() {
|
6866 | this.logger_('handleUpdateEnd_', 'segmentInfo:', this.pendingSegment_);
|
6867 |
|
6868 | if (!this.pendingSegment_) {
|
6869 | this.state = 'READY';
|
6870 | if (!this.paused()) {
|
6871 | this.monitorBuffer_();
|
6872 | }
|
6873 | return;
|
6874 | }
|
6875 |
|
6876 | var segmentInfo = this.pendingSegment_;
|
6877 | var segment = segmentInfo.segment;
|
6878 | var isWalkingForward = this.mediaIndex !== null;
|
6879 |
|
6880 | this.pendingSegment_ = null;
|
6881 | this.recordThroughput_(segmentInfo);
|
6882 | this.addSegmentMetadataCue_(segmentInfo);
|
6883 |
|
6884 | this.state = 'READY';
|
6885 |
|
6886 | this.mediaIndex = segmentInfo.mediaIndex;
|
6887 | this.fetchAtBuffer_ = true;
|
6888 | this.currentTimeline_ = segmentInfo.timeline;
|
6889 |
|
6890 |
|
6891 |
|
6892 |
|
6893 |
|
6894 | this.trigger('syncinfoupdate');
|
6895 |
|
6896 |
|
6897 |
|
6898 |
|
6899 |
|
6900 | if (segment.end && this.currentTime_() - segment.end > segmentInfo.playlist.targetDuration * 3) {
|
6901 | this.resetEverything();
|
6902 | return;
|
6903 | }
|
6904 |
|
6905 |
|
6906 |
|
6907 | if (isWalkingForward) {
|
6908 | this.trigger('bandwidthupdate');
|
6909 | }
|
6910 | this.trigger('progress');
|
6911 |
|
6912 |
|
6913 |
|
6914 |
|
6915 | var isEndOfStream = detectEndOfStream(segmentInfo.playlist, this.mediaSource_, segmentInfo.mediaIndex + 1);
|
6916 |
|
6917 | if (isEndOfStream) {
|
6918 | this.endOfStream();
|
6919 | }
|
6920 |
|
6921 | if (!this.paused()) {
|
6922 | this.monitorBuffer_();
|
6923 | }
|
6924 | }
|
6925 |
|
6926 | |
6927 |
|
6928 |
|
6929 |
|
6930 |
|
6931 |
|
6932 |
|
6933 |
|
6934 |
|
6935 | }, {
|
6936 | key: 'recordThroughput_',
|
6937 | value: function recordThroughput_(segmentInfo) {
|
6938 | var rate = this.throughput.rate;
|
6939 |
|
6940 |
|
6941 | var segmentProcessingTime = Date.now() - segmentInfo.endOfAllRequests + 1;
|
6942 |
|
6943 | var segmentProcessingThroughput = Math.floor(segmentInfo.byteLength / segmentProcessingTime * 8 * 1000);
|
6944 |
|
6945 |
|
6946 |
|
6947 | this.throughput.rate += (segmentProcessingThroughput - rate) / ++this.throughput.count;
|
6948 | }
|
6949 |
|
6950 | |
6951 |
|
6952 |
|
6953 |
|
6954 |
|
6955 |
|
6956 | }, {
|
6957 | key: 'logger_',
|
6958 | value: function logger_() {}
|
6959 |
|
6960 | |
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 | }, {
|
6970 | key: 'addSegmentMetadataCue_',
|
6971 | value: function addSegmentMetadataCue_(segmentInfo) {
|
6972 | if (!this.segmentMetadataTrack_) {
|
6973 | return;
|
6974 | }
|
6975 |
|
6976 | var segment = segmentInfo.segment;
|
6977 | var start = segment.start;
|
6978 | var end = segment.end;
|
6979 |
|
6980 |
|
6981 | if (!finite(start) || !finite(end)) {
|
6982 | return;
|
6983 | }
|
6984 |
|
6985 | (0, _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs2['default'])(start, end, this.segmentMetadataTrack_);
|
6986 |
|
6987 | var Cue = _globalWindow2['default'].WebKitDataCue || _globalWindow2['default'].VTTCue;
|
6988 | var value = {
|
6989 | uri: segmentInfo.uri,
|
6990 | timeline: segmentInfo.timeline,
|
6991 | playlist: segmentInfo.playlist.uri,
|
6992 | start: start,
|
6993 | end: end
|
6994 | };
|
6995 | var data = JSON.stringify(value);
|
6996 | var cue = new Cue(start, end, data);
|
6997 |
|
6998 |
|
6999 |
|
7000 | cue.value = value;
|
7001 |
|
7002 | this.segmentMetadataTrack_.addCue(cue);
|
7003 | }
|
7004 | }]);
|
7005 |
|
7006 | return SegmentLoader;
|
7007 | })(_videoJs2['default'].EventTarget);
|
7008 |
|
7009 | exports['default'] = SegmentLoader;
|
7010 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7011 | },{"./bin-utils":2,"./config":3,"./media-segment-request":7,"./playlist":11,"./playlist-selectors":10,"./ranges":12,"./source-updater":17,"global/window":32,"videojs-contrib-media-sources/es5/remove-cues-from-track.js":72}],17:[function(require,module,exports){
|
7012 | (function (global){
|
7013 |
|
7014 |
|
7015 |
|
7016 | 'use strict';
|
7017 |
|
7018 | Object.defineProperty(exports, '__esModule', {
|
7019 | value: true
|
7020 | });
|
7021 |
|
7022 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
7023 |
|
7024 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
7025 |
|
7026 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
7027 |
|
7028 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
7029 |
|
7030 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
7031 |
|
7032 | var noop = function noop() {};
|
7033 |
|
7034 |
|
7035 |
|
7036 |
|
7037 |
|
7038 |
|
7039 |
|
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 |
|
7046 |
|
7047 | var SourceUpdater = (function () {
|
7048 | function SourceUpdater(mediaSource, mimeType) {
|
7049 | var _this = this;
|
7050 |
|
7051 | _classCallCheck(this, SourceUpdater);
|
7052 |
|
7053 | var createSourceBuffer = function createSourceBuffer() {
|
7054 | _this.sourceBuffer_ = mediaSource.addSourceBuffer(mimeType);
|
7055 |
|
7056 |
|
7057 |
|
7058 | _this.onUpdateendCallback_ = function () {
|
7059 | var pendingCallback = _this.pendingCallback_;
|
7060 |
|
7061 | _this.pendingCallback_ = null;
|
7062 |
|
7063 | if (pendingCallback) {
|
7064 | pendingCallback();
|
7065 | }
|
7066 |
|
7067 | _this.runCallback_();
|
7068 | };
|
7069 |
|
7070 | _this.sourceBuffer_.addEventListener('updateend', _this.onUpdateendCallback_);
|
7071 |
|
7072 | _this.runCallback_();
|
7073 | };
|
7074 |
|
7075 | this.callbacks_ = [];
|
7076 | this.pendingCallback_ = null;
|
7077 | this.timestampOffset_ = 0;
|
7078 | this.mediaSource = mediaSource;
|
7079 | this.processedAppend_ = false;
|
7080 |
|
7081 | if (mediaSource.readyState === 'closed') {
|
7082 | mediaSource.addEventListener('sourceopen', createSourceBuffer);
|
7083 | } else {
|
7084 | createSourceBuffer();
|
7085 | }
|
7086 | }
|
7087 |
|
7088 | |
7089 |
|
7090 |
|
7091 |
|
7092 |
|
7093 |
|
7094 |
|
7095 | _createClass(SourceUpdater, [{
|
7096 | key: 'abort',
|
7097 | value: function abort(done) {
|
7098 | var _this2 = this;
|
7099 |
|
7100 | if (this.processedAppend_) {
|
7101 | this.queueCallback_(function () {
|
7102 | _this2.sourceBuffer_.abort();
|
7103 | }, done);
|
7104 | }
|
7105 | }
|
7106 |
|
7107 | |
7108 |
|
7109 |
|
7110 |
|
7111 |
|
7112 |
|
7113 |
|
7114 | }, {
|
7115 | key: 'appendBuffer',
|
7116 | value: function appendBuffer(bytes, done) {
|
7117 | var _this3 = this;
|
7118 |
|
7119 | this.processedAppend_ = true;
|
7120 | this.queueCallback_(function () {
|
7121 | _this3.sourceBuffer_.appendBuffer(bytes);
|
7122 | }, done);
|
7123 | }
|
7124 |
|
7125 | |
7126 |
|
7127 |
|
7128 |
|
7129 |
|
7130 | }, {
|
7131 | key: 'buffered',
|
7132 | value: function buffered() {
|
7133 | if (!this.sourceBuffer_) {
|
7134 | return _videoJs2['default'].createTimeRanges();
|
7135 | }
|
7136 | return this.sourceBuffer_.buffered;
|
7137 | }
|
7138 |
|
7139 | |
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 | }, {
|
7147 | key: 'remove',
|
7148 | value: function remove(start, end) {
|
7149 | var _this4 = this;
|
7150 |
|
7151 | if (this.processedAppend_) {
|
7152 | this.queueCallback_(function () {
|
7153 | _this4.sourceBuffer_.remove(start, end);
|
7154 | }, noop);
|
7155 | }
|
7156 | }
|
7157 |
|
7158 | |
7159 |
|
7160 |
|
7161 |
|
7162 |
|
7163 | }, {
|
7164 | key: 'updating',
|
7165 | value: function updating() {
|
7166 | return !this.sourceBuffer_ || this.sourceBuffer_.updating || this.pendingCallback_;
|
7167 | }
|
7168 |
|
7169 | |
7170 |
|
7171 |
|
7172 |
|
7173 |
|
7174 | }, {
|
7175 | key: 'timestampOffset',
|
7176 | value: function timestampOffset(offset) {
|
7177 | var _this5 = this;
|
7178 |
|
7179 | if (typeof offset !== 'undefined') {
|
7180 | this.queueCallback_(function () {
|
7181 | _this5.sourceBuffer_.timestampOffset = offset;
|
7182 | });
|
7183 | this.timestampOffset_ = offset;
|
7184 | }
|
7185 | return this.timestampOffset_;
|
7186 | }
|
7187 |
|
7188 | |
7189 |
|
7190 |
|
7191 | }, {
|
7192 | key: 'queueCallback_',
|
7193 | value: function queueCallback_(callback, done) {
|
7194 | this.callbacks_.push([callback.bind(this), done]);
|
7195 | this.runCallback_();
|
7196 | }
|
7197 |
|
7198 | |
7199 |
|
7200 |
|
7201 | }, {
|
7202 | key: 'runCallback_',
|
7203 | value: function runCallback_() {
|
7204 | var callbacks = undefined;
|
7205 |
|
7206 | if (!this.updating() && this.callbacks_.length) {
|
7207 | callbacks = this.callbacks_.shift();
|
7208 | this.pendingCallback_ = callbacks[1];
|
7209 | callbacks[0]();
|
7210 | }
|
7211 | }
|
7212 |
|
7213 | |
7214 |
|
7215 |
|
7216 | }, {
|
7217 | key: 'dispose',
|
7218 | value: function dispose() {
|
7219 | this.sourceBuffer_.removeEventListener('updateend', this.onUpdateendCallback_);
|
7220 | if (this.sourceBuffer_ && this.mediaSource.readyState === 'open') {
|
7221 | this.sourceBuffer_.abort();
|
7222 | }
|
7223 | }
|
7224 | }]);
|
7225 |
|
7226 | return SourceUpdater;
|
7227 | })();
|
7228 |
|
7229 | exports['default'] = SourceUpdater;
|
7230 | module.exports = exports['default'];
|
7231 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7232 | },{}],18:[function(require,module,exports){
|
7233 | (function (global){
|
7234 |
|
7235 |
|
7236 |
|
7237 |
|
7238 | 'use strict';
|
7239 |
|
7240 | Object.defineProperty(exports, '__esModule', {
|
7241 | value: true
|
7242 | });
|
7243 |
|
7244 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
7245 |
|
7246 | var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
7247 |
|
7248 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
7249 |
|
7250 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
7251 |
|
7252 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
7253 |
|
7254 | var _muxJsLibMp4Probe = require('mux.js/lib/mp4/probe');
|
7255 |
|
7256 | var _muxJsLibMp4Probe2 = _interopRequireDefault(_muxJsLibMp4Probe);
|
7257 |
|
7258 | var _muxJsLibToolsTsInspectorJs = require('mux.js/lib/tools/ts-inspector.js');
|
7259 |
|
7260 | var _playlist = require('./playlist');
|
7261 |
|
7262 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
7263 |
|
7264 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
7265 |
|
7266 | var syncPointStrategies = [
|
7267 |
|
7268 |
|
7269 | {
|
7270 | name: 'VOD',
|
7271 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
7272 | if (duration !== Infinity) {
|
7273 | var syncPoint = {
|
7274 | time: 0,
|
7275 | segmentIndex: 0
|
7276 | };
|
7277 |
|
7278 | return syncPoint;
|
7279 | }
|
7280 | return null;
|
7281 | }
|
7282 | },
|
7283 |
|
7284 | {
|
7285 | name: 'ProgramDateTime',
|
7286 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
7287 | if (syncController.datetimeToDisplayTime && playlist.dateTimeObject) {
|
7288 | var playlistTime = playlist.dateTimeObject.getTime() / 1000;
|
7289 | var playlistStart = playlistTime + syncController.datetimeToDisplayTime;
|
7290 | var syncPoint = {
|
7291 | time: playlistStart,
|
7292 | segmentIndex: 0
|
7293 | };
|
7294 |
|
7295 | return syncPoint;
|
7296 | }
|
7297 | return null;
|
7298 | }
|
7299 | },
|
7300 |
|
7301 |
|
7302 | {
|
7303 | name: 'Segment',
|
7304 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
7305 | var segments = playlist.segments || [];
|
7306 | var syncPoint = null;
|
7307 | var lastDistance = null;
|
7308 |
|
7309 | currentTime = currentTime || 0;
|
7310 |
|
7311 | for (var i = 0; i < segments.length; i++) {
|
7312 | var segment = segments[i];
|
7313 |
|
7314 | if (segment.timeline === currentTimeline && typeof segment.start !== 'undefined') {
|
7315 | var distance = Math.abs(currentTime - segment.start);
|
7316 |
|
7317 |
|
7318 |
|
7319 | if (lastDistance !== null && lastDistance < distance) {
|
7320 | break;
|
7321 | }
|
7322 |
|
7323 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
7324 | lastDistance = distance;
|
7325 | syncPoint = {
|
7326 | time: segment.start,
|
7327 | segmentIndex: i
|
7328 | };
|
7329 | }
|
7330 | }
|
7331 | }
|
7332 | return syncPoint;
|
7333 | }
|
7334 | },
|
7335 |
|
7336 |
|
7337 | {
|
7338 | name: 'Discontinuity',
|
7339 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
7340 | var syncPoint = null;
|
7341 |
|
7342 | currentTime = currentTime || 0;
|
7343 |
|
7344 | if (playlist.discontinuityStarts && playlist.discontinuityStarts.length) {
|
7345 | var lastDistance = null;
|
7346 |
|
7347 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
7348 | var segmentIndex = playlist.discontinuityStarts[i];
|
7349 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
7350 | var discontinuitySync = syncController.discontinuities[discontinuity];
|
7351 |
|
7352 | if (discontinuitySync) {
|
7353 | var distance = Math.abs(currentTime - discontinuitySync.time);
|
7354 |
|
7355 |
|
7356 |
|
7357 | if (lastDistance !== null && lastDistance < distance) {
|
7358 | break;
|
7359 | }
|
7360 |
|
7361 | if (!syncPoint || lastDistance === null || lastDistance >= distance) {
|
7362 | lastDistance = distance;
|
7363 | syncPoint = {
|
7364 | time: discontinuitySync.time,
|
7365 | segmentIndex: segmentIndex
|
7366 | };
|
7367 | }
|
7368 | }
|
7369 | }
|
7370 | }
|
7371 | return syncPoint;
|
7372 | }
|
7373 | },
|
7374 |
|
7375 |
|
7376 | {
|
7377 | name: 'Playlist',
|
7378 | run: function run(syncController, playlist, duration, currentTimeline, currentTime) {
|
7379 | if (playlist.syncInfo) {
|
7380 | var syncPoint = {
|
7381 | time: playlist.syncInfo.time,
|
7382 | segmentIndex: playlist.syncInfo.mediaSequence - playlist.mediaSequence
|
7383 | };
|
7384 |
|
7385 | return syncPoint;
|
7386 | }
|
7387 | return null;
|
7388 | }
|
7389 | }];
|
7390 |
|
7391 | exports.syncPointStrategies = syncPointStrategies;
|
7392 |
|
7393 | var SyncController = (function (_videojs$EventTarget) {
|
7394 | _inherits(SyncController, _videojs$EventTarget);
|
7395 |
|
7396 | function SyncController() {
|
7397 | var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
7398 |
|
7399 | _classCallCheck(this, SyncController);
|
7400 |
|
7401 | _get(Object.getPrototypeOf(SyncController.prototype), 'constructor', this).call(this);
|
7402 |
|
7403 |
|
7404 | this.inspectCache_ = undefined;
|
7405 |
|
7406 |
|
7407 | this.timelines = [];
|
7408 | this.discontinuities = [];
|
7409 | this.datetimeToDisplayTime = null;
|
7410 |
|
7411 | if (options.debug) {
|
7412 | this.logger_ = _videoJs2['default'].log.bind(_videoJs2['default'], 'sync-controller ->');
|
7413 | }
|
7414 | }
|
7415 |
|
7416 | |
7417 |
|
7418 |
|
7419 |
|
7420 |
|
7421 |
|
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 |
|
7428 |
|
7429 |
|
7430 |
|
7431 |
|
7432 | _createClass(SyncController, [{
|
7433 | key: 'getSyncPoint',
|
7434 | value: function getSyncPoint(playlist, duration, currentTimeline, currentTime) {
|
7435 | var syncPoints = this.runStrategies_(playlist, duration, currentTimeline, currentTime);
|
7436 |
|
7437 | if (!syncPoints.length) {
|
7438 |
|
7439 |
|
7440 |
|
7441 | return null;
|
7442 | }
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 | return this.selectSyncPoint_(syncPoints, { key: 'time', value: currentTime });
|
7448 | }
|
7449 |
|
7450 | |
7451 |
|
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 |
|
7461 | }, {
|
7462 | key: 'getExpiredTime',
|
7463 | value: function getExpiredTime(playlist, duration) {
|
7464 | if (!playlist || !playlist.segments) {
|
7465 | return null;
|
7466 | }
|
7467 |
|
7468 | var syncPoints = this.runStrategies_(playlist, duration, playlist.discontinuitySequence, 0);
|
7469 |
|
7470 |
|
7471 | if (!syncPoints.length) {
|
7472 | return null;
|
7473 | }
|
7474 |
|
7475 | var syncPoint = this.selectSyncPoint_(syncPoints, {
|
7476 | key: 'segmentIndex',
|
7477 | value: 0
|
7478 | });
|
7479 |
|
7480 |
|
7481 |
|
7482 | if (syncPoint.segmentIndex > 0) {
|
7483 | syncPoint.time *= -1;
|
7484 | }
|
7485 |
|
7486 | return Math.abs(syncPoint.time + (0, _playlist.sumDurations)(playlist, syncPoint.segmentIndex, 0));
|
7487 | }
|
7488 |
|
7489 | |
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 |
|
7495 |
|
7496 |
|
7497 |
|
7498 |
|
7499 |
|
7500 |
|
7501 |
|
7502 |
|
7503 | }, {
|
7504 | key: 'runStrategies_',
|
7505 | value: function runStrategies_(playlist, duration, currentTimeline, currentTime) {
|
7506 | var syncPoints = [];
|
7507 |
|
7508 |
|
7509 | for (var i = 0; i < syncPointStrategies.length; i++) {
|
7510 | var strategy = syncPointStrategies[i];
|
7511 | var syncPoint = strategy.run(this, playlist, duration, currentTimeline, currentTime);
|
7512 |
|
7513 | if (syncPoint) {
|
7514 | syncPoint.strategy = strategy.name;
|
7515 | syncPoints.push({
|
7516 | strategy: strategy.name,
|
7517 | syncPoint: syncPoint
|
7518 | });
|
7519 | this.logger_('syncPoint found via <' + strategy.name + '>:', syncPoint);
|
7520 | }
|
7521 | }
|
7522 |
|
7523 | return syncPoints;
|
7524 | }
|
7525 |
|
7526 | |
7527 |
|
7528 |
|
7529 |
|
7530 |
|
7531 |
|
7532 |
|
7533 |
|
7534 |
|
7535 |
|
7536 |
|
7537 |
|
7538 |
|
7539 |
|
7540 |
|
7541 | }, {
|
7542 | key: 'selectSyncPoint_',
|
7543 | value: function selectSyncPoint_(syncPoints, target) {
|
7544 | var bestSyncPoint = syncPoints[0].syncPoint;
|
7545 | var bestDistance = Math.abs(syncPoints[0].syncPoint[target.key] - target.value);
|
7546 | var bestStrategy = syncPoints[0].strategy;
|
7547 |
|
7548 | for (var i = 1; i < syncPoints.length; i++) {
|
7549 | var newDistance = Math.abs(syncPoints[i].syncPoint[target.key] - target.value);
|
7550 |
|
7551 | if (newDistance < bestDistance) {
|
7552 | bestDistance = newDistance;
|
7553 | bestSyncPoint = syncPoints[i].syncPoint;
|
7554 | bestStrategy = syncPoints[i].strategy;
|
7555 | }
|
7556 | }
|
7557 |
|
7558 | this.logger_('syncPoint with strategy <' + bestStrategy + '> chosen: ', bestSyncPoint);
|
7559 | return bestSyncPoint;
|
7560 | }
|
7561 |
|
7562 | |
7563 |
|
7564 |
|
7565 |
|
7566 |
|
7567 |
|
7568 |
|
7569 |
|
7570 | }, {
|
7571 | key: 'saveExpiredSegmentInfo',
|
7572 | value: function saveExpiredSegmentInfo(oldPlaylist, newPlaylist) {
|
7573 | var mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
7574 |
|
7575 |
|
7576 |
|
7577 | for (var i = mediaSequenceDiff - 1; i >= 0; i--) {
|
7578 | var lastRemovedSegment = oldPlaylist.segments[i];
|
7579 |
|
7580 | if (lastRemovedSegment && typeof lastRemovedSegment.start !== 'undefined') {
|
7581 | newPlaylist.syncInfo = {
|
7582 | mediaSequence: oldPlaylist.mediaSequence + i,
|
7583 | time: lastRemovedSegment.start
|
7584 | };
|
7585 | this.logger_('playlist sync:', newPlaylist.syncInfo);
|
7586 | this.trigger('syncinfoupdate');
|
7587 | break;
|
7588 | }
|
7589 | }
|
7590 | }
|
7591 |
|
7592 | |
7593 |
|
7594 |
|
7595 |
|
7596 |
|
7597 |
|
7598 | }, {
|
7599 | key: 'setDateTimeMapping',
|
7600 | value: function setDateTimeMapping(playlist) {
|
7601 | if (!this.datetimeToDisplayTime && playlist.dateTimeObject) {
|
7602 | var playlistTimestamp = playlist.dateTimeObject.getTime() / 1000;
|
7603 |
|
7604 | this.datetimeToDisplayTime = -playlistTimestamp;
|
7605 | }
|
7606 | }
|
7607 |
|
7608 | |
7609 |
|
7610 |
|
7611 |
|
7612 | }, {
|
7613 | key: 'reset',
|
7614 | value: function reset() {
|
7615 | this.inspectCache_ = undefined;
|
7616 | }
|
7617 |
|
7618 | |
7619 |
|
7620 |
|
7621 |
|
7622 |
|
7623 |
|
7624 |
|
7625 |
|
7626 | }, {
|
7627 | key: 'probeSegmentInfo',
|
7628 | value: function probeSegmentInfo(segmentInfo) {
|
7629 | var segment = segmentInfo.segment;
|
7630 | var playlist = segmentInfo.playlist;
|
7631 | var timingInfo = undefined;
|
7632 |
|
7633 | if (segment.map) {
|
7634 | timingInfo = this.probeMp4Segment_(segmentInfo);
|
7635 | } else {
|
7636 | timingInfo = this.probeTsSegment_(segmentInfo);
|
7637 | }
|
7638 |
|
7639 | if (timingInfo) {
|
7640 | if (this.calculateSegmentTimeMapping_(segmentInfo, timingInfo)) {
|
7641 | this.saveDiscontinuitySyncInfo_(segmentInfo);
|
7642 |
|
7643 |
|
7644 |
|
7645 | if (!playlist.syncInfo) {
|
7646 | playlist.syncInfo = {
|
7647 | mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
|
7648 | time: segment.start
|
7649 | };
|
7650 | }
|
7651 | }
|
7652 | }
|
7653 |
|
7654 | return timingInfo;
|
7655 | }
|
7656 |
|
7657 | |
7658 |
|
7659 |
|
7660 |
|
7661 |
|
7662 |
|
7663 |
|
7664 |
|
7665 | }, {
|
7666 | key: 'probeMp4Segment_',
|
7667 | value: function probeMp4Segment_(segmentInfo) {
|
7668 | var segment = segmentInfo.segment;
|
7669 | var timescales = _muxJsLibMp4Probe2['default'].timescale(segment.map.bytes);
|
7670 | var startTime = _muxJsLibMp4Probe2['default'].startTime(timescales, segmentInfo.bytes);
|
7671 |
|
7672 | if (segmentInfo.timestampOffset !== null) {
|
7673 | segmentInfo.timestampOffset -= startTime;
|
7674 | }
|
7675 |
|
7676 | return {
|
7677 | start: startTime,
|
7678 | end: startTime + segment.duration
|
7679 | };
|
7680 | }
|
7681 |
|
7682 | |
7683 |
|
7684 |
|
7685 |
|
7686 |
|
7687 |
|
7688 |
|
7689 |
|
7690 | }, {
|
7691 | key: 'probeTsSegment_',
|
7692 | value: function probeTsSegment_(segmentInfo) {
|
7693 | var timeInfo = (0, _muxJsLibToolsTsInspectorJs.inspect)(segmentInfo.bytes, this.inspectCache_);
|
7694 | var segmentStartTime = undefined;
|
7695 | var segmentEndTime = undefined;
|
7696 |
|
7697 | if (!timeInfo) {
|
7698 | return null;
|
7699 | }
|
7700 |
|
7701 | if (timeInfo.video && timeInfo.video.length === 2) {
|
7702 | this.inspectCache_ = timeInfo.video[1].dts;
|
7703 | segmentStartTime = timeInfo.video[0].dtsTime;
|
7704 | segmentEndTime = timeInfo.video[1].dtsTime;
|
7705 | } else if (timeInfo.audio && timeInfo.audio.length === 2) {
|
7706 | this.inspectCache_ = timeInfo.audio[1].dts;
|
7707 | segmentStartTime = timeInfo.audio[0].dtsTime;
|
7708 | segmentEndTime = timeInfo.audio[1].dtsTime;
|
7709 | }
|
7710 |
|
7711 | return {
|
7712 | start: segmentStartTime,
|
7713 | end: segmentEndTime,
|
7714 | containsVideo: timeInfo.video && timeInfo.video.length === 2,
|
7715 | containsAudio: timeInfo.audio && timeInfo.audio.length === 2
|
7716 | };
|
7717 | }
|
7718 | }, {
|
7719 | key: 'timestampOffsetForTimeline',
|
7720 | value: function timestampOffsetForTimeline(timeline) {
|
7721 | if (typeof this.timelines[timeline] === 'undefined') {
|
7722 | return null;
|
7723 | }
|
7724 | return this.timelines[timeline].time;
|
7725 | }
|
7726 | }, {
|
7727 | key: 'mappingForTimeline',
|
7728 | value: function mappingForTimeline(timeline) {
|
7729 | if (typeof this.timelines[timeline] === 'undefined') {
|
7730 | return null;
|
7731 | }
|
7732 | return this.timelines[timeline].mapping;
|
7733 | }
|
7734 |
|
7735 | |
7736 |
|
7737 |
|
7738 |
|
7739 |
|
7740 |
|
7741 |
|
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 |
|
7747 | }, {
|
7748 | key: 'calculateSegmentTimeMapping_',
|
7749 | value: function calculateSegmentTimeMapping_(segmentInfo, timingInfo) {
|
7750 | var segment = segmentInfo.segment;
|
7751 | var mappingObj = this.timelines[segmentInfo.timeline];
|
7752 |
|
7753 | if (segmentInfo.timestampOffset !== null) {
|
7754 | this.logger_('tsO:', segmentInfo.timestampOffset);
|
7755 |
|
7756 | mappingObj = {
|
7757 | time: segmentInfo.startOfSegment,
|
7758 | mapping: segmentInfo.startOfSegment - timingInfo.start
|
7759 | };
|
7760 | this.timelines[segmentInfo.timeline] = mappingObj;
|
7761 | this.trigger('timestampoffset');
|
7762 |
|
7763 | segment.start = segmentInfo.startOfSegment;
|
7764 | segment.end = timingInfo.end + mappingObj.mapping;
|
7765 | } else if (mappingObj) {
|
7766 | segment.start = timingInfo.start + mappingObj.mapping;
|
7767 | segment.end = timingInfo.end + mappingObj.mapping;
|
7768 | } else {
|
7769 | return false;
|
7770 | }
|
7771 |
|
7772 | return true;
|
7773 | }
|
7774 |
|
7775 | |
7776 |
|
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 |
|
7782 |
|
7783 | }, {
|
7784 | key: 'saveDiscontinuitySyncInfo_',
|
7785 | value: function saveDiscontinuitySyncInfo_(segmentInfo) {
|
7786 | var playlist = segmentInfo.playlist;
|
7787 | var segment = segmentInfo.segment;
|
7788 |
|
7789 |
|
7790 |
|
7791 |
|
7792 | if (segment.discontinuity) {
|
7793 | this.discontinuities[segment.timeline] = {
|
7794 | time: segment.start,
|
7795 | accuracy: 0
|
7796 | };
|
7797 | } else if (playlist.discontinuityStarts.length) {
|
7798 |
|
7799 |
|
7800 | for (var i = 0; i < playlist.discontinuityStarts.length; i++) {
|
7801 | var segmentIndex = playlist.discontinuityStarts[i];
|
7802 | var discontinuity = playlist.discontinuitySequence + i + 1;
|
7803 | var mediaIndexDiff = segmentIndex - segmentInfo.mediaIndex;
|
7804 | var accuracy = Math.abs(mediaIndexDiff);
|
7805 |
|
7806 | if (!this.discontinuities[discontinuity] || this.discontinuities[discontinuity].accuracy > accuracy) {
|
7807 | var time = undefined;
|
7808 |
|
7809 | if (mediaIndexDiff < 0) {
|
7810 | time = segment.start - (0, _playlist.sumDurations)(playlist, segmentInfo.mediaIndex, segmentIndex);
|
7811 | } else {
|
7812 | time = segment.end + (0, _playlist.sumDurations)(playlist, segmentInfo.mediaIndex + 1, segmentIndex);
|
7813 | }
|
7814 |
|
7815 | this.discontinuities[discontinuity] = {
|
7816 | time: time,
|
7817 | accuracy: accuracy
|
7818 | };
|
7819 | }
|
7820 | }
|
7821 | }
|
7822 | }
|
7823 |
|
7824 | |
7825 |
|
7826 |
|
7827 |
|
7828 |
|
7829 |
|
7830 | }, {
|
7831 | key: 'logger_',
|
7832 | value: function logger_() {}
|
7833 | }]);
|
7834 |
|
7835 | return SyncController;
|
7836 | })(_videoJs2['default'].EventTarget);
|
7837 |
|
7838 | exports['default'] = SyncController;
|
7839 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7840 | },{"./playlist":11,"mux.js/lib/mp4/probe":57,"mux.js/lib/tools/ts-inspector.js":59}],19:[function(require,module,exports){
|
7841 |
|
7842 |
|
7843 |
|
7844 |
|
7845 |
|
7846 |
|
7847 |
|
7848 |
|
7849 |
|
7850 |
|
7851 |
|
7852 | 'use strict';
|
7853 |
|
7854 | Object.defineProperty(exports, '__esModule', {
|
7855 | value: true
|
7856 | });
|
7857 | var parseCodecs = function parseCodecs() {
|
7858 | var codecs = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
|
7859 |
|
7860 | var result = {
|
7861 | codecCount: 0
|
7862 | };
|
7863 | var parsed = undefined;
|
7864 |
|
7865 | result.codecCount = codecs.split(',').length;
|
7866 | result.codecCount = result.codecCount || 2;
|
7867 |
|
7868 |
|
7869 | parsed = /(^|\s|,)+(avc1)([^ ,]*)/i.exec(codecs);
|
7870 | if (parsed) {
|
7871 | result.videoCodec = parsed[2];
|
7872 | result.videoObjectTypeIndicator = parsed[3];
|
7873 | }
|
7874 |
|
7875 |
|
7876 | result.audioProfile = /(^|\s|,)+mp4a.[0-9A-Fa-f]+\.([0-9A-Fa-f]+)/i.exec(codecs);
|
7877 | result.audioProfile = result.audioProfile && result.audioProfile[2];
|
7878 |
|
7879 | return result;
|
7880 | };
|
7881 | exports.parseCodecs = parseCodecs;
|
7882 | },{}],20:[function(require,module,exports){
|
7883 | (function (global){
|
7884 |
|
7885 |
|
7886 |
|
7887 | 'use strict';
|
7888 |
|
7889 | Object.defineProperty(exports, '__esModule', {
|
7890 | value: true
|
7891 | });
|
7892 |
|
7893 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
7894 |
|
7895 | var _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { var object = _x3, property = _x4, receiver = _x5; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
7896 |
|
7897 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
7898 |
|
7899 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
7900 |
|
7901 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
7902 |
|
7903 | var _segmentLoader = require('./segment-loader');
|
7904 |
|
7905 | var _segmentLoader2 = _interopRequireDefault(_segmentLoader);
|
7906 |
|
7907 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
7908 |
|
7909 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
7910 |
|
7911 | var _globalWindow = require('global/window');
|
7912 |
|
7913 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
7914 |
|
7915 | var _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs = require('videojs-contrib-media-sources/es5/remove-cues-from-track.js');
|
7916 |
|
7917 | var _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs2 = _interopRequireDefault(_videojsContribMediaSourcesEs5RemoveCuesFromTrackJs);
|
7918 |
|
7919 | var _binUtils = require('./bin-utils');
|
7920 |
|
7921 | var VTT_LINE_TERMINATORS = new Uint8Array('\n\n'.split('').map(function (char) {
|
7922 | return char.charCodeAt(0);
|
7923 | }));
|
7924 |
|
7925 | var uintToString = function uintToString(uintArray) {
|
7926 | return String.fromCharCode.apply(null, uintArray);
|
7927 | };
|
7928 |
|
7929 |
|
7930 |
|
7931 |
|
7932 |
|
7933 |
|
7934 |
|
7935 |
|
7936 |
|
7937 | var VTTSegmentLoader = (function (_SegmentLoader) {
|
7938 | _inherits(VTTSegmentLoader, _SegmentLoader);
|
7939 |
|
7940 | function VTTSegmentLoader(settings) {
|
7941 | var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
7942 |
|
7943 | _classCallCheck(this, VTTSegmentLoader);
|
7944 |
|
7945 | _get(Object.getPrototypeOf(VTTSegmentLoader.prototype), 'constructor', this).call(this, settings, options);
|
7946 |
|
7947 |
|
7948 |
|
7949 | this.mediaSource_ = null;
|
7950 |
|
7951 | this.subtitlesTrack_ = null;
|
7952 | }
|
7953 |
|
7954 | |
7955 |
|
7956 |
|
7957 |
|
7958 |
|
7959 |
|
7960 |
|
7961 | _createClass(VTTSegmentLoader, [{
|
7962 | key: 'buffered_',
|
7963 | value: function buffered_() {
|
7964 | if (!this.subtitlesTrack_ || !this.subtitlesTrack_.cues.length) {
|
7965 | return _videoJs2['default'].createTimeRanges();
|
7966 | }
|
7967 |
|
7968 | var cues = this.subtitlesTrack_.cues;
|
7969 | var start = cues[0].startTime;
|
7970 | var end = cues[cues.length - 1].startTime;
|
7971 |
|
7972 | return _videoJs2['default'].createTimeRanges([[start, end]]);
|
7973 | }
|
7974 |
|
7975 | |
7976 |
|
7977 |
|
7978 |
|
7979 |
|
7980 |
|
7981 |
|
7982 |
|
7983 |
|
7984 |
|
7985 | }, {
|
7986 | key: 'initSegment',
|
7987 | value: function initSegment(map) {
|
7988 | var set = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
7989 |
|
7990 | if (!map) {
|
7991 | return null;
|
7992 | }
|
7993 |
|
7994 | var id = (0, _binUtils.initSegmentId)(map);
|
7995 | var storedMap = this.initSegments_[id];
|
7996 |
|
7997 | if (set && !storedMap && map.bytes) {
|
7998 |
|
7999 |
|
8000 |
|
8001 |
|
8002 | var combinedByteLength = VTT_LINE_TERMINATORS.byteLength + map.bytes.byteLength;
|
8003 | var combinedSegment = new Uint8Array(combinedByteLength);
|
8004 |
|
8005 | combinedSegment.set(map.bytes);
|
8006 | combinedSegment.set(VTT_LINE_TERMINATORS, map.bytes.byteLength);
|
8007 |
|
8008 | this.initSegments_[id] = storedMap = {
|
8009 | resolvedUri: map.resolvedUri,
|
8010 | byterange: map.byterange,
|
8011 | bytes: combinedSegment
|
8012 | };
|
8013 | }
|
8014 |
|
8015 | return storedMap || map;
|
8016 | }
|
8017 |
|
8018 | |
8019 |
|
8020 |
|
8021 |
|
8022 |
|
8023 |
|
8024 | }, {
|
8025 | key: 'couldBeginLoading_',
|
8026 | value: function couldBeginLoading_() {
|
8027 | return this.playlist_ && this.subtitlesTrack_ && !this.paused();
|
8028 | }
|
8029 |
|
8030 | |
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 |
|
8036 |
|
8037 | }, {
|
8038 | key: 'init_',
|
8039 | value: function init_() {
|
8040 | this.state = 'READY';
|
8041 | this.resetEverything();
|
8042 | return this.monitorBuffer_();
|
8043 | }
|
8044 |
|
8045 | |
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 | }, {
|
8054 | key: 'track',
|
8055 | value: function track(_track) {
|
8056 | if (typeof _track === 'undefined') {
|
8057 | return this.subtitlesTrack_;
|
8058 | }
|
8059 |
|
8060 | this.subtitlesTrack_ = _track;
|
8061 |
|
8062 |
|
8063 |
|
8064 | if (this.state === 'INIT' && this.couldBeginLoading_()) {
|
8065 | this.init_();
|
8066 | }
|
8067 |
|
8068 | return this.subtitlesTrack_;
|
8069 | }
|
8070 |
|
8071 | |
8072 |
|
8073 |
|
8074 |
|
8075 |
|
8076 | }, {
|
8077 | key: 'remove',
|
8078 | value: function remove(start, end) {
|
8079 | (0, _videojsContribMediaSourcesEs5RemoveCuesFromTrackJs2['default'])(start, end, this.subtitlesTrack_);
|
8080 | }
|
8081 |
|
8082 | |
8083 |
|
8084 |
|
8085 |
|
8086 |
|
8087 |
|
8088 |
|
8089 |
|
8090 |
|
8091 | }, {
|
8092 | key: 'fillBuffer_',
|
8093 | value: function fillBuffer_() {
|
8094 | var _this = this;
|
8095 |
|
8096 | if (!this.syncPoint_) {
|
8097 | this.syncPoint_ = this.syncController_.getSyncPoint(this.playlist_, this.duration_(), this.currentTimeline_, this.currentTime_());
|
8098 | }
|
8099 |
|
8100 |
|
8101 | var segmentInfo = this.checkBuffer_(this.buffered_(), this.playlist_, this.mediaIndex, this.hasPlayed_(), this.currentTime_(), this.syncPoint_);
|
8102 |
|
8103 | segmentInfo = this.skipEmptySegments_(segmentInfo);
|
8104 |
|
8105 | if (!segmentInfo) {
|
8106 | return;
|
8107 | }
|
8108 |
|
8109 | if (this.syncController_.timestampOffsetForTimeline(segmentInfo.timeline) === null) {
|
8110 |
|
8111 |
|
8112 | var checkTimestampOffset = function checkTimestampOffset() {
|
8113 | _this.state = 'READY';
|
8114 | if (!_this.paused()) {
|
8115 |
|
8116 | _this.monitorBuffer_();
|
8117 | }
|
8118 | };
|
8119 |
|
8120 | this.syncController_.one('timestampoffset', checkTimestampOffset);
|
8121 | this.state = 'WAITING_ON_TIMELINE';
|
8122 | return;
|
8123 | }
|
8124 |
|
8125 | this.loadSegment_(segmentInfo);
|
8126 | }
|
8127 |
|
8128 | |
8129 |
|
8130 |
|
8131 |
|
8132 |
|
8133 |
|
8134 |
|
8135 |
|
8136 |
|
8137 |
|
8138 | }, {
|
8139 | key: 'skipEmptySegments_',
|
8140 | value: function skipEmptySegments_(segmentInfo) {
|
8141 | while (segmentInfo && segmentInfo.segment.empty) {
|
8142 | segmentInfo = this.generateSegmentInfo_(segmentInfo.playlist, segmentInfo.mediaIndex + 1, segmentInfo.startOfSegment + segmentInfo.duration, segmentInfo.isSyncRequest);
|
8143 | }
|
8144 | return segmentInfo;
|
8145 | }
|
8146 |
|
8147 | |
8148 |
|
8149 |
|
8150 |
|
8151 |
|
8152 | }, {
|
8153 | key: 'handleSegment_',
|
8154 | value: function handleSegment_() {
|
8155 | var _this2 = this;
|
8156 |
|
8157 | if (!this.pendingSegment_ || !this.subtitlesTrack_) {
|
8158 | this.state = 'READY';
|
8159 | return;
|
8160 | }
|
8161 |
|
8162 | this.state = 'APPENDING';
|
8163 |
|
8164 | var segmentInfo = this.pendingSegment_;
|
8165 | var segment = segmentInfo.segment;
|
8166 |
|
8167 |
|
8168 | if (typeof _globalWindow2['default'].WebVTT !== 'function' && this.subtitlesTrack_ && this.subtitlesTrack_.tech_) {
|
8169 | var _ret = (function () {
|
8170 |
|
8171 | var loadHandler = function loadHandler() {
|
8172 | _this2.handleSegment_();
|
8173 | };
|
8174 |
|
8175 | _this2.state = 'WAITING_ON_VTTJS';
|
8176 | _this2.subtitlesTrack_.tech_.one('vttjsloaded', loadHandler);
|
8177 | _this2.subtitlesTrack_.tech_.one('vttjserror', function () {
|
8178 | _this2.subtitlesTrack_.tech_.off('vttjsloaded', loadHandler);
|
8179 | _this2.error({
|
8180 | message: 'Error loading vtt.js'
|
8181 | });
|
8182 | _this2.state = 'READY';
|
8183 | _this2.pause();
|
8184 | _this2.trigger('error');
|
8185 | });
|
8186 |
|
8187 | return {
|
8188 | v: undefined
|
8189 | };
|
8190 | })();
|
8191 |
|
8192 | if (typeof _ret === 'object') return _ret.v;
|
8193 | }
|
8194 |
|
8195 | segment.requested = true;
|
8196 |
|
8197 | try {
|
8198 | this.parseVTTCues_(segmentInfo);
|
8199 | } catch (e) {
|
8200 | this.error({
|
8201 | message: e.message
|
8202 | });
|
8203 | this.state = 'READY';
|
8204 | this.pause();
|
8205 | return this.trigger('error');
|
8206 | }
|
8207 |
|
8208 | this.updateTimeMapping_(segmentInfo, this.syncController_.timelines[segmentInfo.timeline], this.playlist_);
|
8209 |
|
8210 | if (segmentInfo.isSyncRequest) {
|
8211 | this.trigger('syncinfoupdate');
|
8212 | this.pendingSegment_ = null;
|
8213 | this.state = 'READY';
|
8214 | return;
|
8215 | }
|
8216 |
|
8217 | segmentInfo.byteLength = segmentInfo.bytes.byteLength;
|
8218 |
|
8219 | this.mediaSecondsLoaded += segment.duration;
|
8220 |
|
8221 | if (segmentInfo.cues.length) {
|
8222 |
|
8223 | this.remove(segmentInfo.cues[0].endTime, segmentInfo.cues[segmentInfo.cues.length - 1].endTime);
|
8224 | }
|
8225 |
|
8226 | segmentInfo.cues.forEach(function (cue) {
|
8227 | _this2.subtitlesTrack_.addCue(cue);
|
8228 | });
|
8229 |
|
8230 | this.handleUpdateEnd_();
|
8231 | }
|
8232 |
|
8233 | |
8234 |
|
8235 |
|
8236 |
|
8237 |
|
8238 |
|
8239 |
|
8240 | }, {
|
8241 | key: 'parseVTTCues_',
|
8242 | value: function parseVTTCues_(segmentInfo) {
|
8243 | var decoder = undefined;
|
8244 | var decodeBytesToString = false;
|
8245 |
|
8246 | if (typeof _globalWindow2['default'].TextDecoder === 'function') {
|
8247 | decoder = new _globalWindow2['default'].TextDecoder('utf8');
|
8248 | } else {
|
8249 | decoder = _globalWindow2['default'].WebVTT.StringDecoder();
|
8250 | decodeBytesToString = true;
|
8251 | }
|
8252 |
|
8253 | var parser = new _globalWindow2['default'].WebVTT.Parser(_globalWindow2['default'], _globalWindow2['default'].vttjs, decoder);
|
8254 |
|
8255 | segmentInfo.cues = [];
|
8256 | segmentInfo.timestampmap = { MPEGTS: 0, LOCAL: 0 };
|
8257 |
|
8258 | parser.oncue = segmentInfo.cues.push.bind(segmentInfo.cues);
|
8259 | parser.ontimestampmap = function (map) {
|
8260 | return segmentInfo.timestampmap = map;
|
8261 | };
|
8262 | parser.onparsingerror = function (error) {
|
8263 | _videoJs2['default'].log.warn('Error encountered when parsing cues: ' + error.message);
|
8264 | };
|
8265 |
|
8266 | if (segmentInfo.segment.map) {
|
8267 | var mapData = segmentInfo.segment.map.bytes;
|
8268 |
|
8269 | if (decodeBytesToString) {
|
8270 | mapData = uintToString(mapData);
|
8271 | }
|
8272 |
|
8273 | parser.parse(mapData);
|
8274 | }
|
8275 |
|
8276 | var segmentData = segmentInfo.bytes;
|
8277 |
|
8278 | if (decodeBytesToString) {
|
8279 | segmentData = uintToString(segmentData);
|
8280 | }
|
8281 |
|
8282 | parser.parse(segmentData);
|
8283 | parser.flush();
|
8284 | }
|
8285 |
|
8286 | |
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 |
|
8292 |
|
8293 |
|
8294 |
|
8295 |
|
8296 |
|
8297 |
|
8298 |
|
8299 | }, {
|
8300 | key: 'updateTimeMapping_',
|
8301 | value: function updateTimeMapping_(segmentInfo, mappingObj, playlist) {
|
8302 | var segment = segmentInfo.segment;
|
8303 |
|
8304 | if (!mappingObj) {
|
8305 |
|
8306 |
|
8307 |
|
8308 | return;
|
8309 | }
|
8310 |
|
8311 | if (!segmentInfo.cues.length) {
|
8312 |
|
8313 |
|
8314 |
|
8315 | segment.empty = true;
|
8316 | return;
|
8317 | }
|
8318 |
|
8319 | var timestampmap = segmentInfo.timestampmap;
|
8320 | var diff = timestampmap.MPEGTS / 90000 - timestampmap.LOCAL + mappingObj.mapping;
|
8321 |
|
8322 | segmentInfo.cues.forEach(function (cue) {
|
8323 |
|
8324 | cue.startTime += diff;
|
8325 | cue.endTime += diff;
|
8326 | });
|
8327 |
|
8328 | if (!playlist.syncInfo) {
|
8329 | var firstStart = segmentInfo.cues[0].startTime;
|
8330 | var lastStart = segmentInfo.cues[segmentInfo.cues.length - 1].startTime;
|
8331 |
|
8332 | playlist.syncInfo = {
|
8333 | mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
|
8334 | time: Math.min(firstStart, lastStart - segment.duration)
|
8335 | };
|
8336 | }
|
8337 | }
|
8338 | }]);
|
8339 |
|
8340 | return VTTSegmentLoader;
|
8341 | })(_segmentLoader2['default']);
|
8342 |
|
8343 | exports['default'] = VTTSegmentLoader;
|
8344 | module.exports = exports['default'];
|
8345 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
8346 | },{"./bin-utils":2,"./segment-loader":16,"global/window":32,"videojs-contrib-media-sources/es5/remove-cues-from-track.js":72}],21:[function(require,module,exports){
|
8347 | (function (global){
|
8348 |
|
8349 |
|
8350 |
|
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 |
|
8356 |
|
8357 |
|
8358 |
|
8359 | 'use strict';
|
8360 |
|
8361 | Object.defineProperty(exports, '__esModule', {
|
8362 | value: true
|
8363 | });
|
8364 |
|
8365 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
8366 |
|
8367 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
8368 |
|
8369 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
8370 |
|
8371 | var xhrFactory = function xhrFactory() {
|
8372 | var xhr = function XhrFunction(options, callback) {
|
8373 |
|
8374 | options = (0, _videoJs.mergeOptions)({
|
8375 | timeout: 45e3
|
8376 | }, options);
|
8377 |
|
8378 |
|
8379 |
|
8380 | var beforeRequest = XhrFunction.beforeRequest || _videoJs2['default'].Hls.xhr.beforeRequest;
|
8381 |
|
8382 | if (beforeRequest && typeof beforeRequest === 'function') {
|
8383 | var newOptions = beforeRequest(options);
|
8384 |
|
8385 | if (newOptions) {
|
8386 | options = newOptions;
|
8387 | }
|
8388 | }
|
8389 |
|
8390 | var request = (0, _videoJs.xhr)(options, function (error, response) {
|
8391 | var reqResponse = request.response;
|
8392 |
|
8393 | if (!error && reqResponse) {
|
8394 | request.responseTime = Date.now();
|
8395 | request.roundTripTime = request.responseTime - request.requestTime;
|
8396 | request.bytesReceived = reqResponse.byteLength || reqResponse.length;
|
8397 | if (!request.bandwidth) {
|
8398 | request.bandwidth = Math.floor(request.bytesReceived / request.roundTripTime * 8 * 1000);
|
8399 | }
|
8400 | }
|
8401 |
|
8402 |
|
8403 |
|
8404 |
|
8405 | if (error && error.code === 'ETIMEDOUT') {
|
8406 | request.timedout = true;
|
8407 | }
|
8408 |
|
8409 |
|
8410 |
|
8411 |
|
8412 | if (!error && !request.aborted && response.statusCode !== 200 && response.statusCode !== 206 && response.statusCode !== 0) {
|
8413 | error = new Error('XHR Failed with a response of: ' + (request && (reqResponse || request.responseText)));
|
8414 | }
|
8415 |
|
8416 | callback(error, request);
|
8417 | });
|
8418 | var originalAbort = request.abort;
|
8419 |
|
8420 | request.abort = function () {
|
8421 | request.aborted = true;
|
8422 | return originalAbort.apply(request, arguments);
|
8423 | };
|
8424 | request.uri = options.uri;
|
8425 | request.requestTime = Date.now();
|
8426 | return request;
|
8427 | };
|
8428 |
|
8429 | return xhr;
|
8430 | };
|
8431 |
|
8432 | exports['default'] = xhrFactory;
|
8433 | module.exports = exports['default'];
|
8434 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
8435 | },{}],22:[function(require,module,exports){
|
8436 |
|
8437 |
|
8438 |
|
8439 |
|
8440 |
|
8441 |
|
8442 |
|
8443 |
|
8444 |
|
8445 |
|
8446 |
|
8447 |
|
8448 |
|
8449 |
|
8450 |
|
8451 |
|
8452 |
|
8453 |
|
8454 |
|
8455 |
|
8456 |
|
8457 |
|
8458 |
|
8459 |
|
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 |
|
8466 |
|
8467 |
|
8468 |
|
8469 |
|
8470 |
|
8471 |
|
8472 |
|
8473 |
|
8474 |
|
8475 |
|
8476 |
|
8477 |
|
8478 |
|
8479 |
|
8480 | 'use strict';
|
8481 |
|
8482 | Object.defineProperty(exports, '__esModule', {
|
8483 | value: true
|
8484 | });
|
8485 |
|
8486 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
8487 |
|
8488 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
8489 |
|
8490 | var precompute = function precompute() {
|
8491 | var tables = [[[], [], [], [], []], [[], [], [], [], []]];
|
8492 | var encTable = tables[0];
|
8493 | var decTable = tables[1];
|
8494 | var sbox = encTable[4];
|
8495 | var sboxInv = decTable[4];
|
8496 | var i = undefined;
|
8497 | var x = undefined;
|
8498 | var xInv = undefined;
|
8499 | var d = [];
|
8500 | var th = [];
|
8501 | var x2 = undefined;
|
8502 | var x4 = undefined;
|
8503 | var x8 = undefined;
|
8504 | var s = undefined;
|
8505 | var tEnc = undefined;
|
8506 | var tDec = undefined;
|
8507 |
|
8508 |
|
8509 | for (i = 0; i < 256; i++) {
|
8510 | th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
|
8511 | }
|
8512 |
|
8513 | for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
|
8514 |
|
8515 | s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
|
8516 | s = s >> 8 ^ s & 255 ^ 99;
|
8517 | sbox[x] = s;
|
8518 | sboxInv[s] = x;
|
8519 |
|
8520 |
|
8521 | x8 = d[x4 = d[x2 = d[x]]];
|
8522 | tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
|
8523 | tEnc = d[s] * 0x101 ^ s * 0x1010100;
|
8524 |
|
8525 | for (i = 0; i < 4; i++) {
|
8526 | encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
|
8527 | decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
|
8528 | }
|
8529 | }
|
8530 |
|
8531 |
|
8532 | for (i = 0; i < 5; i++) {
|
8533 | encTable[i] = encTable[i].slice(0);
|
8534 | decTable[i] = decTable[i].slice(0);
|
8535 | }
|
8536 | return tables;
|
8537 | };
|
8538 | var aesTables = null;
|
8539 |
|
8540 |
|
8541 |
|
8542 |
|
8543 |
|
8544 |
|
8545 |
|
8546 |
|
8547 |
|
8548 | var AES = (function () {
|
8549 | function AES(key) {
|
8550 | _classCallCheck(this, AES);
|
8551 |
|
8552 | |
8553 |
|
8554 |
|
8555 |
|
8556 |
|
8557 |
|
8558 |
|
8559 |
|
8560 |
|
8561 |
|
8562 |
|
8563 |
|
8564 |
|
8565 |
|
8566 | if (!aesTables) {
|
8567 | aesTables = precompute();
|
8568 | }
|
8569 |
|
8570 | 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()]];
|
8571 | var i = undefined;
|
8572 | var j = undefined;
|
8573 | var tmp = undefined;
|
8574 | var encKey = undefined;
|
8575 | var decKey = undefined;
|
8576 | var sbox = this._tables[0][4];
|
8577 | var decTable = this._tables[1];
|
8578 | var keyLen = key.length;
|
8579 | var rcon = 1;
|
8580 |
|
8581 | if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
|
8582 | throw new Error('Invalid aes key size');
|
8583 | }
|
8584 |
|
8585 | encKey = key.slice(0);
|
8586 | decKey = [];
|
8587 | this._key = [encKey, decKey];
|
8588 |
|
8589 |
|
8590 | for (i = keyLen; i < 4 * keyLen + 28; i++) {
|
8591 | tmp = encKey[i - 1];
|
8592 |
|
8593 |
|
8594 | if (i % keyLen === 0 || keyLen === 8 && i % keyLen === 4) {
|
8595 | tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
|
8596 |
|
8597 |
|
8598 | if (i % keyLen === 0) {
|
8599 | tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
|
8600 | rcon = rcon << 1 ^ (rcon >> 7) * 283;
|
8601 | }
|
8602 | }
|
8603 |
|
8604 | encKey[i] = encKey[i - keyLen] ^ tmp;
|
8605 | }
|
8606 |
|
8607 |
|
8608 | for (j = 0; i; j++, i--) {
|
8609 | tmp = encKey[j & 3 ? i : i - 4];
|
8610 | if (i <= 4 || j < 4) {
|
8611 | decKey[j] = tmp;
|
8612 | } else {
|
8613 | decKey[j] = decTable[0][sbox[tmp >>> 24]] ^ decTable[1][sbox[tmp >> 16 & 255]] ^ decTable[2][sbox[tmp >> 8 & 255]] ^ decTable[3][sbox[tmp & 255]];
|
8614 | }
|
8615 | }
|
8616 | }
|
8617 |
|
8618 | |
8619 |
|
8620 |
|
8621 |
|
8622 |
|
8623 |
|
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 |
|
8629 |
|
8630 |
|
8631 |
|
8632 | _createClass(AES, [{
|
8633 | key: 'decrypt',
|
8634 | value: function decrypt(encrypted0, encrypted1, encrypted2, encrypted3, out, offset) {
|
8635 | var key = this._key[1];
|
8636 |
|
8637 | var a = encrypted0 ^ key[0];
|
8638 | var b = encrypted3 ^ key[1];
|
8639 | var c = encrypted2 ^ key[2];
|
8640 | var d = encrypted1 ^ key[3];
|
8641 | var a2 = undefined;
|
8642 | var b2 = undefined;
|
8643 | var c2 = undefined;
|
8644 |
|
8645 |
|
8646 | var nInnerRounds = key.length / 4 - 2;
|
8647 | var i = undefined;
|
8648 | var kIndex = 4;
|
8649 | var table = this._tables[1];
|
8650 |
|
8651 |
|
8652 | var table0 = table[0];
|
8653 | var table1 = table[1];
|
8654 | var table2 = table[2];
|
8655 | var table3 = table[3];
|
8656 | var sbox = table[4];
|
8657 |
|
8658 |
|
8659 | for (i = 0; i < nInnerRounds; i++) {
|
8660 | a2 = table0[a >>> 24] ^ table1[b >> 16 & 255] ^ table2[c >> 8 & 255] ^ table3[d & 255] ^ key[kIndex];
|
8661 | b2 = table0[b >>> 24] ^ table1[c >> 16 & 255] ^ table2[d >> 8 & 255] ^ table3[a & 255] ^ key[kIndex + 1];
|
8662 | c2 = table0[c >>> 24] ^ table1[d >> 16 & 255] ^ table2[a >> 8 & 255] ^ table3[b & 255] ^ key[kIndex + 2];
|
8663 | d = table0[d >>> 24] ^ table1[a >> 16 & 255] ^ table2[b >> 8 & 255] ^ table3[c & 255] ^ key[kIndex + 3];
|
8664 | kIndex += 4;
|
8665 | a = a2;b = b2;c = c2;
|
8666 | }
|
8667 |
|
8668 |
|
8669 | for (i = 0; i < 4; i++) {
|
8670 | out[(3 & -i) + offset] = sbox[a >>> 24] << 24 ^ sbox[b >> 16 & 255] << 16 ^ sbox[c >> 8 & 255] << 8 ^ sbox[d & 255] ^ key[kIndex++];
|
8671 | a2 = a;a = b;b = c;c = d;d = a2;
|
8672 | }
|
8673 | }
|
8674 | }]);
|
8675 |
|
8676 | return AES;
|
8677 | })();
|
8678 |
|
8679 | exports['default'] = AES;
|
8680 | module.exports = exports['default'];
|
8681 | },{}],23:[function(require,module,exports){
|
8682 |
|
8683 |
|
8684 |
|
8685 | 'use strict';
|
8686 |
|
8687 | Object.defineProperty(exports, '__esModule', {
|
8688 | value: true
|
8689 | });
|
8690 |
|
8691 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
8692 |
|
8693 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
8694 |
|
8695 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
8696 |
|
8697 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
8698 |
|
8699 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
8700 |
|
8701 | var _stream = require('./stream');
|
8702 |
|
8703 | var _stream2 = _interopRequireDefault(_stream);
|
8704 |
|
8705 |
|
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 |
|
8711 |
|
8712 |
|
8713 | var AsyncStream = (function (_Stream) {
|
8714 | _inherits(AsyncStream, _Stream);
|
8715 |
|
8716 | function AsyncStream() {
|
8717 | _classCallCheck(this, AsyncStream);
|
8718 |
|
8719 | _get(Object.getPrototypeOf(AsyncStream.prototype), 'constructor', this).call(this, _stream2['default']);
|
8720 | this.jobs = [];
|
8721 | this.delay = 1;
|
8722 | this.timeout_ = null;
|
8723 | }
|
8724 |
|
8725 | |
8726 |
|
8727 |
|
8728 |
|
8729 |
|
8730 |
|
8731 | _createClass(AsyncStream, [{
|
8732 | key: 'processJob_',
|
8733 | value: function processJob_() {
|
8734 | this.jobs.shift()();
|
8735 | if (this.jobs.length) {
|
8736 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
8737 | } else {
|
8738 | this.timeout_ = null;
|
8739 | }
|
8740 | }
|
8741 |
|
8742 | |
8743 |
|
8744 |
|
8745 |
|
8746 |
|
8747 | }, {
|
8748 | key: 'push',
|
8749 | value: function push(job) {
|
8750 | this.jobs.push(job);
|
8751 | if (!this.timeout_) {
|
8752 | this.timeout_ = setTimeout(this.processJob_.bind(this), this.delay);
|
8753 | }
|
8754 | }
|
8755 | }]);
|
8756 |
|
8757 | return AsyncStream;
|
8758 | })(_stream2['default']);
|
8759 |
|
8760 | exports['default'] = AsyncStream;
|
8761 | module.exports = exports['default'];
|
8762 | },{"./stream":26}],24:[function(require,module,exports){
|
8763 |
|
8764 |
|
8765 |
|
8766 |
|
8767 |
|
8768 |
|
8769 |
|
8770 | 'use strict';
|
8771 |
|
8772 | Object.defineProperty(exports, '__esModule', {
|
8773 | value: true
|
8774 | });
|
8775 |
|
8776 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
8777 |
|
8778 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
8779 |
|
8780 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
8781 |
|
8782 | var _aes = require('./aes');
|
8783 |
|
8784 | var _aes2 = _interopRequireDefault(_aes);
|
8785 |
|
8786 | var _asyncStream = require('./async-stream');
|
8787 |
|
8788 | var _asyncStream2 = _interopRequireDefault(_asyncStream);
|
8789 |
|
8790 | var _pkcs7 = require('pkcs7');
|
8791 |
|
8792 |
|
8793 |
|
8794 |
|
8795 |
|
8796 | var ntoh = function ntoh(word) {
|
8797 | return word << 24 | (word & 0xff00) << 8 | (word & 0xff0000) >> 8 | word >>> 24;
|
8798 | };
|
8799 |
|
8800 |
|
8801 |
|
8802 |
|
8803 |
|
8804 |
|
8805 |
|
8806 |
|
8807 |
|
8808 |
|
8809 |
|
8810 |
|
8811 |
|
8812 |
|
8813 | var decrypt = function decrypt(encrypted, key, initVector) {
|
8814 |
|
8815 | var encrypted32 = new Int32Array(encrypted.buffer, encrypted.byteOffset, encrypted.byteLength >> 2);
|
8816 |
|
8817 | var decipher = new _aes2['default'](Array.prototype.slice.call(key));
|
8818 |
|
8819 |
|
8820 | var decrypted = new Uint8Array(encrypted.byteLength);
|
8821 | var decrypted32 = new Int32Array(decrypted.buffer);
|
8822 |
|
8823 |
|
8824 |
|
8825 | var init0 = undefined;
|
8826 | var init1 = undefined;
|
8827 | var init2 = undefined;
|
8828 | var init3 = undefined;
|
8829 | var encrypted0 = undefined;
|
8830 | var encrypted1 = undefined;
|
8831 | var encrypted2 = undefined;
|
8832 | var encrypted3 = undefined;
|
8833 |
|
8834 |
|
8835 | var wordIx = undefined;
|
8836 |
|
8837 |
|
8838 |
|
8839 | init0 = initVector[0];
|
8840 | init1 = initVector[1];
|
8841 | init2 = initVector[2];
|
8842 | init3 = initVector[3];
|
8843 |
|
8844 |
|
8845 |
|
8846 | for (wordIx = 0; wordIx < encrypted32.length; wordIx += 4) {
|
8847 |
|
8848 |
|
8849 | encrypted0 = ntoh(encrypted32[wordIx]);
|
8850 | encrypted1 = ntoh(encrypted32[wordIx + 1]);
|
8851 | encrypted2 = ntoh(encrypted32[wordIx + 2]);
|
8852 | encrypted3 = ntoh(encrypted32[wordIx + 3]);
|
8853 |
|
8854 |
|
8855 | decipher.decrypt(encrypted0, encrypted1, encrypted2, encrypted3, decrypted32, wordIx);
|
8856 |
|
8857 |
|
8858 |
|
8859 | decrypted32[wordIx] = ntoh(decrypted32[wordIx] ^ init0);
|
8860 | decrypted32[wordIx + 1] = ntoh(decrypted32[wordIx + 1] ^ init1);
|
8861 | decrypted32[wordIx + 2] = ntoh(decrypted32[wordIx + 2] ^ init2);
|
8862 | decrypted32[wordIx + 3] = ntoh(decrypted32[wordIx + 3] ^ init3);
|
8863 |
|
8864 |
|
8865 | init0 = encrypted0;
|
8866 | init1 = encrypted1;
|
8867 | init2 = encrypted2;
|
8868 | init3 = encrypted3;
|
8869 | }
|
8870 |
|
8871 | return decrypted;
|
8872 | };
|
8873 |
|
8874 | exports.decrypt = decrypt;
|
8875 |
|
8876 |
|
8877 |
|
8878 |
|
8879 |
|
8880 |
|
8881 |
|
8882 |
|
8883 |
|
8884 |
|
8885 |
|
8886 |
|
8887 | var Decrypter = (function () {
|
8888 | function Decrypter(encrypted, key, initVector, done) {
|
8889 | _classCallCheck(this, Decrypter);
|
8890 |
|
8891 | var step = Decrypter.STEP;
|
8892 | var encrypted32 = new Int32Array(encrypted.buffer);
|
8893 | var decrypted = new Uint8Array(encrypted.byteLength);
|
8894 | var i = 0;
|
8895 |
|
8896 | this.asyncStream_ = new _asyncStream2['default']();
|
8897 |
|
8898 |
|
8899 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
8900 | for (i = step; i < encrypted32.length; i += step) {
|
8901 | initVector = new Uint32Array([ntoh(encrypted32[i - 4]), ntoh(encrypted32[i - 3]), ntoh(encrypted32[i - 2]), ntoh(encrypted32[i - 1])]);
|
8902 | this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step), key, initVector, decrypted));
|
8903 | }
|
8904 |
|
8905 | this.asyncStream_.push(function () {
|
8906 |
|
8907 | done(null, (0, _pkcs7.unpad)(decrypted));
|
8908 | });
|
8909 | }
|
8910 |
|
8911 | |
8912 |
|
8913 |
|
8914 |
|
8915 |
|
8916 |
|
8917 | _createClass(Decrypter, [{
|
8918 | key: 'decryptChunk_',
|
8919 |
|
8920 | |
8921 |
|
8922 |
|
8923 | value: function decryptChunk_(encrypted, key, initVector, decrypted) {
|
8924 | return function () {
|
8925 | var bytes = decrypt(encrypted, key, initVector);
|
8926 |
|
8927 | decrypted.set(bytes, encrypted.byteOffset);
|
8928 | };
|
8929 | }
|
8930 | }], [{
|
8931 | key: 'STEP',
|
8932 | get: function get() {
|
8933 |
|
8934 | return 32000;
|
8935 | }
|
8936 | }]);
|
8937 |
|
8938 | return Decrypter;
|
8939 | })();
|
8940 |
|
8941 | exports.Decrypter = Decrypter;
|
8942 | exports['default'] = {
|
8943 | Decrypter: Decrypter,
|
8944 | decrypt: decrypt
|
8945 | };
|
8946 | },{"./aes":22,"./async-stream":23,"pkcs7":28}],25:[function(require,module,exports){
|
8947 |
|
8948 |
|
8949 |
|
8950 |
|
8951 |
|
8952 |
|
8953 |
|
8954 |
|
8955 |
|
8956 |
|
8957 | 'use strict';
|
8958 |
|
8959 | Object.defineProperty(exports, '__esModule', {
|
8960 | value: true
|
8961 | });
|
8962 |
|
8963 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
8964 |
|
8965 | var _decrypter = require('./decrypter');
|
8966 |
|
8967 | var _asyncStream = require('./async-stream');
|
8968 |
|
8969 | var _asyncStream2 = _interopRequireDefault(_asyncStream);
|
8970 |
|
8971 | exports['default'] = {
|
8972 | decrypt: _decrypter.decrypt,
|
8973 | Decrypter: _decrypter.Decrypter,
|
8974 | AsyncStream: _asyncStream2['default']
|
8975 | };
|
8976 | module.exports = exports['default'];
|
8977 | },{"./async-stream":23,"./decrypter":24}],26:[function(require,module,exports){
|
8978 |
|
8979 |
|
8980 |
|
8981 |
|
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 | 'use strict';
|
8987 |
|
8988 | Object.defineProperty(exports, '__esModule', {
|
8989 | value: true
|
8990 | });
|
8991 |
|
8992 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
8993 |
|
8994 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
8995 |
|
8996 | var Stream = (function () {
|
8997 | function Stream() {
|
8998 | _classCallCheck(this, Stream);
|
8999 |
|
9000 | this.listeners = {};
|
9001 | }
|
9002 |
|
9003 | |
9004 |
|
9005 |
|
9006 |
|
9007 |
|
9008 |
|
9009 |
|
9010 |
|
9011 | _createClass(Stream, [{
|
9012 | key: 'on',
|
9013 | value: function on(type, listener) {
|
9014 | if (!this.listeners[type]) {
|
9015 | this.listeners[type] = [];
|
9016 | }
|
9017 | this.listeners[type].push(listener);
|
9018 | }
|
9019 |
|
9020 | |
9021 |
|
9022 |
|
9023 |
|
9024 |
|
9025 |
|
9026 |
|
9027 |
|
9028 | }, {
|
9029 | key: 'off',
|
9030 | value: function off(type, listener) {
|
9031 | var index = undefined;
|
9032 |
|
9033 | if (!this.listeners[type]) {
|
9034 | return false;
|
9035 | }
|
9036 | index = this.listeners[type].indexOf(listener);
|
9037 | this.listeners[type].splice(index, 1);
|
9038 | return index > -1;
|
9039 | }
|
9040 |
|
9041 | |
9042 |
|
9043 |
|
9044 |
|
9045 |
|
9046 |
|
9047 | }, {
|
9048 | key: 'trigger',
|
9049 | value: function trigger(type) {
|
9050 | var callbacks = undefined;
|
9051 | var i = undefined;
|
9052 | var length = undefined;
|
9053 | var args = undefined;
|
9054 |
|
9055 | callbacks = this.listeners[type];
|
9056 | if (!callbacks) {
|
9057 | return;
|
9058 | }
|
9059 |
|
9060 |
|
9061 |
|
9062 |
|
9063 | if (arguments.length === 2) {
|
9064 | length = callbacks.length;
|
9065 | for (i = 0; i < length; ++i) {
|
9066 | callbacks[i].call(this, arguments[1]);
|
9067 | }
|
9068 | } else {
|
9069 | args = Array.prototype.slice.call(arguments, 1);
|
9070 | length = callbacks.length;
|
9071 | for (i = 0; i < length; ++i) {
|
9072 | callbacks[i].apply(this, args);
|
9073 | }
|
9074 | }
|
9075 | }
|
9076 |
|
9077 | |
9078 |
|
9079 |
|
9080 | }, {
|
9081 | key: 'dispose',
|
9082 | value: function dispose() {
|
9083 | this.listeners = {};
|
9084 | }
|
9085 |
|
9086 | |
9087 |
|
9088 |
|
9089 |
|
9090 |
|
9091 |
|
9092 |
|
9093 |
|
9094 | }, {
|
9095 | key: 'pipe',
|
9096 | value: function pipe(destination) {
|
9097 | this.on('data', function (data) {
|
9098 | destination.push(data);
|
9099 | });
|
9100 | }
|
9101 | }]);
|
9102 |
|
9103 | return Stream;
|
9104 | })();
|
9105 |
|
9106 | exports['default'] = Stream;
|
9107 | module.exports = exports['default'];
|
9108 | },{}],27:[function(require,module,exports){
|
9109 |
|
9110 |
|
9111 |
|
9112 |
|
9113 |
|
9114 |
|
9115 |
|
9116 |
|
9117 | 'use strict';
|
9118 |
|
9119 | var PADDING;
|
9120 |
|
9121 |
|
9122 |
|
9123 |
|
9124 |
|
9125 |
|
9126 |
|
9127 | module.exports = function pad(plaintext) {
|
9128 | var padding = PADDING[(plaintext.byteLength % 16) || 0],
|
9129 | result = new Uint8Array(plaintext.byteLength + padding.length);
|
9130 | result.set(plaintext);
|
9131 | result.set(padding, plaintext.byteLength);
|
9132 | return result;
|
9133 | };
|
9134 |
|
9135 |
|
9136 | PADDING = [
|
9137 | [16, 16, 16, 16,
|
9138 | 16, 16, 16, 16,
|
9139 | 16, 16, 16, 16,
|
9140 | 16, 16, 16, 16],
|
9141 |
|
9142 | [15, 15, 15, 15,
|
9143 | 15, 15, 15, 15,
|
9144 | 15, 15, 15, 15,
|
9145 | 15, 15, 15],
|
9146 |
|
9147 | [14, 14, 14, 14,
|
9148 | 14, 14, 14, 14,
|
9149 | 14, 14, 14, 14,
|
9150 | 14, 14],
|
9151 |
|
9152 | [13, 13, 13, 13,
|
9153 | 13, 13, 13, 13,
|
9154 | 13, 13, 13, 13,
|
9155 | 13],
|
9156 |
|
9157 | [12, 12, 12, 12,
|
9158 | 12, 12, 12, 12,
|
9159 | 12, 12, 12, 12],
|
9160 |
|
9161 | [11, 11, 11, 11,
|
9162 | 11, 11, 11, 11,
|
9163 | 11, 11, 11],
|
9164 |
|
9165 | [10, 10, 10, 10,
|
9166 | 10, 10, 10, 10,
|
9167 | 10, 10],
|
9168 |
|
9169 | [9, 9, 9, 9,
|
9170 | 9, 9, 9, 9,
|
9171 | 9],
|
9172 |
|
9173 | [8, 8, 8, 8,
|
9174 | 8, 8, 8, 8],
|
9175 |
|
9176 | [7, 7, 7, 7,
|
9177 | 7, 7, 7],
|
9178 |
|
9179 | [6, 6, 6, 6,
|
9180 | 6, 6],
|
9181 |
|
9182 | [5, 5, 5, 5,
|
9183 | 5],
|
9184 |
|
9185 | [4, 4, 4, 4],
|
9186 |
|
9187 | [3, 3, 3],
|
9188 |
|
9189 | [2, 2],
|
9190 |
|
9191 | [1]
|
9192 | ];
|
9193 |
|
9194 | },{}],28:[function(require,module,exports){
|
9195 |
|
9196 |
|
9197 |
|
9198 |
|
9199 |
|
9200 |
|
9201 |
|
9202 |
|
9203 | 'use strict';
|
9204 |
|
9205 | exports.pad = require('./pad.js');
|
9206 | exports.unpad = require('./unpad.js');
|
9207 |
|
9208 | },{"./pad.js":27,"./unpad.js":29}],29:[function(require,module,exports){
|
9209 |
|
9210 |
|
9211 |
|
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 | 'use strict';
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 | module.exports = function unpad(padded) {
|
9226 | return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
|
9227 | };
|
9228 |
|
9229 | },{}],30:[function(require,module,exports){
|
9230 |
|
9231 | },{}],31:[function(require,module,exports){
|
9232 | (function (global){
|
9233 | var topLevel = typeof global !== 'undefined' ? global :
|
9234 | typeof window !== 'undefined' ? window : {}
|
9235 | var minDoc = require('min-document');
|
9236 |
|
9237 | var doccy;
|
9238 |
|
9239 | if (typeof document !== 'undefined') {
|
9240 | doccy = document;
|
9241 | } else {
|
9242 | doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
|
9243 |
|
9244 | if (!doccy) {
|
9245 | doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
|
9246 | }
|
9247 | }
|
9248 |
|
9249 | module.exports = doccy;
|
9250 |
|
9251 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
9252 | },{"min-document":30}],32:[function(require,module,exports){
|
9253 | (function (global){
|
9254 | var win;
|
9255 |
|
9256 | if (typeof window !== "undefined") {
|
9257 | win = window;
|
9258 | } else if (typeof global !== "undefined") {
|
9259 | win = global;
|
9260 | } else if (typeof self !== "undefined"){
|
9261 | win = self;
|
9262 | } else {
|
9263 | win = {};
|
9264 | }
|
9265 |
|
9266 | module.exports = win;
|
9267 |
|
9268 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
9269 | },{}],33:[function(require,module,exports){
|
9270 | 'use strict';
|
9271 |
|
9272 | var _lineStream = require('./line-stream');
|
9273 |
|
9274 | var _lineStream2 = _interopRequireDefault(_lineStream);
|
9275 |
|
9276 | var _parseStream = require('./parse-stream');
|
9277 |
|
9278 | var _parseStream2 = _interopRequireDefault(_parseStream);
|
9279 |
|
9280 | var _parser = require('./parser');
|
9281 |
|
9282 | var _parser2 = _interopRequireDefault(_parser);
|
9283 |
|
9284 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
9285 |
|
9286 | module.exports = {
|
9287 | LineStream: _lineStream2['default'],
|
9288 | ParseStream: _parseStream2['default'],
|
9289 | Parser: _parser2['default']
|
9290 | }; |
9291 |
|
9292 |
|
9293 |
|
9294 |
|
9295 |
|
9296 |
|
9297 |
|
9298 |
|
9299 | },{"./line-stream":34,"./parse-stream":35,"./parser":36}],34:[function(require,module,exports){
|
9300 | 'use strict';
|
9301 |
|
9302 | Object.defineProperty(exports, "__esModule", {
|
9303 | value: true
|
9304 | });
|
9305 |
|
9306 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
9307 |
|
9308 | var _stream = require('./stream');
|
9309 |
|
9310 | var _stream2 = _interopRequireDefault(_stream);
|
9311 |
|
9312 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
9313 |
|
9314 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
9315 |
|
9316 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
9317 |
|
9318 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
9319 |
|
9320 |
|
9321 |
|
9322 |
|
9323 |
|
9324 |
|
9325 |
|
9326 |
|
9327 |
|
9328 |
|
9329 |
|
9330 | var LineStream = function (_Stream) {
|
9331 | _inherits(LineStream, _Stream);
|
9332 |
|
9333 | function LineStream() {
|
9334 | _classCallCheck(this, LineStream);
|
9335 |
|
9336 | var _this = _possibleConstructorReturn(this, (LineStream.__proto__ || Object.getPrototypeOf(LineStream)).call(this));
|
9337 |
|
9338 | _this.buffer = '';
|
9339 | return _this;
|
9340 | }
|
9341 |
|
9342 | |
9343 |
|
9344 |
|
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 | _createClass(LineStream, [{
|
9350 | key: 'push',
|
9351 | value: function push(data) {
|
9352 | var nextNewline = void 0;
|
9353 |
|
9354 | this.buffer += data;
|
9355 | nextNewline = this.buffer.indexOf('\n');
|
9356 |
|
9357 | for (; nextNewline > -1; nextNewline = this.buffer.indexOf('\n')) {
|
9358 | this.trigger('data', this.buffer.substring(0, nextNewline));
|
9359 | this.buffer = this.buffer.substring(nextNewline + 1);
|
9360 | }
|
9361 | }
|
9362 | }]);
|
9363 |
|
9364 | return LineStream;
|
9365 | }(_stream2['default']);
|
9366 |
|
9367 | exports['default'] = LineStream;
|
9368 | },{"./stream":37}],35:[function(require,module,exports){
|
9369 | 'use strict';
|
9370 |
|
9371 | Object.defineProperty(exports, "__esModule", {
|
9372 | value: true
|
9373 | });
|
9374 |
|
9375 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
9376 |
|
9377 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
9378 |
|
9379 | var _stream = require('./stream');
|
9380 |
|
9381 | var _stream2 = _interopRequireDefault(_stream);
|
9382 |
|
9383 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
9384 |
|
9385 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
9386 |
|
9387 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
9388 |
|
9389 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
9390 |
|
9391 |
|
9392 |
|
9393 |
|
9394 |
|
9395 |
|
9396 |
|
9397 |
|
9398 |
|
9399 |
|
9400 |
|
9401 | var attributeSeparator = function attributeSeparator() {
|
9402 | var key = '[^=]*';
|
9403 | var value = '"[^"]*"|[^,]*';
|
9404 | var keyvalue = '(?:' + key + ')=(?:' + value + ')';
|
9405 |
|
9406 | return new RegExp('(?:^|,)(' + keyvalue + ')');
|
9407 | };
|
9408 |
|
9409 |
|
9410 |
|
9411 |
|
9412 |
|
9413 |
|
9414 | var parseAttributes = function parseAttributes(attributes) {
|
9415 |
|
9416 | var attrs = attributes.split(attributeSeparator());
|
9417 | var result = {};
|
9418 | var i = attrs.length;
|
9419 | var attr = void 0;
|
9420 |
|
9421 | while (i--) {
|
9422 |
|
9423 | if (attrs[i] === '') {
|
9424 | continue;
|
9425 | }
|
9426 |
|
9427 |
|
9428 | attr = /([^=]*)=(.*)/.exec(attrs[i]).slice(1);
|
9429 |
|
9430 | attr[0] = attr[0].replace(/^\s+|\s+$/g, '');
|
9431 | attr[1] = attr[1].replace(/^\s+|\s+$/g, '');
|
9432 | attr[1] = attr[1].replace(/^['"](.*)['"]$/g, '$1');
|
9433 | result[attr[0]] = attr[1];
|
9434 | }
|
9435 | return result;
|
9436 | };
|
9437 |
|
9438 |
|
9439 |
|
9440 |
|
9441 |
|
9442 |
|
9443 |
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 |
|
9452 |
|
9453 |
|
9454 |
|
9455 |
|
9456 |
|
9457 |
|
9458 |
|
9459 |
|
9460 |
|
9461 |
|
9462 |
|
9463 | var ParseStream = function (_Stream) {
|
9464 | _inherits(ParseStream, _Stream);
|
9465 |
|
9466 | function ParseStream() {
|
9467 | _classCallCheck(this, ParseStream);
|
9468 |
|
9469 | return _possibleConstructorReturn(this, (ParseStream.__proto__ || Object.getPrototypeOf(ParseStream)).call(this));
|
9470 | }
|
9471 |
|
9472 | |
9473 |
|
9474 |
|
9475 |
|
9476 |
|
9477 |
|
9478 |
|
9479 | _createClass(ParseStream, [{
|
9480 | key: 'push',
|
9481 | value: function push(line) {
|
9482 | var match = void 0;
|
9483 | var event = void 0;
|
9484 |
|
9485 |
|
9486 | line = line.replace(/^[\u0000\s]+|[\u0000\s]+$/g, '');
|
9487 | if (line.length === 0) {
|
9488 |
|
9489 | return;
|
9490 | }
|
9491 |
|
9492 |
|
9493 | if (line[0] !== '#') {
|
9494 | this.trigger('data', {
|
9495 | type: 'uri',
|
9496 | uri: line
|
9497 | });
|
9498 | return;
|
9499 | }
|
9500 |
|
9501 |
|
9502 | if (line.indexOf('#EXT') !== 0) {
|
9503 | this.trigger('data', {
|
9504 | type: 'comment',
|
9505 | text: line.slice(1)
|
9506 | });
|
9507 | return;
|
9508 | }
|
9509 |
|
9510 |
|
9511 |
|
9512 | line = line.replace('\r', '');
|
9513 |
|
9514 |
|
9515 | match = /^#EXTM3U/.exec(line);
|
9516 | if (match) {
|
9517 | this.trigger('data', {
|
9518 | type: 'tag',
|
9519 | tagType: 'm3u'
|
9520 | });
|
9521 | return;
|
9522 | }
|
9523 | match = /^#EXTINF:?([0-9\.]*)?,?(.*)?$/.exec(line);
|
9524 | if (match) {
|
9525 | event = {
|
9526 | type: 'tag',
|
9527 | tagType: 'inf'
|
9528 | };
|
9529 | if (match[1]) {
|
9530 | event.duration = parseFloat(match[1]);
|
9531 | }
|
9532 | if (match[2]) {
|
9533 | event.title = match[2];
|
9534 | }
|
9535 | this.trigger('data', event);
|
9536 | return;
|
9537 | }
|
9538 | match = /^#EXT-X-TARGETDURATION:?([0-9.]*)?/.exec(line);
|
9539 | if (match) {
|
9540 | event = {
|
9541 | type: 'tag',
|
9542 | tagType: 'targetduration'
|
9543 | };
|
9544 | if (match[1]) {
|
9545 | event.duration = parseInt(match[1], 10);
|
9546 | }
|
9547 | this.trigger('data', event);
|
9548 | return;
|
9549 | }
|
9550 | match = /^#ZEN-TOTAL-DURATION:?([0-9.]*)?/.exec(line);
|
9551 | if (match) {
|
9552 | event = {
|
9553 | type: 'tag',
|
9554 | tagType: 'totalduration'
|
9555 | };
|
9556 | if (match[1]) {
|
9557 | event.duration = parseInt(match[1], 10);
|
9558 | }
|
9559 | this.trigger('data', event);
|
9560 | return;
|
9561 | }
|
9562 | match = /^#EXT-X-VERSION:?([0-9.]*)?/.exec(line);
|
9563 | if (match) {
|
9564 | event = {
|
9565 | type: 'tag',
|
9566 | tagType: 'version'
|
9567 | };
|
9568 | if (match[1]) {
|
9569 | event.version = parseInt(match[1], 10);
|
9570 | }
|
9571 | this.trigger('data', event);
|
9572 | return;
|
9573 | }
|
9574 | match = /^#EXT-X-MEDIA-SEQUENCE:?(\-?[0-9.]*)?/.exec(line);
|
9575 | if (match) {
|
9576 | event = {
|
9577 | type: 'tag',
|
9578 | tagType: 'media-sequence'
|
9579 | };
|
9580 | if (match[1]) {
|
9581 | event.number = parseInt(match[1], 10);
|
9582 | }
|
9583 | this.trigger('data', event);
|
9584 | return;
|
9585 | }
|
9586 | match = /^#EXT-X-DISCONTINUITY-SEQUENCE:?(\-?[0-9.]*)?/.exec(line);
|
9587 | if (match) {
|
9588 | event = {
|
9589 | type: 'tag',
|
9590 | tagType: 'discontinuity-sequence'
|
9591 | };
|
9592 | if (match[1]) {
|
9593 | event.number = parseInt(match[1], 10);
|
9594 | }
|
9595 | this.trigger('data', event);
|
9596 | return;
|
9597 | }
|
9598 | match = /^#EXT-X-PLAYLIST-TYPE:?(.*)?$/.exec(line);
|
9599 | if (match) {
|
9600 | event = {
|
9601 | type: 'tag',
|
9602 | tagType: 'playlist-type'
|
9603 | };
|
9604 | if (match[1]) {
|
9605 | event.playlistType = match[1];
|
9606 | }
|
9607 | this.trigger('data', event);
|
9608 | return;
|
9609 | }
|
9610 | match = /^#EXT-X-BYTERANGE:?([0-9.]*)?@?([0-9.]*)?/.exec(line);
|
9611 | if (match) {
|
9612 | event = {
|
9613 | type: 'tag',
|
9614 | tagType: 'byterange'
|
9615 | };
|
9616 | if (match[1]) {
|
9617 | event.length = parseInt(match[1], 10);
|
9618 | }
|
9619 | if (match[2]) {
|
9620 | event.offset = parseInt(match[2], 10);
|
9621 | }
|
9622 | this.trigger('data', event);
|
9623 | return;
|
9624 | }
|
9625 | match = /^#EXT-X-ALLOW-CACHE:?(YES|NO)?/.exec(line);
|
9626 | if (match) {
|
9627 | event = {
|
9628 | type: 'tag',
|
9629 | tagType: 'allow-cache'
|
9630 | };
|
9631 | if (match[1]) {
|
9632 | event.allowed = !/NO/.test(match[1]);
|
9633 | }
|
9634 | this.trigger('data', event);
|
9635 | return;
|
9636 | }
|
9637 | match = /^#EXT-X-MAP:?(.*)$/.exec(line);
|
9638 | if (match) {
|
9639 | event = {
|
9640 | type: 'tag',
|
9641 | tagType: 'map'
|
9642 | };
|
9643 |
|
9644 | if (match[1]) {
|
9645 | var attributes = parseAttributes(match[1]);
|
9646 |
|
9647 | if (attributes.URI) {
|
9648 | event.uri = attributes.URI;
|
9649 | }
|
9650 | if (attributes.BYTERANGE) {
|
9651 | var _attributes$BYTERANGE = attributes.BYTERANGE.split('@'),
|
9652 | _attributes$BYTERANGE2 = _slicedToArray(_attributes$BYTERANGE, 2),
|
9653 | length = _attributes$BYTERANGE2[0],
|
9654 | offset = _attributes$BYTERANGE2[1];
|
9655 |
|
9656 | event.byterange = {};
|
9657 | if (length) {
|
9658 | event.byterange.length = parseInt(length, 10);
|
9659 | }
|
9660 | if (offset) {
|
9661 | event.byterange.offset = parseInt(offset, 10);
|
9662 | }
|
9663 | }
|
9664 | }
|
9665 |
|
9666 | this.trigger('data', event);
|
9667 | return;
|
9668 | }
|
9669 | match = /^#EXT-X-STREAM-INF:?(.*)$/.exec(line);
|
9670 | if (match) {
|
9671 | event = {
|
9672 | type: 'tag',
|
9673 | tagType: 'stream-inf'
|
9674 | };
|
9675 | if (match[1]) {
|
9676 | event.attributes = parseAttributes(match[1]);
|
9677 |
|
9678 | if (event.attributes.RESOLUTION) {
|
9679 | var split = event.attributes.RESOLUTION.split('x');
|
9680 | var resolution = {};
|
9681 |
|
9682 | if (split[0]) {
|
9683 | resolution.width = parseInt(split[0], 10);
|
9684 | }
|
9685 | if (split[1]) {
|
9686 | resolution.height = parseInt(split[1], 10);
|
9687 | }
|
9688 | event.attributes.RESOLUTION = resolution;
|
9689 | }
|
9690 | if (event.attributes.BANDWIDTH) {
|
9691 | event.attributes.BANDWIDTH = parseInt(event.attributes.BANDWIDTH, 10);
|
9692 | }
|
9693 | if (event.attributes['PROGRAM-ID']) {
|
9694 | event.attributes['PROGRAM-ID'] = parseInt(event.attributes['PROGRAM-ID'], 10);
|
9695 | }
|
9696 | }
|
9697 | this.trigger('data', event);
|
9698 | return;
|
9699 | }
|
9700 | match = /^#EXT-X-MEDIA:?(.*)$/.exec(line);
|
9701 | if (match) {
|
9702 | event = {
|
9703 | type: 'tag',
|
9704 | tagType: 'media'
|
9705 | };
|
9706 | if (match[1]) {
|
9707 | event.attributes = parseAttributes(match[1]);
|
9708 | }
|
9709 | this.trigger('data', event);
|
9710 | return;
|
9711 | }
|
9712 | match = /^#EXT-X-ENDLIST/.exec(line);
|
9713 | if (match) {
|
9714 | this.trigger('data', {
|
9715 | type: 'tag',
|
9716 | tagType: 'endlist'
|
9717 | });
|
9718 | return;
|
9719 | }
|
9720 | match = /^#EXT-X-DISCONTINUITY/.exec(line);
|
9721 | if (match) {
|
9722 | this.trigger('data', {
|
9723 | type: 'tag',
|
9724 | tagType: 'discontinuity'
|
9725 | });
|
9726 | return;
|
9727 | }
|
9728 | match = /^#EXT-X-PROGRAM-DATE-TIME:?(.*)$/.exec(line);
|
9729 | if (match) {
|
9730 | event = {
|
9731 | type: 'tag',
|
9732 | tagType: 'program-date-time'
|
9733 | };
|
9734 | if (match[1]) {
|
9735 | event.dateTimeString = match[1];
|
9736 | event.dateTimeObject = new Date(match[1]);
|
9737 | }
|
9738 | this.trigger('data', event);
|
9739 | return;
|
9740 | }
|
9741 | match = /^#EXT-X-KEY:?(.*)$/.exec(line);
|
9742 | if (match) {
|
9743 | event = {
|
9744 | type: 'tag',
|
9745 | tagType: 'key'
|
9746 | };
|
9747 | if (match[1]) {
|
9748 | event.attributes = parseAttributes(match[1]);
|
9749 |
|
9750 | if (event.attributes.IV) {
|
9751 | if (event.attributes.IV.substring(0, 2).toLowerCase() === '0x') {
|
9752 | event.attributes.IV = event.attributes.IV.substring(2);
|
9753 | }
|
9754 |
|
9755 | event.attributes.IV = event.attributes.IV.match(/.{8}/g);
|
9756 | event.attributes.IV[0] = parseInt(event.attributes.IV[0], 16);
|
9757 | event.attributes.IV[1] = parseInt(event.attributes.IV[1], 16);
|
9758 | event.attributes.IV[2] = parseInt(event.attributes.IV[2], 16);
|
9759 | event.attributes.IV[3] = parseInt(event.attributes.IV[3], 16);
|
9760 | event.attributes.IV = new Uint32Array(event.attributes.IV);
|
9761 | }
|
9762 | }
|
9763 | this.trigger('data', event);
|
9764 | return;
|
9765 | }
|
9766 | match = /^#EXT-X-CUE-OUT-CONT:?(.*)?$/.exec(line);
|
9767 | if (match) {
|
9768 | event = {
|
9769 | type: 'tag',
|
9770 | tagType: 'cue-out-cont'
|
9771 | };
|
9772 | if (match[1]) {
|
9773 | event.data = match[1];
|
9774 | } else {
|
9775 | event.data = '';
|
9776 | }
|
9777 | this.trigger('data', event);
|
9778 | return;
|
9779 | }
|
9780 | match = /^#EXT-X-CUE-OUT:?(.*)?$/.exec(line);
|
9781 | if (match) {
|
9782 | event = {
|
9783 | type: 'tag',
|
9784 | tagType: 'cue-out'
|
9785 | };
|
9786 | if (match[1]) {
|
9787 | event.data = match[1];
|
9788 | } else {
|
9789 | event.data = '';
|
9790 | }
|
9791 | this.trigger('data', event);
|
9792 | return;
|
9793 | }
|
9794 | match = /^#EXT-X-CUE-IN:?(.*)?$/.exec(line);
|
9795 | if (match) {
|
9796 | event = {
|
9797 | type: 'tag',
|
9798 | tagType: 'cue-in'
|
9799 | };
|
9800 | if (match[1]) {
|
9801 | event.data = match[1];
|
9802 | } else {
|
9803 | event.data = '';
|
9804 | }
|
9805 | this.trigger('data', event);
|
9806 | return;
|
9807 | }
|
9808 |
|
9809 |
|
9810 | this.trigger('data', {
|
9811 | type: 'tag',
|
9812 | data: line.slice(4)
|
9813 | });
|
9814 | }
|
9815 | }]);
|
9816 |
|
9817 | return ParseStream;
|
9818 | }(_stream2['default']);
|
9819 |
|
9820 | exports['default'] = ParseStream;
|
9821 | },{"./stream":37}],36:[function(require,module,exports){
|
9822 | 'use strict';
|
9823 |
|
9824 | Object.defineProperty(exports, "__esModule", {
|
9825 | value: true
|
9826 | });
|
9827 |
|
9828 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
9829 |
|
9830 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
9831 |
|
9832 | var _stream = require('./stream');
|
9833 |
|
9834 | var _stream2 = _interopRequireDefault(_stream);
|
9835 |
|
9836 | var _lineStream = require('./line-stream');
|
9837 |
|
9838 | var _lineStream2 = _interopRequireDefault(_lineStream);
|
9839 |
|
9840 | var _parseStream = require('./parse-stream');
|
9841 |
|
9842 | var _parseStream2 = _interopRequireDefault(_parseStream);
|
9843 |
|
9844 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
9845 |
|
9846 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
9847 |
|
9848 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
9849 |
|
9850 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 |
|
9864 |
|
9865 |
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 |
|
9872 |
|
9873 |
|
9874 |
|
9875 |
|
9876 | var Parser = function (_Stream) {
|
9877 | _inherits(Parser, _Stream);
|
9878 |
|
9879 | function Parser() {
|
9880 | _classCallCheck(this, Parser);
|
9881 |
|
9882 | var _this = _possibleConstructorReturn(this, (Parser.__proto__ || Object.getPrototypeOf(Parser)).call(this));
|
9883 |
|
9884 | _this.lineStream = new _lineStream2['default']();
|
9885 | _this.parseStream = new _parseStream2['default']();
|
9886 | _this.lineStream.pipe(_this.parseStream);
|
9887 |
|
9888 | var self = _this;
|
9889 |
|
9890 | var uris = [];
|
9891 | var currentUri = {};
|
9892 |
|
9893 | var currentMap = void 0;
|
9894 |
|
9895 | var _key = void 0;
|
9896 | var noop = function noop() {};
|
9897 | var defaultMediaGroups = {
|
9898 | 'AUDIO': {},
|
9899 | 'VIDEO': {},
|
9900 | 'CLOSED-CAPTIONS': {},
|
9901 | 'SUBTITLES': {}
|
9902 | };
|
9903 |
|
9904 | var currentTimeline = 0;
|
9905 |
|
9906 |
|
9907 | _this.manifest = {
|
9908 | allowCache: true,
|
9909 | discontinuityStarts: [],
|
9910 | segments: []
|
9911 | };
|
9912 |
|
9913 |
|
9914 | _this.parseStream.on('data', function (entry) {
|
9915 | var mediaGroup = void 0;
|
9916 | var rendition = void 0;
|
9917 |
|
9918 | ({
|
9919 | tag: function tag() {
|
9920 |
|
9921 | (({
|
9922 | 'allow-cache': function allowCache() {
|
9923 | this.manifest.allowCache = entry.allowed;
|
9924 | if (!('allowed' in entry)) {
|
9925 | this.trigger('info', {
|
9926 | message: 'defaulting allowCache to YES'
|
9927 | });
|
9928 | this.manifest.allowCache = true;
|
9929 | }
|
9930 | },
|
9931 | byterange: function byterange() {
|
9932 | var byterange = {};
|
9933 |
|
9934 | if ('length' in entry) {
|
9935 | currentUri.byterange = byterange;
|
9936 | byterange.length = entry.length;
|
9937 |
|
9938 | if (!('offset' in entry)) {
|
9939 | this.trigger('info', {
|
9940 | message: 'defaulting offset to zero'
|
9941 | });
|
9942 | entry.offset = 0;
|
9943 | }
|
9944 | }
|
9945 | if ('offset' in entry) {
|
9946 | currentUri.byterange = byterange;
|
9947 | byterange.offset = entry.offset;
|
9948 | }
|
9949 | },
|
9950 | endlist: function endlist() {
|
9951 | this.manifest.endList = true;
|
9952 | },
|
9953 | inf: function inf() {
|
9954 | if (!('mediaSequence' in this.manifest)) {
|
9955 | this.manifest.mediaSequence = 0;
|
9956 | this.trigger('info', {
|
9957 | message: 'defaulting media sequence to zero'
|
9958 | });
|
9959 | }
|
9960 | if (!('discontinuitySequence' in this.manifest)) {
|
9961 | this.manifest.discontinuitySequence = 0;
|
9962 | this.trigger('info', {
|
9963 | message: 'defaulting discontinuity sequence to zero'
|
9964 | });
|
9965 | }
|
9966 | if (entry.duration > 0) {
|
9967 | currentUri.duration = entry.duration;
|
9968 | }
|
9969 |
|
9970 | if (entry.duration === 0) {
|
9971 | currentUri.duration = 0.01;
|
9972 | this.trigger('info', {
|
9973 | message: 'updating zero segment duration to a small value'
|
9974 | });
|
9975 | }
|
9976 |
|
9977 | this.manifest.segments = uris;
|
9978 | },
|
9979 | key: function key() {
|
9980 | if (!entry.attributes) {
|
9981 | this.trigger('warn', {
|
9982 | message: 'ignoring key declaration without attribute list'
|
9983 | });
|
9984 | return;
|
9985 | }
|
9986 |
|
9987 | if (entry.attributes.METHOD === 'NONE') {
|
9988 | _key = null;
|
9989 | return;
|
9990 | }
|
9991 | if (!entry.attributes.URI) {
|
9992 | this.trigger('warn', {
|
9993 | message: 'ignoring key declaration without URI'
|
9994 | });
|
9995 | return;
|
9996 | }
|
9997 | if (!entry.attributes.METHOD) {
|
9998 | this.trigger('warn', {
|
9999 | message: 'defaulting key method to AES-128'
|
10000 | });
|
10001 | }
|
10002 |
|
10003 |
|
10004 | _key = {
|
10005 | method: entry.attributes.METHOD || 'AES-128',
|
10006 | uri: entry.attributes.URI
|
10007 | };
|
10008 |
|
10009 | if (typeof entry.attributes.IV !== 'undefined') {
|
10010 | _key.iv = entry.attributes.IV;
|
10011 | }
|
10012 | },
|
10013 | 'media-sequence': function mediaSequence() {
|
10014 | if (!isFinite(entry.number)) {
|
10015 | this.trigger('warn', {
|
10016 | message: 'ignoring invalid media sequence: ' + entry.number
|
10017 | });
|
10018 | return;
|
10019 | }
|
10020 | this.manifest.mediaSequence = entry.number;
|
10021 | },
|
10022 | 'discontinuity-sequence': function discontinuitySequence() {
|
10023 | if (!isFinite(entry.number)) {
|
10024 | this.trigger('warn', {
|
10025 | message: 'ignoring invalid discontinuity sequence: ' + entry.number
|
10026 | });
|
10027 | return;
|
10028 | }
|
10029 | this.manifest.discontinuitySequence = entry.number;
|
10030 | currentTimeline = entry.number;
|
10031 | },
|
10032 | 'playlist-type': function playlistType() {
|
10033 | if (!/VOD|EVENT/.test(entry.playlistType)) {
|
10034 | this.trigger('warn', {
|
10035 | message: 'ignoring unknown playlist type: ' + entry.playlist
|
10036 | });
|
10037 | return;
|
10038 | }
|
10039 | this.manifest.playlistType = entry.playlistType;
|
10040 | },
|
10041 | map: function map() {
|
10042 | currentMap = {};
|
10043 | if (entry.uri) {
|
10044 | currentMap.uri = entry.uri;
|
10045 | }
|
10046 | if (entry.byterange) {
|
10047 | currentMap.byterange = entry.byterange;
|
10048 | }
|
10049 | },
|
10050 | 'stream-inf': function streamInf() {
|
10051 | this.manifest.playlists = uris;
|
10052 | this.manifest.mediaGroups = this.manifest.mediaGroups || defaultMediaGroups;
|
10053 |
|
10054 | if (!entry.attributes) {
|
10055 | this.trigger('warn', {
|
10056 | message: 'ignoring empty stream-inf attributes'
|
10057 | });
|
10058 | return;
|
10059 | }
|
10060 |
|
10061 | if (!currentUri.attributes) {
|
10062 | currentUri.attributes = {};
|
10063 | }
|
10064 | _extends(currentUri.attributes, entry.attributes);
|
10065 | },
|
10066 | media: function media() {
|
10067 | this.manifest.mediaGroups = this.manifest.mediaGroups || defaultMediaGroups;
|
10068 |
|
10069 | if (!(entry.attributes && entry.attributes.TYPE && entry.attributes['GROUP-ID'] && entry.attributes.NAME)) {
|
10070 | this.trigger('warn', {
|
10071 | message: 'ignoring incomplete or missing media group'
|
10072 | });
|
10073 | return;
|
10074 | }
|
10075 |
|
10076 |
|
10077 | var mediaGroupType = this.manifest.mediaGroups[entry.attributes.TYPE];
|
10078 |
|
10079 | mediaGroupType[entry.attributes['GROUP-ID']] = mediaGroupType[entry.attributes['GROUP-ID']] || {};
|
10080 | mediaGroup = mediaGroupType[entry.attributes['GROUP-ID']];
|
10081 |
|
10082 |
|
10083 | rendition = {
|
10084 | 'default': /yes/i.test(entry.attributes.DEFAULT)
|
10085 | };
|
10086 | if (rendition['default']) {
|
10087 | rendition.autoselect = true;
|
10088 | } else {
|
10089 | rendition.autoselect = /yes/i.test(entry.attributes.AUTOSELECT);
|
10090 | }
|
10091 | if (entry.attributes.LANGUAGE) {
|
10092 | rendition.language = entry.attributes.LANGUAGE;
|
10093 | }
|
10094 | if (entry.attributes.URI) {
|
10095 | rendition.uri = entry.attributes.URI;
|
10096 | }
|
10097 | if (entry.attributes['INSTREAM-ID']) {
|
10098 | rendition.instreamId = entry.attributes['INSTREAM-ID'];
|
10099 | }
|
10100 | if (entry.attributes.CHARACTERISTICS) {
|
10101 | rendition.characteristics = entry.attributes.CHARACTERISTICS;
|
10102 | }
|
10103 | if (entry.attributes.FORCED) {
|
10104 | rendition.forced = /yes/i.test(entry.attributes.FORCED);
|
10105 | }
|
10106 |
|
10107 |
|
10108 | mediaGroup[entry.attributes.NAME] = rendition;
|
10109 | },
|
10110 | discontinuity: function discontinuity() {
|
10111 | currentTimeline += 1;
|
10112 | currentUri.discontinuity = true;
|
10113 | this.manifest.discontinuityStarts.push(uris.length);
|
10114 | },
|
10115 | 'program-date-time': function programDateTime() {
|
10116 | this.manifest.dateTimeString = entry.dateTimeString;
|
10117 | this.manifest.dateTimeObject = entry.dateTimeObject;
|
10118 | },
|
10119 | targetduration: function targetduration() {
|
10120 | if (!isFinite(entry.duration) || entry.duration < 0) {
|
10121 | this.trigger('warn', {
|
10122 | message: 'ignoring invalid target duration: ' + entry.duration
|
10123 | });
|
10124 | return;
|
10125 | }
|
10126 | this.manifest.targetDuration = entry.duration;
|
10127 | },
|
10128 | totalduration: function totalduration() {
|
10129 | if (!isFinite(entry.duration) || entry.duration < 0) {
|
10130 | this.trigger('warn', {
|
10131 | message: 'ignoring invalid total duration: ' + entry.duration
|
10132 | });
|
10133 | return;
|
10134 | }
|
10135 | this.manifest.totalDuration = entry.duration;
|
10136 | },
|
10137 | 'cue-out': function cueOut() {
|
10138 | currentUri.cueOut = entry.data;
|
10139 | },
|
10140 | 'cue-out-cont': function cueOutCont() {
|
10141 | currentUri.cueOutCont = entry.data;
|
10142 | },
|
10143 | 'cue-in': function cueIn() {
|
10144 | currentUri.cueIn = entry.data;
|
10145 | }
|
10146 | })[entry.tagType] || noop).call(self);
|
10147 | },
|
10148 | uri: function uri() {
|
10149 | currentUri.uri = entry.uri;
|
10150 | uris.push(currentUri);
|
10151 |
|
10152 |
|
10153 | if (this.manifest.targetDuration && !('duration' in currentUri)) {
|
10154 | this.trigger('warn', {
|
10155 | message: 'defaulting segment duration to the target duration'
|
10156 | });
|
10157 | currentUri.duration = this.manifest.targetDuration;
|
10158 | }
|
10159 |
|
10160 | if (_key) {
|
10161 | currentUri.key = _key;
|
10162 | }
|
10163 | currentUri.timeline = currentTimeline;
|
10164 |
|
10165 | if (currentMap) {
|
10166 | currentUri.map = currentMap;
|
10167 | }
|
10168 |
|
10169 |
|
10170 | currentUri = {};
|
10171 | },
|
10172 | comment: function comment() {
|
10173 |
|
10174 | }
|
10175 | })[entry.type].call(self);
|
10176 | });
|
10177 |
|
10178 | return _this;
|
10179 | }
|
10180 |
|
10181 | |
10182 |
|
10183 |
|
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 | _createClass(Parser, [{
|
10189 | key: 'push',
|
10190 | value: function push(chunk) {
|
10191 | this.lineStream.push(chunk);
|
10192 | }
|
10193 |
|
10194 | |
10195 |
|
10196 |
|
10197 |
|
10198 |
|
10199 |
|
10200 | }, {
|
10201 | key: 'end',
|
10202 | value: function end() {
|
10203 |
|
10204 | this.lineStream.push('\n');
|
10205 | }
|
10206 | }]);
|
10207 |
|
10208 | return Parser;
|
10209 | }(_stream2['default']);
|
10210 |
|
10211 | exports['default'] = Parser;
|
10212 | },{"./line-stream":34,"./parse-stream":35,"./stream":37}],37:[function(require,module,exports){
|
10213 | 'use strict';
|
10214 |
|
10215 | Object.defineProperty(exports, "__esModule", {
|
10216 | value: true
|
10217 | });
|
10218 |
|
10219 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10220 |
|
10221 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
10222 |
|
10223 |
|
10224 |
|
10225 |
|
10226 |
|
10227 |
|
10228 |
|
10229 |
|
10230 |
|
10231 | var Stream = function () {
|
10232 | function Stream() {
|
10233 | _classCallCheck(this, Stream);
|
10234 |
|
10235 | this.listeners = {};
|
10236 | }
|
10237 |
|
10238 | |
10239 |
|
10240 |
|
10241 |
|
10242 |
|
10243 |
|
10244 |
|
10245 |
|
10246 |
|
10247 | _createClass(Stream, [{
|
10248 | key: 'on',
|
10249 | value: function on(type, listener) {
|
10250 | if (!this.listeners[type]) {
|
10251 | this.listeners[type] = [];
|
10252 | }
|
10253 | this.listeners[type].push(listener);
|
10254 | }
|
10255 |
|
10256 | |
10257 |
|
10258 |
|
10259 |
|
10260 |
|
10261 |
|
10262 |
|
10263 |
|
10264 |
|
10265 | }, {
|
10266 | key: 'off',
|
10267 | value: function off(type, listener) {
|
10268 | if (!this.listeners[type]) {
|
10269 | return false;
|
10270 | }
|
10271 |
|
10272 | var index = this.listeners[type].indexOf(listener);
|
10273 |
|
10274 | this.listeners[type].splice(index, 1);
|
10275 | return index > -1;
|
10276 | }
|
10277 |
|
10278 | |
10279 |
|
10280 |
|
10281 |
|
10282 |
|
10283 |
|
10284 |
|
10285 | }, {
|
10286 | key: 'trigger',
|
10287 | value: function trigger(type) {
|
10288 | var callbacks = this.listeners[type];
|
10289 | var i = void 0;
|
10290 | var length = void 0;
|
10291 | var args = void 0;
|
10292 |
|
10293 | if (!callbacks) {
|
10294 | return;
|
10295 | }
|
10296 |
|
10297 |
|
10298 |
|
10299 |
|
10300 | if (arguments.length === 2) {
|
10301 | length = callbacks.length;
|
10302 | for (i = 0; i < length; ++i) {
|
10303 | callbacks[i].call(this, arguments[1]);
|
10304 | }
|
10305 | } else {
|
10306 | args = Array.prototype.slice.call(arguments, 1);
|
10307 | length = callbacks.length;
|
10308 | for (i = 0; i < length; ++i) {
|
10309 | callbacks[i].apply(this, args);
|
10310 | }
|
10311 | }
|
10312 | }
|
10313 |
|
10314 | |
10315 |
|
10316 |
|
10317 |
|
10318 | }, {
|
10319 | key: 'dispose',
|
10320 | value: function dispose() {
|
10321 | this.listeners = {};
|
10322 | }
|
10323 | |
10324 |
|
10325 |
|
10326 |
|
10327 |
|
10328 |
|
10329 |
|
10330 |
|
10331 |
|
10332 | }, {
|
10333 | key: 'pipe',
|
10334 | value: function pipe(destination) {
|
10335 | this.on('data', function (data) {
|
10336 | destination.push(data);
|
10337 | });
|
10338 | }
|
10339 | }]);
|
10340 |
|
10341 | return Stream;
|
10342 | }();
|
10343 |
|
10344 | exports['default'] = Stream;
|
10345 | },{}],38:[function(require,module,exports){
|
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 |
|
10351 |
|
10352 |
|
10353 |
|
10354 |
|
10355 |
|
10356 | 'use strict';
|
10357 | var Stream = require('../utils/stream.js');
|
10358 |
|
10359 |
|
10360 | var AacStream;
|
10361 |
|
10362 |
|
10363 |
|
10364 |
|
10365 |
|
10366 | AacStream = function() {
|
10367 | var
|
10368 | everything = new Uint8Array(),
|
10369 | timeStamp = 0;
|
10370 |
|
10371 | AacStream.prototype.init.call(this);
|
10372 |
|
10373 | this.setTimestamp = function(timestamp) {
|
10374 | timeStamp = timestamp;
|
10375 | };
|
10376 |
|
10377 | this.parseId3TagSize = function(header, byteIndex) {
|
10378 | var
|
10379 | returnSize = (header[byteIndex + 6] << 21) |
|
10380 | (header[byteIndex + 7] << 14) |
|
10381 | (header[byteIndex + 8] << 7) |
|
10382 | (header[byteIndex + 9]),
|
10383 | flags = header[byteIndex + 5],
|
10384 | footerPresent = (flags & 16) >> 4;
|
10385 |
|
10386 | if (footerPresent) {
|
10387 | return returnSize + 20;
|
10388 | }
|
10389 | return returnSize + 10;
|
10390 | };
|
10391 |
|
10392 | this.parseAdtsSize = function(header, byteIndex) {
|
10393 | var
|
10394 | lowThree = (header[byteIndex + 5] & 0xE0) >> 5,
|
10395 | middle = header[byteIndex + 4] << 3,
|
10396 | highTwo = header[byteIndex + 3] & 0x3 << 11;
|
10397 |
|
10398 | return (highTwo | middle) | lowThree;
|
10399 | };
|
10400 |
|
10401 | this.push = function(bytes) {
|
10402 | var
|
10403 | frameSize = 0,
|
10404 | byteIndex = 0,
|
10405 | bytesLeft,
|
10406 | chunk,
|
10407 | packet,
|
10408 | tempLength;
|
10409 |
|
10410 |
|
10411 |
|
10412 | if (everything.length) {
|
10413 | tempLength = everything.length;
|
10414 | everything = new Uint8Array(bytes.byteLength + tempLength);
|
10415 | everything.set(everything.subarray(0, tempLength));
|
10416 | everything.set(bytes, tempLength);
|
10417 | } else {
|
10418 | everything = bytes;
|
10419 | }
|
10420 |
|
10421 | while (everything.length - byteIndex >= 3) {
|
10422 | if ((everything[byteIndex] === 'I'.charCodeAt(0)) &&
|
10423 | (everything[byteIndex + 1] === 'D'.charCodeAt(0)) &&
|
10424 | (everything[byteIndex + 2] === '3'.charCodeAt(0))) {
|
10425 |
|
10426 |
|
10427 |
|
10428 | if (everything.length - byteIndex < 10) {
|
10429 | break;
|
10430 | }
|
10431 |
|
10432 |
|
10433 | frameSize = this.parseId3TagSize(everything, byteIndex);
|
10434 |
|
10435 |
|
10436 |
|
10437 | if (frameSize > everything.length) {
|
10438 | break;
|
10439 | }
|
10440 | chunk = {
|
10441 | type: 'timed-metadata',
|
10442 | data: everything.subarray(byteIndex, byteIndex + frameSize)
|
10443 | };
|
10444 | this.trigger('data', chunk);
|
10445 | byteIndex += frameSize;
|
10446 | continue;
|
10447 | } else if ((everything[byteIndex] & 0xff === 0xff) &&
|
10448 | ((everything[byteIndex + 1] & 0xf0) === 0xf0)) {
|
10449 |
|
10450 |
|
10451 |
|
10452 | if (everything.length - byteIndex < 7) {
|
10453 | break;
|
10454 | }
|
10455 |
|
10456 | frameSize = this.parseAdtsSize(everything, byteIndex);
|
10457 |
|
10458 |
|
10459 |
|
10460 | if (frameSize > everything.length) {
|
10461 | break;
|
10462 | }
|
10463 |
|
10464 | packet = {
|
10465 | type: 'audio',
|
10466 | data: everything.subarray(byteIndex, byteIndex + frameSize),
|
10467 | pts: timeStamp,
|
10468 | dts: timeStamp
|
10469 | };
|
10470 | this.trigger('data', packet);
|
10471 | byteIndex += frameSize;
|
10472 | continue;
|
10473 | }
|
10474 | byteIndex++;
|
10475 | }
|
10476 | bytesLeft = everything.length - byteIndex;
|
10477 |
|
10478 | if (bytesLeft > 0) {
|
10479 | everything = everything.subarray(byteIndex);
|
10480 | } else {
|
10481 | everything = new Uint8Array();
|
10482 | }
|
10483 | };
|
10484 | };
|
10485 |
|
10486 | AacStream.prototype = new Stream();
|
10487 |
|
10488 | module.exports = AacStream;
|
10489 |
|
10490 | },{"../utils/stream.js":62}],39:[function(require,module,exports){
|
10491 |
|
10492 |
|
10493 |
|
10494 |
|
10495 |
|
10496 |
|
10497 |
|
10498 |
|
10499 | 'use strict';
|
10500 |
|
10501 | var ADTS_SAMPLING_FREQUENCIES = [
|
10502 | 96000,
|
10503 | 88200,
|
10504 | 64000,
|
10505 | 48000,
|
10506 | 44100,
|
10507 | 32000,
|
10508 | 24000,
|
10509 | 22050,
|
10510 | 16000,
|
10511 | 12000,
|
10512 | 11025,
|
10513 | 8000,
|
10514 | 7350
|
10515 | ];
|
10516 |
|
10517 | var parseSyncSafeInteger = function(data) {
|
10518 | return (data[0] << 21) |
|
10519 | (data[1] << 14) |
|
10520 | (data[2] << 7) |
|
10521 | (data[3]);
|
10522 | };
|
10523 |
|
10524 |
|
10525 |
|
10526 | var percentEncode = function(bytes, start, end) {
|
10527 | var i, result = '';
|
10528 | for (i = start; i < end; i++) {
|
10529 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
10530 | }
|
10531 | return result;
|
10532 | };
|
10533 |
|
10534 |
|
10535 |
|
10536 | var parseIso88591 = function(bytes, start, end) {
|
10537 | return unescape(percentEncode(bytes, start, end));
|
10538 | };
|
10539 |
|
10540 | var parseId3TagSize = function(header, byteIndex) {
|
10541 | var
|
10542 | returnSize = (header[byteIndex + 6] << 21) |
|
10543 | (header[byteIndex + 7] << 14) |
|
10544 | (header[byteIndex + 8] << 7) |
|
10545 | (header[byteIndex + 9]),
|
10546 | flags = header[byteIndex + 5],
|
10547 | footerPresent = (flags & 16) >> 4;
|
10548 |
|
10549 | if (footerPresent) {
|
10550 | return returnSize + 20;
|
10551 | }
|
10552 | return returnSize + 10;
|
10553 | };
|
10554 |
|
10555 | var parseAdtsSize = function(header, byteIndex) {
|
10556 | var
|
10557 | lowThree = (header[byteIndex + 5] & 0xE0) >> 5,
|
10558 | middle = header[byteIndex + 4] << 3,
|
10559 | highTwo = header[byteIndex + 3] & 0x3 << 11;
|
10560 |
|
10561 | return (highTwo | middle) | lowThree;
|
10562 | };
|
10563 |
|
10564 | var parseType = function(header, byteIndex) {
|
10565 | if ((header[byteIndex] === 'I'.charCodeAt(0)) &&
|
10566 | (header[byteIndex + 1] === 'D'.charCodeAt(0)) &&
|
10567 | (header[byteIndex + 2] === '3'.charCodeAt(0))) {
|
10568 | return 'timed-metadata';
|
10569 | } else if ((header[byteIndex] & 0xff === 0xff) &&
|
10570 | ((header[byteIndex + 1] & 0xf0) === 0xf0)) {
|
10571 | return 'audio';
|
10572 | }
|
10573 | return null;
|
10574 | };
|
10575 |
|
10576 | var parseSampleRate = function(packet) {
|
10577 | var i = 0;
|
10578 |
|
10579 | while (i + 5 < packet.length) {
|
10580 | if (packet[i] !== 0xFF || (packet[i + 1] & 0xF6) !== 0xF0) {
|
10581 |
|
10582 |
|
10583 | i++;
|
10584 | continue;
|
10585 | }
|
10586 | return ADTS_SAMPLING_FREQUENCIES[(packet[i + 2] & 0x3c) >>> 2];
|
10587 | }
|
10588 |
|
10589 | return null;
|
10590 | };
|
10591 |
|
10592 | var parseAacTimestamp = function(packet) {
|
10593 | var frameStart, frameSize, frame, frameHeader;
|
10594 |
|
10595 |
|
10596 | frameStart = 10;
|
10597 | if (packet[5] & 0x40) {
|
10598 |
|
10599 | frameStart += 4;
|
10600 | frameStart += parseSyncSafeInteger(packet.subarray(10, 14));
|
10601 | }
|
10602 |
|
10603 |
|
10604 |
|
10605 | do {
|
10606 |
|
10607 | frameSize = parseSyncSafeInteger(packet.subarray(frameStart + 4, frameStart + 8));
|
10608 | if (frameSize < 1) {
|
10609 | return null;
|
10610 | }
|
10611 | frameHeader = String.fromCharCode(packet[frameStart],
|
10612 | packet[frameStart + 1],
|
10613 | packet[frameStart + 2],
|
10614 | packet[frameStart + 3]);
|
10615 |
|
10616 | if (frameHeader === 'PRIV') {
|
10617 | frame = packet.subarray(frameStart + 10, frameStart + frameSize + 10);
|
10618 |
|
10619 | for (var i = 0; i < frame.byteLength; i++) {
|
10620 | if (frame[i] === 0) {
|
10621 | var owner = parseIso88591(frame, 0, i);
|
10622 | if (owner === 'com.apple.streaming.transportStreamTimestamp') {
|
10623 | var d = frame.subarray(i + 1);
|
10624 | var size = ((d[3] & 0x01) << 30) |
|
10625 | (d[4] << 22) |
|
10626 | (d[5] << 14) |
|
10627 | (d[6] << 6) |
|
10628 | (d[7] >>> 2);
|
10629 | size *= 4;
|
10630 | size += d[7] & 0x03;
|
10631 |
|
10632 | return size;
|
10633 | }
|
10634 | break;
|
10635 | }
|
10636 | }
|
10637 | }
|
10638 |
|
10639 | frameStart += 10;
|
10640 | frameStart += frameSize;
|
10641 | } while (frameStart < packet.byteLength);
|
10642 | return null;
|
10643 | };
|
10644 |
|
10645 | module.exports = {
|
10646 | parseId3TagSize: parseId3TagSize,
|
10647 | parseAdtsSize: parseAdtsSize,
|
10648 | parseType: parseType,
|
10649 | parseSampleRate: parseSampleRate,
|
10650 | parseAacTimestamp: parseAacTimestamp
|
10651 | };
|
10652 |
|
10653 | },{}],40:[function(require,module,exports){
|
10654 | 'use strict';
|
10655 |
|
10656 | var Stream = require('../utils/stream.js');
|
10657 |
|
10658 | var AdtsStream;
|
10659 |
|
10660 | var
|
10661 | ADTS_SAMPLING_FREQUENCIES = [
|
10662 | 96000,
|
10663 | 88200,
|
10664 | 64000,
|
10665 | 48000,
|
10666 | 44100,
|
10667 | 32000,
|
10668 | 24000,
|
10669 | 22050,
|
10670 | 16000,
|
10671 | 12000,
|
10672 | 11025,
|
10673 | 8000,
|
10674 | 7350
|
10675 | ];
|
10676 |
|
10677 |
|
10678 |
|
10679 |
|
10680 |
|
10681 |
|
10682 |
|
10683 |
|
10684 |
|
10685 | AdtsStream = function() {
|
10686 | var buffer;
|
10687 |
|
10688 | AdtsStream.prototype.init.call(this);
|
10689 |
|
10690 | this.push = function(packet) {
|
10691 | var
|
10692 | i = 0,
|
10693 | frameNum = 0,
|
10694 | frameLength,
|
10695 | protectionSkipBytes,
|
10696 | frameEnd,
|
10697 | oldBuffer,
|
10698 | sampleCount,
|
10699 | adtsFrameDuration;
|
10700 |
|
10701 | if (packet.type !== 'audio') {
|
10702 |
|
10703 | return;
|
10704 | }
|
10705 |
|
10706 |
|
10707 |
|
10708 | if (buffer) {
|
10709 | oldBuffer = buffer;
|
10710 | buffer = new Uint8Array(oldBuffer.byteLength + packet.data.byteLength);
|
10711 | buffer.set(oldBuffer);
|
10712 | buffer.set(packet.data, oldBuffer.byteLength);
|
10713 | } else {
|
10714 | buffer = packet.data;
|
10715 | }
|
10716 |
|
10717 |
|
10718 |
|
10719 | while (i + 5 < buffer.length) {
|
10720 |
|
10721 |
|
10722 | if (buffer[i] !== 0xFF || (buffer[i + 1] & 0xF6) !== 0xF0) {
|
10723 |
|
10724 |
|
10725 | i++;
|
10726 | continue;
|
10727 | }
|
10728 |
|
10729 |
|
10730 |
|
10731 | protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
|
10732 |
|
10733 |
|
10734 |
|
10735 | frameLength = ((buffer[i + 3] & 0x03) << 11) |
|
10736 | (buffer[i + 4] << 3) |
|
10737 | ((buffer[i + 5] & 0xe0) >> 5);
|
10738 |
|
10739 | sampleCount = ((buffer[i + 6] & 0x03) + 1) * 1024;
|
10740 | adtsFrameDuration = (sampleCount * 90000) /
|
10741 | ADTS_SAMPLING_FREQUENCIES[(buffer[i + 2] & 0x3c) >>> 2];
|
10742 |
|
10743 | frameEnd = i + frameLength;
|
10744 |
|
10745 |
|
10746 |
|
10747 | if (buffer.byteLength < frameEnd) {
|
10748 | return;
|
10749 | }
|
10750 |
|
10751 |
|
10752 | this.trigger('data', {
|
10753 | pts: packet.pts + (frameNum * adtsFrameDuration),
|
10754 | dts: packet.dts + (frameNum * adtsFrameDuration),
|
10755 | sampleCount: sampleCount,
|
10756 | audioobjecttype: ((buffer[i + 2] >>> 6) & 0x03) + 1,
|
10757 | channelcount: ((buffer[i + 2] & 1) << 2) |
|
10758 | ((buffer[i + 3] & 0xc0) >>> 6),
|
10759 | samplerate: ADTS_SAMPLING_FREQUENCIES[(buffer[i + 2] & 0x3c) >>> 2],
|
10760 | samplingfrequencyindex: (buffer[i + 2] & 0x3c) >>> 2,
|
10761 |
|
10762 | samplesize: 16,
|
10763 | data: buffer.subarray(i + 7 + protectionSkipBytes, frameEnd)
|
10764 | });
|
10765 |
|
10766 |
|
10767 | if (buffer.byteLength === frameEnd) {
|
10768 | buffer = undefined;
|
10769 | return;
|
10770 | }
|
10771 |
|
10772 | frameNum++;
|
10773 |
|
10774 |
|
10775 | buffer = buffer.subarray(frameEnd);
|
10776 | }
|
10777 | };
|
10778 | this.flush = function() {
|
10779 | this.trigger('done');
|
10780 | };
|
10781 | };
|
10782 |
|
10783 | AdtsStream.prototype = new Stream();
|
10784 |
|
10785 | module.exports = AdtsStream;
|
10786 |
|
10787 | },{"../utils/stream.js":62}],41:[function(require,module,exports){
|
10788 | 'use strict';
|
10789 |
|
10790 | var Stream = require('../utils/stream.js');
|
10791 | var ExpGolomb = require('../utils/exp-golomb.js');
|
10792 |
|
10793 | var H264Stream, NalByteStream;
|
10794 | var PROFILES_WITH_OPTIONAL_SPS_DATA;
|
10795 |
|
10796 |
|
10797 |
|
10798 |
|
10799 | NalByteStream = function() {
|
10800 | var
|
10801 | syncPoint = 0,
|
10802 | i,
|
10803 | buffer;
|
10804 | NalByteStream.prototype.init.call(this);
|
10805 |
|
10806 | this.push = function(data) {
|
10807 | var swapBuffer;
|
10808 |
|
10809 | if (!buffer) {
|
10810 | buffer = data.data;
|
10811 | } else {
|
10812 | swapBuffer = new Uint8Array(buffer.byteLength + data.data.byteLength);
|
10813 | swapBuffer.set(buffer);
|
10814 | swapBuffer.set(data.data, buffer.byteLength);
|
10815 | buffer = swapBuffer;
|
10816 | }
|
10817 |
|
10818 |
|
10819 |
|
10820 |
|
10821 |
|
10822 |
|
10823 |
|
10824 |
|
10825 |
|
10826 |
|
10827 |
|
10828 |
|
10829 | for (; syncPoint < buffer.byteLength - 3; syncPoint++) {
|
10830 | if (buffer[syncPoint + 2] === 1) {
|
10831 |
|
10832 | i = syncPoint + 5;
|
10833 | break;
|
10834 | }
|
10835 | }
|
10836 |
|
10837 | while (i < buffer.byteLength) {
|
10838 |
|
10839 |
|
10840 | switch (buffer[i]) {
|
10841 | case 0:
|
10842 |
|
10843 | if (buffer[i - 1] !== 0) {
|
10844 | i += 2;
|
10845 | break;
|
10846 | } else if (buffer[i - 2] !== 0) {
|
10847 | i++;
|
10848 | break;
|
10849 | }
|
10850 |
|
10851 |
|
10852 | if (syncPoint + 3 !== i - 2) {
|
10853 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
10854 | }
|
10855 |
|
10856 |
|
10857 | do {
|
10858 | i++;
|
10859 | } while (buffer[i] !== 1 && i < buffer.length);
|
10860 | syncPoint = i - 2;
|
10861 | i += 3;
|
10862 | break;
|
10863 | case 1:
|
10864 |
|
10865 | if (buffer[i - 1] !== 0 ||
|
10866 | buffer[i - 2] !== 0) {
|
10867 | i += 3;
|
10868 | break;
|
10869 | }
|
10870 |
|
10871 |
|
10872 | this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
|
10873 | syncPoint = i - 2;
|
10874 | i += 3;
|
10875 | break;
|
10876 | default:
|
10877 |
|
10878 |
|
10879 | i += 3;
|
10880 | break;
|
10881 | }
|
10882 | }
|
10883 |
|
10884 | buffer = buffer.subarray(syncPoint);
|
10885 | i -= syncPoint;
|
10886 | syncPoint = 0;
|
10887 | };
|
10888 |
|
10889 | this.flush = function() {
|
10890 |
|
10891 | if (buffer && buffer.byteLength > 3) {
|
10892 | this.trigger('data', buffer.subarray(syncPoint + 3));
|
10893 | }
|
10894 |
|
10895 | buffer = null;
|
10896 | syncPoint = 0;
|
10897 | this.trigger('done');
|
10898 | };
|
10899 | };
|
10900 | NalByteStream.prototype = new Stream();
|
10901 |
|
10902 |
|
10903 |
|
10904 |
|
10905 | PROFILES_WITH_OPTIONAL_SPS_DATA = {
|
10906 | 100: true,
|
10907 | 110: true,
|
10908 | 122: true,
|
10909 | 244: true,
|
10910 | 44: true,
|
10911 | 83: true,
|
10912 | 86: true,
|
10913 | 118: true,
|
10914 | 128: true,
|
10915 | 138: true,
|
10916 | 139: true,
|
10917 | 134: true
|
10918 | };
|
10919 |
|
10920 |
|
10921 |
|
10922 |
|
10923 |
|
10924 | H264Stream = function() {
|
10925 | var
|
10926 | nalByteStream = new NalByteStream(),
|
10927 | self,
|
10928 | trackId,
|
10929 | currentPts,
|
10930 | currentDts,
|
10931 |
|
10932 | discardEmulationPreventionBytes,
|
10933 | readSequenceParameterSet,
|
10934 | skipScalingList;
|
10935 |
|
10936 | H264Stream.prototype.init.call(this);
|
10937 | self = this;
|
10938 |
|
10939 | this.push = function(packet) {
|
10940 | if (packet.type !== 'video') {
|
10941 | return;
|
10942 | }
|
10943 | trackId = packet.trackId;
|
10944 | currentPts = packet.pts;
|
10945 | currentDts = packet.dts;
|
10946 |
|
10947 | nalByteStream.push(packet);
|
10948 | };
|
10949 |
|
10950 | nalByteStream.on('data', function(data) {
|
10951 | var
|
10952 | event = {
|
10953 | trackId: trackId,
|
10954 | pts: currentPts,
|
10955 | dts: currentDts,
|
10956 | data: data
|
10957 | };
|
10958 |
|
10959 | switch (data[0] & 0x1f) {
|
10960 | case 0x05:
|
10961 | event.nalUnitType = 'slice_layer_without_partitioning_rbsp_idr';
|
10962 | break;
|
10963 | case 0x06:
|
10964 | event.nalUnitType = 'sei_rbsp';
|
10965 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
10966 | break;
|
10967 | case 0x07:
|
10968 | event.nalUnitType = 'seq_parameter_set_rbsp';
|
10969 | event.escapedRBSP = discardEmulationPreventionBytes(data.subarray(1));
|
10970 | event.config = readSequenceParameterSet(event.escapedRBSP);
|
10971 | break;
|
10972 | case 0x08:
|
10973 | event.nalUnitType = 'pic_parameter_set_rbsp';
|
10974 | break;
|
10975 | case 0x09:
|
10976 | event.nalUnitType = 'access_unit_delimiter_rbsp';
|
10977 | break;
|
10978 |
|
10979 | default:
|
10980 | break;
|
10981 | }
|
10982 | self.trigger('data', event);
|
10983 | });
|
10984 | nalByteStream.on('done', function() {
|
10985 | self.trigger('done');
|
10986 | });
|
10987 |
|
10988 | this.flush = function() {
|
10989 | nalByteStream.flush();
|
10990 | };
|
10991 |
|
10992 | |
10993 |
|
10994 |
|
10995 |
|
10996 |
|
10997 |
|
10998 |
|
10999 |
|
11000 |
|
11001 | skipScalingList = function(count, expGolombDecoder) {
|
11002 | var
|
11003 | lastScale = 8,
|
11004 | nextScale = 8,
|
11005 | j,
|
11006 | deltaScale;
|
11007 |
|
11008 | for (j = 0; j < count; j++) {
|
11009 | if (nextScale !== 0) {
|
11010 | deltaScale = expGolombDecoder.readExpGolomb();
|
11011 | nextScale = (lastScale + deltaScale + 256) % 256;
|
11012 | }
|
11013 |
|
11014 | lastScale = (nextScale === 0) ? lastScale : nextScale;
|
11015 | }
|
11016 | };
|
11017 |
|
11018 | |
11019 |
|
11020 |
|
11021 |
|
11022 |
|
11023 |
|
11024 |
|
11025 |
|
11026 | discardEmulationPreventionBytes = function(data) {
|
11027 | var
|
11028 | length = data.byteLength,
|
11029 | emulationPreventionBytesPositions = [],
|
11030 | i = 1,
|
11031 | newLength, newData;
|
11032 |
|
11033 |
|
11034 | while (i < length - 2) {
|
11035 | if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0x03) {
|
11036 | emulationPreventionBytesPositions.push(i + 2);
|
11037 | i += 2;
|
11038 | } else {
|
11039 | i++;
|
11040 | }
|
11041 | }
|
11042 |
|
11043 |
|
11044 |
|
11045 | if (emulationPreventionBytesPositions.length === 0) {
|
11046 | return data;
|
11047 | }
|
11048 |
|
11049 |
|
11050 | newLength = length - emulationPreventionBytesPositions.length;
|
11051 | newData = new Uint8Array(newLength);
|
11052 | var sourceIndex = 0;
|
11053 |
|
11054 | for (i = 0; i < newLength; sourceIndex++, i++) {
|
11055 | if (sourceIndex === emulationPreventionBytesPositions[0]) {
|
11056 |
|
11057 | sourceIndex++;
|
11058 |
|
11059 | emulationPreventionBytesPositions.shift();
|
11060 | }
|
11061 | newData[i] = data[sourceIndex];
|
11062 | }
|
11063 |
|
11064 | return newData;
|
11065 | };
|
11066 |
|
11067 | |
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 |
|
11075 |
|
11076 | readSequenceParameterSet = function(data) {
|
11077 | var
|
11078 | frameCropLeftOffset = 0,
|
11079 | frameCropRightOffset = 0,
|
11080 | frameCropTopOffset = 0,
|
11081 | frameCropBottomOffset = 0,
|
11082 | sarScale = 1,
|
11083 | expGolombDecoder, profileIdc, levelIdc, profileCompatibility,
|
11084 | chromaFormatIdc, picOrderCntType,
|
11085 | numRefFramesInPicOrderCntCycle, picWidthInMbsMinus1,
|
11086 | picHeightInMapUnitsMinus1,
|
11087 | frameMbsOnlyFlag,
|
11088 | scalingListCount,
|
11089 | sarRatio,
|
11090 | aspectRatioIdc,
|
11091 | i;
|
11092 |
|
11093 | expGolombDecoder = new ExpGolomb(data);
|
11094 | profileIdc = expGolombDecoder.readUnsignedByte();
|
11095 | profileCompatibility = expGolombDecoder.readUnsignedByte();
|
11096 | levelIdc = expGolombDecoder.readUnsignedByte();
|
11097 | expGolombDecoder.skipUnsignedExpGolomb();
|
11098 |
|
11099 |
|
11100 | if (PROFILES_WITH_OPTIONAL_SPS_DATA[profileIdc]) {
|
11101 | chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
|
11102 | if (chromaFormatIdc === 3) {
|
11103 | expGolombDecoder.skipBits(1);
|
11104 | }
|
11105 | expGolombDecoder.skipUnsignedExpGolomb();
|
11106 | expGolombDecoder.skipUnsignedExpGolomb();
|
11107 | expGolombDecoder.skipBits(1);
|
11108 | if (expGolombDecoder.readBoolean()) {
|
11109 | scalingListCount = (chromaFormatIdc !== 3) ? 8 : 12;
|
11110 | for (i = 0; i < scalingListCount; i++) {
|
11111 | if (expGolombDecoder.readBoolean()) {
|
11112 | if (i < 6) {
|
11113 | skipScalingList(16, expGolombDecoder);
|
11114 | } else {
|
11115 | skipScalingList(64, expGolombDecoder);
|
11116 | }
|
11117 | }
|
11118 | }
|
11119 | }
|
11120 | }
|
11121 |
|
11122 | expGolombDecoder.skipUnsignedExpGolomb();
|
11123 | picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
|
11124 |
|
11125 | if (picOrderCntType === 0) {
|
11126 | expGolombDecoder.readUnsignedExpGolomb();
|
11127 | } else if (picOrderCntType === 1) {
|
11128 | expGolombDecoder.skipBits(1);
|
11129 | expGolombDecoder.skipExpGolomb();
|
11130 | expGolombDecoder.skipExpGolomb();
|
11131 | numRefFramesInPicOrderCntCycle = expGolombDecoder.readUnsignedExpGolomb();
|
11132 | for (i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
|
11133 | expGolombDecoder.skipExpGolomb();
|
11134 | }
|
11135 | }
|
11136 |
|
11137 | expGolombDecoder.skipUnsignedExpGolomb();
|
11138 | expGolombDecoder.skipBits(1);
|
11139 |
|
11140 | picWidthInMbsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
11141 | picHeightInMapUnitsMinus1 = expGolombDecoder.readUnsignedExpGolomb();
|
11142 |
|
11143 | frameMbsOnlyFlag = expGolombDecoder.readBits(1);
|
11144 | if (frameMbsOnlyFlag === 0) {
|
11145 | expGolombDecoder.skipBits(1);
|
11146 | }
|
11147 |
|
11148 | expGolombDecoder.skipBits(1);
|
11149 | if (expGolombDecoder.readBoolean()) {
|
11150 | frameCropLeftOffset = expGolombDecoder.readUnsignedExpGolomb();
|
11151 | frameCropRightOffset = expGolombDecoder.readUnsignedExpGolomb();
|
11152 | frameCropTopOffset = expGolombDecoder.readUnsignedExpGolomb();
|
11153 | frameCropBottomOffset = expGolombDecoder.readUnsignedExpGolomb();
|
11154 | }
|
11155 | if (expGolombDecoder.readBoolean()) {
|
11156 |
|
11157 | if (expGolombDecoder.readBoolean()) {
|
11158 |
|
11159 | aspectRatioIdc = expGolombDecoder.readUnsignedByte();
|
11160 | switch (aspectRatioIdc) {
|
11161 | case 1: sarRatio = [1, 1]; break;
|
11162 | case 2: sarRatio = [12, 11]; break;
|
11163 | case 3: sarRatio = [10, 11]; break;
|
11164 | case 4: sarRatio = [16, 11]; break;
|
11165 | case 5: sarRatio = [40, 33]; break;
|
11166 | case 6: sarRatio = [24, 11]; break;
|
11167 | case 7: sarRatio = [20, 11]; break;
|
11168 | case 8: sarRatio = [32, 11]; break;
|
11169 | case 9: sarRatio = [80, 33]; break;
|
11170 | case 10: sarRatio = [18, 11]; break;
|
11171 | case 11: sarRatio = [15, 11]; break;
|
11172 | case 12: sarRatio = [64, 33]; break;
|
11173 | case 13: sarRatio = [160, 99]; break;
|
11174 | case 14: sarRatio = [4, 3]; break;
|
11175 | case 15: sarRatio = [3, 2]; break;
|
11176 | case 16: sarRatio = [2, 1]; break;
|
11177 | case 255: {
|
11178 | sarRatio = [expGolombDecoder.readUnsignedByte() << 8 |
|
11179 | expGolombDecoder.readUnsignedByte(),
|
11180 | expGolombDecoder.readUnsignedByte() << 8 |
|
11181 | expGolombDecoder.readUnsignedByte() ];
|
11182 | break;
|
11183 | }
|
11184 | }
|
11185 | if (sarRatio) {
|
11186 | sarScale = sarRatio[0] / sarRatio[1];
|
11187 | }
|
11188 | }
|
11189 | }
|
11190 | return {
|
11191 | profileIdc: profileIdc,
|
11192 | levelIdc: levelIdc,
|
11193 | profileCompatibility: profileCompatibility,
|
11194 | width: Math.ceil((((picWidthInMbsMinus1 + 1) * 16) - frameCropLeftOffset * 2 - frameCropRightOffset * 2) * sarScale),
|
11195 | height: ((2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16) - (frameCropTopOffset * 2) - (frameCropBottomOffset * 2)
|
11196 | };
|
11197 | };
|
11198 |
|
11199 | };
|
11200 | H264Stream.prototype = new Stream();
|
11201 |
|
11202 | module.exports = {
|
11203 | H264Stream: H264Stream,
|
11204 | NalByteStream: NalByteStream
|
11205 | };
|
11206 |
|
11207 | },{"../utils/exp-golomb.js":61,"../utils/stream.js":62}],42:[function(require,module,exports){
|
11208 | var highPrefix = [33, 16, 5, 32, 164, 27];
|
11209 | var lowPrefix = [33, 65, 108, 84, 1, 2, 4, 8, 168, 2, 4, 8, 17, 191, 252];
|
11210 | var zeroFill = function(count) {
|
11211 | var a = [];
|
11212 | while (count--) {
|
11213 | a.push(0);
|
11214 | }
|
11215 | return a;
|
11216 | };
|
11217 |
|
11218 | var makeTable = function(metaTable) {
|
11219 | return Object.keys(metaTable).reduce(function(obj, key) {
|
11220 | obj[key] = new Uint8Array(metaTable[key].reduce(function(arr, part) {
|
11221 | return arr.concat(part);
|
11222 | }, []));
|
11223 | return obj;
|
11224 | }, {});
|
11225 | };
|
11226 |
|
11227 |
|
11228 | var coneOfSilence = {
|
11229 | 96000: [highPrefix, [227, 64], zeroFill(154), [56]],
|
11230 | 88200: [highPrefix, [231], zeroFill(170), [56]],
|
11231 | 64000: [highPrefix, [248, 192], zeroFill(240), [56]],
|
11232 | 48000: [highPrefix, [255, 192], zeroFill(268), [55, 148, 128], zeroFill(54), [112]],
|
11233 | 44100: [highPrefix, [255, 192], zeroFill(268), [55, 163, 128], zeroFill(84), [112]],
|
11234 | 32000: [highPrefix, [255, 192], zeroFill(268), [55, 234], zeroFill(226), [112]],
|
11235 | 24000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 112], zeroFill(126), [224]],
|
11236 | 16000: [highPrefix, [255, 192], zeroFill(268), [55, 255, 128], zeroFill(268), [111, 255], zeroFill(269), [223, 108], zeroFill(195), [1, 192]],
|
11237 | 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]],
|
11238 | 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]],
|
11239 | 8000: [lowPrefix, zeroFill(268), [3, 121, 16], zeroFill(47), [7]]
|
11240 | };
|
11241 |
|
11242 | module.exports = makeTable(coneOfSilence);
|
11243 |
|
11244 | },{}],43:[function(require,module,exports){
|
11245 | 'use strict';
|
11246 |
|
11247 | var Stream = require('../utils/stream.js');
|
11248 |
|
11249 |
|
11250 |
|
11251 |
|
11252 |
|
11253 |
|
11254 | var CoalesceStream = function(options) {
|
11255 |
|
11256 |
|
11257 |
|
11258 | this.numberOfTracks = 0;
|
11259 | this.metadataStream = options.metadataStream;
|
11260 |
|
11261 | this.videoTags = [];
|
11262 | this.audioTags = [];
|
11263 | this.videoTrack = null;
|
11264 | this.audioTrack = null;
|
11265 | this.pendingCaptions = [];
|
11266 | this.pendingMetadata = [];
|
11267 | this.pendingTracks = 0;
|
11268 | this.processedTracks = 0;
|
11269 |
|
11270 | CoalesceStream.prototype.init.call(this);
|
11271 |
|
11272 |
|
11273 | this.push = function(output) {
|
11274 |
|
11275 |
|
11276 | if (output.text) {
|
11277 | return this.pendingCaptions.push(output);
|
11278 | }
|
11279 |
|
11280 | if (output.frames) {
|
11281 | return this.pendingMetadata.push(output);
|
11282 | }
|
11283 |
|
11284 | if (output.track.type === 'video') {
|
11285 | this.videoTrack = output.track;
|
11286 | this.videoTags = output.tags;
|
11287 | this.pendingTracks++;
|
11288 | }
|
11289 | if (output.track.type === 'audio') {
|
11290 | this.audioTrack = output.track;
|
11291 | this.audioTags = output.tags;
|
11292 | this.pendingTracks++;
|
11293 | }
|
11294 | };
|
11295 | };
|
11296 |
|
11297 | CoalesceStream.prototype = new Stream();
|
11298 | CoalesceStream.prototype.flush = function(flushSource) {
|
11299 | var
|
11300 | id3,
|
11301 | caption,
|
11302 | i,
|
11303 | timelineStartPts,
|
11304 | event = {
|
11305 | tags: {},
|
11306 | captions: [],
|
11307 | captionStreams: {},
|
11308 | metadata: []
|
11309 | };
|
11310 |
|
11311 | if (this.pendingTracks < this.numberOfTracks) {
|
11312 | if (flushSource !== 'VideoSegmentStream' &&
|
11313 | flushSource !== 'AudioSegmentStream') {
|
11314 |
|
11315 |
|
11316 |
|
11317 | return;
|
11318 | } else if (this.pendingTracks === 0) {
|
11319 |
|
11320 |
|
11321 |
|
11322 |
|
11323 |
|
11324 |
|
11325 | this.processedTracks++;
|
11326 |
|
11327 | if (this.processedTracks < this.numberOfTracks) {
|
11328 | return;
|
11329 | }
|
11330 | }
|
11331 | }
|
11332 |
|
11333 | this.processedTracks += this.pendingTracks;
|
11334 | this.pendingTracks = 0;
|
11335 |
|
11336 | if (this.processedTracks < this.numberOfTracks) {
|
11337 | return;
|
11338 | }
|
11339 |
|
11340 | if (this.videoTrack) {
|
11341 | timelineStartPts = this.videoTrack.timelineStartInfo.pts;
|
11342 | } else if (this.audioTrack) {
|
11343 | timelineStartPts = this.audioTrack.timelineStartInfo.pts;
|
11344 | }
|
11345 |
|
11346 | event.tags.videoTags = this.videoTags;
|
11347 | event.tags.audioTags = this.audioTags;
|
11348 |
|
11349 |
|
11350 |
|
11351 | for (i = 0; i < this.pendingCaptions.length; i++) {
|
11352 | caption = this.pendingCaptions[i];
|
11353 | caption.startTime = caption.startPts - timelineStartPts;
|
11354 | caption.startTime /= 90e3;
|
11355 | caption.endTime = caption.endPts - timelineStartPts;
|
11356 | caption.endTime /= 90e3;
|
11357 | event.captionStreams[caption.stream] = true;
|
11358 | event.captions.push(caption);
|
11359 | }
|
11360 |
|
11361 |
|
11362 |
|
11363 | for (i = 0; i < this.pendingMetadata.length; i++) {
|
11364 | id3 = this.pendingMetadata[i];
|
11365 | id3.cueTime = id3.pts - timelineStartPts;
|
11366 | id3.cueTime /= 90e3;
|
11367 | event.metadata.push(id3);
|
11368 | }
|
11369 |
|
11370 |
|
11371 | event.metadata.dispatchType = this.metadataStream.dispatchType;
|
11372 |
|
11373 |
|
11374 | this.videoTrack = null;
|
11375 | this.audioTrack = null;
|
11376 | this.videoTags = [];
|
11377 | this.audioTags = [];
|
11378 | this.pendingCaptions.length = 0;
|
11379 | this.pendingMetadata.length = 0;
|
11380 | this.pendingTracks = 0;
|
11381 | this.processedTracks = 0;
|
11382 |
|
11383 |
|
11384 | this.trigger('data', event);
|
11385 |
|
11386 | this.trigger('done');
|
11387 | };
|
11388 |
|
11389 | module.exports = CoalesceStream;
|
11390 |
|
11391 | },{"../utils/stream.js":62}],44:[function(require,module,exports){
|
11392 | 'use strict';
|
11393 |
|
11394 | var FlvTag = require('./flv-tag.js');
|
11395 |
|
11396 |
|
11397 |
|
11398 |
|
11399 |
|
11400 |
|
11401 |
|
11402 | var getFlvHeader = function(duration, audio, video) {
|
11403 | var
|
11404 | headBytes = new Uint8Array(3 + 1 + 1 + 4),
|
11405 | head = new DataView(headBytes.buffer),
|
11406 | metadata,
|
11407 | result,
|
11408 | metadataLength;
|
11409 |
|
11410 |
|
11411 | duration = duration || 0;
|
11412 | audio = audio === undefined ? true : audio;
|
11413 | video = video === undefined ? true : video;
|
11414 |
|
11415 |
|
11416 | head.setUint8(0, 0x46);
|
11417 | head.setUint8(1, 0x4c);
|
11418 | head.setUint8(2, 0x56);
|
11419 |
|
11420 |
|
11421 | head.setUint8(3, 0x01);
|
11422 |
|
11423 |
|
11424 | head.setUint8(4, (audio ? 0x04 : 0x00) | (video ? 0x01 : 0x00));
|
11425 |
|
11426 |
|
11427 | head.setUint32(5, headBytes.byteLength);
|
11428 |
|
11429 |
|
11430 | if (duration <= 0) {
|
11431 |
|
11432 |
|
11433 | result = new Uint8Array(headBytes.byteLength + 4);
|
11434 | result.set(headBytes);
|
11435 | result.set([0, 0, 0, 0], headBytes.byteLength);
|
11436 | return result;
|
11437 | }
|
11438 |
|
11439 |
|
11440 | metadata = new FlvTag(FlvTag.METADATA_TAG);
|
11441 | metadata.pts = metadata.dts = 0;
|
11442 | metadata.writeMetaDataDouble('duration', duration);
|
11443 | metadataLength = metadata.finalize().length;
|
11444 | result = new Uint8Array(headBytes.byteLength + metadataLength);
|
11445 | result.set(headBytes);
|
11446 | result.set(head.byteLength, metadataLength);
|
11447 |
|
11448 | return result;
|
11449 | };
|
11450 |
|
11451 | module.exports = getFlvHeader;
|
11452 |
|
11453 | },{"./flv-tag.js":45}],45:[function(require,module,exports){
|
11454 |
|
11455 |
|
11456 |
|
11457 |
|
11458 |
|
11459 | 'use strict';
|
11460 |
|
11461 | var FlvTag;
|
11462 |
|
11463 |
|
11464 | FlvTag = function(type, extraData) {
|
11465 | var
|
11466 |
|
11467 |
|
11468 | adHoc = 0,
|
11469 |
|
11470 |
|
11471 |
|
11472 |
|
11473 | bufferStartSize = 16384,
|
11474 |
|
11475 |
|
11476 |
|
11477 | prepareWrite = function(flv, count) {
|
11478 | var
|
11479 | bytes,
|
11480 | minLength = flv.position + count;
|
11481 | if (minLength < flv.bytes.byteLength) {
|
11482 |
|
11483 | return;
|
11484 | }
|
11485 |
|
11486 |
|
11487 | bytes = new Uint8Array(minLength * 2);
|
11488 | bytes.set(flv.bytes.subarray(0, flv.position), 0);
|
11489 | flv.bytes = bytes;
|
11490 | flv.view = new DataView(flv.bytes.buffer);
|
11491 | },
|
11492 |
|
11493 |
|
11494 | widthBytes = FlvTag.widthBytes || new Uint8Array('width'.length),
|
11495 | heightBytes = FlvTag.heightBytes || new Uint8Array('height'.length),
|
11496 | videocodecidBytes = FlvTag.videocodecidBytes || new Uint8Array('videocodecid'.length),
|
11497 | i;
|
11498 |
|
11499 | if (!FlvTag.widthBytes) {
|
11500 |
|
11501 |
|
11502 |
|
11503 |
|
11504 | for (i = 0; i < 'width'.length; i++) {
|
11505 | widthBytes[i] = 'width'.charCodeAt(i);
|
11506 | }
|
11507 | for (i = 0; i < 'height'.length; i++) {
|
11508 | heightBytes[i] = 'height'.charCodeAt(i);
|
11509 | }
|
11510 | for (i = 0; i < 'videocodecid'.length; i++) {
|
11511 | videocodecidBytes[i] = 'videocodecid'.charCodeAt(i);
|
11512 | }
|
11513 |
|
11514 | FlvTag.widthBytes = widthBytes;
|
11515 | FlvTag.heightBytes = heightBytes;
|
11516 | FlvTag.videocodecidBytes = videocodecidBytes;
|
11517 | }
|
11518 |
|
11519 | this.keyFrame = false;
|
11520 |
|
11521 | switch (type) {
|
11522 | case FlvTag.VIDEO_TAG:
|
11523 | this.length = 16;
|
11524 |
|
11525 | bufferStartSize *= 6;
|
11526 | break;
|
11527 | case FlvTag.AUDIO_TAG:
|
11528 | this.length = 13;
|
11529 | this.keyFrame = true;
|
11530 | break;
|
11531 | case FlvTag.METADATA_TAG:
|
11532 | this.length = 29;
|
11533 | this.keyFrame = true;
|
11534 | break;
|
11535 | default:
|
11536 | throw new Error('Unknown FLV tag type');
|
11537 | }
|
11538 |
|
11539 | this.bytes = new Uint8Array(bufferStartSize);
|
11540 | this.view = new DataView(this.bytes.buffer);
|
11541 | this.bytes[0] = type;
|
11542 | this.position = this.length;
|
11543 | this.keyFrame = extraData;
|
11544 |
|
11545 |
|
11546 | this.pts = 0;
|
11547 |
|
11548 | this.dts = 0;
|
11549 |
|
11550 |
|
11551 | this.writeBytes = function(bytes, offset, length) {
|
11552 | var
|
11553 | start = offset || 0,
|
11554 | end;
|
11555 | length = length || bytes.byteLength;
|
11556 | end = start + length;
|
11557 |
|
11558 | prepareWrite(this, length);
|
11559 | this.bytes.set(bytes.subarray(start, end), this.position);
|
11560 |
|
11561 | this.position += length;
|
11562 | this.length = Math.max(this.length, this.position);
|
11563 | };
|
11564 |
|
11565 |
|
11566 | this.writeByte = function(byte) {
|
11567 | prepareWrite(this, 1);
|
11568 | this.bytes[this.position] = byte;
|
11569 | this.position++;
|
11570 | this.length = Math.max(this.length, this.position);
|
11571 | };
|
11572 |
|
11573 |
|
11574 | this.writeShort = function(short) {
|
11575 | prepareWrite(this, 2);
|
11576 | this.view.setUint16(this.position, short);
|
11577 | this.position += 2;
|
11578 | this.length = Math.max(this.length, this.position);
|
11579 | };
|
11580 |
|
11581 |
|
11582 |
|
11583 | this.negIndex = function(pos) {
|
11584 | return this.bytes[this.length - pos];
|
11585 | };
|
11586 |
|
11587 |
|
11588 |
|
11589 |
|
11590 | this.nalUnitSize = function() {
|
11591 | if (adHoc === 0) {
|
11592 | return 0;
|
11593 | }
|
11594 |
|
11595 | return this.length - (adHoc + 4);
|
11596 | };
|
11597 |
|
11598 | this.startNalUnit = function() {
|
11599 |
|
11600 | if (adHoc > 0) {
|
11601 | throw new Error('Attempted to create new NAL wihout closing the old one');
|
11602 | }
|
11603 |
|
11604 |
|
11605 | adHoc = this.length;
|
11606 | this.length += 4;
|
11607 | this.position = this.length;
|
11608 | };
|
11609 |
|
11610 |
|
11611 | this.endNalUnit = function(nalContainer) {
|
11612 | var
|
11613 | nalStart,
|
11614 | nalLength;
|
11615 |
|
11616 |
|
11617 | if (this.length === adHoc + 4) {
|
11618 |
|
11619 | this.length -= 4;
|
11620 | } else if (adHoc > 0) {
|
11621 | nalStart = adHoc + 4;
|
11622 | nalLength = this.length - nalStart;
|
11623 |
|
11624 | this.position = adHoc;
|
11625 | this.view.setUint32(this.position, nalLength);
|
11626 | this.position = this.length;
|
11627 |
|
11628 | if (nalContainer) {
|
11629 |
|
11630 | nalContainer.push(this.bytes.subarray(nalStart, nalStart + nalLength));
|
11631 | }
|
11632 | }
|
11633 |
|
11634 | adHoc = 0;
|
11635 | };
|
11636 |
|
11637 | |
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 | this.writeMetaDataDouble = function(key, val) {
|
11643 | var i;
|
11644 | prepareWrite(this, 2 + key.length + 9);
|
11645 |
|
11646 |
|
11647 | this.view.setUint16(this.position, key.length);
|
11648 | this.position += 2;
|
11649 |
|
11650 |
|
11651 |
|
11652 |
|
11653 |
|
11654 | if (key === 'width') {
|
11655 | this.bytes.set(widthBytes, this.position);
|
11656 | this.position += 5;
|
11657 | } else if (key === 'height') {
|
11658 | this.bytes.set(heightBytes, this.position);
|
11659 | this.position += 6;
|
11660 | } else if (key === 'videocodecid') {
|
11661 | this.bytes.set(videocodecidBytes, this.position);
|
11662 | this.position += 12;
|
11663 | } else {
|
11664 | for (i = 0; i < key.length; i++) {
|
11665 | this.bytes[this.position] = key.charCodeAt(i);
|
11666 | this.position++;
|
11667 | }
|
11668 | }
|
11669 |
|
11670 |
|
11671 | this.position++;
|
11672 |
|
11673 |
|
11674 | this.view.setFloat64(this.position, val);
|
11675 | this.position += 8;
|
11676 |
|
11677 |
|
11678 | this.length = Math.max(this.length, this.position);
|
11679 | ++adHoc;
|
11680 | };
|
11681 |
|
11682 |
|
11683 | this.writeMetaDataBoolean = function(key, val) {
|
11684 | var i;
|
11685 | prepareWrite(this, 2);
|
11686 | this.view.setUint16(this.position, key.length);
|
11687 | this.position += 2;
|
11688 | for (i = 0; i < key.length; i++) {
|
11689 |
|
11690 | prepareWrite(this, 1);
|
11691 | this.bytes[this.position] = key.charCodeAt(i);
|
11692 | this.position++;
|
11693 | }
|
11694 | prepareWrite(this, 2);
|
11695 | this.view.setUint8(this.position, 0x01);
|
11696 | this.position++;
|
11697 | this.view.setUint8(this.position, val ? 0x01 : 0x00);
|
11698 | this.position++;
|
11699 | this.length = Math.max(this.length, this.position);
|
11700 | ++adHoc;
|
11701 | };
|
11702 |
|
11703 |
|
11704 | this.finalize = function() {
|
11705 | var
|
11706 | dtsDelta,
|
11707 | len;
|
11708 |
|
11709 | switch (this.bytes[0]) {
|
11710 |
|
11711 | case FlvTag.VIDEO_TAG:
|
11712 |
|
11713 |
|
11714 | this.bytes[11] = ((this.keyFrame || extraData) ? 0x10 : 0x20) | 0x07;
|
11715 | this.bytes[12] = extraData ? 0x00 : 0x01;
|
11716 |
|
11717 | dtsDelta = this.pts - this.dts;
|
11718 | this.bytes[13] = (dtsDelta & 0x00FF0000) >>> 16;
|
11719 | this.bytes[14] = (dtsDelta & 0x0000FF00) >>> 8;
|
11720 | this.bytes[15] = (dtsDelta & 0x000000FF) >>> 0;
|
11721 | break;
|
11722 |
|
11723 | case FlvTag.AUDIO_TAG:
|
11724 | this.bytes[11] = 0xAF;
|
11725 | this.bytes[12] = extraData ? 0x00 : 0x01;
|
11726 | break;
|
11727 |
|
11728 | case FlvTag.METADATA_TAG:
|
11729 | this.position = 11;
|
11730 | this.view.setUint8(this.position, 0x02);
|
11731 | this.position++;
|
11732 | this.view.setUint16(this.position, 0x0A);
|
11733 | this.position += 2;
|
11734 |
|
11735 | this.bytes.set([0x6f, 0x6e, 0x4d, 0x65,
|
11736 | 0x74, 0x61, 0x44, 0x61,
|
11737 | 0x74, 0x61], this.position);
|
11738 | this.position += 10;
|
11739 | this.bytes[this.position] = 0x08;
|
11740 | this.position++;
|
11741 | this.view.setUint32(this.position, adHoc);
|
11742 | this.position = this.length;
|
11743 | this.bytes.set([0, 0, 9], this.position);
|
11744 | this.position += 3;
|
11745 | this.length = this.position;
|
11746 | break;
|
11747 | }
|
11748 |
|
11749 | len = this.length - 11;
|
11750 |
|
11751 |
|
11752 | this.bytes[ 1] = (len & 0x00FF0000) >>> 16;
|
11753 | this.bytes[ 2] = (len & 0x0000FF00) >>> 8;
|
11754 | this.bytes[ 3] = (len & 0x000000FF) >>> 0;
|
11755 |
|
11756 | this.bytes[ 4] = (this.dts & 0x00FF0000) >>> 16;
|
11757 | this.bytes[ 5] = (this.dts & 0x0000FF00) >>> 8;
|
11758 | this.bytes[ 6] = (this.dts & 0x000000FF) >>> 0;
|
11759 | this.bytes[ 7] = (this.dts & 0xFF000000) >>> 24;
|
11760 |
|
11761 | this.bytes[ 8] = 0;
|
11762 | this.bytes[ 9] = 0;
|
11763 | this.bytes[10] = 0;
|
11764 |
|
11765 |
|
11766 |
|
11767 | prepareWrite(this, 4);
|
11768 | this.view.setUint32(this.length, this.length);
|
11769 | this.length += 4;
|
11770 | this.position += 4;
|
11771 |
|
11772 |
|
11773 | this.bytes = this.bytes.subarray(0, this.length);
|
11774 | this.frameTime = FlvTag.frameTime(this.bytes);
|
11775 |
|
11776 | return this;
|
11777 | };
|
11778 | };
|
11779 |
|
11780 | FlvTag.AUDIO_TAG = 0x08;
|
11781 | FlvTag.VIDEO_TAG = 0x09;
|
11782 | FlvTag.METADATA_TAG = 0x12;
|
11783 |
|
11784 |
|
11785 | FlvTag.isAudioFrame = function(tag) {
|
11786 | return FlvTag.AUDIO_TAG === tag[0];
|
11787 | };
|
11788 |
|
11789 |
|
11790 | FlvTag.isVideoFrame = function(tag) {
|
11791 | return FlvTag.VIDEO_TAG === tag[0];
|
11792 | };
|
11793 |
|
11794 |
|
11795 | FlvTag.isMetaData = function(tag) {
|
11796 | return FlvTag.METADATA_TAG === tag[0];
|
11797 | };
|
11798 |
|
11799 |
|
11800 | FlvTag.isKeyFrame = function(tag) {
|
11801 | if (FlvTag.isVideoFrame(tag)) {
|
11802 | return tag[11] === 0x17;
|
11803 | }
|
11804 |
|
11805 | if (FlvTag.isAudioFrame(tag)) {
|
11806 | return true;
|
11807 | }
|
11808 |
|
11809 | if (FlvTag.isMetaData(tag)) {
|
11810 | return true;
|
11811 | }
|
11812 |
|
11813 | return false;
|
11814 | };
|
11815 |
|
11816 |
|
11817 | FlvTag.frameTime = function(tag) {
|
11818 | var pts = tag[ 4] << 16;
|
11819 | pts |= tag[ 5] << 8;
|
11820 | pts |= tag[ 6] << 0;
|
11821 | pts |= tag[ 7] << 24;
|
11822 | return pts;
|
11823 | };
|
11824 |
|
11825 | module.exports = FlvTag;
|
11826 |
|
11827 | },{}],46:[function(require,module,exports){
|
11828 | module.exports = {
|
11829 | tag: require('./flv-tag'),
|
11830 | Transmuxer: require('./transmuxer'),
|
11831 | getFlvHeader: require('./flv-header')
|
11832 | };
|
11833 |
|
11834 | },{"./flv-header":44,"./flv-tag":45,"./transmuxer":48}],47:[function(require,module,exports){
|
11835 | 'use strict';
|
11836 |
|
11837 | var TagList = function() {
|
11838 | var self = this;
|
11839 |
|
11840 | this.list = [];
|
11841 |
|
11842 | this.push = function(tag) {
|
11843 | this.list.push({
|
11844 | bytes: tag.bytes,
|
11845 | dts: tag.dts,
|
11846 | pts: tag.pts,
|
11847 | keyFrame: tag.keyFrame,
|
11848 | metaDataTag: tag.metaDataTag
|
11849 | });
|
11850 | };
|
11851 |
|
11852 | Object.defineProperty(this, 'length', {
|
11853 | get: function() {
|
11854 | return self.list.length;
|
11855 | }
|
11856 | });
|
11857 | };
|
11858 |
|
11859 | module.exports = TagList;
|
11860 |
|
11861 | },{}],48:[function(require,module,exports){
|
11862 | 'use strict';
|
11863 |
|
11864 | var Stream = require('../utils/stream.js');
|
11865 | var FlvTag = require('./flv-tag.js');
|
11866 | var m2ts = require('../m2ts/m2ts.js');
|
11867 | var AdtsStream = require('../codecs/adts.js');
|
11868 | var H264Stream = require('../codecs/h264').H264Stream;
|
11869 | var CoalesceStream = require('./coalesce-stream.js');
|
11870 | var TagList = require('./tag-list.js');
|
11871 |
|
11872 | var
|
11873 | Transmuxer,
|
11874 | VideoSegmentStream,
|
11875 | AudioSegmentStream,
|
11876 | collectTimelineInfo,
|
11877 | metaDataTag,
|
11878 | extraDataTag;
|
11879 |
|
11880 |
|
11881 |
|
11882 |
|
11883 |
|
11884 |
|
11885 | collectTimelineInfo = function(track, data) {
|
11886 | if (typeof data.pts === 'number') {
|
11887 | if (track.timelineStartInfo.pts === undefined) {
|
11888 | track.timelineStartInfo.pts = data.pts;
|
11889 | } else {
|
11890 | track.timelineStartInfo.pts =
|
11891 | Math.min(track.timelineStartInfo.pts, data.pts);
|
11892 | }
|
11893 | }
|
11894 |
|
11895 | if (typeof data.dts === 'number') {
|
11896 | if (track.timelineStartInfo.dts === undefined) {
|
11897 | track.timelineStartInfo.dts = data.dts;
|
11898 | } else {
|
11899 | track.timelineStartInfo.dts =
|
11900 | Math.min(track.timelineStartInfo.dts, data.dts);
|
11901 | }
|
11902 | }
|
11903 | };
|
11904 |
|
11905 | metaDataTag = function(track, pts) {
|
11906 | var
|
11907 | tag = new FlvTag(FlvTag.METADATA_TAG);
|
11908 |
|
11909 | tag.dts = pts;
|
11910 | tag.pts = pts;
|
11911 |
|
11912 | tag.writeMetaDataDouble('videocodecid', 7);
|
11913 | tag.writeMetaDataDouble('width', track.width);
|
11914 | tag.writeMetaDataDouble('height', track.height);
|
11915 |
|
11916 | return tag;
|
11917 | };
|
11918 |
|
11919 | extraDataTag = function(track, pts) {
|
11920 | var
|
11921 | i,
|
11922 | tag = new FlvTag(FlvTag.VIDEO_TAG, true);
|
11923 |
|
11924 | tag.dts = pts;
|
11925 | tag.pts = pts;
|
11926 |
|
11927 | tag.writeByte(0x01);
|
11928 | tag.writeByte(track.profileIdc);
|
11929 | tag.writeByte(track.profileCompatibility);
|
11930 | tag.writeByte(track.levelIdc);
|
11931 | tag.writeByte(0xFC | 0x03);
|
11932 | tag.writeByte(0xE0 | 0x01);
|
11933 | tag.writeShort(track.sps[0].length);
|
11934 | tag.writeBytes(track.sps[0]);
|
11935 |
|
11936 | tag.writeByte(track.pps.length);
|
11937 | for (i = 0; i < track.pps.length; ++i) {
|
11938 | tag.writeShort(track.pps[i].length);
|
11939 | tag.writeBytes(track.pps[i]);
|
11940 | }
|
11941 |
|
11942 | return tag;
|
11943 | };
|
11944 |
|
11945 |
|
11946 |
|
11947 |
|
11948 |
|
11949 | AudioSegmentStream = function(track) {
|
11950 | var
|
11951 | adtsFrames = [],
|
11952 | videoKeyFrames = [],
|
11953 | oldExtraData;
|
11954 |
|
11955 | AudioSegmentStream.prototype.init.call(this);
|
11956 |
|
11957 | this.push = function(data) {
|
11958 | collectTimelineInfo(track, data);
|
11959 |
|
11960 | if (track) {
|
11961 | track.audioobjecttype = data.audioobjecttype;
|
11962 | track.channelcount = data.channelcount;
|
11963 | track.samplerate = data.samplerate;
|
11964 | track.samplingfrequencyindex = data.samplingfrequencyindex;
|
11965 | track.samplesize = data.samplesize;
|
11966 | track.extraData = (track.audioobjecttype << 11) |
|
11967 | (track.samplingfrequencyindex << 7) |
|
11968 | (track.channelcount << 3);
|
11969 | }
|
11970 |
|
11971 | data.pts = Math.round(data.pts / 90);
|
11972 | data.dts = Math.round(data.dts / 90);
|
11973 |
|
11974 |
|
11975 | adtsFrames.push(data);
|
11976 | };
|
11977 |
|
11978 | this.flush = function() {
|
11979 | var currentFrame, adtsFrame, lastMetaPts, tags = new TagList();
|
11980 |
|
11981 | if (adtsFrames.length === 0) {
|
11982 | this.trigger('done', 'AudioSegmentStream');
|
11983 | return;
|
11984 | }
|
11985 |
|
11986 | lastMetaPts = -Infinity;
|
11987 |
|
11988 | while (adtsFrames.length) {
|
11989 | currentFrame = adtsFrames.shift();
|
11990 |
|
11991 |
|
11992 | if (videoKeyFrames.length && currentFrame.pts >= videoKeyFrames[0]) {
|
11993 | lastMetaPts = videoKeyFrames.shift();
|
11994 | this.writeMetaDataTags(tags, lastMetaPts);
|
11995 | }
|
11996 |
|
11997 |
|
11998 |
|
11999 |
|
12000 | if (track.extraData !== oldExtraData || currentFrame.pts - lastMetaPts >= 1000) {
|
12001 | this.writeMetaDataTags(tags, currentFrame.pts);
|
12002 | oldExtraData = track.extraData;
|
12003 | lastMetaPts = currentFrame.pts;
|
12004 | }
|
12005 |
|
12006 | adtsFrame = new FlvTag(FlvTag.AUDIO_TAG);
|
12007 | adtsFrame.pts = currentFrame.pts;
|
12008 | adtsFrame.dts = currentFrame.dts;
|
12009 |
|
12010 | adtsFrame.writeBytes(currentFrame.data);
|
12011 |
|
12012 | tags.push(adtsFrame.finalize());
|
12013 | }
|
12014 |
|
12015 | videoKeyFrames.length = 0;
|
12016 | oldExtraData = null;
|
12017 | this.trigger('data', {track: track, tags: tags.list});
|
12018 |
|
12019 | this.trigger('done', 'AudioSegmentStream');
|
12020 | };
|
12021 |
|
12022 | this.writeMetaDataTags = function(tags, pts) {
|
12023 | var adtsFrame;
|
12024 |
|
12025 | adtsFrame = new FlvTag(FlvTag.METADATA_TAG);
|
12026 |
|
12027 |
|
12028 |
|
12029 | adtsFrame.pts = pts;
|
12030 | adtsFrame.dts = pts;
|
12031 |
|
12032 |
|
12033 | adtsFrame.writeMetaDataDouble('audiocodecid', 10);
|
12034 | adtsFrame.writeMetaDataBoolean('stereo', track.channelcount === 2);
|
12035 | adtsFrame.writeMetaDataDouble('audiosamplerate', track.samplerate);
|
12036 |
|
12037 | adtsFrame.writeMetaDataDouble('audiosamplesize', 16);
|
12038 |
|
12039 | tags.push(adtsFrame.finalize());
|
12040 |
|
12041 | adtsFrame = new FlvTag(FlvTag.AUDIO_TAG, true);
|
12042 |
|
12043 |
|
12044 |
|
12045 | adtsFrame.pts = pts;
|
12046 | adtsFrame.dts = pts;
|
12047 |
|
12048 | adtsFrame.view.setUint16(adtsFrame.position, track.extraData);
|
12049 | adtsFrame.position += 2;
|
12050 | adtsFrame.length = Math.max(adtsFrame.length, adtsFrame.position);
|
12051 |
|
12052 | tags.push(adtsFrame.finalize());
|
12053 | };
|
12054 |
|
12055 | this.onVideoKeyFrame = function(pts) {
|
12056 | videoKeyFrames.push(pts);
|
12057 | };
|
12058 | };
|
12059 | AudioSegmentStream.prototype = new Stream();
|
12060 |
|
12061 |
|
12062 |
|
12063 |
|
12064 |
|
12065 | VideoSegmentStream = function(track) {
|
12066 | var
|
12067 | nalUnits = [],
|
12068 | config,
|
12069 | h264Frame;
|
12070 | VideoSegmentStream.prototype.init.call(this);
|
12071 |
|
12072 | this.finishFrame = function(tags, frame) {
|
12073 | if (!frame) {
|
12074 | return;
|
12075 | }
|
12076 |
|
12077 |
|
12078 | if (config && track && track.newMetadata &&
|
12079 | (frame.keyFrame || tags.length === 0)) {
|
12080 |
|
12081 | var metaTag = metaDataTag(config, frame.dts).finalize();
|
12082 | var extraTag = extraDataTag(track, frame.dts).finalize();
|
12083 |
|
12084 | metaTag.metaDataTag = extraTag.metaDataTag = true;
|
12085 |
|
12086 | tags.push(metaTag);
|
12087 | tags.push(extraTag);
|
12088 | track.newMetadata = false;
|
12089 |
|
12090 | this.trigger('keyframe', frame.dts);
|
12091 | }
|
12092 |
|
12093 | frame.endNalUnit();
|
12094 | tags.push(frame.finalize());
|
12095 | h264Frame = null;
|
12096 | };
|
12097 |
|
12098 | this.push = function(data) {
|
12099 | collectTimelineInfo(track, data);
|
12100 |
|
12101 | data.pts = Math.round(data.pts / 90);
|
12102 | data.dts = Math.round(data.dts / 90);
|
12103 |
|
12104 |
|
12105 | nalUnits.push(data);
|
12106 | };
|
12107 |
|
12108 | this.flush = function() {
|
12109 | var
|
12110 | currentNal,
|
12111 | tags = new TagList();
|
12112 |
|
12113 |
|
12114 |
|
12115 | while (nalUnits.length) {
|
12116 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
12117 | break;
|
12118 | }
|
12119 | nalUnits.shift();
|
12120 | }
|
12121 |
|
12122 |
|
12123 | if (nalUnits.length === 0) {
|
12124 | this.trigger('done', 'VideoSegmentStream');
|
12125 | return;
|
12126 | }
|
12127 |
|
12128 | while (nalUnits.length) {
|
12129 | currentNal = nalUnits.shift();
|
12130 |
|
12131 |
|
12132 | if (currentNal.nalUnitType === 'seq_parameter_set_rbsp') {
|
12133 | track.newMetadata = true;
|
12134 | config = currentNal.config;
|
12135 | track.width = config.width;
|
12136 | track.height = config.height;
|
12137 | track.sps = [currentNal.data];
|
12138 | track.profileIdc = config.profileIdc;
|
12139 | track.levelIdc = config.levelIdc;
|
12140 | track.profileCompatibility = config.profileCompatibility;
|
12141 | h264Frame.endNalUnit();
|
12142 | } else if (currentNal.nalUnitType === 'pic_parameter_set_rbsp') {
|
12143 | track.newMetadata = true;
|
12144 | track.pps = [currentNal.data];
|
12145 | h264Frame.endNalUnit();
|
12146 | } else if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
|
12147 | if (h264Frame) {
|
12148 | this.finishFrame(tags, h264Frame);
|
12149 | }
|
12150 | h264Frame = new FlvTag(FlvTag.VIDEO_TAG);
|
12151 | h264Frame.pts = currentNal.pts;
|
12152 | h264Frame.dts = currentNal.dts;
|
12153 | } else {
|
12154 | if (currentNal.nalUnitType === 'slice_layer_without_partitioning_rbsp_idr') {
|
12155 |
|
12156 | h264Frame.keyFrame = true;
|
12157 | }
|
12158 | h264Frame.endNalUnit();
|
12159 | }
|
12160 | h264Frame.startNalUnit();
|
12161 | h264Frame.writeBytes(currentNal.data);
|
12162 | }
|
12163 | if (h264Frame) {
|
12164 | this.finishFrame(tags, h264Frame);
|
12165 | }
|
12166 |
|
12167 | this.trigger('data', {track: track, tags: tags.list});
|
12168 |
|
12169 |
|
12170 | this.trigger('done', 'VideoSegmentStream');
|
12171 | };
|
12172 | };
|
12173 |
|
12174 | VideoSegmentStream.prototype = new Stream();
|
12175 |
|
12176 |
|
12177 |
|
12178 |
|
12179 |
|
12180 | Transmuxer = function(options) {
|
12181 | var
|
12182 | self = this,
|
12183 |
|
12184 | packetStream, parseStream, elementaryStream,
|
12185 | videoTimestampRolloverStream, audioTimestampRolloverStream,
|
12186 | timedMetadataTimestampRolloverStream,
|
12187 | adtsStream, h264Stream,
|
12188 | videoSegmentStream, audioSegmentStream, captionStream,
|
12189 | coalesceStream;
|
12190 |
|
12191 | Transmuxer.prototype.init.call(this);
|
12192 |
|
12193 | options = options || {};
|
12194 |
|
12195 |
|
12196 | this.metadataStream = new m2ts.MetadataStream();
|
12197 |
|
12198 | options.metadataStream = this.metadataStream;
|
12199 |
|
12200 |
|
12201 | packetStream = new m2ts.TransportPacketStream();
|
12202 | parseStream = new m2ts.TransportParseStream();
|
12203 | elementaryStream = new m2ts.ElementaryStream();
|
12204 | videoTimestampRolloverStream = new m2ts.TimestampRolloverStream('video');
|
12205 | audioTimestampRolloverStream = new m2ts.TimestampRolloverStream('audio');
|
12206 | timedMetadataTimestampRolloverStream = new m2ts.TimestampRolloverStream('timed-metadata');
|
12207 |
|
12208 | adtsStream = new AdtsStream();
|
12209 | h264Stream = new H264Stream();
|
12210 | coalesceStream = new CoalesceStream(options);
|
12211 |
|
12212 |
|
12213 | packetStream
|
12214 | .pipe(parseStream)
|
12215 | .pipe(elementaryStream);
|
12216 |
|
12217 |
|
12218 |
|
12219 | elementaryStream
|
12220 | .pipe(videoTimestampRolloverStream)
|
12221 | .pipe(h264Stream);
|
12222 | elementaryStream
|
12223 | .pipe(audioTimestampRolloverStream)
|
12224 | .pipe(adtsStream);
|
12225 |
|
12226 | elementaryStream
|
12227 | .pipe(timedMetadataTimestampRolloverStream)
|
12228 | .pipe(this.metadataStream)
|
12229 | .pipe(coalesceStream);
|
12230 |
|
12231 | captionStream = new m2ts.CaptionStream();
|
12232 | h264Stream.pipe(captionStream)
|
12233 | .pipe(coalesceStream);
|
12234 |
|
12235 |
|
12236 | elementaryStream.on('data', function(data) {
|
12237 | var i, videoTrack, audioTrack;
|
12238 |
|
12239 | if (data.type === 'metadata') {
|
12240 | i = data.tracks.length;
|
12241 |
|
12242 |
|
12243 | while (i--) {
|
12244 | if (data.tracks[i].type === 'video') {
|
12245 | videoTrack = data.tracks[i];
|
12246 | } else if (data.tracks[i].type === 'audio') {
|
12247 | audioTrack = data.tracks[i];
|
12248 | }
|
12249 | }
|
12250 |
|
12251 |
|
12252 | if (videoTrack && !videoSegmentStream) {
|
12253 | coalesceStream.numberOfTracks++;
|
12254 | videoSegmentStream = new VideoSegmentStream(videoTrack);
|
12255 |
|
12256 |
|
12257 | h264Stream
|
12258 | .pipe(videoSegmentStream)
|
12259 | .pipe(coalesceStream);
|
12260 | }
|
12261 |
|
12262 | if (audioTrack && !audioSegmentStream) {
|
12263 |
|
12264 | coalesceStream.numberOfTracks++;
|
12265 | audioSegmentStream = new AudioSegmentStream(audioTrack);
|
12266 |
|
12267 |
|
12268 | adtsStream
|
12269 | .pipe(audioSegmentStream)
|
12270 | .pipe(coalesceStream);
|
12271 |
|
12272 | if (videoSegmentStream) {
|
12273 | videoSegmentStream.on('keyframe', audioSegmentStream.onVideoKeyFrame);
|
12274 | }
|
12275 | }
|
12276 | }
|
12277 | });
|
12278 |
|
12279 |
|
12280 | this.push = function(data) {
|
12281 | packetStream.push(data);
|
12282 | };
|
12283 |
|
12284 |
|
12285 | this.flush = function() {
|
12286 |
|
12287 | packetStream.flush();
|
12288 | };
|
12289 |
|
12290 |
|
12291 | this.resetCaptions = function() {
|
12292 | captionStream.reset();
|
12293 | };
|
12294 |
|
12295 |
|
12296 | coalesceStream.on('data', function(event) {
|
12297 | self.trigger('data', event);
|
12298 | });
|
12299 |
|
12300 |
|
12301 | coalesceStream.on('done', function() {
|
12302 | self.trigger('done');
|
12303 | });
|
12304 | };
|
12305 | Transmuxer.prototype = new Stream();
|
12306 |
|
12307 |
|
12308 | module.exports = Transmuxer;
|
12309 |
|
12310 | },{"../codecs/adts.js":40,"../codecs/h264":41,"../m2ts/m2ts.js":50,"../utils/stream.js":62,"./coalesce-stream.js":43,"./flv-tag.js":45,"./tag-list.js":47}],49:[function(require,module,exports){
|
12311 |
|
12312 |
|
12313 |
|
12314 |
|
12315 |
|
12316 |
|
12317 |
|
12318 |
|
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 |
|
12324 | 'use strict';
|
12325 |
|
12326 |
|
12327 |
|
12328 |
|
12329 |
|
12330 |
|
12331 |
|
12332 |
|
12333 |
|
12334 | var USER_DATA_REGISTERED_ITU_T_T35 = 4,
|
12335 | RBSP_TRAILING_BITS = 128,
|
12336 | Stream = require('../utils/stream');
|
12337 |
|
12338 |
|
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 |
|
12344 |
|
12345 |
|
12346 | var parseSei = function(bytes) {
|
12347 | var
|
12348 | i = 0,
|
12349 | result = {
|
12350 | payloadType: -1,
|
12351 | payloadSize: 0
|
12352 | },
|
12353 | payloadType = 0,
|
12354 | payloadSize = 0;
|
12355 |
|
12356 |
|
12357 | while (i < bytes.byteLength) {
|
12358 |
|
12359 | if (bytes[i] === RBSP_TRAILING_BITS) {
|
12360 | break;
|
12361 | }
|
12362 |
|
12363 |
|
12364 | while (bytes[i] === 0xFF) {
|
12365 | payloadType += 255;
|
12366 | i++;
|
12367 | }
|
12368 | payloadType += bytes[i++];
|
12369 |
|
12370 |
|
12371 | while (bytes[i] === 0xFF) {
|
12372 | payloadSize += 255;
|
12373 | i++;
|
12374 | }
|
12375 | payloadSize += bytes[i++];
|
12376 |
|
12377 |
|
12378 |
|
12379 | if (!result.payload && payloadType === USER_DATA_REGISTERED_ITU_T_T35) {
|
12380 | result.payloadType = payloadType;
|
12381 | result.payloadSize = payloadSize;
|
12382 | result.payload = bytes.subarray(i, i + payloadSize);
|
12383 | break;
|
12384 | }
|
12385 |
|
12386 |
|
12387 | i += payloadSize;
|
12388 | payloadType = 0;
|
12389 | payloadSize = 0;
|
12390 | }
|
12391 |
|
12392 | return result;
|
12393 | };
|
12394 |
|
12395 |
|
12396 | var parseUserData = function(sei) {
|
12397 |
|
12398 |
|
12399 | if (sei.payload[0] !== 181) {
|
12400 | return null;
|
12401 | }
|
12402 |
|
12403 |
|
12404 | if (((sei.payload[1] << 8) | sei.payload[2]) !== 49) {
|
12405 | return null;
|
12406 | }
|
12407 |
|
12408 |
|
12409 | if (String.fromCharCode(sei.payload[3],
|
12410 | sei.payload[4],
|
12411 | sei.payload[5],
|
12412 | sei.payload[6]) !== 'GA94') {
|
12413 | return null;
|
12414 | }
|
12415 |
|
12416 |
|
12417 | if (sei.payload[7] !== 0x03) {
|
12418 | return null;
|
12419 | }
|
12420 |
|
12421 |
|
12422 |
|
12423 | return sei.payload.subarray(8, sei.payload.length - 1);
|
12424 | };
|
12425 |
|
12426 |
|
12427 | var parseCaptionPackets = function(pts, userData) {
|
12428 | var results = [], i, count, offset, data;
|
12429 |
|
12430 |
|
12431 | if (!(userData[0] & 0x40)) {
|
12432 | return results;
|
12433 | }
|
12434 |
|
12435 |
|
12436 | count = userData[0] & 0x1f;
|
12437 | for (i = 0; i < count; i++) {
|
12438 | offset = i * 3;
|
12439 | data = {
|
12440 | type: userData[offset + 2] & 0x03,
|
12441 | pts: pts
|
12442 | };
|
12443 |
|
12444 |
|
12445 | if (userData[offset + 2] & 0x04) {
|
12446 | data.ccData = (userData[offset + 3] << 8) | userData[offset + 4];
|
12447 | results.push(data);
|
12448 | }
|
12449 | }
|
12450 | return results;
|
12451 | };
|
12452 |
|
12453 | var packetDropper = {
|
12454 | push: function() {}
|
12455 | };
|
12456 |
|
12457 | var CaptionStream = function() {
|
12458 |
|
12459 | CaptionStream.prototype.init.call(this);
|
12460 |
|
12461 | this.captionPackets_ = [];
|
12462 |
|
12463 | this.ccStreams_ = [
|
12464 | new Cea608Stream(0, 0),
|
12465 | new Cea608Stream(0, 1),
|
12466 | new Cea608Stream(1, 0),
|
12467 | new Cea608Stream(1, 1)
|
12468 | ];
|
12469 |
|
12470 | this.reset();
|
12471 |
|
12472 |
|
12473 | this.ccStreams_.forEach(function(cc) {
|
12474 | cc.on('data', this.trigger.bind(this, 'data'));
|
12475 | cc.on('done', this.trigger.bind(this, 'done'));
|
12476 | }, this);
|
12477 |
|
12478 | };
|
12479 |
|
12480 | CaptionStream.prototype = new Stream();
|
12481 | CaptionStream.prototype.push = function(event) {
|
12482 | var sei, userData;
|
12483 |
|
12484 |
|
12485 | if (event.nalUnitType !== 'sei_rbsp') {
|
12486 | return;
|
12487 | }
|
12488 |
|
12489 |
|
12490 | sei = parseSei(event.escapedRBSP);
|
12491 |
|
12492 |
|
12493 | if (sei.payloadType !== USER_DATA_REGISTERED_ITU_T_T35) {
|
12494 | return;
|
12495 | }
|
12496 |
|
12497 |
|
12498 | userData = parseUserData(sei);
|
12499 |
|
12500 |
|
12501 | if (!userData) {
|
12502 | return;
|
12503 | }
|
12504 |
|
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 | if (event.dts < this.latestDts_) {
|
12513 |
|
12514 | this.ignoreNextEqualDts_ = true;
|
12515 | return;
|
12516 | } else if ((event.dts === this.latestDts_) && (this.ignoreNextEqualDts_)) {
|
12517 |
|
12518 | this.ignoreNextEqualDts_ = false;
|
12519 | return;
|
12520 | }
|
12521 |
|
12522 |
|
12523 | this.captionPackets_ = this.captionPackets_.concat(parseCaptionPackets(event.pts, userData));
|
12524 | this.latestDts_ = event.dts;
|
12525 | };
|
12526 |
|
12527 | CaptionStream.prototype.flush = function() {
|
12528 |
|
12529 | if (!this.captionPackets_.length) {
|
12530 | this.ccStreams_.forEach(function(cc) {
|
12531 | cc.flush();
|
12532 | }, this);
|
12533 | return;
|
12534 | }
|
12535 |
|
12536 |
|
12537 |
|
12538 | this.captionPackets_.forEach(function(elem, idx) {
|
12539 | elem.presortIndex = idx;
|
12540 | });
|
12541 |
|
12542 |
|
12543 | this.captionPackets_.sort(function(a, b) {
|
12544 | if (a.pts === b.pts) {
|
12545 | return a.presortIndex - b.presortIndex;
|
12546 | }
|
12547 | return a.pts - b.pts;
|
12548 | });
|
12549 |
|
12550 | this.captionPackets_.forEach(function(packet) {
|
12551 | if (packet.type < 2) {
|
12552 |
|
12553 | this.dispatchCea608Packet(packet);
|
12554 | }
|
12555 |
|
12556 |
|
12557 | }, this);
|
12558 |
|
12559 | this.captionPackets_.length = 0;
|
12560 | this.ccStreams_.forEach(function(cc) {
|
12561 | cc.flush();
|
12562 | }, this);
|
12563 | return;
|
12564 | };
|
12565 |
|
12566 | CaptionStream.prototype.reset = function() {
|
12567 | this.latestDts_ = null;
|
12568 | this.ignoreNextEqualDts_ = false;
|
12569 | this.activeCea608Channel_ = null;
|
12570 |
|
12571 |
|
12572 |
|
12573 | this.activeCea608Streams_ = [
|
12574 | packetDropper,
|
12575 | packetDropper
|
12576 | ];
|
12577 | this.ccStreams_.forEach(function(ccStream) {
|
12578 | ccStream.reset();
|
12579 | });
|
12580 | };
|
12581 |
|
12582 | CaptionStream.prototype.dispatchCea608Packet = function(packet) {
|
12583 | if (this.setsChannel1Active(packet) && this.activeCea608Channel_ !== 1) {
|
12584 | this.activeCea608Channel_ = 1;
|
12585 | this.activeCea608Streams_ = [this.ccStreams_[0], this.ccStreams_[2]];
|
12586 | } else if (this.setsChannel2Active(packet) && this.activeCea608Channel_ !== 2) {
|
12587 | this.activeCea608Channel_ = 2;
|
12588 | this.activeCea608Streams_ = [this.ccStreams_[1], this.ccStreams_[3]];
|
12589 | }
|
12590 |
|
12591 |
|
12592 | this.activeCea608Streams_[packet.type].push(packet);
|
12593 | };
|
12594 |
|
12595 | CaptionStream.prototype.setsChannel1Active = function(packet) {
|
12596 | return ((packet.ccData & 0x7800) === 0x1000);
|
12597 | };
|
12598 | CaptionStream.prototype.setsChannel2Active = function(packet) {
|
12599 | return ((packet.ccData & 0x7800) === 0x1800);
|
12600 | };
|
12601 |
|
12602 |
|
12603 |
|
12604 |
|
12605 |
|
12606 | var CHARACTER_TRANSLATION = {
|
12607 | 0x2a: 0xe1,
|
12608 | 0x5c: 0xe9,
|
12609 | 0x5e: 0xed,
|
12610 | 0x5f: 0xf3,
|
12611 | 0x60: 0xfa,
|
12612 | 0x7b: 0xe7,
|
12613 | 0x7c: 0xf7,
|
12614 | 0x7d: 0xd1,
|
12615 | 0x7e: 0xf1,
|
12616 | 0x7f: 0x2588,
|
12617 | 0x0130: 0xae,
|
12618 | 0x0131: 0xb0,
|
12619 | 0x0132: 0xbd,
|
12620 | 0x0133: 0xbf,
|
12621 | 0x0134: 0x2122,
|
12622 | 0x0135: 0xa2,
|
12623 | 0x0136: 0xa3,
|
12624 | 0x0137: 0x266a,
|
12625 | 0x0138: 0xe0,
|
12626 | 0x0139: 0xa0,
|
12627 | 0x013a: 0xe8,
|
12628 | 0x013b: 0xe2,
|
12629 | 0x013c: 0xea,
|
12630 | 0x013d: 0xee,
|
12631 | 0x013e: 0xf4,
|
12632 | 0x013f: 0xfb,
|
12633 | 0x0220: 0xc1,
|
12634 | 0x0221: 0xc9,
|
12635 | 0x0222: 0xd3,
|
12636 | 0x0223: 0xda,
|
12637 | 0x0224: 0xdc,
|
12638 | 0x0225: 0xfc,
|
12639 | 0x0226: 0x2018,
|
12640 | 0x0227: 0xa1,
|
12641 | 0x0228: 0x2a,
|
12642 | 0x0229: 0x27,
|
12643 | 0x022a: 0x2014,
|
12644 | 0x022b: 0xa9,
|
12645 | 0x022c: 0x2120,
|
12646 | 0x022d: 0x2022,
|
12647 | 0x022e: 0x201c,
|
12648 | 0x022f: 0x201d,
|
12649 | 0x0230: 0xc0,
|
12650 | 0x0231: 0xc2,
|
12651 | 0x0232: 0xc7,
|
12652 | 0x0233: 0xc8,
|
12653 | 0x0234: 0xca,
|
12654 | 0x0235: 0xcb,
|
12655 | 0x0236: 0xeb,
|
12656 | 0x0237: 0xce,
|
12657 | 0x0238: 0xcf,
|
12658 | 0x0239: 0xef,
|
12659 | 0x023a: 0xd4,
|
12660 | 0x023b: 0xd9,
|
12661 | 0x023c: 0xf9,
|
12662 | 0x023d: 0xdb,
|
12663 | 0x023e: 0xab,
|
12664 | 0x023f: 0xbb,
|
12665 | 0x0320: 0xc3,
|
12666 | 0x0321: 0xe3,
|
12667 | 0x0322: 0xcd,
|
12668 | 0x0323: 0xcc,
|
12669 | 0x0324: 0xec,
|
12670 | 0x0325: 0xd2,
|
12671 | 0x0326: 0xf2,
|
12672 | 0x0327: 0xd5,
|
12673 | 0x0328: 0xf5,
|
12674 | 0x0329: 0x7b,
|
12675 | 0x032a: 0x7d,
|
12676 | 0x032b: 0x5c,
|
12677 | 0x032c: 0x5e,
|
12678 | 0x032d: 0x5f,
|
12679 | 0x032e: 0x7c,
|
12680 | 0x032f: 0x7e,
|
12681 | 0x0330: 0xc4,
|
12682 | 0x0331: 0xe4,
|
12683 | 0x0332: 0xd6,
|
12684 | 0x0333: 0xf6,
|
12685 | 0x0334: 0xdf,
|
12686 | 0x0335: 0xa5,
|
12687 | 0x0336: 0xa4,
|
12688 | 0x0337: 0x2502,
|
12689 | 0x0338: 0xc5,
|
12690 | 0x0339: 0xe5,
|
12691 | 0x033a: 0xd8,
|
12692 | 0x033b: 0xf8,
|
12693 | 0x033c: 0x250c,
|
12694 | 0x033d: 0x2510,
|
12695 | 0x033e: 0x2514,
|
12696 | 0x033f: 0x2518
|
12697 | };
|
12698 |
|
12699 | var getCharFromCode = function(code) {
|
12700 | if (code === null) {
|
12701 | return '';
|
12702 | }
|
12703 | code = CHARACTER_TRANSLATION[code] || code;
|
12704 | return String.fromCharCode(code);
|
12705 | };
|
12706 |
|
12707 |
|
12708 | var BOTTOM_ROW = 14;
|
12709 |
|
12710 |
|
12711 |
|
12712 | var ROWS = [0x1100, 0x1120, 0x1200, 0x1220, 0x1500, 0x1520, 0x1600, 0x1620,
|
12713 | 0x1700, 0x1720, 0x1000, 0x1300, 0x1320, 0x1400, 0x1420];
|
12714 |
|
12715 |
|
12716 |
|
12717 | var createDisplayBuffer = function() {
|
12718 | var result = [], i = BOTTOM_ROW + 1;
|
12719 | while (i--) {
|
12720 | result.push('');
|
12721 | }
|
12722 | return result;
|
12723 | };
|
12724 |
|
12725 | var Cea608Stream = function(field, dataChannel) {
|
12726 | Cea608Stream.prototype.init.call(this);
|
12727 |
|
12728 | this.field_ = field || 0;
|
12729 | this.dataChannel_ = dataChannel || 0;
|
12730 |
|
12731 | this.name_ = 'CC' + (((this.field_ << 1) | this.dataChannel_) + 1);
|
12732 |
|
12733 | this.setConstants();
|
12734 | this.reset();
|
12735 |
|
12736 | this.push = function(packet) {
|
12737 | var data, swap, char0, char1, text;
|
12738 |
|
12739 | data = packet.ccData & 0x7f7f;
|
12740 |
|
12741 |
|
12742 | if (data === this.lastControlCode_) {
|
12743 | this.lastControlCode_ = null;
|
12744 | return;
|
12745 | }
|
12746 |
|
12747 |
|
12748 | if ((data & 0xf000) === 0x1000) {
|
12749 | this.lastControlCode_ = data;
|
12750 | } else if (data !== this.PADDING_) {
|
12751 | this.lastControlCode_ = null;
|
12752 | }
|
12753 |
|
12754 | char0 = data >>> 8;
|
12755 | char1 = data & 0xff;
|
12756 |
|
12757 | if (data === this.PADDING_) {
|
12758 | return;
|
12759 |
|
12760 | } else if (data === this.RESUME_CAPTION_LOADING_) {
|
12761 | this.mode_ = 'popOn';
|
12762 |
|
12763 | } else if (data === this.END_OF_CAPTION_) {
|
12764 | this.clearFormatting(packet.pts);
|
12765 |
|
12766 | this.flushDisplayed(packet.pts);
|
12767 |
|
12768 |
|
12769 | swap = this.displayed_;
|
12770 | this.displayed_ = this.nonDisplayed_;
|
12771 | this.nonDisplayed_ = swap;
|
12772 |
|
12773 |
|
12774 | this.startPts_ = packet.pts;
|
12775 |
|
12776 | } else if (data === this.ROLL_UP_2_ROWS_) {
|
12777 | this.topRow_ = BOTTOM_ROW - 1;
|
12778 | this.mode_ = 'rollUp';
|
12779 | } else if (data === this.ROLL_UP_3_ROWS_) {
|
12780 | this.topRow_ = BOTTOM_ROW - 2;
|
12781 | this.mode_ = 'rollUp';
|
12782 | } else if (data === this.ROLL_UP_4_ROWS_) {
|
12783 | this.topRow_ = BOTTOM_ROW - 3;
|
12784 | this.mode_ = 'rollUp';
|
12785 | } else if (data === this.CARRIAGE_RETURN_) {
|
12786 | this.clearFormatting(packet.pts);
|
12787 | this.flushDisplayed(packet.pts);
|
12788 | this.shiftRowsUp_();
|
12789 | this.startPts_ = packet.pts;
|
12790 |
|
12791 | } else if (data === this.BACKSPACE_) {
|
12792 | if (this.mode_ === 'popOn') {
|
12793 | this.nonDisplayed_[BOTTOM_ROW] = this.nonDisplayed_[BOTTOM_ROW].slice(0, -1);
|
12794 | } else {
|
12795 | this.displayed_[BOTTOM_ROW] = this.displayed_[BOTTOM_ROW].slice(0, -1);
|
12796 | }
|
12797 | } else if (data === this.ERASE_DISPLAYED_MEMORY_) {
|
12798 | this.flushDisplayed(packet.pts);
|
12799 | this.displayed_ = createDisplayBuffer();
|
12800 | } else if (data === this.ERASE_NON_DISPLAYED_MEMORY_) {
|
12801 | this.nonDisplayed_ = createDisplayBuffer();
|
12802 |
|
12803 | } else if (data === this.RESUME_DIRECT_CAPTIONING_) {
|
12804 | this.mode_ = 'paintOn';
|
12805 |
|
12806 |
|
12807 | } else if (this.isSpecialCharacter(char0, char1)) {
|
12808 |
|
12809 |
|
12810 |
|
12811 |
|
12812 | char0 = (char0 & 0x03) << 8;
|
12813 | text = getCharFromCode(char0 | char1);
|
12814 | this[this.mode_](packet.pts, text);
|
12815 | this.column_++;
|
12816 |
|
12817 |
|
12818 | } else if (this.isExtCharacter(char0, char1)) {
|
12819 |
|
12820 |
|
12821 |
|
12822 |
|
12823 |
|
12824 |
|
12825 | if (this.mode_ === 'popOn') {
|
12826 | this.nonDisplayed_[this.row_] = this.nonDisplayed_[this.row_].slice(0, -1);
|
12827 | } else {
|
12828 | this.displayed_[BOTTOM_ROW] = this.displayed_[BOTTOM_ROW].slice(0, -1);
|
12829 | }
|
12830 |
|
12831 |
|
12832 |
|
12833 |
|
12834 |
|
12835 | char0 = (char0 & 0x03) << 8;
|
12836 | text = getCharFromCode(char0 | char1);
|
12837 | this[this.mode_](packet.pts, text);
|
12838 | this.column_++;
|
12839 |
|
12840 |
|
12841 | } else if (this.isMidRowCode(char0, char1)) {
|
12842 |
|
12843 | this.clearFormatting(packet.pts);
|
12844 |
|
12845 |
|
12846 |
|
12847 | this[this.mode_](packet.pts, ' ');
|
12848 | this.column_++;
|
12849 |
|
12850 | if ((char1 & 0xe) === 0xe) {
|
12851 | this.addFormatting(packet.pts, ['i']);
|
12852 | }
|
12853 |
|
12854 | if ((char1 & 0x1) === 0x1) {
|
12855 | this.addFormatting(packet.pts, ['u']);
|
12856 | }
|
12857 |
|
12858 |
|
12859 | } else if (this.isOffsetControlCode(char0, char1)) {
|
12860 |
|
12861 |
|
12862 |
|
12863 |
|
12864 | this.column_ += (char1 & 0x03);
|
12865 |
|
12866 |
|
12867 | } else if (this.isPAC(char0, char1)) {
|
12868 |
|
12869 |
|
12870 |
|
12871 | var row = ROWS.indexOf(data & 0x1f20);
|
12872 |
|
12873 | if (row !== this.row_) {
|
12874 |
|
12875 | this.clearFormatting(packet.pts);
|
12876 | this.row_ = row;
|
12877 | }
|
12878 |
|
12879 |
|
12880 | if ((char1 & 0x1) && (this.formatting_.indexOf('u') === -1)) {
|
12881 | this.addFormatting(packet.pts, ['u']);
|
12882 | }
|
12883 |
|
12884 | if ((data & 0x10) === 0x10) {
|
12885 |
|
12886 |
|
12887 |
|
12888 |
|
12889 | this.column_ = ((data & 0xe) >> 1) * 4;
|
12890 | }
|
12891 |
|
12892 | if (this.isColorPAC(char1)) {
|
12893 |
|
12894 |
|
12895 |
|
12896 |
|
12897 | if ((char1 & 0xe) === 0xe) {
|
12898 | this.addFormatting(packet.pts, ['i']);
|
12899 | }
|
12900 | }
|
12901 |
|
12902 |
|
12903 | } else if (this.isNormalChar(char0)) {
|
12904 | if (char1 === 0x00) {
|
12905 | char1 = null;
|
12906 | }
|
12907 | text = getCharFromCode(char0);
|
12908 | text += getCharFromCode(char1);
|
12909 | this[this.mode_](packet.pts, text);
|
12910 | this.column_ += text.length;
|
12911 |
|
12912 | }
|
12913 |
|
12914 | };
|
12915 | };
|
12916 | Cea608Stream.prototype = new Stream();
|
12917 |
|
12918 |
|
12919 | Cea608Stream.prototype.flushDisplayed = function(pts) {
|
12920 | var content = this.displayed_
|
12921 |
|
12922 | .map(function(row) {
|
12923 | return row.trim();
|
12924 | })
|
12925 |
|
12926 | .join('\n')
|
12927 |
|
12928 | .replace(/^\n+|\n+$/g, '');
|
12929 |
|
12930 | if (content.length) {
|
12931 | this.trigger('data', {
|
12932 | startPts: this.startPts_,
|
12933 | endPts: pts,
|
12934 | text: content,
|
12935 | stream: this.name_
|
12936 | });
|
12937 | }
|
12938 | };
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 | Cea608Stream.prototype.reset = function() {
|
12944 | this.mode_ = 'popOn';
|
12945 |
|
12946 |
|
12947 |
|
12948 |
|
12949 | this.topRow_ = 0;
|
12950 | this.startPts_ = 0;
|
12951 | this.displayed_ = createDisplayBuffer();
|
12952 | this.nonDisplayed_ = createDisplayBuffer();
|
12953 | this.lastControlCode_ = null;
|
12954 |
|
12955 |
|
12956 | this.column_ = 0;
|
12957 | this.row_ = BOTTOM_ROW;
|
12958 |
|
12959 |
|
12960 | this.formatting_ = [];
|
12961 | };
|
12962 |
|
12963 |
|
12964 |
|
12965 |
|
12966 | Cea608Stream.prototype.setConstants = function() {
|
12967 |
|
12968 |
|
12969 |
|
12970 |
|
12971 |
|
12972 |
|
12973 |
|
12974 |
|
12975 |
|
12976 |
|
12977 |
|
12978 |
|
12979 | if (this.dataChannel_ === 0) {
|
12980 | this.BASE_ = 0x10;
|
12981 | this.EXT_ = 0x11;
|
12982 | this.CONTROL_ = (0x14 | this.field_) << 8;
|
12983 | this.OFFSET_ = 0x17;
|
12984 | } else if (this.dataChannel_ === 1) {
|
12985 | this.BASE_ = 0x18;
|
12986 | this.EXT_ = 0x19;
|
12987 | this.CONTROL_ = (0x1c | this.field_) << 8;
|
12988 | this.OFFSET_ = 0x1f;
|
12989 | }
|
12990 |
|
12991 |
|
12992 |
|
12993 |
|
12994 |
|
12995 | this.PADDING_ = 0x0000;
|
12996 |
|
12997 | this.RESUME_CAPTION_LOADING_ = this.CONTROL_ | 0x20;
|
12998 | this.END_OF_CAPTION_ = this.CONTROL_ | 0x2f;
|
12999 |
|
13000 | this.ROLL_UP_2_ROWS_ = this.CONTROL_ | 0x25;
|
13001 | this.ROLL_UP_3_ROWS_ = this.CONTROL_ | 0x26;
|
13002 | this.ROLL_UP_4_ROWS_ = this.CONTROL_ | 0x27;
|
13003 | this.CARRIAGE_RETURN_ = this.CONTROL_ | 0x2d;
|
13004 |
|
13005 | this.RESUME_DIRECT_CAPTIONING_ = this.CONTROL_ | 0x29;
|
13006 |
|
13007 | this.BACKSPACE_ = this.CONTROL_ | 0x21;
|
13008 | this.ERASE_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2c;
|
13009 | this.ERASE_NON_DISPLAYED_MEMORY_ = this.CONTROL_ | 0x2e;
|
13010 | };
|
13011 |
|
13012 |
|
13013 |
|
13014 |
|
13015 |
|
13016 |
|
13017 |
|
13018 |
|
13019 |
|
13020 |
|
13021 |
|
13022 |
|
13023 | Cea608Stream.prototype.isSpecialCharacter = function(char0, char1) {
|
13024 | return (char0 === this.EXT_ && char1 >= 0x30 && char1 <= 0x3f);
|
13025 | };
|
13026 |
|
13027 |
|
13028 |
|
13029 |
|
13030 |
|
13031 |
|
13032 |
|
13033 |
|
13034 |
|
13035 |
|
13036 |
|
13037 |
|
13038 | Cea608Stream.prototype.isExtCharacter = function(char0, char1) {
|
13039 | return ((char0 === (this.EXT_ + 1) || char0 === (this.EXT_ + 2)) &&
|
13040 | (char1 >= 0x20 && char1 <= 0x3f));
|
13041 | };
|
13042 |
|
13043 |
|
13044 |
|
13045 |
|
13046 |
|
13047 |
|
13048 |
|
13049 |
|
13050 |
|
13051 |
|
13052 |
|
13053 |
|
13054 | Cea608Stream.prototype.isMidRowCode = function(char0, char1) {
|
13055 | return (char0 === this.EXT_ && (char1 >= 0x20 && char1 <= 0x2f));
|
13056 | };
|
13057 |
|
13058 |
|
13059 |
|
13060 |
|
13061 |
|
13062 |
|
13063 |
|
13064 |
|
13065 |
|
13066 |
|
13067 |
|
13068 |
|
13069 | Cea608Stream.prototype.isOffsetControlCode = function(char0, char1) {
|
13070 | return (char0 === this.OFFSET_ && (char1 >= 0x21 && char1 <= 0x23));
|
13071 | };
|
13072 |
|
13073 |
|
13074 |
|
13075 |
|
13076 |
|
13077 |
|
13078 |
|
13079 |
|
13080 |
|
13081 |
|
13082 |
|
13083 |
|
13084 | Cea608Stream.prototype.isPAC = function(char0, char1) {
|
13085 | return (char0 >= this.BASE_ && char0 < (this.BASE_ + 8) &&
|
13086 | (char1 >= 0x40 && char1 <= 0x7f));
|
13087 | };
|
13088 |
|
13089 |
|
13090 |
|
13091 |
|
13092 |
|
13093 |
|
13094 |
|
13095 |
|
13096 |
|
13097 |
|
13098 | Cea608Stream.prototype.isColorPAC = function(char1) {
|
13099 | return ((char1 >= 0x40 && char1 <= 0x4f) || (char1 >= 0x60 && char1 <= 0x7f));
|
13100 | };
|
13101 |
|
13102 |
|
13103 |
|
13104 |
|
13105 |
|
13106 |
|
13107 |
|
13108 |
|
13109 |
|
13110 | Cea608Stream.prototype.isNormalChar = function(char) {
|
13111 | return (char >= 0x20 && char <= 0x7f);
|
13112 | };
|
13113 |
|
13114 |
|
13115 |
|
13116 | Cea608Stream.prototype.addFormatting = function(pts, format) {
|
13117 | this.formatting_ = this.formatting_.concat(format);
|
13118 | var text = format.reduce(function(text, format) {
|
13119 | return text + '<' + format + '>';
|
13120 | }, '');
|
13121 | this[this.mode_](pts, text);
|
13122 | };
|
13123 |
|
13124 |
|
13125 |
|
13126 | Cea608Stream.prototype.clearFormatting = function(pts) {
|
13127 | if (!this.formatting_.length) {
|
13128 | return;
|
13129 | }
|
13130 | var text = this.formatting_.reverse().reduce(function(text, format) {
|
13131 | return text + '</' + format + '>';
|
13132 | }, '');
|
13133 | this.formatting_ = [];
|
13134 | this[this.mode_](pts, text);
|
13135 | };
|
13136 |
|
13137 |
|
13138 | Cea608Stream.prototype.popOn = function(pts, text) {
|
13139 | var baseRow = this.nonDisplayed_[this.row_];
|
13140 |
|
13141 |
|
13142 | baseRow += text;
|
13143 | this.nonDisplayed_[this.row_] = baseRow;
|
13144 | };
|
13145 |
|
13146 | Cea608Stream.prototype.rollUp = function(pts, text) {
|
13147 | var baseRow = this.displayed_[BOTTOM_ROW];
|
13148 |
|
13149 | baseRow += text;
|
13150 | this.displayed_[BOTTOM_ROW] = baseRow;
|
13151 |
|
13152 | };
|
13153 |
|
13154 | Cea608Stream.prototype.shiftRowsUp_ = function() {
|
13155 | var i;
|
13156 |
|
13157 | for (i = 0; i < this.topRow_; i++) {
|
13158 | this.displayed_[i] = '';
|
13159 | }
|
13160 |
|
13161 | for (i = this.topRow_; i < BOTTOM_ROW; i++) {
|
13162 | this.displayed_[i] = this.displayed_[i + 1];
|
13163 | }
|
13164 |
|
13165 | this.displayed_[BOTTOM_ROW] = '';
|
13166 | };
|
13167 |
|
13168 |
|
13169 | Cea608Stream.prototype.paintOn = function() {};
|
13170 |
|
13171 |
|
13172 | module.exports = {
|
13173 | CaptionStream: CaptionStream,
|
13174 | Cea608Stream: Cea608Stream
|
13175 | };
|
13176 |
|
13177 | },{"../utils/stream":62}],50:[function(require,module,exports){
|
13178 |
|
13179 |
|
13180 |
|
13181 |
|
13182 |
|
13183 |
|
13184 |
|
13185 |
|
13186 |
|
13187 |
|
13188 | 'use strict';
|
13189 | var Stream = require('../utils/stream.js'),
|
13190 | CaptionStream = require('./caption-stream'),
|
13191 | StreamTypes = require('./stream-types'),
|
13192 | TimestampRolloverStream = require('./timestamp-rollover-stream').TimestampRolloverStream;
|
13193 |
|
13194 | var m2tsStreamTypes = require('./stream-types.js');
|
13195 |
|
13196 |
|
13197 | var TransportPacketStream, TransportParseStream, ElementaryStream;
|
13198 |
|
13199 |
|
13200 | var
|
13201 | MP2T_PACKET_LENGTH = 188,
|
13202 | SYNC_BYTE = 0x47;
|
13203 |
|
13204 |
|
13205 |
|
13206 |
|
13207 |
|
13208 | TransportPacketStream = function() {
|
13209 | var
|
13210 | buffer = new Uint8Array(MP2T_PACKET_LENGTH),
|
13211 | bytesInBuffer = 0;
|
13212 |
|
13213 | TransportPacketStream.prototype.init.call(this);
|
13214 |
|
13215 |
|
13216 |
|
13217 | this.push = function(bytes) {
|
13218 | var
|
13219 | startIndex = 0,
|
13220 | endIndex = MP2T_PACKET_LENGTH,
|
13221 | everything;
|
13222 |
|
13223 |
|
13224 |
|
13225 | if (bytesInBuffer) {
|
13226 | everything = new Uint8Array(bytes.byteLength + bytesInBuffer);
|
13227 | everything.set(buffer.subarray(0, bytesInBuffer));
|
13228 | everything.set(bytes, bytesInBuffer);
|
13229 | bytesInBuffer = 0;
|
13230 | } else {
|
13231 | everything = bytes;
|
13232 | }
|
13233 |
|
13234 |
|
13235 | while (endIndex < everything.byteLength) {
|
13236 |
|
13237 | if (everything[startIndex] === SYNC_BYTE && everything[endIndex] === SYNC_BYTE) {
|
13238 |
|
13239 |
|
13240 | this.trigger('data', everything.subarray(startIndex, endIndex));
|
13241 | startIndex += MP2T_PACKET_LENGTH;
|
13242 | endIndex += MP2T_PACKET_LENGTH;
|
13243 | continue;
|
13244 | }
|
13245 |
|
13246 |
|
13247 |
|
13248 | startIndex++;
|
13249 | endIndex++;
|
13250 | }
|
13251 |
|
13252 |
|
13253 |
|
13254 |
|
13255 | if (startIndex < everything.byteLength) {
|
13256 | buffer.set(everything.subarray(startIndex), 0);
|
13257 | bytesInBuffer = everything.byteLength - startIndex;
|
13258 | }
|
13259 | };
|
13260 |
|
13261 | this.flush = function() {
|
13262 |
|
13263 |
|
13264 |
|
13265 | if (bytesInBuffer === MP2T_PACKET_LENGTH && buffer[0] === SYNC_BYTE) {
|
13266 | this.trigger('data', buffer);
|
13267 | bytesInBuffer = 0;
|
13268 | }
|
13269 | this.trigger('done');
|
13270 | };
|
13271 | };
|
13272 | TransportPacketStream.prototype = new Stream();
|
13273 |
|
13274 |
|
13275 |
|
13276 |
|
13277 |
|
13278 | TransportParseStream = function() {
|
13279 | var parsePsi, parsePat, parsePmt, self;
|
13280 | TransportParseStream.prototype.init.call(this);
|
13281 | self = this;
|
13282 |
|
13283 | this.packetsWaitingForPmt = [];
|
13284 | this.programMapTable = undefined;
|
13285 |
|
13286 | parsePsi = function(payload, psi) {
|
13287 | var offset = 0;
|
13288 |
|
13289 |
|
13290 |
|
13291 |
|
13292 |
|
13293 |
|
13294 |
|
13295 | if (psi.payloadUnitStartIndicator) {
|
13296 | offset += payload[offset] + 1;
|
13297 | }
|
13298 |
|
13299 | if (psi.type === 'pat') {
|
13300 | parsePat(payload.subarray(offset), psi);
|
13301 | } else {
|
13302 | parsePmt(payload.subarray(offset), psi);
|
13303 | }
|
13304 | };
|
13305 |
|
13306 | parsePat = function(payload, pat) {
|
13307 | pat.section_number = payload[7];
|
13308 | pat.last_section_number = payload[8];
|
13309 |
|
13310 |
|
13311 | self.pmtPid = (payload[10] & 0x1F) << 8 | payload[11];
|
13312 | pat.pmtPid = self.pmtPid;
|
13313 | };
|
13314 |
|
13315 | |
13316 |
|
13317 |
|
13318 |
|
13319 |
|
13320 |
|
13321 |
|
13322 |
|
13323 | parsePmt = function(payload, pmt) {
|
13324 | var sectionLength, tableEnd, programInfoLength, offset;
|
13325 |
|
13326 |
|
13327 |
|
13328 |
|
13329 |
|
13330 |
|
13331 | if (!(payload[5] & 0x01)) {
|
13332 | return;
|
13333 | }
|
13334 |
|
13335 |
|
13336 | self.programMapTable = {
|
13337 | video: null,
|
13338 | audio: null,
|
13339 | 'timed-metadata': {}
|
13340 | };
|
13341 |
|
13342 |
|
13343 | sectionLength = (payload[1] & 0x0f) << 8 | payload[2];
|
13344 | tableEnd = 3 + sectionLength - 4;
|
13345 |
|
13346 |
|
13347 |
|
13348 | programInfoLength = (payload[10] & 0x0f) << 8 | payload[11];
|
13349 |
|
13350 |
|
13351 | offset = 12 + programInfoLength;
|
13352 | while (offset < tableEnd) {
|
13353 | var streamType = payload[offset];
|
13354 | var pid = (payload[offset + 1] & 0x1F) << 8 | payload[offset + 2];
|
13355 |
|
13356 |
|
13357 |
|
13358 |
|
13359 | if (streamType === StreamTypes.H264_STREAM_TYPE &&
|
13360 | self.programMapTable.video === null) {
|
13361 | self.programMapTable.video = pid;
|
13362 | } else if (streamType === StreamTypes.ADTS_STREAM_TYPE &&
|
13363 | self.programMapTable.audio === null) {
|
13364 | self.programMapTable.audio = pid;
|
13365 | } else if (streamType === StreamTypes.METADATA_STREAM_TYPE) {
|
13366 |
|
13367 | self.programMapTable['timed-metadata'][pid] = streamType;
|
13368 | }
|
13369 |
|
13370 |
|
13371 |
|
13372 | offset += ((payload[offset + 3] & 0x0F) << 8 | payload[offset + 4]) + 5;
|
13373 | }
|
13374 |
|
13375 |
|
13376 | pmt.programMapTable = self.programMapTable;
|
13377 | };
|
13378 |
|
13379 | |
13380 |
|
13381 |
|
13382 | this.push = function(packet) {
|
13383 | var
|
13384 | result = {},
|
13385 | offset = 4;
|
13386 |
|
13387 | result.payloadUnitStartIndicator = !!(packet[1] & 0x40);
|
13388 |
|
13389 |
|
13390 | result.pid = packet[1] & 0x1f;
|
13391 | result.pid <<= 8;
|
13392 | result.pid |= packet[2];
|
13393 |
|
13394 |
|
13395 |
|
13396 |
|
13397 |
|
13398 |
|
13399 | if (((packet[3] & 0x30) >>> 4) > 0x01) {
|
13400 | offset += packet[offset] + 1;
|
13401 | }
|
13402 |
|
13403 |
|
13404 | if (result.pid === 0) {
|
13405 | result.type = 'pat';
|
13406 | parsePsi(packet.subarray(offset), result);
|
13407 | this.trigger('data', result);
|
13408 | } else if (result.pid === this.pmtPid) {
|
13409 | result.type = 'pmt';
|
13410 | parsePsi(packet.subarray(offset), result);
|
13411 | this.trigger('data', result);
|
13412 |
|
13413 |
|
13414 | while (this.packetsWaitingForPmt.length) {
|
13415 | this.processPes_.apply(this, this.packetsWaitingForPmt.shift());
|
13416 | }
|
13417 | } else if (this.programMapTable === undefined) {
|
13418 |
|
13419 |
|
13420 | this.packetsWaitingForPmt.push([packet, offset, result]);
|
13421 | } else {
|
13422 | this.processPes_(packet, offset, result);
|
13423 | }
|
13424 | };
|
13425 |
|
13426 | this.processPes_ = function(packet, offset, result) {
|
13427 |
|
13428 | if (result.pid === this.programMapTable.video) {
|
13429 | result.streamType = StreamTypes.H264_STREAM_TYPE;
|
13430 | } else if (result.pid === this.programMapTable.audio) {
|
13431 | result.streamType = StreamTypes.ADTS_STREAM_TYPE;
|
13432 | } else {
|
13433 |
|
13434 |
|
13435 | result.streamType = this.programMapTable['timed-metadata'][result.pid];
|
13436 | }
|
13437 |
|
13438 | result.type = 'pes';
|
13439 | result.data = packet.subarray(offset);
|
13440 |
|
13441 | this.trigger('data', result);
|
13442 | };
|
13443 |
|
13444 | };
|
13445 | TransportParseStream.prototype = new Stream();
|
13446 | TransportParseStream.STREAM_TYPES = {
|
13447 | h264: 0x1b,
|
13448 | adts: 0x0f
|
13449 | };
|
13450 |
|
13451 |
|
13452 |
|
13453 |
|
13454 |
|
13455 |
|
13456 |
|
13457 |
|
13458 |
|
13459 | ElementaryStream = function() {
|
13460 | var
|
13461 | self = this,
|
13462 |
|
13463 | video = {
|
13464 | data: [],
|
13465 | size: 0
|
13466 | },
|
13467 | audio = {
|
13468 | data: [],
|
13469 | size: 0
|
13470 | },
|
13471 | timedMetadata = {
|
13472 | data: [],
|
13473 | size: 0
|
13474 | },
|
13475 | parsePes = function(payload, pes) {
|
13476 | var ptsDtsFlags;
|
13477 |
|
13478 |
|
13479 | pes.packetLength = 6 + ((payload[4] << 8) | payload[5]);
|
13480 |
|
13481 |
|
13482 | pes.dataAlignmentIndicator = (payload[6] & 0x04) !== 0;
|
13483 |
|
13484 |
|
13485 |
|
13486 | ptsDtsFlags = payload[7];
|
13487 |
|
13488 |
|
13489 |
|
13490 |
|
13491 |
|
13492 |
|
13493 |
|
13494 |
|
13495 |
|
13496 | if (ptsDtsFlags & 0xC0) {
|
13497 |
|
13498 |
|
13499 |
|
13500 | pes.pts = (payload[9] & 0x0E) << 27 |
|
13501 | (payload[10] & 0xFF) << 20 |
|
13502 | (payload[11] & 0xFE) << 12 |
|
13503 | (payload[12] & 0xFF) << 5 |
|
13504 | (payload[13] & 0xFE) >>> 3;
|
13505 | pes.pts *= 4;
|
13506 | pes.pts += (payload[13] & 0x06) >>> 1;
|
13507 | pes.dts = pes.pts;
|
13508 | if (ptsDtsFlags & 0x40) {
|
13509 | pes.dts = (payload[14] & 0x0E) << 27 |
|
13510 | (payload[15] & 0xFF) << 20 |
|
13511 | (payload[16] & 0xFE) << 12 |
|
13512 | (payload[17] & 0xFF) << 5 |
|
13513 | (payload[18] & 0xFE) >>> 3;
|
13514 | pes.dts *= 4;
|
13515 | pes.dts += (payload[18] & 0x06) >>> 1;
|
13516 | }
|
13517 | }
|
13518 |
|
13519 |
|
13520 |
|
13521 | pes.data = payload.subarray(9 + payload[8]);
|
13522 | },
|
13523 | flushStream = function(stream, type, forceFlush) {
|
13524 | var
|
13525 | packetData = new Uint8Array(stream.size),
|
13526 | event = {
|
13527 | type: type
|
13528 | },
|
13529 | i = 0,
|
13530 | offset = 0,
|
13531 | packetFlushable = false,
|
13532 | fragment;
|
13533 |
|
13534 |
|
13535 |
|
13536 | if (!stream.data.length || stream.size < 9) {
|
13537 | return;
|
13538 | }
|
13539 | event.trackId = stream.data[0].pid;
|
13540 |
|
13541 |
|
13542 | for (i = 0; i < stream.data.length; i++) {
|
13543 | fragment = stream.data[i];
|
13544 |
|
13545 | packetData.set(fragment.data, offset);
|
13546 | offset += fragment.data.byteLength;
|
13547 | }
|
13548 |
|
13549 |
|
13550 | parsePes(packetData, event);
|
13551 |
|
13552 |
|
13553 |
|
13554 | packetFlushable = type === 'video' || event.packetLength === stream.size;
|
13555 |
|
13556 |
|
13557 | if (forceFlush || packetFlushable) {
|
13558 | stream.size = 0;
|
13559 | stream.data.length = 0;
|
13560 | }
|
13561 |
|
13562 |
|
13563 |
|
13564 | if (packetFlushable) {
|
13565 | self.trigger('data', event);
|
13566 | }
|
13567 | };
|
13568 |
|
13569 | ElementaryStream.prototype.init.call(this);
|
13570 |
|
13571 | this.push = function(data) {
|
13572 | ({
|
13573 | pat: function() {
|
13574 |
|
13575 |
|
13576 | },
|
13577 | pes: function() {
|
13578 | var stream, streamType;
|
13579 |
|
13580 | switch (data.streamType) {
|
13581 | case StreamTypes.H264_STREAM_TYPE:
|
13582 | case m2tsStreamTypes.H264_STREAM_TYPE:
|
13583 | stream = video;
|
13584 | streamType = 'video';
|
13585 | break;
|
13586 | case StreamTypes.ADTS_STREAM_TYPE:
|
13587 | stream = audio;
|
13588 | streamType = 'audio';
|
13589 | break;
|
13590 | case StreamTypes.METADATA_STREAM_TYPE:
|
13591 | stream = timedMetadata;
|
13592 | streamType = 'timed-metadata';
|
13593 | break;
|
13594 | default:
|
13595 |
|
13596 | return;
|
13597 | }
|
13598 |
|
13599 |
|
13600 |
|
13601 | if (data.payloadUnitStartIndicator) {
|
13602 | flushStream(stream, streamType, true);
|
13603 | }
|
13604 |
|
13605 |
|
13606 |
|
13607 | stream.data.push(data);
|
13608 | stream.size += data.data.byteLength;
|
13609 | },
|
13610 | pmt: function() {
|
13611 | var
|
13612 | event = {
|
13613 | type: 'metadata',
|
13614 | tracks: []
|
13615 | },
|
13616 | programMapTable = data.programMapTable;
|
13617 |
|
13618 |
|
13619 | if (programMapTable.video !== null) {
|
13620 | event.tracks.push({
|
13621 | timelineStartInfo: {
|
13622 | baseMediaDecodeTime: 0
|
13623 | },
|
13624 | id: +programMapTable.video,
|
13625 | codec: 'avc',
|
13626 | type: 'video'
|
13627 | });
|
13628 | }
|
13629 | if (programMapTable.audio !== null) {
|
13630 | event.tracks.push({
|
13631 | timelineStartInfo: {
|
13632 | baseMediaDecodeTime: 0
|
13633 | },
|
13634 | id: +programMapTable.audio,
|
13635 | codec: 'adts',
|
13636 | type: 'audio'
|
13637 | });
|
13638 | }
|
13639 |
|
13640 | self.trigger('data', event);
|
13641 | }
|
13642 | })[data.type]();
|
13643 | };
|
13644 |
|
13645 | |
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 |
|
13651 |
|
13652 |
|
13653 |
|
13654 | this.flush = function() {
|
13655 |
|
13656 |
|
13657 | flushStream(video, 'video');
|
13658 | flushStream(audio, 'audio');
|
13659 | flushStream(timedMetadata, 'timed-metadata');
|
13660 | this.trigger('done');
|
13661 | };
|
13662 | };
|
13663 | ElementaryStream.prototype = new Stream();
|
13664 |
|
13665 | var m2ts = {
|
13666 | PAT_PID: 0x0000,
|
13667 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH,
|
13668 | TransportPacketStream: TransportPacketStream,
|
13669 | TransportParseStream: TransportParseStream,
|
13670 | ElementaryStream: ElementaryStream,
|
13671 | TimestampRolloverStream: TimestampRolloverStream,
|
13672 | CaptionStream: CaptionStream.CaptionStream,
|
13673 | Cea608Stream: CaptionStream.Cea608Stream,
|
13674 | MetadataStream: require('./metadata-stream')
|
13675 | };
|
13676 |
|
13677 | for (var type in StreamTypes) {
|
13678 | if (StreamTypes.hasOwnProperty(type)) {
|
13679 | m2ts[type] = StreamTypes[type];
|
13680 | }
|
13681 | }
|
13682 |
|
13683 | module.exports = m2ts;
|
13684 |
|
13685 | },{"../utils/stream.js":62,"./caption-stream":49,"./metadata-stream":51,"./stream-types":53,"./stream-types.js":53,"./timestamp-rollover-stream":54}],51:[function(require,module,exports){
|
13686 |
|
13687 |
|
13688 |
|
13689 |
|
13690 |
|
13691 | 'use strict';
|
13692 | var
|
13693 | Stream = require('../utils/stream'),
|
13694 | StreamTypes = require('./stream-types'),
|
13695 |
|
13696 |
|
13697 | percentEncode = function(bytes, start, end) {
|
13698 | var i, result = '';
|
13699 | for (i = start; i < end; i++) {
|
13700 | result += '%' + ('00' + bytes[i].toString(16)).slice(-2);
|
13701 | }
|
13702 | return result;
|
13703 | },
|
13704 |
|
13705 |
|
13706 | parseUtf8 = function(bytes, start, end) {
|
13707 | return decodeURIComponent(percentEncode(bytes, start, end));
|
13708 | },
|
13709 |
|
13710 |
|
13711 | parseIso88591 = function(bytes, start, end) {
|
13712 | return unescape(percentEncode(bytes, start, end));
|
13713 | },
|
13714 | parseSyncSafeInteger = function(data) {
|
13715 | return (data[0] << 21) |
|
13716 | (data[1] << 14) |
|
13717 | (data[2] << 7) |
|
13718 | (data[3]);
|
13719 | },
|
13720 | tagParsers = {
|
13721 | TXXX: function(tag) {
|
13722 | var i;
|
13723 | if (tag.data[0] !== 3) {
|
13724 |
|
13725 | return;
|
13726 | }
|
13727 |
|
13728 | for (i = 1; i < tag.data.length; i++) {
|
13729 | if (tag.data[i] === 0) {
|
13730 |
|
13731 | tag.description = parseUtf8(tag.data, 1, i);
|
13732 |
|
13733 | tag.value = parseUtf8(tag.data, i + 1, tag.data.length).replace(/\0*$/, '');
|
13734 | break;
|
13735 | }
|
13736 | }
|
13737 | tag.data = tag.value;
|
13738 | },
|
13739 | WXXX: function(tag) {
|
13740 | var i;
|
13741 | if (tag.data[0] !== 3) {
|
13742 |
|
13743 | return;
|
13744 | }
|
13745 |
|
13746 | for (i = 1; i < tag.data.length; i++) {
|
13747 | if (tag.data[i] === 0) {
|
13748 |
|
13749 | tag.description = parseUtf8(tag.data, 1, i);
|
13750 | tag.url = parseUtf8(tag.data, i + 1, tag.data.length);
|
13751 | break;
|
13752 | }
|
13753 | }
|
13754 | },
|
13755 | PRIV: function(tag) {
|
13756 | var i;
|
13757 |
|
13758 | for (i = 0; i < tag.data.length; i++) {
|
13759 | if (tag.data[i] === 0) {
|
13760 |
|
13761 | tag.owner = parseIso88591(tag.data, 0, i);
|
13762 | break;
|
13763 | }
|
13764 | }
|
13765 | tag.privateData = tag.data.subarray(i + 1);
|
13766 | tag.data = tag.privateData;
|
13767 | }
|
13768 | },
|
13769 | MetadataStream;
|
13770 |
|
13771 | MetadataStream = function(options) {
|
13772 | var
|
13773 | settings = {
|
13774 | debug: !!(options && options.debug),
|
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 | descriptor: options && options.descriptor
|
13780 | },
|
13781 |
|
13782 | tagSize = 0,
|
13783 |
|
13784 | buffer = [],
|
13785 |
|
13786 | bufferSize = 0,
|
13787 | i;
|
13788 |
|
13789 | MetadataStream.prototype.init.call(this);
|
13790 |
|
13791 |
|
13792 |
|
13793 | this.dispatchType = StreamTypes.METADATA_STREAM_TYPE.toString(16);
|
13794 | if (settings.descriptor) {
|
13795 | for (i = 0; i < settings.descriptor.length; i++) {
|
13796 | this.dispatchType += ('00' + settings.descriptor[i].toString(16)).slice(-2);
|
13797 | }
|
13798 | }
|
13799 |
|
13800 | this.push = function(chunk) {
|
13801 | var tag, frameStart, frameSize, frame, i, frameHeader;
|
13802 | if (chunk.type !== 'timed-metadata') {
|
13803 | return;
|
13804 | }
|
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 | if (chunk.dataAlignmentIndicator) {
|
13810 | bufferSize = 0;
|
13811 | buffer.length = 0;
|
13812 | }
|
13813 |
|
13814 |
|
13815 | if (buffer.length === 0 &&
|
13816 | (chunk.data.length < 10 ||
|
13817 | chunk.data[0] !== 'I'.charCodeAt(0) ||
|
13818 | chunk.data[1] !== 'D'.charCodeAt(0) ||
|
13819 | chunk.data[2] !== '3'.charCodeAt(0))) {
|
13820 | if (settings.debug) {
|
13821 |
|
13822 | console.log('Skipping unrecognized metadata packet');
|
13823 | }
|
13824 | return;
|
13825 | }
|
13826 |
|
13827 |
|
13828 |
|
13829 | buffer.push(chunk);
|
13830 | bufferSize += chunk.data.byteLength;
|
13831 |
|
13832 |
|
13833 | if (buffer.length === 1) {
|
13834 |
|
13835 |
|
13836 |
|
13837 |
|
13838 | tagSize = parseSyncSafeInteger(chunk.data.subarray(6, 10));
|
13839 |
|
13840 |
|
13841 |
|
13842 | tagSize += 10;
|
13843 | }
|
13844 |
|
13845 |
|
13846 | if (bufferSize < tagSize) {
|
13847 | return;
|
13848 | }
|
13849 |
|
13850 |
|
13851 | tag = {
|
13852 | data: new Uint8Array(tagSize),
|
13853 | frames: [],
|
13854 | pts: buffer[0].pts,
|
13855 | dts: buffer[0].dts
|
13856 | };
|
13857 | for (i = 0; i < tagSize;) {
|
13858 | tag.data.set(buffer[0].data.subarray(0, tagSize - i), i);
|
13859 | i += buffer[0].data.byteLength;
|
13860 | bufferSize -= buffer[0].data.byteLength;
|
13861 | buffer.shift();
|
13862 | }
|
13863 |
|
13864 |
|
13865 | frameStart = 10;
|
13866 | if (tag.data[5] & 0x40) {
|
13867 |
|
13868 | frameStart += 4;
|
13869 | frameStart += parseSyncSafeInteger(tag.data.subarray(10, 14));
|
13870 |
|
13871 |
|
13872 | tagSize -= parseSyncSafeInteger(tag.data.subarray(16, 20));
|
13873 | }
|
13874 |
|
13875 |
|
13876 |
|
13877 | do {
|
13878 |
|
13879 | frameSize = parseSyncSafeInteger(tag.data.subarray(frameStart + 4, frameStart + 8));
|
13880 | if (frameSize < 1) {
|
13881 |
|
13882 | return console.log('Malformed ID3 frame encountered. Skipping metadata parsing.');
|
13883 | }
|
13884 | frameHeader = String.fromCharCode(tag.data[frameStart],
|
13885 | tag.data[frameStart + 1],
|
13886 | tag.data[frameStart + 2],
|
13887 | tag.data[frameStart + 3]);
|
13888 |
|
13889 |
|
13890 | frame = {
|
13891 | id: frameHeader,
|
13892 | data: tag.data.subarray(frameStart + 10, frameStart + frameSize + 10)
|
13893 | };
|
13894 | frame.key = frame.id;
|
13895 | if (tagParsers[frame.id]) {
|
13896 | tagParsers[frame.id](frame);
|
13897 |
|
13898 |
|
13899 |
|
13900 | if (frame.owner === 'com.apple.streaming.transportStreamTimestamp') {
|
13901 | var
|
13902 | d = frame.data,
|
13903 | size = ((d[3] & 0x01) << 30) |
|
13904 | (d[4] << 22) |
|
13905 | (d[5] << 14) |
|
13906 | (d[6] << 6) |
|
13907 | (d[7] >>> 2);
|
13908 |
|
13909 | size *= 4;
|
13910 | size += d[7] & 0x03;
|
13911 | frame.timeStamp = size;
|
13912 |
|
13913 |
|
13914 |
|
13915 |
|
13916 | if (tag.pts === undefined && tag.dts === undefined) {
|
13917 | tag.pts = frame.timeStamp;
|
13918 | tag.dts = frame.timeStamp;
|
13919 | }
|
13920 | this.trigger('timestamp', frame);
|
13921 | }
|
13922 | }
|
13923 | tag.frames.push(frame);
|
13924 |
|
13925 | frameStart += 10;
|
13926 | frameStart += frameSize;
|
13927 | } while (frameStart < tagSize);
|
13928 | this.trigger('data', tag);
|
13929 | };
|
13930 | };
|
13931 | MetadataStream.prototype = new Stream();
|
13932 |
|
13933 | module.exports = MetadataStream;
|
13934 |
|
13935 | },{"../utils/stream":62,"./stream-types":53}],52:[function(require,module,exports){
|
13936 |
|
13937 |
|
13938 |
|
13939 |
|
13940 |
|
13941 |
|
13942 |
|
13943 |
|
13944 | 'use strict';
|
13945 |
|
13946 | var StreamTypes = require('./stream-types.js');
|
13947 |
|
13948 | var parsePid = function(packet) {
|
13949 | var pid = packet[1] & 0x1f;
|
13950 | pid <<= 8;
|
13951 | pid |= packet[2];
|
13952 | return pid;
|
13953 | };
|
13954 |
|
13955 | var parsePayloadUnitStartIndicator = function(packet) {
|
13956 | return !!(packet[1] & 0x40);
|
13957 | };
|
13958 |
|
13959 | var parseAdaptionField = function(packet) {
|
13960 | var offset = 0;
|
13961 |
|
13962 |
|
13963 |
|
13964 |
|
13965 |
|
13966 | if (((packet[3] & 0x30) >>> 4) > 0x01) {
|
13967 | offset += packet[4] + 1;
|
13968 | }
|
13969 | return offset;
|
13970 | };
|
13971 |
|
13972 | var parseType = function(packet, pmtPid) {
|
13973 | var pid = parsePid(packet);
|
13974 | if (pid === 0) {
|
13975 | return 'pat';
|
13976 | } else if (pid === pmtPid) {
|
13977 | return 'pmt';
|
13978 | } else if (pmtPid) {
|
13979 | return 'pes';
|
13980 | }
|
13981 | return null;
|
13982 | };
|
13983 |
|
13984 | var parsePat = function(packet) {
|
13985 | var pusi = parsePayloadUnitStartIndicator(packet);
|
13986 | var offset = 4 + parseAdaptionField(packet);
|
13987 |
|
13988 | if (pusi) {
|
13989 | offset += packet[offset] + 1;
|
13990 | }
|
13991 |
|
13992 | return (packet[offset + 10] & 0x1f) << 8 | packet[offset + 11];
|
13993 | };
|
13994 |
|
13995 | var parsePmt = function(packet) {
|
13996 | var programMapTable = {};
|
13997 | var pusi = parsePayloadUnitStartIndicator(packet);
|
13998 | var payloadOffset = 4 + parseAdaptionField(packet);
|
13999 |
|
14000 | if (pusi) {
|
14001 | payloadOffset += packet[payloadOffset] + 1;
|
14002 | }
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 | if (!(packet[payloadOffset + 5] & 0x01)) {
|
14010 | return;
|
14011 | }
|
14012 |
|
14013 | var sectionLength, tableEnd, programInfoLength;
|
14014 |
|
14015 | sectionLength = (packet[payloadOffset + 1] & 0x0f) << 8 | packet[payloadOffset + 2];
|
14016 | tableEnd = 3 + sectionLength - 4;
|
14017 |
|
14018 |
|
14019 |
|
14020 | programInfoLength = (packet[payloadOffset + 10] & 0x0f) << 8 | packet[payloadOffset + 11];
|
14021 |
|
14022 |
|
14023 | var offset = 12 + programInfoLength;
|
14024 | while (offset < tableEnd) {
|
14025 | var i = payloadOffset + offset;
|
14026 |
|
14027 | programMapTable[(packet[i + 1] & 0x1F) << 8 | packet[i + 2]] = packet[i];
|
14028 |
|
14029 |
|
14030 |
|
14031 | offset += ((packet[i + 3] & 0x0F) << 8 | packet[i + 4]) + 5;
|
14032 | }
|
14033 | return programMapTable;
|
14034 | };
|
14035 |
|
14036 | var parsePesType = function(packet, programMapTable) {
|
14037 | var pid = parsePid(packet);
|
14038 | var type = programMapTable[pid];
|
14039 | switch (type) {
|
14040 | case StreamTypes.H264_STREAM_TYPE:
|
14041 | return 'video';
|
14042 | case StreamTypes.ADTS_STREAM_TYPE:
|
14043 | return 'audio';
|
14044 | case StreamTypes.METADATA_STREAM_TYPE:
|
14045 | return 'timed-metadata';
|
14046 | default:
|
14047 | return null;
|
14048 | }
|
14049 | };
|
14050 |
|
14051 | var parsePesTime = function(packet) {
|
14052 | var pusi = parsePayloadUnitStartIndicator(packet);
|
14053 | if (!pusi) {
|
14054 | return null;
|
14055 | }
|
14056 |
|
14057 | var offset = 4 + parseAdaptionField(packet);
|
14058 |
|
14059 | if (offset >= packet.byteLength) {
|
14060 |
|
14061 |
|
14062 |
|
14063 |
|
14064 |
|
14065 |
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 | return null;
|
14071 | }
|
14072 |
|
14073 | var pes = null;
|
14074 | var ptsDtsFlags;
|
14075 |
|
14076 |
|
14077 |
|
14078 |
|
14079 | ptsDtsFlags = packet[offset + 7];
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 |
|
14086 |
|
14087 |
|
14088 |
|
14089 | if (ptsDtsFlags & 0xC0) {
|
14090 | pes = {};
|
14091 |
|
14092 |
|
14093 |
|
14094 | pes.pts = (packet[offset + 9] & 0x0E) << 27 |
|
14095 | (packet[offset + 10] & 0xFF) << 20 |
|
14096 | (packet[offset + 11] & 0xFE) << 12 |
|
14097 | (packet[offset + 12] & 0xFF) << 5 |
|
14098 | (packet[offset + 13] & 0xFE) >>> 3;
|
14099 | pes.pts *= 4;
|
14100 | pes.pts += (packet[offset + 13] & 0x06) >>> 1;
|
14101 | pes.dts = pes.pts;
|
14102 | if (ptsDtsFlags & 0x40) {
|
14103 | pes.dts = (packet[offset + 14] & 0x0E) << 27 |
|
14104 | (packet[offset + 15] & 0xFF) << 20 |
|
14105 | (packet[offset + 16] & 0xFE) << 12 |
|
14106 | (packet[offset + 17] & 0xFF) << 5 |
|
14107 | (packet[offset + 18] & 0xFE) >>> 3;
|
14108 | pes.dts *= 4;
|
14109 | pes.dts += (packet[offset + 18] & 0x06) >>> 1;
|
14110 | }
|
14111 | }
|
14112 | return pes;
|
14113 | };
|
14114 |
|
14115 | var parseNalUnitType = function(type) {
|
14116 | switch (type) {
|
14117 | case 0x05:
|
14118 | return 'slice_layer_without_partitioning_rbsp_idr';
|
14119 | case 0x06:
|
14120 | return 'sei_rbsp';
|
14121 | case 0x07:
|
14122 | return 'seq_parameter_set_rbsp';
|
14123 | case 0x08:
|
14124 | return 'pic_parameter_set_rbsp';
|
14125 | case 0x09:
|
14126 | return 'access_unit_delimiter_rbsp';
|
14127 | default:
|
14128 | return null;
|
14129 | }
|
14130 | };
|
14131 |
|
14132 | var videoPacketContainsKeyFrame = function(packet) {
|
14133 | var offset = 4 + parseAdaptionField(packet);
|
14134 | var frameBuffer = packet.subarray(offset);
|
14135 | var frameI = 0;
|
14136 | var frameSyncPoint = 0;
|
14137 | var foundKeyFrame = false;
|
14138 | var nalType;
|
14139 |
|
14140 |
|
14141 | for (; frameSyncPoint < frameBuffer.byteLength - 3; frameSyncPoint++) {
|
14142 | if (frameBuffer[frameSyncPoint + 2] === 1) {
|
14143 |
|
14144 | frameI = frameSyncPoint + 5;
|
14145 | break;
|
14146 | }
|
14147 | }
|
14148 |
|
14149 | while (frameI < frameBuffer.byteLength) {
|
14150 |
|
14151 |
|
14152 | switch (frameBuffer[frameI]) {
|
14153 | case 0:
|
14154 |
|
14155 | if (frameBuffer[frameI - 1] !== 0) {
|
14156 | frameI += 2;
|
14157 | break;
|
14158 | } else if (frameBuffer[frameI - 2] !== 0) {
|
14159 | frameI++;
|
14160 | break;
|
14161 | }
|
14162 |
|
14163 | if (frameSyncPoint + 3 !== frameI - 2) {
|
14164 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
14165 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
14166 | foundKeyFrame = true;
|
14167 | }
|
14168 | }
|
14169 |
|
14170 |
|
14171 | do {
|
14172 | frameI++;
|
14173 | } while (frameBuffer[frameI] !== 1 && frameI < frameBuffer.length);
|
14174 | frameSyncPoint = frameI - 2;
|
14175 | frameI += 3;
|
14176 | break;
|
14177 | case 1:
|
14178 |
|
14179 | if (frameBuffer[frameI - 1] !== 0 ||
|
14180 | frameBuffer[frameI - 2] !== 0) {
|
14181 | frameI += 3;
|
14182 | break;
|
14183 | }
|
14184 |
|
14185 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
14186 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
14187 | foundKeyFrame = true;
|
14188 | }
|
14189 | frameSyncPoint = frameI - 2;
|
14190 | frameI += 3;
|
14191 | break;
|
14192 | default:
|
14193 |
|
14194 |
|
14195 | frameI += 3;
|
14196 | break;
|
14197 | }
|
14198 | }
|
14199 | frameBuffer = frameBuffer.subarray(frameSyncPoint);
|
14200 | frameI -= frameSyncPoint;
|
14201 | frameSyncPoint = 0;
|
14202 |
|
14203 | if (frameBuffer && frameBuffer.byteLength > 3) {
|
14204 | nalType = parseNalUnitType(frameBuffer[frameSyncPoint + 3] & 0x1f);
|
14205 | if (nalType === 'slice_layer_without_partitioning_rbsp_idr') {
|
14206 | foundKeyFrame = true;
|
14207 | }
|
14208 | }
|
14209 |
|
14210 | return foundKeyFrame;
|
14211 | };
|
14212 |
|
14213 |
|
14214 | module.exports = {
|
14215 | parseType: parseType,
|
14216 | parsePat: parsePat,
|
14217 | parsePmt: parsePmt,
|
14218 | parsePayloadUnitStartIndicator: parsePayloadUnitStartIndicator,
|
14219 | parsePesType: parsePesType,
|
14220 | parsePesTime: parsePesTime,
|
14221 | videoPacketContainsKeyFrame: videoPacketContainsKeyFrame
|
14222 | };
|
14223 |
|
14224 | },{"./stream-types.js":53}],53:[function(require,module,exports){
|
14225 | 'use strict';
|
14226 |
|
14227 | module.exports = {
|
14228 | H264_STREAM_TYPE: 0x1B,
|
14229 | ADTS_STREAM_TYPE: 0x0F,
|
14230 | METADATA_STREAM_TYPE: 0x15
|
14231 | };
|
14232 |
|
14233 | },{}],54:[function(require,module,exports){
|
14234 |
|
14235 |
|
14236 |
|
14237 |
|
14238 |
|
14239 |
|
14240 |
|
14241 |
|
14242 |
|
14243 |
|
14244 |
|
14245 | 'use strict';
|
14246 |
|
14247 | var Stream = require('../utils/stream');
|
14248 |
|
14249 | var MAX_TS = 8589934592;
|
14250 |
|
14251 | var RO_THRESH = 4294967296;
|
14252 |
|
14253 | var handleRollover = function(value, reference) {
|
14254 | var direction = 1;
|
14255 |
|
14256 | if (value > reference) {
|
14257 |
|
14258 |
|
14259 |
|
14260 |
|
14261 |
|
14262 |
|
14263 |
|
14264 | direction = -1;
|
14265 | }
|
14266 |
|
14267 |
|
14268 |
|
14269 | while (Math.abs(reference - value) > RO_THRESH) {
|
14270 | value += (direction * MAX_TS);
|
14271 | }
|
14272 |
|
14273 | return value;
|
14274 | };
|
14275 |
|
14276 | var TimestampRolloverStream = function(type) {
|
14277 | var lastDTS, referenceDTS;
|
14278 |
|
14279 | TimestampRolloverStream.prototype.init.call(this);
|
14280 |
|
14281 | this.type_ = type;
|
14282 |
|
14283 | this.push = function(data) {
|
14284 | if (data.type !== this.type_) {
|
14285 | return;
|
14286 | }
|
14287 |
|
14288 | if (referenceDTS === undefined) {
|
14289 | referenceDTS = data.dts;
|
14290 | }
|
14291 |
|
14292 | data.dts = handleRollover(data.dts, referenceDTS);
|
14293 | data.pts = handleRollover(data.pts, referenceDTS);
|
14294 |
|
14295 | lastDTS = data.dts;
|
14296 |
|
14297 | this.trigger('data', data);
|
14298 | };
|
14299 |
|
14300 | this.flush = function() {
|
14301 | referenceDTS = lastDTS;
|
14302 | this.trigger('done');
|
14303 | };
|
14304 |
|
14305 | this.discontinuity = function() {
|
14306 | referenceDTS = void 0;
|
14307 | lastDTS = void 0;
|
14308 | };
|
14309 |
|
14310 | };
|
14311 |
|
14312 | TimestampRolloverStream.prototype = new Stream();
|
14313 |
|
14314 | module.exports = {
|
14315 | TimestampRolloverStream: TimestampRolloverStream,
|
14316 | handleRollover: handleRollover
|
14317 | };
|
14318 |
|
14319 | },{"../utils/stream":62}],55:[function(require,module,exports){
|
14320 | module.exports = {
|
14321 | generator: require('./mp4-generator'),
|
14322 | Transmuxer: require('./transmuxer').Transmuxer,
|
14323 | AudioSegmentStream: require('./transmuxer').AudioSegmentStream,
|
14324 | VideoSegmentStream: require('./transmuxer').VideoSegmentStream
|
14325 | };
|
14326 |
|
14327 | },{"./mp4-generator":56,"./transmuxer":58}],56:[function(require,module,exports){
|
14328 |
|
14329 |
|
14330 |
|
14331 |
|
14332 |
|
14333 |
|
14334 |
|
14335 |
|
14336 |
|
14337 | 'use strict';
|
14338 |
|
14339 | var UINT32_MAX = Math.pow(2, 32) - 1;
|
14340 |
|
14341 | var box, dinf, esds, ftyp, mdat, mfhd, minf, moof, moov, mvex, mvhd,
|
14342 | trak, tkhd, mdia, mdhd, hdlr, sdtp, stbl, stsd, traf, trex,
|
14343 | trun, types, MAJOR_BRAND, MINOR_VERSION, AVC1_BRAND, VIDEO_HDLR,
|
14344 | AUDIO_HDLR, HDLR_TYPES, VMHD, SMHD, DREF, STCO, STSC, STSZ, STTS;
|
14345 |
|
14346 |
|
14347 | (function() {
|
14348 | var i;
|
14349 | types = {
|
14350 | avc1: [],
|
14351 | avcC: [],
|
14352 | btrt: [],
|
14353 | dinf: [],
|
14354 | dref: [],
|
14355 | esds: [],
|
14356 | ftyp: [],
|
14357 | hdlr: [],
|
14358 | mdat: [],
|
14359 | mdhd: [],
|
14360 | mdia: [],
|
14361 | mfhd: [],
|
14362 | minf: [],
|
14363 | moof: [],
|
14364 | moov: [],
|
14365 | mp4a: [],
|
14366 | mvex: [],
|
14367 | mvhd: [],
|
14368 | sdtp: [],
|
14369 | smhd: [],
|
14370 | stbl: [],
|
14371 | stco: [],
|
14372 | stsc: [],
|
14373 | stsd: [],
|
14374 | stsz: [],
|
14375 | stts: [],
|
14376 | styp: [],
|
14377 | tfdt: [],
|
14378 | tfhd: [],
|
14379 | traf: [],
|
14380 | trak: [],
|
14381 | trun: [],
|
14382 | trex: [],
|
14383 | tkhd: [],
|
14384 | vmhd: []
|
14385 | };
|
14386 |
|
14387 |
|
14388 |
|
14389 | if (typeof Uint8Array === 'undefined') {
|
14390 | return;
|
14391 | }
|
14392 |
|
14393 | for (i in types) {
|
14394 | if (types.hasOwnProperty(i)) {
|
14395 | types[i] = [
|
14396 | i.charCodeAt(0),
|
14397 | i.charCodeAt(1),
|
14398 | i.charCodeAt(2),
|
14399 | i.charCodeAt(3)
|
14400 | ];
|
14401 | }
|
14402 | }
|
14403 |
|
14404 | MAJOR_BRAND = new Uint8Array([
|
14405 | 'i'.charCodeAt(0),
|
14406 | 's'.charCodeAt(0),
|
14407 | 'o'.charCodeAt(0),
|
14408 | 'm'.charCodeAt(0)
|
14409 | ]);
|
14410 | AVC1_BRAND = new Uint8Array([
|
14411 | 'a'.charCodeAt(0),
|
14412 | 'v'.charCodeAt(0),
|
14413 | 'c'.charCodeAt(0),
|
14414 | '1'.charCodeAt(0)
|
14415 | ]);
|
14416 | MINOR_VERSION = new Uint8Array([0, 0, 0, 1]);
|
14417 | VIDEO_HDLR = new Uint8Array([
|
14418 | 0x00,
|
14419 | 0x00, 0x00, 0x00,
|
14420 | 0x00, 0x00, 0x00, 0x00,
|
14421 | 0x76, 0x69, 0x64, 0x65,
|
14422 | 0x00, 0x00, 0x00, 0x00,
|
14423 | 0x00, 0x00, 0x00, 0x00,
|
14424 | 0x00, 0x00, 0x00, 0x00,
|
14425 | 0x56, 0x69, 0x64, 0x65,
|
14426 | 0x6f, 0x48, 0x61, 0x6e,
|
14427 | 0x64, 0x6c, 0x65, 0x72, 0x00
|
14428 | ]);
|
14429 | AUDIO_HDLR = new Uint8Array([
|
14430 | 0x00,
|
14431 | 0x00, 0x00, 0x00,
|
14432 | 0x00, 0x00, 0x00, 0x00,
|
14433 | 0x73, 0x6f, 0x75, 0x6e,
|
14434 | 0x00, 0x00, 0x00, 0x00,
|
14435 | 0x00, 0x00, 0x00, 0x00,
|
14436 | 0x00, 0x00, 0x00, 0x00,
|
14437 | 0x53, 0x6f, 0x75, 0x6e,
|
14438 | 0x64, 0x48, 0x61, 0x6e,
|
14439 | 0x64, 0x6c, 0x65, 0x72, 0x00
|
14440 | ]);
|
14441 | HDLR_TYPES = {
|
14442 | video: VIDEO_HDLR,
|
14443 | audio: AUDIO_HDLR
|
14444 | };
|
14445 | DREF = new Uint8Array([
|
14446 | 0x00,
|
14447 | 0x00, 0x00, 0x00,
|
14448 | 0x00, 0x00, 0x00, 0x01,
|
14449 | 0x00, 0x00, 0x00, 0x0c,
|
14450 | 0x75, 0x72, 0x6c, 0x20,
|
14451 | 0x00,
|
14452 | 0x00, 0x00, 0x01
|
14453 | ]);
|
14454 | SMHD = new Uint8Array([
|
14455 | 0x00,
|
14456 | 0x00, 0x00, 0x00,
|
14457 | 0x00, 0x00,
|
14458 | 0x00, 0x00
|
14459 | ]);
|
14460 | STCO = new Uint8Array([
|
14461 | 0x00,
|
14462 | 0x00, 0x00, 0x00,
|
14463 | 0x00, 0x00, 0x00, 0x00
|
14464 | ]);
|
14465 | STSC = STCO;
|
14466 | STSZ = new Uint8Array([
|
14467 | 0x00,
|
14468 | 0x00, 0x00, 0x00,
|
14469 | 0x00, 0x00, 0x00, 0x00,
|
14470 | 0x00, 0x00, 0x00, 0x00
|
14471 | ]);
|
14472 | STTS = STCO;
|
14473 | VMHD = new Uint8Array([
|
14474 | 0x00,
|
14475 | 0x00, 0x00, 0x01,
|
14476 | 0x00, 0x00,
|
14477 | 0x00, 0x00,
|
14478 | 0x00, 0x00,
|
14479 | 0x00, 0x00
|
14480 | ]);
|
14481 | }());
|
14482 |
|
14483 | box = function(type) {
|
14484 | var
|
14485 | payload = [],
|
14486 | size = 0,
|
14487 | i,
|
14488 | result,
|
14489 | view;
|
14490 |
|
14491 | for (i = 1; i < arguments.length; i++) {
|
14492 | payload.push(arguments[i]);
|
14493 | }
|
14494 |
|
14495 | i = payload.length;
|
14496 |
|
14497 |
|
14498 | while (i--) {
|
14499 | size += payload[i].byteLength;
|
14500 | }
|
14501 | result = new Uint8Array(size + 8);
|
14502 | view = new DataView(result.buffer, result.byteOffset, result.byteLength);
|
14503 | view.setUint32(0, result.byteLength);
|
14504 | result.set(type, 4);
|
14505 |
|
14506 |
|
14507 | for (i = 0, size = 8; i < payload.length; i++) {
|
14508 | result.set(payload[i], size);
|
14509 | size += payload[i].byteLength;
|
14510 | }
|
14511 | return result;
|
14512 | };
|
14513 |
|
14514 | dinf = function() {
|
14515 | return box(types.dinf, box(types.dref, DREF));
|
14516 | };
|
14517 |
|
14518 | esds = function(track) {
|
14519 | return box(types.esds, new Uint8Array([
|
14520 | 0x00,
|
14521 | 0x00, 0x00, 0x00,
|
14522 |
|
14523 |
|
14524 | 0x03,
|
14525 | 0x19,
|
14526 | 0x00, 0x00,
|
14527 | 0x00,
|
14528 |
|
14529 |
|
14530 | 0x04,
|
14531 | 0x11,
|
14532 | 0x40,
|
14533 | 0x15,
|
14534 | 0x00, 0x06, 0x00,
|
14535 | 0x00, 0x00, 0xda, 0xc0,
|
14536 | 0x00, 0x00, 0xda, 0xc0,
|
14537 |
|
14538 |
|
14539 | 0x05,
|
14540 | 0x02,
|
14541 |
|
14542 |
|
14543 | (track.audioobjecttype << 3) | (track.samplingfrequencyindex >>> 1),
|
14544 | (track.samplingfrequencyindex << 7) | (track.channelcount << 3),
|
14545 | 0x06, 0x01, 0x02
|
14546 | ]));
|
14547 | };
|
14548 |
|
14549 | ftyp = function() {
|
14550 | return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND, AVC1_BRAND);
|
14551 | };
|
14552 |
|
14553 | hdlr = function(type) {
|
14554 | return box(types.hdlr, HDLR_TYPES[type]);
|
14555 | };
|
14556 | mdat = function(data) {
|
14557 | return box(types.mdat, data);
|
14558 | };
|
14559 | mdhd = function(track) {
|
14560 | var result = new Uint8Array([
|
14561 | 0x00,
|
14562 | 0x00, 0x00, 0x00,
|
14563 | 0x00, 0x00, 0x00, 0x02,
|
14564 | 0x00, 0x00, 0x00, 0x03,
|
14565 | 0x00, 0x01, 0x5f, 0x90,
|
14566 |
|
14567 | (track.duration >>> 24) & 0xFF,
|
14568 | (track.duration >>> 16) & 0xFF,
|
14569 | (track.duration >>> 8) & 0xFF,
|
14570 | track.duration & 0xFF,
|
14571 | 0x55, 0xc4,
|
14572 | 0x00, 0x00
|
14573 | ]);
|
14574 |
|
14575 |
|
14576 |
|
14577 |
|
14578 | if (track.samplerate) {
|
14579 | result[12] = (track.samplerate >>> 24) & 0xFF;
|
14580 | result[13] = (track.samplerate >>> 16) & 0xFF;
|
14581 | result[14] = (track.samplerate >>> 8) & 0xFF;
|
14582 | result[15] = (track.samplerate) & 0xFF;
|
14583 | }
|
14584 |
|
14585 | return box(types.mdhd, result);
|
14586 | };
|
14587 | mdia = function(track) {
|
14588 | return box(types.mdia, mdhd(track), hdlr(track.type), minf(track));
|
14589 | };
|
14590 | mfhd = function(sequenceNumber) {
|
14591 | return box(types.mfhd, new Uint8Array([
|
14592 | 0x00,
|
14593 | 0x00, 0x00, 0x00,
|
14594 | (sequenceNumber & 0xFF000000) >> 24,
|
14595 | (sequenceNumber & 0xFF0000) >> 16,
|
14596 | (sequenceNumber & 0xFF00) >> 8,
|
14597 | sequenceNumber & 0xFF
|
14598 | ]));
|
14599 | };
|
14600 | minf = function(track) {
|
14601 | return box(types.minf,
|
14602 | track.type === 'video' ? box(types.vmhd, VMHD) : box(types.smhd, SMHD),
|
14603 | dinf(),
|
14604 | stbl(track));
|
14605 | };
|
14606 | moof = function(sequenceNumber, tracks) {
|
14607 | var
|
14608 | trackFragments = [],
|
14609 | i = tracks.length;
|
14610 |
|
14611 | while (i--) {
|
14612 | trackFragments[i] = traf(tracks[i]);
|
14613 | }
|
14614 | return box.apply(null, [
|
14615 | types.moof,
|
14616 | mfhd(sequenceNumber)
|
14617 | ].concat(trackFragments));
|
14618 | };
|
14619 |
|
14620 |
|
14621 |
|
14622 |
|
14623 |
|
14624 | moov = function(tracks) {
|
14625 | var
|
14626 | i = tracks.length,
|
14627 | boxes = [];
|
14628 |
|
14629 | while (i--) {
|
14630 | boxes[i] = trak(tracks[i]);
|
14631 | }
|
14632 |
|
14633 | return box.apply(null, [types.moov, mvhd(0xffffffff)].concat(boxes).concat(mvex(tracks)));
|
14634 | };
|
14635 | mvex = function(tracks) {
|
14636 | var
|
14637 | i = tracks.length,
|
14638 | boxes = [];
|
14639 |
|
14640 | while (i--) {
|
14641 | boxes[i] = trex(tracks[i]);
|
14642 | }
|
14643 | return box.apply(null, [types.mvex].concat(boxes));
|
14644 | };
|
14645 | mvhd = function(duration) {
|
14646 | var
|
14647 | bytes = new Uint8Array([
|
14648 | 0x00,
|
14649 | 0x00, 0x00, 0x00,
|
14650 | 0x00, 0x00, 0x00, 0x01,
|
14651 | 0x00, 0x00, 0x00, 0x02,
|
14652 | 0x00, 0x01, 0x5f, 0x90,
|
14653 | (duration & 0xFF000000) >> 24,
|
14654 | (duration & 0xFF0000) >> 16,
|
14655 | (duration & 0xFF00) >> 8,
|
14656 | duration & 0xFF,
|
14657 | 0x00, 0x01, 0x00, 0x00,
|
14658 | 0x01, 0x00,
|
14659 | 0x00, 0x00,
|
14660 | 0x00, 0x00, 0x00, 0x00,
|
14661 | 0x00, 0x00, 0x00, 0x00,
|
14662 | 0x00, 0x01, 0x00, 0x00,
|
14663 | 0x00, 0x00, 0x00, 0x00,
|
14664 | 0x00, 0x00, 0x00, 0x00,
|
14665 | 0x00, 0x00, 0x00, 0x00,
|
14666 | 0x00, 0x01, 0x00, 0x00,
|
14667 | 0x00, 0x00, 0x00, 0x00,
|
14668 | 0x00, 0x00, 0x00, 0x00,
|
14669 | 0x00, 0x00, 0x00, 0x00,
|
14670 | 0x40, 0x00, 0x00, 0x00,
|
14671 | 0x00, 0x00, 0x00, 0x00,
|
14672 | 0x00, 0x00, 0x00, 0x00,
|
14673 | 0x00, 0x00, 0x00, 0x00,
|
14674 | 0x00, 0x00, 0x00, 0x00,
|
14675 | 0x00, 0x00, 0x00, 0x00,
|
14676 | 0x00, 0x00, 0x00, 0x00,
|
14677 | 0xff, 0xff, 0xff, 0xff
|
14678 | ]);
|
14679 | return box(types.mvhd, bytes);
|
14680 | };
|
14681 |
|
14682 | sdtp = function(track) {
|
14683 | var
|
14684 | samples = track.samples || [],
|
14685 | bytes = new Uint8Array(4 + samples.length),
|
14686 | flags,
|
14687 | i;
|
14688 |
|
14689 |
|
14690 |
|
14691 |
|
14692 | for (i = 0; i < samples.length; i++) {
|
14693 | flags = samples[i].flags;
|
14694 |
|
14695 | bytes[i + 4] = (flags.dependsOn << 4) |
|
14696 | (flags.isDependedOn << 2) |
|
14697 | (flags.hasRedundancy);
|
14698 | }
|
14699 |
|
14700 | return box(types.sdtp,
|
14701 | bytes);
|
14702 | };
|
14703 |
|
14704 | stbl = function(track) {
|
14705 | return box(types.stbl,
|
14706 | stsd(track),
|
14707 | box(types.stts, STTS),
|
14708 | box(types.stsc, STSC),
|
14709 | box(types.stsz, STSZ),
|
14710 | box(types.stco, STCO));
|
14711 | };
|
14712 |
|
14713 | (function() {
|
14714 | var videoSample, audioSample;
|
14715 |
|
14716 | stsd = function(track) {
|
14717 |
|
14718 | return box(types.stsd, new Uint8Array([
|
14719 | 0x00,
|
14720 | 0x00, 0x00, 0x00,
|
14721 | 0x00, 0x00, 0x00, 0x01
|
14722 | ]), track.type === 'video' ? videoSample(track) : audioSample(track));
|
14723 | };
|
14724 |
|
14725 | videoSample = function(track) {
|
14726 | var
|
14727 | sps = track.sps || [],
|
14728 | pps = track.pps || [],
|
14729 | sequenceParameterSets = [],
|
14730 | pictureParameterSets = [],
|
14731 | i;
|
14732 |
|
14733 |
|
14734 | for (i = 0; i < sps.length; i++) {
|
14735 | sequenceParameterSets.push((sps[i].byteLength & 0xFF00) >>> 8);
|
14736 | sequenceParameterSets.push((sps[i].byteLength & 0xFF));
|
14737 | sequenceParameterSets = sequenceParameterSets.concat(Array.prototype.slice.call(sps[i]));
|
14738 | }
|
14739 |
|
14740 |
|
14741 | for (i = 0; i < pps.length; i++) {
|
14742 | pictureParameterSets.push((pps[i].byteLength & 0xFF00) >>> 8);
|
14743 | pictureParameterSets.push((pps[i].byteLength & 0xFF));
|
14744 | pictureParameterSets = pictureParameterSets.concat(Array.prototype.slice.call(pps[i]));
|
14745 | }
|
14746 |
|
14747 | return box(types.avc1, new Uint8Array([
|
14748 | 0x00, 0x00, 0x00,
|
14749 | 0x00, 0x00, 0x00,
|
14750 | 0x00, 0x01,
|
14751 | 0x00, 0x00,
|
14752 | 0x00, 0x00,
|
14753 | 0x00, 0x00, 0x00, 0x00,
|
14754 | 0x00, 0x00, 0x00, 0x00,
|
14755 | 0x00, 0x00, 0x00, 0x00,
|
14756 | (track.width & 0xff00) >> 8,
|
14757 | track.width & 0xff,
|
14758 | (track.height & 0xff00) >> 8,
|
14759 | track.height & 0xff,
|
14760 | 0x00, 0x48, 0x00, 0x00,
|
14761 | 0x00, 0x48, 0x00, 0x00,
|
14762 | 0x00, 0x00, 0x00, 0x00,
|
14763 | 0x00, 0x01,
|
14764 | 0x13,
|
14765 | 0x76, 0x69, 0x64, 0x65,
|
14766 | 0x6f, 0x6a, 0x73, 0x2d,
|
14767 | 0x63, 0x6f, 0x6e, 0x74,
|
14768 | 0x72, 0x69, 0x62, 0x2d,
|
14769 | 0x68, 0x6c, 0x73, 0x00,
|
14770 | 0x00, 0x00, 0x00, 0x00,
|
14771 | 0x00, 0x00, 0x00, 0x00,
|
14772 | 0x00, 0x00, 0x00,
|
14773 | 0x00, 0x18,
|
14774 | 0x11, 0x11
|
14775 | ]), box(types.avcC, new Uint8Array([
|
14776 | 0x01,
|
14777 | track.profileIdc,
|
14778 | track.profileCompatibility,
|
14779 | track.levelIdc,
|
14780 | 0xff
|
14781 | ].concat([
|
14782 | sps.length
|
14783 | ]).concat(sequenceParameterSets).concat([
|
14784 | pps.length
|
14785 | ]).concat(pictureParameterSets))),
|
14786 | box(types.btrt, new Uint8Array([
|
14787 | 0x00, 0x1c, 0x9c, 0x80,
|
14788 | 0x00, 0x2d, 0xc6, 0xc0,
|
14789 | 0x00, 0x2d, 0xc6, 0xc0
|
14790 | ]))
|
14791 | );
|
14792 | };
|
14793 |
|
14794 | audioSample = function(track) {
|
14795 | return box(types.mp4a, new Uint8Array([
|
14796 |
|
14797 |
|
14798 | 0x00, 0x00, 0x00,
|
14799 | 0x00, 0x00, 0x00,
|
14800 | 0x00, 0x01,
|
14801 |
|
14802 |
|
14803 | 0x00, 0x00, 0x00, 0x00,
|
14804 | 0x00, 0x00, 0x00, 0x00,
|
14805 | (track.channelcount & 0xff00) >> 8,
|
14806 | (track.channelcount & 0xff),
|
14807 |
|
14808 | (track.samplesize & 0xff00) >> 8,
|
14809 | (track.samplesize & 0xff),
|
14810 | 0x00, 0x00,
|
14811 | 0x00, 0x00,
|
14812 |
|
14813 | (track.samplerate & 0xff00) >> 8,
|
14814 | (track.samplerate & 0xff),
|
14815 | 0x00, 0x00
|
14816 |
|
14817 |
|
14818 | ]), esds(track));
|
14819 | };
|
14820 | }());
|
14821 |
|
14822 | tkhd = function(track) {
|
14823 | var result = new Uint8Array([
|
14824 | 0x00,
|
14825 | 0x00, 0x00, 0x07,
|
14826 | 0x00, 0x00, 0x00, 0x00,
|
14827 | 0x00, 0x00, 0x00, 0x00,
|
14828 | (track.id & 0xFF000000) >> 24,
|
14829 | (track.id & 0xFF0000) >> 16,
|
14830 | (track.id & 0xFF00) >> 8,
|
14831 | track.id & 0xFF,
|
14832 | 0x00, 0x00, 0x00, 0x00,
|
14833 | (track.duration & 0xFF000000) >> 24,
|
14834 | (track.duration & 0xFF0000) >> 16,
|
14835 | (track.duration & 0xFF00) >> 8,
|
14836 | track.duration & 0xFF,
|
14837 | 0x00, 0x00, 0x00, 0x00,
|
14838 | 0x00, 0x00, 0x00, 0x00,
|
14839 | 0x00, 0x00,
|
14840 | 0x00, 0x00,
|
14841 | 0x01, 0x00,
|
14842 | 0x00, 0x00,
|
14843 | 0x00, 0x01, 0x00, 0x00,
|
14844 | 0x00, 0x00, 0x00, 0x00,
|
14845 | 0x00, 0x00, 0x00, 0x00,
|
14846 | 0x00, 0x00, 0x00, 0x00,
|
14847 | 0x00, 0x01, 0x00, 0x00,
|
14848 | 0x00, 0x00, 0x00, 0x00,
|
14849 | 0x00, 0x00, 0x00, 0x00,
|
14850 | 0x00, 0x00, 0x00, 0x00,
|
14851 | 0x40, 0x00, 0x00, 0x00,
|
14852 | (track.width & 0xFF00) >> 8,
|
14853 | track.width & 0xFF,
|
14854 | 0x00, 0x00,
|
14855 | (track.height & 0xFF00) >> 8,
|
14856 | track.height & 0xFF,
|
14857 | 0x00, 0x00
|
14858 | ]);
|
14859 |
|
14860 | return box(types.tkhd, result);
|
14861 | };
|
14862 |
|
14863 |
|
14864 |
|
14865 |
|
14866 |
|
14867 | traf = function(track) {
|
14868 | var trackFragmentHeader, trackFragmentDecodeTime, trackFragmentRun,
|
14869 | sampleDependencyTable, dataOffset,
|
14870 | upperWordBaseMediaDecodeTime, lowerWordBaseMediaDecodeTime;
|
14871 |
|
14872 | trackFragmentHeader = box(types.tfhd, new Uint8Array([
|
14873 | 0x00,
|
14874 | 0x00, 0x00, 0x3a,
|
14875 | (track.id & 0xFF000000) >> 24,
|
14876 | (track.id & 0xFF0000) >> 16,
|
14877 | (track.id & 0xFF00) >> 8,
|
14878 | (track.id & 0xFF),
|
14879 | 0x00, 0x00, 0x00, 0x01,
|
14880 | 0x00, 0x00, 0x00, 0x00,
|
14881 | 0x00, 0x00, 0x00, 0x00,
|
14882 | 0x00, 0x00, 0x00, 0x00
|
14883 | ]));
|
14884 |
|
14885 | upperWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime / (UINT32_MAX + 1));
|
14886 | lowerWordBaseMediaDecodeTime = Math.floor(track.baseMediaDecodeTime % (UINT32_MAX + 1));
|
14887 |
|
14888 | trackFragmentDecodeTime = box(types.tfdt, new Uint8Array([
|
14889 | 0x01,
|
14890 | 0x00, 0x00, 0x00,
|
14891 |
|
14892 | (upperWordBaseMediaDecodeTime >>> 24) & 0xFF,
|
14893 | (upperWordBaseMediaDecodeTime >>> 16) & 0xFF,
|
14894 | (upperWordBaseMediaDecodeTime >>> 8) & 0xFF,
|
14895 | upperWordBaseMediaDecodeTime & 0xFF,
|
14896 | (lowerWordBaseMediaDecodeTime >>> 24) & 0xFF,
|
14897 | (lowerWordBaseMediaDecodeTime >>> 16) & 0xFF,
|
14898 | (lowerWordBaseMediaDecodeTime >>> 8) & 0xFF,
|
14899 | lowerWordBaseMediaDecodeTime & 0xFF
|
14900 | ]));
|
14901 |
|
14902 |
|
14903 |
|
14904 |
|
14905 | dataOffset = (32 +
|
14906 | 20 +
|
14907 | 8 +
|
14908 | 16 +
|
14909 | 8 +
|
14910 | 8);
|
14911 |
|
14912 |
|
14913 | if (track.type === 'audio') {
|
14914 | trackFragmentRun = trun(track, dataOffset);
|
14915 | return box(types.traf,
|
14916 | trackFragmentHeader,
|
14917 | trackFragmentDecodeTime,
|
14918 | trackFragmentRun);
|
14919 | }
|
14920 |
|
14921 |
|
14922 |
|
14923 |
|
14924 | sampleDependencyTable = sdtp(track);
|
14925 | trackFragmentRun = trun(track,
|
14926 | sampleDependencyTable.length + dataOffset);
|
14927 | return box(types.traf,
|
14928 | trackFragmentHeader,
|
14929 | trackFragmentDecodeTime,
|
14930 | trackFragmentRun,
|
14931 | sampleDependencyTable);
|
14932 | };
|
14933 |
|
14934 |
|
14935 |
|
14936 |
|
14937 |
|
14938 |
|
14939 | trak = function(track) {
|
14940 | track.duration = track.duration || 0xffffffff;
|
14941 | return box(types.trak,
|
14942 | tkhd(track),
|
14943 | mdia(track));
|
14944 | };
|
14945 |
|
14946 | trex = function(track) {
|
14947 | var result = new Uint8Array([
|
14948 | 0x00,
|
14949 | 0x00, 0x00, 0x00,
|
14950 | (track.id & 0xFF000000) >> 24,
|
14951 | (track.id & 0xFF0000) >> 16,
|
14952 | (track.id & 0xFF00) >> 8,
|
14953 | (track.id & 0xFF),
|
14954 | 0x00, 0x00, 0x00, 0x01,
|
14955 | 0x00, 0x00, 0x00, 0x00,
|
14956 | 0x00, 0x00, 0x00, 0x00,
|
14957 | 0x00, 0x01, 0x00, 0x01
|
14958 | ]);
|
14959 |
|
14960 |
|
14961 |
|
14962 |
|
14963 | if (track.type !== 'video') {
|
14964 | result[result.length - 1] = 0x00;
|
14965 | }
|
14966 |
|
14967 | return box(types.trex, result);
|
14968 | };
|
14969 |
|
14970 | (function() {
|
14971 | var audioTrun, videoTrun, trunHeader;
|
14972 |
|
14973 |
|
14974 |
|
14975 |
|
14976 |
|
14977 | trunHeader = function(samples, offset) {
|
14978 | var durationPresent = 0, sizePresent = 0,
|
14979 | flagsPresent = 0, compositionTimeOffset = 0;
|
14980 |
|
14981 |
|
14982 | if (samples.length) {
|
14983 | if (samples[0].duration !== undefined) {
|
14984 | durationPresent = 0x1;
|
14985 | }
|
14986 | if (samples[0].size !== undefined) {
|
14987 | sizePresent = 0x2;
|
14988 | }
|
14989 | if (samples[0].flags !== undefined) {
|
14990 | flagsPresent = 0x4;
|
14991 | }
|
14992 | if (samples[0].compositionTimeOffset !== undefined) {
|
14993 | compositionTimeOffset = 0x8;
|
14994 | }
|
14995 | }
|
14996 |
|
14997 | return [
|
14998 | 0x00,
|
14999 | 0x00,
|
15000 | durationPresent | sizePresent | flagsPresent | compositionTimeOffset,
|
15001 | 0x01,
|
15002 | (samples.length & 0xFF000000) >>> 24,
|
15003 | (samples.length & 0xFF0000) >>> 16,
|
15004 | (samples.length & 0xFF00) >>> 8,
|
15005 | samples.length & 0xFF,
|
15006 | (offset & 0xFF000000) >>> 24,
|
15007 | (offset & 0xFF0000) >>> 16,
|
15008 | (offset & 0xFF00) >>> 8,
|
15009 | offset & 0xFF
|
15010 | ];
|
15011 | };
|
15012 |
|
15013 | videoTrun = function(track, offset) {
|
15014 | var bytes, samples, sample, i;
|
15015 |
|
15016 | samples = track.samples || [];
|
15017 | offset += 8 + 12 + (16 * samples.length);
|
15018 |
|
15019 | bytes = trunHeader(samples, offset);
|
15020 |
|
15021 | for (i = 0; i < samples.length; i++) {
|
15022 | sample = samples[i];
|
15023 | bytes = bytes.concat([
|
15024 | (sample.duration & 0xFF000000) >>> 24,
|
15025 | (sample.duration & 0xFF0000) >>> 16,
|
15026 | (sample.duration & 0xFF00) >>> 8,
|
15027 | sample.duration & 0xFF,
|
15028 | (sample.size & 0xFF000000) >>> 24,
|
15029 | (sample.size & 0xFF0000) >>> 16,
|
15030 | (sample.size & 0xFF00) >>> 8,
|
15031 | sample.size & 0xFF,
|
15032 | (sample.flags.isLeading << 2) | sample.flags.dependsOn,
|
15033 | (sample.flags.isDependedOn << 6) |
|
15034 | (sample.flags.hasRedundancy << 4) |
|
15035 | (sample.flags.paddingValue << 1) |
|
15036 | sample.flags.isNonSyncSample,
|
15037 | sample.flags.degradationPriority & 0xF0 << 8,
|
15038 | sample.flags.degradationPriority & 0x0F,
|
15039 | (sample.compositionTimeOffset & 0xFF000000) >>> 24,
|
15040 | (sample.compositionTimeOffset & 0xFF0000) >>> 16,
|
15041 | (sample.compositionTimeOffset & 0xFF00) >>> 8,
|
15042 | sample.compositionTimeOffset & 0xFF
|
15043 | ]);
|
15044 | }
|
15045 | return box(types.trun, new Uint8Array(bytes));
|
15046 | };
|
15047 |
|
15048 | audioTrun = function(track, offset) {
|
15049 | var bytes, samples, sample, i;
|
15050 |
|
15051 | samples = track.samples || [];
|
15052 | offset += 8 + 12 + (8 * samples.length);
|
15053 |
|
15054 | bytes = trunHeader(samples, offset);
|
15055 |
|
15056 | for (i = 0; i < samples.length; i++) {
|
15057 | sample = samples[i];
|
15058 | bytes = bytes.concat([
|
15059 | (sample.duration & 0xFF000000) >>> 24,
|
15060 | (sample.duration & 0xFF0000) >>> 16,
|
15061 | (sample.duration & 0xFF00) >>> 8,
|
15062 | sample.duration & 0xFF,
|
15063 | (sample.size & 0xFF000000) >>> 24,
|
15064 | (sample.size & 0xFF0000) >>> 16,
|
15065 | (sample.size & 0xFF00) >>> 8,
|
15066 | sample.size & 0xFF]);
|
15067 | }
|
15068 |
|
15069 | return box(types.trun, new Uint8Array(bytes));
|
15070 | };
|
15071 |
|
15072 | trun = function(track, offset) {
|
15073 | if (track.type === 'audio') {
|
15074 | return audioTrun(track, offset);
|
15075 | }
|
15076 |
|
15077 | return videoTrun(track, offset);
|
15078 | };
|
15079 | }());
|
15080 |
|
15081 | module.exports = {
|
15082 | ftyp: ftyp,
|
15083 | mdat: mdat,
|
15084 | moof: moof,
|
15085 | moov: moov,
|
15086 | initSegment: function(tracks) {
|
15087 | var
|
15088 | fileType = ftyp(),
|
15089 | movie = moov(tracks),
|
15090 | result;
|
15091 |
|
15092 | result = new Uint8Array(fileType.byteLength + movie.byteLength);
|
15093 | result.set(fileType);
|
15094 | result.set(movie, fileType.byteLength);
|
15095 | return result;
|
15096 | }
|
15097 | };
|
15098 |
|
15099 | },{}],57:[function(require,module,exports){
|
15100 |
|
15101 |
|
15102 |
|
15103 |
|
15104 |
|
15105 |
|
15106 |
|
15107 |
|
15108 | 'use strict';
|
15109 |
|
15110 | var findBox, parseType, timescale, startTime;
|
15111 |
|
15112 |
|
15113 | findBox = function(data, path) {
|
15114 | var results = [],
|
15115 | i, size, type, end, subresults;
|
15116 |
|
15117 | if (!path.length) {
|
15118 |
|
15119 | return null;
|
15120 | }
|
15121 |
|
15122 | for (i = 0; i < data.byteLength;) {
|
15123 | size = data[i] << 24;
|
15124 | size |= data[i + 1] << 16;
|
15125 | size |= data[i + 2] << 8;
|
15126 | size |= data[i + 3];
|
15127 |
|
15128 | type = parseType(data.subarray(i + 4, i + 8));
|
15129 |
|
15130 | end = size > 1 ? i + size : data.byteLength;
|
15131 |
|
15132 | if (type === path[0]) {
|
15133 | if (path.length === 1) {
|
15134 |
|
15135 |
|
15136 | results.push(data.subarray(i + 8, end));
|
15137 | } else {
|
15138 |
|
15139 | subresults = findBox(data.subarray(i + 8, end), path.slice(1));
|
15140 | if (subresults.length) {
|
15141 | results = results.concat(subresults);
|
15142 | }
|
15143 | }
|
15144 | }
|
15145 | i = end;
|
15146 | }
|
15147 |
|
15148 |
|
15149 | return results;
|
15150 | };
|
15151 |
|
15152 |
|
15153 |
|
15154 |
|
15155 |
|
15156 |
|
15157 | parseType = function(buffer) {
|
15158 | var result = '';
|
15159 | result += String.fromCharCode(buffer[0]);
|
15160 | result += String.fromCharCode(buffer[1]);
|
15161 | result += String.fromCharCode(buffer[2]);
|
15162 | result += String.fromCharCode(buffer[3]);
|
15163 | return result;
|
15164 | };
|
15165 |
|
15166 |
|
15167 |
|
15168 |
|
15169 |
|
15170 |
|
15171 |
|
15172 |
|
15173 |
|
15174 |
|
15175 |
|
15176 |
|
15177 |
|
15178 |
|
15179 |
|
15180 |
|
15181 |
|
15182 |
|
15183 |
|
15184 | timescale = function(init) {
|
15185 | var
|
15186 | result = {},
|
15187 | traks = findBox(init, ['moov', 'trak']);
|
15188 |
|
15189 |
|
15190 | return traks.reduce(function(result, trak) {
|
15191 | var tkhd, version, index, id, mdhd;
|
15192 |
|
15193 | tkhd = findBox(trak, ['tkhd'])[0];
|
15194 | if (!tkhd) {
|
15195 | return null;
|
15196 | }
|
15197 | version = tkhd[0];
|
15198 | index = version === 0 ? 12 : 20;
|
15199 | id = tkhd[index] << 24 |
|
15200 | tkhd[index + 1] << 16 |
|
15201 | tkhd[index + 2] << 8 |
|
15202 | tkhd[index + 3];
|
15203 |
|
15204 | mdhd = findBox(trak, ['mdia', 'mdhd'])[0];
|
15205 | if (!mdhd) {
|
15206 | return null;
|
15207 | }
|
15208 | version = mdhd[0];
|
15209 | index = version === 0 ? 12 : 20;
|
15210 | result[id] = mdhd[index] << 24 |
|
15211 | mdhd[index + 1] << 16 |
|
15212 | mdhd[index + 2] << 8 |
|
15213 | mdhd[index + 3];
|
15214 | return result;
|
15215 | }, result);
|
15216 | };
|
15217 |
|
15218 |
|
15219 |
|
15220 |
|
15221 |
|
15222 |
|
15223 |
|
15224 |
|
15225 |
|
15226 |
|
15227 |
|
15228 |
|
15229 |
|
15230 |
|
15231 |
|
15232 |
|
15233 |
|
15234 | startTime = function(timescale, fragment) {
|
15235 | var trafs, baseTimes, result;
|
15236 |
|
15237 |
|
15238 | trafs = findBox(fragment, ['moof', 'traf']);
|
15239 |
|
15240 |
|
15241 | baseTimes = [].concat.apply([], trafs.map(function(traf) {
|
15242 | return findBox(traf, ['tfhd']).map(function(tfhd) {
|
15243 | var id, scale, baseTime;
|
15244 |
|
15245 |
|
15246 | id = tfhd[4] << 24 |
|
15247 | tfhd[5] << 16 |
|
15248 | tfhd[6] << 8 |
|
15249 | tfhd[7];
|
15250 |
|
15251 | scale = timescale[id] || 90e3;
|
15252 |
|
15253 |
|
15254 | baseTime = findBox(traf, ['tfdt']).map(function(tfdt) {
|
15255 | var version, result;
|
15256 |
|
15257 | version = tfdt[0];
|
15258 | result = tfdt[4] << 24 |
|
15259 | tfdt[5] << 16 |
|
15260 | tfdt[6] << 8 |
|
15261 | tfdt[7];
|
15262 | if (version === 1) {
|
15263 | result *= Math.pow(2, 32);
|
15264 | result += tfdt[8] << 24 |
|
15265 | tfdt[9] << 16 |
|
15266 | tfdt[10] << 8 |
|
15267 | tfdt[11];
|
15268 | }
|
15269 | return result;
|
15270 | })[0];
|
15271 | baseTime = baseTime || Infinity;
|
15272 |
|
15273 |
|
15274 | return baseTime / scale;
|
15275 | });
|
15276 | }));
|
15277 |
|
15278 |
|
15279 | result = Math.min.apply(null, baseTimes);
|
15280 | return isFinite(result) ? result : 0;
|
15281 | };
|
15282 |
|
15283 | module.exports = {
|
15284 | parseType: parseType,
|
15285 | timescale: timescale,
|
15286 | startTime: startTime
|
15287 | };
|
15288 |
|
15289 | },{}],58:[function(require,module,exports){
|
15290 |
|
15291 |
|
15292 |
|
15293 |
|
15294 |
|
15295 |
|
15296 |
|
15297 |
|
15298 |
|
15299 |
|
15300 | 'use strict';
|
15301 |
|
15302 | var Stream = require('../utils/stream.js');
|
15303 | var mp4 = require('./mp4-generator.js');
|
15304 | var m2ts = require('../m2ts/m2ts.js');
|
15305 | var AdtsStream = require('../codecs/adts.js');
|
15306 | var H264Stream = require('../codecs/h264').H264Stream;
|
15307 | var AacStream = require('../aac');
|
15308 | var coneOfSilence = require('../data/silence');
|
15309 | var clock = require('../utils/clock');
|
15310 |
|
15311 |
|
15312 | var AUDIO_PROPERTIES = [
|
15313 | 'audioobjecttype',
|
15314 | 'channelcount',
|
15315 | 'samplerate',
|
15316 | 'samplingfrequencyindex',
|
15317 | 'samplesize'
|
15318 | ];
|
15319 |
|
15320 | var VIDEO_PROPERTIES = [
|
15321 | 'width',
|
15322 | 'height',
|
15323 | 'profileIdc',
|
15324 | 'levelIdc',
|
15325 | 'profileCompatibility'
|
15326 | ];
|
15327 |
|
15328 | var ONE_SECOND_IN_TS = 90000;
|
15329 |
|
15330 |
|
15331 | var VideoSegmentStream, AudioSegmentStream, Transmuxer, CoalesceStream;
|
15332 |
|
15333 |
|
15334 | var
|
15335 | createDefaultSample,
|
15336 | isLikelyAacData,
|
15337 | collectDtsInfo,
|
15338 | clearDtsInfo,
|
15339 | calculateTrackBaseMediaDecodeTime,
|
15340 | arrayEquals,
|
15341 | sumFrameByteLengths;
|
15342 |
|
15343 |
|
15344 |
|
15345 |
|
15346 |
|
15347 | createDefaultSample = function() {
|
15348 | return {
|
15349 | size: 0,
|
15350 | flags: {
|
15351 | isLeading: 0,
|
15352 | dependsOn: 1,
|
15353 | isDependedOn: 0,
|
15354 | hasRedundancy: 0,
|
15355 | degradationPriority: 0
|
15356 | }
|
15357 | };
|
15358 | };
|
15359 |
|
15360 | isLikelyAacData = function(data) {
|
15361 | if ((data[0] === 'I'.charCodeAt(0)) &&
|
15362 | (data[1] === 'D'.charCodeAt(0)) &&
|
15363 | (data[2] === '3'.charCodeAt(0))) {
|
15364 | return true;
|
15365 | }
|
15366 | return false;
|
15367 | };
|
15368 |
|
15369 |
|
15370 |
|
15371 |
|
15372 | arrayEquals = function(a, b) {
|
15373 | var
|
15374 | i;
|
15375 |
|
15376 | if (a.length !== b.length) {
|
15377 | return false;
|
15378 | }
|
15379 |
|
15380 |
|
15381 | for (i = 0; i < a.length; i++) {
|
15382 | if (a[i] !== b[i]) {
|
15383 | return false;
|
15384 | }
|
15385 | }
|
15386 |
|
15387 | return true;
|
15388 | };
|
15389 |
|
15390 |
|
15391 |
|
15392 |
|
15393 | sumFrameByteLengths = function(array) {
|
15394 | var
|
15395 | i,
|
15396 | currentObj,
|
15397 | sum = 0;
|
15398 |
|
15399 |
|
15400 | for (i = 0; i < array.length; i++) {
|
15401 | currentObj = array[i];
|
15402 | sum += currentObj.data.byteLength;
|
15403 | }
|
15404 |
|
15405 | return sum;
|
15406 | };
|
15407 |
|
15408 |
|
15409 |
|
15410 |
|
15411 |
|
15412 |
|
15413 | AudioSegmentStream = function(track) {
|
15414 | var
|
15415 | adtsFrames = [],
|
15416 | sequenceNumber = 0,
|
15417 | earliestAllowedDts = 0,
|
15418 | audioAppendStartTs = 0,
|
15419 | videoBaseMediaDecodeTime = Infinity;
|
15420 |
|
15421 | AudioSegmentStream.prototype.init.call(this);
|
15422 |
|
15423 | this.push = function(data) {
|
15424 | collectDtsInfo(track, data);
|
15425 |
|
15426 | if (track) {
|
15427 | AUDIO_PROPERTIES.forEach(function(prop) {
|
15428 | track[prop] = data[prop];
|
15429 | });
|
15430 | }
|
15431 |
|
15432 |
|
15433 | adtsFrames.push(data);
|
15434 | };
|
15435 |
|
15436 | this.setEarliestDts = function(earliestDts) {
|
15437 | earliestAllowedDts = earliestDts - track.timelineStartInfo.baseMediaDecodeTime;
|
15438 | };
|
15439 |
|
15440 | this.setVideoBaseMediaDecodeTime = function(baseMediaDecodeTime) {
|
15441 | videoBaseMediaDecodeTime = baseMediaDecodeTime;
|
15442 | };
|
15443 |
|
15444 | this.setAudioAppendStart = function(timestamp) {
|
15445 | audioAppendStartTs = timestamp;
|
15446 | };
|
15447 |
|
15448 | this.flush = function() {
|
15449 | var
|
15450 | frames,
|
15451 | moof,
|
15452 | mdat,
|
15453 | boxes;
|
15454 |
|
15455 |
|
15456 | if (adtsFrames.length === 0) {
|
15457 | this.trigger('done', 'AudioSegmentStream');
|
15458 | return;
|
15459 | }
|
15460 |
|
15461 | frames = this.trimAdtsFramesByEarliestDts_(adtsFrames);
|
15462 | track.baseMediaDecodeTime = calculateTrackBaseMediaDecodeTime(track);
|
15463 |
|
15464 | this.prefixWithSilence_(track, frames);
|
15465 |
|
15466 |
|
15467 |
|
15468 | track.samples = this.generateSampleTable_(frames);
|
15469 |
|
15470 |
|
15471 | mdat = mp4.mdat(this.concatenateFrameData_(frames));
|
15472 |
|
15473 | adtsFrames = [];
|
15474 |
|
15475 | moof = mp4.moof(sequenceNumber, [track]);
|
15476 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
15477 |
|
15478 |
|
15479 | sequenceNumber++;
|
15480 |
|
15481 | boxes.set(moof);
|
15482 | boxes.set(mdat, moof.byteLength);
|
15483 |
|
15484 | clearDtsInfo(track);
|
15485 |
|
15486 | this.trigger('data', {track: track, boxes: boxes});
|
15487 | this.trigger('done', 'AudioSegmentStream');
|
15488 | };
|
15489 |
|
15490 |
|
15491 |
|
15492 | this.prefixWithSilence_ = function(track, frames) {
|
15493 | var
|
15494 | baseMediaDecodeTimeTs,
|
15495 | frameDuration = 0,
|
15496 | audioGapDuration = 0,
|
15497 | audioFillFrameCount = 0,
|
15498 | audioFillDuration = 0,
|
15499 | silentFrame,
|
15500 | i;
|
15501 |
|
15502 | if (!frames.length) {
|
15503 | return;
|
15504 | }
|
15505 |
|
15506 | baseMediaDecodeTimeTs = clock.audioTsToVideoTs(track.baseMediaDecodeTime, track.samplerate);
|
15507 |
|
15508 | frameDuration = Math.ceil(ONE_SECOND_IN_TS / (track.samplerate / 1024));
|
15509 |
|
15510 | if (audioAppendStartTs && videoBaseMediaDecodeTime) {
|
15511 |
|
15512 | audioGapDuration =
|
15513 | baseMediaDecodeTimeTs - Math.max(audioAppendStartTs, videoBaseMediaDecodeTime);
|
15514 |
|
15515 | audioFillFrameCount = Math.floor(audioGapDuration / frameDuration);
|
15516 | audioFillDuration = audioFillFrameCount * frameDuration;
|
15517 | }
|
15518 |
|
15519 |
|
15520 |
|
15521 | if (audioFillFrameCount < 1 || audioFillDuration > ONE_SECOND_IN_TS / 2) {
|
15522 | return;
|
15523 | }
|
15524 |
|
15525 | silentFrame = coneOfSilence[track.samplerate];
|
15526 |
|
15527 | if (!silentFrame) {
|
15528 |
|
15529 |
|
15530 | silentFrame = frames[0].data;
|
15531 | }
|
15532 |
|
15533 | for (i = 0; i < audioFillFrameCount; i++) {
|
15534 | frames.splice(i, 0, {
|
15535 | data: silentFrame
|
15536 | });
|
15537 | }
|
15538 |
|
15539 | track.baseMediaDecodeTime -=
|
15540 | Math.floor(clock.videoTsToAudioTs(audioFillDuration, track.samplerate));
|
15541 | };
|
15542 |
|
15543 |
|
15544 |
|
15545 |
|
15546 |
|
15547 | this.trimAdtsFramesByEarliestDts_ = function(adtsFrames) {
|
15548 | if (track.minSegmentDts >= earliestAllowedDts) {
|
15549 | return adtsFrames;
|
15550 | }
|
15551 |
|
15552 |
|
15553 | track.minSegmentDts = Infinity;
|
15554 |
|
15555 | return adtsFrames.filter(function(currentFrame) {
|
15556 |
|
15557 | if (currentFrame.dts >= earliestAllowedDts) {
|
15558 | track.minSegmentDts = Math.min(track.minSegmentDts, currentFrame.dts);
|
15559 | track.minSegmentPts = track.minSegmentDts;
|
15560 | return true;
|
15561 | }
|
15562 |
|
15563 | return false;
|
15564 | });
|
15565 | };
|
15566 |
|
15567 |
|
15568 | this.generateSampleTable_ = function(frames) {
|
15569 | var
|
15570 | i,
|
15571 | currentFrame,
|
15572 | samples = [];
|
15573 |
|
15574 | for (i = 0; i < frames.length; i++) {
|
15575 | currentFrame = frames[i];
|
15576 | samples.push({
|
15577 | size: currentFrame.data.byteLength,
|
15578 | duration: 1024
|
15579 | });
|
15580 | }
|
15581 | return samples;
|
15582 | };
|
15583 |
|
15584 |
|
15585 | this.concatenateFrameData_ = function(frames) {
|
15586 | var
|
15587 | i,
|
15588 | currentFrame,
|
15589 | dataOffset = 0,
|
15590 | data = new Uint8Array(sumFrameByteLengths(frames));
|
15591 |
|
15592 | for (i = 0; i < frames.length; i++) {
|
15593 | currentFrame = frames[i];
|
15594 |
|
15595 | data.set(currentFrame.data, dataOffset);
|
15596 | dataOffset += currentFrame.data.byteLength;
|
15597 | }
|
15598 | return data;
|
15599 | };
|
15600 | };
|
15601 |
|
15602 | AudioSegmentStream.prototype = new Stream();
|
15603 |
|
15604 |
|
15605 |
|
15606 |
|
15607 |
|
15608 |
|
15609 |
|
15610 |
|
15611 |
|
15612 |
|
15613 | VideoSegmentStream = function(track, options) {
|
15614 | var
|
15615 | sequenceNumber = 0,
|
15616 | nalUnits = [],
|
15617 | gopsToAlignWith = [],
|
15618 | config,
|
15619 | pps;
|
15620 |
|
15621 | options = options || {};
|
15622 |
|
15623 | VideoSegmentStream.prototype.init.call(this);
|
15624 |
|
15625 | delete track.minPTS;
|
15626 |
|
15627 | this.gopCache_ = [];
|
15628 |
|
15629 | this.push = function(nalUnit) {
|
15630 | collectDtsInfo(track, nalUnit);
|
15631 |
|
15632 |
|
15633 | if (nalUnit.nalUnitType === 'seq_parameter_set_rbsp' && !config) {
|
15634 | config = nalUnit.config;
|
15635 | track.sps = [nalUnit.data];
|
15636 |
|
15637 | VIDEO_PROPERTIES.forEach(function(prop) {
|
15638 | track[prop] = config[prop];
|
15639 | }, this);
|
15640 | }
|
15641 |
|
15642 | if (nalUnit.nalUnitType === 'pic_parameter_set_rbsp' &&
|
15643 | !pps) {
|
15644 | pps = nalUnit.data;
|
15645 | track.pps = [nalUnit.data];
|
15646 | }
|
15647 |
|
15648 |
|
15649 | nalUnits.push(nalUnit);
|
15650 | };
|
15651 |
|
15652 | this.flush = function() {
|
15653 | var
|
15654 | frames,
|
15655 | gopForFusion,
|
15656 | gops,
|
15657 | moof,
|
15658 | mdat,
|
15659 | boxes;
|
15660 |
|
15661 |
|
15662 |
|
15663 | while (nalUnits.length) {
|
15664 | if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
|
15665 | break;
|
15666 | }
|
15667 | nalUnits.shift();
|
15668 | }
|
15669 |
|
15670 |
|
15671 | if (nalUnits.length === 0) {
|
15672 | this.resetStream_();
|
15673 | this.trigger('done', 'VideoSegmentStream');
|
15674 | return;
|
15675 | }
|
15676 |
|
15677 |
|
15678 |
|
15679 |
|
15680 | frames = this.groupNalsIntoFrames_(nalUnits);
|
15681 | gops = this.groupFramesIntoGops_(frames);
|
15682 |
|
15683 |
|
15684 |
|
15685 |
|
15686 |
|
15687 |
|
15688 |
|
15689 |
|
15690 |
|
15691 |
|
15692 |
|
15693 |
|
15694 |
|
15695 |
|
15696 |
|
15697 |
|
15698 |
|
15699 |
|
15700 |
|
15701 | if (!gops[0][0].keyFrame) {
|
15702 |
|
15703 | gopForFusion = this.getGopForFusion_(nalUnits[0], track);
|
15704 |
|
15705 | if (gopForFusion) {
|
15706 | gops.unshift(gopForFusion);
|
15707 |
|
15708 |
|
15709 | gops.byteLength += gopForFusion.byteLength;
|
15710 | gops.nalCount += gopForFusion.nalCount;
|
15711 | gops.pts = gopForFusion.pts;
|
15712 | gops.dts = gopForFusion.dts;
|
15713 | gops.duration += gopForFusion.duration;
|
15714 | } else {
|
15715 |
|
15716 | gops = this.extendFirstKeyFrame_(gops);
|
15717 | }
|
15718 | }
|
15719 |
|
15720 |
|
15721 | if (gopsToAlignWith.length) {
|
15722 | var alignedGops;
|
15723 |
|
15724 | if (options.alignGopsAtEnd) {
|
15725 | alignedGops = this.alignGopsAtEnd_(gops);
|
15726 | } else {
|
15727 | alignedGops = this.alignGopsAtStart_(gops);
|
15728 | }
|
15729 |
|
15730 | if (!alignedGops) {
|
15731 |
|
15732 | this.gopCache_.unshift({
|
15733 | gop: gops.pop(),
|
15734 | pps: track.pps,
|
15735 | sps: track.sps
|
15736 | });
|
15737 |
|
15738 |
|
15739 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
15740 |
|
15741 |
|
15742 | nalUnits = [];
|
15743 |
|
15744 |
|
15745 | this.resetStream_();
|
15746 | this.trigger('done', 'VideoSegmentStream');
|
15747 | return;
|
15748 | }
|
15749 |
|
15750 |
|
15751 |
|
15752 | clearDtsInfo(track);
|
15753 |
|
15754 | gops = alignedGops;
|
15755 | }
|
15756 |
|
15757 | collectDtsInfo(track, gops);
|
15758 |
|
15759 |
|
15760 |
|
15761 | track.samples = this.generateSampleTable_(gops);
|
15762 |
|
15763 |
|
15764 | mdat = mp4.mdat(this.concatenateNalData_(gops));
|
15765 |
|
15766 | track.baseMediaDecodeTime = calculateTrackBaseMediaDecodeTime(track);
|
15767 |
|
15768 | this.trigger('processedGopsInfo', gops.map(function(gop) {
|
15769 | return {
|
15770 | pts: gop.pts,
|
15771 | dts: gop.dts,
|
15772 | byteLength: gop.byteLength
|
15773 | };
|
15774 | }));
|
15775 |
|
15776 |
|
15777 | this.gopCache_.unshift({
|
15778 | gop: gops.pop(),
|
15779 | pps: track.pps,
|
15780 | sps: track.sps
|
15781 | });
|
15782 |
|
15783 |
|
15784 | this.gopCache_.length = Math.min(6, this.gopCache_.length);
|
15785 |
|
15786 |
|
15787 | nalUnits = [];
|
15788 |
|
15789 | this.trigger('baseMediaDecodeTime', track.baseMediaDecodeTime);
|
15790 | this.trigger('timelineStartInfo', track.timelineStartInfo);
|
15791 |
|
15792 | moof = mp4.moof(sequenceNumber, [track]);
|
15793 |
|
15794 |
|
15795 |
|
15796 | boxes = new Uint8Array(moof.byteLength + mdat.byteLength);
|
15797 |
|
15798 |
|
15799 | sequenceNumber++;
|
15800 |
|
15801 | boxes.set(moof);
|
15802 | boxes.set(mdat, moof.byteLength);
|
15803 |
|
15804 | this.trigger('data', {track: track, boxes: boxes});
|
15805 |
|
15806 | this.resetStream_();
|
15807 |
|
15808 |
|
15809 | this.trigger('done', 'VideoSegmentStream');
|
15810 | };
|
15811 |
|
15812 | this.resetStream_ = function() {
|
15813 | clearDtsInfo(track);
|
15814 |
|
15815 |
|
15816 |
|
15817 | config = undefined;
|
15818 | pps = undefined;
|
15819 | };
|
15820 |
|
15821 |
|
15822 |
|
15823 | this.getGopForFusion_ = function(nalUnit) {
|
15824 | var
|
15825 | halfSecond = 45000,
|
15826 | allowableOverlap = 10000,
|
15827 | nearestDistance = Infinity,
|
15828 | dtsDistance,
|
15829 | nearestGopObj,
|
15830 | currentGop,
|
15831 | currentGopObj,
|
15832 | i;
|
15833 |
|
15834 |
|
15835 | for (i = 0; i < this.gopCache_.length; i++) {
|
15836 | currentGopObj = this.gopCache_[i];
|
15837 | currentGop = currentGopObj.gop;
|
15838 |
|
15839 |
|
15840 | if (!(track.pps && arrayEquals(track.pps[0], currentGopObj.pps[0])) ||
|
15841 | !(track.sps && arrayEquals(track.sps[0], currentGopObj.sps[0]))) {
|
15842 | continue;
|
15843 | }
|
15844 |
|
15845 |
|
15846 | if (currentGop.dts < track.timelineStartInfo.dts) {
|
15847 | continue;
|
15848 | }
|
15849 |
|
15850 |
|
15851 | dtsDistance = (nalUnit.dts - currentGop.dts) - currentGop.duration;
|
15852 |
|
15853 |
|
15854 |
|
15855 | if (dtsDistance >= -allowableOverlap &&
|
15856 | dtsDistance <= halfSecond) {
|
15857 |
|
15858 |
|
15859 |
|
15860 | if (!nearestGopObj ||
|
15861 | nearestDistance > dtsDistance) {
|
15862 | nearestGopObj = currentGopObj;
|
15863 | nearestDistance = dtsDistance;
|
15864 | }
|
15865 | }
|
15866 | }
|
15867 |
|
15868 | if (nearestGopObj) {
|
15869 | return nearestGopObj.gop;
|
15870 | }
|
15871 | return null;
|
15872 | };
|
15873 |
|
15874 | this.extendFirstKeyFrame_ = function(gops) {
|
15875 | var currentGop;
|
15876 |
|
15877 | if (!gops[0][0].keyFrame && gops.length > 1) {
|
15878 |
|
15879 | currentGop = gops.shift();
|
15880 |
|
15881 | gops.byteLength -= currentGop.byteLength;
|
15882 | gops.nalCount -= currentGop.nalCount;
|
15883 |
|
15884 |
|
15885 |
|
15886 |
|
15887 | gops[0][0].dts = currentGop.dts;
|
15888 | gops[0][0].pts = currentGop.pts;
|
15889 | gops[0][0].duration += currentGop.duration;
|
15890 | }
|
15891 |
|
15892 | return gops;
|
15893 | };
|
15894 |
|
15895 |
|
15896 |
|
15897 |
|
15898 |
|
15899 | this.groupNalsIntoFrames_ = function(nalUnits) {
|
15900 | var
|
15901 | i,
|
15902 | currentNal,
|
15903 | currentFrame = [],
|
15904 | frames = [];
|
15905 |
|
15906 | currentFrame.byteLength = 0;
|
15907 |
|
15908 | for (i = 0; i < nalUnits.length; i++) {
|
15909 | currentNal = nalUnits[i];
|
15910 |
|
15911 |
|
15912 | if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
|
15913 |
|
15914 |
|
15915 | if (currentFrame.length) {
|
15916 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
15917 | frames.push(currentFrame);
|
15918 | }
|
15919 | currentFrame = [currentNal];
|
15920 | currentFrame.byteLength = currentNal.data.byteLength;
|
15921 | currentFrame.pts = currentNal.pts;
|
15922 | currentFrame.dts = currentNal.dts;
|
15923 | } else {
|
15924 |
|
15925 | if (currentNal.nalUnitType === 'slice_layer_without_partitioning_rbsp_idr') {
|
15926 | currentFrame.keyFrame = true;
|
15927 | }
|
15928 | currentFrame.duration = currentNal.dts - currentFrame.dts;
|
15929 | currentFrame.byteLength += currentNal.data.byteLength;
|
15930 | currentFrame.push(currentNal);
|
15931 | }
|
15932 | }
|
15933 |
|
15934 |
|
15935 |
|
15936 | if (frames.length &&
|
15937 | (!currentFrame.duration ||
|
15938 | currentFrame.duration <= 0)) {
|
15939 | currentFrame.duration = frames[frames.length - 1].duration;
|
15940 | }
|
15941 |
|
15942 |
|
15943 | frames.push(currentFrame);
|
15944 | return frames;
|
15945 | };
|
15946 |
|
15947 |
|
15948 |
|
15949 |
|
15950 |
|
15951 | this.groupFramesIntoGops_ = function(frames) {
|
15952 | var
|
15953 | i,
|
15954 | currentFrame,
|
15955 | currentGop = [],
|
15956 | gops = [];
|
15957 |
|
15958 |
|
15959 |
|
15960 | currentGop.byteLength = 0;
|
15961 | currentGop.nalCount = 0;
|
15962 | currentGop.duration = 0;
|
15963 | currentGop.pts = frames[0].pts;
|
15964 | currentGop.dts = frames[0].dts;
|
15965 |
|
15966 |
|
15967 | gops.byteLength = 0;
|
15968 | gops.nalCount = 0;
|
15969 | gops.duration = 0;
|
15970 | gops.pts = frames[0].pts;
|
15971 | gops.dts = frames[0].dts;
|
15972 |
|
15973 | for (i = 0; i < frames.length; i++) {
|
15974 | currentFrame = frames[i];
|
15975 |
|
15976 | if (currentFrame.keyFrame) {
|
15977 |
|
15978 |
|
15979 | if (currentGop.length) {
|
15980 | gops.push(currentGop);
|
15981 | gops.byteLength += currentGop.byteLength;
|
15982 | gops.nalCount += currentGop.nalCount;
|
15983 | gops.duration += currentGop.duration;
|
15984 | }
|
15985 |
|
15986 | currentGop = [currentFrame];
|
15987 | currentGop.nalCount = currentFrame.length;
|
15988 | currentGop.byteLength = currentFrame.byteLength;
|
15989 | currentGop.pts = currentFrame.pts;
|
15990 | currentGop.dts = currentFrame.dts;
|
15991 | currentGop.duration = currentFrame.duration;
|
15992 | } else {
|
15993 | currentGop.duration += currentFrame.duration;
|
15994 | currentGop.nalCount += currentFrame.length;
|
15995 | currentGop.byteLength += currentFrame.byteLength;
|
15996 | currentGop.push(currentFrame);
|
15997 | }
|
15998 | }
|
15999 |
|
16000 | if (gops.length && currentGop.duration <= 0) {
|
16001 | currentGop.duration = gops[gops.length - 1].duration;
|
16002 | }
|
16003 | gops.byteLength += currentGop.byteLength;
|
16004 | gops.nalCount += currentGop.nalCount;
|
16005 | gops.duration += currentGop.duration;
|
16006 |
|
16007 |
|
16008 | gops.push(currentGop);
|
16009 | return gops;
|
16010 | };
|
16011 |
|
16012 |
|
16013 | this.generateSampleTable_ = function(gops, baseDataOffset) {
|
16014 | var
|
16015 | h, i,
|
16016 | sample,
|
16017 | currentGop,
|
16018 | currentFrame,
|
16019 | dataOffset = baseDataOffset || 0,
|
16020 | samples = [];
|
16021 |
|
16022 | for (h = 0; h < gops.length; h++) {
|
16023 | currentGop = gops[h];
|
16024 |
|
16025 | for (i = 0; i < currentGop.length; i++) {
|
16026 | currentFrame = currentGop[i];
|
16027 |
|
16028 | sample = createDefaultSample();
|
16029 |
|
16030 | sample.dataOffset = dataOffset;
|
16031 | sample.compositionTimeOffset = currentFrame.pts - currentFrame.dts;
|
16032 | sample.duration = currentFrame.duration;
|
16033 | sample.size = 4 * currentFrame.length;
|
16034 | sample.size += currentFrame.byteLength;
|
16035 |
|
16036 | if (currentFrame.keyFrame) {
|
16037 | sample.flags.dependsOn = 2;
|
16038 | }
|
16039 |
|
16040 | dataOffset += sample.size;
|
16041 |
|
16042 | samples.push(sample);
|
16043 | }
|
16044 | }
|
16045 | return samples;
|
16046 | };
|
16047 |
|
16048 |
|
16049 | this.concatenateNalData_ = function(gops) {
|
16050 | var
|
16051 | h, i, j,
|
16052 | currentGop,
|
16053 | currentFrame,
|
16054 | currentNal,
|
16055 | dataOffset = 0,
|
16056 | nalsByteLength = gops.byteLength,
|
16057 | numberOfNals = gops.nalCount,
|
16058 | totalByteLength = nalsByteLength + 4 * numberOfNals,
|
16059 | data = new Uint8Array(totalByteLength),
|
16060 | view = new DataView(data.buffer);
|
16061 |
|
16062 |
|
16063 | for (h = 0; h < gops.length; h++) {
|
16064 | currentGop = gops[h];
|
16065 |
|
16066 |
|
16067 | for (i = 0; i < currentGop.length; i++) {
|
16068 | currentFrame = currentGop[i];
|
16069 |
|
16070 |
|
16071 | for (j = 0; j < currentFrame.length; j++) {
|
16072 | currentNal = currentFrame[j];
|
16073 |
|
16074 | view.setUint32(dataOffset, currentNal.data.byteLength);
|
16075 | dataOffset += 4;
|
16076 | data.set(currentNal.data, dataOffset);
|
16077 | dataOffset += currentNal.data.byteLength;
|
16078 | }
|
16079 | }
|
16080 | }
|
16081 | return data;
|
16082 | };
|
16083 |
|
16084 |
|
16085 |
|
16086 | this.alignGopsAtStart_ = function(gops) {
|
16087 | var alignIndex, gopIndex, align, gop, byteLength, nalCount, duration, alignedGops;
|
16088 |
|
16089 | byteLength = gops.byteLength;
|
16090 | nalCount = gops.nalCount;
|
16091 | duration = gops.duration;
|
16092 | alignIndex = gopIndex = 0;
|
16093 |
|
16094 | while (alignIndex < gopsToAlignWith.length && gopIndex < gops.length) {
|
16095 | align = gopsToAlignWith[alignIndex];
|
16096 | gop = gops[gopIndex];
|
16097 |
|
16098 | if (align.pts === gop.pts) {
|
16099 | break;
|
16100 | }
|
16101 |
|
16102 | if (gop.pts > align.pts) {
|
16103 |
|
16104 |
|
16105 | alignIndex++;
|
16106 | continue;
|
16107 | }
|
16108 |
|
16109 |
|
16110 |
|
16111 | gopIndex++;
|
16112 | byteLength -= gop.byteLength;
|
16113 | nalCount -= gop.nalCount;
|
16114 | duration -= gop.duration;
|
16115 | }
|
16116 |
|
16117 | if (gopIndex === 0) {
|
16118 |
|
16119 | return gops;
|
16120 | }
|
16121 |
|
16122 | if (gopIndex === gops.length) {
|
16123 |
|
16124 | return null;
|
16125 | }
|
16126 |
|
16127 | alignedGops = gops.slice(gopIndex);
|
16128 | alignedGops.byteLength = byteLength;
|
16129 | alignedGops.duration = duration;
|
16130 | alignedGops.nalCount = nalCount;
|
16131 | alignedGops.pts = alignedGops[0].pts;
|
16132 | alignedGops.dts = alignedGops[0].dts;
|
16133 |
|
16134 | return alignedGops;
|
16135 | };
|
16136 |
|
16137 |
|
16138 |
|
16139 | this.alignGopsAtEnd_ = function(gops) {
|
16140 | var alignIndex, gopIndex, align, gop, alignEndIndex, matchFound;
|
16141 |
|
16142 | alignIndex = gopsToAlignWith.length - 1;
|
16143 | gopIndex = gops.length - 1;
|
16144 | alignEndIndex = null;
|
16145 | matchFound = false;
|
16146 |
|
16147 | while (alignIndex >= 0 && gopIndex >= 0) {
|
16148 | align = gopsToAlignWith[alignIndex];
|
16149 | gop = gops[gopIndex];
|
16150 |
|
16151 | if (align.pts === gop.pts) {
|
16152 | matchFound = true;
|
16153 | break;
|
16154 | }
|
16155 |
|
16156 | if (align.pts > gop.pts) {
|
16157 | alignIndex--;
|
16158 | continue;
|
16159 | }
|
16160 |
|
16161 | if (alignIndex === gopsToAlignWith.length - 1) {
|
16162 |
|
16163 |
|
16164 |
|
16165 | alignEndIndex = gopIndex;
|
16166 | }
|
16167 |
|
16168 | gopIndex--;
|
16169 | }
|
16170 |
|
16171 | if (!matchFound && alignEndIndex === null) {
|
16172 | return null;
|
16173 | }
|
16174 |
|
16175 | var trimIndex;
|
16176 |
|
16177 | if (matchFound) {
|
16178 | trimIndex = gopIndex;
|
16179 | } else {
|
16180 | trimIndex = alignEndIndex;
|
16181 | }
|
16182 |
|
16183 | if (trimIndex === 0) {
|
16184 | return gops;
|
16185 | }
|
16186 |
|
16187 | var alignedGops = gops.slice(trimIndex);
|
16188 | var metadata = alignedGops.reduce(function(total, gop) {
|
16189 | total.byteLength += gop.byteLength;
|
16190 | total.duration += gop.duration;
|
16191 | total.nalCount += gop.nalCount;
|
16192 | return total;
|
16193 | }, { byteLength: 0, duration: 0, nalCount: 0 });
|
16194 |
|
16195 | alignedGops.byteLength = metadata.byteLength;
|
16196 | alignedGops.duration = metadata.duration;
|
16197 | alignedGops.nalCount = metadata.nalCount;
|
16198 | alignedGops.pts = alignedGops[0].pts;
|
16199 | alignedGops.dts = alignedGops[0].dts;
|
16200 |
|
16201 | return alignedGops;
|
16202 | };
|
16203 |
|
16204 | this.alignGopsWith = function(newGopsToAlignWith) {
|
16205 | gopsToAlignWith = newGopsToAlignWith;
|
16206 | };
|
16207 | };
|
16208 |
|
16209 | VideoSegmentStream.prototype = new Stream();
|
16210 |
|
16211 |
|
16212 |
|
16213 |
|
16214 |
|
16215 |
|
16216 | collectDtsInfo = function(track, data) {
|
16217 | if (typeof data.pts === 'number') {
|
16218 | if (track.timelineStartInfo.pts === undefined) {
|
16219 | track.timelineStartInfo.pts = data.pts;
|
16220 | }
|
16221 |
|
16222 | if (track.minSegmentPts === undefined) {
|
16223 | track.minSegmentPts = data.pts;
|
16224 | } else {
|
16225 | track.minSegmentPts = Math.min(track.minSegmentPts, data.pts);
|
16226 | }
|
16227 |
|
16228 | if (track.maxSegmentPts === undefined) {
|
16229 | track.maxSegmentPts = data.pts;
|
16230 | } else {
|
16231 | track.maxSegmentPts = Math.max(track.maxSegmentPts, data.pts);
|
16232 | }
|
16233 | }
|
16234 |
|
16235 | if (typeof data.dts === 'number') {
|
16236 | if (track.timelineStartInfo.dts === undefined) {
|
16237 | track.timelineStartInfo.dts = data.dts;
|
16238 | }
|
16239 |
|
16240 | if (track.minSegmentDts === undefined) {
|
16241 | track.minSegmentDts = data.dts;
|
16242 | } else {
|
16243 | track.minSegmentDts = Math.min(track.minSegmentDts, data.dts);
|
16244 | }
|
16245 |
|
16246 | if (track.maxSegmentDts === undefined) {
|
16247 | track.maxSegmentDts = data.dts;
|
16248 | } else {
|
16249 | track.maxSegmentDts = Math.max(track.maxSegmentDts, data.dts);
|
16250 | }
|
16251 | }
|
16252 | };
|
16253 |
|
16254 |
|
16255 |
|
16256 |
|
16257 |
|
16258 | clearDtsInfo = function(track) {
|
16259 | delete track.minSegmentDts;
|
16260 | delete track.maxSegmentDts;
|
16261 | delete track.minSegmentPts;
|
16262 | delete track.maxSegmentPts;
|
16263 | };
|
16264 |
|
16265 |
|
16266 |
|
16267 |
|
16268 |
|
16269 |
|
16270 | calculateTrackBaseMediaDecodeTime = function(track) {
|
16271 | var
|
16272 | baseMediaDecodeTime,
|
16273 | scale,
|
16274 |
|
16275 |
|
16276 | timeSinceStartOfTimeline = track.minSegmentDts - track.timelineStartInfo.dts;
|
16277 |
|
16278 |
|
16279 |
|
16280 | baseMediaDecodeTime = track.timelineStartInfo.baseMediaDecodeTime;
|
16281 |
|
16282 |
|
16283 | baseMediaDecodeTime += timeSinceStartOfTimeline;
|
16284 |
|
16285 |
|
16286 | baseMediaDecodeTime = Math.max(0, baseMediaDecodeTime);
|
16287 |
|
16288 | if (track.type === 'audio') {
|
16289 |
|
16290 |
|
16291 | scale = track.samplerate / ONE_SECOND_IN_TS;
|
16292 | baseMediaDecodeTime *= scale;
|
16293 | baseMediaDecodeTime = Math.floor(baseMediaDecodeTime);
|
16294 | }
|
16295 |
|
16296 | return baseMediaDecodeTime;
|
16297 | };
|
16298 |
|
16299 |
|
16300 |
|
16301 |
|
16302 |
|
16303 |
|
16304 | CoalesceStream = function(options, metadataStream) {
|
16305 |
|
16306 |
|
16307 |
|
16308 | this.numberOfTracks = 0;
|
16309 | this.metadataStream = metadataStream;
|
16310 |
|
16311 | if (typeof options.remux !== 'undefined') {
|
16312 | this.remuxTracks = !!options.remux;
|
16313 | } else {
|
16314 | this.remuxTracks = true;
|
16315 | }
|
16316 |
|
16317 | this.pendingTracks = [];
|
16318 | this.videoTrack = null;
|
16319 | this.pendingBoxes = [];
|
16320 | this.pendingCaptions = [];
|
16321 | this.pendingMetadata = [];
|
16322 | this.pendingBytes = 0;
|
16323 | this.emittedTracks = 0;
|
16324 |
|
16325 | CoalesceStream.prototype.init.call(this);
|
16326 |
|
16327 |
|
16328 | this.push = function(output) {
|
16329 |
|
16330 |
|
16331 | if (output.text) {
|
16332 | return this.pendingCaptions.push(output);
|
16333 | }
|
16334 |
|
16335 | if (output.frames) {
|
16336 | return this.pendingMetadata.push(output);
|
16337 | }
|
16338 |
|
16339 |
|
16340 |
|
16341 |
|
16342 | this.pendingTracks.push(output.track);
|
16343 | this.pendingBoxes.push(output.boxes);
|
16344 | this.pendingBytes += output.boxes.byteLength;
|
16345 |
|
16346 | if (output.track.type === 'video') {
|
16347 | this.videoTrack = output.track;
|
16348 | }
|
16349 | if (output.track.type === 'audio') {
|
16350 | this.audioTrack = output.track;
|
16351 | }
|
16352 | };
|
16353 | };
|
16354 |
|
16355 | CoalesceStream.prototype = new Stream();
|
16356 | CoalesceStream.prototype.flush = function(flushSource) {
|
16357 | var
|
16358 | offset = 0,
|
16359 | event = {
|
16360 | captions: [],
|
16361 | captionStreams: {},
|
16362 | metadata: [],
|
16363 | info: {}
|
16364 | },
|
16365 | caption,
|
16366 | id3,
|
16367 | initSegment,
|
16368 | timelineStartPts = 0,
|
16369 | i;
|
16370 |
|
16371 | if (this.pendingTracks.length < this.numberOfTracks) {
|
16372 | if (flushSource !== 'VideoSegmentStream' &&
|
16373 | flushSource !== 'AudioSegmentStream') {
|
16374 |
|
16375 |
|
16376 |
|
16377 | return;
|
16378 | } else if (this.remuxTracks) {
|
16379 |
|
16380 |
|
16381 | return;
|
16382 | } else if (this.pendingTracks.length === 0) {
|
16383 |
|
16384 |
|
16385 |
|
16386 |
|
16387 |
|
16388 |
|
16389 | this.emittedTracks++;
|
16390 |
|
16391 | if (this.emittedTracks >= this.numberOfTracks) {
|
16392 | this.trigger('done');
|
16393 | this.emittedTracks = 0;
|
16394 | }
|
16395 | return;
|
16396 | }
|
16397 | }
|
16398 |
|
16399 | if (this.videoTrack) {
|
16400 | timelineStartPts = this.videoTrack.timelineStartInfo.pts;
|
16401 | VIDEO_PROPERTIES.forEach(function(prop) {
|
16402 | event.info[prop] = this.videoTrack[prop];
|
16403 | }, this);
|
16404 | } else if (this.audioTrack) {
|
16405 | timelineStartPts = this.audioTrack.timelineStartInfo.pts;
|
16406 | AUDIO_PROPERTIES.forEach(function(prop) {
|
16407 | event.info[prop] = this.audioTrack[prop];
|
16408 | }, this);
|
16409 | }
|
16410 |
|
16411 | if (this.pendingTracks.length === 1) {
|
16412 | event.type = this.pendingTracks[0].type;
|
16413 | } else {
|
16414 | event.type = 'combined';
|
16415 | }
|
16416 |
|
16417 | this.emittedTracks += this.pendingTracks.length;
|
16418 |
|
16419 | initSegment = mp4.initSegment(this.pendingTracks);
|
16420 |
|
16421 |
|
16422 | event.initSegment = new Uint8Array(initSegment.byteLength);
|
16423 |
|
16424 |
|
16425 |
|
16426 | event.initSegment.set(initSegment);
|
16427 |
|
16428 |
|
16429 | event.data = new Uint8Array(this.pendingBytes);
|
16430 |
|
16431 |
|
16432 | for (i = 0; i < this.pendingBoxes.length; i++) {
|
16433 | event.data.set(this.pendingBoxes[i], offset);
|
16434 | offset += this.pendingBoxes[i].byteLength;
|
16435 | }
|
16436 |
|
16437 |
|
16438 |
|
16439 | for (i = 0; i < this.pendingCaptions.length; i++) {
|
16440 | caption = this.pendingCaptions[i];
|
16441 | caption.startTime = (caption.startPts - timelineStartPts);
|
16442 | caption.startTime /= 90e3;
|
16443 | caption.endTime = (caption.endPts - timelineStartPts);
|
16444 | caption.endTime /= 90e3;
|
16445 | event.captionStreams[caption.stream] = true;
|
16446 | event.captions.push(caption);
|
16447 | }
|
16448 |
|
16449 |
|
16450 |
|
16451 | for (i = 0; i < this.pendingMetadata.length; i++) {
|
16452 | id3 = this.pendingMetadata[i];
|
16453 | id3.cueTime = (id3.pts - timelineStartPts);
|
16454 | id3.cueTime /= 90e3;
|
16455 | event.metadata.push(id3);
|
16456 | }
|
16457 |
|
16458 |
|
16459 | event.metadata.dispatchType = this.metadataStream.dispatchType;
|
16460 |
|
16461 |
|
16462 | this.pendingTracks.length = 0;
|
16463 | this.videoTrack = null;
|
16464 | this.pendingBoxes.length = 0;
|
16465 | this.pendingCaptions.length = 0;
|
16466 | this.pendingBytes = 0;
|
16467 | this.pendingMetadata.length = 0;
|
16468 |
|
16469 |
|
16470 | this.trigger('data', event);
|
16471 |
|
16472 |
|
16473 | if (this.emittedTracks >= this.numberOfTracks) {
|
16474 | this.trigger('done');
|
16475 | this.emittedTracks = 0;
|
16476 | }
|
16477 | };
|
16478 |
|
16479 |
|
16480 |
|
16481 |
|
16482 |
|
16483 |
|
16484 | Transmuxer = function(options) {
|
16485 | var
|
16486 | self = this,
|
16487 | hasFlushed = true,
|
16488 | videoTrack,
|
16489 | audioTrack;
|
16490 |
|
16491 | Transmuxer.prototype.init.call(this);
|
16492 |
|
16493 | options = options || {};
|
16494 | this.baseMediaDecodeTime = options.baseMediaDecodeTime || 0;
|
16495 | this.transmuxPipeline_ = {};
|
16496 |
|
16497 | this.setupAacPipeline = function() {
|
16498 | var pipeline = {};
|
16499 | this.transmuxPipeline_ = pipeline;
|
16500 |
|
16501 | pipeline.type = 'aac';
|
16502 | pipeline.metadataStream = new m2ts.MetadataStream();
|
16503 |
|
16504 |
|
16505 | pipeline.aacStream = new AacStream();
|
16506 | pipeline.audioTimestampRolloverStream = new m2ts.TimestampRolloverStream('audio');
|
16507 | pipeline.timedMetadataTimestampRolloverStream = new m2ts.TimestampRolloverStream('timed-metadata');
|
16508 | pipeline.adtsStream = new AdtsStream();
|
16509 | pipeline.coalesceStream = new CoalesceStream(options, pipeline.metadataStream);
|
16510 | pipeline.headOfPipeline = pipeline.aacStream;
|
16511 |
|
16512 | pipeline.aacStream
|
16513 | .pipe(pipeline.audioTimestampRolloverStream)
|
16514 | .pipe(pipeline.adtsStream);
|
16515 | pipeline.aacStream
|
16516 | .pipe(pipeline.timedMetadataTimestampRolloverStream)
|
16517 | .pipe(pipeline.metadataStream)
|
16518 | .pipe(pipeline.coalesceStream);
|
16519 |
|
16520 | pipeline.metadataStream.on('timestamp', function(frame) {
|
16521 | pipeline.aacStream.setTimestamp(frame.timeStamp);
|
16522 | });
|
16523 |
|
16524 | pipeline.aacStream.on('data', function(data) {
|
16525 | if (data.type === 'timed-metadata' && !pipeline.audioSegmentStream) {
|
16526 | audioTrack = audioTrack || {
|
16527 | timelineStartInfo: {
|
16528 | baseMediaDecodeTime: self.baseMediaDecodeTime
|
16529 | },
|
16530 | codec: 'adts',
|
16531 | type: 'audio'
|
16532 | };
|
16533 |
|
16534 | pipeline.coalesceStream.numberOfTracks++;
|
16535 | pipeline.audioSegmentStream = new AudioSegmentStream(audioTrack);
|
16536 |
|
16537 | pipeline.adtsStream
|
16538 | .pipe(pipeline.audioSegmentStream)
|
16539 | .pipe(pipeline.coalesceStream);
|
16540 | }
|
16541 | });
|
16542 |
|
16543 |
|
16544 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
16545 |
|
16546 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
16547 | };
|
16548 |
|
16549 | this.setupTsPipeline = function() {
|
16550 | var pipeline = {};
|
16551 | this.transmuxPipeline_ = pipeline;
|
16552 |
|
16553 | pipeline.type = 'ts';
|
16554 | pipeline.metadataStream = new m2ts.MetadataStream();
|
16555 |
|
16556 |
|
16557 | pipeline.packetStream = new m2ts.TransportPacketStream();
|
16558 | pipeline.parseStream = new m2ts.TransportParseStream();
|
16559 | pipeline.elementaryStream = new m2ts.ElementaryStream();
|
16560 | pipeline.videoTimestampRolloverStream = new m2ts.TimestampRolloverStream('video');
|
16561 | pipeline.audioTimestampRolloverStream = new m2ts.TimestampRolloverStream('audio');
|
16562 | pipeline.timedMetadataTimestampRolloverStream = new m2ts.TimestampRolloverStream('timed-metadata');
|
16563 | pipeline.adtsStream = new AdtsStream();
|
16564 | pipeline.h264Stream = new H264Stream();
|
16565 | pipeline.captionStream = new m2ts.CaptionStream();
|
16566 | pipeline.coalesceStream = new CoalesceStream(options, pipeline.metadataStream);
|
16567 | pipeline.headOfPipeline = pipeline.packetStream;
|
16568 |
|
16569 |
|
16570 | pipeline.packetStream
|
16571 | .pipe(pipeline.parseStream)
|
16572 | .pipe(pipeline.elementaryStream);
|
16573 |
|
16574 |
|
16575 |
|
16576 | pipeline.elementaryStream
|
16577 | .pipe(pipeline.videoTimestampRolloverStream)
|
16578 | .pipe(pipeline.h264Stream);
|
16579 | pipeline.elementaryStream
|
16580 | .pipe(pipeline.audioTimestampRolloverStream)
|
16581 | .pipe(pipeline.adtsStream);
|
16582 |
|
16583 | pipeline.elementaryStream
|
16584 | .pipe(pipeline.timedMetadataTimestampRolloverStream)
|
16585 | .pipe(pipeline.metadataStream)
|
16586 | .pipe(pipeline.coalesceStream);
|
16587 |
|
16588 |
|
16589 | pipeline.h264Stream.pipe(pipeline.captionStream)
|
16590 | .pipe(pipeline.coalesceStream);
|
16591 |
|
16592 | pipeline.elementaryStream.on('data', function(data) {
|
16593 | var i;
|
16594 |
|
16595 | if (data.type === 'metadata') {
|
16596 | i = data.tracks.length;
|
16597 |
|
16598 |
|
16599 | while (i--) {
|
16600 | if (!videoTrack && data.tracks[i].type === 'video') {
|
16601 | videoTrack = data.tracks[i];
|
16602 | videoTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
16603 | } else if (!audioTrack && data.tracks[i].type === 'audio') {
|
16604 | audioTrack = data.tracks[i];
|
16605 | audioTrack.timelineStartInfo.baseMediaDecodeTime = self.baseMediaDecodeTime;
|
16606 | }
|
16607 | }
|
16608 |
|
16609 |
|
16610 | if (videoTrack && !pipeline.videoSegmentStream) {
|
16611 | pipeline.coalesceStream.numberOfTracks++;
|
16612 | pipeline.videoSegmentStream = new VideoSegmentStream(videoTrack, options);
|
16613 |
|
16614 | pipeline.videoSegmentStream.on('timelineStartInfo', function(timelineStartInfo) {
|
16615 |
|
16616 |
|
16617 |
|
16618 | if (audioTrack) {
|
16619 | audioTrack.timelineStartInfo = timelineStartInfo;
|
16620 |
|
16621 |
|
16622 |
|
16623 |
|
16624 | pipeline.audioSegmentStream.setEarliestDts(timelineStartInfo.dts);
|
16625 | }
|
16626 | });
|
16627 |
|
16628 | pipeline.videoSegmentStream.on('processedGopsInfo',
|
16629 | self.trigger.bind(self, 'gopInfo'));
|
16630 |
|
16631 | pipeline.videoSegmentStream.on('baseMediaDecodeTime', function(baseMediaDecodeTime) {
|
16632 | if (audioTrack) {
|
16633 | pipeline.audioSegmentStream.setVideoBaseMediaDecodeTime(baseMediaDecodeTime);
|
16634 | }
|
16635 | });
|
16636 |
|
16637 |
|
16638 | pipeline.h264Stream
|
16639 | .pipe(pipeline.videoSegmentStream)
|
16640 | .pipe(pipeline.coalesceStream);
|
16641 | }
|
16642 |
|
16643 | if (audioTrack && !pipeline.audioSegmentStream) {
|
16644 |
|
16645 | pipeline.coalesceStream.numberOfTracks++;
|
16646 | pipeline.audioSegmentStream = new AudioSegmentStream(audioTrack);
|
16647 |
|
16648 |
|
16649 | pipeline.adtsStream
|
16650 | .pipe(pipeline.audioSegmentStream)
|
16651 | .pipe(pipeline.coalesceStream);
|
16652 | }
|
16653 | }
|
16654 | });
|
16655 |
|
16656 |
|
16657 | pipeline.coalesceStream.on('data', this.trigger.bind(this, 'data'));
|
16658 |
|
16659 | pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
|
16660 | };
|
16661 |
|
16662 |
|
16663 | this.setBaseMediaDecodeTime = function(baseMediaDecodeTime) {
|
16664 | var pipeline = this.transmuxPipeline_;
|
16665 |
|
16666 | this.baseMediaDecodeTime = baseMediaDecodeTime;
|
16667 | if (audioTrack) {
|
16668 | audioTrack.timelineStartInfo.dts = undefined;
|
16669 | audioTrack.timelineStartInfo.pts = undefined;
|
16670 | clearDtsInfo(audioTrack);
|
16671 | audioTrack.timelineStartInfo.baseMediaDecodeTime = baseMediaDecodeTime;
|
16672 | if (pipeline.audioTimestampRolloverStream) {
|
16673 | pipeline.audioTimestampRolloverStream.discontinuity();
|
16674 | }
|
16675 | }
|
16676 | if (videoTrack) {
|
16677 | if (pipeline.videoSegmentStream) {
|
16678 | pipeline.videoSegmentStream.gopCache_ = [];
|
16679 | pipeline.videoTimestampRolloverStream.discontinuity();
|
16680 | }
|
16681 | videoTrack.timelineStartInfo.dts = undefined;
|
16682 | videoTrack.timelineStartInfo.pts = undefined;
|
16683 | clearDtsInfo(videoTrack);
|
16684 | pipeline.captionStream.reset();
|
16685 | videoTrack.timelineStartInfo.baseMediaDecodeTime = baseMediaDecodeTime;
|
16686 | }
|
16687 |
|
16688 | if (pipeline.timedMetadataTimestampRolloverStream) {
|
16689 | pipeline.timedMetadataTimestampRolloverStream.discontinuity();
|
16690 | }
|
16691 | };
|
16692 |
|
16693 | this.setAudioAppendStart = function(timestamp) {
|
16694 | if (audioTrack) {
|
16695 | this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(timestamp);
|
16696 | }
|
16697 | };
|
16698 |
|
16699 | this.alignGopsWith = function(gopsToAlignWith) {
|
16700 | if (videoTrack && this.transmuxPipeline_.videoSegmentStream) {
|
16701 | this.transmuxPipeline_.videoSegmentStream.alignGopsWith(gopsToAlignWith);
|
16702 | }
|
16703 | };
|
16704 |
|
16705 |
|
16706 | this.push = function(data) {
|
16707 | if (hasFlushed) {
|
16708 | var isAac = isLikelyAacData(data);
|
16709 |
|
16710 | if (isAac && this.transmuxPipeline_.type !== 'aac') {
|
16711 | this.setupAacPipeline();
|
16712 | } else if (!isAac && this.transmuxPipeline_.type !== 'ts') {
|
16713 | this.setupTsPipeline();
|
16714 | }
|
16715 | hasFlushed = false;
|
16716 | }
|
16717 | this.transmuxPipeline_.headOfPipeline.push(data);
|
16718 | };
|
16719 |
|
16720 |
|
16721 | this.flush = function() {
|
16722 | hasFlushed = true;
|
16723 |
|
16724 | this.transmuxPipeline_.headOfPipeline.flush();
|
16725 | };
|
16726 |
|
16727 |
|
16728 | this.resetCaptions = function() {
|
16729 | if (this.transmuxPipeline_.captionStream) {
|
16730 | this.transmuxPipeline_.captionStream.reset();
|
16731 | }
|
16732 | };
|
16733 |
|
16734 | };
|
16735 | Transmuxer.prototype = new Stream();
|
16736 |
|
16737 | module.exports = {
|
16738 | Transmuxer: Transmuxer,
|
16739 | VideoSegmentStream: VideoSegmentStream,
|
16740 | AudioSegmentStream: AudioSegmentStream,
|
16741 | AUDIO_PROPERTIES: AUDIO_PROPERTIES,
|
16742 | VIDEO_PROPERTIES: VIDEO_PROPERTIES
|
16743 | };
|
16744 |
|
16745 | },{"../aac":38,"../codecs/adts.js":40,"../codecs/h264":41,"../data/silence":42,"../m2ts/m2ts.js":50,"../utils/clock":60,"../utils/stream.js":62,"./mp4-generator.js":56}],59:[function(require,module,exports){
|
16746 |
|
16747 |
|
16748 |
|
16749 |
|
16750 |
|
16751 |
|
16752 |
|
16753 |
|
16754 | 'use strict';
|
16755 |
|
16756 | var StreamTypes = require('../m2ts/stream-types.js');
|
16757 | var handleRollover = require('../m2ts/timestamp-rollover-stream.js').handleRollover;
|
16758 | var probe = {};
|
16759 | probe.ts = require('../m2ts/probe.js');
|
16760 | probe.aac = require('../aac/probe.js');
|
16761 |
|
16762 |
|
16763 | var
|
16764 | PES_TIMESCALE = 90000,
|
16765 | MP2T_PACKET_LENGTH = 188,
|
16766 | SYNC_BYTE = 0x47;
|
16767 |
|
16768 | var isLikelyAacData = function(data) {
|
16769 | if ((data[0] === 'I'.charCodeAt(0)) &&
|
16770 | (data[1] === 'D'.charCodeAt(0)) &&
|
16771 | (data[2] === '3'.charCodeAt(0))) {
|
16772 | return true;
|
16773 | }
|
16774 | return false;
|
16775 | };
|
16776 |
|
16777 |
|
16778 |
|
16779 |
|
16780 |
|
16781 | var parsePsi_ = function(bytes, pmt) {
|
16782 | var
|
16783 | startIndex = 0,
|
16784 | endIndex = MP2T_PACKET_LENGTH,
|
16785 | packet, type;
|
16786 |
|
16787 | while (endIndex < bytes.byteLength) {
|
16788 |
|
16789 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
16790 |
|
16791 | packet = bytes.subarray(startIndex, endIndex);
|
16792 | type = probe.ts.parseType(packet, pmt.pid);
|
16793 |
|
16794 | switch (type) {
|
16795 | case 'pat':
|
16796 | if (!pmt.pid) {
|
16797 | pmt.pid = probe.ts.parsePat(packet);
|
16798 | }
|
16799 | break;
|
16800 | case 'pmt':
|
16801 | if (!pmt.table) {
|
16802 | pmt.table = probe.ts.parsePmt(packet);
|
16803 | }
|
16804 | break;
|
16805 | default:
|
16806 | break;
|
16807 | }
|
16808 |
|
16809 |
|
16810 | if (pmt.pid && pmt.table) {
|
16811 | return;
|
16812 | }
|
16813 |
|
16814 | startIndex += MP2T_PACKET_LENGTH;
|
16815 | endIndex += MP2T_PACKET_LENGTH;
|
16816 | continue;
|
16817 | }
|
16818 |
|
16819 |
|
16820 |
|
16821 |
|
16822 | startIndex++;
|
16823 | endIndex++;
|
16824 | }
|
16825 | };
|
16826 |
|
16827 |
|
16828 |
|
16829 |
|
16830 |
|
16831 | var parseAudioPes_ = function(bytes, pmt, result) {
|
16832 | var
|
16833 | startIndex = 0,
|
16834 | endIndex = MP2T_PACKET_LENGTH,
|
16835 | packet, type, pesType, pusi, parsed;
|
16836 |
|
16837 | var endLoop = false;
|
16838 |
|
16839 |
|
16840 | while (endIndex < bytes.byteLength) {
|
16841 |
|
16842 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
16843 |
|
16844 | packet = bytes.subarray(startIndex, endIndex);
|
16845 | type = probe.ts.parseType(packet, pmt.pid);
|
16846 |
|
16847 | switch (type) {
|
16848 | case 'pes':
|
16849 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
16850 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
16851 | if (pesType === 'audio' && pusi) {
|
16852 | parsed = probe.ts.parsePesTime(packet);
|
16853 | if (parsed) {
|
16854 | parsed.type = 'audio';
|
16855 | result.audio.push(parsed);
|
16856 | endLoop = true;
|
16857 | }
|
16858 | }
|
16859 | break;
|
16860 | default:
|
16861 | break;
|
16862 | }
|
16863 |
|
16864 | if (endLoop) {
|
16865 | break;
|
16866 | }
|
16867 |
|
16868 | startIndex += MP2T_PACKET_LENGTH;
|
16869 | endIndex += MP2T_PACKET_LENGTH;
|
16870 | continue;
|
16871 | }
|
16872 |
|
16873 |
|
16874 |
|
16875 |
|
16876 | startIndex++;
|
16877 | endIndex++;
|
16878 | }
|
16879 |
|
16880 |
|
16881 | endIndex = bytes.byteLength;
|
16882 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
16883 | endLoop = false;
|
16884 | while (startIndex >= 0) {
|
16885 |
|
16886 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
16887 |
|
16888 | packet = bytes.subarray(startIndex, endIndex);
|
16889 | type = probe.ts.parseType(packet, pmt.pid);
|
16890 |
|
16891 | switch (type) {
|
16892 | case 'pes':
|
16893 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
16894 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
16895 | if (pesType === 'audio' && pusi) {
|
16896 | parsed = probe.ts.parsePesTime(packet);
|
16897 | if (parsed) {
|
16898 | parsed.type = 'audio';
|
16899 | result.audio.push(parsed);
|
16900 | endLoop = true;
|
16901 | }
|
16902 | }
|
16903 | break;
|
16904 | default:
|
16905 | break;
|
16906 | }
|
16907 |
|
16908 | if (endLoop) {
|
16909 | break;
|
16910 | }
|
16911 |
|
16912 | startIndex -= MP2T_PACKET_LENGTH;
|
16913 | endIndex -= MP2T_PACKET_LENGTH;
|
16914 | continue;
|
16915 | }
|
16916 |
|
16917 |
|
16918 |
|
16919 |
|
16920 | startIndex--;
|
16921 | endIndex--;
|
16922 | }
|
16923 | };
|
16924 |
|
16925 |
|
16926 |
|
16927 |
|
16928 |
|
16929 |
|
16930 | var parseVideoPes_ = function(bytes, pmt, result) {
|
16931 | var
|
16932 | startIndex = 0,
|
16933 | endIndex = MP2T_PACKET_LENGTH,
|
16934 | packet, type, pesType, pusi, parsed, frame, i, pes;
|
16935 |
|
16936 | var endLoop = false;
|
16937 |
|
16938 | var currentFrame = {
|
16939 | data: [],
|
16940 | size: 0
|
16941 | };
|
16942 |
|
16943 |
|
16944 | while (endIndex < bytes.byteLength) {
|
16945 |
|
16946 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
16947 |
|
16948 | packet = bytes.subarray(startIndex, endIndex);
|
16949 | type = probe.ts.parseType(packet, pmt.pid);
|
16950 |
|
16951 | switch (type) {
|
16952 | case 'pes':
|
16953 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
16954 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
16955 | if (pesType === 'video') {
|
16956 | if (pusi && !endLoop) {
|
16957 | parsed = probe.ts.parsePesTime(packet);
|
16958 | if (parsed) {
|
16959 | parsed.type = 'video';
|
16960 | result.video.push(parsed);
|
16961 | endLoop = true;
|
16962 | }
|
16963 | }
|
16964 | if (!result.firstKeyFrame) {
|
16965 | if (pusi) {
|
16966 | if (currentFrame.size !== 0) {
|
16967 | frame = new Uint8Array(currentFrame.size);
|
16968 | i = 0;
|
16969 | while (currentFrame.data.length) {
|
16970 | pes = currentFrame.data.shift();
|
16971 | frame.set(pes, i);
|
16972 | i += pes.byteLength;
|
16973 | }
|
16974 | if (probe.ts.videoPacketContainsKeyFrame(frame)) {
|
16975 | result.firstKeyFrame = probe.ts.parsePesTime(frame);
|
16976 | result.firstKeyFrame.type = 'video';
|
16977 | }
|
16978 | currentFrame.size = 0;
|
16979 | }
|
16980 | }
|
16981 | currentFrame.data.push(packet);
|
16982 | currentFrame.size += packet.byteLength;
|
16983 | }
|
16984 | }
|
16985 | break;
|
16986 | default:
|
16987 | break;
|
16988 | }
|
16989 |
|
16990 | if (endLoop && result.firstKeyFrame) {
|
16991 | break;
|
16992 | }
|
16993 |
|
16994 | startIndex += MP2T_PACKET_LENGTH;
|
16995 | endIndex += MP2T_PACKET_LENGTH;
|
16996 | continue;
|
16997 | }
|
16998 |
|
16999 |
|
17000 |
|
17001 |
|
17002 | startIndex++;
|
17003 | endIndex++;
|
17004 | }
|
17005 |
|
17006 |
|
17007 | endIndex = bytes.byteLength;
|
17008 | startIndex = endIndex - MP2T_PACKET_LENGTH;
|
17009 | endLoop = false;
|
17010 | while (startIndex >= 0) {
|
17011 |
|
17012 | if (bytes[startIndex] === SYNC_BYTE && bytes[endIndex] === SYNC_BYTE) {
|
17013 |
|
17014 | packet = bytes.subarray(startIndex, endIndex);
|
17015 | type = probe.ts.parseType(packet, pmt.pid);
|
17016 |
|
17017 | switch (type) {
|
17018 | case 'pes':
|
17019 | pesType = probe.ts.parsePesType(packet, pmt.table);
|
17020 | pusi = probe.ts.parsePayloadUnitStartIndicator(packet);
|
17021 | if (pesType === 'video' && pusi) {
|
17022 | parsed = probe.ts.parsePesTime(packet);
|
17023 | if (parsed) {
|
17024 | parsed.type = 'video';
|
17025 | result.video.push(parsed);
|
17026 | endLoop = true;
|
17027 | }
|
17028 | }
|
17029 | break;
|
17030 | default:
|
17031 | break;
|
17032 | }
|
17033 |
|
17034 | if (endLoop) {
|
17035 | break;
|
17036 | }
|
17037 |
|
17038 | startIndex -= MP2T_PACKET_LENGTH;
|
17039 | endIndex -= MP2T_PACKET_LENGTH;
|
17040 | continue;
|
17041 | }
|
17042 |
|
17043 |
|
17044 |
|
17045 |
|
17046 | startIndex--;
|
17047 | endIndex--;
|
17048 | }
|
17049 | };
|
17050 |
|
17051 |
|
17052 |
|
17053 |
|
17054 |
|
17055 | var adjustTimestamp_ = function(segmentInfo, baseTimestamp) {
|
17056 | if (segmentInfo.audio && segmentInfo.audio.length) {
|
17057 | var audioBaseTimestamp = baseTimestamp;
|
17058 | if (typeof audioBaseTimestamp === 'undefined') {
|
17059 | audioBaseTimestamp = segmentInfo.audio[0].dts;
|
17060 | }
|
17061 | segmentInfo.audio.forEach(function(info) {
|
17062 | info.dts = handleRollover(info.dts, audioBaseTimestamp);
|
17063 | info.pts = handleRollover(info.pts, audioBaseTimestamp);
|
17064 |
|
17065 | info.dtsTime = info.dts / PES_TIMESCALE;
|
17066 | info.ptsTime = info.pts / PES_TIMESCALE;
|
17067 | });
|
17068 | }
|
17069 |
|
17070 | if (segmentInfo.video && segmentInfo.video.length) {
|
17071 | var videoBaseTimestamp = baseTimestamp;
|
17072 | if (typeof videoBaseTimestamp === 'undefined') {
|
17073 | videoBaseTimestamp = segmentInfo.video[0].dts;
|
17074 | }
|
17075 | segmentInfo.video.forEach(function(info) {
|
17076 | info.dts = handleRollover(info.dts, videoBaseTimestamp);
|
17077 | info.pts = handleRollover(info.pts, videoBaseTimestamp);
|
17078 |
|
17079 | info.dtsTime = info.dts / PES_TIMESCALE;
|
17080 | info.ptsTime = info.pts / PES_TIMESCALE;
|
17081 | });
|
17082 | if (segmentInfo.firstKeyFrame) {
|
17083 | var frame = segmentInfo.firstKeyFrame;
|
17084 | frame.dts = handleRollover(frame.dts, videoBaseTimestamp);
|
17085 | frame.pts = handleRollover(frame.pts, videoBaseTimestamp);
|
17086 |
|
17087 | frame.dtsTime = frame.dts / PES_TIMESCALE;
|
17088 | frame.ptsTime = frame.dts / PES_TIMESCALE;
|
17089 | }
|
17090 | }
|
17091 | };
|
17092 |
|
17093 |
|
17094 |
|
17095 |
|
17096 | var inspectAac_ = function(bytes) {
|
17097 | var
|
17098 | endLoop = false,
|
17099 | audioCount = 0,
|
17100 | sampleRate = null,
|
17101 | timestamp = null,
|
17102 | frameSize = 0,
|
17103 | byteIndex = 0,
|
17104 | packet;
|
17105 |
|
17106 | while (bytes.length - byteIndex >= 3) {
|
17107 | var type = probe.aac.parseType(bytes, byteIndex);
|
17108 | switch (type) {
|
17109 | case 'timed-metadata':
|
17110 |
|
17111 |
|
17112 | if (bytes.length - byteIndex < 10) {
|
17113 | endLoop = true;
|
17114 | break;
|
17115 | }
|
17116 |
|
17117 | frameSize = probe.aac.parseId3TagSize(bytes, byteIndex);
|
17118 |
|
17119 |
|
17120 |
|
17121 | if (frameSize > bytes.length) {
|
17122 | endLoop = true;
|
17123 | break;
|
17124 | }
|
17125 | if (timestamp === null) {
|
17126 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
17127 | timestamp = probe.aac.parseAacTimestamp(packet);
|
17128 | }
|
17129 | byteIndex += frameSize;
|
17130 | break;
|
17131 | case 'audio':
|
17132 |
|
17133 |
|
17134 | if (bytes.length - byteIndex < 7) {
|
17135 | endLoop = true;
|
17136 | break;
|
17137 | }
|
17138 |
|
17139 | frameSize = probe.aac.parseAdtsSize(bytes, byteIndex);
|
17140 |
|
17141 |
|
17142 |
|
17143 | if (frameSize > bytes.length) {
|
17144 | endLoop = true;
|
17145 | break;
|
17146 | }
|
17147 | if (sampleRate === null) {
|
17148 | packet = bytes.subarray(byteIndex, byteIndex + frameSize);
|
17149 | sampleRate = probe.aac.parseSampleRate(packet);
|
17150 | }
|
17151 | audioCount++;
|
17152 | byteIndex += frameSize;
|
17153 | break;
|
17154 | default:
|
17155 | byteIndex++;
|
17156 | break;
|
17157 | }
|
17158 | if (endLoop) {
|
17159 | return null;
|
17160 | }
|
17161 | }
|
17162 | if (sampleRate === null || timestamp === null) {
|
17163 | return null;
|
17164 | }
|
17165 |
|
17166 | var audioTimescale = PES_TIMESCALE / sampleRate;
|
17167 |
|
17168 | var result = {
|
17169 | audio: [
|
17170 | {
|
17171 | type: 'audio',
|
17172 | dts: timestamp,
|
17173 | pts: timestamp
|
17174 | },
|
17175 | {
|
17176 | type: 'audio',
|
17177 | dts: timestamp + (audioCount * 1024 * audioTimescale),
|
17178 | pts: timestamp + (audioCount * 1024 * audioTimescale)
|
17179 | }
|
17180 | ]
|
17181 | };
|
17182 |
|
17183 | return result;
|
17184 | };
|
17185 |
|
17186 |
|
17187 |
|
17188 |
|
17189 |
|
17190 |
|
17191 | var inspectTs_ = function(bytes) {
|
17192 | var pmt = {
|
17193 | pid: null,
|
17194 | table: null
|
17195 | };
|
17196 |
|
17197 | var result = {};
|
17198 |
|
17199 | parsePsi_(bytes, pmt);
|
17200 |
|
17201 | for (var pid in pmt.table) {
|
17202 | if (pmt.table.hasOwnProperty(pid)) {
|
17203 | var type = pmt.table[pid];
|
17204 | switch (type) {
|
17205 | case StreamTypes.H264_STREAM_TYPE:
|
17206 | result.video = [];
|
17207 | parseVideoPes_(bytes, pmt, result);
|
17208 | if (result.video.length === 0) {
|
17209 | delete result.video;
|
17210 | }
|
17211 | break;
|
17212 | case StreamTypes.ADTS_STREAM_TYPE:
|
17213 | result.audio = [];
|
17214 | parseAudioPes_(bytes, pmt, result);
|
17215 | if (result.audio.length === 0) {
|
17216 | delete result.audio;
|
17217 | }
|
17218 | break;
|
17219 | default:
|
17220 | break;
|
17221 | }
|
17222 | }
|
17223 | }
|
17224 | return result;
|
17225 | };
|
17226 |
|
17227 |
|
17228 |
|
17229 |
|
17230 |
|
17231 |
|
17232 |
|
17233 |
|
17234 |
|
17235 | var inspect = function(bytes, baseTimestamp) {
|
17236 | var isAacData = isLikelyAacData(bytes);
|
17237 |
|
17238 | var result;
|
17239 |
|
17240 | if (isAacData) {
|
17241 | result = inspectAac_(bytes);
|
17242 | } else {
|
17243 | result = inspectTs_(bytes);
|
17244 | }
|
17245 |
|
17246 | if (!result || (!result.audio && !result.video)) {
|
17247 | return null;
|
17248 | }
|
17249 |
|
17250 | adjustTimestamp_(result, baseTimestamp);
|
17251 |
|
17252 | return result;
|
17253 | };
|
17254 |
|
17255 | module.exports = {
|
17256 | inspect: inspect
|
17257 | };
|
17258 |
|
17259 | },{"../aac/probe.js":39,"../m2ts/probe.js":52,"../m2ts/stream-types.js":53,"../m2ts/timestamp-rollover-stream.js":54}],60:[function(require,module,exports){
|
17260 | var
|
17261 | ONE_SECOND_IN_TS = 90000,
|
17262 | secondsToVideoTs,
|
17263 | secondsToAudioTs,
|
17264 | videoTsToSeconds,
|
17265 | audioTsToSeconds,
|
17266 | audioTsToVideoTs,
|
17267 | videoTsToAudioTs;
|
17268 |
|
17269 | secondsToVideoTs = function(seconds) {
|
17270 | return seconds * ONE_SECOND_IN_TS;
|
17271 | };
|
17272 |
|
17273 | secondsToAudioTs = function(seconds, sampleRate) {
|
17274 | return seconds * sampleRate;
|
17275 | };
|
17276 |
|
17277 | videoTsToSeconds = function(timestamp) {
|
17278 | return timestamp / ONE_SECOND_IN_TS;
|
17279 | };
|
17280 |
|
17281 | audioTsToSeconds = function(timestamp, sampleRate) {
|
17282 | return timestamp / sampleRate;
|
17283 | };
|
17284 |
|
17285 | audioTsToVideoTs = function(timestamp, sampleRate) {
|
17286 | return secondsToVideoTs(audioTsToSeconds(timestamp, sampleRate));
|
17287 | };
|
17288 |
|
17289 | videoTsToAudioTs = function(timestamp, sampleRate) {
|
17290 | return secondsToAudioTs(videoTsToSeconds(timestamp), sampleRate);
|
17291 | };
|
17292 |
|
17293 | module.exports = {
|
17294 | secondsToVideoTs: secondsToVideoTs,
|
17295 | secondsToAudioTs: secondsToAudioTs,
|
17296 | videoTsToSeconds: videoTsToSeconds,
|
17297 | audioTsToSeconds: audioTsToSeconds,
|
17298 | audioTsToVideoTs: audioTsToVideoTs,
|
17299 | videoTsToAudioTs: videoTsToAudioTs
|
17300 | };
|
17301 |
|
17302 | },{}],61:[function(require,module,exports){
|
17303 | 'use strict';
|
17304 |
|
17305 | var ExpGolomb;
|
17306 |
|
17307 |
|
17308 |
|
17309 |
|
17310 |
|
17311 | ExpGolomb = function(workingData) {
|
17312 | var
|
17313 |
|
17314 | workingBytesAvailable = workingData.byteLength,
|
17315 |
|
17316 |
|
17317 | workingWord = 0,
|
17318 |
|
17319 |
|
17320 | workingBitsAvailable = 0;
|
17321 |
|
17322 |
|
17323 | this.length = function() {
|
17324 | return (8 * workingBytesAvailable);
|
17325 | };
|
17326 |
|
17327 |
|
17328 | this.bitsAvailable = function() {
|
17329 | return (8 * workingBytesAvailable) + workingBitsAvailable;
|
17330 | };
|
17331 |
|
17332 |
|
17333 | this.loadWord = function() {
|
17334 | var
|
17335 | position = workingData.byteLength - workingBytesAvailable,
|
17336 | workingBytes = new Uint8Array(4),
|
17337 | availableBytes = Math.min(4, workingBytesAvailable);
|
17338 |
|
17339 | if (availableBytes === 0) {
|
17340 | throw new Error('no bytes available');
|
17341 | }
|
17342 |
|
17343 | workingBytes.set(workingData.subarray(position,
|
17344 | position + availableBytes));
|
17345 | workingWord = new DataView(workingBytes.buffer).getUint32(0);
|
17346 |
|
17347 |
|
17348 | workingBitsAvailable = availableBytes * 8;
|
17349 | workingBytesAvailable -= availableBytes;
|
17350 | };
|
17351 |
|
17352 |
|
17353 | this.skipBits = function(count) {
|
17354 | var skipBytes;
|
17355 | if (workingBitsAvailable > count) {
|
17356 | workingWord <<= count;
|
17357 | workingBitsAvailable -= count;
|
17358 | } else {
|
17359 | count -= workingBitsAvailable;
|
17360 | skipBytes = Math.floor(count / 8);
|
17361 |
|
17362 | count -= (skipBytes * 8);
|
17363 | workingBytesAvailable -= skipBytes;
|
17364 |
|
17365 | this.loadWord();
|
17366 |
|
17367 | workingWord <<= count;
|
17368 | workingBitsAvailable -= count;
|
17369 | }
|
17370 | };
|
17371 |
|
17372 |
|
17373 | this.readBits = function(size) {
|
17374 | var
|
17375 | bits = Math.min(workingBitsAvailable, size),
|
17376 | valu = workingWord >>> (32 - bits);
|
17377 |
|
17378 | workingBitsAvailable -= bits;
|
17379 | if (workingBitsAvailable > 0) {
|
17380 | workingWord <<= bits;
|
17381 | } else if (workingBytesAvailable > 0) {
|
17382 | this.loadWord();
|
17383 | }
|
17384 |
|
17385 | bits = size - bits;
|
17386 | if (bits > 0) {
|
17387 | return valu << bits | this.readBits(bits);
|
17388 | }
|
17389 | return valu;
|
17390 | };
|
17391 |
|
17392 |
|
17393 | this.skipLeadingZeros = function() {
|
17394 | var leadingZeroCount;
|
17395 | for (leadingZeroCount = 0; leadingZeroCount < workingBitsAvailable; ++leadingZeroCount) {
|
17396 | if ((workingWord & (0x80000000 >>> leadingZeroCount)) !== 0) {
|
17397 |
|
17398 | workingWord <<= leadingZeroCount;
|
17399 | workingBitsAvailable -= leadingZeroCount;
|
17400 | return leadingZeroCount;
|
17401 | }
|
17402 | }
|
17403 |
|
17404 |
|
17405 | this.loadWord();
|
17406 | return leadingZeroCount + this.skipLeadingZeros();
|
17407 | };
|
17408 |
|
17409 |
|
17410 | this.skipUnsignedExpGolomb = function() {
|
17411 | this.skipBits(1 + this.skipLeadingZeros());
|
17412 | };
|
17413 |
|
17414 |
|
17415 | this.skipExpGolomb = function() {
|
17416 | this.skipBits(1 + this.skipLeadingZeros());
|
17417 | };
|
17418 |
|
17419 |
|
17420 | this.readUnsignedExpGolomb = function() {
|
17421 | var clz = this.skipLeadingZeros();
|
17422 | return this.readBits(clz + 1) - 1;
|
17423 | };
|
17424 |
|
17425 |
|
17426 | this.readExpGolomb = function() {
|
17427 | var valu = this.readUnsignedExpGolomb();
|
17428 | if (0x01 & valu) {
|
17429 |
|
17430 | return (1 + valu) >>> 1;
|
17431 | }
|
17432 | return -1 * (valu >>> 1);
|
17433 | };
|
17434 |
|
17435 |
|
17436 |
|
17437 | this.readBoolean = function() {
|
17438 | return this.readBits(1) === 1;
|
17439 | };
|
17440 |
|
17441 |
|
17442 | this.readUnsignedByte = function() {
|
17443 | return this.readBits(8);
|
17444 | };
|
17445 |
|
17446 | this.loadWord();
|
17447 | };
|
17448 |
|
17449 | module.exports = ExpGolomb;
|
17450 |
|
17451 | },{}],62:[function(require,module,exports){
|
17452 |
|
17453 |
|
17454 |
|
17455 |
|
17456 |
|
17457 |
|
17458 |
|
17459 |
|
17460 |
|
17461 | 'use strict';
|
17462 |
|
17463 | var Stream = function() {
|
17464 | this.init = function() {
|
17465 | var listeners = {};
|
17466 | |
17467 |
|
17468 |
|
17469 |
|
17470 |
|
17471 |
|
17472 | this.on = function(type, listener) {
|
17473 | if (!listeners[type]) {
|
17474 | listeners[type] = [];
|
17475 | }
|
17476 | listeners[type] = listeners[type].concat(listener);
|
17477 | };
|
17478 | |
17479 |
|
17480 |
|
17481 |
|
17482 |
|
17483 |
|
17484 | this.off = function(type, listener) {
|
17485 | var index;
|
17486 | if (!listeners[type]) {
|
17487 | return false;
|
17488 | }
|
17489 | index = listeners[type].indexOf(listener);
|
17490 | listeners[type] = listeners[type].slice();
|
17491 | listeners[type].splice(index, 1);
|
17492 | return index > -1;
|
17493 | };
|
17494 | |
17495 |
|
17496 |
|
17497 |
|
17498 |
|
17499 | this.trigger = function(type) {
|
17500 | var callbacks, i, length, args;
|
17501 | callbacks = listeners[type];
|
17502 | if (!callbacks) {
|
17503 | return;
|
17504 | }
|
17505 |
|
17506 |
|
17507 |
|
17508 |
|
17509 | if (arguments.length === 2) {
|
17510 | length = callbacks.length;
|
17511 | for (i = 0; i < length; ++i) {
|
17512 | callbacks[i].call(this, arguments[1]);
|
17513 | }
|
17514 | } else {
|
17515 | args = [];
|
17516 | i = arguments.length;
|
17517 | for (i = 1; i < arguments.length; ++i) {
|
17518 | args.push(arguments[i]);
|
17519 | }
|
17520 | length = callbacks.length;
|
17521 | for (i = 0; i < length; ++i) {
|
17522 | callbacks[i].apply(this, args);
|
17523 | }
|
17524 | }
|
17525 | };
|
17526 | |
17527 |
|
17528 |
|
17529 | this.dispose = function() {
|
17530 | listeners = {};
|
17531 | };
|
17532 | };
|
17533 | };
|
17534 |
|
17535 |
|
17536 |
|
17537 |
|
17538 |
|
17539 |
|
17540 |
|
17541 |
|
17542 |
|
17543 |
|
17544 | Stream.prototype.pipe = function(destination) {
|
17545 | this.on('data', function(data) {
|
17546 | destination.push(data);
|
17547 | });
|
17548 |
|
17549 | this.on('done', function(flushSource) {
|
17550 | destination.flush(flushSource);
|
17551 | });
|
17552 |
|
17553 | return destination;
|
17554 | };
|
17555 |
|
17556 |
|
17557 |
|
17558 |
|
17559 |
|
17560 | Stream.prototype.push = function(data) {
|
17561 | this.trigger('data', data);
|
17562 | };
|
17563 |
|
17564 | Stream.prototype.flush = function(flushSource) {
|
17565 | this.trigger('done', flushSource);
|
17566 | };
|
17567 |
|
17568 | module.exports = Stream;
|
17569 |
|
17570 | },{}],63:[function(require,module,exports){
|
17571 |
|
17572 | (function(root) {
|
17573 |
|
17574 | var URLToolkit = {
|
17575 |
|
17576 |
|
17577 | buildAbsoluteURL: function(baseURL, relativeURL) {
|
17578 |
|
17579 | relativeURL = relativeURL.trim();
|
17580 | if (/^[a-z]+:/i.test(relativeURL)) {
|
17581 |
|
17582 | return relativeURL;
|
17583 | }
|
17584 |
|
17585 | var relativeURLQuery = null;
|
17586 | var relativeURLHash = null;
|
17587 |
|
17588 | var relativeURLHashSplit = /^([^#]*)(.*)$/.exec(relativeURL);
|
17589 | if (relativeURLHashSplit) {
|
17590 | relativeURLHash = relativeURLHashSplit[2];
|
17591 | relativeURL = relativeURLHashSplit[1];
|
17592 | }
|
17593 | var relativeURLQuerySplit = /^([^\?]*)(.*)$/.exec(relativeURL);
|
17594 | if (relativeURLQuerySplit) {
|
17595 | relativeURLQuery = relativeURLQuerySplit[2];
|
17596 | relativeURL = relativeURLQuerySplit[1];
|
17597 | }
|
17598 |
|
17599 | var baseURLHashSplit = /^([^#]*)(.*)$/.exec(baseURL);
|
17600 | if (baseURLHashSplit) {
|
17601 | baseURL = baseURLHashSplit[1];
|
17602 | }
|
17603 | var baseURLQuerySplit = /^([^\?]*)(.*)$/.exec(baseURL);
|
17604 | if (baseURLQuerySplit) {
|
17605 | baseURL = baseURLQuerySplit[1];
|
17606 | }
|
17607 |
|
17608 | var baseURLDomainSplit = /^(([a-z]+:)?\/\/[^:\/]+(:[0-9]+)?)?(\/?.*)$/i.exec(baseURL);
|
17609 | if (!baseURLDomainSplit) {
|
17610 | throw new Error('Error trying to parse base URL.');
|
17611 | }
|
17612 |
|
17613 |
|
17614 | var baseURLProtocol = baseURLDomainSplit[2] || '';
|
17615 |
|
17616 | var baseURLProtocolDomain = baseURLDomainSplit[1] || '';
|
17617 |
|
17618 | var baseURLPath = baseURLDomainSplit[4];
|
17619 | if (baseURLPath.indexOf('/') !== 0 && baseURLProtocolDomain !== '') {
|
17620 |
|
17621 | baseURLPath = '/'+baseURLPath;
|
17622 | }
|
17623 |
|
17624 | var builtURL = null;
|
17625 | if (/^\/\//.test(relativeURL)) {
|
17626 |
|
17627 | builtURL = baseURLProtocol+'//'+URLToolkit.buildAbsolutePath('', relativeURL.substring(2));
|
17628 | }
|
17629 | else if (/^\//.test(relativeURL)) {
|
17630 |
|
17631 | builtURL = baseURLProtocolDomain+'/'+URLToolkit.buildAbsolutePath('', relativeURL.substring(1));
|
17632 | }
|
17633 | else {
|
17634 | builtURL = URLToolkit.buildAbsolutePath(baseURLProtocolDomain+baseURLPath, relativeURL);
|
17635 | }
|
17636 |
|
17637 |
|
17638 | if (relativeURLQuery) {
|
17639 | builtURL += relativeURLQuery;
|
17640 | }
|
17641 | if (relativeURLHash) {
|
17642 | builtURL += relativeURLHash;
|
17643 | }
|
17644 | return builtURL;
|
17645 | },
|
17646 |
|
17647 |
|
17648 |
|
17649 |
|
17650 | buildAbsolutePath: function(basePath, relativePath) {
|
17651 | var sRelPath = relativePath;
|
17652 | var nUpLn, sDir = '', sPath = basePath.replace(/[^\/]*$/, sRelPath.replace(/(\/|^)(?:\.?\/+)+/g, '$1'));
|
17653 | for (var nEnd, nStart = 0; nEnd = sPath.indexOf('/../', nStart), nEnd > -1; nStart = nEnd + nUpLn) {
|
17654 | nUpLn = /^\/(?:\.\.\/)*/.exec(sPath.slice(nEnd))[0].length;
|
17655 | sDir = (sDir + sPath.substring(nStart, nEnd)).replace(new RegExp('(?:\\\/+[^\\\/]*){0,' + ((nUpLn - 1) / 3) + '}$'), '/');
|
17656 | }
|
17657 | return sDir + sPath.substr(nStart);
|
17658 | }
|
17659 | };
|
17660 |
|
17661 |
|
17662 | if(typeof exports === 'object' && typeof module === 'object')
|
17663 | module.exports = URLToolkit;
|
17664 | else if(typeof define === 'function' && define.amd)
|
17665 | define([], function() { return URLToolkit; });
|
17666 | else if(typeof exports === 'object')
|
17667 | exports["URLToolkit"] = URLToolkit;
|
17668 | else
|
17669 | root["URLToolkit"] = URLToolkit;
|
17670 | })(this);
|
17671 |
|
17672 |
|
17673 | },{}],64:[function(require,module,exports){
|
17674 | (function (global){
|
17675 |
|
17676 |
|
17677 |
|
17678 | 'use strict';
|
17679 |
|
17680 | Object.defineProperty(exports, '__esModule', {
|
17681 | value: true
|
17682 | });
|
17683 |
|
17684 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
17685 |
|
17686 | var _globalWindow = require('global/window');
|
17687 |
|
17688 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
17689 |
|
17690 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
17691 |
|
17692 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
17693 |
|
17694 |
|
17695 |
|
17696 |
|
17697 |
|
17698 |
|
17699 |
|
17700 |
|
17701 |
|
17702 | var deprecateOldCue = function deprecateOldCue(cue) {
|
17703 | Object.defineProperties(cue.frame, {
|
17704 | id: {
|
17705 | get: function get() {
|
17706 | _videoJs2['default'].log.warn('cue.frame.id is deprecated. Use cue.value.key instead.');
|
17707 | return cue.value.key;
|
17708 | }
|
17709 | },
|
17710 | value: {
|
17711 | get: function get() {
|
17712 | _videoJs2['default'].log.warn('cue.frame.value is deprecated. Use cue.value.data instead.');
|
17713 | return cue.value.data;
|
17714 | }
|
17715 | },
|
17716 | privateData: {
|
17717 | get: function get() {
|
17718 | _videoJs2['default'].log.warn('cue.frame.privateData is deprecated. Use cue.value.data instead.');
|
17719 | return cue.value.data;
|
17720 | }
|
17721 | }
|
17722 | });
|
17723 | };
|
17724 |
|
17725 | var durationOfVideo = function durationOfVideo(duration) {
|
17726 | var dur = undefined;
|
17727 |
|
17728 | if (isNaN(duration) || Math.abs(duration) === Infinity) {
|
17729 | dur = Number.MAX_VALUE;
|
17730 | } else {
|
17731 | dur = duration;
|
17732 | }
|
17733 | return dur;
|
17734 | };
|
17735 |
|
17736 |
|
17737 |
|
17738 |
|
17739 |
|
17740 |
|
17741 |
|
17742 |
|
17743 |
|
17744 | var addTextTrackData = function addTextTrackData(sourceHandler, captionArray, metadataArray) {
|
17745 | var Cue = _globalWindow2['default'].WebKitDataCue || _globalWindow2['default'].VTTCue;
|
17746 |
|
17747 | if (captionArray) {
|
17748 | captionArray.forEach(function (caption) {
|
17749 | var track = caption.stream;
|
17750 |
|
17751 | this.inbandTextTracks_[track].addCue(new Cue(caption.startTime + this.timestampOffset, caption.endTime + this.timestampOffset, caption.text));
|
17752 | }, sourceHandler);
|
17753 | }
|
17754 |
|
17755 | if (metadataArray) {
|
17756 | (function () {
|
17757 | var videoDuration = durationOfVideo(sourceHandler.mediaSource_.duration);
|
17758 |
|
17759 | metadataArray.forEach(function (metadata) {
|
17760 | var time = metadata.cueTime + this.timestampOffset;
|
17761 |
|
17762 | metadata.frames.forEach(function (frame) {
|
17763 | var cue = new Cue(time, time, frame.value || frame.url || frame.data || '');
|
17764 |
|
17765 | cue.frame = frame;
|
17766 | cue.value = frame;
|
17767 | deprecateOldCue(cue);
|
17768 |
|
17769 | this.metadataTrack_.addCue(cue);
|
17770 | }, this);
|
17771 | }, sourceHandler);
|
17772 |
|
17773 |
|
17774 |
|
17775 |
|
17776 | if (sourceHandler.metadataTrack_ && sourceHandler.metadataTrack_.cues && sourceHandler.metadataTrack_.cues.length) {
|
17777 | (function () {
|
17778 | var cues = sourceHandler.metadataTrack_.cues;
|
17779 | var cuesArray = [];
|
17780 |
|
17781 |
|
17782 |
|
17783 | for (var i = 0; i < cues.length; i++) {
|
17784 | if (cues[i]) {
|
17785 | cuesArray.push(cues[i]);
|
17786 | }
|
17787 | }
|
17788 |
|
17789 |
|
17790 | var cuesGroupedByStartTime = cuesArray.reduce(function (obj, cue) {
|
17791 | var timeSlot = obj[cue.startTime] || [];
|
17792 |
|
17793 | timeSlot.push(cue);
|
17794 | obj[cue.startTime] = timeSlot;
|
17795 |
|
17796 | return obj;
|
17797 | }, {});
|
17798 |
|
17799 |
|
17800 | var sortedStartTimes = Object.keys(cuesGroupedByStartTime).sort(function (a, b) {
|
17801 | return Number(a) - Number(b);
|
17802 | });
|
17803 |
|
17804 |
|
17805 | sortedStartTimes.forEach(function (startTime, idx) {
|
17806 | var cueGroup = cuesGroupedByStartTime[startTime];
|
17807 | var nextTime = Number(sortedStartTimes[idx + 1]) || videoDuration;
|
17808 |
|
17809 |
|
17810 | cueGroup.forEach(function (cue) {
|
17811 | cue.endTime = nextTime;
|
17812 | });
|
17813 | });
|
17814 | })();
|
17815 | }
|
17816 | })();
|
17817 | }
|
17818 | };
|
17819 |
|
17820 | exports['default'] = {
|
17821 | addTextTrackData: addTextTrackData,
|
17822 | durationOfVideo: durationOfVideo
|
17823 | };
|
17824 | module.exports = exports['default'];
|
17825 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
17826 | },{"global/window":32}],65:[function(require,module,exports){
|
17827 |
|
17828 |
|
17829 |
|
17830 |
|
17831 |
|
17832 |
|
17833 |
|
17834 |
|
17835 |
|
17836 |
|
17837 |
|
17838 | 'use strict';
|
17839 |
|
17840 | Object.defineProperty(exports, '__esModule', {
|
17841 | value: true
|
17842 | });
|
17843 | var isAudioCodec = function isAudioCodec(codec) {
|
17844 | return (/mp4a\.\d+.\d+/i.test(codec)
|
17845 | );
|
17846 | };
|
17847 |
|
17848 |
|
17849 |
|
17850 |
|
17851 |
|
17852 |
|
17853 |
|
17854 |
|
17855 | var isVideoCodec = function isVideoCodec(codec) {
|
17856 | return (/avc1\.[\da-f]+/i.test(codec)
|
17857 | );
|
17858 | };
|
17859 |
|
17860 |
|
17861 |
|
17862 |
|
17863 |
|
17864 |
|
17865 |
|
17866 |
|
17867 |
|
17868 | var parseContentType = function parseContentType(type) {
|
17869 | var object = { type: '', parameters: {} };
|
17870 | var parameters = type.trim().split(';');
|
17871 |
|
17872 |
|
17873 | object.type = parameters.shift().trim();
|
17874 | parameters.forEach(function (parameter) {
|
17875 | var pair = parameter.trim().split('=');
|
17876 |
|
17877 | if (pair.length > 1) {
|
17878 | var _name = pair[0].replace(/"/g, '').trim();
|
17879 | var value = pair[1].replace(/"/g, '').trim();
|
17880 |
|
17881 | object.parameters[_name] = value;
|
17882 | }
|
17883 | });
|
17884 |
|
17885 | return object;
|
17886 | };
|
17887 |
|
17888 |
|
17889 |
|
17890 |
|
17891 |
|
17892 |
|
17893 |
|
17894 |
|
17895 |
|
17896 | var translateLegacyCodecs = function translateLegacyCodecs(codecs) {
|
17897 | return codecs.map(function (codec) {
|
17898 | return codec.replace(/avc1\.(\d+)\.(\d+)/i, function (orig, profile, avcLevel) {
|
17899 | var profileHex = ('00' + Number(profile).toString(16)).slice(-2);
|
17900 | var avcLevelHex = ('00' + Number(avcLevel).toString(16)).slice(-2);
|
17901 |
|
17902 | return 'avc1.' + profileHex + '00' + avcLevelHex;
|
17903 | });
|
17904 | });
|
17905 | };
|
17906 |
|
17907 | exports['default'] = {
|
17908 | isAudioCodec: isAudioCodec,
|
17909 | parseContentType: parseContentType,
|
17910 | isVideoCodec: isVideoCodec,
|
17911 | translateLegacyCodecs: translateLegacyCodecs
|
17912 | };
|
17913 | module.exports = exports['default'];
|
17914 | },{}],66:[function(require,module,exports){
|
17915 |
|
17916 |
|
17917 |
|
17918 |
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 |
|
17926 |
|
17927 | 'use strict';
|
17928 |
|
17929 | Object.defineProperty(exports, '__esModule', {
|
17930 | value: true
|
17931 | });
|
17932 | var createTextTracksIfNecessary = function createTextTracksIfNecessary(sourceBuffer, mediaSource, segment) {
|
17933 | var player = mediaSource.player_;
|
17934 |
|
17935 |
|
17936 | if (segment.captions && segment.captions.length) {
|
17937 | if (!sourceBuffer.inbandTextTracks_) {
|
17938 | sourceBuffer.inbandTextTracks_ = {};
|
17939 | }
|
17940 |
|
17941 | for (var trackId in segment.captionStreams) {
|
17942 | if (!sourceBuffer.inbandTextTracks_[trackId]) {
|
17943 | player.tech_.trigger({ type: 'usage', name: 'hls-608' });
|
17944 | var track = player.textTracks().getTrackById(trackId);
|
17945 |
|
17946 | if (track) {
|
17947 |
|
17948 |
|
17949 |
|
17950 | sourceBuffer.inbandTextTracks_[trackId] = track;
|
17951 | } else {
|
17952 |
|
17953 |
|
17954 | sourceBuffer.inbandTextTracks_[trackId] = player.addRemoteTextTrack({
|
17955 | kind: 'captions',
|
17956 | id: trackId,
|
17957 | label: trackId
|
17958 | }, false).track;
|
17959 | }
|
17960 | }
|
17961 | }
|
17962 | }
|
17963 |
|
17964 | if (segment.metadata && segment.metadata.length && !sourceBuffer.metadataTrack_) {
|
17965 | sourceBuffer.metadataTrack_ = player.addRemoteTextTrack({
|
17966 | kind: 'metadata',
|
17967 | label: 'Timed Metadata'
|
17968 | }, false).track;
|
17969 | sourceBuffer.metadataTrack_.inBandMetadataTrackDispatchType = segment.metadata.dispatchType;
|
17970 | }
|
17971 | };
|
17972 |
|
17973 | exports['default'] = createTextTracksIfNecessary;
|
17974 | module.exports = exports['default'];
|
17975 | },{}],67:[function(require,module,exports){
|
17976 |
|
17977 |
|
17978 |
|
17979 |
|
17980 |
|
17981 |
|
17982 |
|
17983 |
|
17984 |
|
17985 |
|
17986 |
|
17987 |
|
17988 |
|
17989 | "use strict";
|
17990 |
|
17991 | Object.defineProperty(exports, "__esModule", {
|
17992 | value: true
|
17993 | });
|
17994 | var flashConstants = {
|
17995 |
|
17996 | TIME_BETWEEN_CHUNKS: 1,
|
17997 | BYTES_PER_CHUNK: 1024 * 32
|
17998 | };
|
17999 |
|
18000 | exports["default"] = flashConstants;
|
18001 | module.exports = exports["default"];
|
18002 | },{}],68:[function(require,module,exports){
|
18003 | (function (global){
|
18004 |
|
18005 |
|
18006 |
|
18007 | 'use strict';
|
18008 |
|
18009 | Object.defineProperty(exports, '__esModule', {
|
18010 | value: true
|
18011 | });
|
18012 |
|
18013 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
18014 |
|
18015 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
18016 |
|
18017 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
18018 |
|
18019 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
18020 |
|
18021 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
18022 |
|
18023 | var _globalDocument = require('global/document');
|
18024 |
|
18025 | var _globalDocument2 = _interopRequireDefault(_globalDocument);
|
18026 |
|
18027 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
18028 |
|
18029 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
18030 |
|
18031 | var _flashSourceBuffer = require('./flash-source-buffer');
|
18032 |
|
18033 | var _flashSourceBuffer2 = _interopRequireDefault(_flashSourceBuffer);
|
18034 |
|
18035 | var _flashConstants = require('./flash-constants');
|
18036 |
|
18037 | var _flashConstants2 = _interopRequireDefault(_flashConstants);
|
18038 |
|
18039 | var _codecUtils = require('./codec-utils');
|
18040 |
|
18041 |
|
18042 |
|
18043 |
|
18044 |
|
18045 |
|
18046 |
|
18047 |
|
18048 |
|
18049 |
|
18050 | var FlashMediaSource = (function (_videojs$EventTarget) {
|
18051 | _inherits(FlashMediaSource, _videojs$EventTarget);
|
18052 |
|
18053 | function FlashMediaSource() {
|
18054 | var _this = this;
|
18055 |
|
18056 | _classCallCheck(this, FlashMediaSource);
|
18057 |
|
18058 | _get(Object.getPrototypeOf(FlashMediaSource.prototype), 'constructor', this).call(this);
|
18059 | this.sourceBuffers = [];
|
18060 | this.readyState = 'closed';
|
18061 |
|
18062 | this.on(['sourceopen', 'webkitsourceopen'], function (event) {
|
18063 |
|
18064 | _this.swfObj = _globalDocument2['default'].getElementById(event.swfId);
|
18065 | _this.player_ = (0, _videoJs2['default'])(_this.swfObj.parentNode);
|
18066 | _this.tech_ = _this.swfObj.tech;
|
18067 | _this.readyState = 'open';
|
18068 |
|
18069 | _this.tech_.on('seeking', function () {
|
18070 | var i = _this.sourceBuffers.length;
|
18071 |
|
18072 | while (i--) {
|
18073 | _this.sourceBuffers[i].abort();
|
18074 | }
|
18075 | });
|
18076 |
|
18077 |
|
18078 | if (_this.swfObj) {
|
18079 | _this.swfObj.vjs_load();
|
18080 | }
|
18081 | });
|
18082 | }
|
18083 |
|
18084 | |
18085 |
|
18086 |
|
18087 |
|
18088 |
|
18089 |
|
18090 |
|
18091 |
|
18092 | |
18093 |
|
18094 |
|
18095 |
|
18096 |
|
18097 |
|
18098 |
|
18099 | _createClass(FlashMediaSource, [{
|
18100 | key: 'addSeekableRange_',
|
18101 | value: function addSeekableRange_() {}
|
18102 |
|
18103 |
|
18104 | |
18105 |
|
18106 |
|
18107 |
|
18108 |
|
18109 |
|
18110 |
|
18111 |
|
18112 | }, {
|
18113 | key: 'addSourceBuffer',
|
18114 | value: function addSourceBuffer(type) {
|
18115 | var parsedType = (0, _codecUtils.parseContentType)(type);
|
18116 | var sourceBuffer = undefined;
|
18117 |
|
18118 |
|
18119 | if (parsedType.type === 'video/mp2t' || parsedType.type === 'audio/mp2t') {
|
18120 |
|
18121 | sourceBuffer = new _flashSourceBuffer2['default'](this);
|
18122 | } else {
|
18123 | throw new Error('NotSupportedError (Video.js)');
|
18124 | }
|
18125 |
|
18126 | this.sourceBuffers.push(sourceBuffer);
|
18127 | return sourceBuffer;
|
18128 | }
|
18129 |
|
18130 | |
18131 |
|
18132 |
|
18133 |
|
18134 |
|
18135 |
|
18136 |
|
18137 |
|
18138 | }, {
|
18139 | key: 'endOfStream',
|
18140 | value: function endOfStream(error) {
|
18141 | if (error === 'network') {
|
18142 |
|
18143 | this.tech_.error(2);
|
18144 | } else if (error === 'decode') {
|
18145 |
|
18146 | this.tech_.error(3);
|
18147 | }
|
18148 | if (this.readyState !== 'ended') {
|
18149 | this.readyState = 'ended';
|
18150 | this.swfObj.vjs_endOfStream();
|
18151 | }
|
18152 | }
|
18153 | }]);
|
18154 |
|
18155 | return FlashMediaSource;
|
18156 | })(_videoJs2['default'].EventTarget);
|
18157 |
|
18158 | exports['default'] = FlashMediaSource;
|
18159 | try {
|
18160 | Object.defineProperty(FlashMediaSource.prototype, 'duration', {
|
18161 | |
18162 |
|
18163 |
|
18164 |
|
18165 |
|
18166 |
|
18167 | get: function get() {
|
18168 | if (!this.swfObj) {
|
18169 | return NaN;
|
18170 | }
|
18171 |
|
18172 | return this.swfObj.vjs_getProperty('duration');
|
18173 | },
|
18174 | |
18175 |
|
18176 |
|
18177 |
|
18178 |
|
18179 |
|
18180 |
|
18181 | set: function set(value) {
|
18182 | var i = undefined;
|
18183 | var oldDuration = this.swfObj.vjs_getProperty('duration');
|
18184 |
|
18185 | this.swfObj.vjs_setProperty('duration', value);
|
18186 |
|
18187 | if (value < oldDuration) {
|
18188 |
|
18189 |
|
18190 | for (i = 0; i < this.sourceBuffers.length; i++) {
|
18191 | this.sourceBuffers[i].remove(value, oldDuration);
|
18192 | }
|
18193 | }
|
18194 |
|
18195 | return value;
|
18196 | }
|
18197 | });
|
18198 | } catch (e) {
|
18199 |
|
18200 |
|
18201 |
|
18202 | FlashMediaSource.prototype.duration = NaN;
|
18203 | }
|
18204 |
|
18205 | for (var property in _flashConstants2['default']) {
|
18206 | FlashMediaSource[property] = _flashConstants2['default'][property];
|
18207 | }
|
18208 | module.exports = exports['default'];
|
18209 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
18210 | },{"./codec-utils":65,"./flash-constants":67,"./flash-source-buffer":69,"global/document":31}],69:[function(require,module,exports){
|
18211 | (function (global){
|
18212 |
|
18213 |
|
18214 |
|
18215 | 'use strict';
|
18216 |
|
18217 | Object.defineProperty(exports, '__esModule', {
|
18218 | value: true
|
18219 | });
|
18220 |
|
18221 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
18222 |
|
18223 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
18224 |
|
18225 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
18226 |
|
18227 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
18228 |
|
18229 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
18230 |
|
18231 | var _globalWindow = require('global/window');
|
18232 |
|
18233 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
18234 |
|
18235 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
18236 |
|
18237 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
18238 |
|
18239 | var _muxJsLibFlv = require('mux.js/lib/flv');
|
18240 |
|
18241 | var _muxJsLibFlv2 = _interopRequireDefault(_muxJsLibFlv);
|
18242 |
|
18243 | var _removeCuesFromTrack = require('./remove-cues-from-track');
|
18244 |
|
18245 | var _removeCuesFromTrack2 = _interopRequireDefault(_removeCuesFromTrack);
|
18246 |
|
18247 | var _createTextTracksIfNecessary = require('./create-text-tracks-if-necessary');
|
18248 |
|
18249 | var _createTextTracksIfNecessary2 = _interopRequireDefault(_createTextTracksIfNecessary);
|
18250 |
|
18251 | var _addTextTrackData = require('./add-text-track-data');
|
18252 |
|
18253 | var _flashTransmuxerWorker = require('./flash-transmuxer-worker');
|
18254 |
|
18255 | var _flashTransmuxerWorker2 = _interopRequireDefault(_flashTransmuxerWorker);
|
18256 |
|
18257 | var _webworkify = require('webworkify');
|
18258 |
|
18259 | var _webworkify2 = _interopRequireDefault(_webworkify);
|
18260 |
|
18261 | var _flashConstants = require('./flash-constants');
|
18262 |
|
18263 | var _flashConstants2 = _interopRequireDefault(_flashConstants);
|
18264 |
|
18265 |
|
18266 |
|
18267 |
|
18268 |
|
18269 |
|
18270 |
|
18271 |
|
18272 | var scheduleTick = function scheduleTick(func) {
|
18273 |
|
18274 |
|
18275 | _globalWindow2['default'].setTimeout(func, _flashConstants2['default'].TIME_BETWEEN_CHUNKS);
|
18276 | };
|
18277 |
|
18278 |
|
18279 |
|
18280 |
|
18281 |
|
18282 |
|
18283 |
|
18284 |
|
18285 | var generateRandomString = function generateRandomString() {
|
18286 | return Math.random().toString(36).slice(2, 8);
|
18287 | };
|
18288 |
|
18289 |
|
18290 |
|
18291 |
|
18292 |
|
18293 |
|
18294 |
|
18295 |
|
18296 |
|
18297 |
|
18298 | var toDecimalPlaces = function toDecimalPlaces(num, places) {
|
18299 | if (typeof places !== 'number' || places < 0) {
|
18300 | places = 0;
|
18301 | }
|
18302 |
|
18303 | var scale = Math.pow(10, places);
|
18304 |
|
18305 | return Math.round(num * scale) / scale;
|
18306 | };
|
18307 |
|
18308 |
|
18309 |
|
18310 |
|
18311 |
|
18312 |
|
18313 |
|
18314 |
|
18315 |
|
18316 |
|
18317 | var FlashSourceBuffer = (function (_videojs$EventTarget) {
|
18318 | _inherits(FlashSourceBuffer, _videojs$EventTarget);
|
18319 |
|
18320 | function FlashSourceBuffer(mediaSource) {
|
18321 | var _this = this;
|
18322 |
|
18323 | _classCallCheck(this, FlashSourceBuffer);
|
18324 |
|
18325 | _get(Object.getPrototypeOf(FlashSourceBuffer.prototype), 'constructor', this).call(this);
|
18326 | var encodedHeader = undefined;
|
18327 |
|
18328 |
|
18329 |
|
18330 | this.chunkSize_ = _flashConstants2['default'].BYTES_PER_CHUNK;
|
18331 |
|
18332 |
|
18333 | this.buffer_ = [];
|
18334 |
|
18335 |
|
18336 | this.bufferSize_ = 0;
|
18337 |
|
18338 |
|
18339 |
|
18340 |
|
18341 | this.basePtsOffset_ = NaN;
|
18342 |
|
18343 | this.mediaSource_ = mediaSource;
|
18344 |
|
18345 | this.audioBufferEnd_ = NaN;
|
18346 | this.videoBufferEnd_ = NaN;
|
18347 |
|
18348 |
|
18349 |
|
18350 |
|
18351 | this.updating = false;
|
18352 | this.timestampOffset_ = 0;
|
18353 |
|
18354 | encodedHeader = _globalWindow2['default'].btoa(String.fromCharCode.apply(null, Array.prototype.slice.call(_muxJsLibFlv2['default'].getFlvHeader())));
|
18355 |
|
18356 |
|
18357 |
|
18358 |
|
18359 |
|
18360 |
|
18361 |
|
18362 |
|
18363 | var safePlayerId = this.mediaSource_.player_.id().replace(/[^a-zA-Z0-9]/g, '_');
|
18364 |
|
18365 | this.flashEncodedHeaderName_ = 'vjs_flashEncodedHeader_' + safePlayerId + generateRandomString();
|
18366 | this.flashEncodedDataName_ = 'vjs_flashEncodedData_' + safePlayerId + generateRandomString();
|
18367 |
|
18368 | _globalWindow2['default'][this.flashEncodedHeaderName_] = function () {
|
18369 | delete _globalWindow2['default'][_this.flashEncodedHeaderName_];
|
18370 | return encodedHeader;
|
18371 | };
|
18372 |
|
18373 | this.mediaSource_.swfObj.vjs_appendChunkReady(this.flashEncodedHeaderName_);
|
18374 |
|
18375 | this.transmuxer_ = (0, _webworkify2['default'])(_flashTransmuxerWorker2['default']);
|
18376 | this.transmuxer_.postMessage({ action: 'init', options: {} });
|
18377 | this.transmuxer_.onmessage = function (event) {
|
18378 | if (event.data.action === 'data') {
|
18379 | _this.receiveBuffer_(event.data.segment);
|
18380 | }
|
18381 | };
|
18382 |
|
18383 | this.one('updateend', function () {
|
18384 | _this.mediaSource_.tech_.trigger('loadedmetadata');
|
18385 | });
|
18386 |
|
18387 | Object.defineProperty(this, 'timestampOffset', {
|
18388 | get: function get() {
|
18389 | return this.timestampOffset_;
|
18390 | },
|
18391 | set: function set(val) {
|
18392 | if (typeof val === 'number' && val >= 0) {
|
18393 | this.timestampOffset_ = val;
|
18394 |
|
18395 | this.mediaSource_.swfObj.vjs_discontinuity();
|
18396 |
|
18397 |
|
18398 | this.basePtsOffset_ = NaN;
|
18399 | this.audioBufferEnd_ = NaN;
|
18400 | this.videoBufferEnd_ = NaN;
|
18401 |
|
18402 | this.transmuxer_.postMessage({ action: 'reset' });
|
18403 | }
|
18404 | }
|
18405 | });
|
18406 |
|
18407 | Object.defineProperty(this, 'buffered', {
|
18408 | get: function get() {
|
18409 | if (!this.mediaSource_ || !this.mediaSource_.swfObj || !('vjs_getProperty' in this.mediaSource_.swfObj)) {
|
18410 | return _videoJs2['default'].createTimeRange();
|
18411 | }
|
18412 |
|
18413 | var buffered = this.mediaSource_.swfObj.vjs_getProperty('buffered');
|
18414 |
|
18415 | if (buffered && buffered.length) {
|
18416 | buffered[0][0] = toDecimalPlaces(buffered[0][0], 3);
|
18417 | buffered[0][1] = toDecimalPlaces(buffered[0][1], 3);
|
18418 | }
|
18419 | return _videoJs2['default'].createTimeRanges(buffered);
|
18420 | }
|
18421 | });
|
18422 |
|
18423 |
|
18424 |
|
18425 | this.mediaSource_.player_.on('seeked', function () {
|
18426 | (0, _removeCuesFromTrack2['default'])(0, Infinity, _this.metadataTrack_);
|
18427 | if (_this.inbandTextTracks_) {
|
18428 | for (var track in _this.inbandTextTracks_) {
|
18429 | (0, _removeCuesFromTrack2['default'])(0, Infinity, _this.inbandTextTracks_[track]);
|
18430 | }
|
18431 | }
|
18432 | });
|
18433 |
|
18434 | var onHlsReset = this.onHlsReset_.bind(this);
|
18435 |
|
18436 |
|
18437 |
|
18438 | this.mediaSource_.player_.tech_.on('hls-reset', onHlsReset);
|
18439 |
|
18440 | this.mediaSource_.player_.tech_.hls.on('dispose', function () {
|
18441 | _this.transmuxer_.terminate();
|
18442 | _this.mediaSource_.player_.tech_.off('hls-reset', onHlsReset);
|
18443 | });
|
18444 | }
|
18445 |
|
18446 | |
18447 |
|
18448 |
|
18449 |
|
18450 |
|
18451 |
|
18452 |
|
18453 |
|
18454 | _createClass(FlashSourceBuffer, [{
|
18455 | key: 'appendBuffer',
|
18456 | value: function appendBuffer(bytes) {
|
18457 | var error = undefined;
|
18458 |
|
18459 | if (this.updating) {
|
18460 | error = new Error('SourceBuffer.append() cannot be called ' + 'while an update is in progress');
|
18461 | error.name = 'InvalidStateError';
|
18462 | error.code = 11;
|
18463 | throw error;
|
18464 | }
|
18465 | this.updating = true;
|
18466 | this.mediaSource_.readyState = 'open';
|
18467 | this.trigger({ type: 'update' });
|
18468 |
|
18469 | this.transmuxer_.postMessage({
|
18470 | action: 'push',
|
18471 | data: bytes.buffer,
|
18472 | byteOffset: bytes.byteOffset,
|
18473 | byteLength: bytes.byteLength
|
18474 | }, [bytes.buffer]);
|
18475 | this.transmuxer_.postMessage({ action: 'flush' });
|
18476 | }
|
18477 |
|
18478 | |
18479 |
|
18480 |
|
18481 |
|
18482 |
|
18483 | }, {
|
18484 | key: 'abort',
|
18485 | value: function abort() {
|
18486 | this.buffer_ = [];
|
18487 | this.bufferSize_ = 0;
|
18488 | this.mediaSource_.swfObj.vjs_abort();
|
18489 |
|
18490 |
|
18491 | if (this.updating) {
|
18492 | this.updating = false;
|
18493 | this.trigger({ type: 'updateend' });
|
18494 | }
|
18495 | }
|
18496 |
|
18497 | |
18498 |
|
18499 |
|
18500 |
|
18501 |
|
18502 |
|
18503 |
|
18504 |
|
18505 |
|
18506 | }, {
|
18507 | key: 'remove',
|
18508 | value: function remove(start, end) {
|
18509 | (0, _removeCuesFromTrack2['default'])(start, end, this.metadataTrack_);
|
18510 | if (this.inbandTextTracks_) {
|
18511 | for (var track in this.inbandTextTracks_) {
|
18512 | (0, _removeCuesFromTrack2['default'])(start, end, this.inbandTextTracks_[track]);
|
18513 | }
|
18514 | }
|
18515 | this.trigger({ type: 'update' });
|
18516 | this.trigger({ type: 'updateend' });
|
18517 | }
|
18518 |
|
18519 | |
18520 |
|
18521 |
|
18522 |
|
18523 |
|
18524 |
|
18525 | }, {
|
18526 | key: 'receiveBuffer_',
|
18527 | value: function receiveBuffer_(segment) {
|
18528 | var _this2 = this;
|
18529 |
|
18530 |
|
18531 | (0, _createTextTracksIfNecessary2['default'])(this, this.mediaSource_, segment);
|
18532 | (0, _addTextTrackData.addTextTrackData)(this, segment.captions, segment.metadata);
|
18533 |
|
18534 |
|
18535 | scheduleTick(function () {
|
18536 | var flvBytes = _this2.convertTagsToData_(segment);
|
18537 |
|
18538 | if (_this2.buffer_.length === 0) {
|
18539 | scheduleTick(_this2.processBuffer_.bind(_this2));
|
18540 | }
|
18541 |
|
18542 | if (flvBytes) {
|
18543 | _this2.buffer_.push(flvBytes);
|
18544 | _this2.bufferSize_ += flvBytes.byteLength;
|
18545 | }
|
18546 | });
|
18547 | }
|
18548 |
|
18549 | |
18550 |
|
18551 |
|
18552 |
|
18553 |
|
18554 | }, {
|
18555 | key: 'processBuffer_',
|
18556 | value: function processBuffer_() {
|
18557 | var _this3 = this;
|
18558 |
|
18559 | var chunkSize = _flashConstants2['default'].BYTES_PER_CHUNK;
|
18560 |
|
18561 | if (!this.buffer_.length) {
|
18562 | if (this.updating !== false) {
|
18563 | this.updating = false;
|
18564 | this.trigger({ type: 'updateend' });
|
18565 | }
|
18566 |
|
18567 | return;
|
18568 | }
|
18569 |
|
18570 |
|
18571 | var chunk = this.buffer_[0].subarray(0, chunkSize);
|
18572 |
|
18573 |
|
18574 | if (chunk.byteLength < chunkSize || this.buffer_[0].byteLength === chunkSize) {
|
18575 | this.buffer_.shift();
|
18576 | } else {
|
18577 | this.buffer_[0] = this.buffer_[0].subarray(chunkSize);
|
18578 | }
|
18579 |
|
18580 | this.bufferSize_ -= chunk.byteLength;
|
18581 |
|
18582 |
|
18583 | var binary = [];
|
18584 | var length = chunk.byteLength;
|
18585 |
|
18586 | for (var i = 0; i < length; i++) {
|
18587 | binary.push(String.fromCharCode(chunk[i]));
|
18588 | }
|
18589 | var b64str = _globalWindow2['default'].btoa(binary.join(''));
|
18590 |
|
18591 | _globalWindow2['default'][this.flashEncodedDataName_] = function () {
|
18592 |
|
18593 |
|
18594 | scheduleTick(_this3.processBuffer_.bind(_this3));
|
18595 | delete _globalWindow2['default'][_this3.flashEncodedDataName_];
|
18596 | return b64str;
|
18597 | };
|
18598 |
|
18599 |
|
18600 | this.mediaSource_.swfObj.vjs_appendChunkReady(this.flashEncodedDataName_);
|
18601 | }
|
18602 |
|
18603 | |
18604 |
|
18605 |
|
18606 |
|
18607 |
|
18608 |
|
18609 |
|
18610 |
|
18611 |
|
18612 | }, {
|
18613 | key: 'convertTagsToData_',
|
18614 | value: function convertTagsToData_(segmentData) {
|
18615 | var segmentByteLength = 0;
|
18616 | var tech = this.mediaSource_.tech_;
|
18617 | var videoTargetPts = 0;
|
18618 | var segment = undefined;
|
18619 | var videoTags = segmentData.tags.videoTags;
|
18620 | var audioTags = segmentData.tags.audioTags;
|
18621 |
|
18622 |
|
18623 |
|
18624 | if (isNaN(this.basePtsOffset_) && (videoTags.length || audioTags.length)) {
|
18625 |
|
18626 |
|
18627 |
|
18628 | var firstVideoTag = videoTags[0] || { pts: Infinity };
|
18629 | var firstAudioTag = audioTags[0] || { pts: Infinity };
|
18630 |
|
18631 | this.basePtsOffset_ = Math.min(firstAudioTag.pts, firstVideoTag.pts);
|
18632 | }
|
18633 |
|
18634 | if (tech.seeking()) {
|
18635 |
|
18636 |
|
18637 | this.videoBufferEnd_ = NaN;
|
18638 | this.audioBufferEnd_ = NaN;
|
18639 | }
|
18640 |
|
18641 | if (isNaN(this.videoBufferEnd_)) {
|
18642 | if (tech.buffered().length) {
|
18643 | videoTargetPts = tech.buffered().end(0) - this.timestampOffset;
|
18644 | }
|
18645 |
|
18646 |
|
18647 | if (tech.seeking()) {
|
18648 | videoTargetPts = Math.max(videoTargetPts, tech.currentTime() - this.timestampOffset);
|
18649 | }
|
18650 |
|
18651 |
|
18652 | videoTargetPts *= 1e3;
|
18653 | videoTargetPts += this.basePtsOffset_;
|
18654 | } else {
|
18655 |
|
18656 |
|
18657 |
|
18658 |
|
18659 |
|
18660 | videoTargetPts = this.videoBufferEnd_ + 0.1;
|
18661 | }
|
18662 |
|
18663 |
|
18664 | var currentIndex = videoTags.length;
|
18665 |
|
18666 |
|
18667 |
|
18668 | if (currentIndex && videoTags[currentIndex - 1].pts >= videoTargetPts) {
|
18669 |
|
18670 |
|
18671 | while (--currentIndex) {
|
18672 | var currentTag = videoTags[currentIndex];
|
18673 |
|
18674 | if (currentTag.pts > videoTargetPts) {
|
18675 | continue;
|
18676 | }
|
18677 |
|
18678 |
|
18679 |
|
18680 | if (currentTag.keyFrame || currentTag.metaDataTag) {
|
18681 | break;
|
18682 | }
|
18683 | }
|
18684 |
|
18685 |
|
18686 |
|
18687 |
|
18688 |
|
18689 |
|
18690 | while (currentIndex) {
|
18691 | var nextTag = videoTags[currentIndex - 1];
|
18692 |
|
18693 | if (!nextTag.metaDataTag) {
|
18694 | break;
|
18695 | }
|
18696 |
|
18697 | currentIndex--;
|
18698 | }
|
18699 | }
|
18700 |
|
18701 | var filteredVideoTags = videoTags.slice(currentIndex);
|
18702 |
|
18703 | var audioTargetPts = undefined;
|
18704 |
|
18705 | if (isNaN(this.audioBufferEnd_)) {
|
18706 | audioTargetPts = videoTargetPts;
|
18707 | } else {
|
18708 |
|
18709 |
|
18710 |
|
18711 |
|
18712 |
|
18713 | audioTargetPts = this.audioBufferEnd_ + 0.1;
|
18714 | }
|
18715 |
|
18716 | if (filteredVideoTags.length) {
|
18717 |
|
18718 |
|
18719 |
|
18720 | audioTargetPts = Math.min(audioTargetPts, filteredVideoTags[0].pts);
|
18721 | }
|
18722 |
|
18723 |
|
18724 | currentIndex = 0;
|
18725 |
|
18726 | while (currentIndex < audioTags.length) {
|
18727 | if (audioTags[currentIndex].pts >= audioTargetPts) {
|
18728 | break;
|
18729 | }
|
18730 |
|
18731 | currentIndex++;
|
18732 | }
|
18733 |
|
18734 | var filteredAudioTags = audioTags.slice(currentIndex);
|
18735 |
|
18736 |
|
18737 | if (filteredAudioTags.length) {
|
18738 | this.audioBufferEnd_ = filteredAudioTags[filteredAudioTags.length - 1].pts;
|
18739 | }
|
18740 | if (filteredVideoTags.length) {
|
18741 | this.videoBufferEnd_ = filteredVideoTags[filteredVideoTags.length - 1].pts;
|
18742 | }
|
18743 |
|
18744 | var tags = this.getOrderedTags_(filteredVideoTags, filteredAudioTags);
|
18745 |
|
18746 | if (tags.length === 0) {
|
18747 | return;
|
18748 | }
|
18749 |
|
18750 |
|
18751 |
|
18752 |
|
18753 | if (tags[0].pts < videoTargetPts && tech.seeking()) {
|
18754 | var fudgeFactor = 1 / 30;
|
18755 | var currentTime = tech.currentTime();
|
18756 | var diff = (videoTargetPts - tags[0].pts) / 1e3;
|
18757 | var adjustedTime = currentTime - diff;
|
18758 |
|
18759 | if (adjustedTime < fudgeFactor) {
|
18760 | adjustedTime = 0;
|
18761 | }
|
18762 |
|
18763 | try {
|
18764 | this.mediaSource_.swfObj.vjs_adjustCurrentTime(adjustedTime);
|
18765 | } catch (e) {
|
18766 |
|
18767 |
|
18768 |
|
18769 |
|
18770 | }
|
18771 | }
|
18772 |
|
18773 |
|
18774 | for (var i = 0; i < tags.length; i++) {
|
18775 | segmentByteLength += tags[i].bytes.byteLength;
|
18776 | }
|
18777 | segment = new Uint8Array(segmentByteLength);
|
18778 | for (var i = 0, j = 0; i < tags.length; i++) {
|
18779 | segment.set(tags[i].bytes, j);
|
18780 | j += tags[i].bytes.byteLength;
|
18781 | }
|
18782 |
|
18783 | return segment;
|
18784 | }
|
18785 |
|
18786 | |
18787 |
|
18788 |
|
18789 |
|
18790 |
|
18791 |
|
18792 |
|
18793 | }, {
|
18794 | key: 'getOrderedTags_',
|
18795 | value: function getOrderedTags_(videoTags, audioTags) {
|
18796 | var tag = undefined;
|
18797 | var tags = [];
|
18798 |
|
18799 | while (videoTags.length || audioTags.length) {
|
18800 | if (!videoTags.length) {
|
18801 |
|
18802 | tag = audioTags.shift();
|
18803 | } else if (!audioTags.length) {
|
18804 |
|
18805 | tag = videoTags.shift();
|
18806 | } else if (audioTags[0].dts < videoTags[0].dts) {
|
18807 |
|
18808 | tag = audioTags.shift();
|
18809 | } else {
|
18810 |
|
18811 | tag = videoTags.shift();
|
18812 | }
|
18813 |
|
18814 | tags.push(tag);
|
18815 | }
|
18816 |
|
18817 | return tags;
|
18818 | }
|
18819 | }, {
|
18820 | key: 'onHlsReset_',
|
18821 | value: function onHlsReset_() {
|
18822 | this.transmuxer_.postMessage({ action: 'resetCaptions' });
|
18823 | }
|
18824 | }]);
|
18825 |
|
18826 | return FlashSourceBuffer;
|
18827 | })(_videoJs2['default'].EventTarget);
|
18828 |
|
18829 | exports['default'] = FlashSourceBuffer;
|
18830 | module.exports = exports['default'];
|
18831 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
18832 | },{"./add-text-track-data":64,"./create-text-tracks-if-necessary":66,"./flash-constants":67,"./flash-transmuxer-worker":70,"./remove-cues-from-track":72,"global/window":32,"mux.js/lib/flv":46,"webworkify":76}],70:[function(require,module,exports){
|
18833 |
|
18834 |
|
18835 |
|
18836 | 'use strict';
|
18837 |
|
18838 | Object.defineProperty(exports, '__esModule', {
|
18839 | value: true
|
18840 | });
|
18841 |
|
18842 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
18843 |
|
18844 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
18845 |
|
18846 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
18847 |
|
18848 | var _globalWindow = require('global/window');
|
18849 |
|
18850 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
18851 |
|
18852 | var _muxJsLibFlv = require('mux.js/lib/flv');
|
18853 |
|
18854 | var _muxJsLibFlv2 = _interopRequireDefault(_muxJsLibFlv);
|
18855 |
|
18856 |
|
18857 |
|
18858 |
|
18859 |
|
18860 |
|
18861 |
|
18862 |
|
18863 | var wireTransmuxerEvents = function wireTransmuxerEvents(transmuxer) {
|
18864 | transmuxer.on('data', function (segment) {
|
18865 | _globalWindow2['default'].postMessage({
|
18866 | action: 'data',
|
18867 | segment: segment
|
18868 | });
|
18869 | });
|
18870 |
|
18871 | transmuxer.on('done', function (data) {
|
18872 | _globalWindow2['default'].postMessage({ action: 'done' });
|
18873 | });
|
18874 | };
|
18875 |
|
18876 |
|
18877 |
|
18878 |
|
18879 |
|
18880 |
|
18881 |
|
18882 |
|
18883 |
|
18884 | var MessageHandlers = (function () {
|
18885 | function MessageHandlers(options) {
|
18886 | _classCallCheck(this, MessageHandlers);
|
18887 |
|
18888 | this.options = options || {};
|
18889 | this.init();
|
18890 | }
|
18891 |
|
18892 | |
18893 |
|
18894 |
|
18895 |
|
18896 |
|
18897 |
|
18898 |
|
18899 |
|
18900 | |
18901 |
|
18902 |
|
18903 |
|
18904 | _createClass(MessageHandlers, [{
|
18905 | key: 'init',
|
18906 | value: function init() {
|
18907 | if (this.transmuxer) {
|
18908 | this.transmuxer.dispose();
|
18909 | }
|
18910 | this.transmuxer = new _muxJsLibFlv2['default'].Transmuxer(this.options);
|
18911 | wireTransmuxerEvents(this.transmuxer);
|
18912 | }
|
18913 |
|
18914 | |
18915 |
|
18916 |
|
18917 |
|
18918 |
|
18919 |
|
18920 | }, {
|
18921 | key: 'push',
|
18922 | value: function push(data) {
|
18923 |
|
18924 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
18925 |
|
18926 | this.transmuxer.push(segment);
|
18927 | }
|
18928 |
|
18929 | |
18930 |
|
18931 |
|
18932 |
|
18933 | }, {
|
18934 | key: 'reset',
|
18935 | value: function reset() {
|
18936 | this.init();
|
18937 | }
|
18938 |
|
18939 | |
18940 |
|
18941 |
|
18942 |
|
18943 | }, {
|
18944 | key: 'flush',
|
18945 | value: function flush() {
|
18946 | this.transmuxer.flush();
|
18947 | }
|
18948 | }, {
|
18949 | key: 'resetCaptions',
|
18950 | value: function resetCaptions() {
|
18951 | this.transmuxer.resetCaptions();
|
18952 | }
|
18953 | }]);
|
18954 |
|
18955 | return MessageHandlers;
|
18956 | })();
|
18957 |
|
18958 | var FlashTransmuxerWorker = function FlashTransmuxerWorker(self) {
|
18959 | self.onmessage = function (event) {
|
18960 | if (event.data.action === 'init' && event.data.options) {
|
18961 | this.messageHandlers = new MessageHandlers(event.data.options);
|
18962 | return;
|
18963 | }
|
18964 |
|
18965 | if (!this.messageHandlers) {
|
18966 | this.messageHandlers = new MessageHandlers();
|
18967 | }
|
18968 |
|
18969 | if (event.data && event.data.action && event.data.action !== 'init') {
|
18970 | if (this.messageHandlers[event.data.action]) {
|
18971 | this.messageHandlers[event.data.action](event.data);
|
18972 | }
|
18973 | }
|
18974 | };
|
18975 | };
|
18976 |
|
18977 | exports['default'] = function (self) {
|
18978 | return new FlashTransmuxerWorker(self);
|
18979 | };
|
18980 |
|
18981 | module.exports = exports['default'];
|
18982 | },{"global/window":32,"mux.js/lib/flv":46}],71:[function(require,module,exports){
|
18983 | (function (global){
|
18984 |
|
18985 |
|
18986 |
|
18987 | 'use strict';
|
18988 |
|
18989 | Object.defineProperty(exports, '__esModule', {
|
18990 | value: true
|
18991 | });
|
18992 |
|
18993 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
18994 |
|
18995 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
18996 |
|
18997 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
18998 |
|
18999 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
19000 |
|
19001 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
19002 |
|
19003 | var _globalWindow = require('global/window');
|
19004 |
|
19005 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
19006 |
|
19007 | var _globalDocument = require('global/document');
|
19008 |
|
19009 | var _globalDocument2 = _interopRequireDefault(_globalDocument);
|
19010 |
|
19011 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
19012 |
|
19013 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
19014 |
|
19015 | var _virtualSourceBuffer = require('./virtual-source-buffer');
|
19016 |
|
19017 | var _virtualSourceBuffer2 = _interopRequireDefault(_virtualSourceBuffer);
|
19018 |
|
19019 | var _addTextTrackData = require('./add-text-track-data');
|
19020 |
|
19021 | var _codecUtils = require('./codec-utils');
|
19022 |
|
19023 |
|
19024 |
|
19025 |
|
19026 |
|
19027 |
|
19028 |
|
19029 |
|
19030 |
|
19031 |
|
19032 | var HtmlMediaSource = (function (_videojs$EventTarget) {
|
19033 | _inherits(HtmlMediaSource, _videojs$EventTarget);
|
19034 |
|
19035 | function HtmlMediaSource() {
|
19036 | var _this = this;
|
19037 |
|
19038 | _classCallCheck(this, HtmlMediaSource);
|
19039 |
|
19040 | _get(Object.getPrototypeOf(HtmlMediaSource.prototype), 'constructor', this).call(this);
|
19041 | var property = undefined;
|
19042 |
|
19043 | this.nativeMediaSource_ = new _globalWindow2['default'].MediaSource();
|
19044 |
|
19045 | for (property in this.nativeMediaSource_) {
|
19046 | if (!(property in HtmlMediaSource.prototype) && typeof this.nativeMediaSource_[property] === 'function') {
|
19047 | this[property] = this.nativeMediaSource_[property].bind(this.nativeMediaSource_);
|
19048 | }
|
19049 | }
|
19050 |
|
19051 |
|
19052 |
|
19053 |
|
19054 | this.duration_ = NaN;
|
19055 | Object.defineProperty(this, 'duration', {
|
19056 | get: function get() {
|
19057 | if (this.duration_ === Infinity) {
|
19058 | return this.duration_;
|
19059 | }
|
19060 | return this.nativeMediaSource_.duration;
|
19061 | },
|
19062 | set: function set(duration) {
|
19063 | this.duration_ = duration;
|
19064 | if (duration !== Infinity) {
|
19065 | this.nativeMediaSource_.duration = duration;
|
19066 | return;
|
19067 | }
|
19068 | }
|
19069 | });
|
19070 | Object.defineProperty(this, 'seekable', {
|
19071 | get: function get() {
|
19072 | if (this.duration_ === Infinity) {
|
19073 | return _videoJs2['default'].createTimeRanges([[0, this.nativeMediaSource_.duration]]);
|
19074 | }
|
19075 | return this.nativeMediaSource_.seekable;
|
19076 | }
|
19077 | });
|
19078 |
|
19079 | Object.defineProperty(this, 'readyState', {
|
19080 | get: function get() {
|
19081 | return this.nativeMediaSource_.readyState;
|
19082 | }
|
19083 | });
|
19084 |
|
19085 | Object.defineProperty(this, 'activeSourceBuffers', {
|
19086 | get: function get() {
|
19087 | return this.activeSourceBuffers_;
|
19088 | }
|
19089 | });
|
19090 |
|
19091 |
|
19092 |
|
19093 | this.sourceBuffers = [];
|
19094 |
|
19095 | this.activeSourceBuffers_ = [];
|
19096 |
|
19097 | |
19098 |
|
19099 |
|
19100 |
|
19101 |
|
19102 |
|
19103 | this.updateActiveSourceBuffers_ = function () {
|
19104 |
|
19105 | _this.activeSourceBuffers_.length = 0;
|
19106 |
|
19107 |
|
19108 |
|
19109 | if (_this.sourceBuffers.length === 1) {
|
19110 | var sourceBuffer = _this.sourceBuffers[0];
|
19111 |
|
19112 | sourceBuffer.appendAudioInitSegment_ = true;
|
19113 | sourceBuffer.audioDisabled_ = !sourceBuffer.audioCodec_;
|
19114 | _this.activeSourceBuffers_.push(sourceBuffer);
|
19115 | return;
|
19116 | }
|
19117 |
|
19118 |
|
19119 |
|
19120 |
|
19121 |
|
19122 | var disableCombined = false;
|
19123 | var disableAudioOnly = true;
|
19124 |
|
19125 |
|
19126 |
|
19127 | for (var i = 0; i < _this.player_.audioTracks().length; i++) {
|
19128 | var track = _this.player_.audioTracks()[i];
|
19129 |
|
19130 | if (track.enabled && track.kind !== 'main') {
|
19131 |
|
19132 |
|
19133 | disableCombined = true;
|
19134 | disableAudioOnly = false;
|
19135 | break;
|
19136 | }
|
19137 | }
|
19138 |
|
19139 | _this.sourceBuffers.forEach(function (sourceBuffer) {
|
19140 |
|
19141 |
|
19142 |
|
19143 |
|
19144 |
|
19145 | sourceBuffer.appendAudioInitSegment_ = true;
|
19146 |
|
19147 | if (sourceBuffer.videoCodec_ && sourceBuffer.audioCodec_) {
|
19148 |
|
19149 | sourceBuffer.audioDisabled_ = disableCombined;
|
19150 | } else if (sourceBuffer.videoCodec_ && !sourceBuffer.audioCodec_) {
|
19151 |
|
19152 |
|
19153 |
|
19154 | sourceBuffer.audioDisabled_ = true;
|
19155 | disableAudioOnly = false;
|
19156 | } else if (!sourceBuffer.videoCodec_ && sourceBuffer.audioCodec_) {
|
19157 |
|
19158 | sourceBuffer.audioDisabled_ = disableAudioOnly;
|
19159 | if (disableAudioOnly) {
|
19160 | return;
|
19161 | }
|
19162 | }
|
19163 |
|
19164 | _this.activeSourceBuffers_.push(sourceBuffer);
|
19165 | });
|
19166 | };
|
19167 |
|
19168 | this.onPlayerMediachange_ = function () {
|
19169 | _this.sourceBuffers.forEach(function (sourceBuffer) {
|
19170 | sourceBuffer.appendAudioInitSegment_ = true;
|
19171 | });
|
19172 | };
|
19173 |
|
19174 | this.onHlsReset_ = function () {
|
19175 | _this.sourceBuffers.forEach(function (sourceBuffer) {
|
19176 | if (sourceBuffer.transmuxer_) {
|
19177 | sourceBuffer.transmuxer_.postMessage({ action: 'resetCaptions' });
|
19178 | }
|
19179 | });
|
19180 | };
|
19181 |
|
19182 | this.onHlsSegmentTimeMapping_ = function (event) {
|
19183 | _this.sourceBuffers.forEach(function (buffer) {
|
19184 | return buffer.timeMapping_ = event.mapping;
|
19185 | });
|
19186 | };
|
19187 |
|
19188 |
|
19189 | ['sourceopen', 'sourceclose', 'sourceended'].forEach(function (eventName) {
|
19190 | this.nativeMediaSource_.addEventListener(eventName, this.trigger.bind(this));
|
19191 | }, this);
|
19192 |
|
19193 |
|
19194 |
|
19195 | this.on('sourceopen', function (event) {
|
19196 |
|
19197 | var video = _globalDocument2['default'].querySelector('[src="' + _this.url_ + '"]');
|
19198 |
|
19199 | if (!video) {
|
19200 | return;
|
19201 | }
|
19202 |
|
19203 | _this.player_ = (0, _videoJs2['default'])(video.parentNode);
|
19204 |
|
19205 |
|
19206 |
|
19207 | _this.player_.tech_.on('hls-reset', _this.onHlsReset_);
|
19208 |
|
19209 |
|
19210 |
|
19211 | _this.player_.tech_.on('hls-segment-time-mapping', _this.onHlsSegmentTimeMapping_);
|
19212 |
|
19213 | if (_this.player_.audioTracks && _this.player_.audioTracks()) {
|
19214 | _this.player_.audioTracks().on('change', _this.updateActiveSourceBuffers_);
|
19215 | _this.player_.audioTracks().on('addtrack', _this.updateActiveSourceBuffers_);
|
19216 | _this.player_.audioTracks().on('removetrack', _this.updateActiveSourceBuffers_);
|
19217 | }
|
19218 |
|
19219 | _this.player_.on('mediachange', _this.onPlayerMediachange_);
|
19220 | });
|
19221 |
|
19222 | this.on('sourceended', function (event) {
|
19223 | var duration = (0, _addTextTrackData.durationOfVideo)(_this.duration);
|
19224 |
|
19225 | for (var i = 0; i < _this.sourceBuffers.length; i++) {
|
19226 | var sourcebuffer = _this.sourceBuffers[i];
|
19227 | var cues = sourcebuffer.metadataTrack_ && sourcebuffer.metadataTrack_.cues;
|
19228 |
|
19229 | if (cues && cues.length) {
|
19230 | cues[cues.length - 1].endTime = duration;
|
19231 | }
|
19232 | }
|
19233 | });
|
19234 |
|
19235 |
|
19236 |
|
19237 | this.on('sourceclose', function (event) {
|
19238 | this.sourceBuffers.forEach(function (sourceBuffer) {
|
19239 | if (sourceBuffer.transmuxer_) {
|
19240 | sourceBuffer.transmuxer_.terminate();
|
19241 | }
|
19242 | });
|
19243 |
|
19244 | this.sourceBuffers.length = 0;
|
19245 | if (!this.player_) {
|
19246 | return;
|
19247 | }
|
19248 |
|
19249 | if (this.player_.audioTracks && this.player_.audioTracks()) {
|
19250 | this.player_.audioTracks().off('change', this.updateActiveSourceBuffers_);
|
19251 | this.player_.audioTracks().off('addtrack', this.updateActiveSourceBuffers_);
|
19252 | this.player_.audioTracks().off('removetrack', this.updateActiveSourceBuffers_);
|
19253 | }
|
19254 |
|
19255 |
|
19256 |
|
19257 |
|
19258 |
|
19259 | if (this.player_.el_) {
|
19260 | this.player_.off('mediachange', this.onPlayerMediachange_);
|
19261 | this.player_.tech_.off('hls-reset', this.onHlsReset_);
|
19262 | this.player_.tech_.off('hls-segment-time-mapping', this.onHlsSegmentTimeMapping_);
|
19263 | }
|
19264 | });
|
19265 | }
|
19266 |
|
19267 | |
19268 |
|
19269 |
|
19270 |
|
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 | _createClass(HtmlMediaSource, [{
|
19276 | key: 'addSeekableRange_',
|
19277 | value: function addSeekableRange_(start, end) {
|
19278 | var error = undefined;
|
19279 |
|
19280 | if (this.duration !== Infinity) {
|
19281 | error = new Error('MediaSource.addSeekableRange() can only be invoked ' + 'when the duration is Infinity');
|
19282 | error.name = 'InvalidStateError';
|
19283 | error.code = 11;
|
19284 | throw error;
|
19285 | }
|
19286 |
|
19287 | if (end > this.nativeMediaSource_.duration || isNaN(this.nativeMediaSource_.duration)) {
|
19288 | this.nativeMediaSource_.duration = end;
|
19289 | }
|
19290 | }
|
19291 |
|
19292 | |
19293 |
|
19294 |
|
19295 |
|
19296 |
|
19297 |
|
19298 |
|
19299 | }, {
|
19300 | key: 'addSourceBuffer',
|
19301 | value: function addSourceBuffer(type) {
|
19302 | var buffer = undefined;
|
19303 | var parsedType = (0, _codecUtils.parseContentType)(type);
|
19304 |
|
19305 |
|
19306 |
|
19307 | if (/^(video|audio)\/mp2t$/i.test(parsedType.type)) {
|
19308 | var codecs = [];
|
19309 |
|
19310 | if (parsedType.parameters && parsedType.parameters.codecs) {
|
19311 | codecs = parsedType.parameters.codecs.split(',');
|
19312 | codecs = (0, _codecUtils.translateLegacyCodecs)(codecs);
|
19313 | codecs = codecs.filter(function (codec) {
|
19314 | return (0, _codecUtils.isAudioCodec)(codec) || (0, _codecUtils.isVideoCodec)(codec);
|
19315 | });
|
19316 | }
|
19317 |
|
19318 | if (codecs.length === 0) {
|
19319 | codecs = ['avc1.4d400d', 'mp4a.40.2'];
|
19320 | }
|
19321 |
|
19322 | buffer = new _virtualSourceBuffer2['default'](this, codecs);
|
19323 |
|
19324 | if (this.sourceBuffers.length !== 0) {
|
19325 |
|
19326 |
|
19327 |
|
19328 |
|
19329 |
|
19330 | this.sourceBuffers[0].createRealSourceBuffers_();
|
19331 | buffer.createRealSourceBuffers_();
|
19332 |
|
19333 |
|
19334 |
|
19335 | this.sourceBuffers[0].audioDisabled_ = true;
|
19336 | }
|
19337 | } else {
|
19338 |
|
19339 | buffer = this.nativeMediaSource_.addSourceBuffer(type);
|
19340 | }
|
19341 |
|
19342 | this.sourceBuffers.push(buffer);
|
19343 | return buffer;
|
19344 | }
|
19345 | }]);
|
19346 |
|
19347 | return HtmlMediaSource;
|
19348 | })(_videoJs2['default'].EventTarget);
|
19349 |
|
19350 | exports['default'] = HtmlMediaSource;
|
19351 | module.exports = exports['default'];
|
19352 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
19353 | },{"./add-text-track-data":64,"./codec-utils":65,"./virtual-source-buffer":75,"global/document":31,"global/window":32}],72:[function(require,module,exports){
|
19354 |
|
19355 |
|
19356 |
|
19357 |
|
19358 |
|
19359 |
|
19360 |
|
19361 |
|
19362 |
|
19363 |
|
19364 |
|
19365 |
|
19366 | "use strict";
|
19367 |
|
19368 | Object.defineProperty(exports, "__esModule", {
|
19369 | value: true
|
19370 | });
|
19371 | var removeCuesFromTrack = function removeCuesFromTrack(start, end, track) {
|
19372 | var i = undefined;
|
19373 | var cue = undefined;
|
19374 |
|
19375 | if (!track) {
|
19376 | return;
|
19377 | }
|
19378 |
|
19379 | if (!track.cues) {
|
19380 | return;
|
19381 | }
|
19382 |
|
19383 | i = track.cues.length;
|
19384 |
|
19385 | while (i--) {
|
19386 | cue = track.cues[i];
|
19387 |
|
19388 |
|
19389 | if (cue.startTime <= end && cue.endTime >= start) {
|
19390 | track.removeCue(cue);
|
19391 | }
|
19392 | }
|
19393 | };
|
19394 |
|
19395 | exports["default"] = removeCuesFromTrack;
|
19396 | module.exports = exports["default"];
|
19397 | },{}],73:[function(require,module,exports){
|
19398 |
|
19399 |
|
19400 |
|
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 |
|
19407 |
|
19408 |
|
19409 |
|
19410 |
|
19411 |
|
19412 | 'use strict';
|
19413 |
|
19414 | Object.defineProperty(exports, '__esModule', {
|
19415 | value: true
|
19416 | });
|
19417 |
|
19418 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
19419 |
|
19420 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
19421 |
|
19422 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
19423 |
|
19424 | var _globalWindow = require('global/window');
|
19425 |
|
19426 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
19427 |
|
19428 | var _muxJsLibMp4 = require('mux.js/lib/mp4');
|
19429 |
|
19430 | var _muxJsLibMp42 = _interopRequireDefault(_muxJsLibMp4);
|
19431 |
|
19432 |
|
19433 |
|
19434 |
|
19435 |
|
19436 |
|
19437 |
|
19438 |
|
19439 | var wireTransmuxerEvents = function wireTransmuxerEvents(transmuxer) {
|
19440 | transmuxer.on('data', function (segment) {
|
19441 |
|
19442 |
|
19443 |
|
19444 |
|
19445 | var initArray = segment.initSegment;
|
19446 |
|
19447 | segment.initSegment = {
|
19448 | data: initArray.buffer,
|
19449 | byteOffset: initArray.byteOffset,
|
19450 | byteLength: initArray.byteLength
|
19451 | };
|
19452 |
|
19453 | var typedArray = segment.data;
|
19454 |
|
19455 | segment.data = typedArray.buffer;
|
19456 | _globalWindow2['default'].postMessage({
|
19457 | action: 'data',
|
19458 | segment: segment,
|
19459 | byteOffset: typedArray.byteOffset,
|
19460 | byteLength: typedArray.byteLength
|
19461 | }, [segment.data]);
|
19462 | });
|
19463 |
|
19464 | if (transmuxer.captionStream) {
|
19465 | transmuxer.captionStream.on('data', function (caption) {
|
19466 | _globalWindow2['default'].postMessage({
|
19467 | action: 'caption',
|
19468 | data: caption
|
19469 | });
|
19470 | });
|
19471 | }
|
19472 |
|
19473 | transmuxer.on('done', function (data) {
|
19474 | _globalWindow2['default'].postMessage({ action: 'done' });
|
19475 | });
|
19476 |
|
19477 | transmuxer.on('gopInfo', function (gopInfo) {
|
19478 | _globalWindow2['default'].postMessage({
|
19479 | action: 'gopInfo',
|
19480 | gopInfo: gopInfo
|
19481 | });
|
19482 | });
|
19483 | };
|
19484 |
|
19485 |
|
19486 |
|
19487 |
|
19488 |
|
19489 |
|
19490 |
|
19491 |
|
19492 |
|
19493 | var MessageHandlers = (function () {
|
19494 | function MessageHandlers(options) {
|
19495 | _classCallCheck(this, MessageHandlers);
|
19496 |
|
19497 | this.options = options || {};
|
19498 | this.init();
|
19499 | }
|
19500 |
|
19501 | |
19502 |
|
19503 |
|
19504 |
|
19505 |
|
19506 |
|
19507 |
|
19508 |
|
19509 | |
19510 |
|
19511 |
|
19512 |
|
19513 | _createClass(MessageHandlers, [{
|
19514 | key: 'init',
|
19515 | value: function init() {
|
19516 | if (this.transmuxer) {
|
19517 | this.transmuxer.dispose();
|
19518 | }
|
19519 | this.transmuxer = new _muxJsLibMp42['default'].Transmuxer(this.options);
|
19520 | wireTransmuxerEvents(this.transmuxer);
|
19521 | }
|
19522 |
|
19523 | |
19524 |
|
19525 |
|
19526 |
|
19527 |
|
19528 |
|
19529 | }, {
|
19530 | key: 'push',
|
19531 | value: function push(data) {
|
19532 |
|
19533 | var segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
|
19534 |
|
19535 | this.transmuxer.push(segment);
|
19536 | }
|
19537 |
|
19538 | |
19539 |
|
19540 |
|
19541 |
|
19542 | }, {
|
19543 | key: 'reset',
|
19544 | value: function reset() {
|
19545 | this.init();
|
19546 | }
|
19547 |
|
19548 | |
19549 |
|
19550 |
|
19551 |
|
19552 |
|
19553 |
|
19554 |
|
19555 | }, {
|
19556 | key: 'setTimestampOffset',
|
19557 | value: function setTimestampOffset(data) {
|
19558 | var timestampOffset = data.timestampOffset || 0;
|
19559 |
|
19560 | this.transmuxer.setBaseMediaDecodeTime(Math.round(timestampOffset * 90000));
|
19561 | }
|
19562 | }, {
|
19563 | key: 'setAudioAppendStart',
|
19564 | value: function setAudioAppendStart(data) {
|
19565 | this.transmuxer.setAudioAppendStart(Math.ceil(data.appendStart * 90000));
|
19566 | }
|
19567 |
|
19568 | |
19569 |
|
19570 |
|
19571 |
|
19572 |
|
19573 |
|
19574 | }, {
|
19575 | key: 'flush',
|
19576 | value: function flush(data) {
|
19577 | this.transmuxer.flush();
|
19578 | }
|
19579 | }, {
|
19580 | key: 'resetCaptions',
|
19581 | value: function resetCaptions() {
|
19582 | this.transmuxer.resetCaptions();
|
19583 | }
|
19584 | }, {
|
19585 | key: 'alignGopsWith',
|
19586 | value: function alignGopsWith(data) {
|
19587 | this.transmuxer.alignGopsWith(data.gopsToAlignWith.slice());
|
19588 | }
|
19589 | }]);
|
19590 |
|
19591 | return MessageHandlers;
|
19592 | })();
|
19593 |
|
19594 | var TransmuxerWorker = function TransmuxerWorker(self) {
|
19595 | self.onmessage = function (event) {
|
19596 | if (event.data.action === 'init' && event.data.options) {
|
19597 | this.messageHandlers = new MessageHandlers(event.data.options);
|
19598 | return;
|
19599 | }
|
19600 |
|
19601 | if (!this.messageHandlers) {
|
19602 | this.messageHandlers = new MessageHandlers();
|
19603 | }
|
19604 |
|
19605 | if (event.data && event.data.action && event.data.action !== 'init') {
|
19606 | if (this.messageHandlers[event.data.action]) {
|
19607 | this.messageHandlers[event.data.action](event.data);
|
19608 | }
|
19609 | }
|
19610 | };
|
19611 | };
|
19612 |
|
19613 | exports['default'] = function (self) {
|
19614 | return new TransmuxerWorker(self);
|
19615 | };
|
19616 |
|
19617 | module.exports = exports['default'];
|
19618 | },{"global/window":32,"mux.js/lib/mp4":55}],74:[function(require,module,exports){
|
19619 | (function (global){
|
19620 |
|
19621 |
|
19622 |
|
19623 | 'use strict';
|
19624 |
|
19625 | Object.defineProperty(exports, '__esModule', {
|
19626 | value: true
|
19627 | });
|
19628 |
|
19629 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
19630 |
|
19631 | var _globalWindow = require('global/window');
|
19632 |
|
19633 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
19634 |
|
19635 | var _flashMediaSource = require('./flash-media-source');
|
19636 |
|
19637 | var _flashMediaSource2 = _interopRequireDefault(_flashMediaSource);
|
19638 |
|
19639 | var _htmlMediaSource = require('./html-media-source');
|
19640 |
|
19641 | var _htmlMediaSource2 = _interopRequireDefault(_htmlMediaSource);
|
19642 |
|
19643 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
19644 |
|
19645 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
19646 |
|
19647 | var urlCount = 0;
|
19648 |
|
19649 |
|
19650 |
|
19651 |
|
19652 |
|
19653 | var defaults = {
|
19654 |
|
19655 |
|
19656 |
|
19657 |
|
19658 |
|
19659 |
|
19660 | mode: 'auto'
|
19661 | };
|
19662 |
|
19663 |
|
19664 |
|
19665 |
|
19666 | _videoJs2['default'].mediaSources = {};
|
19667 |
|
19668 |
|
19669 |
|
19670 |
|
19671 |
|
19672 |
|
19673 |
|
19674 |
|
19675 | var open = function open(msObjectURL, swfId) {
|
19676 | var mediaSource = _videoJs2['default'].mediaSources[msObjectURL];
|
19677 |
|
19678 | if (mediaSource) {
|
19679 | mediaSource.trigger({ type: 'sourceopen', swfId: swfId });
|
19680 | } else {
|
19681 | throw new Error('Media Source not found (Video.js)');
|
19682 | }
|
19683 | };
|
19684 |
|
19685 |
|
19686 |
|
19687 |
|
19688 |
|
19689 |
|
19690 |
|
19691 | var supportsNativeMediaSources = function supportsNativeMediaSources() {
|
19692 | return !!_globalWindow2['default'].MediaSource && !!_globalWindow2['default'].MediaSource.isTypeSupported && _globalWindow2['default'].MediaSource.isTypeSupported('video/mp4;codecs="avc1.4d400d,mp4a.40.2"');
|
19693 | };
|
19694 |
|
19695 |
|
19696 |
|
19697 |
|
19698 |
|
19699 |
|
19700 |
|
19701 |
|
19702 |
|
19703 |
|
19704 |
|
19705 | var MediaSource = function MediaSource(options) {
|
19706 | var settings = _videoJs2['default'].mergeOptions(defaults, options);
|
19707 |
|
19708 | this.MediaSource = {
|
19709 | open: open,
|
19710 | supportsNativeMediaSources: supportsNativeMediaSources
|
19711 | };
|
19712 |
|
19713 |
|
19714 | if (settings.mode === 'html5' || settings.mode === 'auto' && supportsNativeMediaSources()) {
|
19715 | return new _htmlMediaSource2['default']();
|
19716 | } else if (_videoJs2['default'].getTech('Flash')) {
|
19717 | return new _flashMediaSource2['default']();
|
19718 | }
|
19719 |
|
19720 | throw new Error('Cannot use Flash or Html5 to create a MediaSource for this video');
|
19721 | };
|
19722 |
|
19723 | exports.MediaSource = MediaSource;
|
19724 | MediaSource.open = open;
|
19725 | MediaSource.supportsNativeMediaSources = supportsNativeMediaSources;
|
19726 |
|
19727 |
|
19728 |
|
19729 |
|
19730 |
|
19731 |
|
19732 |
|
19733 | var URL = {
|
19734 | |
19735 |
|
19736 |
|
19737 |
|
19738 |
|
19739 |
|
19740 |
|
19741 |
|
19742 | createObjectURL: function createObjectURL(object) {
|
19743 | var objectUrlPrefix = 'blob:vjs-media-source/';
|
19744 | var url = undefined;
|
19745 |
|
19746 |
|
19747 | if (object instanceof _htmlMediaSource2['default']) {
|
19748 | url = _globalWindow2['default'].URL.createObjectURL(object.nativeMediaSource_);
|
19749 | object.url_ = url;
|
19750 | return url;
|
19751 | }
|
19752 |
|
19753 |
|
19754 | if (!(object instanceof _flashMediaSource2['default'])) {
|
19755 | url = _globalWindow2['default'].URL.createObjectURL(object);
|
19756 | object.url_ = url;
|
19757 | return url;
|
19758 | }
|
19759 |
|
19760 |
|
19761 |
|
19762 | url = objectUrlPrefix + urlCount;
|
19763 |
|
19764 | urlCount++;
|
19765 |
|
19766 |
|
19767 | _videoJs2['default'].mediaSources[url] = object;
|
19768 |
|
19769 | return url;
|
19770 | }
|
19771 | };
|
19772 |
|
19773 | exports.URL = URL;
|
19774 | _videoJs2['default'].MediaSource = MediaSource;
|
19775 | _videoJs2['default'].URL = URL;
|
19776 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
19777 | },{"./flash-media-source":68,"./html-media-source":71,"global/window":32}],75:[function(require,module,exports){
|
19778 | (function (global){
|
19779 |
|
19780 |
|
19781 |
|
19782 | 'use strict';
|
19783 |
|
19784 | Object.defineProperty(exports, '__esModule', {
|
19785 | value: true
|
19786 | });
|
19787 |
|
19788 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
19789 |
|
19790 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
19791 |
|
19792 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
19793 |
|
19794 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
19795 |
|
19796 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
19797 |
|
19798 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
19799 |
|
19800 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
19801 |
|
19802 | var _createTextTracksIfNecessary = require('./create-text-tracks-if-necessary');
|
19803 |
|
19804 | var _createTextTracksIfNecessary2 = _interopRequireDefault(_createTextTracksIfNecessary);
|
19805 |
|
19806 | var _removeCuesFromTrack = require('./remove-cues-from-track');
|
19807 |
|
19808 | var _removeCuesFromTrack2 = _interopRequireDefault(_removeCuesFromTrack);
|
19809 |
|
19810 | var _addTextTrackData = require('./add-text-track-data');
|
19811 |
|
19812 | var _webworkify = require('webworkify');
|
19813 |
|
19814 | var _webworkify2 = _interopRequireDefault(_webworkify);
|
19815 |
|
19816 | var _transmuxerWorker = require('./transmuxer-worker');
|
19817 |
|
19818 | var _transmuxerWorker2 = _interopRequireDefault(_transmuxerWorker);
|
19819 |
|
19820 | var _codecUtils = require('./codec-utils');
|
19821 |
|
19822 |
|
19823 |
|
19824 |
|
19825 |
|
19826 | var makeWrappedSourceBuffer = function makeWrappedSourceBuffer(mediaSource, mimeType) {
|
19827 | var sourceBuffer = mediaSource.addSourceBuffer(mimeType);
|
19828 | var wrapper = Object.create(null);
|
19829 |
|
19830 | wrapper.updating = false;
|
19831 | wrapper.realBuffer_ = sourceBuffer;
|
19832 |
|
19833 | var _loop = function (key) {
|
19834 | if (typeof sourceBuffer[key] === 'function') {
|
19835 | wrapper[key] = function () {
|
19836 | return sourceBuffer[key].apply(sourceBuffer, arguments);
|
19837 | };
|
19838 | } else if (typeof wrapper[key] === 'undefined') {
|
19839 | Object.defineProperty(wrapper, key, {
|
19840 | get: function get() {
|
19841 | return sourceBuffer[key];
|
19842 | },
|
19843 | set: function set(v) {
|
19844 | return sourceBuffer[key] = v;
|
19845 | }
|
19846 | });
|
19847 | }
|
19848 | };
|
19849 |
|
19850 | for (var key in sourceBuffer) {
|
19851 | _loop(key);
|
19852 | }
|
19853 |
|
19854 | return wrapper;
|
19855 | };
|
19856 |
|
19857 |
|
19858 |
|
19859 |
|
19860 |
|
19861 |
|
19862 |
|
19863 |
|
19864 |
|
19865 |
|
19866 |
|
19867 |
|
19868 |
|
19869 |
|
19870 | var gopsSafeToAlignWith = function gopsSafeToAlignWith(buffer, player, mapping) {
|
19871 | if (!player || !buffer.length) {
|
19872 | return [];
|
19873 | }
|
19874 |
|
19875 |
|
19876 | var currentTimePts = Math.ceil((player.currentTime() - mapping + 3) * 90000);
|
19877 |
|
19878 | var i = undefined;
|
19879 |
|
19880 | for (i = 0; i < buffer.length; i++) {
|
19881 | if (buffer[i].pts > currentTimePts) {
|
19882 | break;
|
19883 | }
|
19884 | }
|
19885 |
|
19886 | return buffer.slice(i);
|
19887 | };
|
19888 |
|
19889 | exports.gopsSafeToAlignWith = gopsSafeToAlignWith;
|
19890 |
|
19891 |
|
19892 |
|
19893 |
|
19894 |
|
19895 |
|
19896 |
|
19897 |
|
19898 |
|
19899 |
|
19900 |
|
19901 |
|
19902 |
|
19903 |
|
19904 | var updateGopBuffer = function updateGopBuffer(buffer, gops, replace) {
|
19905 | if (!gops.length) {
|
19906 | return buffer;
|
19907 | }
|
19908 |
|
19909 | if (replace) {
|
19910 |
|
19911 |
|
19912 |
|
19913 |
|
19914 | return gops.slice();
|
19915 | }
|
19916 |
|
19917 | var start = gops[0].pts;
|
19918 |
|
19919 | var i = 0;
|
19920 |
|
19921 | for (i; i < buffer.length; i++) {
|
19922 | if (buffer[i].pts >= start) {
|
19923 | break;
|
19924 | }
|
19925 | }
|
19926 |
|
19927 | return buffer.slice(0, i).concat(gops);
|
19928 | };
|
19929 |
|
19930 | exports.updateGopBuffer = updateGopBuffer;
|
19931 |
|
19932 |
|
19933 |
|
19934 |
|
19935 |
|
19936 |
|
19937 |
|
19938 |
|
19939 |
|
19940 |
|
19941 |
|
19942 |
|
19943 | var removeGopBuffer = function removeGopBuffer(buffer, start, end, mapping) {
|
19944 | var startPts = Math.ceil((start - mapping) * 90000);
|
19945 | var endPts = Math.ceil((end - mapping) * 90000);
|
19946 | var updatedBuffer = buffer.slice();
|
19947 |
|
19948 | var i = buffer.length;
|
19949 |
|
19950 | while (i--) {
|
19951 | if (buffer[i].pts <= endPts) {
|
19952 | break;
|
19953 | }
|
19954 | }
|
19955 |
|
19956 | if (i === -1) {
|
19957 |
|
19958 | return updatedBuffer;
|
19959 | }
|
19960 |
|
19961 | var j = i + 1;
|
19962 |
|
19963 | while (j--) {
|
19964 | if (buffer[j].pts <= startPts) {
|
19965 | break;
|
19966 | }
|
19967 | }
|
19968 |
|
19969 |
|
19970 | j = Math.max(j, 0);
|
19971 |
|
19972 | updatedBuffer.splice(j, i - j + 1);
|
19973 |
|
19974 | return updatedBuffer;
|
19975 | };
|
19976 |
|
19977 | exports.removeGopBuffer = removeGopBuffer;
|
19978 |
|
19979 |
|
19980 |
|
19981 |
|
19982 |
|
19983 |
|
19984 |
|
19985 |
|
19986 |
|
19987 |
|
19988 |
|
19989 |
|
19990 |
|
19991 |
|
19992 | var VirtualSourceBuffer = (function (_videojs$EventTarget) {
|
19993 | _inherits(VirtualSourceBuffer, _videojs$EventTarget);
|
19994 |
|
19995 | function VirtualSourceBuffer(mediaSource, codecs) {
|
19996 | var _this = this;
|
19997 |
|
19998 | _classCallCheck(this, VirtualSourceBuffer);
|
19999 |
|
20000 | _get(Object.getPrototypeOf(VirtualSourceBuffer.prototype), 'constructor', this).call(this, _videoJs2['default'].EventTarget);
|
20001 | this.timestampOffset_ = 0;
|
20002 | this.pendingBuffers_ = [];
|
20003 | this.bufferUpdating_ = false;
|
20004 |
|
20005 | this.mediaSource_ = mediaSource;
|
20006 | this.codecs_ = codecs;
|
20007 | this.audioCodec_ = null;
|
20008 | this.videoCodec_ = null;
|
20009 | this.audioDisabled_ = false;
|
20010 | this.appendAudioInitSegment_ = true;
|
20011 | this.gopBuffer_ = [];
|
20012 | this.timeMapping_ = 0;
|
20013 | this.safeAppend_ = _videoJs2['default'].browser.IE_VERSION >= 11;
|
20014 |
|
20015 | var options = {
|
20016 | remux: false,
|
20017 | alignGopsAtEnd: this.safeAppend_
|
20018 | };
|
20019 |
|
20020 | this.codecs_.forEach(function (codec) {
|
20021 | if ((0, _codecUtils.isAudioCodec)(codec)) {
|
20022 | _this.audioCodec_ = codec;
|
20023 | } else if ((0, _codecUtils.isVideoCodec)(codec)) {
|
20024 | _this.videoCodec_ = codec;
|
20025 | }
|
20026 | });
|
20027 |
|
20028 |
|
20029 |
|
20030 | this.transmuxer_ = (0, _webworkify2['default'])(_transmuxerWorker2['default']);
|
20031 | this.transmuxer_.postMessage({ action: 'init', options: options });
|
20032 |
|
20033 | this.transmuxer_.onmessage = function (event) {
|
20034 | if (event.data.action === 'data') {
|
20035 | return _this.data_(event);
|
20036 | }
|
20037 |
|
20038 | if (event.data.action === 'done') {
|
20039 | return _this.done_(event);
|
20040 | }
|
20041 |
|
20042 | if (event.data.action === 'gopInfo') {
|
20043 | return _this.appendGopInfo_(event);
|
20044 | }
|
20045 | };
|
20046 |
|
20047 |
|
20048 |
|
20049 | Object.defineProperty(this, 'timestampOffset', {
|
20050 | get: function get() {
|
20051 | return this.timestampOffset_;
|
20052 | },
|
20053 | set: function set(val) {
|
20054 | if (typeof val === 'number' && val >= 0) {
|
20055 | this.timestampOffset_ = val;
|
20056 | this.appendAudioInitSegment_ = true;
|
20057 |
|
20058 |
|
20059 | this.gopBuffer_.length = 0;
|
20060 | this.timeMapping_ = 0;
|
20061 |
|
20062 |
|
20063 |
|
20064 | this.transmuxer_.postMessage({
|
20065 | action: 'setTimestampOffset',
|
20066 | timestampOffset: val
|
20067 | });
|
20068 | }
|
20069 | }
|
20070 | });
|
20071 |
|
20072 |
|
20073 | Object.defineProperty(this, 'appendWindowStart', {
|
20074 | get: function get() {
|
20075 | return (this.videoBuffer_ || this.audioBuffer_).appendWindowStart;
|
20076 | },
|
20077 | set: function set(start) {
|
20078 | if (this.videoBuffer_) {
|
20079 | this.videoBuffer_.appendWindowStart = start;
|
20080 | }
|
20081 | if (this.audioBuffer_) {
|
20082 | this.audioBuffer_.appendWindowStart = start;
|
20083 | }
|
20084 | }
|
20085 | });
|
20086 |
|
20087 |
|
20088 | Object.defineProperty(this, 'updating', {
|
20089 | get: function get() {
|
20090 | return !!(this.bufferUpdating_ || !this.audioDisabled_ && this.audioBuffer_ && this.audioBuffer_.updating || this.videoBuffer_ && this.videoBuffer_.updating);
|
20091 | }
|
20092 | });
|
20093 |
|
20094 |
|
20095 |
|
20096 | Object.defineProperty(this, 'buffered', {
|
20097 | get: function get() {
|
20098 | var start = null;
|
20099 | var end = null;
|
20100 | var arity = 0;
|
20101 | var extents = [];
|
20102 | var ranges = [];
|
20103 |
|
20104 |
|
20105 | if (!this.videoBuffer_ && !this.audioBuffer_) {
|
20106 | return _videoJs2['default'].createTimeRange();
|
20107 | }
|
20108 |
|
20109 |
|
20110 | if (!this.videoBuffer_) {
|
20111 | return this.audioBuffer_.buffered;
|
20112 | }
|
20113 | if (!this.audioBuffer_) {
|
20114 | return this.videoBuffer_.buffered;
|
20115 | }
|
20116 |
|
20117 |
|
20118 | if (this.audioDisabled_) {
|
20119 | return this.videoBuffer_.buffered;
|
20120 | }
|
20121 |
|
20122 |
|
20123 | if (this.videoBuffer_.buffered.length === 0 && this.audioBuffer_.buffered.length === 0) {
|
20124 | return _videoJs2['default'].createTimeRange();
|
20125 | }
|
20126 |
|
20127 |
|
20128 |
|
20129 | var videoBuffered = this.videoBuffer_.buffered;
|
20130 | var audioBuffered = this.audioBuffer_.buffered;
|
20131 | var count = videoBuffered.length;
|
20132 |
|
20133 |
|
20134 | while (count--) {
|
20135 | extents.push({ time: videoBuffered.start(count), type: 'start' });
|
20136 | extents.push({ time: videoBuffered.end(count), type: 'end' });
|
20137 | }
|
20138 | count = audioBuffered.length;
|
20139 | while (count--) {
|
20140 | extents.push({ time: audioBuffered.start(count), type: 'start' });
|
20141 | extents.push({ time: audioBuffered.end(count), type: 'end' });
|
20142 | }
|
20143 |
|
20144 | extents.sort(function (a, b) {
|
20145 | return a.time - b.time;
|
20146 | });
|
20147 |
|
20148 |
|
20149 |
|
20150 | for (count = 0; count < extents.length; count++) {
|
20151 | if (extents[count].type === 'start') {
|
20152 | arity++;
|
20153 |
|
20154 |
|
20155 |
|
20156 | if (arity === 2) {
|
20157 | start = extents[count].time;
|
20158 | }
|
20159 | } else if (extents[count].type === 'end') {
|
20160 | arity--;
|
20161 |
|
20162 |
|
20163 |
|
20164 | if (arity === 1) {
|
20165 | end = extents[count].time;
|
20166 | }
|
20167 | }
|
20168 |
|
20169 |
|
20170 | if (start !== null && end !== null) {
|
20171 | ranges.push([start, end]);
|
20172 | start = null;
|
20173 | end = null;
|
20174 | }
|
20175 | }
|
20176 |
|
20177 | return _videoJs2['default'].createTimeRanges(ranges);
|
20178 | }
|
20179 | });
|
20180 | }
|
20181 |
|
20182 | |
20183 |
|
20184 |
|
20185 |
|
20186 |
|
20187 |
|
20188 |
|
20189 |
|
20190 |
|
20191 | _createClass(VirtualSourceBuffer, [{
|
20192 | key: 'data_',
|
20193 | value: function data_(event) {
|
20194 | var segment = event.data.segment;
|
20195 |
|
20196 |
|
20197 | segment.data = new Uint8Array(segment.data, event.data.byteOffset, event.data.byteLength);
|
20198 |
|
20199 | segment.initSegment = new Uint8Array(segment.initSegment.data, segment.initSegment.byteOffset, segment.initSegment.byteLength);
|
20200 |
|
20201 | (0, _createTextTracksIfNecessary2['default'])(this, this.mediaSource_, segment);
|
20202 |
|
20203 |
|
20204 | this.pendingBuffers_.push(segment);
|
20205 | return;
|
20206 | }
|
20207 |
|
20208 | |
20209 |
|
20210 |
|
20211 |
|
20212 |
|
20213 |
|
20214 |
|
20215 |
|
20216 |
|
20217 | }, {
|
20218 | key: 'done_',
|
20219 | value: function done_(event) {
|
20220 |
|
20221 | if (this.mediaSource_.readyState === 'closed') {
|
20222 | this.pendingBuffers_.length = 0;
|
20223 | return;
|
20224 | }
|
20225 |
|
20226 |
|
20227 |
|
20228 | this.processPendingSegments_();
|
20229 | return;
|
20230 | }
|
20231 |
|
20232 | |
20233 |
|
20234 |
|
20235 |
|
20236 |
|
20237 |
|
20238 |
|
20239 |
|
20240 | }, {
|
20241 | key: 'createRealSourceBuffers_',
|
20242 | value: function createRealSourceBuffers_() {
|
20243 | var _this2 = this;
|
20244 |
|
20245 | var types = ['audio', 'video'];
|
20246 |
|
20247 | types.forEach(function (type) {
|
20248 |
|
20249 |
|
20250 | if (!_this2[type + 'Codec_']) {
|
20251 | return;
|
20252 | }
|
20253 |
|
20254 |
|
20255 | if (_this2[type + 'Buffer_']) {
|
20256 | return;
|
20257 | }
|
20258 |
|
20259 | var buffer = null;
|
20260 |
|
20261 |
|
20262 |
|
20263 | if (_this2.mediaSource_[type + 'Buffer_']) {
|
20264 | buffer = _this2.mediaSource_[type + 'Buffer_'];
|
20265 |
|
20266 |
|
20267 |
|
20268 |
|
20269 |
|
20270 |
|
20271 |
|
20272 |
|
20273 |
|
20274 |
|
20275 | buffer.updating = false;
|
20276 | } else {
|
20277 | var codecProperty = type + 'Codec_';
|
20278 | var mimeType = type + '/mp4;codecs="' + _this2[codecProperty] + '"';
|
20279 |
|
20280 | buffer = makeWrappedSourceBuffer(_this2.mediaSource_.nativeMediaSource_, mimeType);
|
20281 |
|
20282 | _this2.mediaSource_[type + 'Buffer_'] = buffer;
|
20283 | }
|
20284 |
|
20285 | _this2[type + 'Buffer_'] = buffer;
|
20286 |
|
20287 |
|
20288 | ['update', 'updatestart', 'updateend'].forEach(function (event) {
|
20289 | buffer.addEventListener(event, function () {
|
20290 |
|
20291 | if (type === 'audio' && _this2.audioDisabled_) {
|
20292 | return;
|
20293 | }
|
20294 |
|
20295 | if (event === 'updateend') {
|
20296 | _this2[type + 'Buffer_'].updating = false;
|
20297 | }
|
20298 |
|
20299 | var shouldTrigger = types.every(function (t) {
|
20300 |
|
20301 |
|
20302 | if (t === 'audio' && _this2.audioDisabled_) {
|
20303 | return true;
|
20304 | }
|
20305 |
|
20306 | if (type !== t && _this2[t + 'Buffer_'] && _this2[t + 'Buffer_'].updating) {
|
20307 | return false;
|
20308 | }
|
20309 | return true;
|
20310 | });
|
20311 |
|
20312 | if (shouldTrigger) {
|
20313 | return _this2.trigger(event);
|
20314 | }
|
20315 | });
|
20316 | });
|
20317 | });
|
20318 | }
|
20319 |
|
20320 | |
20321 |
|
20322 |
|
20323 |
|
20324 |
|
20325 |
|
20326 |
|
20327 |
|
20328 |
|
20329 | }, {
|
20330 | key: 'appendBuffer',
|
20331 | value: function appendBuffer(segment) {
|
20332 |
|
20333 | this.bufferUpdating_ = true;
|
20334 |
|
20335 | if (this.audioBuffer_ && this.audioBuffer_.buffered.length) {
|
20336 | var audioBuffered = this.audioBuffer_.buffered;
|
20337 |
|
20338 | this.transmuxer_.postMessage({
|
20339 | action: 'setAudioAppendStart',
|
20340 | appendStart: audioBuffered.end(audioBuffered.length - 1)
|
20341 | });
|
20342 | }
|
20343 |
|
20344 | if (this.videoBuffer_) {
|
20345 | this.transmuxer_.postMessage({
|
20346 | action: 'alignGopsWith',
|
20347 | gopsToAlignWith: gopsSafeToAlignWith(this.gopBuffer_, this.mediaSource_.player_, this.timeMapping_)
|
20348 | });
|
20349 | }
|
20350 |
|
20351 | this.transmuxer_.postMessage({
|
20352 | action: 'push',
|
20353 |
|
20354 |
|
20355 |
|
20356 | data: segment.buffer,
|
20357 |
|
20358 |
|
20359 |
|
20360 | byteOffset: segment.byteOffset,
|
20361 | byteLength: segment.byteLength
|
20362 | }, [segment.buffer]);
|
20363 | this.transmuxer_.postMessage({ action: 'flush' });
|
20364 | }
|
20365 |
|
20366 | |
20367 |
|
20368 |
|
20369 |
|
20370 |
|
20371 |
|
20372 |
|
20373 |
|
20374 |
|
20375 | }, {
|
20376 | key: 'appendGopInfo_',
|
20377 | value: function appendGopInfo_(event) {
|
20378 | this.gopBuffer_ = updateGopBuffer(this.gopBuffer_, event.data.gopInfo, this.safeAppend_);
|
20379 | }
|
20380 |
|
20381 | |
20382 |
|
20383 |
|
20384 |
|
20385 |
|
20386 |
|
20387 |
|
20388 |
|
20389 | }, {
|
20390 | key: 'remove',
|
20391 | value: function remove(start, end) {
|
20392 | if (this.videoBuffer_) {
|
20393 | this.videoBuffer_.updating = true;
|
20394 | this.videoBuffer_.remove(start, end);
|
20395 | this.gopBuffer_ = removeGopBuffer(this.gopBuffer_, start, end, this.timeMapping_);
|
20396 | }
|
20397 | if (!this.audioDisabled_ && this.audioBuffer_) {
|
20398 | this.audioBuffer_.updating = true;
|
20399 | this.audioBuffer_.remove(start, end);
|
20400 | }
|
20401 |
|
20402 |
|
20403 | (0, _removeCuesFromTrack2['default'])(start, end, this.metadataTrack_);
|
20404 |
|
20405 |
|
20406 | if (this.inbandTextTracks_) {
|
20407 | for (var track in this.inbandTextTracks_) {
|
20408 | (0, _removeCuesFromTrack2['default'])(start, end, this.inbandTextTracks_[track]);
|
20409 | }
|
20410 | }
|
20411 | }
|
20412 |
|
20413 | |
20414 |
|
20415 |
|
20416 |
|
20417 |
|
20418 |
|
20419 |
|
20420 | }, {
|
20421 | key: 'processPendingSegments_',
|
20422 | value: function processPendingSegments_() {
|
20423 | var sortedSegments = {
|
20424 | video: {
|
20425 | segments: [],
|
20426 | bytes: 0
|
20427 | },
|
20428 | audio: {
|
20429 | segments: [],
|
20430 | bytes: 0
|
20431 | },
|
20432 | captions: [],
|
20433 | metadata: []
|
20434 | };
|
20435 |
|
20436 |
|
20437 |
|
20438 | sortedSegments = this.pendingBuffers_.reduce(function (segmentObj, segment) {
|
20439 | var type = segment.type;
|
20440 | var data = segment.data;
|
20441 | var initSegment = segment.initSegment;
|
20442 |
|
20443 | segmentObj[type].segments.push(data);
|
20444 | segmentObj[type].bytes += data.byteLength;
|
20445 |
|
20446 | segmentObj[type].initSegment = initSegment;
|
20447 |
|
20448 |
|
20449 | if (segment.captions) {
|
20450 | segmentObj.captions = segmentObj.captions.concat(segment.captions);
|
20451 | }
|
20452 |
|
20453 | if (segment.info) {
|
20454 | segmentObj[type].info = segment.info;
|
20455 | }
|
20456 |
|
20457 |
|
20458 | if (segment.metadata) {
|
20459 | segmentObj.metadata = segmentObj.metadata.concat(segment.metadata);
|
20460 | }
|
20461 |
|
20462 | return segmentObj;
|
20463 | }, sortedSegments);
|
20464 |
|
20465 |
|
20466 |
|
20467 | if (!this.videoBuffer_ && !this.audioBuffer_) {
|
20468 |
|
20469 |
|
20470 | if (sortedSegments.video.bytes === 0) {
|
20471 | this.videoCodec_ = null;
|
20472 | }
|
20473 | if (sortedSegments.audio.bytes === 0) {
|
20474 | this.audioCodec_ = null;
|
20475 | }
|
20476 |
|
20477 | this.createRealSourceBuffers_();
|
20478 | }
|
20479 |
|
20480 | if (sortedSegments.audio.info) {
|
20481 | this.mediaSource_.trigger({ type: 'audioinfo', info: sortedSegments.audio.info });
|
20482 | }
|
20483 | if (sortedSegments.video.info) {
|
20484 | this.mediaSource_.trigger({ type: 'videoinfo', info: sortedSegments.video.info });
|
20485 | }
|
20486 |
|
20487 | if (this.appendAudioInitSegment_) {
|
20488 | if (!this.audioDisabled_ && this.audioBuffer_) {
|
20489 | sortedSegments.audio.segments.unshift(sortedSegments.audio.initSegment);
|
20490 | sortedSegments.audio.bytes += sortedSegments.audio.initSegment.byteLength;
|
20491 | }
|
20492 | this.appendAudioInitSegment_ = false;
|
20493 | }
|
20494 |
|
20495 | var triggerUpdateend = false;
|
20496 |
|
20497 |
|
20498 | if (this.videoBuffer_ && sortedSegments.video.bytes) {
|
20499 | sortedSegments.video.segments.unshift(sortedSegments.video.initSegment);
|
20500 | sortedSegments.video.bytes += sortedSegments.video.initSegment.byteLength;
|
20501 | this.concatAndAppendSegments_(sortedSegments.video, this.videoBuffer_);
|
20502 |
|
20503 | (0, _addTextTrackData.addTextTrackData)(this, sortedSegments.captions, sortedSegments.metadata);
|
20504 | } else if (this.videoBuffer_ && (this.audioDisabled_ || !this.audioBuffer_)) {
|
20505 |
|
20506 |
|
20507 |
|
20508 |
|
20509 |
|
20510 |
|
20511 | triggerUpdateend = true;
|
20512 | }
|
20513 |
|
20514 | if (!this.audioDisabled_ && this.audioBuffer_) {
|
20515 | this.concatAndAppendSegments_(sortedSegments.audio, this.audioBuffer_);
|
20516 | }
|
20517 |
|
20518 | this.pendingBuffers_.length = 0;
|
20519 |
|
20520 | if (triggerUpdateend) {
|
20521 | this.trigger('updateend');
|
20522 | }
|
20523 |
|
20524 |
|
20525 | this.bufferUpdating_ = false;
|
20526 | }
|
20527 |
|
20528 | |
20529 |
|
20530 |
|
20531 |
|
20532 |
|
20533 |
|
20534 |
|
20535 |
|
20536 | }, {
|
20537 | key: 'concatAndAppendSegments_',
|
20538 | value: function concatAndAppendSegments_(segmentObj, destinationBuffer) {
|
20539 | var offset = 0;
|
20540 | var tempBuffer = undefined;
|
20541 |
|
20542 | if (segmentObj.bytes) {
|
20543 | tempBuffer = new Uint8Array(segmentObj.bytes);
|
20544 |
|
20545 |
|
20546 | segmentObj.segments.forEach(function (segment) {
|
20547 | tempBuffer.set(segment, offset);
|
20548 | offset += segment.byteLength;
|
20549 | });
|
20550 |
|
20551 | try {
|
20552 | destinationBuffer.updating = true;
|
20553 | destinationBuffer.appendBuffer(tempBuffer);
|
20554 | } catch (error) {
|
20555 | if (this.mediaSource_.player_) {
|
20556 | this.mediaSource_.player_.error({
|
20557 | code: -3,
|
20558 | type: 'APPEND_BUFFER_ERR',
|
20559 | message: error.message,
|
20560 | originalError: error
|
20561 | });
|
20562 | }
|
20563 | }
|
20564 | }
|
20565 | }
|
20566 |
|
20567 | |
20568 |
|
20569 |
|
20570 |
|
20571 |
|
20572 |
|
20573 | }, {
|
20574 | key: 'abort',
|
20575 | value: function abort() {
|
20576 | if (this.videoBuffer_) {
|
20577 | this.videoBuffer_.abort();
|
20578 | }
|
20579 | if (!this.audioDisabled_ && this.audioBuffer_) {
|
20580 | this.audioBuffer_.abort();
|
20581 | }
|
20582 | if (this.transmuxer_) {
|
20583 | this.transmuxer_.postMessage({ action: 'reset' });
|
20584 | }
|
20585 | this.pendingBuffers_.length = 0;
|
20586 | this.bufferUpdating_ = false;
|
20587 | }
|
20588 | }]);
|
20589 |
|
20590 | return VirtualSourceBuffer;
|
20591 | })(_videoJs2['default'].EventTarget);
|
20592 |
|
20593 | exports['default'] = VirtualSourceBuffer;
|
20594 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
20595 | },{"./add-text-track-data":64,"./codec-utils":65,"./create-text-tracks-if-necessary":66,"./remove-cues-from-track":72,"./transmuxer-worker":73,"webworkify":76}],76:[function(require,module,exports){
|
20596 | var bundleFn = arguments[3];
|
20597 | var sources = arguments[4];
|
20598 | var cache = arguments[5];
|
20599 |
|
20600 | var stringify = JSON.stringify;
|
20601 |
|
20602 | module.exports = function (fn) {
|
20603 | var keys = [];
|
20604 | var wkey;
|
20605 | var cacheKeys = Object.keys(cache);
|
20606 |
|
20607 | for (var i = 0, l = cacheKeys.length; i < l; i++) {
|
20608 | var key = cacheKeys[i];
|
20609 | if (cache[key].exports === fn) {
|
20610 | wkey = key;
|
20611 | break;
|
20612 | }
|
20613 | }
|
20614 |
|
20615 | if (!wkey) {
|
20616 | wkey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16);
|
20617 | var wcache = {};
|
20618 | for (var i = 0, l = cacheKeys.length; i < l; i++) {
|
20619 | var key = cacheKeys[i];
|
20620 | wcache[key] = key;
|
20621 | }
|
20622 | sources[wkey] = [
|
20623 | Function(['require','module','exports'], '(' + fn + ')(self)'),
|
20624 | wcache
|
20625 | ];
|
20626 | }
|
20627 | var skey = Math.floor(Math.pow(16, 8) * Math.random()).toString(16);
|
20628 |
|
20629 | var scache = {}; scache[wkey] = wkey;
|
20630 | sources[skey] = [
|
20631 | Function(['require'],'require(' + stringify(wkey) + ')(self)'),
|
20632 | scache
|
20633 | ];
|
20634 |
|
20635 | var src = '(' + bundleFn + ')({'
|
20636 | + Object.keys(sources).map(function (key) {
|
20637 | return stringify(key) + ':['
|
20638 | + sources[key][0]
|
20639 | + ',' + stringify(sources[key][1]) + ']'
|
20640 | ;
|
20641 | }).join(',')
|
20642 | + '},{},[' + stringify(skey) + '])'
|
20643 | ;
|
20644 |
|
20645 | var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
20646 |
|
20647 | return new Worker(URL.createObjectURL(
|
20648 | new Blob([src], { type: 'text/javascript' })
|
20649 | ));
|
20650 | };
|
20651 |
|
20652 | },{}],77:[function(require,module,exports){
|
20653 | (function (global){
|
20654 |
|
20655 |
|
20656 |
|
20657 |
|
20658 |
|
20659 |
|
20660 | 'use strict';
|
20661 |
|
20662 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
20663 |
|
20664 | var _get = function get(_x4, _x5, _x6) { var _again = true; _function: while (_again) { var object = _x4, property = _x5, receiver = _x6; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x4 = parent; _x5 = property; _x6 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
20665 |
|
20666 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
20667 |
|
20668 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
20669 |
|
20670 | function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
20671 |
|
20672 | var _globalDocument = require('global/document');
|
20673 |
|
20674 | var _globalDocument2 = _interopRequireDefault(_globalDocument);
|
20675 |
|
20676 | var _playlistLoader = require('./playlist-loader');
|
20677 |
|
20678 | var _playlistLoader2 = _interopRequireDefault(_playlistLoader);
|
20679 |
|
20680 | var _playlist = require('./playlist');
|
20681 |
|
20682 | var _playlist2 = _interopRequireDefault(_playlist);
|
20683 |
|
20684 | var _xhr = require('./xhr');
|
20685 |
|
20686 | var _xhr2 = _interopRequireDefault(_xhr);
|
20687 |
|
20688 | var _aesDecrypter = require('aes-decrypter');
|
20689 |
|
20690 | var _binUtils = require('./bin-utils');
|
20691 |
|
20692 | var _binUtils2 = _interopRequireDefault(_binUtils);
|
20693 |
|
20694 | var _videojsContribMediaSources = require('videojs-contrib-media-sources');
|
20695 |
|
20696 | var _m3u8Parser = require('m3u8-parser');
|
20697 |
|
20698 | var _m3u8Parser2 = _interopRequireDefault(_m3u8Parser);
|
20699 |
|
20700 | var _videoJs = (typeof window !== "undefined" ? window['videojs'] : typeof global !== "undefined" ? global['videojs'] : null);
|
20701 |
|
20702 | var _videoJs2 = _interopRequireDefault(_videoJs);
|
20703 |
|
20704 | var _masterPlaylistController = require('./master-playlist-controller');
|
20705 |
|
20706 | var _config = require('./config');
|
20707 |
|
20708 | var _config2 = _interopRequireDefault(_config);
|
20709 |
|
20710 | var _renditionMixin = require('./rendition-mixin');
|
20711 |
|
20712 | var _renditionMixin2 = _interopRequireDefault(_renditionMixin);
|
20713 |
|
20714 | var _globalWindow = require('global/window');
|
20715 |
|
20716 | var _globalWindow2 = _interopRequireDefault(_globalWindow);
|
20717 |
|
20718 | var _playbackWatcher = require('./playback-watcher');
|
20719 |
|
20720 | var _playbackWatcher2 = _interopRequireDefault(_playbackWatcher);
|
20721 |
|
20722 | var _reloadSourceOnError = require('./reload-source-on-error');
|
20723 |
|
20724 | var _reloadSourceOnError2 = _interopRequireDefault(_reloadSourceOnError);
|
20725 |
|
20726 | var _playlistSelectorsJs = require('./playlist-selectors.js');
|
20727 |
|
20728 | var Hls = {
|
20729 | PlaylistLoader: _playlistLoader2['default'],
|
20730 | Playlist: _playlist2['default'],
|
20731 | Decrypter: _aesDecrypter.Decrypter,
|
20732 | AsyncStream: _aesDecrypter.AsyncStream,
|
20733 | decrypt: _aesDecrypter.decrypt,
|
20734 | utils: _binUtils2['default'],
|
20735 |
|
20736 | STANDARD_PLAYLIST_SELECTOR: _playlistSelectorsJs.lastBandwidthSelector,
|
20737 | INITIAL_PLAYLIST_SELECTOR: _playlistSelectorsJs.lowestBitrateCompatibleVariantSelector,
|
20738 | comparePlaylistBandwidth: _playlistSelectorsJs.comparePlaylistBandwidth,
|
20739 | comparePlaylistResolution: _playlistSelectorsJs.comparePlaylistResolution,
|
20740 |
|
20741 | xhr: (0, _xhr2['default'])()
|
20742 | };
|
20743 |
|
20744 |
|
20745 | var INITIAL_BANDWIDTH = 4194304;
|
20746 |
|
20747 |
|
20748 | ['GOAL_BUFFER_LENGTH', 'MAX_GOAL_BUFFER_LENGTH', 'GOAL_BUFFER_LENGTH_RATE', 'BUFFER_LOW_WATER_LINE', 'MAX_BUFFER_LOW_WATER_LINE', 'BUFFER_LOW_WATER_LINE_RATE', 'BANDWIDTH_VARIANCE'].forEach(function (prop) {
|
20749 | Object.defineProperty(Hls, prop, {
|
20750 | get: function get() {
|
20751 | _videoJs2['default'].log.warn('using Hls.' + prop + ' is UNSAFE be sure you know what you are doing');
|
20752 | return _config2['default'][prop];
|
20753 | },
|
20754 | set: function set(value) {
|
20755 | _videoJs2['default'].log.warn('using Hls.' + prop + ' is UNSAFE be sure you know what you are doing');
|
20756 |
|
20757 | if (typeof value !== 'number' || value < 0) {
|
20758 | _videoJs2['default'].log.warn('value of Hls.' + prop + ' must be greater than or equal to 0');
|
20759 | return;
|
20760 | }
|
20761 |
|
20762 | _config2['default'][prop] = value;
|
20763 | }
|
20764 | });
|
20765 | });
|
20766 |
|
20767 |
|
20768 |
|
20769 |
|
20770 |
|
20771 |
|
20772 |
|
20773 |
|
20774 | var handleHlsMediaChange = function handleHlsMediaChange(qualityLevels, playlistLoader) {
|
20775 | var newPlaylist = playlistLoader.media();
|
20776 | var selectedIndex = -1;
|
20777 |
|
20778 | for (var i = 0; i < qualityLevels.length; i++) {
|
20779 | if (qualityLevels[i].id === newPlaylist.uri) {
|
20780 | selectedIndex = i;
|
20781 | break;
|
20782 | }
|
20783 | }
|
20784 |
|
20785 | qualityLevels.selectedIndex_ = selectedIndex;
|
20786 | qualityLevels.trigger({
|
20787 | selectedIndex: selectedIndex,
|
20788 | type: 'change'
|
20789 | });
|
20790 | };
|
20791 |
|
20792 |
|
20793 |
|
20794 |
|
20795 |
|
20796 |
|
20797 |
|
20798 |
|
20799 | var handleHlsLoadedMetadata = function handleHlsLoadedMetadata(qualityLevels, hls) {
|
20800 | hls.representations().forEach(function (rep) {
|
20801 | qualityLevels.addQualityLevel(rep);
|
20802 | });
|
20803 | handleHlsMediaChange(qualityLevels, hls.playlists);
|
20804 | };
|
20805 |
|
20806 |
|
20807 |
|
20808 | Hls.canPlaySource = function () {
|
20809 | return _videoJs2['default'].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
20810 | };
|
20811 |
|
20812 |
|
20813 |
|
20814 |
|
20815 | Hls.supportsNativeHls = (function () {
|
20816 | var video = _globalDocument2['default'].createElement('video');
|
20817 |
|
20818 |
|
20819 | if (!_videoJs2['default'].getTech('Html5').isSupported()) {
|
20820 | return false;
|
20821 | }
|
20822 |
|
20823 |
|
20824 | var canPlay = [
|
20825 |
|
20826 | 'application/vnd.apple.mpegurl',
|
20827 |
|
20828 | 'audio/mpegurl',
|
20829 |
|
20830 | 'audio/x-mpegurl',
|
20831 |
|
20832 | 'application/x-mpegurl',
|
20833 |
|
20834 | 'video/x-mpegurl', 'video/mpegurl', 'application/mpegurl'];
|
20835 |
|
20836 | return canPlay.some(function (canItPlay) {
|
20837 | return (/maybe|probably/i.test(video.canPlayType(canItPlay))
|
20838 | );
|
20839 | });
|
20840 | })();
|
20841 |
|
20842 |
|
20843 |
|
20844 |
|
20845 |
|
20846 | Hls.isSupported = function () {
|
20847 | return _videoJs2['default'].log.warn('HLS is no longer a tech. Please remove it from ' + 'your player\'s techOrder.');
|
20848 | };
|
20849 |
|
20850 | var Component = _videoJs2['default'].getComponent('Component');
|
20851 |
|
20852 |
|
20853 |
|
20854 |
|
20855 |
|
20856 |
|
20857 |
|
20858 |
|
20859 |
|
20860 |
|
20861 |
|
20862 |
|
20863 | var HlsHandler = (function (_Component) {
|
20864 | _inherits(HlsHandler, _Component);
|
20865 |
|
20866 | function HlsHandler(source, tech, options) {
|
20867 | var _this = this;
|
20868 |
|
20869 | _classCallCheck(this, HlsHandler);
|
20870 |
|
20871 | _get(Object.getPrototypeOf(HlsHandler.prototype), 'constructor', this).call(this, tech, options.hls);
|
20872 |
|
20873 |
|
20874 |
|
20875 | if (tech.options_ && tech.options_.playerId) {
|
20876 | var _player = (0, _videoJs2['default'])(tech.options_.playerId);
|
20877 |
|
20878 | if (!_player.hasOwnProperty('hls')) {
|
20879 | Object.defineProperty(_player, 'hls', {
|
20880 | get: function get() {
|
20881 | _videoJs2['default'].log.warn('player.hls is deprecated. Use player.tech_.hls instead.');
|
20882 | tech.trigger({ type: 'usage', name: 'hls-player-access' });
|
20883 | return _this;
|
20884 | }
|
20885 | });
|
20886 | }
|
20887 | }
|
20888 |
|
20889 | this.tech_ = tech;
|
20890 | this.source_ = source;
|
20891 | this.stats = {};
|
20892 | this.ignoreNextSeekingEvent_ = false;
|
20893 | this.setOptions_();
|
20894 |
|
20895 |
|
20896 |
|
20897 | if (this.options_.overrideNative && (tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
|
20898 | throw new Error('Overriding native HLS requires emulated tracks. ' + 'See https://git.io/vMpjB');
|
20899 | }
|
20900 |
|
20901 |
|
20902 |
|
20903 | this.on(_globalDocument2['default'], ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'], function (event) {
|
20904 | var fullscreenElement = _globalDocument2['default'].fullscreenElement || _globalDocument2['default'].webkitFullscreenElement || _globalDocument2['default'].mozFullScreenElement || _globalDocument2['default'].msFullscreenElement;
|
20905 |
|
20906 | if (fullscreenElement && fullscreenElement.contains(_this.tech_.el())) {
|
20907 | _this.masterPlaylistController_.fastQualityChange_();
|
20908 | }
|
20909 | });
|
20910 |
|
20911 | this.on(this.tech_, 'seeking', function () {
|
20912 | if (this.ignoreNextSeekingEvent_) {
|
20913 | this.ignoreNextSeekingEvent_ = false;
|
20914 | return;
|
20915 | }
|
20916 |
|
20917 | this.setCurrentTime(this.tech_.currentTime());
|
20918 | });
|
20919 | this.on(this.tech_, 'error', function () {
|
20920 | if (this.masterPlaylistController_) {
|
20921 | this.masterPlaylistController_.pauseLoading();
|
20922 | }
|
20923 | });
|
20924 |
|
20925 | this.on(this.tech_, 'play', this.play);
|
20926 | }
|
20927 |
|
20928 | |
20929 |
|
20930 |
|
20931 |
|
20932 |
|
20933 |
|
20934 |
|
20935 |
|
20936 | _createClass(HlsHandler, [{
|
20937 | key: 'setOptions_',
|
20938 | value: function setOptions_() {
|
20939 | var _this2 = this;
|
20940 |
|
20941 |
|
20942 | this.options_.withCredentials = this.options_.withCredentials || false;
|
20943 |
|
20944 | if (typeof this.options_.blacklistDuration !== 'number') {
|
20945 | this.options_.blacklistDuration = 5 * 60;
|
20946 | }
|
20947 |
|
20948 |
|
20949 |
|
20950 | if (typeof this.options_.bandwidth !== 'number') {
|
20951 | this.options_.bandwidth = INITIAL_BANDWIDTH;
|
20952 | }
|
20953 |
|
20954 |
|
20955 |
|
20956 | this.options_.enableLowInitialPlaylist = this.options_.enableLowInitialPlaylist && this.options_.bandwidth === INITIAL_BANDWIDTH;
|
20957 |
|
20958 |
|
20959 | ['withCredentials', 'bandwidth'].forEach(function (option) {
|
20960 | if (typeof _this2.source_[option] !== 'undefined') {
|
20961 | _this2.options_[option] = _this2.source_[option];
|
20962 | }
|
20963 | });
|
20964 |
|
20965 | this.bandwidth = this.options_.bandwidth;
|
20966 | }
|
20967 |
|
20968 | |
20969 |
|
20970 |
|
20971 |
|
20972 |
|
20973 | }, {
|
20974 | key: 'src',
|
20975 | value: function src(_src) {
|
20976 | var _this3 = this;
|
20977 |
|
20978 |
|
20979 | if (!_src) {
|
20980 | return;
|
20981 | }
|
20982 | this.setOptions_();
|
20983 |
|
20984 | this.options_.url = this.source_.src;
|
20985 | this.options_.tech = this.tech_;
|
20986 | this.options_.externHls = Hls;
|
20987 |
|
20988 | this.masterPlaylistController_ = new _masterPlaylistController.MasterPlaylistController(this.options_);
|
20989 | this.playbackWatcher_ = new _playbackWatcher2['default'](_videoJs2['default'].mergeOptions(this.options_, {
|
20990 | seekable: function seekable() {
|
20991 | return _this3.seekable();
|
20992 | }
|
20993 | }));
|
20994 |
|
20995 | this.masterPlaylistController_.on('error', function () {
|
20996 | var player = _videoJs2['default'].players[_this3.tech_.options_.playerId];
|
20997 |
|
20998 | player.error(_this3.masterPlaylistController_.error);
|
20999 | });
|
21000 |
|
21001 |
|
21002 |
|
21003 | this.masterPlaylistController_.selectPlaylist = this.selectPlaylist ? this.selectPlaylist.bind(this) : Hls.STANDARD_PLAYLIST_SELECTOR.bind(this);
|
21004 |
|
21005 | this.masterPlaylistController_.selectInitialPlaylist = Hls.INITIAL_PLAYLIST_SELECTOR.bind(this);
|
21006 |
|
21007 |
|
21008 | this.playlists = this.masterPlaylistController_.masterPlaylistLoader_;
|
21009 | this.mediaSource = this.masterPlaylistController_.mediaSource;
|
21010 |
|
21011 |
|
21012 |
|
21013 |
|
21014 | Object.defineProperties(this, {
|
21015 | selectPlaylist: {
|
21016 | get: function get() {
|
21017 | return this.masterPlaylistController_.selectPlaylist;
|
21018 | },
|
21019 | set: function set(selectPlaylist) {
|
21020 | this.masterPlaylistController_.selectPlaylist = selectPlaylist.bind(this);
|
21021 | }
|
21022 | },
|
21023 | throughput: {
|
21024 | get: function get() {
|
21025 | return this.masterPlaylistController_.mainSegmentLoader_.throughput.rate;
|
21026 | },
|
21027 | set: function set(throughput) {
|
21028 | this.masterPlaylistController_.mainSegmentLoader_.throughput.rate = throughput;
|
21029 |
|
21030 |
|
21031 | this.masterPlaylistController_.mainSegmentLoader_.throughput.count = 1;
|
21032 | }
|
21033 | },
|
21034 | bandwidth: {
|
21035 | get: function get() {
|
21036 | return this.masterPlaylistController_.mainSegmentLoader_.bandwidth;
|
21037 | },
|
21038 | set: function set(bandwidth) {
|
21039 | this.masterPlaylistController_.mainSegmentLoader_.bandwidth = bandwidth;
|
21040 |
|
21041 |
|
21042 |
|
21043 | this.masterPlaylistController_.mainSegmentLoader_.throughput = {
|
21044 | rate: 0,
|
21045 | count: 0
|
21046 | };
|
21047 | }
|
21048 | },
|
21049 | |
21050 |
|
21051 |
|
21052 |
|
21053 |
|
21054 |
|
21055 |
|
21056 |
|
21057 |
|
21058 | systemBandwidth: {
|
21059 | get: function get() {
|
21060 | var invBandwidth = 1 / (this.bandwidth || 1);
|
21061 | var invThroughput = undefined;
|
21062 |
|
21063 | if (this.throughput > 0) {
|
21064 | invThroughput = 1 / this.throughput;
|
21065 | } else {
|
21066 | invThroughput = 0;
|
21067 | }
|
21068 |
|
21069 | var systemBitrate = Math.floor(1 / (invBandwidth + invThroughput));
|
21070 |
|
21071 | return systemBitrate;
|
21072 | },
|
21073 | set: function set() {
|
21074 | _videoJs2['default'].log.error('The "systemBandwidth" property is read-only');
|
21075 | }
|
21076 | }
|
21077 | });
|
21078 |
|
21079 | Object.defineProperties(this.stats, {
|
21080 | bandwidth: {
|
21081 | get: function get() {
|
21082 | return _this3.bandwidth || 0;
|
21083 | },
|
21084 | enumerable: true
|
21085 | },
|
21086 | mediaRequests: {
|
21087 | get: function get() {
|
21088 | return _this3.masterPlaylistController_.mediaRequests_() || 0;
|
21089 | },
|
21090 | enumerable: true
|
21091 | },
|
21092 | mediaRequestsAborted: {
|
21093 | get: function get() {
|
21094 | return _this3.masterPlaylistController_.mediaRequestsAborted_() || 0;
|
21095 | },
|
21096 | enumerable: true
|
21097 | },
|
21098 | mediaRequestsTimedout: {
|
21099 | get: function get() {
|
21100 | return _this3.masterPlaylistController_.mediaRequestsTimedout_() || 0;
|
21101 | },
|
21102 | enumerable: true
|
21103 | },
|
21104 | mediaRequestsErrored: {
|
21105 | get: function get() {
|
21106 | return _this3.masterPlaylistController_.mediaRequestsErrored_() || 0;
|
21107 | },
|
21108 | enumerable: true
|
21109 | },
|
21110 | mediaTransferDuration: {
|
21111 | get: function get() {
|
21112 | return _this3.masterPlaylistController_.mediaTransferDuration_() || 0;
|
21113 | },
|
21114 | enumerable: true
|
21115 | },
|
21116 | mediaBytesTransferred: {
|
21117 | get: function get() {
|
21118 | return _this3.masterPlaylistController_.mediaBytesTransferred_() || 0;
|
21119 | },
|
21120 | enumerable: true
|
21121 | },
|
21122 | mediaSecondsLoaded: {
|
21123 | get: function get() {
|
21124 | return _this3.masterPlaylistController_.mediaSecondsLoaded_() || 0;
|
21125 | },
|
21126 | enumerable: true
|
21127 | }
|
21128 | });
|
21129 |
|
21130 | this.tech_.one('canplay', this.masterPlaylistController_.setupFirstPlay.bind(this.masterPlaylistController_));
|
21131 |
|
21132 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
21133 |
|
21134 | (0, _renditionMixin2['default'])(_this3);
|
21135 | });
|
21136 |
|
21137 |
|
21138 |
|
21139 | this.on(this.masterPlaylistController_, 'progress', function () {
|
21140 | this.tech_.trigger('progress');
|
21141 | });
|
21142 |
|
21143 |
|
21144 |
|
21145 | this.on(this.masterPlaylistController_, 'firstplay', function () {
|
21146 | this.ignoreNextSeekingEvent_ = true;
|
21147 | });
|
21148 |
|
21149 | this.tech_.ready(function () {
|
21150 | return _this3.setupQualityLevels_();
|
21151 | });
|
21152 |
|
21153 |
|
21154 |
|
21155 | if (!this.tech_.el()) {
|
21156 | return;
|
21157 | }
|
21158 |
|
21159 | this.tech_.src(_videoJs2['default'].URL.createObjectURL(this.masterPlaylistController_.mediaSource));
|
21160 | }
|
21161 |
|
21162 | |
21163 |
|
21164 |
|
21165 |
|
21166 |
|
21167 |
|
21168 | }, {
|
21169 | key: 'setupQualityLevels_',
|
21170 | value: function setupQualityLevels_() {
|
21171 | var _this4 = this;
|
21172 |
|
21173 | var player = _videoJs2['default'].players[this.tech_.options_.playerId];
|
21174 |
|
21175 | if (player && player.qualityLevels) {
|
21176 | this.qualityLevels_ = player.qualityLevels();
|
21177 |
|
21178 | this.masterPlaylistController_.on('selectedinitialmedia', function () {
|
21179 | handleHlsLoadedMetadata(_this4.qualityLevels_, _this4);
|
21180 | });
|
21181 |
|
21182 | this.playlists.on('mediachange', function () {
|
21183 | handleHlsMediaChange(_this4.qualityLevels_, _this4.playlists);
|
21184 | });
|
21185 | }
|
21186 | }
|
21187 |
|
21188 | |
21189 |
|
21190 |
|
21191 | }, {
|
21192 | key: 'play',
|
21193 | value: function play() {
|
21194 | this.masterPlaylistController_.play();
|
21195 | }
|
21196 |
|
21197 | |
21198 |
|
21199 |
|
21200 | }, {
|
21201 | key: 'setCurrentTime',
|
21202 | value: function setCurrentTime(currentTime) {
|
21203 | this.masterPlaylistController_.setCurrentTime(currentTime);
|
21204 | }
|
21205 |
|
21206 | |
21207 |
|
21208 |
|
21209 | }, {
|
21210 | key: 'duration',
|
21211 | value: function duration() {
|
21212 | return this.masterPlaylistController_.duration();
|
21213 | }
|
21214 |
|
21215 | |
21216 |
|
21217 |
|
21218 | }, {
|
21219 | key: 'seekable',
|
21220 | value: function seekable() {
|
21221 | return this.masterPlaylistController_.seekable();
|
21222 | }
|
21223 |
|
21224 | |
21225 |
|
21226 |
|
21227 | }, {
|
21228 | key: 'dispose',
|
21229 | value: function dispose() {
|
21230 | if (this.playbackWatcher_) {
|
21231 | this.playbackWatcher_.dispose();
|
21232 | }
|
21233 | if (this.masterPlaylistController_) {
|
21234 | this.masterPlaylistController_.dispose();
|
21235 | }
|
21236 | if (this.qualityLevels_) {
|
21237 | this.qualityLevels_.dispose();
|
21238 | }
|
21239 | _get(Object.getPrototypeOf(HlsHandler.prototype), 'dispose', this).call(this);
|
21240 | }
|
21241 | }]);
|
21242 |
|
21243 | return HlsHandler;
|
21244 | })(Component);
|
21245 |
|
21246 | var HlsSourceHandler = function HlsSourceHandler(mode) {
|
21247 | return {
|
21248 | canHandleSource: function canHandleSource(srcObj) {
|
21249 | var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
21250 |
|
21251 | var localOptions = _videoJs2['default'].mergeOptions(_videoJs2['default'].options, options);
|
21252 |
|
21253 |
|
21254 |
|
21255 | if (localOptions.hls && localOptions.hls.mode && localOptions.hls.mode !== mode) {
|
21256 | return false;
|
21257 | }
|
21258 | return HlsSourceHandler.canPlayType(srcObj.type, localOptions);
|
21259 | },
|
21260 | handleSource: function handleSource(source, tech) {
|
21261 | var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
21262 |
|
21263 | var localOptions = _videoJs2['default'].mergeOptions(_videoJs2['default'].options, options, { hls: { mode: mode } });
|
21264 |
|
21265 | if (mode === 'flash') {
|
21266 |
|
21267 |
|
21268 | tech.setTimeout(function () {
|
21269 | tech.trigger('loadstart');
|
21270 | }, 1);
|
21271 | }
|
21272 |
|
21273 | tech.hls = new HlsHandler(source, tech, localOptions);
|
21274 | tech.hls.xhr = (0, _xhr2['default'])();
|
21275 |
|
21276 | tech.hls.src(source.src);
|
21277 | return tech.hls;
|
21278 | },
|
21279 | canPlayType: function canPlayType(type) {
|
21280 | var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
21281 |
|
21282 | var localOptions = _videoJs2['default'].mergeOptions(_videoJs2['default'].options, options);
|
21283 |
|
21284 | if (HlsSourceHandler.canPlayType(type, localOptions)) {
|
21285 | return 'maybe';
|
21286 | }
|
21287 | return '';
|
21288 | }
|
21289 | };
|
21290 | };
|
21291 |
|
21292 | HlsSourceHandler.canPlayType = function (type, options) {
|
21293 |
|
21294 | if (_videoJs2['default'].browser.IE_VERSION && _videoJs2['default'].browser.IE_VERSION <= 10) {
|
21295 | return false;
|
21296 | }
|
21297 |
|
21298 | var mpegurlRE = /^(audio|video|application)\/(x-|vnd\.apple\.)?mpegurl/i;
|
21299 |
|
21300 |
|
21301 | if (!options.hls.overrideNative && Hls.supportsNativeHls) {
|
21302 | return false;
|
21303 | }
|
21304 | return mpegurlRE.test(type);
|
21305 | };
|
21306 |
|
21307 | if (typeof _videoJs2['default'].MediaSource === 'undefined' || typeof _videoJs2['default'].URL === 'undefined') {
|
21308 | _videoJs2['default'].MediaSource = _videojsContribMediaSources.MediaSource;
|
21309 | _videoJs2['default'].URL = _videojsContribMediaSources.URL;
|
21310 | }
|
21311 |
|
21312 | var flashTech = _videoJs2['default'].getTech('Flash');
|
21313 |
|
21314 |
|
21315 | if (_videojsContribMediaSources.MediaSource.supportsNativeMediaSources()) {
|
21316 | _videoJs2['default'].getTech('Html5').registerSourceHandler(HlsSourceHandler('html5'), 0);
|
21317 | }
|
21318 | if (_globalWindow2['default'].Uint8Array && flashTech) {
|
21319 | flashTech.registerSourceHandler(HlsSourceHandler('flash'));
|
21320 | }
|
21321 |
|
21322 | _videoJs2['default'].HlsHandler = HlsHandler;
|
21323 | _videoJs2['default'].HlsSourceHandler = HlsSourceHandler;
|
21324 | _videoJs2['default'].Hls = Hls;
|
21325 | if (!_videoJs2['default'].use) {
|
21326 | _videoJs2['default'].registerComponent('Hls', Hls);
|
21327 | }
|
21328 | _videoJs2['default'].m3u8 = _m3u8Parser2['default'];
|
21329 | _videoJs2['default'].options.hls = _videoJs2['default'].options.hls || {};
|
21330 |
|
21331 | if (_videoJs2['default'].registerPlugin) {
|
21332 | _videoJs2['default'].registerPlugin('reloadSourceOnError', _reloadSourceOnError2['default']);
|
21333 | } else {
|
21334 | _videoJs2['default'].plugin('reloadSourceOnError', _reloadSourceOnError2['default']);
|
21335 | }
|
21336 |
|
21337 | module.exports = {
|
21338 | Hls: Hls,
|
21339 | HlsHandler: HlsHandler,
|
21340 | HlsSourceHandler: HlsSourceHandler
|
21341 | };
|
21342 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
21343 | },{"./bin-utils":2,"./config":3,"./master-playlist-controller":5,"./playback-watcher":8,"./playlist":11,"./playlist-loader":9,"./playlist-selectors.js":10,"./reload-source-on-error":13,"./rendition-mixin":14,"./xhr":21,"aes-decrypter":25,"global/document":31,"global/window":32,"m3u8-parser":33,"videojs-contrib-media-sources":74}]},{},[77])(77)
|
21344 | }); |
\ | No newline at end of file |