libxcoder 5.8.0
Loading...
Searching...
No Matches
init_rsrc.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 init_rsrc.c
24 *
25 * \brief Application for registering Netint transcoding devices on system
26 * for use by libxcoder
27 ******************************************************************************/
28
29#include <stdio.h>
30
31#if __linux__ || __APPLE__
32#include <unistd.h>
33#include <sys/types.h>
34#elif _WIN32
35#include "ni_getopt.h"
36#endif
37
38#include "ni_defs.h"
39#include "ni_log.h"
40#include "ni_rsrc_api.h"
41#include "ni_rsrc_priv.h"
42#include "ni_util.h"
43#if __linux__
44#include "ni_host_ts.h"
45#endif
46
47int main(int argc, char *argv[])
48{
49 int should_match_rev = 1;
50 int opt;
51 int timeout_seconds = 0;
52 ni_log_level_t log_level = NI_LOG_INFO;
53
54 // arg handling
55 while ((opt = getopt(argc, argv, "hrt:l:v")) != -1) // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
56 {
57 switch (opt)
58 {
59 case 'h':
60 // help message
61 printf("-------- init_rsrc v%s --------\n"
62 "Initialize NetInt transcoder resource pool\n"
63 "\n"
64 "-r Init transcoder card resource regardless of firmware release version to \n"
65 " libxcoder release version compatibility. Default is to only init cards with \n"
66 " compatible firmware version.\n"
67 "-t Set timeout time in seconds for device polling, will exit with failure if \n"
68 " reached. Default 0s which means no timeout.\n"
69 "-l Set loglevel of libxcoder API.\n"
70 " [none, fatal, error, info, debug, trace]\n"
71 " Default: info\n"
72 "-h Display this help and exit.\n"
73 "-v Print version info.\n",
75 return 0;
76 case 'r':
77 should_match_rev = 0;
78 break;
79 case 't':
80 {
81 int32_t tmp_val;
82 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
83 {
84 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
85 return 1;
86 }
87 timeout_seconds = (int)tmp_val;
88 printf("Timeout will be set %d\n", timeout_seconds);
89 break;
90 }
91 case 'l':
92 log_level = arg_to_ni_log_level(optarg);
93 if (log_level != NI_LOG_INVALID)
94 {
95 ni_log_set_level(log_level);
96 } else {
97 (void)fprintf(stderr, "FATAL: invalid log level selected: %s\n",
98 optarg);
99 return 1;
100 }
101 break;
102 case 'v':
103 printf("Release ver: %s\n"
104 "API ver: %s\n"
105 "Date: %s\n"
106 "ID: %s\n",
109 return 0;
110 default:
111 (void)fprintf(stderr, "FATAL: invalid arg '%c'\n", opt);
112 return 1;
113 }
114 }
115
116#if __linux__
117 ni_retcode_t retval = ni_rsrc_init(should_match_rev, timeout_seconds);
118 ni_host_ts_set();
119 return retval;
120#elif __APPLE__
121 return ni_rsrc_init(should_match_rev, timeout_seconds);
122#elif _WIN32
123 ni_retcode_t retval = ni_rsrc_init(should_match_rev, timeout_seconds);
124 if (NI_RETCODE_SUCCESS == retval)
125 {
126 printf("NETINT Resources Intitialized Successfully\n");
127 }
128
129 while (1)
130 Sleep(1000);
131
132 return retval;
133#endif
134}
int main()
Definition client.cpp:51
Common NETINT definitions used by all modules.
#define NI_XCODER_REVISION
Definition ni_defs.h:98
#define LIBXCODER_API_VERSION
Definition ni_defs.h:115
ni_retcode_t
Definition ni_defs.h:447
@ NI_RETCODE_SUCCESS
Definition ni_defs.h:448
int getopt(int argc, char *argv[], const char *optstring)
Definition ni_getopt.c:38
char * optarg
Definition ni_getopt.c:33
Implementation of getopt() and getopt_long() for Windows environment.
Set host timestamp on Quadra NVMe controllers.
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
Logging definitions.
ni_log_level_t
Definition ni_log.h:58
@ NI_LOG_ERROR
Definition ni_log.h:62
@ NI_LOG_INFO
Definition ni_log.h:63
@ NI_LOG_INVALID
Definition ni_log.h:59
#define NI_SW_RELEASE_ID
#define NI_SW_RELEASE_TIME
Public definitions for managing NETINT video processing devices.
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....
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
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.