sbGStreamerMediacore.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #ifndef __SB_GSTREAMERMEDIACORE_H__
28 #define __SB_GSTREAMERMEDIACORE_H__
29 
30 #include <sbIGStreamerMediacore.h>
31 
32 #include <nsIDOMEventListener.h>
33 #include <nsIDOMXULElement.h>
34 #include <nsIObserver.h>
35 #include <nsIPrefBranch2.h>
36 
37 #include <nsAutoPtr.h>
38 #include <nsCOMPtr.h>
39 
40 #include <sbIMediacore.h>
41 #include <sbIMediacorePlaybackControl.h>
42 #include <sbIMediacoreVideoWindow.h>
43 #include <sbIMediacoreVolumeControl.h>
44 #include <sbIMediacoreVotingParticipant.h>
45 #include <sbIMediacoreEventTarget.h>
46 #include <sbIMediacoreError.h>
47 #include <sbIVideoBox.h>
48 
49 #include <sbIPropertyArray.h>
50 
51 #include <sbBaseMediacore.h>
56 
57 #include <gst/gst.h>
59 #include "sbIGstAudioFilter.h"
61 
62 #include <vector>
63 
64 class nsIURI;
65 
71  public sbIGStreamerMediacore,
73  public nsIDOMEventListener,
74  public nsIObserver,
75  public sbIGstAudioFilter,
77 {
78 public:
80  NS_DECL_NSICLASSINFO
81  NS_DECL_NSIDOMEVENTLISTENER
82  NS_DECL_NSIOBSERVER
83  NS_DECL_SBIMEDIACOREEVENTTARGET
84  NS_DECL_SBIMEDIACOREVOTINGPARTICIPANT
85  NS_DECL_SBIMEDIACOREVIDEOWINDOW
86  NS_DECL_SBIGSTREAMERMEDIACORE
87 
89 
90  nsresult Init();
91 
92  // sbBaseMediacore overrides
93  virtual nsresult OnInitBaseMediacore();
94  virtual nsresult OnGetCapabilities();
95  virtual nsresult OnShutdown();
96 
97  // sbBaseMediacoreMultibandEqualizer overrides
98  virtual nsresult OnInitBaseMediacoreMultibandEqualizer();
99  virtual nsresult OnSetEqEnabled(PRBool aEqEnabled);
100  virtual nsresult OnGetBandCount(PRUint32 *aBandCount);
101  virtual nsresult OnGetBand(PRUint32 aBandIndex, sbIMediacoreEqualizerBand *aBand);
102  virtual nsresult OnSetBand(sbIMediacoreEqualizerBand *aBand);
103 
104  // sbBaseMediacorePlaybackControl overrides
105  virtual nsresult OnInitBaseMediacorePlaybackControl();
106  virtual nsresult OnSetUri(nsIURI *aURI);
107  virtual nsresult OnGetDuration(PRUint64 *aDuration);
108  virtual nsresult OnGetPosition(PRUint64 *aPosition);
109  virtual nsresult OnSetPosition(PRUint64 aPosition);
110  virtual nsresult OnGetIsPlayingAudio(PRBool *aIsPlayingAudio);
111  virtual nsresult OnGetIsPlayingVideo(PRBool *aIsPlayingVideo);
112  virtual nsresult OnPlay();
113  virtual nsresult OnPause();
114  virtual nsresult OnStop();
115  virtual nsresult OnSeek(PRUint64 aPosition, PRUint32 aFlag);
116 
117  // sbBaseMediacoreVolumeControl overrides
118  virtual nsresult OnInitBaseMediacoreVolumeControl();
119  virtual nsresult OnSetMute(PRBool aMute);
120  virtual nsresult OnSetVolume(PRFloat64 aVolume);
121 
122  // GStreamer message handling
123  virtual void HandleMessage(GstMessage *message);
124  virtual PRBool HandleSynchronousMessage(GstMessage *message);
125 
126  // sbIGstAudioFilter interface
127  virtual nsresult AddAudioFilter(GstElement *aElement);
128  virtual nsresult RemoveAudioFilter(GstElement *aElement);
129 
130  void RequestVideoWindow();
131 
132 protected:
133  virtual ~sbGStreamerMediacore();
134 
135  nsresult DestroyPipeline();
136  nsresult CreatePlaybackPipeline();
137 
138  void DispatchMediacoreEvent (unsigned long type,
139  nsIVariant *aData = NULL, sbIMediacoreError *aError = NULL);
140 
142  void HandleTagMessage (GstMessage *message);
143  void HandleStateChangedMessage (GstMessage *message);
144  void HandleEOSMessage (GstMessage *message);
145  void HandleErrorMessage (GstMessage *message);
146  void HandleWarningMessage (GstMessage *message);
147  void HandleBufferingMessage (GstMessage *message);
148  void HandleRedirectMessage (GstMessage *message);
149  void HandleMissingPluginMessage (GstMessage *message);
150  void OnAudioCapsSet(GstCaps *caps);
151  void OnVideoCapsSet(GstCaps *caps);
152 
153  GstElement *CreateSinkFromPrefs(const char *aSinkDescription);
154  GstElement *CreateVideoSink();
155  GstElement *CreateAudioSink();
156 
157  nsresult InitPreferences();
158  nsresult ReadPreferences();
159  nsresult SetBufferingProperties(GstElement *aPipeline);
160  nsresult SendInitialBufferingEvent();
161 
162  nsresult GetFileSize(nsIURI *aURI, PRInt64 *aFileSize);
163 
165 
166  bool SetPropertyOnChild(GstElement *aElement,
167  const char *aPropertyName, gint64 aPropertyValue);
168 
169 private:
170  // Static helpers for C callback
171  static void aboutToFinishHandler(GstElement *playbin, gpointer data);
172  static void videoCapsSetHelper(GObject *obj, GParamSpec *pspec,
173  sbGStreamerMediacore *core);
174  static void currentVideoSetHelper(GObject *obj, GParamSpec *pspec,
175  sbGStreamerMediacore *core);
176  static void audioCapsSetHelper(GObject *obj, GParamSpec *pspec,
177  sbGStreamerMediacore *core);
178  static void currentAudioSetHelper(GObject *obj, GParamSpec *pspec,
179  sbGStreamerMediacore *core);
180 
181 protected:
182  // Protects all access to mPipeline
183  PRMonitor* mMonitor;
184 
185  PRBool mIsVideoSupported; // true if we have support for video on the current
186  // platform
187 
188  GstElement *mPipeline;
189  nsAutoPtr<sbIGstPlatformInterface> mPlatformInterface;
190 
191  nsAutoPtr<sbBaseMediacoreEventTarget> mBaseEventTarget;
192 
193  nsCOMPtr<nsIPrefBranch2> mPrefs;
194 
195  std::vector<GstElement*> mAudioFilters;
196 
197  GstElement *mReplaygainElement;
198  GstElement *mEqualizerElement;
199 
200  // Metadata, both in original GstTagList form, and transformed into an
201  // sbIPropertyArray. Both may be NULL.
202  GstTagList *mTags;
203  nsCOMPtr<sbIPropertyArray> mProperties;
204 
205  // Distinguish between being stopped, and stopping due to reaching the end.
206  PRBool mStopped;
207  // Track whether we're currently buffering
208  PRBool mBuffering;
209  // Track if we are using a live pipeline
210  PRBool mIsLive;
211 
212  // If we've seen an error for the current file being played.
213  // To be dispatched when we've shut down the pipeline.
214  nsCOMPtr<sbIMediacoreError> mMediacoreError;
215 
216  // The GstState we want to reach (not necessarily the current pipeline
217  // pending state)
218  GstState mTargetState;
219 
220  // the video box
221  nsCOMPtr<nsIDOMXULElement> mVideoWindow;
222  nsCOMPtr<nsIDOMWindow> mDOMWindow;
223 
224  // The size of the video we're actually playing. If NULL, we're not currently
225  // playing video (or we don't yet know the size).
226  nsCOMPtr<sbIVideoBox> mVideoSize;
227 
228  // Various things read from preferences
229  PRBool mVideoDisabled; // Whether video is disabled via prefs
230 
233 
234  PRInt64 mAudioSinkBufferTime; // Audio sink buffer time in usecs
235  PRInt32 mStreamingBufferSize; // Streaming buffer max size in bytes
236 
237  PRBool mResourceIsLocal; // True if the current resource is a local file.
238  PRInt64 mResourceSize; // Size of current playing file, or -1 if unknown.
239 
240  PRBool mGaplessDisabled; // If true, gapless playback is disabled for the
241  // currently-in-use pipeline. Recreating the
242  // pipeline will re-enable gapless.
243  PRBool mPlayingGaplessly; // Gapless playback is currently happening - we're
244  // on a second or subsequent file in a gapless
245  // sequence.
246 
247  PRBool mAbortingPlayback; // Playback is being aborted (not normally
248  // stopped), and bus messages should not be
249  // processed.
250  PRBool mHasReachedPlaying; // If we've ever made it to PLAYING state while
251  // playing the current resource.
252 
253  nsCString mCurrentUri; // UTF-8 String form (as used by GStreamer) of
254  // the currently-playing URI.
255 
256  GstCaps *mCurrentAudioCaps; // Caps of currently playing audio, or NULL
257 
258  GstGhostPad *mAudioBinGhostPad;
259 
260  PRBool mHasVideo; // True if we're playing video currently.
261  PRBool mHasAudio; // True if we're playing audio currently.
262 };
263 
264 #endif /* __SB_GSTREAMERMEDIACORE_H__ */
nsCOMPtr< sbIVideoBox > mVideoSize
virtual nsresult OnSetEqEnabled(PRBool aEqEnabled)
virtual nsresult OnInitBaseMediacoreVolumeControl()
virtual nsresult OnSetVolume(PRFloat64 aVolume)
virtual nsresult OnSetBand(sbIMediacoreEqualizerBand *aBand)
nsAutoPtr< sbBaseMediacoreEventTarget > mBaseEventTarget
nsCOMPtr< sbIPropertyArray > mProperties
Songbird Mediacore Base Multiband Equalizer Definition.
void HandleMissingPluginMessage(GstMessage *message)
virtual void HandleMessage(GstMessage *message)
virtual nsresult OnInitBaseMediacoreMultibandEqualizer()
virtual nsresult OnShutdown()
virtual nsresult OnSetUri(nsIURI *aURI)
virtual nsresult OnInitBaseMediacorePlaybackControl()
void HandleTagMessage(GstMessage *message)
void HandleStateChangedMessage(GstMessage *message)
nsCOMPtr< nsIPrefBranch2 > mPrefs
std::vector< GstElement * > mAudioFilters
void HandleBufferingMessage(GstMessage *message)
nsCOMPtr< sbIMediacoreError > mMediacoreError
virtual nsresult RemoveAudioFilter(GstElement *aElement)
virtual nsresult OnGetBand(PRUint32 aBandIndex, sbIMediacoreEqualizerBand *aBand)
nsresult SetBufferingProperties(GstElement *aPipeline)
virtual nsresult OnGetDuration(PRUint64 *aDuration)
GstElement * CreateSinkFromPrefs(const char *aSinkDescription)
Songbird Base Mediacore Definition.
void HandleErrorMessage(GstMessage *message)
virtual PRBool HandleSynchronousMessage(GstMessage *message)
virtual nsresult OnGetIsPlayingVideo(PRBool *aIsPlayingVideo)
void OnAudioCapsSet(GstCaps *caps)
Songbird Mediacore Event Definition.
virtual nsresult OnInitBaseMediacore()
virtual nsresult OnSeek(PRUint64 aPosition, PRUint32 aFlag)
virtual nsresult OnSetMute(PRBool aMute)
void OnVideoCapsSet(GstCaps *caps)
virtual nsresult OnGetBandCount(PRUint32 *aBandCount)
virtual nsresult OnGetCapabilities()
GstMessage * message
virtual nsresult OnSetPosition(PRUint64 aPosition)
void HandleEOSMessage(GstMessage *message)
void HandleRedirectMessage(GstMessage *message)
NS_DECL_ISUPPORTS NS_DECL_NSICLASSINFO NS_DECL_NSIDOMEVENTLISTENER NS_DECL_NSIOBSERVER NS_DECL_SBIMEDIACOREEVENTTARGET NS_DECL_SBIMEDIACOREVOTINGPARTICIPANT NS_DECL_SBIMEDIACOREVIDEOWINDOW NS_DECL_SBIGSTREAMERMEDIACORE sbGStreamerMediacore()
virtual nsresult AddAudioFilter(GstElement *aElement)
void HandleWarningMessage(GstMessage *message)
virtual nsresult OnGetIsPlayingAudio(PRBool *aIsPlayingAudio)
void DispatchMediacoreEvent(unsigned long type, nsIVariant *aData=NULL, sbIMediacoreError *aError=NULL)
nsresult GetFileSize(nsIURI *aURI, PRInt64 *aFileSize)
Songbird Base Mediacore Playback Control Definition.
observe data
Definition: FeedWriter.js:1329
bool SetPropertyOnChild(GstElement *aElement, const char *aPropertyName, gint64 aPropertyValue)
nsIDOMEventListener
nsCOMPtr< nsIDOMXULElement > mVideoWindow
nsAutoPtr< sbIGstPlatformInterface > mPlatformInterface
virtual nsresult OnGetPosition(PRUint64 *aPosition)
nsCOMPtr< nsIDOMWindow > mDOMWindow