Chromium Code Reviews| 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/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "media/audio/audio_device_description.h" | 12 #include "media/audio/audio_device_description.h" |
| 13 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
| 14 #include "media/audio/cras/audio_manager_cras.h" | 14 #include "media/audio/cras/audio_manager_cras.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 CrasInputStream::CrasInputStream(const AudioParameters& params, | 18 CrasInputStream::CrasInputStream(const AudioParameters& params, |
| 19 AudioManagerCras* manager, | 19 AudioManagerCras* manager, |
| 20 const std::string& device_id) | 20 const std::string& device_id) |
| 21 : audio_manager_(manager), | 21 : audio_manager_(manager), |
| 22 bytes_per_frame_(0), | 22 bytes_per_frame_(0), |
| 23 callback_(NULL), | 23 callback_(NULL), |
| 24 client_(NULL), | 24 client_(NULL), |
| 25 params_(params), | 25 params_(params), |
| 26 started_(false), | 26 started_(false), |
| 27 stream_id_(0), | 27 stream_id_(0), |
| 28 stream_direction_(CRAS_STREAM_INPUT), | 28 stream_direction_(CRAS_STREAM_INPUT), |
| 29 pin_device_(NO_DEVICE), | 29 pin_device_(NO_DEVICE), |
| 30 is_loopback_(device_id == | 30 is_loopback_( |
| 31 AudioDeviceDescription::kLoopbackInputDeviceId) { | 31 device_id == AudioDeviceDescription::kLoopbackInputDeviceId || |
| 32 device_id == AudioDeviceDescription::kLoopbackWithMuteDeviceId), | |
| 33 mute_system_audio_(device_id == | |
| 34 AudioDeviceDescription::kLoopbackWithMuteDeviceId), | |
| 35 mute_done_(false) { | |
| 32 DCHECK(audio_manager_); | 36 DCHECK(audio_manager_); |
| 33 audio_bus_ = AudioBus::Create(params_); | 37 audio_bus_ = AudioBus::Create(params_); |
| 34 } | 38 } |
| 35 | 39 |
| 36 CrasInputStream::~CrasInputStream() { | 40 CrasInputStream::~CrasInputStream() { |
| 37 DCHECK(!client_); | 41 DCHECK(!client_); |
| 38 } | 42 } |
| 39 | 43 |
| 40 bool CrasInputStream::Open() { | 44 bool CrasInputStream::Open() { |
| 41 if (client_) { | 45 if (client_) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 90 |
| 87 if (is_loopback_) { | 91 if (is_loopback_) { |
| 88 if (cras_client_connected_wait(client_) < 0) { | 92 if (cras_client_connected_wait(client_) < 0) { |
| 89 DLOG(WARNING) << "Couldn't synchronize data."; | 93 DLOG(WARNING) << "Couldn't synchronize data."; |
| 90 // TODO(chinyue): Add a DestroyClientOnError method to de-duplicate the | 94 // TODO(chinyue): Add a DestroyClientOnError method to de-duplicate the |
| 91 // cleanup code. | 95 // cleanup code. |
| 92 cras_client_destroy(client_); | 96 cras_client_destroy(client_); |
| 93 client_ = NULL; | 97 client_ = NULL; |
| 94 return false; | 98 return false; |
| 95 } | 99 } |
| 100 | |
| 101 if (mute_system_audio_ && !cras_client_get_system_muted(client_)) { | |
| 102 cras_client_set_system_mute(client_, 1); | |
| 103 mute_done_ = true; | |
| 104 } | |
| 105 | |
| 96 pin_device_ = cras_client_get_first_dev_type_idx(client_, | 106 pin_device_ = cras_client_get_first_dev_type_idx(client_, |
| 97 CRAS_NODE_TYPE_POST_MIX_PRE_DSP, CRAS_STREAM_INPUT); | 107 CRAS_NODE_TYPE_POST_MIX_PRE_DSP, CRAS_STREAM_INPUT); |
| 98 if (pin_device_ < 0) { | 108 if (pin_device_ < 0) { |
| 99 DLOG(WARNING) << "Couldn't find CRAS loopback device."; | 109 DLOG(WARNING) << "Couldn't find CRAS loopback device."; |
| 100 cras_client_destroy(client_); | 110 cras_client_destroy(client_); |
| 101 client_ = NULL; | 111 client_ = NULL; |
| 102 return false; | 112 return false; |
| 103 } | 113 } |
| 104 } | 114 } |
| 105 | 115 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 started_ = true; | 234 started_ = true; |
| 225 } | 235 } |
| 226 | 236 |
| 227 void CrasInputStream::Stop() { | 237 void CrasInputStream::Stop() { |
| 228 if (!client_) | 238 if (!client_) |
| 229 return; | 239 return; |
| 230 | 240 |
| 231 if (!callback_ || !started_) | 241 if (!callback_ || !started_) |
| 232 return; | 242 return; |
| 233 | 243 |
| 244 if (mute_system_audio_ && mute_done_) { | |
|
DaleCurtis
2016/07/26 23:42:58
Open is called once, but Start()/Stop() may be cal
qiangchen
2016/07/27 17:23:48
Done.
| |
| 245 cras_client_set_system_mute(client_, 0); | |
| 246 mute_done_ = false; | |
| 247 } | |
| 248 | |
| 234 StopAgc(); | 249 StopAgc(); |
| 235 | 250 |
| 236 // Removing the stream from the client stops audio. | 251 // Removing the stream from the client stops audio. |
| 237 cras_client_rm_stream(client_, stream_id_); | 252 cras_client_rm_stream(client_, stream_id_); |
| 238 | 253 |
| 239 started_ = false; | 254 started_ = false; |
| 240 callback_ = NULL; | 255 callback_ = NULL; |
| 241 } | 256 } |
| 242 | 257 |
| 243 // Static callback asking for samples. Run on high priority thread. | 258 // Static callback asking for samples. Run on high priority thread. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 350 |
| 336 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 351 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
| 337 return pow(10, dB / 20.0); | 352 return pow(10, dB / 20.0); |
| 338 } | 353 } |
| 339 | 354 |
| 340 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 355 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
| 341 return 20 * log10(volume_ratio); | 356 return 20 * log10(volume_ratio); |
| 342 } | 357 } |
| 343 | 358 |
| 344 } // namespace media | 359 } // namespace media |
| OLD | NEW |