gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10239: Consolidate parsing of Sound


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10239: Consolidate parsing of SoundInfo records into one place (used in StartSound,
Date: Fri, 07 Nov 2008 14:19:51 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10239
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2008-11-07 14:19:51 +0100
message:
  Consolidate parsing of SoundInfo records into one place (used in StartSound,
  DefineButtonSound, and (not implemented) StartSound2).
  
  Add StartSound2 and log unimplemented.
  
  Split parsing of DefineButtonSound from button_character_def and move into
  swf directory. Clean it up.
added:
  libcore/swf/DefineButtonSoundTag.cpp
  libcore/swf/DefineButtonSoundTag.h
  libcore/swf/SoundInfoRecord.cpp
  libcore/swf/SoundInfoRecord.h
modified:
  libcore/Button.cpp
  libcore/Makefile.am
  libcore/impl.cpp
  libcore/parser/button_character_def.cpp
  libcore/parser/button_character_def.h
  libcore/swf.h
  libcore/swf/StartSoundTag.cpp
  libcore/swf/StartSoundTag.h
  libcore/swf/tag_loaders.cpp
  libcore/swf/tag_loaders.h
    ------------------------------------------------------------
    revno: 10229.1.16
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 11:57:43 +0100
    message:
      Split DefineButtonSoundTag parsing into a separate file. Clean it up and 
make
      access clearer.
    added:
      libcore/swf/DefineButtonSoundTag.cpp
      libcore/swf/DefineButtonSoundTag.h
    modified:
      libcore/Button.cpp
      libcore/Makefile.am
      libcore/impl.cpp
      libcore/parser/button_character_def.cpp
      libcore/parser/button_character_def.h
      libcore/swf/tag_loaders.cpp
      libcore/swf/tag_loaders.h
    ------------------------------------------------------------
    revno: 10229.1.17
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 12:35:40 +0100
    message:
      Use SoundInfoRecord to parse a SoundInfo record.
    added:
      libcore/swf/SoundInfoRecord.cpp
      libcore/swf/SoundInfoRecord.h
    modified:
      libcore/Makefile.am
      libcore/swf/DefineButtonSoundTag.cpp
      libcore/swf/DefineButtonSoundTag.h
    ------------------------------------------------------------
    revno: 10229.1.18
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 13:19:16 +0100
    message:
      Construct StartSoundTag directly from a stream. Rename members of 
SoundInfo.
    modified:
      libcore/Button.cpp
      libcore/swf/SoundInfoRecord.cpp
      libcore/swf/SoundInfoRecord.h
      libcore/swf/StartSoundTag.cpp
      libcore/swf/StartSoundTag.h
    ------------------------------------------------------------
    revno: 10229.1.19
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 13:47:31 +0100
    message:
      Add StartSound2Tag (for logging, not implemented).
    modified:
      libcore/impl.cpp
      libcore/swf.h
      libcore/swf/StartSoundTag.cpp
      libcore/swf/StartSoundTag.h
    ------------------------------------------------------------
    revno: 10229.1.20
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 13:55:48 +0100
    message:
      Correct typo.
    modified:
      libcore/swf/StartSoundTag.cpp
=== modified file 'libcore/Button.cpp'
--- a/libcore/Button.cpp        2008-10-28 15:32:20 +0000
+++ b/libcore/Button.cpp        2008-11-07 12:19:16 +0000
@@ -515,7 +515,7 @@
        set_current_state(new_state);
     
        // Button transition sounds.
-       if (_def.m_sound != NULL)
+       if (_def.hasSound())
        {
                int bi; // button sound array index [0..3]
                sound::sound_handler* s = 
_vm.getRoot().runInfo().soundHandler();
@@ -542,19 +542,22 @@
                        }
                        if (bi >= 0)
                        {
-                               button_character_definition::button_sound_info& 
bs = _def.m_sound->m_button_sounds[bi];
+                               const SWF::DefineButtonSoundTag::ButtonSound& 
bs = _def.buttonSound(bi);
                                // character zero is considered as null 
character
-                               if (bs.m_sound_id > 0)
+                               if (bs.soundID > 0)
                                {
-                                       if 
(_def.m_sound->m_button_sounds[bi].m_sam != NULL)
+                                       if (bs.sample)
                                        {
-                                               if 
(bs.m_sound_style.m_stop_playback)
+                                               if (bs.soundInfo.stopPlayback)
                                                {
-                                                       
s->stop_sound(bs.m_sam->m_sound_handler_id);
+                                                       
s->stop_sound(bs.sample->m_sound_handler_id);
                                                }
                                                else
                                                {
-                                                       
s->play_sound(bs.m_sam->m_sound_handler_id, bs.m_sound_style.m_loop_count, 0, 
0, (bs.m_sound_style.m_envelopes.size() == 0 ? NULL : 
&bs.m_sound_style.m_envelopes));
+                                                       
s->play_sound(bs.sample->m_sound_handler_id,
+                                    bs.soundInfo.loopCount, 0, 0, 
+                                    (bs.soundInfo.envelopes.empty() ? NULL :
+                                                    &bs.soundInfo.envelopes));
                                                }
                                        }
                                }
@@ -562,7 +565,7 @@
                }
        }
 
