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 ~MediaPlayerPrivateGStreamer(); 51 static void registerMediaEngine(MediaEngineRegistrar); 52 gboolean handleMessage(GstMessage*); 53 54 IntSize naturalSize() const; hasVideo()55 bool hasVideo() const { return m_hasVideo; } hasAudio()56 bool hasAudio() const { return m_hasAudio; } 57 58 void load(const String &url); 59 void commitLoad(); 60 void cancelLoad(); 61 62 void prepareToPlay(); 63 void play(); 64 void pause(); 65 66 bool paused() const; 67 bool seeking() const; 68 69 float duration() const; 70 float currentTime() const; 71 void seek(float); 72 73 void setRate(float); 74 75 void setVolume(float); 76 void volumeChanged(); 77 void notifyPlayerOfVolumeChange(); 78 79 bool supportsMuting() const; 80 void setMuted(bool); 81 void muteChanged(); 82 void notifyPlayerOfMute(); 83 84 void setPreload(MediaPlayer::Preload); 85 void fillTimerFired(Timer<MediaPlayerPrivateGStreamer>*); 86 87 MediaPlayer::NetworkState networkState() const; 88 MediaPlayer::ReadyState readyState() const; 89 90 PassRefPtr<TimeRanges> buffered() const; 91 float maxTimeSeekable() const; 92 unsigned bytesLoaded() const; 93 unsigned totalBytes() const; 94 95 void setVisible(bool); 96 void setSize(const IntSize&); 97 98 void loadStateChanged(); 99 void sizeChanged(); 100 void timeChanged(); 101 void didEnd(); 102 void durationChanged(); 103 void loadingFailed(MediaPlayer::NetworkState); 104 105 void triggerRepaint(GstBuffer*); 106 void repaint(); 107 void paint(GraphicsContext*, const IntRect&); 108 109 bool hasSingleSecurityOrigin() const; 110 111 bool supportsFullscreen() const; 112 PlatformMedia platformMedia() const; 113 114 void videoChanged(); 115 void audioChanged(); 116 void notifyPlayerOfVideo(); 117 void notifyPlayerOfAudio(); 118 119 void sourceChanged(); 120 121 unsigned decodedFrameCount() const; 122 unsigned droppedFrameCount() const; 123 unsigned audioDecodedByteCount() const; 124 unsigned videoDecodedByteCount() const; 125 126 private: 127 MediaPlayerPrivateGStreamer(MediaPlayer*); 128 129 static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*); 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