Table of Contents

Class ConfigurationParser

Namespace
VAST.Codecs.H265
Assembly
VAST.Common.dll

Provides parsing functionality for H.265/HEVC configuration data (VPS/SPS/PPS).

public class ConfigurationParser
Inheritance
ConfigurationParser
Inherited Members

Constructors

ConfigurationParser()

Initializes a new instance of the ConfigurationParser class.

public ConfigurationParser()

Properties

AllowParsingErrors

Gets or sets a value indicating whether to allow parsing errors and continue with partial results.

public bool AllowParsingErrors { get; set; }

Property Value

bool

AspectRatio

Gets the sample aspect ratio (SAR) from VUI parameters, or 1:1 if not specified.

public Rational AspectRatio { get; }

Property Value

Rational

FrameRate

Gets the frame rate as a rational number, derived from VPS or VUI timing information.

public Rational FrameRate { get; }

Property Value

Rational

Height

Gets the video height in pixels, calculated from SPS parameters with conformance window cropping applied.

public int Height { get; }

Property Value

int

Level

Gets the H.265 level indicator (general_level_idc) from the VPS.

public int Level { get; }

Property Value

int

MaxBitrate

Gets the maximum bitrate in bits per second based on the H.265 level, or an estimated value if level is unknown.

public int MaxBitrate { get; }

Property Value

int

Profile

Gets the H.265 profile indicator (general_profile_idc) from the VPS.

public int Profile { get; }

Property Value

int

ReorderingQueueDepth

Gets the maximum frame reordering queue depth (vps_max_num_reorder_pics) from VPS parameters.

public int ReorderingQueueDepth { get; }

Property Value

int

Width

Gets the video width in pixels, calculated from SPS parameters with conformance window cropping applied.

public int Width { get; }

Property Value

int

Methods

ConvertCodecPrivateDataToAnnexB(MediaType)

Converts codec private data from HEVCDecoderConfigurationRecord format to Annex B format if not already in Annex B format.

public static void ConvertCodecPrivateDataToAnnexB(MediaType mt)

Parameters

mt MediaType

The media type containing the codec private data to convert.

ConvertCodecPrivateDataToHevc(MediaType)

Converts codec private data from Annex B format to HEVCDecoderConfigurationRecord format if not already in HEVC format.

public static void ConvertCodecPrivateDataToHevc(MediaType mt)

Parameters

mt MediaType

The media type containing the codec private data to convert.

ConvertToAnnexBBitstream(VersatileBuffer, VersatileBuffer, int)

Converts an HEVC bitstream to Annex B format.

public static void ConvertToAnnexBBitstream(VersatileBuffer inputPacket, VersatileBuffer outputPacket, int nalUnitSize)

Parameters

inputPacket VersatileBuffer

The input packet in HEVC format.

outputPacket VersatileBuffer

The output buffer to write the Annex B bitstream to.

nalUnitSize int

The NAL unit length field size in the input bitstream (typically 4).

ConvertToAnnexBBitstream(VersatileBuffer, VersatileBuffer, int, byte[])

Converts input packet in AVC bitstream format to output packet in Annex B bitstream format inserting parameter sets if necessary

public static void ConvertToAnnexBBitstream(VersatileBuffer inputPacket, VersatileBuffer outputPacket, int nalUnitSize, byte[] parameterSets)

Parameters

inputPacket VersatileBuffer

Input packet in AVC bitstream format

outputPacket VersatileBuffer

Output packet in Annex B bitstream format

nalUnitSize int

NAL unit size of the input bitstream

parameterSets byte[]

Parameter sets to insert into output bitstream if not present in input bitstream. Must be in Annex B format!

ConvertToAvcBitstream(byte[], int, int, VersatileBuffer)

Converts an Annex B bitstream to HEVC bitstream format (NAL unit length prefixes).

public static void ConvertToAvcBitstream(byte[] data, int offset, int length, VersatileBuffer outputPacket)

Parameters

data byte[]

The input data in Annex B format.

offset int

The offset within the input data.

length int

The number of bytes to convert.

outputPacket VersatileBuffer

The output buffer to write the HEVC bitstream to.

ConvertToAvcBitstream(VersatileBuffer, int, int, VersatileBuffer)

Converts an Annex B bitstream in a VersatileBuffer to HEVC bitstream format.

