Class DataMatrixDecoderBlock
- Namespace
- VisioForge.Core.MediaBlocks.Special
- Assembly
- VisioForge.Core.dll
A specialized media block that detects and decodes DataMatrix 2D barcodes from video frames in real-time. This block analyzes incoming video frames for DataMatrix codes using the LibDMTX library with optimized frame processing, configurable frame skipping, and asynchronous decoding to minimize performance impact on the video pipeline.
Key features:
- Real-time DataMatrix detection and decoding from video streams
- Asynchronous processing with automatic frame dropping if busy
- Configurable frame skip to reduce CPU usage (analyze every Nth frame)
- Support for multiple DataMatrix codes in a single frame
- Event-based notification when DataMatrix codes are detected
- Support for various video formats (RGB, BGR, RGBA, BGRA)
- Configurable decode timeout and symbol size hints
Common use cases:
- Industrial tracking with DataMatrix codes on products
- Document processing with embedded DataMatrix codes
- Inventory management systems
- Quality control and verification systems
- Medical device and pharmaceutical tracking
Technical details:
- Uses LibDMTX for DataMatrix detection and decoding
- Processes frames asynchronously to avoid blocking the pipeline
- Automatically converts video formats to RGB for LibDMTX
- Thread-safe with proper synchronization
- Supports both passthrough and sink modes
Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.
public class DataMatrixDecoderBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternalsInheritance
Implements
Inherited Members
Extension Methods
Constructors
DataMatrixDecoderBlock(bool, VideoFormatX)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Special.DataMatrixDecoderBlock class.
public DataMatrixDecoderBlock(bool passthrough = true, VideoFormatX videoFormat = VideoFormatX.RGBA)Parameters
passthroughbool-
if set to
true, operates in passthrough mode; otherwise acts as a sink. videoFormatVideoFormatX-
The pixel format for frame processing (default: RGBA).
Properties
DecodeTimeoutMs
Gets or sets the timeout in milliseconds for each decode operation. Default is 500ms. Set to -1 for no timeout.
public int DecodeTimeoutMs { get; set; }Property Value
EnableDebugLogging
Gets or sets a value indicating whether to enable debug logging for the decoder.
public bool EnableDebugLogging { get; set; }Property Value
ExpectedSize
Gets or sets the expected DataMatrix size for optimization. Default is SymbolShapeAuto for automatic detection.
public CodeSize ExpectedSize { get; set; }Property Value
FrameSkip
Gets or sets the number of frames to skip between processing. Default is 0 (process every frame). Higher values reduce CPU usage. For example, setting to 2 will process every 3rd frame.
public int FrameSkip { get; set; }Property Value
Input
Gets the primary input pad for receiving video frames to analyze for DataMatrix codes.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets the array of input pads. This block has a single video input.
public override MediaBlockPad[] Inputs { get; }Property Value
MaxCodes
Gets or sets the maximum number of DataMatrix codes to detect per frame. Default is 1. Set to -1 for unlimited.
public int MaxCodes { get; set; }Property Value
Output
Gets the primary output pad that passes through video frames after DataMatrix detection.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets the array of output pads. Contains one pad in passthrough mode, empty in sink mode.
public override MediaBlockPad[] Outputs { get; }Property Value
Passthrough
Gets or sets a value indicating whether the block operates in passthrough mode. When true, video frames are passed through after analysis. When false, the block acts as a sink and consumes the frames.
public bool Passthrough { get; set; }Property Value
Type
Gets the media block type identifier for this DataMatrix decoder block.
public override MediaBlockType Type { get; }Property Value
VideoFormat
Gets or sets the pixel format used for frame capture and processing. Default is RGBA for best compatibility with LibDMTX.
public VideoFormatX VideoFormat { get; set; }Property Value
Methods
Build()
Builds and initializes the DataMatrix decoder block within the media pipeline. Creates the video sample grabber, configures the decoder, and establishes pad connections. This method is called automatically when the pipeline is being constructed.
public override bool Build()Returns
- bool
-
trueif the block was successfully built and configured;falseif initialization failed.
CleanUp()
Performs cleanup of internal resources and elements. Releases the decoder, sample grabber, and resets the build state.
public void CleanUp()Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
GetCore()
Gets the core GStreamer element wrapper for advanced configuration.
public BaseElement GetCore()Returns
- BaseElement
-
The BaseElement instance wrapping the sample grabber element.
GetElement()
Gets the underlying GStreamer element for direct access to native properties.
public Element GetElement()Returns
- Element
-
The native GStreamer sample grabber element.
IsAvailable()
Determines whether the DataMatrix decoder functionality is available in the current environment. This checks if LibDMTX is properly loaded and the video sample grabber is available.
public static bool IsAvailable()Returns
- bool
-
trueif DataMatrix decoding is available; otherwise,false.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the media pipeline context for this block. This internal method establishes the connection to the parent pipeline and provides access to shared resources.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The parent MediaBlocksPipeline that contains this block.
OnDataMatrixDetected
Occurs when one or more DataMatrix codes are detected in a video frame. The event provides decoded text, symbol information, position, and metadata. This event is raised asynchronously as DataMatrix codes are detected in the video stream.
public event EventHandler<DataMatrixDecoderEventArgs> OnDataMatrixDetected