gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10514: Minor simplifications.


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10514: Minor simplifications.
Date: Wed, 07 Jan 2009 12:37:48 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10514
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2009-01-07 12:37:48 +0100
message:
  Minor simplifications.
modified:
  libcore/Video.cpp
  libcore/swf/DefineVideoStreamTag.cpp
  libcore/swf/DefineVideoStreamTag.h
  libcore/swf/VideoFrameTag.cpp
    ------------------------------------------------------------
    revno: 10513.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-01-07 10:34:02 +0100
    message:
      Make getting a frame slice tidier and more efficient.
    modified:
      libcore/swf/DefineVideoStreamTag.cpp
      libcore/swf/DefineVideoStreamTag.h
    ------------------------------------------------------------
    revno: 10513.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-01-07 10:55:08 +0100
    message:
      Match typedefs, name padding bytes.
    modified:
      libcore/Video.cpp
      libcore/swf/VideoFrameTag.cpp
=== modified file 'libcore/Video.cpp'
--- a/libcore/Video.cpp 2008-11-26 15:26:24 +0000
+++ b/libcore/Video.cpp 2009-01-07 09:55:08 +0000
@@ -214,7 +214,7 @@
                 "object %s", from_frame, current_frame, getTarget());
 #endif
 
-               typedef std::vector<media::EncodedVideoFrame*> EncodedFrames;
+               typedef SWF::DefineVideoStreamTag::EmbeddedFrames EncodedFrames;
 
                EncodedFrames toDecode;
                m_def->getEncodedFrameSlice(from_frame, current_frame, 
toDecode);

=== modified file 'libcore/swf/DefineVideoStreamTag.cpp'
--- a/libcore/swf/DefineVideoStreamTag.cpp      2009-01-05 09:32:03 +0000
+++ b/libcore/swf/DefineVideoStreamTag.cpp      2009-01-07 09:34:02 +0000
@@ -27,7 +27,33 @@
 namespace gnash {
 namespace SWF {
 
-DefineVideoStreamTag::DefineVideoStreamTag(SWFStream& in, boost::uint16_t 
char_id)
+namespace {
+
+/// A Functor for comparing frames by frame number.
+//
+/// A comparison operator would avoid having two variants, but seems less
+/// intuitive, and could open up all sorts of unexpected behaviour due to
+/// type promotion.
+struct FrameFinder
+{
+
+    typedef DefineVideoStreamTag::EmbeddedFrames::value_type Frame;
+
+    bool operator()(const Frame& frame, size_t i)
+    {
+        return frame->frameNum() < i;
+    }
+    
+    bool operator()(size_t i, const Frame& frame)
+    {
+        return i < frame->frameNum();
+    }
+};
+
+}
+
+DefineVideoStreamTag::DefineVideoStreamTag(SWFStream& in,
+        boost::uint16_t char_id)
        :
        m_char_id(char_id),
        _width(0),
@@ -119,6 +145,7 @@
        return frame->frameNum() == frameNumber;
 }
 
+
 void
 DefineVideoStreamTag::getEncodedFrameSlice(boost::uint32_t from,
         boost::uint32_t to, EmbeddedFrames& ret)
@@ -127,28 +154,20 @@
 
        boost::mutex::scoped_lock lock(_video_mutex);
 
-       EmbeddedFrames::iterator it=_video_frames.begin(), 
itEnd=_video_frames.end();
-       for (; it!=itEnd; ++it)
-       {
-               media::EncodedVideoFrame* frame = *it;
-               if ( frame->frameNum() >= from )
-               {
-                       break;
-               }
-       }
-
-       if (it==itEnd) return; // no element was >= from
-
-       // push remaining frames 
-       for (; it!=itEnd; ++it)
-       {
-               media::EncodedVideoFrame* frame = *it;
-               if ( frame->frameNum() > to ) break; // went too far
-               ret.push_back(frame);
-       }
-
+    // It's assumed that frame numbers are in order.
+    EmbeddedFrames::iterator lower = std::lower_bound(
+            _video_frames.begin(), _video_frames.end(), from, FrameFinder());
+
+    EmbeddedFrames::iterator upper = std::upper_bound(
+            lower, _video_frames.end(), to, FrameFinder());
+
+    // This copies a pointer to the encoded video frames; the actual
+    // data is owned by this class for its entire lifetime.
+    std::copy(lower, upper, std::back_inserter(ret));
 }
 
+
+
 } // namespace SWF
 } // namespace gnash
 

=== modified file 'libcore/swf/DefineVideoStreamTag.h'
--- a/libcore/swf/DefineVideoStreamTag.h        2009-01-05 09:32:03 +0000
+++ b/libcore/swf/DefineVideoStreamTag.h        2009-01-07 09:34:02 +0000
@@ -71,6 +71,15 @@
 class DefineVideoStreamTag : public character_def
 {
 public:
+       
+    /// The undecoded video frames and its size, using the swf-frame number
+    /// as key
+       //
+       /// Elements of this vector are owned by this instance, and will be 
deleted 
+       /// at instance destruction time.
+       ///
+       typedef std::vector<media::EncodedVideoFrame*> EmbeddedFrames;
+       
 
        ~DefineVideoStreamTag();
 
@@ -182,14 +191,6 @@
        /// Bounds of the video, as read from the DEFINEVIDEOSTREAM tag.
        rect m_bound;
 
-       /// The undecoded video frames and its size, using the swf-frame number
-    /// as key
-       //
-       /// Elements of this vector are owned by this instance, and will be 
deleted 
-       /// at instance destruction time.
-       ///
-       typedef std::vector<media::EncodedVideoFrame*> EmbeddedFrames;
-       
        boost::mutex _video_mutex;
        
        EmbeddedFrames _video_frames;

=== modified file 'libcore/swf/VideoFrameTag.cpp'
--- a/libcore/swf/VideoFrameTag.cpp     2009-01-05 09:32:03 +0000
+++ b/libcore/swf/VideoFrameTag.cpp     2009-01-07 09:55:08 +0000
@@ -60,13 +60,15 @@
 
        // TODO: skip if there's no MediaHandler registered ?
 
+    const unsigned short padding = 8;
+
        in.ensureBytes(2);
        unsigned int frameNum = in.read_u16(); 
-
+       
        const unsigned int dataLength = in.get_tag_end_position() - in.tell();
-       
+
     // FIXME: catch bad_alloc
-       boost::uint8_t* buffer = new uint8_t[dataLength + 8]; 
+       boost::uint8_t* buffer = new uint8_t[dataLength + padding]; 
 
        const size_t bytesRead = in.read(reinterpret_cast<char*>(buffer),
             dataLength);
@@ -78,7 +80,7 @@
                                 "end of the stream!"));
     }  
        
-    std::fill_n(buffer + bytesRead, 8, 0);
+    std::fill_n(buffer + bytesRead, padding, 0);
 
        using namespace media;
 


reply via email to

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