Commit bc7128d1 authored by Ghislain MARY's avatar Ghislain MARY

Handle the core iteration in the UI so that all linphone API calls are made in...

Handle the core iteration in the UI so that all linphone API calls are made in the UI thread (this is mandatory to prevent deadlocks in the video capture).
parent ce1fe117
......@@ -32,6 +32,7 @@ using System.Text;
using Windows.Foundation.Metadata;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;
using Windows.System.Threading;
namespace Linphone.Model
{
......@@ -118,7 +119,7 @@ namespace Linphone.Model
public void InitLinphoneCore()
{
Core.LogLevel = OutputTraceLevel.Debug;
LinphoneManager.Instance.Core.ChatDatabasePath = GetChatDatabasePath();
LinphoneManager.Instance.Core.RootCa = GetRootCaPath();
......@@ -133,8 +134,15 @@ namespace Linphone.Model
LinphoneManager.Instance.Core.SetUserAgent("LinphoneW10", Core.Version);
InitPushNotifications();
isLinphoneRunning = true;
LinphoneManager.Instance.Core.IsIterateEnabled = true;
isLinphoneRunning = true;
TimeSpan period = TimeSpan.FromMilliseconds(20);
ThreadPoolTimer.CreatePeriodicTimer((source) =>
{
CoreDispatcher.RunIdleAsync((args) =>
{
Core.Iterate();
});
}, period);
}
public void EnableLogCollection(bool enable)
......
......@@ -443,34 +443,6 @@ void Core::IsIpv6Enabled::set(Platform::Boolean enable)
linphone_core_enable_ipv6(this->lc, enable);
}
Platform::Boolean Core::IsIterateEnabled::get()
{
return isIterateEnabled;
}
void Core::IsIterateEnabled::set(Platform::Boolean value)
{
API_LOCK;
if (isIterateEnabled && !value && IterateWorkItem)
{
IterateWorkItem->Cancel();
IterateWorkItem = nullptr;
}
else if (!isIterateEnabled && value)
{
IAsyncAction^ IterateWorkItem = Windows::System::Threading::ThreadPool::RunAsync(ref new Windows::System::Threading::WorkItemHandler([this](IAsyncAction^ action)
{
while (true) {
GlobalApiLock::Instance()->Lock(__FUNCTION__);
linphone_core_iterate(this->lc);
GlobalApiLock::Instance()->Unlock(__FUNCTION__);
ms_usleep(20000);
}
}), Windows::System::Threading::WorkItemPriority::Low);
}
isIterateEnabled = value;
}
Platform::Boolean Core::IsKeepAliveEnabled::get()
{
API_LOCK;
......@@ -1136,6 +1108,12 @@ Platform::Boolean Core::IsMediaEncryptionSupported(BelledonneCommunications::Lin
return (linphone_core_media_encryption_supported(this->lc, (LinphoneMediaEncryption)menc) == TRUE);
}
void Core::Iterate()
{
API_LOCK;
linphone_core_iterate(this->lc);
}
void Core::LeaveConference()
{
API_LOCK;
......@@ -1474,14 +1452,14 @@ void log_collection_upload_progress_indication(::LinphoneCore *lc, size_t offset
}
Core::Core(BelledonneCommunications::Linphone::Native::CoreListener^ coreListener)
: lc(nullptr), listener(coreListener), config(ref new LpConfig(nullptr, nullptr)), isIterateEnabled(false),
: lc(nullptr), listener(coreListener), config(ref new LpConfig(nullptr, nullptr)),
voipCallController(ref new BelledonneCommunications::Linphone::Native::VoipCallController())
{
Init();
}
Core::Core(BelledonneCommunications::Linphone::Native::CoreListener^ coreListener, BelledonneCommunications::Linphone::Native::LpConfig^ config)
: lc(nullptr), listener(coreListener), config(config), isIterateEnabled(false),
: lc(nullptr), listener(coreListener), config(config),
voipCallController(ref new BelledonneCommunications::Linphone::Native::VoipCallController())
{
Init();
......@@ -1513,7 +1491,6 @@ void Core::Init()
Core::~Core()
{
API_LOCK;
IsIterateEnabled = false;
RefToPtrProxy<Core^> *proxy = reinterpret_cast< RefToPtrProxy<Core^> *>(linphone_core_get_user_data(this->lc));
delete proxy;
linphone_core_destroy(this->lc);
......
......@@ -376,16 +376,6 @@ namespace BelledonneCommunications
void set(Platform::Boolean value);
}
/// <summary>
/// Set it to true to start the iterate, set it to false to stop it.
/// Is disabled by default.
/// </summary>
property Platform::Boolean IsIterateEnabled
{
Platform::Boolean get();
void set(Platform::Boolean value);
}
/// <summary>
/// Defines Linphone behaviour when encryption parameters negociation fails on outgoing call.
/// </summary>
......@@ -906,6 +896,20 @@ namespace BelledonneCommunications
/// <returns>true if supported, false otherwise</returns>
Platform::Boolean IsMediaEncryptionSupported(BelledonneCommunications::Linphone::Native::MediaEncryption menc);
/// <summary>
/// Main loop function.It is crucial that your application call it periodically.
/// It performs various backgrounds tasks:
/// - receiving of SIP messages
/// - handles timers and timeout
/// - performs registration to proxies
/// - authentication retries
/// The application MUST call this function periodically, in its main loop.
/// Be careful that this function must be called from the same thread as
/// other liblinphone methods. If it is not the case make sure all liblinphone calls are
/// serialized with a mutex.
/// </summary>
void Iterate();
/// <summary>
/// Moves the local participant out of the conference.
/// When the local participant is out of the conference, the remote participants can continue to talk normally.
......@@ -1069,8 +1073,6 @@ namespace BelledonneCommunications
::LinphoneCore *lc;
BelledonneCommunications::Linphone::Native::CoreListener^ listener;
LpConfig^ config;
Windows::Foundation::IAsyncAction^ IterateWorkItem;
Platform::Boolean isIterateEnabled;
BelledonneCommunications::Linphone::Native::VoipCallController^ voipCallController;
static OutputTraceLevel logLevel;
......
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