sipxmedialib  Version 3.3
StreamHttpDataSource.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 #ifndef DISABLE_STREAM_PLAYER // [
15 
16 #ifndef _StreamHttpDataSource_h_
17 #define _StreamHttpDataSource_h_
18 
19 // SYSTEM INCLUDES
20 // APPLICATION INCLUDES
21 #include "mp/StreamDataSource.h"
22 #include "net/Url.h"
23 #include "os/OsDefs.h"
24 #include "os/OsStatus.h"
25 #include "os/OsTask.h"
26 #include "os/OsBSem.h"
27 
28 
29 // DEFINES
30 #define DEFAULT_BUFFER_SIZE 128*1024
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 // STRUCTS
36 // FORWARD DECLARATIONS
37 class OsConnectionSocket ;
38 class HttpMessage ;
39 // TYPEDEFS
40 typedef UtlBoolean (*GetDataCallbackProc)(char* pData,
41  int iLength,
42  void* pOptionalData,
43  HttpMessage* pMsg);
44 
45 
47 
58 class StreamHttpDataSource : public StreamDataSource, public OsTask
59 {
60 /* //////////////////////////// PUBLIC //////////////////////////////////// */
61 public:
62 
63 /* ============================ CREATORS ================================== */
65 
66  StreamHttpDataSource(Url url, int iFlags);
68 
70  virtual ~StreamHttpDataSource();
71 
73 
74 /* ============================ MANIPULATORS ============================== */
76 
77  virtual OsStatus open() ;
79 
81  virtual OsStatus close() ;
82 
84  virtual OsStatus destroyAndDelete() ;
85 
88  virtual OsStatus read(char *szBuffer, int iLength, int& iLengthRead) ;
95  virtual OsStatus peek(char* szBuffer, int iLength, int& iLengthRead) ;
103  virtual OsStatus interrupt() ;
112  virtual OsStatus seek(unsigned int iLocation);
119  UtlBoolean deliverData(char *szData, int iLength, int iMaxLength) ;
121 
123 
124 /* ============================ ACCESSORS ================================= */
126 
127 
129  virtual OsStatus getLength(int& iLength);
130 
132  virtual OsStatus getPosition(int& iPosition) ;
133 
135  virtual OsStatus toString(UtlString& string) ;
136  // This is often used for debugging purposes.
137 
139  virtual int getBufferedLength();
140 
142 
143 /* ============================ INQUIRY =================================== */
145 
146 
148 
149 /* //////////////////////////// PROTECTED ///////////////////////////////// */
150 protected:
151 
153  StreamHttpDataSource(const StreamHttpDataSource& rStreamHttpDataSource);
154 
157 
159  int run(void *pArgs);
160 
161 /* //////////////////////////// PRIVATE /////////////////////////////////// */
162 private:
163  Url m_url ;
164  UtlString mBuffer ;
165  OsBSem mSemNeedData ;
166  OsBSem mSemLimitData ;
167  OsBSem mSemGuardData;
169  UtlBoolean mbDone ;
170  UtlBoolean mbQuit ;
171  UtlBoolean mbDeleteOnCompletion ;
172  unsigned int miMaxData ;
173  unsigned int miDSLength ;
174  unsigned int miOffset ;
175  unsigned int miBufferOffset ;
176  UtlBoolean mbFiredThrottledEvent ;
177  UtlBoolean mbClosed ;
178  UtlBoolean mbInterrupt ;
179 
180  static OsBSem sSemGuardDelete;
181 };
182 
183 /* ============================ INLINE METHODS ============================ */
184 
185 #endif // _StreamHttpDataSource_h_
186 
187 #endif // DISABLE_STREAM_PLAYER ]
int run(void *pArgs)
Thread entry point.
Definition: StreamHttpDataSource.cpp:497
virtual OsStatus seek(unsigned int iLocation)
Moves the stream pointer to the an absolute location.
Definition: StreamHttpDataSource.cpp:301
UtlBoolean mbClosed
Have we closed this down?
Definition: StreamHttpDataSource.h:177
An abstraction definition of a stream data source.
Definition: StreamDataSource.h:47
OsBSem mSemNeedData
Used block when we need more data.
Definition: StreamHttpDataSource.h:165
static OsBSem sSemGuardDelete
Guard deletion of data sources.
Definition: StreamHttpDataSource.h:180
virtual int getBufferedLength()
Gets the amount of data presently buffered.
Definition: StreamHttpDataSource.cpp:484
unsigned int miMaxData
Max amount of data to buffer.
Definition: StreamHttpDataSource.h:172
virtual ~StreamHttpDataSource()
Destructor.
Definition: StreamHttpDataSource.cpp:65
UtlBoolean mbDeleteOnCompletion
Should the run method delete the object?
Definition: StreamHttpDataSource.h:171
virtual OsStatus close()
Closes the data source.
Definition: StreamHttpDataSource.cpp:117
UtlString mBuffer
Buffered content.
Definition: StreamHttpDataSource.h:164
UtlBoolean mbQuit
Are we quiting?
Definition: StreamHttpDataSource.h:170
StreamHttpDataSource(Url url, int iFlags)
Default constructor.
Definition: StreamHttpDataSource.cpp:42
virtual OsStatus peek(char *szBuffer, int iLength, int &iLengthRead)
Identical to read, except the stream pointer is not advanced.
Definition: StreamHttpDataSource.cpp:244
Url m_url
Source url.
Definition: StreamHttpDataSource.h:163
unsigned int miBufferOffset
Buffer offset from start of stream.
Definition: StreamHttpDataSource.h:175
Defines a stream data source built on top of a Http Stream.
Definition: StreamHttpDataSource.h:58
UtlBoolean mbFiredThrottledEvent
Should fire event on next throttle?
Definition: StreamHttpDataSource.h:176
UtlBoolean deliverData(char *szData, int iLength, int iMaxLength)
Callback routine that is invoked whenever new data is available from http socket. ...
Definition: StreamHttpDataSource.cpp:369
UtlBoolean(* GetDataCallbackProc)(char *pData, int iLength, void *pOptionalData, HttpMessage *pMsg)
Definition: StreamHttpDataSource.h:40
virtual OsStatus read(char *szBuffer, int iLength, int &iLengthRead)
Definition: StreamHttpDataSource.cpp:176
UtlBoolean mbInterrupt
Interrupt current operation?
Definition: StreamHttpDataSource.h:178
virtual OsStatus open()
Opens the data source.
Definition: StreamHttpDataSource.cpp:73
virtual OsStatus toString(UtlString &string)
Renders a string describing this data source.
Definition: StreamHttpDataSource.cpp:447
unsigned int miDSLength
Data Stream Length.
Definition: StreamHttpDataSource.h:173
OsBSem mSemGuardData
Protected data structures.
Definition: StreamHttpDataSource.h:167
OsBSem mSemLimitData
Used to block when need to throttle.
Definition: StreamHttpDataSource.h:166
OsBSem mSemGuardStartClose
Protected Opening/Closing the DataSource.
Definition: StreamHttpDataSource.h:168
virtual OsStatus interrupt()
Interrupts any time consuming operation.
Definition: StreamHttpDataSource.cpp:288
virtual OsStatus getPosition(int &iPosition)
Gets the current position within the stream.
Definition: StreamHttpDataSource.cpp:436
virtual OsStatus destroyAndDelete()
Destroys and deletes the data source object.
Definition: StreamHttpDataSource.cpp:152
virtual OsStatus getLength(int &iLength)
Gets the length of the stream (if available)
Definition: StreamHttpDataSource.cpp:422
StreamHttpDataSource & operator=(const StreamHttpDataSource &rhs)
Assignment operator (not supported)
Definition: StreamHttpDataSource.cpp:475
unsigned int miOffset
Present offset into the buffer.
Definition: StreamHttpDataSource.h:174
UtlBoolean mbDone
Is the data source complete.
Definition: StreamHttpDataSource.h:169