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 <set> // for composition (InputStreams)
28 #include <SDL_audio.h>
29 #include <boost/thread/mutex.hpp>
30 
31 // Forward declarations
32 namespace gnash {
33  class SimpleBuffer;
34  namespace sound {
35  class EmbedSound;
36  class InputStream;
37  }
38 }
39 
40 namespace gnash {
41 namespace sound {
42 
45 {
46 private:
47 
49  SDL_AudioSpec audioSpec;
50 
52  void initAudio();
53 
54  void openAudio();
55 
56  void closeAudio();
57 
58  bool _audioOpened;
59 
61  mutable boost::mutex _mutex;
62 
64  mutable boost::mutex _mutedMutex;
65 
66  // See dox in sound_handler.h
67  void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
68  unsigned int nSamples, float volume);
69 
70 
72  //
87  static void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in);
88 
89 public:
90 
92 
94 
95  virtual int createStreamingSound(const media::SoundInfo& sinfo);
96 
97  // See dox in sound_handler.h
98  virtual int create_sound(std::auto_ptr<SimpleBuffer> data,
99  const media::SoundInfo& sinfo);
100 
101  // See dox in sound_handler.h
102  // overridden to serialize access to the data buffer slot
103  virtual StreamBlockId addSoundBlock(std::auto_ptr<SimpleBuffer> buf,
104  size_t sample_count, int seekSamples, int streamId);
105 
106  // See dox in sound_handler.h
107  virtual void stopEventSound(int sound_handle);
108 
109  // See dox in sound_handler.h
110  virtual void stopAllEventSounds();
111 
112  virtual void stopStreamingSound(int sound_handle);
113 
114  // See dox in sound_handler.h
115  virtual void delete_sound(int sound_handle);
116 
117  // See dox in sound_handler.h
118  virtual void reset();
119 
120  // See dox in sound_handler.h
121  virtual void stop_all_sounds();
122 
123  // See dox in sound_handler.h
124  virtual int get_volume(int sound_handle) const;
125 
126  // See dox in sound_handler.h
127  virtual void set_volume(int sound_handle, int volume);
128 
129  // See dox in sound_handler.h
130  virtual media::SoundInfo* get_sound_info(int soundHandle) const;
131 
132  // See dox in sound_handler.h
133  // overridden to serialize access to the _muted member
134  virtual void mute();
135 
136  // See dox in sound_handler.h
137  // overridden to serialize access to the _muted member
138  virtual void unmute();
139 
140  // See dox in sound_handler.h
141  // overridden to serialize access to the _muted member
142  virtual bool is_muted() const;
143 
144  // See dox in sound_handler.h
145  // overridden to close audio card
146  virtual void pause();
147 
148  // See dox in sound_handler.h
149  // overridden to open audio card
150  virtual void unpause();
151 
152  // See dox in sound_handler.h
153  virtual unsigned int get_duration(int sound_handle) const;
154 
155  // See dox in sound_handler.h
156  virtual unsigned int tell(int sound_handle) const;
157 
158  // See dox in sound_handler.h
159  // Overridden to unpause SDL audio
160  void plugInputStream(std::auto_ptr<InputStream> in);
161 
162  // Overidden to provide thread safety.
163  void unplugInputStream(InputStream* id);
164 
165  // See dox in sound_handler.h
166  void fetchSamples(boost::int16_t* to, unsigned int nSamples);
167 };
168 
169 } // gnash.sound namespace
170 } // namespace gnash
171 
172 #endif // SOUND_HANDLER_SDL_H