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"
55 GstCaps* in_caps, GstCaps* othercaps);
121 GstCaps* in_caps, GstCaps* othercaps)
123 GstCaps* result = NULL;
124 GstStructure *s1, *s2;
125 gint width = 0, height = 0;
126 gint num = 0, denom = 0;
127 const gchar *inputFmt = NULL;
129 GST_INFO_OBJECT (
m_element,
"\n----------\ndirection = %d (1=Src, 2=Sink) -> %s:\nCAPS = %s\n",
130 direction, __func__, gst_caps_to_string(in_caps));
131 GST_INFO_OBJECT (
m_element,
"%s : OTHERCAPS = %s\n", __func__, gst_caps_to_string(othercaps));
134 GST_INFO_OBJECT (nvdsvideotemplate,
"%s : CAPS = %" GST_PTR_FORMAT
"\n\n", __func__, in_caps);
135 GST_INFO_OBJECT (nvdsvideotemplate,
"%s : OTHER CAPS = %" GST_PTR_FORMAT
"\n\n", __func__, othercaps);
138 othercaps = gst_caps_truncate(othercaps);
139 othercaps = gst_caps_make_writable(othercaps);
144 s1 = gst_caps_get_structure(in_caps, 0);
145 s2 = gst_caps_get_structure(othercaps, 0);
147 inputFmt = gst_structure_get_string (s1,
"format");
148 gst_structure_get_int (s1,
"width", &width);
149 gst_structure_get_int (s1,
"height", &height);
152 g_print (
"InputFMT = %s \n\n", inputFmt);
158 gst_structure_fixate_field_nearest_int(s2,
"width", width);
159 gst_structure_fixate_field_nearest_int(s2,
"height", height);
160 if (gst_structure_get_fraction(s1,
"framerate", &num, &denom))
162 gst_structure_fixate_field_nearest_fraction(s2,
"framerate", num, denom);
165 gst_structure_remove_fields (s2,
"width",
"height",
"format", NULL);
169 gst_structure_set (s2,
"width", G_TYPE_INT, width,
170 "height", G_TYPE_INT, height,
171 "format", G_TYPE_STRING,
"NV12",
174 result = gst_caps_ref(othercaps);
177 gst_caps_unref(othercaps);
179 GST_INFO_OBJECT (
m_element,
"%s : Updated OTHERCAPS = %s \n\n", __func__, gst_caps_to_string(othercaps));
181 GST_INFO_OBJECT (nvdsvideotemplate,
"%s : CAPS = %" GST_PTR_FORMAT
"\n\n", __func__, othercaps);
182 GST_INFO_OBJECT(nvdsvideotemplate,
"CAPS fixate: %" GST_PTR_FORMAT
", direction %d",
191 GstBufferPool *m_buf_pool= NULL;
192 GstStructure *config = NULL;
196 config = gst_buffer_pool_get_config (m_buf_pool);
198 GST_INFO_OBJECT (m_element,
"in videoconvert caps = %" GST_PTR_FORMAT
"\n", outcaps);
201 gst_structure_set (config,
203 "gpu-id", G_TYPE_UINT, pool_config->
gpu_id,
204 "batch-size", G_TYPE_UINT, pool_config->
batch_size, NULL);
206 GST_INFO_OBJECT (m_element,
" %s Allocating Buffers in NVM Buffer Pool for Max_Views=%d\n",
210 if (!gst_buffer_pool_set_config (m_buf_pool, config)) {
211 GST_WARNING (
"bufferpool configuration failed");
215 gboolean is_active = gst_buffer_pool_set_active (m_buf_pool, TRUE);
217 GST_WARNING (
" Failed to allocate the buffers inside the output pool");
220 GST_DEBUG (
" Output buffer pool (%p) successfully created with %d buffers",
229 GstMapInfo in_map_info = GST_MAP_INFO_INIT;
233 if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
234 GST_ELEMENT_ERROR (
m_element, STREAM, FAILED,
235 (
"%s:gst buffer map to get pointer to NvBufSurface failed", __func__), (NULL));
242 gst_buffer_unmap(inbuf, &in_map_info);
243 return nvbuf_surface;