summaryrefslogtreecommitdiffstats
path: root/src/plugins/directshow/dsserviceplugin.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-04-09 16:09:39 +0200
committerYoann Lopes <yoann.lopes@theqtcompany.com>2015-04-14 14:49:56 +0000
commitf9145aca166ad2ca1514524ce88ded7834eb207c (patch)
tree66e6acb2ae354361250c0b3228a6c3cdb0366cfe /src/plugins/directshow/dsserviceplugin.cpp
parent07606dde9a1f6b89f582ff8f1fbc53e2d4eb2c22 (diff)
DirectShow: correctly update camera list.
8923c0ff fixed the list not being updated after plugging/unplugging a camera from the system. However, it was only a partial fix affecting only QCameraInfo::availableCameras(). DSVideoDeviceControl was still internally keeping a list of cameras that was never updated, causing the QCamera constructor to not take into account new or removed cameras. Change-Id: Ie5e79c46002017b1e85bfc53c6391a2a747361a0 Task-number: QTBUG-39708 Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src/plugins/directshow/dsserviceplugin.cpp')
-rw-r--r--src/plugins/directshow/dsserviceplugin.cpp52
1 files changed, 14 insertions, 38 deletions
diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp
index f28f274e2..f3713f120 100644
--- a/src/plugins/directshow/dsserviceplugin.cpp
+++ b/src/plugins/directshow/dsserviceplugin.cpp
@@ -39,7 +39,6 @@
#include "dsvideodevicecontrol.h"
#ifdef QMEDIA_DIRECTSHOW_CAMERA
-#include <QtCore/QElapsedTimer>
#include <dshow.h>
#include "dscameraservice.h"
#endif
@@ -122,9 +121,9 @@ QByteArray DSServicePlugin::defaultDevice(const QByteArray &service) const
{
#ifdef QMEDIA_DIRECTSHOW_CAMERA
if (service == Q_MEDIASERVICE_CAMERA) {
- updateDevices();
-
- return m_defaultCameraDevice;
+ const QList<DSVideoDeviceInfo> &devs = DSVideoDeviceControl::availableDevices();
+ if (!devs.isEmpty())
+ return devs.first().first;
}
#endif
@@ -133,52 +132,29 @@ QByteArray DSServicePlugin::defaultDevice(const QByteArray &service) const
QList<QByteArray> DSServicePlugin::devices(const QByteArray &service) const
{
+ QList<QByteArray> result;
+
#ifdef QMEDIA_DIRECTSHOW_CAMERA
if (service == Q_MEDIASERVICE_CAMERA) {
- updateDevices();
-
- return m_cameraDevices;
+ const QList<DSVideoDeviceInfo> &devs = DSVideoDeviceControl::availableDevices();
+ Q_FOREACH (const DSVideoDeviceInfo &info, devs)
+ result.append(info.first);
}
#endif
- return QList<QByteArray>();
+ return result;
}
QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
{
#ifdef QMEDIA_DIRECTSHOW_CAMERA
if (service == Q_MEDIASERVICE_CAMERA) {
- updateDevices();
-
- for (int i=0; i<m_cameraDevices.count(); i++)
- if (m_cameraDevices[i] == device)
- return m_cameraDescriptions[i];
+ const QList<DSVideoDeviceInfo> &devs = DSVideoDeviceControl::availableDevices();
+ Q_FOREACH (const DSVideoDeviceInfo &info, devs) {
+ if (info.first == device)
+ return info.second;
+ }
}
#endif
return QString();
}
-
-#ifdef QMEDIA_DIRECTSHOW_CAMERA
-
-void DSServicePlugin::updateDevices() const
-{
- static QElapsedTimer timer;
- if (timer.isValid() && timer.elapsed() < 500) // ms
- return;
-
- addRefCount();
-
- m_defaultCameraDevice.clear();
- DSVideoDeviceControl::enumerateDevices(&m_cameraDevices, &m_cameraDescriptions);
-
- if (m_cameraDevices.isEmpty()) {
- qWarning() << "No camera devices found";
- } else {
- m_defaultCameraDevice = m_cameraDevices.first();
- }
-
- releaseRefCount();
- timer.restart();
-}
-#endif
-