gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11048: Made sound_handler interface


From: Sandro Santilli
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11048: Made sound_handler interface more aware of the SWF model (fist pass)
Date: Tue, 09 Jun 2009 16:04:51 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11048
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Tue 2009-06-09 16:04:51 +0200
message:
  Made sound_handler interface more aware of the SWF model (fist pass)
modified:
  libcore/Button.cpp
  libcore/asobj/Sound_as.cpp
  libcore/swf/StartSoundTag.cpp
  libcore/swf/StreamSoundBlockTag.cpp
  libcore/swf/StreamSoundBlockTag.h
  libsound/EmbedSoundInst.cpp
  libsound/EmbedSoundInst.h
  libsound/sdl/sound_handler_sdl.cpp
  libsound/sdl/sound_handler_sdl.h
  libsound/sound_handler.cpp
  libsound/sound_handler.h
=== modified file 'libcore/Button.cpp'
--- a/libcore/Button.cpp        2009-06-03 11:12:12 +0000
+++ b/libcore/Button.cpp        2009-06-09 14:04:51 +0000
@@ -551,10 +551,9 @@
             const sound::SoundEnvelopes* env = 
                 sinfo.envelopes.empty() ? 0 : &sinfo.envelopes;
 
-            s->playSound(bs.sample->m_sound_handler_id,
+            s->startSound(bs.sample->m_sound_handler_id,
                     bs.soundInfo.loopCount,
                     0, // secs offset
-                    0, // byte offset
                     env, // envelopes
                     !sinfo.noMultiple // allow multiple instances ?
                     );

=== modified file 'libcore/asobj/Sound_as.cpp'
--- a/libcore/asobj/Sound_as.cpp        2009-06-03 16:05:40 +0000
+++ b/libcore/asobj/Sound_as.cpp        2009-06-09 14:04:51 +0000
@@ -367,13 +367,12 @@
     }
     else
     {
-        _soundHandler->playSound(
+        _soundHandler->startSound(
                     soundId,
                     loops,
                     offset, // in seconds
-                    0, // start position in bytes...
                     0, // envelopes
-                    true // allow multiple instances (TODO: checkme)
+                    true // allow multiple instances (checked)
                     );
     }
 }

=== modified file 'libcore/swf/StartSoundTag.cpp'
--- a/libcore/swf/StartSoundTag.cpp     2009-06-06 22:58:34 +0000
+++ b/libcore/swf/StartSoundTag.cpp     2009-06-09 14:04:51 +0000
@@ -92,10 +92,9 @@
             const sound::SoundEnvelopes* env = 
                 _soundInfo.envelopes.empty() ? 0 : &_soundInfo.envelopes;
 
-            handler->playSound(m_handler_id,
+            handler->startSound(m_handler_id,
                     _soundInfo.loopCount,
                     0, // secs offset
-                    0, // byte offset
                     env, // envelopes
                     !_soundInfo.noMultiple // allow multiple instances ?
                     );

=== modified file 'libcore/swf/StreamSoundBlockTag.cpp'
--- a/libcore/swf/StreamSoundBlockTag.cpp       2009-06-03 16:05:40 +0000
+++ b/libcore/swf/StreamSoundBlockTag.cpp       2009-06-09 14:04:51 +0000
@@ -42,13 +42,7 @@
                // This makes it possible to stop only the stream when 
framejumping.
                m->setStreamSoundId(m_handler_id);
 
-               handler->playSound(m_handler_id,
-                0, // no looping
-                0, // no seconds offset (MP3 seek samples might use this ?)
-                m_start, // offset to this block of sound
-                0, // no envelopes
-                false // don't allow multiple instances of the same sound
-                );
+               handler->playStream(m_handler_id, _blockId);
        }
 }
 
@@ -69,11 +63,11 @@
     }
 
     // Get the ID of the sound stream currently being loaded
-    int handle_id = m.get_loading_sound_stream_id();
+    int streamId = m.get_loading_sound_stream_id();
 
     // Get the SoundInfo object that contains info about the sound stream.
     // Ownership of the object is in the soundhandler
