3 * Copyright (C) 2013 Collabora Ltd.
4 * Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>
6 * gst-validate-pad-monitor.c - Validate PadMonitor class
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.1 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.
28 #include "gst-validate-internal.h"
29 #include "gst-validate-pad-monitor.h"
30 #include "gst-validate-element-monitor.h"
31 #include "gst-validate-reporter.h"
36 * SECTION:gst-validate-pad-monitor
37 * @short_description: Class that wraps a #GstPad for Validate checks
42 #define gst_validate_pad_monitor_parent_class parent_class
43 G_DEFINE_TYPE (GstValidatePadMonitor, gst_validate_pad_monitor,
44 GST_TYPE_VALIDATE_MONITOR);
46 #define PENDING_FIELDS "pending-fields"
47 #define AUDIO_TIMESTAMP_TOLERANCE (GST_MSECOND * 100)
49 #define PAD_PARENT_IS_DEMUXER(m) \
50 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
51 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DEMUXER ( \
52 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
55 #define PAD_PARENT_IS_DECODER(m) \
56 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
57 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER ( \
58 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
61 #define PAD_PARENT_IS_ENCODER(m) \
62 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
63 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER ( \
64 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
69 * Locking the parent should always be done before locking the
70 * pad-monitor to prevent deadlocks in case another monitor from
71 * another pad on the same element starts an operation that also
72 * requires locking itself and some other monitors from internally
76 * An element has a sink and a src pad. Some test starts running at sinkpad
77 * and it locks the parent, and then it locks itself. In case it needs to get
78 * some information from the srcpad, it is able to lock the srcpad and get it
79 * because the srcpad should never lock itself before locking the parent (which
80 * it won't be able as sinkpad already locked it).
82 * As a side one, it is possible that srcpad locks itself without locking the
83 * parent in case it wants to do a check that won't need to use other internally
84 * linked pads (sinkpad). But in this case it might lock and unlock freely without
87 #define GST_VALIDATE_PAD_MONITOR_PARENT_LOCK(m) \
89 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
90 GST_VALIDATE_MONITOR_LOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
92 GST_WARNING_OBJECT (m, "No parent found, can't lock"); \
96 #define GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK(m) \
98 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
99 GST_VALIDATE_MONITOR_UNLOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
101 GST_WARNING_OBJECT (m, "No parent found, can't unlock"); \
107 GstClockTime timestamp;
109 } SerializedEventData;
112 debug_pending_event (GstPad * pad, GPtrArray * array)
117 for (i = 0; i < len; i++) {
118 SerializedEventData *data = g_ptr_array_index (array, i);
119 GST_DEBUG_OBJECT (pad, "event #%d %" GST_TIME_FORMAT " %s %p",
120 i, GST_TIME_ARGS (data->timestamp),
121 GST_EVENT_TYPE_NAME (data->event), data->event);
126 _serialized_event_data_free (SerializedEventData * serialized_event)
128 gst_event_unref (serialized_event->event);
129 g_slice_free (SerializedEventData, serialized_event);
132 static gboolean gst_validate_pad_monitor_do_setup (GstValidateMonitor *
134 static GstElement *gst_validate_pad_monitor_get_element (GstValidateMonitor *
137 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
139 static void gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor *
140 pad_monitor, GstCaps * caps, gboolean ret);
142 #define PAD_IS_IN_PUSH_MODE(p) ((p)->mode == GST_PAD_MODE_PUSH)
145 _structure_is_raw_video (GstStructure * structure)
147 return gst_structure_has_name (structure, "video/x-raw");
151 _structure_is_raw_audio (GstStructure * structure)
153 return gst_structure_has_name (structure, "audio/x-raw");
157 _check_field_type (GstValidatePadMonitor * monitor, GstStructure * structure,
158 const gchar * field, ...)
162 gchar *joined_types = NULL;
163 const gchar *rejected_types[5];
164 gint rejected_types_index = 0;
166 if (!gst_structure_has_field (structure, field)) {
167 GST_VALIDATE_REPORT (monitor, CAPS_IS_MISSING_FIELD,
168 "Field '%s' is missing from structure: %" GST_PTR_FORMAT, field,
173 memset (rejected_types, 0, sizeof (rejected_types));
174 va_start (var_args, field);
175 while ((type = va_arg (var_args, GType)) != 0) {
176 if (gst_structure_has_field_typed (structure, field, type)) {
180 rejected_types[rejected_types_index++] = g_type_name (type);
184 joined_types = g_strjoinv (" / ", (gchar **) rejected_types);
185 GST_VALIDATE_REPORT (monitor, CAPS_FIELD_HAS_BAD_TYPE,
186 "Field '%s' has wrong type %s in structure '%" GST_PTR_FORMAT
187 "'. Expected: %s", field,
188 g_type_name (gst_structure_get_field_type (structure, field)), structure,
190 g_free (joined_types);
194 gst_validate_pad_monitor_check_raw_video_caps_complete (GstValidatePadMonitor *
195 monitor, GstStructure * structure)
197 _check_field_type (monitor, structure, "width", G_TYPE_INT,
198 GST_TYPE_INT_RANGE, 0);
199 _check_field_type (monitor, structure, "height", G_TYPE_INT,
200 GST_TYPE_INT_RANGE, 0);
201 _check_field_type (monitor, structure, "framerate", GST_TYPE_FRACTION,
202 GST_TYPE_FRACTION_RANGE, 0);
203 _check_field_type (monitor, structure, "pixel-aspect-ratio",
204 GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, 0);
205 _check_field_type (monitor, structure, "format", G_TYPE_STRING,
210 gst_validate_pad_monitor_check_raw_audio_caps_complete (GstValidatePadMonitor *
211 monitor, GstStructure * structure)
214 _check_field_type (monitor, structure, "format", G_TYPE_STRING, GST_TYPE_LIST,
216 _check_field_type (monitor, structure, "layout", G_TYPE_STRING, GST_TYPE_LIST,
218 _check_field_type (monitor, structure, "rate", G_TYPE_INT, GST_TYPE_LIST,
219 GST_TYPE_INT_RANGE, 0);
220 _check_field_type (monitor, structure, "channels", G_TYPE_INT, GST_TYPE_LIST,
221 GST_TYPE_INT_RANGE, 0);
222 if (gst_structure_get_int(structure, "channels", &channels)) {
224 _check_field_type (monitor, structure, "channel-mask", GST_TYPE_BITMASK,
230 gst_validate_pad_monitor_check_caps_complete (GstValidatePadMonitor * monitor,
233 GstStructure *structure;
236 GST_DEBUG_OBJECT (monitor->pad, "Checking caps %" GST_PTR_FORMAT, caps);
238 for (i = 0; i < gst_caps_get_size (caps); i++) {
239 structure = gst_caps_get_structure (caps, i);
241 if (_structure_is_raw_video (structure)) {
242 gst_validate_pad_monitor_check_raw_video_caps_complete (monitor,
245 } else if (_structure_is_raw_audio (structure)) {
246 gst_validate_pad_monitor_check_raw_audio_caps_complete (monitor,
253 gst_validate_pad_monitor_get_othercaps (GstValidatePadMonitor * monitor)
255 GstCaps *caps = gst_caps_new_empty ();
262 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
266 GValue value = { 0, };
267 switch (gst_iterator_next (iter, &value)) {
268 case GST_ITERATOR_OK:
269 otherpad = g_value_get_object (&value);
271 /* TODO What would be the correct caps operation to merge the caps in
272 * case one sink is internally linked to multiple srcs? */
273 peercaps = gst_pad_peer_query_caps (otherpad, NULL);
275 caps = gst_caps_merge (caps, peercaps);
277 g_value_reset (&value);
279 case GST_ITERATOR_RESYNC:
280 gst_iterator_resync (iter);
281 gst_caps_replace (&caps, gst_caps_new_empty ());
283 case GST_ITERATOR_ERROR:
284 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
287 case GST_ITERATOR_DONE:
292 gst_iterator_free (iter);
294 GST_DEBUG_OBJECT (monitor->pad, "Otherpad caps: %" GST_PTR_FORMAT, caps);
300 _structure_is_video (GstStructure * structure)
302 const gchar *name = gst_structure_get_name (structure);
304 return g_strstr_len (name, 6, "video/")
305 && strcmp (name, "video/quicktime") != 0;
309 _structure_is_audio (GstStructure * structure)
311 const gchar *name = gst_structure_get_name (structure);
313 return g_strstr_len (name, 6, "audio/") != NULL;
317 gst_validate_pad_monitor_pad_should_proxy_othercaps (GstValidatePadMonitor *
320 GstValidateMonitor *parent = GST_VALIDATE_MONITOR_GET_PARENT (monitor);
325 /* We only know how to handle othercaps checks for codecs so far */
326 return GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER (parent) ||
327 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER (parent);
331 /* Check if the field @f from @s2 (if present) is represented in @s1
332 * Represented here means either equal or @s1's value is in a list/range
336 _structures_field_is_contained (GstStructure * s1, GstStructure * s2,
342 v2 = gst_structure_get_value (s2, f);
344 return TRUE; /* nothing to compare to */
346 v1 = gst_structure_get_value (s1, f);
350 if (!gst_value_is_fixed (v1) && !gst_value_is_fixed (v2))
353 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
356 if (GST_VALUE_HOLDS_LIST (v2)) {
358 for (i = 0; i < gst_value_list_get_size (v2); i++) {
359 const GValue *v2_subvalue = gst_value_list_get_value (v2, i);
360 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
365 if (GST_VALUE_HOLDS_ARRAY (v2)) {
367 for (i = 0; i < gst_value_array_get_size (v2); i++) {
368 const GValue *v2_subvalue = gst_value_array_get_value (v2, i);
369 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
374 if (GST_VALUE_HOLDS_INT_RANGE (v2)) {
377 min = gst_value_get_int_range_min (v2);
378 max = gst_value_get_int_range_max (v2);
380 if (G_VALUE_HOLDS_INT (v1)) {
381 gint v = g_value_get_int (v1);
383 return v >= min && v <= max;
385 /* TODO compare int ranges with int ranges
386 * or with lists if useful */
390 if (GST_VALUE_HOLDS_FRACTION_RANGE (v2)) {
391 const GValue *min, *max;
393 min = gst_value_get_fraction_range_min (v2);
394 max = gst_value_get_fraction_range_max (v2);
396 if (GST_VALUE_HOLDS_FRACTION (v1)) {
397 gint v_min = gst_value_compare (v1, min);
398 gint v_max = gst_value_compare (v1, max);
400 return (v_min == GST_VALUE_EQUAL || v_min == GST_VALUE_GREATER_THAN) &&
401 (v_max == GST_VALUE_EQUAL || v_max == GST_VALUE_LESS_THAN);
403 /* TODO compare fraction ranges with fraction ranges
404 * or with lists if useful */
412 gst_validate_pad_monitor_check_caps_fields_proxied (GstValidatePadMonitor *
413 monitor, GstCaps * caps)
415 GstStructure *structure;
416 GstStructure *otherstructure;
420 if (!gst_validate_pad_monitor_pad_should_proxy_othercaps (monitor))
423 othercaps = gst_validate_pad_monitor_get_othercaps (monitor);
425 for (i = 0; i < gst_caps_get_size (othercaps); i++) {
426 gboolean found = FALSE;
427 gboolean type_match = FALSE;
429 otherstructure = gst_caps_get_structure (othercaps, i);
431 /* look for a proxied version of 'otherstructure' */
432 if (_structure_is_video (otherstructure)) {
433 for (j = 0; j < gst_caps_get_size (caps); j++) {
434 structure = gst_caps_get_structure (caps, j);
435 if (_structure_is_video (structure)) {
437 if (_structures_field_is_contained (structure, otherstructure,
439 && _structures_field_is_contained (structure, otherstructure,
441 && _structures_field_is_contained (structure, otherstructure,
443 && _structures_field_is_contained (structure, otherstructure,
444 "pixel-aspect-ratio")) {
450 } else if (_structure_is_audio (otherstructure)) {
451 for (j = 0; j < gst_caps_get_size (caps); j++) {
452 structure = gst_caps_get_structure (caps, j);
453 if (_structure_is_audio (structure)) {
455 if (_structures_field_is_contained (structure, otherstructure, "rate")
456 && _structures_field_is_contained (structure, otherstructure,
465 if (type_match && !found) {
466 GST_VALIDATE_REPORT (monitor, GET_CAPS_NOT_PROXYING_FIELDS,
467 "Peer pad structure '%" GST_PTR_FORMAT "' has no similar version "
468 "on pad's caps '%" GST_PTR_FORMAT "'", otherstructure, caps);
474 gst_validate_pad_monitor_check_late_serialized_events (GstValidatePadMonitor *
475 monitor, GstClockTime ts)
479 if (!GST_CLOCK_TIME_IS_VALID (ts))
482 GST_DEBUG_OBJECT (monitor->pad, "Timestamp to check %" GST_TIME_FORMAT,
485 for (i = 0; i < monitor->serialized_events->len; i++) {
486 SerializedEventData *data =
487 g_ptr_array_index (monitor->serialized_events, i);
489 GST_DEBUG_OBJECT (monitor->pad, "Event #%d (%s) ts: %" GST_TIME_FORMAT,
490 i, GST_EVENT_TYPE_NAME (data->event), GST_TIME_ARGS (data->timestamp));
492 if (GST_CLOCK_TIME_IS_VALID (data->timestamp) && data->timestamp < ts) {
493 GST_VALIDATE_REPORT (monitor, SERIALIZED_EVENT_WASNT_PUSHED_IN_TIME,
494 "Serialized event %" GST_PTR_FORMAT " wasn't pushed before expected "
495 "timestamp %" GST_TIME_FORMAT " on pad %s:%s", data->event,
496 GST_TIME_ARGS (data->timestamp),
497 GST_DEBUG_PAD_NAME (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor)));
499 /* events should be ordered by ts */
505 debug_pending_event (monitor->pad, monitor->serialized_events);
506 g_ptr_array_remove_range (monitor->serialized_events, 0, i);
511 gst_validate_pad_monitor_dispose (GObject * object)
513 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (object);
514 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
517 if (monitor->pad_probe_id)
518 gst_pad_remove_probe (pad, monitor->pad_probe_id);
521 if (monitor->expected_segment)
522 gst_event_unref (monitor->expected_segment);
524 gst_structure_free (monitor->pending_setcaps_fields);
525 g_ptr_array_unref (monitor->serialized_events);
526 g_list_free_full (monitor->expired_events, (GDestroyNotify) gst_event_unref);
528 G_OBJECT_CLASS (parent_class)->dispose (object);
532 gst_validate_pad_monitor_class_init (GstValidatePadMonitorClass * klass)
534 GObjectClass *gobject_class;
535 GstValidateMonitorClass *monitor_klass;
537 gobject_class = G_OBJECT_CLASS (klass);
538 monitor_klass = GST_VALIDATE_MONITOR_CLASS (klass);
540 gobject_class->dispose = gst_validate_pad_monitor_dispose;
542 monitor_klass->setup = gst_validate_pad_monitor_do_setup;
543 monitor_klass->get_element = gst_validate_pad_monitor_get_element;
547 gst_validate_pad_monitor_init (GstValidatePadMonitor * pad_monitor)
549 pad_monitor->pending_setcaps_fields =
550 gst_structure_new_empty (PENDING_FIELDS);
551 pad_monitor->serialized_events =
552 g_ptr_array_new_with_free_func ((GDestroyNotify)
553 _serialized_event_data_free);
554 pad_monitor->expired_events = NULL;
555 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
556 pad_monitor->first_buffer = TRUE;
558 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
559 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
563 * gst_validate_pad_monitor_new:
564 * @pad: (transfer-none): a #GstPad to run Validate on
566 GstValidatePadMonitor *
567 gst_validate_pad_monitor_new (GstPad * pad, GstValidateRunner * runner,
568 GstValidateElementMonitor * parent)
570 GstValidatePadMonitor *monitor = g_object_new (GST_TYPE_VALIDATE_PAD_MONITOR,
571 "object", pad, "validate-runner", runner, "validate-parent",
574 if (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor) == NULL) {
575 g_object_unref (monitor);
582 gst_validate_pad_monitor_get_element (GstValidateMonitor * monitor)
584 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
586 return GST_PAD_PARENT (pad);
590 gst_validate_pad_monitor_event_overrides (GstValidatePadMonitor * pad_monitor,
595 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
596 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
597 iter = g_list_next (iter)) {
598 GstValidateOverride *override = iter->data;
600 gst_validate_override_event_handler (override,
601 GST_VALIDATE_MONITOR_CAST (pad_monitor), event);
603 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
607 gst_validate_pad_monitor_buffer_overrides (GstValidatePadMonitor * pad_monitor,
612 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
613 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
614 iter = g_list_next (iter)) {
615 GstValidateOverride *override = iter->data;
617 gst_validate_override_buffer_handler (override,
618 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
620 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
624 gst_validate_pad_monitor_buffer_probe_overrides (GstValidatePadMonitor *
625 pad_monitor, GstBuffer * buffer)
629 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
630 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
631 iter = g_list_next (iter)) {
632 GstValidateOverride *override = iter->data;
634 gst_validate_override_buffer_probe_handler (override,
635 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
637 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
641 gst_validate_pad_monitor_query_overrides (GstValidatePadMonitor * pad_monitor,
646 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
647 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
648 iter = g_list_next (iter)) {
649 GstValidateOverride *override = iter->data;
651 gst_validate_override_query_handler (override,
652 GST_VALIDATE_MONITOR_CAST (pad_monitor), query);
654 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
658 gst_validate_pad_monitor_setcaps_overrides (GstValidatePadMonitor * pad_monitor,
663 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
664 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
665 iter = g_list_next (iter)) {
666 GstValidateOverride *override = iter->data;
668 gst_validate_override_setcaps_handler (override,
669 GST_VALIDATE_MONITOR_CAST (pad_monitor), caps);
671 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
674 /* FIXME : This is a bit dubious, what's the point of this check ? */
676 gst_validate_pad_monitor_timestamp_is_in_received_range (GstValidatePadMonitor *
677 monitor, GstClockTime ts, GstClockTime tolerance)
679 GST_DEBUG_OBJECT (monitor->pad, "Checking if timestamp %" GST_TIME_FORMAT
680 " is in range: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT " for pad "
681 "%s:%s with tolerance: %" GST_TIME_FORMAT, GST_TIME_ARGS (ts),
682 GST_TIME_ARGS (monitor->timestamp_range_start),
683 GST_TIME_ARGS (monitor->timestamp_range_end),
684 GST_DEBUG_PAD_NAME (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor)),
685 GST_TIME_ARGS (tolerance));
686 return !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_start) ||
687 !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_end) ||
688 ((monitor->timestamp_range_start >= tolerance ?
689 monitor->timestamp_range_start - tolerance : 0) <= ts
690 && (ts >= tolerance ? ts - tolerance : 0) <=
691 monitor->timestamp_range_end);
694 /* Iterates over internal links (sinkpads) to check that this buffer has
695 * a timestamp that is in the range of the lastly received buffers */
697 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range
698 (GstValidatePadMonitor * monitor, GstBuffer * buffer,
699 GstClockTime tolerance)
704 gboolean has_one = FALSE;
705 gboolean found = FALSE;
708 GstValidatePadMonitor *othermonitor;
710 if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))
711 || !GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
712 GST_DEBUG_OBJECT (monitor->pad,
713 "Can't check buffer timestamps range as "
714 "buffer has no valid timestamp/duration");
717 ts = GST_BUFFER_TIMESTAMP (buffer);
718 ts_end = ts + GST_BUFFER_DURATION (buffer);
721 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
725 GST_WARNING_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor),
726 "No iterator available");
732 GValue value = { 0, };
733 switch (gst_iterator_next (iter, &value)) {
734 case GST_ITERATOR_OK:
735 otherpad = g_value_get_object (&value);
736 GST_DEBUG_OBJECT (monitor->pad, "Checking pad %s:%s input timestamps",
737 GST_DEBUG_PAD_NAME (otherpad));
739 g_object_get_data ((GObject *) otherpad, "validate-monitor");
740 GST_VALIDATE_MONITOR_LOCK (othermonitor);
741 if (gst_validate_pad_monitor_timestamp_is_in_received_range
742 (othermonitor, ts, tolerance)
744 gst_validate_pad_monitor_timestamp_is_in_received_range
745 (othermonitor, ts_end, tolerance)) {
749 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
750 g_value_reset (&value);
753 case GST_ITERATOR_RESYNC:
754 gst_iterator_resync (iter);
758 case GST_ITERATOR_ERROR:
759 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
762 case GST_ITERATOR_DONE:
767 gst_iterator_free (iter);
770 GST_DEBUG_OBJECT (monitor->pad, "Skipping timestamp in range check as no "
771 "internal linked pad was found");
775 GST_VALIDATE_REPORT (monitor, BUFFER_TIMESTAMP_OUT_OF_RECEIVED_RANGE,
776 "Timestamp %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT
777 " is out of range of received input", GST_TIME_ARGS (ts),
778 GST_TIME_ARGS (ts_end));
783 gst_validate_pad_monitor_check_first_buffer (GstValidatePadMonitor *
784 pad_monitor, GstBuffer * buffer)
786 if (G_UNLIKELY (pad_monitor->first_buffer)) {
787 pad_monitor->first_buffer = FALSE;
789 if (!pad_monitor->has_segment
790 && PAD_IS_IN_PUSH_MODE (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor)))
792 GST_VALIDATE_REPORT (pad_monitor, BUFFER_BEFORE_SEGMENT,
793 "Received buffer before Segment event");
795 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
796 gint64 running_time = gst_segment_to_running_time (&pad_monitor->segment,
797 pad_monitor->segment.format, GST_BUFFER_TIMESTAMP (buffer));
798 if (running_time != 0) {
799 GST_VALIDATE_REPORT (pad_monitor, FIRST_BUFFER_RUNNING_TIME_IS_NOT_ZERO,
800 "First buffer running time is not 0, it is: %" GST_TIME_FORMAT,
801 GST_TIME_ARGS (running_time));
808 gst_validate_pad_monitor_update_buffer_data (GstValidatePadMonitor *
809 pad_monitor, GstBuffer * buffer)
811 pad_monitor->current_timestamp = GST_BUFFER_TIMESTAMP (buffer);
812 pad_monitor->current_duration = GST_BUFFER_DURATION (buffer);
813 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
814 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_start)) {
815 pad_monitor->timestamp_range_start =
816 MIN (pad_monitor->timestamp_range_start,
817 GST_BUFFER_TIMESTAMP (buffer));
819 pad_monitor->timestamp_range_start = GST_BUFFER_TIMESTAMP (buffer);
822 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
824 GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
825 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_end)) {
826 pad_monitor->timestamp_range_end =
827 MAX (pad_monitor->timestamp_range_end, endts);
829 pad_monitor->timestamp_range_end = endts;
833 GST_DEBUG_OBJECT (pad_monitor->pad, "Current stored range: %" GST_TIME_FORMAT
834 " - %" GST_TIME_FORMAT,
835 GST_TIME_ARGS (pad_monitor->timestamp_range_start),
836 GST_TIME_ARGS (pad_monitor->timestamp_range_end));
840 _combine_flows (GstFlowReturn ret1, GstFlowReturn ret2)
844 if (ret1 <= GST_FLOW_NOT_NEGOTIATED)
846 if (ret2 <= GST_FLOW_NOT_NEGOTIATED)
848 if (ret1 == GST_FLOW_FLUSHING || ret2 == GST_FLOW_FLUSHING)
849 return GST_FLOW_FLUSHING;
850 if (ret1 == GST_FLOW_OK || ret2 == GST_FLOW_OK)
856 gst_validate_pad_monitor_check_aggregated_return (GstValidatePadMonitor *
857 monitor, GstFlowReturn ret)
863 GstValidatePadMonitor *othermonitor;
864 GstFlowReturn aggregated = GST_FLOW_NOT_LINKED;
865 gboolean found_a_pad = FALSE;
866 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
868 iter = gst_pad_iterate_internal_links (pad);
871 GValue value = { 0, };
872 switch (gst_iterator_next (iter, &value)) {
873 case GST_ITERATOR_OK:
874 otherpad = g_value_get_object (&value);
875 peerpad = gst_pad_get_peer (otherpad);
878 g_object_get_data ((GObject *) peerpad, "validate-monitor");
881 GST_VALIDATE_MONITOR_LOCK (othermonitor);
883 _combine_flows (aggregated, othermonitor->last_flow_return);
884 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
887 gst_object_unref (peerpad);
889 g_value_reset (&value);
891 case GST_ITERATOR_RESYNC:
892 gst_iterator_resync (iter);
894 case GST_ITERATOR_ERROR:
895 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
898 case GST_ITERATOR_DONE:
903 gst_iterator_free (iter);
905 /* no peer pad found, nothing to do */
908 if (aggregated == GST_FLOW_OK || aggregated == GST_FLOW_EOS) {
909 /* those are acceptable situations */
911 if (GST_PAD_IS_FLUSHING (pad) && ret == GST_FLOW_FLUSHING) {
912 /* pad is flushing, always acceptable to return flushing */
916 if (monitor->is_eos && ret == GST_FLOW_EOS) {
917 /* this element received eos and returned eos */
921 if (PAD_PARENT_IS_DEMUXER (monitor) && ret == GST_FLOW_EOS) {
922 /* a demuxer can return EOS when the samples end */
927 if (aggregated != ret) {
928 GST_VALIDATE_REPORT (monitor, WRONG_FLOW_RETURN,
929 "Wrong combined flow return %s(%d). Expected: %s(%d)",
930 gst_flow_get_name (ret), ret, gst_flow_get_name (aggregated),
936 gst_validate_pad_monitor_otherpad_add_pending_serialized_event
937 (GstValidatePadMonitor * monitor, GstEvent * event, GstClockTime last_ts)
942 GstValidatePadMonitor *othermonitor;
944 if (!GST_EVENT_IS_SERIALIZED (event))
948 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
951 /* inputselector will return NULL if the sinkpad is not the active one .... */
952 GST_FIXME_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD
953 (monitor), "No iterator");
958 GValue value = { 0, };
959 switch (gst_iterator_next (iter, &value)) {
960 case GST_ITERATOR_OK:
961 otherpad = g_value_get_object (&value);
963 g_object_get_data ((GObject *) otherpad, "validate-monitor");
965 SerializedEventData *data = g_slice_new0 (SerializedEventData);
966 data->timestamp = last_ts;
967 data->event = gst_event_ref (event);
968 GST_VALIDATE_MONITOR_LOCK (othermonitor);
969 GST_DEBUG_OBJECT (monitor->pad, "Storing for pad %s:%s event %p %s",
970 GST_DEBUG_PAD_NAME (otherpad), event,
971 GST_EVENT_TYPE_NAME (event));
972 g_ptr_array_add (othermonitor->serialized_events, data);
973 debug_pending_event (otherpad, othermonitor->serialized_events);
974 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
976 g_value_reset (&value);
978 case GST_ITERATOR_RESYNC:
979 gst_iterator_resync (iter);
981 case GST_ITERATOR_ERROR:
982 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
985 case GST_ITERATOR_DONE:
990 gst_iterator_free (iter);
994 gst_validate_pad_monitor_otherpad_add_pending_field (GstValidatePadMonitor *
995 monitor, GstStructure * structure, const gchar * field)
1000 GstValidatePadMonitor *othermonitor;
1003 v = gst_structure_get_value (structure, field);
1005 GST_DEBUG_OBJECT (monitor->pad, "Not adding pending field %s as it isn't "
1006 "present on structure %" GST_PTR_FORMAT, field, structure);
1011 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1015 GValue value = { 0, };
1016 switch (gst_iterator_next (iter, &value)) {
1017 case GST_ITERATOR_OK:
1018 otherpad = g_value_get_object (&value);
1020 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1022 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1023 g_assert (othermonitor->pending_setcaps_fields != NULL);
1024 gst_structure_set_value (othermonitor->pending_setcaps_fields,
1026 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1028 g_value_reset (&value);
1030 case GST_ITERATOR_RESYNC:
1031 gst_iterator_resync (iter);
1033 case GST_ITERATOR_ERROR:
1034 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1037 case GST_ITERATOR_DONE:
1042 gst_iterator_free (iter);
1046 gst_validate_pad_monitor_otherpad_clear_pending_fields (GstValidatePadMonitor *
1052 GstValidatePadMonitor *othermonitor;
1055 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1059 GValue value = { 0, };
1060 switch (gst_iterator_next (iter, &value)) {
1061 case GST_ITERATOR_OK:
1062 otherpad = g_value_get_object (&value);
1064 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1066 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1067 g_assert (othermonitor->pending_setcaps_fields != NULL);
1068 gst_structure_free (othermonitor->pending_setcaps_fields);
1069 othermonitor->pending_setcaps_fields =
1070 gst_structure_new_empty (PENDING_FIELDS);
1071 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1073 g_value_reset (&value);
1075 case GST_ITERATOR_RESYNC:
1076 gst_iterator_resync (iter);
1078 case GST_ITERATOR_ERROR:
1079 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1082 case GST_ITERATOR_DONE:
1087 gst_iterator_free (iter);
1091 gst_validate_pad_monitor_add_expected_newsegment (GstValidatePadMonitor *
1092 monitor, GstEvent * event)
1097 GstValidatePadMonitor *othermonitor;
1100 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1104 GValue value = { 0, };
1105 switch (gst_iterator_next (iter, &value)) {
1106 case GST_ITERATOR_OK:
1107 otherpad = g_value_get_object (&value);
1109 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1110 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1111 gst_event_replace (&othermonitor->expected_segment, event);
1112 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1113 g_value_reset (&value);
1115 case GST_ITERATOR_RESYNC:
1116 gst_iterator_resync (iter);
1118 case GST_ITERATOR_ERROR:
1119 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1122 case GST_ITERATOR_DONE:
1127 gst_iterator_free (iter);
1131 gst_validate_pad_monitor_flush (GstValidatePadMonitor * pad_monitor)
1133 pad_monitor->current_timestamp = GST_CLOCK_TIME_NONE;
1134 pad_monitor->current_duration = GST_CLOCK_TIME_NONE;
1135 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
1136 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
1137 pad_monitor->has_segment = FALSE;
1138 pad_monitor->is_eos = FALSE;
1139 pad_monitor->last_flow_return = GST_FLOW_OK;
1140 gst_caps_replace (&pad_monitor->last_caps, NULL);
1141 pad_monitor->caps_is_audio = pad_monitor->caps_is_video = FALSE;
1143 g_list_free_full (pad_monitor->expired_events,
1144 (GDestroyNotify) gst_event_unref);
1145 pad_monitor->expired_events = NULL;
1147 if (pad_monitor->serialized_events->len)
1148 g_ptr_array_remove_range (pad_monitor->serialized_events, 0,
1149 pad_monitor->serialized_events->len);
1152 /* common checks for both sink and src event functions */
1154 gst_validate_pad_monitor_common_event_check (GstValidatePadMonitor *
1155 pad_monitor, GstEvent * event)
1157 guint32 seqnum = gst_event_get_seqnum (event);
1159 switch (GST_EVENT_TYPE (event)) {
1160 case GST_EVENT_FLUSH_START:
1162 if (pad_monitor->pending_flush_start_seqnum) {
1163 if (seqnum == pad_monitor->pending_flush_start_seqnum) {
1164 pad_monitor->pending_flush_start_seqnum = 0;
1166 GST_VALIDATE_REPORT (pad_monitor, EVENT_HAS_WRONG_SEQNUM,
1167 "The expected flush-start seqnum should be the same as the "
1168 "one from the event that caused it (probably a seek). Got: %u."
1169 " Expected: %u", seqnum, pad_monitor->pending_flush_start_seqnum);
1173 if (pad_monitor->pending_flush_stop) {
1174 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1175 "Received flush-start from " " when flush-stop was expected");
1177 pad_monitor->pending_flush_stop = TRUE;
1180 case GST_EVENT_FLUSH_STOP:
1182 if (pad_monitor->pending_flush_stop_seqnum) {
1183 if (seqnum == pad_monitor->pending_flush_stop_seqnum) {
1184 pad_monitor->pending_flush_stop_seqnum = 0;
1186 GST_VALIDATE_REPORT (pad_monitor, EVENT_HAS_WRONG_SEQNUM,
1187 "The expected flush-stop seqnum should be the same as the "
1188 "one from the event that caused it (probably a seek). Got: %u."
1189 " Expected: %u", seqnum, pad_monitor->pending_flush_stop_seqnum);
1193 if (!pad_monitor->pending_flush_stop) {
1194 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_STOP_UNEXPECTED,
1195 "Unexpected flush-stop %p" GST_PTR_FORMAT, event);
1197 pad_monitor->pending_flush_stop = FALSE;
1199 /* cleanup our data */
1200 gst_validate_pad_monitor_flush (pad_monitor);
1209 gst_validate_pad_monitor_downstream_event_check (GstValidatePadMonitor *
1210 pad_monitor, GstObject * parent, GstEvent * event,
1211 GstPadEventFunction handler)
1213 gboolean ret = TRUE;
1214 const GstSegment *segment;
1215 guint32 seqnum = gst_event_get_seqnum (event);
1216 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1218 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1221 switch (GST_EVENT_TYPE (event)) {
1222 case GST_EVENT_SEGMENT:
1223 /* parse segment data to be used if event is handled */
1224 gst_event_parse_segment (event, &segment);
1226 if (pad_monitor->pending_newsegment_seqnum) {
1227 if (pad_monitor->pending_newsegment_seqnum == seqnum) {
1228 pad_monitor->pending_newsegment_seqnum = 0;
1230 /* TODO is this an error? could be a segment from the start
1231 * received just before the seek segment */
1235 /* got a segment, no need for EOS now */
1236 pad_monitor->pending_eos_seqnum = 0;
1238 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1239 gst_validate_pad_monitor_add_expected_newsegment (pad_monitor, event);
1241 /* check if this segment is the expected one */
1242 if (pad_monitor->expected_segment) {
1243 const GstSegment *exp_segment;
1245 if (pad_monitor->expected_segment != event) {
1246 gst_event_parse_segment (pad_monitor->expected_segment,
1248 if (segment->format == exp_segment->format) {
1249 if ((exp_segment->rate * exp_segment->applied_rate !=
1250 segment->rate * segment->applied_rate)
1251 || exp_segment->start != segment->start
1252 || exp_segment->stop != segment->stop
1253 || exp_segment->position != segment->position) {
1254 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1255 "Expected segment didn't match received segment event");
1259 gst_event_replace (&pad_monitor->expected_segment, NULL);
1263 case GST_EVENT_CAPS:{
1266 gst_event_parse_caps (event, &caps);
1267 gst_validate_pad_monitor_setcaps_pre (pad_monitor, caps);
1271 pad_monitor->is_eos = TRUE;
1272 if (pad_monitor->pending_eos_seqnum &&
1273 pad_monitor->pending_eos_seqnum != seqnum) {
1274 GST_VALIDATE_REPORT (pad_monitor, EVENT_HAS_WRONG_SEQNUM,
1275 "The expected EOS seqnum should be the same as the "
1276 "one from the seek that caused it. Got: %u."
1277 " Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1280 * TODO add end of stream checks for
1281 * - events not pushed
1282 * - buffer data not pushed
1283 * - pending events not received
1287 /* both flushes are handled by the common event function */
1288 case GST_EVENT_FLUSH_START:
1289 case GST_EVENT_FLUSH_STOP:
1291 case GST_EVENT_SINK_MESSAGE:
1296 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1297 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1298 gst_validate_pad_monitor_event_overrides (pad_monitor, event);
1300 gst_event_ref (event);
1301 ret = pad_monitor->event_func (pad, parent, event);
1303 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1304 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1307 switch (GST_EVENT_TYPE (event)) {
1308 case GST_EVENT_SEGMENT:
1310 if (!pad_monitor->has_segment
1311 && pad_monitor->segment.format != segment->format) {
1312 gst_segment_init (&pad_monitor->segment, segment->format);
1314 gst_segment_copy_into (segment, &pad_monitor->segment);
1315 pad_monitor->has_segment = TRUE;
1318 case GST_EVENT_CAPS:{
1321 gst_event_parse_caps (event, &caps);
1322 gst_validate_pad_monitor_setcaps_post (pad_monitor, caps, ret);
1325 case GST_EVENT_FLUSH_START:
1326 case GST_EVENT_FLUSH_STOP:
1329 case GST_EVENT_SINK_MESSAGE:
1335 gst_event_unref (event);
1340 gst_validate_pad_monitor_src_event_check (GstValidatePadMonitor * pad_monitor,
1341 GstObject * parent, GstEvent * event, GstPadEventFunction handler)
1343 gboolean ret = TRUE;
1347 GstSeekFlags seek_flags;
1348 GstSeekType start_type, stop_type;
1349 guint32 seqnum = gst_event_get_seqnum (event);
1350 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1352 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1355 switch (GST_EVENT_TYPE (event)) {
1356 case GST_EVENT_SEEK:
1358 gst_event_parse_seek (event, &rate, &format, &seek_flags, &start_type,
1359 &start, &stop_type, &stop);
1360 /* upstream seek - store the seek event seqnum to check
1361 * flushes and newsegments share the same */
1363 /* TODO we might need to use a list as multiple seeks can be sent
1364 * before the flushes arrive here */
1365 if (seek_flags & GST_SEEK_FLAG_FLUSH) {
1366 pad_monitor->pending_flush_start_seqnum = seqnum;
1367 pad_monitor->pending_flush_stop_seqnum = seqnum;
1369 pad_monitor->pending_newsegment_seqnum = seqnum;
1370 pad_monitor->pending_eos_seqnum = seqnum;
1373 /* both flushes are handled by the common event handling function */
1374 case GST_EVENT_FLUSH_START:
1375 case GST_EVENT_FLUSH_STOP:
1376 case GST_EVENT_NAVIGATION:
1377 case GST_EVENT_LATENCY:
1378 case GST_EVENT_STEP:
1385 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1386 gst_event_ref (event);
1387 ret = pad_monitor->event_func (pad, parent, event);
1388 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1392 switch (GST_EVENT_TYPE (event)) {
1393 case GST_EVENT_FLUSH_START:
1394 case GST_EVENT_FLUSH_STOP:
1396 case GST_EVENT_SEEK:
1399 /* do not expect any of these events anymore */
1400 pad_monitor->pending_flush_start_seqnum = 0;
1401 pad_monitor->pending_flush_stop_seqnum = 0;
1402 pad_monitor->pending_newsegment_seqnum = 0;
1403 pad_monitor->pending_eos_seqnum = 0;
1407 case GST_EVENT_NAVIGATION:
1408 case GST_EVENT_LATENCY:
1409 case GST_EVENT_STEP:
1415 gst_event_unref (event);
1419 static GstFlowReturn
1420 gst_validate_pad_monitor_chain_func (GstPad * pad, GstObject * parent,
1423 GstValidatePadMonitor *pad_monitor =
1424 g_object_get_data ((GObject *) pad, "validate-monitor");
1427 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1428 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1430 gst_validate_pad_monitor_check_first_buffer (pad_monitor, buffer);
1431 gst_validate_pad_monitor_update_buffer_data (pad_monitor, buffer);
1433 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1434 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1436 gst_validate_pad_monitor_buffer_overrides (pad_monitor, buffer);
1438 ret = pad_monitor->chain_func (pad, parent, buffer);
1440 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1441 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1443 pad_monitor->last_flow_return = ret;
1444 if (PAD_PARENT_IS_DEMUXER (pad_monitor))
1445 gst_validate_pad_monitor_check_aggregated_return (pad_monitor, ret);
1447 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1448 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1454 gst_validate_pad_monitor_event_is_tracked (GstValidatePadMonitor * monitor,
1457 if (!GST_EVENT_IS_SERIALIZED (event)) {
1461 /* we don't track Tag events because they mutate too much and it is hard
1462 * to match a tag event pushed on a source pad with the one that was received
1464 * One idea would be to use seqnum, but it seems that it is undefined whether
1465 * seqnums should be maintained in tag events that are created from others
1466 * up to today. (2013-08-29)
1468 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
1475 gst_validate_pad_monitor_sink_event_func (GstPad * pad, GstObject * parent,
1478 GstValidatePadMonitor *pad_monitor =
1479 g_object_get_data ((GObject *) pad, "validate-monitor");
1482 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1483 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1485 if (gst_validate_pad_monitor_event_is_tracked (pad_monitor, event)) {
1486 GstClockTime last_ts = GST_CLOCK_TIME_NONE;
1487 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_timestamp)) {
1488 last_ts = pad_monitor->current_timestamp;
1489 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_duration)) {
1490 last_ts += pad_monitor->current_duration;
1493 gst_validate_pad_monitor_otherpad_add_pending_serialized_event (pad_monitor,
1498 gst_validate_pad_monitor_downstream_event_check (pad_monitor, parent,
1499 event, pad_monitor->event_func);
1501 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1502 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1507 gst_validate_pad_monitor_src_event_func (GstPad * pad, GstObject * parent,
1510 GstValidatePadMonitor *pad_monitor =
1511 g_object_get_data ((GObject *) pad, "validate-monitor");
1514 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1515 ret = gst_validate_pad_monitor_src_event_check (pad_monitor, parent, event,
1516 pad_monitor->event_func);
1517 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1522 gst_validate_pad_monitor_query_func (GstPad * pad, GstObject * parent,
1525 GstValidatePadMonitor *pad_monitor =
1526 g_object_get_data ((GObject *) pad, "validate-monitor");
1529 gst_validate_pad_monitor_query_overrides (pad_monitor, query);
1531 ret = pad_monitor->query_func (pad, parent, query);
1534 switch (GST_QUERY_TYPE (query)) {
1535 case GST_QUERY_CAPS:{
1537 /* We shouldn't need to lock the parent as this doesn't modify
1538 * other monitors, just does some peer_pad_caps */
1539 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1541 gst_query_parse_caps_result (query, &res);
1542 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1543 gst_validate_pad_monitor_check_caps_fields_proxied (pad_monitor, res);
1545 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1557 gst_validate_pad_monitor_activatemode_func (GstPad * pad, GstObject * parent,
1558 GstPadMode mode, gboolean active)
1560 GstValidatePadMonitor *pad_monitor =
1561 g_object_get_data ((GObject *) pad, "validate-monitor");
1562 gboolean ret = TRUE;
1564 /* TODO add overrides for activate func */
1566 if (pad_monitor->activatemode_func)
1567 ret = pad_monitor->activatemode_func (pad, parent, mode, active);
1568 if (ret && active == FALSE) {
1569 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1570 gst_validate_pad_monitor_flush (pad_monitor);
1571 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1578 gst_validate_pad_get_range_func (GstPad * pad, GstObject * parent,
1579 guint64 offset, guint size, GstBuffer ** buffer)
1581 GstValidatePadMonitor *pad_monitor =
1582 g_object_get_data ((GObject *) pad, "validate-monitor");
1584 ret = pad_monitor->getrange_func (pad, parent, offset, size, buffer);
1589 gst_validate_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
1592 GstValidatePadMonitor *monitor = udata;
1594 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
1595 GST_VALIDATE_MONITOR_LOCK (monitor);
1597 gst_validate_pad_monitor_check_first_buffer (monitor, buffer);
1598 gst_validate_pad_monitor_update_buffer_data (monitor, buffer);
1600 if (PAD_PARENT_IS_DECODER (monitor) || PAD_PARENT_IS_ENCODER (monitor)) {
1601 GstClockTime tolerance = 0;
1603 if (monitor->caps_is_audio)
1604 tolerance = AUDIO_TIMESTAMP_TOLERANCE;
1606 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range (monitor,
1610 gst_validate_pad_monitor_check_late_serialized_events (monitor,
1611 GST_BUFFER_TIMESTAMP (buffer));
1613 /* a GstValidatePadMonitor parent must be a GstValidateElementMonitor */
1614 if (PAD_PARENT_IS_DECODER (monitor)) {
1616 /* should not push out of segment data */
1617 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
1618 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)) &&
1619 !gst_segment_clip (&monitor->segment, monitor->segment.format,
1620 GST_BUFFER_TIMESTAMP (buffer), GST_BUFFER_TIMESTAMP (buffer) +
1621 GST_BUFFER_DURATION (buffer), NULL, NULL)) {
1622 /* TODO is this a timestamp issue? */
1623 GST_VALIDATE_REPORT (monitor, BUFFER_IS_OUT_OF_SEGMENT,
1624 "buffer is out of segment and shouldn't be pushed. Timestamp: %"
1625 GST_TIME_FORMAT " - duration: %" GST_TIME_FORMAT ". Range: %"
1626 GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
1627 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
1628 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
1629 GST_TIME_ARGS (monitor->segment.start),
1630 GST_TIME_ARGS (monitor->segment.stop));
1634 GST_VALIDATE_MONITOR_UNLOCK (monitor);
1635 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
1636 gst_validate_pad_monitor_buffer_probe_overrides (monitor, buffer);
1641 gst_validate_pad_monitor_event_probe (GstPad * pad, GstEvent * event,
1644 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (udata);
1647 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
1648 GST_VALIDATE_MONITOR_LOCK (monitor);
1650 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
1652 if (GST_EVENT_IS_SERIALIZED (event)) {
1655 /* Detect if events the element received are being forwarded in the same order
1657 * Several scenarios:
1658 * 1) The element pushes the event as-is
1659 * 2) The element consumes the event and does not forward it
1660 * 3) The element consumes the event and creates another one instead
1661 * 4) The element pushes other serialized event before pushing out the
1664 * For each pad we have two lists to track serialized events:
1665 * 1) We received on input and expect to see (serialized_events)
1666 * 2) We received on input but don't expect to see (expired_events)
1668 * To detect events that are pushed in a different order from the one they were
1669 * received in we check that:
1671 * For each event being outputted:
1672 * If it is in the expired_events list:
1674 * If it is in the serialized_events list:
1675 * If there are other events that were received before:
1676 * Put those events on the expired_events list
1677 * Remove that event and any previous ones from the serialized_events list
1679 * Clear expired events list when flushing or on pad deactivation
1683 if (g_list_find (monitor->expired_events, event)) {
1684 /* If it's the expired events, we've failed */
1685 GST_WARNING_OBJECT (pad, "Did not expect event %p %s", event,
1686 GST_EVENT_TYPE_NAME (event));
1687 GST_VALIDATE_REPORT (monitor, EVENT_SERIALIZED_OUT_OF_ORDER,
1688 "Serialized event was pushed out of order: %" GST_PTR_FORMAT, event);
1689 monitor->expired_events = g_list_remove (monitor->expired_events, event);
1690 gst_event_unref (event); /* remove the ref that was on the list */
1691 } else if (monitor->serialized_events->len) {
1692 for (i = 0; i < monitor->serialized_events->len; i++) {
1693 SerializedEventData *next_event =
1694 g_ptr_array_index (monitor->serialized_events, i);
1695 GST_DEBUG_OBJECT (pad, "Checking against stored event #%d: %p %s", i,
1696 next_event->event, GST_EVENT_TYPE_NAME (next_event->event));
1698 if (event == next_event->event
1699 || GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
1700 /* We have found our event */
1701 GST_DEBUG_OBJECT (pad, "Found matching event");
1703 while (monitor->serialized_events->len > i
1704 && GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
1705 /* Swallow all expected events of the same type */
1706 g_ptr_array_remove_index (monitor->serialized_events, i);
1707 next_event = g_ptr_array_index (monitor->serialized_events, i);
1710 /* Move all previous events to expired events */
1711 if (G_UNLIKELY (i > 0)) {
1712 GST_DEBUG_OBJECT (pad,
1713 "Moving previous expected events to expired list");
1715 next_event = g_ptr_array_index (monitor->serialized_events, 0);
1716 monitor->expired_events =
1717 g_list_append (monitor->expired_events,
1718 gst_event_ref (next_event->event));
1719 g_ptr_array_remove_index (monitor->serialized_events, 0);
1722 debug_pending_event (pad, monitor->serialized_events);
1729 /* This so far is just like an event that is flowing downstream,
1730 * so we do the same checks as a sinkpad event handler */
1732 gst_validate_pad_monitor_downstream_event_check (monitor, NULL, event,
1734 GST_VALIDATE_MONITOR_UNLOCK (monitor);
1735 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
1740 static GstPadProbeReturn
1741 gst_validate_pad_monitor_pad_probe (GstPad * pad, GstPadProbeInfo * info,
1744 if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
1745 gst_validate_pad_monitor_buffer_probe (pad, info->data, udata);
1746 else if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
1747 gst_validate_pad_monitor_event_probe (pad, info->data, udata);
1749 return GST_PAD_PROBE_OK;
1753 gst_validate_pad_monitor_update_caps_info (GstValidatePadMonitor * pad_monitor,
1756 GstStructure *structure;
1758 g_return_if_fail (gst_caps_is_fixed (caps));
1760 pad_monitor->caps_is_audio = FALSE;
1761 pad_monitor->caps_is_video = FALSE;
1763 structure = gst_caps_get_structure (caps, 0);
1764 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/")) {
1765 pad_monitor->caps_is_audio = TRUE;
1766 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/")) {
1767 pad_monitor->caps_is_video = TRUE;
1772 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
1775 GstStructure *structure;
1777 /* Check if caps are identical to last caps and complain if so
1778 * Only checked for sink pads as src pads might push the same caps
1779 * multiple times during unlinked/autoplugging scenarios */
1780 if (GST_PAD_IS_SINK (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor)) &&
1781 pad_monitor->last_caps
1782 && gst_caps_is_equal (caps, pad_monitor->last_caps)) {
1783 GST_VALIDATE_REPORT (pad_monitor, EVENT_CAPS_DUPLICATE, "%" GST_PTR_FORMAT,
1787 gst_validate_pad_monitor_check_caps_complete (pad_monitor, caps);
1790 structure = gst_caps_get_structure (caps, 0);
1791 if (gst_structure_n_fields (pad_monitor->pending_setcaps_fields)) {
1794 i < gst_structure_n_fields (pad_monitor->pending_setcaps_fields);
1797 gst_structure_nth_field_name (pad_monitor->pending_setcaps_fields,
1799 const GValue *v = gst_structure_get_value (structure, name);
1800 const GValue *otherv =
1801 gst_structure_get_value (pad_monitor->pending_setcaps_fields, name);
1804 GST_VALIDATE_REPORT (pad_monitor, CAPS_EXPECTED_FIELD_NOT_FOUND,
1805 "Field %s is missing from setcaps caps '%" GST_PTR_FORMAT "'",
1807 } else if (gst_value_compare (v, otherv) != GST_VALUE_EQUAL) {
1808 GST_VALIDATE_REPORT (pad_monitor, CAPS_FIELD_UNEXPECTED_VALUE,
1809 "Field %s from setcaps caps '%" GST_PTR_FORMAT "' is different "
1810 "from expected value in caps '%" GST_PTR_FORMAT "'", name, caps,
1811 pad_monitor->pending_setcaps_fields);
1816 if (gst_validate_pad_monitor_pad_should_proxy_othercaps (pad_monitor)) {
1817 if (_structure_is_video (structure)) {
1818 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1819 structure, "width");
1820 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1821 structure, "height");
1822 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1823 structure, "framerate");
1824 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1825 structure, "pixel-aspect-ratio");
1826 } else if (_structure_is_audio (structure)) {
1827 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1829 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1830 structure, "channels");
1835 gst_structure_free (pad_monitor->pending_setcaps_fields);
1836 pad_monitor->pending_setcaps_fields =
1837 gst_structure_new_empty (PENDING_FIELDS);
1839 gst_validate_pad_monitor_setcaps_overrides (pad_monitor, caps);
1843 gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor * pad_monitor,
1844 GstCaps * caps, gboolean ret)
1847 gst_validate_pad_monitor_otherpad_clear_pending_fields (pad_monitor);
1849 if (pad_monitor->last_caps) {
1850 gst_caps_unref (pad_monitor->last_caps);
1852 pad_monitor->last_caps = gst_caps_ref (caps);
1853 gst_validate_pad_monitor_update_caps_info (pad_monitor, caps);
1858 gst_validate_pad_monitor_do_setup (GstValidateMonitor * monitor)
1860 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR_CAST (monitor);
1862 if (!GST_IS_PAD (GST_VALIDATE_MONITOR_GET_OBJECT (monitor))) {
1863 GST_WARNING_OBJECT (monitor, "Trying to create pad monitor with other "
1868 pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1870 if (g_object_get_data ((GObject *) pad, "validate-monitor")) {
1871 GST_WARNING_OBJECT (pad_monitor,
1872 "Pad already has a validate-monitor associated");
1876 g_object_set_data ((GObject *) pad, "validate-monitor", pad_monitor);
1878 pad_monitor->pad = pad;
1880 pad_monitor->event_func = GST_PAD_EVENTFUNC (pad);
1881 pad_monitor->query_func = GST_PAD_QUERYFUNC (pad);
1882 pad_monitor->activatemode_func = GST_PAD_ACTIVATEMODEFUNC (pad);
1883 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1885 pad_monitor->chain_func = GST_PAD_CHAINFUNC (pad);
1886 if (pad_monitor->chain_func)
1887 gst_pad_set_chain_function (pad, gst_validate_pad_monitor_chain_func);
1889 gst_pad_set_event_function (pad, gst_validate_pad_monitor_sink_event_func);
1891 pad_monitor->getrange_func = GST_PAD_GETRANGEFUNC (pad);
1892 if (pad_monitor->getrange_func)
1893 gst_pad_set_getrange_function (pad, gst_validate_pad_get_range_func);
1895 gst_pad_set_event_function (pad, gst_validate_pad_monitor_src_event_func);
1897 /* add buffer/event probes */
1898 pad_monitor->pad_probe_id =
1899 gst_pad_add_probe (pad,
1900 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
1901 GST_PAD_PROBE_TYPE_EVENT_FLUSH,
1902 (GstPadProbeCallback) gst_validate_pad_monitor_pad_probe, pad_monitor,
1905 gst_pad_set_query_function (pad, gst_validate_pad_monitor_query_func);
1906 gst_pad_set_activatemode_function (pad,
1907 gst_validate_pad_monitor_activatemode_func);
1909 gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (monitor),
1910 g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad)));
1912 if (G_UNLIKELY (GST_PAD_PARENT (pad) == NULL))
1913 GST_FIXME ("Saw a pad not belonging to any object");