Skip to main content
Version: v5.9.0

Transcoder Resource Allocation

To initialize transcoder resources, run the resource pool init program, init_rsrc, or resource monitor program, ni_rsrc_mon, before executing any transcoding tasks.

The example programs operates on a single NETINT Quadra Video Processing Unit specified by the command line option -c, which is the same as the card index shown in the ni_rsrc_mon output.

For each decode or encode session, a specific session context must be set up initially:

ni_session_context_t dec_ctx = {0};
ni_session_context_t enc_ctx = {0};
ni_device_session_context_init(&dec_ctx);
ni_device_session_context_init(&enc_ctx);

Also for every opened session, a keep-alive heartbeat beats periodically. This keeps the channel open between the libxcoder and the device firmware. If there is no heartbeat from the libxcoder for a specified period of time, (default is 3 seconds, but is configurable by the libxcoder keepAliveTimeout parameter for both the decoder and encoder configuration), then the device firmware will assume that the application is terminated, and all current sessions will close. For Linux, MacOS and Android platforms, change the name of this thread to KAT+hw_id+session_ id, such as hw_id=0, session_id=0x3ef, thread name is KAT0003ef.

We use the transcoder card index and set it together with the source codec format, (where source is the destination for the encoder), in the session context. This specifies the transcoder to be used for the video coding task. The reservation and allocation of the video resource is automatically handled by the libxcoder at the session opening. This is shown in the following code snippet for the decoder (similar for encoder):

dec_ctx.codec_format = dec_codec_format;
dec_ctx.hw_id = iXcoderGUID;

We use simple transcoder selection in our example. The transcoder GUID (card index) is specified directly. Section 13.3 of the Integration & Programming Guide[1], describes other resource allocation methods such as - least loaded card. This will allow the libxcoder to automatically pick the least loaded card for use when multiple cards are available on the host, to do this simply set hw_id to value -1.

Several attributes of the session context such as the source bit depth (8 or 10 bit), endianness (little or big), must be specified before the session can be formally opened. Here is some sample code for the decoder below:

// default: little endian
dec_ctx.src_bit_depth = bit_depth;
dec_ctx.src_endian = NI_FRAME_LITTLE_ENDIAN;
dec_ctx.bit_depth_factor = 1;
if (10 == dec_ctx.src_bit_depth)
{
dec_ctx.bit_depth_factor = 2;
}
ret = ni_device_session_open(&dec_ctx, NI_DEVICE_TYPE_DECODER);
note

The session context also needs to have the p_session_config attribute set to appropriate values. For the decoder, the values are used for post processing and output format selection, etc. For the encoder, a number of values related to the encoding configuration need to be set. The decoder parameters and encoder parameters are described in detail in section 9.1 and 8.3 of the Integration and Programming Guide[1] respectively.

At this point, we have the decode/encode session open and can start video decoding/encoding operations.