| 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(IAudioClock* audio_clock, UINT64 device_frequency); | 160 bool RenderAudioFromSource(UINT64 device_frequency); |
| 161 | 161 |
| 162 // Called when the device will be opened in exclusive mode and use the | 162 // Called when the device will be opened in exclusive mode and use the |
| 163 // application specified format. | 163 // application specified format. |
| 164 // TODO(henrika): rewrite and move to CoreAudioUtil when removing flag | 164 // TODO(henrika): rewrite and move to CoreAudioUtil when removing flag |
| 165 // for exclusive audio mode. | 165 // for exclusive audio mode. |
| 166 HRESULT ExclusiveModeInitialization(IAudioClient* client, | 166 HRESULT ExclusiveModeInitialization(IAudioClient* client, |
| 167 HANDLE event_handle, | 167 HANDLE event_handle, |
| 168 uint32* endpoint_buffer_size); | 168 uint32* endpoint_buffer_size); |
| 169 | 169 |
| 170 // If |render_thread_| is valid, sets |stop_render_event_| and blocks until | 170 // If |render_thread_| is valid, sets |stop_render_event_| and blocks until |
| (...skipping 28 matching lines...) Expand all Loading... |
| 199 float volume_; | 199 float volume_; |
| 200 | 200 |
| 201 // Size in audio frames of each audio packet where an audio packet | 201 // Size in audio frames of each audio packet where an audio packet |
| 202 // is defined as the block of data which the source is expected to deliver | 202 // is defined as the block of data which the source is expected to deliver |
| 203 // in each OnMoreData() callback. | 203 // in each OnMoreData() callback. |
| 204 size_t packet_size_frames_; | 204 size_t packet_size_frames_; |
| 205 | 205 |
| 206 // Size in bytes of each audio packet. | 206 // Size in bytes of each audio packet. |
| 207 size_t packet_size_bytes_; | 207 size_t packet_size_bytes_; |
| 208 | 208 |
| 209 // Size in milliseconds of each audio packet. | |
| 210 float packet_size_ms_; | |
| 211 | |
| 212 // Length of the audio endpoint buffer. | 209 // Length of the audio endpoint buffer. |
| 213 uint32 endpoint_buffer_size_frames_; | 210 uint32 endpoint_buffer_size_frames_; |
| 214 | 211 |
| 215 // The target device id or an empty string for the default device. | 212 // The target device id or an empty string for the default device. |
| 216 const std::string device_id_; | 213 const std::string device_id_; |
| 217 | 214 |
| 218 // Defines the role that the system has assigned to an audio endpoint device. | 215 // Defines the role that the system has assigned to an audio endpoint device. |
| 219 ERole device_role_; | 216 ERole device_role_; |
| 220 | 217 |
| 221 // The sharing mode for the connection. | 218 // The sharing mode for the connection. |
| 222 // Valid values are AUDCLNT_SHAREMODE_SHARED and AUDCLNT_SHAREMODE_EXCLUSIVE | 219 // Valid values are AUDCLNT_SHAREMODE_SHARED and AUDCLNT_SHAREMODE_EXCLUSIVE |
| 223 // where AUDCLNT_SHAREMODE_SHARED is the default. | 220 // where AUDCLNT_SHAREMODE_SHARED is the default. |
| 224 AUDCLNT_SHAREMODE share_mode_; | 221 AUDCLNT_SHAREMODE share_mode_; |
| 225 | 222 |
| 226 // Counts the number of audio frames written to the endpoint buffer. | 223 // Counts the number of audio frames written to the endpoint buffer. |
| 227 UINT64 num_written_frames_; | 224 UINT64 num_written_frames_; |
| 228 | 225 |
| 229 // Pointer to the client that will deliver audio samples to be played out. | 226 // Pointer to the client that will deliver audio samples to be played out. |
| 230 AudioSourceCallback* source_; | 227 AudioSourceCallback* source_; |
| 231 | 228 |
| 232 // An IMMDeviceEnumerator interface which represents a device enumerator. | |
| 233 base::win::ScopedComPtr<IMMDeviceEnumerator> device_enumerator_; | |
| 234 | |
| 235 // An IAudioClient interface which enables a client to create and initialize | 229 // An IAudioClient interface which enables a client to create and initialize |
| 236 // an audio stream between an audio application and the audio engine. | 230 // an audio stream between an audio application and the audio engine. |
| 237 base::win::ScopedComPtr<IAudioClient> audio_client_; | 231 base::win::ScopedComPtr<IAudioClient> audio_client_; |
| 238 | 232 |
| 239 // The IAudioRenderClient interface enables a client to write output | 233 // The IAudioRenderClient interface enables a client to write output |
| 240 // data to a rendering endpoint buffer. | 234 // data to a rendering endpoint buffer. |
| 241 base::win::ScopedComPtr<IAudioRenderClient> audio_render_client_; | 235 base::win::ScopedComPtr<IAudioRenderClient> audio_render_client_; |
| 242 | 236 |
| 243 // The audio engine will signal this event each time a buffer becomes | 237 // The audio engine will signal this event each time a buffer becomes |
| 244 // ready to be filled by the client. | 238 // ready to be filled by the client. |
| 245 base::win::ScopedHandle audio_samples_render_event_; | 239 base::win::ScopedHandle audio_samples_render_event_; |
| 246 | 240 |
| 247 // This event will be signaled when rendering shall stop. | 241 // This event will be signaled when rendering shall stop. |
| 248 base::win::ScopedHandle stop_render_event_; | 242 base::win::ScopedHandle stop_render_event_; |
| 249 | 243 |
| 250 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 244 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 251 scoped_ptr<AudioBus> audio_bus_; | 245 scoped_ptr<AudioBus> audio_bus_; |
| 252 | 246 |
| 247 base::win::ScopedComPtr<IAudioClock> audio_clock_; |
| 248 |
| 253 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioOutputStream); | 249 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioOutputStream); |
| 254 }; | 250 }; |
| 255 | 251 |
| 256 } // namespace media | 252 } // namespace media |
| 257 | 253 |
| 258 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_ | 254 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_ |
| OLD | NEW |