affa6abd5e56e134c7b1dcbaaecba928ad125233
1 /* GStreamer
2 *
3 * unit testing helper lib
4 *
5 * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
23 /**
24 * SECTION:gstcheckconsistencychecker
25 * @short_description: Data flow consistency checker for GStreamer unit tests.
26 *
27 * These macros and functions are for internal use of the unit tests found
28 * inside the 'check' directories of various GStreamer packages.
29 *
30 * Since: 0.10.24
31 */
33 #include "gstconsistencychecker.h"
35 static gboolean
36 source_pad_data_cb (GstPad * pad, GstMiniObject * data,
37 GstStreamConsistency * consist)
38 {
39 if (GST_IS_BUFFER (data)) {
40 GST_DEBUG_OBJECT (pad, "Buffer %" GST_TIME_FORMAT,
41 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (GST_BUFFER (data))));
42 /* If an EOS went through, a buffer would be invalid */
43 fail_if (consist->eos, "Buffer received after EOS");
44 /* Buffers need to be preceded by a newsegment event */
45 fail_unless (consist->newsegment, "Buffer received without newsegment");
46 } else {
47 GstEvent *event = (GstEvent *) data;
49 GST_DEBUG_OBJECT (pad, "%s", GST_EVENT_TYPE_NAME (event));
50 switch (GST_EVENT_TYPE (event)) {
51 case GST_EVENT_FLUSH_START:
52 consist->flushing = TRUE;
53 break;
54 case GST_EVENT_FLUSH_STOP:
55 /* Receiving a flush-stop is only valid after receiving a flush-start */
56 fail_unless (consist->flushing,
57 "Received a FLUSH_STOP without a FLUSH_START");
58 fail_if (consist->eos, "Received a FLUSH_STOP after an EOS");
59 consist->flushing = FALSE;
60 break;
61 case GST_EVENT_NEWSEGMENT:
62 consist->newsegment = TRUE;
63 consist->eos = FALSE;
64 break;
65 case GST_EVENT_EOS:
66 /* FIXME : not 100% sure about whether two eos in a row is valid */
67 fail_if (consist->eos, "Received EOS just after another EOS");
68 consist->eos = TRUE;
69 consist->newsegment = FALSE;
70 break;
71 case GST_EVENT_TAG:
72 GST_DEBUG_OBJECT (pad, "tag %" GST_PTR_FORMAT, event->structure);
73 default:
74 if (GST_EVENT_IS_SERIALIZED (event) && GST_EVENT_IS_DOWNSTREAM (event)) {
75 fail_if (consist->eos, "Event received after EOS");
76 fail_unless (consist->newsegment, "Event received before newsegment");
77 }
78 /* FIXME : Figure out what to do for other events */
79 break;
80 }
81 }
83 return TRUE;
84 }
86 /**
87 * gst_consistency_checker_new:
88 * @pad: The #GstPad on which the dataflow will be checked.
89 *
90 * Sets up a data probe on the given pad which will raise assertions if the
91 * data flow is inconsistent.
92 *
93 * Currently only works for source pads.
94 *
95 * Returns: A #GstStreamConsistency structure used to track data flow.
96 *
97 * Since: 0.10.24
98 */
100 GstStreamConsistency *
101 gst_consistency_checker_new (GstPad * pad)
102 {
103 GstStreamConsistency *consist;
105 g_return_val_if_fail (pad != NULL, NULL);
107 consist = g_new0 (GstStreamConsistency, 1);
108 consist->pad = g_object_ref (pad);
109 consist->probeid =
110 gst_pad_add_data_probe (pad, (GCallback) source_pad_data_cb, consist);
112 return consist;
113 }
115 /**
116 * gst_consistency_checker_reset:
117 * @consist: The #GstStreamConsistency to reset.
118 *
119 * Reset the stream checker's internal variables.
120 *
121 * Since: 0.10.24
122 */
124 void
125 gst_consistency_checker_reset (GstStreamConsistency * consist)
126 {
127 consist->eos = FALSE;
128 consist->flushing = FALSE;
129 consist->newsegment = FALSE;
130 }
132 /**
133 * gst_consistency_checker_free:
134 * @consist: The #GstStreamConsistency to free.
135 *
136 * Frees the allocated data and probe associated with @consist.
137 *
138 * Since: 0.10.24
139 */
141 void
142 gst_consistency_checker_free (GstStreamConsistency * consist)
143 {
144 /* Remove the data probe */
145 gst_pad_remove_data_probe (consist->pad, consist->probeid);
146 g_object_unref (consist->pad);
147 g_free (consist);
148 }