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;
27 static const gchar *expected_unsupported_header;
30 test_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
31 gboolean close, gpointer user_data)
33 GstRTSPStatusCode code;
35 GstRTSPVersion version;
37 fail_unless (gst_rtsp_message_get_type (response) ==
38 GST_RTSP_MESSAGE_RESPONSE);
40 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
43 fail_unless (code == GST_RTSP_STS_OK);
44 fail_unless (g_str_equal (reason, "OK"));
45 fail_unless (version == GST_RTSP_VERSION_1_0);
51 test_response_400 (GstRTSPClient * client, GstRTSPMessage * response,
52 gboolean close, gpointer user_data)
54 GstRTSPStatusCode code;
56 GstRTSPVersion version;
58 fail_unless (gst_rtsp_message_get_type (response) ==
59 GST_RTSP_MESSAGE_RESPONSE);
61 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
64 fail_unless (code == GST_RTSP_STS_BAD_REQUEST);
65 fail_unless (g_str_equal (reason, "Bad Request"));
66 fail_unless (version == GST_RTSP_VERSION_1_0);
72 test_response_404 (GstRTSPClient * client, GstRTSPMessage * response,
73 gboolean close, gpointer user_data)
75 GstRTSPStatusCode code;
77 GstRTSPVersion version;
79 fail_unless (gst_rtsp_message_get_type (response) ==
80 GST_RTSP_MESSAGE_RESPONSE);
82 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
85 fail_unless (code == GST_RTSP_STS_NOT_FOUND);
86 fail_unless (g_str_equal (reason, "Not Found"));
87 fail_unless (version == GST_RTSP_VERSION_1_0);
93 test_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
94 gboolean close, gpointer user_data)
96 GstRTSPStatusCode code;
98 GstRTSPVersion version;
100 fail_unless (gst_rtsp_message_get_type (response) ==
101 GST_RTSP_MESSAGE_RESPONSE);
103 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
106 fail_unless (code == GST_RTSP_STS_SESSION_NOT_FOUND);
107 fail_unless (g_str_equal (reason, "Session Not Found"));
108 fail_unless (version == GST_RTSP_VERSION_1_0);
114 test_response_551 (GstRTSPClient * client, GstRTSPMessage * response,
115 gboolean close, gpointer user_data)
117 GstRTSPStatusCode code;
119 GstRTSPVersion version;
122 fail_unless (gst_rtsp_message_get_type (response) ==
123 GST_RTSP_MESSAGE_RESPONSE);
125 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
128 fail_unless (code == GST_RTSP_STS_OPTION_NOT_SUPPORTED);
129 fail_unless (g_str_equal (reason, "Option not supported"));
130 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_UNSUPPORTED,
131 &options, 0) == GST_RTSP_OK);
132 fail_unless (!g_strcmp0 (expected_unsupported_header, options));
133 fail_unless (version == GST_RTSP_VERSION_1_0);
139 create_connection (GstRTSPConnection ** conn)
142 GError *error = NULL;
144 sock = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
145 G_SOCKET_PROTOCOL_TCP, &error);
146 g_assert_no_error (error);
147 fail_unless (gst_rtsp_connection_create_from_socket (sock, "127.0.0.1", 444,
148 NULL, conn) == GST_RTSP_OK);
149 g_object_unref (sock);
152 static GstRTSPClient *
153 setup_client (const gchar * launch_line)
155 GstRTSPClient *client;
156 GstRTSPSessionPool *session_pool;
157 GstRTSPMountPoints *mount_points;
158 GstRTSPMediaFactory *factory;
159 GstRTSPThreadPool *thread_pool;
161 client = gst_rtsp_client_new ();
163 session_pool = gst_rtsp_session_pool_new ();
164 gst_rtsp_client_set_session_pool (client, session_pool);
166 mount_points = gst_rtsp_mount_points_new ();
167 factory = gst_rtsp_media_factory_new ();
168 if (launch_line == NULL)
169 gst_rtsp_media_factory_set_launch (factory,
170 "videotestsrc ! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96");
172 gst_rtsp_media_factory_set_launch (factory, launch_line);
174 gst_rtsp_mount_points_add_factory (mount_points, "/test", factory);
175 gst_rtsp_client_set_mount_points (client, mount_points);
177 thread_pool = gst_rtsp_thread_pool_new ();
178 gst_rtsp_client_set_thread_pool (client, thread_pool);
180 g_object_unref (mount_points);
181 g_object_unref (session_pool);
182 g_object_unref (thread_pool);
188 teardown_client (GstRTSPClient * client)
190 gst_rtsp_client_set_thread_pool (client, NULL);
191 g_object_unref (client);
195 check_requirements_cb (GstRTSPClient * client, GstRTSPContext * ctx,
196 gchar ** req, gpointer user_data)
199 GString *result = g_string_new ("");
201 while (req[index] != NULL) {
202 if (g_strcmp0 (req[index], "test-requirements")) {
204 g_string_append (result, ", ");
205 g_string_append (result, req[index]);
210 return g_string_free (result, FALSE);
213 GST_START_TEST (test_require)
215 GstRTSPClient *client;
216 GstRTSPMessage request = { 0, };
219 client = gst_rtsp_client_new ();
221 /* require header without handler */
222 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
223 "rtsp://localhost/test") == GST_RTSP_OK);
224 str = g_strdup_printf ("test-not-supported1");
225 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
228 expected_unsupported_header = "test-not-supported1";
229 gst_rtsp_client_set_send_func (client, test_response_551, NULL, NULL);
230 fail_unless (gst_rtsp_client_handle_message (client,
231 &request) == GST_RTSP_OK);
232 gst_rtsp_message_unset (&request);
234 g_signal_connect (G_OBJECT (client), "check-requirements",
235 G_CALLBACK (check_requirements_cb), NULL);
237 /* one supported option */
238 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
239 "rtsp://localhost/test") == GST_RTSP_OK);
240 str = g_strdup_printf ("test-requirements");
241 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
244 gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
245 fail_unless (gst_rtsp_client_handle_message (client,
246 &request) == GST_RTSP_OK);
247 gst_rtsp_message_unset (&request);
249 /* unsupported option */
250 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
251 "rtsp://localhost/test") == GST_RTSP_OK);
252 str = g_strdup_printf ("test-not-supported1");
253 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
256 expected_unsupported_header = "test-not-supported1";
257 gst_rtsp_client_set_send_func (client, test_response_551, NULL, NULL);
258 fail_unless (gst_rtsp_client_handle_message (client,
259 &request) == GST_RTSP_OK);
260 gst_rtsp_message_unset (&request);
262 /* more than one unsupported options */
263 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
264 "rtsp://localhost/test") == GST_RTSP_OK);
265 str = g_strdup_printf ("test-not-supported1");
266 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
268 str = g_strdup_printf ("test-not-supported2");
269 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
272 expected_unsupported_header = "test-not-supported1, test-not-supported2";
273 gst_rtsp_client_set_send_func (client, test_response_551, NULL, NULL);
274 fail_unless (gst_rtsp_client_handle_message (client,
275 &request) == GST_RTSP_OK);
276 gst_rtsp_message_unset (&request);
278 /* supported and unsupported together */
279 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
280 "rtsp://localhost/test") == GST_RTSP_OK);
281 str = g_strdup_printf ("test-not-supported1");
282 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
284 str = g_strdup_printf ("test-requirements");
285 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
287 str = g_strdup_printf ("test-not-supported2");
288 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE, str);
291 expected_unsupported_header = "test-not-supported1, test-not-supported2";
292 gst_rtsp_client_set_send_func (client, test_response_551, NULL, NULL);
293 fail_unless (gst_rtsp_client_handle_message (client,
294 &request) == GST_RTSP_OK);
295 gst_rtsp_message_unset (&request);
297 g_object_unref (client);
302 GST_START_TEST (test_request)
304 GstRTSPClient *client;
305 GstRTSPMessage request = { 0, };
307 GstRTSPConnection *conn;
309 client = gst_rtsp_client_new ();
311 /* OPTIONS with invalid url */
312 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
313 "foopy://padoop/") == GST_RTSP_OK);
314 str = g_strdup_printf ("%d", cseq);
315 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
318 gst_rtsp_client_set_send_func (client, test_response_400, NULL, NULL);
319 fail_unless (gst_rtsp_client_handle_message (client,
320 &request) == GST_RTSP_OK);
322 gst_rtsp_message_unset (&request);
324 /* OPTIONS with unknown session id */
325 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
326 "rtsp://localhost/test") == GST_RTSP_OK);
327 str = g_strdup_printf ("%d", cseq);
328 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
330 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, "foobar");
332 gst_rtsp_client_set_send_func (client, test_response_454, NULL, NULL);
333 fail_unless (gst_rtsp_client_handle_message (client,
334 &request) == GST_RTSP_OK);
336 gst_rtsp_message_unset (&request);
338 /* OPTIONS with an absolute path instead of an absolute url */
339 /* set host information */
340 create_connection (&conn);
341 fail_unless (gst_rtsp_client_set_connection (client, conn));
342 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
343 "/test") == GST_RTSP_OK);
344 str = g_strdup_printf ("%d", cseq);
345 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
348 gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
349 fail_unless (gst_rtsp_client_handle_message (client,
350 &request) == GST_RTSP_OK);
351 gst_rtsp_message_unset (&request);
353 /* OPTIONS with an absolute path instead of an absolute url with invalid
354 * host information */
355 g_object_unref (client);
356 client = gst_rtsp_client_new ();
357 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
358 "/test") == GST_RTSP_OK);
359 str = g_strdup_printf ("%d", cseq);
360 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
363 gst_rtsp_client_set_send_func (client, test_response_400, NULL, NULL);
364 fail_unless (gst_rtsp_client_handle_message (client,
365 &request) == GST_RTSP_OK);
366 gst_rtsp_message_unset (&request);
368 g_object_unref (client);
374 test_option_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
375 gboolean close, gpointer user_data)
377 GstRTSPStatusCode code;
379 GstRTSPVersion version;
381 GstRTSPMethod methods;
383 fail_unless (gst_rtsp_message_get_type (response) ==
384 GST_RTSP_MESSAGE_RESPONSE);
386 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
389 fail_unless (code == GST_RTSP_STS_OK);
390 fail_unless (g_str_equal (reason, "OK"));
391 fail_unless (version == GST_RTSP_VERSION_1_0);
393 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
395 fail_unless (atoi (str) == cseq++);
397 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_PUBLIC, &str,
400 methods = gst_rtsp_options_from_text (str);
401 fail_if (methods == 0);
402 fail_unless (methods == (GST_RTSP_DESCRIBE |
409 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN));
414 GST_START_TEST (test_options)
416 GstRTSPClient *client;
417 GstRTSPMessage request = { 0, };
420 client = gst_rtsp_client_new ();
423 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
424 "rtsp://localhost/test") == GST_RTSP_OK);
425 str = g_strdup_printf ("%d", cseq);
426 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
429 gst_rtsp_client_set_send_func (client, test_option_response_200, NULL, NULL);
430 fail_unless (gst_rtsp_client_handle_message (client,
431 &request) == GST_RTSP_OK);
432 gst_rtsp_message_unset (&request);
434 g_object_unref (client);
439 GST_START_TEST (test_describe)
441 GstRTSPClient *client;
442 GstRTSPMessage request = { 0, };
445 client = gst_rtsp_client_new ();
447 /* simple DESCRIBE for non-existing url */
448 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
449 "rtsp://localhost/test") == GST_RTSP_OK);
450 str = g_strdup_printf ("%d", cseq);
451 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
454 gst_rtsp_client_set_send_func (client, test_response_404, NULL, NULL);
455 fail_unless (gst_rtsp_client_handle_message (client,
456 &request) == GST_RTSP_OK);
457 gst_rtsp_message_unset (&request);
459 g_object_unref (client);
461 /* simple DESCRIBE for an existing url */
462 client = setup_client (NULL);
463 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
464 "rtsp://localhost/test") == GST_RTSP_OK);
465 str = g_strdup_printf ("%d", cseq);
466 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
469 gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
470 fail_unless (gst_rtsp_client_handle_message (client,
471 &request) == GST_RTSP_OK);
472 gst_rtsp_message_unset (&request);
474 teardown_client (client);
479 static const gchar *expected_transport = NULL;
482 test_setup_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
483 gboolean close, gpointer user_data)
485 GstRTSPStatusCode code;
487 GstRTSPVersion version;
490 GstRTSPSessionPool *session_pool;
491 GstRTSPSession *session;
492 gchar **session_hdr_params;
494 fail_unless (expected_transport != NULL);
496 fail_unless_equals_int (gst_rtsp_message_get_type (response),
497 GST_RTSP_MESSAGE_RESPONSE);
499 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
502 fail_unless_equals_int (code, GST_RTSP_STS_OK);
503 fail_unless_equals_string (reason, "OK");
504 fail_unless_equals_int (version, GST_RTSP_VERSION_1_0);
506 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
508 fail_unless (atoi (str) == cseq++);
510 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_TRANSPORT,
511 &str, 0) == GST_RTSP_OK);
513 pattern = g_strdup_printf ("^%s$", expected_transport);
514 fail_unless (g_regex_match_simple (pattern, str, 0, 0),
515 "Transport '%s' doesn't match pattern '%s'", str, pattern);
518 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION,
519 &str, 0) == GST_RTSP_OK);
520 session_hdr_params = g_strsplit (str, ";", -1);
522 /* session-id value */
523 fail_unless (session_hdr_params[0] != NULL);
525 if (expected_session_timeout != 60) {
526 /* session timeout param */
527 gchar *timeout_str = g_strdup_printf ("timeout=%u",
528 expected_session_timeout);
530 fail_unless (session_hdr_params[1] != NULL);
531 g_strstrip (session_hdr_params[1]);
532 fail_unless (g_strcmp0 (session_hdr_params[1], timeout_str) == 0);
533 g_free (timeout_str);
536 session_pool = gst_rtsp_client_get_session_pool (client);
537 fail_unless (session_pool != NULL);
539 session = gst_rtsp_session_pool_find (session_pool, session_hdr_params[0]);
540 g_strfreev (session_hdr_params);
542 /* remember session id to be able to send teardown */
545 session_id = g_strdup (gst_rtsp_session_get_sessionid (session));
546 fail_unless (session_id != NULL);
548 fail_unless (session != NULL);
549 g_object_unref (session);
551 g_object_unref (session_pool);
558 test_setup_response_461 (GstRTSPClient * client,
559 GstRTSPMessage * response, gboolean close, gpointer user_data)
561 GstRTSPStatusCode code;
563 GstRTSPVersion version;
566 fail_unless (expected_transport == NULL);
568 fail_unless (gst_rtsp_message_get_type (response) ==
569 GST_RTSP_MESSAGE_RESPONSE);
571 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
574 fail_unless (code == GST_RTSP_STS_UNSUPPORTED_TRANSPORT);
575 fail_unless (g_str_equal (reason, "Unsupported transport"));
576 fail_unless (version == GST_RTSP_VERSION_1_0);
578 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
580 fail_unless (atoi (str) == cseq++);
587 test_teardown_response_200 (GstRTSPClient * client,
588 GstRTSPMessage * response, gboolean close, gpointer user_data)
590 GstRTSPStatusCode code;
592 GstRTSPVersion version;
594 fail_unless (gst_rtsp_message_get_type (response) ==
595 GST_RTSP_MESSAGE_RESPONSE);
597 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
600 fail_unless (code == GST_RTSP_STS_OK);
601 fail_unless (g_str_equal (reason, "OK"));
602 fail_unless (version == GST_RTSP_VERSION_1_0);
608 send_teardown (GstRTSPClient * client)
610 GstRTSPMessage request = { 0, };
613 fail_unless (session_id != NULL);
614 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_TEARDOWN,
615 "rtsp://localhost/test") == GST_RTSP_OK);
616 str = g_strdup_printf ("%d", cseq);
617 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
618 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, session_id);
619 gst_rtsp_client_set_send_func (client, test_teardown_response_200,
621 fail_unless (gst_rtsp_client_handle_message (client,
622 &request) == GST_RTSP_OK);
623 gst_rtsp_message_unset (&request);
628 GST_START_TEST (test_setup_tcp)
630 GstRTSPClient *client;
631 GstRTSPConnection *conn;
632 GstRTSPMessage request = { 0, };
635 client = setup_client (NULL);
636 create_connection (&conn);
637 fail_unless (gst_rtsp_client_set_connection (client, conn));
639 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
640 "rtsp://localhost/test") == GST_RTSP_OK);
641 str = g_strdup_printf ("%d", cseq);
642 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
644 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
645 "RTP/AVP/TCP;unicast");
647 gst_rtsp_client_set_send_func (client, test_setup_response_200, NULL, NULL);
649 "RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=.*;mode=\"PLAY\"";
650 fail_unless (gst_rtsp_client_handle_message (client,
651 &request) == GST_RTSP_OK);
653 gst_rtsp_message_unset (&request);
655 send_teardown (client);
656 teardown_client (client);
661 static GstRTSPClient *
662 setup_multicast_client (guint max_ttl)
664 GstRTSPClient *client;
665 GstRTSPSessionPool *session_pool;
666 GstRTSPMountPoints *mount_points;
667 GstRTSPMediaFactory *factory;
668 GstRTSPAddressPool *address_pool;
669 GstRTSPThreadPool *thread_pool;
671 client = gst_rtsp_client_new ();
673 session_pool = gst_rtsp_session_pool_new ();
674 gst_rtsp_client_set_session_pool (client, session_pool);
676 mount_points = gst_rtsp_mount_points_new ();
677 factory = gst_rtsp_media_factory_new ();
678 gst_rtsp_media_factory_set_launch (factory,
679 "audiotestsrc ! audio/x-raw,rate=44100 ! audioconvert ! rtpL16pay name=pay0");
680 address_pool = gst_rtsp_address_pool_new ();
681 fail_unless (gst_rtsp_address_pool_add_range (address_pool,
682 "233.252.0.1", "233.252.0.1", 5000, 5010, 1));
683 gst_rtsp_media_factory_set_address_pool (factory, address_pool);
684 gst_rtsp_media_factory_add_role (factory, "user",
685 "media.factory.access", G_TYPE_BOOLEAN, TRUE,
686 "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
687 gst_rtsp_mount_points_add_factory (mount_points, "/test", factory);
688 gst_rtsp_client_set_mount_points (client, mount_points);
689 gst_rtsp_media_factory_set_max_mcast_ttl (factory, max_ttl);
691 thread_pool = gst_rtsp_thread_pool_new ();
692 gst_rtsp_client_set_thread_pool (client, thread_pool);
694 g_object_unref (mount_points);
695 g_object_unref (session_pool);
696 g_object_unref (address_pool);
697 g_object_unref (thread_pool);
702 GST_START_TEST (test_client_multicast_transport_404)
704 GstRTSPClient *client;
705 GstRTSPMessage request = { 0, };
708 client = setup_multicast_client (1);
710 /* simple SETUP for non-existing url */
711 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
712 "rtsp://localhost/test2/stream=0") == GST_RTSP_OK);
713 str = g_strdup_printf ("%d", cseq);
714 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
715 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
716 "RTP/AVP;multicast");
718 gst_rtsp_client_set_send_func (client, test_response_404, NULL, NULL);
719 fail_unless (gst_rtsp_client_handle_message (client,
720 &request) == GST_RTSP_OK);
721 gst_rtsp_message_unset (&request);
723 teardown_client (client);
729 new_session_cb (GObject * client, GstRTSPSession * session, gpointer user_data)
731 GST_DEBUG ("%p: new session %p", client, session);
732 gst_rtsp_session_set_timeout (session, expected_session_timeout);
735 GST_START_TEST (test_client_multicast_transport)
737 GstRTSPClient *client;
738 GstRTSPMessage request = { 0, };
741 client = setup_multicast_client (1);
743 expected_session_timeout = 20;
744 g_signal_connect (G_OBJECT (client), "new-session",
745 G_CALLBACK (new_session_cb), NULL);
747 /* simple SETUP with a valid URI and multicast */
748 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
749 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
750 str = g_strdup_printf ("%d", cseq);
751 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
752 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
753 "RTP/AVP;multicast");
755 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
756 "ttl=1;port=5000-5001;mode=\"PLAY\"";
757 gst_rtsp_client_set_send_func (client, test_setup_response_200, NULL, NULL);
758 fail_unless (gst_rtsp_client_handle_message (client,
759 &request) == GST_RTSP_OK);
760 gst_rtsp_message_unset (&request);
761 expected_transport = NULL;
762 expected_session_timeout = 60;
764 send_teardown (client);
766 teardown_client (client);
771 GST_START_TEST (test_client_multicast_ignore_transport_specific)
773 GstRTSPClient *client;
774 GstRTSPMessage request = { 0, };
777 client = setup_multicast_client (1);
779 /* simple SETUP with a valid URI and multicast and a specific dest,
781 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
782 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
783 str = g_strdup_printf ("%d", cseq);
784 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
785 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
786 "RTP/AVP;multicast;destination=233.252.0.2;ttl=2;port=5001-5006;");
788 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
789 "ttl=1;port=5000-5001;mode=\"PLAY\"";
790 gst_rtsp_client_set_send_func (client, test_setup_response_200, NULL, NULL);
791 fail_unless (gst_rtsp_client_handle_message (client,
792 &request) == GST_RTSP_OK);
793 gst_rtsp_message_unset (&request);
794 expected_transport = NULL;
796 send_teardown (client);
798 teardown_client (client);
804 multicast_transport_specific (void)
806 GstRTSPClient *client;
807 GstRTSPMessage request = { 0, };
809 GstRTSPSessionPool *session_pool;
810 GstRTSPContext ctx = { NULL };
812 client = setup_multicast_client (1);
815 ctx.auth = gst_rtsp_auth_new ();
817 gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
818 G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
820 gst_rtsp_context_push_current (&ctx);
822 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
823 "ttl=1;port=5000-5001;mode=\"PLAY\"";
825 /* simple SETUP with a valid URI */
826 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
827 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
828 str = g_strdup_printf ("%d", cseq);
829 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
830 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
833 gst_rtsp_client_set_send_func (client, test_setup_response_200, NULL, NULL);
834 fail_unless (gst_rtsp_client_handle_message (client,
835 &request) == GST_RTSP_OK);
836 gst_rtsp_message_unset (&request);
838 gst_rtsp_client_set_send_func (client, test_setup_response_200, NULL, NULL);
839 session_pool = gst_rtsp_client_get_session_pool (client);
840 fail_unless (session_pool != NULL);
841 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 1);
842 g_object_unref (session_pool);
844 /* send PLAY request */
845 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_PLAY,
846 "rtsp://localhost/test") == GST_RTSP_OK);
847 str = g_strdup_printf ("%d", cseq);
848 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
849 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, session_id);
850 gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
851 fail_unless (gst_rtsp_client_handle_message (client,
852 &request) == GST_RTSP_OK);
853 gst_rtsp_message_unset (&request);
855 send_teardown (client);
856 teardown_client (client);
857 g_object_unref (ctx.auth);
858 gst_rtsp_token_unref (ctx.token);
859 gst_rtsp_context_pop_current (&ctx);
862 /* CASE: multicast address requested by the client exists in the address pool */
863 GST_START_TEST (test_client_multicast_transport_specific)
865 expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
866 "ttl=1;port=5000-5001;mode=\"PLAY\"";
867 multicast_transport_specific ();
868 expected_transport = NULL;
873 /* CASE: multicast address requested by the client does not exist in the address pool */
874 GST_START_TEST (test_client_multicast_transport_specific_no_address_in_pool)
876 expected_transport = "RTP/AVP;multicast;destination=234.252.0.3;"
877 "ttl=1;port=6000-6001;mode=\"PLAY\"";
878 multicast_transport_specific ();
879 expected_transport = NULL;
885 test_response_sdp (GstRTSPClient * client, GstRTSPMessage * response,
886 gboolean close, gpointer user_data)
890 GstSDPMessage *sdp_msg;
891 const GstSDPMedia *sdp_media;
892 const GstSDPBandwidth *bw;
893 gint bandwidth_val = GPOINTER_TO_INT (user_data);
895 fail_unless (gst_rtsp_message_get_body (response, &data, &size)
897 gst_sdp_message_new (&sdp_msg);
898 fail_unless (gst_sdp_message_parse_buffer (data, size, sdp_msg)
901 /* session description */
903 fail_unless (gst_sdp_message_get_version (sdp_msg) != NULL);
905 fail_unless (gst_sdp_message_get_origin (sdp_msg) != NULL);
907 fail_unless (gst_sdp_message_get_session_name (sdp_msg) != NULL);
909 fail_unless (gst_sdp_message_times_len (sdp_msg) == 0);
911 /* verify number of medias */
912 fail_unless (gst_sdp_message_medias_len (sdp_msg) == 1);
914 /* media description */
915 sdp_media = gst_sdp_message_get_media (sdp_msg, 0);
916 fail_unless (sdp_media != NULL);
919 fail_unless (gst_sdp_media_get_media (sdp_media) != NULL);
921 /* media bandwidth */
923 fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 1);
924 bw = gst_sdp_media_get_bandwidth (sdp_media, 0);
925 fail_unless (bw != NULL);
926 fail_unless (g_strcmp0 (bw->bwtype, "AS") == 0);
927 fail_unless (bw->bandwidth == bandwidth_val);
929 fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 0);
932 gst_sdp_message_free (sdp_msg);
938 test_client_sdp (const gchar * launch_line, guint * bandwidth_val)
940 GstRTSPClient *client;
941 GstRTSPMessage request = { 0, };
944 /* simple DESCRIBE for an existing url */
945 client = setup_client (launch_line);
946 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
947 "rtsp://localhost/test") == GST_RTSP_OK);
948 str = g_strdup_printf ("%d", cseq);
949 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
952 gst_rtsp_client_set_send_func (client, test_response_sdp,
953 (gpointer) bandwidth_val, NULL);
954 fail_unless (gst_rtsp_client_handle_message (client,
955 &request) == GST_RTSP_OK);
956 gst_rtsp_message_unset (&request);
958 teardown_client (client);
961 GST_START_TEST (test_client_sdp_with_max_bitrate_tag)
963 test_client_sdp ("videotestsrc "
964 "! taginject tags=\"maximum-bitrate=(uint)50000000\" "
965 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
966 GUINT_TO_POINTER (50000));
969 /* max-bitrate=0: no bandwidth line */
970 test_client_sdp ("videotestsrc "
971 "! taginject tags=\"maximum-bitrate=(uint)0\" "
972 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
973 GUINT_TO_POINTER (0));
978 GST_START_TEST (test_client_sdp_with_bitrate_tag)
980 test_client_sdp ("videotestsrc "
981 "! taginject tags=\"bitrate=(uint)7000000\" "
982 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
983 GUINT_TO_POINTER (7000));
985 /* bitrate=0: no bandwdith line */
986 test_client_sdp ("videotestsrc "
987 "! taginject tags=\"bitrate=(uint)0\" "
988 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
989 GUINT_TO_POINTER (0));
994 GST_START_TEST (test_client_sdp_with_max_bitrate_and_bitrate_tags)
996 test_client_sdp ("videotestsrc "
997 "! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)50000000\" "
998 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
999 GUINT_TO_POINTER (50000));
1001 /* max-bitrate is zero: fallback to bitrate */
1002 test_client_sdp ("videotestsrc "
1003 "! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)0\" "
1004 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
1005 GUINT_TO_POINTER (7000));
1007 /* max-bitrate=bitrate=0o: no bandwidth line */
1008 test_client_sdp ("videotestsrc "
1009 "! taginject tags=\"bitrate=(uint)0,maximum-bitrate=(uint)0\" "
1010 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
1011 GUINT_TO_POINTER (0));
1016 GST_START_TEST (test_client_sdp_with_no_bitrate_tags)
1018 test_client_sdp ("videotestsrc "
1019 "! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", NULL);
1025 mcast_transport_two_clients (gboolean shared, const gchar * transport1,
1026 const gchar * expected_transport1, const gchar * addr1,
1027 const gchar * transport2, const gchar * expected_transport2,
1028 const gchar * addr2)
1030 GstRTSPClient *client1, *client2;
1031 GstRTSPMessage request = { 0, };
1033 GstRTSPSessionPool *session_pool;
1034 GstRTSPContext ctx = { NULL };
1035 GstRTSPContext ctx2 = { NULL };
1036 GstRTSPMountPoints *mount_points;
1037 GstRTSPMediaFactory *factory;
1038 GstRTSPAddressPool *address_pool;
1039 GstRTSPThreadPool *thread_pool;
1041 gchar *client_addr = NULL;
1043 mount_points = gst_rtsp_mount_points_new ();
1044 factory = gst_rtsp_media_factory_new ();
1046 gst_rtsp_media_factory_set_shared (factory, TRUE);
1047 gst_rtsp_media_factory_set_max_mcast_ttl (factory, 5);
1048 gst_rtsp_media_factory_set_launch (factory,
1049 "audiotestsrc ! audio/x-raw,rate=44100 ! audioconvert ! rtpL16pay name=pay0");
1050 address_pool = gst_rtsp_address_pool_new ();
1051 fail_unless (gst_rtsp_address_pool_add_range (address_pool,
1052 "233.252.0.1", "233.252.0.1", 5000, 5001, 1));
1053 gst_rtsp_media_factory_set_address_pool (factory, address_pool);
1054 gst_rtsp_media_factory_add_role (factory, "user",
1055 "media.factory.access", G_TYPE_BOOLEAN, TRUE,
1056 "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
1057 gst_rtsp_mount_points_add_factory (mount_points, "/test", factory);
1058 session_pool = gst_rtsp_session_pool_new ();
1059 thread_pool = gst_rtsp_thread_pool_new ();
1061 /* first multicast client with transport specific request */
1062 client1 = gst_rtsp_client_new ();
1063 gst_rtsp_client_set_session_pool (client1, session_pool);
1064 gst_rtsp_client_set_mount_points (client1, mount_points);
1065 gst_rtsp_client_set_thread_pool (client1, thread_pool);
1067 ctx.client = client1;
1068 ctx.auth = gst_rtsp_auth_new ();
1070 gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
1071 G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
1073 gst_rtsp_context_push_current (&ctx);
1075 expected_transport = expected_transport1;
1077 /* send SETUP request */
1078 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
1079 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
1080 str = g_strdup_printf ("%d", cseq);
1081 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
1082 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT, transport1);
1084 gst_rtsp_client_set_send_func (client1, test_setup_response_200, NULL, NULL);
1085 fail_unless (gst_rtsp_client_handle_message (client1,
1086 &request) == GST_RTSP_OK);
1087 gst_rtsp_message_unset (&request);
1088 expected_transport = NULL;
1090 /* send PLAY request */
1091 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_PLAY,
1092 "rtsp://localhost/test") == GST_RTSP_OK);
1093 str = g_strdup_printf ("%d", cseq);
1094 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
1095 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, session_id);
1096 gst_rtsp_client_set_send_func (client1, test_response_200, NULL, NULL);
1097 fail_unless (gst_rtsp_client_handle_message (client1,
1098 &request) == GST_RTSP_OK);
1099 gst_rtsp_message_unset (&request);
1102 client_addr = gst_rtsp_stream_get_multicast_client_addresses (ctx.stream);
1103 fail_if (client_addr == NULL);
1104 fail_unless (g_str_equal (client_addr, addr1));
1105 g_free (client_addr);
1107 gst_rtsp_context_pop_current (&ctx);
1108 session_id1 = g_strdup (session_id);
1110 /* second multicast client with transport specific request */
1112 client2 = gst_rtsp_client_new ();
1113 gst_rtsp_client_set_session_pool (client2, session_pool);
1114 gst_rtsp_client_set_mount_points (client2, mount_points);
1115 gst_rtsp_client_set_thread_pool (client2, thread_pool);
1117 ctx2.client = client2;
1118 ctx2.auth = gst_rtsp_auth_new ();
1120 gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
1121 G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
1123 gst_rtsp_context_push_current (&ctx2);
1125 expected_transport = expected_transport2;
1127 /* send SETUP request */
1128 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
1129 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
1130 str = g_strdup_printf ("%d", cseq);
1131 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
1132 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT, transport2);
1134 gst_rtsp_client_set_send_func (client2, test_setup_response_200, NULL, NULL);
1135 fail_unless (gst_rtsp_client_handle_message (client2,
1136 &request) == GST_RTSP_OK);
1137 gst_rtsp_message_unset (&request);
1138 expected_transport = NULL;
1140 /* send PLAY request */
1141 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_PLAY,
1142 "rtsp://localhost/test") == GST_RTSP_OK);
1143 str = g_strdup_printf ("%d", cseq);
1144 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
1145 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, session_id);
1146 gst_rtsp_client_set_send_func (client2, test_response_200, NULL, NULL);
1147 fail_unless (gst_rtsp_client_handle_message (client2,
1148 &request) == GST_RTSP_OK);
1149 gst_rtsp_message_unset (&request);
1151 /* check addresses */
1152 client_addr = gst_rtsp_stream_get_multicast_client_addresses (ctx2.stream);
1153 fail_if (client_addr == NULL);
1155 if (g_str_equal (addr1, addr2)) {
1156 fail_unless (g_str_equal (client_addr, addr1));
1158 gchar *addr_str = g_strdup_printf ("%s,%s", addr2, addr1);
1159 fail_unless (g_str_equal (client_addr, addr_str));
1163 fail_unless (g_str_equal (client_addr, addr2));
1165 g_free (client_addr);
1167 send_teardown (client2);
1168 gst_rtsp_context_pop_current (&ctx2);
1170 gst_rtsp_context_push_current (&ctx);
1171 session_id = session_id1;
1172 send_teardown (client1);
1173 gst_rtsp_context_pop_current (&ctx);
1175 teardown_client (client1);
1176 teardown_client (client2);
1177 g_object_unref (ctx.auth);
1178 g_object_unref (ctx2.auth);
1179 gst_rtsp_token_unref (ctx.token);
1180 gst_rtsp_token_unref (ctx2.token);
1181 g_object_unref (mount_points);
1182 g_object_unref (session_pool);
1183 g_object_unref (address_pool);
1184 g_object_unref (thread_pool);
1187 /* test if two multicast clients can choose different transport settings
1188 * CASE: media is shared */
1190 (test_client_multicast_transport_specific_two_clients_shared_media) {
1191 const gchar *transport_client_1 = "RTP/AVP;multicast;destination=233.252.0.1;"
1192 "ttl=1;port=5000-5001;mode=\"PLAY\"";
1193 const gchar *expected_transport_1 = transport_client_1;
1194 const gchar *addr_client_1 = "233.252.0.1:5000";
1196 const gchar *transport_client_2 = "RTP/AVP;multicast;destination=233.252.0.2;"
1197 "ttl=1;port=5002-5003;mode=\"PLAY\"";
1198 const gchar *expected_transport_2 = transport_client_2;
1199 const gchar *addr_client_2 = "233.252.0.2:5002";
1201 mcast_transport_two_clients (TRUE, transport_client_1,
1202 expected_transport_1, addr_client_1, transport_client_2,
1203 expected_transport_2, addr_client_2);
1208 /* test if two multicast clients can choose different transport settings
1209 * CASE: media is not shared */
1210 GST_START_TEST (test_client_multicast_transport_specific_two_clients)
1212 const gchar *transport_client_1 = "RTP/AVP;multicast;destination=233.252.0.1;"
1213 "ttl=1;port=5000-5001;mode=\"PLAY\"";
1214 const gchar *expected_transport_1 = transport_client_1;
1215 const gchar *addr_client_1 = "233.252.0.1:5000";
1217 const gchar *transport_client_2 = "RTP/AVP;multicast;destination=233.252.0.2;"
1218 "ttl=1;port=5002-5003;mode=\"PLAY\"";
1219 const gchar *expected_transport_2 = transport_client_2;
1220 const gchar *addr_client_2 = "233.252.0.2:5002";
1222 mcast_transport_two_clients (FALSE, transport_client_1,
1223 expected_transport_1, addr_client_1, transport_client_2,
1224 expected_transport_2, addr_client_2);
1229 /* test if two multicast clients can choose the same transport settings.
1230 * CASE: media is shared */
1232 (test_client_multicast_transport_specific_two_clients_shared_media_same_transport)
1235 const gchar *transport_client_1 = "RTP/AVP;multicast;destination=233.252.0.1;"
1236 "ttl=1;port=5000-5001;mode=\"PLAY\"";
1237 const gchar *expected_transport_1 = transport_client_1;
1238 const gchar *addr_client_1 = "233.252.0.1:5000";
1240 const gchar *transport_client_2 = transport_client_1;
1241 const gchar *expected_transport_2 = expected_transport_1;
1242 const gchar *addr_client_2 = addr_client_1;
1244 mcast_transport_two_clients (TRUE, transport_client_1,
1245 expected_transport_1, addr_client_1, transport_client_2,
1246 expected_transport_2, addr_client_2);
1251 /* test if two multicast clients get the same transport settings without
1252 * requesting specific transport.
1253 * CASE: media is shared */
1254 GST_START_TEST (test_client_multicast_two_clients_shared_media)
1256 const gchar *transport_client_1 = "RTP/AVP;multicast;mode=\"PLAY\"";
1257 const gchar *expected_transport_1 =
1258 "RTP/AVP;multicast;destination=233.252.0.1;"
1259 "ttl=1;port=5000-5001;mode=\"PLAY\"";
1260 const gchar *addr_client_1 = "233.252.0.1:5000";
1262 const gchar *transport_client_2 = transport_client_1;
1263 const gchar *expected_transport_2 = expected_transport_1;
1264 const gchar *addr_client_2 = addr_client_1;
1266 mcast_transport_two_clients (TRUE, transport_client_1,
1267 expected_transport_1, addr_client_1, transport_client_2,
1268 expected_transport_2, addr_client_2);
1273 /* test if two multicast clients get the different transport settings: the first client
1274 * requests the specific transport configuration while the second client lets
1275 * the server select the multicast address and the ports.
1276 * CASE: media is shared */
1278 (test_client_multicast_two_clients_first_specific_transport_shared_media) {
1279 const gchar *transport_client_1 = "RTP/AVP;multicast;destination=233.252.0.1;"
1280 "ttl=1;port=5000-5001;mode=\"PLAY\"";
1281 const gchar *expected_transport_1 = transport_client_1;
1282 const gchar *addr_client_1 = "233.252.0.1:5000";
1284 const gchar *transport_client_2 = "RTP/AVP;multicast;mode=\"PLAY\"";
1285 const gchar *expected_transport_2 = expected_transport_1;
1286 const gchar *addr_client_2 = addr_client_1;
1288 mcast_transport_two_clients (TRUE, transport_client_1,
1289 expected_transport_1, addr_client_1, transport_client_2,
1290 expected_transport_2, addr_client_2);
1294 /* test if two multicast clients get the different transport settings: the first client lets
1295 * the server select the multicast address and the ports while the second client requests
1296 * the specific transport configuration.
1297 * CASE: media is shared */
1299 (test_client_multicast_two_clients_second_specific_transport_shared_media) {
1300 const gchar *transport_client_1 = "RTP/AVP;multicast;mode=\"PLAY\"";
1301 const gchar *expected_transport_1 =
1302 "RTP/AVP;multicast;destination=233.252.0.1;"
1303 "ttl=1;port=5000-5001;mode=\"PLAY\"";
1304 const gchar *addr_client_1 = "233.252.0.1:5000";
1306 const gchar *transport_client_2 = "RTP/AVP;multicast;destination=233.252.0.2;"
1307 "ttl=2;port=5004-5005;mode=\"PLAY\"";
1308 const gchar *expected_transport_2 = transport_client_2;
1309 const gchar *addr_client_2 = "233.252.0.2:5004";
1311 mcast_transport_two_clients (TRUE, transport_client_1,
1312 expected_transport_1, addr_client_1, transport_client_2,
1313 expected_transport_2, addr_client_2);
1318 /* test if the maximum ttl multicast value is chosen by the server
1319 * CASE: the first client provides the highest ttl value */
1320 GST_START_TEST (test_client_multicast_max_ttl_first_client)
1322 const gchar *transport_client_1 = "RTP/AVP;multicast;destination=233.252.0.1;"
1323 "ttl=3;port=5000-5001;mode=\"PLAY\"";
1324 const gchar *expected_transport_1 = transport_client_1;
1325 const gchar *addr_client_1 = "233.252.0.1:5000";
1327 const gchar *transport_client_2 = "RTP/AVP;multicast;destination=233.252.0.2;"
1328 "ttl=1;port=5002-5003;mode=\"PLAY\"";
1329 const gchar *expected_transport_2 =
1330 "RTP/AVP;multicast;destination=233.252.0.2;"
1331 "ttl=3;port=5002-5003;mode=\"PLAY\"";
1332 const gchar *addr_client_2 = "233.252.0.2:5002";
1334 mcast_transport_two_clients (TRUE, transport_client_1,
1335 expected_transport_1, addr_client_1, transport_client_2,
1336 expected_transport_2, addr_client_2);
1341 /* test if the maximum ttl multicast value is chosen by the server
1342 * CASE: the second client provides the highest ttl value */
1343 GST_START_TEST (test_client_multicast_max_ttl_second_client)
1345 const gchar *transport_client_1 = "RTP/AVP;multicast;destination=233.252.0.1;"
1346 "ttl=2;port=5000-5001;mode=\"PLAY\"";
1347 const gchar *expected_transport_1 = transport_client_1;
1348 const gchar *addr_client_1 = "233.252.0.1:5000";
1350 const gchar *transport_client_2 = "RTP/AVP;multicast;destination=233.252.0.2;"
1351 "ttl=4;port=5002-5003;mode=\"PLAY\"";
1352 const gchar *expected_transport_2 = transport_client_2;
1353 const gchar *addr_client_2 = "233.252.0.2:5002";
1355 mcast_transport_two_clients (TRUE, transport_client_1,
1356 expected_transport_1, addr_client_1, transport_client_2,
1357 expected_transport_2, addr_client_2);
1361 GST_START_TEST (test_client_multicast_invalid_ttl)
1363 GstRTSPClient *client;
1364 GstRTSPMessage request = { 0, };
1366 GstRTSPSessionPool *session_pool;
1367 GstRTSPContext ctx = { NULL };
1369 client = setup_multicast_client (3);
1371 ctx.client = client;
1372 ctx.auth = gst_rtsp_auth_new ();
1374 gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
1375 G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
1377 gst_rtsp_context_push_current (&ctx);
1379 /* simple SETUP with an invalid ttl=0 */
1380 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
1381 "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
1382 str = g_strdup_printf ("%d", cseq);
1383 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
1384 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
1385 "RTP/AVP;multicast;destination=233.252.0.1;ttl=0;port=5000-5001;");
1387 gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
1388 fail_unless (gst_rtsp_client_handle_message (client,
1389 &request) == GST_RTSP_OK);
1390 gst_rtsp_message_unset (&request);
1392 session_pool = gst_rtsp_client_get_session_pool (client);
1393 fail_unless (session_pool != NULL);
1394 fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
1395 g_object_unref (session_pool);
1397 teardown_client (client);
1398 g_object_unref (ctx.auth);
1399 gst_rtsp_token_unref (ctx.token);
1400 gst_rtsp_context_pop_current (&ctx);
1406 rtspclient_suite (void)
1408 Suite *s = suite_create ("rtspclient");
1409 TCase *tc = tcase_create ("general");
1411 suite_add_tcase (s, tc);
1412 tcase_set_timeout (tc, 20);
1413 tcase_add_test (tc, test_require);
1414 tcase_add_test (tc, test_request);
1415 tcase_add_test (tc, test_options);
1416 tcase_add_test (tc, test_describe);
1417 tcase_add_test (tc, test_setup_tcp);
1418 tcase_add_test (tc, test_client_multicast_transport_404);
1419 tcase_add_test (tc, test_client_multicast_transport);
1420 tcase_add_test (tc, test_client_multicast_ignore_transport_specific);
1421 tcase_add_test (tc, test_client_multicast_transport_specific);
1422 tcase_add_test (tc, test_client_sdp_with_max_bitrate_tag);
1423 tcase_add_test (tc, test_client_sdp_with_bitrate_tag);
1424 tcase_add_test (tc, test_client_sdp_with_max_bitrate_and_bitrate_tags);
1425 tcase_add_test (tc, test_client_sdp_with_no_bitrate_tags);
1427 test_client_multicast_transport_specific_two_clients_shared_media);
1428 tcase_add_test (tc, test_client_multicast_transport_specific_two_clients);
1430 test_client_multicast_transport_specific_two_clients_shared_media_same_transport);
1431 tcase_add_test (tc, test_client_multicast_two_clients_shared_media);
1433 test_client_multicast_two_clients_first_specific_transport_shared_media);
1435 test_client_multicast_two_clients_second_specific_transport_shared_media);
1437 test_client_multicast_transport_specific_no_address_in_pool);
1438 tcase_add_test (tc, test_client_multicast_max_ttl_first_client);
1439 tcase_add_test (tc, test_client_multicast_max_ttl_second_client);
1440 tcase_add_test (tc, test_client_multicast_invalid_ttl);
1445 GST_CHECK_MAIN (rtspclient);