38c2dc307d14584ce5b1ce50dd0af3369d322250
[platform/upstream/gstreamer.git] / tests / check / gst / media.c
1 /* GStreamer
2  * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
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 <gst/check/gstcheck.h>
21
22 #include <rtsp-media-factory.h>
23
24 /* Check if the media can return a SDP. We don't actually check whether
25  * the contents are valid or not */
26 static gboolean
27 media_has_sdp (GstRTSPMedia * media)
28 {
29   GstSDPInfo info;
30   GstSDPMessage *sdp;
31   gchar *sdp_str;
32
33   info.is_ipv6 = FALSE;
34   info.server_ip = "0.0.0.0";
35
36   /* Check if media can generate a SDP */
37   gst_sdp_message_new (&sdp);
38   GST_DEBUG ("Getting SDP");
39   if (!gst_rtsp_sdp_from_media (sdp, &info, media)) {
40     GST_WARNING ("failed to get the SDP");
41     gst_sdp_message_free (sdp);
42     return FALSE;
43   }
44   sdp_str = gst_sdp_message_as_text (sdp);
45   GST_DEBUG ("Got SDP\n%s", sdp_str);
46   g_free (sdp_str);
47   gst_sdp_message_free (sdp);
48
49   return TRUE;
50 }
51
52 GST_START_TEST (test_media_seek)
53 {
54   GstRTSPMediaFactory *factory;
55   GstRTSPMedia *media;
56   GstRTSPUrl *url;
57   GstRTSPStream *stream;
58   GstRTSPTimeRange *range;
59   gchar *str;
60   GstRTSPThreadPool *pool;
61   GstRTSPThread *thread;
62   GstRTSPTransport *transport;
63
64   factory = gst_rtsp_media_factory_new ();
65   fail_if (gst_rtsp_media_factory_is_shared (factory));
66   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
67           &url) == GST_RTSP_OK);
68
69   gst_rtsp_media_factory_set_launch (factory,
70       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
71
72   media = gst_rtsp_media_factory_construct (factory, url);
73   fail_unless (GST_IS_RTSP_MEDIA (media));
74
75   fail_unless (gst_rtsp_media_n_streams (media) == 1);
76
77   stream = gst_rtsp_media_get_stream (media, 0);
78   fail_unless (stream != NULL);
79
80   pool = gst_rtsp_thread_pool_new ();
81   thread = gst_rtsp_thread_pool_get_thread (pool,
82       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
83
84   fail_unless (gst_rtsp_media_prepare (media, thread));
85   fail_unless (media_has_sdp (media));
86
87   /* define transport */
88   fail_unless (gst_rtsp_transport_new (&transport) == GST_RTSP_OK);
89   transport->lower_transport = GST_RTSP_LOWER_TRANS_TCP;
90
91   fail_unless (gst_rtsp_stream_complete_stream (stream, transport));
92
93   fail_unless (gst_rtsp_transport_free (transport) == GST_RTSP_OK);
94   fail_unless (gst_rtsp_range_parse ("npt=5.0-", &range) == GST_RTSP_OK);
95
96   /* the media is seekable now */
97   fail_unless (gst_rtsp_media_seek (media, range));
98
99   str = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
100   fail_unless (g_str_equal (str, "npt=5-"));
101
102   gst_rtsp_range_free (range);
103   g_free (str);
104
105   fail_unless (gst_rtsp_media_unprepare (media));
106   g_object_unref (media);
107
108   gst_rtsp_url_free (url);
109   g_object_unref (factory);
110
111   g_object_unref (pool);
112
113   gst_rtsp_thread_pool_cleanup ();
114 }
115
116 GST_END_TEST;
117
118 /* case: media is complete and contains two streams but only one is active */
119 GST_START_TEST (test_media_seek_one_active_stream)
120 {
121   GstRTSPMediaFactory *factory;
122   GstRTSPMedia *media;
123   GstRTSPUrl *url;
124   GstRTSPStream *stream1;
125   GstRTSPStream *stream2;
126   GstRTSPTimeRange *range;
127   GstRTSPThreadPool *pool;
128   GstRTSPThread *thread;
129   GstRTSPTransport *transport;
130
131   factory = gst_rtsp_media_factory_new ();
132   fail_if (gst_rtsp_media_factory_is_shared (factory));
133   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
134           &url) == GST_RTSP_OK);
135
136   gst_rtsp_media_factory_set_launch (factory,
137       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
138       " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
139
140   media = gst_rtsp_media_factory_construct (factory, url);
141   fail_unless (GST_IS_RTSP_MEDIA (media));
142
143   fail_unless (gst_rtsp_media_n_streams (media) == 2);
144
145   stream1 = gst_rtsp_media_get_stream (media, 0);
146   fail_unless (stream1 != NULL);
147
148   pool = gst_rtsp_thread_pool_new ();
149   thread = gst_rtsp_thread_pool_get_thread (pool,
150       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
151
152   fail_unless (gst_rtsp_media_prepare (media, thread));
153   fail_unless (media_has_sdp (media));
154
155   /* define transport */
156   fail_unless (gst_rtsp_transport_new (&transport) == GST_RTSP_OK);
157   transport->lower_transport = GST_RTSP_LOWER_TRANS_TCP;
158
159   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
160
161   /* video stream is complete and seekable */
162   fail_unless (gst_rtsp_stream_complete_stream (stream1, transport));
163   fail_unless (gst_rtsp_stream_seekable (stream1));
164
165   /* audio stream is blocked (it does not contain any transport based part),
166    * but it's seekable */
167   stream2 = gst_rtsp_media_get_stream (media, 1);
168   fail_unless (stream2 != NULL);
169   fail_unless (gst_rtsp_stream_seekable (stream2));
170
171   fail_unless (gst_rtsp_transport_free (transport) == GST_RTSP_OK);
172   fail_unless (gst_rtsp_range_parse ("npt=3.0-", &range) == GST_RTSP_OK);
173
174   /* the media is seekable now */
175   fail_unless (gst_rtsp_media_seek (media, range));
176
177   gst_rtsp_range_free (range);
178
179   fail_unless (gst_rtsp_media_unprepare (media));
180   g_object_unref (media);
181
182   gst_rtsp_url_free (url);
183   g_object_unref (factory);
184
185   g_object_unref (pool);
186
187   gst_rtsp_thread_pool_cleanup ();
188 }
189
190 GST_END_TEST;
191
192
193 GST_START_TEST (test_media_seek_no_sinks)
194 {
195   GstRTSPMediaFactory *factory;
196   GstRTSPMedia *media;
197   GstRTSPUrl *url;
198   GstRTSPStream *stream;
199   GstRTSPTimeRange *range;
200   gchar *str;
201   GstRTSPThreadPool *pool;
202   GstRTSPThread *thread;
203
204   factory = gst_rtsp_media_factory_new ();
205   fail_if (gst_rtsp_media_factory_is_shared (factory));
206   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
207           &url) == GST_RTSP_OK);
208
209   gst_rtsp_media_factory_set_launch (factory,
210       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
211
212   media = gst_rtsp_media_factory_construct (factory, url);
213   fail_unless (GST_IS_RTSP_MEDIA (media));
214
215   fail_unless (gst_rtsp_media_n_streams (media) == 1);
216
217   stream = gst_rtsp_media_get_stream (media, 0);
218   fail_unless (stream != NULL);
219
220   /* fails, need to be prepared */
221   str = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
222   fail_unless (str == NULL);
223
224   fail_unless (gst_rtsp_range_parse ("npt=5.0-", &range) == GST_RTSP_OK);
225   /* fails, need to be prepared */
226   fail_if (gst_rtsp_media_seek (media, range));
227
228   pool = gst_rtsp_thread_pool_new ();
229   thread = gst_rtsp_thread_pool_get_thread (pool,
230       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
231
232   fail_unless (gst_rtsp_media_prepare (media, thread));
233   fail_unless (media_has_sdp (media));
234
235   str = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
236   fail_unless (g_str_equal (str, "npt=0-"));
237   g_free (str);
238
239   str = gst_rtsp_media_get_range_string (media, TRUE, GST_RTSP_RANGE_NPT);
240   fail_unless (g_str_equal (str, "npt=0-"));
241   g_free (str);
242
243   /* fails, need to be prepared and contain sink elements */
244   fail_if (gst_rtsp_media_seek (media, range));
245
246   fail_unless (gst_rtsp_media_unprepare (media));
247
248   /* should fail again */
249   str = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
250   fail_unless (str == NULL);
251   fail_if (gst_rtsp_media_seek (media, range));
252
253   gst_rtsp_range_free (range);
254   g_object_unref (media);
255
256   gst_rtsp_url_free (url);
257   g_object_unref (factory);
258
259   g_object_unref (pool);
260
261   gst_rtsp_thread_pool_cleanup ();
262 }
263
264 GST_END_TEST;
265
266 GST_START_TEST (test_media)
267 {
268   GstRTSPMedia *media;
269   GstElement *bin, *e1, *e2;
270
271   bin = gst_bin_new ("bin");
272   fail_if (bin == NULL);
273
274   e1 = gst_element_factory_make ("videotestsrc", NULL);
275   fail_if (e1 == NULL);
276
277   e2 = gst_element_factory_make ("rtpvrawpay", "pay0");
278   fail_if (e2 == NULL);
279   g_object_set (e2, "pt", 96, NULL);
280
281   gst_bin_add_many (GST_BIN_CAST (bin), e1, e2, NULL);
282   gst_element_link_many (e1, e2, NULL);
283
284   media = gst_rtsp_media_new (bin);
285   fail_unless (GST_IS_RTSP_MEDIA (media));
286   g_object_unref (media);
287 }
288
289 GST_END_TEST;
290
291 static void
292 test_prepare_reusable (const gchar * launch_line, gboolean is_live)
293 {
294   GstRTSPMediaFactory *factory;
295   GstRTSPMedia *media;
296   GstRTSPUrl *url;
297   GstRTSPThread *thread;
298   GstRTSPThreadPool *pool;
299
300   factory = gst_rtsp_media_factory_new ();
301   fail_if (gst_rtsp_media_factory_is_shared (factory));
302   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
303           &url) == GST_RTSP_OK);
304
305   gst_rtsp_media_factory_set_launch (factory, launch_line);
306
307   media = gst_rtsp_media_factory_construct (factory, url);
308   fail_unless (GST_IS_RTSP_MEDIA (media));
309   fail_unless (gst_rtsp_media_n_streams (media) == 1);
310
311   g_object_set (G_OBJECT (media), "reusable", TRUE, NULL);
312
313   pool = gst_rtsp_thread_pool_new ();
314   thread = gst_rtsp_thread_pool_get_thread (pool,
315       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
316   fail_unless (gst_rtsp_media_prepare (media, thread));
317   fail_unless (media_has_sdp (media));
318   if (is_live) {                /* Live is not seekable */
319     fail_unless_equals_int64 (gst_rtsp_media_seekable (media), -1);
320   } else {
321     fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
322   }
323   fail_unless (gst_rtsp_media_unprepare (media));
324   fail_unless (gst_rtsp_media_n_streams (media) == 1);
325
326   thread = gst_rtsp_thread_pool_get_thread (pool,
327       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
328   fail_unless (gst_rtsp_media_prepare (media, thread));
329   fail_unless (media_has_sdp (media));
330   fail_unless (gst_rtsp_media_unprepare (media));
331
332   g_object_unref (media);
333   gst_rtsp_url_free (url);
334   g_object_unref (factory);
335
336   g_object_unref (pool);
337 }
338
339 GST_START_TEST (test_media_reusable)
340 {
341
342   /* test reusable media */
343   test_prepare_reusable ("( videotestsrc ! rtpvrawpay pt=96 name=pay0 )",
344       FALSE);
345   test_prepare_reusable
346       ("( videotestsrc is-live=true ! rtpvrawpay pt=96 name=pay0 )", TRUE);
347 }
348
349 GST_END_TEST;
350
351 GST_START_TEST (test_media_prepare)
352 {
353   GstRTSPMediaFactory *factory;
354   GstRTSPMedia *media;
355   GstRTSPUrl *url;
356   GstRTSPThreadPool *pool;
357   GstRTSPThread *thread;
358
359   pool = gst_rtsp_thread_pool_new ();
360
361   /* test non-reusable media first */
362   factory = gst_rtsp_media_factory_new ();
363   fail_if (gst_rtsp_media_factory_is_shared (factory));
364   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
365           &url) == GST_RTSP_OK);
366
367   gst_rtsp_media_factory_set_launch (factory,
368       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
369
370   media = gst_rtsp_media_factory_construct (factory, url);
371   fail_unless (GST_IS_RTSP_MEDIA (media));
372   fail_unless (gst_rtsp_media_n_streams (media) == 1);
373
374   thread = gst_rtsp_thread_pool_get_thread (pool,
375       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
376   fail_unless (gst_rtsp_media_prepare (media, thread));
377   fail_unless (media_has_sdp (media));
378   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
379   fail_unless (gst_rtsp_media_unprepare (media));
380   fail_unless (gst_rtsp_media_n_streams (media) == 1);
381
382   thread = gst_rtsp_thread_pool_get_thread (pool,
383       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
384   fail_if (gst_rtsp_media_prepare (media, thread));
385
386   g_object_unref (media);
387   gst_rtsp_url_free (url);
388   g_object_unref (factory);
389
390   g_object_unref (pool);
391   gst_rtsp_thread_pool_cleanup ();
392 }
393
394 GST_END_TEST;
395
396 #define FLAG_HAVE_CAPS GST_ELEMENT_FLAG_LAST
397 static void
398 on_notify_caps (GstPad * pad, GParamSpec * pspec, GstElement * pay)
399 {
400   GstCaps *caps;
401
402   g_object_get (pad, "caps", &caps, NULL);
403
404   GST_DEBUG ("notify %" GST_PTR_FORMAT, caps);
405
406   if (caps) {
407     if (!GST_OBJECT_FLAG_IS_SET (pay, FLAG_HAVE_CAPS)) {
408       g_signal_emit_by_name (pay, "pad-added", pad);
409       g_signal_emit_by_name (pay, "no-more-pads", NULL);
410       GST_OBJECT_FLAG_SET (pay, FLAG_HAVE_CAPS);
411     }
412     gst_caps_unref (caps);
413   } else {
414     if (GST_OBJECT_FLAG_IS_SET (pay, FLAG_HAVE_CAPS)) {
415       g_signal_emit_by_name (pay, "pad-removed", pad);
416       GST_OBJECT_FLAG_UNSET (pay, FLAG_HAVE_CAPS);
417     }
418   }
419 }
420
421 GST_START_TEST (test_media_dyn_prepare)
422 {
423   GstRTSPMedia *media;
424   GstElement *bin, *src, *pay;
425   GstElement *pipeline;
426   GstPad *srcpad;
427   GstRTSPThreadPool *pool;
428   GstRTSPThread *thread;
429
430   bin = gst_bin_new ("bin");
431   fail_if (bin == NULL);
432
433   src = gst_element_factory_make ("videotestsrc", NULL);
434   fail_if (src == NULL);
435
436   pay = gst_element_factory_make ("rtpvrawpay", "dynpay0");
437   fail_if (pay == NULL);
438   g_object_set (pay, "pt", 96, NULL);
439
440   gst_bin_add_many (GST_BIN_CAST (bin), src, pay, NULL);
441   gst_element_link_many (src, pay, NULL);
442
443   media = gst_rtsp_media_new (bin);
444   fail_unless (GST_IS_RTSP_MEDIA (media));
445
446   g_object_set (G_OBJECT (media), "reusable", TRUE, NULL);
447
448   pipeline = gst_pipeline_new ("media-pipeline");
449   gst_rtsp_media_take_pipeline (media, GST_PIPELINE_CAST (pipeline));
450
451   gst_rtsp_media_collect_streams (media);
452
453   srcpad = gst_element_get_static_pad (pay, "src");
454
455   g_signal_connect (srcpad, "notify::caps", (GCallback) on_notify_caps, pay);
456
457   pool = gst_rtsp_thread_pool_new ();
458
459   fail_unless (gst_rtsp_media_n_streams (media) == 0);
460
461   thread = gst_rtsp_thread_pool_get_thread (pool,
462       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
463   fail_unless (gst_rtsp_media_prepare (media, thread));
464   fail_unless (gst_rtsp_media_n_streams (media) == 1);
465   fail_unless (media_has_sdp (media));
466   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
467   fail_unless (gst_rtsp_media_unprepare (media));
468   fail_unless (gst_rtsp_media_n_streams (media) == 0);
469
470   thread = gst_rtsp_thread_pool_get_thread (pool,
471       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
472   fail_unless (gst_rtsp_media_prepare (media, thread));
473   fail_unless (gst_rtsp_media_n_streams (media) == 1);
474   fail_unless (media_has_sdp (media));
475   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
476   fail_unless (gst_rtsp_media_unprepare (media));
477   fail_unless (gst_rtsp_media_n_streams (media) == 0);
478
479   gst_object_unref (srcpad);
480   g_object_unref (media);
481   g_object_unref (pool);
482
483   gst_rtsp_thread_pool_cleanup ();
484 }
485
486 GST_END_TEST;
487
488 GST_START_TEST (test_media_take_pipeline)
489 {
490   GstRTSPMediaFactory *factory;
491   GstRTSPMedia *media;
492   GstRTSPUrl *url;
493   GstElement *pipeline;
494
495   factory = gst_rtsp_media_factory_new ();
496   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
497           &url) == GST_RTSP_OK);
498   gst_rtsp_media_factory_set_launch (factory,
499       "( fakesrc ! text/plain ! rtpgstpay name=pay0 )");
500
501   media = gst_rtsp_media_factory_construct (factory, url);
502   fail_unless (GST_IS_RTSP_MEDIA (media));
503
504   pipeline = gst_pipeline_new ("media-pipeline");
505   gst_rtsp_media_take_pipeline (media, GST_PIPELINE_CAST (pipeline));
506
507   g_object_unref (media);
508   gst_rtsp_url_free (url);
509   g_object_unref (factory);
510 }
511
512 GST_END_TEST;
513
514 GST_START_TEST (test_media_reset)
515 {
516   GstRTSPMediaFactory *factory;
517   GstRTSPMedia *media;
518   GstRTSPUrl *url;
519   GstRTSPThreadPool *pool;
520   GstRTSPThread *thread;
521
522   pool = gst_rtsp_thread_pool_new ();
523
524   factory = gst_rtsp_media_factory_new ();
525   fail_if (gst_rtsp_media_factory_is_shared (factory));
526   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
527
528   gst_rtsp_media_factory_set_launch (factory,
529       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
530
531   media = gst_rtsp_media_factory_construct (factory, url);
532   fail_unless (GST_IS_RTSP_MEDIA (media));
533
534   thread = gst_rtsp_thread_pool_get_thread (pool,
535       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
536   fail_unless (gst_rtsp_media_prepare (media, thread));
537   fail_unless (media_has_sdp (media));
538   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
539   fail_unless (gst_rtsp_media_suspend (media));
540   fail_unless (gst_rtsp_media_unprepare (media));
541   g_object_unref (media);
542
543   media = gst_rtsp_media_factory_construct (factory, url);
544   fail_unless (GST_IS_RTSP_MEDIA (media));
545
546   thread = gst_rtsp_thread_pool_get_thread (pool,
547       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
548   gst_rtsp_media_set_suspend_mode (media, GST_RTSP_SUSPEND_MODE_RESET);
549   fail_unless (gst_rtsp_media_prepare (media, thread));
550   fail_unless (media_has_sdp (media));
551   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
552   fail_unless (gst_rtsp_media_suspend (media));
553   fail_unless (gst_rtsp_media_unprepare (media));
554   g_object_unref (media);
555
556   gst_rtsp_url_free (url);
557   g_object_unref (factory);
558   g_object_unref (pool);
559
560   gst_rtsp_thread_pool_cleanup ();
561 }
562
563 GST_END_TEST;
564
565 GST_START_TEST (test_media_multidyn_prepare)
566 {
567   GstRTSPMedia *media;
568   GstElement *bin, *src0, *pay0, *src1, *pay1;
569   GstElement *pipeline;
570   GstPad *srcpad0, *srcpad1;
571   GstRTSPThreadPool *pool;
572   GstRTSPThread *thread;
573
574   bin = gst_bin_new ("bin");
575   fail_if (bin == NULL);
576
577   src0 = gst_element_factory_make ("videotestsrc", NULL);
578   fail_if (src0 == NULL);
579
580   pay0 = gst_element_factory_make ("rtpvrawpay", "dynpay0");
581   fail_if (pay0 == NULL);
582   g_object_set (pay0, "pt", 96, NULL);
583
584   src1 = gst_element_factory_make ("videotestsrc", NULL);
585   fail_if (src1 == NULL);
586
587   pay1 = gst_element_factory_make ("rtpvrawpay", "dynpay1");
588   fail_if (pay1 == NULL);
589   g_object_set (pay1, "pt", 97, NULL);
590
591   gst_bin_add_many (GST_BIN_CAST (bin), src0, pay0, src1, pay1, NULL);
592   gst_element_link_many (src0, pay0, NULL);
593   gst_element_link_many (src1, pay1, NULL);
594
595   media = gst_rtsp_media_new (bin);
596   fail_unless (GST_IS_RTSP_MEDIA (media));
597
598   g_object_set (G_OBJECT (media), "reusable", TRUE, NULL);
599
600   pipeline = gst_pipeline_new ("media-pipeline");
601   gst_rtsp_media_take_pipeline (media, GST_PIPELINE_CAST (pipeline));
602
603   gst_rtsp_media_collect_streams (media);
604
605   srcpad0 = gst_element_get_static_pad (pay0, "src");
606   srcpad1 = gst_element_get_static_pad (pay1, "src");
607
608   g_signal_connect (srcpad0, "notify::caps", (GCallback) on_notify_caps, pay0);
609   g_signal_connect (srcpad1, "notify::caps", (GCallback) on_notify_caps, pay1);
610
611   pool = gst_rtsp_thread_pool_new ();
612
613   fail_unless_equals_int (gst_rtsp_media_n_streams (media), 0);
614
615   thread = gst_rtsp_thread_pool_get_thread (pool,
616       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
617   fail_unless (gst_rtsp_media_prepare (media, thread));
618   fail_unless_equals_int (gst_rtsp_media_n_streams (media), 2);
619   fail_unless (media_has_sdp (media));
620   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
621   fail_unless (gst_rtsp_media_unprepare (media));
622   fail_unless_equals_int (gst_rtsp_media_n_streams (media), 0);
623
624   thread = gst_rtsp_thread_pool_get_thread (pool,
625       GST_RTSP_THREAD_TYPE_MEDIA, NULL);
626   fail_unless (gst_rtsp_media_prepare (media, thread));
627   fail_unless_equals_int (gst_rtsp_media_n_streams (media), 2);
628   fail_unless (media_has_sdp (media));
629   fail_unless_equals_int64 (gst_rtsp_media_seekable (media), G_MAXINT64);
630   fail_unless (gst_rtsp_media_unprepare (media));
631   fail_unless_equals_int (gst_rtsp_media_n_streams (media), 0);
632
633   gst_object_unref (srcpad0);
634   gst_object_unref (srcpad1);
635   g_object_unref (media);
636   g_object_unref (pool);
637
638   gst_rtsp_thread_pool_cleanup ();
639 }
640
641 GST_END_TEST;
642
643
644 static Suite *
645 rtspmedia_suite (void)
646 {
647   Suite *s = suite_create ("rtspmedia");
648   TCase *tc = tcase_create ("general");
649
650   suite_add_tcase (s, tc);
651   tcase_set_timeout (tc, 20);
652   tcase_add_test (tc, test_media_seek);
653   tcase_add_test (tc, test_media_seek_no_sinks);
654   tcase_add_test (tc, test_media_seek_one_active_stream);
655   tcase_add_test (tc, test_media);
656   tcase_add_test (tc, test_media_prepare);
657   tcase_add_test (tc, test_media_reusable);
658   tcase_add_test (tc, test_media_dyn_prepare);
659   tcase_add_test (tc, test_media_take_pipeline);
660   tcase_add_test (tc, test_media_reset);
661   tcase_add_test (tc, test_media_multidyn_prepare);
662
663   return s;
664 }
665
666 GST_CHECK_MAIN (rtspmedia);