pushFrame method

Future<bool> pushFrame(
  1. Image frame
)

Push a processed frame to the virtual stream

This is called by the compositor after blending person + background. The frame will be output at the target FPS.

Returns false if the stream is not initialized (graceful degradation).

Implementation

Future<bool> pushFrame(ui.Image frame) async {
  if (!_isInitialized) {
    // Graceful return instead of throwing - handles race conditions during shutdown
    debugPrint('VirtualStreamSource: pushFrame called but not initialized');
    return false;
  }

  // Add to buffer
  _frameBuffer.add(frame);

  // Limit buffer size
  while (_frameBuffer.length > _maxBufferSize) {
    _frameBuffer.removeAt(0);
  }

  // Update current frame immediately for preview
  _currentFrame = frame;
  onFrameAvailable?.call(frame);

  return true;
}