From 0c71b098965ce4779a7da785249497c15b9d1d14 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 8 Jun 2010 11:30:05 +0100 Subject: Prevent crash when video is played without a VideoWidget The Phonon API allows video to be played via a Phonon::MediaObject, even if no Phonon::VideoWidget has been connected to it. This patch prevents the Phonon MMF backend crashing in this scenario due to dereferencing a null pointer. Reviewed-by: Thierry Bastian --- src/3rdparty/phonon/mmf/abstractvideoplayer.cpp | 10 ++++++++-- src/3rdparty/phonon/mmf/videoplayer_dsa.cpp | 7 ++++++- src/3rdparty/phonon/mmf/videoplayer_surface.cpp | 5 ++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/3rdparty/phonon/mmf/abstractvideoplayer.cpp b/src/3rdparty/phonon/mmf/abstractvideoplayer.cpp index 2e0ab1c..ecfce9e 100644 --- a/src/3rdparty/phonon/mmf/abstractvideoplayer.cpp +++ b/src/3rdparty/phonon/mmf/abstractvideoplayer.cpp @@ -211,7 +211,8 @@ void MMF::AbstractVideoPlayer::aspectRatioChanged() TRACE_CONTEXT(AbstractVideoPlayer::aspectRatioChanged, EVideoInternal); TRACE_ENTRY("state %d aspectRatio %d", state()); - updateScaleFactors(m_videoOutput->videoWindowSize()); + if (m_videoOutput) + updateScaleFactors(m_videoOutput->videoWindowSize()); TRACE_EXIT_0(); } @@ -221,7 +222,8 @@ void MMF::AbstractVideoPlayer::scaleModeChanged() TRACE_CONTEXT(AbstractVideoPlayer::scaleModeChanged, EVideoInternal); TRACE_ENTRY("state %d", state()); - updateScaleFactors(m_videoOutput->videoWindowSize()); + if (m_videoOutput) + updateScaleFactors(m_videoOutput->videoWindowSize()); TRACE_EXIT_0(); } @@ -357,6 +359,8 @@ void MMF::AbstractVideoPlayer::videoOutputChanged() void MMF::AbstractVideoPlayer::initVideoOutput() { + Q_ASSERT(m_videoOutput); + bool connected = connect( m_videoOutput, SIGNAL(videoWindowChanged()), this, SLOT(videoWindowChanged()) @@ -400,6 +404,8 @@ QSize scaleToAspect(const QSize &srcRect, int aspectWidth, int aspectHeight) void MMF::AbstractVideoPlayer::updateScaleFactors(const QSize &windowSize, bool apply) { + Q_ASSERT(m_videoOutput); + if (m_videoFrameSize.isValid()) { QRect videoRect; diff --git a/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp b/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp index 1925471..f0255b1 100644 --- a/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp +++ b/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp @@ -61,6 +61,8 @@ DsaVideoPlayer::~DsaVideoPlayer() void MMF::DsaVideoPlayer::videoWindowScreenRectChanged() { + Q_ASSERT(m_videoOutput); + QRect windowRect = static_cast(m_videoOutput)->videoWindowScreenRect(); // Clip to physical window size @@ -130,6 +132,8 @@ void MMF::DsaVideoPlayer::createPlayer() void MMF::DsaVideoPlayer::initVideoOutput() { + Q_ASSERT(m_videoOutput); + bool connected = connect( m_videoOutput, SIGNAL(videoWindowScreenRectChanged()), this, SLOT(videoWindowScreenRectChanged()) @@ -156,7 +160,8 @@ void MMF::DsaVideoPlayer::initVideoOutput() void MMF::DsaVideoPlayer::prepareCompleted() { - videoWindowScreenRectChanged(); + if (m_videoOutput) + videoWindowScreenRectChanged(); } void MMF::DsaVideoPlayer::handleVideoWindowChanged() diff --git a/src/3rdparty/phonon/mmf/videoplayer_surface.cpp b/src/3rdparty/phonon/mmf/videoplayer_surface.cpp index fda7342..5d8db26 100644 --- a/src/3rdparty/phonon/mmf/videoplayer_surface.cpp +++ b/src/3rdparty/phonon/mmf/videoplayer_surface.cpp @@ -59,7 +59,8 @@ SurfaceVideoPlayer::~SurfaceVideoPlayer() void MMF::SurfaceVideoPlayer::videoWindowSizeChanged() { - updateScaleFactors(m_videoOutput->videoWindowSize()); + if (m_videoOutput) + updateScaleFactors(m_videoOutput->videoWindowSize()); } @@ -80,6 +81,8 @@ void MMF::SurfaceVideoPlayer::createPlayer() void MMF::SurfaceVideoPlayer::initVideoOutput() { + Q_ASSERT(m_videoOutput); + bool connected = connect( m_videoOutput, SIGNAL(videoWindowSizeChanged()), this, SLOT(videoWindowSizeChanged()) -- cgit v0.12