gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog Makefile.am configure.ac backen...


From: Tomas Groth
Subject: [Gnash-commit] gnash ChangeLog Makefile.am configure.ac backen...
Date: Sat, 07 Oct 2006 14:20:27 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Tomas Groth <tgc>       06/10/07 14:20:27

Modified files:
        .              : ChangeLog Makefile.am configure.ac 
        backend        : Makefile.am sound_handler_gst.cpp 
                         sound_handler_sdl.cpp 
        macros         : ffmpeg.m4 mad.m4 
        plugin         : Makefile.am 
        server         : gnash.h 
        server/swf     : tag_loaders.cpp 
        utilities      : Makefile.am 

Log message:
        The new soundbackend...

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1060&r2=1.1061
http://cvs.savannah.gnu.org/viewcvs/gnash/Makefile.am?cvsroot=gnash&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/gnash/configure.ac?cvsroot=gnash&r1=1.129&r2=1.130
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/Makefile.am?cvsroot=gnash&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.cpp?cvsroot=gnash&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.cpp?cvsroot=gnash&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/gnash/macros/ffmpeg.m4?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/macros/mad.m4?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/plugin/Makefile.am?cvsroot=gnash&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/gnash/server/gnash.h?cvsroot=gnash&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/tag_loaders.cpp?cvsroot=gnash&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/gnash/utilities/Makefile.am?cvsroot=gnash&r1=1.26&r2=1.27

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1060
retrieving revision 1.1061
diff -u -b -r1.1060 -r1.1061
--- ChangeLog   7 Oct 2006 12:29:35 -0000       1.1060
+++ ChangeLog   7 Oct 2006 14:20:27 -0000       1.1061
@@ -1,3 +1,13 @@
+2006-10-07 Tomas Groth Christensen <address@hidden>
+
+        * Makefile.am, configure.ac, backend/Makefile.am, 
+        backend/sound_handler_gst.cpp, backend/sound_handler_sdl.cpp,
+        macros/ffmpeg.m4, macros/mad.m4, plugin/Makefile.am, 
+        server/gnash.h, server/swf/tag_loaders.cpp, 
+        utilities/Makefile.am: Commited the new soundbackend, based
+        on SDL and optionally ffmpeg or libmad. Also changed the
+        buildsystem to reflect the change.
+
 2006-10-07 Bastiaan Jacques <address@hidden>
 
        * configure.ac: Replace --enable-lotsa-warnings with --enable-strict,
@@ -9,7 +19,7 @@
        * configure.ac: Fixed typo. '!=' -> '='.
        * macros/sdl.m4: Fixed finding libpath.
 
-2006-10-07 Tomas Groth Christensen <tomas@>
+2006-10-07 Tomas Groth Christensen <address@hidden>
 
        * configure.ac: Fixed typo, so that we check for OpenGL when 
        it is the selected renderer.

Index: Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/Makefile.am,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- Makefile.am 3 Oct 2006 13:52:15 -0000       1.37
+++ Makefile.am 7 Oct 2006 14:20:27 -0000       1.38
@@ -133,8 +133,8 @@
        @echo "X_LIBS is $(X_LIBS)"
        @echo "DMALLOC_CFLAGS is $(DMALLOC_CFLAGS)"
        @echo "DMALLOC_LIBS is $(DMALLOC_LIBS)"
-       @echo "MP3_CFLAGS is $(MP3_CFLAGS)"
-       @echo "MP3_LIBS is $(MP3_LIBS)"
+       @echo "MAD_CFLAGS is $(MAD_CFLAGS)"
+       @echo "MAD_LIBS is $(MAD_LIBS)"
        @echo "PTHREAD_CFLAGS is $(PTHREAD_CFLAGS)"
        @echo "PTHREAD_LIBS is $(PTHREAD_LIBS)"
        @echo "CURL_CFLAGS is $(CURL_CFLAGS)"

Index: configure.ac
===================================================================
RCS file: /sources/gnash/gnash/configure.ac,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -b -r1.129 -r1.130
--- configure.ac        7 Oct 2006 12:29:35 -0000       1.129
+++ configure.ac        7 Oct 2006 14:20:27 -0000       1.130
@@ -33,7 +33,7 @@
 dnl also makes it possible to release a modified version which carries
 dnl forward this exception.
 
-dnl $Id: configure.ac,v 1.129 2006/10/07 12:29:35 bjacques Exp $
+dnl $Id: configure.ac,v 1.130 2006/10/07 14:20:27 tgc Exp $
 
 AC_PREREQ(2.50)
 AC_INIT(gnash, 0.7.1-cvs)
@@ -223,30 +223,22 @@
  sound,
  [  --enable-sound=handler  Enable sound support using the specified handler:
                                  GST (Gstreamer)
-                                 FFMPEG
-                                MAD (libmad)
-                                 SDL (SDL_Mixer)],
+                                 SDL (SDL)],
  [case "${enableval}" in
    GST|gst) sound_handler=gst ;;
    sdl|SDL) sound_handler=sdl  ;;
-   ffmpeg|FFMPEG) sound_handler=ffmpeg ;;
-   mad|MAD) sound_handler=mad ;;
    *) sound_handler=none ;;
   esac],
  [sound_handler=none]
 )
 case "${sound_handler}" in
        gst)  AC_DEFINE([SOUND_GST],  [1], [Use GSTREAMER for sound]) ;;
-       sdl)  AC_DEFINE([SOUND_SDL],  [1], [Use SDL-mixer for sound]) ;;
-       ffmpeg)  AC_DEFINE([SOUND_SDL],  [1], [Use FFMPEG for sound]) ;;
-       mad)  AC_DEFINE([SOUND_SDL],  [1], [Use libMAD for sound]) ;;
+       sdl)  AC_DEFINE([SOUND_SDL],  [1], [Use SDL for sound]) ;;
        *)
 esac
 
 AM_CONDITIONAL(USE_SOUND_GST, test x$sound_handler = xgst)
 AM_CONDITIONAL(USE_SOUND_SDL, test x$sound_handler = xsdl)
-AM_CONDITIONAL(USE_SOUND_MAD, test x$sound_handler = xsdl)
-AM_CONDITIONAL(USE_SOUND_FFMPEG, test x$sound_handler = xffmpeg)
 
 dnl --------------------------------------------------------
 dnl  ...
@@ -399,12 +391,12 @@
 AC_PATH_PROG(DOXYGEN, doxygen)
 AM_CONDITIONAL(ENABLE_DOXYGEN, [ test x"$DOXYGEN" != x ])
 
-GNASH_PATH_MP3
+GNASH_PATH_MAD
 GNASH_PATH_OGG
-if test x$gui = xsdl; then
+if test x$gui = xsdl -o x$sound_handler = xsdl; then
 GNASH_PATH_SDL
 fi
