CameraFrameProcessor<R> class

Runs a FrameHandler on a dedicated background Isolate, keeping heavy per-frame work off the UI isolate.

This is the Flutter analogue of vision-camera running frame processors on a separate native thread. Two properties matter for performance:

  • Drop-latest backpressure — if the worker is still busy when a new frame arrives, only the newest pending frame is kept, so the camera pipeline and UI never stall behind slow processing.
  • Zero-copy hand-off — pixels cross the isolate boundary as TransferableTypedData, so the buffer is copied out of the native frame exactly once (never a second time for the isolate message).

Constructors

CameraFrameProcessor(FrameHandler<R> handler, {WorkerInitializer? workerInit, Object? workerInitArg, BufferReleaser releaseBuffer = nativeBufferReleaser})

Properties

handler → FrameHandler<R>
final
hashCode → int
The hash code for this object.
no setterinherited
isRunning → bool
Whether start has completed and the worker is accepting frames.
no setter
releaseBuffer → BufferReleaser
Returns a frame's native buffer once the handler is done with it (or the frame was dropped). Top-level/static: attachDirect runs it on the worker.
final
results → Stream<R>
Results emitted by the handler, in completion order.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stats → Stream<FrameProcessStats>
Per-frame handler timing, emitted for every processed frame — feed this to a benchmarking HUD ("analyze took N ms").
no setter
workerInit → WorkerInitializer?
Optional worker-isolate bootstrap: workerInit runs once with workerInitArg on the worker before the first frame. Both must satisfy isolate-sendability (workerInit top-level/static).
final
workerInitArg → Object?
final

Methods

attach(Stream<CameraFrame> frames) → StreamSubscription<CameraFrame>
Subscribes to a CameraFrame stream, moving each frame's pixels to the worker with a single copy. Cancel the returned subscription to detach.
attachDirect([FrameSource source = nativeFrameSource]) → void
Has the WORKER subscribe to the frame stream itself — frames go native → worker with no UI-isolate hop (vision-camera's frame processor running on the camera thread, as close as Dart isolates get). Each wake-up processes only the newest frame of a delivered batch, so a slow handler never works through a backlog. Use instead of attach; frame delivery must still be enabled on the controller. results and stats work as before.
dispose() → Future<void>
Kills the worker isolate and closes results. Idempotent.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() → Future<void>
Spawns the worker isolate. Await this before calling submit.
submit(FrameData frame) → void
Submits a frame for processing. If the worker is busy, this frame replaces any previously-pending frame (drop-latest).
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited