From 72a43cee90b495b1e023a9dfe708a6d9105b994f Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 7 Apr 2015 09:55:16 +0200 Subject: Fix compile issue when building with -no-widgets Change-Id: I49a9aa684b0dfbe0e3d9e576aad06d65d6c3ecdd Reviewed-by: Yoann Lopes --- src/plugins/directshow/camera/dscamerasession.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/plugins/directshow/camera') diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index bce603655..d09c6e08d 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -32,7 +32,6 @@ ****************************************************************************/ #include -#include #include #include #include -- cgit v1.2.3 From f9145aca166ad2ca1514524ce88ded7834eb207c Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Thu, 9 Apr 2015 16:09:39 +0200 Subject: 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 --- .../directshow/camera/dsvideodevicecontrol.cpp | 72 ++++++++++++++-------- .../directshow/camera/dsvideodevicecontrol.h | 10 +-- 2 files changed, 52 insertions(+), 30 deletions(-) (limited to 'src/plugins/directshow/camera') diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp index 869299457..c3d23e027 100644 --- a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp +++ b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp @@ -33,6 +33,7 @@ #include #include +#include #include "dsvideodevicecontrol.h" #include "dscamerasession.h" @@ -48,33 +49,37 @@ extern const CLSID CLSID_VideoInputDeviceCategory; QT_BEGIN_NAMESPACE +Q_GLOBAL_STATIC(QList, deviceList) + DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent) : QVideoDeviceSelectorControl(parent) { m_session = qobject_cast(parent); - - enumerateDevices(&m_devices, &m_descriptions); - selected = 0; } int DSVideoDeviceControl::deviceCount() const { - return m_devices.count(); + updateDevices(); + return deviceList->count(); } QString DSVideoDeviceControl::deviceName(int index) const { - if (index >= 0 && index <= m_devices.count()) - return QString::fromUtf8(m_devices.at(index).constData()); + updateDevices(); + + if (index >= 0 && index <= deviceList->count()) + return QString::fromUtf8(deviceList->at(index).first.constData()); return QString(); } QString DSVideoDeviceControl::deviceDescription(int index) const { - if (index >= 0 && index <= m_descriptions.count()) - return m_descriptions.at(index); + updateDevices(); + + if (index >= 0 && index <= deviceList->count()) + return deviceList->at(index).second; return QString(); } @@ -89,10 +94,34 @@ int DSVideoDeviceControl::selectedDevice() const return selected; } -void DSVideoDeviceControl::enumerateDevices(QList *devices, QStringList *descriptions) +void DSVideoDeviceControl::setSelectedDevice(int index) { - devices->clear(); - descriptions->clear(); + updateDevices(); + + if (index >= 0 && index < deviceList->count()) { + if (m_session) { + QString device = deviceList->at(index).first; + if (device.startsWith("ds:")) + device.remove(0,3); + m_session->setDevice(device); + } + selected = index; + } +} + +const QList &DSVideoDeviceControl::availableDevices() +{ + updateDevices(); + return *deviceList; +} + +void DSVideoDeviceControl::updateDevices() +{ + static QElapsedTimer timer; + if (timer.isValid() && timer.elapsed() < 500) // ms + return; + + deviceList->clear(); ICreateDevEnum* pDevEnum = NULL; IEnumMoniker* pEnum = NULL; @@ -116,7 +145,9 @@ void DSVideoDeviceControl::enumerateDevices(QList *devices, QStringL if (SUCCEEDED(hr)) { QString output(QString::fromWCharArray(strName)); mallocInterface->Free(strName); - devices->append(output.toUtf8().constData()); + + DSVideoDeviceInfo devInfo; + devInfo.first = output.toUtf8(); IPropertyBag *pPropBag; hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)(&pPropBag)); @@ -130,7 +161,9 @@ void DSVideoDeviceControl::enumerateDevices(QList *devices, QStringL } pPropBag->Release(); } - descriptions->append(output); + devInfo.second = output; + + deviceList->append(devInfo); } pMoniker->Release(); } @@ -139,19 +172,8 @@ void DSVideoDeviceControl::enumerateDevices(QList *devices, QStringL } pDevEnum->Release(); } -} -void DSVideoDeviceControl::setSelectedDevice(int index) -{ - if (index >= 0 && index < m_devices.count()) { - if (m_session) { - QString device = m_devices.at(index); - if (device.startsWith("ds:")) - device.remove(0,3); - m_session->setDevice(device); - } - selected = index; - } + timer.restart(); } QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.h b/src/plugins/directshow/camera/dsvideodevicecontrol.h index a6d471088..0ba7ce36a 100644 --- a/src/plugins/directshow/camera/dsvideodevicecontrol.h +++ b/src/plugins/directshow/camera/dsvideodevicecontrol.h @@ -42,6 +42,8 @@ class DSCameraSession; //QTM_USE_NAMESPACE +typedef QPair DSVideoDeviceInfo; + class DSVideoDeviceControl : public QVideoDeviceSelectorControl { Q_OBJECT @@ -54,17 +56,15 @@ public: int defaultDevice() const; int selectedDevice() const; - static void enumerateDevices(QList *devices, QStringList *descriptions); + static const QList &availableDevices(); public Q_SLOTS: void setSelectedDevice(int index); private: - DSCameraSession* m_session; - - QList m_devices; - QStringList m_descriptions; + static void updateDevices(); + DSCameraSession* m_session; int selected; }; -- cgit v1.2.3