-GNASH_PATH_SDL_MIXER
+
 AM_CONDITIONAL(HAS_SDL, [ test x$has_sdl = xyes ])
 
 GNASH_PATH_BOOST
@@ -449,7 +441,10 @@
 
 AM_CONDITIONAL(HAS_GTK2, [ test x$has_gtk2 = xyes ])
 
+if test x"$mad" = x"no"; then
 GNASH_PATH_FFMPEG
+fi
+
 AM_CONDITIONAL(HAVE_FFMPEG, [test x"${FFMPEG_LIBS}" != x])
 
 GNASH_PATH_GSTREAMER
@@ -622,10 +617,10 @@
   echo "        Intel 810 LOD bias hack disabled (default). Use 
--enable-i810-lod-bias to enable."
 fi
 
-if test x"$mp3" = x"yes"; then
+if test x"$mad" = x"yes"; then
   echo "        MP3 (libmad) support enabled"
 else
-  echo "        MP3 (libmad) support disabled (default). Use --enable-mp3 to 
enable"
+  echo "        MP3 (libmad) support disabled (default). Use --enable-mad to 
enable"
 fi
 
 if test x"$pthreads" = x"yes"; then
@@ -970,15 +965,15 @@
 fi
 
 if test x"$sound_handler" = x"sdl"; then
-  if test x"$SDL_MIXER_LIBS" != x; then
-      echo "        SDL_Mixer flags are: $SDL_MIXER_CFLAGS"
-      echo "        SDL_Mixer libs are: $SDL_MIXER_LIBS"
-  else
-      echo "ERROR: sdl sound requested, but no SDL_Mixer development package 
installed!\
-   You need to have the SDL Mixer development package installed\
-   if you wish to have sdl-based MP3 support for Gnash.\
+  if test x"$SDL_LIBS" != x; then
+      echo "        SDL flags are: $SDL_CFLAGS"
+      echo "        SDL libs are: $SDL_LIBS"
+  else
+      echo "ERROR: sdl sound requested, but no SDL development package 
installed!\
+   You need to have the SDL development package installed\
+   if you wish to have sdl-based sound support for Gnash.\
    To compile this project with SDL sound support, install\
-   libsdl-mixer1.2-dev (using apt-get) or SDL_mixer-devel (using yum).
+   libsdl-1.2-dev (using apt-get) or SDL-devel (using yum).
    In alternative build with --enable-sound=gst for gstreamer use"
    nogo=true
   fi

Index: backend/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/backend/Makefile.am,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- backend/Makefile.am 7 Oct 2006 09:43:33 -0000       1.37
+++ backend/Makefile.am 7 Oct 2006 14:20:27 -0000       1.38
@@ -20,11 +20,6 @@
 
 AUTOMAKE_OPTIONS =
 
-if MP3
-MP3_CFLAGS = $(MAD_CFLAGS)
-MP3_LIBS = $(MAD_LIBS)
-endif
-
 AM_CPPFLAGS = # -Wall
 
 ## WARNING: make sure GLIB_LIBS appears first
@@ -36,12 +31,10 @@
         $(OGG_LIBS) \
        $(ZLIB_LIBS) \
         $(SDL_LIBS) \
-        $(SDL_MIXER_LIBS) \
        $(PANGO_LIBS) \
        $(ATK_LIBS) \
        $(X_LIBS) \
        $(DMALLOC_LIBS) \
-       $(MP3_LIBS) \
        $(PTHREAD_LIBS) \
        $(NULL)
 
@@ -54,14 +47,12 @@
         -I$(top_srcdir)/libgeometry \
        $(PTHREAD_CFLAGS) \
         $(SDL_CFLAGS) \
-        $(SDL_MIXER_CFLAGS) \
        $(PANGO_CFLAGS) \
        $(GLIB_CFLAGS) \
        $(ATK_CFLAGS) \
        $(DMALLOC_CFLAGS) \
        $(PNG_CFLAGS) \
        $(JPEG_CFLAGS) \
-       $(MP3_CFLAGS) \
        $(OGG_CFLAGS) \
        $(NULL)
 
@@ -93,8 +84,13 @@
 
 if USE_SOUND_SDL
 SOUND_SOURCES = sound_handler_sdl.cpp 
-if MP3
-SOUND_SOURCES += sound_handler_mp3.cpp
+if HAVE_FFMPEG 
+AM_LDFLAGS += $(FFMPEG_LIBS)
+INCLUDES += $(FFMPEG_CFLAGS)
+endif
+if HAVE_MAD
+AM_LDFLAGS += $(MAD_LIBS)
+INCLUDES += $(MAD_CFLAGS)
 endif
 endif
 

Index: backend/sound_handler_gst.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- backend/sound_handler_gst.cpp       20 Sep 2006 06:29:41 -0000      1.18
+++ backend/sound_handler_gst.cpp       7 Oct 2006 14:20:27 -0000       1.19
@@ -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.18 2006/09/20 06:29:41 nihilus Exp $ */
+/* $Id: sound_handler_gst.cpp,v 1.19 2006/10/07 14:20:27 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -28,7 +28,7 @@
 // (HAVE_GST_GST_H seems broken atm, specifically when an older glib
 //  install is around)
 //
-//#ifdef HAVE_GST_GST_H
+
 #ifdef SOUND_GST
 #include "gnash.h"
 #include "container.h"
@@ -256,7 +256,7 @@
 
 
        // this gets called when a stream gets more data
-       virtual long    fill_stream_data(void* data, int data_bytes, int 
handle_id)
+       virtual long    fill_stream_data(void* data, int data_bytes, int 
/*sample_count*/, int handle_id)
        {
                
                // @@ does a negative handle_id have any meaning ?
@@ -648,6 +648,16 @@
 
        }
 
+       virtual void 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())
+               {
+                       *format = m_sound_data[sound_handle]->format;
+                       *stereo = m_sound_data[sound_handle]->stereo;
+               } 
+
+       }
 
 };
 

Index: backend/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- backend/sound_handler_sdl.cpp       20 Sep 2006 06:08:18 -0000      1.20
+++ backend/sound_handler_sdl.cpp       7 Oct 2006 14:20:27 -0000       1.21
@@ -1,106 +1,160 @@
-// sound_handler_sdl.cpp       -- Thatcher Ulrich http://tulrich.com 2003
+//   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
+//
 
-// This source code has been donated to the Public Domain.  Do
-// whatever you want with it.
-
-// A sound_handler that uses SDL_mixer for output
-
-/* $Id: sound_handler_sdl.cpp,v 1.20 2006/09/20 06:08:18 nihilus Exp $ */
+// Based on sound_handler_sdl.cpp by Thatcher Ulrich http://tulrich.com 2003
+// which has been donated to the Public Domain.
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-//#ifdef HAVE_SDL_MIXER_H
 #ifdef SOUND_SDL
 #include "gnash.h"
 #include "container.h"
