From 4b4f8d1a05e2ca5e5fbd4a33d36424104ce8a86e Mon Sep 17 00:00:00 2001 From: Matt Staples Date: Tue, 31 Oct 2017 16:10:19 -0600 Subject: [PATCH] rtsp: Register GstRTSPMessage as a boxed type Registering GstRTSPMessage as a boxed type allows it to be conveniently used as an argument to signals, a-la GstSDPMessage, and general usage from bindings. https://bugzilla.gnome.org/show_bug.cgi?id=762884 --- gst-libs/gst/rtsp/gstrtspmessage.c | 91 ++++++++++++++++++++++++++++++ gst-libs/gst/rtsp/gstrtspmessage.h | 12 +++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/rtsp/gstrtspmessage.c b/gst-libs/gst/rtsp/gstrtspmessage.c index 52e28534ab..06e60a11e3 100644 --- a/gst-libs/gst/rtsp/gstrtspmessage.c +++ b/gst-libs/gst/rtsp/gstrtspmessage.c @@ -75,6 +75,40 @@ key_value_foreach (GArray * array, GFunc func, gpointer user_data) } } +static void +key_value_append (const RTSPKeyValue * kv, GArray * array) +{ + RTSPKeyValue kvcopy; + g_return_if_fail (kv != NULL); + g_return_if_fail (array != NULL); + + kvcopy.field = kv->field; + kvcopy.value = g_strdup (kv->value); + kvcopy.custom_key = g_strdup (kv->custom_key); + + g_array_append_val (array, kvcopy); +} + +static GstRTSPMessage * +gst_rtsp_message_boxed_copy (GstRTSPMessage * orig) +{ + GstRTSPMessage *copy; + + if (gst_rtsp_message_copy (orig, ©) == GST_RTSP_OK) + return copy; + + return NULL; +} + +static void +gst_rtsp_message_boxed_free (GstRTSPMessage * msg) +{ + gst_rtsp_message_free (msg); +} + +G_DEFINE_BOXED_TYPE (GstRTSPMessage, gst_rtsp_msg, gst_rtsp_message_boxed_copy, + gst_rtsp_message_boxed_free); + /** * gst_rtsp_message_new: * @msg: (out) (transfer full): a location for the new #GstRTSPMessage @@ -498,6 +532,63 @@ gst_rtsp_message_free (GstRTSPMessage * msg) return res; } +/** + * gst_rtsp_message_copy: + * @msg: a #GstRTSPMessage + * @copy: (out) (transfer full): pointer to new #GstRTSPMessage + * + * Allocate a new copy of @msg and store the result in @copy. The value in + * @copy should be release with gst_rtsp_message_free function. + * + * Returns: a #GstRTSPResult + * + * Since: 1.14 + */ +GstRTSPResult +gst_rtsp_message_copy (const GstRTSPMessage * msg, GstRTSPMessage ** copy) +{ + GstRTSPResult ret; + GstRTSPMessage *cp; + + if (msg == NULL) + return GST_RTSP_EINVAL; + + ret = gst_rtsp_message_new (copy); + if (ret != GST_RTSP_OK) + return ret; + + cp = *copy; + + cp->type = msg->type; + switch (cp->type) { + case GST_RTSP_MESSAGE_INVALID: + break; + case GST_RTSP_MESSAGE_REQUEST: + case GST_RTSP_MESSAGE_HTTP_REQUEST: + cp->type_data.request.method = msg->type_data.request.method; + cp->type_data.request.uri = g_strdup (msg->type_data.request.uri); + cp->type_data.request.version = msg->type_data.request.version; + break; + case GST_RTSP_MESSAGE_RESPONSE: + case GST_RTSP_MESSAGE_HTTP_RESPONSE: + cp->type_data.response.code = msg->type_data.response.code; + cp->type_data.response.reason = g_strdup (msg->type_data.response.reason); + cp->type_data.response.version = msg->type_data.response.version; + break; + case GST_RTSP_MESSAGE_DATA: + cp->type_data.data.channel = msg->type_data.data.channel; + break; + default: + return GST_RTSP_EINVAL; + } + + key_value_foreach (msg->hdr_fields, (GFunc) key_value_append, cp->hdr_fields); + gst_rtsp_message_set_body (cp, msg->body, msg->body_size); + + return GST_RTSP_OK; +} + + /** * gst_rtsp_message_take_header: * @msg: a #GstRTSPMessage diff --git a/gst-libs/gst/rtsp/gstrtspmessage.h b/gst-libs/gst/rtsp/gstrtspmessage.h index 23ed9f4c93..30ad0bea0f 100644 --- a/gst-libs/gst/rtsp/gstrtspmessage.h +++ b/gst-libs/gst/rtsp/gstrtspmessage.h @@ -107,6 +107,13 @@ struct _GstRTSPMessage gpointer _gst_reserved[GST_PADDING]; }; +GST_EXPORT +GType gst_rtsp_msg_get_type (void); + +#define GST_TYPE_RTSP_MESSAGE (gst_rtsp_msg_get_type()) +#define GST_RTSP_MESSAGE_CAST(object) ((GstRTSPMessage *)(object)) +#define GST_RTSP_MESSAGE(object) (GST_RTSP_MESSAGE_CAST(object)) + /* memory management */ GST_EXPORT @@ -120,6 +127,9 @@ GstRTSPResult gst_rtsp_message_unset (GstRTSPMessage *msg); GST_EXPORT GstRTSPResult gst_rtsp_message_free (GstRTSPMessage *msg); +GST_EXPORT +GstRTSPResult gst_rtsp_message_copy (const GstRTSPMessage *msg, + GstRTSPMessage **copy); GST_EXPORT GstRTSPMsgType gst_rtsp_message_get_type (GstRTSPMessage *msg); @@ -140,7 +150,7 @@ GST_EXPORT GstRTSPResult gst_rtsp_message_parse_request (GstRTSPMessage *msg, GstRTSPMethod *method, const gchar **uri, - GstRTSPVersion *version); + GstRTSPVersion *version); /* response */