| OLD | NEW |
| 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/cras/cras_input.h" | 5 #include "media/audio/cras/cras_input.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
| 13 #include "media/audio/cras/audio_manager_cras.h" | 13 #include "media/audio/cras/audio_manager_cras.h" |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 CrasInputStream::CrasInputStream(const AudioParameters& params, | 17 CrasInputStream::CrasInputStream(const AudioParameters& params, |
| 18 AudioManagerCras* manager, | 18 AudioManagerCras* manager, |
| 19 const std::string& device_id) | 19 const std::string& device_id) |
| 20 : audio_manager_(manager), | 20 : audio_manager_(manager), |
| 21 bytes_per_frame_(0), | 21 bytes_per_frame_(0), |
| 22 callback_(NULL), | 22 callback_(NULL), |
| 23 client_(NULL), | 23 client_(NULL), |
| 24 params_(params), | 24 params_(params), |
| 25 started_(false), | 25 started_(false), |
| 26 stream_id_(0), | 26 stream_id_(0), |
| 27 stream_direction_(device_id == AudioManagerBase::kLoopbackInputDeviceId ? | 27 stream_direction_(device_id == AudioManagerBase::kLoopbackInputDeviceId ? |
| 28 CRAS_STREAM_POST_MIX_PRE_DSP : CRAS_STREAM_INPUT) { | 28 CRAS_STREAM_POST_MIX_PRE_DSP : CRAS_STREAM_INPUT) { |
| 29 DCHECK(audio_manager_); | 29 DCHECK(audio_manager_); |
| 30 audio_bus_ = AudioBus::Create(params_); | |
| 31 } | 30 } |
| 32 | 31 |
| 33 CrasInputStream::~CrasInputStream() { | 32 CrasInputStream::~CrasInputStream() { |
| 34 DCHECK(!client_); | 33 DCHECK(!client_); |
| 35 } | 34 } |
| 36 | 35 |
| 37 bool CrasInputStream::Open() { | 36 bool CrasInputStream::Open() { |
| 38 if (client_) { | 37 if (client_) { |
| 39 NOTREACHED() << "CrasInputStream already open"; | 38 NOTREACHED() << "CrasInputStream already open"; |
| 40 return false; // Already open. | 39 return false; // Already open. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond; | 215 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond; |
| 217 unsigned int bytes_latency = | 216 unsigned int bytes_latency = |
| 218 static_cast<unsigned int>(frames_latency * bytes_per_frame_); | 217 static_cast<unsigned int>(frames_latency * bytes_per_frame_); |
| 219 | 218 |
| 220 // Update the AGC volume level once every second. Note that, |volume| is | 219 // Update the AGC volume level once every second. Note that, |volume| is |
| 221 // also updated each time SetVolume() is called through IPC by the | 220 // also updated each time SetVolume() is called through IPC by the |
| 222 // render-side AGC. | 221 // render-side AGC. |
| 223 double normalized_volume = 0.0; | 222 double normalized_volume = 0.0; |
| 224 GetAgcVolume(&normalized_volume); | 223 GetAgcVolume(&normalized_volume); |
| 225 | 224 |
| 226 audio_bus_->FromInterleaved(buffer, | |
| 227 audio_bus_->frames(), | |
| 228 params_.bits_per_sample() / 8); | |
| 229 callback_->OnData(this, | 225 callback_->OnData(this, |
| 230 audio_bus_.get(), | 226 buffer, |
| 231 frames * bytes_per_frame_, | 227 frames * bytes_per_frame_, |
| 232 bytes_latency, | 228 bytes_latency, |
| 233 normalized_volume); | 229 normalized_volume); |
| 234 } | 230 } |
| 235 | 231 |
| 236 void CrasInputStream::NotifyStreamError(int err) { | 232 void CrasInputStream::NotifyStreamError(int err) { |
| 237 if (callback_) | 233 if (callback_) |
| 238 callback_->OnError(this); | 234 callback_->OnError(this); |
| 239 } | 235 } |
| 240 | 236 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 268 |
| 273 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 269 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
| 274 return pow(10, dB / 20.0); | 270 return pow(10, dB / 20.0); |
| 275 } | 271 } |
| 276 | 272 |
| 277 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 273 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
| 278 return 20 * log10(volume_ratio); | 274 return 20 * log10(volume_ratio); |
| 279 } | 275 } |
| 280 | 276 |
| 281 } // namespace media | 277 } // namespace media |
| OLD | NEW |