-       // From: "ActionScript - The Definiteve Guide" by Colin Moock
+       // From: "ActionScript - The Definitive Guide" by Colin Moock
        // (chapter 10: Events and Event Handlers)
        //
        // "Event-based code [..] is said to be executed asynchronously

=== modified file 'libcore/Makefile.am'
--- a/libcore/Makefile.am       2008-11-06 23:06:02 +0000
+++ b/libcore/Makefile.am       2008-11-07 11:35:40 +0000
@@ -83,7 +83,9 @@
        MovieClip.cpp \
        swf/TagLoadersTable.cpp \
        swf/DefineVideoStreamTag.cpp \
+       swf/DefineButtonSoundTag.cpp \
        swf/VideoFrameTag.cpp \
+       swf/SoundInfoRecord.cpp \
        swf/tag_loaders.cpp \
        swf/DefineFontAlignZonesTag.cpp \
        swf/DefineEditTextTag.cpp \
@@ -182,6 +184,8 @@
        swf/ControlTag.h \
        swf/DefineFontAlignZonesTag.h \
        swf/CSMTextSettingsTag.h \
+       swf/SoundInfoRecord.h \
+       swf/DefineButtonSoundTag.h \
        swf/DefineEditTextTag.h \
        swf/DefineButtonCxformTag.h \
        swf/PlaceObject2Tag.h \

=== modified file 'libcore/impl.cpp'
--- a/libcore/impl.cpp  2008-11-06 22:57:43 +0000
+++ b/libcore/impl.cpp  2008-11-07 12:47:31 +0000
@@ -47,6 +47,7 @@
 #include "SetBackgroundColorTag.h"
 #include "StartSoundTag.h"
 #include "StreamSoundBlockTag.h"
+#include "DefineButtonSoundTag.h"
 #include "DefineVideoStreamTag.h"
 #include "VideoFrameTag.h"
 #include "swf/tag_loaders.h" // for all tag loaders..
@@ -108,13 +109,17 @@
     register_tag_loader(SWF::DEFINEFONTINFO, define_font_info_loader);
     register_tag_loader(SWF::DEFINEFONTINFO2, define_font_info_loader); // 62
     register_tag_loader(SWF::DEFINESOUND, define_sound_loader);
-    register_tag_loader(SWF::STARTSOUND,  StartSoundTag::loader);
+    register_tag_loader(SWF::STARTSOUND, StartSoundTag::loader);
+    register_tag_loader(SWF::STARTSOUND2, StartSound2Tag::loader);
 
     register_tag_loader(SWF::STOPSOUND,     fixme_loader); // 16 
 
-    register_tag_loader(SWF::DEFINEBUTTONSOUND, button_sound_loader);
-    register_tag_loader(SWF::SOUNDSTREAMHEAD, sound_stream_head_loader); // 18
-    register_tag_loader(SWF::SOUNDSTREAMBLOCK, StreamSoundBlockTag::loader); 
// 19
+    // 17
+    register_tag_loader(SWF::DEFINEBUTTONSOUND, DefineButtonSoundTag::loader);
+    // 18
+    register_tag_loader(SWF::SOUNDSTREAMHEAD, sound_stream_head_loader);
+    // 19
+    register_tag_loader(SWF::SOUNDSTREAMBLOCK, StreamSoundBlockTag::loader);
     register_tag_loader(SWF::DEFINELOSSLESS, define_bits_lossless_2_loader);
     register_tag_loader(SWF::DEFINEBITSJPEG2, define_bits_jpeg2_loader);
     register_tag_loader(SWF::DEFINESHAPE2,  define_shape_loader);

=== modified file 'libcore/parser/button_character_def.cpp'
--- a/libcore/parser/button_character_def.cpp   2008-10-19 19:36:12 +0000
+++ b/libcore/parser/button_character_def.cpp   2008-11-07 10:57:43 +0000
@@ -220,7 +220,7 @@
 
 button_character_definition::button_character_definition(movie_definition& m)
        :
-       m_sound(NULL),
+       _soundTag(0),
        _movieDef(m)
 
 // Constructor.
@@ -238,66 +238,6 @@
 }
 
 
