Add murphy support to audio session manager.
[platform/framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / gstreamer / MediaPlayerPrivateGStreamer.h
1 /*
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
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef MediaPlayerPrivateGStreamer_h
24 #define MediaPlayerPrivateGStreamer_h
25 #if ENABLE(VIDEO) && USE(GSTREAMER)
26
27 #include "GRefPtrGStreamer.h"
28 #include "MediaPlayerPrivate.h"
29 #include "Timer.h"
30
31 #include <glib.h>
32 #include <gst/gst.h>
33 #include <wtf/Forward.h>
34
35 #if ENABLE(TIZEN_AUDIO_SESSION_MANAGER)
36 #include "AudioSessionManagerGStreamerTizen.h"
37 #endif
38
39 typedef struct _WebKitVideoSink WebKitVideoSink;
40 typedef struct _GstBuffer GstBuffer;
41 typedef struct _GstMessage GstMessage;
42 typedef struct _GstElement GstElement;
43
44 namespace WebCore {
45
46 class GraphicsContext;
47 class IntSize;
48 class IntRect;
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)
54
55 class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface
56 {
57
58         public:
59             ~MediaPlayerPrivateGStreamer();
60 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
61             MediaPlayer* player() { return m_player; }
62             KURL url() { return m_url; }
63 #endif
64             static void registerMediaEngine(MediaEngineRegistrar);
65             gboolean handleMessage(GstMessage*);
66
67             IntSize naturalSize() const;
68             bool hasVideo() const { return m_hasVideo; }
69             bool hasAudio() const { return m_hasAudio; }
70
71             void load(const String &url);
72             void commitLoad();
73             void cancelLoad();
74
75             void prepareToPlay();
76             void play();
77             void pause();
78
79             bool paused() const;
80             bool seeking() const;
81
82             float duration() const;
83             float currentTime() const;
84             void seek(float);
85
86             void setRate(float);
87             void setPreservesPitch(bool);
88
89             void setVolume(float);
90             void volumeChanged();
91             void notifyPlayerOfVolumeChange();
92
93             bool supportsMuting() const;
94             void setMuted(bool);
95             void muteChanged();
96             void notifyPlayerOfMute();
97
98             void setPreload(MediaPlayer::Preload);
99             void fillTimerFired(Timer<MediaPlayerPrivateGStreamer>*);
100
101             MediaPlayer::NetworkState networkState() const;
102             MediaPlayer::ReadyState readyState() const;
103
104             PassRefPtr<TimeRanges> buffered() const;
105             float maxTimeSeekable() const;
106             bool didLoadingProgress() const;
107             unsigned totalBytes() const;
108
109             void setVisible(bool);
110             void setSize(const IntSize&);
111
112             void loadStateChanged();
113             void sizeChanged();
114             void timeChanged();
115             void didEnd();
116             void durationChanged();
117             void loadingFailed(MediaPlayer::NetworkState);
118             void triggerRepaint(GstBuffer*);
119             void repaint();
120             void paint(GraphicsContext*, const IntRect&);
121
122             bool hasSingleSecurityOrigin() const;
123
124             bool supportsFullscreen() const;
125             PlatformMedia platformMedia() const;
126
127             void videoChanged();
128             void audioChanged();
129             void notifyPlayerOfVideo();
130             void notifyPlayerOfAudio();
131
132             void sourceChanged();
133
134             unsigned decodedFrameCount() const;
135             unsigned droppedFrameCount() const;
136             unsigned audioDecodedByteCount() const;
137             unsigned videoDecodedByteCount() const;
138
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;
146
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;
151 #endif
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)
155
156 #if ENABLE(TIZEN_WEBKIT2_PROXY)
157             void setProxy(GstElement* source);
158 #endif
159
160             MediaPlayer::MovieLoadType movieLoadType() const;
161
162 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
163             virtual void suspend();
164             virtual void resume();
165 #endif
166
167         private:
168             MediaPlayerPrivateGStreamer(MediaPlayer*);
169
170             static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
171
172             static void getSupportedTypes(HashSet<String>&);
173             static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs, const KURL&);
174
175             static bool isAvailable();
176
177             void updateAudioSink();
178             void createAudioSink();
179
180             float playbackPosition() const;
181
182             void cacheDuration();
183             void updateStates();
184             float maxTimeLoaded() const;
185
186             void createGSTPlayBin();
187             bool changePipelineState(GstState state);
188
189             bool loadNextLocation();
190             void mediaLocationChanged(GstMessage*);
191
192             void setDownloadBuffering();
193             void processBufferingStats(GstMessage*);
194
195             virtual String engineDescription() const { return "GStreamer"; }
196             bool isLiveStream() const { return m_isStreaming; }
197
198 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
199             GstElement* createVideoSink();
200             bool isLocalMediaStream();
201 #endif
202
203         private:
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;
210             float m_seekTime;
211             bool m_changingRate;
212             float m_endTime;
213             bool m_isEndReached;
214             MediaPlayer::NetworkState m_networkState;
215             MediaPlayer::ReadyState m_readyState;
216             mutable bool m_isStreaming;
217             IntSize m_size;
218             GstBuffer* m_buffer;
219             GstStructure* m_mediaLocations;
220             int m_mediaLocationCurrentIndex;
221             bool m_resetPipeline;
222             bool m_paused;
223             bool m_seeking;
224             bool m_buffering;
225             float m_playbackRate;
226             bool m_errorOccured;
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;
233             bool m_delayingLoad;
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;
240             bool m_hasVideo;
241             bool m_hasAudio;
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;
251 #endif
252 #endif // ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
253
254             mutable IntSize m_videoSize;
255 #if ENABLE(TIZEN_AUDIO_SESSION_MANAGER)
256             RefPtr<AudioSessionManagerGStreamerTizen> m_audioSessionManager;
257 #endif
258
259             KURL m_url;
260             bool m_originalPreloadWasAutoAndWasOverridden;
261             bool m_preservesPitch;
262
263 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
264             float m_suspendTime;
265 #endif
266     };
267 }
268
269 #endif // USE(GSTREAMER)
270 #endif