public static void ConvertToAvcBitstream(VersatileBuffer inputPacket, int offset, int length, VersatileBuffer outputPacket)

Parameters

inputPacket VersatileBuffer

The input packet in Annex B format.

offset int

The offset within the input packet.

length int

The number of bytes to convert.

outputPacket VersatileBuffer

The output buffer to write the HEVC bitstream to.

FindNextStartCode(byte[], int, int, out int)

Finds next start code in Annex B bitstream within a byte array.

public static int FindNextStartCode(byte[] buffer, int offset, int length, out int startCodeSize)

Parameters

buffer byte[]

Byte array to search.

offset int

Search offset position.

length int

Length of the remaining data size after the offset.

startCodeSize int

Detected start code size (3 or 4 bytes).

Returns

int

If found, the start code position; otherwise, -1.

FindNextStartCode(VersatileBuffer, int, int, out int)

Finds next start code in Annex B bitstream within a VersatileBuffer.

public static int FindNextStartCode(VersatileBuffer buffer, int offset, int length, out int startCodeSize)

Parameters

buffer VersatileBuffer

VersatileBuffer to search.

offset int

Search offset position.

length int

Length of the remaining data size after the offset.

startCodeSize int

Detected start code size (3 or 4 bytes).

Returns

int

If found, the start code position; otherwise, -1.

FindParameterSets(byte[], out byte[], out byte[], out byte[])

Finds and extracts VPS, SPS, and PPS NAL units from codec private data (HEVC or Annex B format).

public static bool FindParameterSets(byte[] buffer, out byte[] vps, out byte[] sps, out byte[] pps)

Parameters

buffer byte[]

The buffer containing the codec private data.

vps byte[]

When this method returns, contains the VPS NAL unit data, or null if not found.

sps byte[]

When this method returns, contains the SPS NAL unit data, or null if not found.

pps byte[]

When this method returns, contains the PPS NAL unit data, or null if not found.

Returns

bool

True if the buffer was parsed successfully; otherwise, false.

FindParameterSets(byte[], int, int, out byte[], out byte[], out byte[])

Finds and extracts VPS, SPS, and PPS NAL units from a portion of codec private data (HEVC or Annex B format).

public static bool FindParameterSets(byte[] buffer, int offset, int length, out byte[] vps, out byte[] sps, out byte[] pps)

Parameters

buffer byte[]

The buffer containing the codec private data.

offset int

The offset within the buffer to start searching.

length int

The number of bytes to search.

vps byte[]

When this method returns, contains the VPS NAL unit data, or null if not found.

sps byte[]

When this method returns, contains the SPS NAL unit data, or null if not found.

pps byte[]

When this method returns, contains the PPS NAL unit data, or null if not found.

Returns

bool

True if the buffer was parsed successfully; otherwise, false.

FindParameterSets(VersatileBuffer, out byte[], out byte[], out byte[])

Finds and extracts VPS, SPS, and PPS NAL units from codec private data in a VersatileBuffer (HEVC or Annex B format).

public static bool FindParameterSets(VersatileBuffer buffer, out byte[] vps, out byte[] sps, out byte[] pps)

Parameters

buffer VersatileBuffer

The buffer containing the codec private data.

vps byte[]

When this method returns, contains the VPS NAL unit data, or null if not found.

sps byte[]

When this method returns, contains the SPS NAL unit data, or null if not found.

pps byte[]

When this method returns, contains the PPS NAL unit data, or null if not found.

Returns

bool

True if the buffer was parsed successfully; otherwise, false.

FindVideoStart(VersatileBuffer, int, int, int, out int)

Finds start of actual video data depending on dropCode parameter.

public static int FindVideoStart(VersatileBuffer buffer, int offset, int length, int dropCode, out int startCodeSize)

Parameters

buffer VersatileBuffer

Frame bitstream

offset int

Offset in the input buffer

length int

Length of the input buffer

dropCode int

Drop code defines which NAL units will be dropped: 0 - AUD, VPS, SPS, PPS and SEI NALs are dropped 1 - AUD, VPS, SPS, and PPS are dropped 2 - only AUD is dropped

startCodeSize int

Start code size of the first video NAL

Returns

int

Position of actual video data

GenerateAnnexBCodecPrivateData(MediaType, byte[])

Generates Annex B format codec private data from an Annex B bitstream.

public static void GenerateAnnexBCodecPrivateData(MediaType mt, byte[] buffer)

