| 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 #include "media/audio/win/audio_low_latency_output_win.h" | 5 #include "media/audio/win/audio_low_latency_output_win.h" |
| 6 | 6 |
| 7 #include <Functiondiscoverykeys_devpkey.h> | 7 #include <Functiondiscoverykeys_devpkey.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 packet_size_bytes_(0), | 66 packet_size_bytes_(0), |
| 67 endpoint_buffer_size_frames_(0), | 67 endpoint_buffer_size_frames_(0), |
| 68 device_id_(device_id), | 68 device_id_(device_id), |
| 69 device_role_(device_role), | 69 device_role_(device_role), |
| 70 share_mode_(GetShareMode()), | 70 share_mode_(GetShareMode()), |
| 71 num_written_frames_(0), | 71 num_written_frames_(0), |
| 72 source_(NULL), | 72 source_(NULL), |
| 73 audio_bus_(AudioBus::Create(params)) { | 73 audio_bus_(AudioBus::Create(params)) { |
| 74 DCHECK(manager_); | 74 DCHECK(manager_); |
| 75 | 75 |
| 76 VLOG(1) << "WASAPIAudioOutputStream::WASAPIAudioOutputStream()"; | 76 DVLOG(1) << "WASAPIAudioOutputStream::WASAPIAudioOutputStream()"; |
| 77 VLOG_IF(1, share_mode_ == AUDCLNT_SHAREMODE_EXCLUSIVE) | 77 DVLOG_IF(1, share_mode_ == AUDCLNT_SHAREMODE_EXCLUSIVE) |
| 78 << "Core Audio (WASAPI) EXCLUSIVE MODE is enabled."; | 78 << "Core Audio (WASAPI) EXCLUSIVE MODE is enabled."; |
| 79 | 79 |
| 80 // Load the Avrt DLL if not already loaded. Required to support MMCSS. | 80 // Load the Avrt DLL if not already loaded. Required to support MMCSS. |
| 81 bool avrt_init = avrt::Initialize(); | 81 bool avrt_init = avrt::Initialize(); |
| 82 DCHECK(avrt_init) << "Failed to load the avrt.dll"; | 82 DCHECK(avrt_init) << "Failed to load the avrt.dll"; |
| 83 | 83 |
| 84 // Set up the desired render format specified by the client. We use the | 84 // Set up the desired render format specified by the client. We use the |
| 85 // WAVE_FORMAT_EXTENSIBLE structure to ensure that multiple channel ordering | 85 // WAVE_FORMAT_EXTENSIBLE structure to ensure that multiple channel ordering |
| 86 // and high precision data can be supported. | 86 // and high precision data can be supported. |
| 87 | 87 |
| 88 // Begin with the WAVEFORMATEX structure that specifies the basic format. | 88 // Begin with the WAVEFORMATEX structure that specifies the basic format. |
| 89 WAVEFORMATEX* format = &format_.Format; | 89 WAVEFORMATEX* format = &format_.Format; |
| 90 format->wFormatTag = WAVE_FORMAT_EXTENSIBLE; | 90 format->wFormatTag = WAVE_FORMAT_EXTENSIBLE; |
| 91 format->nChannels = params.channels(); | 91 format->nChannels = params.channels(); |
| 92 format->nSamplesPerSec = params.sample_rate(); | 92 format->nSamplesPerSec = params.sample_rate(); |
| 93 format->wBitsPerSample = params.bits_per_sample(); | 93 format->wBitsPerSample = params.bits_per_sample(); |
| 94 format->nBlockAlign = (format->wBitsPerSample / 8) * format->nChannels; | 94 format->nBlockAlign = (format->wBitsPerSample / 8) * format->nChannels; |
| 95 format->nAvgBytesPerSec = format->nSamplesPerSec * format->nBlockAlign; | 95 format->nAvgBytesPerSec = format->nSamplesPerSec * format->nBlockAlign; |
| 96 format->cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); | 96 format->cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); |
| 97 | 97 |
| 98 // Add the parts which are unique to WAVE_FORMAT_EXTENSIBLE. | 98 // Add the parts which are unique to WAVE_FORMAT_EXTENSIBLE. |
| 99 format_.Samples.wValidBitsPerSample = params.bits_per_sample(); | 99 format_.Samples.wValidBitsPerSample = params.bits_per_sample(); |
| 100 format_.dwChannelMask = CoreAudioUtil::GetChannelConfig(device_id, eRender); | 100 format_.dwChannelMask = CoreAudioUtil::GetChannelConfig(device_id, eRender); |
| 101 format_.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; | 101 format_.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; |
| 102 | 102 |
| 103 // Store size (in different units) of audio packets which we expect to | 103 // Store size (in different units) of audio packets which we expect to |
| 104 // get from the audio endpoint device in each render event. | 104 // get from the audio endpoint device in each render event. |
| 105 packet_size_frames_ = params.frames_per_buffer(); | 105 packet_size_frames_ = params.frames_per_buffer(); |
| 106 packet_size_bytes_ = params.GetBytesPerBuffer(); | 106 packet_size_bytes_ = params.GetBytesPerBuffer(); |
| 107 VLOG(1) << "Number of bytes per audio frame : " << format->nBlockAlign; | 107 DVLOG(1) << "Number of bytes per audio frame : " << format->nBlockAlign; |
| 108 VLOG(1) << "Number of audio frames per packet: " << packet_size_frames_; | 108 DVLOG(1) << "Number of audio frames per packet: " << packet_size_frames_; |
| 109 VLOG(1) << "Number of bytes per packet : " << packet_size_bytes_; | 109 DVLOG(1) << "Number of bytes per packet : " << packet_size_bytes_; |
| 110 VLOG(1) << "Number of milliseconds per packet: " | 110 DVLOG(1) << "Number of milliseconds per packet: " |
| 111 << params.GetBufferDuration().InMillisecondsF(); | 111 << params.GetBufferDuration().InMillisecondsF(); |
| 112 | 112 |
| 113 // All events are auto-reset events and non-signaled initially. | 113 // All events are auto-reset events and non-signaled initially. |
| 114 | 114 |
| 115 // Create the event which the audio engine will signal each time | 115 // Create the event which the audio engine will signal each time |
| 116 // a buffer becomes ready to be processed by the client. | 116 // a buffer becomes ready to be processed by the client. |
| 117 audio_samples_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); | 117 audio_samples_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); |
| 118 DCHECK(audio_samples_render_event_.IsValid()); | 118 DCHECK(audio_samples_render_event_.IsValid()); |
| 119 | 119 |
| 120 // Create the event which will be set in Stop() when capturing shall stop. | 120 // Create the event which will be set in Stop() when capturing shall stop. |
| 121 stop_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); | 121 stop_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL)); |
| 122 DCHECK(stop_render_event_.IsValid()); | 122 DCHECK(stop_render_event_.IsValid()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 WASAPIAudioOutputStream::~WASAPIAudioOutputStream() { | 125 WASAPIAudioOutputStream::~WASAPIAudioOutputStream() { |
| 126 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 126 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool WASAPIAudioOutputStream::Open() { | 129 bool WASAPIAudioOutputStream::Open() { |
| 130 VLOG(1) << "WASAPIAudioOutputStream::Open()"; | 130 DVLOG(1) << "WASAPIAudioOutputStream::Open()"; |
| 131 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 131 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
| 132 if (opened_) | 132 if (opened_) |
| 133 return true; | 133 return true; |
| 134 | 134 |
| 135 DCHECK(!audio_client_.get()); | 135 DCHECK(!audio_client_.get()); |
| 136 DCHECK(!audio_render_client_.get()); | 136 DCHECK(!audio_render_client_.get()); |
| 137 | 137 |
| 138 // Will be set to true if we ended up opening the default communications | 138 // Will be set to true if we ended up opening the default communications |
| 139 // device. | 139 // device. |
| 140 bool communications_device = false; | 140 bool communications_device = false; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (FAILED(hr)) { | 219 if (FAILED(hr)) { |
| 220 LOG(ERROR) << "Failed to get IAudioClock service."; | 220 LOG(ERROR) << "Failed to get IAudioClock service."; |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| 223 | 223 |
| 224 opened_ = true; | 224 opened_ = true; |
| 225 return true; | 225 return true; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void WASAPIAudioOutputStream::Start(AudioSourceCallback* callback) { | 228 void WASAPIAudioOutputStream::Start(AudioSourceCallback* callback) { |
| 229 VLOG(1) << "WASAPIAudioOutputStream::Start()"; | 229 DVLOG(1) << "WASAPIAudioOutputStream::Start()"; |
| 230 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 230 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
| 231 CHECK(callback); | 231 CHECK(callback); |
| 232 CHECK(opened_); | 232 CHECK(opened_); |
| 233 | 233 |
| 234 if (render_thread_) { | 234 if (render_thread_) { |
| 235 CHECK_EQ(callback, source_); | 235 CHECK_EQ(callback, source_); |
| 236 return; | 236 return; |
| 237 } | 237 } |
| 238 | 238 |
| 239 source_ = callback; | 239 source_ = callback; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 264 // Start streaming data between the endpoint buffer and the audio engine. | 264 // Start streaming data between the endpoint buffer and the audio engine. |
| 265 HRESULT hr = audio_client_->Start(); | 265 HRESULT hr = audio_client_->Start(); |
| 266 if (FAILED(hr)) { | 266 if (FAILED(hr)) { |
| 267 PLOG(ERROR) << "Failed to start output streaming: " << std::hex << hr; | 267 PLOG(ERROR) << "Failed to start output streaming: " << std::hex << hr; |
| 268 StopThread(); | 268 StopThread(); |
| 269 callback->OnError(this); | 269 callback->OnError(this); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 void WASAPIAudioOutputStream::Stop() { | 273 void WASAPIAudioOutputStream::Stop() { |
| 274 VLOG(1) << "WASAPIAudioOutputStream::Stop()"; | 274 DVLOG(1) << "WASAPIAudioOutputStream::Stop()"; |
| 275 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 275 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
| 276 if (!render_thread_) | 276 if (!render_thread_) |
| 277 return; | 277 return; |
| 278 | 278 |
| 279 // Stop output audio streaming. | 279 // Stop output audio streaming. |
| 280 HRESULT hr = audio_client_->Stop(); | 280 HRESULT hr = audio_client_->Stop(); |
| 281 if (FAILED(hr)) { | 281 if (FAILED(hr)) { |
| 282 PLOG(ERROR) << "Failed to stop output streaming: " << std::hex << hr; | 282 PLOG(ERROR) << "Failed to stop output streaming: " << std::hex << hr; |
| 283 source_->OnError(this); | 283 source_->OnError(this); |
| 284 } | 284 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 299 // would fail with AUDCLNT_E_BUFFER_ERROR at IAudioRenderClient::GetBuffer(). | 299 // would fail with AUDCLNT_E_BUFFER_ERROR at IAudioRenderClient::GetBuffer(). |
| 300 // This check is is only needed for shared-mode streams. | 300 // This check is is only needed for shared-mode streams. |
| 301 if (share_mode_ == AUDCLNT_SHAREMODE_SHARED) { | 301 if (share_mode_ == AUDCLNT_SHAREMODE_SHARED) { |
| 302 UINT32 num_queued_frames = 0; | 302 UINT32 num_queued_frames = 0; |
| 303 audio_client_->GetCurrentPadding(&num_queued_frames); | 303 audio_client_->GetCurrentPadding(&num_queued_frames); |
| 304 DCHECK_EQ(0u, num_queued_frames); | 304 DCHECK_EQ(0u, num_queued_frames); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 void WASAPIAudioOutputStream::Close() { | 308 void WASAPIAudioOutputStream::Close() { |
| 309 VLOG(1) << "WASAPIAudioOutputStream::Close()"; | 309 DVLOG(1) << "WASAPIAudioOutputStream::Close()"; |
| 310 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); | 310 DCHECK_EQ(GetCurrentThreadId(), creating_thread_id_); |
| 311 | 311 |
| 312 // It is valid to call Close() before calling open or Start(). | 312 // It is valid to call Close() before calling open or Start(). |
| 313 // It is also valid to call Close() after Start() has been called. | 313 // It is also valid to call Close() after Start() has been called. |
| 314 Stop(); | 314 Stop(); |
| 315 | 315 |
| 316 // Inform the audio manager that we have been closed. This will cause our | 316 // Inform the audio manager that we have been closed. This will cause our |
| 317 // destruction. | 317 // destruction. |
| 318 manager_->ReleaseOutputStream(this); | 318 manager_->ReleaseOutputStream(this); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void WASAPIAudioOutputStream::SetVolume(double volume) { | 321 void WASAPIAudioOutputStream::SetVolume(double volume) { |
| 322 VLOG(1) << "SetVolume(volume=" << volume << ")"; | 322 DVLOG(1) << "SetVolume(volume=" << volume << ")"; |
| 323 float volume_float = static_cast<float>(volume); | 323 float volume_float = static_cast<float>(volume); |
| 324 if (volume_float < 0.0f || volume_float > 1.0f) { | 324 if (volume_float < 0.0f || volume_float > 1.0f) { |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 volume_ = volume_float; | 327 volume_ = volume_float; |
| 328 } | 328 } |
| 329 | 329 |
| 330 void WASAPIAudioOutputStream::GetVolume(double* volume) { | 330 void WASAPIAudioOutputStream::GetVolume(double* volume) { |
| 331 VLOG(1) << "GetVolume()"; | 331 DVLOG(1) << "GetVolume()"; |
| 332 *volume = static_cast<double>(volume_); | 332 *volume = static_cast<double>(volume_); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void WASAPIAudioOutputStream::Run() { | 335 void WASAPIAudioOutputStream::Run() { |
| 336 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 336 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
| 337 | 337 |
| 338 // Increase the thread priority. | 338 // Increase the thread priority. |
| 339 render_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 339 render_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
| 340 | 340 |
| 341 // Enable MMCSS to ensure that this thread receives prioritized access to | 341 // Enable MMCSS to ensure that this thread receives prioritized access to |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 531 |
| 532 float f = (1000.0 * packet_size_frames_) / format_.Format.nSamplesPerSec; | 532 float f = (1000.0 * packet_size_frames_) / format_.Format.nSamplesPerSec; |
| 533 REFERENCE_TIME requested_buffer_duration = | 533 REFERENCE_TIME requested_buffer_duration = |
| 534 static_cast<REFERENCE_TIME>(f * 10000.0 + 0.5); | 534 static_cast<REFERENCE_TIME>(f * 10000.0 + 0.5); |
| 535 | 535 |
| 536 DWORD stream_flags = AUDCLNT_STREAMFLAGS_NOPERSIST; | 536 DWORD stream_flags = AUDCLNT_STREAMFLAGS_NOPERSIST; |
| 537 bool use_event = (event_handle != NULL && | 537 bool use_event = (event_handle != NULL && |
| 538 event_handle != INVALID_HANDLE_VALUE); | 538 event_handle != INVALID_HANDLE_VALUE); |
| 539 if (use_event) | 539 if (use_event) |
| 540 stream_flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK; | 540 stream_flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK; |
| 541 VLOG(2) << "stream_flags: 0x" << std::hex << stream_flags; | 541 DVLOG(2) << "stream_flags: 0x" << std::hex << stream_flags; |
| 542 | 542 |
| 543 // Initialize the audio stream between the client and the device. | 543 // Initialize the audio stream between the client and the device. |
| 544 // For an exclusive-mode stream that uses event-driven buffering, the | 544 // For an exclusive-mode stream that uses event-driven buffering, the |
| 545 // caller must specify nonzero values for hnsPeriodicity and | 545 // caller must specify nonzero values for hnsPeriodicity and |
| 546 // hnsBufferDuration, and the values of these two parameters must be equal. | 546 // hnsBufferDuration, and the values of these two parameters must be equal. |
| 547 // The Initialize method allocates two buffers for the stream. Each buffer | 547 // The Initialize method allocates two buffers for the stream. Each buffer |
| 548 // is equal in duration to the value of the hnsBufferDuration parameter. | 548 // is equal in duration to the value of the hnsBufferDuration parameter. |
| 549 // Following the Initialize call for a rendering stream, the caller should | 549 // Following the Initialize call for a rendering stream, the caller should |
| 550 // fill the first of the two buffers before starting the stream. | 550 // fill the first of the two buffers before starting the stream. |
| 551 HRESULT hr = S_FALSE; | 551 HRESULT hr = S_FALSE; |
| 552 hr = client->Initialize(AUDCLNT_SHAREMODE_EXCLUSIVE, | 552 hr = client->Initialize(AUDCLNT_SHAREMODE_EXCLUSIVE, |
| 553 stream_flags, | 553 stream_flags, |
| 554 requested_buffer_duration, | 554 requested_buffer_duration, |
| 555 requested_buffer_duration, | 555 requested_buffer_duration, |
| 556 reinterpret_cast<WAVEFORMATEX*>(&format_), | 556 reinterpret_cast<WAVEFORMATEX*>(&format_), |
| 557 NULL); | 557 NULL); |
| 558 if (FAILED(hr)) { | 558 if (FAILED(hr)) { |
| 559 if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) { | 559 if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) { |
| 560 LOG(ERROR) << "AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED"; | 560 LOG(ERROR) << "AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED"; |
| 561 | 561 |
| 562 UINT32 aligned_buffer_size = 0; | 562 UINT32 aligned_buffer_size = 0; |
| 563 client->GetBufferSize(&aligned_buffer_size); | 563 client->GetBufferSize(&aligned_buffer_size); |
| 564 VLOG(1) << "Use aligned buffer size instead: " << aligned_buffer_size; | 564 DVLOG(1) << "Use aligned buffer size instead: " << aligned_buffer_size; |
| 565 | 565 |
| 566 // Calculate new aligned periodicity. Each unit of reference time | 566 // Calculate new aligned periodicity. Each unit of reference time |
| 567 // is 100 nanoseconds. | 567 // is 100 nanoseconds. |
| 568 REFERENCE_TIME aligned_buffer_duration = static_cast<REFERENCE_TIME>( | 568 REFERENCE_TIME aligned_buffer_duration = static_cast<REFERENCE_TIME>( |
| 569 (10000000.0 * aligned_buffer_size / format_.Format.nSamplesPerSec) | 569 (10000000.0 * aligned_buffer_size / format_.Format.nSamplesPerSec) |
| 570 + 0.5); | 570 + 0.5); |
| 571 | 571 |
| 572 // It is possible to re-activate and re-initialize the audio client | 572 // It is possible to re-activate and re-initialize the audio client |
| 573 // at this stage but we bail out with an error code instead and | 573 // at this stage but we bail out with an error code instead and |
| 574 // combine it with a log message which informs about the suggested | 574 // combine it with a log message which informs about the suggested |
| 575 // aligned buffer size which should be used instead. | 575 // aligned buffer size which should be used instead. |
| 576 VLOG(1) << "aligned_buffer_duration: " | 576 DVLOG(1) << "aligned_buffer_duration: " |
| 577 << static_cast<double>(aligned_buffer_duration / 10000.0) | 577 << static_cast<double>(aligned_buffer_duration / 10000.0) |
| 578 << " [ms]"; | 578 << " [ms]"; |
| 579 } else if (hr == AUDCLNT_E_INVALID_DEVICE_PERIOD) { | 579 } else if (hr == AUDCLNT_E_INVALID_DEVICE_PERIOD) { |
| 580 // We will get this error if we try to use a smaller buffer size than | 580 // We will get this error if we try to use a smaller buffer size than |
| 581 // the minimum supported size (usually ~3ms on Windows 7). | 581 // the minimum supported size (usually ~3ms on Windows 7). |
| 582 LOG(ERROR) << "AUDCLNT_E_INVALID_DEVICE_PERIOD"; | 582 LOG(ERROR) << "AUDCLNT_E_INVALID_DEVICE_PERIOD"; |
| 583 } | 583 } |
| 584 return hr; | 584 return hr; |
| 585 } | 585 } |
| 586 | 586 |
| 587 if (use_event) { | 587 if (use_event) { |
| 588 hr = client->SetEventHandle(event_handle); | 588 hr = client->SetEventHandle(event_handle); |
| 589 if (FAILED(hr)) { | 589 if (FAILED(hr)) { |
| 590 VLOG(1) << "IAudioClient::SetEventHandle: " << std::hex << hr; | 590 DVLOG(1) << "IAudioClient::SetEventHandle: " << std::hex << hr; |
| 591 return hr; | 591 return hr; |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 UINT32 buffer_size_in_frames = 0; | 595 UINT32 buffer_size_in_frames = 0; |
| 596 hr = client->GetBufferSize(&buffer_size_in_frames); | 596 hr = client->GetBufferSize(&buffer_size_in_frames); |
| 597 if (FAILED(hr)) { | 597 if (FAILED(hr)) { |
| 598 VLOG(1) << "IAudioClient::GetBufferSize: " << std::hex << hr; | 598 DVLOG(1) << "IAudioClient::GetBufferSize: " << std::hex << hr; |
| 599 return hr; | 599 return hr; |
| 600 } | 600 } |
| 601 | 601 |
| 602 *endpoint_buffer_size = buffer_size_in_frames; | 602 *endpoint_buffer_size = buffer_size_in_frames; |
| 603 VLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; | 603 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; |
| 604 return hr; | 604 return hr; |
| 605 } | 605 } |
| 606 | 606 |
| 607 void WASAPIAudioOutputStream::StopThread() { | 607 void WASAPIAudioOutputStream::StopThread() { |
| 608 if (render_thread_ ) { | 608 if (render_thread_ ) { |
| 609 if (render_thread_->HasBeenStarted()) { | 609 if (render_thread_->HasBeenStarted()) { |
| 610 // Wait until the thread completes and perform cleanup. | 610 // Wait until the thread completes and perform cleanup. |
| 611 SetEvent(stop_render_event_.Get()); | 611 SetEvent(stop_render_event_.Get()); |
| 612 render_thread_->Join(); | 612 render_thread_->Join(); |
| 613 } | 613 } |
| 614 | 614 |
| 615 render_thread_.reset(); | 615 render_thread_.reset(); |
| 616 | 616 |
| 617 // Ensure that we don't quit the main thread loop immediately next | 617 // Ensure that we don't quit the main thread loop immediately next |
| 618 // time Start() is called. | 618 // time Start() is called. |
| 619 ResetEvent(stop_render_event_.Get()); | 619 ResetEvent(stop_render_event_.Get()); |
| 620 } | 620 } |
| 621 | 621 |
| 622 source_ = NULL; | 622 source_ = NULL; |
| 623 } | 623 } |
| 624 | 624 |
| 625 } // namespace media | 625 } // namespace media |
| OLD | NEW |