-#include "SDL_mixer.h"
 #include "log.h"
 #include "types.h"     // for IF_VERBOSE_* macros
+#include <pthread.h>
+#include <cmath>
+#include <vector>
+
+#ifdef USE_FFMPEG
+#include <ffmpeg/avcodec.h>
+#include <ffmpeg/avformat.h>
+#elif defined(USE_MAD)
+#include <mad.h>
+#endif
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_audio.h>
+
+void sdl_audio_callback(void *udata, Uint8 *stream, int len); // SDL C audio 
handler
+
+// Used to hold the info about active sounds
+typedef struct
+{
+#ifdef USE_FFMPEG
+       // ffmpeg stuff
+       AVCodec *codec;
+       AVCodecContext *cc;
+#elif defined(USE_MAD)
+       // mad stuff
+       mad_stream      stream;
+       mad_frame       frame;
+       mad_synth       synth;
+#endif
+
+       // data size
+       long data_size;
+
+       // position in the stream
+       long position;
+
+       // The compressed data
+       Uint8* data;
+
+       // data size
+       long raw_data_size;
+
+       // position in the raw stream
+       long raw_position;
+
+       // The decompressed data
+       Uint8* raw_data;
+
+       long loop_count;
+       
+} active_sound;
+
+
+// Used to hold the sounddata when doing on-demand-decoding
+typedef struct
+{
+       // The (un)compressed data
+       Uint8* 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;
 
-using namespace gnash;
+       // Volume, SWF range: 0-100, SDL range 0-128
+       // It's the SWF range that is represented here
+       int volume;
 
-// Use SDL_mixer to handle sounds.
+       // active sounds being playes
+       std::vector<active_sound*>      m_active_sounds;
+
+} sound_data;
+
+// Use SDL and ffmpeg/mad/nothing to handle sounds.
 class SDL_sound_handler : public gnash::sound_handler
 {
 public:
-       bool    m_opened;
-       bool    m_stereo;
-       int     m_sample_rate;
-       uint16_t m_format;
-       std::vector<Mix_Chunk*> m_samples;
-
-       #define SAMPLE_RATE 44100
-       #define MIX_CHANNELS 8
-       #define CHANNELS 2              //stereo - 2, mono - 1
-       #define BUFSIZE 4096            // for 44100 bufsize 1024 is small
+       // Sound data.
+       std::vector<sound_data*>        m_sound_data;
+
+       // Is sound device opened?
+       bool soundOpened;
+
+       // SDL_audio specs
+       SDL_AudioSpec audioSpec;
+       
+       // Keeps track of numbers of playing sounds
+       int soundsPlaying;
+       
+       // mutex for making sure threads doesn't mess things up
+       pthread_mutex_t mutex;
 
        SDL_sound_handler()
-               :
-               m_opened(false),
-               m_stereo(false),
-               m_sample_rate(0),
-               m_format(0)
+               : soundOpened(false),
+                 soundsPlaying(0)
        {
-               // !!! some drivers on Linux always open audio with channels=2
-               if (Mix_OpenAudio(SAMPLE_RATE, AUDIO_S16SYS, CHANNELS, BUFSIZE) 
!= 0)
-               {
-                       gnash::log_error("can't open SDL_mixer: %s\n", 
Mix_GetError());
-               }
-               else
-               {
-                       m_opened = true;     
-                       Mix_AllocateChannels(MIX_CHANNELS);
-                       Mix_Volume(-1, MIX_MAX_VOLUME);
-
-                       // get and print the audio format in use
-                       int channels;
-                       int num_times_opened = Mix_QuerySpec(&m_sample_rate, 
&m_format, &channels);
-                       UNUSED(num_times_opened);
-                       m_stereo = channels == 2 ? true : false;
-                       
-                       const char *format_str = "Unknown";
-                       switch (m_format)
-                       {
-                       case AUDIO_U8: format_str = "U8"; break;
-                       case AUDIO_S8: format_str = "S8"; break;
-                       case AUDIO_U16LSB: format_str = "U16LSB"; break;
-                       case AUDIO_S16LSB: format_str = "S16LSB"; break;
-                       case AUDIO_U16MSB: format_str = "U16MSB"; break;
-                       case AUDIO_S16MSB: format_str = "S16MSB"; break;
-                       }
-           
-                       // @@ Usually I don't care about this.  Need a 
IF_VERBOSE_SOUND or something.
-                       // IF_VERBOSE_DEBUG(
-                       //      gnash::log_msg("SDL_mixer: opened %d times, 
frequency=%dHz, format=%s, stereo=%s\n",
-                       //                   num_times_opened,
-                       //                   m_sample_rate,
-                       //                   format_str,
-                       //                   m_stereo ? "yes" : "no"));
-                       // char name[32];
-                       // IF_VERBOSE_DEBUG(
-                       //      gnash::log_msg("Using audio driver: %s\n", 
SDL_AudioDriverName(name, 32)));
-               }
+               // Init mutex
+               pthread_mutex_init(&mutex , NULL);
+
+               // This is our sound settings
+               audioSpec.freq = 44100;
+               audioSpec.format = AUDIO_S16SYS; // AUDIO_S8 AUDIO_U8;
+               audioSpec.channels = 2;
+               audioSpec.callback = sdl_audio_callback;
+               audioSpec.userdata = this;
+               audioSpec.samples = 512;
        }
 
        ~SDL_sound_handler()
        {
-               if (m_opened)
-               {
-                       Mix_CloseAudio();
-                       for (int i = m_samples.size() - 1; i >= 0; i--) 
//Optimized
-                       {
-                               if (m_samples[i])
-                               {
-                                       Mix_FreeChunk(m_samples[i]);
-                               }
-                       }
-               }
-               else
-               {
-                       assert(m_samples.size() == 0);
+
+               for (size_t i= m_sound_data.size(); i > 0; i--) {
+                       stop_sound(i);
+                       delete_sound(i);
                }
+               if (soundOpened) SDL_CloseAudio();
+               pthread_mutex_destroy(&mutex);
+
        }
 
 
@@ -112,145 +166,366 @@
                int sample_rate,
                bool stereo)
        // Called to create a sample.  We'll return a sample ID that
