libxcoder 5.6.0
Loading...
Searching...
No Matches
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
32extern "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
52NI_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
61extern 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
65void ni_rsrc_get_lock_name(ni_device_type_t device_type, int32_t guid, char* p_name, size_t max_name_len);
66void ni_rsrc_get_shm_name(ni_device_type_t device_type, int32_t guid, char* p_name, size_t max_name_len);
67void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx);
70#ifdef _WIN32
71int 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
75int 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);
82bool 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
87int ni_rsrc_strcmp(const void* p_str, const void* p_str1);
88
89void get_dev_pcie_addr(char *device_name,
90 char *pcie,
91 char *domain, char *slot, char *dev, char *func);
92
94
95#if __linux__ || __APPLE__
96typedef enum _ni_rsrc_shm_state
97{
98 NI_RSRC_SHM_IS_INVALID = -1,
99 NI_RSRC_SHM_IS_CREATED = 0,
100 NI_RSRC_SHM_IS_EXISTED = 1,
101} ni_rsrc_shm_state;
102
103//a set of API for shared memory
104ni_retcode_t ni_rsrc_try_get_shm_lock(const char *lck_name,
105 int flags,
106 const mode_t mode,
107 int *lck_fd);
108
109ni_retcode_t ni_rsrc_open_shm(const char *shm_name,
110 int shm_size,
111 ni_rsrc_shm_state *state,
112 int *shm_fd);
113
114ni_retcode_t ni_rsrc_mmap_shm(const char *shm_name,
115 int shm_fd,
116 int shm_size,
117 void **shm_addr);
118
119ni_retcode_t ni_rsrc_munmap_shm(void *shm_addr,
120 int shm_size);
121
122ni_retcode_t ni_rsrc_remove_shm(const char *shm_name,
123 int shm_size);
124
125ni_retcode_t ni_rsrc_remove_all_shm();
126#endif
127
128#ifdef __cplusplus
129}
130#endif
#define NI_MAX_DEVICE_CNT
Definition ni_defs.h:235
#define NI_MAX_DEVICE_NAME_LEN
Definition ni_defs.h:236
ni_device_type_t
Definition ni_defs.h:356
ni_retcode_t
Definition ni_defs.h:442
#define NI_UNUSED
Definition ni_defs.h:67
Public definitions for operating NETINT video processing devices for video processing.
ni_codec_t
Definition ni_rsrc_api.h:48
LIB_API uint32_t g_xcoder_stop_process
void ni_rsrc_get_shm_name(ni_device_type_t device_type, int32_t guid, char *p_name, size_t max_name_len)
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)
ni_retcode_t ni_rsrc_create_retry_lck()
void ni_rsrc_get_lock_name(ni_device_type_t device_type, int32_t guid, char *p_name, size_t max_name_len)
void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx)
void ni_rsrc_get_one_device_info(ni_device_info_t *p_device_info)
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)
#define LOCK_DIR
int ni_rsrc_enumerate_devices(char ni_devices[][NI_MAX_DEVICE_NAME_LEN], int max_handles)
int ni_rsrc_strcmp(const void *p_str, const void *p_str1)
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)
void get_dev_pcie_addr(char *device_name, char *pcie, char *domain, char *slot, char *dev, char *func)
hardware capability type