Branch data Line data Source code
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 : : */
22 : :
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 : : */
32 : :
33 : : #include "gstconsistencychecker.h"
34 : :
35 : : struct _GstStreamConsistency
36 : : {
37 : : gboolean flushing;
38 : : gboolean newsegment;
39 : : gboolean eos;
40 : : gulong probeid;
41 : : GstPad *pad;
42 : : };
43 : :
44 : : static gboolean
45 : 0 : source_pad_data_cb (GstPad * pad, GstMiniObject * data,
46 : : GstStreamConsistency * consist)
47 : : {
48 [ # # ][ # # ]: 0 : if (GST_IS_BUFFER (data)) {
[ # # ][ # # ]
49 [ # # ][ # # ]: 0 : GST_DEBUG_OBJECT (pad, "Buffer %" GST_TIME_FORMAT,
[ # # ][ # # ]
[ # # ]
50 : : GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (GST_BUFFER (data))));
51 : : /* If an EOS went through, a buffer would be invalid */
52 : 0 : fail_if (consist->eos, "Buffer received after EOS");
53 : : /* Buffers need to be preceded by a newsegment event */
54 : 0 : fail_unless (consist->newsegment, "Buffer received without newsegment");
55 [ # # ][ # # ]: 0 : } else if (GST_IS_EVENT (data)) {
[ # # ][ # # ]
56 : 0 : GstEvent *event = (GstEvent *) data;
57 : :
58 [ # # ]: 0 : GST_DEBUG_OBJECT (pad, "%s", GST_EVENT_TYPE_NAME (event));
59 [ # # # # : 0 : switch (GST_EVENT_TYPE (event)) {
# # ]
60 : : case GST_EVENT_FLUSH_START:
61 : 0 : consist->flushing = TRUE;
62 : 0 : break;
63 : : case GST_EVENT_FLUSH_STOP:
64 : : /* Receiving a flush-stop is only valid after receiving a flush-start */
65 : 0 : fail_unless (consist->flushing,
66 : : "Received a FLUSH_STOP without a FLUSH_START");
67 : 0 : fail_if (consist->eos, "Received a FLUSH_STOP after an EOS");
68 : 0 : consist->flushing = FALSE;
69 : 0 : break;
70 : : case GST_EVENT_NEWSEGMENT:
71 : 0 : consist->newsegment = TRUE;
72 : 0 : consist->eos = FALSE;
73 : 0 : break;
74 : : case GST_EVENT_EOS:
75 : : /* FIXME : not 100% sure about whether two eos in a row is valid */
76 : 0 : fail_if (consist->eos, "Received EOS just after another EOS");
77 : 0 : consist->eos = TRUE;
78 : 0 : consist->newsegment = FALSE;
79 : 0 : break;
80 : : case GST_EVENT_TAG:
81 [ # # ]: 0 : GST_DEBUG_OBJECT (pad, "tag %" GST_PTR_FORMAT, event->structure);
82 : : /* fall through */
83 : : default:
84 [ # # ][ # # ]: 0 : if (GST_EVENT_IS_SERIALIZED (event) && GST_EVENT_IS_DOWNSTREAM (event)) {
85 : 0 : fail_if (consist->eos, "Event received after EOS");
86 : 0 : fail_unless (consist->newsegment, "Event received before newsegment");
87 : : }
88 : : /* FIXME : Figure out what to do for other events */
89 : 0 : break;
90 : : }
91 : : }
92 : :
93 : 0 : return TRUE;
94 : : }
95 : :
96 : : /**
97 : : * gst_consistency_checker_new:
98 : : * @pad: The #GstPad on which the dataflow will be checked.
99 : : *
100 : : * Sets up a data probe on the given pad which will raise assertions if the
101 : : * data flow is inconsistent.
102 : : *
103 : : * Currently only works for source pads.
104 : : *
105 : : * Returns: A #GstStreamConsistency structure used to track data flow.
106 : : *
107 : : * Since: 0.10.24
108 : : */
109 : :
110 : : GstStreamConsistency *
111 : 0 : gst_consistency_checker_new (GstPad * pad)
112 : : {
113 : : GstStreamConsistency *consist;
114 : :
115 [ # # ]: 0 : g_return_val_if_fail (pad != NULL, NULL);
116 : :
117 : 0 : consist = g_new0 (GstStreamConsistency, 1);
118 : 0 : consist->pad = g_object_ref (pad);
119 : 0 : consist->probeid =
120 : 0 : gst_pad_add_data_probe (pad, (GCallback) source_pad_data_cb, consist);
121 : :
122 : 0 : return consist;
123 : : }
124 : :
125 : : /**
126 : : * gst_consistency_checker_reset:
127 : : * @consist: The #GstStreamConsistency to reset.
128 : : *
129 : : * Reset the stream checker's internal variables.
130 : : *
131 : : * Since: 0.10.24
132 : : */
133 : :
134 : : void
135 : 0 : gst_consistency_checker_reset (GstStreamConsistency * consist)
136 : : {
137 : 0 : consist->eos = FALSE;
138 : 0 : consist->flushing = FALSE;
139 : 0 : consist->newsegment = FALSE;
140 : 0 : }
141 : :
142 : : /**
143 : : * gst_consistency_checker_free:
144 : : * @consist: The #GstStreamConsistency to free.
145 : : *
146 : : * Frees the allocated data and probe associated with @consist.
147 : : *
148 : : * Since: 0.10.24
149 : : */
150 : :
151 : : void
152 : 0 : gst_consistency_checker_free (GstStreamConsistency * consist)
153 : : {
154 : : /* Remove the data probe */
155 : 0 : gst_pad_remove_data_probe (consist->pad, consist->probeid);
156 : 0 : g_object_unref (consist->pad);
157 : 0 : g_free (consist);
158 : 0 : }
|