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 <climits> | 9 #include <climits> |
10 | 10 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 274 } |
275 } | 275 } |
276 num_written_frames_ = endpoint_buffer_size_frames_; | 276 num_written_frames_ = endpoint_buffer_size_frames_; |
277 | 277 |
278 // Create and start the thread that will drive the rendering by waiting for | 278 // Create and start the thread that will drive the rendering by waiting for |
279 // render events. | 279 // render events. |
280 render_thread_.reset(new base::DelegateSimpleThread( | 280 render_thread_.reset(new base::DelegateSimpleThread( |
281 this, "wasapi_render_thread", | 281 this, "wasapi_render_thread", |
282 base::SimpleThread::Options(base::ThreadPriority::REALTIME_AUDIO))); | 282 base::SimpleThread::Options(base::ThreadPriority::REALTIME_AUDIO))); |
283 render_thread_->Start(); | 283 render_thread_->Start(); |
| 284 if (!render_thread_->HasBeenStarted()) { |
| 285 LOG(ERROR) << "Failed to start WASAPI render thread."; |
| 286 StopThread(); |
| 287 callback->OnError(this); |
| 288 return; |
| 289 } |
284 | 290 |
285 // Start streaming data between the endpoint buffer and the audio engine. | 291 // Start streaming data between the endpoint buffer and the audio engine. |
286 HRESULT hr = audio_client_->Start(); | 292 HRESULT hr = audio_client_->Start(); |
287 if (FAILED(hr)) { | 293 if (FAILED(hr)) { |
288 PLOG(ERROR) << "Failed to start output streaming: " << std::hex << hr; | 294 PLOG(ERROR) << "Failed to start output streaming: " << std::hex << hr; |
289 StopThread(); | 295 StopThread(); |
290 callback->OnError(this); | 296 callback->OnError(this); |
291 } | 297 } |
292 } | 298 } |
293 | 299 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return hr; | 627 return hr; |
622 } | 628 } |
623 | 629 |
624 *endpoint_buffer_size = buffer_size_in_frames; | 630 *endpoint_buffer_size = buffer_size_in_frames; |
625 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; | 631 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; |
626 return hr; | 632 return hr; |
627 } | 633 } |
628 | 634 |
629 void WASAPIAudioOutputStream::StopThread() { | 635 void WASAPIAudioOutputStream::StopThread() { |
630 if (render_thread_) { | 636 if (render_thread_) { |
631 // Wait until the thread completes and perform cleanup. | 637 if (render_thread_->HasBeenStarted()) { |
632 SetEvent(stop_render_event_.Get()); | 638 // Wait until the thread completes and perform cleanup. |
633 render_thread_->Join(); | 639 SetEvent(stop_render_event_.Get()); |
| 640 render_thread_->Join(); |
| 641 } |
634 | 642 |
635 render_thread_.reset(); | 643 render_thread_.reset(); |
636 | 644 |
637 // Ensure that we don't quit the main thread loop immediately next | 645 // Ensure that we don't quit the main thread loop immediately next |
638 // time Start() is called. | 646 // time Start() is called. |
639 ResetEvent(stop_render_event_.Get()); | 647 ResetEvent(stop_render_event_.Get()); |
640 } | 648 } |
641 | 649 |
642 source_ = NULL; | 650 source_ = NULL; |
643 } | 651 } |
644 | 652 |
645 } // namespace media | 653 } // namespace media |
OLD | NEW |