 |
libxcoder
5.4.0
|
Go to the documentation of this file.
51 static 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')
71 static int getCmd(
const char *prompt)
73 char cmd[64] = {
'\0'};
75 getStr(prompt, cmd,
sizeof(cmd));
86 static void change_log_level(
void)
91 getStr(
"set log level to [none, fatal, error, info, debug, trace]: ",
92 log_str,
sizeof(log_str));
99 fprintf(stderr,
"ERROR: unknown log level selected: %s", log_str);
110 static int getInt(
const char *prompt)
114 getStr(prompt, para,
sizeof(para));
125 NI_UNUSED static float getFloat(
const char *prompt)
129 getStr(prompt, para,
sizeof(para));
130 return (
float)
atof(para);
140 NI_UNUSED static long getLong(
const char *prompt)
144 getStr(prompt, para,
sizeof(para));
155 static void listOneTypeCoders(
void)
164 for (i = 0; i < count; i++)
178 static void listModuleId(
void)
189 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
191 fprintf(stderr,
"ERROR: listModuleId() failed o obtain mutex: %p", p_device_pool->
lock);
195 if (lockf(p_device_pool->
lock, F_LOCK, 0))
199 fprintf(stderr,
"ERROR: %s() lockf() failed: %s\n", __func__,
208 printf(
"Num %ss: %u\n", g_device_type_str[k], ptr->
xcoder_cnt[k]);
213 printf(
"[%u]. %d (load: %d inst: %u %s.%d)\n", i,
216 p_device_info->
hw_id);
223 ReleaseMutex(p_device_pool->
lock);
225 if (lockf(p_device_pool->
lock, F_ULOCK, 0))
227 fprintf(stderr,
"Error lockf() failed\n");
241 static void listAllCodersFull(
void)
246 if (p_coders == NULL)
249 "Error: memory allocation failed, fatal error, exiting\n");
258 printf(
"Num %ss: %d\n", g_device_type_str[k],
277 static void getCoderDetailInfo(
void)
284 guid = getInt(
"Coder module ID: ");
285 printf(
"type: %d id %d\n", type, guid);
304 if (*(int32_t *)a < *(int32_t *)b)
308 else if (*(int32_t *)a > *(int32_t *)b)
325 static void displayRsrcMon(
void)
335 fprintf(stderr,
"FATAL: cannot get devices info\n");
339 printf(
"**************************************************\n");
348 int module_count = 0;
349 char module_name[8] = {
'\0'};
350 int32_t *module_id_arr = NULL;
355 fprintf(stderr,
"ERROR: unsupported module_type %d\n", module_type);
359 module_count = coders->
xcoder_cnt[module_type];
360 ni_strcpy(module_name,
sizeof(module_name), g_device_type_str[module_type]);
362 module_id_arr = malloc(
sizeof(*module_id_arr) * module_count);
365 fprintf(stderr,
"ERROR: malloc() failed for module_id_arr\n");
368 memcpy(module_id_arr, coders->
xcoders[module_type],
369 sizeof(int32_t) * module_count);
371 printf(
"Num %ss: %d\n", g_device_type_str[module_type], module_count);
374 qsort(module_id_arr, module_count,
sizeof(int32_t),
compareInt32_t);
379 printf(
"%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
380 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
385 for (i = 0; i < module_count; i++)
391 if (p_device_context)
404 "ERROR: ni_device_open() failed for %s: %s\n",
416 fprintf(stderr,
"Error query %s %s.%d\n", module_name,
435 printf(
"%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
454 printf(
"**************************************************\n");
464 static void addCoder(
void)
467 int should_match_rev = 0;
468 getStr(
"device name (/dev/*): ", dev,
sizeof(dev));
469 should_match_rev = getInt(
"should match current release version, yes (1) no (0): ");
480 static void initRsrc(
void)
482 int should_match_rev =
483 getInt(
"should match current release version, yes (1) no (0): ");
484 int timeout_seconds = getInt(
"timeout_seconds: ");
495 static void niRsrcRefresh(
void)
497 int should_match_rev =
498 getInt(
"should match current release version, yes (1) no (0): ");
509 static void checkHwAvailable(
void)
511 int guid = getInt(
"guid :");
512 int deviceType=getInt(
"deviceType : ");
524 static void getlocaldevicelist(
void)
536 static void deleteCoder(
void)
539 getStr(
"device name (/dev/*): ", dev,
sizeof(dev));
550 static void removeAllDevices(
void)
556 static void checkHWInfo(
void)
558 int task_mode = 0, device_type = 0, hw_mode = 0, consider_mem = 0;
559 printf(
"Please enter task mode, device type, hw mode and if to consider memory (Divided by spaces)\n");
560 #if defined(_MSC_VER)
561 int ret_scanf = scanf_s(
"%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem);
563 int ret_scanf = scanf(
"%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem);
565 if(ret_scanf == EOF || ret_scanf < 4)
567 fprintf(stderr,
"%s, read parameters failed", __func__);
594 int ret =
ni_check_hw_info(&device_info,task_mode,threshold,device_type,coder_param,hw_mode,consider_mem);
596 printf(
"ret = %d\n",ret);
608 static void allocAuto(
void)
616 rule = (
ni_alloc_rule_t)getInt(
"auto-alloc rule, least-load (0) load-instance (1): ");
617 printf(
"type: %d rule %d\n", type, rule);
620 if (p_device_context)
622 printf(
"Successfully auto-allocated s/w instance on:\n");
624 printf(
"Allocated load: %"PRIu64
"\n", model_load);
636 printf(
"Key function\n"
638 "v change libxcoder log level\n"
639 "l list all decoders, or all encoders\n"
640 "L list all coders detailed info\n"
641 "o list all coders' module #, in order of position in queue\n"
642 "g get a coder's info\n"
644 "i Initialize and create all resources required to work with \n"
646 "d delete xcoder from host resource pool\n"
647 "D Remove all NetInt h/w devices from resource pool on the host.\n"
648 "x add xcoder into host resource pool\n"
649 "m display ni_rsrc_mom value\n"
650 "s Scan and refresh all resources on the host, taking into account\n"
651 " hot-plugged and pulled out cards.\n"
652 "r check the NetInt h/w device in resource pool on the host.\n"
653 "p Print detailed capability information of all devices on the system.\n"
654 "C check hardware device detailed info\n"
655 "a allocate automatically a s/w instance\n"
658 int control = getCmd(
"> ");
675 printf(
"Release ver: %s\n"
692 getCoderDetailInfo();
698 getlocaldevicelist();
uint32_t fw_p2p_mem_usage
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_strerror(char *dest, size_t dmax, int errnum)
void ni_rsrc_free_device_pool(ni_device_pool_t *p_device_pool)
Free all resources taken by the device pool.
ni_device_info_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
int ni_rsrc_remove_device(const char *dev)
Remove an NetInt h/w device from resource pool on the host.
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....
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_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 ...
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
ni_device_handle_t ni_device_open(const char *p_dev, uint32_t *p_max_io_size_out)
Open device and return device device_handle if successful.
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Public definitions for managing NETINT video processing devices.
int xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
#define NI_XCODER_REVISION
ni_device_handle_t blk_io_handle
ni_device_queue_t * p_device_queue
ni_device_type_t device_type
uint32_t fw_share_mem_usage
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_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...
char dev_name[NI_MAX_DEVICE_NAME_LEN]
LIB_API ni_device_pool_t * ni_rsrc_get_device_pool(void)
Create and return the allocated ni_device_pool_t struct.
ni_log_level_t arg_to_ni_log_level(const char *arg_str)
Convert terminal arg string to ni_log_level_t.
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
#define IS_XCODER_DEVICE_TYPE(t)
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.
uint32_t fw_video_mem_usage
ni_device_handle_t device_handle
void ni_rsrc_free_device_context(ni_device_context_t *p_device_context)
Free previously allocated device context.
#define NI_SW_RELEASE_TIME
void ni_rsrc_print_device_info(const ni_device_info_t *p_device_info)
Print the content of the ni_device_info_t struct.
int compareInt32_t(const void *a, const void *b)
compare two int32_t for qsort
void ni_rsrc_print_all_devices_capability(void)
Print detailed capability information of all devices on the system.
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
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.
#define NI_MAX_DEVICE_CNT
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
ni_hw_device_info_quadra_scaler_param_t * scaler_param
ni_device_info_t * p_device_info
ni_load_query_t load_query
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_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.
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....
#define LIBXCODER_API_VERSION
@ NI_DEVICE_TYPE_XCODER_MAX
uint32_t max_nvme_io_size
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_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.
ni_hw_device_info_quadra_encoder_param_t * encoder_param
ni_retcode_t ni_device_session_context_init(ni_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
int ni_rsrc_remove_all_devices(void)
Remove all NetInt h/w devices from resource pool on the host.
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()
ni_hw_device_info_quadra_decoder_param_t * decoder_param