Commit 5d608b49 authored by Thiago Santini's avatar Thiago Santini

Prevents opening busy camera, replaces qDebug by qWarnings

parent 876736b5
...@@ -5,6 +5,7 @@ QMutex UVCCameraSession::sessionMutex; ...@@ -5,6 +5,7 @@ QMutex UVCCameraSession::sessionMutex;
UVCCameraSession::UVCCameraSession(QObject *parent) UVCCameraSession::UVCCameraSession(QObject *parent)
: m_surface(Q_NULLPTR), : m_surface(Q_NULLPTR),
streaming(false), streaming(false),
dev(NULL),
devh(NULL) devh(NULL)
{ {
} }
...@@ -59,7 +60,7 @@ void UVCCameraSession::presentFrame(const QVideoFrame &frame, const qreal t) ...@@ -59,7 +60,7 @@ void UVCCameraSession::presentFrame(const QVideoFrame &frame, const qreal t)
if (latency < MAX_LATENCY_MS) if (latency < MAX_LATENCY_MS)
m_surface->present( tmp ); m_surface->present( tmp );
//else //else
// qDebug() << "Dropping frame (" << latency << "ms old )"; // qWarning() << "Dropping frame (" << latency << "ms old )";
} }
bool UVCCameraSession::load() bool UVCCameraSession::load()
...@@ -67,9 +68,12 @@ bool UVCCameraSession::load() ...@@ -67,9 +68,12 @@ bool UVCCameraSession::load()
QMutexLocker sessionLocker(&sessionMutex); QMutexLocker sessionLocker(&sessionMutex);
uvc_error_t res; uvc_error_t res;
if (!dev)
return false;
res = uvc_open(dev, &devh); res = uvc_open(dev, &devh);
if (res != UVC_SUCCESS) { if (res != UVC_SUCCESS) {
qDebug() << "uvc_open" << uvc_strerror(res); qWarning() << "uvc_open" << uvc_strerror(res);
devh = NULL; devh = NULL;
return false; return false;
} }
...@@ -114,25 +118,25 @@ bool UVCCameraSession::startPreview() ...@@ -114,25 +118,25 @@ bool UVCCameraSession::startPreview()
uvc_frame_format format; uvc_frame_format format;
if (!qPixelFormat2UVCFrameFormat(settings.pixelFormat(), format)) { if (!qPixelFormat2UVCFrameFormat(settings.pixelFormat(), format)) {
qDebug() << "Unknown pixel format"; qWarning() << "Unknown pixel format";
return false; return false;
} }
res = uvc_get_stream_ctrl_format_size(devh, &ctrl, format, settings.resolution().width(), settings.resolution().height(), settings.maximumFrameRate()); res = uvc_get_stream_ctrl_format_size(devh, &ctrl, format, settings.resolution().width(), settings.resolution().height(), settings.maximumFrameRate());
if (res != UVC_SUCCESS) { if (res != UVC_SUCCESS) {
qDebug() << "uvc_get_stream_ctrl" << uvc_strerror(res); qWarning() << "uvc_get_stream_ctrl" << uvc_strerror(res);
return false; return false;
} }
res = uvc_stream_open_ctrl(devh, &strmh, &ctrl); res = uvc_stream_open_ctrl(devh, &strmh, &ctrl);
if (res != UVC_SUCCESS) { if (res != UVC_SUCCESS) {
qDebug() << "uvc_stream_open_ctrl" << uvc_strerror(res); qWarning() << "uvc_stream_open_ctrl" << uvc_strerror(res);
return false; return false;
} }
res = uvc_stream_start(strmh, cb, (void*) this, 1.5f, 0); res = uvc_stream_start(strmh, cb, (void*) this, 1.5f, 0);
if (res != UVC_SUCCESS) { if (res != UVC_SUCCESS) {
qDebug() << "uvc_stream_start" << uvc_strerror(res); qWarning() << "uvc_stream_start" << uvc_strerror(res);
return false; return false;
} }
...@@ -209,7 +213,7 @@ bool UVCCameraSession::stopPreview() ...@@ -209,7 +213,7 @@ bool UVCCameraSession::stopPreview()
if ( (res = uvc_stream_stop(strmh)) != UVC_ERROR_TIMEOUT) if ( (res = uvc_stream_stop(strmh)) != UVC_ERROR_TIMEOUT)
break; break;
if (res != UVC_SUCCESS && res != UVC_ERROR_INVALID_PARAM) if (res != UVC_SUCCESS && res != UVC_ERROR_INVALID_PARAM)
qDebug() << "uvc_stream_stop" << uvc_strerror(res); qWarning() << "uvc_stream_stop" << uvc_strerror(res);
uvc_stream_close(strmh); uvc_stream_close(strmh);
streaming = false; streaming = false;
......
...@@ -6,17 +6,21 @@ Q_GLOBAL_STATIC(QList<UVCVideoDeviceInfo>, deviceList) ...@@ -6,17 +6,21 @@ Q_GLOBAL_STATIC(QList<UVCVideoDeviceInfo>, deviceList)
// this context may never get deleted. Is that a problem? // this context may never get deleted. Is that a problem?
uvc_context_t* UVCVideoDeviceControl::ctx = NULL; uvc_context_t* UVCVideoDeviceControl::ctx = NULL;
QMap<QString,bool> UVCVideoDeviceControl::busyDevices;
UVCVideoDeviceControl::UVCVideoDeviceControl(QObject *parent) UVCVideoDeviceControl::UVCVideoDeviceControl(QObject *parent)
: QVideoDeviceSelectorControl(parent) : QVideoDeviceSelectorControl(parent),
currentDevice(""),
selected(0)
{ {
m_session = qobject_cast<UVCCameraSession*>(parent); m_session = qobject_cast<UVCCameraSession*>(parent);
selected = 0;
updateDevices(); updateDevices();
} }
UVCVideoDeviceControl::~UVCVideoDeviceControl() UVCVideoDeviceControl::~UVCVideoDeviceControl()
{ {
busyDevices.remove(currentDevice);
currentDevice.clear();
} }
int UVCVideoDeviceControl::deviceCount() const int UVCVideoDeviceControl::deviceCount() const
...@@ -87,7 +91,11 @@ void UVCVideoDeviceControl::setSelectedDevice(int index) ...@@ -87,7 +91,11 @@ void UVCVideoDeviceControl::setSelectedDevice(int index)
uvc_free_device_descriptor(desc); uvc_free_device_descriptor(desc);
if (selectedDevice) { if (selectedDevice) {
m_session->setDevice(dev); if (!busyDevices.contains(device)) {
busyDevices[device] = true;
currentDevice = device;
m_session->setDevice(dev);
}
break; break;
} }
} }
......
...@@ -38,6 +38,8 @@ private: ...@@ -38,6 +38,8 @@ private:
UVCCameraSession* m_session; UVCCameraSession* m_session;
int selected; int selected;
static uvc_context_t* ctx; static uvc_context_t* ctx;
static QMap<QString,bool> busyDevices;
QString currentDevice;
}; };
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