1/* 2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 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 GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18*/ 19 20#ifndef MediaPlayerPrivateQt_h 21#define MediaPlayerPrivateQt_h 22 23#include "MediaPlayerPrivate.h" 24 25#include <QAbstractVideoSurface> 26#include <QMediaPlayer> 27#include <QObject> 28#include <QVideoSurfaceFormat> 29 30QT_BEGIN_NAMESPACE 31class QMediaPlayerControl; 32class QGraphicsVideoItem; 33class QGraphicsScene; 34QT_END_NAMESPACE 35 36#if USE(ACCELERATED_COMPOSITING) 37#include "TextureMapperPlatformLayer.h" 38#endif 39 40namespace WebCore { 41 42class MediaPlayerPrivateQt : public QAbstractVideoSurface, public MediaPlayerPrivateInterface 43#if USE(ACCELERATED_COMPOSITING) 44 , public TextureMapperPlatformLayer 45#endif 46{ 47 48 Q_OBJECT 49 50public: 51 static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*); 52 ~MediaPlayerPrivateQt(); 53 54 static void registerMediaEngine(MediaEngineRegistrar); 55 static void getSupportedTypes(HashSet<String>&); 56 static MediaPlayer::SupportsType supportsType(const String&, const String&, const KURL&); 57 static bool isAvailable() { return true; } 58 59 bool hasVideo() const; 60 bool hasAudio() const; 61 62 void load(const String &url); 63 void commitLoad(const String& url); 64 void resumeLoad(); 65 void cancelLoad(); 66 67 void play(); 68 void pause(); 69 void prepareToPlay(); 70 71 bool paused() const; 72 bool seeking() const; 73 74 float duration() const; 75 float currentTime() const; 76 void seek(float); 77 78 void setRate(float); 79 void setVolume(float); 80 81 bool supportsMuting() const; 82 void setMuted(bool); 83 84 void setPreload(MediaPlayer::Preload); 85 86 MediaPlayer::NetworkState networkState() const; 87 MediaPlayer::ReadyState readyState() const; 88 89 PassRefPtr<TimeRanges> buffered() const; 90 float maxTimeSeekable() const; 91 bool didLoadingProgress() const; 92 unsigned totalBytes() const; 93 94 void setVisible(bool); 95 96 IntSize naturalSize() const; 97 void setSize(const IntSize&); 98 99 void paint(GraphicsContext*, const IntRect&); 100 // reimplemented for canvas drawImage(HTMLVideoElement) 101 void paintCurrentFrameInContext(GraphicsContext*, const IntRect&); 102 103 bool supportsFullscreen() const { return true; } 104 105#if USE(ACCELERATED_COMPOSITING) 106 // whether accelerated rendering is supported by the media engine for the current media. 107 virtual bool supportsAcceleratedRendering() const { return false; } 108 // called when the rendering system flips the into or out of accelerated rendering mode. 109 virtual void acceleratedRenderingStateChanged() { } 110 // Const-casting here is safe, since all of TextureMapperPlatformLayer's functions are const.g 111 virtual PlatformLayer* platformLayer() const { return 0; } 112 virtual void paintToTextureMapper(TextureMapper*, const FloatRect& targetRect, const TransformationMatrix&, float opacity); 113#endif 114 115 virtual PlatformMedia platformMedia() const; 116 117 QMediaPlayer* mediaPlayer() const { return m_mediaPlayer; } 118 void removeVideoItem(); 119 void restoreVideoItem(); 120 121 // QAbstractVideoSurface methods 122 virtual bool start(const QVideoSurfaceFormat& format); 123 virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; 124 virtual bool present(const QVideoFrame& frame); 125 126private Q_SLOTS: 127 void mediaStatusChanged(QMediaPlayer::MediaStatus); 128 void handleError(QMediaPlayer::Error); 129 void stateChanged(QMediaPlayer::State); 130 void surfaceFormatChanged(const QVideoSurfaceFormat&); 131 void positionChanged(qint64); 132 void durationChanged(qint64); 133 void bufferStatusChanged(int); 134 void volumeChanged(int); 135 void mutedChanged(bool); 136 137private: 138 void updateStates(); 139 140 virtual String engineDescription() const { return "Qt"; } 141 142private: 143 MediaPlayerPrivateQt(MediaPlayer*); 144 145 MediaPlayer* m_webCorePlayer; 146 QMediaPlayer* m_mediaPlayer; 147 QMediaPlayerControl* m_mediaPlayerControl; 148 QVideoSurfaceFormat m_frameFormat; 149 QVideoFrame m_currentVideoFrame; 150 151 mutable MediaPlayer::NetworkState m_networkState; 152 mutable MediaPlayer::ReadyState m_readyState; 153 154 IntSize m_currentSize; 155 IntSize m_naturalSize; 156 bool m_isVisible; 157 bool m_isSeeking; 158 bool m_composited; 159 MediaPlayer::Preload m_preload; 160 mutable unsigned m_bytesLoadedAtLastDidLoadingProgress; 161 bool m_delayingLoad; 162 String m_mediaUrl; 163 bool m_suppressNextPlaybackChanged; 164 165}; 166} 167 168#endif // MediaPlayerPrivateQt_h 169