Public Types | Public Member Functions

gnash::media::MediaParser Class Reference

The MediaParser class provides cursor-based access to encoded media frames. More...

#include <MediaParser.h>

Inheritance diagram for gnash::media::MediaParser:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::multimap
< boost::uint64_t,
boost::shared_ptr
< SimpleBuffer > > 
MetaTags
 A container for executable MetaTags contained in media streams.
typedef std::vector
< MetaTags::mapped_type > 
OrderedMetaTags

Public Member Functions

 MediaParser (std::auto_ptr< IOChannel > stream)
virtual ~MediaParser ()
virtual bool seek (boost::uint32_t &time)=0
 Seeks to the closest possible position the given position, and returns the new position.
DSOEXPORT boost::uint64_t getBufferLength () const
 Returns mininum length of available buffers in milliseconds.
DSOEXPORT boost::uint64_t getBufferTime () const
 Return the time we want the parser thread to maintain in the buffer.
DSOEXPORT void setBufferTime (boost::uint64_t t)
 Set the time we want the parser thread to maintain in the buffer.
DSOEXPORT bool nextFrameTimestamp (boost::uint64_t &ts) const
 Get timestamp of the next frame available, if any.
DSOEXPORT bool nextVideoFrameTimestamp (boost::uint64_t &ts) const
 Get timestamp of the video frame which would be returned on nextVideoFrame.
DSOEXPORT std::auto_ptr
< EncodedVideoFrame
nextVideoFrame ()
 Returns the next video frame in the parsed buffer, advancing video cursor.
DSOEXPORT bool nextAudioFrameTimestamp (boost::uint64_t &ts) const
 Get timestamp of the audio frame which would be returned on nextAudioFrame.
DSOEXPORT std::auto_ptr
< EncodedAudioFrame
nextAudioFrame ()
 Returns the next audio frame in the parsed buffer, advancing audio cursor.
VideoInfogetVideoInfo ()
 Returns a VideoInfo class about the videostream.
AudioInfogetAudioInfo ()
 Returns a AudioInfo class about the audiostream.
bool parsingCompleted () const
 Return true of parsing is completed.
virtual bool indexingCompleted () const
 Return true of indexing is completed.
virtual boost::uint64_t getBytesLoaded () const
 Return number of bytes parsed so far.
boost::uint64_t getBytesTotal () const
 Return total number of bytes in input.
virtual bool parseNextChunk ()=0
 Parse next chunk of input.
virtual void fetchMetaTags (OrderedMetaTags &tags, boost::uint64_t ts)
 Retrieve any parsed metadata tags up to a specified timestamp.



std::auto_ptr< VideoInfo_videoInfo
 Subclasses *must* set the following variables:
std::auto_ptr< AudioInfo_audioInfo
 Info about the audio stream (if any).
bool _parsingComplete
 Whether the parsing is complete or not.
boost::uint64_t _bytesLoaded
 Number of bytes loaded.
std::auto_ptr< IOChannel_stream
 The stream used to access the file.
boost::mutex _streamMutex
boost::uint64_t _bufferTime
boost::mutex _bufferTimeMutex
std::auto_ptr< boost::thread > _parserThread
boost::barrier _parserThreadStartBarrier
boost::mutex _parserThreadKillRequestMutex
bool _parserThreadKillRequested
boost::condition _parserThreadWakeup
boost::mutex _qMutex
 mutex protecting access to the a/v encoded frames queues
boost::mutex _bytesLoadedMutex
 Mutex protecting _bytesLoaded (read by main, set by parser).
bool _seekRequest
void startParserThread ()
 }@
void stopParserThread ()
 Stop the parser thread.
void clearBuffers ()
 Clear the a/v buffers.
void pushEncodedAudioFrame (std::auto_ptr< EncodedAudioFrame > frame)
 Push an encoded audio frame to buffer.
void pushEncodedVideoFrame (std::auto_ptr< EncodedVideoFrame > frame)
 Push an encoded video frame to buffer.
const EncodedVideoFramepeekNextVideoFrame () const
 Return pointer to next encoded video frame in buffer.
const EncodedAudioFramepeekNextAudioFrame () const
 Return pointer to next encoded audio frame in buffer.