-void button_character_definition::sound_info::read(SWFStream& in)
-{
-       in.ensureBytes(1);
-       m_in_point = m_out_point = m_loop_count = 0;
-    
-    // highest 2 bits are reserved(unused).
-    int flags = in.read_u8();
-       m_stop_playback = flags & (1 << 5); 
-       m_no_multiple   = flags & (1 << 4); 
-       m_has_envelope  = flags & (1 << 3); 
-       m_has_loops     = flags & (1 << 2);  
-       m_has_out_point = flags & (1 << 1); 
-       m_has_in_point  = flags & (1 << 0);  
-    
-       if (m_has_in_point)
-       {
-               in.ensureBytes(4);
-               m_in_point = in.read_u32();
-       }
-       if (m_has_out_point)
-       {
-               in.ensureBytes(4);
-               m_out_point = in.read_u32();
-       }
-       if (m_has_loops)
-       {
-               in.ensureBytes(2);
-               m_loop_count = in.read_u16();
-       }
-       if (m_has_envelope)
-       {
-               in.ensureBytes(1);
-               int nPoints = in.read_u8();
-               m_envelopes.resize(nPoints);
-               in.ensureBytes(8 * nPoints);
-               for (int i=0; i < nPoints; i++)
-               {
-                       m_envelopes[i].m_mark44 = in.read_u32();
-                       m_envelopes[i].m_level0 = in.read_u16();
-                       m_envelopes[i].m_level1 = in.read_u16();
-               }
-       }
-       else
-       {
-               m_envelopes.resize(0);
-       }
-
-
-       IF_VERBOSE_PARSE(
-       log_parse("     has_envelope = %d", m_has_envelope);
-       log_parse("     has_loops = %d", m_has_loops);
-       log_parse("     has_out_point = %d", m_has_out_point);
-       log_parse("     has_in_point = %d", m_has_in_point);
-       log_parse("     in_point = %d", m_in_point);
-       log_parse("     out_point = %d", m_out_point);
-       log_parse("     loop_count = %d", m_loop_count);
-       log_parse("     envelope size = %d", m_envelopes.size());
-       );
-}
-
 void
 button_character_definition::readDefineButton(SWFStream& in, movie_definition& 
m)
 {
@@ -442,46 +382,6 @@
        }
 }
 
