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 audio_bus_(AudioBus::Create(params)), | |
46 weak_factory_(this) {} | 47 weak_factory_(this) {} |
47 | 48 |
48 AlsaPcmInputStream::~AlsaPcmInputStream() {} | 49 AlsaPcmInputStream::~AlsaPcmInputStream() {} |
49 | 50 |
50 bool AlsaPcmInputStream::Open() { | 51 bool AlsaPcmInputStream::Open() { |
51 if (device_handle_) | 52 if (device_handle_) |
52 return false; // Already open. | 53 return false; // Already open. |
53 | 54 |
54 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( | 55 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( |
55 params_.bits_per_sample()); | 56 params_.bits_per_sample()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 202 |
202 // Update the AGC volume level once every second. Note that, |volume| is | 203 // Update the AGC volume level once every second. Note that, |volume| is |
203 // also updated each time SetVolume() is called through IPC by the | 204 // also updated each time SetVolume() is called through IPC by the |
204 // render-side AGC. | 205 // render-side AGC. |
205 GetAgcVolume(&normalized_volume); | 206 GetAgcVolume(&normalized_volume); |
206 | 207 |
207 while (num_buffers--) { | 208 while (num_buffers--) { |
208 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), | 209 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), |
209 params_.frames_per_buffer()); | 210 params_.frames_per_buffer()); |
210 if (frames_read == params_.frames_per_buffer()) { | 211 if (frames_read == params_.frames_per_buffer()) { |
211 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_, | 212 audio_bus_->FromInterleaved( |
212 hardware_delay_bytes, normalized_volume); | 213 audio_buffer_.get(), audio_bus_->frames(), |
214 params_.bits_per_sample() / 8); | |
215 callback_->OnData(this, audio_bus_.get(), hardware_delay_bytes, | |
DaleCurtis
2014/06/03 21:03:06
Formatting is wrong, run this section through clan
henrika (OOO until Aug 14)
2014/06/04 07:50:23
Thx. Done. CL was not cleaned up. Mainly wanted to
| |
216 normalized_volume); | |
213 } else { | 217 } else { |
214 LOG(WARNING) << "PcmReadi returning less than expected frames: " | 218 LOG(WARNING) << "PcmReadi returning less than expected frames: " |
215 << frames_read << " vs. " << params_.frames_per_buffer() | 219 << frames_read << " vs. " << params_.frames_per_buffer() |
216 << ". Dropping this buffer."; | 220 << ". Dropping this buffer."; |
217 } | 221 } |
218 } | 222 } |
219 | 223 |
220 next_read_time_ += buffer_duration_; | 224 next_read_time_ += buffer_duration_; |
221 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now(); | 225 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now(); |
222 if (delay < base::TimeDelta()) { | 226 if (delay < base::TimeDelta()) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 | 334 |
331 return static_cast<double>(current_volume); | 335 return static_cast<double>(current_volume); |
332 } | 336 } |
333 | 337 |
334 void AlsaPcmInputStream::HandleError(const char* method, int error) { | 338 void AlsaPcmInputStream::HandleError(const char* method, int error) { |
335 LOG(WARNING) << method << ": " << wrapper_->StrError(error); | 339 LOG(WARNING) << method << ": " << wrapper_->StrError(error); |
336 callback_->OnError(this); | 340 callback_->OnError(this); |
337 } | 341 } |
338 | 342 |
339 } // namespace media | 343 } // namespace media |
OLD | NEW |