|
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/private/qcore_symbian_p.h> // For qt_TRect2QRect |
|
48 #include <QtCore/qdebug.h> |
|
49 #include <QtGui/qwidget.h> |
|
50 #include <QtCore/qtimer.h> |
|
51 #include <QApplication> |
|
52 |
|
53 #include <coecntrl.h> |
|
54 #include <coemain.h> // For CCoeEnv |
|
55 #include <w32std.h> |
|
56 #include <mmf/common/mmfcontrollerframeworkbase.h> |
|
57 |
|
58 |
|
59 S60VideoPlayerSession::S60VideoPlayerSession(QMediaService *service) |
|
60 : S60MediaPlayerSession(service) |
|
61 , m_player(0) |
|
62 , m_rect(0, 0, 0, 0) |
|
63 , m_output(QVideoOutputControl::NoOutput) |
|
64 , m_windowId(0) |
|
65 , m_dsaActive(false) |
|
66 , m_dsaStopped(false) |
|
67 , m_wsSession(CCoeEnv::Static()->WsSession()) |
|
68 , m_screenDevice(*CCoeEnv::Static()->ScreenDevice()) |
|
69 , m_window(0) |
|
70 , m_service(*service) |
|
71 , m_aspectRatioMode(Qt::KeepAspectRatio) |
|
72 , m_originalSize(1, 1) |
|
73 , m_audioOutput(0) |
|
74 { |
|
75 resetNativeHandles(); |
|
76 QT_TRAP_THROWING(m_player = CVideoPlayerUtility::NewL( |
|
77 *this, |
|
78 0, |
|
79 EMdaPriorityPreferenceNone, |
|
80 m_wsSession, |
|
81 m_screenDevice, |
|
82 *m_window, |
|
83 m_rect, |
|
84 m_rect)); |
|
85 m_dsaActive = true; |
|
86 m_player->RegisterForVideoLoadingNotification(*this); |
|
87 #if !defined(HAS_NO_AUDIOROUTING) |
|
88 //QT_TRAP_THROWING(m_audioOutput = CAudioOutput::NewL(*m_player)); |
|
89 //QT_TRAP_THROWING(m_audioOutput->RegisterObserverL(*this)); |
|
90 #endif |
|
91 } |
|
92 |
|
93 S60VideoPlayerSession::~S60VideoPlayerSession() |
|
94 { |
|
95 #if !defined(HAS_NO_AUDIOROUTING) |
|
96 if (m_audioOutput) |
|
97 m_audioOutput->UnregisterObserver(*this); |
|
98 delete m_audioOutput; |
|
99 #endif |
|
100 m_player->Close(); |
|
101 delete m_player; |
|
102 } |
|
103 |
|
104 void S60VideoPlayerSession::doLoadL(const TDesC &path) |
|
105 { |
|
106 m_player->OpenFileL(path); |
|
107 } |
|
108 |
|
109 void S60VideoPlayerSession::doLoadUrlL(const TDesC &path) |
|
110 { |
|
111 m_player->OpenUrlL(path); |
|
112 } |
|
113 |
|
114 int S60VideoPlayerSession::doGetBufferStatusL() const |
|
115 { |
|
116 int progress = 0; |
|
117 m_player->GetVideoLoadingProgressL(progress); |
|
118 return progress; |
|
119 } |
|
120 |
|
121 qint64 S60VideoPlayerSession::doGetDurationL() const |
|
122 { |
|
123 return m_player->DurationL().Int64() / qint64(1000); |
|
124 } |
|
125 |
|
126 void S60VideoPlayerSession::setVideoRenderer(QObject *videoOutput) |
|
127 { |
|
128 Q_UNUSED(videoOutput) |
|
129 QVideoOutputControl *videoControl = qobject_cast<QVideoOutputControl *>(m_service.control(QVideoOutputControl_iid)); |
|
130 |
|
131 //Render changes |
|
132 if (m_output != videoControl->output()) { |
|
133 |
|
134 if (m_output == QVideoOutputControl::WidgetOutput) { |
|
135 S60VideoWidgetControl *widgetControl = qobject_cast<S60VideoWidgetControl *>(m_service.control(QVideoWidgetControl_iid)); |
|
136 disconnect(widgetControl, SIGNAL(widgetUpdated()), this, SLOT(resetVideoDisplay())); |
|
137 disconnect(widgetControl, SIGNAL(beginVideoWindowNativePaint()), this, SLOT(suspendDirectScreenAccess())); |
|
138 disconnect(widgetControl, SIGNAL(endVideoWindowNativePaint()), this, SLOT(resumeDirectScreenAccess())); |
|
139 disconnect(this, SIGNAL(stateChanged(QMediaPlayer::State)), widgetControl, SLOT(videoStateChanged(QMediaPlayer::State))); |
|
140 } |
|
141 |
|
142 if (videoControl->output() == QVideoOutputControl::WidgetOutput) { |
|
143 S60VideoWidgetControl *widgetControl = qobject_cast<S60VideoWidgetControl *>(m_service.control(QVideoWidgetControl_iid)); |
|
144 connect(widgetControl, SIGNAL(widgetUpdated()), this, SLOT(resetVideoDisplay())); |
|
145 connect(widgetControl, SIGNAL(beginVideoWindowNativePaint()), this, SLOT(suspendDirectScreenAccess())); |
|
146 connect(widgetControl, SIGNAL(endVideoWindowNativePaint()), this, SLOT(resumeDirectScreenAccess())); |
|
147 connect(this, SIGNAL(stateChanged(QMediaPlayer::State)), widgetControl, SLOT(videoStateChanged(QMediaPlayer::State))); |
|
148 } |
|
149 |
|
150 m_output = videoControl->output(); |
|
151 resetVideoDisplay(); |
|
152 } |
|
153 } |
|
154 |
|
155 bool S60VideoPlayerSession::resetNativeHandles() |
|
156 { |
|
157 QVideoOutputControl* videoControl = qobject_cast<QVideoOutputControl *>(m_service.control(QVideoOutputControl_iid)); |
|
158 WId newId = 0; |
|
159 TRect newRect = TRect(0,0,0,0); |
|
160 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio; |
|
161 |
|
162 if (videoControl->output() == QVideoOutputControl::WidgetOutput) { |
|
163 S60VideoWidgetControl* widgetControl = qobject_cast<S60VideoWidgetControl *>(m_service.control(QVideoWidgetControl_iid)); |
|
164 QWidget *videoWidget = widgetControl->videoWidget(); |
|
165 newId = widgetControl->videoWidgetWId(); |
|
166 newRect = QRect2TRect(QRect(videoWidget->mapToGlobal(videoWidget->pos()), videoWidget->size())); |
|
167 aspectRatioMode = widgetControl->aspectRatioMode(); |
|
168 } else if (videoControl->output() == QVideoOutputControl::WindowOutput) { |
|
169 S60VideoOverlay* windowControl = qobject_cast<S60VideoOverlay *>(m_service.control(QVideoWindowControl_iid)); |
|
170 newId = windowControl->winId(); |
|
171 newRect = TRect( newId->DrawableWindow()->AbsPosition(), newId->DrawableWindow()->Size()); |
|
172 } else { |
|
173 if (QApplication::activeWindow()) |
|
174 newId = QApplication::activeWindow()->effectiveWinId(); |
|
175 |
|
176 if (!newId && QApplication::allWidgets().count()) |
|
177 newId = QApplication::allWidgets().at(0)->effectiveWinId(); |
|
178 |
|
179 Q_ASSERT(newId != 0); |
|
180 } |
|
181 |
|
182 if (newRect == m_rect && newId == m_windowId && aspectRatioMode == m_aspectRatioMode) |
|
183 return false; |
|
184 |
|
185 if (newId) { |
|
186 m_rect = newRect; |
|
187 m_windowId = newId; |
|
188 m_window = m_windowId->DrawableWindow(); |
|
189 m_aspectRatioMode = aspectRatioMode; |
|
190 return true; |
|
191 } |
|
192 return false; |
|
193 } |
|
194 |
|
195 bool S60VideoPlayerSession::isVideoAvailable() const |
|
196 { |
|
197 #ifdef PRE_S60_50_PLATFORM |
|
198 return true; // this is not support in pre 5th platforms |
|
199 #else |
|
200 if (m_player) |
|
201 return m_player->VideoEnabledL(); |
|
202 else |
|
203 return false; |
|
204 #endif |
|
205 } |
|
206 |
|
207 bool S60VideoPlayerSession::isAudioAvailable() const |
|
208 { |
|
209 if (m_player) |
|
210 return m_player->AudioEnabledL(); |
|
211 else |
|
212 return false; |
|
213 } |
|
214 |
|
215 void S60VideoPlayerSession::doPlay() |
|
216 { |
|
217 m_player->Play(); |
|
218 } |
|
219 |
|
220 void S60VideoPlayerSession::doPauseL() |
|
221 { |
|
222 m_player->PauseL(); |
|
223 } |
|
224 |
|
225 void S60VideoPlayerSession::doStop() |
|
226 { |
|
227 m_player->Stop(); |
|
228 } |
|
229 |
|
230 qint64 S60VideoPlayerSession::doGetPositionL() const |
|
231 { |
|
232 return m_player->PositionL().Int64() / qint64(1000); |
|
233 } |
|
234 |
|
235 void S60VideoPlayerSession::doSetPositionL(qint64 microSeconds) |
|
236 { |
|
237 m_player->SetPositionL(TTimeIntervalMicroSeconds(microSeconds)); |
|
238 } |
|
239 |
|
240 void S60VideoPlayerSession::doSetVolumeL(int volume) |
|
241 { |
|
242 m_player->SetVolumeL((volume / 100.0)* m_player->MaxVolume()); |
|
243 } |
|
244 |
|
245 QPair<qreal, qreal> S60VideoPlayerSession::scaleFactor() |
|
246 { |
|
247 QSize scaled = m_originalSize; |
|
248 if (m_aspectRatioMode == Qt::IgnoreAspectRatio) |
|
249 scaled.scale(qt_TRect2QRect(m_rect).size(), Qt::IgnoreAspectRatio); |
|
250 else if(m_aspectRatioMode == Qt::KeepAspectRatio) |
|
251 scaled.scale(qt_TRect2QRect(m_rect).size(), Qt::KeepAspectRatio); |
|
252 |
|
253 qreal width = qreal(scaled.width()) / qreal(m_originalSize.width()) * qreal(100); |
|
254 qreal height = qreal(scaled.height()) / qreal(m_originalSize.height()) * qreal(100); |
|
255 |
|
256 return QPair<qreal, qreal>(width, height); |
|
257 } |
|
258 |
|
259 void S60VideoPlayerSession::startDirectScreenAccess() |
|
260 { |
|
261 if(m_dsaActive) |
|
262 return; |
|
263 |
|
264 TRAPD(err, m_player->StartDirectScreenAccessL()); |
|
265 if(err == KErrNone) |
|
266 m_dsaActive = true; |
|
267 setError(err); |
|
268 } |
|
269 |
|
270 bool S60VideoPlayerSession::stopDirectScreenAccess() |
|
271 { |
|
272 if(!m_dsaActive) |
|
273 return false; |
|
274 |
|
275 TRAPD(err, m_player->StopDirectScreenAccessL()); |
|
276 if(err == KErrNone) |
|
277 m_dsaActive = false; |
|
278 |
|
279 setError(err); |
|
280 return true; |
|
281 } |
|
282 |
|
283 void S60VideoPlayerSession::MvpuoOpenComplete(TInt aError) |
|
284 { |
|
285 setError(aError); |
|
286 m_player->Prepare(); |
|
287 } |
|
288 |
|
289 void S60VideoPlayerSession::MvpuoPrepareComplete(TInt aError) |
|
290 { |
|
291 setError(aError); |
|
292 TRAPD(err, |
|
293 m_player->SetDisplayWindowL(m_wsSession, |
|
294 m_screenDevice, |
|
295 *m_window, |
|
296 m_rect, |
|
297 m_rect); |
|
298 TSize originalSize; |
|
299 m_player->VideoFrameSizeL(originalSize); |
|
300 m_originalSize = QSize(originalSize.iWidth, originalSize.iHeight); |
|
301 m_player->SetScaleFactorL(scaleFactor().first, scaleFactor().second, true)); |
|
302 |
|
303 setError(err); |
|
304 m_dsaActive = true; |
|
305 loaded(); |
|
306 } |
|
307 |
|
308 void S60VideoPlayerSession::MvpuoFrameReady(CFbsBitmap &aFrame, TInt aError) |
|
309 { |
|
310 Q_UNUSED(aFrame); |
|
311 Q_UNUSED(aError); |
|
312 } |
|
313 |
|
314 void S60VideoPlayerSession::MvpuoPlayComplete(TInt aError) |
|
315 { |
|
316 setError(aError); |
|
317 endOfMedia(); |
|
318 } |
|
319 |
|
320 void S60VideoPlayerSession::MvpuoEvent(const TMMFEvent &aEvent) |
|
321 { |
|
322 Q_UNUSED(aEvent); |
|
323 } |
|
324 |
|
325 void S60VideoPlayerSession::updateMetaDataEntriesL() |
|
326 { |
|
327 metaDataEntries().clear(); |
|
328 int numberOfMetaDataEntries = 0; |
|
329 |
|
330 numberOfMetaDataEntries = m_player->NumberOfMetaDataEntriesL(); |
|
331 |
|
332 for (int i = 0; i < numberOfMetaDataEntries; i++) { |
|
333 CMMFMetaDataEntry *entry = NULL; |
|
334 entry = m_player->MetaDataEntryL(i); |
|
335 metaDataEntries().insert(TDesC2QString(entry->Name()), TDesC2QString(entry->Value())); |
|
336 delete entry; |
|
337 } |
|
338 emit metaDataChanged(); |
|
339 } |
|
340 |
|
341 void S60VideoPlayerSession::resetVideoDisplay() |
|
342 { |
|
343 if (resetNativeHandles()) { |
|
344 TRAPD(err, |
|
345 m_player->SetDisplayWindowL(m_wsSession, |
|
346 m_screenDevice, |
|
347 *m_window, |
|
348 m_rect, |
|
349 m_rect)); |
|
350 setError(err); |
|
351 if( mediaStatus() == QMediaPlayer::LoadedMedia |
|
352 || mediaStatus() == QMediaPlayer::StalledMedia |
|
353 || mediaStatus() == QMediaPlayer::BufferingMedia |
|
354 || mediaStatus() == QMediaPlayer::BufferedMedia |
|
355 || mediaStatus() == QMediaPlayer::EndOfMedia) { |
|
356 TRAPD(err, m_player->SetScaleFactorL(scaleFactor().first, scaleFactor().second, true)); |
|
357 setError(err); |
|
358 } |
|
359 } |
|
360 } |
|
361 |
|
362 void S60VideoPlayerSession::suspendDirectScreenAccess() |
|
363 { |
|
364 m_dsaStopped = stopDirectScreenAccess(); |
|
365 } |
|
366 |
|
367 void S60VideoPlayerSession::resumeDirectScreenAccess() |
|
368 { |
|
369 if(!m_dsaStopped) |
|
370 return; |
|
371 |
|
372 startDirectScreenAccess(); |
|
373 m_dsaStopped = false; |
|
374 } |
|
375 |
|
376 void S60VideoPlayerSession::MvloLoadingStarted() |
|
377 { |
|
378 buffering(); |
|
379 } |
|
380 |
|
381 void S60VideoPlayerSession::MvloLoadingComplete() |
|
382 { |
|
383 buffered(); |
|
384 } |
|
385 |
|
386 QString S60VideoPlayerSession::activeEndpoint() const |
|
387 { |
|
388 QString outputName; |
|
389 #if !defined(HAS_NO_AUDIOROUTING) |
|
390 if (m_audioOutput) { |
|
391 CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput(); |
|
392 outputName = qStringFromTAudioOutputPreference(output); |
|
393 } |
|
394 #endif |
|
395 return outputName; |
|
396 } |
|
397 |
|
398 QString S60VideoPlayerSession::defaultEndpoint() const |
|
399 { |
|
400 QString outputName; |
|
401 #if !defined(HAS_NO_AUDIOROUTING) |
|
402 if (m_audioOutput) { |
|
403 CAudioOutput::TAudioOutputPreference output = m_audioOutput->DefaultAudioOutput(); |
|
404 outputName = qStringFromTAudioOutputPreference(output); |
|
405 } |
|
406 return outputName; |
|
407 #endif |
|
408 return QString("Default"); |
|
409 } |
|
410 |
|
411 void S60VideoPlayerSession::setActiveEndpoint(const QString& name) |
|
412 { |
|
413 CAudioOutput::TAudioOutputPreference output = CAudioOutput::ENoPreference; |
|
414 |
|
415 if (name == QString("Default")) |
|
416 output = CAudioOutput::ENoPreference; |
|
417 else if (name == QString("All")) |
|
418 output = CAudioOutput::EAll; |
|
419 else if (name == QString("None")) |
|
420 output = CAudioOutput::ENoOutput; |
|
421 else if (name == QString("Earphone")) |
|
422 output = CAudioOutput::EPrivate; |
|
423 else if (name == QString("Speaker")) |
|
424 output = CAudioOutput::EPublic; |
|
425 #if !defined(HAS_NO_AUDIOROUTING) |
|
426 if (m_audioOutput) { |
|
427 TRAPD(err, m_audioOutput->SetAudioOutputL(output)); |
|
428 setError(err); |
|
429 } |
|
430 #endif |
|
431 } |
|
432 |
|
433 void S60VideoPlayerSession::DefaultAudioOutputChanged( CAudioOutput& aAudioOutput, |
|
434 CAudioOutput::TAudioOutputPreference aNewDefault ) |
|
435 { |
|
436 #if !defined(HAS_NO_AUDIOROUTING) |
|
437 if (m_audioOutput) { |
|
438 CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput(); |
|
439 if (output == CAudioOutput::ENoPreference) { |
|
440 QString name; |
|
441 if (output == CAudioOutput::EAll) |
|
442 name = QString("All"); |
|
443 else if (output == CAudioOutput::ENoOutput) |
|
444 name = QString("None"); |
|
445 else if (output == CAudioOutput::EPrivate) |
|
446 name = QString("Earphone"); |
|
447 else if (output == CAudioOutput::EPublic) |
|
448 name = QString("Speaker"); |
|
449 if (!name.isEmpty()) |
|
450 emit activeEndpointChanged(name); |
|
451 } |
|
452 } |
|
453 #endif |
|
454 } |
|
455 |
|
456 QString S60VideoPlayerSession::qStringFromTAudioOutputPreference(CAudioOutput::TAudioOutputPreference output) const |
|
457 { |
|
458 if (output == CAudioOutput::ENoPreference) |
|
459 return QString("Default"); |
|
460 else if (output == CAudioOutput::EAll) |
|
461 return QString("All"); |
|
462 else if (output == CAudioOutput::ENoOutput) |
|
463 return QString("None"); |
|
464 else if (output == CAudioOutput::EPrivate) |
|
465 return QString("Earphone"); |
|
466 else if (output == CAudioOutput::EPublic) |
|
467 return QString("Speaker"); |
|
468 return QString(); |
|
469 } |