summaryrefslogtreecommitdiff
path: root/pjmedia/src
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2010-05-26 17:23:32 +0000
committerNanang Izzuddin <nanang@teluu.com>2010-05-26 17:23:32 +0000
commit73d27ee642ce2afa8d691ae3a1907afd9df8c140 (patch)
tree2aa2b4f2e7c61e467610f8a311d69e9630676a39 /pjmedia/src
parentc33b86ab93c77d9e3599d1fb8f535e382c517b18 (diff)
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
Diffstat (limited to 'pjmedia/src')
-rw-r--r--pjmedia/src/pjmedia/sdp_neg.c75
1 files changed, 47 insertions, 28 deletions
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; i<offer->desc.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; i<answer->desc.fmt_count; ++i) {
+
+ /* Resort offer formats */
+ for (i=0; i<offer->desc.fmt_count; ++i) {
unsigned j;
- pj_str_t *fmt = &answer->desc.fmt[i];
-
- for (j=i; j<offer->desc.fmt_count; ++j) {
- if (pj_strcmp(fmt, &offer->desc.fmt[j])==0) {
+ for (j=i+1; j<offer->desc.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; i<answer->desc.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;
+ }
}
}
}