From 343e281f0e7cc7fd9e1558e4d92f5019fa565181 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 16 Aug 2017 11:33:25 +0200 Subject: 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 --- src/plugins/directshow/player/directshowplayerservice.cpp | 9 +++------ src/plugins/directshow/player/directshowplayerservice.h | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src/plugins/directshow/player') 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(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(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(); -- cgit v1.2.3