Chromium Code Reviews| Index: media/audio/linux/alsa_input.cc |
| diff --git a/media/audio/linux/alsa_input.cc b/media/audio/linux/alsa_input.cc |
| index 2e9a21791704ad038a14459d20d47c03c2aa5b7f..189d28fe30ba6a41ef55a9daf754c8242f7e2814 100644 |
| --- a/media/audio/linux/alsa_input.cc |
| +++ b/media/audio/linux/alsa_input.cc |
| @@ -37,6 +37,8 @@ AlsaPcmInputStream::AlsaPcmInputStream(AudioManagerLinux* audio_manager, |
| params.sample_rate), |
| callback_(NULL), |
| device_handle_(NULL), |
| + mixer_handle_(NULL), |
| + mixer_element_handle_(NULL), |
| ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| read_callback_behind_schedule_(false) { |
| } |
| @@ -62,11 +64,13 @@ bool AlsaPcmInputStream::Open() { |
| latency_us = std::max(latency_us, AlsaPcmOutputStream::kMinLatencyMicros); |
| if (device_name_ == kAutoSelectDevice) { |
| + device_name_ = kDefaultDevice1; |
| device_handle_ = alsa_util::OpenCaptureDevice(wrapper_, kDefaultDevice1, |
| params_.channels, |
| params_.sample_rate, |
| pcm_format, latency_us); |
|
tommi (sloooow) - chröme
2012/02/21 14:03:25
instead of assigning to device_name and copy paste
no longer working on chromium
2012/02/21 18:01:38
Done.
|
| if (!device_handle_) { |
| + device_name_ = kDefaultDevice2; |
| device_handle_ = alsa_util::OpenCaptureDevice(wrapper_, kDefaultDevice2, |
| params_.channels, |
| params_.sample_rate, |
| @@ -80,9 +84,17 @@ bool AlsaPcmInputStream::Open() { |
| pcm_format, latency_us); |
| } |
| - if (device_handle_) |
| + if (device_handle_) { |
| audio_packet_.reset(new uint8[bytes_per_packet_]); |
| + // Open the microphone mixer. |
| + mixer_handle_ = alsa_util::OpenMixer(wrapper_, device_name_); |
| + if (mixer_handle_) { |
| + mixer_element_handle_ = alsa_util::LoadCaptureMixerElement( |
| + wrapper_, mixer_handle_); |
| + } |
| + } |
| + |
| return device_handle_ != NULL; |
| } |
| @@ -239,7 +251,7 @@ void AlsaPcmInputStream::Close() { |
| scoped_ptr<AlsaPcmInputStream> self_deleter(this); |
| // Check in case we were already closed or not initialized yet. |
| - if (!device_handle_ || !callback_) |
| + if (!device_handle_) |
| return; |
| weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. |
| @@ -247,9 +259,65 @@ void AlsaPcmInputStream::Close() { |
| if (error < 0) |
| HandleError("PcmClose", error); |
| + alsa_util::CloseMixer(wrapper_, mixer_handle_, device_name_); |
| audio_packet_.reset(); |
| device_handle_ = NULL; |
| - callback_->OnClose(this); |
| + |
| + if (callback_) |
| + callback_->OnClose(this); |
| +} |
| + |
| +void AlsaPcmInputStream::SetMicVolume(double volume) { |
| + if (!mixer_handle_ || !mixer_element_handle_) { |
| + DLOG(WARNING) << "SetMicVolume is not supported for " << device_name_; |
| + return; |
| + } |
| + |
| + int error = wrapper_->MixerSelemSetCaptureVolumeAll( |
| + mixer_element_handle_, static_cast<long>(volume)); |
| + if (error < 0) { |
| + DLOG(WARNING) << "Unable to set volume for " << device_name_; |
|
tommi (sloooow) - chröme
2012/02/21 14:03:25
do we never intend to support error notifications
no longer working on chromium
2012/02/21 18:01:38
My concern is that we may need to use IPC message
|
| + } |
| +} |
| + |
| +void AlsaPcmInputStream::GetMicVolume(double* volume) { |
| + if (!mixer_handle_ || !mixer_element_handle_) { |
| + DLOG(WARNING) << "GetMicVolume is not supported for " << device_name_; |
| + return; |
| + } |
| + |
| + long current_volume = 0; |
| + int error = wrapper_->MixerSelemGetCaptureVolume( |
| + mixer_element_handle_, static_cast<snd_mixer_selem_channel_id_t>(0), |
| + ¤t_volume); |
| + if (error < 0) { |
| + DLOG(WARNING) << "Unable to get volume for " << device_name_; |
| + } |
| + *volume = static_cast<double>(current_volume); |
|
tommi (sloooow) - chröme
2012/02/21 14:03:25
this should be inside an else {}.
no longer working on chromium
2012/02/21 18:01:38
Done.
|
| +} |
| + |
| +void AlsaPcmInputStream::GetMaxMicVolume(double* max_volume) { |
| + if (!mixer_handle_ || !mixer_element_handle_) { |
| + DLOG(WARNING) << "GetMaxVolume is not supported for " << device_name_; |
| + return; |
| + } |
| + |
| + if (!wrapper_->MixerSelemHasCaptureVolume(mixer_element_handle_)) { |
| + DLOG(WARNING) << "Unsupported microphone volume for " << device_name_; |
| + return; |
| + } |
| + |
| + long min = 0; |
| + long max = 0; |
| + if (wrapper_->MixerSelemGetCaptureVolumeRange( |
| + mixer_element_handle_, &min, &max)) { |
|
tommi (sloooow) - chröme
2012/02/21 14:03:25
indentation feels off to me. Looks like this:
Fo
no longer working on chromium
2012/02/21 18:01:38
Done.
|
| + DLOG(WARNING) << "Unsupported max microphone volume for " << device_name_; |
| + return; |
| + } |
| + DCHECK(min == 0); |
| + DCHECK(max > 0); |
| + |
| + *max_volume = static_cast<double>(max); |
| } |
| void AlsaPcmInputStream::HandleError(const char* method, int error) { |