sipxmedialib  Version 3.3
Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
StreamHttpDataSource Class Reference

Defines a stream data source built on top of a Http Stream. More...

#include <StreamHttpDataSource.h>

Inheritance diagram for StreamHttpDataSource:
Inheritance graph
[legend]
Collaboration diagram for StreamHttpDataSource:
Collaboration graph
[legend]

Public Member Functions

Creators
 StreamHttpDataSource (Url url, int iFlags)
 Default constructor. More...
 
virtual ~StreamHttpDataSource ()
 Destructor. More...
 
Manipulators
virtual OsStatus open ()
 Opens the data source. More...
 
virtual OsStatus close ()
 Closes the data source. More...
 
virtual OsStatus destroyAndDelete ()
 Destroys and deletes the data source object. More...
 
virtual OsStatus read (char *szBuffer, int iLength, int &iLengthRead)
 
virtual OsStatus peek (char *szBuffer, int iLength, int &iLengthRead)
 Identical to read, except the stream pointer is not advanced. More...
 
virtual OsStatus interrupt ()
 Interrupts any time consuming operation. More...
 
virtual OsStatus seek (unsigned int iLocation)
 Moves the stream pointer to the an absolute location. More...
 
UtlBoolean deliverData (char *szData, int iLength, int iMaxLength)
 Callback routine that is invoked whenever new data is available from http socket. More...
 
Accessors
virtual OsStatus getLength (int &iLength)
 Gets the length of the stream (if available) More...
 
virtual OsStatus getPosition (int &iPosition)
 Gets the current position within the stream. More...
 
virtual OsStatus toString (UtlString &string)
 Renders a string describing this data source. More...
 
virtual int getBufferedLength ()
 Gets the amount of data presently buffered. More...
 
- Public Member Functions inherited from StreamDataSource
 StreamDataSource (int iFlags=0)
 Constructors a StreamDataSource given optional flags. More...
 
virtual ~StreamDataSource ()
 Destructor. More...
 
void setListener (StreamDataSourceListener *pListener)
 
int getFlags ()
 Gets the flags specified at time of construction. More...
 

Protected Member Functions

 StreamHttpDataSource (const StreamHttpDataSource &rStreamHttpDataSource)
 Copy constructor (not supported) More...
 
StreamHttpDataSourceoperator= (const StreamHttpDataSource &rhs)
 Assignment operator (not supported) More...
 
int run (void *pArgs)
 Thread entry point. More...
 
- Protected Member Functions inherited from StreamDataSource
 StreamDataSource (const StreamDataSource &rStreamDataSource)
 Copy constructor (not supported) More...
 
StreamDataSourceoperator= (const StreamDataSource &rhs)
 Assignment operator (not supported) More...
 
void fireEvent (StreamDataSourceEvent event)
 Fires a data source event to the interested consumer. More...
 

Private Attributes

Url m_url
 Source url. More...
 
UtlString mBuffer
 Buffered content. More...
 
OsBSem mSemNeedData
 Used block when we need more data. More...
 
OsBSem mSemLimitData
 Used to block when need to throttle. More...
 
OsBSem mSemGuardData
 Protected data structures. More...
 
OsBSem mSemGuardStartClose
 Protected Opening/Closing the DataSource. More...
 
UtlBoolean mbDone
 Is the data source complete. More...
 
UtlBoolean mbQuit
 Are we quiting? More...
 
UtlBoolean mbDeleteOnCompletion
 Should the run method delete the object? More...
 
unsigned int miMaxData
 Max amount of data to buffer. More...
 
unsigned int miDSLength
 Data Stream Length. More...
 
unsigned int miOffset
 Present offset into the buffer. More...
 
unsigned int miBufferOffset
 Buffer offset from start of stream. More...
 
UtlBoolean mbFiredThrottledEvent
 Should fire event on next throttle? More...
 
UtlBoolean mbClosed
 Have we closed this down? More...
 
UtlBoolean mbInterrupt
 Interrupt current operation? More...
 

Static Private Attributes

static OsBSem sSemGuardDelete
 Guard deletion of data sources. More...
 

Detailed Description

