Sequence Frame Source
Defined in framework ScanditCaptureCore
- SequenceFrameSource
open class SequenceFrameSource : NSObject, FrameSource
Added in version 6.12.0
Emits frames added via add(_:).
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, or from an
AVCaptureSessionyour 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 add(_:). 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.currentState 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 add(_:) 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.
Note
The only pixel format type supported is kCVPixelFormatType_420YpCbCr8BiPlanarFullRange.
- init()
init()
Added in version 6.12.0
Constructs a new SequenceFrameSource with an unspecified capture device position and a lens position of 1.0. An unspecified position means the frames are never treated as mirrored, so use init(captureDevicePosition:lensPosition:) instead when they come from the front camera.
- init(captureDevicePosition:lensPosition:)
init(captureDevicePosition: AVCaptureDevice.Position, lensPosition: CGFloat)
Added in version 6.12.0
Constructs a new SequenceFrameSource. It requires the position of the capture device (https://developer.apple.com/documentation/avfoundation/avcapturedevice/position-swift.enum) and the lens position (https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624643-lensposition).
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.
- `switch`(toDesiredState:)
open func `switch`(toDesiredState state: FrameSourceState) async ->
BoolAdded in version 6.14.0
Implemented from FrameSource. See FrameSource.`switch`(toDesiredState:completionHandler:).
- `switch`(toDesiredState:)
open func `switch`(toDesiredState state: FrameSourceState) ->
VoidAdded in version 6.12.0
Convenience method for FrameSource.`switch`(toDesiredState:completionHandler:): it is the same as calling FrameSource.`switch`(toDesiredState:completionHandler:) without a completion handler.
- add(_:)
open func add(_ sampleBuffer: CMSampleBuffer) ->
VoidAdded in version 6.12.0
Adds a sample buffer. If this frame source is on and connected to a DataCaptureContext this is the next frame that will be processed. Note that the only pixel format type supported is kCVPixelFormatType_420YpCbCr8BiPlanarFullRange.