diff options
author | Jose Antonio Santos Cadenas <santoscadenas@gmail.com> | 2013-04-12 09:35:34 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2013-04-15 14:27:47 +0200 |
commit | ba1e6938536b02b4af705ce45f2c89822a6abc62 (patch) | |
tree | 79ea3a05ab354817cb482b95636fdeec9a74c280 | |
parent | 90620b236ac1cd3b037338c1d1b4f44aff9ce0b9 (diff) |
sdp: add boxed type for GstSDPMessage
Also added some tests of this improvement.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=697808
-rw-r--r-- | gst-libs/gst/sdp/gstsdpmessage.c | 188 | ||||
-rw-r--r-- | gst-libs/gst/sdp/gstsdpmessage.h | 9 | ||||
-rw-r--r-- | tests/check/Makefile.am | 8 | ||||
-rw-r--r-- | tests/check/libs/.gitignore | 1 | ||||
-rw-r--r-- | tests/check/libs/sdp.c | 154 | ||||
-rw-r--r-- | win32/common/libgstsdp.def | 3 |
6 files changed, 363 insertions, 0 deletions
diff --git a/gst-libs/gst/sdp/gstsdpmessage.c b/gst-libs/gst/sdp/gstsdpmessage.c index f721939d1..a27bf013f 100644 --- a/gst-libs/gst/sdp/gstsdpmessage.c +++ b/gst-libs/gst/sdp/gstsdpmessage.c @@ -136,6 +136,29 @@ GstSDPResult gst_sdp_message_add_##method (GstSDPMessage *msg, type val) { \ return GST_SDP_OK; \ } +static GstSDPMessage *gst_sdp_message_boxed_copy (GstSDPMessage * orig); +static void gst_sdp_message_boxed_free (GstSDPMessage * msg); + +G_DEFINE_BOXED_TYPE (GstSDPMessage, gst_sdp_message, gst_sdp_message_boxed_copy, + gst_sdp_message_boxed_free); + +static GstSDPMessage * +gst_sdp_message_boxed_copy (GstSDPMessage * orig) +{ + GstSDPMessage *copy; + + if (gst_sdp_message_copy (orig, ©) == GST_SDP_OK) + return copy; + + return NULL; +} + +static void +gst_sdp_message_boxed_free (GstSDPMessage * msg) +{ + gst_sdp_message_free (msg); +} + static void gst_sdp_origin_init (GstSDPOrigin * origin) { @@ -281,6 +304,108 @@ gst_sdp_message_uninit (GstSDPMessage * msg) } /** + * gst_sdp_message_copy: + * @msg: a #GstSDPMessage + * @copy: (out) (transfer full): pointer to new #GstSDPMessage + * + * Allocate a new copy of @msg and store the result in @copy. The value in + * @copy should be release with gst_sdp_message_free function. + * + * Returns: a #GstSDPResult + */ +GstSDPResult +gst_sdp_message_copy (const GstSDPMessage * msg, GstSDPMessage ** copy) +{ + GstSDPResult ret; + GstSDPMessage *cp; + guint i, len; + + if (msg == NULL) + return GST_SDP_EINVAL; + + ret = gst_sdp_message_new (copy); + if (ret != GST_SDP_OK) + return ret; + + cp = *copy; + + REPLACE_STRING (cp->version, msg->version); + gst_sdp_message_set_origin (cp, msg->origin.username, msg->origin.sess_id, + msg->origin.sess_version, msg->origin.nettype, msg->origin.addrtype, + msg->origin.addr); + REPLACE_STRING (cp->session_name, msg->session_name); + REPLACE_STRING (cp->information, msg->information); + REPLACE_STRING (cp->uri, msg->uri); + + len = gst_sdp_message_emails_len (msg); + for (i = 0; i < len; i++) { + gst_sdp_message_add_email (cp, gst_sdp_message_get_email (msg, i)); + } + + len = gst_sdp_message_phones_len (msg); + for (i = 0; i < len; i++) { + gst_sdp_message_add_phone (cp, gst_sdp_message_get_phone (msg, i)); + } + + gst_sdp_message_set_connection (cp, msg->connection.nettype, + msg->connection.addrtype, msg->connection.address, msg->connection.ttl, + msg->connection.addr_number); + + len = gst_sdp_message_bandwidths_len (msg); + for (i = 0; i < len; i++) { + const GstSDPBandwidth *bw = gst_sdp_message_get_bandwidth (msg, i); + gst_sdp_message_add_bandwidth (cp, bw->bwtype, bw->bandwidth); + } + + len = gst_sdp_message_times_len (msg); + for (i = 0; i < len; i++) { + const gchar **repeat = NULL; + const GstSDPTime *time = gst_sdp_message_get_time (msg, i); + + if (time->repeat != NULL) { + guint j; + + repeat = g_malloc0 (time->repeat->len * sizeof (gchar *)); + + for (j = 0; j < time->repeat->len; j++) { + repeat[j] = g_array_index (time->repeat, char *, j); + } + } + + gst_sdp_message_add_time (cp, time->start, time->stop, repeat); + + g_free (repeat); + } + + len = gst_sdp_message_zones_len (msg); + for (i = 0; i < len; i++) { + const GstSDPZone *zone = gst_sdp_message_get_zone (msg, i); + gst_sdp_message_add_zone (cp, zone->time, zone->typed_time); + } + + gst_sdp_message_set_key (cp, msg->key.type, msg->key.data); + + len = gst_sdp_message_attributes_len (msg); + for (i = 0; i < len; i++) { + const GstSDPAttribute *attr = gst_sdp_message_get_attribute (msg, i); + gst_sdp_message_add_attribute (cp, attr->key, attr->value); + } + + len = gst_sdp_message_medias_len (msg); + for (i = 0; i < len; i++) { + GstSDPMedia *media_copy; + const GstSDPMedia *media = gst_sdp_message_get_media (msg, i); + + if (gst_sdp_media_copy (media, &media_copy) == GST_SDP_OK) { + gst_sdp_message_add_media (cp, media_copy); + gst_sdp_media_free (media_copy); + } + } + + return GST_SDP_OK; +} + +/** * gst_sdp_message_free: * @msg: a #GstSDPMessage * @@ -1274,6 +1399,69 @@ gst_sdp_media_free (GstSDPMedia * media) } /** + * gst_sdp_media_copy: + * @media: a #GstSDPMedia + * @copy: (out) (transfer full): pointer to new #GstSDPMedia + * + * Allocate a new copy of @media and store the result in @copy. The value in + * @copy should be release with gst_sdp_media_free function. + * + * Returns: a #GstSDPResult + */ +GstSDPResult +gst_sdp_media_copy (const GstSDPMedia * media, GstSDPMedia ** copy) +{ + GstSDPResult ret; + GstSDPMedia *cp; + guint i, len; + + if (media == NULL) + return GST_SDP_EINVAL; + + ret = gst_sdp_media_new (copy); + if (ret != GST_SDP_OK) + return ret; + + cp = *copy; + + REPLACE_STRING (cp->media, media->media); + cp->port = media->port; + cp->num_ports = media->num_ports; + REPLACE_STRING (cp->proto, media->proto); + + len = gst_sdp_media_formats_len (media); + for (i = 0; i < len; i++) { + gst_sdp_media_add_format (cp, gst_sdp_media_get_format (media, i)); + } + + REPLACE_STRING (cp->information, media->information); + + len = gst_sdp_media_connections_len (media); + for (i = 0; i < len; i++) { + const GstSDPConnection *connection = + gst_sdp_media_get_connection (media, i); + gst_sdp_media_add_connection (cp, connection->nettype, connection->addrtype, + connection->address, connection->ttl, connection->addr_number); + } + + len = gst_sdp_media_bandwidths_len (media); + for (i = 0; i < len; i++) { + const GstSDPBandwidth *bw = gst_sdp_media_get_bandwidth (media, i); + gst_sdp_media_add_bandwidth (cp, bw->bwtype, bw->bandwidth); + } + + gst_sdp_media_set_key (cp, media->key.type, media->key.data); + + len = gst_sdp_media_attributes_len (media); + for (i = 0; i < len; i++) { + const GstSDPAttribute *att = gst_sdp_media_get_attribute (media, i); + gst_sdp_media_add_attribute (cp, att->key, att->value); + } + + return GST_SDP_OK; +} + +/** * gst_sdp_media_as_text: * @media: a #GstSDPMedia * diff --git a/gst-libs/gst/sdp/gstsdpmessage.h b/gst-libs/gst/sdp/gstsdpmessage.h index e58e0b7c9..346db6b06 100644 --- a/gst-libs/gst/sdp/gstsdpmessage.h +++ b/gst-libs/gst/sdp/gstsdpmessage.h @@ -267,11 +267,19 @@ typedef struct { GArray *medias; } GstSDPMessage; + +GType gst_sdp_message_get_type (void); + +#define GST_TYPE_SDP_MESSAGE (gst_sdp_message_get_type()) +#define GST_SDP_MESSAGE_CAST(object) ((GstSDPMessage *)(object)) +#define GST_SDP_MESSAGE(object) (GST_SDP_MESSAGE_CAST(object)) + /* Session descriptions */ GstSDPResult gst_sdp_message_new (GstSDPMessage **msg); GstSDPResult gst_sdp_message_init (GstSDPMessage *msg); GstSDPResult gst_sdp_message_uninit (GstSDPMessage *msg); GstSDPResult gst_sdp_message_free (GstSDPMessage *msg); +GstSDPResult gst_sdp_message_copy (const GstSDPMessage *msg, GstSDPMessage **copy); GstSDPResult gst_sdp_message_parse_buffer (const guint8 *data, guint size, GstSDPMessage *msg); gchar* gst_sdp_message_as_text (const GstSDPMessage *msg); @@ -363,6 +371,7 @@ GstSDPResult gst_sdp_media_new (GstSDPMedia **media GstSDPResult gst_sdp_media_init (GstSDPMedia *media); GstSDPResult gst_sdp_media_uninit (GstSDPMedia *media); GstSDPResult gst_sdp_media_free (GstSDPMedia *media); +GstSDPResult gst_sdp_media_copy (const GstSDPMedia *media, GstSDPMedia **copy); gchar* gst_sdp_media_as_text (const GstSDPMedia *media); diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 48f707512..8b8e9e36a 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -109,6 +109,7 @@ check_PROGRAMS = \ libs/profile \ libs/rtp \ libs/rtsp \ + libs/sdp \ libs/tag \ libs/video \ libs/xmpwriter \ @@ -234,6 +235,13 @@ libs_navigation_LDADD = \ $(GST_BASE_LIBS) \ $(LDADD) +libs_sdp_CFLAGS = \ + $(GST_PLUGINS_BASE_CFLAGS) \ + $(AM_CFLAGS) +libs_sdp_LDADD = \ + $(top_builddir)/gst-libs/gst/sdp/libgstsdp-@GST_API_VERSION@.la \ + $(GST_BASE_LIBS) $(LDADD) + libs_rtp_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ $(AM_CFLAGS) diff --git a/tests/check/libs/.gitignore b/tests/check/libs/.gitignore index a24beca6b..8e9d31464 100644 --- a/tests/check/libs/.gitignore +++ b/tests/check/libs/.gitignore @@ -11,6 +11,7 @@ pbutils profile rtp rtsp +sdp tag utils video diff --git a/tests/check/libs/sdp.c b/tests/check/libs/sdp.c new file mode 100644 index 000000000..ef4cf0fb7 --- /dev/null +++ b/tests/check/libs/sdp.c @@ -0,0 +1,154 @@ +/* GStreamer unit tests for the SDP support library + * + * Copyright (C) 2013 Jose Antonio Santos Cadenas <santoscadenas@gmail.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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/check/gstcheck.h> + +/* + * test_sdp.c - gst-kurento-plugins + * + * Copyright (C) 2013 Kurento + * Contact: Miguel París Díaz <mparisdiaz@gmail.com> + * Contact: José Antonio Santos Cadenas <santoscadenas@kurento.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 + * as published by the Free Software Foundation. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <gst/check/gstcheck.h> +#include <gst/sdp/gstsdpmessage.h> + +static const gchar *sdp = "v=0\r\n" + "o=- 123456 0 IN IP4 127.0.0.1\r\n" + "s=TestSessionToCopy\r\n" + "c=IN IP4 127.0.0.1\r\n" + "t=0 0\r\n" + "m=video 3434 RTP/AVP 96 97 99\r\n" + "a=rtpmap:96 MP4V-ES/90000\r\n" + "a=rtpmap:97 H263-1998/90000\r\n" + "a=rtpmap:99 H263/90000\r\n" + "a=sendrecv\r\n" + "m=video 6565 RTP/AVP 98\r\n" + "a=rtpmap:98 VP8/90000\r\n" + "a=sendrecv\r\n" "m=audio 4545 RTP/AVP 14\r\n" "a=sendrecv\r\n" + "m=audio 1010 TCP 14\r\n"; + +GST_START_TEST (boxed) +{ + GValue value = G_VALUE_INIT; + GValue value_copy = G_VALUE_INIT; + GstSDPMessage *message, *copy; + gchar *message1_str, *message2_str, *copy_str; + const gchar *repeat1[] = { "789", "012", NULL }; + + gst_sdp_message_new (&message); + gst_sdp_message_parse_buffer ((guint8 *) sdp, -1, message); + + gst_sdp_message_add_time (message, "123", "456", repeat1); + + g_value_init (&value, GST_TYPE_SDP_MESSAGE); + g_value_init (&value_copy, GST_TYPE_SDP_MESSAGE); + + g_value_set_boxed (&value, message); + message1_str = gst_sdp_message_as_text (message); + GST_DEBUG ("message1:\n%s", message1_str); + gst_sdp_message_free (message); + + message = g_value_get_boxed (&value); + message2_str = gst_sdp_message_as_text (message); + GST_DEBUG ("message2:\n%s", message2_str); + + fail_if (g_strcmp0 (message1_str, message2_str) != 0); + + g_value_copy (&value, &value_copy); + g_value_reset (&value); + + copy = g_value_dup_boxed (&value_copy); + g_value_reset (&value_copy); + + copy_str = gst_sdp_message_as_text (copy); + GST_DEBUG ("copy:\n%s", copy_str); + + fail_if (g_strcmp0 (message1_str, copy_str)); + + g_free (message1_str); + g_free (message2_str); + g_free (copy_str); +} + +GST_END_TEST +GST_START_TEST (copy) +{ + GstSDPMessage *message, *copy; + glong length = -1; + gchar *message_str, *copy_str; + const gchar *repeat1[] = { "789", "012", NULL }; + const gchar *repeat2[] = { "987", "210", NULL }; + + gst_sdp_message_new (&message); + gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message); + + gst_sdp_message_add_time (message, "123", "456", repeat1); + gst_sdp_message_add_time (message, "321", "654", repeat2); + + gst_sdp_message_copy (message, ©); + + message_str = gst_sdp_message_as_text (message); + GST_DEBUG ("Original:\n%s", message_str); + gst_sdp_message_free (message); + copy_str = gst_sdp_message_as_text (copy); + gst_sdp_message_free (copy); + GST_DEBUG ("Copy:\n%s", copy_str); + + fail_if (g_strcmp0 (copy_str, message_str) != 0); + g_free (copy_str); + g_free (message_str); +} + +GST_END_TEST +/* + * End of test cases + */ +static Suite * +sdp_suite (void) +{ + Suite *s = suite_create ("sdp"); + TCase *tc_chain = tcase_create ("sdp"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, copy); + tcase_add_test (tc_chain, boxed); + + return s; +} + +GST_CHECK_MAIN (sdp); diff --git a/win32/common/libgstsdp.def b/win32/common/libgstsdp.def index 186e4ffae..ace959fbf 100644 --- a/win32/common/libgstsdp.def +++ b/win32/common/libgstsdp.def @@ -8,6 +8,7 @@ EXPORTS gst_sdp_media_attributes_len gst_sdp_media_bandwidths_len gst_sdp_media_connections_len + gst_sdp_media_copy gst_sdp_media_formats_len gst_sdp_media_free gst_sdp_media_get_attribute @@ -41,6 +42,7 @@ EXPORTS gst_sdp_message_as_uri gst_sdp_message_attributes_len gst_sdp_message_bandwidths_len + gst_sdp_message_copy gst_sdp_message_dump gst_sdp_message_emails_len gst_sdp_message_free @@ -57,6 +59,7 @@ EXPORTS gst_sdp_message_get_phone gst_sdp_message_get_session_name gst_sdp_message_get_time + gst_sdp_message_get_type gst_sdp_message_get_uri gst_sdp_message_get_version gst_sdp_message_get_zone |