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

Side by Side Diff: media/audio/win/audio_low_latency_output_win.cc

Issue 2664953004: Do not block in SimpleThread::Start(). (Closed)
Patch Set: CR gab #26 (comment) Created 3 years, 10 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
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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 }
290 284
291 // Start streaming data between the endpoint buffer and the audio engine. 285 // Start streaming data between the endpoint buffer and the audio engine.
292 HRESULT hr = audio_client_->Start(); 286 HRESULT hr = audio_client_->Start();
293 if (FAILED(hr)) { 287 if (FAILED(hr)) {
294 PLOG(ERROR) << "Failed to start output streaming: " << std::hex << hr; 288 PLOG(ERROR) << "Failed to start output streaming: " << std::hex << hr;
295 StopThread(); 289 StopThread();
296 callback->OnError(this); 290 callback->OnError(this);
297 } 291 }
298 } 292 }
299 293
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return hr; 621 return hr;
628 } 622 }
629 623
630 *endpoint_buffer_size = buffer_size_in_frames; 624 *endpoint_buffer_size = buffer_size_in_frames;
631 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; 625 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames;
632 return hr; 626 return hr;
633 } 627 }
634 628
635 void WASAPIAudioOutputStream::StopThread() { 629 void WASAPIAudioOutputStream::StopThread() {
636 if (render_thread_) { 630 if (render_thread_) {
637 if (render_thread_->HasBeenStarted()) { 631 // Wait until the thread completes and perform cleanup.
638 // Wait until the thread completes and perform cleanup. 632 SetEvent(stop_render_event_.Get());
639 SetEvent(stop_render_event_.Get()); 633 render_thread_->Join();
640 render_thread_->Join();
641 }
642 634
643 render_thread_.reset(); 635 render_thread_.reset();
644 636
645 // Ensure that we don't quit the main thread loop immediately next 637 // Ensure that we don't quit the main thread loop immediately next
646 // time Start() is called. 638 // time Start() is called.
647 ResetEvent(stop_render_event_.Get()); 639 ResetEvent(stop_render_event_.Get());
648 } 640 }
649 641
650 source_ = NULL; 642 source_ = NULL;
651 } 643 }
652 644
653 } // namespace media 645 } // namespace media
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698