Debian Codegraph @

tests/check/nle/tempochange.c

raw
1 /* GStreamer Editing Services
2 * Copyright (C) 2016 Sjors Gielen <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "common.h"
21 #include "plugins/nle/nleobject.h"
22
23 static void late_ges_init (void);
24
25 typedef struct _PadEventData
26 {
27 gchar *name;
28 guint expect_num_segments;
29 guint num_segments;
30 GArray *expect_segment_time;
31 GArray *expect_segment_num_seeks;
32 guint expect_num_seeks;
33 guint num_seeks;
34 GArray *expect_seek_start;
35 GArray *expect_seek_stop;
36 GArray *expect_seek_num_segments;
37 guint num_eos;
38 guint expect_num_eos;
39 } PadEventData;
40
41 #define _SEGMENT_FORMAT "flags: %i, rate: %g, applied_rate: %g, format: %i" \
42 ", base: %" G_GUINT64_FORMAT ", offset: %" G_GUINT64_FORMAT ", start: %" \
43 G_GUINT64_FORMAT ", stop: %" G_GUINT64_FORMAT ", time: %" G_GUINT64_FORMAT \
44 ", position: %" G_GUINT64_FORMAT ", duration: %" G_GUINT64_FORMAT
45
46 #define _SEGMENT_ARGS(seg) (seg).flags, (seg).rate, (seg).applied_rate, \
47 (seg).format, (seg).base, (seg).offset, (seg).start, (seg).stop, \
48 (seg).time, (seg).position, (seg).duration
49
50 static GstPadProbeReturn
51 _test_pad_events (GstPad * pad, GstPadProbeInfo * info, PadEventData * data)
52 {
53 guint num;
54 GstEvent *event = info->data;
55 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
56 guint expect_num_seeks;
57 const GstSegment *segment;
58 /* copy the segment start, stop, position and duration since these are
59 * not yet translated by nleghostpad. Also, don't care about flags. */
60 GstSegment expect_segment;
61
62 gst_event_parse_segment (event, &segment);
63 GST_DEBUG ("%s segment: " _SEGMENT_FORMAT, data->name,
64 _SEGMENT_ARGS (*segment));
65
66 if (!GST_CLOCK_TIME_IS_VALID (segment->stop)) {
67 GST_DEBUG ("%s: ignoring pre-roll segment", data->name);
68 return GST_PAD_PROBE_OK;
69 }
70
71 data->num_segments++;
72 num = data->num_segments;
73
74 fail_unless (num <= data->expect_num_segments, "%s received %u "
75 "segments, more than the expected %u segments", data->name, num,
76 data->expect_num_segments);
77
78 expect_num_seeks =
79 g_array_index (data->expect_segment_num_seeks, gint, num - 1);
80
81 fail_unless (data->num_seeks == expect_num_seeks, "%s has received %u "
82 "segments, compared to %u seeks, but expected %u seeks",
83 data->name, num, data->num_seeks, expect_num_seeks);
84
85 /* copy the segment start, stop, position, duration, offset, base
86 * since these are not yet translated by nleghostpad. */
87 gst_segment_copy_into (segment, &expect_segment);
88 expect_segment.rate = 1.0;
89 expect_segment.applied_rate = 1.0;
90 expect_segment.format = GST_FORMAT_TIME;
91 expect_segment.time = g_array_index (data->expect_segment_time,
92 GstClockTime, num - 1);
93
94 fail_unless (gst_segment_is_equal (segment, &expect_segment),
95 "%s %uth segment is not equal to the expected. Received:\n"
96 _SEGMENT_FORMAT "\nExpected\n" _SEGMENT_FORMAT, data->name,
97 num - 1, _SEGMENT_ARGS (*segment), _SEGMENT_ARGS (expect_segment));
98
99 } else if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
100 gdouble rate;
101 GstFormat format;
102 GstClockTime expect;
103 gint64 start, stop;
104 GstSeekType start_type, stop_type;
105 guint expect_num_segments;
106
107 gst_event_parse_seek (event, &rate, &format, NULL, &start_type, &start,
108 &stop_type, &stop);
109
110 GST_DEBUG ("%s seek: rate: %g, start: %" G_GINT64_FORMAT ", stop: %"
111 G_GINT64_FORMAT, data->name, rate, start, stop);
112
113 data->num_seeks++;
114 num = data->num_seeks;
115
116 fail_unless (num <= data->expect_num_seeks, "%s received %u "
117 "seeks, more than the expected %u seeks", data->name, num,
118 data->expect_num_seeks);
119
120 expect_num_segments =
121 g_array_index (data->expect_seek_num_segments, gint, num - 1);
122
123 fail_unless (data->num_segments == expect_num_segments, "%s has "
124 "received %u seeks, compared to %u segments, but expected %u "
125 "segments", data->name, num, data->num_segments, expect_num_segments);
126
127 fail_unless (rate == 1.0, "%s %uth seek has a rate of %g rather than 1.0",
128 data->name, num - 1, rate);
129 fail_unless (format == GST_FORMAT_TIME, "%s %uth seek has a format of %i "
130 " than a time format", data->name, num - 1, format);
131
132 /* expect seek-set or seek-none */
133 fail_if (start_type == GST_SEEK_TYPE_END, "%s %uth seek-start is "
134 "seek-end", data->name, num - 1);
135 fail_if (stop_type == GST_SEEK_TYPE_END, "%s %uth seek-stop is "
136 "seek-end", data->name, num - 1);
137
138 expect = g_array_index (data->expect_seek_start, GstClockTime, num - 1);
139 fail_unless (start == expect, "%s %uth seek start is %" GST_TIME_FORMAT
140 ", rather than the expected %" GST_TIME_FORMAT, data->name, num - 1,
141 GST_TIME_ARGS (start), GST_TIME_ARGS (expect));
142
143 expect = g_array_index (data->expect_seek_stop, GstClockTime, num - 1);
144 fail_unless (stop == expect, "%s %uth seek stop is %" GST_TIME_FORMAT
145 ", rather than the expected %" GST_TIME_FORMAT, data->name, num - 1,
146 GST_TIME_ARGS (stop), GST_TIME_ARGS (expect));
147
148 } else if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
149 data->num_eos++;
150 fail_unless (data->num_eos <= data->expect_num_eos, "%s received %u "
151 "EOS, more than the expected %u EOS", data->name, data->num_eos,
152 data->expect_num_seeks);
153 }
154
155 return GST_PAD_PROBE_OK;
156 }
157
158 static void
159 _pad_event_data_check_received (PadEventData * data)
160 {
161 fail_unless (data->num_eos == data->expect_num_eos, "%s received %u "
162 "EOS, rather than %u", data->num_eos, data->expect_num_eos);
163 fail_unless (data->num_segments == data->expect_num_segments,
164 "%s received %u segments, rather than %u", data->name,
165 data->num_segments, data->expect_num_segments);
166 fail_unless (data->num_seeks == data->expect_num_seeks,
167 "%s received %u seeks, rather than %u", data->name, data->num_seeks,
168 data->expect_num_seeks);
169 }
170
171 static void
172 _pad_event_data_free (PadEventData * data)
173 {
174 g_free (data->name);
175 g_array_unref (data->expect_segment_time);
176 g_array_unref (data->expect_seek_start);
177 g_array_unref (data->expect_seek_stop);
178 g_array_unref (data->expect_segment_num_seeks);
179 g_array_unref (data->expect_seek_num_segments);
180 g_free (data);
181 }
182
183 static PadEventData *
184 _pad_event_data_new (GstElement * element, const gchar * pad_name,
185 const gchar * suffix)
186 {
187 GstPad *pad;
188 PadEventData *data = g_new0 (PadEventData, 1);
189 data->expect_segment_time = g_array_new (FALSE, FALSE, sizeof (GstClockTime));
190 data->expect_seek_start = g_array_new (FALSE, FALSE, sizeof (GstClockTime));
191 data->expect_seek_stop = g_array_new (FALSE, FALSE, sizeof (GstClockTime));
192 data->expect_seek_num_segments = g_array_new (FALSE, FALSE, sizeof (guint));
193 data->expect_segment_num_seeks = g_array_new (FALSE, FALSE, sizeof (guint));
194 data->name = g_strdup_printf ("%s:%s(%s):%s", G_OBJECT_TYPE_NAME (element),
195 GST_ELEMENT_NAME (element), pad_name, suffix);
196
197 pad = gst_element_get_static_pad (element, pad_name);
198 fail_unless (pad, "%s not found", data->name);
199 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
200 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM, (GstPadProbeCallback) _test_pad_events,
201 data, (GDestroyNotify) _pad_event_data_free);
202 gst_object_unref (pad);
203
204 return data;
205 }
206
207 static void
208 _pad_event_data_add_expect_segment (PadEventData * data, GstClockTime time)
209 {
210 data->expect_num_segments++;
211 g_array_append_val (data->expect_segment_time, time);
212 g_array_append_val (data->expect_segment_num_seeks, data->expect_num_seeks);
213 }
214
215 static void
216 _pad_event_data_add_expect_seek (PadEventData * data, GstClockTime start,
217 GstClockTime stop)
218 {
219 data->expect_num_seeks++;
220 g_array_append_val (data->expect_seek_start, start);
221 g_array_append_val (data->expect_seek_stop, stop);
222 g_array_append_val (data->expect_seek_num_segments,
223 data->expect_num_segments);
224 }
225
226 static void
227 _pad_event_data_add_expect_seek_then_segment (PadEventData * data,
228 GstClockTime start, GstClockTime stop)
229 {
230 _pad_event_data_add_expect_seek (data, start, stop);
231 _pad_event_data_add_expect_segment (data, start);
232 }
233
234 #define _EXPECT_SEEK_SEGMENT(data, start, stop) \
235 _pad_event_data_add_expect_seek_then_segment (data, start, stop)
236
237 static GstElement *
238 _get_source (GstElement * nle_source)
239 {
240 GList *tmp;
241 GstElement *bin, *src = NULL;
242
243 fail_unless (g_list_length (GST_BIN_CHILDREN (nle_source)), 1);
244 bin = GST_BIN_CHILDREN (nle_source)->data;
245 fail_unless (GST_IS_BIN (bin));
246
247 for (tmp = GST_BIN_CHILDREN (bin); src == NULL && tmp; tmp = tmp->next) {
248 if (g_strrstr (GST_ELEMENT_NAME (tmp->data), "audiotestsrc"))
249 src = tmp->data;
250 }
251 fail_unless (src);
252 return src;
253 }
254
255 enum
256 {
257 NLE_PREV_SRC,
258 NLE_POST_SRC,
259 NLE_SOURCE_SRC,
260 NLE_OPER_SRC,
261 NLE_OPER_SINK,
262 NLE_IDENTITY_SRC,
263 PREV_SRC,
264 POST_SRC,
265 SOURCE_SRC,
266 PITCH_SRC,
267 PITCH_SINK,
268 IDENTITY_SRC,
269 SINK_SINK,
270 NUM_DATA
271 };
272
273 static PadEventData **
274 _setup_test (GstElement * pipeline, gdouble rate)
275 {
276 GstElement *sink, *pitch, *src, *prev, *post, *identity;
277 GstElement *comp, *nle_source, *nle_prev, *nle_post, *nle_oper, *nle_identity;
278 gboolean ret;
279 gchar *suffix;
280 PadEventData **data = g_new0 (PadEventData *, NUM_DATA);
281
282 /* composition */
283 comp =
284 gst_element_factory_make_or_warn ("nlecomposition", "test_composition");
285 gst_element_set_state (comp, GST_STATE_READY);
286
287 /* sink */
288 sink = gst_element_factory_make_or_warn ("fakeaudiosink", "sink");
289 g_object_set (sink, "sync", FALSE, NULL);
290 gst_bin_add_many (GST_BIN (pipeline), comp, sink, NULL);
291
292 gst_element_link (comp, sink);
293
294 /* sources */
295 nle_source =
296 audiotest_bin_src ("nle_source", 3 * GST_SECOND, 4 * GST_SECOND, 3,
297 FALSE);
298 g_object_set (nle_source, "inpoint", (guint64) 7 * GST_SECOND, NULL);
299 src = _get_source (nle_source);
300 g_object_set (src, "name", "middle-source", NULL);
301
302 nle_prev =
303 audiotest_bin_src ("nle_previous", 0 * GST_SECOND, 3 * GST_SECOND, 2,
304 FALSE);
305 g_object_set (nle_prev, "inpoint", (guint64) 99 * GST_SECOND, NULL);
306 prev = _get_source (nle_prev);
307 g_object_set (src, "name", "previous-source", NULL);
308
309 nle_post =
310 audiotest_bin_src ("post", 7 * GST_SECOND, 5 * GST_SECOND, 2, FALSE);
311 g_object_set (nle_post, "inpoint", (guint64) 20 * GST_SECOND, NULL);
312 post = _get_source (nle_post);
313 g_object_set (src, "name", "post-source", NULL);
314
315 /* Operation, must share the same start and duration as the upstream
316 * source */
317 nle_oper =
318 new_operation ("nle_oper", "pitch", 3 * GST_SECOND, 4 * GST_SECOND, 2);
319 fail_unless (g_list_length (GST_BIN_CHILDREN (nle_oper)) == 1);
320 pitch = GST_ELEMENT (GST_BIN_CHILDREN (nle_oper)->data);
321 g_object_set (pitch, "rate", rate, NULL);
322
323 /* cover with an identity operation
324 * rate effect has lower priority, so we don't need the same start or
325 * duration */
326 nle_identity =
327 new_operation ("nle_identity", "identity", 0, 12 * GST_SECOND, 1);
328 g_object_set (nle_identity, "inpoint", (guint64) 5 * GST_SECOND, NULL);
329 fail_unless (g_list_length (GST_BIN_CHILDREN (nle_oper)) == 1);
330 identity = GST_ELEMENT (GST_BIN_CHILDREN (nle_identity)->data);
331
332 nle_composition_add (GST_BIN (comp), nle_source);
333 nle_composition_add (GST_BIN (comp), nle_prev);
334 nle_composition_add (GST_BIN (comp), nle_post);
335 nle_composition_add (GST_BIN (comp), nle_oper);
336 nle_composition_add (GST_BIN (comp), nle_identity);
337 ret = FALSE;
338 commit_and_wait (comp, &ret);
339 fail_unless (ret);
340
341 check_start_stop_duration (nle_source, 3 * GST_SECOND, 7 * GST_SECOND,
342 4 * GST_SECOND);
343 check_start_stop_duration (nle_oper, 3 * GST_SECOND, 7 * GST_SECOND,
344 4 * GST_SECOND);
345 check_start_stop_duration (nle_prev, 0, 3 * GST_SECOND, 3 * GST_SECOND);
346 check_start_stop_duration (nle_post, 7 * GST_SECOND, 12 * GST_SECOND,
347 5 * GST_SECOND);
348 check_start_stop_duration (nle_identity, 0, 12 * GST_SECOND, 12 * GST_SECOND);
349 check_start_stop_duration (comp, 0, 12 * GST_SECOND, 12 * GST_SECOND);
350
351 /* create data */
352 suffix = g_strdup_printf ("rate=%g", rate);
353
354 /* source */
355 data[NLE_SOURCE_SRC] = _pad_event_data_new (nle_source, "src", suffix);
356 data[NLE_PREV_SRC] = _pad_event_data_new (nle_prev, "src", suffix);
357 data[NLE_POST_SRC] = _pad_event_data_new (nle_post, "src", suffix);
358 data[SOURCE_SRC] = _pad_event_data_new (src, "src", suffix);
359 data[PREV_SRC] = _pad_event_data_new (prev, "src", suffix);
360 data[POST_SRC] = _pad_event_data_new (post, "src", suffix);
361
362 /* rate operation */
363 data[NLE_OPER_SRC] = _pad_event_data_new (nle_oper, "src", suffix);
364 data[NLE_OPER_SINK] = _pad_event_data_new (nle_oper, "sink", suffix);
365 data[PITCH_SRC] = _pad_event_data_new (pitch, "src", suffix);
366 data[PITCH_SINK] = _pad_event_data_new (pitch, "sink", suffix);
367
368 /* identity: only care about the source pads */
369 data[NLE_IDENTITY_SRC] = _pad_event_data_new (nle_identity, "src", suffix);
370 data[IDENTITY_SRC] = _pad_event_data_new (identity, "src", suffix);
371
372 /* sink */
373 data[SINK_SINK] = _pad_event_data_new (sink, "sink", suffix);
374
375 g_free (suffix);
376
377 return data;
378 }
379
380
381 GST_START_TEST (test_tempochange_play)
382 {
383 GstElement *pipeline;
384 GstBus *bus;
385 GstMessage *message;
386 gboolean carry_on;
387 PadEventData **data;
388 gdouble rates[3] = { 0.5, 4.0, 1.0 };
389 guint i, j;
390
391 late_ges_init ();
392
393 for (i = 0; i < G_N_ELEMENTS (rates); i++) {
394 gdouble rate = rates[i];
395 GST_DEBUG ("rate = %g", rate);
396
397 pipeline = gst_pipeline_new ("test_pipeline");
398
399 data = _setup_test (pipeline, rate);
400
401 /* initial seek */
402 _EXPECT_SEEK_SEGMENT (data[SINK_SINK], 0, 3 * GST_SECOND);
403 _EXPECT_SEEK_SEGMENT (data[NLE_IDENTITY_SRC], 0, 3 * GST_SECOND);
404 /* nleobject will convert the seek by removing start and adding inpoint */
405 _EXPECT_SEEK_SEGMENT (data[IDENTITY_SRC], 5 * GST_SECOND, 8 * GST_SECOND);
406 _EXPECT_SEEK_SEGMENT (data[NLE_PREV_SRC], 0, 3 * GST_SECOND);
407 _EXPECT_SEEK_SEGMENT (data[PREV_SRC], 99 * GST_SECOND, 102 * GST_SECOND);
408
409 /* rate-stack seek */
410 _EXPECT_SEEK_SEGMENT (data[SINK_SINK], 3 * GST_SECOND, 7 * GST_SECOND);
411 _EXPECT_SEEK_SEGMENT (data[NLE_IDENTITY_SRC], 3 * GST_SECOND,
412 7 * GST_SECOND);
413 _EXPECT_SEEK_SEGMENT (data[IDENTITY_SRC], 8 * GST_SECOND, 12 * GST_SECOND);
414 _EXPECT_SEEK_SEGMENT (data[NLE_OPER_SRC], 3 * GST_SECOND, 7 * GST_SECOND);
415 _EXPECT_SEEK_SEGMENT (data[PITCH_SRC], 0, 4 * GST_SECOND);
416 /* pitch element will change the stop time, e.g. if rate=2.0, then we
417 * want to use up twice as much source, so the stop time doubles */
418 _EXPECT_SEEK_SEGMENT (data[PITCH_SINK], 0, rate * 4 * GST_SECOND);
419 _EXPECT_SEEK_SEGMENT (data[NLE_OPER_SINK], 3 * GST_SECOND,
420 (GstClockTime) (rate * 4 * GST_SECOND) + 3 * GST_SECOND);
421 _EXPECT_SEEK_SEGMENT (data[NLE_SOURCE_SRC], 3 * GST_SECOND,
422 (GstClockTime) (rate * 4 * GST_SECOND) + 3 * GST_SECOND);
423 _EXPECT_SEEK_SEGMENT (data[SOURCE_SRC], 7 * GST_SECOND,
424 (GstClockTime) (rate * 4 * GST_SECOND) + 7 * GST_SECOND);
425
426 /* final part only involves post source */
427 _EXPECT_SEEK_SEGMENT (data[SINK_SINK], 7 * GST_SECOND, 12 * GST_SECOND);
428 _EXPECT_SEEK_SEGMENT (data[NLE_IDENTITY_SRC], 7 * GST_SECOND,
429 12 * GST_SECOND);
430 _EXPECT_SEEK_SEGMENT (data[IDENTITY_SRC], 12 * GST_SECOND, 17 * GST_SECOND);
431 _EXPECT_SEEK_SEGMENT (data[NLE_POST_SRC], 7 * GST_SECOND, 12 * GST_SECOND);
432 /* nleobject will convert the seek by removing start and adding
433 * inpoint */
434 _EXPECT_SEEK_SEGMENT (data[POST_SRC], 20 * GST_SECOND, 25 * GST_SECOND);
435
436 /* expect 1 EOS from each, apart from identity, which will get 3 since
437 * part of 3 stacks */
438 for (j = 0; j < NUM_DATA; j++)
439 data[j]->expect_num_eos = 1;
440
441 data[IDENTITY_SRC]->expect_num_eos = 3;
442 data[NLE_IDENTITY_SRC]->expect_num_eos = 3;
443
444 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
445
446 GST_DEBUG ("Setting pipeline to PLAYING");
447 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
448 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
449
450 GST_DEBUG ("Let's poll the bus");
451
452 carry_on = TRUE;
453 while (carry_on) {
454 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
455 if (message) {
456 switch (GST_MESSAGE_TYPE (message)) {
457 case GST_MESSAGE_EOS:
458 if (message->src == GST_OBJECT (pipeline)) {
459 GST_DEBUG ("Setting pipeline to NULL");
460 fail_unless (gst_element_set_state (GST_ELEMENT (pipeline),
461 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
462 carry_on = FALSE;
463 }
464 break;
465 case GST_MESSAGE_ERROR:
466 fail_error_message (message);
467 break;
468 default:
469 break;
470 }
471 gst_message_unref (message);
472 }
473 }
474
475 for (j = 0; j < NUM_DATA; j++)
476 _pad_event_data_check_received (data[j]);
477
478 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "main pipeline", 1, 2);
479 gst_object_unref (pipeline);
480 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
481 gst_object_unref (bus);
482 g_free (data);
483 }
484 }
485
486 GST_END_TEST;
487
488 #define _WAIT_UNTIL_ASYNC_DONE \
489 { \
490 GST_DEBUG ("Let's poll the bus"); \
491 carry_on = TRUE; \
492 while (carry_on) { \
493 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10); \
494 if (message) { \
495 switch (GST_MESSAGE_TYPE (message)) { \
496 case GST_MESSAGE_EOS: \
497 fail_if (TRUE, "Received EOS"); \
498 break; \
499 case GST_MESSAGE_ERROR: \
500 fail_error_message (message); \
501 break; \
502 case GST_MESSAGE_ASYNC_DONE: \
503 carry_on = FALSE; \
504 break; \
505 default: \
506 break; \
507 } \
508 gst_message_unref (message); \
509 } \
510 } \
511 }
512
513 GST_START_TEST (test_tempochange_seek)
514 {
515 GstElement *pipeline;
516 GstBus *bus;
517 GstMessage *message;
518 gboolean carry_on;
519 PadEventData **data;
520 gdouble rates[3] = { 2.0, 0.25, 1.0 };
521 guint i, j;
522 GstClockTime offset = 0.1 * GST_SECOND;
523
524 late_ges_init ();
525
526 for (i = 0; i < G_N_ELEMENTS (rates); i++) {
527 gdouble rate = rates[i];
528 GST_DEBUG ("rate = %g", rate);
529
530 pipeline = gst_pipeline_new ("test_pipeline");
531
532 data = _setup_test (pipeline, rate);
533
534 /* initial seek from the pause */
535 _EXPECT_SEEK_SEGMENT (data[SINK_SINK], 0, 3 * GST_SECOND);
536 _EXPECT_SEEK_SEGMENT (data[NLE_IDENTITY_SRC], 0, 3 * GST_SECOND);
537 _EXPECT_SEEK_SEGMENT (data[IDENTITY_SRC], 5 * GST_SECOND, 8 * GST_SECOND);
538 _EXPECT_SEEK_SEGMENT (data[NLE_PREV_SRC], 0, 3 * GST_SECOND);
539 _EXPECT_SEEK_SEGMENT (data[PREV_SRC], 99 * GST_SECOND, 102 * GST_SECOND);
540
541 GST_DEBUG ("Setting pipeline to PAUSED");
542 fail_unless (gst_element_set_state (GST_ELEMENT (pipeline),
543 GST_STATE_PAUSED) == GST_STATE_CHANGE_ASYNC);
544
545 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
546
547 _WAIT_UNTIL_ASYNC_DONE;
548
549 for (j = 0; j < NUM_DATA; j++)
550 _pad_event_data_check_received (data[j]);
551
552 /* first seek for just after the start of the rate effect */
553 /* NOTE: neither prev nor post should receive anything */
554
555 /* sink will receive two seeks: one that initiates the pre-roll, and
556 * then the seek with the stop set */
557 /* expect no segment for the first seek */
558 _pad_event_data_add_expect_seek (data[SINK_SINK], 3 * GST_SECOND + offset,
559 GST_CLOCK_TIME_NONE);
560 _EXPECT_SEEK_SEGMENT (data[SINK_SINK], 3 * GST_SECOND + offset,
561 7 * GST_SECOND);
562 _EXPECT_SEEK_SEGMENT (data[NLE_IDENTITY_SRC], 3 * GST_SECOND + offset,
563 7 * GST_SECOND);
564 _EXPECT_SEEK_SEGMENT (data[IDENTITY_SRC], 8 * GST_SECOND + offset,
565 12 * GST_SECOND);
566 _EXPECT_SEEK_SEGMENT (data[NLE_OPER_SRC], 3 * GST_SECOND + offset,
567 7 * GST_SECOND);
568 _EXPECT_SEEK_SEGMENT (data[PITCH_SRC], offset, 4 * GST_SECOND);
569 _EXPECT_SEEK_SEGMENT (data[PITCH_SINK], rate * offset,
570 rate * 4 * GST_SECOND);
571 _EXPECT_SEEK_SEGMENT (data[NLE_OPER_SINK],
572 3 * GST_SECOND + (GstClockTime) (rate * offset),
573 3 * GST_SECOND + (GstClockTime) (rate * 4 * GST_SECOND));
574 _EXPECT_SEEK_SEGMENT (data[NLE_SOURCE_SRC],
575 3 * GST_SECOND + (GstClockTime) (rate * offset),
576 3 * GST_SECOND + (GstClockTime) (rate * 4 * GST_SECOND));
577 _EXPECT_SEEK_SEGMENT (data[SOURCE_SRC],
578 7 * GST_SECOND + (GstClockTime) (rate * offset),
579 7 * GST_SECOND + (GstClockTime) (rate * 4 * GST_SECOND));
580
581 /* perform seek */
582 fail_unless (gst_element_seek_simple (pipeline, GST_FORMAT_TIME,
583 GST_SEEK_FLAG_FLUSH, 3 * GST_SECOND + offset));
584
585 _WAIT_UNTIL_ASYNC_DONE;
586
587 for (j = 0; j < NUM_DATA; j++)
588 _pad_event_data_check_received (data[j]);
589
590 /* now seek to just before the end */
591 _pad_event_data_add_expect_seek (data[SINK_SINK], 7 * GST_SECOND - offset,
592 GST_CLOCK_TIME_NONE);
593 _EXPECT_SEEK_SEGMENT (data[SINK_SINK], 7 * GST_SECOND - offset,
594 7 * GST_SECOND);
595 _EXPECT_SEEK_SEGMENT (data[NLE_IDENTITY_SRC], 7 * GST_SECOND - offset,
596 7 * GST_SECOND);
597 _EXPECT_SEEK_SEGMENT (data[IDENTITY_SRC], 12 * GST_SECOND - offset,
598 12 * GST_SECOND);
599 _EXPECT_SEEK_SEGMENT (data[NLE_OPER_SRC], 7 * GST_SECOND - offset,
600 7 * GST_SECOND);
601 _EXPECT_SEEK_SEGMENT (data[PITCH_SRC], 4 * GST_SECOND - offset,
602 4 * GST_SECOND);
603 _EXPECT_SEEK_SEGMENT (data[PITCH_SINK],
604 rate * (4 * GST_SECOND) - rate * offset, rate * 4 * GST_SECOND);
605 _EXPECT_SEEK_SEGMENT (data[NLE_OPER_SINK],
606 3 * GST_SECOND + (GstClockTime) (rate * (4 * GST_SECOND - offset)),
607 3 * GST_SECOND + (GstClockTime) (rate * 4 * GST_SECOND));
608 _EXPECT_SEEK_SEGMENT (data[NLE_SOURCE_SRC],
609 3 * GST_SECOND + (GstClockTime) (rate * (4 * GST_SECOND - offset)),
610 3 * GST_SECOND + (GstClockTime) (rate * 4 * GST_SECOND));
611 _EXPECT_SEEK_SEGMENT (data[SOURCE_SRC],
612 7 * GST_SECOND + (GstClockTime) (rate * (4 * GST_SECOND - offset)),
613 7 * GST_SECOND + (GstClockTime) (rate * 4 * GST_SECOND));
614
615 /* perform seek */
616 fail_unless (gst_element_seek_simple (pipeline, GST_FORMAT_TIME,
617 GST_SEEK_FLAG_FLUSH, 7 * GST_SECOND - offset));
618
619 _WAIT_UNTIL_ASYNC_DONE;
620
621 for (j = 0; j < NUM_DATA; j++)
622 _pad_event_data_check_received (data[j]);
623
624 GST_DEBUG ("Setting pipeline to NULL");
625 fail_unless (gst_element_set_state (GST_ELEMENT (pipeline),
626 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
627
628 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "main pipeline", 1, 2);
629 gst_object_unref (pipeline);
630 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
631 gst_object_unref (bus);
632 g_free (data);
633 }
634 }
635
636 GST_END_TEST;
637
638 static void
639 late_ges_init (void)
640 {
641 /* We need to do this inside the test cases, not during the initialization
642 * of the suite, as ges_init() will initialize thread pools, which cannot
643 * work properly after a fork. */
644
645 if (atexit (ges_deinit) != 0) {
646 GST_ERROR ("failed to set ges_deinit as exit function");
647 }
648
649 ges_init ();
650 }
651
652 static Suite *
653 gnonlin_suite (void)
654 {
655 Suite *s = suite_create ("nle");
656 TCase *tc_chain = tcase_create ("tempochange");
657
658 suite_add_tcase (s, tc_chain);
659
660 /* give the tests a little more time than the default
661 * CK_DEFAULT_TIMEOUT=20, this is sometimes needed for running under
662 * valgrind */
663 tcase_set_timeout (tc_chain, 40.0);
664
665 tcase_add_test (tc_chain, test_tempochange_play);
666 tcase_add_test (tc_chain, test_tempochange_seek);
667
668 return s;
669 }
670
671 GST_CHECK_MAIN (gnonlin)