-       // can use for playing it.
-       {
-               if (m_opened == false)
+       // can be use for playing it.
                {
-                       return 0;
+
+               sound_data *sounddata = new sound_data;
+               if (!sounddata) {
+                       gnash::log_error("could not allocate memory for 
sounddata !\n");
+                       return -1;
                }
 
+               sounddata->format = format;
+               sounddata->data_size = data_bytes;
+               sounddata->stereo = stereo;
+               sounddata->sample_count = sample_count;
+               sounddata->sample_rate = sample_rate;
+               sounddata->volume = 100;
+
                int16_t*        adjusted_data = 0;
                int     adjusted_size = 0;
-               Mix_Chunk*      sample = 0;
+
+               pthread_mutex_lock(&mutex);
 
                switch (format)
                {
                case FORMAT_RAW:
+
+                       if (data_bytes > 0) {
                        convert_raw_data(&adjusted_data, &adjusted_size, data, 
sample_count, 1, sample_rate, stereo);
+                               if (!adjusted_data) { 
+                                       gnash::log_error("Some kind of error 
with raw sound data\n");
+                                       pthread_mutex_unlock(&mutex);
+                                       return -1;
+                               }
+                               sounddata->data_size = adjusted_size;
+                               sounddata->data = (Uint8*) adjusted_data;
+                       }
                        break;
 
                case FORMAT_NATIVE16:
+
+                       if (data_bytes > 0) {
                        convert_raw_data(&adjusted_data, &adjusted_size, data, 
sample_count, 2, sample_rate, stereo);
+                               if (!adjusted_data) { 
+                                       gnash::log_error("Some kind of error 
with adpcm sound data\n");
+                                       pthread_mutex_unlock(&mutex);
+                                       return -1;
+                               }
+                               sounddata->data_size = adjusted_size;
+                               sounddata->data = (Uint8*) adjusted_data;
+                       }
                        break;
 
                case FORMAT_MP3:
-#ifdef HAVE_MAD_H
-                       extern void convert_mp3_data(int16_t **adjusted_data, 
int *adjusted_size, void *data, const int sample_count, const int sample_size, 
const int sample_rate, const bool stereo);
-                       if (1) {
-                               int16_t*        x_adjusted_data = 0;
-                               int     x_adjusted_size = 0;
-//                             Mix_Chunk*      x_sample = 0;
-                               convert_mp3_data(&x_adjusted_data, 
&x_adjusted_size, data, sample_count, 0, sample_rate, stereo);
-                               /* convert_mp3_data doesn't ACTUALLY convert
-                                  samplerate, so... */
-                               convert_raw_data(&adjusted_data, 
&adjusted_size, x_adjusted_data, sample_count, 0, sample_rate, stereo);
-                               if (x_adjusted_data) {
-                                       delete x_adjusted_data;
-                               }
-                       } else {
-                               convert_mp3_data(&adjusted_data, 
&adjusted_size, data, sample_count, 0, sample_rate, stereo);
-                       }
-#else
-                       log_error("SDL sound handler: mp3 sound requested, but 
MAD support was not compiled in\n");
+               //case FORMAT_VORBIS:
+#ifndef USE_FFMPEG
+#ifndef USE_MAD
+                       gnash::log_warning("gnash has not been compiled to 
handle mp3 audio\n");
+                       pthread_mutex_unlock(&mutex);
+                       return -1;
 #endif
-                       break;
+#endif
+                       sounddata->data = new Uint8[data_bytes];
+                       if (!sounddata->data) { 
+                               gnash::log_error("could not allocate space for 
data in soundhandler\n");
+                               pthread_mutex_unlock(&mutex);
+                               return -1;
+                       }
+                       memcpy(sounddata->data, data, data_bytes);
 
+                       break;
                default:
                        // Unhandled format.
-                       log_error("SDL sound handler: unknown format sound 
requested\n");
-                       break;
+                       gnash::log_error("unknown format sound requested; gnash 
does not handle it\n");
+                       pthread_mutex_unlock(&mutex);
+                       return -1; // Unhandled format, set to NULL.
                }
 
-               if (adjusted_data)
-               {
-                       sample = Mix_QuickLoad_RAW((unsigned char*) 
adjusted_data, adjusted_size);
-                       Mix_VolumeChunk(sample, MIX_MAX_VOLUME);        // full 
volume by default
-               }
+               m_sound_data.push_back(sounddata);
+               int sound_id = m_sound_data.size()-1;
+
+               pthread_mutex_unlock(&mutex);
+
+               return sound_id;
 
-               m_samples.push_back(sample);
-               return m_samples.size() - 1;
        }
 
-       virtual void    play_sound(int sound_handle, int loop_count, int 
secondOffset, long start_position)
-       // Play the index'd sample.
-       {
-         if (m_opened && (sound_handle >= 0) &&  (unsigned int) sound_handle < 
m_samples.size())
+       // 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)
                {
-                       if (m_samples[sound_handle])
+
+               pthread_mutex_lock(&mutex);             
+               // @@ does a negative handle_id have any meaning ?
+               //    should we change it to unsigned instead ?
+               if (handle_id < 0 || (unsigned int) handle_id+1 > 
m_sound_data.size()) {
+                       pthread_mutex_unlock(&mutex);
+                       return 1;
+               }
+               int start_size = 0;
+
+               // Handling of the sound data
+               if (m_sound_data[handle_id]->format == FORMAT_NATIVE16)
                        {
-                               // Play this sample on the first available 
channel.
-                               Mix_PlayChannel(-1, m_samples[sound_handle], 
loop_count);
+                       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);
+                       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_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]->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]->raw_data = 
m_sound_data[handle_id]->data;
+                       }
+               } else if (m_sound_data[handle_id]->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;
+
+                       // 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]->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;
+#ifdef USE_MAD
+                               uint64_t this_frame = (const 
Uint8*)m_sound_data[handle_id]->m_active_sounds[i]->stream.this_frame - 
m_sound_data[handle_id]->m_active_sounds[i]->data;
+                               uint64_t next_frame = (const 
Uint8*)m_sound_data[handle_id]->m_active_sounds[i]->stream.next_frame - 
m_sound_data[handle_id]->m_active_sounds[i]->data;
+                               
mad_stream_buffer(&m_sound_data[handle_id]->m_active_sounds[i]->stream, 
m_sound_data[handle_id]->data, m_sound_data[handle_id]->data_size);
+                               
m_sound_data[handle_id]->m_active_sounds[i]->stream.this_frame += this_frame;
+                               
m_sound_data[handle_id]->m_active_sounds[i]->stream.next_frame += next_frame;
+#endif
                        }
+
+               } else {
+                       gnash::log_error("Behavior for this codec is unknown. 
Please send this SWF to the developers\n");
                }
+               
+               pthread_mutex_unlock(&mutex);
+               return start_size;
+
+
        }
 
-       virtual void    stop_all_sounds()
-       {
-               if (m_opened)
-               {
-                       for (int i = 0; i < MIX_CHANNELS; i++)
+
+       virtual void    play_sound(int sound_handle, int loop_count, int 
/*offset*/, long start_position)
+       // Play the index'd sample.
                        {
-                               if (Mix_Playing(i))
+               pthread_mutex_lock(&mutex);
+
+               // Check if the sound exists.
+               if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size())
                                {
-                                       Mix_HaltChannel(i);
+                       // Invalid handle.
+                       pthread_mutex_unlock(&mutex);
+                       return;
+               }
+               
+               // 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) {
+                       pthread_mutex_unlock(&mutex);
+                       return;
+               }
+
+               // Make a "active_sound" for this sound which is later placed 
on the vector of instances of this sound being played
+               active_sound* sound = new active_sound;
+
+               // Copy data-info to the active_sound
+               sound->data_size = m_sound_data[sound_handle]->data_size;
+               sound->data = m_sound_data[sound_handle]->data;
+               sound->position = start_position;
+               if (start_position < 0) sound->position = 0;
+
+
+               // 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) { 
+
+#ifdef USE_FFMPEG
+                       // Init the avdecoder-decoder
+                       avcodec_init();
+                       avcodec_register_all();// change this to only register 
mp3?
+                       sound->codec = avcodec_find_decoder(CODEC_ID_MP3);
+               
+                       if (!sound->codec) {
+                               gnash::log_error("Your FFMPEG can't decode 
MP3?!\n");
+                               pthread_mutex_unlock(&mutex);
+                               return;
+                       }
+
+                       sound->raw_data = new 
uint8[AVCODEC_MAX_AUDIO_FRAME_SIZE];
+                       memset((void*)sound->raw_data, 0, 
AVCODEC_MAX_AUDIO_FRAME_SIZE);
+                       sound->raw_position = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+                       sound->raw_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+                       sound->cc = avcodec_alloc_context();
+                       avcodec_open(sound->cc, sound->codec);
+#elif defined(USE_MAD)
+                       // Init the mad decoder
+                       mad_stream_init(&sound->stream);
+                       mad_frame_init(&sound->frame);
+                       mad_synth_init(&sound->synth);
+                       mad_stream_buffer(&sound->stream, sound->data, 
sound->data_size);
+
+                       sound->raw_data = 0;
+                       sound->raw_data_size = 0;
+                       sound->raw_position = 0;
+#endif
+               } else {
+                       sound->raw_data_size = 
m_sound_data[sound_handle]->data_size;
+                       sound->raw_data = m_sound_data[sound_handle]->data;
+                       sound->raw_position = 0;
+                       sound->position = m_sound_data[sound_handle]->data_size;
+               
+               }
+
+               if (!soundOpened) {
+                       if (SDL_OpenAudio(&audioSpec, NULL) < 0 ) {
+                               gnash::log_error("Unable to START SOUND: %s\n", 
SDL_GetError());
+                               pthread_mutex_unlock(&mutex);
+                               return;
                                }
+                       soundOpened = true;
+
+
                        }
+               
+               ++soundsPlaying;
+               m_sound_data[sound_handle]->m_active_sounds.push_back(sound);
+
+               if (soundsPlaying == 1) {
+                       SDL_PauseAudio(0);
                }
+
+               pthread_mutex_unlock(&mutex);
+
        }
 
-       virtual int     get_volume(int sound_handle)
+
+       virtual void    stop_sound(int sound_handle)
        {
-               int previous_volume = 100;
-               if (m_opened && (sound_handle >= 0) && (unsigned int) 
sound_handle < m_samples.size())
+               pthread_mutex_lock(&mutex);
+               
+               // Check if the sound exists.
+               if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size())
                {
-                       //      if you passed a negative value for volume then
-                       //      this volume is still the current volume for the 
chunk
-                       previous_volume = 
Mix_VolumeChunk(m_samples[sound_handle], -1);
+                       // Invalid handle.
+               } else {
+
+                       for (uint32_t i = 0; i < 
m_sound_data[sound_handle]->m_active_sounds.size(); i++) {
+                               
m_sound_data[sound_handle]->m_active_sounds[i]->position = 
m_sound_data[sound_handle]->m_active_sounds[i]->data_size;
+                               
m_sound_data[sound_handle]->m_active_sounds[i]->raw_position = 
m_sound_data[sound_handle]->m_active_sounds[i]->raw_data_size;
+                               
m_sound_data[sound_handle]->m_active_sounds[i]->loop_count = 0;
+                       }
                }
-               return previous_volume;
+               pthread_mutex_unlock(&mutex);
+
        }
 
-       virtual void    set_volume(int sound_handle, int volume)
+
+       virtual void    delete_sound(int sound_handle)
+       // this gets called when it's done with a sample.
        {
-               if (m_opened && sound_handle >= 0 && (unsigned int) 
sound_handle < m_samples.size())
+               pthread_mutex_lock(&mutex);
+               
+               if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
                {
-                       int vol = (MIX_MAX_VOLUME / 100) * volume;
-                       Mix_VolumeChunk(m_samples[sound_handle], vol);
+                       delete[] m_sound_data[sound_handle]->data;
                }
+               pthread_mutex_unlock(&mutex);
+
        }
        
-       virtual void    stop_sound(int sound_handle)
-       {
-               if (m_opened && sound_handle >= 0 && (unsigned int) 
sound_handle < m_samples.size())
-               {
-                       for (int i = 0; i < MIX_CHANNELS; i++)
+       // 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()
                        {
-                               Mix_Chunk*      playing_chunk = Mix_GetChunk(i);
-                               if (playing_chunk == m_samples[sound_handle])
+               int num_sounds = m_sound_data.size();
+               for (size_t i = num_sounds; i > 0; i--) //Optimized
+                       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) {
+       
+               pthread_mutex_lock(&mutex);
+
+               int ret;
+               // Check if the sound exists.
+               if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
                                {
-                                       // Stop this channel.
-                                       Mix_HaltChannel(i);
+                       ret = m_sound_data[sound_handle]->volume;
+               } else {
+                       ret = 0; // Invalid handle
                                }
+               pthread_mutex_unlock(&mutex);
+               return ret;
                        }
+       
+
+       //      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) {
+
+               pthread_mutex_lock(&mutex);
+
+               // Check if the sound exists.
+               if (sound_handle < 0 || (unsigned int) sound_handle >= 
m_sound_data.size())
+               {
+                       // Invalid handle.
+               } else {
+
+                       // Set volume for this sound. Should this only apply to 
the active sounds?
+                       m_sound_data[sound_handle]->volume = volume;
                }
+               pthread_mutex_unlock(&mutex);
+
+
        }
 
+       virtual void get_info(int sound_handle, int* format, bool* stereo) {
 
-       virtual void    delete_sound(int sound_handle)
-       // this gets called this when it's done with a sample.
-       {
-         if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_samples.size())
-               {
-                       Mix_Chunk*      chunk = m_samples[sound_handle];
-                       if (chunk)
+               pthread_mutex_lock(&mutex);
+
+               // Check if the sound exists.
+               if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
                        {
-                               delete [] (chunk->abuf);
-                               Mix_FreeChunk(chunk);
-                               m_samples[sound_handle] = 0;
-                       }
+                       *format = m_sound_data[sound_handle]->format;
+                       *stereo = m_sound_data[sound_handle]->stereo;
                }
+
+               pthread_mutex_unlock(&mutex);
        }
 
+
        virtual void convert_raw_data(
                int16_t** adjusted_data,
                int* adjusted_size,
@@ -274,6 +549,9 @@
 //             }
 //             // xxxxx
 
+               bool m_stereo = (audioSpec.channels == 2 ? true : false);
+               int m_sample_rate = audioSpec.freq;
+
                // simple hack to handle dup'ing mono to stereo
                if ( !stereo && m_stereo)
                {
@@ -334,6 +612,8 @@
                }
        }
 
+
+
 };
 
 
@@ -343,8 +623,232 @@
        return new SDL_sound_handler;
 }
 
+// The callback function which refills the buffer with data
+void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length)
+{
+       // We run through all of the sounds, and mix all of the active sounds 
+       // into the stream given by the callback.
+       // If a sound is looping it will be decoded from the beginning again.
+       // When a sound is finished the empty space in the stream will be set 
to 0.
+
+       SDL_sound_handler* handler = static_cast<SDL_sound_handler*>(udata);
+
+       // If nothing to play there is no reason to play
+       // Is this a potential deadlock problem?
+       if (handler->soundsPlaying == 0) {
+               SDL_PauseAudio(1);
+               return;
+       }
+
+       pthread_mutex_lock(&handler->mutex);
+       
+       // Mixed sounddata buffer
+       Uint8* buffer = stream;  //new Uint8[len];
+       memset(buffer, 0, buffer_length);
+
+       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++) {
+
+                       active_sound* sound = 
handler->m_sound_data[i]->m_active_sounds[j];
+
+                       // When the current sound dont have enough decoded data 
to fill the buffer, 
+                       // we first mix what is alreadt decoded, then decode 
some more data, and
+                       // mix some more until the buffer is full. If a sound 
loops the magic
+                       // happens here ;)
+                       if (sound->raw_data_size - sound->raw_position < 
buffer_length 
+                               && (sound->position < sound->data_size || 
sound->loop_count != 0)) {
+
+                               // First we mix what is decoded
+                               int index = 0;
+                               if (sound->raw_data_size - sound->raw_position 
> 0) {
+                                       SDL_MixAudio(stream, (const 
Uint8*)(sound->raw_data + sound->raw_position), 
+                                               sound->raw_data_size - 
sound->raw_position,
+                                               SDL_MIX_MAXVOLUME);
+                                       index = sound->raw_data_size - 
sound->raw_position;
+                               }
+                               sound->raw_position += index;
+
+                               // Then we decode some data
+                               int outsize = 0;        
+#ifdef USE_FFMPEG
+                               // If we need to loop, we reset the data pointer
+                               if (sound->data_size == sound->position && 
sound->loop_count != 0) {
+                                       sound->loop_count--;
+                                       sound->position = 0;
+                               }
+                               
+                               memset(sound->raw_data, 0, 
sound->raw_data_size);
+                               int bytes_decoded = 
avcodec_decode_audio(sound->cc, 
+                                               (int16_t *)sound->raw_data, 
+                                               &outsize, 
+                                               (uint8_t *)(sound->data + 
sound->position), 
+                                               //AVCODEC_MAX_AUDIO_FRAME_SIZE);
+                                               sound->data_size - 
sound->position);
+
+                               if (bytes_decoded < 0) {
+                                       gnash::log_error("Error while decoding 
MP3-stream\n");
+                                       // TODO: Remove the sound from the 
active list
+                                       sound->position = sound->data_size;
+                                       continue;
+                               }
+
+                               sound->position += bytes_decoded;
+
+#elif defined(USE_MAD)
+                               // If we need to loop, we reset the data 
pointer, and tell mad about it
+                               if (sound->data_size == sound->position && 
sound->loop_count != 0) {
+                                       sound->position = 0;
+                                       mad_stream_buffer(&sound->stream, 
sound->data, sound->data_size);
+                                       sound->loop_count--;
+                               }
+
+                               int ret;
+                               while(true) {
+                                       ret = mad_frame_decode(&sound->frame, 
&sound->stream);
+                                       
+                                       // There is always some junk in front 
of the data, 
+                                       // so we continue until we get past it.
+                                       if (ret && sound->stream.error == 
MAD_ERROR_LOSTSYNC) continue;
+                                       
+                                       break;
+                               }
+
+                               if (ret == -1 && sound->stream.error != 
MAD_ERROR_BUFLEN) {
+                                       gnash::log_error("Error while decoding 
MP3-stream, MAD error: %d", sound->stream.error);
+                                       continue;
+                               } else if (ret == -1 && sound->stream.error == 
MAD_ERROR_BUFLEN) {
+                                       // the buffer is empty, no more to 
decode!
+                                       sound->position = sound->data_size;
+                               } else {
+                                       sound->position += 
sound->stream.next_frame - sound->stream.buffer - sound->position;
+                               }
+
+                               mad_synth_frame (&sound->synth, &sound->frame);
+                               
+                               outsize = sound->synth.pcm.length * 
((handler->m_sound_data[i]->stereo == true) ? 4 : 2);
+
+                               if (sound->raw_data) delete[] sound->raw_data;
+                               sound->raw_data = new Uint8[outsize];
+                               int sample;
+                               
+                               int16_t* dst = (int16_t*) sound->raw_data;
+
+                               // 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)
+
+                                               mad_fixed_t mad_sample = 
sound->synth.pcm.samples[e][f];
+
+                                               // round
+                                               mad_sample += (1L << 
(MAD_F_FRACBITS - 16));
+
+                                               // clip
+                                               if (mad_sample >= MAD_F_ONE) 
mad_sample = MAD_F_ONE - 1;
+                                               else if (mad_sample < 
-MAD_F_ONE) mad_sample = -MAD_F_ONE;
+
+                                               // quantize
+                                               sample = mad_sample >> 
(MAD_F_FRACBITS + 1 - 16);
+
+                                               if ( sample != (int16_t)sample 
) sample = sample < 0 ? -32768 : 32767;
+
+                                               *dst++ = sample;
+                                       }
+                               }
+                               
+#endif
+                               // If we need to convert samplerate...
+                               if (outsize > 0 && 
handler->m_sound_data[i]->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);
+
+                                       // Convert to needed samplerate
+                                       
handler->convert_raw_data(&adjusted_data, &adjusted_size, sound->raw_data, 
sample_count, 0, 
+                                                       
handler->m_sound_data[i]->sample_rate, handler->m_sound_data[i]->stereo);
+
+                                       // Hopefully this wont happen
+                                       if (!adjusted_data) { 
+                                               continue;
+                                       }
+
+                                       // Move the new data to the sound-struct
+                                       if (sound->raw_data) delete[] 
sound->raw_data;
+                                       sound->raw_data = new 
Uint8[adjusted_size];
+                                       memcpy(sound->raw_data, adjusted_data, 
adjusted_size);
+                                       sound->raw_data_size = adjusted_size;
+                                       delete[] adjusted_data;
+
+                               } else {
+                                       sound->raw_data_size = outsize;
+                               }
+                               
+                               sound->raw_position = 0;
+
+
+                               // Then we mix the newly decoded data
+                               SDL_MixAudio((Uint8*)(stream+index),(const 
Uint8*) sound->raw_data, 
+                                               buffer_length - index,
+                                               SDL_MIX_MAXVOLUME);
+                               sound->raw_position = buffer_length - index;
+                               
+                       // 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 ) {
+                       
+                               // Mix the raw data
+                               SDL_MixAudio((Uint8*)(stream),(const Uint8*) 
(sound->raw_data + sound->raw_position), 
+                                               buffer_length,
+                                               SDL_MIX_MAXVOLUME);
+                               sound->raw_position += buffer_length;
+
+                       // When the current sound doesn't have anymore data to 
decode,
+                       // and doesn't loop (anymore), but still got unplayed 
data,
+                       // we put the last data on the stream
+                       } else if (sound->raw_data_size - sound->raw_position < 
buffer_length && sound->raw_data_size > sound->raw_position) {
+                       
+                               // Mix the remaining data
+                               SDL_MixAudio((Uint8*)(stream),(const Uint8*) 
(sound->raw_data + sound->raw_position), 
+                                               sound->raw_data_size - 
sound->raw_position,
+                                               SDL_MIX_MAXVOLUME);
+                               sound->raw_position = sound->raw_data_size;
+
+                       } else {
+                       }
+                       
+                       // 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) {
+#ifdef USE_FFMPEG
+                               avcodec_close(sound->cc);
+#elif defined(USE_MAD)
+                               mad_synth_finish(&sound->synth);
+                               mad_frame_finish(&sound->frame);
+                               mad_stream_finish(&sound->stream);
+#endif
+                               delete[] sound->raw_data;
+                               
handler->m_sound_data[i]->m_active_sounds.erase(handler->m_sound_data[i]->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);
+                               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);
+                               handler->soundsPlaying--;
+                       }
+
+               }
+       }
+       pthread_mutex_unlock(&handler->mutex);
+
+}
+
 #endif
 
 // Local Variables:
 // mode: C++
 // End:
