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-pipeline-monitor.h"
32 #include "gst-validate-reporter.h"
33 #include "gst-validate-utils.h"
39 * SECTION:gst-validate-pad-monitor
40 * @short_description: Class that wraps a #GstPad for Validate checks
44 #define _GET_PAD_MONITOR(p) g_object_get_qdata ((GObject*) p, _Q_VALIDATE_MONITOR)
45 #define _SET_PAD_MONITOR(p,d) g_object_set_qdata ((GObject*) p, _Q_VALIDATE_MONITOR, d)
47 static GstValidateInterceptionReturn
48 gst_validate_pad_monitor_intercept_report (GstValidateReporter * reporter,
49 GstValidateReport * report);
52 G_IMPLEMENT_INTERFACE (GST_TYPE_VALIDATE_REPORTER, _reporter_iface_init)
55 _reporter_iface_init (GstValidateReporterInterface * iface)
57 iface->intercept_report = gst_validate_pad_monitor_intercept_report;
60 #define gst_validate_pad_monitor_parent_class parent_class
61 G_DEFINE_TYPE_WITH_CODE (GstValidatePadMonitor, gst_validate_pad_monitor,
62 GST_TYPE_VALIDATE_MONITOR, _do_init);
64 #define PENDING_FIELDS "pending-fields"
65 #define AUDIO_TIMESTAMP_TOLERANCE (GST_MSECOND * 100)
67 #define PAD_PARENT_IS_DEMUXER(m) \
68 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
69 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DEMUXER ( \
70 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
73 #define PAD_PARENT_IS_DECODER(m) \
74 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
75 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER ( \
76 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
79 #define PAD_PARENT_IS_ENCODER(m) \
80 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
81 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER ( \
82 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
85 #define PAD_PARENT_IS_SINK(m) \
86 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
87 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_SINK ( \
88 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
93 * Locking the parent should always be done before locking the
94 * pad-monitor to prevent deadlocks in case another monitor from
95 * another pad on the same element starts an operation that also
96 * requires locking itself and some other monitors from internally
100 * An element has a sink and a src pad. Some test starts running at sinkpad
101 * and it locks the parent, and then it locks itself. In case it needs to get
102 * some information from the srcpad, it is able to lock the srcpad and get it
103 * because the srcpad should never lock itself before locking the parent (which
104 * it won't be able as sinkpad already locked it).
106 * As a side one, it is possible that srcpad locks itself without locking the
107 * parent in case it wants to do a check that won't need to use other internally
108 * linked pads (sinkpad). But in this case it might lock and unlock freely without
111 #define GST_VALIDATE_PAD_MONITOR_PARENT_LOCK(m) \
113 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
114 GST_VALIDATE_MONITOR_LOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
116 GST_WARNING_OBJECT (m, "No parent found, can't lock"); \
120 #define GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK(m) \
122 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
123 GST_VALIDATE_MONITOR_UNLOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
125 GST_WARNING_OBJECT (m, "No parent found, can't unlock"); \
129 /* Structure used to store all seek-related information */
130 struct _GstValidatePadSeekData
136 GstSeekType start_type, stop_type;
142 GstClockTime timestamp;
144 } SerializedEventData;
147 _get_actual_pad (GstPad * pad)
149 pad = gst_object_ref (pad);
151 while (GST_IS_PROXY_PAD (pad)) {
154 if (GST_PAD_IS_SINK (pad)) {
155 if (GST_IS_GHOST_PAD (pad))
156 next_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
158 next_pad = GST_PAD (gst_proxy_pad_get_internal (GST_PROXY_PAD (pad)));
160 next_pad = gst_pad_get_peer (pad);
163 gst_object_unref (pad);
174 _find_master_report_on_pad (GstPad * pad, GstValidateReport * report)
176 GstValidatePadMonitor *pad_monitor;
177 GstValidateReport *prev_report;
178 gboolean result = FALSE;
179 GstPad *tmppad = pad;
181 pad = _get_actual_pad (pad);
183 GST_ERROR_OBJECT (tmppad, "Does not have a target yet");
188 pad_monitor = _GET_PAD_MONITOR (pad);
190 /* For some reason this pad isn't monitored */
191 if (pad_monitor == NULL)
194 prev_report = gst_validate_reporter_get_report ((GstValidateReporter *)
195 pad_monitor, report->issue->issue_id);
198 if (prev_report->master_report)
199 result = gst_validate_report_set_master_report (report,
200 prev_report->master_report);
202 result = gst_validate_report_set_master_report (report, prev_report);
206 gst_object_unref (pad);
212 _find_master_report_for_sink_pad (GstValidatePadMonitor * pad_monitor,
213 GstValidateReport * report)
216 gboolean result = FALSE;
218 GST_PAD_CAST (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
221 peerpad = gst_pad_get_peer (pad);
222 gst_object_unref (pad);
224 /* If the peer src pad already has a similar report no need to look
226 if (peerpad && _find_master_report_on_pad (peerpad, report))
230 gst_object_unref (peerpad);
236 _find_master_report_for_src_pad (GstValidatePadMonitor * pad_monitor,
237 GstValidateReport * report)
241 gboolean result = FALSE;
243 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
246 iter = gst_pad_iterate_internal_links (target);
249 GValue value = { 0, };
250 switch (gst_iterator_next (iter, &value)) {
251 case GST_ITERATOR_OK:
253 GstPad *pad = g_value_get_object (&value);
255 if (_find_master_report_on_pad (pad, report)) {
260 g_value_reset (&value);
263 case GST_ITERATOR_RESYNC:
264 gst_iterator_resync (iter);
266 case GST_ITERATOR_ERROR:
267 GST_WARNING_OBJECT (target, "Internal links pad iteration error");
270 case GST_ITERATOR_DONE:
275 gst_object_unref (target);
276 gst_iterator_free (iter);
281 static GstValidateInterceptionReturn
282 _concatenate_issues (GstValidatePadMonitor * pad_monitor,
283 GstValidateReport * report)
286 GST_PAD_CAST (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
289 if (GST_PAD_IS_SINK (pad)
290 && _find_master_report_for_sink_pad (pad_monitor, report)) {
291 gst_object_unref (pad);
292 return GST_VALIDATE_REPORTER_KEEP;
293 } else if (GST_PAD_IS_SRC (pad)
294 && _find_master_report_for_src_pad (pad_monitor, report)) {
295 gst_object_unref (pad);
296 return GST_VALIDATE_REPORTER_KEEP;
299 gst_object_unref (pad);
300 return GST_VALIDATE_REPORTER_REPORT;
303 static GstValidateInterceptionReturn
304 gst_validate_pad_monitor_intercept_report (GstValidateReporter *
305 reporter, GstValidateReport * report)
307 GstValidateReporterInterface *iface_class, *old_iface_class;
308 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR (reporter);
309 GstValidateReportingDetails monitor_reporting_level;
310 GstValidateInterceptionReturn ret;
312 monitor_reporting_level =
313 gst_validate_reporter_get_reporting_level (reporter);
316 G_TYPE_INSTANCE_GET_INTERFACE (reporter, GST_TYPE_VALIDATE_REPORTER,
317 GstValidateReporterInterface);
318 old_iface_class = g_type_interface_peek_parent (iface_class);
320 old_iface_class->intercept_report (reporter, report);
322 switch (monitor_reporting_level) {
323 case GST_VALIDATE_SHOW_NONE:
324 ret = GST_VALIDATE_REPORTER_DROP;
326 case GST_VALIDATE_SHOW_UNKNOWN:
327 ret = _concatenate_issues (pad_monitor, report);
330 ret = GST_VALIDATE_REPORTER_REPORT;
334 gst_validate_report_set_reporting_level (report, monitor_reporting_level);
339 debug_pending_event (GstPad * pad, GPtrArray * array)
344 for (i = 0; i < len; i++) {
345 SerializedEventData *data = g_ptr_array_index (array, i);
346 GST_DEBUG_OBJECT (pad, "event #%d %" GST_TIME_FORMAT " %s %p",
347 i, GST_TIME_ARGS (data->timestamp),
348 GST_EVENT_TYPE_NAME (data->event), data->event);
353 _serialized_event_data_free (SerializedEventData * serialized_event)
355 gst_event_unref (serialized_event->event);
356 g_slice_free (SerializedEventData, serialized_event);
359 static gboolean gst_validate_pad_monitor_do_setup (GstValidateMonitor *
361 static GstElement *gst_validate_pad_monitor_get_element (GstValidateMonitor *
364 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
366 static void gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor *
367 pad_monitor, GstCaps * caps, gboolean ret);
369 #define PAD_IS_IN_PUSH_MODE(p) ((p)->mode == GST_PAD_MODE_PUSH)
372 _structure_is_raw_video (GstStructure * structure)
374 return gst_structure_has_name (structure, "video/x-raw");
378 _structure_is_raw_audio (GstStructure * structure)
380 return gst_structure_has_name (structure, "audio/x-raw");
384 _get_event_string (GstEvent * event)
386 const GstStructure *st;
388 if ((st = gst_event_get_structure (event)))
389 return gst_structure_to_string (st);
391 return g_strdup_printf ("%s", GST_EVENT_TYPE_NAME (event));
395 _check_field_type (GstValidatePadMonitor * monitor,
396 GstStructure * structure, gboolean mandatory, const gchar * field, ...)
400 gchar *joined_types = NULL;
401 const gchar *rejected_types[5];
402 gint rejected_types_index = 0;
405 if (!gst_structure_has_field (structure, field)) {
407 gchar *str = gst_structure_to_string (structure);
409 GST_VALIDATE_REPORT (monitor, CAPS_IS_MISSING_FIELD,
410 "Field '%s' is missing from structure: %s", field, str);
413 GST_DEBUG_OBJECT (monitor, "Field %s is missing but is not mandatory",
419 memset ((gchar **) rejected_types, 0, sizeof (rejected_types));
420 va_start (var_args, field);
421 while ((type = va_arg (var_args, GType)) != 0) {
422 if (gst_structure_has_field_typed (structure, field, type)) {
426 rejected_types[rejected_types_index++] = g_type_name (type);
430 joined_types = g_strjoinv (" / ", (gchar **) rejected_types);
431 struct_str = gst_structure_to_string (structure);
432 GST_VALIDATE_REPORT (monitor, CAPS_FIELD_HAS_BAD_TYPE,
433 "Field '%s' has wrong type %s in structure '%s'. Expected: %s", field,
434 g_type_name (gst_structure_get_field_type (structure, field)), struct_str,
436 g_free (joined_types);
441 gst_validate_pad_monitor_check_raw_video_caps_complete (GstValidatePadMonitor *
442 monitor, GstStructure * structure)
444 _check_field_type (monitor, structure, TRUE, "width", G_TYPE_INT,
445 GST_TYPE_INT_RANGE, 0);
446 _check_field_type (monitor, structure, TRUE, "height", G_TYPE_INT,
447 GST_TYPE_INT_RANGE, 0);
448 _check_field_type (monitor, structure, TRUE, "framerate", GST_TYPE_FRACTION,
449 GST_TYPE_FRACTION_RANGE, 0);
450 _check_field_type (monitor, structure, FALSE, "pixel-aspect-ratio",
451 GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, 0);
452 _check_field_type (monitor, structure, TRUE, "format", G_TYPE_STRING,
457 gst_validate_pad_monitor_check_raw_audio_caps_complete (GstValidatePadMonitor *
458 monitor, GstStructure * structure)
461 _check_field_type (monitor, structure, TRUE, "format", G_TYPE_STRING,
463 _check_field_type (monitor, structure, TRUE, "layout", G_TYPE_STRING,
465 _check_field_type (monitor, structure, TRUE, "rate", G_TYPE_INT,
466 GST_TYPE_LIST, GST_TYPE_INT_RANGE, 0);
467 _check_field_type (monitor, structure, TRUE, "channels", G_TYPE_INT,
468 GST_TYPE_LIST, GST_TYPE_INT_RANGE, 0);
469 if (gst_structure_get_int (structure, "channels", &channels)) {
471 _check_field_type (monitor, structure, TRUE, "channel-mask",
472 GST_TYPE_BITMASK, GST_TYPE_LIST, 0);
477 gst_validate_pad_monitor_check_caps_complete (GstValidatePadMonitor * monitor,
480 GstStructure *structure;
483 GST_DEBUG_OBJECT (monitor, "Checking caps %" GST_PTR_FORMAT, caps);
485 for (i = 0; i < gst_caps_get_size (caps); i++) {
486 structure = gst_caps_get_structure (caps, i);
488 if (_structure_is_raw_video (structure)) {
489 gst_validate_pad_monitor_check_raw_video_caps_complete (monitor,
492 } else if (_structure_is_raw_audio (structure)) {
493 gst_validate_pad_monitor_check_raw_audio_caps_complete (monitor,
500 gst_validate_pad_monitor_get_othercaps (GstValidatePadMonitor * monitor,
503 GstCaps *caps = gst_caps_new_empty ();
509 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
512 iter = gst_pad_iterate_internal_links (pad);
515 GValue value = { 0, };
516 switch (gst_iterator_next (iter, &value)) {
517 case GST_ITERATOR_OK:
518 otherpad = g_value_get_object (&value);
520 /* TODO What would be the correct caps operation to merge the caps in
521 * case one sink is internally linked to multiple srcs? */
522 peercaps = gst_pad_peer_query_caps (otherpad, filter);
524 caps = gst_caps_merge (caps, peercaps);
526 g_value_reset (&value);
528 case GST_ITERATOR_RESYNC:
529 gst_iterator_resync (iter);
530 gst_caps_unref (caps);
531 caps = gst_caps_new_empty ();
533 case GST_ITERATOR_ERROR:
534 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
537 case GST_ITERATOR_DONE:
542 GST_DEBUG_OBJECT (pad, "Otherpad caps: %" GST_PTR_FORMAT, caps);
544 gst_iterator_free (iter);
545 gst_object_unref (pad);
551 _structure_is_video (GstStructure * structure)
553 const gchar *name = gst_structure_get_name (structure);
555 return g_strstr_len (name, 6, "video/")
556 && g_strcmp0 (name, "video/quicktime") != 0;
560 _structure_is_audio (GstStructure * structure)
562 const gchar *name = gst_structure_get_name (structure);
564 return g_strstr_len (name, 6, "audio/") != NULL;
568 gst_validate_pad_monitor_pad_should_proxy_othercaps (GstValidatePadMonitor *
571 GstValidateMonitor *parent = GST_VALIDATE_MONITOR_GET_PARENT (monitor);
576 /* We only know how to handle othercaps checks for codecs so far */
577 return (GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER (parent) ||
578 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER (parent)) &&
579 !GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_CONVERTER (parent);
583 /* Check if the field @f from @s2 (if present) is represented in @s1
584 * Represented here means either equal or @s1's value is in a list/range
588 _structures_field_is_contained (GstStructure * s1, GstStructure * s2,
589 gboolean mandatory, const gchar * f)
594 v2 = gst_structure_get_value (s2, f);
596 return TRUE; /* nothing to compare to */
598 v1 = gst_structure_get_value (s1, f);
602 if (!gst_value_is_fixed (v1))
605 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
608 if (GST_VALUE_HOLDS_LIST (v2)) {
610 for (i = 0; i < gst_value_list_get_size (v2); i++) {
611 const GValue *v2_subvalue = gst_value_list_get_value (v2, i);
612 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
617 if (GST_VALUE_HOLDS_ARRAY (v2)) {
619 for (i = 0; i < gst_value_array_get_size (v2); i++) {
620 const GValue *v2_subvalue = gst_value_array_get_value (v2, i);
621 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
626 if (GST_VALUE_HOLDS_INT_RANGE (v2)) {
629 min = gst_value_get_int_range_min (v2);
630 max = gst_value_get_int_range_max (v2);
632 if (G_VALUE_HOLDS_INT (v1)) {
633 gint v = g_value_get_int (v1);
635 return v >= min && v <= max;
637 /* TODO compare int ranges with int ranges
638 * or with lists if useful */
642 if (GST_VALUE_HOLDS_FRACTION_RANGE (v2)) {
643 const GValue *min, *max;
645 min = gst_value_get_fraction_range_min (v2);
646 max = gst_value_get_fraction_range_max (v2);
648 if (GST_VALUE_HOLDS_FRACTION (v1)) {
649 gint v_min = gst_value_compare (v1, min);
650 gint v_max = gst_value_compare (v1, max);
652 return (v_min == GST_VALUE_EQUAL || v_min == GST_VALUE_GREATER_THAN) &&
653 (v_max == GST_VALUE_EQUAL || v_max == GST_VALUE_LESS_THAN);
655 /* TODO compare fraction ranges with fraction ranges
656 * or with lists if useful */
664 _check_and_copy_structure_field (GstStructure * from, GstStructure * to,
667 if (gst_structure_has_field (from, name)) {
668 gst_structure_set_value (to, name, gst_structure_get_value (from, name));
673 gst_validate_pad_monitor_copy_caps_fields_into_caps (GstValidatePadMonitor *
674 monitor, GstCaps * from_caps, GstCaps * into_caps)
676 gint i, j, into_size, from_size;
677 GstStructure *structure;
678 GstCaps *res = gst_caps_new_empty ();
680 into_size = gst_caps_get_size (into_caps);
681 from_size = gst_caps_get_size (from_caps);
683 for (i = 0; i < into_size; i++) {
684 GstStructure *s = gst_caps_get_structure (into_caps, i);
686 for (j = 0; j < from_size; j++) {
687 GstStructure *new_structure = gst_structure_copy (s);
689 structure = gst_caps_get_structure (from_caps, j);
690 if (_structure_is_video (structure)) {
691 _check_and_copy_structure_field (structure, new_structure, "width");
692 _check_and_copy_structure_field (structure, new_structure, "height");
693 _check_and_copy_structure_field (structure, new_structure, "framerate");
694 _check_and_copy_structure_field (structure, new_structure,
695 "pixel-aspect-ratio");
696 } else if (_structure_is_audio (s)) {
697 _check_and_copy_structure_field (structure, new_structure, "rate");
698 _check_and_copy_structure_field (structure, new_structure, "channels");
701 gst_caps_append_structure (res, new_structure);
708 gst_validate_pad_monitor_transform_caps (GstValidatePadMonitor * monitor,
716 GstCaps *template_caps;
720 GST_DEBUG_OBJECT (monitor, "Transform caps %" GST_PTR_FORMAT, caps);
725 othercaps = gst_caps_new_empty ();
728 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
730 iter = gst_pad_iterate_internal_links (pad);
733 GValue value = { 0, };
734 switch (gst_iterator_next (iter, &value)) {
735 case GST_ITERATOR_OK:
736 otherpad = g_value_get_object (&value);
737 template_caps = gst_pad_get_pad_template_caps (otherpad);
740 gst_validate_pad_monitor_copy_caps_fields_into_caps (monitor, caps,
742 if (!gst_caps_is_empty (new_caps))
743 gst_caps_append (othercaps, new_caps);
745 gst_caps_unref (new_caps);
747 gst_caps_unref (template_caps);
748 g_value_reset (&value);
750 case GST_ITERATOR_RESYNC:
751 gst_iterator_resync (iter);
752 gst_caps_unref (othercaps);
753 othercaps = gst_caps_new_empty ();
755 case GST_ITERATOR_ERROR:
756 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
759 case GST_ITERATOR_DONE:
764 gst_iterator_free (iter);
766 GST_DEBUG_OBJECT (pad, "Transformed caps: %" GST_PTR_FORMAT, othercaps);
767 gst_object_unref (pad);
773 gst_validate_pad_monitor_check_caps_fields_proxied (GstValidatePadMonitor *
774 monitor, GstCaps * caps, GstCaps * filter)
776 GstStructure *structure;
777 GstStructure *otherstructure;
779 GstCaps *otherfilter;
782 if (!gst_validate_pad_monitor_pad_should_proxy_othercaps (monitor))
785 otherfilter = gst_validate_pad_monitor_transform_caps (monitor, filter);
786 othercaps = gst_validate_pad_monitor_get_othercaps (monitor, otherfilter);
788 gst_caps_unref (otherfilter);
790 for (i = 0; i < gst_caps_get_size (othercaps); i++) {
791 gboolean found = FALSE;
792 gboolean type_match = FALSE;
794 otherstructure = gst_caps_get_structure (othercaps, i);
796 /* look for a proxied version of 'otherstructure' */
797 if (_structure_is_video (otherstructure)) {
798 for (j = 0; j < gst_caps_get_size (caps); j++) {
799 structure = gst_caps_get_structure (caps, j);
800 if (_structure_is_video (structure)) {
802 if (_structures_field_is_contained (structure, otherstructure, TRUE,
804 && _structures_field_is_contained (structure, otherstructure,
806 && _structures_field_is_contained (structure, otherstructure,
808 && _structures_field_is_contained (structure, otherstructure,
809 FALSE, "pixel-aspect-ratio")) {
815 } else if (_structure_is_audio (otherstructure)) {
816 for (j = 0; j < gst_caps_get_size (caps); j++) {
817 structure = gst_caps_get_structure (caps, j);
818 if (_structure_is_audio (structure)) {
820 if (_structures_field_is_contained (structure, otherstructure, TRUE,
822 && _structures_field_is_contained (structure, otherstructure,
831 if (type_match && !found) {
832 gchar *otherstruct_str = gst_structure_to_string (otherstructure),
833 *caps_str = gst_caps_to_string (caps);
835 GST_VALIDATE_REPORT (monitor, GET_CAPS_NOT_PROXYING_FIELDS,
836 "Peer pad structure '%s' has no similar version "
837 "on pad's caps '%s'", otherstruct_str, caps_str);
839 g_free (otherstruct_str);
844 gst_caps_unref (othercaps);
848 gst_validate_pad_monitor_check_late_serialized_events (GstValidatePadMonitor *
849 monitor, GstClockTime ts)
854 if (!GST_CLOCK_TIME_IS_VALID (ts))
858 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
861 GST_DEBUG_OBJECT (pad, "Timestamp to check %" GST_TIME_FORMAT,
864 for (i = 0; i < monitor->serialized_events->len; i++) {
865 SerializedEventData *data =
866 g_ptr_array_index (monitor->serialized_events, i);
868 GST_DEBUG_OBJECT (pad, "Event #%d (%s) ts: %" GST_TIME_FORMAT,
869 i, GST_EVENT_TYPE_NAME (data->event), GST_TIME_ARGS (data->timestamp));
871 if (GST_CLOCK_TIME_IS_VALID (data->timestamp) && data->timestamp < ts) {
872 gchar *event_str = _get_event_string (data->event);
874 GST_VALIDATE_REPORT (monitor, SERIALIZED_EVENT_WASNT_PUSHED_IN_TIME,
875 "Serialized event %s wasn't pushed before expected timestamp %"
876 GST_TIME_FORMAT " on pad %s:%s", event_str,
877 GST_TIME_ARGS (data->timestamp), GST_DEBUG_PAD_NAME (pad));
881 /* events should be ordered by ts */
887 debug_pending_event (pad, monitor->serialized_events);
888 g_ptr_array_remove_range (monitor->serialized_events, 0, i);
891 gst_object_unref (pad);
895 seek_data_free (GstValidatePadSeekData * data)
897 g_slice_free (GstValidatePadSeekData, data);
900 static GstValidatePadSeekData *
901 seek_data_for_seqnum (GstValidatePadMonitor * monitor, guint32 seqnum)
905 for (tmp = monitor->seeks; tmp; tmp = tmp->next) {
906 GstValidatePadSeekData *data = (GstValidatePadSeekData *) tmp->data;
907 if (data->seqnum == seqnum)
915 gst_validate_pad_monitor_dispose (GObject * object)
917 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (object);
919 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
923 if (monitor->pad_probe_id)
924 gst_pad_remove_probe (pad, monitor->pad_probe_id);
925 gst_object_unref (pad);
928 if (monitor->expected_segment)
929 gst_event_unref (monitor->expected_segment);
931 gst_structure_free (monitor->pending_setcaps_fields);
932 g_ptr_array_unref (monitor->serialized_events);
933 g_list_free_full (monitor->expired_events, (GDestroyNotify) gst_event_unref);
934 g_list_free_full (monitor->all_bufs, (GDestroyNotify) gst_buffer_unref);
935 gst_caps_replace (&monitor->last_caps, NULL);
936 gst_caps_replace (&monitor->last_query_res, NULL);
937 gst_caps_replace (&monitor->last_query_filter, NULL);
939 g_list_free_full (monitor->seeks, (GDestroyNotify) seek_data_free);
941 G_OBJECT_CLASS (parent_class)->dispose (object);
945 gst_validate_pad_monitor_class_init (GstValidatePadMonitorClass * klass)
947 GObjectClass *gobject_class;
948 GstValidateMonitorClass *monitor_klass;
950 gobject_class = G_OBJECT_CLASS (klass);
951 monitor_klass = GST_VALIDATE_MONITOR_CLASS (klass);
953 gobject_class->dispose = gst_validate_pad_monitor_dispose;
955 monitor_klass->setup = gst_validate_pad_monitor_do_setup;
956 monitor_klass->get_element = gst_validate_pad_monitor_get_element;
959 /* Called when a pad is being flushed */
961 gst_validate_pad_monitor_flush (GstValidatePadMonitor * pad_monitor)
963 /* Note: Keep in the same order as in the GstValidatePadMonitor structure */
965 gst_caps_replace (&pad_monitor->last_caps, NULL);
966 pad_monitor->caps_is_audio = pad_monitor->caps_is_video =
967 pad_monitor->caps_is_raw = FALSE;
969 pad_monitor->first_buffer = TRUE;
971 pad_monitor->has_segment = FALSE;
972 pad_monitor->is_eos = FALSE;
974 pad_monitor->pending_buffer_discont = TRUE;
976 gst_event_replace (&pad_monitor->expected_segment, NULL);
977 if (pad_monitor->serialized_events->len)
978 g_ptr_array_remove_range (pad_monitor->serialized_events, 0,
979 pad_monitor->serialized_events->len);
980 g_list_free_full (pad_monitor->expired_events,
981 (GDestroyNotify) gst_event_unref);
982 pad_monitor->expired_events = NULL;
984 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
985 pad_monitor->current_timestamp = GST_CLOCK_TIME_NONE;
986 pad_monitor->current_duration = GST_CLOCK_TIME_NONE;
988 pad_monitor->last_flow_return = GST_FLOW_OK;
990 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
991 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
994 /* Called when the pad monitor is initialized or when
995 * the pad is deactivated */
997 gst_validate_pad_monitor_reset (GstValidatePadMonitor * pad_monitor)
999 gst_validate_pad_monitor_flush (pad_monitor);
1001 /* Note : For the entries that haven't been reset in _flush(), do
1002 * it here and keep in the same order as the GstValidatePadMonitor
1005 pad_monitor->pending_flush_stop = FALSE;
1006 pad_monitor->pending_newsegment_seqnum = GST_SEQNUM_INVALID;
1007 pad_monitor->pending_eos_seqnum = GST_SEQNUM_INVALID;
1009 if (pad_monitor->pending_setcaps_fields)
1010 gst_structure_free (pad_monitor->pending_setcaps_fields);
1011 pad_monitor->pending_setcaps_fields =
1012 gst_structure_new_empty (PENDING_FIELDS);
1013 if (pad_monitor->seeks)
1014 g_list_free_full (pad_monitor->seeks, (GDestroyNotify) seek_data_free);
1015 pad_monitor->current_seek = NULL;
1016 pad_monitor->seeks = NULL;
1018 /* FIXME : Why BYTES and not UNDEFINED ? */
1019 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
1021 pad_monitor->min_buf_freq = 0;
1022 pad_monitor->buffers_pushed = 0;
1023 pad_monitor->last_buffers_pushed = 0;
1024 pad_monitor->min_buf_freq_interval_ts = GST_CLOCK_TIME_NONE;
1025 pad_monitor->min_buf_freq_first_buffer_ts = GST_CLOCK_TIME_NONE;
1026 pad_monitor->min_buf_freq_start = GST_CLOCK_TIME_NONE;
1030 gst_validate_pad_monitor_init (GstValidatePadMonitor * pad_monitor)
1032 pad_monitor->serialized_events =
1033 g_ptr_array_new_with_free_func ((GDestroyNotify)
1034 _serialized_event_data_free);
1036 gst_validate_pad_monitor_reset (pad_monitor);
1040 * gst_validate_pad_monitor_new:
1041 * @pad: (transfer none): a #GstPad to run Validate on
1043 GstValidatePadMonitor *
1044 gst_validate_pad_monitor_new (GstPad * pad, GstValidateRunner * runner,
1045 GstValidateElementMonitor * parent)
1047 GstValidatePadMonitor *monitor = g_object_new (GST_TYPE_VALIDATE_PAD_MONITOR,
1048 "object", pad, "validate-runner", runner, "validate-parent",
1051 gst_validate_monitor_get_target (GST_VALIDATE_MONITOR (monitor));
1053 if (target == NULL) {
1054 g_object_unref (monitor);
1058 gst_object_unref (target);
1063 gst_validate_pad_monitor_get_element (GstValidateMonitor * monitor)
1066 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1068 GstElement *parent = GST_ELEMENT (gst_pad_get_parent (pad));
1070 gst_object_unref (pad);
1076 gst_validate_pad_monitor_event_overrides (GstValidatePadMonitor * pad_monitor,
1081 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1082 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1083 iter = g_list_next (iter)) {
1084 GstValidateOverride *override = iter->data;
1086 gst_validate_override_event_handler (override,
1087 GST_VALIDATE_MONITOR_CAST (pad_monitor), event);
1089 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1093 gst_validate_pad_monitor_buffer_overrides (GstValidatePadMonitor * pad_monitor,
1098 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1099 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1100 iter = g_list_next (iter)) {
1101 GstValidateOverride *override = iter->data;
1103 gst_validate_override_buffer_handler (override,
1104 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
1106 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1110 gst_validate_pad_monitor_buffer_probe_overrides (GstValidatePadMonitor *
1111 pad_monitor, GstBuffer * buffer)
1115 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1116 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1117 iter = g_list_next (iter)) {
1118 GstValidateOverride *override = iter->data;
1120 gst_validate_override_buffer_probe_handler (override,
1121 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
1123 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1127 gst_validate_pad_monitor_query_overrides (GstValidatePadMonitor * pad_monitor,
1132 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1133 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1134 iter = g_list_next (iter)) {
1135 GstValidateOverride *override = iter->data;
1137 gst_validate_override_query_handler (override,
1138 GST_VALIDATE_MONITOR_CAST (pad_monitor), query);
1140 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1144 gst_validate_pad_monitor_setcaps_overrides (GstValidatePadMonitor * pad_monitor,
1149 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1150 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1151 iter = g_list_next (iter)) {
1152 GstValidateOverride *override = iter->data;
1154 gst_validate_override_setcaps_handler (override,
1155 GST_VALIDATE_MONITOR_CAST (pad_monitor), caps);
1157 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1160 /* FIXME : This is a bit dubious, what's the point of this check ? */
1162 gst_validate_pad_monitor_timestamp_is_in_received_range (GstValidatePadMonitor *
1163 monitor, GstClockTime ts, GstClockTime tolerance)
1166 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1169 GST_DEBUG_OBJECT (pad,
1170 "Checking if timestamp %" GST_TIME_FORMAT " is in range: %"
1171 GST_TIME_FORMAT " - %" GST_TIME_FORMAT " for pad "
1172 "%s:%s with tolerance: %" GST_TIME_FORMAT, GST_TIME_ARGS (ts),
1173 GST_TIME_ARGS (monitor->timestamp_range_start),
1174 GST_TIME_ARGS (monitor->timestamp_range_end), GST_DEBUG_PAD_NAME (pad),
1175 GST_TIME_ARGS (tolerance));
1176 gst_object_unref (pad);
1178 return !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_start) ||
1179 !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_end) ||
1180 ((monitor->timestamp_range_start >= tolerance ?
1181 monitor->timestamp_range_start - tolerance : 0) <= ts
1182 && (ts >= tolerance ? ts - tolerance : 0) <=
1183 monitor->timestamp_range_end);
1186 /* Iterates over internal links (sinkpads) to check that this buffer has
1187 * a timestamp that is in the range of the lastly received buffers */
1189 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range
1190 (GstValidatePadMonitor * monitor, GstBuffer * buffer,
1191 GstClockTime tolerance)
1194 GstClockTime ts_end;
1196 gboolean has_one = FALSE;
1197 gboolean found = FALSE;
1200 GstValidatePadMonitor *othermonitor;
1202 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1205 if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))
1206 || !GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
1207 GST_DEBUG_OBJECT (pad,
1208 "Can't check buffer timestamps range as "
1209 "buffer has no valid timestamp/duration");
1213 ts = GST_BUFFER_TIMESTAMP (buffer);
1214 ts_end = ts + GST_BUFFER_DURATION (buffer);
1216 iter = gst_pad_iterate_internal_links (pad);
1219 GST_WARNING_OBJECT (pad, "No iterator available");
1225 GValue value = { 0, };
1226 switch (gst_iterator_next (iter, &value)) {
1227 case GST_ITERATOR_OK:
1228 otherpad = g_value_get_object (&value);
1229 GST_DEBUG_OBJECT (pad, "Checking pad %s:%s input timestamps",
1230 GST_DEBUG_PAD_NAME (otherpad));
1231 othermonitor = _GET_PAD_MONITOR (otherpad);
1235 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1236 if (gst_validate_pad_monitor_timestamp_is_in_received_range
1237 (othermonitor, ts, tolerance)
1239 gst_validate_pad_monitor_timestamp_is_in_received_range
1240 (othermonitor, ts_end, tolerance)) {
1244 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1245 g_value_reset (&value);
1248 case GST_ITERATOR_RESYNC:
1249 gst_iterator_resync (iter);
1253 case GST_ITERATOR_ERROR:
1254 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1257 case GST_ITERATOR_DONE:
1262 gst_iterator_free (iter);
1265 GST_DEBUG_OBJECT (pad, "Skipping timestamp in range check as no "
1266 "internal linked pad was found");
1270 GST_VALIDATE_REPORT (monitor, BUFFER_TIMESTAMP_OUT_OF_RECEIVED_RANGE,
1271 "Timestamp %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT
1272 " is out of range of received input", GST_TIME_ARGS (ts),
1273 GST_TIME_ARGS (ts_end));
1277 gst_object_unref (pad);
1281 gst_validate_pad_monitor_check_discont (GstValidatePadMonitor * pad_monitor,
1284 if (pad_monitor->pending_buffer_discont) {
1285 if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))
1286 GST_VALIDATE_REPORT (pad_monitor, BUFFER_MISSING_DISCONT,
1287 "Buffer is missing a DISCONT flag");
1288 pad_monitor->pending_buffer_discont = FALSE;
1293 gst_validate_pad_monitor_check_first_buffer (GstValidatePadMonitor *
1294 pad_monitor, GstBuffer * buffer)
1297 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1300 if (G_UNLIKELY (pad_monitor->first_buffer)) {
1301 pad_monitor->first_buffer = FALSE;
1303 if (!pad_monitor->has_segment && PAD_IS_IN_PUSH_MODE (pad)) {
1304 GST_VALIDATE_REPORT (pad_monitor, BUFFER_BEFORE_SEGMENT,
1305 "Received buffer before Segment event");
1308 GST_DEBUG_OBJECT (pad,
1309 "Checking first buffer (pts:%" GST_TIME_FORMAT " dts:%" GST_TIME_FORMAT
1310 ")", GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
1311 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)));
1315 gst_object_unref (pad);
1319 gst_validate_pad_monitor_check_eos (GstValidatePadMonitor *
1320 pad_monitor, GstBuffer * buffer)
1322 if (G_UNLIKELY (pad_monitor->is_eos)) {
1323 GST_VALIDATE_REPORT (pad_monitor, BUFFER_AFTER_EOS,
1324 "Received buffer %" GST_PTR_FORMAT " after EOS", buffer);
1329 gst_validate_pad_monitor_update_buffer_data (GstValidatePadMonitor *
1330 pad_monitor, GstBuffer * buffer)
1333 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1335 pad_monitor->current_timestamp = GST_BUFFER_TIMESTAMP (buffer);
1336 pad_monitor->current_duration = GST_BUFFER_DURATION (buffer);
1337 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
1338 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_start)) {
1339 pad_monitor->timestamp_range_start =
1340 MIN (pad_monitor->timestamp_range_start,
1341 GST_BUFFER_TIMESTAMP (buffer));
1343 pad_monitor->timestamp_range_start = GST_BUFFER_TIMESTAMP (buffer);
1346 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
1347 GstClockTime endts =
1348 GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
1349 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_end)) {
1350 pad_monitor->timestamp_range_end =
1351 MAX (pad_monitor->timestamp_range_end, endts);
1353 pad_monitor->timestamp_range_end = endts;
1357 GST_DEBUG_OBJECT (pad, "Current stored range: %" GST_TIME_FORMAT
1358 " - %" GST_TIME_FORMAT,
1359 GST_TIME_ARGS (pad_monitor->timestamp_range_start),
1360 GST_TIME_ARGS (pad_monitor->timestamp_range_end));
1362 gst_object_unref (pad);
1365 static GstFlowReturn
1366 _combine_flows (GstFlowReturn ret1, GstFlowReturn ret2)
1370 if (ret1 <= GST_FLOW_NOT_NEGOTIATED)
1372 if (ret2 <= GST_FLOW_NOT_NEGOTIATED)
1374 if (ret1 == GST_FLOW_FLUSHING || ret2 == GST_FLOW_FLUSHING)
1375 return GST_FLOW_FLUSHING;
1376 if (ret1 == GST_FLOW_OK || ret2 == GST_FLOW_OK)
1382 gst_validate_pad_monitor_check_aggregated_return (GstValidatePadMonitor *
1383 monitor, GstObject * parent, GstFlowReturn ret)
1389 GstState state, pending;
1390 GstValidatePadMonitor *othermonitor;
1391 GstFlowReturn aggregated = GST_FLOW_NOT_LINKED;
1392 gboolean found_a_pad = FALSE;
1394 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1397 iter = gst_pad_iterate_internal_links (pad);
1400 GValue value = { 0, };
1401 switch (gst_iterator_next (iter, &value)) {
1402 case GST_ITERATOR_OK:
1403 otherpad = g_value_get_object (&value);
1404 peerpad = gst_pad_get_peer (otherpad);
1406 othermonitor = _GET_PAD_MONITOR (peerpad);
1409 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1411 _combine_flows (aggregated, othermonitor->last_flow_return);
1412 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1415 gst_object_unref (peerpad);
1417 g_value_reset (&value);
1419 case GST_ITERATOR_RESYNC:
1420 gst_iterator_resync (iter);
1422 case GST_ITERATOR_ERROR:
1423 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1426 case GST_ITERATOR_DONE:
1431 gst_iterator_free (iter);
1433 /* no peer pad found, nothing to do */
1437 if (aggregated == GST_FLOW_FLUSHING) {
1438 gst_element_get_state (GST_ELEMENT (parent), &state, &pending, 0);
1439 if (state < GST_STATE_PAUSED || pending < GST_STATE_PAUSED) {
1440 /* Aggregated is flushing, we might have been aggregating a combination
1441 * of pads that are not what was present on the element during the actual
1442 * data flow combination (pads might have been removed meanwhile) */
1446 } else if (aggregated == GST_FLOW_OK || aggregated == GST_FLOW_EOS) {
1448 /* those are acceptable situations */
1449 if (GST_PAD_IS_FLUSHING (pad) && ret == GST_FLOW_FLUSHING) {
1450 /* pad is flushing, always acceptable to return flushing */
1454 gst_element_get_state (GST_ELEMENT (parent), &state, &pending, 0);
1455 if (ret == GST_FLOW_FLUSHING && (state < GST_STATE_PAUSED
1456 || pending < GST_STATE_PAUSED)) {
1457 /* Element is being teared down, accept FLOW_FLUSHING */
1462 if (monitor->is_eos && ret == GST_FLOW_EOS) {
1463 /* this element received eos and returned eos */
1467 if (PAD_PARENT_IS_DEMUXER (monitor) && ret == GST_FLOW_EOS) {
1468 /* a demuxer can return EOS when the samples end */
1473 if (aggregated != ret) {
1474 GST_VALIDATE_REPORT (monitor, WRONG_FLOW_RETURN,
1475 "Wrong combined flow return %s(%d). Expected: %s(%d)",
1476 gst_flow_get_name (ret), ret, gst_flow_get_name (aggregated),
1481 gst_object_unref (pad);
1485 gst_validate_pad_monitor_otherpad_add_pending_serialized_event
1486 (GstValidatePadMonitor * monitor, GstEvent * event, GstClockTime last_ts)
1491 GstValidatePadMonitor *othermonitor;
1495 if (!GST_EVENT_IS_SERIALIZED (event))
1499 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1501 iter = gst_pad_iterate_internal_links (pad);
1503 /* inputselector will return NULL if the sinkpad is not the active one .... */
1504 GST_FIXME_OBJECT (pad, "No iterator");
1505 gst_object_unref (pad);
1511 GValue value = { 0, };
1512 switch (gst_iterator_next (iter, &value)) {
1513 case GST_ITERATOR_OK:
1514 otherpad = g_value_get_object (&value);
1515 othermonitor = _GET_PAD_MONITOR (otherpad);
1517 SerializedEventData *data = g_slice_new0 (SerializedEventData);
1518 data->timestamp = last_ts;
1519 data->event = gst_event_ref (event);
1520 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1521 GST_DEBUG_OBJECT (pad, "Storing for pad %s:%s event %p %s",
1522 GST_DEBUG_PAD_NAME (otherpad), event,
1523 GST_EVENT_TYPE_NAME (event));
1524 g_ptr_array_add (othermonitor->serialized_events, data);
1525 debug_pending_event (otherpad, othermonitor->serialized_events);
1526 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1528 g_value_reset (&value);
1530 case GST_ITERATOR_RESYNC:
1531 gst_iterator_resync (iter);
1533 case GST_ITERATOR_ERROR:
1534 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1537 case GST_ITERATOR_DONE:
1542 gst_iterator_free (iter);
1543 gst_object_unref (pad);
1547 gst_validate_pad_monitor_otherpad_add_pending_field (GstValidatePadMonitor *
1548 monitor, GstStructure * structure, const gchar * field)
1553 GstValidatePadMonitor *othermonitor;
1557 v = gst_structure_get_value (structure, field);
1559 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1563 GST_DEBUG_OBJECT (pad, "Not adding pending field %s as it isn't "
1564 "present on structure %" GST_PTR_FORMAT, field, structure);
1565 gst_object_unref (pad);
1569 iter = gst_pad_iterate_internal_links (pad);
1572 GValue value = { 0, };
1573 switch (gst_iterator_next (iter, &value)) {
1574 case GST_ITERATOR_OK:
1575 otherpad = g_value_get_object (&value);
1576 othermonitor = _GET_PAD_MONITOR (otherpad);
1578 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1579 g_assert (othermonitor->pending_setcaps_fields != NULL);
1580 gst_structure_set_value (othermonitor->pending_setcaps_fields,
1582 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1584 g_value_reset (&value);
1586 case GST_ITERATOR_RESYNC:
1587 gst_iterator_resync (iter);
1589 case GST_ITERATOR_ERROR:
1590 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1593 case GST_ITERATOR_DONE:
1598 gst_iterator_free (iter);
1599 gst_object_unref (pad);
1603 gst_validate_pad_monitor_otherpad_clear_pending_fields (GstValidatePadMonitor *
1609 GstValidatePadMonitor *othermonitor;
1612 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1615 iter = gst_pad_iterate_internal_links (pad);
1617 gst_object_unref (pad);
1618 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1625 GValue value = { 0, };
1626 switch (gst_iterator_next (iter, &value)) {
1627 case GST_ITERATOR_OK:
1628 otherpad = g_value_get_object (&value);
1629 othermonitor = _GET_PAD_MONITOR (otherpad);
1631 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1632 g_assert (othermonitor->pending_setcaps_fields != NULL);
1633 gst_structure_free (othermonitor->pending_setcaps_fields);
1634 othermonitor->pending_setcaps_fields =
1635 gst_structure_new_empty (PENDING_FIELDS);
1636 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1638 g_value_reset (&value);
1640 case GST_ITERATOR_RESYNC:
1641 gst_iterator_resync (iter);
1643 case GST_ITERATOR_ERROR:
1644 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1647 case GST_ITERATOR_DONE:
1652 gst_object_unref (pad);
1653 gst_iterator_free (iter);
1657 gst_validate_pad_monitor_add_expected_newsegment (GstValidatePadMonitor *
1658 monitor, GstEvent * event)
1663 GstValidatePadMonitor *othermonitor;
1665 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1668 iter = gst_pad_iterate_internal_links (pad);
1670 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1671 gst_object_unref (pad);
1677 GValue value = { 0, };
1678 switch (gst_iterator_next (iter, &value)) {
1679 case GST_ITERATOR_OK:
1680 otherpad = g_value_get_object (&value);
1682 g_value_reset (&value);
1686 othermonitor = _GET_PAD_MONITOR (otherpad);
1687 if (!othermonitor) {
1688 g_value_reset (&value);
1692 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1693 gst_event_replace (&othermonitor->expected_segment, event);
1694 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1695 g_value_reset (&value);
1697 case GST_ITERATOR_RESYNC:
1698 gst_iterator_resync (iter);
1700 case GST_ITERATOR_ERROR:
1701 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1704 case GST_ITERATOR_DONE:
1709 gst_iterator_free (iter);
1710 gst_object_unref (pad);
1713 /* common checks for both sink and src event functions */
1715 gst_validate_pad_monitor_common_event_check (GstValidatePadMonitor *
1716 pad_monitor, GstEvent * event)
1718 guint32 seqnum = gst_event_get_seqnum (event);
1720 if (seqnum == GST_SEQNUM_INVALID)
1721 GST_VALIDATE_REPORT (pad_monitor, EVENT_INVALID_SEQNUM,
1722 "Event %p (%s) has an invalid SEQNUM", event,
1723 GST_EVENT_TYPE_NAME (event));
1725 switch (GST_EVENT_TYPE (event)) {
1726 case GST_EVENT_FLUSH_START:
1728 if (pad_monitor->seeks) {
1729 GstValidatePadSeekData *seekdata =
1730 seek_data_for_seqnum (pad_monitor, seqnum);
1733 GST_VALIDATE_REPORT (pad_monitor, FLUSH_START_HAS_WRONG_SEQNUM,
1734 "Got: %" G_GUINT32_FORMAT " Expected: %" G_GUINT32_FORMAT, seqnum,
1735 ((GstValidatePadSeekData *) pad_monitor->seeks->data)->seqnum);
1737 if (!(seekdata->flags & GST_SEEK_FLAG_FLUSH)) {
1738 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1739 "Received flush-start for a non-flushing seek");
1744 if (pad_monitor->pending_flush_stop) {
1745 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1746 "Received flush-start from when flush-stop was expected");
1748 pad_monitor->pending_flush_stop = TRUE;
1749 /* Remove the current segment seekdata */
1750 if (pad_monitor->current_seek) {
1751 pad_monitor->seeks =
1752 g_list_remove (pad_monitor->seeks, pad_monitor->current_seek);
1753 seek_data_free (pad_monitor->current_seek);
1754 pad_monitor->current_seek = NULL;
1758 case GST_EVENT_FLUSH_STOP:
1760 if (pad_monitor->seeks && !seek_data_for_seqnum (pad_monitor, seqnum)) {
1761 GST_VALIDATE_REPORT (pad_monitor, FLUSH_STOP_HAS_WRONG_SEQNUM,
1762 "Got: %" G_GUINT32_FORMAT " Expected: %" G_GUINT32_FORMAT, seqnum,
1763 ((GstValidatePadSeekData *) pad_monitor->seeks->data)->seqnum);
1766 pad_monitor->pending_newsegment_seqnum = seqnum;
1767 pad_monitor->pending_eos_seqnum = seqnum;
1769 if (!pad_monitor->pending_flush_stop) {
1770 gchar *event_str = _get_event_string (event);
1772 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_STOP_UNEXPECTED,
1773 "Unexpected flush-stop %s", event_str);
1776 pad_monitor->pending_flush_stop = FALSE;
1778 /* Buffers following a FLUSH should have the DISCONT flag set */
1779 pad_monitor->pending_buffer_discont = TRUE;
1781 /* cleanup our data */
1782 gst_validate_pad_monitor_flush (pad_monitor);
1791 mark_pads_eos (GstValidatePadMonitor * pad_monitor)
1793 GstValidatePadMonitor *peer_monitor;
1796 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1798 GstPad *peer = gst_pad_get_peer (pad);
1800 gst_object_unref (pad);
1801 pad_monitor->is_eos = TRUE;
1803 real_peer = _get_actual_pad (peer);
1804 peer_monitor = _GET_PAD_MONITOR (real_peer);
1806 peer_monitor->is_eos = TRUE;
1807 gst_object_unref (peer);
1808 gst_object_unref (real_peer);
1812 static inline gboolean
1813 _should_check_buffers (GstValidatePadMonitor * pad_monitor,
1814 gboolean force_checks)
1817 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1819 GstValidateMonitor *monitor = GST_VALIDATE_MONITOR (pad_monitor);
1821 if (pad_monitor->first_buffer || force_checks) {
1822 if (pad_monitor->segment.rate != 1.0) {
1823 GST_INFO_OBJECT (pad_monitor, "We do not support buffer checking"
1824 " for trick modes");
1826 pad_monitor->check_buffers = FALSE;
1827 } else if (!PAD_PARENT_IS_DECODER (pad_monitor)) {
1828 GST_DEBUG_OBJECT (pad, "Not on a decoder => no buffer checking");
1830 pad_monitor->check_buffers = FALSE;
1831 } else if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK) {
1832 GST_DEBUG_OBJECT (pad, "Not a sinkpad => no buffer checking");
1834 pad_monitor->check_buffers = FALSE;
1835 } else if (!pad_monitor->caps_is_video) {
1836 GST_DEBUG_OBJECT (pad, "Not working with video => no buffer checking");
1838 pad_monitor->check_buffers = FALSE;
1839 } else if (monitor->media_descriptor == NULL) {
1840 GST_DEBUG_OBJECT (pad, "No media_descriptor set => no buffer checking");
1842 pad_monitor->check_buffers = FALSE;
1843 } else if (!gst_validate_media_descriptor_detects_frames
1844 (monitor->media_descriptor)) {
1845 GST_DEBUG_OBJECT (pad,
1846 "No frame detection media descriptor => no buffer checking");
1847 pad_monitor->check_buffers = FALSE;
1848 } else if (pad_monitor->all_bufs == NULL &&
1849 !gst_validate_media_descriptor_get_buffers (monitor->media_descriptor,
1850 pad, NULL, &pad_monitor->all_bufs)) {
1852 GST_INFO_OBJECT (monitor,
1853 "The MediaInfo is marked as detecting frame, but getting frames"
1854 " from pad %" GST_PTR_FORMAT " did not work (some format conversion"
1855 " might be happening)", pad);
1857 pad_monitor->check_buffers = FALSE;
1859 if (!pad_monitor->current_buf)
1860 pad_monitor->current_buf = pad_monitor->all_bufs;
1861 pad_monitor->check_buffers = TRUE;
1864 gst_object_unref (pad);
1866 return pad_monitor->check_buffers;
1870 gst_validate_monitor_find_next_buffer (GstValidatePadMonitor * pad_monitor)
1873 gboolean passed_start = FALSE;
1875 if (!_should_check_buffers (pad_monitor, TRUE))
1878 for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) {
1879 GstBuffer *cbuf = (GstBuffer *) tmp->data;
1881 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf)
1882 : GST_BUFFER_PTS (cbuf);
1884 if (!GST_CLOCK_TIME_IS_VALID (ts))
1887 if (ts <= pad_monitor->segment.start)
1888 passed_start = TRUE;
1893 if (!GST_BUFFER_FLAG_IS_SET (cbuf, GST_BUFFER_FLAG_DELTA_UNIT)) {
1899 pad_monitor->current_buf = pad_monitor->all_bufs;
1901 pad_monitor->current_buf = tmp;
1905 post_segment_message (GstValidatePadMonitor * pad_monitor, GstPad * pad,
1906 const GstSegment * segment, guint32 seqnum)
1908 GstValidateMonitor *element_monitor =
1909 GST_VALIDATE_MONITOR_GET_PARENT (pad_monitor);
1910 GstElement *element;
1911 GstStructure *structure;
1914 if (element_monitor == NULL)
1917 element = gst_validate_monitor_get_element (element_monitor);
1918 if (element == NULL)
1921 GST_DEBUG_OBJECT (pad,
1922 "Posting application message for seqnum:%" G_GUINT32_FORMAT " %"
1923 GST_SEGMENT_FORMAT, seqnum, segment);
1926 gst_structure_new ("validate-segment", "segment", GST_TYPE_SEGMENT,
1928 msg = gst_message_new_application ((GstObject *) element, structure);
1929 gst_message_set_seqnum (msg, seqnum);
1930 gst_element_post_message (element, msg);
1932 gst_object_unref (element);
1937 /* Checks whether a segment is just an update of another,
1938 * That is to say that only the base and offset field differ and all
1939 * other fields are identical */
1941 is_segment_update (GstSegment * a, const GstSegment * b)
1943 /* Note : We never care about the position field, it is only
1944 * used for internal usage by elements */
1945 if (a->rate == b->rate &&
1946 a->applied_rate == b->applied_rate &&
1947 a->format == b->format && a->time == b->time) {
1948 /* Changes in base/offset are considered updates */
1949 /* Updating the end position of a segment is an update */
1950 /* Updating the duration of a segment is an update */
1951 if (a->rate > 0.0) {
1952 if (a->start == b->start)
1955 if (a->stop == b->stop)
1962 static GstFlowReturn
1963 gst_validate_pad_monitor_downstream_event_check (GstValidatePadMonitor *
1964 pad_monitor, GstObject * parent, GstEvent * event,
1965 GstPadEventFunction handler)
1967 GstFlowReturn ret = GST_FLOW_OK;
1968 const GstSegment *segment;
1969 guint32 seqnum = gst_event_get_seqnum (event);
1971 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1974 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1977 switch (GST_EVENT_TYPE (event)) {
1978 case GST_EVENT_STREAM_START:
1979 /* Buffers following a STREAM_START should have the DISCONT flag set */
1980 pad_monitor->pending_buffer_discont = TRUE;
1982 case GST_EVENT_SEGMENT:
1984 GstValidatePadSeekData *seekdata =
1985 seek_data_for_seqnum (pad_monitor, seqnum);
1987 /* parse segment data to be used if event is handled */
1988 gst_event_parse_segment (event, &segment);
1990 GST_DEBUG_OBJECT (pad,
1991 "Got segment seqnum:%" G_GUINT32_FORMAT " %" GST_SEGMENT_FORMAT,
1994 if (pad_monitor->pending_newsegment_seqnum != GST_SEQNUM_INVALID) {
1995 /* FIXME: Convert to more robust checks */
1996 if (pad_monitor->pending_newsegment_seqnum != seqnum) {
1997 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_SEQNUM,
1998 "Got: %u Expected: %u", seqnum,
1999 pad_monitor->pending_newsegment_seqnum);
2003 if (seekdata && seekdata != pad_monitor->current_seek) {
2004 /* Check for accurate seeks */
2005 if (seekdata->flags & GST_SEEK_FLAG_ACCURATE) {
2006 if (segment->time != seekdata->start)
2007 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_START,
2008 "After an accurate seek, got: %" GST_TIME_FORMAT
2009 " Expected: %" GST_TIME_FORMAT, GST_TIME_ARGS (segment->time),
2010 GST_TIME_ARGS (seekdata->start));
2014 pad_monitor->pending_eos_seqnum = seqnum;
2016 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2017 gst_validate_pad_monitor_add_expected_newsegment (pad_monitor, event);
2019 /* check if this segment is the expected one */
2020 if (pad_monitor->expected_segment) {
2021 const GstSegment *exp_segment;
2023 if (pad_monitor->expected_segment != event) {
2024 gst_event_parse_segment (pad_monitor->expected_segment,
2026 if (segment->format == exp_segment->format) {
2027 if ((exp_segment->rate * exp_segment->applied_rate !=
2028 segment->rate * segment->applied_rate))
2029 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
2030 "Rate * applied_rate %f != expected %f",
2031 segment->rate * segment->applied_rate,
2032 exp_segment->rate * exp_segment->applied_rate);
2033 if (exp_segment->start != segment->start)
2034 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
2035 "Start %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
2036 GST_TIME_ARGS (segment->start),
2037 GST_TIME_ARGS (exp_segment->start));
2038 if (exp_segment->stop != segment->stop)
2039 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
2040 "Stop %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
2041 GST_TIME_ARGS (segment->stop),
2042 GST_TIME_ARGS (exp_segment->stop));
2043 if (exp_segment->position != segment->position)
2044 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
2045 "Position %" GST_TIME_FORMAT " != expected %"
2046 GST_TIME_FORMAT, GST_TIME_ARGS (segment->position),
2047 GST_TIME_ARGS (exp_segment->position));
2050 gst_event_replace (&pad_monitor->expected_segment, NULL);
2054 /* Drop all expected seekdata from before this segment */
2056 while (pad_monitor->seeks && pad_monitor->seeks->data != seekdata) {
2057 GstValidatePadSeekData *tmp =
2058 (GstValidatePadSeekData *) pad_monitor->seeks->data;
2059 pad_monitor->seeks =
2060 g_list_delete_link (pad_monitor->seeks, pad_monitor->seeks);
2061 seek_data_free (tmp);
2064 pad_monitor->current_seek = seekdata;
2067 case GST_EVENT_CAPS:{
2070 gst_event_parse_caps (event, &caps);
2071 gst_validate_pad_monitor_setcaps_pre (pad_monitor, caps);
2075 pad_monitor->is_eos = TRUE;
2076 /* FIXME : This feels and looks wrong ... */
2077 if (pad_monitor->pending_eos_seqnum == GST_SEQNUM_INVALID) {
2078 GST_VALIDATE_REPORT (pad_monitor, EVENT_EOS_WITHOUT_SEGMENT,
2079 "EOS %" GST_PTR_FORMAT " received before a segment was received",
2081 } else if (pad_monitor->pending_eos_seqnum != seqnum) {
2082 GST_VALIDATE_REPORT (pad_monitor, EOS_HAS_WRONG_SEQNUM,
2083 "Got: %u. Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
2087 * TODO add end of stream checks for
2088 * - events not pushed
2089 * - buffer data not pushed
2090 * - pending events not received
2094 /* both flushes are handled by the common event function */
2095 case GST_EVENT_FLUSH_START:
2096 case GST_EVENT_FLUSH_STOP:
2098 case GST_EVENT_SINK_MESSAGE:
2103 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2104 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2105 gst_validate_pad_monitor_event_overrides (pad_monitor, event);
2107 gst_event_ref (event);
2108 if (pad_monitor->event_full_func)
2109 ret = pad_monitor->event_full_func (pad, parent, event);
2110 else if (pad_monitor->event_func (pad, parent, event))
2113 ret = GST_FLOW_ERROR;
2115 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2116 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2119 switch (GST_EVENT_TYPE (event)) {
2120 case GST_EVENT_SEGMENT:
2121 if (ret == GST_FLOW_OK) {
2122 /* If the new segment is not an update of the previous one, then
2123 * the following buffer should have the DISCONT flag set */
2124 if (!is_segment_update (&pad_monitor->segment, segment))
2125 pad_monitor->pending_buffer_discont = TRUE;
2126 if (!pad_monitor->has_segment
2127 && pad_monitor->segment.format != segment->format) {
2128 gst_segment_init (&pad_monitor->segment, segment->format);
2130 gst_segment_copy_into (segment, &pad_monitor->segment);
2131 pad_monitor->has_segment = TRUE;
2132 gst_validate_monitor_find_next_buffer (pad_monitor);
2133 if (PAD_PARENT_IS_SINK (pad_monitor))
2134 post_segment_message (pad_monitor, pad, segment, seqnum);
2137 case GST_EVENT_CAPS:{
2140 gst_event_parse_caps (event, &caps);
2141 gst_validate_pad_monitor_setcaps_post (pad_monitor, caps,
2142 ret == GST_FLOW_OK);
2145 case GST_EVENT_FLUSH_START:
2146 case GST_EVENT_FLUSH_STOP:
2149 case GST_EVENT_SINK_MESSAGE:
2155 gst_event_unref (event);
2156 gst_object_unref (pad);
2160 static GstValidatePadSeekData *
2161 _store_seek_event_data (GstValidatePadMonitor * pad_monitor, GstEvent * event)
2163 GstValidatePadSeekData *data = g_slice_new0 (GstValidatePadSeekData);
2165 data->seqnum = gst_event_get_seqnum (event);
2166 gst_event_parse_seek (event, &data->rate, &data->format, &data->flags,
2167 &data->start_type, &data->start, &data->stop_type, &data->stop);
2169 pad_monitor->seeks = g_list_append (pad_monitor->seeks, data);
2175 gst_validate_pad_monitor_src_event_check (GstValidatePadMonitor * pad_monitor,
2176 GstObject * parent, GstEvent * event, GstPadEventFunction handler)
2178 gboolean ret = TRUE;
2180 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2183 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
2186 GstValidatePadSeekData *seekdata = NULL;
2188 GST_DEBUG_OBJECT (pad, "event %" GST_PTR_FORMAT, event);
2190 /* Safely store pending accurate seek values */
2191 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK)
2192 seekdata = _store_seek_event_data (pad_monitor, event);
2193 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2194 ret = pad_monitor->event_func (pad, parent, event);
2196 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2198 if (seekdata && !ret) {
2199 /* Remove failed seek from list */
2200 GST_LOG_OBJECT (pad, "Failed seek, removing stored seek data");
2201 pad_monitor->seeks = g_list_remove (pad_monitor->seeks, seekdata);
2202 g_slice_free (GstValidatePadSeekData, seekdata);
2206 gst_object_unref (pad);
2211 gst_validate_pad_monitor_check_right_buffer (GstValidatePadMonitor *
2212 pad_monitor, GstBuffer * buffer)
2215 GstBuffer *wanted_buf;
2216 GstMapInfo map, wanted_map;
2218 gboolean ret = TRUE;
2222 if (_should_check_buffers (pad_monitor, FALSE) == FALSE)
2226 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2228 if (pad_monitor->current_buf == NULL) {
2229 GST_INFO_OBJECT (pad, "No current buffer one pad, Why?");
2230 gst_object_unref (pad);
2234 wanted_buf = pad_monitor->current_buf->data;
2236 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (wanted_buf)) &&
2237 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buffer)) &&
2238 GST_BUFFER_PTS (wanted_buf) != GST_BUFFER_PTS (buffer)) {
2240 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2241 "buffer %" GST_PTR_FORMAT " PTS %" GST_TIME_FORMAT
2242 " different than expected: %" GST_TIME_FORMAT, buffer,
2243 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
2244 GST_TIME_ARGS (GST_BUFFER_PTS (wanted_buf)));
2249 if (GST_BUFFER_DTS (wanted_buf) != GST_BUFFER_DTS (buffer)) {
2250 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2251 "buffer %" GST_PTR_FORMAT " DTS %" GST_TIME_FORMAT
2252 " different than expected: %" GST_TIME_FORMAT, buffer,
2253 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
2254 GST_TIME_ARGS (GST_BUFFER_DTS (wanted_buf)));
2258 if (GST_BUFFER_DURATION (wanted_buf) != GST_BUFFER_DURATION (buffer)) {
2259 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2260 "buffer %" GST_PTR_FORMAT " DURATION %" GST_TIME_FORMAT
2261 " different than expected: %" GST_TIME_FORMAT, buffer,
2262 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2263 GST_TIME_ARGS (GST_BUFFER_DURATION (wanted_buf)));
2267 if (GST_BUFFER_FLAG_IS_SET (wanted_buf, GST_BUFFER_FLAG_DELTA_UNIT) !=
2268 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
2269 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2270 "buffer %" GST_PTR_FORMAT " Delta unit is set to %s but expected %s",
2271 buffer, GST_BUFFER_FLAG_IS_SET (buffer,
2272 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False",
2273 GST_BUFFER_FLAG_IS_SET (wanted_buf,
2274 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False");
2278 g_assert (gst_buffer_map (wanted_buf, &wanted_map, GST_MAP_READ));
2279 g_assert (gst_buffer_map (buffer, &map, GST_MAP_READ));
2281 checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
2282 (const guchar *) map.data, map.size);
2284 if (g_strcmp0 ((gchar *) wanted_map.data, checksum)) {
2285 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2286 "buffer %" GST_PTR_FORMAT " checksum %s different from expected: %s",
2287 buffer, checksum, wanted_map.data);
2291 gst_buffer_unmap (wanted_buf, &wanted_map);
2292 gst_buffer_unmap (buffer, &map);
2294 gst_object_unref (pad);
2296 pad_monitor->current_buf = pad_monitor->current_buf->next;
2302 gst_validate_pad_monitor_check_return (GstValidatePadMonitor * pad_monitor,
2305 GstValidateMonitor *parent = GST_VALIDATE_MONITOR (pad_monitor);
2307 if (ret != GST_FLOW_ERROR)
2310 while (GST_VALIDATE_MONITOR_GET_PARENT (parent))
2311 parent = GST_VALIDATE_MONITOR_GET_PARENT (parent);
2313 if (GST_IS_VALIDATE_PIPELINE_MONITOR (parent)) {
2314 GstValidatePipelineMonitor *m = GST_VALIDATE_PIPELINE_MONITOR (parent);
2316 GST_VALIDATE_MONITOR_LOCK (m);
2317 if (m->got_error == FALSE) {
2318 GST_VALIDATE_REPORT (pad_monitor, FLOW_ERROR_WITHOUT_ERROR_MESSAGE,
2319 "Pad return GST_FLOW_ERROR but no GST_MESSAGE_ERROR was received on"
2322 /* Only report it the first time */
2323 m->got_error = TRUE;
2325 GST_VALIDATE_MONITOR_UNLOCK (m);
2329 static GstFlowReturn
2330 gst_validate_pad_monitor_chain_func (GstPad * pad, GstObject * parent,
2333 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2336 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2337 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2339 gst_validate_pad_monitor_check_discont (pad_monitor, buffer);
2340 gst_validate_pad_monitor_check_right_buffer (pad_monitor, buffer);
2341 gst_validate_pad_monitor_check_first_buffer (pad_monitor, buffer);
2342 gst_validate_pad_monitor_update_buffer_data (pad_monitor, buffer);
2343 gst_validate_pad_monitor_check_eos (pad_monitor, buffer);
2345 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2346 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2348 gst_validate_pad_monitor_buffer_overrides (pad_monitor, buffer);
2350 ret = pad_monitor->chain_func (pad, parent, buffer);
2352 gst_validate_pad_monitor_check_return (pad_monitor, ret);
2354 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2355 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2357 pad_monitor->last_flow_return = ret;
2358 if (ret == GST_FLOW_EOS) {
2359 mark_pads_eos (pad_monitor);
2361 if (PAD_PARENT_IS_DEMUXER (pad_monitor))
2362 gst_validate_pad_monitor_check_aggregated_return (pad_monitor, parent, ret);
2364 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2365 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2371 gst_validate_pad_monitor_event_is_tracked (GstValidatePadMonitor * monitor,
2374 if (!GST_EVENT_IS_SERIALIZED (event)) {
2378 /* we don't track Tag events because they mutate too much and it is hard
2379 * to match a tag event pushed on a source pad with the one that was received
2381 * One idea would be to use seqnum, but it seems that it is undefined whether
2382 * seqnums should be maintained in tag events that are created from others
2383 * up to today. (2013-08-29)
2385 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
2391 static GstFlowReturn
2392 gst_validate_pad_monitor_sink_event_full_func (GstPad * pad, GstObject * parent,
2395 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2398 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2399 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2401 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
2403 if (gst_validate_pad_monitor_event_is_tracked (pad_monitor, event)) {
2404 GstClockTime last_ts = GST_CLOCK_TIME_NONE;
2405 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_timestamp)) {
2406 last_ts = pad_monitor->current_timestamp;
2407 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_duration)) {
2408 last_ts += pad_monitor->current_duration;
2411 gst_validate_pad_monitor_otherpad_add_pending_serialized_event (pad_monitor,
2416 gst_validate_pad_monitor_downstream_event_check (pad_monitor, parent,
2417 event, pad_monitor->event_func);
2419 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2420 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2425 gst_validate_pad_monitor_sink_event_func (GstPad * pad, GstObject * parent,
2428 if (gst_validate_pad_monitor_sink_event_full_func (pad, parent,
2429 event) == GST_FLOW_OK)
2435 gst_validate_pad_monitor_src_event_func (GstPad * pad, GstObject * parent,
2438 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2441 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2442 ret = gst_validate_pad_monitor_src_event_check (pad_monitor, parent, event,
2443 pad_monitor->event_func);
2444 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2449 gst_validate_pad_monitor_query_func (GstPad * pad, GstObject * parent,
2452 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2455 gst_validate_pad_monitor_query_overrides (pad_monitor, query);
2456 ret = pad_monitor->query_func (pad, parent, query);
2459 switch (GST_QUERY_TYPE (query)) {
2460 case GST_QUERY_ACCEPT_CAPS:
2464 gst_caps_replace (&pad_monitor->last_refused_caps, NULL);
2465 gst_query_parse_accept_caps_result (query, &result);
2467 GstCaps *refused_caps;
2469 gst_query_parse_accept_caps (query, &refused_caps);
2470 pad_monitor->last_refused_caps = gst_caps_copy (refused_caps);
2476 case GST_QUERY_CAPS:{
2480 /* We shouldn't need to lock the parent as this doesn't modify
2481 * other monitors, just does some peer_pad_caps */
2482 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2484 gst_query_parse_caps (query, &filter);
2485 gst_query_parse_caps_result (query, &res);
2487 gst_caps_replace (&pad_monitor->last_query_res, NULL);
2488 gst_caps_replace (&pad_monitor->last_query_filter, NULL);
2489 pad_monitor->last_query_res =
2490 res ? gst_caps_copy (res) : gst_caps_ref (GST_CAPS_NONE);
2491 pad_monitor->last_query_filter =
2492 filter ? gst_caps_copy (filter) : gst_caps_ref (GST_CAPS_NONE);
2494 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2495 gst_validate_pad_monitor_check_caps_fields_proxied (pad_monitor, res,
2498 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2510 gst_validate_pad_monitor_activatemode_func (GstPad * pad, GstObject * parent,
2511 GstPadMode mode, gboolean active)
2513 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2514 gboolean ret = TRUE;
2516 /* TODO add overrides for activate func */
2517 GST_DEBUG_OBJECT (pad, "active:%d", active);
2519 if (pad_monitor->activatemode_func)
2520 ret = pad_monitor->activatemode_func (pad, parent, mode, active);
2521 if (ret && active == FALSE) {
2522 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2523 gst_validate_pad_monitor_reset (pad_monitor);
2524 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2530 static GstFlowReturn
2531 gst_validate_pad_monitor_get_range_func (GstPad * pad, GstObject * parent,
2532 guint64 offset, guint length, GstBuffer ** buffer)
2534 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2536 if (pad_monitor->get_range_func) {
2537 GstPad *peer = gst_pad_get_peer (pad);
2538 GstTask *task = NULL;
2539 GThread *thread = NULL;
2542 GST_OBJECT_LOCK (peer);
2543 task = GST_PAD_TASK (peer);
2544 if (task && GST_TASK_STATE (task) == GST_TASK_STARTED) {
2545 GST_OBJECT_LOCK (task);
2546 /* Only doing pointer comparison, no need to hold a ref */
2547 thread = task->thread;
2548 GST_OBJECT_UNLOCK (task);
2550 GST_OBJECT_UNLOCK (peer);
2552 if (thread && thread != g_thread_self ()) {
2553 GST_VALIDATE_REPORT (pad_monitor, PULL_RANGE_FROM_WRONG_THREAD,
2554 "Pulling from wrong thread, expected pad thread: %p, got %p",
2555 task->thread, g_thread_self ());
2558 gst_object_unref (peer);
2561 return pad_monitor->get_range_func (pad, parent, offset, length, buffer);
2564 return GST_FLOW_NOT_SUPPORTED;
2568 /* The interval between two buffer frequency checks */
2569 #define BUF_FREQ_CHECK_INTERVAL (GST_SECOND)
2572 gst_validate_pad_monitor_check_buffer_freq (GstValidatePadMonitor * monitor,
2577 if (!GST_PAD_IS_SRC (pad))
2580 if (!monitor->min_buf_freq)
2583 ts = gst_util_get_timestamp ();
2584 monitor->buffers_pushed++;
2586 /* Same logic as in fpsdisplaysink to compute the buffer frequency */
2587 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID
2588 (monitor->min_buf_freq_first_buffer_ts))) {
2589 monitor->min_buf_freq_first_buffer_ts = ts;
2590 monitor->min_buf_freq_interval_ts = ts;
2594 if (GST_CLOCK_DIFF (monitor->min_buf_freq_interval_ts,
2595 ts) > BUF_FREQ_CHECK_INTERVAL) {
2599 time_diff = (gdouble) (ts - monitor->min_buf_freq_interval_ts) / GST_SECOND;
2601 (gdouble) (monitor->buffers_pushed -
2602 monitor->last_buffers_pushed) / time_diff;
2604 if (fps < monitor->min_buf_freq) {
2605 if (GST_CLOCK_TIME_IS_VALID (monitor->min_buf_freq_start) &&
2606 GST_CLOCK_DIFF (monitor->min_buf_freq_first_buffer_ts,
2607 ts) < monitor->min_buf_freq_start) {
2608 GST_DEBUG_OBJECT (pad,
2609 "buffer frequency is too low (%.2f) but ignore for now (buffer-frequency-start =%"
2610 GST_TIME_FORMAT ")", fps,
2611 GST_TIME_ARGS (monitor->min_buf_freq_start));
2613 GST_VALIDATE_REPORT (monitor, CONFIG_BUFFER_FREQUENCY_TOO_LOW,
2614 "Buffers are not pushed fast enough on this pad: %.2f/sec (minimum: %.2f)",
2615 fps, monitor->min_buf_freq);
2619 monitor->last_buffers_pushed = monitor->buffers_pushed;
2620 monitor->min_buf_freq_interval_ts = ts;
2625 gst_validate_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
2626 gpointer udata, gboolean pull_mode)
2628 GstValidatePadMonitor *monitor = udata;
2630 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2631 GST_VALIDATE_MONITOR_LOCK (monitor);
2634 gst_validate_pad_monitor_check_discont (monitor, buffer);
2635 gst_validate_pad_monitor_check_first_buffer (monitor, buffer);
2636 gst_validate_pad_monitor_update_buffer_data (monitor, buffer);
2637 gst_validate_pad_monitor_check_eos (monitor, buffer);
2639 if (PAD_PARENT_IS_DECODER (monitor) || PAD_PARENT_IS_ENCODER (monitor)) {
2640 GstClockTime tolerance = 0;
2642 if (monitor->caps_is_audio)
2643 tolerance = AUDIO_TIMESTAMP_TOLERANCE;
2645 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range (monitor,
2649 gst_validate_pad_monitor_check_late_serialized_events (monitor,
2650 GST_BUFFER_TIMESTAMP (buffer));
2652 /* a GstValidatePadMonitor parent must be a GstValidateElementMonitor */
2653 if (PAD_PARENT_IS_DECODER (monitor)) {
2655 /* should not push out of segment data */
2656 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
2657 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)) &&
2658 ((!gst_segment_clip (&monitor->segment, monitor->segment.format,
2659 GST_BUFFER_TIMESTAMP (buffer),
2660 GST_BUFFER_TIMESTAMP (buffer) +
2661 GST_BUFFER_DURATION (buffer), NULL, NULL)) ||
2662 /* In the case of raw data, buffers should be strictly contained inside the
2664 (monitor->caps_is_raw &&
2665 GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer) <
2666 monitor->segment.start))
2668 /* TODO is this a timestamp issue? */
2669 GST_VALIDATE_REPORT (monitor, BUFFER_IS_OUT_OF_SEGMENT,
2670 "buffer is out of segment and shouldn't be pushed. Timestamp: %"
2671 GST_TIME_FORMAT " - Duration: %" GST_TIME_FORMAT ". Range: %"
2672 GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
2673 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
2674 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2675 GST_TIME_ARGS (monitor->segment.start),
2676 GST_TIME_ARGS (monitor->segment.stop));
2680 gst_validate_pad_monitor_check_buffer_freq (monitor, pad);
2682 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2683 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2684 gst_validate_pad_monitor_buffer_probe_overrides (monitor, buffer);
2689 gst_validate_pad_monitor_event_probe (GstPad * pad, GstEvent * event,
2692 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (udata);
2693 guint32 seqnum = gst_event_get_seqnum (event);
2695 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2696 GST_VALIDATE_MONITOR_LOCK (monitor);
2698 GST_DEBUG_OBJECT (pad, "event %p %s seqnum:%" G_GUINT32_FORMAT, event,
2699 GST_EVENT_TYPE_NAME (event), seqnum);
2701 if (GST_EVENT_IS_SERIALIZED (event)) {
2704 /* Detect if events the element received are being forwarded in the same order
2706 * Several scenarios:
2707 * 1) The element pushes the event as-is
2708 * 2) The element consumes the event and does not forward it
2709 * 3) The element consumes the event and creates another one instead
2710 * 4) The element pushes other serialized event before pushing out the
2713 * For each pad we have two lists to track serialized events:
2714 * 1) We received on input and expect to see (serialized_events)
2715 * 2) We received on input but don't expect to see (expired_events)
2717 * To detect events that are pushed in a different order from the one they were
2718 * received in we check that:
2720 * For each event being outputted:
2721 * If it is in the expired_events list:
2723 * If it is in the serialized_events list:
2724 * If there are other events that were received before:
2725 * Put those events on the expired_events list
2726 * Remove that event and any previous ones from the serialized_events list
2728 * Clear expired events list when flushing or on pad deactivation
2732 if (g_list_find (monitor->expired_events, event)) {
2733 gchar *event_str = _get_event_string (event);
2734 /* If it's the expired events, we've failed */
2735 GST_WARNING_OBJECT (pad, "Did not expect event %p %s", event,
2736 GST_EVENT_TYPE_NAME (event));
2737 GST_VALIDATE_REPORT (monitor, EVENT_SERIALIZED_OUT_OF_ORDER,
2738 "Serialized event was pushed out of order: %s", event_str);
2741 monitor->expired_events = g_list_remove (monitor->expired_events, event);
2742 gst_event_unref (event); /* remove the ref that was on the list */
2743 } else if (monitor->serialized_events->len) {
2744 for (i = 0; i < monitor->serialized_events->len; i++) {
2745 SerializedEventData *next_event =
2746 g_ptr_array_index (monitor->serialized_events, i);
2747 GST_DEBUG_OBJECT (pad, "Checking against stored event #%d: %p %s", i,
2748 next_event->event, GST_EVENT_TYPE_NAME (next_event->event));
2750 if (event == next_event->event
2751 || GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2752 /* We have found our event */
2753 GST_DEBUG_OBJECT (pad, "Found matching event");
2755 while (monitor->serialized_events->len > i
2756 && GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2757 /* Swallow all expected events of the same type */
2758 g_ptr_array_remove_index (monitor->serialized_events, i);
2759 next_event = g_ptr_array_index (monitor->serialized_events, i);
2762 /* Move all previous events to expired events */
2763 if (G_UNLIKELY (i > 0)) {
2764 GST_DEBUG_OBJECT (pad,
2765 "Moving previous expected events to expired list");
2767 next_event = g_ptr_array_index (monitor->serialized_events, 0);
2768 monitor->expired_events =
2769 g_list_append (monitor->expired_events,
2770 gst_event_ref (next_event->event));
2771 g_ptr_array_remove_index (monitor->serialized_events, 0);
2774 debug_pending_event (pad, monitor->serialized_events);
2781 /* This so far is just like an event that is flowing downstream,
2782 * so we do the same checks as a sinkpad event handler */
2783 gst_validate_pad_monitor_downstream_event_check (monitor, NULL, event, NULL);
2784 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2785 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2788 static GstPadProbeReturn
2789 gst_validate_pad_monitor_pad_probe (GstPad * pad, GstPadProbeInfo * info,
2792 if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
2793 gst_validate_pad_monitor_buffer_probe (pad, info->data, udata,
2794 GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_PULL);
2795 else if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
2796 gst_validate_pad_monitor_event_probe (pad, info->data, udata);
2798 return GST_PAD_PROBE_OK;
2802 gst_validate_pad_monitor_update_caps_info (GstValidatePadMonitor * pad_monitor,
2805 GstStructure *structure;
2807 g_return_if_fail (gst_caps_is_fixed (caps));
2809 pad_monitor->caps_is_audio = FALSE;
2810 pad_monitor->caps_is_video = FALSE;
2812 structure = gst_caps_get_structure (caps, 0);
2813 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/")) {
2814 pad_monitor->caps_is_audio = TRUE;
2815 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/")) {
2816 pad_monitor->caps_is_video = TRUE;
2819 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/x-raw") ||
2820 g_str_has_prefix (gst_structure_get_name (structure), "video/x-raw")) {
2821 pad_monitor->caps_is_raw = TRUE;
2823 pad_monitor->caps_is_raw = FALSE;
2828 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
2831 GstStructure *structure;
2833 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2836 /* Check if caps are identical to last caps and complain if so
2837 * Only checked for sink pads as src pads might push the same caps
2838 * multiple times during unlinked/autoplugging scenarios */
2839 if (GST_PAD_IS_SINK (pad) && pad_monitor->last_caps
2840 && gst_caps_is_equal (caps, pad_monitor->last_caps)) {
2841 gchar *caps_str = gst_caps_to_string (caps);
2843 GST_VALIDATE_REPORT (pad_monitor, EVENT_CAPS_DUPLICATE, "%s", caps_str);
2848 gst_validate_pad_monitor_check_caps_complete (pad_monitor, caps);
2851 structure = gst_caps_get_structure (caps, 0);
2852 if (gst_structure_n_fields (pad_monitor->pending_setcaps_fields)) {
2855 i < gst_structure_n_fields (pad_monitor->pending_setcaps_fields);
2858 gst_structure_nth_field_name (pad_monitor->pending_setcaps_fields,
2860 const GValue *v = gst_structure_get_value (structure, name);
2861 const GValue *otherv =
2862 gst_structure_get_value (pad_monitor->pending_setcaps_fields, name);
2865 gchar *caps_str = gst_caps_to_string (caps);
2867 GST_VALIDATE_REPORT (pad_monitor, CAPS_EXPECTED_FIELD_NOT_FOUND,
2868 "Field %s is missing from setcaps caps '%s'", name, caps_str);
2870 } else if (gst_value_compare (v, otherv) != GST_VALUE_EQUAL) {
2871 gchar *caps_str = gst_caps_to_string (caps),
2872 *pending_setcaps_fields_str =
2873 gst_structure_to_string (pad_monitor->pending_setcaps_fields);
2876 GST_VALIDATE_REPORT (pad_monitor, CAPS_FIELD_UNEXPECTED_VALUE,
2877 "Field %s from setcaps caps '%s' is different "
2878 "from expected value in caps '%s'", name, caps_str,
2879 pending_setcaps_fields_str);
2881 g_free (pending_setcaps_fields_str);
2887 if (GST_PAD_IS_SINK (pad) &&
2888 gst_validate_pad_monitor_pad_should_proxy_othercaps (pad_monitor)) {
2889 if (_structure_is_video (structure)) {
2890 GST_DEBUG_OBJECT (pad,
2891 "Adding video common pending fields to other pad: %" GST_PTR_FORMAT,
2893 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2894 structure, "width");
2895 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2896 structure, "height");
2897 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2898 structure, "framerate");
2899 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2900 structure, "pixel-aspect-ratio");
2901 } else if (_structure_is_audio (structure)) {
2902 GST_DEBUG_OBJECT (pad,
2903 "Adding audio common pending fields to other pad: %" GST_PTR_FORMAT,
2905 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2907 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2908 structure, "channels");
2913 gst_structure_free (pad_monitor->pending_setcaps_fields);
2914 pad_monitor->pending_setcaps_fields =
2915 gst_structure_new_empty (PENDING_FIELDS);
2916 gst_object_unref (pad);
2918 gst_validate_pad_monitor_setcaps_overrides (pad_monitor, caps);
2922 gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor * pad_monitor,
2923 GstCaps * caps, gboolean ret)
2926 gst_validate_pad_monitor_otherpad_clear_pending_fields (pad_monitor);
2928 if (pad_monitor->last_caps) {
2929 gst_caps_unref (pad_monitor->last_caps);
2931 pad_monitor->last_caps = gst_caps_ref (caps);
2932 gst_validate_pad_monitor_update_caps_info (pad_monitor, caps);
2937 gst_validate_pad_monitor_get_min_buffer_frequency (GstValidatePadMonitor *
2938 monitor, GstPad * pad)
2942 if (!GST_PAD_IS_SRC (pad))
2945 config = gst_validate_plugin_get_config (NULL);
2946 for (l = config; l != NULL; l = g_list_next (l)) {
2947 GstStructure *s = l->data;
2948 gdouble min_buf_freq;
2949 const gchar *pad_name;
2950 GstElement *element = NULL;
2952 if (!gst_structure_get_double (s, "min-buffer-frequency", &min_buf_freq)) {
2955 if (!gst_structure_get_int (s, "min-buffer-frequency", &max_int))
2958 min_buf_freq = max_int;
2961 pad_name = gst_structure_get_string (s, "name");
2965 if (g_strcmp0 (GST_PAD_NAME (pad), pad_name))
2968 element = gst_pad_get_parent_element (pad);
2970 if (!gst_validate_element_matches_target (element, s))
2973 monitor->min_buf_freq = min_buf_freq;
2975 gst_validate_utils_get_clocktime (s, "buffer-frequency-start",
2976 &monitor->min_buf_freq_start);
2978 GST_DEBUG_OBJECT (pad, "pad has a minimum buffer frequency of %f",
2981 g_clear_object (&element);
2986 gst_validate_pad_monitor_do_setup (GstValidateMonitor * monitor)
2988 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR_CAST (monitor);
2989 GstPad *pad = (gpointer) gst_validate_monitor_get_target (monitor);
2991 if (!GST_IS_PAD (pad)) {
2992 GST_WARNING_OBJECT (monitor, "Trying to create pad monitor with other "
2994 gst_object_unref (pad);
2998 if (_GET_PAD_MONITOR (pad)) {
2999 GST_WARNING_OBJECT (pad_monitor,
3000 "Pad already has a validate-monitor associated");
3001 gst_object_unref (pad);
3005 _SET_PAD_MONITOR (pad, pad_monitor);
3007 pad_monitor->event_func = GST_PAD_EVENTFUNC (pad);
3008 pad_monitor->event_full_func = GST_PAD_EVENTFULLFUNC (pad);
3009 pad_monitor->query_func = GST_PAD_QUERYFUNC (pad);
3010 pad_monitor->activatemode_func = GST_PAD_ACTIVATEMODEFUNC (pad);
3011 pad_monitor->get_range_func = GST_PAD_GETRANGEFUNC (pad);
3012 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
3014 pad_monitor->chain_func = GST_PAD_CHAINFUNC (pad);
3015 if (pad_monitor->chain_func)
3016 gst_pad_set_chain_function (pad, gst_validate_pad_monitor_chain_func);
3018 if (pad_monitor->event_full_func)
3019 gst_pad_set_event_full_function (pad,
3020 gst_validate_pad_monitor_sink_event_full_func);
3022 gst_pad_set_event_function (pad,
3023 gst_validate_pad_monitor_sink_event_func);
3025 gst_pad_set_event_function (pad, gst_validate_pad_monitor_src_event_func);
3027 /* add buffer/event probes */
3028 pad_monitor->pad_probe_id =
3029 gst_pad_add_probe (pad,
3030 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
3031 GST_PAD_PROBE_TYPE_EVENT_FLUSH,
3032 (GstPadProbeCallback) gst_validate_pad_monitor_pad_probe, pad_monitor,
3035 gst_pad_set_query_function (pad, gst_validate_pad_monitor_query_func);
3036 gst_pad_set_activatemode_function (pad,
3037 gst_validate_pad_monitor_activatemode_func);
3039 if (GST_PAD_IS_SRC (pad)) {
3040 gst_pad_set_getrange_function (pad,
3041 gst_validate_pad_monitor_get_range_func);
3044 gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (monitor),
3045 g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad)));
3047 if (G_UNLIKELY (GST_PAD_PARENT (pad) == NULL))
3048 GST_FIXME ("Saw a pad not belonging to any object");
3050 gst_validate_pad_monitor_get_min_buffer_frequency (pad_monitor, pad);
3052 gst_object_unref (pad);