|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "s60videoplayersession.h" |
|
43 #include "s60videowidget.h" |
|
44 #include "s60mediaplayerservice.h" |
|
45 #include "s60videooverlay.h" |
|
46 |
|
47 #include <QtCore/qdebug.h> |
|
48 #include <QtCore/private/qcore_symbian_p.h> |
|
49 #include <QtGui/qwidget.h> |
|
50 #include <QApplication> |
|
51 |
|
52 #include <coecntrl.h> |
|
53 #include <coemain.h> // For CCoeEnv |
|
54 #include <w32std.h> |
|
55 #include <mmf/common/mmfcontrollerframeworkbase.h> |
|
56 |
|
57 S60VideoPlayerSession::S60VideoPlayerSession(QMediaService *service) |
|
58 : S60MediaPlayerSession(service) |
|
59 , m_player(0) |
|
60 , m_clipRect(0, 0, 0, 0) |
|
61 , m_windowRect(0, 0, 0, 0) |
|
62 , m_output(QVideoOutputControl::NoOutput) |
|
63 , m_windowId(0) |
|
64 , m_wsSession(0) |
|
65 , m_screenDevice(0) |
|
66 , m_window(0) |
|
67 , m_service(*service) |
|
68 { |
|
69 resetNativeHandles(); |
|
70 QT_TRAP_THROWING(m_player = CVideoPlayerUtility::NewL( |
|
71 *this, |
|
72 0, |
|
73 EMdaPriorityPreferenceNone, |
|
74 *m_wsSession, |
|
75 *m_screenDevice, |
|
76 *m_window, |
|
77 m_windowRect, |
|
78 m_clipRect)); |
|
79 } |
|
80 |
|
81 S60VideoPlayerSession::~S60VideoPlayerSession() |
|
82 { |
|
83 m_player->Close(); |
|
84 delete m_player; |
|
85 } |
|
86 |
|
87 void S60VideoPlayerSession::doLoadL(const TDesC &path) |
|
88 { |
|
89 m_player->OpenFileL(path); |
|
90 } |
|
91 |
|
92 void S60VideoPlayerSession::doLoadUrlL(const TDesC &path) |
|
93 { |
|
94 m_player->OpenUrlL(path); |
|
95 } |
|
96 |
|
97 int S60VideoPlayerSession::doGetMediaLoadingProgressL() const |
|
98 { |
|
99 int progress = 0; |
|
100 m_player->GetVideoLoadingProgressL(progress); |
|
101 return progress; |
|
102 } |
|
103 |
|
104 int S60VideoPlayerSession::doGetDurationL() const |
|
105 { |
|
106 return m_player->DurationL().Int64() / 1000; |
|
107 } |
|
108 |
|
109 void S60VideoPlayerSession::setVideoRenderer(QObject *videoOutput) |
|
110 { |
|
111 Q_UNUSED(videoOutput) |
|
112 QVideoOutputControl *videoControl = qobject_cast<QVideoOutputControl *>(m_service.control(QVideoOutputControl_iid)); |
|
113 |
|
114 //Render changes |
|
115 if (m_output != videoControl->output()) { |
|
116 |
|
117 if (m_output == QVideoOutputControl::WidgetOutput) { |
|
118 S60VideoWidgetControl *widgetControl = qobject_cast<S60VideoWidgetControl *>(m_service.control(QVideoWidgetControl_iid)); |
|
119 disconnect(widgetControl, SIGNAL(widgetUpdated()), this, SLOT(resetVideoDisplay())); |
|
120 disconnect(this, SIGNAL(stateChanged(QMediaPlayer::State)), widgetControl, SLOT(videoStateChanged(QMediaPlayer::State))); |
|
121 } |
|
122 |
|
123 if (videoControl->output() == QVideoOutputControl::WidgetOutput) { |
|
124 S60VideoWidgetControl *widgetControl = qobject_cast<S60VideoWidgetControl *>(m_service.control(QVideoWidgetControl_iid)); |
|
125 connect(widgetControl, SIGNAL(widgetUpdated()), this, SLOT(resetVideoDisplay())); |
|
126 connect(this, SIGNAL(stateChanged(QMediaPlayer::State)), widgetControl, SLOT(videoStateChanged(QMediaPlayer::State))); |
|
127 } |
|
128 |
|
129 m_output = videoControl->output(); |
|
130 resetVideoDisplay(); |
|
131 } |
|
132 } |
|
133 |
|
134 bool S60VideoPlayerSession::resetNativeHandles() |
|
135 { |
|
136 QVideoOutputControl* videoControl = qobject_cast<QVideoOutputControl *>(m_service.control(QVideoOutputControl_iid)); |
|
137 WId newId = 0; |
|
138 TRect newClipRect = TRect(0,0,0,0); |
|
139 |
|
140 if (videoControl->output() == QVideoOutputControl::WidgetOutput) { |
|
141 S60VideoWidgetControl* widgetControl = qobject_cast<S60VideoWidgetControl *>(m_service.control(QVideoWidgetControl_iid)); |
|
142 QWidget *videoWidget = widgetControl->videoWidget(); |
|
143 newId = videoWidget->winId(); |
|
144 newClipRect = qt_QRect2TRect(QRect(videoWidget->mapToGlobal(videoWidget->pos()), videoWidget->size())); |
|
145 } else if (videoControl->output() == QVideoOutputControl::WindowOutput) { |
|
146 S60VideoOverlay* windowControl = qobject_cast<S60VideoOverlay *>(m_service.control(QVideoWindowControl_iid)); |
|
147 newId = windowControl->winId(); |
|
148 newClipRect = TRect( newId->DrawableWindow()->AbsPosition(), newId->DrawableWindow()->Size()); |
|
149 } else { |
|
150 if (QApplication::activeWindow()) |
|
151 newId = QApplication::activeWindow()->effectiveWinId(); |
|
152 } |
|
153 |
|
154 if (newClipRect == m_clipRect && newId == m_windowId) |
|
155 return false; |
|
156 |
|
157 if (newId) { |
|
158 m_windowRect = TRect( newId->DrawableWindow()->AbsPosition(), newId->DrawableWindow()->Size()); |
|
159 m_clipRect = newClipRect; |
|
160 m_windowId = newId; |
|
161 CCoeEnv *coeEnv = m_windowId->ControlEnv(); |
|
162 m_wsSession = &(coeEnv->WsSession()); |
|
163 m_screenDevice = coeEnv->ScreenDevice(); |
|
164 m_window = m_windowId->DrawableWindow(); |
|
165 return true; |
|
166 } |
|
167 return false; |
|
168 } |
|
169 |
|
170 bool S60VideoPlayerSession::isVideoAvailable() const |
|
171 { |
|
172 #ifdef PRE_S60_50_PLATFORM |
|
173 return true; // this is not support in pre 5th platforms |
|
174 #else |
|
175 return m_player->VideoEnabledL(); |
|
176 #endif |
|
177 } |
|
178 |
|
179 bool S60VideoPlayerSession::isAudioAvailable() const |
|
180 { |
|
181 if (m_player) |
|
182 return m_player->AudioEnabledL(); |
|
183 else |
|
184 return false; |
|
185 } |
|
186 |
|
187 void S60VideoPlayerSession::doPlay() |
|
188 { |
|
189 m_player->Play(); |
|
190 } |
|
191 |
|
192 void S60VideoPlayerSession::doPauseL() |
|
193 { |
|
194 m_player->PauseL(); |
|
195 } |
|
196 |
|
197 void S60VideoPlayerSession::doStop() |
|
198 { |
|
199 m_player->Stop(); |
|
200 } |
|
201 |
|
202 qint64 S60VideoPlayerSession::doGetPositionL() const |
|
203 { |
|
204 return m_player->PositionL().Int64() / 1000; |
|
205 } |
|
206 void S60VideoPlayerSession::doSetPositionL(qint64 microSeconds) |
|
207 { |
|
208 m_player->SetPositionL(TTimeIntervalMicroSeconds(microSeconds)); |
|
209 } |
|
210 |
|
211 void S60VideoPlayerSession::doSetVolumeL(int volume) |
|
212 { |
|
213 m_player->SetVolumeL((volume / 100.0)* m_player->MaxVolume()); |
|
214 } |
|
215 |
|
216 void S60VideoPlayerSession::MvpuoOpenComplete(TInt aError) |
|
217 { |
|
218 setError(aError); |
|
219 m_player->Prepare(); |
|
220 } |
|
221 |
|
222 void S60VideoPlayerSession::MvpuoPrepareComplete(TInt aError) |
|
223 { |
|
224 setError(aError); |
|
225 TRAPD(err, |
|
226 m_player->SetDisplayWindowL(*m_wsSession, |
|
227 *m_screenDevice, |
|
228 *m_window, |
|
229 m_windowRect, |
|
230 m_clipRect)); |
|
231 setError(err); |
|
232 initComplete(); |
|
233 } |
|
234 |
|
235 void S60VideoPlayerSession::MvpuoFrameReady(CFbsBitmap &aFrame, TInt aError) |
|
236 { |
|
237 Q_UNUSED(aFrame); |
|
238 Q_UNUSED(aError); |
|
239 } |
|
240 |
|
241 void S60VideoPlayerSession::MvpuoPlayComplete(TInt aError) |
|
242 { |
|
243 setError(aError); |
|
244 playComplete(); |
|
245 } |
|
246 |
|
247 void S60VideoPlayerSession::MvpuoEvent(const TMMFEvent &aEvent) |
|
248 { |
|
249 Q_UNUSED(aEvent); |
|
250 } |
|
251 |
|
252 void S60VideoPlayerSession::updateMetaDataEntriesL() |
|
253 { |
|
254 metaDataEntries().clear(); |
|
255 int numberOfMetaDataEntries = 0; |
|
256 |
|
257 numberOfMetaDataEntries = m_player->NumberOfMetaDataEntriesL(); |
|
258 |
|
259 for (int i = 0; i < numberOfMetaDataEntries; i++) { |
|
260 CMMFMetaDataEntry *entry = NULL; |
|
261 entry = m_player->MetaDataEntryL(i); |
|
262 metaDataEntries().insert(QString::fromUtf16(entry->Name().Ptr(), entry->Name().Length()), QString::fromUtf16(entry->Value().Ptr(), entry->Value().Length())); |
|
263 delete entry; |
|
264 } |
|
265 emit metaDataChanged(); |
|
266 } |
|
267 |
|
268 void S60VideoPlayerSession::resetVideoDisplay() |
|
269 { |
|
270 if (resetNativeHandles()) { |
|
271 TRAPD(err, m_player->SetDisplayWindowL(*m_wsSession, |
|
272 *m_screenDevice, |
|
273 *m_window, |
|
274 m_windowRect, |
|
275 m_clipRect)); |
|
276 setError(err); |
|
277 } |
|
278 } |