~ubuntu-branches/ubuntu/trusty/gstreamer1.0/trusty

« back to all changes in this revision

Viewing changes to tests/check/gst/gstbin.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2012-08-08 18:12:33 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120808181233-riejwxprfsxh1njl
Tags: 0.11.93-1
* New upstream release:
  + debian/libgstreamer.symbols:
    - Update symbols file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 */
22
22
 
23
23
#include <gst/check/gstcheck.h>
 
24
#include <gst/base/gstbasesrc.h>
24
25
 
25
26
static void
26
27
pop_async_done (GstBus * bus)
56
57
  GST_DEBUG ("popped %d messages", count);
57
58
}
58
59
 
 
60
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
 
61
    GST_PAD_SRC,
 
62
    GST_PAD_ALWAYS,
 
63
    GST_STATIC_CAPS_ANY);
 
64
 
 
65
static gpointer
 
66
push_one_eos (GstPad * pad)
 
67
{
 
68
  GST_DEBUG_OBJECT (pad, "Pushing EOS event");
 
69
  gst_pad_push_event (pad, gst_event_new_eos ());
 
70
 
 
71
  return NULL;
 
72
}
 
73
 
 
74
static gpointer
 
75
push_one_stream_start (GstPad * pad)
 
76
{
 
77
  GST_DEBUG_OBJECT (pad, "Pushing STREAM_START event");
 
78
  gst_pad_push_event (pad, gst_event_new_stream_start ("test"));
 
79
 
 
80
  return NULL;
 
81
}
 
82
 
59
83
GST_START_TEST (test_interface)
60
84
{
61
85
  GstBin *bin, *bin2;
126
150
 
127
151
GST_END_TEST;
128
152
 
 
153
GST_START_TEST (test_eos)
 
154
{
 
155
  GstBus *bus;
 
156
  GstElement *pipeline, *sink1, *sink2;
 
157
  GstMessage *message;
 
158
  GstPad *pad1, *pad2;
 
159
  GThread *thread1, *thread2;
 
160
 
 
161
  pipeline = gst_pipeline_new ("test_eos");
 
162
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
 
163
 
 
164
  sink1 = gst_element_factory_make ("fakesink", "sink1");
 
165
  sink2 = gst_element_factory_make ("fakesink", "sink2");
 
166
 
 
167
  gst_bin_add_many (GST_BIN (pipeline), sink1, sink2, NULL);
 
168
 
 
169
  pad1 = gst_check_setup_src_pad_by_name (sink1, &srctemplate, "sink");
 
170
  pad2 = gst_check_setup_src_pad_by_name (sink2, &srctemplate, "sink");
 
171
 
 
172
  gst_pad_set_active (pad1, TRUE);
 
173
  gst_pad_set_active (pad2, TRUE);
 
174
 
 
175
  fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
 
176
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
 
177
 
 
178
  /* Send one EOS to sink1 */
 
179
  thread1 = g_thread_new ("thread1", (GThreadFunc) push_one_eos, pad1);
 
180
 
 
181
  /* Make sure the EOS message is not sent */
 
182
  message =
 
183
      gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 2 * GST_SECOND);
 
184
  fail_if (message != NULL);
 
185
 
 
186
  /* Send one EOS to sink2 */
 
187
  thread2 = g_thread_new ("thread2", (GThreadFunc) push_one_eos, pad2);
 
188
 
 
189
  /* Make sure the EOS message is sent then */
 
190
  message = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, -1);
 
191
  fail_if (message == NULL);
 
192
  fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
 
193
  gst_message_unref (message);
 
194
 
 
195
  /* Cleanup */
 
196
  g_thread_join (thread1);
 
197
  g_thread_join (thread2);
 
198
 
 
199
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
 
200
  gst_pad_set_active (pad1, FALSE);
 
201
  gst_pad_set_active (pad2, FALSE);
 
202
  gst_check_teardown_src_pad (sink1);
 
203
  gst_check_teardown_src_pad (sink2);
 
204
  gst_object_unref (pipeline);
 