-void
-button_character_definition::readDefineButtonSound(SWFStream& in, 
movie_definition& m)
-{
-       // Character ID has been read already
-
-       if ( m_sound )
-       {
-               IF_VERBOSE_MALFORMED_SWF(
-               log_swferror(_("Attempt to redefine button sound ignored"));
-               );
-               return;
-       }
-
-       m_sound.reset( new button_sound_def() );
-
-       IF_VERBOSE_PARSE(
-       log_parse(_("button sound options: "));
-       );
-
-       for (int i = 0; i < 4; i++)
-       {
-               button_sound_info& bs = m_sound->m_button_sounds[i];
-               in.ensureBytes(2);
-               bs.m_sound_id = in.read_u16();
-               if (bs.m_sound_id)
-               {
-                       bs.m_sam = m.get_sound_sample(bs.m_sound_id);
-                       if ( ! bs.m_sam )
-                       {
-                               IF_VERBOSE_MALFORMED_SWF(
-                               log_swferror(_("sound tag not found, 
sound_id=%d, button state #=%i"), bs.m_sound_id, i);
-                               );
-                       }
-                       IF_VERBOSE_PARSE(
-                       log_parse("\tsound_id = %d", bs.m_sound_id);
-                       );
-                       bs.m_sound_style.read(in);
-               }
-       }
-}
 
 
 void
@@ -494,9 +394,6 @@
                case SWF::DEFINEBUTTON:
                        readDefineButton(in, m);
                        break;
-               case SWF::DEFINEBUTTONSOUND:
-                       readDefineButtonSound(in, m);
-                       break;
                case SWF::DEFINEBUTTON2:
                        readDefineButton2(in, m);
                        break;
@@ -514,14 +411,6 @@
        return ch;
 }
 
-#ifdef GNASH_USE_GC
-void
-button_character_definition::button_sound_info::markReachableResources() const
-{
-       if ( m_sam ) m_sam->setReachable();
-}
-#endif // GNASH_USE_GC
-
 int
 button_character_definition::getSWFVersion() const
 {

=== modified file 'libcore/parser/button_character_def.h'
--- a/libcore/parser/button_character_def.h     2008-10-31 14:18:51 +0000
+++ b/libcore/parser/button_character_def.h     2008-11-07 10:57:43 +0000
@@ -1,4 +1,3 @@
-// button_character_def.h:  Mouse-sensitive SWF buttons, for Gnash.
 //
 //   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
 //
@@ -31,9 +30,11 @@
 #include "action_buffer.h" // for composition of button_action
 #include "filter_factory.h" // for Filters (composition of button_record)
 #include "sound_handler.h" // for sound_handler::sound_envelope in a vector..
+#include "DefineButtonSoundTag.h"
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/cstdint.hpp> // for boost::uint64_t typedef
+#include <memory>
 
 // Forward declarations
 namespace gnash {
@@ -96,9 +97,8 @@
        /// @param endPos
        ///     Last stream offset available for a valid read
        ///
-       /// TODO: take the stream by ref, not pointer
-       ///
-       bool    read(SWFStream& in, int tag_type, movie_definition& m, unsigned 
long endPos);
+       bool read(SWFStream& in, int tag_type, movie_definition& m,
+            unsigned long endPos);
 
        /// Return true if the button_record is valid
        //
@@ -134,7 +134,8 @@
        ///     The movie_definition this button action was read from
        ///
        ///
-       button_action(SWFStream& in, int tag_type, unsigned long endPos, 
movie_definition& mdef);
+       button_action(SWFStream& in, int tag_type, unsigned long endPos,
+            movie_definition& mdef);
 
        /// Return true if this action should be triggered by the given event.
        bool triggeredBy(const event_id& ev) const;
@@ -178,66 +179,6 @@
 {
 public:
 
-       struct sound_info
-       {
-               void read(SWFStream& in);
-
-               bool m_no_multiple;
-               bool m_stop_playback;
-               bool m_has_envelope;
-               bool m_has_loops;
-               bool m_has_out_point;
-               bool m_has_in_point;
-               boost::uint32_t m_in_point;
-               boost::uint32_t m_out_point;
-               boost::uint16_t m_loop_count;
-               sound::SoundEnvelopes m_envelopes;
-       };
-
-       struct button_sound_info
-       {
-               boost::uint16_t m_sound_id;
-               sound_sample*   m_sam;
-               sound_info m_sound_style;
-
-               button_sound_info()
-                       :
-                       m_sam(0)
-               {
-               }
-
-#ifdef GNASH_USE_GC
-               /// Mark all reachable resources (for GC)
-               //
-               /// Reachable resources are:
-               ///  - sound sample (m_sam)
-               ///
-               void markReachableResources() const;
-#endif // GNASH_USE_GC
-       };
-
-       struct button_sound_def
-       {
-               // TODO: implement ?
-               //void  read(SWFStream& in, movie_definition& m);
-
-               button_sound_info m_button_sounds[4];
-
-#ifdef GNASH_USE_GC
-               /// Mark all reachable resources (for GC)
-               //
-               /// Reachable resources are:
-               ///  - button sound infos (m_button_sounds)
-               ///
-               void markReachableResources() const
-               {
-                       for (int i=0; i<4; ++i)
-                       {
-                               m_button_sounds[i].markReachableResources();
-                       }
-               }
-#endif // GNASH_USE_GC
-       };
 
        /// \brief
        /// Construct a character definition as read from
@@ -258,9 +199,6 @@
        /// Read a SWF::DEFINEBUTTON2 tag
        void    readDefineButton2(SWFStream& in, movie_definition& m);
 
-       /// Read a SWF::DEFINEBUTTONSOUND tag
-       void    readDefineButtonSound(SWFStream& in, movie_definition& m);
-       
        /// Read a SWF::DEFINEBUTTONCXFORM tag
        void readDefineButtonCxform(SWFStream& in, movie_definition& m);
        
@@ -277,6 +215,23 @@
                return unused;
        }
   
+
+    /// Does this button have an associated DefineButtonSoundTag?
+    bool hasSound() const { return (_soundTag.get()); }
+
+    void addSoundTag(std::auto_ptr<SWF::DefineButtonSoundTag> soundTag) {
+        _soundTag.reset(soundTag.release());
+    }
+
+    /// Return one of the four sounds associated with this Button
+    //
+    /// @param index    The sound index (0-3) to get.
+    /// Do not call this function without checking hasSound() first.
+    const SWF::DefineButtonSoundTag::ButtonSound& buttonSound(size_t index) 
const {
+        assert(_soundTag.get());
+        return _soundTag->getSound(index);
+    }
+
        /// \brief
        /// Return version of the SWF containing
        /// this button definition.
@@ -311,12 +266,13 @@
        void markReachableResources() const
        {
                assert(isReachable());
-               for (ButtonRecVect::const_iterator i=m_button_records.begin(), 
e=m_button_records.end(); i!=e; ++i)
+               for (ButtonRecVect::const_iterator i=m_button_records.begin(),
+                e=m_button_records.end(); i!=e; ++i)
                {
                        i->markReachableResources();
                }
 
-               if ( m_sound ) m_sound->markReachableResources();
+               if (_soundTag) _soundTag->markReachableResources();
        }
 #endif // GNASH_USE_GC
 
@@ -325,7 +281,7 @@
        typedef std::vector<button_record> ButtonRecVect; 
        ButtonRecVect m_button_records;
 
-       boost::scoped_ptr<button_sound_def> m_sound;
+       boost::scoped_ptr<SWF::DefineButtonSoundTag> _soundTag;
 
 private:
 

=== modified file 'libcore/swf.h'
--- a/libcore/swf.h     2008-07-03 23:45:54 +0000
+++ b/libcore/swf.h     2008-11-07 12:47:31 +0000
@@ -168,6 +168,8 @@
 
     DEFINEFONTNAME        = 88,        
 
+    STARTSOUND2           = 89,
+
     REFLEX                = 777,
 
     DEFINEBITSPTR         = 1023

=== added file 'libcore/swf/DefineButtonSoundTag.cpp'
--- a/libcore/swf/DefineButtonSoundTag.cpp      1970-01-01 00:00:00 +0000
+++ b/libcore/swf/DefineButtonSoundTag.cpp      2008-11-07 11:35:40 +0000
@@ -0,0 +1,111 @@
+// DefineButtonSoundTag.cpp: sounds for Button characters.
+//
+//   Copyright (C) 2006, 2007, 2008 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
+//
+
+#include "DefineButtonSoundTag.h"
+#include <vector>
+#include "movie_definition.h"
+#include "SoundInfoRecord.h"
+#include "SWFStream.h"
+#include "button_character_def.h"
+
+namespace gnash {
+namespace SWF {
+
+DefineButtonSoundTag::DefineButtonSoundTag(SWFStream& in, movie_definition& m)
+    :
+    _sounds(4, ButtonSound())
+{
+    read(in, m);
+}
+
+void
+DefineButtonSoundTag::loader(SWFStream& in, tag_type tag, movie_definition& m,
+        const RunInfo& /*r*/)
+{
+    assert(tag == SWF::DEFINEBUTTONSOUND);
+
+    in.ensureBytes(2);
+    int id = in.read_u16();
+    character_def* chdef = m.get_character_def(id);
+    if (!chdef)
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+        log_swferror(_("DEFINEBUTTONSOUND refers to an unknown "
+                "character def %d"), id);
+        );
+        return;
+    }
+
+    button_character_definition* button = 
+        dynamic_cast<button_character_definition*> (chdef);
+
+    if (!button)
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+            log_swferror(_("DEFINEBUTTONSOUND refers to character id "
+                "%d, a %s (expected a button character)"),
+                id, typeName(*chdef));
+        );
+        return;
+    }
+
+    if (button->hasSound())
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+            log_swferror(_("Attempt to redefine button sound ignored"));
+        );
+        return;
+    }
+
+    std::auto_ptr<DefineButtonSoundTag> bs(
+            new DefineButtonSoundTag(in, m));
+    button->addSoundTag(bs);
+}
+
+
+void
+DefineButtonSoundTag::read(SWFStream& in, movie_definition& m)
+{
+
+       for (Sounds::iterator i = _sounds.begin(), e = _sounds.end(); i != e; 
++i)
+       {
+               ButtonSound& sound = *i;
+               in.ensureBytes(2);
+               sound.soundID = in.read_u16();
+               if (sound.soundID)
+               {
+                       sound.sample = m.get_sound_sample(sound.soundID);
+                       if (!sound.sample)
+                       {
+                               IF_VERBOSE_MALFORMED_SWF(
+                               log_swferror(_("sound tag not found, 
sound_id=%d, "
+                        "button state #=%i"), sound.soundID);
+                               );
+                       }
+                       IF_VERBOSE_PARSE(
+                log_parse("\tsound_id = %d", sound.soundID);
+                       );
+                       sound.soundInfo.read(in);
+               }
+       }
+}
+
+
+}
+}

