From c29d018bff6e5629a79b1ccb08fd5638c7ea44e3 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 28 Sep 2015 12:00:27 +0200 Subject: [PATCH] Added possibility to disable audio stream in call params + tester for RTT without audio stream --- coreapi/call_params.c | 11 +++++++ coreapi/call_params.h | 14 +++++++++ coreapi/linphonecall.c | 63 +++++++++++++++++++++-------------------- coreapi/linphonecore.c | 2 ++ coreapi/private.h | 1 + tester/message_tester.c | 25 +++++++++++++++- 6 files changed, 85 insertions(+), 31 deletions(-) diff --git a/coreapi/call_params.c b/coreapi/call_params.c index 7308d8abf..58a1bc17e 100644 --- a/coreapi/call_params.c +++ b/coreapi/call_params.c @@ -116,6 +116,12 @@ void linphone_call_params_enable_low_bandwidth(LinphoneCallParams *cp, bool_t en cp->low_bandwidth=enabled; } +void linphone_call_params_enable_audio(LinphoneCallParams *cp, bool_t enabled){ + cp->has_audio=enabled; + if (enabled && cp->audio_dir==LinphoneMediaDirectionInactive) + cp->audio_dir=LinphoneMediaDirectionSendRecv; +} + void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled){ cp->has_video=enabled; if (enabled && cp->video_dir==LinphoneMediaDirectionInactive) @@ -206,6 +212,10 @@ void linphone_call_params_set_session_name(LinphoneCallParams *cp, const char *n if (name) cp->session_name=ms_strdup(name); } +bool_t linphone_call_params_audio_enabled(const LinphoneCallParams *cp){ + return cp->has_audio; +} + bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp){ return cp->has_video; } @@ -277,6 +287,7 @@ LinphoneCallParams * linphone_call_params_new(void) { LinphoneCallParams *cp=belle_sip_object_new(LinphoneCallParams); cp->audio_dir=LinphoneMediaDirectionSendRecv; cp->video_dir=LinphoneMediaDirectionSendRecv; + cp->has_audio=TRUE; cp->realtimetext_enabled = FALSE; return cp; } diff --git a/coreapi/call_params.h b/coreapi/call_params.h index 302f49e13..84b605bea 100644 --- a/coreapi/call_params.h +++ b/coreapi/call_params.h @@ -101,6 +101,13 @@ LINPHONE_PUBLIC void linphone_call_params_enable_early_media_sending(LinphoneCal **/ LINPHONE_PUBLIC void linphone_call_params_enable_low_bandwidth(LinphoneCallParams *cp, bool_t enabled); +/** + * Enable audio stream. + * @param[in] cp LinphoneCallParams object + * @param[in] enabled A boolean value telling whether to enable audio or not. +**/ +LINPHONE_PUBLIC void linphone_call_params_enable_audio(LinphoneCallParams *cp, bool_t enabled); + /** * Enable video stream. * @param[in] cp LinphoneCallParams object @@ -254,6 +261,13 @@ LINPHONE_PUBLIC void linphone_call_params_set_record_file(LinphoneCallParams *cp **/ LINPHONE_PUBLIC void linphone_call_params_set_session_name(LinphoneCallParams *cp, const char *name); +/** + * Tell whether audio is enabled or not. + * @param[in] cp LinphoneCallParams object + * @return A boolean value telling whether audio is enabled or not. +**/ +LINPHONE_PUBLIC bool_t linphone_call_params_audio_enabled(const LinphoneCallParams *cp); + /** * Tell whether video is enabled or not. * @param[in] cp LinphoneCallParams object diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index ac39b1a7a..8f670652c 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -676,34 +676,36 @@ void linphone_call_make_local_media_description(LinphoneCall *call) { else md->bandwidth=linphone_core_get_download_bandwidth(lc); /*set audio capabilities */ - strncpy(md->streams[call->main_audio_stream_index].rtp_addr,linphone_call_get_public_ip_for_stream(call,call->main_audio_stream_index),sizeof(md->streams[call->main_audio_stream_index].rtp_addr)); - strncpy(md->streams[call->main_audio_stream_index].rtcp_addr,linphone_call_get_public_ip_for_stream(call,call->main_audio_stream_index),sizeof(md->streams[call->main_audio_stream_index].rtcp_addr)); - strncpy(md->streams[call->main_audio_stream_index].name,"Audio",sizeof(md->streams[call->main_audio_stream_index].name)-1); - md->streams[call->main_audio_stream_index].rtp_port=call->media_ports[call->main_audio_stream_index].rtp_port; - md->streams[call->main_audio_stream_index].rtcp_port=call->media_ports[call->main_audio_stream_index].rtcp_port; - md->streams[call->main_audio_stream_index].proto=get_proto_from_call_params(params); - md->streams[call->main_audio_stream_index].dir=get_audio_dir_from_call_params(params); - md->streams[call->main_audio_stream_index].type=SalAudio; - if (params->down_ptime) - md->streams[call->main_audio_stream_index].ptime=params->down_ptime; - else - md->streams[call->main_audio_stream_index].ptime=linphone_core_get_download_ptime(lc); - codec_hints.bandwidth_limit=params->audio_bw; - codec_hints.max_codecs=-1; - codec_hints.previously_used=old_md ? old_md->streams[call->main_audio_stream_index].already_assigned_payloads : NULL; - l=make_codec_list(lc, &codec_hints, SalAudio, lc->codecs_conf.audio_codecs); - md->streams[call->main_audio_stream_index].max_rate=get_max_codec_sample_rate(l); - md->streams[call->main_audio_stream_index].payloads=l; - if (call->audiostream && call->audiostream->ms.sessions.rtp_session) { - char* me = linphone_address_as_string_uri_only(call->me); - md->streams[call->main_audio_stream_index].rtp_ssrc=rtp_session_get_send_ssrc(call->audiostream->ms.sessions.rtp_session); - strncpy(md->streams[call->main_audio_stream_index].rtcp_cname,me,sizeof(md->streams[call->main_audio_stream_index].rtcp_cname)); - ms_free(me); + if (params->has_audio) { + strncpy(md->streams[call->main_audio_stream_index].rtp_addr,linphone_call_get_public_ip_for_stream(call,call->main_audio_stream_index),sizeof(md->streams[call->main_audio_stream_index].rtp_addr)); + strncpy(md->streams[call->main_audio_stream_index].rtcp_addr,linphone_call_get_public_ip_for_stream(call,call->main_audio_stream_index),sizeof(md->streams[call->main_audio_stream_index].rtcp_addr)); + strncpy(md->streams[call->main_audio_stream_index].name,"Audio",sizeof(md->streams[call->main_audio_stream_index].name)-1); + md->streams[call->main_audio_stream_index].rtp_port=call->media_ports[call->main_audio_stream_index].rtp_port; + md->streams[call->main_audio_stream_index].rtcp_port=call->media_ports[call->main_audio_stream_index].rtcp_port; + md->streams[call->main_audio_stream_index].proto=get_proto_from_call_params(params); + md->streams[call->main_audio_stream_index].dir=get_audio_dir_from_call_params(params); + md->streams[call->main_audio_stream_index].type=SalAudio; + if (params->down_ptime) + md->streams[call->main_audio_stream_index].ptime=params->down_ptime; + else + md->streams[call->main_audio_stream_index].ptime=linphone_core_get_download_ptime(lc); + codec_hints.bandwidth_limit=params->audio_bw; + codec_hints.max_codecs=-1; + codec_hints.previously_used=old_md ? old_md->streams[call->main_audio_stream_index].already_assigned_payloads : NULL; + l=make_codec_list(lc, &codec_hints, SalAudio, lc->codecs_conf.audio_codecs); + md->streams[call->main_audio_stream_index].max_rate=get_max_codec_sample_rate(l); + md->streams[call->main_audio_stream_index].payloads=l; + if (call->audiostream && call->audiostream->ms.sessions.rtp_session) { + char* me = linphone_address_as_string_uri_only(call->me); + md->streams[call->main_audio_stream_index].rtp_ssrc=rtp_session_get_send_ssrc(call->audiostream->ms.sessions.rtp_session); + strncpy(md->streams[call->main_audio_stream_index].rtcp_cname,me,sizeof(md->streams[call->main_audio_stream_index].rtcp_cname)); + ms_free(me); + } + else + ms_warning("Cannot get audio local ssrc for call [%p]",call); + if (call->main_audio_stream_index > max_index) + max_index = call->main_audio_stream_index; } - else - ms_warning("Cannot get audio local ssrc for call [%p]",call); - if (call->main_audio_stream_index > max_index) - max_index = call->main_audio_stream_index; md->streams[call->main_video_stream_index].proto=md->streams[call->main_audio_stream_index].proto; md->streams[call->main_video_stream_index].dir=get_video_dir_from_call_params(params); @@ -1312,9 +1314,6 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro } discover_mtu(lc,linphone_address_get_domain(from)); - if (sal_custom_header_find(sal_op_get_recv_custom_header(op),"X-RTT")) { - call->current_params->realtimetext_enabled=TRUE; - } return call; } @@ -1411,6 +1410,10 @@ void linphone_call_fix_call_parameters(LinphoneCall *call, SalMediaDescription * } rcp = linphone_call_get_remote_params(call); if (rcp){ + if (call->params->has_audio && !rcp->has_audio){ + ms_message("Call [%p]: disabling audio in our call params because the remote doesn't want it.", call); + call->params->has_audio = FALSE; + } if (call->params->has_video && !rcp->has_video){ ms_message("Call [%p]: disabling video in our call params because the remote doesn't want it.", call); call->params->has_video = FALSE; diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 69326bbe8..9e3c49049 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2696,6 +2696,7 @@ LinphoneCall * linphone_core_start_refered_call(LinphoneCore *lc, LinphoneCall * } if (!params){ + cp->has_audio = call->current_params->has_audio; cp->has_video = call->current_params->has_video; /*start the call to refer-target with video enabled if original call had video*/ } cp->referer=call; @@ -6953,6 +6954,7 @@ void linphone_core_set_media_encryption_mandatory(LinphoneCore *lc, bool_t m) { } void linphone_core_init_default_params(LinphoneCore*lc, LinphoneCallParams *params) { + params->has_audio = TRUE; params->has_video=linphone_core_video_enabled(lc) && lc->video_policy.automatically_initiate; params->media_encryption=linphone_core_get_media_encryption(lc); params->in_conference=FALSE; diff --git a/coreapi/private.h b/coreapi/private.h index 360164331..6ab74a9f3 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -131,6 +131,7 @@ struct _LinphoneCallParams{ LinphonePrivacyMask privacy; LinphoneMediaDirection audio_dir; LinphoneMediaDirection video_dir; + bool_t has_audio; bool_t has_video; bool_t avpf_enabled; /* RTCP feedback messages are enabled */ bool_t real_early_media; /*send real media even during early media (for outgoing calls)*/ diff --git a/tester/message_tester.c b/tester/message_tester.c index a062ce226..95d52b684 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -1282,18 +1282,24 @@ static void file_transfer_io_error_after_destroying_chatroom() { file_transfer_io_error_base("https://www.linphone.org:444/lft.php", TRUE); } -static void real_time_text_message(void) { +static void real_time_text(bool_t audio_stream_enabled) { LinphoneChatRoom *pauline_chat_room; LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneCallParams *marie_params = linphone_core_create_default_call_parameters(marie->lc); LinphoneCall *pauline_call, *marie_call; linphone_call_params_enable_realtime_text(marie_params,TRUE); + if (!audio_stream_enabled) { + linphone_call_params_enable_audio(marie_params,FALSE); + } BC_ASSERT_TRUE(call_with_caller_params(marie, pauline, marie_params)); pauline_call=linphone_core_get_current_call(pauline->lc); marie_call=linphone_core_get_current_call(marie->lc); BC_ASSERT_TRUE(linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(pauline_call))); + if (!audio_stream_enabled) { + BC_ASSERT_TRUE(linphone_call_params_audio_enabled(linphone_call_get_current_params(pauline_call))); + } pauline_chat_room = linphone_call_get_chat_room(pauline_call); BC_ASSERT_PTR_NOT_NULL(pauline_chat_room); @@ -1321,12 +1327,24 @@ static void real_time_text_message(void) { } } } + + if (!audio_stream_enabled) { + int dummy = 0; + wait_for_until(pauline->lc, marie->lc, &dummy, 1, 30000); /* Wait to see if call is dropped after 30 secs */ + BC_ASSERT_FALSE(marie->stat.number_of_LinphoneCallEnd > 0); + BC_ASSERT_FALSE(pauline->stat.number_of_LinphoneCallEnd > 0); + } + end_call(marie, pauline); linphone_call_params_destroy(marie_params); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } +static void real_time_text_message(void) { + real_time_text(TRUE); +} + static void real_time_text_conversation(void) { LinphoneChatRoom *pauline_chat_room, *marie_chat_room; LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); @@ -1426,6 +1444,10 @@ static void real_time_text_conversation(void) { linphone_core_manager_destroy(pauline); } +static void real_time_text_without_audio(void) { + real_time_text(FALSE); +} + void file_transfer_with_http_proxy(void) { if (transport_supported(LinphoneTransportTls)) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); @@ -1476,6 +1498,7 @@ test_t message_tests[] = { {"Transfer io error after destroying chatroom", file_transfer_io_error_after_destroying_chatroom}, {"Real Time Text message", real_time_text_message}, {"Real Time Text conversation", real_time_text_conversation}, + {"Real Time Text without audio", real_time_text_without_audio}, }; test_suite_t message_test_suite = {