-    media::SoundInfo* sinfo = handler->get_sound_info(handle_id);
+    media::SoundInfo* sinfo = handler->get_sound_info(streamId);
 
     // If there is no SoundInfo something is wrong...
     if (!sinfo)
@@ -86,7 +80,7 @@
     }
 
     media::audioCodecType format = sinfo->getFormat();
-    unsigned int sample_count = sinfo->getSampleCount();
+    unsigned int sampleCount = sinfo->getSampleCount();
 
     // MP3 format blocks have additional info
     if (format == media::AUDIO_CODEC_MP3)
@@ -122,12 +116,12 @@
     //
     // ownership of 'data' is transferred here
     //
-    long start = handler->fill_stream_data(data, dataLength, sample_count,
-            handle_id);
+    sound::sound_handler::StreamBlockId blockId =
+        handler->addSoundBlock(data, dataLength, sampleCount, streamId);
 
     // TODO: log_parse ?
 
-    StreamSoundBlockTag* ssst = new StreamSoundBlockTag(handle_id, start);
+    StreamSoundBlockTag* ssst = new StreamSoundBlockTag(streamId, blockId);
     m.addControlTag(ssst); // ownership is transferred to movie_definition
 }
 

=== modified file 'libcore/swf/StreamSoundBlockTag.h'
--- a/libcore/swf/StreamSoundBlockTag.h 2009-02-20 12:24:00 +0000
+++ b/libcore/swf/StreamSoundBlockTag.h 2009-06-09 14:04:51 +0000
@@ -24,6 +24,7 @@
 
 #include "ControlTag.h" // for inheritance
 #include "swf.h" // for TagType definition
+#include "sound_handler.h" // for StreamBlockId identifier
 
 #include <boost/cstdint.hpp> // for boost::uint16_t and friends
  
@@ -57,12 +58,19 @@
        boost::uint16_t m_handler_id;
 
        /// Offset in the stream buffer to play
-       long            m_start;
+       sound::sound_handler::StreamBlockId _blockId;
 
        //int           latency;
 
 public:
 
+    /// Get the identifier of the sound stream this block belongs to
+    //
+    /// TODO: why is this an uint16_t if sound_handler::create_sound
+    ///       returns an int ? I vote for a sound_handler::SoundId typedef
+    ///
+    boost::uint16_t getStreamId() const { return m_handler_id; }
+
        /// Start the associated block of sound
        void execute(MovieClip* m, DisplayList& dlist) const;
 
@@ -70,25 +78,25 @@
        static void loader(SWFStream& in, TagType tag, movie_definition& m,
             const RunInfo& r);
 
-       /// Not a "state" (DisplayList?) tag, do doesn't need to provide
-    ///  execute_state
+       /// Not a "state" (DisplayList?) tag, so doesn't need to provide
+    /// execute_state
 
 private:
 
        /// Create a ControlTag playing the given sample when executed.
        //
-       /// @param handlerId
+       /// @param streamId
        ///     Identifier of the stream to play.
        ///
-       /// @param start
-       ///     Offset to start playback from.
-       ///     (Should be offset of the associated sound block).
+       /// @param blockId
+       ///     Identifier of the stream block to play.
        ///
     /// This should only be constructed using the loader() function.
-       StreamSoundBlockTag(int handlerId, long start)
+       StreamSoundBlockTag(int streamId,
+                           sound::sound_handler::StreamBlockId blockId)
                :
-               m_handler_id(handlerId),
-               m_start(start)
+               m_handler_id(streamId),
+               _blockId(blockId)
        {}
 };
 

=== modified file 'libsound/EmbedSoundInst.cpp'
--- a/libsound/EmbedSoundInst.cpp       2009-06-08 01:21:36 +0000
+++ b/libsound/EmbedSoundInst.cpp       2009-06-09 14:04:51 +0000
@@ -51,7 +51,8 @@
 
 EmbedSoundInst::EmbedSoundInst(EmbedSound& soundData,
             media::MediaHandler& mediaHandler,
-            unsigned long blockOffset, unsigned int secsOffset,
+            sound_handler::StreamBlockId blockOffset,
+            unsigned int secsOffset,
             const SoundEnvelopes* env,
             unsigned int loopCount)
         :

