4 Copyright (C) 2010 Belledonne Communications SARL
5 (simon.morlat@linphone.org)
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "linphonecore.h"
30 #include "mediastreamer2/mediastream.h"
31 #include "mediastreamer2/msvolume.h"
32 #include "mediastreamer2/msequalizer.h"
33 #include "mediastreamer2/msfileplayer.h"
34 #include "mediastreamer2/msjpegwriter.h"
37 static MSWebCam *get_nowebcam_device(){
38 return ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),"StaticImage: Static picture");
43 static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs){
46 for(it=codecs;it!=NULL;it=it->next){
47 PayloadType *pt=(PayloadType*)it->data;
48 if ((pt->flags & PAYLOAD_TYPE_ENABLED) && linphone_core_check_payload_type_usability(lc,pt)){
49 l=ms_list_append(l,payload_type_clone(pt));
55 SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCall *call){
58 const char *me=linphone_core_get_identity(lc);
59 LinphoneAddress *addr=linphone_address_new(me);
60 const char *username=linphone_address_get_username (addr);
61 SalMediaDescription *md=sal_media_description_new();
64 strncpy(md->addr,call->localip,sizeof(md->addr));
65 strncpy(md->username,username,sizeof(md->username));
66 md->bandwidth=linphone_core_get_download_bandwidth(lc);
67 /*set audio capabilities */
68 strncpy(md->streams[0].addr,call->localip,sizeof(md->streams[0].addr));
69 md->streams[0].port=call->audio_port;
70 md->streams[0].proto=SalProtoRtpAvp;
71 md->streams[0].type=SalAudio;
72 md->streams[0].ptime=lc->net_conf.down_ptime;
73 l=make_codec_list(lc,lc->codecs_conf.audio_codecs);
74 pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event"));
75 l=ms_list_append(l,pt);
76 md->streams[0].payloads=l;
78 if (lc->dw_audio_bw>0)
79 md->streams[0].bandwidth=lc->dw_audio_bw;
81 if (call->params.has_video){
83 md->streams[1].port=call->video_port;
84 md->streams[1].proto=SalProtoRtpAvp;
85 md->streams[1].type=SalVideo;
86 l=make_codec_list(lc,lc->codecs_conf.video_codecs);
87 md->streams[1].payloads=l;
89 md->streams[1].bandwidth=lc->dw_video_bw;
91 linphone_address_destroy(addr);
95 static int find_port_offset(LinphoneCore *lc){
99 bool_t already_used=FALSE;
100 for(offset=0;offset<100;offset+=2){
101 audio_port=linphone_core_get_audio_port (lc)+offset;
103 for(elem=lc->calls;elem!=NULL;elem=elem->next){
104 LinphoneCall *call=(LinphoneCall*)elem->data;
105 if (call->audio_port==audio_port) {
110 if (!already_used) break;
113 ms_error("Could not find any free port !");
119 static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
122 call->state=LinphoneCallIdle;
123 call->start_time=time(NULL);
124 call->media_start_time=0;
125 call->log=linphone_call_log_new(call, from, to);
126 linphone_core_notify_all_friends(call->core,LinphoneStatusOnThePhone);
127 port_offset=find_port_offset (call->core);
128 if (port_offset==-1) return;
129 call->audio_port=linphone_core_get_audio_port(call->core)+port_offset;
130 call->video_port=linphone_core_get_video_port(call->core)+port_offset;
134 static void discover_mtu(LinphoneCore *lc, const char *remote){
136 if (lc->net_conf.mtu==0 ){
137 /*attempt to discover mtu*/
138 mtu=ms_discover_mtu(remote);
141 ms_message("Discovered mtu is %i, RTP payload max size is %i",
142 mtu, ms_get_payload_max_size());
147 LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params)
149 LinphoneCall *call=ms_new0(LinphoneCall,1);
150 call->dir=LinphoneCallOutgoing;
151 call->op=sal_op_new(lc->sal);
152 sal_op_set_user_pointer(call->op,call);
154 linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
155 linphone_call_init_common(call,from,to);
156 call->params=*params;
157 call->localdesc=create_local_media_description (lc,call);
158 call->camera_active=params->has_video;
159 if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun)
160 linphone_core_run_stun_tests(call->core,call);
161 discover_mtu(lc,linphone_address_get_domain (to));
162 if (params->referer){
163 sal_call_set_referer (call->op,params->referer->op);
168 LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
169 LinphoneCall *call=ms_new0(LinphoneCall,1);
173 call->dir=LinphoneCallIncoming;
174 sal_op_set_user_pointer(op,call);
178 if (lc->sip_conf.ping_with_options){
179 /*the following sends an option request back to the caller so that
180 we get a chance to discover our nat'd address before answering.*/
181 call->ping_op=sal_op_new(lc->sal);
182 to_str=linphone_address_as_string(to);
183 from_str=linphone_address_as_string(from);
184 sal_op_set_route(call->ping_op,sal_op_get_network_origin(call->op));
185 sal_op_set_user_pointer(call->ping_op,call);
186 sal_ping(call->ping_op,to_str,from_str);
191 linphone_address_clean(from);
192 linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
193 linphone_call_init_common(call, from, to);
194 call->params.has_video=linphone_core_video_enabled(lc);
195 call->localdesc=create_local_media_description (lc,call);
196 call->camera_active=call->params.has_video;
197 if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun)
198 linphone_core_run_stun_tests(call->core,call);
199 discover_mtu(lc,linphone_address_get_domain(from));
203 /* this function is called internally to get rid of a call.
204 It performs the following tasks:
205 - remove the call from the internal list of calls
206 - unref the LinphoneCall object
207 - update the call logs accordingly
210 static void linphone_call_set_terminated(LinphoneCall *call){
211 LinphoneCallStatus status=LinphoneCallAborted;
212 LinphoneCore *lc=call->core;
214 linphone_core_update_allocated_audio_bandwidth(lc);
215 if (call->state==LinphoneCallEnd){
216 if (call->reason==LinphoneReasonDeclined){
217 status=LinphoneCallDeclined;
219 else status=LinphoneCallSuccess;
222 linphone_call_log_completed(call->log,call, status);
224 if (call == lc->current_call){
225 ms_message("Resetting the current call");
226 lc->current_call=NULL;
229 if (linphone_core_del_call(lc,call) != 0){
230 ms_error("Could not remove the call from the list !!!");
233 if (ms_list_size(lc->calls)==0)
234 linphone_core_notify_all_friends(lc,lc->presence_mode);
236 if (call->op!=NULL) {
237 /* so that we cannot have anymore upcalls for SAL
238 concerning this call*/
239 sal_op_release(call->op);
242 linphone_call_unref(call);
245 const char *linphone_call_state_to_string(LinphoneCallState cs){
247 case LinphoneCallIdle:
248 return "LinphoneCallIdle";
249 case LinphoneCallIncomingReceived:
250 return "LinphoneCallIncomingReceived";
251 case LinphoneCallOutgoingInit:
252 return "LinphoneCallOutgoingInit";
253 case LinphoneCallOutgoingProgress:
254 return "LinphoneCallOutgoingProgress";
255 case LinphoneCallOutgoingRinging:
256 return "LinphoneCallOutgoingRinging";
257 case LinphoneCallOutgoingEarlyMedia:
258 return "LinphoneCallOutgoingEarlyMedia";
259 case LinphoneCallConnected:
260 return "LinphoneCallConnected";
261 case LinphoneCallStreamsRunning:
262 return "LinphoneCallStreamsRunning";
263 case LinphoneCallPausing:
264 return "LinphoneCallPausing";
265 case LinphoneCallPaused:
266 return "LinphoneCallPaused";
267 case LinphoneCallResuming:
268 return "LinphoneCallResuming";
269 case LinphoneCallRefered:
270 return "LinphoneCallRefered";
271 case LinphoneCallError:
272 return "LinphoneCallError";
273 case LinphoneCallEnd:
274 return "LinphoneCallEnd";
275 case LinphoneCallPausedByRemote:
276 return "LinphoneCallPausedByRemote";
277 case LinphoneCallUpdatedByRemote:
278 return "LinphoneCallUpdatedByRemote";
279 case LinphoneCallIncomingEarlyMedia:
280 return "LinphoneCallIncomingEarlyMedia";
281 case LinphoneCallUpdated:
282 return "LinphoneCallUpdated";
284 return "undefined state";
287 void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const char *message){
288 LinphoneCore *lc=call->core;
289 bool_t finalize_call=FALSE;
290 if (call->state!=cstate){
291 ms_message("Call %p: moving from state %s to %s",call,linphone_call_state_to_string(call->state),
292 linphone_call_state_to_string(cstate));
293 if (cstate!=LinphoneCallRefered){
294 /*LinphoneCallRefered is rather an event, not a state.
295 Indeed it does not change the state of the call (still paused or running)*/
298 if (cstate==LinphoneCallEnd || cstate==LinphoneCallError){
300 linphone_call_ref(call);
301 linphone_call_set_terminated (call);
303 if (lc->vtable.call_state_changed)
304 lc->vtable.call_state_changed(lc,call,cstate,message);
306 linphone_call_unref(call);
310 static void linphone_call_destroy(LinphoneCall *obj)
313 sal_op_release(obj->op);
316 if (obj->resultdesc!=NULL) {
317 sal_media_description_unref(obj->resultdesc);
318 obj->resultdesc=NULL;
320 if (obj->localdesc!=NULL) {
321 sal_media_description_unref(obj->localdesc);
325 sal_op_release(obj->ping_op);
328 ms_free(obj->refer_to);
334 * @addtogroup call_control
339 * Increments the call 's reference count.
340 * An application that wishes to retain a pointer to call object
341 * must use this function to unsure the pointer remains
342 * valid. Once the application no more needs this pointer,
343 * it must call linphone_call_unref().
345 void linphone_call_ref(LinphoneCall *obj){
350 * Decrements the call object reference count.
351 * See linphone_call_ref().
353 void linphone_call_unref(LinphoneCall *obj){
356 linphone_call_destroy(obj);
361 * Returns current parameters associated to the call.
363 const LinphoneCallParams * linphone_call_get_current_params(const LinphoneCall *call){
364 return &call->params;
368 * Returns the remote address associated to this call
371 const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call){
372 return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
376 * Returns the remote address associated to this call as a string.
378 * The result string must be freed by user using ms_free().
380 char *linphone_call_get_remote_address_as_string(const LinphoneCall *call){
381 return linphone_address_as_string(linphone_call_get_remote_address(call));
385 * Retrieves the call's current state.
387 LinphoneCallState linphone_call_get_state(const LinphoneCall *call){
392 * Returns the reason for a call termination (either error or normal termination)
394 LinphoneReason linphone_call_get_reason(const LinphoneCall *call){
399 * Get the user_pointer in the LinphoneCall
401 * @ingroup call_control
403 * return user_pointer an opaque user pointer that can be retrieved at any time
405 void *linphone_call_get_user_pointer(LinphoneCall *call)
407 return call->user_pointer;
411 * Set the user_pointer in the LinphoneCall
413 * @ingroup call_control
415 * the user_pointer is an opaque user pointer that can be retrieved at any time in the LinphoneCall
417 void linphone_call_set_user_pointer(LinphoneCall *call, void *user_pointer)
419 call->user_pointer = user_pointer;
423 * Returns the call log associated to this call.
425 LinphoneCallLog *linphone_call_get_call_log(const LinphoneCall *call){
430 * Returns the refer-to uri (if the call was transfered).
432 const char *linphone_call_get_refer_to(const LinphoneCall *call){
433 return call->refer_to;
437 * Returns direction of the call (incoming or outgoing).
439 LinphoneCallDir linphone_call_get_dir(const LinphoneCall *call){
440 return call->log->dir;
444 * Returns the far end's user agent description string, if available.
446 const char *linphone_call_get_remote_user_agent(LinphoneCall *call){
448 return sal_op_get_remote_ua (call->op);
454 * Returns true if this calls has received a transfer that has not been
456 * Pending transfers are executed when this call is being paused or closed,
457 * locally or by remote endpoint.
458 * If the call is already paused while receiving the transfer request, the
459 * transfer immediately occurs.
461 bool_t linphone_call_has_transfer_pending(const LinphoneCall *call){
462 return call->refer_pending;
466 * Returns call's duration in seconds.
468 int linphone_call_get_duration(const LinphoneCall *call){
469 if (call->media_start_time==0) return 0;
470 return time(NULL)-call->media_start_time;
474 * Indicate whether camera input should be sent to remote end.
476 void linphone_call_enable_camera (LinphoneCall *call, bool_t enable){
478 if (call->videostream!=NULL && call->videostream->ticker!=NULL){
479 LinphoneCore *lc=call->core;
480 MSWebCam *nowebcam=get_nowebcam_device();
481 if (call->camera_active!=enable && lc->video_conf.device!=nowebcam){
482 video_stream_change_camera(call->videostream,
483 enable ? lc->video_conf.device : nowebcam);
486 call->camera_active=enable;
491 * Take a photo of currently received video and write it into a jpeg file.
493 int linphone_call_take_video_snapshot(LinphoneCall *call, const char *file){
495 if (call->videostream!=NULL && call->videostream->jpegwriter!=NULL){
496 return ms_filter_call_method(call->videostream->jpegwriter,MS_JPEG_WRITER_TAKE_SNAPSHOT,(void*)file);
498 ms_warning("Cannot take snapshot: no currently running video stream on this call.");
507 bool_t linphone_call_camera_enabled (const LinphoneCall *call){
508 return call->camera_active;
514 void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled){
515 cp->has_video=enabled;
521 bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp){
522 return cp->has_video;
526 * Enable sending of real early media (during outgoing calls).
528 void linphone_call_params_enable_early_media_sending(LinphoneCallParams *cp, bool_t enabled){
529 cp->real_early_media=enabled;
532 bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams *cp){
533 return cp->real_early_media;
539 LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){
540 LinphoneCallParams *ncp=ms_new0(LinphoneCallParams,1);
541 memcpy(ncp,cp,sizeof(LinphoneCallParams));
548 void linphone_call_params_destroy(LinphoneCallParams *p){
557 #ifdef TEST_EXT_RENDERER
558 static void rendercb(void *data, const MSPicture *local, const MSPicture *remote){
559 ms_message("rendercb, local buffer=%p, remote buffer=%p",
560 local ? local->planes[0] : NULL, remote? remote->planes[0] : NULL);
564 void linphone_call_init_media_streams(LinphoneCall *call){
565 LinphoneCore *lc=call->core;
566 SalMediaDescription *md=call->localdesc;
567 AudioStream *audiostream;
569 call->audiostream=audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
570 if (linphone_core_echo_limiter_enabled(lc)){
571 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
572 if (strcasecmp(type,"mic")==0)
573 audio_stream_enable_echo_limiter(audiostream,ELControlMic);
574 else if (strcasecmp(type,"full")==0)
575 audio_stream_enable_echo_limiter(audiostream,ELControlFull);
577 audio_stream_enable_gain_control(audiostream,TRUE);
578 if (linphone_core_echo_cancellation_enabled(lc)){
579 int len,delay,framesize;
580 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
581 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
582 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
583 audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize);
585 audio_stream_enable_automatic_gain_control(audiostream,linphone_core_agc_enabled(lc));
587 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
588 audio_stream_enable_noise_gate(audiostream,enabled);
591 rtp_session_set_transports(audiostream->session,lc->a_rtp,lc->a_rtcp);
594 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0){
595 call->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
596 if( lc->video_conf.displaytype != NULL)
597 video_stream_set_display_filter_name(call->videostream,lc->video_conf.displaytype);
598 #ifdef TEST_EXT_RENDERER
599 video_stream_set_render_callback(call->videostream,rendercb,NULL);
603 call->videostream=NULL;
608 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
610 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
611 LinphoneCore* lc = (LinphoneCore*)user_data;
612 if (dtmf<0 || dtmf>15){
613 ms_warning("Bad dtmf value %i",dtmf);
616 if (lc->vtable.dtmf_received != NULL)
617 lc->vtable.dtmf_received(lc, linphone_core_get_current_call(lc), dtmf_tab[dtmf]);
620 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
622 MSFilter *f=st->equalizer;
623 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
624 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
625 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
631 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
632 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
633 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
643 static void post_configure_audio_streams(LinphoneCall*call){
644 AudioStream *st=call->audiostream;
645 LinphoneCore *lc=call->core;
646 float mic_gain=lp_config_get_float(lc->config,"sound","mic_gain",1);
649 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
650 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
651 int dc_removal=lp_config_get_int(lc->config,"sound","dc_removal",0);
653 if (!call->audio_muted)
654 audio_stream_set_mic_gain(st,mic_gain);
656 audio_stream_set_mic_gain(st,0);
658 recv_gain = lc->sound_conf.soft_play_lev;
659 if (recv_gain != 0) {
660 linphone_core_set_playback_gain_db (lc,recv_gain);
663 ms_filter_call_method(st->volsend,MS_VOLUME_REMOVE_DC,&dc_removal);
665 if (linphone_core_echo_limiter_enabled(lc)){
666 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
667 thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
668 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
669 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
671 if (st->el_type!=ELInactive){
673 if (speed==-1) speed=0.03;
674 if (force==-1) force=25;
675 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
676 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
678 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
680 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
685 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
686 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
689 /* parameters for a limited noise-gate effect, using echo limiter threshold */
690 float floorgain = 1/mic_gain;
691 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&thres);
692 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&floorgain);
694 parametrize_equalizer(lc,st);
695 if (lc->vtable.dtmf_received!=NULL){
696 /* replace by our default action*/
697 audio_stream_play_received_dtmfs(call->audiostream,FALSE);
698 rtp_session_signal_connect(call->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
705 static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
708 RtpProfile *prof=rtp_profile_new("Call profile");
713 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
714 PayloadType *pt=(PayloadType*)elem->data;
718 if (desc->type==SalAudio){
719 linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt);
721 *used_pt=payload_type_get_number(pt);
724 if (desc->bandwidth>0) remote_bw=desc->bandwidth;
725 else if (md->bandwidth>0) {
726 /*case where b=AS is given globally, not per stream*/
727 remote_bw=md->bandwidth;
728 if (desc->type==SalVideo){
729 remote_bw-=lc->audio_bw;
733 if (desc->type==SalAudio){
734 bw=get_min_bandwidth(lc->up_audio_bw,remote_bw);
735 }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw);
736 if (bw>0) pt->normal_bitrate=bw*1000;
737 else if (desc->type==SalAudio){
738 pt->normal_bitrate=-1;
742 snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
743 payload_type_append_send_fmtp(pt,tmp);
745 number=payload_type_get_number(pt);
746 if (rtp_profile_get_payload(prof,number)!=NULL){
747 ms_warning("A payload type with number %i already exists in profile !",number);
749 rtp_profile_set_payload(prof,number,pt);
755 static void setup_ring_player(LinphoneCore *lc, LinphoneCall *call){
757 audio_stream_play(call->audiostream,lc->sound_conf.ringback_tone);
758 ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
762 void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone){
763 LinphoneCore *lc=call->core;
764 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
765 const char *tool="linphone-" LINPHONE_VERSION;
769 if(call->audiostream == NULL)
771 ms_fatal("start_media_stream() called without prior init !");
774 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
775 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
777 if (call->media_start_time==0) call->media_start_time=time(NULL);
779 cname=linphone_address_as_string_uri_only(me);
781 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
782 SalProtoRtpAvp,SalAudio);
783 if (stream && stream->dir!=SalStreamInactive){
784 MSSndCard *playcard=lc->sound_conf.lsd_card ?
785 lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
786 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
787 const char *playfile=lc->play_file;
788 const char *recfile=lc->rec_file;
789 call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
791 if (playcard==NULL) {
792 ms_warning("No card defined for playback !");
794 if (captcard==NULL) {
795 ms_warning("No card defined for capture !");
797 /*Replace soundcard filters by inactive file players or recorders
798 when placed in recvonly or sendonly mode*/
799 if (stream->port==0 || stream->dir==SalStreamRecvOnly){
802 }else if (stream->dir==SalStreamSendOnly){
808 if (send_ringbacktone){
810 playfile=NULL;/* it is setup later*/
812 /*if playfile are supplied don't use soundcards*/
817 audio_stream_start_full(
820 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
829 captcard==NULL ? FALSE : linphone_core_echo_cancellation_enabled(lc));
830 post_configure_audio_streams(call);
831 if (all_inputs_muted && !send_ringbacktone){
832 audio_stream_set_mic_gain(call->audiostream,0);
834 if (send_ringbacktone){
835 setup_ring_player(lc,call);
837 audio_stream_set_rtcp_information(call->audiostream, cname, tool);
838 }else ms_warning("No audio stream accepted ?");
843 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
844 SalProtoRtpAvp,SalVideo);
846 /* shutdown preview */
847 if (lc->previewstream!=NULL) {
848 video_preview_stop(lc->previewstream);
849 lc->previewstream=NULL;
851 if (stream && stream->dir!=SalStreamInactive) {
852 const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
853 call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
855 VideoStreamDir dir=VideoStreamSendRecv;
856 MSWebCam *cam=lc->video_conf.device;
857 bool_t is_inactive=FALSE;
859 call->params.has_video=TRUE;
861 video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
862 video_stream_enable_self_view(call->videostream,lc->video_conf.selfview);
863 if (lc->video_window_id!=0)
864 video_stream_set_native_window_id(call->videostream,lc->video_window_id);
865 if (lc->preview_window_id!=0)
866 video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id);
867 video_stream_use_preview_video_window (call->videostream,lc->use_preview_window);
869 if (stream->dir==SalStreamSendOnly && lc->video_conf.capture ){
870 cam=get_nowebcam_device();
871 dir=VideoStreamSendOnly;
872 }else if (stream->dir==SalStreamRecvOnly && lc->video_conf.display ){
873 dir=VideoStreamRecvOnly;
874 }else if (stream->dir==SalStreamSendRecv){
875 if (lc->video_conf.display && lc->video_conf.capture)
876 dir=VideoStreamSendRecv;
877 else if (lc->video_conf.display)
878 dir=VideoStreamRecvOnly;
880 dir=VideoStreamSendOnly;
882 ms_warning("video stream is inactive.");
883 /*either inactive or incompatible with local capabilities*/
886 if (call->camera_active==FALSE || all_inputs_muted){
887 cam=get_nowebcam_device();
890 video_stream_set_direction (call->videostream, dir);
891 video_stream_start(call->videostream,
892 call->video_profile, addr, stream->port,
894 used_pt, jitt_comp, cam);
895 video_stream_set_rtcp_information(call->videostream, cname,tool);
897 }else ms_warning("No video stream accepted.");
899 ms_warning("No valid video stream defined.");
903 call->all_muted=all_inputs_muted;
904 call->playing_ringbacktone=send_ringbacktone;
905 call->up_bw=linphone_core_get_upload_bandwidth(lc);
910 linphone_address_destroy(me);
913 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
914 audio_stream_get_local_rtp_stats (st,&log->local_stats);
917 void linphone_call_stop_media_streams(LinphoneCall *call){
918 if (call->audiostream!=NULL) {
919 linphone_call_log_fill_stats (call->log,call->audiostream);
920 audio_stream_stop(call->audiostream);
921 call->audiostream=NULL;
924 if (call->videostream!=NULL){
925 video_stream_stop(call->videostream);
926 call->videostream=NULL;
930 if (call->audio_profile){
931 rtp_profile_clear_all(call->audio_profile);
932 rtp_profile_destroy(call->audio_profile);
933 call->audio_profile=NULL;
935 if (call->video_profile){
936 rtp_profile_clear_all(call->video_profile);
937 rtp_profile_destroy(call->video_profile);
938 call->video_profile=NULL;