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