Parameters

mt MediaType

The media type to populate with codec private data.

buffer byte[]

The buffer containing the Annex B bitstream with VPS, SPS, and PPS.

GenerateAnnexBCodecPrivateData(MediaType, byte[], byte[], byte[])

Generates Annex B format codec private data from VPS, SPS, and PPS NAL units.

public static void GenerateAnnexBCodecPrivateData(MediaType mt, byte[] vps, byte[] sps, byte[] pps)

Parameters

mt MediaType

The media type to populate with codec private data.

vps byte[]

The VPS NAL unit data (including NAL unit header).

sps byte[]

The SPS NAL unit data (including NAL unit header).

pps byte[]

The PPS NAL unit data (including NAL unit header).

GenerateHevcCodecPrivateData(MediaType, byte[], bool)

Generates HEVCDecoderConfigurationRecord format codec private data from an Annex B bitstream.

public static void GenerateHevcCodecPrivateData(MediaType mt, byte[] buffer, bool allowParsingErrors = false)

Parameters

mt MediaType

The media type to populate with codec private data.

buffer byte[]

The buffer containing the Annex B bitstream with VPS, SPS, and PPS.

allowParsingErrors bool

If true, allows parsing errors when extracting parameter sets.

GenerateHevcCodecPrivateData(MediaType, byte[], byte[], byte[], bool)

Generates HEVCDecoderConfigurationRecord format codec private data from VPS, SPS, and PPS NAL units.

public static void GenerateHevcCodecPrivateData(MediaType mt, byte[] vpsBuffer, byte[] spsBuffer, byte[] ppsBuffer, bool allowParsingErrors = false)

Parameters

mt MediaType

The media type to populate with codec private data.

vpsBuffer byte[]

The VPS NAL unit data (including NAL unit header).

spsBuffer byte[]

The SPS NAL unit data (including NAL unit header).

ppsBuffer byte[]

The PPS NAL unit data (including NAL unit header).

allowParsingErrors bool

If true, allows parsing errors when extracting parameter sets.

GenerateHevcCodecPrivateData(MediaType, byte[], int, int, bool)

Generates HEVCDecoderConfigurationRecord format codec private data from a portion of an Annex B bitstream.

public static void GenerateHevcCodecPrivateData(MediaType mt, byte[] buffer, int offset, int length, bool allowParsingErrors = false)

Parameters

mt MediaType

The media type to populate with codec private data.

buffer byte[]

The buffer containing the Annex B bitstream with VPS, SPS, and PPS.

offset int

The offset within the buffer to start searching.

length int

The number of bytes to search.

allowParsingErrors bool

If true, allows parsing errors when extracting parameter sets.

HaveParameterSets(VersatileBuffer, int, int)

Checks whether an Annex B bitstream contains VPS, SPS, or PPS NAL units.

public static bool HaveParameterSets(VersatileBuffer buffer, int offset, int length)

Parameters

buffer VersatileBuffer

The buffer containing the Annex B bitstream.

offset int

The offset within the buffer to start searching.

length int

The number of bytes to search.

Returns

bool

True if VPS, SPS, or PPS NAL units are found; otherwise, false.

IsIrapPicture(VersatileBuffer, int, int, bool, int)

Determines whether the bitstream contains an IRAP (Intra Random Access Point) picture (BLA, IDR, CRA).

public static bool IsIrapPicture(VersatileBuffer inputBuffer, int inputOffset, int inputBufferSize, bool isAnnexB, int nalUnitLength)

Parameters

inputBuffer VersatileBuffer

The buffer containing the bitstream.

inputOffset int

The offset within the buffer.

inputBufferSize int

The number of bytes to check.

isAnnexB bool

True if the bitstream is in Annex B format; false if in HEVC format.

nalUnitLength int

The NAL unit length field size if in HEVC format.

Returns

bool

True if an IRAP picture is found; otherwise, false.

Parse(byte[])

Parses H.265/HEVC configuration data from a byte buffer.

public int Parse(byte[] buffer)

Parameters

buffer byte[]

The buffer containing the configuration data.

Returns

int

1 on success, -1 on failure.

Parse(byte[], int, int)

Parses H.265/HEVC configuration data from a portion of a byte buffer. Automatically detects the format (Annex B, HEVC decoder configuration record, or single NAL unit).

public int Parse(byte[] buffer, int offset, int length)

Parameters

