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) ...@@ -120,6 +120,7 @@ bool UVCCameraSession::setDevice(const QString &device)
return false; return false;
} }
ProductFactory pf;
bool ret = false; bool ret = false;
int idx = 0; int idx = 0;
while (1) { while (1) {
...@@ -133,7 +134,7 @@ bool UVCCameraSession::setDevice(const QString &device) ...@@ -133,7 +134,7 @@ bool UVCCameraSession::setDevice(const QString &device)
qWarning() << "uvc_get_device_descriptor" << uvc_strerror(res); qWarning() << "uvc_get_device_descriptor" << uvc_strerror(res);
return false; return false;
} }
QString product(desc->product); QString product = pf.make(desc);
uvc_free_device_descriptor(desc); uvc_free_device_descriptor(desc);
if (product.compare(device) == 0) { if (product.compare(device) == 0) {
...@@ -316,27 +317,12 @@ bool UVCCameraSession::startPreview() ...@@ -316,27 +317,12 @@ bool UVCCameraSession::startPreview()
double UVCCameraSession::getBandwidthFactor() 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()) { switch(settings.pixelFormat()) {
// compressed; user can change it through the default settings // compressed; user can change it through the default settings
case QVideoFrame::Format_Jpeg: case QVideoFrame::Format_Jpeg:
return bandwidthFactor; 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: default:
return 4.0; return -1; // use hw estimation
} }
} }
......
...@@ -49,6 +49,22 @@ struct DefaultParameters { ...@@ -49,6 +49,22 @@ struct DefaultParameters {
int hue_auto; 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 class UVCCameraSession : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -166,7 +182,7 @@ private: ...@@ -166,7 +182,7 @@ private:
static QMutex sessionMutex; static QMutex sessionMutex;
// device availability // device availability
static QMap<QString,bool> UVCCameraSession::devices; static QMap<QString,bool> devices;
static QMutex UVCCameraSession::devicesMutex; static QMutex UVCCameraSession::devicesMutex;
bool acquire(const QString &device); bool acquire(const QString &device);
void release(const QString &device); void release(const QString &device);
......
...@@ -101,6 +101,7 @@ void UVCVideoDeviceControl::updateDevices() ...@@ -101,6 +101,7 @@ void UVCVideoDeviceControl::updateDevices()
return; return;
} }
ProductFactory pf;
int idx = 0; int idx = 0;
while (1) { while (1) {
uvc_device_t *dev = devList[idx]; uvc_device_t *dev = devList[idx];
...@@ -119,8 +120,9 @@ void UVCVideoDeviceControl::updateDevices() ...@@ -119,8 +120,9 @@ void UVCVideoDeviceControl::updateDevices()
UVCVideoDeviceInfo devInfo; UVCVideoDeviceInfo devInfo;
devInfo.first = QString(desc->product).toUtf8(); QString product = pf.make(desc);
devInfo.second = QString(desc->product).toUtf8(); devInfo.first = QString(product).toUtf8();
devInfo.second = QString(product).toUtf8();
deviceList->append(devInfo); 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