From 4b178dc8b2a7f038a75d1afe2b71a1264453a625 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 22 Feb 2012 18:28:21 +0100 Subject: [PATCH] implement dynamic video add/remove in gtk ui. --- coreapi/linphonecall.c | 1 + coreapi/linphonecore.c | 39 ++++++++++++++++++++++- coreapi/linphonecore.h | 14 ++++++++ coreapi/private.h | 1 + gtk/incall_view.c | 30 ++++++++++++++++++ gtk/linphone.h | 1 + gtk/main.c | 72 +++++++++++++++++++++++++++++++++++++----- gtk/main.ui | 16 +++++++++- 8 files changed, 164 insertions(+), 10 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 888c7659..a384a929 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -359,6 +359,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip); linphone_call_init_common(call, from, to); linphone_core_init_default_params(lc, &call->params); + call->params.has_video &= !!lc->video_policy.automatically_accept; call->localdesc=create_local_media_description (lc,call); call->camera_active=call->params.has_video; if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 68cea9b3..dd41305b 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -756,6 +756,7 @@ static void video_config_read(LinphoneCore *lc){ const char **devices; const MSList *elem; int i; + LinphoneVideoPolicy vpol; /* retrieve all video devices */ elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get()); @@ -778,12 +779,15 @@ static void video_config_read(LinphoneCore *lc){ capture=lp_config_get_int(lc->config,"video","capture",1); display=lp_config_get_int(lc->config,"video","display",1); self_view=lp_config_get_int(lc->config,"video","self_view",1); + vpol.automatically_initiate=lp_config_get_int(lc->config,"video","automatically_initiate",1); + vpol.automatically_accept=lp_config_get_int(lc->config,"video","automatically_accept",1); lc->video_conf.displaytype=lp_config_get_string(lc->config,"video","displaytype",NULL); if(lc->video_conf.displaytype) ms_message("we are using a specific display:%s\n",lc->video_conf.displaytype); linphone_core_enable_video(lc,capture,display); linphone_core_enable_self_view(lc,self_view); + linphone_core_set_video_policy(lc,&vpol); #endif } @@ -1930,6 +1934,7 @@ const char * linphone_core_get_route(LinphoneCore *lc){ void linphone_core_start_refered_call(LinphoneCore *lc, LinphoneCall *call){ if (call->refer_pending){ LinphoneCallParams *cp=linphone_core_create_default_call_parameters(lc); + cp->has_video &= !!lc->video_policy.automatically_initiate; cp->referer=call; ms_message("Starting new call to refered address %s",call->refer_to); call->refer_pending=FALSE; @@ -2082,6 +2087,7 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphonePro LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){ LinphoneCall *call; LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc); + p->has_video &= !!lc->video_policy.automatically_initiate; call=linphone_core_invite_with_params(lc,url,p); linphone_call_params_destroy(p); return call; @@ -2128,7 +2134,8 @@ LinphoneCall * linphone_core_invite_with_params(LinphoneCore *lc, const char *ur **/ LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr){ LinphoneCall *call; - LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc); + LinphoneCallParams *p=linphone_core_create_default_call_parameters(lc); + p->has_video &= !!lc->video_policy.automatically_initiate; call=linphone_core_invite_address_with_params (lc,addr,p); linphone_call_params_destroy(p); return call; @@ -3421,6 +3428,14 @@ void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t di linphone_core_get_upload_bandwidth(lc)); } +bool_t linphone_core_video_supported(LinphoneCore *lc){ +#ifdef VIDEO_ENABLED + return TRUE; +#else + return FALSE; +#endif +} + /** * Returns TRUE if video is enabled, FALSE otherwise. * @ingroup media_parameters @@ -3429,6 +3444,28 @@ bool_t linphone_core_video_enabled(LinphoneCore *lc){ return (lc->video_conf.display || lc->video_conf.capture); } +/** + * Sets the default policy for video. + * This policy defines whether: + * - video shall be initiated by default for outgoing calls + * - video shall be accepter by default for incoming calls +**/ +void linphone_core_set_video_policy(LinphoneCore *lc, const LinphoneVideoPolicy *policy){ + lc->video_policy=*policy; + if (linphone_core_ready(lc)){ + lp_config_set_int(lc->config,"video","automatically_initiate",policy->automatically_initiate); + lp_config_set_int(lc->config,"video","automatically_accept",policy->automatically_accept); + } +} + +/** + * Get the default policy for video. + * See linphone_core_set_video_policy() for more details. +**/ +const LinphoneVideoPolicy *linphone_core_get_video_policy(LinphoneCore *lc){ + return &lc->video_policy; +} + /** * Controls video preview enablement. * diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 4a6fed8b..e2c46bf7 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -209,6 +209,17 @@ typedef enum _LinphoneReason LinphoneReason; const char *linphone_reason_to_string(LinphoneReason err); +/** + * Structure describing policy regarding video streams establishments. +**/ +struct _LinphoneVideoPolicy{ + bool_t automatically_initiate; /**1); linphone_gtk_enable_conference_button(lc,call_list_size>1); update_video_title(); + if (call) linphone_gtk_update_video_button(call); } static gboolean linphone_gtk_start_call_do(GtkWidget *uri_bar){ @@ -766,7 +768,11 @@ void linphone_gtk_answer_clicked(GtkWidget *button){ void linphone_gtk_enable_video(GtkWidget *w){ gboolean val=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); GtkWidget *selfview_item=linphone_gtk_get_widget(linphone_gtk_get_main_window(),"selfview_item"); - linphone_core_enable_video(linphone_gtk_get_core(),val,val); + LinphoneVideoPolicy policy={0}; + policy.automatically_initiate=policy.automatically_accept=val; + linphone_core_enable_video(linphone_gtk_get_core(),TRUE,TRUE); + linphone_core_set_video_policy(linphone_gtk_get_core(),&policy); + gtk_widget_set_sensitive(selfview_item,val); if (val){ linphone_core_enable_video_preview(linphone_gtk_get_core(), @@ -1022,6 +1028,52 @@ static void linphone_gtk_notify(LinphoneCall *call, const char *msg){ } } +static void on_call_updated_response(GtkWidget *dialog, gint responseid, LinphoneCall *call){ + if (linphone_call_get_state(call)==LinphoneCallUpdatedByRemote){ + LinphoneCore *lc=linphone_call_get_core(call); + LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call)); + linphone_call_params_enable_video(params,responseid==GTK_RESPONSE_YES); + linphone_core_accept_call_update(lc,call,params); + linphone_call_params_destroy(params); + } + linphone_call_unref(call); + g_source_remove_by_user_data(dialog); + gtk_widget_destroy(dialog); +} + +static void on_call_updated_timeout(GtkWidget *dialog){ + gtk_widget_destroy(dialog); +} + +static void linphone_gtk_call_updated_by_remote(LinphoneCall *call){ + LinphoneCore *lc=linphone_call_get_core(call); + const LinphoneVideoPolicy *pol=linphone_core_get_video_policy(lc); + const LinphoneCallParams *rparams=linphone_call_get_remote_params(call); + const LinphoneCallParams *current_params=linphone_call_get_current_params(call); + gboolean video_requested=linphone_call_params_video_enabled(rparams); + gboolean video_used=linphone_call_params_video_enabled(current_params); + g_message("Video used=%i, video requested=%i, automatically_accept=%i", + video_used,video_requested,pol->automatically_accept); + if (video_used==FALSE && video_requested && !pol->automatically_accept){ + linphone_core_defer_call_update(lc,call); + { + const LinphoneAddress *addr=linphone_call_get_remote_address(call); + GtkWidget *dialog; + const char *dname=linphone_address_get_display_name(addr); + if (dname==NULL) dname=linphone_address_get_username(addr); + if (dname==NULL) dname=linphone_address_get_domain(addr); + dialog=gtk_message_dialog_new(GTK_WINDOW(linphone_gtk_get_main_window()), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_YES_NO, + _("%s proposed to start video. Do you accept ?"),dname); + g_signal_connect(G_OBJECT(dialog),"response",(GCallback)on_call_updated_response,linphone_call_ref(call)); + g_timeout_add(20000,(GSourceFunc)on_call_updated_timeout,dialog); + gtk_widget_show(dialog); + } + } +} + static void linphone_gtk_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cs, const char *msg){ switch(cs){ case LinphoneCallOutgoingInit: @@ -1033,6 +1085,9 @@ static void linphone_gtk_call_state_changed(LinphoneCore *lc, LinphoneCall *call case LinphoneCallStreamsRunning: linphone_gtk_in_call_view_set_in_call(call); break; + case LinphoneCallUpdatedByRemote: + linphone_gtk_call_updated_by_remote(call); + break; case LinphoneCallError: linphone_gtk_in_call_view_terminate (call,msg); break; @@ -1345,7 +1400,8 @@ static void linphone_gtk_connect_digits(void){ } static void linphone_gtk_check_menu_items(void){ - bool_t video_enabled=linphone_core_video_enabled(linphone_gtk_get_core()); + const LinphoneVideoPolicy *pol=linphone_core_get_video_policy(linphone_gtk_get_core()); + bool_t video_enabled=pol->automatically_accept && pol->automatically_initiate; bool_t selfview=linphone_gtk_get_ui_config_int("videoselfview",VIDEOSELFVIEW_DEFAULT); GtkWidget *selfview_item=linphone_gtk_get_widget( linphone_gtk_get_main_window(),"selfview_item"); @@ -1491,13 +1547,13 @@ gboolean linphone_gtk_close(GtkWidget *mw){ #ifdef HAVE_GTK_OSX static gboolean on_window_state_event(GtkWidget *w, GdkEventWindowState *event){ - if ((event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) ||(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN) ){ - linphone_core_enable_video_preview(linphone_gtk_get_core(),FALSE); - }else{ - linphone_core_enable_video_preview(linphone_gtk_get_core(), + if ((event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) ||(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN) ){ + linphone_core_enable_video_preview(linphone_gtk_get_core(),FALSE); + }else{ + linphone_core_enable_video_preview(linphone_gtk_get_core(), linphone_gtk_get_ui_config_int("videoselfview",VIDEOSELFVIEW_DEFAULT) && linphone_core_video_enabled(linphone_gtk_get_core())); - } - return FALSE; + } + return FALSE; } #endif diff --git a/gtk/main.ui b/gtk/main.ui index d4c061a4..96647fe4 100644 --- a/gtk/main.ui +++ b/gtk/main.ui @@ -293,7 +293,7 @@ True False True - center + spread Pause @@ -308,6 +308,20 @@ 0 + + + Video + True + True + True + False + + + False + True + 1 + + False -- 2.39.2