|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 "s60videooverlay.h" |
|
54 #include "s60videorenderer.h" |
|
55 #include "s60mediaplayeraudioendpointselector.h" |
|
56 |
|
57 #include <qmediaplaylistnavigator.h> |
|
58 #include <qmediaplaylist.h> |
|
59 |
|
60 S60MediaPlayerService::S60MediaPlayerService(QObject *parent) |
|
61 : QMediaService(parent) |
|
62 , m_control(NULL) |
|
63 , m_videoPlayerSession(NULL) |
|
64 , m_audioPlayerSession(NULL) |
|
65 , m_metaData(NULL) |
|
66 , m_audioEndpointSelector(NULL) |
|
67 , m_videoWidget(NULL) |
|
68 , m_videoWindow(NULL) |
|
69 , m_videoRenderer(NULL) |
|
70 , m_videoOutput(NULL) |
|
71 { |
|
72 m_control = new S60MediaPlayerControl(*this, this); |
|
73 m_metaData = new S60MediaMetaDataProvider(*this); |
|
74 m_audioEndpointSelector = new S60MediaPlayerAudioEndpointSelector(m_control, this); |
|
75 } |
|
76 |
|
77 S60MediaPlayerService::~S60MediaPlayerService() |
|
78 { |
|
79 delete m_videoWidget; |
|
80 delete m_videoRenderer; |
|
81 delete m_videoWindow; |
|
82 } |
|
83 |
|
84 QMediaControl *S60MediaPlayerService::requestControl(const char *name) |
|
85 { |
|
86 if (qstrcmp(name, QMediaPlayerControl_iid) == 0) |
|
87 return m_control; |
|
88 |
|
89 if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) |
|
90 return m_metaData; |
|
91 |
|
92 if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) |
|
93 return m_audioEndpointSelector; |
|
94 |
|
95 if (!m_videoOutput) { |
|
96 if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { |
|
97 m_videoWidget = new S60VideoWidgetControl; |
|
98 m_videoOutput = m_videoWidget; |
|
99 } |
|
100 else if (qstrcmp(name, QVideoRendererControl_iid) == 0) { |
|
101 m_videoRenderer = new S60VideoRenderer; |
|
102 m_videoOutput = m_videoRenderer; |
|
103 } |
|
104 else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { |
|
105 m_videoWindow = new S60VideoOverlay; |
|
106 m_videoOutput = m_videoWindow; |
|
107 } |
|
108 |
|
109 if (m_videoOutput) { |
|
110 m_control->setVideoOutput(m_videoOutput); |
|
111 return m_videoOutput; |
|
112 } |
|
113 }else { |
|
114 if (qstrcmp(name, QVideoWidgetControl_iid) == 0 || |
|
115 qstrcmp(name, QVideoRendererControl_iid) == 0 || |
|
116 qstrcmp(name, QVideoWindowControl_iid) == 0){ |
|
117 return m_videoOutput; |
|
118 } |
|
119 } |
|
120 return 0; |
|
121 } |
|
122 |
|
123 void S60MediaPlayerService::releaseControl(QMediaControl *control) |
|
124 { |
|
125 if (control == m_videoOutput) { |
|
126 m_videoOutput = 0; |
|
127 m_control->setVideoOutput(0); |
|
128 } |
|
129 } |
|
130 |
|
131 S60MediaPlayerSession* S60MediaPlayerService::PlayerSession() |
|
132 { |
|
133 QUrl url = m_control->media().canonicalUrl(); |
|
134 |
|
135 if (url.isEmpty() == true) { |
|
136 return NULL; |
|
137 } |
|
138 |
|
139 S60MediaRecognizer *m_mediaRecognizer = new S60MediaRecognizer(this); |
|
140 S60MediaRecognizer::MediaType mediaType = m_mediaRecognizer->mediaType(url); |
|
141 |
|
142 switch (mediaType) { |
|
143 case S60MediaRecognizer::Video: |
|
144 case S60MediaRecognizer::Url: |
|
145 return VideoPlayerSession(); |
|
146 case S60MediaRecognizer::Audio: |
|
147 return AudioPlayerSession(); |
|
148 default: |
|
149 break; |
|
150 } |
|
151 |
|
152 return NULL; |
|
153 } |
|
154 |
|
155 S60MediaPlayerSession* S60MediaPlayerService::VideoPlayerSession() |
|
156 { |
|
157 if (!m_videoPlayerSession) { |
|
158 m_videoPlayerSession = new S60VideoPlayerSession(this); |
|
159 |
|
160 connect(m_videoPlayerSession, SIGNAL(positionChanged(qint64)), |
|
161 m_control, SIGNAL(positionChanged(qint64))); |
|
162 connect(m_videoPlayerSession, SIGNAL(durationChanged(qint64)), |
|
163 m_control, SIGNAL(durationChanged(qint64))); |
|
164 connect(m_videoPlayerSession, SIGNAL(stateChanged(QMediaPlayer::State)), |
|
165 m_control, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
166 connect(m_videoPlayerSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), |
|
167 m_control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
168 connect(m_videoPlayerSession,SIGNAL(bufferStatusChanged(int)), |
|
169 m_control, SIGNAL(bufferStatusChanged(int))); |
|
170 connect(m_videoPlayerSession, SIGNAL(videoAvailableChanged(bool)), |
|
171 m_control, SIGNAL(videoAvailableChanged(bool))); |
|
172 connect(m_videoPlayerSession, SIGNAL(audioAvailableChanged(bool)), |
|
173 m_control, SIGNAL(audioAvailableChanged(bool))); |
|
174 connect(m_videoPlayerSession, SIGNAL(seekableChanged(bool)), |
|
175 m_control, SIGNAL(seekableChanged(bool))); |
|
176 connect(m_videoPlayerSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)), |
|
177 m_control, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&))); |
|
178 connect(m_videoPlayerSession, SIGNAL(error(int, const QString &)), |
|
179 m_control, SIGNAL(error(int, const QString &))); |
|
180 connect(m_videoPlayerSession, SIGNAL(metaDataChanged()), |
|
181 m_metaData, SIGNAL(metaDataChanged())); |
|
182 connect(m_videoPlayerSession, SIGNAL(activeEndpointChanged(const QString&)), |
|
183 m_audioEndpointSelector, SIGNAL(activeEndpointChanged(const QString&))); |
|
184 } |
|
185 |
|
186 m_videoPlayerSession->setVolume(m_control->mediaControlSettings().volume()); |
|
187 m_videoPlayerSession->setMuted(m_control->mediaControlSettings().isMuted()); |
|
188 m_videoPlayerSession->setAudioEndpoint(m_control->mediaControlSettings().audioEndpoint()); |
|
189 return m_videoPlayerSession; |
|
190 } |
|
191 |
|
192 S60MediaPlayerSession* S60MediaPlayerService::AudioPlayerSession() |
|
193 { |
|
194 if (!m_audioPlayerSession) { |
|
195 m_audioPlayerSession = new S60AudioPlayerSession(this); |
|
196 |
|
197 connect(m_audioPlayerSession, SIGNAL(positionChanged(qint64)), |
|
198 m_control, SIGNAL(positionChanged(qint64))); |
|
199 connect(m_audioPlayerSession, SIGNAL(durationChanged(qint64)), |
|
200 m_control, SIGNAL(durationChanged(qint64))); |
|
201 connect(m_audioPlayerSession, SIGNAL(stateChanged(QMediaPlayer::State)), |
|
202 m_control, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
203 connect(m_audioPlayerSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), |
|
204 m_control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
205 connect(m_audioPlayerSession,SIGNAL(bufferStatusChanged(int)), |
|
206 m_control, SIGNAL(bufferStatusChanged(int))); |
|
207 connect(m_audioPlayerSession, SIGNAL(videoAvailableChanged(bool)), |
|
208 m_control, SIGNAL(videoAvailableChanged(bool))); |
|
209 connect(m_audioPlayerSession, SIGNAL(audioAvailableChanged(bool)), |
|
210 m_control, SIGNAL(audioAvailableChanged(bool))); |
|
211 connect(m_audioPlayerSession, SIGNAL(seekableChanged(bool)), |
|
212 m_control, SIGNAL(seekableChanged(bool))); |
|
213 connect(m_audioPlayerSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)), |
|
214 m_control, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&))); |
|
215 connect(m_audioPlayerSession, SIGNAL(error(int, const QString &)), |
|
216 m_control, SIGNAL(error(int, const QString &))); |
|
217 connect(m_audioPlayerSession, SIGNAL(metaDataChanged()), |
|
218 m_metaData, SIGNAL(metaDataChanged())); |
|
219 connect(m_audioPlayerSession, SIGNAL(activeEndpointChanged(const QString&)), |
|
220 m_audioEndpointSelector, SIGNAL(activeEndpointChanged(const QString&))); |
|
221 } |
|
222 |
|
223 m_audioPlayerSession->setVolume(m_control->mediaControlSettings().volume()); |
|
224 m_audioPlayerSession->setMuted(m_control->mediaControlSettings().isMuted()); |
|
225 m_audioPlayerSession->setAudioEndpoint(m_control->mediaControlSettings().audioEndpoint()); |
|
226 return m_audioPlayerSession; |
|
227 } |