sbMediacoreSequencer.h
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26 */
27 
28 #include <sbIMediacoreSequencer.h>
29 
30 #include <nsIClassInfo.h>
31 #include <nsIMutableArray.h>
32 #include <nsIStringEnumerator.h>
33 #include <nsITimer.h>
34 #include <nsIURI.h>
35 #include <nsIWeakReference.h>
36 
37 #include <nsCOMPtr.h>
38 #include <nsHashKeys.h>
39 #include <nsTHashtable.h>
40 #include <prmon.h>
41 
42 #include <sbIDataRemote.h>
43 #include <sbIMediacoreEventListener.h>
44 #include <sbIMediacoreManager.h>
45 #include <sbIMediacoreStatus.h>
46 #include <sbIMediacoreSequenceGenerator.h>
47 #include <sbIMediaListListener.h>
48 #include <sbIMediaListView.h>
49 #include <sbIPropertyManager.h>
50 #include <sbIMediaItemController.h>
51 
52 #include <vector>
53 #include <map>
54 
55 class nsAutoMonitor;
56 
59  public sbIMediacoreStatus,
60  public sbIMediaListListener,
63  public nsIClassInfo,
64  public nsITimerCallback
65 {
66 public:
68 
69  NS_DECL_SBIMEDIACORESEQUENCER
70  NS_DECL_SBIMEDIACOREEVENTLISTENER
71  NS_DECL_SBIMEDIACORESTATUS
72  NS_DECL_SBIMEDIALISTLISTENER
73  NS_DECL_SBIMEDIALISTVIEWLISTENER
74  NS_DECL_SBIMEDIAITEMCONTROLLERLISTENER
75  NS_DECL_NSICLASSINFO
76  NS_DECL_NSITIMERCALLBACK
77 
79 
80  typedef std::vector<PRUint32> sequence_t;
81  typedef std::map<PRUint32, PRUint32> sequencemap_t;
82 
83  nsresult Init();
84 
85  // Sequence Processor (timer driven)
86  nsresult StartSequenceProcessor();
87  nsresult StopSequenceProcessor();
88 
89  // DataRemotes
90  nsresult BindDataRemotes();
91  nsresult UnbindDataRemotes();
92 
93  // Faceplate Playback Status DataRemotes
94  nsresult UpdatePlayStateDataRemotes();
95  nsresult UpdatePositionDataRemotes(PRUint64 aPosition);
96  nsresult UpdateDurationDataRemotes(PRUint64 aDuration);
97  nsresult UpdateURLDataRemotes(nsIURI *aURI);
98  nsresult UpdateShuffleDataRemote(PRUint32 aMode);
99  nsresult UpdateRepeatDataRemote(PRUint32 aRepeatMode);
100  nsresult ResetPlayingVideoDataRemote();
101 
102  // Volume & Mute
103  nsresult HandleVolumeChangeEvent(sbIMediacoreEvent *aEvent);
104  nsresult UpdateVolumeDataRemote(PRFloat64 aVolume);
105  nsresult HandleMuteChangeEvent(sbIMediacoreEvent *aEvent);
106  nsresult UpdateMuteDataRemote(PRBool aMuted);
107 
108  // Metadata Event & DataRemote
109  nsresult HandleMetadataEvent(sbIMediacoreEvent *aEvent);
110  nsresult SetMetadataDataRemote(const nsAString &aId,
111  const nsAString &aValue);
113  sbIMediaItem *aItem,
114  sbIPropertyArray *aPropertiesChanged = nsnull);
115  nsresult ResetMetadataDataRemotes();
116 
117  nsresult UpdateCurrentItemDuration(PRUint64 aDuration);
118 
120 
121  // Error Event
122  nsresult HandleErrorEvent(sbIMediacoreEvent *aEvent);
123 
124  // Sequence management
125  nsresult RecalculateSequence(PRInt64 *aViewPosition = nsnull);
126 
127  // Fetching of items, item manipulation.
128  nsresult GetItem(const sequence_t &aSequence,
129  PRUint32 aPosition,
130  sbIMediaItem **aItem);
131 
132  // Setup for playback
133  nsresult ProcessNewPosition();
134  nsresult Setup(nsIURI *aURI = nsnull);
135  nsresult CoreHandleNextSetup();
136  PRBool HandleAbort();
137 
138  // Set view with optional view position
140  PRInt64 *aViewPosition = nsnull);
141 
142  // Timer handlers
143  nsresult HandleSequencerTimer(nsITimer *aTimer);
144  nsresult HandleDelayedCheckTimer(nsITimer *aTimer);
145 
146  nsresult StartWatchingView();
147  nsresult StopWatchingView();
148 
149  nsresult DelayedCheck();
150  nsresult UpdateItemUIDIndex();
151 
152 protected:
153  virtual ~sbMediacoreSequencer();
154 
155  nsresult DispatchMediacoreEvent(sbIMediacoreEvent *aEvent,
156  PRBool aAsync = PR_FALSE);
157 
158  nsresult StartPlayback();
159 
160  PRBool CheckPropertiesInfluenceView(sbIPropertyArray *aProperties);
161 
162  PRBool IsPropertyInPropertyArray(sbIPropertyArray *aPropArray,
163  const nsAString &aPropName);
164 
165 
171  nsIVariant* aData);
172 
176  nsresult SeekCallback(PRUint64 aPosition);
177 
182  nsresult StopPlaybackHelper(nsAutoMonitor& aMonitor);
183 
189  nsresult ValidateMediaItemControllerPlayback(PRBool aFromUserAction,
190  PRInt32 aOnHoldStatus,
191  PRBool *_proceed);
192 
193 protected:
194  PRMonitor *mMonitor;
195 
196  PRUint32 mStatus;
197  PRPackedBool mIsWaitingForPlayback;
198  PRPackedBool mSeenPlaying;
201  PRPackedBool mCoreWillHandleNext;
202  PRPackedBool mPositionInvalidated;
203  PRUint32 mErrorCount;
204 
205  PRPackedBool mCanAbort;
206  PRPackedBool mShouldAbort;
207 
208  PRUint32 mChainIndex;
209  nsCOMPtr<nsIArray> mChain;
210 
211  nsCOMPtr<sbIMediacore> mCore;
212  nsCOMPtr<sbIMediacorePlaybackControl> mPlaybackControl;
213 
214  PRUint32 mMode;
215  PRUint32 mRepeatMode;
216 
217  nsCOMPtr<sbIMediaListView> mView;
220  PRUint32 mPosition;
221  PRUint32 mViewPosition;
222 
223  nsCOMPtr<sbIMediacoreSequenceGenerator> mCustomGenerator;
224  nsCOMPtr<sbIMediacoreSequenceGenerator> mShuffleGenerator;
225 
226  nsCOMPtr<nsIWeakReference> mMediacoreManager;
227 
228  nsCOMPtr<sbIPropertyManager> mPropertyManager;
229 
230  // Data Remotes
231  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplateBuffering;
232  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplatePaused;
233  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplatePlaying;
234  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplatePlayingVideo;
235  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplateSeenPlaying;
236  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplateURL;
237  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplateVolume;
238  nsCOMPtr<sbIDataRemote> mDataRemoteFaceplateMute;
239 
240  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataAlbum;
241  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataArtist;
242  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataTitle;
243  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataGenre;
244 
245  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataDuration;
246  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataDurationStr;
247  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataPosition;
248  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataPositionStr;
249  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataRemainingStr;
250 
251  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataURL;
252  nsCOMPtr<sbIDataRemote> mDataRemoteMetadataImageURL;
253 
254  nsCOMPtr<sbIDataRemote> mDataRemotePlaylistShuffle;
255  nsCOMPtr<sbIDataRemote> mDataRemotePlaylistRepeat;
256 
257  nsCOMPtr<sbIDataRemote> mDataRemotePlaylistShuffleDisabled;
258  nsCOMPtr<sbIDataRemote> mDataRemotePlaylistRepeatDisabled;
259  nsCOMPtr<sbIDataRemote> mDataRemotePlaylistPreviousDisabled;
260  nsCOMPtr<sbIDataRemote> mDataRemotePlaylistNextDisabled;
261 
262  nsCOMPtr<nsITimer> mSequenceProcessorTimer;
263 
264  // MediaListListener and ViewListener data.
265  nsCOMPtr<nsITimer> mDelayedCheckTimer;
266  nsCOMPtr<sbIMediaList> mViewList;
267 
268  nsString mCurrentItemUID;
270  nsCOMPtr<sbIMediaItem> mCurrentItem;
271 
275 
276  PRPackedBool mResetPosition;
277  PRPackedBool mNoRecalculate;
278  PRPackedBool mViewIsLibrary;
280  PRPackedBool mNeedsRecalculate;
281  PRPackedBool mWatchingView;
283  PRPackedBool mValidationComplete;
284  PRUint32 mOnHoldStatus;
285  enum {
290  };
291  nsCOMPtr<sbIMediaItem> mValidatingItem;
293 };
294 
296 {
297 public:
298  explicit
299  sbScopedBoolToggle(PRPackedBool *aBool, PRBool aValue = PR_TRUE) {
300  mBool = aBool;
301  *mBool = aValue;
302  }
304  if(mBool) {
305  *mBool = !(*mBool);
306  }
307  }
308 
309 private:
310  PRPackedBool *mBool;
311 };
312 
nsCOMPtr< sbIMediacore > mCore
nsCOMPtr< sbIMediaItem > mCurrentItem
nsCOMPtr< sbIDataRemote > mDataRemotePlaylistRepeat
nsresult UpdateShuffleDataRemote(PRUint32 aMode)
nsresult UpdateMuteDataRemote(PRBool aMuted)
nsresult HandleMetadataEvent(sbIMediacoreEvent *aEvent)
nsresult RecalculateSequence(PRInt64 *aViewPosition=nsnull)
onPageChanged aValue
Definition: FeedWriter.js:1395
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplateURL
nsCOMPtr< nsITimer > mDelayedCheckTimer
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataRemainingStr
nsresult HandleVolumeChangeEvent(sbIMediacoreEvent *aEvent)
nsresult Setup(nsIURI *aURI=nsnull)
sbScopedBoolToggle(PRPackedBool *aBool, PRBool aValue=PR_TRUE)
nsresult UpdateRepeatDataRemote(PRUint32 aRepeatMode)
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIACORESEQUENCER NS_DECL_SBIMEDIACOREEVENTLISTENER NS_DECL_SBIMEDIACORESTATUS NS_DECL_SBIMEDIALISTLISTENER NS_DECL_SBIMEDIALISTVIEWLISTENER NS_DECL_SBIMEDIAITEMCONTROLLERLISTENER NS_DECL_NSICLASSINFO NS_DECL_NSITIMERCALLBACK sbMediacoreSequencer()
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataPositionStr
nsresult DispatchMediacoreEvent(sbIMediacoreEvent *aEvent, PRBool aAsync=PR_FALSE)
nsresult SetMetadataDataRemote(const nsAString &aId, const nsAString &aValue)
nsresult UpdateVolumeDataRemote(PRFloat64 aVolume)
PRPackedBool mNeedSearchPlayingItem
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplateMute
nsCOMPtr< sbIMediacorePlaybackControl > mPlaybackControl
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplateSeenPlaying
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataDuration
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplatePlaying
PRPackedBool mNextTriggeredByStreamEnd
nsCOMPtr< nsITimer > mSequenceProcessorTimer
nsCOMPtr< sbIDataRemote > mDataRemotePlaylistNextDisabled
nsCOMPtr< sbIDataRemote > mDataRemotePlaylistPreviousDisabled
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataURL
A distinct view on a given media list.
Interface to receive events from a mediaItemController.
nsresult ValidateMediaItemControllerPlayback(PRBool aFromUserAction, PRInt32 aOnHoldStatus, PRBool *_proceed)
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplateBuffering
nsresult HandleSequencerTimer(nsITimer *aTimer)
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataTitle
Interface used to listen to changes to a media list.
PRPackedBool mResumePlaybackPosition
nsresult StopPlaybackHelper(nsAutoMonitor &aMonitor)
Definition of the sbIMediacoreEvent interface.
nsresult UpdateCurrentItemDuration(PRUint64 aDuration)
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplatePlayingVideo
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataArtist
nsresult SeekCallback(PRUint64 aPosition)
nsresult HandleErrorEvent(sbIMediacoreEvent *aEvent)
nsCOMPtr< sbIMediacoreSequenceGenerator > mCustomGenerator
std::map< PRUint32, PRUint32 > sequencemap_t
nsCOMPtr< sbIMediacoreSequenceGenerator > mShuffleGenerator
nsCOMPtr< sbIDataRemote > mDataRemotePlaylistRepeatDisabled
PRPackedBool mIsWaitingForPlayback
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataDurationStr
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataPosition
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataImageURL
std::vector< PRUint32 > sequence_t
nsresult SetMetadataDataRemotesFromItem(sbIMediaItem *aItem, sbIPropertyArray *aPropertiesChanged=nsnull)
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataAlbum
nsresult UpdateLastPositionProperty(sbIMediaItem *aItem, nsIVariant *aData)
nsCOMPtr< sbIMediaListView > mView
nsresult UpdateDurationDataRemotes(PRUint64 aDuration)
Saved state of a media list view.
nsCOMPtr< nsIArray > mChain
nsCOMPtr< sbIPropertyManager > mPropertyManager
sequencemap_t mViewIndexToSequenceIndex
PRBool CheckPropertiesInfluenceView(sbIPropertyArray *aProperties)
nsCOMPtr< sbIDataRemote > mDataRemotePlaylistShuffleDisabled
nsresult HandleDelayedCheckTimer(nsITimer *aTimer)
nsresult GetItem(const sequence_t &aSequence, PRUint32 aPosition, sbIMediaItem **aItem)
PRPackedBool mStopTriggeredBySequencer
nsCOMPtr< sbIMediaItem > mValidatingItem
nsCOMPtr< nsIWeakReference > mMediacoreManager
PRBool IsPropertyInPropertyArray(sbIPropertyArray *aPropArray, const nsAString &aPropName)
Interface that defines a single item of media in the system.
nsCOMPtr< sbIDataRemote > mDataRemotePlaylistShuffle
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplatePaused
nsCOMPtr< sbIDataRemote > mDataRemoteMetadataGenre
nsCOMPtr< sbIDataRemote > mDataRemoteFaceplateVolume
nsresult SetViewWithViewPosition(sbIMediaListView *aView, PRInt64 *aViewPosition=nsnull)
nsresult HandleMuteChangeEvent(sbIMediacoreEvent *aEvent)
nsresult UpdateURLDataRemotes(nsIURI *aURI)
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
nsITimerCallback
nsresult UpdatePositionDataRemotes(PRUint64 aPosition)
nsCOMPtr< sbIMediaList > mViewList
_updateTextAndScrollDataForFrame aData