Gnash 0.8.9

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,
00004 //   2011 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     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     // See dox in sound_handler.h
00096     virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
00097 
00098     // See dox in sound_handler.h
00099     // overridden to serialize access to the data buffer slot
00100     virtual StreamBlockId addSoundBlock(unsigned char* data,
00101                                        unsigned int data_bytes,
00102                                        unsigned int sample_count,
00103                                        int streamId);
00104 
00105     // See dox in sound_handler.h
00106     virtual void    stop_sound(int sound_handle);
00107 
00108     // See dox in sound_handler.h
00109     virtual void    delete_sound(int sound_handle);
00110 
00111     // See dox in sound_handler.h
00112     virtual void reset();
00113 
00114     // See dox in sound_handler.h
00115     virtual void    stop_all_sounds();
00116 
00117     // See dox in sound_handler.h
00118     virtual int get_volume(int sound_handle);
00119 
00120     // See dox in sound_handler.h
00121     virtual void    set_volume(int sound_handle, int volume);
00122         
00123     // See dox in sound_handler.h
00124     virtual media::SoundInfo* get_sound_info(int soundHandle);
00125 
00126     // See dox in sound_handler.h
00127     // overridden to serialize access to the _muted member
00128     virtual void mute();
00129 
00130     // See dox in sound_handler.h
00131     // overridden to serialize access to the _muted member
00132     virtual void unmute();
00133 
00134     // See dox in sound_handler.h
00135     // overridden to serialize access to the _muted member
00136     virtual bool is_muted() const;
00137 
00138     // See dox in sound_handler.h
00139     // overridden to close audio card
00140     virtual void pause();
00141 
00142     // See dox in sound_handler.h
00143     // overridden to open audio card
00144     virtual void unpause();
00145 
00146     // See dox in sound_handler.h
00147     virtual unsigned int get_duration(int sound_handle);
00148 
00149     // See dox in sound_handler.h
00150     virtual unsigned int tell(int sound_handle);
00151     
00152     // See dox in sound_handler.h
00153     // Overridden to unpause SDL audio
00154     void plugInputStream(std::auto_ptr<InputStream> in);
00155 
00156     // Overidden to provide thread safety.
00157     void unplugInputStream(InputStream* id);
00158 
00159     // See dox in sound_handler.h
00160     void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00161 };
00162 
00163 } // gnash.sound namespace 
00164 } // namespace gnash
00165 
00166 #endif // SOUND_HANDLER_SDL_H