|
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 <QtCore/qvariant.h> |
|
43 #include <QtCore/qdebug.h> |
|
44 #include <QtGui/qwidget.h> |
|
45 |
|
46 #include "s60mediaplayerservice.h" |
|
47 #include "s60mediaplayercontrol.h" |
|
48 #include "s60videoplayersession.h" |
|
49 #include "s60audioplayersession.h" |
|
50 #include "s60mediametadataprovider.h" |
|
51 #include "s60videowidget.h" |
|
52 #include "s60mediarecognizer.h" |
|
53 //#include <qmediatimerange.h> |
|
54 #include "s60videooverlay.h" |
|
55 #include "s60videorenderer.h" |
|
56 #include "s60mediaplayeraudioendpointselector.h" |
|
57 |
|
58 #include <QMediaPlaylistNavigator> |
|
59 #include <QMediaPlaylist> |
|
60 |
|
61 S60MediaPlayerService::S60MediaPlayerService(QObject *parent) |
|
62 : QMediaService(parent) |
|
63 , m_control(NULL) |
|
64 , m_mediaRecognizer(NULL) |
|
65 , m_videoOutput(NULL) |
|
66 , m_videoPlayerSession(NULL) |
|
67 , m_audioPlayerSession(NULL) |
|
68 , m_metaData(NULL) |
|
69 , m_videoWidget(NULL) |
|
70 , m_videoWindow(NULL) |
|
71 , m_videoRenderer(NULL) |
|
72 , m_audioEndpointSelector(NULL) |
|
73 { |
|
74 m_control = new S60MediaPlayerControl(*this, this); |
|
75 m_mediaRecognizer = new S60MediaRecognizer(this); |
|
76 m_metaData = new S60MediaMetaDataProvider(*this); |
|
77 } |
|
78 |
|
79 S60MediaPlayerService::~S60MediaPlayerService() |
|
80 { |
|
81 delete m_videoWidget; |
|
82 delete m_videoRenderer; |
|
83 delete m_videoWindow; |
|
84 delete m_videoOutput; |
|
85 delete m_metaData; |
|
86 } |
|
87 |
|
88 QMediaControl *S60MediaPlayerService::control(const char *name) const |
|
89 { |
|
90 if (qstrcmp(name, QMediaPlayerControl_iid) == 0) |
|
91 return m_control; |
|
92 |
|
93 if (qstrcmp(name, QMetaDataControl_iid) == 0) { |
|
94 return m_metaData; |
|
95 } |
|
96 |
|
97 if (qstrcmp(name, QVideoOutputControl_iid) == 0) { |
|
98 if (!m_videoOutput) { |
|
99 m_videoOutput = new S60VideoOutputControl; |
|
100 connect(m_videoOutput, SIGNAL(outputChanged(QVideoOutputControl::Output)), |
|
101 this, SLOT(videoOutputChanged(QVideoOutputControl::Output))); |
|
102 m_videoOutput->setAvailableOutputs(QList<QVideoOutputControl::Output>() |
|
103 // << QVideoOutputControl::RendererOutput |
|
104 // << QVideoOutputControl::WindowOutput |
|
105 << QVideoOutputControl::WidgetOutput); |
|
106 |
|
107 } |
|
108 return m_videoOutput; |
|
109 } |
|
110 |
|
111 if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { |
|
112 if (!m_videoWidget) |
|
113 m_videoWidget = new S60VideoWidgetControl; |
|
114 return m_videoWidget; |
|
115 } |
|
116 |
|
117 if (qstrcmp(name, QVideoRendererControl_iid) == 0) { |
|
118 if (m_videoRenderer) |
|
119 m_videoRenderer = new S60VideoRenderer; |
|
120 return m_videoRenderer; |
|
121 } |
|
122 |
|
123 if (qstrcmp(name, QVideoWindowControl_iid) == 0) { |
|
124 if (!m_videoWindow) |
|
125 m_videoWindow = new S60VideoOverlay; |
|
126 return m_videoWindow; |
|
127 } |
|
128 |
|
129 if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) { |
|
130 if (!m_audioEndpointSelector) |
|
131 m_audioEndpointSelector = new S60MediaPlayerAudioEndpointSelector(m_control); |
|
132 return m_audioEndpointSelector; |
|
133 } |
|
134 |
|
135 return 0; |
|
136 |
|
137 } |
|
138 |
|
139 void S60MediaPlayerService::videoOutputChanged(QVideoOutputControl::Output output) |
|
140 { |
|
141 switch (output) { |
|
142 case QVideoOutputControl::NoOutput: |
|
143 m_control->setVideoOutput(0); |
|
144 break; |
|
145 |
|
146 case QVideoOutputControl::RendererOutput: |
|
147 m_control->setVideoOutput(m_videoRenderer); |
|
148 break; |
|
149 case QVideoOutputControl::WindowOutput: |
|
150 m_control->setVideoOutput(m_videoWindow); |
|
151 break; |
|
152 |
|
153 case QVideoOutputControl::WidgetOutput: |
|
154 m_control->setVideoOutput(m_videoWidget); |
|
155 break; |
|
156 default: |
|
157 qWarning("Invalid video output selection"); |
|
158 break; |
|
159 } |
|
160 } |
|
161 |
|
162 S60MediaPlayerSession* S60MediaPlayerService::PlayerSession() |
|
163 { |
|
164 QUrl url = m_control->media().canonicalUrl(); |
|
165 |
|
166 if (url.isEmpty() == true) { |
|
167 return NULL; |
|
168 } |
|
169 |
|
170 S60MediaRecognizer::MediaType mediaType = m_mediaRecognizer->IdentifyMediaType(url); |
|
171 |
|
172 switch (mediaType) { |
|
173 case S60MediaRecognizer::Video: |
|
174 case S60MediaRecognizer::Url: |
|
175 return VideoPlayerSession(); |
|
176 case S60MediaRecognizer::Audio: |
|
177 return AudioPlayerSession(); |
|
178 default: |
|
179 break; |
|
180 } |
|
181 |
|
182 return NULL; |
|
183 } |
|
184 |
|
185 S60MediaPlayerSession* S60MediaPlayerService::VideoPlayerSession() |
|
186 { |
|
187 if (!m_videoPlayerSession) { |
|
188 m_videoPlayerSession = new S60VideoPlayerSession(this); |
|
189 |
|
190 connect(m_videoPlayerSession, SIGNAL(positionChanged(qint64)), |
|
191 m_control, SIGNAL(positionChanged(qint64))); |
|
192 connect(m_videoPlayerSession, SIGNAL(durationChanged(qint64)), |
|
193 m_control, SIGNAL(durationChanged(qint64))); |
|
194 connect(m_videoPlayerSession, SIGNAL(stateChanged(QMediaPlayer::State)), |
|
195 m_control, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
196 connect(m_videoPlayerSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), |
|
197 m_control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
198 connect(m_videoPlayerSession,SIGNAL(bufferStatusChanged(int)), |
|
199 m_control, SIGNAL(bufferStatusChanged(int))); |
|
200 connect(m_videoPlayerSession, SIGNAL(videoAvailableChanged(bool)), |
|
201 m_control, SIGNAL(videoAvailableChanged(bool))); |
|
202 connect(m_videoPlayerSession, SIGNAL(audioAvailableChanged(bool)), |
|
203 m_control, SIGNAL(audioAvailableChanged(bool))); |
|
204 connect(m_videoPlayerSession, SIGNAL(seekableChanged(bool)), |
|
205 m_control, SIGNAL(seekableChanged(bool))); |
|
206 connect(m_videoPlayerSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)), |
|
207 m_control, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&))); |
|
208 connect(m_videoPlayerSession, SIGNAL(error(int, const QString &)), |
|
209 m_control, SIGNAL(error(int, const QString &))); |
|
210 connect(m_videoPlayerSession, SIGNAL(metaDataChanged()), |
|
211 m_metaData, SIGNAL(metaDataChanged())); |
|
212 } |
|
213 |
|
214 m_videoPlayerSession->setVolume(m_control->mediaControlSettings().volume()); |
|
215 m_videoPlayerSession->setMuted(m_control->mediaControlSettings().isMuted()); |
|
216 return m_videoPlayerSession; |
|
217 } |
|
218 |
|
219 S60MediaPlayerSession* S60MediaPlayerService::AudioPlayerSession() |
|
220 { |
|
221 if (!m_audioPlayerSession) { |
|
222 m_audioPlayerSession = new S60AudioPlayerSession(this); |
|
223 |
|
224 connect(m_audioPlayerSession, SIGNAL(positionChanged(qint64)), |
|
225 m_control, SIGNAL(positionChanged(qint64))); |
|
226 connect(m_audioPlayerSession, SIGNAL(durationChanged(qint64)), |
|
227 m_control, SIGNAL(durationChanged(qint64))); |
|
228 connect(m_audioPlayerSession, SIGNAL(stateChanged(QMediaPlayer::State)), |
|
229 m_control, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
230 connect(m_audioPlayerSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), |
|
231 m_control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
232 connect(m_audioPlayerSession,SIGNAL(bufferStatusChanged(int)), |
|
233 m_control, SIGNAL(bufferStatusChanged(int))); |
|
234 connect(m_audioPlayerSession, SIGNAL(videoAvailableChanged(bool)), |
|
235 m_control, SIGNAL(videoAvailableChanged(bool))); |
|
236 connect(m_audioPlayerSession, SIGNAL(audioAvailableChanged(bool)), |
|
237 m_control, SIGNAL(audioAvailableChanged(bool))); |
|
238 connect(m_audioPlayerSession, SIGNAL(seekableChanged(bool)), |
|
239 m_control, SIGNAL(seekableChanged(bool))); |
|
240 connect(m_audioPlayerSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)), |
|
241 m_control, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&))); |
|
242 connect(m_audioPlayerSession, SIGNAL(error(int, const QString &)), |
|
243 m_control, SIGNAL(error(int, const QString &))); |
|
244 connect(m_audioPlayerSession, SIGNAL(metaDataChanged()), |
|
245 m_metaData, SIGNAL(metaDataChanged())); |
|
246 } |
|
247 |
|
248 m_audioPlayerSession->setVolume(m_control->mediaControlSettings().volume()); |
|
249 m_audioPlayerSession->setMuted(m_control->mediaControlSettings().isMuted()); |
|
250 return m_audioPlayerSession; |
|
251 } |