Fixing camera enumeration on hotplug

Emptying camera HW devices buffer when it becomes obsolete (500ms).
Leaving the list filled was causing video cameras to keep
on the list even when the camera was unplugged. Or vice versa, empty
after the camera was plugged into the system.

Change-Id: I3b38a0b327553cbb6e18dd5421cdde3ded1b7895
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
Libor Tomsik
2015-02-24 13:51:34 +01:00
committed by Yoann Lopes
parent fcf5d826a0
commit 0e161675e6

View File

@@ -41,6 +41,7 @@
#include <QtCore/qset.h>
#include <QtCore/qstringlist.h>
#include <qaudioformat.h>
#include <QtCore/qelapsedtimer.h>
#ifdef USE_V4L
# include <private/qcore_unix_p.h>
@@ -411,6 +412,10 @@ Q_GLOBAL_STATIC(FactoryCameraInfoMap, qt_camera_device_info);
QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *factory)
{
static QElapsedTimer camerasCacheAgeTimer;
if (camerasCacheAgeTimer.isValid() && camerasCacheAgeTimer.elapsed() > 500) // ms
qt_camera_device_info()->clear();
FactoryCameraInfoMap::const_iterator it = qt_camera_device_info()->constFind(factory);
if (it != qt_camera_device_info()->constEnd())
return *it;
@@ -469,6 +474,7 @@ QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *fa
}
if (!devices.isEmpty() || !hasVideoSource) {
camerasCacheAgeTimer.restart();
return devices;
}
}
@@ -527,6 +533,7 @@ QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *fa
}
qt_safe_close(fd);
}
camerasCacheAgeTimer.restart();
#endif // USE_V4L
return devices;