libxcoder  5.2.0
ni_rsrc_api.cpp File Reference

Public definitions for managing NETINT video processing devices. More...

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "ni_rsrc_api.h"
#include "ni_rsrc_priv.h"
#include "ni_util.h"

Go to the source code of this file.

Functions

void print_device (ni_device_t *p_device)
 
ni_retcode_t ni_rsrc_refresh (int should_match_rev)
 Scan and refresh all resources on the host, taking into account hot-plugged and pulled out cards. More...
 
void ni_rsrc_free_device_context (ni_device_context_t *p_device_context)
 Free previously allocated device context. More...
 
ni_retcode_t ni_rsrc_list_devices (ni_device_type_t device_type, ni_device_info_t *p_device_info, int *p_device_count)
 List device(s) based on device type with full information including s/w instances on the system. More...
 
ni_retcode_t ni_rsrc_list_all_devices (ni_device_t *p_device)
 List all devices with full information including s/w instances on the system. More...
 
ni_retcode_t ni_rsrc_list_all_devices2 (ni_device_t *p_device, bool list_uninitialized)
 Grabs information for every initialized and uninitialized device. More...
 
void ni_rsrc_print_device_info (const ni_device_info_t *p_device_info)
 Print the content of the ni_device_info_t struct. More...
 
void ni_rsrc_print_all_devices_capability (void)
 Print detailed capability information of all devices on the system. More...
 
void ni_rsrc_print_all_devices_capability2 (bool list_uninitialized)
 Prints detailed capability information for all initialized devices and general information about uninitialized devices. More...
 
ni_device_info_tni_rsrc_get_device_info (ni_device_type_t device_type, int guid)
 Query a specific device with detailed information on the system. More...
 
int ni_rsrc_get_device_by_block_name (const char *blk_name, ni_device_type_t device_type)
 Get GUID of the device by block device name and type. More...
 
int ni_rsrc_update_device_load (ni_device_context_t *p_device_context, int load, int sw_instance_cnt, const ni_sw_instance_info_t sw_instance_info[])
 Update the load value and s/w instances info of a specific decoder or encoder. This is used by resource management daemon to update periodically. More...
 
ni_device_context_tni_rsrc_allocate_simple_direct (ni_device_type_t device_type, int guid)
 Allocate resources for decoding/encoding, by designating explicitly the device to use. do not track the load on the host side. More...
 
void ni_rsrc_release_resource (ni_device_context_t *p_device_context, uint64_t load)
 Release resources allocated for decoding/encoding. function This must be called at the end of transcoding with previously assigned load value by allocate* functions. More...
 
int ni_rsrc_check_hw_available (int guid, ni_device_type_t device_type)
 check the NetInt h/w device in resource pool on the host. More...
 
int ni_rsrc_remove_device (const char *dev)
 Remove an NetInt h/w device from resource pool on the host. More...
 
int ni_rsrc_remove_all_devices (void)
 Remove all NetInt h/w devices from resource pool on the host. More...
 
int ni_rsrc_add_device (const char *dev, int should_match_rev)
 Add an NetInt h/w device into resource pool on the host. More...
 
void ni_rsrc_free_device_pool (ni_device_pool_t *p_device_pool)
 Free all resources taken by the device pool. More...
 
int ni_rsrc_lock_and_open (int device_type, ni_lock_handle_t *lock)
 lock a file lock and open a session on a device More...
 
int ni_rsrc_unlock (int device_type, ni_lock_handle_t lock)
 unlock a file lock More...
 
int ni_rsrc_is_fw_compat (uint8_t fw_rev[8])
 check if device FW revision is compatible with SW API More...
 
ni_hw_device_info_quadra_coder_param_tni_create_hw_device_info_quadra_coder_param (int mode)
 Create and alloc a pointer to ni_hw_device_info_quadra_coder_param_t This function is used for ni_check_hw_info() More...
 
void ni_destory_hw_device_info_quadra_coder_param (ni_hw_device_info_quadra_coder_param_t *p_hw_device_info_quadra_coder_param)
 Free resource in p_hw_device_info_quadra_coder_param This function is used for ni_check_hw_info() More...
 
ni_hw_device_info_quadra_tni_hw_device_info_alloc_quadra (int device_type_num, int avaliable_card_num)
 Create a ni_hw_device_info_quadra_t This function is used for ni_check_hw_info() More...
 