void parserLoop ()
bool parserThreadKillRequested () const
void waitIfNeeded (boost::mutex::scoped_lock &qMutexLock)
void wakeupParserThread ()
bool bufferFull () const
 Method to check if buffer is full w/out locking the _qMutex.
static void parserLoopStarter (MediaParser *mp)

Detailed Description

The MediaParser class provides cursor-based access to encoded media frames.

Cursor-based access allow seeking as close as possible to a specified time and fetching frames from there on, sequentially. See seek(), nextVideoFrame(), nextAudioFrame()

Input is received from a IOChannel object.


Member Typedef Documentation

typedef std::multimap<boost::uint64_t, boost::shared_ptr<SimpleBuffer> > gnash::media::MediaParser::MetaTags

A container for executable MetaTags contained in media streams.

Presently only known in FLV.

typedef std::vector<MetaTags::mapped_type> gnash::media::MediaParser::OrderedMetaTags

Constructor & Destructor Documentation

gnash::media::MediaParser::MediaParser ( std::auto_ptr< IOChannel stream  ) 
gnash::media::MediaParser::~MediaParser (  )  [virtual]

Member Function Documentation

bool gnash::media::MediaParser::bufferFull (  )  const [protected]

Method to check if buffer is full w/out locking the _qMutex.

This is intended for being called by waitIfNeeded, which is passed a locked lock on _qMutex, and by parseNextChunk to determine whether to index-only or also push on queue.

References getBufferTime().

Referenced by waitIfNeeded().

void gnash::media::MediaParser::clearBuffers (  )  [protected]

Clear the a/v buffers.

References _parserThreadWakeup, _qMutex, gnash::key::e, and gnash::key::i.

void gnash::media::MediaParser::fetchMetaTags ( OrderedMetaTags tags,
boost::uint64_t  ts 
) [virtual]

Retrieve any parsed metadata tags up to a specified timestamp.

Parameters:
ts The latest timestamp to retrieve metadata for.
tags This is filled with shared pointers to metatags in timestamp order. Ownership of the data is shared. It is destroyed automatically along with the last owner. Metadata is currently only parsed from FLV streams. The default is a no-op.

Reimplemented in gnash::media::FLVParser.

AudioInfo* gnash::media::MediaParser::getAudioInfo (  )  [inline]

Returns a AudioInfo class about the audiostream.

Returns:
a AudioInfo class about the audiostream, or zero if unknown (no audio or not enough data parsed yet).

References _audioInfo.

boost::uint64_t gnash::media::MediaParser::getBufferLength (  )  const

Returns mininum length of available buffers in milliseconds.

TODO: FIXME: NOTE: this is currently used by NetStream.bufferLength but is bogus as it doesn't take the *current* playhead cursor time into account. A proper way would be having a getLastBufferTime () interface here, returning minimun timestamp of last available frames and let NetSTream::bufferLength() use that with playhead time to find out...

References _qMutex.

DSOEXPORT boost::uint64_t gnash::media::MediaParser::getBufferTime (  )  const [inline]

Return the time we want the parser thread to maintain in the buffer.

References _bufferTime, and _bufferTimeMutex.

Referenced by bufferFull().

virtual boost::uint64_t gnash::media::MediaParser::getBytesLoaded (  )  const [inline, virtual]
boost::uint64_t gnash::media::MediaParser::getBytesTotal (  )  const [inline]

Return total number of bytes in input.

References _stream.

VideoInfo* gnash::media::MediaParser::getVideoInfo (  )  [inline]

Returns a VideoInfo class about the videostream.

Returns:
a VideoInfo class about the videostream, or zero if unknown (no video or not enough data parsed yet).

References _videoInfo.

virtual bool gnash::media::MediaParser::indexingCompleted (  )  const [inline, virtual]

Return true of indexing is completed.

If this function returns false, parseNextChunk will be called even when buffers are full. Parsers supporting indexing separated from parsing should override this method and have parseNextChunk figure if they only need to index or to parse based on bufferFull.

Reimplemented in gnash::media::FLVParser.

Referenced by waitIfNeeded().

std::auto_ptr< EncodedAudioFrame > gnash::media::MediaParser::nextAudioFrame (  ) 

Returns the next audio frame in the parsed buffer, advancing audio cursor.

If no frame has been played before the first frame is returned. If there is no more frames in the parsed buffer NULL is returned. you can check with parsingCompleted() to know wheter this is due to EOF reached.

