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 // The macro definition in libxcoder_FFmpeg3.1.1only/source/ni_rsrc_priv.h need to be synchronized with libxcoder
38 // If you change this,you should also change LOCK_DIR in libxcoder_FFmpeg3.1.1only/source/ni_rsrc_priv.h
39 #ifdef __APPLE__
40 #define LOCK_DIR "/tmp"
41 #else
42 #define LOCK_DIR "/dev/shm"
43 #endif
44 
45 #define CODERS_LCK_NAME LOCK_DIR "/NI_LCK_CODERS"
46 #define CODERS_SHM_NAME "NI_SHM_CODERS"
47 
48 #ifdef __OPENHARMONY__
49 #define PROJ_ID 818565 //the ascii value for "QUA": 81 85 65
50 #endif
51 
52 NI_UNUSED static const char *XCODERS_RETRY_LCK_NAME[] = {
53  LOCK_DIR "/NI_RETRY_LCK_DECODERS", LOCK_DIR "/NI_RETRY_LCK_ENCODERS",
54  LOCK_DIR "/NI_RETRY_LCK_SCALERS", LOCK_DIR "/NI_RETRY_LCK_AI"};
55 
56 // The macro definition in libxcoder_FFmpeg3.1.1only/source/ni_rsrc_priv.h need to be synchronized with libxcoder
57 // If you change this,you should also change MAX_LOCK_RETRY LOCK_WAIT in libxcoder_FFmpeg3.1.1only/source/ni_rsrc_priv.h
58 #define MAX_LOCK_RETRY 6000
59 #define LOCK_WAIT 10000 // wait in us
60 
61 extern LIB_API uint32_t g_xcoder_stop_process;
62 
63 // The macro definition in libxcoder_FFmpeg3.1.1only/source/ni_rsrc_priv.h need to be synchronized with libxcoder
64 // If you change these functions,you should also change these functions in libxcoder_FFmpeg3.1.1only/source/ni_rsrc_priv.h
65 void ni_rsrc_get_lock_name(ni_device_type_t device_type, int32_t guid, char* p_name, size_t max_name_len);
66 void ni_rsrc_get_shm_name(ni_device_type_t device_type, int32_t guid, char* p_name, size_t max_name_len);
67 void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx);
70 #ifdef _WIN32
71 int ni_rsrc_init_priv(const int should_match_rev,
72  const int existing_number_of_devices,
73  const char device_names[NI_MAX_DEVICE_CNT][NI_MAX_DEVICE_NAME_LEN]);
74 #else
75 int ni_rsrc_init_priv(const int should_match_rev,
76  const int existing_number_of_devices,
77  const char device_names[NI_MAX_DEVICE_CNT][NI_MAX_DEVICE_NAME_LEN],
78  int limit_depth);
79 #endif
81  int max_handles);
82 bool add_to_shared_memory(const char device_name[NI_MAX_DEVICE_NAME_LEN],
83  const bool device_open_should_succeed,
84  const int should_match_rev,
85  ni_device_queue_t *device_queue);
86 
87 int ni_rsrc_strcmp(const void* p_str, const void* p_str1);
88 
89 void get_dev_pcie_addr(char *device_name,
90  char *pcie,
91  char *domain, char *slot, char *dev, char *func);
92 
93 #if __linux__ || __APPLE__
94 typedef enum _ni_rsrc_shm_state
95 {
96  NI_RSRC_SHM_IS_INVALID = -1,
97  NI_RSRC_SHM_IS_CREATED = 0,
98  NI_RSRC_SHM_IS_EXISTED = 1,
99 } ni_rsrc_shm_state;
100 
101 //a set of API for shared memory
102 ni_retcode_t ni_rsrc_try_get_shm_lock(const char *lck_name,
103  int flags,
104  const mode_t mode,
105  int *lck_fd);
106 
107 ni_retcode_t ni_rsrc_open_shm(const char *shm_name,
108  int shm_size,
109  ni_rsrc_shm_state *state,
110  int *shm_fd);
111 
112 ni_retcode_t ni_rsrc_mmap_shm(const char *shm_name,
113  int shm_fd,
114  int shm_size,
115  void **shm_addr);
116 
117 ni_retcode_t ni_rsrc_munmap_shm(void *shm_addr,
118  int shm_size);
119 
120 ni_retcode_t ni_rsrc_remove_shm(const char *shm_name,
121  int shm_size);
122 
123 ni_retcode_t ni_rsrc_remove_all_shm();
124 #endif
125 
126 #ifdef __cplusplus
127 }
128 #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:42
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_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)