Commit 0009e277 authored by Sandrine Avakian's avatar Sandrine Avakian

Added linphone_call_set_params to modify SDP header and attributes.

Added linphone_call_get_params to get local call params used.
Added tests .
parent a4b206ae
......@@ -748,7 +748,7 @@ static void call_updating(SalOp *op, bool_t is_update){
if (rmd == NULL && lp_config_get_int(call->core->config,"sip","sdp_200_ack_follow_video_policy",0)) {
LinphoneCallParams *p=linphone_core_create_call_params(lc, NULL);
ms_message("Applying default policy for offering SDP on call [%p]",call);
linphone_call_set_new_params(call, p);
_linphone_call_set_new_params(call, p);
linphone_call_params_unref(p);
}
linphone_call_make_local_media_description(call);
......
......@@ -4742,13 +4742,29 @@ LinphonePlayer *linphone_call_get_player(LinphoneCall *call){
return call->player;
}
void linphone_call_set_new_params(LinphoneCall *call, const LinphoneCallParams *params){
void linphone_call_set_params(LinphoneCall *call, const LinphoneCallParams *params){
if ( call->state == LinphoneCallOutgoingInit || call->state == LinphoneCallIncomingReceived){
_linphone_call_set_new_params(call, params);
}
else {
ms_error("linphone_call_set_params() invalid state %s to call this function", linphone_call_state_to_string(call->state));
}
}
void _linphone_call_set_new_params(LinphoneCall *call, const LinphoneCallParams *params){
LinphoneCallParams *cp=NULL;
if (params) cp=linphone_call_params_copy(params);
if (call->params) linphone_call_params_unref(call->params);
call->params=cp;
}
const LinphoneCallParams * linphone_call_get_params(LinphoneCall *call){
return call->params;
}
static int send_dtmf_handler(void *data, unsigned int revents){
LinphoneCall *call = (LinphoneCall*)data;
/*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
......@@ -5174,7 +5190,7 @@ int linphone_call_accept_with_params(LinphoneCall *call, const LinphoneCallParam
/* Try to be best-effort in giving real local or routable contact address */
linphone_call_set_contact_op(call);
if (params) {
linphone_call_set_new_params(call, params);
_linphone_call_set_new_params(call, params);
linphone_call_prepare_ice(call, TRUE);
linphone_call_make_local_media_description(call);
sal_call_set_local_media_description(call->op, call->localdesc);
......@@ -5230,7 +5246,7 @@ int linphone_call_accept_early_media_with_params(LinphoneCall *call, const Linph
/* If parameters are passed, update the media description */
if (params) {
linphone_call_set_new_params(call, params);
_linphone_call_set_new_params(call, params);
linphone_call_make_local_media_description(call);
sal_call_set_local_media_description(call->op, call->localdesc);
sal_op_set_sent_custom_header(call->op, params->custom_headers);
......@@ -5303,7 +5319,7 @@ int linphone_call_update(LinphoneCall *call, const LinphoneCallParams *params) {
}
}
#endif /* defined(VIDEO_ENABLED) && defined(BUILD_UPNP) */
linphone_call_set_new_params(call, params);
_linphone_call_set_new_params(call, params);
err = linphone_call_prepare_ice(call, FALSE);
if (err == 1) {
ms_message("Defer call update to gather ICE candidates");
......@@ -5451,7 +5467,7 @@ int _linphone_call_accept_update(LinphoneCall *call, const LinphoneCallParams *p
linphone_call_params_enable_video_multicast(call->params, FALSE);
}
} else {
linphone_call_set_new_params(call, params);
_linphone_call_set_new_params(call, params);
}
if (call->params->has_video && !linphone_core_video_enabled(lc)) {
......
......@@ -378,7 +378,9 @@ BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneCall);
LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params, LinphoneProxyConfig *cfg);
LinphoneCall * linphone_call_new_incoming(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op);
void linphone_call_set_new_params(LinphoneCall *call, const LinphoneCallParams *params);
void _linphone_call_set_new_params(LinphoneCall *call, const LinphoneCallParams *params);
void linphone_call_set_params(LinphoneCall *call, const LinphoneCallParams *params);
const LinphoneCallParams * linphone_call_get_params(LinphoneCall *call);
void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const char *message);
void linphone_call_set_contact_op(LinphoneCall* call);
void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, SalMediaDescription *md);
......
......@@ -1523,6 +1523,260 @@ static void call_with_custom_sdp_attributes(void) {
linphone_core_manager_destroy(pauline);
}
static void call_with_custom_header_or_sdp_cb(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message) {
const char *value;
if (cstate == LinphoneCallOutgoingInit){
LinphoneCallParams *params = linphone_call_params_copy(linphone_call_get_params(call));
linphone_call_params_add_custom_sdp_attribute(params, "working", "maybe");
linphone_call_set_params(call, params);
linphone_call_params_unref(params);
}
else if (cstate == LinphoneCallIncomingReceived){
const LinphoneCallParams *tparams = linphone_call_get_remote_params(call);
LinphoneCallParams *params = linphone_call_params_copy(tparams);
//Check received params
//SDP
value = linphone_call_params_get_custom_sdp_attribute(params, "working");
BC_ASSERT_PTR_NOT_NULL(value);
if (value) BC_ASSERT_STRING_EQUAL(value, "maybe");
//header
value = linphone_call_params_get_custom_header(params, "weather");
BC_ASSERT_PTR_NOT_NULL(value);
if (value) BC_ASSERT_STRING_EQUAL(value, "thunderstorm");
//modify SDP
linphone_call_params_add_custom_sdp_attribute(params, "working", "yes");
linphone_call_set_params(call, params);
linphone_call_params_unref(params);
}
}
static void call_caller_with_custom_header_or_sdp_attributes(void) {
LinphoneCoreManager *callee_mgr = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *caller_mgr = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
LinphoneCall *call_caller = NULL, *call_callee = NULL;
LinphoneCallParams *caller_params; // *callee_params ;
LinphoneCoreVTable *vtable;
LinphoneCallTestParams caller_test_params = {0};
LinphoneCallTestParams callee_test_params = {0};
stats initial_caller=caller_mgr->stat;
stats initial_callee=callee_mgr->stat;
bool_t result=FALSE;
bool_t did_receive_call;
//Create caller params with custom header and custom SDP
caller_params = linphone_core_create_call_params(caller_mgr->lc, NULL);
linphone_call_params_add_custom_header(caller_params, "weather", "thunderstorm");
linphone_call_params_add_custom_sdp_media_attribute(caller_params, LinphoneStreamTypeAudio, "sleeping", "almost");
caller_test_params.base = (LinphoneCallParams*)caller_params;
callee_test_params.base = NULL;
/* TODO: This should be handled correctly inside the liblinphone library but meanwhile handle this here. */
linphone_core_manager_wait_for_stun_resolution(caller_mgr);
linphone_core_manager_wait_for_stun_resolution(callee_mgr);
setup_sdp_handling(&caller_test_params, caller_mgr);
setup_sdp_handling(&callee_test_params, callee_mgr);
// Assign dedicated callback to vtable for caller and callee
vtable = linphone_core_v_table_new();
vtable->call_state_changed = call_with_custom_header_or_sdp_cb;
linphone_core_add_listener(callee_mgr->lc, vtable);
linphone_core_add_listener(caller_mgr->lc, vtable);
//Caller initates the call with INVITE
// caller params not null
BC_ASSERT_PTR_NOT_NULL((call_caller=linphone_core_invite_address_with_params(caller_mgr->lc,callee_mgr->identity,caller_params)));
BC_ASSERT_PTR_NULL(linphone_call_get_remote_params(call_caller)); /*assert that remote params are NULL when no response is received yet*/
// Wait for Incoming received
did_receive_call = wait_for(callee_mgr->lc
,caller_mgr->lc
,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived
,initial_callee.number_of_LinphoneCallIncomingReceived+1);
BC_ASSERT_EQUAL(did_receive_call, !callee_test_params.sdp_simulate_error, int, "%d");
linphone_call_params_unref(caller_params);
sal_default_set_sdp_handling(caller_mgr->lc->sal, SalOpSDPNormal);
sal_default_set_sdp_handling(callee_mgr->lc->sal, SalOpSDPNormal);
// Wait for Outgoing Progress
if (linphone_core_get_calls_nb(callee_mgr->lc)<=1)
BC_ASSERT_TRUE(linphone_core_inc_invite_pending(callee_mgr->lc));
BC_ASSERT_EQUAL(caller_mgr->stat.number_of_LinphoneCallOutgoingProgress,initial_caller.number_of_LinphoneCallOutgoingProgress+1, int, "%d");
LinphoneCallParams *default_params=linphone_core_create_call_params(callee_mgr->lc,call_callee);
ms_message("Created default call params with video=%i", linphone_call_params_video_enabled(default_params));
linphone_core_accept_call_with_params(callee_mgr->lc,call_callee,default_params);
linphone_call_params_unref(default_params);
BC_ASSERT_TRUE(wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallConnected,initial_callee.number_of_LinphoneCallConnected+1));
BC_ASSERT_TRUE(wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallConnected,initial_caller.number_of_LinphoneCallConnected+1));
result = wait_for_until(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_caller.number_of_LinphoneCallStreamsRunning+1, 2000)
&&
wait_for_until(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_callee.number_of_LinphoneCallStreamsRunning+1, 2000);
caller_params = linphone_core_create_call_params(caller_mgr->lc, call_caller);
linphone_call_params_clear_custom_sdp_attributes(caller_params);
linphone_call_params_clear_custom_sdp_media_attributes(caller_params, LinphoneStreamTypeAudio);
linphone_call_params_add_custom_sdp_attribute(caller_params, "weather", "sunny");
linphone_core_update_call(caller_mgr->lc, call_caller, caller_params);
linphone_call_params_unref(caller_params);
end_call(caller_mgr, callee_mgr);
linphone_core_manager_destroy(callee_mgr);
linphone_core_manager_destroy(caller_mgr);
}
static void call_callee_with_custom_header_or_sdp_cb(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message) {
const char *value;
if (cstate == LinphoneCallOutgoingInit){
LinphoneCallParams *params = linphone_call_params_copy(linphone_call_get_params(call));
linphone_call_params_add_custom_sdp_attribute(params, "working", "maybe");
linphone_call_set_params(call, params);
linphone_call_params_unref(params);
}
else if (cstate == LinphoneCallIncomingReceived){
const LinphoneCallParams *tparams = linphone_call_get_remote_params(call);
LinphoneCallParams *params = linphone_call_params_copy(tparams);
value = linphone_call_params_get_custom_sdp_attribute(params, "working");
BC_ASSERT_PTR_NOT_NULL(value);
if (value) BC_ASSERT_STRING_EQUAL(value, "maybe");
linphone_call_set_params(call, params);
linphone_call_params_unref(params);
}
}
static void call_callee_with_custom_header_or_sdp_attributes(void) {
LinphoneCoreManager *callee_mgr = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *caller_mgr = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
LinphoneCall *call_caller = NULL, *call_callee = NULL;
LinphoneCallParams *callee_params, *caller_params ;
LinphoneCoreVTable *vtable;
const char *value;
LinphoneCallTestParams caller_test_params = {0};
LinphoneCallTestParams callee_test_params = {0};
stats initial_caller=caller_mgr->stat;
stats initial_callee=callee_mgr->stat;
bool_t result=FALSE;
bool_t did_receive_call;
const LinphoneCallParams *caller_remote_params;
caller_params = linphone_core_create_call_params(caller_mgr->lc, NULL);
callee_test_params.base = NULL;
caller_test_params.base = NULL;
/* TODO: This should be handled correctly inside the liblinphone library but meanwhile handle this here. */
linphone_core_manager_wait_for_stun_resolution(caller_mgr);
linphone_core_manager_wait_for_stun_resolution(callee_mgr);
setup_sdp_handling(&caller_test_params, caller_mgr);
setup_sdp_handling(&callee_test_params, callee_mgr);
// Assign dedicated callback to vtable for caller and callee
vtable = linphone_core_v_table_new();
vtable->call_state_changed = call_callee_with_custom_header_or_sdp_cb;
linphone_core_add_listener(callee_mgr->lc, vtable);
linphone_core_add_listener(caller_mgr->lc, vtable);
//Caller initates the call with INVITE
// caller params not null
BC_ASSERT_PTR_NOT_NULL((call_caller=linphone_core_invite_address_with_params(caller_mgr->lc,callee_mgr->identity,caller_params)));
BC_ASSERT_PTR_NULL(linphone_call_get_remote_params(call_caller)); /*assert that remote params are NULL when no response is received yet*/
// Wait for Incoming received
did_receive_call = wait_for(callee_mgr->lc
,caller_mgr->lc
,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived
,initial_callee.number_of_LinphoneCallIncomingReceived+1);
BC_ASSERT_EQUAL(did_receive_call, !callee_test_params.sdp_simulate_error, int, "%d");
sal_default_set_sdp_handling(caller_mgr->lc->sal, SalOpSDPNormal);
sal_default_set_sdp_handling(callee_mgr->lc->sal, SalOpSDPNormal);
// Wait for Outgoing Progress
if (linphone_core_get_calls_nb(callee_mgr->lc)<=1)
BC_ASSERT_TRUE(linphone_core_inc_invite_pending(callee_mgr->lc));
BC_ASSERT_EQUAL(caller_mgr->stat.number_of_LinphoneCallOutgoingProgress,initial_caller.number_of_LinphoneCallOutgoingProgress+1, int, "%d");
//Create callee params with custom header and custom SDP
callee_params = linphone_core_create_call_params(callee_mgr->lc,call_callee);
linphone_call_params_add_custom_header(callee_params, "weather", "thunderstorm");
linphone_call_params_add_custom_sdp_media_attribute(callee_params, LinphoneStreamTypeAudio, "sleeping", "almost");
linphone_call_params_add_custom_sdp_attribute(callee_params, "working", "yes");
ms_message("Created default call params with video=%i", linphone_call_params_video_enabled(callee_params));
linphone_core_accept_call_with_params(callee_mgr->lc,call_callee,callee_params);
linphone_call_params_unref(callee_params);
BC_ASSERT_TRUE(wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallConnected,initial_callee.number_of_LinphoneCallConnected+1));
BC_ASSERT_TRUE(wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallConnected,initial_caller.number_of_LinphoneCallConnected+1));
result = wait_for_until(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_caller.number_of_LinphoneCallStreamsRunning+1, 2000)
&&
wait_for_until(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_callee.number_of_LinphoneCallStreamsRunning+1, 2000);
caller_remote_params = linphone_call_get_remote_params(call_caller);
value = linphone_call_params_get_custom_sdp_attribute(caller_remote_params, "working");
BC_ASSERT_PTR_NOT_NULL(value);
if (value) BC_ASSERT_STRING_EQUAL(value, "yes");
//header
value = linphone_call_params_get_custom_header(caller_remote_params, "weather");
BC_ASSERT_PTR_NOT_NULL(value);
if (value) BC_ASSERT_STRING_EQUAL(value, "thunderstorm");
linphone_call_params_unref(caller_params);
end_call(caller_mgr, callee_mgr);
linphone_core_manager_destroy(callee_mgr);
linphone_core_manager_destroy(caller_mgr);
}
void call_paused_resumed_base(bool_t multicast, bool_t with_losses) {
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
......@@ -5493,6 +5747,8 @@ test_t call_tests[] = {
TEST_ONE_TAG("Call with ICE added by reINVITE", ice_added_by_reinvite, "ICE"),
TEST_NO_TAG("Call with custom headers", call_with_custom_headers),
TEST_NO_TAG("Call with custom SDP attributes", call_with_custom_sdp_attributes),
TEST_NO_TAG("Call caller with custom header or sdp", call_caller_with_custom_header_or_sdp_attributes),
TEST_NO_TAG("Call callee with custom header or sdp", call_callee_with_custom_header_or_sdp_attributes),
TEST_NO_TAG("Call established with rejected INFO", call_established_with_rejected_info),
TEST_NO_TAG("Call established with rejected RE-INVITE", call_established_with_rejected_reinvite),
TEST_NO_TAG("Call established with rejected incoming RE-INVITE", call_established_with_rejected_incoming_reinvite),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment