1 |
|
2 |
|
3 |
|
4 | import videojs from 'video.js';
|
5 | import logger from './util/logger';
|
6 | import noop from './util/noop';
|
7 | import { bufferIntersection } from './ranges.js';
|
8 | import {getMimeForCodec} from '@videojs/vhs-utils/es/codecs.js';
|
9 | import window from 'global/window';
|
10 | import toTitleCase from './util/to-title-case.js';
|
11 | import { QUOTA_EXCEEDED_ERR } from './error-codes';
|
12 |
|
13 | const bufferTypes = [
|
14 | 'video',
|
15 | 'audio'
|
16 | ];
|
17 |
|
18 | const updating = (type, sourceUpdater) => {
|
19 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
20 |
|
21 | return (sourceBuffer && sourceBuffer.updating) || sourceUpdater.queuePending[type];
|
22 | };
|
23 |
|
24 | const nextQueueIndexOfType = (type, queue) => {
|
25 | for (let i = 0; i < queue.length; i++) {
|
26 | const queueEntry = queue[i];
|
27 |
|
28 | if (queueEntry.type === 'mediaSource') {
|
29 |
|
30 |
|
31 | return null;
|
32 | }
|
33 |
|
34 | if (queueEntry.type === type) {
|
35 | return i;
|
36 | }
|
37 | }
|
38 |
|
39 | return null;
|
40 | };
|
41 |
|
42 | const shiftQueue = (type, sourceUpdater) => {
|
43 | if (sourceUpdater.queue.length === 0) {
|
44 | return;
|
45 | }
|
46 |
|
47 | let queueIndex = 0;
|
48 | let queueEntry = sourceUpdater.queue[queueIndex];
|
49 |
|
50 | if (queueEntry.type === 'mediaSource') {
|
51 | if (!sourceUpdater.updating() && sourceUpdater.mediaSource.readyState !== 'closed') {
|
52 | sourceUpdater.queue.shift();
|
53 | queueEntry.action(sourceUpdater);
|
54 |
|
55 | if (queueEntry.doneFn) {
|
56 | queueEntry.doneFn();
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | shiftQueue('audio', sourceUpdater);
|
63 | shiftQueue('video', sourceUpdater);
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | return;
|
70 | }
|
71 |
|
72 | if (type === 'mediaSource') {
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | return;
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | if (
|
84 | !sourceUpdater.ready() ||
|
85 | sourceUpdater.mediaSource.readyState === 'closed' ||
|
86 | updating(type, sourceUpdater)
|
87 | ) {
|
88 | return;
|
89 | }
|
90 |
|
91 | if (queueEntry.type !== type) {
|
92 | queueIndex = nextQueueIndexOfType(type, sourceUpdater.queue);
|
93 |
|
94 | if (queueIndex === null) {
|
95 |
|
96 |
|
97 |
|
98 | return;
|
99 | }
|
100 |
|
101 | queueEntry = sourceUpdater.queue[queueIndex];
|
102 | }
|
103 |
|
104 | sourceUpdater.queue.splice(queueIndex, 1);
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | sourceUpdater.queuePending[type] = queueEntry;
|
113 | queueEntry.action(type, sourceUpdater);
|
114 |
|
115 | if (!queueEntry.doneFn) {
|
116 |
|
117 | sourceUpdater.queuePending[type] = null;
|
118 | shiftQueue(type, sourceUpdater);
|
119 | return;
|
120 | }
|
121 | };
|
122 |
|
123 | const cleanupBuffer = (type, sourceUpdater) => {
|
124 | const buffer = sourceUpdater[`${type}Buffer`];
|
125 | const titleType = toTitleCase(type);
|
126 |
|
127 | if (!buffer) {
|
128 | return;
|
129 | }
|
130 |
|
131 | buffer.removeEventListener('updateend', sourceUpdater[`on${titleType}UpdateEnd_`]);
|
132 | buffer.removeEventListener('error', sourceUpdater[`on${titleType}Error_`]);
|
133 |
|
134 | sourceUpdater.codecs[type] = null;
|
135 | sourceUpdater[`${type}Buffer`] = null;
|
136 | };
|
137 |
|
138 | const inSourceBuffers = (mediaSource, sourceBuffer) => mediaSource && sourceBuffer &&
|
139 | Array.prototype.indexOf.call(mediaSource.sourceBuffers, sourceBuffer) !== -1;
|
140 |
|
141 | const actions = {
|
142 | appendBuffer: (bytes, segmentInfo, onError) => (type, sourceUpdater) => {
|
143 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
144 |
|
145 |
|
146 |
|
147 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
148 | return;
|
149 | }
|
150 |
|
151 | sourceUpdater.logger_(`Appending segment ${segmentInfo.mediaIndex}'s ${bytes.length} bytes to ${type}Buffer`);
|
152 |
|
153 | try {
|
154 | sourceBuffer.appendBuffer(bytes);
|
155 | } catch (e) {
|
156 | sourceUpdater.logger_(`Error with code ${e.code} ` +
|
157 | (e.code === QUOTA_EXCEEDED_ERR ? '(QUOTA_EXCEEDED_ERR) ' : '') +
|
158 | `when appending segment ${segmentInfo.mediaIndex} to ${type}Buffer`);
|
159 | sourceUpdater.queuePending[type] = null;
|
160 | onError(e);
|
161 | }
|
162 | },
|
163 | remove: (start, end) => (type, sourceUpdater) => {
|
164 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
165 |
|
166 |
|
167 |
|
168 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
169 | return;
|
170 | }
|
171 |
|
172 | sourceUpdater.logger_(`Removing ${start} to ${end} from ${type}Buffer`);
|
173 | try {
|
174 | sourceBuffer.remove(start, end);
|
175 | } catch (e) {
|
176 | sourceUpdater.logger_(`Remove ${start} to ${end} from ${type}Buffer failed`);
|
177 | }
|
178 | },
|
179 | timestampOffset: (offset) => (type, sourceUpdater) => {
|
180 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
181 |
|
182 |
|
183 |
|
184 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
185 | return;
|
186 | }
|
187 |
|
188 | sourceUpdater.logger_(`Setting ${type}timestampOffset to ${offset}`);
|
189 |
|
190 | sourceBuffer.timestampOffset = offset;
|
191 | },
|
192 | callback: (callback) => (type, sourceUpdater) => {
|
193 | callback();
|
194 | },
|
195 | endOfStream: (error) => (sourceUpdater) => {
|
196 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
197 | return;
|
198 | }
|
199 | sourceUpdater.logger_(`Calling mediaSource endOfStream(${error || ''})`);
|
200 |
|
201 | try {
|
202 | sourceUpdater.mediaSource.endOfStream(error);
|
203 | } catch (e) {
|
204 | videojs.log.warn('Failed to call media source endOfStream', e);
|
205 | }
|
206 | },
|
207 | duration: (duration) => (sourceUpdater) => {
|
208 | sourceUpdater.logger_(`Setting mediaSource duration to ${duration}`);
|
209 | try {
|
210 | sourceUpdater.mediaSource.duration = duration;
|
211 | } catch (e) {
|
212 | videojs.log.warn('Failed to set media source duration', e);
|
213 | }
|
214 | },
|
215 | abort: () => (type, sourceUpdater) => {
|
216 | if (sourceUpdater.mediaSource.readyState !== 'open') {
|
217 | return;
|
218 | }
|
219 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
220 |
|
221 |
|
222 |
|
223 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
224 | return;
|
225 | }
|
226 |
|
227 | sourceUpdater.logger_(`calling abort on ${type}Buffer`);
|
228 | try {
|
229 | sourceBuffer.abort();
|
230 | } catch (e) {
|
231 | videojs.log.warn(`Failed to abort on ${type}Buffer`, e);
|
232 | }
|
233 | },
|
234 | addSourceBuffer: (type, codec) => (sourceUpdater) => {
|
235 | const titleType = toTitleCase(type);
|
236 | const mime = getMimeForCodec(codec);
|
237 |
|
238 | sourceUpdater.logger_(`Adding ${type}Buffer with codec ${codec} to mediaSource`);
|
239 |
|
240 | const sourceBuffer = sourceUpdater.mediaSource.addSourceBuffer(mime);
|
241 |
|
242 | sourceBuffer.addEventListener('updateend', sourceUpdater[`on${titleType}UpdateEnd_`]);
|
243 | sourceBuffer.addEventListener('error', sourceUpdater[`on${titleType}Error_`]);
|
244 | sourceUpdater.codecs[type] = codec;
|
245 | sourceUpdater[`${type}Buffer`] = sourceBuffer;
|
246 | },
|
247 | removeSourceBuffer: (type) => (sourceUpdater) => {
|
248 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
249 |
|
250 | cleanupBuffer(type, sourceUpdater);
|
251 |
|
252 |
|
253 |
|
254 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
255 | return;
|
256 | }
|
257 |
|
258 | sourceUpdater.logger_(`Removing ${type}Buffer with codec ${sourceUpdater.codecs[type]} from mediaSource`);
|
259 |
|
260 | try {
|
261 | sourceUpdater.mediaSource.removeSourceBuffer(sourceBuffer);
|
262 | } catch (e) {
|
263 | videojs.log.warn(`Failed to removeSourceBuffer ${type}Buffer`, e);
|
264 | }
|
265 | },
|
266 | changeType: (codec) => (type, sourceUpdater) => {
|
267 | const sourceBuffer = sourceUpdater[`${type}Buffer`];
|
268 | const mime = getMimeForCodec(codec);
|
269 |
|
270 |
|
271 |
|
272 | if (!inSourceBuffers(sourceUpdater.mediaSource, sourceBuffer)) {
|
273 | return;
|
274 | }
|
275 |
|
276 |
|
277 | if (sourceUpdater.codecs[type] === codec) {
|
278 | return;
|
279 | }
|
280 |
|
281 | sourceUpdater.logger_(`changing ${type}Buffer codec from ${sourceUpdater.codecs[type]} to ${codec}`);
|
282 |
|
283 | sourceBuffer.changeType(mime);
|
284 | sourceUpdater.codecs[type] = codec;
|
285 | }
|
286 | };
|
287 |
|
288 | const pushQueue = ({type, sourceUpdater, action, doneFn, name}) => {
|
289 | sourceUpdater.queue.push({
|
290 | type,
|
291 | action,
|
292 | doneFn,
|
293 | name
|
294 | });
|
295 | shiftQueue(type, sourceUpdater);
|
296 | };
|
297 |
|
298 | const onUpdateend = (type, sourceUpdater) => (e) => {
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | if (sourceUpdater.queuePending[type]) {
|
306 | const doneFn = sourceUpdater.queuePending[type].doneFn;
|
307 |
|
308 | sourceUpdater.queuePending[type] = null;
|
309 |
|
310 | if (doneFn) {
|
311 |
|
312 | doneFn(sourceUpdater[`${type}Error_`]);
|
313 | }
|
314 | }
|
315 |
|
316 | shiftQueue(type, sourceUpdater);
|
317 | };
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | export default class SourceUpdater extends videojs.EventTarget {
|
330 | constructor(mediaSource) {
|
331 | super();
|
332 | this.mediaSource = mediaSource;
|
333 | this.sourceopenListener_ = () => shiftQueue('mediaSource', this);
|
334 | this.mediaSource.addEventListener('sourceopen', this.sourceopenListener_);
|
335 | this.logger_ = logger('SourceUpdater');
|
336 |
|
337 | this.audioTimestampOffset_ = 0;
|
338 | this.videoTimestampOffset_ = 0;
|
339 | this.queue = [];
|
340 | this.queuePending = {
|
341 | audio: null,
|
342 | video: null
|
343 | };
|
344 | this.delayedAudioAppendQueue_ = [];
|
345 | this.videoAppendQueued_ = false;
|
346 | this.codecs = {};
|
347 | this.onVideoUpdateEnd_ = onUpdateend('video', this);
|
348 | this.onAudioUpdateEnd_ = onUpdateend('audio', this);
|
349 | this.onVideoError_ = (e) => {
|
350 |
|
351 | this.videoError_ = e;
|
352 | };
|
353 | this.onAudioError_ = (e) => {
|
354 |
|
355 | this.audioError_ = e;
|
356 | };
|
357 | this.createdSourceBuffers_ = false;
|
358 | this.initializedEme_ = false;
|
359 | this.triggeredReady_ = false;
|
360 | }
|
361 |
|
362 | initializedEme() {
|
363 | this.initializedEme_ = true;
|
364 | this.triggerReady();
|
365 | }
|
366 |
|
367 | hasCreatedSourceBuffers() {
|
368 |
|
369 |
|
370 | return this.createdSourceBuffers_;
|
371 | }
|
372 |
|
373 | hasInitializedAnyEme() {
|
374 | return this.initializedEme_;
|
375 | }
|
376 |
|
377 | ready() {
|
378 | return this.hasCreatedSourceBuffers() && this.hasInitializedAnyEme();
|
379 | }
|
380 |
|
381 | createSourceBuffers(codecs) {
|
382 | if (this.hasCreatedSourceBuffers()) {
|
383 |
|
384 | return;
|
385 | }
|
386 |
|
387 |
|
388 |
|
389 | this.addOrChangeSourceBuffers(codecs);
|
390 | this.createdSourceBuffers_ = true;
|
391 | this.trigger('createdsourcebuffers');
|
392 | this.triggerReady();
|
393 | }
|
394 |
|
395 | triggerReady() {
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 | if (this.ready() && !this.triggeredReady_) {
|
403 | this.triggeredReady_ = true;
|
404 | this.trigger('ready');
|
405 | }
|
406 | }
|
407 |
|
408 | |
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | addSourceBuffer(type, codec) {
|
418 | pushQueue({
|
419 | type: 'mediaSource',
|
420 | sourceUpdater: this,
|
421 | action: actions.addSourceBuffer(type, codec),
|
422 | name: 'addSourceBuffer'
|
423 | });
|
424 | }
|
425 |
|
426 | |
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 | abort(type) {
|
433 | pushQueue({
|
434 | type,
|
435 | sourceUpdater: this,
|
436 | action: actions.abort(type),
|
437 | name: 'abort'
|
438 | });
|
439 | }
|
440 |
|
441 | |
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 | removeSourceBuffer(type) {
|
449 | if (!this.canRemoveSourceBuffer()) {
|
450 | videojs.log.error('removeSourceBuffer is not supported!');
|
451 | return;
|
452 | }
|
453 |
|
454 | pushQueue({
|
455 | type: 'mediaSource',
|
456 | sourceUpdater: this,
|
457 | action: actions.removeSourceBuffer(type),
|
458 | name: 'removeSourceBuffer'
|
459 | });
|
460 | }
|
461 |
|
462 | |
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 | canRemoveSourceBuffer() {
|
470 |
|
471 |
|
472 |
|
473 |
|
474 | return !videojs.browser.IE_VERSION && !videojs.browser.IS_FIREFOX && window.MediaSource &&
|
475 | window.MediaSource.prototype &&
|
476 | typeof window.MediaSource.prototype.removeSourceBuffer === 'function';
|
477 | }
|
478 |
|
479 | |
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 | static canChangeType() {
|
487 | return window.SourceBuffer &&
|
488 | window.SourceBuffer.prototype &&
|
489 | typeof window.SourceBuffer.prototype.changeType === 'function';
|
490 | }
|
491 |
|
492 | |
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 | canChangeType() {
|
500 | return this.constructor.canChangeType();
|
501 | }
|
502 |
|
503 | |
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 | changeType(type, codec) {
|
513 | if (!this.canChangeType()) {
|
514 | videojs.log.error('changeType is not supported!');
|
515 | return;
|
516 | }
|
517 |
|
518 | pushQueue({
|
519 | type,
|
520 | sourceUpdater: this,
|
521 | action: actions.changeType(codec),
|
522 | name: 'changeType'
|
523 | });
|
524 | }
|
525 |
|
526 | |
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 | addOrChangeSourceBuffers(codecs) {
|
534 | if (!codecs || typeof codecs !== 'object' || Object.keys(codecs).length === 0) {
|
535 | throw new Error('Cannot addOrChangeSourceBuffers to undefined codecs');
|
536 | }
|
537 |
|
538 | Object.keys(codecs).forEach((type) => {
|
539 | const codec = codecs[type];
|
540 |
|
541 | if (!this.hasCreatedSourceBuffers()) {
|
542 | return this.addSourceBuffer(type, codec);
|
543 | }
|
544 |
|
545 | if (this.canChangeType()) {
|
546 | this.changeType(type, codec);
|
547 | }
|
548 | });
|
549 | }
|
550 |
|
551 | |
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 | appendBuffer(options, doneFn) {
|
559 | const {segmentInfo, type, bytes} = options;
|
560 |
|
561 | this.processedAppend_ = true;
|
562 | if (type === 'audio' && this.videoBuffer && !this.videoAppendQueued_) {
|
563 | this.delayedAudioAppendQueue_.push([options, doneFn]);
|
564 | this.logger_(`delayed audio append of ${bytes.length} until video append`);
|
565 | return;
|
566 | }
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 | const onError = doneFn;
|
573 |
|
574 | pushQueue({
|
575 | type,
|
576 | sourceUpdater: this,
|
577 | action: actions.appendBuffer(bytes, segmentInfo || {mediaIndex: -1}, onError),
|
578 | doneFn,
|
579 | name: 'appendBuffer'
|
580 | });
|
581 |
|
582 | if (type === 'video') {
|
583 | this.videoAppendQueued_ = true;
|
584 | if (!this.delayedAudioAppendQueue_.length) {
|
585 | return;
|
586 | }
|
587 | const queue = this.delayedAudioAppendQueue_.slice();
|
588 |
|
589 | this.logger_(`queuing delayed audio ${queue.length} appendBuffers`);
|
590 |
|
591 | this.delayedAudioAppendQueue_.length = 0;
|
592 | queue.forEach((que) => {
|
593 | this.appendBuffer.apply(this, que);
|
594 | });
|
595 | }
|
596 | }
|
597 |
|
598 | |
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 | audioBuffered() {
|
605 |
|
606 |
|
607 | if (!inSourceBuffers(this.mediaSource, this.audioBuffer)) {
|
608 | return videojs.createTimeRange();
|
609 | }
|
610 |
|
611 | return this.audioBuffer.buffered ? this.audioBuffer.buffered :
|
612 | videojs.createTimeRange();
|
613 | }
|
614 |
|
615 | |
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 | videoBuffered() {
|
622 |
|
623 |
|
624 | if (!inSourceBuffers(this.mediaSource, this.videoBuffer)) {
|
625 | return videojs.createTimeRange();
|
626 | }
|
627 | return this.videoBuffer.buffered ? this.videoBuffer.buffered :
|
628 | videojs.createTimeRange();
|
629 | }
|
630 |
|
631 | |
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 | buffered() {
|
638 | const video = inSourceBuffers(this.mediaSource, this.videoBuffer) ? this.videoBuffer : null;
|
639 | const audio = inSourceBuffers(this.mediaSource, this.audioBuffer) ? this.audioBuffer : null;
|
640 |
|
641 | if (audio && !video) {
|
642 | return this.audioBuffered();
|
643 | }
|
644 |
|
645 | if (video && !audio) {
|
646 | return this.videoBuffered();
|
647 | }
|
648 |
|
649 | return bufferIntersection(this.audioBuffered(), this.videoBuffered());
|
650 | }
|
651 |
|
652 | |
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 | setDuration(duration, doneFn = noop) {
|
662 |
|
663 |
|
664 |
|
665 |
|
666 | pushQueue({
|
667 | type: 'mediaSource',
|
668 | sourceUpdater: this,
|
669 | action: actions.duration(duration),
|
670 | name: 'duration',
|
671 | doneFn
|
672 | });
|
673 | }
|
674 |
|
675 | |
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | endOfStream(error = null, doneFn = noop) {
|
686 | if (typeof error !== 'string') {
|
687 | error = undefined;
|
688 | }
|
689 |
|
690 |
|
691 |
|
692 |
|
693 | pushQueue({
|
694 | type: 'mediaSource',
|
695 | sourceUpdater: this,
|
696 | action: actions.endOfStream(error),
|
697 | name: 'endOfStream',
|
698 | doneFn
|
699 | });
|
700 | }
|
701 |
|
702 | |
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 | removeAudio(start, end, done = noop) {
|
712 | if (!this.audioBuffered().length || this.audioBuffered().end(0) === 0) {
|
713 | done();
|
714 | return;
|
715 | }
|
716 |
|
717 | pushQueue({
|
718 | type: 'audio',
|
719 | sourceUpdater: this,
|
720 | action: actions.remove(start, end),
|
721 | doneFn: done,
|
722 | name: 'remove'
|
723 | });
|
724 | }
|
725 |
|
726 | |
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 | removeVideo(start, end, done = noop) {
|
736 | if (!this.videoBuffered().length || this.videoBuffered().end(0) === 0) {
|
737 | done();
|
738 | return;
|
739 | }
|
740 |
|
741 | pushQueue({
|
742 | type: 'video',
|
743 | sourceUpdater: this,
|
744 | action: actions.remove(start, end),
|
745 | doneFn: done,
|
746 | name: 'remove'
|
747 | });
|
748 | }
|
749 |
|
750 | |
751 |
|
752 |
|
753 |
|
754 |
|
755 | updating() {
|
756 |
|
757 | if (updating('audio', this) || updating('video', this)) {
|
758 | return true;
|
759 | }
|
760 |
|
761 | return false;
|
762 | }
|
763 |
|
764 | |
765 |
|
766 |
|
767 |
|
768 |
|
769 | audioTimestampOffset(offset) {
|
770 | if (typeof offset !== 'undefined' &&
|
771 | this.audioBuffer &&
|
772 |
|
773 | this.audioTimestampOffset_ !== offset) {
|
774 | pushQueue({
|
775 | type: 'audio',
|
776 | sourceUpdater: this,
|
777 | action: actions.timestampOffset(offset),
|
778 | name: 'timestampOffset'
|
779 | });
|
780 | this.audioTimestampOffset_ = offset;
|
781 | }
|
782 | return this.audioTimestampOffset_;
|
783 | }
|
784 |
|
785 | |
786 |
|
787 |
|
788 |
|
789 |
|
790 | videoTimestampOffset(offset) {
|
791 | if (typeof offset !== 'undefined' &&
|
792 | this.videoBuffer &&
|
793 |
|
794 | this.videoTimestampOffset !== offset) {
|
795 | pushQueue({
|
796 | type: 'video',
|
797 | sourceUpdater: this,
|
798 | action: actions.timestampOffset(offset),
|
799 | name: 'timestampOffset'
|
800 | });
|
801 | this.videoTimestampOffset_ = offset;
|
802 | }
|
803 | return this.videoTimestampOffset_;
|
804 | }
|
805 |
|
806 | |
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 | audioQueueCallback(callback) {
|
814 | if (!this.audioBuffer) {
|
815 | return;
|
816 | }
|
817 | pushQueue({
|
818 | type: 'audio',
|
819 | sourceUpdater: this,
|
820 | action: actions.callback(callback),
|
821 | name: 'callback'
|
822 | });
|
823 | }
|
824 |
|
825 | |
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 | videoQueueCallback(callback) {
|
833 | if (!this.videoBuffer) {
|
834 | return;
|
835 | }
|
836 | pushQueue({
|
837 | type: 'video',
|
838 | sourceUpdater: this,
|
839 | action: actions.callback(callback),
|
840 | name: 'callback'
|
841 | });
|
842 | }
|
843 |
|
844 | |
845 |
|
846 |
|
847 | dispose() {
|
848 | this.trigger('dispose');
|
849 | bufferTypes.forEach((type) => {
|
850 | this.abort(type);
|
851 | if (this.canRemoveSourceBuffer()) {
|
852 | this.removeSourceBuffer(type);
|
853 | } else {
|
854 | this[`${type}QueueCallback`](() => cleanupBuffer(type, this));
|
855 | }
|
856 | });
|
857 |
|
858 | this.videoAppendQueued_ = false;
|
859 | this.delayedAudioAppendQueue_.length = 0;
|
860 |
|
861 | if (this.sourceopenListener_) {
|
862 | this.mediaSource.removeEventListener('sourceopen', this.sourceopenListener_);
|
863 | }
|
864 |
|
865 | this.off();
|
866 | }
|
867 | }
|