Concrete IMatSource that drives an injected IFrameGrabber and an optional IFrameOrientationCorrector. Owns _frameMat, a lazy _rotatedBuffer used only for user 90-degree rotation, and a lazy orientation scratch used only when orientation correction needs a swapped-size buffer and the output color format differs from the grabber. When user rotation is off, _rotatedBuffer is released. When the orientation scratch is not required, it is released. Grabber frames from IFrameGrabber.TryGrab are treated as read-only. Implements IMatTransformable only; IMatUpdateFPSControllable is implemented by derived sources such as ImageFileMatSource and by integration-layer mat sources that throttle texture readback. Also implements IMatSourceEvents, IMatSourceTickable, IMatSourceReinitializable, and IMatSourceDerivedFrames for host event subscription, per-tick acquisition, source-swap re-initialization, and derived frame registration.
More...
|
| | MatSourceBase (IFrameGrabber grabber, IFrameOrientationCorrector orientationCorrector=null) |
| | Initializes a new instance of the MatSourceBase class.
|
| |
| PlaybackRestoreMode | CapturePlaybackRestoreMode () |
| | Captures the current playback state as a PlaybackRestoreMode for re-initialization.- Returns
- PlaybackRestoreMode.Playing when playing, PlaybackRestoreMode.Paused when paused, otherwise PlaybackRestoreMode.Ready.
|
| |
| void | Dispose () |
| |
| async ValueTask | DisposeAsync () |
| | Asynchronously releases resources. Required on single-threaded hosts (for example browser/WebAssembly targets); do not use Dispose on those hosts.
|
| |
| Task | InitializeAsync (CancellationToken cancellationToken=default) |
| | Initializes the source asynchronously and leaves playback in MatSourceState.Ready.- Parameters
-
| cancellationToken | A token used to cancel the operation. |
- Returns
- A task that completes when initialization finishes.
|
| |
| Task | InitializeAsync (PlaybackRestoreMode playbackRestoreMode, CancellationToken cancellationToken=default) |
| | Initializes the source asynchronously and restores the requested playback state before IMatSourceEvents.OnInitialized is raised.- Parameters
-
| playbackRestoreMode | Playback state to apply after the grabber is ready. |
| cancellationToken | A token used to cancel the operation. |
- Returns
- A task that completes when initialization finishes.
|
| |
| virtual Task | PauseAsync (CancellationToken cancellationToken=default) |
| |
| virtual Task | PlayAsync (CancellationToken cancellationToken=default) |
| |
| Task | ReinitializeAsync (PlaybackRestoreMode playbackRestoreMode, CancellationToken cancellationToken=default) |
| | Releases the source when initialized, then initializes again with the requested playback restore mode.- Parameters
-
| playbackRestoreMode | Playback state to apply after the grabber is ready. |
| cancellationToken | A token used to cancel the operation. |
- Returns
- A task that completes when re-initialization finishes.
|
| |
| Task | ReleaseAsync (CancellationToken cancellationToken=default) |
| |
| virtual Task | StopAsync (CancellationToken cancellationToken=default) |
| |
| void | SyncDerivedFrameBuffersIfStale (IList< string > pendingLayoutChanges=null) |
| | Re-applies derived frame outputs whose buffers are stale relative to the current source layout or derived settings.
|
| |
| virtual void | Tick (float deltaTime=0f) |
| |
| bool | TryGetMeta (string key, out object value) |
| | Attempts to get a meta property value by key.- Parameters
-
| key | The meta key. |
| value | When this method returns true, the retrieved value; otherwise the default value. |
- Returns
true when the key is supported and a value is available; otherwise false.
|
| |
| bool | TrySetMeta (string key, object value) |
| | Attempts to set a meta property value by key.- Parameters
-
| key | The meta key. |
| value | The value to set. |
- Returns
true when the key is supported and the value was applied; otherwise false.
|
| |
|
| Action< string > | OnDerivedFrameLayoutChanged |
| |
| Action | OnDisposed |
| |
| Action< SourceToMatErrorCode, string > | OnErrorOccurred |
| |
| Action | OnFrameMatLayoutChanged |
| |
| Action | OnFrameMatUpdated |
| |
| Action | OnInitialized |
| |
| Action | OnReleased |
| |
| Action< string > | OnDerivedFrameLayoutChanged |
| | Occurs after initialization when a derived frame output layout (columns, rows, type) changes without removing the derived frame, on the thread that commits the layout change. Not raised on the first derived layout establishment during IMatSource.InitializeAsync. At invocation, the derived frame's FrameMat matches the committed output layout. Layout-affecting settings updates may commit immediately without waiting for the next IMatSourceTickable.Tick.
|
| |
| Action | OnDisposed |
| | Occurs when IDisposable.Dispose or IAsyncDisposable.DisposeAsync completes and the source enters MatSourceState.Destroyed.
|
| |
| Action< SourceToMatErrorCode, string > | OnErrorOccurred |
| | Occurs for expected runtime failures with a SourceToMatErrorCode and message, on the thread that detected the failure.
|
| |
| Action | OnFrameMatLayoutChanged |
| | Occurs after initialization when the output IMatSource.FrameMat layout (cols, rows, type) changes without a full release cycle, on the thread that commits the layout change. Not raised on the first layout establishment during IMatSource.InitializeAsync. When derived frames are registered, their output buffers are synced to the new primary layout before this event is raised.
|
| |
| Action | OnFrameMatUpdated |
| | Occurs at the end of IMatSourceTickable.Tick when IMatSource.DidUpdateThisFrame is true for that tick, after any registered derived frames are evaluated.
|
| |
| Action | OnInitialized |
| | Occurs when an initialization cycle completes and playback state (Ready / Playing / Paused) is determined, on the thread that completes the underlying async operation.
|
| |
| Action | OnReleased |
| | Occurs when IMatSource.ReleaseAsync completes and the source returns to MatSourceState.Uninitialized, on the thread that completes the underlying async operation.
|
| |
Concrete IMatSource that drives an injected IFrameGrabber and an optional IFrameOrientationCorrector. Owns _frameMat, a lazy _rotatedBuffer used only for user 90-degree rotation, and a lazy orientation scratch used only when orientation correction needs a swapped-size buffer and the output color format differs from the grabber. When user rotation is off, _rotatedBuffer is released. When the orientation scratch is not required, it is released. Grabber frames from IFrameGrabber.TryGrab are treated as read-only. Implements IMatTransformable only; IMatUpdateFPSControllable is implemented by derived sources such as ImageFileMatSource and by integration-layer mat sources that throttle texture readback. Also implements IMatSourceEvents, IMatSourceTickable, IMatSourceReinitializable, and IMatSourceDerivedFrames for host event subscription, per-tick acquisition, source-swap re-initialization, and derived frame registration.
Lifecycle events:
-
OnInitialized is raised on the thread that completes the underlying
await continuation (for example after InitializeAsync).
-
OnFrameMatLayoutChanged is raised on the thread that commits the layout change (for example during Tick or initialization).
-
Layout-affecting settings (IMatTransformable.Rotate90Degree, IMatSource.OutputColorFormat) re-establish the output FrameMat layout and raise OnFrameMatLayoutChanged when the source is initialized, without requiring a new grab. When derived frames are registered, stale derived output buffers are synced to the new primary layout before OnFrameMatLayoutChanged is raised so handlers may read derived outputs safely. OnDerivedFrameLayoutChanged follows when a derived output layout changed.
-
OnFrameMatUpdated is raised at the end of Tick when DidUpdateThisFrame is
true for that tick, after any registered derived frames are evaluated. Not raised by layout-only paths such as ReestablishFrameMatLayout outside Tick.
-
OnDerivedFrameLayoutChanged is raised when a registered derived frame's output layout (columns, rows, type) changes after the primary output layout is established during initialization, including immediately after layout-affecting DerivedFrameCollection.AddOrUpdateSettings while this source is initialized (without waiting for the next Tick). The first derived layout commit during initialization is silent, matching OnFrameMatLayoutChanged.
-
OnReleased is raised when ReleaseAsync completes and the source returns to MatSourceState.Uninitialized, including when initialization was in progress before OnInitialized. Does not require a valid FrameMat.
-
OnDisposed is raised on the thread that completes Dispose or DisposeAsync (for example the caller thread for synchronous Dispose, or the continuation thread for DisposeAsync).
-
OnErrorOccurred is raised on the thread that detected the failure.
Async lifecycle handlers may run on a different thread than the caller when internal paths use ConfigureAwait(false). Do not use host main-thread-only APIs in the handler unless you know the completion thread; marshal if needed.
◆ MatSourceBase()
Initializes a new instance of the MatSourceBase class.
- Parameters
-
| grabber | The frame grabber that supplies raw frames. |
| orientationCorrector | Optional orientation corrector applied after IFrameGrabber.TryGrab. When null, frames pass through without orientation correction. |
◆ CapturePlaybackRestoreMode()
| PlaybackRestoreMode OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.CapturePlaybackRestoreMode |
( |
| ) |
|
◆ ClearDidUpdateThisFrame()
| void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.ClearDidUpdateThisFrame |
( |
| ) |
|
|
protected |
◆ Dispose()
| void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.Dispose |
( |
| ) |
|
Single-threaded hosts: This method performs synchronous blocking waits, which can cause deadlocks or hangs on runtimes without a thread pool (for example browser/WebAssembly targets). On such hosts, product teardown must call DisposeAsync; do not use this method. There is no safe way to wait for incomplete async work on a single-threaded host from IDisposable.Dispose.
Cancels in-flight initialization, waits for LifecycleTask (including on timeout), then waits for IFrameGrabber.CloseAsync (including on timeout). Also disposes the grabber when it implements IDisposable so native / device resources are released even if close did not finish.
◆ DisposeAsync()
| async ValueTask OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.DisposeAsync |
( |
| ) |
|
Asynchronously releases resources. Required on single-threaded hosts (for example browser/WebAssembly targets); do not use Dispose on those hosts.
Cancels in-flight initialization, waits for LifecycleTask (including on timeout), then waits for IFrameGrabber.CloseAsync (including on timeout). Also disposes the grabber when it implements IDisposable so native / device resources are released even if close did not finish.
Unlike ReleaseAsync, close is not awaited directly; a poll loop with Task.Yield lets the host SynchronizationContext pump while waiting. Do not use ConfigureAwait(false) on these waits so single-threaded hosts can resume on the captured host SynchronizationContext.
◆ InferGrabberColorFormat()
◆ InitializeAsync() [1/2]
| Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.InitializeAsync |
( |
CancellationToken | cancellationToken = default | ) |
|
◆ InitializeAsync() [2/2]
| Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.InitializeAsync |
( |
PlaybackRestoreMode | playbackRestoreMode, |
|
|
CancellationToken | cancellationToken = default ) |
◆ PauseAsync()
| virtual Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.PauseAsync |
( |
CancellationToken | cancellationToken = default | ) |
|
|
virtual |
◆ PlayAsync()
| virtual Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.PlayAsync |
( |
CancellationToken | cancellationToken = default | ) |
|
|
virtual |
◆ RaiseError()
| void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.RaiseError |
( |
SourceToMatErrorCode | errorCode, |
|
|
string | message ) |
|
protected |
Raises OnErrorOccurred with the specified error code and message.
- Parameters
-
| errorCode | The expected runtime error code. |
| message | A human-readable error message. |
◆ ReinitializeAsync()
| Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.ReinitializeAsync |
( |
PlaybackRestoreMode | playbackRestoreMode, |
|
|
CancellationToken | cancellationToken = default ) |
Releases the source when initialized, then initializes again with the requested playback restore mode.
- Parameters
-
| playbackRestoreMode | Playback state to apply after the grabber is ready. |
| cancellationToken | A token used to cancel the operation. |
- Returns
- A task that completes when re-initialization finishes.
Implements OpenCVForUnity.Extensions.SourceToMat.IMatSourceReinitializable.
◆ ReleaseAsync()
| Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.ReleaseAsync |
( |
CancellationToken | cancellationToken = default | ) |
|
◆ StopAsync()
| virtual Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.StopAsync |
( |
CancellationToken | cancellationToken = default | ) |
|
|
virtual |
◆ StopPlayingCore()
| void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.StopPlayingCore |
( |
| ) |
|
|
protected |
Stops playback without async overhead. Shared by StopAsync and derived Tick handlers.
◆ SyncDerivedFrameBuffersIfStale()
| void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.SyncDerivedFrameBuffersIfStale |
( |
IList< string > | pendingLayoutChanges = null | ) |
|
Re-applies derived frame outputs whose buffers are stale relative to the current source layout or derived settings.
Called automatically after primary layout re-establishment and after layout-affecting DerivedFrameCollection.AddOrUpdateSettings while this source is initialized. Does not depend on Tick or DidUpdateThisFrame, so DerivedFrameSettings.ProcessEveryNFrames skip slots cannot delay layout sync. When pendingLayoutChanges is non-null, changed derived frame names are appended instead of raising OnDerivedFrameLayoutChanged immediately.
- Parameters
-
| pendingLayoutChanges | When non-null, collects derived frame names whose output layout changed instead of raising events. |
◆ SyncGrabberBeforeOpen()
| virtual void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.SyncGrabberBeforeOpen |
( |
| ) |
|
|
protectedvirtual |
◆ Tick()
| virtual void OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.Tick |
( |
float | deltaTime = 0f | ) |
|
|
virtual |
◆ TryGetMeta()
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.TryGetMeta |
( |
string | key, |
|
|
out object | value ) |
Attempts to get a meta property value by key.
- Parameters
-
| key | The meta key. |
| value | When this method returns true, the retrieved value; otherwise the default value. |
- Returns
true when the key is supported and a value is available; otherwise false.
Implements OpenCVForUnity.Extensions.SourceToMat.IMatMetaProperties.
◆ TrySetMeta()
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.TrySetMeta |
( |
string | key, |
|
|
object | value ) |
◆ BaseColorFormat
◆ DerivedFrames
◆ DidUpdateThisFrame
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.DidUpdateThisFrame |
|
get |
◆ FlipHorizontal
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.FlipHorizontal |
|
getset |
◆ FlipVertical
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.FlipVertical |
|
getset |
◆ FrameMat
| Mat OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.FrameMat |
|
get |
◆ Height
| int OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.Height |
|
get |
◆ InitTimeoutMs
| int OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.InitTimeoutMs |
|
getset |
◆ IsInitialized
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.IsInitialized |
|
get |
◆ IsInitializing
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.IsInitializing |
|
get |
◆ IsPaused
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.IsPaused |
|
get |
◆ IsPlaying
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.IsPlaying |
|
get |
◆ LifecycleTask
| Task OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.LifecycleTask |
|
get |
Gets a task that completes when the current lifecycle operation finishes. Queued operations run sequentially; this reflects the tail of that chain.
◆ OutputColorFormat
◆ Rotate90Degree
| bool OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.Rotate90Degree |
|
getset |
◆ State
| MatSourceState OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.State |
|
get |
Gets the current lifecycle state.
◆ Width
| int OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.Width |
|
get |
◆ OnDerivedFrameLayoutChanged
| Action<string> OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnDerivedFrameLayoutChanged |
◆ OnDisposed
| Action OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnDisposed |
◆ OnErrorOccurred
| Action<SourceToMatErrorCode, string> OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnErrorOccurred |
◆ OnFrameMatLayoutChanged
| Action OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnFrameMatLayoutChanged |
◆ OnFrameMatUpdated
| Action OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnFrameMatUpdated |
◆ OnInitialized
| Action OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnInitialized |
◆ OnReleased
| Action OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.OnReleased |
The documentation for this class was generated from the following file:
- OpenCVForUnity/Assets/OpenCVForUnity/Scripts/Extensions/SourceToMat/Core/MatSourceBase.cs