1
/* $Id: sdp.h 4367 2013-02-21 20:49:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJMEDIA_SDP_H__
21
#define __PJMEDIA_SDP_H__
25
* @brief SDP header file.
27
#include <pjmedia/types.h>
31
* @defgroup PJMEDIA_SDP SDP Parsing and Data Structure
32
* @ingroup PJMEDIA_SESSION
33
* @brief SDP data structure representation and parsing
36
* The basic SDP session descriptor and elements are described in header
37
* file <b><pjmedia/sdp.h></b>. This file contains declaration for
38
* SDP session descriptor and SDP media descriptor, along with their
39
* attributes. This file also declares functions to parse SDP message.
46
* The PJMEDIA_MAX_SDP_FMT macro defines maximum format in a media line.
48
#ifndef PJMEDIA_MAX_SDP_FMT
49
# define PJMEDIA_MAX_SDP_FMT 32
53
* The PJMEDIA_MAX_SDP_BANDW macro defines maximum bandwidth information
54
* lines in a media line.
56
#ifndef PJMEDIA_MAX_SDP_BANDW
57
# define PJMEDIA_MAX_SDP_BANDW 4
61
* The PJMEDIA_MAX_SDP_ATTR macro defines maximum SDP attributes in media and
64
#ifndef PJMEDIA_MAX_SDP_ATTR
65
# define PJMEDIA_MAX_SDP_ATTR (PJMEDIA_MAX_SDP_FMT*2 + 4)
69
* The PJMEDIA_MAX_SDP_MEDIA macro defines maximum SDP media lines in a
70
* SDP session descriptor.
72
#ifndef PJMEDIA_MAX_SDP_MEDIA
73
# define PJMEDIA_MAX_SDP_MEDIA 16
77
/* **************************************************************************
79
***************************************************************************
83
* Generic representation of attribute.
85
struct pjmedia_sdp_attr
87
pj_str_t name; /**< Attribute name. */
88
pj_str_t value; /**< Attribute value. */
92
* @see pjmedia_sdp_attr
94
typedef struct pjmedia_sdp_attr pjmedia_sdp_attr;
98
* Create SDP attribute.
100
* @param pool Pool to create the attribute.
101
* @param name Attribute name.
102
* @param value Optional attribute value.
104
* @return The new SDP attribute.
106
PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create(pj_pool_t *pool,
108
const pj_str_t *value);
113
* @param pool Pool to be used.
114
* @param attr The attribute to clone.
116
* @return New attribute as cloned from the attribute.
118
PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_clone(pj_pool_t *pool,
119
const pjmedia_sdp_attr*attr);
122
* Find the first attribute with the specified type.
124
* @param count Number of attributes in the array.
125
* @param attr_array Array of attributes.
126
* @param name Attribute name to find.
127
* @param fmt Optional string to indicate which payload format
128
* to find for \a rtpmap and \a fmt attributes. For other
129
* types of attributes, the value should be NULL.
131
* @return The specified attribute, or NULL if it can't be found.
133
* @see pjmedia_sdp_attr_find2, pjmedia_sdp_media_find_attr,
134
* pjmedia_sdp_media_find_attr2
136
PJ_DECL(pjmedia_sdp_attr*)
137
pjmedia_sdp_attr_find(unsigned count,
138
pjmedia_sdp_attr *const attr_array[],
139
const pj_str_t *name, const pj_str_t *fmt);
142
* Find the first attribute with the specified type.
144
* @param count Number of attributes in the array.
145
* @param attr_array Array of attributes.
146
* @param name Attribute name to find.
147
* @param fmt Optional string to indicate which payload format
148
* to find for \a rtpmap and \a fmt attributes. For other
149
* types of attributes, the value should be NULL.
151
* @return The specified attribute, or NULL if it can't be found.
153
* @see pjmedia_sdp_attr_find, pjmedia_sdp_media_find_attr,
154
* pjmedia_sdp_media_find_attr2
156
PJ_DECL(pjmedia_sdp_attr*)
157
pjmedia_sdp_attr_find2(unsigned count,
158
pjmedia_sdp_attr *const attr_array[],
159
const char *name, const pj_str_t *fmt);
162
* Add a new attribute to array of attributes.
164
* @param count Number of attributes in the array.
165
* @param attr_array Array of attributes.
166
* @param attr The attribute to add.
168
* @return PJ_SUCCESS or the error code.
170
* @see pjmedia_sdp_media_add_attr
172
PJ_DECL(pj_status_t) pjmedia_sdp_attr_add(unsigned *count,
173
pjmedia_sdp_attr *attr_array[],
174
pjmedia_sdp_attr *attr);
177
* Remove all attributes with the specified name in array of attributes.
179
* @param count Number of attributes in the array.
180
* @param attr_array Array of attributes.
181
* @param name Attribute name to find.
183
* @return Number of attributes removed.
185
* @see pjmedia_sdp_media_remove_all_attr
187
PJ_DECL(unsigned) pjmedia_sdp_attr_remove_all(unsigned *count,
188
pjmedia_sdp_attr *attr_array[],
193
* Remove the specified attribute from the attribute array.
195
* @param count Number of attributes in the array.
196
* @param attr_array Array of attributes.
197
* @param attr The attribute instance to remove.
199
* @return PJ_SUCCESS when attribute has been removed, or
200
* PJ_ENOTFOUND when the attribute can not be found.
202
* @see pjmedia_sdp_media_remove_attr
204
PJ_DECL(pj_status_t) pjmedia_sdp_attr_remove(unsigned *count,
205
pjmedia_sdp_attr *attr_array[],
206
pjmedia_sdp_attr *attr);
210
* This structure declares SDP \a rtpmap attribute.
212
struct pjmedia_sdp_rtpmap
214
pj_str_t pt; /**< Payload type. */
215
pj_str_t enc_name; /**< Encoding name. */
216
unsigned clock_rate; /**< Clock rate. */
217
pj_str_t param; /**< Parameter. */
221
* @see pjmedia_sdp_rtpmap
223
typedef struct pjmedia_sdp_rtpmap pjmedia_sdp_rtpmap;
227
* Convert generic attribute to SDP \a rtpmap. This function allocates
228
* a new attribute and call #pjmedia_sdp_attr_get_rtpmap().
230
* @param pool Pool used to create the rtpmap attribute.
231
* @param attr Generic attribute to be converted to rtpmap, which
232
* name must be "rtpmap".
233
* @param p_rtpmap Pointer to receive SDP rtpmap attribute.
235
* @return PJ_SUCCESS if the attribute can be successfully
236
* converted to \a rtpmap type.
238
* @see pjmedia_sdp_attr_get_rtpmap
240
PJ_DECL(pj_status_t) pjmedia_sdp_attr_to_rtpmap(pj_pool_t *pool,
241
const pjmedia_sdp_attr *attr,
242
pjmedia_sdp_rtpmap **p_rtpmap);
246
* Get the rtpmap representation of the same SDP attribute.
248
* @param attr Generic attribute to be converted to rtpmap, which
249
* name must be "rtpmap".
250
* @param rtpmap SDP \a rtpmap attribute to be initialized.
252
* @return PJ_SUCCESS if the attribute can be successfully
253
* converted to \a rtpmap attribute.
255
* @see pjmedia_sdp_attr_to_rtpmap
257
PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_rtpmap(const pjmedia_sdp_attr *attr,
258
pjmedia_sdp_rtpmap *rtpmap);
262
* Convert \a rtpmap attribute to generic attribute.
264
* @param pool Pool to be used.
265
* @param rtpmap The \a rtpmap attribute.
266
* @param p_attr Pointer to receive the generic SDP attribute.
268
* @return PJ_SUCCESS on success.
271
pjmedia_sdp_rtpmap_to_attr( pj_pool_t *pool,
272
const pjmedia_sdp_rtpmap *rtpmap,
273
pjmedia_sdp_attr **p_attr);
277
* This structure describes SDP \a fmtp attribute.
279
typedef struct pjmedia_sdp_fmtp
281
pj_str_t fmt; /**< Format type. */
282
pj_str_t fmt_param; /**< Format specific parameter. */
287
* Get the fmtp representation of the same SDP attribute.
289
* @param attr Generic attribute to be converted to fmtp, which
290
* name must be "fmtp".
291
* @param fmtp SDP fmtp attribute to be initialized.
293
* @return PJ_SUCCESS on success.
295
PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_fmtp(const pjmedia_sdp_attr *attr,
296
pjmedia_sdp_fmtp *fmtp);
300
* This structure describes SDP \a rtcp attribute.
302
typedef struct pjmedia_sdp_rtcp_attr
304
unsigned port; /**< RTCP port number. */
305
pj_str_t net_type; /**< Optional network type. */
306
pj_str_t addr_type; /**< Optional address type. */
307
pj_str_t addr; /**< Optional address. */
308
} pjmedia_sdp_rtcp_attr;
312
* Parse a generic SDP attribute to get SDP rtcp attribute values.
314
* @param attr Generic attribute to be converted to rtcp, which
315
* name must be "rtcp".
316
* @param rtcp SDP rtcp attribute to be initialized.
318
* @return PJ_SUCCESS on success.
320
PJ_DECL(pj_status_t) pjmedia_sdp_attr_get_rtcp(const pjmedia_sdp_attr *attr,
321
pjmedia_sdp_rtcp_attr *rtcp);
325
* Create a=rtcp attribute.
327
* @param pool Pool to create the attribute.
328
* @param a Socket address.
330
* @return SDP RTCP attribute.
332
PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_rtcp(pj_pool_t *pool,
333
const pj_sockaddr *a);
336
/* **************************************************************************
337
* SDP CONNECTION INFO
338
****************************************************************************
342
* This structure describes SDP connection info ("c=" line).
344
struct pjmedia_sdp_conn
346
pj_str_t net_type; /**< Network type ("IN"). */
347
pj_str_t addr_type; /**< Address type ("IP4", "IP6"). */
348
pj_str_t addr; /**< The address. */
353
* @see pjmedia_sdp_conn
355
typedef struct pjmedia_sdp_conn pjmedia_sdp_conn;
359
* Clone connection info.
361
* @param pool Pool to allocate memory for the new connection info.
362
* @param rhs The connection into to clone.
364
* @return The new connection info.
366
PJ_DECL(pjmedia_sdp_conn*) pjmedia_sdp_conn_clone(pj_pool_t *pool,
367
const pjmedia_sdp_conn *rhs);
371
* Compare connection info.
373
* @param conn1 The first connection info to compare.
374
* @param conn1 The second connection info to compare.
375
* @param option Comparison option, which should be zero for now.
377
* @return PJ_SUCCESS when both connection info are equal, otherwise
378
* returns PJMEDIA_SDP_ECONNNOTEQUAL.
380
PJ_DECL(pj_status_t) pjmedia_sdp_conn_cmp(const pjmedia_sdp_conn *conn1,
381
const pjmedia_sdp_conn *conn2,
385
/* **************************************************************************
387
****************************************************************************
391
* This structure describes SDP bandwidth info ("b=" line).
393
typedef struct pjmedia_sdp_bandw
395
pj_str_t modifier; /**< Bandwidth modifier. */
396
pj_uint32_t value; /**< Bandwidth value. */
401
* Clone bandwidth info.
403
* @param pool Pool to allocate memory for the new bandwidth info.
404
* @param rhs The bandwidth into to clone.
406
* @return The new bandwidth info.
408
PJ_DECL(pjmedia_sdp_bandw*)
409
pjmedia_sdp_bandw_clone(pj_pool_t *pool, const pjmedia_sdp_bandw *rhs);
413
/* **************************************************************************
414
* SDP MEDIA INFO/LINE
415
****************************************************************************
419
* This structure describes SDP media descriptor. A SDP media descriptor
420
* starts with "m=" line and contains the media attributes and optional
423
struct pjmedia_sdp_media
425
/** Media descriptor line ("m=" line) */
428
pj_str_t media; /**< Media type ("audio", "video") */
429
pj_uint16_t port; /**< Port number. */
430
unsigned port_count; /**< Port count, used only when >2 */
431
pj_str_t transport; /**< Transport ("RTP/AVP") */
432
unsigned fmt_count; /**< Number of formats. */
433
pj_str_t fmt[PJMEDIA_MAX_SDP_FMT]; /**< Media formats. */
436
pjmedia_sdp_conn *conn; /**< Optional connection info. */
437
unsigned bandw_count; /**< Number of bandwidth info. */
438
pjmedia_sdp_bandw *bandw[PJMEDIA_MAX_SDP_BANDW]; /**< Bandwidth info. */
439
unsigned attr_count; /**< Number of attributes. */
440
pjmedia_sdp_attr *attr[PJMEDIA_MAX_SDP_ATTR]; /**< Attributes. */
446
* @see pjmedia_sdp_media
448
typedef struct pjmedia_sdp_media pjmedia_sdp_media;
452
* Clone SDP media description.
454
* @param pool Pool to allocate memory for the new media description.
455
* @param rhs The media descriptin to clone.
457
* @return New media description.
459
PJ_DECL(pjmedia_sdp_media*)
460
pjmedia_sdp_media_clone( pj_pool_t *pool,
461
const pjmedia_sdp_media *rhs);
464
* Find the first occurence of the specified attribute name in the media
465
* descriptor. Optionally the format may be specified.
467
* @param m The SDP media description.
468
* @param name Attribute name to find.
469
* @param fmt Optional payload type to match in the
470
* attribute list, when the attribute is \a rtpmap
471
* or \a fmtp. For other types of SDP attributes, this
472
* value should be NULL.
474
* @return The first instance of the specified attribute or NULL.
476
PJ_DECL(pjmedia_sdp_attr*)
477
pjmedia_sdp_media_find_attr(const pjmedia_sdp_media *m,
478
const pj_str_t *name, const pj_str_t *fmt);
482
* Find the first occurence of the specified attribute name in the SDP media
483
* descriptor. Optionally the format may be specified.
485
* @param m The SDP media description.
486
* @param name Attribute name to find.
487
* @param fmt Optional payload type to match in the
488
* attribute list, when the attribute is \a rtpmap
489
* or \a fmtp. For other types of SDP attributes, this
490
* value should be NULL.
492
* @return The first instance of the specified attribute or NULL.
494
PJ_DECL(pjmedia_sdp_attr*)
495
pjmedia_sdp_media_find_attr2(const pjmedia_sdp_media *m,
496
const char *name, const pj_str_t *fmt);
499
* Add new attribute to the media descriptor.
501
* @param m The SDP media description.
502
* @param attr Attribute to add.
504
* @return PJ_SUCCESS or the appropriate error code.
506
PJ_DECL(pj_status_t) pjmedia_sdp_media_add_attr(pjmedia_sdp_media *m,
507
pjmedia_sdp_attr *attr);
510
* Remove all attributes with the specified name from the SDP media
513
* @param m The SDP media description.
514
* @param name Attribute name to remove.
516
* @return The number of attributes removed.
519
pjmedia_sdp_media_remove_all_attr(pjmedia_sdp_media *m,
524
* Remove the occurence of the specified attribute from the SDP media
527
* @param m The SDP media descriptor.
528
* @param attr The attribute to find and remove.
530
* @return PJ_SUCCESS if the attribute can be found and has
531
* been removed from the array.
534
pjmedia_sdp_media_remove_attr(pjmedia_sdp_media *m,
535
pjmedia_sdp_attr *attr);
539
* Compare two SDP media for equality.
541
* @param sd1 The first SDP media to compare.
542
* @param sd2 The second SDP media to compare.
543
* @param option Comparison option, which should be zero for now.
545
* @return PJ_SUCCESS when both SDP medias are equal, or the
546
* appropriate status code describing which part of
547
* the descriptors that are not equal.
549
PJ_DECL(pj_status_t) pjmedia_sdp_media_cmp(const pjmedia_sdp_media *sd1,
550
const pjmedia_sdp_media *sd2,
555
* Compare two media transports for compatibility.
557
* @param t1 The first media transport to compare.
558
* @param t2 The second media transport to compare.
560
* @return PJ_SUCCESS when both media transports are compatible,
561
* otherwise returns PJMEDIA_SDP_ETPORTNOTEQUAL.
563
PJ_DECL(pj_status_t) pjmedia_sdp_transport_cmp(const pj_str_t *t1,
568
* Deactivate SDP media.
570
* @param pool Memory pool to allocate memory from.
571
* @param m The SDP media to deactivate.
573
* @return PJ_SUCCESS when SDP media successfully deactivated,
574
* otherwise appropriate status code returned.
576
PJ_DECL(pj_status_t) pjmedia_sdp_media_deactivate(pj_pool_t *pool,
577
pjmedia_sdp_media *m);
581
* Clone SDP media description and deactivate the new SDP media.
583
* @param pool Memory pool to allocate memory for the clone.
584
* @param rhs The SDP media to clone.
586
* @return New media descrption with deactivated indication.
588
PJ_DECL(pjmedia_sdp_media*) pjmedia_sdp_media_clone_deactivate(
590
const pjmedia_sdp_media *rhs);
593
/* **************************************************************************
594
* SDP SESSION DESCRIPTION
595
****************************************************************************
600
* This structure describes SDP session description. A SDP session descriptor
601
* contains complete information about a session, and normally is exchanged
602
* with remote media peer using signaling protocol such as SIP.
604
struct pjmedia_sdp_session
606
/** Session origin (o= line) */
609
pj_str_t user; /**< User */
610
pj_uint32_t id; /**< Session ID */
611
pj_uint32_t version; /**< Session version */
612
pj_str_t net_type; /**< Network type ("IN") */
613
pj_str_t addr_type; /**< Address type ("IP4", "IP6") */
614
pj_str_t addr; /**< The address. */
617
pj_str_t name; /**< Subject line (s=) */
618
pjmedia_sdp_conn *conn; /**< Connection line (c=) */
619
unsigned bandw_count; /**< Number of bandwidth info (b=) */
620
pjmedia_sdp_bandw *bandw[PJMEDIA_MAX_SDP_BANDW];
621
/**< Bandwidth info array (b=) */
623
/** Session time (t= line) */
626
pj_uint32_t start; /**< Start time. */
627
pj_uint32_t stop; /**< Stop time. */
630
unsigned attr_count; /**< Number of attributes. */
631
pjmedia_sdp_attr *attr[PJMEDIA_MAX_SDP_ATTR]; /**< Attributes array. */
633
unsigned media_count; /**< Number of media. */
634
pjmedia_sdp_media *media[PJMEDIA_MAX_SDP_MEDIA]; /**< Media array. */
639
* @see pjmedia_sdp_session
641
typedef struct pjmedia_sdp_session pjmedia_sdp_session;
648
* @param pool The pool to allocate SDP session description.
649
* @param buf The message buffer.
650
* @param len The length of the message.
651
* @param p_sdp Pointer to receive the SDP session descriptor.
653
* @return PJ_SUCCESS if message was successfully parsed into
654
* SDP session descriptor.
656
PJ_DECL(pj_status_t) pjmedia_sdp_parse( pj_pool_t *pool,
657
char *buf, pj_size_t len,
658
pjmedia_sdp_session **p_sdp );
661
* Print SDP description to a buffer.
663
* @param sdp The SDP session description.
664
* @param buf The buffer.
665
* @param size The buffer length.
667
* @return the length printed, or -1 if the buffer is too
670
PJ_DECL(int) pjmedia_sdp_print( const pjmedia_sdp_session *sdp,
671
char *buf, pj_size_t size);
675
* Perform semantic validation for the specified SDP session descriptor.
676
* This function perform validation beyond just syntactic verification,
677
* such as to verify the value of network type and address type, check
678
* the connection line, and verify that \a rtpmap attribute is present
679
* when dynamic payload type is used.
681
* @param sdp The SDP session descriptor to validate.
683
* @return PJ_SUCCESS on success.
685
PJ_DECL(pj_status_t) pjmedia_sdp_validate(const pjmedia_sdp_session *sdp);
689
* Perform semantic validation for the specified SDP session descriptor.
690
* This function perform validation beyond just syntactic verification,
691
* such as to verify the value of network type and address type, check
692
* the connection line, and verify that \a rtpmap attribute is present
693
* when dynamic payload type is used.
695
* @param sdp The SDP session descriptor to validate.
696
* @param strict Flag whether the check should be strict, i.e: allow
697
* media without connection line when port is zero.
699
* @return PJ_SUCCESS on success.
701
PJ_DECL(pj_status_t) pjmedia_sdp_validate2(const pjmedia_sdp_session *sdp,
706
* Clone SDP session descriptor.
708
* @param pool The pool used to clone the session.
709
* @param sdp The SDP session to clone.
711
* @return New SDP session.
713
PJ_DECL(pjmedia_sdp_session*)
714
pjmedia_sdp_session_clone( pj_pool_t *pool,
715
const pjmedia_sdp_session *sdp);
719
* Compare two SDP session for equality.
721
* @param sd1 The first SDP session to compare.
722
* @param sd2 The second SDP session to compare.
723
* @param option Must be zero for now.
725
* @return PJ_SUCCESS when both SDPs are equal, or otherwise
726
* the status code indicates which part of the session
727
* descriptors are not equal.
729
PJ_DECL(pj_status_t) pjmedia_sdp_session_cmp(const pjmedia_sdp_session *sd1,
730
const pjmedia_sdp_session *sd2,
735
* Add new attribute to the session descriptor.
737
* @param s The SDP session description.
738
* @param attr Attribute to add.
740
* @return PJ_SUCCESS or the appropriate error code.
742
PJ_DECL(pj_status_t) pjmedia_sdp_session_add_attr(pjmedia_sdp_session *s,
743
pjmedia_sdp_attr *attr);
752
#endif /* __PJMEDIA_SDP_H__ */