3 * @brief Session Description Protocol (SDP)
6 /*****************************************************************************
7 * Copyright © 2020 Rémi Denis-Courmont
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22 ****************************************************************************/
30 * \defgroup sdp Session Description Protocol
41 * Parses an SDP session descriptor.
43 * \param str start address of the descriptor
44 * \param length bytes length of the descriptor
45 * \return a parsed SDP or NULL on error (@c errno is set)
47 struct vlc_sdp
*vlc_sdp_parse(const char *str
, size_t length
);
50 * Destroys a parsed SDP session descriptor.
52 void vlc_sdp_free(struct vlc_sdp
*sdp
);
54 const struct vlc_sdp_attr
*vlc_sdp_attr_first_by_name(
55 struct vlc_sdp_attr
*const *ap
, const char *name
);
60 struct vlc_sdp_attr
*next
; /*< Next attribute (or NULL) */
61 const char *value
; /*< Attribute value, or NULL if none */
62 char name
[]; /*< Attribute name */
65 /** SDP connection address */
68 struct vlc_sdp_conn
*next
; /*< Next address (or NULL) */
69 int family
; /*< Address family, or AF_UNSPEC if not recognized */
70 unsigned char ttl
; /*< Multicast TTL */
71 unsigned short addr_count
; /*< Multicast address count */
72 char addr
[]; /*< Address name, usually an IP literal */
78 struct vlc_sdp_media
*next
; /*< Next media in the session (or NULL) */
79 struct vlc_sdp
*session
; /*< Pointer to containing session */
80 char *type
; /*< Media type, e.g. "audio" or "video" */
81 unsigned int port
; /*< Media port number */
82 unsigned int port_count
; /*< Number of ports (usually 1) */
83 char *proto
; /*< Media protocol, e.g. "RTP/AVP" */
84 char *format
; /*< Protocol-specific format parameters */
85 struct vlc_sdp_conn
*conns
; /*< List of media connection addresses */
86 struct vlc_sdp_attr
*attrs
; /*< List of media attributes */
90 * Gets a media attribute by name.
92 * \param media Session media descriptor.
93 * \param name Session attribute name.
95 * \note This function does <b>not</b> look for session attributes, as this is
96 * not always appropriate.
97 * To fallback to session attributes, call vlc_sdp_attr_get() explicitly.
99 * \return the first attribute with the specified name or NULL if not found.
102 const struct vlc_sdp_attr
*vlc_sdp_media_attr_get(
103 const struct vlc_sdp_media
*media
, const char *name
)
105 return vlc_sdp_attr_first_by_name(&media
->attrs
, name
);
109 * Checks if a median attribute is present.
111 * \param media Media descriptor.
112 * \param name Attribute name.
114 * \retval true if present
115 * \retval false it absent
118 bool vlc_sdp_media_attr_present(const struct vlc_sdp_media
*media
,
121 return vlc_sdp_media_attr_get(media
, name
) != NULL
;
125 * Returns a media attribute value.
127 * \param media Media descriptor.
128 * \param name Attribute name.
130 * \note This function cannot distinguish the cases of a missing attribute and
131 * of an attribute without a value.
132 * Use vlc_sdp_media_attr_present() to check for value-less attributes.
134 * \return Nul-terminated attribute value, or NULL if none.
137 const char *vlc_sdp_media_attr_value(const struct vlc_sdp_media
*media
,
140 const struct vlc_sdp_attr
*a
= vlc_sdp_media_attr_get(media
, name
);
141 return (a
!= NULL
) ? a
->value
: NULL
;
144 /** SDP session descriptor */
147 char *name
; /*< Session name */
148 char *info
; /*< Session description, or NULL if none */
149 struct vlc_sdp_conn
*conn
; /*< Session connection address or NULL */
150 struct vlc_sdp_attr
*attrs
; /*< List of session attributes */
151 struct vlc_sdp_media
*media
; /*< List of session media */
155 * Returns the media connection address list.
158 const struct vlc_sdp_conn
*vlc_sdp_media_conn(
159 const struct vlc_sdp_media
*media
)
161 return (media
->conns
!= NULL
) ? media
->conns
: media
->session
->conn
;
165 * Gets a session attribute by name.
167 * \param sdp Session descriptor.
168 * \param name Attribute name.
170 * \return the first attribute with the specified name or NULL if not found.
173 const struct vlc_sdp_attr
*vlc_sdp_attr_get(const struct vlc_sdp
*sdp
,
176 return vlc_sdp_attr_first_by_name(&sdp
->attrs
, name
);
180 * Checks if a session attribute is present.
182 * \param sdp Session descriptor.
183 * \param name Attribute name.
185 * \retval true if present
186 * \retval false it absent
189 bool vlc_sdp_attr_present(const struct vlc_sdp
*sdp
, const char *name
)
191 return vlc_sdp_attr_get(sdp
, name
) != NULL
;
195 * Returns a session attribute value.
197 * \param sdp Session descriptor.
198 * \param name Attribute name.
200 * \note This function cannot distinguish the cases of a missing attribute and
201 * of an attribute without a value.
202 * Use vlc_sdp_attr_present() to check for value-less attributes.
204 * \return Nul-terminated attribute value, or NULL if none.
207 const char *vlc_sdp_attr_value(const struct vlc_sdp
*sdp
, const char *name
)
209 const struct vlc_sdp_attr
*a
= vlc_sdp_attr_get(sdp
, name
);
210 return (a
!= NULL
) ? a
->value
: NULL
;