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 GstValidatePadMonitor *othermonitor;
1342 GstFlowReturn aggregated = GST_FLOW_NOT_LINKED;
1343 gboolean found_a_pad = FALSE;
1345 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1348 iter = gst_pad_iterate_internal_links (pad);
1351 GValue value = { 0, };
1352 switch (gst_iterator_next (iter, &value)) {
1353 case GST_ITERATOR_OK:
1354 otherpad = g_value_get_object (&value);
1355 peerpad = gst_pad_get_peer (otherpad);
1357 othermonitor = _GET_PAD_MONITOR (peerpad);
1360 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1362 _combine_flows (aggregated, othermonitor->last_flow_return);
1363 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1366 gst_object_unref (peerpad);
1368 g_value_reset (&value);
1370 case GST_ITERATOR_RESYNC:
1371 gst_iterator_resync (iter);
1373 case GST_ITERATOR_ERROR:
1374 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1377 case GST_ITERATOR_DONE:
1382 gst_iterator_free (iter);
1384 /* no peer pad found, nothing to do */
1387 if (aggregated == GST_FLOW_OK || aggregated == GST_FLOW_EOS) {
1388 GstState state, pending;
1390 /* those are acceptable situations */
1391 if (GST_PAD_IS_FLUSHING (pad) && ret == GST_FLOW_FLUSHING) {
1392 /* pad is flushing, always acceptable to return flushing */
1396 gst_element_get_state (GST_ELEMENT (parent), &state, &pending, 0);
1397 if (ret == GST_FLOW_FLUSHING && (state < GST_STATE_PAUSED
1398 || pending < GST_STATE_PAUSED)) {
1399 /* Element is being teared down, accept FLOW_FLUSHING */
1404 if (monitor->is_eos && ret == GST_FLOW_EOS) {
1405 /* this element received eos and returned eos */
1409 if (PAD_PARENT_IS_DEMUXER (monitor) && ret == GST_FLOW_EOS) {
1410 /* a demuxer can return EOS when the samples end */
1415 if (aggregated != ret) {
1416 GST_VALIDATE_REPORT (monitor, WRONG_FLOW_RETURN,
1417 "Wrong combined flow return %s(%d). Expected: %s(%d)",
1418 gst_flow_get_name (ret), ret, gst_flow_get_name (aggregated),
1423 gst_object_unref (pad);
1427 gst_validate_pad_monitor_otherpad_add_pending_serialized_event
1428 (GstValidatePadMonitor * monitor, GstEvent * event, GstClockTime last_ts)
1433 GstValidatePadMonitor *othermonitor;
1437 if (!GST_EVENT_IS_SERIALIZED (event))
1441 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1443 iter = gst_pad_iterate_internal_links (pad);
1445 /* inputselector will return NULL if the sinkpad is not the active one .... */
1446 GST_FIXME_OBJECT (pad, "No iterator");
1447 gst_object_unref (pad);
1453 GValue value = { 0, };
1454 switch (gst_iterator_next (iter, &value)) {
1455 case GST_ITERATOR_OK:
1456 otherpad = g_value_get_object (&value);
1457 othermonitor = _GET_PAD_MONITOR (otherpad);
1459 SerializedEventData *data = g_slice_new0 (SerializedEventData);
1460 data->timestamp = last_ts;
1461 data->event = gst_event_ref (event);
1462 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1463 GST_DEBUG_OBJECT (pad, "Storing for pad %s:%s event %p %s",
1464 GST_DEBUG_PAD_NAME (otherpad), event,
1465 GST_EVENT_TYPE_NAME (event));
1466 g_ptr_array_add (othermonitor->serialized_events, data);
1467 debug_pending_event (otherpad, othermonitor->serialized_events);
1468 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1470 g_value_reset (&value);
1472 case GST_ITERATOR_RESYNC:
1473 gst_iterator_resync (iter);
1475 case GST_ITERATOR_ERROR:
1476 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1479 case GST_ITERATOR_DONE:
1484 gst_iterator_free (iter);
1485 gst_object_unref (pad);
1489 gst_validate_pad_monitor_otherpad_add_pending_field (GstValidatePadMonitor *
1490 monitor, GstStructure * structure, const gchar * field)
1495 GstValidatePadMonitor *othermonitor;
1499 v = gst_structure_get_value (structure, field);
1501 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1505 GST_DEBUG_OBJECT (pad, "Not adding pending field %s as it isn't "
1506 "present on structure %" GST_PTR_FORMAT, field, structure);
1507 gst_object_unref (pad);
1511 iter = gst_pad_iterate_internal_links (pad);
1514 GValue value = { 0, };
1515 switch (gst_iterator_next (iter, &value)) {
1516 case GST_ITERATOR_OK:
1517 otherpad = g_value_get_object (&value);
1518 othermonitor = _GET_PAD_MONITOR (otherpad);
1520 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1521 g_assert (othermonitor->pending_setcaps_fields != NULL);
1522 gst_structure_set_value (othermonitor->pending_setcaps_fields,
1524 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1526 g_value_reset (&value);
1528 case GST_ITERATOR_RESYNC:
1529 gst_iterator_resync (iter);
1531 case GST_ITERATOR_ERROR:
1532 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1535 case GST_ITERATOR_DONE:
1540 gst_iterator_free (iter);
1541 gst_object_unref (pad);
1545 gst_validate_pad_monitor_otherpad_clear_pending_fields (GstValidatePadMonitor *
1551 GstValidatePadMonitor *othermonitor;
1554 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1557 iter = gst_pad_iterate_internal_links (pad);
1559 gst_object_unref (pad);
1560 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1567 GValue value = { 0, };
1568 switch (gst_iterator_next (iter, &value)) {
1569 case GST_ITERATOR_OK:
1570 otherpad = g_value_get_object (&value);
1571 othermonitor = _GET_PAD_MONITOR (otherpad);
1573 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1574 g_assert (othermonitor->pending_setcaps_fields != NULL);
1575 gst_structure_free (othermonitor->pending_setcaps_fields);
1576 othermonitor->pending_setcaps_fields =
1577 gst_structure_new_empty (PENDING_FIELDS);
1578 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1580 g_value_reset (&value);
1582 case GST_ITERATOR_RESYNC:
1583 gst_iterator_resync (iter);
1585 case GST_ITERATOR_ERROR:
1586 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1589 case GST_ITERATOR_DONE:
1594 gst_object_unref (pad);
1595 gst_iterator_free (iter);
1599 gst_validate_pad_monitor_add_expected_newsegment (GstValidatePadMonitor *
1600 monitor, GstEvent * event)
1605 GstValidatePadMonitor *othermonitor;
1607 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1610 iter = gst_pad_iterate_internal_links (pad);
1612 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1613 gst_object_unref (pad);
1619 GValue value = { 0, };
1620 switch (gst_iterator_next (iter, &value)) {
1621 case GST_ITERATOR_OK:
1622 otherpad = g_value_get_object (&value);
1625 othermonitor = _GET_PAD_MONITOR (otherpad);
1626 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1627 gst_event_replace (&othermonitor->expected_segment, event);
1628 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1629 g_value_reset (&value);
1631 case GST_ITERATOR_RESYNC:
1632 gst_iterator_resync (iter);
1634 case GST_ITERATOR_ERROR:
1635 GST_WARNING_OBJECT (pad, "Internal links pad iteration error");
1638 case GST_ITERATOR_DONE:
1643 gst_iterator_free (iter);
1644 gst_object_unref (pad);
1647 /* common checks for both sink and src event functions */
1649 gst_validate_pad_monitor_common_event_check (GstValidatePadMonitor *
1650 pad_monitor, GstEvent * event)
1652 guint32 seqnum = gst_event_get_seqnum (event);
1654 if (seqnum == GST_SEQNUM_INVALID)
1655 GST_VALIDATE_REPORT (pad_monitor, EVENT_INVALID_SEQNUM,
1656 "Event %p (%s) has an invalid SEQNUM", event,
1657 GST_EVENT_TYPE_NAME (event));
1659 switch (GST_EVENT_TYPE (event)) {
1660 case GST_EVENT_FLUSH_START:
1662 if (pad_monitor->pending_flush_start_seqnum != GST_SEQNUM_INVALID) {
1663 if (seqnum == pad_monitor->pending_flush_start_seqnum) {
1664 pad_monitor->pending_flush_start_seqnum = GST_SEQNUM_INVALID;
1666 GST_VALIDATE_REPORT (pad_monitor, FLUSH_START_HAS_WRONG_SEQNUM,
1667 "Got: %u Expected: %u", seqnum,
1668 pad_monitor->pending_flush_start_seqnum);
1672 if (pad_monitor->pending_flush_stop) {
1673 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1674 "Received flush-start from when flush-stop was expected");
1676 pad_monitor->pending_flush_stop = TRUE;
1679 case GST_EVENT_FLUSH_STOP:
1681 if (pad_monitor->pending_flush_stop_seqnum != GST_SEQNUM_INVALID) {
1682 if (seqnum == pad_monitor->pending_flush_stop_seqnum) {
1683 pad_monitor->pending_flush_stop_seqnum = GST_SEQNUM_INVALID;
1685 GST_VALIDATE_REPORT (pad_monitor, FLUSH_STOP_HAS_WRONG_SEQNUM,
1686 "Got: %u Expected: %u", seqnum,
1687 pad_monitor->pending_flush_stop_seqnum);
1691 pad_monitor->pending_newsegment_seqnum = seqnum;
1692 pad_monitor->pending_eos_seqnum = seqnum;
1694 if (!pad_monitor->pending_flush_stop) {
1695 gchar *event_str = _get_event_string (event);
1697 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_STOP_UNEXPECTED,
1698 "Unexpected flush-stop %s", event_str);
1701 pad_monitor->pending_flush_stop = FALSE;
1703 /* Buffers following a FLUSH should have the DISCONT flag set */
1704 pad_monitor->pending_buffer_discont = TRUE;
1706 /* cleanup our data */
1707 gst_validate_pad_monitor_flush (pad_monitor);
1716 mark_pads_eos (GstValidatePadMonitor * pad_monitor)
1718 GstValidatePadMonitor *peer_monitor;
1721 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1723 GstPad *peer = gst_pad_get_peer (pad);
1725 gst_object_unref (pad);
1726 pad_monitor->is_eos = TRUE;
1728 real_peer = _get_actual_pad (peer);
1729 peer_monitor = _GET_PAD_MONITOR (real_peer);
1731 peer_monitor->is_eos = TRUE;
1732 gst_object_unref (peer);
1733 gst_object_unref (real_peer);
1737 static inline gboolean
1738 _should_check_buffers (GstValidatePadMonitor * pad_monitor,
1739 gboolean force_checks)
1742 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1744 GstValidateMonitor *monitor = GST_VALIDATE_MONITOR (pad_monitor);
1746 if (pad_monitor->first_buffer || force_checks) {
1747 if (pad_monitor->segment.rate != 1.0) {
1748 GST_INFO_OBJECT (pad_monitor, "We do not support buffer checking"
1749 " for trick modes");
1751 pad_monitor->check_buffers = FALSE;
1752 } else if (!PAD_PARENT_IS_DECODER (pad_monitor)) {
1753 GST_DEBUG_OBJECT (pad, "Not on a decoder => no buffer checking");
1755 pad_monitor->check_buffers = FALSE;
1756 } else if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK) {
1757 GST_DEBUG_OBJECT (pad, "Not a sinkpad => no buffer checking");
1759 pad_monitor->check_buffers = FALSE;
1760 } else if (!pad_monitor->caps_is_video) {
1761 GST_DEBUG_OBJECT (pad, "Not working with video => no buffer checking");
1763 pad_monitor->check_buffers = FALSE;
1764 } else if (monitor->media_descriptor == NULL) {
1765 GST_DEBUG_OBJECT (pad, "No media_descriptor set => no buffer checking");
1767 pad_monitor->check_buffers = FALSE;
1768 } else if (!gst_validate_media_descriptor_detects_frames
1769 (monitor->media_descriptor)) {
1770 GST_DEBUG_OBJECT (pad,
1771 "No frame detection media descriptor => no buffer checking");
1772 pad_monitor->check_buffers = FALSE;
1773 } else if (pad_monitor->all_bufs == NULL &&
1774 !gst_validate_media_descriptor_get_buffers (monitor->media_descriptor,
1775 pad, NULL, &pad_monitor->all_bufs)) {
1777 GST_INFO_OBJECT (monitor,
1778 "The MediaInfo is marked as detecting frame, but getting frames"
1779 " from pad %" GST_PTR_FORMAT " did not work (some format conversion"
1780 " might be happening)", pad);
1782 pad_monitor->check_buffers = FALSE;
1784 if (!pad_monitor->current_buf)
1785 pad_monitor->current_buf = pad_monitor->all_bufs;
1786 pad_monitor->check_buffers = TRUE;
1789 gst_object_unref (pad);
1791 return pad_monitor->check_buffers;
1795 gst_validate_monitor_find_next_buffer (GstValidatePadMonitor * pad_monitor)
1798 gboolean passed_start = FALSE;
1800 if (!_should_check_buffers (pad_monitor, TRUE))
1803 for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) {
1804 GstBuffer *cbuf = (GstBuffer *) tmp->data;
1806 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf)
1807 : GST_BUFFER_PTS (cbuf);
1809 if (!GST_CLOCK_TIME_IS_VALID (ts))
1812 if (ts <= pad_monitor->segment.start)
1813 passed_start = TRUE;
1818 if (!GST_BUFFER_FLAG_IS_SET (cbuf, GST_BUFFER_FLAG_DELTA_UNIT)) {
1824 pad_monitor->current_buf = pad_monitor->all_bufs;
1826 pad_monitor->current_buf = tmp;
1829 /* Checks whether a segment is just an update of another,
1830 * That is to say that only the base and offset field differ and all
1831 * other fields are identical */
1833 is_segment_update (GstSegment * a, const GstSegment * b)
1835 /* Note : We never care about the position field, it is only
1836 * used for internal usage by elements */
1837 if (a->rate == b->rate &&
1838 a->applied_rate == b->applied_rate &&
1839 a->format == b->format && a->time == b->time) {
1840 /* Changes in base/offset are considered updates */
1841 /* Updating the end position of a segment is an update */
1842 /* Updating the duration of a segment is an update */
1843 if (a->rate > 0.0) {
1844 if (a->start == b->start)
1847 if (a->stop == b->stop)
1854 static GstFlowReturn
1855 gst_validate_pad_monitor_downstream_event_check (GstValidatePadMonitor *
1856 pad_monitor, GstObject * parent, GstEvent * event,
1857 GstPadEventFunction handler)
1859 GstFlowReturn ret = GST_FLOW_OK;
1860 const GstSegment *segment;
1861 guint32 seqnum = gst_event_get_seqnum (event);
1863 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
1866 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1869 switch (GST_EVENT_TYPE (event)) {
1870 case GST_EVENT_STREAM_START:
1871 /* Buffers following a STREAM_START should have the DISCONT flag set */
1872 pad_monitor->pending_buffer_discont = TRUE;
1874 case GST_EVENT_SEGMENT:
1875 /* parse segment data to be used if event is handled */
1876 gst_event_parse_segment (event, &segment);
1878 GST_DEBUG_OBJECT (pad, "Got segment %" GST_SEGMENT_FORMAT, segment);
1880 /* Reset expected flush start/stop values, we have a segment */
1881 pad_monitor->pending_flush_start_seqnum = GST_SEQNUM_INVALID;
1882 pad_monitor->pending_flush_stop_seqnum = GST_SEQNUM_INVALID;
1884 if (pad_monitor->pending_newsegment_seqnum != GST_SEQNUM_INVALID) {
1885 if (pad_monitor->pending_newsegment_seqnum == seqnum) {
1886 pad_monitor->pending_newsegment_seqnum = GST_SEQNUM_INVALID;
1887 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->pending_seek_accurate_time)) {
1888 if (segment->time == pad_monitor->pending_seek_accurate_time) {
1889 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
1891 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_START,
1892 "After an accurate seek, got: %" GST_TIME_FORMAT
1893 " Expected: %" GST_TIME_FORMAT, GST_TIME_ARGS (segment->time),
1894 GST_TIME_ARGS (pad_monitor->pending_seek_accurate_time));
1898 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_SEQNUM,
1899 "Got: %u Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1903 pad_monitor->pending_eos_seqnum = seqnum;
1905 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1906 gst_validate_pad_monitor_add_expected_newsegment (pad_monitor, event);
1908 /* check if this segment is the expected one */
1909 if (pad_monitor->expected_segment) {
1910 const GstSegment *exp_segment;
1912 if (pad_monitor->expected_segment != event) {
1913 gst_event_parse_segment (pad_monitor->expected_segment,
1915 if (segment->format == exp_segment->format) {
1916 if ((exp_segment->rate * exp_segment->applied_rate !=
1917 segment->rate * segment->applied_rate))
1918 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1919 "Rate * applied_rate %f != expected %f",
1920 segment->rate * segment->applied_rate,
1921 exp_segment->rate * exp_segment->applied_rate);
1922 if (exp_segment->start != segment->start)
1923 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1924 "Start %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
1925 GST_TIME_ARGS (segment->start),
1926 GST_TIME_ARGS (exp_segment->start));
1927 if (exp_segment->stop != segment->stop)
1928 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1929 "Stop %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
1930 GST_TIME_ARGS (segment->stop),
1931 GST_TIME_ARGS (exp_segment->stop));
1932 if (exp_segment->position != segment->position)
1933 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1934 "Position %" GST_TIME_FORMAT " != expected %"
1935 GST_TIME_FORMAT, GST_TIME_ARGS (segment->position),
1936 GST_TIME_ARGS (exp_segment->position));
1939 gst_event_replace (&pad_monitor->expected_segment, NULL);
1943 case GST_EVENT_CAPS:{
1946 gst_event_parse_caps (event, &caps);
1947 gst_validate_pad_monitor_setcaps_pre (pad_monitor, caps);
1951 pad_monitor->is_eos = TRUE;
1952 /* FIXME : This feels and looks wrong ... */
1953 if (pad_monitor->pending_eos_seqnum == GST_SEQNUM_INVALID) {
1954 GST_VALIDATE_REPORT (pad_monitor, EVENT_EOS_WITHOUT_SEGMENT,
1955 "EOS %" GST_PTR_FORMAT " received before a segment was received",
1957 } else if (pad_monitor->pending_eos_seqnum != seqnum) {
1958 GST_VALIDATE_REPORT (pad_monitor, EOS_HAS_WRONG_SEQNUM,
1959 "Got: %u. Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1963 * TODO add end of stream checks for
1964 * - events not pushed
1965 * - buffer data not pushed
1966 * - pending events not received
1970 /* both flushes are handled by the common event function */
1971 case GST_EVENT_FLUSH_START:
1972 case GST_EVENT_FLUSH_STOP:
1974 case GST_EVENT_SINK_MESSAGE:
1979 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1980 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1981 gst_validate_pad_monitor_event_overrides (pad_monitor, event);
1983 gst_event_ref (event);
1984 if (pad_monitor->event_full_func)
1985 ret = pad_monitor->event_full_func (pad, parent, event);
1986 else if (pad_monitor->event_func (pad, parent, event))
1989 ret = GST_FLOW_ERROR;
1991 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1992 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1995 switch (GST_EVENT_TYPE (event)) {
1996 case GST_EVENT_SEGMENT:
1997 if (ret == GST_FLOW_OK) {
1998 /* If the new segment is not an update of the previous one, then
1999 * the following buffer should have the DISCONT flag set */
2000 if (!is_segment_update (&pad_monitor->segment, segment))
2001 pad_monitor->pending_buffer_discont = TRUE;
2002 if (!pad_monitor->has_segment
2003 && pad_monitor->segment.format != segment->format) {
2004 gst_segment_init (&pad_monitor->segment, segment->format);
2006 gst_segment_copy_into (segment, &pad_monitor->segment);
2007 pad_monitor->has_segment = TRUE;
2008 gst_validate_monitor_find_next_buffer (pad_monitor);
2011 case GST_EVENT_CAPS:{
2014 gst_event_parse_caps (event, &caps);
2015 gst_validate_pad_monitor_setcaps_post (pad_monitor, caps,
2016 ret == GST_FLOW_OK);
2019 case GST_EVENT_FLUSH_START:
2020 case GST_EVENT_FLUSH_STOP:
2023 case GST_EVENT_SINK_MESSAGE:
2029 gst_event_unref (event);
2030 gst_object_unref (pad);
2035 gst_validate_pad_monitor_src_event_check (GstValidatePadMonitor * pad_monitor,
2036 GstObject * parent, GstEvent * event, GstPadEventFunction handler)
2038 gboolean ret = TRUE;
2042 GstSeekFlags seek_flags;
2043 GstSeekType start_type, stop_type;
2044 guint32 seqnum = gst_event_get_seqnum (event);
2046 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2049 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
2052 switch (GST_EVENT_TYPE (event)) {
2053 case GST_EVENT_SEEK:
2055 gst_event_parse_seek (event, &rate, &format, &seek_flags, &start_type,
2056 &start, &stop_type, &stop);
2057 /* upstream seek - store the seek event seqnum to check
2058 * flushes and newsegments share the same */
2061 /* both flushes are handled by the common event handling function */
2062 case GST_EVENT_FLUSH_START:
2063 case GST_EVENT_FLUSH_STOP:
2064 case GST_EVENT_NAVIGATION:
2065 case GST_EVENT_LATENCY:
2066 case GST_EVENT_STEP:
2073 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2074 /* Safely store pending accurate seek values */
2075 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
2076 if (seek_flags & GST_SEEK_FLAG_ACCURATE) {
2077 GST_DEBUG_OBJECT (pad,
2078 "Storing expected accurate seek time %" GST_TIME_FORMAT,
2079 GST_TIME_ARGS (start));
2080 pad_monitor->pending_seek_accurate_time = start;
2082 /* TODO we might need to use a list as multiple seeks can be sent
2083 * before the flushes arrive here */
2084 if (seek_flags & GST_SEEK_FLAG_FLUSH) {
2085 pad_monitor->pending_flush_start_seqnum = seqnum;
2086 pad_monitor->pending_flush_stop_seqnum = seqnum;
2090 gst_event_ref (event);
2091 ret = pad_monitor->event_func (pad, parent, event);
2093 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
2094 /* If the seek was already handled (same current seqnum), reset the
2095 * expected accurate seek value */
2096 if (ret && pad_monitor->has_segment
2097 && seqnum == pad_monitor->pending_eos_seqnum) {
2098 GST_DEBUG_OBJECT (pad,
2099 "Resetting expected accurate seek value, was already handled");
2100 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
2102 /* do not expect any of these events anymore */
2103 pad_monitor->pending_flush_start_seqnum = GST_SEQNUM_INVALID;
2104 pad_monitor->pending_flush_stop_seqnum = GST_SEQNUM_INVALID;
2105 pad_monitor->pending_newsegment_seqnum = GST_SEQNUM_INVALID;
2106 pad_monitor->pending_eos_seqnum = GST_SEQNUM_INVALID;
2107 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
2110 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2114 switch (GST_EVENT_TYPE (event)) {
2115 case GST_EVENT_FLUSH_START:
2116 case GST_EVENT_FLUSH_STOP:
2118 case GST_EVENT_SEEK:
2119 case GST_EVENT_NAVIGATION:
2120 case GST_EVENT_LATENCY:
2121 case GST_EVENT_STEP:
2127 gst_event_unref (event);
2128 gst_object_unref (pad);
2133 gst_validate_pad_monitor_check_right_buffer (GstValidatePadMonitor *
2134 pad_monitor, GstBuffer * buffer)
2137 GstBuffer *wanted_buf;
2138 GstMapInfo map, wanted_map;
2140 gboolean ret = TRUE;
2144 if (_should_check_buffers (pad_monitor, FALSE) == FALSE)
2148 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2150 if (pad_monitor->current_buf == NULL) {
2151 GST_INFO_OBJECT (pad, "No current buffer one pad, Why?");
2152 gst_object_unref (pad);
2156 wanted_buf = pad_monitor->current_buf->data;
2158 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (wanted_buf)) &&
2159 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buffer)) &&
2160 GST_BUFFER_PTS (wanted_buf) != GST_BUFFER_PTS (buffer)) {
2162 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2163 "buffer %" GST_PTR_FORMAT " PTS %" GST_TIME_FORMAT
2164 " different than expected: %" GST_TIME_FORMAT, buffer,
2165 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
2166 GST_TIME_ARGS (GST_BUFFER_PTS (wanted_buf)));
2171 if (GST_BUFFER_DTS (wanted_buf) != GST_BUFFER_DTS (buffer)) {
2172 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2173 "buffer %" GST_PTR_FORMAT " DTS %" GST_TIME_FORMAT
2174 " different than expected: %" GST_TIME_FORMAT, buffer,
2175 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
2176 GST_TIME_ARGS (GST_BUFFER_DTS (wanted_buf)));
2180 if (GST_BUFFER_DURATION (wanted_buf) != GST_BUFFER_DURATION (buffer)) {
2181 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2182 "buffer %" GST_PTR_FORMAT " DURATION %" GST_TIME_FORMAT
2183 " different than expected: %" GST_TIME_FORMAT, buffer,
2184 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2185 GST_TIME_ARGS (GST_BUFFER_DURATION (wanted_buf)));
2189 if (GST_BUFFER_FLAG_IS_SET (wanted_buf, GST_BUFFER_FLAG_DELTA_UNIT) !=
2190 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
2191 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2192 "buffer %" GST_PTR_FORMAT " Delta unit is set to %s but expected %s",
2193 buffer, GST_BUFFER_FLAG_IS_SET (buffer,
2194 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False",
2195 GST_BUFFER_FLAG_IS_SET (wanted_buf,
2196 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False");
2200 g_assert (gst_buffer_map (wanted_buf, &wanted_map, GST_MAP_READ));
2201 g_assert (gst_buffer_map (buffer, &map, GST_MAP_READ));
2203 checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
2204 (const guchar *) map.data, map.size);
2206 if (g_strcmp0 ((gchar *) wanted_map.data, checksum)) {
2207 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2208 "buffer %" GST_PTR_FORMAT " checksum %s different from expected: %s",
2209 buffer, checksum, wanted_map.data);
2213 gst_buffer_unmap (wanted_buf, &wanted_map);
2214 gst_buffer_unmap (buffer, &map);
2216 gst_object_unref (pad);
2218 pad_monitor->current_buf = pad_monitor->current_buf->next;
2224 gst_validate_pad_monitor_check_return (GstValidatePadMonitor * pad_monitor,
2227 GstValidateMonitor *parent = GST_VALIDATE_MONITOR (pad_monitor);
2229 if (ret != GST_FLOW_ERROR)
2232 while (GST_VALIDATE_MONITOR_GET_PARENT (parent))
2233 parent = GST_VALIDATE_MONITOR_GET_PARENT (parent);
2235 if (GST_IS_VALIDATE_PIPELINE_MONITOR (parent)) {
2236 GstValidatePipelineMonitor *m = GST_VALIDATE_PIPELINE_MONITOR (parent);
2238 GST_VALIDATE_MONITOR_LOCK (m);
2239 if (m->got_error == FALSE) {
2240 GST_VALIDATE_REPORT (pad_monitor, FLOW_ERROR_WITHOUT_ERROR_MESSAGE,
2241 "Pad return GST_FLOW_ERROR but no GST_MESSAGE_ERROR was received on"
2244 /* Only report it the first time */
2245 m->got_error = TRUE;
2247 GST_VALIDATE_MONITOR_UNLOCK (m);
2251 static GstFlowReturn
2252 gst_validate_pad_monitor_chain_func (GstPad * pad, GstObject * parent,
2255 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2258 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2259 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2261 gst_validate_pad_monitor_check_discont (pad_monitor, buffer);
2262 gst_validate_pad_monitor_check_right_buffer (pad_monitor, buffer);
2263 gst_validate_pad_monitor_check_first_buffer (pad_monitor, buffer);
2264 gst_validate_pad_monitor_update_buffer_data (pad_monitor, buffer);
2265 gst_validate_pad_monitor_check_eos (pad_monitor, buffer);
2267 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2268 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2270 gst_validate_pad_monitor_buffer_overrides (pad_monitor, buffer);
2272 ret = pad_monitor->chain_func (pad, parent, buffer);
2274 gst_validate_pad_monitor_check_return (pad_monitor, ret);
2276 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2277 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2279 pad_monitor->last_flow_return = ret;
2280 if (ret == GST_FLOW_EOS) {
2281 mark_pads_eos (pad_monitor);
2283 if (PAD_PARENT_IS_DEMUXER (pad_monitor))
2284 gst_validate_pad_monitor_check_aggregated_return (pad_monitor, parent, ret);
2286 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2287 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2293 gst_validate_pad_monitor_event_is_tracked (GstValidatePadMonitor * monitor,
2296 if (!GST_EVENT_IS_SERIALIZED (event)) {
2300 /* we don't track Tag events because they mutate too much and it is hard
2301 * to match a tag event pushed on a source pad with the one that was received
2303 * One idea would be to use seqnum, but it seems that it is undefined whether
2304 * seqnums should be maintained in tag events that are created from others
2305 * up to today. (2013-08-29)
2307 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
2313 static GstFlowReturn
2314 gst_validate_pad_monitor_sink_event_full_func (GstPad * pad, GstObject * parent,
2317 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2320 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2321 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2323 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
2325 if (gst_validate_pad_monitor_event_is_tracked (pad_monitor, event)) {
2326 GstClockTime last_ts = GST_CLOCK_TIME_NONE;
2327 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_timestamp)) {
2328 last_ts = pad_monitor->current_timestamp;
2329 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_duration)) {
2330 last_ts += pad_monitor->current_duration;
2333 gst_validate_pad_monitor_otherpad_add_pending_serialized_event (pad_monitor,
2338 gst_validate_pad_monitor_downstream_event_check (pad_monitor, parent,
2339 event, pad_monitor->event_func);
2341 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2342 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2347 gst_validate_pad_monitor_sink_event_func (GstPad * pad, GstObject * parent,
2350 if (gst_validate_pad_monitor_sink_event_full_func (pad, parent,
2351 event) == GST_FLOW_OK)
2357 gst_validate_pad_monitor_src_event_func (GstPad * pad, GstObject * parent,
2360 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2363 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2364 ret = gst_validate_pad_monitor_src_event_check (pad_monitor, parent, event,
2365 pad_monitor->event_func);
2366 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2371 gst_validate_pad_monitor_query_func (GstPad * pad, GstObject * parent,
2374 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2377 gst_validate_pad_monitor_query_overrides (pad_monitor, query);
2378 ret = pad_monitor->query_func (pad, parent, query);
2381 switch (GST_QUERY_TYPE (query)) {
2382 case GST_QUERY_ACCEPT_CAPS:
2386 gst_caps_replace (&pad_monitor->last_refused_caps, NULL);
2387 gst_query_parse_accept_caps_result (query, &result);
2389 GstCaps *refused_caps;
2391 gst_query_parse_accept_caps (query, &refused_caps);
2392 pad_monitor->last_refused_caps = gst_caps_copy (refused_caps);
2398 case GST_QUERY_CAPS:{
2402 /* We shouldn't need to lock the parent as this doesn't modify
2403 * other monitors, just does some peer_pad_caps */
2404 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2406 gst_query_parse_caps (query, &filter);
2407 gst_query_parse_caps_result (query, &res);
2409 gst_caps_replace (&pad_monitor->last_query_res, NULL);
2410 gst_caps_replace (&pad_monitor->last_query_filter, NULL);
2411 pad_monitor->last_query_res =
2412 res ? gst_caps_copy (res) : gst_caps_ref (GST_CAPS_NONE);
2413 pad_monitor->last_query_filter =
2414 filter ? gst_caps_copy (filter) : gst_caps_ref (GST_CAPS_NONE);
2416 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2417 gst_validate_pad_monitor_check_caps_fields_proxied (pad_monitor, res,
2420 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2432 gst_validate_pad_monitor_activatemode_func (GstPad * pad, GstObject * parent,
2433 GstPadMode mode, gboolean active)
2435 GstValidatePadMonitor *pad_monitor = _GET_PAD_MONITOR (pad);
2436 gboolean ret = TRUE;
2438 /* TODO add overrides for activate func */
2439 GST_DEBUG_OBJECT (pad, "active:%d", active);
2441 if (pad_monitor->activatemode_func)
2442 ret = pad_monitor->activatemode_func (pad, parent, mode, active);
2443 if (ret && active == FALSE) {
2444 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2445 gst_validate_pad_monitor_reset (pad_monitor);
2446 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2452 /* The interval between two buffer frequency checks */
2453 #define BUF_FREQ_CHECK_INTERVAL (GST_SECOND)
2456 gst_validate_pad_monitor_check_buffer_freq (GstValidatePadMonitor * monitor,
2461 if (!GST_PAD_IS_SRC (pad))
2464 if (!monitor->min_buf_freq)
2467 ts = gst_util_get_timestamp ();
2468 monitor->buffers_pushed++;
2470 /* Same logic as in fpsdisplaysink to compute the buffer frequency */
2471 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID
2472 (monitor->min_buf_freq_first_buffer_ts))) {
2473 monitor->min_buf_freq_first_buffer_ts = ts;
2474 monitor->min_buf_freq_interval_ts = ts;
2478 if (GST_CLOCK_DIFF (monitor->min_buf_freq_interval_ts,
2479 ts) > BUF_FREQ_CHECK_INTERVAL) {
2483 time_diff = (gdouble) (ts - monitor->min_buf_freq_interval_ts) / GST_SECOND;
2485 (gdouble) (monitor->buffers_pushed -
2486 monitor->last_buffers_pushed) / time_diff;
2488 if (fps < monitor->min_buf_freq) {
2489 if (GST_CLOCK_TIME_IS_VALID (monitor->min_buf_freq_start) &&
2490 GST_CLOCK_DIFF (monitor->min_buf_freq_first_buffer_ts,
2491 ts) < monitor->min_buf_freq_start) {
2492 GST_DEBUG_OBJECT (pad,
2493 "buffer frequency is too low (%.2f) but ignore for now (buffer-frequency-start =%"
2494 GST_TIME_FORMAT ")", fps,
2495 GST_TIME_ARGS (monitor->min_buf_freq_start));
2497 GST_VALIDATE_REPORT (monitor, CONFIG_BUFFER_FREQUENCY_TOO_LOW,
2498 "Buffers are not pushed fast enough on this pad: %.2f/sec (minimum: %.2f)",
2499 fps, monitor->min_buf_freq);
2503 monitor->last_buffers_pushed = monitor->buffers_pushed;
2504 monitor->min_buf_freq_interval_ts = ts;
2509 gst_validate_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
2510 gpointer udata, gboolean pull_mode)
2512 GstValidatePadMonitor *monitor = udata;
2514 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2515 GST_VALIDATE_MONITOR_LOCK (monitor);
2518 gst_validate_pad_monitor_check_discont (monitor, buffer);
2519 gst_validate_pad_monitor_check_first_buffer (monitor, buffer);
2520 gst_validate_pad_monitor_update_buffer_data (monitor, buffer);
2521 gst_validate_pad_monitor_check_eos (monitor, buffer);
2523 if (PAD_PARENT_IS_DECODER (monitor) || PAD_PARENT_IS_ENCODER (monitor)) {
2524 GstClockTime tolerance = 0;
2526 if (monitor->caps_is_audio)
2527 tolerance = AUDIO_TIMESTAMP_TOLERANCE;
2529 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range (monitor,
2533 gst_validate_pad_monitor_check_late_serialized_events (monitor,
2534 GST_BUFFER_TIMESTAMP (buffer));
2536 /* a GstValidatePadMonitor parent must be a GstValidateElementMonitor */
2537 if (PAD_PARENT_IS_DECODER (monitor)) {
2539 /* should not push out of segment data */
2540 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
2541 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)) &&
2542 ((!gst_segment_clip (&monitor->segment, monitor->segment.format,
2543 GST_BUFFER_TIMESTAMP (buffer),
2544 GST_BUFFER_TIMESTAMP (buffer) +
2545 GST_BUFFER_DURATION (buffer), NULL, NULL)) ||
2546 /* In the case of raw data, buffers should be strictly contained inside the
2548 (monitor->caps_is_raw &&
2549 GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer) <
2550 monitor->segment.start))
2552 /* TODO is this a timestamp issue? */
2553 GST_VALIDATE_REPORT (monitor, BUFFER_IS_OUT_OF_SEGMENT,
2554 "buffer is out of segment and shouldn't be pushed. Timestamp: %"
2555 GST_TIME_FORMAT " - Duration: %" GST_TIME_FORMAT ". Range: %"
2556 GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
2557 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
2558 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2559 GST_TIME_ARGS (monitor->segment.start),
2560 GST_TIME_ARGS (monitor->segment.stop));
2564 gst_validate_pad_monitor_check_buffer_freq (monitor, pad);
2566 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2567 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2568 gst_validate_pad_monitor_buffer_probe_overrides (monitor, buffer);
2573 gst_validate_pad_monitor_event_probe (GstPad * pad, GstEvent * event,
2576 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (udata);
2578 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2579 GST_VALIDATE_MONITOR_LOCK (monitor);
2581 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
2583 if (GST_EVENT_IS_SERIALIZED (event)) {
2586 /* Detect if events the element received are being forwarded in the same order
2588 * Several scenarios:
2589 * 1) The element pushes the event as-is
2590 * 2) The element consumes the event and does not forward it
2591 * 3) The element consumes the event and creates another one instead
2592 * 4) The element pushes other serialized event before pushing out the
2595 * For each pad we have two lists to track serialized events:
2596 * 1) We received on input and expect to see (serialized_events)
2597 * 2) We received on input but don't expect to see (expired_events)
2599 * To detect events that are pushed in a different order from the one they were
2600 * received in we check that:
2602 * For each event being outputted:
2603 * If it is in the expired_events list:
2605 * If it is in the serialized_events list:
2606 * If there are other events that were received before:
2607 * Put those events on the expired_events list
2608 * Remove that event and any previous ones from the serialized_events list
2610 * Clear expired events list when flushing or on pad deactivation
2614 if (g_list_find (monitor->expired_events, event)) {
2615 gchar *event_str = _get_event_string (event);
2616 /* If it's the expired events, we've failed */
2617 GST_WARNING_OBJECT (pad, "Did not expect event %p %s", event,
2618 GST_EVENT_TYPE_NAME (event));
2619 GST_VALIDATE_REPORT (monitor, EVENT_SERIALIZED_OUT_OF_ORDER,
2620 "Serialized event was pushed out of order: %s", event_str);
2623 monitor->expired_events = g_list_remove (monitor->expired_events, event);
2624 gst_event_unref (event); /* remove the ref that was on the list */
2625 } else if (monitor->serialized_events->len) {
2626 for (i = 0; i < monitor->serialized_events->len; i++) {
2627 SerializedEventData *next_event =
2628 g_ptr_array_index (monitor->serialized_events, i);
2629 GST_DEBUG_OBJECT (pad, "Checking against stored event #%d: %p %s", i,
2630 next_event->event, GST_EVENT_TYPE_NAME (next_event->event));
2632 if (event == next_event->event
2633 || GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2634 /* We have found our event */
2635 GST_DEBUG_OBJECT (pad, "Found matching event");
2637 while (monitor->serialized_events->len > i
2638 && GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2639 /* Swallow all expected events of the same type */
2640 g_ptr_array_remove_index (monitor->serialized_events, i);
2641 next_event = g_ptr_array_index (monitor->serialized_events, i);
2644 /* Move all previous events to expired events */
2645 if (G_UNLIKELY (i > 0)) {
2646 GST_DEBUG_OBJECT (pad,
2647 "Moving previous expected events to expired list");
2649 next_event = g_ptr_array_index (monitor->serialized_events, 0);
2650 monitor->expired_events =
2651 g_list_append (monitor->expired_events,
2652 gst_event_ref (next_event->event));
2653 g_ptr_array_remove_index (monitor->serialized_events, 0);
2656 debug_pending_event (pad, monitor->serialized_events);
2663 /* This so far is just like an event that is flowing downstream,
2664 * so we do the same checks as a sinkpad event handler */
2665 gst_validate_pad_monitor_downstream_event_check (monitor, NULL, event, NULL);
2666 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2667 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2670 static GstPadProbeReturn
2671 gst_validate_pad_monitor_pad_probe (GstPad * pad, GstPadProbeInfo * info,
2674 if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
2675 gst_validate_pad_monitor_buffer_probe (pad, info->data, udata,
2676 GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_PULL);
2677 else if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
2678 gst_validate_pad_monitor_event_probe (pad, info->data, udata);
2680 return GST_PAD_PROBE_OK;
2684 gst_validate_pad_monitor_update_caps_info (GstValidatePadMonitor * pad_monitor,
2687 GstStructure *structure;
2689 g_return_if_fail (gst_caps_is_fixed (caps));
2691 pad_monitor->caps_is_audio = FALSE;
2692 pad_monitor->caps_is_video = FALSE;
2694 structure = gst_caps_get_structure (caps, 0);
2695 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/")) {
2696 pad_monitor->caps_is_audio = TRUE;
2697 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/")) {
2698 pad_monitor->caps_is_video = TRUE;
2701 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/x-raw") ||
2702 g_str_has_prefix (gst_structure_get_name (structure), "video/x-raw")) {
2703 pad_monitor->caps_is_raw = TRUE;
2705 pad_monitor->caps_is_raw = FALSE;
2710 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
2713 GstStructure *structure;
2715 GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
2718 /* Check if caps are identical to last caps and complain if so
2719 * Only checked for sink pads as src pads might push the same caps
2720 * multiple times during unlinked/autoplugging scenarios */
2721 if (GST_PAD_IS_SINK (pad) && pad_monitor->last_caps
2722 && gst_caps_is_equal (caps, pad_monitor->last_caps)) {
2723 gchar *caps_str = gst_caps_to_string (caps);
2725 GST_VALIDATE_REPORT (pad_monitor, EVENT_CAPS_DUPLICATE, "%s", caps_str);
2730 gst_validate_pad_monitor_check_caps_complete (pad_monitor, caps);
2733 structure = gst_caps_get_structure (caps, 0);
2734 if (gst_structure_n_fields (pad_monitor->pending_setcaps_fields)) {
2737 i < gst_structure_n_fields (pad_monitor->pending_setcaps_fields);
2740 gst_structure_nth_field_name (pad_monitor->pending_setcaps_fields,
2742 const GValue *v = gst_structure_get_value (structure, name);
2743 const GValue *otherv =
2744 gst_structure_get_value (pad_monitor->pending_setcaps_fields, name);
2747 gchar *caps_str = gst_caps_to_string (caps);
2749 GST_VALIDATE_REPORT (pad_monitor, CAPS_EXPECTED_FIELD_NOT_FOUND,
2750 "Field %s is missing from setcaps caps '%s'", name, caps_str);
2752 } else if (gst_value_compare (v, otherv) != GST_VALUE_EQUAL) {
2753 gchar *caps_str = gst_caps_to_string (caps),
2754 *pending_setcaps_fields_str =
2755 gst_structure_to_string (pad_monitor->pending_setcaps_fields);
2758 GST_VALIDATE_REPORT (pad_monitor, CAPS_FIELD_UNEXPECTED_VALUE,
2759 "Field %s from setcaps caps '%s' is different "
2760 "from expected value in caps '%s'", name, caps_str,
2761 pending_setcaps_fields_str);
2763 g_free (pending_setcaps_fields_str);
2769 if (GST_PAD_IS_SINK (pad) &&
2770 gst_validate_pad_monitor_pad_should_proxy_othercaps (pad_monitor)) {
2771 if (_structure_is_video (structure)) {
2772 GST_DEBUG_OBJECT (pad,
2773 "Adding video common pending fields to other pad: %" GST_PTR_FORMAT,
2775 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2776 structure, "width");
2777 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2778 structure, "height");
2779 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2780 structure, "framerate");
2781 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2782 structure, "pixel-aspect-ratio");
2783 } else if (_structure_is_audio (structure)) {
2784 GST_DEBUG_OBJECT (pad,
2785 "Adding audio common pending fields to other pad: %" GST_PTR_FORMAT,
2787 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2789 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2790 structure, "channels");
2795 gst_structure_free (pad_monitor->pending_setcaps_fields);
2796 pad_monitor->pending_setcaps_fields =
2797 gst_structure_new_empty (PENDING_FIELDS);
2798 gst_object_unref (pad);
2800 gst_validate_pad_monitor_setcaps_overrides (pad_monitor, caps);
2804 gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor * pad_monitor,
2805 GstCaps * caps, gboolean ret)
2808 gst_validate_pad_monitor_otherpad_clear_pending_fields (pad_monitor);
2810 if (pad_monitor->last_caps) {
2811 gst_caps_unref (pad_monitor->last_caps);
2813 pad_monitor->last_caps = gst_caps_ref (caps);
2814 gst_validate_pad_monitor_update_caps_info (pad_monitor, caps);
2819 gst_validate_pad_monitor_get_min_buffer_frequency (GstValidatePadMonitor *
2820 monitor, GstPad * pad)
2824 if (!GST_PAD_IS_SRC (pad))
2827 config = gst_validate_plugin_get_config (NULL);
2828 for (l = config; l != NULL; l = g_list_next (l)) {
2829 GstStructure *s = l->data;
2830 gdouble min_buf_freq;
2831 const gchar *pad_name;
2832 GstElement *element = NULL;
2834 if (!gst_structure_get_double (s, "min-buffer-frequency", &min_buf_freq)) {
2837 if (!gst_structure_get_int (s, "min-buffer-frequency", &max_int))
2840 min_buf_freq = max_int;
2843 pad_name = gst_structure_get_string (s, "name");
2847 if (g_strcmp0 (GST_PAD_NAME (pad), pad_name))
2850 element = gst_pad_get_parent_element (pad);
2852 if (!gst_validate_element_matches_target (element, s))
2855 monitor->min_buf_freq = min_buf_freq;
2857 gst_validate_utils_get_clocktime (s, "buffer-frequency-start",
2858 &monitor->min_buf_freq_start);
2860 GST_DEBUG_OBJECT (pad, "pad has a minimum buffer frequency of %f",
2863 g_clear_object (&element);
2868 gst_validate_pad_monitor_do_setup (GstValidateMonitor * monitor)
2870 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR_CAST (monitor);
2871 GstPad *pad = (gpointer) gst_validate_monitor_get_target (monitor);
2873 if (!GST_IS_PAD (pad)) {
2874 GST_WARNING_OBJECT (monitor, "Trying to create pad monitor with other "
2876 gst_object_unref (pad);
2880 if (_GET_PAD_MONITOR (pad)) {
2881 GST_WARNING_OBJECT (pad_monitor,
2882 "Pad already has a validate-monitor associated");
2883 gst_object_unref (pad);
2887 _SET_PAD_MONITOR (pad, pad_monitor);
2889 pad_monitor->event_func = GST_PAD_EVENTFUNC (pad);
2890 pad_monitor->event_full_func = GST_PAD_EVENTFULLFUNC (pad);
2891 pad_monitor->query_func = GST_PAD_QUERYFUNC (pad);
2892 pad_monitor->activatemode_func = GST_PAD_ACTIVATEMODEFUNC (pad);
2893 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2895 pad_monitor->chain_func = GST_PAD_CHAINFUNC (pad);
2896 if (pad_monitor->chain_func)
2897 gst_pad_set_chain_function (pad, gst_validate_pad_monitor_chain_func);
2899 if (pad_monitor->event_full_func)
2900 gst_pad_set_event_full_function (pad,
2901 gst_validate_pad_monitor_sink_event_full_func);
2903 gst_pad_set_event_function (pad,
2904 gst_validate_pad_monitor_sink_event_func);
2906 gst_pad_set_event_function (pad, gst_validate_pad_monitor_src_event_func);
2908 /* add buffer/event probes */
2909 pad_monitor->pad_probe_id =
2910 gst_pad_add_probe (pad,
2911 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
2912 GST_PAD_PROBE_TYPE_EVENT_FLUSH,
2913 (GstPadProbeCallback) gst_validate_pad_monitor_pad_probe, pad_monitor,
2916 gst_pad_set_query_function (pad, gst_validate_pad_monitor_query_func);
2917 gst_pad_set_activatemode_function (pad,
2918 gst_validate_pad_monitor_activatemode_func);
2920 gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (monitor),
2921 g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad)));
2923 if (G_UNLIKELY (GST_PAD_PARENT (pad) == NULL))
2924 GST_FIXME ("Saw a pad not belonging to any object");
2926 gst_validate_pad_monitor_get_min_buffer_frequency (pad_monitor, pad);
2928 gst_object_unref (pad);