sipxmedialib  Version 3.3
MpStreamQueuePlayer.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 _MpStreamQueuePlayer_h_
16 #define _MpStreamQueuePlayer_h_
17 
18 #ifndef DISABLE_STREAM_PLAYER // [
19 
20 // SYSTEM INCLUDES
21 // APPLICATION INCLUDES
22 #include "mp/MpPlayer.h"
23 #include "mp/MpPlayerListener.h"
24 #include "mp/StreamDefs.h"
25 #include "net/Url.h"
26 #include "os/OsBSem.h"
27 #include "os/OsDefs.h"
28 #include "os/OsMsgQ.h"
29 #include "os/OsServerTask.h"
30 #include "os/OsStatus.h"
31 #include "os/OsRWMutex.h"
32 #include "os/OsQueuedEvent.h"
33 
34 // DEFINES
35 #define DEFAULT_QUEUE_LENGTH 64 // Default length of queue
36 #define EXPAND_QUEUE_LENGTH 16 // Queue grows by this much
37 
38 // Player impotence- If define, the queue player doesn't actually do
39 // anything, however, will still fire off events, etc.
40 #undef PLAYER_STUBS
41 
42 // MACROS
43 // EXTERNAL FUNCTIONS
44 // EXTERNAL VARIABLES
45 // CONSTANTS
46 // STRUCTS
47 // TYPEDEFS
48 // FORWARD DECLARATIONS
49 class UtlString ;
50 class MpStreamPlayer ;
52 
53 //:Class short description which may consist of multiple lines (note the ':')
54 // Class detailed description which may extend to multiple lines
55 class MpStreamQueuePlayer : public OsServerTask, protected MpPlayerListener
56 {
57 /* //////////////////////////// PUBLIC //////////////////////////////////// */
58 public:
59 
60  typedef enum
61  {
64  } SourceType;
65 
66 /* ============================ CREATORS ================================== */
68 
69  MpStreamQueuePlayer(OsMsgQ* pMsgQ, const char* pTarget = NULL);
70  //:Constructor accepting a msgQ
71 
72  virtual
74  //:Destructor
75 
77 
78 /* ============================ MANIPULATORS ============================== */
80 
81  virtual OsStatus add(Url& url, int flags) ;
82  //:Queues a URL for playing
83  //
86 
87 
88  virtual OsStatus add(UtlString* pBuffer, int flags) ;
89  //:Queues a UtlString for playing
90  //
92  // MpStreamPlayer resource will delete the pBuffer upon destruction
93  // of itself.
95 
96  virtual OsStatus play() ;
97  //:Begins playing any queued streams
98 
99  virtual OsStatus reset() ;
100  //: Resets the queue player state by stopping and removing all
101  //: playing entries.
102 
103  virtual OsStatus destroy() ;
104  //: Marks the player as destroy and frees all allocated resources
105  // in media processing.
106 
107  virtual OsStatus clear() ;
108  //: Clears any queued entries that have not yet been scheduled for play.
109  // These entries include streams added after invoking "play()".
110 
111  virtual OsStatus wait(const OsTime& rTimeout = OsTime::OS_INFINITY) ;
112  //: Wait until all play list items are finished playing
113 
114  OsStatus addListener(MpQueuePlayerListener* pListener) ;
115  //:Adds a player listener to receive notifications when this player
116  //:changes state
117 
118  OsStatus removeListener(MpQueuePlayerListener* pListener) ;
119  //:Removes a previously added player listener. This listener will
120  // cease to receive state change notifications.
121 
122 
124 
125 /* ============================ ACCESSORS ================================= */
127 
128 
130 
131 /* ============================ INQUIRY =================================== */
133 
134 
135  UtlBoolean isPlaying() ;
136  //:Is the Queue player playing (or about to play)
137 
138 
140 
141 /* //////////////////////////// PROTECTED ///////////////////////////////// */
142 protected:
143 
144  MpStreamQueuePlayer(const MpStreamQueuePlayer& rMpStreamQueuePlayer);
145  //:Copy constructor
146 
148  //:Assignment operator
149 
150  virtual UtlBoolean handleMessage(OsMsg& rMsg) ;
151  //:Handles an incoming message
152  // If the message is not one that the object is prepared to process,
153  // the handleMessage() method in the derived class should return FALSE
154  // which will cause the OsMessageTask::handleMessage() method to be
155  // invoked on the message.
156 
157  void handleReset() ;
158  void handlePlayNext() ;
159  void handleDequeue() ;
160  void handleRemoveFailed() ;
161 
162  UtlBoolean isPlayingStream(MpPlayer* pPlayer) ;
163  //:Is the specified player the active/playing stream?
164 
165  void setFailedPlayer(MpPlayer* pPlayer) ;
166  //:Designates the the player as failed
167 
168  virtual void playerRealized(MpPlayerEvent& event) ;
169  //: The player has been realized
170 
171  virtual void playerPrefetched(MpPlayerEvent& event) ;
172  //: The player's data source has been prefetched
173 
174  virtual void playerPlaying(MpPlayerEvent& event) ;
175  //: The player has begun playing.
176 
177  virtual void playerPaused(MpPlayerEvent& event) ;
178  //: The player has been paused
179 
180  virtual void playerStopped(MpPlayerEvent& event) ;
181  //: The player has been stopped
182 
183  virtual void playerFailed(MpPlayerEvent& event) ;
184  //: The player has failed
185 
186  void fireQueuePlayerStarted() ;
187  void fireQueuePlayerStopped() ;
188  void fireQueuePlayerAdvanced() ;
189 
190 
191 
192 /* //////////////////////////// PRIVATE /////////////////////////////////// */
193 private:
194  enum
195  {
200  } ;
201 
202  struct PlaylistQueue // Definition for a playlist entry
203  {
205  UtlBoolean bFailed ;
206  } ;
207 
208  OsMsgQ* mpMsgQ ; // Queue to deliever MpStreamMsg commands
209  UtlString mTarget ; // Target Id (CallId)
210  OsBSem mSemQueueChange; // Guard for queue changes
211  OsBSem mSemWaitSynch; // Gives some for block on for waiters
212 
213  OsQueuedEvent* mpQueueEvent; // Used for dequeuing
214 
215  struct PlaylistQueue* mToPlayQueue; // db of entries
216  int mToPlayQueueLength ; // Physical size of queue
217  int mNumToPlayElements ; // Current number of queued elements
218  struct PlaylistQueue* mPlayingQueue; // db of entries
220  int mNumPlayingElements ; // Current number of queued elements
221  UtlBoolean mbFatalError ; // Something REALLY bad has happened (can't create thread)
222 
223  int expandQueue(struct PlaylistQueue*& queue, int currentLength, int desiredLength) ;
224  void swapQueues(struct PlaylistQueue*& queue1, int& queueLength1,
225  struct PlaylistQueue*& queue2, int& queueLength2) ;
226 
227  struct PlayerListenerDb // Data structure used to maintain listeners
228  {
229  UtlBoolean inUse ; // Is the entry in use?
230  MpQueuePlayerListener* pListener ; // Reference to listener
231  } ;
232 
234  OsRWMutex mListenerMutex; // Used to make it thread-safe when adding/removing and using listeners
235 };
236 
237 /* ============================ INLINE METHODS ============================ */
238 
239 #endif // DISABLE_STREAM_PLAYER ]
240 
241 #endif // _MpStreamQueuePlayer_h_
OsStatus addListener(MpQueuePlayerListener *pListener)
Definition: MpStreamQueuePlayer.cpp:387
virtual OsStatus add(Url &url, int flags)
Definition: MpStreamQueuePlayer.cpp:144
virtual void playerPrefetched(MpPlayerEvent &event)
Definition: MpStreamQueuePlayer.cpp:812
OsQueuedEvent * mpQueueEvent
Definition: MpStreamQueuePlayer.h:213
Definition: MpPlayerListener.h:34
OsMsgQ * mpMsgQ
Definition: MpStreamQueuePlayer.h:208
PlayerListenerDb mListenerDb[MAX_PLAYER_LISTENERS]
Definition: MpStreamQueuePlayer.h:233
struct PlaylistQueue * mToPlayQueue
Definition: MpStreamQueuePlayer.h:215
UtlString mTarget
Definition: MpStreamQueuePlayer.h:209
virtual OsStatus wait(const OsTime &rTimeout=OsTime::OS_INFINITY)
Definition: MpStreamQueuePlayer.cpp:361
int expandQueue(struct PlaylistQueue *&queue, int currentLength, int desiredLength)
Definition: MpStreamQueuePlayer.cpp:944
OsRWMutex mListenerMutex
Definition: MpStreamQueuePlayer.h:234
void handleDequeue()
Definition: MpStreamQueuePlayer.cpp:629
virtual void playerStopped(MpPlayerEvent &event)
Definition: MpStreamQueuePlayer.cpp:845
Definition: MpStreamQueuePlayer.h:55
void fireQueuePlayerStopped()
Definition: MpStreamQueuePlayer.cpp:914
Definition: MpStreamQueuePlayer.h:197
virtual void playerPlaying(MpPlayerEvent &event)
Definition: MpStreamQueuePlayer.cpp:832
virtual void playerFailed(MpPlayerEvent &event)
Definition: MpStreamQueuePlayer.cpp:877
Definition: MpPlayer.h:92
void swapQueues(struct PlaylistQueue *&queue1, int &queueLength1, struct PlaylistQueue *&queue2, int &queueLength2)
Definition: MpStreamQueuePlayer.cpp:988
Definition: MpStreamQueuePlayer.h:63
SourceType
Definition: MpStreamQueuePlayer.h:60
Definition: MpStreamQueuePlayer.h:196
MpStreamQueuePlayer & operator=(const MpStreamQueuePlayer &rhs)
Definition: MpStreamQueuePlayer.cpp:472
UtlBoolean isPlaying()
Definition: MpStreamQueuePlayer.cpp:440
int mToPlayQueueLength
Definition: MpStreamQueuePlayer.h:216
void handleRemoveFailed()
Definition: MpStreamQueuePlayer.cpp:692
Definition: MpPlayerEvent.h:35
int mNumToPlayElements
Definition: MpStreamQueuePlayer.h:217
void setFailedPlayer(MpPlayer *pPlayer)
Definition: MpStreamQueuePlayer.cpp:754
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Definition: MpStreamQueuePlayer.cpp:484
void fireQueuePlayerStarted()
Definition: MpStreamQueuePlayer.cpp:901
OsBSem mSemQueueChange
Definition: MpStreamQueuePlayer.h:210
Definition: MpStreamQueuePlayer.h:202
Definition: MpStreamQueuePlayer.h:199
virtual void playerPaused(MpPlayerEvent &event)
Definition: MpStreamQueuePlayer.cpp:838
int mPlayingQueueLength
Definition: MpStreamQueuePlayer.h:219
virtual ~MpStreamQueuePlayer()
Definition: MpStreamQueuePlayer.cpp:80
void handleReset()
Definition: MpStreamQueuePlayer.cpp:533
void handlePlayNext()
Definition: MpStreamQueuePlayer.cpp:586
#define MAX_PLAYER_LISTENERS
Definition: MpPlayer.h:27
OsStatus removeListener(MpQueuePlayerListener *pListener)
Definition: MpStreamQueuePlayer.cpp:413
virtual OsStatus reset()
Definition: MpStreamQueuePlayer.cpp:286
OsBSem mSemWaitSynch
Definition: MpStreamQueuePlayer.h:211
virtual OsStatus clear()
Definition: MpStreamQueuePlayer.cpp:316
MpStreamQueuePlayer(OsMsgQ *pMsgQ, const char *pTarget=NULL)
Definition: MpStreamQueuePlayer.cpp:37
Definition: MpStreamPlayer.h:48
UtlBoolean inUse
Definition: MpStreamQueuePlayer.h:229
virtual OsStatus play()
param pBuffer - Net Buffer containing buffered audio data. The
Definition: MpStreamQueuePlayer.cpp:244
UtlBoolean mbFatalError
Definition: MpStreamQueuePlayer.h:221
Definition: MpStreamQueuePlayer.h:227
int mNumPlayingElements
Definition: MpStreamQueuePlayer.h:220
void fireQueuePlayerAdvanced()
Definition: MpStreamQueuePlayer.cpp:927
MpQueuePlayerListener * pListener
Definition: MpStreamQueuePlayer.h:230
virtual OsStatus destroy()
Definition: MpStreamQueuePlayer.cpp:305
UtlBoolean isPlayingStream(MpPlayer *pPlayer)
Definition: MpStreamQueuePlayer.cpp:677
struct PlaylistQueue * mPlayingQueue
Definition: MpStreamQueuePlayer.h:218
virtual void playerRealized(MpPlayerEvent &event)
Definition: MpStreamQueuePlayer.cpp:788
MpStreamPlayer * pPlayer
Definition: MpStreamQueuePlayer.h:204
Definition: MpStreamQueuePlayer.h:62
Definition: MpQueuePlayerListener.h:34
Definition: MpStreamQueuePlayer.h:198
UtlBoolean bFailed
Definition: MpStreamQueuePlayer.h:205