Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/3rdparty/phonon/mmf/abstractmediaplayer.cpp

    r769 r846  
    1717*/
    1818
     19#include <QResource>
    1920#include <QUrl>
    2021
     
    2324#include "mediaobject.h"
    2425#include "utils.h"
     26#include <cdbcols.h>
     27#include <cdblen.h>
     28#include <commdb.h>
    2529
    2630QT_BEGIN_NAMESPACE
     
    5155        ,   m_pending(NothingPending)
    5256        ,   m_positionTimer(new QTimer(this))
     57        ,   m_position(0)
    5358        ,   m_bufferStatusTimer(new QTimer(this))
    5459        ,   m_mmfMaxVolume(NullMaxVolume)
    5560        ,   m_prefinishMarkSent(false)
    5661        ,   m_aboutToFinishSent(false)
     62#ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD
     63        ,   m_download(0)
     64        ,   m_downloadStalled(false)
     65#endif
    5766{
    5867    connect(m_positionTimer.data(), SIGNAL(timeout()), this, SLOT(positionTick()));
     
    183192
    184193        doSeek(ms);
     194        m_position = ms;
    185195        resetMarksIfRewound();
    186196
     
    207217}
    208218
     219qint64 MMF::AbstractMediaPlayer::currentTime() const
     220{
     221    return m_position;
     222}
     223
    209224void MMF::AbstractMediaPlayer::doSetTickInterval(qint32 interval)
    210225{
     
    217232}
    218233
    219 void MMF::AbstractMediaPlayer::open(const MediaSource &source, RFile& file)
    220 {
    221     TRACE_CONTEXT(AbstractMediaPlayer::setFileSource, EAudioApi);
     234void MMF::AbstractMediaPlayer::open()
     235{
     236    TRACE_CONTEXT(AbstractMediaPlayer::open, EAudioApi);
     237    const MediaSource source = m_parent->source();
    222238    TRACE_ENTRY("state %d source.type %d", privateState(), source.type());
    223239
     
    230246    switch (source.type()) {
    231247    case MediaSource::LocalFile: {
    232         symbianErr = openFile(file);
     248        RFile *const file = m_parent->file();
     249        Q_ASSERT(file);
     250        symbianErr = openFile(*file);
    233251        if (KErrNone != symbianErr)
    234252            errorMessage = tr("Error opening file");
     
    238256    case MediaSource::Url: {
    239257        const QUrl url(source.url());
    240 
    241258        if (url.scheme() == QLatin1String("file")) {
    242             symbianErr = openFile(file);
     259            RFile *const file = m_parent->file();
     260            Q_ASSERT(file);
     261            symbianErr = openFile(*file);
    243262            if (KErrNone != symbianErr)
    244263                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);
    247282            if (KErrNone != symbianErr)
    248283                errorMessage = tr("Error opening URL");
    249284        }
    250285
     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        }
    251299        break;
    252300    }
     
    271319}
    272320
     321void 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
    273331void MMF::AbstractMediaPlayer::volumeChanged(qreal volume)
    274332{
     
    357415    stopBufferStatusTimer();
    358416    emit MMF::AbstractPlayer::bufferStatus(100);
    359     changeState(m_stateBeforeBuffering);
     417    if (!progressiveDownloadStalled())
     418        changeState(m_stateBeforeBuffering);
    360419}
    361420
     
    368427void MMF::AbstractMediaPlayer::loadingComplete(int error)
    369428{
    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        }
    375441    } 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        }
    377453    }
    378454}
     
    398474    }
    399475    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        }
    402482    }
    403483}
     
    408488}
    409489
     490bool 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
     499bool MMF::AbstractMediaPlayer::progressiveDownloadStalled() const
     500{
     501#ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD
     502    return m_downloadStalled;
     503#else
     504    return false;
     505#endif
     506}
     507
    410508//-----------------------------------------------------------------------------
    411509// Slots
     
    414512void MMF::AbstractMediaPlayer::positionTick()
    415513{
    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    }
    419520}
    420521
     
    441542void MMF::AbstractMediaPlayer::resetMarksIfRewound()
    442543{
    443     const qint64 current = currentTime();
     544    const qint64 current = getCurrentTime();
    444545    const qint64 total = totalTime();
    445546    const qint64 remaining = total - current;
     
    470571}
    471572
     573void 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
    472588void MMF::AbstractMediaPlayer::bufferStatusTick()
    473589{
    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
     598void 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
     613void 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
    476641
    477642Phonon::State MMF::AbstractMediaPlayer::phononState(PrivateState state) const
Note: See TracChangeset for help on using the changeset viewer.