void ni_hw_device_info_free_quadra (ni_hw_device_info_quadra_t *p_hw_device_info)
 Free resource in a pointer of ni_hw_device_info_quadra_t This function is used for ni_check_hw_info() More...
 
int ni_check_hw_info (ni_hw_device_info_quadra_t **pointer_to_p_hw_device_info, int task_mode, ni_hw_device_info_quadra_threshold_param_t *hw_info_threshold_param, ni_device_type_t preferential_device_type, ni_hw_device_info_quadra_coder_param_t *coder_param, int hw_mode, int consider_mem)
 check hw info, return the appropriate card number to use depends on the load&task_num&used resource More...
 
ni_device_context_tni_rsrc_allocate_auto (ni_device_type_t device_type, ni_alloc_rule_t rule, ni_codec_t codec, int width, int height, int frame_rate, uint64_t *p_load)
 Allocate resources for decoding/encoding, based on the provided rule. More...
 

Variables

NI_DEPRECATED char ** g_xcoder_refresh_dev_names = NULL
 
NI_DEPRECATED int g_xcoder_refresh_dev_count = 0
 
NI_DEPRECATED bool g_device_in_ctxt = false
 
NI_DEPRECATED ni_device_handle_t g_dev_handle = NI_INVALID_DEVICE_HANDLE
 

Detailed Description

Public definitions for managing NETINT video processing devices.


Definition in file ni_rsrc_api.cpp.

Function Documentation

◆ ni_check_hw_info()

int ni_check_hw_info ( ni_hw_device_info_quadra_t **  pointer_to_p_hw_device_info,
int  task_mode,
ni_hw_device_info_quadra_threshold_param_t hw_info_threshold_param,
ni_device_type_t  preferential_device_type,
ni_hw_device_info_quadra_coder_param_t coder_param,
int  hw_mode,
int  consider_mem 
)

check hw info, return the appropriate card number to use depends on the load&task_num&used resource


Parameters
[out]pointer_to_p_hw_device_info: pointer to user-supplied ni_hw_device_info_quadra_t (allocated by ni_hw_device_info_alloc). May be a ponter to NULL ,in which case a ni_hw_device_info_quadra_coder_param_t is allocated by this function and written to pointer_to_p_hw_device_info. record the device info, including available card num and which card to select, and each card's informaton, such as, the load, task num, device type
[in]task_modeaffect the scheduling strategy, 1 - both the load_num and task_num should consider, usually applied to live scenes 0 - only consider the task_num, don not care the load_num
[in]hw_info_threshold_param: an array of threshold including device type task threshold and load threshold in hw_mode fill the arry with both encoder and decoder threshold or fill the arry with preferential device type threshold when don not in hw_mode load threshold in range[0:100] task num threshold in range [0:32]
[in]preferential_device_type: which device type is preferential 0:decode 1:encode . This need to set to encoder/decoder even if in sw_mode to check whether coder_param is wrong.
[in]coder_param: encoder and decoder information that helps to choose card .This coder_param can be created and set to default value by function hw_device_info_coder_param_t * create_hw_device_info_coder_param(). You may change the resolution fps bit_8_10 or other vaule you want to use
[in]hw_mode:Set1 then this function will choose encoder and decoder in just one card . When no card meets the conditions ,NO card will be choosed. You can try to use set hw_mode 0 to use sw_mode to do encoder/decoder in different card when hw_mode reports an error In hw_mode set both encoder_param and decoder_param in coder_param. Set 0 then just consider sw_mode to choose which card to do encode/decode, In sw_mode set one param in coder_param the other one will be set to NULL.
[in]consider_mem: set 1 this function will consider memory usage extra set 0 this function will not consider memory usage
Returns
0-error 1-success

Definition at line 3401 of file ni_rsrc_api.cpp.

◆ ni_create_hw_device_info_quadra_coder_param()

ni_hw_device_info_quadra_coder_param_t* ni_create_hw_device_info_quadra_coder_param ( int  mode)

Create and alloc a pointer to ni_hw_device_info_quadra_coder_param_t This function is used for ni_check_hw_info()

Create a pointer to hw_device_info_coder_param_t instance .This instance will be created and set to default vaule by param mode.You may change the resolution fps bit_8_10 or other vaule you want to set.


Parameters
[in]mode0 for decoder,1 for encoder,2 for scaler,3 for AI, >= 4 for hw_mode
Returns
a pointer to ni_hw_device_info_quadra_coder_param_t on success,NULL for otherwise

