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 incomming data through unmodified. It has some
27 * useful diagnostic functions, such as offset and timestamp checking.
36 #include "../../gst/gst-i18n-lib.h"
37 #include "gstidentity.h"
38 #include <gst/gstmarshal.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 FALSE
67 #define DEFAULT_SINGLE_SEGMENT FALSE
68 #define DEFAULT_DUMP FALSE
69 #define DEFAULT_SYNC FALSE
70 #define DEFAULT_CHECK_PERFECT FALSE
71 #define DEFAULT_CHECK_IMPERFECT_TIMESTAMP FALSE
72 #define DEFAULT_CHECK_IMPERFECT_OFFSET FALSE
73 #define DEFAULT_SIGNAL_HANDOFFS TRUE
80 PROP_DROP_PROBABILITY,
88 PROP_CHECK_IMPERFECT_TIMESTAMP,
89 PROP_CHECK_IMPERFECT_OFFSET,
95 GST_DEBUG_CATEGORY_INIT (gst_identity_debug, "identity", 0, "identity element");
96 #define gst_identity_parent_class parent_class
97 G_DEFINE_TYPE_WITH_CODE (GstIdentity, gst_identity, GST_TYPE_BASE_TRANSFORM,
100 static void gst_identity_finalize (GObject * object);
101 static void gst_identity_set_property (GObject * object, guint prop_id,
102 const GValue * value, GParamSpec * pspec);
103 static void gst_identity_get_property (GObject * object, guint prop_id,
104 GValue * value, GParamSpec * pspec);
106 static gboolean gst_identity_event (GstBaseTransform * trans, GstEvent * event);
107 static GstFlowReturn gst_identity_transform_ip (GstBaseTransform * trans,
109 static GstFlowReturn gst_identity_prepare_output_buffer (GstBaseTransform
110 * trans, GstBuffer * in_buf, gint out_size, GstCaps * out_caps,
111 GstBuffer ** out_buf);
112 static gboolean gst_identity_start (GstBaseTransform * trans);
113 static gboolean gst_identity_stop (GstBaseTransform * trans);
115 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
117 static GParamSpec *pspec_last_message = NULL;
120 gst_identity_finalize (GObject * object)
122 GstIdentity *identity;
124 identity = GST_IDENTITY (object);
126 g_free (identity->last_message);
128 #if !GLIB_CHECK_VERSION(2,26,0)
129 g_static_rec_mutex_free (&identity->notify_lock);
132 G_OBJECT_CLASS (parent_class)->finalize (object);
135 /* fixme: do something about this */
137 marshal_VOID__MINIOBJECT (GClosure * closure, GValue * return_value,
138 guint n_param_values, const GValue * param_values, gpointer invocation_hint,
139 gpointer marshal_data)
141 typedef void (*marshalfunc_VOID__MINIOBJECT) (gpointer obj, gpointer arg1,
143 register marshalfunc_VOID__MINIOBJECT callback;
144 register GCClosure *cc = (GCClosure *) closure;
145 register gpointer data1, data2;
147 g_return_if_fail (n_param_values == 2);
149 if (G_CCLOSURE_SWAP_DATA (closure)) {
150 data1 = closure->data;
151 data2 = g_value_peek_pointer (param_values + 0);
153 data1 = g_value_peek_pointer (param_values + 0);
154 data2 = closure->data;
157 (marshalfunc_VOID__MINIOBJECT) (marshal_data ? marshal_data :
160 callback (data1, g_value_get_boxed (param_values + 1), data2);
164 gst_identity_class_init (GstIdentityClass * klass)
166 GObjectClass *gobject_class;
167 GstElementClass *gstelement_class;
168 GstBaseTransformClass *gstbasetrans_class;
170 gobject_class = G_OBJECT_CLASS (klass);
171 gstelement_class = GST_ELEMENT_CLASS (klass);
172 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
174 gobject_class->set_property = gst_identity_set_property;
175 gobject_class->get_property = gst_identity_get_property;
177 g_object_class_install_property (gobject_class, PROP_SLEEP_TIME,
178 g_param_spec_uint ("sleep-time", "Sleep time",
179 "Microseconds to sleep between processing", 0, G_MAXUINT,
180 DEFAULT_SLEEP_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
181 g_object_class_install_property (gobject_class, PROP_ERROR_AFTER,
182 g_param_spec_int ("error-after", "Error After", "Error after N buffers",
183 G_MININT, G_MAXINT, DEFAULT_ERROR_AFTER,
184 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (gobject_class, PROP_DROP_PROBABILITY,
186 g_param_spec_float ("drop-probability", "Drop Probability",
187 "The Probability a buffer is dropped", 0.0, 1.0,
188 DEFAULT_DROP_PROBABILITY,
189 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
190 g_object_class_install_property (gobject_class, PROP_DATARATE,
191 g_param_spec_int ("datarate", "Datarate",
192 "(Re)timestamps buffers with number of bytes per second (0 = inactive)",
193 0, G_MAXINT, DEFAULT_DATARATE,
194 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195 g_object_class_install_property (gobject_class, PROP_SILENT,
196 g_param_spec_boolean ("silent", "silent", "silent", DEFAULT_SILENT,
197 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
198 g_object_class_install_property (gobject_class, PROP_SINGLE_SEGMENT,
199 g_param_spec_boolean ("single-segment", "Single Segment",
200 "Timestamp buffers and eat newsegments so as to appear as one segment",
201 DEFAULT_SINGLE_SEGMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
202 pspec_last_message = g_param_spec_string ("last-message", "last-message",
203 "last-message", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
204 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
206 g_object_class_install_property (gobject_class, PROP_DUMP,
207 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents to stdout",
208 DEFAULT_DUMP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
209 g_object_class_install_property (gobject_class, PROP_SYNC,
210 g_param_spec_boolean ("sync", "Synchronize",
211 "Synchronize to pipeline clock", DEFAULT_SYNC,
212 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
213 g_object_class_install_property (gobject_class, PROP_CHECK_PERFECT,
214 g_param_spec_boolean ("check-perfect", "Check For Perfect Stream",
215 "Verify that the stream is time- and data-contiguous. "
216 "This only logs in the debug log. This will be deprecated in favor "
217 "of the check-imperfect-timestamp/offset properties.",
218 DEFAULT_CHECK_PERFECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
219 g_object_class_install_property (gobject_class,
220 PROP_CHECK_IMPERFECT_TIMESTAMP,
221 g_param_spec_boolean ("check-imperfect-timestamp",
222 "Check for discontiguous timestamps",
223 "Send element messages if timestamps and durations do not match up",
224 DEFAULT_CHECK_IMPERFECT_TIMESTAMP,
225 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (gobject_class, PROP_CHECK_IMPERFECT_OFFSET,
227 g_param_spec_boolean ("check-imperfect-offset",
228 "Check for discontiguous offset",
229 "Send element messages if offset and offset_end do not match up",
230 DEFAULT_CHECK_IMPERFECT_OFFSET,
231 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
234 * GstIdentity:signal-handoffs
236 * If set to #TRUE, the identity will emit a handoff signal when handling a buffer.
237 * When set to #FALSE, no signal will be emited, which might improve performance.
241 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
242 g_param_spec_boolean ("signal-handoffs",
243 "Signal handoffs", "Send a signal before pushing the buffer",
244 DEFAULT_SIGNAL_HANDOFFS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 * GstIdentity::handoff:
248 * @identity: the identity instance
249 * @buffer: the buffer that just has been received
250 * @pad: the pad that received it
252 * This signal gets emitted before passing the buffer downstream.
254 gst_identity_signals[SIGNAL_HANDOFF] =
255 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
256 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
257 marshal_VOID__MINIOBJECT, G_TYPE_NONE, 1, GST_TYPE_BUFFER);
259 gobject_class->finalize = gst_identity_finalize;
261 gst_element_class_set_details_simple (gstelement_class,
264 "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>");
265 gst_element_class_add_pad_template (gstelement_class,
266 gst_static_pad_template_get (&srctemplate));
267 gst_element_class_add_pad_template (gstelement_class,
268 gst_static_pad_template_get (&sinktemplate));
270 gstbasetrans_class->event = GST_DEBUG_FUNCPTR (gst_identity_event);
271 gstbasetrans_class->transform_ip =
272 GST_DEBUG_FUNCPTR (gst_identity_transform_ip);
273 gstbasetrans_class->prepare_output_buffer =
274 GST_DEBUG_FUNCPTR (gst_identity_prepare_output_buffer);
275 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_identity_start);
276 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_identity_stop);
280 gst_identity_init (GstIdentity * identity)
282 identity->sleep_time = DEFAULT_SLEEP_TIME;
283 identity->error_after = DEFAULT_ERROR_AFTER;
284 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
285 identity->datarate = DEFAULT_DATARATE;
286 identity->silent = DEFAULT_SILENT;
287 identity->single_segment = DEFAULT_SINGLE_SEGMENT;
288 identity->sync = DEFAULT_SYNC;
289 identity->check_perfect = DEFAULT_CHECK_PERFECT;
290 identity->check_imperfect_timestamp = DEFAULT_CHECK_IMPERFECT_TIMESTAMP;
291 identity->check_imperfect_offset = DEFAULT_CHECK_IMPERFECT_OFFSET;
292 identity->dump = DEFAULT_DUMP;
293 identity->last_message = NULL;
294 identity->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
296 #if !GLIB_CHECK_VERSION(2,26,0)
297 g_static_rec_mutex_init (&identity->notify_lock);
300 gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE);
304 gst_identity_notify_last_message (GstIdentity * identity)
306 /* FIXME: this hacks around a bug in GLib/GObject: doing concurrent
307 * g_object_notify() on the same object might lead to crashes, see
308 * http://bugzilla.gnome.org/show_bug.cgi?id=166020#c60 and follow-ups.
309 * So we really don't want to do a g_object_notify() here for out-of-band
310 * events with the streaming thread possibly also doing a g_object_notify()
311 * for an in-band buffer or event. This is fixed in GLib >= 2.26 */
312 #if !GLIB_CHECK_VERSION(2,26,0)
313 g_static_rec_mutex_lock (&identity->notify_lock);
314 g_object_notify ((GObject *) identity, "last-message");
315 g_static_rec_mutex_unlock (&identity->notify_lock);
317 g_object_notify_by_pspec ((GObject *) identity, pspec_last_message);
322 gst_identity_event (GstBaseTransform * trans, GstEvent * event)
324 GstIdentity *identity;
327 identity = GST_IDENTITY (trans);
329 if (!identity->silent) {
330 const GstStructure *s;
333 GST_OBJECT_LOCK (identity);
334 g_free (identity->last_message);
336 if ((s = gst_event_get_structure (event)))
337 sstr = gst_structure_to_string (s);
339 sstr = g_strdup ("");
341 identity->last_message =
342 g_strdup_printf ("event ******* (%s:%s) E (type: %d, %s) %p",
343 GST_DEBUG_PAD_NAME (trans->sinkpad), GST_EVENT_TYPE (event), sstr,
346 GST_OBJECT_UNLOCK (identity);
348 gst_identity_notify_last_message (identity);
351 if (identity->single_segment
352 && (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT)) {
353 if (trans->have_newsegment == FALSE) {
357 gst_event_parse_new_segment (event, NULL, NULL, NULL, &format, NULL, NULL,
360 /* This is the first newsegment, send out a (0, -1) newsegment */
361 news = gst_event_new_new_segment (TRUE, 1.0, 1.0, format, 0, -1, 0);
363 gst_pad_event_default (trans->sinkpad, news);
367 /* Reset previous timestamp, duration and offsets on NEWSEGMENT
368 * to prevent false warnings when checking for perfect streams */
369 if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) {
370 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
371 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
374 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->event (trans, event);
376 if (identity->single_segment
377 && (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT)) {
378 /* eat up segments */
386 gst_identity_prepare_output_buffer (GstBaseTransform * trans,
387 GstBuffer * in_buf, gint out_size, GstCaps * out_caps, GstBuffer ** out_buf)
389 GstIdentity *identity = GST_IDENTITY (trans);
391 /* only bother if we may have to alter metadata */
392 if (identity->datarate > 0 || identity->single_segment) {
393 if (gst_buffer_is_writable (in_buf))
394 *out_buf = gst_buffer_ref (in_buf);
396 /* make even less writable */
397 gst_buffer_ref (in_buf);
398 /* extra ref is dropped going through the official process */
399 *out_buf = gst_buffer_make_writable (in_buf);
402 *out_buf = gst_buffer_ref (in_buf);
408 gst_identity_check_perfect (GstIdentity * identity, GstBuffer * buf)
410 GstClockTime timestamp;
412 timestamp = GST_BUFFER_TIMESTAMP (buf);
414 /* see if we need to do perfect stream checking */
415 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
416 if (timestamp != GST_CLOCK_TIME_NONE) {
417 /* check if we had a previous buffer to compare to */
418 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
419 identity->prev_duration != GST_CLOCK_TIME_NONE) {
420 guint64 offset, t_expected;
423 t_expected = identity->prev_timestamp + identity->prev_duration;
424 dt = timestamp - t_expected;
426 GST_WARNING_OBJECT (identity,
427 "Buffer not time-contiguous with previous one: " "prev ts %"
428 GST_TIME_FORMAT ", prev dur %" GST_TIME_FORMAT ", new ts %"
429 GST_TIME_FORMAT " (expected ts %" GST_TIME_FORMAT ", delta=%c%"
430 GST_TIME_FORMAT ")", GST_TIME_ARGS (identity->prev_timestamp),
431 GST_TIME_ARGS (identity->prev_duration), GST_TIME_ARGS (timestamp),
432 GST_TIME_ARGS (t_expected), (dt < 0) ? '-' : '+',
433 GST_TIME_ARGS ((dt < 0) ? (GstClockTime) (-dt) : dt));
436 offset = GST_BUFFER_OFFSET (buf);
437 if (identity->prev_offset_end != offset &&
438 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
439 offset != GST_BUFFER_OFFSET_NONE) {
440 GST_WARNING_OBJECT (identity,
441 "Buffer not data-contiguous with previous one: "
442 "prev offset_end %" G_GINT64_FORMAT ", new offset %"
443 G_GINT64_FORMAT, identity->prev_offset_end, offset);
446 GST_DEBUG_OBJECT (identity, "can't check time-contiguity, no timestamp "
447 "and/or duration were set on previous buffer");
453 gst_identity_check_imperfect_timestamp (GstIdentity * identity, GstBuffer * buf)
455 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buf);
457 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
458 if (timestamp != GST_CLOCK_TIME_NONE) {
459 /* check if we had a previous buffer to compare to */
460 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
461 identity->prev_duration != GST_CLOCK_TIME_NONE) {
462 GstClockTime t_expected;
465 t_expected = identity->prev_timestamp + identity->prev_duration;
466 dt = GST_CLOCK_DIFF (t_expected, timestamp);
469 * "imperfect-timestamp" bus message:
470 * @identity: the identity instance
471 * @prev-timestamp: the previous buffer timestamp
472 * @prev-duration: the previous buffer duration
473 * @prev-offset: the previous buffer offset
474 * @prev-offset-end: the previous buffer offset end
475 * @cur-timestamp: the current buffer timestamp
476 * @cur-duration: the current buffer duration
477 * @cur-offset: the current buffer offset
478 * @cur-offset-end: the current buffer offset end
480 * This bus message gets emitted if the check-imperfect-timestamp
481 * property is set and there is a gap in time between the
482 * last buffer and the newly received buffer.
484 gst_element_post_message (GST_ELEMENT (identity),
485 gst_message_new_element (GST_OBJECT (identity),
486 gst_structure_new ("imperfect-timestamp",
487 "prev-timestamp", G_TYPE_UINT64,
488 identity->prev_timestamp, "prev-duration", G_TYPE_UINT64,
489 identity->prev_duration, "prev-offset", G_TYPE_UINT64,
490 identity->prev_offset, "prev-offset-end", G_TYPE_UINT64,
491 identity->prev_offset_end, "cur-timestamp", G_TYPE_UINT64,
492 timestamp, "cur-duration", G_TYPE_UINT64,
493 GST_BUFFER_DURATION (buf), "cur-offset", G_TYPE_UINT64,
494 GST_BUFFER_OFFSET (buf), "cur-offset-end", G_TYPE_UINT64,
495 GST_BUFFER_OFFSET_END (buf), NULL)));
498 GST_DEBUG_OBJECT (identity, "can't check data-contiguity, no "
499 "offset_end was set on previous buffer");
505 gst_identity_check_imperfect_offset (GstIdentity * identity, GstBuffer * buf)
509 offset = GST_BUFFER_OFFSET (buf);
511 if (identity->prev_offset_end != offset &&
512 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
513 offset != GST_BUFFER_OFFSET_NONE) {
515 * "imperfect-offset" bus message:
516 * @identity: the identity instance
517 * @prev-timestamp: the previous buffer timestamp
518 * @prev-duration: the previous buffer duration
519 * @prev-offset: the previous buffer offset
520 * @prev-offset-end: the previous buffer offset end
521 * @cur-timestamp: the current buffer timestamp
522 * @cur-duration: the current buffer duration
523 * @cur-offset: the current buffer offset
524 * @cur-offset-end: the current buffer offset end
526 * This bus message gets emitted if the check-imperfect-offset
527 * property is set and there is a gap in offsets between the
528 * last buffer and the newly received buffer.
530 gst_element_post_message (GST_ELEMENT (identity),
531 gst_message_new_element (GST_OBJECT (identity),
532 gst_structure_new ("imperfect-offset", "prev-timestamp",
533 G_TYPE_UINT64, identity->prev_timestamp, "prev-duration",
534 G_TYPE_UINT64, identity->prev_duration, "prev-offset",
535 G_TYPE_UINT64, identity->prev_offset, "prev-offset-end",
536 G_TYPE_UINT64, identity->prev_offset_end, "cur-timestamp",
537 G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (buf), "cur-duration",
538 G_TYPE_UINT64, GST_BUFFER_DURATION (buf), "cur-offset",
539 G_TYPE_UINT64, GST_BUFFER_OFFSET (buf), "cur-offset-end",
540 G_TYPE_UINT64, GST_BUFFER_OFFSET_END (buf), NULL)));
542 GST_DEBUG_OBJECT (identity, "can't check offset contiguity, no offset "
543 "and/or offset_end were set on previous buffer");
548 print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts)
550 if (ts == GST_CLOCK_TIME_NONE)
553 g_snprintf (ts_str, ts_str_len, "%" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
558 gst_identity_update_last_message_for_buffer (GstIdentity * identity,
559 const gchar * action, GstBuffer * buf, gsize size)
561 gchar ts_str[64], dur_str[64];
563 GST_OBJECT_LOCK (identity);
565 g_free (identity->last_message);
566 identity->last_message = g_strdup_printf ("%s ******* (%s:%s)i "
567 "(%" G_GSIZE_FORMAT " bytes, timestamp: %s, duration: %s, offset: %"
568 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT ", flags: %d) %p",
569 action, GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad),
570 size, print_pretty_time (ts_str, sizeof (ts_str),
571 GST_BUFFER_TIMESTAMP (buf)), print_pretty_time (dur_str,
572 sizeof (dur_str), GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf),
573 GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf);
575 GST_OBJECT_UNLOCK (identity);
577 gst_identity_notify_last_message (identity);
581 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
583 GstFlowReturn ret = GST_FLOW_OK;
584 GstIdentity *identity = GST_IDENTITY (trans);
585 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
589 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
591 if (identity->check_perfect)
592 gst_identity_check_perfect (identity, buf);
593 if (identity->check_imperfect_timestamp)
594 gst_identity_check_imperfect_timestamp (identity, buf);
595 if (identity->check_imperfect_offset)
596 gst_identity_check_imperfect_offset (identity, buf);
598 /* update prev values */
599 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
600 identity->prev_duration = GST_BUFFER_DURATION (buf);
601 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
602 identity->prev_offset = GST_BUFFER_OFFSET (buf);
604 if (identity->error_after >= 0) {
605 identity->error_after--;
606 if (identity->error_after == 0)
610 if (identity->drop_probability > 0.0) {
611 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
615 if (identity->dump) {
616 gst_util_dump_mem (data, size);
619 if (!identity->silent) {
620 gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
623 if (identity->datarate > 0) {
624 GstClockTime time = gst_util_uint64_scale_int (identity->offset,
625 GST_SECOND, identity->datarate);
627 GST_BUFFER_TIMESTAMP (buf) = time;
628 GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
631 if (identity->signal_handoffs)
632 g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
634 if (trans->segment.format == GST_FORMAT_TIME)
635 runtimestamp = gst_segment_to_running_time (&trans->segment,
636 GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
638 if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
641 GST_OBJECT_LOCK (identity);
642 if ((clock = GST_ELEMENT (identity)->clock)) {
644 GstClockTime timestamp;
646 timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
648 /* save id if we need to unlock */
649 /* FIXME: actually unlock this somewhere in the state changes */
650 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
651 GST_OBJECT_UNLOCK (identity);
653 cret = gst_clock_id_wait (identity->clock_id, NULL);
655 GST_OBJECT_LOCK (identity);
656 if (identity->clock_id) {
657 gst_clock_id_unref (identity->clock_id);
658 identity->clock_id = NULL;
660 if (cret == GST_CLOCK_UNSCHEDULED)
661 ret = GST_FLOW_UNEXPECTED;
663 GST_OBJECT_UNLOCK (identity);
666 identity->offset += size;
668 if (identity->sleep_time && ret == GST_FLOW_OK)
669 g_usleep (identity->sleep_time);
671 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
672 && (ret == GST_FLOW_OK)) {
673 GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
674 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
675 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
678 gst_buffer_unmap (buf, data, size);
685 GST_ELEMENT_ERROR (identity, CORE, FAILED,
686 (_("Failed after iterations as requested.")), (NULL));
687 gst_buffer_unmap (buf, data, size);
688 return GST_FLOW_ERROR;
692 if (!identity->silent) {
693 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
696 gst_buffer_unmap (buf, data, size);
697 /* return DROPPED to basetransform. */
698 return GST_BASE_TRANSFORM_FLOW_DROPPED;
703 gst_identity_set_property (GObject * object, guint prop_id,
704 const GValue * value, GParamSpec * pspec)
706 GstIdentity *identity;
708 identity = GST_IDENTITY (object);
711 case PROP_SLEEP_TIME:
712 identity->sleep_time = g_value_get_uint (value);
715 identity->silent = g_value_get_boolean (value);
717 case PROP_SINGLE_SEGMENT:
718 identity->single_segment = g_value_get_boolean (value);
721 identity->dump = g_value_get_boolean (value);
723 case PROP_ERROR_AFTER:
724 identity->error_after = g_value_get_int (value);
726 case PROP_DROP_PROBABILITY:
727 identity->drop_probability = g_value_get_float (value);
730 identity->datarate = g_value_get_int (value);
733 identity->sync = g_value_get_boolean (value);
735 case PROP_CHECK_PERFECT:
736 identity->check_perfect = g_value_get_boolean (value);
738 case PROP_CHECK_IMPERFECT_TIMESTAMP:
739 identity->check_imperfect_timestamp = g_value_get_boolean (value);
741 case PROP_CHECK_IMPERFECT_OFFSET:
742 identity->check_imperfect_offset = g_value_get_boolean (value);
744 case PROP_SIGNAL_HANDOFFS:
745 identity->signal_handoffs = g_value_get_boolean (value);
748 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
754 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
757 GstIdentity *identity;
759 identity = GST_IDENTITY (object);
762 case PROP_SLEEP_TIME:
763 g_value_set_uint (value, identity->sleep_time);
765 case PROP_ERROR_AFTER:
766 g_value_set_int (value, identity->error_after);
768 case PROP_DROP_PROBABILITY:
769 g_value_set_float (value, identity->drop_probability);
772 g_value_set_int (value, identity->datarate);
775 g_value_set_boolean (value, identity->silent);
777 case PROP_SINGLE_SEGMENT:
778 g_value_set_boolean (value, identity->single_segment);
781 g_value_set_boolean (value, identity->dump);
783 case PROP_LAST_MESSAGE:
784 GST_OBJECT_LOCK (identity);
785 g_value_set_string (value, identity->last_message);
786 GST_OBJECT_UNLOCK (identity);
789 g_value_set_boolean (value, identity->sync);
791 case PROP_CHECK_PERFECT:
792 g_value_set_boolean (value, identity->check_perfect);
794 case PROP_CHECK_IMPERFECT_TIMESTAMP:
795 g_value_set_boolean (value, identity->check_imperfect_timestamp);
797 case PROP_CHECK_IMPERFECT_OFFSET:
798 g_value_set_boolean (value, identity->check_imperfect_offset);
800 case PROP_SIGNAL_HANDOFFS:
801 g_value_set_boolean (value, identity->signal_handoffs);
804 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
810 gst_identity_start (GstBaseTransform * trans)
812 GstIdentity *identity;
814 identity = GST_IDENTITY (trans);
816 identity->offset = 0;
817 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
818 identity->prev_duration = GST_CLOCK_TIME_NONE;
819 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
820 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
826 gst_identity_stop (GstBaseTransform * trans)
828 GstIdentity *identity;
830 identity = GST_IDENTITY (trans);
832 GST_OBJECT_LOCK (identity);
833 g_free (identity->last_message);
834 identity->last_message = NULL;
835 GST_OBJECT_UNLOCK (identity);