Gnash  0.8.10
sound_handler_mkit.h
Go to the documentation of this file.
00001 // sound_handler_haiku.h: Sound handling using Mkit media kit
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 #ifndef SOUND_HANDLER_MKIT_H
00021 #define SOUND_HANDLER_MKIT_H
00022 
00023 #include "sound_handler.h" // for inheritance
00024 
00025 #include <set> // for composition (InputStreams)
00026 #include <boost/thread/mutex.hpp>
00027 #include <boost/scoped_ptr.hpp>
00028 
00029 #include <SoundPlayer.h>
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 Mkit_sound_handler : public sound_handler
00045 {
00046     boost::scoped_ptr<BSoundPlayer> _soundplayer;
00047 
00049     static void FillNextBuffer(void *cookie, void *buffer, size_t size,
00050             const media_raw_audio_format &format);
00051 
00053     void openAudio();
00054 
00055     bool _audioopen;
00056 
00058     boost::mutex _mutex;
00059 
00061     mutable boost::mutex _mutedMutex;
00062 
00063     // See dox in sound_handler.h
00064     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
00065                 unsigned int nSamples, float volume);
00066 
00067     void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, boost::uint32_t len, int volume);
00068 
00069 public:
00070     Mkit_sound_handler(media::MediaHandler* m);
00071 
00072     ~Mkit_sound_handler();
00073 
00074     // See dox in sound_handler.h
00075     virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
00076 
00077     // See dox in sound_handler.h
00078     // overridden to serialize access to the data buffer slot
00079     virtual StreamBlockId addSoundBlock(unsigned char* data,
00080                                        unsigned int data_bytes,
00081                                        unsigned int sample_count,
00082                                        int streamId);
00083 
00084     // See dox in sound_handler.h
00085     virtual void    stop_sound(int sound_handle);
00086 
00087     // See dox in sound_handler.h
00088     virtual void    delete_sound(int sound_handle);
00089 
00090     // See dox in sound_handler.h
00091     virtual void reset();
00092 
00093     // See dox in sound_handler.h
00094     virtual void    stop_all_sounds();
00095 
00096     // See dox in sound_handler.h
00097     virtual int get_volume(int sound_handle);
00098 
00099     // See dox in sound_handler.h
00100     virtual void    set_volume(int sound_handle, int volume);
00101 
00102     // See dox in sound_handler.h
00103     virtual media::SoundInfo* get_sound_info(int soundHandle);
00104 
00105     // See dox in sound_handler.h
00106     // overridden to serialize access to the _muted member
00107     virtual void mute();
00108 
00109     // See dox in sound_handler.h
00110     // overridden to serialize access to the _muted member
00111     virtual void unmute();
00112 
00113     // See dox in sound_handler.h
00114     // overridden to serialize access to the _muted member
00115     virtual bool is_muted() const;
00116 
00117     // See dox in sound_handler.h
00118     // overridden to close audio card
00119     virtual void pause();
00120 
00121     // See dox in sound_handler.h
00122     // overridden to open audio card
00123     virtual void unpause();
00124 
00125     // See dox in sound_handler.h
00126     virtual unsigned int get_duration(int sound_handle);
00127 
00128     // See dox in sound_handler.h
00129     virtual unsigned int tell(int sound_handle);
00130 
00131     // See dox in sound_handler.h
00132     // Overridden to unpause SDL audio
00133     void plugInputStream(std::auto_ptr<InputStream> in);
00134 
00135     // See dox in sound_handler.h
00136     void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00137 };
00138 
00139 } // gnash.sound namespace 
00140 } // namespace gnash
00141 
00142 #endif // SOUND_HANDLER_MKIT_H