diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-08-16 11:33:25 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2017-08-16 11:58:54 +0000 |
commit | 343e281f0e7cc7fd9e1558e4d92f5019fa565181 (patch) | |
tree | 9262c3bcd119bd582e89f879d33b49acb43787f5 /src/plugins/directshow/player | |
parent | 116cd7bdbd1e148aef05c27602780d65be335205 (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/player')
-rw-r--r-- | src/plugins/directshow/player/directshowplayerservice.cpp | 9 | ||||
-rw-r--r-- | src/plugins/directshow/player/directshowplayerservice.h | 4 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp index 2f959b232..9cbb62969 100644 --- a/src/plugins/directshow/player/directshowplayerservice.cpp +++ b/src/plugins/directshow/player/directshowplayerservice.cpp @@ -1453,7 +1453,7 @@ void DirectShowPlayerService::videoOutputChanged() QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers") -void DirectShowPlayerService::onAudioBufferAvailable(double time, quint8 *buffer, long len) +void DirectShowPlayerService::onAudioBufferAvailable(double time, const QByteArray &data) { QMutexLocker locker(&m_mutex); if (!m_audioProbeControl || !m_audioSampleGrabber) @@ -1497,18 +1497,16 @@ void DirectShowPlayerService::onAudioBufferAvailable(double time, quint8 *buffer format.setSampleType(QAudioFormat::SignedInt); const quint64 startTime = quint64(time * 1000.); - QAudioBuffer audioBuffer(QByteArray(reinterpret_cast<const char *>(buffer), len), + QAudioBuffer audioBuffer(data, format, startTime); Q_EMIT m_audioProbeControl->audioBufferProbed(audioBuffer); } -void DirectShowPlayerService::onVideoBufferAvailable(double time, quint8 *buffer, long len) +void DirectShowPlayerService::onVideoBufferAvailable(double time, const QByteArray &data) { Q_UNUSED(time); - Q_UNUSED(buffer); - Q_UNUSED(len); QMutexLocker locker(&m_mutex); if (!m_videoProbeControl || !m_videoSampleGrabber) @@ -1536,7 +1534,6 @@ void DirectShowPlayerService::onVideoBufferAvailable(double time, quint8 *buffer const QSize &size = videoFormat.frameSize(); const int bytesPerLine = DirectShowMediaType::bytesPerLine(videoFormat); - QByteArray data(reinterpret_cast<const char *>(buffer), len); QVideoFrame frame(new QMemoryVideoBuffer(data, bytesPerLine), size, format); diff --git a/src/plugins/directshow/player/directshowplayerservice.h b/src/plugins/directshow/player/directshowplayerservice.h index 676d88fb5..01d05449e 100644 --- a/src/plugins/directshow/player/directshowplayerservice.h +++ b/src/plugins/directshow/player/directshowplayerservice.h @@ -106,8 +106,8 @@ protected: private Q_SLOTS: void videoOutputChanged(); - void onAudioBufferAvailable(double time, quint8 *buffer, long len); - void onVideoBufferAvailable(double time, quint8 *buffer, long len); + void onAudioBufferAvailable(double time, const QByteArray &data); + void onVideoBufferAvailable(double time, const QByteArray &data); private: void releaseGraph(); |