OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation of AudioInputStream for Windows using Windows Core Audio | 5 // Implementation of AudioInputStream for Windows using Windows Core Audio |
6 // WASAPI for low latency capturing. | 6 // WASAPI for low latency capturing. |
7 // | 7 // |
8 // Overview of operation: | 8 // Overview of operation: |
9 // | 9 // |
10 // - An object of WASAPIAudioInputStream is created by the AudioManager | 10 // - An object of WASAPIAudioInputStream is created by the AudioManager |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 HRESULT InitializeAudioEngine(); | 124 HRESULT InitializeAudioEngine(); |
125 | 125 |
126 // Retrieves the stream format that the audio engine uses for its internal | 126 // Retrieves the stream format that the audio engine uses for its internal |
127 // processing/mixing of shared-mode streams. | 127 // processing/mixing of shared-mode streams. |
128 // |effects| is a an AudioParameters::effects() flag that will have the | 128 // |effects| is a an AudioParameters::effects() flag that will have the |
129 // DUCKING flag raised for only the default communication device. | 129 // DUCKING flag raised for only the default communication device. |
130 static HRESULT GetMixFormat(const std::string& device_id, | 130 static HRESULT GetMixFormat(const std::string& device_id, |
131 WAVEFORMATEX** device_format, | 131 WAVEFORMATEX** device_format, |
132 int* effects); | 132 int* effects); |
133 | 133 |
134 // Handles sharing of COM pointers between the audio and capture threads. | |
tommi (sloooow) - chröme
2015/04/22 10:31:52
maybe add a note about thread requirements? (these
DaleCurtis
2015/04/22 17:48:54
Done.
| |
135 bool MarshalComPointers(); | |
136 bool UnmarshalComPointers( | |
137 base::win::ScopedComPtr<IAudioCaptureClient>* audio_capture_client); | |
138 | |
134 // Our creator, the audio manager needs to be notified when we close. | 139 // Our creator, the audio manager needs to be notified when we close. |
135 AudioManagerWin* manager_; | 140 AudioManagerWin* manager_; |
136 | 141 |
137 // Capturing is driven by this thread (which has no message loop). | 142 // Capturing is driven by this thread (which has no message loop). |
138 // All OnData() callbacks will be called from this thread. | 143 // All OnData() callbacks will be called from this thread. |
139 base::DelegateSimpleThread* capture_thread_; | 144 base::DelegateSimpleThread* capture_thread_; |
140 | 145 |
141 // Contains the desired audio format which is set up at construction. | 146 // Contains the desired audio format which is set up at construction. |
142 WAVEFORMATEX format_; | 147 WAVEFORMATEX format_; |
143 | 148 |
(...skipping 28 matching lines...) Expand all Loading... | |
172 // Converts a raw performance counter value to 100-nanosecond unit. | 177 // Converts a raw performance counter value to 100-nanosecond unit. |
173 double perf_count_to_100ns_units_; | 178 double perf_count_to_100ns_units_; |
174 | 179 |
175 // Conversion factor used in delay-estimation calculations. | 180 // Conversion factor used in delay-estimation calculations. |
176 // Converts from milliseconds to audio frames. | 181 // Converts from milliseconds to audio frames. |
177 double ms_to_frame_count_; | 182 double ms_to_frame_count_; |
178 | 183 |
179 // Pointer to the object that will receive the recorded audio samples. | 184 // Pointer to the object that will receive the recorded audio samples. |
180 AudioInputCallback* sink_; | 185 AudioInputCallback* sink_; |
181 | 186 |
187 // ------------------------------------------------------ | |
188 // Warning: COM pointers must be marshaled from the audio thread to be used | |
189 // on any other thread. Do not use any of these interfaces on a thread other | |
190 // than the audio thread. See MarshalComPointers() and UnmarshalComPointers() | |
191 // for marshaling pointers to the capture thread. | |
192 | |
193 // Stream into which the COM pointers below are marshaled so that they can | |
194 // be used on another thread. | |
195 base::win::ScopedComPtr<IStream> com_stream_; | |
196 | |
182 // Windows Multimedia Device (MMDevice) API interfaces. | 197 // Windows Multimedia Device (MMDevice) API interfaces. |
183 | |
184 // An IMMDevice interface which represents an audio endpoint device. | 198 // An IMMDevice interface which represents an audio endpoint device. |
185 base::win::ScopedComPtr<IMMDevice> endpoint_device_; | 199 base::win::ScopedComPtr<IMMDevice> endpoint_device_; |
186 | 200 |
187 // Windows Audio Session API (WASAPI) interfaces. | 201 // Windows Audio Session API (WASAPI) interfaces. |
188 | 202 |
189 // An IAudioClient interface which enables a client to create and initialize | 203 // An IAudioClient interface which enables a client to create and initialize |
190 // an audio stream between an audio application and the audio engine. | 204 // an audio stream between an audio application and the audio engine. |
191 base::win::ScopedComPtr<IAudioClient> audio_client_; | 205 base::win::ScopedComPtr<IAudioClient> audio_client_; |
192 | 206 |
193 // Loopback IAudioClient doesn't support event-driven mode, so a separate | 207 // Loopback IAudioClient doesn't support event-driven mode, so a separate |
194 // IAudioClient is needed to receive notifications when data is available in | 208 // IAudioClient is needed to receive notifications when data is available in |
195 // the buffer. For loopback input |audio_client_| is used to receive data, | 209 // the buffer. For loopback input |audio_client_| is used to receive data, |
196 // while |audio_render_client_for_loopback_| is used to get notifications | 210 // while |audio_render_client_for_loopback_| is used to get notifications |
197 // when a new buffer is ready. See comment in InitializeAudioEngine() for | 211 // when a new buffer is ready. See comment in InitializeAudioEngine() for |
198 // details. | 212 // details. |
199 base::win::ScopedComPtr<IAudioClient> audio_render_client_for_loopback_; | 213 base::win::ScopedComPtr<IAudioClient> audio_render_client_for_loopback_; |
200 | 214 |
201 // The IAudioCaptureClient interface enables a client to read input data | |
202 // from a capture endpoint buffer. | |
203 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; | |
204 | |
205 // The ISimpleAudioVolume interface enables a client to control the | 215 // The ISimpleAudioVolume interface enables a client to control the |
206 // master volume level of an audio session. | 216 // master volume level of an audio session. |
207 // The volume-level is a value in the range 0.0 to 1.0. | 217 // The volume-level is a value in the range 0.0 to 1.0. |
208 // This interface does only work with shared-mode streams. | 218 // This interface does only work with shared-mode streams. |
209 base::win::ScopedComPtr<ISimpleAudioVolume> simple_audio_volume_; | 219 base::win::ScopedComPtr<ISimpleAudioVolume> simple_audio_volume_; |
210 | 220 |
221 // The IAudioCaptureClient interface enables a client to read input data | |
222 // from a capture endpoint buffer. | |
223 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; | |
224 // ------------------------------------------------------ | |
225 | |
211 // The audio engine will signal this event each time a buffer has been | 226 // The audio engine will signal this event each time a buffer has been |
212 // recorded. | 227 // recorded. |
213 base::win::ScopedHandle audio_samples_ready_event_; | 228 base::win::ScopedHandle audio_samples_ready_event_; |
214 | 229 |
215 // This event will be signaled when capturing shall stop. | 230 // This event will be signaled when capturing shall stop. |
216 base::win::ScopedHandle stop_capture_event_; | 231 base::win::ScopedHandle stop_capture_event_; |
217 | 232 |
218 // Extra audio bus used for storage of deinterleaved data for the OnData | 233 // Extra audio bus used for storage of deinterleaved data for the OnData |
219 // callback. | 234 // callback. |
220 scoped_ptr<media::AudioBus> audio_bus_; | 235 scoped_ptr<media::AudioBus> audio_bus_; |
221 | 236 |
222 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); | 237 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); |
223 }; | 238 }; |
224 | 239 |
225 } // namespace media | 240 } // namespace media |
226 | 241 |
227 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 242 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
OLD | NEW |