summaryrefslogtreecommitdiff
path: root/pjmedia/src/pjmedia/sdp.h
blob: 1b45744c38a1423dbb8dac51db53ec8124b45506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/* $Id$ */
/* 
 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
#ifndef __PJSDP_SDP_H__
#define __PJSDP_SDP_H__

/**
 * @defgroup PJSDP SDP Library
 */
/**
 * @file sdp.h
 * @brief SDP header file.
 */
/**
 * @defgroup PJ_SDP_H SDP stack.
 * @ingroup PJSDP
 * @{
 *
 * This SDP module consists of SDP parser, SDP structure, and function to
 * print back the structure as SDP message.
 */

#include <pj/types.h>

PJ_BEGIN_DECL

#define PJSDP_MAX_FMT	32
#define PJSDP_MAX_ATTR	32
#define PJSDP_MAX_MEDIA	16

/**
 * This enumeration describes the attribute type.
 */
typedef enum pjsdp_attr_type_e
{
    PJSDP_ATTR_RTPMAP,
    PJSDP_ATTR_CAT,
    PJSDP_ATTR_KEYWORDS,
    PJSDP_ATTR_TOOL,
    PJSDP_ATTR_PTIME,
    PJSDP_ATTR_RECV_ONLY,
    PJSDP_ATTR_SEND_ONLY,
    PJSDP_ATTR_SEND_RECV,
    PJSDP_ATTR_ORIENT,
    PJSDP_ATTR_TYPE,
    PJSDP_ATTR_CHARSET,
    PJSDP_ATTR_SDP_LANG,
    PJSDP_ATTR_LANG,
    PJSDP_ATTR_FRAME_RATE,
    PJSDP_ATTR_QUALITY,
    PJSDP_ATTR_FMTP,
    PJSDP_ATTR_INACTIVE,
    PJSDP_ATTR_GENERIC,
    PJSDP_END_OF_ATTR,
} pjsdp_attr_type_e;


/**
 * This structure keeps the common attributes that all 'descendants' 
 * will have.
 */
typedef struct pjsdp_attr
{
    pjsdp_attr_type_e	type;	/**< Attribute type. */
} pjsdp_attr;


/**
 * This is the structure to represent generic attribute which has a 
 * string value.
 */
typedef struct pjsdp_attr_string
{
    pjsdp_attr_type_e	type;
    pj_str_t		value;
} pjsdp_attr_string;


/**
 * This is the structure to represent generic SDP attribute which has
 * a numeric value.
 */
typedef struct pjsdp_attr_num
{
    pjsdp_attr_type_e	type;
    pj_uint32_t		value;
} pjsdp_attr_num;


/**
 * SDP \a rtpmap attribute.
 */
typedef struct pjsdp_rtpmap_attr
{
    pjsdp_attr_type_e	type;
    unsigned		payload_type;
    pj_str_t		encoding_name;
    unsigned		clock_rate;
    pj_str_t		parameter;
} pjsdp_rtpmap_attr;


/**
 * SDP \a fmtp attribute.
 */
typedef struct pjsdp_fmtp_attr
{
    pjsdp_attr_type_e	type;
    pj_str_t		format;
    pj_str_t		param;
} pjsdp_fmtp_attr;


/** 
 * SDP generic attribute.
 */
typedef struct pjsdp_generic_attr
{
    pjsdp_attr_type_e	type;
    pj_str_t		name;
    pj_str_t		value;
} pjsdp_generic_attr;


/** SDP \a cat attribute. */
typedef struct pjsdp_attr_string pjsdp_cat_attr;

/** SDP \a keywds attribute. */
typedef struct pjsdp_attr_string pjsdp_keywds_attr;

/** SDP \a tool attribute. */
typedef struct pjsdp_attr_string pjsdp_tool_attr;

/** SDP \a ptime attribute. */
typedef struct pjsdp_attr_num pjsdp_ptime_attr;

/** SDP \a recvonly attribute. */
typedef struct pjsdp_attr pjsdp_recv_only_attr;

/** SDP \a sendonly attribute. */
typedef struct pjsdp_attr pjsdp_send_only_attr;

/** SDP \a sendrecv attribute. */
typedef struct pjsdp_attr pjsdp_send_recv_attr;

/** SDP \a orient attribute. */
typedef struct pjsdp_attr_string pjsdp_orient_attr;

/** SDP \a type attribute. */
typedef struct pjsdp_attr_string pjsdp_type_attr;

/** SDP \a charset attribute. */
typedef struct pjsdp_attr_string pjsdp_charset_attr;

