diff options
author | Libor Tomsik <libor@tomsik.eu> | 2015-02-24 13:51:34 +0100 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-02-25 10:29:21 +0000 |
commit | 0e161675e6014faeeaa490a9c73a62c1577c674e (patch) | |
tree | 62f1f02cc10d578c06ea52b82a57b54a38560b9a | |
parent | fcf5d826a0e2d3ea6a01bf4c962e0d4fe096d321 (diff) | |
download | qtmultimedia-0e161675e6014faeeaa490a9c73a62c1577c674e.tar.gz |
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>
-rw-r--r-- | src/gsttools/qgstutils.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
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 <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; |