Changeset 846 for trunk/src/3rdparty/phonon/mmf/abstractmediaplayer.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/3rdparty/phonon/mmf/abstractmediaplayer.cpp
r769 r846 17 17 */ 18 18 19 #include <QResource> 19 20 #include <QUrl> 20 21 … … 23 24 #include "mediaobject.h" 24 25 #include "utils.h" 26 #include <cdbcols.h> 27 #include <cdblen.h> 28 #include <commdb.h> 25 29 26 30 QT_BEGIN_NAMESPACE … … 51 55 , m_pending(NothingPending) 52 56 , m_positionTimer(new QTimer(this)) 57 , m_position(0) 53 58 , m_bufferStatusTimer(new QTimer(this)) 54 59 , m_mmfMaxVolume(NullMaxVolume) 55 60 , m_prefinishMarkSent(false) 56 61 , m_aboutToFinishSent(false) 62 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 63 , m_download(0) 64 , m_downloadStalled(false) 65 #endif 57 66 { 58 67 connect(m_positionTimer.data(), SIGNAL(timeout()), this, SLOT(positionTick())); … … 183 192 184 193 doSeek(ms); 194 m_position = ms; 185 195 resetMarksIfRewound(); 186 196 … … 207 217 } 208 218 219 qint64 MMF::AbstractMediaPlayer::currentTime() const 220 { 221 return m_position; 222 } 223 209 224 void MMF::AbstractMediaPlayer::doSetTickInterval(qint32 interval) 210 225 { … … 217 232 } 218 233 219 void MMF::AbstractMediaPlayer::open(const MediaSource &source, RFile& file) 220 { 221 TRACE_CONTEXT(AbstractMediaPlayer::setFileSource, EAudioApi); 234 void MMF::AbstractMediaPlayer::open() 235 { 236 TRACE_CONTEXT(AbstractMediaPlayer::open, EAudioApi); 237 const MediaSource source = m_parent->source(); 222 238 TRACE_ENTRY("state %d source.type %d", privateState(), source.type()); 223 239 … … 230 246 switch (source.type()) { 231 247 case MediaSource::LocalFile: { 232 symbianErr = openFile(file); 248 RFile *const file = m_parent->file(); 249 Q_ASSERT(file); 250 symbianErr = openFile(*file); 233 251 if (KErrNone != symbianErr) 234 252 errorMessage = tr("Error opening file"); … … 238 256 case MediaSource::Url: { 239 257 const QUrl url(source.url()); 240 241 258 if (url.scheme() == QLatin1String("file")) { 242 symbianErr = openFile(file); 259 RFile *const file = m_parent->file(); 260 Q_ASSERT(file); 261 symbianErr = openFile(*file); 243 262 if (KErrNone != symbianErr) 244 263 errorMessage = tr("Error opening file"); 245 } else { 246 symbianErr = openUrl(url.toString()); 264 } 265 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 266 else if (url.scheme() == QLatin1String("http")) { 267 Q_ASSERT(!m_download); 268 m_download = new Download(url, this); 269 connect(m_download, SIGNAL(lengthChanged(qint64)), 270 this, SLOT(downloadLengthChanged(qint64))); 271 connect(m_download, SIGNAL(stateChanged(Download::State)), 272 this, SLOT(downloadStateChanged(Download::State))); 273 int iap = m_parent->currentIAP(); 274 TRACE("HTTP Url: Using IAP %d", iap); 275 m_download->start(iap); 276 } 277 #endif 278 else { 279 int iap = m_parent->currentIAP(); 280 TRACE("Using IAP %d", iap); 281 symbianErr = openUrl(url.toString(), iap); 247 282 if (KErrNone != symbianErr) 248 283 errorMessage = tr("Error opening URL"); 249 284 } 250 285 286 break; 287 } 288 289 case MediaSource::Stream: { 290 QResource *const resource = m_parent->resource(); 291 if (resource) { 292 m_buffer.Set(resource->data(), resource->size()); 293 symbianErr = openDescriptor(m_buffer); 294 if (KErrNone != symbianErr) 295 errorMessage = tr("Error opening resource"); 296 } else { 297 errorMessage = tr("Error opening source: resource not opened"); 298 } 251 299 break; 252 300 } … … 271 319 } 272 320 321 void MMF::AbstractMediaPlayer::close() 322 { 323 doClose(); 324 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 325 delete m_download; 326 m_download = 0; 327 #endif 328 m_position = 0; 329 } 330 273 331 void MMF::AbstractMediaPlayer::volumeChanged(qreal volume) 274 332 { … … 357 415 stopBufferStatusTimer(); 358 416 emit MMF::AbstractPlayer::bufferStatus(100); 359 changeState(m_stateBeforeBuffering); 417 if (!progressiveDownloadStalled()) 418 changeState(m_stateBeforeBuffering); 360 419 } 361 420 … … 368 427 void MMF::AbstractMediaPlayer::loadingComplete(int error) 369 428 { 370 Q_ASSERT(Phonon::LoadingState == state()); 371 372 if (KErrNone == error) { 373 updateMetaData(); 374 changeState(StoppedState); 429 TRACE_CONTEXT(AbstractMediaPlayer::loadingComplete, EAudioApi); 430 TRACE_ENTRY("state %d error %d", state(), error); 431 if (progressiveDownloadStalled()) { 432 Q_ASSERT(Phonon::BufferingState == state()); 433 if (KErrNone == error) { 434 bufferingComplete(); 435 doSeek(m_position); 436 startPlayback(); 437 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 438 m_downloadStalled = false; 439 #endif 440 } 375 441 } else { 376 setError(tr("Loading clip failed"), error); 442 Q_ASSERT(Phonon::LoadingState == state()); 443 if (KErrNone == error) { 444 updateMetaData(); 445 changeState(StoppedState); 446 } else { 447 if (isProgressiveDownload() && KErrCorrupt == error) { 448 setProgressiveDownloadStalled(); 449 } else { 450 setError(tr("Loading clip failed"), error); 451 } 452 } 377 453 } 378 454 } … … 398 474 } 399 475 else { 400 setError(tr("Playback complete"), error); 401 emit finished(); 476 if (isProgressiveDownload() && KErrCorrupt == error) { 477 setProgressiveDownloadStalled(); 478 } else { 479 setError(tr("Playback complete"), error); 480 emit finished(); 481 } 402 482 } 403 483 } … … 408 488 } 409 489 490 bool MMF::AbstractMediaPlayer::isProgressiveDownload() const 491 { 492 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 493 return (0 != m_download); 494 #else 495 return false; 496 #endif 497 } 498 499 bool MMF::AbstractMediaPlayer::progressiveDownloadStalled() const 500 { 501 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 502 return m_downloadStalled; 503 #else 504 return false; 505 #endif 506 } 507 410 508 //----------------------------------------------------------------------------- 411 509 // Slots … … 414 512 void MMF::AbstractMediaPlayer::positionTick() 415 513 { 416 const qint64 current = currentTime(); 417 emitMarksIfReached(current); 418 emit MMF::AbstractPlayer::tick(current); 514 const qint64 pos = getCurrentTime(); 515 if (pos > m_position) { 516 m_position = pos; 517 emitMarksIfReached(m_position); 518 emit MMF::AbstractPlayer::tick(m_position); 519 } 419 520 } 420 521 … … 441 542 void MMF::AbstractMediaPlayer::resetMarksIfRewound() 442 543 { 443 const qint64 current = currentTime();544 const qint64 current = getCurrentTime(); 444 545 const qint64 total = totalTime(); 445 546 const qint64 remaining = total - current; … … 470 571 } 471 572 573 void MMF::AbstractMediaPlayer::setProgressiveDownloadStalled() 574 { 575 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 576 TRACE_CONTEXT(AbstractMediaPlayer::setProgressiveDownloadStalled, EAudioApi); 577 TRACE_ENTRY("state %d", state()); 578 Q_ASSERT(isProgressiveDownload()); 579 m_downloadStalled = true; 580 doClose(); 581 bufferingStarted(); 582 // Video player loses window handle when closed - need to reapply it here 583 videoOutputChanged(); 584 m_download->resume(); 585 #endif 586 } 587 472 588 void MMF::AbstractMediaPlayer::bufferStatusTick() 473 589 { 474 emit MMF::AbstractPlayer::bufferStatus(bufferStatus()); 475 } 590 // During progressive download, there is no way to detect the buffering status. 591 // Phonon does not support a "buffering; amount unknown" signal, therefore we 592 // return a buffering status of zero. 593 const int status = progressiveDownloadStalled() ? 0 : bufferStatus(); 594 emit MMF::AbstractPlayer::bufferStatus(status); 595 } 596 597 #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD 598 void MMF::AbstractMediaPlayer::downloadLengthChanged(qint64 length) 599 { 600 TRACE_CONTEXT(AbstractMediaPlayer::downloadLengthChanged, EAudioApi); 601 TRACE_ENTRY("length %Ld", length); 602 Q_UNUSED(length) 603 if (m_downloadStalled) { 604 bufferingComplete(); 605 int err = m_parent->openFileHandle(m_download->targetFileName()); 606 if (KErrNone == err) 607 err = openFile(*m_parent->file()); 608 if (KErrNone != err) 609 setError(tr("Error opening file")); 610 } 611 } 612 613 void MMF::AbstractMediaPlayer::downloadStateChanged(Download::State state) 614 { 615 TRACE_CONTEXT(AbstractMediaPlayer::downloadStateChanged, EAudioApi); 616 TRACE_ENTRY("state %d", state); 617 switch (state) { 618 case Download::Idle: 619 case Download::Initializing: 620 break; 621 case Download::Downloading: 622 { 623 int err = m_parent->openFileHandle(m_download->targetFileName()); 624 if (KErrNone == err) 625 err = openFile(*m_parent->file()); 626 else if (KErrCorrupt == err) 627 // Insufficient data downloaded - enter Buffering state 628 setProgressiveDownloadStalled(); 629 if (KErrNone != err) 630 setError(tr("Error opening file")); 631 } 632 break; 633 case Download::Complete: 634 break; 635 case Download::Error: 636 setError(tr("Download error")); 637 break; 638 } 639 } 640 #endif // PHONON_MMF_PROGRESSIVE_DOWNLOAD 476 641 477 642 Phonon::State MMF::AbstractMediaPlayer::phononState(PrivateState state) const
Note:
See TracChangeset
for help on using the changeset viewer.