mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
client: add generic close-after-send support
Add a property to send_response() to close the connection after the response has been sent to the client.
This commit is contained in:
parent
1d53c46d23
commit
84e72262d0
2 changed files with 23 additions and 22 deletions
|
@ -174,7 +174,7 @@ static void
|
|||
gst_rtsp_client_init (GstRTSPClient * client)
|
||||
{
|
||||
client->use_client_settings = DEFAULT_USE_CLIENT_SETTINGS;
|
||||
client->teardown_response_seq = 0;
|
||||
client->close_response_seq = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -303,7 +303,7 @@ gst_rtsp_client_new (void)
|
|||
|
||||
static void
|
||||
send_response (GstRTSPClient * client, GstRTSPSession * session,
|
||||
GstRTSPMessage * response, guint * id)
|
||||
GstRTSPMessage * response, gboolean close)
|
||||
{
|
||||
gst_rtsp_message_add_header (response, GST_RTSP_HDR_SERVER,
|
||||
"GStreamer RTSP server");
|
||||
|
@ -321,7 +321,14 @@ send_response (GstRTSPClient * client, GstRTSPSession * session,
|
|||
gst_rtsp_message_dump (response);
|
||||
}
|
||||
|
||||
gst_rtsp_watch_send_message (client->watch, response, id);
|
||||
if (close) {
|
||||
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONNECTION,
|
||||
"close");
|
||||
}
|
||||
/* send the response and store the seq number so we can wait until it's
|
||||
* written to the client to close the connection */
|
||||
gst_rtsp_watch_send_message (client->watch, response, close ?
|
||||
&client->close_response_seq : NULL);
|
||||
gst_rtsp_message_unset (response);
|
||||
}
|
||||
|
||||
|
@ -332,7 +339,7 @@ send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
|
|||
gst_rtsp_message_init_response (state->response, code,
|
||||
gst_rtsp_status_as_text (code), state->request);
|
||||
|
||||
send_response (client, NULL, state->response, NULL);
|
||||
send_response (client, NULL, state->response, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -347,7 +354,7 @@ handle_unauthorized_request (GstRTSPClient * client, GstRTSPAuth * auth,
|
|||
gst_rtsp_auth_setup_auth (auth, client, 0, state);
|
||||
}
|
||||
|
||||
send_response (client, state->session, state->response, NULL);
|
||||
send_response (client, state->session, state->response, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -605,13 +612,7 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
gst_rtsp_message_init_response (state->response, code,
|
||||
gst_rtsp_status_as_text (code), state->request);
|
||||
|
||||
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONNECTION,
|
||||
"close");
|
||||
|
||||
/* send the response and store the seq number so we can wait until it's
|
||||
* written to the client to close the connection */
|
||||
send_response (client, session, state->response,
|
||||
&client->teardown_response_seq);
|
||||
send_response (client, session, state->response, TRUE);
|
||||
|
||||
/* we emit the signal before closing the connection */
|
||||
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST],
|
||||
|
@ -652,7 +653,7 @@ handle_get_param_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
if (res != GST_RTSP_OK)
|
||||
goto bad_request;
|
||||
|
||||
send_response (client, state->session, state->response, NULL);
|
||||
send_response (client, state->session, state->response, FALSE);
|
||||
}
|
||||
|
||||
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST],
|
||||
|
@ -688,7 +689,7 @@ handle_set_param_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
if (res != GST_RTSP_OK)
|
||||
goto bad_request;
|
||||
|
||||
send_response (client, state->session, state->response, NULL);
|
||||
send_response (client, state->session, state->response, FALSE);
|
||||
}
|
||||
|
||||
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST],
|
||||
|
@ -737,7 +738,7 @@ handle_pause_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
gst_rtsp_message_init_response (state->response, code,
|
||||
gst_rtsp_status_as_text (code), state->request);
|
||||
|
||||
send_response (client, session, state->response, NULL);
|
||||
send_response (client, session, state->response, FALSE);
|
||||
|
||||
/* the state is now READY */
|
||||
media->state = GST_RTSP_STATE_READY;
|
||||
|
@ -859,7 +860,7 @@ handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
str = gst_rtsp_media_get_range_string (media->media, TRUE);
|
||||
gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RANGE, str);
|
||||
|
||||
send_response (client, session, state->response, NULL);
|
||||
send_response (client, session, state->response, FALSE);
|
||||
|
||||
/* start playing after sending the request */
|
||||
gst_rtsp_session_media_set_state (media, GST_STATE_PLAYING);
|
||||
|
@ -1185,7 +1186,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
trans_str);
|
||||
g_free (trans_str);
|
||||
|
||||
send_response (client, session, state->response, NULL);
|
||||
send_response (client, session, state->response, FALSE);
|
||||
|
||||
/* update the state */
|
||||
switch (sessmedia->state) {
|
||||
|
@ -1374,7 +1375,7 @@ handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
gst_rtsp_message_take_body (state->response, (guint8 *) str, strlen (str));
|
||||
gst_sdp_message_free (sdp);
|
||||
|
||||
send_response (client, state->session, state->response, NULL);
|
||||
send_response (client, state->session, state->response, FALSE);
|
||||
|
||||
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST],
|
||||
0, state);
|
||||
|
@ -1416,7 +1417,7 @@ handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
|
|||
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_PUBLIC, str);
|
||||
g_free (str);
|
||||
|
||||
send_response (client, state->session, state->response, NULL);
|
||||
send_response (client, state->session, state->response, FALSE);
|
||||
|
||||
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST],
|
||||
0, state);
|
||||
|
@ -1900,8 +1901,8 @@ message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
|
|||
GstRTSPClient *client;
|
||||
|
||||
client = GST_RTSP_CLIENT (user_data);
|
||||
if (client->teardown_response_seq && client->teardown_response_seq == cseq) {
|
||||
client->teardown_response_seq = 0;
|
||||
if (client->close_response_seq && client->close_response_seq == cseq) {
|
||||
client->close_response_seq = 0;
|
||||
close_connection (client);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ struct _GstRTSPClient {
|
|||
GList *transports;
|
||||
GList *sessions;
|
||||
|
||||
guint teardown_response_seq;
|
||||
guint close_response_seq;
|
||||
};
|
||||
|
||||
struct _GstRTSPClientClass {
|
||||
|
|
Loading…
Reference in a new issue