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)) : \
87 * Locking the parent should always be done before locking the
88 * pad-monitor to prevent deadlocks in case another monitor from
89 * another pad on the same element starts an operation that also
90 * requires locking itself and some other monitors from internally
94 * An element has a sink and a src pad. Some test starts running at sinkpad
95 * and it locks the parent, and then it locks itself. In case it needs to get
96 * some information from the srcpad, it is able to lock the srcpad and get it
97 * because the srcpad should never lock itself before locking the parent (which
98 * it won't be able as sinkpad already locked it).
100 * As a side one, it is possible that srcpad locks itself without locking the
101 * parent in case it wants to do a check that won't need to use other internally
102 * linked pads (sinkpad). But in this case it might lock and unlock freely without
105 #define GST_VALIDATE_PAD_MONITOR_PARENT_LOCK(m) \
107 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
108 GST_VALIDATE_MONITOR_LOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
110 GST_WARNING_OBJECT (m, "No parent found, can't lock"); \
114 #define GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK(m) \
116 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
117 GST_VALIDATE_MONITOR_UNLOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
119 GST_WARNING_OBJECT (m, "No parent found, can't unlock"); \
125 GstClockTime timestamp;
127 } SerializedEventData;
130 _get_actual_pad (GstPad * pad)
134 gst_object_ref (pad);
136 /* We don't monitor ghost pads */
137 while (GST_IS_GHOST_PAD (pad)) {
139 pad = gst_ghost_pad_get_target ((GstGhostPad *) pad);
140 gst_object_unref (tmp_pad);
143 while (GST_IS_PROXY_PAD (pad)) {
145 pad = gst_pad_get_peer (pad);
146 gst_object_unref (tmp_pad);
153 _find_master_report_on_pad (GstPad * pad, GstValidateReport * report)
155 GstValidatePadMonitor *pad_monitor;
156 GstValidateReport *prev_report;
157 gboolean result = FALSE;
158 GstPad *tmppad = pad;
160 pad = _get_actual_pad (pad);
162 GST_ERROR_OBJECT (tmppad, "Does not have a target yet");
167 pad_monitor = _GET_PAD_MONITOR (pad);
169 /* For some reason this pad isn't monitored */
170 if (pad_monitor == NULL)
173 prev_report = gst_validate_reporter_get_report ((GstValidateReporter *)
174 pad_monitor, report->issue->issue_id);
177 if (prev_report->master_report)
178 result = gst_validate_report_set_master_report (report,
179 prev_report->master_report);
181 result = gst_validate_report_set_master_report (report, prev_report);
185 gst_object_unref (pad);
191 _find_master_report_for_sink_pad (GstValidatePadMonitor * pad_monitor,
192 GstValidateReport * report)
195 gboolean result = FALSE;
197 GST_PAD_CAST (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
200 peerpad = gst_pad_get_peer (pad);
201 gst_object_unref (pad);
203 /* If the peer src pad already has a similar report no need to look
205 if (peerpad && _find_master_report_on_pad (peerpad, report))
209 gst_object_unref (peerpad);
215 _find_master_report_for_src_pad (GstValidatePadMonitor * pad_monitor,
216 GstValidateReport * report)
220 gboolean result = FALSE;
222 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
225 iter = gst_pad_iterate_internal_links (target);
228 GValue value = { 0, };
229 switch (gst_iterator_next (iter, &value)) {
230 case GST_ITERATOR_OK:
232 GstPad *pad = g_value_get_object (&value);
234 if (_find_master_report_on_pad (pad, report)) {
239 g_value_reset (&value);
242 case GST_ITERATOR_RESYNC:
243 gst_iterator_resync (iter);
245 case GST_ITERATOR_ERROR:
246 GST_WARNING_OBJECT (target, "Internal links pad iteration error");
249 case GST_ITERATOR_DONE:
254 gst_object_unref (target);
255 gst_iterator_free (iter);
260 static GstValidateInterceptionReturn
261 _concatenate_issues (GstValidatePadMonitor * pad_monitor,
262 GstValidateReport * report)
265 GST_PAD_CAST (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
268 if (GST_PAD_IS_SINK (pad)
269 && _find_master_report_for_sink_pad (pad_monitor, report)) {
270 gst_object_unref (pad);
271 return GST_VALIDATE_REPORTER_KEEP;
272 } else if (GST_PAD_IS_SRC (pad)
273 && _find_master_report_for_src_pad (pad_monitor, report)) {
274 gst_object_unref (pad);
275 return GST_VALIDATE_REPORTER_KEEP;
278 gst_object_unref (pad);
279 return GST_VALIDATE_REPORTER_REPORT;
282 static GstValidateInterceptionReturn
283 gst_validate_pad_monitor_intercept_report (GstValidateReporter *
284 reporter, GstValidateReport * report)
286 GstValidateReporterInterface *iface_class, *old_iface_class;
287 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR (reporter);
288 GstValidateReportingDetails monitor_reporting_level;
289 GstValidateInterceptionReturn ret;
291 monitor_reporting_level =
292 gst_validate_reporter_get_reporting_level (reporter);
295 G_TYPE_INSTANCE_GET_INTERFACE (reporter, GST_TYPE_VALIDATE_REPORTER,
296 GstValidateReporterInterface);
297 old_iface_class = g_type_interface_peek_parent (iface_class);
299 old_iface_class->intercept_report (reporter, report);
301 switch (monitor_reporting_level) {
302 case GST_VALIDATE_SHOW_NONE:
303 ret = GST_VALIDATE_REPORTER_DROP;
305 case GST_VALIDATE_SHOW_UNKNOWN:
306 ret = _concatenate_issues (pad_monitor, report);
309 ret = GST_VALIDATE_REPORTER_REPORT;
313 gst_validate_report_set_reporting_level (report, monitor_reporting_level);
318 debug_pending_event (GstPad * pad, GPtrArray * array)
323 for (i = 0; i < len; i++) {
324 SerializedEventData *data = g_ptr_array_index (array, i);
325 GST_DEBUG_OBJECT (pad, "event #%d %" GST_TIME_FORMAT " %s %p",
326 i, GST_TIME_ARGS (data->timestamp),
327 GST_EVENT_TYPE_NAME (data->event), data->event);
332 _serialized_event_data_free (SerializedEventData * serialized_event)
334 gst_event_unref (serialized_event->event);
335 g_slice_free (SerializedEventData, serialized_event);
338 static gboolean gst_validate_pad_monitor_do_setup (GstValidateMonitor *
340 static GstElement *gst_validate_pad_monitor_get_element (GstValidateMonitor *
343 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
345 static void gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor *
346 pad_monitor, GstCaps * caps, gboolean ret);
348 #define PAD_IS_IN_PUSH_MODE(p) ((p)->mode == GST_PAD_MODE_PUSH)
351 _structure_is_raw_video (GstStructure * structure)
353 return gst_structure_has_name (structure, "video/x-raw");
357 _structure_is_raw_audio (GstStructure * structure)
359 return gst_structure_has_name (structure, "audio/x-raw");
363 _get_event_string (GstEvent * event)
365 const GstStructure *st;
367 if ((st = gst_event_get_structure (event)))
368 return gst_structure_to_string (st);
370 return g_strdup_printf ("%s", GST_EVENT_TYPE_NAME (event));
374 _check_field_type (GstValidatePadMonitor * monitor,
375 GstStructure * structure, gboolean mandatory, const gchar * field, ...)
379 gchar *joined_types = NULL;
380 const gchar *rejected_types[5];
381 gint rejected_types_index = 0;
384 if (!gst_structure_has_field (structure, field)) {
386 gchar *str = gst_structure_to_string (structure);
388 GST_VALIDATE_REPORT (monitor, CAPS_IS_MISSING_FIELD,
389 "Field '%s' is missing from structure: %s", field, str);
392 GST_DEBUG_OBJECT (monitor, "Field %s is missing but is not mandatory",
398 memset ((gchar **) rejected_types, 0, sizeof (rejected_types));
399 va_start (var_args, field);
400 while ((type = va_arg (var_args, GType)) != 0) {
401 if (gst_structure_has_field_typed (structure, field, type)) {
405 rejected_types[rejected_types_index++] = g_type_name (type);
409 joined_types = g_strjoinv (" / ", (gchar **) rejected_types);
410 struct_str = gst_structure_to_string (structure);
411 GST_VALIDATE_REPORT (monitor, CAPS_FIELD_HAS_BAD_TYPE,
412 "Field '%s' has wrong type %s in structure '%s'. Expected: %s", field,
413 g_type_name (gst_structure_get_field_type (structure, field)), struct_str,
415 g_free (joined_types);
420 gst_validate_pad_monitor_check_raw_video_caps_complete (GstValidatePadMonitor *
421 monitor, GstStructure * structure)
423 _check_field_type (monitor, structure, TRUE, "width", G_TYPE_INT,
424 GST_TYPE_INT_RANGE, 0);
425 _check_field_type (monitor, structure, TRUE, "height", G_TYPE_INT,
426 GST_TYPE_INT_RANGE, 0);
427 _check_field_type (monitor, structure, TRUE, "framerate", GST_TYPE_FRACTION,
428 GST_TYPE_FRACTION_RANGE, 0);
429 _check_field_type (monitor, structure, FALSE, "pixel-aspect-ratio",
430 GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, 0);
431 _check_field_type (monitor, structure, TRUE, "format", G_TYPE_STRING,
436 gst_validate_pad_monitor_check_raw_audio_caps_complete (GstValidatePadMonitor *
437 monitor, GstStructure * structure)
440 _check_field_type (monitor, structure, TRUE, "format", G_TYPE_STRING,
442 _check_field_type (monitor, structure, TRUE, "layout", G_TYPE_STRING,
444 _check_field_type (monitor, structure, TRUE, "rate", G_TYPE_INT,
445 GST_TYPE_LIST, GST_TYPE_INT_RANGE, 0);
446 _check_field_type (monitor, structure, TRUE, "channels", G_TYPE_INT,
447 GST_TYPE_LIST, GST_TYPE_INT_RANGE, 0);
448 if (gst_structure_get_int (structure, "channels", &channels)) {
450 _check_field_type (monitor, structure, TRUE, "channel-mask",
451 GST_TYPE_BITMASK, GST_TYPE_LIST, 0);
456 gst_validate_pad_monitor_check_caps_complete (GstValidatePadMonitor * monitor,
459 GstStructure *structure;
462 GST_DEBUG_OBJECT (monitor, "Checking caps %" GST_PTR_FORMAT, caps);
464 for (i = 0; i < gst_caps_get_size (caps); i++) {
465 structure = gst_caps_get_structure (caps, i);
467 if (_structure_is_raw_video (structure)) {
468 gst_validate_pad_monitor_check_raw_video_caps_complete (monitor,
471 } else if (_structure_is_raw_audio (structure)) {
472 gst_validate_pad_monitor_check_raw_audio_caps_complete (monitor,
479 gst_validate_pad_monitor_get_othercaps (GstValidatePadMonitor * monitor,
482 GstCaps *caps = gst_caps_new_empty ();
488 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
491 iter = gst_pad_iterate_internal_links (pad);
494 GValue value = { 0, };
495 switch (gst_iterator_next (iter, &value)) {
496 case GST_ITERATOR_OK:
497 otherpad = g_value_get_object (&value);
499 /* TODO What would be the correct caps operation to merge the caps in
500 * case one sink is internally linked to multiple srcs? */
501 peercaps = gst_pad_peer_query_caps (otherpad, filter);
503 caps = gst_caps_merge (caps, peercaps);
505 g_value_reset (&value);
507 case GST_ITERATOR_RESYNC:
508 gst_iterator_resync (iter);
509 gst_caps_unref (caps);
510 caps = gst_caps_new_empty ();
512 case GST_ITERATOR_ERROR:
513 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
516 case GST_ITERATOR_DONE:
521 GST_DEBUG_OBJECT (pad, "Otherpad caps: %" GST_PTR_FORMAT, caps);
523 gst_iterator_free (iter);
524 gst_object_unref (pad);
530 _structure_is_video (GstStructure * structure)
532 const gchar *name = gst_structure_get_name (structure);
534 return g_strstr_len (name, 6, "video/")
535 && g_strcmp0 (name, "video/quicktime") != 0;
539 _structure_is_audio (GstStructure * structure)
541 const gchar *name = gst_structure_get_name (structure);
543 return g_strstr_len (name, 6, "audio/") != NULL;
547 gst_validate_pad_monitor_pad_should_proxy_othercaps (GstValidatePadMonitor *
550 GstValidateMonitor *parent = GST_VALIDATE_MONITOR_GET_PARENT (monitor);
555 /* We only know how to handle othercaps checks for codecs so far */
556 return (GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER (parent) ||
557 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER (parent)) &&
558 !GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_CONVERTER (parent);
562 /* Check if the field @f from @s2 (if present) is represented in @s1
563 * Represented here means either equal or @s1's value is in a list/range
567 _structures_field_is_contained (GstStructure * s1, GstStructure * s2,
568 gboolean mandatory, const gchar * f)
573 v2 = gst_structure_get_value (s2, f);
575 return TRUE; /* nothing to compare to */
577 v1 = gst_structure_get_value (s1, f);
581 if (!gst_value_is_fixed (v1))
584 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
587 if (GST_VALUE_HOLDS_LIST (v2)) {
589 for (i = 0; i < gst_value_list_get_size (v2); i++) {
590 const GValue *v2_subvalue = gst_value_list_get_value (v2, i);
591 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
596 if (GST_VALUE_HOLDS_ARRAY (v2)) {
598 for (i = 0; i < gst_value_array_get_size (v2); i++) {
599 const GValue *v2_subvalue = gst_value_array_get_value (v2, i);
600 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
605 if (GST_VALUE_HOLDS_INT_RANGE (v2)) {
608 min = gst_value_get_int_range_min (v2);
609 max = gst_value_get_int_range_max (v2);
611 if (G_VALUE_HOLDS_INT (v1)) {
612 gint v = g_value_get_int (v1);
614 return v >= min && v <= max;
616 /* TODO compare int ranges with int ranges
617 * or with lists if useful */
621 if (GST_VALUE_HOLDS_FRACTION_RANGE (v2)) {
622 const GValue *min, *max;
624 min = gst_value_get_fraction_range_min (v2);
625 max = gst_value_get_fraction_range_max (v2);
627 if (GST_VALUE_HOLDS_FRACTION (v1)) {
628 gint v_min = gst_value_compare (v1, min);
629 gint v_max = gst_value_compare (v1, max);
631 return (v_min == GST_VALUE_EQUAL || v_min == GST_VALUE_GREATER_THAN) &&
632 (v_max == GST_VALUE_EQUAL || v_max == GST_VALUE_LESS_THAN);
634 /* TODO compare fraction ranges with fraction ranges
635 * or with lists if useful */
643 _check_and_copy_structure_field (GstStructure * from, GstStructure * to,
646 if (gst_structure_has_field (from, name)) {
647 gst_structure_set_value (to, name, gst_structure_get_value (from, name));
652 gst_validate_pad_monitor_copy_caps_fields_into_caps (GstValidatePadMonitor *
653 monitor, GstCaps * from_caps, GstCaps * into_caps)
655 gint i, j, into_size, from_size;
656 GstStructure *structure;
657 GstCaps *res = gst_caps_new_empty ();
659 into_size = gst_caps_get_size (into_caps);
660 from_size = gst_caps_get_size (from_caps);
662 for (i = 0; i < into_size; i++) {
663 GstStructure *s = gst_caps_get_structure (into_caps, i);
665 for (j = 0; j < from_size; j++) {
666 GstStructure *new_structure = gst_structure_copy (s);
668 structure = gst_caps_get_structure (from_caps, j);
669 if (_structure_is_video (structure)) {
670 _check_and_copy_structure_field (structure, new_structure, "width");
671 _check_and_copy_structure_field (structure, new_structure, "height");
672 _check_and_copy_structure_field (structure, new_structure, "framerate");
673 _check_and_copy_structure_field (structure, new_structure,
674 "pixel-aspect-ratio");
675 } else if (_structure_is_audio (s)) {
676 _check_and_copy_structure_field (structure, new_structure, "rate");
677 _check_and_copy_structure_field (structure, new_structure, "channels");
680 gst_caps_append_structure (res, new_structure);
687 gst_validate_pad_monitor_transform_caps (GstValidatePadMonitor * monitor,
695 GstCaps *template_caps;
699 GST_DEBUG_OBJECT (monitor, "Transform caps %" GST_PTR_FORMAT, caps);
704 othercaps = gst_caps_new_empty ();
707 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
709 iter = gst_pad_iterate_internal_links (pad);
712 GValue value = { 0, };
713 switch (gst_iterator_next (iter, &value)) {
714 case GST_ITERATOR_OK:
715 otherpad = g_value_get_object (&value);
716 template_caps = gst_pad_get_pad_template_caps (otherpad);
719 gst_validate_pad_monitor_copy_caps_fields_into_caps (monitor, caps,
721 if (!gst_caps_is_empty (new_caps))
722 gst_caps_append (othercaps, new_caps);
724 gst_caps_unref (new_caps);
726 gst_caps_unref (template_caps);
727 g_value_reset (&value);
729 case GST_ITERATOR_RESYNC:
730 gst_iterator_resync (iter);
731 gst_caps_unref (othercaps);
732 othercaps = gst_caps_new_empty ();
734 case GST_ITERATOR_ERROR:
735 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
738 case GST_ITERATOR_DONE:
743 gst_iterator_free (iter);
745 GST_DEBUG_OBJECT (pad, "Transformed caps: %" GST_PTR_FORMAT, othercaps);
746 gst_object_unref (pad);
752 gst_validate_pad_monitor_check_caps_fields_proxied (GstValidatePadMonitor *
753 monitor, GstCaps * caps, GstCaps * filter)
755 GstStructure *structure;
756 GstStructure *otherstructure;
758 GstCaps *otherfilter;
761 if (!gst_validate_pad_monitor_pad_should_proxy_othercaps (monitor))
764 otherfilter = gst_validate_pad_monitor_transform_caps (monitor, filter);
765 othercaps = gst_validate_pad_monitor_get_othercaps (monitor, otherfilter);
767 gst_caps_unref (otherfilter);
769 for (i = 0; i < gst_caps_get_size (othercaps); i++) {
770 gboolean found = FALSE;
771 gboolean type_match = FALSE;
773 otherstructure = gst_caps_get_structure (othercaps, i);
775 /* look for a proxied version of 'otherstructure' */
776 if (_structure_is_video (otherstructure)) {
777 for (j = 0; j < gst_caps_get_size (caps); j++) {
778 structure = gst_caps_get_structure (caps, j);
779 if (_structure_is_video (structure)) {
781 if (_structures_field_is_contained (structure, otherstructure, TRUE,
783 && _structures_field_is_contained (structure, otherstructure,
785 && _structures_field_is_contained (structure, otherstructure,
787 && _structures_field_is_contained (structure, otherstructure,
788 FALSE, "pixel-aspect-ratio")) {
794 } else if (_structure_is_audio (otherstructure)) {
795 for (j = 0; j < gst_caps_get_size (caps); j++) {
796 structure = gst_caps_get_structure (caps, j);
797 if (_structure_is_audio (structure)) {
799 if (_structures_field_is_contained (structure, otherstructure, TRUE,
801 && _structures_field_is_contained (structure, otherstructure,
810 if (type_match && !found) {
811 gchar *otherstruct_str = gst_structure_to_string (otherstructure),
812 *caps_str = gst_caps_to_string (caps);
814 GST_VALIDATE_REPORT (monitor, GET_CAPS_NOT_PROXYING_FIELDS,
815 "Peer pad structure '%s' has no similar version "
816 "on pad's caps '%s'", otherstruct_str, caps_str);
818 g_free (otherstruct_str);
823 gst_caps_unref (othercaps);
827 gst_validate_pad_monitor_check_late_serialized_events (GstValidatePadMonitor *
828 monitor, GstClockTime ts)
833 if (!GST_CLOCK_TIME_IS_VALID (ts))
837 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
840 GST_DEBUG_OBJECT (pad, "Timestamp to check %" GST_TIME_FORMAT,
843 for (i = 0; i < monitor->serialized_events->len; i++) {
844 SerializedEventData *data =
845 g_ptr_array_index (monitor->serialized_events, i);
847 GST_DEBUG_OBJECT (pad, "Event #%d (%s) ts: %" GST_TIME_FORMAT,
848 i, GST_EVENT_TYPE_NAME (data->event), GST_TIME_ARGS (data->timestamp));
850 if (GST_CLOCK_TIME_IS_VALID (data->timestamp) && data->timestamp < ts) {
851 gchar *event_str = _get_event_string (data->event);
853 GST_VALIDATE_REPORT (monitor, SERIALIZED_EVENT_WASNT_PUSHED_IN_TIME,
854 "Serialized event %s wasn't pushed before expected timestamp %"
855 GST_TIME_FORMAT " on pad %s:%s", event_str,
856 GST_TIME_ARGS (data->timestamp), GST_DEBUG_PAD_NAME (pad));
860 /* events should be ordered by ts */
866 debug_pending_event (pad, monitor->serialized_events);
867 g_ptr_array_remove_range (monitor->serialized_events, 0, i);
870 gst_object_unref (pad);
874 gst_validate_pad_monitor_dispose (GObject * object)
876 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (object);
878 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
882 if (monitor->pad_probe_id)
883 gst_pad_remove_probe (pad, monitor->pad_probe_id);
884 gst_object_unref (pad);
887 if (monitor->expected_segment)
888 gst_event_unref (monitor->expected_segment);
890 gst_structure_free (monitor->pending_setcaps_fields);
891 g_ptr_array_unref (monitor->serialized_events);
892 g_list_free_full (monitor->expired_events, (GDestroyNotify) gst_event_unref);
893 g_list_free_full (monitor->all_bufs, (GDestroyNotify) gst_buffer_unref);
894 gst_caps_replace (&monitor->last_caps, NULL);
895 gst_caps_replace (&monitor->last_query_res, NULL);
896 gst_caps_replace (&monitor->last_query_filter, NULL);
898 G_OBJECT_CLASS (parent_class)->dispose (object);
902 gst_validate_pad_monitor_class_init (GstValidatePadMonitorClass * klass)
904 GObjectClass *gobject_class;
905 GstValidateMonitorClass *monitor_klass;
907 gobject_class = G_OBJECT_CLASS (klass);
908 monitor_klass = GST_VALIDATE_MONITOR_CLASS (klass);
910 gobject_class->dispose = gst_validate_pad_monitor_dispose;
912 monitor_klass->setup = gst_validate_pad_monitor_do_setup;
913 monitor_klass->get_element = gst_validate_pad_monitor_get_element;
916 /* Called when a pad is being flushed */
918 gst_validate_pad_monitor_flush (GstValidatePadMonitor * pad_monitor)
920 /* Note: Keep in the same order as in the GstValidatePadMonitor structure */
922 gst_caps_replace (&pad_monitor->last_caps, NULL);
923 pad_monitor->caps_is_audio = pad_monitor->caps_is_video =
924 pad_monitor->caps_is_raw = FALSE;
926 pad_monitor->first_buffer = TRUE;
928 pad_monitor->has_segment = FALSE;
929 pad_monitor->is_eos = FALSE;
931 pad_monitor->pending_buffer_discont = TRUE;
933 gst_event_replace (&pad_monitor->expected_segment, NULL);
934 if (pad_monitor->serialized_events->len)
935 g_ptr_array_remove_range (pad_monitor->serialized_events, 0,
936 pad_monitor->serialized_events->len);
937 g_list_free_full (pad_monitor->expired_events,
938 (GDestroyNotify) gst_event_unref);
939 pad_monitor->expired_events = NULL;
941 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
942 pad_monitor->current_timestamp = GST_CLOCK_TIME_NONE;
943 pad_monitor->current_duration = GST_CLOCK_TIME_NONE;
945 pad_monitor->last_flow_return = GST_FLOW_OK;
947 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
948 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
951 /* Called when the pad monitor is initialized or when
952 * the pad is deactivated */
954 gst_validate_pad_monitor_reset (GstValidatePadMonitor * pad_monitor)
956 gst_validate_pad_monitor_flush (pad_monitor);
958 /* Note : For the entries that haven't been resetted in _flush(), do
959 * it here and keep in the same order as the GstValidatePadMonitor
962 pad_monitor->pending_flush_stop = FALSE;
963 pad_monitor->pending_newsegment_seqnum = GST_SEQNUM_INVALID;
964 pad_monitor->pending_eos_seqnum = GST_SEQNUM_INVALID;
966 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
968 if (pad_monitor->pending_setcaps_fields)
969 gst_structure_free (pad_monitor->pending_setcaps_fields);
970 pad_monitor->pending_setcaps_fields =
971 gst_structure_new_empty (PENDING_FIELDS);
973 /* FIXME : Why BYTES and not UNDEFINED ? */
974 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
976 pad_monitor->min_buf_freq = 0;
977 pad_monitor->buffers_pushed = 0;
978 pad_monitor->last_buffers_pushed = 0;
979 pad_monitor->min_buf_freq_interval_ts = GST_CLOCK_TIME_NONE;
980 pad_monitor->min_buf_freq_first_buffer_ts = GST_CLOCK_TIME_NONE;
981 pad_monitor->min_buf_freq_start = GST_CLOCK_TIME_NONE;
985 gst_validate_pad_monitor_init (GstValidatePadMonitor * pad_monitor)
987 pad_monitor->serialized_events =
988 g_ptr_array_new_with_free_func ((GDestroyNotify)
989 _serialized_event_data_free);
991 gst_validate_pad_monitor_reset (pad_monitor);
995 * gst_validate_pad_monitor_new:
996 * @pad: (transfer none): a #GstPad to run Validate on
998 GstValidatePadMonitor *
999 gst_validate_pad_monitor_new (GstPad * pad, GstValidateRunner * runner,
1000 GstValidateElementMonitor * parent)
1002 GstValidatePadMonitor *monitor = g_object_new (GST_TYPE_VALIDATE_PAD_MONITOR,
1003 "object", pad, "validate-runner", runner, "validate-parent",
1006 gst_validate_monitor_get_target (GST_VALIDATE_MONITOR (monitor));
1008 if (target == NULL) {
1009 g_object_unref (monitor);
1013 gst_object_unref (target);
1018 gst_validate_pad_monitor_get_element (GstValidateMonitor * monitor)
1021 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1023 GstElement *parent = GST_ELEMENT (gst_pad_get_parent (pad));
1025 gst_object_unref (pad);
1031 gst_validate_pad_monitor_event_overrides (GstValidatePadMonitor * pad_monitor,
1036 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1037 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1038 iter = g_list_next (iter)) {
1039 GstValidateOverride *override = iter->data;
1041 gst_validate_override_event_handler (override,
1042 GST_VALIDATE_MONITOR_CAST (pad_monitor), event);
1044 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1048 gst_validate_pad_monitor_buffer_overrides (GstValidatePadMonitor * pad_monitor,
1053 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1054 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1055 iter = g_list_next (iter)) {
1056 GstValidateOverride *override = iter->data;
1058 gst_validate_override_buffer_handler (override,
1059 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
1061 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1065 gst_validate_pad_monitor_buffer_probe_overrides (GstValidatePadMonitor *
1066 pad_monitor, GstBuffer * buffer)
1070 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1071 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1072 iter = g_list_next (iter)) {
1073 GstValidateOverride *override = iter->data;
1075 gst_validate_override_buffer_probe_handler (override,
1076 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
1078 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1082 gst_validate_pad_monitor_query_overrides (GstValidatePadMonitor * pad_monitor,
1087 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1088 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1089 iter = g_list_next (iter)) {
1090 GstValidateOverride *override = iter->data;
1092 gst_validate_override_query_handler (override,
1093 GST_VALIDATE_MONITOR_CAST (pad_monitor), query);
1095 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1099 gst_validate_pad_monitor_setcaps_overrides (GstValidatePadMonitor * pad_monitor,
1104 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1105 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1106 iter = g_list_next (iter)) {
1107 GstValidateOverride *override = iter->data;
1109 gst_validate_override_setcaps_handler (override,
1110 GST_VALIDATE_MONITOR_CAST (pad_monitor), caps);
1112 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1115 /* FIXME : This is a bit dubious, what's the point of this check ? */
1117 gst_validate_pad_monitor_timestamp_is_in_received_range (GstValidatePadMonitor *
1118 monitor, GstClockTime ts, GstClockTime tolerance)
1121 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1124 GST_DEBUG_OBJECT (pad,
1125 "Checking if timestamp %" GST_TIME_FORMAT " is in range: %"
1126 GST_TIME_FORMAT " - %" GST_TIME_FORMAT " for pad "
1127 "%s:%s with tolerance: %" GST_TIME_FORMAT, GST_TIME_ARGS (ts),
1128 GST_TIME_ARGS (monitor->timestamp_range_start),
1129 GST_TIME_ARGS (monitor->timestamp_range_end), GST_DEBUG_PAD_NAME (pad),
1130 GST_TIME_ARGS (tolerance));
1131 gst_object_unref (pad);
1133 return !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_start) ||
1134 !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_end) ||
1135 ((monitor->timestamp_range_start >= tolerance ?
1136 monitor->timestamp_range_start - tolerance : 0) <= ts
1137 && (ts >= tolerance ? ts - tolerance : 0) <=
1138 monitor->timestamp_range_end);
1141 /* Iterates over internal links (sinkpads) to check that this buffer has
1142 * a timestamp that is in the range of the lastly received buffers */
1144 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range
1145 (GstValidatePadMonitor * monitor, GstBuffer * buffer,
1146 GstClockTime tolerance)
1149 GstClockTime ts_end;
1151 gboolean has_one = FALSE;
1152 gboolean found = FALSE;
1155 GstValidatePadMonitor *othermonitor;
1157 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1160 if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))
1161 || !GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
1162 GST_DEBUG_OBJECT (pad,
1163 "Can't check buffer timestamps range as "
1164 "buffer has no valid timestamp/duration");
1168 ts = GST_BUFFER_TIMESTAMP (buffer);
1169 ts_end = ts + GST_BUFFER_DURATION (buffer);
1171 iter = gst_pad_iterate_internal_links (pad);
1174 GST_WARNING_OBJECT (pad, "No iterator available");
1180 GValue value = { 0, };
1181 switch (gst_iterator_next (iter, &value)) {
1182 case GST_ITERATOR_OK:
1183 otherpad = g_value_get_object (&value);
1184 GST_DEBUG_OBJECT (pad, "Checking pad %s:%s input timestamps",
1185 GST_DEBUG_PAD_NAME (otherpad));
1186 othermonitor = _GET_PAD_MONITOR (otherpad);
1187 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1188 if (gst_validate_pad_monitor_timestamp_is_in_received_range
1189 (othermonitor, ts, tolerance)
1191 gst_validate_pad_monitor_timestamp_is_in_received_range
1192 (othermonitor, ts_end, tolerance)) {
1196 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1197 g_value_reset (&value);
1200 case GST_ITERATOR_RESYNC:
1201 gst_iterator_resync (iter);
1205 case GST_ITERATOR_ERROR:
1206 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1209 case GST_ITERATOR_DONE:
1214 gst_iterator_free (iter);
1217 GST_DEBUG_OBJECT (pad, "Skipping timestamp in range check as no "
1218 "internal linked pad was found");
1222 GST_VALIDATE_REPORT (monitor, BUFFER_TIMESTAMP_OUT_OF_RECEIVED_RANGE,
1223 "Timestamp %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT
1224 " is out of range of received input", GST_TIME_ARGS (ts),
1225 GST_TIME_ARGS (ts_end));
1229 gst_object_unref (pad);
1233 gst_validate_pad_monitor_check_discont (GstValidatePadMonitor * pad_monitor,
1236 if (pad_monitor->pending_buffer_discont) {
1237 if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))
1238 GST_VALIDATE_REPORT (pad_monitor, BUFFER_MISSING_DISCONT,
1239 "Buffer is missing a DISCONT flag");
1240 pad_monitor->pending_buffer_discont = FALSE;
1245 gst_validate_pad_monitor_check_first_buffer (GstValidatePadMonitor *
1246 pad_monitor, GstBuffer * buffer)
1249 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1252 if (G_UNLIKELY (pad_monitor->first_buffer)) {
1253 pad_monitor->first_buffer = FALSE;
1255 if (!pad_monitor->has_segment && PAD_IS_IN_PUSH_MODE (pad)) {
1256 GST_VALIDATE_REPORT (pad_monitor, BUFFER_BEFORE_SEGMENT,
1257 "Received buffer before Segment event");
1260 GST_DEBUG_OBJECT (pad,
1261 "Checking first buffer (pts:%" GST_TIME_FORMAT " dts:%" GST_TIME_FORMAT
1262 ")", GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
1263 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)));
1267 gst_object_unref (pad);
1271 gst_validate_pad_monitor_check_eos (GstValidatePadMonitor *
1272 pad_monitor, GstBuffer * buffer)
1274 if (G_UNLIKELY (pad_monitor->is_eos)) {
1275 GST_VALIDATE_REPORT (pad_monitor, BUFFER_AFTER_EOS,
1276 "Received buffer %" GST_PTR_FORMAT " after EOS", buffer);
1281 gst_validate_pad_monitor_update_buffer_data (GstValidatePadMonitor *
1282 pad_monitor, GstBuffer * buffer)
1285 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1287 pad_monitor->current_timestamp = GST_BUFFER_TIMESTAMP (buffer);
1288 pad_monitor->current_duration = GST_BUFFER_DURATION (buffer);
1289 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
1290 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_start)) {
1291 pad_monitor->timestamp_range_start =
1292 MIN (pad_monitor->timestamp_range_start,
1293 GST_BUFFER_TIMESTAMP (buffer));
1295 pad_monitor->timestamp_range_start = GST_BUFFER_TIMESTAMP (buffer);
1298 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
1299 GstClockTime endts =
1300 GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
1301 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_end)) {
1302 pad_monitor->timestamp_range_end =
1303 MAX (pad_monitor->timestamp_range_end, endts);
1305 pad_monitor->timestamp_range_end = endts;
1309 GST_DEBUG_OBJECT (pad, "Current stored range: %" GST_TIME_FORMAT
1310 " - %" GST_TIME_FORMAT,
1311 GST_TIME_ARGS (pad_monitor->timestamp_range_start),
1312 GST_TIME_ARGS (pad_monitor->timestamp_range_end));
1314 gst_object_unref (pad);
1317 static GstFlowReturn
1318 _combine_flows (GstFlowReturn ret1, GstFlowReturn ret2)
1322 if (ret1 <= GST_FLOW_NOT_NEGOTIATED)
1324 if (ret2 <= GST_FLOW_NOT_NEGOTIATED)
1326 if (ret1 == GST_FLOW_FLUSHING || ret2 == GST_FLOW_FLUSHING)
1327 return GST_FLOW_FLUSHING;
1328 if (ret1 == GST_FLOW_OK || ret2 == GST_FLOW_OK)
1334 gst_validate_pad_monitor_check_aggregated_return (GstValidatePadMonitor *
1335 monitor, GstObject * parent, GstFlowReturn ret)
1341 GstState state, pending;
1342 GstValidatePadMonitor *othermonitor;
1343 GstFlowReturn aggregated = GST_FLOW_NOT_LINKED;
1344 gboolean found_a_pad = FALSE;
1346 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1349 iter = gst_pad_iterate_internal_links (pad);
1352 GValue value = { 0, };
1353 switch (gst_iterator_next (iter, &value)) {
1354 case GST_ITERATOR_OK:
1355 otherpad = g_value_get_object (&value);
1356 peerpad = gst_pad_get_peer (otherpad);
1358 othermonitor = _GET_PAD_MONITOR (peerpad);
1361 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1363 _combine_flows (aggregated, othermonitor->last_flow_return);
1364 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1367 gst_object_unref (peerpad);
1369 g_value_reset (&value);
1371 case GST_ITERATOR_RESYNC:
1372 gst_iterator_resync (iter);
1374 case GST_ITERATOR_ERROR:
1375 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1378 case GST_ITERATOR_DONE:
1383 gst_iterator_free (iter);
1385 /* no peer pad found, nothing to do */
1389 if (aggregated == GST_FLOW_FLUSHING) {
1390 gst_element_get_state (GST_ELEMENT (parent), &state, &pending, 0);
1391 if (state < GST_STATE_PAUSED || pending < GST_STATE_PAUSED) {
1392 /* Aggregated is flushing, we might have been aggregating a combination
1393 * of pads that are not what was present on the element during the actual
1394 * data flow combination (pads might have been removed meanwhile) */
1398 } else if (aggregated == GST_FLOW_OK || aggregated == GST_FLOW_EOS) {
1400 /* those are acceptable situations */
1401 if (GST_PAD_IS_FLUSHING (pad) && ret == GST_FLOW_FLUSHING) {
1402 /* pad is flushing, always acceptable to return flushing */
1406 gst_element_get_state (GST_ELEMENT (parent), &state, &pending, 0);
1407 if (ret == GST_FLOW_FLUSHING && (state < GST_STATE_PAUSED
1408 || pending < GST_STATE_PAUSED)) {
1409 /* Element is being teared down, accept FLOW_FLUSHING */
1414 if (monitor->is_eos && ret == GST_FLOW_EOS) {
1415 /* this element received eos and returned eos */
1419 if (PAD_PARENT_IS_DEMUXER (monitor) && ret == GST_FLOW_EOS) {
1420 /* a demuxer can return EOS when the samples end */
1425 if (aggregated != ret) {
1426 GST_VALIDATE_REPORT (monitor, WRONG_FLOW_RETURN,
1427 "Wrong combined flow return %s(%d). Expected: %s(%d)",
1428 gst_flow_get_name (ret), ret, gst_flow_get_name (aggregated),
1433 gst_object_unref (pad);
1437 gst_validate_pad_monitor_otherpad_add_pending_serialized_event
1438 (GstValidatePadMonitor * monitor, GstEvent * event, GstClockTime last_ts)
1443 GstValidatePadMonitor *othermonitor;
1447 if (!GST_EVENT_IS_SERIALIZED (event))
1451 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1453 iter = gst_pad_iterate_internal_links (pad);
1455 /* inputselector will return NULL if the sinkpad is not the active one .... */
1456 GST_FIXME_OBJECT (pad, "No iterator");
1457 gst_object_unref (pad);
1463 GValue value = { 0, };
1464 switch (gst_iterator_next (iter, &value)) {
1465 case GST_ITERATOR_OK:
1466 otherpad = g_value_get_object (&value);
1467 othermonitor = _GET_PAD_MONITOR (otherpad);
1469 SerializedEventData *data = g_slice_new0 (SerializedEventData);
1470 data->timestamp = last_ts;
1471 data->event = gst_event_ref (event);
1472 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1473 GST_DEBUG_OBJECT (pad, "Storing for pad %s:%s event %p %s",
1474 GST_DEBUG_PAD_NAME (otherpad), event,
1475 GST_EVENT_TYPE_NAME (event));
1476 g_ptr_array_add (othermonitor->serialized_events, data);
1477 debug_pending_event (otherpad, othermonitor->serialized_events);
1478 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1480 g_value_reset (&value);
1482 case GST_ITERATOR_RESYNC:
1483 gst_iterator_resync (iter);
1485 case GST_ITERATOR_ERROR:
1486 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1489 case GST_ITERATOR_DONE:
1494 gst_iterator_free (iter);
1495 gst_object_unref (pad);
1499 gst_validate_pad_monitor_otherpad_add_pending_field (GstValidatePadMonitor *
1500 monitor, GstStructure * structure, const gchar * field)
1505 GstValidatePadMonitor *othermonitor;
1509 v = gst_structure_get_value (structure, field);
1511 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1515 GST_DEBUG_OBJECT (pad, "Not adding pending field %s as it isn't "
1516 "present on structure %" GST_PTR_FORMAT, field, structure);
1517 gst_object_unref (pad);
1521 iter = gst_pad_iterate_internal_links (pad);
1524 GValue value = { 0, };
1525 switch (gst_iterator_next (iter, &value)) {
1526 case GST_ITERATOR_OK:
1527 otherpad = g_value_get_object (&value);
1528 othermonitor = _GET_PAD_MONITOR (otherpad);
1530 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1531 g_assert (othermonitor->pending_setcaps_fields != NULL);
1532 gst_structure_set_value (othermonitor->pending_setcaps_fields,
1534 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1536 g_value_reset (&value);
1538 case GST_ITERATOR_RESYNC:
1539 gst_iterator_resync (iter);
1541 case GST_ITERATOR_ERROR:
1542 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1545 case GST_ITERATOR_DONE:
1550 gst_iterator_free (iter);
1551 gst_object_unref (pad);
1555 gst_validate_pad_monitor_otherpad_clear_pending_fields (GstValidatePadMonitor *
1561 GstValidatePadMonitor *othermonitor;
1564 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1567 iter = gst_pad_iterate_internal_links (pad);
1569 gst_object_unref (pad);
1570 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1577 GValue value = { 0, };
1578 switch (gst_iterator_next (iter, &value)) {
1579 case GST_ITERATOR_OK:
1580 otherpad = g_value_get_object (&value);
1581 othermonitor = _GET_PAD_MONITOR (otherpad);
1583 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1584 g_assert (othermonitor->pending_setcaps_fields != NULL);
1585 gst_structure_free (othermonitor->pending_setcaps_fields);
1586 othermonitor->pending_setcaps_fields =
1587 gst_structure_new_empty (PENDING_FIELDS);
1588 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1590 g_value_reset (&value);
1592 case GST_ITERATOR_RESYNC:
1593 gst_iterator_resync (iter);
1595 case GST_ITERATOR_ERROR:
1596 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1599 case GST_ITERATOR_DONE:
1604 gst_object_unref (pad);
1605 gst_iterator_free (iter);
1609 gst_validate_pad_monitor_add_expected_newsegment (GstValidatePadMonitor *
1610 monitor, GstEvent * event)
1615 GstValidatePadMonitor *othermonitor;
1617 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1620 iter = gst_pad_iterate_internal_links (pad);
1622 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1623 gst_object_unref (pad);
1629 GValue value = { 0, };
1630 switch (gst_iterator_next (iter, &value)) {
1631 case GST_ITERATOR_OK:
1632 otherpad = g_value_get_object (&value);
1635 othermonitor = _GET_PAD_MONITOR (otherpad);
1636 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1637 gst_event_replace (&othermonitor->expected_segment, event);
1638 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1639 g_value_reset (&value);
1641 case GST_ITERATOR_RESYNC:
1642 gst_iterator_resync (iter);
1644 case GST_ITERATOR_ERROR:
1645 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1648 case GST_ITERATOR_DONE:
1653 gst_iterator_free (iter);
1654 gst_object_unref (pad);
1657 /* common checks for both sink and src event functions */
1659 gst_validate_pad_monitor_common_event_check (GstValidatePadMonitor *
1660 pad_monitor, GstEvent * event)
1662 guint32 seqnum = gst_event_get_seqnum (event);
1664 if (seqnum == GST_SEQNUM_INVALID)
1665 GST_VALIDATE_REPORT (pad_monitor, EVENT_INVALID_SEQNUM,
1666 "Event %p (%s) has an invalid SEQNUM", event,
1667 GST_EVENT_TYPE_NAME (event));
1669 switch (GST_EVENT_TYPE (event)) {
1670 case GST_EVENT_FLUSH_START:
1672 if (pad_monitor->pending_flush_start_seqnum != GST_SEQNUM_INVALID) {
1673 if (seqnum == pad_monitor->pending_flush_start_seqnum) {
1674 pad_monitor->pending_flush_start_seqnum = GST_SEQNUM_INVALID;
1676 GST_VALIDATE_REPORT (pad_monitor, FLUSH_START_HAS_WRONG_SEQNUM,
1677 "Got: %u Expected: %u", seqnum,
1678 pad_monitor->pending_flush_start_seqnum);
1682 if (pad_monitor->pending_flush_stop) {
1683 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1684 "Received flush-start from when flush-stop was expected");
1686 pad_monitor->pending_flush_stop = TRUE;
1689 case GST_EVENT_FLUSH_STOP:
1691 if (pad_monitor->pending_flush_stop_seqnum != GST_SEQNUM_INVALID) {
1692 if (seqnum == pad_monitor->pending_flush_stop_seqnum) {
1693 pad_monitor->pending_flush_stop_seqnum = GST_SEQNUM_INVALID;
1695 GST_VALIDATE_REPORT (pad_monitor, FLUSH_STOP_HAS_WRONG_SEQNUM,
1696 "Got: %u Expected: %u", seqnum,
1697 pad_monitor->pending_flush_stop_seqnum);
1701 pad_monitor->pending_newsegment_seqnum = seqnum;
1702 pad_monitor->pending_eos_seqnum = seqnum;
1704 if (!pad_monitor->pending_flush_stop) {
1705 gchar *event_str = _get_event_string (event);
1707 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_STOP_UNEXPECTED,
1708 "Unexpected flush-stop %s", event_str);
1711 pad_monitor->pending_flush_stop = FALSE;
1713 /* Buffers following a FLUSH should have the DISCONT flag set */
1714 pad_monitor->pending_buffer_discont = TRUE;
1716 /* cleanup our data */
1717 gst_validate_pad_monitor_flush (pad_monitor);
1726 mark_pads_eos (GstValidatePadMonitor * pad_monitor)
1728 GstValidatePadMonitor *peer_monitor;
1731 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1733 GstPad *peer = gst_pad_get_peer (pad);
1735 gst_object_unref (pad);
1736 pad_monitor->is_eos = TRUE;
1738 real_peer = _get_actual_pad (peer);
1739 peer_monitor = _GET_PAD_MONITOR (real_peer);
1741 peer_monitor->is_eos = TRUE;
1742 gst_object_unref (peer);
1743 gst_object_unref (real_peer);
1747 static inline gboolean
1748 _should_check_buffers (GstValidatePadMonitor * pad_monitor,
1749 gboolean force_checks)
1752 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1754 GstValidateMonitor *monitor = GST_VALIDATE_MONITOR (pad_monitor);
1756 if (pad_monitor->first_buffer || force_checks) {
1757 if (pad_monitor->segment.rate != 1.0) {
1758 GST_INFO_OBJECT (pad_monitor, "We do not support buffer checking"
1759 " for trick modes");
1761 pad_monitor->check_buffers = FALSE;
1762 } else if (!PAD_PARENT_IS_DECODER (pad_monitor)) {
1763 GST_DEBUG_OBJECT (pad, "Not on a decoder => no buffer checking");
1765 pad_monitor->check_buffers = FALSE;
1766 } else if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK) {
1767 GST_DEBUG_OBJECT (pad, "Not a sinkpad => no buffer checking");
1769 pad_monitor->check_buffers = FALSE;
1770 } else if (!pad_monitor->caps_is_video) {
1771 GST_DEBUG_OBJECT (pad, "Not working with video => no buffer checking");
1773 pad_monitor->check_buffers = FALSE;
1774 } else if (monitor->media_descriptor == NULL) {
1775 GST_DEBUG_OBJECT (pad, "No media_descriptor set => no buffer checking");
1777 pad_monitor->check_buffers = FALSE;
1778 } else if (!gst_validate_media_descriptor_detects_frames
1779 (monitor->media_descriptor)) {
1780 GST_DEBUG_OBJECT (pad,
1781 "No frame detection media descriptor => no buffer checking");
1782 pad_monitor->check_buffers = FALSE;
1783 } else if (pad_monitor->all_bufs == NULL &&
1784 !gst_validate_media_descriptor_get_buffers (monitor->media_descriptor,
1785 pad, NULL, &pad_monitor->all_bufs)) {
1787 GST_INFO_OBJECT (monitor,
1788 "The MediaInfo is marked as detecting frame, but getting frames"
1789 " from pad %" GST_PTR_FORMAT " did not work (some format conversion"
1790 " might be happening)", pad);
1792 pad_monitor->check_buffers = FALSE;
1794 if (!pad_monitor->current_buf)
1795 pad_monitor->current_buf = pad_monitor->all_bufs;
1796 pad_monitor->check_buffers = TRUE;
1799 gst_object_unref (pad);
1801 return pad_monitor->check_buffers;
1805 gst_validate_monitor_find_next_buffer (GstValidatePadMonitor * pad_monitor)
1808 gboolean passed_start = FALSE;
1810 if (!_should_check_buffers (pad_monitor, TRUE))
1813 for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) {
1814 GstBuffer *cbuf = (GstBuffer *) tmp->data;
1816 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf)
1817 : GST_BUFFER_PTS (cbuf);
1819 if (!GST_CLOCK_TIME_IS_VALID (ts))
1822 if (ts <= pad_monitor->segment.start)
1823 passed_start = TRUE;
1828 if (!GST_BUFFER_FLAG_IS_SET (cbuf, GST_BUFFER_FLAG_DELTA_UNIT)) {
1834 pad_monitor->current_buf = pad_monitor->all_bufs;
1836 pad_monitor->current_buf = tmp;
1839 /* Checks whether a segment is just an update of another,
1840 * That is to say that only the base and offset field differ and all
1841 * other fields are identical */
1843 is_segment_update (GstSegment * a, const GstSegment * b)
1845 /* Note : We never care about the position field, it is only
1846 * used for internal usage by elements */
1847 if (a->rate == b->rate &&
1848 a->applied_rate == b->applied_rate &&
1849 a->format == b->format && a->time == b->time) {
1850 /* Changes in base/offset are considered updates */
1851 /* Updating the end position of a segment is an update */
1852 /* Updating the duration of a segment is an update */
1853 if (a->rate > 0.0) {
1854 if (a->start == b->start)
1857 if (a->stop == b->stop)
1864 static GstFlowReturn
1865 gst_validate_pad_monitor_downstream_event_check (GstValidatePadMonitor *
1866 pad_monitor, GstObject * parent, GstEvent * event,
1867 GstPadEventFunction handler)
1869 GstFlowReturn ret = GST_FLOW_OK;
1870 const GstSegment *segment;
1871 guint32 seqnum = gst_event_get_seqnum (event);
1873 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1876 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1879 switch (GST_EVENT_TYPE (event)) {
1880 case GST_EVENT_STREAM_START:
1881 /* Buffers following a STREAM_START should have the DISCONT flag set */
1882 pad_monitor->pending_buffer_discont = TRUE;
1884 case GST_EVENT_SEGMENT:
1885 /* parse segment data to be used if event is handled */
1886 gst_event_parse_segment (event, &segment);
1888 GST_DEBUG_OBJECT (pad, "Got segment %" GST_SEGMENT_FORMAT, segment);
1890 /* Reset expected flush start/stop values, we have a segment */
1891 pad_monitor->pending_flush_start_seqnum = GST_SEQNUM_INVALID;
1892 pad_monitor->pending_flush_stop_seqnum = GST_SEQNUM_INVALID;
1894 if (pad_monitor->pending_newsegment_seqnum != GST_SEQNUM_INVALID) {
1895 if (pad_monitor->pending_newsegment_seqnum == seqnum) {
1896 pad_monitor->pending_newsegment_seqnum = GST_SEQNUM_INVALID;
1897 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->pending_seek_accurate_time)) {
1898 if (segment->time == pad_monitor->pending_seek_accurate_time) {
1899 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
1901 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_START,
1902 "After an accurate seek, got: %" GST_TIME_FORMAT
1903 " Expected: %" GST_TIME_FORMAT, GST_TIME_ARGS (segment->time),
1904 GST_TIME_ARGS (pad_monitor->pending_seek_accurate_time));
1908 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_SEQNUM,
1909 "Got: %u Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1913 pad_monitor->pending_eos_seqnum = seqnum;
1915 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1916 gst_validate_pad_monitor_add_expected_newsegment (pad_monitor, event);
1918 /* check if this segment is the expected one */
1919 if (pad_monitor->expected_segment) {
1920 const GstSegment *exp_segment;
1922 if (pad_monitor->expected_segment != event) {
1923 gst_event_parse_segment (pad_monitor->expected_segment,
1925 if (segment->format == exp_segment->format) {
1926 if ((exp_segment->rate * exp_segment->applied_rate !=
1927 segment->rate * segment->applied_rate))
1928 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1929 "Rate * applied_rate %f != expected %f",
1930 segment->rate * segment->applied_rate,
1931 exp_segment->rate * exp_segment->applied_rate);
1932 if (exp_segment->start != segment->start)
1933 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1934 "Start %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
1935 GST_TIME_ARGS (segment->start),
1936 GST_TIME_ARGS (exp_segment->start));
1937 if (exp_segment->stop != segment->stop)
1938 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1939 "Stop %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
1940 GST_TIME_ARGS (segment->stop),
1941 GST_TIME_ARGS (exp_segment->stop));
1942 if (exp_segment->position != segment->position)
1943 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1944 "Position %" GST_TIME_FORMAT " != expected %"
1945 GST_TIME_FORMAT, GST_TIME_ARGS (segment->position),
1946 GST_TIME_ARGS (exp_segment->position));
1949 gst_event_replace (&pad_monitor->expected_segment, NULL);
1953 case GST_EVENT_CAPS:{
1956 gst_event_parse_caps (event, &caps);
1957 gst_validate_pad_monitor_setcaps_pre (pad_monitor, caps);
1961 pad_monitor->is_eos = TRUE;
1962 /* FIXME : This feels and looks wrong ... */
1963 if (pad_monitor->pending_eos_seqnum == GST_SEQNUM_INVALID) {
1964 GST_VALIDATE_REPORT (pad_monitor, EVENT_EOS_WITHOUT_SEGMENT,
1965 "EOS %" GST_PTR_FORMAT " received before a segment was received",
1967 } else if (pad_monitor->pending_eos_seqnum != seqnum) {
1968 GST_VALIDATE_REPORT (pad_monitor, EOS_HAS_WRONG_SEQNUM,
1969 "Got: %u. Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1973 * TODO add end of stream checks for
1974 * - events not pushed
1975 * - buffer data not pushed
1976 * - pending events not received
1980 /* both flushes are handled by the common event function */
1981 case GST_EVENT_FLUSH_START:
1982 case GST_EVENT_FLUSH_STOP:
1984 case GST_EVENT_SINK_MESSAGE:
1989 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1990 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1991 gst_validate_pad_monitor_event_overrides (pad_monitor, event);
1993 gst_event_ref (event);
1994 if (pad_monitor->event_full_func)
1995 ret = pad_monitor->event_full_func (pad, parent, event);
1996 else if (pad_monitor->event_func (pad, parent, event))
1999 ret = GST_FLOW_ERROR;
2001 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2002 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2005 switch (GST_EVENT_TYPE (event)) {
2006 case GST_EVENT_SEGMENT:
2007 if (ret == GST_FLOW_OK) {
2008 /* If the new segment is not an update of the previous one, then
2009 * the following buffer should have the DISCONT flag set */
2010 if (!is_segment_update (&pad_monitor->segment, segment))
2011 pad_monitor->pending_buffer_discont = TRUE;
2012 if (!pad_monitor->has_segment
2013 && pad_monitor->segment.format != segment->format) {
2014 gst_segment_init (&pad_monitor->segment, segment->format);
2016 gst_segment_copy_into (segment, &pad_monitor->segment);
2017 pad_monitor->has_segment = TRUE;
2018 gst_validate_monitor_find_next_buffer (pad_monitor);
2021 case GST_EVENT_CAPS:{
2024 gst_event_parse_caps (event, &caps);
2025 gst_validate_pad_monitor_setcaps_post (pad_monitor, caps,
2026 ret == GST_FLOW_OK);
2029 case GST_EVENT_FLUSH_START:
2030 case GST_EVENT_FLUSH_STOP:
2033 case GST_EVENT_SINK_MESSAGE:
2039 gst_event_unref (event);
2040 gst_object_unref (pad);
2045 gst_validate_pad_monitor_src_event_check (GstValidatePadMonitor * pad_monitor,
2046 GstObject * parent, GstEvent * event, GstPadEventFunction handler)
2048 gboolean ret = TRUE;
2052 GstSeekFlags seek_flags;
2053 GstSeekType start_type, stop_type;
2054 guint32 seqnum = gst_event_get_seqnum (event);
2056 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2059 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
2062 switch (GST_EVENT_TYPE (event)) {
2063 case GST_EVENT_SEEK:
2065 gst_event_parse_seek (event, &rate, &format, &seek_flags, &start_type,
2066 &start, &stop_type, &stop);
2067 /* upstream seek - store the seek event seqnum to check
2068 * flushes and newsegments share the same */
2071 /* both flushes are handled by the common event handling function */
2072 case GST_EVENT_FLUSH_START:
2073 case GST_EVENT_FLUSH_STOP:
2074 case GST_EVENT_NAVIGATION:
2075 case GST_EVENT_LATENCY:
2076 case GST_EVENT_STEP:
2083 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2084 /* Safely store pending accurate seek values */
2085 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
2086 if (seek_flags & GST_SEEK_FLAG_ACCURATE) {
2087 GST_DEBUG_OBJECT (pad,
2088 "Storing expected accurate seek time %" GST_TIME_FORMAT,
2089 GST_TIME_ARGS (start));
2090 pad_monitor->pending_seek_accurate_time = start;
2092 /* TODO we might need to use a list as multiple seeks can be sent
2093 * before the flushes arrive here */
2094 if (seek_flags & GST_SEEK_FLAG_FLUSH) {
2095 pad_monitor->pending_flush_start_seqnum = seqnum;
2096 pad_monitor->pending_flush_stop_seqnum = seqnum;
2100 gst_event_ref (event);
2101 ret = pad_monitor->event_func (pad, parent, event);
2103 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
2104 /* If the seek was already handled (same current seqnum), reset the
2105 * expected accurate seek value */
2106 if (ret && pad_monitor->has_segment
2107 && seqnum == pad_monitor->pending_eos_seqnum) {
2108 GST_DEBUG_OBJECT (pad,
2109 "Resetting expected accurate seek value, was already handled");
2110 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
2112 /* do not expect any of these events anymore */
2113 pad_monitor->pending_flush_start_seqnum = GST_SEQNUM_INVALID;
2114 pad_monitor->pending_flush_stop_seqnum = GST_SEQNUM_INVALID;
2115 pad_monitor->pending_newsegment_seqnum = GST_SEQNUM_INVALID;
2116 pad_monitor->pending_eos_seqnum = GST_SEQNUM_INVALID;
2117 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
2120 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2124 switch (GST_EVENT_TYPE (event)) {
2125 case GST_EVENT_FLUSH_START:
2126 case GST_EVENT_FLUSH_STOP:
2128 case GST_EVENT_SEEK:
2129 case GST_EVENT_NAVIGATION:
2130 case GST_EVENT_LATENCY:
2131 case GST_EVENT_STEP:
2137 gst_event_unref (event);
2138 gst_object_unref (pad);
2143 gst_validate_pad_monitor_check_right_buffer (GstValidatePadMonitor *
2144 pad_monitor, GstBuffer * buffer)
2147 GstBuffer *wanted_buf;
2148 GstMapInfo map, wanted_map;
2150 gboolean ret = TRUE;
2154 if (_should_check_buffers (pad_monitor, FALSE) == FALSE)
2158 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2160 if (pad_monitor->current_buf == NULL) {
2161 GST_INFO_OBJECT (pad, "No current buffer one pad, Why?");
2162 gst_object_unref (pad);
2166 wanted_buf = pad_monitor->current_buf->data;
2168 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (wanted_buf)) &&
2169 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buffer)) &&
2170 GST_BUFFER_PTS (wanted_buf) != GST_BUFFER_PTS (buffer)) {
2172 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2173 "buffer %" GST_PTR_FORMAT " PTS %" GST_TIME_FORMAT
2174 " different than expected: %" GST_TIME_FORMAT, buffer,
2175 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
2176 GST_TIME_ARGS (GST_BUFFER_PTS (wanted_buf)));
2181 if (GST_BUFFER_DTS (wanted_buf) != GST_BUFFER_DTS (buffer)) {
2182 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2183 "buffer %" GST_PTR_FORMAT " DTS %" GST_TIME_FORMAT
2184 " different than expected: %" GST_TIME_FORMAT, buffer,
2185 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
2186 GST_TIME_ARGS (GST_BUFFER_DTS (wanted_buf)));
2190 if (GST_BUFFER_DURATION (wanted_buf) != GST_BUFFER_DURATION (buffer)) {
2191 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2192 "buffer %" GST_PTR_FORMAT " DURATION %" GST_TIME_FORMAT
2193 " different than expected: %" GST_TIME_FORMAT, buffer,
2194 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2195 GST_TIME_ARGS (GST_BUFFER_DURATION (wanted_buf)));
2199 if (GST_BUFFER_FLAG_IS_SET (wanted_buf, GST_BUFFER_FLAG_DELTA_UNIT) !=
2200 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
2201 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2202 "buffer %" GST_PTR_FORMAT " Delta unit is set to %s but expected %s",
2203 buffer, GST_BUFFER_FLAG_IS_SET (buffer,
2204 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False",
2205 GST_BUFFER_FLAG_IS_SET (wanted_buf,
2206 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False");
2210 g_assert (gst_buffer_map (wanted_buf, &wanted_map, GST_MAP_READ));
2211 g_assert (gst_buffer_map (buffer, &map, GST_MAP_READ));
2213 checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
2214 (const guchar *) map.data, map.size);
2216 if (g_strcmp0 ((gchar *) wanted_map.data, checksum)) {
2217 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2218 "buffer %" GST_PTR_FORMAT " checksum %s different from expected: %s",
2219 buffer, checksum, wanted_map.data);
2223 gst_buffer_unmap (wanted_buf, &wanted_map);
2224 gst_buffer_unmap (buffer, &map);
2226 gst_object_unref (pad);
2228 pad_monitor->current_buf = pad_monitor->current_buf->next;
2234 gst_validate_pad_monitor_check_return (GstValidatePadMonitor * pad_monitor,
2237 GstValidateMonitor *parent = GST_VALIDATE_MONITOR (pad_monitor);
2239 if (ret != GST_FLOW_ERROR)
2242 while (GST_VALIDATE_MONITOR_GET_PARENT (parent))
2243 parent = GST_VALIDATE_MONITOR_GET_PARENT (parent);
2245 if (GST_IS_VALIDATE_PIPELINE_MONITOR (parent)) {
2246 GstValidatePipelineMonitor *m = GST_VALIDATE_PIPELINE_MONITOR (parent);
2248 GST_VALIDATE_MONITOR_LOCK (m);
2249 if (m->got_error == FALSE) {
2250 GST_VALIDATE_REPORT (pad_monitor, FLOW_ERROR_WITHOUT_ERROR_MESSAGE,
2251 "Pad return GST_FLOW_ERROR but no GST_MESSAGE_ERROR was received on"
2254 /* Only report it the first time */
2255 m->got_error = TRUE;
2257 GST_VALIDATE_MONITOR_UNLOCK (m);
2261 static GstFlowReturn
2262 gst_validate_pad_monitor_chain_func (GstPad * pad, GstObject * parent,
2265 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2268 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2269 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2271 gst_validate_pad_monitor_check_discont (pad_monitor, buffer);
2272 gst_validate_pad_monitor_check_right_buffer (pad_monitor, buffer);
2273 gst_validate_pad_monitor_check_first_buffer (pad_monitor, buffer);
2274 gst_validate_pad_monitor_update_buffer_data (pad_monitor, buffer);
2275 gst_validate_pad_monitor_check_eos (pad_monitor, buffer);
2277 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2278 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2280 gst_validate_pad_monitor_buffer_overrides (pad_monitor, buffer);
2282 ret = pad_monitor->chain_func (pad, parent, buffer);
2284 gst_validate_pad_monitor_check_return (pad_monitor, ret);
2286 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2287 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2289 pad_monitor->last_flow_return = ret;
2290 if (ret == GST_FLOW_EOS) {
2291 mark_pads_eos (pad_monitor);
2293 if (PAD_PARENT_IS_DEMUXER (pad_monitor))
2294 gst_validate_pad_monitor_check_aggregated_return (pad_monitor, parent, ret);
2296 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2297 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2303 gst_validate_pad_monitor_event_is_tracked (GstValidatePadMonitor * monitor,
2306 if (!GST_EVENT_IS_SERIALIZED (event)) {
2310 /* we don't track Tag events because they mutate too much and it is hard
2311 * to match a tag event pushed on a source pad with the one that was received
2313 * One idea would be to use seqnum, but it seems that it is undefined whether
2314 * seqnums should be maintained in tag events that are created from others
2315 * up to today. (2013-08-29)
2317 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
2323 static GstFlowReturn
2324 gst_validate_pad_monitor_sink_event_full_func (GstPad * pad, GstObject * parent,
2327 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2330 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2331 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2333 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
2335 if (gst_validate_pad_monitor_event_is_tracked (pad_monitor, event)) {
2336 GstClockTime last_ts = GST_CLOCK_TIME_NONE;
2337 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_timestamp)) {
2338 last_ts = pad_monitor->current_timestamp;
2339 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_duration)) {
2340 last_ts += pad_monitor->current_duration;
2343 gst_validate_pad_monitor_otherpad_add_pending_serialized_event (pad_monitor,
2348 gst_validate_pad_monitor_downstream_event_check (pad_monitor, parent,
2349 event, pad_monitor->event_func);
2351 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2352 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2357 gst_validate_pad_monitor_sink_event_func (GstPad * pad, GstObject * parent,
2360 if (gst_validate_pad_monitor_sink_event_full_func (pad, parent,
2361 event) == GST_FLOW_OK)
2367 gst_validate_pad_monitor_src_event_func (GstPad * pad, GstObject * parent,
2370 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2373 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2374 ret = gst_validate_pad_monitor_src_event_check (pad_monitor, parent, event,
2375 pad_monitor->event_func);
2376 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2381 gst_validate_pad_monitor_query_func (GstPad * pad, GstObject * parent,
2384 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2387 gst_validate_pad_monitor_query_overrides (pad_monitor, query);
2388 ret = pad_monitor->query_func (pad, parent, query);
2391 switch (GST_QUERY_TYPE (query)) {
2392 case GST_QUERY_ACCEPT_CAPS:
2396 gst_caps_replace (&pad_monitor->last_refused_caps, NULL);
2397 gst_query_parse_accept_caps_result (query, &result);
2399 GstCaps *refused_caps;
2401 gst_query_parse_accept_caps (query, &refused_caps);
2402 pad_monitor->last_refused_caps = gst_caps_copy (refused_caps);
2408 case GST_QUERY_CAPS:{
2412 /* We shouldn't need to lock the parent as this doesn't modify
2413 * other monitors, just does some peer_pad_caps */
2414 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2416 gst_query_parse_caps (query, &filter);
2417 gst_query_parse_caps_result (query, &res);
2419 gst_caps_replace (&pad_monitor->last_query_res, NULL);
2420 gst_caps_replace (&pad_monitor->last_query_filter, NULL);
2421 pad_monitor->last_query_res =
2422 res ? gst_caps_copy (res) : gst_caps_ref (GST_CAPS_NONE);
2423 pad_monitor->last_query_filter =
2424 filter ? gst_caps_copy (filter) : gst_caps_ref (GST_CAPS_NONE);
2426 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2427 gst_validate_pad_monitor_check_caps_fields_proxied (pad_monitor, res,
2430 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2442 gst_validate_pad_monitor_activatemode_func (GstPad * pad, GstObject * parent,
2443 GstPadMode mode, gboolean active)
2445 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2446 gboolean ret = TRUE;
2448 /* TODO add overrides for activate func */
2449 GST_DEBUG_OBJECT (pad, "active:%d", active);
2451 if (pad_monitor->activatemode_func)
2452 ret = pad_monitor->activatemode_func (pad, parent, mode, active);
2453 if (ret && active == FALSE) {
2454 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2455 gst_validate_pad_monitor_reset (pad_monitor);
2456 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2462 /* The interval between two buffer frequency checks */
2463 #define BUF_FREQ_CHECK_INTERVAL (GST_SECOND)
2466 gst_validate_pad_monitor_check_buffer_freq (GstValidatePadMonitor * monitor,
2471 if (!GST_PAD_IS_SRC (pad))
2474 if (!monitor->min_buf_freq)
2477 ts = gst_util_get_timestamp ();
2478 monitor->buffers_pushed++;
2480 /* Same logic as in fpsdisplaysink to compute the buffer frequency */
2481 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID
2482 (monitor->min_buf_freq_first_buffer_ts))) {
2483 monitor->min_buf_freq_first_buffer_ts = ts;
2484 monitor->min_buf_freq_interval_ts = ts;
2488 if (GST_CLOCK_DIFF (monitor->min_buf_freq_interval_ts,
2489 ts) > BUF_FREQ_CHECK_INTERVAL) {
2493 time_diff = (gdouble) (ts - monitor->min_buf_freq_interval_ts) / GST_SECOND;
2495 (gdouble) (monitor->buffers_pushed -
2496 monitor->last_buffers_pushed) / time_diff;
2498 if (fps < monitor->min_buf_freq) {
2499 if (GST_CLOCK_TIME_IS_VALID (monitor->min_buf_freq_start) &&
2500 GST_CLOCK_DIFF (monitor->min_buf_freq_first_buffer_ts,
2501 ts) < monitor->min_buf_freq_start) {
2502 GST_DEBUG_OBJECT (pad,
2503 "buffer frequency is too low (%.2f) but ignore for now (buffer-frequency-start =%"
2504 GST_TIME_FORMAT ")", fps,
2505 GST_TIME_ARGS (monitor->min_buf_freq_start));
2507 GST_VALIDATE_REPORT (monitor, CONFIG_BUFFER_FREQUENCY_TOO_LOW,
2508 "Buffers are not pushed fast enough on this pad: %.2f/sec (minimum: %.2f)",
2509 fps, monitor->min_buf_freq);
2513 monitor->last_buffers_pushed = monitor->buffers_pushed;
2514 monitor->min_buf_freq_interval_ts = ts;
2519 gst_validate_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
2520 gpointer udata, gboolean pull_mode)
2522 GstValidatePadMonitor *monitor = udata;
2524 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2525 GST_VALIDATE_MONITOR_LOCK (monitor);
2528 gst_validate_pad_monitor_check_discont (monitor, buffer);
2529 gst_validate_pad_monitor_check_first_buffer (monitor, buffer);
2530 gst_validate_pad_monitor_update_buffer_data (monitor, buffer);
2531 gst_validate_pad_monitor_check_eos (monitor, buffer);
2533 if (PAD_PARENT_IS_DECODER (monitor) || PAD_PARENT_IS_ENCODER (monitor)) {
2534 GstClockTime tolerance = 0;
2536 if (monitor->caps_is_audio)
2537 tolerance = AUDIO_TIMESTAMP_TOLERANCE;
2539 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range (monitor,
2543 gst_validate_pad_monitor_check_late_serialized_events (monitor,
2544 GST_BUFFER_TIMESTAMP (buffer));
2546 /* a GstValidatePadMonitor parent must be a GstValidateElementMonitor */
2547 if (PAD_PARENT_IS_DECODER (monitor)) {
2549 /* should not push out of segment data */
2550 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
2551 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)) &&
2552 ((!gst_segment_clip (&monitor->segment, monitor->segment.format,
2553 GST_BUFFER_TIMESTAMP (buffer),
2554 GST_BUFFER_TIMESTAMP (buffer) +
2555 GST_BUFFER_DURATION (buffer), NULL, NULL)) ||
2556 /* In the case of raw data, buffers should be strictly contained inside the
2558 (monitor->caps_is_raw &&
2559 GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer) <
2560 monitor->segment.start))
2562 /* TODO is this a timestamp issue? */
2563 GST_VALIDATE_REPORT (monitor, BUFFER_IS_OUT_OF_SEGMENT,
2564 "buffer is out of segment and shouldn't be pushed. Timestamp: %"
2565 GST_TIME_FORMAT " - Duration: %" GST_TIME_FORMAT ". Range: %"
2566 GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
2567 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
2568 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2569 GST_TIME_ARGS (monitor->segment.start),
2570 GST_TIME_ARGS (monitor->segment.stop));
2574 gst_validate_pad_monitor_check_buffer_freq (monitor, pad);
2576 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2577 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2578 gst_validate_pad_monitor_buffer_probe_overrides (monitor, buffer);
2583 gst_validate_pad_monitor_event_probe (GstPad * pad, GstEvent * event,
2586 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (udata);
2588 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2589 GST_VALIDATE_MONITOR_LOCK (monitor);
2591 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
2593 if (GST_EVENT_IS_SERIALIZED (event)) {
2596 /* Detect if events the element received are being forwarded in the same order
2598 * Several scenarios:
2599 * 1) The element pushes the event as-is
2600 * 2) The element consumes the event and does not forward it
2601 * 3) The element consumes the event and creates another one instead
2602 * 4) The element pushes other serialized event before pushing out the
2605 * For each pad we have two lists to track serialized events:
2606 * 1) We received on input and expect to see (serialized_events)
2607 * 2) We received on input but don't expect to see (expired_events)
2609 * To detect events that are pushed in a different order from the one they were
2610 * received in we check that:
2612 * For each event being outputted:
2613 * If it is in the expired_events list:
2615 * If it is in the serialized_events list:
2616 * If there are other events that were received before:
2617 * Put those events on the expired_events list
2618 * Remove that event and any previous ones from the serialized_events list
2620 * Clear expired events list when flushing or on pad deactivation
2624 if (g_list_find (monitor->expired_events, event)) {
2625 gchar *event_str = _get_event_string (event);
2626 /* If it's the expired events, we've failed */
2627 GST_WARNING_OBJECT (pad, "Did not expect event %p %s", event,
2628 GST_EVENT_TYPE_NAME (event));
2629 GST_VALIDATE_REPORT (monitor, EVENT_SERIALIZED_OUT_OF_ORDER,
2630 "Serialized event was pushed out of order: %s", event_str);
2633 monitor->expired_events = g_list_remove (monitor->expired_events, event);
2634 gst_event_unref (event); /* remove the ref that was on the list */
2635 } else if (monitor->serialized_events->len) {
2636 for (i = 0; i < monitor->serialized_events->len; i++) {
2637 SerializedEventData *next_event =
2638 g_ptr_array_index (monitor->serialized_events, i);
2639 GST_DEBUG_OBJECT (pad, "Checking against stored event #%d: %p %s", i,
2640 next_event->event, GST_EVENT_TYPE_NAME (next_event->event));
2642 if (event == next_event->event
2643 || GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2644 /* We have found our event */
2645 GST_DEBUG_OBJECT (pad, "Found matching event");
2647 while (monitor->serialized_events->len > i
2648 && GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2649 /* Swallow all expected events of the same type */
2650 g_ptr_array_remove_index (monitor->serialized_events, i);
2651 next_event = g_ptr_array_index (monitor->serialized_events, i);
2654 /* Move all previous events to expired events */
2655 if (G_UNLIKELY (i > 0)) {
2656 GST_DEBUG_OBJECT (pad,
2657 "Moving previous expected events to expired list");
2659 next_event = g_ptr_array_index (monitor->serialized_events, 0);
2660 monitor->expired_events =
2661 g_list_append (monitor->expired_events,
2662 gst_event_ref (next_event->event));
2663 g_ptr_array_remove_index (monitor->serialized_events, 0);
2666 debug_pending_event (pad, monitor->serialized_events);
2673 /* This so far is just like an event that is flowing downstream,
2674 * so we do the same checks as a sinkpad event handler */
2675 gst_validate_pad_monitor_downstream_event_check (monitor, NULL, event, NULL);
2676 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2677 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2680 static GstPadProbeReturn
2681 gst_validate_pad_monitor_pad_probe (GstPad * pad, GstPadProbeInfo * info,
2684 if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
2685 gst_validate_pad_monitor_buffer_probe (pad, info->data, udata,
2686 GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_PULL);
2687 else if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
2688 gst_validate_pad_monitor_event_probe (pad, info->data, udata);
2690 return GST_PAD_PROBE_OK;
2694 gst_validate_pad_monitor_update_caps_info (GstValidatePadMonitor * pad_monitor,
2697 GstStructure *structure;
2699 g_return_if_fail (gst_caps_is_fixed (caps));
2701 pad_monitor->caps_is_audio = FALSE;
2702 pad_monitor->caps_is_video = FALSE;
2704 structure = gst_caps_get_structure (caps, 0);
2705 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/")) {
2706 pad_monitor->caps_is_audio = TRUE;
2707 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/")) {
2708 pad_monitor->caps_is_video = TRUE;
2711 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/x-raw") ||
2712 g_str_has_prefix (gst_structure_get_name (structure), "video/x-raw")) {
2713 pad_monitor->caps_is_raw = TRUE;
2715 pad_monitor->caps_is_raw = FALSE;
2720 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
2723 GstStructure *structure;
2725 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2728 /* Check if caps are identical to last caps and complain if so
2729 * Only checked for sink pads as src pads might push the same caps
2730 * multiple times during unlinked/autoplugging scenarios */
2731 if (GST_PAD_IS_SINK (pad) && pad_monitor->last_caps
2732 && gst_caps_is_equal (caps, pad_monitor->last_caps)) {
2733 gchar *caps_str = gst_caps_to_string (caps);
2735 GST_VALIDATE_REPORT (pad_monitor, EVENT_CAPS_DUPLICATE, "%s", caps_str);
2740 gst_validate_pad_monitor_check_caps_complete (pad_monitor, caps);
2743 structure = gst_caps_get_structure (caps, 0);
2744 if (gst_structure_n_fields (pad_monitor->pending_setcaps_fields)) {
2747 i < gst_structure_n_fields (pad_monitor->pending_setcaps_fields);
2750 gst_structure_nth_field_name (pad_monitor->pending_setcaps_fields,
2752 const GValue *v = gst_structure_get_value (structure, name);
2753 const GValue *otherv =
2754 gst_structure_get_value (pad_monitor->pending_setcaps_fields, name);
2757 gchar *caps_str = gst_caps_to_string (caps);
2759 GST_VALIDATE_REPORT (pad_monitor, CAPS_EXPECTED_FIELD_NOT_FOUND,
2760 "Field %s is missing from setcaps caps '%s'", name, caps_str);
2762 } else if (gst_value_compare (v, otherv) != GST_VALUE_EQUAL) {
2763 gchar *caps_str = gst_caps_to_string (caps),
2764 *pending_setcaps_fields_str =
2765 gst_structure_to_string (pad_monitor->pending_setcaps_fields);
2768 GST_VALIDATE_REPORT (pad_monitor, CAPS_FIELD_UNEXPECTED_VALUE,
2769 "Field %s from setcaps caps '%s' is different "
2770 "from expected value in caps '%s'", name, caps_str,
2771 pending_setcaps_fields_str);
2773 g_free (pending_setcaps_fields_str);
2779 if (GST_PAD_IS_SINK (pad) &&
2780 gst_validate_pad_monitor_pad_should_proxy_othercaps (pad_monitor)) {
2781 if (_structure_is_video (structure)) {
2782 GST_DEBUG_OBJECT (pad,
2783 "Adding video common pending fields to other pad: %" GST_PTR_FORMAT,
2785 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2786 structure, "width");
2787 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2788 structure, "height");
2789 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2790 structure, "framerate");
2791 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2792 structure, "pixel-aspect-ratio");
2793 } else if (_structure_is_audio (structure)) {
2794 GST_DEBUG_OBJECT (pad,
2795 "Adding audio common pending fields to other pad: %" GST_PTR_FORMAT,
2797 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2799 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2800 structure, "channels");
2805 gst_structure_free (pad_monitor->pending_setcaps_fields);
2806 pad_monitor->pending_setcaps_fields =
2807 gst_structure_new_empty (PENDING_FIELDS);
2808 gst_object_unref (pad);
2810 gst_validate_pad_monitor_setcaps_overrides (pad_monitor, caps);
2814 gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor * pad_monitor,
2815 GstCaps * caps, gboolean ret)
2818 gst_validate_pad_monitor_otherpad_clear_pending_fields (pad_monitor);
2820 if (pad_monitor->last_caps) {
2821 gst_caps_unref (pad_monitor->last_caps);
2823 pad_monitor->last_caps = gst_caps_ref (caps);
2824 gst_validate_pad_monitor_update_caps_info (pad_monitor, caps);
2829 gst_validate_pad_monitor_get_min_buffer_frequency (GstValidatePadMonitor *
2830 monitor, GstPad * pad)
2834 if (!GST_PAD_IS_SRC (pad))
2837 config = gst_validate_plugin_get_config (NULL);
2838 for (l = config; l != NULL; l = g_list_next (l)) {
2839 GstStructure *s = l->data;
2840 gdouble min_buf_freq;
2841 const gchar *pad_name;
2842 GstElement *element = NULL;
2844 if (!gst_structure_get_double (s, "min-buffer-frequency", &min_buf_freq)) {
2847 if (!gst_structure_get_int (s, "min-buffer-frequency", &max_int))
2850 min_buf_freq = max_int;
2853 pad_name = gst_structure_get_string (s, "name");
2857 if (g_strcmp0 (GST_PAD_NAME (pad), pad_name))
2860 element = gst_pad_get_parent_element (pad);
2862 if (!gst_validate_element_matches_target (element, s))
2865 monitor->min_buf_freq = min_buf_freq;
2867 gst_validate_utils_get_clocktime (s, "buffer-frequency-start",
2868 &monitor->min_buf_freq_start);
2870 GST_DEBUG_OBJECT (pad, "pad has a minimum buffer frequency of %f",
2873 g_clear_object (&element);
2878 gst_validate_pad_monitor_do_setup (GstValidateMonitor * monitor)
2880 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR_CAST (monitor);
2881 GstPad *pad = (gpointer) gst_validate_monitor_get_target (monitor);
2883 if (!GST_IS_PAD (pad)) {
2884 GST_WARNING_OBJECT (monitor, "Trying to create pad monitor with other "
2886 gst_object_unref (pad);
2890 if (_GET_PAD_MONITOR (pad)) {
2891 GST_WARNING_OBJECT (pad_monitor,
2892 "Pad already has a validate-monitor associated");
2893 gst_object_unref (pad);
2897 _SET_PAD_MONITOR (pad, pad_monitor);
2899 pad_monitor->event_func = GST_PAD_EVENTFUNC (pad);
2900 pad_monitor->event_full_func = GST_PAD_EVENTFULLFUNC (pad);
2901 pad_monitor->query_func = GST_PAD_QUERYFUNC (pad);
2902 pad_monitor->activatemode_func = GST_PAD_ACTIVATEMODEFUNC (pad);
2903 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2905 pad_monitor->chain_func = GST_PAD_CHAINFUNC (pad);
2906 if (pad_monitor->chain_func)
2907 gst_pad_set_chain_function (pad, gst_validate_pad_monitor_chain_func);
2909 if (pad_monitor->event_full_func)
2910 gst_pad_set_event_full_function (pad,
2911 gst_validate_pad_monitor_sink_event_full_func);
2913 gst_pad_set_event_function (pad,
2914 gst_validate_pad_monitor_sink_event_func);
2916 gst_pad_set_event_function (pad, gst_validate_pad_monitor_src_event_func);
2918 /* add buffer/event probes */
2919 pad_monitor->pad_probe_id =
2920 gst_pad_add_probe (pad,
2921 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
2922 GST_PAD_PROBE_TYPE_EVENT_FLUSH,
2923 (GstPadProbeCallback) gst_validate_pad_monitor_pad_probe, pad_monitor,
2926 gst_pad_set_query_function (pad, gst_validate_pad_monitor_query_func);
2927 gst_pad_set_activatemode_function (pad,
2928 gst_validate_pad_monitor_activatemode_func);
2930 gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (monitor),
2931 g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad)));
2933 if (G_UNLIKELY (GST_PAD_PARENT (pad) == NULL))
2934 GST_FIXME ("Saw a pad not belonging to any object");
2936 gst_validate_pad_monitor_get_min_buffer_frequency (pad_monitor, pad);
2938 gst_object_unref (pad);