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

Side by Side Diff: media/audio/linux/alsa_input.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/linux/alsa_input.h ('k') | media/audio/mac/audio_low_latency_input_mac.h » ('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/linux/alsa_input.h" 5 #include "media/audio/linux/alsa_input.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 wrapper_, mixer_handle_); 95 wrapper_, mixer_handle_);
96 } 96 }
97 } 97 }
98 98
99 return device_handle_ != NULL; 99 return device_handle_ != NULL;
100 } 100 }
101 101
102 void AlsaPcmInputStream::Start(AudioInputCallback* callback) { 102 void AlsaPcmInputStream::Start(AudioInputCallback* callback) {
103 DCHECK(!callback_ && callback); 103 DCHECK(!callback_ && callback);
104 callback_ = callback; 104 callback_ = callback;
105 StartAgc();
105 int error = wrapper_->PcmPrepare(device_handle_); 106 int error = wrapper_->PcmPrepare(device_handle_);
106 if (error < 0) { 107 if (error < 0) {
107 HandleError("PcmPrepare", error); 108 HandleError("PcmPrepare", error);
108 } else { 109 } else {
109 error = wrapper_->PcmStart(device_handle_); 110 error = wrapper_->PcmStart(device_handle_);
110 if (error < 0) 111 if (error < 0)
111 HandleError("PcmStart", error); 112 HandleError("PcmStart", error);
112 } 113 }
113 114
114 if (error < 0) { 115 if (error < 0) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 197 }
197 198
198 int num_buffers = frames / params_.frames_per_buffer(); 199 int num_buffers = frames / params_.frames_per_buffer();
199 uint32 hardware_delay_bytes = 200 uint32 hardware_delay_bytes =
200 static_cast<uint32>(GetCurrentDelay() * params_.GetBytesPerFrame()); 201 static_cast<uint32>(GetCurrentDelay() * params_.GetBytesPerFrame());
201 double normalized_volume = 0.0; 202 double normalized_volume = 0.0;
202 203
203 // Update the AGC volume level once every second. Note that, |volume| is 204 // Update the AGC volume level once every second. Note that, |volume| is
204 // also updated each time SetVolume() is called through IPC by the 205 // also updated each time SetVolume() is called through IPC by the
205 // render-side AGC. 206 // render-side AGC.
206 QueryAgcVolume(&normalized_volume); 207 GetAgcVolume(&normalized_volume);
207 208
208 while (num_buffers--) { 209 while (num_buffers--) {
209 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), 210 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(),
210 params_.frames_per_buffer()); 211 params_.frames_per_buffer());
211 if (frames_read == params_.frames_per_buffer()) { 212 if (frames_read == params_.frames_per_buffer()) {
212 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_, 213 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_,
213 hardware_delay_bytes, normalized_volume); 214 hardware_delay_bytes, normalized_volume);
214 } else { 215 } else {
215 LOG(WARNING) << "PcmReadi returning less than expected frames: " 216 LOG(WARNING) << "PcmReadi returning less than expected frames: "
216 << frames_read << " vs. " << params_.frames_per_buffer() 217 << frames_read << " vs. " << params_.frames_per_buffer()
(...skipping 16 matching lines...) Expand all
233 base::MessageLoop::current()->PostDelayedTask( 234 base::MessageLoop::current()->PostDelayedTask(
234 FROM_HERE, 235 FROM_HERE,
235 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), 236 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()),
236 delay); 237 delay);
237 } 238 }
238 239
239 void AlsaPcmInputStream::Stop() { 240 void AlsaPcmInputStream::Stop() {
240 if (!device_handle_ || !callback_) 241 if (!device_handle_ || !callback_)
241 return; 242 return;
242 243
244 StopAgc();
245
243 // Stop is always called before Close. In case of error, this will be 246 // Stop is always called before Close. In case of error, this will be
244 // also called when closing the input controller. 247 // also called when closing the input controller.
245 audio_manager_->DecreaseActiveInputStreamCount(); 248 audio_manager_->DecreaseActiveInputStreamCount();
246 249
247 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. 250 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read.
248 int error = wrapper_->PcmDrop(device_handle_); 251 int error = wrapper_->PcmDrop(device_handle_);
249 if (error < 0) 252 if (error < 0)
250 HandleError("PcmDrop", error); 253 HandleError("PcmDrop", error);
251 } 254 }
252 255
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 337
335 return static_cast<double>(current_volume); 338 return static_cast<double>(current_volume);
336 } 339 }
337 340
338 void AlsaPcmInputStream::HandleError(const char* method, int error) { 341 void AlsaPcmInputStream::HandleError(const char* method, int error) {
339 LOG(WARNING) << method << ": " << wrapper_->StrError(error); 342 LOG(WARNING) << method << ": " << wrapper_->StrError(error);
340 callback_->OnError(this); 343 callback_->OnError(this);
341 } 344 }
342 345
343 } // namespace media 346 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_input.h ('k') | media/audio/mac/audio_low_latency_input_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698