gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog backend/Makefile.am backend/sou...


From: Tomas Groth
Subject: [Gnash-commit] gnash ChangeLog backend/Makefile.am backend/sou...
Date: Fri, 17 Nov 2006 19:24:57 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Tomas Groth <tgc>       06/11/17 19:24:57

Modified files:
        .              : ChangeLog 
        backend        : Makefile.am sound_handler_gst.cpp 
                         sound_handler_sdl.cpp 
Added files:
        backend        : sound_handler_gst.h 

Log message:
        * backend/Makefile.am, backend/sound_handler_gst.{cpp,h}: Split
          the gstreamer backend into a .cpp-file and a .h-file. Also 
          applied Hiroyuki Ikezoe patches, and did a bit of cleanup.
        * backend/sound_handler_sdl.cpp: More cleanups.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1657&r2=1.1658
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/Makefile.am?cvsroot=gnash&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.cpp?cvsroot=gnash&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.cpp?cvsroot=gnash&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.h?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1657
retrieving revision 1.1658
diff -u -b -r1.1657 -r1.1658
--- ChangeLog   17 Nov 2006 19:05:35 -0000      1.1657
+++ ChangeLog   17 Nov 2006 19:24:57 -0000      1.1658
@@ -1,3 +1,10 @@
+2006-11-17 Tomas Groth Christensen <address@hidden>
+
+       * backend/Makefile.am, backend/sound_handler_gst.{cpp,h}: Split
+         the gstreamer backend into a .cpp-file and a .h-file. Also 
+         applied Hiroyuki Ikezoe patches, and did a bit of cleanup.
+       * backend/sound_handler_sdl.cpp: More cleanups.
+
 2006-11-17 Sandro Santilli <address@hidden>
 
        * server/asobj/gen-asclass.sh: typo fixed.

Index: backend/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/backend/Makefile.am,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- backend/Makefile.am 11 Nov 2006 12:32:08 -0000      1.46
+++ backend/Makefile.am 17 Nov 2006 19:24:57 -0000      1.47
@@ -78,7 +78,7 @@
 endif
 
 if USE_SOUND_GST
-SOUND_SOURCES = sound_handler_gst.cpp 
+SOUND_SOURCES = sound_handler_gst.cpp sound_handler_gst.h 
 AM_LDFLAGS += $(GSTREAMER_LIBS) 
 AM_LDFLAGS += $(LIBXML_LIBS) 
 INCLUDES += $(GSTREAMER_CFLAGS)

Index: backend/sound_handler_gst.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- backend/sound_handler_gst.cpp       8 Nov 2006 21:57:04 -0000       1.29
+++ backend/sound_handler_gst.cpp       17 Nov 2006 19:24:57 -0000      1.30
@@ -18,7 +18,7 @@
 // Based on sound_handler_sdl.cpp by Thatcher Ulrich http://tulrich.com 2003
 // which has been donated to the Public Domain.
 
