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 <videoplayer2.h>
21
#include <QtCore/private/qcore_symbian_p.h> // for qt_QRect2TRect
24
#include "videooutput_surface.h"
25
#include "videoplayer_surface.h"
29
using namespace Phonon;
30
using namespace Phonon::MMF;
32
// Two-phase constructor idiom is used because construct() calls virtual
33
// functions and therefore cannot be called from the AbstractVideoPlayer
35
SurfaceVideoPlayer* SurfaceVideoPlayer::create(MediaObject *parent,
36
const AbstractPlayer *player)
38
QScopedPointer<SurfaceVideoPlayer> self(new SurfaceVideoPlayer(parent, player));
43
SurfaceVideoPlayer::SurfaceVideoPlayer(MediaObject *parent, const AbstractPlayer *player)
44
: AbstractVideoPlayer(parent, player)
50
SurfaceVideoPlayer::~SurfaceVideoPlayer()
56
//-----------------------------------------------------------------------------
58
//-----------------------------------------------------------------------------
60
void MMF::SurfaceVideoPlayer::videoWindowSizeChanged()
63
updateScaleFactors(m_videoOutput->videoWindowSize());
67
//-----------------------------------------------------------------------------
69
//-----------------------------------------------------------------------------
71
void MMF::SurfaceVideoPlayer::createPlayer()
73
const TInt priority = 0;
74
const TMdaPriorityPreference preference = EMdaPriorityPreferenceNone;
76
CVideoPlayerUtility2 *player = 0;
77
QT_TRAP_THROWING(player = CVideoPlayerUtility2::NewL(*this,
78
priority, preference));
79
m_player.reset(player);
82
void MMF::SurfaceVideoPlayer::initVideoOutput()
84
Q_ASSERT(m_videoOutput);
86
bool connected = connect(
87
m_videoOutput, SIGNAL(videoWindowSizeChanged()),
88
this, SLOT(videoWindowSizeChanged())
92
// Suppress warnings in release builds
95
AbstractVideoPlayer::initVideoOutput();
98
void MMF::SurfaceVideoPlayer::prepareCompleted()
100
videoWindowSizeChanged();
103
void MMF::SurfaceVideoPlayer::handleVideoWindowChanged()
105
parametersChanged(WindowHandle);
108
void MMF::SurfaceVideoPlayer::handleParametersChanged(VideoParameters parameters)
110
TRACE_CONTEXT(SurfaceVideoPlayer::handleParametersChanged, EVideoApi);
111
TRACE_ENTRY("parameters 0x%x", parameters.operator int());
115
m_videoOutput->dump();
116
const QSize size = m_videoOutput->videoWindowSize();
117
rect.SetSize(TSize(size.width(), size.height()));
120
CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data());
123
if (parameters & WindowHandle) {
124
removeDisplayWindow();
125
addDisplayWindow(rect);
128
if (KErrNone == err) {
129
if (parameters & ScaleFactors) {
130
if (!m_displayWindow)
131
addDisplayWindow(rect);
132
Q_ASSERT(m_displayWindow);
133
TRAP(err, player->SetVideoExtentL(*m_displayWindow, rect));
135
TRAP(err, player->SetWindowClipRectL(*m_displayWindow, rect));
137
TRAP(err, player->SetScaleFactorL(*m_displayWindow, m_scaleWidth, m_scaleHeight));
139
setError(tr("Video display error"), err);
147
void MMF::SurfaceVideoPlayer::addDisplayWindow(const TRect &rect)
149
TRACE_CONTEXT(SurfaceVideoPlayer::addDisplayWindow, EVideoApi);
150
TRACE_ENTRY("rect %d %d - %d %d", rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
152
Q_ASSERT(!m_displayWindow);
153
RWindow *window = static_cast<RWindow *>(m_window);
155
TRACE("window 0x%08x", window);
158
window->SetBackgroundColor(TRgb(0, 0, 0, 255));
159
CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data());
161
TRAPD(err, player->AddDisplayWindowL(m_wsSession, m_screenDevice, *window, rect, rect));
163
m_displayWindow = window;
165
setError(tr("Video display error"), err);
166
TRACE("err %d", err);
172
void MMF::SurfaceVideoPlayer::removeDisplayWindow()
174
TRACE_CONTEXT(SurfaceVideoPlayer::removeDisplayWindow, EVideoApi);
175
TRACE("player 0x%08x window 0x%08x", m_player.data(), m_displayWindow);
177
CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data());
178
if (player && m_displayWindow) {
179
player->RemoveDisplayWindow(*m_displayWindow);