NVIDIA DeepStream SDK API Reference

6.4 Release
deepstream_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __NVGSTDS_COMMON_H__
24 #define __NVGSTDS_COMMON_H__
25 
26 #include <gst/gst.h>
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "deepstream_config.h"
34 
35 #define NVGSTDS_ERR_MSG_V(msg, ...) \
36  g_print("** ERROR: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
37 
38 #define NVGSTDS_INFO_MSG_V(msg, ...) \
39  g_print("** INFO: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
40 
41 #define NVGSTDS_WARN_MSG_V(msg, ...) \
42  g_print("** WARN: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
43 
44 #define NVGSTDS_LINK_ELEMENT(elem1, elem2) \
45  do { \
46  if (!gst_element_link (elem1,elem2)) { \
47  GstCaps *src_caps, *sink_caps; \
48  src_caps = gst_pad_query_caps ((GstPad *) (elem1)->srcpads->data, NULL); \
49  sink_caps = gst_pad_query_caps ((GstPad *) (elem2)->sinkpads->data, NULL); \
50  NVGSTDS_ERR_MSG_V ("Failed to link '%s' (%s) and '%s' (%s)", \
51  GST_ELEMENT_NAME (elem1), \
52  gst_caps_to_string (src_caps), \
53  GST_ELEMENT_NAME (elem2), \
54  gst_caps_to_string (sink_caps)); \
55  goto done; \
56  } \
57  } while (0)
58 
59 #define NVGSTDS_LINK_ELEMENT_FULL(elem1, elem1_pad_name, elem2, elem2_pad_name) \
60  do { \
61  GstPad *elem1_pad = gst_element_get_static_pad(elem1, elem1_pad_name); \
62  GstPad *elem2_pad = gst_element_get_static_pad(elem2, elem2_pad_name); \
63  GstPadLinkReturn ret = gst_pad_link (elem1_pad,elem2_pad); \
64  if (ret != GST_PAD_LINK_OK) { \
65  gchar *n1 = gst_pad_get_name (elem1_pad); \
66  gchar *n2 = gst_pad_get_name (elem2_pad); \
67  NVGSTDS_ERR_MSG_V ("Failed to link '%s' and '%s': %d", \
68  n1, n2, ret); \
69  g_free (n1); \
70  g_free (n2); \
71  gst_object_unref (elem1_pad); \
72  gst_object_unref (elem2_pad); \
73  goto done; \
74  } \
75  gst_object_unref (elem1_pad); \
76  gst_object_unref (elem2_pad); \
77  } while (0)
78 
79 #define NVGSTDS_BIN_ADD_GHOST_PAD_NAMED(bin, elem, pad, ghost_pad_name) \
80  do { \
81  GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
82  if (!gstpad) { \
83  NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
84  GST_ELEMENT_NAME(elem)); \
85  goto done; \
86  } \
87  gst_element_add_pad (bin, gst_ghost_pad_new (ghost_pad_name, gstpad)); \
88  gst_object_unref (gstpad); \
89  } while (0)
90 
91 #define NVGSTDS_BIN_ADD_GHOST_PAD(bin, elem, pad) \
92  NVGSTDS_BIN_ADD_GHOST_PAD_NAMED (bin, elem, pad, pad)
93 
94 #define NVGSTDS_ELEM_ADD_PROBE(probe_id, elem, pad, probe_func, probe_type, probe_data) \
95  do { \
96  GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
97  if (!gstpad) { \
98  NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
99  GST_ELEMENT_NAME(elem)); \
100  goto done; \
101  } \
102  probe_id = gst_pad_add_probe(gstpad, (probe_type), probe_func, probe_data, NULL); \
103  gst_object_unref (gstpad); \
104  } while (0)
105 
106 #define NVGSTDS_ELEM_REMOVE_PROBE(probe_id, elem, pad) \
107  do { \
108  if (probe_id == 0 || !elem) { \
109  break; \
110  } \
111  GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
112  if (!gstpad) { \
113  NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
114  GST_ELEMENT_NAME(elem)); \
115  break; \
116  } \
117  gst_pad_remove_probe(gstpad, probe_id); \
118  gst_object_unref (gstpad); \
119  } while (0)
120 
121 #define GET_FILE_PATH(path) ((path) + (((path) && strstr ((path), "file://")) ? 7 : 0))
122 
123 
132 gboolean
133 link_element_to_tee_src_pad (GstElement * tee, GstElement * sinkelem);
134 
144 gboolean
145 link_element_to_streammux_sink_pad (GstElement *streammux, GstElement *elem,
146  gint index);
147 
156 gboolean
157 unlink_element_from_streammux_sink_pad (GstElement *streammux, GstElement *elem);
158 
168 gboolean
169 link_element_to_demux_src_pad (GstElement *demux, GstElement *elem,
170  guint index);
171 
172 /*
173  * Function to replace string with another string.
174  * Make sure @ref src is big enough to accommodate replacements.
175  *
176  * @param[in] str string to search in.
177  * @param[in] replace string to replace.
178  * @param[in] replace_with string to replace @ref replace with.
179  */
180 void
181 str_replace (gchar * str, const gchar * replace, const gchar * replace_with);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #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.