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" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 8), | 36 8), |
37 wrapper_(wrapper), | 37 wrapper_(wrapper), |
38 buffer_duration_(base::TimeDelta::FromMicroseconds( | 38 buffer_duration_(base::TimeDelta::FromMicroseconds( |
39 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / | 39 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / |
40 static_cast<float>(params.sample_rate()))), | 40 static_cast<float>(params.sample_rate()))), |
41 callback_(NULL), | 41 callback_(NULL), |
42 device_handle_(NULL), | 42 device_handle_(NULL), |
43 mixer_handle_(NULL), | 43 mixer_handle_(NULL), |
44 mixer_element_handle_(NULL), | 44 mixer_element_handle_(NULL), |
45 read_callback_behind_schedule_(false), | 45 read_callback_behind_schedule_(false), |
46 weak_factory_(this) {} | 46 audio_bus_(AudioBus::Create(params)), |
| 47 weak_factory_(this) { |
| 48 } |
47 | 49 |
48 AlsaPcmInputStream::~AlsaPcmInputStream() {} | 50 AlsaPcmInputStream::~AlsaPcmInputStream() {} |
49 | 51 |
50 bool AlsaPcmInputStream::Open() { | 52 bool AlsaPcmInputStream::Open() { |
51 if (device_handle_) | 53 if (device_handle_) |
52 return false; // Already open. | 54 return false; // Already open. |
53 | 55 |
54 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( | 56 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( |
55 params_.bits_per_sample()); | 57 params_.bits_per_sample()); |
56 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) { | 58 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 203 |
202 // Update the AGC volume level once every second. Note that, |volume| is | 204 // Update the AGC volume level once every second. Note that, |volume| is |
203 // also updated each time SetVolume() is called through IPC by the | 205 // also updated each time SetVolume() is called through IPC by the |
204 // render-side AGC. | 206 // render-side AGC. |
205 GetAgcVolume(&normalized_volume); | 207 GetAgcVolume(&normalized_volume); |
206 | 208 |
207 while (num_buffers--) { | 209 while (num_buffers--) { |
208 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), | 210 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), |
209 params_.frames_per_buffer()); | 211 params_.frames_per_buffer()); |
210 if (frames_read == params_.frames_per_buffer()) { | 212 if (frames_read == params_.frames_per_buffer()) { |
211 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_, | 213 audio_bus_->FromInterleaved(audio_buffer_.get(), |
212 hardware_delay_bytes, normalized_volume); | 214 audio_bus_->frames(), |
| 215 params_.bits_per_sample() / 8); |
| 216 callback_->OnData( |
| 217 this, audio_bus_.get(), hardware_delay_bytes, normalized_volume); |
213 } else { | 218 } else { |
214 LOG(WARNING) << "PcmReadi returning less than expected frames: " | 219 LOG(WARNING) << "PcmReadi returning less than expected frames: " |
215 << frames_read << " vs. " << params_.frames_per_buffer() | 220 << frames_read << " vs. " << params_.frames_per_buffer() |
216 << ". Dropping this buffer."; | 221 << ". Dropping this buffer."; |
217 } | 222 } |
218 } | 223 } |
219 | 224 |
220 next_read_time_ += buffer_duration_; | 225 next_read_time_ += buffer_duration_; |
221 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now(); | 226 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now(); |
222 if (delay < base::TimeDelta()) { | 227 if (delay < base::TimeDelta()) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 335 |
331 return static_cast<double>(current_volume); | 336 return static_cast<double>(current_volume); |
332 } | 337 } |
333 | 338 |
334 void AlsaPcmInputStream::HandleError(const char* method, int error) { | 339 void AlsaPcmInputStream::HandleError(const char* method, int error) { |
335 LOG(WARNING) << method << ": " << wrapper_->StrError(error); | 340 LOG(WARNING) << method << ": " << wrapper_->StrError(error); |
336 callback_->OnError(this); | 341 callback_->OnError(this); |
337 } | 342 } |
338 | 343 |
339 } // namespace media | 344 } // namespace media |
OLD | NEW |