[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/asobj/NetStream.cpp serv...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/asobj/NetStream.cpp serv... |
Date: |
Fri, 23 May 2008 15:27:31 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/05/23 15:27:31
Modified files:
. : ChangeLog
server/asobj : NetStream.cpp NetStream.h
Log message:
Add PlayHead class implementation.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6692&r2=1.6693
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStream.cpp?cvsroot=gnash&r1=1.91&r2=1.92
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStream.h?cvsroot=gnash&r1=1.63&r2=1.64
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6692
retrieving revision 1.6693
diff -u -b -r1.6692 -r1.6693
--- ChangeLog 23 May 2008 15:22:22 -0000 1.6692
+++ ChangeLog 23 May 2008 15:27:29 -0000 1.6693
@@ -1,3 +1,7 @@
+2008-05-23 Sandro Santilli <address@hidden>
+
+ * server/asobj/NetStream.{cpp,h}: Add PlayHead class implementation.
+
2008-05-23 Benjamin Wolsey <address@hidden>
* server/sprite_instance.{h,cpp},
Index: server/asobj/NetStream.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStream.cpp,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -b -r1.91 -r1.92
--- server/asobj/NetStream.cpp 21 May 2008 16:48:15 -0000 1.91
+++ server/asobj/NetStream.cpp 23 May 2008 15:27:30 -0000 1.92
@@ -42,6 +42,8 @@
#include "namedStrings.h"
#include "movie_root.h"
+#include "VirtualClock.h" // for PlayHead
+
// Define the following macro to have status notification handling debugged
//#define GNASH_DEBUG_STATUS
@@ -74,7 +76,6 @@
m_imageframe(NULL),
m_parser(NULL),
m_isFLV(false),
- m_start_onbuffer(false),
inputPos(0),
_lastStatus(invalidStatus)
{
@@ -641,4 +642,100 @@
}
#endif // GNASH_USE_GC
+// ------- PlayHead class --------
+PlayHead::PlayHead(VirtualClock* clockSource)
+ :
+ _position(0),
+ _state(PLAY_PLAYING),
+ _availableConsumers(0),
+ _positionConsumers(0),
+ _clockSource(clockSource)
+{
+ _clockOffset = _clockSource->elapsed();
+}
+
+void
+PlayHead::init(bool hasVideo, bool hasAudio)
+{
+ boost::uint64_t now = _clockSource->elapsed();
+ if ( hasVideo ) _availableConsumers |= CONSUMER_VIDEO;
+ if ( hasAudio ) _availableConsumers |= CONSUMER_AUDIO;
+ _positionConsumers = 0;
+
+ _position = 0;
+ _clockOffset = now;
+ assert(now-_clockOffset == _position);
+}
+
+PlayHead::PlaybackStatus
+PlayHead::setState(PlaybackStatus newState)
+{
+ if ( _state == newState ) return _state; // nothing to do
+
+ if ( _state == PLAY_PAUSED )
+ {
+ _state = PLAY_PLAYING;
+
+ // if we go from PAUSED to PLAYING, reset
+ // _clockOffset to yank current position
+ // when querying clock source *now*
+ boost::uint64_t now = _clockSource->elapsed();
+ _clockOffset = ( now - _position );
+ assert( now-_clockOffset == _position ); // check if we did the
right thing
+
+ return PLAY_PAUSED;
+ }
+ else
+ {
+ assert(_state == PLAY_PLAYING);
+ _state = PLAY_PAUSED;
+ // When going from PLAYING to PAUSED
+ // we do nothing with _clockOffset
+ // as we'll update it when getting back to PLAYING
+ return PLAY_PLAYING;
+ }
+}
+
+PlayHead::PlaybackStatus
+PlayHead::toggleState()
+{
+ if ( _state == PLAY_PAUSED ) return setState(PLAY_PLAYING);
+ else return setState(PLAY_PAUSED);
+}
+
+void
+PlayHead::advanceIfConsumed()
+{
+ if ( (_positionConsumers & _availableConsumers) != _availableConsumers)
+ {
+ // not all available consumers consumed current position,
+ // won't advance
+ log_debug("PlayHead::advance(): "
+ "not all consumers consumed current position, "
+ "won't advance");
+ return;
+ }
+
+ // Advance position
+ boost::uint64_t now = _clockSource->elapsed();
+ _position = now-_clockOffset;
+
+ // Reset consumers state
+ _positionConsumers = 0;
+}
+
+void
+PlayHead::seekTo(boost::uint64_t position)
+{
+ boost::uint64_t now = _clockSource->elapsed();
+ _position = position;
+
+ _clockOffset = ( now - _position );
+ assert( now-_clockOffset == _position ); // check if we did the right
thing
+
+ // Reset consumers state
+ _positionConsumers = 0;
+}
+
+
} // end of gnash namespace
Index: server/asobj/NetStream.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStream.h,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- server/asobj/NetStream.h 21 May 2008 16:48:15 -0000 1.63
+++ server/asobj/NetStream.h 23 May 2008 15:27:30 -0000 1.64
@@ -39,10 +39,147 @@
// Forward declarations
namespace gnash {
//class NetConnection;
+ class VirtualClock;
}
namespace gnash {
+/// The playback controller
+class PlayHead {
+
+public:
+
+ /// Flags for playback state
+ enum PlaybackStatus {
+ PLAY_PLAYING = 1,
+ PLAY_PAUSED = 2
+ };
+
+
+ /// Initialize playhead given a VirtualCock to use
+ /// as clock source.
+ //
+ /// The PlayHead will have initial state set to PLAYING
+ ///
+ /// @param clockSource
+ /// The VirtualClock to use as time source.
+ /// Ownership left to caller (not necessarely a good thing).
+ ///
+ PlayHead(VirtualClock* clockSource);
+
+ /// Initialize playhead
+ //
+ /// @param hasVideo
+ /// Whether video consumer is available
+ ///
+ /// @param hasAudio
+ /// Whether video consumer is available
+ ///
+ void init(bool hasVideo, bool hasAudio);
+
+ /// Get current playhead position (milliseconds)
+ boost::uint64_t getPosition() { return _position; }
+
+ /// Get current playback state
+ PlaybackStatus getState() { return _state; }
+
+ /// Set playback state, returning old state
+ PlaybackStatus setState(PlaybackStatus newState);
+
+ /// Toggle playback state, returning old state
+ PlaybackStatus toggleState();
+
+ /// Return true if video of current position have been consumed
+ bool isVideoConsumed() const
+ {
+ return (_positionConsumers & CONSUMER_VIDEO);
+ }
+
+ /// \brief
+ /// Mark current position as being consumed by video consumer,
+ /// advancing if needed
+ void setVideoConsumed()
+ {
+ _positionConsumers |= CONSUMER_VIDEO;
+ advanceIfConsumed();
+ }
+
+ /// Return true if audio of current position have been consumed
+ bool isAudioConsumed() const
+ {
+ return (_positionConsumers & CONSUMER_AUDIO);
+ }
+
+ /// \brief
+ /// Mark current position as being consumed by audio consumer,
+ /// advancing if needed.
+ void setAudioConsumed()
+ {
+ _positionConsumers |= CONSUMER_AUDIO;
+ advanceIfConsumed();
+ }
+
+ /// Change current position to the given time.
+ //
+ /// Consume flag will be reset.
+ ///
+ /// @param position
+ /// Position timestamp (milliseconds)
+ ///
+ /// POSTCONDITIONS:
+ /// - isVideoConsumed() == false
+ /// - isAudioConsumed() == false
+ /// - getPosition() == position
+ ///
+ void seekTo(boost::uint64_t position);
+
+private:
+
+ /// Advance position if all consumers consumed the current one
+ //
+ /// Clock source will be used to determine the amount
+ /// of milliseconds to advance position to.
+ ///
+ /// Consumer flags will be reset.
+ ///
+ /// POSTCONDITIONS:
+ /// - isVideoConsumed() == false
+ /// - isAudioConsumed() == false
+ ///
+ void advanceIfConsumed();
+
+ /// Flags for consumers state
+ enum ConsumerFlag {
+ CONSUMER_VIDEO = 1,
+ CONSUMER_AUDIO = 2
+ };
+
+ /// Current playhead position
+ boost::uint64_t _position;
+
+ /// Current playback state
+ PlaybackStatus _state;
+
+ /// Binary OR of consumers representing
+ /// which consumers are active
+ int _availableConsumers;
+
+ /// Binary OR of consumers representing
+ /// which consumers consumed current position
+ int _positionConsumers;
+
+ /// The clock source, externally owned
+ VirtualClock* _clockSource;
+
+ /// Offset to subtract from current clock source
+ /// to get current position
+ //
+ /// The offset will be
+ boost::uint64_t _clockOffset;
+
+};
+
+
/// NetStream ActionScript class
//
@@ -149,12 +286,6 @@
// The handler which is invoked on status change
boost::intrusive_ptr<as_function> m_statusHandler;
- // should we start when the FLVParser has buffered/parsed enough frames,
- // so that the differens between the current frames timestamp (0 at the
- // beginning) and the last parseable frames timestamp i bigger than
- // m_bufferTime.
- bool m_start_onbuffer;
-
// The position in the inputfile, only used when not playing a FLV
long inputPos;
@@ -203,6 +334,7 @@
//
/// @param position
/// Defines in seconds where to seek to
+ /// TODO: take milliseconds !!
///
virtual void seek(boost::uint32_t /*pos*/){}