gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11002: Introduce SWFParser class fo


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11002: Introduce SWFParser class for parsing all tags, reducing code duplication
Date: Fri, 05 Jun 2009 14:05:27 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11002
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2009-06-05 14:05:27 +0200
message:
  Introduce SWFParser class for parsing all tags, reducing code duplication
  in sprite_definition and SWFMovieDefinition. The class should also make it
  easier to control parsing (for instance making it non-threaded or linked
  to advances).
added:
  libcore/parser/SWFParser.cpp
  libcore/parser/SWFParser.h
modified:
  libcore/RunInfo.h
  libcore/parser/Makefile.am
  libcore/parser/SWFMovieDefinition.cpp
  libcore/parser/SWFMovieDefinition.h
  libcore/parser/movie_definition.h
  libcore/parser/sprite_definition.cpp
  libcore/parser/sprite_definition.h
  libcore/swf/TagLoadersTable.cpp
  libcore/swf/TagLoadersTable.h
    ------------------------------------------------------------
    revno: 11000.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: test
    timestamp: Fri 2009-06-05 10:28:27 +0200
    message:
      Use a SWFParser for parsing.
    added:
      libcore/parser/SWFParser.cpp
      libcore/parser/SWFParser.h
    modified:
      libcore/parser/Makefile.am
      libcore/parser/SWFMovieDefinition.cpp
      libcore/parser/SWFMovieDefinition.h
      libcore/parser/movie_definition.h
    ------------------------------------------------------------
    revno: 11000.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: test
    timestamp: Fri 2009-06-05 10:51:36 +0200
    message:
      Use the same SWFParser for sprite_definition.
    modified:
      libcore/parser/SWFParser.cpp
      libcore/parser/SWFParser.h
      libcore/parser/sprite_definition.cpp
      libcore/parser/sprite_definition.h
    ------------------------------------------------------------
    revno: 11000.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: test
    timestamp: Fri 2009-06-05 11:25:24 +0200
    message:
      Make the SWFParser deal only with the number of bytes it has to read / 
has 
      read, not with with the absolute stream position.
    modified:
      libcore/parser/SWFMovieDefinition.cpp
      libcore/parser/SWFParser.cpp
      libcore/parser/SWFParser.h
    ------------------------------------------------------------
    revno: 11000.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: test
    timestamp: Fri 2009-06-05 12:25:43 +0200
    message:
      Add documentation.
    modified:
      libcore/parser/SWFMovieDefinition.cpp
      libcore/parser/SWFMovieDefinition.h
      libcore/parser/SWFParser.cpp
      libcore/parser/SWFParser.h
      libcore/parser/movie_definition.h
      libcore/parser/sprite_definition.h
    ------------------------------------------------------------
    revno: 11000.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: test
    timestamp: Fri 2009-06-05 12:36:48 +0200
    message:
      Remove TagLoadersTable from sprite_definition.
    modified:
      libcore/parser/sprite_definition.cpp
      libcore/parser/sprite_definition.h
    ------------------------------------------------------------
    revno: 11000.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: test
    timestamp: Fri 2009-06-05 13:19:22 +0200
    message:
      Put TagLoadersTable in RunInfo with the rest of the external resources.
      
      Const correct.
    modified:
      libcore/RunInfo.h
      libcore/parser/SWFParser.cpp
      libcore/parser/SWFParser.h
      libcore/swf/TagLoadersTable.cpp
      libcore/swf/TagLoadersTable.h
=== modified file 'libcore/RunInfo.h'
--- a/libcore/RunInfo.h 2009-02-25 22:33:03 +0000
+++ b/libcore/RunInfo.h 2009-06-05 11:19:22 +0000
@@ -20,6 +20,7 @@
 #ifndef GNASH_RUN_INFO_H
 #define GNASH_RUN_INFO_H
 
+#include "TagLoadersTable.h"
 #include "StreamProvider.h"
 #include <string>
 #include <boost/shared_ptr.hpp>
