| 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 |
/** |
| 22 |
* SECTION:gstharness |
| 23 |
* @title: GstHarness |
| 24 |
* @short_description: A test-harness for writing GStreamer unit tests |
| 25 |
* @see_also: #GstTestClock |
| 26 |
* |
| 27 |
* #GstHarness is meant to make writing unit test for GStreamer much easier. |
| 28 |
* It can be thought of as a way of treating a #GstElement as a black box, |
| 29 |
* deterministically feeding it data, and controlling what data it outputs. |
| 30 |
* |
| 31 |
* The basic structure of #GstHarness is two "floating" #GstPads that connect |
| 32 |
* to the harnessed #GstElement src and sink #GstPads like so: |
| 33 |
* |
| 34 |
* |[ |
| 35 |
* __________________________ |
| 36 |
* _____ | _____ _____ | _____ |
| 37 |
* | | | | | | | | | | |
| 38 |
* | src |--+-| sink| Element | src |-+--| sink| |
| 39 |
* |_____| | |_____| |_____| | |_____| |
| 40 |
* |__________________________| |
| 41 |
* |
| 42 |
* ]| |
| 43 |
* |
| 44 |
* With this, you can now simulate any environment the #GstElement might find |
| 45 |
* itself in. By specifying the #GstCaps of the harness #GstPads, using |
| 46 |
* functions like gst_harness_set_src_caps() or gst_harness_set_sink_caps_str(), |
| 47 |
* you can test how the #GstElement interacts with different caps sets. |
| 48 |
* |
| 49 |
* Your harnessed #GstElement can of course also be a bin, and using |
| 50 |
* gst_harness_new_parse() supporting standard gst-launch syntax, you can |
| 51 |
* easily test a whole pipeline instead of just one element. |
| 52 |
* |
| 53 |
* You can then go on to push #GstBuffers and #GstEvents on to the srcpad, |
| 54 |
* using functions like gst_harness_push() and gst_harness_push_event(), and |
| 55 |
* then pull them out to examine them with gst_harness_pull() and |
| 56 |
* gst_harness_pull_event(). |
| 57 |
* |
| 58 |
* ## A simple buffer-in buffer-out example |
| 59 |
* |
| 60 |
* |[<!-- language="C" --> |
| 61 |
* #include <gst/gst.h> |
| 62 |
* #include <gst/check/gstharness.h> |
| 63 |
* GstHarness *h; |
| 64 |
* GstBuffer *in_buf; |
| 65 |
* GstBuffer *out_buf; |
| 66 |
* |
| 67 |
* // attach the harness to the src and sink pad of GstQueue |
| 68 |
* h = gst_harness_new ("queue"); |
| 69 |
* |
| 70 |
* // we must specify a caps before pushing buffers |
| 71 |
* gst_harness_set_src_caps_str (h, "mycaps"); |
| 72 |
* |
| 73 |
* // create a buffer of size 42 |
| 74 |
* in_buf = gst_harness_create_buffer (h, 42); |
| 75 |
* |
| 76 |
* // push the buffer into the queue |
| 77 |
* gst_harness_push (h, in_buf); |
| 78 |
* |
| 79 |
* // pull the buffer from the queue |
| 80 |
* out_buf = gst_harness_pull (h); |
| 81 |
* |
| 82 |
* // validate the buffer in is the same as buffer out |
| 83 |
* fail_unless (in_buf == out_buf); |
| 84 |
* |
| 85 |
* // cleanup |
| 86 |
* gst_buffer_unref (out_buf); |
| 87 |
* gst_harness_teardown (h); |
| 88 |
* |
| 89 |
* ]| |
| 90 |
* |
| 91 |
* Another main feature of the #GstHarness is its integration with the |
| 92 |
* #GstTestClock. Operating the #GstTestClock can be very challenging, but |
| 93 |
* #GstHarness simplifies some of the most desired actions a lot, like wanting |
| 94 |
* to manually advance the clock while at the same time releasing a #GstClockID |
| 95 |
* that is waiting, with functions like gst_harness_crank_single_clock_wait(). |
| 96 |
* |
| 97 |
* #GstHarness also supports sub-harnesses, as a way of generating and |
| 98 |
* validating data. A sub-harness is another #GstHarness that is managed by |
| 99 |
* the "parent" harness, and can either be created by using the standard |
| 100 |
* gst_harness_new type functions directly on the (GstHarness *)->src_harness, |
| 101 |
* or using the much more convenient gst_harness_add_src() or |
| 102 |
* gst_harness_add_sink_parse(). If you have a decoder-element you want to test, |
| 103 |
* (like vp8dec) it can be very useful to add a src-harness with both a |
| 104 |
* src-element (videotestsrc) and an encoder (vp8enc) to feed the decoder data |
| 105 |
* with different configurations, by simply doing: |
| 106 |
* |
| 107 |
* |[<!-- language="C" --> |
| 108 |
* GstHarness * h = gst_harness_new ("vp8dec"); |
| 109 |
* gst_harness_add_src_parse (h, "videotestsrc is-live=1 ! vp8enc", TRUE); |
| 110 |
* ]| |
| 111 |
* |
| 112 |
* and then feeding it data with: |
| 113 |
* |
| 114 |
* |[<!-- language="C" --> |
| 115 |
* gst_harness_push_from_src (h); |
| 116 |
* ]| |
| 117 |
* |
| 118 |
*/ |
| 119 |
#ifdef HAVE_CONFIG_H |
| 120 |
#include "config.h" |
| 121 |
#endif |
| 122 |
|
| 123 |
/* we have code with side effects in asserts, so make sure they are active */ |
| 124 |
#ifdef G_DISABLE_ASSERT |
| 125 |
#error "GstHarness must be compiled with G_DISABLE_ASSERT undefined" |
| 126 |
#endif |
| 127 |
|
| 128 |
#include "gstharness.h" |
| 129 |
#include "gstharnesslink.h" |
| 130 |
|
| 131 |
#include <stdio.h> |
| 132 |
#include <string.h> |
| 133 |
#include <math.h> |
| 134 |
|
| 135 |
static void gst_harness_stress_free (GstHarnessThread * t); |
| 136 |
|
| 137 |
/* Keys used for storing and retrieving associations to pads and elements with |
| 138 |
* g_object_set_data (): */ |
| 139 |
/* The HARNESS_REF association inside a GstElement will keep track of how many |
| 140 |
* GstHarness'es are attached to that element. */ |
| 141 |
#define HARNESS_REF "harness-ref" |
| 142 |
|
| 143 |
#define HARNESS_LOCK(h) g_mutex_lock (&(h)->priv->priv_mutex) |
| 144 |
#define HARNESS_UNLOCK(h) g_mutex_unlock (&(h)->priv->priv_mutex) |
| 145 |
|
| 146 |
static GstStaticPadTemplate hsrctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
| 147 |
GST_PAD_SRC, |
| 148 |
GST_PAD_ALWAYS, |
| 149 |
GST_STATIC_CAPS_ANY); |
| 150 |
static GstStaticPadTemplate hsinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
| 151 |
GST_PAD_SINK, |
| 152 |
GST_PAD_ALWAYS, |
| 153 |
GST_STATIC_CAPS_ANY); |
| 154 |
|
| 155 |
typedef struct |
| 156 |
{ |
| 157 |
GType api; |
| 158 |
GstStructure *params; |
| 159 |
} ProposeMeta; |
| 160 |
|
| 161 |
static void |
| 162 |
propose_meta_clear (ProposeMeta * meta) |
| 163 |
{ |
| 164 |
if (meta->params) |
| 165 |
gst_structure_free (meta->params); |
| 166 |
} |
| 167 |
|
| 168 |
struct _GstHarnessPrivate |
| 169 |
{ |
| 170 |
gchar *element_sinkpad_name; |
| 171 |
gchar *element_srcpad_name; |
| 172 |
|
| 173 |
GstCaps *src_caps; |
| 174 |
GstCaps *sink_caps; |
| 175 |
|
| 176 |
gboolean forwarding; |
| 177 |
GstPad *sink_forward_pad; |
| 178 |
GstTestClock *testclock; |
| 179 |
|
| 180 |
gint recv_buffers; |
| 181 |
gint recv_events; |
| 182 |
gint recv_upstream_events; |
| 183 |
|
| 184 |
GAsyncQueue *buffer_queue; |
| 185 |
GAsyncQueue *src_event_queue; |
| 186 |
GAsyncQueue *sink_event_queue; |
| 187 |
|
| 188 |
GstClockTime latency_min; |
| 189 |
GstClockTime latency_max; |
| 190 |
gboolean is_live; |
| 191 |
|
| 192 |
gboolean has_clock_wait; |
| 193 |
gboolean drop_buffers; |
| 194 |
GstClockTime last_push_ts; |
| 195 |
|
| 196 |
GstBufferPool *pool; |
| 197 |
GstAllocator *allocator; |
| 198 |
GstAllocationParams allocation_params; |
| 199 |
GstAllocator *propose_allocator; |
| 200 |
GstAllocationParams propose_allocation_params; |
| 201 |
|
| 202 |
GArray *propose_allocation_metas; |
| 203 |
|
| 204 |
gboolean blocking_push_mode; |
| 205 |
GCond blocking_push_cond; |
| 206 |
GMutex blocking_push_mutex; |
| 207 |
GMutex priv_mutex; |
| 208 |
|
| 209 |
GCond buf_or_eos_cond; |
| 210 |
GMutex buf_or_eos_mutex; |
| 211 |
gboolean eos_received; |
| 212 |
|
| 213 |
GPtrArray *stress; |
| 214 |
}; |
| 215 |
|
| 216 |
static GstFlowReturn |
| 217 |
gst_harness_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) |
| 218 |
{ |
| 219 |
GstHarness *h; |
| 220 |
GstHarnessLink *link; |
| 221 |
GstHarnessPrivate *priv; |
| 222 |
(void) parent; |
| 223 |
|
| 224 |
if (!(link = gst_harness_pad_link_lock (pad, &h))) |
| 225 |
return GST_FLOW_FLUSHING; |
| 226 |
g_assert (h != NULL); |
| 227 |
priv = h->priv; |
| 228 |
|
| 229 |
g_mutex_lock (&priv->blocking_push_mutex); |
| 230 |
g_atomic_int_inc (&priv->recv_buffers); |
| 231 |
|
| 232 |
if (priv->drop_buffers) { |
| 233 |
gst_buffer_unref (buffer); |
| 234 |
} else { |
| 235 |
g_mutex_lock (&priv->buf_or_eos_mutex); |
| 236 |
g_async_queue_push (priv->buffer_queue, buffer); |
| 237 |
g_cond_signal (&priv->buf_or_eos_cond); |
| 238 |
g_mutex_unlock (&priv->buf_or_eos_mutex); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
if (priv->blocking_push_mode) { |
| 243 |
g_cond_wait (&priv->blocking_push_cond, &priv->blocking_push_mutex); |
| 244 |
} |
| 245 |
g_mutex_unlock (&priv->blocking_push_mutex); |
| 246 |
|
| 247 |
gst_harness_link_unlock (link); |
| 248 |
return GST_FLOW_OK; |
| 249 |
} |
| 250 |
|
| 251 |
static gboolean |
| 252 |
gst_harness_src_event (GstPad * pad, GstObject * parent, GstEvent * event) |
| 253 |
{ |
| 254 |
GstHarness *h; |
| 255 |
GstHarnessLink *link; |
| 256 |
GstHarnessPrivate *priv; |
| 257 |
(void) parent; |
| 258 |
|
| 259 |
if (!(link = gst_harness_pad_link_lock (pad, &h))) |
| 260 |
return FALSE; |
| 261 |
g_assert (h != NULL); |
| 262 |
priv = h->priv; |
| 263 |
|
| 264 |
g_atomic_int_inc (&priv->recv_upstream_events); |
| 265 |
g_async_queue_push (priv->src_event_queue, event); |
| 266 |
|
| 267 |
gst_harness_link_unlock (link); |
| 268 |
return TRUE; |
| 269 |
} |
| 270 |
|
| 271 |
static gboolean |
| 272 |
gst_harness_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) |
| 273 |
{ |
| 274 |
GstHarness *h; |
| 275 |
GstHarnessLink *link; |
| 276 |
GstHarnessPrivate *priv; |
| 277 |
gboolean ret = TRUE; |
| 278 |
gboolean forward; |
| 279 |
(void) parent; |
| 280 |
|
| 281 |
if (!(link = gst_harness_pad_link_lock (pad, &h))) |
| 282 |
return FALSE; |
| 283 |
g_assert (h != NULL); |
| 284 |
priv = h->priv; |
| 285 |
|
| 286 |
g_atomic_int_inc (&priv->recv_events); |
| 287 |
|
| 288 |
switch (GST_EVENT_TYPE (event)) { |
| 289 |
case GST_EVENT_STREAM_START: |
| 290 |
case GST_EVENT_CAPS: |
| 291 |
case GST_EVENT_SEGMENT: |
| 292 |
forward = TRUE; |
| 293 |
break; |
| 294 |
default: |
| 295 |
forward = FALSE; |
| 296 |
break; |
| 297 |
} |
| 298 |
|
| 299 |
HARNESS_LOCK (h); |
| 300 |
if (priv->forwarding && forward && priv->sink_forward_pad) { |
| 301 |
GstPad *fwdpad = gst_object_ref (priv->sink_forward_pad); |
| 302 |
HARNESS_UNLOCK (h); |
| 303 |
ret = gst_pad_push_event (fwdpad, event); |
| 304 |
gst_object_unref (fwdpad); |
| 305 |
HARNESS_LOCK (h); |
| 306 |
} else { |
| 307 |
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) { |
| 308 |
g_mutex_lock (&priv->buf_or_eos_mutex); |
| 309 |
priv->eos_received = TRUE; |
| 310 |
g_cond_signal (&priv->buf_or_eos_cond); |
| 311 |
g_mutex_unlock (&priv->buf_or_eos_mutex); |
| 312 |
} |
| 313 |
g_async_queue_push (priv->sink_event_queue, event); |
| 314 |
} |
| 315 |
HARNESS_UNLOCK (h); |
| 316 |
|
| 317 |
gst_harness_link_unlock (link); |
| 318 |
return ret; |
| 319 |
} |
| 320 |
|
| 321 |
static void |
| 322 |
gst_harness_decide_allocation (GstHarness * h, GstCaps * caps) |
| 323 |
{ |
| 324 |
GstHarnessPrivate *priv = h->priv; |
| 325 |
GstQuery *query; |
| 326 |
GstAllocator *allocator; |
| 327 |
GstAllocationParams params; |
| 328 |
GstBufferPool *pool = NULL; |
| 329 |
guint size, min, max; |
| 330 |
|
| 331 |
query = gst_query_new_allocation (caps, FALSE); |
| 332 |
gst_pad_peer_query (h->srcpad, query); |
| 333 |
|
| 334 |
if (gst_query_get_n_allocation_params (query) > 0) { |
| 335 |
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms); |
| 336 |
} else { |
| 337 |
allocator = NULL; |
| 338 |
gst_allocation_params_init (¶ms); |
| 339 |
} |
| 340 |
|
| 341 |
if (gst_query_get_n_allocation_pools (query) > 0) { |
| 342 |
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max); |
| 343 |
#if 0 |
| 344 |
/* Most elements create their own pools if pool == NULL. Not sure if we |
| 345 |
* want to do that in the harness since we may want to test the pool |
| 346 |
* implementation of the elements. Not creating a pool will however ignore |
| 347 |
* the returned size. */ |
| 348 |
if (pool == NULL) |
| 349 |
pool = gst_buffer_pool_new (); |
| 350 |
#endif |
| 351 |
} else { |
| 352 |
pool = NULL; |
| 353 |
size = min = max = 0; |
| 354 |
} |
| 355 |
gst_query_unref (query); |
| 356 |
|
| 357 |
if (pool) { |
| 358 |
GstStructure *config = gst_buffer_pool_get_config (pool); |
| 359 |
gst_buffer_pool_config_set_params (config, caps, size, min, max); |
| 360 |
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms); |
| 361 |
gst_buffer_pool_set_config (pool, config); |
| 362 |
} |
| 363 |
|
| 364 |
if (pool != priv->pool) { |
| 365 |
if (priv->pool != NULL) |
| 366 |
gst_buffer_pool_set_active (priv->pool, FALSE); |
| 367 |
if (pool) |
| 368 |
gst_buffer_pool_set_active (pool, TRUE); |
| 369 |
} |
| 370 |
|
| 371 |
priv->allocation_params = params; |
| 372 |
if (priv->allocator) |
| 373 |
gst_object_unref (priv->allocator); |
| 374 |
priv->allocator = allocator; |
| 375 |
if (priv->pool) |
| 376 |
gst_object_unref (priv->pool); |
| 377 |
priv->pool = pool; |
| 378 |
} |
| 379 |
|
| 380 |
static void |
| 381 |
gst_harness_negotiate (GstHarness * h) |
| 382 |
{ |
| 383 |
GstCaps *caps; |
| 384 |
|
| 385 |
caps = gst_pad_get_current_caps (h->srcpad); |
| 386 |
if (caps != NULL) { |
| 387 |
gst_harness_decide_allocation (h, caps); |
| 388 |
gst_caps_unref (caps); |
| 389 |
} else { |
| 390 |
GST_FIXME_OBJECT (h->srcpad, |
| 391 |
"Cannot negotiate allocation because caps is not set"); |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
static gboolean |
| 396 |
gst_harness_sink_query (GstPad * pad, GstObject * parent, GstQuery * query) |
| 397 |
{ |
| 398 |
GstHarness *h; |
| 399 |
GstHarnessLink *link; |
| 400 |
GstHarnessPrivate *priv; |
| 401 |
gboolean res = TRUE; |
| 402 |
(void) parent; |
| 403 |
|
| 404 |
if (!(link = gst_harness_pad_link_lock (pad, &h))) |
| 405 |
return FALSE; |
| 406 |
g_assert (h != NULL); |
| 407 |
priv = h->priv; |
| 408 |
|
| 409 |
// FIXME: forward all queries? |
| 410 |
|
| 411 |
switch (GST_QUERY_TYPE (query)) { |
| 412 |
case GST_QUERY_LATENCY: |
| 413 |
gst_query_set_latency (query, priv->is_live, priv->latency_min, |
| 414 |
priv->latency_max); |
| 415 |
break; |
| 416 |
case GST_QUERY_CAPS: |
| 417 |
{ |
| 418 |
GstCaps *caps, *filter = NULL; |
| 419 |
|
| 420 |
if (priv->sink_caps) { |
| 421 |
caps = gst_caps_ref (priv->sink_caps); |
| 422 |
} else { |
| 423 |
caps = gst_pad_get_pad_template_caps (pad); |
| 424 |
} |
| 425 |
|
| 426 |
gst_query_parse_caps (query, &filter); |
| 427 |
if (filter != NULL) { |
| 428 |
gst_caps_take (&caps, |
| 429 |
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST)); |
| 430 |
} |
| 431 |
|
| 432 |
gst_query_set_caps_result (query, caps); |
| 433 |
gst_caps_unref (caps); |
| 434 |
} |
| 435 |
break; |
| 436 |
case GST_QUERY_ALLOCATION: |
| 437 |
{ |
| 438 |
HARNESS_LOCK (h); |
| 439 |
if (priv->forwarding && priv->sink_forward_pad != NULL) { |
| 440 |
GstPad *peer = gst_pad_get_peer (priv->sink_forward_pad); |
| 441 |
g_assert (peer != NULL); |
| 442 |
HARNESS_UNLOCK (h); |
| 443 |
res = gst_pad_query (peer, query); |
| 444 |
gst_object_unref (peer); |
| 445 |
HARNESS_LOCK (h); |
| 446 |
} else { |
| 447 |
GstCaps *caps; |
| 448 |
gboolean need_pool; |
| 449 |
guint size; |
| 450 |
|
| 451 |
gst_query_parse_allocation (query, &caps, &need_pool); |
| 452 |
|
| 453 |
/* FIXME: Can this be removed? */ |
| 454 |
size = gst_query_get_n_allocation_params (query); |
| 455 |
g_assert_cmpuint (0, ==, size); |
| 456 |
gst_query_add_allocation_param (query, |
| 457 |
priv->propose_allocator, &priv->propose_allocation_params); |
| 458 |
|
| 459 |
if (priv->propose_allocation_metas) { |
| 460 |
guint i; |
| 461 |
for (i = 0; i < priv->propose_allocation_metas->len; i++) { |
| 462 |
ProposeMeta *meta = |
| 463 |
&g_array_index (priv->propose_allocation_metas, ProposeMeta, i); |
| 464 |
gst_query_add_allocation_meta (query, meta->api, meta->params); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
GST_DEBUG_OBJECT (pad, "proposing allocation %" GST_PTR_FORMAT, |
| 469 |
priv->propose_allocator); |
| 470 |
} |
| 471 |
HARNESS_UNLOCK (h); |
| 472 |
break; |
| 473 |
} |
| 474 |
case GST_QUERY_CONTEXT: |
| 475 |
HARNESS_LOCK (h); |
| 476 |
if (priv->forwarding && priv->sink_forward_pad != NULL) { |
| 477 |
GstPad *peer = gst_pad_get_peer (priv->sink_forward_pad); |
| 478 |
g_assert (peer != NULL); |
| 479 |
HARNESS_UNLOCK (h); |
| 480 |
res = gst_pad_query (peer, query); |
| 481 |
gst_object_unref (peer); |
| 482 |
} else { |
| 483 |
HARNESS_UNLOCK (h); |
| 484 |
res = gst_pad_query_default (pad, parent, query); |
| 485 |
} |
| 486 |
break; |
| 487 |
default: |
| 488 |
res = gst_pad_query_default (pad, parent, query); |
| 489 |
} |
| 490 |
|
| 491 |
gst_harness_link_unlock (link); |
| 492 |
return res; |
| 493 |
} |
| 494 |
|
| 495 |
static gboolean |
| 496 |
gst_harness_src_query (GstPad * pad, GstObject * parent, GstQuery * query) |
| 497 |
{ |
| 498 |
GstHarness *h; |
| 499 |
GstHarnessLink *link; |
| 500 |
GstHarnessPrivate *priv; |
| 501 |
gboolean res = TRUE; |
| 502 |
(void) parent; |
| 503 |
|
| 504 |
if (!(link = gst_harness_pad_link_lock (pad, &h))) |
| 505 |
return FALSE; |
| 506 |
g_assert (h != NULL); |
| 507 |
priv = h->priv; |
| 508 |
|
| 509 |
switch (GST_QUERY_TYPE (query)) { |
| 510 |
case GST_QUERY_LATENCY: |
| 511 |
gst_query_set_latency (query, priv->is_live, priv->latency_min, |
| 512 |
priv->latency_max); |
| 513 |
break; |
| 514 |
case GST_QUERY_CAPS: |
| 515 |
{ |
| 516 |
GstCaps *caps, *filter = NULL; |
| 517 |
|
| 518 |
if (priv->src_caps) { |
| 519 |
caps = gst_caps_ref (priv->src_caps); |
| 520 |
} else { |
| 521 |
caps = gst_pad_get_pad_template_caps (pad); |
| 522 |
} |
| 523 |
|
| 524 |
gst_query_parse_caps (query, &filter); |
| 525 |
if (filter != NULL) { |
| 526 |
gst_caps_take (&caps, |
| 527 |
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST)); |
| 528 |
} |
| 529 |
|
| 530 |
gst_query_set_caps_result (query, caps); |
| 531 |
gst_caps_unref (caps); |
| 532 |
} |
| 533 |
break; |
| 534 |
default: |
| 535 |
res = gst_pad_query_default (pad, parent, query); |
| 536 |
} |
| 537 |
gst_harness_link_unlock (link); |
| 538 |
return res; |
| 539 |
} |
| 540 |
|
| 541 |
static void |
| 542 |
gst_harness_element_ref (GstHarness * h) |
| 543 |
{ |
| 544 |
guint *data; |
| 545 |
|
| 546 |
GST_OBJECT_LOCK (h->element); |
| 547 |
data = g_object_get_data (G_OBJECT (h->element), HARNESS_REF); |
| 548 |
if (data == NULL) { |
| 549 |
data = g_new0 (guint, 1); |
| 550 |
*data = 1; |
| 551 |
g_object_set_data_full (G_OBJECT (h->element), HARNESS_REF, data, g_free); |
| 552 |
} else { |
| 553 |
(*data)++; |
| 554 |
} |
| 555 |
GST_OBJECT_UNLOCK (h->element); |
| 556 |
} |
| 557 |
|
| 558 |
static guint |
| 559 |
gst_harness_element_unref (GstHarness * h) |
| 560 |
{ |
| 561 |
guint *data; |
| 562 |
guint ret; |
| 563 |
|
| 564 |
GST_OBJECT_LOCK (h->element); |
| 565 |
data = g_object_get_data (G_OBJECT (h->element), HARNESS_REF); |
| 566 |
g_assert (data != NULL); |
| 567 |
(*data)--; |
| 568 |
ret = *data; |
| 569 |
GST_OBJECT_UNLOCK (h->element); |
| 570 |
|
| 571 |
return ret; |
| 572 |
} |
| 573 |
|
| 574 |
static void |
| 575 |
gst_harness_link_element_srcpad (GstHarness * h, |
| 576 |
const gchar * element_srcpad_name) |
| 577 |
{ |
| 578 |
GstHarnessPrivate *priv = h->priv; |
| 579 |
GstPad *srcpad = gst_element_get_static_pad (h->element, |
| 580 |
element_srcpad_name); |
| 581 |
GstPadLinkReturn link; |
| 582 |
if (srcpad == NULL) |
| 583 |
srcpad = gst_element_request_pad_simple (h->element, element_srcpad_name); |
| 584 |
g_assert (srcpad); |
| 585 |
link = gst_pad_link (srcpad, h->sinkpad); |
| 586 |
g_assert_cmpint (link, ==, GST_PAD_LINK_OK); |
| 587 |
g_free (priv->element_srcpad_name); |
| 588 |
priv->element_srcpad_name = gst_pad_get_name (srcpad); |
| 589 |
|
| 590 |
gst_object_unref (srcpad); |
| 591 |
} |
| 592 |
|
| 593 |
static void |
| 594 |
gst_harness_link_element_sinkpad (GstHarness * h, |
| 595 |
const gchar * element_sinkpad_name) |
| 596 |
{ |
| 597 |
GstHarnessPrivate *priv = h->priv; |
| 598 |
GstPad *sinkpad = gst_element_get_static_pad (h->element, |
| 599 |
element_sinkpad_name); |
| 600 |
GstPadLinkReturn link; |
| 601 |
if (sinkpad == NULL) |
| 602 |
sinkpad = gst_element_request_pad_simple (h->element, element_sinkpad_name); |
| 603 |
g_assert (sinkpad); |
| 604 |
link = gst_pad_link (h->srcpad, sinkpad); |
| 605 |
g_assert_cmpint (link, ==, GST_PAD_LINK_OK); |
| 606 |
g_free (priv->element_sinkpad_name); |
| 607 |
priv->element_sinkpad_name = gst_pad_get_name (sinkpad); |
| 608 |
|
| 609 |
gst_object_unref (sinkpad); |
| 610 |
} |
| 611 |
|
| 612 |
static void |
| 613 |
gst_harness_setup_src_pad (GstHarness * h, |
| 614 |
GstStaticPadTemplate * src_tmpl, const gchar * element_sinkpad_name) |
| 615 |
{ |
| 616 |
g_assert (src_tmpl); |
| 617 |
g_assert (h->srcpad == NULL); |
| 618 |
|
| 619 |
/* sending pad */ |
| 620 |
h->srcpad = gst_pad_new_from_static_template (src_tmpl, "src"); |
| 621 |
g_assert (h->srcpad); |
| 622 |
|
| 623 |
gst_harness_pad_link_set (h->srcpad, h); |
| 624 |
gst_pad_set_query_function (h->srcpad, gst_harness_src_query); |
| 625 |
gst_pad_set_event_function (h->srcpad, gst_harness_src_event); |
| 626 |
|
| 627 |
gst_pad_set_active (h->srcpad, TRUE); |
| 628 |
|
| 629 |
if (element_sinkpad_name) |
| 630 |
gst_harness_link_element_sinkpad (h, element_sinkpad_name); |
| 631 |
} |
| 632 |
|
| 633 |
static void |
| 634 |
gst_harness_setup_sink_pad (GstHarness * h, |
| 635 |
GstStaticPadTemplate * sink_tmpl, const gchar * element_srcpad_name) |
| 636 |
{ |
| 637 |
g_assert (sink_tmpl); |
| 638 |
g_assert (h->sinkpad == NULL); |
| 639 |
|
| 640 |
/* receiving pad */ |
| 641 |
h->sinkpad = gst_pad_new_from_static_template (sink_tmpl, "sink"); |
| 642 |
g_assert (h->sinkpad); |
| 643 |
|
| 644 |
gst_harness_pad_link_set (h->sinkpad, h); |
| 645 |
gst_pad_set_chain_function (h->sinkpad, gst_harness_chain); |
| 646 |
gst_pad_set_query_function (h->sinkpad, gst_harness_sink_query); |
| 647 |
gst_pad_set_event_function (h->sinkpad, gst_harness_sink_event); |
| 648 |
|
| 649 |
gst_pad_set_active (h->sinkpad, TRUE); |
| 650 |
|
| 651 |
if (element_srcpad_name) |
| 652 |
gst_harness_link_element_srcpad (h, element_srcpad_name); |
| 653 |
} |
| 654 |
|
| 655 |
static void |
| 656 |
check_element_type (GstElement * element, gboolean * has_sinkpad, |
| 657 |
gboolean * has_srcpad) |
| 658 |
{ |
| 659 |
GstElementClass *element_class = GST_ELEMENT_GET_CLASS (element); |
| 660 |
const GList *tmpl_list; |
| 661 |
|
| 662 |
*has_srcpad = element->numsrcpads > 0; |
| 663 |
*has_sinkpad = element->numsinkpads > 0; |
| 664 |
|
| 665 |
tmpl_list = gst_element_class_get_pad_template_list (element_class); |
| 666 |
|
| 667 |
while (tmpl_list) { |
| 668 |
GstPadTemplate *pad_tmpl = (GstPadTemplate *) tmpl_list->data; |
| 669 |
tmpl_list = g_list_next (tmpl_list); |
| 670 |
if (GST_PAD_TEMPLATE_DIRECTION (pad_tmpl) == GST_PAD_SRC) |
| 671 |
*has_srcpad |= TRUE; |
| 672 |
if (GST_PAD_TEMPLATE_DIRECTION (pad_tmpl) == GST_PAD_SINK) |
| 673 |
*has_sinkpad |= TRUE; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
static void |
| 678 |
turn_async_and_sync_off (GstElement * element) |
| 679 |
{ |
| 680 |
GObjectClass *class = G_OBJECT_GET_CLASS (element); |
| 681 |
if (g_object_class_find_property (class, "async")) |
| 682 |
g_object_set (element, "async", FALSE, NULL); |
| 683 |
if (g_object_class_find_property (class, "sync")) |
| 684 |
g_object_set (element, "sync", FALSE, NULL); |
| 685 |
} |
| 686 |
|
| 687 |
static gboolean |
| 688 |
gst_pad_is_request_pad (GstPad * pad) |
| 689 |
{ |
| 690 |
GstPadTemplate *temp; |
| 691 |
gboolean is_request; |
| 692 |
|
| 693 |
if (pad == NULL) |
| 694 |
return FALSE; |
| 695 |
temp = gst_pad_get_pad_template (pad); |
| 696 |
if (temp == NULL) |
| 697 |
return FALSE; |
| 698 |
is_request = GST_PAD_TEMPLATE_PRESENCE (temp) == GST_PAD_REQUEST; |
| 699 |
gst_object_unref (temp); |
| 700 |
return is_request; |
| 701 |
} |
| 702 |
|
| 703 |
/** |
| 704 |
* gst_harness_new_empty: (skip) |
| 705 |
* |
| 706 |
* Creates a new empty harness. Use gst_harness_add_element_full() to add |
| 707 |
* an #GstElement to it. |
| 708 |
* |
| 709 |
* MT safe. |
| 710 |
* |
| 711 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 712 |
* not be created |
| 713 |
* |
| 714 |
* Since: 1.8 |
| 715 |
*/ |
| 716 |
GstHarness * |
| 717 |
gst_harness_new_empty (void) |
| 718 |
{ |
| 719 |
GstHarness *h; |
| 720 |
GstHarnessPrivate *priv; |
| 721 |
|
| 722 |
h = g_new0 (GstHarness, 1); |
| 723 |
g_assert (h != NULL); |
| 724 |
h->priv = g_new0 (GstHarnessPrivate, 1); |
| 725 |
priv = h->priv; |
| 726 |
|
| 727 |
GST_DEBUG ("about to create new harness %p", h); |
| 728 |
priv->last_push_ts = GST_CLOCK_TIME_NONE; |
| 729 |
priv->latency_min = 0; |
| 730 |
priv->latency_max = GST_CLOCK_TIME_NONE; |
| 731 |
priv->is_live = TRUE; |
| 732 |
priv->drop_buffers = FALSE; |
| 733 |
priv->testclock = GST_TEST_CLOCK_CAST (gst_test_clock_new ()); |
| 734 |
|
| 735 |
priv->buffer_queue = g_async_queue_new_full ( |
| 736 |
(GDestroyNotify) gst_buffer_unref); |
| 737 |
priv->src_event_queue = g_async_queue_new_full ( |
| 738 |
(GDestroyNotify) gst_event_unref); |
| 739 |
priv->sink_event_queue = g_async_queue_new_full ( |
| 740 |
(GDestroyNotify) gst_event_unref); |
| 741 |
|
| 742 |
priv->propose_allocator = NULL; |
| 743 |
gst_allocation_params_init (&priv->propose_allocation_params); |
| 744 |
|
| 745 |
g_mutex_init (&priv->blocking_push_mutex); |
| 746 |
g_cond_init (&priv->blocking_push_cond); |
| 747 |
g_mutex_init (&priv->priv_mutex); |
| 748 |
|
| 749 |
g_mutex_init (&priv->buf_or_eos_mutex); |
| 750 |
g_cond_init (&priv->buf_or_eos_cond); |
| 751 |
priv->eos_received = FALSE; |
| 752 |
|
| 753 |
priv->stress = g_ptr_array_new_with_free_func ( |
| 754 |
(GDestroyNotify) gst_harness_stress_free); |
| 755 |
|
| 756 |
/* we have forwarding on as a default */ |
| 757 |
gst_harness_set_forwarding (h, TRUE); |
| 758 |
|
| 759 |
return h; |
| 760 |
} |
| 761 |
|
| 762 |
/** |
| 763 |
* gst_harness_add_element_full: (skip) |
| 764 |
* @h: a #GstHarness |
| 765 |
* @element: a #GstElement to add to the harness (transfer none) |
| 766 |
* @hsrc: (nullable): a #GstStaticPadTemplate describing the harness srcpad. |
| 767 |
* %NULL will not create a harness srcpad. |
| 768 |
* @element_sinkpad_name: (nullable): a #gchar with the name of the element |
| 769 |
* sinkpad that is then linked to the harness srcpad. Can be a static or request |
| 770 |
* or a sometimes pad that has been added. %NULL will not get/request a sinkpad |
| 771 |
* from the element. (Like if the element is a src.) |
| 772 |
* @hsink: (nullable): a #GstStaticPadTemplate describing the harness sinkpad. |
| 773 |
* %NULL will not create a harness sinkpad. |
| 774 |
* @element_srcpad_name: (nullable): a #gchar with the name of the element |
| 775 |
* srcpad that is then linked to the harness sinkpad, similar to the |
| 776 |
* @element_sinkpad_name. |
| 777 |
* |
| 778 |
* Adds a #GstElement to an empty #GstHarness |
| 779 |
* |
| 780 |
* MT safe. |
| 781 |
* |
| 782 |
* Since: 1.6 |
| 783 |
*/ |
| 784 |
void |
| 785 |
gst_harness_add_element_full (GstHarness * h, GstElement * element, |
| 786 |
GstStaticPadTemplate * hsrc, const gchar * element_sinkpad_name, |
| 787 |
GstStaticPadTemplate * hsink, const gchar * element_srcpad_name) |
| 788 |
{ |
| 789 |
GstClock *element_clock; |
| 790 |
gboolean has_sinkpad, has_srcpad; |
| 791 |
|
| 792 |
g_return_if_fail (element != NULL); |
| 793 |
g_return_if_fail (h->element == NULL); |
| 794 |
|
| 795 |
element_clock = GST_ELEMENT_CLOCK (element); |
| 796 |
h->element = gst_object_ref (element); |
| 797 |
check_element_type (element, &has_sinkpad, &has_srcpad); |
| 798 |
|
| 799 |
/* setup the loose srcpad linked to the element sinkpad */ |
| 800 |
if (has_sinkpad) |
| 801 |
gst_harness_setup_src_pad (h, hsrc, element_sinkpad_name); |
| 802 |
|
| 803 |
/* setup the loose sinkpad linked to the element srcpad */ |
| 804 |
if (has_srcpad) |
| 805 |
gst_harness_setup_sink_pad (h, hsink, element_srcpad_name); |
| 806 |
|
| 807 |
/* as a harness sink, we should not need sync and async */ |
| 808 |
if (has_sinkpad && !has_srcpad) |
| 809 |
turn_async_and_sync_off (h->element); |
| 810 |
|
| 811 |
if (h->srcpad != NULL) { |
| 812 |
gboolean handled; |
| 813 |
gchar *stream_id = g_strdup_printf ("%s-%p", |
| 814 |
GST_OBJECT_NAME (h->element), h); |
| 815 |
handled = gst_pad_push_event (h->srcpad, |
| 816 |
gst_event_new_stream_start (stream_id)); |
| 817 |
g_assert (handled); |
| 818 |
g_free (stream_id); |
| 819 |
} |
| 820 |
|
| 821 |
/* if the element already has a testclock attached, |
| 822 |
we replace our own with it, if no clock we attach the testclock */ |
| 823 |
if (element_clock) { |
| 824 |
if (GST_IS_TEST_CLOCK (element_clock)) { |
| 825 |
gst_object_replace ((GstObject **) & h->priv->testclock, |
| 826 |
(GstObject *) GST_ELEMENT_CLOCK (element)); |
| 827 |
} |
| 828 |
} else { |
| 829 |
gst_harness_use_testclock (h); |
| 830 |
} |
| 831 |
|
| 832 |
/* don't start sources, they start producing data! */ |
| 833 |
if (has_sinkpad) |
| 834 |
gst_harness_play (h); |
| 835 |
|
| 836 |
gst_harness_element_ref (h); |
| 837 |
|
| 838 |
GST_DEBUG ("added element to harness %p " |
| 839 |
"with element_srcpad_name (%p, %s, %s) and element_sinkpad_name (%p, %s, %s)", |
| 840 |
h, h->srcpad, GST_DEBUG_PAD_NAME (h->srcpad), |
| 841 |
h->sinkpad, GST_DEBUG_PAD_NAME (h->sinkpad)); |
| 842 |
} |
| 843 |
|
| 844 |
/** |
| 845 |
* gst_harness_new_full: (skip) |
| 846 |
* @element: a #GstElement to attach the harness to (transfer none) |
| 847 |
* @hsrc: (nullable): a #GstStaticPadTemplate describing the harness srcpad. |
| 848 |
* %NULL will not create a harness srcpad. |
| 849 |
* @element_sinkpad_name: (nullable): a #gchar with the name of the element |
| 850 |
* sinkpad that is then linked to the harness srcpad. Can be a static or request |
| 851 |
* or a sometimes pad that has been added. %NULL will not get/request a sinkpad |
| 852 |
* from the element. (Like if the element is a src.) |
| 853 |
* @hsink: (nullable): a #GstStaticPadTemplate describing the harness sinkpad. |
| 854 |
* %NULL will not create a harness sinkpad. |
| 855 |
* @element_srcpad_name: (nullable): a #gchar with the name of the element |
| 856 |
* srcpad that is then linked to the harness sinkpad, similar to the |
| 857 |
* @element_sinkpad_name. |
| 858 |
* |
| 859 |
* Creates a new harness. |
| 860 |
* |
| 861 |
* MT safe. |
| 862 |
* |
| 863 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 864 |
* not be created |
| 865 |
* |
| 866 |
* Since: 1.6 |
| 867 |
*/ |
| 868 |
GstHarness * |
| 869 |
gst_harness_new_full (GstElement * element, |
| 870 |
GstStaticPadTemplate * hsrc, const gchar * element_sinkpad_name, |
| 871 |
GstStaticPadTemplate * hsink, const gchar * element_srcpad_name) |
| 872 |
{ |
| 873 |
GstHarness *h; |
| 874 |
h = gst_harness_new_empty (); |
| 875 |
gst_harness_add_element_full (h, element, |
| 876 |
hsrc, element_sinkpad_name, hsink, element_srcpad_name); |
| 877 |
return h; |
| 878 |
} |
| 879 |
|
| 880 |
/** |
| 881 |
* gst_harness_new_with_element: (skip) |
| 882 |
* @element: a #GstElement to attach the harness to (transfer none) |
| 883 |
* @element_sinkpad_name: (nullable): a #gchar with the name of the element |
| 884 |
* sinkpad that is then linked to the harness srcpad. %NULL does not attach a |
| 885 |
* sinkpad |
| 886 |
* @element_srcpad_name: (nullable): a #gchar with the name of the element |
| 887 |
* srcpad that is then linked to the harness sinkpad. %NULL does not attach a |
| 888 |
* srcpad |
| 889 |
* |
| 890 |
* Creates a new harness. Works in the same way as gst_harness_new_full(), only |
| 891 |
* that generic padtemplates are used for the harness src and sinkpads, which |
| 892 |
* will be sufficient in most usecases. |
| 893 |
* |
| 894 |
* MT safe. |
| 895 |
* |
| 896 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 897 |
* not be created |
| 898 |
* |
| 899 |
* Since: 1.6 |
| 900 |
*/ |
| 901 |
GstHarness * |
| 902 |
gst_harness_new_with_element (GstElement * element, |
| 903 |
const gchar * element_sinkpad_name, const gchar * element_srcpad_name) |
| 904 |
{ |
| 905 |
return gst_harness_new_full (element, |
| 906 |
&hsrctemplate, element_sinkpad_name, &hsinktemplate, element_srcpad_name); |
| 907 |
} |
| 908 |
|
| 909 |
/** |
| 910 |
* gst_harness_new_with_padnames: (skip) |
| 911 |
* @element_name: a #gchar describing the #GstElement name |
| 912 |
* @element_sinkpad_name: (nullable): a #gchar with the name of the element |
| 913 |
* sinkpad that is then linked to the harness srcpad. %NULL does not attach a |
| 914 |
* sinkpad |
| 915 |
* @element_srcpad_name: (nullable): a #gchar with the name of the element |
| 916 |
* srcpad that is then linked to the harness sinkpad. %NULL does not attach a |
| 917 |
* srcpad |
| 918 |
* |
| 919 |
* Creates a new harness. Works like gst_harness_new_with_element(), |
| 920 |
* except you specify the factoryname of the #GstElement |
| 921 |
* |
| 922 |
* MT safe. |
| 923 |
* |
| 924 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 925 |
* not be created |
| 926 |
* |
| 927 |
* Since: 1.6 |
| 928 |
*/ |
| 929 |
GstHarness * |
| 930 |
gst_harness_new_with_padnames (const gchar * element_name, |
| 931 |
const gchar * element_sinkpad_name, const gchar * element_srcpad_name) |
| 932 |
{ |
| 933 |
GstHarness *h; |
| 934 |
GstElement *element = gst_element_factory_make (element_name, NULL); |
| 935 |
g_assert (element != NULL); |
| 936 |
|
| 937 |
h = gst_harness_new_with_element (element, element_sinkpad_name, |
| 938 |
element_srcpad_name); |
| 939 |
gst_object_unref (element); |
| 940 |
return h; |
| 941 |
} |
| 942 |
|
| 943 |
/** |
| 944 |
* gst_harness_new_with_templates: (skip) |
| 945 |
* @element_name: a #gchar describing the #GstElement name |
| 946 |
* @hsrc: (nullable): a #GstStaticPadTemplate describing the harness srcpad. |
| 947 |
* %NULL will not create a harness srcpad. |
| 948 |
* @hsink: (nullable): a #GstStaticPadTemplate describing the harness sinkpad. |
| 949 |
* %NULL will not create a harness sinkpad. |
| 950 |
* |
| 951 |
* Creates a new harness, like gst_harness_new_full(), except it |
| 952 |
* assumes the #GstElement sinkpad is named "sink" and srcpad is named "src" |
| 953 |
* |
| 954 |
* MT safe. |
| 955 |
* |
| 956 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 957 |
* not be created |
| 958 |
* |
| 959 |
* Since: 1.6 |
| 960 |
*/ |
| 961 |
GstHarness * |
| 962 |
gst_harness_new_with_templates (const gchar * element_name, |
| 963 |
GstStaticPadTemplate * hsrc, GstStaticPadTemplate * hsink) |
| 964 |
{ |
| 965 |
GstHarness *h; |
| 966 |
GstElement *element = gst_element_factory_make (element_name, NULL); |
| 967 |
g_assert (element != NULL); |
| 968 |
|
| 969 |
h = gst_harness_new_full (element, hsrc, "sink", hsink, "src"); |
| 970 |
gst_object_unref (element); |
| 971 |
return h; |
| 972 |
} |
| 973 |
|
| 974 |
/** |
| 975 |
* gst_harness_new: (skip) |
| 976 |
* @element_name: a #gchar describing the #GstElement name |
| 977 |
* |
| 978 |
* Creates a new harness. Works like gst_harness_new_with_padnames(), except it |
| 979 |
* assumes the #GstElement sinkpad is named "sink" and srcpad is named "src" |
| 980 |
* |
| 981 |
* MT safe. |
| 982 |
* |
| 983 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 984 |
* not be created |
| 985 |
* |
| 986 |
* Since: 1.6 |
| 987 |
*/ |
| 988 |
GstHarness * |
| 989 |
gst_harness_new (const gchar * element_name) |
| 990 |
{ |
| 991 |
return gst_harness_new_with_padnames (element_name, "sink", "src"); |
| 992 |
} |
| 993 |
|
| 994 |
/** |
| 995 |
* gst_harness_add_parse: (skip) |
| 996 |
* @h: a #GstHarness |
| 997 |
* @launchline: a #gchar describing a gst-launch type line |
| 998 |
* |
| 999 |
* Parses the @launchline and puts that in a #GstBin, |
| 1000 |
* and then attches the supplied #GstHarness to the bin. |
| 1001 |
* |
| 1002 |
* MT safe. |
| 1003 |
* |
| 1004 |
* Since: 1.6 |
| 1005 |
*/ |
| 1006 |
void |
| 1007 |
gst_harness_add_parse (GstHarness * h, const gchar * launchline) |
| 1008 |
{ |
| 1009 |
GstBin *bin; |
| 1010 |
gchar *desc; |
| 1011 |
GstPad *pad; |
| 1012 |
GstIterator *iter; |
| 1013 |
gboolean done = FALSE; |
| 1014 |
GError *error = NULL; |
| 1015 |
|
| 1016 |
g_return_if_fail (launchline != NULL); |
| 1017 |
|
| 1018 |
desc = g_strdup_printf ("bin.( %s )", launchline); |
| 1019 |
bin = |
| 1020 |
(GstBin *) gst_parse_launch_full (desc, NULL, GST_PARSE_FLAG_FATAL_ERRORS, |
| 1021 |
&error); |
| 1022 |
|
| 1023 |
if (G_UNLIKELY (error != NULL)) { |
| 1024 |
g_error ("Unable to create pipeline '%s': %s", desc, error->message); |
| 1025 |
} |
| 1026 |
g_free (desc); |
| 1027 |
|
| 1028 |
/* find pads and ghost them if necessary */ |
| 1029 |
if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC)) != NULL) { |
| 1030 |
gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("src", pad)); |
| 1031 |
gst_object_unref (pad); |
| 1032 |
} |
| 1033 |
if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SINK)) != NULL) { |
| 1034 |
gst_element_add_pad (GST_ELEMENT (bin), gst_ghost_pad_new ("sink", pad)); |
| 1035 |
gst_object_unref (pad); |
| 1036 |
} |
| 1037 |
|
| 1038 |
iter = gst_bin_iterate_sinks (bin); |
| 1039 |
while (!done) { |
| 1040 |
GValue item = { 0, }; |
| 1041 |
|
| 1042 |
switch (gst_iterator_next (iter, &item)) { |
| 1043 |
case GST_ITERATOR_OK: |
| 1044 |
turn_async_and_sync_off (GST_ELEMENT (g_value_get_object (&item))); |
| 1045 |
g_value_reset (&item); |
| 1046 |
break; |
| 1047 |
case GST_ITERATOR_DONE: |
| 1048 |
done = TRUE; |
| 1049 |
break; |
| 1050 |
case GST_ITERATOR_RESYNC: |
| 1051 |
gst_iterator_resync (iter); |
| 1052 |
break; |
| 1053 |
case GST_ITERATOR_ERROR: |
| 1054 |
gst_object_unref (bin); |
| 1055 |
gst_iterator_free (iter); |
| 1056 |
g_return_if_reached (); |
| 1057 |
break; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
gst_iterator_free (iter); |
| 1061 |
|
| 1062 |
gst_harness_add_element_full (h, GST_ELEMENT_CAST (bin), |
| 1063 |
&hsrctemplate, "sink", &hsinktemplate, "src"); |
| 1064 |
gst_object_unref (bin); |
| 1065 |
} |
| 1066 |
|
| 1067 |
/** |
| 1068 |
* gst_harness_new_parse: (skip) |
| 1069 |
* @launchline: a #gchar describing a gst-launch type line |
| 1070 |
* |
| 1071 |
* Creates a new harness, parsing the @launchline and putting that in a #GstBin, |
| 1072 |
* and then attches the harness to the bin. |
| 1073 |
* |
| 1074 |
* MT safe. |
| 1075 |
* |
| 1076 |
* Returns: (transfer full) (nullable): a #GstHarness, or %NULL if the harness could |
| 1077 |
* not be created |
| 1078 |
* |
| 1079 |
* Since: 1.6 |
| 1080 |
*/ |
| 1081 |
GstHarness * |
| 1082 |
gst_harness_new_parse (const gchar * launchline) |
| 1083 |
{ |
| 1084 |
GstHarness *h; |
| 1085 |
h = gst_harness_new_empty (); |
| 1086 |
gst_harness_add_parse (h, launchline); |
| 1087 |
return h; |
| 1088 |
} |
| 1089 |
|
| 1090 |
/** |
| 1091 |
* gst_harness_teardown: |
| 1092 |
* @h: a #GstHarness |
| 1093 |
* |
| 1094 |
* Tears down a @GstHarness, freeing all resources allocated using it. |
| 1095 |
* |
| 1096 |
* MT safe. |
| 1097 |
* |
| 1098 |
* Since: 1.6 |
| 1099 |
*/ |
| 1100 |
void |
| 1101 |
gst_harness_teardown (GstHarness * h) |
| 1102 |
{ |
| 1103 |
GstHarnessPrivate *priv = h->priv; |
| 1104 |
|
| 1105 |
if (priv->blocking_push_mode) { |
| 1106 |
g_mutex_lock (&priv->blocking_push_mutex); |
| 1107 |
priv->blocking_push_mode = FALSE; |
| 1108 |
g_cond_signal (&priv->blocking_push_cond); |
| 1109 |
g_mutex_unlock (&priv->blocking_push_mutex); |
| 1110 |
} |
| 1111 |
|
| 1112 |
if (h->src_harness) |
| 1113 |
gst_harness_teardown (h->src_harness); |
| 1114 |
h->src_harness = NULL; |
| 1115 |
|
| 1116 |
HARNESS_LOCK (h); |
| 1117 |
gst_object_replace ((GstObject **) & priv->sink_forward_pad, NULL); |
| 1118 |
HARNESS_UNLOCK (h); |
| 1119 |
|
| 1120 |
if (h->sink_harness) |
| 1121 |
gst_harness_teardown (h->sink_harness); |
| 1122 |
h->sink_harness = NULL; |
| 1123 |
|
| 1124 |
if (h->srcpad) { |
| 1125 |
if (gst_pad_is_request_pad (GST_PAD_PEER (h->srcpad))) |
| 1126 |
gst_element_release_request_pad (h->element, GST_PAD_PEER (h->srcpad)); |
| 1127 |
g_free (priv->element_sinkpad_name); |
| 1128 |
|
| 1129 |
gst_pad_set_active (h->srcpad, FALSE); |
| 1130 |
|
| 1131 |
/* Make sure our funcs are not called after harness is teared down since |
| 1132 |
* they try to access this harness through pad data */ |
| 1133 |
gst_harness_pad_link_tear_down (h->srcpad); |
| 1134 |
gst_pad_set_event_function (h->srcpad, NULL); |
| 1135 |
gst_pad_set_query_function (h->srcpad, NULL); |
| 1136 |
|
| 1137 |
gst_object_unref (h->srcpad); |
| 1138 |
} |
| 1139 |
h->srcpad = NULL; |
| 1140 |
|
| 1141 |
if (h->sinkpad) { |
| 1142 |
if (gst_pad_is_request_pad (GST_PAD_PEER (h->sinkpad))) |
| 1143 |
gst_element_release_request_pad (h->element, GST_PAD_PEER (h->sinkpad)); |
| 1144 |
g_free (priv->element_srcpad_name); |
| 1145 |
|
| 1146 |
gst_pad_set_active (h->sinkpad, FALSE); |
| 1147 |
|
| 1148 |
/* Make sure our funcs are not called after harness is teared down since |
| 1149 |
* they try to access this harness through pad data */ |
| 1150 |
gst_harness_pad_link_tear_down (h->sinkpad); |
| 1151 |
gst_pad_set_chain_function (h->sinkpad, NULL); |
| 1152 |
gst_pad_set_event_function (h->sinkpad, NULL); |
| 1153 |
gst_pad_set_query_function (h->sinkpad, NULL); |
| 1154 |
|
| 1155 |
gst_object_unref (h->sinkpad); |
| 1156 |
} |
| 1157 |
h->sinkpad = NULL; |
| 1158 |
|
| 1159 |
if (priv->src_caps) |
| 1160 |
gst_caps_unref (priv->src_caps); |
| 1161 |
priv->src_caps = NULL; |
| 1162 |
|
| 1163 |
if (priv->sink_caps) |
| 1164 |
gst_caps_unref (priv->sink_caps); |
| 1165 |
priv->sink_caps = NULL; |
| 1166 |
|
| 1167 |
gst_object_replace ((GstObject **) & priv->propose_allocator, NULL); |
| 1168 |
gst_object_replace ((GstObject **) & priv->allocator, NULL); |
| 1169 |
gst_object_replace ((GstObject **) & priv->pool, NULL); |
| 1170 |
|
| 1171 |
if (priv->propose_allocation_metas) |
| 1172 |
g_array_unref (priv->propose_allocation_metas); |
| 1173 |
priv->propose_allocation_metas = NULL; |
| 1174 |
|
| 1175 |
/* if we hold the last ref, set to NULL */ |
| 1176 |
if (h->element != NULL && gst_harness_element_unref (h) == 0) { |
| 1177 |
gboolean state_change; |
| 1178 |
GstState state, pending; |
| 1179 |
state_change = gst_element_set_state (h->element, GST_STATE_NULL); |
| 1180 |
g_assert (state_change == GST_STATE_CHANGE_SUCCESS); |
| 1181 |
state_change = gst_element_get_state (h->element, &state, &pending, 0); |
| 1182 |
g_assert (state_change == GST_STATE_CHANGE_SUCCESS); |
| 1183 |
g_assert (state == GST_STATE_NULL); |
| 1184 |
} |
| 1185 |
|
| 1186 |
g_cond_clear (&priv->blocking_push_cond); |
| 1187 |
g_mutex_clear (&priv->blocking_push_mutex); |
| 1188 |
g_mutex_clear (&priv->priv_mutex); |
| 1189 |
|
| 1190 |
g_mutex_clear (&priv->buf_or_eos_mutex); |
| 1191 |
g_cond_clear (&priv->buf_or_eos_cond); |
| 1192 |
priv->eos_received = FALSE; |
| 1193 |
|
| 1194 |
g_async_queue_unref (priv->buffer_queue); |
| 1195 |
priv->buffer_queue = NULL; |
| 1196 |
g_async_queue_unref (priv->src_event_queue); |
| 1197 |
priv->src_event_queue = NULL; |
| 1198 |
g_async_queue_unref (priv->sink_event_queue); |
| 1199 |
priv->sink_event_queue = NULL; |
| 1200 |
|
| 1201 |
g_ptr_array_unref (priv->stress); |
| 1202 |
priv->stress = NULL; |
| 1203 |
|
| 1204 |
if (h->element) { |
| 1205 |
gst_object_unref (h->element); |
| 1206 |
h->element = NULL; |
| 1207 |
} |
| 1208 |
|
| 1209 |
gst_object_replace ((GstObject **) & priv->testclock, NULL); |
| 1210 |
|
| 1211 |
g_free (h->priv); |
| 1212 |
h->priv = NULL; |
| 1213 |
g_free (h); |
| 1214 |
} |
| 1215 |
|
| 1216 |
/** |
| 1217 |
* gst_harness_add_element_src_pad: |
| 1218 |
* @h: a #GstHarness |
| 1219 |
* @srcpad: a #GstPad to link to the harness sinkpad |
| 1220 |
* |
| 1221 |
* Links the specified #GstPad the @GstHarness sinkpad. This can be useful if |
| 1222 |
* perhaps the srcpad did not exist at the time of creating the harness, |
| 1223 |
* like a demuxer that provides a sometimes-pad after receiving data. |
| 1224 |
* |
| 1225 |
* MT safe. |
| 1226 |
* |
| 1227 |
* Since: 1.6 |
| 1228 |
*/ |
| 1229 |
void |
| 1230 |
gst_harness_add_element_src_pad (GstHarness * h, GstPad * srcpad) |
| 1231 |
{ |
| 1232 |
GstHarnessPrivate *priv = h->priv; |
| 1233 |
GstPadLinkReturn link; |
| 1234 |
if (h->sinkpad == NULL) |
| 1235 |
gst_harness_setup_sink_pad (h, &hsinktemplate, NULL); |
| 1236 |
link = gst_pad_link (srcpad, h->sinkpad); |
| 1237 |
g_assert_cmpint (link, ==, GST_PAD_LINK_OK); |
| 1238 |
g_free (priv->element_srcpad_name); |
| 1239 |
priv->element_srcpad_name = gst_pad_get_name (srcpad); |
| 1240 |
} |
| 1241 |
|
| 1242 |
/** |
| 1243 |
* gst_harness_add_element_sink_pad: |
| 1244 |
* @h: a #GstHarness |
| 1245 |
* @sinkpad: a #GstPad to link to the harness srcpad |
| 1246 |
* |
| 1247 |
* Links the specified #GstPad the @GstHarness srcpad. |
| 1248 |
* |
| 1249 |
* MT safe. |
| 1250 |
* |
| 1251 |
* Since: 1.6 |
| 1252 |
*/ |
| 1253 |
void |
| 1254 |
gst_harness_add_element_sink_pad (GstHarness * h, GstPad * sinkpad) |
| 1255 |
{ |
| 1256 |
GstHarnessPrivate *priv = h->priv; |
| 1257 |
GstPadLinkReturn link; |
| 1258 |
if (h->srcpad == NULL) |
| 1259 |
gst_harness_setup_src_pad (h, &hsrctemplate, NULL); |
| 1260 |
link = gst_pad_link (h->srcpad, sinkpad); |
| 1261 |
g_assert_cmpint (link, ==, GST_PAD_LINK_OK); |
| 1262 |
g_free (priv->element_sinkpad_name); |
| 1263 |
priv->element_sinkpad_name = gst_pad_get_name (sinkpad); |
| 1264 |
} |
| 1265 |
|
| 1266 |
/** |
| 1267 |
* gst_harness_set_src_caps: |
| 1268 |
* @h: a #GstHarness |
| 1269 |
* @caps: (transfer full): a #GstCaps to set on the harness srcpad |
| 1270 |
* |
| 1271 |
* Sets the @GstHarness srcpad caps. This must be done before any buffers |
| 1272 |
* can legally be pushed from the harness to the element. |
| 1273 |
* |
| 1274 |
* MT safe. |
| 1275 |
* |
| 1276 |
* Since: 1.6 |
| 1277 |
*/ |
| 1278 |
void |
| 1279 |
gst_harness_set_src_caps (GstHarness * h, GstCaps * caps) |
| 1280 |
{ |
| 1281 |
GstHarnessPrivate *priv = h->priv; |
| 1282 |
GstSegment segment; |
| 1283 |
gboolean handled; |
| 1284 |
|
| 1285 |
handled = gst_pad_push_event (h->srcpad, gst_event_new_caps (caps)); |
| 1286 |
g_assert (handled); |
| 1287 |
gst_caps_take (&priv->src_caps, caps); |
| 1288 |
|
| 1289 |
gst_segment_init (&segment, GST_FORMAT_TIME); |
| 1290 |
handled = gst_pad_push_event (h->srcpad, gst_event_new_segment (&segment)); |
| 1291 |
g_assert (handled); |
| 1292 |
} |
| 1293 |
|
| 1294 |
/** |
| 1295 |
* gst_harness_set_sink_caps: |
| 1296 |
* @h: a #GstHarness |
| 1297 |
* @caps: (transfer full): a #GstCaps to set on the harness sinkpad |
| 1298 |
* |
| 1299 |
* Sets the @GstHarness sinkpad caps. |
| 1300 |
* |
| 1301 |
* MT safe. |
| 1302 |
* |
| 1303 |
* Since: 1.6 |
| 1304 |
*/ |
| 1305 |
void |
| 1306 |
gst_harness_set_sink_caps (GstHarness * h, GstCaps * caps) |
| 1307 |
{ |
| 1308 |
GstHarnessPrivate *priv = h->priv; |
| 1309 |
|
| 1310 |
gst_caps_take (&priv->sink_caps, caps); |
| 1311 |
gst_pad_push_event (h->sinkpad, gst_event_new_reconfigure ()); |
| 1312 |
} |
| 1313 |
|
| 1314 |
/** |
| 1315 |
* gst_harness_set_caps: |
| 1316 |
* @h: a #GstHarness |
| 1317 |
* @in: (transfer full): a #GstCaps to set on the harness srcpad |
| 1318 |
* @out: (transfer full): a #GstCaps to set on the harness sinkpad |
| 1319 |
* |
| 1320 |
* Sets the @GstHarness srcpad and sinkpad caps. |
| 1321 |
* |
| 1322 |
* MT safe. |
| 1323 |
* |
| 1324 |
* Since: 1.6 |
| 1325 |
*/ |
| 1326 |
void |
| 1327 |
gst_harness_set_caps (GstHarness * h, GstCaps * in, GstCaps * out) |
| 1328 |
{ |
| 1329 |
gst_harness_set_sink_caps (h, out); |
| 1330 |
gst_harness_set_src_caps (h, in); |
| 1331 |
} |
| 1332 |
|
| 1333 |
/** |
| 1334 |
* gst_harness_set_src_caps_str: |
| 1335 |
* @h: a #GstHarness |
| 1336 |
* @str: a @gchar describing a #GstCaps to set on the harness srcpad |
| 1337 |
* |
| 1338 |
* Sets the @GstHarness srcpad caps using a string. This must be done before |
| 1339 |
* any buffers can legally be pushed from the harness to the element. |
| 1340 |
* |
| 1341 |
* MT safe. |
| 1342 |
* |
| 1343 |
* Since: 1.6 |
| 1344 |
*/ |
| 1345 |
void |
| 1346 |
gst_harness_set_src_caps_str (GstHarness * h, const gchar * str) |
| 1347 |
{ |
| 1348 |
gst_harness_set_src_caps (h, gst_caps_from_string (str)); |
| 1349 |
} |
| 1350 |
|
| 1351 |
/** |
| 1352 |
* gst_harness_set_sink_caps_str: |
| 1353 |
* @h: a #GstHarness |
| 1354 |
* @str: a @gchar describing a #GstCaps to set on the harness sinkpad |
| 1355 |
* |
| 1356 |
* Sets the @GstHarness sinkpad caps using a string. |
| 1357 |
* |
| 1358 |
* MT safe. |
| 1359 |
* |
| 1360 |
* Since: 1.6 |
| 1361 |
*/ |
| 1362 |
void |
| 1363 |
gst_harness_set_sink_caps_str (GstHarness * h, const gchar * str) |
| 1364 |
{ |
| 1365 |
gst_harness_set_sink_caps (h, gst_caps_from_string (str)); |
| 1366 |
} |
| 1367 |
|
| 1368 |
/** |
| 1369 |
* gst_harness_set_caps_str: |
| 1370 |
* @h: a #GstHarness |
| 1371 |
* @in: a @gchar describing a #GstCaps to set on the harness srcpad |
| 1372 |
* @out: a @gchar describing a #GstCaps to set on the harness sinkpad |
| 1373 |
* |
| 1374 |
* Sets the @GstHarness srcpad and sinkpad caps using strings. |
| 1375 |
* |
| 1376 |
* MT safe. |
| 1377 |
* |
| 1378 |
* Since: 1.6 |
| 1379 |
*/ |
| 1380 |
void |
| 1381 |
gst_harness_set_caps_str (GstHarness * h, const gchar * in, const gchar * out) |
| 1382 |
{ |
| 1383 |
gst_harness_set_sink_caps_str (h, out); |
| 1384 |
gst_harness_set_src_caps_str (h, in); |
| 1385 |
} |
| 1386 |
|
| 1387 |
/** |
| 1388 |
* gst_harness_use_systemclock: |
| 1389 |
* @h: a #GstHarness |
| 1390 |
* |
| 1391 |
* Sets the system #GstClock on the @GstHarness #GstElement |
| 1392 |
* |
| 1393 |
* MT safe. |
| 1394 |
* |
| 1395 |
* Since: 1.6 |
| 1396 |
*/ |
| 1397 |
void |
| 1398 |
gst_harness_use_systemclock (GstHarness * h) |
| 1399 |
{ |
| 1400 |
GstClock *clock = gst_system_clock_obtain (); |
| 1401 |
g_assert (clock != NULL); |
| 1402 |
gst_element_set_clock (h->element, clock); |
| 1403 |
gst_object_unref (clock); |
| 1404 |
} |
| 1405 |
|
| 1406 |
/** |
| 1407 |
* gst_harness_use_testclock: |
| 1408 |
* @h: a #GstHarness |
| 1409 |
* |
| 1410 |
* Sets the #GstTestClock on the #GstHarness #GstElement |
| 1411 |
* |
| 1412 |
* MT safe. |
| 1413 |
* |
| 1414 |
* Since: 1.6 |
| 1415 |
*/ |
| 1416 |
void |
| 1417 |
gst_harness_use_testclock (GstHarness * h) |
| 1418 |
{ |
| 1419 |
gst_element_set_clock (h->element, GST_CLOCK_CAST (h->priv->testclock)); |
| 1420 |
} |
| 1421 |
|
| 1422 |
/** |
| 1423 |
* gst_harness_get_testclock: |
| 1424 |
* @h: a #GstHarness |
| 1425 |
* |
| 1426 |
* Get the #GstTestClock. Useful if specific operations on the testclock is |
| 1427 |
* needed. |
| 1428 |
* |
| 1429 |
* MT safe. |
| 1430 |
* |
| 1431 |
* Returns: (transfer full) (nullable): a #GstTestClock, or %NULL if the testclock is not |
| 1432 |
* present. |
| 1433 |
* |
| 1434 |
* Since: 1.6 |
| 1435 |
*/ |
| 1436 |
GstTestClock * |
| 1437 |
gst_harness_get_testclock (GstHarness * h) |
| 1438 |
{ |
| 1439 |
return gst_object_ref (h->priv->testclock); |
| 1440 |
} |
| 1441 |
|
| 1442 |
/** |
| 1443 |
* gst_harness_set_time: |
| 1444 |
* @h: a #GstHarness |
| 1445 |
* @time: a #GstClockTime to advance the clock to |
| 1446 |
* |
| 1447 |
* Advance the #GstTestClock to a specific time. |
| 1448 |
* |
| 1449 |
* MT safe. |
| 1450 |
* |
| 1451 |
* Returns: a @gboolean %TRUE if the time could be set. %FALSE if not. |
| 1452 |
* |
| 1453 |
* Since: 1.6 |
| 1454 |
*/ |
| 1455 |
gboolean |
| 1456 |
gst_harness_set_time (GstHarness * h, GstClockTime time) |
| 1457 |
{ |
| 1458 |
gst_test_clock_set_time (h->priv->testclock, time); |
| 1459 |
return TRUE; |
| 1460 |
} |
| 1461 |
|
| 1462 |
/** |
| 1463 |
* gst_harness_wait_for_clock_id_waits: |
| 1464 |
* @h: a #GstHarness |
| 1465 |
* @waits: a #guint describing the numbers of #GstClockID registered with |
| 1466 |
* the #GstTestClock |
| 1467 |
* @timeout: a #guint describing how many seconds to wait for @waits to be true |
| 1468 |
* |
| 1469 |
* Waits for @timeout seconds until @waits number of #GstClockID waits is |
| 1470 |
* registered with the #GstTestClock. Useful for writing deterministic tests, |
| 1471 |
* where you want to make sure that an expected number of waits have been |
| 1472 |
* reached. |
| 1473 |
* |
| 1474 |
* MT safe. |
| 1475 |
* |
| 1476 |
* Returns: a @gboolean %TRUE if the waits have been registered, %FALSE if not. |
| 1477 |
* (Could be that it timed out waiting or that more waits than waits was found) |
| 1478 |
* |
| 1479 |
* Since: 1.6 |
| 1480 |
*/ |
| 1481 |
gboolean |
| 1482 |
gst_harness_wait_for_clock_id_waits (GstHarness * h, guint waits, guint timeout) |
| 1483 |
{ |
| 1484 |
return gst_test_clock_timed_wait_for_multiple_pending_ids (h->priv->testclock, |
| 1485 |
waits, timeout * 1000, NULL); |
| 1486 |
} |
| 1487 |
|
| 1488 |
/** |
| 1489 |
* gst_harness_crank_single_clock_wait: |
| 1490 |
* @h: a #GstHarness |
| 1491 |
* |
| 1492 |
* A "crank" consists of three steps: |
| 1493 |
* 1: Wait for a #GstClockID to be registered with the #GstTestClock. |
| 1494 |
* 2: Advance the #GstTestClock to the time the #GstClockID is waiting for. |
| 1495 |
* 3: Release the #GstClockID wait. |
| 1496 |
* Together, this provides an easy way to not have to think about the details |
| 1497 |
* around clocks and time, but still being able to write deterministic tests |
| 1498 |
* that are dependent on this. A "crank" can be though of as the notion of |
| 1499 |
* manually driving the clock forward to its next logical step. |
| 1500 |
* |
| 1501 |
* MT safe. |
| 1502 |
* |
| 1503 |
* Returns: a @gboolean %TRUE if the "crank" was successful, %FALSE if not. |
| 1504 |
* |
| 1505 |
* Since: 1.6 |
| 1506 |
*/ |
| 1507 |
gboolean |
| 1508 |
gst_harness_crank_single_clock_wait (GstHarness * h) |
| 1509 |
{ |
| 1510 |
return gst_test_clock_crank (h->priv->testclock); |
| 1511 |
} |
| 1512 |
|
| 1513 |
/** |
| 1514 |
* gst_harness_crank_multiple_clock_waits: |
| 1515 |
* @h: a #GstHarness |
| 1516 |
* @waits: a #guint describing the number of #GstClockIDs to crank |
| 1517 |
* |
| 1518 |
* Similar to gst_harness_crank_single_clock_wait(), this is the function to use |
| 1519 |
* if your harnessed element(s) are using more then one gst_clock_id_wait. |
| 1520 |
* Failing to do so can (and will) make it racy which #GstClockID you actually |
| 1521 |
* are releasing, where as this function will process all the waits at the |
| 1522 |
* same time, ensuring that one thread can't register another wait before |
| 1523 |
* both are released. |
| 1524 |
* |
| 1525 |
* MT safe. |
| 1526 |
* |
| 1527 |
* Returns: a @gboolean %TRUE if the "crank" was successful, %FALSE if not. |
| 1528 |
* |
| 1529 |
* Since: 1.6 |
| 1530 |
*/ |
| 1531 |
gboolean |
| 1532 |
gst_harness_crank_multiple_clock_waits (GstHarness * h, guint waits) |
| 1533 |
{ |
| 1534 |
GstTestClock *testclock = h->priv->testclock; |
| 1535 |
GList *pending; |
| 1536 |
guint processed; |
| 1537 |
|
| 1538 |
gst_test_clock_wait_for_multiple_pending_ids (testclock, waits, &pending); |
| 1539 |
gst_harness_set_time (h, gst_test_clock_id_list_get_latest_time (pending)); |
| 1540 |
processed = gst_test_clock_process_id_list (testclock, pending); |
| 1541 |
|
| 1542 |
g_list_free_full (pending, gst_clock_id_unref); |
| 1543 |
return processed == waits; |
| 1544 |
} |
| 1545 |
|
| 1546 |
/** |
| 1547 |
* gst_harness_play: |
| 1548 |
* @h: a #GstHarness |
| 1549 |
* |
| 1550 |
* This will set the harnessed #GstElement to %GST_STATE_PLAYING. |
| 1551 |
* #GstElements without a sink-#GstPad and with the %GST_ELEMENT_FLAG_SOURCE |
| 1552 |
* flag set is considered a src #GstElement |
| 1553 |
* Non-src #GstElements (like sinks and filters) are automatically set to |
| 1554 |
* playing by the #GstHarness, but src #GstElements are not to avoid them |
| 1555 |
* starting to produce buffers. |
| 1556 |
* Hence, for src #GstElement you must call gst_harness_play() explicitly. |
| 1557 |
* |
| 1558 |
* MT safe. |
| 1559 |
* |
| 1560 |
* Since: 1.6 |
| 1561 |
*/ |
| 1562 |
void |
| 1563 |
gst_harness_play (GstHarness * h) |
| 1564 |
{ |
| 1565 |
GstState state, pending; |
| 1566 |
gboolean state_change; |
| 1567 |
state_change = gst_element_set_state (h->element, GST_STATE_PLAYING); |
| 1568 |
g_assert_cmpint (GST_STATE_CHANGE_SUCCESS, ==, state_change); |
| 1569 |
state_change = gst_element_get_state (h->element, &state, &pending, 0); |
| 1570 |
g_assert_cmpint (GST_STATE_CHANGE_SUCCESS, ==, state_change); |
| 1571 |
g_assert_cmpint (GST_STATE_PLAYING, ==, state); |
| 1572 |
} |
| 1573 |
|
| 1574 |
/** |
| 1575 |
* gst_harness_set_blocking_push_mode: |
| 1576 |
* @h: a #GstHarness |
| 1577 |
* |
| 1578 |
* Setting this will make the harness block in the chain-function, and |
| 1579 |
* then release when gst_harness_pull() or gst_harness_try_pull() is called. |
| 1580 |
* Can be useful when wanting to control a src-element that is not implementing |
| 1581 |
* gst_clock_id_wait() so it can't be controlled by the #GstTestClock, since |
| 1582 |
* it otherwise would produce buffers as fast as possible. |
| 1583 |
* |
| 1584 |
* MT safe. |
| 1585 |
* |
| 1586 |
* Since: 1.6 |
| 1587 |
*/ |
| 1588 |
void |
| 1589 |
gst_harness_set_blocking_push_mode (GstHarness * h) |
| 1590 |
{ |
| 1591 |
GstHarnessPrivate *priv = h->priv; |
| 1592 |
priv->blocking_push_mode = TRUE; |
| 1593 |
} |
| 1594 |
|
| 1595 |
/** |
| 1596 |
* gst_harness_set_forwarding: |
| 1597 |
* @h: a #GstHarness |
| 1598 |
* @forwarding: a #gboolean to enable/disable forwarding |
| 1599 |
* |
| 1600 |
* As a convenience, a src-harness will forward %GST_EVENT_STREAM_START, |
| 1601 |
* %GST_EVENT_CAPS and %GST_EVENT_SEGMENT to the main-harness if forwarding |
| 1602 |
* is enabled, and forward any sticky-events from the main-harness to |
| 1603 |
* the sink-harness. It will also forward the %GST_QUERY_ALLOCATION. |
| 1604 |
* |
| 1605 |
* If forwarding is disabled, the user will have to either manually push |
| 1606 |
* these events from the src-harness using gst_harness_src_push_event(), or |
| 1607 |
* create and push them manually. While this will allow full control and |
| 1608 |
* inspection of these events, for the most cases having forwarding enabled |
| 1609 |
* will be sufficient when writing a test where the src-harness' main function |
| 1610 |
* is providing data for the main-harness. |
| 1611 |
* |
| 1612 |
* Forwarding is enabled by default. |
| 1613 |
* |
| 1614 |
* MT safe. |
| 1615 |
* |
| 1616 |
* Since: 1.6 |
| 1617 |
*/ |
| 1618 |
void |
| 1619 |
gst_harness_set_forwarding (GstHarness * h, gboolean forwarding) |
| 1620 |
{ |
| 1621 |
GstHarnessPrivate *priv = h->priv; |
| 1622 |
priv->forwarding = forwarding; |
| 1623 |
if (h->src_harness) |
| 1624 |
gst_harness_set_forwarding (h->src_harness, forwarding); |
| 1625 |
if (h->sink_harness) |
| 1626 |
gst_harness_set_forwarding (h->sink_harness, forwarding); |
| 1627 |
} |
| 1628 |
|
| 1629 |
/* |
| 1630 |
* Call with HARNESS_LOCK |
| 1631 |
*/ |
| 1632 |
static void |
| 1633 |
gst_harness_set_forward_pad (GstHarness * h, GstPad * fwdpad) |
| 1634 |
{ |
| 1635 |
gst_object_replace ((GstObject **) & h->priv->sink_forward_pad, |
| 1636 |
(GstObject *) fwdpad); |
| 1637 |
} |
| 1638 |
|
| 1639 |
/** |
| 1640 |
* gst_harness_create_buffer: |
| 1641 |
* @h: a #GstHarness |
| 1642 |
* @size: a #gsize specifying the size of the buffer |
| 1643 |
* |
| 1644 |
* Allocates a buffer using a #GstBufferPool if present, or else using the |
| 1645 |
* configured #GstAllocator and #GstAllocationParams |
| 1646 |
* |
| 1647 |
* MT safe. |
| 1648 |
* |
| 1649 |
* Returns: a #GstBuffer of size @size |
| 1650 |
* |
| 1651 |
* Since: 1.6 |
| 1652 |
*/ |
| 1653 |
GstBuffer * |
| 1654 |
gst_harness_create_buffer (GstHarness * h, gsize size) |
| 1655 |
{ |
| 1656 |
GstHarnessPrivate *priv = h->priv; |
| 1657 |
GstBuffer *ret = NULL; |
| 1658 |
GstFlowReturn flow; |
| 1659 |
|
| 1660 |
if (gst_pad_check_reconfigure (h->srcpad)) |
| 1661 |
gst_harness_negotiate (h); |
| 1662 |
|
| 1663 |
if (priv->pool) { |
| 1664 |
flow = gst_buffer_pool_acquire_buffer (priv->pool, &ret, NULL); |
| 1665 |
g_assert_cmpint (flow, ==, GST_FLOW_OK); |
| 1666 |
if (gst_buffer_get_size (ret) != size) { |
| 1667 |
GST_DEBUG ("use fallback, pool is configured with a different size (%" |
| 1668 |
G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT ")", |
| 1669 |
size, gst_buffer_get_size (ret)); |
| 1670 |
gst_buffer_unref (ret); |
| 1671 |
ret = NULL; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
|
| 1675 |
if (!ret) |
| 1676 |
ret = |
| 1677 |
gst_buffer_new_allocate (priv->allocator, size, |
| 1678 |
&priv->allocation_params); |
| 1679 |
|
| 1680 |
g_assert (ret != NULL); |
| 1681 |
return ret; |
| 1682 |
} |
| 1683 |
|
| 1684 |
/** |
| 1685 |
* gst_harness_push: |
| 1686 |
* @h: a #GstHarness |
| 1687 |
* @buffer: (transfer full): a #GstBuffer to push |
| 1688 |
* |
| 1689 |
* Pushes a #GstBuffer on the #GstHarness srcpad. The standard way of |
| 1690 |
* interacting with an harnessed element. |
| 1691 |
* |
| 1692 |
* MT safe. |
| 1693 |
* |
| 1694 |
* Returns: a #GstFlowReturn with the result from the push |
| 1695 |
* |
| 1696 |
* Since: 1.6 |
| 1697 |
*/ |
| 1698 |
GstFlowReturn |
| 1699 |
gst_harness_push (GstHarness * h, GstBuffer * buffer) |
| 1700 |
{ |
| 1701 |
GstHarnessPrivate *priv = h->priv; |
| 1702 |
g_assert (buffer != NULL); |
| 1703 |
priv->last_push_ts = GST_BUFFER_TIMESTAMP (buffer); |
| 1704 |
return gst_pad_push (h->srcpad, buffer); |
| 1705 |
} |
| 1706 |
|
| 1707 |
/** |
| 1708 |
* gst_harness_pull: |
| 1709 |
* @h: a #GstHarness |
| 1710 |
* |
| 1711 |
* Pulls a #GstBuffer from the #GAsyncQueue on the #GstHarness sinkpad. The pull |
| 1712 |
* will timeout in 60 seconds. This is the standard way of getting a buffer |
| 1713 |
* from a harnessed #GstElement. |
| 1714 |
* |
| 1715 |
* MT safe. |
| 1716 |
* |
| 1717 |
* Returns: (transfer full) (nullable): a #GstBuffer or %NULL if timed out. |
| 1718 |
* |
| 1719 |
* Since: 1.6 |
| 1720 |
*/ |
| 1721 |
GstBuffer * |
| 1722 |
gst_harness_pull (GstHarness * h) |
| 1723 |
{ |
| 1724 |
GstHarnessPrivate *priv = h->priv; |
| 1725 |
GstBuffer *buf = (GstBuffer *) g_async_queue_timeout_pop (priv->buffer_queue, |
| 1726 |
G_USEC_PER_SEC * 60); |
| 1727 |
|
| 1728 |
if (priv->blocking_push_mode) { |
| 1729 |
g_mutex_lock (&priv->blocking_push_mutex); |
| 1730 |
g_cond_signal (&priv->blocking_push_cond); |
| 1731 |
g_mutex_unlock (&priv->blocking_push_mutex); |
| 1732 |
} |
| 1733 |
|
| 1734 |
return buf; |
| 1735 |
} |
| 1736 |
|
| 1737 |
/** |
| 1738 |
* gst_harness_pull_until_eos: |
| 1739 |
* @h: a #GstHarness |
| 1740 |
* @buf: (out) (nullable) (transfer full): A #GstBuffer, or %NULL if EOS or timeout occures |
| 1741 |
* first. |
| 1742 |
* |
| 1743 |
* Pulls a #GstBuffer from the #GAsyncQueue on the #GstHarness sinkpad. The pull |
| 1744 |
* will block until an EOS event is received, or timeout in 60 seconds. |
| 1745 |
* MT safe. |
| 1746 |
* |
| 1747 |
* Returns: %TRUE on success, %FALSE on timeout. |
| 1748 |
* |
| 1749 |
* Since: 1.18 |
| 1750 |
*/ |
| 1751 |
gboolean |
| 1752 |
gst_harness_pull_until_eos (GstHarness * h, GstBuffer ** buf) |
| 1753 |
{ |
| 1754 |
GstHarnessPrivate *priv = h->priv; |
| 1755 |
gboolean success = TRUE; |
| 1756 |
gint64 end_time = g_get_monotonic_time () + 60 * G_TIME_SPAN_SECOND; |
| 1757 |
|
| 1758 |
g_mutex_lock (&priv->buf_or_eos_mutex); |
| 1759 |
while (success) { |
| 1760 |
*buf = g_async_queue_try_pop (priv->buffer_queue); |
| 1761 |
if (*buf || priv->eos_received) |
| 1762 |
break; |
| 1763 |
success = g_cond_wait_until (&priv->buf_or_eos_cond, |
| 1764 |
&priv->buf_or_eos_mutex, end_time); |
| 1765 |
} |
| 1766 |
g_mutex_unlock (&priv->buf_or_eos_mutex); |
| 1767 |
|
| 1768 |
return success; |
| 1769 |
} |
| 1770 |
|
| 1771 |
/** |
| 1772 |
* gst_harness_try_pull: |
| 1773 |
* @h: a #GstHarness |
| 1774 |
* |
| 1775 |
* Pulls a #GstBuffer from the #GAsyncQueue on the #GstHarness sinkpad. Unlike |
| 1776 |
* gst_harness_pull this will not wait for any buffers if not any are present, |
| 1777 |
* and return %NULL straight away. |
| 1778 |
* |
| 1779 |
* MT safe. |
| 1780 |
* |
| 1781 |
* Returns: (transfer full) (nullable): a #GstBuffer or %NULL if no buffers are present in the #GAsyncQueue |
| 1782 |
* |
| 1783 |
* Since: 1.6 |
| 1784 |
*/ |
| 1785 |
GstBuffer * |
| 1786 |
gst_harness_try_pull (GstHarness * h) |
| 1787 |
{ |
| 1788 |
GstHarnessPrivate *priv = h->priv; |
| 1789 |
GstBuffer *buf = (GstBuffer *) g_async_queue_try_pop (priv->buffer_queue); |
| 1790 |
|
| 1791 |
if (priv->blocking_push_mode) { |
| 1792 |
g_mutex_lock (&priv->blocking_push_mutex); |
| 1793 |
g_cond_signal (&priv->blocking_push_cond); |
| 1794 |
g_mutex_unlock (&priv->blocking_push_mutex); |
| 1795 |
} |
| 1796 |
|
| 1797 |
return buf; |
| 1798 |
} |
| 1799 |
|
| 1800 |
/** |
| 1801 |
* gst_harness_push_and_pull: |
| 1802 |
* @h: a #GstHarness |
| 1803 |
* @buffer: (transfer full): a #GstBuffer to push |
| 1804 |
* |
| 1805 |
* Basically a gst_harness_push and a gst_harness_pull in one line. Reflects |
| 1806 |
* the fact that you often want to do exactly this in your test: Push one buffer |
| 1807 |
* in, and inspect the outcome. |
| 1808 |
* |
| 1809 |
* MT safe. |
| 1810 |
* |
| 1811 |
* Returns: (transfer full) (nullable): a #GstBuffer or %NULL if timed out. |
| 1812 |
* |
| 1813 |
* Since: 1.6 |
| 1814 |
*/ |
| 1815 |
GstBuffer * |
| 1816 |
gst_harness_push_and_pull (GstHarness * h, GstBuffer * buffer) |
| 1817 |
{ |
| 1818 |
gst_harness_push (h, buffer); |
| 1819 |
return gst_harness_pull (h); |
| 1820 |
} |
| 1821 |
|
| 1822 |
/** |
| 1823 |
* gst_harness_buffers_received: |
| 1824 |
* @h: a #GstHarness |
| 1825 |
* |
| 1826 |
* The total number of #GstBuffers that has arrived on the #GstHarness sinkpad. |
| 1827 |
* This number includes buffers that have been dropped as well as buffers |
| 1828 |
* that have already been pulled out. |
| 1829 |
* |
| 1830 |
* MT safe. |
| 1831 |
* |
| 1832 |
* Returns: a #guint number of buffers received |
| 1833 |
* |
| 1834 |
* Since: 1.6 |
| 1835 |
*/ |
| 1836 |
guint |
| 1837 |
gst_harness_buffers_received (GstHarness * h) |
| 1838 |
{ |
| 1839 |
GstHarnessPrivate *priv = h->priv; |
| 1840 |
return g_atomic_int_get (&priv->recv_buffers); |
| 1841 |
} |
| 1842 |
|
| 1843 |
/** |
| 1844 |
* gst_harness_buffers_in_queue: |
| 1845 |
* @h: a #GstHarness |
| 1846 |
* |
| 1847 |
* The number of #GstBuffers currently in the #GstHarness sinkpad #GAsyncQueue |
| 1848 |
* |
| 1849 |
* MT safe. |
| 1850 |
* |
| 1851 |
* Returns: a #guint number of buffers in the queue |
| 1852 |
* |
| 1853 |
* Since: 1.6 |
| 1854 |
*/ |
| 1855 |
guint |
| 1856 |
gst_harness_buffers_in_queue (GstHarness * h) |
| 1857 |
{ |
| 1858 |
GstHarnessPrivate *priv = h->priv; |
| 1859 |
return g_async_queue_length (priv->buffer_queue); |
| 1860 |
} |
| 1861 |
|
| 1862 |
/** |
| 1863 |
* gst_harness_set_drop_buffers: |
| 1864 |
* @h: a #GstHarness |
| 1865 |
* @drop_buffers: a #gboolean specifying to drop outgoing buffers or not |
| 1866 |
* |
| 1867 |
* When set to %TRUE, instead of placing the buffers arriving from the harnessed |
| 1868 |
* #GstElement inside the sinkpads #GAsyncQueue, they are instead unreffed. |
| 1869 |
* |
| 1870 |
* MT safe. |
| 1871 |
* |
| 1872 |
* Since: 1.6 |
| 1873 |
*/ |
| 1874 |
void |
| 1875 |
gst_harness_set_drop_buffers (GstHarness * h, gboolean drop_buffers) |
| 1876 |
{ |
| 1877 |
GstHarnessPrivate *priv = h->priv; |
| 1878 |
priv->drop_buffers = drop_buffers; |
| 1879 |
} |
| 1880 |
|
| 1881 |
/** |
| 1882 |
* gst_harness_take_all_data_as_buffer: |
| 1883 |
* @h: a #GstHarness |
| 1884 |
* |
| 1885 |
* Pulls all pending data from the harness and returns it as a single buffer. |
| 1886 |
* |
| 1887 |
* Returns: (transfer full): the data as a buffer. Unref with gst_buffer_unref() |
| 1888 |
* when no longer needed. |
| 1889 |
* |
| 1890 |
* Since: 1.14 |
| 1891 |
*/ |
| 1892 |
GstBuffer * |
| 1893 |
gst_harness_take_all_data_as_buffer (GstHarness * h) |
| 1894 |
{ |
| 1895 |
GstHarnessPrivate *priv; |
| 1896 |
GstBuffer *ret, *buf; |
| 1897 |
|
| 1898 |
g_return_val_if_fail (h != NULL, NULL); |
| 1899 |
|
| 1900 |
priv = h->priv; |
| 1901 |
|
| 1902 |
g_async_queue_lock (priv->buffer_queue); |
| 1903 |
|
| 1904 |
ret = g_async_queue_try_pop_unlocked (priv->buffer_queue); |
| 1905 |
|
| 1906 |
if (ret == NULL) { |
| 1907 |
ret = gst_buffer_new (); |
| 1908 |
} else { |
| 1909 |
/* buffer appending isn't very efficient for larger numbers of buffers |
| 1910 |
* or lots of memories, but this function is not performance critical and |
| 1911 |
* we can still improve it if and when the need arises. For now KISS. */ |
| 1912 |
while ((buf = g_async_queue_try_pop_unlocked (priv->buffer_queue))) |
| 1913 |
ret = gst_buffer_append (ret, buf); |
| 1914 |
} |
| 1915 |
|
| 1916 |
g_async_queue_unlock (priv->buffer_queue); |
| 1917 |
|
| 1918 |
return ret; |
| 1919 |
} |
| 1920 |
|
| 1921 |
/** |
| 1922 |
* gst_harness_take_all_data: (skip) |
| 1923 |
* @h: a #GstHarness |
| 1924 |
* @size: (out): the size of the data in bytes |
| 1925 |
* |
| 1926 |
* Pulls all pending data from the harness and returns it as a single |
| 1927 |
* data slice. |
| 1928 |
* |
| 1929 |
* Returns: (transfer full): a pointer to the data, newly allocated. Free |
| 1930 |
* with g_free() when no longer needed. Will return %NULL if there is no |
| 1931 |
* data. |
| 1932 |
* |
| 1933 |
* Since: 1.14 |
| 1934 |
*/ |
| 1935 |
guint8 * |
| 1936 |
gst_harness_take_all_data (GstHarness * h, gsize * size) |
| 1937 |
{ |
| 1938 |
GstBuffer *buf; |
| 1939 |
guint8 *data = NULL; |
| 1940 |
|
| 1941 |
g_return_val_if_fail (h != NULL, NULL); |
| 1942 |
g_return_val_if_fail (size != NULL, NULL); |
| 1943 |
|
| 1944 |
buf = gst_harness_take_all_data_as_buffer (h); |
| 1945 |
gst_buffer_extract_dup (buf, 0, -1, (gpointer *) & data, size); |
| 1946 |
gst_buffer_unref (buf); |
| 1947 |
return data; |
| 1948 |
} |
| 1949 |
|
| 1950 |
/** |
| 1951 |
* gst_harness_take_all_data_as_bytes: (rename-to gst_harness_take_all_data) |
| 1952 |
* @h: a #GstHarness |
| 1953 |
* |
| 1954 |
* Pulls all pending data from the harness and returns it as a single #GBytes. |
| 1955 |
* |
| 1956 |
* Returns: (transfer full): a pointer to the data, newly allocated. Free |
| 1957 |
* with g_free() when no longer needed. |
| 1958 |
* |
| 1959 |
* Since: 1.14 |
| 1960 |
*/ |
| 1961 |
GBytes * |
| 1962 |
gst_harness_take_all_data_as_bytes (GstHarness * h) |
| 1963 |
{ |
| 1964 |
guint8 *data; |
| 1965 |
gsize size = 0; |
| 1966 |
|
| 1967 |
g_return_val_if_fail (h != NULL, NULL); |
| 1968 |
|
| 1969 |
data = gst_harness_take_all_data (h, &size); |
| 1970 |
return g_bytes_new_take (data, size); |
| 1971 |
} |
| 1972 |
|
| 1973 |
|
| 1974 |
/** |
| 1975 |
* gst_harness_dump_to_file: |
| 1976 |
* @h: a #GstHarness |
| 1977 |
* @filename: a #gchar with a the name of a file |
| 1978 |
* |
| 1979 |
* Allows you to dump the #GstBuffers the #GstHarness sinkpad #GAsyncQueue |
| 1980 |
* to a file. |
| 1981 |
* |
| 1982 |
* MT safe. |
| 1983 |
* |
| 1984 |
* Since: 1.6 |
| 1985 |
*/ |
| 1986 |
void |
| 1987 |
gst_harness_dump_to_file (GstHarness * h, const gchar * filename) |
| 1988 |
{ |
| 1989 |
GError *err = NULL; |
| 1990 |
gpointer data; |
| 1991 |
gsize size; |
| 1992 |
|
| 1993 |
data = gst_harness_take_all_data (h, &size); |
| 1994 |
if (!g_file_set_contents (filename, data ? data : "", size, &err)) { |
| 1995 |
g_error ("GstHarness: Failed to write data to file: %s", err->message); |
| 1996 |
g_clear_error (&err); |
| 1997 |
} |
| 1998 |
g_free (data); |
| 1999 |
} |
| 2000 |
|
| 2001 |
/** |
| 2002 |
* gst_harness_get_last_pushed_timestamp: |
| 2003 |
* @h: a #GstHarness |
| 2004 |
* |
| 2005 |
* Get the timestamp of the last #GstBuffer pushed on the #GstHarness srcpad, |
| 2006 |
* typically with gst_harness_push or gst_harness_push_from_src. |
| 2007 |
* |
| 2008 |
* MT safe. |
| 2009 |
* |
| 2010 |
* Returns: a #GstClockTime with the timestamp or %GST_CLOCK_TIME_NONE if no |
| 2011 |
* #GstBuffer has been pushed on the #GstHarness srcpad |
| 2012 |
* |
| 2013 |
* Since: 1.6 |
| 2014 |
*/ |
| 2015 |
GstClockTime |
| 2016 |
gst_harness_get_last_pushed_timestamp (GstHarness * h) |
| 2017 |
{ |
| 2018 |
GstHarnessPrivate *priv = h->priv; |
| 2019 |
return priv->last_push_ts; |
| 2020 |
} |
| 2021 |
|
| 2022 |
/** |
| 2023 |
* gst_harness_push_event: |
| 2024 |
* @h: a #GstHarness |
| 2025 |
* @event: (transfer full): a #GstEvent to push |
| 2026 |
* |
| 2027 |
* Pushes an #GstEvent on the #GstHarness srcpad. |
| 2028 |
* |
| 2029 |
* MT safe. |
| 2030 |
* |
| 2031 |
* Returns: a #gboolean with the result from the push |
| 2032 |
* |
| 2033 |
* Since: 1.6 |
| 2034 |
*/ |
| 2035 |
gboolean |
| 2036 |
gst_harness_push_event (GstHarness * h, GstEvent * event) |
| 2037 |
{ |
| 2038 |
return gst_pad_push_event (h->srcpad, event); |
| 2039 |
} |
| 2040 |
|
| 2041 |
/** |
| 2042 |
* gst_harness_pull_event: |
| 2043 |
* @h: a #GstHarness |
| 2044 |
* |
| 2045 |
* Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness sinkpad. |
| 2046 |
* Timeouts after 60 seconds similar to gst_harness_pull. |
| 2047 |
* |
| 2048 |
* MT safe. |
| 2049 |
* |
| 2050 |
* Returns: (transfer full) (nullable): a #GstEvent or %NULL if timed out. |
| 2051 |
* |
| 2052 |
* Since: 1.6 |
| 2053 |
*/ |
| 2054 |
GstEvent * |
| 2055 |
gst_harness_pull_event (GstHarness * h) |
| 2056 |
{ |
| 2057 |
GstHarnessPrivate *priv = h->priv; |
| 2058 |
return (GstEvent *) g_async_queue_timeout_pop (priv->sink_event_queue, |
| 2059 |
G_USEC_PER_SEC * 60); |
| 2060 |
} |
| 2061 |
|
| 2062 |
/** |
| 2063 |
* gst_harness_try_pull_event: |
| 2064 |
* @h: a #GstHarness |
| 2065 |
* |
| 2066 |
* Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness sinkpad. |
| 2067 |
* See gst_harness_try_pull for details. |
| 2068 |
* |
| 2069 |
* MT safe. |
| 2070 |
* |
| 2071 |
* Returns: (transfer full) (nullable): a #GstEvent or %NULL if no buffers are present in the #GAsyncQueue |
| 2072 |
* |
| 2073 |
* Since: 1.6 |
| 2074 |
*/ |
| 2075 |
GstEvent * |
| 2076 |
gst_harness_try_pull_event (GstHarness * h) |
| 2077 |
{ |
| 2078 |
GstHarnessPrivate *priv = h->priv; |
| 2079 |
return (GstEvent *) g_async_queue_try_pop (priv->sink_event_queue); |
| 2080 |
} |
| 2081 |
|
| 2082 |
/** |
| 2083 |
* gst_harness_events_received: |
| 2084 |
* @h: a #GstHarness |
| 2085 |
* |
| 2086 |
* The total number of #GstEvents that has arrived on the #GstHarness sinkpad |
| 2087 |
* This number includes events handled by the harness as well as events |
| 2088 |
* that have already been pulled out. |
| 2089 |
* |
| 2090 |
* MT safe. |
| 2091 |
* |
| 2092 |
* Returns: a #guint number of events received |
| 2093 |
* |
| 2094 |
* Since: 1.6 |
| 2095 |
*/ |
| 2096 |
guint |
| 2097 |
gst_harness_events_received (GstHarness * h) |
| 2098 |
{ |
| 2099 |
GstHarnessPrivate *priv = h->priv; |
| 2100 |
return g_atomic_int_get (&priv->recv_events); |
| 2101 |
} |
| 2102 |
|
| 2103 |
/** |
| 2104 |
* gst_harness_events_in_queue: |
| 2105 |
* @h: a #GstHarness |
| 2106 |
* |
| 2107 |
* The number of #GstEvents currently in the #GstHarness sinkpad #GAsyncQueue |
| 2108 |
* |
| 2109 |
* MT safe. |
| 2110 |
* |
| 2111 |
* Returns: a #guint number of events in the queue |
| 2112 |
* |
| 2113 |
* Since: 1.6 |
| 2114 |
*/ |
| 2115 |
guint |
| 2116 |
gst_harness_events_in_queue (GstHarness * h) |
| 2117 |
{ |
| 2118 |
GstHarnessPrivate *priv = h->priv; |
| 2119 |
return g_async_queue_length (priv->sink_event_queue); |
| 2120 |
} |
| 2121 |
|
| 2122 |
/** |
| 2123 |
* gst_harness_push_upstream_event: |
| 2124 |
* @h: a #GstHarness |
| 2125 |
* @event: (transfer full): a #GstEvent to push |
| 2126 |
* |
| 2127 |
* Pushes an #GstEvent on the #GstHarness sinkpad. |
| 2128 |
* |
| 2129 |
* MT safe. |
| 2130 |
* |
| 2131 |
* Returns: a #gboolean with the result from the push |
| 2132 |
* |
| 2133 |
* Since: 1.6 |
| 2134 |
*/ |
| 2135 |
gboolean |
| 2136 |
gst_harness_push_upstream_event (GstHarness * h, GstEvent * event) |
| 2137 |
{ |
| 2138 |
g_return_val_if_fail (event != NULL, FALSE); |
| 2139 |
g_return_val_if_fail (GST_EVENT_IS_UPSTREAM (event), FALSE); |
| 2140 |
|
| 2141 |
return gst_pad_push_event (h->sinkpad, event); |
| 2142 |
} |
| 2143 |
|
| 2144 |
/** |
| 2145 |
* gst_harness_pull_upstream_event: |
| 2146 |
* @h: a #GstHarness |
| 2147 |
* |
| 2148 |
* Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness srcpad. |
| 2149 |
* Timeouts after 60 seconds similar to gst_harness_pull. |
| 2150 |
* |
| 2151 |
* MT safe. |
| 2152 |
* |
| 2153 |
* Returns: (transfer full) (nullable): a #GstEvent or %NULL if timed out. |
| 2154 |
* |
| 2155 |
* Since: 1.6 |
| 2156 |
*/ |
| 2157 |
GstEvent * |
| 2158 |
gst_harness_pull_upstream_event (GstHarness * h) |
| 2159 |
{ |
| 2160 |
GstHarnessPrivate *priv = h->priv; |
| 2161 |
return (GstEvent *) g_async_queue_timeout_pop (priv->src_event_queue, |
| 2162 |
G_USEC_PER_SEC * 60); |
| 2163 |
} |
| 2164 |
|
| 2165 |
/** |
| 2166 |
* gst_harness_try_pull_upstream_event: |
| 2167 |
* @h: a #GstHarness |
| 2168 |
* |
| 2169 |
* Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness srcpad. |
| 2170 |
* See gst_harness_try_pull for details. |
| 2171 |
* |
| 2172 |
* MT safe. |
| 2173 |
* |
| 2174 |
* Returns: (transfer full) (nullable): a #GstEvent or %NULL if no buffers are present in the #GAsyncQueue |
| 2175 |
* |
| 2176 |
* Since: 1.6 |
| 2177 |
*/ |
| 2178 |
GstEvent * |
| 2179 |
gst_harness_try_pull_upstream_event (GstHarness * h) |
| 2180 |
{ |
| 2181 |
GstHarnessPrivate *priv = h->priv; |
| 2182 |
return (GstEvent *) g_async_queue_try_pop (priv->src_event_queue); |
| 2183 |
} |
| 2184 |
|
| 2185 |
/** |
| 2186 |
* gst_harness_upstream_events_received: |
| 2187 |
* @h: a #GstHarness |
| 2188 |
* |
| 2189 |
* The total number of #GstEvents that has arrived on the #GstHarness srcpad |
| 2190 |
* This number includes events handled by the harness as well as events |
| 2191 |
* that have already been pulled out. |
| 2192 |
* |
| 2193 |
* MT safe. |
| 2194 |
* |
| 2195 |
* Returns: a #guint number of events received |
| 2196 |
* |
| 2197 |
* Since: 1.6 |
| 2198 |
*/ |
| 2199 |
guint |
| 2200 |
gst_harness_upstream_events_received (GstHarness * h) |
| 2201 |
{ |
| 2202 |
GstHarnessPrivate *priv = h->priv; |
| 2203 |
return g_atomic_int_get (&priv->recv_upstream_events); |
| 2204 |
} |
| 2205 |
|
| 2206 |
/** |
| 2207 |
* gst_harness_upstream_events_in_queue: |
| 2208 |
* @h: a #GstHarness |
| 2209 |
* |
| 2210 |
* The number of #GstEvents currently in the #GstHarness srcpad #GAsyncQueue |
| 2211 |
* |
| 2212 |
* MT safe. |
| 2213 |
* |
| 2214 |
* Returns: a #guint number of events in the queue |
| 2215 |
* |
| 2216 |
* Since: 1.6 |
| 2217 |
*/ |
| 2218 |
guint |
| 2219 |
gst_harness_upstream_events_in_queue (GstHarness * h) |
| 2220 |
{ |
| 2221 |
GstHarnessPrivate *priv = h->priv; |
| 2222 |
return g_async_queue_length (priv->src_event_queue); |
| 2223 |
} |
| 2224 |
|
| 2225 |
/** |
| 2226 |
* gst_harness_query_latency: |
| 2227 |
* @h: a #GstHarness |
| 2228 |
* |
| 2229 |
* Get the min latency reported by any harnessed #GstElement. |
| 2230 |
* |
| 2231 |
* MT safe. |
| 2232 |
* |
| 2233 |
* Returns: a #GstClockTime with min latency |
| 2234 |
* |
| 2235 |
* Since: 1.6 |
| 2236 |
*/ |
| 2237 |
GstClockTime |
| 2238 |
gst_harness_query_latency (GstHarness * h) |
| 2239 |
{ |
| 2240 |
GstQuery *query; |
| 2241 |
gboolean is_live; |
| 2242 |
GstClockTime min = GST_CLOCK_TIME_NONE; |
| 2243 |
GstClockTime max; |
| 2244 |
|
| 2245 |
query = gst_query_new_latency (); |
| 2246 |
|
| 2247 |
if (gst_pad_peer_query (h->sinkpad, query)) { |
| 2248 |
gst_query_parse_latency (query, &is_live, &min, &max); |
| 2249 |
} |
| 2250 |
gst_query_unref (query); |
| 2251 |
|
| 2252 |
return min; |
| 2253 |
} |
| 2254 |
|
| 2255 |
/** |
| 2256 |
* gst_harness_set_upstream_latency: |
| 2257 |
* @h: a #GstHarness |
| 2258 |
* @latency: a #GstClockTime specifying the latency |
| 2259 |
* |
| 2260 |
* Sets the min latency reported by #GstHarness when receiving a latency-query |
| 2261 |
* |
| 2262 |
* Since: 1.6 |
| 2263 |
*/ |
| 2264 |
void |
| 2265 |
gst_harness_set_upstream_latency (GstHarness * h, GstClockTime latency) |
| 2266 |
{ |
| 2267 |
g_return_if_fail (GST_CLOCK_TIME_IS_VALID (latency)); |
| 2268 |
|
| 2269 |
h->priv->latency_min = latency; |
| 2270 |
} |
| 2271 |
|
| 2272 |
/** |
| 2273 |
* gst_harness_set_live: |
| 2274 |
* @h: a #GstHarness |
| 2275 |
* @is_live: %TRUE for live, %FALSE for non-live |
| 2276 |
* |
| 2277 |
* Sets the liveness reported by #GstHarness when receiving a latency-query. |
| 2278 |
* The default is %TRUE. |
| 2279 |
* |
| 2280 |
* Since: 1.20 |
| 2281 |
*/ |
| 2282 |
void |
| 2283 |
gst_harness_set_live (GstHarness * h, gboolean is_live) |
| 2284 |
{ |
| 2285 |
GstHarnessPrivate *priv = h->priv; |
| 2286 |
priv->is_live = is_live; |
| 2287 |
} |
| 2288 |
|
| 2289 |
/** |
| 2290 |
* gst_harness_get_allocator: |
| 2291 |
* @h: a #GstHarness |
| 2292 |
* @allocator: (out) (optional) (nullable) (transfer none): the #GstAllocator used |
| 2293 |
* @params: (out) (optional): the #GstAllocationParams of |
| 2294 |
* @allocator |
| 2295 |
* |
| 2296 |
* Gets the @allocator and its @params that has been decided to use after an |
| 2297 |
* allocation query. |
| 2298 |
* |
| 2299 |
* MT safe. |
| 2300 |
* |
| 2301 |
* Since: 1.6 |
| 2302 |
*/ |
| 2303 |
void |
| 2304 |
gst_harness_get_allocator (GstHarness * h, GstAllocator ** allocator, |
| 2305 |
GstAllocationParams * params) |
| 2306 |
{ |
| 2307 |
GstHarnessPrivate *priv = h->priv; |
| 2308 |
if (allocator) |
| 2309 |
*allocator = priv->allocator; |
| 2310 |
if (params) |
| 2311 |
*params = priv->allocation_params; |
| 2312 |
} |
| 2313 |
|
| 2314 |
|
| 2315 |
/** |
| 2316 |
* gst_harness_set_propose_allocator: |
| 2317 |
* @h: a #GstHarness |
| 2318 |
* @allocator: (nullable) (transfer full): a #GstAllocator |
| 2319 |
* @params: (nullable) (transfer none): a #GstAllocationParams |
| 2320 |
* |
| 2321 |
* Sets the @allocator and @params to propose when receiving an allocation |
| 2322 |
* query. |
| 2323 |
* |
| 2324 |
* MT safe. |
| 2325 |
* |
| 2326 |
* Since: 1.6 |
| 2327 |
*/ |
| 2328 |
void |
| 2329 |
gst_harness_set_propose_allocator (GstHarness * h, GstAllocator * allocator, |
| 2330 |
const GstAllocationParams * params) |
| 2331 |
{ |
| 2332 |
GstHarnessPrivate *priv = h->priv; |
| 2333 |
if (allocator) |
| 2334 |
priv->propose_allocator = allocator; |
| 2335 |
if (params) |
| 2336 |
priv->propose_allocation_params = *params; |
| 2337 |
} |
| 2338 |
|
| 2339 |
/** |
| 2340 |
* gst_harness_add_propose_allocation_meta: |
| 2341 |
* @h: a #GstHarness |
| 2342 |
* @api: a metadata API |
| 2343 |
* @params: (nullable) (transfer none): API specific parameters |
| 2344 |
* |
| 2345 |
* Add api with params as one of the supported metadata API to propose when |
| 2346 |
* receiving an allocation query. |
| 2347 |
* |
| 2348 |
* MT safe. |
| 2349 |
* |
| 2350 |
* Since: 1.16 |
| 2351 |
*/ |
| 2352 |
void |
| 2353 |
gst_harness_add_propose_allocation_meta (GstHarness * h, GType api, |
| 2354 |
const GstStructure * params) |
| 2355 |
{ |
| 2356 |
GstHarnessPrivate *priv = h->priv; |
| 2357 |
ProposeMeta meta; |
| 2358 |
|
| 2359 |
meta.api = api; |
| 2360 |
meta.params = params ? gst_structure_copy (params) : NULL; |
| 2361 |
|
| 2362 |
if (!priv->propose_allocation_metas) { |
| 2363 |
priv->propose_allocation_metas = |
| 2364 |
g_array_new (FALSE, FALSE, sizeof (ProposeMeta)); |
| 2365 |
g_array_set_clear_func (priv->propose_allocation_metas, |
| 2366 |
(GDestroyNotify) propose_meta_clear); |
| 2367 |
} |
| 2368 |
g_array_append_val (priv->propose_allocation_metas, meta); |
| 2369 |
} |
| 2370 |
|
| 2371 |
/** |
| 2372 |
* gst_harness_add_src_harness: |
| 2373 |
* @h: a #GstHarness |
| 2374 |
* @src_harness: (transfer full): a #GstHarness to be added as a src-harness. |
| 2375 |
* @has_clock_wait: a #gboolean specifying if the #GstElement uses |
| 2376 |
* gst_clock_wait_id internally. |
| 2377 |
* |
| 2378 |
* A src-harness is a great way of providing the #GstHarness with data. |
| 2379 |
* By adding a src-type #GstElement, it is then easy to use functions like |
| 2380 |
* gst_harness_push_from_src or gst_harness_src_crank_and_push_many |
| 2381 |
* to provide your harnessed element with input. The @has_clock_wait variable |
| 2382 |
* is a great way to control you src-element with, in that you can have it |
| 2383 |
* produce a buffer for you by simply cranking the clock, and not have it |
| 2384 |
* spin out of control producing buffers as fast as possible. |
| 2385 |
* |
| 2386 |
* If a src-harness already exists it will be replaced. |
| 2387 |
* |
| 2388 |
* MT safe. |
| 2389 |
* |
| 2390 |
* Since: 1.6 |
| 2391 |
*/ |
| 2392 |
void |
| 2393 |
gst_harness_add_src_harness (GstHarness * h, |
| 2394 |
GstHarness * src_harness, gboolean has_clock_wait) |
| 2395 |
{ |
| 2396 |
if (h->src_harness) |
| 2397 |
gst_harness_teardown (h->src_harness); |
| 2398 |
h->src_harness = src_harness; |
| 2399 |
|
| 2400 |
HARNESS_LOCK (h->src_harness); |
| 2401 |
gst_harness_set_forward_pad (h->src_harness, h->srcpad); |
| 2402 |
HARNESS_UNLOCK (h->src_harness); |
| 2403 |
|
| 2404 |
h->src_harness->priv->has_clock_wait = has_clock_wait; |
| 2405 |
gst_harness_set_forwarding (h->src_harness, h->priv->forwarding); |
| 2406 |
} |
| 2407 |
|
| 2408 |
/** |
| 2409 |
* gst_harness_add_src: |
| 2410 |
* @h: a #GstHarness |
| 2411 |
* @src_element_name: a #gchar with the name of a #GstElement |
| 2412 |
* @has_clock_wait: a #gboolean specifying if the #GstElement uses |
| 2413 |
* gst_clock_wait_id internally. |
| 2414 |
* |
| 2415 |
* Similar to gst_harness_add_src_harness, this is a convenience to |
| 2416 |
* directly create a src-harness using the @src_element_name name specified. |
| 2417 |
* |
| 2418 |
* MT safe. |
| 2419 |
* |
| 2420 |
* Since: 1.6 |
| 2421 |
*/ |
| 2422 |
void |
| 2423 |
gst_harness_add_src (GstHarness * h, |
| 2424 |
const gchar * src_element_name, gboolean has_clock_wait) |
| 2425 |
{ |
| 2426 |
GstHarness *src_harness = gst_harness_new (src_element_name); |
| 2427 |
gst_harness_add_src_harness (h, src_harness, has_clock_wait); |
| 2428 |
} |
| 2429 |
|
| 2430 |
/** |
| 2431 |
* gst_harness_add_src_parse: |
| 2432 |
* @h: a #GstHarness |
| 2433 |
* @launchline: a #gchar describing a gst-launch type line |
| 2434 |
* @has_clock_wait: a #gboolean specifying if the #GstElement uses |
| 2435 |
* gst_clock_wait_id internally. |
| 2436 |
* |
| 2437 |
* Similar to gst_harness_add_src, this allows you to specify a launch-line, |
| 2438 |
* which can be useful for both having more then one #GstElement acting as your |
| 2439 |
* src (Like a src producing raw buffers, and then an encoder, providing encoded |
| 2440 |
* data), but also by allowing you to set properties like "is-live" directly on |
| 2441 |
* the elements. |
| 2442 |
* |
| 2443 |
* MT safe. |
| 2444 |
* |
| 2445 |
* Since: 1.6 |
| 2446 |
*/ |
| 2447 |
void |
| 2448 |
gst_harness_add_src_parse (GstHarness * h, |
| 2449 |
const gchar * launchline, gboolean has_clock_wait) |
| 2450 |
{ |
| 2451 |
GstHarness *src_harness = gst_harness_new_parse (launchline); |
| 2452 |
gst_harness_add_src_harness (h, src_harness, has_clock_wait); |
| 2453 |
} |
| 2454 |
|
| 2455 |
/** |
| 2456 |
* gst_harness_push_from_src: |
| 2457 |
* @h: a #GstHarness |
| 2458 |
* |
| 2459 |
* Transfer data from the src-#GstHarness to the main-#GstHarness. It consists |
| 2460 |
* of 4 steps: |
| 2461 |
* 1: Make sure the src is started. (see: gst_harness_play) |
| 2462 |
* 2: Crank the clock (see: gst_harness_crank_single_clock_wait) |
| 2463 |
* 3: Pull a #GstBuffer from the src-#GstHarness (see: gst_harness_pull) |
| 2464 |
* 4: Push the same #GstBuffer into the main-#GstHarness (see: gst_harness_push) |
| 2465 |
* |
| 2466 |
* MT safe. |
| 2467 |
* |
| 2468 |
* Returns: a #GstFlowReturn with the result of the push |
| 2469 |
* |
| 2470 |
* Since: 1.6 |
| 2471 |
*/ |
| 2472 |
GstFlowReturn |
| 2473 |
gst_harness_push_from_src (GstHarness * h) |
| 2474 |
{ |
| 2475 |
GstBuffer *buf; |
| 2476 |
gboolean crank; |
| 2477 |
|
| 2478 |
g_assert (h->src_harness); |
| 2479 |
|
| 2480 |
/* FIXME: this *is* the right time to start the src, |
| 2481 |
but maybe a flag so we don't keep telling it to play? */ |
| 2482 |
gst_harness_play (h->src_harness); |
| 2483 |
|
| 2484 |
if (h->src_harness->priv->has_clock_wait) { |
| 2485 |
crank = gst_harness_crank_single_clock_wait (h->src_harness); |
| 2486 |
g_assert (crank); |
| 2487 |
} |
| 2488 |
|
| 2489 |
buf = gst_harness_pull (h->src_harness); |
| 2490 |
g_assert (buf != NULL); |
| 2491 |
return gst_harness_push (h, buf); |
| 2492 |
} |
| 2493 |
|
| 2494 |
/** |
| 2495 |
* gst_harness_src_crank_and_push_many: |
| 2496 |
* @h: a #GstHarness |
| 2497 |
* @cranks: a #gint with the number of calls to gst_harness_crank_single_clock_wait |
| 2498 |
* @pushes: a #gint with the number of calls to gst_harness_push |
| 2499 |
* |
| 2500 |
* Transfer data from the src-#GstHarness to the main-#GstHarness. Similar to |
| 2501 |
* gst_harness_push_from_src, this variant allows you to specify how many cranks |
| 2502 |
* and how many pushes to perform. This can be useful for both moving a lot |
| 2503 |
* of data at the same time, as well as cases when one crank does not equal one |
| 2504 |
* buffer to push and v.v. |
| 2505 |
* |
| 2506 |
* MT safe. |
| 2507 |
* |
| 2508 |
* Returns: a #GstFlowReturn with the result of the push |
| 2509 |
* |
| 2510 |
* Since: 1.6 |
| 2511 |
*/ |
| 2512 |
GstFlowReturn |
| 2513 |
gst_harness_src_crank_and_push_many (GstHarness * h, gint cranks, gint pushes) |
| 2514 |
{ |
| 2515 |
GstFlowReturn ret = GST_FLOW_OK; |
| 2516 |
gboolean crank; |
| 2517 |
int i; |
| 2518 |
|
| 2519 |
g_assert (h->src_harness); |
| 2520 |
gst_harness_play (h->src_harness); |
| 2521 |
|
| 2522 |
for (i = 0; i < cranks; i++) { |
| 2523 |
crank = gst_harness_crank_single_clock_wait (h->src_harness); |
| 2524 |
g_assert (crank); |
| 2525 |
} |
| 2526 |
|
| 2527 |
for (i = 0; i < pushes; i++) { |
| 2528 |
GstBuffer *buf; |
| 2529 |
buf = gst_harness_pull (h->src_harness); |
| 2530 |
g_assert (buf != NULL); |
| 2531 |
ret = gst_harness_push (h, buf); |
| 2532 |
if (ret != GST_FLOW_OK) |
| 2533 |
break; |
| 2534 |
} |
| 2535 |
|
| 2536 |
return ret; |
| 2537 |
} |
| 2538 |
|
| 2539 |
/** |
| 2540 |
* gst_harness_src_push_event: |
| 2541 |
* @h: a #GstHarness |
| 2542 |
* |
| 2543 |
* Similar to what gst_harness_src_push does with #GstBuffers, this transfers |
| 2544 |
* a #GstEvent from the src-#GstHarness to the main-#GstHarness. Note that |
| 2545 |
* some #GstEvents are being transferred automagically. Look at sink_forward_pad |
| 2546 |
* for details. |
| 2547 |
* |
| 2548 |
* MT safe. |
| 2549 |
* |
| 2550 |
* Returns: a #gboolean with the result of the push |
| 2551 |
* |
| 2552 |
* Since: 1.6 |
| 2553 |
*/ |
| 2554 |
gboolean |
| 2555 |
gst_harness_src_push_event (GstHarness * h) |
| 2556 |
{ |
| 2557 |
return gst_harness_push_event (h, gst_harness_pull_event (h->src_harness)); |
| 2558 |
} |
| 2559 |
|
| 2560 |
|
| 2561 |
static gboolean |
| 2562 |
forward_sticky_events (GstPad * pad, GstEvent ** ev, gpointer user_data) |
| 2563 |
{ |
| 2564 |
GstPad *fwdpad = user_data; |
| 2565 |
return gst_pad_push_event (fwdpad, gst_event_ref (*ev)); |
| 2566 |
} |
| 2567 |
|
| 2568 |
/** |
| 2569 |
* gst_harness_add_sink_harness: |
| 2570 |
* @h: a #GstHarness |
| 2571 |
* @sink_harness: (transfer full): a #GstHarness to be added as a sink-harness. |
| 2572 |
* |
| 2573 |
* Similar to gst_harness_add_src, this allows you to send the data coming out |
| 2574 |
* of your harnessed #GstElement to a sink-element, allowing to test different |
| 2575 |
* responses the element output might create in sink elements. An example might |
| 2576 |
* be an existing sink providing some analytical data on the input it receives that |
| 2577 |
* can be useful to your testing. If the goal is to test a sink-element itself, |
| 2578 |
* this is better achieved using gst_harness_new directly on the sink. |
| 2579 |
* |
| 2580 |
* If a sink-harness already exists it will be replaced. |
| 2581 |
* |
| 2582 |
* MT safe. |
| 2583 |
* |
| 2584 |
* Since: 1.6 |
| 2585 |
*/ |
| 2586 |
void |
| 2587 |
gst_harness_add_sink_harness (GstHarness * h, GstHarness * sink_harness) |
| 2588 |
{ |
| 2589 |
GstHarnessPrivate *priv; |
| 2590 |
GstPad *fwdpad; |
| 2591 |
|
| 2592 |
HARNESS_LOCK (h); |
| 2593 |
priv = h->priv; |
| 2594 |
|
| 2595 |
if (h->sink_harness) { |
| 2596 |
gst_harness_set_forward_pad (h, NULL); |
| 2597 |
gst_harness_teardown (h->sink_harness); |
| 2598 |
} |
| 2599 |
h->sink_harness = sink_harness; |
| 2600 |
|
| 2601 |
fwdpad = h->sink_harness->srcpad; |
| 2602 |
if (fwdpad) |
| 2603 |
gst_object_ref (fwdpad); |
| 2604 |
|
| 2605 |
if (priv->forwarding && h->sinkpad && fwdpad) { |
| 2606 |
HARNESS_UNLOCK (h); |
| 2607 |
gst_pad_sticky_events_foreach (h->sinkpad, forward_sticky_events, fwdpad); |
| 2608 |
HARNESS_LOCK (h); |
| 2609 |
} |
| 2610 |
|
| 2611 |
gst_harness_set_forward_pad (h, fwdpad); |
| 2612 |
if (fwdpad) |
| 2613 |
gst_object_unref (fwdpad); |
| 2614 |
|
| 2615 |
gst_harness_set_forwarding (h->sink_harness, priv->forwarding); |
| 2616 |
|
| 2617 |
HARNESS_UNLOCK (h); |
| 2618 |
} |
| 2619 |
|
| 2620 |
/** |
| 2621 |
* gst_harness_add_sink: |
| 2622 |
* @h: a #GstHarness |
| 2623 |
* @sink_element_name: a #gchar with the name of a #GstElement |
| 2624 |
* |
| 2625 |
* Similar to gst_harness_add_sink_harness, this is a convenience to |
| 2626 |
* directly create a sink-harness using the @sink_element_name name specified. |
| 2627 |
* |
| 2628 |
* MT safe. |
| 2629 |
* |
| 2630 |
* Since: 1.6 |
| 2631 |
*/ |
| 2632 |
void |
| 2633 |
gst_harness_add_sink (GstHarness * h, const gchar * sink_element_name) |
| 2634 |
{ |
| 2635 |
GstHarness *sink_harness = gst_harness_new (sink_element_name); |
| 2636 |
gst_harness_add_sink_harness (h, sink_harness); |
| 2637 |
} |
| 2638 |
|
| 2639 |
/** |
| 2640 |
* gst_harness_add_sink_parse: |
| 2641 |
* @h: a #GstHarness |
| 2642 |
* @launchline: a #gchar with the name of a #GstElement |
| 2643 |
* |
| 2644 |
* Similar to gst_harness_add_sink, this allows you to specify a launch-line |
| 2645 |
* instead of just an element name. See gst_harness_add_src_parse for details. |
| 2646 |
* |
| 2647 |
* MT safe. |
| 2648 |
* |
| 2649 |
* Since: 1.6 |
| 2650 |
*/ |
| 2651 |
void |
| 2652 |
gst_harness_add_sink_parse (GstHarness * h, const gchar * launchline) |
| 2653 |
{ |
| 2654 |
GstHarness *sink_harness = gst_harness_new_parse (launchline); |
| 2655 |
gst_harness_add_sink_harness (h, sink_harness); |
| 2656 |
} |
| 2657 |
|
| 2658 |
/** |
| 2659 |
* gst_harness_push_to_sink: |
| 2660 |
* @h: a #GstHarness |
| 2661 |
* |
| 2662 |
* Transfer one #GstBuffer from the main-#GstHarness to the sink-#GstHarness. |
| 2663 |
* See gst_harness_push_from_src for details. |
| 2664 |
* |
| 2665 |
* MT safe. |
| 2666 |
* |
| 2667 |
* Returns: a #GstFlowReturn with the result of the push |
| 2668 |
* |
| 2669 |
* Since: 1.6 |
| 2670 |
*/ |
| 2671 |
GstFlowReturn |
| 2672 |
gst_harness_push_to_sink (GstHarness * h) |
| 2673 |
{ |
| 2674 |
GstBuffer *buf; |
| 2675 |
g_assert (h->sink_harness); |
| 2676 |
buf = gst_harness_pull (h); |
| 2677 |
g_assert (buf != NULL); |
| 2678 |
return gst_harness_push (h->sink_harness, buf); |
| 2679 |
} |
| 2680 |
|
| 2681 |
/** |
| 2682 |
* gst_harness_sink_push_many: |
| 2683 |
* @h: a #GstHarness |
| 2684 |
* @pushes: a #gint with the number of calls to gst_harness_push_to_sink |
| 2685 |
* |
| 2686 |
* Convenience that calls gst_harness_push_to_sink @pushes number of times. |
| 2687 |
* Will abort the pushing if any one push fails. |
| 2688 |
* |
| 2689 |
* MT safe. |
| 2690 |
* |
| 2691 |
* Returns: a #GstFlowReturn with the result of the push |
| 2692 |
* |
| 2693 |
* Since: 1.6 |
| 2694 |
*/ |
| 2695 |
GstFlowReturn |
| 2696 |
gst_harness_sink_push_many (GstHarness * h, gint pushes) |
| 2697 |
{ |
| 2698 |
GstFlowReturn ret = GST_FLOW_OK; |
| 2699 |
int i; |
| 2700 |
g_assert (h->sink_harness); |
| 2701 |
for (i = 0; i < pushes; i++) { |
| 2702 |
ret = gst_harness_push_to_sink (h); |
| 2703 |
if (ret != GST_FLOW_OK) |
| 2704 |
break; |
| 2705 |
} |
| 2706 |
return ret; |
| 2707 |
} |
| 2708 |
|
| 2709 |
/** |
| 2710 |
* gst_harness_find_element: |
| 2711 |
* @h: a #GstHarness |
| 2712 |
* @element_name: a #gchar with a #GstElementFactory name |
| 2713 |
* |
| 2714 |
* Most useful in conjunction with gst_harness_new_parse, this will scan the |
| 2715 |
* #GstElements inside the #GstHarness, and check if any of them matches |
| 2716 |
* @element_name. Typical usecase being that you need to access one of the |
| 2717 |
* harnessed elements for properties and/or signals. |
| 2718 |
* |
| 2719 |
* MT safe. |
| 2720 |
* |
| 2721 |
* Returns: (transfer full) (nullable): a #GstElement or %NULL if not found |
| 2722 |
* |
| 2723 |
* Since: 1.6 |
| 2724 |
*/ |
| 2725 |
GstElement * |
| 2726 |
gst_harness_find_element (GstHarness * h, const gchar * element_name) |
| 2727 |
{ |
| 2728 |
gboolean done = FALSE; |
| 2729 |
GstIterator *iter; |
| 2730 |
GValue data = G_VALUE_INIT; |
| 2731 |
|
| 2732 |
if (!GST_IS_BIN (h->element)) { |
| 2733 |
GstPluginFeature *feature; |
| 2734 |
|
| 2735 |
g_return_val_if_fail (GST_IS_ELEMENT (h->element), NULL); |
| 2736 |
|
| 2737 |
feature = GST_PLUGIN_FEATURE (gst_element_get_factory (h->element)); |
| 2738 |
if (!strcmp (element_name, gst_plugin_feature_get_name (feature))) |
| 2739 |
return gst_object_ref (h->element); |
| 2740 |
|
| 2741 |
return NULL; |
| 2742 |
} |
| 2743 |
|
| 2744 |
iter = gst_bin_iterate_elements (GST_BIN (h->element)); |
| 2745 |
done = FALSE; |
| 2746 |
|
| 2747 |
while (!done) { |
| 2748 |
switch (gst_iterator_next (iter, &data)) { |
| 2749 |
case GST_ITERATOR_OK: |
| 2750 |
{ |
| 2751 |
GstElement *element = g_value_get_object (&data); |
| 2752 |
GstPluginFeature *feature = |
| 2753 |
GST_PLUGIN_FEATURE (gst_element_get_factory (element)); |
| 2754 |
if (!strcmp (element_name, gst_plugin_feature_get_name (feature))) { |
| 2755 |
gst_iterator_free (iter); |
| 2756 |
return element; |
| 2757 |
} |
| 2758 |
g_value_reset (&data); |
| 2759 |
break; |
| 2760 |
} |
| 2761 |
case GST_ITERATOR_RESYNC: |
| 2762 |
gst_iterator_resync (iter); |
| 2763 |
break; |
| 2764 |
case GST_ITERATOR_ERROR: |
| 2765 |
case GST_ITERATOR_DONE: |
| 2766 |
done = TRUE; |
| 2767 |
break; |
| 2768 |
} |
| 2769 |
} |
| 2770 |
gst_iterator_free (iter); |
| 2771 |
|
| 2772 |
return NULL; |
| 2773 |
} |
| 2774 |
|
| 2775 |
/** |
| 2776 |
* gst_harness_set: |
| 2777 |
* @h: a #GstHarness |
| 2778 |
* @element_name: a #gchar with a #GstElementFactory name |
| 2779 |
* @first_property_name: a #gchar with the first property name |
| 2780 |
* @...: value for the first property, followed optionally by more |
| 2781 |
* name/value pairs, followed by %NULL |
| 2782 |
* |
| 2783 |
* A convenience function to allows you to call g_object_set on a #GstElement |
| 2784 |
* that are residing inside the #GstHarness, by using normal g_object_set |
| 2785 |
* syntax. |
| 2786 |
* |
| 2787 |
* MT safe. |
| 2788 |
* |
| 2789 |
* Since: 1.6 |
| 2790 |
*/ |
| 2791 |
void |
| 2792 |
gst_harness_set (GstHarness * h, |
| 2793 |
const gchar * element_name, const gchar * first_property_name, ...) |
| 2794 |
{ |
| 2795 |
va_list var_args; |
| 2796 |
GstElement *element = gst_harness_find_element (h, element_name); |
| 2797 |
va_start (var_args, first_property_name); |
| 2798 |
g_object_set_valist (G_OBJECT (element), first_property_name, var_args); |
| 2799 |
va_end (var_args); |
| 2800 |
gst_object_unref (element); |
| 2801 |
} |
| 2802 |
|
| 2803 |
/** |
| 2804 |
* gst_harness_get: |
| 2805 |
* @h: a #GstHarness |
| 2806 |
* @element_name: a #gchar with a #GstElementFactory name |
| 2807 |
* @first_property_name: a #gchar with the first property name |
| 2808 |
* @...: return location for the first property, followed optionally by more |
| 2809 |
* name/return location pairs, followed by %NULL |
| 2810 |
* |
| 2811 |
* A convenience function to allows you to call g_object_get on a #GstElement |
| 2812 |
* that are residing inside the #GstHarness, by using normal g_object_get |
| 2813 |
* syntax. |
| 2814 |
* |
| 2815 |
* MT safe. |
| 2816 |
* |
| 2817 |
* Since: 1.6 |
| 2818 |
*/ |
| 2819 |
void |
| 2820 |
gst_harness_get (GstHarness * h, |
| 2821 |
const gchar * element_name, const gchar * first_property_name, ...) |
| 2822 |
{ |
| 2823 |
va_list var_args; |
| 2824 |
GstElement *element = gst_harness_find_element (h, element_name); |
| 2825 |
va_start (var_args, first_property_name); |
| 2826 |
g_object_get_valist (G_OBJECT (element), first_property_name, var_args); |
| 2827 |
va_end (var_args); |
| 2828 |
gst_object_unref (element); |
| 2829 |
} |
| 2830 |
|
| 2831 |
/** |
| 2832 |
* gst_harness_add_probe: |
| 2833 |
* @h: a #GstHarness |
| 2834 |
* @element_name: a #gchar with a #GstElementFactory name |
| 2835 |
* @pad_name: a #gchar with the name of the pad to attach the probe to |
| 2836 |
* @mask: a #GstPadProbeType (see gst_pad_add_probe) |
| 2837 |
* @callback: a #GstPadProbeCallback (see gst_pad_add_probe) |
| 2838 |
* @user_data: a #gpointer (see gst_pad_add_probe) |
| 2839 |
* @destroy_data: a #GDestroyNotify (see gst_pad_add_probe) |
| 2840 |
* |
| 2841 |
* A convenience function to allows you to call gst_pad_add_probe on a |
| 2842 |
* #GstPad of a #GstElement that are residing inside the #GstHarness, |
| 2843 |
* by using normal gst_pad_add_probe syntax |
| 2844 |
* |
| 2845 |
* MT safe. |
| 2846 |
* |
| 2847 |
* Since: 1.6 |
| 2848 |
*/ |
| 2849 |
void |
| 2850 |
gst_harness_add_probe (GstHarness * h, |
| 2851 |
const gchar * element_name, const gchar * pad_name, GstPadProbeType mask, |
| 2852 |
GstPadProbeCallback callback, gpointer user_data, |
| 2853 |
GDestroyNotify destroy_data) |
| 2854 |
{ |
| 2855 |
GstElement *element = gst_harness_find_element (h, element_name); |
| 2856 |
GstPad *pad = gst_element_get_static_pad (element, pad_name); |
| 2857 |
gst_pad_add_probe (pad, mask, callback, user_data, destroy_data); |
| 2858 |
gst_object_unref (pad); |
| 2859 |
gst_object_unref (element); |
| 2860 |
} |
| 2861 |
|
| 2862 |
/******************************************************************************/ |
| 2863 |
/* STRESS */ |
| 2864 |
/******************************************************************************/ |
| 2865 |
struct _GstHarnessThread |
| 2866 |
{ |
| 2867 |
GstHarness *h; |
| 2868 |
GThread *thread; |
| 2869 |
gboolean running; |
| 2870 |
|
| 2871 |
gulong sleep; |
| 2872 |
|
| 2873 |
GDestroyNotify freefunc; |
| 2874 |
}; |
| 2875 |
|
| 2876 |
typedef struct |
| 2877 |
{ |
| 2878 |
GstHarnessThread t; |
| 2879 |
|
| 2880 |
GFunc init; |
| 2881 |
GFunc callback; |
| 2882 |
gpointer data; |
| 2883 |
} GstHarnessCustomThread; |
| 2884 |
|
| 2885 |
typedef struct |
| 2886 |
{ |
| 2887 |
GstHarnessThread t; |
| 2888 |
|
| 2889 |
GstCaps *caps; |
| 2890 |
GstSegment segment; |
| 2891 |
GstHarnessPrepareBufferFunc func; |
| 2892 |
gpointer data; |
| 2893 |
GDestroyNotify notify; |
| 2894 |
} GstHarnessPushBufferThread; |
| 2895 |
|
| 2896 |
typedef struct |
| 2897 |
{ |
| 2898 |
GstHarnessThread t; |
| 2899 |
|
| 2900 |
GstHarnessPrepareEventFunc func; |
| 2901 |
gpointer data; |
| 2902 |
GDestroyNotify notify; |
| 2903 |
} GstHarnessPushEventThread; |
| 2904 |
|
| 2905 |
typedef struct |
| 2906 |
{ |
| 2907 |
GstHarnessThread t; |
| 2908 |
|
| 2909 |
gchar *name; |
| 2910 |
GValue value; |
| 2911 |
} GstHarnessPropThread; |
| 2912 |
|
| 2913 |
typedef struct |
| 2914 |
{ |
| 2915 |
GstHarnessThread t; |
| 2916 |
|
| 2917 |
GstPadTemplate *templ; |
| 2918 |
gchar *name; |
| 2919 |
GstCaps *caps; |
| 2920 |
gboolean release; |
| 2921 |
|
| 2922 |
GSList *pads; |
| 2923 |
} GstHarnessReqPadThread; |
| 2924 |
|
| 2925 |
static void |
| 2926 |
gst_harness_thread_init (GstHarnessThread * t, GDestroyNotify freefunc, |
| 2927 |
GstHarness * h, gulong sleep) |
| 2928 |
{ |
| 2929 |
t->freefunc = freefunc; |
| 2930 |
t->h = h; |
| 2931 |
t->sleep = sleep; |
| 2932 |
|
| 2933 |
g_ptr_array_add (h->priv->stress, t); |
| 2934 |
} |
| 2935 |
|
| 2936 |
static void |
| 2937 |
gst_harness_thread_free (GstHarnessThread * t) |
| 2938 |
{ |
| 2939 |
g_free (t); |
| 2940 |
} |
| 2941 |
|
| 2942 |
static void |
| 2943 |
gst_harness_custom_thread_free (GstHarnessCustomThread * t) |
| 2944 |
{ |
| 2945 |
g_free (t); |
| 2946 |
} |
| 2947 |
|
| 2948 |
static void |
| 2949 |
gst_harness_push_buffer_thread_free (GstHarnessPushBufferThread * t) |
| 2950 |
{ |
| 2951 |
if (t != NULL) { |
| 2952 |
gst_caps_replace (&t->caps, NULL); |
| 2953 |
if (t->notify != NULL) |
| 2954 |
t->notify (t->data); |
| 2955 |
g_free (t); |
| 2956 |
} |
| 2957 |
} |
| 2958 |
|
| 2959 |
static void |
| 2960 |
gst_harness_push_event_thread_free (GstHarnessPushEventThread * t) |
| 2961 |
{ |
| 2962 |
if (t != NULL) { |
| 2963 |
if (t->notify != NULL) |
| 2964 |
t->notify (t->data); |
| 2965 |
g_free (t); |
| 2966 |
} |
| 2967 |
} |
| 2968 |
|
| 2969 |
static void |
| 2970 |
gst_harness_property_thread_free (GstHarnessPropThread * t) |
| 2971 |
{ |
| 2972 |
if (t != NULL) { |
| 2973 |
g_free (t->name); |
| 2974 |
g_value_unset (&t->value); |
| 2975 |
g_free (t); |
| 2976 |
} |
| 2977 |
} |
| 2978 |
|
| 2979 |
static void |
| 2980 |
gst_harness_requestpad_release (GstPad * pad, GstElement * element) |
| 2981 |
{ |
| 2982 |
gst_element_release_request_pad (element, pad); |
| 2983 |
gst_object_unref (pad); |
| 2984 |
} |
| 2985 |
|
| 2986 |
static void |
| 2987 |
gst_harness_requestpad_release_pads (GstHarnessReqPadThread * rpt) |
| 2988 |
{ |
| 2989 |
g_slist_foreach (rpt->pads, (GFunc) gst_harness_requestpad_release, |
| 2990 |
rpt->t.h->element); |
| 2991 |
g_slist_free (rpt->pads); |
| 2992 |
rpt->pads = NULL; |
| 2993 |
} |
| 2994 |
|
| 2995 |
static void |
| 2996 |
gst_harness_requestpad_thread_free (GstHarnessReqPadThread * t) |
| 2997 |
{ |
| 2998 |
if (t != NULL) { |
| 2999 |
gst_object_replace ((GstObject **) & t->templ, NULL); |
| 3000 |
g_free (t->name); |
| 3001 |
gst_caps_replace (&t->caps, NULL); |
| 3002 |
|
| 3003 |
gst_harness_requestpad_release_pads (t); |
| 3004 |
g_free (t); |
| 3005 |
} |
| 3006 |
} |
| 3007 |
|
| 3008 |
#define GST_HARNESS_THREAD_START(ID, t) \ |
| 3009 |
(((GstHarnessThread *)t)->running = TRUE, \ |
| 3010 |
((GstHarnessThread *)t)->thread = g_thread_new ( \ |
| 3011 |
"gst-harness-stress-"G_STRINGIFY(ID), \ |
| 3012 |
(GThreadFunc)gst_harness_stress_##ID##_func, t)) |
| 3013 |
#define GST_HARNESS_THREAD_END(t) \ |
| 3014 |
(t->running = FALSE, \ |
| 3015 |
GPOINTER_TO_UINT (g_thread_join (t->thread))) |
| 3016 |
|
| 3017 |
static void |
| 3018 |
gst_harness_stress_free (GstHarnessThread * t) |
| 3019 |
{ |
| 3020 |
if (t != NULL && t->freefunc != NULL) |
| 3021 |
t->freefunc (t); |
| 3022 |
} |
| 3023 |
|
| 3024 |
static gpointer |
| 3025 |
gst_harness_stress_custom_func (GstHarnessThread * t) |
| 3026 |
{ |
| 3027 |
GstHarnessCustomThread *ct = (GstHarnessCustomThread *) t; |
| 3028 |
guint count = 0; |
| 3029 |
|
| 3030 |
if (ct->init != NULL) |
| 3031 |
ct->init (ct, ct->data); |
| 3032 |
|
| 3033 |
while (t->running) { |
| 3034 |
ct->callback (ct, ct->data); |
| 3035 |
|
| 3036 |
count++; |
| 3037 |
g_usleep (t->sleep); |
| 3038 |
} |
| 3039 |
return GUINT_TO_POINTER (count); |
| 3040 |
} |
| 3041 |
|
| 3042 |
|
| 3043 |
static gpointer |
| 3044 |
gst_harness_stress_statechange_func (GstHarnessThread * t) |
| 3045 |
{ |
| 3046 |
guint count = 0; |
| 3047 |
|
| 3048 |
while (t->running) { |
| 3049 |
GstClock *clock = gst_element_get_clock (t->h->element); |
| 3050 |
GstIterator *it; |
| 3051 |
gboolean done = FALSE; |
| 3052 |
gboolean change; |
| 3053 |
|
| 3054 |
change = gst_element_set_state (t->h->element, GST_STATE_NULL); |
| 3055 |
g_assert (change == GST_STATE_CHANGE_SUCCESS); |
| 3056 |
g_thread_yield (); |
| 3057 |
|
| 3058 |
it = gst_element_iterate_sink_pads (t->h->element); |
| 3059 |
while (!done) { |
| 3060 |
GValue item = G_VALUE_INIT; |
| 3061 |
switch (gst_iterator_next (it, &item)) { |
| 3062 |
case GST_ITERATOR_OK: |
| 3063 |
{ |
| 3064 |
GstPad *sinkpad = g_value_get_object (&item); |
| 3065 |
GstPad *srcpad = gst_pad_get_peer (sinkpad); |
| 3066 |
if (srcpad != NULL) { |
| 3067 |
gst_pad_unlink (srcpad, sinkpad); |
| 3068 |
gst_pad_link (srcpad, sinkpad); |
| 3069 |
gst_object_unref (srcpad); |
| 3070 |
} |
| 3071 |
g_value_reset (&item); |
| 3072 |
break; |
| 3073 |
} |
| 3074 |
case GST_ITERATOR_RESYNC: |
| 3075 |
gst_iterator_resync (it); |
| 3076 |
break; |
| 3077 |
case GST_ITERATOR_ERROR: |
| 3078 |
g_assert_not_reached (); |
| 3079 |
case GST_ITERATOR_DONE: |
| 3080 |
done = TRUE; |
| 3081 |
break; |
| 3082 |
} |
| 3083 |
g_value_unset (&item); |
| 3084 |
} |
| 3085 |
gst_iterator_free (it); |
| 3086 |
|
| 3087 |
if (clock != NULL) { |
| 3088 |
gst_element_set_clock (t->h->element, clock); |
| 3089 |
gst_object_unref (clock); |
| 3090 |
} |
| 3091 |
change = gst_element_set_state (t->h->element, GST_STATE_PLAYING); |
| 3092 |
g_assert (change == GST_STATE_CHANGE_SUCCESS); |
| 3093 |
|
| 3094 |
count++; |
| 3095 |
g_usleep (t->sleep); |
| 3096 |
} |
| 3097 |
return GUINT_TO_POINTER (count); |
| 3098 |
} |
| 3099 |
|
| 3100 |
static gpointer |
| 3101 |
gst_harness_stress_buffer_func (GstHarnessThread * t) |
| 3102 |
{ |
| 3103 |
GstHarnessPushBufferThread *pt = (GstHarnessPushBufferThread *) t; |
| 3104 |
guint count = 0; |
| 3105 |
gchar *sid; |
| 3106 |
gboolean handled; |
| 3107 |
|
| 3108 |
/* Push stream start, caps and segment events */ |
| 3109 |
sid = g_strdup_printf ("%s-%p", GST_OBJECT_NAME (t->h->element), t->h); |
| 3110 |
handled = gst_pad_push_event (t->h->srcpad, gst_event_new_stream_start (sid)); |
| 3111 |
g_assert (handled); |
| 3112 |
g_free (sid); |
| 3113 |
handled = gst_pad_push_event (t->h->srcpad, gst_event_new_caps (pt->caps)); |
| 3114 |
g_assert (handled); |
| 3115 |
handled = gst_pad_push_event (t->h->srcpad, |
| 3116 |
gst_event_new_segment (&pt->segment)); |
| 3117 |
g_assert (handled); |
| 3118 |
|
| 3119 |
while (t->running) { |
| 3120 |
gst_harness_push (t->h, pt->func (t->h, pt->data)); |
| 3121 |
|
| 3122 |
count++; |
| 3123 |
g_usleep (t->sleep); |
| 3124 |
} |
| 3125 |
return GUINT_TO_POINTER (count); |
| 3126 |
} |
| 3127 |
|
| 3128 |
static gpointer |
| 3129 |
gst_harness_stress_event_func (GstHarnessThread * t) |
| 3130 |
{ |
| 3131 |
GstHarnessPushEventThread *pet = (GstHarnessPushEventThread *) t; |
| 3132 |
guint count = 0; |
| 3133 |
|
| 3134 |
while (t->running) { |
| 3135 |
gst_harness_push_event (t->h, pet->func (t->h, pet->data)); |
| 3136 |
|
| 3137 |
count++; |
| 3138 |
g_usleep (t->sleep); |
| 3139 |
} |
| 3140 |
return GUINT_TO_POINTER (count); |
| 3141 |
} |
| 3142 |
|
| 3143 |
static gpointer |
| 3144 |
gst_harness_stress_upstream_event_func (GstHarnessThread * t) |
| 3145 |
{ |
| 3146 |
GstHarnessPushEventThread *pet = (GstHarnessPushEventThread *) t; |
| 3147 |
guint count = 0; |
| 3148 |
|
| 3149 |
while (t->running) { |
| 3150 |
gst_harness_push_upstream_event (t->h, pet->func (t->h, pet->data)); |
| 3151 |
|
| 3152 |
count++; |
| 3153 |
g_usleep (t->sleep); |
| 3154 |
} |
| 3155 |
return GUINT_TO_POINTER (count); |
| 3156 |
} |
| 3157 |
|
| 3158 |
static gpointer |
| 3159 |
gst_harness_stress_property_func (GstHarnessThread * t) |
| 3160 |
{ |
| 3161 |
GstHarnessPropThread *pt = (GstHarnessPropThread *) t; |
| 3162 |
guint count = 0; |
| 3163 |
|
| 3164 |
while (t->running) { |
| 3165 |
GValue value = G_VALUE_INIT; |
| 3166 |
|
| 3167 |
g_object_set_property (G_OBJECT (t->h->element), pt->name, &pt->value); |
| 3168 |
|
| 3169 |
g_value_init (&value, G_VALUE_TYPE (&pt->value)); |
| 3170 |
g_object_get_property (G_OBJECT (t->h->element), pt->name, &value); |
| 3171 |
g_value_reset (&value); |
| 3172 |
|
| 3173 |
count++; |
| 3174 |
g_usleep (t->sleep); |
| 3175 |
} |
| 3176 |
return GUINT_TO_POINTER (count); |
| 3177 |
} |
| 3178 |
|
| 3179 |
static gpointer |
| 3180 |
gst_harness_stress_requestpad_func (GstHarnessThread * t) |
| 3181 |
{ |
| 3182 |
GstHarnessReqPadThread *rpt = (GstHarnessReqPadThread *) t; |
| 3183 |
guint count = 0; |
| 3184 |
|
| 3185 |
while (t->running) { |
| 3186 |
GstPad *reqpad; |
| 3187 |
|
| 3188 |
if (rpt->release) |
| 3189 |
gst_harness_requestpad_release_pads (rpt); |
| 3190 |
|
| 3191 |
g_thread_yield (); |
| 3192 |
|
| 3193 |
reqpad = gst_element_request_pad (t->h->element, |
| 3194 |
rpt->templ, rpt->name, rpt->caps); |
| 3195 |
|
| 3196 |
g_assert (reqpad != NULL); |
| 3197 |
|
| 3198 |
rpt->pads = g_slist_prepend (rpt->pads, reqpad); |
| 3199 |
|
| 3200 |
count++; |
| 3201 |
g_usleep (t->sleep); |
| 3202 |
} |
| 3203 |
return GUINT_TO_POINTER (count); |
| 3204 |
} |
| 3205 |
|
| 3206 |
/** |
| 3207 |
* gst_harness_stress_thread_stop: |
| 3208 |
* @t: a #GstHarnessThread |
| 3209 |
* |
| 3210 |
* Stop the running #GstHarnessThread |
| 3211 |
* |
| 3212 |
* MT safe. |
| 3213 |
* |
| 3214 |
* Since: 1.6 |
| 3215 |
*/ |
| 3216 |
guint |
| 3217 |
gst_harness_stress_thread_stop (GstHarnessThread * t) |
| 3218 |
{ |
| 3219 |
guint ret; |
| 3220 |
|
| 3221 |
g_return_val_if_fail (t != NULL, 0); |
| 3222 |
|
| 3223 |
ret = GST_HARNESS_THREAD_END (t); |
| 3224 |
g_ptr_array_remove (t->h->priv->stress, t); |
| 3225 |
return ret; |
| 3226 |
} |
| 3227 |
|
| 3228 |
/** |
| 3229 |
* gst_harness_stress_custom_start: (skip) |
| 3230 |
* @h: a #GstHarness |
| 3231 |
* @init: (nullable): a #GFunc that is called initially and only once |
| 3232 |
* @callback: a #GFunc that is called as often as possible |
| 3233 |
* @data: a #gpointer with custom data to pass to the @callback function |
| 3234 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3235 |
* each call to the @callback |
| 3236 |
* |
| 3237 |
* Start a custom stress-thread that will call your @callback for every |
| 3238 |
* iteration allowing you to do something nasty. |
| 3239 |
* |
| 3240 |
* MT safe. |
| 3241 |
* |
| 3242 |
* Returns: a #GstHarnessThread |
| 3243 |
* |
| 3244 |
* Since: 1.6 |
| 3245 |
*/ |
| 3246 |
GstHarnessThread * |
| 3247 |
gst_harness_stress_custom_start (GstHarness * h, |
| 3248 |
GFunc init, GFunc callback, gpointer data, gulong sleep) |
| 3249 |
{ |
| 3250 |
GstHarnessCustomThread *t = g_new0 (GstHarnessCustomThread, 1); |
| 3251 |
gst_harness_thread_init (&t->t, |
| 3252 |
(GDestroyNotify) gst_harness_custom_thread_free, h, sleep); |
| 3253 |
|
| 3254 |
t->init = init; |
| 3255 |
t->callback = callback; |
| 3256 |
t->data = data; |
| 3257 |
|
| 3258 |
GST_HARNESS_THREAD_START (custom, t); |
| 3259 |
return &t->t; |
| 3260 |
} |
| 3261 |
|
| 3262 |
/** |
| 3263 |
* gst_harness_stress_statechange_start_full: (skip) |
| 3264 |
* @h: a #GstHarness |
| 3265 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3266 |
* each state-change |
| 3267 |
* |
| 3268 |
* Change the state of your harnessed #GstElement from NULL to PLAYING and |
| 3269 |
* back again, only pausing for @sleep microseconds every time. |
| 3270 |
* |
| 3271 |
* MT safe. |
| 3272 |
* |
| 3273 |
* Returns: a #GstHarnessThread |
| 3274 |
* |
| 3275 |
* Since: 1.6 |
| 3276 |
*/ |
| 3277 |
GstHarnessThread * |
| 3278 |
gst_harness_stress_statechange_start_full (GstHarness * h, gulong sleep) |
| 3279 |
{ |
| 3280 |
GstHarnessThread *t = g_new0 (GstHarnessThread, 1); |
| 3281 |
gst_harness_thread_init (t, |
| 3282 |
(GDestroyNotify) gst_harness_thread_free, h, sleep); |
| 3283 |
GST_HARNESS_THREAD_START (statechange, t); |
| 3284 |
return t; |
| 3285 |
} |
| 3286 |
|
| 3287 |
static GstBuffer * |
| 3288 |
gst_harness_ref_buffer (GstHarness * h, gpointer data) |
| 3289 |
{ |
| 3290 |
(void) h; |
| 3291 |
return gst_buffer_ref (GST_BUFFER_CAST (data)); |
| 3292 |
} |
| 3293 |
|
| 3294 |
static GstEvent * |
| 3295 |
gst_harness_ref_event (GstHarness * h, gpointer data) |
| 3296 |
{ |
| 3297 |
(void) h; |
| 3298 |
return gst_event_ref (GST_EVENT_CAST (data)); |
| 3299 |
} |
| 3300 |
|
| 3301 |
/** |
| 3302 |
* gst_harness_stress_push_buffer_start_full: (skip) |
| 3303 |
* @h: a #GstHarness |
| 3304 |
* @caps: a #GstCaps for the #GstBuffer |
| 3305 |
* @segment: a #GstSegment |
| 3306 |
* @buf: a #GstBuffer to push |
| 3307 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3308 |
* each call to gst_pad_push |
| 3309 |
* |
| 3310 |
* Push a #GstBuffer in intervals of @sleep microseconds. |
| 3311 |
* |
| 3312 |
* MT safe. |
| 3313 |
* |
| 3314 |
* Returns: a #GstHarnessThread |
| 3315 |
* |
| 3316 |
* Since: 1.6 |
| 3317 |
*/ |
| 3318 |
GstHarnessThread * |
| 3319 |
gst_harness_stress_push_buffer_start_full (GstHarness * h, |
| 3320 |
GstCaps * caps, const GstSegment * segment, GstBuffer * buf, gulong sleep) |
| 3321 |
{ |
| 3322 |
return gst_harness_stress_push_buffer_with_cb_start_full (h, caps, segment, |
| 3323 |
gst_harness_ref_buffer, gst_buffer_ref (buf), |
| 3324 |
(GDestroyNotify) gst_buffer_unref, sleep); |
| 3325 |
} |
| 3326 |
|
| 3327 |
/** |
| 3328 |
* gst_harness_stress_push_buffer_with_cb_start_full: (skip) |
| 3329 |
* @h: a #GstHarness |
| 3330 |
* @caps: a #GstCaps for the #GstBuffer |
| 3331 |
* @segment: a #GstSegment |
| 3332 |
* @func: a #GstHarnessPrepareBufferFunc function called before every iteration |
| 3333 |
* to prepare / create a #GstBuffer for pushing |
| 3334 |
* @data: a #gpointer with data to the #GstHarnessPrepareBufferFunc function |
| 3335 |
* @notify: a #GDestroyNotify that is called when thread is stopped |
| 3336 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3337 |
* each call to gst_pad_push |
| 3338 |
* |
| 3339 |
* Push a #GstBuffer returned by @func in intervals of @sleep microseconds. |
| 3340 |
* |
| 3341 |
* MT safe. |
| 3342 |
* |
| 3343 |
* Returns: a #GstHarnessThread |
| 3344 |
* |
| 3345 |
* Since: 1.6 |
| 3346 |
*/ |
| 3347 |
GstHarnessThread * |
| 3348 |
gst_harness_stress_push_buffer_with_cb_start_full (GstHarness * h, |
| 3349 |
GstCaps * caps, const GstSegment * segment, |
| 3350 |
GstHarnessPrepareBufferFunc func, gpointer data, GDestroyNotify notify, |
| 3351 |
gulong sleep) |
| 3352 |
{ |
| 3353 |
GstHarnessPushBufferThread *t = g_new0 (GstHarnessPushBufferThread, 1); |
| 3354 |
gst_harness_thread_init (&t->t, |
| 3355 |
(GDestroyNotify) gst_harness_push_buffer_thread_free, h, sleep); |
| 3356 |
|
| 3357 |
gst_caps_replace (&t->caps, caps); |
| 3358 |
t->segment = *segment; |
| 3359 |
t->func = func; |
| 3360 |
t->data = data; |
| 3361 |
t->notify = notify; |
| 3362 |
|
| 3363 |
GST_HARNESS_THREAD_START (buffer, t); |
| 3364 |
return &t->t; |
| 3365 |
} |
| 3366 |
|
| 3367 |
/** |
| 3368 |
* gst_harness_stress_push_event_start_full: (skip) |
| 3369 |
* @h: a #GstHarness |
| 3370 |
* @event: a #GstEvent to push |
| 3371 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3372 |
* each gst_event_push with @event |
| 3373 |
* |
| 3374 |
* Push the @event onto the harnessed #GstElement sinkpad in intervals of |
| 3375 |
* @sleep microseconds |
| 3376 |
* |
| 3377 |
* MT safe. |
| 3378 |
* |
| 3379 |
* Returns: a #GstHarnessThread |
| 3380 |
* |
| 3381 |
* Since: 1.6 |
| 3382 |
*/ |
| 3383 |
GstHarnessThread * |
| 3384 |
gst_harness_stress_push_event_start_full (GstHarness * h, |
| 3385 |
GstEvent * event, gulong sleep) |
| 3386 |
{ |
| 3387 |
return gst_harness_stress_push_event_with_cb_start_full (h, |
| 3388 |
gst_harness_ref_event, gst_event_ref (event), |
| 3389 |
(GDestroyNotify) gst_event_unref, sleep); |
| 3390 |
} |
| 3391 |
|
| 3392 |
/** |
| 3393 |
* gst_harness_stress_push_event_with_cb_start_full: (skip) |
| 3394 |
* @h: a #GstHarness |
| 3395 |
* @func: a #GstHarnessPrepareEventFunc function called before every iteration |
| 3396 |
* to prepare / create a #GstEvent for pushing |
| 3397 |
* @data: a #gpointer with data to the #GstHarnessPrepareEventFunc function |
| 3398 |
* @notify: a #GDestroyNotify that is called when thread is stopped |
| 3399 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3400 |
* each call to gst_pad_push |
| 3401 |
* |
| 3402 |
* Push a #GstEvent returned by @func onto the harnessed #GstElement sinkpad |
| 3403 |
* in intervals of @sleep microseconds. |
| 3404 |
* |
| 3405 |
* MT safe. |
| 3406 |
* |
| 3407 |
* Returns: a #GstHarnessThread |
| 3408 |
* |
| 3409 |
* Since: 1.8 |
| 3410 |
*/ |
| 3411 |
GstHarnessThread * |
| 3412 |
gst_harness_stress_push_event_with_cb_start_full (GstHarness * h, |
| 3413 |
GstHarnessPrepareEventFunc func, gpointer data, GDestroyNotify notify, |
| 3414 |
gulong sleep) |
| 3415 |
{ |
| 3416 |
GstHarnessPushEventThread *t = g_new0 (GstHarnessPushEventThread, 1); |
| 3417 |
gst_harness_thread_init (&t->t, |
| 3418 |
(GDestroyNotify) gst_harness_push_event_thread_free, h, sleep); |
| 3419 |
|
| 3420 |
t->func = func; |
| 3421 |
t->data = data; |
| 3422 |
t->notify = notify; |
| 3423 |
|
| 3424 |
GST_HARNESS_THREAD_START (event, t); |
| 3425 |
return &t->t; |
| 3426 |
} |
| 3427 |
|
| 3428 |
/** |
| 3429 |
* gst_harness_stress_push_upstream_event_start_full: (skip) |
| 3430 |
* @h: a #GstHarness |
| 3431 |
* @event: a #GstEvent to push |
| 3432 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3433 |
* each gst_event_push with @event |
| 3434 |
* |
| 3435 |
* Push the @event onto the harnessed #GstElement srcpad in intervals of |
| 3436 |
* @sleep microseconds. |
| 3437 |
* |
| 3438 |
* MT safe. |
| 3439 |
* |
| 3440 |
* Returns: a #GstHarnessThread |
| 3441 |
* |
| 3442 |
* Since: 1.6 |
| 3443 |
*/ |
| 3444 |
GstHarnessThread * |
| 3445 |
gst_harness_stress_push_upstream_event_start_full (GstHarness * h, |
| 3446 |
GstEvent * event, gulong sleep) |
| 3447 |
{ |
| 3448 |
return gst_harness_stress_push_upstream_event_with_cb_start_full (h, |
| 3449 |
gst_harness_ref_event, gst_event_ref (event), |
| 3450 |
(GDestroyNotify) gst_event_unref, sleep); |
| 3451 |
} |
| 3452 |
|
| 3453 |
/** |
| 3454 |
* gst_harness_stress_push_upstream_event_with_cb_start_full: (skip) |
| 3455 |
* @h: a #GstHarness |
| 3456 |
* @func: a #GstHarnessPrepareEventFunc function called before every iteration |
| 3457 |
* to prepare / create a #GstEvent for pushing |
| 3458 |
* @data: a #gpointer with data to the #GstHarnessPrepareEventFunc function |
| 3459 |
* @notify: a #GDestroyNotify that is called when thread is stopped |
| 3460 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3461 |
* each call to gst_pad_push |
| 3462 |
* |
| 3463 |
* Push a #GstEvent returned by @func onto the harnessed #GstElement srcpad |
| 3464 |
* in intervals of @sleep microseconds. |
| 3465 |
* |
| 3466 |
* MT safe. |
| 3467 |
* |
| 3468 |
* Returns: a #GstHarnessThread |
| 3469 |
* |
| 3470 |
* Since: 1.8 |
| 3471 |
*/ |
| 3472 |
GstHarnessThread * |
| 3473 |
gst_harness_stress_push_upstream_event_with_cb_start_full (GstHarness * h, |
| 3474 |
GstHarnessPrepareEventFunc func, gpointer data, GDestroyNotify notify, |
| 3475 |
gulong sleep) |
| 3476 |
{ |
| 3477 |
GstHarnessPushEventThread *t = g_new0 (GstHarnessPushEventThread, 1); |
| 3478 |
gst_harness_thread_init (&t->t, |
| 3479 |
(GDestroyNotify) gst_harness_push_event_thread_free, h, sleep); |
| 3480 |
|
| 3481 |
t->func = func; |
| 3482 |
t->data = data; |
| 3483 |
t->notify = notify; |
| 3484 |
|
| 3485 |
GST_HARNESS_THREAD_START (upstream_event, t); |
| 3486 |
return &t->t; |
| 3487 |
} |
| 3488 |
|
| 3489 |
/** |
| 3490 |
* gst_harness_stress_property_start_full: (skip) |
| 3491 |
* @h: a #GstHarness |
| 3492 |
* @name: a #gchar specifying a property name |
| 3493 |
* @value: a #GValue to set the property to |
| 3494 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3495 |
* each g_object_set with @name and @value |
| 3496 |
* |
| 3497 |
* Call g_object_set with @name and @value in intervals of @sleep microseconds |
| 3498 |
* |
| 3499 |
* MT safe. |
| 3500 |
* |
| 3501 |
* Returns: a #GstHarnessThread |
| 3502 |
* |
| 3503 |
* Since: 1.6 |
| 3504 |
*/ |
| 3505 |
GstHarnessThread * |
| 3506 |
gst_harness_stress_property_start_full (GstHarness * h, |
| 3507 |
const gchar * name, const GValue * value, gulong sleep) |
| 3508 |
{ |
| 3509 |
GstHarnessPropThread *t = g_new0 (GstHarnessPropThread, 1); |
| 3510 |
gst_harness_thread_init (&t->t, |
| 3511 |
(GDestroyNotify) gst_harness_property_thread_free, h, sleep); |
| 3512 |
|
| 3513 |
t->name = g_strdup (name); |
| 3514 |
g_value_init (&t->value, G_VALUE_TYPE (value)); |
| 3515 |
g_value_copy (value, &t->value); |
| 3516 |
|
| 3517 |
GST_HARNESS_THREAD_START (property, t); |
| 3518 |
return &t->t; |
| 3519 |
} |
| 3520 |
|
| 3521 |
/** |
| 3522 |
* gst_harness_stress_requestpad_start_full: (skip) |
| 3523 |
* @h: a #GstHarness |
| 3524 |
* @templ: a #GstPadTemplate |
| 3525 |
* @name: a #gchar |
| 3526 |
* @caps: a #GstCaps |
| 3527 |
* @release: a #gboolean |
| 3528 |
* @sleep: a #gulong specifying how long to sleep in (microseconds) for |
| 3529 |
* each gst_element_request_pad |
| 3530 |
* |
| 3531 |
* Call gst_element_request_pad in intervals of @sleep microseconds |
| 3532 |
* |
| 3533 |
* MT safe. |
| 3534 |
* |
| 3535 |
* Returns: a #GstHarnessThread |
| 3536 |
* |
| 3537 |
* Since: 1.6 |
| 3538 |
*/ |
| 3539 |
GstHarnessThread * |
| 3540 |
gst_harness_stress_requestpad_start_full (GstHarness * h, |
| 3541 |
GstPadTemplate * templ, const gchar * name, GstCaps * caps, |
| 3542 |
gboolean release, gulong sleep) |
| 3543 |
{ |
| 3544 |
GstHarnessReqPadThread *t = g_new0 (GstHarnessReqPadThread, 1); |
| 3545 |
gst_harness_thread_init (&t->t, |
| 3546 |
(GDestroyNotify) gst_harness_requestpad_thread_free, h, sleep); |
| 3547 |
|
| 3548 |
t->templ = gst_object_ref (templ); |
| 3549 |
t->name = g_strdup (name); |
| 3550 |
gst_caps_replace (&t->caps, caps); |
| 3551 |
t->release = release; |
| 3552 |
|
| 3553 |
GST_HARNESS_THREAD_START (requestpad, t); |
| 3554 |
return &t->t; |
| 3555 |
} |