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

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

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