mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
921206dc1d
This PR introduces a Web Worker for transmuxing resolving https://github.com/shaka-project/shaka-player/issues/1735 - The worker bundle is compiled separately - The build output is embedded as a string constant and then wrapped in a Blob to create an inline Worker URL (HLS.js does this very similarly) - `TransmuxerProxy` is created wrapping a real transmuxer, but no worker is started yet - on the first `transmux()` call, it checks if the device supports worker transmuxing - For each transmux() call: the buffer is copied, then zero-copy transferred to the worker. A PublicPromise is stored under a reqId with a timeout timer, and the main thread awaits it. - The worker transmuxes and posts back transmuxed (or error). The shared message listener routes the response to the right proxy instance by id, which resolves the promise and cancels the timer. - When the last proxy instance is destroyed, the worker is terminated and the blob URL is revoked. loaded inside the worker. - Some low-end devices have been excluded since their Worker support is questionable There most likely is a better way to do this - please let me know
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.media.Capabilities');
|
|
|
|
/**
|
|
* @summary
|
|
* This is for capturing all media source capabilities on current platform.
|
|
* And this is for static check and can not be constructed.
|
|
*/
|
|
shaka.media.Capabilities = class {
|
|
/**
|
|
* Cache browser engine call to improve performance on some poor platforms
|
|
*
|
|
* @param {string} type
|
|
* @return {boolean}
|
|
*/
|
|
static isTypeSupported(type) {
|
|
const supportMap = shaka.media.Capabilities.MediaSourceTypeSupportMap;
|
|
return supportMap.getOrInsertComputed(type, () => {
|
|
// Use self instead of window so this works in Worker contexts
|
|
// (where window is not defined) as well as on the main thread.
|
|
const mediaSource = self.ManagedMediaSource || self.MediaSource;
|
|
return mediaSource?.isTypeSupported(type) ?? false;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Determine support for MediaSource.setLiveSeekableRange and
|
|
* MediaSource.clearLiveSeekableRange, which can allow for a media element
|
|
* duration of Infinite by providing a non-infinite seekable range.
|
|
*
|
|
* @return {boolean}
|
|
*/
|
|
static isInfiniteLiveStreamDurationSupported() {
|
|
// Use self instead of window so this works in Worker contexts.
|
|
const mediaSource = self.ManagedMediaSource || self.MediaSource;
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
if (mediaSource && mediaSource.prototype) {
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
return !!mediaSource.prototype.setLiveSeekableRange &&
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
!!mediaSource.prototype.clearLiveSeekableRange;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Public it for unit test, and developer could also check the support map.
|
|
* @type {!Map<string, boolean>}
|
|
*/
|
|
shaka.media.Capabilities.MediaSourceTypeSupportMap = new Map();
|