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 TRUE
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 gboolean gst_identity_start (GstBaseTransform * trans);
112 static gboolean gst_identity_stop (GstBaseTransform * trans);
113 static GstStateChangeReturn gst_identity_change_state (GstElement * element,
114 GstStateChange transition);
116 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
118 static GParamSpec *pspec_last_message = NULL;
121 gst_identity_finalize (GObject * object)
123 GstIdentity *identity;
125 identity = GST_IDENTITY (object);
127 g_free (identity->last_message);
129 G_OBJECT_CLASS (parent_class)->finalize (object);
133 gst_identity_class_init (GstIdentityClass * klass)
135 GObjectClass *gobject_class;
136 GstElementClass *gstelement_class;
137 GstBaseTransformClass *gstbasetrans_class;
139 gobject_class = G_OBJECT_CLASS (klass);
140 gstelement_class = GST_ELEMENT_CLASS (klass);
141 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
143 gobject_class->set_property = gst_identity_set_property;
144 gobject_class->get_property = gst_identity_get_property;
146 g_object_class_install_property (gobject_class, PROP_SLEEP_TIME,
147 g_param_spec_uint ("sleep-time", "Sleep time",
148 "Microseconds to sleep between processing", 0, G_MAXUINT,
149 DEFAULT_SLEEP_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
150 g_object_class_install_property (gobject_class, PROP_ERROR_AFTER,
151 g_param_spec_int ("error-after", "Error After", "Error after N buffers",
152 G_MININT, G_MAXINT, DEFAULT_ERROR_AFTER,
153 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
154 g_object_class_install_property (gobject_class, PROP_DROP_PROBABILITY,
155 g_param_spec_float ("drop-probability", "Drop Probability",
156 "The Probability a buffer is dropped", 0.0, 1.0,
157 DEFAULT_DROP_PROBABILITY,
158 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
159 g_object_class_install_property (gobject_class, PROP_DATARATE,
160 g_param_spec_int ("datarate", "Datarate",
161 "(Re)timestamps buffers with number of bytes per second (0 = inactive)",
162 0, G_MAXINT, DEFAULT_DATARATE,
163 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164 g_object_class_install_property (gobject_class, PROP_SILENT,
165 g_param_spec_boolean ("silent", "silent", "silent", DEFAULT_SILENT,
166 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
167 g_object_class_install_property (gobject_class, PROP_SINGLE_SEGMENT,
168 g_param_spec_boolean ("single-segment", "Single Segment",
169 "Timestamp buffers and eat segments so as to appear as one segment",
170 DEFAULT_SINGLE_SEGMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
171 pspec_last_message = g_param_spec_string ("last-message", "last-message",
172 "last-message", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
173 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
175 g_object_class_install_property (gobject_class, PROP_DUMP,
176 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents to stdout",
177 DEFAULT_DUMP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178 g_object_class_install_property (gobject_class, PROP_SYNC,
179 g_param_spec_boolean ("sync", "Synchronize",
180 "Synchronize to pipeline clock", DEFAULT_SYNC,
181 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
182 g_object_class_install_property (gobject_class, PROP_CHECK_PERFECT,
183 g_param_spec_boolean ("check-perfect", "Check For Perfect Stream",
184 "Verify that the stream is time- and data-contiguous. "
185 "This only logs in the debug log. This will be deprecated in favor "
186 "of the check-imperfect-timestamp/offset properties.",
187 DEFAULT_CHECK_PERFECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188 g_object_class_install_property (gobject_class,
189 PROP_CHECK_IMPERFECT_TIMESTAMP,
190 g_param_spec_boolean ("check-imperfect-timestamp",
191 "Check for discontiguous timestamps",
192 "Send element messages if timestamps and durations do not match up",
193 DEFAULT_CHECK_IMPERFECT_TIMESTAMP,
194 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195 g_object_class_install_property (gobject_class, PROP_CHECK_IMPERFECT_OFFSET,
196 g_param_spec_boolean ("check-imperfect-offset",
197 "Check for discontiguous offset",
198 "Send element messages if offset and offset_end do not match up",
199 DEFAULT_CHECK_IMPERFECT_OFFSET,
200 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
203 * GstIdentity:signal-handoffs
205 * If set to #TRUE, the identity will emit a handoff signal when handling a buffer.
206 * When set to #FALSE, no signal will be emited, which might improve performance.
210 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
211 g_param_spec_boolean ("signal-handoffs",
212 "Signal handoffs", "Send a signal before pushing the buffer",
213 DEFAULT_SIGNAL_HANDOFFS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
216 * GstIdentity::handoff:
217 * @identity: the identity instance
218 * @buffer: the buffer that just has been received
219 * @pad: the pad that received it
221 * This signal gets emitted before passing the buffer downstream.
223 gst_identity_signals[SIGNAL_HANDOFF] =
224 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
225 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
226 g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1,
227 GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
229 gobject_class->finalize = gst_identity_finalize;
231 gst_element_class_set_details_simple (gstelement_class,
234 "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>");
235 gst_element_class_add_pad_template (gstelement_class,
236 gst_static_pad_template_get (&srctemplate));
237 gst_element_class_add_pad_template (gstelement_class,
238 gst_static_pad_template_get (&sinktemplate));
240 gstelement_class->change_state =
241 GST_DEBUG_FUNCPTR (gst_identity_change_state);
243 gstbasetrans_class->sink_event = GST_DEBUG_FUNCPTR (gst_identity_sink_event);
244 gstbasetrans_class->transform_ip =
245 GST_DEBUG_FUNCPTR (gst_identity_transform_ip);
246 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_identity_start);
247 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_identity_stop);
251 gst_identity_init (GstIdentity * identity)
253 identity->sleep_time = DEFAULT_SLEEP_TIME;
254 identity->error_after = DEFAULT_ERROR_AFTER;
255 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
256 identity->datarate = DEFAULT_DATARATE;
257 identity->silent = DEFAULT_SILENT;
258 identity->single_segment = DEFAULT_SINGLE_SEGMENT;
259 identity->sync = DEFAULT_SYNC;
260 identity->check_perfect = DEFAULT_CHECK_PERFECT;
261 identity->check_imperfect_timestamp = DEFAULT_CHECK_IMPERFECT_TIMESTAMP;
262 identity->check_imperfect_offset = DEFAULT_CHECK_IMPERFECT_OFFSET;
263 identity->dump = DEFAULT_DUMP;
264 identity->last_message = NULL;
265 identity->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
267 gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE);
271 gst_identity_notify_last_message (GstIdentity * identity)
273 g_object_notify_by_pspec ((GObject *) identity, pspec_last_message);
277 gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event)
279 GstIdentity *identity;
282 identity = GST_IDENTITY (trans);
284 if (!identity->silent) {
285 const GstStructure *s;
289 GST_OBJECT_LOCK (identity);
290 g_free (identity->last_message);
292 tstr = gst_event_type_get_name (GST_EVENT_TYPE (event));
293 if ((s = gst_event_get_structure (event)))
294 sstr = gst_structure_to_string (s);
296 sstr = g_strdup ("");
298 identity->last_message =
299 g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p",
300 GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event),
303 GST_OBJECT_UNLOCK (identity);
305 gst_identity_notify_last_message (identity);
308 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
309 if (trans->have_segment == FALSE) {
313 gst_event_copy_segment (event, &segment);
314 gst_event_copy_segment (event, &trans->segment);
315 trans->have_segment = TRUE;
317 /* This is the first segment, send out a (0, -1) segment */
318 gst_segment_init (&segment, segment.format);
319 news = gst_event_new_segment (&segment);
321 gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news);
325 /* Reset previous timestamp, duration and offsets on NEWSEGMENT
326 * to prevent false warnings when checking for perfect streams */
327 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
328 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
329 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
332 if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
333 /* eat up segments */
334 gst_event_unref (event);
337 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
338 GST_OBJECT_LOCK (identity);
339 if (identity->clock_id) {
340 GST_DEBUG_OBJECT (identity, "unlock clock wait");
341 gst_clock_id_unschedule (identity->clock_id);
342 gst_clock_id_unref (identity->clock_id);
343 identity->clock_id = NULL;
345 GST_OBJECT_UNLOCK (identity);
348 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
355 gst_identity_check_perfect (GstIdentity * identity, GstBuffer * buf)
357 GstClockTime timestamp;
359 timestamp = GST_BUFFER_TIMESTAMP (buf);
361 /* see if we need to do perfect stream checking */
362 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
363 if (timestamp != GST_CLOCK_TIME_NONE) {
364 /* check if we had a previous buffer to compare to */
365 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
366 identity->prev_duration != GST_CLOCK_TIME_NONE) {
367 guint64 offset, t_expected;
370 t_expected = identity->prev_timestamp + identity->prev_duration;
371 dt = timestamp - t_expected;
373 GST_WARNING_OBJECT (identity,
374 "Buffer not time-contiguous with previous one: " "prev ts %"
375 GST_TIME_FORMAT ", prev dur %" GST_TIME_FORMAT ", new ts %"
376 GST_TIME_FORMAT " (expected ts %" GST_TIME_FORMAT ", delta=%c%"
377 GST_TIME_FORMAT ")", GST_TIME_ARGS (identity->prev_timestamp),
378 GST_TIME_ARGS (identity->prev_duration), GST_TIME_ARGS (timestamp),
379 GST_TIME_ARGS (t_expected), (dt < 0) ? '-' : '+',
380 GST_TIME_ARGS ((dt < 0) ? (GstClockTime) (-dt) : dt));
383 offset = GST_BUFFER_OFFSET (buf);
384 if (identity->prev_offset_end != offset &&
385 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
386 offset != GST_BUFFER_OFFSET_NONE) {
387 GST_WARNING_OBJECT (identity,
388 "Buffer not data-contiguous with previous one: "
389 "prev offset_end %" G_GINT64_FORMAT ", new offset %"
390 G_GINT64_FORMAT, identity->prev_offset_end, offset);
393 GST_DEBUG_OBJECT (identity, "can't check time-contiguity, no timestamp "
394 "and/or duration were set on previous buffer");
400 gst_identity_check_imperfect_timestamp (GstIdentity * identity, GstBuffer * buf)
402 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buf);
404 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
405 if (timestamp != GST_CLOCK_TIME_NONE) {
406 /* check if we had a previous buffer to compare to */
407 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
408 identity->prev_duration != GST_CLOCK_TIME_NONE) {
409 GstClockTime t_expected;
412 t_expected = identity->prev_timestamp + identity->prev_duration;
413 dt = GST_CLOCK_DIFF (t_expected, timestamp);
416 * "imperfect-timestamp" bus message:
417 * @identity: the identity instance
418 * @prev-timestamp: the previous buffer timestamp
419 * @prev-duration: the previous buffer duration
420 * @prev-offset: the previous buffer offset
421 * @prev-offset-end: the previous buffer offset end
422 * @cur-timestamp: the current buffer timestamp
423 * @cur-duration: the current buffer duration
424 * @cur-offset: the current buffer offset
425 * @cur-offset-end: the current buffer offset end
427 * This bus message gets emitted if the check-imperfect-timestamp
428 * property is set and there is a gap in time between the
429 * last buffer and the newly received buffer.
431 gst_element_post_message (GST_ELEMENT (identity),
432 gst_message_new_element (GST_OBJECT (identity),
433 gst_structure_new ("imperfect-timestamp",
434 "prev-timestamp", G_TYPE_UINT64,
435 identity->prev_timestamp, "prev-duration", G_TYPE_UINT64,
436 identity->prev_duration, "prev-offset", G_TYPE_UINT64,
437 identity->prev_offset, "prev-offset-end", G_TYPE_UINT64,
438 identity->prev_offset_end, "cur-timestamp", G_TYPE_UINT64,
439 timestamp, "cur-duration", G_TYPE_UINT64,
440 GST_BUFFER_DURATION (buf), "cur-offset", G_TYPE_UINT64,
441 GST_BUFFER_OFFSET (buf), "cur-offset-end", G_TYPE_UINT64,
442 GST_BUFFER_OFFSET_END (buf), NULL)));
445 GST_DEBUG_OBJECT (identity, "can't check data-contiguity, no "
446 "offset_end was set on previous buffer");
452 gst_identity_check_imperfect_offset (GstIdentity * identity, GstBuffer * buf)
456 offset = GST_BUFFER_OFFSET (buf);
458 if (identity->prev_offset_end != offset &&
459 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
460 offset != GST_BUFFER_OFFSET_NONE) {
462 * "imperfect-offset" bus message:
463 * @identity: the identity instance
464 * @prev-timestamp: the previous buffer timestamp
465 * @prev-duration: the previous buffer duration
466 * @prev-offset: the previous buffer offset
467 * @prev-offset-end: the previous buffer offset end
468 * @cur-timestamp: the current buffer timestamp
469 * @cur-duration: the current buffer duration
470 * @cur-offset: the current buffer offset
471 * @cur-offset-end: the current buffer offset end
473 * This bus message gets emitted if the check-imperfect-offset
474 * property is set and there is a gap in offsets between the
475 * last buffer and the newly received buffer.
477 gst_element_post_message (GST_ELEMENT (identity),
478 gst_message_new_element (GST_OBJECT (identity),
479 gst_structure_new ("imperfect-offset", "prev-timestamp",
480 G_TYPE_UINT64, identity->prev_timestamp, "prev-duration",
481 G_TYPE_UINT64, identity->prev_duration, "prev-offset",
482 G_TYPE_UINT64, identity->prev_offset, "prev-offset-end",
483 G_TYPE_UINT64, identity->prev_offset_end, "cur-timestamp",
484 G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (buf), "cur-duration",
485 G_TYPE_UINT64, GST_BUFFER_DURATION (buf), "cur-offset",
486 G_TYPE_UINT64, GST_BUFFER_OFFSET (buf), "cur-offset-end",
487 G_TYPE_UINT64, GST_BUFFER_OFFSET_END (buf), NULL)));
489 GST_DEBUG_OBJECT (identity, "can't check offset contiguity, no offset "
490 "and/or offset_end were set on previous buffer");
495 print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts)
497 if (ts == GST_CLOCK_TIME_NONE)
500 g_snprintf (ts_str, ts_str_len, "%" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
505 gst_identity_update_last_message_for_buffer (GstIdentity * identity,
506 const gchar * action, GstBuffer * buf, gsize size)
508 gchar dts_str[64], pts_str[64], dur_str[64];
511 GST_OBJECT_LOCK (identity);
514 const char *flag_list[15] = {
515 "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
516 "marker", "header", "gap", "droppable", "delta-unit", "in-caps"
519 char *end = flag_str;
521 for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
522 if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
523 strcpy (end, flag_list[i]);
532 g_free (identity->last_message);
533 identity->last_message = g_strdup_printf ("%s ******* (%s:%s) "
534 "(%" G_GSIZE_FORMAT " bytes, dts: %s, pts:%s, duration: %s, offset: %"
535 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT
536 ", flags: %d %s) %p", action,
537 GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), size,
538 print_pretty_time (dts_str, sizeof (dts_str), GST_BUFFER_DTS (buf)),
539 print_pretty_time (pts_str, sizeof (pts_str), GST_BUFFER_PTS (buf)),
540 print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)),
541 GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
542 GST_BUFFER_FLAGS (buf), flag_str, buf);
544 GST_OBJECT_UNLOCK (identity);
546 gst_identity_notify_last_message (identity);
550 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
552 GstFlowReturn ret = GST_FLOW_OK;
553 GstIdentity *identity = GST_IDENTITY (trans);
554 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
557 size = gst_buffer_get_size (buf);
559 if (identity->check_perfect)
560 gst_identity_check_perfect (identity, buf);
561 if (identity->check_imperfect_timestamp)
562 gst_identity_check_imperfect_timestamp (identity, buf);
563 if (identity->check_imperfect_offset)
564 gst_identity_check_imperfect_offset (identity, buf);
566 /* update prev values */
567 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
568 identity->prev_duration = GST_BUFFER_DURATION (buf);
569 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
570 identity->prev_offset = GST_BUFFER_OFFSET (buf);
572 if (identity->error_after >= 0) {
573 identity->error_after--;
574 if (identity->error_after == 0)
578 if (identity->drop_probability > 0.0) {
579 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
583 if (identity->dump) {
586 gst_buffer_map (buf, &info, GST_MAP_READ);
587 gst_util_dump_mem (info.data, info.size);
588 gst_buffer_unmap (buf, &info);
591 if (!identity->silent) {
592 gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
595 if (identity->datarate > 0) {
596 GstClockTime time = gst_util_uint64_scale_int (identity->offset,
597 GST_SECOND, identity->datarate);
599 GST_BUFFER_TIMESTAMP (buf) = time;
600 GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
603 if (identity->signal_handoffs)
604 g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
606 if (trans->segment.format == GST_FORMAT_TIME)
607 runtimestamp = gst_segment_to_running_time (&trans->segment,
608 GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
610 if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
613 GST_OBJECT_LOCK (identity);
614 if ((clock = GST_ELEMENT (identity)->clock)) {
616 GstClockTime timestamp;
618 timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
620 /* save id if we need to unlock */
621 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
622 GST_OBJECT_UNLOCK (identity);
624 cret = gst_clock_id_wait (identity->clock_id, NULL);
626 GST_OBJECT_LOCK (identity);
627 if (identity->clock_id) {
628 gst_clock_id_unref (identity->clock_id);
629 identity->clock_id = NULL;
631 if (cret == GST_CLOCK_UNSCHEDULED)
634 GST_OBJECT_UNLOCK (identity);
637 identity->offset += size;
639 if (identity->sleep_time && ret == GST_FLOW_OK)
640 g_usleep (identity->sleep_time);
642 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
643 && (ret == GST_FLOW_OK)) {
644 GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
645 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
646 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
654 GST_ELEMENT_ERROR (identity, CORE, FAILED,
655 (_("Failed after iterations as requested.")), (NULL));
656 return GST_FLOW_ERROR;
660 if (!identity->silent) {
661 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
664 /* return DROPPED to basetransform. */
665 return GST_BASE_TRANSFORM_FLOW_DROPPED;
670 gst_identity_set_property (GObject * object, guint prop_id,
671 const GValue * value, GParamSpec * pspec)
673 GstIdentity *identity;
675 identity = GST_IDENTITY (object);
678 case PROP_SLEEP_TIME:
679 identity->sleep_time = g_value_get_uint (value);
682 identity->silent = g_value_get_boolean (value);
684 case PROP_SINGLE_SEGMENT:
685 identity->single_segment = g_value_get_boolean (value);
688 identity->dump = g_value_get_boolean (value);
690 case PROP_ERROR_AFTER:
691 identity->error_after = g_value_get_int (value);
693 case PROP_DROP_PROBABILITY:
694 identity->drop_probability = g_value_get_float (value);
697 identity->datarate = g_value_get_int (value);
700 identity->sync = g_value_get_boolean (value);
702 case PROP_CHECK_PERFECT:
703 identity->check_perfect = g_value_get_boolean (value);
705 case PROP_CHECK_IMPERFECT_TIMESTAMP:
706 identity->check_imperfect_timestamp = g_value_get_boolean (value);
708 case PROP_CHECK_IMPERFECT_OFFSET:
709 identity->check_imperfect_offset = g_value_get_boolean (value);
711 case PROP_SIGNAL_HANDOFFS:
712 identity->signal_handoffs = g_value_get_boolean (value);
715 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
718 if (identity->datarate > 0 || identity->single_segment)
719 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), FALSE);
721 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), TRUE);
725 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
728 GstIdentity *identity;
730 identity = GST_IDENTITY (object);
733 case PROP_SLEEP_TIME:
734 g_value_set_uint (value, identity->sleep_time);
736 case PROP_ERROR_AFTER:
737 g_value_set_int (value, identity->error_after);
739 case PROP_DROP_PROBABILITY:
740 g_value_set_float (value, identity->drop_probability);
743 g_value_set_int (value, identity->datarate);
746 g_value_set_boolean (value, identity->silent);
748 case PROP_SINGLE_SEGMENT:
749 g_value_set_boolean (value, identity->single_segment);
752 g_value_set_boolean (value, identity->dump);
754 case PROP_LAST_MESSAGE:
755 GST_OBJECT_LOCK (identity);
756 g_value_set_string (value, identity->last_message);
757 GST_OBJECT_UNLOCK (identity);
760 g_value_set_boolean (value, identity->sync);
762 case PROP_CHECK_PERFECT:
763 g_value_set_boolean (value, identity->check_perfect);
765 case PROP_CHECK_IMPERFECT_TIMESTAMP:
766 g_value_set_boolean (value, identity->check_imperfect_timestamp);
768 case PROP_CHECK_IMPERFECT_OFFSET:
769 g_value_set_boolean (value, identity->check_imperfect_offset);
771 case PROP_SIGNAL_HANDOFFS:
772 g_value_set_boolean (value, identity->signal_handoffs);
775 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
781 gst_identity_start (GstBaseTransform * trans)
783 GstIdentity *identity;
785 identity = GST_IDENTITY (trans);
787 identity->offset = 0;
788 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
789 identity->prev_duration = GST_CLOCK_TIME_NONE;
790 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
791 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
797 gst_identity_stop (GstBaseTransform * trans)
799 GstIdentity *identity;
801 identity = GST_IDENTITY (trans);
803 GST_OBJECT_LOCK (identity);
804 g_free (identity->last_message);
805 identity->last_message = NULL;
806 GST_OBJECT_UNLOCK (identity);
811 static GstStateChangeReturn
812 gst_identity_change_state (GstElement * element, GstStateChange transition)
814 GstStateChangeReturn ret;
815 GstIdentity *identity = GST_IDENTITY (element);
817 switch (transition) {
818 case GST_STATE_CHANGE_NULL_TO_READY:
820 case GST_STATE_CHANGE_READY_TO_PAUSED:
822 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
824 case GST_STATE_CHANGE_PAUSED_TO_READY:
825 GST_OBJECT_LOCK (identity);
826 if (identity->clock_id) {
827 GST_DEBUG_OBJECT (identity, "unlock clock wait");
828 gst_clock_id_unschedule (identity->clock_id);
829 gst_clock_id_unref (identity->clock_id);
830 identity->clock_id = NULL;
832 GST_OBJECT_UNLOCK (identity);
838 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
840 switch (transition) {
841 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
843 case GST_STATE_CHANGE_PAUSED_TO_READY:
845 case GST_STATE_CHANGE_READY_TO_NULL: