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

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

Issue 2804393002: Revert of [reland] Do not block in SimpleThread::Start(). (Closed)
Patch Set: Created 3 years, 8 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 }
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 return hr; 632 return hr;
627 } 633 }
628 634
629 *endpoint_buffer_size = buffer_size_in_frames; 635 *endpoint_buffer_size = buffer_size_in_frames;
630 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; 636 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames;
631 return hr; 637 return hr;
632 } 638 }
633 639
634 void WASAPIAudioOutputStream::StopThread() { 640 void WASAPIAudioOutputStream::StopThread() {
635 if (render_thread_) { 641 if (render_thread_) {
636 // Wait until the thread completes and perform cleanup. 642 if (render_thread_->HasBeenStarted()) {
637 SetEvent(stop_render_event_.Get()); 643 // Wait until the thread completes and perform cleanup.
638 render_thread_->Join(); 644 SetEvent(stop_render_event_.Get());
645 render_thread_->Join();
646 }
639 647
640 render_thread_.reset(); 648 render_thread_.reset();
641 649
642 // Ensure that we don't quit the main thread loop immediately next 650 // Ensure that we don't quit the main thread loop immediately next
643 // time Start() is called. 651 // time Start() is called.
644 ResetEvent(stop_render_event_.Get()); 652 ResetEvent(stop_render_event_.Get());
645 } 653 }
646 654
647 source_ = NULL; 655 source_ = NULL;
648 } 656 }
649 657
650 } // namespace media 658 } // 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