=== added file 'libcore/swf/DefineButtonSoundTag.h'
--- a/libcore/swf/DefineButtonSoundTag.h        1970-01-01 00:00:00 +0000
+++ b/libcore/swf/DefineButtonSoundTag.h        2008-11-07 11:35:40 +0000
@@ -0,0 +1,109 @@
+// DefineButtonSoundTag.h: sounds for Button characters.
+//
+//   Copyright (C) 2006, 2007, 2008 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
+//
+
+#ifndef GNASH_SWF_DEFINEBUTTONSOUNDTAG_H
+#define GNASH_SWF_DEFINEBUTTONSOUNDTAG_H
+
+#include "smart_ptr.h"
+#include "swf.h"
+#include "sound_definition.h" // For sound_sample. Ugh.
+#include "SoundInfoRecord.h" 
+
+#include <vector>
+
+namespace gnash {
+    class SWFStream;
+    class RunInfo;
+    class movie_definition;
+}
+
+namespace gnash {
+namespace SWF {
+
+class DefineButtonSoundTag
+{
+
+public:
+
+       struct ButtonSound
+       {
+               boost::uint16_t soundID;
+               sound_sample* sample;
+               SoundInfo soundInfo;
+
+               ButtonSound()
+                       :
+            soundID(0),
+                       sample(0)
+               {}
+
+#ifdef GNASH_USE_GC
+               /// Mark all reachable resources (for GC)
+               //
+               /// Reachable resources are:
+               ///  - sound sample (sample)
+               ///
+               void markReachableResources() const
+        {
+            if (sample) sample->setReachable();
+        }
+#endif // GNASH_USE_GC
+       };
+
+    typedef std::vector<ButtonSound> Sounds;
+
+    DefineButtonSoundTag(SWFStream& in, movie_definition& m);
+
+    static void loader(SWFStream& in, tag_type tag, movie_definition& m,
+                   const RunInfo& r);
+
+    const ButtonSound& getSound(Sounds::size_type index) const
+    {
+        // There should be exactly four sounds.
+        assert (index < 4);
+        return _sounds[index];
+    }
+#ifdef GNASH_USE_GC
+    /// Mark all reachable resources (for GC)
+    //
+    /// Reachable resources are:
+    ///  - button sound infos (m_button_sounds)
+    ///
+    void markReachableResources() const
+    {
+        for (Sounds::const_iterator i=_sounds.begin(), e = _sounds.end();
+                i != e; ++i)
+        {
+            i->markReachableResources();
+        }
+    }
+#endif // GNASH_USE_GC
+
+private:
+
+    void read(SWFStream& in, movie_definition& m);
+
+    Sounds _sounds;
+
+};
+
+}
+}
+
+#endif

