OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_AUDIO_AUDIO_IO_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_IO_H_ |
6 #define MEDIA_AUDIO_AUDIO_IO_H_ | 6 #define MEDIA_AUDIO_AUDIO_IO_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 | 9 |
10 // Low-level audio output support. To make sound there are 3 objects involved: | 10 // Low-level audio output support. To make sound there are 3 objects involved: |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 virtual void Stop() = 0; | 146 virtual void Stop() = 0; |
147 | 147 |
148 // Close the stream. This also generates AudioInputCallback::OnClose(). This | 148 // Close the stream. This also generates AudioInputCallback::OnClose(). This |
149 // should be the last call made on this object. | 149 // should be the last call made on this object. |
150 virtual void Close() = 0; | 150 virtual void Close() = 0; |
151 | 151 |
152 protected: | 152 protected: |
153 virtual ~AudioInputStream() {} | 153 virtual ~AudioInputStream() {} |
154 }; | 154 }; |
155 | 155 |
| 156 // Manages all audio resources. In particular it owns the AudioOutputStream |
| 157 // objects. Provides some convenience functions that avoid the need to provide |
| 158 // iterators over the existing streams. |
| 159 class AudioManager { |
| 160 public: |
| 161 enum Format { |
| 162 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. |
| 163 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. |
| 164 AUDIO_MOCK, // Creates a dummy AudioOutputStream object. |
| 165 AUDIO_LAST_FORMAT // Only used for validation of format. |
| 166 }; |
| 167 |
| 168 // Telephone quality sample rate, mostly for speech-only audio. |
| 169 static const uint32 kTelephoneSampleRate = 8000; |
| 170 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. |
| 171 static const uint32 kAudioCDSampleRate = 44100; |
| 172 // Digital Audio Tape sample rate. |
| 173 static const uint32 kAudioDATSampleRate = 48000; |
| 174 |
| 175 // Returns true if the OS reports existence of audio devices. This does not |
| 176 // guarantee that the existing devices support all formats and sample rates. |
| 177 virtual bool HasAudioOutputDevices() = 0; |
| 178 |
| 179 // Returns true if the OS reports existence of audio recording devices. This |
| 180 // does not guarantee that the existing devices support all formats and |
| 181 // sample rates. |
| 182 virtual bool HasAudioInputDevices() = 0; |
| 183 |
| 184 // Factory for all the supported stream formats. The |channels| can be 1 to 5. |
| 185 // The |sample_rate| is in hertz and can be any value supported by the |
| 186 // platform. For some future formats the |sample_rate| and |bits_per_sample| |
| 187 // can take special values. |
| 188 // Returns NULL if the combination of the parameters is not supported, or if |
| 189 // we have reached some other platform specific limit. |
| 190 // |
| 191 // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: |
| 192 // 1- Instead of triple buffered the audio will be double buffered. |
| 193 // 2- A low latency driver or alternative audio subsystem will be used when |
| 194 // available. |
| 195 // |
| 196 // Do not free the returned AudioOutputStream. It is owned by AudioManager. |
| 197 virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, |
| 198 int sample_rate, |
| 199 char bits_per_sample) = 0; |
| 200 |
| 201 // Factory to create audio recording streams. |
| 202 // |channels| can be 1 or 2. |
| 203 // |sample_rate| is in hertz and can be any value supported by the platform. |
| 204 // |bits_per_sample| can be any value supported by the platform. |
| 205 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, |
| 206 // with 0 suggesting that the implementation use a default value for that |
| 207 // platform. |
| 208 // Returns NULL if the combination of the parameters is not supported, or if |
| 209 // we have reached some other platform specific limit. |
| 210 // |
| 211 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
| 212 // When you are done with it, call |Stop()| and |Close()| to release it. |
| 213 virtual AudioInputStream* MakeAudioInputStream(Format format, int channels, |
| 214 int sample_rate, |
| 215 char bits_per_sample, |
| 216 uint32 samples_per_packet) = 0; |
| 217 |
| 218 // Muting continues playback but effectively the volume is set to zero. |
| 219 // Un-muting returns the volume to the previous level. |
| 220 virtual void MuteAll() = 0; |
| 221 virtual void UnMuteAll() = 0; |
| 222 |
| 223 // Get AudioManager singleton. |
| 224 // TODO(cpu): Define threading requirements for interacting with AudioManager. |
| 225 static AudioManager* GetAudioManager(); |
| 226 |
| 227 protected: |
| 228 virtual ~AudioManager() {} |
| 229 }; |
| 230 |
| 231 |
156 #endif // MEDIA_AUDIO_AUDIO_IO_H_ | 232 #endif // MEDIA_AUDIO_AUDIO_IO_H_ |
OLD | NEW |