| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "media/audio/audio_device_description.h" | 13 #include "media/audio/audio_device_description.h" |
| 14 #include "media/audio/audio_manager.h" | |
| 15 #include "media/audio/cras/audio_manager_cras.h" | 14 #include "media/audio/cras/audio_manager_cras.h" |
| 16 | 15 |
| 17 namespace media { | 16 namespace media { |
| 18 | 17 |
| 19 CrasInputStream::CrasInputStream(const AudioParameters& params, | 18 CrasInputStream::CrasInputStream(const AudioParameters& params, |
| 20 AudioManagerCras* manager, | 19 AudioManagerCras* manager, |
| 21 const std::string& device_id) | 20 const std::string& device_id) |
| 22 : audio_manager_(manager), | 21 : audio_manager_(manager), |
| 23 bytes_per_frame_(0), | 22 bytes_per_frame_(0), |
| 24 callback_(NULL), | 23 callback_(NULL), |
| 25 client_(NULL), | 24 client_(NULL), |
| 26 params_(params), | 25 params_(params), |
| 27 started_(false), | 26 started_(false), |
| 28 stream_id_(0), | 27 stream_id_(0), |
| 29 stream_direction_(CRAS_STREAM_INPUT), | 28 stream_direction_(CRAS_STREAM_INPUT), |
| 30 pin_device_(NO_DEVICE), | 29 pin_device_(NO_DEVICE), |
| 31 is_loopback_( | 30 is_loopback_( |
| 32 device_id == AudioDeviceDescription::kLoopbackInputDeviceId || | 31 device_id == AudioDeviceDescription::kLoopbackInputDeviceId || |
| 33 device_id == AudioDeviceDescription::kLoopbackWithMuteDeviceId), | 32 device_id == AudioDeviceDescription::kLoopbackWithMuteDeviceId), |
| 34 mute_system_audio_(device_id == | 33 mute_system_audio_(device_id == |
| 35 AudioDeviceDescription::kLoopbackWithMuteDeviceId), | 34 AudioDeviceDescription::kLoopbackWithMuteDeviceId), |
| 36 mute_done_(false) { | 35 mute_done_(false) { |
| 37 DCHECK(audio_manager_); | 36 DCHECK(audio_manager_); |
| 38 audio_bus_ = AudioBus::Create(params_); | 37 audio_bus_ = AudioBus::Create(params_); |
| 39 if (!IsDefault(device_id)) { | 38 if (!audio_manager_->IsDefault(device_id, true)) { |
| 40 uint64_t cras_node_id; | 39 uint64_t cras_node_id; |
| 41 base::StringToUint64(device_id, &cras_node_id); | 40 base::StringToUint64(device_id, &cras_node_id); |
| 42 pin_device_ = dev_index_of(cras_node_id); | 41 pin_device_ = dev_index_of(cras_node_id); |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 CrasInputStream::~CrasInputStream() { | 45 CrasInputStream::~CrasInputStream() { |
| 47 DCHECK(!client_); | 46 DCHECK(!client_); |
| 48 } | 47 } |
| 49 | 48 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 return 0.0; | 347 return 0.0; |
| 349 | 348 |
| 350 long dB = cras_client_get_system_capture_gain(client_) / 100.0; | 349 long dB = cras_client_get_system_capture_gain(client_) / 100.0; |
| 351 return GetVolumeRatioFromDecibels(dB); | 350 return GetVolumeRatioFromDecibels(dB); |
| 352 } | 351 } |
| 353 | 352 |
| 354 bool CrasInputStream::IsMuted() { | 353 bool CrasInputStream::IsMuted() { |
| 355 return false; | 354 return false; |
| 356 } | 355 } |
| 357 | 356 |
| 358 bool CrasInputStream::IsDefault(const std::string& device_id) const { | |
| 359 AudioDeviceNames device_names; | |
| 360 audio_manager_->GetAudioInputDeviceNames(&device_names); | |
| 361 DCHECK(!device_names.empty()); | |
| 362 AudioDeviceName device_name = device_names.front(); | |
| 363 return device_name.unique_id == device_id; | |
| 364 } | |
| 365 | |
| 366 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 357 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
| 367 return pow(10, dB / 20.0); | 358 return pow(10, dB / 20.0); |
| 368 } | 359 } |
| 369 | 360 |
| 370 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 361 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
| 371 return 20 * log10(volume_ratio); | 362 return 20 * log10(volume_ratio); |
| 372 } | 363 } |
| 373 | 364 |
| 374 } // namespace media | 365 } // namespace media |
| OLD | NEW |