• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 USE(GSTREAMER)
26 
27 #include <wtf/Forward.h>
28 #include "MediaPlayerPrivate.h"
29 #include "Timer.h"
30 
31 #include <glib.h>
32 #include <gst/gst.h>
33 
34 typedef struct _WebKitVideoSink WebKitVideoSink;
35 typedef struct _GstBuffer GstBuffer;
36 typedef struct _GstMessage GstMessage;
37 typedef struct _GstElement GstElement;
38 
39 namespace WebCore {
40 
41 class GraphicsContext;
42 class IntSize;
43 class IntRect;
44 class GStreamerGWorld;
45 class MediaPlayerPrivateGStreamer;
46 
47 class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface {
48 
49         public:
50             static void registerMediaEngine(MediaEngineRegistrar);
51             gboolean handleMessage(GstMessage*);
52 
53             IntSize naturalSize() const;
hasVideo()54             bool hasVideo() const { return m_hasVideo; }
hasAudio()55             bool hasAudio() const { return m_hasAudio; }
56 
57             void load(const String &url);
58             void commitLoad();
59             void cancelLoad();
60 
61             void prepareToPlay();
62             void play();
63             void pause();
64 
65             bool paused() const;
66             bool seeking() const;
67 
68             float duration() const;
69             float currentTime() const;
70             void seek(float);
71 
72             void setRate(float);
73 
74             void setVolume(float);
75             void volumeChanged();
76             void notifyPlayerOfVolumeChange();
77 
78             bool supportsMuting() const;
79             void setMuted(bool);
80             void muteChanged();
81             void notifyPlayerOfMute();
82 
83             void setPreload(MediaPlayer::Preload);
84             void fillTimerFired(Timer<MediaPlayerPrivateGStreamer>*);
85 
86             MediaPlayer::NetworkState networkState() const;
87             MediaPlayer::ReadyState readyState() const;
88 
89             PassRefPtr<TimeRanges> buffered() const;
90             float maxTimeSeekable() const;
91             unsigned bytesLoaded() const;
92             unsigned totalBytes() const;
93 
94             void setVisible(bool);
95             void setSize(const IntSize&);
96 
97             void loadStateChanged();
98             void sizeChanged();
99             void timeChanged();
100             void didEnd();
101             void durationChanged();
102             void loadingFailed(MediaPlayer::NetworkState);
103 
104             void triggerRepaint(GstBuffer*);
105             void repaint();
106             void paint(GraphicsContext*, const IntRect&);
107 
108             bool hasSingleSecurityOrigin() const;
109 
110             bool supportsFullscreen() const;
111             PlatformMedia platformMedia() const;
112 
113             void videoChanged();
114             void audioChanged();
115             void notifyPlayerOfVideo();
116             void notifyPlayerOfAudio();
117 
118             void sourceChanged();
119 
120             unsigned decodedFrameCount() const;
121             unsigned droppedFrameCount() const;
122             unsigned audioDecodedByteCount() const;
123             unsigned videoDecodedByteCount() const;
124 
125         private:
126             MediaPlayerPrivateGStreamer(MediaPlayer*);
127             ~MediaPlayerPrivateGStreamer();
128 
129             static MediaPlayerPrivateInterface* create(MediaPlayer* player);
130 
131             static void getSupportedTypes(HashSet<String>&);
132             static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs);
133             static bool isAvailable();
134 
135             void updateAudioSink();
136 
137             float playbackPosition() const;
138 
139             void cacheDuration();
140             void updateStates();
141             float maxTimeLoaded() const;
142 
143             void createGSTPlayBin();
144             bool changePipelineState(GstState state);
145 
146             bool loadNextLocation();
147             void mediaLocationChanged(GstMessage*);
148 
149             void processBufferingStats(GstMessage*);
150 
151         private:
152             MediaPlayer* m_player;
153             GstElement* m_playBin;
154             GstElement* m_webkitVideoSink;
155             GstElement* m_videoSinkBin;
156             GstElement* m_fpsSink;
157             GstElement* m_source;
158             float m_seekTime;
159             bool m_changingRate;
160             float m_endTime;
161             bool m_isEndReached;
162             MediaPlayer::NetworkState m_networkState;
163             MediaPlayer::ReadyState m_readyState;
164             mutable bool m_isStreaming;
165             IntSize m_size;
166             GstBuffer* m_buffer;
167             GstStructure* m_mediaLocations;
168             int m_mediaLocationCurrentIndex;
169             bool m_resetPipeline;
170             bool m_paused;
171             bool m_seeking;
172             bool m_buffering;
173             float m_playbackRate;
174             bool m_errorOccured;
175             gfloat m_mediaDuration;
176             bool m_startedBuffering;
177             Timer<MediaPlayerPrivateGStreamer> m_fillTimer;
178             float m_maxTimeLoaded;
179             int m_bufferingPercentage;
180             MediaPlayer::Preload m_preload;
181             bool m_delayingLoad;
182             bool m_mediaDurationKnown;
183             RefPtr<GStreamerGWorld> m_gstGWorld;
184             guint m_volumeTimerHandler;
185             guint m_muteTimerHandler;
186             bool m_hasVideo;
187             bool m_hasAudio;
188             guint m_audioTimerHandler;
189             guint m_videoTimerHandler;
190             GstElement* m_webkitAudioSink;
191     };
192 }
193 
194 #endif // USE(GSTREAMER)
195 #endif
196