Skip to main content
Version: v5.9.0

Functions

The following table describes each of the libxcoder API functions. For more details please see the Appendix Section.

API Description Details​

The following tables describes the API functions from the following files

  • ni_device_api.h
  • ni_av_codec.h
  • ni_util.h

ni_device_api.h Functions​

API Functions in ni_device_api.hDescription
ni_device_session_context_alloc_initAllocate and initialize a new ni_session_context_t struct
ni_device_session_context_initInitialize already allocated session context to a known state
ni_device_session_context_clearClear already allocated session context
ni_device_session_context_freeFree previously allocated session context
ni_create_eventCreate event and return event handle if successful (Windows only)
ni_close_eventClose event and releases resources (Windows only)
ni_device_openOpen device and return device device_handle if successful.It had been deprecated.
ni_device_open2Open device and return device device_handle if successful.
ni_device_closeClose device and release resources
ni_device_capability_queryQuery device and return device capability structure
ni_device_capability_query2Query device and return device capability structure
ni_device_session_openOpen a new device session depending on the device_type parameter
ni_device_session_closeClose device session that was previously opened by calling ni_device_session_open
ni_device_session_flushSend a flush command to the device
ni_device_dec_session_save_hdrsSave a stream's headers in a decoder session that can be used later for continuous decoding from the same source. This usually works with ni_device_dec_session_flush.
ni_device_dec_session_flushFlush a decoder session to get ready to continue decoding. This is different from ni_device_session_flush in that it closes the current decode session and opens a new one for continuous decoding.
ni_device_session_writeSend data to the device
ni_device_session_readRead data from the device
ni_device_session_queryQuery session data from the device
ni_frame_buffer_allocAllocate preliminary memory for the frame buffer for hwdownload or HWframe descriptor storage based on provided parameters. Applicable to YUV420 or nv12 semiplanar pixel format only, 8 or 10 bit/pixel.
ni_frame_buffer_alloc_dlAllocate preliminary memory for the frame buffer for hwdownload or HWframe descriptor storage based on provided parameters. Applicable to all supported pixel formats.
ni_decoder_frame_buffer_allocAllocate memory for decoder frame buffer based on provided parameters; the memory is retrieved from a memory buffer pool and will be returned to the same buffer pool by ni_decoder_frame_buffer_free.
ni_encoder_frame_buffer_allocAllocate memory for the frame buffer for encoder input based on provided parameters taking into account pic line size, extra data, and alignment 2 pass requirements.

Applicable to YUV420 only. Cb/Cr size matches that of Y.
ni_scaler_dest_frame_allocAllocate device destination frame from scaler hwframe pool. Applicable to scale, crop, pad, overlay operations.
ni_scaler_input_frame_allocAllocate device input frame by hw descriptor. This API won’t actually allocate a frame but sends the incoming hardware frame index to the scaler manager.
ni_scaler_frame_pool_allocInit output hardware frames pool for scaler.

Default pool size is 1.
ni_scaler_p2p_frame_acquireGet p2p buffer address of a frame of scaler.
ni_frame_buffer_alloc_nvAllocate memory for the frame buffer for encoder input based on provided parameters taking into account pic line size, extra data, and alignment 2 pass requirements .

Applicable to NV12 only. Cb/Cr size matches that of Y.
ni_encoder_sw_frame_buffer_allocThis API is a wrapper for ni_encoder_frame_buffer_alloc(), used for planar pixel formats, and ni_frame_buffer_alloc_nv(), used for semi-planar pixel formats. This API is meant to combine the functionality for both individual format APIs.
ni_frame_buffer_freeFree frame buffer that was previously allocated with ni_frame_buffer_alloc or
ni_frame_buffer_alloc_nv or
ni_encoder_frame_buffer_alloc or

