Gnash  0.8.11dev
sound_handler_sdl.h
Go to the documentation of this file.
1 // sound_handler_sdl.h: Sound handling using standard SDL
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 
21 #ifndef SOUND_HANDLER_SDL_H
22 #define SOUND_HANDLER_SDL_H
23 
24 
25 #include "sound_handler.h" // for inheritance
26 
27 #include <SDL_audio.h>
28 #include <boost/thread/mutex.hpp>
29 
30 // Forward declarations
31 namespace gnash {
32  class SimpleBuffer;
33  namespace sound {
34  class EmbedSound;
35  class InputStream;
36  }
37 }
38 
39 namespace gnash {
40 namespace sound {
41 
44 {
45 private:
46 
48  SDL_AudioSpec audioSpec;
49 
51  void initAudio();
52 
53  void openAudio();
54 
55  void closeAudio();
56 
57  bool _audioOpened;
58 
60  mutable boost::mutex _mutex;
61 
63  mutable boost::mutex _mutedMutex;
64 
65  // See dox in sound_handler.h
66  void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
67  unsigned int nSamples, float volume);
68 
69 
71  //
86  static void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in);
87 
88 public:
89 
91 
93 
94  virtual int createStreamingSound(const media::SoundInfo& sinfo);
95 
96  // See dox in sound_handler.h
97  virtual int create_sound(std::auto_ptr<SimpleBuffer> data,
98  const media::SoundInfo& sinfo);
99 
100  // See dox in sound_handler.h
101  // overridden to serialize access to the data buffer slot
102  virtual StreamBlockId addSoundBlock(std::auto_ptr<SimpleBuffer> buf,
103  size_t sample_count, int seekSamples, int streamId);
104 
105  // See dox in sound_handler.h
106  virtual void stopEventSound(int sound_handle);
107 
108  // See dox in sound_handler.h
109  virtual void stopAllEventSounds();
110 
111  virtual void stopStreamingSound(int sound_handle);
112 
113  // See dox in sound_handler.h
114  virtual void delete_sound(int sound_handle);
115 
116  // See dox in sound_handler.h
117  virtual void reset();
118 
119  // See dox in sound_handler.h
120  virtual void stop_all_sounds();
121 
122  // See dox in sound_handler.h
123  virtual int get_volume(int sound_handle) const;
124 
125  // See dox in sound_handler.h
126  virtual void set_volume(int sound_handle, int volume);
127 
128  // See dox in sound_handler.h
129  virtual media::SoundInfo* get_sound_info(int soundHandle) const;
130 
131  // See dox in sound_handler.h
132  // overridden to serialize access to the _muted member
133  virtual void mute();
134 
135  // See dox in sound_handler.h
136  // overridden to serialize access to the _muted member
137  virtual void unmute();
138 
139  // See dox in sound_handler.h
140  // overridden to serialize access to the _muted member
141  virtual bool is_muted() const;
142 
143  // See dox in sound_handler.h
144  // overridden to close audio card
145  virtual void pause();
146 
147  // See dox in sound_handler.h
148  // overridden to open audio card
149  virtual void unpause();
150 
151  // See dox in sound_handler.h
152  virtual unsigned int get_duration(int sound_handle) const;
153 
154  // See dox in sound_handler.h
155  virtual unsigned int tell(int sound_handle) const;
156 
157  // See dox in sound_handler.h
158  // Overridden to unpause SDL audio
159  void plugInputStream(std::auto_ptr<InputStream> in);
160 
161  // Overidden to provide thread safety.
162  void unplugInputStream(InputStream* id);
163 
164  // See dox in sound_handler.h
165  void fetchSamples(boost::int16_t* to, unsigned int nSamples);
166 };
167 
168 } // gnash.sound namespace
169 } // namespace gnash
170 
171 #endif // SOUND_HANDLER_SDL_H