Gnash  0.8.11dev
sound_handler_mkit.h
Go to the documentation of this file.
1 // sound_handler_haiku.h: Sound handling using Mkit media kit
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 #ifndef SOUND_HANDLER_MKIT_H
21 #define SOUND_HANDLER_MKIT_H
22 
23 #include "sound_handler.h" // for inheritance
24 
25 #include <set> // for composition (InputStreams)
26 #include <boost/thread/mutex.hpp>
27 #include <boost/scoped_ptr.hpp>
28 
29 #include <SoundPlayer.h>
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  boost::scoped_ptr<BSoundPlayer> _soundplayer;
47 
49  static void FillNextBuffer(void *cookie, void *buffer, size_t size,
50  const media_raw_audio_format &format);
51 
53  void openAudio();
54 
55  bool _audioopen;
56 
58  boost::mutex _mutex;
59 
61  mutable boost::mutex _mutedMutex;
62 
63  // See dox in sound_handler.h
64  void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
65  unsigned int nSamples, float volume);
66 
67  void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, boost::uint32_t len, int volume);
68 
69 public:
71 
73 
74  // See dox in sound_handler.h
75  virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
76 
77  // See dox in sound_handler.h
78  // overridden to serialize access to the data buffer slot
79  virtual StreamBlockId addSoundBlock(unsigned char* data,
80  unsigned int data_bytes,
81  unsigned int sample_count,
82  int streamId);
83 
84  // See dox in sound_handler.h
85  virtual void stop_sound(int sound_handle);
86 
87  // See dox in sound_handler.h
88  virtual void delete_sound(int sound_handle);
89 
90  // See dox in sound_handler.h
91  virtual void reset();
92 
93  // See dox in sound_handler.h
94  virtual void stop_all_sounds();
95 
96  // See dox in sound_handler.h
97  virtual int get_volume(int sound_handle);
98 
99  // See dox in sound_handler.h
100  virtual void set_volume(int sound_handle, int volume);
101 
102  // See dox in sound_handler.h
103  virtual media::SoundInfo* get_sound_info(int soundHandle);
104 
105  // See dox in sound_handler.h
106  // overridden to serialize access to the _muted member
107  virtual void mute();
108 
109  // See dox in sound_handler.h
110  // overridden to serialize access to the _muted member
111  virtual void unmute();
112 
113  // See dox in sound_handler.h
114  // overridden to serialize access to the _muted member
115  virtual bool is_muted() const;
116 
117  // See dox in sound_handler.h
118  // overridden to close audio card
119  virtual void pause();
120 
121  // See dox in sound_handler.h
122  // overridden to open audio card
123  virtual void unpause();
124 
125  // See dox in sound_handler.h
126  virtual unsigned int get_duration(int sound_handle);
127 
128  // See dox in sound_handler.h
129  virtual unsigned int tell(int sound_handle);
130 
131  // See dox in sound_handler.h
132  // Overridden to unpause SDL audio
133  void plugInputStream(std::auto_ptr<InputStream> in);
134 
135  // See dox in sound_handler.h
136  void fetchSamples(boost::int16_t* to, unsigned int nSamples);
137 };
138 
139 } // gnash.sound namespace
140 } // namespace gnash
141 
142 #endif // SOUND_HANDLER_MKIT_H