diff --git a/src/avcodec/webcodec/AudioDecoder.ts b/src/avcodec/webcodec/AudioDecoder.ts index 89c790e4..c0347db7 100644 --- a/src/avcodec/webcodec/AudioDecoder.ts +++ b/src/avcodec/webcodec/AudioDecoder.ts @@ -87,11 +87,16 @@ export default class WebAudioDecoder { delete config.description } - const support = await AudioDecoder.isConfigSupported(config) - - if (!support.supported) { - logger.error('not support') - return errorType.INVALID_PARAMETERS + try { + const support = await AudioDecoder.isConfigSupported(config) + if (!support.supported) { + logger.error('not support') + return errorType.INVALID_PARAMETERS + } + } + catch (error) { + logger.error(`${error}`) + return errorType.CODEC_NOT_SUPPORT } if (this.decoder && this.decoder.state !== 'closed') { @@ -218,8 +223,12 @@ export default class WebAudioDecoder { delete config.description } - const support = await AudioDecoder.isConfigSupported(config) - - return support.supported + try { + const support = await AudioDecoder.isConfigSupported(config) + return support.supported + } + catch (error) { + return false + } } } diff --git a/src/avcodec/webcodec/AudioEncoder.ts b/src/avcodec/webcodec/AudioEncoder.ts index ba7888eb..d90545ea 100644 --- a/src/avcodec/webcodec/AudioEncoder.ts +++ b/src/avcodec/webcodec/AudioEncoder.ts @@ -122,11 +122,16 @@ export default class WebAudioEncoder { bitrateMode: 'constant' } - const support = await AudioEncoder.isConfigSupported(config) - - if (!support.supported) { - logger.error('not support') - return errorType.INVALID_PARAMETERS + try { + const support = await AudioEncoder.isConfigSupported(config) + if (!support.supported) { + logger.error('not support') + return errorType.INVALID_PARAMETERS + } + } + catch (error) { + logger.error(`${error}`) + return errorType.CODEC_NOT_SUPPORT } if (this.encoder && this.encoder.state !== 'closed') { @@ -222,9 +227,12 @@ export default class WebAudioEncoder { bitrate: static_cast(parameters.bitrate), bitrateMode: 'constant' } - - const support = await AudioEncoder.isConfigSupported(config) - - return support.supported + try { + const support = await AudioEncoder.isConfigSupported(config) + return support.supported + } + catch (error) { + return false + } } } diff --git a/src/avcodec/webcodec/VideoDecoder.ts b/src/avcodec/webcodec/VideoDecoder.ts index 80c58633..48895611 100644 --- a/src/avcodec/webcodec/VideoDecoder.ts +++ b/src/avcodec/webcodec/VideoDecoder.ts @@ -173,11 +173,16 @@ export default class WebVideoDecoder { delete config.description } - const support = await VideoDecoder.isConfigSupported(config) - - if (!support.supported) { - logger.error('not support') - return errorType.INVALID_PARAMETERS + try { + const support = await VideoDecoder.isConfigSupported(config) + if (!support.supported) { + logger.error('not support') + return errorType.INVALID_PARAMETERS + } + } + catch (error) { + logger.error(`${error}`) + return errorType.CODEC_NOT_SUPPORT } if (this.decoder && this.decoder.state !== 'closed') { @@ -361,8 +366,12 @@ export default class WebVideoDecoder { delete config.description } - const support = await VideoDecoder.isConfigSupported(config) - - return support.supported + try { + const support = await VideoDecoder.isConfigSupported(config) + return support.supported + } + catch (error) { + return false + } } } diff --git a/src/avcodec/webcodec/VideoEncoder.ts b/src/avcodec/webcodec/VideoEncoder.ts index 5121b489..57b06a0a 100644 --- a/src/avcodec/webcodec/VideoEncoder.ts +++ b/src/avcodec/webcodec/VideoEncoder.ts @@ -209,11 +209,16 @@ export default class WebVideoEncoder { } } - const support = await VideoEncoder.isConfigSupported(config) - - if (!support.supported) { - logger.error('not support') - return errorType.INVALID_PARAMETERS + try { + const support = await VideoEncoder.isConfigSupported(config) + if (!support.supported) { + logger.error('not support') + return errorType.INVALID_PARAMETERS + } + } + catch (error) { + logger.error(`${error}`) + return errorType.CODEC_NOT_SUPPORT } if (this.encoder && this.encoder.state !== 'closed') { @@ -372,8 +377,12 @@ export default class WebVideoEncoder { } } - const support = await VideoEncoder.isConfigSupported(config) - - return support.supported + try { + const support = await VideoEncoder.isConfigSupported(config) + return support.supported + } + catch (error) { + return false + } } } diff --git a/src/avplayer/AVPlayer.ts b/src/avplayer/AVPlayer.ts index 7004d955..f1a52794 100644 --- a/src/avplayer/AVPlayer.ts +++ b/src/avplayer/AVPlayer.ts @@ -603,18 +603,22 @@ export default class AVPlayer extends Emitter implements ControllerObserver { if (videoStream.codecpar.extradata !== nullptr) { extradata = mapUint8Array(videoStream.codecpar.extradata, reinterpret_cast(videoStream.codecpar.extradataSize)) } - // 检查视频格式是否支持硬解,不支持使用 mse - const isWebcodecSupport = await VideoDecoder.isConfigSupported({ - codec: getVideoCodec(videoStream.codecpar), - codedWidth: videoStream.codecpar.width, - codedHeight: videoStream.codecpar.height, - description: extradata, - hardwareAcceleration: getHardwarePreference(true) - }) - if (!isWebcodecSupport.supported) { - return true + try { + // 检查视频格式是否支持硬解,不支持使用 mse + const isWebcodecSupport = await VideoDecoder.isConfigSupported({ + codec: getVideoCodec(videoStream.codecpar), + codedWidth: videoStream.codecpar.width, + codedHeight: videoStream.codecpar.height, + description: extradata, + hardwareAcceleration: getHardwarePreference(true) + }) + + if (!isWebcodecSupport.supported) { + return true + } } + catch (e) {} } else if (videoStream.codecpar.width * videoStream.codecpar.height === 1920 * 1080) { // safari 1080p@30fps 无法在 worker 中解码