Definition at line 3118 of file ni_rsrc_api.cpp.

◆ ni_destory_hw_device_info_quadra_coder_param()

void ni_destory_hw_device_info_quadra_coder_param ( ni_hw_device_info_quadra_coder_param_t p_hw_device_info_quadra_coder_param)

Free resource in p_hw_device_info_quadra_coder_param This function is used for ni_check_hw_info()

Release a pointer to hw_device_info_coder_param_t instance created by create_hw_device_info_coder_param.


Parameters
[in]device_type_num
[in]avaliable_card_num
Returns
a pointer to ni_hw_device_info_quadra_t on success,NULL for otherwise

Definition at line 3271 of file ni_rsrc_api.cpp.

◆ ni_hw_device_info_alloc_quadra()

ni_hw_device_info_quadra_t* ni_hw_device_info_alloc_quadra ( int  device_type_num,
int  avaliable_card_num 
)

Create a ni_hw_device_info_quadra_t This function is used for ni_check_hw_info()

Create a pointer to ni_hw_device_info_quadra_t instance .


Parameters
[in]device_type_num
[in]avaliable_card_num
Returns
a pointer to ni_hw_device_info_quadra_t on success,NULL for otherwise

Definition at line 3310 of file ni_rsrc_api.cpp.

◆ ni_hw_device_info_free_quadra()

void ni_hw_device_info_free_quadra ( ni_hw_device_info_quadra_t p_hw_device_info)

Free resource in a pointer of ni_hw_device_info_quadra_t This function is used for ni_check_hw_info()

Release a pointer to ni_hw_device_info_quadra_t instance created by create_hw_device_info_coder_param.


Parameters
[in]p_hw_device_infoPoiner to a ni_hw_device_info_quadra_t struct
Returns
None

Definition at line 3381 of file ni_rsrc_api.cpp.

◆ ni_rsrc_add_device()

int ni_rsrc_add_device ( const char *  dev,
int  should_match_rev 
)

Add an NetInt h/w device into resource pool on the host.


Parameters
[in]p_devDevice name represented as C string. ex "/dev/nvme0"
[in]should_match_rev0: transcoder firmware revision matching the library's version is NOT required for placing the transcoder into resource pool; 1: otherwise
Returns
NI_RETCODE_SUCCESS NI_RETCODE_INVALID_PARAM NI_RETCODE_FAILURE

Definition at line 2523 of file ni_rsrc_api.cpp.

◆ ni_rsrc_allocate_auto()

ni_device_context_t* ni_rsrc_allocate_auto ( ni_device_type_t  device_type,
ni_alloc_rule_t  rule,
ni_codec_t  codec,
int  width,
int  height,
int  frame_rate,
uint64_t *  p_load 
)

Allocate resources for decoding/encoding, based on the provided rule.


Parameters
[in]device_typeNI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
[in]ruleallocation rule
[in]codecEN_H264 or EN_H265
[in]widthwidth of video resolution
[in]heightheight of video resolution
[in]frame_ratevideo stream frame rate
[out]p_loadthe p_load that will be generated by this encoding task. Returned only for encoder for now.
Returns
pointer to ni_device_context_t if found, NULL otherwise

Note: codec, width, height, fps need to be supplied for NI_DEVICE_TYPE_ENCODER only, they are ignored otherwize. Note: the returned ni_device_context_t content is not supposed to be used by caller directly: should only be passed to API in the subsequent calls; also after its use, the context should be released by calling ni_rsrc_free_device_context.

retrieve the record and based on the allocation rule specified, find the least loaded or least number of s/w instances among the coders

get the individual device_info info and check the load/num-of-instances

Definition at line 4103 of file ni_rsrc_api.cpp.

◆ ni_rsrc_allocate_simple_direct()

ni_device_context_t* ni_rsrc_allocate_simple_direct ( ni_device_type_t  device_type,
int  guid 
)

Allocate resources for decoding/encoding, by designating explicitly the device to use. do not track the load on the host side.


Parameters
[in]device_typeNI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
[in]guidunique device (decoder or encoder) module id
Returns
pointer to ni_device_context_t if found, NULL otherwise

Note: only need to specify the device type and guid and codec type

Note: the returned ni_device_context_t content is not supposed to be used by caller directly: should only be passed to API in the subsequent calls; also after its use, the context should be released by calling ni_rsrc_free_device_context.

