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 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);
132 /* fixme: do something about this */
134 marshal_VOID__MINIOBJECT (GClosure * closure, GValue * return_value,
135 guint n_param_values, const GValue * param_values, gpointer invocation_hint,
136 gpointer marshal_data)
138 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1,
140 register marshalfunc_VOID__MINIOBJECT callback;
141 register GCClosure *cc = (GCClosure *) closure;
142 register gpointer data1, data2;
144 g_return_if_fail (n_param_values == 2);
146 if (G_CCLOSURE_SWAP_DATA (closure)) {
147 data1 = closure->data;
148 data2 = g_value_peek_pointer (param_values + 0);
150 data1 = g_value_peek_pointer (param_values + 0);
151 data2 = closure->data;
154 (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data :
157 callback (data1, g_value_get_boxed (param_values + 1), data2);
161 gst_identity_class_init (GstIdentityClass * klass)
163 GObjectClass *gobject_class;
164 GstElementClass *gstelement_class;
165 GstBaseTransformClass *gstbasetrans_class;
167 gobject_class = G_OBJECT_CLASS (klass);
168 gstelement_class = GST_ELEMENT_CLASS (klass);
169 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
171 gobject_class->set_property = gst_identity_set_property;
172 gobject_class->get_property = gst_identity_get_property;
174 g_object_class_install_property (gobject_class, PROP_SLEEP_TIME,
175 g_param_spec_uint ("sleep-time", "Sleep time",
176 "Microseconds to sleep between processing", 0, G_MAXUINT,
177 DEFAULT_SLEEP_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178 g_object_class_install_property (gobject_class, PROP_ERROR_AFTER,
179 g_param_spec_int ("error-after", "Error After", "Error after N buffers",
180 G_MININT, G_MAXINT, DEFAULT_ERROR_AFTER,
181 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
182 g_object_class_install_property (gobject_class, PROP_DROP_PROBABILITY,
183 g_param_spec_float ("drop-probability", "Drop Probability",
184 "The Probability a buffer is dropped", 0.0, 1.0,
185 DEFAULT_DROP_PROBABILITY,
186 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
187 g_object_class_install_property (gobject_class, PROP_DATARATE,
188 g_param_spec_int ("datarate", "Datarate",
189 "(Re)timestamps buffers with number of bytes per second (0 = inactive)",
190 0, G_MAXINT, DEFAULT_DATARATE,
191 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192 g_object_class_install_property (gobject_class, PROP_SILENT,
193 g_param_spec_boolean ("silent", "silent", "silent", DEFAULT_SILENT,
194 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195 g_object_class_install_property (gobject_class, PROP_SINGLE_SEGMENT,
196 g_param_spec_boolean ("single-segment", "Single Segment",
197 "Timestamp buffers and eat segments so as to appear as one segment",
198 DEFAULT_SINGLE_SEGMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199 pspec_last_message = g_param_spec_string ("last-message", "last-message",
200 "last-message", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
201 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
203 g_object_class_install_property (gobject_class, PROP_DUMP,
204 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents to stdout",
205 DEFAULT_DUMP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
206 g_object_class_install_property (gobject_class, PROP_SYNC,
207 g_param_spec_boolean ("sync", "Synchronize",
208 "Synchronize to pipeline clock", DEFAULT_SYNC,
209 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
210 g_object_class_install_property (gobject_class, 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 "This only logs in the debug log. This will be deprecated in favor "
214 "of the check-imperfect-timestamp/offset properties.",
215 DEFAULT_CHECK_PERFECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
216 g_object_class_install_property (gobject_class,
217 PROP_CHECK_IMPERFECT_TIMESTAMP,
218 g_param_spec_boolean ("check-imperfect-timestamp",
219 "Check for discontiguous timestamps",
220 "Send element messages if timestamps and durations do not match up",
221 DEFAULT_CHECK_IMPERFECT_TIMESTAMP,
222 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
223 g_object_class_install_property (gobject_class, PROP_CHECK_IMPERFECT_OFFSET,
224 g_param_spec_boolean ("check-imperfect-offset",
225 "Check for discontiguous offset",
226 "Send element messages if offset and offset_end do not match up",
227 DEFAULT_CHECK_IMPERFECT_OFFSET,
228 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
231 * GstIdentity:signal-handoffs
233 * If set to #TRUE, the identity will emit a handoff signal when handling a buffer.
234 * When set to #FALSE, no signal will be emited, which might improve performance.
238 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
239 g_param_spec_boolean ("signal-handoffs",
240 "Signal handoffs", "Send a signal before pushing the buffer",
241 DEFAULT_SIGNAL_HANDOFFS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
244 * GstIdentity::handoff:
245 * @identity: the identity instance
246 * @buffer: the buffer that just has been received
247 * @pad: the pad that received it
249 * This signal gets emitted before passing the buffer downstream.
251 gst_identity_signals[SIGNAL_HANDOFF] =
252 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
253 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
254 marshal_VOID__MINIOBJECT, G_TYPE_NONE, 1, GST_TYPE_BUFFER);
256 gobject_class->finalize = gst_identity_finalize;
258 gst_element_class_set_details_simple (gstelement_class,
261 "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>");
262 gst_element_class_add_pad_template (gstelement_class,
263 gst_static_pad_template_get (&srctemplate));
264 gst_element_class_add_pad_template (gstelement_class,
265 gst_static_pad_template_get (&sinktemplate));
267 gstelement_class->change_state =
268 GST_DEBUG_FUNCPTR (gst_identity_change_state);
270 gstbasetrans_class->sink_event = GST_DEBUG_FUNCPTR (gst_identity_sink_event);
271 gstbasetrans_class->transform_ip =
272 GST_DEBUG_FUNCPTR (gst_identity_transform_ip);
273 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_identity_start);
274 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_identity_stop);
278 gst_identity_init (GstIdentity * identity)
280 identity->sleep_time = DEFAULT_SLEEP_TIME;
281 identity->error_after = DEFAULT_ERROR_AFTER;
282 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
283 identity->datarate = DEFAULT_DATARATE;
284 identity->silent = DEFAULT_SILENT;
285 identity->single_segment = DEFAULT_SINGLE_SEGMENT;
286 identity->sync = DEFAULT_SYNC;
287 identity->check_perfect = DEFAULT_CHECK_PERFECT;
288 identity->check_imperfect_timestamp = DEFAULT_CHECK_IMPERFECT_TIMESTAMP;
289 identity->check_imperfect_offset = DEFAULT_CHECK_IMPERFECT_OFFSET;
290 identity->dump = DEFAULT_DUMP;
291 identity->last_message = NULL;
292 identity->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
294 gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE);
298 gst_identity_notify_last_message (GstIdentity * identity)
300 g_object_notify_by_pspec ((GObject *) identity, pspec_last_message);
304 gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event)
306 GstIdentity *identity;
309 identity = GST_IDENTITY (trans);
311 if (!identity->silent) {
312 const GstStructure *s;
316 GST_OBJECT_LOCK (identity);
317 g_free (identity->last_message);
319 tstr = gst_event_type_get_name (GST_EVENT_TYPE (event));
320 if ((s = gst_event_get_structure (event)))
321 sstr = gst_structure_to_string (s);
323 sstr = g_strdup ("");
325 identity->last_message =
326 g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p",
327 GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event),
330 GST_OBJECT_UNLOCK (identity);
332 gst_identity_notify_last_message (identity);
335 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
336 if (trans->have_segment == FALSE) {
340 gst_event_copy_segment (event, &segment);
341 gst_event_copy_segment (event, &trans->segment);
342 trans->have_segment = TRUE;
344 /* This is the first segment, send out a (0, -1) segment */
345 gst_segment_init (&segment, segment.format);
346 news = gst_event_new_segment (&segment);
348 gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news);
352 /* Reset previous timestamp, duration and offsets on NEWSEGMENT
353 * to prevent false warnings when checking for perfect streams */
354 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
355 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
356 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
359 if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
360 /* eat up segments */
361 gst_event_unref (event);
364 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
365 GST_OBJECT_LOCK (identity);
366 if (identity->clock_id) {
367 GST_DEBUG_OBJECT (identity, "unlock clock wait");
368 gst_clock_id_unschedule (identity->clock_id);
369 gst_clock_id_unref (identity->clock_id);
370 identity->clock_id = NULL;
372 GST_OBJECT_UNLOCK (identity);
375 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
382 gst_identity_check_perfect (GstIdentity * identity, GstBuffer * buf)
384 GstClockTime timestamp;
386 timestamp = GST_BUFFER_TIMESTAMP (buf);
388 /* see if we need to do perfect stream checking */
389 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
390 if (timestamp != GST_CLOCK_TIME_NONE) {
391 /* check if we had a previous buffer to compare to */
392 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
393 identity->prev_duration != GST_CLOCK_TIME_NONE) {
394 guint64 offset, t_expected;
397 t_expected = identity->prev_timestamp + identity->prev_duration;
398 dt = timestamp - t_expected;
400 GST_WARNING_OBJECT (identity,
401 "Buffer not time-contiguous with previous one: " "prev ts %"
402 GST_TIME_FORMAT ", prev dur %" GST_TIME_FORMAT ", new ts %"
403 GST_TIME_FORMAT " (expected ts %" GST_TIME_FORMAT ", delta=%c%"
404 GST_TIME_FORMAT ")", GST_TIME_ARGS (identity->prev_timestamp),
405 GST_TIME_ARGS (identity->prev_duration), GST_TIME_ARGS (timestamp),
406 GST_TIME_ARGS (t_expected), (dt < 0) ? '-' : '+',
407 GST_TIME_ARGS ((dt < 0) ? (GstClockTime) (-dt) : dt));
410 offset = GST_BUFFER_OFFSET (buf);
411 if (identity->prev_offset_end != offset &&
412 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
413 offset != GST_BUFFER_OFFSET_NONE) {
414 GST_WARNING_OBJECT (identity,
415 "Buffer not data-contiguous with previous one: "
416 "prev offset_end %" G_GINT64_FORMAT ", new offset %"
417 G_GINT64_FORMAT, identity->prev_offset_end, offset);
420 GST_DEBUG_OBJECT (identity, "can't check time-contiguity, no timestamp "
421 "and/or duration were set on previous buffer");
427 gst_identity_check_imperfect_timestamp (GstIdentity * identity, GstBuffer * buf)
429 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buf);
431 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
432 if (timestamp != GST_CLOCK_TIME_NONE) {
433 /* check if we had a previous buffer to compare to */
434 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
435 identity->prev_duration != GST_CLOCK_TIME_NONE) {
436 GstClockTime t_expected;
439 t_expected = identity->prev_timestamp + identity->prev_duration;
440 dt = GST_CLOCK_DIFF (t_expected, timestamp);
443 * "imperfect-timestamp" bus message:
444 * @identity: the identity instance
445 * @prev-timestamp: the previous buffer timestamp
446 * @prev-duration: the previous buffer duration
447 * @prev-offset: the previous buffer offset
448 * @prev-offset-end: the previous buffer offset end
449 * @cur-timestamp: the current buffer timestamp
450 * @cur-duration: the current buffer duration
451 * @cur-offset: the current buffer offset
452 * @cur-offset-end: the current buffer offset end
454 * This bus message gets emitted if the check-imperfect-timestamp
455 * property is set and there is a gap in time between the
456 * last buffer and the newly received buffer.
458 gst_element_post_message (GST_ELEMENT (identity),
459 gst_message_new_element (GST_OBJECT (identity),
460 gst_structure_new ("imperfect-timestamp",
461 "prev-timestamp", G_TYPE_UINT64,
462 identity->prev_timestamp, "prev-duration", G_TYPE_UINT64,
463 identity->prev_duration, "prev-offset", G_TYPE_UINT64,
464 identity->prev_offset, "prev-offset-end", G_TYPE_UINT64,
465 identity->prev_offset_end, "cur-timestamp", G_TYPE_UINT64,
466 timestamp, "cur-duration", G_TYPE_UINT64,
467 GST_BUFFER_DURATION (buf), "cur-offset", G_TYPE_UINT64,
468 GST_BUFFER_OFFSET (buf), "cur-offset-end", G_TYPE_UINT64,
469 GST_BUFFER_OFFSET_END (buf), NULL)));
472 GST_DEBUG_OBJECT (identity, "can't check data-contiguity, no "
473 "offset_end was set on previous buffer");
479 gst_identity_check_imperfect_offset (GstIdentity * identity, GstBuffer * buf)
483 offset = GST_BUFFER_OFFSET (buf);
485 if (identity->prev_offset_end != offset &&
486 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
487 offset != GST_BUFFER_OFFSET_NONE) {
489 * "imperfect-offset" bus message:
490 * @identity: the identity instance
491 * @prev-timestamp: the previous buffer timestamp
492 * @prev-duration: the previous buffer duration
493 * @prev-offset: the previous buffer offset
494 * @prev-offset-end: the previous buffer offset end
495 * @cur-timestamp: the current buffer timestamp
496 * @cur-duration: the current buffer duration
497 * @cur-offset: the current buffer offset
498 * @cur-offset-end: the current buffer offset end
500 * This bus message gets emitted if the check-imperfect-offset
501 * property is set and there is a gap in offsets between the
502 * last buffer and the newly received buffer.
504 gst_element_post_message (GST_ELEMENT (identity),
505 gst_message_new_element (GST_OBJECT (identity),
506 gst_structure_new ("imperfect-offset", "prev-timestamp",
507 G_TYPE_UINT64, identity->prev_timestamp, "prev-duration",
508 G_TYPE_UINT64, identity->prev_duration, "prev-offset",
509 G_TYPE_UINT64, identity->prev_offset, "prev-offset-end",
510 G_TYPE_UINT64, identity->prev_offset_end, "cur-timestamp",
511 G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (buf), "cur-duration",
512 G_TYPE_UINT64, GST_BUFFER_DURATION (buf), "cur-offset",
513 G_TYPE_UINT64, GST_BUFFER_OFFSET (buf), "cur-offset-end",
514 G_TYPE_UINT64, GST_BUFFER_OFFSET_END (buf), NULL)));
516 GST_DEBUG_OBJECT (identity, "can't check offset contiguity, no offset "
517 "and/or offset_end were set on previous buffer");
522 print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts)
524 if (ts == GST_CLOCK_TIME_NONE)
527 g_snprintf (ts_str, ts_str_len, "%" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
532 gst_identity_update_last_message_for_buffer (GstIdentity * identity,
533 const gchar * action, GstBuffer * buf, gsize size)
535 gchar ts_str[64], dur_str[64];
538 GST_OBJECT_LOCK (identity);
541 const char *flag_list[15] = {
542 "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
543 "marker", "header", "gap", "droppable", "delta-unit", "in-caps"
546 char *end = flag_str;
548 for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
549 if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
550 strcpy (end, flag_list[i]);
559 g_free (identity->last_message);
560 identity->last_message = g_strdup_printf ("%s ******* (%s:%s) "
561 "(%" G_GSIZE_FORMAT " bytes, timestamp: %s, duration: %s, offset: %"
562 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT
563 ", flags: %d %s) %p", action,
564 GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), size,
565 print_pretty_time (ts_str, sizeof (ts_str), GST_BUFFER_TIMESTAMP (buf)),
566 print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)),
567 GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
568 GST_BUFFER_FLAGS (buf), flag_str, buf);
570 GST_OBJECT_UNLOCK (identity);
572 gst_identity_notify_last_message (identity);
576 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
578 GstFlowReturn ret = GST_FLOW_OK;
579 GstIdentity *identity = GST_IDENTITY (trans);
580 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
583 size = gst_buffer_get_size (buf);
585 if (identity->check_perfect)
586 gst_identity_check_perfect (identity, buf);
587 if (identity->check_imperfect_timestamp)
588 gst_identity_check_imperfect_timestamp (identity, buf);
589 if (identity->check_imperfect_offset)
590 gst_identity_check_imperfect_offset (identity, buf);
592 /* update prev values */
593 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
594 identity->prev_duration = GST_BUFFER_DURATION (buf);
595 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
596 identity->prev_offset = GST_BUFFER_OFFSET (buf);
598 if (identity->error_after >= 0) {
599 identity->error_after--;
600 if (identity->error_after == 0)
604 if (identity->drop_probability > 0.0) {
605 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
609 if (identity->dump) {
612 gst_buffer_map (buf, &info, GST_MAP_READ);
613 gst_util_dump_mem (info.data, info.size);
614 gst_buffer_unmap (buf, &info);
617 if (!identity->silent) {
618 gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
621 if (identity->datarate > 0) {
622 GstClockTime time = gst_util_uint64_scale_int (identity->offset,
623 GST_SECOND, identity->datarate);
625 GST_BUFFER_TIMESTAMP (buf) = time;
626 GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
629 if (identity->signal_handoffs)
630 g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
632 if (trans->segment.format == GST_FORMAT_TIME)
633 runtimestamp = gst_segment_to_running_time (&trans->segment,
634 GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
636 if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
639 GST_OBJECT_LOCK (identity);
640 if ((clock = GST_ELEMENT (identity)->clock)) {
642 GstClockTime timestamp;
644 timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
646 /* save id if we need to unlock */
647 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
648 GST_OBJECT_UNLOCK (identity);
650 cret = gst_clock_id_wait (identity->clock_id, NULL);
652 GST_OBJECT_LOCK (identity);
653 if (identity->clock_id) {
654 gst_clock_id_unref (identity->clock_id);
655 identity->clock_id = NULL;
657 if (cret == GST_CLOCK_UNSCHEDULED)
660 GST_OBJECT_UNLOCK (identity);
663 identity->offset += size;
665 if (identity->sleep_time && ret == GST_FLOW_OK)
666 g_usleep (identity->sleep_time);
668 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
669 && (ret == GST_FLOW_OK)) {
670 GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
671 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
672 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
680 GST_ELEMENT_ERROR (identity, CORE, FAILED,
681 (_("Failed after iterations as requested.")), (NULL));
682 return GST_FLOW_ERROR;
686 if (!identity->silent) {
687 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
690 /* return DROPPED to basetransform. */
691 return GST_BASE_TRANSFORM_FLOW_DROPPED;
696 gst_identity_set_property (GObject * object, guint prop_id,
697 const GValue * value, GParamSpec * pspec)
699 GstIdentity *identity;
701 identity = GST_IDENTITY (object);
704 case PROP_SLEEP_TIME:
705 identity->sleep_time = g_value_get_uint (value);
708 identity->silent = g_value_get_boolean (value);
710 case PROP_SINGLE_SEGMENT:
711 identity->single_segment = g_value_get_boolean (value);
714 identity->dump = g_value_get_boolean (value);
716 case PROP_ERROR_AFTER:
717 identity->error_after = g_value_get_int (value);
719 case PROP_DROP_PROBABILITY:
720 identity->drop_probability = g_value_get_float (value);
723 identity->datarate = g_value_get_int (value);
726 identity->sync = g_value_get_boolean (value);
728 case PROP_CHECK_PERFECT:
729 identity->check_perfect = g_value_get_boolean (value);
731 case PROP_CHECK_IMPERFECT_TIMESTAMP:
732 identity->check_imperfect_timestamp = g_value_get_boolean (value);
734 case PROP_CHECK_IMPERFECT_OFFSET:
735 identity->check_imperfect_offset = g_value_get_boolean (value);
737 case PROP_SIGNAL_HANDOFFS:
738 identity->signal_handoffs = g_value_get_boolean (value);
741 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
744 if (identity->datarate > 0 || identity->single_segment)
745 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), FALSE);
747 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), TRUE);
751 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
754 GstIdentity *identity;
756 identity = GST_IDENTITY (object);
759 case PROP_SLEEP_TIME:
760 g_value_set_uint (value, identity->sleep_time);
762 case PROP_ERROR_AFTER:
763 g_value_set_int (value, identity->error_after);
765 case PROP_DROP_PROBABILITY:
766 g_value_set_float (value, identity->drop_probability);
769 g_value_set_int (value, identity->datarate);
772 g_value_set_boolean (value, identity->silent);
774 case PROP_SINGLE_SEGMENT:
775 g_value_set_boolean (value, identity->single_segment);
778 g_value_set_boolean (value, identity->dump);
780 case PROP_LAST_MESSAGE:
781 GST_OBJECT_LOCK (identity);
782 g_value_set_string (value, identity->last_message);
783 GST_OBJECT_UNLOCK (identity);
786 g_value_set_boolean (value, identity->sync);
788 case PROP_CHECK_PERFECT:
789 g_value_set_boolean (value, identity->check_perfect);
791 case PROP_CHECK_IMPERFECT_TIMESTAMP:
792 g_value_set_boolean (value, identity->check_imperfect_timestamp);
794 case PROP_CHECK_IMPERFECT_OFFSET:
795 g_value_set_boolean (value, identity->check_imperfect_offset);
797 case PROP_SIGNAL_HANDOFFS:
798 g_value_set_boolean (value, identity->signal_handoffs);
801 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
807 gst_identity_start (GstBaseTransform * trans)
809 GstIdentity *identity;
811 identity = GST_IDENTITY (trans);
813 identity->offset = 0;
814 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
815 identity->prev_duration = GST_CLOCK_TIME_NONE;
816 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
817 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
823 gst_identity_stop (GstBaseTransform * trans)
825 GstIdentity *identity;
827 identity = GST_IDENTITY (trans);
829 GST_OBJECT_LOCK (identity);
830 g_free (identity->last_message);
831 identity->last_message = NULL;
832 GST_OBJECT_UNLOCK (identity);
837 static GstStateChangeReturn
838 gst_identity_change_state (GstElement * element, GstStateChange transition)
840 GstStateChangeReturn ret;
841 GstIdentity *identity = GST_IDENTITY (element);
843 switch (transition) {
844 case GST_STATE_CHANGE_NULL_TO_READY:
846 case GST_STATE_CHANGE_READY_TO_PAUSED:
848 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
850 case GST_STATE_CHANGE_PAUSED_TO_READY:
851 GST_OBJECT_LOCK (identity);
852 if (identity->clock_id) {
853 GST_DEBUG_OBJECT (identity, "unlock clock wait");
854 gst_clock_id_unschedule (identity->clock_id);
855 gst_clock_id_unref (identity->clock_id);
856 identity->clock_id = NULL;
858 GST_OBJECT_UNLOCK (identity);
864 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
866 switch (transition) {
867 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
869 case GST_STATE_CHANGE_PAUSED_TO_READY:
871 case GST_STATE_CHANGE_READY_TO_NULL: