Commit 86a71ed7 authored by Thiago Santini's avatar Thiago Santini

Synchronizes load/unload from multiple threads

When experimenting with multiple cameras on separate threads sometimes
uvc_open would return UVC_ERROR_NOT_FOUND.
parent 0bc27dfc
#include "uvccamerasession.h"
QMutex UVCCameraSession::sessionMutex;
UVCCameraSession::UVCCameraSession(QObject *parent)
: m_surface(Q_NULLPTR),
streaming(false),
......@@ -61,6 +63,7 @@ void UVCCameraSession::presentFrame(const QVideoFrame &frame, const qreal t)
bool UVCCameraSession::load()
{
QMutexLocker sessionLocker(&sessionMutex);
uvc_error_t res;
res = uvc_open(dev, &devh);
......@@ -86,6 +89,7 @@ bool UVCCameraSession::load()
bool UVCCameraSession::unload()
{
QMutexLocker sessionLocker(&sessionMutex);
if (streaming)
stopPreview();
......
......@@ -73,6 +73,8 @@ private:
void updateSourceCapabilities();
QCameraViewfinderSettings settings;
bool qPixelFormat2UVCFrameFormat(const QVideoFrame::PixelFormat &qFormat, uvc_frame_format &uvcFormat);
static QMutex sessionMutex;
};
QT_END_NAMESPACE
......
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