| 1 |
/* This file is part of the KDE project. |
| 2 |
|
| 3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
|
| 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. |
| 8 |
|
| 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. |
| 13 |
|
| 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/>. |
| 16 |
|
| 17 |
*/ |
| 18 |
|
| 19 |
#include <videoplayer2.h> |
| 20 |
|
| 21 |
#include <QtCore/private/qcore_symbian_p.h> // for qt_QRect2TRect |
| 22 |
|
| 23 |
#include "utils.h" |
| 24 |
#include "videooutput_surface.h" |
| 25 |
#include "videoplayer_surface.h" |
| 26 |
|
| 27 |
QT_BEGIN_NAMESPACE |
| 28 |
|
| 29 |
using namespace Phonon; |
| 30 |
using namespace Phonon::MMF; |
| 31 |
|
| 32 |
// Two-phase constructor idiom is used because construct() calls virtual |
| 33 |
// functions and therefore cannot be called from the AbstractVideoPlayer |
| 34 |
// C++ constructor. |
| 35 |
SurfaceVideoPlayer* SurfaceVideoPlayer::create(MediaObject *parent, |
| 36 |
const AbstractPlayer *player) |
| 37 |
{ |
| 38 |
QScopedPointer<SurfaceVideoPlayer> self(new SurfaceVideoPlayer(parent, player)); |
| 39 |
self->construct(); |
| 40 |
return self.take(); |
| 41 |
} |
| 42 |
|
| 43 |
SurfaceVideoPlayer::SurfaceVideoPlayer(MediaObject *parent, const AbstractPlayer *player) |
| 44 |
: AbstractVideoPlayer(parent, player) |
| 45 |
, m_displayWindow(0) |
| 46 |
{ |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
SurfaceVideoPlayer::~SurfaceVideoPlayer() |
| 51 |
{ |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
//----------------------------------------------------------------------------- |
| 57 |
// Public functions |
| 58 |
//----------------------------------------------------------------------------- |
| 59 |
|
| 60 |
void MMF::SurfaceVideoPlayer::videoWindowSizeChanged() |
| 61 |
{ |
| 62 |
if (m_videoOutput) |
| 63 |
updateScaleFactors(m_videoOutput->videoWindowSize()); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
//----------------------------------------------------------------------------- |
| 68 |
// Private functions |
| 69 |
//----------------------------------------------------------------------------- |
| 70 |
|
| 71 |
void MMF::SurfaceVideoPlayer::createPlayer() |
| 72 |
{ |
| 73 |
const TInt priority = 0; |
| 74 |
const TMdaPriorityPreference preference = EMdaPriorityPreferenceNone; |
| 75 |
|
| 76 |
CVideoPlayerUtility2 *player = 0; |
| 77 |
QT_TRAP_THROWING(player = CVideoPlayerUtility2::NewL(*this, |
| 78 |
priority, preference)); |
| 79 |
m_player.reset(player); |
| 80 |
} |
| 81 |
|
| 82 |
void MMF::SurfaceVideoPlayer::initVideoOutput() |
| 83 |
{ |
| 84 |
Q_ASSERT(m_videoOutput); |
| 85 |
|
| 86 |
bool connected = connect( |
| 87 |
m_videoOutput, SIGNAL(videoWindowSizeChanged()), |
| 88 |
this, SLOT(videoWindowSizeChanged()) |
| 89 |
); |
| 90 |
Q_ASSERT(connected); |
| 91 |
|
| 92 |
// Suppress warnings in release builds |
| 93 |
Q_UNUSED(connected); |
| 94 |
|
| 95 |
AbstractVideoPlayer::initVideoOutput(); |
| 96 |
} |
| 97 |
|
| 98 |
void MMF::SurfaceVideoPlayer::prepareCompleted() |
| 99 |
{ |
| 100 |
videoWindowSizeChanged(); |
| 101 |
} |
| 102 |
|
| 103 |
void MMF::SurfaceVideoPlayer::handleVideoWindowChanged() |
| 104 |
{ |
| 105 |
parametersChanged(WindowHandle); |
| 106 |
} |
| 107 |
|
| 108 |
void MMF::SurfaceVideoPlayer::handleParametersChanged(VideoParameters parameters) |
| 109 |
{ |
| 110 |
TRACE_CONTEXT(SurfaceVideoPlayer::handleParametersChanged, EVideoApi); |
| 111 |
TRACE_ENTRY("parameters 0x%x", parameters.operator int()); |
| 112 |
|
| 113 |
TRect rect; |
| 114 |
if (m_videoOutput) { |
| 115 |
m_videoOutput->dump(); |
| 116 |
const QSize size = m_videoOutput->videoWindowSize(); |
| 117 |
rect.SetSize(TSize(size.width(), size.height())); |
| 118 |
} |
| 119 |
|
| 120 |
CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data()); |
| 121 |
if (player) { |
| 122 |
int err = KErrNone; |
| 123 |
if (parameters & WindowHandle) { |
| 124 |
removeDisplayWindow(); |
| 125 |
addDisplayWindow(rect); |
| 126 |
} |
| 127 |
|
| 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)); |
| 134 |
if (KErrNone == err) |
| 135 |
TRAP(err, player->SetWindowClipRectL(*m_displayWindow, rect)); |
| 136 |
if (KErrNone == err) |
| 137 |
TRAP(err, player->SetScaleFactorL(*m_displayWindow, m_scaleWidth, m_scaleHeight)); |
| 138 |
if (KErrNone != err) |
| 139 |
setError(tr("Video display error"), err); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
TRACE_EXIT_0(); |
| 145 |
} |
| 146 |
|
| 147 |
void MMF::SurfaceVideoPlayer::addDisplayWindow(const TRect &rect) |
| 148 |
{ |
| 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); |
| 151 |
|
| 152 |
Q_ASSERT(!m_displayWindow); |
| 153 |
RWindow *window = static_cast<RWindow *>(m_window); |
| 154 |
|
| 155 |
TRACE("window 0x%08x", window); |
| 156 |
|
| 157 |
if (window) { |
| 158 |
window->SetBackgroundColor(TRgb(0, 0, 0, 255)); |
| 159 |
CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data()); |
| 160 |
Q_ASSERT(player); |
| 161 |
TRAPD(err, player->AddDisplayWindowL(m_wsSession, m_screenDevice, *window, rect, rect)); |
| 162 |
if (KErrNone == err) |
| 163 |
m_displayWindow = window; |
| 164 |
else |
| 165 |
setError(tr("Video display error"), err); |
| 166 |
TRACE("err %d", err); |
| 167 |
} |
| 168 |
|
| 169 |
TRACE_EXIT_0(); |
| 170 |
} |
| 171 |
|
| 172 |
void MMF::SurfaceVideoPlayer::removeDisplayWindow() |
| 173 |
{ |
| 174 |
TRACE_CONTEXT(SurfaceVideoPlayer::removeDisplayWindow, EVideoApi); |
| 175 |
TRACE("player 0x%08x window 0x%08x", m_player.data(), m_displayWindow); |
| 176 |
|
| 177 |
CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data()); |
| 178 |
if (player && m_displayWindow) { |
| 179 |
player->RemoveDisplayWindow(*m_displayWindow); |
| 180 |
m_displayWindow = 0; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
QT_END_NAMESPACE |