Table of Contents

Class ObjectAnalyticsBlock

Namespace
VisioForge.Core.MediaBlocks.AI
Assembly
VisioForge.Core.AI.dll

Turnkey MediaBlock that performs multi-object tracking, tripwire line crossing, and polygon zone occupancy on top of ONNX object detection, drawing overlays and raising analytics events.

public sealed class ObjectAnalyticsBlock : MediaBlock, IMediaBlockInternals, IVideoProcessingBlock, IMediaBlock, IDisposable

Inheritance

MediaBlock

Implements

IMediaBlockInternals
IVideoProcessingBlock
IMediaBlock

Inherited Members

MediaBlock.GetPipelineContext()
MediaBlock.SetPipelineContext(BlockPipelineContext)
MediaBlock.SetPipeline(MediaBlocksPipeline)
MediaBlock.Context
MediaBlock.Name
MediaBlock.IsBuilt
MediaBlock.Owner
MediaBlock.Type
MediaBlock.ID
MediaBlock.Input
MediaBlock.Inputs
MediaBlock.Output
MediaBlock.Outputs
MediaBlock.HasInputs
MediaBlock.HasOutputs
MediaBlock.Build()
MediaBlock.CreateElements()
MediaBlock.AddElementsToPipeline()
MediaBlock.RemoveElementsFromPipeline()
MediaBlock.DeepCopy(string)
MediaBlock.Reset()
MediaBlock.ClearPads()
MediaBlock.Dispose()

Constructors

ObjectAnalyticsBlock(ObjectAnalyticsSettings)

Initializes a new instance of the VisioForge.Core.MediaBlocks.AI.ObjectAnalyticsBlock class.

public ObjectAnalyticsBlock(ObjectAnalyticsSettings settings)

Parameters

settings ObjectAnalyticsSettings

The analytics settings. Must not be null.

Properties

ActiveProvider

Gets the active ONNX execution provider. Valid from the moment the block is built and it stays valid after teardown — which is when a caller normally logs it. (It used to read through the live detector, so it reverted to CPU once that detector was disposed.)

public OnnxExecutionProvider ActiveProvider { get; }

Property Value

OnnxExecutionProvider

Input

Gets the primary input pad for this media block.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets the collection of input pads for this media block.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

LastAnalyticsTimeMs

Gets the filter + tracker + lines + zones + renderer time of the last processed frame, in milliseconds. Zero before the first frame.

public float LastAnalyticsTimeMs { get; }

Property Value

float

LastInferenceTimeMs

Gets the detector preprocessing + ONNX run + decode time of the last processed frame, in milliseconds. Zero before the first frame.

public float LastInferenceTimeMs { get; }

Property Value

float

Output

Gets the primary output pad for this media block.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets the collection of output pads for this media block.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Type

Gets or sets the functional type of this media block (source, sink, effect, encoder, etc.). This property must be overridden in derived classes to specify the block's role in the pipeline.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Exceptions

NotImplementedException

Thrown when the derived class has not implemented this property.

NotImplementedException

Thrown when the derived class has not implemented the setter.

Methods

Build()

Builds and initializes this media block, creating any necessary GStreamer elements and configuring them. This method must be overridden in derived classes to implement block-specific initialization logic.

public override bool Build()

Returns

bool

true if the block was successfully built; otherwise, false.

CleanUp()

Releases the GStreamer elements this MediaBlock created in VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build and returns the block to a re-buildable state. Called automatically during pipeline teardown.

public void CleanUp()

Remarks

A stopped pipeline can be started again on the same instance, in which case VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build runs a second time on this very block. So the contract is:

  • clear the build latch, so VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build does not short-circuit;
  • release everything VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build created, since VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build will create it again;
  • do NOT release anything VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build cannot recreate - state built in the constructor, user configuration, and event subscriptions belong to Dispose(bool).
Releasing constructor-owned state here makes the second run silently produce no data: the null-conditional code in VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build succeeds while owning nothing.

Dispose(bool)

Releases unmanaged and - optionally - managed resources. Override this method in derived classes to implement block-specific cleanup logic.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

An override must call its CleanUp() only under disposing. VisioForge.Core.MediaBlocks.MediaBlock.Finalize reaches this method with false, and a block's CleanUp() releases GstSharp wrappers - which takes GStreamer locks and can block - on the finalizer thread, which must never do either. A block that is never disposed leaves its elements to the pipeline that owns them; that is what their toggle refs are for. base.Dispose(disposing) stays outside the guard, because the latch below has to be set on both paths. The one carve-out is a block holding a resource nothing else can release - a device handle, say, which no pipeline owns and no toggle ref reclaims; such a block may run its CleanUp() on the finalizer path, guarded against throwing, and has to say why at the call site (see AndroidUVCSourceBlock). GitHub issue #958.

GetCore()

Gets the core GStreamer element wrapped by this block.

public BaseElement GetCore()

Returns

BaseElement

The VisioForge.Core.GStreamer.Base.BaseElement wrapper, or null if not built yet.

GetElement()

Gets the GStreamer element instance.

public Element GetElement()

Returns

Element

The Gst.Element, or null if not built yet.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Associates this MediaBlock with a pipeline and initializes its internal context. This method is called automatically when the block is added to a pipeline, providing access to shared resources and pipeline-wide configuration.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The MediaBlocksPipeline instance that will manage this block.

OnAnalyticsUpdated

Raised on every processed inference frame with the tracked objects, line crossings, zone snapshots, and source frame timestamp.

public event EventHandler<ObjectAnalyticsEventArgs> OnAnalyticsUpdated

Event Type

EventHandler<ObjectAnalyticsEventArgs>