@@ -51,7 +52,8 @@
     ///                 construction.
     RunInfo(const std::string& baseURL)
         :
-        _baseURL(baseURL)
+        _baseURL(baseURL),
+        _tagLoaders(SWF::TagLoadersTable::getInstance())
     {
     }
 
@@ -98,6 +100,10 @@
         return _soundHandler.get();
     }
 
+    const SWF::TagLoadersTable& tagLoaders() const {
+        return _tagLoaders;
+    }
+
 private:
 
     const std::string _baseURL;
@@ -106,6 +112,8 @@
 
     boost::shared_ptr<sound::sound_handler> _soundHandler;
 
+    const SWF::TagLoadersTable& _tagLoaders;
+
 };
 
 }

=== modified file 'libcore/parser/Makefile.am'
--- a/libcore/parser/Makefile.am        2009-05-24 22:25:59 +0000
+++ b/libcore/parser/Makefile.am        2009-06-05 08:28:27 +0000
@@ -47,6 +47,7 @@
 libgnashparser_la_SOURCES = \
        action_buffer.cpp \
        BitmapMovieDefinition.cpp \
+       SWFParser.cpp \
        SWFMovieDefinition.cpp \
        sound_definition.cpp \
        sprite_definition.cpp
@@ -60,6 +61,7 @@
        action_buffer.h \
        BitmapMovieDefinition.h \
        movie_definition.h \
+       SWFParser.h \
        SWFMovieDefinition.h \
        sound_definition.h \
        sprite_definition.h

=== modified file 'libcore/parser/SWFMovieDefinition.cpp'
--- a/libcore/parser/SWFMovieDefinition.cpp     2009-05-18 13:41:45 +0000
+++ b/libcore/parser/SWFMovieDefinition.cpp     2009-06-05 10:25:43 +0000
@@ -34,12 +34,12 @@
 #include "VM.h"
 #include "log.h"
 #include "SWFMovie.h"
-#include "swf/TagLoadersTable.h"
 #include "GnashException.h" // for parser exception
 #include "ControlTag.h"
 #include "sound_definition.h" // for sound_sample
 #include "ExportableResource.h"
 #include "GnashAlgorithm.h"
+#include "SWFParser.h"
 
 #include <boost/bind.hpp>
 #include <boost/version.hpp>
@@ -140,46 +140,6 @@
     return true;
 }
 
-//
-// some utility stuff
-//
-
-/// Log the contents of the current tag, in hex to the output strream
-static void    dumpTagBytes(SWFStream& in, std::ostream& os)
-{
-    const std::streamsize rowlength = 16;
-    os << std::endl;
-    
-    // This decremented until we reach the end of the stream.
-    std::streamsize toRead = in.get_tag_end_position() - in.tell();
-    in.ensureBytes(toRead);
-
-    unsigned char buf[rowlength];    
-    while (toRead)
-    {
-        // Read in max row length or remainder of stream.
-        const std::streamsize thisRow = 
-            std::min<std::streamsize>(toRead, rowlength);
-        
-        const std::streamsize got = 
-            in.read(reinterpret_cast<char*>(&buf), thisRow);
-        
-        // Check that we read all the bytes we expected.
-        if (got < thisRow)
-        {
-            throw ParserException(_("Unexpected end of stream while reading"));
-        }
-        
-        // Stream once as hex
-        os << std::left << std::setw(3 * rowlength) << hexify(buf, got, false);
-        
-        // and once as ASCII
-        os << "| " << hexify(buf, got, true) << std::endl;
-
-        toRead -= got;
-    }
-}
-
 
 //
 // SWFMovieDefinition
@@ -187,8 +147,6 @@
 
 SWFMovieDefinition::SWFMovieDefinition(const RunInfo& runInfo)
        :
-       // FIXME: use a class-static TagLoadersTable for SWFMovieDefinition
-       _tag_loaders(SWF::TagLoadersTable::getInstance()),
        m_frame_rate(30.0f),
        m_frame_count(0u),
        m_version(0),
