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

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

Powered by Google App Engine
This is Rietveld 408576698