205
}
 
206
 
 
207
GST_END_TEST;
 
208
 
 
209
GST_START_TEST (test_stream_start)
 
210
{
 
211
  GstBus *bus;
 
212
  GstElement *pipeline, *sink1, *sink2;
 
213
  GstMessage *message;
 
214
  GstPad *pad1, *pad2;
 
215
  GThread *thread1, *thread2;
 
216
 
 
217
  pipeline = gst_pipeline_new ("test_stream_start");
 
218
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
 
219
 
 
220
  sink1 = gst_element_factory_make ("fakesink", "sink1");
 
221
  sink2 = gst_element_factory_make ("fakesink", "sink2");
 
222
 
 
223
  gst_bin_add_many (GST_BIN (pipeline), sink1, sink2, NULL);
 
224
 
 
225
  pad1 = gst_check_setup_src_pad_by_name (sink1, &srctemplate, "sink");
 
226
  pad2 = gst_check_setup_src_pad_by_name (sink2, &srctemplate, "sink");
 
227
 
 
228
  gst_pad_set_active (pad1, TRUE);
 
229
  gst_pad_set_active (pad2, TRUE);
 
230
 
 
231
  fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
 
232
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
 
233
 
 
234
  /* Send one STREAM_START to sink1 */
 
235
  thread1 = g_thread_new ("thread1", (GThreadFunc) push_one_stream_start, pad1);
 
236
 
 
237
  /* Make sure the STREAM_START message is not sent */
 
238
  message =
 
239
      gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_STREAM_START,
 
240
      2 * GST_SECOND);
 
241
  fail_if (message != NULL);
 
242
 
 
243
  /* Send one STREAM_START to sink2 */
 
244
  thread2 = g_thread_new ("thread2", (GThreadFunc) push_one_stream_start, pad2);
 
245
 
 
246
  /* Make sure the STREAM_START message is sent then */
 
247
  message =
 
248
      gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_STREAM_START, -1);
 
249
  fail_if (message == NULL);
 
250
  fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START);
 
251
  gst_message_unref (message);
 
252
 
 
253
  /* Cleanup */
 
254
  g_thread_join (thread1);
 
255
  g_thread_join (thread2);
 
256
 
 
257
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
 
258
  gst_pad_set_active (pad1, FALSE);
 
259
  gst_pad_set_active (pad2, FALSE);
 
260
  gst_check_teardown_src_pad (sink1);
 
261
  gst_check_teardown_src_pad (sink2);
 
262
  gst_object_unref (pipeline);
 
263
}
 
264
 
 
265
GST_END_TEST;
 
266
 
129
267
GST_START_TEST (test_message_state_changed)
130
268
{
131
269
  GstBin *bin;
281
419
  ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
282
420
  ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
283
421
 
284
 
  /* change state to PAUSED, spawning three messages */
 
422
  /* change state to PAUSED, spawning four messages */
 
423
  /* STATE_CHANGED (NULL => READY)
 
424
   * STREAM_START
 
425
   * ASYNC_DONE
 
426
   * STATE_CHANGED (READY => PAUSED)
 
427
   */
285
428
  GST_DEBUG ("setting pipeline to PAUSED");
286
429
  ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
287
430
  fail_unless (ret == GST_STATE_CHANGE_ASYNC);
294
437
 
295
438
  /* wait for async thread to settle down */
296
439
  GST_DEBUG ("waiting for refcount");
297
 
  while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 3)
 
440
  while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 4)
298
441
    THREAD_SWITCH ();
299
 
  GST_DEBUG ("refcount <= 3 now");
 
442
  GST_DEBUG ("refcount <= 4 now");
300
443
 
301
444
  /* each object is referenced by a message;
302
445
   * base_src is blocked in the push and has an extra refcount.
307
450
  /* refcount can be 4 if the bin is still processing the async_done message of
308
451
   * the sink. */
309
452
  ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 2, 3);
310
 
  /* 2 or 3 is valid, because the pipeline might still be posting 
 
453
  /* 3 or 4 is valid, because the pipeline might still be posting 
311
454
   * its state_change message */
