processFrame method

Future<Map<String, dynamic>> processFrame({
  1. required Uint8List imageData,
  2. required int width,
  3. required int height,
})

Process a single frame with virtual background applied.

This method takes raw BGRA frame data and returns the processed frame with the virtual background composited in.

Use this for:

  • Dart-level frame processing when native WebRTC integration isn't available
  • Preview rendering with virtual background applied
  • Feeding processed frames to a canvas-based video source

imageData - Raw BGRA pixel data (4 bytes per pixel) width - Frame width in pixels height - Frame height in pixels

Returns a map with:

  • 'success': bool
  • 'processedData': Uint8List (BGRA) if successful
  • 'width': int
  • 'height': int
  • 'error': String if failed

Implementation

Future<Map<String, dynamic>> processFrame({
  required Uint8List imageData,
  required int width,
  required int height,
}) async {
  if (!isSupported) {
    return {'success': false, 'error': 'Platform not supported'};
  }

  if (!_isInitialized) {
    return {'success': false, 'error': 'Not initialized'};
  }

  if (!_isEnabled) {
    return {'success': false, 'error': 'Not enabled'};
  }

  try {
    final result = await _channel.invokeMethod<Map>('processFrame', {
      'imageData': imageData,
      'width': width,
      'height': height,
    });

    if (result == null) {
      return {'success': false, 'error': 'No response from native'};
    }

    return Map<String, dynamic>.from(result);
  } catch (e) {
    return {'success': false, 'error': e.toString()};
  }
}