libxcoder 5.6.0
Loading...
Searching...
No Matches
test_rsrc_api.c
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (C) 2022 NETINT Technologies
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 *
20 ******************************************************************************/
21
22/*!*****************************************************************************
23 * \file test_rsrc_api.c
24 *
25 * \brief Application for manually managing NETINT video processing devices on
26 * system. Its code provides examples on how to programatically use
27 * ni_rsrc_api.h for NETINT resource management
28 ******************************************************************************/
29
30#ifdef __linux__
31#include <unistd.h>
32#endif
33#include <stdio.h>
34#include <stdlib.h>
35#include <fcntl.h>
36#include <string.h>
37#include <errno.h>
38
39#include "ni_rsrc_api.h"
40#include "ni_rsrc_priv.h"
41#include "ni_util.h"
42
43
44/*******************************************************************************
45 * @brief
46 *
47 * @param
48 *
49 * @return
50 *******************************************************************************/
51static void getStr(const char *prompt, char *str, size_t str_len)
52{
53 char para[64];
54 printf("%s", prompt);
55
56 if (fgets(para, sizeof(para), stdin) != 0) {
57 size_t len = strlen(para);
58 if (len > 0 && para[len - 1] == '\n')
59 para[len - 1] = '\0';
60 ni_strcpy(str, str_len, para);
61 }
62}
63
64/*******************************************************************************
65 * @brief
66 *
67 * @param
68 *
69 * @return
70 *******************************************************************************/
71static int getCmd(const char *prompt)
72{
73 char cmd[64] = {'\0'};
74
75 getStr(prompt, cmd, sizeof(cmd));
76 return (int)cmd[0];
77}
78
79/******************************************************************************
80 * @brief
81 *
82 * @param
83 *
84 * @return
85 ******************************************************************************/
86static void change_log_level(void)
87{
88 char log_str[64];
89 ni_log_level_t log_level;
90
91 getStr("set log level to [none, fatal, error, info, debug, trace]: ",
92 log_str, sizeof(log_str));
93
94 log_level = arg_to_ni_log_level(log_str);
95 if (log_level != NI_LOG_INVALID)
96 {
97 ni_log_set_level(log_level);
98 } else {
99 fprintf(stderr, "ERROR: unknown log level selected: %s", log_str);
100 }
101}
102
103/*******************************************************************************
104 * @brief
105 *
106 * @param
107 *
108 * @return
109 *******************************************************************************/
110static int getInt(const char *prompt)
111{
112 char para[64];
113
114 getStr(prompt, para, sizeof(para));
115 return atoi(para);
116}
117
118/*******************************************************************************
119 * @brief
120 *
121 * @param
122 *
123 * @return
124 *******************************************************************************/
125NI_UNUSED static float getFloat(const char *prompt)
126{
127 char para[64];
128
129 getStr(prompt, para, sizeof(para));
130 return (float)atof(para);
131}
132
133/*******************************************************************************
134 * @brief
135 *
136 * @param
137 *
138 * @return
139 *******************************************************************************/
140NI_UNUSED static long getLong(const char *prompt)
141{
142 char para[64];
143
144 getStr(prompt, para, sizeof(para));
145 return atol(para);
146}
147
148/*******************************************************************************
149 * @brief
150 *
151 * @param
152 *
153 * @return
154 *******************************************************************************/
155static void listOneTypeCoders(void)
156{
157 ni_device_type_t type;
158 int i, count = 0;
160
161 type = (ni_device_type_t)getInt("coder type, decoder (0) encoder (1): ");
162 if (ni_rsrc_list_devices(type, coders, &count) == 0)
163 {
164 for (i = 0; i < count; i++)
165 {
166 ni_rsrc_print_device_info(&coders[i]);
167 }
168 }
169}
170
171/*******************************************************************************
172 * @brief
173 *
174 * @param
175 *
176 * @return
177 *******************************************************************************/
178static void listModuleId(void)
179{
180 /* read back the stored coders numbers */
181 uint32_t i, k;
183 ni_device_pool_t *p_device_pool;
184
185 p_device_pool = ni_rsrc_get_device_pool();
186 if (p_device_pool)
187 {
188#ifdef _WIN32
189 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
190 {
191 fprintf(stderr, "ERROR: listModuleId() failed o obtain mutex: %p", p_device_pool->lock);
192 return;
193 }
194#elif __linux__
195 if (lockf(p_device_pool->lock, F_LOCK, 0))
196 {
197 char errmsg[NI_ERRNO_LEN] = {0};
199 fprintf(stderr, "ERROR: %s() lockf() failed: %s\n", __func__,
200 errmsg);
201 }
202#endif
203
204 /* print out coders in their current order */
205 ptr = p_device_pool->p_device_queue;
206 for (k = 0; k < NI_DEVICE_TYPE_XCODER_MAX; k++)
207 {
208 printf("Num %ss: %u\n", g_device_type_str[k], ptr->xcoder_cnt[k]);
209 for (i = 0; i < ptr->xcoder_cnt[k]; i++)
210 {
211 ni_device_info_t *p_device_info =
212 ni_rsrc_get_device_info(k, ptr->xcoders[k][i]);
213 printf("[%u]. %d (load: %d inst: %u %s.%d)\n", i,
214 ptr->xcoders[k][i], p_device_info->load,
215 p_device_info->active_num_inst, p_device_info->dev_name,
216 p_device_info->hw_id);
217 free(p_device_info);
218 }
219 printf("\n\n");
220 }
221
222#ifdef _WIN32
223 ReleaseMutex(p_device_pool->lock);
224#elif __linux__
225 if (lockf(p_device_pool->lock, F_ULOCK, 0))
226 {
227 fprintf(stderr, "Error lockf() failed\n");
228 }
229#endif
230 ni_rsrc_free_device_pool(p_device_pool);
231 }
232}
233
234/*******************************************************************************
235 * @brief
236 *
237 * @param
238 *
239 * @return
240 *******************************************************************************/
241static void listAllCodersFull(void)
242{
243 int i, k;
244 ni_device_t *p_coders = NULL;
245 p_coders = (ni_device_t *)malloc(sizeof(ni_device_t));
246 if (p_coders == NULL)
247 {
248 fprintf(stderr,
249 "Error: memory allocation failed, fatal error, exiting\n");
250 return;
251 }
252
253 if (ni_rsrc_list_all_devices(p_coders) == 0)
254 {
255 for (k = 0; k < NI_DEVICE_TYPE_XCODER_MAX; k++)
256 {
257 /* print out coders in the order based on their guid */
258 printf("Num %ss: %d\n", g_device_type_str[k],
259 p_coders->xcoder_cnt[k]);
260
261 for (i = 0; i < p_coders->xcoder_cnt[k]; i++)
262 {
263 ni_rsrc_print_device_info(&(p_coders->xcoders[k][i]));
264 }
265 }
266 }
267 free(p_coders);
268}
269
270/*******************************************************************************
271 * @brief
272 *
273 * @param
274 *
275 * @return
276 *******************************************************************************/
277static void getCoderDetailInfo(void)
278{
279 ni_device_type_t type;
280 int guid;
281 ni_device_info_t *p_device_info;
282
283 type = (ni_device_type_t)getInt("coder type, decoder (0) encoder (1): ");
284 guid = getInt("Coder module ID: ");
285 printf("type: %d id %d\n", type, guid);
286 p_device_info = ni_rsrc_get_device_info(type, guid);
287 if (p_device_info)
288 {
289 ni_rsrc_print_device_info(p_device_info);
290 free(p_device_info);
291 }
292}
293
294/*!******************************************************************************
295 * \brief compare two int32_t for qsort
296 *
297 * \param[in] const void *a
298 * \param[in] const void *b
299 *
300 * \return int atoi(numArray)
301 *******************************************************************************/
302static int compareInt32_t(const void *a, const void *b)
303{
304 if (*(int32_t *)a < *(int32_t *)b)
305 {
306 return -1;
307 }
308 else if (*(int32_t *)a > *(int32_t *)b)
309 {
310 return 1;
311 }
312 else
313 {
314 return 0;
315 }
316}
317
318/******************************************************************************
319 * @brief
320 *
321 * @param
322 *
323 * @return
324 ******************************************************************************/
325static void displayRsrcMon(void)
326{
327 ni_device_pool_t *p_device_pool = NULL;
328 ni_device_queue_t *coders = NULL;
329 ni_session_context_t xCtxt = {0};
330 int k;
331
332 p_device_pool = ni_rsrc_get_device_pool();
333 if (!p_device_pool)
334 {
335 fprintf(stderr, "FATAL: cannot get devices info\n");
336 return;
337 }
338
339 printf("**************************************************\n");
341 coders = p_device_pool->p_device_queue;
342
343 for (k = 0; k < NI_DEVICE_TYPE_XCODER_MAX; k++)
344 {
345 ni_device_type_t module_type = k;
346 ni_session_context_t *sessionCtxt = &xCtxt;
347 int i; // used in later FOR-loop when compiled without c99
348 int module_count = 0;
349 char module_name[8] = {'\0'};
350 int32_t *module_id_arr = NULL;
351 ni_device_context_t *p_device_context = NULL;
352
353 if (!IS_XCODER_DEVICE_TYPE(module_type))
354 {
355 fprintf(stderr, "ERROR: unsupported module_type %d\n", module_type);
356 break;
357 }
358
359 module_count = coders->xcoder_cnt[module_type];
360 ni_strcpy(module_name, sizeof(module_name), g_device_type_str[module_type]);
361
362 module_id_arr = malloc(sizeof(*module_id_arr) * module_count);
363 if (!module_id_arr)
364 {
365 fprintf(stderr, "ERROR: malloc() failed for module_id_arr\n");
366 break;
367 }
368 memcpy(module_id_arr, coders->xcoders[module_type],
369 sizeof(int32_t) * module_count);
370
371 printf("Num %ss: %d\n", g_device_type_str[module_type], module_count);
372
373 // sort module IDs used
374 qsort(module_id_arr, module_count, sizeof(int32_t), compareInt32_t);
375
376 // Print performance info headings
377 if (IS_XCODER_DEVICE_TYPE(module_type))
378 {
379 printf("%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n", "INDEX",
380 "LOAD", "MODEL_LOAD", "INST", "MEM", "SHARE_MEM", "P2P_MEM",
381 "DEVICE");
382 }
383
385 for (i = 0; i < module_count; i++)
386 {
387 p_device_context =
388 ni_rsrc_get_device_context(module_type, module_id_arr[i]);
389
391 if (p_device_context)
392 {
393 sessionCtxt->device_handle =
394 ni_device_open2(p_device_context->p_device_info->dev_name,
396 sessionCtxt->blk_io_handle = sessionCtxt->device_handle;
397
398 // Check device can be opened
399 if (NI_INVALID_DEVICE_HANDLE == sessionCtxt->device_handle)
400 {
401 char errmsg[NI_ERRNO_LEN] = {0};
403 fprintf(stderr,
404 "ERROR: ni_device_open2() failed for %s: %s\n",
405 p_device_context->p_device_info->dev_name,
406 errmsg);
407 ni_rsrc_free_device_context(p_device_context);
408 continue;
409 }
410
411 sessionCtxt->hw_id = p_device_context->p_device_info->hw_id;
412 if (NI_RETCODE_SUCCESS !=
413 ni_device_session_query(sessionCtxt, module_type))
414 {
415 ni_device_close(sessionCtxt->device_handle);
416 fprintf(stderr, "Error query %s %s.%d\n", module_name,
417 p_device_context->p_device_info->dev_name,
418 p_device_context->p_device_info->hw_id);
419 ni_rsrc_free_device_context(p_device_context);
420 continue;
421 }
422 // printf("Done query %s %s.%d\n", module_name,
423 // p_device_context->p_device_info->dev_name,
424 // p_device_context->p_device_info->hw_id);
425 ni_device_close(sessionCtxt->device_handle);
426
427 if (0 == sessionCtxt->load_query.total_contexts)
428 {
429 sessionCtxt->load_query.current_load = 0;
430 }
431
432 // Print performance info row
433 if (IS_XCODER_DEVICE_TYPE(module_type))
434 {
435 printf("%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
436 p_device_context->p_device_info->module_id,
437 sessionCtxt->load_query.current_load,
438 sessionCtxt->load_query.fw_model_load,
439 sessionCtxt->load_query.total_contexts,
440 sessionCtxt->load_query.fw_video_mem_usage,
441 sessionCtxt->load_query.fw_share_mem_usage,
442 sessionCtxt->load_query.fw_p2p_mem_usage,
443 p_device_context->p_device_info->dev_name);
444 }
445 ni_rsrc_free_device_context(p_device_context);
446 }
447 }
448 free(module_id_arr);
449 }
450
452 ni_rsrc_free_device_pool(p_device_pool);
453
454 printf("**************************************************\n");
455}
456
457/*******************************************************************************
458 * @brief
459 *
460 * @param
461 *
462 * @return
463 ******************************************************************************/
464static void addCoder(void)
465{
466 char dev[64];
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): ");
470 ni_rsrc_add_device(dev, should_match_rev);
471}
472
473/*******************************************************************************
474 * @brief
475 *
476 * @param
477 *
478 * @return
479 ******************************************************************************/
480static void initRsrc(void)
481{
482 int should_match_rev =
483 getInt("should match current release version, yes (1) no (0): ");
484 int timeout_seconds = getInt("timeout_seconds: ");
485 ni_rsrc_init(should_match_rev, timeout_seconds);
486}
487
488/******************************************************************************
489 * @brief
490 *
491 * @param
492 *
493 * @return
494 ******************************************************************************/
495static void niRsrcRefresh(void)
496{
497 int should_match_rev =
498 getInt("should match current release version, yes (1) no (0): ");
499 ni_rsrc_refresh(should_match_rev);
500}
501
502/******************************************************************************
503 * @brief
504 *
505 * @param
506 *
507 * @return
508 ******************************************************************************/
509static void checkHwAvailable(void)
510{
511 int guid = getInt("guid :");
512 int deviceType=getInt("deviceType : ");
513 ni_rsrc_check_hw_available(guid,deviceType);
514}
515
516
517/******************************************************************************
518 * @brief
519 *
520 * @param
521 *
522 * @return
523 ******************************************************************************/
524static void getlocaldevicelist(void)
525{
527}
528
529/******************************************************************************
530 * @brief
531 *
532 * @param
533 *
534 * @return
535 ******************************************************************************/
536static void deleteCoder(void)
537{
538 char dev[64];
539 getStr("device name (/dev/*): ", dev, sizeof(dev));
541}
542
543/******************************************************************************
544 * @brief
545 *
546 * @param
547 *
548 * @return
549 ******************************************************************************/
550static void removeAllDevices(void)
551{
553}
554
555
556static void checkHWInfo(void)
557{
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);
562#else
563 int ret_scanf = scanf("%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem);
564#endif
565 if(ret_scanf == EOF || ret_scanf < 4)
566 {
567 fprintf(stderr, "%s, read parameters failed", __func__);
568 }
569 ni_hw_device_info_quadra_t *device_info = NULL;
571 threshold[0].device_type = NI_DEVICE_TYPE_DECODER;//0
572 threshold[0].load_threshold = 10;
573 threshold[0].task_num_threshold = 10;
574 threshold[1].device_type = NI_DEVICE_TYPE_ENCODER;//1
575 threshold[1].load_threshold = 20;
576 threshold[1].task_num_threshold = 10;
577 threshold[2].device_type = NI_DEVICE_TYPE_SCALER;//2
578 threshold[2].load_threshold = 30;
579 threshold[2].task_num_threshold = 10;
580 threshold[3].device_type = NI_DEVICE_TYPE_AI;//3
581 threshold[3].load_threshold = 40;
582 threshold[3].task_num_threshold = 10;
583
585 coder_param->encoder_param->w = 7680;
586 coder_param->encoder_param->h = 4320;
587 coder_param->encoder_param->lookaheadDepth = 20;
588 coder_param->decoder_param->w = 7680;
589 coder_param->decoder_param->h = 4320;
590 coder_param->decoder_param->hw_frame = 1;
591 coder_param->scaler_param->h = 7680;
592 coder_param->scaler_param->w = 1920;
593 coder_param->scaler_param->bit_8_10 = 8;
594 int ret = ni_check_hw_info(&device_info,task_mode,threshold,device_type,coder_param,hw_mode,consider_mem);
595 // int ret = ni_check_hw_info(&device_info, 1, threshold, 1, coder_param, 1, 0);
596 printf("ret = %d\n",ret);
599}
600
601/*******************************************************************************
602 * @brief
603 *
604 * @param
605 *
606 * @return
607 *******************************************************************************/
608static void allocAuto(void)
609{
610 ni_device_context_t *p_device_context;
611 ni_device_type_t type;
612 ni_alloc_rule_t rule;
613 uint64_t model_load;
614
615 type = (ni_device_type_t)getInt("coder type, decoder (0) encoder (1): ");
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);
618
619 p_device_context = ni_rsrc_allocate_auto(type, rule, EN_H265, 1920, 1080, 30, &model_load);
620 if (p_device_context)
621 {
622 printf("Successfully auto-allocated s/w instance on:\n");
623 ni_rsrc_print_device_info(p_device_context->p_device_info);
624 printf("Allocated load: %"PRIu64"\n", model_load);
625 ni_rsrc_free_device_context(p_device_context);
626 }
627}
628
629
630int main(void)
631{
632 int stop = 0;
633
634 while (!stop)
635 {
636 printf("Key function\n"
637 "? show this help\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"
643#ifndef _WIN32
644 "i Initialize and create all resources required to work with \n"
645#endif
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"
656 "q quit\n");
657
658 int control = getCmd("> ");
659 switch (control)
660 {
661 case '?':
662 continue;
663#ifndef _WIN32
664 case 'i':
665 initRsrc();
666 break;
667#endif
668 case 'D':
669 removeAllDevices();
670 break;
671 case 'v':
672 change_log_level();
673 break;
674 case 'V':
675 printf("Release ver: %s\n"
676 "API ver: %s\n"
677 "Date: %s\n"
678 "ID: %s\n",
681 break;
682 case 'l':
683 listOneTypeCoders();
684 break;
685 case 'L':
686 listAllCodersFull();
687 break;
688 case 'o':
689 listModuleId();
690 break;
691 case 'g':
692 getCoderDetailInfo();
693 break;
694 case 's':
695 niRsrcRefresh();
696 break;
697 case 'p':
698 getlocaldevicelist();
699 break;
700 case 'x':
701 addCoder();
702 break;
703 case 'd':
704 deleteCoder();
705 break;
706 case 'r':
707 checkHwAvailable();
708 break;
709 case 'm':
710 displayRsrcMon();
711 break;
712 case 'C':
713 checkHWInfo();
714 break;
715 case 'a':
716 allocAuto();
717 break;
718 case 'q':
719 case EOF:
720 stop = 1;
721 break;
722 default:
723 continue;
724 }
725 }
726
727 return 0;
728}
#define NI_MAX_DEVICE_CNT
Definition ni_defs.h:235
#define NI_XCODER_REVISION
Definition ni_defs.h:98
#define LIBXCODER_API_VERSION
Definition ni_defs.h:115
ni_device_type_t
Definition ni_defs.h:356
@ NI_DEVICE_TYPE_SCALER
Definition ni_defs.h:362
@ NI_DEVICE_TYPE_AI
Definition ni_defs.h:363
@ NI_DEVICE_TYPE_DECODER
Definition ni_defs.h:360
@ NI_DEVICE_TYPE_ENCODER
Definition ni_defs.h:361
@ NI_DEVICE_TYPE_XCODER_MAX
Definition ni_defs.h:364
#define NI_ERRNO
Definition ni_defs.h:229
@ NI_RETCODE_SUCCESS
Definition ni_defs.h:443
#define IS_XCODER_DEVICE_TYPE(t)
Definition ni_defs.h:426
#define NI_UNUSED
Definition ni_defs.h:67
#define atof(p_str)
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.
#define atoi(p_str)
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_DEVICE_READ_ONLY
ni_log_level_t arg_to_ni_log_level(const char *arg_str)
Convert terminal arg string to ni_log_level_t.
Definition ni_log.c:262
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition ni_log.c:202
#define NI_ERRNO_LEN
Definition ni_log.h:51
ni_log_level_t
Definition ni_log.h:58
@ NI_LOG_INVALID
Definition ni_log.h:59
#define NI_SW_RELEASE_ID
#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....
@ EN_H265
Definition ni_rsrc_api.h:51
ni_alloc_rule_t
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_strerror(char *dest, size_t dmax, int errnum)
Definition ni_util.c:656
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition ni_util.c:453
Utility definitions.
ni_device_info_t * p_device_info
char dev_name[NI_MAX_DEVICE_NAME_LEN]
uint32_t active_num_inst
ni_device_queue_t * p_device_queue
Definition ni_rsrc_api.h:99
ni_lock_handle_t lock
Definition ni_rsrc_api.h:98
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
Definition ni_rsrc_api.h:70
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
Definition ni_rsrc_api.h:69
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
uint32_t fw_share_mem_usage
uint32_t fw_model_load
uint32_t fw_p2p_mem_usage
uint32_t current_load
uint32_t total_contexts
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
int main(void)