Public Types | Public Member Functions

gnash::DiskStream Class Reference

#include <diskstream.h>

Collaboration diagram for gnash::DiskStream:
Collaboration graph
[legend]

List of all members.

Public Types

enum  state_e {
  NO_STATE, CREATED, CLOSED, OPEN,
  PLAY, PREVIEW, THUMBNAIL, PAUSE,
  SEEK, UPLOAD, MULTICAST, DONE
}
enum  filetype_e {
  FILETYPE_NONE, FILETYPE_AMF, FILETYPE_SWF, FILETYPE_HTML,
  FILETYPE_PNG, FILETYPE_JPEG, FILETYPE_GIF, FILETYPE_MP3,
  FILETYPE_MP4, FILETYPE_OGG, FILETYPE_VORBIS, FILETYPE_THEORA,
  FILETYPE_DIRAC, FILETYPE_TEXT, FILETYPE_FLV, FILETYPE_VP6,
  FILETYPE_XML, FILETYPE_FLAC, FILETYPE_ENCODED, FILETYPE_PHP
}

Public Member Functions

DSOEXPORT DiskStream ()
DSOEXPORT DiskStream (const std::string &filespec)
DSOEXPORT DiskStream (const std::string &filespec, cygnal::Buffer &buf)
DSOEXPORT DiskStream (const std::string &filespec, boost::uint8_t *data, size_t size)
DSOEXPORT DiskStream (const std::string &filespec, int netfd)
DSOEXPORT ~DiskStream ()
DSOEXPORT void close ()
 Close the open disk file and it's associated stream.
DSOEXPORT bool open (const std::string &filespec)
 Open a file to be streamed.
DSOEXPORT bool open (const std::string &filespec, int netfd)
DSOEXPORT bool open (const std::string &filespec, int netfd, gnash::Statistics &statistics)
bool play ()
 Stream the file that has been loaded,.
bool play (bool flag)
bool play (int netfd, bool flag)
 Stream the file that has been loaded,.
bool preview (const std::string &filespec, int frames)
 Stream a preview of the file. A preview is a series of video frames from the video file. Each video frame is taken by sampling the file at a set interval.
bool thumbnail (const std::string &filespec, int quantity)
 Stream a series of thumbnails. A thumbnail is a series of jpg images of frames from the video file instead of video frames. Each thumbnail is taken by sampling the file at a set interval.
bool pause ()
 Pause the stream currently being played.
boost::uint8_t * seek (off_t offset)
 Seek within the stream.
bool upload (const std::string &filespec)
 Upload a file into a sandbox. The sandbox is an area where uploaded files can get written to safely. For SWF content, the file name also includes a few optional paths used to seperate applications from each other.
bool multicast (const std::string &filespec)
DSOEXPORT boost::uint8_t * loadToMem (size_t filesize, off_t offset)
 Load a chunk of the file into memory This offset must be a multipe of the pagesize.
DSOEXPORT boost::uint8_t * loadToMem (off_t offset)
 Load a chunk (pagesize) of the file into memory. This loads a pagesize of the disk file into memory. We read the file this way as it is faster and takes less resources than read(), which add buffering we don't need. This offset must be a multipe of the pagesize.
DSOEXPORT boost::uint8_t * loadToMem ()
DSOEXPORT bool writeToDisk (const std::string &filespec, boost::uint8_t *data, size_t size)
 Write the data in memory to disk.
DSOEXPORT bool writeToDisk (const std::string &filespec, cygnal::Buffer &data)
DSOEXPORT bool writeToDisk (const std::string &filespec)
DSOEXPORT bool writeToDisk ()
 Write the data in memory to disk.
bool writeToNet (int start, int bytes)
 Write the existing data to the Network.
size_t getPagesize ()
 Get the memory page size This is a cached value of the system configuration value for the default size in bytes of a memory page.
void setPagesize (size_t size)
 Set the memory page size This is a cached value of the system configuration value for the default size in bytes of a memory page.
DiskStreamoperator= (DiskStream *stream)
 copy another DiskStream into ourselves, so they share data in memory.
void dump ()
 Dump the internal data of this class in a human readable form.
boost::uint8_t * get ()
 Get the base address for the memory page.
bool fullyPopulated ()
size_t getFileSize ()
 Get the size of the file.
DiskStream::filetype_e getFileType ()
std::string & getFilespec ()
void setFilespec (std::string filespec)
struct timespec * getLastAccessTime ()
 Get the time of the last access.
state_e getState ()
void setState (state_e state)
int getFileFd ()
int getNetFd ()
void dump () const
 Dump the internal data of this class in a human readable form.
void dump (std::ostream &os) const

Detailed Description

This class handles the loading of files into memory. Instead of using read() from the standard library, this uses mmap() to map the file into memory in chunks of the memory pagesize, which is much faster and less resource intensive.


Member Enumeration Documentation