@@ -538,103 +496,36 @@
        assert( ! _loader.isSelfThread() );
 #endif
 
-       SWFStream &str = *_str;
-
-    while (str.tell() < _swf_end_pos)
-    {
-        if (_loadingCanceled)
-        {
+    SWFParser parser(*_str, this, _runInfo);
+
+    const size_t startPos = _str->tell();
+    assert (startPos <= _swf_end_pos);
+
+    size_t left = _swf_end_pos - startPos;
+
+    const size_t chunkSize = 65535;
+
+    while (left) {
+
+        if (_loadingCanceled) {
             log_debug("Loading thread cancelation requested, "
                     "returning from read_all_swf");
             return;
         }
-
-        bool tagOpened=false;
-
-        try {
-
-            SWF::TagType tag = str.open_tag();
-            tagOpened=true;
-
-parse_tag:
-
-            if (tag == SWF::END) {
-                if (str.tell() != _swf_end_pos) {
-                               IF_VERBOSE_MALFORMED_SWF(
-                        // Safety break, so we don't read past
-                        // the end of the  movie.
-                        log_swferror(_("Hit stream-end tag, "
-                            "but not at the advertised SWF end; "
-                            "stopping for safety."));
-                        )
-                        break;
-                }
-            }
-
-            SWF::TagLoadersTable::loader_function lf = NULL;
-
-            if (tag == SWF::SHOWFRAME)
-            {
-                // show frame tag -- advance to the next frame.
-
-                IF_VERBOSE_PARSE(
-                    log_parse("  show_frame");
-                );
-
-                size_t floaded = incrementLoadedFrames();
-                if (floaded == m_frame_count)
-                {
-                    str.close_tag();
-                    tagOpened=false;
-                    tag = str.open_tag();
-                    tagOpened=true;
-                    if (tag != SWF::END )
-                    {
-                        IF_VERBOSE_MALFORMED_SWF(
-                        log_swferror(_("last expected SHOWFRAME "
-                            "in SWF stream '%s' isn't "
-                            "followed by an END (%d)."),
-                            get_url(), tag);
-                        );
-                    }
-                    goto parse_tag;
-                }
-
-            }
-            else if (_tag_loaders.get(tag, &lf)) {
-                // call the tag loader.  The tag loader should add
-                // DisplayObjects or tags to the movie data structure.
-                lf(str, tag, *this, _runInfo);
-            }
-            else {
-                // no tag loader for this tag type.
-                log_error(_("*** no tag loader for type %d (movie)"), tag);
-                IF_VERBOSE_PARSE(
-                    std::ostringstream ss;
-                    dumpTagBytes(str, ss);
-                    log_error("tag dump follows: %s", ss.str());
-                );
-            }
-
-        }
-        catch (const ParserException& e) {
-            // Log and continue parsing...
-            log_error(_("Parsing exception: %s"), e.what());
-        }
-
-        if ( tagOpened ) str.close_tag();
-
-        setBytesLoaded(str.tell());
+        if (!parser.read(std::min<size_t>(left, chunkSize))) break;
+        
+        left -= parser.bytesRead();
+        setBytesLoaded(startPos + parser.bytesRead());
     }
 
        // Make sure we won't leave any pending writers
        // on any eventual fd-based IOChannel.
-       str.consumeInput();
+       _str->consumeInput();
     
     // Set bytesLoaded to the current stream position unless it's greater
     // than the reported length. TODO: should we be trying to continue
     // parsing after an exception?
-    setBytesLoaded(std::min<size_t>(str.tell(), _swf_end_pos));
+    setBytesLoaded(std::min<size_t>(_str->tell(), _swf_end_pos));
 
        size_t floaded = get_loading_frame();
        if (!m_playlist[floaded].empty())
@@ -666,7 +557,7 @@
        return _frames_loaded;
 }
 
-size_t
+void
 SWFMovieDefinition::incrementLoadedFrames()
 {
        boost::mutex::scoped_lock lock(_frames_loaded_mutex);
@@ -697,7 +588,6 @@
                _frame_reached_condition.notify_all();
        }
 
-       return _frames_loaded;
 }
 
 void

