2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
31 #include "../gst-i18n-lib.h"
32 #include "gstidentity.h"
33 #include <gst/gstmarshal.h>
35 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
40 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
45 GST_DEBUG_CATEGORY_STATIC (gst_identity_debug);
46 #define GST_CAT_DEFAULT gst_identity_debug
48 GstElementDetails gst_identity_details = GST_ELEMENT_DETAILS ("Identity",
50 "Pass data without modification",
51 "Erik Walthinsen <omega@cse.ogi.edu>");
54 /* Identity signals and args */
62 #define DEFAULT_LOOP_BASED FALSE
63 #define DEFAULT_SLEEP_TIME 0
64 #define DEFAULT_DUPLICATE 1
65 #define DEFAULT_ERROR_AFTER -1
66 #define DEFAULT_DROP_PROBABILITY 0.0
67 #define DEFAULT_DATARATE 0
68 #define DEFAULT_SILENT FALSE
69 #define DEFAULT_DUMP FALSE
70 #define DEFAULT_SYNC FALSE
71 #define DEFAULT_CHECK_PERFECT FALSE
84 PROP_DROP_PROBABILITY,
94 typedef GstFlowReturn (*IdentityPushFunc) (GstIdentity *, GstBuffer *);
97 #define _do_init(bla) \
98 GST_DEBUG_CATEGORY_INIT (gst_identity_debug, "identity", 0, "identity element");
100 GST_BOILERPLATE_FULL (GstIdentity, gst_identity, GstElement, GST_TYPE_ELEMENT,
103 static void gst_identity_finalize (GObject * object);
104 static void gst_identity_set_property (GObject * object, guint prop_id,
105 const GValue * value, GParamSpec * pspec);
106 static void gst_identity_get_property (GObject * object, guint prop_id,
107 GValue * value, GParamSpec * pspec);
108 static GstElementStateReturn gst_identity_change_state (GstElement * element);
110 static gboolean gst_identity_event (GstPad * pad, GstEvent * event);
111 static GstFlowReturn gst_identity_getrange (GstPad * pad, guint64 offset,
112 guint length, GstBuffer ** buffer);
113 static GstFlowReturn gst_identity_chain (GstPad * pad, GstBuffer * buffer);
114 static void gst_identity_src_loop (GstPad * pad);
115 static void gst_identity_sink_loop (GstPad * pad);
116 static GstFlowReturn gst_identity_handle_buffer (GstIdentity * identity,
118 static void gst_identity_set_clock (GstElement * element, GstClock * clock);
119 static GstCaps *gst_identity_proxy_getcaps (GstPad * pad);
122 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
125 gst_identity_base_init (gpointer g_class)
127 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
129 gst_element_class_add_pad_template (gstelement_class,
130 gst_static_pad_template_get (&srctemplate));
131 gst_element_class_add_pad_template (gstelement_class,
132 gst_static_pad_template_get (&sinktemplate));
133 gst_element_class_set_details (gstelement_class, &gst_identity_details);
137 gst_identity_finalize (GObject * object)
139 GstIdentity *identity;
141 identity = GST_IDENTITY (object);
143 g_mutex_free (identity->pen_lock);
144 g_cond_free (identity->pen_cond);
146 g_free (identity->last_message);
148 G_OBJECT_CLASS (parent_class)->finalize (object);
152 gst_identity_class_init (GstIdentityClass * klass)
154 GObjectClass *gobject_class;
155 GstElementClass *gstelement_class;
157 gobject_class = G_OBJECT_CLASS (klass);
158 gstelement_class = GST_ELEMENT_CLASS (klass);
160 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_identity_set_property);
161 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_identity_get_property);
163 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_GETRANGE,
164 g_param_spec_boolean ("has-getrange", "Has getrange",
165 "If the src pad will implement a getrange function",
166 TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
167 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_CHAIN,
168 g_param_spec_boolean ("has-chain", "Has chain",
169 "If the sink pad will implement a chain function",
170 TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
171 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_SRC_LOOP,
172 g_param_spec_boolean ("has-src-loop", "Has src loop",
173 "If the src pad will implement a loop function",
174 FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
175 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_SINK_LOOP,
176 g_param_spec_boolean ("has-sink-loop", "Has sink loop",
177 "If the sink pad will implement a loop function",
178 FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
179 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SLEEP_TIME,
180 g_param_spec_uint ("sleep-time", "Sleep time",
181 "Microseconds to sleep between processing", 0, G_MAXUINT,
182 DEFAULT_SLEEP_TIME, G_PARAM_READWRITE));
183 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DUPLICATE,
184 g_param_spec_uint ("duplicate", "Duplicate Buffers",
185 "Push the buffers N times", 0, G_MAXUINT, DEFAULT_DUPLICATE,
187 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ERROR_AFTER,
188 g_param_spec_int ("error_after", "Error After", "Error after N buffers",
189 G_MININT, G_MAXINT, DEFAULT_ERROR_AFTER, G_PARAM_READWRITE));
190 g_object_class_install_property (G_OBJECT_CLASS (klass),
191 PROP_DROP_PROBABILITY, g_param_spec_float ("drop_probability",
192 "Drop Probability", "The Probability a buffer is dropped", 0.0, 1.0,
193 DEFAULT_DROP_PROBABILITY, G_PARAM_READWRITE));
194 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DATARATE,
195 g_param_spec_int ("datarate", "Datarate",
196 "(Re)timestamps buffers with number of bytes per second (0 = inactive)",
197 0, G_MAXINT, DEFAULT_DATARATE, G_PARAM_READWRITE));
198 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SILENT,
199 g_param_spec_boolean ("silent", "silent", "silent", DEFAULT_SILENT,
201 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LAST_MESSAGE,
202 g_param_spec_string ("last-message", "last-message", "last-message", NULL,
204 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DUMP,
205 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents",
206 DEFAULT_DUMP, G_PARAM_READWRITE));
207 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SYNC,
208 g_param_spec_boolean ("sync", "Synchronize",
209 "Synchronize to pipeline clock", DEFAULT_SYNC, G_PARAM_READWRITE));
210 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CHECK_PERFECT,
211 g_param_spec_boolean ("check-perfect", "Check For Perfect Stream",
212 "Verify that the stream is time- and data-contiguous",
213 DEFAULT_CHECK_PERFECT, G_PARAM_READWRITE));
215 gst_identity_signals[SIGNAL_HANDOFF] =
216 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
217 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
218 gst_marshal_VOID__BOXED, G_TYPE_NONE, 1,
219 GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
221 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_identity_finalize);
223 gstelement_class->set_clock = GST_DEBUG_FUNCPTR (gst_identity_set_clock);
224 gstelement_class->change_state =
225 GST_DEBUG_FUNCPTR (gst_identity_change_state);
230 gst_identity_init (GstIdentity * identity)
233 gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate),
235 gst_element_add_pad (GST_ELEMENT (identity), identity->sinkpad);
236 gst_pad_set_getcaps_function (identity->sinkpad,
237 GST_DEBUG_FUNCPTR (gst_identity_proxy_getcaps));
238 gst_pad_set_event_function (identity->sinkpad,
239 GST_DEBUG_FUNCPTR (gst_identity_event));
242 gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate),
244 gst_pad_set_getcaps_function (identity->srcpad,
245 GST_DEBUG_FUNCPTR (gst_identity_proxy_getcaps));
246 gst_pad_set_getrange_function (identity->srcpad,
247 GST_DEBUG_FUNCPTR (gst_identity_getrange));
248 gst_element_add_pad (GST_ELEMENT (identity), identity->srcpad);
250 identity->sleep_time = DEFAULT_SLEEP_TIME;
251 identity->duplicate = DEFAULT_DUPLICATE;
252 identity->error_after = DEFAULT_ERROR_AFTER;
253 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
254 identity->datarate = DEFAULT_DATARATE;
255 identity->silent = DEFAULT_SILENT;
256 identity->sync = DEFAULT_SYNC;
257 identity->check_perfect = DEFAULT_CHECK_PERFECT;
258 identity->dump = DEFAULT_DUMP;
259 identity->last_message = NULL;
260 identity->srccaps = NULL;
262 identity->pen_data = NULL;
263 identity->pen_lock = g_mutex_new ();
264 identity->pen_cond = g_cond_new ();
265 identity->pen_flushing = FALSE;
269 gst_identity_set_clock (GstElement * element, GstClock * clock)
271 GstIdentity *identity = GST_IDENTITY (element);
273 gst_object_replace ((GstObject **) & identity->clock, (GstObject *) clock);
277 gst_identity_proxy_getcaps (GstPad * pad)
280 GstIdentity *identity = GST_IDENTITY (GST_OBJECT_PARENT (pad));
282 otherpad = pad == identity->srcpad ? identity->sinkpad : identity->srcpad;
284 return gst_pad_peer_get_caps (otherpad);
288 identity_queue_push (GstIdentity * identity, GstData * data)
292 g_mutex_lock (identity->pen_lock);
293 while (identity->pen_data && !identity->pen_flushing)
294 g_cond_wait (identity->pen_cond, identity->pen_lock);
295 if (identity->pen_flushing) {
296 gst_data_unref (identity->pen_data);
297 identity->pen_data = NULL;
298 gst_data_unref (data);
301 identity->pen_data = data;
304 g_cond_signal (identity->pen_cond);
305 g_mutex_unlock (identity->pen_lock);
311 identity_queue_pop (GstIdentity * identity)
315 g_mutex_lock (identity->pen_lock);
316 while (!(ret = identity->pen_data) && !identity->pen_flushing)
317 g_cond_wait (identity->pen_cond, identity->pen_lock);
318 g_cond_signal (identity->pen_cond);
319 g_mutex_unlock (identity->pen_lock);
325 identity_queue_flush (GstIdentity * identity)
327 g_mutex_lock (identity->pen_lock);
328 identity->pen_flushing = TRUE;
329 g_cond_signal (identity->pen_cond);
330 g_mutex_unlock (identity->pen_lock);
334 gst_identity_event (GstPad * pad, GstEvent * event)
336 GstIdentity *identity;
339 identity = GST_IDENTITY (GST_PAD_PARENT (pad));
341 GST_STREAM_LOCK (pad);
343 if (!identity->silent) {
344 g_free (identity->last_message);
346 identity->last_message =
347 g_strdup_printf ("chain ******* (%s:%s)E (type: %d) %p",
348 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE (event), event);
350 g_object_notify (G_OBJECT (identity), "last_message");
353 switch (GST_EVENT_TYPE (event)) {
354 case GST_EVENT_FLUSH:
356 gst_pad_event_default (pad, event);
357 if (GST_EVENT_FLUSH_DONE (event)) {
358 if (identity->sink_mode == GST_ACTIVATE_PULL) {
359 /* already have the sink stream lock */
360 gst_task_start (GST_RPAD_TASK (identity->sinkpad));
362 if (identity->src_mode == GST_ACTIVATE_PUSH) {
363 GST_STREAM_LOCK (identity->srcpad);
364 gst_task_start (GST_RPAD_TASK (identity->srcpad));
365 GST_STREAM_UNLOCK (identity->srcpad);
368 /* unblock both functions */
369 identity_queue_flush (identity);
375 if (identity->sink_mode == GST_ACTIVATE_PULL) {
376 /* already have the sink stream lock */
377 gst_task_pause (GST_RPAD_TASK (identity->sinkpad));
384 if (identity->decoupled) {
385 ret = identity_queue_push (identity, (GstData *) event);
387 ret = gst_pad_push_event (identity->srcpad, event);
391 GST_STREAM_UNLOCK (pad);
396 gst_identity_getrange (GstPad * pad, guint64 offset,
397 guint length, GstBuffer ** buffer)
399 GstIdentity *identity;
402 identity = GST_IDENTITY (GST_PAD_PARENT (pad));
404 GST_STREAM_LOCK (pad);
406 ret = gst_pad_pull_range (identity->sinkpad, offset, length, buffer);
408 GST_STREAM_UNLOCK (pad);
414 gst_identity_chain (GstPad * pad, GstBuffer * buffer)
416 GstIdentity *identity;
417 GstFlowReturn ret = GST_FLOW_OK;
419 identity = GST_IDENTITY (GST_PAD_PARENT (pad));
421 GST_STREAM_LOCK (pad);
423 ret = gst_identity_handle_buffer (identity, buffer);
425 GST_STREAM_UNLOCK (pad);
430 #define DEFAULT_PULL_SIZE 1024
433 gst_identity_sink_loop (GstPad * pad)
435 GstIdentity *identity;
439 identity = GST_IDENTITY (GST_PAD_PARENT (pad));
441 GST_STREAM_LOCK (pad);
443 ret = gst_pad_pull_range (pad, identity->offset, DEFAULT_PULL_SIZE, &buffer);
444 if (ret != GST_FLOW_OK)
445 goto sink_loop_pause;
447 ret = gst_identity_handle_buffer (identity, buffer);
448 if (ret != GST_FLOW_OK)
449 goto sink_loop_pause;
451 GST_STREAM_UNLOCK (pad);
455 gst_task_pause (GST_RPAD_TASK (identity->sinkpad));
456 GST_STREAM_UNLOCK (pad);
461 gst_identity_src_loop (GstPad * pad)
463 GstIdentity *identity;
467 identity = GST_IDENTITY (GST_PAD_PARENT (pad));
469 GST_STREAM_LOCK (pad);
471 data = identity_queue_pop (identity);
472 if (!data) /* we're getting flushed */
475 if (GST_IS_EVENT (data)) {
476 if (GST_EVENT_TYPE (data) == GST_EVENT_EOS)
477 gst_task_pause (GST_RPAD_TASK (identity->srcpad));
478 gst_pad_push_event (identity->srcpad, GST_EVENT (data));
480 ret = gst_pad_push (identity->srcpad, (GstBuffer *) data);
481 if (ret != GST_FLOW_OK)
485 GST_STREAM_UNLOCK (pad);
489 gst_task_pause (GST_RPAD_TASK (identity->srcpad));
490 GST_STREAM_UNLOCK (pad);
495 gst_identity_handle_buffer (GstIdentity * identity, GstBuffer * buf)
497 GstFlowReturn ret = GST_FLOW_OK;
500 /* see if we need to do perfect stream checking */
501 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
502 if (identity->check_perfect &&
503 GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
504 /* check if we had a previous buffer to compare to */
505 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE) {
506 if (identity->prev_timestamp + identity->prev_duration !=
507 GST_BUFFER_TIMESTAMP (buf)) {
508 GST_WARNING_OBJECT (identity,
509 "Buffer not time-contiguous with previous one: " "prev ts %"
510 GST_TIME_FORMAT ", prev dur %" GST_TIME_FORMAT ", new ts %"
511 GST_TIME_FORMAT, GST_TIME_ARGS (identity->prev_timestamp),
512 GST_TIME_ARGS (identity->prev_duration),
513 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
515 if (identity->prev_offset_end != GST_BUFFER_OFFSET (buf)) {
516 GST_WARNING_OBJECT (identity,
517 "Buffer not data-contiguous with previous one: "
518 "prev offset_end %" G_GINT64_FORMAT ", new offset %"
519 G_GINT64_FORMAT, identity->prev_offset_end,
520 GST_BUFFER_OFFSET (buf));
523 /* update prev values */
524 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
525 identity->prev_duration = GST_BUFFER_DURATION (buf);
526 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
529 if (identity->error_after >= 0) {
530 identity->error_after--;
531 if (identity->error_after == 0) {
532 gst_buffer_unref (buf);
533 GST_ELEMENT_ERROR (identity, CORE, FAILED,
534 (_("Failed after iterations as requested.")), (NULL));
535 return GST_FLOW_ERROR;
539 if (identity->drop_probability > 0.0) {
540 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) {
541 g_free (identity->last_message);
542 identity->last_message =
543 g_strdup_printf ("dropping ******* (%s:%s)i (%d bytes, timestamp: %"
544 GST_TIME_FORMAT ", duration: %" GST_TIME_FORMAT ", offset: %"
545 G_GINT64_FORMAT ", offset_end: % " G_GINT64_FORMAT ", flags: %d) %p",
546 GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf),
547 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
548 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf),
549 GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf);
550 g_object_notify (G_OBJECT (identity), "last-message");
551 gst_buffer_unref (buf);
556 if (identity->dump) {
557 gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
560 for (i = identity->duplicate; i; i--) {
563 if (!identity->silent) {
564 g_free (identity->last_message);
565 identity->last_message =
566 g_strdup_printf ("chain ******* (%s:%s)i (%d bytes, timestamp: %"
567 GST_TIME_FORMAT ", duration: %" GST_TIME_FORMAT ", offset: %"
568 G_GINT64_FORMAT ", offset_end: % " G_GINT64_FORMAT ", flags: %d) %p",
569 GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf),
570 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
571 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf),
572 GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf);
573 g_object_notify (G_OBJECT (identity), "last-message");
576 time = GST_BUFFER_TIMESTAMP (buf);
578 if (identity->datarate > 0) {
579 time = identity->offset * GST_SECOND / identity->datarate;
581 GST_BUFFER_TIMESTAMP (buf) = time;
582 GST_BUFFER_DURATION (buf) =
583 GST_BUFFER_SIZE (buf) * GST_SECOND / identity->datarate;
586 g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
590 gst_buffer_ref (buf);
592 if (identity->sync) {
593 if (identity->clock) {
594 /* gst_element_wait (GST_ELEMENT (identity), time); */
598 identity->offset += GST_BUFFER_SIZE (buf);
599 if (identity->decoupled) {
600 if (!identity_queue_push (identity, (GstData *) buf))
601 return GST_FLOW_UNEXPECTED;
603 ret = gst_pad_push (identity->srcpad, buf);
604 if (ret != GST_FLOW_OK)
608 if (identity->sleep_time)
609 g_usleep (identity->sleep_time);
616 gst_identity_set_dataflow_funcs (GstIdentity * identity)
618 if (identity->has_getrange)
619 gst_pad_set_getrange_function (identity->srcpad, gst_identity_getrange);
621 gst_pad_set_getrange_function (identity->srcpad, NULL);
623 if (identity->has_chain)
624 gst_pad_set_chain_function (identity->sinkpad, gst_identity_chain);
626 gst_pad_set_chain_function (identity->sinkpad, NULL);
628 if (identity->has_src_loop)
629 gst_pad_set_loop_function (identity->srcpad, gst_identity_src_loop);
631 gst_pad_set_loop_function (identity->srcpad, NULL);
633 if (identity->has_sink_loop)
634 gst_pad_set_loop_function (identity->sinkpad, gst_identity_sink_loop);
636 gst_pad_set_loop_function (identity->sinkpad, NULL);
640 gst_identity_set_property (GObject * object, guint prop_id,
641 const GValue * value, GParamSpec * pspec)
643 GstIdentity *identity;
645 identity = GST_IDENTITY (object);
648 case PROP_HAS_GETRANGE:
649 identity->has_getrange = g_value_get_boolean (value);
650 gst_identity_set_dataflow_funcs (identity);
653 identity->has_chain = g_value_get_boolean (value);
654 gst_identity_set_dataflow_funcs (identity);
656 case PROP_HAS_SRC_LOOP:
657 identity->has_src_loop = g_value_get_boolean (value);
658 gst_identity_set_dataflow_funcs (identity);
660 case PROP_HAS_SINK_LOOP:
661 identity->has_sink_loop = g_value_get_boolean (value);
662 gst_identity_set_dataflow_funcs (identity);
664 case PROP_SLEEP_TIME:
665 identity->sleep_time = g_value_get_uint (value);
668 identity->silent = g_value_get_boolean (value);
671 identity->duplicate = g_value_get_uint (value);
674 identity->dump = g_value_get_boolean (value);
676 case PROP_ERROR_AFTER:
677 identity->error_after = g_value_get_int (value);
679 case PROP_DROP_PROBABILITY:
680 identity->drop_probability = g_value_get_float (value);
683 identity->datarate = g_value_get_int (value);
686 identity->sync = g_value_get_boolean (value);
688 case PROP_CHECK_PERFECT:
689 identity->check_perfect = g_value_get_boolean (value);
692 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
698 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
701 GstIdentity *identity;
703 identity = GST_IDENTITY (object);
706 case PROP_HAS_GETRANGE:
707 g_value_set_boolean (value, identity->has_getrange);
710 g_value_set_boolean (value, identity->has_chain);
712 case PROP_HAS_SRC_LOOP:
713 g_value_set_boolean (value, identity->has_src_loop);
715 case PROP_HAS_SINK_LOOP:
716 g_value_set_boolean (value, identity->has_sink_loop);
718 case PROP_SLEEP_TIME:
719 g_value_set_uint (value, identity->sleep_time);
722 g_value_set_uint (value, identity->duplicate);
724 case PROP_ERROR_AFTER:
725 g_value_set_int (value, identity->error_after);
727 case PROP_DROP_PROBABILITY:
728 g_value_set_float (value, identity->drop_probability);
731 g_value_set_int (value, identity->datarate);
734 g_value_set_boolean (value, identity->silent);
737 g_value_set_boolean (value, identity->dump);
739 case PROP_LAST_MESSAGE:
740 g_value_set_string (value, identity->last_message);
743 g_value_set_boolean (value, identity->sync);
745 case PROP_CHECK_PERFECT:
746 g_value_set_boolean (value, identity->check_perfect);
749 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
754 static GstElementStateReturn
755 gst_identity_change_state (GstElement * element)
757 GstIdentity *identity;
759 g_return_val_if_fail (GST_IS_IDENTITY (element), GST_STATE_FAILURE);
761 identity = GST_IDENTITY (element);
763 switch (GST_STATE_TRANSITION (element)) {
764 case GST_STATE_NULL_TO_READY:
766 case GST_STATE_READY_TO_PAUSED:
767 identity->offset = 0;
768 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
769 identity->prev_duration = GST_CLOCK_TIME_NONE;
770 identity->prev_offset_end = -1;
772 case GST_STATE_PAUSED_TO_PLAYING:
773 case GST_STATE_PLAYING_TO_PAUSED:
775 case GST_STATE_PAUSED_TO_READY:
776 g_free (identity->last_message);
777 identity->last_message = NULL;
779 case GST_STATE_READY_TO_NULL:
785 if (GST_ELEMENT_CLASS (parent_class)->change_state)
786 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
788 return GST_STATE_SUCCESS;