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

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

Issue 15563004: Improved AGC update scheme for the audio backend in Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added Start/Stop APIs for the AGC part Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/win/audio_low_latency_input_win.h ('k') | media/media.gyp » ('j') | 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_input_win.h" 5 #include "media/audio/win/audio_low_latency_input_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "media/audio/audio_util.h" 10 #include "media/audio/audio_util.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 DCHECK(callback); 120 DCHECK(callback);
121 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully"; 121 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully";
122 if (!opened_) 122 if (!opened_)
123 return; 123 return;
124 124
125 if (started_) 125 if (started_)
126 return; 126 return;
127 127
128 sink_ = callback; 128 sink_ = callback;
129 129
130 // Starts periodic AGC microphone measurements if the AGC has been enabled
131 // using SetAutomaticGainControl().
132 StartAgc();
133
130 // Create and start the thread that will drive the capturing by waiting for 134 // Create and start the thread that will drive the capturing by waiting for
131 // capture events. 135 // capture events.
132 capture_thread_ = 136 capture_thread_ =
133 new base::DelegateSimpleThread(this, "wasapi_capture_thread"); 137 new base::DelegateSimpleThread(this, "wasapi_capture_thread");
134 capture_thread_->Start(); 138 capture_thread_->Start();
135 139
136 // Start streaming data between the endpoint buffer and the audio engine. 140 // Start streaming data between the endpoint buffer and the audio engine.
137 HRESULT hr = audio_client_->Start(); 141 HRESULT hr = audio_client_->Start();
138 DLOG_IF(ERROR, FAILED(hr)) << "Failed to start input streaming."; 142 DLOG_IF(ERROR, FAILED(hr)) << "Failed to start input streaming.";
139 143
140 started_ = SUCCEEDED(hr); 144 started_ = SUCCEEDED(hr);
141 } 145 }
142 146
143 void WASAPIAudioInputStream::Stop() { 147 void WASAPIAudioInputStream::Stop() {
144 DCHECK(CalledOnValidThread()); 148 DCHECK(CalledOnValidThread());
145 DVLOG(1) << "WASAPIAudioInputStream::Stop()"; 149 DVLOG(1) << "WASAPIAudioInputStream::Stop()";
146 if (!started_) 150 if (!started_)
147 return; 151 return;
148 152
153 // Stops periodic AGC microphone measurements.
154 StopAgc();
155
149 // Shut down the capture thread. 156 // Shut down the capture thread.
150 if (stop_capture_event_.IsValid()) { 157 if (stop_capture_event_.IsValid()) {
151 SetEvent(stop_capture_event_.Get()); 158 SetEvent(stop_capture_event_.Get());
152 } 159 }
153 160
154 // Stop the input audio streaming. 161 // Stop the input audio streaming.
155 HRESULT hr = audio_client_->Stop(); 162 HRESULT hr = audio_client_->Stop();
156 if (FAILED(hr)) { 163 if (FAILED(hr)) {
157 LOG(ERROR) << "Failed to stop input streaming."; 164 LOG(ERROR) << "Failed to stop input streaming.";
158 } 165 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // Derive a delay estimate for the captured audio packet. 387 // Derive a delay estimate for the captured audio packet.
381 // The value contains two parts (A+B), where A is the delay of the 388 // The value contains two parts (A+B), where A is the delay of the
382 // first audio frame in the packet and B is the extra delay 389 // first audio frame in the packet and B is the extra delay
383 // contained in any stored data. Unit is in audio frames. 390 // contained in any stored data. Unit is in audio frames.
384 QueryPerformanceCounter(&now_count); 391 QueryPerformanceCounter(&now_count);
385 double audio_delay_frames = 392 double audio_delay_frames =
386 ((perf_count_to_100ns_units_ * now_count.QuadPart - 393 ((perf_count_to_100ns_units_ * now_count.QuadPart -
387 first_audio_frame_timestamp) / 10000.0) * ms_to_frame_count_ + 394 first_audio_frame_timestamp) / 10000.0) * ms_to_frame_count_ +
388 buffer_frame_index - num_frames_to_read; 395 buffer_frame_index - num_frames_to_read;
389 396
390 // Update the AGC volume level once every second. Note that, 397 // Get a cached AGC volume level which is updated once every second
391 // |volume| is also updated each time SetVolume() is called 398 // on the audio manager thread. Note that, |volume| is also updated
392 // through IPC by the render-side AGC. 399 // each time SetVolume() is called through IPC by the render-side AGC.
393 QueryAgcVolume(&volume); 400 GetAgcVolume(&volume);
394 401
395 // Deliver captured data to the registered consumer using a packet 402 // Deliver captured data to the registered consumer using a packet
396 // size which was specified at construction. 403 // size which was specified at construction.
397 uint32 delay_frames = static_cast<uint32>(audio_delay_frames + 0.5); 404 uint32 delay_frames = static_cast<uint32>(audio_delay_frames + 0.5);
398 while (buffer_frame_index >= packet_size_frames_) { 405 while (buffer_frame_index >= packet_size_frames_) {
399 uint8* audio_data = 406 uint8* audio_data =
400 reinterpret_cast<uint8*>(capture_buffer.get()); 407 reinterpret_cast<uint8*>(capture_buffer.get());
401 408
402 // Deliver data packet, delay estimation and volume level to 409 // Deliver data packet, delay estimation and volume level to
403 // the user. 410 // the user.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 return hr; 632 return hr;
626 633
627 // Obtain a reference to the ISimpleAudioVolume interface which enables 634 // Obtain a reference to the ISimpleAudioVolume interface which enables
628 // us to control the master volume level of an audio session. 635 // us to control the master volume level of an audio session.
629 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), 636 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume),
630 simple_audio_volume_.ReceiveVoid()); 637 simple_audio_volume_.ReceiveVoid());
631 return hr; 638 return hr;
632 } 639 }
633 640
634 } // namespace media 641 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/audio_low_latency_input_win.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698