libxcoder  5.2.0
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 #include <fcntl.h>
31 
32 #if __linux__ || __APPLE__
33 #include <unistd.h>
34 #include <sys/types.h>
35 #elif _WIN32
36 #include "ni_getopt.h"
37 #endif
38 
39 #include "ni_defs.h"
40 #include "ni_log.h"
41 #include "ni_rsrc_api.h"
42 #include "ni_rsrc_priv.h"
43 
44 int main(int argc, char *argv[])
45 {
46  int should_match_rev = 1;
47  int opt;
48  int timeout_seconds = 0;
49  ni_log_level_t log_level = NI_LOG_INFO;
50 
51  // arg handling
52  while ((opt = getopt(argc, argv, "hrt:l:v")) != -1)
53  {
54  switch (opt)
55  {
56  case 'h':
57  // help message
58  printf("-------- init_rsrc v%s --------\n"
59  "Initialize NetInt transcoder resource pool\n"
60  "\n"
61  "-r Init transcoder card resource regardless of firmware release version to \n"
62  " libxcoder release version compatibility. Default is to only init cards with \n"
63  " compatible firmware version.\n"
64  "-t Set timeout time in seconds for device polling, will exit with failure if \n"
65  " reached. Default 0s which means no timeout.\n"
66  "-l Set loglevel of libxcoder API.\n"
67  " [none, fatal, error, info, debug, trace]\n"
68  " Default: info\n"
69  "-h Display this help and exit.\n"
70  "-v Print version info.\n",
72  return 0;
73  case 'r':
74  should_match_rev = 0;
75  break;
76  case 't':
77  timeout_seconds = atoi(optarg);
78  printf("Timeout will be set %d\n", timeout_seconds);
79  break;
80  case 'l':
81  log_level = arg_to_ni_log_level(optarg);
82  if (log_level != NI_LOG_INVALID)
83  {
84  ni_log_set_level(log_level);
85  } else {
86  fprintf(stderr, "FATAL: invalid log level selected: %s\n",
87  optarg);
88  return 1;
89  }
90  break;
91  case 'v':
92  printf("Release ver: %s\n"
93  "API ver: %s\n"
94  "Date: %s\n"
95  "ID: %s\n",
98  return 0;
99  default:
100  fprintf(stderr, "FATAL: invalid arg '%c'\n", opt);
101  return 1;
102  }
103  }
104 
105 #if __linux__ || __APPLE__
106  return ni_rsrc_init(should_match_rev, timeout_seconds);
107 #elif _WIN32
108  ni_retcode_t retval = ni_rsrc_init(should_match_rev, timeout_seconds);
109  if (NI_RETCODE_SUCCESS == retval)
110  {
111  printf("NETINT Resources Intitialized Successfully\n");
112  }
113 
114  while (1)
115  Sleep(1000);
116 
117  return retval;
118 #endif
119 }
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:427
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:95
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:425
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:7178
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:112
main
int main(int argc, char *argv[])
Definition: init_rsrc.c:44
ni_getopt.h
Implementation of getopt() and getopt_long() for Windows environment.