void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){ SalMediaDescription *oldmd=call->resultdesc; if (lc->ringstream!=NULL){ ring_stop(lc->ringstream); lc->ringstream=NULL; } if (new_md!=NULL){ sal_media_description_ref(new_md); call->media_pending=FALSE; }else{ call->media_pending=TRUE; } call->resultdesc=new_md; if (call->audiostream && call->audiostream->ticker){ /* we already started media: check if we really need to restart it*/ if (oldmd){ if (!media_parameters_changed(call,oldmd,new_md) && !call->playing_ringbacktone){ sal_media_description_unref(oldmd); if (call->all_muted){ ms_message("Early media finished, unmuting inputs..."); /*we were in early media, now we want to enable real media */ linphone_call_enable_camera (call,linphone_call_camera_enabled (call)); if (call->audiostream) linphone_core_mute_mic (lc, linphone_core_is_mic_muted(lc)); #ifdef VIDEO_ENABLED if (call->videostream && call->camera_active) video_stream_change_camera(call->videostream,lc->video_conf.device ); #endif } ms_message("No need to restart streams, SDP is unchanged."); return; }else{ ms_message("Media descriptions are different, need to restart the streams."); } } linphone_call_stop_media_streams (call); linphone_call_init_media_streams (call); } if (oldmd) sal_media_description_unref(oldmd); if (new_md) { bool_t all_muted=FALSE; bool_t send_ringbacktone=FALSE; if (call->audiostream==NULL){ /*this happens after pausing the call locally. The streams is destroyed and then we wait the 200Ok to recreate it*/ linphone_call_init_media_streams (call); } if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){ send_ringbacktone=TRUE; } if (call->state==LinphoneCallIncomingEarlyMedia || (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){ all_muted=TRUE; } linphone_call_start_media_streams(call,all_muted,send_ringbacktone); } }
/*Call API*/ int sal_call_set_local_media_description(SalOp *op, SalMediaDescription *desc){ if (desc) sal_media_description_ref(desc); if (op->base.local_media) sal_media_description_unref(op->base.local_media); op->base.local_media=desc; if (op->base.remote_media){ /*case of an incoming call where we modify the local capabilities between the time * the call is ringing and it is accepted (for example if you want to accept without video*/ /*reset the sdp answer so that it is computed again*/ if (op->sdp_answer){ belle_sip_object_unref(op->sdp_answer); op->sdp_answer=NULL; } } return 0; }
void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){ SalMediaDescription *oldmd=call->resultdesc; bool_t all_muted=FALSE; bool_t send_ringbacktone=FALSE; linphone_core_stop_ringing(lc); if (!new_md) { ms_error("linphone_core_update_streams() called with null media description"); return; } if (call->biggestdesc==NULL || new_md->n_total_streams>call->biggestdesc->n_total_streams){ /*we have been offered and now are ready to proceed, or we added a new stream*/ /*store the media description to remember the mapping of calls*/ if (call->biggestdesc){ sal_media_description_unref(call->biggestdesc); call->biggestdesc=NULL; } if (sal_call_is_offerer(call->op)) call->biggestdesc=sal_media_description_ref(call->localdesc); else call->biggestdesc=sal_media_description_ref(sal_call_get_remote_media_description(call->op)); } sal_media_description_ref(new_md); call->expect_media_in_ack=FALSE; call->resultdesc=new_md; if ((call->audiostream && call->audiostream->ms.ticker) || (call->videostream && call->videostream->ms.ticker)){ /* we already started media: check if we really need to restart it*/ if (oldmd){ int md_changed = media_parameters_changed(call, oldmd, new_md); if ((md_changed & SAL_MEDIA_DESCRIPTION_CODEC_CHANGED) || call->playing_ringbacktone) { ms_message("Media descriptions are different, need to restart the streams."); } else { if (md_changed == SAL_MEDIA_DESCRIPTION_UNCHANGED) { if (call->all_muted){ ms_message("Early media finished, unmuting inputs..."); /*we were in early media, now we want to enable real media */ linphone_call_enable_camera (call,linphone_call_camera_enabled (call)); if (call->audiostream) linphone_core_enable_mic(lc, linphone_core_mic_enabled(lc)); #ifdef VIDEO_ENABLED if (call->videostream && call->camera_enabled) video_stream_change_camera(call->videostream,lc->video_conf.device ); #endif } ms_message("No need to restart streams, SDP is unchanged."); goto end; }else { if (md_changed & SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED) { ms_message("Network parameters have changed, update them."); linphone_core_update_streams_destinations(lc, call, oldmd, new_md); } if (md_changed & SAL_MEDIA_DESCRIPTION_CRYPTO_CHANGED) { ms_message("Crypto parameters have changed, update them."); linphone_call_update_crypto_parameters(call, oldmd, new_md); } goto end; } } } linphone_call_stop_media_streams (call); linphone_call_init_media_streams (call); } if (call->audiostream==NULL){ /*this happens after pausing the call locally. The streams are destroyed and then we wait the 200Ok to recreate them*/ linphone_call_init_media_streams (call); } if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){ send_ringbacktone=TRUE; } if (call->state==LinphoneCallIncomingEarlyMedia || (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){ all_muted=TRUE; } linphone_call_start_media_streams(call,all_muted,send_ringbacktone); if (call->state==LinphoneCallPausing && call->paused_by_app && ms_list_size(lc->calls)==1){ linphone_core_play_named_tone(lc,LinphoneToneCallOnHold); } end: if (oldmd) sal_media_description_unref(oldmd); }