2 * Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
24 * Permission is hereby granted, free of charge, to any person obtaining a copy of
25 * this software and associated documentation files (the "Software"), to deal in
26 * the Software without restriction, including without limitation the rights to
27 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28 * of the Software, and to permit persons to whom the Software is furnished to do
29 * so, subject to the following conditions:
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 * SECTION:gstsdpmessage
45 * @title: GstSDPMessage
46 * @short_description: Helper methods for dealing with SDP messages
48 * The GstSDPMessage helper functions makes it easy to parse and create SDP
63 #include <gst/rtp/gstrtppayloads.h>
64 #include <gst/pbutils/pbutils.h>
65 #include "gstsdpmessage.h"
67 #define FREE_STRING(field) g_free (field); (field) = NULL
68 #define REPLACE_STRING(field, val) FREE_STRING(field); (field) = g_strdup (val)
71 free_string (gchar ** str)
76 #define INIT_ARRAY(field, type, init_func) \
80 for(i = 0; i < (field)->len; i++) \
81 init_func (&g_array_index ((field), type, i)); \
82 g_array_set_size ((field), 0); \
85 (field) = g_array_new (FALSE, TRUE, sizeof (type)); \
88 #define FREE_ARRAY(field) \
91 g_array_free ((field), TRUE); \
95 #define DEFINE_STRING_SETTER(field) \
96 GstSDPResult gst_sdp_message_set_##field (GstSDPMessage *msg, const gchar *val) { \
97 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL); \
98 g_free (msg->field); \
99 msg->field = g_strdup (val); \
102 #define DEFINE_STRING_GETTER(field) \
103 const gchar* gst_sdp_message_get_##field (const GstSDPMessage *msg) { \
104 g_return_val_if_fail (msg != NULL, NULL); \
108 #define DEFINE_ARRAY_LEN(field) \
109 guint gst_sdp_message_##field##_len (const GstSDPMessage *msg) { \
110 g_return_val_if_fail (msg != NULL, 0); \
111 return msg->field->len; \
113 #define DEFINE_ARRAY_GETTER(method, field, type) \
114 const type * gst_sdp_message_get_##method (const GstSDPMessage *msg, guint idx) { \
115 g_return_val_if_fail (msg != NULL, NULL); \
116 return &g_array_index (msg->field, type, idx); \
118 #define DEFINE_PTR_ARRAY_GETTER(method, field, type) \
119 const type gst_sdp_message_get_##method (const GstSDPMessage *msg, guint idx) { \
120 g_return_val_if_fail (msg != NULL, (type) 0); \
121 return g_array_index (msg->field, type, idx); \
123 #define DEFINE_ARRAY_INSERT(method, field, intype, dup_method, type) \
124 GstSDPResult gst_sdp_message_insert_##method (GstSDPMessage *msg, gint idx, intype val) { \
127 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL); \
128 dup_method (v, val); \
130 g_array_append_val (msg->field, vt); \
132 g_array_insert_val (msg->field, idx, vt); \
136 #define DEFINE_ARRAY_REPLACE(method, field, intype, free_method, dup_method, type) \
137 GstSDPResult gst_sdp_message_replace_##method (GstSDPMessage *msg, guint idx, intype val) { \
139 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL); \
140 v = &g_array_index (msg->field, type, idx); \
142 dup_method (v, val); \
145 #define DEFINE_ARRAY_REMOVE(method, field, type, free_method) \
146 GstSDPResult gst_sdp_message_remove_##method (GstSDPMessage *msg, guint idx) { \
148 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL); \
149 v = &g_array_index (msg->field, type, idx); \
151 g_array_remove_index (msg->field, idx); \
154 #define DEFINE_ARRAY_ADDER(method, type) \
155 GstSDPResult gst_sdp_message_add_##method (GstSDPMessage *msg, const type val) { \
156 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL); \
157 return gst_sdp_message_insert_##method (msg, -1, val); \
160 #define dup_string(v,val) ((*v) = g_strdup (val))
161 #define INIT_STR_ARRAY(field) \
162 INIT_ARRAY (field, gchar *, free_string)
163 #define DEFINE_STR_ARRAY_GETTER(method, field) \
164 DEFINE_PTR_ARRAY_GETTER(method, field, gchar *)
165 #define DEFINE_STR_ARRAY_INSERT(method, field) \
166 DEFINE_ARRAY_INSERT (method, field, const gchar *, dup_string, gchar *)
167 #define DEFINE_STR_ARRAY_ADDER(method, field) \
168 DEFINE_ARRAY_ADDER (method, gchar *)
169 #define DEFINE_STR_ARRAY_REPLACE(method, field) \
170 DEFINE_ARRAY_REPLACE (method, field, const gchar *, free_string, dup_string, gchar *)
171 #define DEFINE_STR_ARRAY_REMOVE(method, field) \
172 DEFINE_ARRAY_REMOVE (method, field, gchar *, free_string)
174 static GstSDPMessage *gst_sdp_message_boxed_copy (GstSDPMessage * orig);
175 static void gst_sdp_message_boxed_free (GstSDPMessage * msg);
177 G_DEFINE_BOXED_TYPE (GstSDPMessage, gst_sdp_message, gst_sdp_message_boxed_copy,
178 gst_sdp_message_boxed_free);
180 static GstSDPMessage *
181 gst_sdp_message_boxed_copy (GstSDPMessage * orig)
188 if (gst_sdp_message_copy (orig, ©) == GST_SDP_OK)
195 gst_sdp_message_boxed_free (GstSDPMessage * msg)
197 gst_sdp_message_free (msg);
201 gst_sdp_origin_init (GstSDPOrigin * origin)
203 FREE_STRING (origin->username);
204 FREE_STRING (origin->sess_id);
205 FREE_STRING (origin->sess_version);
206 FREE_STRING (origin->nettype);
207 FREE_STRING (origin->addrtype);
208 FREE_STRING (origin->addr);
212 gst_sdp_key_init (GstSDPKey * key)
214 FREE_STRING (key->type);
215 FREE_STRING (key->data);
219 * gst_sdp_message_new:
220 * @msg: (out) (transfer full): pointer to new #GstSDPMessage
222 * Allocate a new GstSDPMessage and store the result in @msg.
224 * Returns: a #GstSDPResult.
227 gst_sdp_message_new (GstSDPMessage ** msg)
229 GstSDPMessage *newmsg;
231 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
233 newmsg = g_new0 (GstSDPMessage, 1);
237 return gst_sdp_message_init (newmsg);
241 * gst_sdp_message_new_from_text:
242 * @text: A dynamically allocated string representing the SDP description
243 * @msg: (out) (transfer full): pointer to new #GstSDPMessage
245 * Parse @text and create a new SDPMessage from these.
247 * Returns: a #GstSDPResult.
251 gst_sdp_message_new_from_text (const gchar * text, GstSDPMessage ** msg)
255 if ((res = gst_sdp_message_new (msg)) != GST_SDP_OK)
259 gst_sdp_message_parse_buffer ((const guint8 *) text, strlen (text), *msg);
265 * gst_sdp_message_init:
266 * @msg: a #GstSDPMessage
268 * Initialize @msg so that its contents are as if it was freshly allocated
269 * with gst_sdp_message_new(). This function is mostly used to initialize a message
270 * allocated on the stack. gst_sdp_message_uninit() undoes this operation.
272 * When this function is invoked on newly allocated data (with malloc or on the
273 * stack), its contents should be set to 0 before calling this function.
275 * Returns: a #GstSDPResult.
278 gst_sdp_message_init (GstSDPMessage * msg)
280 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
282 FREE_STRING (msg->version);
283 gst_sdp_origin_init (&msg->origin);
284 FREE_STRING (msg->session_name);
285 FREE_STRING (msg->information);
286 FREE_STRING (msg->uri);
287 INIT_STR_ARRAY (msg->emails);
288 INIT_STR_ARRAY (msg->phones);
289 gst_sdp_connection_clear (&msg->connection);
290 INIT_ARRAY (msg->bandwidths, GstSDPBandwidth, gst_sdp_bandwidth_clear);
291 INIT_ARRAY (msg->times, GstSDPTime, gst_sdp_time_clear);
292 INIT_ARRAY (msg->zones, GstSDPZone, gst_sdp_zone_clear);
293 gst_sdp_key_init (&msg->key);
294 INIT_ARRAY (msg->attributes, GstSDPAttribute, gst_sdp_attribute_clear);
295 INIT_ARRAY (msg->medias, GstSDPMedia, gst_sdp_media_uninit);
301 * gst_sdp_message_uninit:
302 * @msg: a #GstSDPMessage
304 * Free all resources allocated in @msg. @msg should not be used anymore after
305 * this function. This function should be used when @msg was allocated on the
306 * stack and initialized with gst_sdp_message_init().
308 * Returns: a #GstSDPResult.
311 gst_sdp_message_uninit (GstSDPMessage * msg)
313 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
315 gst_sdp_message_init (msg);
317 FREE_ARRAY (msg->emails);
318 FREE_ARRAY (msg->phones);
319 FREE_ARRAY (msg->bandwidths);
320 FREE_ARRAY (msg->times);
321 FREE_ARRAY (msg->zones);
322 FREE_ARRAY (msg->attributes);
323 FREE_ARRAY (msg->medias);
329 * gst_sdp_message_copy:
330 * @msg: a #GstSDPMessage
331 * @copy: (out) (transfer full): pointer to new #GstSDPMessage
333 * Allocate a new copy of @msg and store the result in @copy. The value in
334 * @copy should be release with gst_sdp_message_free function.
336 * Returns: a #GstSDPResult
341 gst_sdp_message_copy (const GstSDPMessage * msg, GstSDPMessage ** copy)
348 return GST_SDP_EINVAL;
350 ret = gst_sdp_message_new (copy);
351 if (ret != GST_SDP_OK)
356 REPLACE_STRING (cp->version, msg->version);
357 gst_sdp_message_set_origin (cp, msg->origin.username, msg->origin.sess_id,
358 msg->origin.sess_version, msg->origin.nettype, msg->origin.addrtype,
360 REPLACE_STRING (cp->session_name, msg->session_name);
361 REPLACE_STRING (cp->information, msg->information);
362 REPLACE_STRING (cp->uri, msg->uri);
364 len = gst_sdp_message_emails_len (msg);
365 for (i = 0; i < len; i++) {
366 gst_sdp_message_add_email (cp, gst_sdp_message_get_email (msg, i));
369 len = gst_sdp_message_phones_len (msg);
370 for (i = 0; i < len; i++) {
371 gst_sdp_message_add_phone (cp, gst_sdp_message_get_phone (msg, i));
374 gst_sdp_message_set_connection (cp, msg->connection.nettype,
375 msg->connection.addrtype, msg->connection.address, msg->connection.ttl,
376 msg->connection.addr_number);
378 len = gst_sdp_message_bandwidths_len (msg);
379 for (i = 0; i < len; i++) {
380 const GstSDPBandwidth *bw = gst_sdp_message_get_bandwidth (msg, i);
381 gst_sdp_message_add_bandwidth (cp, bw->bwtype, bw->bandwidth);
384 len = gst_sdp_message_times_len (msg);
385 for (i = 0; i < len; i++) {
386 const gchar **repeat = NULL;
387 const GstSDPTime *time = gst_sdp_message_get_time (msg, i);
389 if (time->repeat != NULL) {
392 repeat = g_malloc0 ((time->repeat->len + 1) * sizeof (gchar *));
393 for (j = 0; j < time->repeat->len; j++) {
394 repeat[j] = g_array_index (time->repeat, char *, j);
399 gst_sdp_message_add_time (cp, time->start, time->stop, repeat);
401 g_free ((gchar **) repeat);
404 len = gst_sdp_message_zones_len (msg);
405 for (i = 0; i < len; i++) {
406 const GstSDPZone *zone = gst_sdp_message_get_zone (msg, i);
407 gst_sdp_message_add_zone (cp, zone->time, zone->typed_time);
410 gst_sdp_message_set_key (cp, msg->key.type, msg->key.data);
412 len = gst_sdp_message_attributes_len (msg);
413 for (i = 0; i < len; i++) {
414 const GstSDPAttribute *attr = gst_sdp_message_get_attribute (msg, i);
415 gst_sdp_message_add_attribute (cp, attr->key, attr->value);
418 len = gst_sdp_message_medias_len (msg);
419 for (i = 0; i < len; i++) {
420 GstSDPMedia *media_copy;
421 const GstSDPMedia *media = gst_sdp_message_get_media (msg, i);
423 if (gst_sdp_media_copy (media, &media_copy) == GST_SDP_OK) {
424 gst_sdp_message_add_media (cp, media_copy);
425 gst_sdp_media_free (media_copy);
433 * gst_sdp_message_free:
434 * @msg: a #GstSDPMessage
436 * Free all resources allocated by @msg. @msg should not be used anymore after
437 * this function. This function should be used when @msg was dynamically
438 * allocated with gst_sdp_message_new().
440 * Returns: a #GstSDPResult.
443 gst_sdp_message_free (GstSDPMessage * msg)
445 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
447 gst_sdp_message_uninit (msg);
454 * gst_sdp_address_is_multicast:
455 * @nettype: a network type
456 * @addrtype: an address type
459 * Check if the given @addr is a multicast address.
461 * Returns: TRUE when @addr is multicast.
464 gst_sdp_address_is_multicast (const gchar * nettype, const gchar * addrtype,
467 gboolean ret = FALSE;
470 g_return_val_if_fail (addr, FALSE);
472 /* we only support IN */
473 if (nettype && strcmp (nettype, "IN") != 0)
476 /* guard against parse failures */
477 if ((iaddr = g_inet_address_new_from_string (addr)) == NULL)
480 ret = g_inet_address_get_is_multicast (iaddr);
481 g_object_unref (iaddr);
487 * gst_sdp_message_as_text:
488 * @msg: a #GstSDPMessage
490 * Convert the contents of @msg to a text string.
492 * Returns: A dynamically allocated string representing the SDP description.
495 gst_sdp_message_as_text (const GstSDPMessage * msg)
497 /* change all vars so they match rfc? */
501 g_return_val_if_fail (msg != NULL, NULL);
503 lines = g_string_new ("");
506 g_string_append_printf (lines, "v=%s\r\n", msg->version);
508 if (msg->origin.sess_id && msg->origin.sess_version && msg->origin.nettype &&
509 msg->origin.addrtype && msg->origin.addr)
510 g_string_append_printf (lines, "o=%s %s %s %s %s %s\r\n",
511 msg->origin.username ? msg->origin.username : "-", msg->origin.sess_id,
512 msg->origin.sess_version, msg->origin.nettype, msg->origin.addrtype,
515 if (msg->session_name)
516 g_string_append_printf (lines, "s=%s\r\n", msg->session_name);
518 if (msg->information)
519 g_string_append_printf (lines, "i=%s\r\n", msg->information);
522 g_string_append_printf (lines, "u=%s\r\n", msg->uri);
524 for (i = 0; i < gst_sdp_message_emails_len (msg); i++)
525 g_string_append_printf (lines, "e=%s\r\n",
526 gst_sdp_message_get_email (msg, i));
528 for (i = 0; i < gst_sdp_message_phones_len (msg); i++)
529 g_string_append_printf (lines, "p=%s\r\n",
530 gst_sdp_message_get_phone (msg, i));
532 if (msg->connection.nettype && msg->connection.addrtype &&
533 msg->connection.address) {
534 g_string_append_printf (lines, "c=%s %s %s", msg->connection.nettype,
535 msg->connection.addrtype, msg->connection.address);
536 if (gst_sdp_address_is_multicast (msg->connection.nettype,
537 msg->connection.addrtype, msg->connection.address)) {
538 /* only add ttl for IP4 */
539 if (strcmp (msg->connection.addrtype, "IP4") == 0)
540 g_string_append_printf (lines, "/%u", msg->connection.ttl);
541 if (msg->connection.addr_number > 1)
542 g_string_append_printf (lines, "/%u", msg->connection.addr_number);
544 g_string_append_printf (lines, "\r\n");
547 for (i = 0; i < gst_sdp_message_bandwidths_len (msg); i++) {
548 const GstSDPBandwidth *bandwidth = gst_sdp_message_get_bandwidth (msg, i);
550 g_string_append_printf (lines, "b=%s:%u\r\n", bandwidth->bwtype,
551 bandwidth->bandwidth);
554 if (gst_sdp_message_times_len (msg) == 0) {
555 g_string_append_printf (lines, "t=0 0\r\n");
557 for (i = 0; i < gst_sdp_message_times_len (msg); i++) {
558 const GstSDPTime *times = gst_sdp_message_get_time (msg, i);
560 g_string_append_printf (lines, "t=%s %s\r\n", times->start, times->stop);
562 if (times->repeat != NULL) {
565 g_string_append_printf (lines, "r=%s",
566 g_array_index (times->repeat, gchar *, 0));
567 for (j = 1; j < times->repeat->len; j++)
568 g_string_append_printf (lines, " %s",
569 g_array_index (times->repeat, gchar *, j));
570 g_string_append_printf (lines, "\r\n");
575 if (gst_sdp_message_zones_len (msg) > 0) {
576 const GstSDPZone *zone = gst_sdp_message_get_zone (msg, 0);
578 g_string_append_printf (lines, "z=%s %s", zone->time, zone->typed_time);
579 for (i = 1; i < gst_sdp_message_zones_len (msg); i++) {
580 zone = gst_sdp_message_get_zone (msg, i);
581 g_string_append_printf (lines, " %s %s", zone->time, zone->typed_time);
583 g_string_append_printf (lines, "\r\n");
587 g_string_append_printf (lines, "k=%s", msg->key.type);
589 g_string_append_printf (lines, ":%s", msg->key.data);
590 g_string_append_printf (lines, "\r\n");
593 for (i = 0; i < gst_sdp_message_attributes_len (msg); i++) {
594 const GstSDPAttribute *attr = gst_sdp_message_get_attribute (msg, i);
597 g_string_append_printf (lines, "a=%s", attr->key);
598 if (attr->value && attr->value[0] != '\0')
599 g_string_append_printf (lines, ":%s", attr->value);
600 g_string_append_printf (lines, "\r\n");
604 for (i = 0; i < gst_sdp_message_medias_len (msg); i++) {
605 const GstSDPMedia *media = gst_sdp_message_get_media (msg, i);
606 gchar *sdp_media_str;
608 sdp_media_str = gst_sdp_media_as_text (media);
609 g_string_append_printf (lines, "%s", sdp_media_str);
610 g_free (sdp_media_str);
613 return g_string_free (lines, FALSE);
619 return c >= '0' && c <= '9' ? c - '0'
620 : c >= 'A' && c <= 'F' ? c - 'A' + 10
621 : c >= 'a' && c <= 'f' ? c - 'a' + 10 : 0;
625 * gst_sdp_message_parse_uri:
626 * @uri: the start of the uri
627 * @msg: the result #GstSDPMessage
629 * Parse the null-terminated @uri and store the result in @msg.
631 * The uri should be of the form:
633 * scheme://[address[:ttl=ttl][:noa=noa]]/[sessionname]
634 * [#type=value *[&type=value]]
636 * where value is url encoded. This looslely resembles
637 * http://tools.ietf.org/html/draft-fujikawa-sdp-url-01
639 * Returns: #GST_SDP_OK on success.
642 gst_sdp_message_parse_uri (const gchar * uri, GstSDPMessage * msg)
646 const gchar *colon, *slash, *hash, *p;
649 g_return_val_if_fail (uri != NULL, GST_SDP_EINVAL);
650 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
652 colon = strstr (uri, "://");
656 /* FIXME connection info goes here */
658 slash = strstr (colon + 3, "/");
662 /* FIXME session name goes here */
664 hash = strstr (slash + 1, "#");
668 lines = g_string_new ("");
671 for (p = hash + 1; *p; p++) {
673 g_string_append_printf (lines, "\r\n");
675 g_string_append_c (lines, ' ');
676 else if (*p == '%') {
681 g_string_append_c (lines, (hex_to_int (a) << 4) | hex_to_int (b));
688 g_string_append_c (lines, *p);
691 message = g_string_free (lines, FALSE);
693 gst_sdp_message_parse_buffer ((const guint8 *) message, strlen (message),
702 return GST_SDP_EINVAL;
706 return GST_SDP_EINVAL;
710 return GST_SDP_EINVAL;
714 static const guchar acceptable[96] = {
715 /* X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
716 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, /* 2X !"#$%&'()*+,-./ */
717 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3X 0123456789:;<=>? */
718 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, /* 4X @ABCDEFGHIJKLMNO */
719 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, /* 5X PQRSTUVWXYZ[\]^_ */
720 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, /* 6X `abcdefghijklmno */
721 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 /* 7X pqrstuvwxyz{|}~DEL */
724 static const gchar hex[16] = "0123456789ABCDEF";
726 #define ACCEPTABLE_CHAR(a) (((guchar)(a))>=32 && ((guchar)(a))<128 && acceptable[(((guchar)a))-32])
729 * gst_sdp_message_as_uri:
730 * @scheme: the uri scheme
731 * @msg: the #GstSDPMessage
733 * Creates a uri from @msg with the given @scheme. The uri has the format:
735 * \@scheme:///[#type=value *[&type=value]]
737 * Where each value is url encoded.
739 * Returns: a uri for @msg.
742 gst_sdp_message_as_uri (const gchar * scheme, const GstSDPMessage * msg)
744 gchar *serialized, *p;
749 g_return_val_if_fail (scheme != NULL, NULL);
750 g_return_val_if_fail (msg != NULL, NULL);
752 serialized = gst_sdp_message_as_text (msg);
754 lines = g_string_new ("");
755 g_string_append_printf (lines, "%s:///#", scheme);
759 for (p = serialized; *p; p++) {
761 g_string_append_printf (lines, "%c=", *p);
769 else if (*p == '\n') {
771 g_string_append_c (lines, '&');
773 } else if (*p == ' ')
774 g_string_append_c (lines, '+');
775 else if (ACCEPTABLE_CHAR (*p))
776 g_string_append_c (lines, *p);
779 g_string_append_printf (lines, "%%%c%c", hex[*p >> 4], hex[*p & 0xf]);
783 res = g_string_free (lines, FALSE);
790 * gst_sdp_message_set_version:
791 * @msg: a #GstSDPMessage
792 * @version: the version
794 * Set the version in @msg.
796 * Returns: a #GstSDPResult.
798 DEFINE_STRING_SETTER (version);
800 * gst_sdp_message_get_version:
801 * @msg: a #GstSDPMessage
803 * Get the version in @msg.
805 * Returns: a #GstSDPResult.
807 DEFINE_STRING_GETTER (version);
810 * gst_sdp_message_set_origin:
811 * @msg: a #GstSDPMessage
812 * @username: the user name
813 * @sess_id: a session id
814 * @sess_version: a session version
815 * @nettype: a network type
816 * @addrtype: an address type
819 * Configure the SDP origin in @msg with the given parameters.
821 * Returns: #GST_SDP_OK.
824 gst_sdp_message_set_origin (GstSDPMessage * msg, const gchar * username,
825 const gchar * sess_id, const gchar * sess_version, const gchar * nettype,
826 const gchar * addrtype, const gchar * addr)
828 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
830 REPLACE_STRING (msg->origin.username, username);
831 REPLACE_STRING (msg->origin.sess_id, sess_id);
832 REPLACE_STRING (msg->origin.sess_version, sess_version);
833 REPLACE_STRING (msg->origin.nettype, nettype);
834 REPLACE_STRING (msg->origin.addrtype, addrtype);
835 REPLACE_STRING (msg->origin.addr, addr);
841 * gst_sdp_message_get_origin:
842 * @msg: a #GstSDPMessage
844 * Get the origin of @msg.
846 * Returns: a #GstSDPOrigin. The result remains valid as long as @msg is valid.
849 gst_sdp_message_get_origin (const GstSDPMessage * msg)
851 g_return_val_if_fail (msg != NULL, NULL);
857 * gst_sdp_message_set_session_name:
858 * @msg: a #GstSDPMessage
859 * @session_name: the session name
861 * Set the session name in @msg.
863 * Returns: a #GstSDPResult.
865 DEFINE_STRING_SETTER (session_name);
867 * gst_sdp_message_get_session_name:
868 * @msg: a #GstSDPMessage
870 * Get the session name in @msg.
872 * Returns: a #GstSDPResult.
874 DEFINE_STRING_GETTER (session_name);
876 * gst_sdp_message_set_information:
877 * @msg: a #GstSDPMessage
878 * @information: the information
880 * Set the information in @msg.
882 * Returns: a #GstSDPResult.
884 DEFINE_STRING_SETTER (information);
886 * gst_sdp_message_get_information:
887 * @msg: a #GstSDPMessage
889 * Get the information in @msg.
891 * Returns: a #GstSDPResult.
893 DEFINE_STRING_GETTER (information);
895 * gst_sdp_message_set_uri:
896 * @msg: a #GstSDPMessage
899 * Set the URI in @msg.
901 * Returns: a #GstSDPResult.
903 DEFINE_STRING_SETTER (uri);
905 * gst_sdp_message_get_uri:
906 * @msg: a #GstSDPMessage
908 * Get the URI in @msg.
910 * Returns: a #GstSDPResult.
912 DEFINE_STRING_GETTER (uri);
915 * gst_sdp_message_emails_len:
916 * @msg: a #GstSDPMessage
918 * Get the number of emails in @msg.
920 * Returns: the number of emails in @msg.
922 DEFINE_ARRAY_LEN (emails);
924 * gst_sdp_message_get_email:
925 * @msg: a #GstSDPMessage
926 * @idx: an email index
928 * Get the email with number @idx from @msg.
930 * Returns: the email at position @idx.
932 DEFINE_STR_ARRAY_GETTER (email, emails);
935 * gst_sdp_message_insert_email:
936 * @msg: a #GstSDPMessage
940 * Insert @email into the array of emails in @msg at index @idx.
941 * When -1 is given as @idx, the email is inserted at the end.
943 * Returns: a #GstSDPResult.
947 DEFINE_STR_ARRAY_INSERT (email, emails);
950 * gst_sdp_message_replace_email:
951 * @msg: a #GstSDPMessage
952 * @idx: an email index
955 * Replace the email in @msg at index @idx with @email.
957 * Returns: a #GstSDPResult.
961 DEFINE_STR_ARRAY_REPLACE (email, emails);
964 * gst_sdp_message_remove_email:
965 * @msg: a #GstSDPMessage
966 * @idx: an email index
968 * Remove the email in @msg at index @idx.
970 * Returns: a #GstSDPResult.
974 DEFINE_STR_ARRAY_REMOVE (email, emails);
977 * gst_sdp_message_add_email:
978 * @msg: a #GstSDPMessage
981 * Add @email to the list of emails in @msg.
983 * Returns: a #GstSDPResult.
985 DEFINE_STR_ARRAY_ADDER (email, emails);
988 * gst_sdp_message_phones_len:
989 * @msg: a #GstSDPMessage
991 * Get the number of phones in @msg.
993 * Returns: the number of phones in @msg.
995 DEFINE_ARRAY_LEN (phones);
997 * gst_sdp_message_get_phone:
998 * @msg: a #GstSDPMessage
999 * @idx: a phone index
1001 * Get the phone with number @idx from @msg.
1003 * Returns: the phone at position @idx.
1005 DEFINE_STR_ARRAY_GETTER (phone, phones);
1008 * gst_sdp_message_insert_phone:
1009 * @msg: a #GstSDPMessage
1010 * @idx: a phone index
1013 * Insert @phone into the array of phone numbers in @msg at index @idx.
1014 * When -1 is given as @idx, the phone is inserted at the end.
1016 * Returns: a #GstSDPResult.
1020 DEFINE_STR_ARRAY_INSERT (phone, phones);
1023 * gst_sdp_message_replace_phone:
1024 * @msg: a #GstSDPMessage
1025 * @idx: a phone index
1028 * Replace the phone number in @msg at index @idx with @phone.
1030 * Returns: a #GstSDPResult.
1034 DEFINE_STR_ARRAY_REPLACE (phone, phones);
1037 * gst_sdp_message_remove_phone:
1038 * @msg: a #GstSDPMessage
1039 * @idx: a phone index
1041 * Remove the phone number in @msg at index @idx.
1043 * Returns: a #GstSDPResult.
1047 DEFINE_STR_ARRAY_REMOVE (phone, phones);
1050 * gst_sdp_message_add_phone:
1051 * @msg: a #GstSDPMessage
1054 * Add @phone to the list of phones in @msg.
1056 * Returns: a #GstSDPResult.
1058 DEFINE_STR_ARRAY_ADDER (phone, phones);
1062 * gst_sdp_message_set_connection:
1063 * @msg: a #GstSDPMessage
1064 * @nettype: the type of network. "IN" is defined to have the meaning
1066 * @addrtype: the type of address.
1067 * @address: the address
1068 * @ttl: the time to live of the address
1069 * @addr_number: the number of layers
1071 * Configure the SDP connection in @msg with the given parameters.
1073 * Returns: a #GstSDPResult.
1076 gst_sdp_message_set_connection (GstSDPMessage * msg, const gchar * nettype,
1077 const gchar * addrtype, const gchar * address, guint ttl, guint addr_number)
1079 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1081 REPLACE_STRING (msg->connection.nettype, nettype);
1082 REPLACE_STRING (msg->connection.addrtype, addrtype);
1083 REPLACE_STRING (msg->connection.address, address);
1084 msg->connection.ttl = ttl;
1085 msg->connection.addr_number = addr_number;
1091 * gst_sdp_message_get_connection:
1092 * @msg: a #GstSDPMessage
1094 * Get the connection of @msg.
1096 * Returns: a #GstSDPConnection. The result remains valid as long as @msg is valid.
1098 const GstSDPConnection *
1099 gst_sdp_message_get_connection (const GstSDPMessage * msg)
1101 g_return_val_if_fail (msg != NULL, NULL);
1103 return &msg->connection;
1107 * gst_sdp_bandwidth_set:
1108 * @bw: a #GstSDPBandwidth
1109 * @bwtype: the bandwidth modifier type
1110 * @bandwidth: the bandwidth in kilobits per second
1112 * Set bandwidth information in @bw.
1114 * Returns: a #GstSDPResult.
1119 gst_sdp_bandwidth_set (GstSDPBandwidth * bw, const gchar * bwtype,
1122 g_return_val_if_fail (bw != NULL, GST_SDP_EINVAL);
1124 bw->bwtype = g_strdup (bwtype);
1125 bw->bandwidth = bandwidth;
1130 * gst_sdp_bandwidth_clear:
1131 * @bw: a #GstSDPBandwidth
1133 * Reset the bandwidth information in @bw.
1135 * Returns: a #GstSDPResult.
1140 gst_sdp_bandwidth_clear (GstSDPBandwidth * bw)
1142 g_return_val_if_fail (bw != NULL, GST_SDP_EINVAL);
1144 FREE_STRING (bw->bwtype);
1150 * gst_sdp_message_bandwidths_len:
1151 * @msg: a #GstSDPMessage
1153 * Get the number of bandwidth information in @msg.
1155 * Returns: the number of bandwidth information in @msg.
1157 DEFINE_ARRAY_LEN (bandwidths);
1159 * gst_sdp_message_get_bandwidth:
1160 * @msg: a #GstSDPMessage
1161 * @idx: the bandwidth index
1163 * Get the bandwidth at index @idx from @msg.
1165 * Returns: a #GstSDPBandwidth.
1167 DEFINE_ARRAY_GETTER (bandwidth, bandwidths, GstSDPBandwidth);
1169 #define DUP_BANDWIDTH(v, val) memcpy (v, val, sizeof (GstSDPBandwidth))
1170 #define FREE_BANDWIDTH(v) gst_sdp_bandwidth_clear(v)
1173 * gst_sdp_message_insert_bandwidth:
1174 * @msg: a #GstSDPMessage
1176 * @bw: the bandwidth
1178 * Insert bandwidth parameters into the array of bandwidths in @msg
1180 * When -1 is given as @idx, the bandwidth is inserted at the end.
1182 * Returns: a #GstSDPResult.
1186 DEFINE_ARRAY_INSERT (bandwidth, bandwidths, GstSDPBandwidth *, DUP_BANDWIDTH,
1190 * gst_sdp_message_replace_bandwidth:
1191 * @msg: a #GstSDPMessage
1192 * @idx: the bandwidth index
1193 * @bw: the bandwidth
1195 * Replace the bandwidth information in @msg at index @idx with @bw.
1197 * Returns: a #GstSDPResult.
1201 DEFINE_ARRAY_REPLACE (bandwidth, bandwidths, GstSDPBandwidth *, FREE_BANDWIDTH,
1202 DUP_BANDWIDTH, GstSDPBandwidth);
1205 * gst_sdp_message_remove_bandwidth:
1206 * @msg: a #GstSDPMessage
1207 * @idx: the bandwidth index
1209 * Remove the bandwidth information in @msg at index @idx.
1211 * Returns: a #GstSDPResult.
1215 DEFINE_ARRAY_REMOVE (bandwidth, bandwidths, GstSDPBandwidth, FREE_BANDWIDTH);
1218 * gst_sdp_message_add_bandwidth:
1219 * @msg: a #GstSDPMessage
1220 * @bwtype: the bandwidth modifier type
1221 * @bandwidth: the bandwidth in kilobits per second
1223 * Add the specified bandwidth information to @msg.
1225 * Returns: a #GstSDPResult.
1228 gst_sdp_message_add_bandwidth (GstSDPMessage * msg, const gchar * bwtype,
1233 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1235 gst_sdp_bandwidth_set (&bw, bwtype, bandwidth);
1236 return gst_sdp_message_insert_bandwidth (msg, -1, &bw);
1242 * @start: the start time
1243 * @stop: the stop time
1244 * @repeat: (array zero-terminated=1): the repeat times
1246 * Set time information @start, @stop and @repeat in @t.
1248 * Returns: a #GstSDPResult.
1253 gst_sdp_time_set (GstSDPTime * t, const gchar * start,
1254 const gchar * stop, const gchar ** repeat)
1256 g_return_val_if_fail (t != NULL, GST_SDP_EINVAL);
1258 t->start = g_strdup (start);
1259 t->stop = g_strdup (stop);
1261 t->repeat = g_array_new (FALSE, TRUE, sizeof (gchar *));
1262 for (; *repeat; repeat++) {
1263 gchar *r = g_strdup (*repeat);
1265 g_array_append_val (t->repeat, r);
1274 * gst_sdp_time_clear:
1277 * Reset the time information in @t.
1279 * Returns: a #GstSDPResult.
1284 gst_sdp_time_clear (GstSDPTime * t)
1286 g_return_val_if_fail (t != NULL, GST_SDP_EINVAL);
1288 FREE_STRING (t->start);
1289 FREE_STRING (t->stop);
1290 INIT_STR_ARRAY (t->repeat);
1291 FREE_ARRAY (t->repeat);
1297 * gst_sdp_message_times_len:
1298 * @msg: a #GstSDPMessage
1300 * Get the number of time information entries in @msg.
1302 * Returns: the number of time information entries in @msg.
1304 DEFINE_ARRAY_LEN (times);
1307 * gst_sdp_message_get_time:
1308 * @msg: a #GstSDPMessage
1309 * @idx: the time index
1311 * Get time information with index @idx from @msg.
1313 * Returns: a #GstSDPTime.
1315 DEFINE_ARRAY_GETTER (time, times, GstSDPTime);
1317 #define DUP_TIME(v, val) memcpy (v, val, sizeof (GstSDPTime))
1318 #define FREE_TIME(v) gst_sdp_time_clear(v)
1321 * gst_sdp_message_insert_time:
1322 * @msg: a #GstSDPMessage
1326 * Insert time parameters into the array of times in @msg
1328 * When -1 is given as @idx, the times are inserted at the end.
1330 * Returns: a #GstSDPResult.
1334 DEFINE_ARRAY_INSERT (time, times, GstSDPTime *, DUP_TIME, GstSDPTime);
1337 * gst_sdp_message_replace_time:
1338 * @msg: a #GstSDPMessage
1342 * Replace the time information in @msg at index @idx with @t.
1344 * Returns: a #GstSDPResult.
1348 DEFINE_ARRAY_REPLACE (time, times, GstSDPTime *, FREE_TIME,
1349 DUP_TIME, GstSDPTime);
1352 * gst_sdp_message_remove_time:
1353 * @msg: a #GstSDPMessage
1356 * Remove the time information in @msg at index @idx.
1358 * Returns: a #GstSDPResult.
1362 DEFINE_ARRAY_REMOVE (time, times, GstSDPTime, FREE_TIME);
1365 * gst_sdp_message_add_time:
1366 * @msg: a #GstSDPMessage
1367 * @start: the start time
1368 * @stop: the stop time
1369 * @repeat: (array zero-terminated=1): the repeat times
1371 * Add time information @start and @stop to @msg.
1373 * Returns: a #GstSDPResult.
1376 gst_sdp_message_add_time (GstSDPMessage * msg, const gchar * start,
1377 const gchar * stop, const gchar ** repeat)
1381 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1383 gst_sdp_time_set (×, start, stop, repeat);
1384 g_array_append_val (msg->times, times);
1391 * @zone: a #GstSDPZone
1392 * @adj_time: the NTP time that a time zone adjustment happens
1393 * @typed_time: the offset from the time when the session was first scheduled
1395 * Set zone information in @zone.
1397 * Returns: a #GstSDPResult.
1402 gst_sdp_zone_set (GstSDPZone * zone, const gchar * adj_time,
1403 const gchar * typed_time)
1405 g_return_val_if_fail (zone != NULL, GST_SDP_EINVAL);
1407 zone->time = g_strdup (adj_time);
1408 zone->typed_time = g_strdup (typed_time);
1413 * gst_sdp_zone_clear:
1414 * @zone: a #GstSDPZone
1416 * Reset the zone information in @zone.
1418 * Returns: a #GstSDPResult.
1423 gst_sdp_zone_clear (GstSDPZone * zone)
1425 g_return_val_if_fail (zone != NULL, GST_SDP_EINVAL);
1427 FREE_STRING (zone->time);
1428 FREE_STRING (zone->typed_time);
1433 * gst_sdp_message_zones_len:
1434 * @msg: a #GstSDPMessage
1436 * Get the number of time zone information entries in @msg.
1438 * Returns: the number of time zone information entries in @msg.
1440 DEFINE_ARRAY_LEN (zones);
1442 * gst_sdp_message_get_zone:
1443 * @msg: a #GstSDPMessage
1444 * @idx: the zone index
1446 * Get time zone information with index @idx from @msg.
1448 * Returns: a #GstSDPZone.
1450 DEFINE_ARRAY_GETTER (zone, zones, GstSDPZone);
1452 #define DUP_ZONE(v, val) memcpy (v, val, sizeof (GstSDPZone))
1453 #define FREE_ZONE(v) gst_sdp_zone_clear(v)
1456 * gst_sdp_message_insert_zone:
1457 * @msg: a #GstSDPMessage
1459 * @zone: a #GstSDPZone
1461 * Insert zone parameters into the array of zones in @msg
1463 * When -1 is given as @idx, the zone is inserted at the end.
1465 * Returns: a #GstSDPResult.
1469 DEFINE_ARRAY_INSERT (zone, zones, GstSDPZone *, DUP_ZONE, GstSDPZone);
1472 * gst_sdp_message_replace_zone:
1473 * @msg: a #GstSDPMessage
1475 * @zone: a #GstSDPZone
1477 * Replace the zone information in @msg at index @idx with @zone.
1479 * Returns: a #GstSDPResult.
1483 DEFINE_ARRAY_REPLACE (zone, zones, GstSDPZone *, FREE_ZONE,
1484 DUP_ZONE, GstSDPZone);
1487 * gst_sdp_message_remove_zone:
1488 * @msg: a #GstSDPMessage
1491 * Remove the zone information in @msg at index @idx.
1493 * Returns: a #GstSDPResult.
1497 DEFINE_ARRAY_REMOVE (zone, zones, GstSDPZone, FREE_ZONE);
1500 * gst_sdp_message_add_zone:
1501 * @msg: a #GstSDPMessage
1502 * @adj_time: the NTP time that a time zone adjustment happens
1503 * @typed_time: the offset from the time when the session was first scheduled
1505 * Add time zone information to @msg.
1507 * Returns: a #GstSDPResult.
1510 gst_sdp_message_add_zone (GstSDPMessage * msg, const gchar * adj_time,
1511 const gchar * typed_time)
1515 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1517 gst_sdp_zone_set (&zone, adj_time, typed_time);
1518 g_array_append_val (msg->zones, zone);
1524 * gst_sdp_message_set_key:
1525 * @msg: a #GstSDPMessage
1526 * @type: the encryption type
1527 * @data: the encryption data
1529 * Adds the encryption information to @msg.
1531 * Returns: a #GstSDPResult.
1534 gst_sdp_message_set_key (GstSDPMessage * msg, const gchar * type,
1537 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1539 REPLACE_STRING (msg->key.type, type);
1540 REPLACE_STRING (msg->key.data, data);
1546 * gst_sdp_message_get_key:
1547 * @msg: a #GstSDPMessage
1549 * Get the encryption information from @msg.
1551 * Returns: a #GstSDPKey.
1554 gst_sdp_message_get_key (const GstSDPMessage * msg)
1556 g_return_val_if_fail (msg != NULL, NULL);
1562 * gst_sdp_attribute_set:
1563 * @attr: a #GstSDPAttribute
1565 * @value: (nullable): the value
1567 * Set the attribute with @key and @value.
1569 * Returns: @GST_SDP_OK.
1574 gst_sdp_attribute_set (GstSDPAttribute * attr, const gchar * key,
1575 const gchar * value)
1577 g_return_val_if_fail (attr != NULL, GST_SDP_EINVAL);
1578 g_return_val_if_fail (key != NULL, GST_SDP_EINVAL);
1580 attr->key = g_strdup (key);
1581 attr->value = g_strdup (value);
1586 * gst_sdp_attribute_clear:
1587 * @attr: a #GstSDPAttribute
1589 * Clear the attribute.
1591 * Returns: @GST_SDP_OK.
1596 gst_sdp_attribute_clear (GstSDPAttribute * attr)
1598 g_return_val_if_fail (attr != NULL, GST_SDP_EINVAL);
1600 FREE_STRING (attr->key);
1601 FREE_STRING (attr->value);
1606 * gst_sdp_message_attributes_len:
1607 * @msg: a #GstSDPMessage
1609 * Get the number of attributes in @msg.
1611 * Returns: the number of attributes in @msg.
1613 DEFINE_ARRAY_LEN (attributes);
1616 * gst_sdp_message_get_attribute:
1617 * @msg: a #GstSDPMessage
1620 * Get the attribute at position @idx in @msg.
1622 * Returns: the #GstSDPAttribute at position @idx.
1624 DEFINE_ARRAY_GETTER (attribute, attributes, GstSDPAttribute);
1627 * gst_sdp_message_get_attribute_val_n:
1628 * @msg: a #GstSDPMessage
1632 * Get the @nth attribute with key @key in @msg.
1634 * Returns: the attribute value of the @nth attribute with @key.
1637 gst_sdp_message_get_attribute_val_n (const GstSDPMessage * msg,
1638 const gchar * key, guint nth)
1642 g_return_val_if_fail (msg != NULL, NULL);
1643 g_return_val_if_fail (key != NULL, NULL);
1645 for (i = 0; i < msg->attributes->len; i++) {
1646 GstSDPAttribute *attr;
1648 attr = &g_array_index (msg->attributes, GstSDPAttribute, i);
1649 if (!strcmp (attr->key, key)) {
1660 * gst_sdp_message_get_attribute_val:
1661 * @msg: a #GstSDPMessage
1664 * Get the first attribute with key @key in @msg.
1666 * Returns: the attribute value of the first attribute with @key.
1669 gst_sdp_message_get_attribute_val (const GstSDPMessage * msg, const gchar * key)
1671 return gst_sdp_message_get_attribute_val_n (msg, key, 0);
1674 #define DUP_ATTRIBUTE(v, val) memcpy (v, val, sizeof (GstSDPAttribute))
1675 #define FREE_ATTRIBUTE(v) gst_sdp_attribute_clear(v)
1678 * gst_sdp_message_insert_attribute:
1679 * @msg: a #GstSDPMessage
1681 * @attr: a #GstSDPAttribute
1683 * Insert attribute into the array of attributes in @msg
1685 * When -1 is given as @idx, the attribute is inserted at the end.
1687 * Returns: a #GstSDPResult.
1691 DEFINE_ARRAY_INSERT (attribute, attributes, GstSDPAttribute *, DUP_ATTRIBUTE,
1695 * gst_sdp_message_replace_attribute:
1696 * @msg: a #GstSDPMessage
1698 * @attr: a #GstSDPAttribute
1700 * Replace the attribute in @msg at index @idx with @attr.
1702 * Returns: a #GstSDPResult.
1706 DEFINE_ARRAY_REPLACE (attribute, attributes, GstSDPAttribute *, FREE_ATTRIBUTE,
1707 DUP_ATTRIBUTE, GstSDPAttribute);
1710 * gst_sdp_message_remove_attribute:
1711 * @msg: a #GstSDPMessage
1714 * Remove the attribute in @msg at index @idx.
1716 * Returns: a #GstSDPResult.
1720 DEFINE_ARRAY_REMOVE (attribute, attributes, GstSDPAttribute, FREE_ATTRIBUTE);
1723 * gst_sdp_message_add_attribute:
1724 * @msg: a #GstSDPMessage
1726 * @value: (nullable): the value
1728 * Add the attribute with @key and @value to @msg.
1730 * Returns: @GST_SDP_OK.
1733 gst_sdp_message_add_attribute (GstSDPMessage * msg, const gchar * key,
1734 const gchar * value)
1736 GstSDPAttribute attr;
1738 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1739 g_return_val_if_fail (key != NULL, GST_SDP_EINVAL);
1741 gst_sdp_attribute_set (&attr, key, value);
1742 g_array_append_val (msg->attributes, attr);
1748 * gst_sdp_message_medias_len:
1749 * @msg: a #GstSDPMessage
1751 * Get the number of media descriptions in @msg.
1753 * Returns: the number of media descriptions in @msg.
1755 DEFINE_ARRAY_LEN (medias);
1757 * gst_sdp_message_get_media:
1758 * @msg: a #GstSDPMessage
1761 * Get the media description at index @idx in @msg.
1763 * Returns: a #GstSDPMedia.
1765 DEFINE_ARRAY_GETTER (media, medias, GstSDPMedia);
1768 * gst_sdp_message_add_media:
1769 * @msg: a #GstSDPMessage
1770 * @media: a #GstSDPMedia to add
1772 * Adds @media to the array of medias in @msg. This function takes ownership of
1773 * the contents of @media so that @media will have to be reinitialized with
1774 * gst_sdp_media_init() before it can be used again.
1776 * Returns: a #GstSDPResult.
1779 gst_sdp_message_add_media (GstSDPMessage * msg, GstSDPMedia * media)
1782 GstSDPMedia *nmedia;
1784 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
1785 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
1787 len = msg->medias->len;
1788 g_array_set_size (msg->medias, len + 1);
1789 nmedia = &g_array_index (msg->medias, GstSDPMedia, len);
1791 memcpy (nmedia, media, sizeof (GstSDPMedia));
1792 memset (media, 0, sizeof (GstSDPMedia));
1800 * gst_sdp_media_new:
1801 * @media: (out) (transfer full): pointer to new #GstSDPMedia
1803 * Allocate a new GstSDPMedia and store the result in @media.
1805 * Returns: a #GstSDPResult.
1808 gst_sdp_media_new (GstSDPMedia ** media)
1810 GstSDPMedia *newmedia;
1812 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
1814 newmedia = g_new0 (GstSDPMedia, 1);
1818 return gst_sdp_media_init (newmedia);
1822 * gst_sdp_media_init:
1823 * @media: a #GstSDPMedia
1825 * Initialize @media so that its contents are as if it was freshly allocated
1826 * with gst_sdp_media_new(). This function is mostly used to initialize a media
1827 * allocated on the stack. gst_sdp_media_uninit() undoes this operation.
1829 * When this function is invoked on newly allocated data (with malloc or on the
1830 * stack), its contents should be set to 0 before calling this function.
1832 * Returns: a #GstSDPResult.
1835 gst_sdp_media_init (GstSDPMedia * media)
1837 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
1839 FREE_STRING (media->media);
1841 media->num_ports = 0;
1842 FREE_STRING (media->proto);
1843 INIT_STR_ARRAY (media->fmts);
1844 FREE_STRING (media->information);
1845 INIT_ARRAY (media->connections, GstSDPConnection, gst_sdp_connection_clear);
1846 INIT_ARRAY (media->bandwidths, GstSDPBandwidth, gst_sdp_bandwidth_clear);
1847 gst_sdp_key_init (&media->key);
1848 INIT_ARRAY (media->attributes, GstSDPAttribute, gst_sdp_attribute_clear);
1854 * gst_sdp_media_uninit:
1855 * @media: a #GstSDPMedia
1857 * Free all resources allocated in @media. @media should not be used anymore after
1858 * this function. This function should be used when @media was allocated on the
1859 * stack and initialized with gst_sdp_media_init().
1861 * Returns: a #GstSDPResult.
1864 gst_sdp_media_uninit (GstSDPMedia * media)
1866 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
1868 gst_sdp_media_init (media);
1869 FREE_ARRAY (media->fmts);
1870 FREE_ARRAY (media->connections);
1871 FREE_ARRAY (media->bandwidths);
1872 FREE_ARRAY (media->attributes);
1878 * gst_sdp_media_free:
1879 * @media: a #GstSDPMedia
1881 * Free all resources allocated by @media. @media should not be used anymore after
1882 * this function. This function should be used when @media was dynamically
1883 * allocated with gst_sdp_media_new().
1885 * Returns: a #GstSDPResult.
1888 gst_sdp_media_free (GstSDPMedia * media)
1890 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
1892 gst_sdp_media_uninit (media);
1899 * gst_sdp_media_copy:
1900 * @media: a #GstSDPMedia
1901 * @copy: (out) (transfer full): pointer to new #GstSDPMedia
1903 * Allocate a new copy of @media and store the result in @copy. The value in
1904 * @copy should be release with gst_sdp_media_free function.
1906 * Returns: a #GstSDPResult
1911 gst_sdp_media_copy (const GstSDPMedia * media, GstSDPMedia ** copy)
1918 return GST_SDP_EINVAL;
1920 ret = gst_sdp_media_new (copy);
1921 if (ret != GST_SDP_OK)
1926 REPLACE_STRING (cp->media, media->media);
1927 cp->port = media->port;
1928 cp->num_ports = media->num_ports;
1929 REPLACE_STRING (cp->proto, media->proto);
1931 len = gst_sdp_media_formats_len (media);
1932 for (i = 0; i < len; i++) {
1933 gst_sdp_media_add_format (cp, gst_sdp_media_get_format (media, i));
1936 REPLACE_STRING (cp->information, media->information);
1938 len = gst_sdp_media_connections_len (media);
1939 for (i = 0; i < len; i++) {
1940 const GstSDPConnection *connection =
1941 gst_sdp_media_get_connection (media, i);
1942 gst_sdp_media_add_connection (cp, connection->nettype, connection->addrtype,
1943 connection->address, connection->ttl, connection->addr_number);
1946 len = gst_sdp_media_bandwidths_len (media);
1947 for (i = 0; i < len; i++) {
1948 const GstSDPBandwidth *bw = gst_sdp_media_get_bandwidth (media, i);
1949 gst_sdp_media_add_bandwidth (cp, bw->bwtype, bw->bandwidth);
1952 gst_sdp_media_set_key (cp, media->key.type, media->key.data);
1954 len = gst_sdp_media_attributes_len (media);
1955 for (i = 0; i < len; i++) {
1956 const GstSDPAttribute *att = gst_sdp_media_get_attribute (media, i);
1957 gst_sdp_media_add_attribute (cp, att->key, att->value);
1964 * gst_sdp_media_as_text:
1965 * @media: a #GstSDPMedia
1967 * Convert the contents of @media to a text string.
1969 * Returns: A dynamically allocated string representing the media.
1972 gst_sdp_media_as_text (const GstSDPMedia * media)
1977 g_return_val_if_fail (media != NULL, NULL);
1979 lines = g_string_new ("");
1982 g_string_append_printf (lines, "m=%s", media->media);
1984 g_string_append_printf (lines, " %u", media->port);
1986 if (media->num_ports > 1)
1987 g_string_append_printf (lines, "/%u", media->num_ports);
1989 g_string_append_printf (lines, " %s", media->proto);
1991 for (i = 0; i < gst_sdp_media_formats_len (media); i++)
1992 g_string_append_printf (lines, " %s", gst_sdp_media_get_format (media, i));
1993 g_string_append_printf (lines, "\r\n");
1995 if (media->information)
1996 g_string_append_printf (lines, "i=%s", media->information);
1998 for (i = 0; i < gst_sdp_media_connections_len (media); i++) {
1999 const GstSDPConnection *conn = gst_sdp_media_get_connection (media, i);
2001 if (conn->nettype && conn->addrtype && conn->address) {
2002 g_string_append_printf (lines, "c=%s %s %s", conn->nettype,
2003 conn->addrtype, conn->address);
2004 if (gst_sdp_address_is_multicast (conn->nettype, conn->addrtype,
2006 /* only add TTL for IP4 multicast */
2007 if (strcmp (conn->addrtype, "IP4") == 0)
2008 g_string_append_printf (lines, "/%u", conn->ttl);
2009 if (conn->addr_number > 1)
2010 g_string_append_printf (lines, "/%u", conn->addr_number);
2012 g_string_append_printf (lines, "\r\n");
2016 for (i = 0; i < gst_sdp_media_bandwidths_len (media); i++) {
2017 const GstSDPBandwidth *bandwidth = gst_sdp_media_get_bandwidth (media, i);
2019 g_string_append_printf (lines, "b=%s:%u\r\n", bandwidth->bwtype,
2020 bandwidth->bandwidth);
2023 if (media->key.type) {
2024 g_string_append_printf (lines, "k=%s", media->key.type);
2025 if (media->key.data)
2026 g_string_append_printf (lines, ":%s", media->key.data);
2027 g_string_append_printf (lines, "\r\n");
2030 for (i = 0; i < gst_sdp_media_attributes_len (media); i++) {
2031 const GstSDPAttribute *attr = gst_sdp_media_get_attribute (media, i);
2034 g_string_append_printf (lines, "a=%s", attr->key);
2035 if (attr->value && attr->value[0] != '\0')
2036 g_string_append_printf (lines, ":%s", attr->value);
2037 g_string_append_printf (lines, "\r\n");
2041 return g_string_free (lines, FALSE);
2045 * gst_sdp_media_get_media:
2046 * @media: a #GstSDPMedia
2048 * Get the media description of @media.
2050 * Returns: the media description.
2053 gst_sdp_media_get_media (const GstSDPMedia * media)
2055 g_return_val_if_fail (media != NULL, NULL);
2057 return media->media;
2061 * gst_sdp_media_set_media:
2062 * @media: a #GstSDPMedia
2063 * @med: the media description
2065 * Set the media description of @media to @med.
2067 * Returns: #GST_SDP_OK.
2070 gst_sdp_media_set_media (GstSDPMedia * media, const gchar * med)
2072 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2073 g_return_val_if_fail (med != NULL, GST_SDP_EINVAL);
2075 g_free (media->media);
2076 media->media = g_strdup (med);
2082 * gst_sdp_media_get_port:
2083 * @media: a #GstSDPMedia
2085 * Get the port number for @media.
2087 * Returns: the port number of @media.
2090 gst_sdp_media_get_port (const GstSDPMedia * media)
2092 g_return_val_if_fail (media != NULL, 0);
2098 * gst_sdp_media_get_num_ports:
2099 * @media: a #GstSDPMedia
2101 * Get the number of ports for @media.
2103 * Returns: the number of ports for @media.
2106 gst_sdp_media_get_num_ports (const GstSDPMedia * media)
2108 g_return_val_if_fail (media != NULL, 0);
2110 return media->num_ports;
2114 * gst_sdp_media_set_port_info:
2115 * @media: a #GstSDPMedia
2116 * @port: the port number
2117 * @num_ports: the number of ports
2119 * Set the port information in @media.
2121 * Returns: #GST_SDP_OK.
2124 gst_sdp_media_set_port_info (GstSDPMedia * media, guint port, guint num_ports)
2126 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2129 media->num_ports = num_ports;
2135 * gst_sdp_media_get_proto:
2136 * @media: a #GstSDPMedia
2138 * Get the transport protocol of @media
2140 * Returns: the transport protocol of @media.
2143 gst_sdp_media_get_proto (const GstSDPMedia * media)
2145 g_return_val_if_fail (media != NULL, NULL);
2147 return media->proto;
2151 * gst_sdp_media_set_proto:
2152 * @media: a #GstSDPMedia
2153 * @proto: the media transport protocol
2155 * Set the media transport protocol of @media to @proto.
2157 * Returns: #GST_SDP_OK.
2160 gst_sdp_media_set_proto (GstSDPMedia * media, const gchar * proto)
2162 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2164 g_free (media->proto);
2165 media->proto = g_strdup (proto);
2171 * gst_sdp_media_formats_len:
2172 * @media: a #GstSDPMedia
2174 * Get the number of formats in @media.
2176 * Returns: the number of formats in @media.
2179 gst_sdp_media_formats_len (const GstSDPMedia * media)
2181 g_return_val_if_fail (media != NULL, 0);
2183 return media->fmts->len;
2187 * gst_sdp_media_get_format:
2188 * @media: a #GstSDPMedia
2191 * Get the format information at position @idx in @media.
2193 * Returns: the format at position @idx.
2196 gst_sdp_media_get_format (const GstSDPMedia * media, guint idx)
2198 g_return_val_if_fail (media != NULL, NULL);
2200 if (idx >= media->fmts->len)
2202 return g_array_index (media->fmts, gchar *, idx);
2206 * gst_sdp_media_insert_format:
2207 * @media: a #GstSDPMedia
2209 * @format: the format
2211 * Insert the format information to @media at @idx. When @idx is -1,
2212 * the format is appended.
2214 * Returns: #GST_SDP_OK.
2219 gst_sdp_media_insert_format (GstSDPMedia * media, gint idx,
2220 const gchar * format)
2224 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2225 g_return_val_if_fail (format != NULL, GST_SDP_EINVAL);
2227 fmt = g_strdup (format);
2230 g_array_append_val (media->fmts, fmt);
2232 g_array_insert_val (media->fmts, idx, fmt);
2238 * gst_sdp_media_replace_format:
2239 * @media: a #GstSDPMedia
2241 * @format: the format
2243 * Replace the format information in @media at @idx with @format.
2245 * Returns: #GST_SDP_OK.
2250 gst_sdp_media_replace_format (GstSDPMedia * media, guint idx,
2251 const gchar * format)
2255 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2256 g_return_val_if_fail (format != NULL, GST_SDP_EINVAL);
2258 old = &g_array_index (media->fmts, gchar *, idx);
2260 *old = g_strdup (format);
2266 * gst_sdp_media_remove_format:
2267 * @media: a #GstSDPMedia
2270 * Remove the format information in @media at @idx.
2272 * Returns: #GST_SDP_OK.
2277 gst_sdp_media_remove_format (GstSDPMedia * media, guint idx)
2281 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2283 old = &g_array_index (media->fmts, gchar *, idx);
2285 g_array_remove_index (media->fmts, idx);
2291 * gst_sdp_media_add_format:
2292 * @media: a #GstSDPMedia
2293 * @format: the format
2295 * Add the format information to @media.
2297 * Returns: #GST_SDP_OK.
2300 gst_sdp_media_add_format (GstSDPMedia * media, const gchar * format)
2304 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2305 g_return_val_if_fail (format != NULL, GST_SDP_EINVAL);
2307 fmt = g_strdup (format);
2309 g_array_append_val (media->fmts, fmt);
2315 * gst_sdp_media_get_information:
2316 * @media: a #GstSDPMedia
2318 * Get the information of @media
2320 * Returns: the information of @media.
2323 gst_sdp_media_get_information (const GstSDPMedia * media)
2325 g_return_val_if_fail (media != NULL, NULL);
2327 return media->information;
2331 * gst_sdp_media_set_information:
2332 * @media: a #GstSDPMedia
2333 * @information: the media information
2335 * Set the media information of @media to @information.
2337 * Returns: #GST_SDP_OK.
2340 gst_sdp_media_set_information (GstSDPMedia * media, const gchar * information)
2342 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2344 g_free (media->information);
2345 media->information = g_strdup (information);
2351 * gst_sdp_connection_set:
2352 * @conn: a #GstSDPConnection
2353 * @nettype: the type of network. "IN" is defined to have the meaning
2355 * @addrtype: the type of address.
2356 * @address: the address
2357 * @ttl: the time to live of the address
2358 * @addr_number: the number of layers
2360 * Set the connection with the given parameters.
2362 * Returns: @GST_SDP_OK.
2367 gst_sdp_connection_set (GstSDPConnection * conn, const gchar * nettype,
2368 const gchar * addrtype, const gchar * address, guint ttl, guint addr_number)
2370 g_return_val_if_fail (conn != NULL, GST_SDP_EINVAL);
2371 g_return_val_if_fail (nettype != NULL, GST_SDP_EINVAL);
2372 g_return_val_if_fail (addrtype != NULL, GST_SDP_EINVAL);
2373 g_return_val_if_fail (address != NULL, GST_SDP_EINVAL);
2375 conn->nettype = g_strdup (nettype);
2376 conn->addrtype = g_strdup (addrtype);
2377 conn->address = g_strdup (address);
2379 conn->addr_number = addr_number;
2384 * gst_sdp_connection_clear:
2385 * @conn: a #GstSDPConnection
2387 * Clear the connection.
2389 * Returns: @GST_SDP_OK.
2394 gst_sdp_connection_clear (GstSDPConnection * conn)
2396 g_return_val_if_fail (conn != NULL, GST_SDP_EINVAL);
2398 FREE_STRING (conn->nettype);
2399 FREE_STRING (conn->addrtype);
2400 FREE_STRING (conn->address);
2402 conn->addr_number = 0;
2408 * gst_sdp_media_connections_len:
2409 * @media: a #GstSDPMedia
2411 * Get the number of connection fields in @media.
2413 * Returns: the number of connections in @media.
2416 gst_sdp_media_connections_len (const GstSDPMedia * media)
2418 g_return_val_if_fail (media != NULL, 0);
2420 return media->connections->len;
2424 * gst_sdp_media_get_connection:
2425 * @media: a #GstSDPMedia
2428 * Get the connection at position @idx in @media.
2430 * Returns: the #GstSDPConnection at position @idx.
2432 const GstSDPConnection *
2433 gst_sdp_media_get_connection (const GstSDPMedia * media, guint idx)
2435 g_return_val_if_fail (media != NULL, NULL);
2436 g_return_val_if_fail (idx < media->connections->len, NULL);
2438 return &g_array_index (media->connections, GstSDPConnection, idx);
2442 * gst_sdp_media_insert_connection:
2443 * @media: a #GstSDPMedia
2445 * @conn: a #GstSDPConnection
2447 * Insert the connection information to @media at @idx. When @idx is -1,
2448 * the connection is appended.
2450 * Returns: #GST_SDP_OK.
2455 gst_sdp_media_insert_connection (GstSDPMedia * media, gint idx,
2456 GstSDPConnection * conn)
2458 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2459 g_return_val_if_fail (conn != NULL, GST_SDP_EINVAL);
2460 g_return_val_if_fail (idx == -1
2461 || idx < media->connections->len, GST_SDP_EINVAL);
2464 g_array_append_val (media->connections, *conn);
2466 g_array_insert_val (media->connections, idx, *conn);
2472 * gst_sdp_media_replace_connection:
2473 * @media: a #GstSDPMedia
2475 * @conn: a #GstSDPConnection
2477 * Replace the connection information in @media at @idx with @conn.
2479 * Returns: #GST_SDP_OK.
2484 gst_sdp_media_replace_connection (GstSDPMedia * media, guint idx,
2485 GstSDPConnection * conn)
2487 GstSDPConnection *old;
2489 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2490 g_return_val_if_fail (conn != NULL, GST_SDP_EINVAL);
2491 g_return_val_if_fail (idx < media->connections->len, GST_SDP_EINVAL);
2493 old = &g_array_index (media->connections, GstSDPConnection, idx);
2494 gst_sdp_connection_clear (old);
2501 * gst_sdp_media_remove_connection:
2502 * @media: a #GstSDPMedia
2505 * Remove the connection information in @media at @idx.
2507 * Returns: #GST_SDP_OK.
2512 gst_sdp_media_remove_connection (GstSDPMedia * media, guint idx)
2514 GstSDPConnection *old;
2516 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2517 g_return_val_if_fail (idx < media->connections->len, GST_SDP_EINVAL);
2519 old = &g_array_index (media->connections, GstSDPConnection, idx);
2520 gst_sdp_connection_clear (old);
2521 g_array_remove_index (media->connections, idx);
2527 * gst_sdp_media_add_connection:
2528 * @media: a #GstSDPMedia
2529 * @nettype: the type of network. "IN" is defined to have the meaning
2531 * @addrtype: the type of address.
2532 * @address: the address
2533 * @ttl: the time to live of the address
2534 * @addr_number: the number of layers
2536 * Add the given connection parameters to @media.
2538 * Returns: a #GstSDPResult.
2541 gst_sdp_media_add_connection (GstSDPMedia * media, const gchar * nettype,
2542 const gchar * addrtype, const gchar * address, guint ttl, guint addr_number)
2544 GstSDPConnection conn;
2546 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2547 g_return_val_if_fail (nettype != NULL, GST_SDP_EINVAL);
2548 g_return_val_if_fail (addrtype != NULL, GST_SDP_EINVAL);
2549 g_return_val_if_fail (address != NULL, GST_SDP_EINVAL);
2551 gst_sdp_connection_set (&conn, nettype, addrtype, address, ttl, addr_number);
2552 g_array_append_val (media->connections, conn);
2558 * gst_sdp_media_bandwidths_len:
2559 * @media: a #GstSDPMedia
2561 * Get the number of bandwidth fields in @media.
2563 * Returns: the number of bandwidths in @media.
2566 gst_sdp_media_bandwidths_len (const GstSDPMedia * media)
2568 g_return_val_if_fail (media != NULL, 0);
2570 return media->bandwidths->len;
2574 * gst_sdp_media_get_bandwidth:
2575 * @media: a #GstSDPMedia
2578 * Get the bandwidth at position @idx in @media.
2580 * Returns: the #GstSDPBandwidth at position @idx.
2582 const GstSDPBandwidth *
2583 gst_sdp_media_get_bandwidth (const GstSDPMedia * media, guint idx)
2585 g_return_val_if_fail (media != NULL, NULL);
2587 return &g_array_index (media->bandwidths, GstSDPBandwidth, idx);
2591 * gst_sdp_media_insert_bandwidth:
2592 * @media: a #GstSDPMedia
2594 * @bw: a #GstSDPBandwidth
2596 * Insert the bandwidth information to @media at @idx. When @idx is -1,
2597 * the bandwidth is appended.
2599 * Returns: #GST_SDP_OK.
2604 gst_sdp_media_insert_bandwidth (GstSDPMedia * media, gint idx,
2605 GstSDPBandwidth * bw)
2607 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2608 g_return_val_if_fail (bw != NULL, GST_SDP_EINVAL);
2609 g_return_val_if_fail (idx == -1
2610 || idx < media->bandwidths->len, GST_SDP_EINVAL);
2613 g_array_append_val (media->bandwidths, *bw);
2615 g_array_insert_val (media->bandwidths, idx, *bw);
2621 * gst_sdp_media_replace_bandwidth:
2622 * @media: a #GstSDPMedia
2624 * @bw: a #GstSDPBandwidth
2626 * Replace the bandwidth information in @media at @idx with @bw.
2628 * Returns: #GST_SDP_OK.
2633 gst_sdp_media_replace_bandwidth (GstSDPMedia * media, guint idx,
2634 GstSDPBandwidth * bw)
2636 GstSDPBandwidth *old;
2637 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2638 g_return_val_if_fail (bw != NULL, GST_SDP_EINVAL);
2639 g_return_val_if_fail (idx < media->bandwidths->len, GST_SDP_EINVAL);
2641 old = &g_array_index (media->bandwidths, GstSDPBandwidth, idx);
2642 gst_sdp_bandwidth_clear (old);
2649 * gst_sdp_media_remove_bandwidth:
2650 * @media: a #GstSDPMedia
2653 * Remove the bandwidth information in @media at @idx.
2655 * Returns: #GST_SDP_OK.
2660 gst_sdp_media_remove_bandwidth (GstSDPMedia * media, guint idx)
2662 GstSDPBandwidth *old;
2664 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2665 g_return_val_if_fail (idx < media->bandwidths->len, GST_SDP_EINVAL);
2667 old = &g_array_index (media->bandwidths, GstSDPBandwidth, idx);
2668 gst_sdp_bandwidth_clear (old);
2669 g_array_remove_index (media->bandwidths, idx);
2675 * gst_sdp_media_add_bandwidth:
2676 * @media: a #GstSDPMedia
2677 * @bwtype: the bandwidth modifier type
2678 * @bandwidth: the bandwidth in kilobits per second
2680 * Add the bandwidth information with @bwtype and @bandwidth to @media.
2682 * Returns: #GST_SDP_OK.
2685 gst_sdp_media_add_bandwidth (GstSDPMedia * media, const gchar * bwtype,
2690 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2691 g_return_val_if_fail (bwtype != NULL, GST_SDP_EINVAL);
2693 gst_sdp_bandwidth_set (&bw, bwtype, bandwidth);
2694 g_array_append_val (media->bandwidths, bw);
2700 * gst_sdp_media_set_key:
2701 * @media: a #GstSDPMedia
2702 * @type: the encryption type
2703 * @data: the encryption data
2705 * Adds the encryption information to @media.
2707 * Returns: a #GstSDPResult.
2710 gst_sdp_media_set_key (GstSDPMedia * media, const gchar * type,
2713 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2715 g_free (media->key.type);
2716 media->key.type = g_strdup (type);
2717 g_free (media->key.data);
2718 media->key.data = g_strdup (data);
2724 * gst_sdp_media_get_key:
2725 * @media: a #GstSDPMedia
2727 * Get the encryption information from @media.
2729 * Returns: a #GstSDPKey.
2732 gst_sdp_media_get_key (const GstSDPMedia * media)
2734 g_return_val_if_fail (media != NULL, NULL);
2740 * gst_sdp_media_attributes_len:
2741 * @media: a #GstSDPMedia
2743 * Get the number of attribute fields in @media.
2745 * Returns: the number of attributes in @media.
2748 gst_sdp_media_attributes_len (const GstSDPMedia * media)
2750 g_return_val_if_fail (media != NULL, 0);
2752 return media->attributes->len;
2756 * gst_sdp_media_add_attribute:
2757 * @media: a #GstSDPMedia
2759 * @value: (nullable): a value
2761 * Add the attribute with @key and @value to @media.
2763 * Returns: #GST_SDP_OK.
2766 gst_sdp_media_add_attribute (GstSDPMedia * media, const gchar * key,
2767 const gchar * value)
2769 GstSDPAttribute attr;
2771 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2772 g_return_val_if_fail (key != NULL, GST_SDP_EINVAL);
2774 gst_sdp_attribute_set (&attr, key, value);
2775 g_array_append_val (media->attributes, attr);
2781 * gst_sdp_media_get_attribute:
2782 * @media: a #GstSDPMedia
2785 * Get the attribute at position @idx in @media.
2787 * Returns: the #GstSDPAttribute at position @idx.
2789 const GstSDPAttribute *
2790 gst_sdp_media_get_attribute (const GstSDPMedia * media, guint idx)
2792 g_return_val_if_fail (media != NULL, NULL);
2793 g_return_val_if_fail (idx < media->attributes->len, NULL);
2795 return &g_array_index (media->attributes, GstSDPAttribute, idx);
2799 * gst_sdp_media_get_attribute_val_n:
2800 * @media: a #GstSDPMedia
2804 * Get the @nth attribute value for @key in @media.
2806 * Returns: the @nth attribute value.
2809 gst_sdp_media_get_attribute_val_n (const GstSDPMedia * media, const gchar * key,
2814 g_return_val_if_fail (media != NULL, NULL);
2815 g_return_val_if_fail (key != NULL, NULL);
2817 for (i = 0; i < media->attributes->len; i++) {
2818 GstSDPAttribute *attr;
2820 attr = &g_array_index (media->attributes, GstSDPAttribute, i);
2821 if (!strcmp (attr->key, key)) {
2832 * gst_sdp_media_get_attribute_val:
2833 * @media: a #GstSDPMedia
2836 * Get the first attribute value for @key in @media.
2838 * Returns: the first attribute value for @key.
2841 gst_sdp_media_get_attribute_val (const GstSDPMedia * media, const gchar * key)
2843 g_return_val_if_fail (media != NULL, NULL);
2844 g_return_val_if_fail (key != NULL, NULL);
2846 return gst_sdp_media_get_attribute_val_n (media, key, 0);
2850 * gst_sdp_media_insert_attribute:
2851 * @media: a #GstSDPMedia
2853 * @attr: a #GstSDPAttribute
2855 * Insert the attribute to @media at @idx. When @idx is -1,
2856 * the attribute is appended.
2858 * Returns: #GST_SDP_OK.
2863 gst_sdp_media_insert_attribute (GstSDPMedia * media, gint idx,
2864 GstSDPAttribute * attr)
2866 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2867 g_return_val_if_fail (attr != NULL, GST_SDP_EINVAL);
2868 g_return_val_if_fail (idx == -1
2869 || idx < media->attributes->len, GST_SDP_EINVAL);
2872 g_array_append_val (media->attributes, *attr);
2874 g_array_insert_val (media->attributes, idx, *attr);
2880 * gst_sdp_media_replace_attribute:
2881 * @media: a #GstSDPMedia
2883 * @attr: a #GstSDPAttribute
2885 * Replace the attribute in @media at @idx with @attr.
2887 * Returns: #GST_SDP_OK.
2892 gst_sdp_media_replace_attribute (GstSDPMedia * media, guint idx,
2893 GstSDPAttribute * attr)
2895 GstSDPAttribute *old;
2897 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2898 g_return_val_if_fail (attr != NULL, GST_SDP_EINVAL);
2899 g_return_val_if_fail (idx < media->attributes->len, GST_SDP_EINVAL);
2901 old = &g_array_index (media->attributes, GstSDPAttribute, idx);
2902 gst_sdp_attribute_clear (old);
2909 * gst_sdp_media_remove_attribute:
2910 * @media: a #GstSDPMedia
2913 * Remove the attribute in @media at @idx.
2915 * Returns: #GST_SDP_OK.
2920 gst_sdp_media_remove_attribute (GstSDPMedia * media, guint idx)
2922 GstSDPAttribute *old;
2923 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
2924 g_return_val_if_fail (idx < media->attributes->len, GST_SDP_EINVAL);
2926 old = &g_array_index (media->attributes, GstSDPAttribute, idx);
2927 gst_sdp_attribute_clear (old);
2928 g_array_remove_index (media->attributes, idx);
2934 read_string (gchar * dest, guint size, gchar ** src)
2940 while (g_ascii_isspace (**src))
2943 while (!g_ascii_isspace (**src) && **src != '\0') {
2945 dest[idx++] = **src;
2953 read_string_del (gchar * dest, guint size, gchar del, gchar ** src)
2959 while (g_ascii_isspace (**src))
2962 while (**src != del && **src != '\0') {
2964 dest[idx++] = **src;
2985 gst_sdp_parse_line (SDPContext * c, gchar type, gchar * buffer)
2990 #define READ_STRING(field) \
2991 do { read_string (str, sizeof (str), &p); REPLACE_STRING (field, str); } while (0)
2992 #define READ_UINT(field) \
2993 do { read_string (str, sizeof (str), &p); field = strtoul (str, NULL, 10); } while (0)
2997 if (buffer[0] != '0')
2998 GST_WARNING ("wrong SDP version");
2999 gst_sdp_message_set_version (c->msg, buffer);
3002 READ_STRING (c->msg->origin.username);
3003 READ_STRING (c->msg->origin.sess_id);
3004 READ_STRING (c->msg->origin.sess_version);
3005 READ_STRING (c->msg->origin.nettype);
3006 READ_STRING (c->msg->origin.addrtype);
3007 READ_STRING (c->msg->origin.addr);
3010 REPLACE_STRING (c->msg->session_name, buffer);
3013 if (c->state == SDP_SESSION) {
3014 REPLACE_STRING (c->msg->information, buffer);
3016 REPLACE_STRING (c->media->information, buffer);
3020 REPLACE_STRING (c->msg->uri, buffer);
3023 gst_sdp_message_add_email (c->msg, buffer);
3026 gst_sdp_message_add_phone (c->msg, buffer);
3030 GstSDPConnection conn;
3033 memset (&conn, 0, sizeof (conn));
3036 while ((str2 = strchr (str2, '/')))
3038 READ_STRING (conn.nettype);
3039 READ_STRING (conn.addrtype);
3040 READ_STRING (conn.address);
3041 /* only read TTL for IP4 */
3042 if (strcmp (conn.addrtype, "IP4") == 0)
3043 READ_UINT (conn.ttl);
3044 READ_UINT (conn.addr_number);
3046 if (c->state == SDP_SESSION) {
3047 gst_sdp_message_set_connection (c->msg, conn.nettype, conn.addrtype,
3048 conn.address, conn.ttl, conn.addr_number);
3050 gst_sdp_media_add_connection (c->media, conn.nettype, conn.addrtype,
3051 conn.address, conn.ttl, conn.addr_number);
3053 gst_sdp_connection_clear (&conn);
3060 read_string_del (str, sizeof (str), ':', &p);
3063 read_string (str2, sizeof (str2), &p);
3064 if (c->state == SDP_SESSION)
3065 gst_sdp_message_add_bandwidth (c->msg, str, atoi (str2));
3067 gst_sdp_media_add_bandwidth (c->media, str, atoi (str2));
3073 read_string_del (str, sizeof (str), ':', &p);
3076 if (c->state == SDP_SESSION)
3077 gst_sdp_message_set_key (c->msg, str, p);
3079 gst_sdp_media_set_key (c->media, str, p);
3082 read_string_del (str, sizeof (str), ':', &p);
3085 if (c->state == SDP_SESSION)
3086 gst_sdp_message_add_attribute (c->msg, str, p);
3088 gst_sdp_media_add_attribute (c->media, str, p);
3095 c->state = SDP_MEDIA;
3096 memset (&nmedia, 0, sizeof (nmedia));
3097 gst_sdp_media_init (&nmedia);
3099 /* m=<media> <port>/<number of ports> <proto> <fmt> ... */
3100 READ_STRING (nmedia.media);
3101 read_string (str, sizeof (str), &p);
3102 slash = g_strrstr (str, "/");
3105 nmedia.port = atoi (str);
3106 nmedia.num_ports = atoi (slash + 1);
3108 nmedia.port = atoi (str);
3109 nmedia.num_ports = 0;
3111 READ_STRING (nmedia.proto);
3113 read_string (str, sizeof (str), &p);
3114 gst_sdp_media_add_format (&nmedia, str);
3115 } while (*p != '\0');
3117 gst_sdp_message_add_media (c->msg, &nmedia);
3119 &g_array_index (c->msg->medias, GstSDPMedia, c->msg->medias->len - 1);
3129 * gst_sdp_message_parse_buffer:
3130 * @data: (array length=size): the start of the buffer
3131 * @size: the size of the buffer
3132 * @msg: the result #GstSDPMessage
3134 * Parse the contents of @size bytes pointed to by @data and store the result in
3137 * Returns: #GST_SDP_OK on success.
3140 gst_sdp_message_parse_buffer (const guint8 * data, guint size,
3141 GstSDPMessage * msg)
3146 gchar *buffer = NULL;
3150 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
3151 g_return_val_if_fail (data != NULL, GST_SDP_EINVAL);
3152 g_return_val_if_fail (size != 0, GST_SDP_EINVAL);
3154 c.state = SDP_SESSION;
3158 #define SIZE_CHECK_GUARD \
3160 if (p - (gchar *) data >= size) \
3166 while (p - (gchar *) data < size && g_ascii_isspace (*p))
3184 while (p - (gchar *) data < size && *p != '\n' && *p != '\r' && *p != '\0')
3188 if (bufsize <= len) {
3189 buffer = g_realloc (buffer, len + 1);
3192 memcpy (buffer, s, len);
3195 gst_sdp_parse_line (&c, type, buffer);
3200 while (p - (gchar *) data < size && *p != '\n' && *p != '\0')
3209 #undef SIZE_CHECK_GUARD
3218 print_media (GstSDPMedia * media)
3220 g_print (" media: '%s'\n", GST_STR_NULL (media->media));
3221 g_print (" port: '%u'\n", media->port);
3222 g_print (" num_ports: '%u'\n", media->num_ports);
3223 g_print (" proto: '%s'\n", GST_STR_NULL (media->proto));
3224 if (media->fmts->len > 0) {
3227 g_print (" formats:\n");
3228 for (i = 0; i < media->fmts->len; i++) {
3229 g_print (" format '%s'\n", g_array_index (media->fmts, gchar *, i));
3232 g_print (" information: '%s'\n", GST_STR_NULL (media->information));
3233 if (media->connections->len > 0) {
3236 g_print (" connections:\n");
3237 for (i = 0; i < media->connections->len; i++) {
3238 GstSDPConnection *conn =
3239 &g_array_index (media->connections, GstSDPConnection, i);
3241 g_print (" nettype: '%s'\n", GST_STR_NULL (conn->nettype));
3242 g_print (" addrtype: '%s'\n", GST_STR_NULL (conn->addrtype));
3243 g_print (" address: '%s'\n", GST_STR_NULL (conn->address));
3244 g_print (" ttl: '%u'\n", conn->ttl);
3245 g_print (" addr_number: '%u'\n", conn->addr_number);
3248 if (media->bandwidths->len > 0) {
3251 g_print (" bandwidths:\n");
3252 for (i = 0; i < media->bandwidths->len; i++) {
3253 GstSDPBandwidth *bw =
3254 &g_array_index (media->bandwidths, GstSDPBandwidth, i);
3256 g_print (" type: '%s'\n", GST_STR_NULL (bw->bwtype));
3257 g_print (" bandwidth: '%u'\n", bw->bandwidth);
3260 g_print (" key:\n");
3261 g_print (" type: '%s'\n", GST_STR_NULL (media->key.type));
3262 g_print (" data: '%s'\n", GST_STR_NULL (media->key.data));
3263 if (media->attributes->len > 0) {
3266 g_print (" attributes:\n");
3267 for (i = 0; i < media->attributes->len; i++) {
3268 GstSDPAttribute *attr =
3269 &g_array_index (media->attributes, GstSDPAttribute, i);
3271 g_print (" attribute '%s' : '%s'\n", attr->key, attr->value);
3277 * gst_sdp_message_dump:
3278 * @msg: a #GstSDPMessage
3280 * Dump the parsed contents of @msg to stdout.
3282 * Returns: a #GstSDPResult.
3285 gst_sdp_message_dump (const GstSDPMessage * msg)
3287 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
3289 g_print ("sdp packet %p:\n", msg);
3290 g_print (" version: '%s'\n", GST_STR_NULL (msg->version));
3291 g_print (" origin:\n");
3292 g_print (" username: '%s'\n", GST_STR_NULL (msg->origin.username));
3293 g_print (" sess_id: '%s'\n", GST_STR_NULL (msg->origin.sess_id));
3294 g_print (" sess_version: '%s'\n", GST_STR_NULL (msg->origin.sess_version));
3295 g_print (" nettype: '%s'\n", GST_STR_NULL (msg->origin.nettype));
3296 g_print (" addrtype: '%s'\n", GST_STR_NULL (msg->origin.addrtype));
3297 g_print (" addr: '%s'\n", GST_STR_NULL (msg->origin.addr));
3298 g_print (" session_name: '%s'\n", GST_STR_NULL (msg->session_name));
3299 g_print (" information: '%s'\n", GST_STR_NULL (msg->information));
3300 g_print (" uri: '%s'\n", GST_STR_NULL (msg->uri));
3302 if (msg->emails->len > 0) {
3305 g_print (" emails:\n");
3306 for (i = 0; i < msg->emails->len; i++) {
3307 g_print (" email '%s'\n", g_array_index (msg->emails, gchar *, i));
3310 if (msg->phones->len > 0) {
3313 g_print (" phones:\n");
3314 for (i = 0; i < msg->phones->len; i++) {
3315 g_print (" phone '%s'\n", g_array_index (msg->phones, gchar *, i));
3318 g_print (" connection:\n");
3319 g_print (" nettype: '%s'\n", GST_STR_NULL (msg->connection.nettype));
3320 g_print (" addrtype: '%s'\n", GST_STR_NULL (msg->connection.addrtype));
3321 g_print (" address: '%s'\n", GST_STR_NULL (msg->connection.address));
3322 g_print (" ttl: '%u'\n", msg->connection.ttl);
3323 g_print (" addr_number: '%u'\n", msg->connection.addr_number);
3324 if (msg->bandwidths->len > 0) {
3327 g_print (" bandwidths:\n");
3328 for (i = 0; i < msg->bandwidths->len; i++) {
3329 GstSDPBandwidth *bw =
3330 &g_array_index (msg->bandwidths, GstSDPBandwidth, i);
3332 g_print (" type: '%s'\n", GST_STR_NULL (bw->bwtype));
3333 g_print (" bandwidth: '%u'\n", bw->bandwidth);
3336 g_print (" key:\n");
3337 g_print (" type: '%s'\n", GST_STR_NULL (msg->key.type));
3338 g_print (" data: '%s'\n", GST_STR_NULL (msg->key.data));
3339 if (msg->attributes->len > 0) {
3342 g_print (" attributes:\n");
3343 for (i = 0; i < msg->attributes->len; i++) {
3344 GstSDPAttribute *attr =
3345 &g_array_index (msg->attributes, GstSDPAttribute, i);
3347 g_print (" attribute '%s' : '%s'\n", attr->key, attr->value);
3350 if (msg->medias->len > 0) {
3353 g_print (" medias:\n");
3354 for (i = 0; i < msg->medias->len; i++) {
3355 g_print (" media %u:\n", i);
3356 print_media (&g_array_index (msg->medias, GstSDPMedia, i));
3362 static const gchar *
3363 gst_sdp_get_attribute_for_pt (const GstSDPMedia * media, const gchar * name,
3372 if ((attr = gst_sdp_media_get_attribute_val_n (media, name, i)) == NULL)
3375 if (sscanf (attr, "%d ", &val) != 1)
3384 /* this may modify the input string (and resets) */
3385 #define PARSE_INT(p, del, res) \
3388 p = strstr (p, del); \
3400 /* this may modify the string without reset */
3401 #define PARSE_STRING(p, del, res) \
3404 p = strstr (p, del); \
3416 #define SKIP_SPACES(p) \
3417 while (*p && g_ascii_isspace (*p)) \
3422 * <payload> <encoding_name>/<clock_rate>[/<encoding_params>]
3425 gst_sdp_parse_rtpmap (const gchar * rtpmap, gint * payload, gchar ** name,
3426 gint * rate, gchar ** params)
3428 gchar *p, *t, *orig_value;
3430 p = orig_value = g_strdup (rtpmap);
3432 PARSE_INT (p, " ", *payload);
3440 PARSE_STRING (p, "/", *name);
3441 if (*name == NULL) {
3442 GST_DEBUG ("no rate, name %s", p);
3443 /* no rate, assume -1 then, this is not supposed to happen but RealMedia
3444 * streams seem to omit the rate. */
3445 *name = g_strdup (p);
3450 *name = strdup (*name);
3454 p = strstr (p, "/");
3466 *params = g_strdup (p);
3469 g_free (orig_value);
3473 g_free (orig_value);
3478 * gst_sdp_media_add_rtcp_fb_attributes_from_media:
3479 * @media: a #GstSDPMedia
3483 * Parse given @media for "rtcp-fb" attributes and add it to the @caps.
3485 * Mapping of caps from SDP fields:
3487 * a=rtcp-fb:(payload) (param1) [param2]...
3489 * Returns: a #GstSDPResult.
3492 gst_sdp_media_add_rtcp_fb_attributes_from_media (const GstSDPMedia * media,
3493 gint pt, GstCaps * caps)
3495 const gchar *rtcp_fb;
3500 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
3501 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
3503 s = gst_caps_get_structure (caps, 0);
3506 gboolean all_formats = FALSE;
3508 if ((rtcp_fb = gst_sdp_media_get_attribute_val_n (media,
3509 "rtcp-fb", i)) == NULL)
3512 /* p is now of the format <payload> attr... */
3513 to_free = p = g_strdup (rtcp_fb);
3515 /* check if it applies to all formats */
3520 PARSE_INT (p, " ", payload);
3523 if (all_formats || (payload != -1 && payload == pt)) {
3528 /* replace space with '-' */
3529 key = g_strdup_printf ("rtcp-fb-%s", p);
3531 for (tmp = key; (tmp = strchr (tmp, ' ')); ++tmp) {
3535 gst_structure_set (s, key, G_TYPE_BOOLEAN, TRUE, NULL);
3536 GST_DEBUG ("adding caps: %s=TRUE", key);
3545 gst_sdp_media_caps_adjust_h264 (GstCaps * caps)
3549 const gchar *profile_level_id;
3550 GstStructure *s = gst_caps_get_structure (caps, 0);
3552 if (g_strcmp0 (gst_structure_get_string (s, "encoding-name"), "H264") ||
3553 g_strcmp0 (gst_structure_get_string (s, "level-asymmetry-allowed"), "1"))
3556 profile_level_id = gst_structure_get_string (s, "profile-level-id");
3557 if (!profile_level_id)
3560 spsint = strtol (profile_level_id, NULL, 16);
3561 sps[0] = spsint >> 16;
3562 sps[1] = spsint >> 8;
3564 GST_DEBUG ("'level-asymmetry-allowed' is set so we shouldn't care about "
3565 "'profile-level-id' and only set a 'profile' instead");
3566 gst_structure_set (s, "profile", G_TYPE_STRING,
3567 gst_codec_utils_h264_get_profile (sps, 2), NULL);
3569 gst_structure_remove_fields (s, "level-asymmetry-allowed", "profile-level-id",
3574 * gst_sdp_media_get_caps_from_media:
3575 * @media: a #GstSDPMedia
3576 * @pt: a payload type
3578 * Mapping of caps from SDP fields:
3580 * a=rtpmap:(payload) (encoding_name)/(clock_rate)[/(encoding_params)]
3582 * a=framesize:(payload) (width)-(height)
3584 * a=fmtp:(payload) (param)[=(value)];...
3586 * Note that the extmap, ssrc and rid attributes are set only by gst_sdp_media_attributes_to_caps().
3588 * Returns: a #GstCaps, or %NULL if an error happened
3593 gst_sdp_media_get_caps_from_media (const GstSDPMedia * media, gint pt)
3596 const gchar *rtpmap;
3598 gchar *framesize = NULL;
3601 gchar *params = NULL;
3607 g_return_val_if_fail (media != NULL, NULL);
3609 /* get and parse rtpmap */
3610 rtpmap = gst_sdp_get_attribute_for_pt (media, "rtpmap", pt);
3613 ret = gst_sdp_parse_rtpmap (rtpmap, &payload, &name, &rate, ¶ms);
3615 GST_ERROR ("error parsing rtpmap, ignoring");
3619 /* dynamic payloads need rtpmap or we fail */
3620 if (rtpmap == NULL && pt >= 96)
3623 /* check if we have a rate, if not, we need to look up the rate from the
3624 * default rates based on the payload types. */
3626 const GstRTPPayloadInfo *info;
3628 if (GST_RTP_PAYLOAD_IS_DYNAMIC (pt)) {
3629 /* dynamic types, use media and encoding_name */
3630 tmp = g_ascii_strdown (media->media, -1);
3631 info = gst_rtp_payload_info_for_name (tmp, name);
3634 /* static types, use payload type */
3635 info = gst_rtp_payload_info_for_pt (pt);
3639 if ((rate = info->clock_rate) == 0)
3642 /* we fail if we cannot find one */
3647 tmp = g_ascii_strdown (media->media, -1);
3648 caps = gst_caps_new_simple ("application/x-unknown",
3649 "media", G_TYPE_STRING, tmp, "payload", G_TYPE_INT, pt, NULL);
3651 s = gst_caps_get_structure (caps, 0);
3653 gst_structure_set (s, "clock-rate", G_TYPE_INT, rate, NULL);
3655 /* encoding name must be upper case */
3657 tmp = g_ascii_strup (name, -1);
3658 gst_structure_set (s, "encoding-name", G_TYPE_STRING, tmp, NULL);
3662 /* params must be lower case */
3663 if (params != NULL) {
3664 tmp = g_ascii_strdown (params, -1);
3665 gst_structure_set (s, "encoding-params", G_TYPE_STRING, tmp, NULL);
3669 /* parse optional fmtp: field */
3670 if ((fmtp = g_strdup (gst_sdp_get_attribute_for_pt (media, "fmtp", pt)))) {
3676 /* p is now of the format <payload> <param>[=<value>];... */
3677 PARSE_INT (p, " ", payload);
3678 if (payload != -1 && payload == pt) {
3682 /* <param>[=<value>] are separated with ';' */
3683 pairs = g_strsplit (p, ";", 0);
3684 for (i = 0; pairs[i]; i++) {
3686 const gchar *val, *key;
3688 const gchar *reserved_keys[] =
3689 { "media", "payload", "clock-rate", "encoding-name",
3693 /* the key may not have a '=', the value can have other '='s */
3694 valpos = strstr (pairs[i], "=");
3696 /* we have a '=' and thus a value, remove the '=' with \0 */
3698 /* value is everything between '=' and ';'. We split the pairs at ;
3699 * boundaries so we can take the remainder of the value. Some servers
3700 * put spaces around the value which we strip off here. Alternatively
3701 * we could strip those spaces in the depayloaders should these spaces
3702 * actually carry any meaning in the future. */
3703 val = g_strstrip (valpos + 1);
3705 /* simple <param>;.. is translated into <param>=1;... */
3708 /* strip the key of spaces, convert key to lowercase but not the value. */
3709 key = g_strstrip (pairs[i]);
3711 /* skip keys from the fmtp, which we already use ourselves for the
3712 * caps. Some software is adding random things like clock-rate into
3713 * the fmtp, and we would otherwise here set a string-typed clock-rate
3714 * in the caps... and thus fail to create valid RTP caps
3716 for (j = 0; j < G_N_ELEMENTS (reserved_keys); j++) {
3717 if (g_ascii_strcasecmp (reserved_keys[j], key) == 0) {
3723 if (strlen (key) > 0) {
3724 tmp = g_ascii_strdown (key, -1);
3725 gst_structure_set (s, tmp, G_TYPE_STRING, val, NULL);
3733 /* parse framesize: field */
3735 g_strdup (gst_sdp_media_get_attribute_val (media, "framesize")))) {
3738 /* p is now of the format <payload> <width>-<height> */
3741 PARSE_INT (p, " ", payload);
3742 if (payload != -1 && payload == pt) {
3743 gst_structure_set (s, "a-framesize", G_TYPE_STRING, p, NULL);
3747 gst_sdp_media_caps_adjust_h264 (caps);
3749 /* parse rtcp-fb: field */
3750 gst_sdp_media_add_rtcp_fb_attributes_from_media (media, pt, caps);
3762 GST_ERROR ("rtpmap type not given for dynamic payload %d", pt);
3768 GST_ERROR ("rate unknown for payload type %d", pt);
3775 * gst_sdp_media_set_media_from_caps:
3777 * @media: a #GstSDPMedia
3779 * Mapping of caps to SDP fields:
3781 * a=rtpmap:(payload) (encoding_name) or (clock_rate)[or (encoding_params)]
3783 * a=framesize:(payload) (width)-(height)
3785 * a=fmtp:(payload) (param)[=(value)];...
3787 * a=rtcp-fb:(payload) (param1) [param2]...
3789 * a=extmap:(id)[/direction] (extensionname) (extensionattributes)
3791 * Returns: a #GstSDPResult.
3796 gst_sdp_media_set_media_from_caps (const GstCaps * caps, GstSDPMedia * media)
3798 const gchar *caps_str, *caps_enc, *caps_params;
3800 gint caps_pt, caps_rate;
3802 gboolean first, nack, nack_pli, ccm_fir, transport_cc;
3806 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
3807 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
3809 s = gst_caps_get_structure (caps, 0);
3811 GST_ERROR ("ignoring stream without media type");
3815 /* get media type and payload for the m= line */
3816 caps_str = gst_structure_get_string (s, "media");
3818 GST_ERROR ("ignoring stream without media type");
3821 gst_sdp_media_set_media (media, caps_str);
3823 if (!gst_structure_get_int (s, "payload", &caps_pt)) {
3824 GST_ERROR ("ignoring stream without payload type");
3827 tmp = g_strdup_printf ("%d", caps_pt);
3828 gst_sdp_media_add_format (media, tmp);
3831 /* get clock-rate, media type and params for the rtpmap attribute */
3832 if (!gst_structure_get_int (s, "clock-rate", &caps_rate)) {
3833 GST_ERROR ("ignoring stream without payload type");
3836 caps_enc = gst_structure_get_string (s, "encoding-name");
3837 caps_params = gst_structure_get_string (s, "encoding-params");
3841 tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
3844 tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);
3846 gst_sdp_media_add_attribute (media, "rtpmap", tmp);
3850 /* get rtcp-fb attributes */
3851 if (gst_structure_get_boolean (s, "rtcp-fb-nack", &nack)) {
3853 tmp = g_strdup_printf ("%d nack", caps_pt);
3854 gst_sdp_media_add_attribute (media, "rtcp-fb", tmp);
3856 GST_DEBUG ("adding rtcp-fb-nack to pt=%d", caps_pt);
3860 if (gst_structure_get_boolean (s, "rtcp-fb-nack-pli", &nack_pli)) {
3862 tmp = g_strdup_printf ("%d nack pli", caps_pt);
3863 gst_sdp_media_add_attribute (media, "rtcp-fb", tmp);
3865 GST_DEBUG ("adding rtcp-fb-nack-pli to pt=%d", caps_pt);
3869 if (gst_structure_get_boolean (s, "rtcp-fb-ccm-fir", &ccm_fir)) {
3871 tmp = g_strdup_printf ("%d ccm fir", caps_pt);
3872 gst_sdp_media_add_attribute (media, "rtcp-fb", tmp);
3874 GST_DEBUG ("adding rtcp-fb-ccm-fir to pt=%d", caps_pt);
3878 if (gst_structure_get_boolean (s, "rtcp-fb-transport-cc", &transport_cc)) {
3880 tmp = g_strdup_printf ("%d transport-cc", caps_pt);
3881 gst_sdp_media_add_attribute (media, "rtcp-fb", tmp);
3883 GST_DEBUG ("adding rtcp-fb-transport-cc to pt=%d", caps_pt);
3887 /* collect all other properties and add them to fmtp, extmap or attributes */
3888 fmtp = g_string_new ("");
3889 g_string_append_printf (fmtp, "%d ", caps_pt);
3891 n_fields = gst_structure_n_fields (s);
3892 for (j = 0; j < n_fields; j++) {
3893 const gchar *fname, *fval;
3895 fname = gst_structure_nth_field_name (s, j);
3897 /* filter out standard properties */
3898 if (!strcmp (fname, "media"))
3900 if (!strcmp (fname, "payload"))
3902 if (!strcmp (fname, "clock-rate"))
3904 if (!strcmp (fname, "encoding-name"))
3906 if (!strcmp (fname, "encoding-params"))
3908 if (!strcmp (fname, "ssrc"))
3910 if (!strcmp (fname, "timestamp-offset"))
3912 if (!strcmp (fname, "seqnum-offset"))
3914 if (g_str_has_prefix (fname, "srtp-"))
3916 if (g_str_has_prefix (fname, "srtcp-"))
3919 if (g_str_has_prefix (fname, "x-gst-rtsp-server-rtx-time"))
3921 if (g_str_has_prefix (fname, "rtcp-fb-"))
3924 if (!strcmp (fname, "a-framesize")) {
3925 /* a-framesize attribute */
3926 if ((fval = gst_structure_get_string (s, fname))) {
3927 tmp = g_strdup_printf ("%d %s", caps_pt, fval);
3928 gst_sdp_media_add_attribute (media, fname + 2, tmp);
3934 if (g_str_has_prefix (fname, "a-")) {
3936 if ((fval = gst_structure_get_string (s, fname)))
3937 gst_sdp_media_add_attribute (media, fname + 2, fval);
3940 if (g_str_has_prefix (fname, "x-")) {
3942 if ((fval = gst_structure_get_string (s, fname)))
3943 gst_sdp_media_add_attribute (media, fname, fval);
3948 if (g_str_has_prefix (fname, "extmap-")) {
3950 guint id = strtoull (fname + 7, &endptr, 10);
3953 if (*endptr != '\0' || id == 0 || id == 15 || id > 9999)
3956 if ((fval = gst_structure_get_string (s, fname))) {
3957 gchar *extmap = g_strdup_printf ("%u %s", id, fval);
3958 gst_sdp_media_add_attribute (media, "extmap", extmap);
3960 } else if ((arr = gst_structure_get_value (s, fname))
3961 && G_VALUE_HOLDS (arr, GST_TYPE_ARRAY)
3962 && gst_value_array_get_size (arr) == 3) {
3964 const gchar *direction, *extensionname, *extensionattributes;
3966 val = gst_value_array_get_value (arr, 0);
3967 direction = g_value_get_string (val);
3969 val = gst_value_array_get_value (arr, 1);
3970 extensionname = g_value_get_string (val);
3972 val = gst_value_array_get_value (arr, 2);
3973 extensionattributes = g_value_get_string (val);
3975 if (!extensionname || *extensionname == '\0')
3978 if (direction && *direction != '\0' && extensionattributes
3979 && *extensionattributes != '\0') {
3981 g_strdup_printf ("%u/%s %s %s", id, direction, extensionname,
3982 extensionattributes);
3983 gst_sdp_media_add_attribute (media, "extmap", extmap);
3985 } else if (direction && *direction != '\0') {
3987 g_strdup_printf ("%u/%s %s", id, direction, extensionname);
3988 gst_sdp_media_add_attribute (media, "extmap", extmap);
3990 } else if (extensionattributes && *extensionattributes != '\0') {
3991 gchar *extmap = g_strdup_printf ("%u %s %s", id, extensionname,
3992 extensionattributes);
3993 gst_sdp_media_add_attribute (media, "extmap", extmap);
3996 gchar *extmap = g_strdup_printf ("%u %s", id, extensionname);
3997 gst_sdp_media_add_attribute (media, "extmap", extmap);
4005 if (g_str_has_prefix (fname, "rid-")) {
4006 const char *rid_id = &fname[strlen ("rid-")];
4009 if (!rid_id || !*rid_id)
4012 if ((fval = gst_structure_get_string (s, fname))) {
4013 char *rid_val = g_strdup_printf ("%s %s", rid_id, fval);
4014 gst_sdp_media_add_attribute (media, "rid", rid_val);
4016 } else if ((arr = gst_structure_get_value (s, fname))
4017 && GST_VALUE_HOLDS_ARRAY (arr)
4018 && gst_value_array_get_size (arr) > 1) {
4019 const gchar *direction, *param;
4023 str = g_string_new (NULL);
4025 g_string_append_printf (str, "%s ", rid_id);
4027 n = gst_value_array_get_size (arr);
4028 for (i = 0; i < n; i++) {
4029 const GValue *val = gst_value_array_get_value (arr, i);
4031 direction = g_value_get_string (val);
4032 g_string_append_printf (str, "%s", direction);
4034 param = g_value_get_string (val);
4036 g_string_append_c (str, ' ');
4038 g_string_append_c (str, ';');
4039 g_string_append_printf (str, "%s", param);
4042 gst_sdp_media_add_attribute (media, "rid", str->str);
4043 g_string_free (str, TRUE);
4045 GST_WARNING ("caps field %s is an unsupported format", fname);
4050 if ((fval = gst_structure_get_string (s, fname))) {
4052 /* "profile" is our internal representation of the notion of
4053 * "level-asymmetry-allowed" with caps, convert it back to the SDP
4055 if (!g_strcmp0 (gst_structure_get_string (s, "encoding-name"), "H264")
4056 && !g_strcmp0 (fname, "profile")) {
4057 fname = "level-asymmetry-allowed";
4061 g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
4067 tmp = g_string_free (fmtp, FALSE);
4068 gst_sdp_media_add_attribute (media, "fmtp", tmp);
4071 g_string_free (fmtp, TRUE);
4079 GST_DEBUG ("ignoring stream");
4080 return GST_SDP_EINVAL;
4085 * gst_sdp_make_keymgmt:
4086 * @uri: a #gchar URI
4087 * @base64: a #gchar base64-encoded key data
4089 * Makes key management data
4091 * Returns: (transfer full): a #gchar key-mgmt data,
4096 gst_sdp_make_keymgmt (const gchar * uri, const gchar * base64)
4098 g_return_val_if_fail (uri != NULL, NULL);
4099 g_return_val_if_fail (base64 != NULL, NULL);
4101 return g_strdup_printf ("prot=mikey;uri=\"%s\";data=\"%s\"", uri, base64);
4105 gst_sdp_parse_keymgmt (const gchar * keymgmt, GstMIKEYMessage ** mikey)
4112 p = orig_value = g_strdup (keymgmt);
4116 g_free (orig_value);
4120 PARSE_STRING (p, " ", kmpid);
4121 if (kmpid == NULL || !g_str_equal (kmpid, "mikey")) {
4122 g_free (orig_value);
4125 data = g_base64_decode (p, &size);
4126 g_free (orig_value); /* Don't need this any more */
4131 *mikey = gst_mikey_message_new_from_data (data, size, NULL, NULL);
4134 return (*mikey != NULL);
4138 sdp_add_attributes_to_keymgmt (GArray * attributes, GstMIKEYMessage ** mikey)
4140 GstSDPResult res = GST_SDP_OK;
4142 if (attributes->len > 0) {
4144 for (i = 0; i < attributes->len; i++) {
4145 GstSDPAttribute *attr = &g_array_index (attributes, GstSDPAttribute, i);
4147 if (g_str_equal (attr->key, "key-mgmt")) {
4148 res = gst_sdp_parse_keymgmt (attr->value, mikey);
4158 * gst_sdp_message_parse_keymgmt:
4159 * @msg: a #GstSDPMessage
4160 * @mikey: (out) (transfer full): pointer to new #GstMIKEYMessage
4162 * Creates a new #GstMIKEYMessage after parsing the key-mgmt attribute
4163 * from a #GstSDPMessage.
4165 * Returns: a #GstSDPResult.
4170 gst_sdp_message_parse_keymgmt (const GstSDPMessage * msg,
4171 GstMIKEYMessage ** mikey)
4173 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
4175 return sdp_add_attributes_to_keymgmt (msg->attributes, mikey);
4179 * gst_sdp_media_parse_keymgmt:
4180 * @media: a #GstSDPMedia
4181 * @mikey: (out) (transfer full): pointer to new #GstMIKEYMessage
4183 * Creates a new #GstMIKEYMessage after parsing the key-mgmt attribute
4184 * from a #GstSDPMedia.
4186 * Returns: a #GstSDPResult.
4191 gst_sdp_media_parse_keymgmt (const GstSDPMedia * media,
4192 GstMIKEYMessage ** mikey)
4194 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
4196 return sdp_add_attributes_to_keymgmt (media->attributes, mikey);
4200 sdp_add_attributes_to_caps (GArray * attributes, GstCaps * caps)
4202 if (attributes->len > 0) {
4206 s = gst_caps_get_structure (caps, 0);
4208 for (i = 0; i < attributes->len; i++) {
4209 GstSDPAttribute *attr = &g_array_index (attributes, GstSDPAttribute, i);
4210 gchar *tofree, *key;
4214 /* skip some of the attribute we already handle */
4215 if (!strcmp (key, "fmtp"))
4217 if (!strcmp (key, "rtpmap"))
4219 if (!strcmp (key, "control"))
4221 if (!strcmp (key, "range"))
4223 if (!strcmp (key, "framesize"))
4225 if (!strcmp (key, "key-mgmt"))
4227 if (!strcmp (key, "extmap"))
4229 if (!strcmp (key, "ssrc"))
4231 if (!strcmp (key, "rid"))
4234 /* string must be valid UTF8 */
4235 if (!g_utf8_validate (attr->value, -1, NULL))
4238 if (!g_str_has_prefix (key, "x-"))
4239 tofree = key = g_strdup_printf ("a-%s", key);
4243 GST_DEBUG ("adding caps: %s=%s", key, attr->value);
4244 gst_structure_set (s, key, G_TYPE_STRING, attr->value, NULL);
4253 gst_sdp_media_add_extmap_attributes (GArray * attributes, GstCaps * caps)
4255 const gchar *extmap;
4256 gchar *p, *tmp, *to_free;
4260 g_return_val_if_fail (attributes != NULL, GST_SDP_EINVAL);
4261 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
4263 s = gst_caps_get_structure (caps, 0);
4265 for (i = 0; i < attributes->len; i++) {
4266 GstSDPAttribute *attr;
4267 const gchar *direction, *extensionname, *extensionattributes;
4269 attr = &g_array_index (attributes, GstSDPAttribute, i);
4270 if (strcmp (attr->key, "extmap") != 0)
4273 extmap = attr->value;
4275 /* p is now of the format id[/direction] extensionname [extensionattributes] */
4276 to_free = p = g_strdup (extmap);
4278 id = strtoul (p, &tmp, 10);
4279 if (id == 0 || id == 15 || id > 9999 || (*tmp != ' ' && *tmp != '/')) {
4280 GST_ERROR ("Invalid extmap '%s'", to_free);
4282 } else if (*tmp == '/') {
4286 PARSE_STRING (p, " ", direction);
4288 /* Invalid format */
4289 if (direction == NULL || *direction == '\0') {
4290 GST_ERROR ("Invalid extmap '%s'", to_free);
4301 tmp = strstr (p, " ");
4304 extensionattributes = "";
4310 extensionattributes = p;
4313 if (extensionname == NULL || *extensionname == '\0') {
4314 GST_ERROR ("Invalid extmap '%s'", to_free);
4318 if (*direction != '\0' || *extensionattributes != '\0') {
4319 GValue arr = G_VALUE_INIT;
4320 GValue val = G_VALUE_INIT;
4323 key = g_strdup_printf ("extmap-%u", id);
4325 g_value_init (&arr, GST_TYPE_ARRAY);
4326 g_value_init (&val, G_TYPE_STRING);
4328 g_value_set_string (&val, direction);
4329 gst_value_array_append_value (&arr, &val);
4331 g_value_set_string (&val, extensionname);
4332 gst_value_array_append_value (&arr, &val);
4334 g_value_set_string (&val, extensionattributes);
4335 gst_value_array_append_value (&arr, &val);
4337 gst_structure_set_value (s, key, &arr);
4338 g_value_unset (&val);
4339 g_value_unset (&arr);
4340 GST_DEBUG ("adding caps: %s=<%s,%s,%s>", key, direction, extensionname,
4341 extensionattributes);
4346 key = g_strdup_printf ("extmap-%u", id);
4347 gst_structure_set (s, key, G_TYPE_STRING, extensionname, NULL);
4348 GST_DEBUG ("adding caps: %s=%s", key, extensionname);
4358 /* parses Source-specific media SDP attributes (RFC5576) into caps */
4360 gst_sdp_media_add_ssrc_attributes (GArray * attributes, GstCaps * caps)
4362 gchar *p, *tmp, *to_free;
4366 g_return_val_if_fail (attributes != NULL, GST_SDP_EINVAL);
4367 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
4369 s = gst_caps_get_structure (caps, 0);
4371 for (i = 0; i < attributes->len; i++) {
4373 GstSDPAttribute *attr;
4375 gchar *ssrc_val, *ssrc_attr;
4378 attr = &g_array_index (attributes, GstSDPAttribute, i);
4379 if (strcmp (attr->key, "ssrc") != 0)
4382 value = attr->value;
4384 /* p is now of the format ssrc attribute[:value] */
4385 to_free = p = g_strdup (value);
4387 ssrc = strtoul (p, &tmp, 10);
4389 GST_ERROR ("Invalid ssrc attribute '%s'", to_free);
4398 tmp = strstr (p, ":");
4401 ssrc_val = (gchar *) "";
4409 if (ssrc_attr == NULL || *ssrc_attr == '\0') {
4410 GST_ERROR ("Invalid ssrc attribute '%s'", to_free);
4414 key = g_strdup_printf ("ssrc-%u-%s", ssrc, ssrc_attr);
4415 gst_structure_set (s, key, G_TYPE_STRING, ssrc_val, NULL);
4416 GST_DEBUG ("adding caps: %s=%s", key, ssrc_val);
4425 /* parses RID SDP attributes (RFC8851) into caps */
4427 gst_sdp_media_add_rid_attributes (GArray * attributes, GstCaps * caps)
4434 g_return_val_if_fail (attributes != NULL, GST_SDP_EINVAL);
4435 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
4436 g_return_val_if_fail (gst_caps_is_writable (caps), GST_SDP_EINVAL);
4438 s = gst_caps_get_structure (caps, 0);
4440 for (i = 0; i < attributes->len; i++) {
4441 GstSDPAttribute *attr;
4442 const char *direction, *params, *id;
4445 attr = &g_array_index (attributes, GstSDPAttribute, i);
4446 if (strcmp (attr->key, "rid") != 0)
4451 /* p is now of the format id dir ;-separated-params */
4452 to_free = p = g_strdup (rid);
4454 PARSE_STRING (p, " ", id);
4455 if (id == NULL || *id == '\0') {
4456 GST_ERROR ("Invalid rid \'%s\'", to_free);
4460 while (*tmp && (*tmp == '-' || *tmp == '_' || g_ascii_isalnum (*tmp)))
4463 GST_ERROR ("Invalid rid-id \'%s\'", id);
4469 PARSE_STRING (p, " ", direction);
4470 if (direction == NULL || *direction == '\0') {
4479 if (direction == NULL || *direction == '\0'
4480 || (g_strcmp0 (direction, "send") != 0
4481 && g_strcmp0 (direction, "recv") != 0)) {
4482 GST_ERROR ("Invalid rid direction \'%s\'", p);
4486 if (params && *params != '\0') {
4487 GValue arr = G_VALUE_INIT;
4488 GValue val = G_VALUE_INIT;
4490 #if !defined(GST_DISABLE_DEBUG)
4491 GString *debug_params = g_string_new (NULL);
4495 key = g_strdup_printf ("rid-%s", id);
4497 g_value_init (&arr, GST_TYPE_ARRAY);
4498 g_value_init (&val, G_TYPE_STRING);
4500 g_value_set_string (&val, direction);
4501 gst_value_array_append_and_take_value (&arr, &val);
4502 val = (GValue) G_VALUE_INIT;
4506 gboolean done = FALSE;
4508 PARSE_STRING (p, ";", param);
4518 g_value_init (&val, G_TYPE_STRING);
4519 g_value_set_string (&val, param);
4520 gst_value_array_append_and_take_value (&arr, &val);
4521 val = (GValue) G_VALUE_INIT;
4522 #if !defined(GST_DISABLE_DEBUG)
4524 g_string_append_c (debug_params, ',');
4525 g_string_append (debug_params, param);
4532 gst_structure_take_value (s, key, &arr);
4533 arr = (GValue) G_VALUE_INIT;
4534 #if !defined(GST_DISABLE_DEBUG)
4536 char *debug_str = g_string_free (debug_params, FALSE);
4537 GST_DEBUG ("adding caps: %s=<%s,%s>", key, direction, debug_str);
4545 key = g_strdup_printf ("rid-%s", id);
4546 gst_structure_set (s, key, G_TYPE_STRING, direction, NULL);
4547 GST_DEBUG ("adding caps: %s=%s", key, direction);
4552 g_clear_pointer (&to_free, g_free);
4558 * gst_sdp_message_attributes_to_caps:
4559 * @msg: a #GstSDPMessage
4562 * Mapping of attributes of #GstSDPMessage to #GstCaps
4564 * Returns: a #GstSDPResult.
4569 gst_sdp_message_attributes_to_caps (const GstSDPMessage * msg, GstCaps * caps)
4572 GstMIKEYMessage *mikey = NULL;
4574 g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
4575 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
4577 gst_sdp_message_parse_keymgmt (msg, &mikey);
4579 if (gst_mikey_message_to_caps (mikey, caps)) {
4580 res = GST_SDP_EINVAL;
4585 res = sdp_add_attributes_to_caps (msg->attributes, caps);
4587 if (res == GST_SDP_OK) {
4588 /* parse global extmap field */
4589 res = gst_sdp_media_add_extmap_attributes (msg->attributes, caps);
4594 gst_mikey_message_unref (mikey);
4599 * gst_sdp_media_attributes_to_caps:
4600 * @media: a #GstSDPMedia
4603 * Mapping of attributes of #GstSDPMedia to #GstCaps
4605 * Returns: a #GstSDPResult.
4610 gst_sdp_media_attributes_to_caps (const GstSDPMedia * media, GstCaps * caps)
4613 GstMIKEYMessage *mikey = NULL;
4615 g_return_val_if_fail (media != NULL, GST_SDP_EINVAL);
4616 g_return_val_if_fail (caps != NULL && GST_IS_CAPS (caps), GST_SDP_EINVAL);
4618 gst_sdp_media_parse_keymgmt (media, &mikey);
4620 if (!gst_mikey_message_to_caps (mikey, caps)) {
4621 res = GST_SDP_EINVAL;
4626 res = sdp_add_attributes_to_caps (media->attributes, caps);
4628 if (res == GST_SDP_OK) {
4629 /* parse media extmap field */
4630 res = gst_sdp_media_add_extmap_attributes (media->attributes, caps);
4633 if (res == GST_SDP_OK) {
4634 /* parse media ssrc field */
4635 res = gst_sdp_media_add_ssrc_attributes (media->attributes, caps);
4638 if (res == GST_SDP_OK) {
4639 /* parse media rid fields */
4640 res = gst_sdp_media_add_rid_attributes (media->attributes, caps);
4645 gst_mikey_message_unref (mikey);