Enumerator:
FILETYPE_NONE 
FILETYPE_AMF 
FILETYPE_SWF 
FILETYPE_HTML 
FILETYPE_PNG 
FILETYPE_JPEG 
FILETYPE_GIF 
FILETYPE_MP3 
FILETYPE_MP4 
FILETYPE_OGG 
FILETYPE_VORBIS 
FILETYPE_THEORA 
FILETYPE_DIRAC 
FILETYPE_TEXT 
FILETYPE_FLV 
FILETYPE_VP6 
FILETYPE_XML 
FILETYPE_FLAC 
FILETYPE_ENCODED 
FILETYPE_PHP 
Enumerator:
NO_STATE 
CREATED 
CLOSED 
OPEN 
PLAY 
PREVIEW 
THUMBNAIL 
PAUSE 
SEEK 
UPLOAD 
MULTICAST 
DONE 

Constructor & Destructor Documentation

gnash::DiskStream::DiskStream (  ) 

get the pagesize and cache the value

References _SC_PAGESIZE, CLOCK_REALTIME, and gnash::MAX_PAGES.

DSOEXPORT gnash::DiskStream::DiskStream ( const std::string &  filespec  ) 
DSOEXPORT gnash::DiskStream::DiskStream ( const std::string &  filespec,
cygnal::Buffer buf 
)
DSOEXPORT gnash::DiskStream::DiskStream ( const std::string &  filespec,
boost::uint8_t *  data,
size_t  size 
)
DSOEXPORT gnash::DiskStream::DiskStream ( const std::string &  filespec,
int  netfd 
)
gnash::DiskStream::~DiskStream (  ) 

References close().


Member Function Documentation

void gnash::DiskStream::close ( void   ) 

Close the open disk file and it's associated stream.

Close the open disk file, but stay resident in memory.

References free(), and MAP_FAILED.

Referenced by loadToMem(), main(), play(), writeToDisk(), and ~DiskStream().

void gnash::DiskStream::dump (  )  const [inline]

Dump the internal data of this class in a human readable form.

Remarks:
This should only be used for debugging purposes.

References dump().

Referenced by dump().

