2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Collabora Ltd. All rights reserved.
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2009, 2010 Igalia S.L
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * aint with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #ifndef MediaPlayerPrivateGStreamer_h
24 #define MediaPlayerPrivateGStreamer_h
25 #if ENABLE(VIDEO) && USE(GSTREAMER)
27 #include "GRefPtrGStreamer.h"
28 #include "MediaPlayerPrivate.h"
33 #include <wtf/Forward.h>
35 #if ENABLE(TIZEN_AUDIO_SESSION_MANAGER)
36 #include "AudioSessionManagerGStreamerTizen.h"
39 typedef struct _WebKitVideoSink WebKitVideoSink;
40 typedef struct _GstBuffer GstBuffer;
41 typedef struct _GstMessage GstMessage;
42 typedef struct _GstElement GstElement;
46 class GraphicsContext;
49 class GStreamerGWorld;
50 class MediaPlayerPrivateGStreamer;
51 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
52 class VideoLayerTizen;
53 #endif // ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
55 class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface
59 ~MediaPlayerPrivateGStreamer();
60 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
61 MediaPlayer* player() { return m_player; }
62 KURL url() { return m_url; }
64 static void registerMediaEngine(MediaEngineRegistrar);
65 gboolean handleMessage(GstMessage*);
67 IntSize naturalSize() const;
68 bool hasVideo() const { return m_hasVideo; }
69 bool hasAudio() const { return m_hasAudio; }
71 void load(const String &url);
82 float duration() const;
83 float currentTime() const;
87 void setPreservesPitch(bool);
89 void setVolume(float);
91 void notifyPlayerOfVolumeChange();
93 bool supportsMuting() const;
96 void notifyPlayerOfMute();
98 void setPreload(MediaPlayer::Preload);
99 void fillTimerFired(Timer<MediaPlayerPrivateGStreamer>*);
101 MediaPlayer::NetworkState networkState() const;
102 MediaPlayer::ReadyState readyState() const;
104 PassRefPtr<TimeRanges> buffered() const;
105 float maxTimeSeekable() const;
106 bool didLoadingProgress() const;
107 unsigned totalBytes() const;
109 void setVisible(bool);
110 void setSize(const IntSize&);
112 void loadStateChanged();
116 void durationChanged();
117 void loadingFailed(MediaPlayer::NetworkState);
118 void triggerRepaint(GstBuffer*);
120 void paint(GraphicsContext*, const IntRect&);
122 bool hasSingleSecurityOrigin() const;
124 bool supportsFullscreen() const;
125 PlatformMedia platformMedia() const;
129 void notifyPlayerOfVideo();
130 void notifyPlayerOfAudio();
132 void sourceChanged();
134 unsigned decodedFrameCount() const;
135 unsigned droppedFrameCount() const;
136 unsigned audioDecodedByteCount() const;
137 unsigned videoDecodedByteCount() const;
139 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
140 // whether accelerated rendering is supported by the media engine for the current media.
141 virtual bool supportsAcceleratedRendering() const;
142 // called when the rendering system flips the into or out of accelerated rendering mode.
143 virtual void acceleratedRenderingStateChanged() { }
144 // Const-casting here is safe, since all of TextureMapperPlatformLayer's functions are const.g
145 virtual PlatformLayer* platformLayer() const;
147 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !USE(TIZEN_GSTREAMER_VIDEO_SET_SINK)
148 void xWindowIdPrepared(GstMessage*);
149 #if USE(ACCELERATED_VIDEO_VAAPI)
150 IntSize scaleHDVideoToDisplaySize(int videoWidth, int videoHeight, int displayWidth, int displayHeight) const;
152 virtual void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
153 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
154 #endif // ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
156 #if ENABLE(TIZEN_WEBKIT2_PROXY)
157 void setProxy(GstElement* source);
160 MediaPlayer::MovieLoadType movieLoadType() const;
162 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
163 virtual void suspend();
164 virtual void resume();
168 MediaPlayerPrivateGStreamer(MediaPlayer*);
170 static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
172 static void getSupportedTypes(HashSet<String>&);
173 static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs, const KURL&);
175 static bool isAvailable();
177 void updateAudioSink();
178 void createAudioSink();
180 float playbackPosition() const;
182 void cacheDuration();
184 float maxTimeLoaded() const;
186 void createGSTPlayBin();
187 bool changePipelineState(GstState state);
189 bool loadNextLocation();
190 void mediaLocationChanged(GstMessage*);
192 void setDownloadBuffering();
193 void processBufferingStats(GstMessage*);
195 virtual String engineDescription() const { return "GStreamer"; }
196 bool isLiveStream() const { return m_isStreaming; }
198 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
199 GstElement* createVideoSink();
200 bool isLocalMediaStream();
204 MediaPlayer* m_player;
205 GRefPtr<GstElement> m_playBin;
206 GstElement* m_webkitVideoSink;
207 GstElement* m_videoSinkBin;
208 GstElement* m_fpsSink;
209 GRefPtr<GstElement> m_source;
214 MediaPlayer::NetworkState m_networkState;
215 MediaPlayer::ReadyState m_readyState;
216 mutable bool m_isStreaming;
219 GstStructure* m_mediaLocations;
220 int m_mediaLocationCurrentIndex;
221 bool m_resetPipeline;
225 float m_playbackRate;
227 gfloat m_mediaDuration;
228 bool m_startedBuffering;
229 Timer<MediaPlayerPrivateGStreamer> m_fillTimer;
230 float m_maxTimeLoaded;
231 int m_bufferingPercentage;
232 MediaPlayer::Preload m_preload;
234 bool m_mediaDurationKnown;
235 mutable float m_maxTimeLoadedAtLastDidLoadingProgress;
236 RefPtr<GStreamerGWorld> m_gstGWorld;
237 guint m_volumeTimerHandler;
238 guint m_muteTimerHandler;
239 bool m_volumeAndMuteInitialized;
242 guint m_audioTimerHandler;
243 guint m_videoTimerHandler;
244 GRefPtr<GstElement> m_webkitAudioSink;
245 mutable long m_totalBytes;
246 GRefPtr<GstPad> m_videoSinkPad;
247 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
248 OwnPtr<VideoLayerTizen> m_videoLayer;
249 #if USE(ACCELERATED_VIDEO_VAAPI)
250 IntSize m_displaySize;
252 #endif // ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
254 mutable IntSize m_videoSize;
255 #if ENABLE(TIZEN_AUDIO_SESSION_MANAGER)
256 RefPtr<AudioSessionManagerGStreamerTizen> m_audioSessionManager;
260 bool m_originalPreloadWasAutoAndWasOverridden;
261 bool m_preservesPitch;
263 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
268 guint m_playerDeferredState;
272 #endif // USE(GSTREAMER)