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

Unified Diff: media/audio/win/audio_low_latency_output_win.cc

Issue 89663004: Don't start WASAPI render thread until setup completes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add IAudioClock. Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/win/audio_low_latency_output_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/win/audio_low_latency_output_win.cc
diff --git a/media/audio/win/audio_low_latency_output_win.cc b/media/audio/win/audio_low_latency_output_win.cc
index 8ba88217ecc44a2454db1d6341376d4d5b14db9e..cb24f43113b8f6a386716751ae28e32a60b78c39 100644
--- a/media/audio/win/audio_low_latency_output_win.cc
+++ b/media/audio/win/audio_low_latency_output_win.cc
@@ -234,6 +234,13 @@ bool WASAPIAudioOutputStream::Open() {
audio_client_ = audio_client;
audio_render_client_ = audio_render_client;
+ hr = audio_client_->GetService(__uuidof(IAudioClock),
+ audio_clock_.ReceiveVoid());
+ if (FAILED(hr)) {
+ LOG(ERROR) << "Failed to get IAudioClock service.";
+ return false;
+ }
+
opened_ = true;
return true;
}
@@ -251,6 +258,17 @@ void WASAPIAudioOutputStream::Start(AudioSourceCallback* callback) {
source_ = callback;
+ // Ensure that the endpoint buffer is prepared with silence.
+ if (share_mode_ == AUDCLNT_SHAREMODE_SHARED) {
+ if (!CoreAudioUtil::FillRenderEndpointBufferWithSilence(
+ audio_client_, audio_render_client_)) {
+ LOG(ERROR) << "Failed to prepare endpoint buffers with silence.";
+ callback->OnError(this);
+ return;
+ }
+ }
+ num_written_frames_ = endpoint_buffer_size_frames_;
+
// Create and start the thread that will drive the rendering by waiting for
// render events.
render_thread_.reset(
@@ -263,18 +281,6 @@ void WASAPIAudioOutputStream::Start(AudioSourceCallback* callback) {
return;
}
- // Ensure that the endpoint buffer is prepared with silence.
- if (share_mode_ == AUDCLNT_SHAREMODE_SHARED) {
- if (!CoreAudioUtil::FillRenderEndpointBufferWithSilence(
- audio_client_, audio_render_client_)) {
- LOG(ERROR) << "Failed to prepare endpoint buffers with silence.";
- StopThread();
- callback->OnError(this);
- return;
- }
- }
- num_written_frames_ = endpoint_buffer_size_frames_;
-
// Start streaming data between the endpoint buffer and the audio engine.
HRESULT hr = audio_client_->Start();
if (FAILED(hr)) {
@@ -377,17 +383,9 @@ void WASAPIAudioOutputStream::Run() {
audio_samples_render_event_ };
UINT64 device_frequency = 0;
- // The IAudioClock interface enables us to monitor a stream's data
- // rate and the current position in the stream. Allocate it before we
- // start spinning.
- ScopedComPtr<IAudioClock> audio_clock;
- hr = audio_client_->GetService(__uuidof(IAudioClock),
- audio_clock.ReceiveVoid());
- if (SUCCEEDED(hr)) {
- // The device frequency is the frequency generated by the hardware clock in
- // the audio device. The GetFrequency() method reports a constant frequency.
- hr = audio_clock->GetFrequency(&device_frequency);
- }
+ // The device frequency is the frequency generated by the hardware clock in
+ // the audio device. The GetFrequency() method reports a constant frequency.
+ hr = audio_clock_->GetFrequency(&device_frequency);
DaleCurtis 2013/11/27 02:45:08 I left this here, but if it's truly constant we co
henrika (OOO until Aug 14) 2013/11/27 08:24:39 Should be OK to use in Open. Can't see any cons by
error = FAILED(hr);
PLOG_IF(ERROR, error) << "Failed to acquire IAudioClock interface: "
<< std::hex << hr;
@@ -408,7 +406,7 @@ void WASAPIAudioOutputStream::Run() {
break;
case WAIT_OBJECT_0 + 1:
// |audio_samples_render_event_| has been set.
- error = !RenderAudioFromSource(audio_clock, device_frequency);
+ error = !RenderAudioFromSource(device_frequency);
break;
default:
error = true;
@@ -430,8 +428,7 @@ void WASAPIAudioOutputStream::Run() {
}
}
-bool WASAPIAudioOutputStream::RenderAudioFromSource(
- IAudioClock* audio_clock, UINT64 device_frequency) {
+bool WASAPIAudioOutputStream::RenderAudioFromSource(UINT64 device_frequency) {
TRACE_EVENT0("audio", "RenderAudioFromSource");
HRESULT hr = S_FALSE;
@@ -503,7 +500,7 @@ bool WASAPIAudioOutputStream::RenderAudioFromSource(
// unit at the render side.
UINT64 position = 0;
int audio_delay_bytes = 0;
- hr = audio_clock->GetPosition(&position, NULL);
+ hr = audio_clock_->GetPosition(&position, NULL);
if (SUCCEEDED(hr)) {
// Stream position of the sample that is currently playing
// through the speaker.
« no previous file with comments | « media/audio/win/audio_low_latency_output_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698