directshow: Fix plugging/unplugging a second camera

When having more than 1 camera (like one laptop integrated webcam
and a separate one) you had to restart the application for QCameraInfo::availableCameras()
to work.

Change-Id: I47cfa928cfd9500524b81a4bf8ec5ebff0b79879
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
Sergio Martins
2015-02-04 16:28:21 +00:00
committed by Sérgio Martins
parent 456944f855
commit 8923c0ff6b

View File

@@ -39,6 +39,7 @@
#include "dsvideodevicecontrol.h"
#ifdef QMEDIA_DIRECTSHOW_CAMERA
#include <QtCore/QElapsedTimer>
#include <dshow.h>
#include "dscameraservice.h"
#endif
@@ -121,7 +122,6 @@ QByteArray DSServicePlugin::defaultDevice(const QByteArray &service) const
{
#ifdef QMEDIA_DIRECTSHOW_CAMERA
if (service == Q_MEDIASERVICE_CAMERA) {
if (m_cameraDevices.isEmpty())
updateDevices();
return m_defaultCameraDevice;
@@ -135,7 +135,6 @@ QList<QByteArray> DSServicePlugin::devices(const QByteArray &service) const
{
#ifdef QMEDIA_DIRECTSHOW_CAMERA
if (service == Q_MEDIASERVICE_CAMERA) {
if (m_cameraDevices.isEmpty())
updateDevices();
return m_cameraDevices;
@@ -149,7 +148,6 @@ QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByt
{
#ifdef QMEDIA_DIRECTSHOW_CAMERA
if (service == Q_MEDIASERVICE_CAMERA) {
if (m_cameraDevices.isEmpty())
updateDevices();
for (int i=0; i<m_cameraDevices.count(); i++)
@@ -164,6 +162,10 @@ QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByt
void DSServicePlugin::updateDevices() const
{
static QElapsedTimer timer;
if (timer.isValid() && timer.elapsed() < 500) // ms
return;
addRefCount();
m_defaultCameraDevice.clear();
@@ -176,6 +178,7 @@ void DSServicePlugin::updateDevices() const
}
releaseRefCount();
timer.restart();
}
#endif