Commit cc00e4e1 authored by Andrea Gianarda's avatar Andrea Gianarda
Browse files

Improve logging of events added to the mainDb

Add participant removed event to the main DB without updating the DB content
Try to terminate event only if it not NULL in subscribe_loosing_dialog_2
Fix test "Call accepted while callee is updating another one"
Preempt sound resources only if media_resources_mode is set to unique. It fixes test "2 Video call accepted in send only" because the core receiving the calls is used in server mode
Bring back LeaksMemory tag to test "Group chat room subscription denied". Leaks are caused by network up and down
Destroy cores if calls are not received in push incoming call suite
parent 1b337066
......@@ -156,7 +156,7 @@ static void linphone_core_zrtp_cache_close(LinphoneCore *lc);
void linphone_core_zrtp_cache_db_init(LinphoneCore *lc, const char *fileName);
static void _linphone_core_stop_async_end(LinphoneCore *lc);
static LinphoneStatus _linphone_core_set_sip_transports(LinphoneCore *lc, const LinphoneSipTransports * tr_config, bool_t applyIt);
bool_t linphone_core_sound_resources_need_locking(const LinphoneCallParams *params);
bool_t linphone_core_sound_resources_need_locking(LinphoneCore *lc, const LinphoneCallParams *params);
#include "enum.h"
#include "contact_providers_priv.h"
......@@ -4230,9 +4230,18 @@ void linphone_configure_op_2(LinphoneCore *lc, SalOp *op, const LinphoneAddress
linphone_configure_op_with_proxy(lc, op, dest, headers, with_contact, linphone_core_lookup_proxy_by_identity(lc, local));
}
void linphone_core_set_media_resource_mode (LinphoneCore *lc, LinphoneMediaResourceMode mode) {
linphone_config_set_int(linphone_core_get_config(lc), "misc", "media_resources_mode", mode);
}
LinphoneMediaResourceMode linphone_core_get_media_resource_mode (const LinphoneCore *lc) {
return (LinphoneMediaResourceMode)linphone_config_get_int(linphone_core_get_config(lc), "misc", "media_resources_mode", LinphoneExclusiveMediaResources);
}
// This function states whether a locking of the sound resources is required based on the given call parameters
bool_t linphone_core_sound_resources_need_locking(const LinphoneCallParams *params){
return (linphone_call_params_audio_enabled(params) &&
bool_t linphone_core_sound_resources_need_locking(LinphoneCore *lc, const LinphoneCallParams *params){
return ((linphone_core_get_media_resource_mode(lc) == LinphoneExclusiveMediaResources) &&
linphone_call_params_audio_enabled(params) &&
linphone_call_params_get_audio_direction(params) != LinphoneMediaDirectionInactive &&
linphone_call_params_get_local_conference_mode(params) == FALSE
);
......@@ -4254,7 +4263,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const
LinphoneCall *current_call = linphone_core_get_current_call(lc);
if (current_call) {
LinphoneCallState current_call_state = linphone_call_get_state (current_call);
if (linphone_core_sound_resources_need_locking(params)
if (linphone_core_sound_resources_need_locking(lc, params)
&& ((current_call_state != LinphoneCallPausing) && (current_call_state != LinphoneCallPaused) && !Call::toCpp(current_call)->canSoundResourcesBeFreed())) {
ms_error("linphone_core_invite_address_with_params(): sound are locked by another call and they cannot be freed. Call attempt is rejected.");
return NULL;
......@@ -4296,7 +4305,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const
// Try to free up resources after adding it to the call list.
// linphone_core_preempt_sound_resources tries to pause a call only if there is more than one in the list of core stored in the core
if (linphone_core_sound_resources_need_locking(params) && (linphone_core_preempt_sound_resources(lc) == -1)) {
if (linphone_core_sound_resources_need_locking(lc, params) && (linphone_core_preempt_sound_resources(lc) == -1)) {
ms_error("linphone_core_invite_address_with_params(): sound is required for this call but another call is already locking the sound resource. The call is automatically terminated.");
linphone_call_terminate(call);
return NULL;
......@@ -4465,8 +4474,14 @@ int linphone_core_preempt_sound_resources(LinphoneCore *lc){
return 0;
}
ms_message("Pausing automatically the current call.");
err = Call::toCpp(current_call)->pause();
shared_ptr<LinphonePrivate::Call> cpp_call = Call::toCpp(current_call)->getSharedFromThis();
auto ms = static_pointer_cast<LinphonePrivate::MediaSession>(cpp_call->getActiveSession());
if (sal_media_description_has_dir(L_GET_PRIVATE(ms)->getResultDesc(), SalStreamSendOnly)) {
ms_error("Trying to empty resources of a call whose SAL media direction is SendOnly - If you wish to do so, please set configuration parameter media_resources_mode to shared: linphone_core_set_media_resource_mode (lc, LinphoneSharedMediaResources)");
} else {
ms_message("Pausing automatically the current call.");
err = cpp_call->pause();
}
}
return err;
}
......
......@@ -3919,6 +3919,22 @@ LINPHONE_PUBLIC void linphone_core_enable_conference_server (LinphoneCore *core,
*/
LINPHONE_PUBLIC bool_t linphone_core_conference_server_enabled (const LinphoneCore *core);
/**
* Sets the media resources mode. Value values are: unique and shared.
* When the mode is set to unique, then only one call in the state StreamsRunning is allowed. While acepting a call, the core will try to free media resource used by the current call. If it is unsuccessful, then the call is not accepted.
* If mode is set to shared, then the media resources of the current call (if any) are not emptied when taking a new call. If the user whishes to free them, he/she is responsible to call linphone_core_preempt_sound_resources himself/herself
* @param core A #LinphoneCore object @notnil
* @param mode the chosen mode
*/
LINPHONE_PUBLIC void linphone_core_set_media_resource_mode (LinphoneCore *core, LinphoneMediaResourceMode mode);
/**
* This function returns the media resource mode for this core
* @param core A #LinphoneCore object @notnil
* @return The media resource mode
*/
LINPHONE_PUBLIC LinphoneMediaResourceMode linphone_core_get_media_resource_mode (const LinphoneCore *core);
/**
* @}
*/
......
......@@ -678,6 +678,15 @@ typedef enum _LinphoneMediaDirection {
LinphoneMediaDirectionSendRecv, /** send receive*/
} LinphoneMediaDirection;
/**
* @brief Media resource usage.
* @ingroup media_parameters
**/
typedef enum _LinphoneMediaResourceMode {
LinphoneExclusiveMediaResources, /**< Media resources are not shared */
LinphoneSharedMediaResources, /**< Media resources are shared */
} LinphoneMediaResourceMode;
/**
* @brief Enum describing type of media encryption types.
* @ingroup media_parameters
......
......@@ -364,7 +364,8 @@ void ServerGroupChatRoomPrivate::removeParticipant (const shared_ptr<Participant
queuedMessages.erase(participant->getAddress().asString());
q->getConference()->notifyParticipantRemoved(time(nullptr), false, participant);
shared_ptr<ConferenceParticipantEvent> event = q->getConference()->notifyParticipantRemoved(time(nullptr), false, participant);
q->getCore()->getPrivate()->mainDb->addConferenceParticipantEventToDb(event);
if (!isAdminLeft())
designateAdmin();
......
......@@ -1971,7 +1971,6 @@ void MediaSessionPrivate::startAccept(){
L_Q();
shared_ptr<Call> currentCall = q->getCore()->getCurrentCall();
lInfo() << "Core " << q->getCore().get() << " session " << q->getSharedFromThis().get() << " current call session " << (currentCall ? currentCall->getActiveSession().get() : nullptr);
// If the core in a call, request to empty sound resources only if this call is not the call the core is currently in
bool isThisNotCurrentMediaSession = currentCall && (currentCall->getActiveSession() != q->getSharedFromThis());
......@@ -1986,7 +1985,7 @@ lInfo() << "Core " << q->getCore().get() << " session " << q->getSharedFromThis(
// Try to preempt sound resources if the core is in a call or conference that are not the current ones
if (isThisNotCurrentConference || isThisNotCurrentMediaSession) {
if (linphone_core_preempt_sound_resources(q->getCore()->getCCore()) != 0) {
if ((linphone_core_get_media_resource_mode(q->getCore()->getCCore()) == LinphoneExclusiveMediaResources) && linphone_core_preempt_sound_resources(q->getCore()->getCCore()) != 0) {
lInfo() << "Delaying call to " << __func__ << " for media session (local addres " << q->getLocalAddress().asString() << " remote address " << q->getRemoteAddress()->asString() << ") in state " << Utils::toString(state) << " because sound resources cannot be preempted";
pendingActions.push([this] {this->startAccept();});
return;
......
......@@ -163,7 +163,7 @@ private:
long long insertConferenceChatMessageEvent (const std::shared_ptr<EventLog> &eventLog);
void updateConferenceChatMessageEvent(const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr, bool executeAction = true);
long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSecurityEvent (const std::shared_ptr<EventLog> &eventLog);
......
......@@ -1088,7 +1088,8 @@ long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr<EventLo
long long MainDbPrivate::insertConferenceParticipantEvent (
const shared_ptr<EventLog> &eventLog,
long long *chatRoomId
long long *chatRoomId,
bool executeAction
) {
#ifdef HAVE_DB_STORAGE
long long curChatRoomId;
......@@ -1106,20 +1107,22 @@ long long MainDbPrivate::insertConferenceParticipantEvent (
*dbSession.getBackendSession() << "INSERT INTO conference_participant_event (event_id, participant_sip_address_id)"
" VALUES (:eventId, :participantAddressId)", soci::use(eventId), soci::use(participantAddressId);
bool isAdmin = eventLog->getType() == EventLog::Type::ConferenceParticipantSetAdmin;
switch (eventLog->getType()) {
case EventLog::Type::ConferenceParticipantAdded:
case EventLog::Type::ConferenceParticipantSetAdmin:
case EventLog::Type::ConferenceParticipantUnsetAdmin:
insertChatRoomParticipant(curChatRoomId, participantAddressId, isAdmin);
break;
if (executeAction) {
bool isAdmin = eventLog->getType() == EventLog::Type::ConferenceParticipantSetAdmin;
switch (eventLog->getType()) {
case EventLog::Type::ConferenceParticipantAdded:
case EventLog::Type::ConferenceParticipantSetAdmin:
case EventLog::Type::ConferenceParticipantUnsetAdmin:
insertChatRoomParticipant(curChatRoomId, participantAddressId, isAdmin);
break;
case EventLog::Type::ConferenceParticipantRemoved:
deleteChatRoomParticipant(curChatRoomId, participantAddressId);
break;
case EventLog::Type::ConferenceParticipantRemoved:
deleteChatRoomParticipant(curChatRoomId, participantAddressId);
break;
default:
break;
default:
break;
}
}
if (chatRoomId)
......@@ -2216,7 +2219,7 @@ bool MainDb::addEvent (const shared_ptr<EventLog> &eventLog) {
long long eventId = -1;
EventLog::Type type = eventLog->getType();
lInfo() << "MainDb::addEvent() of type " << static_cast<int>(type);
lInfo() << "MainDb::addEvent() of type " << type << " (value " << static_cast<int>(type) << ")";
switch (type) {
case EventLog::Type::None:
return false;
......@@ -3468,6 +3471,15 @@ void MainDb::updateChatRoomConferenceId (ConferenceId oldConferenceId, const Con
#endif
}
long long MainDb::addConferenceParticipantEventToDb (
const shared_ptr<EventLog> &eventLog,
long long *chatRoomId
) {
L_D();
return d->insertConferenceParticipantEvent(eventLog, chatRoomId, false);
}
void MainDb::migrateBasicToClientGroupChatRoom (
const shared_ptr<AbstractChatRoom> &basicChatRoom,
const shared_ptr<AbstractChatRoom> &clientGroupChatRoom
......
......@@ -176,6 +176,8 @@ public:
void insertChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom, unsigned int notifyId = 0);
void deleteChatRoom (const ConferenceId &conferenceId);
void updateChatRoomConferenceId (ConferenceId oldConferenceId, const ConferenceId &newConferenceId);
long long addConferenceParticipantEventToDb (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
void enableChatRoomMigration (const ConferenceId &conferenceId, bool enable);
void migrateBasicToClientGroupChatRoom (
......
......@@ -816,7 +816,7 @@ static void call_accepted_while_another_one_is_updating(bool_t update_from_calle
const LinphoneCallParams *old_params = linphone_call_get_params(call_to_update);
LinphoneCallParams * new_params = linphone_call_params_copy(old_params);
linphone_call_params_enable_video (new_params, TRUE);
BC_ASSERT_TRUE(linphone_call_update(call_to_update, new_params));
linphone_call_update(call_to_update, new_params);
linphone_call_params_unref (new_params);
}
}
......@@ -830,23 +830,30 @@ static void call_accepted_while_another_one_is_updating(bool_t update_from_calle
if (update_from_callee) {
BC_ASSERT_TRUE(wait_for_list(lcs, &phead->stat.number_of_LinphoneCallUpdatedByRemote, 1, 5000));
BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallUpdating, 1, 5000));
} else {
BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallUpdatedByRemote, 1, 5000));
BC_ASSERT_TRUE(wait_for_list(lcs, &phead->stat.number_of_LinphoneCallUpdating, 1, 5000));
}
BC_ASSERT_TRUE(wait_for_list(lcs, &phead->stat.number_of_LinphoneCallStreamsRunning, 2, 5000));
BC_ASSERT_TRUE(wait_for_list(lcs, &phead->stat.number_of_LinphoneCallPausedByRemote, 1, 5000));
if (update_from_callee) {
BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallUpdating, no_callers, 5000));
} else {
BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallUpdatedByRemote, no_callers, 5000));
}
// Only one call is not paused
unsigned int no_call_paused = no_callers - 1;
BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallPausing, no_call_paused, 5000));
BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallPaused, no_call_paused, 5000));
const LinphoneAddress *phead_uri = phead->identity;
LinphoneCall * marie_call = linphone_core_get_call_by_remote_address(marie->lc, linphone_address_as_string(phead_uri));
BC_ASSERT_PTR_NOT_NULL(marie_call);
const LinphoneCallParams *marie_params = linphone_call_get_params(marie_call);
BC_ASSERT_TRUE(linphone_call_params_video_enabled(marie_params));
LinphoneCall * phead_call = linphone_core_get_current_call(phead->lc);
BC_ASSERT_PTR_NOT_NULL(phead_call);
const LinphoneCallParams *phead_params = linphone_call_get_params(phead_call);
BC_ASSERT_TRUE(linphone_call_params_video_enabled(phead_params));
LinphoneCall * pcall = NULL;
unsigned int no_paused_by_remote = 0;
LinphoneCoreManager * pm = NULL;
......@@ -1107,8 +1114,8 @@ test_t multi_call_tests[] = {
TEST_NO_TAG("Incoming call accepted when outgoing call in progress", incoming_call_accepted_when_outgoing_call_in_progress),
TEST_NO_TAG("Incoming call accepted when outgoing call in outgoing ringing", incoming_call_accepted_when_outgoing_call_in_outgoing_ringing),
TEST_NO_TAG("Incoming call accepted when outgoing call in outgoing ringing early media", incoming_call_accepted_when_outgoing_call_in_outgoing_ringing_early_media),
TEST_ONE_TAG("Call accepted while callee is updating another one", call_accepted_while_callee_is_updating_another_one, "ICE"),
TEST_ONE_TAG("Call accepted while caller is updating to same callee", call_accepted_while_caller_is_updating_to_same_callee, "ICE"),
TEST_NO_TAG("Call accepted while callee is updating another one", call_accepted_while_callee_is_updating_another_one),
TEST_NO_TAG("Call accepted while caller is updating to same callee", call_accepted_while_caller_is_updating_to_same_callee),
TEST_ONE_TAG("Call with ICE negotiations ending while accepting call", call_with_ice_negotiations_ending_while_accepting_call, "ICE"),
TEST_ONE_TAG("Call with ICE negotiations ending while accepting call back to back", call_with_ice_negotiations_ending_while_accepting_call_back_to_back, "ICE"),
TEST_NO_TAG("Simple call transfer", simple_call_transfer),
......
......@@ -94,12 +94,12 @@ void simple_push_call_base(bool_t push, bool_t canceled, bool_t decline, bool_t
,initial_callee.number_of_LinphoneCallIncomingReceived+1, 12000);
BC_ASSERT_EQUAL(did_receive_call, 1, int, "%d");
if (!did_receive_call) return;
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallReleased,1));
if (did_receive_call) {
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallReleased,1));
}
goto end;
} else {
......@@ -118,7 +118,7 @@ void simple_push_call_base(bool_t push, bool_t canceled, bool_t decline, bool_t
,initial_callee.number_of_LinphoneCallIncomingReceived+1, 12000);
BC_ASSERT_EQUAL(did_receive_call, 1, int, "%d");
if (!did_receive_call) return;
if (!did_receive_call) goto end;
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneCoreFirstCallStarted, 1, int, "%d");
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCoreFirstCallStarted, 1, int, "%d");
......
......@@ -1433,12 +1433,14 @@ static void accept_call_in_send_only_with_ice(void) {
accept_call_in_send_base(TRUE);
}
// The goal of this test is to verify that 2 calls with streams in send only can be taken at the same time
void two_accepted_call_in_send_only(void) {
LinphoneCoreManager *pauline, *marie, *laure;
bctbx_list_t *lcs=NULL;
marie = linphone_core_manager_new("marie_rc");
linphone_core_set_use_files(marie->lc, TRUE);
linphone_core_set_media_resource_mode (marie->lc, LinphoneSharedMediaResources);
pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
laure = linphone_core_manager_new("laure_rc_udp");
......@@ -1451,16 +1453,6 @@ void two_accepted_call_in_send_only(void) {
reset_counters(&marie->stat);
accept_call_in_send_only_base(laure,marie,lcs);
int no_active_calls_stream_running = 0;
bctbx_list_t *calls = bctbx_list_copy(linphone_core_get_calls(marie->lc));
for (bctbx_list_t *it = calls; it; it = bctbx_list_next(it)) {
LinphoneCall *call = (LinphoneCall *)bctbx_list_get_data(it);
no_active_calls_stream_running += (linphone_call_get_state(call) == LinphoneCallStreamsRunning) ? 1 : 0;
}
bctbx_list_free(calls);
BC_ASSERT_EQUAL(no_active_calls_stream_running,1, int, "%d");
end_call(pauline, marie);
end_call(laure, marie);
......
......@@ -341,8 +341,11 @@ static void subscribe_loosing_dialog_2(void) {
BC_ASSERT_TRUE(wait_for_list(lcs,NULL,0,2000));
//now try a terminate the dialog
linphone_event_terminate(pauline->lev);
BC_ASSERT_PTR_NOT_NULL(pauline->lev);
if (pauline->lev) {
linphone_event_terminate(pauline->lev);
}
BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionTerminated,1,5000));
/*let expire the incoming subscribe received by pauline */
BC_ASSERT_TRUE(wait_for_list(lcs,NULL,0,3000));
......
......@@ -6220,7 +6220,7 @@ test_t group_chat_tests[] = {
TEST_NO_TAG("New device after group chat room creation", group_chat_room_new_device_after_creation),
TEST_ONE_TAG("Chat room list subscription", group_chat_room_list_subscription, "LeaksMemory"),
TEST_ONE_TAG("Complex participant removal scenario", group_chat_room_complex_participant_removal_scenario, "LeaksMemory"),
TEST_NO_TAG("Group chat room subscription denied", group_chat_room_subscription_denied),
TEST_ONE_TAG("Group chat room subscription denied", group_chat_room_subscription_denied, "LeaksMemory" /*due network up/down*/),
TEST_ONE_TAG("Search friend result chat room participants", search_friend_chat_room_participants, "MagicSearch"),
TEST_ONE_TAG("Client loose context of a chatroom", group_chat_loss_of_client_context, "LeaksMemory"),
TEST_ONE_TAG("Participant removed then added", participant_removed_then_added, "LeaksMemory" /*due to core restart*/),
......
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