Commit e5cd3b33 authored by Thiago Santini's avatar Thiago Santini

Handles cameras with same id, vendor, serial

parent 37feab74
......@@ -120,6 +120,7 @@ bool UVCCameraSession::setDevice(const QString &device)
return false;
}
ProductFactory pf;
bool ret = false;
int idx = 0;
while (1) {
......@@ -133,7 +134,7 @@ bool UVCCameraSession::setDevice(const QString &device)
qWarning() << "uvc_get_device_descriptor" << uvc_strerror(res);
return false;
}
QString product(desc->product);
QString product = pf.make(desc);
uvc_free_device_descriptor(desc);
if (product.compare(device) == 0) {
......@@ -316,27 +317,12 @@ bool UVCCameraSession::startPreview()
double UVCCameraSession::getBandwidthFactor()
{
/*
* This really is the bpp. For reference see:
* https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
*
* In general:
* 4:4:4 Formats, 32 Bits per Pixel
* 4:2:2 Formats, 16 Bits per Pixel
* 4:2:0 Formats, 16 Bits per Pixel
* 4:2:0 Formats, 12 Bits per Pixel
*/
switch(settings.pixelFormat()) {
// compressed; user can change it through the default settings
case QVideoFrame::Format_Jpeg:
return bandwidthFactor;
// 4:2:2
case QVideoFrame::Format_YUYV:
case QVideoFrame::Format_UYVY:
return 2;
// assume worst case if we don't know it
default:
return 4.0;
return -1; // use hw estimation
}
}
......
......@@ -49,6 +49,22 @@ struct DefaultParameters {
int hue_auto;
};
class ProductFactory {
public:
QString make(const uvc_device_descriptor_t * const desc) {
QString product(desc->product);
if (entries.contains(product)) {
entries[product] += 1;
product = QString("%1 #%2").arg(product).arg(entries[product]);
} else
entries[product] = 0;
return product;
}
private:
QMap<QString,int> entries;
};
class UVCCameraSession : public QObject
{
Q_OBJECT
......@@ -166,7 +182,7 @@ private:
static QMutex sessionMutex;
// device availability
static QMap<QString,bool> UVCCameraSession::devices;
static QMap<QString,bool> devices;
static QMutex UVCCameraSession::devicesMutex;
bool acquire(const QString &device);
void release(const QString &device);
......
......@@ -101,6 +101,7 @@ void UVCVideoDeviceControl::updateDevices()
return;
}
ProductFactory pf;
int idx = 0;
while (1) {
uvc_device_t *dev = devList[idx];
......@@ -119,8 +120,9 @@ void UVCVideoDeviceControl::updateDevices()
UVCVideoDeviceInfo devInfo;
devInfo.first = QString(desc->product).toUtf8();
devInfo.second = QString(desc->product).toUtf8();
QString product = pf.make(desc);
devInfo.first = QString(product).toUtf8();
devInfo.second = QString(product).toUtf8();
deviceList->append(devInfo);
......
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