From 8a08fddb41c7a25e025eaccf92961e1797fd6576 Mon Sep 17 00:00:00 2001 From: Patricia Muscalu Date: Mon, 18 Mar 2013 09:25:54 +0100 Subject: [PATCH] rtsp-client: expose uri --- gst/rtsp-server/rtsp-client.c | 27 +++++++++++++++ gst/rtsp-server/rtsp-client.h | 2 ++ tests/check/gst/client.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 1bb43c1..e48bf21 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -2026,6 +2026,33 @@ gst_rtsp_client_get_auth (GstRTSPClient * client) } /** + * gst_rtsp_client_get_uri: + * @client: a #GstRTSPClient + * + * Get the #GstRTSPUrl of @client. + * + * Returns: (transfer full): the #GstRTSPUrl of @client. Free with + * gst_rtsp_url_free () after usage. + */ +GstRTSPUrl * +gst_rtsp_client_get_uri (GstRTSPClient * client) +{ + GstRTSPClientPrivate *priv; + GstRTSPUrl *result = NULL; + + g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL); + + priv = client->priv; + + g_mutex_lock (&priv->lock); + if (priv->uri != NULL) + result = gst_rtsp_url_copy (priv->uri); + g_mutex_unlock (&priv->lock); + + return result; +} + +/** * gst_rtsp_client_set_send_func: * @client: a #GstRTSPClient * @func: a #GstRTSPClientSendFunc diff --git a/gst/rtsp-server/rtsp-client.h b/gst/rtsp-server/rtsp-client.h index a718cc7..ddb04e9 100644 --- a/gst/rtsp-server/rtsp-client.h +++ b/gst/rtsp-server/rtsp-client.h @@ -137,6 +137,8 @@ gboolean gst_rtsp_client_get_use_client_settings (GstRTSPClient * c void gst_rtsp_client_set_auth (GstRTSPClient *client, GstRTSPAuth *auth); GstRTSPAuth * gst_rtsp_client_get_auth (GstRTSPClient *client); +GstRTSPUrl * gst_rtsp_client_get_uri (GstRTSPClient *client); + void gst_rtsp_client_set_send_func (GstRTSPClient *client, GstRTSPClientSendFunc func, gpointer user_data, diff --git a/tests/check/gst/client.c b/tests/check/gst/client.c index e59e06a..52ef2ae 100644 --- a/tests/check/gst/client.c +++ b/tests/check/gst/client.c @@ -24,6 +24,27 @@ static gint cseq; static gboolean +test_response_200 (GstRTSPClient * client, GstRTSPMessage * response, + gboolean close, gpointer user_data) +{ + GstRTSPStatusCode code; + const gchar *reason; + GstRTSPVersion version; + + 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_OK); + fail_unless (g_str_equal (reason, "OK")); + fail_unless (version == GST_RTSP_VERSION_1_0); + + return TRUE; +} + +static gboolean test_response_400 (GstRTSPClient * client, GstRTSPMessage * response, gboolean close, gpointer user_data) { @@ -86,6 +107,32 @@ test_response_454 (GstRTSPClient * client, GstRTSPMessage * response, return TRUE; } +static GstRTSPClient * +setup_client (void) +{ + GstRTSPClient *client; + GstRTSPSessionPool *session_pool; + GstRTSPMountPoints *mount_points; + GstRTSPMediaFactory *factory; + + client = gst_rtsp_client_new (); + + session_pool = gst_rtsp_session_pool_new (); + gst_rtsp_client_set_session_pool (client, session_pool); + + mount_points = gst_rtsp_mount_points_new (); + factory = gst_rtsp_media_factory_new (); + gst_rtsp_media_factory_set_launch (factory, + "videotestsrc ! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96"); + gst_rtsp_mount_points_add_factory (mount_points, "/test", factory); + gst_rtsp_client_set_mount_points (client, mount_points); + + g_object_unref (mount_points); + g_object_unref (session_pool); + + return client; +} + GST_START_TEST (test_request) { GstRTSPClient *client; @@ -195,6 +242,8 @@ GST_START_TEST (test_describe) GstRTSPClient *client; GstRTSPMessage request = { 0, }; gchar *str; + GstRTSPUrl *uri_client; + gchar *uri_str; client = gst_rtsp_client_new (); @@ -210,6 +259,33 @@ GST_START_TEST (test_describe) &request) == GST_RTSP_OK); gst_rtsp_message_unset (&request); + uri_client = gst_rtsp_client_get_uri (client); + fail_unless (uri_client == NULL); + gst_rtsp_url_free (uri_client); + + + g_object_unref (client); + + /* simple DESCRIBE for an existing url */ + client = setup_client (); + fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE, + "rtsp://localhost/test") == GST_RTSP_OK); + str = g_strdup_printf ("%d", cseq); + gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); + g_free (str); + + 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); + + uri_client = gst_rtsp_client_get_uri (client); + fail_unless (uri_client != NULL); + uri_str = gst_rtsp_url_get_request_uri (uri_client); + gst_rtsp_url_free (uri_client); + fail_unless (g_strcmp0 (uri_str, "rtsp://localhost/test") == 0); + g_free (uri_str); + g_object_unref (client); } -- 2.7.4