/** SDP \a sdplang attribute. */
typedef struct pjsdp_attr_string pjsdp_sdp_lang_attr;

/** SDP \a lang attribute. */
typedef struct pjsdp_attr_string pjsdp_lang_attr;

/** SDP \a framerate attribute. */
typedef struct pjsdp_attr_string pjsdp_frame_rate_attr;

/** SDP \a quality attribute. */
typedef struct pjsdp_attr_num pjsdp_quality_attr;

/** SDP \a inactive attribute. */
typedef struct pjsdp_attr pjsdp_inactive_attr;

/** Clone attribute */
PJ_DECL(pjsdp_attr*) pjsdp_attr_clone (pj_pool_t *pool, const pjsdp_attr *rhs);

/** Find attribute */
PJ_DECL(const pjsdp_attr*) pjsdp_attr_find (int count, const pjsdp_attr *attr_array[], int type);

/**
 * SDP connection info.
 */
typedef struct pjsdp_conn_info
{
    pj_str_t	net_type;
    pj_str_t	addr_type;
    pj_str_t	addr;
} pjsdp_conn_info;

/** 
 *Clone connection info. 
 * 
 * @param pool	    Pool to allocate memory for the new connection info.
 * @param rhs	    The connection into to clone.
 *
 * @return the new connection info.
 */
PJ_DECL(pjsdp_conn_info*) pjsdp_conn_info_clone (pj_pool_t *pool, 
						 const pjsdp_conn_info *rhs);

/**
 * SDP media description.
 */
typedef struct pjsdp_media_desc
{
    struct
    {
	pj_str_t    media;
	pj_uint16_t port;
	unsigned    port_count;
	pj_str_t    transport;
	unsigned    fmt_count;
	pj_str_t    fmt[PJSDP_MAX_FMT];
    } desc;

    pjsdp_conn_info *conn;
    unsigned	    attr_count;
    pjsdp_attr	   *attr[PJSDP_MAX_ATTR];

} pjsdp_media_desc;

/** 
 * Clone SDP media description. 
 *
 * @param pool	    Pool to allocate memory for the new media description.
 * @param rhs	    The media descriptin to clone.
 *
 * @return a new media description.
 */
PJ_DECL(pjsdp_media_desc*) pjsdp_media_desc_clone (pj_pool_t *pool, 
						   const pjsdp_media_desc *rhs);

/** 
 * Check if the media description has the specified attribute.
 *
 * @param m		The SDP media description.
 * @param attr_type	The attribute type.
 *
 * @return nonzero if true.
 */
PJ_DECL(pj_bool_t) pjsdp_media_desc_has_attr (const pjsdp_media_desc *m, 
					      pjsdp_attr_type_e attr_type);

/** 
 * Find rtpmap attribute for the specified payload type. 
 *
 * @param m	    The SDP media description.
 * @param pt	    RTP payload type.
 *
 * @return the SDP rtpmap attribute for the payload type, or NULL if not found.
 */
PJ_DECL(const pjsdp_rtpmap_attr*) 
pjsdp_media_desc_find_rtpmap (const pjsdp_media_desc *m, unsigned pt);


/**
 * This structure describes SDP session description.
 */
typedef struct pjsdp_session_desc
{
    struct
    {
	pj_str_t    user;
	pj_uint32_t id;
	pj_uint32_t version;
	pj_str_t    net_type;
	pj_str_t    addr_type;
	pj_str_t    addr;
    } origin;

    pj_str_t	     name;
    pjsdp_conn_info *conn;
    
    struct
    {
	pj_uint32_t start;
	pj_uint32_t stop;
    } time;

    unsigned	    attr_count;
    pjsdp_attr	   *attr[PJSDP_MAX_ATTR];

    unsigned	      media_count;
    pjsdp_media_desc *media[PJSDP_MAX_MEDIA];

} pjsdp_session_desc;


/**
 * Parse SDP message.
 *
 * @param buf	    The message buffer.
 * @param len	    The length of the message.
 * @param pool	    The pool to allocate SDP session description.
 *
 * @return SDP session description.
 */
PJ_DECL(pjsdp_session_desc*) pjsdp_parse( char *buf, pj_size_t len, 
					  pj_pool_t *pool);

/**
 * Print SDP description to a buffer.
 *
 * @param buf	    The buffer.
 * @param size	    The buffer length.
 * @param desc	    The SDP session description.
 *
 * @return the length printed, or -1.
 */
PJ_DECL(int) pjsdp_print( const pjsdp_session_desc *desc, 
			  char *buf, pj_size_t size);


/**
 * @}
 */

PJ_END_DECL

#endif	/* __PJSDP_SDP_H__ */