18 #ifndef __NVGSTDS_COMMON_H__
19 #define __NVGSTDS_COMMON_H__
33 __attribute__((weak)) gchar *g_nvds_last_error_message = NULL;
42 formatted_msg = g_strdup_vprintf(msg, args);
46 g_print(
"** ERROR: <%s:%d>: %s\n", func, line, formatted_msg);
49 if (!g_nvds_last_error_message) {
51 gchar *colon_pos = strchr(formatted_msg,
':');
54 clean_msg = g_strstrip(g_strdup(colon_pos + 1));
55 g_nvds_last_error_message = clean_msg;
58 g_nvds_last_error_message = g_strdup(formatted_msg);
62 g_free(formatted_msg);
65 #define NVGSTDS_ERR_MSG_V(msg, ...) \
66 nvds_capture_error(__func__, __LINE__, msg, ##__VA_ARGS__)
68 #define NVGSTDS_INFO_MSG_V(msg, ...) \
69 g_print("** INFO: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
71 #define NVGSTDS_WARN_MSG_V(msg, ...) \
72 g_print("** WARN: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
74 #define NVGSTDS_LINK_ELEMENT(elem1, elem2) \
76 if (!gst_element_link (elem1,elem2)) { \
77 GstCaps *src_caps, *sink_caps; \
78 src_caps = gst_pad_query_caps ((GstPad *) (elem1)->srcpads->data, NULL); \
79 sink_caps = gst_pad_query_caps ((GstPad *) (elem2)->sinkpads->data, NULL); \
80 NVGSTDS_ERR_MSG_V ("Failed to link '%s' (%s) and '%s' (%s)", \
81 GST_ELEMENT_NAME (elem1), \
82 gst_caps_to_string (src_caps), \
83 GST_ELEMENT_NAME (elem2), \
84 gst_caps_to_string (sink_caps)); \
89 #define NVGSTDS_LINK_ELEMENT_FULL(elem1, elem1_pad_name, elem2, elem2_pad_name) \
91 GstPad *elem1_pad = gst_element_get_static_pad(elem1, elem1_pad_name); \
92 GstPad *elem2_pad = gst_element_get_static_pad(elem2, elem2_pad_name); \
93 GstPadLinkReturn ret = gst_pad_link (elem1_pad,elem2_pad); \
94 if (ret != GST_PAD_LINK_OK) { \
95 gchar *n1 = gst_pad_get_name (elem1_pad); \
96 gchar *n2 = gst_pad_get_name (elem2_pad); \
97 NVGSTDS_ERR_MSG_V ("Failed to link '%s' and '%s': %d", \
101 gst_object_unref (elem1_pad); \
102 gst_object_unref (elem2_pad); \
105 gst_object_unref (elem1_pad); \
106 gst_object_unref (elem2_pad); \
109 #define NVGSTDS_BIN_ADD_GHOST_PAD_NAMED(bin, elem, pad, ghost_pad_name) \
111 GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
113 NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
114 GST_ELEMENT_NAME(elem)); \
117 gst_element_add_pad (bin, gst_ghost_pad_new (ghost_pad_name, gstpad)); \
118 gst_object_unref (gstpad); \
121 #define NVGSTDS_BIN_ADD_GHOST_PAD(bin, elem, pad) \
122 NVGSTDS_BIN_ADD_GHOST_PAD_NAMED (bin, elem, pad, pad)
124 #define NVGSTDS_ELEM_ADD_PROBE(probe_id, elem, pad, probe_func, probe_type, probe_data) \
126 GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
128 NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
129 GST_ELEMENT_NAME(elem)); \
132 probe_id = gst_pad_add_probe(gstpad, (probe_type), probe_func, probe_data, NULL); \
133 gst_object_unref (gstpad); \
136 #define NVGSTDS_ELEM_REMOVE_PROBE(probe_id, elem, pad) \
138 if (probe_id == 0 || !elem) { \
141 GstPad *gstpad = gst_element_get_static_pad (elem, pad); \
143 NVGSTDS_ERR_MSG_V ("Could not find '%s' in '%s'", pad, \
144 GST_ELEMENT_NAME(elem)); \
147 gst_pad_remove_probe(gstpad, probe_id); \
148 gst_object_unref (gstpad); \
151 #define GET_FILE_PATH(path) ((path) + (((path) && strstr ((path), "file://")) ? 7 : 0))
211 str_replace (gchar * str,
const gchar * replace,
const gchar * replace_with);