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