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 segments 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 && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
352 if (trans->have_segment == FALSE) {
356 gst_event_parse_segment (event, &segment);
358 /* This is the first segment, send out a (0, -1) segment */
359 gst_segment_init (&segment, segment.format);
360 news = gst_event_new_segment (&segment);
362 gst_pad_event_default (trans->sinkpad, news);
366 /* Reset previous timestamp, duration and offsets on NEWSEGMENT
367 * to prevent false warnings when checking for perfect streams */
368 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
369 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
370 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
373 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->event (trans, event);
375 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
376 /* eat up segments */
384 gst_identity_prepare_output_buffer (GstBaseTransform * trans,
385 GstBuffer * in_buf, gint out_size, GstCaps * out_caps, GstBuffer ** out_buf)
387 GstIdentity *identity = GST_IDENTITY (trans);
389 /* only bother if we may have to alter metadata */
390 if (identity->datarate > 0 || identity->single_segment) {
391 if (gst_buffer_is_writable (in_buf))
392 *out_buf = gst_buffer_ref (in_buf);
394 /* make even less writable */
395 gst_buffer_ref (in_buf);
396 /* extra ref is dropped going through the official process */
397 *out_buf = gst_buffer_make_writable (in_buf);
400 *out_buf = gst_buffer_ref (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];
561 GST_OBJECT_LOCK (identity);
563 g_free (identity->last_message);
564 identity->last_message = g_strdup_printf ("%s ******* (%s:%s)i "
565 "(%" G_GSIZE_FORMAT " bytes, timestamp: %s, duration: %s, offset: %"
566 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT ", flags: %d) %p",
567 action, GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad),
568 size, print_pretty_time (ts_str, sizeof (ts_str),
569 GST_BUFFER_TIMESTAMP (buf)), print_pretty_time (dur_str,
570 sizeof (dur_str), GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf),
571 GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf);
573 GST_OBJECT_UNLOCK (identity);
575 gst_identity_notify_last_message (identity);
579 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
581 GstFlowReturn ret = GST_FLOW_OK;
582 GstIdentity *identity = GST_IDENTITY (trans);
583 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
587 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
589 if (identity->check_perfect)
590 gst_identity_check_perfect (identity, buf);
591 if (identity->check_imperfect_timestamp)
592 gst_identity_check_imperfect_timestamp (identity, buf);
593 if (identity->check_imperfect_offset)
594 gst_identity_check_imperfect_offset (identity, buf);
596 /* update prev values */
597 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
598 identity->prev_duration = GST_BUFFER_DURATION (buf);
599 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
600 identity->prev_offset = GST_BUFFER_OFFSET (buf);
602 if (identity->error_after >= 0) {
603 identity->error_after--;
604 if (identity->error_after == 0)
608 if (identity->drop_probability > 0.0) {
609 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
613 if (identity->dump) {
614 gst_util_dump_mem (data, size);
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 /* FIXME: actually unlock this somewhere in the state changes */
648 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
649 GST_OBJECT_UNLOCK (identity);
651 cret = gst_clock_id_wait (identity->clock_id, NULL);
653 GST_OBJECT_LOCK (identity);
654 if (identity->clock_id) {
655 gst_clock_id_unref (identity->clock_id);
656 identity->clock_id = NULL;
658 if (cret == GST_CLOCK_UNSCHEDULED)
659 ret = GST_FLOW_UNEXPECTED;
661 GST_OBJECT_UNLOCK (identity);
664 identity->offset += size;
666 if (identity->sleep_time && ret == GST_FLOW_OK)
667 g_usleep (identity->sleep_time);
669 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
670 && (ret == GST_FLOW_OK)) {
671 GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
672 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
673 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
676 gst_buffer_unmap (buf, data, size);
683 GST_ELEMENT_ERROR (identity, CORE, FAILED,
684 (_("Failed after iterations as requested.")), (NULL));
685 gst_buffer_unmap (buf, data, size);
686 return GST_FLOW_ERROR;
690 if (!identity->silent) {
691 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
694 gst_buffer_unmap (buf, data, size);
695 /* return DROPPED to basetransform. */
696 return GST_BASE_TRANSFORM_FLOW_DROPPED;
701 gst_identity_set_property (GObject * object, guint prop_id,
702 const GValue * value, GParamSpec * pspec)
704 GstIdentity *identity;
706 identity = GST_IDENTITY (object);
709 case PROP_SLEEP_TIME:
710 identity->sleep_time = g_value_get_uint (value);
713 identity->silent = g_value_get_boolean (value);
715 case PROP_SINGLE_SEGMENT:
716 identity->single_segment = g_value_get_boolean (value);
719 identity->dump = g_value_get_boolean (value);
721 case PROP_ERROR_AFTER:
722 identity->error_after = g_value_get_int (value);
724 case PROP_DROP_PROBABILITY:
725 identity->drop_probability = g_value_get_float (value);
728 identity->datarate = g_value_get_int (value);
731 identity->sync = g_value_get_boolean (value);
733 case PROP_CHECK_PERFECT:
734 identity->check_perfect = g_value_get_boolean (value);
736 case PROP_CHECK_IMPERFECT_TIMESTAMP:
737 identity->check_imperfect_timestamp = g_value_get_boolean (value);
739 case PROP_CHECK_IMPERFECT_OFFSET:
740 identity->check_imperfect_offset = g_value_get_boolean (value);
742 case PROP_SIGNAL_HANDOFFS:
743 identity->signal_handoffs = g_value_get_boolean (value);
746 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
752 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
755 GstIdentity *identity;
757 identity = GST_IDENTITY (object);
760 case PROP_SLEEP_TIME:
761 g_value_set_uint (value, identity->sleep_time);
763 case PROP_ERROR_AFTER:
764 g_value_set_int (value, identity->error_after);
766 case PROP_DROP_PROBABILITY:
767 g_value_set_float (value, identity->drop_probability);
770 g_value_set_int (value, identity->datarate);
773 g_value_set_boolean (value, identity->silent);
775 case PROP_SINGLE_SEGMENT:
776 g_value_set_boolean (value, identity->single_segment);
779 g_value_set_boolean (value, identity->dump);
781 case PROP_LAST_MESSAGE:
782 GST_OBJECT_LOCK (identity);
783 g_value_set_string (value, identity->last_message);
784 GST_OBJECT_UNLOCK (identity);
787 g_value_set_boolean (value, identity->sync);
789 case PROP_CHECK_PERFECT:
790 g_value_set_boolean (value, identity->check_perfect);
792 case PROP_CHECK_IMPERFECT_TIMESTAMP:
793 g_value_set_boolean (value, identity->check_imperfect_timestamp);
795 case PROP_CHECK_IMPERFECT_OFFSET:
796 g_value_set_boolean (value, identity->check_imperfect_offset);
798 case PROP_SIGNAL_HANDOFFS:
799 g_value_set_boolean (value, identity->signal_handoffs);
802 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
808 gst_identity_start (GstBaseTransform * trans)
810 GstIdentity *identity;
812 identity = GST_IDENTITY (trans);
814 identity->offset = 0;
815 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
816 identity->prev_duration = GST_CLOCK_TIME_NONE;
817 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
818 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
824 gst_identity_stop (GstBaseTransform * trans)
826 GstIdentity *identity;
828 identity = GST_IDENTITY (trans);
830 GST_OBJECT_LOCK (identity);
831 g_free (identity->last_message);
832 identity->last_message = NULL;
833 GST_OBJECT_UNLOCK (identity);