Add VideoDecoderProperties for the web

This commit is contained in:
Zoe Roux 2024-06-30 09:35:34 +00:00
parent ca2452edb6
commit fa126de97f
No known key found for this signature in database
2 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,45 @@
/// <reference lib="dom" />
import type {VideoDecoderPropertiesType} from './specs/VideoNativeComponent';
class VideoDecoderProperties implements VideoDecoderPropertiesType {
async getWidevineLevel() {
return 0;
}
static canPlay(codec: string): boolean {
// most chrome based browser (and safari I think) supports matroska but reports they do not.
// for those browsers, only check the codecs and not the container.
if (navigator.userAgent.search('Firefox') === -1) {
codec = codec.replace('video/x-matroska', 'video/mp4');
}
// Find any video element that we could use to check, or create one that will
// instantly be garbage collected
const videos = document.getElementsByTagName('video');
const video = videos.item(0) ?? document.createElement('video');
return !!video.canPlayType(codec);
}
async isCodecSupported(
mimeType: string,
_width: number,
_height: number,
): Promise<'unsupported' | 'hardware' | 'software'> {
// TODO: Figure out if we can get hardware support information
return VideoDecoderProperties.canPlay(mimeType)
? 'software'
: 'unsupported';
}
async isHEVCSupported(): Promise<'unsupported' | 'hardware' | 'software'> {
// Just a dummy vidoe mime type codec with HEVC to check.
return VideoDecoderProperties.canPlay(
'video/x-matroska; codecs="hvc1.1.4.L96.BO"',
)
? 'software'
: 'unsupported';
}
}
export default VideoDecoderProperties;

View File

@ -1,5 +1,5 @@
import Video from './Video'; import Video from './Video';
export {VideoDecoderProperties} from './VideoDecoderProperties'; export {VideoDecoderProperties} from './VideoDecoderProperties';
export * from './types'; export type * from './types';
export type {VideoRef} from './Video'; export type {VideoRef} from './Video';
export default Video; export default Video;