=== modified file 'libsound/EmbedSoundInst.h'
--- a/libsound/EmbedSoundInst.h 2009-06-08 01:21:36 +0000
+++ b/libsound/EmbedSoundInst.h 2009-06-09 14:04:51 +0000
@@ -24,6 +24,7 @@
 #include "SoundEnvelope.h" // for SoundEnvelopes typedef
 #include "SimpleBuffer.h" // for composition (decoded data)
 #include "EmbedSound.h" // for inlines
+#include "sound_handler.h" // for StreamBlockId typedef
 
 #include <memory>
 #include <cassert>
@@ -63,12 +64,9 @@
     /// @param mh
     ///     The MediaHandler to use for on-demand decoding
     ///
-    /// @param blockOffset
-    ///     Byte offset in the immutable (encoded) data this
-    ///     instance should start decoding.
-    ///     This is currently used for streaming embedded sounds
-    ///     to refer to a specific StreamSoundBlock.
-    ///     @see gnash::swf::StreamSoundBlockTag
+    /// @param blockId
+    ///     Identifier of the encoded block to start decoding from.
+    ///     @see gnash::swf::StreamBlockIdTag
     ///
     /// @param secsOffset
     ///     Offset, in seconds, this instance should start playing
@@ -83,8 +81,8 @@
     ///     @todo document if every loop starts at secsOffset !
     ///
     EmbedSoundInst(EmbedSound& def, media::MediaHandler& mh,
-            unsigned long blockOffset, unsigned int secsOffset,
-            const SoundEnvelopes* envelopes,
+            sound_handler::StreamBlockId blockId,
+            unsigned int secsOffset, const SoundEnvelopes* envelopes,
             unsigned int loopCount);
 
     // See dox in sound_handler.h (InputStream)

=== modified file 'libsound/sdl/sound_handler_sdl.cpp'
--- a/libsound/sdl/sound_handler_sdl.cpp        2009-06-07 00:17:31 +0000
+++ b/libsound/sdl/sound_handler_sdl.cpp        2009-06-09 14:04:51 +0000
@@ -194,15 +194,14 @@
     return sound_handler::create_sound(data, sinfo);
 }
 
-// This gets called when an SWF embedded sound stream gets more data
-long
-SDL_sound_handler::fill_stream_data(unsigned char* data,
+sound_handler::StreamBlockId
+SDL_sound_handler::addSoundBlock(unsigned char* data,
         unsigned int dataBytes, unsigned int nSamples,
-        int handleId)
+        int streamId)
 {
 
     boost::mutex::scoped_lock lock(_mutex);
-    return sound_handler::fill_stream_data(data, dataBytes, nSamples, 
handleId);
+    return sound_handler::addSoundBlock(data, dataBytes, nSamples, streamId);
 }
 
 

=== modified file 'libsound/sdl/sound_handler_sdl.h'
--- a/libsound/sdl/sound_handler_sdl.h  2009-06-06 23:29:42 +0000
+++ b/libsound/sdl/sound_handler_sdl.h  2009-06-09 14:04:51 +0000
@@ -107,9 +107,12 @@
     // See dox in sound_handler.h
     virtual int create_sound(std::auto_ptr<SimpleBuffer> data, 
std::auto_ptr<media::SoundInfo> sinfo);
 
-    // see dox in sound_handler.h
-    virtual long    fill_stream_data(unsigned char* data, unsigned int 
data_bytes,
-                     unsigned int sample_count, int handle_id);
+    // See dox in sound_handler.h
+    // overridden to serialize access to the data buffer slot
+    virtual StreamBlockId addSoundBlock(unsigned char* data,
+                                       unsigned int data_bytes,
+                                       unsigned int sample_count,
+                                       int streamId);
 
     // See dox in sound_handler.h
     virtual void    stop_sound(int sound_handle);

