1
/* This file is part of the KDE project.
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
19
#include <coecntrl.h> // for CCoeControl
21
#include <QApplication> // for QApplication::activeWindow
22
#include <QtCore/private/qcore_symbian_p.h> // for qt_TRect2QRect
25
#include "videooutput_dsa.h"
26
#include "videoplayer_dsa.h"
30
using namespace Phonon;
31
using namespace Phonon::MMF;
33
// Two-phase constructor idiom is used because construct() calls virtual
34
// functions and therefore cannot be called from the AbstractVideoPlayer
36
DsaVideoPlayer* DsaVideoPlayer::create(MediaObject *parent,
37
const AbstractPlayer *player)
39
QScopedPointer<DsaVideoPlayer> self(new DsaVideoPlayer(parent, player));
44
DsaVideoPlayer::DsaVideoPlayer(MediaObject *parent, const AbstractPlayer *player)
45
: AbstractVideoPlayer(parent, player)
47
, m_dsaWasActive(false)
52
DsaVideoPlayer::~DsaVideoPlayer()
58
//-----------------------------------------------------------------------------
60
//-----------------------------------------------------------------------------
62
void MMF::DsaVideoPlayer::videoWindowScreenRectChanged()
64
QRect windowRect = static_cast<DsaVideoOutput *>(m_videoOutput)->videoWindowScreenRect();
66
// Clip to physical window size
67
// This is due to a defect in the layout when running on S60 3.2, which
68
// results in the rectangle of the video widget extending outside the
69
// screen in certain circumstances. These include the initial startup
70
// of the mediaplayer demo in portrait mode. When this rectangle is
71
// passed to the CVideoPlayerUtility, no video is rendered.
72
const TSize screenSize = m_screenDevice.SizeInPixels();
73
const QRect screenRect(0, 0, screenSize.iWidth, screenSize.iHeight);
74
windowRect = windowRect.intersected(screenRect);
76
// Recalculate scale factors. Pass 'false' as second parameter in order to
77
// suppress application of the change to the player - this is done at the end
79
updateScaleFactors(windowRect.size(), false);
81
m_videoScreenRect = qt_QRect2TRect(windowRect);
83
parametersChanged(WindowScreenRect | ScaleFactors);
86
void MMF::DsaVideoPlayer::suspendDirectScreenAccess()
88
m_dsaWasActive = stopDirectScreenAccess();
91
void MMF::DsaVideoPlayer::resumeDirectScreenAccess()
94
startDirectScreenAccess();
95
m_dsaWasActive = false;
100
//-----------------------------------------------------------------------------
102
//-----------------------------------------------------------------------------
104
void MMF::DsaVideoPlayer::createPlayer()
106
// A window handle must be provided in order to construct
107
// CVideoPlayerUtility. If no VideoOutput has yet been connected to this
108
// player, we temporarily use the top-level application window handle.
109
// No video ever gets rendered into this window; SetDisplayWindowL is
110
// always called before rendering actually begins.
112
m_window = QApplication::activeWindow()->effectiveWinId()->DrawableWindow();
114
const TInt priority = 0;
115
const TMdaPriorityPreference preference = EMdaPriorityPreferenceNone;
117
CVideoPlayerUtility *player = 0;
118
QT_TRAP_THROWING(player = CVideoPlayerUtility::NewL(*this,
119
priority, preference,
120
m_wsSession, m_screenDevice,
122
m_videoScreenRect, m_videoScreenRect));
123
m_player.reset(player);
125
// CVideoPlayerUtility::NewL starts DSA
128
m_player->RegisterForVideoLoadingNotification(*this);
131
void MMF::DsaVideoPlayer::initVideoOutput()
133
bool connected = connect(
134
m_videoOutput, SIGNAL(videoWindowScreenRectChanged()),
135
this, SLOT(videoWindowScreenRectChanged())
140
m_videoOutput, SIGNAL(beginVideoWindowNativePaint()),
141
this, SLOT(suspendDirectScreenAccess())
146
m_videoOutput, SIGNAL(endVideoWindowNativePaint()),
147
this, SLOT(resumeDirectScreenAccess())
151
// Suppress warnings in release builds
154
AbstractVideoPlayer::initVideoOutput();
157
void MMF::DsaVideoPlayer::prepareCompleted()
159
videoWindowScreenRectChanged();
162
void MMF::DsaVideoPlayer::handleVideoWindowChanged()
165
if (QWidget *window = QApplication::activeWindow())
166
m_window = window->effectiveWinId()->DrawableWindow();
169
m_videoScreenRect = TRect();
172
parametersChanged(WindowHandle | WindowScreenRect);
177
// The following code is for debugging problems related to video visibility. It allows
178
// the VideoPlayer instance to query the window server in order to determine the
179
// DSA drawing region for the video window.
181
class CDummyAO : public CActive
184
CDummyAO() : CActive(CActive::EPriorityStandard) { CActiveScheduler::Add(this); }
187
TRequestStatus& Status() { return iStatus; }
188
void SetActive() { CActive::SetActive(); }
191
void getDsaRegion(RWsSession &session, const RWindowBase &window)
193
RDirectScreenAccess dsa(session);
194
TInt err = dsa.Construct();
197
err = dsa.Request(region, ao.Status(), window);
202
qDebug() << "Phonon::MMF::getDsaRegion count" << region->Count();
203
for (int i=0; i<region->Count(); ++i) {
204
const TRect& rect = region->RectangleList()[i];
205
qDebug() << "Phonon::MMF::getDsaRegion rect"
206
<< rect.iTl.iX << rect.iTl.iY << rect.iBr.iX << rect.iBr.iY;
212
#endif // QT_NO_DEBUG
214
void MMF::DsaVideoPlayer::handleParametersChanged(VideoParameters parameters)
216
TRACE_CONTEXT(DsaVideoPlayer::handleParametersChanged, EVideoInternal);
223
getDsaRegion(m_wsSession, *m_window);
226
static const TBool antialias = ETrue;
229
if (parameters & ScaleFactors) {
230
TRAP(err, m_player->SetScaleFactorL(m_scaleWidth, m_scaleHeight,
232
if(KErrNone != err) {
233
TRACE("SetScaleFactorL (1) err %d", err);
234
setError(tr("Video display error"), err);
238
if (KErrNone == err) {
239
if (parameters & WindowHandle || parameters & WindowScreenRect) {
241
m_player->SetDisplayWindowL(m_wsSession, m_screenDevice,
247
if (KErrNone != err) {
248
TRACE("SetDisplayWindowL err %d", err);
249
setError(tr("Video display error"), err);
252
if (parameters & ScaleFactors) {
253
TRAP(err, m_player->SetScaleFactorL(m_scaleWidth, m_scaleHeight,
255
if (KErrNone != err) {
256
TRACE("SetScaleFactorL (2) err %d", err);
257
setError(tr("Video display error"), err);
266
void MMF::DsaVideoPlayer::startDirectScreenAccess()
269
TRAPD(err, m_player->StartDirectScreenAccessL());
273
setError(tr("Video display error"), err);
277
bool MMF::DsaVideoPlayer::stopDirectScreenAccess()
279
const bool dsaWasActive = m_dsaActive;
281
TRAPD(err, m_player->StopDirectScreenAccessL());
285
setError(tr("Video display error"), err);