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.
24 * SECTION:element-identity
26 * Dummy element that passes incoming data through unmodified. It has some
27 * useful diagnostic functions, such as offset and timestamp checking.
37 #include "../../gst/gst-i18n-lib.h"
38 #include "gstidentity.h"
40 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
45 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
50 GST_DEBUG_CATEGORY_STATIC (gst_identity_debug);
51 #define GST_CAT_DEFAULT gst_identity_debug
53 /* Identity signals and args */
61 #define DEFAULT_SLEEP_TIME 0
62 #define DEFAULT_DUPLICATE 1
63 #define DEFAULT_ERROR_AFTER -1
64 #define DEFAULT_DROP_PROBABILITY 0.0
65 #define DEFAULT_DATARATE 0
66 #define DEFAULT_SILENT TRUE
67 #define DEFAULT_SINGLE_SEGMENT FALSE
68 #define DEFAULT_DUMP FALSE
69 #define DEFAULT_SYNC FALSE
70 #define DEFAULT_CHECK_IMPERFECT_TIMESTAMP FALSE
71 #define DEFAULT_CHECK_IMPERFECT_OFFSET FALSE
72 #define DEFAULT_SIGNAL_HANDOFFS TRUE
79 PROP_DROP_PROBABILITY,
86 PROP_CHECK_IMPERFECT_TIMESTAMP,
87 PROP_CHECK_IMPERFECT_OFFSET,
93 GST_DEBUG_CATEGORY_INIT (gst_identity_debug, "identity", 0, "identity element");
94 #define gst_identity_parent_class parent_class
95 G_DEFINE_TYPE_WITH_CODE (GstIdentity, gst_identity, GST_TYPE_BASE_TRANSFORM,
98 static void gst_identity_finalize (GObject * object);
99 static void gst_identity_set_property (GObject * object, guint prop_id,
100 const GValue * value, GParamSpec * pspec);
101 static void gst_identity_get_property (GObject * object, guint prop_id,
102 GValue * value, GParamSpec * pspec);
104 static gboolean gst_identity_sink_event (GstBaseTransform * trans,
106 static GstFlowReturn gst_identity_transform_ip (GstBaseTransform * trans,
108 static gboolean gst_identity_start (GstBaseTransform * trans);
109 static gboolean gst_identity_stop (GstBaseTransform * trans);
110 static GstStateChangeReturn gst_identity_change_state (GstElement * element,
111 GstStateChange transition);
113 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
115 static GParamSpec *pspec_last_message = NULL;
118 gst_identity_finalize (GObject * object)
120 GstIdentity *identity;
122 identity = GST_IDENTITY (object);
124 g_free (identity->last_message);
126 G_OBJECT_CLASS (parent_class)->finalize (object);
130 gst_identity_class_init (GstIdentityClass * klass)
132 GObjectClass *gobject_class;
133 GstElementClass *gstelement_class;
134 GstBaseTransformClass *gstbasetrans_class;
136 gobject_class = G_OBJECT_CLASS (klass);
137 gstelement_class = GST_ELEMENT_CLASS (klass);
138 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
140 gobject_class->set_property = gst_identity_set_property;
141 gobject_class->get_property = gst_identity_get_property;
143 g_object_class_install_property (gobject_class, PROP_SLEEP_TIME,
144 g_param_spec_uint ("sleep-time", "Sleep time",
145 "Microseconds to sleep between processing", 0, G_MAXUINT,
146 DEFAULT_SLEEP_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
147 g_object_class_install_property (gobject_class, PROP_ERROR_AFTER,
148 g_param_spec_int ("error-after", "Error After", "Error after N buffers",
149 G_MININT, G_MAXINT, DEFAULT_ERROR_AFTER,
150 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
151 g_object_class_install_property (gobject_class, PROP_DROP_PROBABILITY,
152 g_param_spec_float ("drop-probability", "Drop Probability",
153 "The Probability a buffer is dropped", 0.0, 1.0,
154 DEFAULT_DROP_PROBABILITY,
155 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
156 g_object_class_install_property (gobject_class, PROP_DATARATE,
157 g_param_spec_int ("datarate", "Datarate",
158 "(Re)timestamps buffers with number of bytes per second (0 = inactive)",
159 0, G_MAXINT, DEFAULT_DATARATE,
160 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
161 g_object_class_install_property (gobject_class, PROP_SILENT,
162 g_param_spec_boolean ("silent", "silent", "silent", DEFAULT_SILENT,
163 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164 g_object_class_install_property (gobject_class, PROP_SINGLE_SEGMENT,
165 g_param_spec_boolean ("single-segment", "Single Segment",
166 "Timestamp buffers and eat segments so as to appear as one segment",
167 DEFAULT_SINGLE_SEGMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
168 pspec_last_message = g_param_spec_string ("last-message", "last-message",
169 "last-message", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
170 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
172 g_object_class_install_property (gobject_class, PROP_DUMP,
173 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents to stdout",
174 DEFAULT_DUMP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
175 g_object_class_install_property (gobject_class, PROP_SYNC,
176 g_param_spec_boolean ("sync", "Synchronize",
177 "Synchronize to pipeline clock", DEFAULT_SYNC,
178 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
179 g_object_class_install_property (gobject_class,
180 PROP_CHECK_IMPERFECT_TIMESTAMP,
181 g_param_spec_boolean ("check-imperfect-timestamp",
182 "Check for discontiguous timestamps",
183 "Send element messages if timestamps and durations do not match up",
184 DEFAULT_CHECK_IMPERFECT_TIMESTAMP,
185 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
186 g_object_class_install_property (gobject_class, PROP_CHECK_IMPERFECT_OFFSET,
187 g_param_spec_boolean ("check-imperfect-offset",
188 "Check for discontiguous offset",
189 "Send element messages if offset and offset_end do not match up",
190 DEFAULT_CHECK_IMPERFECT_OFFSET,
191 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
194 * GstIdentity:signal-handoffs
196 * If set to #TRUE, the identity will emit a handoff signal when handling a buffer.
197 * When set to #FALSE, no signal will be emited, which might improve performance.
201 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
202 g_param_spec_boolean ("signal-handoffs",
203 "Signal handoffs", "Send a signal before pushing the buffer",
204 DEFAULT_SIGNAL_HANDOFFS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207 * GstIdentity::handoff:
208 * @identity: the identity instance
209 * @buffer: the buffer that just has been received
210 * @pad: the pad that received it
212 * This signal gets emitted before passing the buffer downstream.
214 gst_identity_signals[SIGNAL_HANDOFF] =
215 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
216 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
217 g_cclosure_marshal_generic, G_TYPE_NONE, 1,
218 GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
220 gobject_class->finalize = gst_identity_finalize;
222 gst_element_class_set_static_metadata (gstelement_class,
225 "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>");
226 gst_element_class_add_pad_template (gstelement_class,
227 gst_static_pad_template_get (&srctemplate));
228 gst_element_class_add_pad_template (gstelement_class,
229 gst_static_pad_template_get (&sinktemplate));
231 gstelement_class->change_state =
232 GST_DEBUG_FUNCPTR (gst_identity_change_state);
234 gstbasetrans_class->sink_event = GST_DEBUG_FUNCPTR (gst_identity_sink_event);
235 gstbasetrans_class->transform_ip =
236 GST_DEBUG_FUNCPTR (gst_identity_transform_ip);
237 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_identity_start);
238 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_identity_stop);
242 gst_identity_init (GstIdentity * identity)
244 identity->sleep_time = DEFAULT_SLEEP_TIME;
245 identity->error_after = DEFAULT_ERROR_AFTER;
246 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
247 identity->datarate = DEFAULT_DATARATE;
248 identity->silent = DEFAULT_SILENT;
249 identity->single_segment = DEFAULT_SINGLE_SEGMENT;
250 identity->sync = DEFAULT_SYNC;
251 identity->check_imperfect_timestamp = DEFAULT_CHECK_IMPERFECT_TIMESTAMP;
252 identity->check_imperfect_offset = DEFAULT_CHECK_IMPERFECT_OFFSET;
253 identity->dump = DEFAULT_DUMP;
254 identity->last_message = NULL;
255 identity->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
257 gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE);
261 gst_identity_notify_last_message (GstIdentity * identity)
263 g_object_notify_by_pspec ((GObject *) identity, pspec_last_message);
267 gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event)
269 GstIdentity *identity;
272 identity = GST_IDENTITY (trans);
274 if (!identity->silent) {
275 const GstStructure *s;
279 GST_OBJECT_LOCK (identity);
280 g_free (identity->last_message);
282 tstr = gst_event_type_get_name (GST_EVENT_TYPE (event));
283 if ((s = gst_event_get_structure (event)))
284 sstr = gst_structure_to_string (s);
286 sstr = g_strdup ("");
288 identity->last_message =
289 g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p",
290 GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event),
293 GST_OBJECT_UNLOCK (identity);
295 gst_identity_notify_last_message (identity);
298 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
299 if (trans->have_segment == FALSE) {
303 gst_event_copy_segment (event, &segment);
304 gst_event_copy_segment (event, &trans->segment);
305 trans->have_segment = TRUE;
307 /* This is the first segment, send out a (0, -1) segment */
308 gst_segment_init (&segment, segment.format);
309 news = gst_event_new_segment (&segment);
311 gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news);
315 /* Reset previous timestamp, duration and offsets on NEWSEGMENT
316 * to prevent false warnings when checking for perfect streams */
317 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
318 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
319 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
322 if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
323 /* eat up segments */
324 gst_event_unref (event);
327 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
328 GST_OBJECT_LOCK (identity);
329 if (identity->clock_id) {
330 GST_DEBUG_OBJECT (identity, "unlock clock wait");
331 gst_clock_id_unschedule (identity->clock_id);
332 gst_clock_id_unref (identity->clock_id);
333 identity->clock_id = NULL;
335 GST_OBJECT_UNLOCK (identity);
338 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
345 gst_identity_check_imperfect_timestamp (GstIdentity * identity, GstBuffer * buf)
347 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buf);
349 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
350 if (timestamp != GST_CLOCK_TIME_NONE) {
351 /* check if we had a previous buffer to compare to */
352 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
353 identity->prev_duration != GST_CLOCK_TIME_NONE) {
354 GstClockTime t_expected;
357 t_expected = identity->prev_timestamp + identity->prev_duration;
358 dt = GST_CLOCK_DIFF (t_expected, timestamp);
361 * "imperfect-timestamp" bus message:
362 * @identity: the identity instance
363 * @prev-timestamp: the previous buffer timestamp
364 * @prev-duration: the previous buffer duration
365 * @prev-offset: the previous buffer offset
366 * @prev-offset-end: the previous buffer offset end
367 * @cur-timestamp: the current buffer timestamp
368 * @cur-duration: the current buffer duration
369 * @cur-offset: the current buffer offset
370 * @cur-offset-end: the current buffer offset end
372 * This bus message gets emitted if the check-imperfect-timestamp
373 * property is set and there is a gap in time between the
374 * last buffer and the newly received buffer.
376 gst_element_post_message (GST_ELEMENT (identity),
377 gst_message_new_element (GST_OBJECT (identity),
378 gst_structure_new ("imperfect-timestamp",
379 "prev-timestamp", G_TYPE_UINT64,
380 identity->prev_timestamp, "prev-duration", G_TYPE_UINT64,
381 identity->prev_duration, "prev-offset", G_TYPE_UINT64,
382 identity->prev_offset, "prev-offset-end", G_TYPE_UINT64,
383 identity->prev_offset_end, "cur-timestamp", G_TYPE_UINT64,
384 timestamp, "cur-duration", G_TYPE_UINT64,
385 GST_BUFFER_DURATION (buf), "cur-offset", G_TYPE_UINT64,
386 GST_BUFFER_OFFSET (buf), "cur-offset-end", G_TYPE_UINT64,
387 GST_BUFFER_OFFSET_END (buf), NULL)));
390 GST_DEBUG_OBJECT (identity, "can't check data-contiguity, no "
391 "offset_end was set on previous buffer");
397 gst_identity_check_imperfect_offset (GstIdentity * identity, GstBuffer * buf)
401 offset = GST_BUFFER_OFFSET (buf);
403 if (identity->prev_offset_end != offset &&
404 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
405 offset != GST_BUFFER_OFFSET_NONE) {
407 * "imperfect-offset" bus message:
408 * @identity: the identity instance
409 * @prev-timestamp: the previous buffer timestamp
410 * @prev-duration: the previous buffer duration
411 * @prev-offset: the previous buffer offset
412 * @prev-offset-end: the previous buffer offset end
413 * @cur-timestamp: the current buffer timestamp
414 * @cur-duration: the current buffer duration
415 * @cur-offset: the current buffer offset
416 * @cur-offset-end: the current buffer offset end
418 * This bus message gets emitted if the check-imperfect-offset
419 * property is set and there is a gap in offsets between the
420 * last buffer and the newly received buffer.
422 gst_element_post_message (GST_ELEMENT (identity),
423 gst_message_new_element (GST_OBJECT (identity),
424 gst_structure_new ("imperfect-offset", "prev-timestamp",
425 G_TYPE_UINT64, identity->prev_timestamp, "prev-duration",
426 G_TYPE_UINT64, identity->prev_duration, "prev-offset",
427 G_TYPE_UINT64, identity->prev_offset, "prev-offset-end",
428 G_TYPE_UINT64, identity->prev_offset_end, "cur-timestamp",
429 G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (buf), "cur-duration",
430 G_TYPE_UINT64, GST_BUFFER_DURATION (buf), "cur-offset",
431 G_TYPE_UINT64, GST_BUFFER_OFFSET (buf), "cur-offset-end",
432 G_TYPE_UINT64, GST_BUFFER_OFFSET_END (buf), NULL)));
434 GST_DEBUG_OBJECT (identity, "can't check offset contiguity, no offset "
435 "and/or offset_end were set on previous buffer");
440 print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts)
442 if (ts == GST_CLOCK_TIME_NONE)
445 g_snprintf (ts_str, ts_str_len, "%" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
450 gst_identity_update_last_message_for_buffer (GstIdentity * identity,
451 const gchar * action, GstBuffer * buf, gsize size)
453 gchar dts_str[64], pts_str[64], dur_str[64];
456 GST_OBJECT_LOCK (identity);
459 const char *flag_list[15] = {
460 "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
461 "marker", "header", "gap", "droppable", "delta-unit", "in-caps"
464 char *end = flag_str;
466 for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
467 if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
468 strcpy (end, flag_list[i]);
477 g_free (identity->last_message);
478 identity->last_message = g_strdup_printf ("%s ******* (%s:%s) "
479 "(%" G_GSIZE_FORMAT " bytes, dts: %s, pts:%s, duration: %s, offset: %"
480 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT
481 ", flags: %d %s) %p", action,
482 GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), size,
483 print_pretty_time (dts_str, sizeof (dts_str), GST_BUFFER_DTS (buf)),
484 print_pretty_time (pts_str, sizeof (pts_str), GST_BUFFER_PTS (buf)),
485 print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)),
486 GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
487 GST_BUFFER_FLAGS (buf), flag_str, buf);
489 GST_OBJECT_UNLOCK (identity);
491 gst_identity_notify_last_message (identity);
495 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
497 GstFlowReturn ret = GST_FLOW_OK;
498 GstIdentity *identity = GST_IDENTITY (trans);
499 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
502 size = gst_buffer_get_size (buf);
504 if (identity->check_imperfect_timestamp)
505 gst_identity_check_imperfect_timestamp (identity, buf);
506 if (identity->check_imperfect_offset)
507 gst_identity_check_imperfect_offset (identity, buf);
509 /* update prev values */
510 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
511 identity->prev_duration = GST_BUFFER_DURATION (buf);
512 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
513 identity->prev_offset = GST_BUFFER_OFFSET (buf);
515 if (identity->error_after >= 0) {
516 identity->error_after--;
517 if (identity->error_after == 0)
521 if (identity->drop_probability > 0.0) {
522 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
526 if (identity->dump) {
529 gst_buffer_map (buf, &info, GST_MAP_READ);
530 gst_util_dump_mem (info.data, info.size);
531 gst_buffer_unmap (buf, &info);
534 if (!identity->silent) {
535 gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
538 if (identity->datarate > 0) {
539 GstClockTime time = gst_util_uint64_scale_int (identity->offset,
540 GST_SECOND, identity->datarate);
542 GST_BUFFER_TIMESTAMP (buf) = time;
543 GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
546 if (identity->signal_handoffs)
547 g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
549 if (trans->segment.format == GST_FORMAT_TIME)
550 runtimestamp = gst_segment_to_running_time (&trans->segment,
551 GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
553 if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
556 GST_OBJECT_LOCK (identity);
557 if ((clock = GST_ELEMENT (identity)->clock)) {
559 GstClockTime timestamp;
561 timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
563 /* save id if we need to unlock */
564 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
565 GST_OBJECT_UNLOCK (identity);
567 cret = gst_clock_id_wait (identity->clock_id, NULL);
569 GST_OBJECT_LOCK (identity);
570 if (identity->clock_id) {
571 gst_clock_id_unref (identity->clock_id);
572 identity->clock_id = NULL;
574 if (cret == GST_CLOCK_UNSCHEDULED)
577 GST_OBJECT_UNLOCK (identity);
580 identity->offset += size;
582 if (identity->sleep_time && ret == GST_FLOW_OK)
583 g_usleep (identity->sleep_time);
585 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
586 && (ret == GST_FLOW_OK)) {
587 GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
588 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
589 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
597 GST_ELEMENT_ERROR (identity, CORE, FAILED,
598 (_("Failed after iterations as requested.")), (NULL));
599 return GST_FLOW_ERROR;
603 if (!identity->silent) {
604 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
607 /* return DROPPED to basetransform. */
608 return GST_BASE_TRANSFORM_FLOW_DROPPED;
613 gst_identity_set_property (GObject * object, guint prop_id,
614 const GValue * value, GParamSpec * pspec)
616 GstIdentity *identity;
618 identity = GST_IDENTITY (object);
621 case PROP_SLEEP_TIME:
622 identity->sleep_time = g_value_get_uint (value);
625 identity->silent = g_value_get_boolean (value);
627 case PROP_SINGLE_SEGMENT:
628 identity->single_segment = g_value_get_boolean (value);
631 identity->dump = g_value_get_boolean (value);
633 case PROP_ERROR_AFTER:
634 identity->error_after = g_value_get_int (value);
636 case PROP_DROP_PROBABILITY:
637 identity->drop_probability = g_value_get_float (value);
640 identity->datarate = g_value_get_int (value);
643 identity->sync = g_value_get_boolean (value);
645 case PROP_CHECK_IMPERFECT_TIMESTAMP:
646 identity->check_imperfect_timestamp = g_value_get_boolean (value);
648 case PROP_CHECK_IMPERFECT_OFFSET:
649 identity->check_imperfect_offset = g_value_get_boolean (value);
651 case PROP_SIGNAL_HANDOFFS:
652 identity->signal_handoffs = g_value_get_boolean (value);
655 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
658 if (identity->datarate > 0 || identity->single_segment)
659 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), FALSE);
661 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), TRUE);
665 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
668 GstIdentity *identity;
670 identity = GST_IDENTITY (object);
673 case PROP_SLEEP_TIME:
674 g_value_set_uint (value, identity->sleep_time);
676 case PROP_ERROR_AFTER:
677 g_value_set_int (value, identity->error_after);
679 case PROP_DROP_PROBABILITY:
680 g_value_set_float (value, identity->drop_probability);
683 g_value_set_int (value, identity->datarate);
686 g_value_set_boolean (value, identity->silent);
688 case PROP_SINGLE_SEGMENT:
689 g_value_set_boolean (value, identity->single_segment);
692 g_value_set_boolean (value, identity->dump);
694 case PROP_LAST_MESSAGE:
695 GST_OBJECT_LOCK (identity);
696 g_value_set_string (value, identity->last_message);
697 GST_OBJECT_UNLOCK (identity);
700 g_value_set_boolean (value, identity->sync);
702 case PROP_CHECK_IMPERFECT_TIMESTAMP:
703 g_value_set_boolean (value, identity->check_imperfect_timestamp);
705 case PROP_CHECK_IMPERFECT_OFFSET:
706 g_value_set_boolean (value, identity->check_imperfect_offset);
708 case PROP_SIGNAL_HANDOFFS:
709 g_value_set_boolean (value, identity->signal_handoffs);
712 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
718 gst_identity_start (GstBaseTransform * trans)
720 GstIdentity *identity;
722 identity = GST_IDENTITY (trans);
724 identity->offset = 0;
725 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
726 identity->prev_duration = GST_CLOCK_TIME_NONE;
727 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
728 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
734 gst_identity_stop (GstBaseTransform * trans)
736 GstIdentity *identity;
738 identity = GST_IDENTITY (trans);
740 GST_OBJECT_LOCK (identity);
741 g_free (identity->last_message);
742 identity->last_message = NULL;
743 GST_OBJECT_UNLOCK (identity);
748 static GstStateChangeReturn
749 gst_identity_change_state (GstElement * element, GstStateChange transition)
751 GstStateChangeReturn ret;
752 GstIdentity *identity = GST_IDENTITY (element);
754 switch (transition) {
755 case GST_STATE_CHANGE_NULL_TO_READY:
757 case GST_STATE_CHANGE_READY_TO_PAUSED:
759 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
761 case GST_STATE_CHANGE_PAUSED_TO_READY:
762 GST_OBJECT_LOCK (identity);
763 if (identity->clock_id) {
764 GST_DEBUG_OBJECT (identity, "unlock clock wait");
765 gst_clock_id_unschedule (identity->clock_id);
766 gst_clock_id_unref (identity->clock_id);
767 identity->clock_id = NULL;
769 GST_OBJECT_UNLOCK (identity);
775 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
777 switch (transition) {
778 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
780 case GST_STATE_CHANGE_PAUSED_TO_READY:
782 case GST_STATE_CHANGE_READY_TO_NULL: