rtspserver: Add udp-mcast transport SETUP test
[platform/upstream/gstreamer.git] / tests / check / gst / rtspserver.c
1 /* GStreamer unit test for GstRTSPServer
2  * Copyright (C) 2012 Axis Communications <dev-gstreamer at axis dot com>
3  *   @author David Svensson Fors <davidsf at axis dot com>
4  * Copyright (C) 2015 Centricular Ltd
5  *   @author Tim-Philipp Müller <tim@centricular.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #include <gst/check/gstcheck.h>
24 #include <gst/sdp/gstsdpmessage.h>
25 #include <gst/rtp/gstrtpbuffer.h>
26 #include <gst/rtp/gstrtcpbuffer.h>
27
28 #include <stdio.h>
29 #include <netinet/in.h>
30
31 #include "rtsp-server.h"
32
33 #define VIDEO_PIPELINE "videotestsrc ! " \
34   "video/x-raw,width=352,height=288 ! " \
35   "rtpgstpay name=pay0 pt=96"
36 #define AUDIO_PIPELINE "audiotestsrc ! " \
37   "audio/x-raw,rate=8000 ! " \
38   "rtpgstpay name=pay1 pt=97"
39
40 #define TEST_MOUNT_POINT  "/test"
41 #define TEST_PROTO        "RTP/AVP"
42 #define TEST_ENCODING     "X-GST"
43 #define TEST_CLOCK_RATE   "90000"
44
45 /* tested rtsp server */
46 static GstRTSPServer *server = NULL;
47
48 /* tcp port that the test server listens for rtsp requests on */
49 static gint test_port = 0;
50
51 /* id of the server's source within the GMainContext */
52 static guint source_id;
53
54 /* iterate the default main loop until there are no events to dispatch */
55 static void
56 iterate (void)
57 {
58   while (g_main_context_iteration (NULL, FALSE)) {
59     GST_DEBUG ("iteration");
60   }
61 }
62
63 static void
64 get_client_ports_full (GstRTSPRange * range, GSocket ** rtp_socket,
65     GSocket ** rtcp_socket)
66 {
67   GSocket *rtp = NULL;
68   GSocket *rtcp = NULL;
69   gint rtp_port = 0;
70   gint rtcp_port;
71   GInetAddress *anyaddr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
72   GSocketAddress *sockaddr;
73   gboolean bound;
74
75   for (;;) {
76     if (rtp_port != 0)
77       rtp_port += 2;
78
79     rtp = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
80         G_SOCKET_PROTOCOL_UDP, NULL);
81     fail_unless (rtp != NULL);
82
83     sockaddr = g_inet_socket_address_new (anyaddr, rtp_port);
84     fail_unless (sockaddr != NULL);
85     bound = g_socket_bind (rtp, sockaddr, FALSE, NULL);
86     g_object_unref (sockaddr);
87     if (!bound) {
88       g_object_unref (rtp);
89       continue;
90     }
91
92     sockaddr = g_socket_get_local_address (rtp, NULL);
93     fail_unless (sockaddr != NULL && G_IS_INET_SOCKET_ADDRESS (sockaddr));
94     rtp_port =
95         g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (sockaddr));
96     g_object_unref (sockaddr);
97
98     if (rtp_port % 2 != 0) {
99       rtp_port += 1;
100       g_object_unref (rtp);
101       continue;
102     }
103
104     rtcp_port = rtp_port + 1;
105
106     rtcp = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
107         G_SOCKET_PROTOCOL_UDP, NULL);
108     fail_unless (rtcp != NULL);
109
110     sockaddr = g_inet_socket_address_new (anyaddr, rtcp_port);
111     fail_unless (sockaddr != NULL);
112     bound = g_socket_bind (rtcp, sockaddr, FALSE, NULL);
113     g_object_unref (sockaddr);
114     if (!bound) {
115       g_object_unref (rtp);
116       g_object_unref (rtcp);
117       continue;
118     }
119
120     sockaddr = g_socket_get_local_address (rtcp, NULL);
121     fail_unless (sockaddr != NULL && G_IS_INET_SOCKET_ADDRESS (sockaddr));
122     fail_unless (rtcp_port ==
123         g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (sockaddr)));
124     g_object_unref (sockaddr);
125
126     break;
127   }
128
129   range->min = rtp_port;
130   range->max = rtcp_port;
131   if (rtp_socket)
132     *rtp_socket = rtp;
133   else
134     g_object_unref (rtp);
135   if (rtcp_socket)
136     *rtcp_socket = rtcp;
137   else
138     g_object_unref (rtcp);
139   GST_DEBUG ("client_port=%d-%d", range->min, range->max);
140   g_object_unref (anyaddr);
141 }
142
143 /* get a free rtp/rtcp client port pair */
144 static void
145 get_client_ports (GstRTSPRange * range)
146 {
147   get_client_ports_full (range, NULL, NULL);
148 }
149
150 /* start the tested rtsp server */
151 static void
152 start_server (void)
153 {
154   GstRTSPMountPoints *mounts;
155   gchar *service;
156   GstRTSPMediaFactory *factory;
157   GstRTSPAddressPool *pool;
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   /* use an address pool for multicast */
169   pool = gst_rtsp_address_pool_new ();
170   gst_rtsp_address_pool_add_range (pool,
171       "224.3.0.0", "224.3.0.10", 5000, 5010, 16);
172   gst_rtsp_media_factory_set_address_pool (factory, pool);
173   gst_object_unref (pool);
174
175   /* set port to any */
176   gst_rtsp_server_set_service (server, "0");
177
178   /* attach to default main context */
179   source_id = gst_rtsp_server_attach (server, NULL);
180   fail_if (source_id == 0);
181
182   /* get port */
183   service = gst_rtsp_server_get_service (server);
184   test_port = atoi (service);
185   fail_unless (test_port != 0);
186   g_free (service);
187
188   GST_DEBUG ("rtsp server listening on port %d", test_port);
189 }
190
191 /* start the testing rtsp server for RECORD mode */
192 static GstRTSPMediaFactory *
193 start_record_server (const gchar * launch_line)
194 {
195   GstRTSPMediaFactory *factory;
196   GstRTSPMountPoints *mounts;
197   gchar *service;
198
199   mounts = gst_rtsp_server_get_mount_points (server);
200
201   factory = gst_rtsp_media_factory_new ();
202
203   gst_rtsp_media_factory_set_transport_mode (factory,
204       GST_RTSP_TRANSPORT_MODE_RECORD);
205   gst_rtsp_media_factory_set_launch (factory, launch_line);
206   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT, factory);
207   g_object_unref (mounts);
208
209   /* set port to any */
210   gst_rtsp_server_set_service (server, "0");
211
212   /* attach to default main context */
213   source_id = gst_rtsp_server_attach (server, NULL);
214   fail_if (source_id == 0);
215
216   /* get port */
217   service = gst_rtsp_server_get_service (server);
218   test_port = atoi (service);
219   fail_unless (test_port != 0);
220   g_free (service);
221
222   GST_DEBUG ("rtsp server listening on port %d", test_port);
223   return factory;
224 }
225
226 /* stop the tested rtsp server */
227 static void
228 stop_server (void)
229 {
230   g_source_remove (source_id);
231   source_id = 0;
232
233   GST_DEBUG ("rtsp server stopped");
234 }
235
236 /* create an rtsp connection to the server on test_port */
237 static GstRTSPConnection *
238 connect_to_server (gint port, const gchar * mount_point)
239 {
240   GstRTSPConnection *conn = NULL;
241   gchar *address;
242   gchar *uri_string;
243   GstRTSPUrl *url = NULL;
244
245   address = gst_rtsp_server_get_address (server);
246   uri_string = g_strdup_printf ("rtsp://%s:%d%s", address, port, mount_point);
247   g_free (address);
248   fail_unless (gst_rtsp_url_parse (uri_string, &url) == GST_RTSP_OK);
249   g_free (uri_string);
250
251   fail_unless (gst_rtsp_connection_create (url, &conn) == GST_RTSP_OK);
252   gst_rtsp_url_free (url);
253
254   fail_unless (gst_rtsp_connection_connect (conn, NULL) == GST_RTSP_OK);
255
256   return conn;
257 }
258
259 /* create an rtsp request */
260 static GstRTSPMessage *
261 create_request (GstRTSPConnection * conn, GstRTSPMethod method,
262     const gchar * control)
263 {
264   GstRTSPMessage *request = NULL;
265   gchar *base_uri;
266   gchar *full_uri;
267
268   base_uri = gst_rtsp_url_get_request_uri (gst_rtsp_connection_get_url (conn));
269   full_uri = g_strdup_printf ("%s/%s", base_uri, control ? control : "");
270   g_free (base_uri);
271   if (gst_rtsp_message_new_request (&request, method, full_uri) != GST_RTSP_OK) {
272     GST_DEBUG ("failed to create request object");
273     g_free (full_uri);
274     return NULL;
275   }
276   g_free (full_uri);
277   return request;
278 }
279
280 /* send an rtsp request */
281 static gboolean
282 send_request (GstRTSPConnection * conn, GstRTSPMessage * request)
283 {
284   if (gst_rtsp_connection_send (conn, request, NULL) != GST_RTSP_OK) {
285     GST_DEBUG ("failed to send request");
286     return FALSE;
287   }
288   return TRUE;
289 }
290
291 /* read rtsp response. response must be freed by the caller */
292 static GstRTSPMessage *
293 read_response (GstRTSPConnection * conn)
294 {
295   GstRTSPMessage *response = NULL;
296
297   if (gst_rtsp_message_new (&response) != GST_RTSP_OK) {
298     GST_DEBUG ("failed to create response object");
299     return NULL;
300   }
301   if (gst_rtsp_connection_receive (conn, response, NULL) != GST_RTSP_OK) {
302     GST_DEBUG ("failed to read response");
303     gst_rtsp_message_free (response);
304     return NULL;
305   }
306   fail_unless (gst_rtsp_message_get_type (response) ==
307       GST_RTSP_MESSAGE_RESPONSE);
308   return response;
309 }
310
311 /* send an rtsp request and receive response. gchar** parameters are out
312  * parameters that have to be freed by the caller */
313 static GstRTSPStatusCode
314 do_request_full (GstRTSPConnection * conn, GstRTSPMethod method,
315     const gchar * control, const gchar * session_in, const gchar * transport_in,
316     const gchar * range_in, const gchar * require_in,
317     gchar ** content_type, gchar ** content_base, gchar ** body,
318     gchar ** session_out, gchar ** transport_out, gchar ** range_out,
319     gchar ** unsupported_out)
320 {
321   GstRTSPMessage *request;
322   GstRTSPMessage *response;
323   GstRTSPStatusCode code;
324   gchar *value;
325
326   /* create request */
327   request = create_request (conn, method, control);
328
329   /* add headers */
330   if (session_in) {
331     gst_rtsp_message_add_header (request, GST_RTSP_HDR_SESSION, session_in);
332   }
333   if (transport_in) {
334     gst_rtsp_message_add_header (request, GST_RTSP_HDR_TRANSPORT, transport_in);
335   }
336   if (range_in) {
337     gst_rtsp_message_add_header (request, GST_RTSP_HDR_RANGE, range_in);
338   }
339   if (require_in) {
340     gst_rtsp_message_add_header (request, GST_RTSP_HDR_REQUIRE, require_in);
341   }
342
343   /* send request */
344   fail_unless (send_request (conn, request));
345   gst_rtsp_message_free (request);
346
347   iterate ();
348
349   /* read response */
350   response = read_response (conn);
351
352   /* check status line */
353   gst_rtsp_message_parse_response (response, &code, NULL, NULL);
354   if (code != GST_RTSP_STS_OK) {
355     if (unsupported_out != NULL && code == GST_RTSP_STS_OPTION_NOT_SUPPORTED) {
356       gst_rtsp_message_get_header (response, GST_RTSP_HDR_UNSUPPORTED,
357           &value, 0);
358       *unsupported_out = g_strdup (value);
359     }
360     gst_rtsp_message_free (response);
361     return code;
362   }
363
364   /* get information from response */
365   if (content_type) {
366     gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_TYPE,
367         &value, 0);
368     *content_type = g_strdup (value);
369   }
370   if (content_base) {
371     gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_BASE,
372         &value, 0);
373     *content_base = g_strdup (value);
374   }
375   if (body) {
376     *body = g_malloc (response->body_size + 1);
377     strncpy (*body, (gchar *) response->body, response->body_size);
378   }
379   if (session_out) {
380     gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION, &value, 0);
381
382     value = g_strdup (value);
383
384     /* Remove the timeout */
385     if (value) {
386       char *pos = strchr (value, ';');
387       if (pos)
388         *pos = 0;
389     }
390     if (session_in) {
391       /* check that we got the same session back */
392       fail_unless (!g_strcmp0 (value, session_in));
393     }
394     *session_out = value;
395   }
396   if (transport_out) {
397     gst_rtsp_message_get_header (response, GST_RTSP_HDR_TRANSPORT, &value, 0);
398     *transport_out = g_strdup (value);
399   }
400   if (range_out) {
401     gst_rtsp_message_get_header (response, GST_RTSP_HDR_RANGE, &value, 0);
402     *range_out = g_strdup (value);
403   }
404
405   gst_rtsp_message_free (response);
406   return code;
407 }
408
409 /* send an rtsp request and receive response. gchar** parameters are out
410  * parameters that have to be freed by the caller */
411 static GstRTSPStatusCode
412 do_request (GstRTSPConnection * conn, GstRTSPMethod method,
413     const gchar * control, const gchar * session_in,
414     const gchar * transport_in, const gchar * range_in,
415     gchar ** content_type, gchar ** content_base, gchar ** body,
416     gchar ** session_out, gchar ** transport_out, gchar ** range_out)
417 {
418   return do_request_full (conn, method, control, session_in, transport_in,
419       range_in, NULL, content_type, content_base, body, session_out,
420       transport_out, range_out, NULL);
421 }
422
423 /* send an rtsp request with a method and a session, and receive response */
424 static GstRTSPStatusCode
425 do_simple_request (GstRTSPConnection * conn, GstRTSPMethod method,
426     const gchar * session)
427 {
428   return do_request (conn, method, NULL, session, NULL, NULL, NULL,
429       NULL, NULL, NULL, NULL, NULL);
430 }
431
432 /* send a DESCRIBE request and receive response. returns a received
433  * GstSDPMessage that must be freed by the caller */
434 static GstSDPMessage *
435 do_describe (GstRTSPConnection * conn, const gchar * mount_point)
436 {
437   GstSDPMessage *sdp_message;
438   gchar *content_type = NULL;
439   gchar *content_base = NULL;
440   gchar *body = NULL;
441   gchar *address;
442   gchar *expected_content_base;
443
444   /* send DESCRIBE request */
445   fail_unless (do_request (conn, GST_RTSP_DESCRIBE, NULL, NULL, NULL, NULL,
446           &content_type, &content_base, &body, NULL, NULL, NULL) ==
447       GST_RTSP_STS_OK);
448
449   /* check response values */
450   fail_unless (!g_strcmp0 (content_type, "application/sdp"));
451   address = gst_rtsp_server_get_address (server);
452   expected_content_base =
453       g_strdup_printf ("rtsp://%s:%d%s/", address, test_port, mount_point);
454   fail_unless (!g_strcmp0 (content_base, expected_content_base));
455
456   /* create sdp message */
457   fail_unless (gst_sdp_message_new (&sdp_message) == GST_SDP_OK);
458   fail_unless (gst_sdp_message_parse_buffer ((guint8 *) body,
459           strlen (body), sdp_message) == GST_SDP_OK);
460
461   /* clean up */
462   g_free (content_type);
463   g_free (content_base);
464   g_free (body);
465   g_free (address);
466   g_free (expected_content_base);
467
468   return sdp_message;
469 }
470
471 /* send a SETUP request and receive response. if *session is not NULL,
472  * it is used in the request. otherwise, *session is set to a returned
473  * session string that must be freed by the caller. the returned
474  * transport must be freed by the caller. */
475 static GstRTSPStatusCode
476 do_setup_full (GstRTSPConnection * conn, const gchar * control,
477     GstRTSPLowerTrans lower_transport, const GstRTSPRange * client_ports,
478     const gchar * require, gchar ** session, GstRTSPTransport ** transport,
479     gchar ** unsupported)
480 {
481   GstRTSPStatusCode code;
482   gchar *session_in = NULL;
483   GString *transport_string_in = NULL;
484   gchar **session_out = NULL;
485   gchar *transport_string_out = NULL;
486
487   /* prepare and send SETUP request */
488   if (session) {
489     if (*session) {
490       session_in = *session;
491     } else {
492       session_out = session;
493     }
494   }
495
496   transport_string_in = g_string_new (TEST_PROTO);
497   switch (lower_transport) {
498     case GST_RTSP_LOWER_TRANS_UDP:
499       transport_string_in =
500           g_string_append (transport_string_in, "/UDP;unicast");
501       break;
502     case GST_RTSP_LOWER_TRANS_UDP_MCAST:
503       transport_string_in =
504           g_string_append (transport_string_in, "/UDP;multicast");
505       break;
506     case GST_RTSP_LOWER_TRANS_TCP:
507       transport_string_in =
508           g_string_append (transport_string_in, "/TCP;unicast");
509       break;
510     default:
511       g_assert_not_reached ();
512       break;
513   }
514
515   if (client_ports) {
516     g_string_append_printf (transport_string_in, ";client_port=%d-%d",
517         client_ports->min, client_ports->max);
518   }
519
520   code =
521       do_request_full (conn, GST_RTSP_SETUP, control, session_in,
522       transport_string_in->str, NULL, require, NULL, NULL, NULL, session_out,
523       &transport_string_out, NULL, unsupported);
524   g_string_free (transport_string_in, TRUE);
525
526   if (transport_string_out) {
527     /* create transport */
528     fail_unless (gst_rtsp_transport_new (transport) == GST_RTSP_OK);
529     fail_unless (gst_rtsp_transport_parse (transport_string_out,
530             *transport) == GST_RTSP_OK);
531     g_free (transport_string_out);
532   }
533   GST_INFO ("code=%d", code);
534   return code;
535 }
536
537 /* send a SETUP request and receive response. if *session is not NULL,
538  * it is used in the request. otherwise, *session is set to a returned
539  * session string that must be freed by the caller. the returned
540  * transport must be freed by the caller. */
541 static GstRTSPStatusCode
542 do_setup (GstRTSPConnection * conn, const gchar * control,
543     const GstRTSPRange * client_ports, gchar ** session,
544     GstRTSPTransport ** transport)
545 {
546   return do_setup_full (conn, control, GST_RTSP_LOWER_TRANS_UDP, client_ports,
547       NULL, session, transport, NULL);
548 }
549
550 /* fixture setup function */
551 static void
552 setup (void)
553 {
554   server = gst_rtsp_server_new ();
555 }
556
557 /* fixture clean-up function */
558 static void
559 teardown (void)
560 {
561   if (server) {
562     g_object_unref (server);
563     server = NULL;
564   }
565   test_port = 0;
566 }
567
568 GST_START_TEST (test_connect)
569 {
570   GstRTSPConnection *conn;
571
572   start_server ();
573
574   /* connect to server */
575   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
576
577   /* clean up */
578   gst_rtsp_connection_free (conn);
579   stop_server ();
580
581   /* iterate so the clean-up can finish */
582   iterate ();
583 }
584
585 GST_END_TEST;
586
587 GST_START_TEST (test_describe)
588 {
589   GstRTSPConnection *conn;
590   GstSDPMessage *sdp_message = NULL;
591   const GstSDPMedia *sdp_media;
592   gint32 format;
593   gchar *expected_rtpmap;
594   const gchar *rtpmap;
595   const gchar *control_video;
596   const gchar *control_audio;
597
598   start_server ();
599
600   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
601
602   /* send DESCRIBE request */
603   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
604
605   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
606
607   /* check video sdp */
608   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
609   fail_unless (!g_strcmp0 (gst_sdp_media_get_proto (sdp_media), TEST_PROTO));
610   fail_unless (gst_sdp_media_formats_len (sdp_media) == 1);
611   sscanf (gst_sdp_media_get_format (sdp_media, 0), "%" G_GINT32_FORMAT,
612       &format);
613   expected_rtpmap =
614       g_strdup_printf ("%d " TEST_ENCODING "/" TEST_CLOCK_RATE, format);
615   rtpmap = gst_sdp_media_get_attribute_val (sdp_media, "rtpmap");
616   fail_unless (!g_strcmp0 (rtpmap, expected_rtpmap));
617   g_free (expected_rtpmap);
618   control_video = gst_sdp_media_get_attribute_val (sdp_media, "control");
619   fail_unless (!g_strcmp0 (control_video, "stream=0"));
620
621   /* check audio sdp */
622   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
623   fail_unless (!g_strcmp0 (gst_sdp_media_get_proto (sdp_media), TEST_PROTO));
624   fail_unless (gst_sdp_media_formats_len (sdp_media) == 1);
625   sscanf (gst_sdp_media_get_format (sdp_media, 0), "%" G_GINT32_FORMAT,
626       &format);
627   expected_rtpmap =
628       g_strdup_printf ("%d " TEST_ENCODING "/" TEST_CLOCK_RATE, format);
629   rtpmap = gst_sdp_media_get_attribute_val (sdp_media, "rtpmap");
630   fail_unless (!g_strcmp0 (rtpmap, expected_rtpmap));
631   g_free (expected_rtpmap);
632   control_audio = gst_sdp_media_get_attribute_val (sdp_media, "control");
633   fail_unless (!g_strcmp0 (control_audio, "stream=1"));
634
635   /* clean up and iterate so the clean-up can finish */
636   gst_sdp_message_free (sdp_message);
637   gst_rtsp_connection_free (conn);
638   stop_server ();
639   iterate ();
640 }
641
642 GST_END_TEST;
643
644 GST_START_TEST (test_describe_record_media)
645 {
646   GstRTSPConnection *conn;
647
648   start_record_server ("( fakesink name=depay0 )");
649
650   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
651
652   /* send DESCRIBE request */
653   fail_unless_equals_int (do_request (conn, GST_RTSP_DESCRIBE, NULL, NULL, NULL,
654           NULL, NULL, NULL, NULL, NULL, NULL, NULL),
655       GST_RTSP_STS_METHOD_NOT_ALLOWED);
656
657   /* clean up and iterate so the clean-up can finish */
658   gst_rtsp_connection_free (conn);
659   stop_server ();
660   iterate ();
661 }
662
663 GST_END_TEST;
664
665 GST_START_TEST (test_describe_non_existing_mount_point)
666 {
667   GstRTSPConnection *conn;
668
669   start_server ();
670
671   /* send DESCRIBE request for a non-existing mount point
672    * and check that we get a 404 Not Found */
673   conn = connect_to_server (test_port, "/non-existing");
674   fail_unless (do_simple_request (conn, GST_RTSP_DESCRIBE, NULL)
675       == GST_RTSP_STS_NOT_FOUND);
676
677   /* clean up and iterate so the clean-up can finish */
678   gst_rtsp_connection_free (conn);
679   stop_server ();
680   iterate ();
681 }
682
683 GST_END_TEST;
684
685 static void
686 do_test_setup (GstRTSPLowerTrans lower_transport)
687 {
688   GstRTSPConnection *conn;
689   GstSDPMessage *sdp_message = NULL;
690   const GstSDPMedia *sdp_media;
691   const gchar *video_control;
692   const gchar *audio_control;
693   GstRTSPRange client_ports = { 0 };
694   gchar *session = NULL;
695   GstRTSPTransport *video_transport = NULL;
696   GstRTSPTransport *audio_transport = NULL;
697
698   start_server ();
699
700   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
701
702   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
703
704   /* get control strings from DESCRIBE response */
705   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
706   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
707   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
708   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
709   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
710
711   get_client_ports (&client_ports);
712
713   /* send SETUP request for video */
714   fail_unless (do_setup_full (conn, video_control, lower_transport,
715           &client_ports, NULL, &session, &video_transport,
716           NULL) == GST_RTSP_STS_OK);
717   GST_DEBUG ("set up video %s, got session '%s'", video_control, session);
718
719   /* check response from SETUP */
720   fail_unless (video_transport->trans == GST_RTSP_TRANS_RTP);
721   fail_unless (video_transport->profile == GST_RTSP_PROFILE_AVP);
722   fail_unless (video_transport->lower_transport == lower_transport);
723   fail_unless (video_transport->mode_play);
724   gst_rtsp_transport_free (video_transport);
725
726   /* send SETUP request for audio */
727   fail_unless (do_setup_full (conn, audio_control, lower_transport,
728           &client_ports, NULL, &session, &audio_transport,
729           NULL) == GST_RTSP_STS_OK);
730   GST_DEBUG ("set up audio %s with session '%s'", audio_control, session);
731
732   /* check response from SETUP */
733   fail_unless (audio_transport->trans == GST_RTSP_TRANS_RTP);
734   fail_unless (audio_transport->profile == GST_RTSP_PROFILE_AVP);
735   fail_unless (audio_transport->lower_transport == lower_transport);
736   fail_unless (audio_transport->mode_play);
737   gst_rtsp_transport_free (audio_transport);
738
739   /* send TEARDOWN request and check that we get 200 OK */
740   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
741           session) == GST_RTSP_STS_OK);
742
743   /* clean up and iterate so the clean-up can finish */
744   g_free (session);
745   gst_sdp_message_free (sdp_message);
746   gst_rtsp_connection_free (conn);
747   stop_server ();
748   iterate ();
749 }
750
751 GST_START_TEST (test_setup_udp)
752 {
753   do_test_setup (GST_RTSP_LOWER_TRANS_UDP);
754 }
755
756 GST_END_TEST;
757
758 GST_START_TEST (test_setup_tcp)
759 {
760   do_test_setup (GST_RTSP_LOWER_TRANS_TCP);
761 }
762
763 GST_END_TEST;
764
765 GST_START_TEST (test_setup_udp_mcast)
766 {
767   do_test_setup (GST_RTSP_LOWER_TRANS_UDP_MCAST);
768 }
769
770 GST_END_TEST;
771
772 GST_START_TEST (test_setup_twice)
773 {
774   GstRTSPConnection *conn;
775   GstSDPMessage *sdp_message;
776   const GstSDPMedia *sdp_media;
777   const gchar *video_control;
778   GstRTSPRange client_ports;
779   GstRTSPTransport *video_transport = NULL;
780   gchar *session1 = NULL;
781   gchar *session2 = NULL;
782
783   start_server ();
784
785   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
786
787   /* we wan't more than one session for this connection */
788   gst_rtsp_connection_set_remember_session_id (conn, FALSE);
789
790   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
791
792   /* get the control url */
793   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
794   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
795   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
796
797   get_client_ports (&client_ports);
798
799   /* send SETUP request for one session */
800   fail_unless (do_setup (conn, video_control, &client_ports, &session1,
801           &video_transport) == GST_RTSP_STS_OK);
802   GST_DEBUG ("set up video %s, got session '%s'", video_control, session1);
803
804   /* check response from SETUP */
805   fail_unless (video_transport->trans == GST_RTSP_TRANS_RTP);
806   fail_unless (video_transport->profile == GST_RTSP_PROFILE_AVP);
807   fail_unless (video_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP);
808   fail_unless (video_transport->mode_play);
809   gst_rtsp_transport_free (video_transport);
810
811   /* send SETUP request for another session */
812   fail_unless (do_setup (conn, video_control, &client_ports, &session2,
813           &video_transport) == GST_RTSP_STS_OK);
814   GST_DEBUG ("set up video %s, got session '%s'", video_control, session2);
815
816   /* check response from SETUP */
817   fail_unless (video_transport->trans == GST_RTSP_TRANS_RTP);
818   fail_unless (video_transport->profile == GST_RTSP_PROFILE_AVP);
819   fail_unless (video_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP);
820   fail_unless (video_transport->mode_play);
821   gst_rtsp_transport_free (video_transport);
822
823   /* session can not be the same */
824   fail_unless (strcmp (session1, session2));
825
826   /* send TEARDOWN request for the first session */
827   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
828           session1) == GST_RTSP_STS_OK);
829
830   /* send TEARDOWN request for the second session */
831   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
832           session2) == GST_RTSP_STS_OK);
833
834   g_free (session1);
835   g_free (session2);
836   gst_sdp_message_free (sdp_message);
837   gst_rtsp_connection_free (conn);
838   stop_server ();
839   iterate ();
840 }
841
842 GST_END_TEST;
843
844 GST_START_TEST (test_setup_with_require_header)
845 {
846   GstRTSPConnection *conn;
847   GstSDPMessage *sdp_message = NULL;
848   const GstSDPMedia *sdp_media;
849   const gchar *video_control;
850   GstRTSPRange client_ports;
851   gchar *session = NULL;
852   gchar *unsupported = NULL;
853   GstRTSPTransport *video_transport = NULL;
854
855   start_server ();
856
857   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
858
859   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
860
861   /* get control strings from DESCRIBE response */
862   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
863   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
864   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
865
866   get_client_ports (&client_ports);
867
868   /* send SETUP request for video, with single Require header */
869   fail_unless_equals_int (do_setup_full (conn, video_control,
870           GST_RTSP_LOWER_TRANS_UDP, &client_ports, "funky-feature", &session,
871           &video_transport, &unsupported), GST_RTSP_STS_OPTION_NOT_SUPPORTED);
872   fail_unless_equals_string (unsupported, "funky-feature");
873   g_free (unsupported);
874   unsupported = NULL;
875
876   /* send SETUP request for video, with multiple Require headers */
877   fail_unless_equals_int (do_setup_full (conn, video_control,
878           GST_RTSP_LOWER_TRANS_UDP, &client_ports,
879           "funky-feature, foo-bar, superburst", &session, &video_transport,
880           &unsupported), GST_RTSP_STS_OPTION_NOT_SUPPORTED);
881   fail_unless_equals_string (unsupported, "funky-feature, foo-bar, superburst");
882   g_free (unsupported);
883   unsupported = NULL;
884
885   /* ok, just do a normal setup then (make sure that still works) */
886   fail_unless_equals_int (do_setup (conn, video_control, &client_ports,
887           &session, &video_transport), GST_RTSP_STS_OK);
888
889   GST_DEBUG ("set up video %s, got session '%s'", video_control, session);
890
891   /* check response from SETUP */
892   fail_unless (video_transport->trans == GST_RTSP_TRANS_RTP);
893   fail_unless (video_transport->profile == GST_RTSP_PROFILE_AVP);
894   fail_unless (video_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP);
895   fail_unless (video_transport->mode_play);
896   gst_rtsp_transport_free (video_transport);
897
898   /* send TEARDOWN request and check that we get 200 OK */
899   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
900           session) == GST_RTSP_STS_OK);
901
902   /* clean up and iterate so the clean-up can finish */
903   g_free (session);
904   gst_sdp_message_free (sdp_message);
905   gst_rtsp_connection_free (conn);
906   stop_server ();
907   iterate ();
908 }
909
910 GST_END_TEST;
911
912 GST_START_TEST (test_setup_non_existing_stream)
913 {
914   GstRTSPConnection *conn;
915   GstRTSPRange client_ports;
916
917   start_server ();
918
919   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
920
921   get_client_ports (&client_ports);
922
923   /* send SETUP request with a non-existing stream and check that we get a
924    * 404 Not Found */
925   fail_unless (do_setup (conn, "stream=7", &client_ports, NULL,
926           NULL) == GST_RTSP_STS_NOT_FOUND);
927
928   /* clean up and iterate so the clean-up can finish */
929   gst_rtsp_connection_free (conn);
930   stop_server ();
931   iterate ();
932 }
933
934 GST_END_TEST;
935
936 static void
937 receive_rtp (GSocket * socket, GSocketAddress ** addr)
938 {
939   GstBuffer *buffer = gst_buffer_new_allocate (NULL, 65536, NULL);
940
941   for (;;) {
942     gssize bytes;
943     GstMapInfo map = GST_MAP_INFO_INIT;
944     GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
945
946     gst_buffer_map (buffer, &map, GST_MAP_WRITE);
947     bytes = g_socket_receive_from (socket, addr, (gchar *) map.data,
948         map.maxsize, NULL, NULL);
949     fail_unless (bytes > 0);
950     gst_buffer_unmap (buffer, &map);
951     gst_buffer_set_size (buffer, bytes);
952
953     if (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtpbuffer)) {
954       gst_rtp_buffer_unmap (&rtpbuffer);
955       break;
956     }
957
958     if (addr)
959       g_clear_object (addr);
960   }
961
962   gst_buffer_unref (buffer);
963 }
964
965 static void
966 receive_rtcp (GSocket * socket, GSocketAddress ** addr, GstRTCPType type)
967 {
968   GstBuffer *buffer = gst_buffer_new_allocate (NULL, 65536, NULL);
969
970   for (;;) {
971     gssize bytes;
972     GstMapInfo map = GST_MAP_INFO_INIT;
973
974     gst_buffer_map (buffer, &map, GST_MAP_WRITE);
975     bytes = g_socket_receive_from (socket, addr, (gchar *) map.data,
976         map.maxsize, NULL, NULL);
977     fail_unless (bytes > 0);
978     gst_buffer_unmap (buffer, &map);
979     gst_buffer_set_size (buffer, bytes);
980
981     if (gst_rtcp_buffer_validate (buffer)) {
982       GstRTCPBuffer rtcpbuffer = GST_RTCP_BUFFER_INIT;
983       GstRTCPPacket packet;
984
985       if (type) {
986         fail_unless (gst_rtcp_buffer_map (buffer, GST_MAP_READ, &rtcpbuffer));
987         fail_unless (gst_rtcp_buffer_get_first_packet (&rtcpbuffer, &packet));
988         do {
989           if (gst_rtcp_packet_get_type (&packet) == type) {
990             gst_rtcp_buffer_unmap (&rtcpbuffer);
991             goto done;
992           }
993         } while (gst_rtcp_packet_move_to_next (&packet));
994         gst_rtcp_buffer_unmap (&rtcpbuffer);
995       } else {
996         break;
997       }
998     }
999
1000     if (addr)
1001       g_clear_object (addr);
1002   }
1003
1004 done:
1005
1006   gst_buffer_unref (buffer);
1007 }
1008
1009 static void
1010 do_test_play_full (const gchar * range, GstRTSPLowerTrans lower_transport)
1011 {
1012   GstRTSPConnection *conn;
1013   GstSDPMessage *sdp_message = NULL;
1014   const GstSDPMedia *sdp_media;
1015   const gchar *video_control;
1016   const gchar *audio_control;
1017   GstRTSPRange client_port;
1018   gchar *session = NULL;
1019   GstRTSPTransport *video_transport = NULL;
1020   GstRTSPTransport *audio_transport = NULL;
1021   GSocket *rtp_socket, *rtcp_socket;
1022   gchar *range_out = NULL;
1023
1024   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1025
1026   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1027
1028   /* get control strings from DESCRIBE response */
1029   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1030   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1031   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1032   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1033   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1034
1035   get_client_ports_full (&client_port, &rtp_socket, &rtcp_socket);
1036
1037   /* do SETUP for video and audio */
1038   fail_unless (do_setup_full (conn, video_control, lower_transport,
1039           &client_port, NULL, &session, &video_transport,
1040           NULL) == GST_RTSP_STS_OK);
1041   fail_unless (do_setup_full (conn, audio_control, lower_transport,
1042           &client_port, NULL, &session, &audio_transport,
1043           NULL) == GST_RTSP_STS_OK);
1044
1045   /* send PLAY request and check that we get 200 OK */
1046   fail_unless (do_request (conn, GST_RTSP_PLAY, NULL, session, NULL, range,
1047           NULL, NULL, NULL, NULL, NULL, &range_out) == GST_RTSP_STS_OK);
1048   if (range)
1049     fail_unless_equals_string (range, range_out);
1050   g_free (range_out);
1051
1052   receive_rtp (rtp_socket, NULL);
1053   receive_rtcp (rtcp_socket, NULL, 0);
1054
1055   /* send TEARDOWN request and check that we get 200 OK */
1056   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1057           session) == GST_RTSP_STS_OK);
1058
1059   /* FIXME: The rtsp-server always disconnects the transport before
1060    * sending the RTCP BYE
1061    * receive_rtcp (rtcp_socket, NULL, GST_RTCP_TYPE_BYE);
1062    */
1063
1064   /* clean up and iterate so the clean-up can finish */
1065   g_object_unref (rtp_socket);
1066   g_object_unref (rtcp_socket);
1067   g_free (session);
1068   gst_rtsp_transport_free (video_transport);
1069   gst_rtsp_transport_free (audio_transport);
1070   gst_sdp_message_free (sdp_message);
1071   gst_rtsp_connection_free (conn);
1072 }
1073
1074 static void
1075 do_test_play (const gchar * range)
1076 {
1077   do_test_play_full (range, GST_RTSP_LOWER_TRANS_UDP);
1078 }
1079
1080 GST_START_TEST (test_play)
1081 {
1082   start_server ();
1083
1084   do_test_play (NULL);
1085
1086   stop_server ();
1087   iterate ();
1088 }
1089
1090 GST_END_TEST;
1091
1092 GST_START_TEST (test_play_without_session)
1093 {
1094   GstRTSPConnection *conn;
1095
1096   start_server ();
1097
1098   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1099
1100   /* send PLAY request without a session and check that we get a
1101    * 454 Session Not Found */
1102   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1103           NULL) == GST_RTSP_STS_SESSION_NOT_FOUND);
1104
1105   /* clean up and iterate so the clean-up can finish */
1106   gst_rtsp_connection_free (conn);
1107   stop_server ();
1108   iterate ();
1109 }
1110
1111 GST_END_TEST;
1112
1113 GST_START_TEST (test_bind_already_in_use)
1114 {
1115   GstRTSPServer *serv;
1116   GSocketService *service;
1117   GError *error = NULL;
1118   guint16 port;
1119   gchar *port_str;
1120
1121   serv = gst_rtsp_server_new ();
1122   service = g_socket_service_new ();
1123
1124   /* bind service to port */
1125   port =
1126       g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL,
1127       &error);
1128   g_assert_no_error (error);
1129
1130   port_str = g_strdup_printf ("%d\n", port);
1131
1132   /* try to bind server to the same port */
1133   g_object_set (serv, "service", port_str, NULL);
1134   g_free (port_str);
1135
1136   /* attach to default main context */
1137   fail_unless (gst_rtsp_server_attach (serv, NULL) == 0);
1138
1139   /* cleanup */
1140   g_object_unref (serv);
1141   g_socket_service_stop (service);
1142   g_object_unref (service);
1143 }
1144
1145 GST_END_TEST;
1146
1147
1148 GST_START_TEST (test_play_multithreaded)
1149 {
1150   GstRTSPThreadPool *pool;
1151
1152   pool = gst_rtsp_server_get_thread_pool (server);
1153   gst_rtsp_thread_pool_set_max_threads (pool, 2);
1154   g_object_unref (pool);
1155
1156   start_server ();
1157
1158   do_test_play (NULL);
1159
1160   stop_server ();
1161   iterate ();
1162 }
1163
1164 GST_END_TEST;
1165
1166 enum
1167 {
1168   BLOCK_ME,
1169   BLOCKED,
1170   UNBLOCK
1171 };
1172
1173
1174 static void
1175 media_constructed_block (GstRTSPMediaFactory * factory,
1176     GstRTSPMedia * media, gpointer user_data)
1177 {
1178   gint *block_state = user_data;
1179
1180   g_mutex_lock (&check_mutex);
1181
1182   *block_state = BLOCKED;
1183   g_cond_broadcast (&check_cond);
1184
1185   while (*block_state != UNBLOCK)
1186     g_cond_wait (&check_cond, &check_mutex);
1187   g_mutex_unlock (&check_mutex);
1188 }
1189
1190
1191 GST_START_TEST (test_play_multithreaded_block_in_describe)
1192 {
1193   GstRTSPConnection *conn;
1194   GstRTSPMountPoints *mounts;
1195   GstRTSPMediaFactory *factory;
1196   gint block_state = BLOCK_ME;
1197   GstRTSPMessage *request;
1198   GstRTSPMessage *response;
1199   GstRTSPStatusCode code;
1200   GstRTSPThreadPool *pool;
1201
1202   pool = gst_rtsp_server_get_thread_pool (server);
1203   gst_rtsp_thread_pool_set_max_threads (pool, 2);
1204   g_object_unref (pool);
1205
1206   mounts = gst_rtsp_server_get_mount_points (server);
1207   fail_unless (mounts != NULL);
1208   factory = gst_rtsp_media_factory_new ();
1209   gst_rtsp_media_factory_set_launch (factory,
1210       "( " VIDEO_PIPELINE "  " AUDIO_PIPELINE " )");
1211   g_signal_connect (factory, "media-constructed",
1212       G_CALLBACK (media_constructed_block), &block_state);
1213   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT "2", factory);
1214   g_object_unref (mounts);
1215
1216   start_server ();
1217
1218   conn = connect_to_server (test_port, TEST_MOUNT_POINT "2");
1219   iterate ();
1220
1221   /* do describe, it will not return now as we've blocked it */
1222   request = create_request (conn, GST_RTSP_DESCRIBE, NULL);
1223   fail_unless (send_request (conn, request));
1224   gst_rtsp_message_free (request);
1225
1226   g_mutex_lock (&check_mutex);
1227   while (block_state != BLOCKED)
1228     g_cond_wait (&check_cond, &check_mutex);
1229   g_mutex_unlock (&check_mutex);
1230
1231   /* Do a second connection while the first one is blocked */
1232   do_test_play (NULL);
1233
1234   /* Now unblock the describe */
1235   g_mutex_lock (&check_mutex);
1236   block_state = UNBLOCK;
1237   g_cond_broadcast (&check_cond);
1238   g_mutex_unlock (&check_mutex);
1239
1240   response = read_response (conn);
1241   gst_rtsp_message_parse_response (response, &code, NULL, NULL);
1242   fail_unless (code == GST_RTSP_STS_OK);
1243   gst_rtsp_message_free (response);
1244
1245
1246   gst_rtsp_connection_free (conn);
1247   stop_server ();
1248   iterate ();
1249
1250 }
1251
1252 GST_END_TEST;
1253
1254
1255 static void
1256 new_session_timeout_one (GstRTSPClient * client,
1257     GstRTSPSession * session, gpointer user_data)
1258 {
1259   gst_rtsp_session_set_timeout (session, 1);
1260
1261   g_signal_handlers_disconnect_by_func (client, new_session_timeout_one,
1262       user_data);
1263 }
1264
1265 static void
1266 session_connected_new_session_cb (GstRTSPServer * server,
1267     GstRTSPClient * client, gpointer user_data)
1268 {
1269
1270   g_signal_connect (client, "new-session", user_data, NULL);
1271 }
1272
1273 GST_START_TEST (test_play_multithreaded_timeout_client)
1274 {
1275   GstRTSPConnection *conn;
1276   GstSDPMessage *sdp_message = NULL;
1277   const GstSDPMedia *sdp_media;
1278   const gchar *video_control;
1279   const gchar *audio_control;
1280   GstRTSPRange client_port;
1281   gchar *session = NULL;
1282   GstRTSPTransport *video_transport = NULL;
1283   GstRTSPTransport *audio_transport = NULL;
1284   GstRTSPSessionPool *pool;
1285   GstRTSPThreadPool *thread_pool;
1286
1287   thread_pool = gst_rtsp_server_get_thread_pool (server);
1288   gst_rtsp_thread_pool_set_max_threads (thread_pool, 2);
1289   g_object_unref (thread_pool);
1290
1291   pool = gst_rtsp_server_get_session_pool (server);
1292   g_signal_connect (server, "client-connected",
1293       G_CALLBACK (session_connected_new_session_cb), new_session_timeout_one);
1294
1295   start_server ();
1296
1297
1298   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1299
1300   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1301
1302   /* get control strings from DESCRIBE response */
1303   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1304   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1305   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1306   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1307   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1308
1309   get_client_ports (&client_port);
1310
1311   /* do SETUP for video and audio */
1312   fail_unless (do_setup_full (conn, video_control, GST_RTSP_LOWER_TRANS_UDP,
1313           &client_port, NULL, &session, &video_transport,
1314           NULL) == GST_RTSP_STS_OK);
1315   fail_unless (do_setup_full (conn, audio_control, GST_RTSP_LOWER_TRANS_UDP,
1316           &client_port, NULL, &session, &audio_transport,
1317           NULL) == GST_RTSP_STS_OK);
1318
1319   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 1);
1320
1321   /* send PLAY request and check that we get 200 OK */
1322   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1323           session) == GST_RTSP_STS_OK);
1324
1325   sleep (7);
1326
1327   fail_unless (gst_rtsp_session_pool_cleanup (pool) == 1);
1328   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 0);
1329
1330   /* clean up and iterate so the clean-up can finish */
1331   g_object_unref (pool);
1332   g_free (session);
1333   gst_rtsp_transport_free (video_transport);
1334   gst_rtsp_transport_free (audio_transport);
1335   gst_sdp_message_free (sdp_message);
1336   gst_rtsp_connection_free (conn);
1337
1338   stop_server ();
1339   iterate ();
1340 }
1341
1342 GST_END_TEST;
1343
1344
1345 GST_START_TEST (test_play_multithreaded_timeout_session)
1346 {
1347   GstRTSPConnection *conn;
1348   GstSDPMessage *sdp_message = NULL;
1349   const GstSDPMedia *sdp_media;
1350   const gchar *video_control;
1351   const gchar *audio_control;
1352   GstRTSPRange client_port;
1353   gchar *session1 = NULL;
1354   gchar *session2 = NULL;
1355   GstRTSPTransport *video_transport = NULL;
1356   GstRTSPTransport *audio_transport = NULL;
1357   GstRTSPSessionPool *pool;
1358   GstRTSPThreadPool *thread_pool;
1359
1360   thread_pool = gst_rtsp_server_get_thread_pool (server);
1361   gst_rtsp_thread_pool_set_max_threads (thread_pool, 2);
1362   g_object_unref (thread_pool);
1363
1364   pool = gst_rtsp_server_get_session_pool (server);
1365   g_signal_connect (server, "client-connected",
1366       G_CALLBACK (session_connected_new_session_cb), new_session_timeout_one);
1367
1368   start_server ();
1369
1370
1371   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1372
1373   gst_rtsp_connection_set_remember_session_id (conn, FALSE);
1374
1375   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1376
1377   /* get control strings from DESCRIBE response */
1378   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1379   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1380   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1381   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1382   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1383
1384   get_client_ports (&client_port);
1385
1386   /* do SETUP for video and audio */
1387   fail_unless (do_setup (conn, video_control, &client_port, &session1,
1388           &video_transport) == GST_RTSP_STS_OK);
1389   fail_unless (do_setup (conn, audio_control, &client_port, &session2,
1390           &audio_transport) == GST_RTSP_STS_OK);
1391
1392   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 2);
1393
1394   /* send PLAY request and check that we get 200 OK */
1395   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1396           session1) == GST_RTSP_STS_OK);
1397   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1398           session2) == GST_RTSP_STS_OK);
1399
1400   sleep (7);
1401
1402   fail_unless (gst_rtsp_session_pool_cleanup (pool) == 1);
1403
1404   /* send TEARDOWN request and check that we get 454 Session Not found */
1405   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1406           session1) == GST_RTSP_STS_SESSION_NOT_FOUND);
1407
1408   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1409           session2) == GST_RTSP_STS_OK);
1410
1411   /* clean up and iterate so the clean-up can finish */
1412   g_object_unref (pool);
1413   g_free (session1);
1414   g_free (session2);
1415   gst_rtsp_transport_free (video_transport);
1416   gst_rtsp_transport_free (audio_transport);
1417   gst_sdp_message_free (sdp_message);
1418   gst_rtsp_connection_free (conn);
1419
1420   stop_server ();
1421   iterate ();
1422 }
1423
1424 GST_END_TEST;
1425
1426
1427 GST_START_TEST (test_play_disconnect)
1428 {
1429   GstRTSPConnection *conn;
1430   GstSDPMessage *sdp_message = NULL;
1431   const GstSDPMedia *sdp_media;
1432   const gchar *video_control;
1433   const gchar *audio_control;
1434   GstRTSPRange client_port;
1435   gchar *session = NULL;
1436   GstRTSPTransport *video_transport = NULL;
1437   GstRTSPTransport *audio_transport = NULL;
1438   GstRTSPSessionPool *pool;
1439
1440   pool = gst_rtsp_server_get_session_pool (server);
1441   g_signal_connect (server, "client-connected",
1442       G_CALLBACK (session_connected_new_session_cb), new_session_timeout_one);
1443
1444   start_server ();
1445
1446   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1447
1448   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1449
1450   /* get control strings from DESCRIBE response */
1451   fail_unless (gst_sdp_message_medias_len (sdp_message) == 2);
1452   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1453   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1454   sdp_media = gst_sdp_message_get_media (sdp_message, 1);
1455   audio_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1456
1457   get_client_ports (&client_port);
1458
1459   /* do SETUP for video and audio */
1460   fail_unless (do_setup (conn, video_control, &client_port, &session,
1461           &video_transport) == GST_RTSP_STS_OK);
1462   fail_unless (do_setup (conn, audio_control, &client_port, &session,
1463           &audio_transport) == GST_RTSP_STS_OK);
1464
1465   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 1);
1466
1467   /* send PLAY request and check that we get 200 OK */
1468   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1469           session) == GST_RTSP_STS_OK);
1470
1471   gst_rtsp_connection_free (conn);
1472
1473   sleep (7);
1474
1475   fail_unless (gst_rtsp_session_pool_get_n_sessions (pool) == 1);
1476   fail_unless (gst_rtsp_session_pool_cleanup (pool) == 1);
1477
1478
1479   /* clean up and iterate so the clean-up can finish */
1480   g_object_unref (pool);
1481   g_free (session);
1482   gst_rtsp_transport_free (video_transport);
1483   gst_rtsp_transport_free (audio_transport);
1484   gst_sdp_message_free (sdp_message);
1485
1486   stop_server ();
1487   iterate ();
1488 }
1489
1490 GST_END_TEST;
1491
1492 /* Only different with test_play is the specific ports selected */
1493
1494 GST_START_TEST (test_play_specific_server_port)
1495 {
1496   GstRTSPMountPoints *mounts;
1497   gchar *service;
1498   GstRTSPMediaFactory *factory;
1499   GstRTSPAddressPool *pool;
1500   GstRTSPConnection *conn;
1501   GstSDPMessage *sdp_message = NULL;
1502   const GstSDPMedia *sdp_media;
1503   const gchar *video_control;
1504   GstRTSPRange client_port;
1505   gchar *session = NULL;
1506   GstRTSPTransport *video_transport = NULL;
1507   GSocket *rtp_socket, *rtcp_socket;
1508   GSocketAddress *rtp_address, *rtcp_address;
1509   guint16 rtp_port, rtcp_port;
1510
1511   mounts = gst_rtsp_server_get_mount_points (server);
1512
1513   factory = gst_rtsp_media_factory_new ();
1514   pool = gst_rtsp_address_pool_new ();
1515   gst_rtsp_address_pool_add_range (pool, GST_RTSP_ADDRESS_POOL_ANY_IPV4,
1516       GST_RTSP_ADDRESS_POOL_ANY_IPV4, 7770, 7780, 0);
1517   gst_rtsp_media_factory_set_address_pool (factory, pool);
1518   g_object_unref (pool);
1519   gst_rtsp_media_factory_set_launch (factory, "( " VIDEO_PIPELINE " )");
1520   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT, factory);
1521   g_object_unref (mounts);
1522
1523   /* set port to any */
1524   gst_rtsp_server_set_service (server, "0");
1525
1526   /* attach to default main context */
1527   source_id = gst_rtsp_server_attach (server, NULL);
1528   fail_if (source_id == 0);
1529
1530   /* get port */
1531   service = gst_rtsp_server_get_service (server);
1532   test_port = atoi (service);
1533   fail_unless (test_port != 0);
1534   g_free (service);
1535
1536   GST_DEBUG ("rtsp server listening on port %d", test_port);
1537
1538
1539   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1540
1541   sdp_message = do_describe (conn, TEST_MOUNT_POINT);
1542
1543   /* get control strings from DESCRIBE response */
1544   fail_unless (gst_sdp_message_medias_len (sdp_message) == 1);
1545   sdp_media = gst_sdp_message_get_media (sdp_message, 0);
1546   video_control = gst_sdp_media_get_attribute_val (sdp_media, "control");
1547
1548   get_client_ports_full (&client_port, &rtp_socket, &rtcp_socket);
1549
1550   /* do SETUP for video */
1551   fail_unless (do_setup (conn, video_control, &client_port, &session,
1552           &video_transport) == GST_RTSP_STS_OK);
1553
1554   /* send PLAY request and check that we get 200 OK */
1555   fail_unless (do_simple_request (conn, GST_RTSP_PLAY,
1556           session) == GST_RTSP_STS_OK);
1557
1558   receive_rtp (rtp_socket, &rtp_address);
1559   receive_rtcp (rtcp_socket, &rtcp_address, 0);
1560
1561   fail_unless (G_IS_INET_SOCKET_ADDRESS (rtp_address));
1562   fail_unless (G_IS_INET_SOCKET_ADDRESS (rtcp_address));
1563   rtp_port =
1564       g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtp_address));
1565   rtcp_port =
1566       g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtcp_address));
1567   fail_unless (rtp_port >= 7770 && rtp_port <= 7780 && rtp_port % 2 == 0);
1568   fail_unless (rtcp_port >= 7770 && rtcp_port <= 7780 && rtcp_port % 2 == 1);
1569   fail_unless (rtp_port + 1 == rtcp_port);
1570
1571   g_object_unref (rtp_address);
1572   g_object_unref (rtcp_address);
1573
1574   /* send TEARDOWN request and check that we get 200 OK */
1575   fail_unless (do_simple_request (conn, GST_RTSP_TEARDOWN,
1576           session) == GST_RTSP_STS_OK);
1577
1578   /* FIXME: The rtsp-server always disconnects the transport before
1579    * sending the RTCP BYE
1580    * receive_rtcp (rtcp_socket, NULL, GST_RTCP_TYPE_BYE);
1581    */
1582
1583   /* clean up and iterate so the clean-up can finish */
1584   g_object_unref (rtp_socket);
1585   g_object_unref (rtcp_socket);
1586   g_free (session);
1587   gst_rtsp_transport_free (video_transport);
1588   gst_sdp_message_free (sdp_message);
1589   gst_rtsp_connection_free (conn);
1590
1591
1592   stop_server ();
1593   iterate ();
1594 }
1595
1596 GST_END_TEST;
1597
1598
1599 GST_START_TEST (test_play_smpte_range)
1600 {
1601   start_server ();
1602
1603   do_test_play ("npt=5-");
1604   do_test_play ("smpte=0:00:00-");
1605   do_test_play ("smpte=1:00:00-");
1606   do_test_play ("smpte=1:00:03-");
1607   do_test_play ("clock=20120321T152256Z-");
1608
1609   stop_server ();
1610   iterate ();
1611 }
1612
1613 GST_END_TEST;
1614
1615 GST_START_TEST (test_announce_without_sdp)
1616 {
1617   GstRTSPConnection *conn;
1618   GstRTSPStatusCode status;
1619   GstRTSPMessage *request;
1620   GstRTSPMessage *response;
1621
1622   start_record_server ("( fakesink name=depay0 )");
1623
1624   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1625
1626   /* create and send ANNOUNCE request */
1627   request = create_request (conn, GST_RTSP_ANNOUNCE, NULL);
1628
1629   fail_unless (send_request (conn, request));
1630
1631   iterate ();
1632
1633   response = read_response (conn);
1634
1635   /* check response */
1636   gst_rtsp_message_parse_response (response, &status, NULL, NULL);
1637   fail_unless_equals_int (status, GST_RTSP_STS_BAD_REQUEST);
1638   gst_rtsp_message_free (response);
1639
1640   /* try again, this type with content-type, but still no SDP */
1641   gst_rtsp_message_add_header (request, GST_RTSP_HDR_CONTENT_TYPE,
1642       "application/sdp");
1643
1644   fail_unless (send_request (conn, request));
1645
1646   iterate ();
1647
1648   response = read_response (conn);
1649
1650   /* check response */
1651   gst_rtsp_message_parse_response (response, &status, NULL, NULL);
1652   fail_unless_equals_int (status, GST_RTSP_STS_BAD_REQUEST);
1653   gst_rtsp_message_free (response);
1654
1655   /* try again, this type with an unknown content-type */
1656   gst_rtsp_message_remove_header (request, GST_RTSP_HDR_CONTENT_TYPE, -1);
1657   gst_rtsp_message_add_header (request, GST_RTSP_HDR_CONTENT_TYPE,
1658       "application/x-something");
1659
1660   fail_unless (send_request (conn, request));
1661
1662   iterate ();
1663
1664   response = read_response (conn);
1665
1666   /* check response */
1667   gst_rtsp_message_parse_response (response, &status, NULL, NULL);
1668   fail_unless_equals_int (status, GST_RTSP_STS_BAD_REQUEST);
1669   gst_rtsp_message_free (response);
1670
1671   /* clean up and iterate so the clean-up can finish */
1672   gst_rtsp_message_free (request);
1673   gst_rtsp_connection_free (conn);
1674   stop_server ();
1675   iterate ();
1676 }
1677
1678 GST_END_TEST;
1679
1680 static GstRTSPStatusCode
1681 do_announce (GstRTSPConnection * conn, GstSDPMessage * sdp)
1682 {
1683   GstRTSPMessage *request;
1684   GstRTSPMessage *response;
1685   GstRTSPStatusCode code;
1686   gchar *str;
1687
1688   /* create request */
1689   request = create_request (conn, GST_RTSP_ANNOUNCE, NULL);
1690
1691   gst_rtsp_message_add_header (request, GST_RTSP_HDR_CONTENT_TYPE,
1692       "application/sdp");
1693
1694   /* add SDP to the response body */
1695   str = gst_sdp_message_as_text (sdp);
1696   gst_rtsp_message_take_body (request, (guint8 *) str, strlen (str));
1697   gst_sdp_message_free (sdp);
1698
1699   /* send request */
1700   fail_unless (send_request (conn, request));
1701   gst_rtsp_message_free (request);
1702
1703   iterate ();
1704
1705   /* read response */
1706   response = read_response (conn);
1707
1708   /* check status line */
1709   gst_rtsp_message_parse_response (response, &code, NULL, NULL);
1710
1711   gst_rtsp_message_free (response);
1712   return code;
1713 }
1714
1715 static void
1716 media_constructed_cb (GstRTSPMediaFactory * mfactory, GstRTSPMedia * media,
1717     gpointer user_data)
1718 {
1719   GstElement **p_sink = user_data;
1720   GstElement *bin;
1721
1722   bin = gst_rtsp_media_get_element (media);
1723   *p_sink = gst_bin_get_by_name (GST_BIN (bin), "sink");
1724   GST_INFO ("media constructed!: %" GST_PTR_FORMAT, *p_sink);
1725 }
1726
1727 #define RECORD_N_BUFS 10
1728
1729 GST_START_TEST (test_record_tcp)
1730 {
1731   GstRTSPMediaFactory *mfactory;
1732   GstRTSPConnection *conn;
1733   GstRTSPStatusCode status;
1734   GstRTSPMessage *response;
1735   GstRTSPMessage *request;
1736   GstSDPMessage *sdp;
1737   GstRTSPResult rres;
1738   GSocketAddress *sa;
1739   GInetAddress *ia;
1740   GstElement *server_sink = NULL;
1741   GSocket *conn_socket;
1742   const gchar *proto;
1743   gchar *client_ip, *sess_id, *session = NULL;
1744   gint i;
1745
1746   mfactory =
1747       start_record_server ("( rtppcmadepay name=depay0 ! appsink name=sink )");
1748
1749   g_signal_connect (mfactory, "media-constructed",
1750       G_CALLBACK (media_constructed_cb), &server_sink);
1751
1752   conn = connect_to_server (test_port, TEST_MOUNT_POINT);
1753
1754   conn_socket = gst_rtsp_connection_get_read_socket (conn);
1755
1756   sa = g_socket_get_local_address (conn_socket, NULL);
1757   ia = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (sa));
1758   client_ip = g_inet_address_to_string (ia);
1759   if (g_socket_address_get_family (sa) == G_SOCKET_FAMILY_IPV6)
1760     proto = "IP6";
1761   else if (g_socket_address_get_family (sa) == G_SOCKET_FAMILY_IPV4)
1762     proto = "IP4";
1763   else
1764     g_assert_not_reached ();
1765   g_object_unref (sa);
1766
1767   gst_sdp_message_new (&sdp);
1768
1769   /* some standard things first */
1770   gst_sdp_message_set_version (sdp, "0");
1771
1772   /* session ID doesn't have to be super-unique in this case */
1773   sess_id = g_strdup_printf ("%u", g_random_int ());
1774   gst_sdp_message_set_origin (sdp, "-", sess_id, "1", "IN", proto, client_ip);
1775   g_free (sess_id);
1776   g_free (client_ip);
1777
1778   gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
1779   gst_sdp_message_set_information (sdp, "rtsp-server-test");
1780   gst_sdp_message_add_time (sdp, "0", "0", NULL);
1781   gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
1782
1783   /* add stream 0 */
1784   {
1785     GstSDPMedia *smedia;
1786
1787     gst_sdp_media_new (&smedia);
1788     gst_sdp_media_set_media (smedia, "audio");
1789     gst_sdp_media_add_format (smedia, "8");     /* pcma/alaw */
1790     gst_sdp_media_set_port_info (smedia, 0, 1);
1791     gst_sdp_media_set_proto (smedia, "RTP/AVP");
1792     gst_sdp_media_add_attribute (smedia, "rtpmap", "8 PCMA/8000");
1793     gst_sdp_message_add_media (sdp, smedia);
1794     gst_sdp_media_free (smedia);
1795   }
1796
1797   /* send ANNOUNCE request */
1798   status = do_announce (conn, sdp);
1799   fail_unless_equals_int (status, GST_RTSP_STS_OK);
1800
1801   /* create and send SETUP request */
1802   request = create_request (conn, GST_RTSP_SETUP, NULL);
1803   gst_rtsp_message_add_header (request, GST_RTSP_HDR_TRANSPORT,
1804       "RTP/AVP/TCP;interleaved=0;mode=record");
1805   fail_unless (send_request (conn, request));
1806   gst_rtsp_message_free (request);
1807   iterate ();
1808   response = read_response (conn);
1809   gst_rtsp_message_parse_response (response, &status, NULL, NULL);
1810   fail_unless_equals_int (status, GST_RTSP_STS_OK);
1811
1812   rres =
1813       gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION, &session, 0);
1814   session = g_strdup (session);
1815   fail_unless_equals_int (rres, GST_RTSP_OK);
1816   gst_rtsp_message_free (response);
1817
1818   /* send RECORD */
1819   request = create_request (conn, GST_RTSP_RECORD, NULL);
1820   gst_rtsp_message_add_header (request, GST_RTSP_HDR_SESSION, session);
1821   fail_unless (send_request (conn, request));
1822   gst_rtsp_message_free (request);
1823   iterate ();
1824   response = read_response (conn);
1825   gst_rtsp_message_parse_response (response, &status, NULL, NULL);
1826   fail_unless_equals_int (status, GST_RTSP_STS_OK);
1827   gst_rtsp_message_free (response);
1828
1829   /* send some data */
1830   {
1831     GstElement *pipeline, *src, *enc, *pay, *sink;
1832
1833     pipeline = gst_pipeline_new ("send-pipeline");
1834     src = gst_element_factory_make ("audiotestsrc", NULL);
1835     g_object_set (src, "num-buffers", RECORD_N_BUFS,
1836         "samplesperbuffer", 1000, NULL);
1837     enc = gst_element_factory_make ("alawenc", NULL);
1838     pay = gst_element_factory_make ("rtppcmapay", NULL);
1839     sink = gst_element_factory_make ("appsink", NULL);
1840     fail_unless (pipeline && src && enc && pay && sink);
1841     gst_bin_add_many (GST_BIN (pipeline), src, enc, pay, sink, NULL);
1842     gst_element_link_many (src, enc, pay, sink, NULL);
1843     gst_element_set_state (pipeline, GST_STATE_PLAYING);
1844
1845     do {
1846       GstRTSPMessage *data_msg;
1847       GstMapInfo map = GST_MAP_INFO_INIT;
1848       GstRTSPResult rres;
1849       GstSample *sample = NULL;
1850       GstBuffer *buf;
1851
1852       g_signal_emit_by_name (G_OBJECT (sink), "pull-sample", &sample);
1853       if (sample == NULL)
1854         break;
1855       buf = gst_sample_get_buffer (sample);
1856       rres = gst_rtsp_message_new_data (&data_msg, 0);
1857       fail_unless_equals_int (rres, GST_RTSP_OK);
1858       gst_buffer_map (buf, &map, GST_MAP_READ);
1859       GST_INFO ("sending %u bytes of data on channel 0", (guint) map.size);
1860       GST_MEMDUMP ("data on channel 0", map.data, map.size);
1861       rres = gst_rtsp_message_set_body (data_msg, map.data, map.size);
1862       fail_unless_equals_int (rres, GST_RTSP_OK);
1863       gst_buffer_unmap (buf, &map);
1864       rres = gst_rtsp_connection_send (conn, data_msg, NULL);
1865       fail_unless_equals_int (rres, GST_RTSP_OK);
1866       gst_rtsp_message_free (data_msg);
1867       gst_sample_unref (sample);
1868     } while (TRUE);
1869
1870     gst_element_set_state (pipeline, GST_STATE_NULL);
1871     gst_object_unref (pipeline);
1872   }
1873
1874   /* check received data (we assume every buffer created by audiotestsrc and
1875    * subsequently encoded by mulawenc results in exactly one RTP packet) */
1876   for (i = 0; i < RECORD_N_BUFS; ++i) {
1877     GstSample *sample = NULL;
1878
1879     g_signal_emit_by_name (G_OBJECT (server_sink), "pull-sample", &sample);
1880     GST_INFO ("%2d recv sample: %p", i, sample);
1881     gst_sample_unref (sample);
1882   }
1883
1884   fail_unless_equals_int (GST_STATE (server_sink), GST_STATE_PLAYING);
1885
1886   /* clean up and iterate so the clean-up can finish */
1887   gst_rtsp_connection_free (conn);
1888   stop_server ();
1889   iterate ();
1890   g_free (session);
1891 }
1892
1893 GST_END_TEST;
1894
1895 static Suite *
1896 rtspserver_suite (void)
1897 {
1898   Suite *s = suite_create ("rtspserver");
1899   TCase *tc = tcase_create ("general");
1900
1901   suite_add_tcase (s, tc);
1902   tcase_add_checked_fixture (tc, setup, teardown);
1903   tcase_set_timeout (tc, 120);
1904   tcase_add_test (tc, test_connect);
1905   tcase_add_test (tc, test_describe);
1906   tcase_add_test (tc, test_describe_non_existing_mount_point);
1907   tcase_add_test (tc, test_describe_record_media);
1908   tcase_add_test (tc, test_setup_udp);
1909   tcase_add_test (tc, test_setup_tcp);
1910   tcase_add_test (tc, test_setup_udp_mcast);
1911   tcase_add_test (tc, test_setup_twice);
1912   tcase_add_test (tc, test_setup_with_require_header);
1913   tcase_add_test (tc, test_setup_non_existing_stream);
1914   tcase_add_test (tc, test_play);
1915   tcase_add_test (tc, test_play_without_session);
1916   tcase_add_test (tc, test_bind_already_in_use);
1917   tcase_add_test (tc, test_play_multithreaded);
1918   tcase_add_test (tc, test_play_multithreaded_block_in_describe);
1919   tcase_add_test (tc, test_play_multithreaded_timeout_client);
1920   tcase_add_test (tc, test_play_multithreaded_timeout_session);
1921   tcase_add_test (tc, test_play_disconnect);
1922   tcase_add_test (tc, test_play_specific_server_port);
1923   tcase_add_test (tc, test_play_smpte_range);
1924   tcase_add_test (tc, test_announce_without_sdp);
1925   tcase_add_test (tc, test_record_tcp);
1926   return s;
1927 }
1928
1929 GST_CHECK_MAIN (rtspserver);