From 0e161675e6014faeeaa490a9c73a62c1577c674e Mon Sep 17 00:00:00 2001 From: Libor Tomsik Date: Tue, 24 Feb 2015 13:51:34 +0100 Subject: 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 --- src/gsttools/qgstutils.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/gsttools') diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp index 1281d3fc5..465f43989 100644 --- a/src/gsttools/qgstutils.cpp +++ b/src/gsttools/qgstutils.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef USE_V4L # include @@ -411,6 +412,10 @@ Q_GLOBAL_STATIC(FactoryCameraInfoMap, qt_camera_device_info); QVector 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::enumerateCameras(GstElementFactory *fa } if (!devices.isEmpty() || !hasVideoSource) { + camerasCacheAgeTimer.restart(); return devices; } } @@ -527,6 +533,7 @@ QVector QGstUtils::enumerateCameras(GstElementFactory *fa } qt_safe_close(fd); } + camerasCacheAgeTimer.restart(); #endif // USE_V4L return devices; -- cgit v1.2.3