Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: media/audio/win/audio_low_latency_input_win.h

Issue 1097553003: Switch to STA mode for audio thread and WASAPI I/O streams. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 bool UnmarshalComPointers(
139 base::win::ScopedComPtr<IAudioCaptureClient>* audio_capture_client);
140
134 // Our creator, the audio manager needs to be notified when we close. 141 // Our creator, the audio manager needs to be notified when we close.
135 AudioManagerWin* manager_; 142 AudioManagerWin* manager_;
136 143
137 // Capturing is driven by this thread (which has no message loop). 144 // Capturing is driven by this thread (which has no message loop).
138 // All OnData() callbacks will be called from this thread. 145 // All OnData() callbacks will be called from this thread.
139 base::DelegateSimpleThread* capture_thread_; 146 base::DelegateSimpleThread* capture_thread_;
140 147
141 // Contains the desired audio format which is set up at construction. 148 // Contains the desired audio format which is set up at construction.
142 WAVEFORMATEX format_; 149 WAVEFORMATEX format_;
143 150
(...skipping 28 matching lines...) Expand all
172 // Converts a raw performance counter value to 100-nanosecond unit. 179 // Converts a raw performance counter value to 100-nanosecond unit.
173 double perf_count_to_100ns_units_; 180 double perf_count_to_100ns_units_;
174 181
175 // Conversion factor used in delay-estimation calculations. 182 // Conversion factor used in delay-estimation calculations.
176 // Converts from milliseconds to audio frames. 183 // Converts from milliseconds to audio frames.
177 double ms_to_frame_count_; 184 double ms_to_frame_count_;
178 185
179 // Pointer to the object that will receive the recorded audio samples. 186 // Pointer to the object that will receive the recorded audio samples.
180 AudioInputCallback* sink_; 187 AudioInputCallback* sink_;
181 188
189 // ------------------------------------------------------
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
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
182 // Windows Multimedia Device (MMDevice) API interfaces. 199 // Windows Multimedia Device (MMDevice) API interfaces.
183
184 // An IMMDevice interface which represents an audio endpoint device. 200 // An IMMDevice interface which represents an audio endpoint device.
185 base::win::ScopedComPtr<IMMDevice> endpoint_device_; 201 base::win::ScopedComPtr<IMMDevice> endpoint_device_;
186 202
187 // Windows Audio Session API (WASAPI) interfaces. 203 // Windows Audio Session API (WASAPI) interfaces.
188 204
189 // An IAudioClient interface which enables a client to create and initialize 205 // An IAudioClient interface which enables a client to create and initialize
190 // an audio stream between an audio application and the audio engine. 206 // an audio stream between an audio application and the audio engine.
191 base::win::ScopedComPtr<IAudioClient> audio_client_; 207 base::win::ScopedComPtr<IAudioClient> audio_client_;
192 208
193 // Loopback IAudioClient doesn't support event-driven mode, so a separate 209 // Loopback IAudioClient doesn't support event-driven mode, so a separate
194 // IAudioClient is needed to receive notifications when data is available in 210 // IAudioClient is needed to receive notifications when data is available in
195 // the buffer. For loopback input |audio_client_| is used to receive data, 211 // the buffer. For loopback input |audio_client_| is used to receive data,
196 // while |audio_render_client_for_loopback_| is used to get notifications 212 // while |audio_render_client_for_loopback_| is used to get notifications
197 // when a new buffer is ready. See comment in InitializeAudioEngine() for 213 // when a new buffer is ready. See comment in InitializeAudioEngine() for
198 // details. 214 // details.
199 base::win::ScopedComPtr<IAudioClient> audio_render_client_for_loopback_; 215 base::win::ScopedComPtr<IAudioClient> audio_render_client_for_loopback_;
200 216
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 217 // The ISimpleAudioVolume interface enables a client to control the
206 // master volume level of an audio session. 218 // master volume level of an audio session.
207 // The volume-level is a value in the range 0.0 to 1.0. 219 // The volume-level is a value in the range 0.0 to 1.0.
208 // This interface does only work with shared-mode streams. 220 // This interface does only work with shared-mode streams.
209 base::win::ScopedComPtr<ISimpleAudioVolume> simple_audio_volume_; 221 base::win::ScopedComPtr<ISimpleAudioVolume> simple_audio_volume_;
210 222
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
211 // The audio engine will signal this event each time a buffer has been 228 // The audio engine will signal this event each time a buffer has been
212 // recorded. 229 // recorded.
213 base::win::ScopedHandle audio_samples_ready_event_; 230 base::win::ScopedHandle audio_samples_ready_event_;
214 231
215 // This event will be signaled when capturing shall stop. 232 // This event will be signaled when capturing shall stop.
216 base::win::ScopedHandle stop_capture_event_; 233 base::win::ScopedHandle stop_capture_event_;
217 234
218 // Extra audio bus used for storage of deinterleaved data for the OnData 235 // Extra audio bus used for storage of deinterleaved data for the OnData
219 // callback. 236 // callback.
220 scoped_ptr<media::AudioBus> audio_bus_; 237 scoped_ptr<media::AudioBus> audio_bus_;
221 238
222 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); 239 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream);
223 }; 240 };
224 241
225 } // namespace media 242 } // namespace media
226 243
227 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ 244 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698