+

Index: macros/ffmpeg.m4
===================================================================
RCS file: /sources/gnash/gnash/macros/ffmpeg.m4,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- macros/ffmpeg.m4    7 Oct 2006 02:54:24 -0000       1.3
+++ macros/ffmpeg.m4    7 Oct 2006 14:20:27 -0000       1.4
@@ -131,6 +131,8 @@
       FFMPEG_LIBS="${ac_cv_path_ffmpeg_lib} -lavcodec -lavutil"
   fi
 
+  AC_DEFINE([USE_FFMPEG],  [1], [Use FFMPEG for MP3 decoding])
+  
   AC_SUBST(FFMPEG_LIBS)
 
 ])

Index: macros/mad.m4
===================================================================
RCS file: /sources/gnash/gnash/macros/mad.m4,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- macros/mad.m4       9 Aug 2006 01:59:07 -0000       1.10
+++ macros/mad.m4       7 Oct 2006 14:20:27 -0000       1.11
@@ -35,16 +35,16 @@
 dnl  
 dnl 
 
-AC_DEFUN([GNASH_PATH_MP3],
+AC_DEFUN([GNASH_PATH_MAD],
 [
-  AC_ARG_ENABLE(mp3, [  --enable-mp3            Enable support for playing 
mp3s],
+  AC_ARG_ENABLE(mad, [  --enable-mad            Enable support for decoding 
mp3 with mad],
   [case "${enableval}" in
-    yes) mp3=yes ;;
-    no)  mp3=no ;;
-    *)   AC_MSG_ERROR([bad value ${enableval} for enable-mp3 option]) ;;
-  esac], mp3=no)
+    yes) mad=yes ;;
+    no)  mad=no ;;
+    *)   AC_MSG_ERROR([bad value ${enableval} for enable-mad option]) ;;
+  esac], mad=no)
 