Defines a stream data source built on top of a Http Stream.

Deletion of this class is very problematic, because the thread that pumps the data from the stream may be blocked for a long period of time and most cases the media task is player destroying this resource. Ideally, we would interrupt the socket read, however, that is not possible. So, to avoid blocking the thread context used to destroy this object, we use a variable mbDeleteOnCompletion to mark if/when we need to destroy this class once the run method has completed. This method is wrapped in a static binary semaphore to guard against races.

Constructor & Destructor Documentation

StreamHttpDataSource ( Url  url,
int  iFlags 
)

Default constructor.

~StreamHttpDataSource ( )
virtual

Destructor.

StreamHttpDataSource ( const StreamHttpDataSource rStreamHttpDataSource)
protected

Copy constructor (not supported)

Member Function Documentation

OsStatus open ( )
virtual

Opens the data source.

Implements StreamDataSource.

OsStatus close ( )
virtual

Closes the data source.

Implements StreamDataSource.

OsStatus destroyAndDelete ( )
virtual

Destroys and deletes the data source object.

Implements StreamDataSource.

OsStatus read ( char *  szBuffer,
int  iLength,
int &  iLengthRead 
)
virtual

Reads iLength bytes of data from the data source and places the data into the passed szBuffer buffer.

Parameters
szBuffer- Buffer to place data
iLength- Max length to read
iLengthRead- The actual amount of data read.

Implements StreamDataSource.

OsStatus peek ( char *  szBuffer,
int  iLength,
int &  iLengthRead 
)
virtual

Identical to read, except the stream pointer is not advanced.

Parameters
szBuffer- Buffer to place data
iLength- Max length to read
iLengthRead- The actual amount of data read.

Implements StreamDataSource.

OsStatus interrupt ( )
virtual

Interrupts any time consuming operation.

For example, some data sources may require network access (e.g. http) to read or fetch data. Invoking an interrupt() will cause any time consuming or blocking calls to exit with more quickly with an OS_INTERRUPTED return code.

Reimplemented from StreamDataSource.

OsStatus seek ( unsigned int  iLocation)
virtual

Moves the stream pointer to the an absolute location.

Parameters
iLocation- The desired seek location

Implements StreamDataSource.

UtlBoolean deliverData ( char *  szData,
int  iLength,
int  iMaxLength 
)

Callback routine that is invoked whenever new data is available from http socket.

OsStatus getLength ( int &  iLength)
virtual

Gets the length of the stream (if available)

Implements StreamDataSource.

OsStatus getPosition ( int &  iPosition)
virtual

Gets the current position within the stream.

Implements StreamDataSource.

OsStatus toString ( UtlString &  string)
virtual

Renders a string describing this data source.

Implements StreamDataSource.

int getBufferedLength ( )
virtual

Gets the amount of data presently buffered.

StreamHttpDataSource & operator= ( const StreamHttpDataSource rhs)
protected

Assignment operator (not supported)

int run ( void *  pArgs)
protected

Thread entry point.

Member Data Documentation

Url m_url
private

Source url.

UtlString mBuffer
private

Buffered content.

OsBSem mSemNeedData
private

Used block when we need more data.

OsBSem mSemLimitData
private

Used to block when need to throttle.

OsBSem mSemGuardData
private

Protected data structures.

OsBSem mSemGuardStartClose
private

Protected Opening/Closing the DataSource.

UtlBoolean mbDone
private

Is the data source complete.

UtlBoolean mbQuit
private

Are we quiting?

UtlBoolean mbDeleteOnCompletion
private

Should the run method delete the object?

unsigned int miMaxData
private

Max amount of data to buffer.

unsigned int miDSLength
private

Data Stream Length.

unsigned int miOffset
private

Present offset into the buffer.

unsigned int miBufferOffset
private

Buffer offset from start of stream.

UtlBoolean mbFiredThrottledEvent
private

Should fire event on next throttle?

UtlBoolean mbClosed
private

Have we closed this down?

UtlBoolean mbInterrupt
private

Interrupt current operation?

OsBSem sSemGuardDelete
staticprivate

Guard deletion of data sources.