2 * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <gst/check/gstcheck.h>
22 #include <rtsp-client.h>
24 static gchar * session_id;
26 static guint expected_session_timeout = 60;
29 test_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
30 gboolean close, gpointer user_data)
32 GstRTSPStatusCode code;
34 GstRTSPVersion version;
36 fail_unless (gst_rtsp_message_get_type (response) ==
37 GST_RTSP_MESSAGE_RESPONSE);
39 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
42 fail_unless (code == GST_RTSP_STS_OK);
43 fail_unless (g_str_equal (reason, "OK"));
44 fail_unless (version == GST_RTSP_VERSION_1_0);
50 test_response_400 (GstRTSPClient * client, GstRTSPMessage * response,
51 gboolean close, gpointer user_data)
53 GstRTSPStatusCode code;
55 GstRTSPVersion version;
57 fail_unless (gst_rtsp_message_get_type (response) ==
58 GST_RTSP_MESSAGE_RESPONSE);
60 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
63 fail_unless (code == GST_RTSP_STS_BAD_REQUEST);
64 fail_unless (g_str_equal (reason, "Bad Request"));
65 fail_unless (version == GST_RTSP_VERSION_1_0);
71 test_response_404 (GstRTSPClient * client, GstRTSPMessage * response,
72 gboolean close, gpointer user_data)
74 GstRTSPStatusCode code;
76 GstRTSPVersion version;
78 fail_unless (gst_rtsp_message_get_type (response) ==
79 GST_RTSP_MESSAGE_RESPONSE);
81 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
84 fail_unless (code == GST_RTSP_STS_NOT_FOUND);
85 fail_unless (g_str_equal (reason, "Not Found"));
86 fail_unless (version == GST_RTSP_VERSION_1_0);
92 test_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
93 gboolean close, gpointer user_data)
95 GstRTSPStatusCode code;
97 GstRTSPVersion version;
99 fail_unless (gst_rtsp_message_get_type (response) ==
100 GST_RTSP_MESSAGE_RESPONSE);
102 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
105 fail_unless (code == GST_RTSP_STS_SESSION_NOT_FOUND);
106 fail_unless (g_str_equal (reason, "Session Not Found"));
107 fail_unless (version == GST_RTSP_VERSION_1_0);
112 static GstRTSPClient *
113 setup_client (const gchar * launch_line)
115 GstRTSPClient *client;
116 GstRTSPSessionPool *session_pool;
117 GstRTSPMountPoints *mount_points;
118 GstRTSPMediaFactory *factory;
119 GstRTSPThreadPool *thread_pool;
121 client = gst_rtsp_client_new ();
123 session_pool = gst_rtsp_session_pool_new ();
124 gst_rtsp_client_set_session_pool (client, session_pool);
126 mount_points = gst_rtsp_mount_points_new ();
127 factory = gst_rtsp_media_factory_new ();
128 if (launch_line == NULL)
129 gst_rtsp_media_factory_set_launch (factory,
130 "videotestsrc ! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96");
132 gst_rtsp_media_factory_set_launch (factory, launch_line);
134 gst_rtsp_mount_points_add_factory (mount_points, "/test", factory);
135 gst_rtsp_client_set_mount_points (client, mount_points);
137 thread_pool = gst_rtsp_thread_pool_new ();
138 gst_rtsp_client_set_thread_pool (client, thread_pool);
140 g_object_unref (mount_points);
141 g_object_unref (session_pool);
142 g_object_unref (thread_pool);
148 teardown_client (GstRTSPClient * client)
150 gst_rtsp_client_set_thread_pool (client, NULL);
151 g_object_unref (client);
154 GST_START_TEST (test_request)
156 GstRTSPClient *client;
157 GstRTSPMessage request = { 0, };
159 GstRTSPConnection *conn;
161 GError *error = NULL;
163 client = gst_rtsp_client_new ();
165 /* OPTIONS with invalid url */
166 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
167 "foopy://padoop/") == GST_RTSP_OK);
168 str = g_strdup_printf ("%d", cseq);
169 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
172 gst_rtsp_client_set_send_func (client, test_response_400, NULL, NULL);
173 fail_unless (gst_rtsp_client_handle_message (client,
174 &request) == GST_RTSP_OK);
176 gst_rtsp_message_unset (&request);
178 /* OPTIONS with unknown session id */
179 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
180 "rtsp://localhost/test") == GST_RTSP_OK);
181 str = g_strdup_printf ("%d", cseq);
182 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
184 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, "foobar");
186 gst_rtsp_client_set_send_func (client, test_response_454, NULL, NULL);
187 fail_unless (gst_rtsp_client_handle_message (client,
188 &request) == GST_RTSP_OK);
190 gst_rtsp_message_unset (&request);
192 /* OPTIONS with an absolute path instead of an absolute url */
193 /* set host information */
194 sock = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
195 G_SOCKET_PROTOCOL_TCP, &error);
196 g_assert_no_error (error);
197 gst_rtsp_connection_create_from_socket (sock, "localhost", 444, NULL, &conn);
198 fail_unless (gst_rtsp_client_set_connection (client, conn));
199 g_object_unref (sock);
201 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
202 "/test") == GST_RTSP_OK);
203 str = g_strdup_printf ("%d", cseq);
204 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
207 gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
208 fail_unless (gst_rtsp_client_handle_message (client,
209 &request) == GST_RTSP_OK);
210 gst_rtsp_message_unset (&request);
212 /* OPTIONS with an absolute path instead of an absolute url with invalid
213 * host information */
214 g_object_unref (client);
215 client = gst_rtsp_client_new ();
216 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
217 "/test") == GST_RTSP_OK);
218 str = g_strdup_printf ("%d", cseq);
219 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
222 gst_rtsp_client_set_send_func (client, test_response_400, NULL, NULL);
223 fail_unless (gst_rtsp_client_handle_message (client,
224 &request) == GST_RTSP_OK);
225 gst_rtsp_message_unset (&request);
227 g_object_unref (client);
233 test_option_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
234 gboolean close, gpointer user_data)
236 GstRTSPStatusCode code;
238 GstRTSPVersion version;
240 GstRTSPMethod methods;
242 fail_unless (gst_rtsp_message_get_type (response) ==
243 GST_RTSP_MESSAGE_RESPONSE);
245 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
248 fail_unless (code == GST_RTSP_STS_OK);
249 fail_unless (g_str_equal (reason, "OK"));
250 fail_unless (version == GST_RTSP_VERSION_1_0);
252 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
254 fail_unless (atoi (str) == cseq++);
256 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_PUBLIC, &str,
259 methods = gst_rtsp_options_from_text (str);
260 fail_if (methods == 0);
261 fail_unless (methods == (GST_RTSP_DESCRIBE |
266 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN));
271 GST_START_TEST (test_options)
273 GstRTSPClient *client;
274 GstRTSPMessage request = { 0, };
277 client = gst_rtsp_client_new ();
280 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
281 "rtsp://localhost/test") == GST_RTSP_OK);
282 str = g_strdup_printf ("%d", cseq);
283 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
286 gst_rtsp_client_set_send_func (client, test_option_response_200, NULL, NULL);
287 fail_unless (gst_rtsp_client_handle_message (client,
288 &request) == GST_RTSP_OK);
289 gst_rtsp_message_unset (&request);
291 g_object_unref (client);
296 GST_START_TEST (test_describe)
298 GstRTSPClient *client;
299 GstRTSPMessage request = { 0, };
302 client = gst_rtsp_client_new ();
304 /* simple DESCRIBE for non-existing url */
305 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
306 "rtsp://localhost/test") == GST_RTSP_OK);
307 str = g_strdup_printf ("%d", cseq);
308 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
311 gst_rtsp_client_set_send_func (client, test_response_404, NULL, NULL);
312 fail_unless (gst_rtsp_client_handle_message (client,
313 &request) == GST_RTSP_OK);
314 gst_rtsp_message_unset (&request);
316 g_object_unref (client);
318 /* simple DESCRIBE for an existing url */
319 client = setup_client (NULL);
320 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
321 "rtsp://localhost/test") == GST_RTSP_OK);
322 str = g_strdup_printf ("%d", cseq);
323 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
326 gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
327 fail_unless (gst_rtsp_client_handle_message (client,
328 &request) == GST_RTSP_OK);
329 gst_rtsp_message_unset (&request);
331 teardown_client (client);
336 static const gchar *expected_transport = NULL;;
339 test_setup_response_200_multicast (GstRTSPClient * client,
340 GstRTSPMessage * response, gboolean close, gpointer user_data)
342 GstRTSPStatusCode code;
344 GstRTSPVersion version;
346 GstRTSPSessionPool *session_pool;
347 GstRTSPSession *session;
348 gchar **session_hdr_params;
350 fail_unless (expected_transport != NULL);
352 fail_unless (gst_rtsp_message_get_type (response) ==
353 GST_RTSP_MESSAGE_RESPONSE);
355 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
358 fail_unless (code == GST_RTSP_STS_OK);
359 fail_unless (g_str_equal (reason, "OK"));
360 fail_unless (version == GST_RTSP_VERSION_1_0);
362 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
364 fail_unless (atoi (str) == cseq++);
366 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_TRANSPORT,
367 &str, 0) == GST_RTSP_OK);
369 fail_unless (!strcmp (str, expected_transport));
371 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION,
372 &str, 0) == GST_RTSP_OK);
373 session_hdr_params = g_strsplit (str, ";", -1);
375 /* session-id value */
376 fail_unless (session_hdr_params[0] != NULL);
378 if (expected_session_timeout != 60) {
379 /* session timeout param */
380 gchar *timeout_str = g_strdup_printf ("timeout=%u",
381 expected_session_timeout);
383 fail_unless (session_hdr_params[1] != NULL);
384 g_strstrip (session_hdr_params[1]);
385 fail_unless (g_strcmp0 (session_hdr_params[1], timeout_str) == 0);
386 g_free (timeout_str);
389 session_pool = gst_rtsp_client_get_session_pool (client);
390 fail_unless (session_pool != NULL);
392 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 1);
393 session = gst_rtsp_session_pool_find (session_pool, session_hdr_params[0]);
394 g_strfreev (session_hdr_params);
396 /* remember session id to be able to send teardown */
397 session_id = g_strdup (gst_rtsp_session_get_sessionid (session));
398 fail_unless (session_id != NULL);
400 fail_unless (session != NULL);
401 g_object_unref (session);
403 g_object_unref (session_pool);
410 test_teardown_response_200 (GstRTSPClient * client,
411 GstRTSPMessage * response, gboolean close, gpointer user_data)
413 GstRTSPStatusCode code;
415 GstRTSPVersion version;
417 fail_unless (gst_rtsp_message_get_type (response) ==
418 GST_RTSP_MESSAGE_RESPONSE);
420 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
423 fail_unless (code == GST_RTSP_STS_OK);
424 fail_unless (g_str_equal (reason, "OK"));
425 fail_unless (version == GST_RTSP_VERSION_1_0);
431 send_teardown (GstRTSPClient * client)
433 GstRTSPMessage request = { 0, };
436 fail_unless (session_id != NULL);
437 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_TEARDOWN,
438 "rtsp://localhost/test") == GST_RTSP_OK);
439 str = g_strdup_printf ("%d", cseq);
440 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
441 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION,
443 gst_rtsp_client_set_send_func (client, test_teardown_response_200,
445 fail_unless (gst_rtsp_client_handle_message (client,
446 &request) == GST_RTSP_OK);
447 gst_rtsp_message_unset (&request);
452 static GstRTSPClient *
453 setup_multicast_client (void)
455 GstRTSPClient *client;
456 GstRTSPSessionPool *session_pool;
457 GstRTSPMountPoints *mount_points;
458 GstRTSPMediaFactory *factory;
459 GstRTSPAddressPool *address_pool;
460 GstRTSPThreadPool *thread_pool;
462 client = gst_rtsp_client_new ();
464 session_pool = gst_rtsp_session_pool_new ();
465 gst_rtsp_client_set_session_pool (client, session_pool);
467 mount_points = gst_rtsp_mount_points_new ();
468 factory = gst_rtsp_media_factory_new ();
469 gst_rtsp_media_factory_set_launch (factory,
470 "audiotestsrc ! audio/x-raw,rate=44100 ! audioconvert ! rtpL16pay name=pay0");
471 address_pool = gst_rtsp_address_pool_new ();
472 fail_unless (gst_rtsp_address_pool_add_range (address_pool,
473 "233.252.0.1", "233.252.0.1", 5000, 5010, 1));
474 gst_rtsp_media_factory_set_address_pool (factory, address_pool);
475 gst_rtsp_media_factory_add_role (factory, "user",
476 "media.factory.access", G_TYPE_BOOLEAN, TRUE,
477 "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
478 gst_rtsp_mount_points_add_factory (mount_points, "/test", factory);
479 gst_rtsp_client_set_mount_points (client, mount_points);
481 thread_pool = gst_rtsp_thread_pool_new ();
482 gst_rtsp_client_set_thread_pool (client, thread_pool);
484 g_object_unref (mount_points);
485 g_object_unref (session_pool);
486 g_object_unref (address_pool);
487 g_object_unref (thread_pool);
492 GST_START_TEST (test_client_multicast_transport_404)
494 GstRTSPClient *client;
495 GstRTSPMessage request = { 0, };
498 client = setup_multicast_client ();
500 /* simple SETUP for non-existing url */
501 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
502 "rtsp://localhost/test2/stream=0") == GST_RTSP_OK);
503 str = g_strdup_printf ("%d", cseq);
504 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
505 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
506 "RTP/AVP;multicast");
508 gst_rtsp_client_set_send_func (client, test_response_404, NULL, NULL);
509 fail_unless (gst_rtsp_client_handle_message (client,
510 &request) == GST_RTSP_OK);
511 gst_rtsp_message_unset (&request);
513 teardown_client (client);
519 new_session_cb (GObject * client, GstRTSPSession * session, gpointer user_data)
521 GST_DEBUG ("%p: new session %p", client, session);
522 gst_rtsp_session_set_timeout (session, expected_session_timeout);
525 GST_START_TEST (test_client_multicast_transport)
527 GstRTSPClient *client;
528 GstRTSPMessage request = { 0, };
531 client = setup_multicast_client ();
533 expected_session_timeout = 20;
534 g_signal_connect (G_OBJECT (client), "new-session",
535 G_CALLBACK (new_session_cb), NULL);
537 /* simple SETUP with a valid URI and multicast */
538 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
539 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
540 str = g_strdup_printf ("%d", cseq);
541 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
542 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
543 "RTP/AVP;multicast");
545 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
546 "ttl=1;port=5000-5001;mode=\"PLAY\"";
547 gst_rtsp_client_set_send_func (client, test_setup_response_200_multicast,
549 fail_unless (gst_rtsp_client_handle_message (client,
550 &request) == GST_RTSP_OK);
551 gst_rtsp_message_unset (&request);
552 expected_transport = NULL;
553 expected_session_timeout = 60;
555 send_teardown (client);
557 teardown_client (client);
562 GST_START_TEST (test_client_multicast_ignore_transport_specific)
564 GstRTSPClient *client;
565 GstRTSPMessage request = { 0, };
568 client = setup_multicast_client ();
570 /* simple SETUP with a valid URI and multicast and a specific dest,
572 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
573 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
574 str = g_strdup_printf ("%d", cseq);
575 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
576 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
577 "RTP/AVP;multicast;destination=233.252.0.2;ttl=2;port=5001-5006;");
579 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
580 "ttl=1;port=5000-5001;mode=\"PLAY\"";
581 gst_rtsp_client_set_send_func (client, test_setup_response_200_multicast,
583 fail_unless (gst_rtsp_client_handle_message (client,
584 &request) == GST_RTSP_OK);
585 gst_rtsp_message_unset (&request);
586 expected_transport = NULL;
588 send_teardown (client);
590 teardown_client (client);
596 test_setup_response_461 (GstRTSPClient * client,
597 GstRTSPMessage * response, gboolean close, gpointer user_data)
599 GstRTSPStatusCode code;
601 GstRTSPVersion version;
604 fail_unless (expected_transport == NULL);
606 fail_unless (gst_rtsp_message_get_type (response) ==
607 GST_RTSP_MESSAGE_RESPONSE);
609 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
612 fail_unless (code == GST_RTSP_STS_UNSUPPORTED_TRANSPORT);
613 fail_unless (g_str_equal (reason, "Unsupported transport"));
614 fail_unless (version == GST_RTSP_VERSION_1_0);
616 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
618 fail_unless (atoi (str) == cseq++);
624 GST_START_TEST (test_client_multicast_invalid_transport_specific)
626 GstRTSPClient *client;
627 GstRTSPMessage request = { 0, };
629 GstRTSPSessionPool *session_pool;
630 GstRTSPContext ctx = { NULL };
632 client = setup_multicast_client ();
635 ctx.auth = gst_rtsp_auth_new ();
637 gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
638 G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
640 gst_rtsp_context_push_current (&ctx);
642 /* simple SETUP with a valid URI and multicast, but an invalid ip */
643 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
644 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
645 str = g_strdup_printf ("%d", cseq);
646 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
647 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
648 "RTP/AVP;multicast;destination=233.252.0.2;ttl=1;port=5000-5001;");
650 gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
651 fail_unless (gst_rtsp_client_handle_message (client,
652 &request) == GST_RTSP_OK);
653 gst_rtsp_message_unset (&request);
655 session_pool = gst_rtsp_client_get_session_pool (client);
656 fail_unless (session_pool != NULL);
657 /* FIXME: There seems to be a leak of a session here ! */
658 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
659 g_object_unref (session_pool);
663 /* simple SETUP with a valid URI and multicast, but an invalid prt */
664 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
665 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
666 str = g_strdup_printf ("%d", cseq);
667 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
668 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
669 "RTP/AVP;multicast;destination=233.252.0.1;ttl=1;port=6000-6001;");
671 gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
672 fail_unless (gst_rtsp_client_handle_message (client,
673 &request) == GST_RTSP_OK);
674 gst_rtsp_message_unset (&request);
676 session_pool = gst_rtsp_client_get_session_pool (client);
677 fail_unless (session_pool != NULL);
678 /* FIXME: There seems to be a leak of a session here ! */
679 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
680 g_object_unref (session_pool);
684 /* simple SETUP with a valid URI and multicast, but an invalid ttl */
685 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
686 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
687 str = g_strdup_printf ("%d", cseq);
688 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
689 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
690 "RTP/AVP;multicast;destination=233.252.0.1;ttl=2;port=5000-5001;");
692 gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
693 fail_unless (gst_rtsp_client_handle_message (client,
694 &request) == GST_RTSP_OK);
695 gst_rtsp_message_unset (&request);
697 session_pool = gst_rtsp_client_get_session_pool (client);
698 fail_unless (session_pool != NULL);
699 /* FIXME: There seems to be a leak of a session here ! */
700 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
701 g_object_unref (session_pool);
704 teardown_client (client);
705 g_object_unref (ctx.auth);
706 gst_rtsp_token_unref (ctx.token);
707 gst_rtsp_context_pop_current (&ctx);
712 GST_START_TEST (test_client_multicast_transport_specific)
714 GstRTSPClient *client;
715 GstRTSPMessage request = { 0, };
717 GstRTSPSessionPool *session_pool;
718 GstRTSPContext ctx = { NULL };
720 client = setup_multicast_client ();
723 ctx.auth = gst_rtsp_auth_new ();
725 gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
726 G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
728 gst_rtsp_context_push_current (&ctx);
730 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
731 "ttl=1;port=5000-5001;mode=\"PLAY\"";
733 /* simple SETUP with a valid URI and multicast, but an invalid ip */
734 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
735 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
736 str = g_strdup_printf ("%d", cseq);
737 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
738 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
741 gst_rtsp_client_set_send_func (client, test_setup_response_200_multicast,
743 fail_unless (gst_rtsp_client_handle_message (client,
744 &request) == GST_RTSP_OK);
745 gst_rtsp_message_unset (&request);
746 expected_transport = NULL;
748 gst_rtsp_client_set_send_func (client, test_setup_response_200_multicast,
750 session_pool = gst_rtsp_client_get_session_pool (client);
751 fail_unless (session_pool != NULL);
752 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 1);
753 g_object_unref (session_pool);
755 send_teardown (client);
757 teardown_client (client);
758 g_object_unref (ctx.auth);
759 gst_rtsp_token_unref (ctx.token);
760 gst_rtsp_context_pop_current (&ctx);
766 test_response_sdp (GstRTSPClient * client, GstRTSPMessage * response,
767 gboolean close, gpointer user_data)
771 GstSDPMessage *sdp_msg;
772 const GstSDPMedia *sdp_media;
773 const GstSDPBandwidth *bw;
774 gint bandwidth_val = GPOINTER_TO_INT (user_data);
776 fail_unless (gst_rtsp_message_get_body (response, &data, &size)
778 gst_sdp_message_new (&sdp_msg);
779 fail_unless (gst_sdp_message_parse_buffer (data, size, sdp_msg)
782 /* session description */
784 fail_unless (gst_sdp_message_get_version (sdp_msg) != NULL);
786 fail_unless (gst_sdp_message_get_origin (sdp_msg) != NULL);
788 fail_unless (gst_sdp_message_get_session_name (sdp_msg) != NULL);
790 fail_unless (gst_sdp_message_times_len (sdp_msg) == 0);
792 /* verify number of medias */
793 fail_unless (gst_sdp_message_medias_len (sdp_msg) == 1);
795 /* media description */
796 sdp_media = gst_sdp_message_get_media (sdp_msg, 0);
797 fail_unless (sdp_media != NULL);
800 fail_unless (gst_sdp_media_get_media (sdp_media) != NULL);
802 /* media bandwidth */
804 fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 1);
805 bw = gst_sdp_media_get_bandwidth (sdp_media, 0);
806 fail_unless (bw != NULL);
807 fail_unless (g_strcmp0 (bw->bwtype, "AS") == 0);
808 fail_unless (bw->bandwidth == bandwidth_val);
810 fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 0);
813 gst_sdp_message_free (sdp_msg);
819 test_client_sdp (const gchar * launch_line, guint * bandwidth_val)
821 GstRTSPClient *client;
822 GstRTSPMessage request = { 0, };
825 /* simple DESCRIBE for an existing url */
826 client = setup_client (launch_line);
827 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
828 "rtsp://localhost/test") == GST_RTSP_OK);
829 str = g_strdup_printf ("%d", cseq);
830 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
833 gst_rtsp_client_set_send_func (client, test_response_sdp,
834 (gpointer) bandwidth_val, NULL);
835 fail_unless (gst_rtsp_client_handle_message (client,
836 &request) == GST_RTSP_OK);
837 gst_rtsp_message_unset (&request);
839 teardown_client (client);
842 GST_START_TEST (test_client_sdp_with_max_bitrate_tag)
844 test_client_sdp ("videotestsrc "
845 "! taginject tags=\"maximum-bitrate=(uint)50000000\" "
846 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
847 GUINT_TO_POINTER (50000));
850 /* max-bitrate=0: no bandwidth line */
851 test_client_sdp ("videotestsrc "
852 "! taginject tags=\"maximum-bitrate=(uint)0\" "
853 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
854 GUINT_TO_POINTER (0));
859 GST_START_TEST (test_client_sdp_with_bitrate_tag)
861 test_client_sdp ("videotestsrc "
862 "! taginject tags=\"bitrate=(uint)7000000\" "
863 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
864 GUINT_TO_POINTER (7000));
866 /* bitrate=0: no bandwdith line */
867 test_client_sdp ("videotestsrc "
868 "! taginject tags=\"bitrate=(uint)0\" "
869 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
870 GUINT_TO_POINTER (0));
875 GST_START_TEST (test_client_sdp_with_max_bitrate_and_bitrate_tags)
877 test_client_sdp ("videotestsrc "
878 "! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)50000000\" "
879 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
880 GUINT_TO_POINTER (50000));
882 /* max-bitrate is zero: fallback to bitrate */
883 test_client_sdp ("videotestsrc "
884 "! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)0\" "
885 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
886 GUINT_TO_POINTER (7000));
888 /* max-bitrate=bitrate=0o: no bandwidth line */
889 test_client_sdp ("videotestsrc "
890 "! taginject tags=\"bitrate=(uint)0,maximum-bitrate=(uint)0\" "
891 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
892 GUINT_TO_POINTER (0));
897 GST_START_TEST (test_client_sdp_with_no_bitrate_tags)
899 test_client_sdp ("videotestsrc "
900 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", NULL);
906 rtspclient_suite (void)
908 Suite *s = suite_create ("rtspclient");
909 TCase *tc = tcase_create ("general");
911 suite_add_tcase (s, tc);
912 tcase_set_timeout (tc, 20);
913 tcase_add_test (tc, test_request);
914 tcase_add_test (tc, test_options);
915 tcase_add_test (tc, test_describe);
916 tcase_add_test (tc, test_client_multicast_transport_404);
917 tcase_add_test (tc, test_client_multicast_transport);
918 tcase_add_test (tc, test_client_multicast_ignore_transport_specific);
919 tcase_add_test (tc, test_client_multicast_invalid_transport_specific);
920 tcase_add_test (tc, test_client_multicast_transport_specific);
921 tcase_add_test (tc, test_client_sdp_with_max_bitrate_tag);
922 tcase_add_test (tc, test_client_sdp_with_bitrate_tag);
923 tcase_add_test (tc, test_client_sdp_with_max_bitrate_and_bitrate_tags);
924 tcase_add_test (tc, test_client_sdp_with_no_bitrate_tags);
929 GST_CHECK_MAIN (rtspclient);