Changeset 2236 for pjproject/trunk/pjmedia/src/pjmedia/session.c
- Timestamp:
- Aug 25, 2008 1:58:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/session.c
r2153 r2236 68 68 69 69 /* 70 * Get fmtp mode parameter associated with the codec. 71 */ 72 static pj_status_t get_fmtp_mode(const pjmedia_sdp_media *m, 73 const pj_str_t *fmt, 74 int *p_mode) 70 * Parse fmtp for specified format/payload type. 71 */ 72 static void parse_fmtp( pj_pool_t *pool, 73 const pjmedia_sdp_media *m, 74 unsigned pt, 75 pjmedia_codec_fmtp *fmtp) 75 76 { 76 77 const pjmedia_sdp_attr *attr; 77 pjmedia_sdp_fmtp fmtp; 78 const pj_str_t str_mode = { "mode=", 5 }; 79 char *pos; 78 pjmedia_sdp_fmtp sdp_fmtp; 79 char *p, *p_end, fmt_buf[8]; 80 pj_str_t fmt; 81 82 pj_assert(m && fmtp); 83 84 pj_bzero(fmtp, sizeof(pjmedia_codec_fmtp)); 80 85 81 86 /* Get "fmtp" attribute for the format */ 82 attr = pjmedia_sdp_media_find_attr2(m, "fmtp", fmt); 87 pj_ansi_sprintf(fmt_buf, "%d", pt); 88 fmt = pj_str(fmt_buf); 89 attr = pjmedia_sdp_media_find_attr2(m, "fmtp", &fmt); 83 90 if (attr == NULL) 84 return -1;91 return; 85 92 86 93 /* Parse "fmtp" attribute */ 87 if (pjmedia_sdp_attr_get_fmtp(attr, &fmtp) != PJ_SUCCESS) 88 return -1; 89 90 /* Look for "mode=" string in the fmtp */ 91 while (fmtp.fmt_param.slen >= str_mode.slen + 1) { 92 if (pj_strnicmp(&fmtp.fmt_param, &str_mode, str_mode.slen)==0) { 93 /* Found "mode=" string */ 94 if (pjmedia_sdp_attr_get_fmtp(attr, &sdp_fmtp) != PJ_SUCCESS) 95 return; 96 97 /* Prepare parsing */ 98 p = sdp_fmtp.fmt_param.ptr; 99 p_end = p + sdp_fmtp.fmt_param.slen; 100 101 /* Parse */ 102 while (p < p_end) { 103 char *token, *start, *end; 104 105 /* Skip whitespaces */ 106 while (p < p_end && (*p == ' ' || *p == '\t')) ++p; 107 if (p == p_end) 94 108 break; 95 } 96 97 fmtp.fmt_param.ptr++; 98 fmtp.fmt_param.slen--; 99 } 100 101 if (fmtp.fmt_param.slen < str_mode.slen + 1) { 102 /* "mode=" param not found */ 103 return -1; 104 } 105 106 /* Get the mode */ 107 pos = fmtp.fmt_param.ptr + str_mode.slen; 108 *p_mode = 0; 109 while (pj_isdigit(*pos)) { 110 *p_mode = *p_mode * 10 + (*pos - '0'); 111 ++pos; 112 } 113 114 return PJ_SUCCESS; 109 110 /* Get token */ 111 start = p; 112 while (p < p_end && *p != ';' && *p != '=') ++p; 113 end = p - 1; 114 115 /* Right trim */ 116 while (end >= start && (*end == ' ' || *end == '\t' || 117 *end == '\r' || *end == '\n' )) 118 --end; 119 120 /* Forward a char after trimming */ 121 ++end; 122 123 /* Store token */ 124 if (end > start) { 125 token = (char*)pj_pool_alloc(pool, end - start); 126 pj_ansi_strncpy(token, start, end - start); 127 if (*p == '=') 128 /* Got param name */ 129 pj_strset(&fmtp->param[fmtp->cnt].name, token, end - start); 130 else 131 /* Got param value */ 132 pj_strset(&fmtp->param[fmtp->cnt++].val, token, end - start); 133 } else if (*p != '=') { 134 ++fmtp->cnt; 135 } 136 137 /* Next */ 138 ++p; 139 } 115 140 } 116 141 … … 136 161 pj_sockaddr local_addr; 137 162 pjmedia_sdp_rtpmap *rtpmap; 138 int local_fmtp_mode = 0, rem_fmtp_mode = 0;139 163 unsigned i, pt, fmti; 140 164 pj_status_t status; … … 401 425 #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG != 0) 402 426 /* The session info should have the actual clock rate, because 403 * this info is used for calculationg buffer size, etc in stream */ 427 * this info is used for calculationg buffer size, etc in stream 428 */ 404 429 if (si->fmt.pt == PJMEDIA_RTP_PT_G722) 405 430 si->fmt.clock_rate = 16000; … … 464 489 } 465 490 466 /* Get fmtp mode= param in local SDP, if any */467 get_fmtp_mode(local_m, &local_m->desc.fmt[fmti], &local_fmtp_mode);468 469 491 /* Determine payload type for outgoing channel, by finding 470 492 * dynamic payload type in remote SDP that matches the answer. … … 494 516 si->tx_pt = rpt; 495 517 496 /* Get fmtp mode param in remote SDP, if any */497 get_fmtp_mode(rem_m, &rtpmap->pt, &rem_fmtp_mode);498 499 518 break; 500 519 } … … 509 528 si->param = PJ_POOL_ALLOC_T(pool, pjmedia_codec_param); 510 529 status = pjmedia_codec_mgr_get_default_param(mgr, &si->fmt, si->param); 530 531 /* Get remote fmtp for our encoder. */ 532 parse_fmtp(pool, rem_m, si->tx_pt, &si->param->setting.enc_fmtp); 533 534 /* Get local fmtp for our decoder. */ 535 parse_fmtp(pool, local_m, si->fmt.pt, &si->param->setting.dec_fmtp); 536 537 /* Get remote maxptime for our encoder. */ 538 attr = pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr, 539 "maxptime", NULL); 540 if (attr) { 541 pj_str_t tmp_val = attr->value; 542 543 pj_strltrim(&tmp_val); 544 si->tx_maxptime = pj_strtoul(&tmp_val); 545 } 511 546 512 547 /* When direction is NONE (it means SDP negotiation has failed) we don't … … 520 555 return status; 521 556 522 /* Set fmtp mode for both local and remote */523 if (local_fmtp_mode != 0)524 si->param->setting.dec_fmtp_mode = (pj_int8_t)local_fmtp_mode;525 if (rem_fmtp_mode != 0)526 si->param->setting.enc_fmtp_mode = (pj_int8_t)rem_fmtp_mode;527 528 557 529 558 /* Get incomming payload type for telephone-events */
Note: See TracChangeset
for help on using the changeset viewer.