1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/* 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()
{
Q_ASSERT(m_videoOutput);
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;
}
void MMF::DsaVideoPlayer::initVideoOutput()
{
Q_ASSERT(m_videoOutput);
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()
{
if (m_videoOutput)
videoWindowScreenRectChanged();
}
void MMF::DsaVideoPlayer::handleVideoWindowChanged()
{
if (!m_window) {
if (QWidget *window = QApplication::activeWindow())
m_window = window->effectiveWinId()->DrawableWindow();
else
m_window = 0;
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)
{
// Dump complete window tree
session.LogCommand(RWsSession::ELoggingStatusDump);
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("parameters 0x%x", parameters.operator int());
if (!m_window)
return;
#ifndef QT_NO_DEBUG
getDsaRegion(m_wsSession, *m_window);
#endif
if (m_player) {
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()
{
TRACE_CONTEXT(DsaVideoPlayer::startDirectScreenAccess, EVideoInternal);
TRACE_ENTRY("dsaActive %d", m_dsaActive);
int err = KErrNone;
if (!m_dsaActive) {
TRAP(err, m_player->StartDirectScreenAccessL());
if (KErrNone == err)
m_dsaActive = true;
else
setError(tr("Video display error"), err);
}
if (m_videoOutput)
m_videoOutput->dump();
TRACE_EXIT("error %d", err);
}
bool MMF::DsaVideoPlayer::stopDirectScreenAccess()
{
TRACE_CONTEXT(DsaVideoPlayer::stopDirectScreenAccess, EVideoInternal);
TRACE_ENTRY("dsaActive %d", m_dsaActive);
int err = KErrNone;
const bool dsaWasActive = m_dsaActive;
if (m_dsaActive) {
TRAP(err, m_player->StopDirectScreenAccessL());
if (KErrNone == err)
m_dsaActive = false;
else
setError(tr("Video display error"), err);
}
TRACE_EXIT("error %d", err);
return dsaWasActive;
}
QT_END_NAMESPACE
|