=== modified file 'libcore/parser/SWFMovieDefinition.h'
--- a/libcore/parser/SWFMovieDefinition.h       2009-05-18 13:41:45 +0000
+++ b/libcore/parser/SWFMovieDefinition.h       2009-06-05 10:25:43 +0000
@@ -52,9 +52,6 @@
     class movie_root;
        class MovieClip;
        class SWFMovie;
-       namespace SWF {
-               class TagLoadersTable;
-       }
     class RunInfo;
     class Font;
 }
@@ -428,9 +425,6 @@
        /// Mutex protecting _dictionary
        mutable boost::mutex _dictionaryMutex;
 
-       /// Tags loader table
-       SWF::TagLoadersTable& _tag_loaders;
-
        typedef std::map<int, boost::intrusive_ptr<Font> > FontMap;
        FontMap m_fonts;
 
@@ -527,7 +521,7 @@
        ///
        /// @return the new value of _frames_loaded
        ///
-       size_t incrementLoadedFrames();
+       virtual void incrementLoadedFrames();
 
        /// Set number of bytes loaded from input stream
        //

=== added file 'libcore/parser/SWFParser.cpp'
--- a/libcore/parser/SWFParser.cpp      1970-01-01 00:00:00 +0000
+++ b/libcore/parser/SWFParser.cpp      2009-06-05 11:19:22 +0000
@@ -0,0 +1,167 @@
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// The SWFMovieDefinition is the 'root' definition of a SWF movie, including
+// movies loaded into another SWF file. Each self-contained SWF file has 
exactly
+// one SWFMovieDefinition.
+
+#include "SWFStream.h"
+#include "movie_definition.h"
+#include "RunInfo.h"
+#include "SWFParser.h"
+#include "TagLoadersTable.h"
+
+#include <iomanip>
+
+namespace gnash {
+
+// Forward declarations
+namespace {
+    void dumpTagBytes(SWFStream& in, std::ostream& os);
+}
+
+size_t
+SWFParser::openTag()
+{
+    _tag = _stream.open_tag();
+    _tagOpen = true;
+    return _stream.get_tag_end_position();
+}
+
+void
+SWFParser::closeTag()
+{
+    _stream.close_tag();
+    _tagOpen = false;
+}
+
+bool
+SWFParser::read(std::streamsize bytes)
+{
+
+    // If we didn't use all the bytes given to us last time,
+    // we may read more than the size passed.
+    _endRead += bytes;
+
+    const SWF::TagLoadersTable& tagLoaders = _runInfo.tagLoaders();
+
+    while (_bytesRead < _endRead) {
+        
+        const size_t startPos = _stream.tell();
+
+        try {
+
+            // If a tag hasn't been opened, open one and check
+            // how many bytes are needed. The size reported by the
+            // tag seems to be the value used, even when it's wrong.
+            if (!_tagOpen) {
+                _nextTagEnd = openTag() - startPos;
+            }
+         
+            // Check if we are now supposed to read enough bytes to get to the
+            // end of the tag.   
+            if (_nextTagEnd > _endRead) {
+                return true;
+            }
+
+            // Signal that we have reached the end of a SWF or sprite when
+            // a SWF::END tag is encountered.
+            if (_tag == SWF::END) {
+                closeTag();
+                return false;
+            }
+
+            SWF::TagLoadersTable::loader_function lf = 0;
+
+            if (_tag == SWF::SHOWFRAME) {
+                // show frame tag -- advance to the next frame.
+                IF_VERBOSE_PARSE(log_parse("SHOWFRAME tag"));
+                _md->incrementLoadedFrames();
+            }
+            else if (tagLoaders.get(_tag, &lf)) {
+                // call the tag loader.  The tag loader should add
+                // DisplayObjects or tags to the movie data structure.
+                lf(_stream, _tag, *_md, _runInfo);
+            }
+            else {
+                // no tag loader for this tag type.
+                log_error(_("*** no tag loader for type %d (movie)"), _tag);
+                IF_VERBOSE_PARSE(
+                    std::ostringstream ss;
+                    dumpTagBytes(_stream, ss);
+                    log_error("tag dump follows: %s", ss.str());
+                );
+            }
+
+        }
+        catch (const ParserException& e) {
+            // We continue parsing so that single malformed tags don't
+            // prevent reading subsequent tags.
+            log_error(_("Parsing exception: %s"), e.what());
+        }
+
+        if (_tagOpen) closeTag();
+        _bytesRead += (_stream.tell() - startPos);
+    }
+
+    return true;
+
+}
+
+namespace {
+
+/// Log the contents of the current tag, in hex to the output strream
+void 
+dumpTagBytes(SWFStream& in, std::ostream& os)
+{
+    const std::streamsize rowlength = 16;
+    os << std::endl;
+    
+    const std::streamsize end = in.get_tag_end_position();
+
+    // This is decremented until we reach the end of the stream.
+    std::streamsize toRead = end - in.tell();
+    in.ensureBytes(toRead);
+
+    unsigned char buf[rowlength];    
+    while (toRead)
+    {
+        // Read in max row length or remainder of stream.
+        const std::streamsize thisRow = 
+            std::min<std::streamsize>(toRead, rowlength);
+        
+        const std::streamsize got = 
+            in.read(reinterpret_cast<char*>(&buf), thisRow);
+        
+        // Check that we read all the bytes we expected.
+        if (got < thisRow) {
+            throw ParserException(_("Unexpected end of stream while reading"));
+        }
+        
+        // Stream once as hex
+        os << std::left << std::setw(3 * rowlength) << hexify(buf, got, false);
+        
+        // and once as ASCII
+        os << "| " << hexify(buf, got, true) << std::endl;
+
+        toRead -= got;
+    }
+}
+
+} // anonymous namespace
+
+} // namespace gnash

