gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10256: Implement Video.clear(). Net


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10256: Implement Video.clear(). Netstream_as has to expose its play state for this
Date: Tue, 11 Nov 2008 10:58:42 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10256
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2008-11-11 10:58:42 +0100
message:
  Implement Video.clear(). Netstream_as has to expose its play state for this
  to work.
  
  Drop unused enum in Netstream_as.
modified:
  libcore/TextField.cpp
  libcore/Video.cpp
  libcore/Video.h
  libcore/asobj/NetStream_as.cpp
  libcore/asobj/NetStream_as.h
  testsuite/misc-ming.all/Video-EmbedSquareTest.c
  testsuite/misc-ming.all/Video-EmbedSquareTestRunner.cpp
    ------------------------------------------------------------
    revno: 10255.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-11-11 09:43:14 +0100
    message:
      Implement Video.clear().
      
      Silence excessive TextField debugging.
    modified:
      libcore/TextField.cpp
      libcore/Video.cpp
      libcore/Video.h
      libcore/asobj/NetStream_as.cpp
      libcore/asobj/NetStream_as.h
    ------------------------------------------------------------
    revno: 10255.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-11-11 10:38:07 +0100
    message:
      Test for Video.clear() on embedded video (should not have any effect).
    modified:
      testsuite/misc-ming.all/Video-EmbedSquareTest.c
      testsuite/misc-ming.all/Video-EmbedSquareTestRunner.cpp
=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2008-11-09 14:11:08 +0000
+++ b/libcore/TextField.cpp     2008-11-11 08:43:14 +0000
@@ -1535,8 +1535,8 @@
     boost::uint16_t blockIndent = getBlockIndent();
     bool underlined = getUnderlined();
 
-    log_debug("%s: fontDescent:%g, fontLeading:%g, fontHeight:%g, scale:%g",
-      getTarget(), fontDescent, fontLeading, fontHeight, scale);
+    //log_debug("%s: fontDescent:%g, fontLeading:%g, fontHeight:%g, scale:%g",
+    //  getTarget(), fontDescent, fontLeading, fontHeight, scale);
 
     SWF::TextRecord rec;    // one to work on
     rec.setFont(_font.get());

=== modified file 'libcore/Video.cpp'
--- a/libcore/Video.cpp 2008-11-06 23:06:02 +0000
+++ b/libcore/Video.cpp 2008-11-11 08:43:14 +0000
@@ -124,7 +124,8 @@
                return as_value();
        }
 
-       boost::intrusive_ptr<NetStream_as> ns = 
boost::dynamic_pointer_cast<NetStream_as>(fn.arg(0).to_object());
+       boost::intrusive_ptr<NetStream_as> ns = 
+        boost::dynamic_pointer_cast<NetStream_as>(fn.arg(0).to_object());
        if (ns)
        {
                video->setStream(ns);
@@ -140,9 +141,11 @@
 }
 
 static as_value
-video_clear(const fn_call& /*fn*/)
+video_clear(const fn_call& fn)
 {
-    log_unimpl (__FUNCTION__);
+       boost::intrusive_ptr<Video> video = ensureType<Video>(fn.this_ptr);
+
+    video->clear();
     return as_value();
 }
 
