OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_OUTPUT_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_H_ |
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_H_ |
7 | 7 |
8 // Low-level audio output support. To make sound there are 3 objects involved: | 8 // Low-level audio output support. To make sound there are 3 objects involved: |
9 // - AudioSource : produces audio samples on a pull model. Implements | 9 // - AudioSource : produces audio samples on a pull model. Implements |
10 // the AudioSourceCallback interface. | 10 // the AudioSourceCallback interface. |
(...skipping 15 matching lines...) Expand all Loading... |
26 // idiosyncrasies of each platform. Non-goals: | 26 // idiosyncrasies of each platform. Non-goals: |
27 // - Positional, 3d audio | 27 // - Positional, 3d audio |
28 // - Dependence on non-default libraries such as DirectX 9, 10, XAudio | 28 // - Dependence on non-default libraries such as DirectX 9, 10, XAudio |
29 // - Digital signal processing or effects | 29 // - Digital signal processing or effects |
30 // - Extra features if a specific hardware is installed (EAX, X-fi) | 30 // - Extra features if a specific hardware is installed (EAX, X-fi) |
31 // | 31 // |
32 // The primary client of this facility is audio coming from several tabs. | 32 // The primary client of this facility is audio coming from several tabs. |
33 // Specifically for this case we avoid supporting complex formats such as MP3 | 33 // Specifically for this case we avoid supporting complex formats such as MP3 |
34 // or WMA. Complex format decoding should be done by the renderers. | 34 // or WMA. Complex format decoding should be done by the renderers. |
35 | 35 |
| 36 |
36 // Models an audio stream that gets rendered to the audio hardware output. | 37 // Models an audio stream that gets rendered to the audio hardware output. |
37 // Because we support more audio streams than physically available channels | 38 // Because we support more audio streams than physically available channels |
38 // a given AudioOutputStream might or might not talk directly to hardware. | 39 // a given AudioOutputStream might or might not talk directly to hardware. |
39 class AudioOutputStream { | 40 class AudioOutputStream { |
40 public: | 41 public: |
41 // Audio sources must implement AudioSourceCallback. This interface will be | 42 // Audio sources must implement AudioSourceCallback. This interface will be |
42 // called in a random thread which very likely is a high priority thread. Do | 43 // called in a random thread which very likely is a high priority thread. Do |
43 // not rely on using this thread TLS or make calls that alter the thread | 44 // not rely on using this thread TLS or make calls that alter the thread |
44 // itself such as creating Windows or initializing COM. | 45 // itself such as creating Windows or initializing COM. |
45 class AudioSourceCallback { | 46 class AudioSourceCallback { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // objects. Provides some convenience functions that avoid the need to provide | 100 // objects. Provides some convenience functions that avoid the need to provide |
100 // iterators over the existing streams. | 101 // iterators over the existing streams. |
101 class AudioManager { | 102 class AudioManager { |
102 public: | 103 public: |
103 enum Format { | 104 enum Format { |
104 AUDIO_PCM_LINEAR, // Pulse code modulation means 'raw' amplitude samples. | 105 AUDIO_PCM_LINEAR, // Pulse code modulation means 'raw' amplitude samples. |
105 AUDIO_PCM_DELTA, // Delta-encoded pulse code modulation. | 106 AUDIO_PCM_DELTA, // Delta-encoded pulse code modulation. |
106 AUDIO_MOCK // Creates a dummy AudioOutputStream object. | 107 AUDIO_MOCK // Creates a dummy AudioOutputStream object. |
107 }; | 108 }; |
108 | 109 |
| 110 // Telephone quality sample rate, mostly for speech-only audio. |
| 111 static const int kTelephoneSampleRate = 8000; |
| 112 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. |
| 113 static const int kAudioCDSampleRate = 44100; |
| 114 // Digital Audio Tape sample rate. |
| 115 static const int kAudioDATSampleRate = 48000; |
| 116 |
109 // Factory for all the supported stream formats. At this moment |channels| | 117 // Factory for all the supported stream formats. At this moment |channels| |
110 // can be 1 (mono) or 2 (stereo). The |sample_rate| is in hertz and can be | 118 // can be 1 (mono) or 2 (stereo). The |sample_rate| is in hertz and can be |
111 // any value supported by the underlying platform. For some future formats | 119 // any value supported by the underlying platform. For some future formats |
112 // the |sample_rate| and |bits_per_sample| can take special values. | 120 // the |sample_rate| and |bits_per_sample| can take special values. |
113 // Returns NULL if the combination of the parameters is not supported, or if | 121 // Returns NULL if the combination of the parameters is not supported, or if |
114 // we have reached some other platform specific limit. | 122 // we have reached some other platform specific limit. |
115 // | 123 // |
116 // Do not free the returned AudioOutputStream. It is owned by AudioManager. | 124 // Do not free the returned AudioOutputStream. It is owned by AudioManager. |
117 virtual AudioOutputStream* MakeAudioStream(Format format, int channels, | 125 virtual AudioOutputStream* MakeAudioStream(Format format, int channels, |
118 int sample_rate, | 126 int sample_rate, |
119 char bits_per_sample) = 0; | 127 char bits_per_sample) = 0; |
120 | 128 |
121 // Muting continues playback but effectively the volume is set to zero. | 129 // Muting continues playback but effectively the volume is set to zero. |
122 // Un-muting returns the volume to the previous level. | 130 // Un-muting returns the volume to the previous level. |
123 virtual void MuteAll() = 0; | 131 virtual void MuteAll() = 0; |
124 virtual void UnMuteAll() = 0; | 132 virtual void UnMuteAll() = 0; |
125 | 133 |
| 134 // For testing purposes only. Returns the internal buffer of the last |
| 135 // AUDIO_MOCK AudioOutputStream closed. Returns NULL if none closed yet. |
| 136 // The buffer size is the same as passed to AudioOutputStream::Open(). |
| 137 virtual const void* GetLastMockBuffer() = 0; |
| 138 |
| 139 // Get AudioManager singleton. |
| 140 // TODO(cpu): Define threading requirements for interacting with AudioManager. |
| 141 static AudioManager* GetAudioManager(); |
| 142 |
126 protected: | 143 protected: |
127 virtual ~AudioManager() {} | 144 virtual ~AudioManager() {} |
128 }; | 145 }; |
129 | 146 |
130 // Get AudioManager singleton. | |
131 // TODO(cpu): Define threading requirements for interacting with AudioManager. | |
132 AudioManager* GetAudioManager(); | |
133 | 147 |
134 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_H_ | 148 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_H_ |
135 | 149 |
OLD | NEW |