18 #ifndef __NVDSCUSTOMLIB_BASE_HPP__
19 #define __NVDSCUSTOMLIB_BASE_HPP__
21 #include <gst/base/gstbasetransform.h>
22 #include <gst/video/video.h>
24 #include "gstnvdsbufferpool.h"
26 #include <nvbufsurface.h>
59 GstCaps* in_caps, GstCaps* othercaps);
125 GstCaps* in_caps, GstCaps* othercaps)
127 GstCaps* result = NULL;
128 GstStructure *s1, *s2;
129 gint
width = 0, height = 0;
130 gint num = 0, denom = 0;
131 const gchar *inputFmt = NULL;
133 GST_INFO_OBJECT (
m_element,
"\n----------\ndirection = %d (1=Src, 2=Sink) -> %s:\nCAPS = %s\n",
134 direction, __func__, gst_caps_to_string(in_caps));
135 GST_INFO_OBJECT (
m_element,
"%s : OTHERCAPS = %s\n", __func__, gst_caps_to_string(othercaps));
138 GST_INFO_OBJECT (nvdsvideotemplate,
"%s : CAPS = %" GST_PTR_FORMAT
"\n\n", __func__, in_caps);
139 GST_INFO_OBJECT (nvdsvideotemplate,
"%s : OTHER CAPS = %" GST_PTR_FORMAT
"\n\n", __func__, othercaps);
142 othercaps = gst_caps_truncate(othercaps);
143 othercaps = gst_caps_make_writable(othercaps);
148 s1 = gst_caps_get_structure(in_caps, 0);
149 s2 = gst_caps_get_structure(othercaps, 0);
151 inputFmt = gst_structure_get_string (s1,
"format");
152 gst_structure_get_int (s1,
"width", &
width);
153 gst_structure_get_int (s1,
"height", &height);
156 g_print (
"InputFMT = %s \n\n", inputFmt);
162 gst_structure_fixate_field_nearest_int(s2,
"width",
width);
163 gst_structure_fixate_field_nearest_int(s2,
"height", height);
164 if (gst_structure_get_fraction(s1,
"framerate", &num, &denom))
166 gst_structure_fixate_field_nearest_fraction(s2,
"framerate", num, denom);
169 gst_structure_remove_fields (s2,
"width",
"height",
"format", NULL);
173 gst_structure_set (s2,
"width", G_TYPE_INT,
width,
174 "height", G_TYPE_INT, height,
175 "format", G_TYPE_STRING,
"NV12",
178 result = gst_caps_ref(othercaps);
181 gst_caps_unref(othercaps);
183 GST_INFO_OBJECT (
m_element,
"%s : Updated OTHERCAPS = %s \n\n", __func__, gst_caps_to_string(othercaps));
185 GST_INFO_OBJECT (nvdsvideotemplate,
"%s : CAPS = %" GST_PTR_FORMAT
"\n\n", __func__, othercaps);
186 GST_INFO_OBJECT(nvdsvideotemplate,
"CAPS fixate: %" GST_PTR_FORMAT
", direction %d",
195 GstBufferPool *m_buf_pool= NULL;
196 GstStructure *config = NULL;
200 config = gst_buffer_pool_get_config (m_buf_pool);
202 GST_INFO_OBJECT (m_element,
"in videoconvert caps = %" GST_PTR_FORMAT
"\n", outcaps);
205 gst_structure_set (config,
207 "gpu-id", G_TYPE_UINT, pool_config->
gpu_id,
208 "batch-size", G_TYPE_UINT, pool_config->
batch_size, NULL);
210 GST_INFO_OBJECT (m_element,
" %s Allocating Buffers in NVM Buffer Pool for Max_Views=%d\n",
214 if (!gst_buffer_pool_set_config (m_buf_pool, config)) {
215 GST_WARNING (
"bufferpool configuration failed");
219 gboolean is_active = gst_buffer_pool_set_active (m_buf_pool,
TRUE);
221 GST_WARNING (
" Failed to allocate the buffers inside the output pool");
224 GST_DEBUG (
" Output buffer pool (%p) successfully created with %d buffers",
233 GstMapInfo in_map_info = GST_MAP_INFO_INIT;
237 if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
238 GST_ELEMENT_ERROR (
m_element, STREAM, FAILED,
239 (
"%s:gst buffer map to get pointer to NvBufSurface failed", __func__), (NULL));
246 gst_buffer_unmap(inbuf, &in_map_info);
247 return nvbuf_surface;