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);
234 g_return_val_if_fail (event != NULL,
FALSE);
236 switch (GST_EVENT_TYPE (event)) {
242 gst_event_parse_caps (event, &caps);
246 gst_event_unref (event);
253 return gst_pad_event_default (pad, parent, event);
265 caps = gst_pad_get_current_caps (pad);
268 caps = gst_pad_get_pad_template_caps (pad);
275 GstCaps *intersection;
277 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
279 gst_caps_unref (caps);
298 GST_DEBUG_OBJECT (
self,
"Received %s query: %" GST_PTR_FORMAT,
299 GST_QUERY_TYPE_NAME (query), query);
301 switch (GST_QUERY_TYPE (query)) {
307 gst_query_parse_caps (query, &filter);
311 gst_query_set_caps_result (query, caps);
312 gst_caps_unref (caps);
315 case GST_QUERY_ACCEPT_CAPS:
318 GstCaps *template_caps;
319 gboolean res =
FALSE;
321 gst_query_parse_accept_caps (query, &caps);
324 if (gst_caps_is_fixed (caps)) {
325 template_caps = gst_pad_get_pad_template_caps (pad);
327 res = gst_caps_can_intersect (template_caps, caps);
328 gst_caps_unref (template_caps);
331 gst_query_set_accept_caps_result (query, res);
338 return gst_pad_query_default (pad, parent, query);
348 GstFlowReturn ret = GST_FLOW_OK;
350 GstMemory *in_mem, *out_mem;
358 info = &
self->in_config.
info;
360 outbuf = gst_buffer_new ();
374 gst_memory_unref (in_mem);
377 nns_loge (
"failed to convert to sparse tensor");
378 ret = GST_FLOW_ERROR;
385 ret = gst_pad_push (self->srcpad, outbuf);
388 gst_buffer_unref (buf);
389 if (ret != GST_FLOW_OK)
390 gst_buffer_unref (outbuf);