Changeset 5135 for pjproject/trunk
- Timestamp:
- Jul 14, 2015 8:38:29 AM (9 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r5127 r5135 1140 1140 } 1141 1141 1142 1143 /* Go through the list of media in the call, find acceptable media, and 1144 * sort them based on the "quality" of the media, and store the indexes 1145 * in the specified array. Media with the best quality will be listed 1146 * first in the array. 1147 */ 1148 static void sort_media2(const pjsua_call_media *call_med, 1149 unsigned call_med_cnt, 1150 pjmedia_type type, 1151 pj_uint8_t midx[], 1152 unsigned *p_count, 1153 unsigned *p_total_count) 1154 { 1155 unsigned i; 1156 unsigned count = 0; 1157 int score[PJSUA_MAX_CALL_MEDIA]; 1158 1159 pj_assert(*p_count >= PJSUA_MAX_CALL_MEDIA); 1160 pj_assert(*p_total_count >= PJSUA_MAX_CALL_MEDIA); 1161 1162 *p_count = 0; 1163 *p_total_count = 0; 1164 for (i=0; i<PJSUA_MAX_CALL_MEDIA; ++i) 1165 score[i] = 1; 1166 1167 /* Score each media */ 1168 for (i=0; i<call_med_cnt && count<PJSUA_MAX_CALL_MEDIA; ++i) { 1169 1170 /* Skip different media */ 1171 if (call_med[i].type != type) { 1172 score[count++] = -22000; 1173 continue; 1174 } 1175 1176 /* Is it active? */ 1177 if (!call_med[i].tp) { 1178 score[i] -= 10; 1179 } 1180 1181 ++count; 1182 } 1183 1184 /* Created sorted list based on quality */ 1185 for (i=0; i<count; ++i) { 1186 unsigned j; 1187 int best = 0; 1188 1189 for (j=1; j<count; ++j) { 1190 if (score[j] > score[best]) 1191 best = j; 1192 } 1193 /* Don't put media with negative score, that media is unacceptable 1194 * for us. 1195 */ 1196 midx[i] = (pj_uint8_t)best; 1197 if (score[best] >= 0) 1198 (*p_count)++; 1199 if (score[best] > -22000) 1200 (*p_total_count)++; 1201 1202 score[best] = -22000; 1203 1204 } 1205 } 1206 1207 1142 1208 /* Callback to receive media events */ 1143 1209 pj_status_t call_media_on_event(pjmedia_event *event, … … 1529 1595 1530 1596 1531 /* If idx == 0, clean up media transports in provisional media that 1532 * is not used by call media, else clean up media transports starting 1533 * from index idx that have been removed by remote. 1597 /* Clean up media transports in provisional media that is not used by 1598 * call media. 1534 1599 */ 1535 static void media_prov_clean_up(pjsua_call_id call_id, int idx)1600 void pjsua_media_prov_clean_up(pjsua_call_id call_id) 1536 1601 { 1537 1602 pjsua_call *call = &pjsua_var.calls[call_id]; 1538 1603 unsigned i; 1539 1604 1540 if ( idx > 0 ||call->med_prov_cnt > call->med_cnt) {1605 if (call->med_prov_cnt > call->med_cnt) { 1541 1606 PJ_LOG(4,(THIS_FILE, "Call %d: cleaning up provisional media, " 1542 1607 "prov_med_cnt=%d, med_cnt=%d", 1543 call_id, (idx == 0? call->med_prov_cnt: idx), 1544 call->med_cnt)); 1545 } 1546 1547 for (i = idx; i < call->med_prov_cnt; ++i) { 1608 call_id, call->med_prov_cnt, call->med_cnt)); 1609 } 1610 1611 for (i = 0; i < call->med_prov_cnt; ++i) { 1548 1612 pjsua_call_media *call_med = &call->media_prov[i]; 1549 1613 unsigned j; … … 1554 1618 1555 1619 for (j = 0; j < call->med_cnt; ++j) { 1556 if ( idx == 0 &&call->media[j].tp == call_med->tp) {1620 if (call->media[j].tp == call_med->tp) { 1557 1621 used = PJ_TRUE; 1558 1622 break; … … 1572 1636 1573 1637 call->med_prov_cnt = 0; 1574 }1575 1576 void pjsua_media_prov_clean_up(pjsua_call_id call_id)1577 {1578 media_prov_clean_up(call_id, 0);1579 1638 } 1580 1639 … … 1665 1724 /* Get media count for each media type */ 1666 1725 if (rem_sdp) { 1726 1727 /* We are sending answer, check media count for each media type 1728 * from the remote SDP. 1729 */ 1667 1730 sort_media(rem_sdp, &STR_AUDIO, acc->cfg.use_srtp, 1668 1731 maudidx, &maudcnt, &mtotaudcnt); … … 1696 1759 } else { 1697 1760 1698 /* If call already established, calculate media count from current 1699 * local active SDP and call setting. Otherwise, calculate media 1700 * count from the call setting only. 1761 /* If call is already established, adjust the existing call media list 1762 * to media count setting in call setting, e.g: re-enable/disable/add 1763 * media from existing media. 1764 * Otherwise, apply media count from the call setting directly. 1701 1765 */ 1702 1766 if (reinit) { 1703 const pjmedia_sdp_session *sdp; 1704 1705 status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &sdp); 1706 pj_assert(status == PJ_SUCCESS); 1707 1708 sort_media(sdp, &STR_AUDIO, acc->cfg.use_srtp, 1709 maudidx, &maudcnt, &mtotaudcnt); 1767 1768 /* We are sending reoffer, check media count for each media type 1769 * from the existing call media list. 1770 */ 1771 sort_media2(call->media_prov, call->med_prov_cnt, 1772 PJMEDIA_TYPE_AUDIO, maudidx, &maudcnt, &mtotaudcnt); 1710 1773 pj_assert(maudcnt > 0); 1711 1774 1712 sort_media (sdp, &STR_VIDEO, acc->cfg.use_srtp,1713 1775 sort_media2(call->media_prov, call->med_prov_cnt, 1776 PJMEDIA_TYPE_VIDEO, mvididx, &mvidcnt, &mtotvidcnt); 1714 1777 1715 1778 /* Call setting may add or remove media. Adding media is done by … … 1856 1919 } 1857 1920 1858 /* Put media type just for info */ 1859 call_med->type = media_type; 1921 /* Put media type just for info if not yet defined */ 1922 if (call_med->type == PJMEDIA_TYPE_NONE) 1923 call_med->type = media_type; 1860 1924 } 1861 1925 } … … 1992 2056 if (rem_sdp && mi >= rem_sdp->media_count) { 1993 2057 /* Remote might have removed some media lines. */ 1994 for (i = rem_sdp->media_count; i < call->med_prov_cnt; ++i) { 1995 stop_media_stream(call, i); 1996 } 1997 media_prov_clean_up(call->index, rem_sdp->media_count); 1998 call->med_prov_cnt = rem_sdp->media_count; 2058 /* Note that we must not modify the current active media 2059 * (e.g: stop stream, close/cleanup media transport), as if 2060 * SDP nego fails, the current active media should be maintained. 2061 * Also note that our media count should never decrease, even when 2062 * remote removed some media lines. 2063 */ 1999 2064 break; 2000 2065 } … … 2990 3055 sizeof(call->media_prov[0]) * call->med_prov_cnt); 2991 3056 2992 /* Perform SDP re-negotiation if needed. */ 3057 /* Perform SDP re-negotiation if some media have just got disabled 3058 * in this function due to media count limit settings. 3059 */ 2993 3060 if (got_media && need_renego_sdp) { 2994 3061 pjmedia_sdp_neg *neg = call->inv->neg;
Note: See TracChangeset
for help on using the changeset viewer.