|
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 updateScaleFactors(m_videoOutput->videoWindowSize()); |
|
63 } |
|
64 |
|
65 |
|
66 //----------------------------------------------------------------------------- |
|
67 // Private functions |
|
68 //----------------------------------------------------------------------------- |
|
69 |
|
70 void MMF::SurfaceVideoPlayer::createPlayer() |
|
71 { |
|
72 const TInt priority = 0; |
|
73 const TMdaPriorityPreference preference = EMdaPriorityPreferenceNone; |
|
74 |
|
75 CVideoPlayerUtility2 *player = 0; |
|
76 QT_TRAP_THROWING(player = CVideoPlayerUtility2::NewL(*this, |
|
77 priority, preference)); |
|
78 m_player.reset(player); |
|
79 } |
|
80 |
|
81 void MMF::SurfaceVideoPlayer::initVideoOutput() |
|
82 { |
|
83 bool connected = connect( |
|
84 m_videoOutput, SIGNAL(videoWindowSizeChanged()), |
|
85 this, SLOT(videoWindowSizeChanged()) |
|
86 ); |
|
87 Q_ASSERT(connected); |
|
88 |
|
89 // Suppress warnings in release builds |
|
90 Q_UNUSED(connected); |
|
91 |
|
92 AbstractVideoPlayer::initVideoOutput(); |
|
93 } |
|
94 |
|
95 void MMF::SurfaceVideoPlayer::prepareCompleted() |
|
96 { |
|
97 videoWindowSizeChanged(); |
|
98 } |
|
99 |
|
100 void MMF::SurfaceVideoPlayer::handleVideoWindowChanged() |
|
101 { |
|
102 parametersChanged(WindowHandle); |
|
103 } |
|
104 |
|
105 void MMF::SurfaceVideoPlayer::handleParametersChanged(VideoParameters parameters) |
|
106 { |
|
107 CVideoPlayerUtility2 *player = static_cast<CVideoPlayerUtility2 *>(m_player.data()); |
|
108 |
|
109 int err = KErrNone; |
|
110 |
|
111 TRect rect; |
|
112 |
|
113 if (m_videoOutput) { |
|
114 m_videoOutput->dump(); |
|
115 const QSize size = m_videoOutput->videoWindowSize(); |
|
116 rect.SetSize(TSize(size.width(), size.height())); |
|
117 } |
|
118 |
|
119 if (parameters & WindowHandle) { |
|
120 if (m_displayWindow) |
|
121 player->RemoveDisplayWindow(*m_displayWindow); |
|
122 |
|
123 RWindow *window = static_cast<RWindow *>(m_window); |
|
124 if (window) { |
|
125 window->SetBackgroundColor(TRgb(0, 0, 0, 255)); |
|
126 TRAP(err, player->AddDisplayWindowL(m_wsSession, m_screenDevice, *window, rect, rect)); |
|
127 if (KErrNone != err) { |
|
128 setError(tr("Video display error"), err); |
|
129 window = 0; |
|
130 } |
|
131 } |
|
132 m_displayWindow = window; |
|
133 } |
|
134 |
|
135 if (KErrNone == err) { |
|
136 if (parameters & ScaleFactors) { |
|
137 Q_ASSERT(m_displayWindow); |
|
138 TRAP(err, player->SetVideoExtentL(*m_displayWindow, rect)); |
|
139 if (KErrNone == err) |
|
140 TRAP(err, player->SetWindowClipRectL(*m_displayWindow, rect)); |
|
141 if (KErrNone == err) |
|
142 TRAP(err, player->SetScaleFactorL(*m_displayWindow, m_scaleWidth, m_scaleHeight)); |
|
143 if (KErrNone != err) |
|
144 setError(tr("Video display error"), err); |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 QT_END_NAMESPACE |
|
150 |