author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 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 "audiooutput.h" |
|
20 |
#include "audioplayer.h" |
|
21 |
#include "defs.h" |
|
22 |
#include "dummyplayer.h" |
|
23 |
#include "utils.h" |
|
24 |
#include "utils.h" |
|
25 |
#include "mmf_videoplayer.h" |
|
26 |
#include "videowidget.h" |
|
27 |
||
28 |
#include "mediaobject.h" |
|
29 |
||
30 |
#include <QDir> |
|
31 |
#include <QUrl> |
|
32 |
||
33 |
QT_BEGIN_NAMESPACE |
|
34 |
||
35 |
using namespace Phonon; |
|
36 |
using namespace Phonon::MMF; |
|
37 |
||
38 |
/*! \class MMF::MediaObject |
|
39 |
\internal |
|
40 |
*/ |
|
41 |
||
42 |
//----------------------------------------------------------------------------- |
|
43 |
// Constructor / destructor |
|
44 |
//----------------------------------------------------------------------------- |
|
45 |
||
46 |
MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent) |
|
47 |
, m_recognizerOpened(false) |
|
48 |
{ |
|
49 |
m_player.reset(new DummyPlayer()); |
|
50 |
||
51 |
TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi); |
|
52 |
TRACE_ENTRY_0(); |
|
53 |
||
54 |
Q_UNUSED(parent); |
|
55 |
||
56 |
TRACE_EXIT_0(); |
|
57 |
} |
|
58 |
||
59 |
MMF::MediaObject::~MediaObject() |
|
60 |
{ |
|
61 |
TRACE_CONTEXT(MediaObject::~MediaObject, EAudioApi); |
|
62 |
TRACE_ENTRY_0(); |
|
63 |
||
64 |
m_file.Close(); |
|
65 |
m_fileServer.Close(); |
|
66 |
m_recognizer.Close(); |
|
67 |
||
68 |
TRACE_EXIT_0(); |
|
69 |
} |
|
70 |
||
71 |
||
72 |
//----------------------------------------------------------------------------- |
|
73 |
// Recognizer |
|
74 |
//----------------------------------------------------------------------------- |
|
75 |
||
76 |
bool MMF::MediaObject::openRecognizer() |
|
77 |
{ |
|
78 |
TRACE_CONTEXT(MediaObject::openRecognizer, EAudioInternal); |
|
79 |
||
80 |
if (!m_recognizerOpened) { |
|
81 |
TInt err = m_recognizer.Connect(); |
|
82 |
if (KErrNone != err) { |
|
83 |
TRACE("RApaLsSession::Connect error %d", err); |
|
84 |
return false; |
|
85 |
} |
|
86 |
||
87 |
err = m_fileServer.Connect(); |
|
88 |
if (KErrNone != err) { |
|
89 |
TRACE("RFs::Connect error %d", err); |
|
90 |
return false; |
|
91 |
} |
|
92 |
||
93 |
// This must be called in order to be able to share file handles with |
|
94 |
// the recognizer server (see fileMediaType function). |
|
95 |
err = m_fileServer.ShareProtected(); |
|
96 |
if (KErrNone != err) { |
|
97 |
TRACE("RFs::ShareProtected error %d", err); |
|
98 |
return false; |
|
99 |
} |
|
100 |
||
101 |
m_recognizerOpened = true; |
|
102 |
} |
|
103 |
||
104 |
return true; |
|
105 |
} |
|
106 |
||
107 |
MMF::MediaType MMF::MediaObject::fileMediaType |
|
108 |
(const QString& fileName) |
|
109 |
{ |
|
110 |
TRACE_CONTEXT(MediaObject::fileMediaType, EAudioInternal); |
|
111 |
||
112 |
MediaType result = MediaTypeUnknown; |
|
113 |
||
114 |
if (openRecognizer()) { |
|
115 |
||
116 |
const QHBufC fileNameSymbian(QDir::toNativeSeparators(fileName)); |
|
117 |
||
118 |
m_file.Close(); |
|
119 |
TInt err = m_file.Open(m_fileServer, *fileNameSymbian, EFileRead | EFileShareReadersOnly); |
|
120 |
||
121 |
if (KErrNone == err) { |
|
122 |
TDataRecognitionResult recognizerResult; |
|
123 |
err = m_recognizer.RecognizeData(m_file, recognizerResult); |
|
124 |
if (KErrNone == err) { |
|
125 |
const TPtrC mimeType = recognizerResult.iDataType.Des(); |
|
126 |
result = Utils::mimeTypeToMediaType(mimeType); |
|
127 |
} else { |
|
128 |
TRACE("RApaLsSession::RecognizeData filename %S error %d", fileNameSymbian.data(), err); |
|
129 |
} |
|
130 |
} else { |
|
131 |
TRACE("RFile::Open filename %S error %d", fileNameSymbian.data(), err); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
return result; |
|
136 |
} |
|
137 |
||
138 |
||
139 |
//----------------------------------------------------------------------------- |
|
140 |
// MediaObjectInterface |
|
141 |
//----------------------------------------------------------------------------- |
|
142 |
||
143 |
void MMF::MediaObject::play() |
|
144 |
{ |
|
145 |
m_player->play(); |
|
146 |
} |
|
147 |
||
148 |
void MMF::MediaObject::pause() |
|
149 |
{ |
|
150 |
m_player->pause(); |
|
151 |
} |
|
152 |
||
153 |
void MMF::MediaObject::stop() |
|
154 |
{ |
|
155 |
m_player->stop(); |
|
156 |
} |
|
157 |
||
158 |
void MMF::MediaObject::seek(qint64 ms) |
|
159 |
{ |
|
160 |
m_player->seek(ms); |
|
161 |
||
162 |
if (state() == PausedState or state() == PlayingState) { |
|
163 |
emit tick(currentTime()); |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
qint32 MMF::MediaObject::tickInterval() const |
|
168 |
{ |
|
169 |
return m_player->tickInterval(); |
|
170 |
} |
|
171 |
||
172 |
void MMF::MediaObject::setTickInterval(qint32 interval) |
|
173 |
{ |
|
174 |
m_player->setTickInterval(interval); |
|
175 |
} |
|
176 |
||
177 |
bool MMF::MediaObject::hasVideo() const |
|
178 |
{ |
|
179 |
return m_player->hasVideo(); |
|
180 |
} |
|
181 |
||
182 |
bool MMF::MediaObject::isSeekable() const |
|
183 |
{ |
|
184 |
return m_player->isSeekable(); |
|
185 |
} |
|
186 |
||
187 |
Phonon::State MMF::MediaObject::state() const |
|
188 |
{ |
|
189 |
return m_player->state(); |
|
190 |
} |
|
191 |
||
192 |
qint64 MMF::MediaObject::currentTime() const |
|
193 |
{ |
|
194 |
return m_player->currentTime(); |
|
195 |
} |
|
196 |
||
197 |
QString MMF::MediaObject::errorString() const |
|
198 |
{ |
|
199 |
return m_player->errorString(); |
|
200 |
} |
|
201 |
||
202 |
Phonon::ErrorType MMF::MediaObject::errorType() const |
|
203 |
{ |
|
204 |
return m_player->errorType(); |
|
205 |
} |
|
206 |
||
207 |
qint64 MMF::MediaObject::totalTime() const |
|
208 |
{ |
|
209 |
return m_player->totalTime(); |
|
210 |
} |
|
211 |
||
212 |
MediaSource MMF::MediaObject::source() const |
|
213 |
{ |
|
214 |
return m_player->source(); |
|
215 |
} |
|
216 |
||
217 |
void MMF::MediaObject::setSource(const MediaSource &source) |
|
218 |
{ |
|
219 |
createPlayer(source); |
|
220 |
||
221 |
// This is a hack to work around KErrInUse from MMF client utility |
|
222 |
// OpenFileL calls |
|
223 |
m_player->setFileSource(source, m_file); |
|
224 |
||
225 |
emit currentSourceChanged(source); |
|
226 |
} |
|
227 |
||
228 |
void MMF::MediaObject::createPlayer(const MediaSource &source) |
|
229 |
{ |
|
230 |
TRACE_CONTEXT(MediaObject::createPlayer, EAudioApi); |
|
231 |
TRACE_ENTRY("state %d source.type %d", state(), source.type()); |
|
232 |
TRACE_ENTRY("source.type %d", source.type()); |
|
233 |
||
234 |
MediaType mediaType = MediaTypeUnknown; |
|
235 |
||
236 |
AbstractPlayer* oldPlayer = m_player.data(); |
|
237 |
||
238 |
const bool oldPlayerHasVideo = oldPlayer->hasVideo(); |
|
239 |
const bool oldPlayerSeekable = oldPlayer->isSeekable(); |
|
240 |
||
241 |
Phonon::ErrorType error = NoError; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
QString errorMessage; |
0 | 243 |
|
244 |
// Determine media type |
|
245 |
switch (source.type()) { |
|
246 |
case MediaSource::LocalFile: |
|
247 |
mediaType = fileMediaType(source.fileName()); |
|
248 |
break; |
|
249 |
||
250 |
case MediaSource::Url: |
|
251 |
{ |
|
252 |
const QUrl url(source.url()); |
|
253 |
if (url.scheme() == QLatin1String("file")) { |
|
254 |
mediaType = fileMediaType(url.toLocalFile()); |
|
255 |
} |
|
256 |
else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
errorMessage = QLatin1String("Network streaming not supported yet"); |
0 | 258 |
error = NormalError; |
259 |
} |
|
260 |
} |
|
261 |
break; |
|
262 |
||
263 |
case MediaSource::Invalid: |
|
264 |
case MediaSource::Disc: |
|
265 |
case MediaSource::Stream: |
|
266 |
TRACE_0("Unsupported media type"); |
|
267 |
error = NormalError; |
|
268 |
break; |
|
269 |
||
270 |
case MediaSource::Empty: |
|
271 |
TRACE_0("Empty media source"); |
|
272 |
break; |
|
273 |
} |
|
274 |
||
275 |
AbstractPlayer* newPlayer = 0; |
|
276 |
||
277 |
// Construct newPlayer using oldPlayer (if not 0) in order to copy |
|
278 |
// parameters (volume, prefinishMark, transitionTime) which may have |
|
279 |
// been set on oldPlayer. |
|
280 |
||
281 |
switch (mediaType) { |
|
282 |
case MediaTypeUnknown: |
|
283 |
TRACE_0("Media type could not be determined"); |
|
284 |
if (oldPlayer) { |
|
285 |
newPlayer = new DummyPlayer(*oldPlayer); |
|
286 |
} else { |
|
287 |
newPlayer = new DummyPlayer(); |
|
288 |
} |
|
289 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
error = NormalError; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
errorMessage = tr("Media type could not be determined"); |
0 | 292 |
break; |
293 |
||
294 |
case MediaTypeAudio: |
|
295 |
if (oldPlayer) { |
|
296 |
newPlayer = new AudioPlayer(*oldPlayer); |
|
297 |
} else { |
|
298 |
newPlayer = new AudioPlayer(); |
|
299 |
} |
|
300 |
break; |
|
301 |
||
302 |
case MediaTypeVideo: |
|
303 |
if (oldPlayer) { |
|
304 |
newPlayer = new VideoPlayer(*oldPlayer); |
|
305 |
} else { |
|
306 |
newPlayer = new VideoPlayer(); |
|
307 |
} |
|
308 |
break; |
|
309 |
} |
|
310 |
||
311 |
m_player.reset(newPlayer); |
|
312 |
||
313 |
if (oldPlayerHasVideo != hasVideo()) { |
|
314 |
emit hasVideoChanged(hasVideo()); |
|
315 |
} |
|
316 |
||
317 |
if (oldPlayerSeekable != isSeekable()) { |
|
318 |
emit seekableChanged(isSeekable()); |
|
319 |
} |
|
320 |
||
321 |
connect(m_player.data(), SIGNAL(totalTimeChanged(qint64)), SIGNAL(totalTimeChanged(qint64))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
connect(m_player.data(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), SIGNAL(stateChanged(Phonon::State,Phonon::State))); |
0 | 323 |
connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished())); |
324 |
connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
connect(m_player.data(), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)), SIGNAL(metaDataChanged(QMultiMap<QString,QString>))); |
0 | 326 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
// We need to call setError() after doing the connects, otherwise the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
// error won't be received. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
if (error != NoError) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
Q_ASSERT(m_player); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
m_player->setError(error, errorMessage); |
0 | 332 |
} |
333 |
||
334 |
TRACE_EXIT_0(); |
|
335 |
} |
|
336 |
||
337 |
void MMF::MediaObject::setNextSource(const MediaSource &source) |
|
338 |
{ |
|
339 |
m_player->setNextSource(source); |
|
340 |
} |
|
341 |
||
342 |
qint32 MMF::MediaObject::prefinishMark() const |
|
343 |
{ |
|
344 |
return m_player->prefinishMark(); |
|
345 |
} |
|
346 |
||
347 |
void MMF::MediaObject::setPrefinishMark(qint32 mark) |
|
348 |
{ |
|
349 |
m_player->setPrefinishMark(mark); |
|
350 |
} |
|
351 |
||
352 |
qint32 MMF::MediaObject::transitionTime() const |
|
353 |
{ |
|
354 |
return m_player->transitionTime(); |
|
355 |
} |
|
356 |
||
357 |
void MMF::MediaObject::setTransitionTime(qint32 time) |
|
358 |
{ |
|
359 |
m_player->setTransitionTime(time); |
|
360 |
} |
|
361 |
||
362 |
void MMF::MediaObject::volumeChanged(qreal volume) |
|
363 |
{ |
|
364 |
m_player->volumeChanged(volume); |
|
365 |
} |
|
366 |
||
367 |
//----------------------------------------------------------------------------- |
|
368 |
// Video output |
|
369 |
//----------------------------------------------------------------------------- |
|
370 |
||
371 |
void MMF::MediaObject::setVideoOutput(VideoOutput* videoOutput) |
|
372 |
{ |
|
373 |
m_player->setVideoOutput(videoOutput); |
|
374 |
} |
|
375 |
||
376 |
||
377 |
AbstractPlayer *MMF::MediaObject::abstractPlayer() const |
|
378 |
{ |
|
379 |
return m_player.data(); |
|
380 |
} |
|
381 |
||
382 |
bool MMF::MediaObject::activateOnMediaObject(MediaObject *) |
|
383 |
{ |
|
384 |
// Guess what, we do nothing. |
|
385 |
return true; |
|
386 |
} |
|
387 |
||
388 |
QT_END_NAMESPACE |
|
389 |