1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix: Invoke device methods in deviceThread

Fix #2058
This commit is contained in:
Diadlo 2017-06-26 14:05:26 +03:00
parent d720cca969
commit d86912eacd
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
2 changed files with 22 additions and 1 deletions

View File

@ -103,6 +103,7 @@ CameraSource::CameraSource()
, _isNone{true}
, subscriptions{0}
{
qRegisterMetaType<VideoMode>("VideoMode");
deviceThread->setObjectName("Device thread");
deviceThread->start();
moveToThread(deviceThread);
@ -155,6 +156,12 @@ void CameraSource::setupDefault()
*/
void CameraSource::setupDevice(const QString& DeviceName, const VideoMode& Mode)
{
if (QThread::currentThread() != deviceThread) {
QMetaObject::invokeMethod(this, "setupDevice", Q_ARG(const QString&, DeviceName),
Q_ARG(const VideoMode&, Mode));
return;
}
QWriteLocker locker{&deviceMutex};
if (DeviceName == deviceName && Mode == mode) {
@ -240,6 +247,11 @@ void CameraSource::unsubscribe()
*/
void CameraSource::openDevice()
{
if (QThread::currentThread() != deviceThread) {
QMetaObject::invokeMethod(this, "openDevice");
return;
}
QWriteLocker locker{&streamMutex};
qDebug() << "Opening device " << deviceName;
@ -347,6 +359,11 @@ void CameraSource::openDevice()
*/
void CameraSource::closeDevice()
{
if (QThread::currentThread() != deviceThread) {
QMetaObject::invokeMethod(this, "closeDevice");
return;
}
QWriteLocker locker{&streamMutex};
qDebug() << "Closing device " << deviceName;

View File

@ -40,13 +40,15 @@ public:
static CameraSource& getInstance();
static void destroyInstance();
void setupDefault();
void setupDevice(const QString& deviceName, const VideoMode& mode);
bool isNone() const;
// VideoSource interface
virtual void subscribe() override;
virtual void unsubscribe() override;
public slots:
void setupDevice(const QString& deviceName, const VideoMode& mode);
signals:
void deviceOpened();
void openFailed();
@ -55,6 +57,8 @@ private:
CameraSource();
~CameraSource();
void stream();
private slots:
void openDevice();
void closeDevice();