-/* $Id: sound_handler_gst.cpp,v 1.29 2006/11/08 21:57:04 nihilus Exp $ */
+/* $Id: sound_handler_gst.cpp,v 1.30 2006/11/17 19:24:57 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -30,6 +30,7 @@
 //
 
 #ifdef SOUND_GST
+#include "sound_handler_gst.h"
 #include "gnash.h"
 #include "container.h"
 #include "log.h"
@@ -42,158 +43,34 @@
 
 #define BUFFER_SIZE 5000
 
-// Used to hold the gstreamer when doing on-demand-decoding
-typedef struct
-{
-       // gstreamer objects
-       GstElement *input;
-       GstElement *decoder;
-       GstElement *capsfilter;
-       GstElement *audioconvert;
-       GstElement *audioresample;
-       GstElement *volume;
-       GstElement *bin;
-       GstPad     *addersinkpad;
-       
-       // position in the stream
-       long position;
-
-       // The (un)compressed data
-       guint8* data;
-
-       // data size
-       long data_size;
-
-       long loop_count;
-       
-       // signal id
-       guint handoff_signal_id;
-
-} gst_elements;
-
-
-// Used to hold the sounddata when doing on-demand-decoding
-typedef struct
-{
-       // The (un)compressed data
-       guint8* data;
-
-       // data format
-       int format;
-
-       // data size
-       long data_size;
-
-       // stereo or not
-       bool stereo;
-
-       // number of samples
-       int sample_count;
-
-       // sample rate
-       int sample_rate;
-
-       // Volume, SWF range: 0-100, GST range 0-10 (we only use 0-1, the rest 
is amplified)
-       // It's the SWF range that is represented here
-       int volume;
-
-       // gstreamer objects
-       std::vector<gst_elements*>      m_gst_elements;
-
-} sound_data;
-
-// Use gstreamer to handle sounds.
-class GST_sound_handler : public gnash::sound_handler
-{
-public:
-       // gstreamer pipeline objects
-
-       // the main bin containing the adder and output (sink)
-       GstElement *pipeline;
-
-       GstElement *adder;
-       GstElement *audiosink;
-
-       // Sound data.
-       std::vector<sound_data*>        m_sound_data;
-
-       // Keeps track of numbers of playing sounds
-       int soundsPlaying;
-       
-       // Is the loop running?
-       bool looping;
-       
-       // Is the audio muted?
-       bool muted;
-
-       GST_sound_handler()
-               : soundsPlaying(0),
-                 looping(false),
+GST_sound_handler::GST_sound_handler()
+       : looping(false),
                  muted(false)
-       {
+{
                // init gstreamer
                gst_init(NULL, NULL);
+}
 
-               // create main pipeline
-               pipeline = gst_pipeline_new (NULL);
-
-               // create adder
-               adder = gst_element_factory_make ("adder", NULL);
-
-               // create an audio sink - use oss, alsa or...? make a 
commandline option?
-               // we first try atudetect, then alsa, then oss, then esd, 
then...?
-               audiosink = gst_element_factory_make ("autoaudiosink", NULL);
-               if (!audiosink) audiosink = gst_element_factory_make 
("alsasink", NULL);
-               if (!audiosink) audiosink = gst_element_factory_make 
("osssink", NULL);
-               if (!audiosink) audiosink = gst_element_factory_make 
("esdsink", NULL);
-
-               // Check if the creation of the gstreamer pipeline, adder and 
audiosink was a succes
-               if (!pipeline) {
-                       gnash::log_error("The gstreamer pipeline element could 
not be created\n");
-               }
-               if (!adder) {
-                       gnash::log_error("The gstreamer adder element could not 
be created\n");
-               }
-               if (!audiosink) {
-                       gnash::log_error("The gstreamer audiosink element could 
not be created\n");
-               }
-
-               // link adder and output to bin
-               gst_bin_add (GST_BIN (pipeline), adder);
-               gst_bin_add (GST_BIN (pipeline), audiosink);
-
-               // link adder and audiosink
-               GstPad *srcpad = gst_element_get_pad (adder, "src");
-               GstPad *sinkpad = gst_element_get_pad (audiosink, "sink");
-               gst_pad_link (srcpad, sinkpad);
-               gst_object_unref (GST_OBJECT (srcpad));
-               gst_object_unref (GST_OBJECT (sinkpad));
-               
-       }
-
-       ~GST_sound_handler()
-       {
+GST_sound_handler::~GST_sound_handler()
+{
 
                for (size_t i=0, e=m_sound_data.size(); i < e; ++i)  {
                        stop_sound(i);
                        delete_sound(i);
                }
-
-               gst_object_unref (GST_OBJECT (pipeline));
-
-       }
+}
 
 
-       virtual int     create_sound(
+int    GST_sound_handler::create_sound(
                void* data,
                int data_bytes,
                int sample_count,
                format_type format,
                int sample_rate,
                bool stereo)
-       // Called to create a sample.  We'll return a sample ID that
-       // can be use for playing it.
-       {
+// Called to create a sample.  We'll return a sample ID that
+// can be use for playing it.
+{
 
                sound_data *sounddata = new sound_data;
                if (!sounddata) {
@@ -264,42 +141,44 @@
                m_sound_data.push_back(sounddata);
 
                return m_sound_data.size()-1;
-       }
+}
 
 
-       // this gets called when a stream gets more data
-       virtual long    fill_stream_data(void* data, int data_bytes, int 
/*sample_count*/, int handle_id)
-       {
+// this gets called when a stream gets more data
+long   GST_sound_handler::fill_stream_data(void* data, int data_bytes, int 
/*sample_count*/, int handle_id)
+{
                
                // @@ does a negative handle_id have any meaning ?
                //    should we change it to unsigned instead ?
                if (handle_id >= 0 && (unsigned int) handle_id < 
m_sound_data.size())
                {       
+               sound_data* sounddata = m_sound_data[handle_id];
+
                        // Reallocate the required memory.
-                       guint8* tmp_data = new guint8[data_bytes + 
m_sound_data[handle_id]->data_size];
-                       memcpy(tmp_data, m_sound_data[handle_id]->data, 
m_sound_data[handle_id]->data_size);
-                       memcpy(tmp_data + m_sound_data[handle_id]->data_size, 
data, data_bytes);
-                       delete [] m_sound_data[handle_id]->data;
-                       m_sound_data[handle_id]->data = tmp_data;
+               guint8* tmp_data = new guint8[data_bytes + 
sounddata->data_size];
+               memcpy(tmp_data, sounddata->data, sounddata->data_size);
+               memcpy(tmp_data + sounddata->data_size, data, data_bytes);
+               delete [] sounddata->data;
+               sounddata->data = tmp_data;
                        
-                       m_sound_data[handle_id]->data_size += data_bytes;
+               sounddata->data_size += data_bytes;
 
-                       for (size_t i=0, 
e=m_sound_data[handle_id]->m_gst_elements.size(); i < e; ++i) {
-                               
m_sound_data[handle_id]->m_gst_elements[i]->data_size = 
m_sound_data[handle_id]->data_size;
-                               
m_sound_data[handle_id]->m_gst_elements[i]->data = 
m_sound_data[handle_id]->data;
+               for (size_t i=0, e=sounddata->m_gst_elements.size(); i < e; 
++i) {
+                       gst_elements* sound = sounddata->m_gst_elements[i];
+                       sound->data_size = sounddata->data_size;
+                       sound->data = sounddata->data;
                        }
 
-                       return m_sound_data[handle_id]->data_size - data_bytes;
+               return sounddata->data_size - data_bytes;
                }
                return 0;
-       }
-
-
+}
 
-       // The callback function which refills the buffer with data
-       static void callback_handoff (GstElement * /*c*/, GstBuffer *buffer, 
GstPad* /*pad*/, gpointer user_data)
-       {
+// The callback function which refills the buffer with data
+static void callback_handoff (GstElement * /*c*/, GstBuffer *buffer, GstPad* 
/*pad*/, gpointer user_data)
+{
                gst_elements *gstelements = 
static_cast<gst_elements*>(user_data);
+       guint8* data_pos = gstelements->data+gstelements->position;
 
                // First callback
                if (GST_BUFFER_SIZE(buffer) == 0) {
@@ -324,22 +203,23 @@
 
                // Last callback - the last re-fill
                if (gstelements->position+BUFFER_SIZE > gstelements->data_size) 
{
+       
+               unsigned int chunk_size = 
gstelements->data_size-gstelements->position;
                        // Check if we should loop. If loop_count is 0 we have 
we just
                        // played the sound for the last (and perhaps first) 
time.
                        // If loop_count is anything else we continue to loop.
                        if (gstelements->loop_count == 0) {
-                               GST_BUFFER_SIZE(buffer) = 
gstelements->data_size-gstelements->position;
-                               memcpy(GST_BUFFER_DATA(buffer), 
static_cast<guint8*>(gstelements->data+gstelements->position), 
gstelements->data_size-gstelements->position);
+                       GST_BUFFER_SIZE(buffer) = chunk_size;
+                       memcpy(GST_BUFFER_DATA(buffer), data_pos, chunk_size);
                                gstelements->position += BUFFER_SIZE;
 
                                gst_element_set_state (GST_ELEMENT 
(gstelements->input), GST_STATE_PAUSED);
 
                        } else {
                                // Copy what's left of the data, and then fill 
the rest with "new" data.
-                               //int chunck_size = 
(gstelements->data_size-gstelements->position);
-                               memcpy(GST_BUFFER_DATA(buffer), 
static_cast<guint8*>(gstelements->data+gstelements->position),  
(gstelements->data_size-gstelements->position));
-                               memcpy(GST_BUFFER_DATA(buffer) + 
(gstelements->data_size-gstelements->position), 
static_cast<guint8*>(gstelements->data), GST_BUFFER_SIZE(buffer)- 
(gstelements->data_size-gstelements->position));
-                               gstelements->position = 
GST_BUFFER_SIZE(buffer)- (gstelements->data_size-gstelements->position);
+                       memcpy(GST_BUFFER_DATA(buffer), data_pos,  chunk_size);
+                       memcpy(GST_BUFFER_DATA(buffer) + chunk_size, 
gstelements->data, GST_BUFFER_SIZE(buffer)- chunk_size);
+                       gstelements->position = GST_BUFFER_SIZE(buffer) - 
chunk_size;
                                gstelements->loop_count--;
 
                        }
@@ -349,37 +229,15 @@
                }
 
                // Standard re-fill
-               memcpy(GST_BUFFER_DATA(buffer), 
static_cast<guint8*>(gstelements->data+gstelements->position), BUFFER_SIZE);
+       memcpy(GST_BUFFER_DATA(buffer), data_pos, BUFFER_SIZE);
                gstelements->position += BUFFER_SIZE;
 
-       }
-
-
-       /*static void event_callback (GstPad*, GstMiniObject *o, gpointer 
user_data)
-       {
-
-               GstEvent *event = (GstEvent*) o;
-               if (GST_EVENT_TYPE (event) == GST_EVENT_EOS)
-               {
-                       // Find the instance of this sound which needs to be 
deleted
-                       sound_data *sounddata = (sound_data*) user_data;
-
-#if 0 // this loop does nothing, right ?
-                       for (size_t i=0, n=m_gst_elements.size(); i<n; ++i)
-                       {
-                               if (m_gst_elements.at(i)->position > 
m_gst_elements.at(i)->data_size)
-                       }
-#endif
-                       printf("EOS detected! :D\n");
-                       gst_object_unref (GST_OBJECT (
-               }
-
-       }*/
+}
 
 
-       virtual void    play_sound(int sound_handle, int loop_count, int 
/*offset*/, long start_position, std::vector<sound_envelope>* /*envelopes*/)
-       // Play the index'd sample.
-       {
+void   GST_sound_handler::play_sound(int sound_handle, int loop_count, int 
/*offset*/, long start_position, std::vector<sound_envelope>* /*envelopes*/)
+// Play the index'd sample.
+{
 
                // Check if the sound exists, or if audio is muted
                if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size() || muted)
@@ -388,10 +246,12 @@
                        return;
                }
                
+       sound_data* sounddata = m_sound_data[sound_handle];
+
                // If this is called from a streamsoundblocktag, we only start 
if this
                // sound isn't already playing. If a gst_element-struct is 
existing we
                // assume it is also playing.
-               if (start_position > 0 && 
m_sound_data[sound_handle]->m_gst_elements.size() > 0) {
+       if (start_position > 0 && sounddata->m_gst_elements.size() > 0) {
                        return;
                }
 
@@ -402,13 +262,36 @@
                        return;
                }
                // Copy data-info to the "gst_elements"
-               gst_element->data_size = m_sound_data[sound_handle]->data_size;
-               gst_element->data = m_sound_data[sound_handle]->data;
+       gst_element->data_size = sounddata->data_size;
+       gst_element->data = sounddata->data;
                gst_element->position = start_position;
 
                // Set number of loop we should do. -1 is infinte loop, 0 plays 
it once, 1 twice etc.
                gst_element->loop_count = loop_count;
 
+       // create main pipeline
+       gst_element->pipeline = gst_pipeline_new (NULL);
+
+       // create an audio sink - use oss, alsa or...? make a commandline 
option?
+       // we first try atudetect, then alsa, then oss, then esd, then...?
+#if !defined(__NetBSD__)
+       gst_element->audiosink = gst_element_factory_make ("autoaudiosink", 
NULL);
+       if (!gst_element->audiosink) gst_element->audiosink = 
gst_element_factory_make ("alsasink", NULL);
+       if (!gst_element->audiosink) gst_element->audiosink = 
gst_element_factory_make ("osssink", NULL);
+#endif
+       if (!gst_element->audiosink) gst_element->audiosink = 
gst_element_factory_make ("esdsink", NULL);
+
+       // Check if the creation of the gstreamer pipeline, adder and audiosink 
was a succes
+       if (!gst_element->pipeline) {
+               gnash::log_error("The gstreamer pipeline element could not be 
created\n");
+       }
+       if (!gst_element->audiosink) {
+               gnash::log_error("The gstreamer audiosink element could not be 
created\n");
+       }
+
+       // link adder and output to bin
+       gst_bin_add (GST_BIN (gst_element->pipeline), gst_element->audiosink);
+
                gst_element->bin = gst_bin_new(NULL);
                gst_element->input = gst_element_factory_make ("fakesrc", NULL);
                gst_element->capsfilter = gst_element_factory_make 
("capsfilter", NULL);
@@ -435,7 +318,7 @@
 
                // Create a gstreamer decoder for the chosen sound.
 
-               if (m_sound_data[sound_handle]->format == FORMAT_MP3) { // || 
sound_data[m_sound_handle]->format == FORMAT_VORBIS) {
+       if (sounddata->format == FORMAT_MP3) { // || sounddata->format == 
FORMAT_VORBIS) {
 
                        gst_element->decoder = gst_element_factory_make ("mad", 
NULL);
                        if (gst_element->decoder == NULL) gst_element->decoder 
= gst_element_factory_make ("ffdec_mp3", NULL);
@@ -452,13 +335,13 @@
                        GstCaps *caps = gst_caps_new_simple ("audio/mpeg",
                                "mpegversion", G_TYPE_INT, 1,
                                "layer", G_TYPE_INT, 3,
-                               "rate", G_TYPE_INT, 
m_sound_data[sound_handle]->sample_rate,
-                               "channels", G_TYPE_INT, 
m_sound_data[sound_handle]->stereo ? 2 : 1, NULL);
+                       "rate", G_TYPE_INT, sounddata->sample_rate,
+                       "channels", G_TYPE_INT, sounddata->stereo ? 2 : 1, 
NULL);
                        g_object_set (G_OBJECT (gst_element->capsfilter), 
"caps", caps, NULL);
                        gst_caps_unref (caps);
 
                        // number of buffers to send
-                       int numBuf = 
static_cast<int>(ceil(static_cast<float>(m_sound_data[sound_handle]->data_size) 
/ static_cast<float>(BUFFER_SIZE)));
+               int numBuf = 
static_cast<int>(ceil(static_cast<float>(sounddata->data_size) / 
static_cast<float>(BUFFER_SIZE)));
                        if (loop_count == -1) {
                                numBuf = -1;
                        } else if (loop_count > 0) {
@@ -480,12 +363,12 @@
                                                        
gst_element->audioresample, 
                                                        gst_element->volume, 
NULL);
 
-               } else if (m_sound_data[sound_handle]->format == 
FORMAT_NATIVE16) {
+       } else if (sounddata->format == FORMAT_NATIVE16) {
 
                        // Set the info about the stream so that gstreamer 
knows what it is.
                        GstCaps *caps = gst_caps_new_simple ("audio/x-raw-int",
-                               "rate", G_TYPE_INT, 
m_sound_data[sound_handle]->sample_rate,
-                               "channels", G_TYPE_INT, 
m_sound_data[sound_handle]->stereo ? 2 : 1,
+                       "rate", G_TYPE_INT, sounddata->sample_rate,
+                       "channels", G_TYPE_INT, sounddata->stereo ? 2 : 1,
                                "endianness", G_TYPE_INT, G_BIG_ENDIAN,
                                "width", G_TYPE_INT, 16,
                                /*"signed", G_TYPE_INT, 1,*/ NULL);
@@ -493,7 +376,7 @@
                        gst_caps_unref (caps);
 
                        // number of buffers to send
-                       int numBuf = 
static_cast<int>(ceil(static_cast<float>(m_sound_data[sound_handle]->data_size) 
/ static_cast<float>(BUFFER_SIZE)));
+               int numBuf = 
static_cast<int>(ceil(static_cast<float>(sounddata->data_size) / 
static_cast<float>(BUFFER_SIZE)));
                        if (loop_count == -1) {
                                numBuf = -1;
                        } else if (loop_count > 0) {
@@ -527,30 +410,30 @@
                gst_object_unref (GST_OBJECT (pad));
                
                // Add the bin to the main pipeline
-               gst_bin_add(GST_BIN (pipeline), gst_element->bin);
+       gst_bin_add(GST_BIN (gst_element->pipeline), gst_element->bin);
                // Link to the adder sink pad
-               gst_element->addersinkpad = gst_element_get_request_pad (adder, 
"sink%d");
+       GstPad *sinkpad = gst_element_get_pad (gst_element->audiosink, "sink");
                GstPad *srcpad = gst_element_get_pad (gst_element->bin, "src");
-               gst_pad_link (srcpad, gst_element->addersinkpad);
+       gst_pad_link (srcpad, sinkpad);
                gst_object_unref (GST_OBJECT (srcpad));
+       gst_object_unref (GST_OBJECT (sinkpad));
                
                // Set the volume
-               g_object_set (G_OBJECT (gst_element->volume), "volume", 
static_cast<double>(m_sound_data[sound_handle]->volume) / 100.0, NULL);
+       g_object_set (G_OBJECT (gst_element->volume), "volume", 
static_cast<double>(sounddata->volume) / 100.0, NULL);
 
-               //gst_pad_add_event_probe(pad, G_CALLBACK(event_callback), 
m_sound_data[sound_handle]);
+       //gst_pad_add_event_probe(pad, G_CALLBACK(event_callback), sounddata);
 
                // Put the gst_element on the vector
-               
m_sound_data[sound_handle]->m_gst_elements.push_back(gst_element);
+       sounddata->m_gst_elements.push_back(gst_element);
 
                // If not already playing, start doing it
-               gst_element_set_state (GST_ELEMENT (pipeline), 
GST_STATE_PLAYING);
+       gst_element_set_state (GST_ELEMENT (gst_element->pipeline), 
GST_STATE_PLAYING);
 
-               ++soundsPlaying;
-       }
+}
 
 
-       virtual void    stop_sound(int sound_handle)
-       {
+void   GST_sound_handler::stop_sound(int sound_handle)
+{
                
                // Check if the sound exists.
                if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size())
@@ -561,10 +444,6 @@
 
                sound_data* sounddata = m_sound_data[sound_handle];
 
-               // This variable is used to asure that we don't try to pause
-               // if nothing is playing, which would mess things up
-               bool stopped = false;
-
                // Stop all the instances of this sound.
                // TODO: fix the loop to use size_t instead of i
                for (int i = sounddata->m_gst_elements.size()-1; i >= 0 ; i--)
@@ -578,39 +457,21 @@
                        // Disconnect signals
                        g_signal_handler_disconnect (elements->input, 
elements->handoff_signal_id);
 
-                       // FIXME: This stops ALL sounds, not just the current.
-                       if (gst_element_set_state (GST_ELEMENT (elements->bin), 
GST_STATE_NULL) != 1) continue;
-
-                       // Unlink the pad which is linked the adder sink pad.
-                       GstPad *srcpad = gst_element_get_pad (elements->bin, 
"src");
-                       gst_pad_unlink (srcpad, elements->addersinkpad);
-                       gst_element_release_request_pad (adder, 
elements->addersinkpad);
-                       gst_object_unref (GST_OBJECT (srcpad));
-
-                       // Unref/delete the elements
-                       gst_bin_remove (GST_BIN (pipeline), elements->bin);
+               gst_element_set_state (GST_ELEMENT (elements->pipeline), 
GST_STATE_NULL);
+               gst_object_unref (GST_OBJECT (elements->pipeline));
 
                        // Delete the gst_element struct
                        // @@ we're deleting the elements from the start, so 
half-way of the loop we will be referring to undefined elements. Is this 
intended ? --strk;
                        delete elements;
                        
sounddata->m_gst_elements.erase(sounddata->m_gst_elements.begin() + i);
-                       --soundsPlaying;
-                       stopped = true;
                }
                
-                       
-               // If no sounds, set pipeline to paused. Else the pipeline 
thinks it's still playing,
-               // and will fastforward through new sounds until it reach the 
"correct posistion".
-               if (soundsPlaying == 0 && stopped) {
-                       gst_element_set_state (GST_ELEMENT (pipeline), 
GST_STATE_PAUSED);
-               }
-               
-       }
+}
 
 
-       virtual void    delete_sound(int sound_handle)
-       // this gets called when it's done with a sample.
-       {
+void   GST_sound_handler::delete_sound(int sound_handle)
+// this gets called when it's done with a sample.
+{
                
                if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
                {
@@ -619,21 +480,21 @@
                        m_sound_data.erase (m_sound_data.begin() + 
sound_handle);
                }
 
-       }
+}
 
-       // This will stop all sounds playing. Will cause problems if the 
soundhandler is made static
-       // and supplys sound_handling for many SWF's, since it will stop all 
sounds with no regard
-       // for what sounds is associated with what SWF.
-       virtual void    stop_all_sounds()
-       {
+// This will stop all sounds playing. Will cause problems if the soundhandler 
is made static
+// and supplys sound_handling for many SWF's, since it will stop all sounds 
with no regard
+// for what sounds is associated with what SWF.
+void   GST_sound_handler::stop_all_sounds()
+{
                for (size_t i=0, e=m_sound_data.size(); i < e; ++i) 
                        stop_sound(i);
-       }
+}
 
 
-       //      returns the sound volume level as an integer from 0 to 100,
-       //      where 0 is off and 100 is full volume. The default setting is 
100.
-       virtual int     get_volume(int sound_handle) {
+//     returns the sound volume level as an integer from 0 to 100,
+//     where 0 is off and 100 is full volume. The default setting is 100.
+int    GST_sound_handler::get_volume(int sound_handle) {
        
                // Check if the sound exists.
                if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
@@ -642,12 +503,12 @@
                } else {
                        return 0; // Invalid handle
                }
-       }
+}
        
 
-       //      A number from 0 to 100 representing a volume level. 
-       //      100 is full volume and 0 is no volume. The default setting is 
100.
-       virtual void    set_volume(int sound_handle, int volume) {
+//     A number from 0 to 100 representing a volume level. 
+//     100 is full volume and 0 is no volume. The default setting is 100.
+void   GST_sound_handler::set_volume(int sound_handle, int volume) {
 
                // Check if the sound exists.
                if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size())
@@ -671,9 +532,9 @@
                                NULL);
                }
 
