Gnash  0.8.10
sound_handler_sdl.h
Go to the documentation of this file.
00001 // sound_handler_sdl.h: Sound handling using standard SDL
00002 //
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 
00021 #ifndef SOUND_HANDLER_SDL_H
00022 #define SOUND_HANDLER_SDL_H
00023 
00024 
00025 #include "sound_handler.h" // for inheritance
00026 
00027 #include <set> // for composition (InputStreams)
00028 #include <SDL_audio.h>
00029 #include <boost/thread/mutex.hpp>
00030 
00031 // Forward declarations
00032 namespace gnash {
00033     class SimpleBuffer;
00034     namespace sound {
00035         class EmbedSound;
00036         class InputStream;
00037     }
00038 }
00039 
00040 namespace gnash {
00041 namespace sound {
00042 
00044 class SDL_sound_handler : public sound_handler
00045 {
00046 private:
00047 
00049     SDL_AudioSpec audioSpec;
00050 
00052     void initAudio();
00053 
00054     void openAudio();
00055 
00056     void closeAudio();
00057 
00058     bool _audioOpened;
00059     
00061     mutable boost::mutex _mutex;
00062 
00064     mutable boost::mutex _mutedMutex;
00065 
00066     // See dox in sound_handler.h
00067     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
00068                 unsigned int nSamples, float volume);
00069 
00070 
00072     //
00087     static void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in);
00088 
00089 public:
00090 
00091     SDL_sound_handler(media::MediaHandler* m);
00092 
00093     ~SDL_sound_handler();
00094 
00095     virtual int createStreamingSound(const media::SoundInfo& sinfo);
00096 
00097     // See dox in sound_handler.h
00098     virtual int create_sound(std::auto_ptr<SimpleBuffer> data,
00099             const media::SoundInfo& sinfo);
00100 
00101     // See dox in sound_handler.h
00102     // overridden to serialize access to the data buffer slot
00103     virtual StreamBlockId addSoundBlock(std::auto_ptr<SimpleBuffer> buf,
00104            size_t sample_count, int seekSamples, int streamId);
00105 
00106     // See dox in sound_handler.h
00107     virtual void stopEventSound(int sound_handle);
00108 
00109     // See dox in sound_handler.h
00110     virtual void stopAllEventSounds();
00111 
00112     virtual void stopStreamingSound(int sound_handle);
00113 
00114     // See dox in sound_handler.h
00115     virtual void    delete_sound(int sound_handle);
00116 
00117     // See dox in sound_handler.h
00118     virtual void reset();
00119 
00120     // See dox in sound_handler.h
00121     virtual void    stop_all_sounds();
00122 
00123     // See dox in sound_handler.h
00124     virtual int get_volume(int sound_handle) const;
00125 
00126     // See dox in sound_handler.h
00127     virtual void set_volume(int sound_handle, int volume);
00128         
00129     // See dox in sound_handler.h
00130     virtual media::SoundInfo* get_sound_info(int soundHandle) const;
00131 
00132     // See dox in sound_handler.h
00133     // overridden to serialize access to the _muted member
00134     virtual void mute();
00135 
00136     // See dox in sound_handler.h
00137     // overridden to serialize access to the _muted member
00138     virtual void unmute();
00139 
00140     // See dox in sound_handler.h
00141     // overridden to serialize access to the _muted member
00142     virtual bool is_muted() const;
00143 
00144     // See dox in sound_handler.h
00145     // overridden to close audio card
00146     virtual void pause();
00147 
00148     // See dox in sound_handler.h
00149     // overridden to open audio card
00150     virtual void unpause();
00151 
00152     // See dox in sound_handler.h
00153     virtual unsigned int get_duration(int sound_handle) const;
00154 
00155     // See dox in sound_handler.h
00156     virtual unsigned int tell(int sound_handle) const;
00157     
00158     // See dox in sound_handler.h
00159     // Overridden to unpause SDL audio
00160     void plugInputStream(std::auto_ptr<InputStream> in);
00161 
00162     // Overidden to provide thread safety.
00163     void unplugInputStream(InputStream* id);
00164 
00165     // See dox in sound_handler.h
00166     void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00167 };
00168 
00169 } // gnash.sound namespace 
00170 } // namespace gnash
00171 
00172 #endif // SOUND_HANDLER_SDL_H