diff --git a/src/video/camerasource.cpp b/src/video/camerasource.cpp index 6cf0603da..bb1f47564 100644 --- a/src/video/camerasource.cpp +++ b/src/video/camerasource.cpp @@ -90,7 +90,8 @@ extern "C" { CameraSource* CameraSource::instance{nullptr}; CameraSource::CameraSource() - : deviceName{"none"} + : deviceThread{new QThread} + , deviceName{"none"} , device{nullptr} , mode(VideoMode()) // clang-format off @@ -102,6 +103,10 @@ CameraSource::CameraSource() , _isNone{true} , subscriptions{0} { + deviceThread->setObjectName("Device thread"); + deviceThread->start(); + moveToThread(deviceThread); + subscriptions = 0; av_register_all(); avdevice_register_all(); @@ -204,6 +209,10 @@ CameraSource::~CameraSource() // Synchronize with our stream thread while (streamFuture.isRunning()) QThread::yieldCurrentThread(); + + deviceThread->exit(0); + deviceThread->wait(); + delete deviceThread; } void CameraSource::subscribe() diff --git a/src/video/camerasource.h b/src/video/camerasource.h index 1880b8400..9e95acb3a 100644 --- a/src/video/camerasource.h +++ b/src/video/camerasource.h @@ -60,6 +60,8 @@ private: private: QFuture streamFuture; + QThread* deviceThread; + QString deviceName; CameraDevice* device; VideoMode mode; @@ -67,6 +69,7 @@ private: // TODO: Remove when ffmpeg version will be bumped to the 3.1.0 AVCodecContext* cctxOrig; int videoStreamIndex; + QReadWriteLock streamMutex; std::atomic_bool _isNone;