=== added file 'libcore/parser/SWFParser.h'
--- a/libcore/parser/SWFParser.h        1970-01-01 00:00:00 +0000
+++ b/libcore/parser/SWFParser.h        2009-06-05 11:19:22 +0000
@@ -0,0 +1,109 @@
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// The SWFMovieDefinition is the 'root' definition of a SWF movie, including
+// movies loaded into another SWF file. Each self-contained SWF file has 
exactly
+// one SWFMovieDefinition.
+
+#ifndef GNASH_SWFPARSER_H
+#define GNASH_SWFPARSER_H
+
+#include "swf.h"
+#include "TagLoadersTable.h"
+
+namespace gnash {
+    class SWFStream;
+    class movie_definition;
+    class RunInfo;
+}
+
+namespace gnash {
+
+
+/// The SWFParser parses tags from a SWFStream.
+//
+/// The definitions created from the tags are added to one of the higher-level
+/// definition types: either a sprite_definition or a SWFMovieDefinition.
+//
+/// SWFParser's interface deals only with the size of data it has to read, or
+/// the number of bytes read. It does not expose the absolute stream position.
+/// This is intended to make internal refactoring simpler. Users must tell
+/// the SWFParser how many bytes it should read from the stream.
+class SWFParser
+{
+
+public:
+    SWFParser(SWFStream& in, movie_definition* md, const RunInfo& runInfo)
+        :
+        _stream(in),
+        _md(md),
+        _runInfo(runInfo),
+        _bytesRead(0),
+        _tagOpen(false),
+        _endRead(0),
+        _nextTagEnd(0)
+
+    {
+    }
+
+    /// The number of bytes processed by this SWFParser.
+    size_t bytesRead() const {
+        return _bytesRead;
+    }
+
+    /// Parse a specified number of bytes from the stream.
+    //
+    /// This function will as many complete tags as it can in the specified
+    /// number of bytes. Any incomplete tags will be left open and unparsed
+    /// until the next call to read().
+    //
+    /// @param bytes    The number of bytes to read. Callers must ensure
+    ///                 this is not past the end of the stream, or this
+    ///                 function may never return.
+    //
+    /// @return         False if the end of a SWF is reached during parsing.
+    ///                 This can be mean that a SWF::END tag appears before
+    ///                 the end of the bytes to parse.
+    bool read(std::streamsize bytes);
+    
+private:
+
+    size_t openTag();
+
+    void closeTag();
+
+    SWFStream& _stream;
+    
+    movie_definition* _md;
+    
+    const RunInfo& _runInfo;
+    
+    size_t _bytesRead;
+    
+    bool _tagOpen;
+    
+    size_t _endRead;
+    
+    size_t _nextTagEnd;
+    
+    SWF::TagType _tag;
+
+};
+
+} // namespace gnash
+
+#endif

