no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / third_party / sipcc / sdp_access.c
blob8a065e2a6a030b9fe41a74793a1102077429211e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "sdp_os_defs.h"
6 #include "sipcc_sdp.h"
7 #include "sdp_private.h"
9 #include "sdp_log.h"
11 static const char* logTag = "sdp_access";
13 /* Pulled in from ccsip_sdp.h */
14 /* Possible encoding names of static payload types*/
15 #define SIPSDP_ATTR_ENCNAME_PCMU "PCMU"
16 #define SIPSDP_ATTR_ENCNAME_PCMA "PCMA"
17 #define SIPSDP_ATTR_ENCNAME_G729 "G729"
18 #define SIPSDP_ATTR_ENCNAME_G723 "G723"
19 #define SIPSDP_ATTR_ENCNAME_G726 "G726-32"
20 #define SIPSDP_ATTR_ENCNAME_G728 "G728"
21 #define SIPSDP_ATTR_ENCNAME_GSM "GSM"
22 #define SIPSDP_ATTR_ENCNAME_CN "CN"
23 #define SIPSDP_ATTR_ENCNAME_G722 "G722"
24 #define SIPSDP_ATTR_ENCNAME_ILBC "iLBC"
25 #define SIPSDP_ATTR_ENCNAME_H263v2 "H263-1998"
26 #define SIPSDP_ATTR_ENCNAME_H264 "H264"
27 #define SIPSDP_ATTR_ENCNAME_VP8 "VP8"
28 #define SIPSDP_ATTR_ENCNAME_VP9 "VP9"
29 #define SIPSDP_ATTR_ENCNAME_L16_256K "L16"
30 #define SIPSDP_ATTR_ENCNAME_ISAC "ISAC"
31 #define SIPSDP_ATTR_ENCNAME_OPUS "opus"
32 #define SIPSDP_ATTR_ENCNAME_RED "red"
33 #define SIPSDP_ATTR_ENCNAME_ULPFEC "ulpfec"
34 #define SIPSDP_ATTR_ENCNAME_TELEPHONE_EVENT "telephone-event"
35 #define SIPSDP_ATTR_ENCNAME_RTX "rtx"
37 /* Function: sdp_find_media_level
38 * Description: Find and return a pointer to the specified media level,
39 * if it exists.
40 * Note: This is not an API for the application but an internal
41 * routine used by the SDP library.
42 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
43 * level The media level to find.
44 * Returns: Pointer to the media level or NULL if not found.
46 sdp_mca_t *sdp_find_media_level (sdp_t *sdp_p, uint16_t level)
48 int i;
49 sdp_mca_t *mca_p = NULL;
51 if ((level >= 1) && (level <= sdp_p->mca_count)) {
52 for (i=1, mca_p = sdp_p->mca_p;
53 ((i < level) && (mca_p != NULL));
54 mca_p = mca_p->next_p, i++) {
56 /*sa_ignore EMPTYLOOP*/
57 ; /* Do nothing. */
61 return (mca_p);
64 /* Function: sdp_version_valid
65 * Description: Returns true or false depending on whether the version
66 * set for this SDP is valid. Currently the only valid
67 * version is 0.
68 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
69 * Returns: TRUE or FALSE.
71 tinybool sdp_version_valid (sdp_t *sdp_p)
73 if (sdp_p->version == SDP_INVALID_VALUE) {
74 return (FALSE);
75 } else {
76 return (TRUE);
80 /* Function: sdp_get_version
81 * Description: Returns the version value set for the given SDP.
82 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
83 * Returns: Version value.
85 int32_t sdp_get_version (sdp_t *sdp_p)
87 return (sdp_p->version);
90 /* Function: sdp_set_version
91 * Description: Sets the value of the version parameter for the v= version
92 * token line.
93 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
94 * version Version to set.
95 * Returns: SDP_SUCCESS
97 sdp_result_e sdp_set_version (sdp_t *sdp_p, int32_t version)
99 sdp_p->version = version;
100 return (SDP_SUCCESS);
103 /* Function: sdp_owner_valid
104 * Description: Returns true or false depending on whether the owner
105 * token line has been defined for this SDP.
106 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
107 * Returns: TRUE or FALSE.
109 tinybool sdp_owner_valid (sdp_t *sdp_p)
111 if ((sdp_p->owner_name[0] == '\0') ||
112 (sdp_p->owner_network_type == SDP_NT_INVALID) ||
113 (sdp_p->owner_addr_type == SDP_AT_INVALID) ||
114 (sdp_p->owner_addr[0] == '\0')) {
115 return (FALSE);
116 } else {
117 return (TRUE);
121 /* Function: sdp_get_owner_username
122 * Description: Returns a pointer to the value of the username parameter
123 * from the o= owner token line. Value is returned as a
124 * const ptr and so cannot be modified by the application.
125 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
126 * Returns: Version value.
128 const char *sdp_get_owner_username (sdp_t *sdp_p)
130 return (sdp_p->owner_name);
133 /* Function: sdp_get_owner_sessionid
134 * Description: Returns the session id parameter from the o= owner token
135 * line. Because the value may be larger than 32 bits, this
136 * parameter is returned as a string, though has been verified
137 * to be numeric. Value is returned as a const ptr and so
138 * cannot be modified by the application.
139 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
140 * Returns: Ptr to owner session id or NULL.
142 const char *sdp_get_owner_sessionid (sdp_t *sdp_p)
144 return (sdp_p->owner_sessid);
147 /* Function: sdp_get_owner_version
148 * Description: Returns the version parameter from the o= owner token
149 * line. Because the value may be larger than 32 bits, this
150 * parameter is returned as a string, though has been verified
151 * to be numeric. Value is returned as a const ptr and so
152 * cannot be modified by the application.
153 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
154 * Returns: Ptr to owner version or NULL.
156 const char *sdp_get_owner_version (sdp_t *sdp_p)
158 return (sdp_p->owner_version);
161 /* Function: sdp_get_owner_network_type
162 * Description: Returns the network type parameter from the o= owner token
163 * line. If network type has not been set SDP_NT_INVALID will
164 * be returned.
165 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
166 * Returns: Network type or SDP_NT_INVALID.
168 sdp_nettype_e sdp_get_owner_network_type (sdp_t *sdp_p)
170 return (sdp_p->owner_network_type);
173 /* Function: sdp_get_owner_address_type
174 * Description: Returns the address type parameter from the o= owner token
175 * line. If address type has not been set SDP_AT_INVALID will
176 * be returned.
177 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
178 * Returns: Address type or SDP_AT_INVALID.
180 sdp_addrtype_e sdp_get_owner_address_type (sdp_t *sdp_p)
182 return (sdp_p->owner_addr_type);
185 /* Function: sdp_get_owner_address
186 * Description: Returns the address parameter from the o= owner token
187 * line. Value is returned as a const ptr and so
188 * cannot be modified by the application.
189 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
190 * Returns: Ptr to address or NULL.
192 const char *sdp_get_owner_address (sdp_t *sdp_p)
194 return (sdp_p->owner_addr);
197 /* Function: sdp_set_owner_username
198 * Description: Sets the value of the username parameter for the o= owner
199 * token line. The string is copied into the SDP structure
200 * so application memory will not be referenced by the SDP lib.
201 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
202 * username Ptr to the username string.
203 * Returns: SDP_SUCCESS
205 sdp_result_e sdp_set_owner_username (sdp_t *sdp_p, const char *username)
207 sstrncpy(sdp_p->owner_name, username, sizeof(sdp_p->owner_name));
208 return (SDP_SUCCESS);
211 /* Function: sdp_set_owner_username
212 * Description: Sets the value of the session id parameter for the o= owner
213 * token line. The string is copied into the SDP structure
214 * so application memory will not be referenced by the SDP lib.
215 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
216 * sessionid Ptr to the sessionid string.
217 * Returns: SDP_SUCCESS
219 sdp_result_e sdp_set_owner_sessionid (sdp_t *sdp_p, const char *sessionid)
221 sstrncpy(sdp_p->owner_sessid, sessionid, sizeof(sdp_p->owner_sessid));
222 return (SDP_SUCCESS);
225 /* Function: sdp_set_owner_version
226 * Description: Sets the value of the version parameter for the o= owner
227 * token line. The string is copied into the SDP structure
228 * so application memory will not be referenced by the SDP lib.
229 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
230 * version Ptr to the version string.
231 * Returns: SDP_SUCCESS
233 sdp_result_e sdp_set_owner_version (sdp_t *sdp_p, const char *version)
235 sstrncpy(sdp_p->owner_version, version, sizeof(sdp_p->owner_version));
236 return (SDP_SUCCESS);
239 /* Function: sdp_set_owner_network_type
240 * Description: Sets the value of the network type parameter for the o= owner
241 * token line.
242 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
243 * network_type Network type for the owner line.
244 * Returns: SDP_SUCCESS
246 sdp_result_e sdp_set_owner_network_type (sdp_t *sdp_p,
247 sdp_nettype_e network_type)
249 sdp_p->owner_network_type = network_type;
250 return (SDP_SUCCESS);
253 /* Function: sdp_set_owner_address_type
254 * Description: Sets the value of the address type parameter for the o= owner
255 * token line.
256 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
257 * address_type Address type for the owner line.
258 * Returns: SDP_SUCCESS
260 sdp_result_e sdp_set_owner_address_type (sdp_t *sdp_p,
261 sdp_addrtype_e address_type)
263 sdp_p->owner_addr_type = address_type;
264 return (SDP_SUCCESS);
267 /* Function: sdp_set_owner_address
268 * Description: Sets the value of the address parameter for the o= owner
269 * token line. The string is copied into the SDP structure
270 * so application memory will not be referenced by the SDP lib.
271 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
272 * version Ptr to the version string.
273 * Returns: SDP_SUCCESS
275 sdp_result_e sdp_set_owner_address (sdp_t *sdp_p, const char *address)
277 sstrncpy(sdp_p->owner_addr, address, sizeof(sdp_p->owner_addr));
278 return (SDP_SUCCESS);
281 /* Function: sdp_session_name_valid
282 * Description: Returns true or false depending on whether the session name
283 * s= token line has been defined for this SDP.
284 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
285 * Returns: TRUE or FALSE.
287 tinybool sdp_session_name_valid (sdp_t *sdp_p)
289 if (sdp_p->sessname[0] == '\0') {
290 return (FALSE);
291 } else {
292 return (TRUE);
296 /* Function: sdp_get_session_name
297 * Description: Returns the session name parameter from the s= session
298 * name token line. Value is returned as a const ptr and so
299 * cannot be modified by the application.
300 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
301 * Returns: Ptr to session name or NULL.
303 const char *sdp_get_session_name (sdp_t *sdp_p)
305 return (sdp_p->sessname);
308 /* Function: sdp_set_session_name
309 * Description: Sets the value of the session name parameter for the s=
310 * session name token line. The string is copied into the
311 * SDP structure so application memory will not be
312 * referenced by the SDP lib.
313 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
314 * sessname Ptr to the session name string.
315 * Returns: SDP_SUCCESS
317 sdp_result_e sdp_set_session_name (sdp_t *sdp_p, const char *sessname)
319 sstrncpy(sdp_p->sessname, sessname, sizeof(sdp_p->sessname));
320 return (SDP_SUCCESS);
323 /* Function: sdp_timespec_valid
324 * Description: Returns true or false depending on whether the timespec t=
325 * token line has been defined for this SDP.
326 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
327 * Returns: TRUE or FALSE.
329 tinybool sdp_timespec_valid (sdp_t *sdp_p)
331 if ((sdp_p->timespec_p == NULL) ||
332 (sdp_p->timespec_p->start_time[0] == '\0') ||
333 (sdp_p->timespec_p->stop_time[0] == '\0')) {
334 return (FALSE);
335 } else {
336 return (TRUE);
340 /* Function: sdp_get_time_start
341 * Description: Returns the start time parameter from the t= timespec token
342 * line. Because the value may be larger than 32 bits, this
343 * parameter is returned as a string, though has been verified
344 * to be numeric. Value is returned as a const ptr and so
345 * cannot be modified by the application.
346 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
347 * Returns: Ptr to start time or NULL.
349 const char *sdp_get_time_start (sdp_t *sdp_p)
351 if (sdp_p->timespec_p != NULL) {
352 return (sdp_p->timespec_p->start_time);
353 } else {
354 return (NULL);
358 /* Function: sdp_get_time_stop
359 * Description: Returns the stop time parameter from the t= timespec token
360 * line. Because the value may be larger than 32 bits, this
361 * parameter is returned as a string, though has been verified
362 * to be numeric. Value is returned as a const ptr and so
363 * cannot be modified by the application.
364 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
365 * Returns: Ptr to stop time or NULL.
367 const char *sdp_get_time_stop (sdp_t *sdp_p)
369 if (sdp_p->timespec_p != NULL) {
370 return (sdp_p->timespec_p->stop_time);
371 } else {
372 return (NULL);
376 /* Function: sdp_set_time_start
377 * Description: Sets the value of the start time parameter for the t=
378 * timespec token line. The string is copied into the
379 * SDP structure so application memory will not be
380 * referenced by the SDP lib.
381 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
382 * start_time Ptr to the start time string.
383 * Returns: SDP_SUCCESS
385 sdp_result_e sdp_set_time_start (sdp_t *sdp_p, const char *start_time)
387 if (sdp_p->timespec_p == NULL) {
388 sdp_p->timespec_p = (sdp_timespec_t *)SDP_MALLOC(sizeof(sdp_timespec_t));
389 if (sdp_p->timespec_p == NULL) {
390 sdp_p->conf_p->num_no_resource++;
391 return (SDP_NO_RESOURCE);
393 sdp_p->timespec_p->start_time[0] = '\0';
394 sdp_p->timespec_p->stop_time[0] = '\0';
396 sstrncpy(sdp_p->timespec_p->start_time, start_time,
397 sizeof(sdp_p->timespec_p->start_time));
398 return (SDP_SUCCESS);
401 /* Function: sdp_set_time_stop
402 * Description: Sets the value of the stop time parameter for the t=
403 * timespec token line. The string is copied into the
404 * SDP structure so application memory will not be
405 * referenced by the SDP lib.
406 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
407 * stop_time Ptr to the stop time string.
408 * Returns: SDP_SUCCESS
410 sdp_result_e sdp_set_time_stop (sdp_t *sdp_p, const char *stop_time)
412 if (sdp_p->timespec_p == NULL) {
413 sdp_p->timespec_p = (sdp_timespec_t *)SDP_MALLOC(sizeof(sdp_timespec_t));
414 if (sdp_p->timespec_p == NULL) {
415 sdp_p->conf_p->num_no_resource++;
416 return (SDP_NO_RESOURCE);
418 sdp_p->timespec_p->start_time[0] = '\0';
419 sdp_p->timespec_p->stop_time[0] = '\0';
421 sstrncpy(sdp_p->timespec_p->stop_time, stop_time,
422 sizeof(sdp_p->timespec_p->stop_time));
423 return (SDP_SUCCESS);
426 /* Function: sdp_encryption_valid
427 * Description: Returns true or false depending on whether the encryption k=
428 * token line has been defined for this SDP at the given level.
429 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
430 * level The level to check for the k= line. Will be
431 * either SDP_SESSION_LEVEL or 1-n specifying a
432 * media line level.
433 * Returns: TRUE or FALSE.
435 tinybool sdp_encryption_valid (sdp_t *sdp_p, uint16_t level)
437 sdp_encryptspec_t *encrypt_p;
438 sdp_mca_t *mca_p;
440 if (level == SDP_SESSION_LEVEL) {
441 encrypt_p = &(sdp_p->encrypt);
442 } else {
443 mca_p = sdp_find_media_level(sdp_p, level);
444 if (mca_p == NULL) {
445 return (FALSE);
447 encrypt_p = &(mca_p->encrypt);
450 if ((encrypt_p->encrypt_type == SDP_ENCRYPT_INVALID) ||
451 ((encrypt_p->encrypt_type != SDP_ENCRYPT_PROMPT) &&
452 (encrypt_p->encrypt_key[0] == '\0'))) {
453 return (FALSE);
454 } else {
455 return (TRUE);
459 /* Function: sdp_get_encryption_method
460 * Description: Returns the encryption method parameter from the k=
461 * encryption token line. If encryption method has not been
462 * set SDP_ENCRYPT_INVALID will be returned.
463 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
464 * level The level to check for the c= line. Will be
465 * either SDP_SESSION_LEVEL or 1-n specifying a
466 * media line level.
467 * Returns: Encryption method or SDP_ENCRYPT_INVALID.
469 sdp_encrypt_type_e sdp_get_encryption_method (sdp_t *sdp_p, uint16_t level)
471 sdp_encryptspec_t *encrypt_p;
472 sdp_mca_t *mca_p;
474 if (level == SDP_SESSION_LEVEL) {
475 encrypt_p = &(sdp_p->encrypt);
476 } else {
477 mca_p = sdp_find_media_level(sdp_p, level);
478 if (mca_p == NULL) {
479 return (SDP_ENCRYPT_INVALID);
481 encrypt_p = &(mca_p->encrypt);
484 return (encrypt_p->encrypt_type);
487 /* Function: sdp_get_encryption_key
488 * Description: Returns a pointer to the encryption key parameter
489 * from the k= encryption token line. Value is returned as a
490 * const ptr and so cannot be modified by the application.
491 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
492 * level The level to check for the c= line. Will be
493 * either SDP_SESSION_LEVEL or 1-n specifying a
494 * media line level.
495 * Returns: Ptr to encryption key or NULL.
497 const char *sdp_get_encryption_key (sdp_t *sdp_p, uint16_t level)
499 sdp_encryptspec_t *encrypt_p;
500 sdp_mca_t *mca_p;
502 if (level == SDP_SESSION_LEVEL) {
503 encrypt_p = &(sdp_p->encrypt);
504 } else {
505 mca_p = sdp_find_media_level(sdp_p, level);
506 if (mca_p == NULL) {
507 return (NULL);
509 encrypt_p = &(mca_p->encrypt);
512 return (encrypt_p->encrypt_key);
515 /* Function: sdp_connection_valid
516 * Description: Returns true or false depending on whether the connection c=
517 * token line has been defined for this SDP at the given level.
518 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
519 * level The level to check for the c= line. Will be
520 * either SDP_SESSION_LEVEL or 1-n specifying a
521 * media line level.
522 * Returns: TRUE or FALSE.
524 tinybool sdp_connection_valid (sdp_t *sdp_p, uint16_t level)
526 sdp_conn_t *conn_p;
527 sdp_mca_t *mca_p;
529 if (level == SDP_SESSION_LEVEL) {
530 conn_p = &(sdp_p->default_conn);
531 } else {
532 mca_p = sdp_find_media_level(sdp_p, level);
533 if (mca_p == NULL) {
534 return (FALSE);
536 conn_p = &(mca_p->conn);
539 /*if network type is ATM . then allow c= line without address type
540 * and address . This is a special case to cover PVC
542 if (conn_p->nettype == SDP_NT_ATM &&
543 conn_p->addrtype == SDP_AT_INVALID) {
544 return TRUE;
547 if ((conn_p->nettype >= SDP_MAX_NETWORK_TYPES) ||
548 (conn_p->addrtype >= SDP_MAX_ADDR_TYPES) ||
549 (conn_p->conn_addr[0] == '\0')) {
550 return (FALSE);
551 } else {
552 return (TRUE);
556 /* Function: sdp_bandwidth_valid
557 * Description: Returns true or false depending on whether the bandwidth b=
558 * token line has been defined for this SDP at the given level.
559 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
560 * level The level to check for the c= line. Will be
561 * either SDP_SESSION_LEVEL or 1-n specifying a
562 * media line level.
563 * inst_num instance number of bw line at that level. The first
564 * instance has a inst_num of 1 and so on.
565 * Returns: TRUE or FALSE.
567 tinybool sdp_bandwidth_valid (sdp_t *sdp_p, uint16_t level, uint16_t inst_num)
569 sdp_bw_data_t *bw_data_p;
571 bw_data_p = sdp_find_bw_line(sdp_p, level, inst_num);
572 if (bw_data_p != NULL) {
573 if ((bw_data_p->bw_modifier < SDP_BW_MODIFIER_AS) ||
574 (bw_data_p->bw_modifier >= SDP_MAX_BW_MODIFIER_VAL)) {
575 return FALSE;
576 } else {
577 return TRUE;
579 } else {
580 return FALSE;
585 * sdp_bw_line_exists
587 * Description: This api retruns true if there exists a bw line at the
588 * instance and level specified.
589 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
590 * level The level to check for the c= line. Will be
591 * either SDP_SESSION_LEVEL or 1-n specifying a
592 * media line level.
593 * inst_num instance number of bw line at that level. The first
594 * instance has a inst_num of 1 and so on.
595 * Returns: TRUE or FALSE
597 tinybool sdp_bw_line_exists (sdp_t *sdp_p, uint16_t level, uint16_t inst_num)
599 sdp_bw_data_t *bw_data_p;
601 bw_data_p = sdp_find_bw_line(sdp_p, level, inst_num);
602 if (bw_data_p != NULL) {
603 return TRUE;
604 } else {
605 return FALSE;
609 /* Function: sdp_get_conn_nettype
610 * Description: Returns the network type parameter from the c=
611 * connection token line. If network type has not been
612 * set SDP_NT_INVALID will be returned.
613 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
614 * level The level to check for the c= line. Will be
615 * either SDP_SESSION_LEVEL or 1-n specifying a
616 * media line level.
617 * Returns: Network type or SDP_NT_INVALID.
619 sdp_nettype_e sdp_get_conn_nettype (sdp_t *sdp_p, uint16_t level)
621 sdp_conn_t *conn_p;
622 sdp_mca_t *mca_p;
624 if (level == SDP_SESSION_LEVEL) {
625 conn_p = &(sdp_p->default_conn);
626 } else {
627 mca_p = sdp_find_media_level(sdp_p, level);
628 if (mca_p == NULL) {
629 return (SDP_NT_INVALID);
631 conn_p = &(mca_p->conn);
634 return (conn_p->nettype);
637 /* Function: sdp_get_conn_addrtype
638 * Description: Returns the address type parameter from the c=
639 * connection token line. If address type has not been
640 * set SDP_AT_INVALID will be returned.
641 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
642 * level The level to check for the c= line. Will be
643 * either SDP_SESSION_LEVEL or 1-n specifying a
644 * media line level.
645 * Returns: Address type or SDP_AT_INVALID.
647 sdp_addrtype_e sdp_get_conn_addrtype (sdp_t *sdp_p, uint16_t level)
649 sdp_conn_t *conn_p;
650 sdp_mca_t *mca_p;
652 if (level == SDP_SESSION_LEVEL) {
653 conn_p = &(sdp_p->default_conn);
654 } else {
655 mca_p = sdp_find_media_level(sdp_p, level);
656 if (mca_p == NULL) {
657 return (SDP_AT_INVALID);
659 conn_p = &(mca_p->conn);
662 return (conn_p->addrtype);
665 /* Function: sdp_get_conn_address
666 * Description: Returns a pointer to the address parameter
667 * from the c= connection token line. Value is returned as a
668 * const ptr and so cannot be modified by the application.
669 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
670 * level The level to check for the c= line. Will be
671 * either SDP_SESSION_LEVEL or 1-n specifying a
672 * media line level.
673 * Returns: Ptr to address or NULL.
675 const char *sdp_get_conn_address (sdp_t *sdp_p, uint16_t level)
677 sdp_conn_t *conn_p;
678 sdp_mca_t *mca_p;
680 if (level == SDP_SESSION_LEVEL) {
681 conn_p = &(sdp_p->default_conn);
682 } else {
683 mca_p = sdp_find_media_level(sdp_p, level);
684 if (mca_p == NULL) {
685 return (NULL);
687 conn_p = &(mca_p->conn);
690 return (conn_p->conn_addr);
693 /* Function: sdp_is_mcast_addr
694 * Description: Returns a boolean to indicate if the addr is multicast in
695 * the c=line.
696 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
697 * level The level to check for the c= line. Will be
698 * either SDP_SESSION_LEVEL or 1-n specifying a
699 * media line level.
700 * Returns: TRUE if the addr is multicast, FALSE if not.
703 tinybool sdp_is_mcast_addr (sdp_t *sdp_p, uint16_t level)
705 sdp_conn_t *conn_p;
706 sdp_mca_t *mca_p;
708 if (level == SDP_SESSION_LEVEL) {
709 conn_p = &(sdp_p->default_conn);
710 } else {
711 mca_p = sdp_find_media_level(sdp_p, level);
712 if (mca_p != NULL) {
713 conn_p = &(mca_p->conn);
714 } else {
715 return (FALSE);
719 if ((conn_p) && (conn_p->is_multicast)) {
720 return (TRUE);
721 } else {
722 return (FALSE);
726 /* Function: sdp_get_mcast_ttl
727 * Description: Get the time to live(ttl) value for the multicast address
728 * if present.
729 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
730 * level The level to check for the c= line. Will be
731 * either SDP_SESSION_LEVEL or 1-n specifying a
732 * media line level.
733 * Returns: Multicast address - Time to live (ttl) value
736 int32_t sdp_get_mcast_ttl (sdp_t *sdp_p, uint16_t level)
738 sdp_conn_t *conn_p;
739 sdp_mca_t *mca_p;
740 uint16_t ttl=0;
742 if (level == SDP_SESSION_LEVEL) {
743 conn_p = &(sdp_p->default_conn);
744 } else {
745 mca_p = sdp_find_media_level(sdp_p, level);
746 if (mca_p != NULL) {
747 conn_p = &(mca_p->conn);
748 } else {
749 return SDP_INVALID_VALUE;
753 if (conn_p) {
754 ttl = conn_p->ttl;
756 return ttl;
759 /* Function: sdp_get_mcast_num_of_addresses
760 * Description: Get the number of addresses value for the multicast address
761 * if present.
762 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
763 * level The level to check for the c= line. Will be
764 * either SDP_SESSION_LEVEL or 1-n specifying a
765 * media line level.
766 * Returns: Multicast address - number of addresses value
769 int32_t sdp_get_mcast_num_of_addresses (sdp_t *sdp_p, uint16_t level)
771 sdp_conn_t *conn_p;
772 sdp_mca_t *mca_p;
773 uint16_t num_addr = 0;
775 if (level == SDP_SESSION_LEVEL) {
776 conn_p = &(sdp_p->default_conn);
777 } else {
778 mca_p = sdp_find_media_level(sdp_p, level);
779 if (mca_p != NULL) {
780 conn_p = &(mca_p->conn);
781 } else {
782 return (SDP_INVALID_VALUE);
786 if (conn_p) {
787 num_addr = conn_p->num_of_addresses;
789 return num_addr;
791 /* Function: sdp_set_conn_nettype
792 * Description: Sets the value of the network type parameter for the c=
793 * connection token line.
794 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
795 * nettype Network type for the connection line.
796 * level The level to check for the c= line. Will be
797 * either SDP_SESSION_LEVEL or 1-n specifying a
798 * media line level.
799 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
801 sdp_result_e sdp_set_conn_nettype (sdp_t *sdp_p, uint16_t level,
802 sdp_nettype_e nettype)
804 sdp_conn_t *conn_p;
805 sdp_mca_t *mca_p;
807 if (level == SDP_SESSION_LEVEL) {
808 conn_p = &(sdp_p->default_conn);
809 } else {
810 mca_p = sdp_find_media_level(sdp_p, level);
811 if (mca_p == NULL) {
812 sdp_p->conf_p->num_invalid_param++;
813 return (SDP_INVALID_PARAMETER);
815 conn_p = &(mca_p->conn);
818 conn_p->nettype = nettype;
819 return (SDP_SUCCESS);
822 /* Function: sdp_set_conn_addrtype
823 * Description: Sets the value of the address type parameter for the c=
824 * connection token line.
825 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
826 * addrtype Address type for the connection line.
827 * level The level to check for the c= line. Will be
828 * either SDP_SESSION_LEVEL or 1-n specifying a
829 * media line level.
830 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
832 sdp_result_e sdp_set_conn_addrtype (sdp_t *sdp_p, uint16_t level,
833 sdp_addrtype_e addrtype)
835 sdp_conn_t *conn_p;
836 sdp_mca_t *mca_p;
838 if (level == SDP_SESSION_LEVEL) {
839 conn_p = &(sdp_p->default_conn);
840 } else {
841 mca_p = sdp_find_media_level(sdp_p, level);
842 if (mca_p == NULL) {
843 sdp_p->conf_p->num_invalid_param++;
844 return (SDP_INVALID_PARAMETER);
846 conn_p = &(mca_p->conn);
849 conn_p->addrtype = addrtype;
850 return (SDP_SUCCESS);
853 /* Function: sdp_set_conn_address
854 * Description: Sets the value of the address parameter for the c=
855 * connection token line. The string is copied into the
856 * SDP structure so application memory will not be
857 * referenced by the SDP lib.
858 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
859 * level The level to check for the c= line. Will be
860 * either SDP_SESSION_LEVEL or 1-n specifying a
861 * media line level.
862 * address Ptr to the address string.
863 * Returns: SDP_SUCCESS
865 sdp_result_e sdp_set_conn_address (sdp_t *sdp_p, uint16_t level,
866 const char *address)
868 sdp_conn_t *conn_p;
869 sdp_mca_t *mca_p;
871 if (level == SDP_SESSION_LEVEL) {
872 conn_p = &(sdp_p->default_conn);
873 } else {
874 mca_p = sdp_find_media_level(sdp_p, level);
875 if (mca_p == NULL) {
876 sdp_p->conf_p->num_invalid_param++;
877 return (SDP_INVALID_PARAMETER);
879 conn_p = &(mca_p->conn);
882 sstrncpy(conn_p->conn_addr, address, sizeof(conn_p->conn_addr));
883 return (SDP_SUCCESS);
886 /* Function: sdp_media_line_valid
887 * Description: Returns true or false depending on whether the specified
888 * media line m= has been defined for this SDP. The
889 * SDP_SESSION_LEVEL level is not valid for this check since,
890 * by definition, this is a media level.
891 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
892 * level The level to check for the c= line. Will be
893 * 1-n specifying a media line level.
894 * Returns: TRUE or FALSE.
896 tinybool sdp_media_line_valid (sdp_t *sdp_p, uint16_t level)
898 sdp_mca_t *mca_p;
900 mca_p = sdp_find_media_level(sdp_p, level);
901 if (mca_p == NULL) {
902 return (FALSE);
905 /* Validate params for this media line */
906 if ((mca_p->media >= SDP_MAX_MEDIA_TYPES) ||
907 (mca_p->port_format >= SDP_MAX_PORT_FORMAT_TYPES) ||
908 (mca_p->transport >= SDP_MAX_TRANSPORT_TYPES) ||
909 (mca_p->num_payloads == 0)) {
910 return (FALSE);
911 } else {
912 return (TRUE);
916 /* Function: sdp_get_num_media_lines
917 * Description: Returns the number of media lines associated with the SDP.
918 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
919 * Returns: Number of media lines.
921 uint16_t sdp_get_num_media_lines (sdp_t *sdp_p)
923 return (sdp_p->mca_count);
926 /* Function: sdp_get_media_type
927 * Description: Returns the media type parameter from the m=
928 * media token line. If media type has not been
929 * set SDP_MEDIA_INVALID will be returned.
930 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
931 * level The level to of the m= media line. Will be 1-n.
932 * Returns: Media type or SDP_MEDIA_INVALID.
934 sdp_media_e sdp_get_media_type (sdp_t *sdp_p, uint16_t level)
936 sdp_mca_t *mca_p;
938 mca_p = sdp_find_media_level(sdp_p, level);
939 if (mca_p == NULL) {
940 return (SDP_MEDIA_INVALID);
943 return (mca_p->media);
946 /* Function: sdp_get_media_line_number
947 * Description: Returns the line number in the SDP the media
948 * section starts on. Only set if SDP has been parsed
949 * (rather than built).
950 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
951 * level The level to of the m= media line. Will be 1-n.
952 * Returns: Line number (0 if not found or if locally built)
954 uint32_t sdp_get_media_line_number (sdp_t *sdp_p, uint16_t level)
956 sdp_mca_t *mca_p;
958 mca_p = sdp_find_media_level(sdp_p, level);
959 if (mca_p == NULL) {
960 return 0;
963 return (mca_p->line_number);
966 /* Function: sdp_get_media_port_format
967 * Description: Returns the port format type associated with the m=
968 * media token line. If port format type has not been
969 * set SDP_PORT_FORMAT_INVALID will be returned.
970 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
971 * level The level to of the m= media line. Will be 1-n.
972 * Returns: Port format type or SDP_PORT_FORMAT_INVALID.
974 sdp_port_format_e sdp_get_media_port_format (sdp_t *sdp_p, uint16_t level)
976 sdp_mca_t *mca_p;
978 mca_p = sdp_find_media_level(sdp_p, level);
979 if (mca_p == NULL) {
980 return (SDP_PORT_FORMAT_INVALID);
983 return (mca_p->port_format);
986 /* Function: sdp_get_media_portnum
987 * Description: Returns the port number associated with the m=
988 * media token line. If port number has not been
989 * set SDP_INVALID_VALUE will be returned.
990 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
991 * level The level to of the m= media line. Will be 1-n.
992 * Returns: Port number or SDP_INVALID_VALUE.
994 int32_t sdp_get_media_portnum (sdp_t *sdp_p, uint16_t level)
996 sdp_mca_t *mca_p;
998 mca_p = sdp_find_media_level(sdp_p, level);
999 if (mca_p == NULL) {
1000 return (SDP_INVALID_VALUE);
1003 /* Make sure port number is valid for the specified format. */
1004 if ((mca_p->port_format != SDP_PORT_NUM_ONLY) &&
1005 (mca_p->port_format != SDP_PORT_NUM_COUNT) &&
1006 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI) &&
1007 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI_CID)) {
1008 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1009 SDPLogError(logTag, "%s Port num not valid for media line %u",
1010 sdp_p->debug_str, (unsigned)level);
1012 sdp_p->conf_p->num_invalid_param++;
1013 return (SDP_INVALID_VALUE);
1016 return (mca_p->port);
1019 /* Function: sdp_get_media_portcount
1020 * Description: Returns the port count associated with the m=
1021 * media token line. If port count has not been
1022 * set SDP_INVALID_VALUE will be returned.
1023 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1024 * level The level to of the m= media line. Will be 1-n.
1025 * Returns: Port count or SDP_INVALID_VALUE.
1027 int32_t sdp_get_media_portcount (sdp_t *sdp_p, uint16_t level)
1029 sdp_mca_t *mca_p;
1031 mca_p = sdp_find_media_level(sdp_p, level);
1032 if (mca_p == NULL) {
1033 return (SDP_INVALID_VALUE);
1036 /* Make sure port number is valid for the specified format. */
1037 if (mca_p->port_format != SDP_PORT_NUM_COUNT) {
1038 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1039 SDPLogError(logTag, "%s Port count not valid for media line %u",
1040 sdp_p->debug_str, (unsigned)level);
1042 sdp_p->conf_p->num_invalid_param++;
1043 return (SDP_INVALID_VALUE);
1046 return (mca_p->num_ports);
1049 /* Function: sdp_get_media_vpi
1050 * Description: Returns the VPI parameter associated with the m=
1051 * media token line. If VPI has not been set
1052 * SDP_INVALID_VALUE will be returned.
1053 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1054 * level The level to of the m= media line. Will be 1-n.
1055 * Returns: VPI or SDP_INVALID_VALUE.
1057 int32_t sdp_get_media_vpi (sdp_t *sdp_p, uint16_t level)
1059 sdp_mca_t *mca_p;
1061 mca_p = sdp_find_media_level(sdp_p, level);
1062 if (mca_p == NULL) {
1063 return (SDP_INVALID_VALUE);
1066 /* Make sure port number is valid for the specified format. */
1067 if ((mca_p->port_format != SDP_PORT_VPI_VCI) &&
1068 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI) &&
1069 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI_CID)) {
1070 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1071 SDPLogError(logTag, "%s VPI not valid for media line %u",
1072 sdp_p->debug_str, (unsigned)level);
1074 sdp_p->conf_p->num_invalid_param++;
1075 return (SDP_INVALID_VALUE);
1078 return (mca_p->vpi);
1081 /* Function: sdp_get_media_vci
1082 * Description: Returns the VCI parameter associated with the m=
1083 * media token line. If VCI has not been set
1084 * SDP_INVALID_VALUE will be returned.
1085 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1086 * level The level to of the m= media line. Will be 1-n.
1087 * Returns: VCI or zero.
1089 uint32_t sdp_get_media_vci (sdp_t *sdp_p, uint16_t level)
1091 sdp_mca_t *mca_p;
1093 mca_p = sdp_find_media_level(sdp_p, level);
1094 if (mca_p == NULL) {
1095 return (0);
1098 /* Make sure port number is valid for the specified format. */
1099 if ((mca_p->port_format != SDP_PORT_VPI_VCI) &&
1100 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI) &&
1101 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI_CID)) {
1102 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1103 SDPLogError(logTag, "%s VCI not valid for media line %u",
1104 sdp_p->debug_str, (unsigned)level);
1106 sdp_p->conf_p->num_invalid_param++;
1107 return (0);
1110 return (mca_p->vci);
1113 /* Function: sdp_get_media_vcci
1114 * Description: Returns the VCCI parameter associated with the m=
1115 * media token line. If VCCI has not been set
1116 * SDP_INVALID_VALUE will be returned.
1117 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1118 * level The level to of the m= media line. Will be 1-n.
1119 * Returns: VCCI or SDP_INVALID_VALUE.
1121 int32_t sdp_get_media_vcci (sdp_t *sdp_p, uint16_t level)
1123 sdp_mca_t *mca_p;
1125 mca_p = sdp_find_media_level(sdp_p, level);
1126 if (mca_p == NULL) {
1127 return (SDP_INVALID_VALUE);
1130 /* Make sure port number is valid for the specified format. */
1131 if ((mca_p->port_format != SDP_PORT_VCCI) &&
1132 (mca_p->port_format != SDP_PORT_VCCI_CID)) {
1133 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1134 SDPLogError(logTag, "%s VCCI not valid for media line %u",
1135 sdp_p->debug_str, (unsigned)level);
1137 sdp_p->conf_p->num_invalid_param++;
1138 return (SDP_INVALID_VALUE);
1141 return (mca_p->vcci);
1144 /* Function: sdp_get_media_cid
1145 * Description: Returns the CID parameter associated with the m=
1146 * media token line. If CID has not been set
1147 * SDP_INVALID_VALUE will be returned.
1148 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1149 * level The level to of the m= media line. Will be 1-n.
1150 * Returns: CID or SDP_INVALID_VALUE.
1152 int32_t sdp_get_media_cid (sdp_t *sdp_p, uint16_t level)
1154 sdp_mca_t *mca_p;
1156 mca_p = sdp_find_media_level(sdp_p, level);
1157 if (mca_p == NULL) {
1158 return (SDP_INVALID_VALUE);
1161 /* Make sure port number is valid for the specified format. */
1162 if ((mca_p->port_format != SDP_PORT_VCCI_CID) &&
1163 (mca_p->port_format != SDP_PORT_NUM_VPI_VCI_CID)) {
1164 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1165 SDPLogError(logTag, "%s CID not valid for media line %u",
1166 sdp_p->debug_str, (unsigned)level);
1168 sdp_p->conf_p->num_invalid_param++;
1169 return (SDP_INVALID_VALUE);
1172 return (mca_p->cid);
1175 /* Function: sdp_get_media_transport
1176 * Description: Returns the transport type parameter associated with the m=
1177 * media token line. If transport type has not been set
1178 * SDP_TRANSPORT_INVALID will be returned. If the transport
1179 * type is one of the AAL2 variants, the profile routines below
1180 * should be used to access multiple profile types and payload
1181 * lists per m= line.
1182 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1183 * level The level to of the m= media line. Will be 1-n.
1184 * Returns: CID or SDP_TRANSPORT_INVALID.
1186 sdp_transport_e sdp_get_media_transport (sdp_t *sdp_p, uint16_t level)
1188 sdp_mca_t *mca_p;
1190 mca_p = sdp_find_media_level(sdp_p, level);
1191 if (mca_p == NULL) {
1192 return (SDP_TRANSPORT_INVALID);
1195 return (mca_p->transport);
1198 /* Function: sdp_get_media_num_profiles
1199 * Description: Returns the number of profiles associated with the m=
1200 * media token line. If the media line is invalid, zero will
1201 * be returned. Application must validate the media line
1202 * before using this routine. Multiple profile types per
1203 * media line is currently only used for AAL2. If the appl
1204 * detects that the transport type is one of the AAL2 types,
1205 * it should use these profile access routines to access the
1206 * profile types and payload list for each.
1207 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1208 * level The level to of the m= media line. Will be 1-n.
1209 * Returns: Number of profiles or zero.
1211 uint16_t sdp_get_media_num_profiles (sdp_t *sdp_p, uint16_t level)
1213 sdp_mca_t *mca_p;
1215 mca_p = sdp_find_media_level(sdp_p, level);
1216 if (mca_p == NULL) {
1217 return (0);
1220 if (mca_p->media_profiles_p == NULL) {
1221 return (0);
1222 } else {
1223 return (mca_p->media_profiles_p->num_profiles);
1227 /* Function: sdp_get_media_profile
1228 * Description: Returns the specified profile type associated with the m=
1229 * media token line. If the media line or profile number is
1230 * invalid, SDP_TRANSPORT_INVALID will be returned.
1231 * Applications must validate the media line before using this
1232 * routine.
1233 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1234 * level The level to of the m= media line. Will be 1-n.
1235 * profile_num The specific profile type number to be retrieved.
1236 * Returns: The profile type or SDP_TRANSPORT_INVALID.
1238 sdp_transport_e sdp_get_media_profile (sdp_t *sdp_p, uint16_t level,
1239 uint16_t profile_num)
1241 sdp_mca_t *mca_p;
1243 mca_p = sdp_find_media_level(sdp_p, level);
1244 if (mca_p == NULL) {
1245 return (SDP_TRANSPORT_INVALID);
1248 if ((profile_num < 1) ||
1249 (profile_num > mca_p->media_profiles_p->num_profiles)) {
1250 return (SDP_TRANSPORT_INVALID);
1251 } else {
1252 return (mca_p->media_profiles_p->profile[profile_num-1]);
1256 /* Function: sdp_get_media_num_payload_types
1257 * Description: Returns the number of payload types associated with the m=
1258 * media token line. If the media line is invalid, zero will
1259 * be returned. Application must validate the media line
1260 * before using this routine.
1261 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1262 * level The level to of the m= media line. Will be 1-n.
1263 * Returns: Number of payload types or zero.
1265 uint16_t sdp_get_media_num_payload_types (sdp_t *sdp_p, uint16_t level)
1267 sdp_mca_t *mca_p;
1269 mca_p = sdp_find_media_level(sdp_p, level);
1270 if (mca_p == NULL) {
1271 return (0);
1274 return (mca_p->num_payloads);
1277 /* Function: sdp_get_media_profile_num_payload_types
1278 * Description: Returns the number of payload types associated with the
1279 * specified profile on the m= media token line. If the
1280 * media line or profile number is invalid, zero will
1281 * be returned. Application must validate the media line
1282 * and profile before using this routine.
1283 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1284 * level The level to of the m= media line. Will be 1-n.
1285 * profile_num The specific profile number. Will be 1-n.
1286 * Returns: Number of payload types or zero.
1288 uint16_t sdp_get_media_profile_num_payload_types (sdp_t *sdp_p, uint16_t level,
1289 uint16_t profile_num)
1291 sdp_mca_t *mca_p;
1293 mca_p = sdp_find_media_level(sdp_p, level);
1294 if (mca_p == NULL) {
1295 return (0);
1298 if ((profile_num < 1) ||
1299 (profile_num > mca_p->media_profiles_p->num_profiles)) {
1300 return (0);
1301 } else {
1302 return (mca_p->media_profiles_p->num_payloads[profile_num-1]);
1306 rtp_ptype sdp_get_known_payload_type(sdp_t *sdp_p,
1307 uint16_t level,
1308 uint16_t payload_type_raw) {
1309 sdp_attr_t *attr_p;
1310 sdp_transport_map_t *rtpmap;
1311 uint16_t pack_mode = 0; /*default 0, if remote did not provide any */
1312 const char *encname = NULL;
1313 uint16_t num_a_lines = 0;
1314 int i;
1317 * Get number of RTPMAP attributes for the media line
1319 (void) sdp_attr_num_instances(sdp_p, level, 0, SDP_ATTR_RTPMAP,
1320 &num_a_lines);
1323 * Loop through media line RTPMAP attributes.
1325 for (i = 0; i < num_a_lines; i++) {
1326 attr_p = sdp_find_attr(sdp_p, level, 0, SDP_ATTR_RTPMAP, (i + 1));
1327 if (attr_p == NULL) {
1328 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1329 SDPLogError(logTag, "%s rtpmap attribute, level %u instance %u "
1330 "not found.",
1331 sdp_p->debug_str,
1332 (unsigned)level,
1333 (unsigned)(i + 1));
1335 sdp_p->conf_p->num_invalid_param++;
1336 return (RTP_NONE);
1339 rtpmap = &(attr_p->attr.transport_map);
1341 if (rtpmap->payload_num == payload_type_raw) {
1342 encname = rtpmap->encname;
1343 if (encname) {
1344 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_ILBC) == 0) {
1345 return (RTP_ILBC);
1347 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_L16_256K) == 0) {
1348 return (RTP_L16);
1350 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_ISAC) == 0) {
1351 return (RTP_ISAC);
1353 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_OPUS) == 0) {
1354 return (RTP_OPUS);
1356 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_PCMU) == 0) {
1357 return (RTP_PCMU);
1359 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_PCMA) == 0) {
1360 return (RTP_PCMA);
1362 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_G722) == 0) {
1363 return (RTP_G722);
1365 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_H264) == 0) {
1366 int fmtp_inst = sdp_find_fmtp_inst(sdp_p, level, rtpmap->payload_num);
1367 if (fmtp_inst < 0) {
1368 return (RTP_H264_P0);
1369 } else {
1370 sdp_attr_get_fmtp_pack_mode(sdp_p, level, 0, (uint16_t) fmtp_inst, &pack_mode);
1371 if (pack_mode == SDP_DEFAULT_PACKETIZATION_MODE_VALUE) {
1372 return (RTP_H264_P0);
1373 } else {
1374 return (RTP_H264_P1);
1378 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_VP8) == 0) {
1379 return (RTP_VP8);
1381 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_VP9) == 0) {
1382 return (RTP_VP9);
1384 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_RED) == 0) {
1385 return (RTP_RED);
1387 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_ULPFEC) == 0) {
1388 return (RTP_ULPFEC);
1390 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_TELEPHONE_EVENT) == 0) {
1391 return (RTP_TELEPHONE_EVENT);
1393 if (cpr_strcasecmp(encname, SIPSDP_ATTR_ENCNAME_RTX) == 0) {
1394 return (RTP_RTX);
1400 return (RTP_NONE);
1403 /* Function: sdp_get_media_payload_type
1404 * Description: Returns the payload type of the specified payload for the m=
1405 * media token line. If the media line or payload number is
1406 * invalid, zero will be returned. Application must validate
1407 * the media line before using this routine.
1408 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1409 * level The level to of the m= media line. Will be 1-n.
1410 * payload_num Number of the payload type to retrieve. The
1411 * range is (1 - max num payloads).
1412 * indicator Returns the type of payload returned, either
1413 * NUMERIC or ENUM.
1414 * Returns: Payload type or zero.
1416 uint32_t sdp_get_media_payload_type (sdp_t *sdp_p, uint16_t level, uint16_t payload_num,
1417 sdp_payload_ind_e *indicator)
1419 sdp_mca_t *mca_p;
1420 rtp_ptype ptype;
1422 mca_p = sdp_find_media_level(sdp_p, level);
1423 if (mca_p == NULL) {
1424 return (0);
1427 if ((payload_num < 1) || (payload_num > mca_p->num_payloads)) {
1428 return (0);
1431 *indicator = mca_p->payload_indicator[payload_num-1];
1432 if ((mca_p->payload_type[payload_num-1] >= SDP_MIN_DYNAMIC_PAYLOAD) &&
1433 (mca_p->payload_type[payload_num-1] <= SDP_MAX_DYNAMIC_PAYLOAD)) {
1434 ptype = sdp_get_known_payload_type(sdp_p,
1435 level,
1436 mca_p->payload_type[payload_num-1]);
1437 if (ptype != RTP_NONE) {
1438 return (SET_PAYLOAD_TYPE_WITH_DYNAMIC(
1439 mca_p->payload_type[payload_num-1], ptype));
1443 return (mca_p->payload_type[payload_num-1]);
1446 /* Function: sdp_get_media_profile_payload_type
1447 * Description: Returns the payload type of the specified payload for the m=
1448 * media token line. If the media line or payload number is
1449 * invalid, zero will be returned. Application must validate
1450 * the media line before using this routine.
1451 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1452 * level The level to of the m= media line. Will be 1-n.
1453 * payload_num Number of the payload type to retrieve. The
1454 * range is (1 - max num payloads).
1455 * indicator Returns the type of payload returned, either
1456 * NUMERIC or ENUM.
1457 * Returns: Payload type or zero.
1459 uint32_t sdp_get_media_profile_payload_type (sdp_t *sdp_p, uint16_t level, uint16_t prof_num,
1460 uint16_t payload_num,
1461 sdp_payload_ind_e *indicator)
1463 sdp_mca_t *mca_p;
1464 sdp_media_profiles_t *prof_p;
1466 mca_p = sdp_find_media_level(sdp_p, level);
1467 if (mca_p == NULL) {
1468 return (0);
1471 prof_p = mca_p->media_profiles_p;
1472 if ((prof_num < 1) ||
1473 (prof_num > prof_p->num_profiles)) {
1474 return (0);
1477 if ((payload_num < 1) ||
1478 (payload_num > prof_p->num_payloads[prof_num-1])) {
1479 return (0);
1482 *indicator = prof_p->payload_indicator[prof_num-1][payload_num-1];
1483 return (prof_p->payload_type[prof_num-1][payload_num-1]);
1486 /* Function: sdp_insert_media_line
1487 * Description: Insert a new media line at the level specified for the
1488 * given SDP.
1489 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1490 * level The new media level to insert. Will be 1-n.
1491 * Returns: SDP_SUCCESS, SDP_NO_RESOURCE, or SDP_INVALID_PARAMETER
1493 sdp_result_e sdp_insert_media_line (sdp_t *sdp_p, uint16_t level)
1495 sdp_mca_t *mca_p;
1496 sdp_mca_t *new_mca_p;
1498 if ((level < 1) || (level > (sdp_p->mca_count+1))) {
1499 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1500 SDPLogError(logTag, "%s Invalid media line (%u) to insert, max is "
1501 "(%u).", sdp_p->debug_str, (unsigned)level, (unsigned)sdp_p->mca_count);
1503 sdp_p->conf_p->num_invalid_param++;
1504 return (SDP_INVALID_PARAMETER);
1507 /* Allocate resource for new media stream. */
1508 new_mca_p = sdp_alloc_mca(0);
1509 if (new_mca_p == NULL) {
1510 sdp_p->conf_p->num_no_resource++;
1511 return (SDP_NO_RESOURCE);
1514 if (level == 1) {
1515 /* We're inserting the first media line */
1516 new_mca_p->next_p = sdp_p->mca_p;
1517 sdp_p->mca_p = new_mca_p;
1518 } else {
1519 /* Find the pointer to the media stream just prior to where
1520 * we want to insert the new stream.
1522 mca_p = sdp_find_media_level(sdp_p, (uint16_t)(level-1));
1523 if (mca_p == NULL) {
1524 SDP_FREE(new_mca_p);
1525 sdp_p->conf_p->num_invalid_param++;
1526 return (SDP_INVALID_PARAMETER);
1529 new_mca_p->next_p = mca_p->next_p;
1530 mca_p->next_p = new_mca_p;
1533 sdp_p->mca_count++;
1534 return (SDP_SUCCESS);
1537 /* Function: sdp_set_media_type
1538 * Description: Sets the value of the media type parameter for the m=
1539 * media token line.
1540 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1541 * level The media level to set the param. Will be 1-n.
1542 * media Media type for the media line.
1543 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
1545 sdp_result_e sdp_set_media_type (sdp_t *sdp_p, uint16_t level, sdp_media_e media)
1547 sdp_mca_t *mca_p;
1549 mca_p = sdp_find_media_level(sdp_p, level);
1550 if (mca_p == NULL) {
1551 sdp_p->conf_p->num_invalid_param++;
1552 return (SDP_INVALID_PARAMETER);
1555 mca_p->media = media;
1556 return (SDP_SUCCESS);
1559 /* Function: sdp_set_media_portnum
1560 * Description: Sets the value of the port number parameter for the m=
1561 * media token line. If the port number is not valid with the
1562 * port format specified for the media line, this call will
1563 * fail.
1564 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1565 * level The media level to set the param. Will be 1-n.
1566 * portnum Port number to set.
1567 * sctpport sctp port for application m= line
1568 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
1570 sdp_result_e sdp_set_media_portnum (sdp_t *sdp_p, uint16_t level, int32_t portnum, int32_t sctp_port)
1572 sdp_mca_t *mca_p;
1574 mca_p = sdp_find_media_level(sdp_p, level);
1575 if (mca_p == NULL) {
1576 sdp_p->conf_p->num_invalid_param++;
1577 return (SDP_INVALID_PARAMETER);
1580 mca_p->port = portnum;
1581 mca_p->sctpport = sctp_port;
1582 return (SDP_SUCCESS);
1585 /* Function: sdp_get_media_sctp_port
1586 * Description: Gets the value of the sctp port number parameter for the m=
1587 * media token line.
1588 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1589 * level The media level to set the param. Will be 1-n.
1590 * Returns: sctp_port or -1 on failure
1592 int32_t sdp_get_media_sctp_port(sdp_t *sdp_p, uint16_t level)
1594 sdp_mca_t *mca_p;
1596 mca_p = sdp_find_media_level(sdp_p, level);
1597 if (!mca_p) {
1598 sdp_p->conf_p->num_invalid_param++;
1599 return -1;
1602 return mca_p->sctpport;
1605 sdp_sctp_media_fmt_type_e sdp_get_media_sctp_fmt(sdp_t *sdp_p, uint16_t level)
1607 sdp_mca_t *mca_p;
1609 mca_p = sdp_find_media_level(sdp_p, level);
1610 if (!mca_p) {
1611 sdp_p->conf_p->num_invalid_param++;
1612 return -1;
1615 return mca_p->sctp_fmt;
1618 /* Function: sdp_set_media_transport
1619 * Description: Sets the value of the transport type parameter for the m=
1620 * media token line.
1621 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1622 * level The media level to set the param. Will be 1-n.
1623 * transport The transport type to set.
1624 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
1626 sdp_result_e sdp_set_media_transport (sdp_t *sdp_p, uint16_t level,
1627 sdp_transport_e transport)
1629 sdp_mca_t *mca_p;
1631 mca_p = sdp_find_media_level(sdp_p, level);
1632 if (mca_p == NULL) {
1633 sdp_p->conf_p->num_invalid_param++;
1634 return (SDP_INVALID_PARAMETER);
1637 mca_p->transport = transport;
1638 return (SDP_SUCCESS);
1641 /* Function: sdp_add_media_profile
1642 * Description: Add a new profile type for the m= media token line. This is
1643 * used for AAL2 transport/profile types where more than one can
1644 * be specified per media line. All other transport types should
1645 * use the other transport access routines rather than this.
1646 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1647 * level The media level to add the param. Will be 1-n.
1648 * profile The profile type to add.
1649 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
1651 sdp_result_e sdp_add_media_profile (sdp_t *sdp_p, uint16_t level,
1652 sdp_transport_e profile)
1654 uint16_t prof_num;
1655 sdp_mca_t *mca_p;
1657 mca_p = sdp_find_media_level(sdp_p, level);
1658 if (mca_p == NULL) {
1659 sdp_p->conf_p->num_invalid_param++;
1660 return (SDP_INVALID_PARAMETER);
1663 if (mca_p->media_profiles_p == NULL) {
1664 mca_p->media_profiles_p = (sdp_media_profiles_t *) \
1665 SDP_MALLOC(sizeof(sdp_media_profiles_t));
1666 if (mca_p->media_profiles_p == NULL) {
1667 sdp_p->conf_p->num_no_resource++;
1668 return (SDP_NO_RESOURCE);
1669 } else {
1670 mca_p->media_profiles_p->num_profiles = 0;
1671 /* Set the transport type to this first profile type. */
1672 mca_p->transport = profile;
1676 if (mca_p->media_profiles_p->num_profiles >= SDP_MAX_PROFILES) {
1677 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1678 SDPLogError(logTag, "%s Max number of media profiles already specified"
1679 " for media level %u", sdp_p->debug_str, (unsigned)level);
1681 sdp_p->conf_p->num_invalid_param++;
1682 return (SDP_INVALID_PARAMETER);
1685 prof_num = mca_p->media_profiles_p->num_profiles++;
1686 mca_p->media_profiles_p->profile[prof_num] = profile;
1687 mca_p->media_profiles_p->num_payloads[prof_num] = 0;
1688 return (SDP_SUCCESS);
1691 /* Function: sdp_add_media_payload_type
1692 * Description: Add a new payload type for the media line at the level
1693 * specified. The new payload type will be added at the end
1694 * of the payload type list.
1695 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1696 * level The media level to add the payload. Will be 1-n.
1697 * payload_type The new payload type.
1698 * indicator Defines the type of payload returned, either
1699 * NUMERIC or ENUM.
1700 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
1702 sdp_result_e sdp_add_media_payload_type (sdp_t *sdp_p, uint16_t level,
1703 uint16_t payload_type,
1704 sdp_payload_ind_e indicator)
1706 sdp_mca_t *mca_p;
1708 mca_p = sdp_find_media_level(sdp_p, level);
1709 if (mca_p == NULL) {
1710 sdp_p->conf_p->num_invalid_param++;
1711 return (SDP_INVALID_PARAMETER);
1714 if (mca_p->num_payloads == SDP_MAX_PAYLOAD_TYPES) {
1715 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1716 SDPLogError(logTag, "%s Max number of payload types already defined "
1717 "for media line %u", sdp_p->debug_str, (unsigned)level);
1719 sdp_p->conf_p->num_invalid_param++;
1720 return (SDP_INVALID_PARAMETER);
1723 mca_p->payload_indicator[mca_p->num_payloads] = indicator;
1724 mca_p->payload_type[mca_p->num_payloads++] = payload_type;
1725 return (SDP_SUCCESS);
1728 /* Function: sdp_add_media_profile_payload_type
1729 * Description: Add a new payload type for the media line at the level
1730 * specified. The new payload type will be added at the end
1731 * of the payload type list.
1732 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1733 * level The media level to add the payload. Will be 1-n.
1734 * prof_num The profile number to add the payload type.
1735 * payload_type The new payload type.
1736 * indicator Defines the type of payload returned, either
1737 * NUMERIC or ENUM.
1738 * Returns: SDP_SUCCESS or SDP_INVALID_PARAMETER
1740 sdp_result_e sdp_add_media_profile_payload_type (sdp_t *sdp_p, uint16_t level,
1741 uint16_t prof_num, uint16_t payload_type,
1742 sdp_payload_ind_e indicator)
1744 uint16_t num_payloads;
1745 sdp_mca_t *mca_p;
1747 mca_p = sdp_find_media_level(sdp_p, level);
1748 if (mca_p == NULL) {
1749 sdp_p->conf_p->num_invalid_param++;
1750 return (SDP_INVALID_PARAMETER);
1753 if ((prof_num < 1) ||
1754 (prof_num > mca_p->media_profiles_p->num_profiles)) {
1755 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1756 SDPLogError(logTag, "%s Invalid profile number (%u) for set profile "
1757 " payload type", sdp_p->debug_str, (unsigned)level);
1759 sdp_p->conf_p->num_invalid_param++;
1760 return (SDP_INVALID_PARAMETER);
1763 if (mca_p->media_profiles_p->num_payloads[prof_num-1] ==
1764 SDP_MAX_PAYLOAD_TYPES) {
1765 if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1766 SDPLogError(logTag, "%s Max number of profile payload types already "
1767 "defined profile %u on media line %u",
1768 sdp_p->debug_str, (unsigned)prof_num, (unsigned)level);
1770 sdp_p->conf_p->num_invalid_param++;
1771 return (SDP_INVALID_PARAMETER);
1774 /* Get the current num payloads for this profile, and inc the number
1775 * of payloads at the same time. Then store the new payload type. */
1776 num_payloads = mca_p->media_profiles_p->num_payloads[prof_num-1]++;
1777 mca_p->media_profiles_p->payload_indicator[prof_num-1][num_payloads] =
1778 indicator;
1779 mca_p->media_profiles_p->payload_type[prof_num-1][num_payloads] =
1780 payload_type;
1781 return (SDP_SUCCESS);
1785 * sdp_find_bw_line
1787 * This helper function locates a specific bw line instance given the
1788 * sdp, the level and the instance number of the bw line.
1790 * Returns: Pointer to the sdp_bw_data_t instance, or NULL.
1792 sdp_bw_data_t* sdp_find_bw_line (sdp_t *sdp_p, uint16_t level, uint16_t inst_num)
1794 sdp_bw_t *bw_p;
1795 sdp_bw_data_t *bw_data_p;
1796 sdp_mca_t *mca_p;
1797 int bw_attr_count=0;
1799 if (level == SDP_SESSION_LEVEL) {
1800 bw_p = &(sdp_p->bw);
1801 } else {
1802 mca_p = sdp_find_media_level(sdp_p, level);
1803 if (mca_p == NULL) {
1804 sdp_p->conf_p->num_invalid_param++;
1805 return (NULL);
1807 bw_p = &(mca_p->bw);
1810 for (bw_data_p = bw_p->bw_data_list;
1811 bw_data_p != NULL;
1812 bw_data_p = bw_data_p->next_p) {
1813 bw_attr_count++;
1814 if (bw_attr_count == inst_num) {
1815 return bw_data_p;
1819 return NULL;
1823 * sdp_copy_all_bw_lines
1825 * Appends all the bw lines from the specified level of the orig sdp to the
1826 * specified level of the dst sdp.
1828 * Parameters: src_sdp_p The source SDP handle.
1829 * dst_sdp_p The dest SDP handle.
1830 * src_level The level in the src sdp from where to get the
1831 * attributes.
1832 * dst_level The level in the dst sdp where to put the
1833 * attributes.
1834 * Returns: SDP_SUCCESS Attributes were successfully copied.
1836 sdp_result_e sdp_copy_all_bw_lines (sdp_t *src_sdp_p, sdp_t *dst_sdp_p,
1837 uint16_t src_level, uint16_t dst_level)
1839 sdp_bw_data_t *orig_bw_data_p;
1840 sdp_bw_data_t *new_bw_data_p;
1841 sdp_bw_data_t *bw_data_p;
1842 sdp_bw_t *src_bw_p;
1843 sdp_bw_t *dst_bw_p;
1844 sdp_mca_t *mca_p;
1846 /* Find src bw list */
1847 if (src_level == SDP_SESSION_LEVEL) {
1848 src_bw_p = &(src_sdp_p->bw);
1849 } else {
1850 mca_p = sdp_find_media_level(src_sdp_p, src_level);
1851 if (mca_p == NULL) {
1852 if (src_sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1853 SDPLogError(logTag, "%s Invalid src media level (%u) for copy all "
1854 "attrs ", src_sdp_p->debug_str, (unsigned)src_level);
1856 return (SDP_INVALID_PARAMETER);
1858 src_bw_p = &(mca_p->bw);
1861 /* Find dst bw list */
1862 if (dst_level == SDP_SESSION_LEVEL) {
1863 dst_bw_p = &(dst_sdp_p->bw);
1864 } else {
1865 mca_p = sdp_find_media_level(dst_sdp_p, dst_level);
1866 if (mca_p == NULL) {
1867 if (src_sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
1868 SDPLogError(logTag, "%s Invalid dst media level (%u) for copy all "
1869 "attrs ", src_sdp_p->debug_str, (unsigned)dst_level);
1871 return (SDP_INVALID_PARAMETER);
1873 dst_bw_p = &(mca_p->bw);
1876 orig_bw_data_p = src_bw_p->bw_data_list;
1877 while (orig_bw_data_p) {
1878 /* For ever bw line in the src, allocate a new one for the dst */
1879 new_bw_data_p = (sdp_bw_data_t*)SDP_MALLOC(sizeof(sdp_bw_data_t));
1880 if (new_bw_data_p == NULL) {
1881 return (SDP_NO_RESOURCE);
1883 new_bw_data_p->next_p = NULL;
1884 new_bw_data_p->bw_modifier = orig_bw_data_p->bw_modifier;
1885 new_bw_data_p->bw_val = orig_bw_data_p->bw_val;
1888 * Enqueue the sdp_bw_data_t instance at the end of the list of
1889 * sdp_bw_data_t instances.
1891 if (dst_bw_p->bw_data_list == NULL) {
1892 dst_bw_p->bw_data_list = new_bw_data_p;
1893 } else {
1894 for (bw_data_p = dst_bw_p->bw_data_list;
1895 bw_data_p->next_p != NULL;
1896 bw_data_p = bw_data_p->next_p) {
1898 /*sa_ignore EMPTYLOOP*/
1899 ; /* Do nothing. */
1902 bw_data_p->next_p = new_bw_data_p;
1904 dst_bw_p->bw_data_count++;
1906 orig_bw_data_p = orig_bw_data_p->next_p;
1909 return (SDP_SUCCESS);
1912 /* Function: sdp_get_bw_modifier
1913 * Description: Returns the bandwidth modifier parameter from the b=
1914 * line. If no bw modifier has been set ,
1915 * SDP_BW_MODIFIER_UNSUPPORTED will be returned.
1916 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1917 * level The level from which to get the bw modifier.
1918 * inst_num instance number of bw line at that level. The first
1919 * instance has a inst_num of 1 and so on.
1920 * Returns: Valid modifer value or SDP_BW_MODIFIER_UNSUPPORTED.
1922 sdp_bw_modifier_e sdp_get_bw_modifier (sdp_t *sdp_p, uint16_t level, uint16_t inst_num)
1924 sdp_bw_data_t *bw_data_p;
1926 bw_data_p = sdp_find_bw_line(sdp_p, level, inst_num);
1928 if (bw_data_p) {
1929 return (bw_data_p->bw_modifier);
1930 } else {
1931 return (SDP_BW_MODIFIER_UNSUPPORTED);
1935 /* Function: sdp_get_bw_value
1936 * Description: Returns the bandwidth value parameter from the b=
1937 * line.
1938 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1939 * level The level from which to get the bw value.
1940 * inst_num instance number of bw line at the level. The first
1941 * instance has a inst_num of 1 and so on.
1942 * Returns: A valid numerical bw value or SDP_INVALID_VALUE.
1944 int32_t sdp_get_bw_value (sdp_t *sdp_p, uint16_t level, uint16_t inst_num)
1946 sdp_bw_data_t *bw_data_p;
1948 bw_data_p = sdp_find_bw_line(sdp_p, level, inst_num);
1950 if (bw_data_p) {
1951 return (bw_data_p->bw_val);
1952 } else {
1953 return (SDP_INVALID_VALUE);
1958 * sdp_get_num_bw_lines
1960 * Returns the number of bw lines are present at a given level.
1962 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
1963 * level The level at which the count of bw lines is required
1965 * Returns: A valid count or SDP_INVALID_VALUE
1967 int32_t sdp_get_num_bw_lines (sdp_t *sdp_p, uint16_t level)
1969 sdp_bw_t *bw_p;
1970 sdp_mca_t *mca_p;
1972 if (level == SDP_SESSION_LEVEL) {
1973 bw_p = &(sdp_p->bw);
1974 } else {
1975 mca_p = sdp_find_media_level(sdp_p, level);
1976 if (mca_p == NULL) {
1977 sdp_p->conf_p->num_invalid_param++;
1978 return (SDP_INVALID_VALUE);
1980 bw_p = &(mca_p->bw);
1983 return (bw_p->bw_data_count);
1987 * sdp_add_new_bw_line
1989 * To specify bandwidth parameters at any level, a bw line must first be
1990 * added at that level using this function. After this addition, you can set
1991 * the properties of the added bw line by using sdp_set_bw().
1993 * Note carefully though, that since there can be multiple instances of bw
1994 * lines at any level, you must specify the instance number when setting
1995 * or getting the properties of a bw line at any level.
1997 * This function returns within the inst_num variable, the instance number
1998 * of the created bw_line at that level. The instance number is 1-based.
1999 * For example:
2000 * v=0 #Session Level
2001 * o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4
2002 * s=SDP Seminar
2003 * c=IN IP4 10.1.0.2
2004 * t=0 0
2005 * b=AS:60 # instance number 1
2006 * b=TIAS:50780 # instance number 2
2007 * m=audio 1234 RTP/AVP 0 101 102 # 1st Media level
2008 * b=AS:12 # instance number 1
2009 * b=TIAS:8480 # instance number 2
2010 * m=audio 1234 RTP/AVP 0 101 102 # 2nd Media level
2011 * b=AS:20 # instance number 1
2013 * Parameters:
2014 * sdp_p The SDP handle returned by sdp_init_description.
2015 * level The level to create the bw line.
2016 * bw_modifier The Type of bandwidth, CT, AS or TIAS.
2017 * *inst_num This memory is set with the instance number of the newly
2018 * created bw line instance.
2020 sdp_result_e sdp_add_new_bw_line (sdp_t *sdp_p, uint16_t level, sdp_bw_modifier_e bw_modifier, uint16_t *inst_num)
2022 sdp_bw_t *bw_p;
2023 sdp_mca_t *mca_p;
2024 sdp_bw_data_t *new_bw_data_p;
2025 sdp_bw_data_t *bw_data_p = NULL;
2027 *inst_num = 0;
2029 if (level == SDP_SESSION_LEVEL) {
2030 bw_p = &(sdp_p->bw);
2031 } else {
2032 mca_p = sdp_find_media_level(sdp_p, level);
2033 if (mca_p == NULL) {
2034 sdp_p->conf_p->num_invalid_param++;
2035 return (SDP_INVALID_PARAMETER);
2037 bw_p = &(mca_p->bw);
2040 //see if a bw line already exist for this bw_modifier.
2041 for(bw_data_p = bw_p->bw_data_list; bw_data_p != NULL; bw_data_p = bw_data_p->next_p) {
2042 ++(*inst_num);
2043 if (bw_data_p->bw_modifier == bw_modifier) {
2044 return (SDP_SUCCESS);
2049 * Allocate a new sdp_bw_data_t instance and set it's values from the
2050 * input parameters.
2052 new_bw_data_p = (sdp_bw_data_t*)SDP_MALLOC(sizeof(sdp_bw_data_t));
2053 if (new_bw_data_p == NULL) {
2054 sdp_p->conf_p->num_no_resource++;
2055 return (SDP_NO_RESOURCE);
2057 new_bw_data_p->next_p = NULL;
2058 new_bw_data_p->bw_modifier = SDP_BW_MODIFIER_UNSUPPORTED;
2059 new_bw_data_p->bw_val = 0;
2062 * Enqueue the sdp_bw_data_t instance at the end of the list of
2063 * sdp_bw_data_t instances.
2065 if (bw_p->bw_data_list == NULL) {
2066 bw_p->bw_data_list = new_bw_data_p;
2067 } else {
2068 for (bw_data_p = bw_p->bw_data_list;
2069 bw_data_p->next_p != NULL;
2070 bw_data_p = bw_data_p->next_p) {
2072 /*sa_ignore EMPTYLOOP*/
2073 ; /* Do nothing. */
2076 bw_data_p->next_p = new_bw_data_p;
2078 *inst_num = ++bw_p->bw_data_count;
2080 return (SDP_SUCCESS);
2083 /* Function: sdp_get_mid_value
2084 * Description: Returns the mid value parameter from the a= mid: line.
2085 * Parameters: sdp_p The SDP handle returned by sdp_init_description.
2086 * level SDP_MEDIA_LEVEL
2087 * Returns: mid value.
2089 int32_t sdp_get_mid_value (sdp_t *sdp_p, uint16_t level)
2091 sdp_mca_t *mca_p;
2093 mca_p = sdp_find_media_level(sdp_p, level);
2094 if (mca_p == NULL) {
2095 sdp_p->conf_p->num_invalid_param++;
2096 return (SDP_INVALID_VALUE);
2098 return (mca_p->mid);