Commit 0be5c584 authored by DanmeiChen's avatar DanmeiChen
Browse files

fix destroy core

parent 03144434
......@@ -6906,7 +6906,7 @@ void _linphone_core_stop_async_end(LinphoneCore *lc) {
// Call uninit here because there may be the need to access DB while unregistering
L_GET_PRIVATE_FROM_C_OBJECT(lc)->uninit();
lc->chat_rooms = bctbx_list_free_with_data(lc->chat_rooms, (bctbx_list_free_func)linphone_chat_room_unref);
getPlatformHelpers(lc)->onLinphoneCoreStop();
if (lc->platform_helper) getPlatformHelpers(lc)->onLinphoneCoreStop();
/* save all config */
......@@ -6987,11 +6987,13 @@ void _linphone_core_stop_async_end(LinphoneCore *lc) {
lc->factory = NULL;
#if TARGET_OS_IPHONE
getPlatformHelpers(lc)->stop();
/* this will unlock the other Linphone Shared Core that are waiting to start (if any).
We need to unlock them at the very end of the stopping process otherwise two Cores will
process at the same time until this one is finally stopped */
LinphonePrivate::uninitSharedCore(lc);
if (lc->platform_helper) {
getPlatformHelpers(lc)->stop();
/* this will unlock the other Linphone Shared Core that are waiting to start (if any).
We need to unlock them at the very end of the stopping process otherwise two Cores will
process at the same time until this one is finally stopped */
LinphonePrivate::uninitSharedCore(lc);
}
#else
if (lc->platform_helper) delete getPlatformHelpers(lc);
lc->platform_helper = NULL;
......
......@@ -22,15 +22,16 @@
#import <UserNotifications/UserNotifications.h>
@interface IosObject : NSObject {
std::shared_ptr<LinphonePrivate::Core> pcore;
std::weak_ptr<LinphonePrivate::Core> pcore;
}
- (id)initWithCore:(std::shared_ptr<LinphonePrivate::Core>)core;
- (std::shared_ptr<LinphonePrivate::Core>)getCore;
@end
/*
Used only by mais core.
Used only by main core.
IosAppDelegate is an object taking care of all application delegate's notifications and iteartion:
UIApplicationDidEnterBackgroundNotification
UIApplicationWillEnterForegroundNotification
......@@ -40,7 +41,6 @@
@interface IosAppDelegate : IosObject
- (id)initWithCore:(std::shared_ptr<LinphonePrivate::Core>)core;
- (void)configure:(std::shared_ptr<LinphonePrivate::Core>)core;
@end
......
......@@ -27,6 +27,15 @@
return self;
}
-(std::shared_ptr<LinphonePrivate::Core>)getCore {
std::shared_ptr<LinphonePrivate::Core> core = pcore.lock();
if (!core) {
lWarning() << "Unable to get valid core instance.";
return nullptr;
}
return core;
}
@end
@implementation IosAppDelegate
......@@ -53,22 +62,21 @@
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)configure:(std::shared_ptr<LinphonePrivate::Core>)core{
pcore = core;
}
- (void)didEnterBackground:(NSNotification *)notif {
ms_message("[Ios App] didEnterBackground");
pcore->enterBackground();
if ([self getCore])
[self getCore]->enterBackground();
}
- (void)didEnterForeground:(NSNotification *)notif {
ms_message("[Ios App] didEnterForeground");
pcore->enterForeground();
if ([self getCore])
[self getCore]->enterForeground();
}
- (void)iterate {
linphone_core_iterate(pcore->getCCore());
if ([self getCore])
linphone_core_iterate([self getCore]->getCCore());
}
@end
......@@ -133,7 +141,9 @@
if (currentInputPort == previousInputPort && currentOutputPort == previousOutputPort)
return;
pcore->doLater([=]() {
std::shared_ptr<LinphonePrivate::Core> core = [self getCore];
if (!core) return;
core->doLater([=]() {
switch (changeReason)
{
......@@ -143,7 +153,7 @@
{
// We need to reload for these 3 category, because the first list of AudioDevices available may not be up to date
// For example, bluetooth devices would possibly not be detected before a call Start, as the AudioSession may be in a category other than AVAudioSessionCategoryPlayAndRecord
linphone_core_reload_sound_devices(pcore->getCCore());
linphone_core_reload_sound_devices([self getCore]->getCCore());
}
default: {}
}
......@@ -159,8 +169,8 @@
return (deviceName == currentOutputPort);
};
const LinphoneAudioDevice * inputDevice = linphone_core_get_input_audio_device(pcore->getCCore());
const LinphoneAudioDevice * outputDevice = linphone_core_get_output_audio_device(pcore->getCCore());
const LinphoneAudioDevice * inputDevice = linphone_core_get_input_audio_device(core->getCCore());
const LinphoneAudioDevice * outputDevice = linphone_core_get_output_audio_device(core->getCCore());
std::string currentInputDeviceInCore( (inputDevice == NULL) ? "" : linphone_audio_device_get_device_name(inputDevice) );
std::string currentOutputDeviceInCore( (outputDevice == NULL) ? "" : linphone_audio_device_get_device_name(outputDevice) );
......@@ -168,7 +178,7 @@
bool inputRequiresUpdate = !deviceMatchCurrentInput(currentInputDeviceInCore);
bool outputRequiresUpdate = !deviceMatchCurrentOutput(currentOutputDeviceInCore);
bctbx_list_t * deviceIt = linphone_core_get_extended_audio_devices(pcore->getCCore());
bctbx_list_t * deviceIt = linphone_core_get_extended_audio_devices(core->getCCore());
LinphoneAudioDevice * pLastDeviceSet = NULL;
while ( deviceIt != NULL && (inputRequiresUpdate || outputRequiresUpdate) ) {
LinphoneAudioDevice * pDevice = (LinphoneAudioDevice *) deviceIt->data;
......@@ -176,7 +186,7 @@
bool inputMatch = deviceMatchCurrentInput(deviceName);
if (inputRequiresUpdate && inputMatch) {
linphone_core_set_input_audio_device(pcore->getCCore(), pDevice);
linphone_core_set_input_audio_device(core->getCCore(), pDevice);
pLastDeviceSet = pDevice;
inputRequiresUpdate = false;
}
......@@ -188,7 +198,7 @@
bool isReceiverSpecialCase = currentOutputIsReceiver && inputMatch;
if (isReceiverSpecialCase || deviceMatchCurrentOutput(deviceName)) {
linphone_core_set_output_audio_device(pcore->getCCore(), pDevice);
linphone_core_set_output_audio_device(core->getCCore(), pDevice);
pLastDeviceSet = pDevice;
outputRequiresUpdate = false;
}
......@@ -200,19 +210,19 @@
ms_warning("Current audio route input is '%s', but we could not find the matching device in the linphone devices list", currentInputPort.c_str());
if (!outputRequiresUpdate && pLastDeviceSet != NULL) {
ms_warning("Setting input device to match the current output device by default");
linphone_core_set_input_audio_device(pcore->getCCore(), pLastDeviceSet);
linphone_core_set_input_audio_device(core->getCCore(), pLastDeviceSet);
}
}
if (outputRequiresUpdate) {
ms_warning("Current audio route output is '%s', but we could not find the matching device in the linphone devices list", currentOutputPort.c_str());
if (!inputRequiresUpdate && pLastDeviceSet != NULL) {
ms_warning("Setting output device to match the current input device by default");
linphone_core_set_output_audio_device(pcore->getCCore(), pLastDeviceSet);
linphone_core_set_output_audio_device(core->getCCore(), pLastDeviceSet);
}
}
// Notify the filter that the audio route changed
pcore->soundcardAudioRouteChanged();
core->soundcardAudioRouteChanged();
});
}
......
......@@ -142,9 +142,6 @@ void IosPlatformHelpers::start (std::shared_ptr<LinphonePrivate::Core> core) {
mNetworkReachable = 0; // wait until monitor to give a status;
mSharedCoreHelpers = createIosSharedCoreHelpers(core);
mHandler = [[IosHandler alloc] initWithCore:core];
if (mUseAppDelgate) {
[mAppDelegate configure:core];
}
string cpimPath = getResourceDirPath(Framework, "cpim_grammar");
if (!cpimPath.empty())
......
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