Commit 2ae919f2 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/camera/Camera): provide a protection to render in other thread

parent 690f4bef
...@@ -143,7 +143,11 @@ void CallModel::acceptWithVideo () { ...@@ -143,7 +143,11 @@ void CallModel::acceptWithVideo () {
} }
void CallModel::terminate () { void CallModel::terminate () {
CoreManager *core = CoreManager::getInstance();
core->lockVideoRender();
m_linphone_call->terminate(); m_linphone_call->terminate();
core->unlockVideoRender();
} }
void CallModel::transfer () { void CallModel::transfer () {
......
...@@ -104,11 +104,23 @@ void CameraRenderer::render () { ...@@ -104,11 +104,23 @@ void CameraRenderer::render () {
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw with ms filter. // Draw with ms filter.
MSFunctions *ms_functions = MSFunctions::getInstance(); {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClearColor(0.f, 0.f, 0.f, 0.f);
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CoreManager *core = CoreManager::getInstance();
MSFunctions *ms_functions = MSFunctions::getInstance();
ms_functions->bind(f); core->lockVideoRender();
m_camera->getCall()->getLinphoneCall()->oglRender(m_camera->m_is_preview);
ms_functions->bind(nullptr); ms_functions->bind(f);
m_camera->getCall()->getLinphoneCall()->oglRender(m_camera->m_is_preview);
ms_functions->bind(nullptr);
core->unlockVideoRender();
}
// Synchronize opengl calls with QML. // Synchronize opengl calls with QML.
if (m_window) if (m_window)
......
...@@ -68,7 +68,9 @@ void CoreManager::init (QObject *parent, const QString &config_path) { ...@@ -68,7 +68,9 @@ void CoreManager::init (QObject *parent, const QString &config_path) {
QObject::connect( QObject::connect(
timer, &QTimer::timeout, m_instance, []() { timer, &QTimer::timeout, m_instance, []() {
m_instance->m_mutex_video_render.lock();
m_instance->m_core->iterate(); m_instance->m_core->iterate();
m_instance->m_mutex_video_render.unlock();
} }
); );
} }
......
...@@ -27,8 +27,11 @@ ...@@ -27,8 +27,11 @@
#include "../contacts/ContactsListModel.hpp" #include "../contacts/ContactsListModel.hpp"
#include "../settings/SettingsModel.hpp" #include "../settings/SettingsModel.hpp"
#include "../sip-addresses/SipAddressesModel.hpp" #include "../sip-addresses/SipAddressesModel.hpp"
#include "CoreHandlers.hpp" #include "CoreHandlers.hpp"
#include <QMutex>
// ============================================================================= // =============================================================================
class QTimer; class QTimer;
...@@ -49,6 +52,18 @@ public: ...@@ -49,6 +52,18 @@ public:
return m_handlers; return m_handlers;
} }
// ---------------------------------------------------------------------------
// Video render lock.
// ---------------------------------------------------------------------------
void lockVideoRender () {
m_mutex_video_render.lock();
}
void unlockVideoRender () {
m_mutex_video_render.unlock();
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Singleton models. // Singleton models.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -102,6 +117,8 @@ private: ...@@ -102,6 +117,8 @@ private:
QTimer *m_cbs_timer; QTimer *m_cbs_timer;
QMutex m_mutex_video_render;
static CoreManager *m_instance; static CoreManager *m_instance;
}; };
......
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