-       }
+}
 
-       virtual void get_info(int sound_handle, int* format, bool* stereo) {
+void GST_sound_handler::get_info(int sound_handle, int* format, bool* stereo) {
        
                // Check if the sound exists.
                if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
@@ -682,34 +543,34 @@
                        *stereo = m_sound_data[sound_handle]->stereo;
                } 
 
-       }
+}
 
-       // gnash calls this to mute audio
-       virtual void mute() {
+// gnash calls this to mute audio
+void GST_sound_handler::mute() {
                stop_all_sounds();
                muted = true;
-       }
+}
 
-       // gnash calls this to unmute audio
-       virtual void unmute() {
+// gnash calls this to unmute audio
+void GST_sound_handler::unmute() {
                muted = false;
-       }
+}
 
-       virtual bool is_muted() {
+bool GST_sound_handler::is_muted() {
                return muted;
-       }
+}
        
-       void attach_aux_streamer(aux_streamer_ptr /*ptr*/, void* /*owner*/)
-       {
+void GST_sound_handler::attach_aux_streamer(aux_streamer_ptr /*ptr*/, void* 
/*owner*/)
+{
                gnash::log_msg("%s: unimplemented \n", __PRETTY_FUNCTION__);
-       }
+}
 
-       void detach_aux_streamer(void* /*owner*/)
-       {
+void GST_sound_handler::detach_aux_streamer(void* /*owner*/)
+{
                gnash::log_msg("%s: unimplemented \n", __PRETTY_FUNCTION__);
-       }
+}
 
