createDecoder method

  1. @override
Future<PlatformDecoder?> createDecoder(
  1. DecoderConfig config, {
  2. BackendContext? context,
})
override

Implementation

@override
Future<PlatformDecoder?> createDecoder(
  DecoderConfig config, {
  BackendContext? context,
}) async {
  if (!_videoCodecs.contains(config.codec)) return null;
  if (!WebCapability.hasVideoDecoder) return null;
  // Symmetry with createEncoder (and with audio decode): HEVC/AV1 support
  // varies by browser and by hardware, so ask before committing rather than
  // configuring and throwing.
  if (!await WebCapability.isVideoDecoderSupported(
    toWebCodecsString(config.codec, config.backendOptions),
  )) {
    return null;
  }
  // Prefer the worker: the browser decodes off-thread either way, but the
  // bridge to it (chunk in, poll the event loop, frame out) was running on
  // the UI thread. Null means no worker was available — decode in process,
  // exactly as this did before workers existed.
  return await WorkerVideoDecoder.tryCreate(config) ??
      await WebCodecsVideoDecoder.create(config);
}