@@ -151,8 +154,8 @@
 {
        log_debug("new Video() TESTING !");
 
-       // I'm not sure We can rely on the def and parent values being accepted 
 as NULL
-       // Not till we add some testing...
+       // I'm not sure We can rely on the def and parent values being accepted 
+    // as NULL. Not till we add some testing...
        boost::intrusive_ptr<character> obj = new Video(NULL, NULL, -1);
        obj->setDynamic();
        return as_value(obj.get()); // will keep alive
@@ -193,17 +196,14 @@
        :
        character(parent, id),
        m_def(def),
-       //m_video_source(NULL),
        _ns(NULL),
-       _embeddedStream(false),
+       _embeddedStream(m_def ? true : false),
        _lastDecodedVideoFrameNum(-1),
        _lastDecodedVideoFrame()
 {
-       //log_debug("Video %p ctor", (void*)this);
 
-       if ( m_def )
+       if (_embeddedStream)
        {
-               _embeddedStream = true;
                attachVideoProperties(*this);
                initializeDecoder();
        }
@@ -216,6 +216,17 @@
 }
 
 void
+Video::clear()
+{
+    // Clear the current image only if paused.
+    if (_ns && _ns->playbackState() == PlayHead::PLAY_PAUSED)
+    {
+        set_invalidated();
+        _lastDecodedVideoFrame.reset();
+    }
+}
+
+void
 Video::display()
 {
        // if m_def is NULL we've been constructed by 'new Video', in this
@@ -239,14 +250,16 @@
 {
 
 
-       // If this is a video from a NetStream_as object, retrieve a video 
frame from there.
+       // If this is a video from a NetStream_as object, retrieve a video
+    // frame from there.
        if (_ns)
        {
                std::auto_ptr<GnashImage> tmp = _ns->get_video();
                if ( tmp.get() ) _lastDecodedVideoFrame = tmp;
        }
 
-       // If this is a video from a VideoFrame tag, retrieve a video frame 
from there.
+       // If this is a video from a VideoFrame tag, retrieve a video frame
+    // from there.
        else if (_embeddedStream)
        {
 
@@ -267,19 +280,22 @@
                if ( _lastDecodedVideoFrameNum == current_frame )
                {
 #ifdef DEBUG_EMBEDDED_VIDEO_DECODING
-                       log_debug("  current frame == _lastDecodedVideoFrameNum 
(%d)", current_frame);
+                       log_debug("  current frame == _lastDecodedVideoFrameNum 
(%d)",
+                    current_frame);
 #endif
                        return _lastDecodedVideoFrame.get();
                }
 
-               int from_frame = _lastDecodedVideoFrameNum < 0 ? 0 : 
_lastDecodedVideoFrameNum+1;
+               int from_frame = _lastDecodedVideoFrameNum < 0 ?
+            0 : _lastDecodedVideoFrameNum + 1;
 
                // If current frame is smaller then last decoded frame
                // we restart decoding from scratch
                if ( current_frame < _lastDecodedVideoFrameNum )
                {
 #ifdef DEBUG_EMBEDDED_VIDEO_DECODING
-                       log_debug("  current frame (%d) < 
_lastDecodedVideoFrameNum (%d)", current_frame, _lastDecodedVideoFrameNum);
+                       log_debug("  current frame (%d) < 
_lastDecodedVideoFrameNum (%d)",
+                    current_frame, _lastDecodedVideoFrameNum);
 #endif
                        from_frame = 0;
                }
@@ -289,8 +305,8 @@
                _lastDecodedVideoFrameNum = current_frame;
 
 #ifdef DEBUG_EMBEDDED_VIDEO_DECODING
-               log_debug("  decoding embedded frames from %d to %d for video 
instance %s",
-                       from_frame, current_frame, getTarget());
+               log_debug("  decoding embedded frames from %d to %d for Video "
+                "object %s", from_frame, current_frame, getTarget());
 #endif
 
                typedef std::vector<media::EncodedVideoFrame*> EncodedFrames;
@@ -307,7 +323,8 @@
                        return _lastDecodedVideoFrame.get();
                }
 
-               for (EncodedFrames::iterator it=toDecode.begin(), 
itEnd=toDecode.end(); it!=itEnd; ++it)
+               for (EncodedFrames::iterator it=toDecode.begin(),
+                itEnd=toDecode.end(); it!=itEnd; ++it)
                {
                        media::EncodedVideoFrame* frame = *it;
 #ifdef DEBUG_EMBEDDED_VIDEO_DECODING
@@ -337,7 +354,9 @@
 {
        if (_ns) {
                //_ns->advance();
-               if (_ns->newFrameReady()) set_invalidated(); // NOTE: only 
needed for gstreamer !!
+        
+        // NOTE: only needed for gstreamer:
+               if (_ns->newFrameReady()) set_invalidated();
        }
 }
 
@@ -378,10 +397,6 @@
        {
                cl=new builtin_function(&video_ctor, getVideoInterface(global));
                global.getVM().addStatic(cl.get());
-
-               // replicate all interface to class, to be able to access
-               // all methods as static functions
-               //attachVideoInterface(*cl);
        }
 
        // Register _global.Video

=== modified file 'libcore/Video.h'
--- a/libcore/Video.h   2008-11-06 23:06:02 +0000
+++ b/libcore/Video.h   2008-11-11 08:43:14 +0000
@@ -63,12 +63,12 @@
        rect getBounds() const;
 
        /// We use the call to ::advance to properly set invalidated status
-       virtual void    advance();
+       virtual void advance();
 
        /// Register this video instance as a live character
        virtual void stagePlacementCallback();
 
-       void    display();
+       void display();
 
        // For sure isActionScriptReferenceable...
        bool wantsInstanceName() const
@@ -81,6 +81,8 @@
        /// Set the input stream for this video
        void setStream(boost::intrusive_ptr<NetStream_as> ns);
 
+    void clear();
+
 protected:
 
 #ifdef GNASH_USE_GC
@@ -104,11 +106,6 @@
        /// Get video frame to be displayed
        GnashImage* getVideoFrame();
 
-       // m_video_source - A Camera object that is capturing video data or a 
NetStream object.
-       // To drop the connection to the Video object, pass null for source.
-       // FIXME: don't use as_object, but a more meaningful type
-       //as_object* m_video_source;
-
        // Who owns this ? Should it be an intrusive ptr ?
        boost::intrusive_ptr<NetStream_as> _ns;
 

=== modified file 'libcore/asobj/NetStream_as.cpp'
--- a/libcore/asobj/NetStream_as.cpp    2008-11-08 10:14:21 +0000
+++ b/libcore/asobj/NetStream_as.cpp    2008-11-11 08:43:14 +0000
@@ -141,9 +141,11 @@
        return as_value();
 }
 
-static as_value netstream_pause(const fn_call& fn)
+static as_value
+netstream_pause(const fn_call& fn)
 {
-       boost::intrusive_ptr<NetStream_as> ns = 
ensureType<NetStream_as>(fn.this_ptr);
+       boost::intrusive_ptr<NetStream_as> ns = 
+        ensureType<NetStream_as>(fn.this_ptr);
        
        // mode: -1 ==> toogle, 0==> pause, 1==> play
        NetStream_as::PauseMode mode = NetStream_as::pauseModeToggle;
@@ -156,7 +158,8 @@
        return as_value();
 }
 
-static as_value netstream_play(const fn_call& fn)
+static as_value
+netstream_play(const fn_call& fn)
 {
        boost::intrusive_ptr<NetStream_as> ns = 
ensureType<NetStream_as>(fn.this_ptr);
 

=== modified file 'libcore/asobj/NetStream_as.h'
--- a/libcore/asobj/NetStream_as.h      2008-11-08 10:14:21 +0000
+++ b/libcore/asobj/NetStream_as.h      2008-11-11 08:43:14 +0000
@@ -69,7 +69,6 @@
                PLAY_PLAYING = 1,
                PLAY_PAUSED = 2
        };
-       
 
        /// Initialize playhead given a VirtualCock to use
        /// as clock source.
@@ -103,10 +102,10 @@
     }
 
        /// Get current playhead position (milliseconds)
-       boost::uint64_t getPosition() { return _position; }
+       boost::uint64_t getPosition() const { return _position; }
 
        /// Get current playback state
-       PlaybackStatus getState() { return _state; }
+       PlaybackStatus getState() const { return _state; }
 
        /// Set playback state, returning old state
        PlaybackStatus setState(PlaybackStatus newState);
@@ -332,7 +331,6 @@
 
 public:
 
-
        enum PauseMode {
          pauseModeToggle = -1,
          pauseModePause = 0,
@@ -343,7 +341,11 @@
 
        ~NetStream_as();
 
-       /// Closes the video session and frees all ressources used for decoding
+    PlayHead::PlaybackStatus playbackState() const {
+        return _playHead.getState();
+    }
+
+    /// Closes the video session and frees all ressources used for decoding
        /// except the FLV-parser (this might not be correct).
        void close();
 
@@ -496,13 +498,6 @@
     // Delete all samples in the audio queue.
     void cleanAudioQueue();
 
-       enum PlaybackState {
-               PLAY_NONE,
-               PLAY_STOPPED,
-               PLAY_PLAYING,
-               PLAY_PAUSED
-       };
-
        enum DecodingState {
                DEC_NONE,
                DEC_STOPPED,
@@ -554,9 +549,10 @@
        //
        /// Uses by ::advance().
        ///
-       /// Note that get_video will be called by 
video_stream_instance::display, which
-       /// is usually called right after video_stream_instance::advance, so  
the result
-       /// is that  refreshVideoFrame() is called right before get_video(). 
This is important
+       /// Note that get_video will be called by Video::display(), which
+       /// is usually called right after Video::advance(), so the result
+       /// is that refreshVideoFrame() is called right before
+    /// get_video(). This is important
        /// to ensure timing is correct..
        ///
        /// @param alsoIfPaused
@@ -569,7 +565,8 @@
        /// and up to current timestamp
        void refreshAudioBuffer();
 
-       // Used to decode and push the next available (non-FLV) frame to the 
audio or video queue
+       /// Used to decode and push the next available (non-FLV) frame to
+    /// the audio or video queue
        bool decodeMediaFrame();
 
        /// Decode next video frame fetching it MediaParser cursor
@@ -667,8 +664,6 @@
        ///
        void detachAuxStreamer();
 
-
-
        /// Pop next queued status notification from the queue
        //
        /// Lock the statusMutex during operations

=== modified file 'testsuite/misc-ming.all/Video-EmbedSquareTest.c'
--- a/testsuite/misc-ming.all/Video-EmbedSquareTest.c   2008-07-11 15:28:44 
+0000
+++ b/testsuite/misc-ming.all/Video-EmbedSquareTest.c   2008-11-11 09:38:07 
+0000
@@ -53,8 +53,11 @@
   SWFVideoStream stream;
   SWFDisplayItem item;
   SWFMovieClip mc;
-  FILE *flv;
+  SWFMovieClip dejagnuclip;
+  FILE *flv, *font_file;
+  SWFFont font;
   char filename[256];
+  char fdbfont[1024];
 
   if ( argc>1 ) mediadir=argv[1];
   else
@@ -71,9 +74,18 @@
          return -1;
   }
 
+  sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", mediadir);
+  font_file = fopen(fdbfont, "r");
+  if ( font_file == NULL )
+  {
+    perror(fdbfont);
+    exit(1);
+  }
+
   Ming_init();
   Ming_useSWFVersion (OUTPUT_VERSION);
 
+  font = loadSWFFontFromFile(font_file);
        
   mo = newSWFMovie();
   SWFMovie_setDimension(mo, 320, 96);
@@ -82,8 +94,14 @@
 
   SWFMovie_setRate(mo, 5);
 
+  dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 200, 200);
+  item = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
+  SWFDisplayItem_setDepth(item, 200); 
+  SWFDisplayItem_move(item, 140, 0); 
+
   stream = newSWFVideoStream_fromFile(flv);
   item = SWFMovie_add(mo, (SWFBlock)stream);
+  SWFDisplayItem_setName(item, "vid");
 
   // A bug in Ming prevents this from working the
   // way I liked it to. It was useful to try this
@@ -117,7 +135,20 @@
   // TODO: dynamic frame rate adjust
   frames = SWFVideoStream_getNumFrames(stream);
   for(; frames > 0; frames--)
+  {
     SWFMovie_nextFrame(mo);
+  }
+
+  /// Video.clear() should not work on embedded Videos.
+  add_actions(mo, "stop(); vid.clear(); trace(vid);");
+  add_actions(mo, "note('You should still see the video frame."
+          " Click to replay');"
+                 "o = {};"
+                 "o.onMouseDown = function() { _root.play(); };"
+                 "Mouse.addListener(o);"
+            );
+
+  SWFMovie_nextFrame(mo);
 
   //Output movie
   puts("Saving " OUTPUT_FILENAME );

=== modified file 'testsuite/misc-ming.all/Video-EmbedSquareTestRunner.cpp'
--- a/testsuite/misc-ming.all/Video-EmbedSquareTestRunner.cpp   2008-10-25 
10:38:32 +0000
+++ b/testsuite/misc-ming.all/Video-EmbedSquareTestRunner.cpp   2008-11-11 
09:38:07 +0000
@@ -59,7 +59,7 @@
        int scale_y = 1;
 
        size_t framecount = root->get_frame_count();
-       check_equals(framecount, 11);
+       check_equals(framecount, 12);
        
        // Just loop twice, so to catch crashes...
        for (int j = 0; j < 2; ++j) {
@@ -108,7 +108,7 @@
                                check_pixel((45 + i)*scale_x, 5, 2, yellow, 5);
                        }
 
-                       if ( framenum == framecount-1 )
+                       if ( framenum == framecount-2 )
                        {
                                // check we're playing, or we'll never get to 
next loop...
                                check_equals(root->get_play_state(), 
MovieClip::PLAY);
@@ -119,6 +119,18 @@
                }
 
                tester.advance();
+
+               // Check the color in (5,5) - should be yellow. Well, anything
+               // but white or transparent.
+               check_pixel(5, 5, 2, yellow, 5);
+               check_equals(root->get_play_state(), MovieClip::STOP);
+               tester.click();
+
+               // Sanity check
+               check_equals(root->get_play_state(), MovieClip::PLAY);
+
+               tester.advance();
+
        }
 
 }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]