ni_frame_buffer_alloc_dl
ni_decoder_frame_buffer_freeFree decoder frame buffer that was previously allocated with ni_decoder_frame_buffer_alloc, returning memory to a buffer pool.
ni_decoder_frame_buffer_pool_return_bufReturn a memory buffer to memory buffer pool, for a decoder frame.
ni_packet_buffer_allocAllocate memory for the packet buffer based on provided packet size
ni_custom_packet_buffer_allocAllocate packet buffer using a user provided pointer
ni_packet_buffer_freeFree packet buffer that was previously allocated with ni_packet_buffer_alloc
ni_packet_buffer_free_av1Free packet buffer that was previously allocated with

ni_packet_buffer_alloc for AV1 packets merge
ni_packet_copyCopy video packet accounting for alignment and padding
ni_frame_new_aux_dataAdd a new auxiliary data to a frame for encoding. Auxiliary data is non-video data associated with the frame such as closed captions, HDR metadata, ROI info, etc.
ni_frame_new_aux_data_from_raw_dataAdd a new auxiliary data to a frame and copy in the raw data
ni_frame_get_aux_dataRetrieve from the frame auxiliary data of a given type if exists
ni_frame_free_aux_dataIf auxiliary data of the given type exists in the frame, free it and remove it from the frame.
ni_frame_wipe_aux_dataFree and remove all auxiliary data from the frame.
ni_encoder_init_default_paramsInitialize default encoder parameters
ni_decoder_init_default_paramsInitialize default decoder parameters
ni_encoder_params_set_valueSet value referenced by name in encoder parameters structure
ni_decoder_params_set_valueSet value referenced by name in decoder parameters structure
ni_encoder_gop_params_set_valueSet GOP parameter value referenced by name in encoder parameters structure
ni_device_session_copyCopy source session params into target session
ni_device_session_init_framepoolSend frame pool setup info to device for uploader instance creation
ni_device_session_update_framepoolAdjust uploader instance frame pool
ni_device_session_read_hwdescRead HW descriptor from decoder or 2D engine instance.
ni_device_session_hwdlRead raw YUV data stored on device based on provided HW descriptor
ni_device_session_hwupSend raw YUV to uploader instance and update the HW descriptor structure with new corresponding descriptor information
ni_frame_buffer_alloc_hwencAllocates memory for HW descriptor buffer used for encoder input based on provided parameters
ni_hwframe_buffer_recycleFree the memory buffer used for HW descriptor buffer and send the command to device to recycle the corresponding memory bin it referred to
ni_hwframe_buffer_recycle2Provide same function of ni_hwframe_buffer_recycle, but without device handle parameter
ni_scaler_set_paramsSet parameters on the device for the 2D engine
ni_device_config_frameConfigure a frame on the device for 2D engine to work on based on provided parameters
ni_device_multi_config_frameConfigure multiple frames on the device for 2D engine to work on based on provided parameters
ni_device_alloc_frameAllocate an input or output frame on the device for 2D engine based on provided parameters
ni_device_alloc_dst_frameAllocate a frame on the device and return the frame index with a hw frame surface
ni_device_clone_hwframeCopy the data of src hw frame to dst hw frame
ni_frame_buffer_alloc_pixfmtAllocate memory for the frame buffer to be used for HW upload or 2D engine i/o frames based on provided parameters taking into account pixel format, width, height, format, stride, alignment, and extra data
ni_ai_config_network_binaryConfigure a network context based with the network binary provided
ni_ai_frame_buffer_allocAllocate input layers memory for AI frame buffer based on provided parameters
ni_ai_packet_buffer_allocAllocate output layers memory for the packet buffer based on provided network
ni_reconfig_bitrateReconfigure bitrate dynamically during encoding.
ni_reconfig_intraprdReconfigure intra period dynamically during encoding.

NOTE - the frame upon which intra period is reconfigured is encoded as IDR frame