312
 
  ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "pipeline", 2, 3);
 
455
  ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "pipeline", 3, 4);
313
456
 
314
457
  pop_messages (bus, 3);
315
458
  pop_async_done (bus);
989
1132
 
990
1133
  /* use the sync signal handler to link elements while the pipeline is still
991
1134
   * doing the state change */
992
 
  gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, pipeline);
 
1135
  gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, pipeline, NULL);
993
1136
  g_object_connect (bus, "signal::sync-message::state-changed",
994
1137
      G_CALLBACK (test_link_structure_change_state_changed_sync_cb), pipeline,
995
1138
      NULL);
1061
1204
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1062
1205
  fail_unless (bus != NULL, "Could not get bus");
1063
1206
 
1064
 
  gst_bus_set_sync_handler (bus, sync_handler_remove_sink, pipeline);
 
1207
  gst_bus_set_sync_handler (bus, sync_handler_remove_sink, pipeline, NULL);
1065
1208
 
1066
1209
  ret = gst_element_set_state (pipeline, GST_STATE_READY);
1067
1210
  fail_unless (ret == GST_STATE_CHANGE_SUCCESS,
1265
1408
  fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "downward state change failed");
1266
1409
 
1267
1410
  gst_object_unref (pipeline);
1268
 
}
1269
 
 
1270
 
GST_END_TEST;
 
1411
  gst_object_unref (bus);
 
1412
}
 
1413
 
 
1414
GST_END_TEST;
 
1415
 
 
1416
GST_START_TEST (test_duration_is_max)
 
1417
{
 
1418
  GstElement *bin, *src[3], *sink[3];
 
1419
  GstStateChangeReturn state_res;
 
1420
  GstFormat format = GST_FORMAT_BYTES;
 
1421
  gboolean res;
 
1422
  gint64 duration;
 
1423
 
 
1424
  GST_INFO ("preparing test");
 
1425
 
 
1426
  /* build pipeline */
 
1427
  bin = gst_pipeline_new ("pipeline");
 
1428
 
 
1429
  /* 3 sources, an adder and a fakesink */
 
1430
  src[0] = gst_element_factory_make ("fakesrc", NULL);
 
1431
  src[1] = gst_element_factory_make ("fakesrc", NULL);
 
1432
  src[2] = gst_element_factory_make ("fakesrc", NULL);
 
1433
  sink[0] = gst_element_factory_make ("fakesink", NULL);
 
1434
  sink[1] = gst_element_factory_make ("fakesink", NULL);
 
1435
  sink[2] = gst_element_factory_make ("fakesink", NULL);
 
1436
  gst_bin_add_many (GST_BIN (bin), src[0], src[1], src[2], sink[0], sink[1],
 
1437
      sink[2], NULL);
 
1438
 
 
1439
  gst_element_link (src[0], sink[0]);
 
1440
  gst_element_link (src[1], sink[1]);
 
1441
  gst_element_link (src[2], sink[2]);
 
1442
 
 
1443
  /* irks, duration is reset on basesrc */
 
1444
  state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
 
1445
  fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
 
1446
 
 
1447
  /* set durations on src */
 
1448
  GST_BASE_SRC (src[0])->segment.duration = 1000;
 
1449
  GST_BASE_SRC (src[1])->segment.duration = 3000;
 
1450
  GST_BASE_SRC (src[2])->segment.duration = 2000;
 
1451
 
 
1452
  /* set to playing */
 
1453
  state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
 
1454
  fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
 
1455
 
 
1456
  /* wait for completion */
 
1457
  state_res =
 
1458
      gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
 
1459
      GST_CLOCK_TIME_NONE);
 
1460
  fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
 
1461
 
 
1462
  res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
 
1463
  fail_unless (res, NULL);
 
1464
 
 
1465
  ck_assert_int_eq (duration, 3000);
 
1466
 
 
1467
  gst_element_set_state (bin, GST_STATE_NULL);
 
