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

Side by Side Diff: media/audio/win/audio_low_latency_output_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: Simplify. 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 AudioOutputStream for Windows using Windows Core Audio 5 // Implementation of AudioOutputStream for Windows using Windows Core Audio
6 // WASAPI for low latency rendering. 6 // WASAPI for low latency rendering.
7 // 7 //
8 // Overview of operation and performance: 8 // Overview of operation and performance:
9 // 9 //
10 // - An object of WASAPIAudioOutputStream is created by the AudioManager 10 // - An object of WASAPIAudioOutputStream is created by the AudioManager
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 bool started() const { return render_thread_.get() != NULL; } 150 bool started() const { return render_thread_.get() != NULL; }
151 151
152 private: 152 private:
153 // DelegateSimpleThread::Delegate implementation. 153 // DelegateSimpleThread::Delegate implementation.
154 virtual void Run() override; 154 virtual void Run() override;
155 155
156 // Core part of the thread loop which controls the actual rendering. 156 // Core part of the thread loop which controls the actual rendering.
157 // Checks available amount of space in the endpoint buffer and reads 157 // Checks available amount of space in the endpoint buffer and reads
158 // data from the client to fill up the buffer without causing audio 158 // data from the client to fill up the buffer without causing audio
159 // glitches. 159 // glitches.
160 bool RenderAudioFromSource(UINT64 device_frequency); 160 bool RenderAudioFromSource(UINT64 device_frequency,
161 IAudioClient* thread_audio_client,
162 IAudioRenderClient* thread_audio_render_client,
163 IAudioClock* thread_audio_clock);
161 164
162 // Called when the device will be opened in exclusive mode and use the 165 // Called when the device will be opened in exclusive mode and use the
163 // application specified format. 166 // application specified format.
164 // TODO(henrika): rewrite and move to CoreAudioUtil when removing flag 167 // TODO(henrika): rewrite and move to CoreAudioUtil when removing flag
165 // for exclusive audio mode. 168 // for exclusive audio mode.
166 HRESULT ExclusiveModeInitialization(IAudioClient* client, 169 HRESULT ExclusiveModeInitialization(IAudioClient* client,
167 HANDLE event_handle, 170 HANDLE event_handle,
168 uint32* endpoint_buffer_size); 171 uint32* endpoint_buffer_size);
169 172
170 // If |render_thread_| is valid, sets |stop_render_event_| and blocks until 173 // If |render_thread_| is valid, sets |stop_render_event_| and blocks until
171 // the thread has stopped. |stop_render_event_| is reset after the call. 174 // the thread has stopped. |stop_render_event_| is reset after the call.
172 // |source_| is set to NULL. 175 // |source_| is set to NULL.
173 void StopThread(); 176 void StopThread();
174 177
178 // Handles sharing of COM pointers between the audio and render threads.
179 bool MarshalComPointers();
180 bool UnmarshalComPointers(
181 base::win::ScopedComPtr<IAudioClient>* audio_client,
182 base::win::ScopedComPtr<IAudioRenderClient>* audio_render_client,
183 base::win::ScopedComPtr<IAudioClock>* audio_clock);
184
175 // Contains the thread ID of the creating thread. 185 // Contains the thread ID of the creating thread.
176 base::PlatformThreadId creating_thread_id_; 186 base::PlatformThreadId creating_thread_id_;
177 187
178 // Our creator, the audio manager needs to be notified when we close. 188 // Our creator, the audio manager needs to be notified when we close.
179 AudioManagerWin* manager_; 189 AudioManagerWin* manager_;
180 190
181 // Rendering is driven by this thread (which has no message loop). 191 // Rendering is driven by this thread (which has no message loop).
182 // All OnMoreData() callbacks will be called from this thread. 192 // All OnMoreData() callbacks will be called from this thread.
183 scoped_ptr<base::DelegateSimpleThread> render_thread_; 193 scoped_ptr<base::DelegateSimpleThread> render_thread_;
184 194
(...skipping 29 matching lines...) Expand all
214 // Valid values are AUDCLNT_SHAREMODE_SHARED and AUDCLNT_SHAREMODE_EXCLUSIVE 224 // Valid values are AUDCLNT_SHAREMODE_SHARED and AUDCLNT_SHAREMODE_EXCLUSIVE
215 // where AUDCLNT_SHAREMODE_SHARED is the default. 225 // where AUDCLNT_SHAREMODE_SHARED is the default.
216 AUDCLNT_SHAREMODE share_mode_; 226 AUDCLNT_SHAREMODE share_mode_;
217 227
218 // Counts the number of audio frames written to the endpoint buffer. 228 // Counts the number of audio frames written to the endpoint buffer.
219 UINT64 num_written_frames_; 229 UINT64 num_written_frames_;
220 230
221 // Pointer to the client that will deliver audio samples to be played out. 231 // Pointer to the client that will deliver audio samples to be played out.
222 AudioSourceCallback* source_; 232 AudioSourceCallback* source_;
223 233
234 // ------------------------------------------------------
235 // Warning: COM pointers must be marshaled from the audio thread to be used
236 // on any other thread. Do not use any of these interfaces on a thread other
237 // than the audio thread. See MarshalComPointers() and UnmarshalComPointers()
238 // for marshaling pointers to the render thread.
239
240 // Stream into which the COM pointers below are marshaled so that they can
241 // be used on another thread.
242 base::win::ScopedComPtr<IStream> com_stream_;
243
244 // Windows Audio Session API (WASAPI) interfaces.
245
224 // An IAudioClient interface which enables a client to create and initialize 246 // An IAudioClient interface which enables a client to create and initialize
225 // an audio stream between an audio application and the audio engine. 247 // an audio stream between an audio application and the audio engine.
226 base::win::ScopedComPtr<IAudioClient> audio_client_; 248 base::win::ScopedComPtr<IAudioClient> audio_client_;
227 249
228 // The IAudioRenderClient interface enables a client to write output 250 // The IAudioRenderClient interface enables a client to write output
229 // data to a rendering endpoint buffer. 251 // data to a rendering endpoint buffer.
230 base::win::ScopedComPtr<IAudioRenderClient> audio_render_client_; 252 base::win::ScopedComPtr<IAudioRenderClient> audio_render_client_;
231 253
254 base::win::ScopedComPtr<IAudioClock> audio_clock_;
255 // ------------------------------------------------------
256
232 // The audio engine will signal this event each time a buffer becomes 257 // The audio engine will signal this event each time a buffer becomes
233 // ready to be filled by the client. 258 // ready to be filled by the client.
234 base::win::ScopedHandle audio_samples_render_event_; 259 base::win::ScopedHandle audio_samples_render_event_;
235 260
236 // This event will be signaled when rendering shall stop. 261 // This event will be signaled when rendering shall stop.
237 base::win::ScopedHandle stop_render_event_; 262 base::win::ScopedHandle stop_render_event_;
238 263
239 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 264 // Container for retrieving data from AudioSourceCallback::OnMoreData().
240 scoped_ptr<AudioBus> audio_bus_; 265 scoped_ptr<AudioBus> audio_bus_;
241 266
242 base::win::ScopedComPtr<IAudioClock> audio_clock_;
243
244 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioOutputStream); 267 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioOutputStream);
245 }; 268 };
246 269
247 } // namespace media 270 } // namespace media
248 271
249 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_ 272 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698