=== added file 'libcore/swf/SoundInfoRecord.cpp'
--- a/libcore/swf/SoundInfoRecord.cpp   1970-01-01 00:00:00 +0000
+++ b/libcore/swf/SoundInfoRecord.cpp   2008-11-07 12:19:16 +0000
@@ -0,0 +1,94 @@
+// SoundInfo.cpp: parse and store a SoundInfo record.
+//
+//   Copyright (C) 2006, 2007, 2008 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
+//
+
+
+#include "SoundInfoRecord.h"
+#include "sound_handler.h" // sound::SoundEnvelopes
+#include "SWFStream.h"
+#include "log.h"
+
+namespace gnash {
+namespace SWF {
+
+
+void
+SoundInfo::read(SWFStream& in)
+{
+       in.ensureBytes(1);
+    
+    // highest 2 bits are reserved(unused).
+    int flags = in.read_u8();
+       stopPlayback = flags & (1 << 5); 
+       noMultiple   = flags & (1 << 4); 
+       hasEnvelope  = flags & (1 << 3); 
+       hasLoops     = flags & (1 << 2);  
+       hasOutPoint = flags & (1 << 1); 
+       hasInPoint  = flags & (1 << 0);  
+    
+    if (noMultiple) {
+        LOG_ONCE(log_unimpl("syncNoMultiple flag in SoundInfo record"));
+    }
+
+    in.ensureBytes(hasInPoint * 4 + hasOutPoint * 4 + hasLoops * 2);
+
+       if (hasInPoint) {
+               log_unimpl(_("SoundInfo record with in point"));
+               inPoint = in.read_u32();
+       }
+
+       if (hasOutPoint) {
+               log_unimpl(_("SoundInfo record with out point"));
+               outPoint = in.read_u32();
+       }
+
+       if (hasLoops) {
+               loopCount = in.read_u16();
+       }
+
+       if (hasEnvelope) {
+               in.ensureBytes(1);
+               int nPoints = in.read_u8();
+               envelopes.resize(nPoints);
+               in.ensureBytes(8 * nPoints);
+               for (int i=0; i < nPoints; i++)
+               {
+                       envelopes[i].m_mark44 = in.read_u32();
+                       envelopes[i].m_level0 = in.read_u16();
+                       envelopes[i].m_level1 = in.read_u16();
+               }
+       }
+       else {
+               envelopes.clear();
+       }
+
+       IF_VERBOSE_PARSE(
+        log_parse("    hasEnvelope = %d", hasEnvelope);
+        log_parse("    hasLoops = %d", hasLoops);
+        log_parse("    hasOutPoint = %d", hasOutPoint);
+        log_parse("    hasInPoint = %d", hasInPoint);
+        log_parse("    inPoint = %d", inPoint);
+        log_parse("    outPoint = %d", outPoint);
+        log_parse("    loopCount = %d", loopCount);
+        log_parse("    envelope size = %d", envelopes.size());
+       );
+}
+
+}
+}
+

=== added file 'libcore/swf/SoundInfoRecord.h'
--- a/libcore/swf/SoundInfoRecord.h     1970-01-01 00:00:00 +0000
+++ b/libcore/swf/SoundInfoRecord.h     2008-11-07 12:19:16 +0000
@@ -0,0 +1,85 @@
+// SoundInfo.h: parse and store a SoundInfo record.
+//
+//   Copyright (C) 2006, 2007, 2008 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
+//
+
+#ifndef GNASH_SWF_SOUNDINFO_H
+#define GNASH_SWF_SOUNDINFO_H
+
+#include "sound_handler.h" // sound::SoundEnvelopes
+
+namespace gnash {
+    class SWFStream;
+}
+
+namespace gnash {
+namespace SWF {
+
+struct SoundInfo
+{
+    /// Construct a SoundInfo record object
+    //
+    /// This SoundInfo is not valid until read() has been called.
+    SoundInfo()
+        :
+        loopCount(0),
+        inPoint(0),
+        outPoint(0)
+    {}
+
+    bool noMultiple;
+    bool hasEnvelope;
+    bool hasLoops;
+    bool hasOutPoint;
+    bool hasInPoint;
+
+       /// Number of loops started by an execution of this tag 
+       // 
+       /// This number is 0 if the sound must be played only once,
+       /// 1 to play twice and so on...
+       ///
+       /// It is not known whether a value exists to specify "loop forever"
+       ///
+       int     loopCount;
+
+       /// If true this tag actually *stops* the sound rather then playing it.
+       //
+       /// In a well-formed SWF when this flag is on all others should be off
+       /// (no loops, no envelopes, no in/out points).
+       ///
+       bool stopPlayback;
+
+       /// In/Out points, currently unsupported
+       //
+       /// See http://sswf.sourceforge.net/SWFalexref.html#swf_soundinfo
+    boost::uint32_t inPoint;
+    boost::uint32_t outPoint;
+
+       /// Sound effects (envelopes) for this start of the sound
+       //
+       /// See http://sswf.sourceforge.net/SWFalexref.html#swf_envelope
+       ///
+       sound::SoundEnvelopes envelopes;
+
+    void read(SWFStream& in);
+
+};
+
+}
+}
+
+#endif

=== modified file 'libcore/swf/StartSoundTag.cpp'
--- a/libcore/swf/StartSoundTag.cpp     2008-10-30 21:35:10 +0000
+++ b/libcore/swf/StartSoundTag.cpp     2008-11-07 12:55:48 +0000
@@ -23,17 +23,18 @@
 #include "log.h" // for log_parse
 #include "sound_definition.h" // for sound_sample
 #include "RunInfo.h"