-       void convert_raw_data(
+void GST_sound_handler::convert_raw_data(
        int16_t** /*adjusted_data*/,
        int* /*adjusted_size*/,
        void* /*data*/,
@@ -717,11 +578,9 @@
        int /*sample_size*/,
        int /*sample_rate*/,
        bool /*stereo*/)
-       {
+{
                gnash::log_msg("%s: unimplemented \n", __PRETTY_FUNCTION__);
-       }
-
-};
+}
 
 
 gnash::sound_handler*  gnash::create_sound_handler_gst()

Index: backend/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- backend/sound_handler_sdl.cpp       17 Nov 2006 14:52:19 -0000      1.37
+++ backend/sound_handler_sdl.cpp       17 Nov 2006 19:24:57 -0000      1.38
@@ -171,58 +171,63 @@
                return 1;
        }
        int start_size = 0;
+       sound_data* sounddata = m_sound_data[handle_id];
 
        // Handling of the sound data
-       if (m_sound_data[handle_id]->format == FORMAT_NATIVE16)
+       if (sounddata->format == FORMAT_NATIVE16)
        {
                int16_t*        adjusted_data = 0;
                int     adjusted_size = 0;
 
-               convert_raw_data(&adjusted_data, &adjusted_size, data, 
sample_count, 2, m_sound_data[handle_id]->sample_rate, 
m_sound_data[handle_id]->stereo);
+               convert_raw_data(&adjusted_data, &adjusted_size, data, 
sample_count, 2, sounddata->sample_rate, sounddata->stereo);
                if (!adjusted_data || adjusted_size < 1) {
                        gnash::log_error("Some kind of error with re-formating 
sound data\n");
                        pthread_mutex_unlock(&mutex);
                        return -1;
                }
-               adjusted_data = (int16_t*)data;
+               adjusted_data = static_cast<int16_t*>(data);
                adjusted_size = data_bytes;
 
                // Reallocate the required memory.
-               Uint8* tmp_data = new Uint8[adjusted_size + 
m_sound_data[handle_id]->data_size];
-               memcpy(tmp_data, m_sound_data[handle_id]->data, 
m_sound_data[handle_id]->data_size);
-               memcpy(tmp_data + m_sound_data[handle_id]->data_size, 
adjusted_data, adjusted_size);
-               if (m_sound_data[handle_id]->data_size > 0) delete [] 
m_sound_data[handle_id]->data;
-               m_sound_data[handle_id]->data = tmp_data;
-
-               start_size = m_sound_data[handle_id]->data_size;
-               m_sound_data[handle_id]->data_size += adjusted_size;
-
-               for(uint32_t i=0; i < 
m_sound_data[handle_id]->m_active_sounds.size(); i++) {
-                       
m_sound_data[handle_id]->m_active_sounds[i]->set_data(m_sound_data[handle_id]->data);
-                       m_sound_data[handle_id]->m_active_sounds[i]->data_size 
= m_sound_data[handle_id]->data_size;
-                       m_sound_data[handle_id]->m_active_sounds[i]->position = 
m_sound_data[handle_id]->data_size;
-                       
m_sound_data[handle_id]->m_active_sounds[i]->set_raw_data(m_sound_data[handle_id]->data);
+               Uint8* tmp_data = new Uint8[adjusted_size + 
sounddata->data_size];
+               memcpy(tmp_data, sounddata->data, sounddata->data_size);
+               memcpy(tmp_data + sounddata->data_size, adjusted_data, 
adjusted_size);
+               if (sounddata->data_size > 0) delete [] sounddata->data;
+               sounddata->data = tmp_data;
+
+               start_size = sounddata->data_size;
+               sounddata->data_size += adjusted_size;
+               std::vector<active_sound*> asounds = sounddata->m_active_sounds;
+
+               for(uint32_t i=0; i < asounds.size(); i++) {
+                       active_sound* sound = asounds[i];
+                       sound->set_data(sounddata->data);
+                       sound->data_size = sounddata->data_size;
+                       sound->position = sounddata->data_size;
+                       sound->set_raw_data(sounddata->data);
                }
-       } else if (m_sound_data[handle_id]->format == FORMAT_MP3) {
+       } else if (sounddata->format == FORMAT_MP3) {
 
                // Reallocate the required memory.
-               Uint8* tmp_data = new Uint8[data_bytes + 
m_sound_data[handle_id]->data_size];
-               memcpy(tmp_data, m_sound_data[handle_id]->data, 
m_sound_data[handle_id]->data_size);
-               memcpy(tmp_data + m_sound_data[handle_id]->data_size, data, 
data_bytes);
-               if (m_sound_data[handle_id]->data_size > 0) delete [] 
m_sound_data[handle_id]->data;
-               m_sound_data[handle_id]->data = tmp_data;
-
-               start_size = m_sound_data[handle_id]->data_size;
-               m_sound_data[handle_id]->data_size += data_bytes;
+               Uint8* tmp_data = new Uint8[data_bytes + sounddata->data_size];
+               memcpy(tmp_data, sounddata->data, sounddata->data_size);
+               memcpy(tmp_data + sounddata->data_size, data, data_bytes);
+               if (sounddata->data_size > 0) delete [] sounddata->data;
+               sounddata->data = tmp_data;
+
+               start_size = sounddata->data_size;
+               sounddata->data_size += data_bytes;
+               std::vector<active_sound*> asounds = sounddata->m_active_sounds;
 
                // If playback has already started, we also update the active 
sounds
-               for(uint32_t i=0; i < 
m_sound_data[handle_id]->m_active_sounds.size(); i++) {
-                       
m_sound_data[handle_id]->m_active_sounds[i]->set_data(m_sound_data[handle_id]->data);
-                       m_sound_data[handle_id]->m_active_sounds[i]->data_size 
= m_sound_data[handle_id]->data_size;
+               for(uint32_t i=0; i < asounds.size(); i++) {
+                       active_sound* sound = asounds[i];
+                       sound->set_data(sounddata->data);
+                       sound->data_size = sounddata->data_size;
                }
 
        } else {
-               gnash::log_error("Behavior for this codec is unknown. Please 
send this SWF to the developers\n");
+               gnash::log_error("Behavior for this audio codec is unknown. 
Please send this SWF to the developers\n");
        }
 
        pthread_mutex_unlock(&mutex);
@@ -237,17 +242,19 @@
        pthread_mutex_lock(&mutex);
 
        // Check if the sound exists, or if audio is muted
-       if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size() || muted)
+       if (sound_handle < 0 || static_cast<unsigned int>(sound_handle) >= 
m_sound_data.size() || muted)
        {
                // Invalid handle or muted
                pthread_mutex_unlock(&mutex);
                return;
        }
 
+       sound_data* sounddata = m_sound_data[sound_handle];
+
        // If this is called from a streamsoundblocktag, we only start if this
        // sound isn't already playing. If a active_sound-struct is existing we
        // assume it is also playing.
-       if (start_position > 0 && 
m_sound_data[sound_handle]->m_active_sounds.size() > 0) {
+       if (start_position > 0 && sounddata->m_active_sounds.size() > 0) {
                pthread_mutex_unlock(&mutex);
                return;
        }
@@ -256,15 +263,15 @@
        active_sound* sound = new active_sound;
 
        // Copy data-info to the active_sound
-       sound->data_size = m_sound_data[sound_handle]->data_size;
-       sound->set_data(m_sound_data[sound_handle]->data);
+       sound->data_size = sounddata->data_size;
+       sound->set_data(sounddata->data);
 
        // Set the given options of the sound
        if (start_position < 0) sound->position = 0;
        else sound->position = start_position;
 
        if (offset < 0) sound->offset = 0;
-       else sound->offset = (m_sound_data[sound_handle]->stereo ? offset : 
offset*2); // offset is stored as stereo
+       else sound->offset = (sounddata->stereo ? offset : offset*2); // offset 
is stored as stereo
 
        sound->envelopes = envelopes;
        sound->current_env = 0;
@@ -273,7 +280,7 @@
        // Set number of loop we should do. -1 is infinte loop, 0 plays it 
once, 1 twice etc.
        sound->loop_count = loop_count;
 
-       if (m_sound_data[sound_handle]->format == FORMAT_MP3) {
+       if (sounddata->format == FORMAT_MP3) {
 
 #ifdef USE_FFMPEG
                // Init the avdecoder-decoder
@@ -305,10 +312,10 @@
                sound->raw_data_size = 0;
 
        } else {
-               sound->raw_data_size = m_sound_data[sound_handle]->data_size;
-               sound->set_raw_data(m_sound_data[sound_handle]->data);
+               sound->raw_data_size = sounddata->data_size;
+               sound->set_raw_data(sounddata->data);
                sound->raw_position = 0;
-               sound->position = m_sound_data[sound_handle]->data_size;
+               sound->position = sounddata->data_size;
 
        }
 
@@ -323,7 +330,7 @@
        }
 
        ++soundsPlaying;
-       m_sound_data[sound_handle]->m_active_sounds.push_back(sound);
+       sounddata->m_active_sounds.push_back(sound);
 
        if (soundsPlaying == 1) {
                SDL_PauseAudio(0);
@@ -344,25 +351,29 @@
                // Invalid handle.
        } else {
 
-               for (int32_t i = 
(int32_t)m_sound_data[sound_handle]->m_active_sounds.size()-1; i >-1; i--) {
+               sound_data* sounddata = m_sound_data[sound_handle];
+       
+               for (int32_t i = (int32_t) sounddata->m_active_sounds.size()-1; 
i >-1; i--) {
+
+                       active_sound* sound = sounddata->m_active_sounds[i];
 
                        // Stop sound, remove it from the active list (mp3)
-                       if (m_sound_data[sound_handle]->format == 2) {
+                       if (sounddata->format == 2) {
 #ifdef USE_FFMPEG
-                               
avcodec_close(m_sound_data[sound_handle]->m_active_sounds[i]->cc);
-                               
av_parser_close(m_sound_data[sound_handle]->m_active_sounds[i]->parser);
+                               avcodec_close(sound->cc);
+                               av_parser_close(sound->parser);
 #elif defined(USE_MAD)
-                               
mad_synth_finish(&m_sound_data[sound_handle]->m_active_sounds[i]->synth);
-                               
mad_frame_finish(&m_sound_data[sound_handle]->m_active_sounds[i]->frame);
-                               
mad_stream_finish(&m_sound_data[sound_handle]->m_active_sounds[i]->stream);
+                               mad_synth_finish(&sound->synth);
+                               mad_frame_finish(&sound->frame);
+                               mad_stream_finish(&sound->stream);
 #endif
-                               
m_sound_data[sound_handle]->m_active_sounds[i]->delete_raw_data();
-                               
m_sound_data[sound_handle]->m_active_sounds.erase(m_sound_data[sound_handle]->m_active_sounds.begin()
 + i);
+                               sound->delete_raw_data();
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + i);
                                soundsPlaying--;
 
                        // Stop sound, remove it from the active list 
(adpcm/native16)
                        } else {
-                               
m_sound_data[i]->m_active_sounds.erase(m_sound_data[sound_handle]->m_active_sounds.begin()
 + i);
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + i);
                                soundsPlaying--;
                        }
                }
@@ -377,7 +388,7 @@
 {
        pthread_mutex_lock(&mutex);
 
-       if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
+       if (sound_handle >= 0 && static_cast<unsigned int>(sound_handle) < 
m_sound_data.size())
        {
                delete[] m_sound_data[sound_handle]->data;
        }
@@ -394,26 +405,29 @@
 
        int32_t num_sounds = (int32_t) m_sound_data.size()-1;
        for (int32_t j = num_sounds; j > -1; j--) {//Optimized
-               int32_t num_active_sounds = (int32_t) 
m_sound_data[j]->m_active_sounds.size()-1;
+               sound_data* sounddata = m_sound_data[j];
+               int32_t num_active_sounds = (int32_t) 
sounddata->m_active_sounds.size()-1;
                for (int32_t i = num_active_sounds; i > -1; i--) {
 
+                       active_sound* sound = sounddata->m_active_sounds[i];
+
                        // Stop sound, remove it from the active list (mp3)
-                       if (m_sound_data[j]->format == 2) {
+                       if (sounddata->format == 2) {
 #ifdef USE_FFMPEG
-                               
avcodec_close(m_sound_data[j]->m_active_sounds[i]->cc);
-                               
av_parser_close(m_sound_data[j]->m_active_sounds[i]->parser);
+                               avcodec_close(sound->cc);
+                               av_parser_close(sound->parser);
 #elif defined(USE_MAD)
-                               
mad_synth_finish(&m_sound_data[j]->m_active_sounds[i]->synth);
-                               
mad_frame_finish(&m_sound_data[j]->m_active_sounds[i]->frame);
-                               
mad_stream_finish(&m_sound_data[j]->m_active_sounds[i]->stream);
+                               mad_synth_finish(&sound->synth);
+                               mad_frame_finish(&sound->frame);
+                               mad_stream_finish(&sound->stream);
 #endif
-                               
m_sound_data[j]->m_active_sounds[i]->delete_raw_data();
-                               
m_sound_data[j]->m_active_sounds.erase(m_sound_data[j]->m_active_sounds.begin() 
+ i);
+                               sound->delete_raw_data();
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + i);
                                soundsPlaying--;
 
                        // Stop sound, remove it from the active list 
(adpcm/native16)
                        } else {
-                               
m_sound_data[i]->m_active_sounds.erase(m_sound_data[j]->m_active_sounds.begin() 
+ i);
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + i);
                                soundsPlaying--;
                        }
                }
@@ -430,7 +444,7 @@
 
        int ret;
        // Check if the sound exists.
-       if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
+       if (sound_handle >= 0 && static_cast<unsigned int>(sound_handle) < 
m_sound_data.size())
        {
                ret = m_sound_data[sound_handle]->volume;
        } else {
@@ -448,7 +462,7 @@
        pthread_mutex_lock(&mutex);
 
        // Check if the sound exists.
-       if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size())
+       if (sound_handle < 0 || static_cast<unsigned int>(sound_handle) >= 
m_sound_data.size())
        {
                // Invalid handle.
        } else {
@@ -466,7 +480,7 @@
        pthread_mutex_lock(&mutex);
 
        // Check if the sound exists.
-       if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
+       if (sound_handle >= 0 && static_cast<unsigned int>(sound_handle) < 
m_sound_data.size())
        {
                *format = m_sound_data[sound_handle]->format;
                *stereo = m_sound_data[sound_handle]->stereo;
@@ -682,14 +696,14 @@
                startpos = sound->raw_position;
        }
 
-       int16_t* data = (int16_t*) (sound->get_raw_data_ptr(startpos));
+       int16_t* data = 
reinterpret_cast<int16_t*>(sound->get_raw_data_ptr(startpos));
 
        for (unsigned int i=0; i < length/2; i+=2) {
-               float left = 
(float)(*sound->envelopes)[sound->current_env].m_level0 / 32768.0;
-               float right = 
(float)(*sound->envelopes)[sound->current_env].m_level1 / 32768.0;
+               float left = 
static_cast<float>((*sound->envelopes)[sound->current_env].m_level0 / 32768.0);
+               float right = 
static_cast<float>((*sound->envelopes)[sound->current_env].m_level1 / 32768.0);
 
-               data[i] = (int16_t)(data[i] * left); // Left
-               data[i+1] = (int16_t)(data[i+1] * right); // Right
+               data[i] = static_cast<int16_t>(data[i] * left); // Left
+               data[i+1] = static_cast<int16_t>(data[i+1] * right); // Right
 
                if ((sound->samples_played+(length/2-i)) >= next_env_pos && 
sound->current_env != (sound->envelopes->size()-1)) {
                        sound->current_env++;
@@ -698,7 +712,7 @@
                                // If there is no "next envelope" then set the 
next envelope start point to be unreachable
                                next_env_pos = cur_env_pos + length;
                        } else {
-                               next_env_pos = 
sound->envelopes->operator[](sound->current_env+1).m_mark44;
+                               next_env_pos = 
(*sound->envelopes)[sound->current_env+1].m_mark44;
                        }
                }
        }
@@ -710,13 +724,13 @@
 do_mixing(Uint8* stream, active_sound* sound, Uint8* data, unsigned int 
mix_length, unsigned int volume) {
        // If the volume needs adjustments we call a function to do that
        if (volume != 100) {
-               adjust_volume((int16_t*)(data), mix_length, volume);
+               adjust_volume(reinterpret_cast<int16_t*>(data), mix_length, 
volume);
        } else if (sound->envelopes != NULL) {
                use_envelopes(sound, mix_length);
        }
 
        // Mix the raw data
-       SDL_MixAudio((Uint8*)(stream),(const Uint8*) (data), mix_length, 
SDL_MIX_MAXVOLUME);
+       SDL_MixAudio(static_cast<Uint8*>(stream),static_cast<const 
Uint8*>(data), mix_length, SDL_MIX_MAXVOLUME);
 
        // Update sound info
        sound->raw_position += mix_length;
@@ -782,9 +796,10 @@
        }
 
        for(uint32_t i=0; i < handler->m_sound_data.size(); i++) {
-               for(uint32_t j = 0; j < 
handler->m_sound_data[i]->m_active_sounds.size(); j++) {
+               sound_data* sounddata = handler->m_sound_data[i];
+               for(uint32_t j = 0; j < sounddata->m_active_sounds.size(); j++) 
{
 
-                       active_sound* sound = 
handler->m_sound_data[i]->m_active_sounds[j];
+                       active_sound* sound = sounddata->m_active_sounds[j];
 
                        // When the current sound dont have enough decoded data 
to fill the buffer, 
                        // we first mix what is already decoded, then decode 
some more data, and
@@ -799,7 +814,7 @@
                                        index = sound->raw_data_size - 
sound->raw_position;
 
                                        do_mixing(stream, sound, 
sound->get_raw_data_ptr(sound->raw_position),
-                                               index, 
handler->m_sound_data[i]->volume);
+                                               index, sounddata->volume);
 
                                }
 
@@ -836,11 +851,11 @@
                                                int framesize;
 
                                                bytes_decoded = 
av_parser_parse(sound->parser, sound->cc, &frame, &framesize,
-                                                                       
(uint8_t *)(sound->get_data_ptr(sound->position)), sound->data_size - 
sound->position,
+                                                                       
static_cast<uint8_t *>(sound->get_data_ptr(sound->position)), sound->data_size 
- sound->position,
                                                                        0 ,0);  
//pts, dts
 
                                                int tmp = 0;
-                                               tmp = 
avcodec_decode_audio(sound->cc, (int16_t *)tmp_raw_buffer, &outsize, frame, 
framesize);
+                                               tmp = 
avcodec_decode_audio(sound->cc, (int16_t*)(tmp_raw_buffer), &outsize, frame, 
framesize);
 
                                                if (bytes_decoded < 0 || tmp < 
0 || outsize < 0) {
                                                        gnash::log_error("Error 
while decoding MP3-stream. Upgrading ffmpeg/libavcodec might fix this 
issue.\n");
@@ -893,18 +908,18 @@
 
                                        mad_synth_frame (&sound->synth, 
&sound->frame);
                                        
-                                       outsize = sound->synth.pcm.length * 
((handler->m_sound_data[i]->stereo == true) ? 4 : 2);
+                                       outsize = sound->synth.pcm.length * 
((sounddata->stereo == true) ? 4 : 2);
 
                                        tmp_raw_buffer = new Uint8[outsize];
                                        int sample;
                                        
-                                       int16_t* dst = (int16_t*) 
tmp_raw_buffer;
+                                       int16_t* dst = 
reinterpret_cast<int16_t*>(tmp_raw_buffer);
 
                                        // transfer the decoded samples into 
the sound-struct, and do some
                                        // scaling while we're at it.
                                        for(int f = 0; f < 
sound->synth.pcm.length; f++)
                                        {
-                                               for (int e = 0; e < 
((handler->m_sound_data[i]->stereo == true) ? 2 : 1); e++){ // channels 
(stereo/mono)
+                                               for (int e = 0; e < 
((sounddata->stereo == true) ? 2 : 1); e++){ // channels (stereo/mono)
 
                                                        mad_fixed_t mad_sample 
= sound->synth.pcm.samples[e][f];
 
@@ -918,7 +933,7 @@
                                                        // quantize
                                                        sample = mad_sample >> 
(MAD_F_FRACBITS + 1 - 16);
 
-                                                       if ( sample != 
(int16_t)sample ) sample = sample < 0 ? -32768 : 32767;
+                                                       if ( sample != 
static_cast<int16_t>(sample) ) sample = sample < 0 ? -32768 : 32767;
 
                                                        *dst++ = sample;
                                                }
@@ -926,15 +941,15 @@
 #endif
 
                                        // If we need to convert samplerate...
-                                       if (outsize > 0 && 
handler->m_sound_data[i]->sample_rate != handler->audioSpec.freq) {
+                                       if (outsize > 0 && 
sounddata->sample_rate != handler->audioSpec.freq) {
 
                                                int16_t* adjusted_data = 0;
                                                int     adjusted_size = 0;
-                                               int sample_count = outsize / 
((handler->m_sound_data[i]->stereo == true) ? 4 : 2);
+                                               int sample_count = outsize / 
((sounddata->stereo == true) ? 4 : 2);
 
                                                // Convert to needed samplerate
                                                
handler->convert_raw_data(&adjusted_data, &adjusted_size, tmp_raw_buffer, 
sample_count, 0, 
-                                                               
handler->m_sound_data[i]->sample_rate, handler->m_sound_data[i]->stereo);
+                                                               
sounddata->sample_rate, sounddata->stereo);
 
                                                // Hopefully this wont happen
                                                if (!adjusted_data) {
@@ -944,7 +959,7 @@
 
                                                // Move the new data to the 
sound-struct
                                                delete[] tmp_raw_buffer;
-                                               tmp_raw_buffer = (Uint8*) 
adjusted_data;
+                                               tmp_raw_buffer = 
reinterpret_cast<Uint8*>(adjusted_data);
                                                tmp_raw_buffer_size = 
adjusted_size;
 
                                        } else {
@@ -979,14 +994,14 @@
                                        mix_length = decoded_size;
                                }
 
-                               do_mixing(stream+index, sound, 
sound->get_raw_data_ptr(0), mix_length, handler->m_sound_data[i]->volume);
+                               do_mixing(stream+index, sound, 
sound->get_raw_data_ptr(0), mix_length, sounddata->volume);
 
                        // When the current sound has enough decoded data to 
fill 
                        // the buffer, we do just that.
                        } else if (sound->raw_data_size - sound->raw_position > 
buffer_length ) {
                        
                                do_mixing(stream, sound, 
sound->get_raw_data_ptr(sound->raw_position), 
-                                       buffer_length, 
handler->m_sound_data[i]->volume);
+                                       buffer_length, sounddata->volume);
 
                        // When the current sound doesn't have anymore data to 
decode,
                        // and doesn't loop (anymore), but still got unplayed 
data,
@@ -995,13 +1010,13 @@
                        
 
                                do_mixing(stream, sound, 
sound->get_raw_data_ptr(sound->raw_position), 
-                                       sound->raw_data_size - 
sound->raw_position, handler->m_sound_data[i]->volume);
+                                       sound->raw_data_size - 
sound->raw_position, sounddata->volume);
 
                                sound->raw_position = sound->raw_data_size;
                        } 
 
                        // Sound is done, remove it from the active list (mp3)
-                       if (sound->position == sound->data_size && 
sound->loop_count == 0 && handler->m_sound_data[i]->format == 2) {
+                       if (sound->position == sound->data_size && 
sound->loop_count == 0 && sounddata->format == 2) {
 #ifdef USE_FFMPEG
                                avcodec_close(sound->cc);
                                av_parser_close(sound->parser);
@@ -1011,16 +1026,16 @@
                                mad_stream_finish(&sound->stream);
 #endif
                                sound->delete_raw_data();
-                               
handler->m_sound_data[i]->m_active_sounds.erase(handler->m_sound_data[i]->m_active_sounds.begin()
 + j);
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + j);
                                handler->soundsPlaying--;
 
 
                        // Sound is done, remove it from the active list 
(adpcm/native16)
-                       } else if (sound->loop_count == 0 && 
handler->m_sound_data[i]->format == 7 && sound->raw_position >= 
sound->raw_data_size && sound->raw_data_size != 0) {
-                               
handler->m_sound_data[i]->m_active_sounds.erase(handler->m_sound_data[i]->m_active_sounds.begin()
 + j);
+                       } else if (sound->loop_count == 0 && sounddata->format 
== 7 && sound->raw_position >= sound->raw_data_size && sound->raw_data_size != 
0) {
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + j);
                                handler->soundsPlaying--;
                        } else if (sound->raw_position == 0 && 
sound->raw_data_size == 0) {
-                               
handler->m_sound_data[i]->m_active_sounds.erase(handler->m_sound_data[i]->m_active_sounds.begin()
 + j);
+                               
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + j);
                                handler->soundsPlaying--;
                        }
 

Index: backend/sound_handler_gst.h
===================================================================
RCS file: backend/sound_handler_gst.h
diff -N backend/sound_handler_gst.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ backend/sound_handler_gst.h 17 Nov 2006 19:24:57 -0000      1.1
@@ -0,0 +1,161 @@
+//   Copyright (C) 2005, 2006 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 2 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 SOUND_HANDLER_GST_H
+#define SOUND_HANDLER_GST_H
+
+#include "gnash.h"
+#include <vector>
+
+#include <gst/gst.h>
+
+#define BUFFER_SIZE 5000
+
+// Used to hold the gstreamer when doing on-demand-decoding
+class gst_elements
+{
+public:
+       // gstreamer pipeline objects
+
+       // the main bin containing the adder and output (sink)
+       GstElement *pipeline;
+       GstElement *audiosink;
+
+       // gstreamer objects
+       GstElement *input;
+       GstElement *decoder;
+       GstElement *capsfilter;
+       GstElement *audioconvert;
+       GstElement *audioresample;
+       GstElement *volume;
+       GstElement *bin;
+       GstPad     *addersinkpad;
+       
+       // position in the stream
+       long position;
+
+       // The (un)compressed data
+       guint8* data;
+
+       // data size
+       long data_size;
+
+       long loop_count;
+       
+       // signal id
+       guint handoff_signal_id;
+
+};
+
+
+// Used to hold the sounddata when doing on-demand-decoding
+class sound_data
+{
+public:
+       // The (un)compressed data
+       guint8* data;
+
+       // data format
+       int format;
+
+       // data size
+       long data_size;
+
+       // stereo or not
+       bool stereo;
+
+       // number of samples
+       int sample_count;
+
+       // sample rate
+       int sample_rate;
+
+       // Volume, SWF range: 0-100, GST range 0-10 (we only use 0-1, the rest 
is amplified)
+       // It's the SWF range that is represented here
+       int volume;
+
+       // gstreamer objects
+       std::vector<gst_elements*>      m_gst_elements;
+
+};
+
+// Use gstreamer to handle sounds.
+class GST_sound_handler : public gnash::sound_handler
+{
+public:
+       /// Vector containing all the sounds
+       std::vector<sound_data*>        m_sound_data;
+       
+       /// Is the loop running?
+       bool looping;
+       
+       /// Is the audio muted?
+       bool muted;
+
+       GST_sound_handler();
+       virtual ~GST_sound_handler();
+
+       /// Called to create a sound.
+       virtual int     create_sound(void* data, int data_bytes,
+                                    int sample_count, format_type format,
+                                    int sample_rate, bool stereo);
+
+       /// this gets called when a stream gets more data
+       virtual long    fill_stream_data(void* data, int data_bytes,
+                                        int sample_count, int handle_id);
+
+       /// Play the index'd sample.
+       virtual void    play_sound(int sound_handle, int loop_count, int offset,
+                                  long start_position, 
std::vector<sound_envelope>* envelopes);
+
+       /// Stop the index'd sample.
+       virtual void    stop_sound(int sound_handle);
+
+       /// This gets called when it's done with a sample.
+       virtual void    delete_sound(int sound_handle);
+
+       /// This will stop all sounds playing.
+       virtual void    stop_all_sounds();
+
+       /// Returns the sound volume level as an integer from 0 to 100. 
AS-script only.
+       virtual int     get_volume(int sound_handle);
+
+       /// Sets the sound volume level as an integer from 0 to 100. AS-script 
only.
+       virtual void    set_volume(int sound_handle, int volume);
+               
+       /// Gnash uses this to get info about a sound. Used when a stream needs 
more data.
+       virtual void    get_info(int sound_handle, int* format, bool* stereo);
+
+       /// Gnash calls this to mute audio.
+       virtual void    mute();
+
+       /// Gnash calls this to unmute audio.
+       virtual void    unmute();
+
+       /// Gnash calls this to get the mute state.
+       virtual bool    is_muted();
+
+       virtual void    attach_aux_streamer(aux_streamer_ptr ptr, void* owner); 
//vv
+       virtual void    detach_aux_streamer(void* owner);       //vv
+
+       /// Converts input data to the SDL output format.
+       virtual void    convert_raw_data(int16_t** adjusted_data,
+                         int* adjusted_size, void* data, int sample_count,
+                         int sample_size, int sample_rate, bool stereo);       
//vv
+};
+
+#endif // SOUND_HANDLER_GST_H
+




reply via email to

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