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"
37 * SECTION:gst-validate-pad-monitor
38 * @short_description: Class that wraps a #GstPad for Validate checks
43 static GstValidateInterceptionReturn
44 gst_validate_pad_monitor_intercept_report (GstValidateReporter * reporter,
45 GstValidateReport * report);
48 G_IMPLEMENT_INTERFACE (GST_TYPE_VALIDATE_REPORTER, _reporter_iface_init)
51 _reporter_iface_init (GstValidateReporterInterface * iface)
53 iface->intercept_report = gst_validate_pad_monitor_intercept_report;
56 #define gst_validate_pad_monitor_parent_class parent_class
57 G_DEFINE_TYPE_WITH_CODE (GstValidatePadMonitor, gst_validate_pad_monitor,
58 GST_TYPE_VALIDATE_MONITOR, _do_init);
60 #define PENDING_FIELDS "pending-fields"
61 #define AUDIO_TIMESTAMP_TOLERANCE (GST_MSECOND * 100)
63 #define PAD_PARENT_IS_DEMUXER(m) \
64 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
65 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DEMUXER ( \
66 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
69 #define PAD_PARENT_IS_DECODER(m) \
70 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
71 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER ( \
72 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
75 #define PAD_PARENT_IS_ENCODER(m) \
76 (GST_VALIDATE_MONITOR_GET_PARENT(m) ? \
77 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER ( \
78 GST_VALIDATE_MONITOR_GET_PARENT(m)) : \
83 * Locking the parent should always be done before locking the
84 * pad-monitor to prevent deadlocks in case another monitor from
85 * another pad on the same element starts an operation that also
86 * requires locking itself and some other monitors from internally
90 * An element has a sink and a src pad. Some test starts running at sinkpad
91 * and it locks the parent, and then it locks itself. In case it needs to get
92 * some information from the srcpad, it is able to lock the srcpad and get it
93 * because the srcpad should never lock itself before locking the parent (which
94 * it won't be able as sinkpad already locked it).
96 * As a side one, it is possible that srcpad locks itself without locking the
97 * parent in case it wants to do a check that won't need to use other internally
98 * linked pads (sinkpad). But in this case it might lock and unlock freely without
101 #define GST_VALIDATE_PAD_MONITOR_PARENT_LOCK(m) \
103 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
104 GST_VALIDATE_MONITOR_LOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
106 GST_WARNING_OBJECT (m, "No parent found, can't lock"); \
110 #define GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK(m) \
112 if (G_LIKELY (GST_VALIDATE_MONITOR_GET_PARENT (m))) { \
113 GST_VALIDATE_MONITOR_UNLOCK (GST_VALIDATE_MONITOR_GET_PARENT (m)); \
115 GST_WARNING_OBJECT (m, "No parent found, can't unlock"); \
121 GstClockTime timestamp;
123 } SerializedEventData;
126 _get_actual_pad (GstPad * pad)
130 gst_object_ref (pad);
132 /* We don't monitor ghost pads */
133 while (GST_IS_GHOST_PAD (pad)) {
135 pad = gst_ghost_pad_get_target ((GstGhostPad *) pad);
136 gst_object_unref (tmp_pad);
139 while (GST_IS_PROXY_PAD (pad)) {
141 pad = gst_pad_get_peer (pad);
142 gst_object_unref (tmp_pad);
149 _find_master_report_on_pad (GstPad * pad, GstValidateReport * report)
151 GstValidatePadMonitor *pad_monitor;
152 GstValidateReport *prev_report;
153 gboolean result = FALSE;
154 GstPad *tmppad = pad;
156 pad = _get_actual_pad (pad);
158 GST_ERROR_OBJECT (tmppad, "Does not have a target yet");
163 pad_monitor = g_object_get_data ((GObject *) pad, "validate-monitor");
165 /* For some reason this pad isn't monitored */
166 if (pad_monitor == NULL)
169 prev_report = gst_validate_reporter_get_report ((GstValidateReporter *)
170 pad_monitor, report->issue->issue_id);
173 if (prev_report->master_report)
174 result = gst_validate_report_set_master_report (report,
175 prev_report->master_report);
177 result = gst_validate_report_set_master_report (report, prev_report);
181 gst_object_unref (pad);
187 _find_master_report_for_sink_pad (GstValidatePadMonitor * pad_monitor,
188 GstValidateReport * report)
191 gboolean result = FALSE;
193 peerpad = gst_pad_get_peer (pad_monitor->pad);
195 /* If the peer src pad already has a similar report no need to look
197 if (peerpad && _find_master_report_on_pad (peerpad, report))
201 gst_object_unref (peerpad);
207 _find_master_report_for_src_pad (GstValidatePadMonitor * pad_monitor,
208 GstValidateReport * report)
213 gboolean result = FALSE;
216 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
220 GValue value = { 0, };
221 switch (gst_iterator_next (iter, &value)) {
222 case GST_ITERATOR_OK:
223 pad = g_value_get_object (&value);
225 if (_find_master_report_on_pad (pad, report)) {
230 g_value_reset (&value);
232 case GST_ITERATOR_RESYNC:
233 gst_iterator_resync (iter);
235 case GST_ITERATOR_ERROR:
236 GST_WARNING_OBJECT (pad_monitor->pad,
237 "Internal links pad iteration error");
240 case GST_ITERATOR_DONE:
245 gst_iterator_free (iter);
250 static GstValidateInterceptionReturn
251 _concatenate_issues (GstValidatePadMonitor * pad_monitor,
252 GstValidateReport * report)
254 if (GST_PAD_IS_SINK (pad_monitor->pad)
255 && _find_master_report_for_sink_pad (pad_monitor, report))
256 return GST_VALIDATE_REPORTER_KEEP;
257 else if (GST_PAD_IS_SRC (pad_monitor->pad)
258 && _find_master_report_for_src_pad (pad_monitor, report))
259 return GST_VALIDATE_REPORTER_KEEP;
261 return GST_VALIDATE_REPORTER_REPORT;
264 static GstValidateInterceptionReturn
265 gst_validate_pad_monitor_intercept_report (GstValidateReporter *
266 reporter, GstValidateReport * report)
268 GstValidateReporterInterface *iface_class, *old_iface_class;
269 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR (reporter);
270 GstValidateReportingDetails monitor_reporting_level;
271 GstValidateInterceptionReturn ret;
273 monitor_reporting_level =
274 gst_validate_reporter_get_reporting_level (reporter);
277 G_TYPE_INSTANCE_GET_INTERFACE (reporter, GST_TYPE_VALIDATE_REPORTER,
278 GstValidateReporterInterface);
279 old_iface_class = g_type_interface_peek_parent (iface_class);
281 old_iface_class->intercept_report (reporter, report);
283 switch (monitor_reporting_level) {
284 case GST_VALIDATE_SHOW_NONE:
285 ret = GST_VALIDATE_REPORTER_DROP;
287 case GST_VALIDATE_SHOW_UNKNOWN:
288 ret = _concatenate_issues (pad_monitor, report);
291 ret = GST_VALIDATE_REPORTER_REPORT;
295 gst_validate_report_set_reporting_level (report, monitor_reporting_level);
300 debug_pending_event (GstPad * pad, GPtrArray * array)
305 for (i = 0; i < len; i++) {
306 SerializedEventData *data = g_ptr_array_index (array, i);
307 GST_DEBUG_OBJECT (pad, "event #%d %" GST_TIME_FORMAT " %s %p",
308 i, GST_TIME_ARGS (data->timestamp),
309 GST_EVENT_TYPE_NAME (data->event), data->event);
314 _serialized_event_data_free (SerializedEventData * serialized_event)
316 gst_event_unref (serialized_event->event);
317 g_slice_free (SerializedEventData, serialized_event);
320 static gboolean gst_validate_pad_monitor_do_setup (GstValidateMonitor *
322 static GstElement *gst_validate_pad_monitor_get_element (GstValidateMonitor *
325 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
327 static void gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor *
328 pad_monitor, GstCaps * caps, gboolean ret);
330 #define PAD_IS_IN_PUSH_MODE(p) ((p)->mode == GST_PAD_MODE_PUSH)
333 _structure_is_raw_video (GstStructure * structure)
335 return gst_structure_has_name (structure, "video/x-raw");
339 _structure_is_raw_audio (GstStructure * structure)
341 return gst_structure_has_name (structure, "audio/x-raw");
345 _get_event_string (GstEvent * event)
347 const GstStructure *st;
349 if ((st = gst_event_get_structure (event)))
350 return gst_structure_to_string (st);
352 return g_strdup_printf ("%s", GST_EVENT_TYPE_NAME (event));
356 _check_field_type (GstValidatePadMonitor * monitor,
357 GstStructure * structure, gboolean mandatory, const gchar * field, ...)
361 gchar *joined_types = NULL;
362 const gchar *rejected_types[5];
363 gint rejected_types_index = 0;
366 if (!gst_structure_has_field (structure, field)) {
368 gchar *str = gst_structure_to_string (structure);
370 GST_VALIDATE_REPORT (monitor, CAPS_IS_MISSING_FIELD,
371 "Field '%s' is missing from structure: %s", field, str);
374 GST_DEBUG_OBJECT (monitor, "Field %s is missing but is not mandatory",
380 memset (rejected_types, 0, sizeof (rejected_types));
381 va_start (var_args, field);
382 while ((type = va_arg (var_args, GType)) != 0) {
383 if (gst_structure_has_field_typed (structure, field, type)) {
387 rejected_types[rejected_types_index++] = g_type_name (type);
391 joined_types = g_strjoinv (" / ", (gchar **) rejected_types);
392 struct_str = gst_structure_to_string (structure);
393 GST_VALIDATE_REPORT (monitor, CAPS_FIELD_HAS_BAD_TYPE,
394 "Field '%s' has wrong type %s in structure '%s'. Expected: %s", field,
395 g_type_name (gst_structure_get_field_type (structure, field)), struct_str,
397 g_free (joined_types);
402 gst_validate_pad_monitor_check_raw_video_caps_complete (GstValidatePadMonitor *
403 monitor, GstStructure * structure)
405 _check_field_type (monitor, structure, TRUE, "width", G_TYPE_INT,
406 GST_TYPE_INT_RANGE, 0);
407 _check_field_type (monitor, structure, TRUE, "height", G_TYPE_INT,
408 GST_TYPE_INT_RANGE, 0);
409 _check_field_type (monitor, structure, TRUE, "framerate", GST_TYPE_FRACTION,
410 GST_TYPE_FRACTION_RANGE, 0);
411 _check_field_type (monitor, structure, FALSE, "pixel-aspect-ratio",
412 GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, 0);
413 _check_field_type (monitor, structure, TRUE, "format", G_TYPE_STRING,
418 gst_validate_pad_monitor_check_raw_audio_caps_complete (GstValidatePadMonitor *
419 monitor, GstStructure * structure)
422 _check_field_type (monitor, structure, TRUE, "format", G_TYPE_STRING,
424 _check_field_type (monitor, structure, TRUE, "layout", G_TYPE_STRING,
426 _check_field_type (monitor, structure, TRUE, "rate", G_TYPE_INT,
427 GST_TYPE_LIST, GST_TYPE_INT_RANGE, 0);
428 _check_field_type (monitor, structure, TRUE, "channels", G_TYPE_INT,
429 GST_TYPE_LIST, GST_TYPE_INT_RANGE, 0);
430 if (gst_structure_get_int (structure, "channels", &channels)) {
432 _check_field_type (monitor, structure, TRUE, "channel-mask",
433 GST_TYPE_BITMASK, GST_TYPE_LIST, 0);
438 gst_validate_pad_monitor_check_caps_complete (GstValidatePadMonitor * monitor,
441 GstStructure *structure;
444 GST_DEBUG_OBJECT (monitor->pad, "Checking caps %" GST_PTR_FORMAT, caps);
446 for (i = 0; i < gst_caps_get_size (caps); i++) {
447 structure = gst_caps_get_structure (caps, i);
449 if (_structure_is_raw_video (structure)) {
450 gst_validate_pad_monitor_check_raw_video_caps_complete (monitor,
453 } else if (_structure_is_raw_audio (structure)) {
454 gst_validate_pad_monitor_check_raw_audio_caps_complete (monitor,
461 gst_validate_pad_monitor_get_othercaps (GstValidatePadMonitor * monitor,
464 GstCaps *caps = gst_caps_new_empty ();
471 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
475 GValue value = { 0, };
476 switch (gst_iterator_next (iter, &value)) {
477 case GST_ITERATOR_OK:
478 otherpad = g_value_get_object (&value);
480 /* TODO What would be the correct caps operation to merge the caps in
481 * case one sink is internally linked to multiple srcs? */
482 peercaps = gst_pad_peer_query_caps (otherpad, filter);
484 caps = gst_caps_merge (caps, peercaps);
486 g_value_reset (&value);
488 case GST_ITERATOR_RESYNC:
489 gst_iterator_resync (iter);
490 gst_caps_unref (caps);
491 caps = gst_caps_new_empty ();
493 case GST_ITERATOR_ERROR:
494 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
497 case GST_ITERATOR_DONE:
502 gst_iterator_free (iter);
504 GST_DEBUG_OBJECT (monitor->pad, "Otherpad caps: %" GST_PTR_FORMAT, caps);
510 _structure_is_video (GstStructure * structure)
512 const gchar *name = gst_structure_get_name (structure);
514 return g_strstr_len (name, 6, "video/")
515 && strcmp (name, "video/quicktime") != 0;
519 _structure_is_audio (GstStructure * structure)
521 const gchar *name = gst_structure_get_name (structure);
523 return g_strstr_len (name, 6, "audio/") != NULL;
527 gst_validate_pad_monitor_pad_should_proxy_othercaps (GstValidatePadMonitor *
530 GstValidateMonitor *parent = GST_VALIDATE_MONITOR_GET_PARENT (monitor);
535 /* We only know how to handle othercaps checks for codecs so far */
536 return (GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_DECODER (parent) ||
537 GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_ENCODER (parent)) &&
538 !GST_VALIDATE_ELEMENT_MONITOR_ELEMENT_IS_CONVERTER (parent);
542 /* Check if the field @f from @s2 (if present) is represented in @s1
543 * Represented here means either equal or @s1's value is in a list/range
547 _structures_field_is_contained (GstStructure * s1, GstStructure * s2,
548 gboolean mandatory, const gchar * f)
553 v2 = gst_structure_get_value (s2, f);
555 return TRUE; /* nothing to compare to */
557 v1 = gst_structure_get_value (s1, f);
561 if (!gst_value_is_fixed (v1))
564 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
567 if (GST_VALUE_HOLDS_LIST (v2)) {
569 for (i = 0; i < gst_value_list_get_size (v2); i++) {
570 const GValue *v2_subvalue = gst_value_list_get_value (v2, i);
571 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
576 if (GST_VALUE_HOLDS_ARRAY (v2)) {
578 for (i = 0; i < gst_value_array_get_size (v2); i++) {
579 const GValue *v2_subvalue = gst_value_array_get_value (v2, i);
580 if (gst_value_compare (v1, v2_subvalue) == GST_VALUE_EQUAL)
585 if (GST_VALUE_HOLDS_INT_RANGE (v2)) {
588 min = gst_value_get_int_range_min (v2);
589 max = gst_value_get_int_range_max (v2);
591 if (G_VALUE_HOLDS_INT (v1)) {
592 gint v = g_value_get_int (v1);
594 return v >= min && v <= max;
596 /* TODO compare int ranges with int ranges
597 * or with lists if useful */
601 if (GST_VALUE_HOLDS_FRACTION_RANGE (v2)) {
602 const GValue *min, *max;
604 min = gst_value_get_fraction_range_min (v2);
605 max = gst_value_get_fraction_range_max (v2);
607 if (GST_VALUE_HOLDS_FRACTION (v1)) {
608 gint v_min = gst_value_compare (v1, min);
609 gint v_max = gst_value_compare (v1, max);
611 return (v_min == GST_VALUE_EQUAL || v_min == GST_VALUE_GREATER_THAN) &&
612 (v_max == GST_VALUE_EQUAL || v_max == GST_VALUE_LESS_THAN);
614 /* TODO compare fraction ranges with fraction ranges
615 * or with lists if useful */
623 _check_and_copy_structure_field (GstStructure * from, GstStructure * to,
626 if (gst_structure_has_field (from, name)) {
627 gst_structure_set_value (to, name, gst_structure_get_value (from, name));
632 gst_validate_pad_monitor_copy_caps_fields_into_caps (GstValidatePadMonitor *
633 monitor, GstCaps * from_caps, GstCaps * into_caps)
635 gint i, j, into_size, from_size;
636 GstStructure *structure;
637 GstCaps *res = gst_caps_new_empty ();
639 into_size = gst_caps_get_size (into_caps);
640 from_size = gst_caps_get_size (from_caps);
642 for (i = 0; i < into_size; i++) {
643 GstStructure *s = gst_caps_get_structure (into_caps, i);
645 for (j = 0; j < from_size; j++) {
646 GstStructure *new_structure = gst_structure_copy (s);
648 structure = gst_caps_get_structure (from_caps, j);
649 if (_structure_is_video (structure)) {
650 _check_and_copy_structure_field (structure, new_structure, "width");
651 _check_and_copy_structure_field (structure, new_structure, "height");
652 _check_and_copy_structure_field (structure, new_structure, "framerate");
653 _check_and_copy_structure_field (structure, new_structure,
654 "pixel-aspect-ratio");
655 } else if (_structure_is_audio (s)) {
656 _check_and_copy_structure_field (structure, new_structure, "rate");
657 _check_and_copy_structure_field (structure, new_structure, "channels");
660 gst_caps_append_structure (res, new_structure);
667 gst_validate_pad_monitor_transform_caps (GstValidatePadMonitor * monitor,
675 GstCaps *template_caps;
677 GST_DEBUG_OBJECT (monitor->pad, "Transform caps %" GST_PTR_FORMAT, caps);
682 othercaps = gst_caps_new_empty ();
685 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
689 GValue value = { 0, };
690 switch (gst_iterator_next (iter, &value)) {
691 case GST_ITERATOR_OK:
692 otherpad = g_value_get_object (&value);
693 template_caps = gst_pad_get_pad_template_caps (otherpad);
696 gst_validate_pad_monitor_copy_caps_fields_into_caps (monitor, caps,
698 if (!gst_caps_is_empty (new_caps))
699 gst_caps_append (othercaps, new_caps);
701 gst_caps_unref (new_caps);
703 gst_caps_unref (template_caps);
704 g_value_reset (&value);
706 case GST_ITERATOR_RESYNC:
707 gst_iterator_resync (iter);
708 gst_caps_unref (othercaps);
709 othercaps = gst_caps_new_empty ();
711 case GST_ITERATOR_ERROR:
712 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
715 case GST_ITERATOR_DONE:
720 gst_iterator_free (iter);
722 GST_DEBUG_OBJECT (monitor->pad, "Transformed caps: %" GST_PTR_FORMAT,
729 gst_validate_pad_monitor_check_caps_fields_proxied (GstValidatePadMonitor *
730 monitor, GstCaps * caps, GstCaps * filter)
732 GstStructure *structure;
733 GstStructure *otherstructure;
735 GstCaps *otherfilter;
738 if (!gst_validate_pad_monitor_pad_should_proxy_othercaps (monitor))
741 otherfilter = gst_validate_pad_monitor_transform_caps (monitor, filter);
742 othercaps = gst_validate_pad_monitor_get_othercaps (monitor, otherfilter);
744 gst_caps_unref (otherfilter);
746 for (i = 0; i < gst_caps_get_size (othercaps); i++) {
747 gboolean found = FALSE;
748 gboolean type_match = FALSE;
750 otherstructure = gst_caps_get_structure (othercaps, i);
752 /* look for a proxied version of 'otherstructure' */
753 if (_structure_is_video (otherstructure)) {
754 for (j = 0; j < gst_caps_get_size (caps); j++) {
755 structure = gst_caps_get_structure (caps, j);
756 if (_structure_is_video (structure)) {
758 if (_structures_field_is_contained (structure, otherstructure, TRUE,
760 && _structures_field_is_contained (structure, otherstructure,
762 && _structures_field_is_contained (structure, otherstructure,
764 && _structures_field_is_contained (structure, otherstructure,
765 FALSE, "pixel-aspect-ratio")) {
771 } else if (_structure_is_audio (otherstructure)) {
772 for (j = 0; j < gst_caps_get_size (caps); j++) {
773 structure = gst_caps_get_structure (caps, j);
774 if (_structure_is_audio (structure)) {
776 if (_structures_field_is_contained (structure, otherstructure, TRUE,
778 && _structures_field_is_contained (structure, otherstructure,
787 if (type_match && !found) {
788 gchar *otherstruct_str = gst_structure_to_string (otherstructure),
789 *caps_str = gst_caps_to_string (caps);
791 GST_VALIDATE_REPORT (monitor, GET_CAPS_NOT_PROXYING_FIELDS,
792 "Peer pad structure '%s' has no similar version "
793 "on pad's caps '%s'", otherstruct_str, caps_str);
795 g_free (otherstruct_str);
800 gst_caps_unref (othercaps);
804 gst_validate_pad_monitor_check_late_serialized_events (GstValidatePadMonitor *
805 monitor, GstClockTime ts)
809 if (!GST_CLOCK_TIME_IS_VALID (ts))
812 GST_DEBUG_OBJECT (monitor->pad, "Timestamp to check %" GST_TIME_FORMAT,
815 for (i = 0; i < monitor->serialized_events->len; i++) {
816 SerializedEventData *data =
817 g_ptr_array_index (monitor->serialized_events, i);
819 GST_DEBUG_OBJECT (monitor->pad, "Event #%d (%s) ts: %" GST_TIME_FORMAT,
820 i, GST_EVENT_TYPE_NAME (data->event), GST_TIME_ARGS (data->timestamp));
822 if (GST_CLOCK_TIME_IS_VALID (data->timestamp) && data->timestamp < ts) {
823 gchar *event_str = _get_event_string (data->event);
825 GST_VALIDATE_REPORT (monitor, SERIALIZED_EVENT_WASNT_PUSHED_IN_TIME,
826 "Serialized event %s wasn't pushed before expected " "timestamp %"
827 GST_TIME_FORMAT " on pad %s:%s", event_str,
828 GST_TIME_ARGS (data->timestamp),
829 GST_DEBUG_PAD_NAME (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor)));
833 /* events should be ordered by ts */
839 debug_pending_event (monitor->pad, monitor->serialized_events);
840 g_ptr_array_remove_range (monitor->serialized_events, 0, i);
845 gst_validate_pad_monitor_dispose (GObject * object)
847 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (object);
848 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
851 if (monitor->pad_probe_id)
852 gst_pad_remove_probe (pad, monitor->pad_probe_id);
855 if (monitor->expected_segment)
856 gst_event_unref (monitor->expected_segment);
858 gst_structure_free (monitor->pending_setcaps_fields);
859 g_ptr_array_unref (monitor->serialized_events);
860 g_list_free_full (monitor->expired_events, (GDestroyNotify) gst_event_unref);
861 g_list_free_full (monitor->all_bufs, (GDestroyNotify) gst_buffer_unref);
862 gst_caps_replace (&monitor->last_caps, NULL);
864 G_OBJECT_CLASS (parent_class)->dispose (object);
868 gst_validate_pad_monitor_class_init (GstValidatePadMonitorClass * klass)
870 GObjectClass *gobject_class;
871 GstValidateMonitorClass *monitor_klass;
873 gobject_class = G_OBJECT_CLASS (klass);
874 monitor_klass = GST_VALIDATE_MONITOR_CLASS (klass);
876 gobject_class->dispose = gst_validate_pad_monitor_dispose;
878 monitor_klass->setup = gst_validate_pad_monitor_do_setup;
879 monitor_klass->get_element = gst_validate_pad_monitor_get_element;
883 gst_validate_pad_monitor_init (GstValidatePadMonitor * pad_monitor)
885 pad_monitor->pending_setcaps_fields =
886 gst_structure_new_empty (PENDING_FIELDS);
887 pad_monitor->serialized_events =
888 g_ptr_array_new_with_free_func ((GDestroyNotify)
889 _serialized_event_data_free);
890 pad_monitor->expired_events = NULL;
891 gst_segment_init (&pad_monitor->segment, GST_FORMAT_BYTES);
892 pad_monitor->first_buffer = TRUE;
893 pad_monitor->pending_buffer_discont = TRUE;
895 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
896 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
897 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
901 * gst_validate_pad_monitor_new:
902 * @pad: (transfer none): a #GstPad to run Validate on
904 GstValidatePadMonitor *
905 gst_validate_pad_monitor_new (GstPad * pad, GstValidateRunner * runner,
906 GstValidateElementMonitor * parent)
908 GstValidatePadMonitor *monitor = g_object_new (GST_TYPE_VALIDATE_PAD_MONITOR,
909 "object", pad, "validate-runner", runner, "validate-parent",
912 if (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor) == NULL) {
913 g_object_unref (monitor);
920 gst_validate_pad_monitor_get_element (GstValidateMonitor * monitor)
922 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
924 return GST_PAD_PARENT (pad);
928 gst_validate_pad_monitor_event_overrides (GstValidatePadMonitor * pad_monitor,
933 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
934 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
935 iter = g_list_next (iter)) {
936 GstValidateOverride *override = iter->data;
938 gst_validate_override_event_handler (override,
939 GST_VALIDATE_MONITOR_CAST (pad_monitor), event);
941 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
945 gst_validate_pad_monitor_buffer_overrides (GstValidatePadMonitor * pad_monitor,
950 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
951 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
952 iter = g_list_next (iter)) {
953 GstValidateOverride *override = iter->data;
955 gst_validate_override_buffer_handler (override,
956 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
958 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
962 gst_validate_pad_monitor_buffer_probe_overrides (GstValidatePadMonitor *
963 pad_monitor, GstBuffer * buffer)
967 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
968 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
969 iter = g_list_next (iter)) {
970 GstValidateOverride *override = iter->data;
972 gst_validate_override_buffer_probe_handler (override,
973 GST_VALIDATE_MONITOR_CAST (pad_monitor), buffer);
975 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
979 gst_validate_pad_monitor_query_overrides (GstValidatePadMonitor * pad_monitor,
984 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
985 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
986 iter = g_list_next (iter)) {
987 GstValidateOverride *override = iter->data;
989 gst_validate_override_query_handler (override,
990 GST_VALIDATE_MONITOR_CAST (pad_monitor), query);
992 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
996 gst_validate_pad_monitor_setcaps_overrides (GstValidatePadMonitor * pad_monitor,
1001 GST_VALIDATE_MONITOR_OVERRIDES_LOCK (pad_monitor);
1002 for (iter = GST_VALIDATE_MONITOR_OVERRIDES (pad_monitor).head; iter;
1003 iter = g_list_next (iter)) {
1004 GstValidateOverride *override = iter->data;
1006 gst_validate_override_setcaps_handler (override,
1007 GST_VALIDATE_MONITOR_CAST (pad_monitor), caps);
1009 GST_VALIDATE_MONITOR_OVERRIDES_UNLOCK (pad_monitor);
1012 /* FIXME : This is a bit dubious, what's the point of this check ? */
1014 gst_validate_pad_monitor_timestamp_is_in_received_range (GstValidatePadMonitor *
1015 monitor, GstClockTime ts, GstClockTime tolerance)
1017 GST_DEBUG_OBJECT (monitor->pad, "Checking if timestamp %" GST_TIME_FORMAT
1018 " is in range: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT " for pad "
1019 "%s:%s with tolerance: %" GST_TIME_FORMAT, GST_TIME_ARGS (ts),
1020 GST_TIME_ARGS (monitor->timestamp_range_start),
1021 GST_TIME_ARGS (monitor->timestamp_range_end),
1022 GST_DEBUG_PAD_NAME (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor)),
1023 GST_TIME_ARGS (tolerance));
1024 return !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_start) ||
1025 !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_end) ||
1026 ((monitor->timestamp_range_start >= tolerance ?
1027 monitor->timestamp_range_start - tolerance : 0) <= ts
1028 && (ts >= tolerance ? ts - tolerance : 0) <=
1029 monitor->timestamp_range_end);
1032 /* Iterates over internal links (sinkpads) to check that this buffer has
1033 * a timestamp that is in the range of the lastly received buffers */
1035 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range
1036 (GstValidatePadMonitor * monitor, GstBuffer * buffer,
1037 GstClockTime tolerance)
1040 GstClockTime ts_end;
1042 gboolean has_one = FALSE;
1043 gboolean found = FALSE;
1046 GstValidatePadMonitor *othermonitor;
1048 if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))
1049 || !GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
1050 GST_DEBUG_OBJECT (monitor->pad,
1051 "Can't check buffer timestamps range as "
1052 "buffer has no valid timestamp/duration");
1055 ts = GST_BUFFER_TIMESTAMP (buffer);
1056 ts_end = ts + GST_BUFFER_DURATION (buffer);
1059 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1063 GST_WARNING_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor),
1064 "No iterator available");
1070 GValue value = { 0, };
1071 switch (gst_iterator_next (iter, &value)) {
1072 case GST_ITERATOR_OK:
1073 otherpad = g_value_get_object (&value);
1074 GST_DEBUG_OBJECT (monitor->pad, "Checking pad %s:%s input timestamps",
1075 GST_DEBUG_PAD_NAME (otherpad));
1077 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1078 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1079 if (gst_validate_pad_monitor_timestamp_is_in_received_range
1080 (othermonitor, ts, tolerance)
1082 gst_validate_pad_monitor_timestamp_is_in_received_range
1083 (othermonitor, ts_end, tolerance)) {
1087 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1088 g_value_reset (&value);
1091 case GST_ITERATOR_RESYNC:
1092 gst_iterator_resync (iter);
1096 case GST_ITERATOR_ERROR:
1097 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1100 case GST_ITERATOR_DONE:
1105 gst_iterator_free (iter);
1108 GST_DEBUG_OBJECT (monitor->pad, "Skipping timestamp in range check as no "
1109 "internal linked pad was found");
1113 GST_VALIDATE_REPORT (monitor, BUFFER_TIMESTAMP_OUT_OF_RECEIVED_RANGE,
1114 "Timestamp %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT
1115 " is out of range of received input", GST_TIME_ARGS (ts),
1116 GST_TIME_ARGS (ts_end));
1121 gst_validate_pad_monitor_check_discont (GstValidatePadMonitor * pad_monitor,
1124 if (pad_monitor->pending_buffer_discont) {
1125 if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))
1126 GST_VALIDATE_REPORT (pad_monitor, BUFFER_MISSING_DISCONT,
1127 "Buffer is missing a DISCONT flag");
1128 pad_monitor->pending_buffer_discont = FALSE;
1133 gst_validate_pad_monitor_check_first_buffer (GstValidatePadMonitor *
1134 pad_monitor, GstBuffer * buffer)
1136 if (G_UNLIKELY (pad_monitor->first_buffer)) {
1137 pad_monitor->first_buffer = FALSE;
1139 if (!pad_monitor->has_segment
1140 && PAD_IS_IN_PUSH_MODE (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor)))
1142 GST_VALIDATE_REPORT (pad_monitor, BUFFER_BEFORE_SEGMENT,
1143 "Received buffer before Segment event");
1146 GST_DEBUG_OBJECT (pad_monitor->pad,
1147 "Checking first buffer (pts:%" GST_TIME_FORMAT " dts:%" GST_TIME_FORMAT
1148 ")", GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
1149 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)));
1155 gst_validate_pad_monitor_check_eos (GstValidatePadMonitor *
1156 pad_monitor, GstBuffer * buffer)
1158 if (G_UNLIKELY (pad_monitor->is_eos)) {
1159 GST_VALIDATE_REPORT (pad_monitor, BUFFER_AFTER_EOS,
1160 "Received buffer %" GST_PTR_FORMAT " after EOS", buffer);
1165 gst_validate_pad_monitor_update_buffer_data (GstValidatePadMonitor *
1166 pad_monitor, GstBuffer * buffer)
1168 pad_monitor->current_timestamp = GST_BUFFER_TIMESTAMP (buffer);
1169 pad_monitor->current_duration = GST_BUFFER_DURATION (buffer);
1170 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
1171 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_start)) {
1172 pad_monitor->timestamp_range_start =
1173 MIN (pad_monitor->timestamp_range_start,
1174 GST_BUFFER_TIMESTAMP (buffer));
1176 pad_monitor->timestamp_range_start = GST_BUFFER_TIMESTAMP (buffer);
1179 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
1180 GstClockTime endts =
1181 GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
1182 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_end)) {
1183 pad_monitor->timestamp_range_end =
1184 MAX (pad_monitor->timestamp_range_end, endts);
1186 pad_monitor->timestamp_range_end = endts;
1190 GST_DEBUG_OBJECT (pad_monitor->pad, "Current stored range: %" GST_TIME_FORMAT
1191 " - %" GST_TIME_FORMAT,
1192 GST_TIME_ARGS (pad_monitor->timestamp_range_start),
1193 GST_TIME_ARGS (pad_monitor->timestamp_range_end));
1196 static GstFlowReturn
1197 _combine_flows (GstFlowReturn ret1, GstFlowReturn ret2)
1201 if (ret1 <= GST_FLOW_NOT_NEGOTIATED)
1203 if (ret2 <= GST_FLOW_NOT_NEGOTIATED)
1205 if (ret1 == GST_FLOW_FLUSHING || ret2 == GST_FLOW_FLUSHING)
1206 return GST_FLOW_FLUSHING;
1207 if (ret1 == GST_FLOW_OK || ret2 == GST_FLOW_OK)
1213 gst_validate_pad_monitor_check_aggregated_return (GstValidatePadMonitor *
1214 monitor, GstObject * parent, GstFlowReturn ret)
1220 GstValidatePadMonitor *othermonitor;
1221 GstFlowReturn aggregated = GST_FLOW_NOT_LINKED;
1222 gboolean found_a_pad = FALSE;
1223 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (monitor);
1225 iter = gst_pad_iterate_internal_links (pad);
1228 GValue value = { 0, };
1229 switch (gst_iterator_next (iter, &value)) {
1230 case GST_ITERATOR_OK:
1231 otherpad = g_value_get_object (&value);
1232 peerpad = gst_pad_get_peer (otherpad);
1235 g_object_get_data ((GObject *) peerpad, "validate-monitor");
1238 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1240 _combine_flows (aggregated, othermonitor->last_flow_return);
1241 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1244 gst_object_unref (peerpad);
1246 g_value_reset (&value);
1248 case GST_ITERATOR_RESYNC:
1249 gst_iterator_resync (iter);
1251 case GST_ITERATOR_ERROR:
1252 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1255 case GST_ITERATOR_DONE:
1260 gst_iterator_free (iter);
1262 /* no peer pad found, nothing to do */
1265 if (aggregated == GST_FLOW_OK || aggregated == GST_FLOW_EOS) {
1266 GstState state, pending;
1268 /* those are acceptable situations */
1269 if (GST_PAD_IS_FLUSHING (pad) && ret == GST_FLOW_FLUSHING) {
1270 /* pad is flushing, always acceptable to return flushing */
1274 gst_element_get_state (GST_ELEMENT (parent), &state, &pending, 0);
1275 if (ret == GST_FLOW_FLUSHING && (state < GST_STATE_PAUSED
1276 || pending < GST_STATE_PAUSED)) {
1277 /* Element is being teared down, accept FLOW_FLUSHING */
1282 if (monitor->is_eos && ret == GST_FLOW_EOS) {
1283 /* this element received eos and returned eos */
1287 if (PAD_PARENT_IS_DEMUXER (monitor) && ret == GST_FLOW_EOS) {
1288 /* a demuxer can return EOS when the samples end */
1293 if (aggregated != ret) {
1294 GST_VALIDATE_REPORT (monitor, WRONG_FLOW_RETURN,
1295 "Wrong combined flow return %s(%d). Expected: %s(%d)",
1296 gst_flow_get_name (ret), ret, gst_flow_get_name (aggregated),
1302 gst_validate_pad_monitor_otherpad_add_pending_serialized_event
1303 (GstValidatePadMonitor * monitor, GstEvent * event, GstClockTime last_ts)
1308 GstValidatePadMonitor *othermonitor;
1310 if (!GST_EVENT_IS_SERIALIZED (event))
1314 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1317 /* inputselector will return NULL if the sinkpad is not the active one .... */
1318 GST_FIXME_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD
1319 (monitor), "No iterator");
1324 GValue value = { 0, };
1325 switch (gst_iterator_next (iter, &value)) {
1326 case GST_ITERATOR_OK:
1327 otherpad = g_value_get_object (&value);
1329 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1331 SerializedEventData *data = g_slice_new0 (SerializedEventData);
1332 data->timestamp = last_ts;
1333 data->event = gst_event_ref (event);
1334 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1335 GST_DEBUG_OBJECT (monitor->pad, "Storing for pad %s:%s event %p %s",
1336 GST_DEBUG_PAD_NAME (otherpad), event,
1337 GST_EVENT_TYPE_NAME (event));
1338 g_ptr_array_add (othermonitor->serialized_events, data);
1339 debug_pending_event (otherpad, othermonitor->serialized_events);
1340 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1342 g_value_reset (&value);
1344 case GST_ITERATOR_RESYNC:
1345 gst_iterator_resync (iter);
1347 case GST_ITERATOR_ERROR:
1348 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1351 case GST_ITERATOR_DONE:
1356 gst_iterator_free (iter);
1360 gst_validate_pad_monitor_otherpad_add_pending_field (GstValidatePadMonitor *
1361 monitor, GstStructure * structure, const gchar * field)
1366 GstValidatePadMonitor *othermonitor;
1369 v = gst_structure_get_value (structure, field);
1371 GST_DEBUG_OBJECT (monitor->pad, "Not adding pending field %s as it isn't "
1372 "present on structure %" GST_PTR_FORMAT, field, structure);
1377 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1381 GValue value = { 0, };
1382 switch (gst_iterator_next (iter, &value)) {
1383 case GST_ITERATOR_OK:
1384 otherpad = g_value_get_object (&value);
1386 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1388 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1389 g_assert (othermonitor->pending_setcaps_fields != NULL);
1390 gst_structure_set_value (othermonitor->pending_setcaps_fields,
1392 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1394 g_value_reset (&value);
1396 case GST_ITERATOR_RESYNC:
1397 gst_iterator_resync (iter);
1399 case GST_ITERATOR_ERROR:
1400 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1403 case GST_ITERATOR_DONE:
1408 gst_iterator_free (iter);
1412 gst_validate_pad_monitor_otherpad_clear_pending_fields (GstValidatePadMonitor *
1418 GstValidatePadMonitor *othermonitor;
1421 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1425 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1432 GValue value = { 0, };
1433 switch (gst_iterator_next (iter, &value)) {
1434 case GST_ITERATOR_OK:
1435 otherpad = g_value_get_object (&value);
1437 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1439 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1440 g_assert (othermonitor->pending_setcaps_fields != NULL);
1441 gst_structure_free (othermonitor->pending_setcaps_fields);
1442 othermonitor->pending_setcaps_fields =
1443 gst_structure_new_empty (PENDING_FIELDS);
1444 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1446 g_value_reset (&value);
1448 case GST_ITERATOR_RESYNC:
1449 gst_iterator_resync (iter);
1451 case GST_ITERATOR_ERROR:
1452 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1455 case GST_ITERATOR_DONE:
1460 gst_iterator_free (iter);
1464 gst_validate_pad_monitor_add_expected_newsegment (GstValidatePadMonitor *
1465 monitor, GstEvent * event)
1470 GstValidatePadMonitor *othermonitor;
1473 gst_pad_iterate_internal_links (GST_VALIDATE_PAD_MONITOR_GET_PAD
1477 GST_DEBUG_OBJECT (monitor, "No internally linked pad");
1483 GValue value = { 0, };
1484 switch (gst_iterator_next (iter, &value)) {
1485 case GST_ITERATOR_OK:
1486 otherpad = g_value_get_object (&value);
1490 g_object_get_data ((GObject *) otherpad, "validate-monitor");
1491 GST_VALIDATE_MONITOR_LOCK (othermonitor);
1492 gst_event_replace (&othermonitor->expected_segment, event);
1493 GST_VALIDATE_MONITOR_UNLOCK (othermonitor);
1494 g_value_reset (&value);
1496 case GST_ITERATOR_RESYNC:
1497 gst_iterator_resync (iter);
1499 case GST_ITERATOR_ERROR:
1500 GST_WARNING_OBJECT (monitor->pad, "Internal links pad iteration error");
1503 case GST_ITERATOR_DONE:
1508 gst_iterator_free (iter);
1512 gst_validate_pad_monitor_flush (GstValidatePadMonitor * pad_monitor)
1514 pad_monitor->current_timestamp = GST_CLOCK_TIME_NONE;
1515 pad_monitor->current_duration = GST_CLOCK_TIME_NONE;
1516 pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
1517 pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
1518 pad_monitor->has_segment = FALSE;
1519 pad_monitor->is_eos = FALSE;
1520 pad_monitor->last_flow_return = GST_FLOW_OK;
1521 gst_caps_replace (&pad_monitor->last_caps, NULL);
1522 pad_monitor->caps_is_audio = pad_monitor->caps_is_video =
1523 pad_monitor->caps_is_raw = FALSE;
1525 g_list_free_full (pad_monitor->expired_events,
1526 (GDestroyNotify) gst_event_unref);
1527 pad_monitor->expired_events = NULL;
1529 if (pad_monitor->serialized_events->len)
1530 g_ptr_array_remove_range (pad_monitor->serialized_events, 0,
1531 pad_monitor->serialized_events->len);
1534 /* common checks for both sink and src event functions */
1536 gst_validate_pad_monitor_common_event_check (GstValidatePadMonitor *
1537 pad_monitor, GstEvent * event)
1539 guint32 seqnum = gst_event_get_seqnum (event);
1541 switch (GST_EVENT_TYPE (event)) {
1542 case GST_EVENT_FLUSH_START:
1544 if (pad_monitor->pending_flush_start_seqnum) {
1545 if (seqnum == pad_monitor->pending_flush_start_seqnum) {
1546 pad_monitor->pending_flush_start_seqnum = 0;
1548 GST_VALIDATE_REPORT (pad_monitor, FLUSH_START_HAS_WRONG_SEQNUM,
1549 "Got: %u Expected: %u", seqnum,
1550 pad_monitor->pending_flush_start_seqnum);
1554 if (pad_monitor->pending_flush_stop) {
1555 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_START_UNEXPECTED,
1556 "Received flush-start from " " when flush-stop was expected");
1558 pad_monitor->pending_flush_stop = TRUE;
1561 case GST_EVENT_FLUSH_STOP:
1563 if (pad_monitor->pending_flush_stop_seqnum) {
1564 if (seqnum == pad_monitor->pending_flush_stop_seqnum) {
1565 pad_monitor->pending_flush_stop_seqnum = 0;
1567 GST_VALIDATE_REPORT (pad_monitor, FLUSH_STOP_HAS_WRONG_SEQNUM,
1568 "Got: %u Expected: %u", seqnum,
1569 pad_monitor->pending_flush_stop_seqnum);
1573 pad_monitor->pending_newsegment_seqnum = seqnum;
1574 pad_monitor->pending_eos_seqnum = seqnum;
1576 if (!pad_monitor->pending_flush_stop) {
1577 gchar *event_str = _get_event_string (event);
1579 GST_VALIDATE_REPORT (pad_monitor, EVENT_FLUSH_STOP_UNEXPECTED,
1580 "Unexpected flush-stop %s", event_str);
1583 pad_monitor->pending_flush_stop = FALSE;
1585 /* Buffers following a FLUSH should have the DISCONT flag set */
1586 pad_monitor->pending_buffer_discont = TRUE;
1588 /* cleanup our data */
1589 gst_validate_pad_monitor_flush (pad_monitor);
1598 mark_pads_eos (GstValidatePadMonitor * pad_monitor)
1600 GstValidatePadMonitor *peer_monitor;
1601 GstPad *peer = gst_pad_get_peer (pad_monitor->pad);
1604 pad_monitor->is_eos = TRUE;
1606 real_peer = _get_actual_pad (peer);
1608 g_object_get_data ((GObject *) real_peer, "validate-monitor");
1610 peer_monitor->is_eos = TRUE;
1611 gst_object_unref (peer);
1612 gst_object_unref (real_peer);
1616 static inline gboolean
1617 _should_check_buffers (GstValidatePadMonitor * pad_monitor,
1618 gboolean force_checks)
1620 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1621 GstValidateMonitor *monitor = GST_VALIDATE_MONITOR (pad_monitor);
1623 if (pad_monitor->first_buffer || force_checks) {
1624 if (pad_monitor->segment.rate != 1.0) {
1625 GST_INFO_OBJECT (pad_monitor, "We do not support buffer checking"
1626 " for trick modes");
1628 pad_monitor->check_buffers = FALSE;
1629 } else if (!PAD_PARENT_IS_DECODER (pad_monitor)) {
1630 GST_DEBUG_OBJECT (pad, "Not on a decoder => no buffer checking");
1632 pad_monitor->check_buffers = FALSE;
1633 } else if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK) {
1634 GST_DEBUG_OBJECT (pad, "Not a sinkpad => no buffer checking");
1636 pad_monitor->check_buffers = FALSE;
1637 } else if (!pad_monitor->caps_is_video) {
1638 GST_DEBUG_OBJECT (pad, "Not working with video => no buffer checking");
1640 pad_monitor->check_buffers = FALSE;
1641 } else if (monitor->media_descriptor == NULL) {
1642 GST_DEBUG_OBJECT (pad, "No media_descriptor set => no buffer checking");
1644 pad_monitor->check_buffers = FALSE;
1646 if (!gst_validate_media_descriptor_detects_frames
1647 (monitor->media_descriptor)) {
1648 GST_DEBUG_OBJECT (pad,
1649 "No frame detection media descriptor " "=> not buffer checking");
1650 pad_monitor->check_buffers = FALSE;
1651 } else if (pad_monitor->all_bufs == NULL &&
1652 !gst_validate_media_descriptor_get_buffers (monitor->media_descriptor,
1653 pad, NULL, &pad_monitor->all_bufs)) {
1655 GST_INFO_OBJECT (monitor,
1656 "The MediaInfo is marked as detecting frame, but getting frames"
1657 " from pad %" GST_PTR_FORMAT " did not work (some format conversion"
1658 " might be happening)", pad);
1660 pad_monitor->check_buffers = FALSE;
1662 if (!pad_monitor->current_buf)
1663 pad_monitor->current_buf = pad_monitor->all_bufs;
1664 pad_monitor->check_buffers = TRUE;
1668 return pad_monitor->check_buffers;
1672 gst_validate_monitor_find_next_buffer (GstValidatePadMonitor * pad_monitor)
1675 gboolean passed_start = FALSE;
1677 if (!_should_check_buffers (pad_monitor, TRUE))
1680 for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) {
1681 GstBuffer *cbuf = tmp->data;
1683 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf)
1684 : GST_BUFFER_PTS (cbuf);
1686 if (!GST_CLOCK_TIME_IS_VALID (ts))
1689 if (ts <= pad_monitor->segment.start)
1690 passed_start = TRUE;
1695 if (!GST_BUFFER_FLAG_IS_SET (cbuf, GST_BUFFER_FLAG_DELTA_UNIT)) {
1701 pad_monitor->current_buf = pad_monitor->all_bufs;
1703 pad_monitor->current_buf = tmp;
1706 /* Checks whether a segment is just an update of another,
1707 * That is to say that only the base and offset field differ and all
1708 * other fields are identical */
1710 is_segment_update (GstSegment * a, const GstSegment * b)
1712 /* Note : We never care about the position field, it is only
1713 * used for internal usage by elements */
1714 if (a->rate == b->rate &&
1715 a->applied_rate == b->applied_rate &&
1716 a->format == b->format && a->time == b->time) {
1717 /* Changes in base/offset are considered updates */
1718 /* Updating the end position of a segment is an update */
1719 /* Updating the duration of a segment is an update */
1720 if (a->rate > 0.0) {
1721 if (a->start == b->start)
1724 if (a->stop == b->stop)
1731 static GstFlowReturn
1732 gst_validate_pad_monitor_downstream_event_check (GstValidatePadMonitor *
1733 pad_monitor, GstObject * parent, GstEvent * event,
1734 GstPadEventFunction handler)
1736 GstFlowReturn ret = GST_FLOW_OK;
1737 const GstSegment *segment;
1738 guint32 seqnum = gst_event_get_seqnum (event);
1739 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1741 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1744 switch (GST_EVENT_TYPE (event)) {
1745 case GST_EVENT_STREAM_START:
1746 /* Buffers following a STREAM_START should have the DISCONT flag set */
1747 pad_monitor->pending_buffer_discont = TRUE;
1749 case GST_EVENT_SEGMENT:
1750 /* parse segment data to be used if event is handled */
1751 gst_event_parse_segment (event, &segment);
1753 GST_DEBUG_OBJECT (pad_monitor->pad, "Got segment %" GST_SEGMENT_FORMAT,
1756 if (pad_monitor->pending_newsegment_seqnum) {
1757 if (pad_monitor->pending_newsegment_seqnum == seqnum) {
1758 pad_monitor->pending_newsegment_seqnum = 0;
1759 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->pending_seek_accurate_time)) {
1760 if (segment->time == pad_monitor->pending_seek_accurate_time) {
1761 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
1763 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_START,
1764 "After an accurate seek, got: %" GST_TIME_FORMAT
1765 " Expected: %" GST_TIME_FORMAT, GST_TIME_ARGS (segment->time),
1766 GST_TIME_ARGS (pad_monitor->pending_seek_accurate_time));
1770 GST_VALIDATE_REPORT (pad_monitor, SEGMENT_HAS_WRONG_SEQNUM,
1771 "Got: %u Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1775 pad_monitor->pending_eos_seqnum = seqnum;
1777 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
1778 gst_validate_pad_monitor_add_expected_newsegment (pad_monitor, event);
1780 /* check if this segment is the expected one */
1781 if (pad_monitor->expected_segment) {
1782 const GstSegment *exp_segment;
1784 if (pad_monitor->expected_segment != event) {
1785 gst_event_parse_segment (pad_monitor->expected_segment,
1787 if (segment->format == exp_segment->format) {
1788 if ((exp_segment->rate * exp_segment->applied_rate !=
1789 segment->rate * segment->applied_rate))
1790 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1791 "Rate * applied_rate %f != expected %f",
1792 segment->rate * segment->applied_rate,
1793 exp_segment->rate * exp_segment->applied_rate);
1794 if (exp_segment->start != segment->start)
1795 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1796 "Start %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
1797 GST_TIME_ARGS (segment->start),
1798 GST_TIME_ARGS (exp_segment->start));
1799 if (exp_segment->stop != segment->stop)
1800 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1801 "Stop %" GST_TIME_FORMAT " != expected %" GST_TIME_FORMAT,
1802 GST_TIME_ARGS (segment->stop),
1803 GST_TIME_ARGS (exp_segment->stop));
1804 if (exp_segment->position != segment->position)
1805 GST_VALIDATE_REPORT (pad_monitor, EVENT_NEW_SEGMENT_MISMATCH,
1806 "Position %" GST_TIME_FORMAT " != expected %"
1807 GST_TIME_FORMAT, GST_TIME_ARGS (segment->position),
1808 GST_TIME_ARGS (exp_segment->position));
1811 gst_event_replace (&pad_monitor->expected_segment, NULL);
1815 case GST_EVENT_CAPS:{
1818 gst_event_parse_caps (event, &caps);
1819 gst_validate_pad_monitor_setcaps_pre (pad_monitor, caps);
1823 pad_monitor->is_eos = TRUE;
1824 if (pad_monitor->pending_eos_seqnum == 0) {
1825 GST_VALIDATE_REPORT (pad_monitor, EVENT_EOS_WITHOUT_SEGMENT,
1826 "EOS %" GST_PTR_FORMAT " received before a segment was received",
1828 } else if (pad_monitor->pending_eos_seqnum != seqnum) {
1829 GST_VALIDATE_REPORT (pad_monitor, EOS_HAS_WRONG_SEQNUM,
1830 "Got: %u. Expected: %u", seqnum, pad_monitor->pending_eos_seqnum);
1834 * TODO add end of stream checks for
1835 * - events not pushed
1836 * - buffer data not pushed
1837 * - pending events not received
1841 /* both flushes are handled by the common event function */
1842 case GST_EVENT_FLUSH_START:
1843 case GST_EVENT_FLUSH_STOP:
1845 case GST_EVENT_SINK_MESSAGE:
1850 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1851 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
1852 gst_validate_pad_monitor_event_overrides (pad_monitor, event);
1854 gst_event_ref (event);
1855 if (pad_monitor->event_full_func)
1856 ret = pad_monitor->event_full_func (pad, parent, event);
1857 else if (pad_monitor->event_func (pad, parent, event))
1860 ret = GST_FLOW_ERROR;
1862 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
1863 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1866 switch (GST_EVENT_TYPE (event)) {
1867 case GST_EVENT_SEGMENT:
1868 if (ret == GST_FLOW_OK) {
1869 /* If the new segment is not an update of the previous one, then
1870 * the following buffer should have the DISCONT flag set */
1871 if (!is_segment_update (&pad_monitor->segment, segment))
1872 pad_monitor->pending_buffer_discont = TRUE;
1873 if (!pad_monitor->has_segment
1874 && pad_monitor->segment.format != segment->format) {
1875 gst_segment_init (&pad_monitor->segment, segment->format);
1877 gst_segment_copy_into (segment, &pad_monitor->segment);
1878 pad_monitor->has_segment = TRUE;
1879 gst_validate_monitor_find_next_buffer (pad_monitor);
1882 case GST_EVENT_CAPS:{
1885 gst_event_parse_caps (event, &caps);
1886 gst_validate_pad_monitor_setcaps_post (pad_monitor, caps,
1887 ret == GST_FLOW_OK);
1890 case GST_EVENT_FLUSH_START:
1891 case GST_EVENT_FLUSH_STOP:
1894 case GST_EVENT_SINK_MESSAGE:
1900 gst_event_unref (event);
1905 gst_validate_pad_monitor_src_event_check (GstValidatePadMonitor * pad_monitor,
1906 GstObject * parent, GstEvent * event, GstPadEventFunction handler)
1908 gboolean ret = TRUE;
1912 GstSeekFlags seek_flags;
1913 GstSeekType start_type, stop_type;
1914 guint32 seqnum = gst_event_get_seqnum (event);
1915 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1917 gst_validate_pad_monitor_common_event_check (pad_monitor, event);
1920 switch (GST_EVENT_TYPE (event)) {
1921 case GST_EVENT_SEEK:
1923 gst_event_parse_seek (event, &rate, &format, &seek_flags, &start_type,
1924 &start, &stop_type, &stop);
1925 /* upstream seek - store the seek event seqnum to check
1926 * flushes and newsegments share the same */
1928 /* TODO we might need to use a list as multiple seeks can be sent
1929 * before the flushes arrive here */
1930 if (seek_flags & GST_SEEK_FLAG_FLUSH) {
1931 pad_monitor->pending_flush_start_seqnum = seqnum;
1932 pad_monitor->pending_flush_stop_seqnum = seqnum;
1934 if (seek_flags & GST_SEEK_FLAG_ACCURATE) {
1935 pad_monitor->pending_seek_accurate_time = start;
1939 /* both flushes are handled by the common event handling function */
1940 case GST_EVENT_FLUSH_START:
1941 case GST_EVENT_FLUSH_STOP:
1942 case GST_EVENT_NAVIGATION:
1943 case GST_EVENT_LATENCY:
1944 case GST_EVENT_STEP:
1951 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
1952 gst_event_ref (event);
1953 ret = pad_monitor->event_func (pad, parent, event);
1954 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
1958 switch (GST_EVENT_TYPE (event)) {
1959 case GST_EVENT_FLUSH_START:
1960 case GST_EVENT_FLUSH_STOP:
1962 case GST_EVENT_SEEK:
1965 /* do not expect any of these events anymore */
1966 pad_monitor->pending_flush_start_seqnum = 0;
1967 pad_monitor->pending_flush_stop_seqnum = 0;
1968 pad_monitor->pending_newsegment_seqnum = 0;
1969 pad_monitor->pending_eos_seqnum = 0;
1970 pad_monitor->pending_seek_accurate_time = GST_CLOCK_TIME_NONE;
1974 case GST_EVENT_NAVIGATION:
1975 case GST_EVENT_LATENCY:
1976 case GST_EVENT_STEP:
1982 gst_event_unref (event);
1987 gst_validate_pad_monitor_check_right_buffer (GstValidatePadMonitor *
1988 pad_monitor, GstBuffer * buffer)
1991 GstBuffer *wanted_buf;
1992 GstMapInfo map, wanted_map;
1994 gboolean ret = TRUE;
1995 GstPad *pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
1997 if (_should_check_buffers (pad_monitor, FALSE) == FALSE)
2000 if (pad_monitor->current_buf == NULL) {
2001 GST_INFO_OBJECT (pad, "No current buffer one pad, Why?");
2005 wanted_buf = pad_monitor->current_buf->data;
2007 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (wanted_buf)) &&
2008 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buffer)) &&
2009 GST_BUFFER_PTS (wanted_buf) != GST_BUFFER_PTS (buffer)) {
2011 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2012 "buffer %" GST_PTR_FORMAT " PTS %" GST_TIME_FORMAT
2013 " different than expected: %" GST_TIME_FORMAT, buffer,
2014 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
2015 GST_TIME_ARGS (GST_BUFFER_PTS (wanted_buf)));
2020 if (GST_BUFFER_DTS (wanted_buf) != GST_BUFFER_DTS (buffer)) {
2021 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2022 "buffer %" GST_PTR_FORMAT " DTS %" GST_TIME_FORMAT
2023 " different than expected: %" GST_TIME_FORMAT, buffer,
2024 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)),
2025 GST_TIME_ARGS (GST_BUFFER_DTS (wanted_buf)));
2029 if (GST_BUFFER_DURATION (wanted_buf) != GST_BUFFER_DURATION (buffer)) {
2030 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2031 "buffer %" GST_PTR_FORMAT " DURATION %" GST_TIME_FORMAT
2032 " different than expected: %" GST_TIME_FORMAT, buffer,
2033 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2034 GST_TIME_ARGS (GST_BUFFER_DURATION (wanted_buf)));
2038 if (GST_BUFFER_FLAG_IS_SET (wanted_buf, GST_BUFFER_FLAG_DELTA_UNIT) !=
2039 GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
2040 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2041 "buffer %" GST_PTR_FORMAT " Delta unit is set to %s but expected %s",
2042 buffer, GST_BUFFER_FLAG_IS_SET (buffer,
2043 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False",
2044 GST_BUFFER_FLAG_IS_SET (wanted_buf,
2045 GST_BUFFER_FLAG_DELTA_UNIT) ? "True" : "False");
2049 g_assert (gst_buffer_map (wanted_buf, &wanted_map, GST_MAP_READ));
2050 g_assert (gst_buffer_map (buffer, &map, GST_MAP_READ));
2052 checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
2053 (const guchar *) map.data, map.size);
2055 if (g_strcmp0 ((gchar *) wanted_map.data, checksum)) {
2056 GST_VALIDATE_REPORT (pad_monitor, WRONG_BUFFER,
2057 "buffer %" GST_PTR_FORMAT " checksum %s different from expected: %s",
2058 buffer, checksum, wanted_map.data);
2062 gst_buffer_unmap (wanted_buf, &wanted_map);
2063 gst_buffer_unmap (buffer, &map);
2066 pad_monitor->current_buf = pad_monitor->current_buf->next;
2072 gst_validate_pad_monitor_check_return (GstValidatePadMonitor * pad_monitor,
2075 GstValidateMonitor *parent = GST_VALIDATE_MONITOR (pad_monitor);
2077 if (ret != GST_FLOW_ERROR)
2080 while (GST_VALIDATE_MONITOR_GET_PARENT (parent))
2081 parent = GST_VALIDATE_MONITOR_GET_PARENT (parent);
2083 if (GST_IS_VALIDATE_PIPELINE_MONITOR (parent)) {
2084 GstValidatePipelineMonitor *m = GST_VALIDATE_PIPELINE_MONITOR (parent);
2086 GST_VALIDATE_MONITOR_LOCK (m);
2087 if (m->got_error == FALSE) {
2088 GST_VALIDATE_REPORT (pad_monitor, FLOW_ERROR_WITHOUT_ERROR_MESSAGE,
2089 "Pad return GST_FLOW_ERROR but no GST_MESSAGE_ERROR was received on"
2092 /* Only report it the first time */
2093 m->got_error = TRUE;
2095 GST_VALIDATE_MONITOR_UNLOCK (m);
2099 static GstFlowReturn
2100 gst_validate_pad_monitor_chain_func (GstPad * pad, GstObject * parent,
2103 GstValidatePadMonitor *pad_monitor =
2104 g_object_get_data ((GObject *) pad, "validate-monitor");
2107 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2108 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2110 gst_validate_pad_monitor_check_discont (pad_monitor, buffer);
2111 gst_validate_pad_monitor_check_right_buffer (pad_monitor, buffer);
2112 gst_validate_pad_monitor_check_first_buffer (pad_monitor, buffer);
2113 gst_validate_pad_monitor_update_buffer_data (pad_monitor, buffer);
2114 gst_validate_pad_monitor_check_eos (pad_monitor, buffer);
2116 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2117 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2119 gst_validate_pad_monitor_buffer_overrides (pad_monitor, buffer);
2121 ret = pad_monitor->chain_func (pad, parent, buffer);
2123 gst_validate_pad_monitor_check_return (pad_monitor, ret);
2125 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2126 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2128 pad_monitor->last_flow_return = ret;
2129 if (ret == GST_FLOW_EOS) {
2130 mark_pads_eos (pad_monitor);
2132 if (PAD_PARENT_IS_DEMUXER (pad_monitor))
2133 gst_validate_pad_monitor_check_aggregated_return (pad_monitor, parent, ret);
2135 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2136 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2142 gst_validate_pad_monitor_event_is_tracked (GstValidatePadMonitor * monitor,
2145 if (!GST_EVENT_IS_SERIALIZED (event)) {
2149 /* we don't track Tag events because they mutate too much and it is hard
2150 * to match a tag event pushed on a source pad with the one that was received
2152 * One idea would be to use seqnum, but it seems that it is undefined whether
2153 * seqnums should be maintained in tag events that are created from others
2154 * up to today. (2013-08-29)
2156 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
2162 static GstFlowReturn
2163 gst_validate_pad_monitor_sink_event_full_func (GstPad * pad, GstObject * parent,
2166 GstValidatePadMonitor *pad_monitor =
2167 g_object_get_data ((GObject *) pad, "validate-monitor");
2170 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (pad_monitor);
2171 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2173 if (gst_validate_pad_monitor_event_is_tracked (pad_monitor, event)) {
2174 GstClockTime last_ts = GST_CLOCK_TIME_NONE;
2175 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_timestamp)) {
2176 last_ts = pad_monitor->current_timestamp;
2177 if (GST_CLOCK_TIME_IS_VALID (pad_monitor->current_duration)) {
2178 last_ts += pad_monitor->current_duration;
2181 gst_validate_pad_monitor_otherpad_add_pending_serialized_event (pad_monitor,
2186 gst_validate_pad_monitor_downstream_event_check (pad_monitor, parent,
2187 event, pad_monitor->event_func);
2189 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2190 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (pad_monitor);
2195 gst_validate_pad_monitor_sink_event_func (GstPad * pad, GstObject * parent,
2198 if (gst_validate_pad_monitor_sink_event_full_func (pad, parent,
2199 event) == GST_FLOW_OK)
2205 gst_validate_pad_monitor_src_event_func (GstPad * pad, GstObject * parent,
2208 GstValidatePadMonitor *pad_monitor =
2209 g_object_get_data ((GObject *) pad, "validate-monitor");
2212 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2213 ret = gst_validate_pad_monitor_src_event_check (pad_monitor, parent, event,
2214 pad_monitor->event_func);
2215 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2220 gst_validate_pad_monitor_query_func (GstPad * pad, GstObject * parent,
2223 GstValidatePadMonitor *pad_monitor =
2224 g_object_get_data ((GObject *) pad, "validate-monitor");
2227 gst_validate_pad_monitor_query_overrides (pad_monitor, query);
2228 ret = pad_monitor->query_func (pad, parent, query);
2231 switch (GST_QUERY_TYPE (query)) {
2232 case GST_QUERY_ACCEPT_CAPS:
2236 gst_caps_replace (&pad_monitor->last_refused_caps, NULL);
2237 gst_query_parse_accept_caps_result (query, &result);
2239 GstCaps *refused_caps;
2241 gst_query_parse_accept_caps (query, &refused_caps);
2242 pad_monitor->last_refused_caps = gst_caps_copy (refused_caps);
2248 case GST_QUERY_CAPS:{
2252 /* We shouldn't need to lock the parent as this doesn't modify
2253 * other monitors, just does some peer_pad_caps */
2254 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2256 gst_query_parse_caps (query, &filter);
2257 gst_query_parse_caps_result (query, &res);
2259 gst_caps_replace (&pad_monitor->last_query_res, NULL);
2260 gst_caps_replace (&pad_monitor->last_query_filter, NULL);
2261 pad_monitor->last_query_res =
2262 res ? gst_caps_copy (res) : gst_caps_ref (GST_CAPS_NONE);
2263 pad_monitor->last_query_filter =
2264 filter ? gst_caps_copy (filter) : gst_caps_ref (GST_CAPS_NONE);
2266 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2267 gst_validate_pad_monitor_check_caps_fields_proxied (pad_monitor, res,
2270 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2282 gst_validate_pad_monitor_activatemode_func (GstPad * pad, GstObject * parent,
2283 GstPadMode mode, gboolean active)
2285 GstValidatePadMonitor *pad_monitor =
2286 g_object_get_data ((GObject *) pad, "validate-monitor");
2287 gboolean ret = TRUE;
2289 /* TODO add overrides for activate func */
2291 if (pad_monitor->activatemode_func)
2292 ret = pad_monitor->activatemode_func (pad, parent, mode, active);
2293 if (ret && active == FALSE) {
2294 GST_VALIDATE_MONITOR_LOCK (pad_monitor);
2295 gst_validate_pad_monitor_flush (pad_monitor);
2296 GST_VALIDATE_MONITOR_UNLOCK (pad_monitor);
2303 gst_validate_pad_get_range_func (GstPad * pad, GstObject * parent,
2304 guint64 offset, guint size, GstBuffer ** buffer)
2306 GstValidatePadMonitor *pad_monitor =
2307 g_object_get_data ((GObject *) pad, "validate-monitor");
2309 ret = pad_monitor->getrange_func (pad, parent, offset, size, buffer);
2314 gst_validate_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
2315 gpointer udata, gboolean pull_mode)
2317 GstValidatePadMonitor *monitor = udata;
2319 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2320 GST_VALIDATE_MONITOR_LOCK (monitor);
2323 gst_validate_pad_monitor_check_discont (monitor, buffer);
2324 gst_validate_pad_monitor_check_first_buffer (monitor, buffer);
2325 gst_validate_pad_monitor_update_buffer_data (monitor, buffer);
2326 gst_validate_pad_monitor_check_eos (monitor, buffer);
2328 if (PAD_PARENT_IS_DECODER (monitor) || PAD_PARENT_IS_ENCODER (monitor)) {
2329 GstClockTime tolerance = 0;
2331 if (monitor->caps_is_audio)
2332 tolerance = AUDIO_TIMESTAMP_TOLERANCE;
2334 gst_validate_pad_monitor_check_buffer_timestamp_in_received_range (monitor,
2338 gst_validate_pad_monitor_check_late_serialized_events (monitor,
2339 GST_BUFFER_TIMESTAMP (buffer));
2341 /* a GstValidatePadMonitor parent must be a GstValidateElementMonitor */
2342 if (PAD_PARENT_IS_DECODER (monitor)) {
2344 /* should not push out of segment data */
2345 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
2346 GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)) &&
2347 ((!gst_segment_clip (&monitor->segment, monitor->segment.format,
2348 GST_BUFFER_TIMESTAMP (buffer),
2349 GST_BUFFER_TIMESTAMP (buffer) +
2350 GST_BUFFER_DURATION (buffer), NULL, NULL)) ||
2351 /* In the case of raw data, buffers should be strictly contained inside the
2353 (monitor->caps_is_raw &&
2354 GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer) <
2355 monitor->segment.start))
2357 /* TODO is this a timestamp issue? */
2358 GST_VALIDATE_REPORT (monitor, BUFFER_IS_OUT_OF_SEGMENT,
2359 "buffer is out of segment and shouldn't be pushed. Timestamp: %"
2360 GST_TIME_FORMAT " - duration: %" GST_TIME_FORMAT ". Range: %"
2361 GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
2362 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
2363 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
2364 GST_TIME_ARGS (monitor->segment.start),
2365 GST_TIME_ARGS (monitor->segment.stop));
2369 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2370 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2371 gst_validate_pad_monitor_buffer_probe_overrides (monitor, buffer);
2376 gst_validate_pad_monitor_event_probe (GstPad * pad, GstEvent * event,
2379 GstValidatePadMonitor *monitor = GST_VALIDATE_PAD_MONITOR_CAST (udata);
2381 GST_VALIDATE_PAD_MONITOR_PARENT_LOCK (monitor);
2382 GST_VALIDATE_MONITOR_LOCK (monitor);
2384 GST_DEBUG_OBJECT (pad, "event %p %s", event, GST_EVENT_TYPE_NAME (event));
2386 if (GST_EVENT_IS_SERIALIZED (event)) {
2389 /* Detect if events the element received are being forwarded in the same order
2391 * Several scenarios:
2392 * 1) The element pushes the event as-is
2393 * 2) The element consumes the event and does not forward it
2394 * 3) The element consumes the event and creates another one instead
2395 * 4) The element pushes other serialized event before pushing out the
2398 * For each pad we have two lists to track serialized events:
2399 * 1) We received on input and expect to see (serialized_events)
2400 * 2) We received on input but don't expect to see (expired_events)
2402 * To detect events that are pushed in a different order from the one they were
2403 * received in we check that:
2405 * For each event being outputted:
2406 * If it is in the expired_events list:
2408 * If it is in the serialized_events list:
2409 * If there are other events that were received before:
2410 * Put those events on the expired_events list
2411 * Remove that event and any previous ones from the serialized_events list
2413 * Clear expired events list when flushing or on pad deactivation
2417 if (g_list_find (monitor->expired_events, event)) {
2418 gchar *event_str = _get_event_string (event);
2419 /* If it's the expired events, we've failed */
2420 GST_WARNING_OBJECT (pad, "Did not expect event %p %s", event,
2421 GST_EVENT_TYPE_NAME (event));
2422 GST_VALIDATE_REPORT (monitor, EVENT_SERIALIZED_OUT_OF_ORDER,
2423 "Serialized event was pushed out of order: %s", event_str);
2426 monitor->expired_events = g_list_remove (monitor->expired_events, event);
2427 gst_event_unref (event); /* remove the ref that was on the list */
2428 } else if (monitor->serialized_events->len) {
2429 for (i = 0; i < monitor->serialized_events->len; i++) {
2430 SerializedEventData *next_event =
2431 g_ptr_array_index (monitor->serialized_events, i);
2432 GST_DEBUG_OBJECT (pad, "Checking against stored event #%d: %p %s", i,
2433 next_event->event, GST_EVENT_TYPE_NAME (next_event->event));
2435 if (event == next_event->event
2436 || GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2437 /* We have found our event */
2438 GST_DEBUG_OBJECT (pad, "Found matching event");
2440 while (monitor->serialized_events->len > i
2441 && GST_EVENT_TYPE (event) == GST_EVENT_TYPE (next_event->event)) {
2442 /* Swallow all expected events of the same type */
2443 g_ptr_array_remove_index (monitor->serialized_events, i);
2444 next_event = g_ptr_array_index (monitor->serialized_events, i);
2447 /* Move all previous events to expired events */
2448 if (G_UNLIKELY (i > 0)) {
2449 GST_DEBUG_OBJECT (pad,
2450 "Moving previous expected events to expired list");
2452 next_event = g_ptr_array_index (monitor->serialized_events, 0);
2453 monitor->expired_events =
2454 g_list_append (monitor->expired_events,
2455 gst_event_ref (next_event->event));
2456 g_ptr_array_remove_index (monitor->serialized_events, 0);
2459 debug_pending_event (pad, monitor->serialized_events);
2466 /* This so far is just like an event that is flowing downstream,
2467 * so we do the same checks as a sinkpad event handler */
2468 gst_validate_pad_monitor_downstream_event_check (monitor, NULL, event, NULL);
2469 GST_VALIDATE_MONITOR_UNLOCK (monitor);
2470 GST_VALIDATE_PAD_MONITOR_PARENT_UNLOCK (monitor);
2473 static GstPadProbeReturn
2474 gst_validate_pad_monitor_pad_probe (GstPad * pad, GstPadProbeInfo * info,
2477 if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
2478 gst_validate_pad_monitor_buffer_probe (pad, info->data, udata,
2479 GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_PULL);
2480 else if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
2481 gst_validate_pad_monitor_event_probe (pad, info->data, udata);
2483 return GST_PAD_PROBE_OK;
2487 gst_validate_pad_monitor_update_caps_info (GstValidatePadMonitor * pad_monitor,
2490 GstStructure *structure;
2492 g_return_if_fail (gst_caps_is_fixed (caps));
2494 pad_monitor->caps_is_audio = FALSE;
2495 pad_monitor->caps_is_video = FALSE;
2497 structure = gst_caps_get_structure (caps, 0);
2498 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/")) {
2499 pad_monitor->caps_is_audio = TRUE;
2500 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/")) {
2501 pad_monitor->caps_is_video = TRUE;
2504 if (g_str_has_prefix (gst_structure_get_name (structure), "audio/x-raw") ||
2505 g_str_has_prefix (gst_structure_get_name (structure), "video/x-raw")) {
2506 pad_monitor->caps_is_raw = TRUE;
2508 pad_monitor->caps_is_raw = FALSE;
2513 gst_validate_pad_monitor_setcaps_pre (GstValidatePadMonitor * pad_monitor,
2516 GstStructure *structure;
2518 /* Check if caps are identical to last caps and complain if so
2519 * Only checked for sink pads as src pads might push the same caps
2520 * multiple times during unlinked/autoplugging scenarios */
2521 if (GST_PAD_IS_SINK (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor)) &&
2522 pad_monitor->last_caps
2523 && gst_caps_is_equal (caps, pad_monitor->last_caps)) {
2524 gchar *caps_str = gst_caps_to_string (caps);
2526 GST_VALIDATE_REPORT (pad_monitor, EVENT_CAPS_DUPLICATE, "%s", caps_str);
2531 gst_validate_pad_monitor_check_caps_complete (pad_monitor, caps);
2534 structure = gst_caps_get_structure (caps, 0);
2535 if (gst_structure_n_fields (pad_monitor->pending_setcaps_fields)) {
2538 i < gst_structure_n_fields (pad_monitor->pending_setcaps_fields);
2541 gst_structure_nth_field_name (pad_monitor->pending_setcaps_fields,
2543 const GValue *v = gst_structure_get_value (structure, name);
2544 const GValue *otherv =
2545 gst_structure_get_value (pad_monitor->pending_setcaps_fields, name);
2548 gchar *caps_str = gst_caps_to_string (caps);
2550 GST_VALIDATE_REPORT (pad_monitor, CAPS_EXPECTED_FIELD_NOT_FOUND,
2551 "Field %s is missing from setcaps caps '%s'", name, caps_str);
2553 } else if (gst_value_compare (v, otherv) != GST_VALUE_EQUAL) {
2554 gchar *caps_str = gst_caps_to_string (caps),
2555 *pending_setcaps_fields_str =
2556 gst_structure_to_string (pad_monitor->pending_setcaps_fields);
2559 GST_VALIDATE_REPORT (pad_monitor, CAPS_FIELD_UNEXPECTED_VALUE,
2560 "Field %s from setcaps caps '%s' is different "
2561 "from expected value in caps '%s'", name, caps_str,
2562 pending_setcaps_fields_str);
2564 g_free (pending_setcaps_fields_str);
2570 if (GST_PAD_IS_SINK (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor)) &&
2571 gst_validate_pad_monitor_pad_should_proxy_othercaps (pad_monitor)) {
2572 if (_structure_is_video (structure)) {
2573 GST_DEBUG_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor),
2574 "Adding video common pending fields to other pad: %" GST_PTR_FORMAT,
2576 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2577 structure, "width");
2578 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2579 structure, "height");
2580 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2581 structure, "framerate");
2582 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2583 structure, "pixel-aspect-ratio");
2584 } else if (_structure_is_audio (structure)) {
2585 GST_DEBUG_OBJECT (GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor),
2586 "Adding audio common pending fields to other pad: %" GST_PTR_FORMAT,
2588 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2590 gst_validate_pad_monitor_otherpad_add_pending_field (pad_monitor,
2591 structure, "channels");
2596 gst_structure_free (pad_monitor->pending_setcaps_fields);
2597 pad_monitor->pending_setcaps_fields =
2598 gst_structure_new_empty (PENDING_FIELDS);
2600 gst_validate_pad_monitor_setcaps_overrides (pad_monitor, caps);
2604 gst_validate_pad_monitor_setcaps_post (GstValidatePadMonitor * pad_monitor,
2605 GstCaps * caps, gboolean ret)
2608 gst_validate_pad_monitor_otherpad_clear_pending_fields (pad_monitor);
2610 if (pad_monitor->last_caps) {
2611 gst_caps_unref (pad_monitor->last_caps);
2613 pad_monitor->last_caps = gst_caps_ref (caps);
2614 gst_validate_pad_monitor_update_caps_info (pad_monitor, caps);
2619 gst_validate_pad_monitor_do_setup (GstValidateMonitor * monitor)
2621 GstValidatePadMonitor *pad_monitor = GST_VALIDATE_PAD_MONITOR_CAST (monitor);
2623 if (!GST_IS_PAD (GST_VALIDATE_MONITOR_GET_OBJECT (monitor))) {
2624 GST_WARNING_OBJECT (monitor, "Trying to create pad monitor with other "
2629 pad = GST_VALIDATE_PAD_MONITOR_GET_PAD (pad_monitor);
2631 if (g_object_get_data ((GObject *) pad, "validate-monitor")) {
2632 GST_WARNING_OBJECT (pad_monitor,
2633 "Pad already has a validate-monitor associated");
2637 g_object_set_data ((GObject *) pad, "validate-monitor", pad_monitor);
2639 pad_monitor->pad = pad;
2641 pad_monitor->event_func = GST_PAD_EVENTFUNC (pad);
2642 pad_monitor->event_full_func = GST_PAD_EVENTFULLFUNC (pad);
2643 pad_monitor->query_func = GST_PAD_QUERYFUNC (pad);
2644 pad_monitor->activatemode_func = GST_PAD_ACTIVATEMODEFUNC (pad);
2645 if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
2647 pad_monitor->chain_func = GST_PAD_CHAINFUNC (pad);
2648 if (pad_monitor->chain_func)
2649 gst_pad_set_chain_function (pad, gst_validate_pad_monitor_chain_func);
2651 if (pad_monitor->event_full_func)
2652 gst_pad_set_event_full_function (pad,
2653 gst_validate_pad_monitor_sink_event_full_func);
2655 gst_pad_set_event_function (pad,
2656 gst_validate_pad_monitor_sink_event_func);
2658 pad_monitor->getrange_func = GST_PAD_GETRANGEFUNC (pad);
2659 if (pad_monitor->getrange_func)
2660 gst_pad_set_getrange_function (pad, gst_validate_pad_get_range_func);
2662 gst_pad_set_event_function (pad, gst_validate_pad_monitor_src_event_func);
2664 /* add buffer/event probes */
2665 pad_monitor->pad_probe_id =
2666 gst_pad_add_probe (pad,
2667 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
2668 GST_PAD_PROBE_TYPE_EVENT_FLUSH,
2669 (GstPadProbeCallback) gst_validate_pad_monitor_pad_probe, pad_monitor,
2672 gst_pad_set_query_function (pad, gst_validate_pad_monitor_query_func);
2673 gst_pad_set_activatemode_function (pad,
2674 gst_validate_pad_monitor_activatemode_func);
2676 gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (monitor),
2677 g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad)));
2679 if (G_UNLIKELY (GST_PAD_PARENT (pad) == NULL))
2680 GST_FIXME ("Saw a pad not belonging to any object");