+#include "SoundInfoRecord.h"
 #include "MovieClip.h"
 
 namespace gnash {
 namespace SWF {
 
-/* public static */
+
 void
 StartSoundTag::loader(SWFStream& in, tag_type tag, movie_definition& m,
         const RunInfo& r)
 {
-    assert(tag == SWF::STARTSOUND); // 15 
+    assert(tag == STARTSOUND); 
 
     sound::sound_handler* handler = r.soundHandler();
 
@@ -58,87 +59,26 @@
     // NOTE: sound_id is the SWF-defined id,
     //       sam->m_sound_handler_id is the sound_handler-provided id
     //
-    StartSoundTag*  sst = new StartSoundTag(sam->m_sound_handler_id);
-    sst->read(in);
+    in.align(); // necessary?
+    StartSoundTag* sst = new StartSoundTag(in, sam->m_sound_handler_id);
 
     IF_VERBOSE_PARSE (
-         log_parse(_("StartSound: id=%d, stop = %d, loop ct = %d"),
-              sound_id, int(sst->m_stop_playback), sst->m_loop_count);
+         log_parse(_("StartSound: id=%d"), sound_id);
     );
 
     m.addControlTag(sst); // takes ownership
 }
 
-/* private */
-void
-StartSoundTag::read(SWFStream& in)
-{
-    in.align();
-    in.ensureBytes(1); // header
-
-    int flags = in.read_u8();
-    // first two bits are reserved.
-    m_stop_playback     = flags & (1 << 5); 
-    bool  no_multiple   = flags & (1 << 4); 
-    bool  has_envelope  = flags & (1 << 3); 
-    bool  has_loops     = flags & (1 << 2); 
-    bool  has_out_point = flags & (1 << 1); 
-    bool  has_in_point  = flags & (1 << 0); 
-
-    if (no_multiple)
-    {
-        LOG_ONCE( log_unimpl("syncNoMultiple flag in StartSoundTag") );
-    }
-
-    boost::uint32_t in_point = 0;
-    boost::uint32_t out_point = 0;
-
-    if ( in_point ) log_unimpl(_("StartSoundTag with in point"));
-    if ( out_point ) log_unimpl(_("StartSoundTag with out point"));
-
-    in.ensureBytes(has_in_point*4 + has_out_point*4 + has_loops*2);
-
-    if (has_in_point)
-    {
-        in_point = in.read_u32();
-    }
-    if (has_out_point)
-    {
-        out_point = in.read_u32();
-    }
-    if (has_loops)
-    {
-        m_loop_count = in.read_u16();
-    }
-
-    if (has_envelope)
-    {
-        in.ensureBytes(1);
-        int nPoints = in.read_u8();
-
-        m_envelopes.resize(nPoints);
-        in.ensureBytes(8*nPoints);
-        for (int i=0; i < nPoints; i++)
-        {
-            m_envelopes[i].m_mark44 = in.read_u32();
-            m_envelopes[i].m_level0 = in.read_u16();
-            m_envelopes[i].m_level1 = in.read_u16();
-        }
-    }
-
-}
-
 void
 StartSoundTag::execute(MovieClip* m, DisplayList& /* dlist */) const
 {
-    //GNASH_REPORT_FUNCTION;
 
     sound::sound_handler* handler = 
         m->getVM().getRoot().runInfo().soundHandler();
 
     if (handler)
     {
-        if (m_stop_playback)
+        if (_soundInfo.stopPlayback)
         {
             //log_debug("Execute StartSoundTag with 'stop playback' flag on");
             handler->stop_sound(m_handler_id);
@@ -146,12 +86,31 @@
         else
         {
             //log_debug("Execute StartSoundTag with 'stop playback' flag OFF");
-            handler->play_sound(m_handler_id, m_loop_count, 0, 0,
-                    (m_envelopes.empty() ? NULL : &m_envelopes));
+            handler->play_sound(m_handler_id, _soundInfo.loopCount, 0, 0,
+                    (_soundInfo.envelopes.empty() ? NULL :
+                     &_soundInfo.envelopes));
         }
     }
 }
 
+void
+StartSound2Tag::loader(SWFStream& in, tag_type tag, movie_definition& /*m*/,
+        const RunInfo& /*r*/)
+{
+    assert(tag == STARTSOUND2);
+
+    std::string className;
+    in.read_string(className);
+    log_unimpl(_("STARTSOUND2 tag not parsed and not used"));
+
+    // We should probably then use StartSoundTag to parse the
+    // tag, but we don't know which sound_handler_id to use.
+
+    IF_VERBOSE_PARSE(
+        log_parse("StartSound2 tag: SoundClassName %s", className);
+    );
+}
+
 
 } // namespace gnash::SWF
 } // namespace gnash

=== modified file 'libcore/swf/StartSoundTag.h'
--- a/libcore/swf/StartSoundTag.h       2008-10-31 14:18:51 +0000
+++ b/libcore/swf/StartSoundTag.h       2008-11-07 12:47:31 +0000
@@ -26,6 +26,7 @@
 #include "sound_handler.h" // for sound_envelope (composition)
 #include "VM.h" // We only need this to get movie_root
 #include "swf.h" // for tag_type definition
+#include "SoundInfoRecord.h"
 
 #include <vector> // for composition
 #include <boost/cstdint.hpp> // for boost::uint16_t and friends
@@ -58,64 +59,46 @@
        ///
        boost::uint16_t m_handler_id;
 
-       /// Number of loops started by an execution of this tag 
-       // 
-       /// This number is 0 if the sound must be played only once,
-       /// 1 to play twice and so on...
-       ///
-       /// It is not known whether a value exists to specify "loop forever"
-       ///
-       int     m_loop_count;
-
-       /// If true this tag actually *stops* the sound rather then playing it.
-       //
-       /// In a well-formed SWF when this flag is on all others should be off
-       /// (no loops, no envelopes, no in/out points).
-       ///
-       bool    m_stop_playback;
-
-       /// In/Out points, currently unsupported
-       //
-       /// See http://sswf.sourceforge.net/SWFalexref.html#swf_soundinfo
-       // unsigned long m_in_point;
-       // unsigned long m_out_point;
-
-       /// Sound effects (envelopes) for this start of the sound
-       //
-       /// See http://sswf.sourceforge.net/SWFalexref.html#swf_envelope
-       ///
-       sound::SoundEnvelopes m_envelopes;
-
-       /// Initialize this StartSoundTag from the SWFStream  
+       /// Create a StartSoundTag for starting the given sound sample
        //
        /// The stream is assumed to be positioned right after the
        /// sound_id field of the tag structure.
        ///
-       void read(SWFStream& in);
-
-
-       /// Create a StartSoundTag for starting the given sound sample
-       //
+    /// @param in   The SWFStream to initialize the tag from.
        /// @param sound_handler_id
        /// Sound sample identifier as provided by sound_handler (sic!)
        ///
-       StartSoundTag(int sound_id)
+       StartSoundTag(SWFStream& in, int sound_id)
                :
-               m_handler_id(sound_id),
-               m_loop_count(0),
-               m_stop_playback(false)
+               m_handler_id(sound_id)
        {
+        _soundInfo.read(in);
        }
 
+    SoundInfo _soundInfo;
+
 public:
 
-       void    execute(MovieClip* /* m */, DisplayList& /* dlist */) const;
+       void execute(MovieClip* /* m */, DisplayList& /* dlist */) const;
 
        /// Load a SWF::STARTSOUND tag.
-       static void loader(SWFStream& in, tag_type tag, movie_definition& m, 
const RunInfo& r);
-
-};
-
+       static void loader(SWFStream& in, tag_type tag, movie_definition& m,
+            const RunInfo& r);
+
+};
+
+/// StartSound2Tag (SWF9)
+//
+/// Very similar to StartSoundTag, but uses a SoundClassName instead of
+/// character ID. This is not implemented.
+class StartSound2Tag
+{
+public:
+
+       /// Load a SWF::STARTSOUND2 tag.
+       static void loader(SWFStream& in, tag_type tag, movie_definition& m,
+            const RunInfo& r);
+};
 
 } // namespace gnash::SWF
 } // namespace gnash

