NVIDIA DeepStream SDK API Reference

7.0 Release
deepstream_common.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2019 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef __NVGSTDS_COMMON_H__
14 #define __NVGSTDS_COMMON_H__
15 
16 #include <gst/gst.h>
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include "deepstream_config.h"
24 
25 #define NVGSTDS_ERR_MSG_V(msg, ...) \
26  g_print("** ERROR: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
27 
28 #define NVGSTDS_INFO_MSG_V(msg, ...) \
29  g_print("** INFO: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
30 
31 #define NVGSTDS_WARN_MSG_V(msg, ...) \
32  g_print("** WARN: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
33 
34 #define NVGSTDS_LINK_ELEMENT(elem1, elem2) \
35  do { \
36  if (!gst_element_link (elem1,elem2)) { \
37  GstCaps *src_caps, *sink_caps; \
38  src_caps = gst_pad_query_caps ((GstPad *) (elem1)->srcpads->data, NULL); \
39  sink_caps = gst_pad_query_caps ((GstPad *) (elem2)->sinkpads->data, NULL); \
40  NVGSTDS_ERR_MSG_V ("Failed to link '%s' (%s) and '%s' (%s)", \
41  GST_ELEMENT_NAME (elem1), \
42  gst_caps_to_string (src_caps), \
43  GST_ELEMENT_NAME (elem2), \
44  gst_caps_to_string (sink_caps)); \
45  goto done; \
46  } \
47  } while (0)
48 
49 #define NVGSTDS_LINK_ELEMENT_FULL(elem1, elem1_pad_name, elem2, elem2_pad_name) \
50  do { \
51  GstPad *elem1_pad = gst_element_get_static_pad(elem1, elem1_pad_name); \
52  GstPad *elem2_pad = gst_element_get_static_pad(elem2, elem2_pad_name); \
53  GstPadLinkReturn ret = gst_pad_link (elem1_pad,elem2_pad); \
54  if (ret != GST_PAD_LINK_OK) { \
55  gchar *n1 = gst_pad_get_name (elem1_pad); \
56  gchar *n2 = gst_pad_get_name (elem2_pad); \
57  NVGSTDS_ERR_MSG_V ("Failed to link '%s' and '%s': %d", \
58  n1, n2, ret); \
59  g_free (n1); \
60  g_free (n2); \
61  gst_object_unref (elem1_pad); \
62  gst_object_unref (elem2_pad); \
63  goto done; \
64  } \
65  gst_object_unref (elem1_pad); \
66  gst_object_unref (elem2_pad); \
67  } while (0)
68 
69 #define NVGSTDS_BIN_ADD_GHOST_PAD_NAMED(bin, elem, pad, ghost_pad_name) \
70  do { \
71  GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
72  if (!gstpad) { \
73  NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
74  GST_ELEMENT_NAME(elem)); \
75  goto done; \
76  } \
77  gst_element_add_pad (bin, gst_ghost_pad_new (ghost_pad_name, gstpad)); \
78  gst_object_unref (gstpad); \
79  } while (0)
80 
81 #define NVGSTDS_BIN_ADD_GHOST_PAD(bin, elem, pad) \
82  NVGSTDS_BIN_ADD_GHOST_PAD_NAMED (bin, elem, pad, pad)
83 
84 #define NVGSTDS_ELEM_ADD_PROBE(probe_id, elem, pad, probe_func, probe_type, probe_data) \
85  do { \
86  GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
87  if (!gstpad) { \
88  NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
89  GST_ELEMENT_NAME(elem)); \
90  goto done; \
91  } \
92  probe_id = gst_pad_add_probe(gstpad, (probe_type), probe_func, probe_data, NULL); \
93  gst_object_unref (gstpad); \
94  } while (0)
95 
96 #define NVGSTDS_ELEM_REMOVE_PROBE(probe_id, elem, pad) \
97  do { \
98  if (probe_id == 0 || !elem) { \
99  break; \
100  } \
101  GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
102  if (!gstpad) { \
103  NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
104  GST_ELEMENT_NAME(elem)); \
105  break; \
106  } \
107  gst_pad_remove_probe(gstpad, probe_id); \
108  gst_object_unref (gstpad); \
109  } while (0)
110 
111 #define GET_FILE_PATH(path) ((path) + (((path) && strstr ((path), "file://")) ? 7 : 0))
112 
113 
122 gboolean
123 link_element_to_tee_src_pad (GstElement * tee, GstElement * sinkelem);
124 
134 gboolean
135 link_element_to_streammux_sink_pad (GstElement *streammux, GstElement *elem,
136  gint index);
137 
146 gboolean
147 unlink_element_from_streammux_sink_pad (GstElement *streammux, GstElement *elem);
148 
158 gboolean
159 link_element_to_demux_src_pad (GstElement *demux, GstElement *elem,
160  guint index);
161 
162 /*
163  * Function to replace string with another string.
164  * Make sure @ref src is big enough to accommodate replacements.
165  *
166  * @param[in] str string to search in.
167  * @param[in] replace string to replace.
168  * @param[in] replace_with string to replace @ref replace with.
169  */
170 void
171 str_replace (gchar * str, const gchar * replace, const gchar * replace_with);
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif
str_replace
void str_replace(gchar *str, const gchar *replace, const gchar *replace_with)
link_element_to_streammux_sink_pad
gboolean link_element_to_streammux_sink_pad(GstElement *streammux, GstElement *elem, gint index)
Function to link source pad of an element to sink pad of muxer element.
deepstream_config.h
link_element_to_tee_src_pad
gboolean link_element_to_tee_src_pad(GstElement *tee, GstElement *sinkelem)
Function to link sink pad of an element to source pad of tee.
link_element_to_demux_src_pad
gboolean link_element_to_demux_src_pad(GstElement *demux, GstElement *elem, guint index)
Function to link sink pad of an element to source pad of demux element.
unlink_element_from_streammux_sink_pad
gboolean unlink_element_from_streammux_sink_pad(GstElement *streammux, GstElement *elem)
Function to unlink source pad of an element from sink pad of muxer element.