Debian Codegraph @

libs/gst/check/gstharness.h

raw
1 /* GstHarness - A test-harness for GStreamer testing
2 *
3 * Copyright (C) 2012-2015 Pexip <pexip.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21 #ifndef __GST_HARNESS_H__
22 #define __GST_HARNESS_H__
23
24 #include <gst/gst.h>
25 #include <gst/check/gsttestclock.h>
26 #include <gst/check/check-prelude.h>
27
28 G_BEGIN_DECLS
29
30 /**
31 * GstHarnessThread:
32 *
33 * Opaque handle representing a GstHarness stress testing thread.
34 *
35 * Since: 1.6
36 */
37 typedef struct _GstHarnessThread GstHarnessThread;
38
39 typedef struct _GstHarness GstHarness;
40 typedef struct _GstHarnessPrivate GstHarnessPrivate;
41
42 /**
43 * GstHarness:
44 * @element: the element inside the harness
45 * @srcpad: the internal harness source pad
46 * @sinkpad: the internal harness sink pad
47 * @src_harness: the source (input) harness (if any)
48 * @sink_harness: the sink (output) harness (if any)
49 *
50 * Since: 1.6
51 */
52 struct _GstHarness {
53 GstElement * element;
54
55 GstPad * srcpad;
56 GstPad * sinkpad;
57
58 GstHarness * src_harness;
59 GstHarness * sink_harness;
60
61 /*< private >*/
62 GstHarnessPrivate * priv;
63 };
64
65 /* Harness creation */
66
67 GST_CHECK_API
68 GstHarness * gst_harness_new_empty (void);
69
70 GST_CHECK_API
71 void gst_harness_add_element_full (GstHarness * h,
72 GstElement * element,
73 GstStaticPadTemplate * hsrc,
74 const gchar * element_sinkpad_name,
75 GstStaticPadTemplate * hsink,
76 const gchar * element_srcpad_name);
77
78 GST_CHECK_API
79 GstHarness * gst_harness_new_full (GstElement * element,
80 GstStaticPadTemplate * hsrc,
81 const gchar * element_sinkpad_name,
82 GstStaticPadTemplate * hsink,
83 const gchar * element_srcpad_name);
84
85 GST_CHECK_API
86 GstHarness * gst_harness_new_with_element (GstElement * element,
87 const gchar * element_sinkpad_name,
88 const gchar * element_srcpad_name);
89
90 GST_CHECK_API
91 GstHarness * gst_harness_new_with_padnames (const gchar * element_name,
92 const gchar * element_sinkpad_name,
93 const gchar * element_srcpad_name);
94
95 GST_CHECK_API
96 GstHarness * gst_harness_new_with_templates (const gchar * element_name,
97 GstStaticPadTemplate * hsrc,
98 GstStaticPadTemplate * hsink);
99
100 GST_CHECK_API
101 GstHarness * gst_harness_new (const gchar * element_name);
102
103 GST_CHECK_API
104 GstHarness * gst_harness_new_parse (const gchar * launchline);
105
106 GST_CHECK_API
107 void gst_harness_add_parse (GstHarness * h, const gchar * launchline);
108
109 GST_CHECK_API
110 void gst_harness_teardown (GstHarness * h);
111
112 GST_CHECK_API
113 void gst_harness_add_element_src_pad (GstHarness * h, GstPad * srcpad);
114
115 GST_CHECK_API
116 void gst_harness_add_element_sink_pad (GstHarness * h, GstPad * sinkpad);
117
118 /* Caps Functions */
119
120 GST_CHECK_API
121 void gst_harness_set_src_caps (GstHarness * h, GstCaps * caps);
122
123 GST_CHECK_API
124 void gst_harness_set_sink_caps (GstHarness * h, GstCaps * caps);
125
126 GST_CHECK_API
127 void gst_harness_set_caps (GstHarness * h, GstCaps * in, GstCaps * out);
128
129 GST_CHECK_API
130 void gst_harness_set_src_caps_str (GstHarness * h, const gchar * str);
131
132 GST_CHECK_API
133 void gst_harness_set_sink_caps_str (GstHarness * h, const gchar * str);
134
135 GST_CHECK_API
136 void gst_harness_set_caps_str (GstHarness * h,
137 const gchar * in,
138 const gchar * out);
139
140 /* Clock Functions */
141
142 GST_CHECK_API
143 void gst_harness_use_systemclock (GstHarness * h);
144
145 GST_CHECK_API
146 void gst_harness_use_testclock (GstHarness * h);
147
148 GST_CHECK_API
149 GstTestClock * gst_harness_get_testclock (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
150
151 GST_CHECK_API
152 gboolean gst_harness_set_time (GstHarness * h, GstClockTime time);
153
154 GST_CHECK_API
155 gboolean gst_harness_wait_for_clock_id_waits (GstHarness * h,
156 guint waits,
157 guint timeout);
158
159 GST_CHECK_API
160 gboolean gst_harness_crank_single_clock_wait (GstHarness * h);
161
162 GST_CHECK_API
163 gboolean gst_harness_crank_multiple_clock_waits (GstHarness * h,
164 guint waits);
165
166 /* misc */
167
168 GST_CHECK_API
169 void gst_harness_play (GstHarness * h);
170
171 GST_CHECK_API
172 void gst_harness_set_blocking_push_mode (GstHarness * h);
173
174 GST_CHECK_API
175 void gst_harness_set_forwarding (GstHarness * h, gboolean forwarding);
176
177 /* buffers */
178
179 GST_CHECK_API
180 GstBuffer * gst_harness_create_buffer (GstHarness * h, gsize size) G_GNUC_WARN_UNUSED_RESULT;
181
182 GST_CHECK_API
183 GstFlowReturn gst_harness_push (GstHarness * h, GstBuffer * buffer);
184
185 GST_CHECK_API
186 GstBuffer * gst_harness_pull (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
187
188 GST_CHECK_API
189 GstBuffer * gst_harness_try_pull (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
190
191 GST_CHECK_API
192 gboolean gst_harness_pull_until_eos (GstHarness * h, GstBuffer ** buf);
193
194 GST_CHECK_API
195 GstBuffer * gst_harness_push_and_pull (GstHarness * h, GstBuffer * buffer) G_GNUC_WARN_UNUSED_RESULT;
196
197 GST_CHECK_API
198 guint gst_harness_buffers_received (GstHarness * h);
199
200 GST_CHECK_API
201 guint gst_harness_buffers_in_queue (GstHarness * h);
202
203 GST_CHECK_API
204 void gst_harness_set_drop_buffers (GstHarness * h, gboolean drop_buffers);
205
206 GST_CHECK_API
207 void gst_harness_dump_to_file (GstHarness * h, const gchar * filename);
208
209 GST_CHECK_API
210 guint8 * gst_harness_take_all_data (GstHarness * h, gsize * size) G_GNUC_WARN_UNUSED_RESULT;
211
212 GST_CHECK_API
213 GstBuffer * gst_harness_take_all_data_as_buffer (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
214
215 GST_CHECK_API
216 GBytes * gst_harness_take_all_data_as_bytes (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
217
218 GST_CHECK_API
219 GstClockTime gst_harness_get_last_pushed_timestamp (GstHarness * h);
220
221 /* downstream events */
222
223 GST_CHECK_API
224 gboolean gst_harness_push_event (GstHarness * h, GstEvent * event);
225
226 GST_CHECK_API
227 GstEvent * gst_harness_pull_event (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
228
229 GST_CHECK_API
230 GstEvent * gst_harness_try_pull_event (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
231
232 GST_CHECK_API
233 guint gst_harness_events_received (GstHarness * h);
234
235 GST_CHECK_API
236 guint gst_harness_events_in_queue (GstHarness * h);
237
238 /* upstream events */
239
240 GST_CHECK_API
241 gboolean gst_harness_push_upstream_event (GstHarness * h, GstEvent * event);
242
243 GST_CHECK_API
244 GstEvent * gst_harness_pull_upstream_event (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
245
246 GST_CHECK_API
247 GstEvent * gst_harness_try_pull_upstream_event (GstHarness * h) G_GNUC_WARN_UNUSED_RESULT;
248
249 GST_CHECK_API
250 guint gst_harness_upstream_events_received (GstHarness * h);
251
252 GST_CHECK_API
253 guint gst_harness_upstream_events_in_queue (GstHarness * h);
254
255 /* latency */
256
257 GST_CHECK_API
258 GstClockTime gst_harness_query_latency (GstHarness * h);
259
260 GST_CHECK_API
261 void gst_harness_set_upstream_latency (GstHarness * h, GstClockTime latency);
262
263 GST_CHECK_API
264 void gst_harness_set_live (GstHarness * h, gboolean is_live);
265
266 /* allocation query parameters */
267
268 GST_CHECK_API
269 void gst_harness_set_propose_allocator (GstHarness * h,
270 GstAllocator * allocator,
271 const GstAllocationParams * params);
272
273 GST_CHECK_API
274 void gst_harness_get_allocator (GstHarness * h,
275 GstAllocator ** allocator,
276 GstAllocationParams * params);
277
278 GST_CHECK_API
279 void gst_harness_add_propose_allocation_meta (GstHarness * h,
280 GType api,
281 const GstStructure * params);
282
283 /* src-harness */
284
285 GST_CHECK_API
286 void gst_harness_add_src_harness (GstHarness * h,
287 GstHarness * src_harness,
288 gboolean has_clock_wait);
289
290 GST_CHECK_API
291 void gst_harness_add_src (GstHarness * h,
292 const gchar * src_element_name,
293 gboolean has_clock_wait);
294
295 GST_CHECK_API
296 void gst_harness_add_src_parse (GstHarness * h,
297 const gchar * launchline,
298 gboolean has_clock_wait);
299
300 GST_CHECK_API
301 GstFlowReturn gst_harness_push_from_src (GstHarness * h);
302
303 GST_CHECK_API
304 GstFlowReturn gst_harness_src_crank_and_push_many (GstHarness * h,
305 gint cranks,
306 gint pushes);
307
308 GST_CHECK_API
309 gboolean gst_harness_src_push_event (GstHarness * h);
310
311 /* sink-harness */
312
313 GST_CHECK_API
314 void gst_harness_add_sink_harness (GstHarness * h,
315 GstHarness * sink_harness);
316
317 GST_CHECK_API
318 void gst_harness_add_sink (GstHarness * h,
319 const gchar * sink_element_name);
320
321 GST_CHECK_API
322 void gst_harness_add_sink_parse (GstHarness * h,
323 const gchar * launchline);
324
325 GST_CHECK_API
326 GstFlowReturn gst_harness_push_to_sink (GstHarness * h);
327
328 GST_CHECK_API
329 GstFlowReturn gst_harness_sink_push_many (GstHarness * h, gint pushes);
330
331 /* convenience functions */
332
333 GST_CHECK_API
334 GstElement * gst_harness_find_element (GstHarness * h,
335 const gchar * element_name) G_GNUC_WARN_UNUSED_RESULT;
336
337 GST_CHECK_API
338 void gst_harness_set (GstHarness * h,
339 const gchar * element_name,
340 const gchar * first_property_name, ...) G_GNUC_NULL_TERMINATED;
341
342 GST_CHECK_API
343 void gst_harness_get (GstHarness * h,
344 const gchar * element_name,
345 const gchar * first_property_name, ...) G_GNUC_NULL_TERMINATED;
346
347 GST_CHECK_API
348 void gst_harness_add_probe (GstHarness * h,
349 const gchar * element_name,
350 const gchar * pad_name,
351 GstPadProbeType mask,
352 GstPadProbeCallback callback,
353 gpointer user_data,
354 GDestroyNotify destroy_data);
355
356 /* Stress */
357
358 GST_CHECK_API
359 guint gst_harness_stress_thread_stop (GstHarnessThread * t);
360
361 GST_CHECK_API
362 GstHarnessThread * gst_harness_stress_custom_start (GstHarness * h,
363 GFunc init,
364 GFunc callback,
365 gpointer data,
366 gulong sleep);
367
368 #define gst_harness_stress_statechange_start(h) \
369 gst_harness_stress_statechange_start_full (h, G_USEC_PER_SEC / 100)
370
371 GST_CHECK_API
372 GstHarnessThread * gst_harness_stress_statechange_start_full (GstHarness * h,
373 gulong sleep);
374
375 #define gst_harness_stress_push_buffer_start(h, c, s, b) \
376 gst_harness_stress_push_buffer_start_full (h, c, s, b, 0)
377
378 GST_CHECK_API
379 GstHarnessThread * gst_harness_stress_push_buffer_start_full (GstHarness * h,
380 GstCaps * caps,
381 const GstSegment * segment,
382 GstBuffer * buf,
383 gulong sleep);
384
385 /**
386 * GstHarnessPrepareBufferFunc:
387 * @h: a #GstHarness
388 * @data: user data
389 *
390 * Since: 1.6
391 */
392 typedef GstBuffer * (*GstHarnessPrepareBufferFunc) (GstHarness * h, gpointer data);
393
394 #define gst_harness_stress_push_buffer_with_cb_start(h, c, s, f, d, n) \
395 gst_harness_stress_push_buffer_with_cb_start_full (h, c, s, f, d, n, 0)
396
397 GST_CHECK_API
398 GstHarnessThread * gst_harness_stress_push_buffer_with_cb_start_full (GstHarness * h,
399 GstCaps * caps,
400 const GstSegment * segment,
401 GstHarnessPrepareBufferFunc func,
402 gpointer data,
403 GDestroyNotify notify,
404 gulong sleep);
405
406 #define gst_harness_stress_push_event_start(h, e) \
407 gst_harness_stress_push_event_start_full (h, e, 0)
408
409 GST_CHECK_API
410 GstHarnessThread * gst_harness_stress_push_event_start_full (GstHarness * h,
411 GstEvent * event,
412 gulong sleep);
413
414 /**
415 * GstHarnessPrepareEventFunc:
416 * @h: a #GstHarness
417 * @data: user data
418 *
419 * Since: 1.8
420 */
421 typedef GstEvent * (*GstHarnessPrepareEventFunc) (GstHarness * h, gpointer data);
422
423 #define gst_harness_stress_push_event_with_cb_start(h, f, d, n) \
424 gst_harness_stress_push_event_with_cb_start_full (h, f, d, n, 0)
425
426 GST_CHECK_API
427 GstHarnessThread * gst_harness_stress_push_event_with_cb_start_full (GstHarness * h,
428 GstHarnessPrepareEventFunc func,
429 gpointer data,
430 GDestroyNotify notify,
431 gulong sleep);
432
433 #define gst_harness_stress_send_upstream_event_start(h, e) \
434 gst_harness_stress_push_upstream_event_start_full (h, e, 0)
435
436 GST_CHECK_API
437 GstHarnessThread * gst_harness_stress_push_upstream_event_start_full (GstHarness * h,
438 GstEvent * event,
439 gulong sleep);
440
441 #define gst_harness_stress_send_upstream_event_with_cb_start(h, f, d, n) \
442 gst_harness_stress_push_upstream_event_with_cb_start_full (h, f, d, n, 0)
443
444 GST_CHECK_API
445 GstHarnessThread * gst_harness_stress_push_upstream_event_with_cb_start_full (GstHarness * h,
446 GstHarnessPrepareEventFunc func,
447 gpointer data,
448 GDestroyNotify notify,
449 gulong sleep);
450
451
452 #define gst_harness_stress_property_start(h, n, v) \
453 gst_harness_stress_property_start_full (h, n, v, G_USEC_PER_SEC / 1000)
454
455 GST_CHECK_API
456 GstHarnessThread * gst_harness_stress_property_start_full (GstHarness * h,
457 const gchar * name,
458 const GValue * value,
459 gulong sleep);
460
461 #define gst_harness_stress_requestpad_start(h, t, n, c, r) \
462 gst_harness_stress_requestpad_start_full (h, t, n, c, r, G_USEC_PER_SEC / 100)
463
464 GST_CHECK_API
465 GstHarnessThread * gst_harness_stress_requestpad_start_full (GstHarness * h,
466 GstPadTemplate * templ,
467 const gchar * name,
468 GstCaps * caps,
469 gboolean release,
470 gulong sleep);
471
472 G_END_DECLS
473
474 #endif /* __GST_HARNESS_H__ */