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 #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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // two buffers of |packet_size| size are created, one will be locked for | 84 // two buffers of |packet_size| size are created, one will be locked for |
85 // playback and one will be ready to be filled in the call to | 85 // playback and one will be ready to be filled in the call to |
86 // AudioSourceCallback::OnMoreData(). | 86 // AudioSourceCallback::OnMoreData(). |
87 // | 87 // |
88 // TODO(ajwong): Streams are not reusable, so try to move packet_size into the | 88 // TODO(ajwong): Streams are not reusable, so try to move packet_size into the |
89 // constructor. | 89 // constructor. |
90 virtual bool Open(size_t packet_size) = 0; | 90 virtual bool Open(size_t packet_size) = 0; |
91 | 91 |
92 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). | 92 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). |
93 // Since implementor of AudioOutputStream may have internal buffers, right | 93 // Since implementor of AudioOutputStream may have internal buffers, right |
94 // after calling this method initial buffers are fetched. User of this | 94 // after calling this method initial buffers are fetched. |
95 // object should prepare |AudioOutputStream::GetNumBuffers()| before calling | |
96 // AudioOutputStream::Start(). | |
97 // | 95 // |
98 // The output stream does not take ownership of this callback. | 96 // The output stream does not take ownership of this callback. |
99 virtual void Start(AudioSourceCallback* callback) = 0; | 97 virtual void Start(AudioSourceCallback* callback) = 0; |
100 | 98 |
101 // Stops playing audio. Effect might not be instantaneous as the hardware | 99 // Stops playing audio. Effect might not be instantaneous as the hardware |
102 // might have locked audio data that is processing. | 100 // might have locked audio data that is processing. |
103 virtual void Stop() = 0; | 101 virtual void Stop() = 0; |
104 | 102 |
105 // Sets the relative volume, with range [0.0, 1.0] inclusive. For mono audio | 103 // Sets the relative volume, with range [0.0, 1.0] inclusive. For mono audio |
106 // sources the volume must be the same in both channels. | 104 // sources the volume must be the same in both channels. |
107 virtual void SetVolume(double left_level, double right_level) = 0; | 105 virtual void SetVolume(double left_level, double right_level) = 0; |
108 | 106 |
109 // Gets the relative volume, with range [0.0, 1.0] inclusive. For mono audio | 107 // Gets the relative volume, with range [0.0, 1.0] inclusive. For mono audio |
110 // sources the level is returned in both channels. | 108 // sources the level is returned in both channels. |
111 virtual void GetVolume(double* left_level, double* right_level) = 0; | 109 virtual void GetVolume(double* left_level, double* right_level) = 0; |
112 | 110 |
113 // Close the stream. This also generates AudioSourceCallback::OnClose(). | 111 // Close the stream. This also generates AudioSourceCallback::OnClose(). |
114 // After calling this method, the object should not be used anymore. | 112 // After calling this method, the object should not be used anymore. |
115 virtual void Close() = 0; | 113 virtual void Close() = 0; |
116 | 114 |
117 // Gets the number of internal buffers used in this output stream. This | |
118 // method is useful for providing information about how user of this object | |
119 // should prepare initial buffers before calling AudioOutputStream::Start(). | |
120 virtual size_t GetNumBuffers() = 0; | |
121 | |
122 protected: | 115 protected: |
123 virtual ~AudioOutputStream() {} | 116 virtual ~AudioOutputStream() {} |
124 }; | 117 }; |
125 | 118 |
126 // Manages all audio resources. In particular it owns the AudioOutputStream | 119 // Manages all audio resources. In particular it owns the AudioOutputStream |
127 // objects. Provides some convenience functions that avoid the need to provide | 120 // objects. Provides some convenience functions that avoid the need to provide |
128 // iterators over the existing streams. | 121 // iterators over the existing streams. |
129 class AudioManager { | 122 class AudioManager { |
130 public: | 123 public: |
131 enum Format { | 124 enum Format { |
(...skipping 25 matching lines...) Expand all Loading... |
157 // Do not free the returned AudioOutputStream. It is owned by AudioManager. | 150 // Do not free the returned AudioOutputStream. It is owned by AudioManager. |
158 virtual AudioOutputStream* MakeAudioStream(Format format, int channels, | 151 virtual AudioOutputStream* MakeAudioStream(Format format, int channels, |
159 int sample_rate, | 152 int sample_rate, |
160 char bits_per_sample) = 0; | 153 char bits_per_sample) = 0; |
161 | 154 |
162 // Muting continues playback but effectively the volume is set to zero. | 155 // Muting continues playback but effectively the volume is set to zero. |
163 // Un-muting returns the volume to the previous level. | 156 // Un-muting returns the volume to the previous level. |
164 virtual void MuteAll() = 0; | 157 virtual void MuteAll() = 0; |
165 virtual void UnMuteAll() = 0; | 158 virtual void UnMuteAll() = 0; |
166 | 159 |
167 // For testing purposes only. Returns the internal buffer of the last | |
168 // AUDIO_MOCK AudioOutputStream closed. Returns NULL if none closed yet. | |
169 // The buffer size is the same as passed to AudioOutputStream::Open(). | |
170 virtual const void* GetLastMockBuffer() = 0; | |
171 | |
172 // Get AudioManager singleton. | 160 // Get AudioManager singleton. |
173 // TODO(cpu): Define threading requirements for interacting with AudioManager. | 161 // TODO(cpu): Define threading requirements for interacting with AudioManager. |
174 static AudioManager* GetAudioManager(); | 162 static AudioManager* GetAudioManager(); |
175 | 163 |
176 protected: | 164 protected: |
177 virtual ~AudioManager() {} | 165 virtual ~AudioManager() {} |
178 }; | 166 }; |
179 | 167 |
180 | 168 |
181 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_H_ | 169 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_H_ |
OLD | NEW |