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"
48 #define PAD_PARENT_IS_DEMUXER(m) \
49 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
50 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DEMUXER ( \
51 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
54 #define PAD_PARENT_IS_DECODER(m) \
55 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
56 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER ( \
57 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
61 * Locking the parent should always be done before locking the
62 * pad-monitor to prevent deadlocks in case another monitor from
63 * another pad on the same element starts an operation that also
64 * requires locking itself and some other monitors from internally
68 * An element has a sink and a src pad. Some test starts running at sinkpad
69 * and it locks the parent, and then it locks itself. In case it needs to get
70 * some information from the srcpad, it is able to lock the srcpad and get it
71 * because the srcpad should never lock itself before locking the parent (which
72 * it won't be able as sinkpad already locked it).
74 * As a side one, it is possible that srcpad locks itself without locking the
75 * parent in case it wants to do a check that won't need to use other internally
76 * linked pads (sinkpad). But in this case it might lock and unlock freely without
79 #define GST_VALIDATE_PAD_MONITOR_PARENT_LOCK(m) \
81 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
82 GST_VALIDATE_MONITOR_LOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
84 GST_WARNING_OBJECT (m, "No parent found, can't lock"); \
88 #define GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK(m) \
90 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
91 GST_VALIDATE_MONITOR_UNLOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
93 GST_WARNING_OBJECT (m, "No parent found, can't unlock"); \
99 GstClockTime timestamp;
101 } SerializedEventData;
104 debug_pending_event (GstPad * pad, GPtrArray * array)
109 for (i = 0; i < len; i++) {
110 SerializedEventData *data = g_ptr_array_index (array, i);
111 GST_DEBUG_OBJECT (pad, "event #%d %" GST_TIME_FORMAT " %s %p",
112 i, GST_TIME_ARGS (data->timestamp),
113 GST_EVENT_TYPE_NAME (data->event), data->event);
118 _serialized_event_data_free (SerializedEventData * serialized_event)
120 gst_event_unref (serialized_event->event);
121 g_slice_free (SerializedEventData, serialized_event);
124 static gboolean gst_validate_pad_monitor_do_setup (GstValidateMonitor *
126 static GstElement *gst_validate_pad_monitor_get_element (GstValidateMonitor *
129 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
131 static void gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor *
132 pad_monitor, GstCaps * caps, gboolean ret);
134 #define PAD_IS_IN_PUSH_MODE(p) ((p)->mode == GST_PAD_MODE_PUSH)
137 _structure_is_raw_video (GstStructure * structure)
139 return gst_structure_has_name (structure, "video/x-raw");
143 _structure_is_raw_audio (GstStructure * structure)
145 return gst_structure_has_name (structure, "audio/x-raw");
149 _check_field_type (GstValidatePadMonitor * monitor, GstStructure * structure,
150 const gchar * field, ...)
154 gchar *joined_types = NULL;
155 const gchar *rejected_types[5];
156 gint rejected_types_index = 0;
158 if (!gst_structure_has_field (structure, field)) {
159 GST_VALIDATE_REPORT (monitor, CAPS_IS_MISSING_FIELD,
160 "Field '%s' is missing from structure: %" GST_PTR_FORMAT, field,
165 memset (rejected_types, 0, sizeof (rejected_types));
166 va_start (var_args, field);
167 while ((type = va_arg (var_args, GType)) != 0) {
168 if (gst_structure_has_field_typed (structure, field, type)) {
172 rejected_types[rejected_types_index++] = g_type_name (type);
176 joined_types = g_strjoinv (" / ", (gchar **) rejected_types);
177 GST_VALIDATE_REPORT (monitor, CAPS_FIELD_HAS_BAD_TYPE,
178 "Field '%s' has wrong type %s in structure '%" GST_PTR_FORMAT
179 "'. Expected: %s", field,
180 g_type_name (gst_structure_get_field_type (structure, field)), structure,
182 g_free (joined_types);
186 gst_validate_pad_monitor_check_raw_video_caps_complete (GstValidatePadMonitor *
187 monitor, GstStructure * structure)
189 _check_field_type (monitor, structure, "width", G_TYPE_INT,
190 GST_TYPE_INT_RANGE, 0);
191 _check_field_type (monitor, structure, "height", G_TYPE_INT,
192 GST_TYPE_INT_RANGE, 0);
193 _check_field_type (monitor, structure, "framerate", GST_TYPE_FRACTION,
194 GST_TYPE_FRACTION_RANGE, 0);
195 _check_field_type (monitor, structure, "pixel-aspect-ratio",
196 GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, 0);
197 _check_field_type (monitor, structure, "format", G_TYPE_STRING,
202 gst_validate_pad_monitor_check_raw_audio_caps_complete (GstValidatePadMonitor *
203 monitor, GstStructure * structure)
205 _check_field_type (monitor, structure, "format", G_TYPE_STRING, GST_TYPE_LIST,
207 _check_field_type (monitor, structure, "layout", G_TYPE_STRING, GST_TYPE_LIST,
209 _check_field_type (monitor, structure, "rate", G_TYPE_INT, GST_TYPE_LIST,
210 GST_TYPE_INT_RANGE, 0);
211 _check_field_type (monitor, structure, "channels", G_TYPE_INT, GST_TYPE_LIST,
212 GST_TYPE_INT_RANGE, 0);
213 _check_field_type (monitor, structure, "channel-mask", GST_TYPE_BITMASK,
218 gst_validate_pad_monitor_check_caps_complete (GstValidatePadMonitor * monitor,
221 GstStructure *structure;
224 GST_DEBUG_OBJECT (monitor->pad, "Checking caps %" GST_PTR_FORMAT, caps);
226 for (i = 0; i < gst_caps_get_size (caps); i++) {
227 structure = gst_caps_get_structure (caps, i);
229 if (_structure_is_raw_video (structure)) {
230 gst_validate_pad_monitor_check_raw_video_caps_complete (monitor,
233 } else if (_structure_is_raw_audio (structure)) {
234 gst_validate_pad_monitor_check_raw_audio_caps_complete (monitor,
241 gst_validate_pad_monitor_get_othercaps (GstValidatePadMonitor * monitor)
243 GstCaps *caps = gst_caps_new_empty ();
250 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
254 GValue value = { 0, };
255 switch (gst_iterator_next (iter, &value)) {
256 case GST_ITERATOR_OK:
257 otherpad = g_value_get_object (&value);
259 /* TODO What would be the correct caps operation to merge the caps in
260 * case one sink is internally linked to multiple srcs? */
261 peercaps = gst_pad_peer_query_caps (otherpad, NULL);
263 caps = gst_caps_merge (caps, peercaps);
265 g_value_reset (&value);
267 case GST_ITERATOR_RESYNC:
268 gst_iterator_resync (iter);
269 gst_caps_replace (&caps, gst_caps_new_empty ());
271 case GST_ITERATOR_ERROR:
272 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
275 case GST_ITERATOR_DONE:
280 gst_iterator_free (iter);
282 GST_DEBUG_OBJECT (monitor->pad, "Otherpad caps: %" GST_PTR_FORMAT, caps);
288 _structure_is_video (GstStructure * structure)
290 const gchar *name = gst_structure_get_name (structure);
292 return g_strstr_len (name, 6, "video/")
293 && strcmp (name, "video/quicktime") != 0;
297 _structure_is_audio (GstStructure * structure)
299 const gchar *name = gst_structure_get_name (structure);
301 return g_strstr_len (name, 6, "audio/") != NULL;
305 gst_validate_pad_monitor_pad_should_proxy_othercaps (GstValidatePadMonitor *
308 GstValidateMonitor *parent = GST_VALIDATE_MONITOR_GET_PARENT (monitor);
313 /* We only know how to handle othercaps checks for codecs so far */
314 return GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER (parent) ||
315 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER (parent);
319 /* Check if the field @f from @s2 (if present) is represented in @s1
320 * Represented here means either equal or @s1's value is in a list/range
324 _structures_field_is_contained (GstStructure * s1, GstStructure * s2,
330 v2 = gst_structure_get_value (s2, f);
332 return TRUE; /* nothing to compare to */
334 v1 = gst_structure_get_value (s1, f);
338 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
341 if (GST_VALUE_HOLDS_LIST (v2)) {
343 for (i = 0; i < gst_value_list_get_size (v2); i++) {
344 const GValue *v2_subvalue = gst_value_list_get_value (v2, i);
345 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
350 if (GST_VALUE_HOLDS_ARRAY (v2)) {
352 for (i = 0; i < gst_value_array_get_size (v2); i++) {
353 const GValue *v2_subvalue = gst_value_array_get_value (v2, i);
354 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
359 if (GST_VALUE_HOLDS_INT_RANGE (v2)) {
362 min = gst_value_get_int_range_min (v2);
363 max = gst_value_get_int_range_max (v2);
365 if (G_VALUE_HOLDS_INT (v1)) {
366 gint v = g_value_get_int (v1);
368 return v >= min && v <= max;
370 /* TODO compare int ranges with int ranges
371 * or with lists if useful */
375 if (GST_VALUE_HOLDS_FRACTION_RANGE (v2)) {
376 const GValue *min, *max;
378 min = gst_value_get_fraction_range_min (v2);
379 max = gst_value_get_fraction_range_max (v2);
381 if (GST_VALUE_HOLDS_FRACTION (v1)) {
382 gint v_min = gst_value_compare (v1, min);
383 gint v_max = gst_value_compare (v1, max);
385 return (v_min == GST_VALUE_EQUAL || v_min == GST_VALUE_GREATER_THAN) &&
386 (v_max == GST_VALUE_EQUAL || v_max == GST_VALUE_LESS_THAN);
388 /* TODO compare fraction ranges with fraction ranges
389 * or with lists if useful */
397 gst_validate_pad_monitor_check_caps_fields_proxied (GstValidatePadMonitor *
398 monitor, GstCaps * caps)
400 GstStructure *structure;
401 GstStructure *otherstructure;
405 if (!gst_validate_pad_monitor_pad_should_proxy_othercaps (monitor))
408 othercaps = gst_validate_pad_monitor_get_othercaps (monitor);
410 for (i = 0; i < gst_caps_get_size (othercaps); i++) {
411 gboolean found = FALSE;
412 gboolean type_match = FALSE;
414 otherstructure = gst_caps_get_structure (othercaps, i);
416 /* look for a proxied version of 'otherstructure' */
417 if (_structure_is_video (otherstructure)) {
418 for (j = 0; j < gst_caps_get_size (caps); j++) {
419 structure = gst_caps_get_structure (caps, j);
420 if (_structure_is_video (structure)) {
422 if (_structures_field_is_contained (structure, otherstructure,
424 && _structures_field_is_contained (structure, otherstructure,
426 && _structures_field_is_contained (structure, otherstructure,
428 && _structures_field_is_contained (structure, otherstructure,
429 "pixel-aspect-ratio")) {
435 } else if (_structure_is_audio (otherstructure)) {
436 for (j = 0; j < gst_caps_get_size (caps); j++) {
437 structure = gst_caps_get_structure (caps, j);
438 if (_structure_is_audio (structure)) {
440 if (_structures_field_is_contained (structure, otherstructure, "rate")
441 && _structures_field_is_contained (structure, otherstructure,
450 if (type_match && !found) {
451 GST_VALIDATE_REPORT (monitor, GET_CAPS_NOT_PROXYING_FIELDS,
452 "Peer pad structure '%" GST_PTR_FORMAT "' has no similar version "
453 "on pad's caps '%" GST_PTR_FORMAT "'", otherstructure, caps);
459 gst_validate_pad_monitor_check_late_serialized_events (GstValidatePadMonitor *
460 monitor, GstClockTime ts)
464 if (!GST_CLOCK_TIME_IS_VALID (ts))
467 GST_DEBUG_OBJECT (monitor->pad, "Timestamp to check %" GST_TIME_FORMAT,
470 for (i = 0; i < monitor->serialized_events->len; i++) {
471 SerializedEventData *data =
472 g_ptr_array_index (monitor->serialized_events, i);
474 GST_DEBUG_OBJECT (monitor->pad, "Event #%d (%s) ts: %" GST_TIME_FORMAT,
475 i, GST_EVENT_TYPE_NAME (data->event), GST_TIME_ARGS (data->timestamp));
477 if (data->timestamp < ts) {
478 GST_VALIDATE_REPORT (monitor, SERIALIZED_EVENT_WASNT_PUSHED_IN_TIME,
479 "Serialized event %" GST_PTR_FORMAT " wasn't pushed before expected "
480 "timestamp %" GST_TIME_FORMAT " on pad %s:%s", data->event,
481 GST_TIME_ARGS (data->timestamp),
482 GST_DEBUG_PAD_NAME (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor)));
484 /* events should be ordered by ts */
490 debug_pending_event (monitor->pad, monitor->serialized_events);
491 g_ptr_array_remove_range (monitor->serialized_events, 0, i);
496 gst_validate_pad_monitor_dispose (GObject * object)
498 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (object);
499 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
502 if (monitor->pad_probe_id)
503 gst_pad_remove_probe (pad, monitor->pad_probe_id);
506 if (monitor->expected_segment)
507 gst_event_unref (monitor->expected_segment);
509 gst_structure_free (monitor->pending_setcaps_fields);
510 g_ptr_array_unref (monitor->serialized_events);
511 g_list_free (monitor->expired_events);
513 G_OBJECT_CLASS (parent_class)->dispose (object);
517 gst_validate_pad_monitor_class_init (GstValidatePadMonitorClass * klass)
519 GObjectClass *gobject_class;
520 GstValidateMonitorClass *monitor_klass;
522 gobject_class = G_OBJECT_CLASS (klass);
523 monitor_klass = GST_VALIDATE_MONITOR_CLASS (klass);
525 gobject_class->dispose = gst_validate_pad_monitor_dispose;
527 monitor_klass->setup = gst_validate_pad_monitor_do_setup;
528 monitor_klass->get_element = gst_validate_pad_monitor_get_element;
532 gst_validate_pad_monitor_init (GstValidatePadMonitor * pad_monitor)
534 pad_monitor->pending_setcaps_fields =
535 gst_structure_new_empty (PENDING_FIELDS);
536 pad_monitor->serialized_events =
537 g_ptr_array_new_with_free_func ((GDestroyNotify)
538 _serialized_event_data_free);
539 pad_monitor->expired_events = NULL;
540 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
541 pad_monitor->first_buffer = TRUE;
543 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
544 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
548 * gst_validate_pad_monitor_new:
549 * @pad: (transfer-none): a #GstPad to run Validate on
551 GstValidatePadMonitor *
552 gst_validate_pad_monitor_new (GstPad * pad, GstValidateRunner * runner,
553 GstValidateElementMonitor * parent)
555 GstValidatePadMonitor *monitor = g_object_new (GST_TYPE_VALIDATE_PAD_MONITOR,
556 "object", pad, "qa-runner", runner, "qa-parent",
559 if (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor) == NULL) {
560 g_object_unref (monitor);
567 gst_validate_pad_monitor_get_element (GstValidateMonitor * monitor)
569 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
571 return GST_PAD_PARENT (pad);
575 gst_validate_pad_monitor_event_overrides (GstValidatePadMonitor * pad_monitor,
580 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
581 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
582 iter = g_list_next (iter)) {
583 GstValidateOverride *override = iter->data;
585 gst_validate_override_event_handler (override,
586 GST_VALIDATE_MONITOR_CAST (pad_monitor), event);
588 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
592 gst_validate_pad_monitor_buffer_overrides (GstValidatePadMonitor * pad_monitor,
597 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
598 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
599 iter = g_list_next (iter)) {
600 GstValidateOverride *override = iter->data;
602 gst_validate_override_buffer_handler (override,
603 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
605 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
609 gst_validate_pad_monitor_buffer_probe_overrides (GstValidatePadMonitor *
610 pad_monitor, GstBuffer * buffer)
614 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
615 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
616 iter = g_list_next (iter)) {
617 GstValidateOverride *override = iter->data;
619 gst_validate_override_buffer_probe_handler (override,
620 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
622 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
626 gst_validate_pad_monitor_query_overrides (GstValidatePadMonitor * pad_monitor,
631 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
632 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
633 iter = g_list_next (iter)) {
634 GstValidateOverride *override = iter->data;
636 gst_validate_override_query_handler (override,
637 GST_VALIDATE_MONITOR_CAST (pad_monitor), query);
639 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
643 gst_validate_pad_monitor_setcaps_overrides (GstValidatePadMonitor * pad_monitor,
648 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
649 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
650 iter = g_list_next (iter)) {
651 GstValidateOverride *override = iter->data;
653 gst_validate_override_setcaps_handler (override,
654 GST_VALIDATE_MONITOR_CAST (pad_monitor), caps);
656 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
659 /* FIXME : This is a bit dubious, what's the point of this check ? */
661 gst_validate_pad_monitor_timestamp_is_in_received_range (GstValidatePadMonitor *
662 monitor, GstClockTime ts)
664 GST_DEBUG_OBJECT (monitor->pad, "Checking if timestamp %" GST_TIME_FORMAT
665 " is in range: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT " for pad "
666 "%s:%s", GST_TIME_ARGS (ts),
667 GST_TIME_ARGS (monitor->timestamp_range_start),
668 GST_TIME_ARGS (monitor->timestamp_range_end),
669 GST_DEBUG_PAD_NAME (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor)));
670 return !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_start) ||
671 !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_end) ||
672 (monitor->timestamp_range_start <= ts
673 && ts <= monitor->timestamp_range_end);
676 /* Iterates over internal links (sinkpads) to check that this buffer has
677 * a timestamp that is in the range of the lastly received buffers */
679 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range
680 (GstValidatePadMonitor * monitor, GstBuffer * buffer)
685 gboolean has_one = FALSE;
686 gboolean found = FALSE;
689 GstValidatePadMonitor *othermonitor;
691 if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))
692 || !GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
693 GST_DEBUG_OBJECT (monitor->pad,
694 "Can't check buffer timestamps range as "
695 "buffer has no valid timestamp/duration");
698 ts = GST_BUFFER_TIMESTAMP (buffer);
699 ts_end = ts + GST_BUFFER_DURATION (buffer);
702 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
706 GValue value = { 0, };
707 switch (gst_iterator_next (iter, &value)) {
708 case GST_ITERATOR_OK:
709 otherpad = g_value_get_object (&value);
710 GST_DEBUG_OBJECT (monitor->pad, "Checking pad %s:%s input timestamps",
711 GST_DEBUG_PAD_NAME (otherpad));
712 othermonitor = g_object_get_data ((GObject *) otherpad, "qa-monitor");
713 GST_VALIDATE_MONITOR_LOCK (othermonitor);
714 if (gst_validate_pad_monitor_timestamp_is_in_received_range
717 gst_validate_pad_monitor_timestamp_is_in_received_range
718 (othermonitor, ts_end)) {
722 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
723 g_value_reset (&value);
726 case GST_ITERATOR_RESYNC:
727 gst_iterator_resync (iter);
731 case GST_ITERATOR_ERROR:
732 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
735 case GST_ITERATOR_DONE:
740 gst_iterator_free (iter);
743 GST_DEBUG_OBJECT (monitor->pad, "Skipping timestamp in range check as no "
744 "internal linked pad was found");
748 GST_VALIDATE_REPORT (monitor, BUFFER_TIMESTAMP_OUT_OF_RECEIVED_RANGE,
749 "Timestamp %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT
750 " is out of range of received input", GST_TIME_ARGS (ts),
751 GST_TIME_ARGS (ts_end));
756 gst_validate_pad_monitor_check_first_buffer (GstValidatePadMonitor *
757 pad_monitor, GstBuffer * buffer)
759 if (G_UNLIKELY (pad_monitor->first_buffer)) {
760 pad_monitor->first_buffer = FALSE;
762 if (!pad_monitor->has_segment
763 && PAD_IS_IN_PUSH_MODE (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor)))
765 GST_VALIDATE_REPORT (pad_monitor, BUFFER_BEFORE_SEGMENT,
766 "Received buffer before Segment event");
768 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
769 gint64 running_time = gst_segment_to_running_time (&pad_monitor->segment,
770 pad_monitor->segment.format, GST_BUFFER_TIMESTAMP (buffer));
771 if (running_time != 0) {
772 GST_VALIDATE_REPORT (pad_monitor, FIRST_BUFFER_RUNNING_TIME_IS_NOT_ZERO,
773 "First buffer running time is not 0, it is: %" GST_TIME_FORMAT,
774 GST_TIME_ARGS (running_time));
781 gst_validate_pad_monitor_update_buffer_data (GstValidatePadMonitor *
782 pad_monitor, GstBuffer * buffer)
784 pad_monitor->current_timestamp = GST_BUFFER_TIMESTAMP (buffer);
785 pad_monitor->current_duration = GST_BUFFER_DURATION (buffer);
786 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
787 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_start)) {
788 pad_monitor->timestamp_range_start =
789 MIN (pad_monitor->timestamp_range_start,
790 GST_BUFFER_TIMESTAMP (buffer));
792 pad_monitor->timestamp_range_start = GST_BUFFER_TIMESTAMP (buffer);
795 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
797 GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
798 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_end)) {
799 pad_monitor->timestamp_range_end =
800 MAX (pad_monitor->timestamp_range_end, endts);
802 pad_monitor->timestamp_range_end = endts;
806 GST_DEBUG_OBJECT (pad_monitor->pad, "Current stored range: %" GST_TIME_FORMAT
807 " - %" GST_TIME_FORMAT,
808 GST_TIME_ARGS (pad_monitor->timestamp_range_start),
809 GST_TIME_ARGS (pad_monitor->timestamp_range_end));
813 _combine_flows (GstFlowReturn ret1, GstFlowReturn ret2)
817 if (ret1 <= GST_FLOW_NOT_NEGOTIATED)
819 if (ret2 <= GST_FLOW_NOT_NEGOTIATED)
821 if (ret1 == GST_FLOW_FLUSHING || ret2 == GST_FLOW_FLUSHING)
822 return GST_FLOW_FLUSHING;
823 if (ret1 == GST_FLOW_OK || ret2 == GST_FLOW_OK)
829 gst_validate_pad_monitor_check_aggregated_return (GstValidatePadMonitor *
830 monitor, GstFlowReturn ret)
836 GstValidatePadMonitor *othermonitor;
837 GstFlowReturn aggregated = GST_FLOW_NOT_LINKED;
838 gboolean found_a_pad = FALSE;
841 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
845 GValue value = { 0, };
846 switch (gst_iterator_next (iter, &value)) {
847 case GST_ITERATOR_OK:
848 otherpad = g_value_get_object (&value);
849 peerpad = gst_pad_get_peer (otherpad);
851 othermonitor = g_object_get_data ((GObject *) peerpad, "qa-monitor");
854 GST_VALIDATE_MONITOR_LOCK (othermonitor);
856 _combine_flows (aggregated, othermonitor->last_flow_return);
857 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
860 gst_object_unref (peerpad);
862 g_value_reset (&value);
864 case GST_ITERATOR_RESYNC:
865 gst_iterator_resync (iter);
867 case GST_ITERATOR_ERROR:
868 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
871 case GST_ITERATOR_DONE:
876 gst_iterator_free (iter);
878 /* no peer pad found, nothing to do */
881 if (aggregated == GST_FLOW_OK || aggregated == GST_FLOW_EOS) {
882 /* those are acceptable situations */
884 if (monitor->is_eos && ret == GST_FLOW_EOS) {
885 /* this element received eos and returned eos */
889 if (PAD_PARENT_IS_DEMUXER (monitor) && ret == GST_FLOW_EOS) {
890 /* a demuxer can return EOS when the samples end */
895 if (aggregated != ret) {
896 GST_VALIDATE_REPORT (monitor, WRONG_FLOW_RETURN,
897 "Wrong combined flow return %s(%d). Expected: %s(%d)",
898 gst_flow_get_name (ret), ret, gst_flow_get_name (aggregated),
904 gst_validate_pad_monitor_otherpad_add_pending_serialized_event
905 (GstValidatePadMonitor * monitor, GstEvent * event, GstClockTime last_ts)
910 GstValidatePadMonitor *othermonitor;
912 if (!GST_EVENT_IS_SERIALIZED (event))
916 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
919 /* inputselector will return NULL if the sinkpad is not the active one .... */
920 GST_FIXME_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD
921 (monitor), "No iterator");
926 GValue value = { 0, };
927 switch (gst_iterator_next (iter, &value)) {
928 case GST_ITERATOR_OK:
929 otherpad = g_value_get_object (&value);
930 othermonitor = g_object_get_data ((GObject *) otherpad, "qa-monitor");
932 SerializedEventData *data = g_slice_new0 (SerializedEventData);
933 data->timestamp = last_ts;
934 data->event = gst_event_ref (event);
935 GST_VALIDATE_MONITOR_LOCK (othermonitor);
936 GST_DEBUG_OBJECT (monitor->pad, "Storing for pad %s:%s event %p %s",
937 GST_DEBUG_PAD_NAME (otherpad), event,
938 GST_EVENT_TYPE_NAME (event));
939 g_ptr_array_add (othermonitor->serialized_events, data);
940 debug_pending_event (otherpad, othermonitor->serialized_events);
941 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
943 g_value_reset (&value);
945 case GST_ITERATOR_RESYNC:
946 gst_iterator_resync (iter);
948 case GST_ITERATOR_ERROR:
949 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
952 case GST_ITERATOR_DONE:
957 gst_iterator_free (iter);
961 gst_validate_pad_monitor_otherpad_add_pending_field (GstValidatePadMonitor *
962 monitor, GstStructure * structure, const gchar * field)
967 GstValidatePadMonitor *othermonitor;
970 v = gst_structure_get_value (structure, field);
972 GST_DEBUG_OBJECT (monitor->pad, "Not adding pending field %s as it isn't "
973 "present on structure %" GST_PTR_FORMAT, field, structure);
978 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
982 GValue value = { 0, };
983 switch (gst_iterator_next (iter, &value)) {
984 case GST_ITERATOR_OK:
985 otherpad = g_value_get_object (&value);
986 othermonitor = g_object_get_data ((GObject *) otherpad, "qa-monitor");
988 GST_VALIDATE_MONITOR_LOCK (othermonitor);
989 g_assert (othermonitor->pending_setcaps_fields != NULL);
990 gst_structure_set_value (othermonitor->pending_setcaps_fields,
992 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
994 g_value_reset (&value);
996 case GST_ITERATOR_RESYNC:
997 gst_iterator_resync (iter);
999 case GST_ITERATOR_ERROR:
1000 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1003 case GST_ITERATOR_DONE:
1008 gst_iterator_free (iter);
1012 gst_validate_pad_monitor_otherpad_clear_pending_fields (GstValidatePadMonitor *
1018 GstValidatePadMonitor *othermonitor;
1021 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1025 GValue value = { 0, };
1026 switch (gst_iterator_next (iter, &value)) {
1027 case GST_ITERATOR_OK:
1028 otherpad = g_value_get_object (&value);
1029 othermonitor = g_object_get_data ((GObject *) otherpad, "qa-monitor");
1031 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1032 g_assert (othermonitor->pending_setcaps_fields != NULL);
1033 gst_structure_free (othermonitor->pending_setcaps_fields);
1034 othermonitor->pending_setcaps_fields =
1035 gst_structure_new_empty (PENDING_FIELDS);
1036 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1038 g_value_reset (&value);
1040 case GST_ITERATOR_RESYNC:
1041 gst_iterator_resync (iter);
1043 case GST_ITERATOR_ERROR:
1044 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1047 case GST_ITERATOR_DONE:
1052 gst_iterator_free (iter);
1056 gst_validate_pad_monitor_add_expected_newsegment (GstValidatePadMonitor *
1057 monitor, GstEvent * event)
1062 GstValidatePadMonitor *othermonitor;
1065 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1069 GValue value = { 0, };
1070 switch (gst_iterator_next (iter, &value)) {
1071 case GST_ITERATOR_OK:
1072 otherpad = g_value_get_object (&value);
1073 othermonitor = g_object_get_data ((GObject *) otherpad, "qa-monitor");
1074 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1075 if (othermonitor->expected_segment) {
1076 GST_VALIDATE_REPORT (othermonitor, EVENT_NEWSEGMENT_NOT_PUSHED, "");
1077 gst_event_unref (othermonitor->expected_segment);
1079 othermonitor->expected_segment = gst_event_ref (event);
1080 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1081 g_value_reset (&value);
1083 case GST_ITERATOR_RESYNC:
1084 gst_iterator_resync (iter);
1086 case GST_ITERATOR_ERROR:
1087 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1090 case GST_ITERATOR_DONE:
1095 gst_iterator_free (iter);
1099 gst_validate_pad_monitor_flush (GstValidatePadMonitor * pad_monitor)
1101 pad_monitor->current_timestamp = GST_CLOCK_TIME_NONE;
1102 pad_monitor->current_duration = GST_CLOCK_TIME_NONE;
1103 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
1104 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
1105 pad_monitor->has_segment = FALSE;
1106 pad_monitor->is_eos = FALSE;
1107 gst_caps_replace (&pad_monitor->last_caps, NULL);
1109 g_list_free_full (pad_monitor->expired_events,
1110 (GDestroyNotify) gst_event_unref);
1111 pad_monitor->expired_events = NULL;
1113 if (pad_monitor->serialized_events->len)
1114 g_ptr_array_remove_range (pad_monitor->serialized_events, 0,
1115 pad_monitor->serialized_events->len);
1118 /* common checks for both sink and src event functions */
1120 gst_validate_pad_monitor_common_event_check (GstValidatePadMonitor *
1121 pad_monitor, GstEvent * event)
1123 guint32 seqnum = gst_event_get_seqnum (event);
1125 switch (GST_EVENT_TYPE (event)) {
1126 case GST_EVENT_FLUSH_START:
1128 if (pad_monitor->pending_flush_start_seqnum) {
1129 if (seqnum == pad_monitor->pending_flush_start_seqnum) {
1130 pad_monitor->pending_flush_start_seqnum = 0;
1132 GST_VALIDATE_REPORT (pad_monitor, EVENT_HAS_WRONG_SEQNUM,
1133 "The expected flush-start seqnum should be the same as the "
1134 "one from the event that caused it (probably a seek). Got: %u."
1135 " Expected: %u", seqnum, pad_monitor->pending_flush_start_seqnum);
1139 if (pad_monitor->pending_flush_stop) {
1140 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1141 "Received flush-start from " " when flush-stop was expected");
1143 pad_monitor->pending_flush_stop = TRUE;
1146 case GST_EVENT_FLUSH_STOP:
1148 if (pad_monitor->pending_flush_stop_seqnum) {
1149 if (seqnum == pad_monitor->pending_flush_stop_seqnum) {
1150 pad_monitor->pending_flush_stop_seqnum = 0;
1152 GST_VALIDATE_REPORT (pad_monitor, EVENT_HAS_WRONG_SEQNUM,
1153 "The expected flush-stop seqnum should be the same as the "
1154 "one from the event that caused it (probably a seek). Got: %u."
1155 " Expected: %u", seqnum, pad_monitor->pending_flush_stop_seqnum);
1159 if (!pad_monitor->pending_flush_stop) {
1160 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_STOP_UNEXPECTED,
1161 "Unexpected flush-stop %p" GST_PTR_FORMAT, event);
1163 pad_monitor->pending_flush_stop = FALSE;
1165 /* cleanup our data */
1166 gst_validate_pad_monitor_flush (pad_monitor);
1175 gst_validate_pad_monitor_downstream_event_check (GstValidatePadMonitor *
1176 pad_monitor, GstObject * parent, GstEvent * event,
1177 GstPadEventFunction handler)
1179 gboolean ret = TRUE;
1180 const GstSegment *segment;
1181 guint32 seqnum = gst_event_get_seqnum (event);
1182 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1184 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1187 switch (GST_EVENT_TYPE (event)) {
1188 case GST_EVENT_SEGMENT:
1189 /* parse segment data to be used if event is handled */
1190 gst_event_parse_segment (event, &segment);
1192 if (pad_monitor->pending_newsegment_seqnum) {
1193 if (pad_monitor->pending_newsegment_seqnum == seqnum) {
1194 pad_monitor->pending_newsegment_seqnum = 0;
1196 /* TODO is this an error? could be a segment from the start
1197 * received just before the seek segment */
1201 /* got a segment, no need for EOS now */
1202 pad_monitor->pending_eos_seqnum = 0;
1204 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1205 gst_validate_pad_monitor_add_expected_newsegment (pad_monitor, event);
1207 /* check if this segment is the expected one */
1208 if (pad_monitor->expected_segment) {
1209 const GstSegment *exp_segment;
1211 if (pad_monitor->expected_segment != event) {
1212 gst_event_parse_segment (pad_monitor->expected_segment,
1214 if (segment->format == exp_segment->format) {
1215 if ((exp_segment->rate * exp_segment->applied_rate !=
1216 segment->rate * segment->applied_rate)
1217 || exp_segment->start != segment->start
1218 || exp_segment->stop != segment->stop
1219 || exp_segment->position != segment->position) {
1220 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1221 "Expected segment didn't match received segment event");
1225 gst_event_replace (&pad_monitor->expected_segment, NULL);
1230 pad_monitor->is_eos = TRUE;
1231 if (pad_monitor->pending_eos_seqnum &&
1232 pad_monitor->pending_eos_seqnum != seqnum) {
1233 GST_VALIDATE_REPORT (pad_monitor, EVENT_HAS_WRONG_SEQNUM,
1234 "The expected EOS seqnum should be the same as the "
1235 "one from the seek that caused it. Got: %u."
1236 " Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1239 * TODO add end of stream checks for
1240 * - events not pushed
1241 * - buffer data not pushed
1242 * - pending events not received
1246 /* both flushes are handled by the common event function */
1247 case GST_EVENT_FLUSH_START:
1248 case GST_EVENT_FLUSH_STOP:
1250 case GST_EVENT_SINK_MESSAGE:
1255 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1256 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1257 gst_validate_pad_monitor_event_overrides (pad_monitor, event);
1259 gst_event_ref (event);
1260 ret = pad_monitor->event_func (pad, parent, event);
1262 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1263 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1266 switch (GST_EVENT_TYPE (event)) {
1267 case GST_EVENT_SEGMENT:
1269 if (!pad_monitor->has_segment
1270 && pad_monitor->segment.format != segment->format) {
1271 gst_segment_init (&pad_monitor->segment, segment->format);
1273 gst_segment_copy_into (segment, &pad_monitor->segment);
1274 pad_monitor->has_segment = TRUE;
1277 case GST_EVENT_FLUSH_START:
1278 case GST_EVENT_FLUSH_STOP:
1281 case GST_EVENT_SINK_MESSAGE:
1287 gst_event_unref (event);
1292 gst_validate_pad_monitor_src_event_check (GstValidatePadMonitor * pad_monitor,
1293 GstObject * parent, GstEvent * event, GstPadEventFunction handler)
1295 gboolean ret = TRUE;
1299 GstSeekFlags seek_flags;
1300 GstSeekType start_type, stop_type;
1301 guint32 seqnum = gst_event_get_seqnum (event);
1302 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1304 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1307 switch (GST_EVENT_TYPE (event)) {
1308 case GST_EVENT_SEEK:
1310 gst_event_parse_seek (event, &rate, &format, &seek_flags, &start_type,
1311 &start, &stop_type, &stop);
1312 /* upstream seek - store the seek event seqnum to check
1313 * flushes and newsegments share the same */
1315 /* TODO we might need to use a list as multiple seeks can be sent
1316 * before the flushes arrive here */
1317 if (seek_flags & GST_SEEK_FLAG_FLUSH) {
1318 pad_monitor->pending_flush_start_seqnum = seqnum;
1319 pad_monitor->pending_flush_stop_seqnum = seqnum;
1321 pad_monitor->pending_newsegment_seqnum = seqnum;
1322 pad_monitor->pending_eos_seqnum = seqnum;
1325 /* both flushes are handled by the common event handling function */
1326 case GST_EVENT_FLUSH_START:
1327 case GST_EVENT_FLUSH_STOP:
1328 case GST_EVENT_NAVIGATION:
1329 case GST_EVENT_LATENCY:
1330 case GST_EVENT_STEP:
1337 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1338 gst_event_ref (event);
1339 ret = pad_monitor->event_func (pad, parent, event);
1340 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1344 switch (GST_EVENT_TYPE (event)) {
1345 case GST_EVENT_FLUSH_START:
1346 case GST_EVENT_FLUSH_STOP:
1348 case GST_EVENT_SEEK:
1349 case GST_EVENT_NAVIGATION:
1350 case GST_EVENT_LATENCY:
1351 case GST_EVENT_STEP:
1357 gst_event_unref (event);
1361 static GstFlowReturn
1362 gst_validate_pad_monitor_chain_func (GstPad * pad, GstObject * parent,
1365 GstValidatePadMonitor *pad_monitor =
1366 g_object_get_data ((GObject *) pad, "qa-monitor");
1369 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1370 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1372 gst_validate_pad_monitor_check_first_buffer (pad_monitor, buffer);
1373 gst_validate_pad_monitor_update_buffer_data (pad_monitor, buffer);
1375 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1376 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1378 gst_validate_pad_monitor_buffer_overrides (pad_monitor, buffer);
1380 ret = pad_monitor->chain_func (pad, parent, buffer);
1382 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1383 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1385 pad_monitor->last_flow_return = ret;
1386 if (PAD_PARENT_IS_DEMUXER (pad_monitor))
1387 gst_validate_pad_monitor_check_aggregated_return (pad_monitor, ret);
1389 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1390 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1396 gst_validate_pad_monitor_event_is_tracked (GstValidatePadMonitor * monitor,
1399 if (!GST_EVENT_IS_SERIALIZED (event)) {
1403 /* we don't track Tag events because they mutate too much and it is hard
1404 * to match a tag event pushed on a source pad with the one that was received
1406 * One idea would be to use seqnum, but it seems that it is undefined whether
1407 * seqnums should be maintained in tag events that are created from others
1408 * up to today. (2013-08-29)
1410 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
1417 gst_validate_pad_monitor_sink_event_func (GstPad * pad, GstObject * parent,
1420 GstValidatePadMonitor *pad_monitor =
1421 g_object_get_data ((GObject *) pad, "qa-monitor");
1424 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1425 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1427 if (gst_validate_pad_monitor_event_is_tracked (pad_monitor, event)) {
1428 GstClockTime last_ts;
1429 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_timestamp)) {
1430 last_ts = pad_monitor->current_timestamp;
1431 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_duration)) {
1432 last_ts += pad_monitor->current_duration;
1437 gst_validate_pad_monitor_otherpad_add_pending_serialized_event (pad_monitor,
1442 switch (GST_EVENT_TYPE (event)) {
1443 case GST_EVENT_CAPS:{
1446 gst_event_parse_caps (event, &caps);
1447 gst_validate_pad_monitor_setcaps_pre (pad_monitor, caps);
1454 gst_validate_pad_monitor_downstream_event_check (pad_monitor, parent,
1455 event, pad_monitor->event_func);
1457 switch (GST_EVENT_TYPE (event)) {
1458 case GST_EVENT_CAPS:{
1461 gst_event_parse_caps (event, &caps);
1462 gst_validate_pad_monitor_setcaps_post (pad_monitor, caps, ret);
1469 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1470 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1475 gst_validate_pad_monitor_src_event_func (GstPad * pad, GstObject * parent,
1478 GstValidatePadMonitor *pad_monitor =
1479 g_object_get_data ((GObject *) pad, "qa-monitor");
1482 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1483 ret = gst_validate_pad_monitor_src_event_check (pad_monitor, parent, event,
1484 pad_monitor->event_func);
1485 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1490 gst_validate_pad_monitor_query_func (GstPad * pad, GstObject * parent,
1493 GstValidatePadMonitor *pad_monitor =
1494 g_object_get_data ((GObject *) pad, "qa-monitor");
1497 gst_validate_pad_monitor_query_overrides (pad_monitor, query);
1499 ret = pad_monitor->query_func (pad, parent, query);
1502 switch (GST_QUERY_TYPE (query)) {
1503 case GST_QUERY_CAPS:{
1505 /* We shouldn't need to lock the parent as this doesn't modify
1506 * other monitors, just does some peer_pad_caps */
1507 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1509 gst_query_parse_caps_result (query, &res);
1510 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1511 gst_validate_pad_monitor_check_caps_fields_proxied (pad_monitor, res);
1513 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1525 gst_validate_pad_monitor_activatemode_func (GstPad * pad, GstObject * parent,
1526 GstPadMode mode, gboolean active)
1528 GstValidatePadMonitor *pad_monitor =
1529 g_object_get_data ((GObject *) pad, "qa-monitor");
1530 gboolean ret = TRUE;
1532 /* TODO add overrides for activate func */
1534 if (pad_monitor->activatemode_func)
1535 ret = pad_monitor->activatemode_func (pad, parent, mode, active);
1536 if (ret && active == FALSE) {
1537 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1538 gst_validate_pad_monitor_flush (pad_monitor);
1539 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1546 gst_validate_pad_get_range_func (GstPad * pad, GstObject * parent,
1547 guint64 offset, guint size, GstBuffer ** buffer)
1549 GstValidatePadMonitor *pad_monitor =
1550 g_object_get_data ((GObject *) pad, "qa-monitor");
1552 ret = pad_monitor->getrange_func (pad, parent, offset, size, buffer);
1557 gst_validate_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
1560 GstValidatePadMonitor *monitor = udata;
1561 GstValidateMonitor *parent = GST_VALIDATE_MONITOR_GET_PARENT (monitor);
1563 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
1564 GST_VALIDATE_MONITOR_LOCK (monitor);
1566 gst_validate_pad_monitor_check_first_buffer (monitor, buffer);
1567 gst_validate_pad_monitor_update_buffer_data (monitor, buffer);
1569 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range (monitor,
1572 gst_validate_pad_monitor_check_late_serialized_events (monitor,
1573 GST_BUFFER_TIMESTAMP (buffer));
1575 /* a GstValidatePadMonitor parent must be a GstValidateElementMonitor */
1576 if (PAD_PARENT_IS_DECODER (parent)) {
1577 /* should not push out of segment data */
1578 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
1579 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)) &&
1580 !gst_segment_clip (&monitor->segment, monitor->segment.format,
1581 GST_BUFFER_TIMESTAMP (buffer), GST_BUFFER_TIMESTAMP (buffer) +
1582 GST_BUFFER_DURATION (buffer), NULL, NULL)) {
1583 /* TODO is this a timestamp issue? */
1584 GST_VALIDATE_REPORT (monitor, BUFFER_IS_OUT_OF_SEGMENT,
1585 "buffer is out of segment and shouldn't be pushed. Timestamp: %"
1586 GST_TIME_FORMAT " - duration: %" GST_TIME_FORMAT ". Range: %"
1587 GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
1588 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
1589 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
1590 GST_TIME_ARGS (monitor->segment.start),
1591 GST_TIME_ARGS (monitor->segment.stop));
1595 GST_VALIDATE_MONITOR_UNLOCK (monitor);
1596 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
1597 gst_validate_pad_monitor_buffer_probe_overrides (monitor, buffer);
1602 gst_validate_pad_monitor_event_probe (GstPad * pad, GstEvent * event,
1605 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (udata);
1608 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
1609 GST_VALIDATE_MONITOR_LOCK (monitor);
1611 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
1613 if (GST_EVENT_IS_SERIALIZED (event)) {
1616 /* Detect if events the element received are being forwarded in the same order
1618 * Several scenarios:
1619 * 1) The element pushes the event as-is
1620 * 2) The element consumes the event and does not forward it
1621 * 3) The element consumes the event and creates another one instead
1622 * 4) The element pushes other serialized event before pushing out the
1625 * For each pad we have two lists to track serialized events:
1626 * 1) We received on input and expect to see (serialized_events)
1627 * 2) We received on input but don't expect to see (expired_events)
1629 * To detect events that are pushed in a different order from the one they were
1630 * received in we check that:
1632 * For each event being outputted:
1633 * If it is in the expired_events list:
1635 * If it is in the serialized_events list:
1636 * If there are other events that were received before:
1637 * Put those events on the expired_events list
1638 * Remove that event and any previous ones from the serialized_events list
1640 * Clear expired events list when flushing or on pad deactivation
1644 if (g_list_find (monitor->expired_events, event)) {
1645 /* If it's the expired events, we've failed */
1646 GST_WARNING_OBJECT (pad, "Did not expect event %p %s", event,
1647 GST_EVENT_TYPE_NAME (event));
1648 GST_VALIDATE_REPORT (monitor, EVENT_SERIALIZED_OUT_OF_ORDER,
1649 "Serialized event was pushed out of order: %" GST_PTR_FORMAT, event);
1650 monitor->expired_events =
1651 g_list_remove (monitor->expired_events, monitor);
1652 } else if (monitor->serialized_events->len) {
1653 for (i = 0; i < monitor->serialized_events->len; i++) {
1654 SerializedEventData *next_event =
1655 g_ptr_array_index (monitor->serialized_events, i);
1656 GST_DEBUG_OBJECT (pad, "Checking against stored event #%d: %p %s", i,
1657 next_event->event, GST_EVENT_TYPE_NAME (next_event->event));
1659 if (event == next_event->event
1660 || GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
1661 /* We have found our event */
1662 GST_DEBUG_OBJECT (pad, "Found matching event");
1664 while (monitor->serialized_events->len > i
1665 && GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
1666 /* Swallow all expected events of the same type */
1667 g_ptr_array_remove_index (monitor->serialized_events, i);
1668 next_event = g_ptr_array_index (monitor->serialized_events, i);
1671 /* Move all previous events to expired events */
1672 if (G_UNLIKELY (i > 0)) {
1673 GST_DEBUG_OBJECT (pad,
1674 "Moving previous expected events to expired list");
1676 next_event = g_ptr_array_index (monitor->serialized_events, 0);
1677 monitor->expired_events =
1678 g_list_append (monitor->expired_events, next_event->event);
1679 g_ptr_array_remove_index (monitor->serialized_events, 0);
1682 debug_pending_event (pad, monitor->serialized_events);
1689 /* This so far is just like an event that is flowing downstream,
1690 * so we do the same checks as a sinkpad event handler */
1692 gst_validate_pad_monitor_downstream_event_check (monitor, NULL, event,
1694 GST_VALIDATE_MONITOR_UNLOCK (monitor);
1695 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
1700 static GstPadProbeReturn
1701 gst_validate_pad_monitor_pad_probe (GstPad * pad, GstPadProbeInfo * info,
1704 if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
1705 gst_validate_pad_monitor_buffer_probe (pad, info->data, udata);
1706 else if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
1707 gst_validate_pad_monitor_event_probe (pad, info->data, udata);
1709 return GST_PAD_PROBE_OK;
1713 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
1716 GstStructure *structure;
1718 /* Check if caps are identical to last caps and complain if so */
1719 if (pad_monitor->last_caps
1720 && gst_caps_is_equal (caps, pad_monitor->last_caps)) {
1721 GST_VALIDATE_REPORT (pad_monitor, EVENT_CAPS_DUPLICATE, "%" GST_PTR_FORMAT,
1725 gst_validate_pad_monitor_check_caps_complete (pad_monitor, caps);
1728 structure = gst_caps_get_structure (caps, 0);
1729 if (gst_structure_n_fields (pad_monitor->pending_setcaps_fields)) {
1732 i < gst_structure_n_fields (pad_monitor->pending_setcaps_fields);
1735 gst_structure_nth_field_name (pad_monitor->pending_setcaps_fields,
1737 const GValue *v = gst_structure_get_value (structure, name);
1738 const GValue *otherv =
1739 gst_structure_get_value (pad_monitor->pending_setcaps_fields, name);
1742 GST_VALIDATE_REPORT (pad_monitor, CAPS_EXPECTED_FIELD_NOT_FOUND,
1743 "Field %s is missing from setcaps caps '%" GST_PTR_FORMAT "'",
1745 } else if (gst_value_compare (v, otherv) != GST_VALUE_EQUAL) {
1746 GST_VALIDATE_REPORT (pad_monitor, CAPS_FIELD_UNEXPECTED_VALUE,
1747 "Field %s from setcaps caps '%" GST_PTR_FORMAT "' is different "
1748 "from expected value in caps '%" GST_PTR_FORMAT "'", name, caps,
1749 pad_monitor->pending_setcaps_fields);
1754 if (gst_validate_pad_monitor_pad_should_proxy_othercaps (pad_monitor)) {
1755 if (_structure_is_video (structure)) {
1756 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1757 structure, "width");
1758 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1759 structure, "height");
1760 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1761 structure, "framerate");
1762 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1763 structure, "pixel-aspect-ratio");
1764 } else if (_structure_is_audio (structure)) {
1765 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1767 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
1768 structure, "channels");
1773 gst_structure_free (pad_monitor->pending_setcaps_fields);
1774 pad_monitor->pending_setcaps_fields =
1775 gst_structure_new_empty (PENDING_FIELDS);
1777 gst_validate_pad_monitor_setcaps_overrides (pad_monitor, caps);
1781 gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor * pad_monitor,
1782 GstCaps * caps, gboolean ret)
1785 gst_validate_pad_monitor_otherpad_clear_pending_fields (pad_monitor);
1787 if (pad_monitor->last_caps) {
1788 gst_caps_unref (pad_monitor->last_caps);
1790 pad_monitor->last_caps = gst_caps_ref (caps);
1795 gst_validate_pad_monitor_do_setup (GstValidateMonitor * monitor)
1797 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR_CAST (monitor);
1799 if (!GST_IS_PAD (GST_VALIDATE_MONITOR_GET_OBJECT (monitor))) {
1800 GST_WARNING_OBJECT (monitor, "Trying to create pad monitor with other "
1805 pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1807 if (g_object_get_data ((GObject *) pad, "qa-monitor")) {
1808 GST_WARNING_OBJECT (pad_monitor, "Pad already has a qa-monitor associated");
1812 g_object_set_data ((GObject *) pad, "qa-monitor", pad_monitor);
1814 pad_monitor->pad = pad;
1816 pad_monitor->event_func = GST_PAD_EVENTFUNC (pad);
1817 pad_monitor->query_func = GST_PAD_QUERYFUNC (pad);
1818 pad_monitor->activatemode_func = GST_PAD_ACTIVATEMODEFUNC (pad);
1819 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1821 pad_monitor->chain_func = GST_PAD_CHAINFUNC (pad);
1822 if (pad_monitor->chain_func)
1823 gst_pad_set_chain_function (pad, gst_validate_pad_monitor_chain_func);
1825 gst_pad_set_event_function (pad, gst_validate_pad_monitor_sink_event_func);
1827 pad_monitor->getrange_func = GST_PAD_GETRANGEFUNC (pad);
1828 if (pad_monitor->getrange_func)
1829 gst_pad_set_getrange_function (pad, gst_validate_pad_get_range_func);
1831 gst_pad_set_event_function (pad, gst_validate_pad_monitor_src_event_func);
1833 /* add buffer/event probes */
1834 pad_monitor->pad_probe_id =
1835 gst_pad_add_probe (pad,
1836 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
1837 GST_PAD_PROBE_TYPE_EVENT_FLUSH,
1838 (GstPadProbeCallback) gst_validate_pad_monitor_pad_probe, pad_monitor,
1841 gst_pad_set_query_function (pad, gst_validate_pad_monitor_query_func);
1842 gst_pad_set_activatemode_function (pad,
1843 gst_validate_pad_monitor_activatemode_func);
1845 gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (monitor),
1846 g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad)));
1848 if (G_UNLIKELY (GST_PAD_PARENT (pad) == NULL))
1849 GST_FIXME ("Saw a pad not belonging to any object");