| 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 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 Loading... |
| 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(IAudioClient** audio_client, |
| 181 IAudioRenderClient** audio_render_client, |
| 182 IAudioClock** audio_clock); |
| 183 |
| 175 // Contains the thread ID of the creating thread. | 184 // Contains the thread ID of the creating thread. |
| 176 base::PlatformThreadId creating_thread_id_; | 185 base::PlatformThreadId creating_thread_id_; |
| 177 | 186 |
| 178 // Our creator, the audio manager needs to be notified when we close. | 187 // Our creator, the audio manager needs to be notified when we close. |
| 179 AudioManagerWin* manager_; | 188 AudioManagerWin* manager_; |
| 180 | 189 |
| 181 // Rendering is driven by this thread (which has no message loop). | 190 // Rendering is driven by this thread (which has no message loop). |
| 182 // All OnMoreData() callbacks will be called from this thread. | 191 // All OnMoreData() callbacks will be called from this thread. |
| 183 scoped_ptr<base::DelegateSimpleThread> render_thread_; | 192 scoped_ptr<base::DelegateSimpleThread> render_thread_; |
| 184 | 193 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 214 // Valid values are AUDCLNT_SHAREMODE_SHARED and AUDCLNT_SHAREMODE_EXCLUSIVE | 223 // Valid values are AUDCLNT_SHAREMODE_SHARED and AUDCLNT_SHAREMODE_EXCLUSIVE |
| 215 // where AUDCLNT_SHAREMODE_SHARED is the default. | 224 // where AUDCLNT_SHAREMODE_SHARED is the default. |
| 216 AUDCLNT_SHAREMODE share_mode_; | 225 AUDCLNT_SHAREMODE share_mode_; |
| 217 | 226 |
| 218 // Counts the number of audio frames written to the endpoint buffer. | 227 // Counts the number of audio frames written to the endpoint buffer. |
| 219 UINT64 num_written_frames_; | 228 UINT64 num_written_frames_; |
| 220 | 229 |
| 221 // Pointer to the client that will deliver audio samples to be played out. | 230 // Pointer to the client that will deliver audio samples to be played out. |
| 222 AudioSourceCallback* source_; | 231 AudioSourceCallback* source_; |
| 223 | 232 |
| 233 // ------------------------------------------------------ |
| 234 // Warning: COM pointers must be marshaled from the audio thread to be used |
| 235 // on any other thread. Do not use any of these interfaces on a thread other |
| 236 // than the audio thread. See MarshalComPointers() and UnmarshalComPointers() |
| 237 // for marshaling pointers to the render thread. |
| 238 |
| 239 // Stream into which the COM pointers below are marshaled so that they can |
| 240 // be used on another thread. |
| 241 IStream* com_stream_; |
| 242 |
| 243 // Windows Audio Session API (WASAPI) interfaces. |
| 244 |
| 224 // An IAudioClient interface which enables a client to create and initialize | 245 // An IAudioClient interface which enables a client to create and initialize |
| 225 // an audio stream between an audio application and the audio engine. | 246 // an audio stream between an audio application and the audio engine. |
| 226 base::win::ScopedComPtr<IAudioClient> audio_client_; | 247 base::win::ScopedComPtr<IAudioClient> audio_client_; |
| 227 | 248 |
| 228 // The IAudioRenderClient interface enables a client to write output | 249 // The IAudioRenderClient interface enables a client to write output |
| 229 // data to a rendering endpoint buffer. | 250 // data to a rendering endpoint buffer. |
| 230 base::win::ScopedComPtr<IAudioRenderClient> audio_render_client_; | 251 base::win::ScopedComPtr<IAudioRenderClient> audio_render_client_; |
| 231 | 252 |
| 253 base::win::ScopedComPtr<IAudioClock> audio_clock_; |
| 254 // ------------------------------------------------------ |
| 255 |
| 232 // The audio engine will signal this event each time a buffer becomes | 256 // The audio engine will signal this event each time a buffer becomes |
| 233 // ready to be filled by the client. | 257 // ready to be filled by the client. |
| 234 base::win::ScopedHandle audio_samples_render_event_; | 258 base::win::ScopedHandle audio_samples_render_event_; |
| 235 | 259 |
| 236 // This event will be signaled when rendering shall stop. | 260 // This event will be signaled when rendering shall stop. |
| 237 base::win::ScopedHandle stop_render_event_; | 261 base::win::ScopedHandle stop_render_event_; |
| 238 | 262 |
| 239 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 263 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 240 scoped_ptr<AudioBus> audio_bus_; | 264 scoped_ptr<AudioBus> audio_bus_; |
| 241 | 265 |
| 242 base::win::ScopedComPtr<IAudioClock> audio_clock_; | |
| 243 | |
| 244 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioOutputStream); | 266 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioOutputStream); |
| 245 }; | 267 }; |
| 246 | 268 |
| 247 } // namespace media | 269 } // namespace media |
| 248 | 270 |
| 249 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_ | 271 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_ |
| OLD | NEW |