References _audioInfo, _parserThreadWakeup, _qMutex, parseNextChunk(), and parsingCompleted().

bool gnash::media::MediaParser::nextAudioFrameTimestamp ( boost::uint64_t &  ts  )  const

Get timestamp of the audio frame which would be returned on nextAudioFrame.

Returns:
false if there no video frame left (either none or no more)

References peekNextAudioFrame(), and gnash::media::EncodedAudioFrame::timestamp.

bool gnash::media::MediaParser::nextFrameTimestamp ( boost::uint64_t &  ts  )  const

Get timestamp of the next frame available, if any.

Parameters:
ts will be set to timestamp of next available frame
Returns:
false if no frame is available yet

References _qMutex, _videoInfo, parseNextChunk(), and parsingCompleted().

std::auto_ptr< EncodedVideoFrame > gnash::media::MediaParser::nextVideoFrame (  ) 

Returns the next video frame in the parsed buffer, advancing video cursor.

If no frame has been played before the first frame is returned. If there is no more frames in the parsed buffer NULL is returned. you can check with parsingCompleted() to know wheter this is due to EOF reached.

References _parserThreadWakeup, _qMutex, _videoInfo, parseNextChunk(), and parsingCompleted().

bool gnash::media::MediaParser::nextVideoFrameTimestamp ( boost::uint64_t &  ts  )  const

Get timestamp of the video frame which would be returned on nextVideoFrame.

Returns:
false if there no video frame left (either none or no more)

References peekNextVideoFrame(), and gnash::media::EncodedVideoFrame::timestamp().

virtual bool gnash::media::MediaParser::parseNextChunk (  )  [pure virtual]

Parse next chunk of input.

The implementations are required to parse a small chunk of input, so to avoid blocking too much if parsing conditions change (ie: seek or destruction requested)

When LOAD_MEDIA_IN_A_SEPARATE_THREAD is defined, this should never be called by users (consider protected).

Implemented in gnash::media::ffmpeg::MediaParserFfmpeg, gnash::media::FLVParser, gnash::media::gst::MediaParserGst, and gnash::media::haiku::MediaParserHaiku.

Referenced by nextAudioFrame(), nextFrameTimestamp(), nextVideoFrame(), parserLoop(), peekNextAudioFrame(), and peekNextVideoFrame().

void gnash::media::MediaParser::parserLoop (  )  [protected]

The parser loop runs in a separate thread and calls parseNextChunk until killed.

parseNextChunk is expected to push encoded frames on the queue, which may trigger the thread to be put to sleep when queues are full or parsing was completed.

References _parserThreadStartBarrier, _qMutex, gnash::gnashSleep(), parseNextChunk(), parserThreadKillRequested(), and waitIfNeeded().

Referenced by parserLoopStarter().

static void gnash::media::MediaParser::parserLoopStarter ( MediaParser mp  )  [inline, static, protected]

References parserLoop().

Referenced by startParserThread().

bool gnash::media::MediaParser::parserThreadKillRequested (  )  const [inline, protected]
bool gnash::media::MediaParser::parsingCompleted (  )  const [inline]

Return true of parsing is completed.

If this function returns true, any call to nextVideoFrame() or nextAudioFrame() will always return NULL

TODO: make thread-safe

References _parsingComplete.

Referenced by nextAudioFrame(), nextFrameTimestamp(), nextVideoFrame(), peekNextAudioFrame(), peekNextVideoFrame(), and waitIfNeeded().

const EncodedAudioFrame * gnash::media::MediaParser::peekNextAudioFrame (  )  const [protected]

Return pointer to next encoded audio frame in buffer.

If no video is present, or queue is empty, 0 is returned

References _audioInfo, _qMutex, parseNextChunk(), and parsingCompleted().

Referenced by nextAudioFrameTimestamp().

const EncodedVideoFrame * gnash::media::MediaParser::peekNextVideoFrame (  )  const [protected]

Return pointer to next encoded video frame in buffer.

If no video is present, or queue is empty, 0 is returned

References _qMutex, _videoInfo, parseNextChunk(), and parsingCompleted().

Referenced by nextVideoFrameTimestamp().

void gnash::media::MediaParser::pushEncodedAudioFrame ( std::auto_ptr< EncodedAudioFrame frame  )  [protected]

