From 8ec92863f13061c3dd2d56376eddfe258915589f Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Mon, 16 Oct 2017 13:26:15 +0200 Subject: DirectShow: Fix memory leak in CLSID_FilterGraph Fixed memory leak when using Filter Graph Manager by moving creation of the manager to worker thread and changing threading model from shared to application thread. Task-number: QTBUG-52713 Change-Id: I7725697ced1992959d18588303c329b4dfd56b2e Reviewed-by: Christian Stromme --- .../directshow/player/directshowplayerservice.cpp | 31 +++++++++++++++++----- .../directshow/player/directshowplayerservice.h | 4 ++- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'src/plugins/directshow') diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp index 8ee5d67a1..2218ca5ed 100644 --- a/src/plugins/directshow/player/directshowplayerservice.cpp +++ b/src/plugins/directshow/player/directshowplayerservice.cpp @@ -318,18 +318,15 @@ void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream m_graphStatus = InvalidMedia; m_error = QMediaPlayer::ResourceError; } else { - // {36b73882-c2c8-11cf-8b46-00805f6cef60} - static const GUID iid_IFilterGraph2 = { - 0x36b73882, 0xc2c8, 0x11cf, {0x8b, 0x46, 0x00, 0x80, 0x5f, 0x6c, 0xef, 0x60} }; m_graphStatus = Loading; - m_graph = com_new(CLSID_FilterGraph, iid_IFilterGraph2); - if (stream) m_pendingTasks = SetStreamSource; else m_pendingTasks = SetUrlSource; + m_pendingTasks |= CreateGraph; + ::SetEvent(m_taskHandle); } @@ -340,6 +337,17 @@ void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream updateStatus(); } +void DirectShowPlayerService::doCreateGraph(QMutexLocker *locker) +{ + Q_UNUSED(locker); + + // {36b73882-c2c8-11cf-8b46-00805f6cef60} + static const GUID iid_IFilterGraph2 = { + 0x36b73882, 0xc2c8, 0x11cf, {0x8b, 0x46, 0x00, 0x80, 0x5f, 0x6c, 0xef, 0x60} }; + + m_graph = com_new(CLSID_FilterGraphNoThread, iid_IFilterGraph2); +} + void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) { IBaseFilter *source = 0; @@ -1686,6 +1694,8 @@ void DirectShowPlayerService::run() { QMutexLocker locker(&m_mutex); + CoInitialize(NULL); + for (;;) { while (m_pendingTasks == 0) { DWORD result = 0; @@ -1700,12 +1710,17 @@ void DirectShowPlayerService::run() } locker.relock(); - if (result == WAIT_OBJECT_0 + 1) { + if (m_graph && result == WAIT_OBJECT_0 + 1) { graphEvent(&locker); } } - if (m_pendingTasks & ReleaseGraph) { + if (m_pendingTasks & CreateGraph) { + m_pendingTasks ^= CreateGraph; + m_executingTask = CreateGraph; + + doCreateGraph(&locker); + } else if (m_pendingTasks & ReleaseGraph) { m_pendingTasks ^= ReleaseGraph; m_executingTask = ReleaseGraph; @@ -1798,6 +1813,8 @@ void DirectShowPlayerService::run() } m_executingTask = 0; } + + CoUninitialize(); } QT_END_NAMESPACE diff --git a/src/plugins/directshow/player/directshowplayerservice.h b/src/plugins/directshow/player/directshowplayerservice.h index 01d05449e..cc7b4dd3e 100644 --- a/src/plugins/directshow/player/directshowplayerservice.h +++ b/src/plugins/directshow/player/directshowplayerservice.h @@ -124,6 +124,7 @@ private: void run(); + void doCreateGraph(QMutexLocker *locker); void doSetUrlSource(QMutexLocker *locker); void doSetStreamSource(QMutexLocker *locker); void doRender(QMutexLocker *locker); @@ -169,7 +170,8 @@ private: ReleaseVideoProbe = 0x40000, ReleaseFilters = ReleaseGraph | ReleaseAudioOutput | ReleaseVideoOutput | ReleaseAudioProbe - | ReleaseVideoProbe + | ReleaseVideoProbe, + CreateGraph = 0x80000 }; enum Event -- cgit v1.2.3 From b69259b65707acc9fc3c0818f6affe53938cebc3 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Fri, 24 Nov 2017 08:36:36 +0100 Subject: DirectShow: Fix rendering of overlapping MDI subwindows Media type MEDIASUBTYPE_RGB32 is 32 bytes per pixel (like 0x00RRGGBB). When MDI subwindows are overlapping bottom window with QImage::Format_RGB32 requires 0xffRRGGBB. If "not used byte" is not 0xFF rendering will not be correct (0x00 produces empty image). Changed samples to ARGB32 to provide alpha channel, which is 0xFF in most cases. If alpha channel is not set to 0xFF, the bottom window will still be rendered incorrectly. Task-number: QTBUG-51405 Change-Id: I69f15d3835f901a04bf39b079394c6292b793610 Reviewed-by: Christian Stromme --- src/plugins/directshow/camera/dscamerasession.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/directshow') diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index 55ab868ce..dc0dfc8b3 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -815,8 +815,8 @@ bool DSCameraSession::configurePreviewFormat() return false; } - // Set sample grabber format (always RGB32) - static const AM_MEDIA_TYPE grabberFormat { MEDIATYPE_Video, MEDIASUBTYPE_RGB32, 0, 0, 0, FORMAT_VideoInfo, nullptr, 0, nullptr}; + // Set sample grabber format + static const AM_MEDIA_TYPE grabberFormat { MEDIATYPE_Video, MEDIASUBTYPE_ARGB32, 0, 0, 0, FORMAT_VideoInfo, nullptr, 0, nullptr}; if (!m_previewSampleGrabber->setMediaType(&grabberFormat)) return false; -- cgit v1.2.3 From 5629823b05ca7d24924ac879b5a0469a3cb03e78 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Wed, 18 Oct 2017 16:17:44 +0200 Subject: DirectShow: Add initialization of com library to service plugin In case when QCoreApplication is used the COM library was not initialized on the calling thread before the COM library calls were made. QApplication initializes it by calling OleInitialize(). Task-number: QTBUG-59320 Change-Id: I50a71b1bcc8a63f5a8ffd22c5d044f9c56de15f9 Reviewed-by: Timur Pocheptsov Reviewed-by: Christian Stromme --- src/plugins/directshow/dsserviceplugin.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/plugins/directshow') diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp index 51be7e500..cb4f0cdf9 100644 --- a/src/plugins/directshow/dsserviceplugin.cpp +++ b/src/plugins/directshow/dsserviceplugin.cpp @@ -123,7 +123,9 @@ QMediaServiceProviderHint::Features DSServicePlugin::supportedFeatures( QByteArray DSServicePlugin::defaultDevice(const QByteArray &service) const { if (service == Q_MEDIASERVICE_CAMERA) { + addRefCount(); const QList &devs = DSVideoDeviceControl::availableDevices(); + releaseRefCount(); if (!devs.isEmpty()) return devs.first().first; } @@ -135,7 +137,9 @@ QList DSServicePlugin::devices(const QByteArray &service) const QList result; if (service == Q_MEDIASERVICE_CAMERA) { + addRefCount(); const QList &devs = DSVideoDeviceControl::availableDevices(); + releaseRefCount(); for (const DSVideoDeviceInfo &info : devs) result.append(info.first); } @@ -146,7 +150,9 @@ QList DSServicePlugin::devices(const QByteArray &service) const QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) { if (service == Q_MEDIASERVICE_CAMERA) { + addRefCount(); const QList &devs = DSVideoDeviceControl::availableDevices(); + releaseRefCount(); for (const DSVideoDeviceInfo &info : devs) { if (info.first == device) return info.second; -- cgit v1.2.3 From c8bf0cd37c5f526e3687dfeff9e23d15104328b5 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Fri, 24 Nov 2017 08:36:36 +0100 Subject: DirectShow: Fix rendering of overlapping MDI subwindows Media type MEDIASUBTYPE_RGB32 is 32 bytes per pixel (like 0x00RRGGBB). When MDI subwindows are overlapping bottom window with QImage::Format_RGB32 requires 0xffRRGGBB. If "not used byte" is not 0xFF rendering will not be correct (0x00 produces empty image). Changed samples to ARGB32 to provide alpha channel, which is 0xFF in most cases. If alpha channel is not set to 0xFF, the bottom window will still be rendered incorrectly. Task-number: QTBUG-51405 Change-Id: I69f15d3835f901a04bf39b079394c6292b793610 Reviewed-by: Christian Stromme (cherry picked from commit b69259b65707acc9fc3c0818f6affe53938cebc3) --- src/plugins/directshow/camera/dscamerasession.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/directshow') diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index 55ab868ce..dc0dfc8b3 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -815,8 +815,8 @@ bool DSCameraSession::configurePreviewFormat() return false; } - // Set sample grabber format (always RGB32) - static const AM_MEDIA_TYPE grabberFormat { MEDIATYPE_Video, MEDIASUBTYPE_RGB32, 0, 0, 0, FORMAT_VideoInfo, nullptr, 0, nullptr}; + // Set sample grabber format + static const AM_MEDIA_TYPE grabberFormat { MEDIATYPE_Video, MEDIASUBTYPE_ARGB32, 0, 0, 0, FORMAT_VideoInfo, nullptr, 0, nullptr}; if (!m_previewSampleGrabber->setMediaType(&grabberFormat)) return false; -- cgit v1.2.3