Changeset 3837 for pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c
- Timestamp:
- Oct 23, 2011 6:59:48 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c
r3714 r3837 1121 1121 } 1122 1122 1123 1124 /* Internal function to rewrite the format string in SDP attribute rtpmap 1125 * and fmtp. 1126 */ 1127 PJ_INLINE(void) rewrite_pt(pj_pool_t *pool, pj_str_t *attr_val, 1128 const pj_str_t *old_pt, const pj_str_t *new_pt) 1129 { 1130 int len_diff = new_pt->slen - old_pt->slen; 1131 1132 /* Note that attribute value should be null-terminated. */ 1133 if (len_diff > 0) { 1134 pj_str_t new_val; 1135 new_val.ptr = (char*)pj_pool_alloc(pool, attr_val->slen+len_diff+1); 1136 new_val.slen = attr_val->slen + len_diff; 1137 pj_memcpy(new_val.ptr + len_diff, attr_val->ptr, attr_val->slen + 1); 1138 *attr_val = new_val; 1139 } else if (len_diff < 0) { 1140 pj_memmove(attr_val->ptr, attr_val->ptr - len_diff, 1141 attr_val->slen + len_diff + 1); 1142 } 1143 pj_memcpy(attr_val->ptr, new_pt->ptr, new_pt->slen); 1144 } 1145 1146 1147 /* Internal function to apply symmetric PT for the local answer. */ 1148 static void apply_answer_symmetric_pt(pj_pool_t *pool, 1149 pjmedia_sdp_media *answer, 1150 unsigned pt_cnt, 1151 const pj_str_t pt_offer[], 1152 const pj_str_t pt_answer[]) 1153 { 1154 pjmedia_sdp_attr *a_tmp[PJMEDIA_MAX_SDP_ATTR]; 1155 unsigned i, a_tmp_cnt = 0; 1156 1157 /* Rewrite the payload types in the answer if different to 1158 * the ones in the offer. 1159 */ 1160 for (i = 0; i < pt_cnt; ++i) { 1161 pjmedia_sdp_attr *a; 1162 1163 /* Skip if the PTs are the same already, e.g: static PT. */ 1164 if (pj_strcmp(&pt_answer[i], &pt_offer[i]) == 0) 1165 continue; 1166 1167 /* Rewrite payload type in the answer to match to the offer */ 1168 pj_strdup(pool, &answer->desc.fmt[i], &pt_offer[i]); 1169 1170 /* Also update payload type in rtpmap */ 1171 a = pjmedia_sdp_media_find_attr2(answer, "rtpmap", &pt_answer[i]); 1172 if (a) { 1173 rewrite_pt(pool, &a->value, &pt_answer[i], &pt_offer[i]); 1174 /* Temporarily remove the attribute in case the new payload 1175 * type is being used by another format in the media. 1176 */ 1177 pjmedia_sdp_media_remove_attr(answer, a); 1178 a_tmp[a_tmp_cnt++] = a; 1179 } 1180 1181 /* Also update payload type in fmtp */ 1182 a = pjmedia_sdp_media_find_attr2(answer, "fmtp", &pt_answer[i]); 1183 if (a) { 1184 rewrite_pt(pool, &a->value, &pt_answer[i], &pt_offer[i]); 1185 /* Temporarily remove the attribute in case the new payload 1186 * type is being used by another format in the media. 1187 */ 1188 pjmedia_sdp_media_remove_attr(answer, a); 1189 a_tmp[a_tmp_cnt++] = a; 1190 } 1191 } 1192 1193 /* Return back 'rtpmap' and 'fmtp' attributes */ 1194 for (i = 0; i < a_tmp_cnt; ++i) 1195 pjmedia_sdp_media_add_attr(answer, a_tmp[i]); 1196 } 1197 1198 1123 1199 /* Try to match offer with answer. */ 1124 1200 static pj_status_t match_offer(pj_pool_t *pool, … … 1138 1214 unsigned pt_answer_count = 0; 1139 1215 pj_str_t pt_answer[PJMEDIA_MAX_SDP_FMT]; 1216 pj_str_t pt_offer[PJMEDIA_MAX_SDP_FMT]; 1140 1217 pjmedia_sdp_media *answer; 1141 1218 const pjmedia_sdp_media *master, *slave; … … 1202 1279 if (p == pt && pj_isdigit(*slave->desc.fmt[j].ptr)) { 1203 1280 found_matching_codec = 1; 1281 pt_offer[pt_answer_count] = slave->desc.fmt[j]; 1204 1282 pt_answer[pt_answer_count++] = slave->desc.fmt[j]; 1205 1283 break; … … 1301 1379 } 1302 1380 1381 pt_offer[pt_answer_count] = 1382 prefer_remote_codec_order? 1383 offer->desc.fmt[i]: 1384 offer->desc.fmt[j]; 1303 1385 pt_answer[pt_answer_count++] = 1304 1386 prefer_remote_codec_order? … … 1326 1408 /* Match */ 1327 1409 found_matching_other = 1; 1410 pt_offer[pt_answer_count] = prefer_remote_codec_order? 1411 offer->desc.fmt[i]: 1412 offer->desc.fmt[j]; 1328 1413 pt_answer[pt_answer_count++] = prefer_remote_codec_order? 1329 1414 preanswer->desc.fmt[j]: … … 1390 1475 } 1391 1476 answer->desc.fmt_count = pt_answer_count; 1477 1478 #if PJMEDIA_SDP_NEG_ANSWER_SYMMETRIC_PT 1479 apply_answer_symmetric_pt(pool, answer, pt_answer_count, 1480 pt_offer, pt_answer); 1481 #endif 1392 1482 1393 1483 /* Update media direction. */
Note: See TracChangeset
for help on using the changeset viewer.