Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / imagefreeze.c
1 /* GStreamer
2  * Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <string.h>
21
22 #include <gst/check/gstcheck.h>
23 #include <gst/video/video.h>
24
25 static gboolean
26 bus_handler (GstBus * bus, GstMessage * message, gpointer data)
27 {
28   GMainLoop *loop = (GMainLoop *) data;
29
30   switch (message->type) {
31     case GST_MESSAGE_EOS:
32       g_main_loop_quit (loop);
33       break;
34     case GST_MESSAGE_WARNING:
35     case GST_MESSAGE_ERROR:{
36       GError *gerror;
37       gchar *debug;
38
39       if (message->type == GST_MESSAGE_WARNING)
40         gst_message_parse_warning (message, &gerror, &debug);
41       else
42         gst_message_parse_error (message, &gerror, &debug);
43       g_error ("error from %s: %s (%s)\n",
44           GST_ELEMENT_NAME (GST_MESSAGE_SRC (message)), gerror->message,
45           GST_STR_NULL (debug));
46       gst_message_unref (message);
47       g_error_free (gerror);
48       g_free (debug);
49       g_main_loop_quit (loop);
50       break;
51     }
52     default:
53       break;
54   }
55
56   return TRUE;
57 }
58
59 static GstElement *
60 setup_imagefreeze (const GstCaps * caps1, const GstCaps * caps2,
61     GCallback sink_handoff, gpointer sink_handoff_data)
62 {
63   GstElement *pipeline;
64   GstElement *videotestsrc, *capsfilter1, *imagefreeze, *capsfilter2, *fakesink;
65
66   pipeline = gst_pipeline_new ("pipeline");
67   fail_unless (pipeline != NULL);
68
69   videotestsrc = gst_element_factory_make ("videotestsrc", "src");
70   fail_unless (videotestsrc != NULL);
71   g_object_set (videotestsrc, "num-buffers", 1, NULL);
72
73   capsfilter1 = gst_element_factory_make ("capsfilter", "filter1");
74   fail_unless (capsfilter1 != NULL);
75   g_object_set (capsfilter1, "caps", caps1, NULL);
76
77   imagefreeze = gst_element_factory_make ("imagefreeze", "freeze");
78   fail_unless (imagefreeze != NULL);
79
80   capsfilter2 = gst_element_factory_make ("capsfilter", "filter2");
81   fail_unless (capsfilter2 != NULL);
82   g_object_set (capsfilter2, "caps", caps2, NULL);
83
84   fakesink = gst_element_factory_make ("fakesink", "sink");
85   fail_unless (fakesink != NULL);
86   g_object_set (fakesink, "signal-handoffs", TRUE, "async", FALSE, NULL);
87
88   if (sink_handoff)
89     g_signal_connect (fakesink, "handoff", sink_handoff, sink_handoff_data);
90
91   gst_bin_add_many (GST_BIN (pipeline), videotestsrc, capsfilter1, imagefreeze,
92       capsfilter2, fakesink, NULL);
93
94   fail_unless (gst_element_link_pads (videotestsrc, "src", capsfilter1,
95           "sink"));
96   fail_unless (gst_element_link_pads (capsfilter1, "src", imagefreeze, "sink"));
97   fail_unless (gst_element_link_pads (imagefreeze, "src", capsfilter2, "sink"));
98   fail_unless (gst_element_link_pads (capsfilter2, "src", fakesink, "sink"));
99
100   return pipeline;
101 }
102
103 static void
104 sink_handoff_cb_0_1 (GstElement * object, GstBuffer * buffer, GstPad * pad,
105     gpointer user_data)
106 {
107   guint *n_buffers = (guint *) user_data;
108
109   if (*n_buffers == G_MAXUINT)
110     return;
111
112   fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer), 0);
113   fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), GST_CLOCK_TIME_NONE);
114   fail_unless_equals_uint64 (GST_BUFFER_OFFSET (buffer), 0);
115   fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (buffer), 1);
116
117   *n_buffers = *n_buffers + 1;
118 }
119
120 GST_START_TEST (test_imagefreeze_0_1)
121 {
122   GstElement *pipeline;
123   GstCaps *caps1, *caps2;
124   GstBus *bus;
125   GMainLoop *loop;
126   guint n_buffers = G_MAXUINT;
127   guint bus_watch = 0;
128
129   caps1 =
130       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
131   caps2 =
132       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 0, 1, 1, 1);
133
134   pipeline =
135       setup_imagefreeze (caps1, caps2, G_CALLBACK (sink_handoff_cb_0_1),
136       &n_buffers);
137
138   loop = g_main_loop_new (NULL, TRUE);
139   fail_unless (loop != NULL);
140
141   bus = gst_element_get_bus (pipeline);
142   fail_unless (bus != NULL);
143   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
144   gst_object_unref (bus);
145
146   n_buffers = 0;
147   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
148       GST_STATE_CHANGE_SUCCESS);
149
150   g_main_loop_run (loop);
151
152   fail_unless_equals_int (n_buffers, 1);
153
154   gst_element_set_state (pipeline, GST_STATE_NULL);
155
156   gst_object_unref (pipeline);
157   g_main_loop_unref (loop);
158   gst_caps_unref (caps1);
159   gst_caps_unref (caps2);
160   g_source_remove (bus_watch);
161 }
162
163 GST_END_TEST;
164
165 static void
166 sink_handoff_cb_25_1_0ms_400ms (GstElement * object, GstBuffer * buffer,
167     GstPad * pad, gpointer user_data)
168 {
169   guint *n_buffers = (guint *) user_data;
170
171   if (*n_buffers == G_MAXUINT)
172     return;
173
174   fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
175       *n_buffers * 40 * GST_MSECOND);
176   fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), 40 * GST_MSECOND);
177   fail_unless_equals_uint64 (GST_BUFFER_OFFSET (buffer), *n_buffers);
178   fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (buffer), *n_buffers + 1);
179
180   *n_buffers = *n_buffers + 1;
181 }
182
183 GST_START_TEST (test_imagefreeze_25_1_0ms_400ms)
184 {
185   GstElement *pipeline;
186   GstCaps *caps1, *caps2;
187   GstBus *bus;
188   GMainLoop *loop;
189   guint n_buffers = G_MAXUINT;
190   guint bus_watch = 0;
191
192   caps1 =
193       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
194   caps2 =
195       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
196
197   pipeline =
198       setup_imagefreeze (caps1, caps2,
199       G_CALLBACK (sink_handoff_cb_25_1_0ms_400ms), &n_buffers);
200
201   loop = g_main_loop_new (NULL, TRUE);
202   fail_unless (loop != NULL);
203
204   bus = gst_element_get_bus (pipeline);
205   fail_unless (bus != NULL);
206   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
207   gst_object_unref (bus);
208
209   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
210       GST_STATE_CHANGE_SUCCESS);
211
212   fail_unless (gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME,
213           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET,
214           400 * GST_MSECOND));
215
216   n_buffers = 0;
217
218   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
219       GST_STATE_CHANGE_SUCCESS);
220
221   g_main_loop_run (loop);
222
223   fail_unless_equals_int (n_buffers, 10);
224
225   gst_element_set_state (pipeline, GST_STATE_NULL);
226
227   gst_object_unref (pipeline);
228   g_main_loop_unref (loop);
229   gst_caps_unref (caps1);
230   gst_caps_unref (caps2);
231   g_source_remove (bus_watch);
232 }
233
234 GST_END_TEST;
235
236 static void
237 sink_handoff_cb_25_1_200ms_400ms (GstElement * object, GstBuffer * buffer,
238     GstPad * pad, gpointer user_data)
239 {
240   guint *n_buffers = (guint *) user_data;
241
242   if (*n_buffers == G_MAXUINT)
243     return;
244
245   fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
246       200 * GST_MSECOND + *n_buffers * 40 * GST_MSECOND);
247   fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), 40 * GST_MSECOND);
248   fail_unless_equals_uint64 (GST_BUFFER_OFFSET (buffer), 5 + *n_buffers);
249   fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (buffer),
250       5 + *n_buffers + 1);
251
252   *n_buffers = *n_buffers + 1;
253 }
254
255 GST_START_TEST (test_imagefreeze_25_1_200ms_400ms)
256 {
257   GstElement *pipeline;
258   GstCaps *caps1, *caps2;
259   GstBus *bus;
260   GMainLoop *loop;
261   guint n_buffers = G_MAXUINT;
262   guint bus_watch = 0;
263
264   caps1 =
265       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
266   caps2 =
267       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
268
269   pipeline =
270       setup_imagefreeze (caps1, caps2,
271       G_CALLBACK (sink_handoff_cb_25_1_200ms_400ms), &n_buffers);
272
273   loop = g_main_loop_new (NULL, TRUE);
274   fail_unless (loop != NULL);
275
276   bus = gst_element_get_bus (pipeline);
277   fail_unless (bus != NULL);
278   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
279   gst_object_unref (bus);
280
281   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
282       GST_STATE_CHANGE_SUCCESS);
283
284   fail_unless (gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME,
285           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 200 * GST_MSECOND,
286           GST_SEEK_TYPE_SET, 400 * GST_MSECOND));
287
288   n_buffers = 0;
289
290   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
291       GST_STATE_CHANGE_SUCCESS);
292
293   g_main_loop_run (loop);
294
295   fail_unless_equals_int (n_buffers, 5);
296
297   gst_element_set_state (pipeline, GST_STATE_NULL);
298
299   gst_object_unref (pipeline);
300   g_main_loop_unref (loop);
301   gst_caps_unref (caps1);
302   gst_caps_unref (caps2);
303   g_source_remove (bus_watch);
304 }
305
306 GST_END_TEST;
307
308 static void
309 sink_handoff_cb_25_1_400ms_0ms (GstElement * object, GstBuffer * buffer,
310     GstPad * pad, gpointer user_data)
311 {
312   guint *n_buffers = (guint *) user_data;
313
314   if (*n_buffers == G_MAXUINT)
315     return;
316
317   fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
318       400 * GST_MSECOND - (*n_buffers + 1) * 40 * GST_MSECOND);
319   fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), 40 * GST_MSECOND);
320   fail_unless_equals_uint64 (GST_BUFFER_OFFSET (buffer), 10 - (*n_buffers + 1));
321   fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (buffer),
322       10 - (*n_buffers + 1) + 1);
323
324   *n_buffers = *n_buffers + 1;
325 }
326
327 GST_START_TEST (test_imagefreeze_25_1_400ms_0ms)
328 {
329   GstElement *pipeline;
330   GstCaps *caps1, *caps2;
331   GstBus *bus;
332   GMainLoop *loop;
333   guint n_buffers = G_MAXUINT;
334   guint bus_watch = 0;
335
336   caps1 =
337       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
338   caps2 =
339       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
340
341   pipeline =
342       setup_imagefreeze (caps1, caps2,
343       G_CALLBACK (sink_handoff_cb_25_1_400ms_0ms), &n_buffers);
344
345   loop = g_main_loop_new (NULL, TRUE);
346   fail_unless (loop != NULL);
347
348   bus = gst_element_get_bus (pipeline);
349   fail_unless (bus != NULL);
350   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
351   gst_object_unref (bus);
352
353   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
354       GST_STATE_CHANGE_SUCCESS);
355
356   fail_unless (gst_element_seek (pipeline, -1.0, GST_FORMAT_TIME,
357           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET,
358           400 * GST_MSECOND));
359
360   n_buffers = 0;
361
362   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
363       GST_STATE_CHANGE_SUCCESS);
364
365   g_main_loop_run (loop);
366
367   fail_unless_equals_int (n_buffers, 10);
368
369   gst_element_set_state (pipeline, GST_STATE_NULL);
370
371   gst_object_unref (pipeline);
372   g_main_loop_unref (loop);
373   gst_caps_unref (caps1);
374   gst_caps_unref (caps2);
375   g_source_remove (bus_watch);
376 }
377
378 GST_END_TEST;
379
380 static void
381 sink_handoff_cb_25_1_220ms_380ms (GstElement * object, GstBuffer * buffer,
382     GstPad * pad, gpointer user_data)
383 {
384   guint *n_buffers = (guint *) user_data;
385
386   if (*n_buffers == G_MAXUINT)
387     return;
388
389   if (*n_buffers == 0) {
390     fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
391         220 * GST_MSECOND);
392     fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), 20 * GST_MSECOND);
393   } else if (*n_buffers == 4) {
394     fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
395         360 * GST_MSECOND);
396     fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), 20 * GST_MSECOND);
397   } else {
398     fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
399         200 * GST_MSECOND + *n_buffers * 40 * GST_MSECOND);
400     fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), 40 * GST_MSECOND);
401   }
402
403   fail_unless_equals_uint64 (GST_BUFFER_OFFSET (buffer), 5 + *n_buffers);
404   fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (buffer),
405       5 + *n_buffers + 1);
406
407   *n_buffers = *n_buffers + 1;
408 }
409
410 GST_START_TEST (test_imagefreeze_25_1_220ms_380ms)
411 {
412   GstElement *pipeline;
413   GstCaps *caps1, *caps2;
414   GstBus *bus;
415   GMainLoop *loop;
416   guint n_buffers = G_MAXUINT;
417   guint bus_watch = 0;
418
419   caps1 =
420       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
421   caps2 =
422       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
423
424   pipeline =
425       setup_imagefreeze (caps1, caps2,
426       G_CALLBACK (sink_handoff_cb_25_1_220ms_380ms), &n_buffers);
427
428   loop = g_main_loop_new (NULL, TRUE);
429   fail_unless (loop != NULL);
430
431   bus = gst_element_get_bus (pipeline);
432   fail_unless (bus != NULL);
433   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
434   gst_object_unref (bus);
435
436   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
437       GST_STATE_CHANGE_SUCCESS);
438
439   fail_unless (gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME,
440           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 220 * GST_MSECOND,
441           GST_SEEK_TYPE_SET, 380 * GST_MSECOND));
442
443   n_buffers = 0;
444
445   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
446       GST_STATE_CHANGE_SUCCESS);
447
448   g_main_loop_run (loop);
449
450   fail_unless_equals_int (n_buffers, 5);
451
452   gst_element_set_state (pipeline, GST_STATE_NULL);
453
454   gst_object_unref (pipeline);
455   g_main_loop_unref (loop);
456   gst_caps_unref (caps1);
457   gst_caps_unref (caps2);
458   g_source_remove (bus_watch);
459 }
460
461 GST_END_TEST;
462
463 static GstBuffer *test_buffer = NULL;
464
465 static GstFlowReturn
466 test_bufferalloc (GstPad * pad, guint64 offset, guint size, GstCaps * caps,
467     GstBuffer ** buf)
468 {
469   fail_if (test_buffer != NULL);
470
471   test_buffer = gst_buffer_new_and_alloc (size);
472   gst_buffer_set_caps (test_buffer, caps);
473
474   *buf = gst_buffer_ref (test_buffer);
475
476   return GST_FLOW_OK;
477 }
478
479 static void
480 sink_handoff_cb_bufferalloc (GstElement * object, GstBuffer * buffer,
481     GstPad * pad, gpointer user_data)
482 {
483   guint *n_buffers = (guint *) user_data;
484
485   if (*n_buffers == G_MAXUINT)
486     return;
487
488   fail_unless (buffer->parent != NULL);
489   fail_unless (test_buffer != NULL);
490   fail_unless (buffer->parent == test_buffer);
491
492   *n_buffers = *n_buffers + 1;
493 }
494
495 GST_START_TEST (test_imagefreeze_bufferalloc)
496 {
497   GstElement *pipeline;
498   GstElement *sink;
499   GstPad *sinkpad;
500   GstCaps *caps1, *caps2;
501   GstBus *bus;
502   GMainLoop *loop;
503   guint n_buffers = G_MAXUINT;
504   guint bus_watch = 0;
505
506   caps1 =
507       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
508   caps2 =
509       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
510
511   pipeline =
512       setup_imagefreeze (caps1, caps2, G_CALLBACK (sink_handoff_cb_bufferalloc),
513       &n_buffers);
514
515   sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
516   fail_unless (sink != NULL);
517   sinkpad = gst_element_get_static_pad (sink, "sink");
518   fail_unless (sinkpad != NULL);
519   gst_pad_set_bufferalloc_function (sinkpad, test_bufferalloc);
520   gst_object_unref (sinkpad);
521   gst_object_unref (sink);
522
523   loop = g_main_loop_new (NULL, TRUE);
524   fail_unless (loop != NULL);
525
526   bus = gst_element_get_bus (pipeline);
527   fail_unless (bus != NULL);
528   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
529   gst_object_unref (bus);
530
531   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
532       GST_STATE_CHANGE_SUCCESS);
533
534   fail_unless (gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME,
535           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET,
536           400 * GST_MSECOND));
537
538   n_buffers = 0;
539   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
540       GST_STATE_CHANGE_SUCCESS);
541
542   g_main_loop_run (loop);
543
544   fail_unless (test_buffer != NULL);
545   fail_unless (n_buffers >= 1);
546
547   gst_element_set_state (pipeline, GST_STATE_NULL);
548
549   gst_buffer_unref (test_buffer);
550   test_buffer = NULL;
551
552   gst_object_unref (pipeline);
553   g_main_loop_unref (loop);
554   gst_caps_unref (caps1);
555   gst_caps_unref (caps2);
556   g_source_remove (bus_watch);
557 }
558
559 GST_END_TEST;
560
561 GST_START_TEST (test_imagefreeze_eos)
562 {
563   GstElement *pipeline;
564   GstElement *src;
565   GstCaps *caps1, *caps2;
566   GstBus *bus;
567   GMainLoop *loop;
568   GstFormat fmt = GST_FORMAT_TIME;
569   gint64 position;
570   guint bus_watch = 0;
571
572   caps1 =
573       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
574   caps2 =
575       gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
576
577   pipeline = setup_imagefreeze (caps1, caps2, NULL, NULL);
578
579   src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
580   fail_unless (src != NULL);
581   g_object_set (src, "num-buffers", 100, NULL);
582
583   loop = g_main_loop_new (NULL, TRUE);
584   fail_unless (loop != NULL);
585
586   bus = gst_element_get_bus (pipeline);
587   fail_unless (bus != NULL);
588   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
589   gst_object_unref (bus);
590
591   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
592       GST_STATE_CHANGE_SUCCESS);
593
594   fail_unless (gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME,
595           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET,
596           400 * GST_MSECOND));
597
598   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
599       GST_STATE_CHANGE_SUCCESS);
600
601   g_main_loop_run (loop);
602
603   fail_unless (gst_element_query_position (src, &fmt, &position));
604   fail_unless_equals_uint64 (position, 40 * GST_MSECOND);
605
606   gst_element_set_state (pipeline, GST_STATE_NULL);
607
608   gst_object_unref (src);
609   gst_object_unref (pipeline);
610   g_main_loop_unref (loop);
611   gst_caps_unref (caps1);
612   gst_caps_unref (caps2);
613   g_source_remove (bus_watch);
614 }
615
616 GST_END_TEST;
617
618 static Suite *
619 imagefreeze_suite (void)
620 {
621   Suite *s = suite_create ("imagefreeze");
622   TCase *tc_chain = tcase_create ("linear");
623
624   /* time out after 120s, not the default 3 */
625   tcase_set_timeout (tc_chain, 120);
626
627   suite_add_tcase (s, tc_chain);
628   tcase_add_test (tc_chain, test_imagefreeze_0_1);
629   tcase_add_test (tc_chain, test_imagefreeze_25_1_0ms_400ms);
630   tcase_add_test (tc_chain, test_imagefreeze_25_1_200ms_400ms);
631   tcase_add_test (tc_chain, test_imagefreeze_25_1_400ms_0ms);
632   tcase_add_test (tc_chain, test_imagefreeze_25_1_220ms_380ms);
633
634   tcase_add_test (tc_chain, test_imagefreeze_bufferalloc);
635   tcase_add_test (tc_chain, test_imagefreeze_eos);
636
637   return s;
638 }
639
640 GST_CHECK_MAIN (imagefreeze);