sipxmedialib  Version 3.3
MpStreamPlaylistPlayer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2006 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 
15 #ifndef _MpStreamPlaylistPlayer_h_
16 #define _MpStreamPlaylistPlayer_h_
17 
18 #ifndef DISABLE_STREAM_PLAYER // [
19 
20 // SYSTEM INCLUDES
21 // APPLICATION INCLUDES
22 #include "mp/MpPlayer.h"
23 #include "mp/StreamDefs.h"
24 #include "net/Url.h"
25 #include "os/OsBSem.h"
26 #include "os/OsEvent.h"
27 #include "os/OsDefs.h"
28 #include "os/OsServerTask.h"
29 #include "os/OsStatus.h"
30 #include "os/OsQueuedEvent.h"
31 
32 // DEFINES
33 #define MAX_PLAYLIST_LENGTH 40
34 #define REALIZE_TIMEOUT 15
35 #define PREFETCH_TIMEOUT 30
36 #define PLAY_TIMEOUT 180
37 #define REWIND_TIMEOUT 15
38 #define STOP_TIMEOUT 15
39 #define DESTROY_TIMEOUT 30
40 
41 // MACROS
42 // EXTERNAL FUNCTIONS
43 // EXTERNAL VARIABLES
44 // CONSTANTS
45 // STRUCTS
46 // TYPEDEFS
47 // FORWARD DECLARATIONS
48 class UtlString;
49 
50 class MpStreamPlaylistPlayer : public OsServerTask, public MpPlayer
51 {
52 /* //////////////////////////// PUBLIC //////////////////////////////////// */
53 public:
54 
55  typedef enum
56  {
59  } SourceType;
60 
61 /* ============================ CREATORS ================================== */
63 
64 
66  MpStreamPlaylistPlayer(OsMsgQ* pMsgQ, const char* pTarget = NULL);
67 
68 
70  virtual
72 
74 
75 /* ============================ MANIPULATORS ============================== */
77 
78 
80  virtual OsStatus add( Url& url
81  , int flags
82  );
83 
84 
86  virtual OsStatus add(UtlString* pBuffer, int flags);
95  virtual OsStatus realize(UtlBoolean bBlock = TRUE);
103  virtual OsStatus prefetch(UtlBoolean bBlock = TRUE);
110  virtual OsStatus play(UtlBoolean bBlock = TRUE);
118  virtual OsStatus wait(const OsTime& rTimeout = OsTime::OS_INFINITY);
125  virtual OsStatus rewind(UtlBoolean bBlock = TRUE);
133  virtual OsStatus reset() ;
136 
139  virtual OsStatus stop() ;
140 
143  virtual OsStatus destroy() ;
144 
146  virtual OsStatus pause() ;
147 
148 
150 
151 /* ============================ ACCESSORS ================================= */
153 
154 
156  virtual OsStatus getCount(int& count) const ;
157 
159  virtual OsStatus getSourceType(int index, int& type) const ;
160 
162  virtual OsStatus getSourceUrl(int index, Url url) const ;
163 
165  virtual OsStatus getSourceBuffer(int index, UtlString*& netBuffer) const ;
166 
168  virtual OsStatus getSourceState(int index, PlayerState& state) const ;
169 
172  virtual OsStatus getCurrentIndex(int& iIndex) const ;
173 
175  virtual OsStatus getState(PlayerState& state) ;
176 
178 
179 /* ============================ INQUIRY =================================== */
181 
182 
184 
185 /* //////////////////////////// PROTECTED ///////////////////////////////// */
186 protected:
187 
189  MpStreamPlaylistPlayer(const MpStreamPlaylistPlayer& rMpStreamPlaylistPlayer);
190 
193 
195  virtual OsStatus first() ;
200  virtual OsStatus last() ;
206  virtual OsStatus playNext(UtlBoolean bBlock = TRUE) ;
208 
210  virtual OsStatus playPrevious(UtlBoolean bBlock = TRUE) ;
211 
213  void setEntryState(int index, PlayerState iState) ;
214 
216  OsStatus playEntry(int iEntry, UtlBoolean bBlock = TRUE);
217 
219  OsStatus rewindEntry(int iEntry, UtlBoolean bBlock = TRUE);
220 
222  OsStatus stopEntry(int index, UtlBoolean bBlock = TRUE);
223 
225  OsStatus pauseEntry(int index);
226 
228  OsStatus destroyEntry(int index, UtlBoolean bBlockAndClean = TRUE);
229 
231  virtual UtlBoolean handleMessage(OsMsg& rMsg) ;
232 
234  void handleRealizedState(int index, PlayerState oldState, PlayerState newState);
235 
237  void handlePrefetchedState(int index, PlayerState oldState, PlayerState newState);
238 
240  void handlePlayingState(int index, PlayerState oldState, PlayerState newState);
241 
243  void handlePausedState(int index, PlayerState oldState, PlayerState newState);
244 
246  void handleStoppedState(int index, PlayerState oldState, PlayerState newState);
247 
249  void handleFailedState(int index, PlayerState oldState, PlayerState newState);
250 
252  const char* getFeederEventString(int iEvent);
253 
254 /* //////////////////////////// PRIVATE /////////////////////////////////// */
255 private:
256 
258  struct PlaylistDb
259  {
260  int sourceType ;
261  Url url ;
262  UtlString* pBuffer ;
265  int flags ;
266  OsQueuedEvent* pQueuedEvent ;
267  } ;
268 
269 
273 
274  OsQueuedEvent* mpQueueEvent;
276  OsMsgQ* mpMsgQ;
277  UtlString mTarget;
278  OsEvent mWaitEvent;
281  OsTime mPlayTimeout;
282  OsTime mRewindTimeout;
283  OsTime mStopTimeout;
285 
286  UtlBoolean mbAutoAdvance;
287 
290 };
291 
292 /* ============================ INLINE METHODS ============================ */
293 
294 #endif // DISABLE_STREAM_PLAYER ]
295 
296 #endif // _MpStreamPlaylistPlayer_h_
int sourceType
Source type (url or buffer)
Definition: MpStreamPlaylistPlayer.h:260
virtual OsStatus getSourceUrl(int index, Url url) const
Gets the source url for playlist entry 'index'.
Definition: MpStreamPlaylistPlayer.cpp:463
OsTime mRealizeTimeout
Timeout for Realize operation.
Definition: MpStreamPlaylistPlayer.h:279
virtual OsStatus stop()
Stops play the media stream and resources used for buffering and streaming.
Definition: MpStreamPlaylistPlayer.cpp:390
MpStreamPlaylistPlayer(OsMsgQ *pMsgQ, const char *pTarget=NULL)
Constructor accepting a flow graph.
Definition: MpStreamPlaylistPlayer.cpp:34
void handlePausedState(int index, PlayerState oldState, PlayerState newState)
Handles processing for the paused state.
Definition: MpStreamPlaylistPlayer.cpp:1070
OsStatus playEntry(int iEntry, UtlBoolean bBlock=TRUE)
Starts playing a specific entry.
Definition: MpStreamPlaylistPlayer.cpp:663
virtual OsStatus play(UtlBoolean bBlock=TRUE)
Plays the media stream. This will play all play lists from start to finish.
Definition: MpStreamPlaylistPlayer.cpp:285
Definition: MpStreamPlaylistPlayer.h:57
virtual OsStatus rewind(UtlBoolean bBlock=TRUE)
Rewinds a previously played media stream. In some cases this may result in a re-connect/refetch.
Definition: MpStreamPlaylistPlayer.cpp:342
OsTime mRewindTimeout
Timeout for Rewind operation.
Definition: MpStreamPlaylistPlayer.h:282
void handlePrefetchedState(int index, PlayerState oldState, PlayerState newState)
Handles processing for the prefetched state.
Definition: MpStreamPlaylistPlayer.cpp:1021
#define MAX_PLAYLIST_LENGTH
Max number of play list entries.
Definition: MpStreamPlaylistPlayer.h:33
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Handle messages directed to this server task.
Definition: MpStreamPlaylistPlayer.cpp:915
MpStreamPlaylistPlayer & operator=(const MpStreamPlaylistPlayer &rhs)
Assignment operator.
Definition: MpStreamPlaylistPlayer.cpp:549
UtlString * pBuffer
buffer if source type buffer
Definition: MpStreamPlaylistPlayer.h:262
void handlePlayingState(int index, PlayerState oldState, PlayerState newState)
Handles processing for the playing state.
Definition: MpStreamPlaylistPlayer.cpp:1055
PlayerState state
state of the entry
Definition: MpStreamPlaylistPlayer.h:264
Definition: MpPlayer.h:92
Definition: MpStreamPlaylistPlayer.h:58
void setEntryState(int index, PlayerState iState)
Sets the state for a specific entry.
Definition: MpStreamPlaylistPlayer.cpp:615
virtual OsStatus wait(const OsTime &rTimeout=OsTime::OS_INFINITY)
Waits for the media stream(s) to finish playing. This will block the caller until all play lists have...
Definition: MpStreamPlaylistPlayer.cpp:322
virtual OsStatus playPrevious(UtlBoolean bBlock=TRUE)
Plays the previous playlist entry without wrapping.
Definition: MpStreamPlaylistPlayer.cpp:599
int mCurrentElement
next item to play
Definition: MpStreamPlaylistPlayer.h:271
Url url
url if source type url
Definition: MpStreamPlaylistPlayer.h:261
virtual OsStatus reset()
Resets the playlist player state by stopping and removing all entries.
Definition: MpStreamPlaylistPlayer.cpp:363
OsTime mPrefetchTimeout
Timeout for Prefetch operation.
Definition: MpStreamPlaylistPlayer.h:280
virtual OsStatus getSourceType(int index, int &type) const
Gets the source type for playlist entry 'index'.
Definition: MpStreamPlaylistPlayer.cpp:448
virtual OsStatus add(Url &url, int flags)
Adds a url to the playlist.
Definition: MpStreamPlaylistPlayer.cpp:92
void * StreamHandle
Handles used by the renderer.
Definition: StreamDefs.h:42
virtual OsStatus destroy()
Definition: MpStreamPlaylistPlayer.cpp:408
OsBSem mSemStateChange
used to block for state changes
Definition: MpStreamPlaylistPlayer.h:275
OsMsgQ * mpMsgQ
MsgQ to send commands.
Definition: MpStreamPlaylistPlayer.h:276
virtual OsStatus prefetch(UtlBoolean bBlock=TRUE)
Prefetch enough of the data source to ensure a smooth playback.
Definition: MpStreamPlaylistPlayer.cpp:240
const char * getFeederEventString(int iEvent)
Handles converting Feeder events into human readable form.
OsQueuedEvent * pQueuedEvent
queued event for notifications
Definition: MpStreamPlaylistPlayer.h:266
UtlBoolean mbAutoAdvance
used to play playlist lists
Definition: MpStreamPlaylistPlayer.h:286
OsTime mStopTimeout
Timeout for Stop operation.
Definition: MpStreamPlaylistPlayer.h:283
virtual OsStatus realize(UtlBoolean bBlock=TRUE)
Realizes the player by initiating a connection to the target, allocates buffers, etc.
Definition: MpStreamPlaylistPlayer.cpp:136
OsStatus destroyEntry(int index, UtlBoolean bBlockAndClean=TRUE)
Destroys a specific entry.
Definition: MpStreamPlaylistPlayer.cpp:846
Definition: MpStreamPlaylistPlayer.h:50
Definition for a playlist entry.
Definition: MpStreamPlaylistPlayer.h:258
struct PlaylistDb mPlayListDb[MAX_PLAYLIST_LENGTH]
db of entries
Definition: MpStreamPlaylistPlayer.h:288
void handleFailedState(int index, PlayerState oldState, PlayerState newState)
Handles processing for the failed state.
Definition: MpStreamPlaylistPlayer.cpp:1130
int flags
flags for the entry
Definition: MpStreamPlaylistPlayer.h:265
virtual OsStatus getSourceBuffer(int index, UtlString *&netBuffer) const
Gets the source buffer for playlist entry 'index'.
Definition: MpStreamPlaylistPlayer.cpp:481
virtual OsStatus getState(PlayerState &state)
Gets the aggregate playerlist player state.
Definition: MpStreamPlaylistPlayer.cpp:527
OsStatus pauseEntry(int index)
Pauses a specific entry.
Definition: MpStreamPlaylistPlayer.cpp:818
virtual OsStatus getCount(int &count) const
Gets the number of play list entries.
Definition: MpStreamPlaylistPlayer.cpp:440
virtual OsStatus getCurrentIndex(int &iIndex) const
Gets the current playing index if playing or the next index to play if playNext() was invoked...
Definition: MpStreamPlaylistPlayer.cpp:514
void handleStoppedState(int index, PlayerState oldState, PlayerState newState)
Handles processing for the stopped state.
Definition: MpStreamPlaylistPlayer.cpp:1085
virtual OsStatus getSourceState(int index, PlayerState &state) const
Gets the state for the playlist entry 'index'.
Definition: MpStreamPlaylistPlayer.cpp:498
virtual OsStatus first()
Selects the first playlist entry as the next index to play.
Definition: MpStreamPlaylistPlayer.cpp:559
PlayerState
Definition: MpPlayer.h:38
int mNumPlayListElements
number of play list entries
Definition: MpStreamPlaylistPlayer.h:270
virtual OsStatus pause()
Pauses the media stream temporarily.
Definition: MpStreamPlaylistPlayer.cpp:423
OsTime mPlayTimeout
Timeout for Play operation.
Definition: MpStreamPlaylistPlayer.h:281
SourceType
Definition: MpStreamPlaylistPlayer.h:55
virtual ~MpStreamPlaylistPlayer()
Destructor.
Definition: MpStreamPlaylistPlayer.cpp:79
int mPlayingElement
current playing item
Definition: MpStreamPlaylistPlayer.h:272
UtlString mTarget
target used for MsgQ receive to help dispatch
Definition: MpStreamPlaylistPlayer.h:277
OsTime mDestroyTimeout
Timeout for Destroy operation.
Definition: MpStreamPlaylistPlayer.h:284
virtual OsStatus last()
Selects the last playlist entry as the next index to play.
Definition: MpStreamPlaylistPlayer.cpp:570
OsQueuedEvent * mpQueueEvent
event for notifications
Definition: MpStreamPlaylistPlayer.h:274
virtual OsStatus playNext(UtlBoolean bBlock=TRUE)
Plays the next playlist entry without wrapping.
Definition: MpStreamPlaylistPlayer.cpp:584
StreamHandle handle
handle of the feeder
Definition: MpStreamPlaylistPlayer.h:263
void handleRealizedState(int index, PlayerState oldState, PlayerState newState)
Handles processing for the realized state.
Definition: MpStreamPlaylistPlayer.cpp:988
#define TRUE
Definition: PlgDefsV1.h:41
OsStatus rewindEntry(int iEntry, UtlBoolean bBlock=TRUE)
Rewinds a specific entry.
Definition: MpStreamPlaylistPlayer.cpp:718
OsStatus stopEntry(int index, UtlBoolean bBlock=TRUE)
Stops playing a specific entry.
Definition: MpStreamPlaylistPlayer.cpp:771
PlayerState mAggregateState
Aggregate state of the player.
Definition: MpStreamPlaylistPlayer.h:289
OsEvent mWaitEvent
used to block until player completes
Definition: MpStreamPlaylistPlayer.h:278