summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Doroshchuk <valentyn.doroshchuk@qt.io>2017-10-16 11:26:15 (GMT)
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2017-12-14 10:31:38 (GMT)
commit8ec92863f13061c3dd2d56376eddfe258915589f (patch)
treeef60462b87cce1bdcd45386ce2d13c1dab16be03
parent7097e38a48db6ea25314121e70c48e8561399d98 (diff)
downloadqtmultimedia-8ec92863f13061c3dd2d56376eddfe258915589f.tar.gz
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 <christian.stromme@qt.io>
-rw-r--r--src/plugins/directshow/player/directshowplayerservice.cpp31
-rw-r--r--src/plugins/directshow/player/directshowplayerservice.h4
2 files changed, 27 insertions, 8 deletions
diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp
index 8ee5d67..2218ca5 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<IFilterGraph2>(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<IFilterGraph2>(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 01d0544..cc7b4dd 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