gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp b...


From: Bastiaan Jacques
Subject: [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp b...
Date: Sat, 07 Oct 2006 16:13:52 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     06/10/07 16:13:52

Modified files:
        .              : ChangeLog 
        backend        : sound_handler_sdl.cpp 
Added files:
        backend        : sound_handler_sdl.h 

Log message:
        Code cleanup: move declarations into a seperate header file.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1063&r2=1.1064
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.cpp?cvsroot=gnash&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.h?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1063
retrieving revision 1.1064
diff -u -b -r1.1063 -r1.1064
--- ChangeLog   7 Oct 2006 16:07:34 -0000       1.1063
+++ ChangeLog   7 Oct 2006 16:13:52 -0000       1.1064
@@ -1,3 +1,8 @@
+2006-10-07 Bastiaan Jacques <address@hidden>
+
+       * backend/sound_handler_sdl{.cpp, .h}: Code cleanup: move declarations
+       into a seperate header file.
+
 2006-10-07 Sandro Santilli <address@hidden>
 
        * backend/render_handler_tri.{h,cpp}: moved initialization
@@ -27,8 +32,8 @@
 2006-10-07 Bastiaan Jacques <address@hidden>
 
        * configure.ac: Replace --enable-lotsa-warnings with --enable-strict,
-       because strict a more descriptive name for what lotsa-warnings actually
-       does.
+       because strict is a more descriptive name for what lotsa-warnings
+       actually does.
 
 2006-10-07 Markus Gothe <address@hidden>
 

Index: backend/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- backend/sound_handler_sdl.cpp       7 Oct 2006 14:20:27 -0000       1.21
+++ backend/sound_handler_sdl.cpp       7 Oct 2006 16:13:52 -0000       1.22
@@ -22,117 +22,25 @@
 #include "config.h"
 #endif
 
-#ifdef SOUND_SDL
-#include "gnash.h"
+#include "sound_handler_sdl.h"
+
 #include "container.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;
-
-       // Volume, SWF range: 0-100, SDL range 0-128
-       // It's the SWF range that is represented here
-       int volume;
-
-       // 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:
-       // Sound data.
-       std::vector<sound_data*>        m_sound_data;
 
-       // Is sound device opened?
-       bool soundOpened;
-
-       // SDL_audio specs
-       SDL_AudioSpec audioSpec;
+void sdl_audio_callback(void *udata, Uint8 *stream, int len); // SDL C audio 
handler
        
-       // 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()
+SDL_sound_handler::SDL_sound_handler()
                : soundOpened(false),
                  soundsPlaying(0)
-       {
+{
                // Init mutex
                pthread_mutex_init(&mutex , NULL);
 
@@ -143,31 +51,29 @@
                audioSpec.callback = sdl_audio_callback;
                audioSpec.userdata = this;
                audioSpec.samples = 512;
-       }
-
-       ~SDL_sound_handler()
-       {
+}
 
+SDL_sound_handler::~SDL_sound_handler()
+{
                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);
-
-       }
+}
 
 
-       virtual int     create_sound(
+int    SDL_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) {
@@ -249,11 +155,11 @@
 
                return sound_id;
 
-       }
+}
 
-       // 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   SDL_sound_handler::fill_stream_data(void* data, int data_bytes, int 
sample_count, int handle_id)
+{
 
                pthread_mutex_lock(&mutex);             
                // @@ does a negative handle_id have any meaning ?
@@ -328,12 +234,12 @@
                return start_size;
 
 
-       }
+}
 
 
-       virtual void    play_sound(int sound_handle, int loop_count, int 
/*offset*/, long start_position)
-       // Play the index'd sample.
-       {
+void   SDL_sound_handler::play_sound(int sound_handle, int loop_count, int 
/*offset*/, long start_position)
+// Play the index'd sample.
+{
                pthread_mutex_lock(&mutex);
 
                // Check if the sound exists.
@@ -424,11 +330,11 @@
 
                pthread_mutex_unlock(&mutex);
 
-       }
+}
 
 
-       virtual void    stop_sound(int sound_handle)
-       {
+void   SDL_sound_handler::stop_sound(int sound_handle)
+{
                pthread_mutex_lock(&mutex);
                
                // Check if the sound exists.
@@ -445,12 +351,12 @@
                }
                pthread_mutex_unlock(&mutex);
 
-       }
+}
 
 
-       virtual void    delete_sound(int sound_handle)
-       // this gets called when it's done with a sample.
-       {
+void   SDL_sound_handler::delete_sound(int sound_handle)
+// this gets called when it's done with a sample.
+{
                pthread_mutex_lock(&mutex);
                
                if (sound_handle >= 0 && (unsigned int) sound_handle < 
m_sound_data.size())
@@ -459,22 +365,22 @@
                }
                pthread_mutex_unlock(&mutex);
 
-       }
+}
 
