Skip to content

Decoder

ReferenceType edited this page Mar 12, 2025 · 8 revisions

H264Decoder Class

The H264Decoder class provides an H.264 decoder based on Cisco's OpenH264 library. It allows you to decode H.264 video streams into YUV or RGB images.

Table of Contents


Overview

The H264Decoder class wraps the Cisco OpenH264 library to provide efficient H.264 decoding capabilities. It supports various initialization modes, runtime configuration adjustments, and decoding to different output image formats.

Features:

  • Decodes H.264 streams to YUV 420P or RGB images.
  • Supports runtime configuration adjustments (options).
  • Provides multiple decoding methods for different scenarios.
  • Implements IDisposable for proper resource management.

Constructors

Constructor Description
H264Decoder() Creates a new instance using the default Cisco DLL name.
H264Decoder(string ciscoDllPath) Creates a new instance using the specified Cisco DLL path.

Properties

Property Type Description
EnableDebugPrints bool Enables or disables debug prints during initialization.

Methods

Method Return Type Description
Initialize() int Initializes decoder with default parameters.
Initialize(TagSVCDecodingParam param) int Initializes decoder with custom parameters.
GetOption<T>(DECODER_OPTION option, out T value) bool Gets a decoder option.
GetOptionRef<T>(DECODER_OPTION option, ref T value) bool Gets a decoder option, allowing reuse of the value.
SetOption<T>(DECODER_OPTION option, T value) bool Sets a decoder option.
Decode(byte[] encoded, int offset, int count, bool noDelay, out DecodingState state, out YUVImagePointer yuv) bool Decodes encoded data into YUV420Planar (YV12) image.
Decode(EncodedData data, bool noDelay, out DecodingState state, out YUVImagePointer yuv) bool Decodes encoded data into YUV420Planar (YV12) image.
Decode(EncodedData data, bool noDelay, out DecodingState state, ref YuvImage yuv) bool Decodes encoded data into provided YuvImage memory.
Decode(byte[] encoded, int offset, int count, bool noDelay, out DecodingState state, ref YuvImage yuv) bool Decodes encoded data into provided YuvImage memory.
Decode(EncodedData data, bool noDelay, out DecodingState state, ref RgbImage img) bool Decodes encoded data into an RGB image.
Decode(byte[] encoded, int offset, int count, bool noDelay, out DecodingState state, ref RgbImage img) bool Decodes encoded data into an RGB image.
Dispose() void Disposes of the decoder and releases native resources.

Decoding State

Value Name Description Category
0x00 dsErrorFree bit stream error-free Bitstream Parsing
0x01 dsFramePending need more throughput to generate a frame output Bitstream Parsing
0x02 dsRefLost layer lost at reference frame with temporal id 0 Bitstream Parsing
0x04 dsBitstreamError error bitstreams(maybe broken internal frame) the decoder cared Bitstream Parsing
0x08 dsDepLayerLost dependented layer is ever lost Bitstream Parsing
0x10 dsNoParamSets no parameter set NALs involved Bitstream Parsing
0x20 dsDataErrorConcealed current data error concealed specified Bitstream Parsing
0x40 dsRefListNullPtrs picure list contains null ptrs within uiRefCount range Bitstream Parsing
0x1000 dsInvalidArgument invalid argument specified Logic Level
0x2000 dsInitialOptExpected initializing operation is expected Logic Level
0x4000 dsOutOfMemory out of memory due to new request Logic Level
0x8000 dsDstBufNeedExpan actual picture size exceeds size of dst pBuffer feed in decoder, so need expand its size Logic Level

Usage Examples

Creating and Initializing a Decoder

using (var decoder = new H264Decoder())
{
    decoder.Initialize(); // Initialize with default parameters

    byte[] buffer // some encoded data located
    int offset = 0 ;
    int count = 256;
    YUVImagePointer yuvPtr;
    if (decoder.Decode(buffer, offset, count, noDelay: true, out DecodingState state, yuvPtr))
    {
        // Process YUV data
    }  
}

Decoding into RGB Image

using (var decoder = new H264Decoder())
{
    decoder.Initialize();

    byte[] buffer // encoded data located
    int offset = 0 ;
    int count = 256;
    RgbImage rgbImage = new RgbImage(ImageFormat.Rgb, 1280, 720); // Create an RgbImage
    if (decoder.Decode(buffer, offset, count, noDelay: true, out DecodingState state, ref rgbImage))
    {
        // Process RGB image
    }
}
Clone this wiki locally