From 1f846187257f373c8c6066bf2f0288a507a61c24 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Thu, 8 Aug 2013 10:57:42 -0400 Subject: [PATCH] Add handle-response signal for when we receive a GET_PARAMETER response --- gst/rtsp-server/rtsp-client.c | 86 +++++++++++++++++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-client.h | 1 + 2 files changed, 87 insertions(+) diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 08fe9f1..5de2cb2 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -107,6 +107,7 @@ enum SIGNAL_TEARDOWN_REQUEST, SIGNAL_SET_PARAMETER_REQUEST, SIGNAL_GET_PARAMETER_REQUEST, + SIGNAL_HANDLE_RESPONSE, SIGNAL_LAST }; @@ -223,6 +224,12 @@ gst_rtsp_client_class_init (GstRTSPClientClass * klass) get_parameter_request), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); + gst_rtsp_client_signals[SIGNAL_HANDLE_RESPONSE] = + g_signal_new ("handle-response", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, + handle_response), NULL, NULL, g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + tunnels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); g_mutex_init (&tunnels_lock); @@ -1947,6 +1954,84 @@ not_implemented: } } + +static void +handle_response (GstRTSPClient * client, GstRTSPMessage * response) +{ + GstRTSPClientPrivate *priv = client->priv; + GstRTSPResult res; + GstRTSPSession *session = NULL; + GstRTSPContext sctx = { NULL }, *ctx; + gchar *sessid; + + if (!(ctx = gst_rtsp_context_get_current ())) { + ctx = &sctx; + ctx->auth = priv->auth; + gst_rtsp_context_push_current (ctx); + } + + ctx->conn = priv->connection; + ctx->client = client; + ctx->request = NULL; + ctx->uri = NULL; + ctx->method = GST_RTSP_INVALID; + ctx->response = response; + + if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) { + gst_rtsp_message_dump (response); + } + + GST_INFO ("client %p: received a response", client); + + /* get the session if there is any */ + res = + gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION, &sessid, 0); + if (res == GST_RTSP_OK) { + if (priv->session_pool == NULL) + goto no_pool; + + /* we had a session in the request, find it again */ + if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid))) + goto session_not_found; + + /* we add the session to the client list of watched sessions. When a session + * disappears because it times out, we will be notified. If all sessions are + * gone, we will close the connection */ + client_watch_session (client, session); + } + + ctx->session = session; + + if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_URL)) + goto not_authorized; + + g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_HANDLE_RESPONSE], + 0, ctx); + +done: + if (ctx == &sctx) + gst_rtsp_context_pop_current (ctx); + if (session) + g_object_unref (session); + return; + +no_pool: + { + GST_ERROR ("client %p: no pool configured", client); + goto done; + } +session_not_found: + { + GST_ERROR ("client %p: session not found", client); + goto done; + } +not_authorized: + { + GST_ERROR ("client %p: not allowed", client); + goto done; + } +} + static void handle_data (GstRTSPClient * client, GstRTSPMessage * message) { @@ -2368,6 +2453,7 @@ gst_rtsp_client_handle_message (GstRTSPClient * client, handle_request (client, message); break; case GST_RTSP_MESSAGE_RESPONSE: + handle_response (client, message); break; case GST_RTSP_MESSAGE_DATA: handle_data (client, message); diff --git a/gst/rtsp-server/rtsp-client.h b/gst/rtsp-server/rtsp-client.h index e2fb734..2f9cdf9 100644 --- a/gst/rtsp-server/rtsp-client.h +++ b/gst/rtsp-server/rtsp-client.h @@ -104,6 +104,7 @@ struct _GstRTSPClientClass { void (*teardown_request) (GstRTSPClient *client, GstRTSPContext *ctx); void (*set_parameter_request) (GstRTSPClient *client, GstRTSPContext *ctx); void (*get_parameter_request) (GstRTSPClient *client, GstRTSPContext *ctx); + void (*handle_response) (GstRTSPClient *client, GstRTSPContext *ctx); }; GType gst_rtsp_client_get_type (void); -- 2.7.4