From 9944702e692e3dc8ab6afb53c78c1e66da6bff9f Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Fri, 27 Jan 2012 09:12:59 +0000 Subject: Re #1244: Added bandwidth info in SDP ("b=" lines) based on codec bitrate settings. Two SDP bandwidth types/modifiers are used: AS in session level & TIAS in media level. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3945 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsua-lib/pjsua_media.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'pjsip/src/pjsua-lib/pjsua_media.c') diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index 66cecf58..917dadcb 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -1938,6 +1938,7 @@ pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, pjsua_call *call = &pjsua_var.calls[call_id]; pjmedia_sdp_neg_state sdp_neg_state = PJMEDIA_SDP_NEG_STATE_NULL; unsigned mi; + unsigned tot_bandw_tias = 0; pj_status_t status; if (pjsua_get_state() != PJSUA_STATE_RUNNING) @@ -2011,6 +2012,7 @@ pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, pjsua_call_media *call_med = &call->media[mi]; pjmedia_sdp_media *m = NULL; pjmedia_transport_info tpinfo; + unsigned i; if (rem_sdp && mi >= rem_sdp->media_count) { /* Remote might have removed some media lines. */ @@ -2108,6 +2110,17 @@ pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, if (sdp->conn == NULL) { sdp->conn = pjmedia_sdp_conn_clone(pool, m->conn); } + + + /* Find media bandwidth info */ + for (i = 0; i < m->bandw_count; ++i) { + const pj_str_t STR_BANDW_MODIFIER_TIAS = { "TIAS", 4 }; + if (!pj_stricmp(&m->bandw[i]->modifier, &STR_BANDW_MODIFIER_TIAS)) + { + tot_bandw_tias += m->bandw[i]->value; + break; + } + } } /* Add NAT info in the SDP */ @@ -2135,6 +2148,26 @@ pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, } + /* Add bandwidth info in session level using bandwidth modifier "AS". */ + if (tot_bandw_tias) { + unsigned bandw; + const pj_str_t STR_BANDW_MODIFIER_AS = { "AS", 2 }; + pjmedia_sdp_bandw *b; + + /* AS bandwidth = RTP bitrate + RTCP bitrate. + * RTP bitrate = payload bitrate (total TIAS) + overheads (~16kbps). + * RTCP bitrate = est. 5% of RTP bitrate. + * Note that AS bandwidth is in kbps. + */ + bandw = tot_bandw_tias + 16000; + bandw += bandw * 5 / 100; + b = PJ_POOL_ALLOC_T(pool, pjmedia_sdp_bandw); + b->modifier = STR_BANDW_MODIFIER_AS; + b->value = bandw / 1000; + sdp->bandw[sdp->bandw_count++] = b; + } + + #if DISABLED_FOR_TICKET_1185 && defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) /* Check if SRTP is in optional mode and configured to use duplicated * media, i.e: secured and unsecured version, in the SDP offer. -- cgit v1.2.3