[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F... |
Date: |
Fri, 23 May 2008 16:48:12 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/05/23 16:48:12
Modified files:
. : ChangeLog
libbase : FLVParser.cpp FLVParser.h
Log message:
* libbase/FLVParser.{cpp,h}: add peekNextVideoFrameInfo
and peekNextAudioFrameInfo to check timestamp of next frame
w/out advancing cursor; make parseNextTag public to be
eventually used from a parser thread; drop embedded
mutex locking as we'll want to control mutexes from outside.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6693&r2=1.6694
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/FLVParser.cpp?cvsroot=gnash&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/FLVParser.h?cvsroot=gnash&r1=1.29&r2=1.30
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6693
retrieving revision 1.6694
diff -u -b -r1.6693 -r1.6694
--- ChangeLog 23 May 2008 15:27:29 -0000 1.6693
+++ ChangeLog 23 May 2008 16:48:10 -0000 1.6694
@@ -1,5 +1,13 @@
2008-05-23 Sandro Santilli <address@hidden>
+ * libbase/FLVParser.{cpp,h}: add peekNextVideoFrameInfo
+ and peekNextAudioFrameInfo to check timestamp of next frame
+ w/out advancing cursor; make parseNextTag public to be
+ eventually used from a parser thread; drop embedded
+ mutex locking as we'll want to control mutexes from outside.
+
+2008-05-23 Sandro Santilli <address@hidden>
+
* server/asobj/NetStream.{cpp,h}: Add PlayHead class implementation.
2008-05-23 Benjamin Wolsey <address@hidden>
Index: libbase/FLVParser.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/FLVParser.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- libbase/FLVParser.cpp 21 May 2008 08:51:21 -0000 1.38
+++ libbase/FLVParser.cpp 23 May 2008 16:48:11 -0000 1.39
@@ -115,28 +115,26 @@
}
-boost::uint32_t FLVParser::getBufferLength()
+boost::uint32_t
+FLVParser::getBufferLength()
{
- boost::mutex::scoped_lock lock(_mutex);
-
if (_video) {
size_t size = _videoFrames.size();
if (size > 1 && size > _nextVideoFrame) {
- return _videoFrames.back()->timestamp -
_videoFrames[_nextVideoFrame]->timestamp;
+ return _videoFrames.back()->timestamp; // -
_videoFrames[_nextVideoFrame]->timestamp;
}
}
if (_audio) {
size_t size = _audioFrames.size();
if (size > 1 && size > _nextAudioFrame) {
- return _audioFrames.back()->timestamp -
_audioFrames[_nextAudioFrame]->timestamp;
+ return _audioFrames.back()->timestamp; // -
_audioFrames[_nextAudioFrame]->timestamp;
}
}
return 0;
}
-boost::uint16_t FLVParser::videoFrameRate()
+boost::uint16_t
+FLVParser::videoFrameRate()
{
- boost::mutex::scoped_lock lock(_mutex);
-
// Make sure that there are parsed some frames
while(_videoFrames.size() < 2 && !_parsingComplete) {
parseNextTag();
@@ -150,10 +148,9 @@
}
-boost::uint32_t FLVParser::videoFrameDelay()
+boost::uint32_t
+FLVParser::videoFrameDelay()
{
- boost::mutex::scoped_lock lock(_mutex);
-
// If there are no video in this FLV return 0
if (!_video && _lastParsedPosition > 0) return 0;
@@ -168,10 +165,9 @@
return _videoFrames[_nextVideoFrame-1]->timestamp -
_videoFrames[_nextVideoFrame-2]->timestamp;
}
-boost::uint32_t FLVParser::audioFrameDelay()
+boost::uint32_t
+FLVParser::audioFrameDelay()
{
- boost::mutex::scoped_lock lock(_mutex);
-
// If there are no audio in this FLV return 0
if (!_audio && _lastParsedPosition > 0) return 0;
@@ -186,87 +182,32 @@
return _audioFrames[_nextAudioFrame-1]->timestamp -
_audioFrames[_nextAudioFrame-2]->timestamp;
}
-FLVFrame* FLVParser::nextMediaFrame()
+FLVAudioFrameInfo*
+FLVParser::peekNextAudioFrameInfo()
{
- boost::mutex::scoped_lock lock(_mutex);
-
- boost::uint32_t video_size = _videoFrames.size();
- boost::uint32_t audio_size = _audioFrames.size();
-
- if (audio_size <= _nextAudioFrame && video_size <= _nextVideoFrame)
- {
+ // If there are no audio in this FLV return NULL
+ if (!_audio && _lastParsedPosition > 0) return 0;
- // Parse a media frame if any left or if needed
- while(_videoFrames.size() <= _nextVideoFrame &&
_audioFrames.size() <= _nextAudioFrame && !_parsingComplete) {
+ // Make sure that there are parsed enough frames to return the need
frame
+ while(_audioFrames.size() <= _nextAudioFrame && !_parsingComplete) {
if (!parseNextTag()) break;
}
- }
-
- // Find the next frame in the file
- bool audioReady = _audioFrames.size() > _nextAudioFrame;
- bool videoReady = _videoFrames.size() > _nextVideoFrame;
- bool useAudio = false;
-
- if (audioReady && videoReady) {
- useAudio = _audioFrames[_nextAudioFrame]->dataPosition <
_videoFrames[_nextVideoFrame]->dataPosition;
- } else if (!audioReady && videoReady) {
- useAudio = false;
- } else if (audioReady && !videoReady) {
- useAudio = true;
- } else {
- // If no frames are next we have reached EOF
- return NULL;
- }
-
- // Find the next frame in the file a return it
-
- if (useAudio) {
-
- FLVAudioFrameInfo* frameInfo = _audioFrames[_nextAudioFrame];
-
- std::auto_ptr<FLVFrame> frame = makeAudioFrame(_lt, *frameInfo);
- if ( ! frame.get() )
- {
- log_error("Could not make audio frame %d",
_nextAudioFrame);
- return 0;
- }
- _nextAudioFrame++;
- return frame.release(); // TODO: return by auto_ptr
-
- } else {
-
- FLVVideoFrameInfo* frameInfo = _videoFrames[_nextVideoFrame];
- std::auto_ptr<FLVFrame> frame = makeVideoFrame(_lt, *frameInfo);
- if ( ! frame.get() )
+ // If the needed frame can't be parsed (EOF reached) return NULL
+ if (_audioFrames.empty() || _audioFrames.size() <= _nextAudioFrame)
{
- log_error("Could not make video frame %d",
_nextVideoFrame);
return 0;
}
- _nextVideoFrame++;
- return frame.release(); // TODO: return by auto_ptr
- }
-
-
+ return _audioFrames[_nextAudioFrame];
}
-FLVFrame* FLVParser::nextAudioFrame()
+FLVFrame*
+FLVParser::nextAudioFrame()
{
- boost::mutex::scoped_lock lock(_mutex);
+ FLVAudioFrameInfo* frameInfo = peekNextAudioFrameInfo();
+ if ( ! frameInfo ) return 0;
- // If there are no audio in this FLV return NULL
- if (!_audio && _lastParsedPosition > 0) return NULL;
-
- // Make sure that there are parsed enough frames to return the need
frame
- while(_audioFrames.size() <= _nextAudioFrame && !_parsingComplete) {
- if (!parseNextTag()) break;
- }
-
- // If the needed frame can't be parsed (EOF reached) return NULL
- if (_audioFrames.size() <= _nextAudioFrame || _audioFrames.size() == 0)
return NULL;
-
- FLVAudioFrameInfo* frameInfo = _audioFrames[_nextAudioFrame];
std::auto_ptr<FLVFrame> frame = makeAudioFrame(_lt, *frameInfo);
if ( ! frame.get() )
{
@@ -279,15 +220,14 @@
}
-FLVFrame* FLVParser::nextVideoFrame()
+FLVVideoFrameInfo*
+ FLVParser::peekNextVideoFrameInfo()
{
- boost::mutex::scoped_lock lock(_mutex);
-
// If there are no video in this FLV return NULL
if (!_video && _lastParsedPosition > 0)
{
//gnash::log_debug("no video, or lastParserPosition > 0");
- return NULL;
+ return 0;
}
// Make sure that there are parsed enough frames to return the need
frame
@@ -297,14 +237,18 @@
}
// If the needed frame can't be parsed (EOF reached) return NULL
- if (_videoFrames.size() <= _nextVideoFrame || _videoFrames.size() == 0)
+ if (_videoFrames.empty() || _videoFrames.size() <= _nextVideoFrame)
{
//gnash::log_debug("The needed frame (%d) can't be parsed (EOF
reached)", _lastVideoFrame);
- return NULL;
+ return 0;
}
- // TODO: let a function do this
- FLVVideoFrameInfo* frameInfo = _videoFrames[_nextVideoFrame];
+ return _videoFrames[_nextVideoFrame];
+}
+
+FLVFrame* FLVParser::nextVideoFrame()
+{
+ FLVVideoFrameInfo* frameInfo = peekNextVideoFrameInfo();
std::auto_ptr<FLVFrame> frame = makeVideoFrame(_lt, *frameInfo);
if ( ! frame.get() )
{
@@ -483,8 +427,6 @@
FLVVideoInfo* FLVParser::getVideoInfo()
{
- boost::mutex::scoped_lock lock(_mutex);
-
// If there are no video in this FLV return NULL
if (!_video && _lastParsedPosition > 0) return NULL;
@@ -496,9 +438,6 @@
FLVAudioInfo* FLVParser::getAudioInfo()
{
-
- boost::mutex::scoped_lock lock(_mutex);
-
// If there are no audio in this FLV return NULL
if (!_audio && _lastParsedPosition > 0) return NULL;
@@ -511,10 +450,9 @@
return _audioInfo.get(); // may be null
}
-bool FLVParser::isTimeLoaded(boost::uint32_t time)
+bool
+FLVParser::isTimeLoaded(boost::uint32_t time)
{
- boost::mutex::scoped_lock lock(_mutex);
-
// Parse frames until the need time is found, or EOF
while (!_parsingComplete) {
if (!parseNextTag()) break;
@@ -536,10 +474,9 @@
}
-boost::uint32_t FLVParser::seek(boost::uint32_t time)
+boost::uint32_t
+FLVParser::seek(boost::uint32_t time)
{
- boost::mutex::scoped_lock lock(_mutex);
-
if (time == 0) {
if (_video) _nextVideoFrame = 0;
if (_audio) _nextAudioFrame = 0;
@@ -747,6 +684,18 @@
return (in[0] << 16) | (in[1] << 8) | in[2];
}
+boost::uint64_t
+FLVParser::getBytesLoaded() const
+{
+ return _lastParsedPosition;
+}
+
+boost::uint64_t
+FLVParser::getBytesTotal() const
+{
+ return _lt.get_size();
+}
+
} // end of gnash namespace
#undef PADDING_BYTES
Index: libbase/FLVParser.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/FLVParser.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- libbase/FLVParser.h 12 May 2008 08:33:15 -0000 1.29
+++ libbase/FLVParser.h 23 May 2008 16:48:11 -0000 1.30
@@ -26,7 +26,6 @@
#include "LoadThread.h"
#include "dsodefs.h"
#include <vector>
-#include <boost/thread/mutex.hpp>
#include <memory>
namespace gnash {
@@ -156,7 +155,7 @@
/// and fetching frames from there on, sequentially.
/// See seek(), nextVideoFrame(), nextAudioFrame() and nextMediaFrame().
///
-/// Input is received from a LoadThread object.
+/// Input is received from a tu_file object.
///
class DSOEXPORT FLVParser
{
@@ -204,39 +203,56 @@
/// @param lt
/// LoadThread to use for input.
/// Ownership left to the caller.
+ /// TODO: take ownership
///
FLVParser(tu_file& lt);
/// Kills the parser...
~FLVParser();
- /// Return next media frame
+ /// \brief
+ /// Return the next audio frame info in the parsed buffer.
//
- /// Locks the _mutex
+ /// 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.
+ ///
+ /// TODO: return a more abstract EncodedAudioFrameInfo
///
- FLVFrame* nextMediaFrame();
+ FLVAudioFrameInfo* peekNextAudioFrameInfo();
/// \brief
- /// Returns the next audio frame in the parsed buffer.
+ /// 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.
///
- /// Locks the _mutex
+ /// TODO: return a more abstract EncodedAudioFrame
///
FLVFrame* nextAudioFrame();
- /// \brief
- /// Returns the next video frame in the parsed buffer.
+ /// Returns the next video frame info in the parsed buffer.
//
/// 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.
///
- /// Locks the _mutex
+ /// TODO: return a more abstract EncodedVideoFrameInfo
+ ///
+ FLVVideoFrameInfo* peekNextVideoFrameInfo();
+
+ /// 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.
+ ///
+ /// TODO: return a more abstract EncodedVideoFrame
///
FLVFrame* nextVideoFrame();
@@ -249,17 +265,17 @@
/// Returns information about video in the stream.
//
- /// Locks the _mutex
- ///
/// The returned object is owned by the FLVParser object.
/// Can return NULL if video contains NO video frames.
/// Will block till either parsing finished or a video frame is found.
///
+ /// TODO: return a more abstract VideoInfo
+ ///
FLVVideoInfo* getVideoInfo();
/// Returns a FLVAudioInfo class about the audiostream
//
- /// Locks the _mutex
+ /// TODO: return a more abstract AudioInfo
///
FLVAudioInfo* getAudioInfo();
@@ -271,8 +287,6 @@
/// available in list of already the parsed frames, we
/// parse some more. This is used to check how much is buffered.
///
- /// Locks the _mutex
- ///
/// @param time
/// Timestamp, in milliseconds.
///
@@ -282,39 +296,47 @@
/// Seeks to the closest possible position the given position,
/// and returns the new position.
//
- /// Locks the _mutex
+ ///
+ /// TODO: throw something for sending Seek.InvalidTime ?
+ /// (triggered by seeks beyond the end of video or beyond what's
+ /// downloaded so far)
///
boost::uint32_t seek(boost::uint32_t);
/// Returns the framedelay from the last to the current
/// audioframe in milliseconds. This is used for framerate.
//
- /// Locks the _mutex
- ///
boost::uint32_t audioFrameDelay();
/// \brief
/// Returns the framedelay from the last to the current
/// videoframe in milliseconds.
//
- /// Locks the _mutex
- ///
boost::uint32_t videoFrameDelay();
/// Returns the framerate of the video
//
- /// Locks the _mutex
- ///
boost::uint16_t videoFrameRate();
/// Returns the "bufferlength", meaning the differens between the
/// current frames timestamp and the timestamp of the last parseable
/// frame. Returns the difference in milliseconds.
//
- /// Locks the _mutex
- ///
boost::uint32_t getBufferLength();
+ /// Parses next tag from the file
+ //
+ /// Returns true if something was parsed, false otherwise.
+ /// Sets _parsingComplete=true on end of file.
+ ///
+ bool parseNextTag();
+
+ /// Return number of bytes parsed so far
+ boost::uint64_t getBytesLoaded() const;
+
+ /// Return total number of bytes in input
+ boost::uint64_t getBytesTotal() const;
+
private:
/// seeks to the closest possible position the given position,
@@ -325,16 +347,6 @@
/// and returns the new position.
boost::uint32_t seekVideo(boost::uint32_t time);
-
- /// Parses next tag from the file
- //
- /// Returns true if something was parsed, false otherwise.
- /// Sets _parsingComplete=true on end of file.
- ///
- /// TODO: make public (seems useful for an external parsing driver)
- ///
- bool parseNextTag();
-
/// Parses the header of the file
bool parseHeader();
@@ -383,9 +395,6 @@
/// Audio stream is present
bool _video;
-
- /// Mutex to avoid problems with threads using the parser
- boost::mutex _mutex;
};
} // end of gnash namespace
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/09
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/11
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/11
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/12
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/12
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F...,
Sandro Santilli <=
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/24
- [Gnash-commit] gnash ChangeLog libbase/FLVParser.cpp libbase/F..., Sandro Santilli, 2008/05/27