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

Unified Diff: media/audio/audio_input_controller.cc

Issue 9702019: Adds Analog Gain Control (AGC) to the WebRTC client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved volume updating on Mac Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_input_controller.cc
diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc
index 14d3bbae0e86f267d74f3dc10c1cbd26d6192eda..cef502e716483803579db5b6597e50d04cb1111e 100644
--- a/media/audio/audio_input_controller.cc
+++ b/media/audio/audio_input_controller.cc
@@ -28,7 +28,8 @@ AudioInputController::AudioInputController(EventHandler* handler,
this,
&AudioInputController::DoReportNoDataError)),
state_(kEmpty),
- sync_writer_(sync_writer) {
+ sync_writer_(sync_writer),
+ max_volume_(0.0) {
DCHECK(creator_loop_);
}
@@ -107,6 +108,16 @@ void AudioInputController::Close(const base::Closure& closed_task) {
&AudioInputController::DoClose, this, closed_task));
}
+void AudioInputController::SetVolume(double volume) {
+ message_loop_->PostTask(FROM_HERE, base::Bind(
+ &AudioInputController::DoSetVolume, this, volume));
+}
+
+void AudioInputController::SetAutomaticGainControl(bool enabled) {
+ message_loop_->PostTask(FROM_HERE, base::Bind(
+ &AudioInputController::DoSetAutomaticGainControl, this, enabled));
+}
+
void AudioInputController::DoCreate(AudioManager* audio_manager,
const AudioParameters& params,
const std::string& device_id) {
@@ -171,6 +182,37 @@ void AudioInputController::DoReportError(int code) {
handler_->OnError(this, code);
}
+void AudioInputController::DoSetVolume(double volume) {
+ DCHECK(message_loop_->BelongsToCurrentThread());
+ DCHECK(volume >= 0 && volume <= 1.0);
scherkus (not reviewing) 2012/03/20 13:49:41 nit: if you split these DCHECKs into DCHECK_GE() a
henrika (OOO until Aug 14) 2012/03/21 10:16:04 Nice. Thanks.
+
+ if (state_ != kCreated && state_ != kRecording)
+ return;
+
+ // Only ask for the maximum volume at first call and use cached value
+ // for remaining function calls.
+ if (!max_volume_) {
+ max_volume_ = stream_->GetMaxVolume();
+ }
+
+ if (max_volume_ == 0.0) {
+ DLOG(WARNING) << "Failed to access input volume control";
+ return;
+ }
+
+ // Set the stream volume and scale to a range matched to the platform.
+ stream_->SetVolume(max_volume_ * volume);
+}
+
+void AudioInputController::DoSetAutomaticGainControl(bool enabled) {
+ DCHECK(message_loop_->BelongsToCurrentThread());
+
+ if (state_ != kCreated)
+ return;
+
+ stream_->SetAutomaticGainControl(enabled);
+}
+
void AudioInputController::DoReportNoDataError() {
DCHECK(creator_loop_->BelongsToCurrentThread());
@@ -186,19 +228,20 @@ void AudioInputController::DoResetNoDataTimer() {
}
void AudioInputController::OnData(AudioInputStream* stream, const uint8* data,
- uint32 size, uint32 hardware_delay_bytes) {
+ uint32 size, uint32 hardware_delay_bytes,
+ double volume) {
{
base::AutoLock auto_lock(lock_);
if (state_ != kRecording)
return;
}
- creator_loop_->PostTask(FROM_HERE, base::Bind(
+ creator_loop_->PostTask(FROM_HERE, base::Bind(
&AudioInputController::DoResetNoDataTimer, this));
// Use SyncSocket if we are in a low-latency mode.
if (LowLatencyMode()) {
- sync_writer_->Write(data, size);
+ sync_writer_->Write(data, size, volume);
sync_writer_->UpdateRecordedBytes(hardware_delay_bytes);
return;
}

Powered by Google App Engine
This is Rietveld 408576698