1468
  gst_object_unref (bin);
 
1469
}
 
1470
 
 
1471
GST_END_TEST;
 
1472
 
 
1473
GST_START_TEST (test_duration_unknown_overrides)
 
1474
{
 
1475
  GstElement *bin, *src[3], *sink[3];
 
1476
  GstStateChangeReturn state_res;
 
1477
  GstFormat format = GST_FORMAT_BYTES;
 
1478
  gboolean res;
 
1479
  gint64 duration;
 
1480
 
 
1481
  GST_INFO ("preparing test");
 
1482
 
 
1483
  /* build pipeline */
 
1484
  bin = gst_pipeline_new ("pipeline");
 
1485
 
 
1486
  /* 3 sources, an adder and a fakesink */
 
1487
  src[0] = gst_element_factory_make ("fakesrc", NULL);
 
1488
  src[1] = gst_element_factory_make ("fakesrc", NULL);
 
1489
  src[2] = gst_element_factory_make ("fakesrc", NULL);
 
1490
  sink[0] = gst_element_factory_make ("fakesink", NULL);
 
1491
  sink[1] = gst_element_factory_make ("fakesink", NULL);
 
1492
  sink[2] = gst_element_factory_make ("fakesink", NULL);
 
1493
  gst_bin_add_many (GST_BIN (bin), src[0], src[1], src[2], sink[0], sink[1],
 
1494
      sink[2], NULL);
 
1495
 
 
1496
  gst_element_link (src[0], sink[0]);
 
1497
  gst_element_link (src[1], sink[1]);
 
1498
  gst_element_link (src[2], sink[2]);
 
1499
 
 
1500
  /* irks, duration is reset on basesrc */
 
1501
  state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
 
1502
  fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
 
1503
 
 
1504
  /* set durations on src */
 
1505
  GST_BASE_SRC (src[0])->segment.duration = GST_CLOCK_TIME_NONE;
 
1506
  GST_BASE_SRC (src[1])->segment.duration = 3000;
 
1507
  GST_BASE_SRC (src[2])->segment.duration = 2000;
 
1508
 
 
1509
  /* set to playing */
 
1510
  state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
 
1511
  fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
 
1512
 
 
1513
  /* wait for completion */
 
1514
  state_res =
 
1515
      gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
 
1516
      GST_CLOCK_TIME_NONE);
 
1517
  fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
 
1518
 
 
1519
  res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
 
1520
  fail_unless (res, NULL);
 
1521
 
 
1522
  ck_assert_int_eq (duration, GST_CLOCK_TIME_NONE);
 
1523
 
 
1524
  gst_element_set_state (bin, GST_STATE_NULL);
 
1525
  gst_object_unref (bin);
 
1526
}
 
1527
 
 
1528
GST_END_TEST;
 
1529
 
 
1530
 
1271
1531
 
1272
1532
static Suite *
1273
1533
gst_bin_suite (void)
1279
1539
 
1280
1540
  suite_add_tcase (s, tc_chain);
1281
1541
  tcase_add_test (tc_chain, test_interface);
 
1542
  tcase_add_test (tc_chain, test_eos);
 
1543
  tcase_add_test (tc_chain, test_stream_start);
1282
1544
  tcase_add_test (tc_chain, test_children_state_change_order_flagged_sink);
1283
1545
  tcase_add_test (tc_chain, test_children_state_change_order_semi_sink);
1284
1546
  tcase_add_test (tc_chain, test_children_state_change_order_two_sink);
1294
1556
  tcase_add_test (tc_chain, test_state_failure_remove);
1295
1557
  tcase_add_test (tc_chain, test_state_failure_unref);
1296
1558
  tcase_add_test (tc_chain, test_state_change_skip);
 
1559
  tcase_add_test (tc_chain, test_duration_is_max);
 
1560
  tcase_add_test (tc_chain, test_duration_unknown_overrides);
1297
1561
 
1298
1562
  /* fails on OSX build bot for some reason, and is a bit silly anyway */
1299
1563
  if (0)