tests: Check gst_rtsp_url_parse return value
[platform/upstream/gstreamer.git] / tests / check / gst / rtspserver.c
1 /* GStreamer
2  *
3  * unit test for GstRTSPServer
4  *
5  * Copyright (C) 2012 Axis Communications <dev-gstreamer at axis dot com>
6  * @author David Svensson Fors <davidsf at axis dot com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #include <gst/check/gstcheck.h>
25 #include <gst/sdp/gstsdpmessage.h>
26 #include <gst/rtp/gstrtpbuffer.h>
27 #include <gst/rtp/gstrtcpbuffer.h>
28
29 #include <stdio.h>
30 #include <netinet/in.h>
31
32 #include "rtsp-server.h"
33
34 #define VIDEO_PIPELINE "videotestsrc ! " \
35   "video/x-raw,width=352,height=288 ! " \
36   "rtpgstpay name=pay0 pt=96"
37 #define AUDIO_PIPELINE "audiotestsrc ! " \
38   "audio/x-raw,rate=8000 ! " \
39   "rtpgstpay name=pay1 pt=97"
40
41 #define TEST_MOUNT_POINT  "/test"
42 #define TEST_PROTO        "RTP/AVP"
43 #define TEST_ENCODING     "X-GST"
44 #define TEST_CLOCK_RATE   "90000"
45
46 /* tested rtsp server */
47 static GstRTSPServer *server = NULL;
48
49 /* tcp port that the test server listens for rtsp requests on */
50 static gint test_port = 0;
51
52 /* id of the server's source within the GMainContext */
53 static guint source_id;
54
55 /* iterate the default main loop until there are no events to dispatch */
56 static void
57 iterate (void)
58 {
59   while (g_main_context_iteration (NULL, FALSE)) {
60     GST_DEBUG ("iteration");
61   }
62 }
63
64 static void
65 get_client_ports_full (GstRTSPRange * range, GSocket ** rtp_socket,
66     GSocket ** rtcp_socket)
67 {
68   GSocket *rtp = NULL;
69   GSocket *rtcp = NULL;
70   gint rtp_port = 0;
71   gint rtcp_port;
72   GInetAddress *anyaddr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
73   GSocketAddress *sockaddr;
74   gboolean bound;
75
76   for (;;) {
77     if (rtp_port != 0)
78       rtp_port += 2;
79
80     rtp = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
81         G_SOCKET_PROTOCOL_UDP, NULL);
82     fail_unless (rtp != NULL);
83
84     sockaddr = g_inet_socket_address_new (anyaddr, rtp_port);
85     fail_unless (sockaddr != NULL);
86     bound = g_socket_bind (rtp, sockaddr, FALSE, NULL);
87     g_object_unref (sockaddr);
88     if (!bound) {
89       g_object_unref (rtp);
90       continue;
91     }
92
93     sockaddr = g_socket_get_local_address (rtp, NULL);
94     fail_unless (sockaddr != NULL && G_IS_INET_SOCKET_ADDRESS (sockaddr));
95     rtp_port =
96         g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (sockaddr));
97     g_object_unref (sockaddr);
98
99     if (rtp_port % 2 != 0) {
100       rtp_port += 1;
101       g_object_unref (rtp);
102       continue;
103     }
104
105     rtcp_port = rtp_port + 1;
106
107     rtcp = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
108         G_SOCKET_PROTOCOL_UDP, NULL);
109     fail_unless (rtcp != NULL);
110
111     sockaddr = g_inet_socket_address_new (anyaddr, rtcp_port);
112     fail_unless (sockaddr != NULL);
113     bound = g_socket_bind (rtcp, sockaddr, FALSE, NULL);
114     g_object_unref (sockaddr);
115     if (!bound) {
116       g_object_unref (rtp);
117       g_object_unref (rtcp);
118       continue;
119     }
120
121     sockaddr = g_socket_get_local_address (rtcp, NULL);
122     fail_unless (sockaddr != NULL && G_IS_INET_SOCKET_ADDRESS (sockaddr));
123     fail_unless (rtcp_port ==
124         g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (sockaddr)));
125     g_object_unref (sockaddr);
126
127     break;
128   }
129
130   range->min = rtp_port;
131   range->max = rtcp_port;
132   if (rtp_socket)
133     *rtp_socket = rtp;
134   else
135     g_object_unref (rtp);
136   if (rtcp_socket)
137     *rtcp_socket = rtcp;
138   else
139     g_object_unref (rtcp);
140   GST_DEBUG ("client_port=%d-%d", range->min, range->max);
141   g_object_unref (anyaddr);
142 }
143
144 /* get a free rtp/rtcp client port pair */
145 static void
146 get_client_ports (GstRTSPRange * range)
147 {
148   get_client_ports_full (range, NULL, NULL);
149 }
150
151 /* start the tested rtsp server */
152 static void
153 start_server (void)
154 {
155   GstRTSPMountPoints *mounts;
156   gchar *service;
157   GstRTSPMediaFactory *factory;
158
159   mounts = gst_rtsp_server_get_mount_points (server);
160
161   factory = gst_rtsp_media_factory_new ();
162
163   gst_rtsp_media_factory_set_launch (factory,
164       "( " VIDEO_PIPELINE "  " AUDIO_PIPELINE " )");
165   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT, factory);
166   g_object_unref (mounts);
167
168   /* set port to any */
169   gst_rtsp_server_set_service (server, "0");
170
171   /* attach to default main context */
172   source_id = gst_rtsp_server_attach (server, NULL);
173   fail_if (source_id == 0);
174
175   /* get port */
176   service = gst_rtsp_server_get_service (server);
177   test_port = atoi (service);
178   fail_unless (test_port != 0);
179   g_free (service);
180
181   GST_DEBUG ("rtsp server listening on port %d", test_port);
182 }
183
184 /* stop the tested rtsp server */
185 static void
186 stop_server ()
187 {
188   g_source_remove (source_id);
189   source_id = 0;
190
191   GST_DEBUG ("rtsp server stopped");
192 }
193
194 /* create an rtsp connection to the server on test_port */
195 static GstRTSPConnection *
196 connect_to_server (gint port, const gchar * mount_point)
197 {
198   GstRTSPConnection *conn = NULL;
199   gchar *address;
200   gchar *uri_string;
201   GstRTSPUrl *url = NULL;
202
203   address = gst_rtsp_server_get_address (server);
204   uri_string = g_strdup_printf ("rtsp://%s:%d%s", address, port, mount_point);
205   g_free (address);
206   fail_unless (gst_rtsp_url_parse (uri_string, &url) == GST_RTSP_OK);
207   g_free (uri_string);
208
209   fail_unless (gst_rtsp_connection_create (url, &conn) == GST_RTSP_OK);
210   gst_rtsp_url_free (url);
211
212   fail_unless (gst_rtsp_connection_connect (conn, NULL) == GST_RTSP_OK);
213
214   return conn;
215 }
216
217 /* create an rtsp request */
218 static GstRTSPMessage *
219 create_request (GstRTSPConnection * conn, GstRTSPMethod method,
220     const gchar * control)
221 {
222   GstRTSPMessage *request = NULL;
223   gchar *base_uri;
224   gchar *full_uri;
225
226   base_uri = gst_rtsp_url_get_request_uri (gst_rtsp_connection_get_url (conn));
227   full_uri = g_strdup_printf ("%s/%s", base_uri, control ? control : "");
228   g_free (base_uri);
229   if (gst_rtsp_message_new_request (&request, method, full_uri) != GST_RTSP_OK) {
230     GST_DEBUG ("failed to create request object");
231     g_free (full_uri);
232     return NULL;
233   }
234   g_free (full_uri);
235   return request;
236 }
237
238 /* send an rtsp request */
239 static gboolean
240 send_request (GstRTSPConnection * conn, GstRTSPMessage * request)
241 {
242   if (gst_rtsp_connection_send (conn, request, NULL) != GST_RTSP_OK) {
243     GST_DEBUG ("failed to send request");
244     return FALSE;
245   }
246   return TRUE;
247 }
248
249 /* read rtsp response. response must be freed by the caller */
250 static GstRTSPMessage *
251 read_response (GstRTSPConnection * conn)
252 {
253   GstRTSPMessage *response = NULL;
254
255   if (gst_rtsp_message_new (&response) != GST_RTSP_OK) {
256     GST_DEBUG ("failed to create response object");
257     return NULL;
258   }
259   if (gst_rtsp_connection_receive (conn, response, NULL) != GST_RTSP_OK) {
260     GST_DEBUG ("failed to read response");
261     gst_rtsp_message_free (response);
262     return NULL;
263   }
264   fail_unless (gst_rtsp_message_get_type (response) ==
265       GST_RTSP_MESSAGE_RESPONSE);
266   return response;
267 }
268
269 /* send an rtsp request and receive response. gchar** parameters are out
270  * parameters that have to be freed by the caller */
271 static GstRTSPStatusCode
272 do_request (GstRTSPConnection * conn, GstRTSPMethod method,
273     const gchar * control, const gchar * session_in, const gchar * transport_in,
274     const gchar * range_in,
275     gchar ** content_type, gchar ** content_base, gchar ** body,
276     gchar ** session_out, gchar ** transport_out, gchar ** range_out)
277 {
278   GstRTSPMessage *request;
279   GstRTSPMessage *response;
280   GstRTSPStatusCode code;
281   gchar *value;
282
283   /* create request */
284   request = create_request (conn, method, control);
285
286   /* add headers */
287   if (session_in) {
288     gst_rtsp_message_add_header (request, GST_RTSP_HDR_SESSION, session_in);
289   }
290   if (transport_in) {
291     gst_rtsp_message_add_header (request, GST_RTSP_HDR_TRANSPORT, transport_in);
292   }
293   if (range_in) {
294     gst_rtsp_message_add_header (request, GST_RTSP_HDR_RANGE, range_in);
295   }
296
297   /* send request */
298   fail_unless (send_request (conn, request));
299   gst_rtsp_message_free (request);
300
301   iterate ();
302
303   /* read response */
304   response = read_response (conn);
305
306   /* check status line */
307   gst_rtsp_message_parse_response (response, &code, NULL, NULL);
308   if (code != GST_RTSP_STS_OK) {
309     gst_rtsp_message_free (response);
310     return code;
311   }
312
313   /* get information from response */
314   if (content_type) {
315     gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_TYPE,
316         &value, 0);
317     *content_type = g_strdup (value);
318   }
319   if (content_base) {
320     gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_BASE,
321         &value, 0);
322     *content_base = g_strdup (value);
323   }
324   if (body) {
325     *body = g_malloc (response->body_size + 1);
326     strncpy (*body, (gchar *) response->body, response->body_size);
327   }
328   if (session_out) {
329     gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION, &value, 0);
330
331     value = g_strdup (value);
332
333     /* Remove the timeout */
334     if (value) {
335       char *pos = strchr (value, ';');
336       if (pos)
337         *pos = 0;
338     }
339     if (session_in) {
340       /* check that we got the same session back */
341       fail_unless (!g_strcmp0 (value, session_in));
342     }
343     *session_out = value;
344   }
345   if (transport_out) {
346     gst_rtsp_message_get_header (response, GST_RTSP_HDR_TRANSPORT, &value, 0);
347     *transport_out = g_strdup (value);
348   }
349   if (range_out) {
350     gst_rtsp_message_get_header (response, GST_RTSP_HDR_RANGE, &value, 0);
351     *range_out = g_strdup (value);
352   }
353
354   gst_rtsp_message_free (response);
355   return code;
356 }
357
358 /* send an rtsp request with a method and a session, and receive response */
359 static GstRTSPStatusCode
360 do_simple_request (GstRTSPConnection * conn, GstRTSPMethod method,
361     const gchar * session)
362 {
363   return do_request (conn, method, NULL, session, NULL, NULL, NULL,
364       NULL, NULL, NULL, NULL, NULL);
365 }
366
367 /* send a DESCRIBE request and receive response. returns a received
368  * GstSDPMessage that must be freed by the caller */
369 static GstSDPMessage *
370 do_describe (GstRTSPConnection * conn, const gchar * mount_point)
371 {
372   GstSDPMessage *sdp_message;
373   gchar *content_type;
374   gchar *content_base;
375   gchar *body;
376   gchar *address;
377   gchar *expected_content_base;
378
379   /* send DESCRIBE request */
380   fail_unless (do_request (conn, GST_RTSP_DESCRIBE, NULL, NULL, NULL, NULL,
381           &content_type, &content_base, &body, NULL, NULL, NULL) ==
382       GST_RTSP_STS_OK);
383
384   /* check response values */
385   fail_unless (!g_strcmp0 (content_type, "application/sdp"));
386   address = gst_rtsp_server_get_address (server);
387   expected_content_base =
388       g_strdup_printf ("rtsp://%s:%d%s/", address, test_port, mount_point);
389   fail_unless (!g_strcmp0 (content_base, expected_content_base));
390
391   /* create sdp message */
392   fail_unless (gst_sdp_message_new (&sdp_message) == GST_SDP_OK);
393   fail_unless (gst_sdp_message_parse_buffer ((guint8 *) body,
394           strlen (body), sdp_message) == GST_SDP_OK);
395
396   /* clean up */
397   g_free (content_type);
398   g_free (content_base);
399   g_free (body);
400   g_free (address);
401   g_free (expected_content_base);
402
403   return sdp_message;
404 }
405
406 /* send a SETUP request and receive response. if *session is not NULL,
407  * it is used in the request. otherwise, *session is set to a returned
408  * session string that must be freed by the caller. the returned
409  * transport must be freed by the caller. */
410 static GstRTSPStatusCode
411 do_setup (GstRTSPConnection * conn, const gchar * control,
412     const GstRTSPRange * client_ports, gchar ** session,
413     GstRTSPTransport ** transport)
414 {
415   GstRTSPStatusCode code;
416   gchar *session_in = NULL;
417   gchar *transport_string_in = NULL;
418   gchar **session_out = NULL;
419   gchar *transport_string_out = NULL;
420
421   /* prepare and send SETUP request */
422   if (session) {
423     if (*session) {
424       session_in = *session;
425     } else {
426       session_out = session;
427     }
428   }
429   transport_string_in =
430       g_strdup_printf (TEST_PROTO ";unicast;client_port=%d-%d",
431       client_ports->min, client_ports->max);
432   code =
433       do_request (conn, GST_RTSP_SETUP, control, session_in,
434       transport_string_in, NULL, NULL, NULL, NULL, session_out,
435       &transport_string_out, NULL);
436   g_free (transport_string_in);
437
438   if (transport_string_out) {
439     /* create transport */
440     fail_unless (gst_rtsp_transport_new (transport) == GST_RTSP_OK);
441     fail_unless (gst_rtsp_transport_parse (transport_string_out,
442             *transport) == GST_RTSP_OK);
443     g_free (transport_string_out);
444   }
445
446   return code;
447 }
448
449 /* fixture setup function */
450 static void
451 setup (void)
452 {
453   server = gst_rtsp_server_new ();
454 }
455
456 /* fixture clean-up function */
457 static void
458 teardown (void)
459 {
460   if (server) {
461     g_object_unref (server);
462     server = NULL;
463   }
464   test_port = 0;
465 }
466
467 GST_START_TEST (test_connect)
468 {
469   GstRTSPConnection *conn;
470
471   start_server ();
472
473   /* connect to server */
474   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
475
476   /* clean up */
477   gst_rtsp_connection_free (conn);
478   stop_server ();
479
480   /* iterate so the clean-up can finish */
481   iterate ();
482 }
483
484 GST_END_TEST;
485
486 GST_START_TEST (test_describe)
487 {
488   GstRTSPConnection *conn;
489   GstSDPMessage *sdp_message = NULL;
490   const GstSDPMedia *sdp_media;
491   gint32 format;
492   gchar *expected_rtpmap;
493   const gchar *rtpmap;
494   const gchar *control_video;
495   const gchar *control_audio;
496
497   start_server ();
498
499   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
500
501   /* send DESCRIBE request */
502   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
503
504   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
505
506   /* check video sdp */
507   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
508   fail_unless (!g_strcmp0 (gst_sdp_media_get_proto (sdp_media), TEST_PROTO));
509   fail_unless (gst_sdp_media_formats_len (sdp_media) == 1);
510   sscanf (gst_sdp_media_get_format (sdp_media, 0), "%" G_GINT32_FORMAT,
511       &format);
512   expected_rtpmap =
513       g_strdup_printf ("%d " TEST_ENCODING "/" TEST_CLOCK_RATE, format);
514   rtpmap = gst_sdp_media_get_attribute_val (sdp_media, "rtpmap");
515   fail_unless (!g_strcmp0 (rtpmap, expected_rtpmap));
516   g_free (expected_rtpmap);
517   control_video = gst_sdp_media_get_attribute_val (sdp_media, "control");
518   fail_unless (!g_strcmp0 (control_video, "stream=0"));
519
520   /* check audio sdp */
521   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
522   fail_unless (!g_strcmp0 (gst_sdp_media_get_proto (sdp_media), TEST_PROTO));
523   fail_unless (gst_sdp_media_formats_len (sdp_media) == 1);
524   sscanf (gst_sdp_media_get_format (sdp_media, 0), "%" G_GINT32_FORMAT,
525       &format);
526   expected_rtpmap =
527       g_strdup_printf ("%d " TEST_ENCODING "/" TEST_CLOCK_RATE, format);
528   rtpmap = gst_sdp_media_get_attribute_val (sdp_media, "rtpmap");
529   fail_unless (!g_strcmp0 (rtpmap, expected_rtpmap));
530   g_free (expected_rtpmap);
531   control_audio = gst_sdp_media_get_attribute_val (sdp_media, "control");
532   fail_unless (!g_strcmp0 (control_audio, "stream=1"));
533
534   /* clean up and iterate so the clean-up can finish */
535   gst_sdp_message_free (sdp_message);
536   gst_rtsp_connection_free (conn);
537   stop_server ();
538   iterate ();
539 }
540
541 GST_END_TEST;
542
543 GST_START_TEST (test_describe_non_existing_mount_point)
544 {
545   GstRTSPConnection *conn;
546
547   start_server ();
548
549   /* send DESCRIBE request for a non-existing mount point
550    * and check that we get a 404 Not Found */
551   conn = connect_to_server (test_port, "/non-existing");
552   fail_unless (do_simple_request (conn, GST_RTSP_DESCRIBE, NULL)
553       == GST_RTSP_STS_NOT_FOUND);
554
555   /* clean up and iterate so the clean-up can finish */
556   gst_rtsp_connection_free (conn);
557   stop_server ();
558   iterate ();
559 }
560
561 GST_END_TEST;
562
563 GST_START_TEST (test_setup)
564 {
565   GstRTSPConnection *conn;
566   GstSDPMessage *sdp_message = NULL;
567   const GstSDPMedia *sdp_media;
568   const gchar *video_control;
569   const gchar *audio_control;
570   GstRTSPRange client_ports;
571   gchar *session = NULL;
572   GstRTSPTransport *video_transport = NULL;
573   GstRTSPTransport *audio_transport = NULL;
574
575   start_server ();
576
577   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
578
579   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
580
581   /* get control strings from DESCRIBE response */
582   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
583   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
584   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
585   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
586   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
587
588   get_client_ports (&client_ports);
589
590   /* send SETUP request for video */
591   fail_unless (do_setup (conn, video_control, &client_ports, &session,
592           &video_transport) == GST_RTSP_STS_OK);
593   GST_DEBUG ("set up video %s, got session '%s'", video_control, session);
594
595   /* check response from SETUP */
596   fail_unless (video_transport->trans == GST_RTSP_TRANS_RTP);
597   fail_unless (video_transport->profile == GST_RTSP_PROFILE_AVP);
598   fail_unless (video_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP);
599   fail_unless (video_transport->mode_play);
600   gst_rtsp_transport_free (video_transport);
601
602   /* send SETUP request for audio */
603   fail_unless (do_setup (conn, audio_control, &client_ports, &session,
604           &audio_transport) == GST_RTSP_STS_OK);
605   GST_DEBUG ("set up audio %s with session '%s'", audio_control, session);
606
607   /* check response from SETUP */
608   fail_unless (audio_transport->trans == GST_RTSP_TRANS_RTP);
609   fail_unless (audio_transport->profile == GST_RTSP_PROFILE_AVP);
610   fail_unless (audio_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP);
611   fail_unless (audio_transport->mode_play);
612   gst_rtsp_transport_free (audio_transport);
613
614   /* clean up and iterate so the clean-up can finish */
615   g_free (session);
616   gst_sdp_message_free (sdp_message);
617   gst_rtsp_connection_free (conn);
618   stop_server ();
619   iterate ();
620 }
621
622 GST_END_TEST;
623
624 GST_START_TEST (test_setup_non_existing_stream)
625 {
626   GstRTSPConnection *conn;
627   GstRTSPRange client_ports;
628
629   start_server ();
630
631   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
632
633   get_client_ports (&client_ports);
634
635   /* send SETUP request with a non-existing stream and check that we get a
636    * 404 Not Found */
637   fail_unless (do_setup (conn, "stream=7", &client_ports, NULL,
638           NULL) == GST_RTSP_STS_NOT_FOUND);
639
640   /* clean up and iterate so the clean-up can finish */
641   gst_rtsp_connection_free (conn);
642   stop_server ();
643   iterate ();
644 }
645
646 GST_END_TEST;
647
648 static void
649 receive_rtp (GSocket * socket, GSocketAddress ** addr)
650 {
651   GstBuffer *buffer = gst_buffer_new_allocate (NULL, 65536, NULL);
652
653   for (;;) {
654     gssize bytes;
655     GstMapInfo map = GST_MAP_INFO_INIT;
656     GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
657
658     gst_buffer_map (buffer, &map, GST_MAP_WRITE);
659     bytes = g_socket_receive_from (socket, addr, (gchar *) map.data,
660         map.maxsize, NULL, NULL);
661     fail_unless (bytes > 0);
662     gst_buffer_unmap (buffer, &map);
663     gst_buffer_set_size (buffer, bytes);
664
665     if (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtpbuffer)) {
666       gst_rtp_buffer_unmap (&rtpbuffer);
667       break;
668     }
669
670     if (addr)
671       g_clear_object (addr);
672   }
673
674   gst_buffer_unref (buffer);
675 }
676
677 static void
678 receive_rtcp (GSocket * socket, GSocketAddress ** addr, GstRTCPType type)
679 {
680   GstBuffer *buffer = gst_buffer_new_allocate (NULL, 65536, NULL);
681
682   for (;;) {
683     gssize bytes;
684     GstMapInfo map = GST_MAP_INFO_INIT;
685
686     gst_buffer_map (buffer, &map, GST_MAP_WRITE);
687     bytes = g_socket_receive_from (socket, addr, (gchar *) map.data,
688         map.maxsize, NULL, NULL);
689     fail_unless (bytes > 0);
690     gst_buffer_unmap (buffer, &map);
691     gst_buffer_set_size (buffer, bytes);
692
693     if (gst_rtcp_buffer_validate (buffer)) {
694       GstRTCPBuffer rtcpbuffer = GST_RTCP_BUFFER_INIT;
695       GstRTCPPacket packet;
696
697       if (type) {
698         fail_unless (gst_rtcp_buffer_map (buffer, GST_MAP_READ, &rtcpbuffer));
699         fail_unless (gst_rtcp_buffer_get_first_packet (&rtcpbuffer, &packet));
700         do {
701           if (gst_rtcp_packet_get_type (&packet) == type) {
702             gst_rtcp_buffer_unmap (&rtcpbuffer);
703             goto done;
704           }
705         } while (gst_rtcp_packet_move_to_next (&packet));
706         gst_rtcp_buffer_unmap (&rtcpbuffer);
707       } else {
708         break;
709       }
710     }
711
712     if (addr)
713       g_clear_object (addr);
714   }
715
716 done:
717
718   gst_buffer_unref (buffer);
719 }
720
721 static void
722 do_test_play (const gchar * range)
723 {
724   GstRTSPConnection *conn;
725   GstSDPMessage *sdp_message = NULL;
726   const GstSDPMedia *sdp_media;
727   const gchar *video_control;
728   const gchar *audio_control;
729   GstRTSPRange client_port;
730   gchar *session = NULL;
731   GstRTSPTransport *video_transport = NULL;
732   GstRTSPTransport *audio_transport = NULL;
733   GSocket *rtp_socket, *rtcp_socket;
734   gchar *range_out = NULL;
735
736   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
737
738   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
739
740   /* get control strings from DESCRIBE response */
741   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
742   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
743   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
744   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
745   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
746
747   get_client_ports_full (&client_port, &rtp_socket, &rtcp_socket);
748
749   /* do SETUP for video and audio */
750   fail_unless (do_setup (conn, video_control, &client_port, &session,
751           &video_transport) == GST_RTSP_STS_OK);
752   fail_unless (do_setup (conn, audio_control, &client_port, &session,
753           &audio_transport) == GST_RTSP_STS_OK);
754
755   /* send PLAY request and check that we get 200 OK */
756   fail_unless (do_request (conn, GST_RTSP_PLAY, NULL, session, NULL, range,
757           NULL, NULL, NULL, NULL, NULL, &range_out) == GST_RTSP_STS_OK);
758   if (range)
759     fail_unless_equals_string (range, range_out);
760   g_free (range_out);
761
762   receive_rtp (rtp_socket, NULL);
763   receive_rtcp (rtcp_socket, NULL, 0);
764
765   /* send TEARDOWN request and check that we get 200 OK */
766   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
767           session) == GST_RTSP_STS_OK);
768
769   /* FIXME: The rtsp-server always disconnects the transport before
770    * sending the RTCP BYE
771    * receive_rtcp (rtcp_socket, NULL, GST_RTCP_TYPE_BYE);
772    */
773
774   /* clean up and iterate so the clean-up can finish */
775   g_object_unref (rtp_socket);
776   g_object_unref (rtcp_socket);
777   g_free (session);
778   gst_rtsp_transport_free (video_transport);
779   gst_rtsp_transport_free (audio_transport);
780   gst_sdp_message_free (sdp_message);
781   gst_rtsp_connection_free (conn);
782 }
783
784
785 GST_START_TEST (test_play)
786 {
787   start_server ();
788
789   do_test_play (NULL);
790
791   stop_server ();
792   iterate ();
793 }
794
795 GST_END_TEST;
796
797 GST_START_TEST (test_play_without_session)
798 {
799   GstRTSPConnection *conn;
800
801   start_server ();
802
803   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
804
805   /* send PLAY request without a session and check that we get a
806    * 454 Session Not Found */
807   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
808           NULL) == GST_RTSP_STS_SESSION_NOT_FOUND);
809
810   /* clean up and iterate so the clean-up can finish */
811   gst_rtsp_connection_free (conn);
812   stop_server ();
813   iterate ();
814 }
815
816 GST_END_TEST;
817
818 GST_START_TEST (test_bind_already_in_use)
819 {
820   GstRTSPServer *serv;
821   GSocketService *service;
822   GError *error = NULL;
823   guint16 port;
824   gchar *port_str;
825
826   serv = gst_rtsp_server_new ();
827   service = g_socket_service_new ();
828
829   /* bind service to port */
830   port =
831       g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL,
832       &error);
833   g_assert_no_error (error);
834
835   port_str = g_strdup_printf ("%d\n", port);
836
837   /* try to bind server to the same port */
838   g_object_set (serv, "service", port_str, NULL);
839   g_free (port_str);
840
841   /* attach to default main context */
842   fail_unless (gst_rtsp_server_attach (serv, NULL) == 0);
843
844   /* cleanup */
845   g_object_unref (serv);
846   g_socket_service_stop (service);
847   g_object_unref (service);
848 }
849
850 GST_END_TEST;
851
852
853 GST_START_TEST (test_play_multithreaded)
854 {
855   GstRTSPThreadPool *pool;
856
857   pool = gst_rtsp_server_get_thread_pool (server);
858   gst_rtsp_thread_pool_set_max_threads (pool, 2);
859   g_object_unref (pool);
860
861   start_server ();
862
863   do_test_play (NULL);
864
865   stop_server ();
866   iterate ();
867 }
868
869 GST_END_TEST;
870
871 enum
872 {
873   BLOCK_ME,
874   BLOCKED,
875   UNBLOCK
876 };
877
878
879 static void
880 media_constructed_block (GstRTSPMediaFactory * factory,
881     GstRTSPMedia * media, gpointer user_data)
882 {
883   gint *block_state = user_data;
884
885   g_mutex_lock (&check_mutex);
886
887   *block_state = BLOCKED;
888   g_cond_broadcast (&check_cond);
889
890   while (*block_state != UNBLOCK)
891     g_cond_wait (&check_cond, &check_mutex);
892   g_mutex_unlock (&check_mutex);
893 }
894
895
896 GST_START_TEST (test_play_multithreaded_block_in_describe)
897 {
898   GstRTSPConnection *conn;
899   GstRTSPMountPoints *mounts;
900   GstRTSPMediaFactory *factory;
901   gint block_state = BLOCK_ME;
902   GstRTSPMessage *request;
903   GstRTSPMessage *response;
904   GstRTSPStatusCode code;
905   GstRTSPThreadPool *pool;
906
907   pool = gst_rtsp_server_get_thread_pool (server);
908   gst_rtsp_thread_pool_set_max_threads (pool, 2);
909   g_object_unref (pool);
910
911   mounts = gst_rtsp_server_get_mount_points (server);
912   fail_unless (mounts != NULL);
913   factory = gst_rtsp_media_factory_new ();
914   gst_rtsp_media_factory_set_launch (factory,
915       "( " VIDEO_PIPELINE "  " AUDIO_PIPELINE " )");
916   g_signal_connect (factory, "media-constructed",
917       G_CALLBACK (media_constructed_block), &block_state);
918   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT "2", factory);
919   g_object_unref (mounts);
920
921   start_server ();
922
923   conn = connect_to_server (test_port, TEST_MOUNT_POINT "2");
924   iterate ();
925
926   /* do describe, it will not return now as we've blocked it */
927   request = create_request (conn, GST_RTSP_DESCRIBE, NULL);
928   fail_unless (send_request (conn, request));
929   gst_rtsp_message_free (request);
930
931   g_mutex_lock (&check_mutex);
932   while (block_state != BLOCKED)
933     g_cond_wait (&check_cond, &check_mutex);
934   g_mutex_unlock (&check_mutex);
935
936   /* Do a second connection while the first one is blocked */
937   do_test_play (NULL);
938
939   /* Now unblock the describe */
940   g_mutex_lock (&check_mutex);
941   block_state = UNBLOCK;
942   g_cond_broadcast (&check_cond);
943   g_mutex_unlock (&check_mutex);
944
945   response = read_response (conn);
946   gst_rtsp_message_parse_response (response, &code, NULL, NULL);
947   fail_unless (code == GST_RTSP_STS_OK);
948   gst_rtsp_message_free (response);
949
950
951   gst_rtsp_connection_free (conn);
952   stop_server ();
953   iterate ();
954
955 }
956
957 GST_END_TEST;
958
959
960 static void
961 new_session_timeout_one (GstRTSPClient * client,
962     GstRTSPSession * session, gpointer user_data)
963 {
964   gst_rtsp_session_set_timeout (session, 1);
965
966   g_signal_handlers_disconnect_by_func (client, new_session_timeout_one,
967       user_data);
968 }
969
970 static void
971 session_connected_new_session_cb (GstRTSPServer * server,
972     GstRTSPClient * client, gpointer user_data)
973 {
974
975   g_signal_connect (client, "new-session", user_data, NULL);
976 }
977
978 GST_START_TEST (test_play_multithreaded_timeout_client)
979 {
980   GstRTSPConnection *conn;
981   GstSDPMessage *sdp_message = NULL;
982   const GstSDPMedia *sdp_media;
983   const gchar *video_control;
984   const gchar *audio_control;
985   GstRTSPRange client_port;
986   gchar *session = NULL;
987   GstRTSPTransport *video_transport = NULL;
988   GstRTSPTransport *audio_transport = NULL;
989   GstRTSPSessionPool *pool;
990   GstRTSPThreadPool *thread_pool;
991
992   thread_pool = gst_rtsp_server_get_thread_pool (server);
993   gst_rtsp_thread_pool_set_max_threads (thread_pool, 2);
994   g_object_unref (thread_pool);
995
996   pool = gst_rtsp_server_get_session_pool (server);
997   g_signal_connect (server, "client-connected",
998       G_CALLBACK (session_connected_new_session_cb), new_session_timeout_one);
999
1000   start_server ();
1001
1002
1003   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1004
1005   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1006
1007   /* get control strings from DESCRIBE response */
1008   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1009   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1010   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1011   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1012   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1013
1014   get_client_ports (&client_port);
1015
1016   /* do SETUP for video and audio */
1017   fail_unless (do_setup (conn, video_control, &client_port, &session,
1018           &video_transport) == GST_RTSP_STS_OK);
1019   fail_unless (do_setup (conn, audio_control, &client_port, &session,
1020           &audio_transport) == GST_RTSP_STS_OK);
1021
1022   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 1);
1023
1024   /* send PLAY request and check that we get 200 OK */
1025   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1026           session) == GST_RTSP_STS_OK);
1027
1028   sleep (7);
1029
1030   fail_unless (gst_rtsp_session_pool_cleanup (pool) == 1);
1031   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 0);
1032
1033   /* clean up and iterate so the clean-up can finish */
1034   g_object_unref (pool);
1035   g_free (session);
1036   gst_rtsp_transport_free (video_transport);
1037   gst_rtsp_transport_free (audio_transport);
1038   gst_sdp_message_free (sdp_message);
1039   gst_rtsp_connection_free (conn);
1040
1041   stop_server ();
1042   iterate ();
1043 }
1044
1045 GST_END_TEST;
1046
1047
1048 GST_START_TEST (test_play_multithreaded_timeout_session)
1049 {
1050   GstRTSPConnection *conn;
1051   GstSDPMessage *sdp_message = NULL;
1052   const GstSDPMedia *sdp_media;
1053   const gchar *video_control;
1054   const gchar *audio_control;
1055   GstRTSPRange client_port;
1056   gchar *session1 = NULL;
1057   gchar *session2 = NULL;
1058   GstRTSPTransport *video_transport = NULL;
1059   GstRTSPTransport *audio_transport = NULL;
1060   GstRTSPSessionPool *pool;
1061   GstRTSPThreadPool *thread_pool;
1062
1063   thread_pool = gst_rtsp_server_get_thread_pool (server);
1064   gst_rtsp_thread_pool_set_max_threads (thread_pool, 2);
1065   g_object_unref (thread_pool);
1066
1067   pool = gst_rtsp_server_get_session_pool (server);
1068   g_signal_connect (server, "client-connected",
1069       G_CALLBACK (session_connected_new_session_cb), new_session_timeout_one);
1070
1071   start_server ();
1072
1073
1074   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1075
1076   gst_rtsp_connection_set_remember_session_id (conn, FALSE);
1077
1078   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1079
1080   /* get control strings from DESCRIBE response */
1081   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1082   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1083   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1084   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1085   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1086
1087   get_client_ports (&client_port);
1088
1089   /* do SETUP for video and audio */
1090   fail_unless (do_setup (conn, video_control, &client_port, &session1,
1091           &video_transport) == GST_RTSP_STS_OK);
1092   fail_unless (do_setup (conn, audio_control, &client_port, &session2,
1093           &audio_transport) == GST_RTSP_STS_OK);
1094
1095   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 2);
1096
1097   /* send PLAY request and check that we get 200 OK */
1098   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1099           session1) == GST_RTSP_STS_OK);
1100   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1101           session2) == GST_RTSP_STS_OK);
1102
1103   sleep (7);
1104
1105   fail_unless (gst_rtsp_session_pool_cleanup (pool) == 1);
1106
1107   /* send TEARDOWN request and check that we get 454 Session Not found */
1108   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1109           session1) == GST_RTSP_STS_SESSION_NOT_FOUND);
1110
1111   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1112           session2) == GST_RTSP_STS_OK);
1113
1114   /* clean up and iterate so the clean-up can finish */
1115   g_object_unref (pool);
1116   g_free (session1);
1117   g_free (session2);
1118   gst_rtsp_transport_free (video_transport);
1119   gst_rtsp_transport_free (audio_transport);
1120   gst_sdp_message_free (sdp_message);
1121   gst_rtsp_connection_free (conn);
1122
1123   stop_server ();
1124   iterate ();
1125 }
1126
1127 GST_END_TEST;
1128
1129
1130 GST_START_TEST (test_play_disconnect)
1131 {
1132   GstRTSPConnection *conn;
1133   GstSDPMessage *sdp_message = NULL;
1134   const GstSDPMedia *sdp_media;
1135   const gchar *video_control;
1136   const gchar *audio_control;
1137   GstRTSPRange client_port;
1138   gchar *session = NULL;
1139   GstRTSPTransport *video_transport = NULL;
1140   GstRTSPTransport *audio_transport = NULL;
1141   GstRTSPSessionPool *pool;
1142
1143   pool = gst_rtsp_server_get_session_pool (server);
1144   g_signal_connect (server, "client-connected",
1145       G_CALLBACK (session_connected_new_session_cb), new_session_timeout_one);
1146
1147   start_server ();
1148
1149   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1150
1151   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1152
1153   /* get control strings from DESCRIBE response */
1154   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1155   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1156   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1157   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1158   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1159
1160   get_client_ports (&client_port);
1161
1162   /* do SETUP for video and audio */
1163   fail_unless (do_setup (conn, video_control, &client_port, &session,
1164           &video_transport) == GST_RTSP_STS_OK);
1165   fail_unless (do_setup (conn, audio_control, &client_port, &session,
1166           &audio_transport) == GST_RTSP_STS_OK);
1167
1168   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 1);
1169
1170   /* send PLAY request and check that we get 200 OK */
1171   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1172           session) == GST_RTSP_STS_OK);
1173
1174   gst_rtsp_connection_free (conn);
1175
1176   sleep (7);
1177
1178   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 1);
1179   fail_unless (gst_rtsp_session_pool_cleanup (pool) == 1);
1180
1181
1182   /* clean up and iterate so the clean-up can finish */
1183   g_object_unref (pool);
1184   g_free (session);
1185   gst_rtsp_transport_free (video_transport);
1186   gst_rtsp_transport_free (audio_transport);
1187   gst_sdp_message_free (sdp_message);
1188
1189   stop_server ();
1190   iterate ();
1191 }
1192
1193 GST_END_TEST;
1194
1195 /* Only different with test_play is the specific ports selected */
1196
1197 GST_START_TEST (test_play_specific_server_port)
1198 {
1199   GstRTSPMountPoints *mounts;
1200   gchar *service;
1201   GstRTSPMediaFactory *factory;
1202   GstRTSPAddressPool *pool;
1203   GstRTSPConnection *conn;
1204   GstSDPMessage *sdp_message = NULL;
1205   const GstSDPMedia *sdp_media;
1206   const gchar *video_control;
1207   GstRTSPRange client_port;
1208   gchar *session = NULL;
1209   GstRTSPTransport *video_transport = NULL;
1210   GSocket *rtp_socket, *rtcp_socket;
1211   GSocketAddress *rtp_address, *rtcp_address;
1212   guint16 rtp_port, rtcp_port;
1213
1214   mounts = gst_rtsp_server_get_mount_points (server);
1215
1216   factory = gst_rtsp_media_factory_new ();
1217   pool = gst_rtsp_address_pool_new ();
1218   gst_rtsp_address_pool_add_range (pool, GST_RTSP_ADDRESS_POOL_ANY_IPV4,
1219       GST_RTSP_ADDRESS_POOL_ANY_IPV4, 7770, 7780, 0);
1220   gst_rtsp_media_factory_set_address_pool (factory, pool);
1221   g_object_unref (pool);
1222   gst_rtsp_media_factory_set_launch (factory, "( " VIDEO_PIPELINE " )");
1223   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT, factory);
1224   g_object_unref (mounts);
1225
1226   /* set port to any */
1227   gst_rtsp_server_set_service (server, "0");
1228
1229   /* attach to default main context */
1230   source_id = gst_rtsp_server_attach (server, NULL);
1231   fail_if (source_id == 0);
1232
1233   /* get port */
1234   service = gst_rtsp_server_get_service (server);
1235   test_port = atoi (service);
1236   fail_unless (test_port != 0);
1237   g_free (service);
1238
1239   GST_DEBUG ("rtsp server listening on port %d", test_port);
1240
1241
1242   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1243
1244   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1245
1246   /* get control strings from DESCRIBE response */
1247   fail_unless (gst_sdp_message_medias_len (sdp_message) == 1);
1248   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1249   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1250
1251   get_client_ports_full (&client_port, &rtp_socket, &rtcp_socket);
1252
1253   /* do SETUP for video */
1254   fail_unless (do_setup (conn, video_control, &client_port, &session,
1255           &video_transport) == GST_RTSP_STS_OK);
1256
1257   /* send PLAY request and check that we get 200 OK */
1258   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1259           session) == GST_RTSP_STS_OK);
1260
1261   receive_rtp (rtp_socket, &rtp_address);
1262   receive_rtcp (rtcp_socket, &rtcp_address, 0);
1263
1264   fail_unless (G_IS_INET_SOCKET_ADDRESS (rtp_address));
1265   fail_unless (G_IS_INET_SOCKET_ADDRESS (rtcp_address));
1266   rtp_port =
1267       g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtp_address));
1268   rtcp_port =
1269       g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtcp_address));
1270   fail_unless (rtp_port >= 7770 && rtp_port <= 7780 && rtp_port % 2 == 0);
1271   fail_unless (rtcp_port >= 7770 && rtcp_port <= 7780 && rtcp_port % 2 == 1);
1272   fail_unless (rtp_port + 1 == rtcp_port);
1273
1274   g_object_unref (rtp_address);
1275   g_object_unref (rtcp_address);
1276
1277   /* send TEARDOWN request and check that we get 200 OK */
1278   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1279           session) == GST_RTSP_STS_OK);
1280
1281   /* FIXME: The rtsp-server always disconnects the transport before
1282    * sending the RTCP BYE
1283    * receive_rtcp (rtcp_socket, NULL, GST_RTCP_TYPE_BYE);
1284    */
1285
1286   /* clean up and iterate so the clean-up can finish */
1287   g_object_unref (rtp_socket);
1288   g_object_unref (rtcp_socket);
1289   g_free (session);
1290   gst_rtsp_transport_free (video_transport);
1291   gst_sdp_message_free (sdp_message);
1292   gst_rtsp_connection_free (conn);
1293
1294
1295   stop_server ();
1296   iterate ();
1297 }
1298
1299 GST_END_TEST;
1300
1301
1302 GST_START_TEST (test_play_smpte_range)
1303 {
1304   start_server ();
1305
1306   do_test_play ("npt=5-");
1307   do_test_play ("smpte=0:00:00-");
1308   do_test_play ("smpte=1:00:00-");
1309   do_test_play ("smpte=1:00:03-");
1310   do_test_play ("clock=20120321T152256Z-");
1311
1312   stop_server ();
1313   iterate ();
1314 }
1315
1316 GST_END_TEST;
1317
1318
1319 static Suite *
1320 rtspserver_suite (void)
1321 {
1322   Suite *s = suite_create ("rtspserver");
1323   TCase *tc = tcase_create ("general");
1324
1325   suite_add_tcase (s, tc);
1326   tcase_add_checked_fixture (tc, setup, teardown);
1327   tcase_set_timeout (tc, 20);
1328   tcase_add_test (tc, test_connect);
1329   tcase_add_test (tc, test_describe);
1330   tcase_add_test (tc, test_describe_non_existing_mount_point);
1331   tcase_add_test (tc, test_setup);
1332   tcase_add_test (tc, test_setup_non_existing_stream);
1333   tcase_add_test (tc, test_play);
1334   tcase_add_test (tc, test_play_without_session);
1335   tcase_add_test (tc, test_bind_already_in_use);
1336   tcase_add_test (tc, test_play_multithreaded);
1337   tcase_add_test (tc, test_play_multithreaded_block_in_describe);
1338   tcase_add_test (tc, test_play_multithreaded_timeout_client);
1339   tcase_add_test (tc, test_play_multithreaded_timeout_session);
1340   tcase_add_test (tc, test_play_disconnect);
1341   tcase_add_test (tc, test_play_specific_server_port);
1342   tcase_add_test (tc, test_play_smpte_range);
1343   return s;
1344 }
1345
1346 GST_CHECK_MAIN (rtspserver);