summaryrefslogtreecommitdiffstats
path: root/src/plugins/directshow/common/directshowsamplegrabber.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-08-16 11:33:25 +0200
committerAndy Shaw <andy.shaw@qt.io>2017-08-16 11:58:54 +0000
commit343e281f0e7cc7fd9e1558e4d92f5019fa565181 (patch)
tree9262c3bcd119bd582e89f879d33b49acb43787f5 /src/plugins/directshow/common/directshowsamplegrabber.cpp
parent116cd7bdbd1e148aef05c27602780d65be335205 (diff)
DirectShow: Copy the frame data when we get it before emitting
Since the slot connected to the frameAvailable signal may be in another thread there is a bigger risk of it being invalid by the time the slot is invoked. Therefore we copy the data and emit with the copy to ensure that we don't lose the data. Task-number: QTBUG-61817 Change-Id: I2888661d8a7f97105a85f87b08cc9ec25f8ce8c7 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/directshow/common/directshowsamplegrabber.cpp')
-rw-r--r--src/plugins/directshow/common/directshowsamplegrabber.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/plugins/directshow/common/directshowsamplegrabber.cpp b/src/plugins/directshow/common/directshowsamplegrabber.cpp
index b33c3cfc6..fb95370ca 100644
--- a/src/plugins/directshow/common/directshowsamplegrabber.cpp
+++ b/src/plugins/directshow/common/directshowsamplegrabber.cpp
@@ -99,9 +99,11 @@ public:
STDMETHODIMP BufferCB(double time, BYTE *buffer, long bufferLen)
{
- if (m_grabber)
- Q_EMIT m_grabber->bufferAvailable(time, buffer, bufferLen);
-
+ if (m_grabber) {
+ // Deep copy, the data might be modified or freed after the callback returns
+ QByteArray data(reinterpret_cast<const char *>(buffer), bufferLen);
+ Q_EMIT m_grabber->bufferAvailable(time, data);
+ }
return S_OK;
}