2008-03-11 Tor Arne Vestbø <tavestbo@trolltech.com>
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Mar 2008 14:59:58 +0000 (14:59 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Mar 2008 14:59:58 +0000 (14:59 +0000)
        Reviewed by Darin.

        Implemented HTML media element support for QtWebKit, using Phonon.

        http://bugs.webkit.org/show_bug.cgi?id=17766

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30960 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.pro
WebCore/platform/graphics/MediaPlayer.cpp
WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp [new file with mode: 0644]
WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h [new file with mode: 0644]

index d88ce46..55c4cae 100644 (file)
@@ -1,3 +1,69 @@
+2008-03-11  Tor Arne Vestbø  <tavestbo@trolltech.com>
+
+        Reviewed by Darin.
+
+        Implemented HTML media element support for QtWebKit, using Phonon.
+
+        http://bugs.webkit.org/show_bug.cgi?id=17766
+
+        * WebCore.pro:
+        * platform/graphics/MediaPlayer.cpp:
+        * platform/graphics/qt/MediaPlayerPrivatePhonon.cpp: Added.
+        (debugMediaObject):
+        (WebCore::MediaPlayerPrivate::MediaPlayerPrivate):
+        (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
+        (WebCore::MediaPlayerPrivate::getSupportedTypes):
+        (WebCore::MediaPlayerPrivate::hasVideo):
+        (WebCore::MediaPlayerPrivate::load):
+        (WebCore::MediaPlayerPrivate::cancelLoad):
+        (WebCore::MediaPlayerPrivate::play):
+        (WebCore::MediaPlayerPrivate::pause):
+        (WebCore::MediaPlayerPrivate::paused):
+        (WebCore::MediaPlayerPrivate::seek):
+        (WebCore::MediaPlayerPrivate::seeking):
+        (WebCore::MediaPlayerPrivate::duration):
+        (WebCore::MediaPlayerPrivate::currentTime):
+        (WebCore::MediaPlayerPrivate::setEndTime):
+        (WebCore::MediaPlayerPrivate::maxTimeBuffered):
+        (WebCore::MediaPlayerPrivate::maxTimeSeekable):
+        (WebCore::MediaPlayerPrivate::bytesLoaded):
+        (WebCore::MediaPlayerPrivate::totalBytesKnown):
+        (WebCore::MediaPlayerPrivate::totalBytes):
+        (WebCore::MediaPlayerPrivate::setRate):
+        (WebCore::MediaPlayerPrivate::setVolume):
+        (WebCore::MediaPlayerPrivate::setMuted):
+        (WebCore::MediaPlayerPrivate::dataRate):
+        (WebCore::MediaPlayerPrivate::networkState):
+        (WebCore::MediaPlayerPrivate::readyState):
+        (WebCore::MediaPlayerPrivate::updateStates):
+        (WebCore::MediaPlayerPrivate::setVisible):
+        (WebCore::MediaPlayerPrivate::setRect):
+        (WebCore::MediaPlayerPrivate::loadStateChanged):
+        (WebCore::MediaPlayerPrivate::rateChanged):
+        (WebCore::MediaPlayerPrivate::sizeChanged):
+        (WebCore::MediaPlayerPrivate::timeChanged):
+        (WebCore::MediaPlayerPrivate::volumeChanged):
+        (WebCore::MediaPlayerPrivate::didEnd):
+        (WebCore::MediaPlayerPrivate::loadingFailed):
+        (WebCore::MediaPlayerPrivate::naturalSize):
+        (WebCore::MediaPlayerPrivate::eventFilter):
+        (WebCore::MediaPlayerPrivate::repaint):
+        (WebCore::MediaPlayerPrivate::paint):
+        (WebCore::MediaPlayerPrivate::stateChanged):
+        (WebCore::MediaPlayerPrivate::tick):
+        (WebCore::MediaPlayerPrivate::metaDataChanged):
+        (WebCore::MediaPlayerPrivate::seekableChanged):
+        (WebCore::MediaPlayerPrivate::hasVideoChanged):
+        (WebCore::MediaPlayerPrivate::bufferStatus):
+        (WebCore::MediaPlayerPrivate::finished):
+        (WebCore::MediaPlayerPrivate::currentSourceChanged):
+        (WebCore::MediaPlayerPrivate::aboutToFinish):
+        (WebCore::MediaPlayerPrivate::prefinishMarkReached):
+        (WebCore::MediaPlayerPrivate::totalTimeChanged):
+        * platform/graphics/qt/MediaPlayerPrivatePhonon.h: Added.
+        (WebCore::MediaPlayerPrivate::):
+        (WebCore::MediaPlayerPrivate::isAvailable):
+
 2008-03-10  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Beth Dakin.
index 48e7f8a..35368fd 100644 (file)
@@ -76,7 +76,8 @@ gtk-port:!contains(DEFINES, ENABLE_XSLT=.): DEFINES += ENABLE_XSLT=1
 #!contains(DEFINES, ENABLE_XBL=.): DEFINES += ENABLE_XBL=1
 qt-port: !contains(DEFINES, ENABLE_SVG=.): DEFINES += ENABLE_SVG=1
 gtk-port:DEFINES += ENABLE_SVG=0
-DEFINES += ENABLE_VIDEO=0
+qt-port:contains(QT_CONFIG, phonon):DEFINES += ENABLE_VIDEO=1
+else:DEFINES += ENABLE_VIDEO=0
 
 DEFINES += WTF_CHANGES=1
 
@@ -1221,6 +1222,16 @@ contains(DEFINES, ENABLE_VIDEO=1) {
         rendering/RenderMedia.cpp \
         bindings/js/JSAudioConstructor.cpp
 
+    qt-port {
+        HEADERS += \
+            platform/graphics/qt/MediaPlayerPrivatePhonon.h
+
+        SOURCES += \
+            platform/graphics/qt/MediaPlayerPrivatePhonon.cpp
+
+        QT += phonon
+    }
+
     gtk-port {
         SOURCES += \
             platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp \
index 82e9950..3b59cac 100644 (file)
@@ -37,6 +37,8 @@
 #include "MediaPlayerPrivateQuickTimeWin.h"
 #elif PLATFORM(GTK)
 #include "MediaPlayerPrivateGStreamer.h"
+#elif PLATFORM(QT)
+#include "MediaPlayerPrivatePhonon.h"
 #endif
 
 namespace WebCore {
diff --git a/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp b/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp
new file mode 100644 (file)
index 0000000..79af818
--- /dev/null
@@ -0,0 +1,524 @@
+/*
+    Copyright (C) 2008 Trolltech ASA
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "MediaPlayerPrivatePhonon.h"
+
+#include <limits>
+
+#include "CString.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "NotImplemented.h"
+#include "Widget.h"
+#include <wtf/HashSet.h>
+
+#include <QDebug>
+#include <QPainter>
+#include <QWidget>
+#include <phonon>
+
+using namespace Phonon;
+
+#define LOG_MEDIAOBJECT() (LOG(Media,"%s", debugMediaObject(*m_mediaObject).constData()))
+
+static QByteArray debugMediaObject(const MediaObject& mediaObject)
+{
+    QByteArray byteArray;
+    QTextStream stream(&byteArray);
+    
+    const QMetaObject* metaObject = mediaObject.metaObject();
+    QMetaEnum phononStates = metaObject->enumerator(metaObject->indexOfEnumerator("PhononState"));
+
+    stream << "Phonon::MediaObject(";
+    stream << "State:" << phononStates.valueToKey(mediaObject.state());
+    stream << "| Current time:" << mediaObject.currentTime();
+    stream << "| Remaining time:" << mediaObject.remainingTime();
+    stream << "| Total time:" << mediaObject.totalTime();
+    stream << "| Meta-data:";
+    QMultiMap<QString, QString> map = mediaObject.metaData();
+    for (QMap<QString, QString>::const_iterator it = map.constBegin();
+        it != map.constEnd(); ++it) {
+        stream << "(" << it.key() << ", " << it.value() << ")";
+    }
+    stream << "| Has video:" << mediaObject.hasVideo();
+    stream << "| Is seekable:" << mediaObject.isSeekable();
+    stream << ")";
+    
+    stream.flush();
+
+    return byteArray;
+}
+
+using namespace WTF;
+
+namespace WebCore {
+
+MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
+    : m_player(player)
+    , m_networkState(MediaPlayer::Empty)
+    , m_readyState(MediaPlayer::DataUnavailable)
+    , m_mediaObject(new MediaObject())
+    , m_videoWidget(new VideoWidget(0))
+    , m_audioOutput(new AudioOutput())
+    , m_isVisible(false)
+{
+    // Hint to Phonon to disable overlay painting
+    m_videoWidget->setAttribute(Qt::WA_DontShowOnScreen);
+
+    createPath(m_mediaObject, m_videoWidget);
+    createPath(m_mediaObject, m_audioOutput);
+
+    // Make sure we get updates for each frame
+    m_videoWidget->installEventFilter(this);
+    foreach(QWidget* widget, qFindChildren<QWidget*>(m_videoWidget)) {
+        widget->installEventFilter(this);
+    }
+
+    connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
+            this, SLOT(stateChanged(Phonon::State, Phonon::State)));
+    connect(m_mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
+    connect(m_mediaObject, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
+    connect(m_mediaObject, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
+    connect(m_mediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool)));
+    connect(m_mediaObject, SIGNAL(bufferStatus(int)), this, SLOT(bufferStatus(int)));
+    connect(m_mediaObject, SIGNAL(finished()), this, SLOT(finished()));
+    connect(m_mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource&)),
+            this, SLOT(currentSourceChanged(const Phonon::MediaSource&)));
+    connect(m_mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
+    connect(m_mediaObject, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(prefinishMarkReached(qint32)));
+    connect(m_mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
+}
+
+MediaPlayerPrivate::~MediaPlayerPrivate()
+{
+    LOG(Media, "MediaPlayerPrivatePhonon::dtor deleting videowidget");
+    delete m_videoWidget;
+    m_videoWidget = 0;
+
+    LOG(Media, "MediaPlayerPrivatePhonon::dtor deleting audiooutput");
+    delete m_audioOutput;
+    m_audioOutput = 0;
+
+    LOG(Media, "MediaPlayerPrivatePhonon::dtor deleting mediaobject");
+    delete m_mediaObject;
+    m_mediaObject = 0;
+}
+
+void MediaPlayerPrivate::getSupportedTypes(HashSet<String>&)
+{
+    notImplemented();
+}
+
+bool MediaPlayerPrivate::hasVideo() const
+{
+    bool hasVideo = m_mediaObject->hasVideo();
+    LOG(Media, "MediaPlayerPrivatePhonon::hasVideo() -> %s", hasVideo ? "true" : "false");
+    return hasVideo;
+}
+
+void MediaPlayerPrivate::load(String url)
+{
+    LOG(Media, "MediaPlayerPrivatePhonon::load(\"%s\")", url.utf8().data());
+
+    // We are now loading
+    if (m_networkState != MediaPlayer::Loading) {
+        m_networkState = MediaPlayer::Loading;
+        m_player->networkStateChanged();
+    }
+
+    // And we don't have any data yet
+    if (m_readyState != MediaPlayer::DataUnavailable) {
+        m_readyState = MediaPlayer::DataUnavailable;
+        m_player->readyStateChanged();
+    }
+
+    m_mediaObject->setCurrentSource(QUrl(url));
+    m_audioOutput->setVolume(m_player->volume());
+    setVisible(m_player->visible());
+}
+
+void MediaPlayerPrivate::cancelLoad()
+{
+    notImplemented();
+}
+
+
+void MediaPlayerPrivate::play()
+{
+    Q_ASSERT(m_mediaObject);
+
+    LOG(Media, "MediaPlayerPrivatePhonon::play()");
+    m_mediaObject->play();
+}
+
+void MediaPlayerPrivate::pause()
+{
+    Q_ASSERT(m_mediaObject);
+
+    LOG(Media, "MediaPlayerPrivatePhonon::pause()");
+    m_mediaObject->pause();
+}
+
+
+bool MediaPlayerPrivate::paused() const
+{
+    Q_ASSERT(m_mediaObject);
+
+    bool paused = m_mediaObject->state() == Phonon::PausedState;
+    LOG(Media, "MediaPlayerPrivatePhonon::paused() --> %s", paused ? "true" : "false");
+    return paused;
+}
+
+void MediaPlayerPrivate::seek(float)
+{
+    notImplemented();
+}
+
+bool MediaPlayerPrivate::seeking() const
+{
+    notImplemented();
+    return false;
+}
+
+float MediaPlayerPrivate::duration() const
+{
+    Q_ASSERT(m_mediaObject);
+
+    if (m_networkState < MediaPlayer::LoadedMetaData)
+        return 0.0f;
+
+    float duration = m_mediaObject->totalTime() / 1000.0f;
+
+    if (duration == 0.0f) // We are streaming
+        duration = std::numeric_limits<float>::infinity();
+
+    LOG(Media, "MediaPlayerPrivatePhonon::duration() --> %f", duration);
+    return duration;
+}
+
+float MediaPlayerPrivate::currentTime() const
+{
+    Q_ASSERT(m_mediaObject);
+
+    float currentTime = m_mediaObject->currentTime() / 1000.0f;
+
+    LOG(Media, "MediaPlayerPrivatePhonon::currentTime() --> %f", currentTime);
+    return currentTime;
+}
+
+void MediaPlayerPrivate::setEndTime(float endTime)
+{
+    notImplemented();
+}
+
+float MediaPlayerPrivate::maxTimeBuffered() const
+{
+    notImplemented();
+    return 0.0f;
+}
+
+float MediaPlayerPrivate::maxTimeSeekable() const
+{
+    notImplemented();
+    return 0.0f;
+}
+
+unsigned MediaPlayerPrivate::bytesLoaded() const
+{ 
+    notImplemented();
+    return 0;
+}
+
+bool MediaPlayerPrivate::totalBytesKnown() const
+{
+    //notImplemented();
+    return false;
+}
+
+unsigned MediaPlayerPrivate::totalBytes() const
+{
+    //notImplemented();
+    return 0;
+}
+
+void MediaPlayerPrivate::setRate(float)
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::setVolume(float volume)
+{
+    Q_ASSERT(m_audioOutput);
+
+    m_audioOutput->setVolume(volume);
+}
+
+void MediaPlayerPrivate::setMuted(bool muted)
+{
+    Q_ASSERT(m_audioOutput);
+
+    m_audioOutput->setMuted(muted);
+}
+
+
+int MediaPlayerPrivate::dataRate() const
+{
+    notImplemented();
+    return 0;
+}
+
+
+MediaPlayer::NetworkState MediaPlayerPrivate::networkState() const
+{
+    const QMetaObject* metaObj = this->metaObject();
+    QMetaEnum networkStates = metaObj->enumerator(metaObj->indexOfEnumerator("NetworkState"));
+    LOG(Media, "MediaPlayerPrivatePhonon::networkState() --> %s", networkStates.valueToKey(m_networkState));
+    return m_networkState;
+}
+
+MediaPlayer::ReadyState MediaPlayerPrivate::readyState() const
+{
+    const QMetaObject* metaObj = this->metaObject();
+    QMetaEnum readyStates = metaObj->enumerator(metaObj->indexOfEnumerator("ReadyState"));
+    LOG(Media, "MediaPlayerPrivatePhonon::readyState() --> %s", readyStates.valueToKey(m_readyState));
+    return m_readyState;
+}
+
+void MediaPlayerPrivate::updateStates()
+{
+    Q_ASSERT(m_mediaObject);
+
+    MediaPlayer::NetworkState oldNetworkState = m_networkState;
+    MediaPlayer::ReadyState oldReadyState = m_readyState;
+
+    Phonon::State state = m_mediaObject ? m_mediaObject->state() : Phonon::ErrorState;
+
+    if (state == Phonon::StoppedState) {
+        if (oldNetworkState < MediaPlayer::LoadedMetaData) {
+            m_networkState = MediaPlayer::LoadedMetaData;
+            m_readyState = MediaPlayer::DataUnavailable;
+            m_mediaObject->pause();
+        }
+    } else if (state == Phonon::PausedState) {
+        m_networkState = MediaPlayer::LoadedFirstFrame;
+        m_readyState = MediaPlayer::CanPlayThrough;
+    }
+
+    if (seeking())
+        m_readyState = MediaPlayer::DataUnavailable;
+
+    if (m_networkState != oldNetworkState) {
+        const QMetaObject* metaObj = this->metaObject();
+        QMetaEnum networkStates = metaObj->enumerator(metaObj->indexOfEnumerator("NetworkState"));
+        qDebug("Network state changed from '%s' to '%s'",
+                networkStates.valueToKey(oldNetworkState),
+                networkStates.valueToKey(m_networkState));
+        m_player->networkStateChanged();
+    }
+
+    if (m_readyState != oldReadyState) {
+        const QMetaObject* metaObj = this->metaObject();
+        QMetaEnum readyStates = metaObj->enumerator(metaObj->indexOfEnumerator("ReadyState"));
+        qDebug("Ready state changed from '%s' to '%s'",
+                readyStates.valueToKey(oldReadyState),
+                readyStates.valueToKey(m_readyState));
+        m_player->readyStateChanged();
+    }
+}
+
+void MediaPlayerPrivate::setVisible(bool visible)
+{
+    m_isVisible = visible;
+    LOG(Media, "MediaPlayerPrivatePhonon::setVisible(%s)", visible ? "true" : "false");
+
+    m_videoWidget->setVisible(m_isVisible);
+}
+
+void MediaPlayerPrivate::setRect(const IntRect& newRect)
+{
+    if (!m_videoWidget)
+        return;
+
+    LOG(Media, "MediaPlayerPrivatePhonon::setRect(%d,%d %dx%d)",
+                newRect.x(), newRect.y(),
+                newRect.width(), newRect.height());
+
+    QRect currentRect = m_videoWidget->rect();
+
+    if (newRect.width() != currentRect.width() || newRect.height() != currentRect.height())
+        m_videoWidget->resize(newRect.width(), newRect.height());
+}
+
+
+void MediaPlayerPrivate::loadStateChanged() 
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::rateChanged()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::sizeChanged()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::timeChanged()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::volumeChanged()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::didEnd()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::loadingFailed()
+{
+    notImplemented();
+}
+
+IntSize MediaPlayerPrivate::naturalSize() const
+{
+    Q_ASSERT(m_videoWidget);
+
+    if (!hasVideo())
+         return IntSize();
+
+    if (m_networkState < MediaPlayer::LoadedMetaData)
+           return IntSize();
+
+    QSize videoSize = m_videoWidget->sizeHint();
+    IntSize naturalSize(videoSize.width(), videoSize.height());
+    LOG(Media, "MediaPlayerPrivatePhonon::naturalSize() -> %dx%d",
+            naturalSize.width(), naturalSize.height());
+    return naturalSize;
+}
+
+bool MediaPlayerPrivate::eventFilter(QObject* obj, QEvent* event)
+{
+    if (event->type() == QEvent::Paint)
+        m_player->repaint();
+
+    return QObject::eventFilter(obj, event);
+}
+
+void MediaPlayerPrivate::repaint()
+{
+    m_player->repaint();
+}
+
+void MediaPlayerPrivate::paint(GraphicsContext* graphicsContect, const IntRect& rect)
+{
+    Q_ASSERT(m_videoWidget);
+
+    if (graphicsContect->paintingDisabled())
+        return;
+
+    if (!m_isVisible)
+        return;
+
+    //QPainter* painter = static_cast<QPainter*>(graphicsContect->platformContext());
+    QPainter* painter = graphicsContect->platformContext();
+
+    painter->fillRect(rect, Qt::black);
+
+    m_videoWidget->render(painter, QPoint(rect.x(), rect.y()),
+            QRegion(0, 0, rect.width(), rect.height()));
+}
+
+// ====================== Phonon::MediaObject signals ======================
+
+void MediaPlayerPrivate::stateChanged(Phonon::State, Phonon::State)
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+    updateStates();
+}
+
+void MediaPlayerPrivate::tick(qint64)
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivate::metaDataChanged()
+{
+    LOG(Media, "MediaPlayerPrivatePhonon::metaDataChanged()");
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::seekableChanged(bool)
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::hasVideoChanged(bool)
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::bufferStatus(int)
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::finished()
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::currentSourceChanged(const Phonon::MediaSource&)
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::aboutToFinish()
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::prefinishMarkReached(qint32)
+{
+    notImplemented();
+    LOG_MEDIAOBJECT();
+}
+
+void MediaPlayerPrivate::totalTimeChanged(qint64 totalTime)
+{
+    LOG(Media, "MediaPlayerPrivatePhonon::totalTimeChanged(%d)", totalTime);
+    LOG_MEDIAOBJECT();
+}
+
+} // namespace WebCore
+
+#include "moc_MediaPlayerPrivatePhonon.cpp"
diff --git a/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h b/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h
new file mode 100644 (file)
index 0000000..c57170c
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+    Copyright (C) 2008 Trolltech ASA
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef MediaPlayerPrivatePhonon_h
+#define MediaPlayerPrivatePhonon_h
+
+#include "MediaPlayer.h"
+#include <wtf/Noncopyable.h>
+
+#include <QObject>
+#include <phononnamespace.h>
+
+QT_BEGIN_NAMESPACE
+class QWidget;
+class QUrl;
+QT_END_NAMESPACE
+
+namespace Phonon {
+    class MediaObject;
+    class VideoWidget;
+    class AudioOutput;
+    class MediaSource;
+}
+
+namespace WebCore {
+
+    class MediaPlayerPrivate : public QObject, Noncopyable {
+
+        Q_OBJECT
+
+    public:
+        MediaPlayerPrivate(MediaPlayer*);
+        ~MediaPlayerPrivate();
+
+        // These enums are used for debugging
+        Q_ENUMS(ReadyState NetworkState PhononState)
+
+        enum ReadyState {
+            DataUnavailable,
+            CanShowCurrentFrame,
+            CanPlay,
+            CanPlayThrough
+        };
+
+        enum NetworkState {
+            Empty,
+            LoadFailed,
+            Loading,
+            LoadedMetaData,
+            LoadedFirstFrame,
+            Loaded
+        };
+
+        enum PhononState {
+            LoadingState,
+            StoppedState,
+            PlayingState,
+            BufferingState,
+            PausedState,
+            ErrorState
+        };
+
+        IntSize naturalSize() const;
+        bool hasVideo() const;
+
+        void load(String url);
+        void cancelLoad();
+
+        void play();
+        void pause();
+
+        bool paused() const;
+        bool seeking() const;
+
+        float duration() const;
+        float currentTime() const;
+        void seek(float);
+        void setEndTime(float);
+
+        void setRate(float);
+        void setVolume(float);
+        void setMuted(bool);
+
+        int dataRate() const;
+
+        MediaPlayer::NetworkState networkState() const;
+        MediaPlayer::ReadyState readyState() const;
+
+        float maxTimeBuffered() const;
+        float maxTimeSeekable() const;
+        unsigned bytesLoaded() const;
+        bool totalBytesKnown() const;
+        unsigned totalBytes() const;
+
+        void setVisible(bool);
+        void setRect(const IntRect&);
+
+        void loadStateChanged();
+        void rateChanged();
+        void sizeChanged();
+        void timeChanged();
+        void volumeChanged();
+        void didEnd();
+        void loadingFailed();
+
+        void repaint();
+        void paint(GraphicsContext*, const IntRect&);
+        static void getSupportedTypes(HashSet<String>&);
+        static bool isAvailable()   { return true; }
+
+    protected:
+        bool eventFilter(QObject*, QEvent*);
+
+    private slots:
+        void stateChanged(Phonon::State, Phonon::State);
+        void tick(qint64);
+        void metaDataChanged();
+        void seekableChanged(bool);
+        void hasVideoChanged(bool);
+        void bufferStatus(int);
+        void finished();
+        void currentSourceChanged(const Phonon::MediaSource&);
+        void aboutToFinish();
+        void prefinishMarkReached(qint32);
+        void totalTimeChanged(qint64);
+
+    private:
+        void updateStates();
+
+        MediaPlayer* m_player;
+
+        MediaPlayer::NetworkState m_networkState;
+        MediaPlayer::ReadyState m_readyState;
+
+        Phonon::MediaObject* m_mediaObject;
+        Phonon::VideoWidget* m_videoWidget;
+        Phonon::AudioOutput* m_audioOutput;
+
+        bool m_isVisible;
+    };
+}
+
+#endif // MediaPlayerPrivatePhonon_h