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 (at) atoker.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * aint with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef MediaPlayerPrivateGStreamer_h 23 #define MediaPlayerPrivateGStreamer_h 24 25 #if ENABLE(VIDEO) 26 27 #include "MediaPlayerPrivate.h" 28 #include "Timer.h" 29 30 #include <cairo.h> 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 typedef struct _GstBus GstBus; 39 40 namespace WebCore { 41 42 class GraphicsContext; 43 class IntSize; 44 class IntRect; 45 class String; 46 47 gboolean mediaPlayerPrivateMessageCallback(GstBus* bus, GstMessage* message, gpointer data); 48 void mediaPlayerPrivateVolumeChangedCallback(GObject* element, GParamSpec* pspec, gpointer data); 49 void mediaPlayerPrivateSourceChangedCallback(GObject* element, GParamSpec* pspec, gpointer data); 50 51 class MediaPlayerPrivate : public MediaPlayerPrivateInterface { 52 friend gboolean mediaPlayerPrivateMessageCallback(GstBus* bus, GstMessage* message, gpointer data); 53 friend void mediaPlayerPrivateRepaintCallback(WebKitVideoSink*, GstBuffer* buffer, MediaPlayerPrivate* playerPrivate); 54 friend void mediaPlayerPrivateSourceChangedCallback(GObject* element, GParamSpec* pspec, gpointer data); 55 56 public: 57 static void registerMediaEngine(MediaEngineRegistrar); 58 ~MediaPlayerPrivate(); 59 60 IntSize naturalSize() const; 61 bool hasVideo() const; 62 bool hasAudio() const; 63 64 void load(const String &url); 65 void cancelLoad(); 66 bool loadNextLocation(); 67 68 void play(); 69 void pause(); 70 71 bool paused() const; 72 bool seeking() const; 73 74 float duration() const; 75 float currentTime() const; 76 void seek(float); 77 78 void setRate(float); 79 80 void setVolume(float); 81 void volumeChanged(); 82 void volumeChangedCallback(); 83 84 bool supportsMuting() const; 85 void setMuted(bool); 86 void muteChanged(); 87 void muteChangedCallback(); 88 89 MediaPlayer::NetworkState networkState() const; 90 MediaPlayer::ReadyState readyState() const; 91 92 PassRefPtr<TimeRanges> buffered() const; 93 float maxTimeSeekable() const; 94 unsigned bytesLoaded() const; 95 unsigned totalBytes() const; 96 97 void setVisible(bool); 98 void setSize(const IntSize&); 99 100 void mediaLocationChanged(GstMessage*); 101 void loadStateChanged(); 102 void sizeChanged(); 103 void timeChanged(); 104 void didEnd(); 105 void durationChanged(); 106 void loadingFailed(MediaPlayer::NetworkState); 107 108 void repaint(); 109 void paint(GraphicsContext*, const IntRect&); 110 111 bool hasSingleSecurityOrigin() const; 112 113 bool supportsFullscreen() const; 114 115 bool pipelineReset() const { return m_resetPipeline; } 116 117 private: 118 MediaPlayerPrivate(MediaPlayer*); 119 static MediaPlayerPrivateInterface* create(MediaPlayer* player); 120 121 static void getSupportedTypes(HashSet<String>&); 122 static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs); 123 static bool isAvailable(); 124 125 void updateStates(); 126 void cancelSeek(); 127 void endPointTimerFired(Timer<MediaPlayerPrivate>*); 128 float maxTimeLoaded() const; 129 void startEndPointTimerIfNeeded(); 130 131 void createGSTPlayBin(String url); 132 bool changePipelineState(GstState state); 133 134 private: 135 MediaPlayer* m_player; 136 GstElement* m_playBin; 137 GstElement* m_videoSink; 138 GstElement* m_fpsSink; 139 GstElement* m_source; 140 GstClockTime m_seekTime; 141 bool m_changingRate; 142 float m_endTime; 143 bool m_isEndReached; 144 MediaPlayer::NetworkState m_networkState; 145 MediaPlayer::ReadyState m_readyState; 146 bool m_startedPlaying; 147 mutable bool m_isStreaming; 148 IntSize m_size; 149 GstBuffer* m_buffer; 150 GstStructure* m_mediaLocations; 151 gint m_mediaLocationCurrentIndex; 152 bool m_resetPipeline; 153 bool m_paused; 154 bool m_seeking; 155 float m_playbackRate; 156 bool m_errorOccured; 157 guint m_volumeIdleId; 158 gfloat m_mediaDuration; 159 guint m_muteIdleId; 160 }; 161 } 162 163 #endif 164 #endif 165