libxcoder 5.8.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 (void)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 int32_t tmp_val;
114
115 getStr(prompt, para, sizeof(para));
116 if (ni_strtoi(para, &tmp_val) != NI_RETCODE_SUCCESS)
117 {
118 ni_log(NI_LOG_ERROR, "%s: invalid integer value '%s'\n", __func__, para);
119 return -1;
120 }
121 return (int)tmp_val;
122}
123
124/*******************************************************************************
125 * @brief
126 *
127 * @param
128 *
129 * @return
130 *******************************************************************************/
131NI_UNUSED static float getFloat(const char *prompt)
132{
133 char para[64];
134 double tmp_val;
135
136 getStr(prompt, para, sizeof(para));
137 if (ni_strtod_val(para, &tmp_val) != NI_RETCODE_SUCCESS)
138 {
139 ni_log(NI_LOG_ERROR, "%s: invalid float value '%s'\n", __func__, para);
140 return -1.0f;
141 }
142 return (float)tmp_val;
143}
144
145/*******************************************************************************
146 * @brief
147 *
148 * @param
149 *
150 * @return
151 *******************************************************************************/
152NI_UNUSED static long getLong(const char *prompt)
153{
154 char para[64];
155 char *end;
156 long val;
157
158 getStr(prompt, para, sizeof(para));
159 errno = 0;
160 val = strtol(para, &end, 10);
161 if (end == para || *end != '\0' || errno == ERANGE)
162 {
163 ni_log(NI_LOG_ERROR, "%s: invalid long value '%s'\n", __func__, para);
164 return -1;
165 }
166 return val;
167}
168
169/*******************************************************************************
170 * @brief
171 *
172 * @param
173 *
174 * @return
175 *******************************************************************************/
176static void listOneTypeCoders(void)
177{
178 ni_device_type_t type;
179 int i, count = 0;
181
182 int type_val = getInt("coder type, decoder (0) encoder (1): ");
183 if (type_val < 0)
184 {
185 ni_log(NI_LOG_ERROR, "ERROR: invalid input for type\n");
186 return;
187 }
188 type = (ni_device_type_t)type_val;
189 if (ni_rsrc_list_devices(type, coders, &count) == 0)
190 {
191 for (i = 0; i < count; i++)
192 {
193 ni_rsrc_print_device_info(&coders[i]);
194 }
195 }
196}
197
198/*******************************************************************************
199 * @brief
200 *
201 * @param
202 *
203 * @return
204 *******************************************************************************/
205static void listModuleId(void)
206{
207 /* read back the stored coders numbers */
208 uint32_t i, k;
210 ni_device_pool_t *p_device_pool;
211
212 p_device_pool = ni_rsrc_get_device_pool();
213 if (p_device_pool)
214 {
215#ifdef _WIN32
216 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
217 {
218 (void)fprintf(stderr, "ERROR: listModuleId() failed o obtain mutex: %p", p_device_pool->lock);
219 return;
220 }
221#elif __linux__
222 if (lockf(p_device_pool->lock, F_LOCK, 0))
223 {
224 char errmsg[NI_ERRNO_LEN] = {0};
226 (void)fprintf(stderr, "ERROR: %s() lockf() failed: %s\n", __func__,
227 errmsg);
228 }
229#endif
230
231 /* print out coders in their current order */
232 ptr = p_device_pool->p_device_queue;
233 for (k = 0; k < NI_DEVICE_TYPE_XCODER_MAX; k++)
234 {
235 printf("Num %ss: %u\n", g_device_type_str[k], ptr->xcoder_cnt[k]);
236 for (i = 0; i < ptr->xcoder_cnt[k]; i++)
237 {
238 ni_device_info_t *p_device_info =
239 ni_rsrc_get_device_info(k, ptr->xcoders[k][i]);
240 printf("[%u]. %d (load: %d inst: %u %s.%d)\n", i,
241 ptr->xcoders[k][i], p_device_info->load,
242 p_device_info->active_num_inst, p_device_info->dev_name,
243 p_device_info->hw_id);
244 free(p_device_info);
245 }
246 printf("\n\n");
247 }
248
249#ifdef _WIN32
250 ReleaseMutex(p_device_pool->lock);
251#elif __linux__
252 if (lockf(p_device_pool->lock, F_ULOCK, 0))
253 {
254 (void)fprintf(stderr, "Error lockf() failed\n");
255 }
256#endif
257 ni_rsrc_free_device_pool(p_device_pool);
258 }
259}
260
261/*******************************************************************************
262 * @brief
263 *
264 * @param
265 *
266 * @return
267 *******************************************************************************/
268static void listAllCodersFull(void)
269{
270 int i, k;
271 ni_device_t *p_coders = NULL;
272 p_coders = (ni_device_t *)malloc(sizeof(ni_device_t));
273 if (p_coders == NULL)
274 {
275 (void)fprintf(stderr,
276 "Error: memory allocation failed, fatal error, exiting\n");
277 return;
278 }
279
280 if (ni_rsrc_list_all_devices(p_coders) == 0)
281 {
282 for (k = 0; k < NI_DEVICE_TYPE_XCODER_MAX; k++)
283 {
284 /* print out coders in the order based on their guid */
285 printf("Num %ss: %d\n", g_device_type_str[k],
286 p_coders->xcoder_cnt[k]);
287
288 for (i = 0; i < p_coders->xcoder_cnt[k]; i++)
289 {
290 ni_rsrc_print_device_info(&(p_coders->xcoders[k][i]));
291 }
292 }
293 }
294 free(p_coders);
295}
296
297/*******************************************************************************
298 * @brief
299 *
300 * @param
301 *
302 * @return
303 *******************************************************************************/
304static void getCoderDetailInfo(void)
305{
306 ni_device_type_t type;
307 int guid;
308 ni_device_info_t *p_device_info;
309
310 int type_val = getInt("coder type, decoder (0) encoder (1): ");
311 if (type_val < 0)
312 {
313 ni_log(NI_LOG_ERROR, "ERROR: invalid input for type\n");
314 return;
315 }
316 type = (ni_device_type_t)type_val;
317 guid = getInt("Coder module ID: ");
318 printf("type: %d id %d\n", type, guid);
319 p_device_info = ni_rsrc_get_device_info(type, guid);
320 if (p_device_info)
321 {
322 ni_rsrc_print_device_info(p_device_info);
323 free(p_device_info);
324 }
325}
326
327/*!******************************************************************************
328 * \brief compare two int32_t for qsort
329 *
330 * \param[in] const void *a
331 * \param[in] const void *b
332 *
333 * \return int atoi(numArray)
334 *******************************************************************************/
335static int compareInt32_t(const void *a, const void *b)
336{
337 if (*(int32_t *)a < *(int32_t *)b)
338 {
339 return -1;
340 }
341 else if (*(int32_t *)a > *(int32_t *)b)
342 {
343 return 1;
344 }
345 else
346 {
347 return 0;
348 }
349}
350
351/******************************************************************************
352 * @brief
353 *
354 * @param
355 *
356 * @return
357 ******************************************************************************/
358static void displayRsrcMon(void)
359{
360 ni_device_pool_t *p_device_pool = NULL;
361 ni_device_queue_t *coders = NULL;
362 ni_session_context_t xCtxt = {0};
363 int k;
364
365 p_device_pool = ni_rsrc_get_device_pool();
366 if (!p_device_pool)
367 {
368 (void)fprintf(stderr, "FATAL: cannot get devices info\n");
369 return;
370 }
371
372 printf("**************************************************\n");
374 coders = p_device_pool->p_device_queue;
375
376 for (k = 0; k < NI_DEVICE_TYPE_XCODER_MAX; k++)
377 {
378 ni_device_type_t module_type = k;
379 ni_session_context_t *sessionCtxt = &xCtxt;
380 int i; // used in later FOR-loop when compiled without c99
381 int module_count = 0;
382 char module_name[8] = {'\0'};
383 int32_t *module_id_arr = NULL;
384 ni_device_context_t *p_device_context = NULL;
385
386 if (!IS_XCODER_DEVICE_TYPE(module_type))
387 {
388 (void)fprintf(stderr, "ERROR: unsupported module_type %d\n", module_type);
389 break;
390 }
391
392 module_count = (int)coders->xcoder_cnt[module_type];
393 ni_strcpy(module_name, sizeof(module_name), g_device_type_str[module_type]);
394
395 module_id_arr = malloc(sizeof(*module_id_arr) * module_count);
396 if (!module_id_arr)
397 {
398 (void)fprintf(stderr, "ERROR: malloc() failed for module_id_arr\n");
399 break;
400 }
401 memcpy(module_id_arr, coders->xcoders[module_type],
402 sizeof(int32_t) * module_count);
403
404 printf("Num %ss: %d\n", g_device_type_str[module_type], module_count);
405
406 // sort module IDs used
407 qsort(module_id_arr, module_count, sizeof(int32_t), compareInt32_t);
408
409 // Print performance info headings
410 if (IS_XCODER_DEVICE_TYPE(module_type))
411 {
412 printf("%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n", "INDEX",
413 "LOAD", "MODEL_LOAD", "INST", "MEM", "SHARE_MEM", "P2P_MEM",
414 "DEVICE");
415 }
416
418 for (i = 0; i < module_count; i++)
419 {
420 p_device_context =
421 ni_rsrc_get_device_context(module_type, module_id_arr[i]);
422
424 if (p_device_context)
425 {
426 sessionCtxt->device_handle =
427 ni_device_open2(p_device_context->p_device_info->dev_name,
429 sessionCtxt->blk_io_handle = sessionCtxt->device_handle;
430
431 // Check device can be opened
432 if (NI_INVALID_DEVICE_HANDLE == sessionCtxt->device_handle)
433 {
434 char errmsg[NI_ERRNO_LEN] = {0};
436 (void)fprintf(stderr,
437 "ERROR: ni_device_open2() failed for %s: %s\n",
438 p_device_context->p_device_info->dev_name,
439 errmsg);
440 ni_rsrc_free_device_context(p_device_context);
441 continue;
442 }
443
444 sessionCtxt->hw_id = p_device_context->p_device_info->hw_id;
445 if (NI_RETCODE_SUCCESS !=
446 ni_device_session_query(sessionCtxt, module_type))
447 {
448 ni_device_close(sessionCtxt->device_handle);
449 (void)fprintf(stderr, "Error query %s %s.%d\n", module_name,
450 p_device_context->p_device_info->dev_name,
451 p_device_context->p_device_info->hw_id);
452 ni_rsrc_free_device_context(p_device_context);
453 continue;
454 }
455 // printf("Done query %s %s.%d\n", module_name,
456 // p_device_context->p_device_info->dev_name,
457 // p_device_context->p_device_info->hw_id);
458 ni_device_close(sessionCtxt->device_handle);
459
460 if (0 == sessionCtxt->load_query.total_contexts)
461 {
462 sessionCtxt->load_query.current_load = 0;
463 }
464
465 // Print performance info row
466 if (IS_XCODER_DEVICE_TYPE(module_type))
467 {
468 printf("%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
469 p_device_context->p_device_info->module_id,
470 sessionCtxt->load_query.current_load,
471 sessionCtxt->load_query.fw_model_load,
472 sessionCtxt->load_query.total_contexts,
473 sessionCtxt->load_query.fw_video_mem_usage,
474 sessionCtxt->load_query.fw_share_mem_usage,
475 sessionCtxt->load_query.fw_p2p_mem_usage,
476 p_device_context->p_device_info->dev_name);
477 }
478 ni_rsrc_free_device_context(p_device_context);
479 }
480 }
481 free(module_id_arr);
482 }
483
485 ni_rsrc_free_device_pool(p_device_pool);
486
487 printf("**************************************************\n");
488}
489
490/*******************************************************************************
491 * @brief
492 *
493 * @param
494 *
495 * @return
496 ******************************************************************************/
497static void addCoder(void)
498{
499 char dev[64];
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): ");
503 ni_rsrc_add_device(dev, should_match_rev);
504}
505
506/*******************************************************************************
507 * @brief
508 *
509 * @param
510 *
511 * @return
512 ******************************************************************************/
513static void initRsrc(void)
514{
515 int should_match_rev =
516 getInt("should match current release version, yes (1) no (0): ");
517 int timeout_seconds = getInt("timeout_seconds: ");
518 ni_rsrc_init(should_match_rev, timeout_seconds);
519}
520
521/******************************************************************************
522 * @brief
523 *
524 * @param
525 *
526 * @return
527 ******************************************************************************/
528static void niRsrcRefresh(void)
529{
530 int should_match_rev =
531 getInt("should match current release version, yes (1) no (0): ");
532 ni_rsrc_refresh(should_match_rev);
533}
534
535/******************************************************************************
536 * @brief
537 *
538 * @param
539 *
540 * @return
541 ******************************************************************************/
542static void checkHwAvailable(void)
543{
544 int guid = getInt("guid :");
545 int deviceType=getInt("deviceType : ");
546 ni_rsrc_check_hw_available(guid,deviceType);
547}
548
549
550/******************************************************************************
551 * @brief
552 *
553 * @param
554 *
555 * @return
556 ******************************************************************************/
557static void getlocaldevicelist(void)
558{
560}
561
562/******************************************************************************
563 * @brief
564 *
565 * @param
566 *
567 * @return
568 ******************************************************************************/
569static void deleteCoder(void)
570{
571 char dev[64];
572 getStr("device name (/dev/*): ", dev, sizeof(dev));
574}
575
576/******************************************************************************
577 * @brief
578 *
579 * @param
580 *
581 * @return
582 ******************************************************************************/
583static void removeAllDevices(void)
584{
586}
587
588
589static void checkHWInfo(void)
590{
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");
593#if defined(_MSC_VER)
594 int ret_scanf = scanf_s("%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem);
595#else
596 int ret_scanf = scanf("%d %d %d %d",&task_mode,&device_type,&hw_mode,&consider_mem); // NOLINT(cert-err34-c) - return value checked below
597#endif
598 if(ret_scanf == EOF || ret_scanf < 4)
599 {
600 (void)fprintf(stderr, "%s, read parameters failed", __func__);
601 }
602 ni_hw_device_info_quadra_t *device_info = NULL;
604 threshold[0].device_type = NI_DEVICE_TYPE_DECODER;//0
605 threshold[0].load_threshold = 10;
606 threshold[0].task_num_threshold = 10;
607 threshold[1].device_type = NI_DEVICE_TYPE_ENCODER;//1
608 threshold[1].load_threshold = 20;
609 threshold[1].task_num_threshold = 10;
610 threshold[2].device_type = NI_DEVICE_TYPE_SCALER;//2
611 threshold[2].load_threshold = 30;
612 threshold[2].task_num_threshold = 10;
613 threshold[3].device_type = NI_DEVICE_TYPE_AI;//3
614 threshold[3].load_threshold = 40;
615 threshold[3].task_num_threshold = 10;
616
618 coder_param->encoder_param->w = 7680;
619 coder_param->encoder_param->h = 4320;
620 coder_param->encoder_param->lookaheadDepth = 20;
621 coder_param->decoder_param->w = 7680;
622 coder_param->decoder_param->h = 4320;
623 coder_param->decoder_param->hw_frame = 1;
624 coder_param->scaler_param->h = 7680;
625 coder_param->scaler_param->w = 1920;
626 coder_param->scaler_param->bit_8_10 = 8;
627 int ret = ni_check_hw_info(&device_info,task_mode,threshold,device_type,coder_param,hw_mode,consider_mem);
628 // int ret = ni_check_hw_info(&device_info, 1, threshold, 1, coder_param, 1, 0);
629 printf("ret = %d\n",ret);
632}
633
634/*******************************************************************************
635 * @brief
636 *
637 * @param
638 *
639 * @return
640 *******************************************************************************/
641static void allocAuto(void)
642{
643 ni_device_context_t *p_device_context;
644 ni_device_type_t type;
645 ni_alloc_rule_t rule;
646 uint64_t model_load;
647
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)
651 {
652 ni_log(NI_LOG_ERROR, "ERROR: invalid input for type or rule\n");
653 return;
654 }
655 type = (ni_device_type_t)type_val;
656 rule = (ni_alloc_rule_t)rule_val;
657 printf("type: %d rule %d\n", type, rule);
658
659 p_device_context = ni_rsrc_allocate_auto(type, rule, EN_H265, 1920, 1080, 30, &model_load);
660 if (p_device_context)
661 {
662 printf("Successfully auto-allocated s/w instance on:\n");
663 ni_rsrc_print_device_info(p_device_context->p_device_info);
664 printf("Allocated load: %"PRIu64"\n", model_load);
665 ni_rsrc_free_device_context(p_device_context);
666 }
667}
668
669
670int main(void)
671{
672 int stop = 0;
673
674 while (!stop)
675 {
676 printf("Key function\n"
677 "? show this help\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"
683#ifndef _WIN32
684 "i Initialize and create all resources required to work with \n"
685#endif
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"
696 "q quit\n");
697
698 int control = getCmd("> ");
699 switch (control)
700 {
701 case '?':
702 continue;
703#ifndef _WIN32
704 case 'i':
705 initRsrc();
706 break;
707#endif
708 case 'D':
709 removeAllDevices();
710 break;
711 case 'v':
712 change_log_level();
713 break;
714 case 'V':
715 printf("Release ver: %s\n"
716 "API ver: %s\n"
717 "Date: %s\n"
718 "ID: %s\n",
721 break;
722 case 'l':
723 listOneTypeCoders();
724 break;
725 case 'L':
726 listAllCodersFull();
727 break;
728 case 'o':
729 listModuleId();
730 break;
731 case 'g':
732 getCoderDetailInfo();
733 break;
734 case 's':
735 niRsrcRefresh();
736 break;
737 case 'p':
738 getlocaldevicelist();
739 break;
740 case 'x':
741 addCoder();
742 break;
743 case 'd':
744 deleteCoder();
745 break;
746 case 'r':
747 checkHwAvailable();
748 break;
749 case 'm':
750 displayRsrcMon();
751 break;
752 case 'C':
753 checkHWInfo();
754 break;
755 case 'a':
756 allocAuto();
757 break;
758 case 'q':
759 case EOF:
760 stop = 1;
761 break;
762 default:
763 continue;
764 }
765 }
766
767 return 0;
768}
#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:448
#define IS_XCODER_DEVICE_TYPE(t)
Definition ni_defs.h:431
#define NI_UNUSED
Definition ni_defs.h:67
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_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
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Definition ni_log.c:183
#define NI_ERRNO_LEN
Definition ni_log.h:51
ni_log_level_t
Definition ni_log.h:58
@ NI_LOG_ERROR
Definition ni_log.h:62
@ 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_strtod_val(const char *str, double *out_val)
Safely convert a decimal string to a double with full validation. Trailing whitespace is tolerated.
Definition ni_util.c:2612
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
Definition ni_util.c:663
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition ni_util.c:460
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...
Definition ni_util.c:2577
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)