buffer byte[]

The buffer containing the configuration data.

offset int

The offset within the buffer to start parsing.

length int

The number of bytes to parse.

Returns

int

1 on success, -1 on failure.

ParsePps(byte[], int, int, bool)

Parses a Picture Parameter Set (PPS) NAL unit from the specified buffer.

public ConfigurationParser.Pps_t ParsePps(byte[] inputData, int inputOffset, int inputDataLen, bool allowParsingErrors = false)

Parameters

inputData byte[]

The buffer containing the PPS data (without NAL unit header bytes).

inputOffset int

The offset within the buffer to start parsing.

inputDataLen int

The number of bytes to parse.

allowParsingErrors bool

If true, returns partial results even if parsing errors occur.

Returns

ConfigurationParser.Pps_t

The parsed PPS object, or null if parsing failed and allowParsingErrors is false.

ParseSliceSegmentHeader(byte[], int, int, NalUnitTypes)

Parses a slice segment header from the specified buffer.

public ConfigurationParser.SliceSegmentHeader_t ParseSliceSegmentHeader(byte[] inputData, int inputOffset, int inputDataLen, NalUnitTypes nalUnit)

Parameters

inputData byte[]

The buffer containing the slice segment header data (without NAL unit header bytes).

inputOffset int

The offset within the buffer to start parsing.

inputDataLen int

The number of bytes to parse.

nalUnit NalUnitTypes

The NAL unit type of the slice.

Returns

ConfigurationParser.SliceSegmentHeader_t

The parsed slice segment header object.

ParseSps(byte[], int, int, bool)

Parses a Sequence Parameter Set (SPS) NAL unit from the specified buffer.

public static ConfigurationParser.Sps_t ParseSps(byte[] inputData, int inputOffset, int inputDataLen, bool allowParsingErrors = false)

Parameters

inputData byte[]

The buffer containing the SPS data (without NAL unit header bytes).

inputOffset int

The offset within the buffer to start parsing.

inputDataLen int

The number of bytes to parse.

allowParsingErrors bool

If true, returns partial results even if parsing errors occur.

Returns

ConfigurationParser.Sps_t

The parsed SPS object, or null if parsing failed and allowParsingErrors is false.

ParseVps(byte[], int, int, bool)

Parses a Video Parameter Set (VPS) NAL unit from the specified buffer.

public static ConfigurationParser.Vps_t ParseVps(byte[] inputData, int inputOffset, int inputDataLen, bool allowParsingErrors = false)

Parameters

inputData byte[]

The buffer containing the VPS data (without NAL unit header bytes).

inputOffset int

The offset within the buffer to start parsing.

inputDataLen int

The number of bytes to parse.

allowParsingErrors bool

If true, returns partial results even if parsing errors occur.

Returns

ConfigurationParser.Vps_t

The parsed VPS object, or null if parsing failed and allowParsingErrors is false.

RefineAnnexBBitstream(VersatileBuffer, VersatileBuffer, byte[])

Refines an Annex B bitstream by normalizing start codes to 4 bytes and optionally inserting parameter sets.

public static void RefineAnnexBBitstream(VersatileBuffer inputPacket, VersatileBuffer outputPacket, byte[] parameterSets = null)

Parameters

inputPacket VersatileBuffer

The input packet in Annex B format.

outputPacket VersatileBuffer

The output buffer to write the refined bitstream to.

parameterSets byte[]

Optional parameter sets in Annex B format to insert if not present in the input.

RemoveForbiddenSequenceEmulation(byte[], int, int, ref VersatileBuffer)

Removes emulation prevention bytes (0x03) from RBSP data to restore the original SODB.

public static bool RemoveForbiddenSequenceEmulation(byte[] srcBuf, int srcOffset, int srcLength, ref VersatileBuffer outBuf)

Parameters

srcBuf byte[]

The buffer containing the RBSP data with emulation prevention bytes.

srcOffset int

The offset within the buffer to start processing.

srcLength int

The number of bytes to process.

outBuf VersatileBuffer

The output buffer to write the processed data to (will be created if null).

Returns

bool

True on success.

ToBucketMediaType()

Generates a codec string suitable for MIME type or bucket media type specification (e.g., "hev1.1.6.L93.B0").

public string ToBucketMediaType()

Returns

string

A codec string in the format "hev1.[profile].[compatibility].[tier][level].[constraints]".