13 #ifndef __NVGSTDS_COMMON_H__
14 #define __NVGSTDS_COMMON_H__
28 __attribute__((weak)) gchar *g_nvds_last_error_message = NULL;
37 formatted_msg = g_strdup_vprintf(msg, args);
41 g_print(
"** ERROR: <%s:%d>: %s\n", func, line, formatted_msg);
44 if (!g_nvds_last_error_message) {
46 gchar *colon_pos = strchr(formatted_msg,
':');
49 clean_msg = g_strstrip(g_strdup(colon_pos + 1));
50 g_nvds_last_error_message = clean_msg;
53 g_nvds_last_error_message = g_strdup(formatted_msg);
57 g_free(formatted_msg);
60 #define NVGSTDS_ERR_MSG_V(msg, ...) \
61 nvds_capture_error(__func__, __LINE__, msg, ##__VA_ARGS__)
63 #define NVGSTDS_INFO_MSG_V(msg, ...) \
64 g_print("** INFO: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
66 #define NVGSTDS_WARN_MSG_V(msg, ...) \
67 g_print("** WARN: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
69 #define NVGSTDS_LINK_ELEMENT(elem1, elem2) \
71 if (!gst_element_link (elem1,elem2)) { \
72 GstCaps *src_caps, *sink_caps; \
73 src_caps = gst_pad_query_caps ((GstPad *) (elem1)->srcpads->data, NULL); \
74 sink_caps = gst_pad_query_caps ((GstPad *) (elem2)->sinkpads->data, NULL); \
75 NVGSTDS_ERR_MSG_V ("Failed to link '%s' (%s) and '%s' (%s)", \
76 GST_ELEMENT_NAME (elem1), \
77 gst_caps_to_string (src_caps), \
78 GST_ELEMENT_NAME (elem2), \
79 gst_caps_to_string (sink_caps)); \
84 #define NVGSTDS_LINK_ELEMENT_FULL(elem1, elem1_pad_name, elem2, elem2_pad_name) \
86 GstPad *elem1_pad = gst_element_get_static_pad(elem1, elem1_pad_name); \
87 GstPad *elem2_pad = gst_element_get_static_pad(elem2, elem2_pad_name); \
88 GstPadLinkReturn ret = gst_pad_link (elem1_pad,elem2_pad); \
89 if (ret != GST_PAD_LINK_OK) { \
90 gchar *n1 = gst_pad_get_name (elem1_pad); \
91 gchar *n2 = gst_pad_get_name (elem2_pad); \
92 NVGSTDS_ERR_MSG_V ("Failed to link '%s' and '%s': %d", \
96 gst_object_unref (elem1_pad); \
97 gst_object_unref (elem2_pad); \
100 gst_object_unref (elem1_pad); \
101 gst_object_unref (elem2_pad); \
104 #define NVGSTDS_BIN_ADD_GHOST_PAD_NAMED(bin, elem, pad, ghost_pad_name) \
106 GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
108 NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
109 GST_ELEMENT_NAME(elem)); \
112 gst_element_add_pad (bin, gst_ghost_pad_new (ghost_pad_name, gstpad)); \
113 gst_object_unref (gstpad); \
116 #define NVGSTDS_BIN_ADD_GHOST_PAD(bin, elem, pad) \
117 NVGSTDS_BIN_ADD_GHOST_PAD_NAMED (bin, elem, pad, pad)
119 #define NVGSTDS_ELEM_ADD_PROBE(probe_id, elem, pad, probe_func, probe_type, probe_data) \
121 GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
123 NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
124 GST_ELEMENT_NAME(elem)); \
127 probe_id = gst_pad_add_probe(gstpad, (probe_type), probe_func, probe_data, NULL); \
128 gst_object_unref (gstpad); \
131 #define NVGSTDS_ELEM_REMOVE_PROBE(probe_id, elem, pad) \
133 if (probe_id == 0 || !elem) { \
136 GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
138 NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
139 GST_ELEMENT_NAME(elem)); \
142 gst_pad_remove_probe(gstpad, probe_id); \
143 gst_object_unref (gstpad); \
146 #define GET_FILE_PATH(path) ((path) + (((path) && strstr ((path), "file://")) ? 7 : 0))
206 str_replace (gchar * str,
const gchar * replace,
const gchar * replace_with);