libxcoder  5.3.1
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 
43 int main(int argc, char *argv[])
44 {
45  int should_match_rev = 1;
46  int opt;
47  int timeout_seconds = 0;
48  ni_log_level_t log_level = NI_LOG_INFO;
49 
50  // arg handling
51  while ((opt = getopt(argc, argv, "hrt:l:v")) != -1)
52  {
53  switch (opt)
54  {
55  case 'h':
56  // help message
57  printf("-------- init_rsrc v%s --------\n"
58  "Initialize NetInt transcoder resource pool\n"
59  "\n"
60  "-r Init transcoder card resource regardless of firmware release version to \n"
61  " libxcoder release version compatibility. Default is to only init cards with \n"
62  " compatible firmware version.\n"
63  "-t Set timeout time in seconds for device polling, will exit with failure if \n"
64  " reached. Default 0s which means no timeout.\n"
65  "-l Set loglevel of libxcoder API.\n"
66  " [none, fatal, error, info, debug, trace]\n"
67  " Default: info\n"
68  "-h Display this help and exit.\n"
69  "-v Print version info.\n",
71  return 0;
72  case 'r':
73  should_match_rev = 0;
74  break;
75  case 't':
76  timeout_seconds = atoi(optarg);
77  printf("Timeout will be set %d\n", timeout_seconds);
78  break;
79  case 'l':
80  log_level = arg_to_ni_log_level(optarg);
81  if (log_level != NI_LOG_INVALID)
82  {
83  ni_log_set_level(log_level);
84  } else {
85  fprintf(stderr, "FATAL: invalid log level selected: %s\n",
86  optarg);
87  return 1;
88  }
89  break;
90  case 'v':
91  printf("Release ver: %s\n"
92  "API ver: %s\n"
93  "Date: %s\n"
94  "ID: %s\n",
97  return 0;
98  default:
99  fprintf(stderr, "FATAL: invalid arg '%c'\n", opt);
100  return 1;
101  }
102  }
103 
104 #if __linux__ || __APPLE__
105  return ni_rsrc_init(should_match_rev, timeout_seconds);
106 #elif _WIN32
107  ni_retcode_t retval = ni_rsrc_init(should_match_rev, timeout_seconds);
108  if (NI_RETCODE_SUCCESS == retval)
109  {
110  printf("NETINT Resources Intitialized Successfully\n");
111  }
112 
113  while (1)
114  Sleep(1000);
115 
116  return retval;
117 #endif
118 }
ni_log_level_t
ni_log_level_t
Definition: ni_log.h:55
NI_SW_RELEASE_ID
#define NI_SW_RELEASE_ID
Definition: ni_release_info.h:29
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:439
ni_log_set_level
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition: ni_log.c:202
ni_rsrc_api.h
Public definitions for managing NETINT video processing devices.
NI_XCODER_REVISION
#define NI_XCODER_REVISION
Definition: ni_defs.h:98
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:437
ni_log.h
Logging definitions.
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:61
arg_to_ni_log_level
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
ni_defs.h
Common NETINT definitions used by all modules.
NI_SW_RELEASE_TIME
#define NI_SW_RELEASE_TIME
Definition: ni_release_info.h:28
NI_LOG_INVALID
@ NI_LOG_INVALID
Definition: ni_log.h:57
optarg
char * optarg
Definition: ni_getopt.c:33
ni_rsrc_priv.h
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
getopt
int getopt(int argc, char *argv[], const char *optstring)
Definition: ni_getopt.c:38
atoi
#define atoi(p_str)
Definition: ni_device_api.c:7263
ni_rsrc_init
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....
LIBXCODER_API_VERSION
#define LIBXCODER_API_VERSION
Definition: ni_defs.h:115
main
int main(int argc, char *argv[])
Definition: init_rsrc.c:43
ni_getopt.h
Implementation of getopt() and getopt_long() for Windows environment.