From 389d66b3ed5e2d798e9fb124064523239c393ad8 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 7 Apr 2014 14:24:51 +0200 Subject: DirectShow: Refactor camera backend. Almost entire rewrite of the camera backend. It doesn't provide new features but is more stable and behave as it should. - Correctly report camera state and status - Correctly report if the camera is ready to capture - Emit imageExposed() signal - Save captured images in an appropriate directory - Images can be captured even without a viewport - Better error handling Removed the custom QVideoWidgetControl as it doesn't provide anything more than the QVideoWidget's renderer control fallback. Task-number: QTBUG-33782 Change-Id: I9baf6f83e7c69619f20a101921f7865a1c90d5e4 Reviewed-by: Christian Stromme --- src/plugins/directshow/dsserviceplugin.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/plugins/directshow/dsserviceplugin.cpp') diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp index d262febdd..954fab22c 100644 --- a/src/plugins/directshow/dsserviceplugin.cpp +++ b/src/plugins/directshow/dsserviceplugin.cpp @@ -79,15 +79,32 @@ extern const CLSID CLSID_VideoInputDeviceCategory; QT_USE_NAMESPACE +static int g_refCount = 0; +void addRefCount() +{ + if (++g_refCount == 1) + CoInitialize(NULL); +} + +void releaseRefCount() +{ + if (--g_refCount == 0) + CoUninitialize(); +} + QMediaService* DSServicePlugin::create(QString const& key) { #ifdef QMEDIA_DIRECTSHOW_CAMERA - if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) + if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) { + addRefCount(); return new DSCameraService; + } #endif #ifdef QMEDIA_DIRECTSHOW_PLAYER - if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) + if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) { + addRefCount(); return new DirectShowPlayerService; + } #endif return 0; @@ -96,6 +113,7 @@ QMediaService* DSServicePlugin::create(QString const& key) void DSServicePlugin::release(QMediaService *service) { delete service; + releaseRefCount(); } QMediaServiceProviderHint::Features DSServicePlugin::supportedFeatures( @@ -154,6 +172,8 @@ QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByt void DSServicePlugin::updateDevices() const { + addRefCount(); + m_defaultCameraDevice.clear(); DSVideoDeviceControl::enumerateDevices(&m_cameraDevices, &m_cameraDescriptions); @@ -162,6 +182,8 @@ void DSServicePlugin::updateDevices() const } else { m_defaultCameraDevice = m_cameraDevices.first(); } + + releaseRefCount(); } #endif -- cgit v1.2.3