libxcoder  5.2.0
ni_rsrc_priv.h
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 ni_rsrc_priv.h
24  *
25  * \brief Private definitions used by ni_rsrc_api.cpp for management of
26  * NETINT video processing devices
27  ******************************************************************************/
28 
29 #pragma once
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include "ni_device_api.h"
36 
37 #ifdef __APPLE__
38 #define LOCK_DIR "/tmp"
39 #else
40 #define LOCK_DIR "/dev/shm"
41 #endif
42 
43 #define CODERS_LCK_NAME LOCK_DIR "/NI_QUADRA_LCK_CODERS"
44 #define CODERS_SHM_NAME "NI_QUADRA_SHM_CODERS"
45 
46 #ifdef __OPENHARMONY__
47 #define PROJ_ID 818565 //the ascii value for "QUA": 81 85 65
48 #endif
49 
50 NI_UNUSED static const char *XCODERS_RETRY_LCK_NAME[] = {
51  LOCK_DIR "/NI_QUADRA_RETRY_LCK_DECODERS", LOCK_DIR "/NI_QUADRA_RETRY_LCK_ENCODERS",
52  LOCK_DIR "/NI_QUADRA_RETRY_LCK_SCALERS", LOCK_DIR "/NI_QUADRA_RETRY_LCK_AI"};
53 
54 #define MAX_LOCK_RETRY 6000
55 #define LOCK_WAIT 10000 // wait in us
56 
57 extern LIB_API uint32_t g_xcoder_stop_process;
58 
59 void ni_rsrc_get_lock_name(ni_device_type_t device_type, int32_t guid, char* p_name, size_t max_name_len);
60 void ni_rsrc_get_shm_name(ni_device_type_t device_type, int32_t guid, char* p_name, size_t max_name_len);
61 void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx);
64 #ifdef _WIN32
65 int ni_rsrc_init_priv(const int should_match_rev,
66  const int existing_number_of_devices,
67  const char device_names[NI_MAX_DEVICE_CNT][NI_MAX_DEVICE_NAME_LEN]);
68 #else
69 int ni_rsrc_init_priv(const int should_match_rev,
70  const int existing_number_of_devices,
71  const char device_names[NI_MAX_DEVICE_CNT][NI_MAX_DEVICE_NAME_LEN],
72  int limit_depth);
73 #endif
75  int max_handles);
76 bool add_to_shared_memory(const char device_name[NI_MAX_DEVICE_NAME_LEN],
77  const bool device_open_should_succeed,
78  const int should_match_rev,
79  ni_device_queue_t *device_queue);
80 
81 int ni_rsrc_strcmp(const void* p_str, const void* p_str1);
82 
83 // return 1 if fw_rev is compatible with NI_XCODER_REVISION, 0 otherwise
84 int ni_is_fw_compatible(uint8_t fw_rev[8]);
85 
86 void get_dev_pcie_addr(char *device_name,
87  char *pcie,
88  char *domain, char *slot, char *dev, char *func);
89 
90 #if __linux__ || __APPLE__
91 typedef enum _ni_rsrc_shm_state
92 {
93  NI_RSRC_SHM_IS_INVALID = -1,
94  NI_RSRC_SHM_IS_CREATED = 0,
95  NI_RSRC_SHM_IS_EXISTED = 1,
96 } ni_rsrc_shm_state;
97 
98 //a set of API for shared memory
99 ni_retcode_t ni_rsrc_try_get_shm_lock(const char *lck_name,
100  int flags,
101  const mode_t mode,
102  int *lck_fd);
103 
104 ni_retcode_t ni_rsrc_open_shm(const char *shm_name,
105  int shm_size,
106  ni_rsrc_shm_state *state,
107  int *shm_fd);
108 
109 ni_retcode_t ni_rsrc_mmap_shm(const char *shm_name,
110  int shm_fd,
111  int shm_size,
112  void **shm_addr);
113 
114 ni_retcode_t ni_rsrc_munmap_shm(void *shm_addr,
115  int shm_size);
116 
117 ni_retcode_t ni_rsrc_remove_shm(const char *shm_name,
118  int shm_size);
119 
120 ni_retcode_t ni_rsrc_remove_all_shm();
121 #endif
122 
123 #ifdef __cplusplus
124 }
125 #endif
NI_UNUSED
#define NI_UNUSED
Definition: ni_defs.h:64
_ni_hw_capability
hardware capability type
Definition: ni_device_api.h:1134
LOCK_DIR
#define LOCK_DIR
Definition: ni_rsrc_priv.h:40
ni_device_type_t
ni_device_type_t
Definition: ni_defs.h:341
ni_codec_t
ni_codec_t
Definition: ni_rsrc_api.h:47
ni_rsrc_fill_device_info
ni_retcode_t ni_rsrc_fill_device_info(ni_device_info_t *p_device_info, ni_codec_t fmt, ni_device_type_t type, ni_hw_capability_t *p_hw_cap)
Definition: ni_rsrc_priv.cpp:82
ni_rsrc_init_priv
int ni_rsrc_init_priv(const int should_match_rev, const int existing_number_of_devices, const char device_names[NI_MAX_DEVICE_CNT][NI_MAX_DEVICE_NAME_LEN], int limit_depth)
ni_rsrc_update_record
void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx)
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:425
ni_rsrc_strcmp
int ni_rsrc_strcmp(const void *p_str, const void *p_str1)
Definition: ni_rsrc_priv.cpp:205
ni_is_fw_compatible
int ni_is_fw_compatible(uint8_t fw_rev[8])
ni_rsrc_get_one_device_info
void ni_rsrc_get_one_device_info(ni_device_info_t *p_device_info)
_ni_device_info
Definition: ni_rsrc_api.h:102
_ni_device_queue
Definition: ni_rsrc_api.h:67
_ni_device_context
Definition: ni_rsrc_api.h:145
_ni_session_context
Definition: ni_device_api.h:1408
NI_MAX_DEVICE_CNT
#define NI_MAX_DEVICE_CNT
Definition: ni_defs.h:223
NI_MAX_DEVICE_NAME_LEN
#define NI_MAX_DEVICE_NAME_LEN
Definition: ni_defs.h:224
g_xcoder_stop_process
LIB_API uint32_t g_xcoder_stop_process
Definition: ni_rsrc_priv.cpp:73
ni_rsrc_enumerate_devices
int ni_rsrc_enumerate_devices(char ni_devices[][NI_MAX_DEVICE_NAME_LEN], int max_handles)
ni_rsrc_get_lock_name
void ni_rsrc_get_lock_name(ni_device_type_t device_type, int32_t guid, char *p_name, size_t max_name_len)
Definition: ni_rsrc_priv.cpp:242
ni_device_api.h
Public definitions for operating NETINT video processing devices for video processing.
LIB_API
#define LIB_API
Definition: ni_libxcoder_dynamic_loading.h:52
ni_rsrc_get_shm_name
void ni_rsrc_get_shm_name(ni_device_type_t device_type, int32_t guid, char *p_name, size_t max_name_len)
Definition: ni_rsrc_priv.cpp:265
add_to_shared_memory
bool add_to_shared_memory(const char device_name[NI_MAX_DEVICE_NAME_LEN], const bool device_open_should_succeed, const int should_match_rev, ni_device_queue_t *device_queue)
Definition: ni_rsrc_priv.cpp:408
get_dev_pcie_addr
void get_dev_pcie_addr(char *device_name, char *pcie, char *domain, char *slot, char *dev, char *func)