51static void getStr(
const char *prompt,
char *str,
size_t str_len)
56 if (fgets(para,
sizeof(para), stdin) != 0) {
57 size_t len = strlen(para);
58 if (len > 0 && para[len - 1] ==
'\n')
71static int getCmd(
const char *prompt)
73 char cmd[64] = {
'\0'};
75 getStr(prompt, cmd,
sizeof(cmd));
86static void change_log_level(
void)
91 getStr(
"set log level to [none, fatal, error, info, debug, trace]: ",
92 log_str,
sizeof(log_str));
99 (void)fprintf(stderr,
"ERROR: unknown log level selected: %s", log_str);
110static int getInt(
const char *prompt)
115 getStr(prompt, para,
sizeof(para));
131NI_UNUSED static float getFloat(
const char *prompt)
136 getStr(prompt, para,
sizeof(para));
142 return (
float)tmp_val;
152NI_UNUSED static long getLong(
const char *prompt)
158 getStr(prompt, para,
sizeof(para));
160 val = strtol(para, &end, 10);
161 if (end == para || *end !=
'\0' || errno == ERANGE)
176static void listOneTypeCoders(
void)
182 int type_val = getInt(
"coder type, decoder (0) encoder (1): ");
191 for (i = 0; i < count; i++)
205static void listModuleId(
void)
216 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
218 (void)fprintf(stderr,
"ERROR: listModuleId() failed o obtain mutex: %p", p_device_pool->
lock);
222 if (lockf(p_device_pool->
lock, F_LOCK, 0))
226 (void)fprintf(stderr,
"ERROR: %s() lockf() failed: %s\n", __func__,
235 printf(
"Num %ss: %u\n", g_device_type_str[k], ptr->
xcoder_cnt[k]);
240 printf(
"[%u]. %d (load: %d inst: %u %s.%d)\n", i,
243 p_device_info->
hw_id);
250 ReleaseMutex(p_device_pool->
lock);
252 if (lockf(p_device_pool->
lock, F_ULOCK, 0))
254 (void)fprintf(stderr,
"Error lockf() failed\n");
268static void listAllCodersFull(
void)
273 if (p_coders == NULL)
275 (void)fprintf(stderr,
276 "Error: memory allocation failed, fatal error, exiting\n");
285 printf(
"Num %ss: %d\n", g_device_type_str[k],
304static void getCoderDetailInfo(
void)
310 int type_val = getInt(
"coder type, decoder (0) encoder (1): ");
317 guid = getInt(
"Coder module ID: ");
318 printf(
"type: %d id %d\n", type, guid);
337 if (*(int32_t *)a < *(int32_t *)b)
341 else if (*(int32_t *)a > *(int32_t *)b)
358static void displayRsrcMon(
void)
368 (void)fprintf(stderr,
"FATAL: cannot get devices info\n");
372 printf(
"**************************************************\n");
381 int module_count = 0;
382 char module_name[8] = {
'\0'};
383 int32_t *module_id_arr = NULL;
388 (void)fprintf(stderr,
"ERROR: unsupported module_type %d\n", module_type);
392 module_count = (int)coders->
xcoder_cnt[module_type];
393 ni_strcpy(module_name,
sizeof(module_name), g_device_type_str[module_type]);
395 module_id_arr = malloc(
sizeof(*module_id_arr) * module_count);
398 (void)fprintf(stderr,
"ERROR: malloc() failed for module_id_arr\n");
401 memcpy(module_id_arr, coders->
xcoders[module_type],
402 sizeof(int32_t) * module_count);
404 printf(
"Num %ss: %d\n", g_device_type_str[module_type], module_count);
407 qsort(module_id_arr, module_count,
sizeof(int32_t), compareInt32_t);
412 printf(
"%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
413 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
418 for (i = 0; i < module_count; i++)
424 if (p_device_context)
436 (void)fprintf(stderr,
437 "ERROR: ni_device_open2() failed for %s: %s\n",
449 (void)fprintf(stderr,
"Error query %s %s.%d\n", module_name,
468 printf(
"%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
487 printf(
"**************************************************\n");
497static void addCoder(
void)
500 int should_match_rev = 0;
501 getStr(
"device name (/dev/*): ", dev,
sizeof(dev));
502 should_match_rev = getInt(
"should match current release version, yes (1) no (0): ");
513static void initRsrc(
void)
515 int should_match_rev =
516 getInt(
"should match current release version, yes (1) no (0): ");
517 int timeout_seconds = getInt(
"timeout_seconds: ");
528static void niRsrcRefresh(
void)
530 int should_match_rev =
531 getInt(
"should match current release version, yes (1) no (0): ");
542static void checkHwAvailable(
void)
544 int guid = getInt(
"guid :");
545 int deviceType=getInt(
"deviceType : ");
557static void getlocaldevicelist(
void)
569static void deleteCoder(
void)
572 getStr(
"device name (/dev/*): ", dev,
sizeof(dev));
583static void removeAllDevices(
void)
589static void checkHWInfo(
void)
591 int task_mode = 0, device_type = 0, hw_mode = 0, consider_mem = 0;
592 printf(
"Please enter task mode, device type, hw mode and if to consider memory (Divided by spaces)\n");
594 int ret_scanf = scanf_s(
"%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem);
596 int ret_scanf = scanf(
"%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem);
598 if(ret_scanf == EOF || ret_scanf < 4)
600 (void)fprintf(stderr,
"%s, read parameters failed", __func__);
627 int ret =
ni_check_hw_info(&device_info,task_mode,threshold,device_type,coder_param,hw_mode,consider_mem);
629 printf(
"ret = %d\n",ret);
641static void allocAuto(
void)
648 int type_val = getInt(
"coder type, decoder (0) encoder (1): ");
649 int rule_val = getInt(
"auto-alloc rule, least-load (0) load-instance (1): ");
650 if (type_val < 0 || rule_val < 0)
657 printf(
"type: %d rule %d\n", type, rule);
660 if (p_device_context)
662 printf(
"Successfully auto-allocated s/w instance on:\n");
664 printf(
"Allocated load: %"PRIu64
"\n", model_load);
676 printf(
"Key function\n"
678 "v change libxcoder log level\n"
679 "l list all decoders, or all encoders\n"
680 "L list all coders detailed info\n"
681 "o list all coders' module #, in order of position in queue\n"
682 "g get a coder's info\n"
684 "i Initialize and create all resources required to work with \n"
686 "d delete xcoder from host resource pool\n"
687 "D Remove all NetInt h/w devices from resource pool on the host.\n"
688 "x add xcoder into host resource pool\n"
689 "m display ni_rsrc_mom value\n"
690 "s Scan and refresh all resources on the host, taking into account\n"
691 " hot-plugged and pulled out cards.\n"
692 "r check the NetInt h/w device in resource pool on the host.\n"
693 "p Print detailed capability information of all devices on the system.\n"
694 "C check hardware device detailed info\n"
695 "a allocate automatically a s/w instance\n"
698 int control = getCmd(
"> ");
715 printf(
"Release ver: %s\n"
732 getCoderDetailInfo();
738 getlocaldevicelist();
#define NI_MAX_DEVICE_CNT
#define NI_XCODER_REVISION
#define LIBXCODER_API_VERSION
@ NI_DEVICE_TYPE_XCODER_MAX
#define IS_XCODER_DEVICE_TYPE(t)
ni_retcode_t ni_device_session_query(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query session data from the device - If device_type is valid, will query session data from specified ...
ni_retcode_t ni_device_session_context_init(ni_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
ni_device_handle_t ni_device_open2(const char *p_dev, ni_device_mode_t mode)
Open device and return device device_handle if successful.
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
ni_log_level_t arg_to_ni_log_level(const char *arg_str)
Convert terminal arg string to ni_log_level_t.
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
#define NI_SW_RELEASE_TIME
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()
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.
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_che...
void ni_rsrc_print_device_info(const ni_device_info_t *p_device_info)
Print the content of the ni_device_info_t struct.
void ni_rsrc_free_device_context(ni_device_context_t *p_device_context)
Free previously allocated device context.
int ni_rsrc_remove_all_devices(void)
Remove all NetInt h/w devices from resource pool on the host.
int ni_rsrc_add_device(const char *dev, int should_match_rev)
Add an NetInt h/w device into resource pool on the host.
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.
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()
void ni_rsrc_free_device_pool(ni_device_pool_t *p_device_pool)
Free all resources taken by the device pool.
int ni_rsrc_remove_device(const char *dev)
Remove an NetInt h/w device from resource pool on the host.
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.
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.
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.
void ni_rsrc_print_all_devices_capability(void)
Print detailed capability information of all devices on the system.
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
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.
Public definitions for managing NETINT video processing devices.
LIB_API ni_device_context_t * ni_rsrc_get_device_context(ni_device_type_t type, int guid)
Allocates and returns a pointer to ni_device_context_t struct based on provided device_type and guid....
LIB_API ni_device_pool_t * ni_rsrc_get_device_pool(void)
Create and return the allocated ni_device_pool_t struct.
LIB_API int ni_rsrc_init(int should_match_rev, int timeout_seconds)
Initialize and create all resources required to work with NETINT NVMe transcoder devices....
int compareInt32_t(const void *a, const void *b)
compare two int32_t for qsort
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
ni_retcode_t ni_strtod_val(const char *str, double *out_val)
Safely convert a decimal string to a double with full validation. Trailing whitespace is tolerated.
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
ni_retcode_t ni_strtoi(const char *str, int32_t *out_val)
Safely convert a decimal string to a 32-bit integer with full validation. Trailing whitespace is tole...
ni_device_info_t * p_device_info
char dev_name[NI_MAX_DEVICE_NAME_LEN]
ni_device_queue_t * p_device_queue
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
ni_device_info_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
int xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
ni_hw_device_info_quadra_encoder_param_t * encoder_param
ni_hw_device_info_quadra_decoder_param_t * decoder_param
ni_hw_device_info_quadra_scaler_param_t * scaler_param
ni_device_type_t device_type
uint32_t fw_share_mem_usage
uint32_t fw_p2p_mem_usage
uint32_t fw_video_mem_usage
ni_device_handle_t device_handle
ni_load_query_t load_query
ni_device_handle_t blk_io_handle