mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 18:20:44 +00:00
a437e9f0ed
Original commit message from CVS: * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_media_to_caps), (gst_rtspsrc_send), (gst_rtspsrc_parse_methods), (gst_rtspsrc_open), (gst_rtspsrc_close), (gst_rtspsrc_play), (gst_rtspsrc_pause), (gst_rtspsrc_change_state), (gst_rtspsrc_uri_get_uri), (gst_rtspsrc_uri_set_uri): * gst/rtsp/gstrtspsrc.h: Small cleanups, added documentation. Try to clean up the requests and responses. Refactor parsing the supported methods. * gst/rtsp/rtspconnection.c: (rtsp_connection_open), (rtsp_connection_create), (rtsp_connection_send), (parse_response_status), (parse_request_line), (rtsp_connection_receive), (rtsp_connection_close), (rtsp_connection_free): * gst/rtsp/rtsptransport.c: (rtsp_transport_new), (rtsp_transport_init), (rtsp_transport_parse), (rtsp_transport_free): * gst/rtsp/rtspurl.c: (rtsp_url_parse): * gst/rtsp/sdpmessage.c: (sdp_message_new), (sdp_message_init), (sdp_message_clean), (sdp_message_free), (sdp_media_new), (sdp_media_init), (sdp_message_parse_buffer), (sdp_message_dump): Use g_return_val some more. * gst/rtsp/rtspdefs.h: Add more enum values to track initial states. * gst/rtsp/rtspmessage.c: (rtsp_message_new_request), (rtsp_message_init_request), (rtsp_message_new_response), (rtsp_message_init_response), (rtsp_message_init_data), (rtsp_message_unset), (rtsp_message_free), (rtsp_message_add_header), (rtsp_message_remove_header), (rtsp_message_get_header), (rtsp_message_set_body), (rtsp_message_take_body), (rtsp_message_get_body), (rtsp_message_steal_body), (rtsp_message_dump): * gst/rtsp/rtspmessage.h: Reorder arguments, object goes as the first one. Use g_return_val some more.
317 lines
7.9 KiB
C
317 lines
7.9 KiB
C
/* GStreamer
|
|
* Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "rtspmessage.h"
|
|
|
|
RTSPResult
|
|
rtsp_message_new_request (RTSPMessage ** msg, RTSPMethod method, gchar * uri)
|
|
{
|
|
RTSPMessage *newmsg;
|
|
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (uri != NULL, RTSP_EINVAL);
|
|
|
|
newmsg = g_new0 (RTSPMessage, 1);
|
|
|
|
*msg = newmsg;
|
|
|
|
return rtsp_message_init_request (newmsg, method, uri);
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_init_request (RTSPMessage * msg, RTSPMethod method, gchar * uri)
|
|
{
|
|
g_return_val_if_fail (uri != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
rtsp_message_unset (msg);
|
|
|
|
msg->type = RTSP_MESSAGE_REQUEST;
|
|
msg->type_data.request.method = method;
|
|
msg->type_data.request.uri = g_strdup (uri);
|
|
msg->hdr_fields =
|
|
g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_new_response (RTSPMessage ** msg, RTSPStatusCode code,
|
|
gchar * reason, RTSPMessage * request)
|
|
{
|
|
RTSPMessage *newmsg;
|
|
|
|
g_return_val_if_fail (reason != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (request != NULL, RTSP_EINVAL);
|
|
|
|
newmsg = g_new0 (RTSPMessage, 1);
|
|
|
|
*msg = newmsg;
|
|
|
|
return rtsp_message_init_response (newmsg, code, reason, request);
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_init_response (RTSPMessage * msg, RTSPStatusCode code,
|
|
gchar * reason, RTSPMessage * request)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (reason != NULL, RTSP_EINVAL);
|
|
|
|
rtsp_message_unset (msg);
|
|
|
|
msg->type = RTSP_MESSAGE_RESPONSE;
|
|
msg->type_data.response.code = code;
|
|
msg->type_data.response.reason = g_strdup (reason);
|
|
msg->hdr_fields =
|
|
g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
|
|
|
|
if (request) {
|
|
/* FIXME copy headers */
|
|
}
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_init_data (RTSPMessage * msg, gint channel)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
rtsp_message_unset (msg);
|
|
|
|
msg->type = RTSP_MESSAGE_DATA;
|
|
msg->type_data.data.channel = channel;
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_unset (RTSPMessage * msg)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
msg->type = RTSP_MESSAGE_INVALID;
|
|
msg->type_data.request.method = RTSP_INVALID;
|
|
g_free (msg->type_data.request.uri);
|
|
msg->type_data.request.uri = NULL;
|
|
|
|
msg->type_data.response.code = RTSP_STS_INVALID;
|
|
g_free (msg->type_data.response.reason);
|
|
msg->type_data.response.reason = NULL;
|
|
|
|
if (msg->hdr_fields != NULL)
|
|
g_hash_table_destroy (msg->hdr_fields);
|
|
msg->hdr_fields = NULL;
|
|
|
|
g_free (msg->body);
|
|
msg->body = NULL;
|
|
msg->body_size = 0;
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_free (RTSPMessage * msg)
|
|
{
|
|
RTSPResult res;
|
|
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
res = rtsp_message_unset (msg);
|
|
if (res == RTSP_OK)
|
|
g_free (msg);
|
|
|
|
return res;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_add_header (RTSPMessage * msg, RTSPHeaderField field,
|
|
gchar * value)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (value != NULL, RTSP_EINVAL);
|
|
|
|
g_hash_table_insert (msg->hdr_fields, GINT_TO_POINTER (field),
|
|
g_strdup (value));
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_remove_header (RTSPMessage * msg, RTSPHeaderField field)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
g_hash_table_remove (msg->hdr_fields, GINT_TO_POINTER (field));
|
|
|
|
return RTSP_ENOTIMPL;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_get_header (RTSPMessage * msg, RTSPHeaderField field,
|
|
gchar ** value)
|
|
{
|
|
gchar *val;
|
|
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (value != NULL, RTSP_EINVAL);
|
|
|
|
val = g_hash_table_lookup (msg->hdr_fields, GINT_TO_POINTER (field));
|
|
if (val == NULL)
|
|
return RTSP_ENOTIMPL;
|
|
|
|
*value = val;
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_set_body (RTSPMessage * msg, guint8 * data, guint size)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
return rtsp_message_take_body (msg, g_memdup (data, size), size);
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_take_body (RTSPMessage * msg, guint8 * data, guint size)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
if (msg->body)
|
|
g_free (msg->body);
|
|
|
|
msg->body = data;
|
|
msg->body_size = size;
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_get_body (RTSPMessage * msg, guint8 ** data, guint * size)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (data != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (size != NULL, RTSP_EINVAL);
|
|
|
|
*data = msg->body;
|
|
*size = msg->body_size;
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_steal_body (RTSPMessage * msg, guint8 ** data, guint * size)
|
|
{
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (data != NULL, RTSP_EINVAL);
|
|
g_return_val_if_fail (size != NULL, RTSP_EINVAL);
|
|
|
|
*data = msg->body;
|
|
*size = msg->body_size;
|
|
|
|
msg->body = NULL;
|
|
msg->body_size = 0;
|
|
|
|
return RTSP_OK;
|
|
}
|
|
|
|
static void
|
|
dump_mem (guint8 * mem, gint size)
|
|
{
|
|
guint i, j;
|
|
GString *string = g_string_sized_new (50);
|
|
GString *chars = g_string_sized_new (18);
|
|
|
|
i = j = 0;
|
|
while (i < size) {
|
|
if (g_ascii_isprint (mem[i]))
|
|
g_string_append_printf (chars, "%c", mem[i]);
|
|
else
|
|
g_string_append_printf (chars, ".");
|
|
|
|
g_string_append_printf (string, "%02x ", mem[i]);
|
|
|
|
j++;
|
|
i++;
|
|
|
|
if (j == 16 || i == size) {
|
|
g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
|
|
string->str, chars->str);
|
|
g_string_set_size (string, 0);
|
|
g_string_set_size (chars, 0);
|
|
j = 0;
|
|
}
|
|
}
|
|
g_string_free (string, TRUE);
|
|
g_string_free (chars, TRUE);
|
|
}
|
|
|
|
static void
|
|
dump_key_value (gpointer key, gpointer value, gpointer data)
|
|
{
|
|
RTSPHeaderField field = GPOINTER_TO_INT (key);
|
|
|
|
g_print (" key: '%s', value: '%s'\n", rtsp_header_as_text (field),
|
|
(gchar *) value);
|
|
}
|
|
|
|
RTSPResult
|
|
rtsp_message_dump (RTSPMessage * msg)
|
|
{
|
|
guint8 *data;
|
|
guint size;
|
|
|
|
g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
|
|
|
|
if (msg->type == RTSP_MESSAGE_REQUEST) {
|
|
g_print ("request message %p\n", msg);
|
|
g_print (" request line:\n");
|
|
g_print (" method: '%s'\n",
|
|
rtsp_method_as_text (msg->type_data.request.method));
|
|
g_print (" uri: '%s'\n", msg->type_data.request.uri);
|
|
g_print (" headers:\n");
|
|
g_hash_table_foreach (msg->hdr_fields, dump_key_value, NULL);
|
|
g_print (" body:\n");
|
|
rtsp_message_get_body (msg, &data, &size);
|
|
dump_mem (data, size);
|
|
} else if (msg->type == RTSP_MESSAGE_RESPONSE) {
|
|
g_print ("response message %p\n", msg);
|
|
g_print (" status line:\n");
|
|
g_print (" code: '%d'\n", msg->type_data.response.code);
|
|
g_print (" reason: '%s'\n", msg->type_data.response.reason);
|
|
g_print (" headers:\n");
|
|
g_hash_table_foreach (msg->hdr_fields, dump_key_value, NULL);
|
|
rtsp_message_get_body (msg, &data, &size);
|
|
g_print (" body: length %d\n", size);
|
|
dump_mem (data, size);
|
|
} else if (msg->type == RTSP_MESSAGE_DATA) {
|
|
g_print ("data message %p\n", msg);
|
|
g_print (" channel: '%d'\n", msg->type_data.data.channel);
|
|
g_print (" size: '%d'\n", msg->body_size);
|
|
rtsp_message_get_body (msg, &data, &size);
|
|
dump_mem (data, size);
|
|
} else {
|
|
g_print ("unsupported packet type %d\n", msg->type);
|
|
return RTSP_EINVAL;
|
|
}
|
|
return RTSP_OK;
|
|
}
|