summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp
diff options
context:
space:
mode:
authorGareth Stockwell <ext-gareth.stockwell@nokia.com>2010-03-18 08:30:45 (GMT)
committerGareth Stockwell <ext-gareth.stockwell@nokia.com>2010-03-18 14:38:38 (GMT)
commit0c8d49ca802da435107c489142064e2736b7e10f (patch)
tree204bfbeef3e8d9c2158e2ad0047efd8888850ce0 /src/3rdparty/phonon/mmf/videoplayer_dsa.cpp
parent4bec9a7dcb89e18b54a7bc3f5230b5a98611fd06 (diff)
downloadQt-0c8d49ca802da435107c489142064e2736b7e10f.zip
Qt-0c8d49ca802da435107c489142064e2736b7e10f.tar.gz
Qt-0c8d49ca802da435107c489142064e2736b7e10f.tar.bz2
Added support for video surfaces to Phonon MMF backend
Symbian^3 introduces a new compositing graphics subsystem in which non-UI content such as video is provided by client applications via graphics surfaces. This patch modifies the video playback part of the Phonon MMF backend so that, on devices which use the new graphics architecture (NGA), video is rendered to a surface. On devices which use the legacy graphics architecture, the existing video rendering path, which uses Direct Screen Access (DSA) is maintained. On NGA devices, video playback applications do not deal with surfaces directly; instead, they use a new MMF client API called CVideoPlayerUtility2. The implementation of this API takes care of creating a graphics surface, registering it with the window manager, and directing the output of the video decoder into this surface. CVideoPlayerUtility2 inherits from the legacy video playback API, CVideoPlayerUtility, deprecating certain functions and adding new ones. The main changes involved in modifying CVideoPlayerUtility client code to instead use CVideoPlayerUtility2 are: 1. CVideoPlayerUtility requires a window handle to be provided at object construction time. The CVideoPlayerUtility2 constructor does not take a window handle; it is provided by the client later via the SetDisplayWindowL function. 2. CVideoPlayerUtility requires the client to provide an absolute screen rectangle at construction time, and then to call SetDisplayWindowL whenever this rectangle changes due to either window repositioning or resizing. CVideoPlayerUtility2 requires the client to provide a display rectangle which is relative to the display window. This rectangle must be updated via SetVideoExtentL / SetWindowClipRectL when the window is resized, but no update is required when the window is repositioned - the compositing window system takes care of repositioning the video content on the screen. 3. CVideoPlayerUtility requires the client to paint transparent black into the region of the window in which video will be displayed. CVideoPlayerUtility2 does not require the client to paint the video window. In order to accomodate these differences, the existing VideoPlayer and VideoOutput classes are replaced with AbstractVideoPlayer and AbstractVideoOutput respectively. These abstract base classes encapsulate functionality which is common between the DSA and surface rendering client code. Because CVideoPlayerUtility2 inherits from CVideoPlayerUtility, AbstractVideoPlayer is able to hold a pointer to CVideoPlayerUtility, via which it controls functionality which is not affected by the details of the rendering path, such as play/pause/stop, seek and metadata access. The three areas of divergence listed above are encapsulated in the derived classes DsaVideoOutput/SurfaceVideoOutput and DsaVideoPlayer/ SurfaceVideoPlayer. Of the three, (1) and (3) are fairly straightforward. For DSA video playback, the need to respond to changes in video widget absolute screen position in (2) necessitated the AncestorMoveMonitor class, which installs an event filter on each ancestor of the video widget. This class is not required for surface video playback and is therefore removed from the surface-rendering code path. Selection of either the DSA- or surface-rendering code path is done at qmake time, via the exists(...) check introduced in mmf.pro. This checks for existence of the header in which CVideoPlayerUtility2 is defined; if this file is found, surface rendering is selected, otherwise the DSA rendering version of the backend is built. Note that this approach is not completely robust, since it is possible for an environment to include the videoplayer2.h header and yet be configured to use the legacy graphics subsystem. This could be dealt with by instead performing the check for surface support at configuration time, building and executing a small Symbian program which will return different output according to which of the two graphics subsystems is in use. Task-number: QTBUG-8919 Reviewed-by: Frans Englich
Diffstat (limited to 'src/3rdparty/phonon/mmf/videoplayer_dsa.cpp')
-rw-r--r--src/3rdparty/phonon/mmf/videoplayer_dsa.cpp285
1 files changed, 285 insertions, 0 deletions
diff --git a/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp b/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp
new file mode 100644
index 0000000..21cdb16
--- /dev/null
+++ b/src/3rdparty/phonon/mmf/videoplayer_dsa.cpp
@@ -0,0 +1,285 @@
+/* This file is part of the KDE project.
+
+Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+
+This library is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 2.1 or 3 of the License.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <coecntrl.h> // for CCoeControl
+
+#include <QApplication> // for QApplication::activeWindow
+#include <QtCore/private/qcore_symbian_p.h> // for qt_TRect2QRect
+
+#include "utils.h"
+#include "videooutput_dsa.h"
+#include "videoplayer_dsa.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace Phonon;
+using namespace Phonon::MMF;
+
+// Two-phase constructor idiom is used because construct() calls virtual
+// functions and therefore cannot be called from the AbstractVideoPlayer
+// C++ constructor.
+DsaVideoPlayer* DsaVideoPlayer::create(MediaObject *parent,
+ const AbstractPlayer *player)
+{
+ QScopedPointer<DsaVideoPlayer> self(new DsaVideoPlayer(parent, player));
+ self->construct();
+ return self.take();
+}
+
+DsaVideoPlayer::DsaVideoPlayer(MediaObject *parent, const AbstractPlayer *player)
+ : AbstractVideoPlayer(parent, player)
+ , m_dsaActive(false)
+ , m_dsaWasActive(false)
+{
+
+}
+
+DsaVideoPlayer::~DsaVideoPlayer()
+{
+
+}
+
+
+//-----------------------------------------------------------------------------
+// Public functions
+//-----------------------------------------------------------------------------
+
+void MMF::DsaVideoPlayer::videoWindowScreenRectChanged()
+{
+ QRect windowRect = static_cast<DsaVideoOutput *>(m_videoOutput)->videoWindowScreenRect();
+
+ // Clip to physical window size
+ // This is due to a defect in the layout when running on S60 3.2, which
+ // results in the rectangle of the video widget extending outside the
+ // screen in certain circumstances. These include the initial startup
+ // of the mediaplayer demo in portrait mode. When this rectangle is
+ // passed to the CVideoPlayerUtility, no video is rendered.
+ const TSize screenSize = m_screenDevice.SizeInPixels();
+ const QRect screenRect(0, 0, screenSize.iWidth, screenSize.iHeight);
+ windowRect = windowRect.intersected(screenRect);
+
+ // Recalculate scale factors. Pass 'false' as second parameter in order to
+ // suppress application of the change to the player - this is done at the end
+ // of the function.
+ updateScaleFactors(windowRect.size(), false);
+
+ m_videoScreenRect = qt_QRect2TRect(windowRect);
+
+ parametersChanged(WindowScreenRect | ScaleFactors);
+}
+
+void MMF::DsaVideoPlayer::suspendDirectScreenAccess()
+{
+ m_dsaWasActive = stopDirectScreenAccess();
+}
+
+void MMF::DsaVideoPlayer::resumeDirectScreenAccess()
+{
+ if (m_dsaWasActive) {
+ startDirectScreenAccess();
+ m_dsaWasActive = false;
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// Private functions
+//-----------------------------------------------------------------------------
+
+void MMF::DsaVideoPlayer::createPlayer()
+{
+ // A window handle must be provided in order to construct
+ // CVideoPlayerUtility. If no VideoOutput has yet been connected to this
+ // player, we temporarily use the top-level application window handle.
+ // No video ever gets rendered into this window; SetDisplayWindowL is
+ // always called before rendering actually begins.
+ if (!m_window)
+ m_window = QApplication::activeWindow()->effectiveWinId()->DrawableWindow();
+
+ const TInt priority = 0;
+ const TMdaPriorityPreference preference = EMdaPriorityPreferenceNone;
+
+ CVideoPlayerUtility *player = 0;
+ QT_TRAP_THROWING(player = CVideoPlayerUtility::NewL(*this,
+ priority, preference,
+ m_wsSession, m_screenDevice,
+ *m_window,
+ m_videoScreenRect, m_videoScreenRect));
+ m_player.reset(player);
+
+ // CVideoPlayerUtility::NewL starts DSA
+ m_dsaActive = true;
+
+ m_player->RegisterForVideoLoadingNotification(*this);
+}
+
+void MMF::DsaVideoPlayer::initVideoOutput()
+{
+ bool connected = connect(
+ m_videoOutput, SIGNAL(videoWindowScreenRectChanged()),
+ this, SLOT(videoWindowScreenRectChanged())
+ );
+ Q_ASSERT(connected);
+
+ connected = connect(
+ m_videoOutput, SIGNAL(beginVideoWindowNativePaint()),
+ this, SLOT(suspendDirectScreenAccess())
+ );
+ Q_ASSERT(connected);
+
+ connected = connect(
+ m_videoOutput, SIGNAL(endVideoWindowNativePaint()),
+ this, SLOT(resumeDirectScreenAccess())
+ );
+ Q_ASSERT(connected);
+
+ // Suppress warnings in release builds
+ Q_UNUSED(connected);
+
+ AbstractVideoPlayer::initVideoOutput();
+}
+
+void MMF::DsaVideoPlayer::prepareCompleted()
+{
+ videoWindowScreenRectChanged();
+}
+
+void MMF::DsaVideoPlayer::handleVideoWindowChanged()
+{
+ if (!m_window) {
+ m_window = QApplication::activeWindow()->effectiveWinId()->DrawableWindow();
+ m_videoScreenRect = TRect();
+ }
+
+ parametersChanged(WindowHandle | WindowScreenRect);
+}
+
+#ifndef QT_NO_DEBUG
+
+// The following code is for debugging problems related to video visibility. It allows
+// the VideoPlayer instance to query the window server in order to determine the
+// DSA drawing region for the video window.
+
+class CDummyAO : public CActive
+{
+public:
+ CDummyAO() : CActive(CActive::EPriorityStandard) { CActiveScheduler::Add(this); }
+ void RunL() { }
+ void DoCancel() { }
+ TRequestStatus& Status() { return iStatus; }
+ void SetActive() { CActive::SetActive(); }
+};
+
+void getDsaRegion(RWsSession &session, const RWindowBase &window)
+{
+ RDirectScreenAccess dsa(session);
+ TInt err = dsa.Construct();
+ CDummyAO ao;
+ RRegion* region;
+ err = dsa.Request(region, ao.Status(), window);
+ ao.SetActive();
+ dsa.Close();
+ ao.Cancel();
+ if (region) {
+ qDebug() << "Phonon::MMF::getDsaRegion count" << region->Count();
+ for (int i=0; i<region->Count(); ++i) {
+ const TRect& rect = region->RectangleList()[i];
+ qDebug() << "Phonon::MMF::getDsaRegion rect"
+ << rect.iTl.iX << rect.iTl.iY << rect.iBr.iX << rect.iBr.iY;
+ }
+ region->Close();
+ }
+}
+
+#endif // QT_NO_DEBUG
+
+void MMF::DsaVideoPlayer::handleParametersChanged(VideoParameters parameters)
+{
+ TRACE_CONTEXT(DsaVideoPlayer::handleParametersChanged, EVideoInternal);
+ TRACE_ENTRY_0();
+
+#ifndef QT_NO_DEBUG
+ getDsaRegion(m_wsSession, *m_window);
+#endif
+
+ static const TBool antialias = ETrue;
+ int err = KErrNone;
+
+ if (parameters & ScaleFactors) {
+ TRAP(err, m_player->SetScaleFactorL(m_scaleWidth, m_scaleHeight,
+ antialias));
+ if(KErrNone != err) {
+ TRACE("SetScaleFactorL (1) err %d", err);
+ setError(tr("Video display error"), err);
+ }
+ }
+
+ if (KErrNone == err) {
+ if (parameters & WindowHandle || parameters & WindowScreenRect) {
+ TRAP(err,
+ m_player->SetDisplayWindowL(m_wsSession, m_screenDevice,
+ *m_window,
+ m_videoScreenRect,
+ m_videoScreenRect));
+ }
+
+ if (KErrNone != err) {
+ TRACE("SetDisplayWindowL err %d", err);
+ setError(tr("Video display error"), err);
+ } else {
+ m_dsaActive = true;
+ if (parameters & ScaleFactors) {
+ TRAP(err, m_player->SetScaleFactorL(m_scaleWidth, m_scaleHeight,
+ antialias));
+ if (KErrNone != err) {
+ TRACE("SetScaleFactorL (2) err %d", err);
+ setError(tr("Video display error"), err);
+ }
+ }
+ }
+ }
+
+ TRACE_EXIT_0();
+}
+
+void MMF::DsaVideoPlayer::startDirectScreenAccess()
+{
+ if (!m_dsaActive) {
+ TRAPD(err, m_player->StartDirectScreenAccessL());
+ if (KErrNone == err)
+ m_dsaActive = true;
+ else
+ setError(tr("Video display error"), err);
+ }
+}
+
+bool MMF::DsaVideoPlayer::stopDirectScreenAccess()
+{
+ const bool dsaWasActive = m_dsaActive;
+ if (m_dsaActive) {
+ TRAPD(err, m_player->StopDirectScreenAccessL());
+ if (KErrNone == err)
+ m_dsaActive = false;
+ else
+ setError(tr("Video display error"), err);
+ }
+ return dsaWasActive;
+}
+
+QT_END_NAMESPACE
+