void gnash::DiskStream::dump ( std::ostream &  os  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void gnash::DiskStream::dump (  ) 

Dump the internal data of this class in a human readable form.

Remarks:
This should only be used for debugging purposes.

References CLOCK_REALTIME.

Referenced by gnash::operator<<().

bool gnash::DiskStream::fullyPopulated (  ) 
boost::uint8_t* gnash::DiskStream::get (  )  [inline]

Get the base address for the memory page.

Returns:
A real pointer to the base address data in the file, but after the header bytes.

Referenced by main(), and operator=().

int gnash::DiskStream::getFileFd (  )  [inline]

Referenced by operator=().

size_t gnash::DiskStream::getFileSize (  )  [inline]

Get the size of the file.

Returns:
A value that is the size of the file in bytes.
std::string& gnash::DiskStream::getFilespec (  )  [inline]

Referenced by operator=().

DiskStream::filetype_e gnash::DiskStream::getFileType (  )  [inline]

Referenced by operator=().

struct timespec* gnash::DiskStream::getLastAccessTime (  )  [inline, read]

Get the time of the last access.

Returns:
A real pointer to the struct timespec of the last access.
int gnash::DiskStream::getNetFd (  )  [inline]

Referenced by operator=().

size_t gnash::DiskStream::getPagesize (  )  [inline]

Get the memory page size This is a cached value of the system configuration value for the default size in bytes of a memory page.

Returns:
the currently cached memory page size.

Referenced by main().

state_e gnash::DiskStream::getState (  )  [inline]

Referenced by operator=().

DSOEXPORT boost::uint8_t* gnash::DiskStream::loadToMem (  )  [inline]

References loadToMem().

Referenced by loadToMem(), play(), and seek().

boost::uint8_t * gnash::DiskStream::loadToMem ( size_t  filesize,
off_t  offset 
)

Load a chunk of the file into memory This offset must be a multipe of the pagesize.

Parameters:
size The amount of bytes to read, often the filesize for smaller files below CACHE_LIMIT.
offset The location in bytes in the file of the desired data.
Returns:
A real pointer to the location of the data at the location pointed to by the offset.

We only map memory in pages of pagesize, so if the offset is smaller than that, start at page 0.

If the data pointer is legit, then we need to unmap that page to mmap() a new one. If we're still in the current mapped page, then just return the existing data pointer.

References _, __FUNCTION__, CLOCK_REALTIME, close(), errno, FILETYPE_FLV, free(), gnash::key::i, malloc(), MAP_FAILED, and cygnal::Flv::TAG_METADATA.

Referenced by main().

boost::uint8_t * gnash::DiskStream::loadToMem ( off_t  offset  ) 

Load a chunk (pagesize) of the file into memory. This loads a pagesize of the disk file into memory. We read the file this way as it is faster and takes less resources than read(), which add buffering we don't need. This offset must be a multipe of the pagesize.

Parameters:
size The amount of bytes to read, often the filesize for smaller files below CACHE_LIMIT.
offset The location in bytes in the file of the desired data.
Returns:
A real pointer to the location of the data at the location pointed to by the offset.

References loadToMem().

bool gnash::DiskStream::multicast ( const std::string &  filespec  ) 
DSOEXPORT bool gnash::DiskStream::open ( const std::string &  filespec  ) 

Open a file to be streamed.

Parameters:
filespec The full path and file name for the data to be read. The file must already exist.
netfd An optional file descriptor to read data from
statistics The optional data structure to use for collecting statistics on this stream.
Returns:
True if the file was opened successfully, false if not.

Referenced by main(), and writeToDisk().

DSOEXPORT bool gnash::DiskStream::open ( const std::string &  filespec,
int  netfd,
gnash::Statistics statistics 
)
DSOEXPORT bool gnash::DiskStream::open ( const std::string &  filespec,
int  netfd 
)
DiskStream & gnash::DiskStream::operator= ( DiskStream stream  ) 

copy another DiskStream into ourselves, so they share data in memory.

References get(), getFileFd(), getFilespec(), getFileType(), getNetFd(), and getState().

bool gnash::DiskStream::pause (  ) 

Pause the stream currently being played.

Returns:
True if the stream was paused successfully, false if not.

References __PRETTY_FUNCTION__.

bool gnash::DiskStream::play (  ) 

Stream the file that has been loaded,.

Parameters:
netfd An optional file descriptor to read data from
flag True to play the entire file, false to play part.
Returns:
True if the data was streamed successfully, false if not.
True if the data was streamed successfully, false if not.

Referenced by play().

bool gnash::DiskStream::play ( bool  flag  ) 

References play().

bool gnash::DiskStream::play ( int  netfd,
bool  flag 
)

Stream the file that has been loaded,.

Parameters:
netfd The file descriptor to use for operations
flag True to only send the first packet, False plays entire file.
Returns:
True if the data was streamed successfully, false if not.

References __FUNCTION__, gnash::NetStats::addBytes(), close(), CLOSED, CREATED, DONE, errno, loadToMem(), MULTICAST, NO_STATE, OPEN, PAUSE, PLAY, PREVIEW, SEEK, THUMBNAIL, UPLOAD, and gnash::Network::writeNet().

bool gnash::DiskStream::preview ( const std::string &  filespec,
int  frames 
)

Stream a preview of the file. A preview is a series of video frames from the video file. Each video frame is taken by sampling the file at a set interval.

Parameters:
filespec The full path and file name for the data to be read.
quantity The number of frames to stream..
Returns:
True if the thumbnails were streamed successfully, false if not.
boost::uint8_t * gnash::DiskStream::seek ( off_t  offset  ) 

Seek within the stream.

Parameters:
the offset in bytes to the location within the file to seek to.
Returns:
A real pointer to the location of the data seeked to.

References loadToMem().

void gnash::DiskStream::setFilespec ( std::string  filespec  )  [inline]
void gnash::DiskStream::setPagesize ( size_t  size  )  [inline]

Set the memory page size This is a cached value of the system configuration value for the default size in bytes of a memory page.

Parameters:
size The size of a page of memory to cache.
Returns:
nothing.
void gnash::DiskStream::setState ( state_e  state  )  [inline]
bool gnash::DiskStream::thumbnail ( const std::string &  filespec,
int  quantity 
)

Stream a series of thumbnails. A thumbnail is a series of jpg images of frames from the video file instead of video frames. Each thumbnail is taken by sampling the file at a set interval.

Parameters:
filespec The full path and file name for the data to be read.
quantity The number of thumbnails to stream..
Returns:
True if the thumbnails were streamed successfully, false if not.
bool gnash::DiskStream::upload ( const std::string &  filespec  ) 

Upload a file into a sandbox. The sandbox is an area where uploaded files can get written to safely. For SWF content, the file name also includes a few optional paths used to seperate applications from each other.

Parameters:
filespec The file name for the data to be written.
Returns:
True if the file was uploaded successfully, false if not.
bool gnash::DiskStream::writeToDisk (  ) 

Write the data in memory to disk.

Parameters:
filespec The relative path to the file to write, which goes in a safebox for storage.
Returns:
true if the operation suceeded, false if it failed.

Referenced by writeToDisk().

bool gnash::DiskStream::writeToDisk ( const std::string &  filespec  ) 

References writeToDisk().

bool gnash::DiskStream::writeToDisk ( const std::string &  filespec,
cygnal::Buffer data 
)
bool gnash::DiskStream::writeToDisk ( const std::string &  filespec,
boost::uint8_t *  data,
size_t  size 
)

Write the data in memory to disk.

Parameters:
filespec The relative path to the file to write, which goes in a safebox for storage.
data The data to be written
size The amount of data in bytes to be written
Returns:
true if the operation suceeded, false if it failed.

References close(), errno, open(), and gnash::amf::write().

Referenced by cygnal::HTTPServer::processPostRequest().

bool gnash::DiskStream::writeToNet ( int  start,
int  bytes 
)

Write the existing data to the Network.

Returns:
true is the write suceeded, false if it failed.

The documentation for this class was generated from the following files: