Commit 21ff0b70 authored by Thiago Santini's avatar Thiago Santini

Mimics most of Pupil Labs settings

parent d4a17470
...@@ -6,6 +6,7 @@ UVCCameraSession::UVCCameraSession(QObject *parent) ...@@ -6,6 +6,7 @@ UVCCameraSession::UVCCameraSession(QObject *parent)
: QObject(parent), : QObject(parent),
m_surface(Q_NULLPTR), m_surface(Q_NULLPTR),
streaming(false), streaming(false),
bandwidthFactor(1.3f),
dev(NULL), dev(NULL),
devh(NULL) devh(NULL)
{ {
...@@ -81,12 +82,17 @@ bool UVCCameraSession::load() ...@@ -81,12 +82,17 @@ bool UVCCameraSession::load()
// TODO: parametrize this // TODO: parametrize this
uvc_set_focus_auto(devh, 0); uvc_set_focus_auto(devh, 0);
uvc_set_ae_priority(devh, 0); if (isPupilFieldCamera()) {
uvc_set_ae_mode(devh, 1); bandwidthFactor = 2.0f;
uvc_set_saturation(devh, 63); uvc_set_ae_priority(devh, 1);
uvc_set_exposure_abs(devh, 63); } else if (isPupilEyeCamera()) {
uvc_set_backlight_compensation(devh, 2); uvc_set_ae_priority(devh, 0);
uvc_set_gamma(devh, 100); uvc_set_ae_mode(devh, 1);
uvc_set_saturation(devh, 127); // do not set saturation to zero as to not lose color information
uvc_set_exposure_abs(devh, 63);
uvc_set_backlight_compensation(devh, 2);
uvc_set_gamma(devh, 100);
}
updateSourceCapabilities(); updateSourceCapabilities();
...@@ -136,14 +142,6 @@ bool UVCCameraSession::startPreview() ...@@ -136,14 +142,6 @@ bool UVCCameraSession::startPreview()
return false; return false;
} }
float bandwidthFactor = 1.3f;
uvc_device_descriptor *desc;
uvc_get_device_descriptor(dev, &desc);
QString name(desc->product);
if (name.contains("ID2"))
bandwidthFactor = 2.0f;
uvc_free_device_descriptor(desc);
res = uvc_stream_start(strmh, cb, (void*) this, bandwidthFactor, 0); res = uvc_stream_start(strmh, cb, (void*) this, bandwidthFactor, 0);
if (res != UVC_SUCCESS) { if (res != UVC_SUCCESS) {
qWarning() << "uvc_stream_start" << uvc_strerror(res); qWarning() << "uvc_stream_start" << uvc_strerror(res);
...@@ -245,3 +243,27 @@ void UVCCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &se ...@@ -245,3 +243,27 @@ void UVCCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &se
{ {
this->settings = settings; this->settings = settings;
} }
bool UVCCameraSession::isPupilFieldCamera()
{
bool ret = false;
uvc_device_descriptor *desc;
uvc_get_device_descriptor(dev, &desc);
QString name(desc->product);
if ( name.contains("Pupil Cam1 ID2") )
ret = true;
uvc_free_device_descriptor(desc);
return ret;
}
bool UVCCameraSession::isPupilEyeCamera()
{
bool ret = false;
uvc_device_descriptor *desc;
uvc_get_device_descriptor(dev, &desc);
QString name(desc->product);
if ( name.contains("Pupil Cam1 ID0") || name.contains("Pupil Cam1 ID1") )
ret = true;
uvc_free_device_descriptor(desc);
return ret;
}
...@@ -52,6 +52,7 @@ private Q_SLOTS: ...@@ -52,6 +52,7 @@ private Q_SLOTS:
private: private:
bool streaming; bool streaming;
float bandwidthFactor;
QCamera::Status m_status; QCamera::Status m_status;
QAbstractVideoSurface *m_surface; QAbstractVideoSurface *m_surface;
...@@ -75,6 +76,9 @@ private: ...@@ -75,6 +76,9 @@ private:
bool qPixelFormat2UVCFrameFormat(const QVideoFrame::PixelFormat &qFormat, uvc_frame_format &uvcFormat); bool qPixelFormat2UVCFrameFormat(const QVideoFrame::PixelFormat &qFormat, uvc_frame_format &uvcFormat);
static QMutex sessionMutex; static QMutex sessionMutex;
bool isPupilFieldCamera();
bool isPupilEyeCamera();
}; };
QT_END_NAMESPACE QT_END_NAMESPACE
......
...@@ -71,7 +71,7 @@ void UVCVideoDeviceControl::setSelectedDevice(int index) ...@@ -71,7 +71,7 @@ void UVCVideoDeviceControl::setSelectedDevice(int index)
uvc_error_t res; uvc_error_t res;
res = uvc_get_device_list(ctx, &devList); res = uvc_get_device_list(ctx, &devList);
if (res < 0) { if (res < 0) {
qDebug() << "uvc_get_device_list" << uvc_strerror(res); qWarning() << "uvc_get_device_list" << uvc_strerror(res);
return; return;
} }
...@@ -84,7 +84,7 @@ void UVCVideoDeviceControl::setSelectedDevice(int index) ...@@ -84,7 +84,7 @@ void UVCVideoDeviceControl::setSelectedDevice(int index)
uvc_device_descriptor_t *desc; uvc_device_descriptor_t *desc;
res = uvc_get_device_descriptor(dev, &desc); res = uvc_get_device_descriptor(dev, &desc);
if (res < 0) { if (res < 0) {
qDebug() << "uvc_get_device_descriptor" << uvc_strerror(res); qWarning() << "uvc_get_device_descriptor" << uvc_strerror(res);
return; return;
} }
bool selectedDevice = QString::number(desc->idProduct).compare(device) == 0; bool selectedDevice = QString::number(desc->idProduct).compare(device) == 0;
...@@ -95,6 +95,8 @@ void UVCVideoDeviceControl::setSelectedDevice(int index) ...@@ -95,6 +95,8 @@ void UVCVideoDeviceControl::setSelectedDevice(int index)
busyDevices[device] = true; busyDevices[device] = true;
currentDevice = device; currentDevice = device;
m_session->setDevice(dev); m_session->setDevice(dev);
} else {
qWarning() << "Device is busy.";
} }
break; break;
} }
...@@ -123,10 +125,10 @@ void UVCVideoDeviceControl::updateDevices() ...@@ -123,10 +125,10 @@ void UVCVideoDeviceControl::updateDevices()
if (!ctx) { if (!ctx) {
// Init libuvc // Init libuvc
qDebug() << "Initializing libuvc context..."; qInfo() << "Initializing libuvc context...";
res = uvc_init(&ctx, NULL); res = uvc_init(&ctx, NULL);
if (res < 0) { if (res < 0) {
qDebug() << "uvc_init" << uvc_strerror(res); qWarning() << "uvc_init" << uvc_strerror(res);
return; return;
} }
} }
...@@ -134,7 +136,7 @@ void UVCVideoDeviceControl::updateDevices() ...@@ -134,7 +136,7 @@ void UVCVideoDeviceControl::updateDevices()
uvc_device_t **devList; uvc_device_t **devList;
res = uvc_get_device_list(ctx, &devList); res = uvc_get_device_list(ctx, &devList);
if (res < 0) { if (res < 0) {
qDebug() << "uvc_get_device_list" << uvc_strerror(res); qWarning() << "uvc_get_device_list" << uvc_strerror(res);
return; return;
} }
...@@ -147,7 +149,7 @@ void UVCVideoDeviceControl::updateDevices() ...@@ -147,7 +149,7 @@ void UVCVideoDeviceControl::updateDevices()
uvc_device_descriptor_t *desc; uvc_device_descriptor_t *desc;
res = uvc_get_device_descriptor(dev, &desc); res = uvc_get_device_descriptor(dev, &desc);
if (res < 0) { if (res < 0) {
qDebug() << "uvc_get_device_descriptor" << uvc_strerror(res); qWarning() << "uvc_get_device_descriptor" << uvc_strerror(res);
break; break;
} }
......
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