Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/3rdparty/phonon/qt7/backend.mm

    r2 r561  
    6060    setProperty("backendVersion", QLatin1String("0.1"));
    6161    setProperty("backendIcon",    QLatin1String(""));
    62     setProperty("backendWebsite", QLatin1String("http://qtsoftware.com/"));
     62    setProperty("backendWebsite", QLatin1String("http://qt.com/"));
    6363}
    6464
  • trunk/src/3rdparty/phonon/qt7/mediaobject.h

    r2 r561  
    2525
    2626#include "medianode.h"
     27
     28
     29
     30
    2731
    2832QT_BEGIN_NAMESPACE
     
    3943
    4044    class MediaObject : public MediaNode,
    41         public Phonon::MediaObjectInterface, public Phonon::AddonInterface
     45        public Phonon::MediaObjectInterface
     46#ifndef QT_NO_PHONON_MEDIACONTROLLER
     47        , public Phonon::AddonInterface
     48#endif
    4249    {
    4350        Q_OBJECT
     
    9299
    93100                int videoOutputCount();
     101
     102
     103
     104
    94105
    95106    signals:
     
    106117        void currentSourceChanged(const MediaSource &newSource);
    107118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
    108129    protected:
    109130        void mediaNodeEvent(const MediaNodeEvent *event);
     
    119140        QuickTimeAudioPlayer *m_nextAudioPlayer;
    120141        MediaObjectAudioNode *m_mediaObjectAudioNode;
    121         QuickTimeMetaData *m_metaData;
     142
     143#if QT_ALLOW_QUICKTIME
     144        CVDisplayLinkRef m_displayLink;
     145        QMutex m_displayLinkMutex;
     146        bool m_pendingDisplayLinkEvent;
     147        void startDisplayLink();
     148        void stopDisplayLink();
     149#endif
    122150
    123151        qint32 m_tickInterval;
     
    128156
    129157        int m_tickTimer;
    130         int m_bufferTimer;
     158        int m_videoTimer;
     159        int m_audioTimer;
    131160        int m_rapidTimer;
    132161
     
    134163        int m_swapTimeLeft;
    135164        QTime m_swapTime;
     165
    136166
    137167        void synchAudioVideo();
     
    142172        void play_internal();
    143173        void setupAudioSystem();
    144         void updateTimer(int &timer, int interval);
    145         void bufferAudioVideo();
     174        void restartAudioVideoTimers();
    146175        void updateRapidly();
    147176        void updateCrossFade();
     
    155184        void inspectGraph();
    156185        bool isCrossFading();
     186
    157187
    158188        QString m_errorString;
  • trunk/src/3rdparty/phonon/qt7/mediaobject.mm

    r2 r561  
    4747    setAudioNode(m_mediaObjectAudioNode);
    4848
    49     m_metaData = new QuickTimeMetaData();
    5049    m_audioGraph = new AudioGraph(this);
    5150
     
    5655    m_percentageLoaded = 0;
    5756    m_waitNextSwap = false;
     57
    5858    m_audioEffectCount = 0;
    5959    m_audioOutputCount = 0;
     
    6464
    6565    m_tickTimer = 0;
    66     m_bufferTimer = 0;
     66    m_videoTimer = 0;
     67    m_audioTimer = 0;
    6768    m_rapidTimer = 0;
    6869
     70
     71
     72
     73
     74
    6975    checkForError();
    7076}
    7177
    7278MediaObject::~MediaObject()
    73 {   
    74     // m_mediaObjectAudioNode is owned by super class.   
     79{
     80    // m_mediaObjectAudioNode is owned by super class.
     81#if QT_ALLOW_QUICKTIME
     82    stopDisplayLink();
     83#endif
    7584    m_audioPlayer->unsetVideoPlayer();
    7685    m_nextAudioPlayer->unsetVideoPlayer();
    7786    delete m_videoPlayer;
    7887    delete m_nextVideoPlayer;
    79     delete m_metaData;
    8088    checkForError();
    8189}
     
    8997        if (m_state != state){
    9098            // End-application did something
    91             // upon  receiving the signal. 
     99            // upon  receiving the signal.
    92100            return false;
    93101        }
     
    123131    // effects or outputs connected. This will have
    124132    // influence on the audio system and video system that ends up beeing used:
    125     int prevVideoOutputCount = m_videoOutputCount;     
     133    int prevVideoOutputCount = m_videoOutputCount;
    126134    m_audioEffectCount = 0;
    127135    m_audioOutputCount = 0;
     
    135143            MediaNodeEvent e1(MediaNodeEvent::VideoOutputCountChanged, &m_videoOutputCount);
    136144            notify(&e1);
    137         }       
     145    }
    138146}
    139147
     
    168176    if (newAudioSystem == m_audioSystem)
    169177        return;
    170  
     178
    171179    // Enable selected audio system:
    172     m_audioSystem = newAudioSystem; 
     180    m_audioSystem = newAudioSystem;
    173181    switch (newAudioSystem){
    174182        case AS_Silent:
    175183            m_audioGraph->stop();
    176184            m_videoPlayer->enableAudio(false);
    177             m_nextVideoPlayer->enableAudio(false);   
     185            m_nextVideoPlayer->enableAudio(false);
    178186            m_audioPlayer->enableAudio(false);
    179187            m_nextAudioPlayer->enableAudio(false);
     
    215223        PhononAutoReleasePool pool;
    216224    setState(Phonon::LoadingState);
    217    
     225
    218226    // Save current state for event/signal handling below:
    219227    bool prevHasVideo = m_videoPlayer->hasVideo();
    220228    qint64 prevTotalTime = totalTime();
     229
    221230    m_waitNextSwap = false;
    222        
     231
    223232    // Cancel cross-fade if any:
    224233    m_nextVideoPlayer->pause();
    225234    m_nextAudioPlayer->pause();
    226235    m_mediaObjectAudioNode->cancelCrossFade();
    227    
     236
    228237    // Set new source:
    229238    m_audioPlayer->unsetVideoPlayer();
    230239    m_videoPlayer->setMediaSource(source);
    231240    m_audioPlayer->setVideoPlayer(m_videoPlayer);
    232     m_metaData->setVideo(m_videoPlayer);       
    233 
    234     m_audioGraph->updateStreamSpecifications();       
     241
     242    m_audioGraph->updateStreamSpecifications();
    235243    m_nextAudioPlayer->unsetVideoPlayer();
    236     m_nextVideoPlayer->unsetVideo();
     244    m_nextVideoPlayer->unset();
    237245    m_currentTime = 0;
    238        
     246
    239247    // Emit/notify information about the new source:
    240248    QRect videoRect = m_videoPlayer->videoRect();
     
    247255
    248256    emit currentSourceChanged(source);
    249     emit metaDataChanged(m_metaData->metaData());
     257    emit metaDataChanged(m_->metaData());
    250258
    251259    if (prevHasVideo != m_videoPlayer->hasVideo())
    252         emit hasVideoChanged(m_videoPlayer->hasVideo());       
     260        emit hasVideoChanged(m_videoPlayer->hasVideo());
    253261    if (prevTotalTime != totalTime())
    254         emit totalTimeChanged(totalTime());       
     262        emit totalTimeChanged(totalTime());
     263    if (prevTrackCount != m_videoPlayer->trackCount())
     264        emit availableTitlesChanged(m_videoPlayer->trackCount());
    255265    if (checkForError())
    256266        return;
     
    261271    if (!m_videoPlayer->canPlayMedia())
    262272        SET_ERROR("Cannot play media.", FATAL_ERROR)
    263        
     273
    264274    // The state might have changed from LoadingState
    265275    // as a response to an error state change. So we
     
    288298    bool prevHasVideo = m_videoPlayer->hasVideo();
    289299    qint64 prevTotalTime = totalTime();
     300
    290301
    291302    qSwap(m_audioPlayer, m_nextAudioPlayer);
     
    293304    m_mediaObjectAudioNode->startCrossFade(transitionTime);
    294305    m_audioGraph->updateStreamSpecifications();
    295     m_metaData->setVideo(m_videoPlayer);
    296306
    297307    m_waitNextSwap = false;
    298308    m_currentTime = 0;
    299        
     309
    300310    // Emit/notify information about the new source:
    301311    QRect videoRect = m_videoPlayer->videoRect();
     
    304314
    305315    emit currentSourceChanged(m_videoPlayer->mediaSource());
    306     emit metaDataChanged(m_metaData->metaData());
     316    emit metaDataChanged(m_->metaData());
    307317
    308318    if (prevHasVideo != m_videoPlayer->hasVideo())
    309         emit hasVideoChanged(m_videoPlayer->hasVideo());       
     319        emit hasVideoChanged(m_videoPlayer->hasVideo());
    310320    if (prevTotalTime != totalTime())
    311321        emit totalTimeChanged(totalTime());
     322
     323
    312324    if (checkForError())
    313325        return;
     
    328340}
    329341
    330 void MediaObject::updateTimer(int &timer, int interval)
    331 {
    332     if (timer)
    333         killTimer(timer);
    334     timer = 0;
    335     if (interval >= 0)   
    336         timer = startTimer(interval);
     342#if QT_ALLOW_QUICKTIME
     343static CVReturn displayLinkCallback(CVDisplayLinkRef /*displayLink*/,
     344                                                                 const CVTimeStamp */*inNow*/,
     345                                                                 const CVTimeStamp */*inOutputTime*/,
     346                                                                 CVOptionFlags /*flagsIn*/,
     347                                                                 CVOptionFlags */*flagsOut*/,
     348                                 void *userData)
     349{
     350    MediaObject *mediaObject = static_cast<MediaObject *>(userData);
     351    mediaObject->displayLinkEvent();
     352    return kCVReturnSuccess;
     353}
     354
     355void MediaObject::displayLinkEvent()
     356{
     357    // This function is called from a
     358    // thread != gui thread. So we post the event.
     359    // But we need to make sure that we don't post faster
     360    // than the event loop can eat:
     361    m_displayLinkMutex.lock();
     362    bool pending = m_pendingDisplayLinkEvent;
     363    m_pendingDisplayLinkEvent = true;
     364    m_displayLinkMutex.unlock();
     365
     366    if (!pending)
     367        qApp->postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority);
     368}
     369
     370void MediaObject::startDisplayLink()
     371{
     372    if (m_displayLink)
     373        return;
     374    OSStatus err = CVDisplayLinkCreateWithCGDisplay(kCGDirectMainDisplay, &m_displayLink);
     375    if (err != noErr)
     376        goto fail;
     377    err = CVDisplayLinkSetCurrentCGDisplay(m_displayLink, kCGDirectMainDisplay);
     378    if (err != noErr)
     379        goto fail;
     380    err = CVDisplayLinkSetOutputCallback(m_displayLink, displayLinkCallback, this);
     381    if (err != noErr)
     382        goto fail;
     383    err = CVDisplayLinkStart(m_displayLink);
     384    if (err != noErr)
     385        goto fail;
     386    return;
     387fail:
     388    stopDisplayLink();
     389}
     390
     391void MediaObject::stopDisplayLink()
     392{
     393    if (!m_displayLink)
     394        return;
     395    CVDisplayLinkStop(m_displayLink);
     396    CFRelease(m_displayLink);
     397    m_displayLink = 0;
     398}
     399#endif
     400
     401void MediaObject::restartAudioVideoTimers()
     402{
     403    if (m_videoTimer)
     404        killTimer(m_videoTimer);
     405    if (m_audioTimer)
     406        killTimer(m_audioTimer);
     407
     408#if QT_ALLOW_QUICKTIME
     409    // We prefer to use a display link as timer if available, since
     410    // it is more steady, and results in better and smoother frame drawing:
     411    startDisplayLink();
     412    if (!m_displayLink){
     413        float fps = m_videoPlayer->staticFps();
     414        long videoUpdateFrequency = fps ? long(1000.0f / fps) : 0.001;
     415        m_videoTimer = startTimer(videoUpdateFrequency);
     416    }
     417#else
     418    float fps = m_videoPlayer->staticFps();
     419    long videoUpdateFrequency = fps ? long(1000.0f / fps) : 0.001;
     420    m_videoTimer = startTimer(videoUpdateFrequency);
     421#endif
     422
     423    long audioUpdateFrequency = m_audioPlayer->regularTaskFrequency();
     424    m_audioTimer = startTimer(audioUpdateFrequency);
     425    updateVideoFrames();
     426    updateAudioBuffers();
    337427}
    338428
     
    341431    // Play main audio/video:
    342432    m_videoPlayer->play();
    343     m_audioPlayer->play();     
     433    m_audioPlayer->play();
    344434    updateLipSynch(0);
    345435    // Play old audio/video to finish cross-fade:
     
    348438        m_nextAudioPlayer->play();
    349439    }
    350     bufferAudioVideo();
    351     updateTimer(m_rapidTimer, 100);
     440    restartAudioVideoTimers();
     441    if (!m_rapidTimer)
     442        m_rapidTimer = startTimer(100);
    352443}
    353444
     
    359450    m_videoPlayer->pause();
    360451    m_nextVideoPlayer->pause();
    361     updateTimer(m_rapidTimer, -1);
    362     updateTimer(m_bufferTimer, -1);
    363 
     452    killTimer(m_rapidTimer);
     453    killTimer(m_videoTimer);
     454    killTimer(m_audioTimer);
     455    m_rapidTimer = 0;
     456    m_videoTimer = 0;
     457    m_audioTimer = 0;
     458#if QT_ALLOW_QUICKTIME
     459    stopDisplayLink();
     460#endif
    364461    if (m_waitNextSwap)
    365462        m_swapTimeLeft = m_swapTime.msecsTo(QTime::currentTime());
     
    383480        return;
    384481    if (!setState(Phonon::PlayingState))
    385         return;       
     482        return;
    386483    if (m_audioSystem == AS_Graph){
    387484        m_audioGraph->start();
     
    424521        return;
    425522    m_waitNextSwap = false;
    426     m_nextVideoPlayer->unsetVideo();
     523    m_nextVideoPlayer->unset();
    427524    m_nextAudioPlayer->unsetVideoPlayer();
    428525    pause_internal();
     
    436533    if (m_state == Phonon::ErrorState)
    437534        return;
    438        
     535
    439536    // Stop cross-fade if any:
    440     m_nextVideoPlayer->unsetVideo();
     537    m_nextVideoPlayer->unset();
    441538    m_nextAudioPlayer->unsetVideoPlayer();
    442539    m_mediaObjectAudioNode->cancelCrossFade();
     
    447544    m_audioPlayer->seek(m_videoPlayer->currentTime());
    448545    m_mediaObjectAudioNode->setMute(false);
    449    
     546
    450547    // Update time and cancel pending swap:
    451548    if (m_currentTime < m_videoPlayer->duration())
     
    558655{
    559656    IMPLEMENTED_SILENT;
    560     const_cast<MediaObject *>(this)->updateCurrentTime(); 
     657    const_cast<MediaObject *>(this)->updateCurrentTime();
    561658    return m_currentTime;
    562659}
     
    568665    quint64 total = m_videoPlayer->duration();
    569666
    570     // Check if it's time to emit aboutToFinish:
    571     quint32 mark = qMax(quint64(0), qMin(total, total + m_transitionTime - 2000));
    572     if (lastUpdateTime < mark && mark <= m_currentTime)
    573         emit aboutToFinish();
    574 
    575     // Check if it's time to emit prefinishMarkReached:
    576     mark = qMax(quint64(0), total - m_prefinishMark);
    577     if (lastUpdateTime < mark && mark <= m_currentTime)
    578         emit prefinishMarkReached(total - m_currentTime);
    579 
    580     if (m_nextVideoPlayer->state() == QuickTimeVideoPlayer::NoMedia){
    581         // There is no next source in que.
    582         // Check if it's time to emit finished:
     667    if (m_videoPlayer->currentTrack() < m_videoPlayer->trackCount() - 1){
     668        // There are still more tracks to play after the current track.
     669        if (m_autoplayTitles) {
     670            if (lastUpdateTime < m_currentTime && m_currentTime == total)
     671                setCurrentTrack(m_videoPlayer->currentTrack() + 1);
     672        }
     673    } else if (m_nextVideoPlayer->state() == QuickTimeVideoPlayer::NoMedia){
     674        // There is no more sources or tracks to play after the current source.
     675        // Check if it's time to emit aboutToFinish:
     676        quint32 mark = qMax(quint64(0), qMin(total, total + m_transitionTime - 2000));
     677        if (lastUpdateTime < mark && mark <= m_currentTime)
     678            emit aboutToFinish();
     679
     680        // Check if it's time to emit prefinishMarkReached:
     681        mark = qMax(quint64(0), total - m_prefinishMark);
     682        if (lastUpdateTime < mark && mark <= m_currentTime)
     683            emit prefinishMarkReached(total - m_currentTime);
     684
    583685        if (lastUpdateTime < m_currentTime && m_currentTime == total){
    584686            emit finished();
     
    590692        // We have a next source.
    591693        // Check if it's time to swap to next source:
    592         mark = qMax(quint64(0), total + m_transitionTime);
     694        mark = qMax(quint64(0), total + m_transitionTime);
    593695        if (m_waitNextSwap && m_state == Phonon::PlayingState &&
    594696            m_transitionTime < m_swapTime.msecsTo(QTime::currentTime())){
     
    693795void MediaObject::updateCrossFade()
    694796{
    695     m_mediaObjectAudioNode->updateCrossFade(m_currentTime);   
     797    m_mediaObjectAudioNode->updateCrossFade(m_currentTime);
    696798    // Clean-up previous movie if done fading:
    697799    if (m_mediaObjectAudioNode->m_fadeDuration == 0){
    698800        if (m_nextVideoPlayer->isPlaying() || m_nextAudioPlayer->isPlaying()){
    699             m_nextVideoPlayer->unsetVideo();
     801            m_nextVideoPlayer->unset();
    700802            m_nextAudioPlayer->unsetVideoPlayer();
    701803        }
    702     }       
     804    }
    703805}
    704806
     
    729831    if (m_videoPlayer->videoFrameChanged()){
    730832        updateLipSynch(50);
    731         VideoFrame frame(m_videoPlayer);           
     833        VideoFrame frame(m_videoPlayer);
    732834        if (m_nextVideoPlayer->isPlaying()
    733835            && m_nextVideoPlayer->hasVideo()
     
    737839            frame.setBaseOpacity(m_mediaObjectAudioNode->m_volume1);
    738840        }
    739        
     841
    740842        // Send the frame through the graph:
    741         updateVideo(frame);   
     843        updateVideo(frame);
    742844        checkForError();
    743845    }
     
    750852    if (m_videoSinkList.isEmpty() || m_audioSinkList.isEmpty())
    751853        return;
    752        
     854
    753855    if (m_videoPlayer->hasVideo()){
    754856        qint64 diff = m_audioPlayer->currentTime() - m_videoPlayer->currentTime();
     
    762864            m_nextAudioPlayer->seek(m_nextVideoPlayer->currentTime());
    763865    }
    764 }
    765 
    766 void MediaObject::bufferAudioVideo()
    767 {
    768     long nextVideoUpdate = m_videoPlayer->hasVideo() ? 30 : INT_MAX;
    769     long nextAudioUpdate = m_audioPlayer->regularTaskFrequency();
    770     updateAudioBuffers();
    771     updateVideoFrames();
    772     if (m_state == Phonon::PlayingState)
    773         updateTimer(m_bufferTimer, qMin(nextVideoUpdate, nextAudioUpdate));
    774866}
    775867
     
    798890            checkForError();
    799891            m_mediaObjectAudioNode->setMute(false);
    800              if (m_state == Phonon::PlayingState)
    801                 bufferAudioVideo();
     892            if (m_state == Phonon::PlayingState)
     893                ();
    802894            break;
    803895        case MediaNodeEvent::AudioGraphCannotPlay:
     
    810902                m_mediaObjectAudioNode->setMute(false);
    811903            }
    812             break;
    813         default:
    814             break;
    815     }
    816 }
    817 
    818 bool MediaObject::event(QEvent *event)
    819 {
    820     switch (event->type()){
    821         case QEvent::Timer: {
    822             QTimerEvent *timerEvent = static_cast<QTimerEvent *>(event);
    823             if (timerEvent->timerId() == m_rapidTimer)
    824                 updateRapidly();
    825             else if (timerEvent->timerId() == m_tickTimer)
    826                 emit tick(currentTime());
    827             else if (timerEvent->timerId() == m_bufferTimer)
    828                 bufferAudioVideo();
    829             }
    830904            break;
    831905        default:
    832906            break;
    833907    }
     908
     909
     910
     911
     912
     913
     914
     915
     916
     917
     918
     919
     920
     921
     922
     923
     924
     925
     926
     927
     928
     929
     930
     931
     932
     933
     934
    834935    return QObject::event(event);
    835936}
    836937
    837 bool MediaObject::hasInterface(Interface /*interface*/) const
    838 {
    839     return false;
    840 }
    841 
    842 QVariant MediaObject::interfaceCall(Interface /*interface*/, int /*command*/, const QList<QVariant> &/*arguments*/)
    843 {
     938void MediaObject::setCurrentTrack(int track)
     939{
     940    if (track == m_videoPlayer->currentTrack() || track < 0 || track >= m_videoPlayer->trackCount())
     941        return;
     942
     943    m_videoPlayer->setCurrentTrack(track);
     944    emit titleChanged(track);
     945    emit metaDataChanged(m_videoPlayer->metaData());
     946}
     947
     948bool MediaObject::hasInterface(Interface iface) const
     949{
     950    return iface == AddonInterface::TitleInterface;
     951}
     952
     953QVariant MediaObject::interfaceCall(Interface iface, int command, const QList<QVariant> &params)
     954{
     955    switch (iface) {
     956        case TitleInterface:
     957            switch (command) {
     958                case availableTitles:
     959                    return m_videoPlayer->trackCount();
     960                case title:
     961                    return m_videoPlayer->currentTrack();
     962                case setTitle:
     963                    setCurrentTrack(params.first().toInt());
     964                    break;
     965                case autoplayTitles:
     966                    return m_autoplayTitles;
     967                case setAutoplayTitles:
     968                    m_autoplayTitles = params.first().toBool();
     969                    break;
     970            }
     971        default:
     972            break;
     973    }
    844974    return QVariant();
    845975}
  • trunk/src/3rdparty/phonon/qt7/quicktimemetadata.h

    r2 r561  
    3939    {
    4040        public:
    41             QuickTimeMetaData();
    42             virtual ~QuickTimeMetaData();
    43 
    44             void setVideo(QuickTimeVideoPlayer *videoPlayer);
     41            QuickTimeMetaData(QuickTimeVideoPlayer *videoPlayer);
     42            void update();
    4543            QMultiMap<QString, QString> metaData();
    4644
     
    5048            QuickTimeVideoPlayer *m_videoPlayer;
    5149            void readMetaData();
     50
     51
    5252
    5353#ifdef QUICKTIME_C_API_AVAILABLE
  • trunk/src/3rdparty/phonon/qt7/quicktimemetadata.mm

    r2 r561  
    1616*/
    1717
     18
    1819#include "quicktimemetadata.h"
    1920#include "quicktimevideoplayer.h"
     
    2627{
    2728
    28 QuickTimeMetaData::QuickTimeMetaData()
    29 {
    30     m_videoPlayer = 0;
     29QuickTimeMetaData::QuickTimeMetaData()
     30{
     31    m_videoPlayer = ;
    3132    m_movieChanged = false;
    3233}
    3334
    34 QuickTimeMetaData::~QuickTimeMetaData()
    35 {
    36 }
    37 
    38 void QuickTimeMetaData::setVideo(QuickTimeVideoPlayer *videoPlayer)
    39 {
    40     m_videoPlayer = videoPlayer;
     35void QuickTimeMetaData::update()
     36{
    4137    m_movieChanged = true;
    4238    m_metaData.clear();
     
    146142#endif // QUICKTIME_C_API_AVAILABLE
    147143
    148 void QuickTimeMetaData::readMetaData()
    149 {
    150         if (!m_videoPlayer)
    151         return;
     144void QuickTimeMetaData::guessMetaDataForCD()
     145{
     146    QString album = QFileInfo(m_videoPlayer->movieCompactDiscPath()).fileName();
     147    QString title = QFileInfo(m_videoPlayer->currentTrackPath()).fileName();
     148    title = title.left(title.lastIndexOf('.'));
     149    m_metaData.insert(QLatin1String("ALBUM"), album);
     150    m_metaData.insert(QLatin1String("TITLE"), title);
     151    m_metaData.insert(QLatin1String("TRACKNUMBER"), QString::number(m_videoPlayer->currentTrack()));
     152}
     153
     154void QuickTimeMetaData::readMetaDataFromMovie()
     155{
    152156    QMultiMap<QString, QString> metaMap;
    153    
     157
    154158#ifdef QUICKTIME_C_API_AVAILABLE
    155         QTMetaDataRef metaDataRef;       
     159    QTMetaDataRef metaDataRef;
    156160        OSStatus err = QTCopyMovieMetaData([m_videoPlayer->qtMovie() quickTimeMovie], &metaDataRef);
    157161    BACKEND_ASSERT2(err == noErr, "Could not read QuickTime meta data", NORMAL_ERROR)
     
    174178}
    175179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
    176191QMultiMap<QString, QString> QuickTimeMetaData::metaData()
    177192{
  • trunk/src/3rdparty/phonon/qt7/quicktimevideoplayer.h

    r2 r561  
    4040{
    4141    class QuickTimeStreamReader;
     42
    4243        class VideoRenderWidgetQTMovieView;
    4344
     
    5758            void setMediaSource(const MediaSource &source);
    5859            MediaSource mediaSource() const;
    59             void unsetVideo();
     60            void unset();
    6061
    6162            void play();
     
    6869                        void *currentFrameAsCIImage();
    6970            QImage currentFrameAsQImage();
     71
    7072            QRect videoRect() const;
    7173
     
    7375            quint64 currentTime() const;
    7476            long timeScale() const;
     77
    7578            QString currentTimeString();
    7679
     
    8588            void setPlaybackRate(float rate);
    8689            QTMovie *qtMovie() const;
     90
    8791
    8892            float playbackRate() const;
     
    104108            quint64 timeLoaded();
    105109
     110
     111
     112
     113
     114
     115
    106116            static QString timeToString(quint64 ms);
    107117
     
    117127            State m_state;
    118128            QGLPixelBuffer *m_QImagePixelBuffer;
     129
     130
     131
     132
    119133
    120134            bool m_playbackRateSat;
     
    127141            float m_relativeVolume;
    128142            float m_playbackRate;
     143
    129144            quint64 m_currentTime;
    130145            MediaSource m_mediaSource;
     146
    131147                        void *m_primaryRenderingCIImage;
    132148                        qreal m_brightness;
     
    134150                        qreal m_hue;
    135151                        qreal m_saturation;
     152
     153
     154
    136155
    137156#ifdef QUICKTIME_C_API_AVAILABLE
     
    141160            QuickTimeStreamReader *m_streamReader;
    142161
     162
    143163            void createVisualContext();
    144164            void openMovieFromCurrentMediaSource();
     
    147167            void openMovieFromUrl();
    148168            void openMovieFromStream();
     169
    149170            void openMovieFromData(QByteArray *data, char *fileType);
    150171            void openMovieFromDataGuessType(QByteArray *data);
    151172                        QString mediaSourcePath();
    152173                        bool codecExistsAccordingToSuffix(const QString &fileName);
     174
     175
     176
    153177
    154178            void setError(NSError *error);
    155179            bool errorOccured();
    156180            void readProtection();
     181
    157182            void checkIfVideoAwailable();
    158183            bool movieNotLoaded();
  • trunk/src/3rdparty/phonon/qt7/quicktimevideoplayer.mm

    r2 r561  
    2121#include "audiodevice.h"
    2222#include "quicktimestreamreader.h"
     23
    2324
    2425#include <QtCore/QCoreApplication>
     
    5354    m_state = NoMedia;
    5455    m_mediaSource = MediaSource();
     56
    5557    m_QTMovie = 0;
    5658    m_streamReader = 0;
     
    6264    m_audioEnabled = false;
    6365    m_hasVideo = false;
     66
    6467    m_playbackRateSat = false;
    6568    m_isDrmProtected = false;
     
    6871        m_primaryRenderingCIImage = 0;
    6972    m_QImagePixelBuffer = 0;
     73
     74
     75
    7076
    7177#ifdef QUICKTIME_C_API_AVAILABLE
     
    7884QuickTimeVideoPlayer::~QuickTimeVideoPlayer()
    7985{
    80     unsetVideo();
     86        PhononAutoReleasePool pool;
     87    unsetCurrentMediaSource();
     88    delete m_metaData;
    8189    [(NSObject*)m_primaryRenderingTarget release];
    8290    m_primaryRenderingTarget = 0;
     
    8593        CFRelease(m_visualContext);
    8694#endif
     95
     96
     97
     98
     99
     100
     101
     102
     103
    87104}
    88105
     
    126143
    127144    QTVisualContextTask(m_visualContext);
    128     return QTVisualContextIsNewImageAvailable(m_visualContext, 0);
     145    bool changed = QTVisualContextIsNewImageAvailable(m_visualContext, 0);
     146    if (changed)
     147        releaseImageCache();
     148    return changed;
    129149
    130150#elif defined(QT_MAC_USE_COCOA)
     
    141161    if (!m_visualContext)
    142162        return 0;
    143     CVOpenGLTextureRef texture = 0;
    144     OSStatus err = QTVisualContextCopyImageForTime(m_visualContext, 0, 0, &texture);
    145     BACKEND_ASSERT3(err == noErr, "Could not copy image for time in QuickTime player", FATAL_ERROR, 0)
    146     return texture;
     163    if (!m_cachedCVTextureRef){
     164        OSStatus err = QTVisualContextCopyImageForTime(m_visualContext, 0, 0, &m_cachedCVTextureRef);
     165        BACKEND_ASSERT3(err == noErr, "Could not copy image for time in QuickTime player", FATAL_ERROR, 0)
     166    }
     167    return m_cachedCVTextureRef;
    147168
    148169#else
     
    153174QImage QuickTimeVideoPlayer::currentFrameAsQImage()
    154175{
     176
     177
     178
    155179#ifdef QUICKTIME_C_API_AVAILABLE
    156180    QGLContext *prevContext = const_cast<QGLContext *>(QGLContext::currentContext());
     
    182206    glEnd();
    183207
    184     QImage image = m_QImagePixelBuffer->toImage();
    185     CVOpenGLTextureRelease(texture);
     208    m_cachedQImage = m_QImagePixelBuffer->toImage();
    186209    // Because of QuickTime, m_QImagePixelBuffer->doneCurrent() will fail.
    187210    // So we store, and restore, the context our selves:
    188211    prevContext->makeCurrent();
    189     return image;
     212    return mage;
    190213#else
    191214        CIImage *img = (CIImage *)currentFrameAsCIImage();
     
    196219        CGRect bounds = [img extent];
    197220        QImage qImg([bitmap bitmapData], bounds.size.width, bounds.size.height, QImage::Format_ARGB32);
    198         QImage swapped = qImg.rgbSwapped();
     221        = qImg.rgbSwapped();
    199222        [bitmap release];
    200223        [img release];
    201         return swapped;
     224        return ;
    202225#endif
    203226}
     
    251274        CVOpenGLTextureRef cvImg = currentFrameAsCVTexture();
    252275        CIImage *img = [[CIImage alloc] initWithCVImageBuffer:cvImg];
    253         CVOpenGLTextureRelease(cvImg);
    254         return img;     
     276        return img;
    255277#else
    256278        return 0;
     
    274296    int samplesPerPixel = [bitmap samplesPerPixel];
    275297    if (![bitmap isPlanar] && (samplesPerPixel == 3 || samplesPerPixel == 4)){
    276         glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 
     298        glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0,
    277299            samplesPerPixel == 4 ? GL_RGBA8 : GL_RGB8,
    278300            [bitmap pixelsWide], [bitmap pixelsHigh],
     
    303325    m_relativeVolume = relativeVolume;
    304326    if (!m_QTMovie || !m_audioEnabled || m_mute)
    305         return;               
     327        return;
    306328    [m_QTMovie setVolume:(m_masterVolume * m_relativeVolume)];
    307329}
     
    314336
    315337    // Work-around bug that happends if you set/unset mute
    316     // before movie is playing, and audio is not played 
     338    // before movie is playing, and audio is not played
    317339    // through graph. Then audio is delayed.
    318340    [m_QTMovie setMuted:mute];
     
    327349
    328350    // Work-around bug that happends if you set/unset mute
    329     // before movie is playing, and audio is not played 
     351    // before movie is playing, and audio is not played
    330352    // through graph. Then audio is delayed.
    331353    [m_QTMovie setMuted:(!enable || m_mute)];
     
    346368    // The following code will not work for some media codecs that
    347369    // typically mingle audio/video frames (e.g mpeg).
    348     CFStringRef idString = PhononCFString::toCFStringRef(AudioDevice::deviceUID(id));       
     370    CFStringRef idString = PhononCFString::toCFStringRef(AudioDevice::deviceUID(id));
    349371    QTAudioContextRef context;
    350372    QTAudioContextCreateForAudioDevice(kCFAllocatorDefault, idString, 0, &context);
     
    370392    saturation += 1;
    371393
     394
     395
     396
     397
     398
     399
    372400        m_brightness = brightness;
    373401        m_contrast = contrast;
    374402        m_hue = hue;
    375403        m_saturation = saturation;
    376        
    377404#ifdef QUICKTIME_C_API_AVAILABLE
    378405    Float32 value;
     
    386413    SetMovieVisualSaturation([m_QTMovie quickTimeMovie], value, 0);
    387414#endif
     415
    388416}
    389417
     
    398426}
    399427
    400 void QuickTimeVideoPlayer::unsetVideo()
     428void QuickTimeVideoPlayer::unset()
    401429{
    402430    if (!m_QTMovie)
     
    411439    m_isDrmProtected = false;
    412440    m_isDrmAuthorized = true;
     441
     442
    413443    m_mediaSource = MediaSource();
     444
    414445        [(CIImage *)m_primaryRenderingCIImage release];
    415446        m_primaryRenderingCIImage = 0;
    416447    delete m_QImagePixelBuffer;
    417448    m_QImagePixelBuffer = 0;
     449
     450
     451
    418452}
    419453
     
    525559{
    526560    PhononAutoReleasePool pool;
    527     unsetVideo();
     561    unsetCurrentMediaSource();
     562
    528563    m_mediaSource = mediaSource;
    529564    if (mediaSource.type() == MediaSource::Empty || mediaSource.type() == MediaSource::Invalid){
     
    531566        return;
    532567    }
     568
    533569    openMovieFromCurrentMediaSource();
    534570    if (errorOccured()){
    535         unsetVideo();
    536         return;
    537     }
    538 
     571        unsetCurrentMediaSource();
     572        return;
     573    }
     574
     575    prepareCurrentMovieForPlayback();
     576}
     577
     578void QuickTimeVideoPlayer::prepareCurrentMovieForPlayback()
     579{
    539580#ifdef QUICKTIME_C_API_AVAILABLE
    540581    if (m_visualContext)
     
    544585    waitStatePlayable();
    545586    if (errorOccured()){
    546         unsetVideo();
     587        unset();
    547588        return;
    548589    }
     
    551592    preRollMovie();
    552593    if (errorOccured()){
    553         unsetVideo();
     594        unset();
    554595        return;
    555596    }
     
    558599        m_playbackRate = prefferedPlaybackRate();
    559600    checkIfVideoAwailable();
     601
    560602    enableAudio(m_audioEnabled);
    561603    setMute(m_mute);
    562604    setVolume(m_masterVolume, m_relativeVolume);
     605
    563606    pause();
    564607}
     
    574617        break;
    575618    case MediaSource::Disc:
    576         CASE_UNSUPPORTED("Could not open media source.", FATAL_ERROR)
     619       
    577620        break;
    578621    case MediaSource::Stream:
     
    636679    // codecs *think* they can decode the stream, and crash...
    637680#define TryOpenMovieWithCodec(type) gClearError(); \
    638     openMovieFromData(data, "."type); \
     681    openMovieFromData(data, "."type); \
    639682    if (m_QTMovie) return;
    640683
     
    676719}
    677720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
     744
     745
     746
     747
     748
     749
     750
     751
     752
     753
     754
     755
     756
     757
     758
     759
     760
     761
     762
     763
     764
    678765MediaSource QuickTimeVideoPlayer::mediaSource() const
    679766{
     
    719806        PhononAutoReleasePool pool;
    720807    return [[m_QTMovie attributeForKey:@"QTMovieTimeScaleAttribute"] longValue];
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
    721846}
    722847
     
    9511076}
    9521077
     1078
     1079
     1080
     1081
     1082
     1083
     1084
     1085
     1086
     1087
     1088
     1089
     1090
     1091
     1092
     1093
     1094
     1095
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
     1113
     1114
     1115
     1116
     1117
     1118
     1119
     1120
     1121
     1122
     1123
     1124
     1125
     1126
     1127
     1128
     1129
     1130
     1131
     1132
     1133
     1134
     1135
     1136
     1137
     1138
     1139
     1140
     1141
     1142
     1143
     1144
     1145
     1146
     1147
     1148
     1149
     1150
     1151
     1152
     1153
     1154
     1155
     1156
     1157
     1158
     1159
     1160
     1161
     1162
     1163
     1164
     1165
    9531166}}
    9541167
  • trunk/src/3rdparty/phonon/qt7/videoframe.mm

    r2 r561  
    2020#import <QuartzCore/CIFilter.h>
    2121#import <QuartzCore/CIContext.h>
     22
     23
    2224
    2325QT_BEGIN_NAMESPACE
     
    7173    void VideoFrame::copyMembers(const VideoFrame& frame)
    7274    {
     75
    7376        m_cachedCVTextureRef = frame.m_cachedCVTextureRef;
     77
    7478                m_cachedCIImage = frame.m_cachedCIImage;
    7579                m_cachedQImage = frame.m_cachedQImage;
     
    106110    CVOpenGLTextureRef VideoFrame::cachedCVTexture() const
    107111    {
     112
    108113        if (!m_cachedCVTextureRef && m_videoPlayer){
    109114            m_videoPlayer->setColors(m_brightness, m_contrast, m_hue, m_saturation);
    110115            (const_cast<VideoFrame *>(this))->m_cachedCVTextureRef = m_videoPlayer->currentFrameAsCVTexture();
     116
    111117        }
    112118        return m_cachedCVTextureRef;
     119
     120
     121
     122
     123
     124
     125
    113126    }
    114127
     
    330343    void VideoFrame::invalidateImage() const
    331344    {
     345
    332346        if (m_cachedCVTextureRef){
    333347            CVOpenGLTextureRelease(m_cachedCVTextureRef);
    334348            (const_cast<VideoFrame *>(this))->m_cachedCVTextureRef = 0;
    335349        }
     350
    336351        if (m_cachedCIImage){
    337352                        [(CIImage *) m_cachedCIImage release];
     
    347362    void VideoFrame::retain() const
    348363    {
     364
    349365        if (m_cachedCVTextureRef)
    350366            CVOpenGLTextureRetain(m_cachedCVTextureRef);
     367
    351368                if (m_cachedCIImage)
    352369                        [(CIImage *) m_cachedCIImage retain];
     
    359376    void VideoFrame::release() const
    360377    {
    361         if (m_cachedCVTextureRef)
     378#ifdef CACHE_CV_TEXTURE
     379        if (m_cachedCVTextureRef){
    362380            CVOpenGLTextureRelease(m_cachedCVTextureRef);
     381
     382
     383
    363384                if (m_cachedCIImage)
    364385                        [(CIImage *) m_cachedCIImage release];
     
    369390
    370391        (const_cast<VideoFrame *>(this))->m_backgroundFrame = 0;
    371         (const_cast<VideoFrame *>(this))->m_cachedCVTextureRef = 0;
    372392        (const_cast<VideoFrame *>(this))->m_cachedCIImage = 0;
    373393        (const_cast<VideoFrame *>(this))->m_cachedNSBitmap = 0;
Note: See TracChangeset for help on using the changeset viewer.