async function initializeBackgroundBlur()

in src/providers/BackgroundBlurProvider/index.tsx [107:148]


  async function initializeBackgroundBlur(): Promise<
    BackgroundBlurProcessor | undefined
  > {
    logger.info(
      `Initializing background blur processor with, spec: ${JSON.stringify(
        spec
      )}, options: { blurStrength: ${
        options?.blurStrength
      }, filterCPUUtilization: ${
        options?.filterCPUUtilization
      }, reportingPeriodMillis: ${options?.reportingPeriodMillis} }`
    );

    try {
      const createdProcessor = await BackgroundBlurVideoFrameProcessor.create(
        { ...spec } as BackgroundFilterSpec,
        { ...options } as BackgroundBlurOptions
      );
      // BackgroundBlurVideoFrameProcessor.create will return a NoOpVideoFrameProcessor
      // in the case that BackgroundBlurVideoFrameProcessor.isSupported() returns false.
      // BackgroundBlurVideoFrameProcessor.create() can also throw an error in case loading
      // the assets are not fetched successfully.
      if (createdProcessor instanceof NoOpVideoFrameProcessor) {
        logger.warn('Initialized NoOpVideoFrameProcessor');
        setBackgroundBlurProcessor(undefined);
        setIsBackgroundBlurSupported(false);
        return undefined;
      } else {
        logger.info('Initialized background blur processor');
        setBackgroundBlurProcessor(createdProcessor);
        setIsBackgroundBlurSupported(true);
        return createdProcessor;
      }
    } catch (error) {
      logger.error(
        `Error creating a background blur video frame processor device ${error}`
      );
      setBackgroundBlurProcessor(undefined);
      setIsBackgroundBlurSupported(false);
      return undefined;
    }
  }