Definition at line 1932 of file ni_rsrc_api.cpp.

◆ ni_rsrc_check_hw_available()

int ni_rsrc_check_hw_available ( int  guid,
ni_device_type_t  device_type 
)

check the NetInt h/w device in resource pool on the host.


Parameters
[in]guidthe global unique device index in resource pool device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
Returns
NI_RETCODE_SUCCESS

Definition at line 2016 of file ni_rsrc_api.cpp.

◆ ni_rsrc_free_device_context()

void ni_rsrc_free_device_context ( ni_device_context_t p_device_context)

Free previously allocated device context.


Parameters
p_device_contextPointer to previously allocated device context
Returns
None

Definition at line 1310 of file ni_rsrc_api.cpp.

◆ ni_rsrc_free_device_pool()

void ni_rsrc_free_device_pool ( ni_device_pool_t p_device_pool)

Free all resources taken by the device pool.


Parameters
[in]p_device_poolPoiner to a device pool struct
Returns
None

Definition at line 2621 of file ni_rsrc_api.cpp.

◆ ni_rsrc_get_device_by_block_name()

int ni_rsrc_get_device_by_block_name ( const char *  blk_name,
ni_device_type_t  device_type 
)

Get GUID of the device by block device name and type.


Parameters
[in]blk_namedevice's block name
[in]typedevice type
Returns
device GUID (>= 0) if found, NI_RETCODE_FAILURE (-1) otherwise

Definition at line 1799 of file ni_rsrc_api.cpp.

◆ ni_rsrc_get_device_info()

ni_device_info_t* ni_rsrc_get_device_info ( ni_device_type_t  device_type,
int  guid 
)

Query a specific device with detailed information on the system.


Parameters
[in]device_typeNI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
[in]guidunique device(decoder or encoder) id
Returns
pointer to ni_device_info_t if found NULL otherwise

Note: Caller is responsible for releasing memory that was allocated for the returned pointer

Definition at line 1748 of file ni_rsrc_api.cpp.

◆ ni_rsrc_is_fw_compat()

int ni_rsrc_is_fw_compat ( uint8_t  fw_rev[8])

check if device FW revision is compatible with SW API


Parameters
fw_rev
Returns
1 for full compatibility, 2 for partial, 0 for none

Definition at line 2784 of file ni_rsrc_api.cpp.

◆ ni_rsrc_list_all_devices()

ni_retcode_t ni_rsrc_list_all_devices ( ni_device_t p_device)

List all devices with full information including s/w instances on the system.


Parameters
[out]p_deviceThe device information returned.
Returns
NI_RETCODE_SUCCESS NI_RETCODE_INVALID_PARAM NI_RETCODE_FAILURE

Note: Caller is responsible for allocating memory for "p_device".

Definition at line 1445 of file ni_rsrc_api.cpp.

◆ ni_rsrc_list_all_devices2()

ni_retcode_t ni_rsrc_list_all_devices2 ( ni_device_t p_device,
bool  list_uninitialized 
)

Grabs information for every initialized and uninitialized device.


Parameters
list_uninitializedFlag to determine if uninitialized devices should be grabbed.
Returns
NI_RETCODE_SUCCESS NI_RETCODE_INVALID_PARAM NI_RETCODE_FAILURE

Note: Caller is responsible for allocating memory for "p_device".

Definition at line 1487 of file ni_rsrc_api.cpp.

◆ ni_rsrc_list_devices()

ni_retcode_t ni_rsrc_list_devices ( ni_device_type_t  device_type,
ni_device_info_t p_device_info,
int *  p_device_count 
)

List device(s) based on device type with full information including s/w instances on the system.


Parameters
[in]device_typeNI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
[out]p_deviceThe device information returned.
[out]p_device_countThe number of ni_device_info_t structs returned.
Returns
NI_RETCODE_SUCCESS NI_RETCODE_FAILURE

Note: Caller is responsible for allocating memory for "p_device".

Definition at line 1340 of file ni_rsrc_api.cpp.

◆ ni_rsrc_lock_and_open()

int ni_rsrc_lock_and_open ( int  device_type,
ni_lock_handle_t *  lock 
)

lock a file lock and open a session on a device


Parameters
device_type
lock
Returns
None

Definition at line 2652 of file ni_rsrc_api.cpp.

◆ ni_rsrc_print_all_devices_capability()

void ni_rsrc_print_all_devices_capability ( void  )