=== modified file 'libcore/swf/tag_loaders.cpp'
--- a/libcore/swf/tag_loaders.cpp       2008-11-06 22:57:43 +0000
+++ b/libcore/swf/tag_loaders.cpp       2008-11-07 10:57:43 +0000
@@ -944,37 +944,6 @@
 
 // end_tag doesn't actually need to exist.
 
-void button_sound_loader(SWFStream& in, tag_type tag, movie_definition& m,
-               const RunInfo& /*r*/)
-{
-    assert(tag == SWF::DEFINEBUTTONSOUND); // 17
-
-    in.ensureBytes(2);
-    int    button_character_id = in.read_u16();
-    character_def* chdef = m.get_character_def(button_character_id);
-    if ( ! chdef )
-    {
-        IF_VERBOSE_MALFORMED_SWF(
-        log_swferror(_("DEFINEBUTTONSOUND refers to an unknown character def 
%d"), button_character_id);
-        );
-        return;
-    }
-
-    button_character_definition* ch = 
dynamic_cast<button_character_definition*> (chdef);
-    if ( ! ch )
-    {
-        IF_VERBOSE_MALFORMED_SWF(
-        log_swferror(_("DEFINEBUTTONSOUND refers to character id %d, "
-            "being a %s (expected a button definition)"),
-            button_character_id,
-            typeName(*chdef));
-        );
-        return;
-    }
-
-    ch->read(in, tag, m);
-}
-
 
 void button_character_loader(SWFStream& in, tag_type tag, movie_definition& m,
                const RunInfo& /*r*/)

=== modified file 'libcore/swf/tag_loaders.h'
--- a/libcore/swf/tag_loaders.h 2008-11-06 11:56:50 +0000
+++ b/libcore/swf/tag_loaders.h 2008-11-07 10:57:43 +0000
@@ -140,9 +140,6 @@
 void define_sound_loader(SWFStream&, tag_type, movie_definition&,
                const RunInfo&);
 
-void button_sound_loader(SWFStream&, tag_type, movie_definition&,
-               const RunInfo&);
-
 void do_init_action_loader(SWFStream&, tag_type, movie_definition&,
                const RunInfo&);
 


reply via email to

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