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"
39 #include <gst/gstmarshal.h>
41 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
46 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
51 GST_DEBUG_CATEGORY_STATIC (gst_identity_debug);
52 #define GST_CAT_DEFAULT gst_identity_debug
54 /* Identity signals and args */
62 #define DEFAULT_SLEEP_TIME 0
63 #define DEFAULT_DUPLICATE 1
64 #define DEFAULT_ERROR_AFTER -1
65 #define DEFAULT_DROP_PROBABILITY 0.0
66 #define DEFAULT_DATARATE 0
67 #define DEFAULT_SILENT FALSE
68 #define DEFAULT_SINGLE_SEGMENT FALSE
69 #define DEFAULT_DUMP FALSE
70 #define DEFAULT_SYNC FALSE
71 #define DEFAULT_CHECK_PERFECT FALSE
72 #define DEFAULT_CHECK_IMPERFECT_TIMESTAMP FALSE
73 #define DEFAULT_CHECK_IMPERFECT_OFFSET FALSE
74 #define DEFAULT_SIGNAL_HANDOFFS TRUE
81 PROP_DROP_PROBABILITY,
89 PROP_CHECK_IMPERFECT_TIMESTAMP,
90 PROP_CHECK_IMPERFECT_OFFSET,
96 GST_DEBUG_CATEGORY_INIT (gst_identity_debug, "identity", 0, "identity element");
97 #define gst_identity_parent_class parent_class
98 G_DEFINE_TYPE_WITH_CODE (GstIdentity, gst_identity, GST_TYPE_BASE_TRANSFORM,
101 static void gst_identity_finalize (GObject * object);
102 static void gst_identity_set_property (GObject * object, guint prop_id,
103 const GValue * value, GParamSpec * pspec);
104 static void gst_identity_get_property (GObject * object, guint prop_id,
105 GValue * value, GParamSpec * pspec);
107 static gboolean gst_identity_sink_event (GstBaseTransform * trans,
109 static GstFlowReturn gst_identity_transform_ip (GstBaseTransform * trans,
111 static GstFlowReturn gst_identity_prepare_output_buffer (GstBaseTransform *
112 trans, GstBuffer * in_buf, GstBuffer ** out_buf);
113 static gboolean gst_identity_start (GstBaseTransform * trans);
114 static gboolean gst_identity_stop (GstBaseTransform * trans);
115 static GstStateChangeReturn gst_identity_change_state (GstElement * element,
116 GstStateChange transition);
118 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
120 static GParamSpec *pspec_last_message = NULL;
123 gst_identity_finalize (GObject * object)
125 GstIdentity *identity;
127 identity = GST_IDENTITY (object);
129 g_free (identity->last_message);
131 G_OBJECT_CLASS (parent_class)->finalize (object);
134 /* fixme: do something about this */
136 marshal_VOID__MINIOBJECT (GClosure * closure, GValue * return_value,
137 guint n_param_values, const GValue * param_values, gpointer invocation_hint,
138 gpointer marshal_data)
140 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1,
142 register marshalfunc_VOID__MINIOBJECT callback;
143 register GCClosure *cc = (GCClosure *) closure;
144 register gpointer data1, data2;
146 g_return_if_fail (n_param_values == 2);
148 if (G_CCLOSURE_SWAP_DATA (closure)) {
149 data1 = closure->data;
150 data2 = g_value_peek_pointer (param_values + 0);
152 data1 = g_value_peek_pointer (param_values + 0);
153 data2 = closure->data;
156 (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data :
159 callback (data1, g_value_get_boxed (param_values + 1), data2);
163 gst_identity_class_init (GstIdentityClass * klass)
165 GObjectClass *gobject_class;
166 GstElementClass *gstelement_class;
167 GstBaseTransformClass *gstbasetrans_class;
169 gobject_class = G_OBJECT_CLASS (klass);
170 gstelement_class = GST_ELEMENT_CLASS (klass);
171 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
173 gobject_class->set_property = gst_identity_set_property;
174 gobject_class->get_property = gst_identity_get_property;
176 g_object_class_install_property (gobject_class, PROP_SLEEP_TIME,
177 g_param_spec_uint ("sleep-time", "Sleep time",
178 "Microseconds to sleep between processing", 0, G_MAXUINT,
179 DEFAULT_SLEEP_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
180 g_object_class_install_property (gobject_class, PROP_ERROR_AFTER,
181 g_param_spec_int ("error-after", "Error After", "Error after N buffers",
182 G_MININT, G_MAXINT, DEFAULT_ERROR_AFTER,
183 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (gobject_class, PROP_DROP_PROBABILITY,
185 g_param_spec_float ("drop-probability", "Drop Probability",
186 "The Probability a buffer is dropped", 0.0, 1.0,
187 DEFAULT_DROP_PROBABILITY,
188 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
189 g_object_class_install_property (gobject_class, PROP_DATARATE,
190 g_param_spec_int ("datarate", "Datarate",
191 "(Re)timestamps buffers with number of bytes per second (0 = inactive)",
192 0, G_MAXINT, DEFAULT_DATARATE,
193 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
194 g_object_class_install_property (gobject_class, PROP_SILENT,
195 g_param_spec_boolean ("silent", "silent", "silent", DEFAULT_SILENT,
196 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197 g_object_class_install_property (gobject_class, PROP_SINGLE_SEGMENT,
198 g_param_spec_boolean ("single-segment", "Single Segment",
199 "Timestamp buffers and eat segments so as to appear as one segment",
200 DEFAULT_SINGLE_SEGMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
201 pspec_last_message = g_param_spec_string ("last-message", "last-message",
202 "last-message", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
203 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
205 g_object_class_install_property (gobject_class, PROP_DUMP,
206 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents to stdout",
207 DEFAULT_DUMP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
208 g_object_class_install_property (gobject_class, PROP_SYNC,
209 g_param_spec_boolean ("sync", "Synchronize",
210 "Synchronize to pipeline clock", DEFAULT_SYNC,
211 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
212 g_object_class_install_property (gobject_class, PROP_CHECK_PERFECT,
213 g_param_spec_boolean ("check-perfect", "Check For Perfect Stream",
214 "Verify that the stream is time- and data-contiguous. "
215 "This only logs in the debug log. This will be deprecated in favor "
216 "of the check-imperfect-timestamp/offset properties.",
217 DEFAULT_CHECK_PERFECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
218 g_object_class_install_property (gobject_class,
219 PROP_CHECK_IMPERFECT_TIMESTAMP,
220 g_param_spec_boolean ("check-imperfect-timestamp",
221 "Check for discontiguous timestamps",
222 "Send element messages if timestamps and durations do not match up",
223 DEFAULT_CHECK_IMPERFECT_TIMESTAMP,
224 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
225 g_object_class_install_property (gobject_class, PROP_CHECK_IMPERFECT_OFFSET,
226 g_param_spec_boolean ("check-imperfect-offset",
227 "Check for discontiguous offset",
228 "Send element messages if offset and offset_end do not match up",
229 DEFAULT_CHECK_IMPERFECT_OFFSET,
230 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
233 * GstIdentity:signal-handoffs
235 * If set to #TRUE, the identity will emit a handoff signal when handling a buffer.
236 * When set to #FALSE, no signal will be emited, which might improve performance.
240 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
241 g_param_spec_boolean ("signal-handoffs",
242 "Signal handoffs", "Send a signal before pushing the buffer",
243 DEFAULT_SIGNAL_HANDOFFS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
246 * GstIdentity::handoff:
247 * @identity: the identity instance
248 * @buffer: the buffer that just has been received
249 * @pad: the pad that received it
251 * This signal gets emitted before passing the buffer downstream.
253 gst_identity_signals[SIGNAL_HANDOFF] =
254 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
255 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
256 marshal_VOID__MINIOBJECT, G_TYPE_NONE, 1, GST_TYPE_BUFFER);
258 gobject_class->finalize = gst_identity_finalize;
260 gst_element_class_set_details_simple (gstelement_class,
263 "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>");
264 gst_element_class_add_pad_template (gstelement_class,
265 gst_static_pad_template_get (&srctemplate));
266 gst_element_class_add_pad_template (gstelement_class,
267 gst_static_pad_template_get (&sinktemplate));
269 gstelement_class->change_state =
270 GST_DEBUG_FUNCPTR (gst_identity_change_state);
271 gstbasetrans_class->sink_event = GST_DEBUG_FUNCPTR (gst_identity_sink_event);
272 gstbasetrans_class->transform_ip =
273 GST_DEBUG_FUNCPTR (gst_identity_transform_ip);
274 gstbasetrans_class->prepare_output_buffer =
275 GST_DEBUG_FUNCPTR (gst_identity_prepare_output_buffer);
276 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_identity_start);
277 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_identity_stop);
281 gst_identity_init (GstIdentity * identity)
283 identity->sleep_time = DEFAULT_SLEEP_TIME;
284 identity->error_after = DEFAULT_ERROR_AFTER;
285 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
286 identity->datarate = DEFAULT_DATARATE;
287 identity->silent = DEFAULT_SILENT;
288 identity->single_segment = DEFAULT_SINGLE_SEGMENT;
289 identity->sync = DEFAULT_SYNC;
290 identity->check_perfect = DEFAULT_CHECK_PERFECT;
291 identity->check_imperfect_timestamp = DEFAULT_CHECK_IMPERFECT_TIMESTAMP;
292 identity->check_imperfect_offset = DEFAULT_CHECK_IMPERFECT_OFFSET;
293 identity->dump = DEFAULT_DUMP;
294 identity->last_message = NULL;
295 identity->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
297 gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE);
301 gst_identity_notify_last_message (GstIdentity * identity)
303 g_object_notify_by_pspec ((GObject *) identity, pspec_last_message);
307 gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event)
309 GstIdentity *identity;
312 identity = GST_IDENTITY (trans);
314 if (!identity->silent) {
315 const GstStructure *s;
319 GST_OBJECT_LOCK (identity);
320 g_free (identity->last_message);
322 tstr = gst_event_type_get_name (GST_EVENT_TYPE (event));
323 if ((s = gst_event_get_structure (event)))
324 sstr = gst_structure_to_string (s);
326 sstr = g_strdup ("");
328 identity->last_message =
329 g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p",
330 GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event),
333 GST_OBJECT_UNLOCK (identity);
335 gst_identity_notify_last_message (identity);
338 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
339 if (trans->have_segment == FALSE) {
343 gst_event_copy_segment (event, &segment);
344 gst_event_copy_segment (event, &trans->segment);
345 trans->have_segment = TRUE;
347 /* This is the first segment, send out a (0, -1) segment */
348 gst_segment_init (&segment, segment.format);
349 news = gst_event_new_segment (&segment);
351 gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news);
355 /* Reset previous timestamp, duration and offsets on NEWSEGMENT
356 * to prevent false warnings when checking for perfect streams */
357 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
358 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
359 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
362 if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
363 /* eat up segments */
364 gst_event_unref (event);
367 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
368 GST_OBJECT_LOCK (identity);
369 if (identity->clock_id) {
370 GST_DEBUG_OBJECT (identity, "unlock clock wait");
371 gst_clock_id_unschedule (identity->clock_id);
372 gst_clock_id_unref (identity->clock_id);
373 identity->clock_id = NULL;
375 GST_OBJECT_UNLOCK (identity);
378 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
385 gst_identity_prepare_output_buffer (GstBaseTransform * trans,
386 GstBuffer * in_buf, GstBuffer ** out_buf)
388 GstIdentity *identity = GST_IDENTITY (trans);
390 /* only bother if we may have to alter metadata */
391 if (identity->datarate > 0 || identity->single_segment) {
392 if (gst_buffer_is_writable (in_buf))
397 *out_buf = gst_buffer_copy (in_buf);
406 gst_identity_check_perfect (GstIdentity * identity, GstBuffer * buf)
408 GstClockTime timestamp;
410 timestamp = GST_BUFFER_TIMESTAMP (buf);
412 /* see if we need to do perfect stream checking */
413 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
414 if (timestamp != GST_CLOCK_TIME_NONE) {
415 /* check if we had a previous buffer to compare to */
416 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
417 identity->prev_duration != GST_CLOCK_TIME_NONE) {
418 guint64 offset, t_expected;
421 t_expected = identity->prev_timestamp + identity->prev_duration;
422 dt = timestamp - t_expected;
424 GST_WARNING_OBJECT (identity,
425 "Buffer not time-contiguous with previous one: " "prev ts %"
426 GST_TIME_FORMAT ", prev dur %" GST_TIME_FORMAT ", new ts %"
427 GST_TIME_FORMAT " (expected ts %" GST_TIME_FORMAT ", delta=%c%"
428 GST_TIME_FORMAT ")", GST_TIME_ARGS (identity->prev_timestamp),
429 GST_TIME_ARGS (identity->prev_duration), GST_TIME_ARGS (timestamp),
430 GST_TIME_ARGS (t_expected), (dt < 0) ? '-' : '+',
431 GST_TIME_ARGS ((dt < 0) ? (GstClockTime) (-dt) : dt));
434 offset = GST_BUFFER_OFFSET (buf);
435 if (identity->prev_offset_end != offset &&
436 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
437 offset != GST_BUFFER_OFFSET_NONE) {
438 GST_WARNING_OBJECT (identity,
439 "Buffer not data-contiguous with previous one: "
440 "prev offset_end %" G_GINT64_FORMAT ", new offset %"
441 G_GINT64_FORMAT, identity->prev_offset_end, offset);
444 GST_DEBUG_OBJECT (identity, "can't check time-contiguity, no timestamp "
445 "and/or duration were set on previous buffer");
451 gst_identity_check_imperfect_timestamp (GstIdentity * identity, GstBuffer * buf)
453 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buf);
455 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
456 if (timestamp != GST_CLOCK_TIME_NONE) {
457 /* check if we had a previous buffer to compare to */
458 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
459 identity->prev_duration != GST_CLOCK_TIME_NONE) {
460 GstClockTime t_expected;
463 t_expected = identity->prev_timestamp + identity->prev_duration;
464 dt = GST_CLOCK_DIFF (t_expected, timestamp);
467 * "imperfect-timestamp" bus message:
468 * @identity: the identity instance
469 * @prev-timestamp: the previous buffer timestamp
470 * @prev-duration: the previous buffer duration
471 * @prev-offset: the previous buffer offset
472 * @prev-offset-end: the previous buffer offset end
473 * @cur-timestamp: the current buffer timestamp
474 * @cur-duration: the current buffer duration
475 * @cur-offset: the current buffer offset
476 * @cur-offset-end: the current buffer offset end
478 * This bus message gets emitted if the check-imperfect-timestamp
479 * property is set and there is a gap in time between the
480 * last buffer and the newly received buffer.
482 gst_element_post_message (GST_ELEMENT (identity),
483 gst_message_new_element (GST_OBJECT (identity),
484 gst_structure_new ("imperfect-timestamp",
485 "prev-timestamp", G_TYPE_UINT64,
486 identity->prev_timestamp, "prev-duration", G_TYPE_UINT64,
487 identity->prev_duration, "prev-offset", G_TYPE_UINT64,
488 identity->prev_offset, "prev-offset-end", G_TYPE_UINT64,
489 identity->prev_offset_end, "cur-timestamp", G_TYPE_UINT64,
490 timestamp, "cur-duration", G_TYPE_UINT64,
491 GST_BUFFER_DURATION (buf), "cur-offset", G_TYPE_UINT64,
492 GST_BUFFER_OFFSET (buf), "cur-offset-end", G_TYPE_UINT64,
493 GST_BUFFER_OFFSET_END (buf), NULL)));
496 GST_DEBUG_OBJECT (identity, "can't check data-contiguity, no "
497 "offset_end was set on previous buffer");
503 gst_identity_check_imperfect_offset (GstIdentity * identity, GstBuffer * buf)
507 offset = GST_BUFFER_OFFSET (buf);
509 if (identity->prev_offset_end != offset &&
510 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
511 offset != GST_BUFFER_OFFSET_NONE) {
513 * "imperfect-offset" bus message:
514 * @identity: the identity instance
515 * @prev-timestamp: the previous buffer timestamp
516 * @prev-duration: the previous buffer duration
517 * @prev-offset: the previous buffer offset
518 * @prev-offset-end: the previous buffer offset end
519 * @cur-timestamp: the current buffer timestamp
520 * @cur-duration: the current buffer duration
521 * @cur-offset: the current buffer offset
522 * @cur-offset-end: the current buffer offset end
524 * This bus message gets emitted if the check-imperfect-offset
525 * property is set and there is a gap in offsets between the
526 * last buffer and the newly received buffer.
528 gst_element_post_message (GST_ELEMENT (identity),
529 gst_message_new_element (GST_OBJECT (identity),
530 gst_structure_new ("imperfect-offset", "prev-timestamp",
531 G_TYPE_UINT64, identity->prev_timestamp, "prev-duration",
532 G_TYPE_UINT64, identity->prev_duration, "prev-offset",
533 G_TYPE_UINT64, identity->prev_offset, "prev-offset-end",
534 G_TYPE_UINT64, identity->prev_offset_end, "cur-timestamp",
535 G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (buf), "cur-duration",
536 G_TYPE_UINT64, GST_BUFFER_DURATION (buf), "cur-offset",
537 G_TYPE_UINT64, GST_BUFFER_OFFSET (buf), "cur-offset-end",
538 G_TYPE_UINT64, GST_BUFFER_OFFSET_END (buf), NULL)));
540 GST_DEBUG_OBJECT (identity, "can't check offset contiguity, no offset "
541 "and/or offset_end were set on previous buffer");
546 print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts)
548 if (ts == GST_CLOCK_TIME_NONE)
551 g_snprintf (ts_str, ts_str_len, "%" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
556 gst_identity_update_last_message_for_buffer (GstIdentity * identity,
557 const gchar * action, GstBuffer * buf, gsize size)
559 gchar ts_str[64], dur_str[64];
562 GST_OBJECT_LOCK (identity);
565 const char *flag_list[15] = {
566 "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
567 "marker", "header", "gap", "droppable", "delta-unit", "in-caps"
570 char *end = flag_str;
572 for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
573 if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
574 strcpy (end, flag_list[i]);
583 g_free (identity->last_message);
584 identity->last_message = g_strdup_printf ("%s ******* (%s:%s) "
585 "(%" G_GSIZE_FORMAT " bytes, timestamp: %s, duration: %s, offset: %"
586 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT
587 ", flags: %d %s) %p", action,
588 GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), size,
589 print_pretty_time (ts_str, sizeof (ts_str), GST_BUFFER_TIMESTAMP (buf)),
590 print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)),
591 GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
592 GST_BUFFER_FLAGS (buf), flag_str, buf);
594 GST_OBJECT_UNLOCK (identity);
596 gst_identity_notify_last_message (identity);
600 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
602 GstFlowReturn ret = GST_FLOW_OK;
603 GstIdentity *identity = GST_IDENTITY (trans);
604 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
607 gst_buffer_map (buf, &info, GST_MAP_READ);
609 if (identity->check_perfect)
610 gst_identity_check_perfect (identity, buf);
611 if (identity->check_imperfect_timestamp)
612 gst_identity_check_imperfect_timestamp (identity, buf);
613 if (identity->check_imperfect_offset)
614 gst_identity_check_imperfect_offset (identity, buf);
616 /* update prev values */
617 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
618 identity->prev_duration = GST_BUFFER_DURATION (buf);
619 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
620 identity->prev_offset = GST_BUFFER_OFFSET (buf);
622 if (identity->error_after >= 0) {
623 identity->error_after--;
624 if (identity->error_after == 0)
628 if (identity->drop_probability > 0.0) {
629 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
633 if (identity->dump) {
634 gst_util_dump_mem (info.data, info.size);
637 if (!identity->silent) {
638 gst_identity_update_last_message_for_buffer (identity, "chain", buf,
642 if (identity->datarate > 0) {
643 GstClockTime time = gst_util_uint64_scale_int (identity->offset,
644 GST_SECOND, identity->datarate);
646 GST_BUFFER_TIMESTAMP (buf) = time;
647 GST_BUFFER_DURATION (buf) = info.size * GST_SECOND / identity->datarate;
650 if (identity->signal_handoffs)
651 g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
653 if (trans->segment.format == GST_FORMAT_TIME)
654 runtimestamp = gst_segment_to_running_time (&trans->segment,
655 GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
657 if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
660 GST_OBJECT_LOCK (identity);
661 if ((clock = GST_ELEMENT (identity)->clock)) {
663 GstClockTime timestamp;
665 timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
667 /* save id if we need to unlock */
668 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
669 GST_OBJECT_UNLOCK (identity);
671 cret = gst_clock_id_wait (identity->clock_id, NULL);
673 GST_OBJECT_LOCK (identity);
674 if (identity->clock_id) {
675 gst_clock_id_unref (identity->clock_id);
676 identity->clock_id = NULL;
678 if (cret == GST_CLOCK_UNSCHEDULED)
681 GST_OBJECT_UNLOCK (identity);
684 identity->offset += info.size;
686 if (identity->sleep_time && ret == GST_FLOW_OK)
687 g_usleep (identity->sleep_time);
689 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
690 && (ret == GST_FLOW_OK)) {
691 GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
692 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
693 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
696 gst_buffer_unmap (buf, &info);
703 GST_ELEMENT_ERROR (identity, CORE, FAILED,
704 (_("Failed after iterations as requested.")), (NULL));
705 gst_buffer_unmap (buf, &info);
706 return GST_FLOW_ERROR;
710 if (!identity->silent) {
711 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
714 gst_buffer_unmap (buf, &info);
715 /* return DROPPED to basetransform. */
716 return GST_BASE_TRANSFORM_FLOW_DROPPED;
721 gst_identity_set_property (GObject * object, guint prop_id,
722 const GValue * value, GParamSpec * pspec)
724 GstIdentity *identity;
726 identity = GST_IDENTITY (object);
729 case PROP_SLEEP_TIME:
730 identity->sleep_time = g_value_get_uint (value);
733 identity->silent = g_value_get_boolean (value);
735 case PROP_SINGLE_SEGMENT:
736 identity->single_segment = g_value_get_boolean (value);
739 identity->dump = g_value_get_boolean (value);
741 case PROP_ERROR_AFTER:
742 identity->error_after = g_value_get_int (value);
744 case PROP_DROP_PROBABILITY:
745 identity->drop_probability = g_value_get_float (value);
748 identity->datarate = g_value_get_int (value);
751 identity->sync = g_value_get_boolean (value);
753 case PROP_CHECK_PERFECT:
754 identity->check_perfect = g_value_get_boolean (value);
756 case PROP_CHECK_IMPERFECT_TIMESTAMP:
757 identity->check_imperfect_timestamp = g_value_get_boolean (value);
759 case PROP_CHECK_IMPERFECT_OFFSET:
760 identity->check_imperfect_offset = g_value_get_boolean (value);
762 case PROP_SIGNAL_HANDOFFS:
763 identity->signal_handoffs = g_value_get_boolean (value);
766 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
772 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
775 GstIdentity *identity;
777 identity = GST_IDENTITY (object);
780 case PROP_SLEEP_TIME:
781 g_value_set_uint (value, identity->sleep_time);
783 case PROP_ERROR_AFTER:
784 g_value_set_int (value, identity->error_after);
786 case PROP_DROP_PROBABILITY:
787 g_value_set_float (value, identity->drop_probability);
790 g_value_set_int (value, identity->datarate);
793 g_value_set_boolean (value, identity->silent);
795 case PROP_SINGLE_SEGMENT:
796 g_value_set_boolean (value, identity->single_segment);
799 g_value_set_boolean (value, identity->dump);
801 case PROP_LAST_MESSAGE:
802 GST_OBJECT_LOCK (identity);
803 g_value_set_string (value, identity->last_message);
804 GST_OBJECT_UNLOCK (identity);
807 g_value_set_boolean (value, identity->sync);
809 case PROP_CHECK_PERFECT:
810 g_value_set_boolean (value, identity->check_perfect);
812 case PROP_CHECK_IMPERFECT_TIMESTAMP:
813 g_value_set_boolean (value, identity->check_imperfect_timestamp);
815 case PROP_CHECK_IMPERFECT_OFFSET:
816 g_value_set_boolean (value, identity->check_imperfect_offset);
818 case PROP_SIGNAL_HANDOFFS:
819 g_value_set_boolean (value, identity->signal_handoffs);
822 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
828 gst_identity_start (GstBaseTransform * trans)
830 GstIdentity *identity;
832 identity = GST_IDENTITY (trans);
834 identity->offset = 0;
835 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
836 identity->prev_duration = GST_CLOCK_TIME_NONE;
837 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
838 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
844 gst_identity_stop (GstBaseTransform * trans)
846 GstIdentity *identity;
848 identity = GST_IDENTITY (trans);
850 GST_OBJECT_LOCK (identity);
851 g_free (identity->last_message);
852 identity->last_message = NULL;
853 GST_OBJECT_UNLOCK (identity);
858 static GstStateChangeReturn
859 gst_identity_change_state (GstElement * element, GstStateChange transition)
861 GstStateChangeReturn ret;
862 GstIdentity *identity = GST_IDENTITY (element);
864 switch (transition) {
865 case GST_STATE_CHANGE_NULL_TO_READY:
867 case GST_STATE_CHANGE_READY_TO_PAUSED:
869 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
871 case GST_STATE_CHANGE_PAUSED_TO_READY:
872 GST_OBJECT_LOCK (identity);
873 if (identity->clock_id) {
874 GST_DEBUG_OBJECT (identity, "unlock clock wait");
875 gst_clock_id_unschedule (identity->clock_id);
876 gst_clock_id_unref (identity->clock_id);
877 identity->clock_id = NULL;
879 GST_OBJECT_UNLOCK (identity);
885 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
887 switch (transition) {
888 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
890 case GST_STATE_CHANGE_PAUSED_TO_READY:
892 case GST_STATE_CHANGE_READY_TO_NULL: