]> sjero.net Git - linphone/blobdiff - coreapi/linphonecore.c
Merge branch 'master' of git.savannah.nongnu.org:/srv/git/linphone
[linphone] / coreapi / linphonecore.c
index 6af2fbfc9d5d5a1140c5ac663b92460a2036a2d8..167630e1a8e241895f9beed8c35e3c04e7b48193 100644 (file)
@@ -49,6 +49,8 @@ static void toggle_video_preview(LinphoneCore *lc, bool_t val);
 #define LOCAL_RING "rings/oldphone.wav"
 /* same for remote ring (ringback)*/
 #define REMOTE_RING "ringback.wav"
+#define HOLD_MUSIC "rings/toy-mono.wav"
+
 
 extern SalCallbacks linphone_sal_callbacks;
 
@@ -452,6 +454,8 @@ static void sound_config_read(LinphoneCore *lc)
                tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
        }
        linphone_core_set_ringback(lc,tmpbuf);
+
+       linphone_core_set_play_file(lc,lp_config_get_string(lc->config,"sound","hold_music",PACKAGE_SOUND_DIR "/" HOLD_MUSIC));
        check_sound_device(lc);
        lc->sound_conf.latency=0;
 
@@ -571,6 +575,7 @@ static void sip_config_read(LinphoneCore *lc)
        lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
        sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
        sal_use_one_matching_codec_policy(lc->sal,lp_config_get_int(lc->config,"sip","only_one_codec",0));
+       sal_use_double_registrations(lc->sal,lp_config_get_int(lc->config,"sip","use_double_registrations",1));
 }
 
 static void rtp_config_read(LinphoneCore *lc)
@@ -590,6 +595,8 @@ static void rtp_config_read(LinphoneCore *lc)
        jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
        linphone_core_set_audio_jittcomp(lc,jitt_comp);
        jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
+       if (jitt_comp==0) jitt_comp=60;
+       lc->rtp_conf.video_jitt_comp=jitt_comp;
        nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
        linphone_core_set_nortp_timeout(lc,nortp_timeout);
        rtp_no_xmit_on_audio_mute=lp_config_get_int(lc->config,"rtp","rtp_no_xmit_on_audio_mute",FALSE);
@@ -910,7 +917,8 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
 {
        memset (lc, 0, sizeof (LinphoneCore));
        lc->data=userdata;
-
+       lc->ringstream_autorelease=TRUE;
+       
        memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
 
        linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
@@ -1635,6 +1643,19 @@ void linphone_core_iterate(LinphoneCore *lc){
                one_second_elapsed=TRUE;
        }
 
+       if (lc->ecc!=NULL){
+               LinphoneEcCalibratorStatus ecs=ec_calibrator_get_status(lc->ecc);
+               if (ecs!=LinphoneEcCalibratorInProgress){
+                       if (lc->ecc->cb)
+                               lc->ecc->cb(lc,ecs,lc->ecc->delay,lc->ecc->cb_data);
+                       if (ecs==LinphoneEcCalibratorDone){
+                               lp_config_set_int(lc->config, "sound", "ec_delay",MAX(lc->ecc->delay-10,0));
+                       }
+                       ec_calibrator_destroy(lc->ecc);
+                       lc->ecc=NULL;
+               }
+       }
+
        if (lc->preview_finished){
                lc->preview_finished=0;
                ring_stop(lc->ringstream);
@@ -1642,7 +1663,7 @@ void linphone_core_iterate(LinphoneCore *lc){
                lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
        }
 
-       if (lc->ringstream && lc->dmfs_playing_start_time!=0 
+       if (lc->ringstream && lc->ringstream_autorelease && lc->dmfs_playing_start_time!=0 
            && (curtime-lc->dmfs_playing_start_time)>5){
                ring_stop(lc->ringstream);
                lc->ringstream=NULL;
@@ -2176,15 +2197,13 @@ bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
 int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params){
        int err=0;
        if (params!=NULL){
-               if (call->localdesc)
-                       sal_media_description_unref(call->localdesc);
                call->params=*params;
-               call->localdesc=create_local_media_description (lc,call);
+               update_local_media_description(lc,call,&call->localdesc);
                call->camera_active=params->has_video;
                if (lc->vtable.display_status)
                        lc->vtable.display_status(lc,_("Modifying call parameters..."));
                sal_call_set_local_media_description (call->op,call->localdesc);
-               err=sal_call_update(call->op);
+               err=sal_call_update(call->op,"Media parameters update");
        }else{
 #ifdef VIDEO_ENABLED
                if (call->videostream!=NULL){
@@ -2411,13 +2430,23 @@ LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
 {
        LinphoneCall *call = the_call;
+       const char *subject=NULL;
 
        if (call->state!=LinphoneCallStreamsRunning && call->state!=LinphoneCallPausedByRemote){
                ms_warning("Cannot pause this call, it is not active.");
                return -1;
        }
-       
-       if (sal_call_hold(call->op,TRUE) != 0)
+       if (sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv)){
+               sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
+               subject="Call on hold";
+       }else if (sal_media_description_has_dir(call->resultdesc,SalStreamRecvOnly)){
+               sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
+               subject="Call on hold for me too";
+       }else{
+               ms_error("No reason to pause this call, it is already paused or inactive.");
+               return -1;
+       }
+       if (sal_call_update(call->op,subject) != 0)
        {
                if (lc->vtable.display_warning)
                        lc->vtable.display_warning(lc,_("Could not pause the call"));
@@ -2467,14 +2496,14 @@ int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
                return -1;
        }
        ms_message("Resuming call %p",call);
-       if(sal_call_hold(call->op,FALSE) != 0){
+       sal_media_description_set_dir(call->localdesc,SalStreamSendRecv);
+       if(sal_call_update(call->op,"Call resuming") != 0){
                return -1;
        }
        linphone_call_set_state (call,LinphoneCallResuming,"Resuming");
        snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call));
        if (lc->vtable.display_status) 
                lc->vtable.display_status(lc,temp);
-       lc->current_call=call;
        return 0;
 }
 
@@ -2687,6 +2716,7 @@ static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
  * Returns true if the specified sound device can capture sound.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
  * @param devid the device name as returned by linphone_core_get_sound_devices()
 **/
 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
@@ -2700,6 +2730,7 @@ bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devi
  * Returns true if the specified sound device can play sound.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
  * @param devid the device name as returned by linphone_core_get_sound_devices()
 **/
 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
@@ -2713,6 +2744,7 @@ bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *dev
  * Sets the sound device used for ringing.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
  * @param devid the device name as returned by linphone_core_get_sound_devices()
 **/
 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
@@ -2727,6 +2759,7 @@ int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
  * Sets the sound device used for playback.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
  * @param devid the device name as returned by linphone_core_get_sound_devices()
 **/
 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
@@ -2741,6 +2774,7 @@ int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
  * Sets the sound device used for capture.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
  * @param devid the device name as returned by linphone_core_get_sound_devices()
 **/
 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
@@ -2755,6 +2789,7 @@ int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
  * Returns the name of the currently assigned sound device for ringing.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
 **/
 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
 {
@@ -2766,6 +2801,7 @@ const char * linphone_core_get_ringer_device(LinphoneCore *lc)
  * Returns the name of the currently assigned sound device for playback.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
 **/
 const char * linphone_core_get_playback_device(LinphoneCore *lc)
 {
@@ -2776,6 +2812,7 @@ const char * linphone_core_get_playback_device(LinphoneCore *lc)
  * Returns the name of the currently assigned sound device for capture.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
 **/
 const char * linphone_core_get_capture_device(LinphoneCore *lc)
 {
@@ -2785,8 +2822,10 @@ const char * linphone_core_get_capture_device(LinphoneCore *lc)
 /**
  * Returns an unmodifiable array of available sound devices.
  *
- * @ingroup media_parameters
  * The array is NULL terminated.
+ *
+ * @ingroup media_parameters
+ * @param lc The LinphoneCore object
 **/
 const char**  linphone_core_get_sound_devices(LinphoneCore *lc){
        build_sound_devices_table(lc);
@@ -2829,14 +2868,17 @@ void linphone_core_set_sound_source(LinphoneCore *lc, char source)
  * Sets the path to a wav file used for ringing.
  *
  * @param path The file must be a wav 16bit linear. Local ring is disabled if null
+ * @param lc The LinphoneCore object
  *
  * @ingroup media_parameters
 **/
 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
        if (lc->sound_conf.local_ring!=0){
                ms_free(lc->sound_conf.local_ring);
+               lc->sound_conf.local_ring=NULL;
        }
-       lc->sound_conf.local_ring=ms_strdup(path);
+       if (path)
+               lc->sound_conf.local_ring=ms_strdup(path);
        if ( linphone_core_ready(lc) && lc->sound_conf.local_ring)
                lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
 }
@@ -2844,6 +2886,7 @@ void linphone_core_set_ring(LinphoneCore *lc,const char *path){
 /**
  * Returns the path to the wav file used for ringing.
  *
+ * @param lc The LinphoneCore object
  * @ingroup media_parameters
 **/
 const char *linphone_core_get_ring(const LinphoneCore *lc){
@@ -3112,6 +3155,7 @@ static void toggle_video_preview(LinphoneCore *lc, bool_t val){
  * initiate future calls with video or not. The two boolean parameters indicate in which
  * direction video is enabled. Setting both to false disables video entirely.
  *
+ * @param lc The LinphoneCore object
  * @param vcap_enabled indicates whether video capture is enabled
  * @param display_enabled indicates whether video display should be shown
  *
@@ -3191,6 +3235,7 @@ bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
  * Sets the active video device.
  *
  * @ingroup media_parameters
+ * @param lc The LinphoneCore object
  * @param id the name of the video device as returned by linphone_core_get_video_devices()
 **/
 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
@@ -3220,6 +3265,7 @@ int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
 /**
  * Returns the name of the currently active video device.
  *
+ * @param lc The LinphoneCore object
  * @ingroup media_parameters
 **/
 const char *linphone_core_get_video_device(const LinphoneCore *lc){
@@ -3371,6 +3417,10 @@ void linphone_core_use_preview_window(LinphoneCore *lc, bool_t yesno){
 }
 
 static MSVideoSizeDef supported_resolutions[]={
+#ifdef ENABLE_HD
+       {       {MS_VIDEO_SIZE_1080P_W,MS_VIDEO_SIZE_1080P_H}   ,       "1080p" },
+       {       {MS_VIDEO_SIZE_720P_W,MS_VIDEO_SIZE_720P_H}     ,       "1080p" },
+#endif
        {       {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H}     ,       "svga"  },
        {       {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H}     ,       "4cif"  },
        {       {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H}       ,       "vga"   },
@@ -3519,8 +3569,10 @@ static MSFilter *get_dtmf_gen(LinphoneCore *lc){
                }
        }
        if (lc->ringstream==NULL){
+               float amp=0.1;
                MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
                lc->ringstream=ring_start(NULL,0,ringcard);
+               ms_filter_call_method(lc->ringstream->gendtmf,MS_DTMF_GEN_SET_DEFAULT_AMPLITUDE,&amp);
                lc->dmfs_playing_start_time=time(NULL);
        }else{
                if (lc->dmfs_playing_start_time!=0)
@@ -3688,7 +3740,7 @@ void sip_config_uninit(LinphoneCore *lc)
        linphone_proxy_config_write_to_config_file(lc->config,NULL,i);
 
        for (i=0;i<20;i++){
-               linphone_core_iterate(lc);
+               sal_iterate(lc->sal);
 #ifndef WIN32
                usleep(100000);
 #else
@@ -3825,7 +3877,6 @@ static void linphone_core_uninit(LinphoneCore *lc)
                usleep(50000);
 #endif
        }
-
        if (lc->friends)
                ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
        linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
@@ -3839,12 +3890,13 @@ static void linphone_core_uninit(LinphoneCore *lc)
        lc->msevq=NULL;
        /* save all config */
        net_config_uninit(lc);
-       sip_config_uninit(lc);
        rtp_config_uninit(lc);
+       if (lc->ringstream) ring_stop(lc->ringstream);
        sound_config_uninit(lc);
        video_config_uninit(lc);
        codecs_config_uninit(lc);
        ui_config_uninit(lc);
+       sip_config_uninit(lc);
        if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
        lp_config_destroy(lc->config);
        lc->config = NULL; /* Mark the config as NULL to block further calls */
@@ -3854,7 +3906,6 @@ static void linphone_core_uninit(LinphoneCore *lc)
        lc->call_logs=ms_list_free(lc->call_logs);
 
        linphone_core_free_payload_types();
-
        ortp_exit();
        linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
 }
@@ -3875,8 +3926,24 @@ static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t cu
        }
        lc->netup_time=curtime;
        lc->network_reachable=isReachable;
-}
+       if(!isReachable) {
+               sal_unlisten_ports (lc->sal);
+       } else {
+               apply_transports(lc);
+       }
 
+}
+void linphone_core_refresh_registers(LinphoneCore* lc) {
+       const MSList *elem=linphone_core_get_proxy_config_list(lc);
+       for(;elem!=NULL;elem=elem->next){
+               LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
+               if (linphone_proxy_config_register_enabled(cfg) ) {
+                       cfg->registered=0;
+                       cfg->commit=TRUE;
+               }
+       }
+       
+}
 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
        //first disable automatic mode
        if (lc->auto_net_state_mon) {
@@ -4044,4 +4111,31 @@ const char *linphone_error_to_string(LinphoneReason err){
        }
        return "unknown error";
 }
+/**
+ * enable signaling keep alive
+ */
+void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) {
+       if (enable > 0) {
+               sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
+       } else {
+               sal_set_keepalive_period(lc->sal,0);
+       }
+}
+/**
+ * Is signaling keep alive
+ */
+bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc) {
+       return sal_get_keepalive_period(lc->sal) > 0;
+}
+       
+void linphone_core_start_dtmf_stream(LinphoneCore* lc) {
+       get_dtmf_gen(lc); /*make sure ring stream is started*/
+       lc->ringstream_autorelease=FALSE; /*disable autorelease mode*/
+}
+
+void linphone_core_stop_dtmf_stream(LinphoneCore* lc) {
+       if (lc->ringstream) ring_stop(lc->ringstream);
+       lc->ringstream=NULL;
+}
+