| 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. The | |
| 135 // marshal method must be called on the audio manager thread, while unmarshal | |
| 136 // must be called on |capture_thread_|. | |
| 137 bool MarshalComPointers(); | |
| 138 void UnmarshalComPointers( | |
| 139 base::win::ScopedComPtr<IAudioCaptureClient>* audio_capture_client); | |
| 140 | |
| 141 // Our creator, the audio manager needs to be notified when we close. | 134 // Our creator, the audio manager needs to be notified when we close. |
| 142 AudioManagerWin* manager_; | 135 AudioManagerWin* manager_; |
| 143 | 136 |
| 144 // Capturing is driven by this thread (which has no message loop). | 137 // Capturing is driven by this thread (which has no message loop). |
| 145 // All OnData() callbacks will be called from this thread. | 138 // All OnData() callbacks will be called from this thread. |
| 146 base::DelegateSimpleThread* capture_thread_; | 139 base::DelegateSimpleThread* capture_thread_; |
| 147 | 140 |
| 148 // Contains the desired audio format which is set up at construction. | 141 // Contains the desired audio format which is set up at construction. |
| 149 WAVEFORMATEX format_; | 142 WAVEFORMATEX format_; |
| 150 | 143 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 179 // Converts a raw performance counter value to 100-nanosecond unit. | 172 // Converts a raw performance counter value to 100-nanosecond unit. |
| 180 double perf_count_to_100ns_units_; | 173 double perf_count_to_100ns_units_; |
| 181 | 174 |
| 182 // Conversion factor used in delay-estimation calculations. | 175 // Conversion factor used in delay-estimation calculations. |
| 183 // Converts from milliseconds to audio frames. | 176 // Converts from milliseconds to audio frames. |
| 184 double ms_to_frame_count_; | 177 double ms_to_frame_count_; |
| 185 | 178 |
| 186 // Pointer to the object that will receive the recorded audio samples. | 179 // Pointer to the object that will receive the recorded audio samples. |
| 187 AudioInputCallback* sink_; | 180 AudioInputCallback* sink_; |
| 188 | 181 |
| 189 // ------------------------------------------------------ | 182 // Windows Multimedia Device (MMDevice) API interfaces. |
| 190 // Warning: COM pointers must be marshaled from the audio thread to be used | |
| 191 // on any other thread. Do not use any of these interfaces on a thread other | |
| 192 // than the audio thread. See MarshalComPointers() and UnmarshalComPointers() | |
| 193 // for marshaling pointers to the capture thread. | |
| 194 | 183 |
| 195 // Stream into which the COM pointers below are marshaled so that they can | |
| 196 // be used on another thread. | |
| 197 base::win::ScopedComPtr<IStream> com_stream_; | |
| 198 | |
| 199 // Windows Multimedia Device (MMDevice) API interfaces. | |
| 200 // An IMMDevice interface which represents an audio endpoint device. | 184 // An IMMDevice interface which represents an audio endpoint device. |
| 201 base::win::ScopedComPtr<IMMDevice> endpoint_device_; | 185 base::win::ScopedComPtr<IMMDevice> endpoint_device_; |
| 202 | 186 |
| 203 // Windows Audio Session API (WASAPI) interfaces. | 187 // Windows Audio Session API (WASAPI) interfaces. |
| 204 | 188 |
| 205 // An IAudioClient interface which enables a client to create and initialize | 189 // An IAudioClient interface which enables a client to create and initialize |
| 206 // an audio stream between an audio application and the audio engine. | 190 // an audio stream between an audio application and the audio engine. |
| 207 base::win::ScopedComPtr<IAudioClient> audio_client_; | 191 base::win::ScopedComPtr<IAudioClient> audio_client_; |
| 208 | 192 |
| 209 // Loopback IAudioClient doesn't support event-driven mode, so a separate | 193 // Loopback IAudioClient doesn't support event-driven mode, so a separate |
| 210 // IAudioClient is needed to receive notifications when data is available in | 194 // IAudioClient is needed to receive notifications when data is available in |
| 211 // the buffer. For loopback input |audio_client_| is used to receive data, | 195 // the buffer. For loopback input |audio_client_| is used to receive data, |
| 212 // while |audio_render_client_for_loopback_| is used to get notifications | 196 // while |audio_render_client_for_loopback_| is used to get notifications |
| 213 // when a new buffer is ready. See comment in InitializeAudioEngine() for | 197 // when a new buffer is ready. See comment in InitializeAudioEngine() for |
| 214 // details. | 198 // details. |
| 215 base::win::ScopedComPtr<IAudioClient> audio_render_client_for_loopback_; | 199 base::win::ScopedComPtr<IAudioClient> audio_render_client_for_loopback_; |
| 216 | 200 |
| 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 |
| 217 // The ISimpleAudioVolume interface enables a client to control the | 205 // The ISimpleAudioVolume interface enables a client to control the |
| 218 // master volume level of an audio session. | 206 // master volume level of an audio session. |
| 219 // The volume-level is a value in the range 0.0 to 1.0. | 207 // The volume-level is a value in the range 0.0 to 1.0. |
| 220 // This interface does only work with shared-mode streams. | 208 // This interface does only work with shared-mode streams. |
| 221 base::win::ScopedComPtr<ISimpleAudioVolume> simple_audio_volume_; | 209 base::win::ScopedComPtr<ISimpleAudioVolume> simple_audio_volume_; |
| 222 | 210 |
| 223 // The IAudioCaptureClient interface enables a client to read input data | |
| 224 // from a capture endpoint buffer. | |
| 225 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; | |
| 226 // ------------------------------------------------------ | |
| 227 | |
| 228 // The audio engine will signal this event each time a buffer has been | 211 // The audio engine will signal this event each time a buffer has been |
| 229 // recorded. | 212 // recorded. |
| 230 base::win::ScopedHandle audio_samples_ready_event_; | 213 base::win::ScopedHandle audio_samples_ready_event_; |
| 231 | 214 |
| 232 // This event will be signaled when capturing shall stop. | 215 // This event will be signaled when capturing shall stop. |
| 233 base::win::ScopedHandle stop_capture_event_; | 216 base::win::ScopedHandle stop_capture_event_; |
| 234 | 217 |
| 235 // Extra audio bus used for storage of deinterleaved data for the OnData | 218 // Extra audio bus used for storage of deinterleaved data for the OnData |
| 236 // callback. | 219 // callback. |
| 237 scoped_ptr<media::AudioBus> audio_bus_; | 220 scoped_ptr<media::AudioBus> audio_bus_; |
| 238 | 221 |
| 239 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); | 222 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); |
| 240 }; | 223 }; |
| 241 | 224 |
| 242 } // namespace media | 225 } // namespace media |
| 243 | 226 |
| 244 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 227 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
| OLD | NEW |