Print detailed capability information of all devices on the system.


Parameters
none
Returns
none

Definition at line 1681 of file ni_rsrc_api.cpp.

◆ ni_rsrc_print_all_devices_capability2()

void ni_rsrc_print_all_devices_capability2 ( bool  list_uninitialized)

Prints detailed capability information for all initialized devices and general information about uninitialized devices.


Parameters
list_uninitializedFlag to determine if uninitialized devices should be grabbed.
Returns
none

Definition at line 1713 of file ni_rsrc_api.cpp.

◆ ni_rsrc_print_device_info()

void ni_rsrc_print_device_info ( const ni_device_info_t p_device_info)

Print the content of the ni_device_info_t struct.


Parameters
p_device_info- pointer to the ni_device_info_t struct to print
Returns
None

Definition at line 1600 of file ni_rsrc_api.cpp.

◆ ni_rsrc_refresh()

ni_retcode_t ni_rsrc_refresh ( int  should_match_rev)

Scan and refresh all resources on the host, taking into account hot-plugged and pulled out cards.


Parameters
[in]should_match_rev0: transcoder firmware revision matching the library's version is NOT required for placing the transcoder into resource pool; 1: otherwise
Returns
NI_RETCODE_SUCCESS on success NI_RETCODE_FAILURE on failure

Definition at line 159 of file ni_rsrc_api.cpp.

◆ ni_rsrc_release_resource()

void ni_rsrc_release_resource ( ni_device_context_t p_device_context,
uint64_t  load 
)

Release resources allocated for decoding/encoding. function This must be called at the end of transcoding with previously assigned load value by allocate* functions.


Parameters
[in/out]p_ctxt the device context
[in]loadthe load value returned by allocate* functions
Returns
None

Definition at line 1953 of file ni_rsrc_api.cpp.

◆ ni_rsrc_remove_all_devices()

int ni_rsrc_remove_all_devices ( void  )

Remove all NetInt h/w devices from resource pool on the host.


Parameters
none
Returns
NI_RETCODE_SUCCESS NI_RETCODE_FAILURE

Definition at line 2407 of file ni_rsrc_api.cpp.

◆ ni_rsrc_remove_device()

int ni_rsrc_remove_device ( const char *  dev)

Remove an NetInt h/w device from resource pool on the host.


Parameters
[in]p_devthe NVMe device name
Returns
NI_RETCODE_SUCCESS NI_RETCODE_FAILURE

Definition at line 2203 of file ni_rsrc_api.cpp.

◆ ni_rsrc_unlock()

int ni_rsrc_unlock ( int  device_type,
ni_lock_handle_t  lock 
)

unlock a file lock


Parameters
device_type
lock
Returns
None

Definition at line 2738 of file ni_rsrc_api.cpp.

◆ ni_rsrc_update_device_load()

int ni_rsrc_update_device_load ( ni_device_context_t p_device_context,
int  load,
int  sw_instance_cnt,
const ni_sw_instance_info_t  sw_instance_info[] 
)

Update the load value and s/w instances info of a specific decoder or encoder. This is used by resource management daemon to update periodically.


Parameters
[in]p_ctxtThe device context returned by ni_rsrc_get_device_context
[in]p_loadThe latest load value to update
[in]sw_instance_cntNumber of s/w instances
[in]sw_instance_infoInfo of s/w instances
Returns
NI_RETCODE_SUCCESS NI_RETCODE_FAILURE

Definition at line 1878 of file ni_rsrc_api.cpp.

◆ print_device()

void print_device ( ni_device_t p_device)

Definition at line 82 of file ni_rsrc_api.cpp.

Variable Documentation

◆ g_dev_handle

NI_DEPRECATED ni_device_handle_t g_dev_handle = NI_INVALID_DEVICE_HANDLE

Definition at line 63 of file ni_rsrc_api.cpp.

◆ g_device_in_ctxt

NI_DEPRECATED bool g_device_in_ctxt = false

Definition at line 62 of file ni_rsrc_api.cpp.

◆ g_xcoder_refresh_dev_count

NI_DEPRECATED int g_xcoder_refresh_dev_count = 0

Definition at line 61 of file ni_rsrc_api.cpp.

◆ g_xcoder_refresh_dev_names

NI_DEPRECATED char** g_xcoder_refresh_dev_names = NULL

Definition at line 60 of file ni_rsrc_api.cpp.