OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 |
| 10 class AudioInputStream; |
| 11 class AudioOutputStream; |
| 12 class MessageLoop; |
| 13 |
| 14 // Manages all audio resources. In particular it owns the AudioOutputStream |
| 15 // objects. Provides some convenience functions that avoid the need to provide |
| 16 // iterators over the existing streams. |
| 17 class AudioManager { |
| 18 public: |
| 19 enum Format { |
| 20 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. |
| 21 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. |
| 22 AUDIO_MOCK, // Creates a dummy AudioOutputStream object. |
| 23 AUDIO_LAST_FORMAT // Only used for validation of format. |
| 24 }; |
| 25 |
| 26 // Telephone quality sample rate, mostly for speech-only audio. |
| 27 static const uint32 kTelephoneSampleRate = 8000; |
| 28 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. |
| 29 static const uint32 kAudioCDSampleRate = 44100; |
| 30 // Digital Audio Tape sample rate. |
| 31 static const uint32 kAudioDATSampleRate = 48000; |
| 32 |
| 33 // Returns true if the OS reports existence of audio devices. This does not |
| 34 // guarantee that the existing devices support all formats and sample rates. |
| 35 virtual bool HasAudioOutputDevices() = 0; |
| 36 |
| 37 // Returns true if the OS reports existence of audio recording devices. This |
| 38 // does not guarantee that the existing devices support all formats and |
| 39 // sample rates. |
| 40 virtual bool HasAudioInputDevices() = 0; |
| 41 |
| 42 // Factory for all the supported stream formats. The |channels| can be 1 to 5. |
| 43 // The |sample_rate| is in hertz and can be any value supported by the |
| 44 // platform. For some future formats the |sample_rate| and |bits_per_sample| |
| 45 // can take special values. |
| 46 // Returns NULL if the combination of the parameters is not supported, or if |
| 47 // we have reached some other platform specific limit. |
| 48 // |
| 49 // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: |
| 50 // 1- Instead of triple buffered the audio will be double buffered. |
| 51 // 2- A low latency driver or alternative audio subsystem will be used when |
| 52 // available. |
| 53 // |
| 54 // Do not free the returned AudioOutputStream. It is owned by AudioManager. |
| 55 virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, |
| 56 int sample_rate, |
| 57 char bits_per_sample) = 0; |
| 58 |
| 59 // Factory to create audio recording streams. |
| 60 // |channels| can be 1 or 2. |
| 61 // |sample_rate| is in hertz and can be any value supported by the platform. |
| 62 // |bits_per_sample| can be any value supported by the platform. |
| 63 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, |
| 64 // with 0 suggesting that the implementation use a default value for that |
| 65 // platform. |
| 66 // Returns NULL if the combination of the parameters is not supported, or if |
| 67 // we have reached some other platform specific limit. |
| 68 // |
| 69 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
| 70 // When you are done with it, call |Stop()| and |Close()| to release it. |
| 71 virtual AudioInputStream* MakeAudioInputStream(Format format, int channels, |
| 72 int sample_rate, |
| 73 char bits_per_sample, |
| 74 uint32 samples_per_packet) = 0; |
| 75 |
| 76 // Muting continues playback but effectively the volume is set to zero. |
| 77 // Un-muting returns the volume to the previous level. |
| 78 virtual void MuteAll() = 0; |
| 79 virtual void UnMuteAll() = 0; |
| 80 |
| 81 // Returns message loop used for audio IO. |
| 82 virtual MessageLoop* GetMessageLoop() = 0; |
| 83 |
| 84 // Get AudioManager singleton. |
| 85 // TODO(cpu): Define threading requirements for interacting with AudioManager. |
| 86 static AudioManager* GetAudioManager(); |
| 87 |
| 88 protected: |
| 89 virtual ~AudioManager() {} |
| 90 |
| 91 // Called from GetAudioManager() to initialiaze the instance. |
| 92 virtual void Init() = 0; |
| 93 |
| 94 private: |
| 95 static void Destroy(void*); |
| 96 |
| 97 // Called by GetAudioManager() to create platform-specific audio manager. |
| 98 static AudioManager* CreateAudioManager(); |
| 99 }; |
| 100 |
| 101 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
OLD | NEW |