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