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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, 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 "gstelements_private.h"
38 #include "../../gst/gst-i18n-lib.h"
39 #include "gstidentity.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_IMPERFECT_TIMESTAMP FALSE
72 #define DEFAULT_CHECK_IMPERFECT_OFFSET FALSE
73 #define DEFAULT_SIGNAL_HANDOFFS TRUE
80 PROP_DROP_PROBABILITY,
87 PROP_CHECK_IMPERFECT_TIMESTAMP,
88 PROP_CHECK_IMPERFECT_OFFSET,
94 GST_DEBUG_CATEGORY_INIT (gst_identity_debug, "identity", 0, "identity element");
95 #define gst_identity_parent_class parent_class
96 G_DEFINE_TYPE_WITH_CODE (GstIdentity, gst_identity, GST_TYPE_BASE_TRANSFORM,
99 static void gst_identity_finalize (GObject * object);
100 static void gst_identity_set_property (GObject * object, guint prop_id,
101 const GValue * value, GParamSpec * pspec);
102 static void gst_identity_get_property (GObject * object, guint prop_id,
103 GValue * value, GParamSpec * pspec);
105 static gboolean gst_identity_sink_event (GstBaseTransform * trans,
107 static GstFlowReturn gst_identity_transform_ip (GstBaseTransform * trans,
109 static gboolean gst_identity_start (GstBaseTransform * trans);
110 static gboolean gst_identity_stop (GstBaseTransform * trans);
111 static GstStateChangeReturn gst_identity_change_state (GstElement * element,
112 GstStateChange transition);
113 static gboolean gst_identity_accept_caps (GstBaseTransform * base,
114 GstPadDirection direction, GstCaps * caps);
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,
183 PROP_CHECK_IMPERFECT_TIMESTAMP,
184 g_param_spec_boolean ("check-imperfect-timestamp",
185 "Check for discontiguous timestamps",
186 "Send element messages if timestamps and durations do not match up",
187 DEFAULT_CHECK_IMPERFECT_TIMESTAMP,
188 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
189 g_object_class_install_property (gobject_class, PROP_CHECK_IMPERFECT_OFFSET,
190 g_param_spec_boolean ("check-imperfect-offset",
191 "Check for discontiguous offset",
192 "Send element messages if offset and offset_end do not match up",
193 DEFAULT_CHECK_IMPERFECT_OFFSET,
194 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197 * GstIdentity:signal-handoffs
199 * If set to #TRUE, the identity will emit a handoff signal when handling a buffer.
200 * When set to #FALSE, no signal will be emitted, which might improve performance.
202 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
203 g_param_spec_boolean ("signal-handoffs",
204 "Signal handoffs", "Send a signal before pushing the buffer",
205 DEFAULT_SIGNAL_HANDOFFS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
208 * GstIdentity::handoff:
209 * @identity: the identity instance
210 * @buffer: the buffer that just has been received
211 * @pad: the pad that received it
213 * This signal gets emitted before passing the buffer downstream.
215 gst_identity_signals[SIGNAL_HANDOFF] =
216 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
217 G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
218 g_cclosure_marshal_generic, G_TYPE_NONE, 1,
219 GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
221 gobject_class->finalize = gst_identity_finalize;
223 gst_element_class_set_static_metadata (gstelement_class,
226 "Pass data without modification", "Erik Walthinsen <omega@cse.ogi.edu>");
227 gst_element_class_add_pad_template (gstelement_class,
228 gst_static_pad_template_get (&srctemplate));
229 gst_element_class_add_pad_template (gstelement_class,
230 gst_static_pad_template_get (&sinktemplate));
232 gstelement_class->change_state =
233 GST_DEBUG_FUNCPTR (gst_identity_change_state);
235 gstbasetrans_class->sink_event = GST_DEBUG_FUNCPTR (gst_identity_sink_event);
236 gstbasetrans_class->transform_ip =
237 GST_DEBUG_FUNCPTR (gst_identity_transform_ip);
238 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_identity_start);
239 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_identity_stop);
240 gstbasetrans_class->accept_caps =
241 GST_DEBUG_FUNCPTR (gst_identity_accept_caps);
245 gst_identity_init (GstIdentity * identity)
247 identity->sleep_time = DEFAULT_SLEEP_TIME;
248 identity->error_after = DEFAULT_ERROR_AFTER;
249 identity->drop_probability = DEFAULT_DROP_PROBABILITY;
250 identity->datarate = DEFAULT_DATARATE;
251 identity->silent = DEFAULT_SILENT;
252 identity->single_segment = DEFAULT_SINGLE_SEGMENT;
253 identity->sync = DEFAULT_SYNC;
254 identity->check_imperfect_timestamp = DEFAULT_CHECK_IMPERFECT_TIMESTAMP;
255 identity->check_imperfect_offset = DEFAULT_CHECK_IMPERFECT_OFFSET;
256 identity->dump = DEFAULT_DUMP;
257 identity->last_message = NULL;
258 identity->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
260 gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE);
264 gst_identity_notify_last_message (GstIdentity * identity)
266 g_object_notify_by_pspec ((GObject *) identity, pspec_last_message);
270 gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event)
272 GstIdentity *identity;
275 identity = GST_IDENTITY (trans);
277 if (!identity->silent) {
278 const GstStructure *s;
282 GST_OBJECT_LOCK (identity);
283 g_free (identity->last_message);
285 tstr = gst_event_type_get_name (GST_EVENT_TYPE (event));
286 if ((s = gst_event_get_structure (event)))
287 sstr = gst_structure_to_string (s);
289 sstr = g_strdup ("");
291 identity->last_message =
292 g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p",
293 GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event),
296 GST_OBJECT_UNLOCK (identity);
298 gst_identity_notify_last_message (identity);
301 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) {
302 if (!trans->have_segment) {
306 gst_event_copy_segment (event, &segment);
307 gst_event_copy_segment (event, &trans->segment);
308 trans->have_segment = TRUE;
310 /* This is the first segment, send out a (0, -1) segment */
311 gst_segment_init (&segment, segment.format);
312 news = gst_event_new_segment (&segment);
314 gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news);
316 /* need to track segment for proper running time */
317 gst_event_copy_segment (event, &trans->segment);
321 /* also transform GAP timestamp similar to buffer timestamps */
322 if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_GAP) &&
323 trans->have_segment && trans->segment.format == GST_FORMAT_TIME) {
324 GstClockTime start, dur;
326 gst_event_parse_gap (event, &start, &dur);
327 if (GST_CLOCK_TIME_IS_VALID (start)) {
328 start = gst_segment_to_running_time (&trans->segment,
329 GST_FORMAT_TIME, start);
330 gst_event_unref (event);
331 event = gst_event_new_gap (start, dur);
335 /* Reset previous timestamp, duration and offsets on SEGMENT
336 * to prevent false warnings when checking for perfect streams */
337 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
338 identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE;
339 identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
342 if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
343 /* eat up segments */
344 gst_event_unref (event);
347 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
348 GST_OBJECT_LOCK (identity);
349 if (identity->clock_id) {
350 GST_DEBUG_OBJECT (identity, "unlock clock wait");
351 gst_clock_id_unschedule (identity->clock_id);
352 gst_clock_id_unref (identity->clock_id);
353 identity->clock_id = NULL;
355 GST_OBJECT_UNLOCK (identity);
358 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
365 gst_identity_check_imperfect_timestamp (GstIdentity * identity, GstBuffer * buf)
367 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buf);
369 /* invalid timestamp drops us out of check. FIXME: maybe warn ? */
370 if (timestamp != GST_CLOCK_TIME_NONE) {
371 /* check if we had a previous buffer to compare to */
372 if (identity->prev_timestamp != GST_CLOCK_TIME_NONE &&
373 identity->prev_duration != GST_CLOCK_TIME_NONE) {
374 GstClockTime t_expected;
377 t_expected = identity->prev_timestamp + identity->prev_duration;
378 dt = GST_CLOCK_DIFF (t_expected, timestamp);
381 * "imperfect-timestamp" bus message:
382 * @identity: the identity instance
383 * @delta: the GST_CLOCK_DIFF to the prev timestamp
384 * @prev-timestamp: the previous buffer timestamp
385 * @prev-duration: the previous buffer duration
386 * @prev-offset: the previous buffer offset
387 * @prev-offset-end: the previous buffer offset end
388 * @cur-timestamp: the current buffer timestamp
389 * @cur-duration: the current buffer duration
390 * @cur-offset: the current buffer offset
391 * @cur-offset-end: the current buffer offset end
393 * This bus message gets emitted if the check-imperfect-timestamp
394 * property is set and there is a gap in time between the
395 * last buffer and the newly received buffer.
397 gst_element_post_message (GST_ELEMENT (identity),
398 gst_message_new_element (GST_OBJECT (identity),
399 gst_structure_new ("imperfect-timestamp",
400 "delta", G_TYPE_INT64, dt,
401 "prev-timestamp", G_TYPE_UINT64,
402 identity->prev_timestamp, "prev-duration", G_TYPE_UINT64,
403 identity->prev_duration, "prev-offset", G_TYPE_UINT64,
404 identity->prev_offset, "prev-offset-end", G_TYPE_UINT64,
405 identity->prev_offset_end, "cur-timestamp", G_TYPE_UINT64,
406 timestamp, "cur-duration", G_TYPE_UINT64,
407 GST_BUFFER_DURATION (buf), "cur-offset", G_TYPE_UINT64,
408 GST_BUFFER_OFFSET (buf), "cur-offset-end", G_TYPE_UINT64,
409 GST_BUFFER_OFFSET_END (buf), NULL)));
412 GST_DEBUG_OBJECT (identity, "can't check data-contiguity, no "
413 "offset_end was set on previous buffer");
419 gst_identity_check_imperfect_offset (GstIdentity * identity, GstBuffer * buf)
423 offset = GST_BUFFER_OFFSET (buf);
425 if (identity->prev_offset_end != offset &&
426 identity->prev_offset_end != GST_BUFFER_OFFSET_NONE &&
427 offset != GST_BUFFER_OFFSET_NONE) {
429 * "imperfect-offset" bus message:
430 * @identity: the identity instance
431 * @prev-timestamp: the previous buffer timestamp
432 * @prev-duration: the previous buffer duration
433 * @prev-offset: the previous buffer offset
434 * @prev-offset-end: the previous buffer offset end
435 * @cur-timestamp: the current buffer timestamp
436 * @cur-duration: the current buffer duration
437 * @cur-offset: the current buffer offset
438 * @cur-offset-end: the current buffer offset end
440 * This bus message gets emitted if the check-imperfect-offset
441 * property is set and there is a gap in offsets between the
442 * last buffer and the newly received buffer.
444 gst_element_post_message (GST_ELEMENT (identity),
445 gst_message_new_element (GST_OBJECT (identity),
446 gst_structure_new ("imperfect-offset", "prev-timestamp",
447 G_TYPE_UINT64, identity->prev_timestamp, "prev-duration",
448 G_TYPE_UINT64, identity->prev_duration, "prev-offset",
449 G_TYPE_UINT64, identity->prev_offset, "prev-offset-end",
450 G_TYPE_UINT64, identity->prev_offset_end, "cur-timestamp",
451 G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (buf), "cur-duration",
452 G_TYPE_UINT64, GST_BUFFER_DURATION (buf), "cur-offset",
453 G_TYPE_UINT64, GST_BUFFER_OFFSET (buf), "cur-offset-end",
454 G_TYPE_UINT64, GST_BUFFER_OFFSET_END (buf), NULL)));
456 GST_DEBUG_OBJECT (identity, "can't check offset contiguity, no offset "
457 "and/or offset_end were set on previous buffer");
462 print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts)
464 if (ts == GST_CLOCK_TIME_NONE)
467 g_snprintf (ts_str, ts_str_len, "%" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
472 gst_identity_update_last_message_for_buffer (GstIdentity * identity,
473 const gchar * action, GstBuffer * buf, gsize size)
475 gchar dts_str[64], pts_str[64], dur_str[64];
478 GST_OBJECT_LOCK (identity);
480 flag_str = gst_buffer_get_flags_string (buf);
482 g_free (identity->last_message);
483 identity->last_message = g_strdup_printf ("%s ******* (%s:%s) "
484 "(%" G_GSIZE_FORMAT " bytes, dts: %s, pts:%s, duration: %s, offset: %"
485 G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT
486 ", flags: %08x %s) %p", action,
487 GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), size,
488 print_pretty_time (dts_str, sizeof (dts_str), GST_BUFFER_DTS (buf)),
489 print_pretty_time (pts_str, sizeof (pts_str), GST_BUFFER_PTS (buf)),
490 print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)),
491 GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
492 GST_BUFFER_FLAGS (buf), flag_str, buf);
495 GST_OBJECT_UNLOCK (identity);
497 gst_identity_notify_last_message (identity);
501 gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
503 GstFlowReturn ret = GST_FLOW_OK;
504 GstIdentity *identity = GST_IDENTITY (trans);
505 GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
508 size = gst_buffer_get_size (buf);
510 if (identity->check_imperfect_timestamp)
511 gst_identity_check_imperfect_timestamp (identity, buf);
512 if (identity->check_imperfect_offset)
513 gst_identity_check_imperfect_offset (identity, buf);
515 /* update prev values */
516 identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
517 identity->prev_duration = GST_BUFFER_DURATION (buf);
518 identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
519 identity->prev_offset = GST_BUFFER_OFFSET (buf);
521 if (identity->error_after >= 0) {
522 identity->error_after--;
523 if (identity->error_after == 0)
527 if (identity->drop_probability > 0.0) {
528 if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
532 if (identity->dump) {
535 gst_buffer_map (buf, &info, GST_MAP_READ);
536 gst_util_dump_mem (info.data, info.size);
537 gst_buffer_unmap (buf, &info);
540 if (!identity->silent) {
541 gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
544 if (identity->datarate > 0) {
545 GstClockTime time = gst_util_uint64_scale_int (identity->offset,
546 GST_SECOND, identity->datarate);
548 GST_BUFFER_PTS (buf) = GST_BUFFER_DTS (buf) = time;
549 GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
552 if (identity->signal_handoffs)
553 g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
555 if (trans->segment.format == GST_FORMAT_TIME)
556 runtimestamp = gst_segment_to_running_time (&trans->segment,
557 GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
559 if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
562 GST_OBJECT_LOCK (identity);
563 if ((clock = GST_ELEMENT (identity)->clock)) {
565 GstClockTime timestamp;
567 timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
569 /* save id if we need to unlock */
570 identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
571 GST_OBJECT_UNLOCK (identity);
573 cret = gst_clock_id_wait (identity->clock_id, NULL);
575 GST_OBJECT_LOCK (identity);
576 if (identity->clock_id) {
577 gst_clock_id_unref (identity->clock_id);
578 identity->clock_id = NULL;
580 if (cret == GST_CLOCK_UNSCHEDULED)
583 GST_OBJECT_UNLOCK (identity);
586 identity->offset += size;
588 if (identity->sleep_time && ret == GST_FLOW_OK)
589 g_usleep (identity->sleep_time);
591 if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
592 && (ret == GST_FLOW_OK)) {
593 GST_BUFFER_PTS (buf) = GST_BUFFER_DTS (buf) = runtimestamp;
594 GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
595 GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
603 GST_ELEMENT_ERROR (identity, CORE, FAILED,
604 (_("Failed after iterations as requested.")), (NULL));
605 return GST_FLOW_ERROR;
609 if (!identity->silent) {
610 gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
613 /* return DROPPED to basetransform. */
614 return GST_BASE_TRANSFORM_FLOW_DROPPED;
619 gst_identity_set_property (GObject * object, guint prop_id,
620 const GValue * value, GParamSpec * pspec)
622 GstIdentity *identity;
624 identity = GST_IDENTITY (object);
627 case PROP_SLEEP_TIME:
628 identity->sleep_time = g_value_get_uint (value);
631 identity->silent = g_value_get_boolean (value);
633 case PROP_SINGLE_SEGMENT:
634 identity->single_segment = g_value_get_boolean (value);
637 identity->dump = g_value_get_boolean (value);
639 case PROP_ERROR_AFTER:
640 identity->error_after = g_value_get_int (value);
642 case PROP_DROP_PROBABILITY:
643 identity->drop_probability = g_value_get_float (value);
646 identity->datarate = g_value_get_int (value);
649 identity->sync = g_value_get_boolean (value);
651 case PROP_CHECK_IMPERFECT_TIMESTAMP:
652 identity->check_imperfect_timestamp = g_value_get_boolean (value);
654 case PROP_CHECK_IMPERFECT_OFFSET:
655 identity->check_imperfect_offset = g_value_get_boolean (value);
657 case PROP_SIGNAL_HANDOFFS:
658 identity->signal_handoffs = g_value_get_boolean (value);
661 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
664 if (identity->datarate > 0 || identity->single_segment)
665 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), FALSE);
667 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), TRUE);
671 gst_identity_get_property (GObject * object, guint prop_id, GValue * value,
674 GstIdentity *identity;
676 identity = GST_IDENTITY (object);
679 case PROP_SLEEP_TIME:
680 g_value_set_uint (value, identity->sleep_time);
682 case PROP_ERROR_AFTER:
683 g_value_set_int (value, identity->error_after);
685 case PROP_DROP_PROBABILITY:
686 g_value_set_float (value, identity->drop_probability);
689 g_value_set_int (value, identity->datarate);
692 g_value_set_boolean (value, identity->silent);
694 case PROP_SINGLE_SEGMENT:
695 g_value_set_boolean (value, identity->single_segment);
698 g_value_set_boolean (value, identity->dump);
700 case PROP_LAST_MESSAGE:
701 GST_OBJECT_LOCK (identity);
702 g_value_set_string (value, identity->last_message);
703 GST_OBJECT_UNLOCK (identity);
706 g_value_set_boolean (value, identity->sync);
708 case PROP_CHECK_IMPERFECT_TIMESTAMP:
709 g_value_set_boolean (value, identity->check_imperfect_timestamp);
711 case PROP_CHECK_IMPERFECT_OFFSET:
712 g_value_set_boolean (value, identity->check_imperfect_offset);
714 case PROP_SIGNAL_HANDOFFS:
715 g_value_set_boolean (value, identity->signal_handoffs);
718 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
724 gst_identity_start (GstBaseTransform * trans)
726 GstIdentity *identity;
728 identity = GST_IDENTITY (trans);
730 identity->offset = 0;
731 identity->prev_timestamp = GST_CLOCK_TIME_NONE;
732 identity->prev_duration = GST_CLOCK_TIME_NONE;
733 identity->prev_offset_end = GST_BUFFER_OFFSET_NONE;
734 identity->prev_offset = GST_BUFFER_OFFSET_NONE;
740 gst_identity_stop (GstBaseTransform * trans)
742 GstIdentity *identity;
744 identity = GST_IDENTITY (trans);
746 GST_OBJECT_LOCK (identity);
747 g_free (identity->last_message);
748 identity->last_message = NULL;
749 GST_OBJECT_UNLOCK (identity);
755 gst_identity_accept_caps (GstBaseTransform * base,
756 GstPadDirection direction, GstCaps * caps)
761 /* Proxy accept-caps */
763 if (direction == GST_PAD_SRC)
764 pad = GST_BASE_TRANSFORM_SINK_PAD (base);
766 pad = GST_BASE_TRANSFORM_SRC_PAD (base);
768 ret = gst_pad_peer_query_accept_caps (pad, caps);
773 static GstStateChangeReturn
774 gst_identity_change_state (GstElement * element, GstStateChange transition)
776 GstStateChangeReturn ret;
777 GstIdentity *identity = GST_IDENTITY (element);
779 switch (transition) {
780 case GST_STATE_CHANGE_NULL_TO_READY:
782 case GST_STATE_CHANGE_READY_TO_PAUSED:
784 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
786 case GST_STATE_CHANGE_PAUSED_TO_READY:
787 GST_OBJECT_LOCK (identity);
788 if (identity->clock_id) {
789 GST_DEBUG_OBJECT (identity, "unlock clock wait");
790 gst_clock_id_unschedule (identity->clock_id);
791 gst_clock_id_unref (identity->clock_id);
792 identity->clock_id = NULL;
794 GST_OBJECT_UNLOCK (identity);
800 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
802 switch (transition) {
803 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
805 case GST_STATE_CHANGE_PAUSED_TO_READY:
807 case GST_STATE_CHANGE_READY_TO_NULL: