From 73d27ee642ce2afa8d691ae3a1907afd9df8c140 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 26 May 2010 17:23:32 +0000 Subject: Re #1066, in process_m_answer() of sdp_neg.c: - Fixed removing any unmatching formats in the remote-answer to also work with dynamic payload type. - Updated reordering formats priority in the offer based on the answer to also work with dynamic payload type. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3187 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/src/pjmedia/sdp_neg.c | 75 +++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 28 deletions(-) (limited to 'pjmedia') diff --git a/pjmedia/src/pjmedia/sdp_neg.c b/pjmedia/src/pjmedia/sdp_neg.c index c7341386..2fb9bdc9 100644 --- a/pjmedia/src/pjmedia/sdp_neg.c +++ b/pjmedia/src/pjmedia/sdp_neg.c @@ -815,6 +815,9 @@ static pj_status_t process_m_answer( pj_pool_t *pool, PJ_TODO(CHECK_SDP_NEGOTIATION_WHEN_ASYMETRIC_MEDIA_IS_ALLOWED); } else { + /* Offer format priority based on answer format index/priority */ + unsigned offer_fmt_prior[PJMEDIA_MAX_SDP_FMT]; + /* Remove all format in the offer that has no matching answer */ for (i=0; idesc.fmt_count;) { unsigned pt; @@ -907,6 +910,7 @@ static pj_status_t process_m_answer( pj_pool_t *pool, --offer->desc.fmt_count; } else { + offer_fmt_prior[i] = j; ++i; } } @@ -916,40 +920,55 @@ static pj_status_t process_m_answer( pj_pool_t *pool, return PJMEDIA_SDPNEG_EANSNOMEDIA; } - /* Arrange format in the offer so the order match the priority - * in the answer + /* Post process: + * - Resort offer formats so the order match to the answer. + * - Remove answer formats that unmatches to the offer. */ - for (i=0; idesc.fmt_count; ++i) { + + /* Resort offer formats */ + for (i=0; idesc.fmt_count; ++i) { unsigned j; - pj_str_t *fmt = &answer->desc.fmt[i]; - - for (j=i; jdesc.fmt_count; ++j) { - if (pj_strcmp(fmt, &offer->desc.fmt[j])==0) { + for (j=i+1; jdesc.fmt_count; ++j) { + if (offer_fmt_prior[i] > offer_fmt_prior[j]) { + unsigned tmp = offer_fmt_prior[i]; + offer_fmt_prior[i] = offer_fmt_prior[j]; + offer_fmt_prior[j] = tmp; str_swap(&offer->desc.fmt[i], &offer->desc.fmt[j]); - break; } } + } - /* If this answer format has no matching format, let's remove it - * from the answer. - */ - if (j >= offer->desc.fmt_count) { - pjmedia_sdp_attr *a; - - /* Remove rtpmap associated with this format */ - a = pjmedia_sdp_media_find_attr2(answer, "rtpmap", fmt); - if (a) - pjmedia_sdp_media_remove_attr(answer, a); - - /* Remove fmtp associated with this format */ - a = pjmedia_sdp_media_find_attr2(answer, "fmtp", fmt); - if (a) - pjmedia_sdp_media_remove_attr(answer, a); - - /* Remove this format from answer's array */ - pj_array_erase(answer->desc.fmt, sizeof(answer->desc.fmt[0]), - answer->desc.fmt_count, i); - --answer->desc.fmt_count; + /* Remove unmatched answer formats */ + { + unsigned del_cnt = 0; + for (i=0; idesc.fmt_count;) { + /* The offer is ordered now, also the offer_fmt_prior */ + if (i >= offer->desc.fmt_count || + offer_fmt_prior[i]-del_cnt != i) + { + pj_str_t *fmt = &answer->desc.fmt[i]; + pjmedia_sdp_attr *a; + + /* Remove rtpmap associated with this format */ + a = pjmedia_sdp_media_find_attr2(answer, "rtpmap", fmt); + if (a) + pjmedia_sdp_media_remove_attr(answer, a); + + /* Remove fmtp associated with this format */ + a = pjmedia_sdp_media_find_attr2(answer, "fmtp", fmt); + if (a) + pjmedia_sdp_media_remove_attr(answer, a); + + /* Remove this format from answer's array */ + pj_array_erase(answer->desc.fmt, + sizeof(answer->desc.fmt[0]), + answer->desc.fmt_count, i); + --answer->desc.fmt_count; + + ++del_cnt; + } else { + ++i; + } } } } -- cgit v1.2.3