Commit 77902202 authored by Thiago Santini's avatar Thiago Santini

Allows changing the cameras

When testing selecting different cameras online, a problem with the device
handle was found: after closing the stream, we can successfully reopen it
but never get frames. This commit works around that issue.
parent 2600e619
...@@ -34,6 +34,8 @@ void UVCCameraControl::setState(QCamera::State state) ...@@ -34,6 +34,8 @@ void UVCCameraControl::setState(QCamera::State state)
case QCamera::LoadedState: case QCamera::LoadedState:
if (m_state == QCamera::UnloadedState && !(succeeded=m_session->load())) if (m_state == QCamera::UnloadedState && !(succeeded=m_session->load()))
return; return;
if (m_state == QCamera::ActiveState)
succeeded = m_session->stopPreview();
break; break;
case QCamera::ActiveState: case QCamera::ActiveState:
......
...@@ -93,9 +93,10 @@ bool UVCCameraSession::unload() ...@@ -93,9 +93,10 @@ bool UVCCameraSession::unload()
if (streaming) if (streaming)
stopPreview(); stopPreview();
if (devh) // TODO: closing here seems to mess up the device
uvc_close(devh); //if (devh)
devh = NULL; // uvc_close(devh);
//devh = NULL;
m_supportedViewfinderSettings.clear(); m_supportedViewfinderSettings.clear();
return true; return true;
...@@ -127,7 +128,7 @@ bool UVCCameraSession::startPreview() ...@@ -127,7 +128,7 @@ bool UVCCameraSession::startPreview()
return false; return false;
} }
res = uvc_stream_start(strmh, cb, (void*) this, 2.0f, 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); qDebug() << "uvc_stream_start" << uvc_strerror(res);
return false; return false;
...@@ -203,6 +204,7 @@ bool UVCCameraSession::stopPreview() ...@@ -203,6 +204,7 @@ bool UVCCameraSession::stopPreview()
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); qDebug() << "uvc_stream_stop" << uvc_strerror(res);
uvc_stream_close(strmh);
streaming = false; streaming = false;
frameReference.invalidate(); frameReference.invalidate();
......
...@@ -9,7 +9,7 @@ QMediaService* UVCServicePlugin::create(const QString &key) ...@@ -9,7 +9,7 @@ QMediaService* UVCServicePlugin::create(const QString &key)
void UVCServicePlugin::release(QMediaService *service) void UVCServicePlugin::release(QMediaService *service)
{ {
qDebug() << "Plugin release"; delete service;
} }
QByteArray UVCServicePlugin::defaultDevice(const QByteArray &service) const QByteArray UVCServicePlugin::defaultDevice(const QByteArray &service) const
......
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