-       // 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   SDL_sound_handler::stop_all_sounds()
+{
                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) {
+//     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    SDL_sound_handler::get_volume(int sound_handle) {
        
                pthread_mutex_lock(&mutex);
 
@@ -488,12 +394,12 @@
                }
                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) {
+//     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   SDL_sound_handler::set_volume(int sound_handle, int volume) {
 
                pthread_mutex_lock(&mutex);
 
@@ -509,9 +415,9 @@
                pthread_mutex_unlock(&mutex);
 
 
-       }
+}
        
-       virtual void get_info(int sound_handle, int* format, bool* stereo) {
+void SDL_sound_handler::get_info(int sound_handle, int* format, bool* stereo) {
        
                pthread_mutex_lock(&mutex);
 
@@ -523,10 +429,10 @@
                } 
 
                pthread_mutex_unlock(&mutex);
-       }
+}
 
 
-       virtual void convert_raw_data(
+void SDL_sound_handler::convert_raw_data(
                int16_t** adjusted_data,
                int* adjusted_size,
                void* data,
@@ -534,10 +440,10 @@
                int sample_size,
                int sample_rate,
                bool stereo)
-       // VERY crude sample-rate & sample-size conversion.  Converts
-       // input data to the SDL_mixer output format (SAMPLE_RATE,
-       // stereo, 16-bit native endianness)
-       {
+// VERY crude sample-rate & sample-size conversion.  Converts
+// input data to the SDL_mixer output format (SAMPLE_RATE,
+// stereo, 16-bit native endianness)
+{
 //             // xxxxx debug pass-thru
 //             {
 //                     int     output_sample_count = sample_count * (stereo ? 
2 : 1);
@@ -610,11 +516,7 @@
                                in += inc;
                        }
                }
-       }
-
-
-
-};
+}
 
 
 gnash::sound_handler*  gnash::create_sound_handler_sdl()
@@ -846,8 +748,6 @@
 
 }
 
-#endif
-
 // Local Variables:
 // mode: C++
 // End:

Index: backend/sound_handler_sdl.h
===================================================================
RCS file: backend/sound_handler_sdl.h
diff -N backend/sound_handler_sdl.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ backend/sound_handler_sdl.h 7 Oct 2006 16:13:52 -0000       1.1
@@ -0,0 +1,160 @@
+//   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_SDL_H
+#define SOUND_HANDLER_SDL_H
+
+
+#ifdef USE_FFMPEG
+#include <ffmpeg/avcodec.h>
+#include <ffmpeg/avformat.h>
+#elif defined(USE_MAD)
+#include <mad.h>
+#endif
+
+#include "gnash.h"
+#include <vector>
+
+#include <SDL/SDL_audio.h>
+
+
+// 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_t* data;
+
+       // data size
+       long raw_data_size;
+
+       // position in the raw stream
+       long raw_position;
+
+       // The decompressed data
+       uint8_t* raw_data;
+
+       long loop_count;
+       
+} active_sound;
+
+
+// Used to hold the sounddata when doing on-demand-decoding
+typedef struct
+{
+       // The (un)compressed data
+       uint8_t* 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, SDL range 0-128
+       // It's the SWF range that is represented here
+       int volume;
+
+       // active sounds being playes
+       std::vector<active_sound*>      m_active_sounds;
+
+} sound_data;
+
+
+// Use SDL and ffmpeg/mad/nothing to handle sounds.
+struct SDL_sound_handler : public gnash::sound_handler
+{
+       // 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();
+       virtual ~SDL_sound_handler();
+
+       // Called to create a sample.
+       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);
+
+       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.
+       virtual int     get_volume(int sound_handle);
+
+       virtual void    set_volume(int sound_handle, int volume);
+               
+       virtual void    get_info(int sound_handle, int* format, bool* stereo);
+
+
+       // Converts input data to the SDL_mixer 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);
+
+};
+
+
+#endif // SOUND_HANDLER_SDL_H




reply via email to

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