Gnash  0.8.10
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:
gnash::media::ffmpeg::MediaParserFfmpeg gnash::media::FLVParser gnash::media::gst::MediaParserGst gnash::media::haiku::MediaParserHaiku

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 bool isBufferEmpty () const
 Return true if both audio and video buffers are empty.
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.
virtual boost::optional< Id3InfogetId3Info () const
 Get ID3 data from the parsed stream if it exists.
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.
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 gnash::media::FLVParser::parseNextChunk(), and waitIfNeeded().

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

Retrieve any parsed metadata tags up to a specified timestamp.

Parameters:
tsThe latest timestamp to retrieve metadata for.
tagsThis 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 _bufferTimeMutex, and _bufferTime.

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.

boost::optional< Id3Info > gnash::media::MediaParser::getId3Info ( ) const [virtual]

Get ID3 data from the parsed stream if it exists.

It's best to do this only when parsingComplete is true.

Reimplemented in gnash::media::gst::MediaParserGst, and gnash::media::ffmpeg::MediaParserFfmpeg.

References _.

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().

bool gnash::media::MediaParser::isBufferEmpty ( ) const

Return true if both audio and video buffers are empty.

NOTE: locks _qMutex

References _qMutex.

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 _qMutex, parsingCompleted(), _audioInfo, parseNextChunk(), and _parserThreadWakeup.

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)

NOTE: locks _qMutex

References _qMutex, 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:
tswill be set to timestamp of next available frame
Returns:
false if no frame is available yet

NOTE: locks _qMutex

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

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 _qMutex, parsingCompleted(), _videoInfo, parseNextChunk(), and _parserThreadWakeup.

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)

NOTE: locks _qMutex

References _qMutex, 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::FLVParser, gnash::media::gst::MediaParserGst, gnash::media::ffmpeg::MediaParserFfmpeg, and gnash::media::haiku::MediaParserHaiku.

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

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, parserThreadKillRequested(), parseNextChunk(), gnash::gnashSleep(), _qMutex, 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 nextFrameTimestamp(), nextVideoFrame(), nextAudioFrame(), and waitIfNeeded().

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::i, gnash::key::e, 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::i, gnash::key::e, 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:
timeinput/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::FLVParser, gnash::media::gst::MediaParserGst, gnash::media::ffmpeg::MediaParserFfmpeg, 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:
tNumber of milliseconds to keep in the buffers.

References _bufferTimeMutex, _bufferTime, and gnash::key::t.

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 gnash::media::FLVParser::~FLVParser(), ~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 parsingCompleted(), indexingCompleted(), bufferFull(), parserThreadKillRequested(), and _parserThreadWakeup.

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

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

Member Data Documentation

Info about the audio stream (if any)

Referenced by nextAudioFrame(), getAudioInfo(), and gnash::media::gst::MediaParserGst::MediaParserGst().

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]
std::auto_ptr<boost::thread> gnash::media::MediaParser::_parserThread [protected]

Referenced by startParserThread(), and parserLoop().

boost::condition gnash::media::MediaParser::_parserThreadWakeup [protected]
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.

Referenced by gnash::media::FLVParser::seek().

std::auto_ptr<IOChannel> gnash::media::MediaParser::_stream [protected]
boost::mutex gnash::media::MediaParser::_streamMutex [mutable, protected]

Subclasses *must* set the following variables:

Info about the video stream (if any)

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


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