44 #define DBG (!self->silent)
48 #define GST_CAT_DEFAULT gst_tensor_sparse_enc_debug
62 #define DEFAULT_SILENT TRUE
67 static GstStaticPadTemplate
sink_template = GST_STATIC_PAD_TEMPLATE (
"sink",
75 static GstStaticPadTemplate
src_template = GST_STATIC_PAD_TEMPLATE (
"src",
80 #define gst_tensor_sparse_enc_parent_class parent_class
85 const GValue * value, GParamSpec * pspec);
87 GValue * value, GParamSpec * pspec);
91 GstPad * pad, GstCaps * filter);
93 GstObject * parent, GstEvent * event);
95 GstObject * parent, GstQuery * query);
103 GObjectClass *object_class;
104 GstElementClass *element_class;
106 GST_DEBUG_CATEGORY_INIT (gst_tensor_sparse_enc_debug,
"tensor_sparse_enc", 0,
107 "Element to encode sparse tensors");
109 object_class = (GObjectClass *) klass;
110 element_class = (GstElementClass *) klass;
121 g_object_class_install_property (object_class,
PROP_SILENT,
122 g_param_spec_boolean (
"silent",
"Silent",
"Produce verbose output",
125 gst_element_class_add_pad_template (element_class,
128 gst_element_class_add_pad_template (element_class,
131 gst_element_class_set_static_metadata (element_class,
134 "Element to encode dense tensors into sparse tensors",
135 "Samsung Electronics Co., Ltd.");
145 self->sinkpad = gst_pad_new_from_static_template (&
sink_template,
"sink");
146 gst_element_add_pad (GST_ELEMENT (
self), self->sinkpad);
149 self->srcpad = gst_pad_new_from_static_template (&
src_template,
"src");
150 gst_element_add_pad (GST_ELEMENT (
self), self->srcpad);
153 gst_pad_set_chain_function (self->sinkpad,
157 gst_pad_set_event_function (self->sinkpad,
160 gst_pad_set_query_function (self->sinkpad,
179 G_OBJECT_CLASS (parent_class)->finalize (
object);
187 const GValue * value, GParamSpec * pspec)
195 self->silent = g_value_get_boolean (value);
198 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
208 GValue * value, GParamSpec * pspec)
216 g_value_set_boolean (value, self->silent);
219 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
229 const GstCaps * caps)
231 GstStructure *structure;
234 g_return_val_if_fail (caps != NULL,
FALSE);
235 g_return_val_if_fail (gst_caps_is_fixed (caps),
FALSE);
237 structure = gst_caps_get_structure (caps, 0);
242 GST_ERROR_OBJECT (
self,
"Failed to configure tensors config.\n");
246 self->in_config = config;
260 g_return_val_if_fail (event != NULL,
FALSE);
262 switch (GST_EVENT_TYPE (event)) {
268 gst_event_parse_caps (event, &caps);
272 gst_event_unref (event);
279 return gst_pad_event_default (pad, parent, event);
291 caps = gst_pad_get_current_caps (pad);
294 caps = gst_pad_get_pad_template_caps (pad);
301 GstCaps *intersection;
303 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
305 gst_caps_unref (caps);
324 GST_DEBUG_OBJECT (
self,
"Received %s query: %" GST_PTR_FORMAT,
325 GST_QUERY_TYPE_NAME (query), query);
327 switch (GST_QUERY_TYPE (query)) {
333 gst_query_parse_caps (query, &filter);
337 gst_query_set_caps_result (query, caps);
338 gst_caps_unref (caps);
341 case GST_QUERY_ACCEPT_CAPS:
344 GstCaps *template_caps;
345 gboolean res =
FALSE;
347 gst_query_parse_accept_caps (query, &caps);
350 if (gst_caps_is_fixed (caps)) {
351 template_caps = gst_pad_get_pad_template_caps (pad);
353 res = gst_caps_can_intersect (template_caps, caps);
354 gst_caps_unref (template_caps);
357 gst_query_set_accept_caps_result (query, res);
364 return gst_pad_query_default (pad, parent, query);
374 GstFlowReturn ret = GST_FLOW_OK;
376 GstMemory *in_mem, *out_mem;
384 info = &
self->in_config.
info;
386 outbuf = gst_buffer_new ();
400 gst_memory_unref (in_mem);
403 nns_loge (
"failed to convert to sparse tensor");
404 ret = GST_FLOW_ERROR;
411 ret = gst_pad_push (self->srcpad, outbuf);
414 gst_buffer_unref (buf);
415 if (ret != GST_FLOW_OK)
416 gst_buffer_unref (outbuf);