From b7c6893d274bc3d646da066fbc9f7457e75b83c8 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Wed, 17 Sep 2014 14:58:56 +0200 Subject: [PATCH] Video source reuse API --- coreapi/linphonecall.c | 34 +++++++++++++++++++++++++++------- coreapi/linphonecore.c | 16 +++++++++++++++- coreapi/linphonecore.h | 18 ++++++++++++++++++ coreapi/private.h | 1 + 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 50cdf48fa..3ab82d28a 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -1108,7 +1108,7 @@ const LinphoneCallParams * linphone_call_get_current_params(LinphoneCall *call){ const LinphoneCallParams * linphone_call_get_remote_params(LinphoneCall *call){ if (call->op){ LinphoneCallParams *cp; - SalMediaDescription *md; + SalMediaDescription *md; if (call->remote_params != NULL) linphone_call_params_unref(call->remote_params); cp = call->remote_params = linphone_call_params_new(); md=sal_call_get_remote_media_description(call->op); @@ -2025,12 +2025,17 @@ static void linphone_call_start_video_stream(LinphoneCall *call, const char *cna int used_pt=-1; char rtcp_tool[128]={0}; const SalStreamDescription *vstream; + MSFilter* source = NULL; + bool_t reused_preview = FALSE; snprintf(rtcp_tool,sizeof(rtcp_tool)-1,"%s-%s",linphone_core_get_user_agent_name(),linphone_core_get_user_agent_version()); /* shutdown preview */ if (lc->previewstream!=NULL) { - video_preview_stop(lc->previewstream); + + if( lc->video_conf.reuse_preview_source == FALSE) video_preview_stop(lc->previewstream); + else source = video_preview_stop_reuse_source(lc->previewstream); + lc->previewstream=NULL; } @@ -2105,16 +2110,31 @@ static void linphone_call_start_video_stream(LinphoneCall *call, const char *cna video_stream_set_device_rotation(call->videostream, lc->device_rotation); video_stream_set_rtcp_information(call->videostream, cname, rtcp_tool); video_stream_set_freeze_on_error(call->videostream, lp_config_get_int(lc->config, "video", "freeze_on_error", 0)); - video_stream_start(call->videostream, - call->video_profile, rtp_addr, vstream->rtp_port, - rtcp_addr, - linphone_core_rtcp_enabled(lc) ? (vstream->rtcp_port ? vstream->rtcp_port : vstream->rtp_port+1) : 0, - used_pt, linphone_core_get_video_jittcomp(lc), cam); + if( lc->video_conf.reuse_preview_source && source ){ + ms_message("video_stream_start_with_source kept: %p", source); + video_stream_start_with_source(call->videostream, + call->video_profile, rtp_addr, vstream->rtp_port, + rtcp_addr, + linphone_core_rtcp_enabled(lc) ? (vstream->rtcp_port ? vstream->rtcp_port : vstream->rtp_port+1) : 0, + used_pt, linphone_core_get_video_jittcomp(lc), cam, source); + reused_preview = TRUE; + } else { + video_stream_start(call->videostream, + call->video_profile, rtp_addr, vstream->rtp_port, + rtcp_addr, + linphone_core_rtcp_enabled(lc) ? (vstream->rtcp_port ? vstream->rtcp_port : vstream->rtp_port+1) : 0, + used_pt, linphone_core_get_video_jittcomp(lc), cam); + } } }else ms_warning("No video stream accepted."); }else{ ms_message("No valid video stream defined."); } + if( reused_preview == FALSE && source != NULL ){ + /* destroy not-reused source filter */ + ms_warning("Video preview (%p) not reused: destroying it.", source); + ms_filter_destroy(source); + } #endif } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index dd22a0b9f..e1b289275 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -692,7 +692,7 @@ static void build_video_devices_table(LinphoneCore *lc){ static void video_config_read(LinphoneCore *lc){ #ifdef VIDEO_ENABLED - int capture, display, self_view; + int capture, display, self_view, reuse_source; int automatic_video=1; #endif const char *str; @@ -721,12 +721,14 @@ 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); + reuse_source=lp_config_get_int(lc->config,"video","reuse_source",0); vpol.automatically_initiate=lp_config_get_int(lc->config,"video","automatically_initiate",automatic_video); vpol.automatically_accept=lp_config_get_int(lc->config,"video","automatically_accept",automatic_video); linphone_core_enable_video_capture(lc, capture); linphone_core_enable_video_display(lc, display); linphone_core_enable_video_preview(lc,lp_config_get_int(lc->config,"video","show_local",0)); linphone_core_enable_self_view(lc,self_view); + linphone_core_enable_video_source_reuse(lc, reuse_source); linphone_core_set_video_policy(lc,&vpol); #endif } @@ -4593,6 +4595,18 @@ void linphone_core_enable_video_display(LinphoneCore *lc, bool_t enable) { reapply_network_bandwidth_settings(lc); } +void linphone_core_enable_video_source_reuse(LinphoneCore* lc, bool_t enable){ +#ifndef VIDEO_ENABLED + if (enable == TRUE) { + ms_warning("Cannot enable video display, this version of linphone was built without video support."); + } +#endif + lc->video_conf.reuse_preview_source = enable; + if( linphone_core_ready(lc) ){ + lp_config_set_int(lc->config, "video", "reuse_source", lc->video_conf.reuse_preview_source); + } +} + bool_t linphone_core_video_capture_enabled(LinphoneCore *lc) { return lc->video_conf.capture; } diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 39a1efd49..86feccd14 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -2486,6 +2486,24 @@ LINPHONE_PUBLIC void linphone_core_enable_video_capture(LinphoneCore *lc, bool_t **/ LINPHONE_PUBLIC void linphone_core_enable_video_display(LinphoneCore *lc, bool_t enable); + +/** + * Enable or disable video source reuse when switching from preview to actual video call. + * + * This source reuse is useful when you always display the preview, even before calls are initiated. + * By keeping the video source for the transition to a real video call, you will smooth out the + * source close/reopen cycle. + * + * This function does not have any effect durfing calls. It just indicates the #LinphoneCore to + * initiate future calls with video source reuse or not. + * Also, at the end of a video call, the source will be closed whatsoever for now. + * @param[in] lc #LinphoneCore object + * @param[in] enable TRUE to enable video source reuse. FALSE to disable it for subsequent calls. + * @ingroup media_parameters + * + */ +LINPHONE_PUBLIC void linphone_core_enable_video_source_reuse(LinphoneCore* lc, bool_t enable); + /** * Tells whether video capture is enabled. * @param[in] lc #LinphoneCore object. diff --git a/coreapi/private.h b/coreapi/private.h index afd6b9509..c1c5a31ad 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -632,6 +632,7 @@ typedef struct video_config{ bool_t show_local; bool_t display; bool_t selfview; /*during calls*/ + bool_t reuse_preview_source; }video_config_t; typedef struct ui_config