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 <mutex>
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 std::mutex _mutex;
61 
62  // See dox in sound_handler.h
63  void mix(std::int16_t* outSamples, std::int16_t* inSamples,
64  unsigned int nSamples, float volume);
65 
66 
68  //
83  static void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in);
84 
85 public:
86 
88 
90 
91  virtual int createStreamingSound(const media::SoundInfo& sinfo);
92 
93  // See dox in sound_handler.h
94  virtual int create_sound(std::unique_ptr<SimpleBuffer> data,
95  const media::SoundInfo& sinfo);
96 
97  // See dox in sound_handler.h
98  // overridden to serialize access to the data buffer slot
99  virtual StreamBlockId addSoundBlock(SimpleBuffer buf,
100  size_t sample_count, int seekSamples, int streamId);
101 
102  // See dox in sound_handler.h
103  virtual void stopEventSound(int sound_handle);
104 
105  // See dox in sound_handler.h
106  virtual void stopAllEventSounds();
107 
108  virtual void stopStreamingSound(int sound_handle);
109 
110  // See dox in sound_handler.h
111  virtual void delete_sound(int sound_handle);
112 
113  // See dox in sound_handler.h
114  virtual void reset();
115 
116  // See dox in sound_handler.h
117  virtual void stop_all_sounds();
118 
119  // See dox in sound_handler.h
120  virtual int get_volume(int sound_handle) const;
121 
122  // See dox in sound_handler.h
123  virtual void set_volume(int sound_handle, int volume);
124 
125  // See dox in sound_handler.h
126  virtual media::SoundInfo* get_sound_info(int soundHandle) const;
127 
128  // See dox in sound_handler.h
129  // overridden to close audio card
130  virtual void pause();
131 
132  // See dox in sound_handler.h
133  // overridden to open audio card
134  virtual void unpause();
135 
136  // See dox in sound_handler.h
137  virtual unsigned int get_duration(int sound_handle) const;
138 
139  // See dox in sound_handler.h
140  virtual unsigned int tell(int sound_handle) const;
141 
142  // See dox in sound_handler.h
143  // Overridden to unpause SDL audio
144  void plugInputStream(std::unique_ptr<InputStream> in);
145 
146  // Overidden to provide thread safety.
147  void unplugInputStream(InputStream* id);
148 
149  // See dox in sound_handler.h
150  void fetchSamples(std::int16_t* to, unsigned int nSamples);
151 };
152 
153 } // gnash.sound namespace
154 } // namespace gnash
155 
156 #endif // SOUND_HANDLER_SDL_H
A sound input stream.
Definition: InputStream.h:47
Definition: klash_part.cpp:331
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
Sound mixer.
Definition: sound_handler.h:87
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:69
SDL-based sound_handler.
Definition: sound_handler_sdl.h:43
unsigned long StreamBlockId
Identifier of a streaming sound block.
Definition: sound_handler.h:97
A simple buffer of bytes.
Definition: SimpleBuffer.h:38
Definition: GnashKey.h:159