react-native-video/src/VideoDecoderProperties.web.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-06-30 03:35:34 -06:00
/// <reference lib="dom" />
import type {VideoDecoderPropertiesType} from './specs/VideoNativeComponent';
const 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');
2024-06-30 03:35:34 -06:00
}
return !!MediaSource.isTypeSupported(codec);
};
2024-06-30 03:35:34 -06:00
export const VideoDecoderProperties = {
async getWidevineLevel() {
return 0;
},
2024-06-30 03:35:34 -06:00
async isCodecSupported(
mimeType: string,
_width: number,
_height: number,
): Promise<'unsupported' | 'hardware' | 'software'> {
// TODO: Figure out if we can get hardware support information
return canPlay(mimeType) ? 'software' : 'unsupported';
},
2024-06-30 03:35:34 -06:00
async isHEVCSupported(): Promise<'unsupported' | 'hardware' | 'software'> {
// Just a dummy vidoe mime type codec with HEVC to check.
return canPlay('video/x-matroska; codecs="hvc1.1.4.L96.BO"')
2024-06-30 03:35:34 -06:00
? 'software'
: 'unsupported';
},
} satisfies VideoDecoderPropertiesType;