=== modified file 'libsound/sound_handler.cpp'
--- a/libsound/sound_handler.cpp        2009-06-09 10:30:46 +0000
+++ b/libsound/sound_handler.cpp        2009-06-09 14:04:51 +0000
@@ -38,8 +38,8 @@
 namespace gnash {
 namespace sound {
 
-long
-sound_handler::fill_stream_data(unsigned char* data,
+sound_handler::StreamBlockId
+sound_handler::addSoundBlock(unsigned char* data,
         unsigned int data_bytes, unsigned int /*sample_count*/,
         int handleId)
 {
@@ -334,7 +334,7 @@
 
 void
 sound_handler::playSound(int sound_handle, int loopCount, int offSecs,
-                            long start_position,
+                            StreamBlockId blockId,
                             const SoundEnvelopes* envelopes,
                             bool allowMultiples)
 {
@@ -347,14 +347,6 @@
     }
 
     // parameter checking
-    if (start_position < 0)
-    {
-        log_error("Negative (%d) start_position passed to playSound, "
-                  "taking as zero ", start_position);
-        start_position=0;
-    }
-
-    // parameter checking
     if (offSecs < 0)
     {
         log_error("Negative (%d) seconds offset passed to playSound, "
@@ -409,9 +401,8 @@
             // MediaHandler to use for decoding
             *_mediaHandler,
 
-            // Byte offset position to start decoding from
-            // (would be offset to streaming sound block)
-            start_position, // or blockOffset
+            // Sound block identifier
+            blockId, 
 
             // Seconds offset
             // WARNING: this is wrong, offset is passed as seconds !!
@@ -429,6 +420,22 @@
     plugInputStream(sound);
 }
 
+/*public*/
+void
+sound_handler::playStream(int soundId, StreamBlockId blockId)
+{
+    playSound(soundId, 0, 0, blockId, 0, false);
+}
+
+/*public*/
+void
+sound_handler::startSound(int soundId, int loops, int secsOffset,
+                      const SoundEnvelopes* env,
+                      bool allowMultiple)
+{
+    playSound(soundId, loops, secsOffset, 0, env, allowMultiple);
+}
+
 void
 sound_handler::plugInputStream(std::auto_ptr<InputStream> newStreamer)
 {

=== modified file 'libsound/sound_handler.h'
--- a/libsound/sound_handler.h  2009-06-06 23:29:42 +0000
+++ b/libsound/sound_handler.h  2009-06-09 14:04:51 +0000
@@ -82,6 +82,12 @@
 {
 public:
 
+    /// Identifier of a streaming sound block
+    //
+    /// Use coupled with a soundId for fully qualified identifier
+    ///
+    typedef unsigned long StreamBlockId;
+
        /// Create a sound buffer slot, for on-demand playback.
        //
        /// @param data
@@ -119,14 +125,17 @@
        /// @param sampleCount
        ///     Number of samples in the data
        ///
-       /// @param handleId
-       ///     The soundhandlers id of the sound we want some info about.
-       ///
-       /// @return size of the data buffer before the new data is appended, or 
-1
-       ///         on error.
-       ///
-       virtual long fill_stream_data(unsigned char* data, unsigned int 
dataBytes,
-                                  unsigned int sampleCount, int handleId);
+       /// @param streamId
+       ///     The soundhandlers id of the sound we want to add data to
+       ///
+       /// @return an identifier for the new block for use in playSound
+       ///
+       /// @throw SoundException on error
+       ///
+       virtual StreamBlockId addSoundBlock(unsigned char* data,
+                                          unsigned int dataBytes,
+                                          unsigned int sampleCount,
+                                          int streamId);
 
        /// Returns a pointer to the SoundInfo object for the sound with the 
given id.
     //
@@ -139,7 +148,7 @@
        ///
        virtual media::SoundInfo* get_sound_info(int soundHandle);
 
-       /// Schedule playing of a sound buffer slot
+       /// Start playback of an event sound
        //
        /// All scheduled sounds will be played on next output flush.
        ///
@@ -150,31 +159,38 @@
        ///     loops == 0 means play the sound once (1 means play it twice, 
etc)
        ///
        /// @param secsOffset
-       ///     When starting event sounds there sometimes is a offset to make 
the sound
-       ///     start at the exact right moment. Gnash supports this troough 
'Sound' AS
-       ///     class only, not from the actual control tag (StartSound). Units 
given in 
-    ///     seconds.
-       ///
-       /// @param start
-       ///     When starting a soundstream from a random frame, this tells 
where in the
-       ///     data the decoding should start, in bytes.
-       ///     If non-zero, the sound will only start when no other instances 
of it
-       ///     are already playing.
-       ///     @todo use unsigned
+       ///     When starting event sounds there sometimes is a offset to make
+       ///             the sound start at the exact right moment. Gnash 
supports this
+       ///             through 'Sound' AS class only, not from the actual 
control tag
+       ///             (StartSound). Units given in seconds.
        ///
        /// @param env
-       ///     Some eventsounds have some volume control mechanism called 
envelopes.
+       ///     Some eventsounds have some volume control mechanism called
+    ///     envelopes.
        ///     They basically tells that from sample X the volume should be Y.
     ///
        /// @param allowMultiple
        ///     If false, the sound will not be scheduled if there's another
     ///     instance of it already playing.
        ///
-       /// TODO: add out_point parameter (when to stop playing the sound)
-       ///
-       virtual void playSound(int id, int loops, int secsOffset,
-                                       long start, const SoundEnvelopes* env,
-                    bool allowMultiple);
+       /// TODO: add inPoint and outPoint parameters
+    ///       (pre-resampling samples offset of start and end)
+       ///       or take SWF::SoundInfoRecord& directly !
+       void startSound(int id, int loops, int secsOffset,
+                      const SoundEnvelopes* env,
+                      bool allowMultiple);
+
+       /// Start playback of a streaming sound, if not playing already
+       //
+       ///
+       /// @param streamId
+       ///     Id of the sound buffer slot schedule playback of.
+       ///     It is assumed to refer to a straming sound
+       ///
+       /// @param blockId
+       ///     Identifier of the block to start decoding from.
+       ///
+       void playStream(int id, StreamBlockId blockId);
 
        /// Remove all scheduled request for playback of sound buffer slots
        virtual void    stop_all_sounds();
@@ -469,6 +485,43 @@
     /// Unplug any completed input stream
     void unplugCompletedInputStreams();
 
+       /// Schedule playing of a sound buffer slot
+       //
+       /// All scheduled sounds will be played on next output flush.
+       ///
+       /// @param id
+       ///     Id of the sound buffer slot schedule playback of.
+       ///
+       /// @param loops
+       ///     loops == 0 means play the sound once (1 means play it twice, 
etc)
+       ///
+       /// @param secsOffset
+       ///     When starting event sounds there sometimes is a offset to make
+       ///             the sound start at the exact right moment. Gnash 
supports this
+       ///             through 'Sound' AS class only, not from the actual 
control tag
+       ///             (StartSound). Units given in seconds.
+       ///
+       /// @param blockId
+       ///     When starting a soundstream from a random frame, this tells 
which
+       ///     block to start decoding from.
+       ///     If non-zero, the sound will only start when no other instances 
of it
+       ///     are already playing.
+       ///
+       /// @param env
+       ///     Some eventsounds have some volume control mechanism called
+    ///     envelopes.
+       ///     They basically tells that from sample X the volume should be Y.
+    ///
+       /// @param allowMultiple
+       ///     If false, the sound will not be scheduled if there's another
+    ///     instance of it already playing.
+       ///
+       /// TODO: add out_point parameter (when to stop playing the sound)
+       ///
+       void playSound(int id, int loops, int secsOffset,
+                      StreamBlockId blockId, const SoundEnvelopes* env,
+                      bool allowMultiple);
+
 };
 
 // TODO: move to appropriate specific sound handlers


reply via email to

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