NOTE - reconfigure intra period is not allowed if intraRefreshMode is enabled or if gopPresetIdx is 1
ni_reconfig_vuiReconfigure VUI parameters dynamically during encoding.
ni_force_idr_frame_typeForce next frame to be IDR frame during encoding.
ni_set_ltrSet a frame's support of Long Term Reference frame during encoding.
ni_set_ltr_intervalSet Long Term Reference interval
ni_set_frame_ref_invalidSet frame reference invalidation
ni_reconfig_framerateReconfigure framerate dynamically during encoding
ni_reconfig_max_frame_sizeReconfigure maxFrameSize_Bytes parameter setting during encoding (for details regarding maxFrameSize_Bytes parameter, please refer to Integration Programming Guide)

NOTE - maxFrameSize_Bytes value less than ((bitrate / 8) / framerate) will be rejected, refer to Integration Programming Guide maxFrameSize_Bytes descriptions for range of supported values
ni_reconfig_crfReconfigure crf value dynamically during encoding (for details regarding crf parameter and its reconfiguration, please refer to Integration Programming Guide section 8.4 “Encoding Parameters” for crf and ReconfDemoMode descriptions)
ni_reconfig_vbv_valueReconfigure vbv buffer size and vbv max rate dynamically during encoding.
ni_reconfig_max_frame_size_ratioReconfigure maxFrameSizeRatio parameter setting during encoding (for details regarding maxFrameSizeRatio parameter, please refer to Integration Programming Guide)
ni_reconfig_slice_argReconfigure sliceArg dynamically during encoding
ni_device_session_acquireAcquire a frame buffer from a P2P hwupload session
ni_uploader_frame_buffer_lockLock a frame from a P2P hwupload session
ni_uploader_frame_buffer_unlockUnlock a frame from a P2P hwupload session
ni_uploader_p2p_test_sendSpecial P2P test API call. Copy YUV data from the software frame to the hardware P2P frame on the Quadra device
ni_encoder_set_input_frame_formatSet the input frame format for the encoder
ni_uploader_set_frame_formatSet the frame format for the hwupload session
ni_hwframe_p2p_buffer_recycleRecycle a frame from the P2P hwupload session
ni_scaler_set_drawbox_paramsSend box paramters to drawbox session
ni_device_session_sequence_changeSend sequence / resolution change information to device

NOTE - this API is only for changing from large to small resolution – changing from small to large resolution requires application to close existing session and open new session with large resolution
ni_query_nvme_statusQuery NVMe and TP load from the device
ni_encoder_session_read_stream_headerA convenience function that may be used to read the initial stream header from the encoder.
ni_get_dma_buf_file_descriptorGet DMA buffer file descriptor from HW frame (P2P only)
ni_device_config_namespace_numConfig Namespace number for different SRIOV
ni_encoder_frame_zerocopy_checkCheck if incoming frame is encoder zero copy compatible or not

Applicable to YUV420 8 or 10 bit with planar or semi-planar pixel format, or RGBA / BGRA / ABGR / ARGB pixel format
ni_encoder_frame_zerocopy_buffer_allocAllocate memory for encoder zero copy (metadata, etc.) based on given parameters, taking into account pic linesize and extra data

Applicable to YUV420 8 or 10 bit with planar or semi-planar pixel format, or RGBA / BGRA / ABGR / ARGB pixel format
ni_uploader_frame_zerocopy_checkCheck if input frame is hwupload zero copy compatible or not. Zero copy can be enabled if the incoming frame meets the following requirements -

Input frame is in YUV420 8 or 10 bit + planar or semi-planar pixel format, or in RGBA / BGRA / ABGR / ARGB pixel format

Input frame resolution > = 1080p

For YUV420 8 / 10-bit with planar / semi-planar pixel formats: Zero copy is applicable only if frame buffer linesize is 128 bytes aligned

For RGBA / BGRA / ABGR / ARGB pixel formats: Zero copy is applicable only if frame buffer linesize is 64 bytes aligned
ni_query_temperatureQuery CompositeTemp from device
ni_query_extra_infoQuery CompositeTemp and power from device
ni_device_alloc_and_get_firmware_logsAllocate log buffer if needed and retrieve firmware logs from device. Also write firmware logs to files if requested.
ni_device_alloc_and_get_firmware_logsSend a p_config command to reconfigure decoding ppu params.

