45 #define DBG (!self->silent)
49 #define GST_CAT_DEFAULT gst_tensor_sparse_dec_debug
63 #define DEFAULT_SILENT TRUE
68 static GstStaticPadTemplate
sink_template = GST_STATIC_PAD_TEMPLATE (
"sink",
76 static GstStaticPadTemplate
src_template = GST_STATIC_PAD_TEMPLATE (
"src",
81 #define gst_tensor_sparse_dec_parent_class parent_class
86 const GValue * value, GParamSpec * pspec);
88 GValue * value, GParamSpec * pspec);
95 GstObject * parent, GstQuery * query);
103 GObjectClass *object_class;
104 GstElementClass *element_class;
106 GST_DEBUG_CATEGORY_INIT (gst_tensor_sparse_dec_debug,
"tensor_sparse_dec", 0,
107 "Element to decode 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,
127 gst_element_class_add_pad_template (element_class,
130 gst_element_class_set_static_metadata (element_class,
133 "Element to decode dense tensors into sparse tensors",
134 "Samsung Electronics Co., Ltd.");
144 self->sinkpad = gst_pad_new_from_static_template (&
sink_template,
"sink");
145 gst_element_add_pad (GST_ELEMENT (
self), self->sinkpad);
148 self->srcpad = gst_pad_new_from_static_template (&
src_template,
"src");
149 gst_element_add_pad (GST_ELEMENT (
self), self->srcpad);
152 gst_pad_set_chain_function (self->sinkpad,
156 gst_pad_set_event_function (self->sinkpad,
159 gst_pad_set_query_function (self->sinkpad,
180 G_OBJECT_CLASS (parent_class)->finalize (
object);
188 const GValue * value, GParamSpec * pspec)
196 self->silent = g_value_get_boolean (value);
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
209 GValue * value, GParamSpec * pspec)
217 g_value_set_boolean (value, self->silent);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
234 caps = gst_pad_get_current_caps (pad);
237 caps = gst_pad_get_pad_template_caps (pad);
244 GstCaps *intersection;
246 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
248 gst_caps_unref (caps);
266 GST_DEBUG_OBJECT (
self,
"Received %s query: %" GST_PTR_FORMAT,
267 GST_QUERY_TYPE_NAME (query), query);
269 switch (GST_QUERY_TYPE (query)) {
275 gst_query_parse_caps (query, &filter);
279 gst_query_set_caps_result (query, caps);
280 gst_caps_unref (caps);
283 case GST_QUERY_ACCEPT_CAPS:
286 GstCaps *template_caps;
287 gboolean res =
FALSE;
289 gst_query_parse_accept_caps (query, &caps);
292 if (gst_caps_is_fixed (caps)) {
293 template_caps = gst_pad_get_pad_template_caps (pad);
295 res = gst_caps_can_intersect (template_caps, caps);
296 gst_caps_unref (template_caps);
299 gst_query_set_accept_caps_result (query, res);
306 return gst_pad_query_default (pad, parent, query);
318 g_return_val_if_fail (event != NULL,
FALSE);
320 switch (GST_EVENT_TYPE (event)) {
323 GstCaps *caps, *out_caps;
324 GstStructure *structure;
326 gst_event_parse_caps (event, &caps);
330 structure = gst_caps_get_structure (caps, 0);
335 self->out_config.rate_n =
self->in_config.rate_n;
336 self->out_config.rate_d =
self->in_config.rate_d;
342 gst_pad_set_caps (self->srcpad, out_caps);
343 gst_caps_unref (out_caps);
345 gst_event_unref (event);
352 return gst_pad_event_default (pad, parent, event);
361 GstFlowReturn ret = GST_FLOW_ERROR;
364 GstMemory *in_mem, *out_mem;
373 outbuf = gst_buffer_new ();
381 gst_memory_unref (in_mem);
384 nns_loge (
"failed to convert to dense tensor");
398 gst_buffer_unref (outbuf);
404 ret = gst_pad_push (self->srcpad, outbuf);
407 gst_buffer_unref (buf);
408 if (ret != GST_FLOW_OK)
409 gst_buffer_unref (outbuf);