Sequence Frame Source

Defined under the namespace Scandit.Datacapture.Core

SequenceFrameSource
class SequenceFrameSource : FrameSource

Added in version 8.6.0

Emits frames added via addFrame().

Use this class when your application, and not the Scandit Data Capture SDK, owns the camera.

That is the case when the frames come from a framework that runs its own capture session, such as ARKit on iOS or ARCore on Android, or from a camera plugin your application configures itself.

Register an instance of this class as the frame source via DataCaptureContext.frameSource, switch it to On, and then add the frames coming from the camera via addFrame(). The frame source never opens, selects or configures a camera itself — it only forwards the frames you push into it.

Frames reach the Scandit Data Capture SDK only while FrameSource.getCurrentState is On and the frame source is attached to a DataCaptureContext, which is why the state has to be switched explicitly, just as it is for Camera. A frame added before both conditions are true stays in a short internal queue and is emitted as soon as they are. If the queue fills up, the oldest frames are dropped first. Switching the frame source Off again stops processing without discarding that queue.

Only one frame is in flight at a time — the next queued frame is emitted once the DataCaptureContext has finished with the previous one. Pushing frames faster than they can be processed therefore drops frames rather than building up latency.

Note

Register the frame source and switch it on once, outside of your frame loop, and then call addFrame() for each frame. Do not create a frame source per frame, and do not set one on the DataCaptureContext from inside the frame loop. In particular, do not feed a continuous camera stream through ImageFrameSource — it is meant for single images and turns off after each one.

On this platform both mistakes are expensive rather than merely wasteful: setting a frame source re-serializes the whole DataCaptureContext, and ImageFrameSource encodes every image it is given to pass it over the bridge. Measured on a Flutter sample at 720p, the per-frame variant cost 520 ms per frame against 21 ms for the loop below.

create(position, lensPosition)
static create(position: CameraPosition,
        lensPosition?: number): SequenceFrameSource

Added in version 8.6.0

Constructs a new SequenceFrameSource for the given CameraPosition. The lens position (0.0-1.0) sets the capture device lens position on iOS and is ignored on Android.

The capture device position neither selects nor opens a camera. Instead, it tells the Scandit Data Capture SDK how to interpret the frames you push: frames declared as coming from a user-facing camera are treated as mirrored. Pass the position of the camera your application is actually reading from.

desiredState
get desiredState(): FrameSourceState

Added in version 8.6.0

Implemented from FrameSource. See FrameSource.desiredState.

getCurrentState()
getCurrentState(): Promise<FrameSourceState>

Added in version 8.6.0

Implemented from FrameSource. See FrameSource.getCurrentState.

addListener(listener)
addListener(listener: FrameSourceListener): void

Added in version 8.6.0

Implemented from FrameSource. See FrameSource.addListener().

removeListener(listener)
removeListener(listener: FrameSourceListener): void

Added in version 8.6.0

Implemented from FrameSource. See FrameSource.removeListener().

switchToDesiredState(state)
switchToDesiredState(state: FrameSourceState): Promise<void>

Added in version 8.6.0

Convenience method for FrameSource.switchToDesiredState(): it is the same as calling FrameSource.switchToDesiredState() without a completion handler.

addFrame(width, height, frameData)
addFrame(width: number,
        height: number,
        frameData: string): Promise<void>

Added in version 8.6.0

Adds a frame with the given width and height. The frame data must be the Base64 encoding of the raw NV21 bytes of the frame. If this frame source is On and connected to a DataCaptureContext this is the next frame that will be processed.