2022-01-18 17:05:34 +08:00
|
|
|
// example: https://github.com/rgov/js-theora-decoder/blob/main/index.html
|
2022-02-05 01:55:23 +08:00
|
|
|
// https://github.com/brion/ogv.js/releases, yarn add has no simd
|
2022-01-18 17:05:34 +08:00
|
|
|
// dev: copy decoder files from node/ogv/dist/* to project dir
|
|
|
|
// dist: .... to dist
|
2022-01-18 17:24:36 +08:00
|
|
|
/*
|
2022-01-20 01:00:35 +08:00
|
|
|
OGVDemuxerOggW: 'ogv-demuxer-ogg-wasm.js',
|
|
|
|
OGVDemuxerWebMW: 'ogv-demuxer-webm-wasm.js',
|
|
|
|
OGVDecoderAudioOpusW: 'ogv-decoder-audio-opus-wasm.js',
|
|
|
|
OGVDecoderAudioVorbisW: 'ogv-decoder-audio-vorbis-wasm.js',
|
|
|
|
OGVDecoderVideoTheoraW: 'ogv-decoder-video-theora-wasm.js',
|
|
|
|
OGVDecoderVideoVP8W: 'ogv-decoder-video-vp8-wasm.js',
|
|
|
|
OGVDecoderVideoVP8MTW: 'ogv-decoder-video-vp8-mt-wasm.js',
|
|
|
|
OGVDecoderVideoVP9W: 'ogv-decoder-video-vp9-wasm.js',
|
|
|
|
OGVDecoderVideoVP9SIMDW: 'ogv-decoder-video-vp9-simd-wasm.js',
|
|
|
|
OGVDecoderVideoVP9MTW: 'ogv-decoder-video-vp9-mt-wasm.js',
|
|
|
|
OGVDecoderVideoVP9SIMDMTW: 'ogv-decoder-video-vp9-simd-mt-wasm.js',
|
|
|
|
OGVDecoderVideoAV1W: 'ogv-decoder-video-av1-wasm.js',
|
|
|
|
OGVDecoderVideoAV1SIMDW: 'ogv-decoder-video-av1-simd-wasm.js',
|
|
|
|
OGVDecoderVideoAV1MTW: 'ogv-decoder-video-av1-mt-wasm.js',
|
|
|
|
OGVDecoderVideoAV1SIMDMTW: 'ogv-decoder-video-av1-simd-mt-wasm.js',
|
2022-01-18 17:24:36 +08:00
|
|
|
*/
|
2022-02-05 04:28:40 +08:00
|
|
|
import { simd } from "wasm-feature-detect";
|
2022-01-18 17:05:34 +08:00
|
|
|
|
2022-02-05 04:28:40 +08:00
|
|
|
export async function loadVp9(callback) {
|
2022-02-05 01:55:23 +08:00
|
|
|
// Multithreading is used only if `options.threading` is true.
|
|
|
|
// This requires browser support for the new `SharedArrayBuffer` and `Atomics` APIs,
|
|
|
|
// currently available in Firefox and Chrome with experimental flags enabled.
|
|
|
|
// 所有主流浏览器均默认于2018年1月5日禁用SharedArrayBuffer
|
2022-02-05 04:28:40 +08:00
|
|
|
const isSIMD = await simd();
|
|
|
|
console.log('isSIMD: ' + isSIMD);
|
2022-01-20 01:00:35 +08:00
|
|
|
window.OGVLoader.loadClass(
|
2022-02-05 04:28:40 +08:00
|
|
|
isSIMD ? "OGVDecoderVideoVP9SIMDW" : "OGVDecoderVideoVP9W",
|
2022-01-20 01:00:35 +08:00
|
|
|
(videoCodecClass) => {
|
2022-01-20 21:58:28 +08:00
|
|
|
window.videoCodecClass = videoCodecClass;
|
2022-01-21 00:41:02 +08:00
|
|
|
videoCodecClass({ videoFormat: {} }).then((decoder) => {
|
2022-01-20 01:00:35 +08:00
|
|
|
decoder.init(() => {
|
2022-01-20 21:58:28 +08:00
|
|
|
callback(decoder);
|
2022-01-20 01:00:35 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2022-02-05 01:55:23 +08:00
|
|
|
{ worker: true, threading: true }
|
2022-01-20 01:00:35 +08:00
|
|
|
);
|
2022-01-18 17:05:34 +08:00
|
|
|
}
|