=== modified file 'libcore/parser/movie_definition.h'
--- a/libcore/parser/movie_definition.h 2009-05-18 13:41:45 +0000
+++ b/libcore/parser/movie_definition.h 2009-06-05 10:25:43 +0000
@@ -139,6 +139,7 @@
                return NULL;
        }
        
+    virtual void incrementLoadedFrames() {}
 
        /// Return the list of execute tags for given frame number
        //

=== modified file 'libcore/parser/sprite_definition.cpp'
--- a/libcore/parser/sprite_definition.cpp      2009-05-14 11:45:23 +0000
+++ b/libcore/parser/sprite_definition.cpp      2009-06-05 10:36:48 +0000
@@ -27,6 +27,7 @@
 #include "as_function.h" // for dtor visibility
 #include "SWFStream.h" // for use
 #include "GnashAlgorithm.h"
+#include "SWFParser.h"
 
 #include <vector>
 #include <string>
@@ -65,7 +66,7 @@
 void
 sprite_definition::read(SWFStream& in, const RunInfo& runInfo)
 {
-    unsigned long tag_end = in.get_tag_end_position();
+    const size_t tag_end = in.get_tag_end_position();
 
     in.ensureBytes(2);
     m_frame_count = in.read_u16();
@@ -76,69 +77,9 @@
 
        m_loading_frame = 0;
 
-       while (in.tell() < tag_end) {
-
-               SWF::TagType tag = in.open_tag();
-
-               SWF::TagLoadersTable::loader_function lf = 0;
-
-               if (tag == SWF::END) {
-
-                       if (in.tell() != tag_end) {
-                IF_VERBOSE_MALFORMED_SWF(
-                    // Safety break, so we don't read past
-                    // the end of the  movie.
-                    log_swferror(_("Hit end tag, "
-                        "before the advertised DEFINESPRITE end; "
-                        "stopping for safety."));
-                    );
-                               in.close_tag();
-                break;
-                       }
-               }
-
-               else if (tag == SWF::SHOWFRAME) {
-                       // show frame tag -- advance to the next frame.
-            ++m_loading_frame;
-
-                       IF_VERBOSE_PARSE (
-                               log_parse(_("  show_frame %d/%d"
-                                       " (sprite)"),
-                                       m_loading_frame,
-                                       m_frame_count);
-                       );
-
-                       if (m_loading_frame == m_frame_count) {
-
-                               // better break then sorry
-                               in.close_tag();
-                               if (in.open_tag() != SWF::END)
-                               {
-                                       IF_VERBOSE_MALFORMED_SWF(
-                        log_swferror(_("last SHOWFRAME of a "
-                            "DEFINESPRITE tag "
-                            "isn't followed by an END."
-                            " Stopping for safety."));
-                    );
-                                       in.close_tag();
-                                       return;
-                               }
-                       }
-               }
-               else if (_tag_loaders.get(tag, &lf)) {
-                   // call the tag loader.  The tag loader should add
-                   // DisplayObjects or tags to the movie data structure.
-                   (*lf)(in, tag, *this, runInfo);
-               }
-               else {
-                       // no tag loader for this tag type.
-                       // FIXME, should this be a log_swferror instead?
-                    log_error(_("*** no tag loader for type %d (sprite)"),
-                              tag);
-               }
-
-               in.close_tag();
-       }
+    SWFParser parser(in, this, runInfo);
+
+    parser.read(tag_end - in.tell());
 
     if (m_frame_count > m_loading_frame) {
         IF_VERBOSE_MALFORMED_SWF(
@@ -178,8 +119,6 @@
 sprite_definition::sprite_definition(movie_definition& m, SWFStream& in, 
         const RunInfo& runInfo)
        :
-       // FIXME: use a class-static TagLoadersTable for sprite_definition
-       _tag_loaders(SWF::TagLoadersTable::getInstance()),
        m_movie_def(m),
        m_frame_count(0),
        m_loading_frame(0),

=== modified file 'libcore/parser/sprite_definition.h'
--- a/libcore/parser/sprite_definition.h        2009-05-18 13:41:45 +0000
+++ b/libcore/parser/sprite_definition.h        2009-06-05 10:36:48 +0000
@@ -28,7 +28,6 @@
 #include "log.h"
 #include "rect.h"
 #include "StringPredicates.h" // StringNoCaseLessThan
-#include "TagLoadersTable.h"
 
 // Forward declarations
 namespace gnash {
@@ -87,6 +86,10 @@
                return registeredClass.get();
        }
 
+    virtual void incrementLoadedFrames() {
+        ++m_loading_frame;
+    }
+
        // overload from movie_definition
        virtual float   get_width_pixels() const { return 1; }
 
@@ -245,11 +248,6 @@
 
        void read(SWFStream& in, const RunInfo& runInfo);
 
-       /// Tags loader table.
-       //
-       /// TODO: make it a static member, specific to sprite_definition
-       SWF::TagLoadersTable& _tag_loaders;
-
        /// Top-level movie definition
        /// (the definition read from SWF stream)
        movie_definition& m_movie_def;
@@ -268,8 +266,6 @@
        // Number of frames completely parsed 
        size_t m_loading_frame;
 
-
-
        // See dox in movie_definition.h
        virtual void add_frame_name(const std::string& name);
 

=== modified file 'libcore/swf/TagLoadersTable.cpp'
--- a/libcore/swf/TagLoadersTable.cpp   2009-01-22 20:10:39 +0000
+++ b/libcore/swf/TagLoadersTable.cpp   2009-06-05 11:19:22 +0000
@@ -29,12 +29,12 @@
 namespace SWF {
 
 bool
-TagLoadersTable::get(SWF::TagType t, loader_function* lf)
+TagLoadersTable::get(SWF::TagType t, loader_function* lf) const
 {
-       container::iterator it = _tag_loaders.find(t);
+       container::const_iterator it = _tag_loaders.find(t);
 
        // no loader found for the specified tag
-       if ( it == _tag_loaders.end() ) return false;
+       if (it == _tag_loaders.end()) return false;
 
        // copy loader_function to the given pointer
        *lf = it->second;

=== modified file 'libcore/swf/TagLoadersTable.h'
--- a/libcore/swf/TagLoadersTable.h     2009-02-20 12:24:00 +0000
+++ b/libcore/swf/TagLoadersTable.h     2009-06-05 11:19:22 +0000
@@ -57,7 +57,7 @@
        //
        /// @return false if no loader is associated with the tag.
        ///
-       bool get(TagType t, loader_function* lf);
+       bool get(TagType t, loader_function* lf) const;
 
        /// \brief
        /// Register a loader for the specified SWF::TagType.


reply via email to

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