41 #define DBG (!self->silent)
44 #define silent_debug_timestamp(self, buf) do { \
46 GST_DEBUG_OBJECT (self, "pts = %" GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_PTS (buf))); \
47 GST_DEBUG_OBJECT (self, "dts = %" GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_DTS (buf))); \
48 GST_DEBUG_OBJECT (self, "duration = %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); \
53 #define GST_CAT_DEFAULT gst_tensor_sink_debug
80 #define DEFAULT_EMIT_SIGNAL TRUE
85 #define DEFAULT_SIGNAL_RATE 0
90 #define DEFAULT_SILENT TRUE
97 #define DEFAULT_QOS TRUE
104 #define DEFAULT_SYNC FALSE
113 const GValue * value, GParamSpec * pspec);
115 GValue * value, GParamSpec * pspec);
124 GstBufferList * buffer_list);
140 #define gst_tensor_sink_parent_class parent_class
149 GObjectClass *gobject_class;
150 GstElementClass *element_class;
151 GstBaseSinkClass *bsink_class;
152 GstPadTemplate *pad_template;
155 GST_DEBUG_CATEGORY_INIT (gst_tensor_sink_debug,
"tensor_sink", 0,
156 "Sink element to handle tensor stream");
158 gobject_class = G_OBJECT_CLASS (klass);
159 element_class = GST_ELEMENT_CLASS (klass);
160 bsink_class = GST_BASE_SINK_CLASS (klass);
178 g_param_spec_uint (
"signal-rate",
"Signal rate",
179 "New data signals per second (0 for unlimited, max 500)", 0, 500,
188 g_param_spec_boolean (
"emit-signal",
"Emit signal",
190 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197 g_object_class_install_property (gobject_class,
PROP_SILENT,
198 g_param_spec_boolean (
"silent",
"Silent",
"Produce verbose output",
207 g_signal_new (
"new-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
209 G_TYPE_NONE, 1, GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
218 g_signal_new (
"stream-start", G_TYPE_FROM_CLASS (klass),
220 NULL, NULL, NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
229 g_signal_new (
"eos", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
231 G_TYPE_NONE, 0, G_TYPE_NONE);
233 gst_element_class_set_static_metadata (element_class,
236 "Sink element to handle tensor stream",
"Samsung Electronics Co., Ltd.");
241 pad_template = gst_pad_template_new (
"sink", GST_PAD_SINK, GST_PAD_ALWAYS,
243 gst_element_class_add_pad_template (element_class, pad_template);
244 gst_caps_unref (pad_caps);
261 bsink = GST_BASE_SINK (
self);
263 g_mutex_init (&self->mutex);
269 self->last_render_time = GST_CLOCK_TIME_NONE;
272 gst_base_sink_set_qos_enabled (bsink,
DEFAULT_QOS);
285 const GValue * value, GParamSpec * pspec)
305 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
317 GValue * value, GParamSpec * pspec)
337 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
354 g_mutex_clear (&self->mutex);
356 G_OBJECT_CLASS (parent_class)->finalize (
object);
371 type = GST_EVENT_TYPE (event);
373 GST_DEBUG_OBJECT (
self,
"Received %s event: %" GST_PTR_FORMAT,
374 GST_EVENT_TYPE_NAME (event), event);
377 case GST_EVENT_STREAM_START:
397 return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
413 type = GST_QUERY_TYPE (query);
415 GST_DEBUG_OBJECT (
self,
"Received %s query: %" GST_PTR_FORMAT,
416 GST_QUERY_TYPE_NAME (query), query);
419 case GST_QUERY_SEEKING:
421 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
422 gst_query_set_seeking (query, format,
FALSE, 0, -1);
429 return GST_BASE_SINK_CLASS (parent_class)->query (sink, query);
462 num_buffers = gst_buffer_list_length (buffer_list);
464 for (i = 0; i < num_buffers; i++) {
465 buffer = gst_buffer_list_get (buffer_list, i);
481 GstClockTime now = GST_CLOCK_TIME_NONE;
483 gboolean notify =
FALSE;
491 GstClockTime render_time;
492 GstClockTime last_render_time;
494 clock = gst_element_get_clock (GST_ELEMENT (
self));
497 now = gst_clock_get_time (clock);
501 render_time = (1000 / signal_rate) * GST_MSECOND + last_render_time;
503 if (!GST_CLOCK_TIME_IS_VALID (last_render_time) ||
504 GST_CLOCK_DIFF (now, render_time) <= 0) {
509 gst_object_unref (clock);
521 "Emit signal for new data [%" GST_TIME_FORMAT
"] rate [%d]",
522 GST_TIME_ARGS (now), signal_rate);
539 g_mutex_lock (&self->mutex);
540 self->last_render_time = now;
541 g_mutex_unlock (&self->mutex);
550 GstClockTime last_render_time;
554 g_mutex_lock (&self->mutex);
555 last_render_time =
self->last_render_time;
556 g_mutex_unlock (&self->mutex);
558 return last_render_time;
569 GST_INFO_OBJECT (
self,
"set signal_rate to %d", rate);
570 g_mutex_lock (&self->mutex);
571 self->signal_rate = rate;
572 g_mutex_unlock (&self->mutex);
585 g_mutex_lock (&self->mutex);
586 rate =
self->signal_rate;
587 g_mutex_unlock (&self->mutex);
600 GST_INFO_OBJECT (
self,
"set emit_signal to %d", emit);
601 g_mutex_lock (&self->mutex);
602 self->emit_signal = emit;
603 g_mutex_unlock (&self->mutex);
616 g_mutex_lock (&self->mutex);
617 res =
self->emit_signal;
618 g_mutex_unlock (&self->mutex);
631 GST_INFO_OBJECT (
self,
"set silent to %d", silent);
632 self->silent = silent;