initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / qt / MediaPlayerPrivateQt.h
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 <QMediaPlayer>
26 #include <QObject>
27
28 QT_BEGIN_NAMESPACE
29 class QMediaPlayerControl;
30 class QGraphicsVideoItem;
31 class QGraphicsScene;
32 QT_END_NAMESPACE
33
34 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
35 #include "TextureMapper.h"
36 #endif
37
38 namespace WebCore {
39
40 class MediaPlayerPrivateQt : public QObject, public MediaPlayerPrivateInterface
41 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
42         , public TextureMapperPlatformLayer
43 #endif
44 {
45
46     Q_OBJECT
47
48 public:
49     static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
50     ~MediaPlayerPrivateQt();
51
52     static void registerMediaEngine(MediaEngineRegistrar);
53     static void getSupportedTypes(HashSet<String>&);
54     static MediaPlayer::SupportsType supportsType(const String&, const String&);
55     static bool isAvailable() { return true; }
56
57     bool hasVideo() const;
58     bool hasAudio() const;
59
60     void load(const String &url);
61     void commitLoad(const String& url);
62     void resumeLoad();
63     void cancelLoad();
64
65     void play();
66     void pause();
67     void prepareToPlay();
68
69     bool paused() const;
70     bool seeking() const;
71
72     float duration() const;
73     float currentTime() const;
74     void seek(float);
75
76     void setRate(float);
77     void setVolume(float);
78
79     bool supportsMuting() const;
80     void setMuted(bool);
81
82     void setPreload(MediaPlayer::Preload);
83
84     MediaPlayer::NetworkState networkState() const;
85     MediaPlayer::ReadyState readyState() const;
86
87     PassRefPtr<TimeRanges> buffered() const;
88     float maxTimeSeekable() const;
89     unsigned bytesLoaded() const;
90     unsigned totalBytes() const;
91
92     void setVisible(bool);
93
94     IntSize naturalSize() const;
95     void setSize(const IntSize&);
96
97     void paint(GraphicsContext*, const IntRect&);
98     // reimplemented for canvas drawImage(HTMLVideoElement)
99     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
100
101     bool supportsFullscreen() const { return true; }
102
103 #if USE(ACCELERATED_COMPOSITING)
104 #if USE(TEXTURE_MAPPER)
105     // whether accelerated rendering is supported by the media engine for the current media.
106     virtual bool supportsAcceleratedRendering() const { return false; }
107     // called when the rendering system flips the into or out of accelerated rendering mode.
108     virtual void acceleratedRenderingStateChanged() { }
109     // Const-casting here is safe, since all of TextureMapperPlatformLayer's functions are const.g
110     virtual PlatformLayer* platformLayer() const { return 0; }
111     virtual void paintToTextureMapper(TextureMapper*, const FloatRect& targetRect, const TransformationMatrix&, float opacity, BitmapTexture* mask) const;
112 #else
113     virtual bool supportsAcceleratedRendering() const { return false; }
114     virtual void acceleratedRenderingStateChanged() { }
115     virtual PlatformLayer* platformLayer() const { return 0; }
116 #endif
117 #endif
118
119     virtual PlatformMedia platformMedia() const;
120
121     QMediaPlayer* mediaPlayer() const { return m_mediaPlayer; }
122     void removeVideoItem();
123     void restoreVideoItem();
124
125 private slots:
126     void mediaStatusChanged(QMediaPlayer::MediaStatus);
127     void handleError(QMediaPlayer::Error);
128     void stateChanged(QMediaPlayer::State);
129     void nativeSizeChanged(const QSizeF&);
130     void positionChanged(qint64);
131     void durationChanged(qint64);
132     void bufferStatusChanged(int);
133     void volumeChanged(int);
134     void mutedChanged(bool);
135     void repaint();
136
137 private:
138     void updateStates();
139
140 private:
141     MediaPlayerPrivateQt(MediaPlayer*);
142
143     MediaPlayer* m_webCorePlayer;
144     QMediaPlayer* m_mediaPlayer;
145     QMediaPlayerControl* m_mediaPlayerControl;
146     QGraphicsVideoItem* m_videoItem;
147     QGraphicsScene* m_videoScene;
148
149     mutable MediaPlayer::NetworkState m_networkState;
150     mutable MediaPlayer::ReadyState m_readyState;
151
152     IntSize m_currentSize;
153     IntSize m_naturalSize;
154     IntSize m_oldNaturalSize;
155     bool m_isVisible;
156     bool m_isSeeking;
157     bool m_composited;
158     MediaPlayer::Preload m_preload;
159     bool m_delayingLoad;
160     String m_mediaUrl;
161     bool m_suppressNextPlaybackChanged;
162
163 };
164 }
165
166 #endif // MediaPlayerPrivateQt_h