sipxmedialib  Version 3.3
MpPlayer.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 _MpPlayer_h_
16 #define _MpPlayer_h_
17 
18 // SYSTEM INCLUDES
19 
20 // APPLICATION INCLUDES
21 #include "mp/StreamDefs.h"
22 #include "os/OsDefs.h"
23 #include "os/OsStatus.h"
24 #include "os/OsMutex.h"
25 
26 // DEFINES
27 #define MAX_PLAYER_LISTENERS 16 // Max number of player listeners
28 
29 
30 // MACROS
31 // EXTERNAL FUNCTIONS
32 // EXTERNAL VARIABLES
33 // CONSTANTS
34 // STRUCTS
35 // TYPEDEFS
36 
37 //:Definition of states used by audio players
38 typedef enum
39 {
49 } PlayerState ;
51 // resources have been allocated.
54 // the entire data source or just enough to ensure smooth playback.
61 // a call to stop() (as opposed to normal playing).
62 
63 // FORWARD DECLARATIONS
64 class MpPlayerListener ;
65 
66 
67 //:Defines a stream player control that allows users to realize, start, stop,
68 //:and pause an audio source.
69 //
70 // <pre>
71 // +-----------------------------------+
72 // \ / |
73 // ------------ ------------ --------- ---------
74 // | Unrealized | ---> | Prefetched | <---> | Playing | ---> | Stopped |
75 // ------------ ------------ --------- ---------
76 // / \ .
77 // |
78 // \ /
79 // -------- --------
80 // | Failed | <--* | Paused |
81 // -------- --------
82 //
83 // -----------
84 // | Destroyed | <--*
85 // -----------
86 //
87 // ---------
88 // | Aborted | <--*
89 // ---------
90 
91 // </pre>
92 class MpPlayer
93 {
94 /* //////////////////////////// PUBLIC //////////////////////////////////// */
95 public:
96 
97  typedef enum // Type of players
98  {
102  } playerType;
103 
104 /* ============================ CREATORS ================================== */
105  MpPlayer();
106  //:Default Constructor
107 
108  virtual ~MpPlayer();
109  //:Destructor
110 
112 
113 /* ============================ MANIPULATORS ============================== */
115 
116  virtual OsStatus realize(UtlBoolean bBlock = TRUE) = 0;
117  //: Realizes the player by initiating a connection to the target,
118  //: allocates buffers, etc.
119  //
121  // otherwise FALSE.
122 
123  virtual OsStatus prefetch(UtlBoolean bBlock = TRUE) = 0 ;
124  //: Prefetch enough of the data source to ensure a smooth playback.
125  //
127  // otherwise FALSE.
128 
129  virtual OsStatus play(UtlBoolean bBlock = TRUE) = 0 ;
130  //: Plays the media stream.
131  //
133  // otherwise FALSE.
134 
135  virtual OsStatus pause() = 0 ;
136  //: Pauses the media stream temporarily.
137 
138  virtual OsStatus stop() = 0 ;
139  //: Stops playing the media stream and resources used for buffering
140  //: and streaming.
141 
142  virtual OsStatus destroy() = 0 ;
143  //: Marks the player as destroy and frees all allocated resources
144  // in media processing.
145 
146  OsStatus addListener(MpPlayerListener* pListener, void* pUserData = NULL) ;
147  //:Adds a player listener to receive notifications when this player
148  //:changes state
149 
150  OsStatus removeListener(MpPlayerListener* pListener) ;
151  //:Removes a previously added player listener. This listener will
152  // cease to receive state change notifications.
153 
154 
156 
157 /* ============================ ACCESSORS ================================= */
159 
160 
161  virtual OsStatus getState(PlayerState& state) = 0 ;
162  //: Gets the player state
163 
165 
166 /* ============================ INQUIRY =================================== */
168 
169 
170 /* ============================ TESTING =================================== */
171 
172 #ifdef MP_STREAM_DEBUG /* [ */
173 static const char* getEventString(PlayerState event);
174 #endif /* MP_STREAM_DEBUG ] */
175 
176 
178 
179 /* //////////////////////////// PROTECTED ///////////////////////////////// */
180 protected:
181 
182  void fireEvent(PlayerState state);
183  //:Fires an event to all registered listeners
184 
185  UtlBoolean isValidStateChange(PlayerState oldState, PlayerState newState) ;
186  //:Is the transition from oldState to newState valid?
187 
188 /* //////////////////////////// PRIVATE /////////////////////////////////// */
189 private:
190 
191  struct PlayerListenerDb // Data structure used to maintain listeners
192  {
193  UtlBoolean inUse ; // Is the entry in use?
194  MpPlayerListener* pListener ; // Reference to listener
195  void* pUserData; // User data specified when added
196  } ;
197 
198 
200  OsMutex mListenerLock ;
201 };
202 
203 /* ============================ INLINE METHODS ============================ */
204 
205 #endif // _MpPlayer_h_
Definition: MpPlayer.h:40
Definition: MpPlayer.h:47
Definition: MpPlayerListener.h:34
Definition: MpPlayer.h:101
Definition: MpPlayer.h:191
void fireEvent(PlayerState state)
Definition: MpPlayer.cpp:156
virtual OsStatus prefetch(UtlBoolean bBlock=TRUE)=0
param bBlock - TRUE if the method should block until completion,
MpPlayer()
Definition: MpPlayer.cpp:33
Definition: MpPlayer.h:92
virtual OsStatus play(UtlBoolean bBlock=TRUE)=0
param bBlock - TRUE if the method should block until completion,
Definition: MpPlayer.h:43
OsMutex mListenerLock
Definition: MpPlayer.h:200
PlayerListenerDb mListenerDb[MAX_PLAYER_LISTENERS]
Definition: MpPlayer.h:199
void * pUserData
Definition: MpPlayer.h:195
OsStatus removeListener(MpPlayerListener *pListener)
Definition: MpPlayer.cpp:83
Definition: MpPlayer.h:42
Definition: MpPlayer.h:100
MpPlayerListener * pListener
Definition: MpPlayer.h:194
virtual ~MpPlayer()
Definition: MpPlayer.cpp:45
virtual OsStatus realize(UtlBoolean bBlock=TRUE)=0
Definition: MpPlayer.h:45
#define MAX_PLAYER_LISTENERS
Definition: MpPlayer.h:27
Definition: MpPlayer.h:99
virtual OsStatus destroy()=0
virtual OsStatus getState(PlayerState &state)=0
UtlBoolean isValidStateChange(PlayerState oldState, PlayerState newState)
Definition: MpPlayer.cpp:202
PlayerState
Definition: MpPlayer.h:38
UtlBoolean inUse
Definition: MpPlayer.h:193
Definition: MpPlayer.h:48
Definition: MpPlayer.h:46
Definition: MpPlayer.h:44
virtual OsStatus pause()=0
param bBlock - TRUE if the method should block until completion,
OsStatus addListener(MpPlayerListener *pListener, void *pUserData=NULL)
Definition: MpPlayer.cpp:54
Definition: MpPlayer.h:41
virtual OsStatus stop()=0
#define TRUE
Definition: PlgDefsV1.h:41
playerType
Definition: MpPlayer.h:97