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