summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatricia Muscalu <patricia@axis.com>2018-07-24 09:35:46 +0200
committerSebastian Dröge <sebastian@centricular.com>2018-08-14 14:10:20 +0300
commit7f0ae77e400fb8a0462a76a5dd2e63e12c4a2e52 (patch)
tree52d4bf5e857359b8c5b2b3e646c65bf517195772 /tests
parent33570944401747f44d8ebfec535350651413fb92 (diff)
Add new API for setting/getting maximum multicast ttl value
https://bugzilla.gnome.org/show_bug.cgi?id=793441
Diffstat (limited to 'tests')
-rw-r--r--tests/check/gst/client.c267
-rw-r--r--tests/check/gst/mediafactory.c58
2 files changed, 211 insertions, 114 deletions
diff --git a/tests/check/gst/client.c b/tests/check/gst/client.c
index 4adf3d18c9..ab95509f93 100644
--- a/tests/check/gst/client.c
+++ b/tests/check/gst/client.c
@@ -525,7 +525,6 @@ test_setup_response_200_multicast (GstRTSPClient * client,
session_pool = gst_rtsp_client_get_session_pool (client);
fail_unless (session_pool != NULL);
- fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 1);
session = gst_rtsp_session_pool_find (session_pool, session_hdr_params[0]);
g_strfreev (session_hdr_params);
@@ -727,117 +726,6 @@ GST_START_TEST (test_client_multicast_ignore_transport_specific)
GST_END_TEST;
-static gboolean
-test_setup_response_461 (GstRTSPClient * client,
- GstRTSPMessage * response, gboolean close, gpointer user_data)
-{
- GstRTSPStatusCode code;
- const gchar *reason;
- GstRTSPVersion version;
- gchar *str;
-
- fail_unless (expected_transport == NULL);
-
- fail_unless (gst_rtsp_message_get_type (response) ==
- GST_RTSP_MESSAGE_RESPONSE);
-
- fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
- &version)
- == GST_RTSP_OK);
- fail_unless (code == GST_RTSP_STS_UNSUPPORTED_TRANSPORT);
- fail_unless (g_str_equal (reason, "Unsupported transport"));
- fail_unless (version == GST_RTSP_VERSION_1_0);
-
- fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
- 0) == GST_RTSP_OK);
- fail_unless (atoi (str) == cseq++);
-
-
- return TRUE;
-}
-
-GST_START_TEST (test_client_multicast_invalid_transport_specific)
-{
- GstRTSPClient *client;
- GstRTSPMessage request = { 0, };
- gchar *str;
- GstRTSPSessionPool *session_pool;
- GstRTSPContext ctx = { NULL };
-
- client = setup_multicast_client ();
-
- ctx.client = client;
- ctx.auth = gst_rtsp_auth_new ();
- ctx.token =
- gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
- G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
- "user", NULL);
- gst_rtsp_context_push_current (&ctx);
-
- /* simple SETUP with a valid URI and multicast, but an invalid ip */
- fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
- "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
- str = g_strdup_printf ("%d", cseq);
- gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
- gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
- "RTP/AVP;multicast;destination=233.252.0.2;ttl=1;port=5000-5001;");
-
- gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
- fail_unless (gst_rtsp_client_handle_message (client,
- &request) == GST_RTSP_OK);
- gst_rtsp_message_unset (&request);
-
- session_pool = gst_rtsp_client_get_session_pool (client);
- fail_unless (session_pool != NULL);
- fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
- g_object_unref (session_pool);
-
-
- /* simple SETUP with a valid URI and multicast, but an invalid prt */
- fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
- "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
- str = g_strdup_printf ("%d", cseq);
- gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
- gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
- "RTP/AVP;multicast;destination=233.252.0.1;ttl=1;port=6000-6001;");
-
- gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
- fail_unless (gst_rtsp_client_handle_message (client,
- &request) == GST_RTSP_OK);
- gst_rtsp_message_unset (&request);
-
- session_pool = gst_rtsp_client_get_session_pool (client);
- fail_unless (session_pool != NULL);
- fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
- g_object_unref (session_pool);
-
-
- /* simple SETUP with a valid URI and multicast, but an invalid ttl */
- fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
- "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
- str = g_strdup_printf ("%d", cseq);
- gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
- gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
- "RTP/AVP;multicast;destination=233.252.0.1;ttl=2;port=5000-5001;");
-
- gst_rtsp_client_set_send_func (client, test_setup_response_461, NULL, NULL);
- fail_unless (gst_rtsp_client_handle_message (client,
- &request) == GST_RTSP_OK);
- gst_rtsp_message_unset (&request);
-
- session_pool = gst_rtsp_client_get_session_pool (client);
- fail_unless (session_pool != NULL);
- fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 0);
- g_object_unref (session_pool);
-
- teardown_client (client);
- g_object_unref (ctx.auth);
- gst_rtsp_token_unref (ctx.token);
- gst_rtsp_context_pop_current (&ctx);
-}
-
-GST_END_TEST;
-
GST_START_TEST (test_client_multicast_transport_specific)
{
GstRTSPClient *client;
@@ -859,7 +747,7 @@ GST_START_TEST (test_client_multicast_transport_specific)
expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
"ttl=1;port=5000-5001;mode=\"PLAY\"";
- /* simple SETUP with a valid URI and multicast, but an invalid ip */
+ /* simple SETUP with a valid URI */
fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
"rtsp://localhost/test/stream=0") == GST_RTSP_OK);
str = g_strdup_printf ("%d", cseq);
@@ -1031,6 +919,156 @@ GST_START_TEST (test_client_sdp_with_no_bitrate_tags)
GST_END_TEST;
+static void
+mcast_transport_specific_two_clients (gboolean shared)
+{
+ GstRTSPClient *client, *client2;
+ GstRTSPMessage request = { 0, };
+ gchar *str;
+ GstRTSPSessionPool *session_pool;
+ GstRTSPContext ctx = { NULL };
+ GstRTSPContext ctx2 = { NULL };
+ GstRTSPMountPoints *mount_points;
+ GstRTSPMediaFactory *factory;
+ GstRTSPAddressPool *address_pool;
+ GstRTSPThreadPool *thread_pool;
+ gchar *session_id1;
+
+ mount_points = gst_rtsp_mount_points_new ();
+ factory = gst_rtsp_media_factory_new ();
+ if (shared)
+ gst_rtsp_media_factory_set_shared (factory, TRUE);
+ gst_rtsp_media_factory_set_max_mcast_ttl (factory, 5);
+ gst_rtsp_media_factory_set_launch (factory,
+ "audiotestsrc ! audio/x-raw,rate=44100 ! audioconvert ! rtpL16pay name=pay0");
+ address_pool = gst_rtsp_address_pool_new ();
+ fail_unless (gst_rtsp_address_pool_add_range (address_pool,
+ "233.252.0.1", "233.252.0.1", 5000, 5001, 1));
+ gst_rtsp_media_factory_set_address_pool (factory, address_pool);
+ gst_rtsp_media_factory_add_role (factory, "user",
+ "media.factory.access", G_TYPE_BOOLEAN, TRUE,
+ "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
+ gst_rtsp_mount_points_add_factory (mount_points, "/test", factory);
+ session_pool = gst_rtsp_session_pool_new ();
+ thread_pool = gst_rtsp_thread_pool_new ();
+
+ /* first multicast client with transport specific request */
+ client = gst_rtsp_client_new ();
+ gst_rtsp_client_set_session_pool (client, session_pool);
+ gst_rtsp_client_set_mount_points (client, mount_points);
+ gst_rtsp_client_set_thread_pool (client, thread_pool);
+
+ ctx.client = client;
+ ctx.auth = gst_rtsp_auth_new ();
+ ctx.token =
+ gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
+ G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
+ "user", NULL);
+ gst_rtsp_context_push_current (&ctx);
+
+ expected_transport = "RTP/AVP;multicast;destination=233.252.0.1;"
+ "ttl=1;port=5000-5001;mode=\"PLAY\"";
+
+ /* send SETUP request */
+ fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
+ "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
+ str = g_strdup_printf ("%d", cseq);
+ gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
+ gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
+ expected_transport);
+
+ gst_rtsp_client_set_send_func (client, test_setup_response_200_multicast,
+ NULL, NULL);
+ fail_unless (gst_rtsp_client_handle_message (client,
+ &request) == GST_RTSP_OK);
+ gst_rtsp_message_unset (&request);
+ expected_transport = NULL;
+
+ /* send PLAY request */
+ fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_PLAY,
+ "rtsp://localhost/test") == GST_RTSP_OK);
+ str = g_strdup_printf ("%d", cseq);
+ gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
+ gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, session_id);
+ gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL);
+ fail_unless (gst_rtsp_client_handle_message (client,
+ &request) == GST_RTSP_OK);
+ gst_rtsp_message_unset (&request);
+ gst_rtsp_context_pop_current (&ctx);
+ session_id1 = session_id;
+
+ /* second multicast client with transport specific request */
+ cseq = 0;
+ client2 = gst_rtsp_client_new ();
+ gst_rtsp_client_set_session_pool (client2, session_pool);
+ gst_rtsp_client_set_mount_points (client2, mount_points);
+ gst_rtsp_client_set_thread_pool (client2, thread_pool);
+
+ ctx2.client = client2;
+ ctx2.auth = gst_rtsp_auth_new ();
+ ctx2.token =
+ gst_rtsp_token_new (GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS,
+ G_TYPE_BOOLEAN, TRUE, GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
+ "user", NULL);
+ gst_rtsp_context_push_current (&ctx2);
+
+ expected_transport = "RTP/AVP;multicast;destination=233.252.0.2;"
+ "ttl=1;port=5002-5003;mode=\"PLAY\"";
+
+ /* send SETUP request */
+ fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
+ "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
+ str = g_strdup_printf ("%d", cseq);
+ gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
+ gst_rtsp_message_add_header (&request, GST_RTSP_HDR_TRANSPORT,
+ expected_transport);
+
+ gst_rtsp_client_set_send_func (client2, test_setup_response_200_multicast,
+ NULL, NULL);
+ fail_unless (gst_rtsp_client_handle_message (client2,
+ &request) == GST_RTSP_OK);
+ gst_rtsp_message_unset (&request);
+ expected_transport = NULL;
+
+ /* send PLAY request */
+ fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_PLAY,
+ "rtsp://localhost/test") == GST_RTSP_OK);
+ str = g_strdup_printf ("%d", cseq);
+ gst_rtsp_message_take_header (&request, GST_RTSP_HDR_CSEQ, str);
+ gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, session_id);
+ gst_rtsp_client_set_send_func (client2, test_response_200, NULL, NULL);
+ fail_unless (gst_rtsp_client_handle_message (client2,
+ &request) == GST_RTSP_OK);
+ gst_rtsp_message_unset (&request);
+
+ send_teardown (client2);
+ gst_rtsp_context_pop_current (&ctx2);
+
+ gst_rtsp_context_push_current (&ctx);
+ session_id = session_id1;
+ send_teardown (client);
+ gst_rtsp_context_pop_current (&ctx);
+
+ teardown_client (client);
+ teardown_client (client2);
+ g_object_unref (ctx.auth);
+ g_object_unref (ctx2.auth);
+ gst_rtsp_token_unref (ctx.token);
+ gst_rtsp_token_unref (ctx2.token);
+ g_object_unref (mount_points);
+ g_object_unref (session_pool);
+ g_object_unref (address_pool);
+ g_object_unref (thread_pool);
+}
+
+/* test if two multicast clients can choose different transport settings */
+GST_START_TEST
+ (test_client_multicast_transport_specific_two_clients_shared_media) {
+ mcast_transport_specific_two_clients (TRUE);
+}
+
+GST_END_TEST;
+
static Suite *
rtspclient_suite (void)
{
@@ -1046,12 +1084,13 @@ rtspclient_suite (void)
tcase_add_test (tc, test_client_multicast_transport_404);
tcase_add_test (tc, test_client_multicast_transport);
tcase_add_test (tc, test_client_multicast_ignore_transport_specific);
- tcase_add_test (tc, test_client_multicast_invalid_transport_specific);
tcase_add_test (tc, test_client_multicast_transport_specific);
tcase_add_test (tc, test_client_sdp_with_max_bitrate_tag);
tcase_add_test (tc, test_client_sdp_with_bitrate_tag);
tcase_add_test (tc, test_client_sdp_with_max_bitrate_and_bitrate_tags);
tcase_add_test (tc, test_client_sdp_with_no_bitrate_tags);
+ tcase_add_test (tc,
+ test_client_multicast_transport_specific_two_clients_shared_media);
return s;
}
diff --git a/tests/check/gst/mediafactory.c b/tests/check/gst/mediafactory.c
index b6b250beb7..ba1719ea04 100644
--- a/tests/check/gst/mediafactory.c
+++ b/tests/check/gst/mediafactory.c
@@ -314,6 +314,63 @@ GST_START_TEST (test_reset)
GST_END_TEST;
+GST_START_TEST (test_mcast_ttl)
+{
+ GstRTSPMediaFactory *factory;
+ GstElement *element;
+ GstRTSPMedia *media;
+ GstRTSPUrl *url;
+ GstRTSPStream *stream;
+
+ factory = gst_rtsp_media_factory_new ();
+ gst_rtsp_media_factory_set_shared (factory, TRUE);
+ fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
+ &url) == GST_RTSP_OK);
+
+ gst_rtsp_media_factory_set_launch (factory,
+ "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
+ " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
+
+ /* try to set an invalid ttl and make sure that the default ttl value (255) is
+ * set */
+ gst_rtsp_media_factory_set_max_mcast_ttl (factory, 0);
+ fail_unless (gst_rtsp_media_factory_get_max_mcast_ttl (factory) == 255);
+ gst_rtsp_media_factory_set_max_mcast_ttl (factory, 300);
+ fail_unless (gst_rtsp_media_factory_get_max_mcast_ttl (factory) == 255);
+
+ /* set a valid ttl value */
+ gst_rtsp_media_factory_set_max_mcast_ttl (factory, 3);
+ fail_unless (gst_rtsp_media_factory_get_max_mcast_ttl (factory) == 3);
+
+ element = gst_rtsp_media_factory_create_element (factory, url);
+ fail_unless (GST_IS_BIN (element));
+ fail_if (GST_IS_PIPELINE (element));
+ gst_object_unref (element);
+
+ media = gst_rtsp_media_factory_construct (factory, url);
+ fail_unless (GST_IS_RTSP_MEDIA (media));
+
+ fail_unless (gst_rtsp_media_n_streams (media) == 2);
+ fail_unless (gst_rtsp_media_get_max_mcast_ttl (media) == 3);
+
+ /* verify that the correct ttl value has been propageted to the media
+ * streams */
+ stream = gst_rtsp_media_get_stream (media, 0);
+ fail_unless (stream != NULL);
+ fail_unless (gst_rtsp_stream_get_max_mcast_ttl (stream) == 3);
+
+ stream = gst_rtsp_media_get_stream (media, 1);
+ fail_unless (stream != NULL);
+ fail_unless (gst_rtsp_stream_get_max_mcast_ttl (stream) == 3);
+
+ g_object_unref (media);
+
+ gst_rtsp_url_free (url);
+ g_object_unref (factory);
+}
+
+GST_END_TEST;
+
static Suite *
rtspmediafactory_suite (void)
{
@@ -329,6 +386,7 @@ rtspmediafactory_suite (void)
tcase_add_test (tc, test_addresspool);
tcase_add_test (tc, test_permissions);
tcase_add_test (tc, test_reset);
+ tcase_add_test (tc, test_mcast_ttl);
return s;
}