-  if test x"$mp3" = x"yes"; then
+  if test x"$mad" = x"yes"; then
     dnl Look for the header
   AC_ARG_WITH(mad_incl, [  --with-mad_incl         directory where libmad 
header is], with_mad_incl=${withval})
     AC_CACHE_VAL(ac_cv_path_mad_incl,[
@@ -142,9 +142,10 @@
 
   if test x"${ac_cv_path_mad_lib}" != x ; then
       MAD_LIBS="${ac_cv_path_mad_lib}"
+      AC_DEFINE([USE_MAD],  [1], [Use MAD for MP3 decoding])
   fi
 
-  AM_CONDITIONAL(MP3, [test x$mp3 = xyes])
+  AM_CONDITIONAL(HAVE_MAD, [test x$mad = xyes])
 
   AC_SUBST(MAD_CFLAGS)
   AC_SUBST(MAD_LIBS)

Index: plugin/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/plugin/Makefile.am,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- plugin/Makefile.am  4 Oct 2006 05:13:00 -0000       1.45
+++ plugin/Makefile.am  7 Oct 2006 14:20:27 -0000       1.46
@@ -43,11 +43,6 @@
 endif
 SUBDIRS = $(KLASH) # test mozilla-sdk
 
-if MP3
-MP3_CFLAGS = $(MAD_CFLAGS)
-MP3_LIBS = $(MAD_LIBS)
-endif
-
 # if DMALLOC
 # MALL_CFLAGS = $(DMALLOC_CFLAGS)
 # MALL_LIBS = $(DMALLOC_LIBS)
@@ -71,10 +66,8 @@
        $(CAIRO_CFLAGS) \
        $(ATK_CFLAGS) \
        $(SDL_CFLAGS) \
-       $(SDL_MIXER_CFLAGS) \
        $(X_CFLAGS) \
        $(DMALLOC_CFLAGS) \
-       $(MP3_CFLAGS) \
        $(OGG_CFLAGS)
 
 

Index: server/gnash.h
===================================================================
RCS file: /sources/gnash/gnash/server/gnash.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- server/gnash.h      2 Oct 2006 11:33:08 -0000       1.56
+++ server/gnash.h      7 Oct 2006 14:20:27 -0000       1.57
@@ -35,7 +35,7 @@
 // 
 //
 
-/* $Id: gnash.h,v 1.56 2006/10/02 11:33:08 nihilus Exp $ */
+/* $Id: gnash.h,v 1.57 2006/10/07 14:20:27 tgc Exp $ */
 
 /// \mainpage
 ///
@@ -432,12 +432,14 @@
                int             sample_rate,    /* one of 5512, 11025, 22050, 
44100 */
                bool            stereo
                ) = 0;
-#ifdef SOUND_GST
+
        // gnash calls this to fill up soundstreams data
-       virtual long    fill_stream_data(void* data, int data_bytes, int 
handle_id) = 0;
-#endif
+       virtual long    fill_stream_data(void* data, int data_bytes, int 
sample_count, int handle_id) = 0;
+
+       //      Gives info about the format, samplerate and stereo of the sound 
in question;
+       virtual void get_info(int sound_handle, int* format, bool* stereo) = 0;
+
        // gnash calls this when it wants you to play the defined sound.
-       //
        // loop_count == 0 means play the sound once (1 means play it twice, 
etc)
        virtual void    play_sound(int sound_handle, int loop_count, int 
secondOffset, long start) = 0;
 

