sipxmedialib  Version 3.3
MpStreamPlayer.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 _MpStreamPlayer_h_
16 #define _MpStreamPlayer_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/OsDefs.h"
27 #include "os/OsServerTask.h"
28 #include "os/OsStatus.h"
29 
30 // DEFINES
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 // STRUCTS
36 // TYPEDEFS
37 // FORWARD DECLARATIONS
38 class UtlString;
39 class OsQueuedEvent;
40 
41 //: Player capable of controlling a single audio source (Url or Buffer).
42 //
43 // NOTE: This player creates and communicates with a number of objects within
44 // the flowgraph, primarily MpStreamFeeder. However, the creating and
45 // connection to these objects are not made until the "realize" method
46 // is invoked.
47 //
48 class MpStreamPlayer : public OsServerTask, public MpPlayer
49 {
50 /* //////////////////////////// PUBLIC //////////////////////////////////// */
51 public:
52 
53  typedef enum // Type of source data (url or buffer)
54  {
57  } SourceType;
58 
59 /* ============================ CREATORS ================================== */
61 
62  MpStreamPlayer(OsMsgQ* pMsg, Url url, int flags, const char* pTarget = NULL) ;
63  //:Contructs a stream player given a msgq, stream url, and
64  //:playing flags.
65  //
70  // dispatching
71 
72  MpStreamPlayer(OsMsgQ* pMsg, UtlString* pBuffer, int flags, const char* pTarget = NULL) ;
73  //:Constructs a stream player given a msgq, net buffer, and
74  //:playing flags.
75  //
78  // MpStreamPlayer resource will delete the pBuffer upon destruction
79  // of itself.
82  // dispatching
83 
84  virtual ~MpStreamPlayer();
85  //:Destructor
86 
88 
89 /* ============================ MANIPULATORS ============================== */
91 
92  virtual OsStatus realize(UtlBoolean bBlock = TRUE);
93  //: Realizes the player by initiating a connection to the target,
94  //: allocates buffers, etc.
95  //
97  // otherwise FALSE.
98 
99  virtual OsStatus prefetch(UtlBoolean bBlock = TRUE);
100  //: Prefetch enough of the data source to ensure a smooth playback.
101  //
103  // otherwise FALSE.
104 
105  virtual OsStatus play(UtlBoolean bBlock = TRUE);
106  //: Plays the media stream.
107  //
109  // otherwise FALSE.
110 
111  virtual OsStatus rewind(UtlBoolean bBlock = TRUE);
112  //: Rewinds a previously played media stream. In some cases this
113  // may result in a re-connect/refetch.
114  //
116  // otherwise FALSE.
117 
118  virtual OsStatus pause();
119  //: Pauses the media stream temporarily.
120 
121  OsStatus setLoopCount(int iLoopCount);
122  //: sets the loop count.
123  //: default is 1. -1 means infinite loop.
124  //: 0 is invalid.
125 
126  virtual OsStatus stop();
127  //: Stops play the media stream and resources used for buffering
128  //: and streaming.
129 
130  virtual OsStatus destroy() ;
131  //: Marks the player as destroy and frees all allocated resources
132  // in media processing.
133 
134  virtual void waitForDestruction() ;
135  //: Blocks until the the lower layer stream player is destroyed
136 
138 
139 /* ============================ ACCESSORS ================================= */
141 
142 
143  virtual OsStatus getState(PlayerState& state) ;
144  //: Gets the player state
145 
146  virtual OsStatus getSourceType(int& iType) const;
147  //: Gets the source type for this player (SourceUrl or SourceBuffer)
148 
149  virtual OsStatus getSourceUrl(Url& url) const;
150  //: Gets the url if the source type is a SourceUrl
151 
152  virtual OsStatus getSourceBuffer(UtlString*& pBuffer) const;
153  //: Gets the source buffer if the source type is a SourceBuffer
154 
156 
157 /* ============================ INQUIRY =================================== */
159 
160 
162 
163 /* //////////////////////////// PROTECTED ///////////////////////////////// */
164 protected:
165 
166  MpStreamPlayer(const MpStreamPlayer& rMpStreamPlayer);
167  //:Copy constructor (not supported)
168 
170  //:Assignment operator (not supported)
171 
172  virtual UtlBoolean handleMessage(OsMsg& rMsg) ;
173  //:Handles OS server task events/messages
174 
175  void setState(PlayerState iState);
176  //:Sets the internal state for this resource
177 
179  //: Gets the player state; internal use
180 
181 /* //////////////////////////// PRIVATE /////////////////////////////////// */
182 private:
183 
184  OsMsgQ* mpMsgQ;
185  int mSourceType; // Data source type (buffer | url)
186  Url mUrl; // Url for our stream (if specified)
187  UtlString* mpBuffer; // Buffer data source (if specified)
188  PlayerState mState; // Present state of the player
189  StreamHandle mHandle; // StreamHandle from lower layers
190  UtlString mTarget; // target id (callId)
191  int mFlags; // Player Flags
192  OsQueuedEvent* mpQueueEvent; // Used for comm. w/ Flowgraph
193  OsBSem mSemStateChange;// Synch for state changes
194  OsBSem mSemStateGuard; // Guard for state changes
195  int miLoopCount; // default is 1. -1 means infinite loop.
196  // 0 is invalid.
198  UtlBoolean mbRealized; // Has this player been realized?
199 
200 };
201 
202 /* ============================ INLINE METHODS ============================ */
203 
204 #endif // DISABLE_STREAM_PLAYER ]
205 
206 #endif // _MpStreamPlayer_h_
virtual OsStatus pause()
param bBlock - TRUE if the method should block until completion,
Definition: MpStreamPlayer.cpp:347
virtual OsStatus play(UtlBoolean bBlock=TRUE)
param bBlock - TRUE if the method should block until completion,
Definition: MpStreamPlayer.cpp:264
SourceType
Definition: MpStreamPlayer.h:53
virtual OsStatus realize(UtlBoolean bBlock=TRUE)
Definition: MpStreamPlayer.cpp:117
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Definition: MpStreamPlayer.cpp:575
MpStreamPlayer & operator=(const MpStreamPlayer &rhs)
Definition: MpStreamPlayer.cpp:522
int mSourceType
Definition: MpStreamPlayer.h:185
void setState(PlayerState iState)
Definition: MpStreamPlayer.cpp:650
virtual void waitForDestruction()
Definition: MpStreamPlayer.cpp:441
Definition: MpStreamPlayer.h:55
Definition: MpPlayer.h:92
MpStreamPlayer(OsMsgQ *pMsg, Url url, int flags, const char *pTarget=NULL)
Definition: MpStreamPlayer.cpp:35
Url mUrl
Definition: MpStreamPlayer.h:186
UtlBoolean mbRealized
Definition: MpStreamPlayer.h:198
int miTimesAlreadyLooped
Definition: MpStreamPlayer.h:197
int miLoopCount
Definition: MpStreamPlayer.h:195
virtual OsStatus destroy()
Definition: MpStreamPlayer.cpp:405
void * StreamHandle
Handles used by the renderer.
Definition: StreamDefs.h:42
OsStatus setLoopCount(int iLoopCount)
Definition: MpStreamPlayer.cpp:335
virtual OsStatus prefetch(UtlBoolean bBlock=TRUE)
param bBlock - TRUE if the method should block until completion,
Definition: MpStreamPlayer.cpp:236
virtual ~MpStreamPlayer()
Definition: MpStreamPlayer.cpp:99
virtual OsStatus rewind(UtlBoolean bBlock=TRUE)
param bBlock - TRUE if the method should block until completion,
Definition: MpStreamPlayer.cpp:301
OsQueuedEvent * mpQueueEvent
Definition: MpStreamPlayer.h:192
PlayerState getState()
Definition: MpStreamPlayer.cpp:681
virtual OsStatus getSourceType(int &iType) const
Definition: MpStreamPlayer.cpp:471
virtual OsStatus getSourceUrl(Url &url) const
Definition: MpStreamPlayer.cpp:480
UtlString mTarget
Definition: MpStreamPlayer.h:190
OsBSem mSemStateChange
Definition: MpStreamPlayer.h:193
PlayerState
Definition: MpPlayer.h:38
Definition: MpStreamPlayer.h:48
int mFlags
Definition: MpStreamPlayer.h:191
virtual OsStatus stop()
Definition: MpStreamPlayer.cpp:368
OsMsgQ * mpMsgQ
Definition: MpStreamPlayer.h:184
PlayerState mState
Definition: MpStreamPlayer.h:188
OsBSem mSemStateGuard
Definition: MpStreamPlayer.h:194
Definition: MpStreamPlayer.h:56
#define TRUE
Definition: PlgDefsV1.h:41
virtual OsStatus getSourceBuffer(UtlString *&pBuffer) const
Definition: MpStreamPlayer.cpp:495
UtlString * mpBuffer
Definition: MpStreamPlayer.h:187
StreamHandle mHandle
Definition: MpStreamPlayer.h:189