ni_util.h Functions​

API Functions in ni_util.hDescription
ni_get_hw_yuv420p_dimGet dimension information of NETINT HW YUV420p frame to be sent to encoder for encoding.
ni_copy_hw_yuv420pCopy YUV data to NETINT HW YUV420p frame layout to be sent to encoder for encoding.
ni_copy_yuv_444p_to_420pCopy yuv444p data to two pieces of NETINT HW yuv420p frame layout to be sent to encoder for encoding
ni_insert_emulation_prevent_bytesInsert emulation prevention byte(s) as needed into the data buffer
ni_remove_emulation_present_bytesRemove emulation prevention byte(s) as needed from the data buffer
ni_copy_hw_descriptorsCopy HW descriptor structure from source to destination
ni_get_libxcoder_api_verGet libxcoder API version
ni_get_compat_fw_api_verGet FW API version libxcoder is compatible with
ni_get_libxcoder_release_verGet libxcoder SW release version
ni_network_layer_convert_outputHelper function to convert one layer’s output raw data in binary format to data in tensor format.
ni_ai_network_layer_sizeGet one layer’s raw size in byte
ni_ai_network_layer_dimsGet one layer’s number of dimensions
ni_network_layer_convert_tensorHelper function to convert one layer’s input file in tensor format to hardware raw input data in binary format.
ni_network_convert_tensor_to_dataHelper function to convert one layer’s input data in tensor format to hardware raw input data in binary format.
ni_network_convert_data_to_tensorHelper function to convert one layer’s output raw data in binary format to data in tensor format with general buffers
ni_get_rc_txtGet text string for the provided error
ni_param_get_key_valueRetrieve key and value from 'key=value' pair
ni_retrieve_xcoder_paramsRetrieve encoder config parameter values
ni_retrieve_decoder_paramsRetrieve decoder config parameter values
ni_calculate_sha256Calculate the SHA256 value from data
ni_gettimeofdayRetrieve time for logs with microsecond timestamps
ni_gettime_nsRetrieve the system clock time in nanoseconds
ni_usleepSuspend execution for microsecond intervals
ni_posix_memalignAllocate aligned memory
ni_pthread_mutex_initInitialize a mutex which can be recursive.
ni_pthread_mutex_destroyDestroy a mutex.
ni_pthread_mutex_lockThread mutex lock.
ni_pthread_mutex_unlockThread mutex unlock.
ni_pthread_createCreate a new thread.
ni_pthread_joinJoin with a terminated thread.
ni_pthread_cond_initInitialize a condition variable.
ni_pthread_cond_destroyDestroy a condition variable.
ni_pthread_cond_broadcastBroadcast a condition.
ni_pthread_cond_waitWait on a condition.
ni_pthread_cond_signalSignal a condition.
ni_pthread_cond_timedwaitWait on a condition with timeout.
ni_pthread_sigmaskExamine and change mask of blocked signals.

ni_av_codec.h Functions​

API Functions in ni_av_codec.hDescription
ni_should_send_sei_with_frameWhether SEI should be sent together with this frame to encoder
ni_dec_retrieve_aux_dataRetrieve auxiliary data (close caption, various SEI) associated with this frame returned by decoder, convert them to appropriate format and save in the frame's auxiliary data storage for future use by encoding.
ni_enc_prep_aux_dataPrepare auxiliary data to send with this frame to the encoder based on the auxiliary data of the decoded frame.
ni_enc_copy_aux_dataCopy auxiliary data that should be sent together with this frame to encoder
ni_enc_insert_timecodeInsert time code info into picture timing SEI (for H264) or time code SEI (for H265) which is sent together with a frame to encoder
ni_enc_write_from_yuv_bufferSend an input data frame to the encoder with YUV data given in the inputs.
ni_device_session_restartSend a restart command after flush command.

Only support Encoder now.
ni_dec_reconfig_ppu_paramsSend a p_config command to reconfigure decoding ppu params.