Index: server/swf/tag_loaders.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf/tag_loaders.cpp,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- server/swf/tag_loaders.cpp  2 Oct 2006 17:14:41 -0000       1.52
+++ server/swf/tag_loaders.cpp  7 Oct 2006 14:20:27 -0000       1.53
@@ -36,7 +36,7 @@
 //
 //
 
-/* $Id: tag_loaders.cpp,v 1.52 2006/10/02 17:14:41 strk Exp $ */
+/* $Id: tag_loaders.cpp,v 1.53 2006/10/07 14:20:27 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1684,8 +1684,6 @@
        // If we don't have a sound_handler registered stop here
        if (!s_sound_handler) return;
 
-#ifdef SOUND_GST
-
        // FIXME:
        // no character id for soundstreams... so we make one up... 
        // This only works if there is only one stream in the movie...
@@ -1723,6 +1721,9 @@
                return;
        }
 
+       // Since the ADPCM is converted to NATIVE16, the format is set to 
that...
+       if (format == sound_handler::FORMAT_ADPCM) format = 
sound_handler::FORMAT_NATIVE16;
+
        int     handler_id = s_sound_handler->create_sound(
                NULL,
                data_bytes,
@@ -1732,15 +1733,6 @@
                stereo);
        m->set_loading_sound_stream_id(handler_id);
 
-#else
-       static bool already_warned=false;
-       if ( ! already_warned )
-       {
-               log_warning("Only Gstreamer sound backend "
-                       "supports SoundStreamHead tag");
-               already_warned=true;
-       }
-#endif
 }
 
 
@@ -1752,9 +1744,6 @@
 
        assert(tag == SWF::SOUNDSTREAMBLOCK); // 19
 
-#ifdef SOUND_GST
-
-
        // discard garbage data
        //int   garbage = in->read_u32();
        in->skip_bytes(4);
@@ -1763,6 +1752,8 @@
        // If we don't have a sound_handler registered stop here
        if (!s_sound_handler) return;
 
+       int handle_id = m->get_loading_sound_stream_id();
+
        // store the data with the appropiate sound.
        int     data_bytes = 0;
 
@@ -1770,18 +1761,59 @@
        data_bytes = in->get_tag_end_position() - in->get_position();
 
        if (data_bytes <= 0) return;
-       
        unsigned char *data = new unsigned char[data_bytes];
+
+
+       int format = 0;
+       bool stereo = true;
+       int sample_count = -1;
+       
+       s_sound_handler->get_info(handle_id, &format, &stereo);
+
+       if (format == sound_handler::FORMAT_ADPCM)
+       {
+               // Uncompress the ADPCM before handing data to host.
+               sample_count =  data_bytes / (stereo ? 4 : 2);
+               data_bytes = sample_count * (stereo ? 4 : 2);
+               data = new unsigned char[data_bytes];
+               sound_handler::adpcm_expand(data, in, sample_count, stereo);
+               format = sound_handler::FORMAT_NATIVE16;
+       } else if (format == sound_handler::FORMAT_NATIVE16)
+       {
+               // Raw data
+               sample_count =  data_bytes / (stereo ? 4 : 2);
        for (int i = 0; i < data_bytes; i++)
        {
                data[i] = in->read_u8();
        }
 
-       int handle_id = m->get_loading_sound_stream_id();
+       } else {
+       
+               for (int i = 0; i < data_bytes; i++)
+               {
+                       data[i] = in->read_u8();
+               }
+
+               // Swap bytes on behalf of the host, to make it easier for the 
handler.
+               // @@ I'm assuming this is a good idea?  Most sound handlers 
will prefer native endianness?
+               /*if (format == sound_handler::FORMAT_UNCOMPRESSED && 
sample_16bit)
+               {
+                       #ifndef _TU_LITTLE_ENDIAN_
+                       // Swap sample bytes to get big-endian format.
+                       for (int i = 0; i < data_bytes - 1; i += 2)
+                       {
+                               swap(&data[i], &data[i+1]);
+                       }
+                       #endif // not _TU_LITTLE_ENDIAN_
+
+                       format = sound_handler::FORMAT_NATIVE16;
+               }*/
+       }
+
 
        // Fill the data on the apropiate sound, and receives the starting point
        // for later "start playing from this frame" events.
-       long start = s_sound_handler->fill_stream_data(data, data_bytes, 
handle_id);
+       long start = s_sound_handler->fill_stream_data(data, data_bytes, 
sample_count, handle_id);
 
        delete [] data;
 
@@ -1790,15 +1822,6 @@
 
        // @@ who's going to delete the start_stream_sound_tag ??
 
-#else
-       static bool already_warned=false;
-       if ( ! already_warned )
-       {
-               log_warning("Only Gstreamer sound backend "
-                       "supports SoundStreamBlock tag");
-               already_warned=true;
-       }
-#endif
 }
 
 

Index: utilities/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/utilities/Makefile.am,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- utilities/Makefile.am       3 Oct 2006 15:40:50 -0000       1.26
+++ utilities/Makefile.am       7 Oct 2006 14:20:27 -0000       1.27
@@ -20,11 +20,6 @@
 
 AUTOMAKE_OPTIONS = # dejagnu
 
-if MP3
-MP3_CFLAGS = $(MAD_CFLAGS)
-MP3_LIBS = $(MAD_LIBS)
-endif
-
 # @@ shouldn't we drop package_LIBS and leave deps
 #    on the gnash libraries side instead ?
 




reply via email to

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