NVIDIA DeepStream SDK API Reference

9.1 Release
sources/includes/gst-nvcommon.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
26 #ifndef __GST_NVCOMMON_H__
27 #define __GST_NVCOMMON_H__
28 
29 #include <gst/gst.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef __aarch64__
36 #define CHECK_DEFAULT_MEM(memType1, memType2) ((memType1 == NVBUF_MEM_DEFAULT && memType2 == NVBUF_MEM_CUDA_DEVICE) || \
37  (memType1 == NVBUF_MEM_CUDA_DEVICE && memType2 == NVBUF_MEM_DEFAULT))
38 
39 #define GET_DEFAULT_MEM_TYPE(mem_type) {mem_type=NVBUF_MEM_CUDA_DEVICE;}
40 
41 #else
42 
43 #define CHECK_DEFAULT_MEM(memType1, memType2) ((memType1 == NVBUF_MEM_DEFAULT && memType2 == NVBUF_MEM_SURFACE_ARRAY) || \
44  (memType1 == NVBUF_MEM_SURFACE_ARRAY && memType2 == NVBUF_MEM_DEFAULT))
45 
46 #ifdef __cplusplus
47 #define GET_DEFAULT_MEM_TYPE(mem_type) {int is_nvgpu = 0; NvBufSurfaceDeviceInfo dev_info{}; \
48  if (NvBufSurfaceGetDeviceInfo(&dev_info) == 0) { \
49  if (dev_info.driverType == NVBUF_DRIVER_TYPE_NVGPU) { \
50  is_nvgpu = 1; \
51  } \
52  } \
53  if(is_nvgpu) mem_type=NVBUF_MEM_SURFACE_ARRAY;\
54  else mem_type=NVBUF_MEM_CUDA_DEVICE;}
55 #else
56 #define GET_DEFAULT_MEM_TYPE(mem_type) {int is_nvgpu = 0; NvBufSurfaceDeviceInfo dev_info = {0}; \
57  if (NvBufSurfaceGetDeviceInfo(&dev_info) == 0) { \
58  if (dev_info.driverType == NVBUF_DRIVER_TYPE_NVGPU) { \
59  is_nvgpu = 1; \
60  } \
61  } \
62  if(is_nvgpu) mem_type=NVBUF_MEM_SURFACE_ARRAY;\
63  else mem_type=NVBUF_MEM_CUDA_DEVICE;}
64 #endif
65 #endif
66 
67 #define CHECK_NVDS_MEMORY_AND_GPUID(object, surface) \
68  ({ int _errtype=0;\
69  do { \
70  if (((surface->memType == NVBUF_MEM_DEFAULT || surface->memType == NVBUF_MEM_CUDA_DEVICE) && \
71  ((int)surface->gpuId != (int)object->gpu_id)) || \
72  (((int)surface->gpuId == (int)object->gpu_id) && (surface->memType == NVBUF_MEM_SYSTEM))) { \
73  GST_ELEMENT_ERROR (object, RESOURCE, FAILED, \
74  ("Memory Compatibility Error:Input surface gpu-id doesnt match with configured gpu-id for element," \
75  " please allocate input using unified memory, or use same gpu-ids OR,"\
76  " if same gpu-ids are used ensure appropriate Cuda memories are used"),\
77  ("surface-gpu-id=%d,%s-gpu-id=%d",surface->gpuId,GST_ELEMENT_NAME(object),\
78  object->gpu_id)); \
79  _errtype = 1;\
80  } \
81  } while(0); \
82  _errtype; \
83  })
84 
85 
86 #define GST_TYPE_NVBUF_MEMORY_TYPE (gst_nvbuf_memory_get_type ())
87 GType gst_nvbuf_memory_get_type (void);
88 
89 #define GST_TYPE_COMPUTE_HW (gst_compute_hw_get_type ())
90 GType gst_compute_hw_get_type (void);
91 
92 #define GST_TYPE_INTERPOLATION_METHOD (gst_video_interpolation_method_get_type ())
94 
95 const char * gst_nvbuf_memory_get_name(int mem_type);
96 int gst_nvbuf_memory_get_value(const char *mem_type_string);
97 
98 #define PROP_NVDS_GPU_ID_INSTALL(gobject_class) \
99 do { \
100 g_object_class_install_property (gobject_class, PROP_GPU_DEVICE_ID, \
101  g_param_spec_uint ("gpu-id", "Set GPU Device ID for operation", \
102  "Set GPU Device ID for operation", \
103  0, G_MAXUINT, 0, \
104  (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | \
105  GST_PARAM_MUTABLE_READY))); \
106 }while(0)
107 
108 #define PROP_NVBUF_MEMORY_TYPE_INSTALL(gobject_class) \
109 do { \
110  g_object_class_install_property (gobject_class, PROP_NVBUF_MEMORY_TYPE, \
111  g_param_spec_enum ("nvbuf-memory-type", "Type of NvBufSurface memory allocated", \
112  "Type of NvBufSurface Memory to be allocated for output buffers", \
113  GST_TYPE_NVBUF_MEMORY_TYPE, \
114  NVBUF_MEM_DEFAULT, \
115  (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | \
116  GST_PARAM_MUTABLE_READY))); \
117 }while(0)
118 
119 #define PROP_COMPUTE_HW_INSTALL(gobject_class) \
120 do { \
121  g_object_class_install_property (gobject_class, PROP_COMPUTE_HW, \
122  g_param_spec_enum ("compute-hw", "compute-hw", \
123  "Compute Scaling HW", \
124  GST_TYPE_COMPUTE_HW, NvBufSurfTransformCompute_Default, \
125  (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | \
126  GST_PARAM_CONTROLLABLE | G_PARAM_CONSTRUCT))); \
127 }while(0)
128 
129 #define PROP_INTERPOLATION_METHOD_INSTALL(gobject_class) \
130 do { \
131  g_object_class_install_property (gobject_class, PROP_INTERPOLATION_METHOD, \
132  g_param_spec_enum ("interpolation-method", "Interpolation-method", \
133  "Set interpolation methods", \
134  GST_TYPE_INTERPOLATION_METHOD, NvBufSurfTransformInter_Default, \
135  (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | \
136  GST_PARAM_CONTROLLABLE | G_PARAM_CONSTRUCT))); \
137 }while(0)
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 
143 #endif /* __GST_NVCOMMON_H__ */
gst_video_interpolation_method_get_type
GType gst_video_interpolation_method_get_type(void)
gst_nvbuf_memory_get_type
GType gst_nvbuf_memory_get_type(void)
gst_nvbuf_memory_get_value
int gst_nvbuf_memory_get_value(const char *mem_type_string)
gst_compute_hw_get_type
GType gst_compute_hw_get_type(void)
gst_nvbuf_memory_get_name
const char * gst_nvbuf_memory_get_name(int mem_type)