Changeset 2191
- Timestamp:
- Aug 4, 2008 3:01:38 PM (16 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r2176 r2191 2211 2211 ring_stop(call_id); 2212 2212 2213 if (call_info.media_status == PJSUA_CALL_MEDIA_ACTIVE) { 2213 /* Connect ports appropriately when media status is ACTIVE or REMOTE HOLD, 2214 * otherwise we should NOT connect the ports. 2215 */ 2216 if (call_info.media_status == PJSUA_CALL_MEDIA_ACTIVE || 2217 call_info.media_status == PJSUA_CALL_MEDIA_REMOTE_HOLD) 2218 { 2214 2219 pj_bool_t connect_sound = PJ_TRUE; 2215 2220 … … 2279 2284 } 2280 2285 } 2281 2286 } 2287 2288 /* Handle media status */ 2289 switch (call_info.media_status) { 2290 case PJSUA_CALL_MEDIA_ACTIVE: 2282 2291 PJ_LOG(3,(THIS_FILE, "Media for call %d is active", call_id)); 2283 2284 } else if (call_info.media_status == PJSUA_CALL_MEDIA_LOCAL_HOLD) { 2292 break; 2293 2294 case PJSUA_CALL_MEDIA_LOCAL_HOLD: 2285 2295 PJ_LOG(3,(THIS_FILE, "Media for call %d is suspended (hold) by local", 2286 2296 call_id)); 2287 } else if (call_info.media_status == PJSUA_CALL_MEDIA_REMOTE_HOLD) { 2297 break; 2298 2299 case PJSUA_CALL_MEDIA_REMOTE_HOLD: 2288 2300 PJ_LOG(3,(THIS_FILE, 2289 2301 "Media for call %d is suspended (hold) by remote", 2290 2302 call_id)); 2291 } else if (call_info.media_status == PJSUA_CALL_MEDIA_ERROR) { 2292 pj_str_t reason = pj_str("ICE negotiation failed"); 2293 2294 PJ_LOG( 1,(THIS_FILE,2303 break; 2304 2305 case PJSUA_CALL_MEDIA_ERROR: 2306 PJ_LOG(3,(THIS_FILE, 2295 2307 "Media has reported error, disconnecting call")); 2296 2297 pjsua_call_hangup(call_id, 500, &reason, NULL); 2298 2299 } else { 2308 { 2309 pj_str_t reason = pj_str("ICE negotiation failed"); 2310 pjsua_call_hangup(call_id, 500, &reason, NULL); 2311 } 2312 break; 2313 2314 case PJSUA_CALL_MEDIA_NONE: 2300 2315 PJ_LOG(3,(THIS_FILE, 2301 2316 "Media for call %d is inactive", 2302 2317 call_id)); 2318 break; 2319 2320 default: 2321 pj_assert(!"Unhandled media status"); 2322 break; 2303 2323 } 2304 2324 } -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r2162 r2191 61 61 pjsua_acc_id acc_id; /**< Account index being used. */ 62 62 int secure_level;/**< Signaling security level. */ 63 pj_bool_t local_hold;/**< Flag for call-hold by local. */ 63 64 pjsua_call_media_status media_st;/**< Media state. */ 64 65 pjmedia_dir media_dir; /**< Media direction. */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
r2152 r2191 67 67 68 68 69 70 /* Create inactive SDP for call hold. */ 71 static pj_status_t create_inactive_sdp(pjsua_call *call, 72 pjmedia_sdp_session **p_answer); 69 /* Create SDP for call hold. */ 70 static pj_status_t create_sdp_of_call_hold(pjsua_call *call, 71 pjmedia_sdp_session **p_answer); 73 72 74 73 /* Update SDP version in the offer */ … … 118 117 call->rem_nat_type = PJ_STUN_NAT_TYPE_UNKNOWN; 119 118 call->rem_srtp_use = PJMEDIA_SRTP_DISABLED; 119 call->local_hold = PJ_FALSE; 120 120 } 121 121 … … 1427 1427 } 1428 1428 1429 status = create_ inactive_sdp(call, &sdp);1429 status = create_sdp_of_call_hold(call, &sdp); 1430 1430 if (status != PJ_SUCCESS) { 1431 1431 pjsip_dlg_dec_lock(dlg); … … 1453 1453 return status; 1454 1454 } 1455 1456 /* Set flag that local put the call on hold */ 1457 call->local_hold = PJ_TRUE; 1455 1458 1456 1459 pjsip_dlg_dec_lock(dlg); … … 1488 1491 1489 1492 /* Create SDP */ 1490 PJ_UNUSED_ARG(unhold); 1491 PJ_TODO(create_active_inactive_sdp_based_on_unhold_arg); 1492 status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 1493 NULL, &sdp, NULL); 1493 if (call->local_hold && !unhold) { 1494 status = create_sdp_of_call_hold(call, &sdp); 1495 } else { 1496 status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 1497 NULL, &sdp, NULL); 1498 call->local_hold = PJ_FALSE; 1499 } 1494 1500 if (status != PJ_SUCCESS) { 1495 1501 pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", … … 1574 1580 status = pjsip_inv_send_msg( call->inv, tdata); 1575 1581 if (status != PJ_SUCCESS) { 1576 pjsua_perror(THIS_FILE, "Unable to send UPDAT Erequest", status);1582 pjsua_perror(THIS_FILE, "Unable to send UPDATE request", status); 1577 1583 pjsip_dlg_dec_lock(dlg); 1578 1584 return status; 1579 1585 } 1586 1587 call->local_hold = PJ_FALSE; 1580 1588 1581 1589 pjsip_dlg_dec_lock(dlg); … … 3013 3021 3014 3022 3015 /* 3016 * Create inactive SDP for call hold. 3017 */ 3018 static pj_status_t create_inactive_sdp(pjsua_call *call, 3019 pjmedia_sdp_session **p_answer) 3023 /* Create SDP for call hold. */ 3024 static pj_status_t create_sdp_of_call_hold(pjsua_call *call, 3025 pjmedia_sdp_session **p_answer) 3020 3026 { 3021 3027 pj_status_t status; 3022 3028 pj_pool_t *pool; 3023 pjmedia_sdp_conn *conn;3024 pjmedia_sdp_attr *attr;3025 pjmedia_transport_info tp_info;3026 3029 pjmedia_sdp_session *sdp; 3027 3030 … … 3029 3032 pool = call->inv->pool; 3030 3033 3031 /* Get media socket info */3032 pjmedia_transport_info_init(&tp_info);3033 pjmedia_transport_get_info(call->med_tp, &tp_info);3034 3035 3034 /* Create new offer */ 3036 status = pj media_endpt_create_sdp(pjsua_var.med_endpt, pool, 1,3037 &tp_info.sock_info, &sdp);3035 status = pjsua_media_channel_create_sdp(call->index, pool, NULL, &sdp, 3036 NULL); 3038 3037 if (status != PJ_SUCCESS) { 3039 3038 pjsua_perror(THIS_FILE, "Unable to create local SDP", status); … … 3041 3040 } 3042 3041 3043 /* Get SDP media connection line */ 3044 conn = sdp->media[0]->conn; 3045 if (!conn) 3046 conn = sdp->conn; 3047 3048 /* Modify address */ 3049 conn->addr = pj_str("0.0.0.0"); 3050 3051 /* Remove existing directions attributes */ 3052 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "sendrecv"); 3053 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "sendonly"); 3054 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "recvonly"); 3055 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "inactive"); 3056 3057 /* Add inactive attribute */ 3058 attr = pjmedia_sdp_attr_create(pool, "inactive", NULL); 3059 pjmedia_sdp_media_add_attr(sdp->media[0], attr); 3042 /* Call-hold is done by set the media direction to 'sendonly' 3043 * (PJMEDIA_DIR_ENCODING), except when current media direction is 3044 * 'inactive' (PJMEDIA_DIR_NONE). 3045 * (See RFC 3264 Section 8.4 and RFC 4317 Section 3.1) 3046 */ 3047 if (call->media_dir != PJMEDIA_DIR_ENCODING) { 3048 pjmedia_sdp_attr *attr; 3049 3050 /* Remove existing directions attributes */ 3051 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "sendrecv"); 3052 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "sendonly"); 3053 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "recvonly"); 3054 pjmedia_sdp_media_remove_all_attr(sdp->media[0], "inactive"); 3055 3056 if (call->media_dir == PJMEDIA_DIR_ENCODING_DECODING) { 3057 /* Add sendonly attribute */ 3058 attr = pjmedia_sdp_attr_create(pool, "sendonly", NULL); 3059 pjmedia_sdp_media_add_attr(sdp->media[0], attr); 3060 } else { 3061 /* Add inactive attribute */ 3062 attr = pjmedia_sdp_attr_create(pool, "inactive", NULL); 3063 pjmedia_sdp_media_add_attr(sdp->media[0], attr); 3064 } 3065 } 3060 3066 3061 3067 *p_answer = sdp; … … 3063 3069 return status; 3064 3070 } 3065 3066 3071 3067 3072 /* … … 3071 3076 const pjmedia_sdp_session *offer) 3072 3077 { 3073 const char *remote_state;3074 3078 pjsua_call *call; 3075 3079 pjmedia_sdp_conn *conn; 3076 3080 pjmedia_sdp_session *answer; 3077 pj_bool_t is_remote_active;3078 3081 pj_status_t status; 3079 3082 … … 3081 3084 3082 3085 call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id]; 3083 3084 /*3085 * See if remote is offering active media (i.e. not on-hold)3086 */3087 is_remote_active = PJ_TRUE;3088 3086 3089 3087 conn = offer->media[0]->conn; … … 3091 3089 conn = offer->conn; 3092 3090 3091 /* Supply candidate answer */ 3092 PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer", 3093 call->index)); 3094 3095 status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 3096 offer, &answer, NULL); 3097 if (status != PJ_SUCCESS) { 3098 pjsua_perror(THIS_FILE, "Unable to create local SDP", status); 3099 PJSUA_UNLOCK(); 3100 return; 3101 } 3102 3103 /* Check if offer's conn address is zero */ 3093 3104 if (pj_strcmp2(&conn->addr, "0.0.0.0")==0 || 3094 3105 pj_strcmp2(&conn->addr, "0")==0) 3095 3106 { 3096 is_remote_active = PJ_FALSE; 3097 3098 } 3099 else if (pjmedia_sdp_media_find_attr2(offer->media[0], "inactive", NULL) || 3100 pjmedia_sdp_media_find_attr2(offer->media[0], "sendonly", NULL)) 3101 { 3102 is_remote_active = PJ_FALSE; 3103 } 3104 3105 remote_state = (is_remote_active ? "active" : "inactive"); 3106 3107 /* Supply candidate answer */ 3108 if (call->media_st == PJSUA_CALL_MEDIA_LOCAL_HOLD || !is_remote_active) { 3109 PJ_LOG(4,(THIS_FILE, 3110 "Call %d: RX new media offer, creating inactive SDP " 3111 "(media in offer is %s)", call->index, remote_state)); 3112 status = create_inactive_sdp( call, &answer ); 3113 } else { 3114 PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer", 3115 call->index)); 3116 3117 status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 3118 offer, &answer, NULL); 3119 } 3120 3121 if (status != PJ_SUCCESS) { 3122 pjsua_perror(THIS_FILE, "Unable to create local SDP", status); 3123 PJSUA_UNLOCK(); 3124 return; 3107 /* Modify address */ 3108 answer->conn->addr = pj_str("0.0.0.0"); 3109 } 3110 3111 /* Check if call is on-hold */ 3112 if (call->local_hold) { 3113 pjmedia_sdp_attr *attr; 3114 3115 /* Remove existing directions attributes */ 3116 pjmedia_sdp_media_remove_all_attr(answer->media[0], "sendrecv"); 3117 pjmedia_sdp_media_remove_all_attr(answer->media[0], "sendonly"); 3118 pjmedia_sdp_media_remove_all_attr(answer->media[0], "recvonly"); 3119 pjmedia_sdp_media_remove_all_attr(answer->media[0], "inactive"); 3120 3121 /* Keep call on-hold by setting 'sendonly' attribute. 3122 * (See RFC 3264 Section 8.4 and RFC 4317 Section 3.1) 3123 */ 3124 attr = pjmedia_sdp_attr_create(call->inv->pool, "sendonly", NULL); 3125 pjmedia_sdp_media_add_attr(answer->media[0], attr); 3125 3126 } 3126 3127 … … 3150 3151 3151 3152 /* See if we've put call on hold. */ 3152 if (call-> media_st == PJSUA_CALL_MEDIA_LOCAL_HOLD) {3153 if (call->local_hold) { 3153 3154 PJ_LOG(4,(THIS_FILE, 3154 "Call %d: call is on-hold locally, creating inactiveSDP ",3155 "Call %d: call is on-hold locally, creating call-hold SDP ", 3155 3156 call->index)); 3156 status = create_ inactive_sdp( call, offer );3157 status = create_sdp_of_call_hold( call, offer ); 3157 3158 } else { 3158 3159 PJ_LOG(4,(THIS_FILE, "Call %d: asked to send a new offer", -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r2135 r2191 1232 1232 pj_memcpy(&sess_info.stream_info[0], si, sizeof(pjmedia_stream_info)); 1233 1233 1234 /* Check if media is put on-hold*/1234 /* Check if no media is active */ 1235 1235 if (sess_info.stream_cnt == 0 || si->dir == PJMEDIA_DIR_NONE) 1236 1236 { 1237 1238 /* Determine who puts the call on-hold */ 1239 if (prev_media_st == PJSUA_CALL_MEDIA_ACTIVE) { 1240 if (pjmedia_sdp_neg_was_answer_remote(call->inv->neg)) { 1241 /* It was local who offer hold */ 1242 call->media_st = PJSUA_CALL_MEDIA_LOCAL_HOLD; 1243 } else { 1244 call->media_st = PJSUA_CALL_MEDIA_REMOTE_HOLD; 1245 } 1246 } 1247 1237 /* Call media state */ 1238 call->media_st = PJSUA_CALL_MEDIA_NONE; 1239 1240 /* Call media direction */ 1248 1241 call->media_dir = PJMEDIA_DIR_NONE; 1249 1242 … … 1368 1361 } 1369 1362 1370 /* Call's media state is active */ 1371 call->media_st = PJSUA_CALL_MEDIA_ACTIVE; 1363 /* Call media direction */ 1372 1364 call->media_dir = si->dir; 1365 1366 /* Call media state */ 1367 if (call->local_hold) 1368 call->media_st = PJSUA_CALL_MEDIA_LOCAL_HOLD; 1369 else if (call->media_dir == PJMEDIA_DIR_DECODING) 1370 call->media_st = PJSUA_CALL_MEDIA_REMOTE_HOLD; 1371 else 1372 call->media_st = PJSUA_CALL_MEDIA_ACTIVE; 1373 1373 } 1374 1374
Note: See TracChangeset
for help on using the changeset viewer.