Push an encoded audio frame to buffer.

Will wait on a condition if buffer is full or parsing was completed

References _qMutex, gnash::key::e, gnash::key::i, and waitIfNeeded().

void gnash::media::MediaParser::pushEncodedVideoFrame ( std::auto_ptr< EncodedVideoFrame frame  )  [protected]

Push an encoded video frame to buffer.

Will wait on a condition if buffer is full or parsing was completed

References _qMutex, gnash::key::e, gnash::key::i, and waitIfNeeded().

virtual bool gnash::media::MediaParser::seek ( boost::uint32_t &  time  )  [pure virtual]

Seeks to the closest possible position the given position, and returns the new position.

Parameters:
time input/output parameter, input requests a time, output return the actual time seeked to.
Returns:
true if the seek was valid, false otherwise.

Implemented in gnash::media::ffmpeg::MediaParserFfmpeg, gnash::media::FLVParser, gnash::media::gst::MediaParserGst, and gnash::media::haiku::MediaParserHaiku.

DSOEXPORT void gnash::media::MediaParser::setBufferTime ( boost::uint64_t  t  )  [inline]

Set the time we want the parser thread to maintain in the buffer.

Parameters:
t Number of milliseconds to keep in the buffers.

References _bufferTime, and _bufferTimeMutex.

void gnash::media::MediaParser::startParserThread (  )  [protected]
void gnash::media::MediaParser::stopParserThread (  )  [protected]

Stop the parser thread.

This method should be always called by destructors of subclasses to ensure the parser thread won't attempt to access destroyed structures.

References _parserThread.

Referenced by ~MediaParser(), gnash::media::ffmpeg::MediaParserFfmpeg::~MediaParserFfmpeg(), and gnash::media::gst::MediaParserGst::~MediaParserGst().

void gnash::media::MediaParser::waitIfNeeded ( boost::mutex::scoped_lock &  qMutexLock  )  [protected]

Wait on the _parserThreadWakeup condition if buffer is full or parsing was completed.

Callers *must* pass a locked lock on _qMutex

References _parserThreadWakeup, bufferFull(), indexingCompleted(), parserThreadKillRequested(), and parsingCompleted().

Referenced by parserLoop(), pushEncodedAudioFrame(), and pushEncodedVideoFrame().

void gnash::media::MediaParser::wakeupParserThread (  )  [protected]

Member Data Documentation

boost::uint64_t gnash::media::MediaParser::_bufferTime [protected]

Referenced by getBufferTime(), and setBufferTime().

boost::mutex gnash::media::MediaParser::_bufferTimeMutex [mutable, protected]

Referenced by getBufferTime(), and setBufferTime().

boost::uint64_t gnash::media::MediaParser::_bytesLoaded [protected]
boost::mutex gnash::media::MediaParser::_bytesLoadedMutex [mutable, protected]

Mutex protecting _bytesLoaded (read by main, set by parser).

Referenced by gnash::media::gst::MediaParserGst::getBytesLoaded(), and gnash::media::gst::MediaParserGst::parseNextChunk().

std::auto_ptr<boost::thread> gnash::media::MediaParser::_parserThread [protected]

Referenced by parserLoop(), and startParserThread().

boost::condition gnash::media::MediaParser::_parserThreadWakeup [protected]

Whether the parsing is complete or not.

Referenced by gnash::media::gst::MediaParserGst::parseNextChunk(), and parsingCompleted().

boost::mutex gnash::media::MediaParser::_qMutex [mutable, protected]

On seek, this flag will be set, while holding a lock on _streamMutex. The parser, when obtained a lock on _streamMutex, will check this flag, if found to be true will clear the buffers and reset to false.

std::auto_ptr<IOChannel> gnash::media::MediaParser::_stream [protected]

The stream used to access the file.

Referenced by getBytesTotal(), and gnash::media::gst::MediaParserGst::parseNextChunk().

boost::mutex gnash::media::MediaParser::_streamMutex [mutable, protected]

Subclasses *must* set the following variables:

Info about the video stream (if any)

Referenced by getVideoInfo(), gnash::media::gst::MediaParserGst::MediaParserGst(), nextFrameTimestamp(), nextVideoFrame(), and peekNextVideoFrame().


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