| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/alsa/alsa_input.h" | 5 #include "media/audio/alsa/alsa_input.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/bind.h" | 7 #include "base/bind.h" |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 11 #include "media/audio/alsa/alsa_output.h" | 10 #include "media/audio/alsa/alsa_output.h" |
| 12 #include "media/audio/alsa/alsa_util.h" | 11 #include "media/audio/alsa/alsa_util.h" |
| 13 #include "media/audio/alsa/alsa_wrapper.h" | 12 #include "media/audio/alsa/alsa_wrapper.h" |
| 14 #include "media/audio/alsa/audio_manager_alsa.h" | 13 #include "media/audio/alsa/audio_manager_alsa.h" |
| 15 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
| 16 | 15 |
| 17 namespace media { | 16 namespace media { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return false; // Already open. | 52 return false; // Already open. |
| 54 | 53 |
| 55 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( | 54 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( |
| 56 params_.bits_per_sample()); | 55 params_.bits_per_sample()); |
| 57 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) { | 56 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) { |
| 58 LOG(WARNING) << "Unsupported bits per sample: " | 57 LOG(WARNING) << "Unsupported bits per sample: " |
| 59 << params_.bits_per_sample(); | 58 << params_.bits_per_sample(); |
| 60 return false; | 59 return false; |
| 61 } | 60 } |
| 62 | 61 |
| 63 uint32 latency_us = | 62 uint32_t latency_us = |
| 64 buffer_duration_.InMicroseconds() * kNumPacketsInRingBuffer; | 63 buffer_duration_.InMicroseconds() * kNumPacketsInRingBuffer; |
| 65 | 64 |
| 66 // Use the same minimum required latency as output. | 65 // Use the same minimum required latency as output. |
| 67 latency_us = std::max(latency_us, AlsaPcmOutputStream::kMinLatencyMicros); | 66 latency_us = std::max(latency_us, AlsaPcmOutputStream::kMinLatencyMicros); |
| 68 | 67 |
| 69 if (device_name_ == kAutoSelectDevice) { | 68 if (device_name_ == kAutoSelectDevice) { |
| 70 const char* device_names[] = { kDefaultDevice1, kDefaultDevice2 }; | 69 const char* device_names[] = { kDefaultDevice1, kDefaultDevice2 }; |
| 71 for (size_t i = 0; i < arraysize(device_names); ++i) { | 70 for (size_t i = 0; i < arraysize(device_names); ++i) { |
| 72 device_handle_ = alsa_util::OpenCaptureDevice( | 71 device_handle_ = alsa_util::OpenCaptureDevice( |
| 73 wrapper_, device_names[i], params_.channels(), | 72 wrapper_, device_names[i], params_.channels(), |
| 74 params_.sample_rate(), pcm_format, latency_us); | 73 params_.sample_rate(), pcm_format, latency_us); |
| 75 | 74 |
| 76 if (device_handle_) { | 75 if (device_handle_) { |
| 77 device_name_ = device_names[i]; | 76 device_name_ = device_names[i]; |
| 78 break; | 77 break; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 } else { | 80 } else { |
| 82 device_handle_ = alsa_util::OpenCaptureDevice(wrapper_, | 81 device_handle_ = alsa_util::OpenCaptureDevice(wrapper_, |
| 83 device_name_.c_str(), | 82 device_name_.c_str(), |
| 84 params_.channels(), | 83 params_.channels(), |
| 85 params_.sample_rate(), | 84 params_.sample_rate(), |
| 86 pcm_format, latency_us); | 85 pcm_format, latency_us); |
| 87 } | 86 } |
| 88 | 87 |
| 89 if (device_handle_) { | 88 if (device_handle_) { |
| 90 audio_buffer_.reset(new uint8[bytes_per_buffer_]); | 89 audio_buffer_.reset(new uint8_t[bytes_per_buffer_]); |
| 91 | 90 |
| 92 // Open the microphone mixer. | 91 // Open the microphone mixer. |
| 93 mixer_handle_ = alsa_util::OpenMixer(wrapper_, device_name_); | 92 mixer_handle_ = alsa_util::OpenMixer(wrapper_, device_name_); |
| 94 if (mixer_handle_) { | 93 if (mixer_handle_) { |
| 95 mixer_element_handle_ = alsa_util::LoadCaptureMixerElement( | 94 mixer_element_handle_ = alsa_util::LoadCaptureMixerElement( |
| 96 wrapper_, mixer_handle_); | 95 wrapper_, mixer_handle_); |
| 97 } | 96 } |
| 98 } | 97 } |
| 99 | 98 |
| 100 return device_handle_ != NULL; | 99 return device_handle_ != NULL; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 188 |
| 190 base::TimeDelta next_check_time = buffer_duration_ / 2; | 189 base::TimeDelta next_check_time = buffer_duration_ / 2; |
| 191 base::MessageLoop::current()->PostDelayedTask( | 190 base::MessageLoop::current()->PostDelayedTask( |
| 192 FROM_HERE, | 191 FROM_HERE, |
| 193 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), | 192 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), |
| 194 next_check_time); | 193 next_check_time); |
| 195 return; | 194 return; |
| 196 } | 195 } |
| 197 | 196 |
| 198 int num_buffers = frames / params_.frames_per_buffer(); | 197 int num_buffers = frames / params_.frames_per_buffer(); |
| 199 uint32 hardware_delay_bytes = | 198 uint32_t hardware_delay_bytes = |
| 200 static_cast<uint32>(GetCurrentDelay() * params_.GetBytesPerFrame()); | 199 static_cast<uint32_t>(GetCurrentDelay() * params_.GetBytesPerFrame()); |
| 201 double normalized_volume = 0.0; | 200 double normalized_volume = 0.0; |
| 202 | 201 |
| 203 // Update the AGC volume level once every second. Note that, |volume| is | 202 // Update the AGC volume level once every second. Note that, |volume| is |
| 204 // also updated each time SetVolume() is called through IPC by the | 203 // also updated each time SetVolume() is called through IPC by the |
| 205 // render-side AGC. | 204 // render-side AGC. |
| 206 GetAgcVolume(&normalized_volume); | 205 GetAgcVolume(&normalized_volume); |
| 207 | 206 |
| 208 while (num_buffers--) { | 207 while (num_buffers--) { |
| 209 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), | 208 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), |
| 210 params_.frames_per_buffer()); | 209 params_.frames_per_buffer()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 bool AlsaPcmInputStream::IsMuted() { | 337 bool AlsaPcmInputStream::IsMuted() { |
| 339 return false; | 338 return false; |
| 340 } | 339 } |
| 341 | 340 |
| 342 void AlsaPcmInputStream::HandleError(const char* method, int error) { | 341 void AlsaPcmInputStream::HandleError(const char* method, int error) { |
| 343 LOG(WARNING) << method << ": " << wrapper_->StrError(error); | 342 LOG(WARNING) << method << ": " << wrapper_->StrError(error); |
| 344 callback_->OnError(this); | 343 callback_->OnError(this); |
| 345 } | 344 } |
| 346 | 345 |
| 347 } // namespace media | 346 } // namespace media |
| OLD | NEW |